]>
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.19 2000-04-24 12:59:39 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>
40 * XXX: We consider a case where IPv6 is not ready yet for portability,
41 * but PIM dependent defintions should be independent of IPv6...
46 /* upper 4bit: PIM version number; 2 for PIMv2 */
47 /* lower 4bit: the PIM message type, currently they are:
48 * Hello, Register, Register-Stop, Join/Prune,
49 * Bootstrap, Assert, Graft (PIM-DM only),
50 * Graft-Ack (PIM-DM only), C-RP-Adv
52 #define PIM_VER(x) (((x) & 0xf0) >> 4)
53 #define PIM_TYPE(x) ((x) & 0x0f)
54 u_char pim_rsv
; /* Reserved */
55 u_short pim_cksum
; /* IP style check sum */
63 #include "interface.h"
64 #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");
99 (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp
));
101 (void)printf("\n Hold time: ");
102 relts_print(EXTRACT_16BITS(&bp
[6]));
112 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
113 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
114 (void)printf("/%s", ipaddr_string(&bp
[4]));
116 njoin
= EXTRACT_16BITS(&bp
[8]);
117 nprune
= EXTRACT_16BITS(&bp
[10]);
118 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
120 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
129 (void)printf("\n\t%s %s%s%s%s/%d", type
,
130 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
131 (bp
[1] & 0x80) ? "WC " : "",
132 (bp
[1] & 0x40) ? "RP " : "SPT ",
133 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
139 (void)printf("[|pim]");
144 pimv1_print(register const u_char
*bp
, register u_int len
)
146 register const u_char
*ep
;
147 register u_char type
;
149 ep
= (const u_char
*)snapend
;
157 (void)printf(" Query");
159 switch (bp
[8] >> 4) {
160 case 0: (void)printf(" Dense-mode");
162 case 1: (void)printf(" Sparse-mode");
164 case 2: (void)printf(" Sparse-Dense-mode");
166 default: (void)printf(" mode-%d", bp
[8] >> 4);
172 (void)printf(" (Hold-time ");
173 relts_print(EXTRACT_16BITS(&bp
[10]));
179 (void)printf(" Register");
180 TCHECK2(bp
[8], 20); /* ip header */
181 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
182 ipaddr_string(&bp
[24]));
186 (void)printf(" Register-Stop");
188 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
189 ipaddr_string(&bp
[12]));
193 (void)printf(" Join/Prune");
195 pimv1_join_prune_print(&bp
[8], len
- 8);
200 (void)printf(" RP-reachable");
203 (void)printf(" group %s",
204 ipaddr_string(&bp
[8]));
205 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
206 (void)printf("/%s", ipaddr_string(&bp
[12]));
207 (void)printf(" RP %s hold ",
208 ipaddr_string(&bp
[16]));
209 relts_print(EXTRACT_16BITS(&bp
[22]));
214 (void)printf(" Assert");
216 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
217 ipaddr_string(&bp
[8]));
218 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
219 (void)printf("/%s", ipaddr_string(&bp
[12]));
221 (void)printf(" %s pref %d metric %d",
222 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
223 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
224 EXTRACT_32BITS(&bp
[24]));
228 (void)printf(" Graft");
230 pimv1_join_prune_print(&bp
[8], len
- 8);
235 (void)printf(" Graft-ACK");
237 pimv1_join_prune_print(&bp
[8], len
- 8);
242 (void)printf(" Mode");
246 (void)printf(" [type %d]", type
);
249 if ((bp
[4] >> 4) != 1)
250 (void)printf(" [v%d]", bp
[4] >> 4);
254 (void)printf("[|pim]");
259 * auto-RP is a cisco protocol, documented at
260 * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt
263 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
270 (void)printf(" auto-rp ");
274 (void)printf("candidate-advert");
277 (void)printf("mapping");
280 (void)printf("type-0x%02x", type
);
288 (void)printf(" Hold ");
289 hold
= EXTRACT_16BITS(&bp
[2]);
291 relts_print(EXTRACT_16BITS(&bp
[2]));
295 /* Next 4 bytes are reserved. */
299 /*XXX skip unless -v? */
303 * numrps entries of the form:
306 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
307 * 8 bits: # of entries for this RP
308 * each entry: 7 bits: reserved, 1 bit: negative,
309 * 8 bits: mask 32 bits: source
310 * lather, rinse, repeat.
317 (void)printf(" RP %s", ipaddr_string(bp
));
319 switch (bp
[4] & 0x3) {
320 case 0: printf(" PIMv?");
322 case 1: printf(" PIMv1");
324 case 2: printf(" PIMv2");
326 case 3: printf(" PIMv1+2");
333 for (; nentries
; nentries
--) {
335 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
336 ipaddr_string(&bp
[2]), bp
[1]);
344 (void)printf("[|autorp]");
349 pim_print(register const u_char
*bp
, register u_int len
)
351 register const u_char
*ep
;
352 register struct pim
*pim
= (struct pim
*)bp
;
354 ep
= (const u_char
*)snapend
;
357 #ifdef notyet /* currently we see only version and type */
358 TCHECK(pim
->pim_rsv
);
361 switch (PIM_VER(pim
->pim_typever
)) {
362 case 2: /* avoid hardcoding? */
363 (void)printf("pim v2");
364 pimv2_print(bp
, len
);
367 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
374 * PIMv2 uses encoded address representations.
376 * The last PIM-SM I-D before RFC2117 was published specified the
377 * following representation for unicast addresses. However, RFC2117
378 * specified no encoding for unicast addresses with the unicast
379 * address length specified in the header. Therefore, we have to
380 * guess which encoding is being used (Cisco's PIMv2 implementation
381 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
382 * field into a 'unicast-address-length-in-bytes' field. We guess
383 * that it's the draft encoding if this reserved field is zero.
385 * RFC2362 goes back to the encoded format, and calls the addr length
386 * field "reserved" again.
388 * The first byte is the address family, from:
391 * 1 IP (IP version 4)
392 * 2 IP6 (IP version 6)
394 * 4 HDLC (8-bit multidrop)
396 * 6 802 (includes all 802 media plus Ethernet "canonical format")
398 * 8 E.164 (SMDS, Frame Relay, ATM)
400 * 10 X.121 (X.25, Frame Relay)
405 * 15 E.164 with NSAP format subaddress
407 * In addition, the second byte is an "Encoding". 0 is the default
408 * encoding for the address family, and no other encodings are currently
413 static int pimv2_addr_len
;
415 enum pimv2_addrtype
{
416 pimv2_unicast
, pimv2_group
, pimv2_source
419 static char *addrtypestr
[] = {
420 "unicast", "group", "source"
425 * 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
426 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
427 * | Addr Family | Encoding Type | Unicast Address |
428 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
430 * 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
431 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
432 * | Addr Family | Encoding Type | Reserved | Mask Len |
433 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
434 * | Group multicast Address |
435 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * 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
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
440 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
442 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
445 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
453 if (pimv2_addr_len
== 0) {
475 switch (pimv2_addr_len
) {
490 len
= pimv2_addr_len
;
500 (void)printf("%s", ipaddr_string(bp
));
503 else if (af
== AF_INET6
) {
505 (void)printf("%s", ip6addr_string(bp
));
511 TCHECK2(bp
[0], len
+ 2);
514 (void)printf("%s", ipaddr_string(bp
+ 2));
516 (void)printf("/%u", bp
[1]);
520 else if (af
== AF_INET6
) {
522 (void)printf("%s", ip6addr_string(bp
+ 2));
524 (void)printf("/%u", bp
[1]);
528 if (bp
[0] && !silent
) {
529 if (at
== pimv2_group
) {
530 (void)printf("(0x%02x)", bp
[0]);
532 (void)printf("(%s%s%s",
533 bp
[0] & 0x04 ? "S" : "",
534 bp
[0] & 0x02 ? "W" : "",
535 bp
[0] & 0x01 ? "R" : "");
537 (void) printf("+0x%02x", bp
[0] & 0xf8);
542 return hdrlen
+ 2 + len
;
551 pimv2_print(register const u_char
*bp
, register u_int len
)
553 register const u_char
*ep
;
554 register struct pim
*pim
= (struct pim
*)bp
;
557 ep
= (const u_char
*)snapend
;
562 TCHECK(pim
->pim_rsv
);
563 pimv2_addr_len
= pim
->pim_rsv
;
564 if (pimv2_addr_len
!= 0)
565 (void)printf("[RFC2117-encoding] ");
567 switch (PIM_TYPE(pim
->pim_typever
)) {
570 u_int16_t otype
, olen
;
571 (void)printf(" Hello");
575 otype
= EXTRACT_16BITS(&bp
[0]);
576 olen
= EXTRACT_16BITS(&bp
[2]);
577 TCHECK2(bp
[0], 4 + olen
);
579 case 1: /* Hold time */
580 (void)printf(" (Hold-time ");
581 relts_print(EXTRACT_16BITS(&bp
[4]));
586 * draft-ietf-idmr-pimv2-dr-priority-00.txt
587 * says that DR-Priority is option 19.
588 * draft-ietf-pim-v2-sm-00.txt says it's 18.
590 case 18: /* DR-Priority */
591 (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
594 case 19: /* Bidir-Capable */
596 (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
598 (void)printf(" (bidir-capable)");
602 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
606 (void)printf(" (State Refresh Capable");
607 if (EXTRACT_32BITS(&bp
[4]) != 1) {
608 (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp
[4]));
615 (void)printf(" [Hello option %d]", otype
);
626 (void)printf(" Register");
627 if (vflag
&& bp
+ 8 <= ep
) {
628 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
629 bp
[4] & 0x40 ? "N" : "");
633 /* encapsulated multicast packet */
636 ip
= (struct ip
*)bp
;
649 (void)printf(" IP ver %d", ip
->ip_v
);
656 (void)printf(" Register-Stop");
660 (void)printf(" group=");
661 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
665 bp
+= advance
; len
-= advance
;
668 (void)printf(" source=");
669 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
673 bp
+= advance
; len
-= advance
;
686 switch (PIM_TYPE(pim
->pim_typever
)) {
688 (void)printf(" Join/Prune");
691 (void)printf(" Graft");
694 (void)printf(" Graft-ACK");
698 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
701 (void)printf(" upstream-neighbor=");
702 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
706 bp
+= advance
; len
-= advance
;
711 holdtime
= EXTRACT_16BITS(&bp
[2]);
712 (void)printf(" groups=%u", ngroup
);
713 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
714 (void)printf(" holdtime=");
715 if (holdtime
== 0xffff)
716 (void)printf("infty");
718 relts_print(holdtime
);
721 for (i
= 0; i
< ngroup
; i
++) {
724 (void)printf(" (group%d: ", i
);
725 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
726 (void)printf("...)");
729 bp
+= advance
; len
-= advance
;
731 (void)printf("...)");
734 njoin
= EXTRACT_16BITS(&bp
[0]);
735 nprune
= EXTRACT_16BITS(&bp
[2]);
736 (void)printf(" join=%u", njoin
);
738 for (j
= 0; j
< njoin
; j
++) {
740 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
741 (void)printf("...)");
744 bp
+= advance
; len
-= advance
;
746 (void)printf(" prune=%u", nprune
);
747 for (j
= 0; j
< nprune
; j
++) {
749 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
750 (void)printf("...)");
753 bp
+= advance
; len
-= advance
;
765 (void)printf(" Bootstrap");
768 /* Fragment Tag, Hash Mask len, and BSR-priority */
769 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
770 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
771 bp
+= sizeof(u_int16_t
);
773 (void)printf(" hashmlen=%d", bp
[0]);
774 if (bp
+ 1 >= ep
) break;
775 (void)printf(" BSRprio=%d", bp
[1]);
778 /* Encoded-Unicast-BSR-Address */
780 (void)printf(" BSR=");
781 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
787 for (i
= 0; bp
< ep
; i
++) {
788 /* Encoded-Group Address */
789 (void)printf(" (group%d: ", i
);
790 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
792 (void)printf("...)");
797 /* RP-Count, Frag RP-Cnt, and rsvd */
799 (void)printf("...)");
802 (void)printf(" RPcnt=%d", frpcnt
= bp
[0]);
804 (void)printf("...)");
807 (void)printf(" FRPcnt=%d", bp
[1]);
810 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
812 (void)printf(" RP%d=", j
);
813 if ((advance
= pimv2_addr_print(bp
,
816 (void)printf("...)");
822 (void)printf("...)");
825 (void)printf(",holdtime=");
826 relts_print(EXTRACT_16BITS(bp
));
828 (void)printf("...)");
831 (void)printf(",prio=%d", bp
[2]);
840 (void)printf(" Assert");
844 (void)printf(" group=");
845 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
849 bp
+= advance
; len
-= advance
;
852 (void)printf(" src=");
853 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
857 bp
+= advance
; len
-= advance
;
861 (void)printf(" RPT");
862 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
863 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
870 (void)printf(" Candidate-RP-Advertisement");
873 /* Prefix-Cnt, Priority, and Holdtime */
875 (void)printf(" prefix-cnt=%d", bp
[0]);
877 if (bp
+ 1 >= ep
) break;
878 (void)printf(" prio=%d", bp
[1]);
879 if (bp
+ 3 >= ep
) break;
880 (void)printf(" holdtime=");
881 relts_print(EXTRACT_16BITS(&bp
[2]));
884 /* Encoded-Unicast-RP-Address */
886 (void)printf(" RP=");
887 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
893 /* Encoded-Group Addresses */
894 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
895 (void)printf(" Group%d=", i
);
896 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
907 (void)printf(" Prune-Refresh");
908 (void)printf(" src=");
909 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
914 (void)printf(" grp=");
915 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
920 (void)printf(" forwarder=");
921 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
927 (void)printf(" TUNR ");
928 relts_print(EXTRACT_16BITS(bp
));
933 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
940 (void)printf("[|pim]");