]>
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.40 2003-11-19 09:42:05 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
));
116 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
117 (void)printf("/%s", ipaddr_string(&bp
[4]));
119 njoin
= EXTRACT_16BITS(&bp
[8]);
120 nprune
= EXTRACT_16BITS(&bp
[10]);
121 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
124 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
132 (void)printf("\n\t%s %s%s%s%s/%d", type
,
133 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
134 (bp
[1] & 0x80) ? "WC " : "",
135 (bp
[1] & 0x40) ? "RP " : "SPT ",
136 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
143 (void)printf("[|pim]");
148 pimv1_print(register const u_char
*bp
, register u_int len
)
150 register const u_char
*ep
;
151 register u_char type
;
153 ep
= (const u_char
*)snapend
;
162 (void)printf(" Query");
164 switch (bp
[8] >> 4) {
166 (void)printf(" Dense-mode");
169 (void)printf(" Sparse-mode");
172 (void)printf(" Sparse-Dense-mode");
175 (void)printf(" mode-%d", bp
[8] >> 4);
181 (void)printf(" (Hold-time ");
182 relts_print(EXTRACT_16BITS(&bp
[10]));
188 (void)printf(" Register");
189 TCHECK2(bp
[8], 20); /* ip header */
190 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
191 ipaddr_string(&bp
[24]));
194 (void)printf(" Register-Stop");
196 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
197 ipaddr_string(&bp
[12]));
200 (void)printf(" Join/Prune");
202 pimv1_join_prune_print(&bp
[8], len
- 8);
205 (void)printf(" RP-reachable");
208 (void)printf(" group %s",
209 ipaddr_string(&bp
[8]));
210 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
211 (void)printf("/%s", ipaddr_string(&bp
[12]));
212 (void)printf(" RP %s hold ", ipaddr_string(&bp
[16]));
213 relts_print(EXTRACT_16BITS(&bp
[22]));
217 (void)printf(" Assert");
219 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
220 ipaddr_string(&bp
[8]));
221 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
222 (void)printf("/%s", ipaddr_string(&bp
[12]));
224 (void)printf(" %s pref %d metric %d",
225 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
226 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
227 EXTRACT_32BITS(&bp
[24]));
230 (void)printf(" Graft");
232 pimv1_join_prune_print(&bp
[8], len
- 8);
235 (void)printf(" Graft-ACK");
237 pimv1_join_prune_print(&bp
[8], len
- 8);
240 (void)printf(" Mode");
243 (void)printf(" [type %d]", type
);
246 if ((bp
[4] >> 4) != 1)
247 (void)printf(" [v%d]", bp
[4] >> 4);
251 (void)printf("[|pim]");
256 * auto-RP is a cisco protocol, documented at
257 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
259 * This implements version 1+, dated Sept 9, 1998.
262 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
269 (void)printf(" auto-rp ");
273 (void)printf("candidate-advert");
276 (void)printf("mapping");
279 (void)printf("type-0x%02x", type
);
287 (void)printf(" Hold ");
288 hold
= EXTRACT_16BITS(&bp
[2]);
290 relts_print(EXTRACT_16BITS(&bp
[2]));
294 /* Next 4 bytes are reserved. */
298 /*XXX skip unless -v? */
302 * numrps entries of the form:
305 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
306 * 8 bits: # of entries for this RP
307 * each entry: 7 bits: reserved, 1 bit: negative,
308 * 8 bits: mask 32 bits: source
309 * lather, rinse, repeat.
316 (void)printf(" RP %s", ipaddr_string(bp
));
318 switch (bp
[4] & 0x3) {
319 case 0: printf(" PIMv?");
321 case 1: printf(" PIMv1");
323 case 2: printf(" PIMv2");
325 case 3: printf(" PIMv1+2");
329 (void)printf(" [rsvd=0x%02x]", bp
[4] & 0xfc);
334 for (; nentries
; nentries
--) {
336 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
337 ipaddr_string(&bp
[2]), bp
[1]);
339 (void)printf("[rsvd=0x%02x]", bp
[0] & 0xfe);
347 (void)printf("[|autorp]");
352 pim_print(register const u_char
*bp
, register u_int len
)
354 register const u_char
*ep
;
355 register struct pim
*pim
= (struct pim
*)bp
;
357 ep
= (const u_char
*)snapend
;
360 #ifdef notyet /* currently we see only version and type */
361 TCHECK(pim
->pim_rsv
);
364 switch (PIM_VER(pim
->pim_typever
)) {
365 case 2: /* avoid hardcoding? */
366 (void)printf("pim v2");
367 pimv2_print(bp
, len
);
370 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
377 * PIMv2 uses encoded address representations.
379 * The last PIM-SM I-D before RFC2117 was published specified the
380 * following representation for unicast addresses. However, RFC2117
381 * specified no encoding for unicast addresses with the unicast
382 * address length specified in the header. Therefore, we have to
383 * guess which encoding is being used (Cisco's PIMv2 implementation
384 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
385 * field into a 'unicast-address-length-in-bytes' field. We guess
386 * that it's the draft encoding if this reserved field is zero.
388 * RFC2362 goes back to the encoded format, and calls the addr length
389 * field "reserved" again.
391 * The first byte is the address family, from:
394 * 1 IP (IP version 4)
395 * 2 IP6 (IP version 6)
397 * 4 HDLC (8-bit multidrop)
399 * 6 802 (includes all 802 media plus Ethernet "canonical format")
401 * 8 E.164 (SMDS, Frame Relay, ATM)
403 * 10 X.121 (X.25, Frame Relay)
408 * 15 E.164 with NSAP format subaddress
410 * In addition, the second byte is an "Encoding". 0 is the default
411 * encoding for the address family, and no other encodings are currently
416 static int pimv2_addr_len
;
418 enum pimv2_addrtype
{
419 pimv2_unicast
, pimv2_group
, pimv2_source
423 * 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
424 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
425 * | Addr Family | Encoding Type | Unicast Address |
426 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
428 * 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
429 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
430 * | Addr Family | Encoding Type | Reserved | Mask Len |
431 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
432 * | Group multicast Address |
433 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
435 * 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
436 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
438 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
443 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
451 if (pimv2_addr_len
== 0) {
473 switch (pimv2_addr_len
) {
488 len
= pimv2_addr_len
;
498 (void)printf("%s", ipaddr_string(bp
));
501 else if (af
== AF_INET6
) {
503 (void)printf("%s", ip6addr_string(bp
));
509 TCHECK2(bp
[0], len
+ 2);
512 (void)printf("%s", ipaddr_string(bp
+ 2));
514 (void)printf("/%u", bp
[1]);
518 else if (af
== AF_INET6
) {
520 (void)printf("%s", ip6addr_string(bp
+ 2));
522 (void)printf("/%u", bp
[1]);
526 if (bp
[0] && !silent
) {
527 if (at
== pimv2_group
) {
528 (void)printf("(0x%02x)", bp
[0]);
530 (void)printf("(%s%s%s",
531 bp
[0] & 0x04 ? "S" : "",
532 bp
[0] & 0x02 ? "W" : "",
533 bp
[0] & 0x01 ? "R" : "");
535 (void) printf("+0x%02x", bp
[0] & 0xf8);
540 return hdrlen
+ 2 + len
;
549 pimv2_print(register const u_char
*bp
, register u_int len
)
551 register const u_char
*ep
;
552 register struct pim
*pim
= (struct pim
*)bp
;
555 ep
= (const u_char
*)snapend
;
560 TCHECK(pim
->pim_rsv
);
561 pimv2_addr_len
= pim
->pim_rsv
;
562 if (pimv2_addr_len
!= 0)
563 (void)printf("[RFC2117-encoding] ");
565 switch (PIM_TYPE(pim
->pim_typever
)) {
568 u_int16_t otype
, olen
;
569 (void)printf(" Hello");
573 otype
= EXTRACT_16BITS(&bp
[0]);
574 olen
= EXTRACT_16BITS(&bp
[2]);
575 TCHECK2(bp
[0], 4 + olen
);
577 case 1: /* Hold time */
578 (void)printf(" (Hold-time ");
579 relts_print(EXTRACT_16BITS(&bp
[4]));
583 case 2: /* LAN Prune Delay */
584 (void)printf(" (LAN-Prune-Delay: ");
586 (void)printf("!olen=%d!)", olen
);
589 u_int16_t lan_delay
, override_interval
;
590 lan_delay
= EXTRACT_16BITS(&bp
[4]);
591 override_interval
= EXTRACT_16BITS(&bp
[6]);
592 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
593 lan_delay
&= ~0x8000;
594 (void)printf("T-bit=%d lan-delay=%dms override-interval=%dms)",
595 t_bit
, lan_delay
, override_interval
);
599 case 18: /* Old DR-Priority */
601 (void)printf(" (OLD-DR-Priority: %d)",
602 EXTRACT_32BITS(&bp
[4]));
608 case 19: /* DR-Priority */
610 (void)printf(" (OLD-bidir-capable)");
613 (void)printf(" (DR-Priority: ");
615 (void)printf("!olen=%d!)", olen
);
617 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
622 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
626 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
628 (void)printf(" interval ");
631 if (EXTRACT_16BITS(&bp
[6]) != 0) {
632 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
637 case 22: /* Bidir-Capable */
638 (void)printf(" (bidir-capable)");
641 case 24: /* Address List */
642 case 65001: /* Address List (old implementations) */
643 (void)printf(" (%saddr-list",
644 otype
== 65001 ? "old" : "");
646 const u_char
*ptr
= &bp
[4];
647 while (ptr
< &bp
[4 + olen
]) {
651 advance
= pimv2_addr_print(ptr
, pimv2_unicast
, 0);
664 (void)printf(" [Hello option %d]", otype
);
675 (void)printf(" Register");
676 if (vflag
&& bp
+ 8 <= ep
) {
677 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
678 bp
[4] & 0x40 ? "N" : "");
682 /* encapsulated multicast packet */
685 ip
= (struct ip
*)bp
;
698 (void)printf(" IP ver %d", IP_V(ip
));
705 (void)printf(" Register-Stop");
709 (void)printf(" group=");
710 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
714 bp
+= advance
; len
-= advance
;
717 (void)printf(" source=");
718 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
722 bp
+= advance
; len
-= advance
;
735 switch (PIM_TYPE(pim
->pim_typever
)) {
737 (void)printf(" Join/Prune");
740 (void)printf(" Graft");
743 (void)printf(" Graft-ACK");
747 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
750 (void)printf(" upstream-neighbor=");
751 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
755 bp
+= advance
; len
-= advance
;
760 holdtime
= EXTRACT_16BITS(&bp
[2]);
761 (void)printf(" groups=%u", ngroup
);
762 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
763 (void)printf(" holdtime=");
764 if (holdtime
== 0xffff)
765 (void)printf("infty");
767 relts_print(holdtime
);
770 for (i
= 0; i
< ngroup
; i
++) {
773 (void)printf(" (group%d: ", i
);
774 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
775 (void)printf("...)");
778 bp
+= advance
; len
-= advance
;
780 (void)printf("...)");
783 njoin
= EXTRACT_16BITS(&bp
[0]);
784 nprune
= EXTRACT_16BITS(&bp
[2]);
785 (void)printf(" join=%u", njoin
);
787 for (j
= 0; j
< njoin
; j
++) {
789 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
790 (void)printf("...)");
793 bp
+= advance
; len
-= advance
;
795 (void)printf(" prune=%u", nprune
);
796 for (j
= 0; j
< nprune
; j
++) {
798 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
799 (void)printf("...)");
802 bp
+= advance
; len
-= advance
;
814 (void)printf(" Bootstrap");
817 /* Fragment Tag, Hash Mask len, and BSR-priority */
818 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
819 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
820 bp
+= sizeof(u_int16_t
);
822 (void)printf(" hashmlen=%d", bp
[0]);
823 if (bp
+ 1 >= ep
) break;
824 (void)printf(" BSRprio=%d", bp
[1]);
827 /* Encoded-Unicast-BSR-Address */
829 (void)printf(" BSR=");
830 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
836 for (i
= 0; bp
< ep
; i
++) {
837 /* Encoded-Group Address */
838 (void)printf(" (group%d: ", i
);
839 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
841 (void)printf("...)");
846 /* RP-Count, Frag RP-Cnt, and rsvd */
848 (void)printf("...)");
851 (void)printf(" RPcnt=%d", bp
[0]);
853 (void)printf("...)");
856 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
859 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
861 (void)printf(" RP%d=", j
);
862 if ((advance
= pimv2_addr_print(bp
,
865 (void)printf("...)");
871 (void)printf("...)");
874 (void)printf(",holdtime=");
875 relts_print(EXTRACT_16BITS(bp
));
877 (void)printf("...)");
880 (void)printf(",prio=%d", bp
[2]);
889 (void)printf(" Assert");
893 (void)printf(" group=");
894 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
898 bp
+= advance
; len
-= advance
;
901 (void)printf(" src=");
902 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
906 bp
+= advance
; len
-= advance
;
910 (void)printf(" RPT");
911 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
912 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
919 (void)printf(" Candidate-RP-Advertisement");
922 /* Prefix-Cnt, Priority, and Holdtime */
924 (void)printf(" prefix-cnt=%d", bp
[0]);
926 if (bp
+ 1 >= ep
) break;
927 (void)printf(" prio=%d", bp
[1]);
928 if (bp
+ 3 >= ep
) break;
929 (void)printf(" holdtime=");
930 relts_print(EXTRACT_16BITS(&bp
[2]));
933 /* Encoded-Unicast-RP-Address */
935 (void)printf(" RP=");
936 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
942 /* Encoded-Group Addresses */
943 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
944 (void)printf(" Group%d=", i
);
945 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
956 (void)printf(" Prune-Refresh");
957 (void)printf(" src=");
958 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
963 (void)printf(" grp=");
964 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
969 (void)printf(" forwarder=");
970 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
976 (void)printf(" TUNR ");
977 relts_print(EXTRACT_16BITS(bp
));
982 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
989 (void)printf("[|pim]");