xref: /netbsd-src/external/bsd/tcpdump/dist/print-babel.c (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
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.4 2019/10/01 16:06:16 christos 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     if (4U + bodylen > length)
361         goto invalid;
362 
363     /* Process the TLVs in the body */
364     i = 0;
365     while(i < bodylen) {
366         const u_char *message;
367         u_int type, len;
368 
369         message = cp + 4 + i;
370 
371         ND_TCHECK2(*message, 1);
372         if((type = message[0]) == MESSAGE_PAD1) {
373             ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
374             i += 1;
375             continue;
376         }
377 
378         ND_TCHECK2(*message, 2);
379         ICHECK(i, 2);
380         len = message[1];
381 
382         ND_TCHECK2(*message, 2 + len);
383         ICHECK(i, 2 + len);
384 
385         switch(type) {
386         case MESSAGE_PADN: {
387             if (!ndo->ndo_vflag)
388                 ND_PRINT((ndo, " padN"));
389             else
390                 ND_PRINT((ndo, "\n\tPad %d", len + 2));
391         }
392             break;
393 
394         case MESSAGE_ACK_REQ: {
395             u_short nonce, interval;
396             if (!ndo->ndo_vflag)
397                 ND_PRINT((ndo, " ack-req"));
398             else {
399                 ND_PRINT((ndo, "\n\tAcknowledgment Request "));
400                 if(len < 6) goto invalid;
401                 nonce = EXTRACT_16BITS(message + 4);
402                 interval = EXTRACT_16BITS(message + 6);
403                 ND_PRINT((ndo, "%04x %s", nonce, format_interval(interval)));
404             }
405         }
406             break;
407 
408         case MESSAGE_ACK: {
409             u_short nonce;
410             if (!ndo->ndo_vflag)
411                 ND_PRINT((ndo, " ack"));
412             else {
413                 ND_PRINT((ndo, "\n\tAcknowledgment "));
414                 if(len < 2) goto invalid;
415                 nonce = EXTRACT_16BITS(message + 2);
416                 ND_PRINT((ndo, "%04x", nonce));
417             }
418         }
419             break;
420 
421         case MESSAGE_HELLO:  {
422             u_short seqno, interval;
423             if (!ndo->ndo_vflag)
424                 ND_PRINT((ndo, " hello"));
425             else {
426                 ND_PRINT((ndo, "\n\tHello "));
427                 if(len < 6) goto invalid;
428                 seqno = EXTRACT_16BITS(message + 4);
429                 interval = EXTRACT_16BITS(message + 6);
430                 ND_PRINT((ndo, "seqno %u interval %s", seqno, format_interval(interval)));
431                 /* Extra data. */
432                 if(len > 6)
433                     subtlvs_print(ndo, message + 8, message + 2 + len, type);
434             }
435         }
436             break;
437 
438         case MESSAGE_IHU: {
439             unsigned short txcost, interval;
440             if (!ndo->ndo_vflag)
441                 ND_PRINT((ndo, " ihu"));
442             else {
443                 u_char address[16];
444                 int rc;
445                 ND_PRINT((ndo, "\n\tIHU "));
446                 if(len < 6) goto invalid;
447                 txcost = EXTRACT_16BITS(message + 4);
448                 interval = EXTRACT_16BITS(message + 6);
449                 rc = network_address(message[2], message + 8, len - 6, address);
450                 if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
451                 ND_PRINT((ndo, "%s txcost %u interval %s",
452                        format_address(ndo, address), txcost, format_interval(interval)));
453                 /* Extra data. */
454                 if((u_int)rc < len - 6)
455                     subtlvs_print(ndo, message + 8 + rc, message + 2 + len,
456                                   type);
457             }
458         }
459             break;
460 
461         case MESSAGE_ROUTER_ID: {
462             if (!ndo->ndo_vflag)
463                 ND_PRINT((ndo, " router-id"));
464             else {
465                 ND_PRINT((ndo, "\n\tRouter Id"));
466                 if(len < 10) goto invalid;
467                 ND_PRINT((ndo, " %s", format_id(message + 4)));
468             }
469         }
470             break;
471 
472         case MESSAGE_NH: {
473             if (!ndo->ndo_vflag)
474                 ND_PRINT((ndo, " nh"));
475             else {
476                 int rc;
477                 u_char nh[16];
478                 ND_PRINT((ndo, "\n\tNext Hop"));
479                 if(len < 2) goto invalid;
480                 rc = network_address(message[2], message + 4, 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 < 10)
491                     ND_PRINT((ndo, "/truncated"));
492                 else
493                     ND_PRINT((ndo, "%s%s%s",
494                            (message[3] & 0x80) ? "/prefix": "",
495                            (message[3] & 0x40) ? "/id" : "",
496                            (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 = message[4] + (message[2] == 1 ? 96 : 0);
505                 rc = network_prefix(message[2], message[4], message[5],
506                                     message + 12,
507                                     message[2] == 1 ? v4_prefix : v6_prefix,
508                                     len - 10, prefix);
509                 if(rc < 0) goto invalid;
510                 interval = EXTRACT_16BITS(message + 6);
511                 seqno = EXTRACT_16BITS(message + 8);
512                 metric = EXTRACT_16BITS(message + 10);
513                 ND_PRINT((ndo, "%s%s%s %s metric %u seqno %u interval %s",
514                        (message[3] & 0x80) ? "/prefix": "",
515                        (message[3] & 0x40) ? "/id" : "",
516                        (message[3] & 0x3f) ? "/unknown" : "",
517                        format_prefix(ndo, prefix, plen),
518                        metric, seqno, format_interval_update(interval)));
519                 if(message[3] & 0x80) {
520                     if(message[2] == 1)
521                         memcpy(v4_prefix, prefix, 16);
522                     else
523                         memcpy(v6_prefix, prefix, 16);
524                 }
525                 /* extra data? */
526                 if((u_int)rc < len - 10)
527                     subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type);
528             }
529         }
530             break;
531 
532         case MESSAGE_REQUEST: {
533             if (!ndo->ndo_vflag)
534                 ND_PRINT((ndo, " request"));
535             else {
536                 int rc;
537                 u_char prefix[16], plen;
538                 ND_PRINT((ndo, "\n\tRequest "));
539                 if(len < 2) goto invalid;
540                 plen = message[3] + (message[2] == 1 ? 96 : 0);
541                 rc = network_prefix(message[2], message[3], 0,
542                                     message + 4, NULL, len - 2, prefix);
543                 if(rc < 0) goto invalid;
544                 ND_PRINT((ndo, "for %s",
545                        message[2] == 0 ? "any" : format_prefix(ndo, prefix, plen)));
546             }
547         }
548             break;
549 
550         case MESSAGE_MH_REQUEST : {
551             if (!ndo->ndo_vflag)
552                 ND_PRINT((ndo, " mh-request"));
553             else {
554                 int rc;
555                 u_short seqno;
556                 u_char prefix[16], plen;
557                 ND_PRINT((ndo, "\n\tMH-Request "));
558                 if(len < 14) goto invalid;
559                 seqno = EXTRACT_16BITS(message + 4);
560                 rc = network_prefix(message[2], message[3], 0,
561                                     message + 16, NULL, len - 14, prefix);
562                 if(rc < 0) goto invalid;
563                 plen = message[3] + (message[2] == 1 ? 96 : 0);
564                 ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
565                        message[6], format_prefix(ndo, prefix, plen),
566                        seqno, format_id(message + 8)));
567             }
568         }
569             break;
570         case MESSAGE_TSPC :
571             if (!ndo->ndo_vflag)
572                 ND_PRINT((ndo, " tspc"));
573             else {
574                 ND_PRINT((ndo, "\n\tTS/PC "));
575                 if(len < 6) goto invalid;
576                 ND_PRINT((ndo, "timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
577                        EXTRACT_16BITS(message + 2)));
578             }
579             break;
580         case MESSAGE_HMAC : {
581             if (!ndo->ndo_vflag)
582                 ND_PRINT((ndo, " hmac"));
583             else {
584                 unsigned j;
585                 ND_PRINT((ndo, "\n\tHMAC "));
586                 if(len < 18) goto invalid;
587                 ND_PRINT((ndo, "key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2));
588                 for (j = 0; j < len - 2; j++)
589                     ND_PRINT((ndo, "%02X", message[4 + j]));
590             }
591         }
592             break;
593 
594         case MESSAGE_UPDATE_SRC_SPECIFIC : {
595             if(!ndo->ndo_vflag) {
596                 ND_PRINT((ndo, " ss-update"));
597             } else {
598                 u_char prefix[16], src_prefix[16];
599                 u_short interval, seqno, metric;
600                 u_char ae, plen, src_plen, omitted;
601                 int rc;
602                 int parsed_len = 10;
603                 ND_PRINT((ndo, "\n\tSS-Update"));
604                 if(len < 10) goto invalid;
605                 ae = message[2];
606                 src_plen = message[3];
607                 plen = message[4];
608                 omitted = message[5];
609                 interval = EXTRACT_16BITS(message + 6);
610                 seqno = EXTRACT_16BITS(message + 8);
611                 metric = EXTRACT_16BITS(message + 10);
612                 rc = network_prefix(ae, plen, omitted, message + 2 + parsed_len,
613                                     ae == 1 ? v4_prefix : v6_prefix,
614                                     len - parsed_len, prefix);
615                 if(rc < 0) goto invalid;
616                 if(ae == 1)
617                     plen += 96;
618                 parsed_len += rc;
619                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
620                                     NULL, len - parsed_len, src_prefix);
621                 if(rc < 0) goto invalid;
622                 if(ae == 1)
623                     src_plen += 96;
624                 parsed_len += rc;
625 
626                 ND_PRINT((ndo, " %s from", format_prefix(ndo, prefix, plen)));
627                 ND_PRINT((ndo, " %s metric %u seqno %u interval %s",
628                           format_prefix(ndo, src_prefix, src_plen),
629                           metric, seqno, format_interval_update(interval)));
630                 /* extra data? */
631                 if((u_int)parsed_len < len)
632                     subtlvs_print(ndo, message + 2 + parsed_len,
633                                   message + 2 + len, type);
634             }
635         }
636             break;
637 
638         case MESSAGE_REQUEST_SRC_SPECIFIC : {
639             if(!ndo->ndo_vflag)
640                 ND_PRINT((ndo, " ss-request"));
641             else {
642                 int rc, parsed_len = 3;
643                 u_char ae, plen, src_plen, prefix[16], src_prefix[16];
644                 ND_PRINT((ndo, "\n\tSS-Request "));
645                 if(len < 3) goto invalid;
646                 ae = message[2];
647                 plen = message[3];
648                 src_plen = message[4];
649                 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
650                                     NULL, len - parsed_len, prefix);
651                 if(rc < 0) goto invalid;
652                 if(ae == 1)
653                     plen += 96;
654                 parsed_len += rc;
655                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
656                                     NULL, len - parsed_len, src_prefix);
657                 if(rc < 0) goto invalid;
658                 if(ae == 1)
659                     src_plen += 96;
660                 parsed_len += rc;
661                 if(ae == 0) {
662                     ND_PRINT((ndo, "for any"));
663                 } else {
664                     ND_PRINT((ndo, "for (%s, ", format_prefix(ndo, prefix, plen)));
665                     ND_PRINT((ndo, "%s)", format_prefix(ndo, src_prefix, src_plen)));
666                 }
667             }
668         }
669             break;
670 
671         case MESSAGE_MH_REQUEST_SRC_SPECIFIC : {
672             if(!ndo->ndo_vflag)
673                 ND_PRINT((ndo, " ss-mh-request"));
674             else {
675                 int rc, parsed_len = 14;
676                 u_short seqno;
677                 u_char ae, plen, src_plen, prefix[16], src_prefix[16], hopc;
678                 const u_char *router_id = NULL;
679                 ND_PRINT((ndo, "\n\tSS-MH-Request "));
680                 if(len < 14) goto invalid;
681                 ae = message[2];
682                 plen = message[3];
683                 seqno = EXTRACT_16BITS(message + 4);
684                 hopc = message[6];
685                 src_plen = message[7];
686                 router_id = message + 8;
687                 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len,
688                                     NULL, len - parsed_len, prefix);
689                 if(rc < 0) goto invalid;
690                 if(ae == 1)
691                     plen += 96;
692                 parsed_len += rc;
693                 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len,
694                                     NULL, len - parsed_len, src_prefix);
695                 if(rc < 0) goto invalid;
696                 if(ae == 1)
697                     src_plen += 96;
698                 ND_PRINT((ndo, "(%u hops) for (%s, ",
699                           hopc, format_prefix(ndo, prefix, plen)));
700                 ND_PRINT((ndo, "%s) seqno %u id %s",
701                           format_prefix(ndo, src_prefix, src_plen),
702                           seqno, format_id(router_id)));
703             }
704         }
705             break;
706 
707         default:
708             if (!ndo->ndo_vflag)
709                 ND_PRINT((ndo, " unknown"));
710             else
711                 ND_PRINT((ndo, "\n\tUnknown message type %d", type));
712         }
713         i += len + 2;
714     }
715     return;
716 
717  trunc:
718     ND_PRINT((ndo, " %s", tstr));
719     return;
720 
721  invalid:
722     ND_PRINT((ndo, "%s", istr));
723     return;
724 }
725