]>
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.15 1999-12-14 16:58:03 fenner Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <netinet/in_systm.h>
37 #include <netinet/ip.h>
39 #include <netinet/ip_var.h>
40 #include <netinet/udp.h>
41 #include <netinet/udp_var.h>
42 #include <netinet/tcp.h>
46 * XXX: We consider a case where IPv6 is not ready yet for portability,
47 * but PIM dependent defintions should be independent of IPv6...
50 #include <netinet6/pim6.h>
53 #if defined(WORDS_BIGENDIAN) || (defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN))
54 u_int pim_type
:4, /* the PIM message type, currently they are:
55 * Hello, Register, Register-Stop, Join/Prune,
56 * Bootstrap, Assert, Graft (PIM-DM only),
57 * Graft-Ack (PIM-DM only), C-RP-Adv
59 pim_ver
:4; /* PIM version number; 2 for PIMv2 */
61 u_int pim_ver
:4, /* PIM version */
62 pim_type
:4; /* PIM type */
64 u_char pim_rsv
; /* Reserved */
65 u_short pim_cksum
; /* IP style check sum */
74 #include "interface.h"
75 #include "addrtoname.h"
78 static void pimv2_print(register const u_char
*bp
, register u_int len
);
81 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
83 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
86 /* If it's a single group and a single source, use 1-line output. */
87 if (TTEST2(bp
[0], 30) && bp
[11] == 1 &&
88 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
91 (void)printf(" RPF %s ", ipaddr_string(bp
));
92 hold
= EXTRACT_16BITS(&bp
[6]);
94 (void)printf("Hold ");
97 (void)printf("%s (%s/%d, %s", njoin
? "Join" : "Prune",
98 ipaddr_string(&bp
[26]), bp
[25] & 0x3f,
99 ipaddr_string(&bp
[12]));
100 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
101 (void)printf("/%s", ipaddr_string(&bp
[16]));
102 (void)printf(") %s%s %s",
103 (bp
[24] & 0x01) ? "Sparse" : "Dense",
104 (bp
[25] & 0x80) ? " WC" : "",
105 (bp
[25] & 0x40) ? "RP" : "SPT");
110 (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp
));
112 (void)printf("\n Hold time: ");
113 relts_print(EXTRACT_16BITS(&bp
[6]));
123 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
124 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
125 (void)printf("/%s", ipaddr_string(&bp
[4]));
127 njoin
= EXTRACT_16BITS(&bp
[8]);
128 nprune
= EXTRACT_16BITS(&bp
[10]);
129 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
131 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
140 (void)printf("\n\t%s %s%s%s%s/%d", type
,
141 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
142 (bp
[1] & 0x80) ? "WC " : "",
143 (bp
[1] & 0x40) ? "RP " : "SPT ",
144 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
150 (void)printf("[|pim]");
155 pimv1_print(register const u_char
*bp
, register u_int len
)
157 register const u_char
*ep
;
158 register u_char type
;
160 ep
= (const u_char
*)snapend
;
168 (void)printf(" Query");
170 switch (bp
[8] >> 4) {
171 case 0: (void)printf(" Dense-mode");
173 case 1: (void)printf(" Sparse-mode");
175 case 2: (void)printf(" Sparse-Dense-mode");
177 default: (void)printf(" mode-%d", bp
[8] >> 4);
183 (void)printf(" (Hold-time ");
184 relts_print(EXTRACT_16BITS(&bp
[10]));
190 (void)printf(" Register");
191 TCHECK2(bp
[8], 20); /* ip header */
192 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
193 ipaddr_string(&bp
[24]));
197 (void)printf(" Register-Stop");
199 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
200 ipaddr_string(&bp
[12]));
204 (void)printf(" Join/Prune");
206 pimv1_join_prune_print(&bp
[8], len
- 8);
211 (void)printf(" RP-reachable");
214 (void)printf(" group %s",
215 ipaddr_string(&bp
[8]));
216 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
217 (void)printf("/%s", ipaddr_string(&bp
[12]));
218 (void)printf(" RP %s hold ",
219 ipaddr_string(&bp
[16]));
220 relts_print(EXTRACT_16BITS(&bp
[22]));
225 (void)printf(" Assert");
227 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
228 ipaddr_string(&bp
[8]));
229 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
230 (void)printf("/%s", ipaddr_string(&bp
[12]));
232 (void)printf(" %s pref %d metric %d",
233 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
234 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
235 EXTRACT_32BITS(&bp
[24]));
239 (void)printf(" Graft");
241 pimv1_join_prune_print(&bp
[8], len
- 8);
246 (void)printf(" Graft-ACK");
248 pimv1_join_prune_print(&bp
[8], len
- 8);
253 (void)printf(" Mode");
257 (void)printf(" [type %d]", type
);
260 if ((bp
[4] >> 4) != 1)
261 (void)printf(" [v%d]", bp
[4] >> 4);
265 (void)printf("[|pim]");
270 * auto-RP is a cisco protocol, documented at
271 * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt
274 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
281 (void)printf(" auto-rp ");
285 (void)printf("candidate-advert");
288 (void)printf("mapping");
291 (void)printf("type-0x%02x", type
);
299 (void)printf(" Hold ");
300 hold
= EXTRACT_16BITS(&bp
[2]);
302 relts_print(EXTRACT_16BITS(&bp
[2]));
306 /* Next 4 bytes are reserved. */
310 /*XXX skip unless -v? */
314 * numrps entries of the form:
317 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
318 * 8 bits: # of entries for this RP
319 * each entry: 7 bits: reserved, 1 bit: negative,
320 * 8 bits: mask 32 bits: source
321 * lather, rinse, repeat.
328 (void)printf(" RP %s", ipaddr_string(bp
));
330 switch(bp
[4] & 0x3) {
331 case 0: printf(" PIMv?");
333 case 1: printf(" PIMv1");
335 case 2: printf(" PIMv2");
337 case 3: printf(" PIMv1+2");
344 for (; nentries
; nentries
--) {
346 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
347 ipaddr_string(&bp
[2]), bp
[1]);
355 (void)printf("[|autorp]");
360 pim_print(register const u_char
*bp
, register u_int len
)
362 register const u_char
*ep
;
363 register struct pim
*pim
= (struct pim
*)bp
;
365 ep
= (const u_char
*)snapend
;
368 #ifdef notyet /* currently we see only version and type */
369 TCHECK(pim
->pim_rsv
);
372 switch(pim
->pim_ver
) {
373 case 2: /* avoid hardcoding? */
375 pimv2_print(bp
, len
);
378 (void)printf("v%d", pim
->pim_ver
);
385 * PIMv2 uses encoded address representations.
387 * The last PIM-SM I-D before RFC2117 was published specified the
388 * following representation for unicast addresses. However, RFC2117
389 * specified no encoding for unicast addresses with the unicast
390 * address length specified in the header. Therefore, we have to
391 * guess which encoding is being used (Cisco's PIMv2 implementation
392 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
393 * field into a 'unicast-address-length-in-bytes' field. We guess
394 * that it's the draft encoding if this reserved field is zero.
396 * RFC2362 goes back to the encoded format, and calls the addr length
397 * field "reserved" again.
399 * The first byte is the address family, from:
402 * 1 IP (IP version 4)
403 * 2 IP6 (IP version 6)
405 * 4 HDLC (8-bit multidrop)
407 * 6 802 (includes all 802 media plus Ethernet "canonical format")
409 * 8 E.164 (SMDS, Frame Relay, ATM)
411 * 10 X.121 (X.25, Frame Relay)
416 * 15 E.164 with NSAP format subaddress
418 * In addition, the second byte is an "Encoding". 0 is the default
419 * encoding for the address family, and no other encodings are currently
424 static int pimv2_addr_len
;
426 enum pimv2_addrtype
{
427 pimv2_unicast
, pimv2_group
, pimv2_source
430 static char *addrtypestr
[] = {
431 "unicast", "group", "source"
436 * 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
437 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438 * | Addr Family | Encoding Type | Unicast Address |
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
441 * 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
442 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 * | Addr Family | Encoding Type | Reserved | Mask Len |
444 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
445 * | Group multicast Address |
446 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448 * 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
449 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
451 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
453 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
456 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
464 if (pimv2_addr_len
== 0) {
486 switch (pimv2_addr_len
) {
501 len
= pimv2_addr_len
;
511 (void)printf("%s", ipaddr_string(bp
));
514 else if (af
== AF_INET6
) {
516 (void)printf("%s", ip6addr_string(bp
));
522 TCHECK2(bp
[0], len
+ 2);
525 (void)printf("%s", ipaddr_string(bp
+ 2));
527 (void)printf("/%u", bp
[1]);
531 else if (af
== AF_INET6
) {
533 (void)printf("%s", ip6addr_string(bp
+ 2));
535 (void)printf("/%u", bp
[1]);
539 if (bp
[0] && !silent
) {
540 if (at
== pimv2_group
) {
541 (void)printf("(0x%02x)", bp
[0]);
543 (void)printf("(%s%s%s",
544 bp
[0] & 0x04 ? "S" : "",
545 bp
[0] & 0x02 ? "W" : "",
546 bp
[0] & 0x01 ? "R" : "");
548 (void) printf("+0x%02x", bp
[0] & 0xf8);
553 return hdrlen
+ 2 + len
;
562 pimv2_print(register const u_char
*bp
, register u_int len
)
564 register const u_char
*ep
;
565 register struct pim
*pim
= (struct pim
*)bp
;
568 ep
= (const u_char
*)snapend
;
571 TCHECK(pim
->pim_rsv
);
572 pimv2_addr_len
= pim
->pim_rsv
;
573 if (pimv2_addr_len
!= 0)
574 (void)printf("[RFC2117-encoding] ");
576 switch (pim
->pim_type
) {
579 u_int16_t otype
, olen
;
580 (void)printf(" Hello");
584 otype
= EXTRACT_16BITS(&bp
[0]);
585 olen
= EXTRACT_16BITS(&bp
[2]);
586 TCHECK2(bp
[0], 4 + olen
);
588 case 1: /* Hold time */
589 (void)printf(" (Hold-time ");
590 relts_print(EXTRACT_16BITS(&bp
[4]));
595 * draft-ietf-idmr-pimv2-dr-priority-00.txt
596 * says that DR-Priority is option 19.
597 * draft-ietf-pim-v2-sm-00.txt says it's 18.
599 case 18: /* DR-Priority */
600 (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
603 case 19: /* Bidir-Capable */
605 (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
607 (void)printf(" (bidir-capable)");
611 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
615 (void)printf(" (State Refresh Capable");
616 if (EXTRACT_32BITS(&bp
[4]) != 1) {
617 (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp
[4]));
624 (void)printf(" [Hello option %d]", otype
);
635 (void)printf(" Register");
636 if (vflag
&& bp
+ 8 <= ep
) {
637 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
638 bp
[4] & 0x40 ? "N" : "");
642 /* encapsulated multicast packet */
645 ip
= (struct ip
*)bp
;
658 (void)printf(" IP ver %d", ip
->ip_v
);
665 (void)printf(" Register-Stop");
669 (void)printf(" group=");
670 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
674 bp
+= advance
; len
-= advance
;
677 (void)printf(" source=");
678 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
682 bp
+= advance
; len
-= advance
;
695 switch (pim
->pim_type
) {
697 (void)printf(" Join/Prune");
700 (void)printf(" Graft");
703 (void)printf(" Graft-ACK");
707 if (pim
->pim_type
!= 7) { /*not for Graft-ACK*/
710 (void)printf(" upstream-neighbor=");
711 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
715 bp
+= advance
; len
-= advance
;
720 holdtime
= EXTRACT_16BITS(&bp
[2]);
721 (void)printf(" groups=%u", ngroup
);
722 if (pim
->pim_type
!= 7) { /*not for Graft-ACK*/
723 (void)printf(" holdtime=");
724 if (holdtime
== 0xffff)
725 (void)printf("infty");
727 relts_print(holdtime
);
730 for (i
= 0; i
< ngroup
; i
++) {
733 (void)printf(" (group%d: ", i
);
734 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
735 (void)printf("...)");
738 bp
+= advance
; len
-= advance
;
740 (void)printf("...)");
743 njoin
= EXTRACT_16BITS(&bp
[0]);
744 nprune
= EXTRACT_16BITS(&bp
[2]);
745 (void)printf(" join=%u", njoin
);
747 for (j
= 0; j
< njoin
; j
++) {
749 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
750 (void)printf("...)");
753 bp
+= advance
; len
-= advance
;
755 (void)printf(" prune=%u", nprune
);
756 for (j
= 0; j
< nprune
; j
++) {
758 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
759 (void)printf("...)");
762 bp
+= advance
; len
-= advance
;
774 (void)printf(" Bootstrap");
777 /* Fragment Tag, Hash Mask len, and BSR-priority */
778 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
779 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
780 bp
+= sizeof(u_int16_t
);
782 (void)printf(" hashmlen=%d", bp
[0]);
783 if (bp
+ 1 >= ep
) break;
784 (void)printf(" BSRprio=%d", bp
[1]);
787 /* Encoded-Unicast-BSR-Address */
789 (void)printf(" BSR=");
790 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
796 for (i
= 0; bp
< ep
; i
++) {
797 /* Encoded-Group Address */
798 (void)printf(" (group%d: ", i
);
799 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
801 (void)printf("...)");
806 /* RP-Count, Frag RP-Cnt, and rsvd */
808 (void)printf("...)");
811 (void)printf(" RPcnt=%d", frpcnt
= bp
[0]);
813 (void)printf("...)");
816 (void)printf(" FRPcnt=%d", bp
[1]);
819 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
821 (void)printf(" RP%d=", j
);
822 if ((advance
= pimv2_addr_print(bp
,
825 (void)printf("...)");
831 (void)printf("...)");
834 (void)printf(",holdtime=");
835 relts_print(EXTRACT_16BITS(bp
));
837 (void)printf("...)");
840 (void)printf(",prio=%d", bp
[2]);
849 (void)printf(" Assert");
853 (void)printf(" group=");
854 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
858 bp
+= advance
; len
-= advance
;
861 (void)printf(" src=");
862 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
866 bp
+= advance
; len
-= advance
;
870 (void)printf(" RPT");
871 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
872 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
879 (void)printf(" Candidate-RP-Advertisement");
882 /* Prefix-Cnt, Priority, and Holdtime */
884 (void)printf(" prefix-cnt=%d", bp
[0]);
886 if (bp
+ 1 >= ep
) break;
887 (void)printf(" prio=%d", bp
[1]);
888 if (bp
+ 3 >= ep
) break;
889 (void)printf(" holdtime=");
890 relts_print(EXTRACT_16BITS(&bp
[2]));
893 /* Encoded-Unicast-RP-Address */
895 (void)printf(" RP=");
896 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
902 /* Encoded-Group Addresses */
903 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
904 (void)printf(" Group%d=", i
);
905 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
916 (void)printf(" Prune-Refresh");
917 (void)printf(" src=");
918 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
923 (void)printf(" grp=");
924 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
929 (void)printf(" forwarder=");
930 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
936 (void)printf(" TUNR ");
937 relts_print(EXTRACT_16BITS(bp
));
942 (void)printf(" [type %d]", pim
->pim_type
);
949 (void)printf("[|pim]");