]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
ec5d24e540daca312eefafca29e040708dafc137
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.16 2000-01-19 04:57:12 itojun 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...
52 /* upper 4bit: the PIM message type, currently they are:
53 * Hello, Register, Register-Stop, Join/Prune,
54 * Bootstrap, Assert, Graft (PIM-DM only),
55 * Graft-Ack (PIM-DM only), C-RP-Adv
57 /* lower 4bit: PIM version number; 2 for PIMv2 */
58 #define PIM_TYPE(x) (((x) & 0xf0) >> 4)
59 #define PIM_VER(x) ((x) & 0x0f)
60 u_char pim_rsv
; /* Reserved */
61 u_short pim_cksum
; /* IP style check sum */
69 #include "interface.h"
70 #include "addrtoname.h"
73 static void pimv2_print(register const u_char
*bp
, register u_int len
);
76 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
78 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
81 /* If it's a single group and a single source, use 1-line output. */
82 if (TTEST2(bp
[0], 30) && bp
[11] == 1 &&
83 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
86 (void)printf(" RPF %s ", ipaddr_string(bp
));
87 hold
= EXTRACT_16BITS(&bp
[6]);
89 (void)printf("Hold ");
92 (void)printf("%s (%s/%d, %s", njoin
? "Join" : "Prune",
93 ipaddr_string(&bp
[26]), bp
[25] & 0x3f,
94 ipaddr_string(&bp
[12]));
95 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
96 (void)printf("/%s", ipaddr_string(&bp
[16]));
97 (void)printf(") %s%s %s",
98 (bp
[24] & 0x01) ? "Sparse" : "Dense",
99 (bp
[25] & 0x80) ? " WC" : "",
100 (bp
[25] & 0x40) ? "RP" : "SPT");
105 (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp
));
107 (void)printf("\n Hold time: ");
108 relts_print(EXTRACT_16BITS(&bp
[6]));
118 (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
);
126 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);
145 (void)printf("[|pim]");
150 pimv1_print(register const u_char
*bp
, register u_int len
)
152 register const u_char
*ep
;
153 register u_char type
;
155 ep
= (const u_char
*)snapend
;
163 (void)printf(" Query");
165 switch (bp
[8] >> 4) {
166 case 0: (void)printf(" Dense-mode");
168 case 1: (void)printf(" Sparse-mode");
170 case 2: (void)printf(" Sparse-Dense-mode");
172 default: (void)printf(" mode-%d", bp
[8] >> 4);
178 (void)printf(" (Hold-time ");
179 relts_print(EXTRACT_16BITS(&bp
[10]));
185 (void)printf(" Register");
186 TCHECK2(bp
[8], 20); /* ip header */
187 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
188 ipaddr_string(&bp
[24]));
192 (void)printf(" Register-Stop");
194 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
195 ipaddr_string(&bp
[12]));
199 (void)printf(" Join/Prune");
201 pimv1_join_prune_print(&bp
[8], len
- 8);
206 (void)printf(" RP-reachable");
209 (void)printf(" group %s",
210 ipaddr_string(&bp
[8]));
211 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
212 (void)printf("/%s", ipaddr_string(&bp
[12]));
213 (void)printf(" RP %s hold ",
214 ipaddr_string(&bp
[16]));
215 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]));
234 (void)printf(" Graft");
236 pimv1_join_prune_print(&bp
[8], len
- 8);
241 (void)printf(" Graft-ACK");
243 pimv1_join_prune_print(&bp
[8], len
- 8);
248 (void)printf(" Mode");
252 (void)printf(" [type %d]", type
);
255 if ((bp
[4] >> 4) != 1)
256 (void)printf(" [v%d]", bp
[4] >> 4);
260 (void)printf("[|pim]");
265 * auto-RP is a cisco protocol, documented at
266 * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt
269 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
276 (void)printf(" auto-rp ");
280 (void)printf("candidate-advert");
283 (void)printf("mapping");
286 (void)printf("type-0x%02x", type
);
294 (void)printf(" Hold ");
295 hold
= EXTRACT_16BITS(&bp
[2]);
297 relts_print(EXTRACT_16BITS(&bp
[2]));
301 /* Next 4 bytes are reserved. */
305 /*XXX skip unless -v? */
309 * numrps entries of the form:
312 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
313 * 8 bits: # of entries for this RP
314 * each entry: 7 bits: reserved, 1 bit: negative,
315 * 8 bits: mask 32 bits: source
316 * lather, rinse, repeat.
323 (void)printf(" RP %s", ipaddr_string(bp
));
325 switch(bp
[4] & 0x3) {
326 case 0: printf(" PIMv?");
328 case 1: printf(" PIMv1");
330 case 2: printf(" PIMv2");
332 case 3: printf(" PIMv1+2");
339 for (; nentries
; nentries
--) {
341 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
342 ipaddr_string(&bp
[2]), bp
[1]);
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? */
370 pimv2_print(bp
, len
);
373 (void)printf("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
425 static char *addrtypestr
[] = {
426 "unicast", "group", "source"
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 | Unicast Address |
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
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 | Reserved | Mask Len |
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 * | Group multicast Address |
441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 * 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
444 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
445 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
446 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
451 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
459 if (pimv2_addr_len
== 0) {
481 switch (pimv2_addr_len
) {
496 len
= pimv2_addr_len
;
506 (void)printf("%s", ipaddr_string(bp
));
509 else if (af
== AF_INET6
) {
511 (void)printf("%s", ip6addr_string(bp
));
517 TCHECK2(bp
[0], len
+ 2);
520 (void)printf("%s", ipaddr_string(bp
+ 2));
522 (void)printf("/%u", bp
[1]);
526 else if (af
== AF_INET6
) {
528 (void)printf("%s", ip6addr_string(bp
+ 2));
530 (void)printf("/%u", bp
[1]);
534 if (bp
[0] && !silent
) {
535 if (at
== pimv2_group
) {
536 (void)printf("(0x%02x)", bp
[0]);
538 (void)printf("(%s%s%s",
539 bp
[0] & 0x04 ? "S" : "",
540 bp
[0] & 0x02 ? "W" : "",
541 bp
[0] & 0x01 ? "R" : "");
543 (void) printf("+0x%02x", bp
[0] & 0xf8);
548 return hdrlen
+ 2 + len
;
557 pimv2_print(register const u_char
*bp
, register u_int len
)
559 register const u_char
*ep
;
560 register struct pim
*pim
= (struct pim
*)bp
;
563 ep
= (const u_char
*)snapend
;
566 TCHECK(pim
->pim_rsv
);
567 pimv2_addr_len
= pim
->pim_rsv
;
568 if (pimv2_addr_len
!= 0)
569 (void)printf("[RFC2117-encoding] ");
571 switch (PIM_TYPE(pim
->pim_typever
)) {
574 u_int16_t otype
, olen
;
575 (void)printf(" Hello");
579 otype
= EXTRACT_16BITS(&bp
[0]);
580 olen
= EXTRACT_16BITS(&bp
[2]);
581 TCHECK2(bp
[0], 4 + olen
);
583 case 1: /* Hold time */
584 (void)printf(" (Hold-time ");
585 relts_print(EXTRACT_16BITS(&bp
[4]));
590 * draft-ietf-idmr-pimv2-dr-priority-00.txt
591 * says that DR-Priority is option 19.
592 * draft-ietf-pim-v2-sm-00.txt says it's 18.
594 case 18: /* DR-Priority */
595 (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
598 case 19: /* Bidir-Capable */
600 (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
602 (void)printf(" (bidir-capable)");
606 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
610 (void)printf(" (State Refresh Capable");
611 if (EXTRACT_32BITS(&bp
[4]) != 1) {
612 (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp
[4]));
619 (void)printf(" [Hello option %d]", otype
);
630 (void)printf(" Register");
631 if (vflag
&& bp
+ 8 <= ep
) {
632 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
633 bp
[4] & 0x40 ? "N" : "");
637 /* encapsulated multicast packet */
640 ip
= (struct ip
*)bp
;
653 (void)printf(" IP ver %d", ip
->ip_v
);
660 (void)printf(" Register-Stop");
664 (void)printf(" group=");
665 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
669 bp
+= advance
; len
-= advance
;
672 (void)printf(" source=");
673 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
677 bp
+= advance
; len
-= advance
;
690 switch (PIM_TYPE(pim
->pim_typever
)) {
692 (void)printf(" Join/Prune");
695 (void)printf(" Graft");
698 (void)printf(" Graft-ACK");
702 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
705 (void)printf(" upstream-neighbor=");
706 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
710 bp
+= advance
; len
-= advance
;
715 holdtime
= EXTRACT_16BITS(&bp
[2]);
716 (void)printf(" groups=%u", ngroup
);
717 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
718 (void)printf(" holdtime=");
719 if (holdtime
== 0xffff)
720 (void)printf("infty");
722 relts_print(holdtime
);
725 for (i
= 0; i
< ngroup
; i
++) {
728 (void)printf(" (group%d: ", i
);
729 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
730 (void)printf("...)");
733 bp
+= advance
; len
-= advance
;
735 (void)printf("...)");
738 njoin
= EXTRACT_16BITS(&bp
[0]);
739 nprune
= EXTRACT_16BITS(&bp
[2]);
740 (void)printf(" join=%u", njoin
);
742 for (j
= 0; j
< njoin
; j
++) {
744 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
745 (void)printf("...)");
748 bp
+= advance
; len
-= advance
;
750 (void)printf(" prune=%u", nprune
);
751 for (j
= 0; j
< nprune
; j
++) {
753 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
754 (void)printf("...)");
757 bp
+= advance
; len
-= advance
;
769 (void)printf(" Bootstrap");
772 /* Fragment Tag, Hash Mask len, and BSR-priority */
773 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
774 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
775 bp
+= sizeof(u_int16_t
);
777 (void)printf(" hashmlen=%d", bp
[0]);
778 if (bp
+ 1 >= ep
) break;
779 (void)printf(" BSRprio=%d", bp
[1]);
782 /* Encoded-Unicast-BSR-Address */
784 (void)printf(" BSR=");
785 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
791 for (i
= 0; bp
< ep
; i
++) {
792 /* Encoded-Group Address */
793 (void)printf(" (group%d: ", i
);
794 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
796 (void)printf("...)");
801 /* RP-Count, Frag RP-Cnt, and rsvd */
803 (void)printf("...)");
806 (void)printf(" RPcnt=%d", frpcnt
= bp
[0]);
808 (void)printf("...)");
811 (void)printf(" FRPcnt=%d", bp
[1]);
814 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
816 (void)printf(" RP%d=", j
);
817 if ((advance
= pimv2_addr_print(bp
,
820 (void)printf("...)");
826 (void)printf("...)");
829 (void)printf(",holdtime=");
830 relts_print(EXTRACT_16BITS(bp
));
832 (void)printf("...)");
835 (void)printf(",prio=%d", bp
[2]);
844 (void)printf(" Assert");
848 (void)printf(" group=");
849 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
853 bp
+= advance
; len
-= advance
;
856 (void)printf(" src=");
857 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
861 bp
+= advance
; len
-= advance
;
865 (void)printf(" RPT");
866 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
867 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
874 (void)printf(" Candidate-RP-Advertisement");
877 /* Prefix-Cnt, Priority, and Holdtime */
879 (void)printf(" prefix-cnt=%d", bp
[0]);
881 if (bp
+ 1 >= ep
) break;
882 (void)printf(" prio=%d", bp
[1]);
883 if (bp
+ 3 >= ep
) break;
884 (void)printf(" holdtime=");
885 relts_print(EXTRACT_16BITS(&bp
[2]));
888 /* Encoded-Unicast-RP-Address */
890 (void)printf(" RP=");
891 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
897 /* Encoded-Group Addresses */
898 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
899 (void)printf(" Group%d=", i
);
900 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
911 (void)printf(" Prune-Refresh");
912 (void)printf(" src=");
913 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
918 (void)printf(" grp=");
919 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
924 (void)printf(" forwarder=");
925 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
931 (void)printf(" TUNR ");
932 relts_print(EXTRACT_16BITS(bp
));
937 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
944 (void)printf("[|pim]");