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>
39 #include "netdissect.h"
40 #include "addrtoname.h"
41 #include "extract.h" /* must come after interface.h */
45 uint8_t rreq_type
; /* AODV message type (1) */
46 uint8_t rreq_flags
; /* various flags */
47 uint8_t rreq_zero0
; /* reserved, set to zero */
48 uint8_t rreq_hops
; /* number of hops from originator */
49 uint32_t rreq_id
; /* request ID */
50 uint32_t rreq_da
; /* destination IPv4 address */
51 uint32_t rreq_ds
; /* destination sequence number */
52 uint32_t rreq_oa
; /* originator IPv4 address */
53 uint32_t rreq_os
; /* originator sequence number */
57 uint8_t rreq_type
; /* AODV message type (1) */
58 uint8_t rreq_flags
; /* various flags */
59 uint8_t rreq_zero0
; /* reserved, set to zero */
60 uint8_t rreq_hops
; /* number of hops from originator */
61 uint32_t rreq_id
; /* request ID */
62 struct in6_addr rreq_da
; /* destination IPv6 address */
63 uint32_t rreq_ds
; /* destination sequence number */
64 struct in6_addr rreq_oa
; /* originator IPv6 address */
65 uint32_t rreq_os
; /* originator sequence number */
67 struct aodv_rreq6_draft_01
{
68 uint8_t rreq_type
; /* AODV message type (16) */
69 uint8_t rreq_flags
; /* various flags */
70 uint8_t rreq_zero0
; /* reserved, set to zero */
71 uint8_t rreq_hops
; /* number of hops from originator */
72 uint32_t rreq_id
; /* request ID */
73 uint32_t rreq_ds
; /* destination sequence number */
74 uint32_t rreq_os
; /* originator sequence number */
75 struct in6_addr rreq_da
; /* destination IPv6 address */
76 struct in6_addr rreq_oa
; /* originator IPv6 address */
80 #define RREQ_JOIN 0x80 /* join (reserved for multicast */
81 #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */
82 #define RREQ_GRAT 0x20 /* gratuitous RREP */
83 #define RREQ_DEST 0x10 /* destination only */
84 #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */
85 #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
88 uint8_t rrep_type
; /* AODV message type (2) */
89 uint8_t rrep_flags
; /* various flags */
90 uint8_t rrep_ps
; /* prefix size */
91 uint8_t rrep_hops
; /* number of hops from o to d */
92 uint32_t rrep_da
; /* destination IPv4 address */
93 uint32_t rrep_ds
; /* destination sequence number */
94 uint32_t rrep_oa
; /* originator IPv4 address */
95 uint32_t rrep_life
; /* lifetime of this route */
99 uint8_t rrep_type
; /* AODV message type (2) */
100 uint8_t rrep_flags
; /* various flags */
101 uint8_t rrep_ps
; /* prefix size */
102 uint8_t rrep_hops
; /* number of hops from o to d */
103 struct in6_addr rrep_da
; /* destination IPv6 address */
104 uint32_t rrep_ds
; /* destination sequence number */
105 struct in6_addr rrep_oa
; /* originator IPv6 address */
106 uint32_t rrep_life
; /* lifetime of this route */
108 struct aodv_rrep6_draft_01
{
109 uint8_t rrep_type
; /* AODV message type (17) */
110 uint8_t rrep_flags
; /* various flags */
111 uint8_t rrep_ps
; /* prefix size */
112 uint8_t rrep_hops
; /* number of hops from o to d */
113 uint32_t rrep_ds
; /* destination sequence number */
114 struct in6_addr rrep_da
; /* destination IPv6 address */
115 struct in6_addr rrep_oa
; /* originator IPv6 address */
116 uint32_t rrep_life
; /* lifetime of this route */
120 #define RREP_REPAIR 0x80 /* repair (reserved for multicast */
121 #define RREP_ACK 0x40 /* acknowledgement required */
122 #define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */
123 #define RREP_PREFIX_MASK 0x1F /* mask for prefix size */
125 struct rerr_unreach
{
126 uint32_t u_da
; /* IPv4 address */
127 uint32_t u_ds
; /* sequence number */
130 struct rerr_unreach6
{
131 struct in6_addr u_da
; /* IPv6 address */
132 uint32_t u_ds
; /* sequence number */
134 struct rerr_unreach6_draft_01
{
135 struct in6_addr u_da
; /* IPv6 address */
136 uint32_t u_ds
; /* sequence number */
141 uint8_t rerr_type
; /* AODV message type (3 or 18) */
142 uint8_t rerr_flags
; /* various flags */
143 uint8_t rerr_zero0
; /* reserved, set to zero */
144 uint8_t rerr_dc
; /* destination count */
147 #define RERR_NODELETE 0x80 /* don't delete the link */
148 #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
150 struct aodv_rrep_ack
{
155 #define AODV_RREQ 1 /* route request */
156 #define AODV_RREP 2 /* route response */
157 #define AODV_RERR 3 /* error report */
158 #define AODV_RREP_ACK 4 /* route response acknowledgement */
160 #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */
161 #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */
162 #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */
163 #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
166 uint8_t type
; /* extension type */
167 uint8_t length
; /* extension length */
171 struct aodv_ext eh
; /* extension header */
172 uint8_t interval
[4]; /* expect my next hello in
174 * NOTE: this is not aligned */
177 #define AODV_EXT_HELLO 1
180 aodv_extension(netdissect_options
*ndo
,
181 const struct aodv_ext
*ep
, u_int length
)
183 const struct aodv_hello
*ah
;
187 ah
= (const struct aodv_hello
*)(const void *)ep
;
189 if (length
< sizeof(struct aodv_hello
))
191 ND_PRINT((ndo
, "\n\text HELLO %ld ms",
192 (unsigned long)EXTRACT_32BITS(&ah
->interval
)));
196 ND_PRINT((ndo
, "\n\text %u %u", ep
->type
, ep
->length
));
202 ND_PRINT((ndo
, " [|hello]"));
206 aodv_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
209 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
212 if (length
< sizeof(*ap
))
214 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
215 "\tdst %s seq %lu src %s seq %lu", length
,
216 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
217 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
218 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
219 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
220 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
222 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
223 ipaddr_string(ndo
, &ap
->rreq_da
),
224 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
225 ipaddr_string(ndo
, &ap
->rreq_oa
),
226 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
227 i
= length
- sizeof(*ap
);
228 if (i
>= sizeof(struct aodv_ext
))
229 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
233 ND_PRINT((ndo
, " [|rreq"));
237 aodv_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
240 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
243 if (length
< sizeof(*ap
))
245 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
246 "\tdst %s dseq %lu src %s %lu ms", length
,
247 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
248 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
249 ap
->rrep_ps
& RREP_PREFIX_MASK
,
251 ipaddr_string(ndo
, &ap
->rrep_da
),
252 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
253 ipaddr_string(ndo
, &ap
->rrep_oa
),
254 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
255 i
= length
- sizeof(*ap
);
256 if (i
>= sizeof(struct aodv_ext
))
257 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
261 ND_PRINT((ndo
, " [|rreq"));
265 aodv_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
268 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
269 const struct rerr_unreach
*dp
;
272 if (length
< sizeof(*ap
))
274 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
275 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
276 ap
->rerr_dc
, length
));
277 dp
= (const struct rerr_unreach
*)(dat
+ sizeof(*ap
));
278 i
= length
- sizeof(*ap
);
279 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
283 ND_PRINT((ndo
, " {%s}(%ld)", ipaddr_string(ndo
, &dp
->u_da
),
284 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
)));
291 ND_PRINT((ndo
, "[|rerr]"));
296 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
298 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
303 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
306 if (length
< sizeof(*ap
))
308 ND_PRINT((ndo
, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
309 "\tdst %s seq %lu src %s seq %lu", length
,
310 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
311 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
312 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
313 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
314 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
316 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
317 ip6addr_string(ndo
, &ap
->rreq_da
),
318 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
319 ip6addr_string(ndo
, &ap
->rreq_oa
),
320 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
321 i
= length
- sizeof(*ap
);
322 if (i
>= sizeof(struct aodv_ext
))
323 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
327 ND_PRINT((ndo
, " [|rreq"));
329 ND_PRINT((ndo
, " v6 rreq %u", length
));
335 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
337 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
342 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
345 if (length
< sizeof(*ap
))
347 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
348 "\tdst %s dseq %lu src %s %lu ms", length
,
349 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
350 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
351 ap
->rrep_ps
& RREP_PREFIX_MASK
,
353 ip6addr_string(ndo
, &ap
->rrep_da
),
354 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
355 ip6addr_string(ndo
, &ap
->rrep_oa
),
356 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
357 i
= length
- sizeof(*ap
);
358 if (i
>= sizeof(struct aodv_ext
))
359 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
363 ND_PRINT((ndo
, " [|rreq"));
365 ND_PRINT((ndo
, " rrep %u", length
));
371 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
373 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
378 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
379 const struct rerr_unreach6
*dp6
;
382 if (length
< sizeof(*ap
))
384 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
385 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
386 ap
->rerr_dc
, length
));
387 dp6
= (const struct rerr_unreach6
*)(const void *)(ap
+ 1);
388 i
= length
- sizeof(*ap
);
389 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
391 if (i
< sizeof(*dp6
))
393 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
394 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
401 ND_PRINT((ndo
, "[|rerr]"));
403 ND_PRINT((ndo
, " rerr %u", length
));
409 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
411 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
416 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
419 if (length
< sizeof(*ap
))
421 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
422 "\tdst %s seq %lu src %s seq %lu", length
,
423 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
424 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
425 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
426 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
427 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
429 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
430 ip6addr_string(ndo
, &ap
->rreq_da
),
431 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
432 ip6addr_string(ndo
, &ap
->rreq_oa
),
433 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
434 i
= length
- sizeof(*ap
);
435 if (i
>= sizeof(struct aodv_ext
))
436 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
440 ND_PRINT((ndo
, " [|rreq"));
442 ND_PRINT((ndo
, " rreq %u", length
));
448 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
450 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
455 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
458 if (length
< sizeof(*ap
))
460 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
461 "\tdst %s dseq %lu src %s %lu ms", length
,
462 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
463 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
464 ap
->rrep_ps
& RREP_PREFIX_MASK
,
466 ip6addr_string(ndo
, &ap
->rrep_da
),
467 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
468 ip6addr_string(ndo
, &ap
->rrep_oa
),
469 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
470 i
= length
- sizeof(*ap
);
471 if (i
>= sizeof(struct aodv_ext
))
472 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
476 ND_PRINT((ndo
, " [|rreq"));
478 ND_PRINT((ndo
, " rrep %u", length
));
484 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
486 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat _U_
, u_int length
)
491 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
492 const struct rerr_unreach6_draft_01
*dp6
;
495 if (length
< sizeof(*ap
))
497 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
498 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
499 ap
->rerr_dc
, length
));
500 dp6
= (const struct rerr_unreach6_draft_01
*)(const void *)(ap
+ 1);
501 i
= length
- sizeof(*ap
);
502 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
504 if (i
< sizeof(*dp6
))
506 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
507 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
514 ND_PRINT((ndo
, "[|rerr]"));
516 ND_PRINT((ndo
, " rerr %u", length
));
521 aodv_print(netdissect_options
*ndo
,
522 const u_char
*dat
, u_int length
, int is_ip6
)
527 * The message type is the first byte; make sure we have it
532 ND_PRINT((ndo
, " aodv"));
538 aodv_v6_rreq(ndo
, dat
, length
);
540 aodv_rreq(ndo
, dat
, length
);
545 aodv_v6_rrep(ndo
, dat
, length
);
547 aodv_rrep(ndo
, dat
, length
);
552 aodv_v6_rerr(ndo
, dat
, length
);
554 aodv_rerr(ndo
, dat
, length
);
558 ND_PRINT((ndo
, " rrep-ack %u", length
));
561 case AODV_V6_DRAFT_01_RREQ
:
562 aodv_v6_draft_01_rreq(ndo
, dat
, length
);
565 case AODV_V6_DRAFT_01_RREP
:
566 aodv_v6_draft_01_rrep(ndo
, dat
, length
);
569 case AODV_V6_DRAFT_01_RERR
:
570 aodv_v6_draft_01_rerr(ndo
, dat
, length
);
573 case AODV_V6_DRAFT_01_RREP_ACK
:
574 ND_PRINT((ndo
, " rrep-ack %u", length
));
578 ND_PRINT((ndo
, " type %u %u", msg_type
, length
));
583 ND_PRINT((ndo
, " [|aodv]"));