]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
Parse State-Refresh Hello option properly.
[tcpdump] / print-pim.c
1 /*
2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.27 2001-05-11 02:12:32 fenner Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/socket.h>
34
35 #include <netinet/in.h>
36
37 /*
38 * XXX: We consider a case where IPv6 is not ready yet for portability,
39 * but PIM dependent defintions should be independent of IPv6...
40 */
41
42 struct pim {
43 u_int8_t pim_typever;
44 /* upper 4bit: PIM version number; 2 for PIMv2 */
45 /* lower 4bit: the PIM message type, currently they are:
46 * Hello, Register, Register-Stop, Join/Prune,
47 * Bootstrap, Assert, Graft (PIM-DM only),
48 * Graft-Ack (PIM-DM only), C-RP-Adv
49 */
50 #define PIM_VER(x) (((x) & 0xf0) >> 4)
51 #define PIM_TYPE(x) ((x) & 0x0f)
52 u_char pim_rsv; /* Reserved */
53 u_short pim_cksum; /* IP style check sum */
54 };
55
56
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <unistd.h>
60
61 #include "interface.h"
62 #include "addrtoname.h"
63 #include "extract.h"
64
65 #include "ip.h"
66
67 static void pimv2_print(register const u_char *bp, register u_int len);
68
69 static void
70 pimv1_join_prune_print(register const u_char *bp, register u_int len)
71 {
72 int maddrlen, addrlen, ngroups, njoin, nprune;
73 int njp;
74
75 /* If it's a single group and a single source, use 1-line output. */
76 if (TTEST2(bp[0], 30) && bp[11] == 1 &&
77 ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) {
78 int hold;
79
80 (void)printf(" RPF %s ", ipaddr_string(bp));
81 hold = EXTRACT_16BITS(&bp[6]);
82 if (hold != 180) {
83 (void)printf("Hold ");
84 relts_print(hold);
85 }
86 (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune",
87 ipaddr_string(&bp[26]), bp[25] & 0x3f,
88 ipaddr_string(&bp[12]));
89 if (EXTRACT_32BITS(&bp[16]) != 0xffffffff)
90 (void)printf("/%s", ipaddr_string(&bp[16]));
91 (void)printf(") %s%s %s",
92 (bp[24] & 0x01) ? "Sparse" : "Dense",
93 (bp[25] & 0x80) ? " WC" : "",
94 (bp[25] & 0x40) ? "RP" : "SPT");
95 return;
96 }
97
98 TCHECK2(bp[0], 4);
99 if (vflag > 1)
100 (void)printf("\n");
101 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp));
102 TCHECK2(bp[6], 2);
103 if (vflag > 1)
104 (void)printf("\n");
105 (void)printf(" Hold time: ");
106 relts_print(EXTRACT_16BITS(&bp[6]));
107 if (vflag < 2)
108 return;
109 bp += 8;
110 len -= 8;
111
112 TCHECK2(bp[0], 4);
113 maddrlen = bp[1];
114 addrlen = bp[2];
115 ngroups = bp[3];
116 bp += 4;
117 len -= 4;
118 while (ngroups--) {
119 TCHECK2(bp[0], 4);
120 (void)printf("\n\tGroup: %s", ipaddr_string(bp));
121 if (EXTRACT_32BITS(&bp[4]) != 0xffffffff)
122 (void)printf("/%s", ipaddr_string(&bp[4]));
123 TCHECK2(bp[8], 4);
124 njoin = EXTRACT_16BITS(&bp[8]);
125 nprune = EXTRACT_16BITS(&bp[10]);
126 (void)printf(" joined: %d pruned: %d", njoin, nprune);
127 bp += 12;
128 len -= 12;
129 for (njp = 0; njp < (njoin + nprune); njp++) {
130 char *type;
131
132 if (njp < njoin)
133 type = "Join ";
134 else
135 type = "Prune";
136 TCHECK2(bp[0], 6);
137 (void)printf("\n\t%s %s%s%s%s/%d", type,
138 (bp[0] & 0x01) ? "Sparse " : "Dense ",
139 (bp[1] & 0x80) ? "WC " : "",
140 (bp[1] & 0x40) ? "RP " : "SPT ",
141 ipaddr_string(&bp[2]), bp[1] & 0x3f);
142 bp += 6;
143 len -= 6;
144 }
145 }
146 return;
147 trunc:
148 (void)printf("[|pim]");
149 return;
150 }
151
152 void
153 pimv1_print(register const u_char *bp, register u_int len)
154 {
155 register const u_char *ep;
156 register u_char type;
157
158 ep = (const u_char *)snapend;
159 if (bp >= ep)
160 return;
161
162 type = bp[1];
163
164 switch (type) {
165 case 0:
166 (void)printf(" Query");
167 if (TTEST(bp[8])) {
168 switch (bp[8] >> 4) {
169 case 0:
170 (void)printf(" Dense-mode");
171 break;
172 case 1:
173 (void)printf(" Sparse-mode");
174 break;
175 case 2:
176 (void)printf(" Sparse-Dense-mode");
177 break;
178 default:
179 (void)printf(" mode-%d", bp[8] >> 4);
180 break;
181 }
182 }
183 if (vflag) {
184 TCHECK2(bp[10],2);
185 (void)printf(" (Hold-time ");
186 relts_print(EXTRACT_16BITS(&bp[10]));
187 (void)printf(")");
188 }
189 break;
190
191 case 1:
192 (void)printf(" Register");
193 TCHECK2(bp[8], 20); /* ip header */
194 (void)printf(" for %s > %s", ipaddr_string(&bp[20]),
195 ipaddr_string(&bp[24]));
196 break;
197 case 2:
198 (void)printf(" Register-Stop");
199 TCHECK2(bp[12], 4);
200 (void)printf(" for %s > %s", ipaddr_string(&bp[8]),
201 ipaddr_string(&bp[12]));
202 break;
203 case 3:
204 (void)printf(" Join/Prune");
205 if (vflag)
206 pimv1_join_prune_print(&bp[8], len - 8);
207 break;
208 case 4:
209 (void)printf(" RP-reachable");
210 if (vflag) {
211 TCHECK2(bp[22], 2);
212 (void)printf(" group %s",
213 ipaddr_string(&bp[8]));
214 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
215 (void)printf("/%s", ipaddr_string(&bp[12]));
216 (void)printf(" RP %s hold ", ipaddr_string(&bp[16]));
217 relts_print(EXTRACT_16BITS(&bp[22]));
218 }
219 break;
220 case 5:
221 (void)printf(" Assert");
222 TCHECK2(bp[16], 4);
223 (void)printf(" for %s > %s", ipaddr_string(&bp[16]),
224 ipaddr_string(&bp[8]));
225 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
226 (void)printf("/%s", ipaddr_string(&bp[12]));
227 TCHECK2(bp[24], 4);
228 (void)printf(" %s pref %d metric %d",
229 (bp[20] & 0x80) ? "RP-tree" : "SPT",
230 EXTRACT_32BITS(&bp[20]) & 0x7fffffff,
231 EXTRACT_32BITS(&bp[24]));
232 break;
233 case 6:
234 (void)printf(" Graft");
235 if (vflag)
236 pimv1_join_prune_print(&bp[8], len - 8);
237 break;
238 case 7:
239 (void)printf(" Graft-ACK");
240 if (vflag)
241 pimv1_join_prune_print(&bp[8], len - 8);
242 break;
243 case 8:
244 (void)printf(" Mode");
245 break;
246 default:
247 (void)printf(" [type %d]", type);
248 break;
249 }
250 if ((bp[4] >> 4) != 1)
251 (void)printf(" [v%d]", bp[4] >> 4);
252 return;
253
254 trunc:
255 (void)printf("[|pim]");
256 return;
257 }
258
259 /*
260 * auto-RP is a cisco protocol, documented at
261 * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt
262 */
263 void
264 cisco_autorp_print(register const u_char *bp, register u_int len)
265 {
266 int type;
267 int numrps;
268 int hold;
269
270 TCHECK(bp[0]);
271 (void)printf(" auto-rp ");
272 type = bp[0];
273 switch (type) {
274 case 0x11:
275 (void)printf("candidate-advert");
276 break;
277 case 0x12:
278 (void)printf("mapping");
279 break;
280 default:
281 (void)printf("type-0x%02x", type);
282 break;
283 }
284
285 TCHECK(bp[1]);
286 numrps = bp[1];
287
288 TCHECK2(bp[2], 2);
289 (void)printf(" Hold ");
290 hold = EXTRACT_16BITS(&bp[2]);
291 if (hold)
292 relts_print(EXTRACT_16BITS(&bp[2]));
293 else
294 printf("FOREVER");
295
296 /* Next 4 bytes are reserved. */
297
298 bp += 8; len -= 8;
299
300 /*XXX skip unless -v? */
301
302 /*
303 * Rest of packet:
304 * numrps entries of the form:
305 * 32 bits: RP
306 * 6 bits: reserved
307 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
308 * 8 bits: # of entries for this RP
309 * each entry: 7 bits: reserved, 1 bit: negative,
310 * 8 bits: mask 32 bits: source
311 * lather, rinse, repeat.
312 */
313 while (numrps--) {
314 int nentries;
315 char s;
316
317 TCHECK2(bp[0], 4);
318 (void)printf(" RP %s", ipaddr_string(bp));
319 TCHECK(bp[4]);
320 switch (bp[4] & 0x3) {
321 case 0: printf(" PIMv?");
322 break;
323 case 1: printf(" PIMv1");
324 break;
325 case 2: printf(" PIMv2");
326 break;
327 case 3: printf(" PIMv1+2");
328 break;
329 }
330 TCHECK(bp[5]);
331 nentries = bp[5];
332 bp += 6; len -= 6;
333 s = ' ';
334 for (; nentries; nentries--) {
335 TCHECK2(bp[0], 6);
336 (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "",
337 ipaddr_string(&bp[2]), bp[1]);
338 s = ',';
339 bp += 6; len -= 6;
340 }
341 }
342 return;
343
344 trunc:
345 (void)printf("[|autorp]");
346 return;
347 }
348
349 void
350 pim_print(register const u_char *bp, register u_int len)
351 {
352 register const u_char *ep;
353 register struct pim *pim = (struct pim *)bp;
354
355 ep = (const u_char *)snapend;
356 if (bp >= ep)
357 return;
358 #ifdef notyet /* currently we see only version and type */
359 TCHECK(pim->pim_rsv);
360 #endif
361
362 switch (PIM_VER(pim->pim_typever)) {
363 case 2: /* avoid hardcoding? */
364 (void)printf("pim v2");
365 pimv2_print(bp, len);
366 break;
367 default:
368 (void)printf("pim v%d", PIM_VER(pim->pim_typever));
369 break;
370 }
371 return;
372 }
373
374 /*
375 * PIMv2 uses encoded address representations.
376 *
377 * The last PIM-SM I-D before RFC2117 was published specified the
378 * following representation for unicast addresses. However, RFC2117
379 * specified no encoding for unicast addresses with the unicast
380 * address length specified in the header. Therefore, we have to
381 * guess which encoding is being used (Cisco's PIMv2 implementation
382 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
383 * field into a 'unicast-address-length-in-bytes' field. We guess
384 * that it's the draft encoding if this reserved field is zero.
385 *
386 * RFC2362 goes back to the encoded format, and calls the addr length
387 * field "reserved" again.
388 *
389 * The first byte is the address family, from:
390 *
391 * 0 Reserved
392 * 1 IP (IP version 4)
393 * 2 IP6 (IP version 6)
394 * 3 NSAP
395 * 4 HDLC (8-bit multidrop)
396 * 5 BBN 1822
397 * 6 802 (includes all 802 media plus Ethernet "canonical format")
398 * 7 E.163
399 * 8 E.164 (SMDS, Frame Relay, ATM)
400 * 9 F.69 (Telex)
401 * 10 X.121 (X.25, Frame Relay)
402 * 11 IPX
403 * 12 Appletalk
404 * 13 Decnet IV
405 * 14 Banyan Vines
406 * 15 E.164 with NSAP format subaddress
407 *
408 * In addition, the second byte is an "Encoding". 0 is the default
409 * encoding for the address family, and no other encodings are currently
410 * specified.
411 *
412 */
413
414 static int pimv2_addr_len;
415
416 enum pimv2_addrtype {
417 pimv2_unicast, pimv2_group, pimv2_source
418 };
419 #if 0
420 static char *addrtypestr[] = {
421 "unicast", "group", "source"
422 };
423 #endif
424
425 /* 0 1 2 3
426 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
427 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
428 * | Addr Family | Encoding Type | Unicast Address |
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
430 * 0 1 2 3
431 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
432 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * | Addr Family | Encoding Type | Reserved | Mask Len |
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Group multicast Address |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * 0 1 2 3
438 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
442 * | Source Address |
443 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 */
445 static int
446 pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
447 {
448 int af;
449 char *afstr;
450 int len, hdrlen;
451
452 TCHECK(bp[0]);
453
454 if (pimv2_addr_len == 0) {
455 TCHECK(bp[1]);
456 switch (bp[0]) {
457 case 1:
458 af = AF_INET;
459 afstr = "IPv4";
460 len = 4;
461 break;
462 #ifdef INET6
463 case 2:
464 af = AF_INET6;
465 afstr = "IPv6";
466 len = 16;
467 break;
468 #endif
469 default:
470 return -1;
471 }
472 if (bp[1] != 0)
473 return -1;
474 hdrlen = 2;
475 } else {
476 switch (pimv2_addr_len) {
477 case 4:
478 af = AF_INET;
479 afstr = "IPv4";
480 break;
481 #ifdef INET6
482 case 16:
483 af = AF_INET6;
484 afstr = "IPv6";
485 break;
486 #endif
487 default:
488 return -1;
489 break;
490 }
491 len = pimv2_addr_len;
492 hdrlen = 0;
493 }
494
495 bp += hdrlen;
496 switch (at) {
497 case pimv2_unicast:
498 TCHECK2(bp[0], len);
499 if (af == AF_INET) {
500 if (!silent)
501 (void)printf("%s", ipaddr_string(bp));
502 }
503 #ifdef INET6
504 else if (af == AF_INET6) {
505 if (!silent)
506 (void)printf("%s", ip6addr_string(bp));
507 }
508 #endif
509 return hdrlen + len;
510 case pimv2_group:
511 case pimv2_source:
512 TCHECK2(bp[0], len + 2);
513 if (af == AF_INET) {
514 if (!silent) {
515 (void)printf("%s", ipaddr_string(bp + 2));
516 if (bp[1] != 32)
517 (void)printf("/%u", bp[1]);
518 }
519 }
520 #ifdef INET6
521 else if (af == AF_INET6) {
522 if (!silent) {
523 (void)printf("%s", ip6addr_string(bp + 2));
524 if (bp[1] != 128)
525 (void)printf("/%u", bp[1]);
526 }
527 }
528 #endif
529 if (bp[0] && !silent) {
530 if (at == pimv2_group) {
531 (void)printf("(0x%02x)", bp[0]);
532 } else {
533 (void)printf("(%s%s%s",
534 bp[0] & 0x04 ? "S" : "",
535 bp[0] & 0x02 ? "W" : "",
536 bp[0] & 0x01 ? "R" : "");
537 if (bp[0] & 0xf8) {
538 (void) printf("+0x%02x", bp[0] & 0xf8);
539 }
540 (void)printf(")");
541 }
542 }
543 return hdrlen + 2 + len;
544 default:
545 return -1;
546 }
547 trunc:
548 return -1;
549 }
550
551 static void
552 pimv2_print(register const u_char *bp, register u_int len)
553 {
554 register const u_char *ep;
555 register struct pim *pim = (struct pim *)bp;
556 int advance;
557
558 ep = (const u_char *)snapend;
559 if (bp >= ep)
560 return;
561 if (ep > bp + len)
562 ep = bp + len;
563 TCHECK(pim->pim_rsv);
564 pimv2_addr_len = pim->pim_rsv;
565 if (pimv2_addr_len != 0)
566 (void)printf("[RFC2117-encoding] ");
567
568 switch (PIM_TYPE(pim->pim_typever)) {
569 case 0:
570 {
571 u_int16_t otype, olen;
572 (void)printf(" Hello");
573 bp += 4;
574 while (bp < ep) {
575 TCHECK2(bp[0], 4);
576 otype = EXTRACT_16BITS(&bp[0]);
577 olen = EXTRACT_16BITS(&bp[2]);
578 TCHECK2(bp[0], 4 + olen);
579 switch (otype) {
580 case 1: /* Hold time */
581 (void)printf(" (Hold-time ");
582 relts_print(EXTRACT_16BITS(&bp[4]));
583 (void)printf(")");
584 break;
585
586 case 19: /* DR-Priority */
587 (void)printf(" (DR-Priority: ");
588 if (olen != 4) {
589 (void)printf("!olen=%d!)", olen);
590 } else {
591 (void)printf("%d)", EXTRACT_32BITS(&bp[4]));
592 }
593 break;
594
595 case 20:
596 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4]));
597 break;
598
599 case 21:
600 (void)printf(" (State Refresh Capable; v%d", bp[4]);
601 if (bp[5] != 0) {
602 (void)printf(" interval ");
603 relts_print(bp[5]);
604 }
605 if (EXTRACT_16BITS(&bp[6]) != 0) {
606 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp[6]));
607 }
608 (void)printf(")");
609 break;
610
611 case 22: /* Bidir-Capable */
612 (void)printf(" (bidir-capable)");
613 break;
614
615 default:
616 if (vflag)
617 (void)printf(" [Hello option %d]", otype);
618 }
619 bp += 4 + olen;
620 }
621 break;
622 }
623
624 case 1:
625 {
626 struct ip *ip;
627
628 (void)printf(" Register");
629 if (vflag && bp + 8 <= ep) {
630 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
631 bp[4] & 0x40 ? "N" : "");
632 }
633 bp += 8; len -= 8;
634
635 /* encapsulated multicast packet */
636 if (bp >= ep)
637 break;
638 ip = (struct ip *)bp;
639 switch (IP_V(ip)) {
640 case 4: /* IPv4 */
641 printf(" ");
642 ip_print(bp, len);
643 break;
644 #ifdef INET6
645 case 6: /* IPv6 */
646 printf(" ");
647 ip6_print(bp, len);
648 break;
649 #endif
650 default:
651 (void)printf(" IP ver %d", IP_V(ip));
652 break;
653 }
654 break;
655 }
656
657 case 2:
658 (void)printf(" Register-Stop");
659 bp += 4; len -= 4;
660 if (bp >= ep)
661 break;
662 (void)printf(" group=");
663 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
664 (void)printf("...");
665 break;
666 }
667 bp += advance; len -= advance;
668 if (bp >= ep)
669 break;
670 (void)printf(" source=");
671 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
672 (void)printf("...");
673 break;
674 }
675 bp += advance; len -= advance;
676 break;
677
678 case 3:
679 case 6:
680 case 7:
681 {
682 u_int8_t ngroup;
683 u_int16_t holdtime;
684 u_int16_t njoin;
685 u_int16_t nprune;
686 int i, j;
687
688 switch (PIM_TYPE(pim->pim_typever)) {
689 case 3:
690 (void)printf(" Join/Prune");
691 break;
692 case 6:
693 (void)printf(" Graft");
694 break;
695 case 7:
696 (void)printf(" Graft-ACK");
697 break;
698 }
699 bp += 4; len -= 4;
700 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
701 if (bp >= ep)
702 break;
703 (void)printf(" upstream-neighbor=");
704 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
705 (void)printf("...");
706 break;
707 }
708 bp += advance; len -= advance;
709 }
710 if (bp + 4 > ep)
711 break;
712 ngroup = bp[1];
713 holdtime = EXTRACT_16BITS(&bp[2]);
714 (void)printf(" groups=%u", ngroup);
715 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
716 (void)printf(" holdtime=");
717 if (holdtime == 0xffff)
718 (void)printf("infty");
719 else
720 relts_print(holdtime);
721 }
722 bp += 4; len -= 4;
723 for (i = 0; i < ngroup; i++) {
724 if (bp >= ep)
725 goto jp_done;
726 (void)printf(" (group%d: ", i);
727 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
728 (void)printf("...)");
729 goto jp_done;
730 }
731 bp += advance; len -= advance;
732 if (bp + 4 > ep) {
733 (void)printf("...)");
734 goto jp_done;
735 }
736 njoin = EXTRACT_16BITS(&bp[0]);
737 nprune = EXTRACT_16BITS(&bp[2]);
738 (void)printf(" join=%u", njoin);
739 bp += 4; len -= 4;
740 for (j = 0; j < njoin; j++) {
741 (void)printf(" ");
742 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
743 (void)printf("...)");
744 goto jp_done;
745 }
746 bp += advance; len -= advance;
747 }
748 (void)printf(" prune=%u", nprune);
749 for (j = 0; j < nprune; j++) {
750 (void)printf(" ");
751 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
752 (void)printf("...)");
753 goto jp_done;
754 }
755 bp += advance; len -= advance;
756 }
757 (void)printf(")");
758 }
759 jp_done:
760 break;
761 }
762
763 case 4:
764 {
765 int i, j, frpcnt;
766
767 (void)printf(" Bootstrap");
768 bp += 4;
769
770 /* Fragment Tag, Hash Mask len, and BSR-priority */
771 if (bp + sizeof(u_int16_t) >= ep) break;
772 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
773 bp += sizeof(u_int16_t);
774 if (bp >= ep) break;
775 (void)printf(" hashmlen=%d", bp[0]);
776 if (bp + 1 >= ep) break;
777 (void)printf(" BSRprio=%d", bp[1]);
778 bp += 2;
779
780 /* Encoded-Unicast-BSR-Address */
781 if (bp >= ep) break;
782 (void)printf(" BSR=");
783 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
784 (void)printf("...");
785 break;
786 }
787 bp += advance;
788
789 for (i = 0; bp < ep; i++) {
790 /* Encoded-Group Address */
791 (void)printf(" (group%d: ", i);
792 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
793 < 0) {
794 (void)printf("...)");
795 goto bs_done;
796 }
797 bp += advance;
798
799 /* RP-Count, Frag RP-Cnt, and rsvd */
800 if (bp >= ep) {
801 (void)printf("...)");
802 goto bs_done;
803 }
804 (void)printf(" RPcnt=%d", bp[0]);
805 if (bp + 1 >= ep) {
806 (void)printf("...)");
807 goto bs_done;
808 }
809 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
810 bp += 4;
811
812 for (j = 0; j < frpcnt && bp < ep; j++) {
813 /* each RP info */
814 (void)printf(" RP%d=", j);
815 if ((advance = pimv2_addr_print(bp,
816 pimv2_unicast,
817 0)) < 0) {
818 (void)printf("...)");
819 goto bs_done;
820 }
821 bp += advance;
822
823 if (bp + 1 >= ep) {
824 (void)printf("...)");
825 goto bs_done;
826 }
827 (void)printf(",holdtime=");
828 relts_print(EXTRACT_16BITS(bp));
829 if (bp + 2 >= ep) {
830 (void)printf("...)");
831 goto bs_done;
832 }
833 (void)printf(",prio=%d", bp[2]);
834 bp += 4;
835 }
836 (void)printf(")");
837 }
838 bs_done:
839 break;
840 }
841 case 5:
842 (void)printf(" Assert");
843 bp += 4; len -= 4;
844 if (bp >= ep)
845 break;
846 (void)printf(" group=");
847 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
848 (void)printf("...");
849 break;
850 }
851 bp += advance; len -= advance;
852 if (bp >= ep)
853 break;
854 (void)printf(" src=");
855 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
856 (void)printf("...");
857 break;
858 }
859 bp += advance; len -= advance;
860 if (bp + 8 > ep)
861 break;
862 if (bp[0] & 0x80)
863 (void)printf(" RPT");
864 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
865 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
866 break;
867
868 case 8:
869 {
870 int i, pfxcnt;
871
872 (void)printf(" Candidate-RP-Advertisement");
873 bp += 4;
874
875 /* Prefix-Cnt, Priority, and Holdtime */
876 if (bp >= ep) break;
877 (void)printf(" prefix-cnt=%d", bp[0]);
878 pfxcnt = bp[0];
879 if (bp + 1 >= ep) break;
880 (void)printf(" prio=%d", bp[1]);
881 if (bp + 3 >= ep) break;
882 (void)printf(" holdtime=");
883 relts_print(EXTRACT_16BITS(&bp[2]));
884 bp += 4;
885
886 /* Encoded-Unicast-RP-Address */
887 if (bp >= ep) break;
888 (void)printf(" RP=");
889 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
890 (void)printf("...");
891 break;
892 }
893 bp += advance;
894
895 /* Encoded-Group Addresses */
896 for (i = 0; i < pfxcnt && bp < ep; i++) {
897 (void)printf(" Group%d=", i);
898 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
899 < 0) {
900 (void)printf("...");
901 break;
902 }
903 bp += advance;
904 }
905 break;
906 }
907
908 case 9:
909 (void)printf(" Prune-Refresh");
910 (void)printf(" src=");
911 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
912 (void)printf("...");
913 break;
914 }
915 bp += advance;
916 (void)printf(" grp=");
917 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
918 (void)printf("...");
919 break;
920 }
921 bp += advance;
922 (void)printf(" forwarder=");
923 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
924 (void)printf("...");
925 break;
926 }
927 bp += advance;
928 TCHECK2(bp[0], 2);
929 (void)printf(" TUNR ");
930 relts_print(EXTRACT_16BITS(bp));
931 break;
932
933
934 default:
935 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
936 break;
937 }
938
939 return;
940
941 trunc:
942 (void)printf("[|pim]");
943 }