]>
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.28 2001-06-15 22:17:34 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/pim-autorp-spec01.txt
264 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
271 (void)printf(" auto-rp ");
275 (void)printf("candidate-advert");
278 (void)printf("mapping");
281 (void)printf("type-0x%02x", type
);
289 (void)printf(" Hold ");
290 hold
= EXTRACT_16BITS(&bp
[2]);
292 relts_print(EXTRACT_16BITS(&bp
[2]));
296 /* Next 4 bytes are reserved. */
300 /*XXX skip unless -v? */
304 * numrps entries of the form:
307 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
308 * 8 bits: # of entries for this RP
309 * each entry: 7 bits: reserved, 1 bit: negative,
310 * 8 bits: mask 32 bits: source
311 * lather, rinse, repeat.
318 (void)printf(" RP %s", ipaddr_string(bp
));
320 switch (bp
[4] & 0x3) {
321 case 0: printf(" PIMv?");
323 case 1: printf(" PIMv1");
325 case 2: printf(" PIMv2");
327 case 3: printf(" PIMv1+2");
334 for (; nentries
; nentries
--) {
336 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
337 ipaddr_string(&bp
[2]), bp
[1]);
345 (void)printf("[|autorp]");
350 pim_print(register const u_char
*bp
, register u_int len
)
352 register const u_char
*ep
;
353 register struct pim
*pim
= (struct pim
*)bp
;
355 ep
= (const u_char
*)snapend
;
358 #ifdef notyet /* currently we see only version and type */
359 TCHECK(pim
->pim_rsv
);
362 switch (PIM_VER(pim
->pim_typever
)) {
363 case 2: /* avoid hardcoding? */
364 (void)printf("pim v2");
365 pimv2_print(bp
, len
);
368 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
375 * PIMv2 uses encoded address representations.
377 * The last PIM-SM I-D before RFC2117 was published specified the
378 * following representation for unicast addresses. However, RFC2117
379 * specified no encoding for unicast addresses with the unicast
380 * address length specified in the header. Therefore, we have to
381 * guess which encoding is being used (Cisco's PIMv2 implementation
382 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
383 * field into a 'unicast-address-length-in-bytes' field. We guess
384 * that it's the draft encoding if this reserved field is zero.
386 * RFC2362 goes back to the encoded format, and calls the addr length
387 * field "reserved" again.
389 * The first byte is the address family, from:
392 * 1 IP (IP version 4)
393 * 2 IP6 (IP version 6)
395 * 4 HDLC (8-bit multidrop)
397 * 6 802 (includes all 802 media plus Ethernet "canonical format")
399 * 8 E.164 (SMDS, Frame Relay, ATM)
401 * 10 X.121 (X.25, Frame Relay)
406 * 15 E.164 with NSAP format subaddress
408 * In addition, the second byte is an "Encoding". 0 is the default
409 * encoding for the address family, and no other encodings are currently
414 static int pimv2_addr_len
;
416 enum pimv2_addrtype
{
417 pimv2_unicast
, pimv2_group
, pimv2_source
421 * 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
422 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
423 * | Addr Family | Encoding Type | Unicast Address |
424 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
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 | Reserved | Mask Len |
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
430 * | Group multicast Address |
431 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * 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
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
449 if (pimv2_addr_len
== 0) {
471 switch (pimv2_addr_len
) {
486 len
= pimv2_addr_len
;
496 (void)printf("%s", ipaddr_string(bp
));
499 else if (af
== AF_INET6
) {
501 (void)printf("%s", ip6addr_string(bp
));
507 TCHECK2(bp
[0], len
+ 2);
510 (void)printf("%s", ipaddr_string(bp
+ 2));
512 (void)printf("/%u", bp
[1]);
516 else if (af
== AF_INET6
) {
518 (void)printf("%s", ip6addr_string(bp
+ 2));
520 (void)printf("/%u", bp
[1]);
524 if (bp
[0] && !silent
) {
525 if (at
== pimv2_group
) {
526 (void)printf("(0x%02x)", bp
[0]);
528 (void)printf("(%s%s%s",
529 bp
[0] & 0x04 ? "S" : "",
530 bp
[0] & 0x02 ? "W" : "",
531 bp
[0] & 0x01 ? "R" : "");
533 (void) printf("+0x%02x", bp
[0] & 0xf8);
538 return hdrlen
+ 2 + len
;
547 pimv2_print(register const u_char
*bp
, register u_int len
)
549 register const u_char
*ep
;
550 register struct pim
*pim
= (struct pim
*)bp
;
553 ep
= (const u_char
*)snapend
;
558 TCHECK(pim
->pim_rsv
);
559 pimv2_addr_len
= pim
->pim_rsv
;
560 if (pimv2_addr_len
!= 0)
561 (void)printf("[RFC2117-encoding] ");
563 switch (PIM_TYPE(pim
->pim_typever
)) {
566 u_int16_t otype
, olen
;
567 (void)printf(" Hello");
571 otype
= EXTRACT_16BITS(&bp
[0]);
572 olen
= EXTRACT_16BITS(&bp
[2]);
573 TCHECK2(bp
[0], 4 + olen
);
575 case 1: /* Hold time */
576 (void)printf(" (Hold-time ");
577 relts_print(EXTRACT_16BITS(&bp
[4]));
581 case 19: /* DR-Priority */
582 (void)printf(" (DR-Priority: ");
584 (void)printf("!olen=%d!)", olen
);
586 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
591 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
595 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
597 (void)printf(" interval ");
600 if (EXTRACT_16BITS(&bp
[6]) != 0) {
601 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
606 case 22: /* Bidir-Capable */
607 (void)printf(" (bidir-capable)");
612 (void)printf(" [Hello option %d]", otype
);
623 (void)printf(" Register");
624 if (vflag
&& bp
+ 8 <= ep
) {
625 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
626 bp
[4] & 0x40 ? "N" : "");
630 /* encapsulated multicast packet */
633 ip
= (struct ip
*)bp
;
646 (void)printf(" IP ver %d", IP_V(ip
));
653 (void)printf(" Register-Stop");
657 (void)printf(" group=");
658 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
662 bp
+= advance
; len
-= advance
;
665 (void)printf(" source=");
666 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
670 bp
+= advance
; len
-= advance
;
683 switch (PIM_TYPE(pim
->pim_typever
)) {
685 (void)printf(" Join/Prune");
688 (void)printf(" Graft");
691 (void)printf(" Graft-ACK");
695 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
698 (void)printf(" upstream-neighbor=");
699 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
703 bp
+= advance
; len
-= advance
;
708 holdtime
= EXTRACT_16BITS(&bp
[2]);
709 (void)printf(" groups=%u", ngroup
);
710 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
711 (void)printf(" holdtime=");
712 if (holdtime
== 0xffff)
713 (void)printf("infty");
715 relts_print(holdtime
);
718 for (i
= 0; i
< ngroup
; i
++) {
721 (void)printf(" (group%d: ", i
);
722 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
723 (void)printf("...)");
726 bp
+= advance
; len
-= advance
;
728 (void)printf("...)");
731 njoin
= EXTRACT_16BITS(&bp
[0]);
732 nprune
= EXTRACT_16BITS(&bp
[2]);
733 (void)printf(" join=%u", njoin
);
735 for (j
= 0; j
< njoin
; j
++) {
737 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
738 (void)printf("...)");
741 bp
+= advance
; len
-= advance
;
743 (void)printf(" prune=%u", nprune
);
744 for (j
= 0; j
< nprune
; j
++) {
746 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
747 (void)printf("...)");
750 bp
+= advance
; len
-= advance
;
762 (void)printf(" Bootstrap");
765 /* Fragment Tag, Hash Mask len, and BSR-priority */
766 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
767 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
768 bp
+= sizeof(u_int16_t
);
770 (void)printf(" hashmlen=%d", bp
[0]);
771 if (bp
+ 1 >= ep
) break;
772 (void)printf(" BSRprio=%d", bp
[1]);
775 /* Encoded-Unicast-BSR-Address */
777 (void)printf(" BSR=");
778 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
784 for (i
= 0; bp
< ep
; i
++) {
785 /* Encoded-Group Address */
786 (void)printf(" (group%d: ", i
);
787 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
789 (void)printf("...)");
794 /* RP-Count, Frag RP-Cnt, and rsvd */
796 (void)printf("...)");
799 (void)printf(" RPcnt=%d", bp
[0]);
801 (void)printf("...)");
804 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
807 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
809 (void)printf(" RP%d=", j
);
810 if ((advance
= pimv2_addr_print(bp
,
813 (void)printf("...)");
819 (void)printf("...)");
822 (void)printf(",holdtime=");
823 relts_print(EXTRACT_16BITS(bp
));
825 (void)printf("...)");
828 (void)printf(",prio=%d", bp
[2]);
837 (void)printf(" Assert");
841 (void)printf(" group=");
842 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
846 bp
+= advance
; len
-= advance
;
849 (void)printf(" src=");
850 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
854 bp
+= advance
; len
-= advance
;
858 (void)printf(" RPT");
859 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
860 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
867 (void)printf(" Candidate-RP-Advertisement");
870 /* Prefix-Cnt, Priority, and Holdtime */
872 (void)printf(" prefix-cnt=%d", bp
[0]);
874 if (bp
+ 1 >= ep
) break;
875 (void)printf(" prio=%d", bp
[1]);
876 if (bp
+ 3 >= ep
) break;
877 (void)printf(" holdtime=");
878 relts_print(EXTRACT_16BITS(&bp
[2]));
881 /* Encoded-Unicast-RP-Address */
883 (void)printf(" RP=");
884 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
890 /* Encoded-Group Addresses */
891 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
892 (void)printf(" Group%d=", i
);
893 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
904 (void)printf(" Prune-Refresh");
905 (void)printf(" src=");
906 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
911 (void)printf(" grp=");
912 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
917 (void)printf(" forwarder=");
918 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
924 (void)printf(" TUNR ");
925 relts_print(EXTRACT_16BITS(bp
));
930 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
937 (void)printf("[|pim]");