|
|
a41ce5f |
From e302ff0e4a6bde6915bee1c89373aa14c823dd60 Mon Sep 17 00:00:00 2001
|
|
|
a41ce5f |
From: Guy Harris <guy@alum.mit.edu>
|
|
|
a41ce5f |
Date: Tue, 11 Nov 2014 19:05:48 -0800
|
|
|
a41ce5f |
Subject: [PATCH 2/4] Further cleanups.
|
|
|
a41ce5f |
|
|
|
a41ce5f |
Use ND_TCHECK() rather than home-brew bounds checks. Do simpler length
|
|
|
a41ce5f |
checks.
|
|
|
a41ce5f |
|
|
|
a41ce5f |
Let i be the length of the actual remaining packet data; use ND_TCHECK()
|
|
|
a41ce5f |
inside loops that iterate over the remaining data.
|
|
|
a41ce5f |
|
|
|
a41ce5f |
Let the printers for particular message types cast the raw data pointer
|
|
|
a41ce5f |
to a pointer of the appropriate type, rather than passing two pointers,
|
|
|
a41ce5f |
with different types, to the same data.
|
|
|
a41ce5f |
---
|
|
|
a41ce5f |
print-aodv.c | 277 +++++++++++++++++++++++++++--------------------------------
|
|
|
a41ce5f |
1 file changed, 126 insertions(+), 151 deletions(-)
|
|
|
a41ce5f |
|
|
|
a41ce5f |
diff --git a/print-aodv.c b/print-aodv.c
|
|
|
a41ce5f |
index da26473..2649936 100644
|
|
|
a41ce5f |
--- a/print-aodv.c
|
|
|
a41ce5f |
+++ b/print-aodv.c
|
|
|
a41ce5f |
@@ -184,22 +184,14 @@ static void
|
|
|
a41ce5f |
aodv_extension(netdissect_options *ndo,
|
|
|
a41ce5f |
const struct aodv_ext *ep, u_int length)
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
- u_int i;
|
|
|
a41ce5f |
const struct aodv_hello *ah;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
switch (ep->type) {
|
|
|
a41ce5f |
case AODV_EXT_HELLO:
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < (u_char *) ep) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|hello]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - (u_char *)ep));
|
|
|
a41ce5f |
- if (i < sizeof(struct aodv_hello)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|hello]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(struct aodv_hello);
|
|
|
a41ce5f |
- ah = (void *)ep;
|
|
|
a41ce5f |
+ ah = (const struct aodv_hello *)(const void *)ep;
|
|
|
a41ce5f |
+ ND_TCHECK(*ah);
|
|
|
a41ce5f |
+ if (length < sizeof(struct aodv_hello))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
ND_PRINT((ndo, "\n\text HELLO %ld ms",
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ah->interval)));
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
@@ -208,24 +200,21 @@ aodv_extension(netdissect_options *ndo,
|
|
|
a41ce5f |
ND_PRINT((ndo, "\n\text %u %u", ep->type, ep->length));
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|hello]"));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
-aodv_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rreq *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rreq *ap = (const struct aodv_rreq *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rreq]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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_type & RREQ_JOIN ? "[J]" : "",
|
|
|
a41ce5f |
@@ -239,26 +228,24 @@ aodv_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
|
|
|
a41ce5f |
ipaddr_string(ndo, &ap->rreq_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
-aodv_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rrep *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rrep *ap = (const struct aodv_rrep *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rrep]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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_type & RREP_REPAIR ? "[R]" : "",
|
|
|
a41ce5f |
@@ -269,62 +256,58 @@ aodv_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
|
|
|
a41ce5f |
ipaddr_string(ndo, &ap->rrep_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
-aodv_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rerr *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
u_int i, dc;
|
|
|
a41ce5f |
+ const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
|
|
|
a41ce5f |
const struct rerr_unreach *dp;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rerr]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
|
|
|
a41ce5f |
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
|
|
|
a41ce5f |
ap->rerr_dc, length));
|
|
|
a41ce5f |
- dp = (struct rerr_unreach *)(void *)(ap + 1);
|
|
|
a41ce5f |
+ dp = (struct rerr_unreach *)(dat + sizeof(*ap));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
for (dc = ap->rerr_dc; dc != 0 && i >= sizeof(*dp);
|
|
|
a41ce5f |
++dp, --dc, i -= sizeof(*dp)) {
|
|
|
a41ce5f |
+ ND_TCHECK(*dp);
|
|
|
a41ce5f |
ND_PRINT((ndo, " {%s}(%ld)", ipaddr_string(ndo, &dp->u_da),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&dp->u_ds)));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
if ((i % sizeof(*dp)) != 0)
|
|
|
a41ce5f |
- ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rreq6 *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rreq6 *ap _U_, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rreq(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rreq6 *ap = (const struct aodv_rreq6 *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rreq6]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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->rreq_type & RREQ_JOIN ? "[J]" : "",
|
|
|
a41ce5f |
@@ -338,8 +321,13 @@ aodv_v6_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
|
|
|
a41ce5f |
ip6addr_string(ndo, &ap->rreq_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " v6 rreq %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -347,26 +335,18 @@ aodv_v6_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rrep6 *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rrep6 *ap _U_, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rrep(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rrep6 *ap = (const struct aodv_rrep6 *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rrep6]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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_type & RREP_REPAIR ? "[R]" : "",
|
|
|
a41ce5f |
@@ -377,8 +357,13 @@ aodv_v6_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
|
|
|
a41ce5f |
ip6addr_string(ndo, &ap->rrep_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " rrep %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -386,38 +371,36 @@ aodv_v6_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rerr *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rerr *ap _U_, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_rerr(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i, dc;
|
|
|
a41ce5f |
+ const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
|
|
|
a41ce5f |
const struct rerr_unreach6 *dp6;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rerr]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
|
|
|
a41ce5f |
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
|
|
|
a41ce5f |
ap->rerr_dc, length));
|
|
|
a41ce5f |
dp6 = (struct rerr_unreach6 *)(void *)(ap + 1);
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
for (dc = ap->rerr_dc; dc != 0 && i >= sizeof(*dp6);
|
|
|
a41ce5f |
++dp6, --dc, i -= sizeof(*dp6)) {
|
|
|
a41ce5f |
+ ND_TCHECK(*dp6);
|
|
|
a41ce5f |
ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
if ((i % sizeof(*dp6)) != 0)
|
|
|
a41ce5f |
- ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " rerr %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -425,26 +408,18 @@ aodv_v6_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_draft_01_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rreq6_draft_01 *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rreq(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_draft_01_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rreq6_draft_01 *ap _U_, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rreq(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rreq6_draft_01 *ap = (const struct aodv_rreq6_draft_01 *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rreq6]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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_type & RREQ_JOIN ? "[J]" : "",
|
|
|
a41ce5f |
@@ -458,8 +433,13 @@ aodv_v6_draft_01_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_ds),
|
|
|
a41ce5f |
ip6addr_string(ndo, &ap->rreq_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rreq_os)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " rreq %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -467,26 +447,18 @@ aodv_v6_draft_01_rreq(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_draft_01_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rrep6_draft_01 *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rrep(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_draft_01_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rrep6_draft_01 *ap _U_, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rrep(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i;
|
|
|
a41ce5f |
+ const struct aodv_rrep6_draft_01 *ap = (const struct aodv_rrep6_draft_01 *)dat;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rrep6]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
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_type & RREP_REPAIR ? "[R]" : "",
|
|
|
a41ce5f |
@@ -497,8 +469,13 @@ aodv_v6_draft_01_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_ds),
|
|
|
a41ce5f |
ip6addr_string(ndo, &ap->rrep_oa),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&ap->rrep_life)));
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
if (i >= sizeof(struct aodv_ext))
|
|
|
a41ce5f |
- aodv_extension(ndo, (void *)(ap + 1), i);
|
|
|
a41ce5f |
+ aodv_extension(ndo, (const struct aodv_ext *)(dat + sizeof(*ap)), i);
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, " [|rreq"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " rrep %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -506,38 +483,36 @@ aodv_v6_draft_01_rrep(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
static void
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
-aodv_v6_draft_01_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rerr *ap, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rerr(netdissect_options *ndo, const u_char *dat, u_int length)
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
-aodv_v6_draft_01_rerr(netdissect_options *ndo,
|
|
|
a41ce5f |
- const struct aodv_rerr *ap _U_, const u_char *dat, u_int length)
|
|
|
a41ce5f |
+aodv_v6_draft_01_rerr(netdissect_options *ndo, const u_char *dat _U_, u_int length)
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
{
|
|
|
a41ce5f |
#ifdef INET6
|
|
|
a41ce5f |
u_int i, dc;
|
|
|
a41ce5f |
+ const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
|
|
|
a41ce5f |
const struct rerr_unreach6_draft_01 *dp6;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
- if (ndo->ndo_snapend < dat) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|aodv]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i = min(length, (u_int)(ndo->ndo_snapend - dat));
|
|
|
a41ce5f |
- if (i < sizeof(*ap)) {
|
|
|
a41ce5f |
- ND_PRINT((ndo, " [|rerr]"));
|
|
|
a41ce5f |
- return;
|
|
|
a41ce5f |
- }
|
|
|
a41ce5f |
- i -= sizeof(*ap);
|
|
|
a41ce5f |
+ ND_TCHECK(*ap);
|
|
|
a41ce5f |
+ if (length < sizeof(*ap))
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
ND_PRINT((ndo, " rerr %s [items %u] [%u]:",
|
|
|
a41ce5f |
ap->rerr_flags & RERR_NODELETE ? "[D]" : "",
|
|
|
a41ce5f |
ap->rerr_dc, length));
|
|
|
a41ce5f |
dp6 = (struct rerr_unreach6_draft_01 *)(void *)(ap + 1);
|
|
|
a41ce5f |
+ i = length - sizeof(*ap);
|
|
|
a41ce5f |
for (dc = ap->rerr_dc; dc != 0 && i >= sizeof(*dp6);
|
|
|
a41ce5f |
++dp6, --dc, i -= sizeof(*dp6)) {
|
|
|
a41ce5f |
+ ND_TCHECK(*dp6);
|
|
|
a41ce5f |
ND_PRINT((ndo, " {%s}(%ld)", ip6addr_string(ndo, &dp6->u_da),
|
|
|
a41ce5f |
(unsigned long)EXTRACT_32BITS(&dp6->u_ds)));
|
|
|
a41ce5f |
}
|
|
|
a41ce5f |
if ((i % sizeof(*dp6)) != 0)
|
|
|
a41ce5f |
- ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
+ goto trunc;
|
|
|
a41ce5f |
+ return;
|
|
|
a41ce5f |
+
|
|
|
a41ce5f |
+trunc:
|
|
|
a41ce5f |
+ ND_PRINT((ndo, "[|rerr]"));
|
|
|
a41ce5f |
#else
|
|
|
a41ce5f |
ND_PRINT((ndo, " rerr %u", length));
|
|
|
a41ce5f |
#endif
|
|
|
a41ce5f |
@@ -561,23 +536,23 @@ aodv_print(netdissect_options *ndo,
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_RREQ:
|
|
|
a41ce5f |
if (is_ip6)
|
|
|
a41ce5f |
- aodv_v6_rreq(ndo, (const struct aodv_rreq6 *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_rreq(ndo, dat, length);
|
|
|
a41ce5f |
else
|
|
|
a41ce5f |
- aodv_rreq(ndo, (const struct aodv_rreq *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_rreq(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_RREP:
|
|
|
a41ce5f |
if (is_ip6)
|
|
|
a41ce5f |
- aodv_v6_rrep(ndo, (const struct aodv_rrep6 *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_rrep(ndo, dat, length);
|
|
|
a41ce5f |
else
|
|
|
a41ce5f |
- aodv_rrep(ndo, (const struct aodv_rrep *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_rrep(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_RERR:
|
|
|
a41ce5f |
if (is_ip6)
|
|
|
a41ce5f |
- aodv_v6_rerr(ndo, (const struct aodv_rerr *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_rerr(ndo, dat, length);
|
|
|
a41ce5f |
else
|
|
|
a41ce5f |
- aodv_rerr(ndo, (const struct aodv_rerr *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_rerr(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_RREP_ACK:
|
|
|
a41ce5f |
@@ -585,15 +560,15 @@ aodv_print(netdissect_options *ndo,
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_V6_DRAFT_01_RREQ:
|
|
|
a41ce5f |
- aodv_v6_draft_01_rreq(ndo, (const struct aodv_rreq6_draft_01 *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_draft_01_rreq(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_V6_DRAFT_01_RREP:
|
|
|
a41ce5f |
- aodv_v6_draft_01_rrep(ndo, (const struct aodv_rrep6_draft_01 *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_draft_01_rrep(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_V6_DRAFT_01_RERR:
|
|
|
a41ce5f |
- aodv_v6_draft_01_rerr(ndo, (const struct aodv_rerr *)dat, dat, length);
|
|
|
a41ce5f |
+ aodv_v6_draft_01_rerr(ndo, dat, length);
|
|
|
a41ce5f |
break;
|
|
|
a41ce5f |
|
|
|
a41ce5f |
case AODV_V6_DRAFT_01_RREP_ACK:
|
|
|
a41ce5f |
--
|
|
|
a41ce5f |
1.8.3.1
|
|
|
a41ce5f |
|