]>
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.27 2001-05-11 02:12:32 fenner Exp $ (LBL)";
31 #include <sys/param.h>
33 #include <sys/socket.h>
35 #include <netinet/in.h>
38 * XXX: We consider a case where IPv6 is not ready yet for portability,
39 * but PIM dependent defintions should be independent of IPv6...
44 /* upper 4bit: PIM version number; 2 for PIMv2 */
45 /* lower 4bit: the PIM message type, currently they are:
46 * Hello, Register, Register-Stop, Join/Prune,
47 * Bootstrap, Assert, Graft (PIM-DM only),
48 * Graft-Ack (PIM-DM only), C-RP-Adv
50 #define PIM_VER(x) (((x) & 0xf0) >> 4)
51 #define PIM_TYPE(x) ((x) & 0x0f)
52 u_char pim_rsv
; /* Reserved */
53 u_short pim_cksum
; /* IP style check sum */
61 #include "interface.h"
62 #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");
101 (void)printf(" Upstream Nbr: %s", ipaddr_string(bp
));
105 (void)printf(" Hold time: ");
106 relts_print(EXTRACT_16BITS(&bp
[6]));
120 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
121 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
122 (void)printf("/%s", ipaddr_string(&bp
[4]));
124 njoin
= EXTRACT_16BITS(&bp
[8]);
125 nprune
= EXTRACT_16BITS(&bp
[10]);
126 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
129 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
137 (void)printf("\n\t%s %s%s%s%s/%d", type
,
138 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
139 (bp
[1] & 0x80) ? "WC " : "",
140 (bp
[1] & 0x40) ? "RP " : "SPT ",
141 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
148 (void)printf("[|pim]");
153 pimv1_print(register const u_char
*bp
, register u_int len
)
155 register const u_char
*ep
;
156 register u_char type
;
158 ep
= (const u_char
*)snapend
;
166 (void)printf(" Query");
168 switch (bp
[8] >> 4) {
170 (void)printf(" Dense-mode");
173 (void)printf(" Sparse-mode");
176 (void)printf(" Sparse-Dense-mode");
179 (void)printf(" mode-%d", bp
[8] >> 4);
185 (void)printf(" (Hold-time ");
186 relts_print(EXTRACT_16BITS(&bp
[10]));
192 (void)printf(" Register");
193 TCHECK2(bp
[8], 20); /* ip header */
194 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
195 ipaddr_string(&bp
[24]));
198 (void)printf(" Register-Stop");
200 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
201 ipaddr_string(&bp
[12]));
204 (void)printf(" Join/Prune");
206 pimv1_join_prune_print(&bp
[8], len
- 8);
209 (void)printf(" RP-reachable");
212 (void)printf(" group %s",
213 ipaddr_string(&bp
[8]));
214 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
215 (void)printf("/%s", ipaddr_string(&bp
[12]));
216 (void)printf(" RP %s hold ", ipaddr_string(&bp
[16]));
217 relts_print(EXTRACT_16BITS(&bp
[22]));
221 (void)printf(" Assert");
223 (void)printf(" for %s > %s", ipaddr_string(&bp
[16]),
224 ipaddr_string(&bp
[8]));
225 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
226 (void)printf("/%s", ipaddr_string(&bp
[12]));
228 (void)printf(" %s pref %d metric %d",
229 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
230 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
231 EXTRACT_32BITS(&bp
[24]));
234 (void)printf(" Graft");
236 pimv1_join_prune_print(&bp
[8], len
- 8);
239 (void)printf(" Graft-ACK");
241 pimv1_join_prune_print(&bp
[8], len
- 8);
244 (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]));
586 case 19: /* DR-Priority */
587 (void)printf(" (DR-Priority: ");
589 (void)printf("!olen=%d!)", olen
);
591 (void)printf("%d)", EXTRACT_32BITS(&bp
[4]));
596 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
600 (void)printf(" (State Refresh Capable; v%d", bp
[4]);
602 (void)printf(" interval ");
605 if (EXTRACT_16BITS(&bp
[6]) != 0) {
606 (void)printf(" ?0x%04x?", EXTRACT_16BITS(&bp
[6]));
611 case 22: /* Bidir-Capable */
612 (void)printf(" (bidir-capable)");
617 (void)printf(" [Hello option %d]", otype
);
628 (void)printf(" Register");
629 if (vflag
&& bp
+ 8 <= ep
) {
630 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
631 bp
[4] & 0x40 ? "N" : "");
635 /* encapsulated multicast packet */
638 ip
= (struct ip
*)bp
;
651 (void)printf(" IP ver %d", IP_V(ip
));
658 (void)printf(" Register-Stop");
662 (void)printf(" group=");
663 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
667 bp
+= advance
; len
-= advance
;
670 (void)printf(" source=");
671 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
675 bp
+= advance
; len
-= advance
;
688 switch (PIM_TYPE(pim
->pim_typever
)) {
690 (void)printf(" Join/Prune");
693 (void)printf(" Graft");
696 (void)printf(" Graft-ACK");
700 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
703 (void)printf(" upstream-neighbor=");
704 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
708 bp
+= advance
; len
-= advance
;
713 holdtime
= EXTRACT_16BITS(&bp
[2]);
714 (void)printf(" groups=%u", ngroup
);
715 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
716 (void)printf(" holdtime=");
717 if (holdtime
== 0xffff)
718 (void)printf("infty");
720 relts_print(holdtime
);
723 for (i
= 0; i
< ngroup
; i
++) {
726 (void)printf(" (group%d: ", i
);
727 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
728 (void)printf("...)");
731 bp
+= advance
; len
-= advance
;
733 (void)printf("...)");
736 njoin
= EXTRACT_16BITS(&bp
[0]);
737 nprune
= EXTRACT_16BITS(&bp
[2]);
738 (void)printf(" join=%u", njoin
);
740 for (j
= 0; j
< njoin
; j
++) {
742 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
743 (void)printf("...)");
746 bp
+= advance
; len
-= advance
;
748 (void)printf(" prune=%u", nprune
);
749 for (j
= 0; j
< nprune
; j
++) {
751 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
752 (void)printf("...)");
755 bp
+= advance
; len
-= advance
;
767 (void)printf(" Bootstrap");
770 /* Fragment Tag, Hash Mask len, and BSR-priority */
771 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
772 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
773 bp
+= sizeof(u_int16_t
);
775 (void)printf(" hashmlen=%d", bp
[0]);
776 if (bp
+ 1 >= ep
) break;
777 (void)printf(" BSRprio=%d", bp
[1]);
780 /* Encoded-Unicast-BSR-Address */
782 (void)printf(" BSR=");
783 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
789 for (i
= 0; bp
< ep
; i
++) {
790 /* Encoded-Group Address */
791 (void)printf(" (group%d: ", i
);
792 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
794 (void)printf("...)");
799 /* RP-Count, Frag RP-Cnt, and rsvd */
801 (void)printf("...)");
804 (void)printf(" RPcnt=%d", bp
[0]);
806 (void)printf("...)");
809 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
812 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
814 (void)printf(" RP%d=", j
);
815 if ((advance
= pimv2_addr_print(bp
,
818 (void)printf("...)");
824 (void)printf("...)");
827 (void)printf(",holdtime=");
828 relts_print(EXTRACT_16BITS(bp
));
830 (void)printf("...)");
833 (void)printf(",prio=%d", bp
[2]);
842 (void)printf(" Assert");
846 (void)printf(" group=");
847 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
851 bp
+= advance
; len
-= advance
;
854 (void)printf(" src=");
855 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
859 bp
+= advance
; len
-= advance
;
863 (void)printf(" RPT");
864 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
865 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
872 (void)printf(" Candidate-RP-Advertisement");
875 /* Prefix-Cnt, Priority, and Holdtime */
877 (void)printf(" prefix-cnt=%d", bp
[0]);
879 if (bp
+ 1 >= ep
) break;
880 (void)printf(" prio=%d", bp
[1]);
881 if (bp
+ 3 >= ep
) break;
882 (void)printf(" holdtime=");
883 relts_print(EXTRACT_16BITS(&bp
[2]));
886 /* Encoded-Unicast-RP-Address */
888 (void)printf(" RP=");
889 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
895 /* Encoded-Group Addresses */
896 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
897 (void)printf(" Group%d=", i
);
898 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
909 (void)printf(" Prune-Refresh");
910 (void)printf(" src=");
911 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
916 (void)printf(" grp=");
917 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
922 (void)printf(" forwarder=");
923 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
929 (void)printf(" TUNR ");
930 relts_print(EXTRACT_16BITS(bp
));
935 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
942 (void)printf("[|pim]");