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/ipproto.h>
37 #include "packet-ipv6.h"
38 #include <epan/in_cksum.h>
39 #include "packet-pim.h"
41 #define PIM_TYPE(x) ((x) & 0x0f)
42 #define PIM_VER(x) (((x) & 0xf0) >> 4)
45 pimv2_unicast, pimv2_group, pimv2_source
48 static int proto_pim = -1;
49 static int hf_pim_version = -1;
50 static int hf_pim_type = -1;
51 static int hf_pim_code = -1;
52 static int hf_pim_cksum = -1;
54 static gint ett_pim = -1;
56 static dissector_handle_t ip_handle;
57 static dissector_handle_t ipv6_handle;
60 * For PIM v1, see the PDF slides at
62 * http://www.mbone.de/training/Module3.pdf
64 * Is it documented anywhere else?
67 dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
68 guint16 flags_masklen;
70 flags_masklen = tvb_get_ntohs(tvb, offset);
71 if (flags_masklen & 0x0180) {
72 return ep_strdup_printf("(%s%s%s) ",
73 flags_masklen & 0x0100 ? "S" : "",
74 flags_masklen & 0x0080 ? "W" : "",
75 flags_masklen & 0x0040 ? "R" : "");
77 return ep_strdup_printf("%s/%u",
78 ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)), flags_masklen & 0x3f);
82 static const value_string type1vals[] = {
85 { 2, "Register-stop" },
87 { 4, "RP-Reachable" },
95 /* This function is only called from the IGMP dissector */
97 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
101 guint length, pim_length;
102 guint16 pim_cksum, computed_cksum;
104 proto_tree *pim_tree = NULL;
106 proto_tree *pimopt_tree = NULL;
109 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_pim))) {
111 * We are not enabled; skip entire packet to be nice to the
112 * IGMP layer (so clicking on IGMP will display the data).
114 return offset+tvb_length_remaining(tvb, offset);
117 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
118 col_clear(pinfo->cinfo, COL_INFO);
121 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
122 pim_tree = proto_item_add_subtree(ti, ett_pim);
124 /* Put IGMP type, 0x14, into the tree */
125 proto_tree_add_text(pim_tree, tvb, offset, 1,
130 pim_type = tvb_get_guint8(tvb, offset);
131 if (check_col(pinfo->cinfo, COL_INFO))
132 col_add_str(pinfo->cinfo, COL_INFO,
133 val_to_str(pim_type, type1vals, "Unknown (%u)"));
136 proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
140 pim_cksum = tvb_get_ntohs(tvb, offset);
141 pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
144 * Not PIMv1 - what gives?
147 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
148 offset, 2, pim_cksum);
152 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
153 return offset+tvb_length_remaining(tvb, offset);
157 * Well, it's PIM v1, so we can check whether this is a
158 * Register message, and thus can figure out how much to
159 * checksum and whether to make the columns read-only.
161 length = tvb_length(tvb);
164 * Register message - the PIM header is 8 bytes long.
165 * Also set the columns non-writable. Otherwise the IPv4 or
166 * IPv6 dissector for the encapsulated packet that caused
167 * this register will overwrite the PIM info in the columns.
170 col_set_writable(pinfo->cinfo, FALSE);
173 * Other message - checksum the entire packet.
175 pim_length = tvb_reported_length(tvb);
179 if (!pinfo->fragmented && length >= pim_length) {
181 * The packet isn't part of a fragmented datagram and isn't
182 * truncated, so we can checksum it.
184 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
185 cksum_vec[0].len = pim_length;
186 computed_cksum = in_cksum(&cksum_vec[0], 1);
187 if (computed_cksum == 0) {
188 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
189 offset, 2, pim_cksum,
190 "Checksum: 0x%04x [correct]",
193 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
194 offset, 2, pim_cksum,
195 "Checksum: 0x%04x [incorrect, should be 0x%04x]",
196 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
199 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
200 offset, 2, pim_cksum);
206 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
209 offset += 3; /* skip reserved stuff */
212 if (tvb_reported_length_remaining(tvb, offset) > 0) {
213 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
215 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
219 /* version 1 decoder */
225 static const value_string pimv1_modevals[] = {
228 { 2, "Sparse-Dense" },
232 mode = tvb_get_guint8(tvb, offset) >> 4;
233 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
235 val_to_str(mode, pimv1_modevals, "Unknown (%u)"));
237 holdtime = tvb_get_ntohs(tvb, offset);
238 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
239 "Holdtime: %u%s", holdtime,
240 holdtime == 0xffff ? " (infty)" : "");
245 case 1: /* register */
251 * The rest of the packet is a multicast data packet.
253 next_tvb = tvb_new_subset_remaining(tvb, offset);
256 * It's an IP packet - determine whether it's IPv4 or IPv6.
258 v_hl = tvb_get_guint8(tvb, offset);
259 switch((v_hl & 0xf0) >> 4) {
260 case 0: /* Null-Register dummy header.
261 * Has the same address family as the encapsulating PIM packet,
262 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
264 if (pinfo->src.type == AT_IPv4) {
265 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
266 "IPv4 dummy header");
267 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
269 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
270 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
272 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
273 } else if (pinfo->src.type == AT_IPv6) {
274 struct ip6_hdr ip6_hdr;
275 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
277 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
278 "IPv6 dummy header");
279 proto_tree_add_text(pimopt_tree, tvb,
280 offset + offsetof(struct ip6_hdr, ip6_src), 16,
282 ip6_to_str(&ip6_hdr.ip6_src));
283 proto_tree_add_text(pimopt_tree, tvb,
284 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
286 ip6_to_str(&ip6_hdr.ip6_dst));
288 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
289 "Dummy header for an unknown protocol");
293 call_dissector(ip_handle, next_tvb, pinfo, tree);
295 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
300 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
302 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
306 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
307 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
313 case 2: /* register-stop */
315 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
317 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
319 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
321 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
326 case 3: /* join/prune */
328 case 7: /* graft-ack */
332 int ngroup, i, njoin, nprune, j;
336 proto_tree *grouptree = NULL;
338 proto_tree *subtree = NULL;
341 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
342 "Upstream-neighbor: %s",
343 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
346 offset += 2; /* skip reserved stuff */
348 holdtime = tvb_get_ntohs(tvb, offset);
349 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
350 "Holdtime: %u%s", holdtime,
351 holdtime == 0xffff ? " (infty)" : "");
354 offset += 1; /* skip reserved stuff */
356 mask_len = tvb_get_guint8(tvb, offset);
357 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
358 "Mask length: %u", mask_len);
361 adr_len = tvb_get_guint8(tvb, offset);
362 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
363 "Address length: %u", adr_len);
366 ngroup = tvb_get_guint8(tvb, offset);
367 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
368 "Groups: %u", ngroup);
371 for (i = 0; i < ngroup; i++) {
373 * XXX - does the group address have the length "adr_len"
374 * and the group mask the length "mask_len"?
376 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
378 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
379 grouptree = proto_item_add_subtree(tigroup, ett_pim);
382 proto_tree_add_text(grouptree, tvb, offset, 4,
383 "Group %d Mask: %s", i,
384 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
387 njoin = tvb_get_ntohs(tvb, offset);
388 nprune = tvb_get_ntohs(tvb, offset + 2);
390 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
392 subtree = proto_item_add_subtree(tisub, ett_pim);
394 for (j = 0; j < njoin; j++) {
395 s = dissect_pimv1_addr(tvb, off);
396 proto_tree_add_text(subtree, tvb, off, 6,
397 "IP address: %s", s);
401 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
402 "Prune: %d", nprune);
403 subtree = proto_item_add_subtree(tisub, ett_pim);
404 for (j = 0; j < nprune; j++) {
405 s = dissect_pimv1_addr(tvb, off);
406 proto_tree_add_text(subtree, tvb, off, 6,
407 "IP address: %s", s);
415 case 4: /* rp-reachability */
419 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
421 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
424 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
426 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
429 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
431 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
434 offset += 2; /* skip reserved stuff */
436 holdtime = tvb_get_ntohs(tvb, offset);
437 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
438 "Holdtime: %u%s", holdtime,
439 holdtime == 0xffff ? " (infty)" : "");
446 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
448 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
451 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
453 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
456 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
457 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
458 "RP Tree", "Not RP Tree"));
459 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
460 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
463 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
464 tvb_get_ntohl(tvb, offset));
475 return offset+tvb_length_remaining(tvb, offset);
479 dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
481 emem_strbuf_t *strbuf;
488 af = tvb_get_guint8(tvb, offset);
489 if (af != AFNUM_INET && af != AFNUM_INET6) {
491 * We don't handle the other formats, and addresses don't include
492 * a length field, so we can't even show them as raw bytes.
497 et = tvb_get_guint8(tvb, offset + 1);
500 * The only defined encoding type is 0, for the native encoding;
501 * again, as addresses don't include a length field, we can't
502 * even show addresses with a different encoding type as raw
508 strbuf = ep_strbuf_new_label(NULL);
514 ep_strbuf_printf(strbuf, "%s", ip_to_str(tvb_get_ptr(tvb, offset + 2, len)));
519 ep_strbuf_printf(strbuf, "%s", ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 2, len)));
527 mask_len = tvb_get_guint8(tvb, offset + 3);
531 ep_strbuf_printf(strbuf, "%s/%u",
532 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
537 ep_strbuf_printf(strbuf, "%s/%u",
538 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
546 flags = tvb_get_guint8(tvb, offset + 2);
547 mask_len = tvb_get_guint8(tvb, offset + 3);
551 ep_strbuf_printf(strbuf, "%s/%u",
552 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
557 ep_strbuf_printf(strbuf, "%s/%u",
558 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
562 ep_strbuf_append_printf(strbuf,
564 flags & 0x04 ? "S" : "",
565 flags & 0x02 ? "W" : "",
566 flags & 0x01 ? "R" : "");
578 static const value_string type2vals[] = {
581 { 2, "Register-stop" },
587 { 8, "Candidate-RP-Advertisement" },
588 { 9, "State-Refresh" },
593 * For PIM v2, see RFC 4601, RFC 3973 and draft-ietf-pim-sm-v2-new-03
594 * (when PIM is run over IPv6, the rules for computing the PIM checksum
595 * from the draft in question, not from RFC 2362, should be used).
598 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
601 guint length, pim_length;
602 guint16 pim_cksum, computed_cksum;
606 proto_tree *pim_tree = NULL;
608 proto_tree *pimopt_tree = NULL;
611 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
612 col_clear(pinfo->cinfo, COL_INFO);
614 pim_typever = tvb_get_guint8(tvb, 0);
616 switch (PIM_VER(pim_typever)) {
618 typestr = val_to_str(PIM_TYPE(pim_typever), type2vals, "Unknown (%u)");
620 case 1: /* PIMv1 - we should never see this */
626 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
627 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
628 PIM_VER(pim_typever));
630 if (check_col(pinfo->cinfo, COL_INFO))
631 col_add_str(pinfo->cinfo, COL_INFO, typestr);
634 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
635 pim_tree = proto_item_add_subtree(ti, ett_pim);
637 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1,
638 PIM_VER(pim_typever));
639 proto_tree_add_uint(pim_tree, hf_pim_type, tvb, offset, 1,
640 PIM_TYPE(pim_typever));
642 pim_cksum = tvb_get_ntohs(tvb, offset + 2);
643 length = tvb_length(tvb);
644 if (PIM_VER(pim_typever) == 2) {
646 * Well, it's PIM v2, so we can check whether this is a Register
647 * message, and thus can figure out how much to checksum and
648 * whether to make the columns read-only.
650 if (PIM_TYPE(pim_typever) == 1) {
652 * Register message - the PIM header is 8 bytes long.
653 * Also set the columns non-writable. Otherwise the IPv4 or
654 * IPv6 dissector for the encapsulated packet that caused
655 * this register will overwrite the PIM info in the columns.
658 col_set_writable(pinfo->cinfo, FALSE);
661 * Other message - checksum the entire packet.
663 pim_length = tvb_reported_length(tvb);
667 * We don't know what type of message this is, so say that
668 * the length is 0, to force it not to be checksummed.
672 if (!pinfo->fragmented && length >= pim_length) {
674 * The packet isn't part of a fragmented datagram and isn't
675 * truncated, so we can checksum it.
678 switch (pinfo->src.type) {
680 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
681 cksum_vec[0].len = pim_length;
682 computed_cksum = in_cksum(&cksum_vec[0], 1);
685 /* Set up the fields of the pseudo-header. */
686 cksum_vec[0].ptr = pinfo->src.data;
687 cksum_vec[0].len = pinfo->src.len;
688 cksum_vec[1].ptr = pinfo->dst.data;
689 cksum_vec[1].len = pinfo->dst.len;
690 cksum_vec[2].ptr = (const guint8 *)&phdr;
691 phdr[0] = g_htonl(pim_length);
692 phdr[1] = g_htonl(IP_PROTO_PIM);
693 cksum_vec[2].len = 8;
694 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, pim_length);
695 cksum_vec[3].len = pim_length;
696 computed_cksum = in_cksum(&cksum_vec[0], 4);
699 /* PIM is available for IPv4 and IPv6 right now */
700 computed_cksum = 0; /* squelch GCC complaints */
701 DISSECTOR_ASSERT_NOT_REACHED();
705 if (computed_cksum == 0) {
706 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
707 offset + 2, 2, pim_cksum,
708 "Checksum: 0x%04x [correct]",
711 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
712 offset + 2, 2, pim_cksum,
713 "Checksum: 0x%04x [incorrect, should be 0x%04x]",
714 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
717 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
718 offset + 2, 2, pim_cksum);
723 if (tvb_reported_length_remaining(tvb, offset) > 0) {
724 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
726 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
730 if (PIM_VER(pim_typever) != 2)
733 /* version 2 decoder */
734 switch (PIM_TYPE(pim_typever)) {
737 while (tvb_reported_length_remaining(tvb, offset) >= 2) {
738 guint16 hello_opt, opt_len;
741 guint16 override_interval;
743 guint32 opt_value = 0;
745 hello_opt = tvb_get_ntohs(tvb, offset);
746 opt_len = tvb_get_ntohs(tvb, offset + 2);
749 opt_value = tvb_get_ntohs(tvb, offset + 4);
751 opt_value = tvb_get_ntohl(tvb, offset + 4);
754 case 1: /* holdtime */
755 holdtime = opt_value;
756 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
757 "Holdtime (%u): %us %s", hello_opt, holdtime,
758 holdtime == 0xffff ? " (infty)" : "");
760 case 2: /* LAN prune delay
763 * 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
764 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
765 * | Type = 2 | Length = 4 |
766 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
767 * |T| LAN Prune Delay | Override Interval |
768 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
771 proto_tree *sub_tree = NULL;
772 proto_item *landelay_option;
774 landelay_option = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
775 "LAN Prune Delay (%u)", hello_opt);
776 sub_tree = proto_item_add_subtree(landelay_option, ett_pim);
778 lan_delay = (opt_value & 0x7fff0000) >> 16;
779 override_interval = opt_value & 0x0000ffff;
780 proto_tree_add_text(sub_tree, tvb, offset + 4, 1,
782 (opt_value & 0x80000000) ? "set" : "not set");
783 proto_tree_add_text(sub_tree, tvb, offset + 4, 2,
784 "LAN Delay: %ums", lan_delay);
785 proto_tree_add_text(sub_tree, tvb, offset + 6, 2,
786 "Override Interval: %ums", override_interval);
789 case 19: /* priority */
790 priority = opt_value;
791 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
792 "DR Priority (%u): %u", hello_opt, priority);
794 case 20: /* generation ID */
795 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
796 "Generation ID (%u): %d", hello_opt, opt_value);
799 case 24: /* address list */
800 case 65001: /* address list (old implementations) */
803 proto_tree *sub_tree = NULL;
804 proto_item *addrlist_option;
806 addrlist_option = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
807 "%sAddress List (%u)",
808 hello_opt == 65001 ? "old " : "",
810 sub_tree = proto_item_add_subtree(addrlist_option, ett_pim);
812 for (i = offset + 4; i < offset + 4 + opt_len; ) {
816 s = dissect_pim_addr(tvb, i, pimv2_unicast, &advance);
819 proto_tree_add_text(sub_tree, tvb, offset,
820 advance, "Address: %s", s);
826 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
827 "Unknown option (%u), length: %u, value: 0x%x",
828 hello_opt, opt_len, opt_value);
831 offset += 4 + opt_len;
836 case 1: /* register */
841 proto_tree *flag_tree = NULL;
844 flags = tvb_get_ntohl(tvb, offset);
845 tiflag = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
846 "Flags: 0x%08x", flags);
847 flag_tree = proto_item_add_subtree(tiflag, ett_pim);
848 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
849 decode_boolean_bitfield(flags, 0x80000000, 32,
850 "Border", "Not border"));
851 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
852 decode_boolean_bitfield(flags, 0x40000000, 32,
853 "Null-Register", "Not Null-Register"));
857 * The rest of the packet is a multicast data packet.
859 next_tvb = tvb_new_subset_remaining(tvb, offset);
862 * It's an IP packet - determine whether it's IPv4 or IPv6.
864 v_hl = tvb_get_guint8(tvb, offset);
865 switch((v_hl & 0xf0) >> 4) {
866 case 0: /* Null-Register dummy header.
867 * Has the same address family as the encapsulating PIM packet,
868 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
870 if (pinfo->src.type == AT_IPv4) {
871 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
872 "IPv4 dummy header");
873 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
875 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
876 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
878 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
879 } else if (pinfo->src.type == AT_IPv6) {
880 struct ip6_hdr ip6_hdr;
881 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
883 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
884 "IPv6 dummy header");
885 proto_tree_add_text(pimopt_tree, tvb,
886 offset + offsetof(struct ip6_hdr, ip6_src), 16,
888 ip6_to_str(&ip6_hdr.ip6_src));
889 proto_tree_add_text(pimopt_tree, tvb,
890 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
892 ip6_to_str(&ip6_hdr.ip6_dst));
894 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
895 "Dummy header for an unknown protocol");
899 call_dissector(ip_handle, next_tvb, pinfo, tree);
901 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
906 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
908 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
912 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
913 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
919 case 2: /* register-stop */
924 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
927 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
929 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
932 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
936 case 3: /* join/prune */
938 case 7: /* graft-ack */
943 int ngroup, i, njoin, nprune, j;
945 proto_tree *grouptree = NULL;
947 proto_tree *subtree = NULL;
950 if (PIM_TYPE(pim_typever) != 7) {
952 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
955 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
956 "Upstream-neighbor: %s", s);
960 offset += 1; /* skip reserved field */
962 ngroup = tvb_get_guint8(tvb, offset);
963 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
964 "Groups: %u", ngroup);
967 if (PIM_TYPE(pim_typever) != 7) {
969 holdtime = tvb_get_ntohs(tvb, offset);
970 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
971 "Holdtime: %u%s", holdtime,
972 holdtime == 0xffff ? " (infty)" : "");
976 for (i = 0; i < ngroup; i++) {
977 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
980 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
981 "Group %d: %s", i, s);
982 grouptree = proto_item_add_subtree(tigroup, ett_pim);
985 njoin = tvb_get_ntohs(tvb, offset);
986 nprune = tvb_get_ntohs(tvb, offset + 2);
988 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
990 subtree = proto_item_add_subtree(tisub, ett_pim);
992 for (j = 0; j < njoin; j++) {
993 s = dissect_pim_addr(tvb, off, pimv2_source,
997 proto_tree_add_text(subtree, tvb, off, advance,
998 "IP address: %s", s);
1002 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
1003 "Prune: %d", nprune);
1004 subtree = proto_item_add_subtree(tisub, ett_pim);
1005 for (j = 0; j < nprune; j++) {
1006 s = dissect_pim_addr(tvb, off, pimv2_source,
1010 proto_tree_add_text(subtree, tvb, off, advance,
1011 "IP address: %s", s);
1020 case 4: /* bootstrap */
1027 proto_tree *grouptree = NULL;
1028 proto_item *tigroup;
1030 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1031 "Fragment tag: 0x%04x", tvb_get_ntohs(tvb, offset));
1034 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1035 "Hash mask len: %u", tvb_get_guint8(tvb, offset));
1037 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1038 "BSR priority: %u", tvb_get_guint8(tvb, offset));
1041 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1044 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "BSR: %s", s);
1047 for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
1048 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1051 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1052 "Group %d: %s", i, s);
1053 grouptree = proto_item_add_subtree(tigroup, ett_pim);
1056 proto_tree_add_text(grouptree, tvb, offset, 1,
1057 "RP count: %u", tvb_get_guint8(tvb, offset));
1059 frpcnt = tvb_get_guint8(tvb, offset);
1060 proto_tree_add_text(grouptree, tvb, offset, 1,
1061 "FRP count: %u", frpcnt);
1064 for (j = 0; j < frpcnt; j++) {
1065 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1068 proto_tree_add_text(grouptree, tvb, offset, advance,
1072 holdtime = tvb_get_ntohs(tvb, offset);
1073 proto_tree_add_text(grouptree, tvb, offset, 2,
1074 "Holdtime: %u%s", holdtime,
1075 holdtime == 0xffff ? " (infty)" : "");
1077 proto_tree_add_text(grouptree, tvb, offset, 1,
1078 "Priority: %u", tvb_get_guint8(tvb, offset));
1079 offset += 2; /* also skips reserved field */
1087 case 5: /* assert */
1092 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1095 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
1098 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1101 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
1104 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
1105 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
1106 "RP Tree", "Not RP Tree"));
1107 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
1108 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
1111 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
1112 tvb_get_ntohl(tvb, offset));
1117 case 8: /* Candidate-RP-Advertisement */
1125 pfxcnt = tvb_get_guint8(tvb, offset);
1126 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1127 "Prefix-count: %u", pfxcnt);
1129 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1130 "Priority: %u", tvb_get_guint8(tvb, offset));
1132 holdtime = tvb_get_ntohs(tvb, offset);
1133 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1134 "Holdtime: %u%s", holdtime,
1135 holdtime == 0xffff ? " (infty)" : "");
1138 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1141 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "RP: %s", s);
1144 for (i = 0; i < pfxcnt; i++) {
1145 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1148 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1149 "Group %d: %s", i, s);
1156 case 9: /* State-Refresh */
1161 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1164 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1168 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1171 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1175 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1178 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1179 "Originator: %s", s);
1182 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "Rendezvous Point Tree %s",
1183 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 1, 1,
1185 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
1186 "Metric Preference: %u", tvb_get_ntohl(tvb, offset) & 0x7FFFFFFF);
1189 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
1190 "Metric: %u", tvb_get_ntohl(tvb, offset));
1193 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1194 "Masklen: %u", tvb_get_guint8(tvb, offset));
1197 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1198 "TTL: %u", tvb_get_guint8(tvb, offset));
1201 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "Prune indicator %s",
1202 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
1204 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "Prune now %s",
1205 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x40, 8,
1207 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "Assert override %s",
1208 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x20, 8,
1212 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1213 "Interval: %u", tvb_get_guint8(tvb, offset));
1227 proto_register_pim(void)
1229 static hf_register_info hf[] = {
1231 { "Version", "pim.version",
1232 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
1234 { "Type", "pim.type",
1235 FT_UINT8, BASE_DEC, VALS(type2vals), 0x0, NULL, HFILL }},
1237 { "Code", "pim.code",
1238 FT_UINT8, BASE_DEC, VALS(type1vals), 0x0, NULL, HFILL }},
1240 { "Checksum", "pim.cksum",
1241 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
1243 static gint *ett[] = {
1247 proto_pim = proto_register_protocol("Protocol Independent Multicast",
1249 proto_register_field_array(proto_pim, hf, array_length(hf));
1250 proto_register_subtree_array(ett, array_length(ett));
1254 proto_reg_handoff_pim(void)
1256 dissector_handle_t pim_handle;
1258 pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1259 dissector_add("ip.proto", IP_PROTO_PIM, pim_handle);
1262 * Get handles for the IPv4 and IPv6 dissectors.
1264 ip_handle = find_dissector("ip");
1265 ipv6_handle = find_dissector("ipv6");