2 * Routines for PIM disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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 #include <stddef.h> /* For offsetof */
34 #include <epan/packet.h>
35 #include <epan/emem.h>
36 #include <epan/ipproto.h>
38 #include "packet-ipv6.h"
39 #include <epan/in_cksum.h>
40 #include "packet-pim.h"
42 #define PIM_TYPE(x) ((x) & 0x0f)
43 #define PIM_VER(x) (((x) & 0xf0) >> 4)
46 pimv2_unicast, pimv2_group, pimv2_source
49 static int proto_pim = -1;
50 static int hf_pim_version = -1;
51 static int hf_pim_type = -1;
52 static int hf_pim_code = -1;
53 static int hf_pim_cksum = -1;
55 static gint ett_pim = -1;
57 static dissector_handle_t ip_handle;
58 static dissector_handle_t ipv6_handle;
61 * For PIM v1, see the PDF slides at
63 * http://www.mbone.de/training/Module3.pdf
65 * Is it documented anywhere else?
68 dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
70 guint16 flags_masklen;
72 flags_masklen = tvb_get_ntohs(tvb, offset);
73 if (flags_masklen & 0x0180) {
74 g_snprintf(buf, sizeof(buf),
76 flags_masklen & 0x0100 ? "S" : "",
77 flags_masklen & 0x0080 ? "W" : "",
78 flags_masklen & 0x0040 ? "R" : "");
81 g_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s/%u",
82 ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)), flags_masklen & 0x3f);
87 static const value_string type1vals[] = {
90 { 2, "Register-stop" },
92 { 4, "RP-Reachable" },
100 /* This function is only called from the IGMP dissector */
102 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
106 guint length, pim_length;
107 guint16 pim_cksum, computed_cksum;
109 proto_tree *pim_tree = NULL;
111 proto_tree *pimopt_tree = NULL;
114 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_pim))) {
116 * We are not enabled; skip entire packet to be nice to the
117 * IGMP layer (so clicking on IGMP will display the data).
119 return offset+tvb_length_remaining(tvb, offset);
122 if (check_col(pinfo->cinfo, COL_PROTOCOL))
123 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
124 if (check_col(pinfo->cinfo, COL_INFO))
125 col_clear(pinfo->cinfo, COL_INFO);
128 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
129 pim_tree = proto_item_add_subtree(ti, ett_pim);
131 /* Put IGMP type, 0x14, into the tree */
132 proto_tree_add_text(pim_tree, tvb, offset, 1,
137 pim_type = tvb_get_guint8(tvb, offset);
138 if (check_col(pinfo->cinfo, COL_INFO))
139 col_add_str(pinfo->cinfo, COL_INFO,
140 val_to_str(pim_type, type1vals, "Unknown (%u)"));
143 proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
147 pim_cksum = tvb_get_ntohs(tvb, offset);
148 pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
151 * Not PIMv1 - what gives?
154 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
155 offset, 2, pim_cksum);
159 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
160 return offset+tvb_length_remaining(tvb, offset);
164 * Well, it's PIM v1, so we can check whether this is a
165 * Register message, and thus can figure out how much to
166 * checksum and whether to make the columns read-only.
168 length = tvb_length(tvb);
171 * Register message - the PIM header is 8 bytes long.
172 * Also set the columns non-writable. Otherwise the IPv4 or
173 * IPv6 dissector for the encapsulated packet that caused
174 * this register will overwrite the PIM info in the columns.
177 col_set_writable(pinfo->cinfo, FALSE);
180 * Other message - checksum the entire packet.
182 pim_length = tvb_reported_length(tvb);
186 if (!pinfo->fragmented && length >= pim_length) {
188 * The packet isn't part of a fragmented datagram and isn't
189 * truncated, so we can checksum it.
191 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
192 cksum_vec[0].len = pim_length;
193 computed_cksum = in_cksum(&cksum_vec[0], 1);
194 if (computed_cksum == 0) {
195 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
196 offset, 2, pim_cksum,
197 "Checksum: 0x%04x [correct]",
200 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
201 offset, 2, pim_cksum,
202 "Checksum: 0x%04x [incorrect, should be 0x%04x]",
203 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
206 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
207 offset, 2, pim_cksum);
213 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
216 offset += 3; /* skip reserved stuff */
219 if (tvb_reported_length_remaining(tvb, offset) > 0) {
220 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
222 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
226 /* version 1 decoder */
232 static const value_string pimv1_modevals[] = {
235 { 2, "Sparse-Dense" },
239 mode = tvb_get_guint8(tvb, offset) >> 4;
240 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
242 val_to_str(mode, pimv1_modevals, "Unknown (%u)"));
244 holdtime = tvb_get_ntohs(tvb, offset);
245 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
246 "Holdtime: %u%s", holdtime,
247 holdtime == 0xffff ? " (infty)" : "");
252 case 1: /* register */
258 * The rest of the packet is a multicast data packet.
260 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
263 * It's an IP packet - determine whether it's IPv4 or IPv6.
265 v_hl = tvb_get_guint8(tvb, offset);
266 switch((v_hl & 0xf0) >> 4) {
267 case 0: /* Null-Register dummy header.
268 * Has the same address family as the encapsulating PIM packet,
269 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
271 if (pinfo->src.type == AT_IPv4) {
272 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
273 "IPv4 dummy header");
274 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
276 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
277 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
279 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
280 } else if (pinfo->src.type == AT_IPv6) {
281 struct ip6_hdr ip6_hdr;
282 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
284 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
285 "IPv6 dummy header");
286 proto_tree_add_text(pimopt_tree, tvb,
287 offset + offsetof(struct ip6_hdr, ip6_src), 16,
289 ip6_to_str(&ip6_hdr.ip6_src));
290 proto_tree_add_text(pimopt_tree, tvb,
291 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
293 ip6_to_str(&ip6_hdr.ip6_dst));
295 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
296 "Dummy header for an unknown protocol");
300 call_dissector(ip_handle, next_tvb, pinfo, tree);
302 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
307 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
309 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
313 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
314 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
320 case 2: /* register-stop */
322 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
324 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
326 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
328 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
333 case 3: /* join/prune */
335 case 7: /* graft-ack */
339 int ngroup, i, njoin, nprune, j;
343 proto_tree *grouptree = NULL;
345 proto_tree *subtree = NULL;
348 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
349 "Upstream-neighbor: %s",
350 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
353 offset += 2; /* skip reserved stuff */
355 holdtime = tvb_get_ntohs(tvb, offset);
356 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
357 "Holdtime: %u%s", holdtime,
358 holdtime == 0xffff ? " (infty)" : "");
361 offset += 1; /* skip reserved stuff */
363 mask_len = tvb_get_guint8(tvb, offset);
364 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
365 "Mask length: %u", mask_len);
368 adr_len = tvb_get_guint8(tvb, offset);
369 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
370 "Address length: %u", adr_len);
373 ngroup = tvb_get_guint8(tvb, offset);
374 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
375 "Groups: %u", ngroup);
378 for (i = 0; i < ngroup; i++) {
380 * XXX - does the group address have the length "adr_len"
381 * and the group mask the length "mask_len"?
383 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
385 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
386 grouptree = proto_item_add_subtree(tigroup, ett_pim);
389 proto_tree_add_text(grouptree, tvb, offset, 4,
390 "Group %d Mask: %s", i,
391 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
394 njoin = tvb_get_ntohs(tvb, offset);
395 nprune = tvb_get_ntohs(tvb, offset + 2);
397 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
399 subtree = proto_item_add_subtree(tisub, ett_pim);
401 for (j = 0; j < njoin; j++) {
402 s = dissect_pimv1_addr(tvb, off);
403 proto_tree_add_text(subtree, tvb, off, 6,
404 "IP address: %s", s);
408 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
409 "Prune: %d", nprune);
410 subtree = proto_item_add_subtree(tisub, ett_pim);
411 for (j = 0; j < nprune; j++) {
412 s = dissect_pimv1_addr(tvb, off);
413 proto_tree_add_text(subtree, tvb, off, 6,
414 "IP address: %s", s);
422 case 4: /* rp-reachability */
426 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
428 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
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 offset += 2; /* skip reserved stuff */
443 holdtime = tvb_get_ntohs(tvb, offset);
444 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
445 "Holdtime: %u%s", holdtime,
446 holdtime == 0xffff ? " (infty)" : "");
453 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
455 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
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, 1, "%s",
464 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
465 "RP Tree", "Not RP Tree"));
466 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
467 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
470 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
471 tvb_get_ntohl(tvb, offset));
482 return offset+tvb_length_remaining(tvb, offset);
486 dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
488 static char buf[512];
495 af = tvb_get_guint8(tvb, offset);
496 if (af != AFNUM_INET && af != AFNUM_INET6) {
498 * We don't handle the other formats, and addresses don't include
499 * a length field, so we can't even show them as raw bytes.
504 et = tvb_get_guint8(tvb, offset + 1);
507 * The only defined encoding type is 0, for the native encoding;
508 * again, as addresses don't include a length field, we can't
509 * even show addresses with a different encoding type as raw
520 g_snprintf(buf, sizeof(buf), "%s",
521 ip_to_str(tvb_get_ptr(tvb, offset + 2, len)));
526 g_snprintf(buf, sizeof(buf), "%s",
527 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 2, len)));
535 mask_len = tvb_get_guint8(tvb, offset + 3);
539 g_snprintf(buf, sizeof(buf), "%s/%u",
540 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
545 g_snprintf(buf, sizeof(buf), "%s/%u",
546 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
554 flags = tvb_get_guint8(tvb, offset + 2);
555 mask_len = tvb_get_guint8(tvb, offset + 3);
559 g_snprintf(buf, sizeof(buf), "%s/%u",
560 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
565 g_snprintf(buf, sizeof(buf), "%s/%u",
566 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
570 g_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
572 flags & 0x04 ? "S" : "",
573 flags & 0x02 ? "W" : "",
574 flags & 0x01 ? "R" : "");
586 static const value_string type2vals[] = {
589 { 2, "Register-stop" },
595 { 8, "Candidate-RP-Advertisement" },
600 * For PIM v2, see RFC 2362, and draft-ietf-pim-sm-v2-new-03 (when PIM
601 * is run over IPv6, the rules for computing the PIM checksum from the
602 * draft in question, not from RFC 2362, should be used).
605 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
608 guint length, pim_length;
609 guint16 pim_cksum, computed_cksum;
613 proto_tree *pim_tree = NULL;
615 proto_tree *pimopt_tree = NULL;
618 if (check_col(pinfo->cinfo, COL_PROTOCOL))
619 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
620 if (check_col(pinfo->cinfo, COL_INFO))
621 col_clear(pinfo->cinfo, COL_INFO);
623 pim_typever = tvb_get_guint8(tvb, 0);
625 switch (PIM_VER(pim_typever)) {
627 typestr = val_to_str(PIM_TYPE(pim_typever), type2vals, "Unknown (%u)");
629 case 1: /* PIMv1 - we should never see this */
635 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
636 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
637 PIM_VER(pim_typever));
639 if (check_col(pinfo->cinfo, COL_INFO))
640 col_add_str(pinfo->cinfo, COL_INFO, typestr);
643 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
644 pim_tree = proto_item_add_subtree(ti, ett_pim);
646 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1,
647 PIM_VER(pim_typever));
648 proto_tree_add_uint(pim_tree, hf_pim_type, tvb, offset, 1,
649 PIM_TYPE(pim_typever));
651 pim_cksum = tvb_get_ntohs(tvb, offset + 2);
652 length = tvb_length(tvb);
653 if (PIM_VER(pim_typever) == 2) {
655 * Well, it's PIM v2, so we can check whether this is a Register
656 * message, and thus can figure out how much to checksum and
657 * whether to make the columns read-only.
659 if (PIM_TYPE(pim_typever) == 1) {
661 * Register message - the PIM header is 8 bytes long.
662 * Also set the columns non-writable. Otherwise the IPv4 or
663 * IPv6 dissector for the encapsulated packet that caused
664 * this register will overwrite the PIM info in the columns.
667 col_set_writable(pinfo->cinfo, FALSE);
670 * Other message - checksum the entire packet.
672 pim_length = tvb_reported_length(tvb);
676 * We don't know what type of message this is, so say that
677 * the length is 0, to force it not to be checksummed.
681 if (!pinfo->fragmented && length >= pim_length) {
683 * The packet isn't part of a fragmented datagram and isn't
684 * truncated, so we can checksum it.
687 switch (pinfo->src.type) {
689 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
690 cksum_vec[0].len = pim_length;
691 computed_cksum = in_cksum(&cksum_vec[0], 1);
694 /* Set up the fields of the pseudo-header. */
695 cksum_vec[0].ptr = pinfo->src.data;
696 cksum_vec[0].len = pinfo->src.len;
697 cksum_vec[1].ptr = pinfo->dst.data;
698 cksum_vec[1].len = pinfo->dst.len;
699 cksum_vec[2].ptr = (const guint8 *)&phdr;
700 phdr[0] = g_htonl(pim_length);
701 phdr[1] = g_htonl(IP_PROTO_PIM);
702 cksum_vec[2].len = 8;
703 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, pim_length);
704 cksum_vec[3].len = pim_length;
705 computed_cksum = in_cksum(&cksum_vec[0], 4);
708 /* PIM is available for IPv4 and IPv6 right now */
709 computed_cksum = 0; /* squelch GCC complaints */
710 DISSECTOR_ASSERT_NOT_REACHED();
714 if (computed_cksum == 0) {
715 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
716 offset + 2, 2, pim_cksum,
717 "Checksum: 0x%04x [correct]",
720 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
721 offset + 2, 2, pim_cksum,
722 "Checksum: 0x%04x [incorrect, should be 0x%04x]",
723 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
726 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
727 offset + 2, 2, pim_cksum);
732 if (tvb_reported_length_remaining(tvb, offset) > 0) {
733 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
735 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
739 if (PIM_VER(pim_typever) != 2)
742 /* version 2 decoder */
743 switch (PIM_TYPE(pim_typever)) {
746 while (tvb_reported_length_remaining(tvb, offset) >= 2) {
747 guint16 hello_opt, opt_len;
750 guint16 override_interval;
752 guint32 opt_value = 0;
754 hello_opt = tvb_get_ntohs(tvb, offset);
755 opt_len = tvb_get_ntohs(tvb, offset + 2);
758 opt_value = tvb_get_ntohs(tvb, offset + 4);
760 opt_value = tvb_get_ntohl(tvb, offset + 4);
763 case 1: /* holdtime */
764 holdtime = opt_value;
765 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
766 "Holdtime (%u): %us %s", hello_opt, holdtime,
767 holdtime == 0xffff ? " (infty)" : "");
769 case 2: /* LAN prune delay
772 * 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
773 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
774 * | Type = 2 | Length = 4 |
775 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
776 * |T| LAN Prune Delay | Override Interval |
777 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
780 proto_tree *sub_tree = NULL;
781 proto_item *landelay_option;
783 landelay_option = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
784 "LAN Prune Delay (%u)", hello_opt);
785 sub_tree = proto_item_add_subtree(landelay_option, ett_pim);
787 lan_delay = (opt_value & 0x7fff0000) >> 16;
788 override_interval = opt_value & 0x0000ffff;
789 proto_tree_add_text(sub_tree, tvb, offset + 4, 1,
791 opt_value & 0x8000 ? "set" : "not set");
792 proto_tree_add_text(sub_tree, tvb, offset + 4, 2,
793 "LAN Delay: %ums", lan_delay);
794 proto_tree_add_text(sub_tree, tvb, offset + 6, 2,
795 "Override Interval: %ums", override_interval);
798 case 19: /* priority */
799 priority = opt_value;
800 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
801 "DR Priority (%u): %u", hello_opt, priority);
803 case 20: /* generation ID */
804 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
805 "Generation ID (%u): %d", hello_opt, opt_value);
808 case 24: /* address list */
809 case 65001: /* address list (old implementations) */
812 proto_tree *sub_tree = NULL;
813 proto_item *addrlist_option;
815 addrlist_option = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
816 "%sAddress List (%u)",
817 hello_opt == 65001 ? "old " : "",
819 sub_tree = proto_item_add_subtree(addrlist_option, ett_pim);
821 for (i = offset + 4; i < offset + 4 + opt_len; ) {
825 s = dissect_pim_addr(tvb, i, pimv2_unicast, &advance);
828 proto_tree_add_text(sub_tree, tvb, offset,
829 advance, "Address: %s", s);
835 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
836 "Unknown option (%u), length: %u, value: 0x%x",
837 hello_opt, opt_len, opt_value);
840 offset += 4 + opt_len;
845 case 1: /* register */
850 proto_tree *flag_tree = NULL;
853 flags = tvb_get_ntohl(tvb, offset);
854 tiflag = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
855 "Flags: 0x%08x", flags);
856 flag_tree = proto_item_add_subtree(tiflag, ett_pim);
857 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
858 decode_boolean_bitfield(flags, 0x80000000, 32,
859 "Border", "Not border"));
860 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
861 decode_boolean_bitfield(flags, 0x40000000, 32,
862 "Null-Register", "Not Null-Register"));
866 * The rest of the packet is a multicast data packet.
868 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
871 * It's an IP packet - determine whether it's IPv4 or IPv6.
873 v_hl = tvb_get_guint8(tvb, offset);
874 switch((v_hl & 0xf0) >> 4) {
875 case 0: /* Null-Register dummy header.
876 * Has the same address family as the encapsulating PIM packet,
877 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
879 if (pinfo->src.type == AT_IPv4) {
880 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
881 "IPv4 dummy header");
882 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
884 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
885 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
887 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
888 } else if (pinfo->src.type == AT_IPv6) {
889 struct ip6_hdr ip6_hdr;
890 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
892 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
893 "IPv6 dummy header");
894 proto_tree_add_text(pimopt_tree, tvb,
895 offset + offsetof(struct ip6_hdr, ip6_src), 16,
897 ip6_to_str(&ip6_hdr.ip6_src));
898 proto_tree_add_text(pimopt_tree, tvb,
899 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
901 ip6_to_str(&ip6_hdr.ip6_dst));
903 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
904 "Dummy header for an unknown protocol");
908 call_dissector(ip_handle, next_tvb, pinfo, tree);
910 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
915 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
917 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
921 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
922 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
928 case 2: /* register-stop */
933 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
936 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
938 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
941 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
945 case 3: /* join/prune */
947 case 7: /* graft-ack */
952 int ngroup, i, njoin, nprune, j;
954 proto_tree *grouptree = NULL;
956 proto_tree *subtree = NULL;
959 if (PIM_TYPE(pim_typever) != 7) {
961 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
964 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
965 "Upstream-neighbor: %s", s);
969 offset += 1; /* skip reserved field */
971 ngroup = tvb_get_guint8(tvb, offset);
972 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
973 "Groups: %u", ngroup);
976 if (PIM_TYPE(pim_typever) != 7) {
978 holdtime = tvb_get_ntohs(tvb, offset);
979 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
980 "Holdtime: %u%s", holdtime,
981 holdtime == 0xffff ? " (infty)" : "");
985 for (i = 0; i < ngroup; i++) {
986 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
989 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
990 "Group %d: %s", i, s);
991 grouptree = proto_item_add_subtree(tigroup, ett_pim);
994 njoin = tvb_get_ntohs(tvb, offset);
995 nprune = tvb_get_ntohs(tvb, offset + 2);
997 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
999 subtree = proto_item_add_subtree(tisub, ett_pim);
1001 for (j = 0; j < njoin; j++) {
1002 s = dissect_pim_addr(tvb, off, pimv2_source,
1006 proto_tree_add_text(subtree, tvb, off, advance,
1007 "IP address: %s", s);
1011 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
1012 "Prune: %d", nprune);
1013 subtree = proto_item_add_subtree(tisub, ett_pim);
1014 for (j = 0; j < nprune; j++) {
1015 s = dissect_pim_addr(tvb, off, pimv2_source,
1019 proto_tree_add_text(subtree, tvb, off, advance,
1020 "IP address: %s", s);
1029 case 4: /* bootstrap */
1036 proto_tree *grouptree = NULL;
1037 proto_item *tigroup;
1039 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1040 "Fragment tag: 0x%04x", tvb_get_ntohs(tvb, offset));
1043 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1044 "Hash mask len: %u", tvb_get_guint8(tvb, offset));
1046 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1047 "BSR priority: %u", tvb_get_guint8(tvb, offset));
1050 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1053 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "BSR: %s", s);
1056 for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
1057 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1060 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1061 "Group %d: %s", i, s);
1062 grouptree = proto_item_add_subtree(tigroup, ett_pim);
1065 proto_tree_add_text(grouptree, tvb, offset, 1,
1066 "RP count: %u", tvb_get_guint8(tvb, offset));
1068 frpcnt = tvb_get_guint8(tvb, offset);
1069 proto_tree_add_text(grouptree, tvb, offset, 1,
1070 "FRP count: %u", frpcnt);
1073 for (j = 0; j < frpcnt; j++) {
1074 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1077 proto_tree_add_text(grouptree, tvb, offset, advance,
1081 holdtime = tvb_get_ntohs(tvb, offset);
1082 proto_tree_add_text(grouptree, tvb, offset, 2,
1083 "Holdtime: %u%s", holdtime,
1084 holdtime == 0xffff ? " (infty)" : "");
1086 proto_tree_add_text(grouptree, tvb, offset, 1,
1087 "Priority: %u", tvb_get_guint8(tvb, offset));
1088 offset += 2; /* also skips reserved field */
1096 case 5: /* assert */
1101 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1104 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
1107 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1110 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
1113 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
1114 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
1115 "RP Tree", "Not RP Tree"));
1116 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
1117 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
1120 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
1121 tvb_get_ntohl(tvb, offset));
1126 case 8: /* Candidate-RP-Advertisement */
1134 pfxcnt = tvb_get_guint8(tvb, offset);
1135 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1136 "Prefix-count: %u", pfxcnt);
1138 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1139 "Priority: %u", tvb_get_guint8(tvb, offset));
1141 holdtime = tvb_get_ntohs(tvb, offset);
1142 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1143 "Holdtime: %u%s", holdtime,
1144 holdtime == 0xffff ? " (infty)" : "");
1147 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1150 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "RP: %s", s);
1153 for (i = 0; i < pfxcnt; i++) {
1154 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1157 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1158 "Group %d: %s", i, s);
1173 proto_register_pim(void)
1175 static hf_register_info hf[] = {
1177 { "Version", "pim.version",
1178 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
1180 { "Type", "pim.type",
1181 FT_UINT8, BASE_DEC, VALS(type2vals), 0x0, "", HFILL }},
1183 { "Code", "pim.code",
1184 FT_UINT8, BASE_DEC, VALS(type1vals), 0x0, "", HFILL }},
1186 { "Checksum", "pim.cksum",
1187 FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
1189 static gint *ett[] = {
1193 proto_pim = proto_register_protocol("Protocol Independent Multicast",
1195 proto_register_field_array(proto_pim, hf, array_length(hf));
1196 proto_register_subtree_array(ett, array_length(ett));
1200 proto_reg_handoff_pim(void)
1202 dissector_handle_t pim_handle;
1204 pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1205 dissector_add("ip.proto", IP_PROTO_PIM, pim_handle);
1208 * Get handles for the IPv4 and IPv6 dissectors.
1210 ip_handle = find_dissector("ip");
1211 ipv6_handle = find_dissector("ipv6");