xref: /netbsd-src/external/bsd/tcpdump/dist/print-babel.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
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 #include <sys/cdefs.h>
30 #ifndef lint
31 __RCSID("$NetBSD: print-babel.c,v 1.3 2017/02/05 04:05:05 spz Exp $");
32 #endif
33 
34 /* \summary: Babel Routing Protocol printer */
35 
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39 
40 #include <netdissect-stdinc.h>
41 
42 #include <stdio.h>
43 #include <string.h>
44 
45 #include "netdissect.h"
46 #include "addrtoname.h"
47 #include "extract.h"
48 
49 static const char tstr[] = "[|babel]";
50 
51 static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length);
52 
53 void
54 babel_print(netdissect_options *ndo,
55             const u_char *cp, u_int length)
56 {
57     ND_PRINT((ndo, "babel"));
58 
59     ND_TCHECK2(*cp, 4);
60 
61     if(cp[0] != 42) {
62         ND_PRINT((ndo, " invalid header"));
63         return;
64     } else {
65         ND_PRINT((ndo, " %d", cp[1]));
66     }
67 
68     switch(cp[1]) {
69     case 2:
70         babel_print_v2(ndo, cp, length);
71         break;
72     default:
73         ND_PRINT((ndo, " unknown version"));
74         break;
75     }
76 
77     return;
78 
79  trunc:
80     ND_PRINT((ndo, " %s", tstr));
81     return;
82 }
83 
84 /* TLVs */
85 #define MESSAGE_PAD1 0
86 #define MESSAGE_PADN 1
87 #define MESSAGE_ACK_REQ 2
88 #define MESSAGE_ACK 3
89 #define MESSAGE_HELLO 4
90 #define MESSAGE_IHU 5
91 #define MESSAGE_ROUTER_ID 6
92 #define MESSAGE_NH 7
93 #define MESSAGE_UPDATE 8
94 #define MESSAGE_REQUEST 9
95 #define MESSAGE_MH_REQUEST 10
96 #define MESSAGE_TSPC 11
97 #define MESSAGE_HMAC 12
98 #define MESSAGE_UPDATE_SRC_SPECIFIC 13
99 #define MESSAGE_REQUEST_SRC_SPECIFIC 14
100 #define MESSAGE_MH_REQUEST_SRC_SPECIFIC 15
101 
102 /* sub-TLVs */
103 #define MESSAGE_SUB_PAD1 0
104 #define MESSAGE_SUB_PADN 1
105 #define MESSAGE_SUB_DIVERSITY 2
106 #define MESSAGE_SUB_TIMESTAMP 3
107 
108 /* Diversity sub-TLV channel codes */
109 static const struct tok diversity_str[] = {
110     { 0,   "reserved" },
111     { 255, "all"      },
112     { 0, NULL }
113 };
114 
115 static const char *
116 format_id(const u_char *id)
117 {
118     static char buf[25];
119     snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
120              id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
121     buf[24] = '\0';
122     return buf;
123 }
124 
125 static const unsigned char v4prefix[16] =
126     {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
127 
128 static const char *
129 format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen)
130 {
131     static char buf[50];
132     if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0)
133         snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96);
134     else
135         snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen);
136     buf[49] = '\0';
137     return buf;
138 }
139 
140 static const char *
141 format_address(netdissect_options *ndo, const u_char *prefix)
142 {
143     if(memcmp(prefix, v4prefix, 12) == 0)
144         return ipaddr_string(ndo, prefix + 12);
145     else
146         return ip6addr_string(ndo, prefix);
147 }
148 
149 static const char *
150 format_interval(const uint16_t i)
151 {
152     static char buf[sizeof("000.00s")];
153 
154     if (i == 0)
155         return "0.0s (bogus)";
156     snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100);
157     return buf;
158 }
159 
160 static const char *
161 format_interval_update(const uint16_t i)
162 {
163     return i == 0xFFFF ? "infinity" : format_interval(i);
164 }
165 
166 static const char *
167 format_timestamp(const uint32_t i)
168 {
169     static char buf[sizeof("0000.000000s")];
170     snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000);
171     return buf;
172 }
173 
174 /* Return number of octets consumed from the input buffer (not the prefix length
175  * in bytes), or -1 for encoding error. */
176 static int
177 network_prefix(int ae, int plen, unsigned int omitted,
178                const unsigned char *p, const unsigned char *dp,
179                unsigned int len, unsigned char *p_r)
180 {
181     unsigned pb;
182     unsigned char prefix[16];
183     int consumed = 0;
184 
185     if(plen >= 0)
186         pb = (plen + 7) / 8;
187     else if(ae == 1)
188         pb = 4;
189     else
190         pb = 16;
191 
192     if(pb > 16)
193         return -1;
194 
195     memset(prefix, 0, 16);
196 
197     switch(ae) {
198     case 0: break;
199     case 1:
200         if(omitted > 4 || pb > 4 || (pb > omitted && len < pb - omitted))
201             return -1;
202         memcpy(prefix, v4prefix, 12);
203         if(omitted) {
204             if (dp == NULL) return -1;
205             memcpy(prefix, dp, 12 + omitted);
206         }
207         if(pb > omitted) {
208             memcpy(prefix + 12 + omitted, p, pb - omitted);
209             consumed = pb - omitted;
210         }
211         break;
212     case 2:
213         if(omitted > 16 || (pb > omitted && len < pb - omitted))
214             return -1;
215         if(omitted) {
216             if (dp == NULL) return -1;
217             memcpy(prefix, dp, omitted);
218         }
219         if(pb > omitted) {
220             memcpy(prefix + omitted, p, pb - omitted);
221             consumed = pb - omitted;
222         }
223         break;
224     case 3:
225         if(pb > 8 && len < pb - 8) return -1;
226         prefix[0] = 0xfe;
227         prefix[1] = 0x80;
228         if(pb > 8) {
229             memcpy(prefix + 8, p, pb - 8);
230             consumed = pb - 8;
231         }
232         break;
233     default:
234         return -1;
235     }
236 
237     memcpy(p_r, prefix, 16);
238     return consumed;
239 }
240 
241 static int
242 network_address(int ae, const unsigned char *a, unsigned int len,
243                 unsigned char *a_r)
244 {
245     return network_prefix(ae, -1, 0, a, NULL, len, a_r);
246 }
247 
248 /*
249  * Sub-TLVs consume the "extra data" of Babel TLVs (see Section 4.3 of RFC6126),
250  * their encoding is similar to the encoding of TLVs, but the type namespace is
251  * different:
252  *
253  * o Type 0 stands for Pad1 sub-TLV with the same encoding as the Pad1 TLV.
254  * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV.
255  * o Type 2 stands for Diversity sub-TLV, which propagates diversity routing
256  *   data. Its body is a variable-length sequence of 8-bit unsigned integers,
257  *   each representing per-hop number of interferring radio channel for the
258  *   prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel
259  *   255 interferes with any other channel.
260  * o Type 3 stands for Timestamp sub-TLV, used to compute RTT between
261  *   neighbours. In the case of a Hello TLV, the body stores a 32-bits
262  *   timestamp, while in the case of a IHU TLV, two 32-bits timestamps are
263  *   stored.
264  *
265  * Sub-TLV types 0 and 1 are valid for any TLV type, whether sub-TLV type 2 is
266  * only valid for TLV type 8 (Update). Note that within an Update TLV a missing
267  * Diversity sub-TLV is not the same as a Diversity sub-TLV with an empty body.
268  * The former would mean a lack of any claims about the interference, and the
269  * latter would state that interference is definitely absent.
270  * A type 3 sub-TLV is valid both for Hello and IHU TLVs, though the exact
271  * semantic of the sub-TLV is different in each case.
272  */
273 static void
274 subtlvs_print(netdissect_options *ndo,
275               const u_char *cp, const u_char *ep, const uint8_t tlv_type)
276 {
277     uint8_t subtype, sublen;
278     const char *sep;
279     uint32_t t1, t2;
280 
281     while (cp < ep) {
282         subtype = *cp++;
283         if(subtype == MESSAGE_SUB_PAD1) {
284             ND_PRINT((ndo, " sub-pad1"));
285             continue;
286         }
287         if(cp == ep)
288             goto invalid;
289         sublen = *cp++;
290         if(cp + sublen > ep)
291             goto invalid;
292 
293         switch(subtype) {
294         case MESSAGE_SUB_PADN:
295             ND_PRINT((ndo, " sub-padn"));
296             cp += sublen;
297             break;
298         case MESSAGE_SUB_DIVERSITY:
299             ND_PRINT((ndo, " sub-diversity"));
300             if (sublen == 0) {
301                 ND_PRINT((ndo, " empty"));
302                 break;
303             }
304             sep = " ";
305             while(sublen--) {
306                 ND_PRINT((ndo, "%s%s", sep, tok2str(diversity_str, "%u", *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_32BITS(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_32BITS(cp);
324                 ND_PRINT((ndo, " %s", format_timestamp(t1)));
325                 t2 = EXTRACT_32BITS(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_TCHECK2(*cp, 4);
356     if (length < 4)
357         goto invalid;
358     bodylen = EXTRACT_16BITS(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_TCHECK2(*message, 1);
370         if((type = message[0]) == MESSAGE_PAD1) {
371             ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
372             i += 1;
373             continue;
374         }
375 
376         ND_TCHECK2(*message, 2);
377         ICHECK(i, 2);
378         len = 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_16BITS(message + 4);
400                 interval = EXTRACT_16BITS(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_16BITS(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_16BITS(message + 4);
427                 interval = EXTRACT_16BITS(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_16BITS(message + 4);
446                 interval = EXTRACT_16BITS(message + 6);
447                 rc = network_address(message[2], message + 8, len - 6, address);
448                 if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
449                 ND_PRINT((ndo, "%s txcost %u interval %s",
450                        format_address(ndo, address), txcost, format_interval(interval)));
451                 /* Extra data. */
452                 if((u_int)rc < len - 6)
453                     subtlvs_print(ndo, message + 8 + rc, message + 2 + len,
454                                   type);
455             }
456         }
457             break;
458 
459         case MESSAGE_ROUTER_ID: {
460             if (!ndo->ndo_vflag)
461                 ND_PRINT((ndo, " router-id"));
462             else {
463                 ND_PRINT((ndo, "\n\tRouter Id"));
464                 if(len < 10) goto invalid;
465                 ND_PRINT((ndo, " %s", format_id(message + 4)));
466             }
467         }
468             break;
469 
470         case MESSAGE_NH: {
471             if (!ndo->ndo_vflag)
472                 ND_PRINT((ndo, " nh"));
473             else {
474                 int rc;
475                 u_char nh[16];
476                 ND_PRINT((ndo, "\n\tNext Hop"));
477                 if(len < 2) goto invalid;
478                 rc = network_address(message[2], message + 4, len - 2, nh);
479                 if(rc < 0) goto invalid;
480                 ND_PRINT((ndo, " %s", format_address(ndo, nh)));
481             }
482         }
483             break;
484 
485         case MESSAGE_UPDATE: {
486             if (!ndo->ndo_vflag) {
487                 ND_PRINT((ndo, " update"));
488                 if(len < 1)
489                     ND_PRINT((ndo, "/truncated"));
490                 else
491                     ND_PRINT((ndo, "%s%s%s",
492                            (message[3] & 0x80) ? "/prefix": "",
493                            (message[3] & 0x40) ? "/id" : "",
494                            (message[3] & 0x3f) ? "/unknown" : ""));
495             } else {
496                 u_short interval, seqno, metric;
497                 u_char plen;
498                 int rc;
499                 u_char prefix[16];
500                 ND_PRINT((ndo, "\n\tUpdate"));
501                 if(len < 10) goto invalid;
502                 plen = message[4] + (message[2] == 1 ? 96 : 0);
503                 rc = network_prefix(message[2], message[4], message[5],
504                                     message + 12,
505                                     message[2] == 1 ? v4_prefix : v6_prefix,
506                                     len - 10, prefix);
507                 if(rc < 0) goto invalid;
508                 interval = EXTRACT_16BITS(message + 6);
509                 seqno = EXTRACT_16BITS(message + 8);
510                 metric = EXTRACT_16BITS(message + 10);
511                 ND_PRINT((ndo, "%s%s%s %s metric %u seqno %u interval %s",
512                        (message[3] & 0x80) ? "/prefix": "",
513                        (message[3] & 0x40) ? "/id" : "",
514                        (message[3] & 0x3f) ? "/unknown" : "",
515                        format_prefix(ndo, prefix, plen),
516                        metric, seqno, format_interval_update(interval)));
517                 if(message[3] & 0x80) {
518                     if(message[2] == 1)
519                         memcpy(v4_prefix, prefix, 16);
520                     else
521                         memcpy(v6_prefix, prefix, 16);
522                 }
523                 /* extra data? */
524                 if((u_int)rc < len - 10)
525                     subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type);
526             }
527         }
528             break;
529 
530         case MESSAGE_REQUEST: {
531             if (!ndo->ndo_vflag)
532                 ND_PRINT((ndo, " request"));
533             else {
534                 int rc;
535                 u_char prefix[16], plen;
536                 ND_PRINT((ndo, "\n\tRequest "));
537                 if(len < 2) goto invalid;
538                 plen = message[3] + (message[2] == 1 ? 96 : 0);
539                 rc = network_prefix(message[2], message[3], 0,
540                                     message + 4, NULL, len - 2, prefix);
541                 if(rc < 0) goto invalid;
542                 ND_PRINT((ndo, "for %s",
543                        message[2] == 0 ? "any" : format_prefix(ndo, prefix, plen)));
544             }
545         }
546             break;
547 
548         case MESSAGE_MH_REQUEST : {
549             if (!ndo->ndo_vflag)
550                 ND_PRINT((ndo, " mh-request"));
551             else {
552                 int rc;
553                 u_short seqno;
554                 u_char prefix[16], plen;
555                 ND_PRINT((ndo, "\n\tMH-Request "));
556                 if(len < 14) goto invalid;
557                 seqno = EXTRACT_16BITS(message + 4);
558                 rc = network_prefix(message[2], message[3], 0,
559                                     message + 16, NULL, len - 14, prefix);
560                 if(rc < 0) goto invalid;
561                 plen = message[3] + (message[2] == 1 ? 96 : 0);
562                 ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
563                        message[6], format_prefix(ndo, prefix, plen),
564                        seqno, format_id(message + 8)));
565             }
566         }
567             break;
568         case MESSAGE_TSPC :
569             if (!ndo->ndo_vflag)
570                 ND_PRINT((ndo, " tspc"));
571             else {
572                 ND_PRINT((ndo, "\n\tTS/PC "));
573                 if(len < 6) goto invalid;
574                 ND_PRINT((ndo, "timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
575                        EXTRACT_16BITS(message + 2)));
576             }
577             break;
578         case MESSAGE_HMAC : {
579             if (!ndo->ndo_vflag)
580                 ND_PRINT((ndo, " hmac"));
581             else {
582                 unsigned j;
583                 ND_PRINT((ndo, "\n\tHMAC "));
584                 if(len < 18) goto invalid;
585                 ND_PRINT((ndo, "key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2));
586                 for (j = 0; j < len - 2; j++)
587                     ND_PRINT((ndo, "%02X", message[4 + j]));
588             }
589         }
590             break;
591 
592         case MESSAGE_UPDATE_SRC_SPECIFIC : {
593             if(!ndo->ndo_vflag) {
594                 ND_PRINT((ndo, " ss-update"));
595             } else {
596                 u_char prefix[16], src_prefix[16];
597                 u_short interval, seqno, metric;
598                 u_char ae, plen, src_plen, omitted;
599                 int rc;
600                 int parsed_len = 10;
601                 ND_PRINT((ndo, "\n\tSS-Update"));
602                 if(len < 10) goto invalid;
603                 ae = message[2];
604                 src_plen = message[3];
605                 plen = message[4];
606                 omitted = message[5];
607                 interval = EXTRACT_16BITS(message + 6);
608                 seqno = EXTRACT_16BITS(message + 8);
609                 metric = EXTRACT_16BITS(message + 10);
610                 rc = network_prefix(ae, plen, omitted, message + 2 + parsed_len,
611                                     ae == 1 ? v4_prefix : v6_prefix,
612                                     len - parsed_len, prefix);
613                 if(rc < 0) goto invalid;
614                 if(ae == 1)
615                     plen += 96;
616                 parsed_len += rc;
617                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
618                                     NULL, len - parsed_len, src_prefix);
619                 if(rc < 0) goto invalid;
620                 if(ae == 1)
621                     src_plen += 96;
622                 parsed_len += rc;
623 
624                 ND_PRINT((ndo, " %s from", format_prefix(ndo, prefix, plen)));
625                 ND_PRINT((ndo, " %s metric %u seqno %u interval %s",
626                           format_prefix(ndo, src_prefix, src_plen),
627                           metric, seqno, format_interval_update(interval)));
628                 /* extra data? */
629                 if((u_int)parsed_len < len)
630                     subtlvs_print(ndo, message + 2 + parsed_len,
631                                   message + 2 + len, type);
632             }
633         }
634             break;
635 
636         case MESSAGE_REQUEST_SRC_SPECIFIC : {
637             if(!ndo->ndo_vflag)
638                 ND_PRINT((ndo, " ss-request"));
639             else {
640                 int rc, parsed_len = 3;
641                 u_char ae, plen, src_plen, prefix[16], src_prefix[16];
642                 ND_PRINT((ndo, "\n\tSS-Request "));
643                 if(len < 3) goto invalid;
644                 ae = message[2];
645                 plen = message[3];
646                 src_plen = message[4];
647                 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
648                                     NULL, len - parsed_len, prefix);
649                 if(rc < 0) goto invalid;
650                 if(ae == 1)
651                     plen += 96;
652                 parsed_len += rc;
653                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
654                                     NULL, len - parsed_len, src_prefix);
655                 if(rc < 0) goto invalid;
656                 if(ae == 1)
657                     src_plen += 96;
658                 parsed_len += rc;
659                 if(ae == 0) {
660                     ND_PRINT((ndo, "for any"));
661                 } else {
662                     ND_PRINT((ndo, "for (%s, ", format_prefix(ndo, prefix, plen)));
663                     ND_PRINT((ndo, "%s)", format_prefix(ndo, src_prefix, src_plen)));
664                 }
665             }
666         }
667             break;
668 
669         case MESSAGE_MH_REQUEST_SRC_SPECIFIC : {
670             if(!ndo->ndo_vflag)
671                 ND_PRINT((ndo, " ss-mh-request"));
672             else {
673                 int rc, parsed_len = 14;
674                 u_short seqno;
675                 u_char ae, plen, src_plen, prefix[16], src_prefix[16], hopc;
676                 const u_char *router_id = NULL;
677                 ND_PRINT((ndo, "\n\tSS-MH-Request "));
678                 if(len < 14) goto invalid;
679                 ae = message[2];
680                 plen = message[3];
681                 seqno = EXTRACT_16BITS(message + 4);
682                 hopc = message[6];
683                 src_plen = message[7];
684                 router_id = message + 8;
685                 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
686                                     NULL, len - parsed_len, prefix);
687                 if(rc < 0) goto invalid;
688                 if(ae == 1)
689                     plen += 96;
690                 parsed_len += rc;
691                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
692                                     NULL, len - parsed_len, src_prefix);
693                 if(rc < 0) goto invalid;
694                 if(ae == 1)
695                     src_plen += 96;
696                 ND_PRINT((ndo, "(%u hops) for (%s, ",
697                           hopc, format_prefix(ndo, prefix, plen)));
698                 ND_PRINT((ndo, "%s) seqno %u id %s",
699                           format_prefix(ndo, src_prefix, src_plen),
700                           seqno, format_id(router_id)));
701             }
702         }
703             break;
704 
705         default:
706             if (!ndo->ndo_vflag)
707                 ND_PRINT((ndo, " unknown"));
708             else
709                 ND_PRINT((ndo, "\n\tUnknown message type %d", type));
710         }
711         i += len + 2;
712     }
713     return;
714 
715  trunc:
716     ND_PRINT((ndo, " %s", tstr));
717     return;
718 
719  invalid:
720     ND_PRINT((ndo, "%s", istr));
721     return;
722 }
723