HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-pim.c
blobd0acaa83d5a993078bf6905f3084d9d8951499ed
1 /* packet-pim.c
2 * Routines for PIM disassembly
3 * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
5 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/ipproto.h>
32 #include <epan/afn.h>
33 #include <epan/prefs.h>
34 #include <epan/in_cksum.h>
35 #include <epan/wmem/wmem.h>
36 #include "packet-pim.h"
38 #define PIM_TYPE(x) ((x) & 0x0f)
39 #define PIM_VER(x) (((x) & 0xf0) >> 4)
41 enum pimv2_addrtype {
42 pimv2_unicast, pimv2_group, pimv2_source
45 static int proto_pim = -1;
46 static int hf_pim_version = -1;
47 static int hf_pim_type = -1;
48 static int hf_pim_code = -1;
49 static int hf_pim_cksum = -1;
50 static int hf_pim_res_bytes = -1;
51 /* PIM Hello options (RFC 4601, section 4.9.2 and RFC 3973, section 4.7.5) */
52 static int hf_pim_optiontype = -1;
53 static int hf_pim_optionlength = -1;
54 static int hf_pim_optionvalue = -1;
55 static int hf_pim_register_flag = -1;
56 static int hf_pim_register_flag_border = -1;
57 static int hf_pim_register_flag_null_register = -1;
58 static int hf_pim_mode = -1;
59 static int hf_pim_holdtime = -1;
60 static int hf_pim_numgroups = -1;
61 static int hf_pim_numjoins = -1;
62 static int hf_pim_numprunes = -1;
63 static int hf_pim_t = -1;
64 static int hf_pim_propagation_delay = -1;
65 static int hf_pim_override_interval = -1;
66 static int hf_pim_dr_priority = -1;
67 static int hf_pim_generation_id = -1;
68 static int hf_pim_state_refresh_version = -1;
69 static int hf_pim_state_refresh_interval = -1;
70 static int hf_pim_state_refresh_reserved = -1;
71 /* Assert fields */
72 static int hf_pim_rpt = -1;
73 static int hf_pim_metric_pref = -1;
74 static int hf_pim_metric = -1;
75 static int hf_pim_prune_indicator = -1;
76 static int hf_pim_prune_now = -1;
77 static int hf_pim_assert_override = -1;
78 static int hf_pim_source_ip4 = -1;
79 static int hf_pim_source_ip6 = -1;
80 static int hf_pim_group_ip4 = -1;
81 static int hf_pim_group_ip6 = -1;
82 static int hf_pim_group_mask_ip4 = -1;
83 static int hf_pim_upstream_neighbor_ip4 = -1;
84 static int hf_pim_upstream_neighbor_ip6 = -1;
85 static int hf_pim_join_ip4 = -1;
86 static int hf_pim_join_ip6 = -1;
87 static int hf_pim_prune_ip4 = -1;
88 static int hf_pim_prune_ip6 = -1;
89 static int hf_pim_address_list_ip4 = -1;
90 static int hf_pim_address_list_ip6 = -1;
91 static int hf_pim_bsr_ip4 = -1;
92 static int hf_pim_bsr_ip6 = -1;
93 static int hf_pim_rp_ip4 = -1;
94 static int hf_pim_rp_ip6 = -1;
95 static int hf_pim_originator_ip4 = -1;
96 static int hf_pim_originator_ip6 = -1;
97 static int hf_pim_group_address_ip4 = -1;
98 static int hf_pim_rp_address_ip4 = -1;
99 static int hf_pim_fragment_tag = -1;
100 static int hf_pim_hash_mask_len = -1;
101 static int hf_pim_bsr_priority = -1;
102 static int hf_pim_rp_count = -1;
103 static int hf_pim_frp_count = -1;
104 static int hf_pim_priority = -1;
105 static int hf_pim_prefix_count = -1;
106 static int hf_pim_mask_len = -1;
107 static int hf_pim_ttl = -1;
108 static int hf_pim_interval = -1;
110 static gint ett_pim = -1;
111 static gint ett_pim_opts = -1;
112 static gint ett_pim_opt = -1;
114 static dissector_handle_t ip_handle;
115 static dissector_handle_t ipv6_handle;
117 static gboolean use_main_tree = TRUE;
120 * For PIM v1, see
122 * ftp://ftp.usc.edu/pub/csinfo/tech-reports/papers/95-599.ps.Z
124 * NOTE: There is still some doubt that this is THE definitive PIMv1
125 * specification. Of note, the type1vals entry, { 8, "Mode" }, does
126 * not appear as a valid code in the referenced document above.
128 * This one is likely closer to the last PIMv1 spec:
129 * http://tools.ietf.org/id/draft-ietf-idmr-pim-spec-02.txt
131 static const char *
132 dissect_pimv1_addr(tvbuff_t *tvb, int offset) {
133 guint16 flags_masklen;
135 flags_masklen = tvb_get_ntohs(tvb, offset);
136 if (flags_masklen & 0x0180) {
137 return wmem_strdup_printf(wmem_packet_scope(), "(%s%s%s) ",
138 flags_masklen & 0x0100 ? "S" : "",
139 flags_masklen & 0x0080 ? "W" : "",
140 flags_masklen & 0x0040 ? "R" : "");
141 } else {
142 return wmem_strdup_printf(wmem_packet_scope(), "%s/%u",
143 tvb_ip_to_str(tvb, offset + 2), flags_masklen & 0x3f);
147 static const value_string type1vals[] = {
148 { 0, "Query" },
149 { 1, "Register" },
150 { 2, "Register-stop" },
151 { 3, "Join/Prune" },
152 { 4, "RP-Reachable" },
153 { 5, "Assert" },
154 { 6, "Graft" },
155 { 7, "Graft-Ack" },
156 { 8, "Mode" },
157 { 0, NULL },
160 static const value_string pimv1_modevals[] = {
161 { 0, "Dense" },
162 { 1, "Sparse" },
163 { 2, "Sparse-Dense" },
164 { 0, NULL }
167 /* This function is only called from the IGMP dissector */
169 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
170 int offset) {
171 guint8 pim_type;
172 guint8 pim_ver;
173 guint length, pim_length;
174 guint16 pim_cksum, computed_cksum;
175 vec_t cksum_vec[1];
176 proto_tree *pim_tree = NULL;
177 proto_item *ti;
178 proto_tree *pimopt_tree = NULL;
179 proto_item *tiopt;
181 if (!proto_is_protocol_enabled(find_protocol_by_id(proto_pim))) {
183 * We are not enabled; skip entire packet to be nice to the
184 * IGMP layer (so clicking on IGMP will display the data).
186 return offset+tvb_length_remaining(tvb, offset);
189 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
190 col_clear(pinfo->cinfo, COL_INFO);
192 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, ENC_NA);
193 pim_tree = proto_item_add_subtree(ti, ett_pim);
195 /* Put IGMP type, 0x14, into the tree */
196 proto_tree_add_text(pim_tree, tvb, offset, 1, "Type: PIM (0x14)");
197 offset += 1;
199 pim_type = tvb_get_guint8(tvb, offset);
200 col_add_str(pinfo->cinfo, COL_INFO,
201 val_to_str(pim_type, type1vals, "Unknown (%u)"));
203 proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
204 offset += 1;
206 pim_cksum = tvb_get_ntohs(tvb, offset);
207 pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
208 if (pim_ver != 1) {
210 * Not PIMv1 - what gives?
212 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
213 offset, 2, pim_cksum);
215 offset += 2;
216 proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
217 return offset+tvb_length_remaining(tvb, offset);
221 * Well, it's PIM v1, so we can check whether this is a
222 * Register message, and thus can figure out how much to
223 * checksum and whether to make the columns read-only.
225 length = tvb_length(tvb);
226 if (pim_type == 1) {
228 * Register message - the PIM header is 8 bytes long.
229 * Also set the columns non-writable. Otherwise the IPv4 or
230 * IPv6 dissector for the encapsulated packet that caused
231 * this register will overwrite the PIM info in the columns.
233 pim_length = 8;
234 col_set_writable(pinfo->cinfo, FALSE);
235 } else {
237 * Other message - checksum the entire packet.
239 pim_length = tvb_reported_length(tvb);
242 if (!pinfo->fragmented && length >= pim_length) {
244 * The packet isn't part of a fragmented datagram and isn't
245 * truncated, so we can checksum it.
247 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
248 cksum_vec[0].len = pim_length;
249 computed_cksum = in_cksum(&cksum_vec[0], 1);
250 if (computed_cksum == 0) {
251 proto_tree_add_uint_format_value(pim_tree, hf_pim_cksum, tvb,
252 offset, 2, pim_cksum,
253 "0x%04x [correct]",
254 pim_cksum);
255 } else {
256 proto_tree_add_uint_format_value(pim_tree, hf_pim_cksum, tvb,
257 offset, 2, pim_cksum,
258 "0x%04x [incorrect, should be 0x%04x]",
259 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
261 } else {
262 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
263 offset, 2, pim_cksum);
265 offset += 2;
267 proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
268 offset += 1;
270 offset += 3; /* skip reserved stuff */
272 if (tvb_reported_length_remaining(tvb, offset) > 0) {
273 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1, "PIM options");
274 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim_opts);
275 } else
276 goto done;
278 /* version 1 decoder */
279 switch (pim_type) {
280 case 0: /* query */
282 guint16 holdtime;
284 proto_tree_add_item(pimopt_tree, hf_pim_mode, tvb, offset, 1, ENC_BIG_ENDIAN);
285 offset += 2;
287 holdtime = tvb_get_ntohs(tvb, offset);
288 proto_tree_add_uint_format_value(pimopt_tree, hf_pim_holdtime, tvb,
289 offset, 2, holdtime,
290 "%us %s", holdtime,
291 holdtime == 0xffff ? "(infinity)": "");
292 offset += 2;
293 break;
296 case 1: /* register */
298 guint8 v_hl;
299 tvbuff_t *next_tvb;
302 * The rest of the packet is a multicast data packet.
304 next_tvb = tvb_new_subset_remaining(tvb, offset);
307 * It's an IP packet - determine whether it's IPv4 or IPv6.
309 v_hl = tvb_get_guint8(tvb, offset);
310 switch((v_hl & 0xf0) >> 4) {
311 case 0: /* Null-Register dummy header.
312 * Has the same address family as the encapsulating PIM packet,
313 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
315 if (pinfo->src.type == AT_IPv4) {
316 proto_tree_add_text(pimopt_tree, tvb, offset, -1, "IPv4 dummy header");
317 proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
318 proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
319 } else if (pinfo->src.type == AT_IPv6) {
320 proto_tree_add_text(pimopt_tree, tvb, offset, -1, "IPv6 dummy header");
321 proto_tree_add_item(pimopt_tree, hf_pim_source_ip6, tvb, offset + 8, 16, ENC_NA);
322 proto_tree_add_item(pimopt_tree, hf_pim_group_ip6, tvb, offset + 8 + 16, 16, ENC_NA);
323 } else
324 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
325 "Dummy header for an unknown protocol");
326 break;
327 case 4: /* IPv4 */
328 if (use_main_tree) {
329 call_dissector(ip_handle, next_tvb, pinfo, tree);
330 } else {
331 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
333 break;
334 case 6: /* IPv6 */
335 if (use_main_tree) {
336 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
337 } else {
338 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
340 break;
341 default:
342 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
343 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
344 break;
346 break;
349 case 2: /* register-stop */
351 proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
352 offset += 4;
353 proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
354 offset += 4;
355 break;
358 case 3: /* join/prune */
359 case 6: /* graft */
360 case 7: /* graft-ack */
362 int off;
363 const char *s;
364 int ngroup, i, njoin, nprune, j;
365 guint16 holdtime;
366 guint8 mask_len;
367 guint8 adr_len;
368 proto_tree *grouptree = NULL;
369 proto_item *tigroup;
370 proto_tree *subtree = NULL;
371 proto_item *tisub;
373 proto_tree_add_item(pimopt_tree, hf_pim_upstream_neighbor_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
374 offset += 4;
376 offset += 2; /* skip reserved stuff */
378 holdtime = tvb_get_ntohs(tvb, offset);
379 proto_tree_add_uint_format_value(pimopt_tree, hf_pim_holdtime, tvb,
380 offset, 2, holdtime,
381 "%us %s", holdtime,
382 holdtime == 0xffff ? "(infinity)": "");
383 offset += 2;
385 offset += 1; /* skip reserved stuff */
387 mask_len = tvb_get_guint8(tvb, offset);
388 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
389 "Mask length: %u", mask_len);
390 offset += 1;
392 adr_len = tvb_get_guint8(tvb, offset);
393 proto_tree_add_text(pimopt_tree, tvb, offset, 1,
394 "Address length: %u", adr_len);
395 offset += 1;
397 ngroup = tvb_get_guint8(tvb, offset);
398 proto_tree_add_item(pimopt_tree, hf_pim_numgroups, tvb, offset, 1, ENC_BIG_ENDIAN);
399 offset += 1;
401 for (i = 0; i < ngroup; i++) {
403 * XXX - does the group address have the length "adr_len"
404 * and the group mask the length "mask_len"?
406 tigroup = proto_tree_add_ipv4_format(pimopt_tree, hf_pim_group_ip4, tvb, offset, 4,
407 tvb_get_ipv4(tvb, offset), "Group %d: %s", i, tvb_ip_to_str(tvb, offset));
408 grouptree = proto_item_add_subtree(tigroup, ett_pim);
409 offset += 4;
411 proto_tree_add_ipv4_format(grouptree, hf_pim_group_mask_ip4, tvb, offset, 4,
412 tvb_get_ipv4(tvb, offset), "Group %d Mask: %s", i, tvb_ip_to_str(tvb, offset));
413 offset += 4;
415 njoin = tvb_get_ntohs(tvb, offset);
416 nprune = tvb_get_ntohs(tvb, offset + 2);
417 tisub = proto_tree_add_item(grouptree, hf_pim_numjoins, tvb,
418 offset, 2, ENC_BIG_ENDIAN);
419 subtree = proto_item_add_subtree(tisub, ett_pim);
420 off = offset + 4;
421 for (j = 0; j < njoin; j++) {
422 s = dissect_pimv1_addr(tvb, off);
423 proto_tree_add_text(subtree, tvb, off, 6,
424 "IP address: %s", s);
425 off += 6;
428 tisub = proto_tree_add_item(grouptree, hf_pim_numprunes, tvb,
429 offset + 2, 2, ENC_BIG_ENDIAN);
430 subtree = proto_item_add_subtree(tisub, ett_pim);
431 for (j = 0; j < nprune; j++) {
432 s = dissect_pimv1_addr(tvb, off);
433 proto_tree_add_text(subtree, tvb, off, 6,
434 "IP address: %s", s);
435 off += 6;
437 offset = off;
439 break;
442 case 4: /* rp-reachability */
444 guint16 holdtime;
446 proto_tree_add_item(pimopt_tree, hf_pim_group_address_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
447 offset += 4;
449 proto_tree_add_item(pimopt_tree, hf_pim_group_mask_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
450 offset += 4;
452 proto_tree_add_item(pimopt_tree, hf_pim_rp_address_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
453 offset += 4;
455 offset += 2; /* skip reserved stuff */
457 holdtime = tvb_get_ntohs(tvb, offset);
458 proto_tree_add_uint_format_value(pimopt_tree, hf_pim_holdtime, tvb,
459 offset, 2, holdtime,
460 "%us %s", holdtime,
461 holdtime == 0xffff ? "(infinity)": "");
462 offset += 2;
463 break;
466 case 5: /* assert */
469 proto_tree_add_item(pimopt_tree, hf_pim_group_address_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
470 offset += 4;
472 proto_tree_add_item(pimopt_tree, hf_pim_group_mask_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
473 offset += 4;
475 proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
476 proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
477 offset, 4, ENC_BIG_ENDIAN);
478 offset += 4;
480 proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
481 offset += 4;
482 break;
485 default:
486 break;
488 done:;
490 return offset+tvb_length_remaining(tvb, offset);
493 static gboolean
494 dissect_pim_addr(proto_tree* tree, tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
495 const char* label, proto_item** ret_item, int hf_ip4, int hf_ip6, int *advance) {
496 guint8 af, et, flags, mask_len;
497 struct e_in6_addr ipv6;
498 guint32 ipv4;
499 proto_item* ti = NULL;
500 int len = 0;
502 af = tvb_get_guint8(tvb, offset);
503 if (af != AFNUM_INET && af != AFNUM_INET6) {
505 * We don't handle the other formats, and addresses don't include
506 * a length field, so we can't even show them as raw bytes.
508 return FALSE;
511 et = tvb_get_guint8(tvb, offset + 1);
512 if (et != 0) {
514 * The only defined encoding type is 0, for the native encoding;
515 * again, as addresses don't include a length field, we can't
516 * even show addresses with a different encoding type as raw
517 * bytes.
519 return FALSE;
522 switch (at) {
523 case pimv2_unicast:
524 switch (af) {
525 case AFNUM_INET:
526 len = 4;
527 ipv4 = tvb_get_ipv4(tvb, offset + 2);
528 if (label)
530 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 2 + len,
531 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 2));
533 else
535 ti = proto_tree_add_ipv4(tree, hf_ip4, tvb, offset, 2 + len, ipv4);
537 break;
539 case AFNUM_INET6:
540 len = 16;
541 tvb_get_ipv6(tvb, offset + 2, &ipv6);
542 if (label)
544 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 2 + len,
545 (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 2));
547 else
549 ti = proto_tree_add_ipv6(tree, hf_ip6, tvb, offset, 2 + len, (guint8 *)&ipv6);
551 break;
553 *advance = 2 + len;
554 break;
556 case pimv2_group:
557 mask_len = tvb_get_guint8(tvb, offset + 3);
558 switch (af) {
559 case AFNUM_INET:
560 len = 4;
561 ipv4 = tvb_get_ipv4(tvb, offset + 4);
562 if (label)
564 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 4 + len,
565 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 4));
567 else
569 ti = proto_tree_add_ipv4(tree, hf_ip4, tvb, offset, 4 + len, ipv4);
572 proto_item_append_text(ti, "/%u", mask_len);
573 break;
575 case AFNUM_INET6:
576 len = 16;
577 tvb_get_ipv6(tvb, offset + 4, &ipv6);
578 if (label)
580 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 4 + len,
581 (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 4));
583 else
585 ti = proto_tree_add_ipv6(tree, hf_ip6, tvb, offset, 4 + len, (guint8 *)&ipv6);
587 proto_item_append_text(ti, "/%u", mask_len);
588 break;
590 *advance = 4 + len;
591 break;
593 case pimv2_source:
594 flags = tvb_get_guint8(tvb, offset + 2);
595 mask_len = tvb_get_guint8(tvb, offset + 3);
596 switch (af) {
597 case AFNUM_INET:
598 len = 4;
599 ipv4 = tvb_get_ipv4(tvb, offset + 4);
600 if (label)
602 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 4 + len,
603 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 4));
605 else
607 ti = proto_tree_add_ipv4_format_value(tree, hf_ip4, tvb, offset, 4 + len, ipv4,
608 "%s", tvb_ip_to_str(tvb, offset + 4));
610 proto_item_append_text(ti, "/%u", mask_len);
611 break;
613 case AFNUM_INET6:
614 len = 16;
615 tvb_get_ipv6(tvb, offset + 4, &ipv6);
616 if (label)
618 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 4 + len,
619 (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 4));
621 else
623 ti = proto_tree_add_ipv6_format_value(tree, hf_ip6, tvb, offset, 4 + len, (guint8 *)&ipv6,
624 "%s", tvb_ip6_to_str(tvb, offset + 4));
626 proto_item_append_text(ti, "/%u", mask_len);
627 break;
629 if (flags) {
630 proto_item_append_text(ti, " (%s%s%s)",
631 flags & 0x04 ? "S" : "",
632 flags & 0x02 ? "W" : "",
633 flags & 0x01 ? "R" : "");
635 *advance = 4 + len;
636 break;
637 default:
638 return FALSE;
641 if (ret_item != NULL)
642 *ret_item = ti;
644 return TRUE;
647 static const value_string type2vals[] = {
648 { 0, "Hello" },
649 { 1, "Register" },
650 { 2, "Register-stop" },
651 { 3, "Join/Prune" },
652 { 4, "Bootstrap" },
653 { 5, "Assert" },
654 { 6, "Graft" },
655 { 7, "Graft-Ack" },
656 { 8, "Candidate-RP-Advertisement" },
657 { 9, "State-Refresh" },
658 { 0, NULL }
661 static const value_string pim_opt_vals[] = {
662 {1, "Hold Time"},
663 {2, "LAN Prune Delay"},
664 {18, "Deprecated and should not be used"},
665 {19, "DR Priority"},
666 {20, "Generation ID"},
667 {21, "State Refresh Capable"},
668 {22, "Bidir Capable"},
669 {24, "Address List"},
670 {65001, "Address List"}, /* old implementation */
671 {0, NULL}
675 * For PIM v2, see RFC 4601, RFC 3973 and draft-ietf-pim-sm-v2-new-03
676 * (when PIM is run over IPv6, the rules for computing the PIM checksum
677 * from the draft in question, not from RFC 2362, should be used).
679 static void
680 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
681 int offset = 0;
682 guint8 pim_typever;
683 guint length, pim_length;
684 guint16 pim_cksum, computed_cksum;
685 vec_t cksum_vec[4];
686 guint32 phdr[2];
687 const char *typestr;
688 proto_tree *pim_tree = NULL;
689 proto_item *ti;
690 proto_tree *pimopt_tree = NULL;
691 proto_item *tiopt;
693 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
694 col_clear(pinfo->cinfo, COL_INFO);
696 pim_typever = tvb_get_guint8(tvb, 0);
698 switch (PIM_VER(pim_typever)) {
699 case 2:
700 typestr = val_to_str(PIM_TYPE(pim_typever), type2vals, "Unknown (%u)");
701 break;
702 case 1: /* PIMv1 - we should never see this */
703 default:
704 typestr = "Unknown";
705 break;
708 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
709 PIM_VER(pim_typever));
710 col_add_str(pinfo->cinfo, COL_INFO, typestr);
712 ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, ENC_NA);
713 pim_tree = proto_item_add_subtree(ti, ett_pim);
715 proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
716 proto_tree_add_item(pim_tree, hf_pim_type, tvb, offset, 1, ENC_BIG_ENDIAN);
717 proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset + 1, 1, ENC_NA);
718 pim_cksum = tvb_get_ntohs(tvb, offset + 2);
719 length = tvb_length(tvb);
720 if (PIM_VER(pim_typever) == 2) {
722 * Well, it's PIM v2, so we can check whether this is a Register
723 * message, and thus can figure out how much to checksum and
724 * whether to make the columns read-only.
726 if (PIM_TYPE(pim_typever) == 1) {
728 * Register message - the PIM header is 8 bytes long.
729 * Also set the columns non-writable. Otherwise the IPv4 or
730 * IPv6 dissector for the encapsulated packet that caused
731 * this register will overwrite the PIM info in the columns.
733 pim_length = 8;
734 col_set_writable(pinfo->cinfo, FALSE);
735 } else {
737 * Other message - checksum the entire packet.
739 pim_length = tvb_reported_length(tvb);
741 } else {
743 * We don't know what type of message this is, so say that
744 * the length is 0, to force it not to be checksummed.
746 pim_length = 0;
748 if (!pinfo->fragmented && length >= pim_length) {
750 * The packet isn't part of a fragmented datagram and isn't
751 * truncated, so we can checksum it.
754 switch (pinfo->src.type) {
755 case AT_IPv4:
756 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, pim_length);
757 cksum_vec[0].len = pim_length;
758 computed_cksum = in_cksum(&cksum_vec[0], 1);
759 break;
760 case AT_IPv6:
761 /* Set up the fields of the pseudo-header. */
762 cksum_vec[0].ptr = (guint8 *)pinfo->src.data;
763 cksum_vec[0].len = pinfo->src.len;
764 cksum_vec[1].ptr = (guint8 *)pinfo->dst.data;
765 cksum_vec[1].len = pinfo->dst.len;
766 cksum_vec[2].ptr = (const guint8 *)&phdr;
767 phdr[0] = g_htonl(pim_length);
768 phdr[1] = g_htonl(IP_PROTO_PIM);
769 cksum_vec[2].len = 8;
770 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, pim_length);
771 cksum_vec[3].len = pim_length;
772 computed_cksum = in_cksum(&cksum_vec[0], 4);
773 break;
774 default:
775 /* PIM is available for IPv4 and IPv6 right now */
776 DISSECTOR_ASSERT_NOT_REACHED();
777 break;
780 if (computed_cksum == 0) {
781 proto_tree_add_uint_format_value(pim_tree, hf_pim_cksum, tvb,
782 offset + 2, 2, pim_cksum,
783 "0x%04x [correct]",
784 pim_cksum);
785 } else {
786 proto_tree_add_uint_format_value(pim_tree, hf_pim_cksum, tvb,
787 offset + 2, 2, pim_cksum,
788 "0x%04x [incorrect, should be 0x%04x]",
789 pim_cksum, in_cksum_shouldbe(pim_cksum, computed_cksum));
791 } else {
792 proto_tree_add_uint(pim_tree, hf_pim_cksum, tvb,
793 offset + 2, 2, pim_cksum);
796 offset += 4;
798 if (tvb_reported_length_remaining(tvb, offset) > 0) {
799 tiopt = proto_tree_add_text(pim_tree, tvb, offset, -1, "PIM options");
800 pimopt_tree = proto_item_add_subtree(tiopt, ett_pim_opts);
801 } else
802 goto done;
804 if (PIM_VER(pim_typever) != 2)
805 goto done;
807 /* version 2 decoder */
808 switch (PIM_TYPE(pim_typever)) {
809 case 0: /*hello*/
811 int opt_count = 0;
813 while (tvb_reported_length_remaining(tvb, offset) >= 2) {
814 guint16 hello_opt, opt_len;
815 guint16 opt_value;
816 proto_item *opt_item;
817 proto_tree *opt_tree;
819 opt_count++;
820 hello_opt = tvb_get_ntohs(tvb, offset);
821 opt_len = tvb_get_ntohs(tvb, offset + 2);
822 opt_item = proto_tree_add_text(pimopt_tree, tvb, offset, 4 + opt_len,
823 "Option %u: %s", hello_opt,
824 val_to_str(hello_opt, pim_opt_vals, "Unknown: %u"));
825 opt_tree = proto_item_add_subtree(opt_item, ett_pim_opt);
826 proto_tree_add_item(opt_tree, hf_pim_optiontype, tvb, offset, 2, ENC_BIG_ENDIAN);
827 proto_tree_add_item(opt_tree, hf_pim_optionlength, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
829 switch(hello_opt) {
830 case 1: /* Hello Hold Time Option */
831 opt_value = tvb_get_ntohs(tvb, offset + 4);
832 proto_tree_add_uint_format_value(opt_tree, hf_pim_holdtime, tvb,
833 offset + 4, opt_len, opt_value,
834 "%us %s", opt_value, opt_value == 0 ? "(goodbye)" :
835 opt_value == 0xffff ? "(infinity)": "");
836 proto_item_append_text(opt_item, ": %us %s", opt_value,
837 opt_value == 0 ? "(goodbye)" :
838 opt_value == 0xffff ? "(infinity)": "");
839 break;
841 case 2: /* LAN Prune Delay Option */
842 proto_tree_add_item(opt_tree, hf_pim_t, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
843 proto_tree_add_item(opt_tree, hf_pim_propagation_delay, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
844 proto_tree_add_item(opt_tree, hf_pim_override_interval, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
845 proto_item_append_text(opt_item,
846 ": T = %u, Propagation Delay = %ums, Override Interval = %ums",
847 tvb_get_guint8(tvb, offset + 4) & 0x80 ? 1 : 0,
848 tvb_get_ntohs(tvb, offset + 4) & 0x7fff,
849 tvb_get_ntohs(tvb, offset + 6));
850 break;
852 case 19: /* DR priority */
853 proto_tree_add_item(opt_tree, hf_pim_dr_priority, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
854 proto_item_append_text(opt_item, ": %u", tvb_get_ntohl(tvb, offset + 4));
855 break;
857 case 20: /* Generation ID */
858 proto_tree_add_item(opt_tree, hf_pim_generation_id, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
859 proto_item_append_text(opt_item, ": %u", tvb_get_ntohl(tvb, offset + 4));
860 break;
862 case 21: /* State Refresh Capable Option */
863 proto_tree_add_item(opt_tree, hf_pim_state_refresh_version, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
864 proto_tree_add_item(opt_tree, hf_pim_state_refresh_interval, tvb, offset + 5, 1, ENC_BIG_ENDIAN);
865 proto_tree_add_item(opt_tree, hf_pim_state_refresh_reserved, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
866 proto_item_append_text(opt_item, ": Version = %u, Interval = %us",
867 tvb_get_guint8(tvb, offset + 4),
868 tvb_get_guint8(tvb, offset + 5));
869 break;
871 case 24: /* address list */
872 case 65001: /* address list (old implementations) */
874 int i;
875 proto_tree *sub_tree = NULL;
876 proto_item *addrlist_option;
878 addrlist_option = proto_tree_add_text(opt_tree, tvb, offset, 4 + opt_len,
879 "%sAddress List (%u)",
880 hello_opt == 65001 ? "old " : "",
881 hello_opt);
882 sub_tree = proto_item_add_subtree(addrlist_option, ett_pim_opt);
883 for (i = offset + 4; i < offset + 4 + opt_len; ) {
884 int advance;
885 if (!dissect_pim_addr(sub_tree, tvb, i, pimv2_unicast, NULL, NULL,
886 hf_pim_address_list_ip4, hf_pim_address_list_ip6, &advance))
887 break;
888 i += advance;
890 break;
893 default:
894 if (opt_len)
895 proto_tree_add_item(opt_tree, hf_pim_optionvalue, tvb,
896 offset + 4, opt_len, ENC_NA);
897 break;
899 offset += 4 + opt_len;
901 proto_item_append_text(tiopt, ": %u", opt_count);
902 break;
905 case 1: /* register */
907 guint8 v_hl;
908 tvbuff_t *next_tvb;
909 proto_tree *flag_tree;
910 proto_item *tiflag;
912 tiflag = proto_tree_add_item(pimopt_tree, hf_pim_register_flag, tvb, offset, 4, ENC_BIG_ENDIAN);
913 flag_tree = proto_item_add_subtree(tiflag, ett_pim);
914 proto_tree_add_item(flag_tree, hf_pim_register_flag_border, tvb, offset, 4, ENC_BIG_ENDIAN);
915 proto_tree_add_item(flag_tree, hf_pim_register_flag_null_register, tvb, offset, 4, ENC_BIG_ENDIAN);
916 offset += 4;
919 * The rest of the packet is a multicast data packet.
921 next_tvb = tvb_new_subset_remaining(tvb, offset);
924 * It's an IP packet - determine whether it's IPv4 or IPv6.
926 v_hl = tvb_get_guint8(tvb, offset);
927 switch((v_hl & 0xf0) >> 4) {
928 case 0: /* Null-Register dummy header.
929 * Has the same address family as the encapsulating PIM packet,
930 * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
932 if (pinfo->src.type == AT_IPv4) {
933 proto_tree_add_text(pimopt_tree, tvb, offset, -1, "IPv4 dummy header");
934 proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
935 proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
936 } else if (pinfo->src.type == AT_IPv6) {
937 proto_tree_add_text(pimopt_tree, tvb, offset, -1, "IPv6 dummy header");
938 proto_tree_add_item(pimopt_tree, hf_pim_source_ip6, tvb, offset + 8, 16, ENC_NA);
939 proto_tree_add_item(pimopt_tree, hf_pim_group_ip6, tvb, offset + 8 + 16, 16, ENC_NA);
940 } else
941 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
942 "Dummy header for an unknown protocol");
943 break;
944 case 4: /* IPv4 */
945 if (use_main_tree) {
946 call_dissector(ip_handle, next_tvb, pinfo, tree);
947 } else {
948 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
950 break;
951 case 6: /* IPv6 */
952 if (use_main_tree) {
953 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
954 } else {
955 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
957 break;
958 default:
959 proto_tree_add_text(pimopt_tree, tvb, offset, -1,
960 "Unknown IP version %d", (v_hl & 0xf0) >> 4);
961 break;
963 break;
966 case 2: /* register-stop */
968 int advance;
970 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group, NULL, NULL,
971 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
972 break;
973 offset += advance;
974 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
975 hf_pim_source_ip4, hf_pim_source_ip6, &advance))
976 break;
977 break;
980 case 3: /* join/prune */
981 case 6: /* graft */
982 case 7: /* graft-ack */
984 int advance;
985 int off;
986 int ngroup, i, njoin, nprune, j;
987 guint16 holdtime;
988 proto_tree *grouptree = NULL;
989 proto_item *tigroup;
990 proto_tree *subtree = NULL;
991 proto_item *tisub;
993 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
994 hf_pim_upstream_neighbor_ip4, hf_pim_upstream_neighbor_ip6, &advance))
995 break;
997 offset += advance;
999 proto_tree_add_item(pimopt_tree, hf_pim_res_bytes, tvb, offset, 1, ENC_NA);
1000 offset += 1; /* skip reserved field */
1002 ngroup = tvb_get_guint8(tvb, offset);
1003 proto_tree_add_item(pimopt_tree, hf_pim_numgroups, tvb, offset, 1, ENC_BIG_ENDIAN);
1004 offset += 1;
1006 holdtime = tvb_get_ntohs(tvb, offset);
1007 proto_tree_add_uint_format_value(pimopt_tree, hf_pim_holdtime, tvb,
1008 offset, 2, holdtime,
1009 "%us %s", holdtime,
1010 holdtime == 0xffff ? "(infinity)": "");
1011 offset += 2;
1013 for (i = 0; i < ngroup; i++) {
1014 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1015 wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), &tigroup,
1016 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1017 goto breakbreak3;
1019 grouptree = proto_item_add_subtree(tigroup, ett_pim);
1020 offset += advance;
1022 njoin = tvb_get_ntohs(tvb, offset);
1023 nprune = tvb_get_ntohs(tvb, offset + 2);
1024 tisub = proto_tree_add_item(grouptree, hf_pim_numjoins, tvb,
1025 offset, 2, ENC_BIG_ENDIAN);
1026 subtree = proto_item_add_subtree(tisub, ett_pim);
1027 off = offset + 4;
1028 for (j = 0; j < njoin; j++) {
1029 if (!dissect_pim_addr(subtree, tvb, off, pimv2_source, NULL, NULL,
1030 hf_pim_join_ip4, hf_pim_join_ip6, &advance))
1031 goto breakbreak3;
1033 off += advance;
1036 tisub = proto_tree_add_item(grouptree, hf_pim_numprunes, tvb,
1037 offset + 2, 2, ENC_BIG_ENDIAN);
1038 subtree = proto_item_add_subtree(tisub, ett_pim);
1039 for (j = 0; j < nprune; j++) {
1040 if (!dissect_pim_addr(subtree, tvb, off, pimv2_source, NULL, NULL,
1041 hf_pim_prune_ip4, hf_pim_prune_ip6, &advance))
1042 goto breakbreak3;
1044 off += advance;
1046 offset = off;
1048 breakbreak3:
1049 break;
1052 case 4: /* bootstrap */
1054 int advance;
1055 int i, j;
1056 int frpcnt;
1057 guint16 holdtime;
1058 proto_tree *grouptree = NULL;
1059 proto_item *tigroup;
1061 proto_tree_add_item(pimopt_tree, hf_pim_fragment_tag, tvb,
1062 offset, 2, ENC_BIG_ENDIAN);
1063 offset += 2;
1065 proto_tree_add_item(pimopt_tree, hf_pim_hash_mask_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1066 offset += 1;
1067 proto_tree_add_item(pimopt_tree, hf_pim_bsr_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1068 offset += 1;
1070 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
1071 hf_pim_bsr_ip4, hf_pim_bsr_ip6, &advance))
1072 break;
1073 offset += advance;
1075 for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
1076 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1077 wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), &tigroup,
1078 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1079 goto breakbreak4;
1081 grouptree = proto_item_add_subtree(tigroup, ett_pim);
1082 offset += advance;
1084 proto_tree_add_item(grouptree, hf_pim_rp_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1085 offset += 1;
1086 frpcnt = tvb_get_guint8(tvb, offset);
1087 proto_tree_add_item(grouptree, hf_pim_frp_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1088 offset += 3;
1090 for (j = 0; j < frpcnt; j++) {
1091 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1092 wmem_strdup_printf(wmem_packet_scope(), "RP %d", j), NULL,
1093 hf_pim_rp_ip4, hf_pim_rp_ip6, &advance))
1095 goto breakbreak4;
1096 offset += advance;
1098 holdtime = tvb_get_ntohs(tvb, offset);
1099 proto_tree_add_uint_format_value(grouptree, hf_pim_holdtime, tvb,
1100 offset, 2, holdtime,
1101 "%us %s", holdtime,
1102 holdtime == 0xffff ? "(infinity)": "");
1103 offset += 2;
1104 proto_tree_add_item(grouptree, hf_pim_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1105 offset += 2; /* also skips reserved field */
1109 breakbreak4:
1110 break;
1113 case 5: /* assert */
1115 int advance;
1117 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1118 NULL, NULL,
1119 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1120 break;
1121 offset += advance;
1123 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1124 NULL, NULL,
1125 hf_pim_source_ip4, hf_pim_source_ip6, &advance))
1126 break;
1127 offset += advance;
1129 proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
1130 proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
1131 offset, 4, ENC_BIG_ENDIAN);
1132 offset += 4;
1134 proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1135 /* offset += 4;*/
1136 break;
1139 case 8: /* Candidate-RP-Advertisement */
1141 int advance;
1142 int pfxcnt;
1143 guint16 holdtime;
1144 int i;
1146 pfxcnt = tvb_get_guint8(tvb, offset);
1147 proto_tree_add_item(pimopt_tree, hf_pim_prefix_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1148 offset += 1;
1149 proto_tree_add_item(pimopt_tree, hf_pim_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1150 offset += 1;
1151 holdtime = tvb_get_ntohs(tvb, offset);
1152 proto_tree_add_uint_format_value(pimopt_tree, hf_pim_holdtime, tvb,
1153 offset, 2, holdtime,
1154 "%us %s", holdtime,
1155 holdtime == 0xffff ? "(infinity)": "");
1156 offset += 2;
1158 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1159 NULL, NULL,
1160 hf_pim_rp_ip4, hf_pim_rp_ip6, &advance))
1161 break;
1162 offset += advance;
1164 for (i = 0; i < pfxcnt; i++) {
1165 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1166 wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), NULL,
1167 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1168 goto breakbreak8;
1169 offset += advance;
1171 breakbreak8:
1172 break;
1175 case 9: /* State-Refresh */
1177 int advance;
1179 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1180 NULL, NULL,
1181 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1182 break;
1183 offset += advance;
1185 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1186 NULL, NULL,
1187 hf_pim_source_ip4, hf_pim_source_ip6, &advance))
1188 break;
1189 offset += advance;
1191 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1192 NULL, NULL,
1193 hf_pim_originator_ip4, hf_pim_originator_ip6, &advance))
1194 break;
1195 offset += advance;
1197 proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
1198 proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
1199 offset, 4, ENC_BIG_ENDIAN);
1200 offset += 4;
1202 proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1203 offset += 4;
1205 proto_tree_add_item(pimopt_tree, hf_pim_mask_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1206 offset += 1;
1208 proto_tree_add_item(pimopt_tree, hf_pim_ttl, tvb, offset, 1, ENC_BIG_ENDIAN);
1209 offset += 1;
1211 proto_tree_add_item(pimopt_tree, hf_pim_prune_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
1212 proto_tree_add_item(pimopt_tree, hf_pim_prune_now, tvb, offset, 1, ENC_BIG_ENDIAN);
1213 proto_tree_add_item(pimopt_tree, hf_pim_assert_override, tvb, offset, 1, ENC_BIG_ENDIAN);
1214 offset += 1;
1216 proto_tree_add_item(pimopt_tree, hf_pim_interval, tvb, offset, 1, ENC_BIG_ENDIAN);
1217 /*offset += 1;*/
1219 break;
1222 default:
1223 break;
1225 done:;
1228 void
1229 proto_register_pim(void)
1231 static hf_register_info hf[] =
1233 { &hf_pim_version,
1234 { "Version", "pim.version",
1235 FT_UINT8, BASE_DEC, NULL, 0xf0,
1236 NULL, HFILL }
1238 { &hf_pim_type,
1239 { "Type", "pim.type",
1240 FT_UINT8, BASE_DEC, VALS(type2vals), 0x0f,
1241 NULL, HFILL }
1243 { &hf_pim_code,
1244 { "Code", "pim.code",
1245 FT_UINT8, BASE_DEC, VALS(type1vals), 0x0,
1246 NULL, HFILL }
1248 { &hf_pim_cksum,
1249 { "Checksum", "pim.cksum",
1250 FT_UINT16, BASE_HEX, NULL, 0x0,
1251 NULL, HFILL }
1253 { &hf_pim_res_bytes,
1254 { "Reserved byte(s)", "pim.res_bytes",
1255 FT_BYTES, BASE_NONE, NULL, 0x0,
1256 NULL, HFILL }
1258 { &hf_pim_optiontype,
1259 { "Type", "pim.optiontype",
1260 FT_UINT16, BASE_DEC, NULL, 0x0,
1261 NULL, HFILL }
1263 { &hf_pim_optionlength,
1264 { "Length", "pim.optionlength",
1265 FT_UINT16, BASE_DEC, NULL, 0x0,
1266 NULL, HFILL }
1268 { &hf_pim_optionvalue,
1269 { "Unknown", "pim.optionvalue",
1270 FT_BYTES, BASE_NONE, NULL, 0x0,
1271 NULL, HFILL }
1273 { &hf_pim_register_flag,
1274 { "Flags", "pim.register_flag",
1275 FT_UINT32, BASE_HEX, NULL, 0x0,
1276 NULL, HFILL }
1278 { &hf_pim_register_flag_border,
1279 { "Border", "pim.register_flag.border",
1280 FT_BOOLEAN, 32, TFS(&tfs_yes_no), 0x80000000,
1281 NULL, HFILL }
1283 { &hf_pim_register_flag_null_register,
1284 { "Null-Register", "pim.register_flag.null_register",
1285 FT_BOOLEAN, 32, TFS(&tfs_yes_no), 0x40000000,
1286 NULL, HFILL }
1288 { &hf_pim_mode,
1289 { "Mode", "pim.mode",
1290 FT_UINT8, BASE_DEC, VALS(pimv1_modevals), 0xf0,
1291 NULL, HFILL }
1293 { &hf_pim_holdtime,
1294 { "Holdtime", "pim.holdtime",
1295 FT_UINT16, BASE_DEC, NULL, 0x0,
1296 "The amount of time a receiver must keep the neighbor "
1297 "reachable, in seconds.", HFILL }
1299 { &hf_pim_numgroups,
1300 { "Num Groups", "pim.numgroups",
1301 FT_UINT16, BASE_DEC, NULL, 0x0,
1302 "Number of multicast group sets contained in the message.",
1303 HFILL }
1305 { &hf_pim_numjoins,
1306 { "Num Joins", "pim.numjoins",
1307 FT_UINT16, BASE_DEC, NULL, 0x0,
1308 "Number of joined sources.", HFILL }
1310 { &hf_pim_numprunes,
1311 { "Num Prunes", "pim.numprunes",
1312 FT_UINT16, BASE_DEC, NULL, 0x0,
1313 "Number of pruned sources.", HFILL }
1315 { &hf_pim_t,
1316 { "T", "pim.t",
1317 FT_BOOLEAN, 8, NULL, 0x80,
1318 "Specifies the ability of the sending router to disable joins "
1319 "suppression.", HFILL }
1321 { &hf_pim_propagation_delay,
1322 { "Propagation Delay", "pim.propagation_delay",
1323 FT_UINT16, BASE_DEC, NULL, 0x07fff,
1324 "Units are milli-seconds", HFILL }
1326 { &hf_pim_override_interval,
1327 { "Override Interval", "pim.override_interval",
1328 FT_UINT16, BASE_DEC, NULL, 0x0,
1329 "Units are milli-seconds", HFILL }
1331 { &hf_pim_dr_priority,
1332 { "DR Priority", "pim.dr_priority",
1333 FT_UINT32, BASE_DEC, NULL, 0x0,
1334 NULL, HFILL }
1336 { &hf_pim_generation_id,
1337 { "Generation ID", "pim.generation_id",
1338 FT_UINT32, BASE_DEC, NULL, 0x0,
1339 NULL, HFILL }
1341 { &hf_pim_state_refresh_version,
1342 { "Version", "pim.state_refresh_version",
1343 FT_UINT8, BASE_DEC, NULL, 0x0,
1344 NULL, HFILL }
1346 { &hf_pim_state_refresh_interval,
1347 { "Interval", "pim.state_refresh_interval",
1348 FT_UINT8, BASE_DEC, NULL, 0x0,
1349 "Units in seconds.", HFILL }
1351 { &hf_pim_state_refresh_reserved,
1352 { "Reserved", "pim.state_refresh_reserved",
1353 FT_UINT16, BASE_DEC, NULL, 0x0,
1354 NULL, HFILL }
1356 { &hf_pim_rpt,
1357 { "RP Tree", "pim.rpt",
1358 FT_BOOLEAN, 8, NULL, 0x80,
1359 "Set to 1 for assert(*,G) messages and 0 for assert(S,G) "
1360 "messages.", HFILL }
1362 { &hf_pim_metric_pref ,
1363 { "Metric Preference", "pim.metric_pref",
1364 FT_UINT32, BASE_DEC, NULL, 0x7fffffff,
1365 NULL, HFILL }
1367 { &hf_pim_metric ,
1368 { "Metric", "pim.metric",
1369 FT_UINT32, BASE_DEC, NULL, 0x0,
1370 NULL, HFILL }
1372 { &hf_pim_prune_indicator ,
1373 { "Prune indicator", "pim.prune_indicator",
1374 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x80,
1375 NULL, HFILL }
1377 { &hf_pim_prune_now ,
1378 { "Prune now", "pim.prune_now",
1379 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
1380 NULL, HFILL }
1382 { &hf_pim_assert_override ,
1383 { "Assert override", "pim.assert_override",
1384 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x20,
1385 NULL, HFILL }
1387 { &hf_pim_source_ip4 ,
1388 { "Source", "pim.source",
1389 FT_IPv4, BASE_NONE, NULL, 0,
1390 NULL, HFILL }
1392 { &hf_pim_source_ip6 ,
1393 { "Source", "pim.source",
1394 FT_IPv6, BASE_NONE, NULL, 0,
1395 NULL, HFILL }
1397 { &hf_pim_group_ip4 ,
1398 { "Group", "pim.group",
1399 FT_IPv4, BASE_NONE, NULL, 0,
1400 NULL, HFILL }
1402 { &hf_pim_group_mask_ip4 ,
1403 { "Mask", "pim.group_mask",
1404 FT_IPv4, BASE_NONE, NULL, 0,
1405 NULL, HFILL }
1407 { &hf_pim_group_ip6 ,
1408 { "Group", "pim.group",
1409 FT_IPv6, BASE_NONE, NULL, 0,
1410 NULL, HFILL }
1412 { &hf_pim_upstream_neighbor_ip4 ,
1413 { "Upstream-neighbor", "pim.upstream_neighbor",
1414 FT_IPv4, BASE_NONE, NULL, 0,
1415 NULL, HFILL }
1417 { &hf_pim_upstream_neighbor_ip6 ,
1418 { "Upstream-neighbor", "pim.upstream_neighbor",
1419 FT_IPv6, BASE_NONE, NULL, 0,
1420 NULL, HFILL }
1422 { &hf_pim_join_ip4 ,
1423 { "IP address", "pim.join_ip",
1424 FT_IPv4, BASE_NONE, NULL, 0,
1425 NULL, HFILL }
1427 { &hf_pim_join_ip6 ,
1428 { "IP address", "pim.join_ip",
1429 FT_IPv6, BASE_NONE, NULL, 0,
1430 NULL, HFILL }
1432 { &hf_pim_prune_ip4 ,
1433 { "IP address", "pim.prune_ip",
1434 FT_IPv4, BASE_NONE, NULL, 0,
1435 NULL, HFILL }
1437 { &hf_pim_prune_ip6 ,
1438 { "IP address", "pim.prune_ip",
1439 FT_IPv6, BASE_NONE, NULL, 0,
1440 NULL, HFILL }
1442 { &hf_pim_address_list_ip4 ,
1443 { "Address", "pim.address_list",
1444 FT_IPv4, BASE_NONE, NULL, 0,
1445 NULL, HFILL }
1447 { &hf_pim_address_list_ip6 ,
1448 { "Address", "pim.address_list",
1449 FT_IPv6, BASE_NONE, NULL, 0,
1450 NULL, HFILL }
1452 { &hf_pim_bsr_ip4 ,
1453 { "BSR", "pim.bsr",
1454 FT_IPv4, BASE_NONE, NULL, 0,
1455 NULL, HFILL }
1457 { &hf_pim_bsr_ip6 ,
1458 { "BSR", "pim.bsr",
1459 FT_IPv6, BASE_NONE, NULL, 0,
1460 NULL, HFILL }
1462 { &hf_pim_rp_ip4 ,
1463 { "RP", "pim.rp",
1464 FT_IPv4, BASE_NONE, NULL, 0,
1465 NULL, HFILL }
1467 { &hf_pim_rp_ip6 ,
1468 { "RP", "pim.rp",
1469 FT_IPv6, BASE_NONE, NULL, 0,
1470 NULL, HFILL }
1472 { &hf_pim_originator_ip4 ,
1473 { "Originator", "pim.originator",
1474 FT_IPv4, BASE_NONE, NULL, 0,
1475 NULL, HFILL }
1477 { &hf_pim_originator_ip6 ,
1478 { "Originator", "pim.originator",
1479 FT_IPv6, BASE_NONE, NULL, 0,
1480 NULL, HFILL }
1482 { &hf_pim_group_address_ip4 ,
1483 { "Group Address", "pim.group_address",
1484 FT_IPv4, BASE_NONE, NULL, 0,
1485 NULL, HFILL }
1487 { &hf_pim_rp_address_ip4 ,
1488 { "RP Address", "pim.rp_address",
1489 FT_IPv4, BASE_NONE, NULL, 0,
1490 NULL, HFILL }
1492 { &hf_pim_fragment_tag,
1493 { "Fragment tag", "pim.fragment_tag",
1494 FT_UINT16, BASE_HEX, NULL, 0x0,
1495 NULL, HFILL }
1497 { &hf_pim_hash_mask_len,
1498 { "Hash mask len", "pim.hash_mask_len",
1499 FT_UINT8, BASE_DEC, NULL, 0x0,
1500 NULL, HFILL }
1502 { &hf_pim_bsr_priority,
1503 { "BSR priority", "pim.bsr_priority",
1504 FT_UINT8, BASE_DEC, NULL, 0x0,
1505 NULL, HFILL }
1507 { &hf_pim_rp_count,
1508 { "RP count", "pim.rp_count",
1509 FT_UINT8, BASE_DEC, NULL, 0x0,
1510 NULL, HFILL }
1512 { &hf_pim_frp_count,
1513 { "FRP count", "pim.frp_count",
1514 FT_UINT8, BASE_DEC, NULL, 0x0,
1515 NULL, HFILL }
1517 { &hf_pim_priority,
1518 { "Priority", "pim.priority",
1519 FT_UINT8, BASE_DEC, NULL, 0x0,
1520 NULL, HFILL }
1522 { &hf_pim_prefix_count,
1523 { "Prefix-count", "pim.prefix_count",
1524 FT_UINT8, BASE_DEC, NULL, 0x0,
1525 NULL, HFILL }
1527 { &hf_pim_mask_len,
1528 { "Masklen", "pim.mask_len",
1529 FT_UINT8, BASE_DEC, NULL, 0x0,
1530 NULL, HFILL }
1532 { &hf_pim_ttl,
1533 { "TTL", "pim.ttl",
1534 FT_UINT8, BASE_DEC, NULL, 0x0,
1535 NULL, HFILL }
1537 { &hf_pim_interval,
1538 { "Interval", "pim.interval",
1539 FT_UINT8, BASE_DEC, NULL, 0x0,
1540 NULL, HFILL }
1544 static gint *ett[] = {
1545 &ett_pim,
1546 &ett_pim_opts, /* Tree for all options */
1547 &ett_pim_opt /* Tree for each option */
1550 module_t *pim_module;
1552 proto_pim = proto_register_protocol("Protocol Independent Multicast",
1553 "PIM", "pim");
1554 proto_register_field_array(proto_pim, hf, array_length(hf));
1555 proto_register_subtree_array(ett, array_length(ett));
1557 pim_module = prefs_register_protocol(proto_pim, NULL);
1558 prefs_register_bool_preference(pim_module, "payload_tree",
1559 "PIM payload shown on main tree",
1560 "Whether the PIM payload is shown off of the main tree or encapsulated within the PIM options",
1561 &use_main_tree);
1565 void
1566 proto_reg_handoff_pim(void)
1568 dissector_handle_t pim_handle;
1570 pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1571 dissector_add_uint("ip.proto", IP_PROTO_PIM, pim_handle);
1574 * Get handles for the IPv4 and IPv6 dissectors.
1576 ip_handle = find_dissector("ip");
1577 ipv6_handle = find_dissector("ipv6");