2 * Routines for PIM disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
5 * $Id: packet-pim.c,v 1.39 2002/02/01 07:06:32 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
38 #include <stddef.h> /* For offsetof */
42 #ifdef NEED_SNPRINTF_H
43 # include "snprintf.h"
46 #include <epan/packet.h>
49 #include "packet-ipv6.h"
52 #define PIM_TYPE(x) ((x) & 0x0f)
53 #define PIM_VER(x) (((x) & 0xf0) >> 4)
56 pimv2_unicast, pimv2_group, pimv2_source
59 static int proto_pim = -1;
60 static int hf_pim_version = -1;
61 static int hf_pim_type = -1;
62 static int hf_pim_code = -1;
63 static int hf_pim_cksum = -1;
65 static gint ett_pim = -1;
67 static dissector_handle_t ip_handle;
68 static dissector_handle_t ipv6_handle;
71 * For PIM v1, see the PDF slides at
73 * http://www.mbone.de/training/Module3.pdf
75 * Is it documented anywhere else?
78 dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
80 guint16 flags_masklen;
82 flags_masklen = tvb_get_ntohs(tvb, offset);
83 if (flags_masklen & 0x0180) {
84 (void)snprintf(buf, sizeof(buf),
86 flags_masklen & 0x0100 ? "S" : "",
87 flags_masklen & 0x0080 ? "W" : "",
88 flags_masklen & 0x0040 ? "R" : "");
91 (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s/%u",
92 ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)), flags_masklen & 0x3f);
97 static const value_string type1vals[] = {
100 { 2, "Register-stop" },
102 { 4, "RP-Reachable" },
110 /* This function is only called from the IGMP dissector */
112 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
116 guint length, pim_length;
117 guint16 pim_cksum, computed_cksum;
119 proto_tree *pim_tree = NULL;
121 proto_tree *pimopt_tree = NULL;
124 if (!proto_is_protocol_enabled(proto_pim)) {
126 * We are not enabled; skip entire packet to be nice to the
127 * IGMP layer (so clicking on IGMP will display the data).
129 return offset+tvb_length_remaining(tvb, offset);
132 if (check_col(pinfo->cinfo, COL_PROTOCOL))
133 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
134 if (check_col(pinfo->cinfo, COL_INFO))
135 col_clear(pinfo->cinfo, COL_INFO);
138 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
139 pim_tree = proto_item_add_subtree(ti, ett_pim);
141 /* Put IGMP type, 0x14, into the tree */
142 proto_tree_add_text(pim_tree, tvb, offset, 1,
147 pim_type = tvb_get_guint8(tvb, offset);
148 if (check_col(pinfo->cinfo, COL_INFO))
149 col_add_str(pinfo->cinfo, COL_INFO,
150 val_to_str(pim_type, type1vals, "Unknown (%u)"));
153 proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
157 pim_cksum = tvb_get_ntohs(tvb, offset);
158 pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
161 * Not PIMv1 - what gives?
164 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
165 offset, 2, pim_cksum);
169 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
170 return offset+tvb_length_remaining(tvb, offset);
174 * Well, it's PIM v1, so we can check whether this is a
175 * Register message, and thus can figure out how much to
176 * checksum and whether to make the columns read-only.
178 length = tvb_length(tvb);
181 * Register message - the PIM header is 8 bytes long.
182 * Also set the columns non-writable. Otherwise the IPv4 or
183 * IPv6 dissector for the encapsulated packet that caused
184 * this register will overwrite the PIM info in the columns.
187 col_set_writable(pinfo->cinfo, FALSE);
190 * Other message - checksum the entire packet.
192 pim_length = tvb_reported_length(tvb);
196 if (!pinfo->fragmented && length >= pim_length) {
198 * The packet isn't part of a fragmented datagram and isn't
199 * truncated, so we can checksum it.
201 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
202 cksum_vec[0].len = pim_length;
203 computed_cksum = in_cksum(&cksum_vec[0], 1);
204 if (computed_cksum == 0) {
205 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
206 offset, 2, pim_cksum,
207 "Checksum: 0x%04x (correct)",
210 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
211 offset, 2, pim_cksum,
212 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
213 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
216 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
217 offset, 2, pim_cksum);
223 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
226 offset += 3; /* skip reserved stuff */
229 if (tvb_reported_length_remaining(tvb, offset) > 0) {
230 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
232 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
236 /* version 1 decoder */
242 static const value_string pimv1_modevals[] = {
245 { 2, "Sparse-Dense" },
249 mode = tvb_get_guint8(tvb, offset) >> 4;
250 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
252 val_to_str(mode, pimv1_modevals, "Unknown (%u)"));
254 holdtime = tvb_get_ntohs(tvb, offset);
255 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
256 "Holdtime: %u%s", holdtime,
257 holdtime == 0xffff ? " (infty)" : "");
262 case 1: /* register */
268 * The rest of the packet is a multicast data packet.
270 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
273 * It's an IP packet - determine whether it's IPv4 or IPv6.
275 v_hl = tvb_get_guint8(tvb, offset);
276 switch((v_hl & 0xf0) >> 4) {
277 case 0: /* Null-Register dummy header.
278 * Has the same address family as the encapsulating PIM packet,
279 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
281 if (pinfo->src.type == AT_IPv4) {
282 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
283 "IPv4 dummy header");
284 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
286 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
287 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
289 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
290 } else if (pinfo->src.type == AT_IPv6) {
291 struct ip6_hdr ip6_hdr;
292 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
294 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
295 "IPv6 dummy header");
296 proto_tree_add_text(pimopt_tree, tvb,
297 offset + offsetof(struct ip6_hdr, ip6_src), 16,
299 ip6_to_str(&ip6_hdr.ip6_src));
300 proto_tree_add_text(pimopt_tree, tvb,
301 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
303 ip6_to_str(&ip6_hdr.ip6_dst));
305 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
306 "Dummy header for an unknown protocol");
310 call_dissector(ip_handle, next_tvb, pinfo, tree);
312 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
317 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
319 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
323 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
324 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
330 case 2: /* register-stop */
332 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
334 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
336 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
338 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
343 case 3: /* join/prune */
345 case 7: /* graft-ack */
349 int ngroup, i, njoin, nprune, j;
353 proto_tree *grouptree = NULL;
355 proto_tree *subtree = NULL;
358 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
359 "Upstream-neighbor: %s",
360 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
363 offset += 2; /* skip reserved stuff */
365 holdtime = tvb_get_ntohs(tvb, offset);
366 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
367 "Holdtime: %u%s", holdtime,
368 holdtime == 0xffff ? " (infty)" : "");
371 offset += 1; /* skip reserved stuff */
373 mask_len = tvb_get_guint8(tvb, offset);
374 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
375 "Mask length: %u", mask_len);
378 adr_len = tvb_get_guint8(tvb, offset);
379 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
380 "Address length: %u", adr_len);
383 ngroup = tvb_get_guint8(tvb, offset);
384 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
385 "Groups: %u", ngroup);
388 for (i = 0; i < ngroup; i++) {
389 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
391 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
392 grouptree = proto_item_add_subtree(tigroup, ett_pim);
395 proto_tree_add_text(grouptree, tvb, offset, 4,
396 "Group %d Mask: %s", i,
397 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
400 njoin = tvb_get_ntohs(tvb, offset);
401 nprune = tvb_get_ntohs(tvb, offset + 2);
403 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
405 subtree = proto_item_add_subtree(tisub, ett_pim);
407 for (j = 0; j < njoin; j++) {
408 s = dissect_pimv1_addr(tvb, off);
409 proto_tree_add_text(subtree, tvb, off, 6,
410 "IP address: %s", s);
414 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
415 "Prune: %d", nprune);
416 subtree = proto_item_add_subtree(tisub, ett_pim);
417 for (j = 0; j < nprune; j++) {
418 s = dissect_pimv1_addr(tvb, off);
419 proto_tree_add_text(subtree, tvb, off, 6,
420 "IP address: %s", s);
427 case 4: /* rp-reachability */
431 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
433 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
436 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
438 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
441 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
443 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
446 offset += 2; /* skip reserved stuff */
448 holdtime = tvb_get_ntohs(tvb, offset);
449 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
450 "Holdtime: %u%s", holdtime,
451 holdtime == 0xffff ? " (infty)" : "");
458 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
460 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
463 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
465 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
468 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
469 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
470 "RP Tree", "Not RP Tree"));
471 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
472 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
475 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
476 tvb_get_ntohl(tvb, offset));
487 return offset+tvb_length_remaining(tvb, offset);
491 dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
493 static char buf[512];
500 af = tvb_get_guint8(tvb, offset);
501 if (af != AFNUM_INET && af != AFNUM_INET6) {
503 * We don't handle the other formats, and addresses don't include
504 * a length field, so we can't even show them as raw bytes.
509 et = tvb_get_guint8(tvb, offset + 1);
512 * The only defined encoding type is 0, for the native encoding;
513 * again, as addresses don't include a length field, we can't
514 * even show addresses with a different encoding type as raw
525 (void)snprintf(buf, sizeof(buf), "%s",
526 ip_to_str(tvb_get_ptr(tvb, offset + 2, len)));
531 (void)snprintf(buf, sizeof(buf), "%s",
532 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 2, len)));
540 mask_len = tvb_get_guint8(tvb, offset + 3);
544 (void)snprintf(buf, sizeof(buf), "%s/%u",
545 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
550 (void)snprintf(buf, sizeof(buf), "%s/%u",
551 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
559 flags = tvb_get_guint8(tvb, offset + 2);
560 mask_len = tvb_get_guint8(tvb, offset + 3);
564 (void)snprintf(buf, sizeof(buf), "%s/%u",
565 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
570 (void)snprintf(buf, sizeof(buf), "%s/%u",
571 ip6_to_str((struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
575 (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
577 flags & 0x04 ? "S" : "",
578 flags & 0x02 ? "W" : "",
579 flags & 0x01 ? "R" : "");
591 static const value_string type2vals[] = {
594 { 2, "Register-stop" },
600 { 8, "Candidate-RP-Advertisement" },
605 * For PIM v2, see RFC 2362, and draft-ietf-pim-sm-v2-new-03 (when PIM
606 * is run over IPv6, the rules for computing the PIM checksum from the
607 * draft in question, not from RFC 2362, should be used).
610 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
613 guint length, pim_length;
614 guint16 pim_cksum, computed_cksum;
618 proto_tree *pim_tree = NULL;
620 proto_tree *pimopt_tree = NULL;
623 if (check_col(pinfo->cinfo, COL_PROTOCOL))
624 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
625 if (check_col(pinfo->cinfo, COL_INFO))
626 col_clear(pinfo->cinfo, COL_INFO);
628 pim_typever = tvb_get_guint8(tvb, 0);
630 switch (PIM_VER(pim_typever)) {
632 typestr = val_to_str(PIM_TYPE(pim_typever), type2vals, "Unknown (%u)");
634 case 1: /* PIMv1 - we should never see this */
640 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
641 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
642 PIM_VER(pim_typever));
644 if (check_col(pinfo->cinfo, COL_INFO))
645 col_add_str(pinfo->cinfo, COL_INFO, typestr);
648 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
649 pim_tree = proto_item_add_subtree(ti, ett_pim);
651 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1,
652 PIM_VER(pim_typever));
653 proto_tree_add_uint(pim_tree, hf_pim_type, tvb, offset, 1,
654 PIM_TYPE(pim_typever));
656 pim_cksum = tvb_get_ntohs(tvb, offset + 2);
657 length = tvb_length(tvb);
658 if (PIM_VER(pim_typever) == 2) {
660 * Well, it's PIM v2, so we can check whether this is a Register
661 * message, and thus can figure out how much to checksum and
662 * whether to make the columns read-only.
664 if (PIM_TYPE(pim_typever) == 1) {
666 * Register message - the PIM header is 8 bytes long.
667 * Also set the columns non-writable. Otherwise the IPv4 or
668 * IPv6 dissector for the encapsulated packet that caused
669 * this register will overwrite the PIM info in the columns.
672 col_set_writable(pinfo->cinfo, FALSE);
675 * Other message - checksum the entire packet.
677 pim_length = tvb_reported_length(tvb);
681 * We don't know what type of message this is, so say that
682 * the length is 0, to force it not to be checksummed.
686 if (!pinfo->fragmented && length >= pim_length) {
688 * The packet isn't part of a fragmented datagram and isn't
689 * truncated, so we can checksum it.
692 switch (pinfo->src.type) {
694 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
695 cksum_vec[0].len = pim_length;
696 computed_cksum = in_cksum(&cksum_vec[0], 1);
699 /* Set up the fields of the pseudo-header. */
700 cksum_vec[0].ptr = pinfo->src.data;
701 cksum_vec[0].len = pinfo->src.len;
702 cksum_vec[1].ptr = pinfo->dst.data;
703 cksum_vec[1].len = pinfo->dst.len;
704 cksum_vec[2].ptr = (const guint8 *)&phdr;
705 phdr[0] = htonl(pim_length);
706 phdr[1] = htonl(IP_PROTO_PIM);
707 cksum_vec[2].len = 8;
708 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, pim_length);
709 cksum_vec[3].len = pim_length;
710 computed_cksum = in_cksum(&cksum_vec[0], 4);
713 /* PIM is available for IPv4 and IPv6 right now */
714 computed_cksum = 0; /* squelch GCC complaints */
715 g_assert_not_reached();
719 if (computed_cksum == 0) {
720 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
721 offset + 2, 2, pim_cksum,
722 "Checksum: 0x%04x (correct)",
725 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
726 offset + 2, 2, pim_cksum,
727 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
728 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
731 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
732 offset + 2, 2, pim_cksum);
737 if (tvb_reported_length_remaining(tvb, offset) > 0) {
738 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
740 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
744 if (PIM_VER(pim_typever) != 2)
747 /* version 2 decoder */
748 switch (PIM_TYPE(pim_typever)) {
751 while (tvb_reported_length_remaining(tvb, offset) >= 2) {
752 if (tvb_get_ntohs(tvb, offset) == 1 &&
753 tvb_get_ntohs(tvb, offset + 2) == 2) {
756 holdtime = tvb_get_ntohs(tvb, offset + 4);
757 proto_tree_add_text(pimopt_tree, tvb, offset, 6,
758 "Holdtime: %u%s", holdtime,
759 holdtime == 0xffff ? " (infty)" : "");
767 case 1: /* register */
772 proto_tree *flag_tree = NULL;
775 flags = tvb_get_ntohl(tvb, offset);
776 tiflag = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
777 "Flags: 0x%08x", flags);
778 flag_tree = proto_item_add_subtree(tiflag, ett_pim);
779 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
780 decode_boolean_bitfield(flags, 0x80000000, 32,
781 "Border", "Not border"));
782 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
783 decode_boolean_bitfield(flags, 0x40000000, 32,
784 "Null-Register", "Not Null-Register"));
788 * The rest of the packet is a multicast data packet.
790 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
793 * It's an IP packet - determine whether it's IPv4 or IPv6.
795 v_hl = tvb_get_guint8(tvb, offset);
796 switch((v_hl & 0xf0) >> 4) {
797 case 0: /* Null-Register dummy header.
798 * Has the same address family as the encapsulating PIM packet,
799 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
801 if (pinfo->src.type == AT_IPv4) {
802 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
803 "IPv4 dummy header");
804 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
806 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
807 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
809 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
810 } else if (pinfo->src.type == AT_IPv6) {
811 struct ip6_hdr ip6_hdr;
812 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
814 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
815 "IPv6 dummy header");
816 proto_tree_add_text(pimopt_tree, tvb,
817 offset + offsetof(struct ip6_hdr, ip6_src), 16,
819 ip6_to_str(&ip6_hdr.ip6_src));
820 proto_tree_add_text(pimopt_tree, tvb,
821 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
823 ip6_to_str(&ip6_hdr.ip6_dst));
825 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
826 "Dummy header for an unknown protocol");
830 call_dissector(ip_handle, next_tvb, pinfo, tree);
832 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
837 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
839 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
843 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
844 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
850 case 2: /* register-stop */
855 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
858 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
860 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
863 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
867 case 3: /* join/prune */
869 case 7: /* graft-ack */
874 int ngroup, i, njoin, nprune, j;
876 proto_tree *grouptree = NULL;
878 proto_tree *subtree = NULL;
881 if (PIM_TYPE(pim_typever) != 7) {
883 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
886 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
887 "Upstream-neighbor: %s", s);
891 offset += 1; /* skip reserved field */
893 ngroup = tvb_get_guint8(tvb, offset);
894 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
895 "Groups: %u", ngroup);
898 if (PIM_TYPE(pim_typever) != 7) {
900 holdtime = tvb_get_ntohs(tvb, offset);
901 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
902 "Holdtime: %u%s", holdtime,
903 holdtime == 0xffff ? " (infty)" : "");
907 for (i = 0; i < ngroup; i++) {
908 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
911 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
912 "Group %d: %s", i, s);
913 grouptree = proto_item_add_subtree(tigroup, ett_pim);
916 njoin = tvb_get_ntohs(tvb, offset);
917 nprune = tvb_get_ntohs(tvb, offset + 2);
919 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
921 subtree = proto_item_add_subtree(tisub, ett_pim);
923 for (j = 0; j < njoin; j++) {
924 s = dissect_pim_addr(tvb, off, pimv2_source,
928 proto_tree_add_text(subtree, tvb, off, advance,
929 "IP address: %s", s);
933 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
934 "Prune: %d", nprune);
935 subtree = proto_item_add_subtree(tisub, ett_pim);
936 for (j = 0; j < nprune; j++) {
937 s = dissect_pim_addr(tvb, off, pimv2_source,
941 proto_tree_add_text(subtree, tvb, off, advance,
942 "IP address: %s", s);
950 case 4: /* bootstrap */
957 proto_tree *grouptree = NULL;
960 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
961 "Fragment tag: 0x%04x", tvb_get_ntohs(tvb, offset));
964 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
965 "Hash mask len: %u", tvb_get_guint8(tvb, offset));
967 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
968 "BSR priority: %u", tvb_get_guint8(tvb, offset));
971 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
974 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "BSR: %s", s);
977 for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
978 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
981 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
982 "Group %d: %s", i, s);
983 grouptree = proto_item_add_subtree(tigroup, ett_pim);
986 proto_tree_add_text(grouptree, tvb, offset, 1,
987 "RP count: %u", tvb_get_guint8(tvb, offset));
989 frpcnt = tvb_get_guint8(tvb, offset);
990 proto_tree_add_text(grouptree, tvb, offset, 1,
991 "FRP count: %u", frpcnt);
994 for (j = 0; j < frpcnt; j++) {
995 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
998 proto_tree_add_text(grouptree, tvb, offset, advance,
1002 holdtime = tvb_get_ntohs(tvb, offset);
1003 proto_tree_add_text(grouptree, tvb, offset, 2,
1004 "Holdtime: %u%s", holdtime,
1005 holdtime == 0xffff ? " (infty)" : "");
1007 proto_tree_add_text(grouptree, tvb, offset, 1,
1008 "Priority: %u", tvb_get_guint8(tvb, offset));
1009 offset += 2; /* also skips reserved field */
1017 case 5: /* assert */
1022 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1025 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
1028 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1031 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
1034 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
1035 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
1036 "RP Tree", "Not RP Tree"));
1037 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
1038 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
1041 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
1042 tvb_get_ntohl(tvb, offset));
1047 case 8: /* Candidate-RP-Advertisement */
1055 pfxcnt = tvb_get_guint8(tvb, offset);
1056 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1057 "Prefix-count: %u", pfxcnt);
1059 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1060 "Priority: %u", tvb_get_guint8(tvb, offset));
1062 holdtime = tvb_get_ntohs(tvb, offset);
1063 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1064 "Holdtime: %u%s", holdtime,
1065 holdtime == 0xffff ? " (infty)" : "");
1068 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1071 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "RP: %s", s);
1074 for (i = 0; i < pfxcnt; i++) {
1075 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1078 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1079 "Group %d: %s", i, s);
1094 proto_register_pim(void)
1096 static hf_register_info hf[] = {
1098 { "Version", "pim.version",
1099 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
1101 { "Type", "pim.type",
1102 FT_UINT8, BASE_DEC, VALS(type2vals), 0x0, "", HFILL }},
1104 { "Code", "pim.code",
1105 FT_UINT8, BASE_DEC, VALS(type1vals), 0x0, "", HFILL }},
1107 { "Checksum", "pim.cksum",
1108 FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
1110 static gint *ett[] = {
1114 proto_pim = proto_register_protocol("Protocol Independent Multicast",
1116 proto_register_field_array(proto_pim, hf, array_length(hf));
1117 proto_register_subtree_array(ett, array_length(ett));
1121 proto_reg_handoff_pim(void)
1123 dissector_handle_t pim_handle;
1125 pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1126 dissector_add("ip.proto", IP_PROTO_PIM, pim_handle);
1129 * Get handles for the IPv4 and IPv6 dissectors.
1131 ip_handle = find_dissector("ip");
1132 ipv6_handle = find_dissector("ipv6");