]>
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.29 2001-07-04 21:36:15 fenner Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
38 * XXX: We consider a case where IPv6 is not ready yet for portability,
39 * but PIM dependent defintions should be independent of IPv6...
44 /* upper 4bit: PIM version number; 2 for PIMv2 */
45 /* lower 4bit: the PIM message type, currently they are:
46 * Hello, Register, Register-Stop, Join/Prune,
47 * Bootstrap, Assert, Graft (PIM-DM only),
48 * Graft-Ack (PIM-DM only), C-RP-Adv
50 #define PIM_VER(x) (((x) & 0xf0) >> 4)
51 #define PIM_TYPE(x) ((x) & 0x0f)
52 u_char pim_rsv
; /* Reserved */
53 u_short pim_cksum
; /* IP style check sum */
61 #include "interface.h"
62 #include "addrtoname.h"
67 static void pimv2_print(register const u_char
*bp
, register u_int len
);
70 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
72 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
75 /* If it's a single group and a single source, use 1-line output. */
76 if (TTEST2(bp
[0], 30) && bp
[11] == 1 &&
77 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
80 (void)printf(" RPF %s ", ipaddr_string(bp
));
81 hold
= EXTRACT_16BITS(&bp
[6]);
83 (void)printf("Hold ");
86 (void)printf("%s (%s/%d, %s", njoin
? "Join" : "Prune",
87 ipaddr_string(&bp
[26]), bp
[25] & 0x3f,
88 ipaddr_string(&bp
[12]));
89 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
90 (void)printf("/%s", ipaddr_string(&bp
[16]));
91 (void)printf(") %s%s %s",
92 (bp
[24] & 0x01) ? "Sparse" : "Dense",
93 (bp
[25] & 0x80) ? " WC" : "",
94 (bp
[25] & 0x40) ? "RP" : "SPT");
101 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp
));
105 (void)printf(" Hold time: ");
106 relts_print(EXTRACT_16BITS(&bp
[6]));
120 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
121 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
122 (void)printf("/%s", ipaddr_string(&bp
[4]));
124 njoin
= EXTRACT_16BITS(&bp
[8]);
125 nprune
= EXTRACT_16BITS(&bp
[10]);
126 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
129 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
137 (void)printf("\n\t%s %s%s%s%s/%d", type
,
138 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
139 (bp
[1] & 0x80) ? "WC " : "",
140 (bp
[1] & 0x40) ? "RP " : "SPT ",
141 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
148 (void)printf("[|pim]");
153 pimv1_print(register const u_char
*bp
, register u_int len
)
155 register const u_char
*ep
;
156 register u_char type
;
158 ep
= (const u_char
*)snapend
;
166 (void)printf(" Query");
168 switch (bp
[8] >> 4) {
170 (void)printf(" Dense-mode");
173 (void)printf(" Sparse-mode");
176 (void)printf(" Sparse-Dense-mode");
179 (void)printf(" mode-%d", bp
[8] >> 4);
185 (void)printf(" (Hold-time ");
186 relts_print(EXTRACT_16BITS(&bp
[10]));
192 (void)printf(" Register");
193 TCHECK2(bp
[8], 20); /* ip header */
194 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
195 ipaddr_string(&bp
[24]));
198 (void)printf(" Register-Stop");
200 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
201 ipaddr_string(&bp
[12]));
204 (void)printf(" Join/Prune");
206 pimv1_join_prune_print(&bp
[8], len
- 8);
209 (void)printf(" RP-reachable");
212 (void)printf(" group %s",
213 ipaddr_string(&bp
[8]));
214 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
215 (void)printf("/%s", ipaddr_string(&bp
[12]));
216 (void)printf(" RP %s hold ", ipaddr_string(&bp
[16]));
217 relts_print(EXTRACT_16BITS(&bp
[22]));
221 (void)printf(" Assert");
223 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
224 ipaddr_string(&bp
[8]));
225 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
226 (void)printf("/%s", ipaddr_string(&bp
[12]));
228 (void)printf(" %s pref %d metric %d",
229 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
230 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
231 EXTRACT_32BITS(&bp
[24]));
234 (void)printf(" Graft");
236 pimv1_join_prune_print(&bp
[8], len
- 8);
239 (void)printf(" Graft-ACK");
241 pimv1_join_prune_print(&bp
[8], len
- 8);
244 (void)printf(" Mode");
247 (void)printf(" [type %d]", type
);
250 if ((bp
[4] >> 4) != 1)
251 (void)printf(" [v%d]", bp
[4] >> 4);
255 (void)printf("[|pim]");
260 * auto-RP is a cisco protocol, documented at
261 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
263 * This implements version 1+, dated Sept 9, 1998.
266 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
273 (void)printf(" auto-rp ");
277 (void)printf("candidate-advert");
280 (void)printf("mapping");
283 (void)printf("type-0x%02x", type
);
291 (void)printf(" Hold ");
292 hold
= EXTRACT_16BITS(&bp
[2]);
294 relts_print(EXTRACT_16BITS(&bp
[2]));
298 /* Next 4 bytes are reserved. */
302 /*XXX skip unless -v? */
306 * numrps entries of the form:
309 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
310 * 8 bits: # of entries for this RP
311 * each entry: 7 bits: reserved, 1 bit: negative,
312 * 8 bits: mask 32 bits: source
313 * lather, rinse, repeat.
320 (void)printf(" RP %s", ipaddr_string(bp
));
322 switch (bp
[4] & 0x3) {
323 case 0: printf(" PIMv?");
325 case 1: printf(" PIMv1");
327 case 2: printf(" PIMv2");
329 case 3: printf(" PIMv1+2");
333 (void)printf(" [rsvd=0x%02x]", bp
[4] & 0xfc);
338 for (; nentries
; nentries
--) {
340 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
341 ipaddr_string(&bp
[2]), bp
[1]);
343 (void)printf("[rsvd=0x%02x]", bp
[0] & 0xfe);
351 (void)printf("[|autorp]");
356 pim_print(register const u_char
*bp
, register u_int len
)
358 register const u_char
*ep
;
359 register struct pim
*pim
= (struct pim
*)bp
;
361 ep
= (const u_char
*)snapend
;
364 #ifdef notyet /* currently we see only version and type */
365 TCHECK(pim
->pim_rsv
);
368 switch (PIM_VER(pim
->pim_typever
)) {
369 case 2: /* avoid hardcoding? */
370 (void)printf("pim v2");
371 pimv2_print(bp
, len
);
374 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
381 * PIMv2 uses encoded address representations.
383 * The last PIM-SM I-D before RFC2117 was published specified the
384 * following representation for unicast addresses. However, RFC2117
385 * specified no encoding for unicast addresses with the unicast
386 * address length specified in the header. Therefore, we have to
387 * guess which encoding is being used (Cisco's PIMv2 implementation
388 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
389 * field into a 'unicast-address-length-in-bytes' field. We guess
390 * that it's the draft encoding if this reserved field is zero.
392 * RFC2362 goes back to the encoded format, and calls the addr length
393 * field "reserved" again.
395 * The first byte is the address family, from:
398 * 1 IP (IP version 4)
399 * 2 IP6 (IP version 6)
401 * 4 HDLC (8-bit multidrop)
403 * 6 802 (includes all 802 media plus Ethernet "canonical format")
405 * 8 E.164 (SMDS, Frame Relay, ATM)
407 * 10 X.121 (X.25, Frame Relay)
412 * 15 E.164 with NSAP format subaddress
414 * In addition, the second byte is an "Encoding". 0 is the default
415 * encoding for the address family, and no other encodings are currently
420 static int pimv2_addr_len
;
422 enum pimv2_addrtype
{
423 pimv2_unicast
, pimv2_group
, pimv2_source
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 | Unicast Address |
430 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
432 * 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
433 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
434 * | Addr Family | Encoding Type | Reserved | Mask Len |
435 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
436 * | Group multicast Address |
437 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 * 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
440 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
442 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
447 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
455 if (pimv2_addr_len
== 0) {
477 switch (pimv2_addr_len
) {
492 len
= pimv2_addr_len
;
502 (void)printf("%s", ipaddr_string(bp
));
505 else if (af
== AF_INET6
) {
507 (void)printf("%s", ip6addr_string(bp
));
513 TCHECK2(bp
[0], len
+ 2);
516 (void)printf("%s", ipaddr_string(bp
+ 2));
518 (void)printf("/%u", bp
[1]);
522 else if (af
== AF_INET6
) {
524 (void)printf("%s", ip6addr_string(bp
+ 2));
526 (void)printf("/%u", bp
[1]);
530 if (bp
[0] && !silent
) {
531 if (at
== pimv2_group
) {
532 (void)printf("(0x%02x)", bp
[0]);
534 (void)printf("(%s%s%s",
535 bp
[0] & 0x04 ? "S" : "",
536 bp
[0] & 0x02 ? "W" : "",
537 bp
[0] & 0x01 ? "R" : "");
539 (void) printf("+0x%02x", bp
[0] & 0xf8);
544 return hdrlen
+ 2 + len
;
553 pimv2_print(register const u_char
*bp
, register u_int len
)
555 register const u_char
*ep
;
556 register struct pim
*pim
= (struct pim
*)bp
;
559 ep
= (const u_char
*)snapend
;
564 TCHECK(pim
->pim_rsv
);
565 pimv2_addr_len
= pim
->pim_rsv
;
566 if (pimv2_addr_len
!= 0)
567 (void)printf("[RFC2117-encoding] ");
569 switch (PIM_TYPE(pim
->pim_typever
)) {
572 u_int16_t otype
, olen
;
573 (void)printf(" Hello");
577 otype
= EXTRACT_16BITS(&bp
[0]);
578 olen
= EXTRACT_16BITS(&bp
[2]);
579 TCHECK2(bp
[0], 4 + olen
);
581 case 1: /* Hold time */
582 (void)printf(" (Hold-time ");
583 relts_print(EXTRACT_16BITS(&bp
[4]));
587 case 19: /* DR-Priority */
588 (void)printf(" (DR-Priority: ");
590 (void)printf("!olen=%d!)", olen
);
592 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
597 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
601 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
603 (void)printf(" interval ");
606 if (EXTRACT_16BITS(&bp
[6]) != 0) {
607 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
612 case 22: /* Bidir-Capable */
613 (void)printf(" (bidir-capable)");
618 (void)printf(" [Hello option %d]", otype
);
629 (void)printf(" Register");
630 if (vflag
&& bp
+ 8 <= ep
) {
631 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
632 bp
[4] & 0x40 ? "N" : "");
636 /* encapsulated multicast packet */
639 ip
= (struct ip
*)bp
;
652 (void)printf(" IP ver %d", IP_V(ip
));
659 (void)printf(" Register-Stop");
663 (void)printf(" group=");
664 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
668 bp
+= advance
; len
-= advance
;
671 (void)printf(" source=");
672 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
676 bp
+= advance
; len
-= advance
;
689 switch (PIM_TYPE(pim
->pim_typever
)) {
691 (void)printf(" Join/Prune");
694 (void)printf(" Graft");
697 (void)printf(" Graft-ACK");
701 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
704 (void)printf(" upstream-neighbor=");
705 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
709 bp
+= advance
; len
-= advance
;
714 holdtime
= EXTRACT_16BITS(&bp
[2]);
715 (void)printf(" groups=%u", ngroup
);
716 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
717 (void)printf(" holdtime=");
718 if (holdtime
== 0xffff)
719 (void)printf("infty");
721 relts_print(holdtime
);
724 for (i
= 0; i
< ngroup
; i
++) {
727 (void)printf(" (group%d: ", i
);
728 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
729 (void)printf("...)");
732 bp
+= advance
; len
-= advance
;
734 (void)printf("...)");
737 njoin
= EXTRACT_16BITS(&bp
[0]);
738 nprune
= EXTRACT_16BITS(&bp
[2]);
739 (void)printf(" join=%u", njoin
);
741 for (j
= 0; j
< njoin
; j
++) {
743 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
744 (void)printf("...)");
747 bp
+= advance
; len
-= advance
;
749 (void)printf(" prune=%u", nprune
);
750 for (j
= 0; j
< nprune
; j
++) {
752 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
753 (void)printf("...)");
756 bp
+= advance
; len
-= advance
;
768 (void)printf(" Bootstrap");
771 /* Fragment Tag, Hash Mask len, and BSR-priority */
772 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
773 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
774 bp
+= sizeof(u_int16_t
);
776 (void)printf(" hashmlen=%d", bp
[0]);
777 if (bp
+ 1 >= ep
) break;
778 (void)printf(" BSRprio=%d", bp
[1]);
781 /* Encoded-Unicast-BSR-Address */
783 (void)printf(" BSR=");
784 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
790 for (i
= 0; bp
< ep
; i
++) {
791 /* Encoded-Group Address */
792 (void)printf(" (group%d: ", i
);
793 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
795 (void)printf("...)");
800 /* RP-Count, Frag RP-Cnt, and rsvd */
802 (void)printf("...)");
805 (void)printf(" RPcnt=%d", bp
[0]);
807 (void)printf("...)");
810 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
813 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
815 (void)printf(" RP%d=", j
);
816 if ((advance
= pimv2_addr_print(bp
,
819 (void)printf("...)");
825 (void)printf("...)");
828 (void)printf(",holdtime=");
829 relts_print(EXTRACT_16BITS(bp
));
831 (void)printf("...)");
834 (void)printf(",prio=%d", bp
[2]);
843 (void)printf(" Assert");
847 (void)printf(" group=");
848 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
852 bp
+= advance
; len
-= advance
;
855 (void)printf(" src=");
856 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
860 bp
+= advance
; len
-= advance
;
864 (void)printf(" RPT");
865 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
866 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
873 (void)printf(" Candidate-RP-Advertisement");
876 /* Prefix-Cnt, Priority, and Holdtime */
878 (void)printf(" prefix-cnt=%d", bp
[0]);
880 if (bp
+ 1 >= ep
) break;
881 (void)printf(" prio=%d", bp
[1]);
882 if (bp
+ 3 >= ep
) break;
883 (void)printf(" holdtime=");
884 relts_print(EXTRACT_16BITS(&bp
[2]));
887 /* Encoded-Unicast-RP-Address */
889 (void)printf(" RP=");
890 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
896 /* Encoded-Group Addresses */
897 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
898 (void)printf(" Group%d=", i
);
899 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
910 (void)printf(" Prune-Refresh");
911 (void)printf(" src=");
912 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
917 (void)printf(" grp=");
918 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
923 (void)printf(" forwarder=");
924 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
930 (void)printf(" TUNR ");
931 relts_print(EXTRACT_16BITS(bp
));
936 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
943 (void)printf("[|pim]");