tstellar / rpms / tcpdump

Forked from rpms/tcpdump 3 years ago
Clone
a41ce5f
From ab4e52b94aac6cb729a5a695aa612d5ebda2ec3a Mon Sep 17 00:00:00 2001
a41ce5f
From: Guy Harris <guy@alum.mit.edu>
a41ce5f
Date: Tue, 11 Nov 2014 17:24:12 -0800
a41ce5f
Subject: [PATCH] Add initial bounds check, get rid of union aodv.
a41ce5f
a41ce5f
Fetch the type field without using a structure, and check to make sure
a41ce5f
it's not past the end of the packet.
a41ce5f
a41ce5f
Pass to each dissection routine a pointer to the appropriate message
a41ce5f
type structure, rather than a pointer to a union of all the message type
a41ce5f
structures.
a41ce5f
---
a41ce5f
 print-aodv.c | 274 ++++++++++++++++++++++++++++-------------------------------
a41ce5f
 1 file changed, 130 insertions(+), 144 deletions(-)
a41ce5f
a41ce5f
diff --git a/print-aodv.c b/print-aodv.c
a41ce5f
index 093e174..da5b169 100644
a41ce5f
--- a/print-aodv.c
a41ce5f
+++ b/print-aodv.c
a41ce5f
@@ -163,19 +163,6 @@ struct aodv_rrep_ack {
a41ce5f
 	uint8_t		ra_zero0;
a41ce5f
 };
a41ce5f
 
a41ce5f
-union aodv {
a41ce5f
-	struct aodv_rreq rreq;
a41ce5f
-	struct aodv_rrep rrep;
a41ce5f
-	struct aodv_rerr rerr;
a41ce5f
-	struct aodv_rrep_ack rrep_ack;
a41ce5f
-#ifdef INET6
a41ce5f
-	struct aodv_rreq6 rreq6;
a41ce5f
-	struct aodv_rreq6_draft_01 rreq6_draft_01;
a41ce5f
-	struct aodv_rrep6 rrep6;
a41ce5f
-	struct aodv_rrep6_draft_01 rrep6_draft_01;
a41ce5f
-#endif
a41ce5f
-};
a41ce5f
-
a41ce5f
 #define	AODV_RREQ		1	/* route request */
a41ce5f
 #define	AODV_RREP		2	/* route response */
a41ce5f
 #define	AODV_RERR		3	/* error report */
a41ce5f
@@ -232,7 +219,7 @@ aodv_extension(netdissect_options *ndo,
a41ce5f
 
a41ce5f
 static void
a41ce5f
 aodv_rreq(netdissect_options *ndo,
a41ce5f
-          const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+          const struct aodv_rreq *ap, const u_char *dat, u_int length)
a41ce5f
 {
a41ce5f
 	u_int i;
a41ce5f
 
a41ce5f
@@ -241,31 +228,31 @@ aodv_rreq(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rreq)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rreq]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rreq);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
a41ce5f
 	    "\tdst %s seq %lu src %s seq %lu", length,
a41ce5f
-	    ap->rreq.rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
-	    ap->rreq.rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rreq.rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
-	    ap->rreq.rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
-	    ap->rreq.rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
-	    ap->rreq.rreq_hops,
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_id),
a41ce5f
-	    ipaddr_string(ndo, &ap->rreq.rreq_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_ds),
a41ce5f
-	    ipaddr_string(ndo, &ap->rreq.rreq_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq.rreq_os)));
a41ce5f
+	    ap->rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
+	    ap->rreq_hops,
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_id),
a41ce5f
+	    ipaddr_string(ndo, &ap->rreq_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
a41ce5f
+	    ipaddr_string(ndo, &ap->rreq_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rreq + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 }
a41ce5f
 
a41ce5f
 static void
a41ce5f
 aodv_rrep(netdissect_options *ndo,
a41ce5f
-          const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+          const struct aodv_rrep *ap, const u_char *dat, u_int length)
a41ce5f
 {
a41ce5f
 	u_int i;
a41ce5f
 
a41ce5f
@@ -274,28 +261,28 @@ aodv_rrep(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rrep)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rrep]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rrep);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
a41ce5f
 	    "\tdst %s dseq %lu src %s %lu ms", length,
