]>
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
[] _U_
=
24 "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.37.2.4 2004-03-24 02:52:37 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
34 * XXX: We consider a case where IPv6 is not ready yet for portability,
35 * but PIM dependent defintions should be independent of IPv6...
40 /* upper 4bit: PIM version number; 2 for PIMv2 */
41 /* lower 4bit: the PIM message type, currently they are:
42 * Hello, Register, Register-Stop, Join/Prune,
43 * Bootstrap, Assert, Graft (PIM-DM only),
44 * Graft-Ack (PIM-DM only), C-RP-Adv
46 #define PIM_VER(x) (((x) & 0xf0) >> 4)
47 #define PIM_TYPE(x) ((x) & 0x0f)
48 u_char pim_rsv
; /* Reserved */
49 u_short pim_cksum
; /* IP style check sum */
56 #include "interface.h"
57 #include "addrtoname.h"
62 static void pimv2_print(register const u_char
*bp
, register u_int len
);
65 pimv1_join_prune_print(register const u_char
*bp
, register u_int len
)
67 int maddrlen
, addrlen
, ngroups
, njoin
, nprune
;
70 /* If it's a single group and a single source, use 1-line output. */
71 if (TTEST2(bp
[0], 30) && bp
[11] == 1 &&
72 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
75 (void)printf(" RPF %s ", ipaddr_string(bp
));
76 hold
= EXTRACT_16BITS(&bp
[6]);
78 (void)printf("Hold ");
81 (void)printf("%s (%s/%d, %s", njoin
? "Join" : "Prune",
82 ipaddr_string(&bp
[26]), bp
[25] & 0x3f,
83 ipaddr_string(&bp
[12]));
84 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
85 (void)printf("/%s", ipaddr_string(&bp
[16]));
86 (void)printf(") %s%s %s",
87 (bp
[24] & 0x01) ? "Sparse" : "Dense",
88 (bp
[25] & 0x80) ? " WC" : "",
89 (bp
[25] & 0x40) ? "RP" : "SPT");
96 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp
));
100 (void)printf(" Hold time: ");
101 relts_print(EXTRACT_16BITS(&bp
[6]));
115 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
117 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
118 (void)printf("/%s", ipaddr_string(&bp
[4]));
120 njoin
= EXTRACT_16BITS(&bp
[8]);
121 nprune
= EXTRACT_16BITS(&bp
[10]);
122 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
125 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
133 (void)printf("\n\t%s %s%s%s%s/%d", type
,
134 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
135 (bp
[1] & 0x80) ? "WC " : "",
136 (bp
[1] & 0x40) ? "RP " : "SPT ",
137 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
144 (void)printf("[|pim]");
149 pimv1_print(register const u_char
*bp
, register u_int len
)
151 register const u_char
*ep
;
152 register u_char type
;
154 ep
= (const u_char
*)snapend
;
163 (void)printf(" Query");
165 switch (bp
[8] >> 4) {
167 (void)printf(" Dense-mode");
170 (void)printf(" Sparse-mode");
173 (void)printf(" Sparse-Dense-mode");
176 (void)printf(" mode-%d", bp
[8] >> 4);
182 (void)printf(" (Hold-time ");
183 relts_print(EXTRACT_16BITS(&bp
[10]));
189 (void)printf(" Register");
190 TCHECK2(bp
[8], 20); /* ip header */
191 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
192 ipaddr_string(&bp
[24]));
195 (void)printf(" Register-Stop");
197 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
198 ipaddr_string(&bp
[12]));
201 (void)printf(" Join/Prune");
203 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 ", ipaddr_string(&bp
[16]));
214 relts_print(EXTRACT_16BITS(&bp
[22]));
218 (void)printf(" Assert");
220 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
221 ipaddr_string(&bp
[8]));
222 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
223 (void)printf("/%s", ipaddr_string(&bp
[12]));
225 (void)printf(" %s pref %d metric %d",
226 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
227 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
228 EXTRACT_32BITS(&bp
[24]));
231 (void)printf(" Graft");
233 pimv1_join_prune_print(&bp
[8], len
- 8);
236 (void)printf(" Graft-ACK");
238 pimv1_join_prune_print(&bp
[8], len
- 8);
241 (void)printf(" Mode");
244 (void)printf(" [type %d]", type
);
247 if ((bp
[4] >> 4) != 1)
248 (void)printf(" [v%d]", bp
[4] >> 4);
252 (void)printf("[|pim]");
257 * auto-RP is a cisco protocol, documented at
258 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
260 * This implements version 1+, dated Sept 9, 1998.
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");
330 (void)printf(" [rsvd=0x%02x]", bp
[4] & 0xfc);
335 for (; nentries
; nentries
--) {
337 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
338 ipaddr_string(&bp
[2]), bp
[1]);
340 (void)printf("[rsvd=0x%02x]", bp
[0] & 0xfe);
348 (void)printf("[|autorp]");
353 pim_print(register const u_char
*bp
, register u_int len
)
355 register const u_char
*ep
;
356 register struct pim
*pim
= (struct pim
*)bp
;
358 ep
= (const u_char
*)snapend
;
361 #ifdef notyet /* currently we see only version and type */
362 TCHECK(pim
->pim_rsv
);
365 switch (PIM_VER(pim
->pim_typever
)) {
366 case 2: /* avoid hardcoding? */
367 (void)printf("pim v2");
368 pimv2_print(bp
, len
);
371 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
378 * PIMv2 uses encoded address representations.
380 * The last PIM-SM I-D before RFC2117 was published specified the
381 * following representation for unicast addresses. However, RFC2117
382 * specified no encoding for unicast addresses with the unicast
383 * address length specified in the header. Therefore, we have to
384 * guess which encoding is being used (Cisco's PIMv2 implementation
385 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
386 * field into a 'unicast-address-length-in-bytes' field. We guess
387 * that it's the draft encoding if this reserved field is zero.
389 * RFC2362 goes back to the encoded format, and calls the addr length
390 * field "reserved" again.
392 * The first byte is the address family, from:
395 * 1 IP (IP version 4)
396 * 2 IP6 (IP version 6)
398 * 4 HDLC (8-bit multidrop)
400 * 6 802 (includes all 802 media plus Ethernet "canonical format")
402 * 8 E.164 (SMDS, Frame Relay, ATM)
404 * 10 X.121 (X.25, Frame Relay)
409 * 15 E.164 with NSAP format subaddress
411 * In addition, the second byte is an "Encoding". 0 is the default
412 * encoding for the address family, and no other encodings are currently
417 static int pimv2_addr_len
;
419 enum pimv2_addrtype
{
420 pimv2_unicast
, pimv2_group
, pimv2_source
424 * 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
425 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
426 * | Addr Family | Encoding Type | Unicast Address |
427 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
429 * 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
430 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
431 * | Addr Family | Encoding Type | Reserved | Mask Len |
432 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433 * | Group multicast 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 | Rsrvd |S|W|R| Mask Len |
439 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
441 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
452 if (pimv2_addr_len
== 0) {
474 switch (pimv2_addr_len
) {
489 len
= pimv2_addr_len
;
499 (void)printf("%s", ipaddr_string(bp
));
502 else if (af
== AF_INET6
) {
504 (void)printf("%s", ip6addr_string(bp
));
510 TCHECK2(bp
[0], len
+ 2);
513 (void)printf("%s", ipaddr_string(bp
+ 2));
515 (void)printf("/%u", bp
[1]);
519 else if (af
== AF_INET6
) {
521 (void)printf("%s", ip6addr_string(bp
+ 2));
523 (void)printf("/%u", bp
[1]);
527 if (bp
[0] && !silent
) {
528 if (at
== pimv2_group
) {
529 (void)printf("(0x%02x)", bp
[0]);
531 (void)printf("(%s%s%s",
532 bp
[0] & 0x04 ? "S" : "",
533 bp
[0] & 0x02 ? "W" : "",
534 bp
[0] & 0x01 ? "R" : "");
536 (void) printf("+0x%02x", bp
[0] & 0xf8);
541 return hdrlen
+ 2 + len
;
550 pimv2_print(register const u_char
*bp
, register u_int len
)
552 register const u_char
*ep
;
553 register struct pim
*pim
= (struct pim
*)bp
;
556 ep
= (const u_char
*)snapend
;
561 TCHECK(pim
->pim_rsv
);
562 pimv2_addr_len
= pim
->pim_rsv
;
563 if (pimv2_addr_len
!= 0)
564 (void)printf("[RFC2117-encoding] ");
566 switch (PIM_TYPE(pim
->pim_typever
)) {
569 u_int16_t otype
, olen
;
570 (void)printf(" Hello");
574 otype
= EXTRACT_16BITS(&bp
[0]);
575 olen
= EXTRACT_16BITS(&bp
[2]);
576 TCHECK2(bp
[0], 4 + olen
);
578 case 1: /* Hold time */
579 (void)printf(" (Hold-time ");
580 relts_print(EXTRACT_16BITS(&bp
[4]));
584 case 2: /* LAN Prune Delay */
585 (void)printf(" (LAN-Prune-Delay: ");
587 (void)printf("!olen=%d!)", olen
);
590 u_int16_t lan_delay
, override_interval
;
591 lan_delay
= EXTRACT_16BITS(&bp
[4]);
592 override_interval
= EXTRACT_16BITS(&bp
[6]);
593 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
594 lan_delay
&= ~0x8000;
595 (void)printf("T-bit=%d lan-delay=%dms override-interval=%dms)",
596 t_bit
, lan_delay
, override_interval
);
600 case 18: /* Old DR-Priority */
602 (void)printf(" (OLD-DR-Priority: %d)",
603 EXTRACT_32BITS(&bp
[4]));
609 case 19: /* DR-Priority */
611 (void)printf(" (OLD-bidir-capable)");
614 (void)printf(" (DR-Priority: ");
616 (void)printf("!olen=%d!)", olen
);
618 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
623 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
627 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
629 (void)printf(" interval ");
632 if (EXTRACT_16BITS(&bp
[6]) != 0) {
633 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
638 case 22: /* Bidir-Capable */
639 (void)printf(" (bidir-capable)");
642 case 24: /* Address List */
643 case 65001: /* Address List (old implementations) */
644 (void)printf(" (%saddr-list",
645 otype
== 65001 ? "old" : "");
647 const u_char
*ptr
= &bp
[4];
648 while (ptr
< &bp
[4 + olen
]) {
652 advance
= pimv2_addr_print(ptr
, pimv2_unicast
, 0);
665 (void)printf(" [Hello option %d]", otype
);
676 (void)printf(" Register");
677 if (vflag
&& bp
+ 8 <= ep
) {
678 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
679 bp
[4] & 0x40 ? "N" : "");
683 /* encapsulated multicast packet */
686 ip
= (struct ip
*)bp
;
699 (void)printf(" IP ver %d", IP_V(ip
));
706 (void)printf(" Register-Stop");
710 (void)printf(" group=");
711 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
715 bp
+= advance
; len
-= advance
;
718 (void)printf(" source=");
719 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
723 bp
+= advance
; len
-= advance
;
736 switch (PIM_TYPE(pim
->pim_typever
)) {
738 (void)printf(" Join/Prune");
741 (void)printf(" Graft");
744 (void)printf(" Graft-ACK");
748 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
751 (void)printf(" upstream-neighbor=");
752 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
756 bp
+= advance
; len
-= advance
;
761 holdtime
= EXTRACT_16BITS(&bp
[2]);
762 (void)printf(" groups=%u", ngroup
);
763 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
764 (void)printf(" holdtime=");
765 if (holdtime
== 0xffff)
766 (void)printf("infty");
768 relts_print(holdtime
);
771 for (i
= 0; i
< ngroup
; i
++) {
774 (void)printf(" (group%d: ", i
);
775 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
776 (void)printf("...)");
779 bp
+= advance
; len
-= advance
;
781 (void)printf("...)");
784 njoin
= EXTRACT_16BITS(&bp
[0]);
785 nprune
= EXTRACT_16BITS(&bp
[2]);
786 (void)printf(" join=%u", njoin
);
788 for (j
= 0; j
< njoin
; j
++) {
790 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
791 (void)printf("...)");
794 bp
+= advance
; len
-= advance
;
796 (void)printf(" prune=%u", nprune
);
797 for (j
= 0; j
< nprune
; j
++) {
799 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
800 (void)printf("...)");
803 bp
+= advance
; len
-= advance
;
815 (void)printf(" Bootstrap");
818 /* Fragment Tag, Hash Mask len, and BSR-priority */
819 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
820 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
821 bp
+= sizeof(u_int16_t
);
823 (void)printf(" hashmlen=%d", bp
[0]);
824 if (bp
+ 1 >= ep
) break;
825 (void)printf(" BSRprio=%d", bp
[1]);
828 /* Encoded-Unicast-BSR-Address */
830 (void)printf(" BSR=");
831 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
837 for (i
= 0; bp
< ep
; i
++) {
838 /* Encoded-Group Address */
839 (void)printf(" (group%d: ", i
);
840 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
842 (void)printf("...)");
847 /* RP-Count, Frag RP-Cnt, and rsvd */
849 (void)printf("...)");
852 (void)printf(" RPcnt=%d", bp
[0]);
854 (void)printf("...)");
857 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
860 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
862 (void)printf(" RP%d=", j
);
863 if ((advance
= pimv2_addr_print(bp
,
866 (void)printf("...)");
872 (void)printf("...)");
875 (void)printf(",holdtime=");
876 relts_print(EXTRACT_16BITS(bp
));
878 (void)printf("...)");
881 (void)printf(",prio=%d", bp
[2]);
890 (void)printf(" Assert");
894 (void)printf(" group=");
895 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
899 bp
+= advance
; len
-= advance
;
902 (void)printf(" src=");
903 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
907 bp
+= advance
; len
-= advance
;
911 (void)printf(" RPT");
912 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
913 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
920 (void)printf(" Candidate-RP-Advertisement");
923 /* Prefix-Cnt, Priority, and Holdtime */
925 (void)printf(" prefix-cnt=%d", bp
[0]);
927 if (bp
+ 1 >= ep
) break;
928 (void)printf(" prio=%d", bp
[1]);
929 if (bp
+ 3 >= ep
) break;
930 (void)printf(" holdtime=");
931 relts_print(EXTRACT_16BITS(&bp
[2]));
934 /* Encoded-Unicast-RP-Address */
936 (void)printf(" RP=");
937 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
943 /* Encoded-Group Addresses */
944 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
945 (void)printf(" Group%d=", i
);
946 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
957 (void)printf(" Prune-Refresh");
958 (void)printf(" src=");
959 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
964 (void)printf(" grp=");
965 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
970 (void)printf(" forwarder=");
971 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
977 (void)printf(" TUNR ");
978 relts_print(EXTRACT_16BITS(bp
));
983 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
990 (void)printf("[|pim]");