]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
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.
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)";
31 #include <tcpdump-stdinc.h>
34 * XXX: We consider a case where IPv6 is not ready yet for portability,
35 * but PIM dependent defintions should be independent of IPv6...
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
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 */
56 #include "interface.h"
57 #include "addrtoname.h"
62 static void pimv2_print(register const u_char
*bp
, register u_int len
);
65 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
67 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
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) {
75 (void)printf(" RPF %s ", ipaddr_string(bp
));
76 hold
= EXTRACT_16BITS(&bp
[6]);
78 (void)printf("Hold ");
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");
96 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp
));
100 (void)printf(" Hold time: ");
101 relts_print(EXTRACT_16BITS(&bp
[6]));
115 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
116 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
117 (void)printf("/%s", ipaddr_string(&bp
[4]));
119 njoin
= EXTRACT_16BITS(&bp
[8]);
120 nprune
= EXTRACT_16BITS(&bp
[10]);
121 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
124 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
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);
143 (void)printf("[|pim]");
148 pimv1_print(register const u_char
*bp
, register u_int len
)
150 register const u_char
*ep
;
151 register u_char type
;
153 ep
= (const u_char
*)snapend
;
161 (void)printf(" Query");
163 switch (bp
[8] >> 4) {
165 (void)printf(" Dense-mode");
168 (void)printf(" Sparse-mode");
171 (void)printf(" Sparse-Dense-mode");
174 (void)printf(" mode-%d", bp
[8] >> 4);
180 (void)printf(" (Hold-time ");
181 relts_print(EXTRACT_16BITS(&bp
[10]));
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]));
193 (void)printf(" Register-Stop");
195 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
196 ipaddr_string(&bp
[12]));
199 (void)printf(" Join/Prune");
201 pimv1_join_prune_print(&bp
[8], len
- 8);
204 (void)printf(" RP-reachable");
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]));
216 (void)printf(" Assert");
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]));
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]));
229 (void)printf(" Graft");
231 pimv1_join_prune_print(&bp
[8], len
- 8);
234 (void)printf(" Graft-ACK");
236 pimv1_join_prune_print(&bp
[8], len
- 8);
239 (void)printf(" Mode");
242 (void)printf(" [type %d]", type
);
245 if ((bp
[4] >> 4) != 1)
246 (void)printf(" [v%d]", bp
[4] >> 4);
250 (void)printf("[|pim]");
255 * auto-RP is a cisco protocol, documented at
256 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
258 * This implements version 1+, dated Sept 9, 1998.
261 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
268 (void)printf(" auto-rp ");
272 (void)printf("candidate-advert");
275 (void)printf("mapping");
278 (void)printf("type-0x%02x", type
);
286 (void)printf(" Hold ");
287 hold
= EXTRACT_16BITS(&bp
[2]);
289 relts_print(EXTRACT_16BITS(&bp
[2]));
293 /* Next 4 bytes are reserved. */
297 /*XXX skip unless -v? */
301 * numrps entries of the form:
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.
315 (void)printf(" RP %s", ipaddr_string(bp
));
317 switch (bp
[4] & 0x3) {
318 case 0: printf(" PIMv?");
320 case 1: printf(" PIMv1");
322 case 2: printf(" PIMv2");
324 case 3: printf(" PIMv1+2");
328 (void)printf(" [rsvd=0x%02x]", bp
[4] & 0xfc);
333 for (; nentries
; nentries
--) {
335 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
336 ipaddr_string(&bp
[2]), bp
[1]);
338 (void)printf("[rsvd=0x%02x]", bp
[0] & 0xfe);
346 (void)printf("[|autorp]");
351 pim_print(register const u_char
*bp
, register u_int len
)
353 register const u_char
*ep
;
354 register struct pim
*pim
= (struct pim
*)bp
;
356 ep
= (const u_char
*)snapend
;
359 #ifdef notyet /* currently we see only version and type */
360 TCHECK(pim
->pim_rsv
);
363 switch (PIM_VER(pim
->pim_typever
)) {
364 case 2: /* avoid hardcoding? */
365 (void)printf("pim v2");
366 pimv2_print(bp
, len
);
369 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
376 * PIMv2 uses encoded address representations.
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.
387 * RFC2362 goes back to the encoded format, and calls the addr length
388 * field "reserved" again.
390 * The first byte is the address family, from:
393 * 1 IP (IP version 4)
394 * 2 IP6 (IP version 6)
396 * 4 HDLC (8-bit multidrop)
398 * 6 802 (includes all 802 media plus Ethernet "canonical format")
400 * 8 E.164 (SMDS, Frame Relay, ATM)
402 * 10 X.121 (X.25, Frame Relay)
407 * 15 E.164 with NSAP format subaddress
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
415 static int pimv2_addr_len
;
417 enum pimv2_addrtype
{
418 pimv2_unicast
, pimv2_group
, pimv2_source
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
442 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
450 if (pimv2_addr_len
== 0) {
472 switch (pimv2_addr_len
) {
487 len
= pimv2_addr_len
;
497 (void)printf("%s", ipaddr_string(bp
));
500 else if (af
== AF_INET6
) {
502 (void)printf("%s", ip6addr_string(bp
));
508 TCHECK2(bp
[0], len
+ 2);
511 (void)printf("%s", ipaddr_string(bp
+ 2));
513 (void)printf("/%u", bp
[1]);
517 else if (af
== AF_INET6
) {
519 (void)printf("%s", ip6addr_string(bp
+ 2));
521 (void)printf("/%u", bp
[1]);
525 if (bp
[0] && !silent
) {
526 if (at
== pimv2_group
) {
527 (void)printf("(0x%02x)", bp
[0]);
529 (void)printf("(%s%s%s",
530 bp
[0] & 0x04 ? "S" : "",
531 bp
[0] & 0x02 ? "W" : "",
532 bp
[0] & 0x01 ? "R" : "");
534 (void) printf("+0x%02x", bp
[0] & 0xf8);
539 return hdrlen
+ 2 + len
;
548 pimv2_print(register const u_char
*bp
, register u_int len
)
550 register const u_char
*ep
;
551 register struct pim
*pim
= (struct pim
*)bp
;
554 ep
= (const u_char
*)snapend
;
559 TCHECK(pim
->pim_rsv
);
560 pimv2_addr_len
= pim
->pim_rsv
;
561 if (pimv2_addr_len
!= 0)
562 (void)printf("[RFC2117-encoding] ");
564 switch (PIM_TYPE(pim
->pim_typever
)) {
567 u_int16_t otype
, olen
;
568 (void)printf(" Hello");
572 otype
= EXTRACT_16BITS(&bp
[0]);
573 olen
= EXTRACT_16BITS(&bp
[2]);
574 TCHECK2(bp
[0], 4 + olen
);
576 case 1: /* Hold time */
577 (void)printf(" (Hold-time ");
578 relts_print(EXTRACT_16BITS(&bp
[4]));
582 case 2: /* LAN Prune Delay */
583 (void)printf(" (LAN-Prune-Delay: ");
585 (void)printf("!olen=%d!)", olen
);
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
);
598 case 18: /* Old DR-Priority */
600 (void)printf(" (OLD-DR-Priority: %d)",
601 EXTRACT_32BITS(&bp
[4]));
607 case 19: /* DR-Priority */
609 (void)printf(" (OLD-bidir-capable)");
612 (void)printf(" (DR-Priority: ");
614 (void)printf("!olen=%d!)", olen
);
616 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
621 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
625 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
627 (void)printf(" interval ");
630 if (EXTRACT_16BITS(&bp
[6]) != 0) {
631 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
636 case 22: /* Bidir-Capable */
637 (void)printf(" (bidir-capable)");
643 (void)printf(" [Hello option %d]", otype
);
654 (void)printf(" Register");
655 if (vflag
&& bp
+ 8 <= ep
) {
656 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
657 bp
[4] & 0x40 ? "N" : "");
661 /* encapsulated multicast packet */
664 ip
= (struct ip
*)bp
;
677 (void)printf(" IP ver %d", IP_V(ip
));
684 (void)printf(" Register-Stop");
688 (void)printf(" group=");
689 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
693 bp
+= advance
; len
-= advance
;
696 (void)printf(" source=");
697 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
701 bp
+= advance
; len
-= advance
;
714 switch (PIM_TYPE(pim
->pim_typever
)) {
716 (void)printf(" Join/Prune");
719 (void)printf(" Graft");
722 (void)printf(" Graft-ACK");
726 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
729 (void)printf(" upstream-neighbor=");
730 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
734 bp
+= advance
; len
-= advance
;
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");
746 relts_print(holdtime
);
749 for (i
= 0; i
< ngroup
; i
++) {
752 (void)printf(" (group%d: ", i
);
753 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
754 (void)printf("...)");
757 bp
+= advance
; len
-= advance
;
759 (void)printf("...)");
762 njoin
= EXTRACT_16BITS(&bp
[0]);
763 nprune
= EXTRACT_16BITS(&bp
[2]);
764 (void)printf(" join=%u", njoin
);
766 for (j
= 0; j
< njoin
; j
++) {
768 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
769 (void)printf("...)");
772 bp
+= advance
; len
-= advance
;
774 (void)printf(" prune=%u", nprune
);
775 for (j
= 0; j
< nprune
; j
++) {
777 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
778 (void)printf("...)");
781 bp
+= advance
; len
-= advance
;
793 (void)printf(" Bootstrap");
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
);
801 (void)printf(" hashmlen=%d", bp
[0]);
802 if (bp
+ 1 >= ep
) break;
803 (void)printf(" BSRprio=%d", bp
[1]);
806 /* Encoded-Unicast-BSR-Address */
808 (void)printf(" BSR=");
809 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
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))
820 (void)printf("...)");
825 /* RP-Count, Frag RP-Cnt, and rsvd */
827 (void)printf("...)");
830 (void)printf(" RPcnt=%d", bp
[0]);
832 (void)printf("...)");
835 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
838 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
840 (void)printf(" RP%d=", j
);
841 if ((advance
= pimv2_addr_print(bp
,
844 (void)printf("...)");
850 (void)printf("...)");
853 (void)printf(",holdtime=");
854 relts_print(EXTRACT_16BITS(bp
));
856 (void)printf("...)");
859 (void)printf(",prio=%d", bp
[2]);
868 (void)printf(" Assert");
872 (void)printf(" group=");
873 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
877 bp
+= advance
; len
-= advance
;
880 (void)printf(" src=");
881 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
885 bp
+= advance
; len
-= advance
;
889 (void)printf(" RPT");
890 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
891 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
898 (void)printf(" Candidate-RP-Advertisement");
901 /* Prefix-Cnt, Priority, and Holdtime */
903 (void)printf(" prefix-cnt=%d", 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]));
912 /* Encoded-Unicast-RP-Address */
914 (void)printf(" RP=");
915 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
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))
935 (void)printf(" Prune-Refresh");
936 (void)printf(" src=");
937 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
942 (void)printf(" grp=");
943 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
948 (void)printf(" forwarder=");
949 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
955 (void)printf(" TUNR ");
956 relts_print(EXTRACT_16BITS(bp
));
961 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
968 (void)printf("[|pim]");