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.
26 #include <netdissect-stdinc.h>
28 #include "netdissect.h"
29 #include "addrtoname.h"
36 #define PIMV1_TYPE_QUERY 0
37 #define PIMV1_TYPE_REGISTER 1
38 #define PIMV1_TYPE_REGISTER_STOP 2
39 #define PIMV1_TYPE_JOIN_PRUNE 3
40 #define PIMV1_TYPE_RP_REACHABILITY 4
41 #define PIMV1_TYPE_ASSERT 5
42 #define PIMV1_TYPE_GRAFT 6
43 #define PIMV1_TYPE_GRAFT_ACK 7
45 static const struct tok pimv1_type_str
[] = {
46 { PIMV1_TYPE_QUERY
, "Query" },
47 { PIMV1_TYPE_REGISTER
, "Register" },
48 { PIMV1_TYPE_REGISTER_STOP
, "Register-Stop" },
49 { PIMV1_TYPE_JOIN_PRUNE
, "Join/Prune" },
50 { PIMV1_TYPE_RP_REACHABILITY
, "RP-reachable" },
51 { PIMV1_TYPE_ASSERT
, "Assert" },
52 { PIMV1_TYPE_GRAFT
, "Graft" },
53 { PIMV1_TYPE_GRAFT_ACK
, "Graft-ACK" },
57 #define PIMV2_TYPE_HELLO 0
58 #define PIMV2_TYPE_REGISTER 1
59 #define PIMV2_TYPE_REGISTER_STOP 2
60 #define PIMV2_TYPE_JOIN_PRUNE 3
61 #define PIMV2_TYPE_BOOTSTRAP 4
62 #define PIMV2_TYPE_ASSERT 5
63 #define PIMV2_TYPE_GRAFT 6
64 #define PIMV2_TYPE_GRAFT_ACK 7
65 #define PIMV2_TYPE_CANDIDATE_RP 8
66 #define PIMV2_TYPE_PRUNE_REFRESH 9
67 #define PIMV2_TYPE_DF_ELECTION 10
68 #define PIMV2_TYPE_ECMP_REDIRECT 11
70 static const struct tok pimv2_type_values
[] = {
71 { PIMV2_TYPE_HELLO
, "Hello" },
72 { PIMV2_TYPE_REGISTER
, "Register" },
73 { PIMV2_TYPE_REGISTER_STOP
, "Register Stop" },
74 { PIMV2_TYPE_JOIN_PRUNE
, "Join / Prune" },
75 { PIMV2_TYPE_BOOTSTRAP
, "Bootstrap" },
76 { PIMV2_TYPE_ASSERT
, "Assert" },
77 { PIMV2_TYPE_GRAFT
, "Graft" },
78 { PIMV2_TYPE_GRAFT_ACK
, "Graft Acknowledgement" },
79 { PIMV2_TYPE_CANDIDATE_RP
, "Candidate RP Advertisement" },
80 { PIMV2_TYPE_PRUNE_REFRESH
, "Prune Refresh" },
81 { PIMV2_TYPE_DF_ELECTION
, "DF Election" },
82 { PIMV2_TYPE_ECMP_REDIRECT
, "ECMP Redirect" },
86 #define PIMV2_HELLO_OPTION_HOLDTIME 1
87 #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2
88 #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18
89 #define PIMV2_HELLO_OPTION_DR_PRIORITY 19
90 #define PIMV2_HELLO_OPTION_GENID 20
91 #define PIMV2_HELLO_OPTION_REFRESH_CAP 21
92 #define PIMV2_HELLO_OPTION_BIDIR_CAP 22
93 #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24
94 #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001
96 static const struct tok pimv2_hello_option_values
[] = {
97 { PIMV2_HELLO_OPTION_HOLDTIME
, "Hold Time" },
98 { PIMV2_HELLO_OPTION_LANPRUNEDELAY
, "LAN Prune Delay" },
99 { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
, "DR Priority (Old)" },
100 { PIMV2_HELLO_OPTION_DR_PRIORITY
, "DR Priority" },
101 { PIMV2_HELLO_OPTION_GENID
, "Generation ID" },
102 { PIMV2_HELLO_OPTION_REFRESH_CAP
, "State Refresh Capability" },
103 { PIMV2_HELLO_OPTION_BIDIR_CAP
, "Bi-Directional Capability" },
104 { PIMV2_HELLO_OPTION_ADDRESS_LIST
, "Address List" },
105 { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
, "Address List (Old)" },
109 #define PIMV2_REGISTER_FLAG_LEN 4
110 #define PIMV2_REGISTER_FLAG_BORDER 0x80000000
111 #define PIMV2_REGISTER_FLAG_NULL 0x40000000
113 static const struct tok pimv2_register_flag_values
[] = {
114 { PIMV2_REGISTER_FLAG_BORDER
, "Border" },
115 { PIMV2_REGISTER_FLAG_NULL
, "Null" },
120 * XXX: We consider a case where IPv6 is not ready yet for portability,
121 * but PIM dependent defintions should be independent of IPv6...
126 /* upper 4bit: PIM version number; 2 for PIMv2 */
127 /* lower 4bit: the PIM message type, currently they are:
128 * Hello, Register, Register-Stop, Join/Prune,
129 * Bootstrap, Assert, Graft (PIM-DM only),
130 * Graft-Ack (PIM-DM only), C-RP-Adv
132 #define PIM_VER(x) (((x) & 0xf0) >> 4)
133 #define PIM_TYPE(x) ((x) & 0x0f)
134 u_char pim_rsv
; /* Reserved */
135 u_short pim_cksum
; /* IP style check sum */
138 static void pimv2_print(netdissect_options
*, register const u_char
*bp
, register u_int len
, const u_char
*);
141 pimv1_join_prune_print(netdissect_options
*ndo
,
142 register const u_char
*bp
, register u_int len
)
144 int ngroups
, njoin
, nprune
;
147 /* If it's a single group and a single source, use 1-line output. */
148 if (ND_TTEST2(bp
[0], 30) && bp
[11] == 1 &&
149 ((njoin
= EXTRACT_16BITS(&bp
[20])) + EXTRACT_16BITS(&bp
[22])) == 1) {
152 ND_PRINT((ndo
, " RPF %s ", ipaddr_string(ndo
, bp
)));
153 hold
= EXTRACT_16BITS(&bp
[6]);
155 ND_PRINT((ndo
, "Hold "));
156 relts_print(ndo
, hold
);
158 ND_PRINT((ndo
, "%s (%s/%d, %s", njoin
? "Join" : "Prune",
159 ipaddr_string(ndo
, &bp
[26]), bp
[25] & 0x3f,
160 ipaddr_string(ndo
, &bp
[12])));
161 if (EXTRACT_32BITS(&bp
[16]) != 0xffffffff)
162 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[16])));
163 ND_PRINT((ndo
, ") %s%s %s",
164 (bp
[24] & 0x01) ? "Sparse" : "Dense",
165 (bp
[25] & 0x80) ? " WC" : "",
166 (bp
[25] & 0x40) ? "RP" : "SPT"));
170 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
171 if (ndo
->ndo_vflag
> 1)
172 ND_PRINT((ndo
, "\n"));
173 ND_PRINT((ndo
, " Upstream Nbr: %s", ipaddr_string(ndo
, bp
)));
174 ND_TCHECK2(bp
[6], 2);
175 if (ndo
->ndo_vflag
> 1)
176 ND_PRINT((ndo
, "\n"));
177 ND_PRINT((ndo
, " Hold time: "));
178 relts_print(ndo
, EXTRACT_16BITS(&bp
[6]));
179 if (ndo
->ndo_vflag
< 2)
184 ND_TCHECK2(bp
[0], 4);
190 * XXX - does the address have length "addrlen" and the
191 * mask length "maddrlen"?
193 ND_TCHECK2(bp
[0], sizeof(struct in_addr
));
194 ND_PRINT((ndo
, "\n\tGroup: %s", ipaddr_string(ndo
, bp
)));
195 ND_TCHECK2(bp
[4], sizeof(struct in_addr
));
196 if (EXTRACT_32BITS(&bp
[4]) != 0xffffffff)
197 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[4])));
198 ND_TCHECK2(bp
[8], 4);
199 njoin
= EXTRACT_16BITS(&bp
[8]);
200 nprune
= EXTRACT_16BITS(&bp
[10]);
201 ND_PRINT((ndo
, " joined: %d pruned: %d", njoin
, nprune
));
204 for (njp
= 0; njp
< (njoin
+ nprune
); njp
++) {
211 ND_TCHECK2(bp
[0], 6);
212 ND_PRINT((ndo
, "\n\t%s %s%s%s%s/%d", type
,
213 (bp
[0] & 0x01) ? "Sparse " : "Dense ",
214 (bp
[1] & 0x80) ? "WC " : "",
215 (bp
[1] & 0x40) ? "RP " : "SPT ",
216 ipaddr_string(ndo
, &bp
[2]), bp
[1] & 0x3f));
223 ND_PRINT((ndo
, "[|pim]"));
228 pimv1_print(netdissect_options
*ndo
,
229 register const u_char
*bp
, register u_int len
)
231 register const u_char
*ep
;
232 register u_char type
;
234 ep
= (const u_char
*)ndo
->ndo_snapend
;
241 ND_PRINT((ndo
, " %s", tok2str(pimv1_type_str
, "[type %u]", type
)));
243 case PIMV1_TYPE_QUERY
:
244 if (ND_TTEST(bp
[8])) {
245 switch (bp
[8] >> 4) {
247 ND_PRINT((ndo
, " Dense-mode"));
250 ND_PRINT((ndo
, " Sparse-mode"));
253 ND_PRINT((ndo
, " Sparse-Dense-mode"));
256 ND_PRINT((ndo
, " mode-%d", bp
[8] >> 4));
260 if (ndo
->ndo_vflag
) {
261 ND_TCHECK2(bp
[10],2);
262 ND_PRINT((ndo
, " (Hold-time "));
263 relts_print(ndo
, EXTRACT_16BITS(&bp
[10]));
264 ND_PRINT((ndo
, ")"));
268 case PIMV1_TYPE_REGISTER
:
269 ND_TCHECK2(bp
[8], 20); /* ip header */
270 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[20]),
271 ipaddr_string(ndo
, &bp
[24])));
273 case PIMV1_TYPE_REGISTER_STOP
:
274 ND_TCHECK2(bp
[12], sizeof(struct in_addr
));
275 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[8]),
276 ipaddr_string(ndo
, &bp
[12])));
278 case PIMV1_TYPE_RP_REACHABILITY
:
279 if (ndo
->ndo_vflag
) {
280 ND_TCHECK2(bp
[22], 2);
281 ND_PRINT((ndo
, " group %s", ipaddr_string(ndo
, &bp
[8])));
282 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
283 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
284 ND_PRINT((ndo
, " RP %s hold ", ipaddr_string(ndo
, &bp
[16])));
285 relts_print(ndo
, EXTRACT_16BITS(&bp
[22]));
288 case PIMV1_TYPE_ASSERT
:
289 ND_TCHECK2(bp
[16], sizeof(struct in_addr
));
290 ND_PRINT((ndo
, " for %s > %s", ipaddr_string(ndo
, &bp
[16]),
291 ipaddr_string(ndo
, &bp
[8])));
292 if (EXTRACT_32BITS(&bp
[12]) != 0xffffffff)
293 ND_PRINT((ndo
, "/%s", ipaddr_string(ndo
, &bp
[12])));
294 ND_TCHECK2(bp
[24], 4);
295 ND_PRINT((ndo
, " %s pref %d metric %d",
296 (bp
[20] & 0x80) ? "RP-tree" : "SPT",
297 EXTRACT_32BITS(&bp
[20]) & 0x7fffffff,
298 EXTRACT_32BITS(&bp
[24])));
300 case PIMV1_TYPE_JOIN_PRUNE
:
301 case PIMV1_TYPE_GRAFT
:
302 case PIMV1_TYPE_GRAFT_ACK
:
304 pimv1_join_prune_print(ndo
, &bp
[8], len
- 8);
307 if ((bp
[4] >> 4) != 1)
308 ND_PRINT((ndo
, " [v%d]", bp
[4] >> 4));
312 ND_PRINT((ndo
, "[|pim]"));
317 * auto-RP is a cisco protocol, documented at
318 * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt
320 * This implements version 1+, dated Sept 9, 1998.
323 cisco_autorp_print(netdissect_options
*ndo
,
324 register const u_char
*bp
, register u_int len
)
331 ND_PRINT((ndo
, " auto-rp "));
335 ND_PRINT((ndo
, "candidate-advert"));
338 ND_PRINT((ndo
, "mapping"));
341 ND_PRINT((ndo
, "type-0x%02x", type
));
348 ND_TCHECK2(bp
[2], 2);
349 ND_PRINT((ndo
, " Hold "));
350 hold
= EXTRACT_16BITS(&bp
[2]);
352 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
354 ND_PRINT((ndo
, "FOREVER"));
356 /* Next 4 bytes are reserved. */
360 /*XXX skip unless -v? */
364 * numrps entries of the form:
367 * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2".
368 * 8 bits: # of entries for this RP
369 * each entry: 7 bits: reserved, 1 bit: negative,
370 * 8 bits: mask 32 bits: source
371 * lather, rinse, repeat.
377 ND_TCHECK2(bp
[0], 4);
378 ND_PRINT((ndo
, " RP %s", ipaddr_string(ndo
, bp
)));
380 switch (bp
[4] & 0x3) {
381 case 0: ND_PRINT((ndo
, " PIMv?"));
383 case 1: ND_PRINT((ndo
, " PIMv1"));
385 case 2: ND_PRINT((ndo
, " PIMv2"));
387 case 3: ND_PRINT((ndo
, " PIMv1+2"));
391 ND_PRINT((ndo
, " [rsvd=0x%02x]", bp
[4] & 0xfc));
396 for (; nentries
; nentries
--) {
397 ND_TCHECK2(bp
[0], 6);
398 ND_PRINT((ndo
, "%c%s%s/%d", s
, bp
[0] & 1 ? "!" : "",
399 ipaddr_string(ndo
, &bp
[2]), bp
[1]));
401 ND_PRINT((ndo
, " bidir"));
404 ND_PRINT((ndo
, "[rsvd=0x%02x]", bp
[0] & 0xfc));
413 ND_PRINT((ndo
, "[|autorp]"));
418 pim_print(netdissect_options
*ndo
,
419 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
421 register const u_char
*ep
;
422 register const struct pim
*pim
= (const struct pim
*)bp
;
424 ep
= (const u_char
*)ndo
->ndo_snapend
;
427 #ifdef notyet /* currently we see only version and type */
428 ND_TCHECK(pim
->pim_rsv
);
431 switch (PIM_VER(pim
->pim_typever
)) {
433 if (!ndo
->ndo_vflag
) {
434 ND_PRINT((ndo
, "PIMv%u, %s, length %u",
435 PIM_VER(pim
->pim_typever
),
436 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
)),
440 ND_PRINT((ndo
, "PIMv%u, length %u\n\t%s",
441 PIM_VER(pim
->pim_typever
),
443 tok2str(pimv2_type_values
,"Unknown Type",PIM_TYPE(pim
->pim_typever
))));
444 pimv2_print(ndo
, bp
, len
, bp2
);
448 ND_PRINT((ndo
, "PIMv%u, length %u",
449 PIM_VER(pim
->pim_typever
),
457 * PIMv2 uses encoded address representations.
459 * The last PIM-SM I-D before RFC2117 was published specified the
460 * following representation for unicast addresses. However, RFC2117
461 * specified no encoding for unicast addresses with the unicast
462 * address length specified in the header. Therefore, we have to
463 * guess which encoding is being used (Cisco's PIMv2 implementation
464 * uses the non-RFC encoding). RFC2117 turns a previously "Reserved"
465 * field into a 'unicast-address-length-in-bytes' field. We guess
466 * that it's the draft encoding if this reserved field is zero.
468 * RFC2362 goes back to the encoded format, and calls the addr length
469 * field "reserved" again.
471 * The first byte is the address family, from:
474 * 1 IP (IP version 4)
475 * 2 IP6 (IP version 6)
477 * 4 HDLC (8-bit multidrop)
479 * 6 802 (includes all 802 media plus Ethernet "canonical format")
481 * 8 E.164 (SMDS, Frame Relay, ATM)
483 * 10 X.121 (X.25, Frame Relay)
488 * 15 E.164 with NSAP format subaddress
490 * In addition, the second byte is an "Encoding". 0 is the default
491 * encoding for the address family, and no other encodings are currently
496 static int pimv2_addr_len
;
498 enum pimv2_addrtype
{
499 pimv2_unicast
, pimv2_group
, pimv2_source
503 * 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
504 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
505 * | Addr Family | Encoding Type | Unicast Address |
506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++
508 * 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
509 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510 * | Addr Family | Encoding Type | Reserved | Mask Len |
511 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512 * | Group multicast Address |
513 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
515 * 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
516 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
523 pimv2_addr_print(netdissect_options
*ndo
,
524 const u_char
*bp
, enum pimv2_addrtype at
, int silent
)
531 if (pimv2_addr_len
== 0) {
536 len
= sizeof(struct in_addr
);
541 len
= sizeof(struct in6_addr
);
551 switch (pimv2_addr_len
) {
552 case sizeof(struct in_addr
):
556 case sizeof(struct in6_addr
):
564 len
= pimv2_addr_len
;
571 ND_TCHECK2(bp
[0], len
);
574 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
)));
577 else if (af
== AF_INET6
) {
579 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
)));
585 ND_TCHECK2(bp
[0], len
+ 2);
588 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, bp
+ 2)));
590 ND_PRINT((ndo
, "/%u", bp
[1]));
594 else if (af
== AF_INET6
) {
596 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, bp
+ 2)));
598 ND_PRINT((ndo
, "/%u", bp
[1]));
602 if (bp
[0] && !silent
) {
603 if (at
== pimv2_group
) {
604 ND_PRINT((ndo
, "(0x%02x)", bp
[0]));
606 ND_PRINT((ndo
, "(%s%s%s",
607 bp
[0] & 0x04 ? "S" : "",
608 bp
[0] & 0x02 ? "W" : "",
609 bp
[0] & 0x01 ? "R" : ""));
611 ND_PRINT((ndo
, "+0x%02x", bp
[0] & 0xf8));
613 ND_PRINT((ndo
, ")"));
616 return hdrlen
+ 2 + len
;
624 enum checksum_status
{
630 static enum checksum_status
631 pimv2_check_checksum(const u_char
*bp
, const u_char
*bp2
, u_int len
)
636 ip
= (const struct ip
*)bp2
;
638 struct cksum_vec vec
[1];
642 cksum
= in_cksum(vec
, 1);
643 return (cksum
? INCORRECT
: CORRECT
);
645 } else if (IP_V(ip
) == 6) {
646 const struct ip6_hdr
*ip6
;
648 ip6
= (const struct ip6_hdr
*)bp2
;
649 cksum
= nextproto6_cksum(ip6
, bp
, len
, len
, IPPROTO_PIM
);
650 return (cksum
? INCORRECT
: CORRECT
);
658 pimv2_print(netdissect_options
*ndo
,
659 register const u_char
*bp
, register u_int len
, const u_char
*bp2
)
661 register const u_char
*ep
;
662 register const struct pim
*pim
= (const struct pim
*)bp
;
664 enum checksum_status cksum_status
;
666 ep
= (const u_char
*)ndo
->ndo_snapend
;
671 ND_TCHECK(pim
->pim_rsv
);
672 pimv2_addr_len
= pim
->pim_rsv
;
673 if (pimv2_addr_len
!= 0)
674 ND_PRINT((ndo
, ", RFC2117-encoding"));
676 ND_PRINT((ndo
, ", cksum 0x%04x ", EXTRACT_16BITS(&pim
->pim_cksum
)));
677 if (EXTRACT_16BITS(&pim
->pim_cksum
) == 0) {
678 ND_PRINT((ndo
, "(unverified)"));
680 if (PIM_TYPE(pim
->pim_typever
) == PIMV2_TYPE_REGISTER
) {
682 * The checksum only covers the packet header,
683 * not the encapsulated packet.
685 cksum_status
= pimv2_check_checksum(bp
, bp2
, 8);
686 if (cksum_status
== INCORRECT
) {
688 * To quote RFC 4601, "For interoperability
689 * reasons, a message carrying a checksum
690 * calculated over the entire PIM Register
691 * message should also be accepted."
693 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
697 * The checksum covers the entire packet.
699 cksum_status
= pimv2_check_checksum(bp
, bp2
, len
);
701 switch (cksum_status
) {
704 ND_PRINT((ndo
, "(correct)"));
708 ND_PRINT((ndo
, "(incorrect)"));
712 ND_PRINT((ndo
, "(unverified)"));
717 switch (PIM_TYPE(pim
->pim_typever
)) {
718 case PIMV2_TYPE_HELLO
:
720 uint16_t otype
, olen
;
723 ND_TCHECK2(bp
[0], 4);
724 otype
= EXTRACT_16BITS(&bp
[0]);
725 olen
= EXTRACT_16BITS(&bp
[2]);
726 ND_TCHECK2(bp
[0], 4 + olen
);
727 ND_PRINT((ndo
, "\n\t %s Option (%u), length %u, Value: ",
728 tok2str(pimv2_hello_option_values
, "Unknown", otype
),
734 case PIMV2_HELLO_OPTION_HOLDTIME
:
735 relts_print(ndo
, EXTRACT_16BITS(bp
));
738 case PIMV2_HELLO_OPTION_LANPRUNEDELAY
:
740 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
743 uint16_t lan_delay
, override_interval
;
744 lan_delay
= EXTRACT_16BITS(bp
);
745 override_interval
= EXTRACT_16BITS(bp
+2);
746 t_bit
= (lan_delay
& 0x8000)? 1 : 0;
747 lan_delay
&= ~0x8000;
748 ND_PRINT((ndo
, "\n\t T-bit=%d, LAN delay %dms, Override interval %dms",
749 t_bit
, lan_delay
, override_interval
));
753 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD
:
754 case PIMV2_HELLO_OPTION_DR_PRIORITY
:
757 ND_PRINT((ndo
, "Bi-Directional Capability (Old)"));
760 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(bp
)));
763 ND_PRINT((ndo
, "ERROR: Option Length != 4 Bytes (%u)", olen
));
768 case PIMV2_HELLO_OPTION_GENID
:
769 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(bp
)));
772 case PIMV2_HELLO_OPTION_REFRESH_CAP
:
773 ND_PRINT((ndo
, "v%d", *bp
));
775 ND_PRINT((ndo
, ", interval "));
776 relts_print(ndo
, *(bp
+1));
778 if (EXTRACT_16BITS(bp
+2) != 0) {
779 ND_PRINT((ndo
, " ?0x%04x?", EXTRACT_16BITS(bp
+2)));
783 case PIMV2_HELLO_OPTION_BIDIR_CAP
:
786 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD
:
787 case PIMV2_HELLO_OPTION_ADDRESS_LIST
:
788 if (ndo
->ndo_vflag
> 1) {
789 const u_char
*ptr
= bp
;
790 while (ptr
< (bp
+olen
)) {
791 ND_PRINT((ndo
, "\n\t "));
792 advance
= pimv2_addr_print(ndo
, ptr
, pimv2_unicast
, 0);
794 ND_PRINT((ndo
, "..."));
802 if (ndo
->ndo_vflag
<= 1)
803 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
806 /* do we want to see an additionally hexdump ? */
807 if (ndo
->ndo_vflag
> 1)
808 print_unknown_data(ndo
, bp
, "\n\t ", olen
);
814 case PIMV2_TYPE_REGISTER
:
818 ND_TCHECK2(*(bp
+ 4), PIMV2_REGISTER_FLAG_LEN
);
820 ND_PRINT((ndo
, ", Flags [ %s ]\n\t",
821 tok2str(pimv2_register_flag_values
,
823 EXTRACT_32BITS(bp
+4))));
826 /* encapsulated multicast packet */
827 ip
= (const struct ip
*)bp
;
829 case 0: /* Null header */
830 ND_PRINT((ndo
, "IP-Null-header %s > %s",
831 ipaddr_string(ndo
, &ip
->ip_src
),
832 ipaddr_string(ndo
, &ip
->ip_dst
)));
836 ip_print(ndo
, bp
, len
);
840 ip6_print(ndo
, bp
, len
);
844 ND_PRINT((ndo
, "IP ver %d", IP_V(ip
)));
850 case PIMV2_TYPE_REGISTER_STOP
:
854 ND_PRINT((ndo
, " group="));
855 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
856 ND_PRINT((ndo
, "..."));
859 bp
+= advance
; len
-= advance
;
862 ND_PRINT((ndo
, " source="));
863 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
864 ND_PRINT((ndo
, "..."));
867 bp
+= advance
; len
-= advance
;
870 case PIMV2_TYPE_JOIN_PRUNE
:
871 case PIMV2_TYPE_GRAFT
:
872 case PIMV2_TYPE_GRAFT_ACK
:
877 * 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
878 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
879 * |PIM Ver| Type | Addr length | Checksum |
880 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
881 * | Unicast-Upstream Neighbor Address |
882 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
883 * | Reserved | Num groups | Holdtime |
884 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
885 * | Encoded-Multicast Group Address-1 |
886 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
887 * | Number of Joined Sources | Number of Pruned Sources |
888 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
889 * | Encoded-Joined Source Address-1 |
890 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
894 * | Encoded-Joined Source Address-n |
895 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
896 * | Encoded-Pruned Source Address-1 |
897 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
900 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
901 * | Encoded-Pruned Source Address-n |
902 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
905 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
906 * | Encoded-Multicast Group Address-n |
907 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
918 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
921 ND_PRINT((ndo
, ", upstream-neighbor: "));
922 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
923 ND_PRINT((ndo
, "..."));
926 bp
+= advance
; len
-= advance
;
931 holdtime
= EXTRACT_16BITS(&bp
[2]);
932 ND_PRINT((ndo
, "\n\t %u group(s)", ngroup
));
933 if (PIM_TYPE(pim
->pim_typever
) != 7) { /*not for Graft-ACK*/
934 ND_PRINT((ndo
, ", holdtime: "));
935 if (holdtime
== 0xffff)
936 ND_PRINT((ndo
, "infinite"));
938 relts_print(ndo
, holdtime
);
941 for (i
= 0; i
< ngroup
; i
++) {
944 ND_PRINT((ndo
, "\n\t group #%u: ", i
+1));
945 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
946 ND_PRINT((ndo
, "...)"));
949 bp
+= advance
; len
-= advance
;
951 ND_PRINT((ndo
, "...)"));
954 njoin
= EXTRACT_16BITS(&bp
[0]);
955 nprune
= EXTRACT_16BITS(&bp
[2]);
956 ND_PRINT((ndo
, ", joined sources: %u, pruned sources: %u", njoin
, nprune
));
958 for (j
= 0; j
< njoin
; j
++) {
959 ND_PRINT((ndo
, "\n\t joined source #%u: ", j
+1));
960 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
961 ND_PRINT((ndo
, "...)"));
964 bp
+= advance
; len
-= advance
;
966 for (j
= 0; j
< nprune
; j
++) {
967 ND_PRINT((ndo
, "\n\t pruned source #%u: ", j
+1));
968 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_source
, 0)) < 0) {
969 ND_PRINT((ndo
, "...)"));
972 bp
+= advance
; len
-= advance
;
979 case PIMV2_TYPE_BOOTSTRAP
:
984 /* Fragment Tag, Hash Mask len, and BSR-priority */
985 if (bp
+ sizeof(uint16_t) >= ep
) break;
986 ND_PRINT((ndo
, " tag=%x", EXTRACT_16BITS(bp
)));
987 bp
+= sizeof(uint16_t);
989 ND_PRINT((ndo
, " hashmlen=%d", bp
[0]));
990 if (bp
+ 1 >= ep
) break;
991 ND_PRINT((ndo
, " BSRprio=%d", bp
[1]));
994 /* Encoded-Unicast-BSR-Address */
996 ND_PRINT((ndo
, " BSR="));
997 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
998 ND_PRINT((ndo
, "..."));
1003 for (i
= 0; bp
< ep
; i
++) {
1004 /* Encoded-Group Address */
1005 ND_PRINT((ndo
, " (group%d: ", i
));
1006 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1008 ND_PRINT((ndo
, "...)"));
1013 /* RP-Count, Frag RP-Cnt, and rsvd */
1015 ND_PRINT((ndo
, "...)"));
1018 ND_PRINT((ndo
, " RPcnt=%d", bp
[0]));
1020 ND_PRINT((ndo
, "...)"));
1023 ND_PRINT((ndo
, " FRPcnt=%d", frpcnt
= bp
[1]));
1026 for (j
= 0; j
< frpcnt
&& bp
< ep
; j
++) {
1028 ND_PRINT((ndo
, " RP%d=", j
));
1029 if ((advance
= pimv2_addr_print(ndo
, bp
,
1032 ND_PRINT((ndo
, "...)"));
1038 ND_PRINT((ndo
, "...)"));
1041 ND_PRINT((ndo
, ",holdtime="));
1042 relts_print(ndo
, EXTRACT_16BITS(bp
));
1044 ND_PRINT((ndo
, "...)"));
1047 ND_PRINT((ndo
, ",prio=%d", bp
[2]));
1050 ND_PRINT((ndo
, ")"));
1055 case PIMV2_TYPE_ASSERT
:
1059 ND_PRINT((ndo
, " group="));
1060 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1061 ND_PRINT((ndo
, "..."));
1064 bp
+= advance
; len
-= advance
;
1067 ND_PRINT((ndo
, " src="));
1068 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1069 ND_PRINT((ndo
, "..."));
1072 bp
+= advance
; len
-= advance
;
1076 ND_PRINT((ndo
, " RPT"));
1077 ND_PRINT((ndo
, " pref=%u", EXTRACT_32BITS(&bp
[0]) & 0x7fffffff));
1078 ND_PRINT((ndo
, " metric=%u", EXTRACT_32BITS(&bp
[4])));
1081 case PIMV2_TYPE_CANDIDATE_RP
:
1086 /* Prefix-Cnt, Priority, and Holdtime */
1087 if (bp
>= ep
) break;
1088 ND_PRINT((ndo
, " prefix-cnt=%d", bp
[0]));
1090 if (bp
+ 1 >= ep
) break;
1091 ND_PRINT((ndo
, " prio=%d", bp
[1]));
1092 if (bp
+ 3 >= ep
) break;
1093 ND_PRINT((ndo
, " holdtime="));
1094 relts_print(ndo
, EXTRACT_16BITS(&bp
[2]));
1097 /* Encoded-Unicast-RP-Address */
1098 if (bp
>= ep
) break;
1099 ND_PRINT((ndo
, " RP="));
1100 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1101 ND_PRINT((ndo
, "..."));
1106 /* Encoded-Group Addresses */
1107 for (i
= 0; i
< pfxcnt
&& bp
< ep
; i
++) {
1108 ND_PRINT((ndo
, " Group%d=", i
));
1109 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0))
1111 ND_PRINT((ndo
, "..."));
1119 case PIMV2_TYPE_PRUNE_REFRESH
:
1120 ND_PRINT((ndo
, " src="));
1121 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1122 ND_PRINT((ndo
, "..."));
1126 ND_PRINT((ndo
, " grp="));
1127 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_group
, 0)) < 0) {
1128 ND_PRINT((ndo
, "..."));
1132 ND_PRINT((ndo
, " forwarder="));
1133 if ((advance
= pimv2_addr_print(ndo
, bp
, pimv2_unicast
, 0)) < 0) {
1134 ND_PRINT((ndo
, "..."));
1138 ND_TCHECK2(bp
[0], 2);
1139 ND_PRINT((ndo
, " TUNR "));
1140 relts_print(ndo
, EXTRACT_16BITS(bp
));
1145 ND_PRINT((ndo
, " [type %d]", PIM_TYPE(pim
->pim_typever
)));
1152 ND_PRINT((ndo
, "[|pim]"));
1157 * c-style: whitesmith