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 /* \summary: Ad hoc On-Demand Distance Vector (AODV) Routing printer */
39 #include "netdissect-stdinc.h"
41 #include "netdissect.h"
42 #include "addrtoname.h"
49 nd_uint8_t rreq_type
; /* AODV message type (1) */
50 nd_uint8_t rreq_flags
; /* various flags */
51 nd_uint8_t rreq_zero0
; /* reserved, set to zero */
52 nd_uint8_t rreq_hops
; /* number of hops from originator */
53 nd_uint32_t rreq_id
; /* request ID */
54 nd_uint32_t rreq_da
; /* destination IPv4 address */
55 nd_uint32_t rreq_ds
; /* destination sequence number */
56 nd_uint32_t rreq_oa
; /* originator IPv4 address */
57 nd_uint32_t rreq_os
; /* originator sequence number */
60 nd_uint8_t rreq_type
; /* AODV message type (1) */
61 nd_uint8_t rreq_flags
; /* various flags */
62 nd_uint8_t rreq_zero0
; /* reserved, set to zero */
63 nd_uint8_t rreq_hops
; /* number of hops from originator */
64 nd_uint32_t rreq_id
; /* request ID */
65 nd_ipv6 rreq_da
; /* destination IPv6 address */
66 nd_uint32_t rreq_ds
; /* destination sequence number */
67 nd_ipv6 rreq_oa
; /* originator IPv6 address */
68 nd_uint32_t rreq_os
; /* originator sequence number */
70 struct aodv_rreq6_draft_01
{
71 nd_uint8_t rreq_type
; /* AODV message type (16) */
72 nd_uint8_t rreq_flags
; /* various flags */
73 nd_uint8_t rreq_zero0
; /* reserved, set to zero */
74 nd_uint8_t rreq_hops
; /* number of hops from originator */
75 nd_uint32_t rreq_id
; /* request ID */
76 nd_uint32_t rreq_ds
; /* destination sequence number */
77 nd_uint32_t rreq_os
; /* originator sequence number */
78 nd_ipv6 rreq_da
; /* destination IPv6 address */
79 nd_ipv6 rreq_oa
; /* originator IPv6 address */
82 #define RREQ_JOIN 0x80 /* join (reserved for multicast */
83 #define RREQ_REPAIR 0x40 /* repair (reserved for multicast */
84 #define RREQ_GRAT 0x20 /* gratuitous RREP */
85 #define RREQ_DEST 0x10 /* destination only */
86 #define RREQ_UNKNOWN 0x08 /* unknown destination sequence num */
87 #define RREQ_FLAGS_MASK 0xF8 /* mask for rreq_flags */
90 nd_uint8_t rrep_type
; /* AODV message type (2) */
91 nd_uint8_t rrep_flags
; /* various flags */
92 nd_uint8_t rrep_ps
; /* prefix size */
93 nd_uint8_t rrep_hops
; /* number of hops from o to d */
94 nd_uint32_t rrep_da
; /* destination IPv4 address */
95 nd_uint32_t rrep_ds
; /* destination sequence number */
96 nd_uint32_t rrep_oa
; /* originator IPv4 address */
97 nd_uint32_t rrep_life
; /* lifetime of this route */
100 nd_uint8_t rrep_type
; /* AODV message type (2) */
101 nd_uint8_t rrep_flags
; /* various flags */
102 nd_uint8_t rrep_ps
; /* prefix size */
103 nd_uint8_t rrep_hops
; /* number of hops from o to d */
104 nd_ipv6 rrep_da
; /* destination IPv6 address */
105 nd_uint32_t rrep_ds
; /* destination sequence number */
106 nd_ipv6 rrep_oa
; /* originator IPv6 address */
107 nd_uint32_t rrep_life
; /* lifetime of this route */
109 struct aodv_rrep6_draft_01
{
110 nd_uint8_t rrep_type
; /* AODV message type (17) */
111 nd_uint8_t rrep_flags
; /* various flags */
112 nd_uint8_t rrep_ps
; /* prefix size */
113 nd_uint8_t rrep_hops
; /* number of hops from o to d */
114 nd_uint32_t rrep_ds
; /* destination sequence number */
115 nd_ipv6 rrep_da
; /* destination IPv6 address */
116 nd_ipv6 rrep_oa
; /* originator IPv6 address */
117 nd_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 nd_uint32_t u_da
; /* IPv4 address */
127 nd_uint32_t u_ds
; /* sequence number */
129 struct rerr_unreach6
{
130 nd_ipv6 u_da
; /* IPv6 address */
131 nd_uint32_t u_ds
; /* sequence number */
133 struct rerr_unreach6_draft_01
{
134 nd_ipv6 u_da
; /* IPv6 address */
135 nd_uint32_t u_ds
; /* sequence number */
139 nd_uint8_t rerr_type
; /* AODV message type (3 or 18) */
140 nd_uint8_t rerr_flags
; /* various flags */
141 nd_uint8_t rerr_zero0
; /* reserved, set to zero */
142 nd_uint8_t rerr_dc
; /* destination count */
145 #define RERR_NODELETE 0x80 /* don't delete the link */
146 #define RERR_FLAGS_MASK 0x80 /* mask for rerr_flags */
148 struct aodv_rrep_ack
{
153 #define AODV_RREQ 1 /* route request */
154 #define AODV_RREP 2 /* route response */
155 #define AODV_RERR 3 /* error report */
156 #define AODV_RREP_ACK 4 /* route response acknowledgement */
158 #define AODV_V6_DRAFT_01_RREQ 16 /* IPv6 route request */
159 #define AODV_V6_DRAFT_01_RREP 17 /* IPv6 route response */
160 #define AODV_V6_DRAFT_01_RERR 18 /* IPv6 error report */
161 #define AODV_V6_DRAFT_01_RREP_ACK 19 /* IPV6 route response acknowledgment */
164 nd_uint8_t type
; /* extension type */
165 nd_uint8_t length
; /* extension length */
169 struct aodv_ext eh
; /* extension header */
170 nd_uint32_t interval
; /* expect my next hello in
172 * NOTE: this is not aligned */
175 #define AODV_EXT_HELLO 1
178 aodv_extension(netdissect_options
*ndo
,
179 const struct aodv_ext
*ep
, u_int length
)
181 const struct aodv_hello
*ah
;
184 switch (EXTRACT_U_1(ep
->type
)) {
186 ah
= (const struct aodv_hello
*)(const void *)ep
;
188 if (length
< sizeof(struct aodv_hello
))
190 if (EXTRACT_U_1(ep
->length
) < 4) {
191 ND_PRINT("\n\text HELLO - bad length %u", EXTRACT_U_1(ep
->length
));
194 ND_PRINT("\n\text HELLO %u ms",
195 EXTRACT_BE_U_4(ah
->interval
));
199 ND_PRINT("\n\text %u %u", EXTRACT_U_1(ep
->type
), EXTRACT_U_1(ep
->length
));
205 ND_PRINT(" [|hello]");
209 aodv_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
212 const struct aodv_rreq
*ap
= (const struct aodv_rreq
*)dat
;
215 if (length
< sizeof(*ap
))
217 ND_PRINT(" rreq %u %s%s%s%s%shops %u id 0x%08x\n"
218 "\tdst %s seq %u src %s seq %u", length
,
219 EXTRACT_U_1(ap
->rreq_type
) & RREQ_JOIN
? "[J]" : "",
220 EXTRACT_U_1(ap
->rreq_type
) & RREQ_REPAIR
? "[R]" : "",
221 EXTRACT_U_1(ap
->rreq_type
) & RREQ_GRAT
? "[G]" : "",
222 EXTRACT_U_1(ap
->rreq_type
) & RREQ_DEST
? "[D]" : "",
223 EXTRACT_U_1(ap
->rreq_type
) & RREQ_UNKNOWN
? "[U] " : " ",
224 EXTRACT_U_1(ap
->rreq_hops
),
225 EXTRACT_BE_U_4(ap
->rreq_id
),
226 ipaddr_string(ndo
, &ap
->rreq_da
),
227 EXTRACT_BE_U_4(ap
->rreq_ds
),
228 ipaddr_string(ndo
, &ap
->rreq_oa
),
229 EXTRACT_BE_U_4(ap
->rreq_os
));
230 i
= length
- sizeof(*ap
);
231 if (i
>= sizeof(struct aodv_ext
))
232 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
240 aodv_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
243 const struct aodv_rrep
*ap
= (const struct aodv_rrep
*)dat
;
246 if (length
< sizeof(*ap
))
248 ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
249 "\tdst %s dseq %u src %s %u ms", length
,
250 EXTRACT_U_1(ap
->rrep_type
) & RREP_REPAIR
? "[R]" : "",
251 EXTRACT_U_1(ap
->rrep_type
) & RREP_ACK
? "[A] " : " ",
252 EXTRACT_U_1(ap
->rrep_ps
) & RREP_PREFIX_MASK
,
253 EXTRACT_U_1(ap
->rrep_hops
),
254 ipaddr_string(ndo
, &ap
->rrep_da
),
255 EXTRACT_BE_U_4(ap
->rrep_ds
),
256 ipaddr_string(ndo
, &ap
->rrep_oa
),
257 EXTRACT_BE_U_4(ap
->rrep_life
));
258 i
= length
- sizeof(*ap
);
259 if (i
>= sizeof(struct aodv_ext
))
260 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
268 aodv_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
271 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
272 const struct rerr_unreach
*dp
;
275 if (length
< sizeof(*ap
))
277 ND_PRINT(" rerr %s [items %u] [%u]:",
278 EXTRACT_U_1(ap
->rerr_flags
) & RERR_NODELETE
? "[D]" : "",
279 EXTRACT_U_1(ap
->rerr_dc
), length
);
280 dp
= (const struct rerr_unreach
*)(dat
+ sizeof(*ap
));
281 i
= length
- sizeof(*ap
);
282 for (dc
= EXTRACT_U_1(ap
->rerr_dc
); dc
!= 0; dc
--) {
286 ND_PRINT(" {%s}(%u)", ipaddr_string(ndo
, &dp
->u_da
),
287 EXTRACT_BE_U_4(dp
->u_ds
));
298 aodv_v6_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
301 const struct aodv_rreq6
*ap
= (const struct aodv_rreq6
*)dat
;
304 if (length
< sizeof(*ap
))
306 ND_PRINT(" v6 rreq %u %s%s%s%s%shops %u id 0x%08x\n"
307 "\tdst %s seq %u src %s seq %u", length
,
308 EXTRACT_U_1(ap
->rreq_type
) & RREQ_JOIN
? "[J]" : "",
309 EXTRACT_U_1(ap
->rreq_type
) & RREQ_REPAIR
? "[R]" : "",
310 EXTRACT_U_1(ap
->rreq_type
) & RREQ_GRAT
? "[G]" : "",
311 EXTRACT_U_1(ap
->rreq_type
) & RREQ_DEST
? "[D]" : "",
312 EXTRACT_U_1(ap
->rreq_type
) & RREQ_UNKNOWN
? "[U] " : " ",
313 EXTRACT_U_1(ap
->rreq_hops
),
314 EXTRACT_BE_U_4(ap
->rreq_id
),
315 ip6addr_string(ndo
, ap
->rreq_da
),
316 EXTRACT_BE_U_4(ap
->rreq_ds
),
317 ip6addr_string(ndo
, ap
->rreq_oa
),
318 EXTRACT_BE_U_4(ap
->rreq_os
));
319 i
= length
- sizeof(*ap
);
320 if (i
>= sizeof(struct aodv_ext
))
321 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
329 aodv_v6_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
332 const struct aodv_rrep6
*ap
= (const struct aodv_rrep6
*)dat
;
335 if (length
< sizeof(*ap
))
337 ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
338 "\tdst %s dseq %u src %s %u ms", length
,
339 EXTRACT_U_1(ap
->rrep_type
) & RREP_REPAIR
? "[R]" : "",
340 EXTRACT_U_1(ap
->rrep_type
) & RREP_ACK
? "[A] " : " ",
341 EXTRACT_U_1(ap
->rrep_ps
) & RREP_PREFIX_MASK
,
342 EXTRACT_U_1(ap
->rrep_hops
),
343 ip6addr_string(ndo
, ap
->rrep_da
),
344 EXTRACT_BE_U_4(ap
->rrep_ds
),
345 ip6addr_string(ndo
, ap
->rrep_oa
),
346 EXTRACT_BE_U_4(ap
->rrep_life
));
347 i
= length
- sizeof(*ap
);
348 if (i
>= sizeof(struct aodv_ext
))
349 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
357 aodv_v6_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
360 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
361 const struct rerr_unreach6
*dp6
;
364 if (length
< sizeof(*ap
))
366 ND_PRINT(" rerr %s [items %u] [%u]:",
367 EXTRACT_U_1(ap
->rerr_flags
) & RERR_NODELETE
? "[D]" : "",
368 EXTRACT_U_1(ap
->rerr_dc
), length
);
369 dp6
= (const struct rerr_unreach6
*)(const void *)(ap
+ 1);
370 i
= length
- sizeof(*ap
);
371 for (dc
= EXTRACT_U_1(ap
->rerr_dc
); dc
!= 0; dc
--) {
373 if (i
< sizeof(*dp6
))
375 ND_PRINT(" {%s}(%u)", ip6addr_string(ndo
, dp6
->u_da
),
376 EXTRACT_BE_U_4(dp6
->u_ds
));
387 aodv_v6_draft_01_rreq(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
390 const struct aodv_rreq6_draft_01
*ap
= (const struct aodv_rreq6_draft_01
*)dat
;
393 if (length
< sizeof(*ap
))
395 ND_PRINT(" rreq %u %s%s%s%s%shops %u id 0x%08x\n"
396 "\tdst %s seq %u src %s seq %u", length
,
397 EXTRACT_U_1(ap
->rreq_type
) & RREQ_JOIN
? "[J]" : "",
398 EXTRACT_U_1(ap
->rreq_type
) & RREQ_REPAIR
? "[R]" : "",
399 EXTRACT_U_1(ap
->rreq_type
) & RREQ_GRAT
? "[G]" : "",
400 EXTRACT_U_1(ap
->rreq_type
) & RREQ_DEST
? "[D]" : "",
401 EXTRACT_U_1(ap
->rreq_type
) & RREQ_UNKNOWN
? "[U] " : " ",
402 EXTRACT_U_1(ap
->rreq_hops
),
403 EXTRACT_BE_U_4(ap
->rreq_id
),
404 ip6addr_string(ndo
, ap
->rreq_da
),
405 EXTRACT_BE_U_4(ap
->rreq_ds
),
406 ip6addr_string(ndo
, ap
->rreq_oa
),
407 EXTRACT_BE_U_4(ap
->rreq_os
));
408 i
= length
- sizeof(*ap
);
409 if (i
>= sizeof(struct aodv_ext
))
410 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
418 aodv_v6_draft_01_rrep(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
421 const struct aodv_rrep6_draft_01
*ap
= (const struct aodv_rrep6_draft_01
*)dat
;
424 if (length
< sizeof(*ap
))
426 ND_PRINT(" rrep %u %s%sprefix %u hops %u\n"
427 "\tdst %s dseq %u src %s %u ms", length
,
428 EXTRACT_U_1(ap
->rrep_type
) & RREP_REPAIR
? "[R]" : "",
429 EXTRACT_U_1(ap
->rrep_type
) & RREP_ACK
? "[A] " : " ",
430 EXTRACT_U_1(ap
->rrep_ps
) & RREP_PREFIX_MASK
,
431 EXTRACT_U_1(ap
->rrep_hops
),
432 ip6addr_string(ndo
, ap
->rrep_da
),
433 EXTRACT_BE_U_4(ap
->rrep_ds
),
434 ip6addr_string(ndo
, ap
->rrep_oa
),
435 EXTRACT_BE_U_4(ap
->rrep_life
));
436 i
= length
- sizeof(*ap
);
437 if (i
>= sizeof(struct aodv_ext
))
438 aodv_extension(ndo
, (const struct aodv_ext
*)(dat
+ sizeof(*ap
)), i
);
446 aodv_v6_draft_01_rerr(netdissect_options
*ndo
, const u_char
*dat
, u_int length
)
449 const struct aodv_rerr
*ap
= (const struct aodv_rerr
*)dat
;
450 const struct rerr_unreach6_draft_01
*dp6
;
453 if (length
< sizeof(*ap
))
455 ND_PRINT(" rerr %s [items %u] [%u]:",
456 EXTRACT_U_1(ap
->rerr_flags
) & RERR_NODELETE
? "[D]" : "",
457 EXTRACT_U_1(ap
->rerr_dc
), length
);
458 dp6
= (const struct rerr_unreach6_draft_01
*)(const void *)(ap
+ 1);
459 i
= length
- sizeof(*ap
);
460 for (dc
= EXTRACT_U_1(ap
->rerr_dc
); dc
!= 0; dc
--) {
462 if (i
< sizeof(*dp6
))
464 ND_PRINT(" {%s}(%u)", ip6addr_string(ndo
, dp6
->u_da
),
465 EXTRACT_BE_U_4(dp6
->u_ds
));
476 aodv_print(netdissect_options
*ndo
,
477 const u_char
*dat
, u_int length
, int is_ip6
)
482 * The message type is the first byte; make sure we have it
486 msg_type
= EXTRACT_U_1(dat
);
493 aodv_v6_rreq(ndo
, dat
, length
);
495 aodv_rreq(ndo
, dat
, length
);
500 aodv_v6_rrep(ndo
, dat
, length
);
502 aodv_rrep(ndo
, dat
, length
);
507 aodv_v6_rerr(ndo
, dat
, length
);
509 aodv_rerr(ndo
, dat
, length
);
513 ND_PRINT(" rrep-ack %u", length
);
516 case AODV_V6_DRAFT_01_RREQ
:
517 aodv_v6_draft_01_rreq(ndo
, dat
, length
);
520 case AODV_V6_DRAFT_01_RREP
:
521 aodv_v6_draft_01_rrep(ndo
, dat
, length
);
524 case AODV_V6_DRAFT_01_RERR
:
525 aodv_v6_draft_01_rerr(ndo
, dat
, length
);
528 case AODV_V6_DRAFT_01_RREP_ACK
:
529 ND_PRINT(" rrep-ack %u", length
);
533 ND_PRINT(" type %u %u", msg_type
, length
);
538 ND_PRINT(" [|aodv]");