]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pim.c
78f525a6210cf060df7a73d0d88a6a183bb1a7af
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.24 2001-01-28 08:27:28 itojun 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");
99 (void)printf("\n Upstream Nbr: %s", ipaddr_string(bp
));
101 (void)printf("\n Hold time: ");
102 relts_print(EXTRACT_16BITS(&bp
[6]));
114 (void)printf("\n\tGroup: %s", ipaddr_string(bp
));
115 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
116 (void)printf("/%s", ipaddr_string(&bp
[4]));
118 njoin
= EXTRACT_16BITS(&bp
[8]);
119 nprune
= EXTRACT_16BITS(&bp
[10]);
120 (void)printf(" joined: %d pruned: %d", njoin
, nprune
);
123 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
131 (void)printf("\n\t%s %s%s%s%s/%d", type
,
132 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
133 (bp
[1] & 0x80) ? "WC " : "",
134 (bp
[1] & 0x40) ? "RP " : "SPT ",
135 ipaddr_string(&bp
[2]), bp
[1] & 0x3f);
142 (void)printf("[|pim]");
147 pimv1_print(register const u_char
*bp
, register u_int len
)
149 register const u_char
*ep
;
150 register u_char type
;
152 ep
= (const u_char
*)snapend
;
160 (void)printf(" Query");
162 switch (bp
[8] >> 4) {
164 (void)printf(" Dense-mode");
167 (void)printf(" Sparse-mode");
170 (void)printf(" Sparse-Dense-mode");
173 (void)printf(" mode-%d", bp
[8] >> 4);
179 (void)printf(" (Hold-time ");
180 relts_print(EXTRACT_16BITS(&bp
[10]));
186 (void)printf(" Register");
187 TCHECK2(bp
[8], 20); /* ip header */
188 (void)printf(" for %s > %s", ipaddr_string(&bp
[20]),
189 ipaddr_string(&bp
[24]));
192 (void)printf(" Register-Stop");
194 (void)printf(" for %s > %s", ipaddr_string(&bp
[8]),
195 ipaddr_string(&bp
[12]));
198 (void)printf(" Join/Prune");
200 pimv1_join_prune_print(&bp
[8], len
- 8);
203 (void)printf(" RP-reachable");
206 (void)printf(" group %s",
207 ipaddr_string(&bp
[8]));
208 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
209 (void)printf("/%s", ipaddr_string(&bp
[12]));
210 (void)printf(" RP %s hold ", ipaddr_string(&bp
[16]));
211 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]));
228 (void)printf(" Graft");
230 pimv1_join_prune_print(&bp
[8], len
- 8);
233 (void)printf(" Graft-ACK");
235 pimv1_join_prune_print(&bp
[8], len
- 8);
238 (void)printf(" Mode");
241 (void)printf(" [type %d]", type
);
244 if ((bp
[4] >> 4) != 1)
245 (void)printf(" [v%d]", bp
[4] >> 4);
249 (void)printf("[|pim]");
254 * auto-RP is a cisco protocol, documented at
255 * ftp://ftpeng.cisco.com/ipmulticast/pim-autorp-spec01.txt
258 cisco_autorp_print(register const u_char
*bp
, register u_int len
)
265 (void)printf(" auto-rp ");
269 (void)printf("candidate-advert");
272 (void)printf("mapping");
275 (void)printf("type-0x%02x", type
);
283 (void)printf(" Hold ");
284 hold
= EXTRACT_16BITS(&bp
[2]);
286 relts_print(EXTRACT_16BITS(&bp
[2]));
290 /* Next 4 bytes are reserved. */
294 /*XXX skip unless -v? */
298 * numrps entries of the form:
301 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
302 * 8 bits: # of entries for this RP
303 * each entry: 7 bits: reserved, 1 bit: negative,
304 * 8 bits: mask 32 bits: source
305 * lather, rinse, repeat.
312 (void)printf(" RP %s", ipaddr_string(bp
));
314 switch (bp
[4] & 0x3) {
315 case 0: printf(" PIMv?");
317 case 1: printf(" PIMv1");
319 case 2: printf(" PIMv2");
321 case 3: printf(" PIMv1+2");
328 for (; nentries
; nentries
--) {
330 (void)printf("%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
331 ipaddr_string(&bp
[2]), bp
[1]);
339 (void)printf("[|autorp]");
344 pim_print(register const u_char
*bp
, register u_int len
)
346 register const u_char
*ep
;
347 register struct pim
*pim
= (struct pim
*)bp
;
349 ep
= (const u_char
*)snapend
;
352 #ifdef notyet /* currently we see only version and type */
353 TCHECK(pim
->pim_rsv
);
356 switch (PIM_VER(pim
->pim_typever
)) {
357 case 2: /* avoid hardcoding? */
358 (void)printf("pim v2");
359 pimv2_print(bp
, len
);
362 (void)printf("pim v%d", PIM_VER(pim
->pim_typever
));
369 * PIMv2 uses encoded address representations.
371 * The last PIM-SM I-D before RFC2117 was published specified the
372 * following representation for unicast addresses. However, RFC2117
373 * specified no encoding for unicast addresses with the unicast
374 * address length specified in the header. Therefore, we have to
375 * guess which encoding is being used (Cisco's PIMv2 implementation
376 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
377 * field into a 'unicast-address-length-in-bytes' field. We guess
378 * that it's the draft encoding if this reserved field is zero.
380 * RFC2362 goes back to the encoded format, and calls the addr length
381 * field "reserved" again.
383 * The first byte is the address family, from:
386 * 1 IP (IP version 4)
387 * 2 IP6 (IP version 6)
389 * 4 HDLC (8-bit multidrop)
391 * 6 802 (includes all 802 media plus Ethernet "canonical format")
393 * 8 E.164 (SMDS, Frame Relay, ATM)
395 * 10 X.121 (X.25, Frame Relay)
400 * 15 E.164 with NSAP format subaddress
402 * In addition, the second byte is an "Encoding". 0 is the default
403 * encoding for the address family, and no other encodings are currently
408 static int pimv2_addr_len
;
410 enum pimv2_addrtype
{
411 pimv2_unicast
, pimv2_group
, pimv2_source
414 static char *addrtypestr
[] = {
415 "unicast", "group", "source"
420 * 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
421 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
422 * | Addr Family | Encoding Type | Unicast Address |
423 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
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 | Reserved | Mask Len |
428 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
429 * | Group multicast Address |
430 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
432 * 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
433 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
434 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
435 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440 pimv2_addr_print(const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
448 if (pimv2_addr_len
== 0) {
470 switch (pimv2_addr_len
) {
485 len
= pimv2_addr_len
;
495 (void)printf("%s", ipaddr_string(bp
));
498 else if (af
== AF_INET6
) {
500 (void)printf("%s", ip6addr_string(bp
));
506 TCHECK2(bp
[0], len
+ 2);
509 (void)printf("%s", ipaddr_string(bp
+ 2));
511 (void)printf("/%u", bp
[1]);
515 else if (af
== AF_INET6
) {
517 (void)printf("%s", ip6addr_string(bp
+ 2));
519 (void)printf("/%u", bp
[1]);
523 if (bp
[0] && !silent
) {
524 if (at
== pimv2_group
) {
525 (void)printf("(0x%02x)", bp
[0]);
527 (void)printf("(%s%s%s",
528 bp
[0] & 0x04 ? "S" : "",
529 bp
[0] & 0x02 ? "W" : "",
530 bp
[0] & 0x01 ? "R" : "");
532 (void) printf("+0x%02x", bp
[0] & 0xf8);
537 return hdrlen
+ 2 + len
;
546 pimv2_print(register const u_char
*bp
, register u_int len
)
548 register const u_char
*ep
;
549 register struct pim
*pim
= (struct pim
*)bp
;
552 ep
= (const u_char
*)snapend
;
557 TCHECK(pim
->pim_rsv
);
558 pimv2_addr_len
= pim
->pim_rsv
;
559 if (pimv2_addr_len
!= 0)
560 (void)printf("[RFC2117-encoding] ");
562 switch (PIM_TYPE(pim
->pim_typever
)) {
565 u_int16_t otype
, olen
;
566 (void)printf(" Hello");
570 otype
= EXTRACT_16BITS(&bp
[0]);
571 olen
= EXTRACT_16BITS(&bp
[2]);
572 TCHECK2(bp
[0], 4 + olen
);
574 case 1: /* Hold time */
575 (void)printf(" (Hold-time ");
576 relts_print(EXTRACT_16BITS(&bp
[4]));
581 * draft-ietf-idmr-pimv2-dr-priority-00.txt
582 * says that DR-Priority is option 19.
583 * draft-ietf-pim-v2-sm-00.txt says it's 18.
585 case 18: /* DR-Priority */
586 (void)printf(" (DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
589 case 19: /* Bidir-Capable */
591 (void)printf(" (OLD-DR-Priority: %d)", EXTRACT_32BITS(&bp
[4]));
593 (void)printf(" (bidir-capable)");
597 (void)printf(" (Genid: 0x%08x)", EXTRACT_32BITS(&bp
[4]));
601 (void)printf(" (State Refresh Capable");
602 if (EXTRACT_32BITS(&bp
[4]) != 1) {
603 (void)printf(" ?0x%x?", EXTRACT_32BITS(&bp
[4]));
610 (void)printf(" [Hello option %d]", otype
);
621 (void)printf(" Register");
622 if (vflag
&& bp
+ 8 <= ep
) {
623 (void)printf(" %s%s", bp
[4] & 0x80 ? "B" : "",
624 bp
[4] & 0x40 ? "N" : "");
628 /* encapsulated multicast packet */
631 ip
= (struct ip
*)bp
;
644 (void)printf(" IP ver %d", IP_V(ip
));
651 (void)printf(" Register-Stop");
655 (void)printf(" group=");
656 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
660 bp
+= advance
; len
-= advance
;
663 (void)printf(" source=");
664 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
668 bp
+= advance
; len
-= advance
;
681 switch (PIM_TYPE(pim
->pim_typever
)) {
683 (void)printf(" Join/Prune");
686 (void)printf(" Graft");
689 (void)printf(" Graft-ACK");
693 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
696 (void)printf(" upstream-neighbor=");
697 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
701 bp
+= advance
; len
-= advance
;
706 holdtime
= EXTRACT_16BITS(&bp
[2]);
707 (void)printf(" groups=%u", ngroup
);
708 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
709 (void)printf(" holdtime=");
710 if (holdtime
== 0xffff)
711 (void)printf("infty");
713 relts_print(holdtime
);
716 for (i
= 0; i
< ngroup
; i
++) {
719 (void)printf(" (group%d: ", i
);
720 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
721 (void)printf("...)");
724 bp
+= advance
; len
-= advance
;
726 (void)printf("...)");
729 njoin
= EXTRACT_16BITS(&bp
[0]);
730 nprune
= EXTRACT_16BITS(&bp
[2]);
731 (void)printf(" join=%u", njoin
);
733 for (j
= 0; j
< njoin
; j
++) {
735 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
736 (void)printf("...)");
739 bp
+= advance
; len
-= advance
;
741 (void)printf(" prune=%u", nprune
);
742 for (j
= 0; j
< nprune
; j
++) {
744 if ((advance
= pimv2_addr_print(bp
, pimv2_source
, 0)) < 0) {
745 (void)printf("...)");
748 bp
+= advance
; len
-= advance
;
760 (void)printf(" Bootstrap");
763 /* Fragment Tag, Hash Mask len, and BSR-priority */
764 if (bp
+ sizeof(u_int16_t
) >= ep
) break;
765 (void)printf(" tag=%x", EXTRACT_16BITS(bp
));
766 bp
+= sizeof(u_int16_t
);
768 (void)printf(" hashmlen=%d", bp
[0]);
769 if (bp
+ 1 >= ep
) break;
770 (void)printf(" BSRprio=%d", bp
[1]);
773 /* Encoded-Unicast-BSR-Address */
775 (void)printf(" BSR=");
776 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
782 for (i
= 0; bp
< ep
; i
++) {
783 /* Encoded-Group Address */
784 (void)printf(" (group%d: ", i
);
785 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
787 (void)printf("...)");
792 /* RP-Count, Frag RP-Cnt, and rsvd */
794 (void)printf("...)");
797 (void)printf(" RPcnt=%d", bp
[0]);
799 (void)printf("...)");
802 (void)printf(" FRPcnt=%d", frpcnt
= bp
[1]);
805 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
807 (void)printf(" RP%d=", j
);
808 if ((advance
= pimv2_addr_print(bp
,
811 (void)printf("...)");
817 (void)printf("...)");
820 (void)printf(",holdtime=");
821 relts_print(EXTRACT_16BITS(bp
));
823 (void)printf("...)");
826 (void)printf(",prio=%d", bp
[2]);
835 (void)printf(" Assert");
839 (void)printf(" group=");
840 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
844 bp
+= advance
; len
-= advance
;
847 (void)printf(" src=");
848 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
852 bp
+= advance
; len
-= advance
;
856 (void)printf(" RPT");
857 (void)printf(" pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff);
858 (void)printf(" metric=%u", EXTRACT_32BITS(&bp
[4]));
865 (void)printf(" Candidate-RP-Advertisement");
868 /* Prefix-Cnt, Priority, and Holdtime */
870 (void)printf(" prefix-cnt=%d", bp
[0]);
872 if (bp
+ 1 >= ep
) break;
873 (void)printf(" prio=%d", bp
[1]);
874 if (bp
+ 3 >= ep
) break;
875 (void)printf(" holdtime=");
876 relts_print(EXTRACT_16BITS(&bp
[2]));
879 /* Encoded-Unicast-RP-Address */
881 (void)printf(" RP=");
882 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
888 /* Encoded-Group Addresses */
889 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
890 (void)printf(" Group%d=", i
);
891 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0))
902 (void)printf(" Prune-Refresh");
903 (void)printf(" src=");
904 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
909 (void)printf(" grp=");
910 if ((advance
= pimv2_addr_print(bp
, pimv2_group
, 0)) < 0) {
915 (void)printf(" forwarder=");
916 if ((advance
= pimv2_addr_print(bp
, pimv2_unicast
, 0)) < 0) {
922 (void)printf(" TUNR ");
923 relts_print(EXTRACT_16BITS(bp
));
928 (void)printf(" [type %d]", PIM_TYPE(pim
->pim_typever
));
935 (void)printf("[|pim]");