a41ce5f
-	    ap->rrep.rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rrep.rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
-	    ap->rrep.rrep_ps & RREP_PREFIX_MASK,
a41ce5f
-	    ap->rrep.rrep_hops,
a41ce5f
-	    ipaddr_string(ndo, &ap->rrep.rrep_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_ds),
a41ce5f
-	    ipaddr_string(ndo, &ap->rrep.rrep_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep.rrep_life)));
a41ce5f
+	    ap->rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
+	    ap->rrep_ps & RREP_PREFIX_MASK,
a41ce5f
+	    ap->rrep_hops,
a41ce5f
+	    ipaddr_string(ndo, &ap->rrep_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
a41ce5f
+	    ipaddr_string(ndo, &ap->rrep_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rrep + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 }
a41ce5f
 
a41ce5f
 static void
a41ce5f
 aodv_rerr(netdissect_options *ndo,
a41ce5f
-          const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+          const struct aodv_rerr *ap, const u_char *dat, u_int length)
a41ce5f
 {
a41ce5f
 	u_int i;
a41ce5f
 	const struct rerr_unreach *dp = NULL;
a41ce5f
@@ -311,14 +298,14 @@ aodv_rerr(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i -= offsetof(struct aodv_rerr, r);
a41ce5f
-	dp = &ap->rerr.r.dest[0];
a41ce5f
-	n = ap->rerr.rerr_dc * sizeof(ap->rerr.r.dest[0]);
a41ce5f
+	dp = &ap->r.dest[0];
a41ce5f
+	n = ap->rerr_dc * sizeof(ap->r.dest[0]);
a41ce5f
 	ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
a41ce5f
-	    ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
-	    ap->rerr.rerr_dc, length));
a41ce5f
-	trunc = n - (i/sizeof(ap->rerr.r.dest[0]));
a41ce5f
-	for (; i >= sizeof(ap->rerr.r.dest[0]);
a41ce5f
-	    ++dp, i -= sizeof(ap->rerr.r.dest[0])) {
a41ce5f
+	    ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
+	    ap->rerr_dc, length));
a41ce5f
+	trunc = n - (i/sizeof(ap->r.dest[0]));
a41ce5f
+	for (; i >= sizeof(ap->r.dest[0]);
a41ce5f
+	    ++dp, i -= sizeof(ap->r.dest[0])) {
a41ce5f
 		ND_PRINT((ndo, " {%s}(%ld)", ipaddr_string(ndo, &dp->u_da),
a41ce5f
 		    (unsigned long)EXTRACT_32BITS(&dp->u_ds)));
a41ce5f
 	}
