]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
Remove #if 0 sections
[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.28 2001-06-15 22:17:34 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
420 /* 0 1 2 3
421 * 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
422 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
423 * | Addr Family | Encoding Type | Unicast Address |
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 | Reserved | Mask Len |
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
430 * | Group multicast Address |
431 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
432 * 0 1 2 3
433 * 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
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * | Source Address |
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 */
440 static int
441 pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
442 {
443 int af;
444 char *afstr;
445 int len, hdrlen;
446
447 TCHECK(bp[0]);
448
449 if (pimv2_addr_len == 0) {
450 TCHECK(bp[1]);
451 switch (bp[0]) {
452 case 1:
453 af = AF_INET;
454 afstr = "IPv4";
455 len = 4;
456 break;
457 #ifdef INET6
458 case 2:
459 af = AF_INET6;
460 afstr = "IPv6";
461 len = 16;
462 break;
463 #endif
464 default:
465 return -1;
466 }
467 if (bp[1] != 0)
468 return -1;
469 hdrlen = 2;
470 } else {
471 switch (pimv2_addr_len) {
472 case 4:
473 af = AF_INET;
474 afstr = "IPv4";
475 break;
476 #ifdef INET6
477 case 16:
478 af = AF_INET6;
479 afstr = "IPv6";
480 break;
481 #endif
482 default:
483 return -1;
484 break;
485 }
486 len = pimv2_addr_len;
487 hdrlen = 0;
488 }
489
490 bp += hdrlen;
491 switch (at) {
492 case pimv2_unicast:
493 TCHECK2(bp[0], len);
494 if (af == AF_INET) {
495 if (!silent)
496 (void)printf("%s", ipaddr_string(bp));
497 }
498 #ifdef INET6
499 else if (af == AF_INET6) {
500 if (!silent)
501 (void)printf("%s", ip6addr_string(bp));
502 }
503 #endif
504 return hdrlen + len;
505 case pimv2_group:
506 case pimv2_source:
507 TCHECK2(bp[0], len + 2);
508 if (af == AF_INET) {
509 if (!silent) {
510 (void)printf("%s", ipaddr_string(bp + 2));
511 if (bp[1] != 32)
512 (void)printf("/%u", bp[1]);
513 }
514 }
515 #ifdef INET6
516 else if (af == AF_INET6) {
517 if (!silent) {
518 (void)printf("%s", ip6addr_string(bp + 2));
519 if (bp[1] != 128)
520 (void)printf("/%u", bp[1]);
521 }
522 }
523 #endif
524 if (bp[0] && !silent) {
525 if (at == pimv2_group) {
526 (void)printf("(0x%02x)", bp[0]);
527 } else {
528 (void)printf("(%s%s%s",
529 bp[0] & 0x04 ? "S" : "",
530 bp[0] & 0x02 ? "W" : "",
531 bp[0] & 0x01 ? "R" : "");
532 if (bp[0] & 0xf8) {
533 (void) printf("+0x%02x", bp[0] & 0xf8);
534 }
535 (void)printf(")");
536 }
537 }
538 return hdrlen + 2 + len;
539 default:
540 return -1;
541 }
542 trunc:
543 return -1;
544 }
545
546 static void
547 pimv2_print(register const u_char *bp, register u_int len)
548 {
549 register const u_char *ep;
550 register struct pim *pim = (struct pim *)bp;
551 int advance;
552
553 ep = (const u_char *)snapend;
554 if (bp >= ep)
555 return;
556 if (ep > bp + len)
557 ep = bp + len;
558 TCHECK(pim->pim_rsv);
559 pimv2_addr_len = pim->pim_rsv;
560 if (pimv2_addr_len != 0)
561 (void)printf("[RFC2117-encoding] ");
562
563 switch (PIM_TYPE(pim->pim_typever)) {
564 case 0:
565 {
566 u_int16_t otype, olen;
567 (void)printf(" Hello");
568 bp += 4;
569 while (bp < ep) {
570 TCHECK2(bp[0], 4);
571 otype = EXTRACT_16BITS(&bp[0]);
572 olen = EXTRACT_16BITS(&bp[2]);
573 TCHECK2(bp[0], 4 + olen);
574 switch (otype) {
575 case 1: /* Hold time */
576 (void)printf(" (Hold-time ");
577 relts_print(EXTRACT_16BITS(&bp[4]));
578 (void)printf(")");
579 break;
580
581 case 19: /* DR-Priority */
582 (void)printf(" (DR-Priority: ");
583 if (olen != 4) {
584 (void)printf("!olen=%d!)", olen);
585 } else {
586 (void)printf("%d)", EXTRACT_32BITS(&bp[4]));
587 }
588 break;
589
590 case 20:
591 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4]));
592 break;
593
594 case 21:
595 (void)printf(" (State Refresh Capable; v%d", bp[4]);
596 if (bp[5] != 0) {
597 (void)printf(" interval ");
598 relts_print(bp[5]);
599 }
600 if (EXTRACT_16BITS(&bp[6]) != 0) {
601 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp[6]));
602 }
603 (void)printf(")");
604 break;
605
606 case 22: /* Bidir-Capable */
607 (void)printf(" (bidir-capable)");
608 break;
609
610 default:
611 if (vflag)
612 (void)printf(" [Hello option %d]", otype);
613 }
614 bp += 4 + olen;
615 }
616 break;
617 }
618
619 case 1:
620 {
621 struct ip *ip;
622
623 (void)printf(" Register");
624 if (vflag && bp + 8 <= ep) {
625 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
626 bp[4] & 0x40 ? "N" : "");
627 }
628 bp += 8; len -= 8;
629
630 /* encapsulated multicast packet */
631 if (bp >= ep)
632 break;
633 ip = (struct ip *)bp;
634 switch (IP_V(ip)) {
635 case 4: /* IPv4 */
636 printf(" ");
637 ip_print(bp, len);
638 break;
639 #ifdef INET6
640 case 6: /* IPv6 */
641 printf(" ");
642 ip6_print(bp, len);
643 break;
644 #endif
645 default:
646 (void)printf(" IP ver %d", IP_V(ip));
647 break;
648 }
649 break;
650 }
651
652 case 2:
653 (void)printf(" Register-Stop");
654 bp += 4; len -= 4;
655 if (bp >= ep)
656 break;
657 (void)printf(" group=");
658 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
659 (void)printf("...");
660 break;
661 }
662 bp += advance; len -= advance;
663 if (bp >= ep)
664 break;
665 (void)printf(" source=");
666 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
667 (void)printf("...");
668 break;
669 }
670 bp += advance; len -= advance;
671 break;
672
673 case 3:
674 case 6:
675 case 7:
676 {
677 u_int8_t ngroup;
678 u_int16_t holdtime;
679 u_int16_t njoin;
680 u_int16_t nprune;
681 int i, j;
682
683 switch (PIM_TYPE(pim->pim_typever)) {
684 case 3:
685 (void)printf(" Join/Prune");
686 break;
687 case 6:
688 (void)printf(" Graft");
689 break;
690 case 7:
691 (void)printf(" Graft-ACK");
692 break;
693 }
694 bp += 4; len -= 4;
695 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
696 if (bp >= ep)
697 break;
698 (void)printf(" upstream-neighbor=");
699 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
700 (void)printf("...");
701 break;
702 }
703 bp += advance; len -= advance;
704 }
705 if (bp + 4 > ep)
706 break;
707 ngroup = bp[1];
708 holdtime = EXTRACT_16BITS(&bp[2]);
709 (void)printf(" groups=%u", ngroup);
710 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
711 (void)printf(" holdtime=");
712 if (holdtime == 0xffff)
713 (void)printf("infty");
714 else
715 relts_print(holdtime);
716 }
717 bp += 4; len -= 4;
718 for (i = 0; i < ngroup; i++) {
719 if (bp >= ep)
720 goto jp_done;
721 (void)printf(" (group%d: ", i);
722 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
723 (void)printf("...)");
724 goto jp_done;
725 }
726 bp += advance; len -= advance;
727 if (bp + 4 > ep) {
728 (void)printf("...)");
729 goto jp_done;
730 }
731 njoin = EXTRACT_16BITS(&bp[0]);
732 nprune = EXTRACT_16BITS(&bp[2]);
733 (void)printf(" join=%u", njoin);
734 bp += 4; len -= 4;
735 for (j = 0; j < njoin; j++) {
736 (void)printf(" ");
737 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
738 (void)printf("...)");
739 goto jp_done;
740 }
741 bp += advance; len -= advance;
742 }
743 (void)printf(" prune=%u", nprune);
744 for (j = 0; j < nprune; j++) {
745 (void)printf(" ");
746 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
747 (void)printf("...)");
748 goto jp_done;
749 }
750 bp += advance; len -= advance;
751 }
752 (void)printf(")");
753 }
754 jp_done:
755 break;
756 }
757
758 case 4:
759 {
760 int i, j, frpcnt;
761
762 (void)printf(" Bootstrap");
763 bp += 4;
764
765 /* Fragment Tag, Hash Mask len, and BSR-priority */
766 if (bp + sizeof(u_int16_t) >= ep) break;
767 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
768 bp += sizeof(u_int16_t);
769 if (bp >= ep) break;
770 (void)printf(" hashmlen=%d", bp[0]);
771 if (bp + 1 >= ep) break;
772 (void)printf(" BSRprio=%d", bp[1]);
773 bp += 2;
774
775 /* Encoded-Unicast-BSR-Address */
776 if (bp >= ep) break;
777 (void)printf(" BSR=");
778 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
779 (void)printf("...");
780 break;
781 }
782 bp += advance;
783
784 for (i = 0; bp < ep; i++) {
785 /* Encoded-Group Address */
786 (void)printf(" (group%d: ", i);
787 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
788 < 0) {
789 (void)printf("...)");
790 goto bs_done;
791 }
792 bp += advance;
793
794 /* RP-Count, Frag RP-Cnt, and rsvd */
795 if (bp >= ep) {
796 (void)printf("...)");
797 goto bs_done;
798 }
799 (void)printf(" RPcnt=%d", bp[0]);
800 if (bp + 1 >= ep) {
801 (void)printf("...)");
802 goto bs_done;
803 }
804 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
805 bp += 4;
806
807 for (j = 0; j < frpcnt && bp < ep; j++) {
808 /* each RP info */
809 (void)printf(" RP%d=", j);
810 if ((advance = pimv2_addr_print(bp,
811 pimv2_unicast,
812 0)) < 0) {
813 (void)printf("...)");
814 goto bs_done;
815 }
816 bp += advance;
817
818 if (bp + 1 >= ep) {
819 (void)printf("...)");
820 goto bs_done;
821 }
822 (void)printf(",holdtime=");
823 relts_print(EXTRACT_16BITS(bp));
824 if (bp + 2 >= ep) {
825 (void)printf("...)");
826 goto bs_done;
827 }
828 (void)printf(",prio=%d", bp[2]);
829 bp += 4;
830 }
831 (void)printf(")");
832 }
833 bs_done:
834 break;
835 }
836 case 5:
837 (void)printf(" Assert");
838 bp += 4; len -= 4;
839 if (bp >= ep)
840 break;
841 (void)printf(" group=");
842 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
843 (void)printf("...");
844 break;
845 }
846 bp += advance; len -= advance;
847 if (bp >= ep)
848 break;
849 (void)printf(" src=");
850 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
851 (void)printf("...");
852 break;
853 }
854 bp += advance; len -= advance;
855 if (bp + 8 > ep)
856 break;
857 if (bp[0] & 0x80)
858 (void)printf(" RPT");
859 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
860 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
861 break;
862
863 case 8:
864 {
865 int i, pfxcnt;
866
867 (void)printf(" Candidate-RP-Advertisement");
868 bp += 4;
869
870 /* Prefix-Cnt, Priority, and Holdtime */
871 if (bp >= ep) break;
872 (void)printf(" prefix-cnt=%d", bp[0]);
873 pfxcnt = bp[0];
874 if (bp + 1 >= ep) break;
875 (void)printf(" prio=%d", bp[1]);
876 if (bp + 3 >= ep) break;
877 (void)printf(" holdtime=");
878 relts_print(EXTRACT_16BITS(&bp[2]));
879 bp += 4;
880
881 /* Encoded-Unicast-RP-Address */
882 if (bp >= ep) break;
883 (void)printf(" RP=");
884 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
885 (void)printf("...");
886 break;
887 }
888 bp += advance;
889
890 /* Encoded-Group Addresses */
891 for (i = 0; i < pfxcnt && bp < ep; i++) {
892 (void)printf(" Group%d=", i);
893 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
894 < 0) {
895 (void)printf("...");
896 break;
897 }
898 bp += advance;
899 }
900 break;
901 }
902
903 case 9:
904 (void)printf(" Prune-Refresh");
905 (void)printf(" src=");
906 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
907 (void)printf("...");
908 break;
909 }
910 bp += advance;
911 (void)printf(" grp=");
912 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
913 (void)printf("...");
914 break;
915 }
916 bp += advance;
917 (void)printf(" forwarder=");
918 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
919 (void)printf("...");
920 break;
921 }
922 bp += advance;
923 TCHECK2(bp[0], 2);
924 (void)printf(" TUNR ");
925 relts_print(EXTRACT_16BITS(bp));
926 break;
927
928
929 default:
930 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
931 break;
932 }
933
934 return;
935
936 trunc:
937 (void)printf("[|pim]");
938 }