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.
33 #define NETDISSECT_REWORKED
38 #include <tcpdump-stdinc.h>
40 #include "interface.h"
41 #include "addrtoname.h"
42 #include "extract.h" /* must come after interface.h */
46 uint8_t rreq_type
; /* AODV message type (1) */
47 uint8_t rreq_flags
; /* various flags */
48 uint8_t rreq_zero0
; /* reserved, set to zero */
49 uint8_t rreq_hops
; /* number of hops from originator */
50 uint32_t rreq_id
; /* request ID */
51 uint32_t rreq_da
; /* destination IPv4 address */
52 uint32_t rreq_ds
; /* destination sequence number */
53 uint32_t rreq_oa
; /* originator IPv4 address */
54 uint32_t rreq_os
; /* originator sequence number */
58 uint8_t rreq_type
; /* AODV message type (1) */
59 uint8_t rreq_flags
; /* various flags */
60 uint8_t rreq_zero0
; /* reserved, set to zero */
61 uint8_t rreq_hops
; /* number of hops from originator */
62 uint32_t rreq_id
; /* request ID */
63 struct in6_addr rreq_da
; /* destination IPv6 address */
64 uint32_t rreq_ds
; /* destination sequence number */
65 struct in6_addr rreq_oa
; /* originator IPv6 address */
66 uint32_t rreq_os
; /* originator sequence number */
68 struct aodv_rreq6_draft_01
{
69 uint8_t rreq_type
; /* AODV message type (16) */
70 uint8_t rreq_flags
; /* various flags */
71 uint8_t rreq_zero0
; /* reserved, set to zero */
72 uint8_t rreq_hops
; /* number of hops from originator */
73 uint32_t rreq_id
; /* request ID */
74 uint32_t rreq_ds
; /* destination sequence number */
75 uint32_t rreq_os
; /* originator sequence number */
76 struct in6_addr rreq_da
; /* destination IPv6 address */
77 struct in6_addr rreq_oa
; /* originator IPv6 address */
81 #define RREQ_JOIN 0x80 /* join (reserved for multicast */
82 #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */
83 #define RREQ_GRAT 0x20 /* gratuitous RREP */
84 #define RREQ_DEST 0x10 /* destination only */
85 #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */
86 #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
89 uint8_t rrep_type
; /* AODV message type (2) */
90 uint8_t rrep_flags
; /* various flags */
91 uint8_t rrep_ps
; /* prefix size */
92 uint8_t rrep_hops
; /* number of hops from o to d */
93 uint32_t rrep_da
; /* destination IPv4 address */
94 uint32_t rrep_ds
; /* destination sequence number */
95 uint32_t rrep_oa
; /* originator IPv4 address */
96 uint32_t rrep_life
; /* lifetime of this route */
100 uint8_t rrep_type
; /* AODV message type (2) */
101 uint8_t rrep_flags
; /* various flags */
102 uint8_t rrep_ps
; /* prefix size */
103 uint8_t rrep_hops
; /* number of hops from o to d */
104 struct in6_addr rrep_da
; /* destination IPv6 address */
105 uint32_t rrep_ds
; /* destination sequence number */
106 struct in6_addr rrep_oa
; /* originator IPv6 address */
107 uint32_t rrep_life
; /* lifetime of this route */
109 struct aodv_rrep6_draft_01
{
110 uint8_t rrep_type
; /* AODV message type (17) */
111 uint8_t rrep_flags
; /* various flags */
112 uint8_t rrep_ps
; /* prefix size */
113 uint8_t rrep_hops
; /* number of hops from o to d */
114 uint32_t rrep_ds
; /* destination sequence number */
115 struct in6_addr rrep_da
; /* destination IPv6 address */
116 struct in6_addr rrep_oa
; /* originator IPv6 address */
117 uint32_t rrep_life
; /* lifetime of this route */
121 #define RREP_REPAIR 0x80 /* repair (reserved for multicast */
122 #define RREP_ACK 0x40 /* acknowledgement required */
123 #define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */
124 #define RREP_PREFIX_MASK 0x1F /* mask for prefix size */
126 struct rerr_unreach
{
127 uint32_t u_da
; /* IPv4 address */
128 uint32_t u_ds
; /* sequence number */
131 struct rerr_unreach6
{
132 struct in6_addr u_da
; /* IPv6 address */
133 uint32_t u_ds
; /* sequence number */
135 struct rerr_unreach6_draft_01
{
136 struct in6_addr u_da
; /* IPv6 address */
137 uint32_t u_ds
; /* sequence number */
142 uint8_t rerr_type
; /* AODV message type (3 or 18) */
143 uint8_t rerr_flags
; /* various flags */
144 uint8_t rerr_zero0
; /* reserved, set to zero */
145 uint8_t rerr_dc
; /* destination count */
148 #define RERR_NODELETE 0x80 /* don't delete the link */
149 #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
151 struct aodv_rrep_ack
{
156 #define AODV_RREQ 1 /* route request */
157 #define AODV_RREP 2 /* route response */
158 #define AODV_RERR 3 /* error report */
159 #define AODV_RREP_ACK 4 /* route response acknowledgement */
161 #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */
162 #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */
163 #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */
164 #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
167 uint8_t type
; /* extension type */
168 uint8_t length
; /* extension length */
172 struct aodv_ext eh
; /* extension header */
173 uint8_t interval
[4]; /* expect my next hello in
175 * NOTE: this is not aligned */
178 #define AODV_EXT_HELLO 1
181 aodv_extension(netdissect_options
*ndo
,
182 const struct aodv_ext
*ep
, u_int length
)
184 const struct aodv_hello
*ah
;
188 ah
= (const struct aodv_hello
*)(const void *)ep
;
190 if (length
< sizeof(struct aodv_hello
))
192 ND_PRINT((ndo
, "\n\text HELLO %ld ms",
193 (unsigned long)EXTRACT_32BITS(&ah
->interval
)));
197 ND_PRINT((ndo
, "\n\text %u %u", ep
->type
, ep
->length
));
203 ND_PRINT((ndo
, " [|hello]"));
207 aodv_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
210 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
213 if (length
< sizeof(*ap
))
215 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
216 "\tdst %s seq %lu src %s seq %lu", length
,
217 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
218 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
219 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
220 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
221 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
223 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
224 ipaddr_string(ndo
, &ap
->rreq_da
),
225 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
226 ipaddr_string(ndo
, &ap
->rreq_oa
),
227 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
228 i
= length
- sizeof(*ap
);
229 if (i
>= sizeof(struct aodv_ext
))
230 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
234 ND_PRINT((ndo
, " [|rreq"));
238 aodv_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
241 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
244 if (length
< sizeof(*ap
))
246 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
247 "\tdst %s dseq %lu src %s %lu ms", length
,
248 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
249 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
250 ap
->rrep_ps
& RREP_PREFIX_MASK
,
252 ipaddr_string(ndo
, &ap
->rrep_da
),
253 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
254 ipaddr_string(ndo
, &ap
->rrep_oa
),
255 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
256 i
= length
- sizeof(*ap
);
257 if (i
>= sizeof(struct aodv_ext
))
258 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
262 ND_PRINT((ndo
, " [|rreq"));
266 aodv_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
269 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
270 const struct rerr_unreach
*dp
;
273 if (length
< sizeof(*ap
))
275 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
276 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
277 ap
->rerr_dc
, length
));
278 dp
= (struct rerr_unreach
*)(dat
+ sizeof(*ap
));
279 i
= length
- sizeof(*ap
);
280 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
284 ND_PRINT((ndo
, " {%s}(%ld)", ipaddr_string(ndo
, &dp
->u_da
),
285 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
)));
292 ND_PRINT((ndo
, "[|rerr]"));
297 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
299 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
304 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
307 if (length
< sizeof(*ap
))
309 ND_PRINT((ndo
, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
310 "\tdst %s seq %lu src %s seq %lu", length
,
311 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
312 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
313 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
314 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
315 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
317 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
318 ip6addr_string(ndo
, &ap
->rreq_da
),
319 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
320 ip6addr_string(ndo
, &ap
->rreq_oa
),
321 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
322 i
= length
- sizeof(*ap
);
323 if (i
>= sizeof(struct aodv_ext
))
324 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
328 ND_PRINT((ndo
, " [|rreq"));
330 ND_PRINT((ndo
, " v6 rreq %u", length
));
336 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
338 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
343 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
346 if (length
< sizeof(*ap
))
348 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
349 "\tdst %s dseq %lu src %s %lu ms", length
,
350 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
351 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
352 ap
->rrep_ps
& RREP_PREFIX_MASK
,
354 ip6addr_string(ndo
, &ap
->rrep_da
),
355 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
356 ip6addr_string(ndo
, &ap
->rrep_oa
),
357 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
358 i
= length
- sizeof(*ap
);
359 if (i
>= sizeof(struct aodv_ext
))
360 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
364 ND_PRINT((ndo
, " [|rreq"));
366 ND_PRINT((ndo
, " rrep %u", length
));
372 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
374 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
379 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
380 const struct rerr_unreach6
*dp6
;
383 if (length
< sizeof(*ap
))
385 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
386 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
387 ap
->rerr_dc
, length
));
388 dp6
= (struct rerr_unreach6
*)(void *)(ap
+ 1);
389 i
= length
- sizeof(*ap
);
390 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
392 if (i
< sizeof(*dp6
))
394 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
395 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
402 ND_PRINT((ndo
, "[|rerr]"));
404 ND_PRINT((ndo
, " rerr %u", length
));
410 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
412 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
417 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
420 if (length
< sizeof(*ap
))
422 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
423 "\tdst %s seq %lu src %s seq %lu", length
,
424 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
425 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
426 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
427 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
428 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
430 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
431 ip6addr_string(ndo
, &ap
->rreq_da
),
432 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
433 ip6addr_string(ndo
, &ap
->rreq_oa
),
434 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
435 i
= length
- sizeof(*ap
);
436 if (i
>= sizeof(struct aodv_ext
))
437 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
441 ND_PRINT((ndo
, " [|rreq"));
443 ND_PRINT((ndo
, " rreq %u", length
));
449 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
451 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
456 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
459 if (length
< sizeof(*ap
))
461 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
462 "\tdst %s dseq %lu src %s %lu ms", length
,
463 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
464 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
465 ap
->rrep_ps
& RREP_PREFIX_MASK
,
467 ip6addr_string(ndo
, &ap
->rrep_da
),
468 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
469 ip6addr_string(ndo
, &ap
->rrep_oa
),
470 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
471 i
= length
- sizeof(*ap
);
472 if (i
>= sizeof(struct aodv_ext
))
473 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
477 ND_PRINT((ndo
, " [|rreq"));
479 ND_PRINT((ndo
, " rrep %u", length
));
485 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
487 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
492 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
493 const struct rerr_unreach6_draft_01
*dp6
;
496 if (length
< sizeof(*ap
))
498 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
499 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
500 ap
->rerr_dc
, length
));
501 dp6
= (struct rerr_unreach6_draft_01
*)(void *)(ap
+ 1);
502 i
= length
- sizeof(*ap
);
503 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
505 if (i
< sizeof(*dp6
))
507 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
508 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
515 ND_PRINT((ndo
, "[|rerr]"));
517 ND_PRINT((ndo
, " rerr %u", length
));
522 aodv_print(netdissect_options
*ndo
,
523 const u_char
*dat
, u_int length
, int is_ip6
)
528 * The message type is the first byte; make sure we have it
533 ND_PRINT((ndo
, " aodv"));
539 aodv_v6_rreq(ndo
, dat
, length
);
541 aodv_rreq(ndo
, dat
, length
);
546 aodv_v6_rrep(ndo
, dat
, length
);
548 aodv_rrep(ndo
, dat
, length
);
553 aodv_v6_rerr(ndo
, dat
, length
);
555 aodv_rerr(ndo
, dat
, length
);
559 ND_PRINT((ndo
, " rrep-ack %u", length
));
562 case AODV_V6_DRAFT_01_RREQ
:
563 aodv_v6_draft_01_rreq(ndo
, dat
, length
);
566 case AODV_V6_DRAFT_01_RREP
:
567 aodv_v6_draft_01_rrep(ndo
, dat
, length
);
570 case AODV_V6_DRAFT_01_RERR
:
571 aodv_v6_draft_01_rerr(ndo
, dat
, length
);
574 case AODV_V6_DRAFT_01_RREP_ACK
:
575 ND_PRINT((ndo
, " rrep-ack %u", length
));
579 ND_PRINT((ndo
, " type %u %u", msg_type
, length
));
584 ND_PRINT((ndo
, " [|aodv]"));