2 * Copyright (c) 2003 Bruce M. Simpson <bms@spc.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bruce M. Simpson.
16 * 4. Neither the name of Bruce M. Simpson nor the names of co-
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bruce M. Simpson AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bruce M. Simpson OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
37 #include <tcpdump-stdinc.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h" /* must come after interface.h */
50 u_int8_t rreq_type
; /* AODV message type (1) */
51 u_int8_t rreq_flags
; /* various flags */
52 u_int8_t rreq_zero0
; /* reserved, set to zero */
53 u_int8_t rreq_hops
; /* number of hops from originator */
54 u_int32_t rreq_id
; /* request ID */
55 u_int32_t rreq_da
; /* destination IPv4 address */
56 u_int32_t rreq_ds
; /* destination sequence number */
57 u_int32_t rreq_oa
; /* originator IPv4 address */
58 u_int32_t rreq_os
; /* originator sequence number */
62 u_int8_t rreq_type
; /* AODV message type (1) */
63 u_int8_t rreq_flags
; /* various flags */
64 u_int8_t rreq_zero0
; /* reserved, set to zero */
65 u_int8_t rreq_hops
; /* number of hops from originator */
66 u_int32_t rreq_id
; /* request ID */
67 struct in6_addr rreq_da
; /* destination IPv6 address */
68 u_int32_t rreq_ds
; /* destination sequence number */
69 struct in6_addr rreq_oa
; /* originator IPv6 address */
70 u_int32_t rreq_os
; /* originator sequence number */
72 struct aodv_rreq6_draft_01
{
73 u_int8_t rreq_type
; /* AODV message type (16) */
74 u_int8_t rreq_flags
; /* various flags */
75 u_int8_t rreq_zero0
; /* reserved, set to zero */
76 u_int8_t rreq_hops
; /* number of hops from originator */
77 u_int32_t rreq_id
; /* request ID */
78 u_int32_t rreq_ds
; /* destination sequence number */
79 u_int32_t rreq_os
; /* originator sequence number */
80 struct in6_addr rreq_da
; /* destination IPv6 address */
81 struct in6_addr rreq_oa
; /* originator IPv6 address */
85 #define RREQ_JOIN 0x80 /* join (reserved for multicast */
86 #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */
87 #define RREQ_GRAT 0x20 /* gratuitous RREP */
88 #define RREQ_DEST 0x10 /* destination only */
89 #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */
90 #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
93 u_int8_t rrep_type
; /* AODV message type (2) */
94 u_int8_t rrep_flags
; /* various flags */
95 u_int8_t rrep_ps
; /* prefix size */
96 u_int8_t rrep_hops
; /* number of hops from o to d */
97 u_int32_t rrep_da
; /* destination IPv4 address */
98 u_int32_t rrep_ds
; /* destination sequence number */
99 u_int32_t rrep_oa
; /* originator IPv4 address */
100 u_int32_t rrep_life
; /* lifetime of this route */
104 u_int8_t rrep_type
; /* AODV message type (2) */
105 u_int8_t rrep_flags
; /* various flags */
106 u_int8_t rrep_ps
; /* prefix size */
107 u_int8_t rrep_hops
; /* number of hops from o to d */
108 struct in6_addr rrep_da
; /* destination IPv6 address */
109 u_int32_t rrep_ds
; /* destination sequence number */
110 struct in6_addr rrep_oa
; /* originator IPv6 address */
111 u_int32_t rrep_life
; /* lifetime of this route */
113 struct aodv_rrep6_draft_01
{
114 u_int8_t rrep_type
; /* AODV message type (17) */
115 u_int8_t rrep_flags
; /* various flags */
116 u_int8_t rrep_ps
; /* prefix size */
117 u_int8_t rrep_hops
; /* number of hops from o to d */
118 u_int32_t rrep_ds
; /* destination sequence number */
119 struct in6_addr rrep_da
; /* destination IPv6 address */
120 struct in6_addr rrep_oa
; /* originator IPv6 address */
121 u_int32_t rrep_life
; /* lifetime of this route */
125 #define RREP_REPAIR 0x80 /* repair (reserved for multicast */
126 #define RREP_ACK 0x40 /* acknowledgement required */
127 #define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */
128 #define RREP_PREFIX_MASK 0x1F /* mask for prefix size */
130 struct rerr_unreach
{
131 u_int32_t u_da
; /* IPv4 address */
132 u_int32_t u_ds
; /* sequence number */
135 struct rerr_unreach6
{
136 struct in6_addr u_da
; /* IPv6 address */
137 u_int32_t u_ds
; /* sequence number */
139 struct rerr_unreach6_draft_01
{
140 struct in6_addr u_da
; /* IPv6 address */
141 u_int32_t u_ds
; /* sequence number */
146 u_int8_t rerr_type
; /* AODV message type (3 or 18) */
147 u_int8_t rerr_flags
; /* various flags */
148 u_int8_t rerr_zero0
; /* reserved, set to zero */
149 u_int8_t rerr_dc
; /* destination count */
151 struct rerr_unreach dest
[1];
153 struct rerr_unreach6 dest6
[1];
154 struct rerr_unreach6_draft_01 dest6_draft_01
[1];
159 #define RERR_NODELETE 0x80 /* don't delete the link */
160 #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
162 struct aodv_rrep_ack
{
168 struct aodv_rreq rreq
;
169 struct aodv_rrep rrep
;
170 struct aodv_rerr rerr
;
171 struct aodv_rrep_ack rrep_ack
;
173 struct aodv_rreq6 rreq6
;
174 struct aodv_rreq6_draft_01 rreq6_draft_01
;
175 struct aodv_rrep6 rrep6
;
176 struct aodv_rrep6_draft_01 rrep6_draft_01
;
180 #define AODV_RREQ 1 /* route request */
181 #define AODV_RREP 2 /* route response */
182 #define AODV_RERR 3 /* error report */
183 #define AODV_RREP_ACK 4 /* route response acknowledgement */
185 #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */
186 #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */
187 #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */
188 #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
191 u_int8_t type
; /* extension type */
192 u_int8_t length
; /* extension length */
196 struct aodv_ext eh
; /* extension header */
197 u_int8_t interval
[4]; /* expect my next hello in
199 * NOTE: this is not aligned */
202 #define AODV_EXT_HELLO 1
205 aodv_extension(const struct aodv_ext
*ep
, u_int length
)
208 const struct aodv_hello
*ah
;
212 if (snapend
< (u_char
*) ep
) {
216 i
= min(length
, (u_int
)(snapend
- (u_char
*)ep
));
217 if (i
< sizeof(struct aodv_hello
)) {
221 i
-= sizeof(struct aodv_hello
);
223 printf("\n\text HELLO %ld ms",
224 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
228 printf("\n\text %u %u", ep
->type
, ep
->length
);
234 aodv_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
242 i
= min(length
, (u_int
)(snapend
- dat
));
243 if (i
< sizeof(ap
->rreq
)) {
247 i
-= sizeof(ap
->rreq
);
248 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
249 "\tdst %s seq %lu src %s seq %lu", length
,
250 ap
->rreq
.rreq_type
& RREQ_JOIN
? "[J]" : "",
251 ap
->rreq
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
252 ap
->rreq
.rreq_type
& RREQ_GRAT
? "[G]" : "",
253 ap
->rreq
.rreq_type
& RREQ_DEST
? "[D]" : "",
254 ap
->rreq
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
256 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_id
),
257 ipaddr_string(&ap
->rreq
.rreq_da
),
258 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_ds
),
259 ipaddr_string(&ap
->rreq
.rreq_oa
),
260 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_os
));
261 if (i
>= sizeof(struct aodv_ext
))
262 aodv_extension((void *)(&ap
->rreq
+ 1), i
);
266 aodv_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
274 i
= min(length
, (u_int
)(snapend
- dat
));
275 if (i
< sizeof(ap
->rrep
)) {
279 i
-= sizeof(ap
->rrep
);
280 printf(" rrep %u %s%sprefix %u hops %u\n"
281 "\tdst %s dseq %lu src %s %lu ms", length
,
282 ap
->rrep
.rrep_type
& RREP_REPAIR
? "[R]" : "",
283 ap
->rrep
.rrep_type
& RREP_ACK
? "[A] " : " ",
284 ap
->rrep
.rrep_ps
& RREP_PREFIX_MASK
,
286 ipaddr_string(&ap
->rrep
.rrep_da
),
287 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_ds
),
288 ipaddr_string(&ap
->rrep
.rrep_oa
),
289 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_life
));
290 if (i
>= sizeof(struct aodv_ext
))
291 aodv_extension((void *)(&ap
->rrep
+ 1), i
);
295 aodv_rerr(const union aodv
*ap
, const u_char
*dat
, u_int length
)
298 const struct rerr_unreach
*dp
= NULL
;
305 i
= min(length
, (u_int
)(snapend
- dat
));
306 if (i
< offsetof(struct aodv_rerr
, r
)) {
310 i
-= offsetof(struct aodv_rerr
, r
);
311 dp
= &ap
->rerr
.r
.dest
[0];
312 n
= ap
->rerr
.rerr_dc
* sizeof(ap
->rerr
.r
.dest
[0]);
313 printf(" rerr %s [items %u] [%u]:",
314 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
315 ap
->rerr
.rerr_dc
, length
);
316 trunc
= n
- (i
/sizeof(ap
->rerr
.r
.dest
[0]));
317 for (; i
>= sizeof(ap
->rerr
.r
.dest
[0]);
318 ++dp
, i
-= sizeof(ap
->rerr
.r
.dest
[0])) {
319 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
320 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
328 aodv_v6_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
330 aodv_v6_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
340 i
= min(length
, (u_int
)(snapend
- dat
));
341 if (i
< sizeof(ap
->rreq6
)) {
345 i
-= sizeof(ap
->rreq6
);
346 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
347 "\tdst %s seq %lu src %s seq %lu", length
,
348 ap
->rreq6
.rreq_type
& RREQ_JOIN
? "[J]" : "",
349 ap
->rreq6
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
350 ap
->rreq6
.rreq_type
& RREQ_GRAT
? "[G]" : "",
351 ap
->rreq6
.rreq_type
& RREQ_DEST
? "[D]" : "",
352 ap
->rreq6
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
354 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_id
),
355 ip6addr_string(&ap
->rreq6
.rreq_da
),
356 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_ds
),
357 ip6addr_string(&ap
->rreq6
.rreq_oa
),
358 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_os
));
359 if (i
>= sizeof(struct aodv_ext
))
360 aodv_extension((void *)(&ap
->rreq6
+ 1), i
);
362 printf(" v6 rreq %u", length
);
368 aodv_v6_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
370 aodv_v6_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
380 i
= min(length
, (u_int
)(snapend
- dat
));
381 if (i
< sizeof(ap
->rrep6
)) {
385 i
-= sizeof(ap
->rrep6
);
386 printf(" rrep %u %s%sprefix %u hops %u\n"
387 "\tdst %s dseq %lu src %s %lu ms", length
,
388 ap
->rrep6
.rrep_type
& RREP_REPAIR
? "[R]" : "",
389 ap
->rrep6
.rrep_type
& RREP_ACK
? "[A] " : " ",
390 ap
->rrep6
.rrep_ps
& RREP_PREFIX_MASK
,
392 ip6addr_string(&ap
->rrep6
.rrep_da
),
393 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_ds
),
394 ip6addr_string(&ap
->rrep6
.rrep_oa
),
395 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_life
));
396 if (i
>= sizeof(struct aodv_ext
))
397 aodv_extension((void *)(&ap
->rrep6
+ 1), i
);
399 printf(" rrep %u", length
);
405 aodv_v6_rerr(const union aodv
*ap
, u_int length
)
407 aodv_v6_rerr(const union aodv
*ap _U_
, u_int length
)
411 const struct rerr_unreach6
*dp6
= NULL
;
414 i
= length
- offsetof(struct aodv_rerr
, r
);
415 j
= sizeof(ap
->rerr
.r
.dest6
[0]);
416 dp6
= &ap
->rerr
.r
.dest6
[0];
417 n
= ap
->rerr
.rerr_dc
* j
;
418 printf(" rerr %s [items %u] [%u]:",
419 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
420 ap
->rerr
.rerr_dc
, length
);
422 for (; i
-= j
>= 0; ++dp6
) {
423 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
424 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
429 printf(" rerr %u", length
);
435 aodv_v6_draft_01_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
437 aodv_v6_draft_01_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
,
448 i
= min(length
, (u_int
)(snapend
- dat
));
449 if (i
< sizeof(ap
->rreq6_draft_01
)) {
453 i
-= sizeof(ap
->rreq6_draft_01
);
454 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
455 "\tdst %s seq %lu src %s seq %lu", length
,
456 ap
->rreq6_draft_01
.rreq_type
& RREQ_JOIN
? "[J]" : "",
457 ap
->rreq6_draft_01
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
458 ap
->rreq6_draft_01
.rreq_type
& RREQ_GRAT
? "[G]" : "",
459 ap
->rreq6_draft_01
.rreq_type
& RREQ_DEST
? "[D]" : "",
460 ap
->rreq6_draft_01
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
461 ap
->rreq6_draft_01
.rreq_hops
,
462 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_id
),
463 ip6addr_string(&ap
->rreq6_draft_01
.rreq_da
),
464 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_ds
),
465 ip6addr_string(&ap
->rreq6_draft_01
.rreq_oa
),
466 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_os
));
467 if (i
>= sizeof(struct aodv_ext
))
468 aodv_extension((void *)(&ap
->rreq6_draft_01
+ 1), i
);
470 printf(" rreq %u", length
);
476 aodv_v6_draft_01_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
478 aodv_v6_draft_01_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
,
489 i
= min(length
, (u_int
)(snapend
- dat
));
490 if (i
< sizeof(ap
->rrep6_draft_01
)) {
494 i
-= sizeof(ap
->rrep6_draft_01
);
495 printf(" rrep %u %s%sprefix %u hops %u\n"
496 "\tdst %s dseq %lu src %s %lu ms", length
,
497 ap
->rrep6_draft_01
.rrep_type
& RREP_REPAIR
? "[R]" : "",
498 ap
->rrep6_draft_01
.rrep_type
& RREP_ACK
? "[A] " : " ",
499 ap
->rrep6_draft_01
.rrep_ps
& RREP_PREFIX_MASK
,
500 ap
->rrep6_draft_01
.rrep_hops
,
501 ip6addr_string(&ap
->rrep6_draft_01
.rrep_da
),
502 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_ds
),
503 ip6addr_string(&ap
->rrep6_draft_01
.rrep_oa
),
504 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_life
));
505 if (i
>= sizeof(struct aodv_ext
))
506 aodv_extension((void *)(&ap
->rrep6_draft_01
+ 1), i
);
508 printf(" rrep %u", length
);
514 aodv_v6_draft_01_rerr(const union aodv
*ap
, u_int length
)
516 aodv_v6_draft_01_rerr(const union aodv
*ap _U_
, u_int length
)
520 const struct rerr_unreach6_draft_01
*dp6
= NULL
;
523 i
= length
- offsetof(struct aodv_rerr
, r
);
524 j
= sizeof(ap
->rerr
.r
.dest6_draft_01
[0]);
525 dp6
= &ap
->rerr
.r
.dest6_draft_01
[0];
526 n
= ap
->rerr
.rerr_dc
* j
;
527 printf(" rerr %s [items %u] [%u]:",
528 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
529 ap
->rerr
.rerr_dc
, length
);
531 for (; i
-= j
>= 0; ++dp6
) {
532 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
533 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
538 printf(" rerr %u", length
);
543 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
545 const union aodv
*ap
;
547 ap
= (union aodv
*)dat
;
552 if (min(length
, (u_int
)(snapend
- dat
)) < sizeof(ap
->rrep_ack
)) {
558 switch (ap
->rerr
.rerr_type
) {
562 aodv_v6_rreq(ap
, dat
, length
);
564 aodv_rreq(ap
, dat
, length
);
569 aodv_v6_rrep(ap
, dat
, length
);
571 aodv_rrep(ap
, dat
, length
);
576 aodv_v6_rerr(ap
, length
);
578 aodv_rerr(ap
, dat
, length
);
582 printf(" rrep-ack %u", length
);
585 case AODV_V6_DRAFT_01_RREQ
:
586 aodv_v6_draft_01_rreq(ap
, dat
, length
);
589 case AODV_V6_DRAFT_01_RREP
:
590 aodv_v6_draft_01_rrep(ap
, dat
, length
);
593 case AODV_V6_DRAFT_01_RERR
:
594 aodv_v6_draft_01_rerr(ap
, length
);
597 case AODV_V6_DRAFT_01_RREP_ACK
:
598 printf(" rrep-ack %u", length
);
602 printf(" %u %u", ap
->rreq
.rreq_type
, length
);