]>
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.21 2000-09-23 08:54:37 guy Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <netinet/in_systm.h>
39 * XXX: We consider a case where IPv6 is not ready yet for portability,
40 * but PIM dependent defintions should be independent of IPv6...
45 /* upper 4bit: PIM version number; 2 for PIMv2 */
46 /* lower 4bit: the PIM message type, currently they are:
47 * Hello, Register, Register-Stop, Join/Prune,
48 * Bootstrap, Assert, Graft (PIM-DM only),
49 * Graft-Ack (PIM-DM only), C-RP-Adv
51 #define PIM_VER(x) (((x) & 0xf0) >> 4)
52 #define PIM_TYPE(x) ((x) & 0x0f)
53 u_char pim_rsv
; /* Reserved */
54 u_short pim_cksum
; /* IP style check sum */
62 #include "interface.h"
63 #include "addrtoname.h"
68 static void pimv2_print(register const u_char
*bp
, register u_int len
);
71 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
73 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
76 /* If it's a single group and a single source, use 1-line output. */
77 if (TTEST2(bp
[0], 30) && bp
[11] == 1 &&
78 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
81 (void)printf(" RPF %s ", ipaddr_string(bp
));
82 hold
= EXTRACT_16BITS(&bp
[6]);
84 (void)printf("Hold ");
87 (void)printf("%s (%s/%d, %s", njoin
? "Join" : "Prune",
88 ipaddr_string(&bp
[26]), bp
[25] & 0x3f,
89 ipaddr_string(&bp
[12]));
90 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
91 (void)printf("/%s", ipaddr_string(&bp
[16]));
92 (void)printf(") %s%s %s",
93 (bp
[24] & 0x01) ? "Sparse" : "Dense",
94 (bp
[25] & 0x80) ? " WC" : "",
95 (bp
[25] & 0x40) ? "RP" : "SPT");
100 (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp
));
102 (void)printf("\n Hold time: ");
103 relts_print(EXTRACT_16BITS(&bp
[6]));
113 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
114 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
115 (void)printf("/%s", ipaddr_string(&bp
[4]));
117 njoin
= EXTRACT_16BITS(&bp
[8]);
118 nprune
= EXTRACT_16BITS(&bp
[10]);
119 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
121 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
130 (void)printf("\n\t%s %s%s%s%s/%d", type
,
131 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
132 (bp
[1] & 0x80) ? "WC " : "",
133 (bp
[1] & 0x40) ? "RP " : "SPT ",
134 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
140 (void)printf("[|pim]");
145 pimv1_print(register const u_char
*bp
, register u_int len
)
147 register const u_char
*ep
;
148 register u_char type
;
150 ep
= (const u_char
*)snapend
;
158 (void)printf(" Query");
160 switch (bp
[8] >> 4) {
161 case 0: (void)printf(" Dense-mode");
163 case 1: (void)printf(" Sparse-mode");
165 case 2: (void)printf(" Sparse-Dense-mode");
167 default: (void)printf(" mode-%d", bp
[8] >> 4);
173 (void)printf(" (Hold-time ");
174 relts_print(EXTRACT_16BITS(&bp
[10]));
180 (void)printf(" Register");
181 TCHECK2(bp
[8], 20); /* ip header */
182 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
183 ipaddr_string(&bp
[24]));
187 (void)printf(" Register-Stop");
189 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
190 ipaddr_string(&bp
[12]));
194 (void)printf(" Join/Prune");
196 pimv1_join_prune_print(&bp
[8], len
- 8);
201 (void)printf(" RP-reachable");
204 (void)printf(" group %s",
205 ipaddr_string(&bp
[8]));
206 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
207 (void)printf("/%s", ipaddr_string(&bp
[12]));
208 (void)printf(" RP %s hold ",
209 ipaddr_string(&bp
[16]));
210 relts_print(EXTRACT_16BITS(&bp
[22]));
215 (void)printf(" Assert");
217 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
218 ipaddr_string(&bp
[8]));
219 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
220 (void)printf("/%s", ipaddr_string(&bp
[12]));
222 (void)printf(" %s pref %d metric %d",
223 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
224 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
225 EXTRACT_32BITS(&bp
[24]));
229 (void)printf(" Graft");
231 pimv1_join_prune_print(&bp
[8], len
- 8);
236 (void)printf(" Graft-ACK");
238 pimv1_join_prune_print(&bp
[8], len
- 8);
243 (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
420 static char *addrtypestr
[] = {
421 "unicast", "group", "source"
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 | Unicast Address |
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
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 | Reserved | Mask Len |
434 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * | Group multicast Address |
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438 * 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
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
446 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
454 if (pimv2_addr_len
== 0) {
476 switch (pimv2_addr_len
) {
491 len
= pimv2_addr_len
;
501 (void)printf("%s", ipaddr_string(bp
));
504 else if (af
== AF_INET6
) {
506 (void)printf("%s", ip6addr_string(bp
));
512 TCHECK2(bp
[0], len
+ 2);
515 (void)printf("%s", ipaddr_string(bp
+ 2));
517 (void)printf("/%u", bp
[1]);
521 else if (af
== AF_INET6
) {
523 (void)printf("%s", ip6addr_string(bp
+ 2));
525 (void)printf("/%u", bp
[1]);
529 if (bp
[0] && !silent
) {
530 if (at
== pimv2_group
) {
531 (void)printf("(0x%02x)", bp
[0]);
533 (void)printf("(%s%s%s",
534 bp
[0] & 0x04 ? "S" : "",
535 bp
[0] & 0x02 ? "W" : "",
536 bp
[0] & 0x01 ? "R" : "");
538 (void) printf("+0x%02x", bp
[0] & 0xf8);
543 return hdrlen
+ 2 + len
;
552 pimv2_print(register const u_char
*bp
, register u_int len
)
554 register const u_char
*ep
;
555 register struct pim
*pim
= (struct pim
*)bp
;
558 ep
= (const u_char
*)snapend
;
563 TCHECK(pim
->pim_rsv
);
564 pimv2_addr_len
= pim
->pim_rsv
;
565 if (pimv2_addr_len
!= 0)
566 (void)printf("[RFC2117-encoding] ");
568 switch (PIM_TYPE(pim
->pim_typever
)) {
571 u_int16_t otype
, olen
;
572 (void)printf(" Hello");
576 otype
= EXTRACT_16BITS(&bp
[0]);
577 olen
= EXTRACT_16BITS(&bp
[2]);
578 TCHECK2(bp
[0], 4 + olen
);
580 case 1: /* Hold time */
581 (void)printf(" (Hold-time ");
582 relts_print(EXTRACT_16BITS(&bp
[4]));
587 * draft-ietf-idmr-pimv2-dr-priority-00.txt
588 * says that DR-Priority is option 19.
589 * draft-ietf-pim-v2-sm-00.txt says it's 18.
591 case 18: /* DR-Priority */
592 (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
595 case 19: /* Bidir-Capable */
597 (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
599 (void)printf(" (bidir-capable)");
603 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
607 (void)printf(" (State Refresh Capable");
608 if (EXTRACT_32BITS(&bp
[4]) != 1) {
609 (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp
[4]));
616 (void)printf(" [Hello option %d]", otype
);
627 (void)printf(" Register");
628 if (vflag
&& bp
+ 8 <= ep
) {
629 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
630 bp
[4] & 0x40 ? "N" : "");
634 /* encapsulated multicast packet */
637 ip
= (struct ip
*)bp
;
650 (void)printf(" IP ver %d", ip
->ip_v
);
657 (void)printf(" Register-Stop");
661 (void)printf(" group=");
662 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
666 bp
+= advance
; len
-= advance
;
669 (void)printf(" source=");
670 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
674 bp
+= advance
; len
-= advance
;
687 switch (PIM_TYPE(pim
->pim_typever
)) {
689 (void)printf(" Join/Prune");
692 (void)printf(" Graft");
695 (void)printf(" Graft-ACK");
699 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
702 (void)printf(" upstream-neighbor=");
703 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
707 bp
+= advance
; len
-= advance
;
712 holdtime
= EXTRACT_16BITS(&bp
[2]);
713 (void)printf(" groups=%u", ngroup
);
714 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
715 (void)printf(" holdtime=");
716 if (holdtime
== 0xffff)
717 (void)printf("infty");
719 relts_print(holdtime
);
722 for (i
= 0; i
< ngroup
; i
++) {
725 (void)printf(" (group%d: ", i
);
726 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
727 (void)printf("...)");
730 bp
+= advance
; len
-= advance
;
732 (void)printf("...)");
735 njoin
= EXTRACT_16BITS(&bp
[0]);
736 nprune
= EXTRACT_16BITS(&bp
[2]);
737 (void)printf(" join=%u", njoin
);
739 for (j
= 0; j
< njoin
; j
++) {
741 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
742 (void)printf("...)");
745 bp
+= advance
; len
-= advance
;
747 (void)printf(" prune=%u", nprune
);
748 for (j
= 0; j
< nprune
; j
++) {
750 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
751 (void)printf("...)");
754 bp
+= advance
; len
-= advance
;
766 (void)printf(" Bootstrap");
769 /* Fragment Tag, Hash Mask len, and BSR-priority */
770 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
771 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
772 bp
+= sizeof(u_int16_t
);
774 (void)printf(" hashmlen=%d", bp
[0]);
775 if (bp
+ 1 >= ep
) break;
776 (void)printf(" BSRprio=%d", bp
[1]);
779 /* Encoded-Unicast-BSR-Address */
781 (void)printf(" BSR=");
782 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
788 for (i
= 0; bp
< ep
; i
++) {
789 /* Encoded-Group Address */
790 (void)printf(" (group%d: ", i
);
791 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
793 (void)printf("...)");
798 /* RP-Count, Frag RP-Cnt, and rsvd */
800 (void)printf("...)");
803 (void)printf(" RPcnt=%d", bp
[0]);
805 (void)printf("...)");
808 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
811 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
813 (void)printf(" RP%d=", j
);
814 if ((advance
= pimv2_addr_print(bp
,
817 (void)printf("...)");
823 (void)printf("...)");
826 (void)printf(",holdtime=");
827 relts_print(EXTRACT_16BITS(bp
));
829 (void)printf("...)");
832 (void)printf(",prio=%d", bp
[2]);
841 (void)printf(" Assert");
845 (void)printf(" group=");
846 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
850 bp
+= advance
; len
-= advance
;
853 (void)printf(" src=");
854 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
858 bp
+= advance
; len
-= advance
;
862 (void)printf(" RPT");
863 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
864 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
871 (void)printf(" Candidate-RP-Advertisement");
874 /* Prefix-Cnt, Priority, and Holdtime */
876 (void)printf(" prefix-cnt=%d", bp
[0]);
878 if (bp
+ 1 >= ep
) break;
879 (void)printf(" prio=%d", bp
[1]);
880 if (bp
+ 3 >= ep
) break;
881 (void)printf(" holdtime=");
882 relts_print(EXTRACT_16BITS(&bp
[2]));
885 /* Encoded-Unicast-RP-Address */
887 (void)printf(" RP=");
888 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
894 /* Encoded-Group Addresses */
895 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
896 (void)printf(" Group%d=", i
);
897 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
908 (void)printf(" Prune-Refresh");
909 (void)printf(" src=");
910 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
915 (void)printf(" grp=");
916 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
921 (void)printf(" forwarder=");
922 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
928 (void)printf(" TUNR ");
929 relts_print(EXTRACT_16BITS(bp
));
934 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
941 (void)printf("[|pim]");