]> The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
Have the configure script arrange that the Makefile define _U_
[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[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.39 2003-11-16 09:36:32 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 case 24: /* Address List */
641 case 65001: /* Address List (old implementations) */
642 (void)printf(" (%saddr-list",
643 otype == 65001 ? "old" : "");
644 if (vflag > 1) {
645 const u_char *ptr = &bp[4];
646 while (ptr < &bp[4 + olen]) {
647 int advance;
648
649 printf(" ");
650 advance = pimv2_addr_print(ptr, pimv2_unicast, 0);
651 if (advance < 0) {
652 printf("...");
653 break;
654 }
655 ptr += advance;
656 }
657 }
658 (void)printf(")");
659 break;
660 default:
661 unknown:
662 if (vflag)
663 (void)printf(" [Hello option %d]", otype);
664 }
665 bp += 4 + olen;
666 }
667 break;
668 }
669
670 case 1:
671 {
672 struct ip *ip;
673
674 (void)printf(" Register");
675 if (vflag && bp + 8 <= ep) {
676 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
677 bp[4] & 0x40 ? "N" : "");
678 }
679 bp += 8; len -= 8;
680
681 /* encapsulated multicast packet */
682 if (bp >= ep)
683 break;
684 ip = (struct ip *)bp;
685 switch (IP_V(ip)) {
686 case 4: /* IPv4 */
687 printf(" ");
688 ip_print(bp, len);
689 break;
690 #ifdef INET6
691 case 6: /* IPv6 */
692 printf(" ");
693 ip6_print(bp, len);
694 break;
695 #endif
696 default:
697 (void)printf(" IP ver %d", IP_V(ip));
698 break;
699 }
700 break;
701 }
702
703 case 2:
704 (void)printf(" Register-Stop");
705 bp += 4; len -= 4;
706 if (bp >= ep)
707 break;
708 (void)printf(" group=");
709 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
710 (void)printf("...");
711 break;
712 }
713 bp += advance; len -= advance;
714 if (bp >= ep)
715 break;
716 (void)printf(" source=");
717 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
718 (void)printf("...");
719 break;
720 }
721 bp += advance; len -= advance;
722 break;
723
724 case 3:
725 case 6:
726 case 7:
727 {
728 u_int8_t ngroup;
729 u_int16_t holdtime;
730 u_int16_t njoin;
731 u_int16_t nprune;
732 int i, j;
733
734 switch (PIM_TYPE(pim->pim_typever)) {
735 case 3:
736 (void)printf(" Join/Prune");
737 break;
738 case 6:
739 (void)printf(" Graft");
740 break;
741 case 7:
742 (void)printf(" Graft-ACK");
743 break;
744 }
745 bp += 4; len -= 4;
746 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
747 if (bp >= ep)
748 break;
749 (void)printf(" upstream-neighbor=");
750 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
751 (void)printf("...");
752 break;
753 }
754 bp += advance; len -= advance;
755 }
756 if (bp + 4 > ep)
757 break;
758 ngroup = bp[1];
759 holdtime = EXTRACT_16BITS(&bp[2]);
760 (void)printf(" groups=%u", ngroup);
761 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
762 (void)printf(" holdtime=");
763 if (holdtime == 0xffff)
764 (void)printf("infty");
765 else
766 relts_print(holdtime);
767 }
768 bp += 4; len -= 4;
769 for (i = 0; i < ngroup; i++) {
770 if (bp >= ep)
771 goto jp_done;
772 (void)printf(" (group%d: ", i);
773 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
774 (void)printf("...)");
775 goto jp_done;
776 }
777 bp += advance; len -= advance;
778 if (bp + 4 > ep) {
779 (void)printf("...)");
780 goto jp_done;
781 }
782 njoin = EXTRACT_16BITS(&bp[0]);
783 nprune = EXTRACT_16BITS(&bp[2]);
784 (void)printf(" join=%u", njoin);
785 bp += 4; len -= 4;
786 for (j = 0; j < njoin; j++) {
787 (void)printf(" ");
788 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
789 (void)printf("...)");
790 goto jp_done;
791 }
792 bp += advance; len -= advance;
793 }
794 (void)printf(" prune=%u", nprune);
795 for (j = 0; j < nprune; j++) {
796 (void)printf(" ");
797 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
798 (void)printf("...)");
799 goto jp_done;
800 }
801 bp += advance; len -= advance;
802 }
803 (void)printf(")");
804 }
805 jp_done:
806 break;
807 }
808
809 case 4:
810 {
811 int i, j, frpcnt;
812
813 (void)printf(" Bootstrap");
814 bp += 4;
815
816 /* Fragment Tag, Hash Mask len, and BSR-priority */
817 if (bp + sizeof(u_int16_t) >= ep) break;
818 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
819 bp += sizeof(u_int16_t);
820 if (bp >= ep) break;
821 (void)printf(" hashmlen=%d", bp[0]);
822 if (bp + 1 >= ep) break;
823 (void)printf(" BSRprio=%d", bp[1]);
824 bp += 2;
825
826 /* Encoded-Unicast-BSR-Address */
827 if (bp >= ep) break;
828 (void)printf(" BSR=");
829 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
830 (void)printf("...");
831 break;
832 }
833 bp += advance;
834
835 for (i = 0; bp < ep; i++) {
836 /* Encoded-Group Address */
837 (void)printf(" (group%d: ", i);
838 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
839 < 0) {
840 (void)printf("...)");
841 goto bs_done;
842 }
843 bp += advance;
844
845 /* RP-Count, Frag RP-Cnt, and rsvd */
846 if (bp >= ep) {
847 (void)printf("...)");
848 goto bs_done;
849 }
850 (void)printf(" RPcnt=%d", bp[0]);
851 if (bp + 1 >= ep) {
852 (void)printf("...)");
853 goto bs_done;
854 }
855 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
856 bp += 4;
857
858 for (j = 0; j < frpcnt && bp < ep; j++) {
859 /* each RP info */
860 (void)printf(" RP%d=", j);
861 if ((advance = pimv2_addr_print(bp,
862 pimv2_unicast,
863 0)) < 0) {
864 (void)printf("...)");
865 goto bs_done;
866 }
867 bp += advance;
868
869 if (bp + 1 >= ep) {
870 (void)printf("...)");
871 goto bs_done;
872 }
873 (void)printf(",holdtime=");
874 relts_print(EXTRACT_16BITS(bp));
875 if (bp + 2 >= ep) {
876 (void)printf("...)");
877 goto bs_done;
878 }
879 (void)printf(",prio=%d", bp[2]);
880 bp += 4;
881 }
882 (void)printf(")");
883 }
884 bs_done:
885 break;
886 }
887 case 5:
888 (void)printf(" Assert");
889 bp += 4; len -= 4;
890 if (bp >= ep)
891 break;
892 (void)printf(" group=");
893 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
894 (void)printf("...");
895 break;
896 }
897 bp += advance; len -= advance;
898 if (bp >= ep)
899 break;
900 (void)printf(" src=");
901 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
902 (void)printf("...");
903 break;
904 }
905 bp += advance; len -= advance;
906 if (bp + 8 > ep)
907 break;
908 if (bp[0] & 0x80)
909 (void)printf(" RPT");
910 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
911 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
912 break;
913
914 case 8:
915 {
916 int i, pfxcnt;
917
918 (void)printf(" Candidate-RP-Advertisement");
919 bp += 4;
920
921 /* Prefix-Cnt, Priority, and Holdtime */
922 if (bp >= ep) break;
923 (void)printf(" prefix-cnt=%d", bp[0]);
924 pfxcnt = bp[0];
925 if (bp + 1 >= ep) break;
926 (void)printf(" prio=%d", bp[1]);
927 if (bp + 3 >= ep) break;
928 (void)printf(" holdtime=");
929 relts_print(EXTRACT_16BITS(&bp[2]));
930 bp += 4;
931
932 /* Encoded-Unicast-RP-Address */
933 if (bp >= ep) break;
934 (void)printf(" RP=");
935 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
936 (void)printf("...");
937 break;
938 }
939 bp += advance;
940
941 /* Encoded-Group Addresses */
942 for (i = 0; i < pfxcnt && bp < ep; i++) {
943 (void)printf(" Group%d=", i);
944 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
945 < 0) {
946 (void)printf("...");
947 break;
948 }
949 bp += advance;
950 }
951 break;
952 }
953
954 case 9:
955 (void)printf(" Prune-Refresh");
956 (void)printf(" src=");
957 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
958 (void)printf("...");
959 break;
960 }
961 bp += advance;
962 (void)printf(" grp=");
963 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
964 (void)printf("...");
965 break;
966 }
967 bp += advance;
968 (void)printf(" forwarder=");
969 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
970 (void)printf("...");
971 break;
972 }
973 bp += advance;
974 TCHECK2(bp[0], 2);
975 (void)printf(" TUNR ");
976 relts_print(EXTRACT_16BITS(bp));
977 break;
978
979
980 default:
981 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
982 break;
983 }
984
985 return;
986
987 trunc:
988 (void)printf("[|pim]");
989 }