Replace tabs in files with editor modeline "expandtab"
[metze/wireshark/wip.git] / epan / dissectors / packet-pim.c
1 /* packet-pim.c
2  * Routines for PIM disassembly
3  * (c) Copyright Jun-ichiro itojun Hagino <itojun@itojun.org>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <epan/packet.h>
27 #include <epan/ipproto.h>
28 #include <epan/afn.h>
29 #include <epan/prefs.h>
30 #include <epan/in_cksum.h>
31 #include <epan/to_str.h>
32 #include "packet-igmp.h"
33
34 void proto_register_pim(void);
35 void proto_reg_handoff_pim(void);
36
37 #define PIM_TYPE(x)             ((x) & 0x0f)
38 #define PIM_VER(x)              (((x) & 0xf0) >> 4)
39 #define PIM_BIDIR_SUBTYPE(x)    ((x) & 0x0f)
40 #define PIM_BIDIR_RSVD(x)       (((x) & 0xf0) >> 4)
41
42 /* PIM message type */
43
44 #define PIM_TYPE_HELLO 0            /* Hello [RFC3973][RFC4601] */
45 #define PIM_TYPE_REGISTER 1         /* Register [RFC4601] */
46 #define PIM_TYPE_REGISTER_STOP 2    /* Register Stop [RFC4601] */
47 #define PIM_TYPE_JOIN_PRUNE 3       /* Join/Prune [RFC3973][RFC4601] */
48 #define PIM_TYPE_BOOTSTRAP 4        /* Bootstrap [RFC4601] */
49 #define PIM_TYPE_ASSERT 5           /* Assert [RFC3973][RFC4601] */
50 #define PIM_TYPE_GRAFT 6            /* Graft [RFC3973] */
51 #define PIM_TYPE_GRAFT_ACK 7        /* Graft-Ack [RFC3973] */
52 #define PIM_TYPE_CAND_RP_ADV 8      /* Candidate RP Advertisement [RFC4601] */
53 #define PIM_TYPE_STATE_REFRESH 9    /* State Refresh [RFC3973] */
54 #define PIM_TYPE_DF_ELECT 10        /* DF Election [RFC5015] */
55 #define PIM_TYPE_ECMP_REDIR 11      /* ECMP Redirect [RFC6754] */
56
57 /* PIM Message hello options */
58
59 #define PIM_HELLO_HOLD_T 1          /* Hold Time [RFC4601] */
60 #define PIM_HELLO_LAN_PRUNE_DELAY 2 /*LAN Prune Delay [RFC3973] */
61 #define PIM_HELLO_LABEL_PARA 17     /* Label Parameters [Dino_Farinacci] */
62 #define PIM_HELLO_DR_PRIORITY 19    /* DR Priority */
63 #define PIM_HELLO_GEN_ID 20         /* Generation ID [RFC3973] */
64 #define PIM_HELLO_STATE_REFRESH 21  /* State-Refresh [RFC3973] */
65 #define PIM_HELLO_BIDIR_CAPA 22     /* Bidirectional Capable [RFC5015] */
66 #define PIM_HELLO_VCI_CAPA 23       /* VCI Capability */
67 #define PIM_HELLO_VAR_ADDR_LST 24   /* variable Address List [RFC4601] */
68 #define PIM_HELLO_VAR_NEIG_LST 25   /* variable Neighbor List TLV */
69 #define PIM_HELL0_JOIN_ATTR 26      /* Join Attribute [RFC5384] */
70 #define PIM_HELLO_O_TCP_CAPA 27     /* variable PIM-over-TCP-Capable */
71 #define PIM_HELLO_O_SCTP_CAPA 28    /* variable PIM-over-SCTP-Capable */
72 #define PIM_HELLO_VAR_POP_COUNT 29  /* variable Pop-Count [RFC6807] */
73 #define PIM_HELLO_MT_ID 30          /* PIM MT-ID [RFC6420] */
74 #define PIM_HELLO_INT_ID 31         /* Interface ID [RFC6395] */
75 #define PIM_HELLO_ECMP_REDIR  32    /* PIM ECMP Redirect Hello Option [RFC6754] */
76 #define PIM_HELLO_VPC_PEER_ID 33    /* 2 vPC Peer ID */
77 #define PIM_HELLO_DR_LB_CAPA 34     /* variable DR Load Balancing Capability [draft-ietf-pim-drlb] */
78 #define PIM_HELLO_LB_GDR 35         /* variable DR Load Balancing GDR (LBGDR) [draft-ietf-pim-drlb] */
79
80 /* PIM BIDIR DF election messages */
81
82 #define PIM_BDIR_DF_OFFER 1
83 #define PIM_BDIR_DF_WINNER 2
84 #define PIM_BDIR_DF_BACKOFF 3
85 #define PIM_BDIR_DF_PASS 4
86
87
88 static const value_string pimtypevals[] = {
89     { PIM_TYPE_HELLO, "Hello" },
90     { PIM_TYPE_REGISTER, "Register" },
91     { PIM_TYPE_REGISTER_STOP, "Register-stop" },
92     { PIM_TYPE_JOIN_PRUNE, "Join/Prune" },
93     { PIM_TYPE_BOOTSTRAP, "Bootstrap" },
94     { PIM_TYPE_ASSERT, "Assert" },
95     { PIM_TYPE_GRAFT, "Graft" },
96     { PIM_TYPE_GRAFT_ACK, "Graft-Ack" },
97     { PIM_TYPE_CAND_RP_ADV, "Candidate-RP-Advertisement" },
98     { PIM_TYPE_STATE_REFRESH, "State-Refresh" },
99     { PIM_TYPE_DF_ELECT, "DF election"},
100     { PIM_TYPE_ECMP_REDIR, "ECMP redirect" },
101     { 0, NULL }
102 };
103
104 static const value_string pimbdirdfvals[] = {
105     { PIM_BDIR_DF_OFFER, "offer"},
106     { PIM_BDIR_DF_WINNER, "DF Winner"},
107     { PIM_BDIR_DF_BACKOFF, "DF Backoff"},
108     { PIM_BDIR_DF_PASS, "DF Pass"},
109     { 0, NULL }
110 };
111
112 static const value_string pim_opt_vals[] = {
113     {1, "Hold Time"},
114     {2, "LAN Prune Delay"},
115     {18, "Deprecated and should not be used"},
116     {19, "DR Priority"},
117     {20, "Generation ID"},
118     {21, "State Refresh Capable"},
119     {22, "Bidir Capable"},
120     {24, "Address List"},
121     {65001, "Address List"},    /* old implementation */
122     {0, NULL}
123 };
124
125
126 enum pimv2_addrtype {
127     pimv2_unicast, pimv2_group, pimv2_source
128 };
129
130 static int proto_pim = -1;
131 static int hf_pim_version = -1;
132 static int hf_pim_type = -1;
133 static int hf_pim_code = -1;
134 static int hf_pim_igmp_type = -1;
135 static int hf_pim_df_elect_subtype = -1;
136 static int hf_pim_df_elect_rsvd = -1;
137 static int hf_pim_cksum = -1;
138 static int hf_pim_res_bytes = -1;
139 /* PIM Hello options (RFC 4601, section 4.9.2 and RFC 3973, section 4.7.5) */
140 static int hf_pim_option = -1;
141 static int hf_pim_optiontype = -1;
142 static int hf_pim_optionlength = -1;
143 static int hf_pim_optionvalue = -1;
144 static int hf_pim_register_flag = -1;
145 static int hf_pim_register_flag_border = -1;
146 static int hf_pim_register_flag_null_register = -1;
147 static int hf_pim_mode = -1;
148 static int hf_pim_holdtime = -1;
149 static int hf_pim_numgroups = -1;
150 static int hf_pim_numjoins = -1;
151 static int hf_pim_numprunes = -1;
152 static int hf_pim_t = -1;
153 static int hf_pim_propagation_delay = -1;
154 static int hf_pim_override_interval = -1;
155 static int hf_pim_dr_priority = -1;
156 static int hf_pim_generation_id = -1;
157 static int hf_pim_state_refresh_version = -1;
158 static int hf_pim_state_refresh_interval = -1;
159 static int hf_pim_state_refresh_reserved = -1;
160 /* Assert fields */
161 static int hf_pim_rpt = -1;
162 static int hf_pim_metric_pref = -1;
163 static int hf_pim_df_metric_pref = -1;
164 static int hf_pim_metric = -1;
165 static int hf_pim_prune_indicator = -1;
166 static int hf_pim_prune_now = -1;
167 static int hf_pim_assert_override = -1;
168 static int hf_pim_ip_version = -1;
169 static int hf_pim_dummy_header = -1;
170 static int hf_pim_source_ip4 = -1;
171 static int hf_pim_source_ip6 = -1;
172 static int hf_pim_group_ip4 = -1;
173 static int hf_pim_group_ip6 = -1;
174 static int hf_pim_group_mask_ip4 = -1;
175 static int hf_pim_upstream_neighbor_ip4 = -1;
176 static int hf_pim_upstream_neighbor_ip6 = -1;
177 static int hf_pim_join_ip4 = -1;
178 static int hf_pim_join_ip6 = -1;
179 static int hf_pim_prune_ip4 = -1;
180 static int hf_pim_prune_ip6 = -1;
181 static int hf_pim_address_list_ip4 = -1;
182 static int hf_pim_address_list_ip6 = -1;
183 static int hf_pim_bsr_ip4 = -1;
184 static int hf_pim_bsr_ip6 = -1;
185 static int hf_pim_rp_ip4 = -1;
186 static int hf_pim_rp_ip6 = -1;
187 static int hf_pim_bd_bo_offer_ip4 = -1;
188 static int hf_pim_bd_bo_offer_ip6 = -1;
189 static int hf_pim_bd_offer_metric_pref = -1;
190 static int hf_pim_bd_offer_metric = -1;
191 static int hf_pim_bd_offer_interval = -1;
192 static int hf_pim_bd_pass_ip4 = -1;
193 static int hf_pim_bd_pass_ip6 = -1;
194 static int hf_pim_bd_pass_metric_pref = -1;
195 static int hf_pim_bd_pass_metric = -1;
196 static int hf_pim_originator_ip4 = -1;
197 static int hf_pim_originator_ip6 = -1;
198 static int hf_pim_group_address_ip4 = -1;
199 static int hf_pim_fragment_tag = -1;
200 static int hf_pim_hash_mask_len = -1;
201 static int hf_pim_bsr_priority = -1;
202 static int hf_pim_rp_count = -1;
203 static int hf_pim_frp_count = -1;
204 static int hf_pim_priority = -1;
205 static int hf_pim_prefix_count = -1;
206 static int hf_pim_addr_len = -1;
207 static int hf_pim_src_flags_a = -1;
208 static int hf_pim_src_flags_s = -1;
209 static int hf_pim_src_flags_w = -1;
210 static int hf_pim_src_flags_r = -1;
211 static int hf_pim_src_flags_rsv = -1;
212 static int hf_pim_mask_len = -1;
213 static int hf_pim_ttl = -1;
214 static int hf_pim_interval = -1;
215
216 static gint ett_pim = -1;
217 static gint ett_pim_opts = -1;
218 static gint ett_pim_opt = -1;
219
220 static dissector_handle_t ip_handle;
221 static dissector_handle_t ipv6_handle;
222
223 static gboolean use_main_tree  = TRUE;
224
225 /*
226  * The Story About Ping^WPIM:
227  *
228  *   http://www.cs.usc.edu/assets/003/83187.pdf
229  *
230  * dated January 11, 1995, entitled "Protocol Independent Multicast (PIM):
231  * Protocol Specification", calls itself draft-ietf-idmr-pim-spec-01,
232  * and is in PostScript-converted-to-PDF form.  It describes a protocol
233  * that runs atop IGMP, with a type of 4 for "Router PIM Messages", and
234  * a PIM version number field of 1.
235  *
236  *   https://tools.ietf.org/html/draft-ietf-idmr-pim-sm-spec-00
237  *
238  * dated September 7, 1995, and
239  *
240  *   http://tools.ietf.org/html/draft-ietf-idmr-pim-spec-02
241  *
242  * dated September 7, 1995, both entitled "Protocol Independent Multicast-
243  * Sparse Mode (PIM-SM): Protocol Specification", describe a protocol that
244  * runs atop IGMP, with a type of 4 for "Router PIM Messages", and a PIM
245  * version number field of 2.
246  *
247  *   https://tools.ietf.org/html/draft-ietf-idmr-pim-sm-spec-03
248  *
249  * dated June 6, 1996, and all subsequent drafts, and RFC 2117, dated
250  * June 1997, all entitled "Protocol Independent Multicast-Sparse Mode
251  * (PIM-SM): Protocol Specification", describe a protocol that runs
252  * atop IP, with a protocol number of 103, and with a PIM version number
253  * field of 2. RFC 2117 was obsoleted by RFC 2362, which was obsoleted by
254  * RFC 4601.
255  *
256  * None of them, including the PDF from USC, appear to describe the protocol
257  * dissected by the dissect_pimv1() code.  In particular, none have a
258  * packet type value of 8 meaning "Mode"; the PDF from USC doesn't mention
259  * it at all, and subsequent drafts and RFC 2117 have (Candidate-)RP-
260  * Advertisement.  Perhaps what's dissected by dissect_pimv1() was
261  * something between the PDF and draft-ietf-idmr-pim-spec-02.
262  *
263  * Looking at the Dense Mode specs,
264  *
265  *   http://tools.ietf.org/html/draft-ietf-idmr-pim-dm-spec-02
266  *
267  * entitled "Protocol Independent Multicast-Dense Mode (PIM-DM): Protocol
268  * Specification", dated September 1995, describes a protocol that runs
269  * atop IGMP, with a type of 4 for "Router PIM Messages", and with a PIM
270  * version number field of 2.
271  *
272  * RFC 3973, entitled "Protocol Independent Multicast-Dense Mode (PIM-DM):
273  * Protocol Specification", also describes a protocol that runs atop IP,
274  * with a protocol number of 103, and with a PIM version number field of 2.
275  */
276 static const gint *pim_src_flags_fields[] = {
277     &hf_pim_src_flags_a,
278     &hf_pim_src_flags_s,
279     &hf_pim_src_flags_w,
280     &hf_pim_src_flags_r,
281     &hf_pim_src_flags_rsv,
282     NULL
283 };
284
285 static void
286 dissect_pimv1_addr(tvbuff_t *tvb, int offset, proto_tree *pim_tree, int hf_ip) {
287
288     proto_tree_add_bitmask_list(pim_tree, tvb, offset, 1, pim_src_flags_fields, ENC_BIG_ENDIAN);
289     offset += 1;
290
291     proto_tree_add_item(pim_tree, hf_pim_mask_len, tvb, offset, 1, ENC_BIG_ENDIAN);
292     offset += 1;
293
294     proto_tree_add_item(pim_tree, hf_ip, tvb, offset, 4, ENC_BIG_ENDIAN);
295
296 }
297
298 static const value_string pim_type1_vals[] = {
299     { 0, "Query" },
300     { 1, "Register" },
301     { 2, "Register-stop" },
302     { 3, "Join/Prune" },
303     { 4, "RP-Reachable" },
304     { 5, "Assert" },
305     { 6, "Graft" },
306     { 7, "Graft-Ack" },
307     { 8, "Mode" },
308     { 0, NULL },
309 };
310
311 static const value_string pimv1_modevals[] = {
312     { 0, "Dense" },
313     { 1, "Sparse" },
314     { 2, "Sparse-Dense" },
315     { 0, NULL }
316 };
317
318 static const value_string pim_ip_version_vals[] = {
319     { 0, "Dummy Header" },
320     { 4, "IPv4" },
321     { 6, "IPv6" },
322     { 0, NULL }
323 };
324 /* This function is only called from the IGMP dissector */
325 static int
326 dissect_pimv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
327     guint8 pim_type;
328     guint8 pim_ver;
329     guint length, pim_length;
330     guint16 pim_cksum, computed_cksum;
331     vec_t cksum_vec[1];
332     proto_tree *pim_tree = NULL;
333     proto_item *ti;
334     proto_tree *pimopt_tree = NULL;
335     proto_item *ticksum;
336     int offset = 0;
337
338     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIMv1");
339     col_clear(pinfo->cinfo, COL_INFO);
340
341     ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, ENC_NA);
342     pim_tree = proto_item_add_subtree(ti, ett_pim);
343
344     /* Put IGMP type, 0x14, into the tree */
345     proto_tree_add_string(pim_tree, hf_pim_igmp_type, tvb, offset, 0, "PIM (0x14)");
346
347     offset += 1;
348
349     pim_type = tvb_get_guint8(tvb, offset);
350     col_add_str(pinfo->cinfo, COL_INFO,
351                     val_to_str(pim_type, pim_type1_vals, "Unknown (%u)"));
352
353     proto_tree_add_uint(pim_tree, hf_pim_code, tvb, offset, 1, pim_type);
354     offset += 1;
355
356     pim_cksum = tvb_get_ntohs(tvb, offset);
357     ticksum = proto_tree_add_item(pim_tree, hf_pim_cksum, tvb, offset, 2, ENC_BIG_ENDIAN);
358     pim_ver = PIM_VER(tvb_get_guint8(tvb, offset + 2));
359     if (pim_ver != 1) {
360         /*
361          * Not PIMv1; should we bother dissecting the PIM drafts
362          * with a version number of 2 and with PIM running atop
363          * IGMP?
364          */
365         offset += 2;
366         proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
367         return offset+tvb_reported_length_remaining(tvb, offset);
368     }
369
370     /*
371      * Well, it's PIM v1, so we can check whether this is a
372      * Register message, and thus can figure out how much to
373      * checksum and whether to make the columns read-only.
374      */
375     length = tvb_reported_length(tvb);
376     if (pim_type == 1) {
377         /*
378          * Register message - the PIM header is 8 bytes long.
379          * Also set the columns non-writable. Otherwise the IPv4 or
380          * IPv6 dissector for the encapsulated packet that caused
381          * this register will overwrite the PIM info in the columns.
382          *
383          * XXX - that's not what draft-ietf-idmr-pim-spec-01 or
384          * draft-ietf-idmr-pim-spec-02 say; they say that the checksum
385          * covers the entire IGMP message.  Later drafts say it
386          * doesn't cover the encapsulated packet; perhaps that's what
387          * was always intended, and they just felt they needed to
388          * explicitly state that.
389          */
390         pim_length = 8;
391         col_set_writable(pinfo->cinfo, FALSE);
392     } else {
393         /*
394          * Other message - checksum the entire packet.
395          */
396         pim_length = length;
397     }
398
399     if (!pinfo->fragmented && length >= pim_length &&
400          tvb_captured_length(tvb) >= pim_length) {
401         /*
402          * The packet isn't part of a fragmented datagram and isn't
403          * truncated, so we can checksum it.
404          */
405         SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, pim_length);
406         computed_cksum = in_cksum(&cksum_vec[0], 1);
407         if (computed_cksum == 0) {
408              proto_item_append_text(ticksum, " [correct]");
409         } else {
410             proto_item_append_text(ticksum, " [incorrect, should be 0x%04x]", in_cksum_shouldbe(pim_cksum, computed_cksum));
411         }
412     }
413     offset += 2;
414
415     proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
416     offset += 1;
417
418     /* reserved stuff */
419     proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset, 3, ENC_NA);
420     offset += 3;
421
422     if (tvb_reported_length_remaining(tvb, offset) > 0) {
423         proto_item *subitem;
424         subitem = proto_tree_add_item(pim_tree, hf_pim_option, tvb, offset, -1, ENC_NA);
425         pimopt_tree = proto_item_add_subtree(subitem, ett_pim_opts);
426     } else
427         return offset;
428
429     /* version 1 decoder */
430     switch (pim_type) {
431     case 0:     /* query */
432     {
433         guint32 holdtime;
434         proto_item *ti_hold;
435
436         proto_tree_add_item(pimopt_tree, hf_pim_mode, tvb, offset, 1, ENC_BIG_ENDIAN);
437         offset += 2;
438
439         ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
440                                    offset, 2, ENC_BIG_ENDIAN, &holdtime);
441         if(holdtime == 0xFFFF){
442             proto_item_append_text(ti_hold, " (Infinity)");
443         }
444         offset += 2;
445         break;
446     }
447
448     case 1:     /* register */
449     {
450         guint8 v_hl;
451         tvbuff_t *next_tvb;
452
453         /*
454          * The rest of the packet is a multicast data packet.
455          */
456         next_tvb = tvb_new_subset_remaining(tvb, offset);
457
458         /*
459          * It's an IP packet - determine whether it's IPv4 or IPv6.
460          */
461         v_hl = tvb_get_guint8(tvb, offset);
462         proto_tree_add_item(pimopt_tree, hf_pim_ip_version, tvb, offset, 1, ENC_BIG_ENDIAN);
463
464         switch((v_hl & 0xf0) >> 4) {
465         case 0:     /* Null-Register dummy header.
466                      * Has the same address family as the encapsulating PIM packet,
467                      * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
468                      */
469             ti = proto_tree_add_item(pimopt_tree, hf_pim_dummy_header, tvb, offset, -1, ENC_NA);
470             if (pinfo->src.type == AT_IPv4) {
471                 proto_item_append_text(ti, " IPv4");
472                 proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
473                 proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
474             } else if (pinfo->src.type == AT_IPv6) {
475                 proto_item_append_text(ti, " IPv6");
476                 proto_tree_add_item(pimopt_tree, hf_pim_source_ip6, tvb, offset + 8, 16, ENC_NA);
477                 proto_tree_add_item(pimopt_tree, hf_pim_group_ip6, tvb, offset + 8 + 16, 16, ENC_NA);
478             } else
479                 proto_item_append_text(ti, " for an unknown protocol");
480
481             break;
482         case 4: /* IPv4 */
483             if (use_main_tree) {
484                 call_dissector(ip_handle, next_tvb, pinfo, tree);
485             } else {
486                 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
487             }
488             break;
489         case 6: /* IPv6 */
490             if (use_main_tree) {
491                 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
492             } else {
493                 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
494             }
495             break;
496         default:
497             break;
498         }
499         break;
500     }
501
502     case 2:     /* register-stop */
503     {
504         proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
505         offset += 4;
506         proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
507         offset += 4;
508         break;
509     }
510
511     case 3:     /* join/prune */
512     case 6:     /* graft */
513     case 7:     /* graft-ack */
514     {
515         int off;
516         int ngroup, i, njoin, nprune, j;
517         guint32 holdtime;
518         proto_tree *grouptree = NULL;
519         proto_item *tigroup;
520         proto_tree *subtree = NULL;
521         proto_item *tisub;
522         proto_item *ti_hold;
523
524         proto_tree_add_item(pimopt_tree, hf_pim_upstream_neighbor_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
525         offset += 4;
526
527         /* reserved stuff */
528         proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset, 2, ENC_NA);
529         offset += 2;
530
531         ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
532                                    offset, 2, ENC_BIG_ENDIAN, &holdtime);
533         if(holdtime == 0xFFFF){
534             proto_item_append_text(ti_hold, " (Infinity)");
535         }
536         offset += 2;
537
538         /* reserved stuff */
539         proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset, 1, ENC_NA);
540         offset += 1;
541
542         proto_tree_add_item(pimopt_tree, hf_pim_mask_len, tvb, offset, 1, ENC_NA);
543         offset += 1;
544
545         proto_tree_add_item(pimopt_tree, hf_pim_addr_len, tvb, offset, 1, ENC_NA);
546         offset += 1;
547
548         ngroup = tvb_get_guint8(tvb, offset);
549         proto_tree_add_item(pimopt_tree, hf_pim_numgroups, tvb, offset, 1, ENC_BIG_ENDIAN);
550         offset += 1;
551
552         for (i = 0; i < ngroup; i++) {
553             /*
554              * XXX - does the group address have the length "adr_len"
555              * and the group mask the length "mask_len"?
556              */
557             tigroup = proto_tree_add_ipv4_format(pimopt_tree, hf_pim_group_ip4, tvb, offset, 4,
558                                 tvb_get_ipv4(tvb, offset), "Group %d: %s", i, tvb_ip_to_str(tvb, offset));
559             grouptree = proto_item_add_subtree(tigroup, ett_pim);
560             offset += 4;
561
562             proto_tree_add_ipv4_format(grouptree, hf_pim_group_mask_ip4, tvb, offset, 4,
563                                 tvb_get_ipv4(tvb, offset), "Group %d Mask: %s", i, tvb_ip_to_str(tvb, offset));
564             offset += 4;
565
566             njoin = tvb_get_ntohs(tvb, offset);
567             nprune = tvb_get_ntohs(tvb, offset + 2);
568             tisub = proto_tree_add_item(grouptree, hf_pim_numjoins, tvb,
569                                         offset, 2, ENC_BIG_ENDIAN);
570             subtree = proto_item_add_subtree(tisub, ett_pim);
571             off = offset + 4;
572             for (j = 0; j < njoin; j++) {
573                 dissect_pimv1_addr(tvb, off, subtree, hf_pim_join_ip4);
574                 off += 6;
575             }
576
577             tisub = proto_tree_add_item(grouptree, hf_pim_numprunes, tvb,
578                                         offset + 2, 2, ENC_BIG_ENDIAN);
579             subtree = proto_item_add_subtree(tisub, ett_pim);
580             for (j = 0; j < nprune; j++) {
581                 dissect_pimv1_addr(tvb, off, subtree, hf_pim_prune_ip4);
582                 off += 6;
583             }
584             offset = off;
585         }
586         break;
587     }
588
589     case 4:     /* rp-reachability */
590     {
591         guint32 holdtime;
592         proto_item *ti_hold;
593
594         proto_tree_add_item(pimopt_tree, hf_pim_group_address_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
595         offset += 4;
596
597         proto_tree_add_item(pimopt_tree, hf_pim_group_mask_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
598         offset += 4;
599
600         proto_tree_add_item(pimopt_tree, hf_pim_rp_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
601         offset += 4;
602
603         /* reserved stuff */
604         proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset, 2, ENC_NA);
605         offset += 2;
606
607         ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
608                                    offset, 2, ENC_BIG_ENDIAN, &holdtime);
609         if(holdtime == 0xFFFF){
610             proto_item_append_text(ti_hold, " (Infinity)");
611         }
612         offset += 2;
613         break;
614     }
615
616     case 5:     /* assert */
617     {
618
619         proto_tree_add_item(pimopt_tree, hf_pim_group_address_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
620         offset += 4;
621
622         proto_tree_add_item(pimopt_tree, hf_pim_group_mask_ip4, tvb, offset, 4, ENC_BIG_ENDIAN);
623         offset += 4;
624
625         proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
626         proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
627                                    offset, 4, ENC_BIG_ENDIAN);
628         offset += 4;
629
630         proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
631         offset += 4;
632         break;
633     }
634
635     default:
636         break;
637     }
638
639     return offset;
640 }
641
642 static gboolean
643 dissect_pim_addr(proto_tree* tree, tvbuff_t *tvb, int offset, enum pimv2_addrtype at,
644                  const char* label, proto_item** ret_item, int hf_ip4, int hf_ip6, int *advance) {
645     guint8 af, et, flags, mask_len;
646     struct e_in6_addr ipv6;
647     guint32 ipv4;
648     proto_item* ti = NULL;
649     int len = 0;
650
651     af = tvb_get_guint8(tvb, offset);
652     if (af != AFNUM_INET && af != AFNUM_INET6) {
653         /*
654          * We don't handle the other formats, and addresses don't include
655          * a length field, so we can't even show them as raw bytes.
656          */
657         return FALSE;
658     }
659
660     et = tvb_get_guint8(tvb, offset + 1);
661     if (et != 0) {
662         /*
663          * The only defined encoding type is 0, for the native encoding;
664          * again, as addresses don't include a length field, we can't
665          * even show addresses with a different encoding type as raw
666          * bytes.
667          */
668         return FALSE;
669     }
670
671     switch (at) {
672     case pimv2_unicast:
673         switch (af) {
674         case AFNUM_INET:
675             len = 4;
676             ipv4 = tvb_get_ipv4(tvb, offset + 2);
677             if (label)
678             {
679                 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 2 + len,
680                                 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 2));
681             }
682             else
683             {
684                 ti = proto_tree_add_ipv4(tree, hf_ip4, tvb, offset, 2 + len, ipv4);
685             }
686             break;
687
688         case AFNUM_INET6:
689             len = 16;
690             tvb_get_ipv6(tvb, offset + 2, &ipv6);
691             if (label)
692             {
693                 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 2 + len,
694                         (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 2));
695             }
696             else
697             {
698                 ti = proto_tree_add_ipv6(tree, hf_ip6, tvb, offset, 2 + len, (guint8 *)&ipv6);
699             }
700             break;
701         }
702         *advance = 2 + len;
703         break;
704
705     case pimv2_group:
706         mask_len = tvb_get_guint8(tvb, offset + 3);
707         switch (af) {
708         case AFNUM_INET:
709             len = 4;
710             ipv4 = tvb_get_ipv4(tvb, offset + 4);
711             if (label)
712             {
713                 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 4 + len,
714                                 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 4));
715             }
716             else
717             {
718                 ti = proto_tree_add_ipv4(tree, hf_ip4, tvb, offset, 4 + len, ipv4);
719             }
720
721             proto_item_append_text(ti, "/%u", mask_len);
722             break;
723
724         case AFNUM_INET6:
725             len = 16;
726             tvb_get_ipv6(tvb, offset + 4, &ipv6);
727             if (label)
728             {
729                 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 4 + len,
730                         (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 4));
731             }
732             else
733             {
734                 ti = proto_tree_add_ipv6(tree, hf_ip6, tvb, offset, 4 + len, (guint8 *)&ipv6);
735             }
736             proto_item_append_text(ti, "/%u", mask_len);
737             break;
738         }
739         *advance = 4 + len;
740         break;
741
742     case pimv2_source:
743         flags = tvb_get_guint8(tvb, offset + 2);
744         mask_len = tvb_get_guint8(tvb, offset + 3);
745         switch (af) {
746         case AFNUM_INET:
747             len = 4;
748             ipv4 = tvb_get_ipv4(tvb, offset + 4);
749             if (label)
750             {
751                 ti = proto_tree_add_ipv4_format(tree, hf_ip4, tvb, offset, 4 + len,
752                                 ipv4, "%s: %s", label, tvb_ip_to_str(tvb, offset + 4));
753             }
754             else
755             {
756                 ti = proto_tree_add_ipv4_format_value(tree, hf_ip4, tvb, offset, 4 + len, ipv4,
757                                                       "%s", tvb_ip_to_str(tvb, offset + 4));
758             }
759             proto_item_append_text(ti, "/%u", mask_len);
760             break;
761
762         case AFNUM_INET6:
763             len = 16;
764             tvb_get_ipv6(tvb, offset + 4, &ipv6);
765             if (label)
766             {
767                 ti = proto_tree_add_ipv6_format(tree, hf_ip6, tvb, offset, 4 + len,
768                         (guint8 *)&ipv6, "%s: %s", label, tvb_ip6_to_str(tvb, offset + 4));
769             }
770             else
771             {
772                 ti = proto_tree_add_ipv6_format_value(tree, hf_ip6, tvb, offset, 4 + len, (guint8 *)&ipv6,
773                                                       "%s", tvb_ip6_to_str(tvb, offset + 4));
774             }
775             proto_item_append_text(ti, "/%u", mask_len);
776             break;
777         }
778         if (flags) {
779             proto_item_append_text(ti, " (%s%s%s)",
780                                     flags & 0x04 ? "S" : "",
781                                     flags & 0x02 ? "W" : "",
782                                     flags & 0x01 ? "R" : "");
783         }
784         *advance = 4 + len;
785         break;
786     default:
787         return FALSE;
788     }
789
790     if (ret_item != NULL)
791         *ret_item = ti;
792
793     return TRUE;
794 }
795
796
797 /*
798  * For PIM v2, see RFC 4601, RFC 3973 and draft-ietf-pim-sm-v2-new-03
799  * (when PIM is run over IPv6, the rules for computing the PIM checksum
800  * from the draft in question, not from RFC 2362, should be used).
801  */
802 static void
803 dissect_pim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
804     int offset = 0;
805     guint8 pim_typever;
806     guint8 pim_bidir_subtype = 0;
807     guint length, pim_length;
808     guint16 pim_cksum, computed_cksum;
809     vec_t cksum_vec[4];
810     guint32 phdr[2];
811     const char *typestr;
812     proto_tree *pim_tree = NULL;
813     proto_item *ti;
814     proto_tree *pimopt_tree = NULL;
815     proto_item *tiopt, *ticksum;
816
817     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PIM");
818     col_clear(pinfo->cinfo, COL_INFO);
819
820     pim_typever = tvb_get_guint8(tvb, 0);
821
822     switch (PIM_VER(pim_typever)) {
823     case 2:
824         typestr = val_to_str(PIM_TYPE(pim_typever), pimtypevals, "Unknown (%u)");
825         break;
826     case 1:     /* PIMv1 - we should never see this */
827     default:
828         typestr = "Unknown";
829         break;
830     }
831
832     col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "PIMv%d",
833                      PIM_VER(pim_typever));
834     col_add_str(pinfo->cinfo, COL_INFO, typestr);
835
836     ti = proto_tree_add_item(tree, proto_pim, tvb, offset, -1, ENC_NA);
837     pim_tree = proto_item_add_subtree(ti, ett_pim);
838
839     proto_tree_add_item(pim_tree, hf_pim_version, tvb, offset, 1, ENC_BIG_ENDIAN);
840     proto_tree_add_item(pim_tree, hf_pim_type, tvb, offset, 1, ENC_BIG_ENDIAN);
841     if (PIM_TYPE(pim_typever) == PIM_TYPE_DF_ELECT) {
842         proto_tree_add_item(pim_tree, hf_pim_df_elect_subtype, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
843         proto_tree_add_item(pim_tree, hf_pim_df_elect_rsvd, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
844         pim_bidir_subtype = tvb_get_guint8(tvb,offset);
845     }
846     else {
847         proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset + 1, 1, ENC_NA);
848     }
849     pim_cksum = tvb_get_ntohs(tvb, offset + 2);
850     ticksum = proto_tree_add_item(pim_tree, hf_pim_cksum, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
851
852     if (PIM_VER(pim_typever) != 2) {
853         /*
854          * We don't know this version, so we don't know how much of the
855          * packet the checksum covers.
856          */
857         if (tvb_reported_length_remaining(tvb, offset) > 0) {
858             proto_tree_add_item(pim_tree, hf_pim_option, tvb, offset, -1, ENC_NA);
859         }
860         goto done;
861     }
862
863     /*
864      * Well, it's PIM v2, so we can check whether this is a Register
865      * message, and thus can figure out how much to checksum and
866      * whether to make the columns read-only.
867      */
868     length = tvb_reported_length(tvb);
869     if (PIM_TYPE(pim_typever) == 1) {
870         /*
871          * Register message - the PIM header is 8 bytes long.
872          * Also set the columns non-writable. Otherwise the IPv4 or
873          * IPv6 dissector for the encapsulated packet that caused
874          * this register will overwrite the PIM info in the columns.
875          */
876         pim_length = 8;
877         col_set_writable(pinfo->cinfo, FALSE);
878     } else {
879         /*
880          * Other message - checksum the entire packet.
881          */
882         pim_length = length;
883     }
884     if (!pinfo->fragmented && length >= pim_length &&
885          tvb_captured_length(tvb) >= pim_length) {
886         /*
887          * The packet isn't part of a fragmented datagram and isn't
888          * truncated, so we can checksum it.
889          */
890
891         switch (pinfo->src.type) {
892         case AT_IPv4:
893             SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, pim_length);
894             computed_cksum = in_cksum(&cksum_vec[0], 1);
895             break;
896         case AT_IPv6:
897             /* Set up the fields of the pseudo-header. */
898             SET_CKSUM_VEC_PTR(cksum_vec[0], (const guint8 *)pinfo->src.data, pinfo->src.len);
899             SET_CKSUM_VEC_PTR(cksum_vec[1], (const guint8 *)pinfo->dst.data, pinfo->dst.len);
900             phdr[0] = g_htonl(pim_length);
901             phdr[1] = g_htonl(IP_PROTO_PIM);
902             SET_CKSUM_VEC_PTR(cksum_vec[2], (const guint8 *)&phdr, 8);
903             SET_CKSUM_VEC_TVB(cksum_vec[3], tvb, 0, pim_length);
904             computed_cksum = in_cksum(&cksum_vec[0], 4);
905             break;
906         default:
907             /* PIM is available for IPv4 and IPv6 right now */
908             DISSECTOR_ASSERT_NOT_REACHED();
909             break;
910         }
911
912         if (computed_cksum == 0) {
913             proto_item_append_text(ticksum, " [correct]");
914
915         } else {
916             proto_item_append_text(ticksum, " [incorrect, should be 0x%04x]", in_cksum_shouldbe(pim_cksum, computed_cksum));
917         }
918     }
919     offset += 4;
920
921     if (tvb_reported_length_remaining(tvb, offset) > 0) {
922         tiopt = proto_tree_add_item(pim_tree, hf_pim_option, tvb, offset, -1, ENC_NA);
923         pimopt_tree = proto_item_add_subtree(tiopt, ett_pim_opts);
924     } else
925         goto done;
926
927     /* version 2 decoder */
928     switch (PIM_TYPE(pim_typever)) {
929     case PIM_TYPE_HELLO:     /*hello*/
930     {
931         int opt_count = 0;
932
933         while (tvb_reported_length_remaining(tvb, offset) >= 2) {
934             guint16 hello_opt, opt_len;
935             guint32 holdtime;
936             proto_item *opt_item;
937             proto_item *ti_hold;
938             proto_tree *opt_tree;
939
940             opt_count++;
941             hello_opt = tvb_get_ntohs(tvb, offset);
942             opt_len = tvb_get_ntohs(tvb, offset + 2);
943             opt_tree = proto_tree_add_subtree_format(pimopt_tree, tvb, offset, 4 + opt_len,
944                                            ett_pim_opt, &opt_item, "Option %u: %s", hello_opt,
945                                            val_to_str(hello_opt, pim_opt_vals, "Unknown: %u"));
946             proto_tree_add_item(opt_tree, hf_pim_optiontype, tvb, offset, 2, ENC_BIG_ENDIAN);
947             proto_tree_add_item(opt_tree, hf_pim_optionlength, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
948
949             switch(hello_opt) {
950             case PIM_HELLO_HOLD_T: /* Hello Hold Time Option */
951
952                 ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
953                                            offset, 2, ENC_BIG_ENDIAN, &holdtime);
954                 switch(holdtime){
955                     case 0:
956                         proto_item_append_text(ti_hold, " (goodbye)");
957                         proto_item_append_text(opt_item, " (goodbye)");
958                     break;
959                     case 0xFFFF:
960                         proto_item_append_text(ti_hold, " (Infinity)");
961                         proto_item_append_text(opt_item, " (Infinity)");
962                     break;
963                     default:
964                         /* no default action */
965                     break;
966                 }
967                 break;
968
969             case PIM_HELLO_LAN_PRUNE_DELAY: /* LAN Prune Delay Option */
970                 proto_tree_add_item(opt_tree, hf_pim_t, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
971                 proto_tree_add_item(opt_tree, hf_pim_propagation_delay, tvb, offset + 4, 2, ENC_BIG_ENDIAN);
972                 proto_tree_add_item(opt_tree, hf_pim_override_interval, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
973                 proto_item_append_text(opt_item,
974                                        ": T = %u, Propagation Delay = %ums, Override Interval = %ums",
975                                        tvb_get_guint8(tvb, offset + 4) & 0x80 ? 1 : 0,
976                                        tvb_get_ntohs(tvb, offset + 4) & 0x7fff,
977                                        tvb_get_ntohs(tvb, offset + 6));
978                 break;
979
980             case PIM_HELLO_DR_PRIORITY: /* DR priority */
981                 proto_tree_add_item(opt_tree, hf_pim_dr_priority, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
982                 proto_item_append_text(opt_item, ": %u", tvb_get_ntohl(tvb, offset + 4));
983                 break;
984
985             case PIM_HELLO_GEN_ID: /* Generation ID */
986                 proto_tree_add_item(opt_tree, hf_pim_generation_id, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
987                 proto_item_append_text(opt_item, ": %u", tvb_get_ntohl(tvb, offset + 4));
988                 break;
989
990             case PIM_HELLO_STATE_REFRESH: /* State Refresh Capable Option */
991                 proto_tree_add_item(opt_tree, hf_pim_state_refresh_version, tvb, offset + 4, 1, ENC_BIG_ENDIAN);
992                 proto_tree_add_item(opt_tree, hf_pim_state_refresh_interval, tvb, offset + 5, 1, ENC_BIG_ENDIAN);
993                 proto_tree_add_item(opt_tree, hf_pim_state_refresh_reserved, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
994                 proto_item_append_text(opt_item, ": Version = %u, Interval = %us",
995                                        tvb_get_guint8(tvb, offset + 4),
996                                        tvb_get_guint8(tvb, offset + 5));
997                 break;
998
999             case PIM_HELLO_VAR_ADDR_LST: /* address list */
1000             case 65001: /* address list (old implementations) */
1001             {
1002                 int i;
1003                 proto_tree *sub_tree = NULL;
1004
1005                 sub_tree = proto_tree_add_subtree_format(opt_tree, tvb, offset, 4 + opt_len,
1006                                                       ett_pim_opt, NULL, "%sAddress List (%u)",
1007                                                       hello_opt == 65001 ? "old " : "",
1008                                                       hello_opt);
1009                 for (i = offset + 4; i < offset + 4 + opt_len; ) {
1010                     int advance;
1011                     if (!dissect_pim_addr(sub_tree, tvb, i, pimv2_unicast, NULL, NULL,
1012                                                hf_pim_address_list_ip4, hf_pim_address_list_ip6, &advance))
1013                         break;
1014                     i += advance;
1015                 }
1016                 break;
1017             }
1018             case PIM_HELLO_LABEL_PARA:
1019             case PIM_HELLO_BIDIR_CAPA:
1020             case PIM_HELLO_VCI_CAPA:
1021             case PIM_HELLO_VAR_NEIG_LST:
1022             case PIM_HELL0_JOIN_ATTR:
1023             case PIM_HELLO_O_TCP_CAPA:
1024             case PIM_HELLO_O_SCTP_CAPA:
1025             case PIM_HELLO_VAR_POP_COUNT:
1026             case PIM_HELLO_MT_ID:
1027             case PIM_HELLO_INT_ID:
1028             case PIM_HELLO_ECMP_REDIR:
1029             case PIM_HELLO_VPC_PEER_ID:
1030             case PIM_HELLO_DR_LB_CAPA:
1031             case PIM_HELLO_LB_GDR:
1032             default:
1033                 if (opt_len)
1034                     proto_tree_add_item(opt_tree, hf_pim_optionvalue, tvb,
1035                                         offset + 4, opt_len, ENC_NA);
1036                 break;
1037             }
1038             offset += 4 + opt_len;
1039         }
1040         proto_item_append_text(tiopt, ": %u", opt_count);
1041         break;
1042     }
1043
1044     case PIM_TYPE_REGISTER:     /* register */
1045     {
1046         guint8 v_hl;
1047         tvbuff_t *next_tvb;
1048         proto_tree *flag_tree;
1049         proto_item *tiflag;
1050
1051         tiflag = proto_tree_add_item(pimopt_tree, hf_pim_register_flag, tvb, offset, 4, ENC_BIG_ENDIAN);
1052         flag_tree = proto_item_add_subtree(tiflag, ett_pim);
1053         proto_tree_add_item(flag_tree, hf_pim_register_flag_border, tvb, offset, 4, ENC_BIG_ENDIAN);
1054         proto_tree_add_item(flag_tree, hf_pim_register_flag_null_register, tvb, offset, 4, ENC_BIG_ENDIAN);
1055         offset += 4;
1056
1057         /*
1058          * The rest of the packet is a multicast data packet.
1059          */
1060         next_tvb = tvb_new_subset_remaining(tvb, offset);
1061
1062         /*
1063          * It's an IP packet - determine whether it's IPv4 or IPv6.
1064          */
1065         v_hl = tvb_get_guint8(tvb, offset);
1066         proto_tree_add_item(pimopt_tree, hf_pim_ip_version, tvb, offset, 1, ENC_BIG_ENDIAN);
1067
1068         switch((v_hl & 0xf0) >> 4) {
1069         case 0:     /* Null-Register dummy header.
1070                      * Has the same address family as the encapsulating PIM packet,
1071                      * e.g. an IPv6 data packet is encapsulated in IPv6 PIM packet.
1072                      */
1073             ti = proto_tree_add_item(pimopt_tree, hf_pim_dummy_header, tvb, offset, -1, ENC_NA);
1074             if (pinfo->src.type == AT_IPv4) {
1075                 proto_item_append_text(ti, "IPv4");
1076                 proto_tree_add_item(pimopt_tree, hf_pim_source_ip4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
1077                 proto_tree_add_item(pimopt_tree, hf_pim_group_ip4, tvb, offset + 16, 4, ENC_BIG_ENDIAN);
1078             } else if (pinfo->src.type == AT_IPv6) {
1079                 proto_item_append_text(ti, "IPv6");
1080                 proto_tree_add_item(pimopt_tree, hf_pim_source_ip6, tvb, offset + 8, 16, ENC_NA);
1081                 proto_tree_add_item(pimopt_tree, hf_pim_group_ip6, tvb, offset + 8 + 16, 16, ENC_NA);
1082             } else
1083                 proto_item_append_text(ti, "for an unknown protocol");
1084             break;
1085         case 4: /* IPv4 */
1086             if (use_main_tree) {
1087                 call_dissector(ip_handle, next_tvb, pinfo, tree);
1088             } else {
1089                 call_dissector(ip_handle, next_tvb, pinfo, pimopt_tree);
1090             }
1091             break;
1092         case 6: /* IPv6 */
1093             if (use_main_tree) {
1094                 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
1095             } else {
1096                 call_dissector(ipv6_handle, next_tvb, pinfo, pimopt_tree);
1097             }
1098             break;
1099         default:
1100             break;
1101         }
1102         break;
1103     }
1104
1105     case PIM_TYPE_REGISTER_STOP:     /* register-stop */
1106     {
1107         int advance;
1108
1109         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group, NULL, NULL,
1110                                     hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1111             break;
1112         offset += advance;
1113         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
1114                                     hf_pim_source_ip4, hf_pim_source_ip6, &advance))
1115             break;
1116         break;
1117     }
1118
1119     case PIM_TYPE_JOIN_PRUNE:     /* join/prune */
1120     case PIM_TYPE_GRAFT:     /* graft */
1121     case PIM_TYPE_GRAFT_ACK:     /* graft-ack */
1122     {
1123         int advance;
1124         int off;
1125         int ngroup, i, njoin, nprune, j;
1126         guint32 holdtime;
1127         proto_tree *grouptree = NULL;
1128         proto_item *tigroup;
1129         proto_tree *subtree = NULL;
1130         proto_item *tisub;
1131         proto_item *ti_hold;
1132
1133         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
1134                                    hf_pim_upstream_neighbor_ip4, hf_pim_upstream_neighbor_ip6, &advance))
1135             break;
1136
1137         offset += advance;
1138
1139         /* reserved field */
1140         proto_tree_add_item(pimopt_tree, hf_pim_res_bytes, tvb, offset, 1, ENC_NA);
1141         offset += 1;
1142
1143         ngroup = tvb_get_guint8(tvb, offset);
1144         proto_tree_add_item(pimopt_tree, hf_pim_numgroups, tvb, offset, 1, ENC_BIG_ENDIAN);
1145         offset += 1;
1146
1147         ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
1148                                    offset, 2, ENC_BIG_ENDIAN, &holdtime);
1149         if(holdtime == 0xFFFF){
1150             proto_item_append_text(ti_hold, " (Infinity)");
1151         }
1152         offset += 2;
1153
1154         for (i = 0; i < ngroup; i++) {
1155             if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1156                                    wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), &tigroup,
1157                                    hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1158                 goto breakbreak3;
1159
1160             grouptree = proto_item_add_subtree(tigroup, ett_pim);
1161             offset += advance;
1162
1163             njoin = tvb_get_ntohs(tvb, offset);
1164             nprune = tvb_get_ntohs(tvb, offset + 2);
1165             tisub = proto_tree_add_item(grouptree, hf_pim_numjoins, tvb,
1166                                         offset, 2, ENC_BIG_ENDIAN);
1167             subtree = proto_item_add_subtree(tisub, ett_pim);
1168             off = offset + 4;
1169             for (j = 0; j < njoin; j++) {
1170                 if (!dissect_pim_addr(subtree, tvb, off, pimv2_source, NULL, NULL,
1171                                            hf_pim_join_ip4, hf_pim_join_ip6, &advance))
1172                     goto breakbreak3;
1173
1174                 off += advance;
1175             }
1176
1177             tisub = proto_tree_add_item(grouptree, hf_pim_numprunes, tvb,
1178                                         offset + 2, 2, ENC_BIG_ENDIAN);
1179             subtree = proto_item_add_subtree(tisub, ett_pim);
1180             for (j = 0; j < nprune; j++) {
1181                 if (!dissect_pim_addr(subtree, tvb, off, pimv2_source, NULL, NULL,
1182                                            hf_pim_prune_ip4, hf_pim_prune_ip6, &advance))
1183                     goto breakbreak3;
1184
1185                 off += advance;
1186             }
1187             offset = off;
1188         }
1189     breakbreak3:
1190         break;
1191     }
1192
1193     case PIM_TYPE_BOOTSTRAP:     /* bootstrap */
1194     {
1195         int advance;
1196         int i, j;
1197         int frpcnt;
1198         guint32 holdtime;
1199         proto_tree *grouptree = NULL;
1200         proto_item *tigroup;
1201         proto_item *ti_hold;
1202
1203         proto_tree_add_item(pimopt_tree, hf_pim_fragment_tag, tvb,
1204                                    offset, 2, ENC_BIG_ENDIAN);
1205         offset += 2;
1206
1207         proto_tree_add_item(pimopt_tree, hf_pim_hash_mask_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1208         offset += 1;
1209         proto_tree_add_item(pimopt_tree, hf_pim_bsr_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1210         offset += 1;
1211
1212         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast, NULL, NULL,
1213                                     hf_pim_bsr_ip4, hf_pim_bsr_ip6, &advance))
1214             break;
1215         offset += advance;
1216
1217         for (i = 0; tvb_reported_length_remaining(tvb, offset) > 0; i++) {
1218             if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1219                                    wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), &tigroup,
1220                                    hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1221                 goto breakbreak4;
1222
1223             grouptree = proto_item_add_subtree(tigroup, ett_pim);
1224             offset += advance;
1225
1226             proto_tree_add_item(grouptree, hf_pim_rp_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1227             offset += 1;
1228             frpcnt = tvb_get_guint8(tvb, offset);
1229             proto_tree_add_item(grouptree, hf_pim_frp_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1230             offset += 3;
1231
1232             for (j = 0; j < frpcnt; j++) {
1233                 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1234                                        wmem_strdup_printf(wmem_packet_scope(), "RP %d", j), NULL,
1235                                        hf_pim_rp_ip4, hf_pim_rp_ip6, &advance))
1236
1237                     goto breakbreak4;
1238                 offset += advance;
1239
1240                 ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
1241                                            offset, 2, ENC_BIG_ENDIAN, &holdtime);
1242                 if(holdtime == 0xFFFF){
1243                     proto_item_append_text(ti_hold, " (Infinity)");
1244                 }
1245                 offset += 2;
1246                 proto_tree_add_item(grouptree, hf_pim_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1247                 offset += 1;
1248
1249                 /* reserved stuff */
1250                 proto_tree_add_item(pim_tree, hf_pim_res_bytes, tvb, offset, 1, ENC_NA);
1251                 offset += 1;
1252             }
1253         }
1254
1255     breakbreak4:
1256         break;
1257     }
1258
1259     case PIM_TYPE_ASSERT:     /* assert */
1260     {
1261         int advance;
1262
1263         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1264                                 NULL, NULL,
1265                                 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1266             break;
1267         offset += advance;
1268
1269         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1270                                 NULL, NULL,
1271                                 hf_pim_source_ip4, hf_pim_source_ip6, &advance))
1272             break;
1273         offset += advance;
1274
1275         proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
1276         proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
1277                                    offset, 4, ENC_BIG_ENDIAN);
1278         offset += 4;
1279
1280         proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1281         /* offset += 4;*/
1282         break;
1283     }
1284
1285     case PIM_TYPE_CAND_RP_ADV:     /* Candidate-RP-Advertisement */
1286     {
1287         int advance;
1288         int pfxcnt;
1289         guint32 holdtime;
1290         int i;
1291         proto_item *ti_hold;
1292
1293         pfxcnt = tvb_get_guint8(tvb, offset);
1294         proto_tree_add_item(pimopt_tree, hf_pim_prefix_count, tvb, offset, 1, ENC_BIG_ENDIAN);
1295         offset += 1;
1296         proto_tree_add_item(pimopt_tree, hf_pim_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
1297         offset += 1;
1298
1299         ti_hold = proto_tree_add_item_ret_uint(pimopt_tree, hf_pim_holdtime, tvb,
1300                                    offset, 2, ENC_BIG_ENDIAN, &holdtime);
1301         if(holdtime == 0xFFFF){
1302             proto_item_append_text(ti_hold, " (Infinity)");
1303         }
1304         offset += 2;
1305
1306         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1307                                 NULL, NULL,
1308                                 hf_pim_rp_ip4, hf_pim_rp_ip6, &advance))
1309             break;
1310         offset += advance;
1311
1312         for (i = 0; i < pfxcnt; i++) {
1313             if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1314                                    wmem_strdup_printf(wmem_packet_scope(), "Group %d", i), NULL,
1315                                    hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1316                 goto breakbreak8;
1317             offset += advance;
1318         }
1319     breakbreak8:
1320         break;
1321     }
1322
1323     case PIM_TYPE_STATE_REFRESH:     /* State-Refresh */
1324     {
1325         int advance;
1326
1327         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_group,
1328                                 NULL, NULL,
1329                                 hf_pim_group_ip4, hf_pim_group_ip6, &advance))
1330             break;
1331         offset += advance;
1332
1333         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1334                                 NULL, NULL,
1335                                 hf_pim_source_ip4, hf_pim_source_ip6, &advance))
1336             break;
1337         offset += advance;
1338
1339         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1340                                 NULL, NULL,
1341                                 hf_pim_originator_ip4, hf_pim_originator_ip6, &advance))
1342             break;
1343         offset += advance;
1344
1345         proto_tree_add_item(pimopt_tree, hf_pim_rpt, tvb, offset, 1, ENC_BIG_ENDIAN);
1346         proto_tree_add_item(pimopt_tree, hf_pim_metric_pref, tvb,
1347                                    offset, 4, ENC_BIG_ENDIAN);
1348         offset += 4;
1349
1350         proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1351         offset += 4;
1352
1353         proto_tree_add_item(pimopt_tree, hf_pim_mask_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1354         offset += 1;
1355
1356         proto_tree_add_item(pimopt_tree, hf_pim_ttl, tvb, offset, 1, ENC_BIG_ENDIAN);
1357         offset += 1;
1358
1359         proto_tree_add_item(pimopt_tree, hf_pim_prune_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
1360         proto_tree_add_item(pimopt_tree, hf_pim_prune_now, tvb, offset, 1, ENC_BIG_ENDIAN);
1361         proto_tree_add_item(pimopt_tree, hf_pim_assert_override, tvb, offset, 1, ENC_BIG_ENDIAN);
1362         offset += 1;
1363
1364         proto_tree_add_item(pimopt_tree, hf_pim_interval, tvb, offset, 1, ENC_BIG_ENDIAN);
1365         /*offset += 1;*/
1366
1367         break;
1368     }
1369
1370     case PIM_TYPE_DF_ELECT:
1371     {
1372         int advance;
1373
1374         if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1375                                 NULL, NULL,
1376                                 hf_pim_rp_ip4, hf_pim_rp_ip6, &advance))
1377             break;
1378         offset += advance;
1379         proto_tree_add_item(pimopt_tree, hf_pim_df_metric_pref, tvb,
1380                             offset, 4, ENC_BIG_ENDIAN);
1381         offset += 4;
1382         proto_tree_add_item(pimopt_tree, hf_pim_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1383         offset += 4;
1384
1385         switch(PIM_BIDIR_SUBTYPE(pim_bidir_subtype)) {
1386             case PIM_BDIR_DF_BACKOFF :
1387                 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1388                                     NULL, NULL,
1389                                     hf_pim_bd_bo_offer_ip4, hf_pim_bd_bo_offer_ip6, &advance))
1390                     break;
1391                 offset += advance;
1392                 proto_tree_add_item(pimopt_tree, hf_pim_bd_offer_metric_pref, tvb, offset, 4, ENC_BIG_ENDIAN);
1393                 offset += 4;
1394                 proto_tree_add_item(pimopt_tree, hf_pim_bd_offer_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1395                 offset += 4;
1396                 proto_tree_add_item(pimopt_tree, hf_pim_bd_offer_interval, tvb, offset, 2, ENC_BIG_ENDIAN);
1397                 break;
1398             case PIM_BDIR_DF_PASS:
1399                 if (!dissect_pim_addr(pimopt_tree, tvb, offset, pimv2_unicast,
1400                                     NULL, NULL,
1401                                     hf_pim_bd_pass_ip4, hf_pim_bd_pass_ip6, &advance))
1402                     break;
1403                 offset += advance;
1404                 proto_tree_add_item(pimopt_tree, hf_pim_bd_pass_metric_pref, tvb, offset, 4, ENC_BIG_ENDIAN);
1405                 offset += 4;
1406                 proto_tree_add_item(pimopt_tree, hf_pim_bd_pass_metric, tvb, offset, 4, ENC_BIG_ENDIAN);
1407                 break;
1408         }
1409     }
1410
1411     default:
1412         break;
1413     }
1414 done:;
1415 }
1416
1417 void
1418 proto_register_pim(void)
1419 {
1420     static hf_register_info hf[] =
1421         {
1422             { &hf_pim_version,
1423               { "Version", "pim.version",
1424                 FT_UINT8, BASE_DEC, NULL, 0xf0,
1425                 NULL, HFILL }
1426             },
1427             { &hf_pim_type,
1428               { "Type", "pim.type",
1429                 FT_UINT8, BASE_DEC, VALS(pimtypevals), 0x0f,
1430                 NULL, HFILL }
1431             },
1432             { &hf_pim_df_elect_subtype,
1433               { "DF Subtype", "pim.df_elect.subtype",
1434                 FT_UINT8, BASE_DEC, VALS(pimbdirdfvals), 0xf0,
1435                 NULL, HFILL}
1436             },
1437             { &hf_pim_df_elect_rsvd,
1438               { "DF reserved", "pim.df_elect.rsvd",
1439                 FT_UINT8, BASE_DEC, NULL, 0x0f,
1440                 NULL, HFILL}
1441             },
1442             { &hf_pim_igmp_type,
1443               { "Type", "pim.igmp_type",
1444                 FT_STRING, BASE_NONE, NULL, 0x0,
1445                 NULL, HFILL }
1446             },
1447             { &hf_pim_code,
1448               { "Code", "pim.code",
1449                 FT_UINT8, BASE_DEC, VALS(pim_type1_vals), 0x0,
1450                 NULL, HFILL }
1451             },
1452             { &hf_pim_cksum,
1453               { "Checksum", "pim.cksum",
1454                 FT_UINT16, BASE_HEX, NULL, 0x0,
1455                 NULL, HFILL }
1456             },
1457             { &hf_pim_res_bytes,
1458               { "Reserved byte(s)", "pim.res_bytes",
1459                 FT_BYTES, BASE_NONE, NULL, 0x0,
1460                 NULL, HFILL }
1461             },
1462             { &hf_pim_option,
1463               { "PIM Options", "pim.option",
1464                 FT_NONE, BASE_NONE, NULL, 0x0,
1465                 NULL, HFILL }
1466             },
1467             { &hf_pim_optiontype,
1468               { "Type", "pim.optiontype",
1469                 FT_UINT16, BASE_DEC, NULL, 0x0,
1470                 NULL, HFILL }
1471             },
1472             { &hf_pim_optionlength,
1473               { "Length", "pim.optionlength",
1474                 FT_UINT16, BASE_DEC, NULL, 0x0,
1475                 NULL, HFILL }
1476             },
1477             { &hf_pim_optionvalue,
1478               { "Unknown", "pim.optionvalue",
1479                 FT_BYTES, BASE_NONE, NULL, 0x0,
1480                 NULL, HFILL }
1481             },
1482             { &hf_pim_register_flag,
1483               { "Flags", "pim.register_flag",
1484                 FT_UINT32, BASE_HEX, NULL, 0x0,
1485                 NULL, HFILL }
1486             },
1487             { &hf_pim_register_flag_border,
1488               { "Border", "pim.register_flag.border",
1489                 FT_BOOLEAN, 32, TFS(&tfs_yes_no), 0x80000000,
1490                 NULL, HFILL }
1491             },
1492             { &hf_pim_register_flag_null_register,
1493               { "Null-Register", "pim.register_flag.null_register",
1494                 FT_BOOLEAN, 32, TFS(&tfs_yes_no), 0x40000000,
1495                 NULL, HFILL }
1496             },
1497             { &hf_pim_mode,
1498               { "Mode", "pim.mode",
1499                 FT_UINT8, BASE_DEC, VALS(pimv1_modevals), 0xf0,
1500                 NULL, HFILL }
1501             },
1502             { &hf_pim_holdtime,
1503               { "Holdtime", "pim.holdtime",
1504                 FT_UINT16, BASE_DEC, NULL, 0x0,
1505                 "The amount of time a receiver must keep the neighbor "
1506                 "reachable, in seconds.", HFILL }
1507             },
1508             { &hf_pim_numgroups,
1509               { "Num Groups", "pim.numgroups",
1510                 FT_UINT16, BASE_DEC, NULL, 0x0,
1511                 "Number of multicast group sets contained in the message.",
1512                 HFILL }
1513             },
1514             { &hf_pim_numjoins,
1515               { "Num Joins", "pim.numjoins",
1516                 FT_UINT16, BASE_DEC, NULL, 0x0,
1517                 "Number of joined sources.", HFILL }
1518             },
1519             { &hf_pim_numprunes,
1520               { "Num Prunes", "pim.numprunes",
1521                 FT_UINT16, BASE_DEC, NULL, 0x0,
1522                 "Number of pruned sources.", HFILL }
1523             },
1524             { &hf_pim_t,
1525               { "T", "pim.t",
1526                 FT_BOOLEAN, 8, NULL, 0x80,
1527                 "Specifies the ability of the sending router to disable joins "
1528                 "suppression.", HFILL }
1529             },
1530             { &hf_pim_propagation_delay,
1531               { "Propagation Delay", "pim.propagation_delay",
1532                 FT_UINT16, BASE_DEC, NULL, 0x07fff,
1533                 "Units are milli-seconds", HFILL }
1534             },
1535             { &hf_pim_override_interval,
1536               { "Override Interval", "pim.override_interval",
1537                 FT_UINT16, BASE_DEC, NULL, 0x0,
1538                 "Units are milli-seconds", HFILL }
1539             },
1540             { &hf_pim_dr_priority,
1541               { "DR Priority", "pim.dr_priority",
1542                 FT_UINT32, BASE_DEC, NULL, 0x0,
1543                 NULL, HFILL }
1544             },
1545             { &hf_pim_generation_id,
1546               { "Generation ID", "pim.generation_id",
1547                 FT_UINT32, BASE_DEC, NULL, 0x0,
1548                 NULL, HFILL }
1549             },
1550             { &hf_pim_state_refresh_version,
1551               { "Version", "pim.state_refresh_version",
1552                 FT_UINT8, BASE_DEC, NULL, 0x0,
1553                 NULL, HFILL }
1554             },
1555             { &hf_pim_state_refresh_interval,
1556               { "Interval", "pim.state_refresh_interval",
1557                 FT_UINT8, BASE_DEC, NULL, 0x0,
1558                 "Units in seconds.", HFILL }
1559             },
1560             { &hf_pim_state_refresh_reserved,
1561               { "Reserved", "pim.state_refresh_reserved",
1562                 FT_UINT16, BASE_DEC, NULL, 0x0,
1563                 NULL, HFILL }
1564             },
1565             { &hf_pim_rpt,
1566               { "RP Tree", "pim.rpt",
1567                 FT_BOOLEAN, 8, NULL, 0x80,
1568                 "Set to 1 for assert(*,G) messages and 0 for assert(S,G) "
1569                 "messages.", HFILL }
1570             },
1571             { &hf_pim_metric_pref,
1572               { "Metric Preference", "pim.metric_pref",
1573                 FT_UINT32, BASE_DEC, NULL, 0x7fffffff,
1574                 NULL, HFILL }
1575             },
1576             { &hf_pim_df_metric_pref,
1577               { "DF Metric Preference", "pim.metric_pref",
1578                 FT_UINT32, BASE_DEC, NULL, 0,
1579                 NULL, HFILL }
1580             },
1581             { &hf_pim_metric,
1582               { "Metric", "pim.metric",
1583                 FT_UINT32, BASE_DEC, NULL, 0x0,
1584                 NULL, HFILL }
1585             },
1586             { &hf_pim_prune_indicator,
1587               { "Prune indicator", "pim.prune_indicator",
1588                 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x80,
1589                 NULL, HFILL }
1590             },
1591             { &hf_pim_prune_now,
1592               { "Prune now", "pim.prune_now",
1593                 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
1594                 NULL, HFILL }
1595             },
1596             { &hf_pim_assert_override,
1597               { "Assert override", "pim.assert_override",
1598                 FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x20,
1599                 NULL, HFILL }
1600             },
1601             { &hf_pim_ip_version,
1602               { "IP Version", "pim.ip_version",
1603                 FT_UINT8, BASE_DEC, VALS(pim_ip_version_vals), 0xF0,
1604                 NULL, HFILL }
1605             },
1606             { &hf_pim_dummy_header,
1607               { "Dummy Header", "pim.dummy_header",
1608                 FT_NONE, BASE_NONE, NULL, 0,
1609                 NULL, HFILL }
1610             },
1611             { &hf_pim_source_ip4,
1612               { "Source", "pim.source",
1613                 FT_IPv4, BASE_NONE, NULL, 0,
1614                 NULL, HFILL }
1615             },
1616             { &hf_pim_source_ip6,
1617               { "Source", "pim.source",
1618                 FT_IPv6, BASE_NONE, NULL, 0,
1619                 NULL, HFILL }
1620             },
1621             { &hf_pim_group_ip4,
1622               { "Group", "pim.group",
1623                 FT_IPv4, BASE_NONE, NULL, 0,
1624                 NULL, HFILL }
1625             },
1626             { &hf_pim_group_mask_ip4,
1627               { "Mask", "pim.group_mask",
1628                 FT_IPv4, BASE_NONE, NULL, 0,
1629                 NULL, HFILL }
1630             },
1631             { &hf_pim_group_ip6,
1632               { "Group", "pim.group",
1633                 FT_IPv6, BASE_NONE, NULL, 0,
1634                 NULL, HFILL }
1635             },
1636             { &hf_pim_upstream_neighbor_ip4,
1637               { "Upstream-neighbor", "pim.upstream_neighbor",
1638                 FT_IPv4, BASE_NONE, NULL, 0,
1639                 NULL, HFILL }
1640             },
1641             { &hf_pim_upstream_neighbor_ip6,
1642               { "Upstream-neighbor", "pim.upstream_neighbor",
1643                 FT_IPv6, BASE_NONE, NULL, 0,
1644                 NULL, HFILL }
1645             },
1646             { &hf_pim_join_ip4,
1647               { "IP address", "pim.join_ip",
1648                 FT_IPv4, BASE_NONE, NULL, 0,
1649                 NULL, HFILL }
1650             },
1651             { &hf_pim_join_ip6,
1652               { "IP address", "pim.join_ip",
1653                 FT_IPv6, BASE_NONE, NULL, 0,
1654                 NULL, HFILL }
1655             },
1656             { &hf_pim_prune_ip4,
1657               { "IP address", "pim.prune_ip",
1658                 FT_IPv4, BASE_NONE, NULL, 0,
1659                 NULL, HFILL }
1660             },
1661             { &hf_pim_prune_ip6,
1662               { "IP address", "pim.prune_ip",
1663                 FT_IPv6, BASE_NONE, NULL, 0,
1664                 NULL, HFILL }
1665             },
1666             { &hf_pim_address_list_ip4,
1667               { "Address", "pim.address_list",
1668                 FT_IPv4, BASE_NONE, NULL, 0,
1669                 NULL, HFILL }
1670             },
1671             { &hf_pim_address_list_ip6,
1672               { "Address", "pim.address_list",
1673                 FT_IPv6, BASE_NONE, NULL, 0,
1674                 NULL, HFILL }
1675             },
1676             { &hf_pim_bsr_ip4,
1677               { "BSR", "pim.bsr",
1678                 FT_IPv4, BASE_NONE, NULL, 0,
1679                 NULL, HFILL }
1680             },
1681             { &hf_pim_bsr_ip6,
1682               { "BSR", "pim.bsr",
1683                 FT_IPv6, BASE_NONE, NULL, 0,
1684                 NULL, HFILL }
1685             },
1686             { &hf_pim_rp_ip4,
1687               { "RP", "pim.rp",
1688                 FT_IPv4, BASE_NONE, NULL, 0,
1689                 NULL, HFILL }
1690             },
1691             { &hf_pim_rp_ip6,
1692               { "RP", "pim.rp",
1693                 FT_IPv6, BASE_NONE, NULL, 0,
1694                 NULL, HFILL }
1695             },
1696             { &hf_pim_originator_ip4,
1697               { "Originator", "pim.originator",
1698                 FT_IPv4, BASE_NONE, NULL, 0,
1699                 NULL, HFILL }
1700             },
1701             { &hf_pim_originator_ip6,
1702               { "Originator", "pim.originator",
1703                 FT_IPv6, BASE_NONE, NULL, 0,
1704                 NULL, HFILL }
1705             },
1706             { &hf_pim_group_address_ip4,
1707               { "Group Address", "pim.group_address",
1708                 FT_IPv4, BASE_NONE, NULL, 0,
1709                 NULL, HFILL }
1710             },
1711             { &hf_pim_bd_pass_ip4,
1712               { "New Winner IP", "pim.bidir_winner_ip4",
1713                 FT_IPv4, BASE_NONE, NULL, 0,
1714                 NULL, HFILL }
1715             },
1716             { &hf_pim_bd_pass_ip6,
1717               { "New Winner IP", "pim.bidir_winner_ip6",
1718                 FT_IPv6, BASE_NONE, NULL, 0,
1719                 NULL, HFILL }
1720             },
1721             { &hf_pim_bd_pass_metric_pref,
1722               { "Winner Metric Preference", "pim.bidir_win_metric_pref",
1723                 FT_UINT32, BASE_DEC, NULL, 0,
1724                 NULL, HFILL }
1725             },
1726             { &hf_pim_bd_pass_metric,
1727               { "Winner Metric", "pim.bidir_win_metric",
1728                 FT_UINT32, BASE_DEC, NULL, 0,
1729                 NULL, HFILL }
1730             },
1731             { &hf_pim_bd_bo_offer_ip4,
1732               { "Offering IP", "pim.bidir_offering_ip4",
1733                  FT_IPv4, BASE_NONE, NULL, 0,
1734                  NULL, HFILL }
1735             },
1736             { &hf_pim_bd_bo_offer_ip6,
1737               { "Offering IP", "pim.bidir_offering_ip6",
1738                 FT_IPv6, BASE_NONE, NULL, 0,
1739                 NULL, HFILL }
1740             },
1741             { &hf_pim_bd_offer_metric_pref,
1742               { "Offering Metric Preference", "pim.bidir_off_metric_pref",
1743                 FT_UINT32, BASE_DEC, NULL, 0,
1744                 NULL, HFILL }
1745             },
1746             { &hf_pim_bd_offer_metric,
1747               { "Offering Metric", "pim.bidir_off_metric",
1748                 FT_UINT32, BASE_DEC, NULL, 0,
1749                 NULL, HFILL }
1750             },
1751             { &hf_pim_bd_offer_interval,
1752               { "Offering interval (ms)", "pim.bidir_offering_interval",
1753                 FT_UINT16, BASE_DEC, NULL, 0,
1754                 NULL, HFILL }
1755             },
1756             { &hf_pim_fragment_tag,
1757               { "Fragment tag", "pim.fragment_tag",
1758                 FT_UINT16, BASE_HEX, NULL, 0x0,
1759                 NULL, HFILL }
1760             },
1761             { &hf_pim_hash_mask_len,
1762               { "Hash mask len", "pim.hash_mask_len",
1763                 FT_UINT8, BASE_DEC, NULL, 0x0,
1764                 NULL, HFILL }
1765             },
1766             { &hf_pim_bsr_priority,
1767               { "BSR priority", "pim.bsr_priority",
1768                 FT_UINT8, BASE_DEC, NULL, 0x0,
1769                 NULL, HFILL }
1770             },
1771             { &hf_pim_rp_count,
1772               { "RP count", "pim.rp_count",
1773                 FT_UINT8, BASE_DEC, NULL, 0x0,
1774                 NULL, HFILL }
1775             },
1776             { &hf_pim_frp_count,
1777               { "FRP count", "pim.frp_count",
1778                 FT_UINT8, BASE_DEC, NULL, 0x0,
1779                 NULL, HFILL }
1780             },
1781             { &hf_pim_priority,
1782               { "Priority", "pim.priority",
1783                 FT_UINT8, BASE_DEC, NULL, 0x0,
1784                 NULL, HFILL }
1785             },
1786             { &hf_pim_prefix_count,
1787               { "Prefix-count", "pim.prefix_count",
1788                 FT_UINT8, BASE_DEC, NULL, 0x0,
1789                 NULL, HFILL }
1790             },
1791             { &hf_pim_src_flags_a,
1792               { "Annotated", "pim.src_flags.a",
1793                 FT_UINT8, BASE_DEC, NULL, 0x08,
1794                 NULL, HFILL }
1795             },
1796             { &hf_pim_src_flags_s,
1797               { "Sparse", "pim.src_flags.s",
1798                 FT_UINT8, BASE_DEC, NULL, 0x04,
1799                 NULL, HFILL }
1800             },
1801             { &hf_pim_src_flags_w,
1802               { "WC", "pim.src_flags.w",
1803                 FT_UINT8, BASE_DEC, NULL, 0x02,
1804                 NULL, HFILL }
1805             },
1806             { &hf_pim_src_flags_r,
1807               { "RP", "pim.src_flags.r",
1808                 FT_UINT8, BASE_DEC, NULL, 0x01,
1809                 NULL, HFILL }
1810             },
1811             { &hf_pim_src_flags_rsv,
1812               { "Reserved", "pim.src_flags.rsv",
1813                 FT_UINT8, BASE_DEC, NULL, 0xF0,
1814                 NULL, HFILL }
1815             },
1816             { &hf_pim_mask_len,
1817               { "Masklen", "pim.mask_len",
1818                 FT_UINT8, BASE_DEC, NULL, 0x0,
1819                 NULL, HFILL }
1820             },
1821             { &hf_pim_addr_len,
1822               { "Address Len", "pim.addr_len",
1823                 FT_UINT8, BASE_DEC, NULL, 0x0,
1824                 NULL, HFILL }
1825             },
1826             { &hf_pim_ttl,
1827               { "TTL", "pim.ttl",
1828                 FT_UINT8, BASE_DEC, NULL, 0x0,
1829                 NULL, HFILL }
1830             },
1831             { &hf_pim_interval,
1832               { "Interval", "pim.interval",
1833                 FT_UINT8, BASE_DEC, NULL, 0x0,
1834                 NULL, HFILL }
1835             },
1836         };
1837
1838     static gint *ett[] = {
1839         &ett_pim,
1840         &ett_pim_opts,  /* Tree for all options */
1841         &ett_pim_opt    /* Tree for each option */
1842     };
1843
1844     module_t *pim_module;
1845
1846     proto_pim = proto_register_protocol("Protocol Independent Multicast",
1847                                         "PIM", "pim");
1848     proto_register_field_array(proto_pim, hf, array_length(hf));
1849     proto_register_subtree_array(ett, array_length(ett));
1850
1851     pim_module = prefs_register_protocol(proto_pim, NULL);
1852     prefs_register_bool_preference(pim_module, "payload_tree",
1853                                   "PIM payload shown on main tree",
1854                                   "Whether the PIM payload is shown off of the main tree or encapsulated within the PIM options",
1855                                   &use_main_tree);
1856
1857 }
1858
1859 void
1860 proto_reg_handoff_pim(void)
1861 {
1862     dissector_handle_t pim_handle, pimv1_handle;
1863
1864     pim_handle = create_dissector_handle(dissect_pim, proto_pim);
1865     dissector_add_uint("ip.proto", IP_PROTO_PIM, pim_handle);
1866
1867     pimv1_handle = new_create_dissector_handle(dissect_pimv1, proto_pim);
1868     dissector_add_uint("igmp.type", IGMP_V1_PIM_ROUTING_MESSAGE, pimv1_handle);
1869
1870     /*
1871      * Get handles for the IPv4 and IPv6 dissectors.
1872      */
1873     ip_handle = find_dissector("ip");
1874     ipv6_handle = find_dissector("ipv6");
1875 }
1876
1877 /*
1878  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1879  *
1880  * Local variables:
1881  * c-basic-offset: 4
1882  * tab-width: 8
1883  * indent-tabs-mode: nil
1884  * End:
1885  *
1886  * vi: set shiftwidth=4 tabstop=8 expandtab:
1887  * :indentSize=4:tabSize=8:noTabs=true:
1888  */