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