]> The Tcpdump Group git mirrors - tcpdump/blob - print-babel.c
10408e9f8676a5d0e2052d109d50d6377bf6ce4c
[tcpdump] / print-babel.c
1 /*
2 * Copyright (c) 2007-2011 Grégoire Henry, Juliusz Chroboczek
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the project nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /* \summary: Babel Routing Protocol printer */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <netdissect-stdinc.h>
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "netdissect.h"
41 #include "addrtoname.h"
42 #include "extract.h"
43
44 static const char tstr[] = "[|babel]";
45
46 static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length);
47
48 void
49 babel_print(netdissect_options *ndo,
50 const u_char *cp, u_int length)
51 {
52 ND_PRINT((ndo, "babel"));
53
54 ND_TCHECK_4(cp);
55
56 if(EXTRACT_U_1(cp) != 42) {
57 ND_PRINT((ndo, " invalid header"));
58 return;
59 } else {
60 ND_PRINT((ndo, " %d", EXTRACT_U_1(cp + 1)));
61 }
62
63 switch(EXTRACT_U_1(cp + 1)) {
64 case 2:
65 babel_print_v2(ndo, cp, length);
66 break;
67 default:
68 ND_PRINT((ndo, " unknown version"));
69 break;
70 }
71
72 return;
73
74 trunc:
75 ND_PRINT((ndo, " %s", tstr));
76 return;
77 }
78
79 /* TLVs */
80 #define MESSAGE_PAD1 0
81 #define MESSAGE_PADN 1
82 #define MESSAGE_ACK_REQ 2
83 #define MESSAGE_ACK 3
84 #define MESSAGE_HELLO 4
85 #define MESSAGE_IHU 5
86 #define MESSAGE_ROUTER_ID 6
87 #define MESSAGE_NH 7
88 #define MESSAGE_UPDATE 8
89 #define MESSAGE_REQUEST 9
90 #define MESSAGE_MH_REQUEST 10
91 #define MESSAGE_TSPC 11
92 #define MESSAGE_HMAC 12
93 #define MESSAGE_UPDATE_SRC_SPECIFIC 13
94 #define MESSAGE_REQUEST_SRC_SPECIFIC 14
95 #define MESSAGE_MH_REQUEST_SRC_SPECIFIC 15
96
97 /* sub-TLVs */
98 #define MESSAGE_SUB_PAD1 0
99 #define MESSAGE_SUB_PADN 1
100 #define MESSAGE_SUB_DIVERSITY 2
101 #define MESSAGE_SUB_TIMESTAMP 3
102
103 /* Diversity sub-TLV channel codes */
104 static const struct tok diversity_str[] = {
105 { 0, "reserved" },
106 { 255, "all" },
107 { 0, NULL }
108 };
109
110 static const char *
111 format_id(const u_char *id)
112 {
113 static char buf[25];
114 snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
115 EXTRACT_U_1(id), EXTRACT_U_1(id + 1), EXTRACT_U_1(id + 2),
116 EXTRACT_U_1(id + 3), EXTRACT_U_1(id + 4), EXTRACT_U_1(id + 5),
117 EXTRACT_U_1(id + 6), EXTRACT_U_1(id + 7));
118 buf[24] = '\0';
119 return buf;
120 }
121
122 static const unsigned char v4prefix[16] =
123 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
124
125 static const char *
126 format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen)
127 {
128 static char buf[50];
129 if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0)
130 snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96);
131 else
132 snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen);
133 buf[49] = '\0';
134 return buf;
135 }
136
137 static const char *
138 format_address(netdissect_options *ndo, const u_char *prefix)
139 {
140 if(memcmp(prefix, v4prefix, 12) == 0)
141 return ipaddr_string(ndo, prefix + 12);
142 else
143 return ip6addr_string(ndo, prefix);
144 }
145
146 static const char *
147 format_interval(const uint16_t i)
148 {
149 static char buf[sizeof("000.00s")];
150
151 if (i == 0)
152 return "0.0s (bogus)";
153 snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100);
154 return buf;
155 }
156
157 static const char *
158 format_interval_update(const uint16_t i)
159 {
160 return i == 0xFFFF ? "infinity" : format_interval(i);
161 }
162
163 static const char *
164 format_timestamp(const uint32_t i)
165 {
166 static char buf[sizeof("0000.000000s")];
167 snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000);
168 return buf;
169 }
170
171 /* Return number of octets consumed from the input buffer (not the prefix length
172 * in bytes), or -1 for encoding error. */
173 static int
174 network_prefix(int ae, int plen, unsigned int omitted,
175 const unsigned char *p, const unsigned char *dp,
176 unsigned int len, unsigned char *p_r)
177 {
178 unsigned pb;
179 unsigned char prefix[16];
180 int consumed = 0;
181
182 if(plen >= 0)
183 pb = (plen + 7) / 8;
184 else if(ae == 1)
185 pb = 4;
186 else
187 pb = 16;
188
189 if(pb > 16)
190 return -1;
191
192 memset(prefix, 0, 16);
193
194 switch(ae) {
195 case 0: break;
196 case 1:
197 if(omitted > 4 || pb > 4 || (pb > omitted && len < pb - omitted))
198 return -1;
199 memcpy(prefix, v4prefix, 12);
200 if(omitted) {
201 if (dp == NULL) return -1;
202 memcpy(prefix, dp, 12 + omitted);
203 }
204 if(pb > omitted) {
205 memcpy(prefix + 12 + omitted, p, pb - omitted);
206 consumed = pb - omitted;
207 }
208 break;
209 case 2:
210 if(omitted > 16 || (pb > omitted && len < pb - omitted))
211 return -1;
212 if(omitted) {
213 if (dp == NULL) return -1;
214 memcpy(prefix, dp, omitted);
215 }
216 if(pb > omitted) {
217 memcpy(prefix + omitted, p, pb - omitted);
218 consumed = pb - omitted;
219 }
220 break;
221 case 3:
222 if(pb > 8 && len < pb - 8) return -1;
223 prefix[0] = 0xfe;
224 prefix[1] = 0x80;
225 if(pb > 8) {
226 memcpy(prefix + 8, p, pb - 8);
227 consumed = pb - 8;
228 }
229 break;
230 default:
231 return -1;
232 }
233
234 memcpy(p_r, prefix, 16);
235 return consumed;
236 }
237
238 static int
239 network_address(int ae, const unsigned char *a, unsigned int len,
240 unsigned char *a_r)
241 {
242 return network_prefix(ae, -1, 0, a, NULL, len, a_r);
243 }
244
245 /*
246 * Sub-TLVs consume the "extra data" of Babel TLVs (see Section 4.3 of RFC6126),
247 * their encoding is similar to the encoding of TLVs, but the type namespace is
248 * different:
249 *
250 * o Type 0 stands for Pad1 sub-TLV with the same encoding as the Pad1 TLV.
251 * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV.
252 * o Type 2 stands for Diversity sub-TLV, which propagates diversity routing
253 * data. Its body is a variable-length sequence of 8-bit unsigned integers,
254 * each representing per-hop number of interferring radio channel for the
255 * prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel
256 * 255 interferes with any other channel.
257 * o Type 3 stands for Timestamp sub-TLV, used to compute RTT between
258 * neighbours. In the case of a Hello TLV, the body stores a 32-bits
259 * timestamp, while in the case of a IHU TLV, two 32-bits timestamps are
260 * stored.
261 *
262 * Sub-TLV types 0 and 1 are valid for any TLV type, whether sub-TLV type 2 is
263 * only valid for TLV type 8 (Update). Note that within an Update TLV a missing
264 * Diversity sub-TLV is not the same as a Diversity sub-TLV with an empty body.
265 * The former would mean a lack of any claims about the interference, and the
266 * latter would state that interference is definitely absent.
267 * A type 3 sub-TLV is valid both for Hello and IHU TLVs, though the exact
268 * semantic of the sub-TLV is different in each case.
269 */
270 static void
271 subtlvs_print(netdissect_options *ndo,
272 const u_char *cp, const u_char *ep, const uint8_t tlv_type)
273 {
274 uint8_t subtype, sublen;
275 const char *sep;
276 uint32_t t1, t2;
277
278 while (cp < ep) {
279 subtype = EXTRACT_U_1(cp);
280 cp++;
281 if(subtype == MESSAGE_SUB_PAD1) {
282 ND_PRINT((ndo, " sub-pad1"));
283 continue;
284 }
285 if(cp == ep)
286 goto invalid;
287 sublen = EXTRACT_U_1(cp);
288 cp++;
289 if(cp + sublen > ep)
290 goto invalid;
291
292 switch(subtype) {
293 case MESSAGE_SUB_PADN:
294 ND_PRINT((ndo, " sub-padn"));
295 cp += sublen;
296 break;
297 case MESSAGE_SUB_DIVERSITY:
298 ND_PRINT((ndo, " sub-diversity"));
299 if (sublen == 0) {
300 ND_PRINT((ndo, " empty"));
301 break;
302 }
303 sep = " ";
304 while(sublen--) {
305 ND_PRINT((ndo, "%s%s", sep, tok2str(diversity_str, "%u", EXTRACT_U_1(cp))));
306 cp++;
307 sep = "-";
308 }
309 if(tlv_type != MESSAGE_UPDATE &&
310 tlv_type != MESSAGE_UPDATE_SRC_SPECIFIC)
311 ND_PRINT((ndo, " (bogus)"));
312 break;
313 case MESSAGE_SUB_TIMESTAMP:
314 ND_PRINT((ndo, " sub-timestamp"));
315 if(tlv_type == MESSAGE_HELLO) {
316 if(sublen < 4)
317 goto invalid;
318 t1 = EXTRACT_BE_U_4(cp);
319 ND_PRINT((ndo, " %s", format_timestamp(t1)));
320 } else if(tlv_type == MESSAGE_IHU) {
321 if(sublen < 8)
322 goto invalid;
323 t1 = EXTRACT_BE_U_4(cp);
324 ND_PRINT((ndo, " %s", format_timestamp(t1)));
325 t2 = EXTRACT_BE_U_4(cp + 4);
326 ND_PRINT((ndo, "|%s", format_timestamp(t2)));
327 } else
328 ND_PRINT((ndo, " (bogus)"));
329 cp += sublen;
330 break;
331 default:
332 ND_PRINT((ndo, " sub-unknown-0x%02x", subtype));
333 cp += sublen;
334 } /* switch */
335 } /* while */
336 return;
337
338 invalid:
339 ND_PRINT((ndo, "%s", istr));
340 }
341
342 #define ICHECK(i, l) \
343 if ((i) + (l) > bodylen || (i) + (l) > length) goto invalid;
344
345 static void
346 babel_print_v2(netdissect_options *ndo,
347 const u_char *cp, u_int length)
348 {
349 u_int i;
350 u_short bodylen;
351 u_char v4_prefix[16] =
352 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
353 u_char v6_prefix[16] = {0};
354
355 ND_TCHECK_4(cp);
356 if (length < 4)
357 goto invalid;
358 bodylen = EXTRACT_BE_U_2(cp + 2);
359 ND_PRINT((ndo, " (%u)", bodylen));
360
361 /* Process the TLVs in the body */
362 i = 0;
363 while(i < bodylen) {
364 const u_char *message;
365 u_int type, len;
366
367 message = cp + 4 + i;
368
369 ND_TCHECK_1(message);
370 if((type = EXTRACT_U_1(message)) == MESSAGE_PAD1) {
371 ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
372 i += 1;
373 continue;
374 }
375
376 ND_TCHECK_2(message);
377 ICHECK(i, 2);
378 len = EXTRACT_U_1(message + 1);
379
380 ND_TCHECK2(*message, 2 + len);
381 ICHECK(i, 2 + len);
382
383 switch(type) {
384 case MESSAGE_PADN: {
385 if (!ndo->ndo_vflag)
386 ND_PRINT((ndo, " padN"));
387 else
388 ND_PRINT((ndo, "\n\tPad %d", len + 2));
389 }
390 break;
391
392 case MESSAGE_ACK_REQ: {
393 u_short nonce, interval;
394 if (!ndo->ndo_vflag)
395 ND_PRINT((ndo, " ack-req"));
396 else {
397 ND_PRINT((ndo, "\n\tAcknowledgment Request "));
398 if(len < 6) goto invalid;
399 nonce = EXTRACT_BE_U_2(message + 4);
400 interval = EXTRACT_BE_U_2(message + 6);
401 ND_PRINT((ndo, "%04x %s", nonce, format_interval(interval)));
402 }
403 }
404 break;
405
406 case MESSAGE_ACK: {
407 u_short nonce;
408 if (!ndo->ndo_vflag)
409 ND_PRINT((ndo, " ack"));
410 else {
411 ND_PRINT((ndo, "\n\tAcknowledgment "));
412 if(len < 2) goto invalid;
413 nonce = EXTRACT_BE_U_2(message + 2);
414 ND_PRINT((ndo, "%04x", nonce));
415 }
416 }
417 break;
418
419 case MESSAGE_HELLO: {
420 u_short seqno, interval;
421 if (!ndo->ndo_vflag)
422 ND_PRINT((ndo, " hello"));
423 else {
424 ND_PRINT((ndo, "\n\tHello "));
425 if(len < 6) goto invalid;
426 seqno = EXTRACT_BE_U_2(message + 4);
427 interval = EXTRACT_BE_U_2(message + 6);
428 ND_PRINT((ndo, "seqno %u interval %s", seqno, format_interval(interval)));
429 /* Extra data. */
430 if(len > 6)
431 subtlvs_print(ndo, message + 8, message + 2 + len, type);
432 }
433 }
434 break;
435
436 case MESSAGE_IHU: {
437 unsigned short txcost, interval;
438 if (!ndo->ndo_vflag)
439 ND_PRINT((ndo, " ihu"));
440 else {
441 u_char address[16];
442 int rc;
443 ND_PRINT((ndo, "\n\tIHU "));
444 if(len < 6) goto invalid;
445 txcost = EXTRACT_BE_U_2(message + 4);
446 interval = EXTRACT_BE_U_2(message + 6);
447 rc = network_address(EXTRACT_U_1(message + 2), message + 8,
448 len - 6, address);
449 if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
450 ND_PRINT((ndo, "%s txcost %u interval %s",
451 format_address(ndo, address), txcost, format_interval(interval)));
452 /* Extra data. */
453 if((u_int)rc < len - 6)
454 subtlvs_print(ndo, message + 8 + rc, message + 2 + len,
455 type);
456 }
457 }
458 break;
459
460 case MESSAGE_ROUTER_ID: {
461 if (!ndo->ndo_vflag)
462 ND_PRINT((ndo, " router-id"));
463 else {
464 ND_PRINT((ndo, "\n\tRouter Id"));
465 if(len < 10) goto invalid;
466 ND_PRINT((ndo, " %s", format_id(message + 4)));
467 }
468 }
469 break;
470
471 case MESSAGE_NH: {
472 if (!ndo->ndo_vflag)
473 ND_PRINT((ndo, " nh"));
474 else {
475 int rc;
476 u_char nh[16];
477 ND_PRINT((ndo, "\n\tNext Hop"));
478 if(len < 2) goto invalid;
479 rc = network_address(EXTRACT_U_1(message + 2), message + 4,
480 len - 2, nh);
481 if(rc < 0) goto invalid;
482 ND_PRINT((ndo, " %s", format_address(ndo, nh)));
483 }
484 }
485 break;
486
487 case MESSAGE_UPDATE: {
488 if (!ndo->ndo_vflag) {
489 ND_PRINT((ndo, " update"));
490 if(len < 1)
491 ND_PRINT((ndo, "/truncated"));
492 else
493 ND_PRINT((ndo, "%s%s%s",
494 (EXTRACT_U_1(message + 3) & 0x80) ? "/prefix": "",
495 (EXTRACT_U_1(message + 3) & 0x40) ? "/id" : "",
496 (EXTRACT_U_1(message + 3) & 0x3f) ? "/unknown" : ""));
497 } else {
498 u_short interval, seqno, metric;
499 u_char plen;
500 int rc;
501 u_char prefix[16];
502 ND_PRINT((ndo, "\n\tUpdate"));
503 if(len < 10) goto invalid;
504 plen = EXTRACT_U_1(message + 4) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
505 rc = network_prefix(EXTRACT_U_1(message + 2),
506 EXTRACT_U_1(message + 4),
507 EXTRACT_U_1(message + 5),
508 message + 12,
509 EXTRACT_U_1(message + 2) == 1 ? v4_prefix : v6_prefix,
510 len - 10, prefix);
511 if(rc < 0) goto invalid;
512 interval = EXTRACT_BE_U_2(message + 6);
513 seqno = EXTRACT_BE_U_2(message + 8);
514 metric = EXTRACT_BE_U_2(message + 10);
515 ND_PRINT((ndo, "%s%s%s %s metric %u seqno %u interval %s",
516 (EXTRACT_U_1(message + 3) & 0x80) ? "/prefix": "",
517 (EXTRACT_U_1(message + 3) & 0x40) ? "/id" : "",
518 (EXTRACT_U_1(message + 3) & 0x3f) ? "/unknown" : "",
519 format_prefix(ndo, prefix, plen),
520 metric, seqno, format_interval_update(interval)));
521 if(EXTRACT_U_1(message + 3) & 0x80) {
522 if(message[2] == 1)
523 memcpy(v4_prefix, prefix, 16);
524 else
525 memcpy(v6_prefix, prefix, 16);
526 }
527 /* extra data? */
528 if((u_int)rc < len - 10)
529 subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type);
530 }
531 }
532 break;
533
534 case MESSAGE_REQUEST: {
535 if (!ndo->ndo_vflag)
536 ND_PRINT((ndo, " request"));
537 else {
538 int rc;
539 u_char prefix[16], plen;
540 ND_PRINT((ndo, "\n\tRequest "));
541 if(len < 2) goto invalid;
542 plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
543 rc = network_prefix(EXTRACT_U_1(message + 2),
544 EXTRACT_U_1(message + 3), 0,
545 message + 4, NULL, len - 2, prefix);
546 if(rc < 0) goto invalid;
547 ND_PRINT((ndo, "for %s",
548 EXTRACT_U_1(message + 2) == 0 ? "any" : format_prefix(ndo, prefix, plen)));
549 }
550 }
551 break;
552
553 case MESSAGE_MH_REQUEST : {
554 if (!ndo->ndo_vflag)
555 ND_PRINT((ndo, " mh-request"));
556 else {
557 int rc;
558 u_short seqno;
559 u_char prefix[16], plen;
560 ND_PRINT((ndo, "\n\tMH-Request "));
561 if(len < 14) goto invalid;
562 seqno = EXTRACT_BE_U_2(message + 4);
563 rc = network_prefix(EXTRACT_U_1(message + 2),
564 EXTRACT_U_1(message + 3), 0,
565 message + 16, NULL, len - 14, prefix);
566 if(rc < 0) goto invalid;
567 plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0);
568 ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
569 EXTRACT_U_1(message + 6), format_prefix(ndo, prefix, plen),
570 seqno, format_id(message + 8)));
571 }
572 }
573 break;
574 case MESSAGE_TSPC :
575 if (!ndo->ndo_vflag)
576 ND_PRINT((ndo, " tspc"));
577 else {
578 ND_PRINT((ndo, "\n\tTS/PC "));
579 if(len < 6) goto invalid;
580 ND_PRINT((ndo, "timestamp %u packetcounter %u", EXTRACT_BE_U_4(message + 4),
581 EXTRACT_BE_U_2(message + 2)));
582 }
583 break;
584 case MESSAGE_HMAC : {
585 if (!ndo->ndo_vflag)
586 ND_PRINT((ndo, " hmac"));
587 else {
588 unsigned j;
589 ND_PRINT((ndo, "\n\tHMAC "));
590 if(len < 18) goto invalid;
591 ND_PRINT((ndo, "key-id %u digest-%u ", EXTRACT_BE_U_2(message + 2), len - 2));
592 for (j = 0; j < len - 2; j++)
593 ND_PRINT((ndo, "%02X", EXTRACT_U_1(message + j + 4)));
594 }
595 }
596 break;
597
598 case MESSAGE_UPDATE_SRC_SPECIFIC : {
599 if(!ndo->ndo_vflag) {
600 ND_PRINT((ndo, " ss-update"));
601 } else {
602 u_char prefix[16], src_prefix[16];
603 u_short interval, seqno, metric;
604 u_char ae, plen, src_plen, omitted;
605 int rc;
606 int parsed_len = 10;
607 ND_PRINT((ndo, "\n\tSS-Update"));
608 if(len < 10) goto invalid;
609 ae = EXTRACT_U_1(message + 2);
610 src_plen = EXTRACT_U_1(message + 3);
611 plen = EXTRACT_U_1(message + 4);
612 omitted = EXTRACT_U_1(message + 5);
613 interval = EXTRACT_BE_U_2(message + 6);
614 seqno = EXTRACT_BE_U_2(message + 8);
615 metric = EXTRACT_BE_U_2(message + 10);
616 rc = network_prefix(ae, plen, omitted, message + 2 + parsed_len,
617 ae == 1 ? v4_prefix : v6_prefix,
618 len - parsed_len, prefix);
619 if(rc < 0) goto invalid;
620 if(ae == 1)
621 plen += 96;
622 parsed_len += rc;
623 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
624 NULL, len - parsed_len, src_prefix);
625 if(rc < 0) goto invalid;
626 if(ae == 1)
627 src_plen += 96;
628 parsed_len += rc;
629
630 ND_PRINT((ndo, " %s from", format_prefix(ndo, prefix, plen)));
631 ND_PRINT((ndo, " %s metric %u seqno %u interval %s",
632 format_prefix(ndo, src_prefix, src_plen),
633 metric, seqno, format_interval_update(interval)));
634 /* extra data? */
635 if((u_int)parsed_len < len)
636 subtlvs_print(ndo, message + 2 + parsed_len,
637 message + 2 + len, type);
638 }
639 }
640 break;
641
642 case MESSAGE_REQUEST_SRC_SPECIFIC : {
643 if(!ndo->ndo_vflag)
644 ND_PRINT((ndo, " ss-request"));
645 else {
646 int rc, parsed_len = 3;
647 u_char ae, plen, src_plen, prefix[16], src_prefix[16];
648 ND_PRINT((ndo, "\n\tSS-Request "));
649 if(len < 3) goto invalid;
650 ae = EXTRACT_U_1(message + 2);
651 plen = EXTRACT_U_1(message + 3);
652 src_plen = EXTRACT_U_1(message + 4);
653 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
654 NULL, len - parsed_len, prefix);
655 if(rc < 0) goto invalid;
656 if(ae == 1)
657 plen += 96;
658 parsed_len += rc;
659 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
660 NULL, len - parsed_len, src_prefix);
661 if(rc < 0) goto invalid;
662 if(ae == 1)
663 src_plen += 96;
664 parsed_len += rc;
665 if(ae == 0) {
666 ND_PRINT((ndo, "for any"));
667 } else {
668 ND_PRINT((ndo, "for (%s, ", format_prefix(ndo, prefix, plen)));
669 ND_PRINT((ndo, "%s)", format_prefix(ndo, src_prefix, src_plen)));
670 }
671 }
672 }
673 break;
674
675 case MESSAGE_MH_REQUEST_SRC_SPECIFIC : {
676 if(!ndo->ndo_vflag)
677 ND_PRINT((ndo, " ss-mh-request"));
678 else {
679 int rc, parsed_len = 14;
680 u_short seqno;
681 u_char ae, plen, src_plen, prefix[16], src_prefix[16], hopc;
682 const u_char *router_id = NULL;
683 ND_PRINT((ndo, "\n\tSS-MH-Request "));
684 if(len < 14) goto invalid;
685 ae = EXTRACT_U_1(message + 2);
686 plen = EXTRACT_U_1(message + 3);
687 seqno = EXTRACT_BE_U_2(message + 4);
688 hopc = EXTRACT_U_1(message + 6);
689 src_plen = EXTRACT_U_1(message + 7);
690 router_id = message + 8;
691 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
692 NULL, len - parsed_len, prefix);
693 if(rc < 0) goto invalid;
694 if(ae == 1)
695 plen += 96;
696 parsed_len += rc;
697 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
698 NULL, len - parsed_len, src_prefix);
699 if(rc < 0) goto invalid;
700 if(ae == 1)
701 src_plen += 96;
702 ND_PRINT((ndo, "(%u hops) for (%s, ",
703 hopc, format_prefix(ndo, prefix, plen)));
704 ND_PRINT((ndo, "%s) seqno %u id %s",
705 format_prefix(ndo, src_prefix, src_plen),
706 seqno, format_id(router_id)));
707 }
708 }
709 break;
710
711 default:
712 if (!ndo->ndo_vflag)
713 ND_PRINT((ndo, " unknown"));
714 else
715 ND_PRINT((ndo, "\n\tUnknown message type %d", type));
716 }
717 i += len + 2;
718 }
719 return;
720
721 trunc:
722 ND_PRINT((ndo, " %s", tstr));
723 return;
724
725 invalid:
726 ND_PRINT((ndo, "%s", istr));
727 return;
728 }