summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorLawrence Teo <lteo@cvs.openbsd.org>2014-06-20 04:04:53 +0000
committerLawrence Teo <lteo@cvs.openbsd.org>2014-06-20 04:04:53 +0000
commit52bfa89556e0719100a1a96bd1695d65ad5b9e32 (patch)
tree64eed16719ad06a0a33cd4ef0e5c841c68a168ae /usr.sbin
parentc0d146063d45fc9282793453cb0e29f9bc7b8ff5 (diff)
Instead of showing the difference between a bad checksum and a good
checksum, make tcpdump (with the -v flag) show the actual bad checksum within the IP/protocol header itself and what the good checksum should be, e.g. "[bad tcp cksum abcd! -> d1e6]" This change applies to IP, TCP (over IPv4 and IPv6), UDP (over IPv4 and IPv6), ICMP, and ICMPv6. This commit also fixes several inconsistencies in the way bad checksums were displayed for these protocols. Tested on amd64, i386, and macppc. ok henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tcpdump/print-icmp.c13
-rw-r--r--usr.sbin/tcpdump/print-icmp6.c13
-rw-r--r--usr.sbin/tcpdump/print-ip.c11
-rw-r--r--usr.sbin/tcpdump/print-tcp.c22
-rw-r--r--usr.sbin/tcpdump/print-udp.c21
5 files changed, 46 insertions, 34 deletions
diff --git a/usr.sbin/tcpdump/print-icmp.c b/usr.sbin/tcpdump/print-icmp.c
index fcb51f4478a..14849ba2a61 100644
--- a/usr.sbin/tcpdump/print-icmp.c
+++ b/usr.sbin/tcpdump/print-icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-icmp.c,v 1.22 2014/01/11 04:40:45 lteo Exp $ */
+/* $OpenBSD: print-icmp.c,v 1.23 2014/06/20 04:04:52 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -375,15 +375,18 @@ icmp_print(const u_char *bp, u_int length, const u_char *bp2)
}
(void)printf("icmp: %s", str);
if (vflag) {
- u_int16_t sum;
if (TTEST2(dp->icmp_type, length)) {
+ u_int16_t sum, icmp_sum;
sum = in_cksum((const u_short *)dp, length, 0);
- if (sum != 0)
- (void)printf(" [bad icmp cksum %x!]", sum);
+ if (sum != 0) {
+ icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum);
+ (void)printf(" [bad icmp cksum %x! -> %x]", icmp_sum,
+ in_cksum_shouldbe(icmp_sum, sum));
+ }
else
(void)printf(" [icmp cksum ok]");
}
- }
+ }
if (vflag > 1 && !ICMP_INFOTYPE(dp->icmp_type) &&
TTEST(dp->icmp_ip)) {
(void)printf(" for ");
diff --git a/usr.sbin/tcpdump/print-icmp6.c b/usr.sbin/tcpdump/print-icmp6.c
index 0249039d27e..56a9559d87d 100644
--- a/usr.sbin/tcpdump/print-icmp6.c
+++ b/usr.sbin/tcpdump/print-icmp6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-icmp6.c,v 1.12 2014/01/11 04:41:08 lteo Exp $ */
+/* $OpenBSD: print-icmp6.c,v 1.13 2014/06/20 04:04:52 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994
@@ -53,6 +53,7 @@
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
void icmp6_opt_print(const u_char *, int);
void mld6_print(const u_char *);
@@ -485,12 +486,14 @@ icmp6_print(const u_char *bp, u_int length, const u_char *bp2)
break;
}
if (vflag) {
- u_int16_t sum;
if (TTEST2(dp->icmp6_type, length)) {
+ u_int16_t sum, icmp6_sum;
sum = icmp6_cksum(ip, dp, length);
- if (sum != 0)
- printf(" [bad icmp6 cksum %x!]", sum);
- else
+ if (sum != 0) {
+ icmp6_sum = EXTRACT_16BITS(&dp->icmp6_cksum);
+ printf(" [bad icmp6 cksum %x! -> %x]", icmp6_sum,
+ in_cksum_shouldbe(icmp6_sum, sum));
+ } else
printf(" [icmp6 cksum ok]");
}
}
diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c
index c3324980fef..4fd1e8d1394 100644
--- a/usr.sbin/tcpdump/print-ip.c
+++ b/usr.sbin/tcpdump/print-ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-ip.c,v 1.37 2014/01/11 04:35:52 lteo Exp $ */
+/* $OpenBSD: print-ip.c,v 1.38 2014/06/20 04:04:52 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -627,7 +627,6 @@ ip_print(register const u_char *bp, register u_int length)
(void)printf(" [ttl %d]", (int)ip->ip_ttl);
if (vflag) {
- int sum;
char *sep = "";
printf(" (");
@@ -642,12 +641,12 @@ ip_print(register const u_char *bp, register u_int length)
(void)printf("%slen %u", sep, ntohs(ip->ip_len));
sep = ", ";
if ((u_char *)ip + hlen <= snapend) {
+ u_int16_t sum, ip_sum;
sum = in_cksum((const u_short *)ip, hlen, 0);
if (sum != 0) {
- (void)printf("%sbad cksum %x!", sep,
- ntohs(ip->ip_sum));
- if (vflag > 1)
- (void)printf(" differs by %x", htons(sum));
+ ip_sum = EXTRACT_16BITS(&ip->ip_sum);
+ (void)printf("%sbad ip cksum %x! -> %x", sep, ip_sum,
+ in_cksum_shouldbe(ip_sum, sum));
sep = ", ";
}
}
diff --git a/usr.sbin/tcpdump/print-tcp.c b/usr.sbin/tcpdump/print-tcp.c
index a0c46b3bec3..43ee76f2c58 100644
--- a/usr.sbin/tcpdump/print-tcp.c
+++ b/usr.sbin/tcpdump/print-tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-tcp.c,v 1.29 2014/02/05 21:12:19 florian Exp $ */
+/* $OpenBSD: print-tcp.c,v 1.30 2014/06/20 04:04:52 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -419,23 +419,27 @@ tcp_print(register const u_char *bp, register u_int length,
}
if (ip && ip->ip_v == 4 && vflag) {
- int sum;
if (TTEST2(tp->th_sport, length)) {
+ u_int16_t sum, tcp_sum;
sum = tcp_cksum(ip, tp, length);
- if (sum != 0)
- (void)printf(" [bad tcp cksum %x!]", sum);
- else
+ if (sum != 0) {
+ tcp_sum = EXTRACT_16BITS(&tp->th_sum);
+ (void)printf(" [bad tcp cksum %x! -> %x]", tcp_sum,
+ in_cksum_shouldbe(tcp_sum, sum));
+ } else
(void)printf(" [tcp sum ok]");
}
}
#ifdef INET6
if (ip6 && ip6->ip6_plen && vflag) {
- int sum;
if (TTEST2(tp->th_sport, length)) {
+ u_int16_t sum, tcp_sum;
sum = tcp6_cksum(ip6, tp, length);
- if (sum != 0)
- (void)printf(" [bad tcp cksum %x!]", sum);
- else
+ if (sum != 0) {
+ tcp_sum = EXTRACT_16BITS(&tp->th_sum);
+ (void)printf(" [bad tcp cksum %x! -> %x]", tcp_sum,
+ in_cksum_shouldbe(tcp_sum, sum));
+ } else
(void)printf(" [tcp sum ok]");
}
}
diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c
index f1ecd7a83ef..dca0c68e93c 100644
--- a/usr.sbin/tcpdump/print-udp.c
+++ b/usr.sbin/tcpdump/print-udp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-udp.c,v 1.35 2014/01/26 18:03:27 naddy Exp $ */
+/* $OpenBSD: print-udp.c,v 1.36 2014/06/20 04:04:52 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
@@ -57,6 +57,7 @@
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
#include "appletalk.h"
#include "nfsv2.h"
@@ -566,27 +567,29 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
#endif
if (ip->ip_v == 4 && vflag) {
- int sum = up->uh_sum;
- if (sum == 0) {
- (void)printf(" [no cksum]");
+ u_int16_t sum, udp_sum = EXTRACT_16BITS(&up->uh_sum);
+ if (udp_sum == 0) {
+ (void)printf(" [no udp cksum]");
} else if (TTEST2(cp[0], length)) {
sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
if (sum != 0)
- (void)printf(" [bad udp cksum %x!]", sum);
+ (void)printf(" [bad udp cksum %x! -> %x]", udp_sum,
+ in_cksum_shouldbe(udp_sum, sum));
else
(void)printf(" [udp sum ok]");
}
}
#ifdef INET6
if (ip->ip_v == 6 && ip6->ip6_plen && vflag) {
- int sum = up->uh_sum;
+ u_int16_t sum, udp_sum = EXTRACT_16BITS(&up->uh_sum);
/* for IPv6, UDP checksum is mandatory */
- if (sum == 0) {
- (void)printf(" [invalid cksum 0]");
+ if (udp_sum == 0) {
+ (void)printf(" [invalid udp cksum 0]");
} else if (TTEST2(cp[0], length)) {
sum = udp6_cksum(ip6, up, length + sizeof(struct udphdr));
if (sum != 0)
- (void)printf(" [bad udp cksum %x!]", sum);
+ (void)printf(" [bad udp cksum %x! -> %x]", udp_sum,
+ in_cksum_shouldbe(udp_sum, sum));
else
(void)printf(" [udp sum ok]");
}