summaryrefslogtreecommitdiffstats
path: root/usr.sbin/tcpdump/print-rip.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2018-07-06 05:47:22 +0000
committerdlg <dlg@openbsd.org>2018-07-06 05:47:22 +0000
commiteb9376818a9b25c1270e004624fd7f7b5ec31760 (patch)
tree5176fc22152f3c68ccb5ccbf653176a835a9f55a /usr.sbin/tcpdump/print-rip.c
parentmove the ip checksumming code into in_cksum.c (diff)
downloadwireguard-openbsd-eb9376818a9b25c1270e004624fd7f7b5ec31760.tar.xz
wireguard-openbsd-eb9376818a9b25c1270e004624fd7f7b5ec31760.zip
Rework UDP parsing, particularly around IP addresses.
This originally started as trying to put a consistent space between the UDP header information and the payload parsing, but while doing that I noticed inconsistent IPv4 vs IPv6 handling. Apart from the default "srcip.srcport > dstip.dstpor" output, all the other places that IP addresses were printed assumed IPv4. It looks like it is possible that udp_print() can be called without an IP header, which made these blind IPv4 prints turn into NULL derefs. This fixes the problem above by only having a single place that prints the addresses out, and makes sure to get the difference between IPv4, IPv6 and no IP correct. This changes how the checksum is calculated. It incrementally builds the UDP checksum by feeding the IPv4 and v6 addresses in separately, then using common code for the rest of the pseudo header and actual payload. Lastly, this does make printing the space between the UDP header and its payload consistent. The UDP code is now responsible for adding a space after itself so the payload parsers don't have to. They got it wrong in some cases anyway, so this should be a lot more uniform. help and ok sthen@
Diffstat (limited to 'usr.sbin/tcpdump/print-rip.c')
-rw-r--r--usr.sbin/tcpdump/print-rip.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/usr.sbin/tcpdump/print-rip.c b/usr.sbin/tcpdump/print-rip.c
index 44e9301296f..4b77c14ecb8 100644
--- a/usr.sbin/tcpdump/print-rip.c
+++ b/usr.sbin/tcpdump/print-rip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-rip.c,v 1.16 2015/11/16 00:16:39 mmcc Exp $ */
+/* $OpenBSD: print-rip.c,v 1.17 2018/07/06 05:47:22 dlg Exp $ */
/*
* Copyright (c) 1989, 1990, 1991, 1993, 1994, 1996
@@ -159,7 +159,7 @@ rip_print(const u_char *dat, u_int length)
i = min(length, snapend - dat) - sizeof(*rp);
if (i < 0) {
- printf(" [|rip]");
+ printf("[|rip]");
return;
}
@@ -167,21 +167,21 @@ rip_print(const u_char *dat, u_int length)
switch (rp->rip_vers) {
case 0:
/* RFC 1058 */
- printf(" RIPv0: ");
+ printf("RIPv0: ");
rip_printblk((u_char *)(rp + 1), snapend);
break;
default:
switch (rp->rip_cmd) {
case RIPCMD_REQUEST:
- printf(" RIPv%d-req %d", rp->rip_vers, length);
+ printf("RIPv%d-req %d", rp->rip_vers, length);
break;
case RIPCMD_RESPONSE:
j = length / sizeof(*ni);
if (j * sizeof(*ni) != length - 4)
- printf(" RIPv%d-resp [items %d] [%d]:",
+ printf("RIPv%d-resp [items %d] [%d]:",
rp->rip_vers, j, length);
else
- printf(" RIPv%d-resp [items %d]:",
+ printf("RIPv%d-resp [items %d]:",
rp->rip_vers, j);
trunc = (i / sizeof(*ni)) != j;
ni = (struct rip_netinfo *)(rp + 1);
@@ -195,21 +195,21 @@ rip_print(const u_char *dat, u_int length)
printf("[|rip]");
break;
case RIPCMD_TRACEON:
- printf(" RIPv%d-traceon %d: \"", rp->rip_vers, length);
+ printf("RIPv%d-traceon %d: \"", rp->rip_vers, length);
(void)fn_print((const u_char *)(rp + 1), snapend);
fputs("\"", stdout);
break;
case RIPCMD_TRACEOFF:
- printf(" RIPv%d-traceoff %d", rp->rip_vers, length);
+ printf("RIPv%d-traceoff %d", rp->rip_vers, length);
break;
case RIPCMD_POLL:
- printf(" RIPv%d-poll %d", rp->rip_vers, length);
+ printf("RIPv%d-poll %d", rp->rip_vers, length);
break;
case RIPCMD_POLLENTRY:
- printf(" RIPv%d-pollentry %d", rp->rip_vers, length);
+ printf("RIPv%d-pollentry %d", rp->rip_vers, length);
break;
default:
- printf(" RIPv%d-#%d %d", rp->rip_vers, rp->rip_cmd,
+ printf("RIPv%d-#%d %d", rp->rip_vers, rp->rip_cmd,
length);
break;
}