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_int32_t interval
; /* expect my next hello in
201 #define AODV_EXT_HELLO 1
204 aodv_extension(const struct aodv_ext
*ep
, u_int length
)
207 const struct aodv_hello
*ah
;
211 if (snapend
< (u_char
*) ep
) {
215 i
= min(length
, (u_int
)(snapend
- (u_char
*)ep
));
216 if (i
< sizeof(struct aodv_hello
)) {
220 i
-= sizeof(struct aodv_hello
);
222 printf("\n\text HELLO %ld ms",
223 (unsigned long)EXTRACT_32BITS(&ah
->interval
));
227 printf("\n\text %u %u", ep
->type
, ep
->length
);
233 aodv_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
241 i
= min(length
, (u_int
)(snapend
- dat
));
242 if (i
< sizeof(ap
->rreq
)) {
246 i
-= sizeof(ap
->rreq
);
247 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
248 "\tdst %s seq %lu src %s seq %lu", length
,
249 ap
->rreq
.rreq_type
& RREQ_JOIN
? "[J]" : "",
250 ap
->rreq
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
251 ap
->rreq
.rreq_type
& RREQ_GRAT
? "[G]" : "",
252 ap
->rreq
.rreq_type
& RREQ_DEST
? "[D]" : "",
253 ap
->rreq
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
255 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_id
),
256 ipaddr_string(&ap
->rreq
.rreq_da
),
257 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_ds
),
258 ipaddr_string(&ap
->rreq
.rreq_oa
),
259 (unsigned long)EXTRACT_32BITS(&ap
->rreq
.rreq_os
));
260 if (i
>= sizeof(struct aodv_ext
))
261 aodv_extension((void *)(&ap
->rreq
+ 1), i
);
265 aodv_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
273 i
= min(length
, (u_int
)(snapend
- dat
));
274 if (i
< sizeof(ap
->rrep
)) {
278 i
-= sizeof(ap
->rrep
);
279 printf(" rrep %u %s%sprefix %u hops %u\n"
280 "\tdst %s dseq %lu src %s %lu ms", length
,
281 ap
->rrep
.rrep_type
& RREP_REPAIR
? "[R]" : "",
282 ap
->rrep
.rrep_type
& RREP_ACK
? "[A] " : " ",
283 ap
->rrep
.rrep_ps
& RREP_PREFIX_MASK
,
285 ipaddr_string(&ap
->rrep
.rrep_da
),
286 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_ds
),
287 ipaddr_string(&ap
->rrep
.rrep_oa
),
288 (unsigned long)EXTRACT_32BITS(&ap
->rrep
.rrep_life
));
289 if (i
>= sizeof(struct aodv_ext
))
290 aodv_extension((void *)(&ap
->rrep
+ 1), i
);
294 aodv_rerr(const union aodv
*ap
, const u_char
*dat
, u_int length
)
297 const struct rerr_unreach
*dp
= NULL
;
304 i
= min(length
, (u_int
)(snapend
- dat
));
305 if (i
< offsetof(struct aodv_rerr
, r
)) {
309 i
-= offsetof(struct aodv_rerr
, r
);
310 dp
= &ap
->rerr
.r
.dest
[0];
311 n
= ap
->rerr
.rerr_dc
* sizeof(ap
->rerr
.r
.dest
[0]);
312 printf(" rerr %s [items %u] [%u]:",
313 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
314 ap
->rerr
.rerr_dc
, length
);
315 trunc
= n
- (i
/sizeof(ap
->rerr
.r
.dest
[0]));
316 for (; i
>= sizeof(ap
->rerr
.r
.dest
[0]);
317 ++dp
, i
-= sizeof(ap
->rerr
.r
.dest
[0])) {
318 printf(" {%s}(%ld)", ipaddr_string(&dp
->u_da
),
319 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
));
327 aodv_v6_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
329 aodv_v6_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
339 i
= min(length
, (u_int
)(snapend
- dat
));
340 if (i
< sizeof(ap
->rreq6
)) {
344 i
-= sizeof(ap
->rreq6
);
345 printf(" v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
346 "\tdst %s seq %lu src %s seq %lu", length
,
347 ap
->rreq6
.rreq_type
& RREQ_JOIN
? "[J]" : "",
348 ap
->rreq6
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
349 ap
->rreq6
.rreq_type
& RREQ_GRAT
? "[G]" : "",
350 ap
->rreq6
.rreq_type
& RREQ_DEST
? "[D]" : "",
351 ap
->rreq6
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
353 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_id
),
354 ip6addr_string(&ap
->rreq6
.rreq_da
),
355 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_ds
),
356 ip6addr_string(&ap
->rreq6
.rreq_oa
),
357 (unsigned long)EXTRACT_32BITS(&ap
->rreq6
.rreq_os
));
358 if (i
>= sizeof(struct aodv_ext
))
359 aodv_extension((void *)(&ap
->rreq6
+ 1), i
);
361 printf(" v6 rreq %u", length
);
367 aodv_v6_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
369 aodv_v6_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
, u_int length
)
379 i
= min(length
, (u_int
)(snapend
- dat
));
380 if (i
< sizeof(ap
->rrep6
)) {
384 i
-= sizeof(ap
->rrep6
);
385 printf(" rrep %u %s%sprefix %u hops %u\n"
386 "\tdst %s dseq %lu src %s %lu ms", length
,
387 ap
->rrep6
.rrep_type
& RREP_REPAIR
? "[R]" : "",
388 ap
->rrep6
.rrep_type
& RREP_ACK
? "[A] " : " ",
389 ap
->rrep6
.rrep_ps
& RREP_PREFIX_MASK
,
391 ip6addr_string(&ap
->rrep6
.rrep_da
),
392 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_ds
),
393 ip6addr_string(&ap
->rrep6
.rrep_oa
),
394 (unsigned long)EXTRACT_32BITS(&ap
->rrep6
.rrep_life
));
395 if (i
>= sizeof(struct aodv_ext
))
396 aodv_extension((void *)(&ap
->rrep6
+ 1), i
);
398 printf(" rrep %u", length
);
404 aodv_v6_rerr(const union aodv
*ap
, u_int length
)
406 aodv_v6_rerr(const union aodv
*ap _U_
, u_int length
)
410 const struct rerr_unreach6
*dp6
= NULL
;
413 i
= length
- offsetof(struct aodv_rerr
, r
);
414 j
= sizeof(ap
->rerr
.r
.dest6
[0]);
415 dp6
= &ap
->rerr
.r
.dest6
[0];
416 n
= ap
->rerr
.rerr_dc
* j
;
417 printf(" rerr %s [items %u] [%u]:",
418 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
419 ap
->rerr
.rerr_dc
, length
);
421 for (; i
-= j
>= 0; ++dp6
) {
422 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
423 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
428 printf(" rerr %u", length
);
434 aodv_v6_draft_01_rreq(const union aodv
*ap
, const u_char
*dat
, u_int length
)
436 aodv_v6_draft_01_rreq(const union aodv
*ap _U_
, const u_char
*dat _U_
,
447 i
= min(length
, (u_int
)(snapend
- dat
));
448 if (i
< sizeof(ap
->rreq6_draft_01
)) {
452 i
-= sizeof(ap
->rreq6_draft_01
);
453 printf(" rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
454 "\tdst %s seq %lu src %s seq %lu", length
,
455 ap
->rreq6_draft_01
.rreq_type
& RREQ_JOIN
? "[J]" : "",
456 ap
->rreq6_draft_01
.rreq_type
& RREQ_REPAIR
? "[R]" : "",
457 ap
->rreq6_draft_01
.rreq_type
& RREQ_GRAT
? "[G]" : "",
458 ap
->rreq6_draft_01
.rreq_type
& RREQ_DEST
? "[D]" : "",
459 ap
->rreq6_draft_01
.rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
460 ap
->rreq6_draft_01
.rreq_hops
,
461 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_id
),
462 ip6addr_string(&ap
->rreq6_draft_01
.rreq_da
),
463 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_ds
),
464 ip6addr_string(&ap
->rreq6_draft_01
.rreq_oa
),
465 (unsigned long)EXTRACT_32BITS(&ap
->rreq6_draft_01
.rreq_os
));
466 if (i
>= sizeof(struct aodv_ext
))
467 aodv_extension((void *)(&ap
->rreq6_draft_01
+ 1), i
);
469 printf(" rreq %u", length
);
475 aodv_v6_draft_01_rrep(const union aodv
*ap
, const u_char
*dat
, u_int length
)
477 aodv_v6_draft_01_rrep(const union aodv
*ap _U_
, const u_char
*dat _U_
,
488 i
= min(length
, (u_int
)(snapend
- dat
));
489 if (i
< sizeof(ap
->rrep6_draft_01
)) {
493 i
-= sizeof(ap
->rrep6_draft_01
);
494 printf(" rrep %u %s%sprefix %u hops %u\n"
495 "\tdst %s dseq %lu src %s %lu ms", length
,
496 ap
->rrep6_draft_01
.rrep_type
& RREP_REPAIR
? "[R]" : "",
497 ap
->rrep6_draft_01
.rrep_type
& RREP_ACK
? "[A] " : " ",
498 ap
->rrep6_draft_01
.rrep_ps
& RREP_PREFIX_MASK
,
499 ap
->rrep6_draft_01
.rrep_hops
,
500 ip6addr_string(&ap
->rrep6_draft_01
.rrep_da
),
501 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_ds
),
502 ip6addr_string(&ap
->rrep6_draft_01
.rrep_oa
),
503 (unsigned long)EXTRACT_32BITS(&ap
->rrep6_draft_01
.rrep_life
));
504 if (i
>= sizeof(struct aodv_ext
))
505 aodv_extension((void *)(&ap
->rrep6_draft_01
+ 1), i
);
507 printf(" rrep %u", length
);
513 aodv_v6_draft_01_rerr(const union aodv
*ap
, u_int length
)
515 aodv_v6_draft_01_rerr(const union aodv
*ap _U_
, u_int length
)
519 const struct rerr_unreach6_draft_01
*dp6
= NULL
;
522 i
= length
- offsetof(struct aodv_rerr
, r
);
523 j
= sizeof(ap
->rerr
.r
.dest6_draft_01
[0]);
524 dp6
= &ap
->rerr
.r
.dest6_draft_01
[0];
525 n
= ap
->rerr
.rerr_dc
* j
;
526 printf(" rerr %s [items %u] [%u]:",
527 ap
->rerr
.rerr_flags
& RERR_NODELETE
? "[D]" : "",
528 ap
->rerr
.rerr_dc
, length
);
530 for (; i
-= j
>= 0; ++dp6
) {
531 printf(" {%s}(%ld)", ip6addr_string(&dp6
->u_da
),
532 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
));
537 printf(" rerr %u", length
);
542 aodv_print(const u_char
*dat
, u_int length
, int is_ip6
)
544 const union aodv
*ap
;
546 ap
= (union aodv
*)dat
;
551 if (min(length
, (u_int
)(snapend
- dat
)) < sizeof(ap
->rrep_ack
)) {
557 switch (ap
->rerr
.rerr_type
) {
561 aodv_v6_rreq(ap
, dat
, length
);
563 aodv_rreq(ap
, dat
, length
);
568 aodv_v6_rrep(ap
, dat
, length
);
570 aodv_rrep(ap
, dat
, length
);
575 aodv_v6_rerr(ap
, length
);
577 aodv_rerr(ap
, dat
, length
);
581 printf(" rrep-ack %u", length
);
584 case AODV_V6_DRAFT_01_RREQ
:
585 aodv_v6_draft_01_rreq(ap
, dat
, length
);
588 case AODV_V6_DRAFT_01_RREP
:
589 aodv_v6_draft_01_rrep(ap
, dat
, length
);
592 case AODV_V6_DRAFT_01_RERR
:
593 aodv_v6_draft_01_rerr(ap
, length
);
596 case AODV_V6_DRAFT_01_RREP_ACK
:
597 printf(" rrep-ack %u", length
);
601 printf(" %u %u", ap
->rreq
.rreq_type
, length
);