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 <netdissect-stdinc.h>
39 #include "netdissect.h"
40 #include "addrtoname.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 */
56 uint8_t rreq_type
; /* AODV message type (1) */
57 uint8_t rreq_flags
; /* various flags */
58 uint8_t rreq_zero0
; /* reserved, set to zero */
59 uint8_t rreq_hops
; /* number of hops from originator */
60 uint32_t rreq_id
; /* request ID */
61 struct in6_addr rreq_da
; /* destination IPv6 address */
62 uint32_t rreq_ds
; /* destination sequence number */
63 struct in6_addr rreq_oa
; /* originator IPv6 address */
64 uint32_t rreq_os
; /* originator sequence number */
66 struct aodv_rreq6_draft_01
{
67 uint8_t rreq_type
; /* AODV message type (16) */
68 uint8_t rreq_flags
; /* various flags */
69 uint8_t rreq_zero0
; /* reserved, set to zero */
70 uint8_t rreq_hops
; /* number of hops from originator */
71 uint32_t rreq_id
; /* request ID */
72 uint32_t rreq_ds
; /* destination sequence number */
73 uint32_t rreq_os
; /* originator sequence number */
74 struct in6_addr rreq_da
; /* destination IPv6 address */
75 struct in6_addr rreq_oa
; /* originator IPv6 address */
78 #define RREQ_JOIN 0x80 /* join (reserved for multicast */
79 #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */
80 #define RREQ_GRAT 0x20 /* gratuitous RREP */
81 #define RREQ_DEST 0x10 /* destination only */
82 #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */
83 #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
86 uint8_t rrep_type
; /* AODV message type (2) */
87 uint8_t rrep_flags
; /* various flags */
88 uint8_t rrep_ps
; /* prefix size */
89 uint8_t rrep_hops
; /* number of hops from o to d */
90 uint32_t rrep_da
; /* destination IPv4 address */
91 uint32_t rrep_ds
; /* destination sequence number */
92 uint32_t rrep_oa
; /* originator IPv4 address */
93 uint32_t rrep_life
; /* lifetime of this route */
96 uint8_t rrep_type
; /* AODV message type (2) */
97 uint8_t rrep_flags
; /* various flags */
98 uint8_t rrep_ps
; /* prefix size */
99 uint8_t rrep_hops
; /* number of hops from o to d */
100 struct in6_addr rrep_da
; /* destination IPv6 address */
101 uint32_t rrep_ds
; /* destination sequence number */
102 struct in6_addr rrep_oa
; /* originator IPv6 address */
103 uint32_t rrep_life
; /* lifetime of this route */
105 struct aodv_rrep6_draft_01
{
106 uint8_t rrep_type
; /* AODV message type (17) */
107 uint8_t rrep_flags
; /* various flags */
108 uint8_t rrep_ps
; /* prefix size */
109 uint8_t rrep_hops
; /* number of hops from o to d */
110 uint32_t rrep_ds
; /* destination sequence number */
111 struct in6_addr rrep_da
; /* destination IPv6 address */
112 struct in6_addr rrep_oa
; /* originator IPv6 address */
113 uint32_t rrep_life
; /* lifetime of this route */
116 #define RREP_REPAIR 0x80 /* repair (reserved for multicast */
117 #define RREP_ACK 0x40 /* acknowledgement required */
118 #define RREP_FLAGS_MASK 0xC0 /* mask for rrep_flags */
119 #define RREP_PREFIX_MASK 0x1F /* mask for prefix size */
121 struct rerr_unreach
{
122 uint32_t u_da
; /* IPv4 address */
123 uint32_t u_ds
; /* sequence number */
125 struct rerr_unreach6
{
126 struct in6_addr u_da
; /* IPv6 address */
127 uint32_t u_ds
; /* sequence number */
129 struct rerr_unreach6_draft_01
{
130 struct in6_addr u_da
; /* IPv6 address */
131 uint32_t u_ds
; /* sequence number */
135 uint8_t rerr_type
; /* AODV message type (3 or 18) */
136 uint8_t rerr_flags
; /* various flags */
137 uint8_t rerr_zero0
; /* reserved, set to zero */
138 uint8_t rerr_dc
; /* destination count */
141 #define RERR_NODELETE 0x80 /* don't delete the link */
142 #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
144 struct aodv_rrep_ack
{
149 #define AODV_RREQ 1 /* route request */
150 #define AODV_RREP 2 /* route response */
151 #define AODV_RERR 3 /* error report */
152 #define AODV_RREP_ACK 4 /* route response acknowledgement */
154 #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */
155 #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */
156 #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */
157 #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
160 uint8_t type
; /* extension type */
161 uint8_t length
; /* extension length */
165 struct aodv_ext eh
; /* extension header */
166 uint8_t interval
[4]; /* expect my next hello in
168 * NOTE: this is not aligned */
171 #define AODV_EXT_HELLO 1
174 aodv_extension(netdissect_options
*ndo
,
175 const struct aodv_ext
*ep
, u_int length
)
177 const struct aodv_hello
*ah
;
181 ah
= (const struct aodv_hello
*)(const void *)ep
;
183 if (length
< sizeof(struct aodv_hello
))
185 ND_PRINT((ndo
, "\n\text HELLO %ld ms",
186 (unsigned long)EXTRACT_32BITS(&ah
->interval
)));
190 ND_PRINT((ndo
, "\n\text %u %u", ep
->type
, ep
->length
));
196 ND_PRINT((ndo
, " [|hello]"));
200 aodv_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
203 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
206 if (length
< sizeof(*ap
))
208 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
209 "\tdst %s seq %lu src %s seq %lu", length
,
210 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
211 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
212 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
213 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
214 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
216 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
217 ipaddr_string(ndo
, &ap
->rreq_da
),
218 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
219 ipaddr_string(ndo
, &ap
->rreq_oa
),
220 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
221 i
= length
- sizeof(*ap
);
222 if (i
>= sizeof(struct aodv_ext
))
223 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
227 ND_PRINT((ndo
, " [|rreq"));
231 aodv_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
234 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
237 if (length
< sizeof(*ap
))
239 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
240 "\tdst %s dseq %lu src %s %lu ms", length
,
241 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
242 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
243 ap
->rrep_ps
& RREP_PREFIX_MASK
,
245 ipaddr_string(ndo
, &ap
->rrep_da
),
246 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
247 ipaddr_string(ndo
, &ap
->rrep_oa
),
248 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
249 i
= length
- sizeof(*ap
);
250 if (i
>= sizeof(struct aodv_ext
))
251 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
255 ND_PRINT((ndo
, " [|rreq"));
259 aodv_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
262 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
263 const struct rerr_unreach
*dp
;
266 if (length
< sizeof(*ap
))
268 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
269 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
270 ap
->rerr_dc
, length
));
271 dp
= (const struct rerr_unreach
*)(dat
+ sizeof(*ap
));
272 i
= length
- sizeof(*ap
);
273 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
277 ND_PRINT((ndo
, " {%s}(%ld)", ipaddr_string(ndo
, &dp
->u_da
),
278 (unsigned long)EXTRACT_32BITS(&dp
->u_ds
)));
285 ND_PRINT((ndo
, "[|rerr]"));
289 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
292 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
295 if (length
< sizeof(*ap
))
297 ND_PRINT((ndo
, " v6 rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
298 "\tdst %s seq %lu src %s seq %lu", length
,
299 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
300 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
301 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
302 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
303 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
305 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
306 ip6addr_string(ndo
, &ap
->rreq_da
),
307 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
308 ip6addr_string(ndo
, &ap
->rreq_oa
),
309 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
310 i
= length
- sizeof(*ap
);
311 if (i
>= sizeof(struct aodv_ext
))
312 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
316 ND_PRINT((ndo
, " [|rreq"));
320 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
323 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
326 if (length
< sizeof(*ap
))
328 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
329 "\tdst %s dseq %lu src %s %lu ms", length
,
330 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
331 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
332 ap
->rrep_ps
& RREP_PREFIX_MASK
,
334 ip6addr_string(ndo
, &ap
->rrep_da
),
335 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
336 ip6addr_string(ndo
, &ap
->rrep_oa
),
337 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
338 i
= length
- sizeof(*ap
);
339 if (i
>= sizeof(struct aodv_ext
))
340 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
344 ND_PRINT((ndo
, " [|rreq"));
348 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
351 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
352 const struct rerr_unreach6
*dp6
;
355 if (length
< sizeof(*ap
))
357 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
358 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
359 ap
->rerr_dc
, length
));
360 dp6
= (const struct rerr_unreach6
*)(const void *)(ap
+ 1);
361 i
= length
- sizeof(*ap
);
362 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
364 if (i
< sizeof(*dp6
))
366 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
367 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
374 ND_PRINT((ndo
, "[|rerr]"));
378 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
381 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
384 if (length
< sizeof(*ap
))
386 ND_PRINT((ndo
, " rreq %u %s%s%s%s%shops %u id 0x%08lx\n"
387 "\tdst %s seq %lu src %s seq %lu", length
,
388 ap
->rreq_type
& RREQ_JOIN
? "[J]" : "",
389 ap
->rreq_type
& RREQ_REPAIR
? "[R]" : "",
390 ap
->rreq_type
& RREQ_GRAT
? "[G]" : "",
391 ap
->rreq_type
& RREQ_DEST
? "[D]" : "",
392 ap
->rreq_type
& RREQ_UNKNOWN
? "[U] " : " ",
394 (unsigned long)EXTRACT_32BITS(&ap
->rreq_id
),
395 ip6addr_string(ndo
, &ap
->rreq_da
),
396 (unsigned long)EXTRACT_32BITS(&ap
->rreq_ds
),
397 ip6addr_string(ndo
, &ap
->rreq_oa
),
398 (unsigned long)EXTRACT_32BITS(&ap
->rreq_os
)));
399 i
= length
- sizeof(*ap
);
400 if (i
>= sizeof(struct aodv_ext
))
401 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
405 ND_PRINT((ndo
, " [|rreq"));
409 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
412 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
415 if (length
< sizeof(*ap
))
417 ND_PRINT((ndo
, " rrep %u %s%sprefix %u hops %u\n"
418 "\tdst %s dseq %lu src %s %lu ms", length
,
419 ap
->rrep_type
& RREP_REPAIR
? "[R]" : "",
420 ap
->rrep_type
& RREP_ACK
? "[A] " : " ",
421 ap
->rrep_ps
& RREP_PREFIX_MASK
,
423 ip6addr_string(ndo
, &ap
->rrep_da
),
424 (unsigned long)EXTRACT_32BITS(&ap
->rrep_ds
),
425 ip6addr_string(ndo
, &ap
->rrep_oa
),
426 (unsigned long)EXTRACT_32BITS(&ap
->rrep_life
)));
427 i
= length
- sizeof(*ap
);
428 if (i
>= sizeof(struct aodv_ext
))
429 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
433 ND_PRINT((ndo
, " [|rreq"));
437 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
440 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
441 const struct rerr_unreach6_draft_01
*dp6
;
444 if (length
< sizeof(*ap
))
446 ND_PRINT((ndo
, " rerr %s [items %u] [%u]:",
447 ap
->rerr_flags
& RERR_NODELETE
? "[D]" : "",
448 ap
->rerr_dc
, length
));
449 dp6
= (const struct rerr_unreach6_draft_01
*)(const void *)(ap
+ 1);
450 i
= length
- sizeof(*ap
);
451 for (dc
= ap
->rerr_dc
; dc
!= 0; dc
--) {
453 if (i
< sizeof(*dp6
))
455 ND_PRINT((ndo
, " {%s}(%ld)", ip6addr_string(ndo
, &dp6
->u_da
),
456 (unsigned long)EXTRACT_32BITS(&dp6
->u_ds
)));
463 ND_PRINT((ndo
, "[|rerr]"));
467 aodv_print(netdissect_options
*ndo
,
468 const u_char
*dat
, u_int length
, int is_ip6
)
473 * The message type is the first byte; make sure we have it
478 ND_PRINT((ndo
, " aodv"));
484 aodv_v6_rreq(ndo
, dat
, length
);
486 aodv_rreq(ndo
, dat
, length
);
491 aodv_v6_rrep(ndo
, dat
, length
);
493 aodv_rrep(ndo
, dat
, length
);
498 aodv_v6_rerr(ndo
, dat
, length
);
500 aodv_rerr(ndo
, dat
, length
);
504 ND_PRINT((ndo
, " rrep-ack %u", length
));
507 case AODV_V6_DRAFT_01_RREQ
:
508 aodv_v6_draft_01_rreq(ndo
, dat
, length
);
511 case AODV_V6_DRAFT_01_RREP
:
512 aodv_v6_draft_01_rrep(ndo
, dat
, length
);
515 case AODV_V6_DRAFT_01_RERR
:
516 aodv_v6_draft_01_rerr(ndo
, dat
, length
);
519 case AODV_V6_DRAFT_01_RREP_ACK
:
520 ND_PRINT((ndo
, " rrep-ack %u", length
));
524 ND_PRINT((ndo
, " type %u %u", msg_type
, length
));
529 ND_PRINT((ndo
, " [|aodv]"));