2 * Routines for PIM disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
5 * $Id: packet-pim.c,v 1.47 2003/12/12 21:17:54 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 #include <stddef.h> /* For offsetof */
34 #ifdef NEED_SNPRINTF_H
35 # include "snprintf.h"
38 #include <epan/packet.h>
41 #include "packet-ipv6.h"
44 #define PIM_TYPE(x) ((x) & 0x0f)
45 #define PIM_VER(x) (((x) & 0xf0) >> 4)
48 pimv2_unicast, pimv2_group, pimv2_source
51 static int proto_pim = -1;
52 static int hf_pim_version = -1;
53 static int hf_pim_type = -1;
54 static int hf_pim_code = -1;
55 static int hf_pim_cksum = -1;
57 static gint ett_pim = -1;
59 static dissector_handle_t ip_handle;
60 static dissector_handle_t ipv6_handle;
63 * For PIM v1, see the PDF slides at
65 * http://www.mbone.de/training/Module3.pdf
67 * Is it documented anywhere else?
70 dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
72 guint16 flags_masklen;
74 flags_masklen = tvb_get_ntohs(tvb, offset);
75 if (flags_masklen & 0x0180) {
76 (void)snprintf(buf, sizeof(buf),
78 flags_masklen & 0x0100 ? "S" : "",
79 flags_masklen & 0x0080 ? "W" : "",
80 flags_masklen & 0x0040 ? "R" : "");
83 (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s/%u",
84 ip_to_str(tvb_get_ptr(tvb, offset + 2, 4)), flags_masklen & 0x3f);
89 static const value_string type1vals[] = {
92 { 2, "Register-stop" },
94 { 4, "RP-Reachable" },
102 /* This function is only called from the IGMP dissector */
104 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
108 guint length, pim_length;
109 guint16 pim_cksum, computed_cksum;
111 proto_tree *pim_tree = NULL;
113 proto_tree *pimopt_tree = NULL;
116 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_pim))) {
118 * We are not enabled; skip entire packet to be nice to the
119 * IGMP layer (so clicking on IGMP will display the data).
121 return offset+tvb_length_remaining(tvb, offset);
124 if (check_col(pinfo->cinfo, COL_PROTOCOL))
125 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
126 if (check_col(pinfo->cinfo, COL_INFO))
127 col_clear(pinfo->cinfo, COL_INFO);
130 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
131 pim_tree = proto_item_add_subtree(ti, ett_pim);
133 /* Put IGMP type, 0x14, into the tree */
134 proto_tree_add_text(pim_tree, tvb, offset, 1,
139 pim_type = tvb_get_guint8(tvb, offset);
140 if (check_col(pinfo->cinfo, COL_INFO))
141 col_add_str(pinfo->cinfo, COL_INFO,
142 val_to_str(pim_type, type1vals, "Unknown (%u)"));
145 proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
149 pim_cksum = tvb_get_ntohs(tvb, offset);
150 pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
153 * Not PIMv1 - what gives?
156 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
157 offset, 2, pim_cksum);
161 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
162 return offset+tvb_length_remaining(tvb, offset);
166 * Well, it's PIM v1, so we can check whether this is a
167 * Register message, and thus can figure out how much to
168 * checksum and whether to make the columns read-only.
170 length = tvb_length(tvb);
173 * Register message - the PIM header is 8 bytes long.
174 * Also set the columns non-writable. Otherwise the IPv4 or
175 * IPv6 dissector for the encapsulated packet that caused
176 * this register will overwrite the PIM info in the columns.
179 col_set_writable(pinfo->cinfo, FALSE);
182 * Other message - checksum the entire packet.
184 pim_length = tvb_reported_length(tvb);
188 if (!pinfo->fragmented && length >= pim_length) {
190 * The packet isn't part of a fragmented datagram and isn't
191 * truncated, so we can checksum it.
193 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
194 cksum_vec[0].len = pim_length;
195 computed_cksum = in_cksum(&cksum_vec[0], 1);
196 if (computed_cksum == 0) {
197 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
198 offset, 2, pim_cksum,
199 "Checksum: 0x%04x (correct)",
202 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
203 offset, 2, pim_cksum,
204 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
205 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
208 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
209 offset, 2, pim_cksum);
215 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1, pim_ver);
218 offset += 3; /* skip reserved stuff */
221 if (tvb_reported_length_remaining(tvb, offset) > 0) {
222 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
224 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
228 /* version 1 decoder */
234 static const value_string pimv1_modevals[] = {
237 { 2, "Sparse-Dense" },
241 mode = tvb_get_guint8(tvb, offset) >> 4;
242 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
244 val_to_str(mode, pimv1_modevals, "Unknown (%u)"));
246 holdtime = tvb_get_ntohs(tvb, offset);
247 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
248 "Holdtime: %u%s", holdtime,
249 holdtime == 0xffff ? " (infty)" : "");
254 case 1: /* register */
260 * The rest of the packet is a multicast data packet.
262 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
265 * It's an IP packet - determine whether it's IPv4 or IPv6.
267 v_hl = tvb_get_guint8(tvb, offset);
268 switch((v_hl & 0xf0) >> 4) {
269 case 0: /* Null-Register dummy header.
270 * Has the same address family as the encapsulating PIM packet,
271 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
273 if (pinfo->src.type == AT_IPv4) {
274 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
275 "IPv4 dummy header");
276 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
278 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
279 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
281 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
282 } else if (pinfo->src.type == AT_IPv6) {
283 struct ip6_hdr ip6_hdr;
284 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
286 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
287 "IPv6 dummy header");
288 proto_tree_add_text(pimopt_tree, tvb,
289 offset + offsetof(struct ip6_hdr, ip6_src), 16,
291 ip6_to_str(&ip6_hdr.ip6_src));
292 proto_tree_add_text(pimopt_tree, tvb,
293 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
295 ip6_to_str(&ip6_hdr.ip6_dst));
297 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
298 "Dummy header for an unknown protocol");
302 call_dissector(ip_handle, next_tvb, pinfo, tree);
304 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
309 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
311 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
315 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
316 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
322 case 2: /* register-stop */
324 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
326 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
328 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
330 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
335 case 3: /* join/prune */
337 case 7: /* graft-ack */
341 int ngroup, i, njoin, nprune, j;
345 proto_tree *grouptree = NULL;
347 proto_tree *subtree = NULL;
350 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
351 "Upstream-neighbor: %s",
352 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
355 offset += 2; /* skip reserved stuff */
357 holdtime = tvb_get_ntohs(tvb, offset);
358 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
359 "Holdtime: %u%s", holdtime,
360 holdtime == 0xffff ? " (infty)" : "");
363 offset += 1; /* skip reserved stuff */
365 mask_len = tvb_get_guint8(tvb, offset);
366 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
367 "Mask length: %u", mask_len);
370 adr_len = tvb_get_guint8(tvb, offset);
371 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
372 "Address length: %u", adr_len);
375 ngroup = tvb_get_guint8(tvb, offset);
376 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
377 "Groups: %u", ngroup);
380 for (i = 0; i < ngroup; i++) {
381 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
383 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
384 grouptree = proto_item_add_subtree(tigroup, ett_pim);
387 proto_tree_add_text(grouptree, tvb, offset, 4,
388 "Group %d Mask: %s", i,
389 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
392 njoin = tvb_get_ntohs(tvb, offset);
393 nprune = tvb_get_ntohs(tvb, offset + 2);
395 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
397 subtree = proto_item_add_subtree(tisub, ett_pim);
399 for (j = 0; j < njoin; j++) {
400 s = dissect_pimv1_addr(tvb, off);
401 proto_tree_add_text(subtree, tvb, off, 6,
402 "IP address: %s", s);
406 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
407 "Prune: %d", nprune);
408 subtree = proto_item_add_subtree(tisub, ett_pim);
409 for (j = 0; j < nprune; j++) {
410 s = dissect_pimv1_addr(tvb, off);
411 proto_tree_add_text(subtree, tvb, off, 6,
412 "IP address: %s", s);
420 case 4: /* rp-reachability */
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 proto_tree_add_text(pimopt_tree, tvb, offset, 4,
436 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
439 offset += 2; /* skip reserved stuff */
441 holdtime = tvb_get_ntohs(tvb, offset);
442 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
443 "Holdtime: %u%s", holdtime,
444 holdtime == 0xffff ? " (infty)" : "");
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, 4,
458 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
461 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
462 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
463 "RP Tree", "Not RP Tree"));
464 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
465 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
468 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
469 tvb_get_ntohl(tvb, offset));
480 return offset+tvb_length_remaining(tvb, offset);
484 dissect_pim_addr(tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
486 static char buf[512];
493 af = tvb_get_guint8(tvb, offset);
494 if (af != AFNUM_INET && af != AFNUM_INET6) {
496 * We don't handle the other formats, and addresses don't include
497 * a length field, so we can't even show them as raw bytes.
502 et = tvb_get_guint8(tvb, offset + 1);
505 * The only defined encoding type is 0, for the native encoding;
506 * again, as addresses don't include a length field, we can't
507 * even show addresses with a different encoding type as raw
518 (void)snprintf(buf, sizeof(buf), "%s",
519 ip_to_str(tvb_get_ptr(tvb, offset + 2, len)));
524 (void)snprintf(buf, sizeof(buf), "%s",
525 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 2, len)));
533 mask_len = tvb_get_guint8(tvb, offset + 3);
537 (void)snprintf(buf, sizeof(buf), "%s/%u",
538 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
543 (void)snprintf(buf, sizeof(buf), "%s/%u",
544 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
552 flags = tvb_get_guint8(tvb, offset + 2);
553 mask_len = tvb_get_guint8(tvb, offset + 3);
557 (void)snprintf(buf, sizeof(buf), "%s/%u",
558 ip_to_str(tvb_get_ptr(tvb, offset + 4, len)), mask_len);
563 (void)snprintf(buf, sizeof(buf), "%s/%u",
564 ip6_to_str((const struct e_in6_addr *)tvb_get_ptr(tvb, offset + 4, len)), mask_len);
568 (void)snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
570 flags & 0x04 ? "S" : "",
571 flags & 0x02 ? "W" : "",
572 flags & 0x01 ? "R" : "");
584 static const value_string type2vals[] = {
587 { 2, "Register-stop" },
593 { 8, "Candidate-RP-Advertisement" },
598 * For PIM v2, see RFC 2362, and draft-ietf-pim-sm-v2-new-03 (when PIM
599 * is run over IPv6, the rules for computing the PIM checksum from the
600 * draft in question, not from RFC 2362, should be used).
603 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
606 guint length, pim_length;
607 guint16 pim_cksum, computed_cksum;
611 proto_tree *pim_tree = NULL;
613 proto_tree *pimopt_tree = NULL;
616 if (check_col(pinfo->cinfo, COL_PROTOCOL))
617 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
618 if (check_col(pinfo->cinfo, COL_INFO))
619 col_clear(pinfo->cinfo, COL_INFO);
621 pim_typever = tvb_get_guint8(tvb, 0);
623 switch (PIM_VER(pim_typever)) {
625 typestr = val_to_str(PIM_TYPE(pim_typever), type2vals, "Unknown (%u)");
627 case 1: /* PIMv1 - we should never see this */
633 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
634 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
635 PIM_VER(pim_typever));
637 if (check_col(pinfo->cinfo, COL_INFO))
638 col_add_str(pinfo->cinfo, COL_INFO, typestr);
641 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, FALSE);
642 pim_tree = proto_item_add_subtree(ti, ett_pim);
644 proto_tree_add_uint(pim_tree, hf_pim_version, tvb, offset, 1,
645 PIM_VER(pim_typever));
646 proto_tree_add_uint(pim_tree, hf_pim_type, tvb, offset, 1,
647 PIM_TYPE(pim_typever));
649 pim_cksum = tvb_get_ntohs(tvb, offset + 2);
650 length = tvb_length(tvb);
651 if (PIM_VER(pim_typever) == 2) {
653 * Well, it's PIM v2, so we can check whether this is a Register
654 * message, and thus can figure out how much to checksum and
655 * whether to make the columns read-only.
657 if (PIM_TYPE(pim_typever) == 1) {
659 * Register message - the PIM header is 8 bytes long.
660 * Also set the columns non-writable. Otherwise the IPv4 or
661 * IPv6 dissector for the encapsulated packet that caused
662 * this register will overwrite the PIM info in the columns.
665 col_set_writable(pinfo->cinfo, FALSE);
668 * Other message - checksum the entire packet.
670 pim_length = tvb_reported_length(tvb);
674 * We don't know what type of message this is, so say that
675 * the length is 0, to force it not to be checksummed.
679 if (!pinfo->fragmented && length >= pim_length) {
681 * The packet isn't part of a fragmented datagram and isn't
682 * truncated, so we can checksum it.
685 switch (pinfo->src.type) {
687 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
688 cksum_vec[0].len = pim_length;
689 computed_cksum = in_cksum(&cksum_vec[0], 1);
692 /* Set up the fields of the pseudo-header. */
693 cksum_vec[0].ptr = pinfo->src.data;
694 cksum_vec[0].len = pinfo->src.len;
695 cksum_vec[1].ptr = pinfo->dst.data;
696 cksum_vec[1].len = pinfo->dst.len;
697 cksum_vec[2].ptr = (const guint8 *)&phdr;
698 phdr[0] = g_htonl(pim_length);
699 phdr[1] = g_htonl(IP_PROTO_PIM);
700 cksum_vec[2].len = 8;
701 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, pim_length);
702 cksum_vec[3].len = pim_length;
703 computed_cksum = in_cksum(&cksum_vec[0], 4);
706 /* PIM is available for IPv4 and IPv6 right now */
707 computed_cksum = 0; /* squelch GCC complaints */
708 g_assert_not_reached();
712 if (computed_cksum == 0) {
713 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
714 offset + 2, 2, pim_cksum,
715 "Checksum: 0x%04x (correct)",
718 proto_tree_add_uint_format(pim_tree, hf_pim_cksum, tvb,
719 offset + 2, 2, pim_cksum,
720 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
721 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
724 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
725 offset + 2, 2, pim_cksum);
730 if (tvb_reported_length_remaining(tvb, offset) > 0) {
731 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1,
733 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim);
737 if (PIM_VER(pim_typever) != 2)
740 /* version 2 decoder */
741 switch (PIM_TYPE(pim_typever)) {
744 while (tvb_reported_length_remaining(tvb, offset) >= 2) {
745 guint16 hello_opt, opt_len;
748 guint16 override_interval;
750 guint32 opt_value = 0;
752 hello_opt = tvb_get_ntohs(tvb, offset);
753 opt_len = tvb_get_ntohs(tvb, offset + 2);
756 opt_value = tvb_get_ntohs(tvb, offset + 4);
758 opt_value = tvb_get_ntohl(tvb, offset + 4);
761 case 1: /* holdtime */
762 holdtime = opt_value;
763 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
764 "Holdtime (%u): %us %s", hello_opt, holdtime,
765 holdtime == 0xffff ? " (infty)" : "");
767 case 2: /* LAN prune delay
770 * 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
771 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
772 * | Type = 2 | Length = 4 |
773 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
774 * |T| LAN Prune Delay | Override Interval |
775 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
778 proto_tree *sub_tree = NULL;
779 proto_item *landelay_option;
781 landelay_option = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
782 "LAN Prune Delay (%u)", hello_opt);
783 sub_tree = proto_item_add_subtree(landelay_option, ett_pim);
785 lan_delay = (opt_value & 0x7fff0000) >> 16;
786 override_interval = opt_value & 0x0000ffff;
787 proto_tree_add_text(sub_tree, tvb, offset + 4, 1,
789 opt_value & 0x8000 ? "set" : "not set");
790 proto_tree_add_text(sub_tree, tvb, offset + 4, 2,
791 "LAN Delay: %ums", lan_delay);
792 proto_tree_add_text(sub_tree, tvb, offset + 6, 2,
793 "Override Interval: %ums", override_interval);
796 case 19: /* priority */
797 priority = opt_value;
798 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
799 "DR Priority (%u): %u", hello_opt, priority);
801 case 20: /* generation ID */
802 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
803 "Generation ID (%u): %d", hello_opt, opt_value);
806 case 24: /* address list */
807 case 65001: /* address list (old implementations) */
810 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
811 "%sAddress List (%u)",
812 hello_opt == 65001 ? "old " : "",
814 for (i = offset + 4; i < offset + 4 + opt_len; ) {
818 s = dissect_pim_addr(tvb, i, pimv2_unicast, &advance);
821 proto_tree_add_text(pimopt_tree, tvb, offset,
822 advance, "Address: %s", s);
827 proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
828 "Unknown option (%u), length: %u, value: 0x%x",
829 hello_opt, opt_len, opt_value);
832 offset += 4 + opt_len;
837 case 1: /* register */
842 proto_tree *flag_tree = NULL;
845 flags = tvb_get_ntohl(tvb, offset);
846 tiflag = proto_tree_add_text(pimopt_tree, tvb, offset, 4,
847 "Flags: 0x%08x", flags);
848 flag_tree = proto_item_add_subtree(tiflag, ett_pim);
849 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
850 decode_boolean_bitfield(flags, 0x80000000, 32,
851 "Border", "Not border"));
852 proto_tree_add_text(flag_tree, tvb, offset, 1, "%s",
853 decode_boolean_bitfield(flags, 0x40000000, 32,
854 "Null-Register", "Not Null-Register"));
858 * The rest of the packet is a multicast data packet.
860 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
863 * It's an IP packet - determine whether it's IPv4 or IPv6.
865 v_hl = tvb_get_guint8(tvb, offset);
866 switch((v_hl & 0xf0) >> 4) {
867 case 0: /* Null-Register dummy header.
868 * Has the same address family as the encapsulating PIM packet,
869 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
871 if (pinfo->src.type == AT_IPv4) {
872 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
873 "IPv4 dummy header");
874 proto_tree_add_text(pimopt_tree, tvb, offset + 12, 4,
876 ip_to_str(tvb_get_ptr(tvb, offset + 12, 4)));
877 proto_tree_add_text(pimopt_tree, tvb, offset + 16, 4,
879 ip_to_str(tvb_get_ptr(tvb, offset + 16, 4)));
880 } else if (pinfo->src.type == AT_IPv6) {
881 struct ip6_hdr ip6_hdr;
882 tvb_memcpy(tvb, (guint8 *)&ip6_hdr, offset,
884 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
885 "IPv6 dummy header");
886 proto_tree_add_text(pimopt_tree, tvb,
887 offset + offsetof(struct ip6_hdr, ip6_src), 16,
889 ip6_to_str(&ip6_hdr.ip6_src));
890 proto_tree_add_text(pimopt_tree, tvb,
891 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
893 ip6_to_str(&ip6_hdr.ip6_dst));
895 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
896 "Dummy header for an unknown protocol");
900 call_dissector(ip_handle, next_tvb, pinfo, tree);
902 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
907 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
909 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
913 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
914 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
920 case 2: /* register-stop */
925 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
928 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
930 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
933 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
937 case 3: /* join/prune */
939 case 7: /* graft-ack */
944 int ngroup, i, njoin, nprune, j;
946 proto_tree *grouptree = NULL;
948 proto_tree *subtree = NULL;
951 if (PIM_TYPE(pim_typever) != 7) {
953 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
956 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
957 "Upstream-neighbor: %s", s);
961 offset += 1; /* skip reserved field */
963 ngroup = tvb_get_guint8(tvb, offset);
964 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
965 "Groups: %u", ngroup);
968 if (PIM_TYPE(pim_typever) != 7) {
970 holdtime = tvb_get_ntohs(tvb, offset);
971 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
972 "Holdtime: %u%s", holdtime,
973 holdtime == 0xffff ? " (infty)" : "");
977 for (i = 0; i < ngroup; 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 njoin = tvb_get_ntohs(tvb, offset);
987 nprune = tvb_get_ntohs(tvb, offset + 2);
989 tisub = proto_tree_add_text(grouptree, tvb, offset, 2,
991 subtree = proto_item_add_subtree(tisub, ett_pim);
993 for (j = 0; j < njoin; j++) {
994 s = dissect_pim_addr(tvb, off, pimv2_source,
998 proto_tree_add_text(subtree, tvb, off, advance,
999 "IP address: %s", s);
1003 tisub = proto_tree_add_text(grouptree, tvb, offset + 2, 2,
1004 "Prune: %d", nprune);
1005 subtree = proto_item_add_subtree(tisub, ett_pim);
1006 for (j = 0; j < nprune; j++) {
1007 s = dissect_pim_addr(tvb, off, pimv2_source,
1011 proto_tree_add_text(subtree, tvb, off, advance,
1012 "IP address: %s", s);
1021 case 4: /* bootstrap */
1028 proto_tree *grouptree = NULL;
1029 proto_item *tigroup;
1031 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1032 "Fragment tag: 0x%04x", tvb_get_ntohs(tvb, offset));
1035 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1036 "Hash mask len: %u", tvb_get_guint8(tvb, offset));
1038 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1039 "BSR priority: %u", tvb_get_guint8(tvb, offset));
1042 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1045 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "BSR: %s", s);
1048 for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
1049 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1052 tigroup = proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1053 "Group %d: %s", i, s);
1054 grouptree = proto_item_add_subtree(tigroup, ett_pim);
1057 proto_tree_add_text(grouptree, tvb, offset, 1,
1058 "RP count: %u", tvb_get_guint8(tvb, offset));
1060 frpcnt = tvb_get_guint8(tvb, offset);
1061 proto_tree_add_text(grouptree, tvb, offset, 1,
1062 "FRP count: %u", frpcnt);
1065 for (j = 0; j < frpcnt; j++) {
1066 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1069 proto_tree_add_text(grouptree, tvb, offset, advance,
1073 holdtime = tvb_get_ntohs(tvb, offset);
1074 proto_tree_add_text(grouptree, tvb, offset, 2,
1075 "Holdtime: %u%s", holdtime,
1076 holdtime == 0xffff ? " (infty)" : "");
1078 proto_tree_add_text(grouptree, tvb, offset, 1,
1079 "Priority: %u", tvb_get_guint8(tvb, offset));
1080 offset += 2; /* also skips reserved field */
1088 case 5: /* assert */
1093 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1096 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Group: %s", s);
1099 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1102 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "Source: %s", s);
1105 proto_tree_add_text(pimopt_tree, tvb, offset, 1, "%s",
1106 decode_boolean_bitfield(tvb_get_guint8(tvb, offset), 0x80, 8,
1107 "RP Tree", "Not RP Tree"));
1108 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Preference: %u",
1109 tvb_get_ntohl(tvb, offset) & 0x7fffffff);
1112 proto_tree_add_text(pimopt_tree, tvb, offset, 4, "Metric: %u",
1113 tvb_get_ntohl(tvb, offset));
1118 case 8: /* Candidate-RP-Advertisement */
1126 pfxcnt = tvb_get_guint8(tvb, offset);
1127 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1128 "Prefix-count: %u", pfxcnt);
1130 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
1131 "Priority: %u", tvb_get_guint8(tvb, offset));
1133 holdtime = tvb_get_ntohs(tvb, offset);
1134 proto_tree_add_text(pimopt_tree, tvb, offset, 2,
1135 "Holdtime: %u%s", holdtime,
1136 holdtime == 0xffff ? " (infty)" : "");
1139 s = dissect_pim_addr(tvb, offset, pimv2_unicast, &advance);
1142 proto_tree_add_text(pimopt_tree, tvb, offset, advance, "RP: %s", s);
1145 for (i = 0; i < pfxcnt; i++) {
1146 s = dissect_pim_addr(tvb, offset, pimv2_group, &advance);
1149 proto_tree_add_text(pimopt_tree, tvb, offset, advance,
1150 "Group %d: %s", i, s);
1165 proto_register_pim(void)
1167 static hf_register_info hf[] = {
1169 { "Version", "pim.version",
1170 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
1172 { "Type", "pim.type",
1173 FT_UINT8, BASE_DEC, VALS(type2vals), 0x0, "", HFILL }},
1175 { "Code", "pim.code",
1176 FT_UINT8, BASE_DEC, VALS(type1vals), 0x0, "", HFILL }},
1178 { "Checksum", "pim.cksum",
1179 FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
1181 static gint *ett[] = {
1185 proto_pim = proto_register_protocol("Protocol Independent Multicast",
1187 proto_register_field_array(proto_pim, hf, array_length(hf));
1188 proto_register_subtree_array(ett, array_length(ett));
1192 proto_reg_handoff_pim(void)
1194 dissector_handle_t pim_handle;
1196 pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1197 dissector_add("ip.proto", IP_PROTO_PIM, pim_handle);
1200 * Get handles for the IPv4 and IPv6 dissectors.
1202 ip_handle = find_dissector("ip");
1203 ipv6_handle = find_dissector("ipv6");