2 * Copyright (c) 1995, 1996
3 * The Regents of the University of California. All rights reserved.
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
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.
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.37.2.4 2004/03/24 02:52:37 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
36 * XXX: We consider a case where IPv6 is not ready yet for portability,
37 * but PIM dependent defintions should be independent of IPv6...
42 /* upper 4bit: PIM version number; 2 for PIMv2 */
43 /* lower 4bit: the PIM message type, currently they are:
44 * Hello, Register, Register-Stop, Join/Prune,
45 * Bootstrap, Assert, Graft (PIM-DM only),
46 * Graft-Ack (PIM-DM only), C-RP-Adv
48 #define PIM_VER(x) (((x) & 0xf0) >> 4)
49 #define PIM_TYPE(x) ((x) & 0x0f)
50 u_char pim_rsv; /* Reserved */
51 u_short pim_cksum; /* IP style check sum */
58 #include "interface.h"
59 #include "addrtoname.h"
64 static void pimv2_print(register const u_char *bp, register u_int len);
67 pimv1_join_prune_print(register const u_char *bp, register u_int len)
69 int maddrlen, addrlen, ngroups, njoin, nprune;
72 /* If it's a single group and a single source, use 1-line output. */
73 if (TTEST2(bp[0], 30) && bp[11] == 1 &&
74 ((njoin = EXTRACT_16BITS(&bp[20])) + EXTRACT_16BITS(&bp[22])) == 1) {
77 (void)printf(" RPF %s ", ipaddr_string(bp));
78 hold = EXTRACT_16BITS(&bp[6]);
80 (void)printf("Hold ");
83 (void)printf("%s (%s/%d, %s", njoin ? "Join" : "Prune",
84 ipaddr_string(&bp[26]), bp[25] & 0x3f,
85 ipaddr_string(&bp[12]));
86 if (EXTRACT_32BITS(&bp[16]) != 0xffffffff)
87 (void)printf("/%s", ipaddr_string(&bp[16]));
88 (void)printf(") %s%s %s",
89 (bp[24] & 0x01) ? "Sparse" : "Dense",
90 (bp[25] & 0x80) ? " WC" : "",
91 (bp[25] & 0x40) ? "RP" : "SPT");
98 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp));
102 (void)printf(" Hold time: ");
103 relts_print(EXTRACT_16BITS(&bp[6]));
117 (void)printf("\n\tGroup: %s", ipaddr_string(bp));
119 if (EXTRACT_32BITS(&bp[4]) != 0xffffffff)
120 (void)printf("/%s", ipaddr_string(&bp[4]));
122 njoin = EXTRACT_16BITS(&bp[8]);
123 nprune = EXTRACT_16BITS(&bp[10]);
124 (void)printf(" joined: %d pruned: %d", njoin, nprune);
127 for (njp = 0; njp < (njoin + nprune); njp++) {
135 (void)printf("\n\t%s %s%s%s%s/%d", type,
136 (bp[0] & 0x01) ? "Sparse " : "Dense ",
137 (bp[1] & 0x80) ? "WC " : "",
138 (bp[1] & 0x40) ? "RP " : "SPT ",
139 ipaddr_string(&bp[2]), bp[1] & 0x3f);
146 (void)printf("[|pim]");
151 pimv1_print(register const u_char *bp, register u_int len)
153 register const u_char *ep;
154 register u_char type;
156 ep = (const u_char *)snapend;
165 (void)printf(" Query");
167 switch (bp[8] >> 4) {
169 (void)printf(" Dense-mode");
172 (void)printf(" Sparse-mode");
175 (void)printf(" Sparse-Dense-mode");
178 (void)printf(" mode-%d", bp[8] >> 4);
184 (void)printf(" (Hold-time ");
185 relts_print(EXTRACT_16BITS(&bp[10]));
191 (void)printf(" Register");
192 TCHECK2(bp[8], 20); /* ip header */
193 (void)printf(" for %s > %s", ipaddr_string(&bp[20]),
194 ipaddr_string(&bp[24]));
197 (void)printf(" Register-Stop");
199 (void)printf(" for %s > %s", ipaddr_string(&bp[8]),
200 ipaddr_string(&bp[12]));
203 (void)printf(" Join/Prune");
205 pimv1_join_prune_print(&bp[8], len - 8);
208 (void)printf(" RP-reachable");
211 (void)printf(" group %s",
212 ipaddr_string(&bp[8]));
213 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
214 (void)printf("/%s", ipaddr_string(&bp[12]));
215 (void)printf(" RP %s hold ", ipaddr_string(&bp[16]));
216 relts_print(EXTRACT_16BITS(&bp[22]));
220 (void)printf(" Assert");
222 (void)printf(" for %s > %s", ipaddr_string(&bp[16]),
223 ipaddr_string(&bp[8]));
224 if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
225 (void)printf("/%s", ipaddr_string(&bp[12]));
227 (void)printf(" %s pref %d metric %d",
228 (bp[20] & 0x80) ? "RP-tree" : "SPT",
229 EXTRACT_32BITS(&bp[20]) & 0x7fffffff,
230 EXTRACT_32BITS(&bp[24]));
233 (void)printf(" Graft");
235 pimv1_join_prune_print(&bp[8], len - 8);
238 (void)printf(" Graft-ACK");
240 pimv1_join_prune_print(&bp[8], len - 8);
243 (void)printf(" Mode");
246 (void)printf(" [type %d]", type);
249 if ((bp[4] >> 4) != 1)
250 (void)printf(" [v%d]", bp[4] >> 4);
254 (void)printf("[|pim]");
259 * auto-RP is a cisco protocol, documented at
260 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
262 * This implements version 1+, dated Sept 9, 1998.
265 cisco_autorp_print(register const u_char *bp, register u_int len)
272 (void)printf(" auto-rp ");
276 (void)printf("candidate-advert");
279 (void)printf("mapping");
282 (void)printf("type-0x%02x", type);
290 (void)printf(" Hold ");
291 hold = EXTRACT_16BITS(&bp[2]);
293 relts_print(EXTRACT_16BITS(&bp[2]));
297 /* Next 4 bytes are reserved. */
301 /*XXX skip unless -v? */
305 * numrps entries of the form:
308 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
309 * 8 bits: # of entries for this RP
310 * each entry: 7 bits: reserved, 1 bit: negative,
311 * 8 bits: mask 32 bits: source
312 * lather, rinse, repeat.
319 (void)printf(" RP %s", ipaddr_string(bp));
321 switch (bp[4] & 0x3) {
322 case 0: printf(" PIMv?");
324 case 1: printf(" PIMv1");
326 case 2: printf(" PIMv2");
328 case 3: printf(" PIMv1+2");
332 (void)printf(" [rsvd=0x%02x]", bp[4] & 0xfc);
337 for (; nentries; nentries--) {
339 (void)printf("%c%s%s/%d", s, bp[0] & 1 ? "!" : "",
340 ipaddr_string(&bp[2]), bp[1]);
342 (void)printf("[rsvd=0x%02x]", bp[0] & 0xfe);
350 (void)printf("[|autorp]");
355 pim_print(register const u_char *bp, register u_int len)
357 register const u_char *ep;
358 register struct pim *pim = (struct pim *)bp;
360 ep = (const u_char *)snapend;
363 #ifdef notyet /* currently we see only version and type */
364 TCHECK(pim->pim_rsv);
367 switch (PIM_VER(pim->pim_typever)) {
368 case 2: /* avoid hardcoding? */
369 (void)printf("pim v2");
370 pimv2_print(bp, len);
373 (void)printf("pim v%d", PIM_VER(pim->pim_typever));
380 * PIMv2 uses encoded address representations.
382 * The last PIM-SM I-D before RFC2117 was published specified the
383 * following representation for unicast addresses. However, RFC2117
384 * specified no encoding for unicast addresses with the unicast
385 * address length specified in the header. Therefore, we have to
386 * guess which encoding is being used (Cisco's PIMv2 implementation
387 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
388 * field into a 'unicast-address-length-in-bytes' field. We guess
389 * that it's the draft encoding if this reserved field is zero.
391 * RFC2362 goes back to the encoded format, and calls the addr length
392 * field "reserved" again.
394 * The first byte is the address family, from:
397 * 1 IP (IP version 4)
398 * 2 IP6 (IP version 6)
400 * 4 HDLC (8-bit multidrop)
402 * 6 802 (includes all 802 media plus Ethernet "canonical format")
404 * 8 E.164 (SMDS, Frame Relay, ATM)
406 * 10 X.121 (X.25, Frame Relay)
411 * 15 E.164 with NSAP format subaddress
413 * In addition, the second byte is an "Encoding". 0 is the default
414 * encoding for the address family, and no other encodings are currently
419 static int pimv2_addr_len;
421 enum pimv2_addrtype {
422 pimv2_unicast, pimv2_group, pimv2_source
426 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
427 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
428 * | Addr Family | Encoding Type | Unicast Address |
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
431 * 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
432 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * | Addr Family | Encoding Type | Reserved | Mask Len |
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Group multicast Address |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438 * 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
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446 pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
454 if (pimv2_addr_len == 0) {
476 switch (pimv2_addr_len) {
491 len = pimv2_addr_len;
501 (void)printf("%s", ipaddr_string(bp));
504 else if (af == AF_INET6) {
506 (void)printf("%s", ip6addr_string(bp));
512 TCHECK2(bp[0], len + 2);
515 (void)printf("%s", ipaddr_string(bp + 2));
517 (void)printf("/%u", bp[1]);
521 else if (af == AF_INET6) {
523 (void)printf("%s", ip6addr_string(bp + 2));
525 (void)printf("/%u", bp[1]);
529 if (bp[0] && !silent) {
530 if (at == pimv2_group) {
531 (void)printf("(0x%02x)", bp[0]);
533 (void)printf("(%s%s%s",
534 bp[0] & 0x04 ? "S" : "",
535 bp[0] & 0x02 ? "W" : "",
536 bp[0] & 0x01 ? "R" : "");
538 (void) printf("+0x%02x", bp[0] & 0xf8);
543 return hdrlen + 2 + len;
552 pimv2_print(register const u_char *bp, register u_int len)
554 register const u_char *ep;
555 register struct pim *pim = (struct pim *)bp;
558 ep = (const u_char *)snapend;
563 TCHECK(pim->pim_rsv);
564 pimv2_addr_len = pim->pim_rsv;
565 if (pimv2_addr_len != 0)
566 (void)printf("[RFC2117-encoding] ");
568 switch (PIM_TYPE(pim->pim_typever)) {
571 u_int16_t otype, olen;
572 (void)printf(" Hello");
576 otype = EXTRACT_16BITS(&bp[0]);
577 olen = EXTRACT_16BITS(&bp[2]);
578 TCHECK2(bp[0], 4 + olen);
580 case 1: /* Hold time */
581 (void)printf(" (Hold-time ");
582 relts_print(EXTRACT_16BITS(&bp[4]));
586 case 2: /* LAN Prune Delay */
587 (void)printf(" (LAN-Prune-Delay: ");
589 (void)printf("!olen=%d!)", olen);
592 u_int16_t lan_delay, override_interval;
593 lan_delay = EXTRACT_16BITS(&bp[4]);
594 override_interval = EXTRACT_16BITS(&bp[6]);
595 t_bit = (lan_delay & 0x8000)? 1 : 0;
596 lan_delay &= ~0x8000;
597 (void)printf("T-bit=%d lan-delay=%dms override-interval=%dms)",
598 t_bit, lan_delay, override_interval);
602 case 18: /* Old DR-Priority */
604 (void)printf(" (OLD-DR-Priority: %d)",
605 EXTRACT_32BITS(&bp[4]));
611 case 19: /* DR-Priority */
613 (void)printf(" (OLD-bidir-capable)");
616 (void)printf(" (DR-Priority: ");
618 (void)printf("!olen=%d!)", olen);
620 (void)printf("%d)", EXTRACT_32BITS(&bp[4]));
625 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp[4]));
629 (void)printf(" (State Refresh Capable; v%d", bp[4]);
631 (void)printf(" interval ");
634 if (EXTRACT_16BITS(&bp[6]) != 0) {
635 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp[6]));
640 case 22: /* Bidir-Capable */
641 (void)printf(" (bidir-capable)");
644 case 24: /* Address List */
645 case 65001: /* Address List (old implementations) */
646 (void)printf(" (%saddr-list",
647 otype == 65001 ? "old" : "");
649 const u_char *ptr = &bp[4];
650 while (ptr < &bp[4 + olen]) {
654 advance = pimv2_addr_print(ptr, pimv2_unicast, 0);
667 (void)printf(" [Hello option %d]", otype);
678 (void)printf(" Register");
679 if (vflag && bp + 8 <= ep) {
680 (void)printf(" %s%s", bp[4] & 0x80 ? "B" : "",
681 bp[4] & 0x40 ? "N" : "");
685 /* encapsulated multicast packet */
688 ip = (struct ip *)bp;
701 (void)printf(" IP ver %d", IP_V(ip));
708 (void)printf(" Register-Stop");
712 (void)printf(" group=");
713 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
717 bp += advance; len -= advance;
720 (void)printf(" source=");
721 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
725 bp += advance; len -= advance;
738 switch (PIM_TYPE(pim->pim_typever)) {
740 (void)printf(" Join/Prune");
743 (void)printf(" Graft");
746 (void)printf(" Graft-ACK");
750 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
753 (void)printf(" upstream-neighbor=");
754 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
758 bp += advance; len -= advance;
763 holdtime = EXTRACT_16BITS(&bp[2]);
764 (void)printf(" groups=%u", ngroup);
765 if (PIM_TYPE(pim->pim_typever) != 7) { /*not for Graft-ACK*/
766 (void)printf(" holdtime=");
767 if (holdtime == 0xffff)
768 (void)printf("infty");
770 relts_print(holdtime);
773 for (i = 0; i < ngroup; i++) {
776 (void)printf(" (group%d: ", i);
777 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
778 (void)printf("...)");
781 bp += advance; len -= advance;
783 (void)printf("...)");
786 njoin = EXTRACT_16BITS(&bp[0]);
787 nprune = EXTRACT_16BITS(&bp[2]);
788 (void)printf(" join=%u", njoin);
790 for (j = 0; j < njoin; j++) {
792 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
793 (void)printf("...)");
796 bp += advance; len -= advance;
798 (void)printf(" prune=%u", nprune);
799 for (j = 0; j < nprune; j++) {
801 if ((advance = pimv2_addr_print(bp, pimv2_source, 0)) < 0) {
802 (void)printf("...)");
805 bp += advance; len -= advance;
817 (void)printf(" Bootstrap");
820 /* Fragment Tag, Hash Mask len, and BSR-priority */
821 if (bp + sizeof(u_int16_t) >= ep) break;
822 (void)printf(" tag=%x", EXTRACT_16BITS(bp));
823 bp += sizeof(u_int16_t);
825 (void)printf(" hashmlen=%d", bp[0]);
826 if (bp + 1 >= ep) break;
827 (void)printf(" BSRprio=%d", bp[1]);
830 /* Encoded-Unicast-BSR-Address */
832 (void)printf(" BSR=");
833 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
839 for (i = 0; bp < ep; i++) {
840 /* Encoded-Group Address */
841 (void)printf(" (group%d: ", i);
842 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
844 (void)printf("...)");
849 /* RP-Count, Frag RP-Cnt, and rsvd */
851 (void)printf("...)");
854 (void)printf(" RPcnt=%d", bp[0]);
856 (void)printf("...)");
859 (void)printf(" FRPcnt=%d", frpcnt = bp[1]);
862 for (j = 0; j < frpcnt && bp < ep; j++) {
864 (void)printf(" RP%d=", j);
865 if ((advance = pimv2_addr_print(bp,
868 (void)printf("...)");
874 (void)printf("...)");
877 (void)printf(",holdtime=");
878 relts_print(EXTRACT_16BITS(bp));
880 (void)printf("...)");
883 (void)printf(",prio=%d", bp[2]);
892 (void)printf(" Assert");
896 (void)printf(" group=");
897 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
901 bp += advance; len -= advance;
904 (void)printf(" src=");
905 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
909 bp += advance; len -= advance;
913 (void)printf(" RPT");
914 (void)printf(" pref=%u", EXTRACT_32BITS(&bp[0]) & 0x7fffffff);
915 (void)printf(" metric=%u", EXTRACT_32BITS(&bp[4]));
922 (void)printf(" Candidate-RP-Advertisement");
925 /* Prefix-Cnt, Priority, and Holdtime */
927 (void)printf(" prefix-cnt=%d", bp[0]);
929 if (bp + 1 >= ep) break;
930 (void)printf(" prio=%d", bp[1]);
931 if (bp + 3 >= ep) break;
932 (void)printf(" holdtime=");
933 relts_print(EXTRACT_16BITS(&bp[2]));
936 /* Encoded-Unicast-RP-Address */
938 (void)printf(" RP=");
939 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
945 /* Encoded-Group Addresses */
946 for (i = 0; i < pfxcnt && bp < ep; i++) {
947 (void)printf(" Group%d=", i);
948 if ((advance = pimv2_addr_print(bp, pimv2_group, 0))
959 (void)printf(" Prune-Refresh");
960 (void)printf(" src=");
961 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
966 (void)printf(" grp=");
967 if ((advance = pimv2_addr_print(bp, pimv2_group, 0)) < 0) {
972 (void)printf(" forwarder=");
973 if ((advance = pimv2_addr_print(bp, pimv2_unicast, 0)) < 0) {
979 (void)printf(" TUNR ");
980 relts_print(EXTRACT_16BITS(bp));
985 (void)printf(" [type %d]", PIM_TYPE(pim->pim_typever));
992 (void)printf("[|pim]");