]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
don't pass on src & dst MAC adresses to the isoclns decoder as MAC adresses
[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.36 2002-12-11 07:14:06 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 2: /* LAN Prune Delay */
583 (void)printf(" (LAN-Prune-Delay: ");
584 if (olen != 4) {
585 (void)printf("!olen=%d!)", olen);
586 } else {
587 char t_bit;
588 u_int16_t lan_delay, override_interval;
589 lan_delay = EXTRACT_16BITS(&bp[4]);
590 override_interval = EXTRACT_16BITS(&bp[6]);
591 t_bit = (lan_delay & 0x8000)? 1 : 0;
592 lan_delay &= ~0x8000;
593 (void)printf("T-bit=%d lan-delay=%dms override-interval=%dms)",
594 t_bit, lan_delay, override_interval);
595 }
596 break;
597
598 case 18: /* Old DR-Priority */
599 if (olen == 4)
600 (void)printf(" (OLD-DR-Priority: %d)",
601 EXTRACT_32BITS(&bp[4]));
602 else
603 goto unknown;
604 break;
605
606
607 case 19: /* DR-Priority */
608 if (olen == 0) {
609 (void)printf(" (OLD-bidir-capable)");
610 break;
611 }
612 (void)printf(" (DR-Priority: ");
613 if (olen != 4) {
614 (void)printf("!olen=%d!)", olen);
615 } else {
616 (void)printf("%d)", EXTRACT_32BITS(&bp[4]));
617 }
618 break;
619
620 case 20:
621 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4]));
622 break;
623
624 case 21:
625 (void)printf(" (State Refresh Capable; v%d", bp[4]);
626 if (bp[5] != 0) {
627 (void)printf(" interval ");
628 relts_print(bp[5]);
629 }
630 if (EXTRACT_16BITS(&bp[6]) != 0) {
631 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp[6]));
632 }
633 (void)printf(")");
634 break;
635
636 case 22: /* Bidir-Capable */
637 (void)printf(" (bidir-capable)");
638 break;
639
640 default:
641 unknown:
642 if (vflag)
643 (void)printf(" [Hello option %d]", otype);
644 }
645 bp += 4 + olen;
646 }
647 break;
648 }
649
650 case 1:
651 {
652 struct ip *ip;
653
654 (void)printf(" Register");
655 if (vflag && bp + 8 <= ep) {
656 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
657 bp[4] & 0x40 ? "N" : "");
658 }
659 bp += 8; len -= 8;
660
661 /* encapsulated multicast packet */
662 if (bp >= ep)
663 break;
664 ip = (struct ip *)bp;
665 switch (IP_V(ip)) {
666 case 4: /* IPv4 */
667 printf(" ");
668 ip_print(bp, len);
669 break;
670 #ifdef INET6
671 case 6: /* IPv6 */
672 printf(" ");
673 ip6_print(bp, len);
674 break;
675 #endif
676 default:
677 (void)printf(" IP ver %d", IP_V(ip));
678 break;
679 }
680 break;
681 }
682
683 case 2:
684 (void)printf(" Register-Stop");
685 bp += 4; len -= 4;
686 if (bp >= ep)
687 break;
688 (void)printf(" group=");
689 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
690 (void)printf("...");
691 break;
692 }
693 bp += advance; len -= advance;
694 if (bp >= ep)
695 break;
696 (void)printf(" source=");
697 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
698 (void)printf("...");
699 break;
700 }
701 bp += advance; len -= advance;
702 break;
703
704 case 3:
705 case 6:
706 case 7:
707 {
708 u_int8_t ngroup;
709 u_int16_t holdtime;
710 u_int16_t njoin;
711 u_int16_t nprune;
712 int i, j;
713
714 switch (PIM_TYPE(pim->pim_typever)) {
715 case 3:
716 (void)printf(" Join/Prune");
717 break;
718 case 6:
719 (void)printf(" Graft");
720 break;
721 case 7:
722 (void)printf(" Graft-ACK");
723 break;
724 }
725 bp += 4; len -= 4;
726 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
727 if (bp >= ep)
728 break;
729 (void)printf(" upstream-neighbor=");
730 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
731 (void)printf("...");
732 break;
733 }
734 bp += advance; len -= advance;
735 }
736 if (bp + 4 > ep)
737 break;
738 ngroup = bp[1];
739 holdtime = EXTRACT_16BITS(&bp[2]);
740 (void)printf(" groups=%u", ngroup);
741 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
742 (void)printf(" holdtime=");
743 if (holdtime == 0xffff)
744 (void)printf("infty");
745 else
746 relts_print(holdtime);
747 }
748 bp += 4; len -= 4;
749 for (i = 0; i < ngroup; i++) {
750 if (bp >= ep)
751 goto jp_done;
752 (void)printf(" (group%d: ", i);
753 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
754 (void)printf("...)");
755 goto jp_done;
756 }
757 bp += advance; len -= advance;
758 if (bp + 4 > ep) {
759 (void)printf("...)");
760 goto jp_done;
761 }
762 njoin = EXTRACT_16BITS(&bp[0]);
763 nprune = EXTRACT_16BITS(&bp[2]);
764 (void)printf(" join=%u", njoin);
765 bp += 4; len -= 4;
766 for (j = 0; j < njoin; j++) {
767 (void)printf(" ");
768 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
769 (void)printf("...)");
770 goto jp_done;
771 }
772 bp += advance; len -= advance;
773 }
774 (void)printf(" prune=%u", nprune);
775 for (j = 0; j < nprune; j++) {
776 (void)printf(" ");
777 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
778 (void)printf("...)");
779 goto jp_done;
780 }
781 bp += advance; len -= advance;
782 }
783 (void)printf(")");
784 }
785 jp_done:
786 break;
787 }
788
789 case 4:
790 {
791 int i, j, frpcnt;
792
793 (void)printf(" Bootstrap");
794 bp += 4;
795
796 /* Fragment Tag, Hash Mask len, and BSR-priority */
797 if (bp + sizeof(u_int16_t) >= ep) break;
798 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
799 bp += sizeof(u_int16_t);
800 if (bp >= ep) break;
801 (void)printf(" hashmlen=%d", bp[0]);
802 if (bp + 1 >= ep) break;
803 (void)printf(" BSRprio=%d", bp[1]);
804 bp += 2;
805
806 /* Encoded-Unicast-BSR-Address */
807 if (bp >= ep) break;
808 (void)printf(" BSR=");
809 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
810 (void)printf("...");
811 break;
812 }
813 bp += advance;
814
815 for (i = 0; bp < ep; i++) {
816 /* Encoded-Group Address */
817 (void)printf(" (group%d: ", i);
818 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
819 < 0) {
820 (void)printf("...)");
821 goto bs_done;
822 }
823 bp += advance;
824
825 /* RP-Count, Frag RP-Cnt, and rsvd */
826 if (bp >= ep) {
827 (void)printf("...)");
828 goto bs_done;
829 }
830 (void)printf(" RPcnt=%d", bp[0]);
831 if (bp + 1 >= ep) {
832 (void)printf("...)");
833 goto bs_done;
834 }
835 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
836 bp += 4;
837
838 for (j = 0; j < frpcnt && bp < ep; j++) {
839 /* each RP info */
840 (void)printf(" RP%d=", j);
841 if ((advance = pimv2_addr_print(bp,
842 pimv2_unicast,
843 0)) < 0) {
844 (void)printf("...)");
845 goto bs_done;
846 }
847 bp += advance;
848
849 if (bp + 1 >= ep) {
850 (void)printf("...)");
851 goto bs_done;
852 }
853 (void)printf(",holdtime=");
854 relts_print(EXTRACT_16BITS(bp));
855 if (bp + 2 >= ep) {
856 (void)printf("...)");
857 goto bs_done;
858 }
859 (void)printf(",prio=%d", bp[2]);
860 bp += 4;
861 }
862 (void)printf(")");
863 }
864 bs_done:
865 break;
866 }
867 case 5:
868 (void)printf(" Assert");
869 bp += 4; len -= 4;
870 if (bp >= ep)
871 break;
872 (void)printf(" group=");
873 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
874 (void)printf("...");
875 break;
876 }
877 bp += advance; len -= advance;
878 if (bp >= ep)
879 break;
880 (void)printf(" src=");
881 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
882 (void)printf("...");
883 break;
884 }
885 bp += advance; len -= advance;
886 if (bp + 8 > ep)
887 break;
888 if (bp[0] & 0x80)
889 (void)printf(" RPT");
890 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
891 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
892 break;
893
894 case 8:
895 {
896 int i, pfxcnt;
897
898 (void)printf(" Candidate-RP-Advertisement");
899 bp += 4;
900
901 /* Prefix-Cnt, Priority, and Holdtime */
902 if (bp >= ep) break;
903 (void)printf(" prefix-cnt=%d", bp[0]);
904 pfxcnt = bp[0];
905 if (bp + 1 >= ep) break;
906 (void)printf(" prio=%d", bp[1]);
907 if (bp + 3 >= ep) break;
908 (void)printf(" holdtime=");
909 relts_print(EXTRACT_16BITS(&bp[2]));
910 bp += 4;
911
912 /* Encoded-Unicast-RP-Address */
913 if (bp >= ep) break;
914 (void)printf(" RP=");
915 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
916 (void)printf("...");
917 break;
918 }
919 bp += advance;
920
921 /* Encoded-Group Addresses */
922 for (i = 0; i < pfxcnt && bp < ep; i++) {
923 (void)printf(" Group%d=", i);
924 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
925 < 0) {
926 (void)printf("...");
927 break;
928 }
929 bp += advance;
930 }
931 break;
932 }
933
934 case 9:
935 (void)printf(" Prune-Refresh");
936 (void)printf(" src=");
937 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
938 (void)printf("...");
939 break;
940 }
941 bp += advance;
942 (void)printf(" grp=");
943 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
944 (void)printf("...");
945 break;
946 }
947 bp += advance;
948 (void)printf(" forwarder=");
949 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
950 (void)printf("...");
951 break;
952 }
953 bp += advance;
954 TCHECK2(bp[0], 2);
955 (void)printf(" TUNR ");
956 relts_print(EXTRACT_16BITS(bp));
957 break;
958
959
960 default:
961 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
962 break;
963 }
964
965 return;
966
967 trunc:
968 (void)printf("[|pim]");
969 }