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