a41ce5f
@@ -329,10 +316,10 @@ aodv_rerr(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_rreq(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+             const struct aodv_rreq6 *ap, const u_char *dat, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_rreq(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
+             const struct aodv_rreq6 *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -343,26 +330,26 @@ aodv_v6_rreq(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rreq6)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rreq6]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rreq6);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
a41ce5f
 	    "\tdst %s seq %lu src %s seq %lu", length,
a41ce5f
-	    ap->rreq6.rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
-	    ap->rreq6.rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rreq6.rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
-	    ap->rreq6.rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
-	    ap->rreq6.rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
-	    ap->rreq6.rreq_hops,
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_id),
a41ce5f
-	    ip6addr_string(ndo, &ap->rreq6.rreq_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_ds),
a41ce5f
-	    ip6addr_string(ndo, &ap->rreq6.rreq_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6.rreq_os)));
a41ce5f
+	    ap->rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
+	    ap->rreq_hops,
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_id),
a41ce5f
+	    ip6addr_string(ndo, &ap->rreq_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
a41ce5f
+	    ip6addr_string(ndo, &ap->rreq_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rreq6 + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 #else
a41ce5f
 	ND_PRINT((ndo, " v6 rreq %u", length));
a41ce5f
 #endif
a41ce5f
@@ -371,10 +358,10 @@ aodv_v6_rreq(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_rrep(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+             const struct aodv_rrep6 *ap, const u_char *dat, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_rrep(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
+             const struct aodv_rrep6 *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -385,23 +372,23 @@ aodv_v6_rrep(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rrep6)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rrep6]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rrep6);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
a41ce5f
 	   "\tdst %s dseq %lu src %s %lu ms", length,
a41ce5f
-	    ap->rrep6.rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rrep6.rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
-	    ap->rrep6.rrep_ps & RREP_PREFIX_MASK,
a41ce5f
-	    ap->rrep6.rrep_hops,
a41ce5f
-	    ip6addr_string(ndo, &ap->rrep6.rrep_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_ds),
a41ce5f
-	    ip6addr_string(ndo, &ap->rrep6.rrep_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep6.rrep_life)));
a41ce5f
+	    ap->rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
+	    ap->rrep_ps & RREP_PREFIX_MASK,
a41ce5f
+	    ap->rrep_hops,
a41ce5f
+	    ip6addr_string(ndo, &ap->rrep_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
a41ce5f
+	    ip6addr_string(ndo, &ap->rrep_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rrep6 + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 #else
a41ce5f
 	ND_PRINT((ndo, " rrep %u", length));
a41ce5f
 #endif
a41ce5f
@@ -410,10 +397,10 @@ aodv_v6_rrep(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_rerr(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap, u_int length)
a41ce5f
+             const struct aodv_rerr *ap, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_rerr(netdissect_options *ndo,
a41ce5f
-             const union aodv *ap _U_, u_int length)
a41ce5f
+             const struct aodv_rerr *ap _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -421,12 +408,12 @@ aodv_v6_rerr(netdissect_options *ndo,
a41ce5f
 	int i, j, n, trunc;
a41ce5f
 
a41ce5f
 	i = length - offsetof(struct aodv_rerr, r);
a41ce5f
-	j = sizeof(ap->rerr.r.dest6[0]);
a41ce5f
-	dp6 = &ap->rerr.r.dest6[0];
a41ce5f
-	n = ap->rerr.rerr_dc * j;
a41ce5f
+	j = sizeof(ap->r.dest6[0]);
a41ce5f
+	dp6 = &ap->r.dest6[0];
a41ce5f
+	n = ap->rerr_dc * j;
a41ce5f
 	ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
a41ce5f
-	    ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
-	    ap->rerr.rerr_dc, length));
a41ce5f
+	    ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
+	    ap->rerr_dc, length));
a41ce5f
 	trunc = n - (i/j);
a41ce5f
 	for (; i -= j >= 0; ++dp6) {
a41ce5f
 		ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
a41ce5f
@@ -442,11 +429,10 @@ aodv_v6_rerr(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_draft_01_rreq(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+                      const struct aodv_rreq6_draft_01 *ap, const u_char *dat, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_draft_01_rreq(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap _U_, const u_char *dat _U_,
a41ce5f
-    u_int length)
a41ce5f
+                      const struct aodv_rreq6_draft_01 *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -457,26 +443,26 @@ aodv_v6_draft_01_rreq(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rreq6_draft_01)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rreq6]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rreq6_draft_01);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
a41ce5f
 	    "\tdst %s seq %lu src %s seq %lu", length,
a41ce5f
-	    ap->rreq6_draft_01.rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
-	    ap->rreq6_draft_01.rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rreq6_draft_01.rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
-	    ap->rreq6_draft_01.rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
-	    ap->rreq6_draft_01.rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
-	    ap->rreq6_draft_01.rreq_hops,
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_id),
a41ce5f
-	    ip6addr_string(ndo, &ap->rreq6_draft_01.rreq_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_ds),
a41ce5f
-	    ip6addr_string(ndo, &ap->rreq6_draft_01.rreq_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rreq6_draft_01.rreq_os)));
a41ce5f
+	    ap->rreq_type & RREQ_JOIN ? "[J]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_GRAT ? "[G]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_DEST ? "[D]" : "",
a41ce5f
+	    ap->rreq_type & RREQ_UNKNOWN ? "[U] " : " ",
a41ce5f
+	    ap->rreq_hops,
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_id),
a41ce5f
+	    ip6addr_string(ndo, &ap->rreq_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
a41ce5f
+	    ip6addr_string(ndo, &ap->rreq_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rreq6_draft_01 + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 #else
a41ce5f
 	ND_PRINT((ndo, " rreq %u", length));
a41ce5f
 #endif
a41ce5f
@@ -485,11 +471,10 @@ aodv_v6_draft_01_rreq(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_draft_01_rrep(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap, const u_char *dat, u_int length)
a41ce5f
+                      const struct aodv_rrep6_draft_01 *ap, const u_char *dat, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_draft_01_rrep(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap _U_, const u_char *dat _U_,
a41ce5f
-    u_int length)
a41ce5f
+                      const struct aodv_rrep6_draft_01 *ap _U_, const u_char *dat _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -500,23 +485,23 @@ aodv_v6_draft_01_rrep(netdissect_options *ndo,
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
 	i = min(length, (u_int)(ndo->ndo_snapend - dat));
a41ce5f
-	if (i < sizeof(ap->rrep6_draft_01)) {
a41ce5f
+	if (i < sizeof(*ap)) {
a41ce5f
 		ND_PRINT((ndo, " [|rrep6]"));
a41ce5f
 		return;
a41ce5f
 	}
a41ce5f
-	i -= sizeof(ap->rrep6_draft_01);
a41ce5f
+	i -= sizeof(*ap);
a41ce5f
 	ND_PRINT((ndo, " rrep %u %s%sprefix %u hops %u\n"
a41ce5f
 	   "\tdst %s dseq %lu src %s %lu ms", length,
a41ce5f
-	    ap->rrep6_draft_01.rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
-	    ap->rrep6_draft_01.rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
-	    ap->rrep6_draft_01.rrep_ps & RREP_PREFIX_MASK,
a41ce5f
-	    ap->rrep6_draft_01.rrep_hops,
a41ce5f
-	    ip6addr_string(ndo, &ap->rrep6_draft_01.rrep_da),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_ds),
a41ce5f
-	    ip6addr_string(ndo, &ap->rrep6_draft_01.rrep_oa),
a41ce5f
-	    (unsigned long)EXTRACT_32BITS(&ap->rrep6_draft_01.rrep_life)));
a41ce5f
+	    ap->rrep_type & RREP_REPAIR ? "[R]" : "",
a41ce5f
+	    ap->rrep_type & RREP_ACK ? "[A] " : " ",
a41ce5f
+	    ap->rrep_ps & RREP_PREFIX_MASK,
a41ce5f
+	    ap->rrep_hops,
a41ce5f
+	    ip6addr_string(ndo, &ap->rrep_da),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
a41ce5f
+	    ip6addr_string(ndo, &ap->rrep_oa),
a41ce5f
+	    (unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
a41ce5f
 	if (i >= sizeof(struct aodv_ext))
a41ce5f
-		aodv_extension(ndo, (void *)(&ap->rrep6_draft_01 + 1), i);
a41ce5f
+		aodv_extension(ndo, (void *)(ap + 1), i);
a41ce5f
 #else
a41ce5f
 	ND_PRINT((ndo, " rrep %u", length));
a41ce5f
 #endif
a41ce5f
@@ -525,10 +510,10 @@ aodv_v6_draft_01_rrep(netdissect_options *ndo,
a41ce5f
 static void
a41ce5f
 #ifdef INET6
a41ce5f
 aodv_v6_draft_01_rerr(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap, u_int length)
a41ce5f
+                      const struct aodv_rerr *ap, u_int length)
a41ce5f
 #else
a41ce5f
 aodv_v6_draft_01_rerr(netdissect_options *ndo,
a41ce5f
-                      const union aodv *ap _U_, u_int length)
a41ce5f
+                      const struct aodv_rerr *ap _U_, u_int length)
a41ce5f
 #endif
a41ce5f
 {
a41ce5f
 #ifdef INET6
a41ce5f
@@ -536,12 +521,12 @@ aodv_v6_draft_01_rerr(netdissect_options *ndo,
a41ce5f
 	int i, j, n, trunc;
a41ce5f
 
a41ce5f
 	i = length - offsetof(struct aodv_rerr, r);
a41ce5f
-	j = sizeof(ap->rerr.r.dest6_draft_01[0]);
a41ce5f
-	dp6 = &ap->rerr.r.dest6_draft_01[0];
a41ce5f
-	n = ap->rerr.rerr_dc * j;
a41ce5f
+	j = sizeof(ap->r.dest6_draft_01[0]);
a41ce5f
+	dp6 = &ap->r.dest6_draft_01[0];
a41ce5f
+	n = ap->rerr_dc * j;
a41ce5f
 	ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
a41ce5f
-	    ap->rerr.rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
-	    ap->rerr.rerr_dc, length));
a41ce5f
+	    ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
a41ce5f
+	    ap->rerr_dc, length));
a41ce5f
 	trunc = n - (i/j);
a41ce5f
 	for (; i -= j >= 0; ++dp6) {
a41ce5f
 		ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
a41ce5f
@@ -558,40 +543,37 @@ void
a41ce5f
 aodv_print(netdissect_options *ndo,
a41ce5f
            const u_char *dat, u_int length, int is_ip6)
a41ce5f
 {
a41ce5f
-	const union aodv *ap;
a41ce5f
-
a41ce5f
-	ap = (union aodv *)dat;
a41ce5f
-	if (ndo->ndo_snapend < dat) {
a41ce5f
-		ND_PRINT((ndo, " [|aodv]"));
a41ce5f
-		return;
a41ce5f
-	}
a41ce5f
-	if (min(length, (u_int)(ndo->ndo_snapend - dat)) < sizeof(ap->rrep_ack)) {
a41ce5f
-		ND_PRINT((ndo, " [|aodv]"));
a41ce5f
-		return;
a41ce5f
-	}
a41ce5f
+	uint8_t msg_type;
a41ce5f
+
a41ce5f
+	/*
a41ce5f
+	 * The message type is the first byte; make sure we have it
a41ce5f
+	 * and then fetch it.
a41ce5f
+	 */
a41ce5f
+	ND_TCHECK(*dat);
a41ce5f
+	msg_type = *dat;
a41ce5f
 	ND_PRINT((ndo, " aodv"));
a41ce5f
 
a41ce5f
-	switch (ap->rerr.rerr_type) {
a41ce5f
+	switch (msg_type) {
a41ce5f
 
a41ce5f
 	case AODV_RREQ:
a41ce5f
 		if (is_ip6)
a41ce5f
-			aodv_v6_rreq(ndo, ap, dat, length);
a41ce5f
+			aodv_v6_rreq(ndo, (const struct aodv_rreq6 *)dat, dat, length);
a41ce5f
 		else
a41ce5f
-			aodv_rreq(ndo, ap, dat, length);
a41ce5f
+			aodv_rreq(ndo, (const struct aodv_rreq *)dat, dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_RREP:
a41ce5f
 		if (is_ip6)
a41ce5f
-			aodv_v6_rrep(ndo, ap, dat, length);
a41ce5f
+			aodv_v6_rrep(ndo, (const struct aodv_rrep6 *)dat, dat, length);
a41ce5f
 		else
a41ce5f
-			aodv_rrep(ndo, ap, dat, length);
a41ce5f
+			aodv_rrep(ndo, (const struct aodv_rrep *)dat, dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_RERR:
a41ce5f
 		if (is_ip6)
a41ce5f
-			aodv_v6_rerr(ndo, ap, length);
a41ce5f
+			aodv_v6_rerr(ndo, (const struct aodv_rerr *)dat, length);
a41ce5f
 		else
a41ce5f
-			aodv_rerr(ndo, ap, dat, length);
a41ce5f
+			aodv_rerr(ndo, (const struct aodv_rerr *)dat, dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_RREP_ACK:
a41ce5f
@@ -599,15 +581,15 @@ aodv_print(netdissect_options *ndo,
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_V6_DRAFT_01_RREQ:
a41ce5f
-		aodv_v6_draft_01_rreq(ndo, ap, dat, length);
a41ce5f
+		aodv_v6_draft_01_rreq(ndo, (const struct aodv_rreq6_draft_01 *)dat, dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_V6_DRAFT_01_RREP:
a41ce5f
-		aodv_v6_draft_01_rrep(ndo, ap, dat, length);
a41ce5f
+		aodv_v6_draft_01_rrep(ndo, (const struct aodv_rrep6_draft_01 *)dat, dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_V6_DRAFT_01_RERR:
a41ce5f
-		aodv_v6_draft_01_rerr(ndo, ap, length);
a41ce5f
+		aodv_v6_draft_01_rerr(ndo, (const struct aodv_rerr *)dat, length);
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	case AODV_V6_DRAFT_01_RREP_ACK:
a41ce5f
@@ -615,6 +597,10 @@ aodv_print(netdissect_options *ndo,
a41ce5f
 		break;
a41ce5f
 
a41ce5f
 	default:
a41ce5f
-		ND_PRINT((ndo, " %u %u", ap->rreq.rreq_type, length));
a41ce5f
+		ND_PRINT((ndo, " type %u %u", msg_type, length));
a41ce5f
 	}
a41ce5f
+	return;
a41ce5f
+
a41ce5f
+trunc:
a41ce5f
+	ND_PRINT((ndo, " [|aodv]"));
a41ce5f
 }
a41ce5f
-- 
a41ce5f
1.8.3.1
a41ce5f