GTPv2: fix dissection of APN IE
[metze/wireshark/wip.git] / epan / dissectors / packet-ipv6.c
1 /* packet-ipv6.c
2  * Routines for IPv6 packet disassembly
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SHIM6 support added by Matthijs Mekking <matthijs@NLnetLabs.nl>
9  *
10  * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14
15 #include "config.h"
16
17 #include <math.h>
18 #include <epan/packet.h>
19 #include <epan/capture_dissectors.h>
20 #include <epan/expert.h>
21 #include <epan/ip_opts.h>
22 #include <epan/addr_resolv.h>
23 #include <epan/maxmind_db.h>
24 #include <epan/prefs.h>
25 #include <epan/conversation_table.h>
26 #include <epan/dissector_filters.h>
27 #include <epan/reassemble.h>
28 #include <epan/ipproto.h>
29 #include <epan/etypes.h>
30 #include <epan/ppptypes.h>
31 #include <epan/aftypes.h>
32 #include <epan/nlpid.h>
33 #include <epan/arcnet_pids.h>
34 #include <epan/decode_as.h>
35 #include <epan/proto_data.h>
36 #include <epan/to_str.h>
37
38 #include <wiretap/erf.h>
39 #include <wsutil/str_util.h>
40 #include "packet-ip.h"
41 #include "packet-juniper.h"
42 #include "packet-sflow.h"
43 #include "packet-vxlan.h"
44 #include "packet-mpls.h"
45 #include "packet-nsh.h"
46
47 void proto_register_ipv6(void);
48 void proto_reg_handoff_ipv6(void);
49
50 /* Offsets of fields within an IPv6 header. */
51 #define IP6H_CTL_VFC    0
52 #define IP6H_CTL_FLOW   0
53 #define IP6H_CTL_PLEN   4
54 #define IP6H_CTL_NXT    6
55 #define IP6H_CTL_HLIM   7
56 #define IP6H_SRC        8
57 #define IP6H_DST        24
58
59 /* Option types and related macros */
60 #define IP6OPT_PAD1                     0x00    /* 00 0 00000 =   0 */
61 #define IP6OPT_PADN                     0x01    /* 00 0 00001 =   1 */
62 #define IP6OPT_TEL                      0x04    /* 00 0 00100 =   4 */
63 #define IP6OPT_RTALERT                  0x05    /* 00 0 00101 =   5 */
64 #define IP6OPT_CALIPSO                  0x07    /* 00 0 00111 =   7 */
65 #define IP6OPT_SMF_DPD                  0x08    /* 00 0 01000 =   8 */
66 #define IP6OPT_PDM                      0x0F    /* 00 0 01111 =  15 */
67 #define IP6OPT_EXP_1E                   0x1E    /* 00 0 11110 =  30 */
68 #define IP6OPT_QUICKSTART               0x26    /* 00 1 00110 =  38 */
69 #define IP6OPT_EXP_3E                   0x3E    /* 00 1 11110 =  62 */
70 #define IP6OPT_EXP_5E                   0x5E    /* 01 0 11110 =  94 */
71 #define IP6OPT_RPL                      0x63    /* 01 1 00011 =  99 */
72 #define IP6OPT_MPL                      0x6D    /* 01 1 01101 = 109 */
73 #define IP6OPT_EXP_7E                   0x7E    /* 01 1 11110 = 126 */
74 #define IP6OPT_ENDI                     0x8A    /* 10 0 01010 = 138 */ /* DEPRECATED */
75 #define IP6OPT_ILNP_NONCE               0x8B    /* 10 0 01011 = 139 */
76 #define IP6OPT_LIO                      0x8C    /* 10 0 01100 = 140 */
77 #define IP6OPT_EXP_9E                   0x9E    /* 10 0 11110 = 158 */
78 #define IP6OPT_EXP_BE                   0xBE    /* 10 1 11110 = 190 */
79 #define IP6OPT_JUMBO                    0xC2    /* 11 0 00010 = 194 */
80 #define IP6OPT_HOME_ADDRESS             0xC9    /* 11 0 01001 = 201 */
81 #define IP6OPT_EXP_DE                   0xDE    /* 11 0 11110 = 222 */
82 #define IP6OPT_IP_DFF                   0xEE    /* 11 1 01110 = 238 */
83 #define IP6OPT_EXP_FE                   0xFE    /* 11 1 11110 = 254 */
84
85 #define IP6OPT_RTALERT_MLD              0       /* Datagram contains MLD msg */
86 #define IP6OPT_RTALERT_RSVP             1       /* Datagram contains RSVP msg */
87 #define IP6OPT_RTALERT_ACTNET           2       /* Datagram contains ACTNET msg */
88
89 /* RPL Routing header */
90 #define IP6RRPL_BITMASK_CMPRI     0xF0000000
91 #define IP6RRPL_BITMASK_CMPRE     0x0F000000
92 #define IP6RRPL_BITMASK_PAD       0x00F00000
93 #define IP6RRPL_BITMASK_RESERVED  0x000FFFFF
94
95 /* Protocol specific data indices */
96 #define IPV6_PROTO_VALUE            1
97 #define IPV6_PROTO_PINFO            2
98
99 static int ipv6_tap  = -1;
100
101 static int proto_ipv6                           = -1;
102 static int proto_ipv6_hopopts                   = -1;
103 static int proto_ipv6_routing                   = -1;
104 static int proto_ipv6_fraghdr                   = -1;
105 static int proto_ipv6_dstopts                   = -1;
106
107 static int proto_ipv6_routing_rt0               = -1;
108 static int proto_ipv6_routing_mipv6             = -1;
109 static int proto_ipv6_routing_rpl               = -1;
110 static int proto_ipv6_routing_srh               = -1;
111
112 static int hf_ipv6_version                      = -1;
113 static int hf_ip_version                        = -1;
114 static int hf_ipv6_tclass                       = -1;
115 static int hf_ipv6_tclass_dscp                  = -1;
116 static int hf_ipv6_tclass_ecn                   = -1;
117 static int hf_ipv6_flow                         = -1;
118 static int hf_ipv6_plen                         = -1;
119 static int hf_ipv6_nxt                          = -1;
120 static int hf_ipv6_hlim                         = -1;
121 static int hf_ipv6_src                          = -1;
122 static int hf_ipv6_src_host                     = -1;
123 static int hf_ipv6_src_sa_mac                   = -1;
124 static int hf_ipv6_src_isatap_ipv4              = -1;
125 static int hf_ipv6_src_6to4_gateway_ipv4        = -1;
126 static int hf_ipv6_src_6to4_sla_id              = -1;
127 static int hf_ipv6_src_teredo_server_ipv4       = -1;
128 static int hf_ipv6_src_teredo_port              = -1;
129 static int hf_ipv6_src_teredo_client_ipv4       = -1;
130 static int hf_ipv6_src_embed_ipv4               = -1;
131 static int hf_ipv6_dst                          = -1;
132 static int hf_ipv6_dst_host                     = -1;
133 static int hf_ipv6_dst_sa_mac                   = -1;
134 static int hf_ipv6_dst_isatap_ipv4              = -1;
135 static int hf_ipv6_dst_6to4_gateway_ipv4        = -1;
136 static int hf_ipv6_dst_6to4_sla_id              = -1;
137 static int hf_ipv6_dst_teredo_server_ipv4       = -1;
138 static int hf_ipv6_dst_teredo_port              = -1;
139 static int hf_ipv6_dst_teredo_client_ipv4       = -1;
140 static int hf_ipv6_dst_embed_ipv4               = -1;
141 static int hf_ipv6_addr                         = -1;
142 static int hf_ipv6_host                         = -1;
143 static int hf_ipv6_sa_mac                       = -1;
144 static int hf_ipv6_isatap_ipv4                  = -1;
145 static int hf_ipv6_6to4_gateway_ipv4            = -1;
146 static int hf_ipv6_6to4_sla_id                  = -1;
147 static int hf_ipv6_teredo_server_ipv4           = -1;
148 static int hf_ipv6_teredo_port                  = -1;
149 static int hf_ipv6_teredo_client_ipv4           = -1;
150 static int hf_ipv6_embed_ipv4                   = -1;
151 static int hf_ipv6_opt                          = -1;
152 static int hf_ipv6_opt_type                     = -1;
153 static int hf_ipv6_opt_type_action              = -1;
154 static int hf_ipv6_opt_type_change              = -1;
155 static int hf_ipv6_opt_type_rest                = -1;
156 static int hf_ipv6_opt_length                   = -1;
157 static int hf_ipv6_opt_pad1                     = -1;
158 static int hf_ipv6_opt_padn                     = -1;
159 static int hf_ipv6_opt_tel                      = -1;
160 static int hf_ipv6_opt_rtalert                  = -1;
161 static int hf_ipv6_opt_jumbo                    = -1;
162 static int hf_ipv6_opt_calipso_doi              = -1;
163 static int hf_ipv6_opt_calipso_cmpt_length      = -1;
164 static int hf_ipv6_opt_calipso_sens_level       = -1;
165 static int hf_ipv6_opt_calipso_checksum         = -1;
166 static int hf_ipv6_opt_calipso_cmpt_bitmap      = -1;
167 static int hf_ipv6_opt_smf_dpd_hash_bit         = -1;
168 static int hf_ipv6_opt_smf_dpd_tid_type         = -1;
169 static int hf_ipv6_opt_smf_dpd_tid_len          = -1;
170 static int hf_ipv6_opt_smf_dpd_tagger_id        = -1;
171 static int hf_ipv6_opt_smf_dpd_ident            = -1;
172 static int hf_ipv6_opt_smf_dpd_hav              = -1;
173 static int hf_ipv6_opt_pdm_scale_dtlr           = -1;
174 static int hf_ipv6_opt_pdm_scale_dtls           = -1;
175 static int hf_ipv6_opt_pdm_psn_this_pkt         = -1;
176 static int hf_ipv6_opt_pdm_psn_last_recv        = -1;
177 static int hf_ipv6_opt_pdm_delta_last_recv      = -1;
178 static int hf_ipv6_opt_pdm_delta_last_sent      = -1;
179 static int hf_ipv6_opt_qs_func                  = -1;
180 static int hf_ipv6_opt_qs_rate                  = -1;
181 static int hf_ipv6_opt_qs_ttl                   = -1;
182 static int hf_ipv6_opt_qs_ttl_diff              = -1;
183 static int hf_ipv6_opt_qs_unused                = -1;
184 static int hf_ipv6_opt_qs_nonce                 = -1;
185 static int hf_ipv6_opt_qs_reserved              = -1;
186 static int hf_ipv6_opt_mipv6_home_address       = -1;
187 static int hf_ipv6_opt_rpl_flag                 = -1;
188 static int hf_ipv6_opt_rpl_flag_o               = -1;
189 static int hf_ipv6_opt_rpl_flag_r               = -1;
190 static int hf_ipv6_opt_rpl_flag_f               = -1;
191 static int hf_ipv6_opt_rpl_flag_rsv             = -1;
192 static int hf_ipv6_opt_rpl_instance_id          = -1;
193 static int hf_ipv6_opt_rpl_senderrank           = -1;
194 static int hf_ipv6_opt_ilnp_nonce               = -1;
195 static int hf_ipv6_opt_lio_len                  = -1;
196 static int hf_ipv6_opt_lio_id                   = -1;
197 static int hf_ipv6_opt_mpl_flag                 = -1;
198 static int hf_ipv6_opt_mpl_flag_s               = -1;
199 static int hf_ipv6_opt_mpl_flag_m               = -1;
200 static int hf_ipv6_opt_mpl_flag_v               = -1;
201 static int hf_ipv6_opt_mpl_flag_rsv             = -1;
202 static int hf_ipv6_opt_mpl_sequence             = -1;
203 static int hf_ipv6_opt_mpl_seed_id              = -1;
204 static int hf_ipv6_opt_dff_flags                = -1;
205 static int hf_ipv6_opt_dff_flag_ver             = -1;
206 static int hf_ipv6_opt_dff_flag_dup             = -1;
207 static int hf_ipv6_opt_dff_flag_ret             = -1;
208 static int hf_ipv6_opt_dff_flag_rsv             = -1;
209 static int hf_ipv6_opt_dff_seqnum               = -1;
210 static int hf_ipv6_opt_experimental             = -1;
211 static int hf_ipv6_opt_unknown_data             = -1;
212 static int hf_ipv6_opt_unknown                  = -1;
213 static int hf_ipv6_dstopts_nxt                  = -1;
214 static int hf_ipv6_dstopts_len                  = -1;
215 static int hf_ipv6_dstopts_len_oct              = -1;
216 static int hf_ipv6_hopopts_nxt                  = -1;
217 static int hf_ipv6_hopopts_len                  = -1;
218 static int hf_ipv6_hopopts_len_oct              = -1;
219 static int hf_ipv6_routing_nxt                  = -1;
220 static int hf_ipv6_routing_len                  = -1;
221 static int hf_ipv6_routing_len_oct              = -1;
222 static int hf_ipv6_routing_type                 = -1;
223 static int hf_ipv6_routing_segleft              = -1;
224 static int hf_ipv6_routing_unknown_data         = -1;
225 static int hf_ipv6_fraghdr_nxt                  = -1;
226 static int hf_ipv6_fraghdr_reserved_octet       = -1;
227 static int hf_ipv6_fraghdr_offset               = -1;
228 static int hf_ipv6_fraghdr_reserved_bits        = -1;
229 static int hf_ipv6_fraghdr_more                 = -1;
230 static int hf_ipv6_fraghdr_ident                = -1;
231 static int hf_ipv6_fragment                     = -1;
232 static int hf_ipv6_fragment_overlap             = -1;
233 static int hf_ipv6_fragment_overlap_conflict    = -1;
234 static int hf_ipv6_fragment_multiple_tails      = -1;
235 static int hf_ipv6_fragment_too_long_fragment   = -1;
236 static int hf_ipv6_fragment_error               = -1;
237 static int hf_ipv6_fragment_count               = -1;
238 static int hf_ipv6_fragments                    = -1;
239 static int hf_ipv6_reassembled_in               = -1;
240 static int hf_ipv6_reassembled_length           = -1;
241 static int hf_ipv6_reassembled_data             = -1;
242
243 static int hf_ipv6_routing_src_reserved         = -1;
244 static int hf_ipv6_routing_src_addr             = -1;
245
246 static int hf_ipv6_routing_mipv6_reserved       = -1;
247 static int hf_ipv6_routing_mipv6_home_address   = -1;
248
249 static int hf_ipv6_routing_rpl_cmprI            = -1;
250 static int hf_ipv6_routing_rpl_cmprE            = -1;
251 static int hf_ipv6_routing_rpl_pad              = -1;
252 static int hf_ipv6_routing_rpl_reserved         = -1;
253 static int hf_ipv6_routing_rpl_addr_count       = -1;
254 static int hf_ipv6_routing_rpl_addr             = -1;
255 static int hf_ipv6_routing_rpl_fulladdr         = -1;
256
257 static int hf_ipv6_routing_srh_first_seg        = -1;
258 static int hf_ipv6_routing_srh_flags            = -1;
259 static int hf_ipv6_routing_srh_flag_unused1     = -1;
260 static int hf_ipv6_routing_srh_flag_p           = -1;
261 static int hf_ipv6_routing_srh_flag_o           = -1;
262 static int hf_ipv6_routing_srh_flag_a           = -1;
263 static int hf_ipv6_routing_srh_flag_h           = -1;
264 static int hf_ipv6_routing_srh_flag_unused2     = -1;
265 static int hf_ipv6_routing_srh_reserved         = -1;
266 static int hf_ipv6_routing_srh_addr             = -1;
267
268 static int hf_geoip_country             = -1;
269 static int hf_geoip_country_iso         = -1;
270 static int hf_geoip_city                = -1;
271 static int hf_geoip_as_number           = -1;
272 static int hf_geoip_as_org              = -1;
273 static int hf_geoip_latitude            = -1;
274 static int hf_geoip_longitude           = -1;
275 static int hf_geoip_src_summary         = -1;
276 static int hf_geoip_src_country         = -1;
277 static int hf_geoip_src_country_iso     = -1;
278 static int hf_geoip_src_city            = -1;
279 static int hf_geoip_src_as_number       = -1;
280 static int hf_geoip_src_as_org          = -1;
281 static int hf_geoip_src_latitude        = -1;
282 static int hf_geoip_src_longitude       = -1;
283 static int hf_geoip_dst_summary         = -1;
284 static int hf_geoip_dst_country         = -1;
285 static int hf_geoip_dst_country_iso     = -1;
286 static int hf_geoip_dst_city            = -1;
287 static int hf_geoip_dst_as_number       = -1;
288 static int hf_geoip_dst_as_org          = -1;
289 static int hf_geoip_dst_latitude        = -1;
290 static int hf_geoip_dst_longitude       = -1;
291
292 static gint ett_ipv6_proto              = -1;
293 static gint ett_ipv6_traffic_class      = -1;
294 static gint ett_ipv6_opt                = -1;
295 static gint ett_ipv6_opt_type           = -1;
296 static gint ett_ipv6_opt_rpl            = -1;
297 static gint ett_ipv6_opt_mpl            = -1;
298 static gint ett_ipv6_opt_dff_flags      = -1;
299 static gint ett_ipv6_hopopts_proto      = -1;
300 static gint ett_ipv6_fraghdr_proto      = -1;
301 static gint ett_ipv6_routing_proto      = -1;
302 static gint ett_ipv6_routing_srh_flags  = -1;
303 static gint ett_ipv6_routing_srh_vect   = -1;
304 static gint ett_ipv6_fragments          = -1;
305 static gint ett_ipv6_fragment           = -1;
306 static gint ett_ipv6_dstopts_proto      = -1;
307
308 static gint ett_geoip_info              = -1;
309
310 static expert_field ei_ipv6_routing_invalid_length = EI_INIT;
311 static expert_field ei_ipv6_routing_invalid_segleft = EI_INIT;
312 static expert_field ei_ipv6_routing_undecoded = EI_INIT;
313 static expert_field ei_ipv6_dst_addr_not_multicast = EI_INIT;
314 static expert_field ei_ipv6_src_route_list_mult_inst_same_addr = EI_INIT;
315 static expert_field ei_ipv6_src_route_list_src_addr = EI_INIT;
316 static expert_field ei_ipv6_src_route_list_dst_addr = EI_INIT;
317 static expert_field ei_ipv6_src_route_list_multicast_addr = EI_INIT;
318 static expert_field ei_ipv6_routing_rpl_cmpri_cmpre_pad = EI_INIT;
319 static expert_field ei_ipv6_routing_rpl_addr_count_ge0 = EI_INIT;
320 static expert_field ei_ipv6_routing_rpl_reserved = EI_INIT;
321 static expert_field ei_ipv6_routing_deprecated = EI_INIT;
322 static expert_field ei_ipv6_opt_jumbo_missing = EI_INIT;
323 static expert_field ei_ipv6_opt_jumbo_prohibited = EI_INIT;
324 static expert_field ei_ipv6_opt_jumbo_truncated = EI_INIT;
325 static expert_field ei_ipv6_opt_jumbo_fragment = EI_INIT;
326 static expert_field ei_ipv6_opt_invalid_len = EI_INIT;
327 static expert_field ei_ipv6_opt_unknown_data = EI_INIT;
328 static expert_field ei_ipv6_opt_deprecated = EI_INIT;
329 static expert_field ei_ipv6_hopopts_not_first = EI_INIT;
330 static expert_field ei_ipv6_plen_exceeds_framing = EI_INIT;
331 static expert_field ei_ipv6_plen_zero = EI_INIT;
332 static expert_field ei_ipv6_bogus_ipv6_version = EI_INIT;
333 static expert_field ei_ipv6_invalid_header = EI_INIT;
334 static expert_field ei_ipv6_opt_header_mismatch = EI_INIT;
335
336 static dissector_handle_t ipv6_handle;
337
338 #define set_address_ipv6(dst, src_ip6) \
339     set_address((dst), AT_IPv6, IPv6_ADDR_SIZE, (src_ip6))
340
341 #define set_address_ipv6_tvb(dst, tvb, offset) \
342     set_address_tvb((dst), AT_IPv6, IPv6_ADDR_SIZE, (tvb), (offset))
343
344 #define alloc_address_wmem_ipv6(scope, dst, src_ip6) \
345     alloc_address_wmem((scope), (dst), AT_IPv6, IPv6_ADDR_SIZE, (src_ip6))
346
347 #define alloc_address_tvb_ipv6(scope, dst, tvb, offset) \
348     alloc_address_tvb((scope), (dst), AT_IPv6, IPv6_ADDR_SIZE, (tvb), (offset))
349
350 extern const ws_in6_addr *tvb_get_ptr_ipv6(tvbuff_t tvb, int offset);
351 #define tvb_get_ptr_ipv6(tvb, offset) \
352     ((const ws_in6_addr *)tvb_get_ptr(tvb, offset, IPv6_ADDR_SIZE))
353
354 ipv6_pinfo_t *p_get_ipv6_pinfo(packet_info *pinfo)
355 {
356     return (ipv6_pinfo_t *)p_get_proto_data(pinfo->pool, pinfo, proto_ipv6, IPV6_PROTO_PINFO);
357 }
358
359 /* Return tree pointer (for tree root preference) */
360 proto_tree *p_ipv6_pinfo_select_root(packet_info *pinfo, proto_tree *tree)
361 {
362     ipv6_pinfo_t *p;
363
364     if ((p = p_get_ipv6_pinfo(pinfo)) != NULL && p->ipv6_tree != NULL)
365         return p->ipv6_tree;
366     return tree;
367 }
368
369 ipv6_pinfo_t *p_ipv6_pinfo_add_len(packet_info *pinfo, int exthdr_len)
370 {
371     ipv6_pinfo_t *p;
372
373     if ((p = p_get_ipv6_pinfo(pinfo)) == NULL)
374         return NULL;
375
376     p->frag_plen -= exthdr_len;
377     p->ipv6_item_len += exthdr_len;
378     return p;
379 }
380
381 static void p_add_ipv6_nxt(packet_info *pinfo, guint8 nxt)
382 {
383     guint8 *ptr;
384
385     ptr = (guint8 *)wmem_memdup(pinfo->pool, &nxt, sizeof(guint8));
386     p_add_proto_data(pinfo->pool, pinfo, proto_ipv6,
387                         (pinfo->curr_layer_num<<8) | IPV6_PROTO_VALUE, ptr);
388 }
389
390 static guint8 *p_get_ipv6_nxt(packet_info *pinfo)
391 {
392     return (guint8 *)p_get_proto_data(pinfo->pool, pinfo, proto_ipv6,
393                         (pinfo->curr_layer_num<<8) | IPV6_PROTO_VALUE);
394 }
395
396 static gpointer ipv6_value(packet_info *pinfo)
397 {
398     guint8 *nxt = p_get_ipv6_nxt(pinfo);
399
400     if (nxt == NULL) {
401         return GUINT_TO_POINTER(255); /* Reserved IP Protocol */
402     }
403     return GUINT_TO_POINTER((guint)*nxt);
404 }
405
406 static void ipv6_prompt(packet_info *pinfo, gchar *result)
407 {
408     gpointer value = ipv6_value(pinfo);
409
410     g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "IP protocol %u as", GPOINTER_TO_UINT(value));
411 }
412
413 static const char* ipv6_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
414 {
415     if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == AT_IPv6))
416         return "ipv6.src";
417
418     if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == AT_IPv6))
419         return "ipv6.dst";
420
421     if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == AT_IPv6))
422         return "ipv6.addr";
423
424     return CONV_FILTER_INVALID;
425 }
426
427 static ct_dissector_info_t ipv6_ct_dissector_info = {&ipv6_conv_get_filter_type};
428
429 static int
430 ipv6_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
431 {
432     conv_hash_t *hash = (conv_hash_t*) pct;
433     const ipv6_tap_info_t *ip6 = (const ipv6_tap_info_t *)vip;
434
435     add_conversation_table_data(hash, &ip6->ip6_src, &ip6->ip6_dst, 0, 0, 1,
436             pinfo->fd->pkt_len, &pinfo->rel_ts, &pinfo->abs_ts,
437             &ipv6_ct_dissector_info, ENDPOINT_NONE);
438
439     return 1;
440 }
441
442 static const char* ipv6_host_get_filter_type(hostlist_talker_t* host, conv_filter_type_e filter)
443 {
444     if ((filter == CONV_FT_ANY_ADDRESS) && (host->myaddress.type == AT_IPv6))
445         return "ipv6.addr";
446
447     return CONV_FILTER_INVALID;
448 }
449
450 static hostlist_dissector_info_t ipv6_host_dissector_info = {&ipv6_host_get_filter_type};
451
452 static int
453 ipv6_hostlist_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
454 {
455     conv_hash_t *hash = (conv_hash_t*) pit;
456     const ipv6_tap_info_t *ip6 = (const ipv6_tap_info_t *)vip;
457
458     add_hostlist_table_data(hash, &ip6->ip6_src, 0, TRUE, 1,
459                 pinfo->fd->pkt_len, &ipv6_host_dissector_info, ENDPOINT_NONE);
460     add_hostlist_table_data(hash, &ip6->ip6_dst, 0, FALSE, 1,
461                 pinfo->fd->pkt_len, &ipv6_host_dissector_info, ENDPOINT_NONE);
462
463     return 1;
464 }
465
466 static gboolean
467 ipv6_filter_valid(packet_info *pinfo)
468 {
469     return proto_is_frame_protocol(pinfo->layers, "ipv6");
470 }
471
472 static gchar*
473 ipv6_build_filter(packet_info *pinfo)
474 {
475     return g_strdup_printf("ipv6.addr eq %s and ipv6.addr eq %s",
476                 address_to_str(pinfo->pool, &pinfo->net_src),
477                 address_to_str(pinfo->pool, &pinfo->net_dst));
478 }
479
480 static gint
481 ipv6_previous_layer_id(packet_info *pinfo)
482 {
483     wmem_list_frame_t *layer;
484
485     layer = wmem_list_tail(pinfo->layers);
486     DISSECTOR_ASSERT(layer);
487     layer = wmem_list_frame_prev(layer);
488     if (layer != NULL) {
489         return GPOINTER_TO_INT(wmem_list_frame_data(layer));
490     }
491     return -1;
492 }
493
494 static const fragment_items ipv6_frag_items = {
495     &ett_ipv6_fragment,
496     &ett_ipv6_fragments,
497     &hf_ipv6_fragments,
498     &hf_ipv6_fragment,
499     &hf_ipv6_fragment_overlap,
500     &hf_ipv6_fragment_overlap_conflict,
501     &hf_ipv6_fragment_multiple_tails,
502     &hf_ipv6_fragment_too_long_fragment,
503     &hf_ipv6_fragment_error,
504     &hf_ipv6_fragment_count,
505     &hf_ipv6_reassembled_in,
506     &hf_ipv6_reassembled_length,
507     &hf_ipv6_reassembled_data,
508     "IPv6 fragments"
509 };
510
511 static dissector_table_t ip_dissector_table;
512 static dissector_table_t ipv6_routing_dissector_table;
513
514 /* Reassemble fragmented datagrams */
515 static gboolean ipv6_reassemble = TRUE;
516
517 /* Place IPv6 summary in proto tree */
518 static gboolean ipv6_summary_in_tree = TRUE;
519
520 /* Look up addresses via mmdbresolve */
521 static gboolean ipv6_use_geoip = TRUE;
522
523 /* Perform strict RFC adherence checking */
524 static gboolean g_ipv6_rpl_srh_strict_rfc_checking = FALSE;
525
526 /* Use heuristics to determine subdissector */
527 static gboolean try_heuristic_first = FALSE;
528
529 /* Display IPv6 extension headers under the root tree */
530 static gboolean ipv6_exthdr_under_root = FALSE;
531
532 /* Hide extension header generated field for length */
533 static gboolean ipv6_exthdr_hide_len_oct_field = FALSE;
534
535 /* Assume TSO and correct zero-length IP packets */
536 static gboolean ipv6_tso_supported = FALSE;
537
538 /*
539  * defragmentation of IPv6
540  */
541 static reassembly_table ipv6_reassembly_table;
542
543 /* http://www.iana.org/assignments/ipv6-parameters (last updated 2015-07-07) */
544 static const value_string ipv6_opt_type_vals[] = {
545     { IP6OPT_PAD1,          "Pad1"                          },
546     { IP6OPT_PADN,          "PadN"                          },
547     { IP6OPT_TEL,           "Tunnel Encapsulation Limit"    },
548     { IP6OPT_RTALERT,       "Router Alert"                  },
549     { IP6OPT_CALIPSO,       "CALIPSO"                       },
550     { IP6OPT_SMF_DPD,       "SMF_DPD"                       },
551     { IP6OPT_PDM,           "Performance and Diagnostic Metrics" },
552     { IP6OPT_EXP_1E,        "Experimental (0x1E)"           },
553     { IP6OPT_QUICKSTART,    "Quick-Start"                   },
554     { IP6OPT_EXP_3E,        "Experimental (0x3E)"           },
555     { IP6OPT_EXP_5E,        "Experimental (0x5E)"           },
556     { IP6OPT_RPL,           "RPL Option"                    },
557     { IP6OPT_MPL,           "MPL Option"                    },
558     { IP6OPT_EXP_7E,        "Experimental (0x7E)"           },
559     { IP6OPT_ENDI,          "Endpoint Identification"       },
560     { IP6OPT_ILNP_NONCE,    "ILNP Nonce"                    },
561     { IP6OPT_LIO,           "Line-Identification Option"    },
562     { IP6OPT_EXP_9E,        "Experimental (0x9E)"           },
563     { IP6OPT_EXP_BE,        "Experimental (0xBE)"           },
564     { IP6OPT_JUMBO,         "Jumbo Payload"                 },
565     { IP6OPT_HOME_ADDRESS,  "Home Address"                  },
566     { IP6OPT_EXP_DE,        "Experimental (0xDE)"           },
567     { IP6OPT_IP_DFF,        "IP_DFF"                        },
568     { IP6OPT_EXP_FE,        "Experimental (0xFE)"           },
569     { 0, NULL }
570 };
571 value_string_ext ipv6_opt_type_vals_ext = VALUE_STRING_EXT_INIT(ipv6_opt_type_vals);
572
573 static const value_string ipv6_opt_rtalert_vals[] = {
574     { IP6OPT_RTALERT_MLD,       "MLD"            },
575     { IP6OPT_RTALERT_RSVP,      "RSVP"           },
576     { IP6OPT_RTALERT_ACTNET,    "Active Network" },
577     { 0, NULL }
578 };
579
580 enum {
581     IP6OPT_SMF_DPD_NULL = 0,
582     IP6OPT_SMF_DPD_DFLT,
583     IP6OPT_SMF_DPD_IPv4,
584     IP6OPT_SMF_DPD_IPv6
585 };
586
587 static const value_string ipv6_opt_smf_dpd_tidty_vals[] = {
588     { IP6OPT_SMF_DPD_NULL, "NULL"       },
589     { IP6OPT_SMF_DPD_DFLT, "DEFAULT"    },
590     { IP6OPT_SMF_DPD_IPv4, "IPv4"       },
591     { IP6OPT_SMF_DPD_IPv6, "IPv6"       },
592     { 0, NULL }
593 };
594
595 enum {
596     IPv6_OPT_ACTION_SKIP = 0,
597     IPv6_OPT_ACTION_DISC,
598     IPv6_OPT_ACTION_ICMP,
599     IPv6_OPT_ACTION_MCST,
600 };
601
602 static const value_string ipv6_opt_type_action_vals[] = {
603     { IPv6_OPT_ACTION_SKIP, "Skip and continue" },
604     { IPv6_OPT_ACTION_DISC, "Discard" },
605     { IPv6_OPT_ACTION_ICMP, "Discard and send ICMP Parameter Problem" },
606     { IPv6_OPT_ACTION_MCST, "Discard and send ICMP if not multicast" },
607     { 0, NULL }
608 };
609
610 enum {
611     IPv6_OPT_HDR_HBH = 0,
612     IPv6_OPT_HDR_DST,
613     IPv6_OPT_HDR_ANY
614 };
615
616 static const gint _ipv6_opt_type_hdr[][2] = {
617     { IP6OPT_TEL,           IPv6_OPT_HDR_DST },
618     { IP6OPT_RTALERT,       IPv6_OPT_HDR_HBH },
619     { IP6OPT_CALIPSO,       IPv6_OPT_HDR_HBH },
620     { IP6OPT_SMF_DPD,       IPv6_OPT_HDR_HBH },
621     { IP6OPT_PDM,           IPv6_OPT_HDR_DST },
622     { IP6OPT_QUICKSTART,    IPv6_OPT_HDR_HBH },
623     { IP6OPT_RPL,           IPv6_OPT_HDR_HBH },
624     { IP6OPT_MPL,           IPv6_OPT_HDR_HBH },
625     { IP6OPT_ILNP_NONCE,    IPv6_OPT_HDR_DST },
626     { IP6OPT_LIO,           IPv6_OPT_HDR_DST },
627     { IP6OPT_JUMBO,         IPv6_OPT_HDR_HBH },
628     { IP6OPT_HOME_ADDRESS,  IPv6_OPT_HDR_DST },
629     { IP6OPT_IP_DFF,        IPv6_OPT_HDR_HBH },
630     { 0, IPv6_OPT_HDR_ANY }
631 };
632
633 static inline gint
634 ipv6_opt_type_hdr(gint type)
635 {
636     const gint (*p)[2] = _ipv6_opt_type_hdr;
637
638     for (; (*p)[1] != IPv6_OPT_HDR_ANY; p++) {
639         if ((*p)[0] == type) {
640             return (*p)[1];
641         }
642     }
643     return IPv6_OPT_HDR_ANY;
644 }
645
646 enum {
647     IPv6_RT_HEADER_SOURCE_ROUTING  = 0,     /* DEPRECATED */
648     IPv6_RT_HEADER_NIMROD          = 1,     /* DEPRECATED */
649     IPv6_RT_HEADER_MOBILE_IP       = 2,
650     IPv6_RT_HEADER_RPL             = 3,
651     IPv6_RT_HEADER_SEGMENT_ROUTING = 4,
652     IPv6_RT_HEADER_EXP1            = 253,
653     IPv6_RT_HEADER_EXP2            = 254
654 };
655
656 /* Routing Header Types */
657 static const value_string routing_header_type[] = {
658     { IPv6_RT_HEADER_SOURCE_ROUTING,    "Source Route"     },
659     { IPv6_RT_HEADER_NIMROD,            "Nimrod"           },
660     { IPv6_RT_HEADER_MOBILE_IP,         "Type 2 Routing"   },
661     { IPv6_RT_HEADER_RPL,               "RPL Source Route" },
662     { IPv6_RT_HEADER_SEGMENT_ROUTING,   "Segment Routing"  },
663     { IPv6_RT_HEADER_EXP1,              "Experiment 1"     },
664     { IPv6_RT_HEADER_EXP2,              "Experiment 2"     },
665     { 0, NULL }
666 };
667
668 static gboolean
669 capture_ipv6(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
670 {
671     guint8 nxt;
672
673     if (!BYTES_ARE_IN_FRAME(offset, len, IPv6_HDR_SIZE))
674         return FALSE;
675
676     capture_dissector_increment_count(cpinfo, proto_ipv6);
677
678     nxt = pd[offset+6];           /* get the "next header" value */
679     offset += IPv6_HDR_SIZE;      /* skip past the IPv6 header */
680
681     return try_capture_dissector("ip.proto", nxt, pd, offset, len, cpinfo, pseudo_header);
682 }
683
684 static gboolean
685 capture_ipv6_exthdr(const guchar *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
686 {
687     guint8 nxt;
688     int    advance;
689
690     if (!BYTES_ARE_IN_FRAME(offset, len, 2))
691         return FALSE;
692     nxt = pd[offset];
693     switch (nxt) {
694         case IP_PROTO_FRAGMENT:
695             advance = IPv6_FRAGMENT_HDR_SIZE;
696             break;
697         default:
698             advance = (pd[offset+1] + 1) << 3;
699             break;
700     }
701     if (!BYTES_ARE_IN_FRAME(offset, len, advance))
702         return FALSE;
703     offset += advance;
704
705     return try_capture_dissector("ip.proto", nxt, pd, offset, len, cpinfo, pseudo_header);
706 }
707
708 static void
709 add_geoip_info_entry(proto_tree *tree, tvbuff_t *tvb, gint offset, const ws_in6_addr *ip6, int isdst)
710 {
711     const mmdb_lookup_t *lookup = maxmind_db_lookup_ipv6(ip6);
712     if (!lookup->found) return;
713
714     wmem_strbuf_t *summary = wmem_strbuf_new(wmem_packet_scope(), "");
715     if (lookup->city) {
716         wmem_strbuf_append(summary, lookup->city);
717     }
718     if (lookup->country_iso) {
719         if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
720         wmem_strbuf_append(summary, lookup->country_iso);
721     } else if (lookup->country) {
722         if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
723         wmem_strbuf_append(summary, lookup->country);
724     }
725     if (lookup->as_number > 0) {
726         if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
727         wmem_strbuf_append_printf(summary, "ASN %u", lookup->as_number);
728     }
729     if (lookup->as_org) {
730         if (wmem_strbuf_get_len(summary) > 0) wmem_strbuf_append(summary, ", ");
731         wmem_strbuf_append(summary, lookup->as_org);
732     }
733
734     int addr_offset = offset + isdst ? IP6H_DST : IP6H_SRC;
735     int dir_hf = isdst ? hf_geoip_dst_summary : hf_geoip_src_summary;
736     proto_item *geoip_info_item = proto_tree_add_string(tree, dir_hf, tvb, addr_offset, 16, wmem_strbuf_finalize(summary));
737     PROTO_ITEM_SET_GENERATED(geoip_info_item);
738     proto_tree *geoip_info_tree = proto_item_add_subtree(geoip_info_item, ett_geoip_info);
739
740     proto_item *item;
741
742     if (lookup->city) {
743         dir_hf = isdst ? hf_geoip_dst_city : hf_geoip_src_city;
744         item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->city);
745         PROTO_ITEM_SET_GENERATED(item);
746         item = proto_tree_add_string(geoip_info_tree, hf_geoip_city, tvb, addr_offset, 16, lookup->city);
747         PROTO_ITEM_SET_GENERATED(item);
748     }
749
750     if (lookup->country) {
751         dir_hf = isdst ? hf_geoip_dst_country : hf_geoip_src_country;
752         item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->country);
753         PROTO_ITEM_SET_GENERATED(item);
754         item = proto_tree_add_string(geoip_info_tree, hf_geoip_country, tvb, addr_offset, 16, lookup->country);
755         PROTO_ITEM_SET_GENERATED(item);
756     }
757
758     if (lookup->country_iso) {
759         dir_hf = isdst ? hf_geoip_dst_country_iso : hf_geoip_src_country_iso;
760         item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->country_iso);
761         PROTO_ITEM_SET_GENERATED(item);
762         item = proto_tree_add_string(geoip_info_tree, hf_geoip_country_iso, tvb, addr_offset, 16, lookup->country_iso);
763         PROTO_ITEM_SET_GENERATED(item);
764     }
765
766     if (lookup->as_number > 0) {
767         dir_hf = isdst ? hf_geoip_dst_as_number : hf_geoip_src_as_number;
768         item = proto_tree_add_uint(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->as_number);
769         PROTO_ITEM_SET_GENERATED(item);
770         item = proto_tree_add_uint(geoip_info_tree, hf_geoip_as_number, tvb, addr_offset, 16, lookup->as_number);
771         PROTO_ITEM_SET_GENERATED(item);
772     }
773
774     if (lookup->as_org) {
775         dir_hf = isdst ? hf_geoip_dst_as_org : hf_geoip_src_as_org;
776         item = proto_tree_add_string(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->as_org);
777         PROTO_ITEM_SET_GENERATED(item);
778         item = proto_tree_add_string(geoip_info_tree, hf_geoip_as_org, tvb, addr_offset, 16, lookup->as_org);
779         PROTO_ITEM_SET_GENERATED(item);
780     }
781
782     if (lookup->latitude >= -90.0 && lookup->latitude <= 90.0) {
783         dir_hf = isdst ? hf_geoip_dst_latitude : hf_geoip_src_latitude;
784         item = proto_tree_add_double(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->latitude);
785         PROTO_ITEM_SET_GENERATED(item);
786         item = proto_tree_add_double(geoip_info_tree, hf_geoip_latitude, tvb, addr_offset, 16, lookup->latitude);
787         PROTO_ITEM_SET_GENERATED(item);
788     }
789
790     if (lookup->longitude >= -180.0 && lookup->longitude <= 180.0) {
791         dir_hf = isdst ? hf_geoip_dst_longitude : hf_geoip_src_longitude;
792         item = proto_tree_add_double(geoip_info_tree, dir_hf, tvb, addr_offset, 16, lookup->longitude);
793         PROTO_ITEM_SET_GENERATED(item);
794         item = proto_tree_add_double(geoip_info_tree, hf_geoip_longitude, tvb, addr_offset, 16, lookup->longitude);
795         PROTO_ITEM_SET_GENERATED(item);
796     }
797 }
798
799 static void
800 add_geoip_info(proto_tree *tree, tvbuff_t *tvb, gint offset, const ws_in6_addr *src, const ws_in6_addr *dst)
801 {
802     add_geoip_info_entry(tree, tvb, offset, src, FALSE);
803     add_geoip_info_entry(tree, tvb, offset, dst, TRUE);
804 }
805
806 /* Returns TRUE if reassembled */
807 static gboolean
808 ipv6_reassemble_do(tvbuff_t **tvb_ptr, gint *offset_ptr, packet_info *pinfo, proto_tree *ipv6_tree,
809                     guint32 plen, guint16 frag_off, gboolean frag_flg, guint32 frag_ident,
810                     gboolean *show_data_ptr)
811 {
812     fragment_head   *ipfd_head;
813     tvbuff_t        *next_tvb;
814     gboolean         update_col_info = TRUE;
815
816     pinfo->fragmented = TRUE;
817     *show_data_ptr = TRUE;
818     if (!ipv6_reassemble) {
819         /* not reassembling */
820         if (frag_off == 0) {
821              /* first fragment */
822             *show_data_ptr = FALSE;
823         }
824         return FALSE;
825     }
826
827     /* reassembling */
828     if (tvb_bytes_exist(*tvb_ptr, *offset_ptr, plen)) {
829         ipfd_head = fragment_add_check(&ipv6_reassembly_table,
830                                        *tvb_ptr, *offset_ptr, pinfo, frag_ident, NULL,
831                                        frag_off, plen, frag_flg);
832         next_tvb = process_reassembled_data(*tvb_ptr, *offset_ptr, pinfo, "Reassembled IPv6",
833                                             ipfd_head, &ipv6_frag_items, &update_col_info, ipv6_tree);
834         if (next_tvb) {
835             /* Process post-fragment headers after reassembly */
836             *offset_ptr = 0;
837             *tvb_ptr = next_tvb;
838             pinfo->fragmented = FALSE;
839             *show_data_ptr = FALSE;
840             return TRUE;
841         }
842     }
843     return FALSE;
844 }
845
846 static proto_item *
847 _proto_tree_add_ipv6_vector_address(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
848                             gint length, const ws_in6_addr *value_ptr, int idx)
849 {
850     address addr;
851     gchar *str;
852
853     set_address_ipv6(&addr, value_ptr);
854     str = address_with_resolution_to_str(wmem_packet_scope(), &addr);
855     return proto_tree_add_ipv6_format(tree, hfindex, tvb, start, length,
856                         value_ptr, "Address[%d]: %s", idx, str);
857 }
858
859 /* IPv6 Source Routing Header (Type 0) */
860 static int
861 dissect_routing6_rt0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
862 {
863     struct ws_rthdr *rt = (struct ws_rthdr *)data;
864     proto_item *ti;
865     int offset = 0;
866     gint idx;
867     gint rt0_addr_count;
868     const ws_in6_addr *addr = NULL;
869
870     proto_tree_add_item(tree, hf_ipv6_routing_src_reserved, tvb, offset, 4, ENC_NA);
871     offset += 4;
872
873     if (rt->hdr.ip6r_len % 2 != 0) {
874         expert_add_info_format(pinfo, rt->ti_len, &ei_ipv6_routing_invalid_length,
875                 "IPv6 Routing Header extension header length must not be odd");
876     }
877     rt0_addr_count = rt->hdr.ip6r_len / 2;
878     if (rt->hdr.ip6r_segleft > rt0_addr_count) {
879         expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
880                 "IPv6 Type 0 Routing Header segments left field must not exceed address count (%u)", rt0_addr_count);
881     }
882
883     for (idx = 1; idx <= rt0_addr_count; idx++) {
884         addr = tvb_get_ptr_ipv6(tvb, offset);
885         ti = _proto_tree_add_ipv6_vector_address(tree, hf_ipv6_routing_src_addr, tvb,
886                             offset, IPv6_ADDR_SIZE, addr, idx);
887         offset += IPv6_ADDR_SIZE;
888         if (in6_addr_is_multicast(addr)) {
889             expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
890         }
891     }
892
893     if (addr != NULL && pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
894         alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, addr);
895     }
896
897     expert_add_info(pinfo, rt->ti_type, &ei_ipv6_routing_deprecated);
898     return tvb_captured_length(tvb);
899 }
900
901 /* Mobile IPv6 Routing Header (Type 2) */
902 static int
903 dissect_routing6_mipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
904 {
905     struct ws_rthdr *rt = (struct ws_rthdr *)data;
906     proto_item *ti;
907     int offset = 0;
908     const ws_in6_addr *addr;
909
910     proto_tree_add_item(tree, hf_ipv6_routing_mipv6_reserved, tvb, offset, 4, ENC_NA);
911     offset += 4;
912
913     if (rt->hdr.ip6r_len != 2) {
914         expert_add_info_format(pinfo, rt->ti_len, &ei_ipv6_routing_invalid_length,
915                 "IPv6 Type 2 Routing Header extension header length must equal 2");
916     }
917     if (rt->hdr.ip6r_segleft != 1) {
918         expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
919                 "IPv6 Type 2 Routing Header segments left field must equal 1");
920     }
921
922     addr = tvb_get_ptr_ipv6(tvb, offset);
923     ti = _proto_tree_add_ipv6_vector_address(tree, hf_ipv6_routing_mipv6_home_address, tvb,
924                         offset, IPv6_ADDR_SIZE, addr, 1);
925     if (in6_addr_is_multicast(addr)) {
926         expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
927     }
928
929     if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
930         alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, addr);
931     }
932
933     return tvb_captured_length(tvb);
934 }
935
936 /* RPL Source Routing Header (Type 3) */
937 static int
938 dissect_routing6_rpl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
939 {
940     struct ws_rthdr *rt = (struct ws_rthdr *)data;
941     proto_item *ti;
942     int offset = 0;
943     guint8 cmprI, cmprE, cmprX, pad;
944     guint32 reserved;
945     gint idx;
946     gint rpl_addr_count;
947     ws_in6_addr rpl_fulladdr;
948     const ws_in6_addr *ip6_dst_addr, *ip6_src_addr;
949     wmem_array_t *rpl_addr_vector = NULL;
950     guint i;
951
952     /* Must be IPv6 addresses */
953     if ((pinfo->dst.type != AT_IPv6) || (pinfo->src.type != AT_IPv6))
954         return 0;
955
956     /* IPv6 destination address used for elided bytes */
957     ip6_dst_addr = (const ws_in6_addr *)pinfo->dst.data;
958     /* IPv6 source address used for strict checking */
959     ip6_src_addr = (const ws_in6_addr *)pinfo->src.data;
960
961     /* from RFC6554: Multicast addresses MUST NOT appear in the IPv6 Destination Address field */
962     if (in6_addr_is_multicast(ip6_dst_addr)) {
963         expert_add_info(pinfo, proto_tree_get_parent(tree), &ei_ipv6_dst_addr_not_multicast);
964     }
965
966     proto_tree_add_item(tree, hf_ipv6_routing_rpl_cmprI, tvb, offset, 4, ENC_BIG_ENDIAN);
967     proto_tree_add_item(tree, hf_ipv6_routing_rpl_cmprE, tvb, offset, 4, ENC_BIG_ENDIAN);
968     ti = proto_tree_add_item(tree, hf_ipv6_routing_rpl_pad, tvb, offset, 4, ENC_BIG_ENDIAN);
969
970     cmprI = tvb_get_guint8(tvb, offset) & 0xF0;
971     cmprE = tvb_get_guint8(tvb, offset) & 0x0F;
972     pad   = tvb_get_guint8(tvb, offset + 1) & 0xF0;
973
974     /* Shift bytes over */
975     cmprI >>= 4;
976     pad >>= 4;
977
978     /* from RFC6554: when CmprI and CmprE are both 0, Pad MUST carry a value of 0 */
979     if (cmprI == 0 && cmprE == 0 && pad != 0) {
980         expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_cmpri_cmpre_pad, "When cmprI equals 0 and cmprE equals 0, pad MUST equal 0 but instead was %d", pad);
981     }
982
983     ti = proto_tree_add_item(tree, hf_ipv6_routing_rpl_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
984     reserved = tvb_get_bits32(tvb, ((offset + 1) * 8) + 4, 20, ENC_BIG_ENDIAN);
985
986     if (reserved != 0) {
987         expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_reserved, "Reserved field must equal 0 but instead was %d", reserved);
988     }
989
990     /* From RFC6554:
991      *   n = (((Hdr Ext Len * 8) - Pad - (16 - CmprE)) / (16 - CmprI)) + 1
992      */
993     rpl_addr_count = 0;
994     if (rt->hdr.ip6r_len > 0) {
995         rpl_addr_count = (((rt->hdr.ip6r_len * 8) - pad - (16 - cmprE)) / (16 - cmprI)) + 1;
996     }
997     ti = proto_tree_add_int(tree, hf_ipv6_routing_rpl_addr_count, tvb, offset, 2, rpl_addr_count);
998     PROTO_ITEM_SET_GENERATED(ti);
999     if (rpl_addr_count < 0) {
1000         /* This error should always be reported */
1001         expert_add_info_format(pinfo, ti, &ei_ipv6_routing_rpl_addr_count_ge0, "Calculated total address count must be greater than or equal to 0, instead was %d", rpl_addr_count);
1002     }
1003     else if (rt->hdr.ip6r_segleft > (guint)rpl_addr_count) {
1004         expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
1005             "IPv6 RPL Routing Header segments left field must not exceed address count (%d)", rpl_addr_count);
1006     }
1007
1008     if (rpl_addr_count > 0) {
1009         offset += 4;
1010
1011         if (g_ipv6_rpl_srh_strict_rfc_checking)
1012             rpl_addr_vector = wmem_array_sized_new(wmem_packet_scope(), IPv6_ADDR_SIZE, rpl_addr_count);
1013
1014         /* We use cmprI for internal (e.g.: not last) address for how many bytes to elide, so actual bytes present = 16-CmprI */
1015         for (idx = 1; idx <= rpl_addr_count; idx++) {
1016             if (idx == rpl_addr_count)
1017                 cmprX = 16 - cmprE;
1018             else
1019                 cmprX = 16 - cmprI;
1020             proto_tree_add_item(tree, hf_ipv6_routing_rpl_addr, tvb, offset, cmprX, ENC_NA);
1021             /* Display Full Address */
1022             memcpy(&rpl_fulladdr, ip6_dst_addr, IPv6_ADDR_SIZE);
1023             tvb_memcpy(tvb, &rpl_fulladdr.bytes[16-cmprX], offset, cmprX);
1024             ti = _proto_tree_add_ipv6_vector_address(tree, hf_ipv6_routing_rpl_fulladdr, tvb,
1025                                 offset, cmprX, &rpl_fulladdr, idx);
1026             PROTO_ITEM_SET_GENERATED(ti);
1027             offset += cmprX;
1028
1029             /* IPv6 Source and Destination addresses of the encapsulating datagram (MUST) not appear in the SRH*/
1030             if (memcmp(&rpl_fulladdr, ip6_src_addr, IPv6_ADDR_SIZE) == 0) {
1031                 expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_src_addr);
1032             }
1033             if (memcmp(&rpl_fulladdr, ip6_dst_addr, IPv6_ADDR_SIZE) == 0) {
1034                 expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_dst_addr);
1035             }
1036
1037             /* Multicast addresses MUST NOT appear in the in SRH */
1038             if (in6_addr_is_multicast(&rpl_fulladdr)) {
1039                 expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
1040             }
1041
1042             if (g_ipv6_rpl_srh_strict_rfc_checking) {
1043                 /* from RFC6554: */
1044                 /* The SRH MUST NOT specify a path that visits a node more than once. */
1045                 /* To do this, we will just check the current 'addr' against the previous addresses */
1046                 for (i = 0; i < wmem_array_get_count(rpl_addr_vector); i++) {
1047                     /* Compare the addresses */
1048                     if (memcmp(&rpl_fulladdr, wmem_array_index(rpl_addr_vector, i), IPv6_ADDR_SIZE) == 0) {
1049                         /* Found a previous that is the same */
1050                         expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_mult_inst_same_addr);
1051                         break;
1052                     }
1053                 }
1054                 wmem_array_append(rpl_addr_vector, &rpl_fulladdr, 1);
1055             }
1056
1057             if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
1058                 alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, &rpl_fulladdr);
1059             }
1060         }
1061     }
1062
1063     return tvb_captured_length(tvb);
1064 }
1065
1066 /* Segment Routing Header (Type 4) */
1067 /* draft-ietf-6man-segment-routing-header-05 */
1068 static int
1069 dissect_routing6_srh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1070 {
1071     struct ws_rthdr *rt = (struct ws_rthdr *)data;
1072     proto_item *ti;
1073     int offset = 0;
1074     gint offlim, offstart;
1075     gint idx;
1076     gint srh_first_seg, srh_addr_count;
1077     const ws_in6_addr *addr;
1078     proto_tree *rthdr_srh_addr_tree;
1079     static const int *srh_flags[] = {
1080         &hf_ipv6_routing_srh_flag_unused1,
1081         &hf_ipv6_routing_srh_flag_p,
1082         &hf_ipv6_routing_srh_flag_o,
1083         &hf_ipv6_routing_srh_flag_a,
1084         &hf_ipv6_routing_srh_flag_h,
1085         &hf_ipv6_routing_srh_flag_unused2,
1086         NULL
1087     };
1088
1089     srh_first_seg = tvb_get_guint8(tvb, offset);
1090     proto_tree_add_item(tree, hf_ipv6_routing_srh_first_seg, tvb, offset, 1, ENC_NA);
1091     offset += 1;
1092     srh_addr_count = srh_first_seg + 1;
1093
1094     /* TODO: dissect TLVs */
1095     ti = proto_tree_add_bitmask(tree, tvb, offset, hf_ipv6_routing_srh_flags,
1096                             ett_ipv6_routing_srh_flags, srh_flags, ENC_BIG_ENDIAN);
1097     expert_add_info_format(pinfo, ti, &ei_ipv6_routing_undecoded,
1098                 "Dissection for SRH TLVs not yet implemented");
1099     offset += 1;
1100
1101     proto_tree_add_item(tree, hf_ipv6_routing_srh_reserved, tvb, offset, 2, ENC_NA);
1102     offset += 2;
1103
1104     if (rt->hdr.ip6r_segleft > srh_first_seg) {
1105         expert_add_info_format(pinfo, rt->ti_segleft, &ei_ipv6_routing_invalid_segleft,
1106                                "IPv6 Type 4 Routing Header segments left field must not exceed first segment (%u)", srh_first_seg);
1107     }
1108
1109     offstart = offset;
1110     offlim = offset + srh_addr_count * IPv6_ADDR_SIZE;
1111
1112     /* Destination address is the first vector address */
1113     addr = tvb_get_ptr_ipv6(tvb, offset);
1114     if (in6_addr_is_multicast(addr)) {
1115         expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
1116     }
1117     ti = _proto_tree_add_ipv6_vector_address(tree, hf_ipv6_routing_srh_addr, tvb,
1118                             offset, IPv6_ADDR_SIZE, addr, 0);
1119     if (rt->hdr.ip6r_segleft == 1) {
1120         proto_item_append_text(ti, " [next segment]");
1121     }
1122
1123     if (pinfo->dst.type == AT_IPv6 && rt->hdr.ip6r_segleft > 0) {
1124         alloc_address_wmem_ipv6(pinfo->pool, &pinfo->dst, addr);
1125     }
1126
1127     offset += IPv6_ADDR_SIZE;
1128     for (idx = 1; offset < offlim; offset += IPv6_ADDR_SIZE, idx++) {
1129         addr = tvb_get_ptr_ipv6(tvb, offset);
1130         if (in6_addr_is_multicast(addr)) {
1131             expert_add_info(pinfo, ti, &ei_ipv6_src_route_list_multicast_addr);
1132         }
1133         ti = _proto_tree_add_ipv6_vector_address(tree, hf_ipv6_routing_srh_addr, tvb,
1134                             offset, IPv6_ADDR_SIZE, addr, idx);
1135         if (idx == rt->hdr.ip6r_segleft - 1) {
1136             proto_item_append_text(ti, " [next segment]");
1137         }
1138     }
1139
1140     rthdr_srh_addr_tree = proto_tree_add_subtree_format(tree, tvb, offstart, srh_addr_count * IPv6_ADDR_SIZE,
1141                             ett_ipv6_routing_srh_vect, &ti, "Segments in Traversal Order");
1142     PROTO_ITEM_SET_GENERATED(ti);
1143     offset -= IPv6_ADDR_SIZE;
1144     for (idx = srh_first_seg; offset >= offstart; offset -= IPv6_ADDR_SIZE, idx--) {
1145         addr = tvb_get_ptr_ipv6(tvb, offset);
1146         ti = _proto_tree_add_ipv6_vector_address(rthdr_srh_addr_tree, hf_ipv6_routing_srh_addr, tvb,
1147                             offset, IPv6_ADDR_SIZE, addr, idx);
1148         if (idx == rt->hdr.ip6r_segleft - 1) {
1149             proto_item_append_text(ti, " [next segment]");
1150         }
1151     }
1152
1153     return tvb_captured_length(tvb);
1154 }
1155
1156
1157 /*
1158     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1159     |  Next Header  |  Hdr Ext Len  |  Routing Type | Segments Left |
1160     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1161     |                                                               |
1162     .                                                               .
1163     .                       type-specific data                      .
1164     .                                                               .
1165     |                                                               |
1166     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1167 */
1168 static int
1169 dissect_routing6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
1170     struct ws_rthdr    rt;
1171     guint              nxt, hdr_len, total_len;
1172     proto_tree        *rt_tree, *root_tree;
1173     proto_item        *pi, *ti, *ti_hdr_len, *ti_type, *ti_segs;
1174     int                offset = 0;
1175     tvbuff_t          *next_tvb;
1176     int                type, type_len;
1177     dissector_handle_t type_dissector;
1178
1179     col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 routing");
1180
1181     root_tree = p_ipv6_pinfo_select_root(pinfo, tree);
1182
1183     pi = proto_tree_add_item(root_tree, proto_ipv6_routing, tvb, offset, -1, ENC_NA);
1184     rt_tree = proto_item_add_subtree(pi, ett_ipv6_routing_proto);
1185
1186     proto_tree_add_item(rt_tree, hf_ipv6_routing_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
1187     nxt = tvb_get_guint8(tvb, offset);
1188     offset += 1;
1189
1190     ti_hdr_len = proto_tree_add_item(rt_tree, hf_ipv6_routing_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1191     hdr_len = tvb_get_guint8(tvb, offset);
1192     /*
1193           Hdr Ext Len         8-bit unsigned integer.  Length of the Routing
1194                               header in 8-octet units, not including the
1195                               first 8 octets.
1196     */
1197     total_len = (hdr_len + 1) * 8;
1198     type_len = total_len - 4;
1199
1200     proto_item_set_len(pi, total_len);
1201     ti = proto_tree_add_uint(rt_tree, hf_ipv6_routing_len_oct, tvb, offset, 1, total_len);
1202     PROTO_ITEM_SET_GENERATED(ti);
1203     if (ipv6_exthdr_hide_len_oct_field) {
1204         PROTO_ITEM_SET_HIDDEN(ti);
1205         proto_item_append_text(ti_hdr_len, " (%d bytes)", total_len);
1206     }
1207     p_ipv6_pinfo_add_len(pinfo, total_len);
1208     offset += 1;
1209
1210     ti_type = proto_tree_add_item(rt_tree, hf_ipv6_routing_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1211     type = tvb_get_guint8(tvb, offset);
1212     proto_item_append_text(pi, " (%s)", val_to_str(type, routing_header_type, "Unknown type %u"));
1213     offset += 1;
1214
1215     ti_segs = proto_tree_add_item(rt_tree, hf_ipv6_routing_segleft, tvb, offset, 1, ENC_BIG_ENDIAN);
1216     offset += 1;
1217
1218     type_dissector = dissector_get_uint_handle(ipv6_routing_dissector_table, type);
1219     if (type_dissector != NULL) {
1220         tvb_memcpy(tvb, &(rt.hdr), 0, 4);
1221         rt.ti_len = ti_hdr_len;
1222         rt.ti_type = ti_type;
1223         rt.ti_segleft = ti_segs;
1224         call_dissector_with_data(type_dissector, tvb_new_subset_length(tvb, offset, type_len), pinfo, rt_tree, &rt);
1225     }
1226     else {
1227         /* Unknown Routing Header Type */
1228         ti = proto_tree_add_item(rt_tree, hf_ipv6_routing_unknown_data, tvb, offset, type_len, ENC_NA);
1229         expert_add_info(pinfo, ti, &ei_ipv6_routing_undecoded);
1230     }
1231
1232     p_add_ipv6_nxt(pinfo, nxt);
1233
1234     next_tvb = tvb_new_subset_remaining(tvb, total_len);
1235     ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
1236     return tvb_captured_length(tvb);
1237 }
1238
1239 static int
1240 dissect_fraghdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) {
1241     proto_item      *pi, *ti;
1242     proto_tree      *frag_tree, *root_tree;
1243     guint8           nxt;
1244     guint16          offlg;
1245     guint16          frag_off;
1246     gboolean         frag_flg;
1247     guint32          frag_ident;
1248     gint             offset = 0;
1249     ipv6_pinfo_t    *ipv6_pinfo;
1250     gboolean         show_data = FALSE;
1251     gboolean         reassembled;
1252     tvbuff_t        *next_tvb;
1253
1254     nxt = tvb_get_guint8(tvb, offset);
1255     offlg = tvb_get_ntohs(tvb, offset + 2);
1256     frag_off = offlg & IP6F_OFF_MASK; /* offset in bytes */
1257     frag_flg = offlg & IP6F_MORE_FRAG;
1258     frag_ident = tvb_get_ntohl(tvb, offset + 4);
1259     col_add_fstr(pinfo->cinfo, COL_INFO, "IPv6 fragment (off=%u more=%s ident=0x%08x nxt=%u)",
1260                         frag_off, frag_flg ? "y" : "n", frag_ident, nxt);
1261
1262     root_tree = p_ipv6_pinfo_select_root(pinfo, tree);
1263     ipv6_pinfo = p_ipv6_pinfo_add_len(pinfo, IPv6_FRAGMENT_HDR_SIZE);
1264
1265     /* IPv6 Fragmentation Header has fixed length of 8 bytes */
1266     pi = proto_tree_add_item(root_tree, proto_ipv6_fraghdr, tvb, offset, IPv6_FRAGMENT_HDR_SIZE, ENC_NA);
1267     if (ipv6_pinfo != NULL && ipv6_pinfo->jumbo_plen != 0) {
1268         expert_add_info(pinfo, pi, &ei_ipv6_opt_jumbo_fragment);
1269     }
1270
1271     frag_tree = proto_item_add_subtree(pi, ett_ipv6_fraghdr_proto);
1272
1273     proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
1274     offset += 1;
1275
1276     proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_reserved_octet, tvb, offset, 1, ENC_BIG_ENDIAN);
1277     offset += 1;
1278
1279     ti = proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_offset, tvb, offset, 2, ENC_BIG_ENDIAN);
1280     proto_item_append_text(ti, " (%d bytes)", frag_off);
1281
1282     proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_reserved_bits, tvb, offset, 2, ENC_BIG_ENDIAN);
1283
1284     proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_more, tvb, offset, 2, ENC_BIG_ENDIAN);
1285     offset += 2;
1286
1287     proto_tree_add_item(frag_tree, hf_ipv6_fraghdr_ident, tvb, offset, 4, ENC_BIG_ENDIAN);
1288     offset += 4;
1289
1290     if (ipv6_pinfo != NULL && ipv6_pinfo->frag_plen > 0) {
1291         if ((frag_off != 0) || frag_flg) {
1292             reassembled = ipv6_reassemble_do(&tvb, &offset, pinfo, root_tree, ipv6_pinfo->frag_plen,
1293                                              frag_off, frag_flg, frag_ident, &show_data);
1294             if (show_data) {
1295                 next_tvb = tvb_new_subset_remaining(tvb, offset);
1296                 call_data_dissector(next_tvb, pinfo, tree);
1297                 return tvb_captured_length(tvb);
1298             }
1299             if (reassembled) {
1300                 ipv6_pinfo->frag_plen = 0;
1301                 next_tvb = tvb_new_subset_remaining(tvb, offset);
1302                 ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
1303                 return tvb_captured_length(tvb);
1304             }
1305         }
1306     }
1307
1308     p_add_ipv6_nxt(pinfo, nxt);
1309
1310     next_tvb = tvb_new_subset_remaining(tvb, offset);
1311     ipv6_dissect_next(nxt, next_tvb, pinfo, tree, (ws_ip6 *)data);
1312     return tvb_captured_length(tvb);
1313 }
1314
1315 struct opt_proto_item {
1316     proto_item *type, *len;
1317 };
1318
1319 /*
1320  * Jumbo Payload Option
1321  *
1322                                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1323                                    |  Option Type  |  Opt Data Len |
1324    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1325    |                     Jumbo Payload Length                      |
1326    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1327 */
1328 static gint
1329 dissect_opt_jumbo(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1330                     struct opt_proto_item *opt_ti, guint8 opt_len)
1331 {
1332     proto_item *pi = proto_tree_get_parent(opt_tree);
1333     proto_item *ti;
1334     guint32 jumbo_plen = 0;
1335     ipv6_pinfo_t *ipv6_pinfo = p_get_ipv6_pinfo(pinfo);
1336
1337     if (opt_len != 4) {
1338         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1339                 "Jumbo Payload: Invalid length (%u bytes)", opt_len);
1340     }
1341     ti = proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_jumbo, tvb, offset, 4, ENC_BIG_ENDIAN, &jumbo_plen);
1342     offset += 4;
1343
1344     if (ipv6_pinfo != NULL && ipv6_pinfo->ip6_plen != 0) {
1345         expert_add_info(pinfo, pi, &ei_ipv6_opt_jumbo_prohibited);
1346     }
1347     if (jumbo_plen < 65536) {
1348         expert_add_info(pinfo, ti, &ei_ipv6_opt_jumbo_truncated);
1349     }
1350
1351     return offset;
1352 }
1353
1354 /*
1355  * RPL Option
1356  *
1357       0                   1                   2                   3
1358       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1359                                      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1360                                      |  Option Type  |  Opt Data Len |
1361      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1362      |O|R|F|0|0|0|0|0| RPLInstanceID |          SenderRank           |
1363      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1364      |                         (sub-TLVs)                            |
1365      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1366 */
1367 static gint
1368 dissect_opt_rpl(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1369                     struct opt_proto_item *opt_ti, guint8 opt_len)
1370 {
1371     static const int *rpl_flags[] = {
1372         &hf_ipv6_opt_rpl_flag_o,
1373         &hf_ipv6_opt_rpl_flag_r,
1374         &hf_ipv6_opt_rpl_flag_f,
1375         &hf_ipv6_opt_rpl_flag_rsv,
1376         NULL
1377     };
1378
1379     if (opt_len < 4) {
1380         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1381                 "RPL Option: Invalid length (%u bytes)", opt_len);
1382     }
1383     proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_rpl_flag, ett_ipv6_opt_rpl, rpl_flags, ENC_NA);
1384     offset += 1;
1385     proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_instance_id, tvb, offset, 1, ENC_NA);
1386     offset += 1;
1387     proto_tree_add_item(opt_tree, hf_ipv6_opt_rpl_senderrank, tvb, offset, 2, ENC_BIG_ENDIAN);
1388     offset += 2;
1389
1390     /* TODO: Add dissection of sub-TLVs */
1391
1392     return offset;
1393 }
1394
1395 /*
1396  * Tunnel Encapsulation Limit Option
1397  *
1398       Option Type     Opt Data Len   Opt Data Len
1399     0 1 2 3 4 5 6 7
1400    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1401    |0 0 0 0 0 1 0 0|       1       | Tun Encap Lim |
1402    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1403 */
1404 static gint
1405 dissect_opt_tel(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1406                     struct opt_proto_item *opt_ti, guint8 opt_len)
1407 {
1408     if (opt_len != 1) {
1409         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1410                 "Tunnel Encapsulation Limit: Invalid length (%u bytes)", opt_len);
1411     }
1412     proto_tree_add_item(opt_tree, hf_ipv6_opt_tel, tvb, offset, 1, ENC_BIG_ENDIAN);
1413     offset += 1;
1414
1415     return offset;
1416 }
1417
1418 /*
1419  * IPv6 Router Alert Option
1420  *
1421    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1422    |0 0 0|0 0 1 0 1|0 0 0 0 0 0 1 0|        Value (2 octets)       |
1423    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1424                       length = 2
1425 */
1426 static gint
1427 dissect_opt_rtalert(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1428                         struct opt_proto_item *opt_ti, guint8 opt_len)
1429 {
1430     if (opt_len != 2) {
1431         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1432                 "Router alert: Invalid Length (%u bytes)", opt_len);
1433     }
1434     proto_tree_add_item(opt_tree, hf_ipv6_opt_rtalert, tvb, offset, 2, ENC_BIG_ENDIAN);
1435     offset += 2;
1436
1437     return offset;
1438 }
1439
1440 /*
1441  * Quick-Start Option for IPv6
1442  *
1443     0                   1                   2                   3
1444     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1445    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1446    |   Option      |  Length=6     | Func. | Rate  |   Not Used    |
1447    |               |               | 1000  | Report|               |
1448    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1449    |                        QS Nonce                           | R |
1450    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1451 */
1452 static gint
1453 dissect_opt_quickstart(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1454                         struct opt_proto_item *opt_ti, guint8 opt_len, ws_ip6 *iph)
1455 {
1456     proto_item *pi = proto_tree_get_parent(opt_tree);
1457     proto_item *ti;
1458     guint8 command, function, rate;
1459     guint32 qs_ttl = 0;
1460
1461     if (opt_len != 6) {
1462         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1463                 "Quick-Start: Invalid Length (%u bytes)", opt_len);
1464     }
1465
1466     command = tvb_get_guint8(tvb, offset);
1467     function = command >> 4;
1468     rate = command & QS_RATE_MASK;
1469
1470     proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_func, tvb, offset, 1, ENC_BIG_ENDIAN);
1471
1472     switch (function) {
1473     case QS_RATE_REQUEST:
1474         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
1475         offset += 1;
1476         proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_qs_ttl, tvb, offset, 1, ENC_BIG_ENDIAN, &qs_ttl);
1477         proto_item_append_text(pi, ", %s, QS TTL %u",
1478                                val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"),
1479                                qs_ttl);
1480         if (iph != NULL) {
1481             guint8 ttl_diff;
1482
1483             ttl_diff = (iph->ip6_hop - qs_ttl) % 256;
1484             ti = proto_tree_add_uint(opt_tree, hf_ipv6_opt_qs_ttl_diff, tvb, offset, 1, ttl_diff);
1485             PROTO_ITEM_SET_GENERATED(ti);
1486             proto_item_append_text(pi, ", QS TTL diff %u", ttl_diff);
1487         }
1488         offset += 1;
1489         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_BIG_ENDIAN);
1490         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
1491         offset += 4;
1492         break;
1493     case QS_RATE_REPORT:
1494         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_rate, tvb, offset, 1, ENC_BIG_ENDIAN);
1495         proto_item_append_text(pi, ", %s", val_to_str_ext(rate, &qs_rate_vals_ext, "Unknown (%u)"));
1496         offset += 1;
1497         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_unused, tvb, offset, 1, ENC_BIG_ENDIAN);
1498         offset += 1;
1499         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_nonce, tvb, offset, 4, ENC_BIG_ENDIAN);
1500         proto_tree_add_item(opt_tree, hf_ipv6_opt_qs_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
1501         offset += 4;
1502         break;
1503     default:
1504         break;
1505     }
1506
1507     return offset;
1508 }
1509
1510 /*
1511    ------------------------------------------------------------
1512    | Next Header | Hdr Ext Len   | Option Type | Option Length|
1513    +-------------+---------------+-------------+--------------+
1514    |             CALIPSO Domain of Interpretation             |
1515    +-------------+---------------+-------------+--------------+
1516    | Cmpt Length |  Sens Level   |     Checksum (CRC-16)      |
1517    +-------------+---------------+-------------+--------------+
1518    |      Compartment Bitmap (Optional; variable length)      |
1519    +-------------+---------------+-------------+--------------+
1520 */
1521 static gint
1522 dissect_opt_calipso(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1523                     struct opt_proto_item *opt_ti, guint8 opt_len)
1524 {
1525     guint32 cmpt_length = 0;
1526
1527     if (opt_len < 8) {
1528         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1529                 "CALIPSO: Invalid Length (%u bytes)", opt_len);
1530     }
1531
1532     proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_doi, tvb,
1533                         offset, 4, ENC_BIG_ENDIAN);
1534     offset += 4;
1535
1536     proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_calipso_cmpt_length, tvb,
1537                         offset, 1, ENC_BIG_ENDIAN, &cmpt_length);
1538     offset += 1;
1539
1540     proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_sens_level, tvb,
1541                         offset, 1, ENC_BIG_ENDIAN);
1542     offset += 1;
1543
1544     proto_tree_add_checksum(opt_tree, tvb, offset, hf_ipv6_opt_calipso_checksum, -1,
1545                                 NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1546     offset += 2;
1547
1548     proto_tree_add_item(opt_tree, hf_ipv6_opt_calipso_cmpt_bitmap, tvb,
1549                         offset, cmpt_length*4, ENC_NA);
1550     offset += cmpt_length*4;
1551
1552     return offset;
1553 }
1554
1555 /*
1556  * IPv6 SMF_DPD Option Header
1557  *
1558        0                   1                   2                   3
1559        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1560       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1561                      ...              |0|0|0|  01000  | Opt. Data Len |
1562       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1563       |0|TidTy| TidLen|             TaggerId (optional) ...           |
1564       +-+-+-+-+-+-+-+-+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1565       |                               |            Identifier  ...
1566       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1567
1568            Figure 3: IPv6 SMF_DPD Option Header in I-DPD mode
1569
1570        0                   1                   2                   3
1571        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1572       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1573                      ...              |0|0|0| OptType | Opt. Data Len |
1574       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1575       |1|    Hash Assist Value (HAV) ...
1576       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1577
1578            Figure 4: IPv6 SMF_DPD Option Header in H-DPD Mode
1579 */
1580 static gint
1581 dissect_opt_smf_dpd(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
1582                     struct opt_proto_item *opt_ti _U_, guint8 opt_len)
1583 {
1584     guint8 hash_tid;
1585     guint8 tid_len;
1586     gint ident_len;
1587
1588     proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_hash_bit, tvb, offset, 1, ENC_BIG_ENDIAN);
1589     hash_tid = tvb_get_guint8(tvb, offset);
1590
1591     if (hash_tid & 0x80) {
1592         /* H-DPD Mode */
1593         proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_hav, tvb, offset, opt_len, ENC_NA);
1594         return offset + opt_len;
1595     }
1596
1597     /* I-DPD Mode */
1598     proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tid_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1599     proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tid_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1600     offset += 1;
1601     ident_len = opt_len - 1;
1602     if (hash_tid & 0x70) {
1603         tid_len = (hash_tid & 0x0f) + 1;
1604         proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_tagger_id, tvb, offset, tid_len, ENC_NA);
1605         offset += tid_len;
1606         ident_len -= tid_len;
1607     }
1608     if (ident_len > 0) {
1609         proto_tree_add_item(opt_tree, hf_ipv6_opt_smf_dpd_ident, tvb, offset, ident_len, ENC_NA);
1610         offset += ident_len;
1611     }
1612
1613     return offset;
1614 }
1615
1616 /*
1617  * Performance and Diagnostic Metrics Destination Option (ietf-ippm-6man-pdm-option-13)
1618  *
1619       0                   1                   2                   3
1620       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1621       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1622       |  Option Type  | Option Length |    ScaleDTLR  |     ScaleDTLS |
1623       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1624       |   PSN This Packet             |  PSN Last Received            |
1625       |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1626       |   Delta Time Last Received    |  Delta Time Last Sent         |
1627       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1628 */
1629 static gint
1630 dissect_opt_pdm(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
1631                     struct opt_proto_item *opt_ti _U_, guint8 opt_len)
1632 {
1633     if (opt_len != 10) {
1634         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1635                 "PDM: Invalid length (%u bytes)", opt_len);
1636     }
1637     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_scale_dtlr, tvb, offset, 1, ENC_BIG_ENDIAN);
1638     offset += 1;
1639     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_scale_dtls, tvb, offset, 1, ENC_BIG_ENDIAN);
1640     offset += 1;
1641     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_psn_this_pkt, tvb, offset, 2, ENC_BIG_ENDIAN);
1642     offset += 2;
1643     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_psn_last_recv, tvb, offset, 2, ENC_BIG_ENDIAN);
1644     offset += 2;
1645     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_delta_last_recv, tvb, offset, 2, ENC_BIG_ENDIAN);
1646     offset += 2;
1647     proto_tree_add_item(opt_tree, hf_ipv6_opt_pdm_delta_last_sent, tvb, offset, 2, ENC_BIG_ENDIAN);
1648     offset += 2;
1649
1650     return offset;
1651 }
1652
1653 /*
1654  * Home Address Option
1655  *
1656        0                   1                   2                   3
1657        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1658                                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1659                                       |  Option Type  | Option Length |
1660       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1661       |                                                               |
1662       +                                                               +
1663       |                                                               |
1664       +                          Home Address                         +
1665       |                                                               |
1666       +                                                               +
1667       |                                                               |
1668       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1669 */
1670 static gint
1671 dissect_opt_home_address(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1672                             struct opt_proto_item *opt_ti, guint8 opt_len)
1673 {
1674     if (opt_len != 16) {
1675         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1676                 "Home Address: Invalid length (%u bytes)", opt_len);
1677     }
1678     proto_tree_add_item(opt_tree, hf_ipv6_opt_mipv6_home_address, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
1679     alloc_address_tvb_ipv6(pinfo->pool, &pinfo->src, tvb, offset);
1680     offset += IPv6_ADDR_SIZE;
1681
1682     return offset;
1683 }
1684
1685 /*
1686  * ILNP Nonce Option
1687  *
1688
1689      0                   1                   2                   3
1690      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1691     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1692     | Next Header   | Hdr Ext Len   |  Option Type  | Option Length |
1693     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1694     /                         Nonce Value                           /
1695     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1696 */
1697 static gint
1698 dissect_opt_ilnp_nonce(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
1699                             struct opt_proto_item *opt_ti _U_, guint8 opt_len)
1700 {
1701     proto_tree_add_item(opt_tree, hf_ipv6_opt_ilnp_nonce, tvb, offset, opt_len, ENC_NA);
1702     offset += opt_len;
1703
1704     return offset;
1705 }
1706
1707 /*
1708  * Line-Identification Option
1709  *
1710     0                   1                   2                   3
1711     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1712                                    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1713                                    |  Option Type  | Option Length |
1714    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1715    | LineIDLen     |     Line ID...
1716    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1717 */
1718 static gint
1719 dissect_opt_lio(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
1720                             struct opt_proto_item *opt_ti _U_, guint8 opt_len)
1721 {
1722     guint32 lid_len = 0;
1723
1724     proto_tree_add_item_ret_uint(opt_tree, hf_ipv6_opt_lio_len, tvb, offset, 1, ENC_BIG_ENDIAN, &lid_len);
1725     offset += 1;
1726
1727     if (lid_len + 1 > opt_len) {
1728         /* XXX Add expert info */
1729         lid_len = opt_len - 1;
1730     }
1731     proto_tree_add_item(opt_tree, hf_ipv6_opt_lio_id, tvb, offset, lid_len, ENC_BIG_ENDIAN|ENC_ASCII);
1732     offset += lid_len;
1733
1734     return offset;
1735 }
1736
1737 /*
1738  * MPL Option
1739  *
1740       0                   1                   2                   3
1741       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1742                                      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1743                                      |  Option Type  |  Opt Data Len |
1744      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1745      | S |M|V|  rsv  |   sequence    |      seed-id (optional)       |
1746      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1747 */
1748 static gint
1749 dissect_opt_mpl(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *opt_tree,
1750                     struct opt_proto_item *opt_ti _U_, guint8 opt_len _U_)
1751 {
1752     static const int *mpl_flags[] = {
1753         &hf_ipv6_opt_mpl_flag_s,
1754         &hf_ipv6_opt_mpl_flag_m,
1755         &hf_ipv6_opt_mpl_flag_v,
1756         &hf_ipv6_opt_mpl_flag_rsv,
1757         NULL
1758     };
1759     static const guint8 seed_id_len_arr[4] = {0, 2, 8, 16};
1760     guint8 seed_id_len;
1761
1762     proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_mpl_flag, ett_ipv6_opt_mpl, mpl_flags, ENC_NA);
1763     seed_id_len = seed_id_len_arr[tvb_get_guint8(tvb, offset) >> 6];
1764     offset +=1;
1765
1766     proto_tree_add_item(opt_tree, hf_ipv6_opt_mpl_sequence, tvb, offset, 1, ENC_NA);
1767     offset +=1;
1768     if (seed_id_len > 0) {
1769         proto_tree_add_item(opt_tree, hf_ipv6_opt_mpl_seed_id, tvb, offset, seed_id_len, ENC_NA);
1770         offset += seed_id_len;
1771     }
1772
1773     return offset;
1774 }
1775
1776 /*
1777  * IPv6 DFF Header
1778  *
1779                           1                   2                   3
1780       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1781      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1782      |  Next Header  |  Hdr Ext Len  |  OptTypeDFF   | OptDataLenDFF |
1783      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1784      |VER|D|R|0|0|0|0|        Sequence Number        |      Pad1     |
1785      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1786 */
1787 static gint
1788 dissect_opt_dff(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1789                             struct opt_proto_item *opt_ti, guint8 opt_len)
1790 {
1791     static const int *dff_flags[] = {
1792         &hf_ipv6_opt_dff_flag_ver,
1793         &hf_ipv6_opt_dff_flag_dup,
1794         &hf_ipv6_opt_dff_flag_ret,
1795         &hf_ipv6_opt_dff_flag_rsv,
1796         NULL
1797     };
1798
1799     /* Option length is 3 octets */
1800     /* http://www.rfc-editor.org/errata_search.php?eid=3937 */
1801     if (opt_len != 3) {
1802         expert_add_info_format(pinfo, opt_ti->len, &ei_ipv6_opt_invalid_len,
1803                 "IPv6 DFF: Invalid length (%u bytes)", opt_len);
1804     }
1805     proto_tree_add_bitmask(opt_tree, tvb, offset, hf_ipv6_opt_dff_flags,
1806                             ett_ipv6_opt_dff_flags, dff_flags, ENC_NA);
1807     offset += 1;
1808     proto_tree_add_item(opt_tree, hf_ipv6_opt_dff_seqnum, tvb, offset, 2, ENC_BIG_ENDIAN);
1809     offset += 2;
1810
1811     return offset;
1812 }
1813
1814 static gint
1815 dissect_opt_unknown(tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *opt_tree,
1816                             struct opt_proto_item *opt_ti _U_, guint8 opt_len)
1817 {
1818     proto_item *ti;
1819
1820     ti = proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown, tvb,
1821                         offset, opt_len, ENC_NA);
1822     expert_add_info(pinfo, ti, &ei_ipv6_opt_unknown_data);
1823
1824     return offset + opt_len;
1825 }
1826
1827 static int
1828 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, packet_info *pinfo, ws_ip6 *iph, const int exthdr_proto)
1829 {
1830     gint            len, offset_end;
1831     guint8          nxt;
1832     proto_tree     *exthdr_tree, *opt_tree, *opt_type_tree, *root_tree;
1833     proto_item     *pi, *ti, *ti_len;
1834     int             hf_exthdr_item_nxt, hf_exthdr_item_len, hf_exthdr_item_len_oct;
1835     int             ett_exthdr_proto;
1836     guint8          opt_type, opt_len, opt_start;
1837     gint            opt_hdr_type;
1838     const gchar    *opt_name;
1839     gboolean        hopopts;
1840     struct opt_proto_item opt_ti;
1841     tvbuff_t       *next_tvb;
1842
1843     hopopts = (exthdr_proto == proto_ipv6_hopopts);
1844
1845     nxt = tvb_get_guint8(tvb, offset);
1846     len = (tvb_get_guint8(tvb, offset + 1) + 1) << 3;
1847     offset_end = offset + len;
1848
1849     root_tree = p_ipv6_pinfo_select_root(pinfo, tree);
1850     p_ipv6_pinfo_add_len(pinfo, len);
1851
1852     /* !!! specify length */
1853     ti = proto_tree_add_item(root_tree, exthdr_proto, tvb, offset, len, ENC_NA);
1854
1855     if (hopopts && ipv6_previous_layer_id(pinfo) != proto_ipv6) {
1856         /* IPv6 Hop-by-Hop must appear immediately after IPv6 header (RFC 2460) */
1857         expert_add_info(pinfo, ti, &ei_ipv6_hopopts_not_first);
1858     }
1859
1860     if (exthdr_proto == proto_ipv6_hopopts) {
1861         hf_exthdr_item_nxt = hf_ipv6_hopopts_nxt;
1862         hf_exthdr_item_len = hf_ipv6_hopopts_len;
1863         hf_exthdr_item_len_oct = hf_ipv6_hopopts_len_oct;
1864         ett_exthdr_proto = ett_ipv6_hopopts_proto;
1865     } else if (exthdr_proto == proto_ipv6_dstopts) {
1866         hf_exthdr_item_nxt = hf_ipv6_dstopts_nxt;
1867         hf_exthdr_item_len = hf_ipv6_dstopts_len;
1868         hf_exthdr_item_len_oct = hf_ipv6_dstopts_len_oct;
1869         ett_exthdr_proto = ett_ipv6_dstopts_proto;
1870     } else {
1871         DISSECTOR_ASSERT_NOT_REACHED();
1872     }
1873
1874     exthdr_tree = proto_item_add_subtree(ti, ett_exthdr_proto);
1875
1876     proto_tree_add_item(exthdr_tree, hf_exthdr_item_nxt, tvb, offset, 1, ENC_BIG_ENDIAN);
1877     offset += 1;
1878
1879     ti_len = proto_tree_add_item(exthdr_tree, hf_exthdr_item_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1880     ti = proto_tree_add_uint(exthdr_tree, hf_exthdr_item_len_oct, tvb, offset, 1, len);
1881     PROTO_ITEM_SET_GENERATED(ti);
1882     if (ipv6_exthdr_hide_len_oct_field) {
1883         PROTO_ITEM_SET_HIDDEN(ti);
1884         proto_item_append_text(ti_len, " (%d bytes)", len);
1885     }
1886     offset += 1;
1887
1888     while (offset < offset_end) {
1889         /* there are more options */
1890
1891         opt_type = tvb_get_guint8(tvb, offset);
1892         opt_len = tvb_get_guint8(tvb, offset + 1);
1893         opt_name = val_to_str_ext(opt_type, &ipv6_opt_type_vals_ext, "Unknown IPv6 Option (%u)");
1894
1895         pi = proto_tree_add_none_format(exthdr_tree, hf_ipv6_opt, tvb, offset, 2 + opt_len,
1896                     "%s", opt_name);
1897         opt_tree = proto_item_add_subtree(pi, ett_ipv6_opt);
1898
1899         opt_ti.type = proto_tree_add_item(opt_tree, hf_ipv6_opt_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1900
1901         if (opt_type == IP6OPT_PAD1) {
1902             /* The Pad1 option is a special case, and contains no data. */
1903             proto_tree_add_item(opt_tree, hf_ipv6_opt_pad1, tvb, offset, 1, ENC_NA);
1904             offset += 1;
1905             continue;
1906         }
1907
1908         if ((opt_hdr_type = ipv6_opt_type_hdr(opt_type)) != IPv6_OPT_HDR_ANY) {
1909             if (hopopts && (opt_hdr_type == IPv6_OPT_HDR_DST)) {
1910                 expert_add_info_format(pinfo, opt_ti.type, &ei_ipv6_opt_header_mismatch,
1911                         "%s must use a destination options header", opt_name);
1912             }
1913             else if (!hopopts && (opt_hdr_type == IPv6_OPT_HDR_HBH)) {
1914                 expert_add_info_format(pinfo, opt_ti.type, &ei_ipv6_opt_header_mismatch,
1915                         "%s must use a hop-by-hop options header", opt_name);
1916             }
1917         }
1918
1919         opt_type_tree = proto_item_add_subtree(opt_ti.type, ett_ipv6_opt_type);
1920         proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_action, tvb, offset, 1, ENC_BIG_ENDIAN);
1921         proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_change, tvb, offset, 1, ENC_BIG_ENDIAN);
1922         proto_tree_add_item(opt_type_tree, hf_ipv6_opt_type_rest,   tvb, offset, 1, ENC_BIG_ENDIAN);
1923         offset += 1;
1924
1925         opt_ti.len = proto_tree_add_item(opt_tree, hf_ipv6_opt_length, tvb, offset, 1, ENC_BIG_ENDIAN);
1926         offset += 1;
1927
1928         if (opt_type == IP6OPT_PADN) {
1929             /* RFC 2460 states :
1930              * "The PadN option is used to insert two or more octets of
1931              * padding into the Options area of a header.  For N octets of
1932              * padding, the Opt Data Len field contains the value N-2, and
1933              * the Option Data consists of N-2 zero-valued octets."
1934              */
1935             proto_tree_add_item(opt_tree, hf_ipv6_opt_padn, tvb, offset, opt_len, ENC_NA);
1936             offset += opt_len;
1937             continue;
1938         }
1939
1940         opt_start = offset;
1941         switch (opt_type) {
1942         case IP6OPT_JUMBO:
1943             offset = dissect_opt_jumbo(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1944             break;
1945         case IP6OPT_RPL:
1946             offset = dissect_opt_rpl(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1947             break;
1948         case IP6OPT_TEL:
1949             offset = dissect_opt_tel(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1950             break;
1951         case IP6OPT_RTALERT:
1952             offset = dissect_opt_rtalert(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1953             break;
1954         case IP6OPT_QUICKSTART:
1955             offset = dissect_opt_quickstart(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len, iph);
1956             break;
1957         case IP6OPT_CALIPSO:
1958             offset = dissect_opt_calipso(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1959             break;
1960         case IP6OPT_SMF_DPD:
1961             offset = dissect_opt_smf_dpd(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1962             break;
1963         case IP6OPT_PDM:
1964             offset = dissect_opt_pdm(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1965             break;
1966         case IP6OPT_HOME_ADDRESS:
1967             offset = dissect_opt_home_address(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1968             break;
1969         case IP6OPT_ILNP_NONCE:
1970             offset = dissect_opt_ilnp_nonce(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1971             break;
1972         case IP6OPT_LIO:
1973             offset = dissect_opt_lio(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1974             break;
1975         case IP6OPT_MPL:
1976             offset = dissect_opt_mpl(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1977             break;
1978         case IP6OPT_IP_DFF:
1979             offset = dissect_opt_dff(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1980             break;
1981         case IP6OPT_ENDI:
1982             offset = dissect_opt_unknown(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1983             expert_add_info(pinfo, opt_ti.type, &ei_ipv6_opt_deprecated);
1984             break;
1985         case IP6OPT_EXP_1E:
1986         case IP6OPT_EXP_3E:
1987         case IP6OPT_EXP_5E:
1988         case IP6OPT_EXP_7E:
1989         case IP6OPT_EXP_9E:
1990         case IP6OPT_EXP_BE:
1991         case IP6OPT_EXP_DE:
1992         case IP6OPT_EXP_FE:
1993             proto_tree_add_item(opt_tree, hf_ipv6_opt_experimental, tvb,
1994                                 offset, opt_len, ENC_NA);
1995             offset += opt_len;
1996             break;
1997         default:
1998             offset = dissect_opt_unknown(tvb, offset, pinfo, opt_tree, &opt_ti, opt_len);
1999             break;
2000         }
2001         if (offset < opt_start + opt_len) {
2002             ti = proto_tree_add_item(opt_tree, hf_ipv6_opt_unknown_data, tvb,
2003                                 offset, opt_start + opt_len - offset, ENC_NA);
2004             expert_add_info(pinfo, ti, &ei_ipv6_opt_unknown_data);
2005             offset = opt_start + opt_len;
2006         }
2007     }
2008
2009     p_add_ipv6_nxt(pinfo, nxt);
2010
2011     next_tvb = tvb_new_subset_remaining(tvb, len);
2012     ipv6_dissect_next(nxt, next_tvb, pinfo, tree, iph);
2013     return tvb_captured_length(tvb);
2014 }
2015
2016 static int
2017 dissect_hopopts(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2018 {
2019     col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 hop-by-hop options");
2020
2021     return dissect_opts(tvb, 0, tree, pinfo, (ws_ip6 *)data, proto_ipv6_hopopts);
2022 }
2023
2024 static int
2025 dissect_dstopts(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2026 {
2027     col_append_sep_str(pinfo->cinfo, COL_INFO, " , ", "IPv6 destination options");
2028
2029     return dissect_opts(tvb, 0, tree, pinfo, (ws_ip6 *)data, proto_ipv6_dstopts);
2030 }
2031
2032 /* return value is > G_MAXUINT16, else zero */
2033 /* tvb + offset contains the Hbh header */
2034 static guint32
2035 ipv6_get_jumbo_plen(tvbuff_t *tvb, gint offset)
2036 {
2037     gint         offset_end, hdr_len;
2038     gint         opt_type, opt_len;
2039     guint32      jumbo_plen;
2040
2041     if (!tvb_bytes_exist(tvb, offset, 2)) {
2042         return 0;
2043     }
2044     hdr_len = (tvb_get_guint8(tvb, offset + 1) + 1) * 8;
2045     offset_end = offset + hdr_len;
2046     offset +=2;
2047
2048     while (offset < offset_end && tvb_bytes_exist(tvb, offset, 6)) {
2049         opt_type = tvb_get_guint8(tvb, offset);
2050         offset += 1;
2051         if (opt_type == IP6OPT_PAD1) {
2052             continue;
2053         }
2054         opt_len = tvb_get_guint8(tvb, offset);
2055         offset += 1;
2056         if (opt_type == IP6OPT_JUMBO && opt_len == 4) {
2057             jumbo_plen = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN);
2058             if (jumbo_plen > G_MAXUINT16) {
2059                 return jumbo_plen;
2060             }
2061             return 0;
2062         }
2063         offset += opt_len;
2064     }
2065     return 0;
2066 }
2067
2068 static void
2069 add_ipv6_address(proto_tree *tree, tvbuff_t *tvb, int offset,
2070                         gint hf_addr, gint hf_host)
2071 {
2072     address addr;
2073     const char *name;
2074     proto_item *ti;
2075
2076     proto_tree_add_item(tree, hf_addr, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
2077     ti = proto_tree_add_item(tree, hf_ipv6_addr, tvb, offset, IPv6_ADDR_SIZE, ENC_NA);
2078     PROTO_ITEM_SET_HIDDEN(ti);
2079
2080     set_address_ipv6_tvb(&addr, tvb, offset);
2081     name = address_to_display(wmem_packet_scope(), &addr);
2082
2083     ti = proto_tree_add_string(tree, hf_host, tvb, offset, IPv6_ADDR_SIZE, name);
2084     PROTO_ITEM_SET_GENERATED(ti);
2085     PROTO_ITEM_SET_HIDDEN(ti);
2086     ti = proto_tree_add_string(tree, hf_ipv6_host, tvb, offset, IPv6_ADDR_SIZE, name);
2087     PROTO_ITEM_SET_GENERATED(ti);
2088     PROTO_ITEM_SET_HIDDEN(ti);
2089 }
2090
2091 #define ADDRESS_SET_GENERATED_HIDDEN(ti) \
2092     G_STMT_START {                              \
2093         PROTO_ITEM_SET_GENERATED(ti);           \
2094         if (i > 0) PROTO_ITEM_SET_HIDDEN(ti);   \
2095     } G_STMT_END
2096
2097 /* RFC 3056 section 2 */
2098 static void
2099 add_ipv6_address_6to4(proto_tree *tree, tvbuff_t *tvb, int offset,
2100                         gint hf_gateway, gint hf_sla_id)
2101 {
2102     if (tvb_get_ntohs(tvb, offset) != 0x2002)
2103         return;
2104
2105     struct { gint gateway, sla_id; } hf[2] = {
2106         { hf_gateway, hf_sla_id},
2107         { hf_ipv6_6to4_gateway_ipv4, hf_ipv6_6to4_sla_id}
2108     };
2109     proto_item *ti;
2110     for (int i = 0; i < 2; i++) {
2111         ti = proto_tree_add_item(tree, hf[i].gateway, tvb, offset + 2, 4, ENC_BIG_ENDIAN);
2112         ADDRESS_SET_GENERATED_HIDDEN(ti);
2113         ti = proto_tree_add_item(tree, hf[i].sla_id, tvb, offset + 6, 2, ENC_BIG_ENDIAN);
2114         ADDRESS_SET_GENERATED_HIDDEN(ti);
2115     }
2116 }
2117
2118 /* RFC 4380 section 4 */
2119 static void
2120 add_ipv6_address_teredo(proto_tree *tree, tvbuff_t *tvb, int offset,
2121                         gint hf_server, gint hf_port, gint hf_client)
2122 {
2123     if (tvb_get_ntohl(tvb, offset) != 0x20010000)
2124         return;
2125
2126     guint16 mapped_port = tvb_get_ntohs(tvb, offset + 10) ^ 0xffff;
2127     guint32 client_v4 = tvb_get_ipv4(tvb, offset + 12) ^ 0xffffffff;
2128
2129     struct { gint server, port, client; } hf[2] = {
2130         { hf_server, hf_port, hf_client },
2131         { hf_ipv6_teredo_server_ipv4, hf_ipv6_teredo_port, hf_ipv6_teredo_client_ipv4 }
2132     };
2133     proto_item *ti;
2134     for (int i = 0; i < 2; i++) {
2135         ti = proto_tree_add_item(tree, hf[i].server, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
2136         ADDRESS_SET_GENERATED_HIDDEN(ti);
2137         ti = proto_tree_add_uint(tree, hf[i].port, tvb, offset + 10, 2, mapped_port);
2138         ADDRESS_SET_GENERATED_HIDDEN(ti);
2139         ti = proto_tree_add_ipv4(tree, hf[i].client, tvb, offset + 12, 4, client_v4);
2140         ADDRESS_SET_GENERATED_HIDDEN(ti);
2141     }
2142 }
2143
2144 /* RFC 4291 appendix A */
2145 static void
2146 add_ipv6_address_slaac(proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_slaac)
2147 {
2148     if (!(tvb_get_guint8(tvb, offset + 8) & 0x02) ||
2149                             !(tvb_get_ntohs(tvb, offset + 11) == 0xfffe)) {
2150         return;
2151     }
2152
2153     guint8 *mac_addr = (guint8 *)wmem_alloc(wmem_packet_scope(), 6);
2154     tvb_memcpy(tvb, mac_addr, offset + 8, 3);
2155     tvb_memcpy(tvb, mac_addr+3, offset + 13, 3);
2156     mac_addr[0] &= ~0x02;
2157
2158     struct { gint mac; } hf[2] = {
2159         { hf_slaac },
2160         { hf_ipv6_sa_mac }
2161     };
2162     proto_item *ti;
2163     for (int i = 0; i < 2; i++) {
2164         ti = proto_tree_add_ether(tree, hf[i].mac, tvb, offset + 8, 8, mac_addr);
2165         ADDRESS_SET_GENERATED_HIDDEN(ti);
2166     }
2167 }
2168
2169 /* RFC 5214 section 6.1 */
2170 static void
2171 add_ipv6_address_isatap(proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_isatap)
2172 {
2173     if ((tvb_get_ntohl(tvb, offset + 8) & 0xfcffffff) != 0x00005efe)
2174         return;
2175
2176     struct { gint ipv4; } hf[2] = {
2177         { hf_isatap },
2178         { hf_ipv6_isatap_ipv4 }
2179     };
2180     proto_item *ti;
2181     for (int i = 0; i < 2; i++) {
2182         ti = proto_tree_add_item(tree, hf[i].ipv4, tvb, offset + 12, 4, ENC_BIG_ENDIAN);
2183         ADDRESS_SET_GENERATED_HIDDEN(ti);
2184     }
2185 }
2186
2187 /* RFC 6052 */
2188 static void
2189 add_ipv6_address_embed_ipv4(proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_embed)
2190 {
2191     /* Well-Known Prefix for IPv4-Embedded IPv6 Address: 64:FF9B::/96 */
2192     static const guint8 ipv6_embedded_ipv4_well_known_prefix[] = {
2193         0x00, 0x64, 0xFF, 0x9B,
2194         0x00, 0x00, 0x00, 0x00,
2195         0x00, 0x00, 0x00, 0x00
2196     };
2197     /* Check for well-known prefix */
2198     if (tvb_memeql(tvb, offset, ipv6_embedded_ipv4_well_known_prefix, 12) != 0)
2199         return;
2200
2201     struct { gint embed; } hf[2] = {
2202         { hf_embed },
2203         { hf_ipv6_embed_ipv4 }
2204     };
2205     proto_item *ti;
2206     for (int i = 0; i < 2; i++) {
2207         ti = proto_tree_add_item(tree, hf[i].embed, tvb, offset + 12, 4, ENC_NA);
2208         ADDRESS_SET_GENERATED_HIDDEN(ti);
2209     }
2210 }
2211
2212 static int
2213 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
2214 {
2215     proto_tree    *ipv6_tree, *pt;
2216     proto_item    *ipv6_item, *ti, *pi;
2217     proto_item    *ti_ipv6_plen = NULL, *ti_ipv6_version;
2218     guint8         ip6_tcls, ip6_nxt, ip6_hlim;
2219     guint32        ip6_flow;
2220     const ws_in6_addr *ip6_src, *ip6_dst;
2221     guint32        ip6_plen = 0, jumbo_plen = 0;
2222     guint32        plen;
2223     int            offset;
2224     guint          reported_plen;
2225     tvbuff_t      *next_tvb;
2226     gboolean       save_fragmented;
2227     int            version;
2228     ws_ip6        *iph;
2229
2230     offset = 0;
2231
2232     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPv6");
2233     col_clear(pinfo->cinfo, COL_INFO);
2234
2235     ipv6_item = proto_tree_add_item(tree, proto_ipv6, tvb, offset, IPv6_HDR_SIZE, ENC_NA);
2236     ipv6_tree = proto_item_add_subtree(ipv6_item, ett_ipv6_proto);
2237
2238     /* Validate IP version (6) */
2239     version = tvb_get_bits8(tvb, (offset + IP6H_CTL_VFC) * 8, 4);
2240     ti_ipv6_version = proto_tree_add_item(ipv6_tree, hf_ipv6_version, tvb,
2241                                  offset + IP6H_CTL_VFC, 1, ENC_BIG_ENDIAN);
2242     pi = proto_tree_add_item(ipv6_tree, hf_ip_version, tvb,
2243                                  offset + IP6H_CTL_VFC, 1, ENC_BIG_ENDIAN);
2244     proto_item_append_text(pi, " [This field makes the filter match on \"ip.version == 6\" possible]");
2245     PROTO_ITEM_SET_HIDDEN(pi);
2246     if (version != 6) {
2247         col_add_fstr(pinfo->cinfo, COL_INFO,
2248                  "Bogus IPv6 version (%u, must be 6)", version);
2249         expert_add_info_format(pinfo, ti_ipv6_version, &ei_ipv6_bogus_ipv6_version, "Bogus IPv6 version");
2250         return offset + IP6H_CTL_VFC;
2251     }
2252
2253     /* Validate header size (40 bytes) */
2254     if (tvb_reported_length(tvb) < IPv6_HDR_SIZE) {
2255         col_add_fstr(pinfo->cinfo, COL_INFO,
2256                         "Invalid IPv6 header (%u bytes, need exactly 40)",
2257                         tvb_reported_length(tvb));
2258         expert_add_info_format(pinfo, ipv6_item, &ei_ipv6_invalid_header,
2259                         "IPv6 header must be exactly 40 bytes");
2260     }
2261
2262     /* !!! warning: (4-bit) version, (6-bit) DSCP, (2-bit) ECN and (20-bit) Flow */
2263     ti = proto_tree_add_item(ipv6_tree, hf_ipv6_tclass, tvb,
2264                         offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);
2265     ip6_tcls = tvb_get_bits8(tvb, (offset + IP6H_CTL_VFC) * 8 + 4, 8);
2266     proto_item_append_text(ti, " (DSCP: %s, ECN: %s)",
2267                         val_to_str_ext_const(IPDSFIELD_DSCP(ip6_tcls), &dscp_short_vals_ext, "Unknown"),
2268                         val_to_str_ext_const(IPDSFIELD_ECN(ip6_tcls), &ecn_short_vals_ext, "Unknown"));
2269
2270     pt = proto_item_add_subtree(ti, ett_ipv6_traffic_class);
2271     proto_tree_add_item(pt, hf_ipv6_tclass_dscp, tvb,
2272                         offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);
2273     proto_tree_add_item(pt, hf_ipv6_tclass_ecn, tvb,
2274                         offset + IP6H_CTL_VFC, 4, ENC_BIG_ENDIAN);
2275
2276     /* Set DSCP column */
2277     col_add_str(pinfo->cinfo, COL_DSCP_VALUE,
2278                 val_to_str_ext(IPDSFIELD_DSCP(ip6_tcls), &dscp_short_vals_ext, "%u"));
2279
2280     proto_tree_add_item_ret_uint(ipv6_tree, hf_ipv6_flow, tvb,
2281                         offset + IP6H_CTL_FLOW, 4, ENC_BIG_ENDIAN, &ip6_flow);
2282
2283     ip6_plen = tvb_get_guint16(tvb, offset + IP6H_CTL_PLEN, ENC_BIG_ENDIAN);
2284
2285     ip6_nxt = tvb_get_guint8(tvb, offset + IP6H_CTL_NXT);
2286
2287     if (ipv6_tso_supported && ip6_plen == 0 &&
2288                     ip6_nxt != IP_PROTO_HOPOPTS && ip6_nxt != IP_PROTO_NONE) {
2289         ip6_plen = tvb_reported_length(tvb) - IPv6_HDR_SIZE;
2290         pi = proto_tree_add_uint_format_value(ipv6_tree, hf_ipv6_plen, tvb,
2291                                 offset + IP6H_CTL_PLEN, 2, ip6_plen,
2292                                 "%u bytes (reported as 0, presumed to be because "
2293                                 "of \"TCP segmentation offload\" (TSO))",
2294                                 ip6_plen);
2295         PROTO_ITEM_SET_GENERATED(pi);
2296     } else {
2297         ti_ipv6_plen = proto_tree_add_item(ipv6_tree, hf_ipv6_plen, tvb,
2298                                 offset + IP6H_CTL_PLEN, 2, ENC_BIG_ENDIAN);
2299         if (ip6_plen == 0 && ip6_nxt != IP_PROTO_HOPOPTS && ip6_nxt != IP_PROTO_NONE) {
2300             expert_add_info(pinfo, ti_ipv6_plen, &ei_ipv6_plen_zero);
2301         }
2302     }
2303
2304     proto_tree_add_item(ipv6_tree, hf_ipv6_nxt, tvb, offset + IP6H_CTL_NXT, 1, ENC_NA);
2305
2306     proto_tree_add_item(ipv6_tree, hf_ipv6_hlim, tvb,
2307                         offset + IP6H_CTL_HLIM, 1, ENC_BIG_ENDIAN);
2308     ip6_hlim = tvb_get_guint8(tvb, offset + IP6H_CTL_HLIM);
2309
2310     /* Source address */
2311     add_ipv6_address(ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src, hf_ipv6_src_host);
2312     ip6_src = tvb_get_ptr_ipv6(tvb, offset + IP6H_SRC);
2313     alloc_address_wmem_ipv6(pinfo->pool, &pinfo->net_src, ip6_src);
2314     copy_address_shallow(&pinfo->src, &pinfo->net_src);
2315
2316     /* Destination address */
2317     add_ipv6_address(ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst, hf_ipv6_dst_host);
2318     ip6_dst = tvb_get_ptr_ipv6(tvb, offset + IP6H_DST);
2319     alloc_address_wmem_ipv6(pinfo->pool, &pinfo->net_dst, ip6_dst);
2320     copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
2321
2322     if (tree) {
2323         if (ipv6_summary_in_tree) {
2324             proto_item_append_text(ipv6_item, ", Src: %s, Dst: %s",
2325                     address_with_resolution_to_str(wmem_packet_scope(), &pinfo->src),
2326                     address_with_resolution_to_str(wmem_packet_scope(), &pinfo->dst));
2327         }
2328
2329         /* Add the different items for the address */
2330         add_ipv6_address_6to4(ipv6_tree, tvb, offset + IP6H_SRC,
2331                 hf_ipv6_src_6to4_gateway_ipv4, hf_ipv6_src_6to4_sla_id);
2332         add_ipv6_address_6to4(ipv6_tree, tvb, offset + IP6H_DST,
2333                 hf_ipv6_dst_6to4_gateway_ipv4, hf_ipv6_dst_6to4_sla_id);
2334
2335         add_ipv6_address_teredo(ipv6_tree, tvb, offset + IP6H_SRC,
2336                 hf_ipv6_src_teredo_server_ipv4, hf_ipv6_src_teredo_port, hf_ipv6_src_teredo_client_ipv4);
2337         add_ipv6_address_teredo(ipv6_tree, tvb, offset + IP6H_DST,
2338                 hf_ipv6_dst_teredo_server_ipv4, hf_ipv6_dst_teredo_port, hf_ipv6_dst_teredo_client_ipv4);
2339
2340         add_ipv6_address_slaac(ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_sa_mac);
2341         add_ipv6_address_slaac(ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_sa_mac);
2342
2343         add_ipv6_address_isatap(ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_isatap_ipv4);
2344         add_ipv6_address_isatap(ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_isatap_ipv4);
2345
2346         add_ipv6_address_embed_ipv4(ipv6_tree, tvb, offset + IP6H_SRC, hf_ipv6_src_embed_ipv4);
2347         add_ipv6_address_embed_ipv4(ipv6_tree, tvb, offset + IP6H_DST, hf_ipv6_dst_embed_ipv4);
2348
2349         if (ipv6_use_geoip) {
2350             add_geoip_info(ipv6_tree, tvb, offset, ip6_src, ip6_dst);
2351         }
2352     }
2353
2354     /* Increment offset to point to next header (may be an extension header) */
2355     offset += IPv6_HDR_SIZE;
2356
2357     /* Check for Jumbo option */
2358     plen = ip6_plen;
2359     if (plen == 0 && ip6_nxt == IP_PROTO_HOPOPTS) {
2360         jumbo_plen = ipv6_get_jumbo_plen(tvb, offset);
2361         if (jumbo_plen != 0) {
2362             proto_item_append_text(ti_ipv6_plen, " (Jumbogram)");
2363             plen = jumbo_plen;
2364         } else {
2365             /* IPv6 length zero is invalid if there is a hop-by-hop header without jumbo option */
2366             col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid IPv6 payload length");
2367             expert_add_info(pinfo, ti_ipv6_plen, &ei_ipv6_opt_jumbo_missing);
2368         }
2369     }
2370
2371     reported_plen = tvb_reported_length(tvb) - IPv6_HDR_SIZE;
2372     if (!pinfo->flags.in_error_pkt && plen > reported_plen) {
2373         expert_add_info_format(pinfo, ti_ipv6_plen, &ei_ipv6_plen_exceeds_framing,
2374                     "IPv6 payload length exceeds framing length (%d bytes)", reported_plen);
2375     }
2376
2377     /* Fill in IP header fields for subdissectors */
2378     iph = wmem_new0(wmem_packet_scope(), ws_ip6);
2379     iph->ip6_ver = 6;
2380     iph->ip6_tc = ip6_tcls;
2381     iph->ip6_flw = ip6_flow;
2382     iph->ip6_len = plen;
2383     iph->ip6_nxt = ip6_nxt;
2384     iph->ip6_hop = ip6_hlim;
2385     alloc_address_wmem_ipv6(wmem_packet_scope(), &iph->ip6_src, ip6_src);
2386     alloc_address_wmem_ipv6(wmem_packet_scope(), &iph->ip6_dst, ip6_dst);
2387
2388     /* Shared state between IPv6 header and extensions. */
2389     ipv6_pinfo_t  *ipv6_pinfo = wmem_new0(pinfo->pool, ipv6_pinfo_t);
2390     ipv6_pinfo->ip6_plen = ip6_plen;
2391     ipv6_pinfo->jumbo_plen = jumbo_plen;
2392     ipv6_pinfo->frag_plen = ip6_plen; /* updated by extension header dissectors, if any */
2393     if (!ipv6_exthdr_under_root) {
2394         ipv6_pinfo->ipv6_tree = ipv6_tree;
2395         ipv6_pinfo->ipv6_item_len = IPv6_HDR_SIZE;
2396     }
2397     p_add_proto_data(pinfo->pool, pinfo, proto_ipv6, IPV6_PROTO_PINFO, ipv6_pinfo);
2398
2399     /* Adjust the length of this tvbuff to include only the IPv6 datagram. */
2400     set_actual_length(tvb, IPv6_HDR_SIZE + plen);
2401     save_fragmented = pinfo->fragmented;
2402
2403     p_add_ipv6_nxt(pinfo, ip6_nxt);
2404
2405     next_tvb = tvb_new_subset_remaining(tvb, offset);
2406     ipv6_dissect_next(ip6_nxt, next_tvb, pinfo, tree, iph);
2407
2408     pinfo->fragmented = save_fragmented;
2409     return tvb_captured_length(tvb);
2410 }
2411
2412 void
2413 ipv6_dissect_next(guint nxt, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ws_ip6 *iph)
2414 {
2415     dissector_handle_t nxt_handle;
2416     ipv6_pinfo_t *ipv6_pinfo = p_get_ipv6_pinfo(pinfo);
2417
2418     switch (nxt) {
2419         case IP_PROTO_HOPOPTS:
2420         case IP_PROTO_ROUTING:
2421         case IP_PROTO_FRAGMENT:
2422         case IP_PROTO_DSTOPTS:
2423         case IP_PROTO_AH:
2424         case IP_PROTO_MIPV6:
2425         case IP_PROTO_SHIM6:
2426             nxt_handle = dissector_get_uint_handle(ip_dissector_table, nxt);
2427             break;
2428         default:
2429             nxt_handle = NULL;
2430             break;
2431     }
2432     if (nxt_handle != NULL) {
2433         call_dissector_with_data(nxt_handle, tvb, pinfo, tree, iph);
2434         return;
2435     }
2436
2437     /*
2438      * Done with extension header chain
2439      */
2440
2441     if (ipv6_pinfo != NULL && ipv6_pinfo->ipv6_tree != NULL) {
2442         /* Set IPv6 Header length */
2443         proto_item_set_len(proto_tree_get_parent(ipv6_pinfo->ipv6_tree), ipv6_pinfo->ipv6_item_len);
2444         ipv6_pinfo->ipv6_tree = NULL;
2445     }
2446
2447     if (iph != NULL && iph->ip6_ver == 6) {
2448         iph->ip6_nxt = nxt; /* upper-layer protocol more useful */
2449         tap_queue_packet(ipv6_tap, pinfo, iph);
2450     }
2451
2452     if (nxt == IP_PROTO_NONE) {
2453         col_set_str(pinfo->cinfo, COL_INFO, "IPv6 no next header");
2454         call_data_dissector(tvb, pinfo, tree);
2455         return;
2456     }
2457
2458     if (ip_try_dissect(try_heuristic_first, nxt, tvb, pinfo, tree, iph)) {
2459         return;
2460     }
2461
2462     /* Unknown protocol. */
2463     col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown IP Protocol: %s (%u)", ipprotostr(nxt), nxt);
2464     call_data_dissector(tvb, pinfo, tree);
2465 }
2466
2467 void
2468 proto_register_ipv6(void)
2469 {
2470     static hf_register_info hf_ipv6[] = {
2471         { &hf_ipv6_version,
2472             { "Version", "ipv6.version",
2473                 FT_UINT8, BASE_DEC, NULL, 0xF0,
2474                 NULL, HFILL }
2475         },
2476         { &hf_ip_version,
2477             { "Version", "ip.version",
2478                 FT_UINT8, BASE_DEC, NULL, 0xF0,
2479                 NULL, HFILL }
2480         },
2481         { &hf_ipv6_tclass,
2482             { "Traffic Class", "ipv6.tclass",
2483                 FT_UINT32, BASE_HEX, NULL, 0x0FF00000,
2484                 NULL, HFILL }
2485         },
2486         { &hf_ipv6_tclass_dscp,
2487             { "Differentiated Services Codepoint", "ipv6.tclass.dscp",
2488                 FT_UINT32, BASE_DEC | BASE_EXT_STRING, &dscp_vals_ext, 0x0FC00000,
2489                 NULL, HFILL }
2490         },
2491         { &hf_ipv6_tclass_ecn,
2492             { "Explicit Congestion Notification", "ipv6.tclass.ecn",
2493                 FT_UINT32, BASE_DEC | BASE_EXT_STRING, &ecn_vals_ext, 0x00300000,
2494                 NULL, HFILL }
2495         },
2496         { &hf_ipv6_flow,
2497             { "Flow Label", "ipv6.flow",
2498                 FT_UINT32, BASE_HEX, NULL, 0x000FFFFF,
2499                 NULL, HFILL }
2500         },
2501         { &hf_ipv6_plen,
2502             { "Payload Length", "ipv6.plen",
2503                 FT_UINT16, BASE_DEC, NULL, 0x0,
2504                 NULL, HFILL }
2505         },
2506         { &hf_ipv6_nxt,
2507             { "Next Header", "ipv6.nxt",
2508                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
2509                 NULL, HFILL }
2510         },
2511         { &hf_ipv6_hlim,
2512             { "Hop Limit", "ipv6.hlim",
2513                 FT_UINT8, BASE_DEC, NULL, 0x0,
2514                 NULL, HFILL }
2515         },
2516         { &hf_ipv6_src,
2517             { "Source", "ipv6.src",
2518                 FT_IPv6, BASE_NONE, NULL, 0x0,
2519                 "Source IPv6 Address", HFILL }
2520         },
2521         { &hf_ipv6_src_host,
2522             { "Source Host", "ipv6.src_host",
2523                 FT_STRING, BASE_NONE, NULL, 0x0,
2524                 "Source IPv6 Host", HFILL }
2525         },
2526         { &hf_ipv6_src_sa_mac,
2527             { "Source SA MAC", "ipv6.src_sa_mac",
2528                 FT_ETHER, BASE_NONE, NULL, 0x0,
2529                 "Source IPv6 Stateless Autoconfiguration MAC Address", HFILL }
2530         },
2531         { &hf_ipv6_src_isatap_ipv4,
2532             { "Source ISATAP IPv4", "ipv6.src_isatap_ipv4",
2533                 FT_IPv4, BASE_NONE, NULL, 0x0,
2534                 "Source IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
2535         },
2536         { &hf_ipv6_src_6to4_gateway_ipv4,
2537             { "Source 6to4 Gateway IPv4", "ipv6.src_6to4_gw_ipv4",
2538                 FT_IPv4, BASE_NONE, NULL, 0x0,
2539                 "Source IPv6 6to4 Gateway IPv4 Address", HFILL }
2540         },
2541         { &hf_ipv6_src_6to4_sla_id,
2542             { "Source 6to4 SLA ID", "ipv6.src_6to4_sla_id",
2543                 FT_UINT16, BASE_DEC, NULL, 0x0,
2544                 "Source IPv6 6to4 SLA ID", HFILL }
2545         },
2546         { &hf_ipv6_src_teredo_server_ipv4,
2547             { "Source Teredo Server IPv4", "ipv6.src_ts_ipv4",
2548                 FT_IPv4, BASE_NONE, NULL, 0x0,
2549                 "Source IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
2550         },
2551         { &hf_ipv6_src_teredo_port,
2552             { "Source Teredo Port", "ipv6.src_tc_port",
2553                 FT_UINT16, BASE_DEC, NULL, 0x0,
2554                 "Source IPv6 Teredo Client Mapped Port", HFILL }
2555         },
2556         { &hf_ipv6_src_teredo_client_ipv4,
2557             { "Source Teredo Client IPv4", "ipv6.src_tc_ipv4",
2558                 FT_IPv4, BASE_NONE, NULL, 0x0,
2559                 "Source IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
2560         },
2561         { &hf_ipv6_src_embed_ipv4,
2562             { "Source Embedded IPv4", "ipv6.src_embed_ipv4",
2563                 FT_IPv4, BASE_NONE, NULL, 0x0,
2564                 "Source IPv4-Embedded IPv6 Address with Well-Known Prefix", HFILL }
2565         },
2566         { &hf_ipv6_dst,
2567             { "Destination", "ipv6.dst",
2568                 FT_IPv6, BASE_NONE, NULL, 0x0,
2569                 "Destination IPv6 Address", HFILL }
2570         },
2571         { &hf_ipv6_dst_host,
2572             { "Destination Host", "ipv6.dst_host",
2573                 FT_STRING, BASE_NONE, NULL, 0x0,
2574                 "Destination IPv6 Host", HFILL }
2575         },
2576         { &hf_ipv6_dst_sa_mac,
2577             { "Destination SA MAC", "ipv6.dst_sa_mac",
2578                 FT_ETHER, BASE_NONE, NULL, 0x0,
2579                 "Destination IPv6 Stateless Autoconfiguration MAC Address", HFILL }
2580         },
2581         { &hf_ipv6_dst_isatap_ipv4,
2582             { "Destination ISATAP IPv4", "ipv6.dst_isatap_ipv4",
2583                 FT_IPv4, BASE_NONE, NULL, 0x0,
2584                 "Destination IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
2585         },
2586         { &hf_ipv6_dst_6to4_gateway_ipv4,
2587             { "Destination 6to4 Gateway IPv4", "ipv6.dst_6to4_gw_ipv4",
2588                 FT_IPv4, BASE_NONE, NULL, 0x0,
2589                 "Destination IPv6 6to4 Gateway IPv4 Address", HFILL }
2590         },
2591         { &hf_ipv6_dst_6to4_sla_id,
2592             { "Destination 6to4 SLA ID", "ipv6.dst_6to4_sla_id",
2593                 FT_UINT16, BASE_DEC, NULL, 0x0,
2594                 "Destination IPv6 6to4 SLA ID", HFILL }
2595         },
2596         { &hf_ipv6_dst_teredo_server_ipv4,
2597             { "Destination Teredo Server IPv4", "ipv6.dst_ts_ipv4",
2598                 FT_IPv4, BASE_NONE, NULL, 0x0,
2599                 "Destination IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
2600         },
2601         { &hf_ipv6_dst_teredo_port,
2602             { "Destination Teredo Port", "ipv6.dst_tc_port",
2603                 FT_UINT16, BASE_DEC, NULL, 0x0,
2604                 "Destination IPv6 Teredo Client Mapped Port", HFILL }
2605         },
2606         { &hf_ipv6_dst_teredo_client_ipv4,
2607             { "Destination Teredo Client IPv4", "ipv6.dst_tc_ipv4",
2608                 FT_IPv4, BASE_NONE, NULL, 0x0,
2609                 "Destination IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
2610         },
2611         { &hf_ipv6_dst_embed_ipv4,
2612             { "Destination Embedded IPv4", "ipv6.dst_embed_ipv4",
2613                 FT_IPv4, BASE_NONE, NULL, 0x0,
2614                 "Destination IPv4-Embedded IPv6 Address with Well-Known Prefix", HFILL }
2615         },
2616         { &hf_ipv6_addr,
2617             { "Source or Destination Address", "ipv6.addr",
2618                 FT_IPv6, BASE_NONE, NULL, 0x0,
2619                 NULL, HFILL }
2620         },
2621         { &hf_ipv6_host,
2622             { "Source or Destination Host", "ipv6.host",
2623                 FT_STRING, BASE_NONE, NULL, 0x0,
2624                 NULL, HFILL }
2625         },
2626         { &hf_ipv6_sa_mac,
2627             { "SA MAC", "ipv6.sa_mac",
2628                 FT_ETHER, BASE_NONE, NULL, 0x0,
2629                 "IPv6 Stateless Autoconfiguration MAC Address", HFILL }
2630         },
2631         { &hf_ipv6_isatap_ipv4,
2632             { "ISATAP IPv4", "ipv6.isatap_ipv4",
2633                 FT_IPv4, BASE_NONE, NULL, 0x0,
2634                 "IPv6 ISATAP Encapsulated IPv4 Address", HFILL }
2635         },
2636         { &hf_ipv6_6to4_gateway_ipv4,
2637             { "6to4 Gateway IPv4", "ipv6.6to4_gw_ipv4",
2638                 FT_IPv4, BASE_NONE, NULL, 0x0,
2639                 "IPv6 6to4 Gateway IPv4 Address", HFILL }
2640         },
2641         { &hf_ipv6_6to4_sla_id,
2642             { "6to4 SLA ID", "ipv6.6to4_sla_id",
2643                 FT_UINT16, BASE_DEC, NULL, 0x0,
2644                 "IPv6 6to4 SLA ID", HFILL }
2645         },
2646         { &hf_ipv6_teredo_server_ipv4,
2647             { "Teredo Server IPv4", "ipv6.ts_ipv4",
2648                 FT_IPv4, BASE_NONE, NULL, 0x0,
2649                 "IPv6 Teredo Server Encapsulated IPv4 Address", HFILL }
2650         },
2651         { &hf_ipv6_teredo_port,
2652             { "Teredo Port", "ipv6.tc_port",
2653                 FT_UINT16, BASE_DEC, NULL, 0x0,
2654                 "IPv6 Teredo Client Mapped Port", HFILL }
2655         },
2656         { &hf_ipv6_teredo_client_ipv4,
2657             { "Teredo Client IPv4", "ipv6.tc_ipv4",
2658                 FT_IPv4, BASE_NONE, NULL, 0x0,
2659                 "IPv6 Teredo Client Encapsulated IPv4 Address", HFILL }
2660         },
2661         { &hf_ipv6_embed_ipv4,
2662             { "Embedded IPv4", "ipv6.embed_ipv4",
2663                 FT_IPv4, BASE_NONE, NULL, 0x0,
2664                 "IPv4-Embedded IPv6 Address with Well-Known Prefix", HFILL }
2665         },
2666
2667         { &hf_geoip_country,
2668             { "Source or Destination GeoIP Country", "ipv6.geoip.country",
2669                 FT_STRING, STR_UNICODE, NULL, 0x0,
2670                 NULL, HFILL }
2671         },
2672         { &hf_geoip_country_iso,
2673             { "Source or Destination GeoIP ISO Two Letter Country Code", "ipv6.geoip.country_iso",
2674                 FT_STRING, STR_UNICODE, NULL, 0x0,
2675                 NULL, HFILL }
2676         },
2677         { &hf_geoip_city,
2678             { "Source or Destination GeoIP City", "ipv6.geoip.city",
2679                 FT_STRING, STR_UNICODE, NULL, 0x0,
2680                 NULL, HFILL }
2681         },
2682         { &hf_geoip_as_number,
2683             { "Source or Destination GeoIP AS Number", "ipv6.geoip.asnum",
2684                 FT_UINT32, BASE_DEC, NULL, 0x0,
2685                 NULL, HFILL }
2686         },
2687         { &hf_geoip_as_org,
2688             { "Source or Destination GeoIP AS Organization", "ipv6.geoip.org",
2689                 FT_STRING, STR_UNICODE, NULL, 0x0,
2690                 NULL, HFILL }
2691         },
2692         { &hf_geoip_latitude,
2693             { "Source or Destination GeoIP Latitude", "ipv6.geoip.lat",
2694                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2695                 NULL, HFILL }
2696         },
2697         { &hf_geoip_longitude,
2698             { "Source or Destination GeoIP Longitude", "ipv6.geoip.lon",
2699                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2700                 NULL, HFILL }
2701         },
2702         { &hf_geoip_src_summary,
2703             { "Source GeoIP", "ipv6.geoip.src_summary",
2704                 FT_STRING, STR_UNICODE, NULL, 0x0,
2705                 NULL, HFILL }
2706         },
2707         { &hf_geoip_src_country,
2708             { "Source GeoIP Country", "ipv6.geoip.src_country",
2709                 FT_STRING, STR_UNICODE, NULL, 0x0,
2710                 NULL, HFILL }
2711         },
2712         { &hf_geoip_src_country_iso,
2713             { "Source GeoIP ISO Two Letter Country Code", "ipv6.geoip.src_country_iso",
2714                 FT_STRING, STR_UNICODE, NULL, 0x0,
2715                 NULL, HFILL }
2716         },
2717         { &hf_geoip_src_city,
2718             { "Source GeoIP City", "ipv6.geoip.src_city",
2719                 FT_STRING, STR_UNICODE, NULL, 0x0,
2720                 NULL, HFILL }
2721         },
2722         { &hf_geoip_src_as_number,
2723             { "Source GeoIP AS Number", "ipv6.geoip.src_asnum",
2724                 FT_UINT32, BASE_DEC, NULL, 0x0,
2725                 NULL, HFILL }
2726         },
2727         { &hf_geoip_src_as_org,
2728             { "Source GeoIP AS Organization", "ipv6.geoip.src_org",
2729                 FT_STRING, STR_UNICODE, NULL, 0x0,
2730                 NULL, HFILL }
2731         },
2732         { &hf_geoip_src_latitude,
2733             { "Source GeoIP Latitude", "ipv6.geoip.src_lat",
2734                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2735                 NULL, HFILL }
2736         },
2737         { &hf_geoip_src_longitude,
2738             { "Source GeoIP Longitude", "ipv6.geoip.src_lon",
2739                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2740                 NULL, HFILL }
2741         },
2742         { &hf_geoip_dst_summary,
2743             { "Destination GeoIP", "ipv6.geoip.dst_summary",
2744                 FT_STRING, STR_UNICODE, NULL, 0x0,
2745                 NULL, HFILL }
2746         },
2747         { &hf_geoip_dst_country,
2748             { "Destination GeoIP Country", "ipv6.geoip.dst_country",
2749                 FT_STRING, STR_UNICODE, NULL, 0x0,
2750                 NULL, HFILL }
2751         },
2752         { &hf_geoip_dst_country_iso,
2753             { "Destination GeoIP ISO Two Letter Country Code", "ipv6.geoip.dst_country_iso",
2754                 FT_STRING, STR_UNICODE, NULL, 0x0,
2755                 NULL, HFILL }
2756         },
2757         { &hf_geoip_dst_city,
2758             { "Destination GeoIP City", "ipv6.geoip.dst_city",
2759                 FT_STRING, STR_UNICODE, NULL, 0x0,
2760                 NULL, HFILL }
2761         },
2762         { &hf_geoip_dst_as_number,
2763             { "Destination GeoIP AS Number", "ipv6.geoip.dst_asnum",
2764                 FT_UINT32, BASE_DEC, NULL, 0x0,
2765                 NULL, HFILL }
2766         },
2767         { &hf_geoip_dst_as_org,
2768             { "Destination GeoIP AS Organization", "ipv6.geoip.dst_org",
2769                 FT_STRING, STR_UNICODE, NULL, 0x0,
2770                 NULL, HFILL }
2771         },
2772         { &hf_geoip_dst_latitude,
2773             { "Destination GeoIP Latitude", "ipv6.geoip.dst_lat",
2774                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2775                 NULL, HFILL }
2776         },
2777         { &hf_geoip_dst_longitude,
2778             { "Destination GeoIP Longitude", "ipv6.geoip.dst_lon",
2779                 FT_DOUBLE, BASE_NONE, NULL, 0x0,
2780                 NULL, HFILL }
2781         },
2782
2783         { &hf_ipv6_opt,
2784             { "IPv6 Option", "ipv6.opt",
2785                 FT_NONE, BASE_NONE, NULL, 0x0,
2786                 "Option", HFILL }
2787         },
2788         { &hf_ipv6_opt_type,
2789             { "Type", "ipv6.opt.type",
2790                 FT_UINT8, BASE_HEX | BASE_EXT_STRING, &ipv6_opt_type_vals_ext, 0x0,
2791                 "Option type", HFILL }
2792         },
2793         { &hf_ipv6_opt_type_action,
2794             { "Action", "ipv6.opt.type.action",
2795                 FT_UINT8, BASE_DEC, VALS(ipv6_opt_type_action_vals), 0xC0,
2796                 "Action for unrecognized option type", HFILL }
2797         },
2798         { &hf_ipv6_opt_type_change,
2799             { "May Change", "ipv6.opt.type.change",
2800                 FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x20,
2801                 "Whether the option data may change en-route", HFILL }
2802         },
2803         { &hf_ipv6_opt_type_rest,
2804             { "Low-Order Bits", "ipv6.opt.type.rest",
2805                 FT_UINT8, BASE_HEX, NULL, 0x1F,
2806                 "Remaining low-order bits", HFILL }
2807         },
2808         { &hf_ipv6_opt_length,
2809             { "Length", "ipv6.opt.length",
2810                 FT_UINT8, BASE_DEC, NULL, 0x0,
2811                 "Option length in octets", HFILL }
2812         },
2813         { &hf_ipv6_opt_pad1,
2814             { "Pad1", "ipv6.opt.pad1",
2815                 FT_NONE, BASE_NONE, NULL, 0x0,
2816                 "Pad1 Option", HFILL }
2817         },
2818         { &hf_ipv6_opt_padn,
2819             { "PadN", "ipv6.opt.padn",
2820                 FT_BYTES, BASE_NONE|BASE_ALLOW_ZERO, NULL, 0x0,
2821                 "PadN Option", HFILL }
2822         },
2823         { &hf_ipv6_opt_rtalert,
2824             { "Router Alert", "ipv6.opt.router_alert",
2825                 FT_UINT16, BASE_DEC, VALS(ipv6_opt_rtalert_vals), 0x0,
2826                 "Router Alert Option", HFILL }
2827         },
2828         { &hf_ipv6_opt_tel,
2829             { "Tunnel Encapsulation Limit", "ipv6.opt.tel",
2830                 FT_UINT8, BASE_DEC, NULL, 0x0,
2831                 "How many further levels of encapsulation are permitted", HFILL }
2832         },
2833         { &hf_ipv6_opt_jumbo,
2834             { "Payload Length", "ipv6.opt.jumbo",
2835                 FT_UINT32, BASE_DEC, NULL, 0x0,
2836                 "IPv6 (Jumbo) Payload Length", HFILL }
2837         },
2838         { &hf_ipv6_opt_calipso_doi,
2839             { "CALIPSO Domain of Interpretation", "ipv6.opt.calipso.doi",
2840                 FT_UINT8, BASE_DEC, NULL, 0x0,
2841                 NULL, HFILL }
2842         },
2843         { &hf_ipv6_opt_calipso_cmpt_length,
2844             { "Compartment Length", "ipv6.opt.calipso.cmpt.length",
2845                 FT_UINT8, BASE_DEC, NULL, 0x0,
2846                 NULL, HFILL }
2847         },
2848         { &hf_ipv6_opt_calipso_sens_level,
2849             { "Sensitivity Level", "ipv6.opt.calipso.sens_level",
2850                 FT_UINT8, BASE_DEC, NULL, 0x0,
2851                 NULL, HFILL }
2852         },
2853         { &hf_ipv6_opt_calipso_checksum,
2854             { "Checksum", "ipv6.opt.calipso.checksum",
2855                 FT_UINT16, BASE_HEX, NULL, 0x0,
2856                 NULL, HFILL }
2857         },
2858         { &hf_ipv6_opt_calipso_cmpt_bitmap,
2859             { "Compartment Bitmap", "ipv6.opt.calipso.cmpt_bitmap",
2860                 FT_BYTES, BASE_NONE, NULL, 0x0,
2861                 NULL, HFILL }
2862         },
2863         { &hf_ipv6_opt_smf_dpd_hash_bit,
2864             { "H-bit", "ipv6.opt.smf_dpd.hash_bit",
2865                 FT_BOOLEAN, 8, NULL, 0x80,
2866                 "Hash indicator", HFILL }
2867         },
2868         { &hf_ipv6_opt_smf_dpd_tid_type,
2869             { "TaggerID Type", "ipv6.opt.smf_dpd.tid_type",
2870                 FT_UINT8, BASE_DEC, VALS(ipv6_opt_smf_dpd_tidty_vals), 0x70,
2871                 NULL, HFILL }
2872         },
2873         { &hf_ipv6_opt_smf_dpd_tid_len,
2874             { "TaggerID Length", "ipv6.opt.smf_dpd.tid_len",
2875                 FT_UINT8, BASE_DEC, NULL, 0x0F,
2876                 NULL, HFILL }
2877         },
2878         { &hf_ipv6_opt_smf_dpd_tagger_id,
2879             { "TaggerID", "ipv6.opt.smf_dpd.tagger_id",
2880                 FT_BYTES, BASE_NONE, NULL, 0x0,
2881                 NULL, HFILL }
2882         },
2883         { &hf_ipv6_opt_smf_dpd_ident,
2884             { "Identifier", "ipv6.opt.smf_dpd.ident",
2885                 FT_BYTES, BASE_NONE, NULL, 0x0,
2886                 NULL, HFILL }
2887         },
2888         { &hf_ipv6_opt_smf_dpd_hav,
2889             { "Hash Assist Value", "ipv6.opt.smf_dpd.hav",
2890                 FT_BYTES, BASE_NONE, NULL, 0x0,
2891                 NULL, HFILL }
2892         },
2893         { &hf_ipv6_opt_pdm_scale_dtlr,
2894             { "Scale DTLR", "ipv6.opt.pdm.scale_dtlr",
2895                 FT_UINT8, BASE_DEC, NULL, 0x0,
2896                 "Scale for Delta Time Last Received", HFILL }
2897         },
2898         { &hf_ipv6_opt_pdm_scale_dtls,
2899             { "Scale DTLS", "ipv6.opt.pdm.scale_dtls",
2900                 FT_UINT8, BASE_DEC, NULL, 0x0,
2901                 "Scale for Delta Time Last Sent", HFILL }
2902         },
2903         { &hf_ipv6_opt_pdm_psn_this_pkt,
2904             { "PSN This Packet", "ipv6.opt.pdm.psn_this_pkt",
2905                 FT_UINT16, BASE_DEC, NULL, 0x0,
2906                 "Packet Sequence Number This Packet", HFILL }
2907         },
2908         { &hf_ipv6_opt_pdm_psn_last_recv,
2909             { "PSN Last Received", "ipv6.opt.pdm.psn_last_recv",
2910                 FT_UINT16, BASE_DEC, NULL, 0x0,
2911                 "Packet Sequence Number Last Received", HFILL }
2912         },
2913         { &hf_ipv6_opt_pdm_delta_last_recv,
2914             { "Delta Time Last Received", "ipv6.opt.pdm.delta_last_recv",
2915                 FT_UINT16, BASE_DEC, NULL, 0x0,
2916                 NULL, HFILL }
2917         },
2918         { &hf_ipv6_opt_pdm_delta_last_sent,
2919             { "Delta Time Last Sent", "ipv6.opt.pdm.delta_last_sent",
2920                 FT_UINT16, BASE_DEC, NULL, 0x0,
2921                 NULL, HFILL }
2922         },
2923         { &hf_ipv6_opt_qs_func,
2924             { "Function", "ipv6.opt.qs_func",
2925                 FT_UINT8, BASE_DEC, VALS(qs_func_vals), QS_FUNC_MASK,
2926                 NULL, HFILL }
2927         },
2928         { &hf_ipv6_opt_qs_rate,
2929             { "Rate", "ipv6.opt.qs_rate",
2930                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &qs_rate_vals_ext, QS_RATE_MASK,
2931                 NULL, HFILL }
2932         },
2933         { &hf_ipv6_opt_qs_ttl,
2934             { "QS TTL", "ipv6.opt.qs_ttl",
2935                 FT_UINT8, BASE_DEC, NULL, 0x0,
2936                 NULL, HFILL }
2937         },
2938         { &hf_ipv6_opt_qs_ttl_diff,
2939             { "TTL Diff", "ipv6.opt.qs_ttl_diff",
2940                 FT_UINT8, BASE_DEC, NULL, 0x0,
2941                 NULL, HFILL }
2942         },
2943         { &hf_ipv6_opt_qs_unused,
2944             { "Not Used", "ipv6.opt.qs_unused",
2945                 FT_UINT8, BASE_DEC, NULL, 0x0,
2946                 NULL, HFILL }
2947         },
2948         { &hf_ipv6_opt_qs_nonce,
2949             { "QS Nonce", "ipv6.opt.qs_nonce",
2950                 FT_UINT32, BASE_HEX, NULL, 0xFFFFFFFC,
2951                 NULL, HFILL }
2952         },
2953         { &hf_ipv6_opt_qs_reserved,
2954             { "Reserved", "ipv6.opt.qs_reserved",
2955                 FT_UINT32, BASE_HEX, NULL, 0x0003,
2956                 NULL, HFILL }
2957         },
2958         { &hf_ipv6_opt_mipv6_home_address,
2959             { "MIPv6 Home Address", "ipv6.opt.mipv6.home_address",
2960                 FT_IPv6, BASE_NONE, NULL, 0x0,
2961                 NULL, HFILL }
2962         },
2963         { &hf_ipv6_opt_rpl_flag,
2964             { "Flag", "ipv6.opt.rpl.flag",
2965                 FT_UINT8, BASE_HEX, NULL, 0x0,
2966                 NULL, HFILL }
2967         },
2968         { &hf_ipv6_opt_rpl_flag_o,
2969             { "Down", "ipv6.opt.rpl.flag.o",
2970                 FT_BOOLEAN, 8, NULL, 0x80,
2971                 "The packet is expected to progress Up or Down", HFILL }
2972         },
2973         { &hf_ipv6_opt_rpl_flag_r,
2974             { "Rank Error", "ipv6.opt.rpl.flag.r",
2975                 FT_BOOLEAN, 8, NULL, 0x40,
2976                 "Whether a rank error was detected", HFILL }
2977         },
2978         { &hf_ipv6_opt_rpl_flag_f,
2979             { "Forwarding Error", "ipv6.opt.rpl.flag.f",
2980                 FT_BOOLEAN, 8, NULL, 0x20,
2981                 "Set if the node cannot forward the packet further towards the destination", HFILL }
2982         },
2983         { &hf_ipv6_opt_rpl_flag_rsv,
2984             { "Reserved", "ipv6.opt.rpl.flag.rsv",
2985                 FT_UINT8, BASE_HEX, NULL, 0x1F,
2986                 "Reserved (must be zero)", HFILL }
2987         },
2988         { &hf_ipv6_opt_rpl_instance_id,
2989             { "RPLInstanceID", "ipv6.opt.rpl.instance_id",
2990                 FT_UINT8, BASE_HEX, NULL, 0x0,
2991                 "The DODAG instance along which the packet is sent", HFILL }
2992         },
2993         { &hf_ipv6_opt_rpl_senderrank,
2994             { "Sender Rank", "ipv6.opt.rpl.sender_rank",
2995                 FT_UINT16, BASE_HEX, NULL, 0x0,
2996                 "Set to zero by the source and to DAGRank(rank) by a router that forwards inside the RPL network", HFILL }
2997         },
2998         { &hf_ipv6_opt_ilnp_nonce,
2999             { "ILNP Nonce", "ipv6.opt.ilnp_nonce",
3000                 FT_BYTES, BASE_NONE, NULL, 0x0,
3001                 NULL, HFILL }
3002         },
3003         { &hf_ipv6_opt_lio_len,
3004             { "LineIDLen", "ipv6.opt.lio.length",
3005                 FT_UINT8, BASE_DEC, NULL, 0x0,
3006                 NULL, HFILL }
3007         },
3008         { &hf_ipv6_opt_lio_id,
3009             { "Line ID", "ipv6.opt.lio.line_id",
3010                 FT_STRING, BASE_NONE, NULL, 0x0,
3011                 NULL, HFILL }
3012         },
3013         { &hf_ipv6_opt_mpl_flag,
3014             { "Flag", "ipv6.opt.mpl.flag",
3015                 FT_UINT8, BASE_HEX, NULL, 0x0,
3016                 NULL, HFILL }
3017         },
3018         { &hf_ipv6_opt_mpl_flag_s,
3019             { "Seed ID Length", "ipv6.opt.mpl.flag.s",
3020                 FT_UINT8, BASE_DEC, NULL, 0xC0,
3021                 "Identifies the length of Seed ID", HFILL }
3022         },
3023         { &hf_ipv6_opt_mpl_flag_m,
3024             { "Largest Sequence", "ipv6.opt.mpl.flag.m",
3025                 FT_BOOLEAN, 8, NULL, 0x20,
3026                 "Indicates Sequence is known to be the largest sequence number", HFILL }
3027         },
3028         { &hf_ipv6_opt_mpl_flag_v,
3029             { "Version", "ipv6.opt.mpl.flag.v",
3030                 FT_BOOLEAN, 8, NULL, 0x10,
3031                 "0 indicates this option conforms to RFC<TBC>", HFILL }
3032         },
3033         { &hf_ipv6_opt_mpl_flag_rsv,
3034             { "Reserved", "ipv6.opt.mpl.flag.rsv",
3035                 FT_UINT8, BASE_HEX, NULL, 0x0F,
3036                 "Reserved (must be zero)", HFILL }
3037         },
3038         { &hf_ipv6_opt_mpl_sequence,
3039             { "Sequence", "ipv6.opt.mpl.sequence",
3040                 FT_UINT8, BASE_HEX, NULL, 0x0,
3041                 "Identifies relative ordering of MPL Data Messages from the MPL Seed identified by Seed ID", HFILL }
3042         },
3043         { &hf_ipv6_opt_mpl_seed_id,
3044             { "Seed ID", "ipv6.opt.mpl.seed_id",
3045                 FT_BYTES, BASE_NONE, NULL, 0x0,
3046                 "Uniquely identifies the MPL Seed that initiated dissemination of the MPL Data Message", HFILL }
3047         },
3048         { &hf_ipv6_opt_dff_flags,
3049             { "Flags", "ipv6.opt.dff.flags",
3050                 FT_UINT8, BASE_HEX, NULL, 0x0,
3051                 NULL, HFILL }
3052         },
3053         { &hf_ipv6_opt_dff_flag_ver,
3054             { "Version (VER)", "ipv6.opt.dff.flag.ver",
3055                 FT_UINT8, BASE_DEC, NULL, 0xC0,
3056                 "The version of DFF that is used", HFILL }
3057         },
3058         { &hf_ipv6_opt_dff_flag_dup,
3059             { "Duplicate (DUP)", "ipv6.opt.dff.flag.dup",
3060                 FT_BOOLEAN, 8, NULL, 0x20,
3061                 "Indicates the packet is being retransmitted", HFILL }
3062         },
3063         { &hf_ipv6_opt_dff_flag_ret,
3064             { "Return (RET)", "ipv6.opt.dff.flag.ret",
3065                 FT_BOOLEAN, 8, NULL, 0x10,
3066                 "Must be set to 1 prior to sending the packet back to the Previous Hop", HFILL }
3067         },
3068         { &hf_ipv6_opt_dff_flag_rsv,
3069             { "Reserved", "ipv6.opt.dff.flag.rsv",
3070                 FT_UINT8, BASE_HEX, NULL, 0x0F,
3071                 "Reserved (must be zero)", HFILL }
3072         },
3073         { &hf_ipv6_opt_dff_seqnum,
3074             { "Sequence Number", "ipv6.opt.dff.sequence_number",
3075                 FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
3076                 NULL, HFILL }
3077         },
3078         { &hf_ipv6_opt_experimental,
3079             { "Experimental Option", "ipv6.opt.experimental",
3080                 FT_BYTES, BASE_NONE, NULL, 0x0,
3081                 NULL, HFILL }
3082         },
3083         { &hf_ipv6_opt_unknown_data,
3084             { "Unknown Data", "ipv6.opt_unknown_data",
3085                 FT_BYTES, BASE_NONE, NULL, 0x0,
3086                 "Not interpreted data", HFILL }
3087         },
3088         { &hf_ipv6_opt_unknown,
3089             { "Unknown Option Payload", "ipv6.opt.unknown",
3090                 FT_BYTES, BASE_NONE, NULL, 0x0,
3091                 NULL, HFILL }
3092         },
3093         { &hf_ipv6_fragment,
3094             { "IPv6 Fragment", "ipv6.fragment",
3095                 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3096                 NULL, HFILL }
3097         },
3098         { &hf_ipv6_fragment_overlap,
3099             { "Fragment overlap", "ipv6.fragment.overlap",
3100                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3101                 "Fragment overlaps with other fragments", HFILL }
3102         },
3103         { &hf_ipv6_fragment_overlap_conflict,
3104             { "Conflicting data in fragment overlap", "ipv6.fragment.overlap.conflict",
3105                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3106                 "Overlapping fragments contained conflicting data", HFILL }
3107         },
3108         { &hf_ipv6_fragment_multiple_tails,
3109             { "Multiple tail fragments found", "ipv6.fragment.multipletails",
3110                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3111                 "Several tails were found when defragmenting the packet", HFILL }
3112         },
3113         { &hf_ipv6_fragment_too_long_fragment,
3114             { "Fragment too long", "ipv6.fragment.toolongfragment",
3115                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
3116                 "Fragment contained data past end of packet", HFILL }
3117         },
3118         { &hf_ipv6_fragment_error,
3119             { "Defragmentation error", "ipv6.fragment.error",
3120                 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3121                 "Defragmentation error due to illegal fragments", HFILL }
3122         },
3123         { &hf_ipv6_fragment_count,
3124             { "Fragment count", "ipv6.fragment.count",
3125                 FT_UINT32, BASE_DEC, NULL, 0x0,
3126                 NULL, HFILL }
3127         },
3128         { &hf_ipv6_fragments,
3129             { "IPv6 Fragments", "ipv6.fragments",
3130                 FT_NONE, BASE_NONE, NULL, 0x0,
3131                 NULL, HFILL }
3132         },
3133         { &hf_ipv6_reassembled_in,
3134             { "Reassembled IPv6 in frame", "ipv6.reassembled.in",
3135                 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
3136                 "This IPv6 packet is reassembled in this frame", HFILL }
3137         },
3138         { &hf_ipv6_reassembled_length,
3139             { "Reassembled IPv6 length", "ipv6.reassembled.length",
3140                 FT_UINT32, BASE_DEC, NULL, 0x0,
3141                 "The total length of the reassembled payload", HFILL }
3142         },
3143         { &hf_ipv6_reassembled_data,
3144             { "Reassembled IPv6 data", "ipv6.reassembled.data",
3145                 FT_BYTES, BASE_NONE, NULL, 0x0,
3146                 "The reassembled payload", HFILL }
3147         }
3148     };
3149
3150     static hf_register_info hf_ipv6_hopopts[] = {
3151         { &hf_ipv6_hopopts_nxt,
3152             { "Next Header", "ipv6.hopopts.nxt",
3153                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
3154                 NULL, HFILL }
3155         },
3156         { &hf_ipv6_hopopts_len,
3157             { "Length", "ipv6.hopopts.len",
3158                 FT_UINT8, BASE_DEC, NULL, 0x0,
3159                 "Extension header length in 8-octet words (minus 1)", HFILL }
3160         },
3161         { &hf_ipv6_hopopts_len_oct,
3162             { "Length", "ipv6.hopopts.len_oct",
3163                 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
3164                 "Extension header length in octets", HFILL }
3165         }
3166     };
3167
3168     static hf_register_info hf_ipv6_dstopts[] = {
3169         { &hf_ipv6_dstopts_nxt,
3170             { "Next Header", "ipv6.dstopts.nxt",
3171                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
3172                 NULL, HFILL }
3173         },
3174         { &hf_ipv6_dstopts_len,
3175             { "Length", "ipv6.dstopts.len",
3176                 FT_UINT8, BASE_DEC, NULL, 0x0,
3177                 "Extension header length in 8-octet words (minus 1)", HFILL }
3178         },
3179         { &hf_ipv6_dstopts_len_oct,
3180             { "Length", "ipv6.dstopts.len_oct",
3181                 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
3182                 "Extension header length in octets", HFILL }
3183         }
3184     };
3185
3186     static hf_register_info hf_ipv6_routing[] = {
3187
3188         /* IPv6 Routing Header */
3189         { &hf_ipv6_routing_nxt,
3190             { "Next Header", "ipv6.routing.nxt",
3191                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
3192                 NULL, HFILL }
3193         },
3194         { &hf_ipv6_routing_len,
3195             { "Length", "ipv6.routing.len",
3196                 FT_UINT8, BASE_DEC, NULL, 0x0,
3197                 "Extension header length in 8-octet words (minus 1)", HFILL }
3198         },
3199         { &hf_ipv6_routing_len_oct,
3200             { "Length", "ipv6.routing.len_oct",
3201                 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
3202                 "Extension header length in octets", HFILL }
3203         },
3204         { &hf_ipv6_routing_type,
3205             { "Type", "ipv6.routing.type",
3206                 FT_UINT8, BASE_DEC, VALS(routing_header_type), 0x0,
3207                 "Routing Header Type", HFILL }
3208         },
3209         { &hf_ipv6_routing_segleft,
3210             { "Segments Left", "ipv6.routing.segleft",
3211                 FT_UINT8, BASE_DEC, NULL, 0x0,
3212                 "Routing Header Segments Left", HFILL }
3213         },
3214         { &hf_ipv6_routing_unknown_data,
3215             { "Type-Specific Data", "ipv6.routing.unknown_data",
3216                 FT_BYTES, BASE_NONE, NULL, 0x0,
3217                 "Unknown routing header type-specific data", HFILL }
3218         },
3219
3220         /* Source Routing Header */
3221         { &hf_ipv6_routing_src_reserved,
3222             { "Reserved", "ipv6.routing.src.reserved",
3223                 FT_BYTES, BASE_NONE, NULL, 0x0,
3224                 "Must be zero", HFILL }
3225         },
3226         { &hf_ipv6_routing_src_addr,
3227             { "Address", "ipv6.routing.src.addr",
3228                 FT_IPv6, BASE_NONE, NULL, 0x0,
3229                 "Source Routing Header Address", HFILL }},
3230
3231         /* Mobile IPv6 */
3232         { &hf_ipv6_routing_mipv6_reserved,
3233             { "Reserved", "ipv6.routing.mipv6.reserved",
3234                 FT_BYTES, BASE_NONE, NULL, 0x0,
3235                 "Must be zero", HFILL }
3236         },
3237         { &hf_ipv6_routing_mipv6_home_address,
3238             { "Home Address", "ipv6.routing.mipv6.home_address",
3239                 FT_IPv6, BASE_NONE, NULL, 0x0,
3240                 NULL, HFILL }
3241         },
3242
3243         /* RPL Routing Header */
3244         { &hf_ipv6_routing_rpl_cmprI,
3245             { "Compressed Internal Octets (CmprI)", "ipv6.routing.rpl.cmprI",
3246                 FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_CMPRI,
3247                 "Elided octets from all but last segment", HFILL }
3248         },
3249         { &hf_ipv6_routing_rpl_cmprE,
3250             { "Compressed Final Octets (CmprE)", "ipv6.routing.rpl.cmprE",
3251                 FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_CMPRE,
3252                 "Elided octets from last segment address", HFILL }
3253         },
3254         { &hf_ipv6_routing_rpl_pad,
3255             { "Padding Bytes", "ipv6.routing.rpl.pad",
3256                 FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_PAD,
3257                 NULL, HFILL }
3258         },
3259         { &hf_ipv6_routing_rpl_reserved,
3260             { "Reserved", "ipv6.routing.rpl.reserved",
3261                 FT_UINT32, BASE_DEC, NULL, IP6RRPL_BITMASK_RESERVED,
3262                 "Must be zero", HFILL }
3263         },
3264         { &hf_ipv6_routing_rpl_addr_count,
3265             { "Total Address Count", "ipv6.routing.rpl.addr_count",
3266                 FT_INT32, BASE_DEC, NULL, 0,
3267                 NULL, HFILL }
3268         },
3269         { &hf_ipv6_routing_rpl_addr,
3270             { "Address", "ipv6.routing.rpl.address",
3271                 FT_BYTES, BASE_NONE, NULL, 0,
3272                 NULL, HFILL }
3273         },
3274         { &hf_ipv6_routing_rpl_fulladdr,
3275             { "Full Address", "ipv6.routing.rpl.full_address",
3276                 FT_IPv6, BASE_NONE, NULL, 0,
3277                 "Uncompressed IPv6 Address", HFILL }
3278         },
3279
3280         /* Segment Routing Header */
3281         { &hf_ipv6_routing_srh_first_seg,
3282             { "First segment", "ipv6.routing.srh.first_segment",
3283                 FT_UINT8, BASE_DEC, NULL, 0x0,
3284                 "Index of the first segment", HFILL }
3285         },
3286         { &hf_ipv6_routing_srh_flags,
3287             { "Flags", "ipv6.routing.srh.flags",
3288                 FT_UINT8, BASE_HEX, NULL, 0x0,
3289                 NULL, HFILL }
3290         },
3291         { &hf_ipv6_routing_srh_flag_unused1,
3292             { "Unused", "ipv6.routing.srh.flag_unused1",
3293                 FT_UINT8, BASE_HEX, NULL, 0x80,
3294                 "Unset on transmission and ignored on receipt", HFILL }
3295         },
3296         { &hf_ipv6_routing_srh_flag_p,
3297             { "Protected", "ipv6.routing.srh.flag_p",
3298                 FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x40,
3299                 NULL, HFILL }
3300         },
3301         { &hf_ipv6_routing_srh_flag_o,
3302             { "OAM", "ipv6.routing.srh.flag_o",
3303                 FT_BOOLEAN, 8, TFS(&tfs_true_false), 0x20,
3304                 NULL, HFILL }
3305         },
3306         { &hf_ipv6_routing_srh_flag_a,
3307             { "Alert", "ipv6.routing.srh.flag_a",
3308                 FT_BOOLEAN, 8, TFS(&tfs_present_not_present), 0x10,
3309                 NULL, HFILL }
3310         },
3311         { &hf_ipv6_routing_srh_flag_h,
3312             { "HMAC", "ipv6.routing.srh.flag_h",
3313                 FT_BOOLEAN, 8, TFS(&tfs_present_not_present), 0x08,
3314                 NULL, HFILL }
3315         },
3316         { &hf_ipv6_routing_srh_flag_unused2,
3317             { "Unused", "ipv6.routing.srh.flag_unused2",
3318                 FT_UINT8, BASE_HEX, NULL, 0x07,
3319                 NULL, HFILL }
3320         },
3321         { &hf_ipv6_routing_srh_reserved,
3322             { "Reserved", "ipv6.routing.srh.reserved",
3323                 FT_BYTES, BASE_NONE, NULL, 0x0,
3324                 "Must be zero", HFILL }
3325         },
3326         { &hf_ipv6_routing_srh_addr,
3327             { "Address", "ipv6.routing.srh.addr",
3328                 FT_IPv6, BASE_NONE, NULL, 0x0,
3329                 "Segment address", HFILL }
3330         }
3331     };
3332
3333     static hf_register_info hf_ipv6_fraghdr[] = {
3334         { &hf_ipv6_fraghdr_nxt,
3335             { "Next header", "ipv6.fraghdr.nxt",
3336                 FT_UINT8, BASE_DEC | BASE_EXT_STRING, &ipproto_val_ext, 0x0,
3337                 NULL, HFILL }
3338         },
3339         { &hf_ipv6_fraghdr_reserved_octet,
3340             { "Reserved octet", "ipv6.fraghdr.reserved_octet",
3341                 FT_UINT8, BASE_HEX, NULL, 0x0,
3342                 "Should always be 0", HFILL }
3343         },
3344         { &hf_ipv6_fraghdr_offset,
3345             { "Offset", "ipv6.fraghdr.offset",
3346                 FT_UINT16, BASE_DEC, NULL, IP6F_OFF_MASK,
3347                 "Fragment Offset", HFILL }
3348         },
3349         { &hf_ipv6_fraghdr_reserved_bits,
3350             { "Reserved bits", "ipv6.fraghdr.reserved_bits",
3351                 FT_UINT16, BASE_DEC, NULL, IP6F_RESERVED_MASK,
3352                 NULL, HFILL }
3353         },
3354         { &hf_ipv6_fraghdr_more,
3355             { "More Fragments", "ipv6.fraghdr.more",
3356                 FT_BOOLEAN, 16, TFS(&tfs_yes_no), IP6F_MORE_FRAG,
3357                 NULL, HFILL }
3358         },
3359         { &hf_ipv6_fraghdr_ident,
3360             { "Identification", "ipv6.fraghdr.ident",
3361                 FT_UINT32, BASE_HEX, NULL, 0x0,
3362                 "Fragment Identification", HFILL }
3363         }
3364     };
3365
3366     static gint *ett_ipv6[] = {
3367         &ett_ipv6_proto,
3368         &ett_ipv6_traffic_class,
3369         &ett_geoip_info,
3370         &ett_ipv6_opt,
3371         &ett_ipv6_opt_type,
3372         &ett_ipv6_opt_rpl,
3373         &ett_ipv6_opt_mpl,
3374         &ett_ipv6_opt_dff_flags,
3375         &ett_ipv6_fragment,
3376         &ett_ipv6_fragments
3377     };
3378
3379     static gint *ett_ipv6_hopopts[] = {
3380         &ett_ipv6_hopopts_proto
3381     };
3382
3383     static gint *ett_ipv6_routing[] = {
3384         &ett_ipv6_routing_proto,
3385         &ett_ipv6_routing_srh_flags,
3386         &ett_ipv6_routing_srh_vect
3387     };
3388
3389     static gint *ett_ipv6_fraghdr[] = {
3390         &ett_ipv6_fraghdr_proto
3391     };
3392
3393     static gint *ett_ipv6_dstopts[] = {
3394         &ett_ipv6_dstopts_proto
3395     };
3396
3397     static ei_register_info ei_ipv6[] = {
3398         { &ei_ipv6_opt_jumbo_missing,
3399             { "ipv6.opt.jumbo.missing", PI_MALFORMED, PI_ERROR,
3400                 "IPv6 payload length equals 0 and Hop-By-Hop present and Jumbo Payload option missing", EXPFILL }
3401         },
3402         { &ei_ipv6_opt_jumbo_prohibited,
3403             { "ipv6.opt.jumbo.prohibited", PI_PROTOCOL, PI_WARN,
3404                 "When IPv6 payload length does not equal 0 a Jumbo Payload option must not be present", EXPFILL }
3405         },
3406         { &ei_ipv6_opt_jumbo_truncated,
3407             { "ipv6.opt.jumbo.truncated", PI_PROTOCOL, PI_WARN,
3408                 "Jumbo Payload option present and jumbo length < 65536", EXPFILL }
3409         },
3410         { &ei_ipv6_opt_jumbo_fragment,
3411             { "ipv6.opt.jumbo.fragment", PI_PROTOCOL, PI_WARN,
3412                 "Jumbo Payload option cannot be used with a fragment header", EXPFILL }
3413         },
3414         { &ei_ipv6_opt_invalid_len,
3415             { "ipv6.opt.invalid_len", PI_MALFORMED, PI_ERROR,
3416                 "Invalid IPv6 option length", EXPFILL }
3417         },
3418         { &ei_ipv6_opt_unknown_data,
3419             { "ipv6.opt.unknown_data.expert", PI_UNDECODED, PI_NOTE,
3420                 "Unknown Data (not interpreted)", EXPFILL }
3421         },
3422         { &ei_ipv6_plen_exceeds_framing,
3423             { "ipv6.plen_exceeds_framing", PI_PROTOCOL, PI_WARN,
3424                 "IPv6 payload length does not match expected framing length", EXPFILL }
3425         },
3426         { &ei_ipv6_plen_zero,
3427             { "ipv6.plen_zero", PI_PROTOCOL, PI_CHAT,
3428                 "IPv6 payload length equals 0 (maybe because of \"TCP segmentation offload\" (TSO))", EXPFILL }
3429         },
3430         { &ei_ipv6_bogus_ipv6_version,
3431             { "ipv6.bogus_ipv6_version", PI_MALFORMED, PI_ERROR,
3432                 "Bogus IP version", EXPFILL }
3433             },
3434         { &ei_ipv6_invalid_header,
3435             { "ipv6.invalid_header", PI_MALFORMED, PI_ERROR,
3436                 "Invalid IPv6 header", EXPFILL }
3437         },
3438         { &ei_ipv6_opt_header_mismatch,
3439             { "ipv6.opt.header_mismatch", PI_PROTOCOL, PI_WARN,
3440                 "Wrong options extension header for type", EXPFILL }
3441         },
3442         { &ei_ipv6_opt_deprecated,
3443             { "ipv6.opt.deprecated", PI_DEPRECATED, PI_NOTE,
3444                 "Option type is deprecated", EXPFILL }
3445         }
3446     };
3447
3448     static ei_register_info ei_ipv6_hopopts[] = {
3449         { &ei_ipv6_hopopts_not_first,
3450             { "ipv6.hopopts.not_first", PI_PROTOCOL, PI_ERROR,
3451                 "IPv6 Hop-by-Hop extension header must appear immediately after IPv6 header", EXPFILL }
3452         }
3453     };
3454
3455     static ei_register_info ei_ipv6_routing[] = {
3456         { &ei_ipv6_dst_addr_not_multicast,
3457             { "ipv6.dst_addr.not_multicast", PI_PROTOCOL, PI_WARN,
3458                 "Destination address must not be a multicast address", EXPFILL }
3459         },
3460         { &ei_ipv6_src_route_list_mult_inst_same_addr,
3461             { "ipv6.src_route_list.mult_inst_same_addr", PI_PROTOCOL, PI_WARN,
3462                 "Multiple instances of the same address must not appear in the source route list", EXPFILL }
3463         },
3464         { &ei_ipv6_src_route_list_src_addr,
3465             { "ipv6.src_route_list.src_addr", PI_PROTOCOL, PI_WARN,
3466                 "Source address must not appear in the source route list", EXPFILL }
3467         },
3468         { &ei_ipv6_src_route_list_dst_addr,
3469             { "ipv6.src_route_list.dst_addr", PI_PROTOCOL, PI_WARN,
3470                 "Destination address must not appear in the source route list", EXPFILL }
3471         },
3472         { &ei_ipv6_src_route_list_multicast_addr,
3473             { "ipv6.src_route_list.multicast_addr", PI_PROTOCOL, PI_WARN,
3474                 "Multicast addresses must not appear in the source route list", EXPFILL }
3475         },
3476         { &ei_ipv6_routing_rpl_cmpri_cmpre_pad,
3477             { "ipv6.routing.rpl.cmprI_cmprE_pad", PI_PROTOCOL, PI_WARN,
3478                 "When cmprI equals 0 and cmprE equals 0, pad MUST equal 0 but instead was X", EXPFILL }
3479         },
3480         { &ei_ipv6_routing_rpl_addr_count_ge0,
3481             { "ipv6.routing.rpl.addr_count_ge0", PI_MALFORMED, PI_ERROR,
3482                 "Calculated total address count must be greater than or equal to 0, instead was X", EXPFILL }
3483         },
3484         { &ei_ipv6_routing_rpl_reserved,
3485             { "ipv6.routing.rpl.reserved_not0", PI_PROTOCOL, PI_NOTE,
3486                 "Reserved field must equal 0 but instead was X", EXPFILL }
3487         },
3488         { &ei_ipv6_routing_invalid_length,
3489             { "ipv6.routing.invalid_length", PI_MALFORMED, PI_ERROR,
3490                 "Invalid IPv6 Routing header length", EXPFILL }
3491             },
3492         { &ei_ipv6_routing_invalid_segleft,
3493             { "ipv6.routing.invalid_segleft", PI_PROTOCOL, PI_WARN,
3494                 "IPv6 Routing Header segments left field must not exceed address count", EXPFILL }
3495         },
3496         { &ei_ipv6_routing_undecoded,
3497             { "ipv6.routing.undecoded", PI_UNDECODED, PI_NOTE,
3498                 "Undecoded IPv6 routing header field", EXPFILL }
3499         },
3500         { &ei_ipv6_routing_deprecated,
3501             { "ipv6.routing.deprecated", PI_DEPRECATED, PI_NOTE,
3502                 "Routing header type is deprecated", EXPFILL }
3503         }
3504     };
3505
3506     /* Decode As handling */
3507     static build_valid_func ipv6_da_build_value[1] = {ipv6_value};
3508     static decode_as_value_t ipv6_da_values = {ipv6_prompt, 1, ipv6_da_build_value};
3509
3510     static decode_as_t ipv6_da = {"ipv6", "Network", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
3511                                   decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
3512
3513     static decode_as_t ipv6_hopopts_da = {"ipv6.hopopts", "Network", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
3514                                   decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
3515
3516     static decode_as_t ipv6_routing_da = {"ipv6.routing", "Network", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
3517                                   decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
3518
3519     static decode_as_t ipv6_fraghdr_da = {"ipv6.fraghdr", "Network", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
3520                                   decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
3521
3522     static decode_as_t ipv6_dstopts_da = {"ipv6.dstopts", "Network", "ip.proto", 1, 0, &ipv6_da_values, NULL, NULL,
3523                                   decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
3524
3525     module_t *ipv6_module;
3526     expert_module_t* expert_ipv6;
3527     expert_module_t* expert_ipv6_hopopts;
3528     expert_module_t* expert_ipv6_routing;
3529
3530     proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
3531     proto_register_field_array(proto_ipv6, hf_ipv6, array_length(hf_ipv6));
3532     proto_register_subtree_array(ett_ipv6, array_length(ett_ipv6));
3533     expert_ipv6 = expert_register_protocol(proto_ipv6);
3534     expert_register_field_array(expert_ipv6, ei_ipv6, array_length(ei_ipv6));
3535
3536     proto_ipv6_hopopts = proto_register_protocol("IPv6 Hop-by-Hop Option", "IPv6 Hop-by-Hop", "ipv6.hopopts");
3537     proto_register_field_array(proto_ipv6_hopopts, hf_ipv6_hopopts, array_length(hf_ipv6_hopopts));
3538     proto_register_subtree_array(ett_ipv6_hopopts, array_length(ett_ipv6_hopopts));
3539     expert_ipv6_hopopts = expert_register_protocol(proto_ipv6_hopopts);
3540     expert_register_field_array(expert_ipv6_hopopts, ei_ipv6_hopopts, array_length(ei_ipv6_hopopts));
3541
3542     proto_ipv6_routing = proto_register_protocol("Routing Header for IPv6", "IPv6 Routing", "ipv6.routing");
3543     proto_register_field_array(proto_ipv6_routing, hf_ipv6_routing, array_length(hf_ipv6_routing));
3544     proto_register_subtree_array(ett_ipv6_routing, array_length(ett_ipv6_routing));
3545     expert_ipv6_routing = expert_register_protocol(proto_ipv6_routing);
3546     expert_register_field_array(expert_ipv6_routing, ei_ipv6_routing, array_length(ei_ipv6_routing));
3547
3548     ipv6_routing_dissector_table = register_dissector_table("ipv6.routing.type", "IPv6 Routing Type",
3549                                                 proto_ipv6_routing, FT_UINT8, BASE_DEC);
3550
3551     proto_ipv6_routing_rt0 = proto_register_protocol_in_name_only("IPv6 Routing Type - Source Route", "Source Route", "ipv6.routing.type.rt0", proto_ipv6, FT_BYTES);
3552     proto_ipv6_routing_mipv6 = proto_register_protocol_in_name_only("IPv6 Routing Type - Type 2", "Type 2", "ipv6.routing.type.mipv6", proto_ipv6, FT_BYTES);
3553     proto_ipv6_routing_rpl = proto_register_protocol_in_name_only("IPv6 Routing Type - RPL Source Route", "RPL Source Route", "ipv6.routing.type.mipv6", proto_ipv6, FT_BYTES);
3554     proto_ipv6_routing_srh = proto_register_protocol_in_name_only("IPv6 Routing Types - Segment Routing", "Segment Routing", "ipv6.routing.type.srh", proto_ipv6, FT_BYTES);
3555
3556     proto_ipv6_fraghdr = proto_register_protocol("Fragment Header for IPv6", "IPv6 Fragment", "ipv6.fraghdr");
3557     proto_register_field_array(proto_ipv6_fraghdr, hf_ipv6_fraghdr, array_length(hf_ipv6_fraghdr));
3558     proto_register_subtree_array(ett_ipv6_fraghdr, array_length(ett_ipv6_fraghdr));
3559
3560     proto_ipv6_dstopts = proto_register_protocol("Destination Options for IPv6", "IPv6 Destination", "ipv6.dstopts");
3561     proto_register_field_array(proto_ipv6_dstopts, hf_ipv6_dstopts, array_length(hf_ipv6_dstopts));
3562     proto_register_subtree_array(ett_ipv6_dstopts, array_length(ett_ipv6_dstopts));
3563
3564     /* Register configuration options */
3565     ipv6_module = prefs_register_protocol(proto_ipv6, NULL);
3566     prefs_register_bool_preference(ipv6_module, "defragment",
3567                                    "Reassemble fragmented IPv6 datagrams",
3568                                    "Whether fragmented IPv6 datagrams should be reassembled",
3569                                    &ipv6_reassemble);
3570     prefs_register_bool_preference(ipv6_module, "summary_in_tree",
3571                                    "Show IPv6 summary in protocol tree",
3572                                    "Whether the IPv6 summary line should be shown in the protocol tree",
3573                                    &ipv6_summary_in_tree);
3574     prefs_register_bool_preference(ipv6_module, "use_geoip" ,
3575                                    "Enable IPv6 geolocation",
3576                                    "Whether to look up IPv6 addresses in each MaxMind database we have loaded",
3577                                    &ipv6_use_geoip);
3578
3579     /* RPL Strict Header Checking */
3580     prefs_register_bool_preference(ipv6_module, "perform_strict_rpl_srh_rfc_checking",
3581                                    "Perform strict checking for RPL Source Routing Headers (RFC 6554)",
3582                                    "Check that all RPL Source Routed packets conform to RFC 6554 and do not visit a node more than once",
3583                                    &g_ipv6_rpl_srh_strict_rfc_checking);
3584
3585     prefs_register_bool_preference(ipv6_module, "try_heuristic_first",
3586                                    "Try heuristic sub-dissectors first",
3587                                    "Try to decode a packet using an heuristic sub-dissector before using a sub-dissector registered to a specific port",
3588                                    &try_heuristic_first);
3589
3590     prefs_register_bool_preference(ipv6_module, "exthdr_under_root_protocol_tree",
3591                                    "Display IPv6 extension headers under the root protocol tree",
3592                                    "Whether to display IPv6 extension headers as a separate protocol or a sub-protocol of the IPv6 packet",
3593                                    &ipv6_exthdr_under_root);
3594
3595     prefs_register_bool_preference(ipv6_module, "exthdr_hide_len_oct_field",
3596                                    "Use a single field for IPv6 extension header length",
3597                                    "If enabled the Length field in octets will be hidden",
3598                                    &ipv6_exthdr_hide_len_oct_field);
3599
3600     prefs_register_bool_preference(ipv6_module, "tso_support",
3601                                     "Support packet-capture from IPv6 TSO-enabled hardware",
3602                                     "Whether to correct for TSO-enabled (TCP segmentation offload) hardware "
3603                                     "captures, such as spoofing the IPv6 packet length", &ipv6_tso_supported);
3604
3605     ipv6_handle = register_dissector("ipv6", dissect_ipv6, proto_ipv6);
3606     reassembly_table_register(&ipv6_reassembly_table,
3607                           &addresses_reassembly_table_functions);
3608     ipv6_tap = register_tap("ipv6");
3609
3610     register_decode_as(&ipv6_da);
3611     register_decode_as(&ipv6_hopopts_da);
3612     register_decode_as(&ipv6_routing_da);
3613     register_decode_as(&ipv6_fraghdr_da);
3614     register_decode_as(&ipv6_dstopts_da);
3615
3616     register_conversation_table(proto_ipv6, TRUE, ipv6_conversation_packet, ipv6_hostlist_packet);
3617     register_conversation_filter("ipv6", "IPv6", ipv6_filter_valid, ipv6_build_filter);
3618
3619     register_capture_dissector("ipv6", capture_ipv6, proto_ipv6);
3620 }
3621
3622 void
3623 proto_reg_handoff_ipv6(void)
3624 {
3625     dissector_handle_t ipv6_hopopts_handle;
3626     dissector_handle_t ipv6_routing_handle;
3627     dissector_handle_t ipv6_fraghdr_handle;
3628     dissector_handle_t ipv6_dstopts_handle;
3629     capture_dissector_handle_t ipv6_cap_handle;
3630     capture_dissector_handle_t ipv6_ext_cap_handle;
3631     dissector_handle_t h;
3632
3633     dissector_add_uint("ethertype", ETHERTYPE_IPv6, ipv6_handle);
3634     dissector_add_uint("erf.types.type", ERF_TYPE_IPV6, ipv6_handle);
3635     dissector_add_uint("ppp.protocol", PPP_IPV6, ipv6_handle);
3636     dissector_add_uint("ppp.protocol", ETHERTYPE_IPv6, ipv6_handle);
3637     dissector_add_uint("gre.proto", ETHERTYPE_IPv6, ipv6_handle);
3638     dissector_add_uint("ip.proto", IP_PROTO_IPV6, ipv6_handle);
3639     dissector_add_uint("null.type", BSD_AF_INET6_BSD, ipv6_handle);
3640     dissector_add_uint("null.type", BSD_AF_INET6_FREEBSD, ipv6_handle);
3641     dissector_add_uint("null.type", BSD_AF_INET6_DARWIN, ipv6_handle);
3642     dissector_add_uint("chdlc.protocol", ETHERTYPE_IPv6, ipv6_handle);
3643     dissector_add_uint("fr.nlpid", NLPID_IP6, ipv6_handle);
3644     dissector_add_uint("osinl.excl", NLPID_IP6, ipv6_handle);
3645     dissector_add_uint("x.25.spi", NLPID_IP6, ipv6_handle);
3646     dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_IPv6, ipv6_handle);
3647     dissector_add_uint("juniper.proto", JUNIPER_PROTO_IP6, ipv6_handle);
3648     dissector_add_uint("juniper.proto", JUNIPER_PROTO_MPLS_IP6, ipv6_handle);
3649     dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_IPV6, ipv6_handle);
3650     dissector_add_uint("mcc.proto", PW_ACH_TYPE_IPV6, ipv6_handle);
3651     dissector_add_uint("sflow_245.header_protocol", SFLOW_245_HEADER_IPv6, ipv6_handle);
3652     dissector_add_uint("wtap_encap", WTAP_ENCAP_RAW_IP6, ipv6_handle);
3653     dissector_add_uint("enc", BSD_AF_INET6_BSD, ipv6_handle);
3654     dissector_add_uint("vxlan.next_proto", VXLAN_IPV6, ipv6_handle);
3655     dissector_add_uint("nsh.next_proto", NSH_IPV6, ipv6_handle);
3656
3657     dissector_add_for_decode_as_with_preference("udp.port", ipv6_handle);
3658
3659     ipv6_hopopts_handle = create_dissector_handle(dissect_hopopts, proto_ipv6_hopopts);
3660     dissector_add_uint("ip.proto", IP_PROTO_HOPOPTS, ipv6_hopopts_handle);
3661
3662     ipv6_routing_handle = create_dissector_handle(dissect_routing6, proto_ipv6_routing);
3663     dissector_add_uint("ip.proto", IP_PROTO_ROUTING, ipv6_routing_handle);
3664
3665     ipv6_fraghdr_handle = create_dissector_handle(dissect_fraghdr, proto_ipv6_fraghdr);
3666     dissector_add_uint("ip.proto", IP_PROTO_FRAGMENT, ipv6_fraghdr_handle);
3667
3668     ipv6_dstopts_handle = create_dissector_handle(dissect_dstopts, proto_ipv6_dstopts);
3669     dissector_add_uint("ip.proto", IP_PROTO_DSTOPTS, ipv6_dstopts_handle);
3670
3671     ip_dissector_table = find_dissector_table("ip.proto");
3672
3673     ipv6_cap_handle = find_capture_dissector("ipv6");
3674     capture_dissector_add_uint("ethertype", ETHERTYPE_IPv6, ipv6_cap_handle);
3675     capture_dissector_add_uint("enc", BSD_AF_INET6_BSD, ipv6_cap_handle);
3676     capture_dissector_add_uint("null.bsd", BSD_AF_INET6_BSD, ipv6_cap_handle);
3677     capture_dissector_add_uint("null.bsd", BSD_AF_INET6_FREEBSD, ipv6_cap_handle);
3678     capture_dissector_add_uint("null.bsd", BSD_AF_INET6_DARWIN, ipv6_cap_handle);
3679     capture_dissector_add_uint("fr.nlpid", NLPID_IP6, ipv6_cap_handle);
3680
3681     ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_hopopts);
3682     capture_dissector_add_uint("ip.proto", IP_PROTO_HOPOPTS, ipv6_ext_cap_handle);
3683     ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_routing);
3684     capture_dissector_add_uint("ip.proto", IP_PROTO_ROUTING, ipv6_ext_cap_handle);
3685     ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_fraghdr);
3686     capture_dissector_add_uint("ip.proto", IP_PROTO_FRAGMENT, ipv6_ext_cap_handle);
3687     ipv6_ext_cap_handle = create_capture_dissector_handle(capture_ipv6_exthdr, proto_ipv6_dstopts);
3688     capture_dissector_add_uint("ip.proto", IP_PROTO_DSTOPTS, ipv6_ext_cap_handle);
3689
3690     h = create_dissector_handle(dissect_routing6_rt0, proto_ipv6_routing_rt0);
3691     dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_SOURCE_ROUTING, h);
3692     h = create_dissector_handle(dissect_routing6_mipv6, proto_ipv6_routing_mipv6);
3693     dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_MOBILE_IP, h);
3694     h = create_dissector_handle(dissect_routing6_rpl, proto_ipv6_routing_rpl);
3695     dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_RPL, h);
3696     h = create_dissector_handle(dissect_routing6_srh, proto_ipv6_routing_srh);
3697     dissector_add_uint("ipv6.routing.type", IPv6_RT_HEADER_SEGMENT_ROUTING, h);
3698 }
3699
3700 /*
3701  * Editor modelines
3702  *
3703  * Local Variables:
3704  * c-basic-offset: 4
3705  * tab-width: 8
3706  * indent-tabs-mode: nil
3707  * End:
3708  *
3709  * ex: set shiftwidth=4 tabstop=8 expandtab:
3710  * :indentSize=4:tabSize=8:noTabs=true:
3711  */