Add a separate hash table to the reassembly code for reassembled
[obnox/wireshark/wip.git] / packet-ipv6.c
1 /* packet-ipv6.c
2  * Routines for IPv6 packet disassembly
3  *
4  * $Id: packet-ipv6.c,v 1.79 2002/03/27 04:27:03 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #ifdef HAVE_SYS_SOCKET_h
36 #include <sys/socket.h>
37 #endif
38
39 #ifdef HAVE_NETINET_IN_H
40 # include <netinet/in.h>
41 #endif
42
43 #include <string.h>
44 #include <stdio.h>
45 #include <glib.h>
46 #include <epan/packet.h>
47 #include "packet-ip.h"
48 #include "packet-ipsec.h"
49 #include "packet-ipv6.h"
50 #include <epan/resolv.h>
51 #include "prefs.h"
52 #include "reassemble.h"
53 #include "ipproto.h"
54 #include "etypes.h"
55 #include "ppptypes.h"
56 #include "aftypes.h"
57 #include "nlpid.h"
58
59 /*
60  * NOTE: ipv6.nxt is not very useful as we will have chained header.
61  * now testing ipv6.final, but it raises SEGV.
62 #define TEST_FINALHDR
63  */
64
65 static int proto_ipv6 = -1;
66 static int hf_ipv6_version = -1;
67 static int hf_ipv6_class = -1;
68 static int hf_ipv6_flow = -1;
69 static int hf_ipv6_plen = -1;
70 static int hf_ipv6_nxt = -1;
71 static int hf_ipv6_hlim = -1;
72 static int hf_ipv6_src = -1;
73 static int hf_ipv6_dst = -1;
74 static int hf_ipv6_addr = -1;
75 #ifdef TEST_FINALHDR
76 static int hf_ipv6_final = -1;
77 #endif
78 static int hf_ipv6_fragments = -1;
79 static int hf_ipv6_fragment = -1;
80 static int hf_ipv6_fragment_overlap = -1;
81 static int hf_ipv6_fragment_overlap_conflict = -1;
82 static int hf_ipv6_fragment_multiple_tails = -1;
83 static int hf_ipv6_fragment_too_long_fragment = -1;
84 static int hf_ipv6_fragment_error = -1;
85
86 static int hf_ipv6_mipv6_type = -1;
87 static int hf_ipv6_mipv6_length = -1;
88 static int hf_ipv6_mipv6_a_flag = -1;
89 static int hf_ipv6_mipv6_h_flag = -1;
90 static int hf_ipv6_mipv6_r_flag = -1;
91 static int hf_ipv6_mipv6_d_flag = -1;
92 static int hf_ipv6_mipv6_m_flag = -1;
93 static int hf_ipv6_mipv6_b_flag = -1;
94 static int hf_ipv6_mipv6_prefix_length = -1;
95 static int hf_ipv6_mipv6_sequence_number = -1;
96 static int hf_ipv6_mipv6_life_time = -1;
97 static int hf_ipv6_mipv6_status = -1;
98 static int hf_ipv6_mipv6_refresh = -1;
99 static int hf_ipv6_mipv6_home_address = -1;
100 static int hf_ipv6_mipv6_sub_type = -1;
101 static int hf_ipv6_mipv6_sub_length = -1;
102 static int hf_ipv6_mipv6_sub_unique_ID = -1;
103 static int hf_ipv6_mipv6_sub_alternative_COA = -1;
104
105 static gint ett_ipv6 = -1;
106 static gint ett_ipv6_fragments = -1;
107 static gint ett_ipv6_fragment  = -1;
108
109 static dissector_handle_t data_handle;
110
111 /* Reassemble fragmented datagrams */
112 static gboolean ipv6_reassemble = FALSE;
113
114 #ifndef offsetof
115 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
116 #endif
117
118 /*
119  * defragmentation of IPv6
120  */
121 static GHashTable *ipv6_fragment_table = NULL;
122
123 static void
124 ipv6_reassemble_init(void)
125 {
126   fragment_table_init(&ipv6_fragment_table);
127 }
128
129 static int
130 dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree) {
131     struct ip6_rthdr rt;
132     guint len;
133     proto_tree *rthdr_tree;
134         proto_item *ti;
135     char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
136
137     tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
138     len = (rt.ip6r_len + 1) << 3;
139
140     if (tree) {
141         /* !!! specify length */
142         ti = proto_tree_add_text(tree, tvb, offset, len,
143             "Routing Header, Type %u", rt.ip6r_type);
144         rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
145
146         proto_tree_add_text(rthdr_tree, tvb,
147             offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
148             "Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
149         proto_tree_add_text(rthdr_tree, tvb,
150             offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
151             "Length: %u (%d bytes)", rt.ip6r_len, len);
152         proto_tree_add_text(rthdr_tree, tvb,
153             offset + offsetof(struct ip6_rthdr, ip6r_type), 1,
154             "Type: %u", rt.ip6r_type);
155         proto_tree_add_text(rthdr_tree, tvb,
156             offset + offsetof(struct ip6_rthdr, ip6r_segleft), 1,
157             "Segments left: %u", rt.ip6r_segleft);
158
159         if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
160             struct e_in6_addr *a;
161             int n;
162             struct ip6_rthdr0 *rt0;
163
164             tvb_memcpy(tvb, buf, offset, len);
165             rt0 = (struct ip6_rthdr0 *)buf;
166             for (a = rt0->ip6r0_addr, n = 0;
167                  a < (struct e_in6_addr *)(buf + len);
168                  a++, n++) {
169                 proto_tree_add_text(rthdr_tree, tvb,
170                     offset + offsetof(struct ip6_rthdr0, ip6r0_addr) + n * sizeof(struct e_in6_addr),
171                     sizeof(struct e_in6_addr),
172 #ifdef INET6
173                     "address %d: %s (%s)",
174                     n, get_hostname6(a), ip6_to_str(a)
175 #else
176                     "address %d: %s", n, ip6_to_str(a)
177 #endif
178                     );
179             }
180         }
181
182         /* decode... */
183     }
184
185     return len;
186 }
187
188 static int
189 dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
190     guint16 *offlg, guint32 *ident) {
191     struct ip6_frag frag;
192     int len;
193     proto_item *ti;
194     proto_tree *rthdr_tree;
195
196     tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
197     len = sizeof(frag);
198     frag.ip6f_offlg = ntohs(frag.ip6f_offlg);
199     *offlg = frag.ip6f_offlg;
200     *ident = frag.ip6f_ident;
201     if (check_col(pinfo->cinfo, COL_INFO)) {
202         col_add_fstr(pinfo->cinfo, COL_INFO,
203             "IPv6 fragment (nxt=%s (0x%02x) off=%u id=0x%x)",
204             ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
205             frag.ip6f_offlg & IP6F_OFF_MASK, frag.ip6f_ident);
206     }
207     if (tree) {
208            ti = proto_tree_add_text(tree, tvb, offset, len,
209                            "Fragmention Header");
210            rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
211
212            proto_tree_add_text(rthdr_tree, tvb,
213                          offset + offsetof(struct ip6_frag, ip6f_nxt), 1,
214                          "Next header: %s (0x%02x)",
215                          ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt);
216
217 #if 0
218            proto_tree_add_text(rthdr_tree, tvb,
219                          offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
220                          "Reserved: %u",
221                          frag.ip6f_reserved);
222 #endif
223
224            proto_tree_add_text(rthdr_tree, tvb,
225                          offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
226                          "Offset: %u",
227                          frag.ip6f_offlg & IP6F_OFF_MASK);
228
229            proto_tree_add_text(rthdr_tree, tvb,
230                          offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
231                          "More fragments: %s",
232                                 frag.ip6f_offlg & IP6F_MORE_FRAG ?
233                                 "Yes" : "No");
234
235            proto_tree_add_text(rthdr_tree, tvb,
236                          offset + offsetof(struct ip6_frag, ip6f_ident), 4,
237                          "Identification: 0x%08x",
238                          frag.ip6f_ident);
239     }
240     return len;
241 }
242
243 /* Binding Update flag description */
244 static const true_false_string ipv6_mipv6_bu_a_flag_value = {
245     "Binding Acknowledgement requested",
246     "Binding Acknowledgement not requested"
247 };
248 static const true_false_string ipv6_mipv6_bu_h_flag_value = {
249     "Home Registration",
250     "No Home Registration"
251 };
252 static const true_false_string ipv6_mipv6_bu_r_flag_value = {
253     "Router",
254     "Not a Router"
255 };
256 static const true_false_string ipv6_mipv6_bu_d_flag_value = {
257     "Perform Duplicate Address Detection",
258     "Do not perform Duplicate Address Detection"
259 };
260 static const true_false_string ipv6_mipv6_bu_m_flag_value = {
261     "MAP Registration",
262     "No MAP Registration"
263 };
264 static const true_false_string ipv6_mipv6_bu_b_flag_value = {
265     "Request for bicasting",
266     "Do not request for bicasting"
267 };
268
269 static int
270 dissect_mipv6_ba(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
271 {
272     guint8 status, len = 0;
273     const char *status_text;
274     gboolean sub_options = FALSE;
275
276     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
277         offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
278         tvb_get_guint8(tvb, offset + len),
279         "Option Type: %u (0x%02x) - Binding Acknowledgement",
280         tvb_get_guint8(tvb, offset + len),
281     tvb_get_guint8(tvb, offset + len));
282     len += IP6_MIPv6_OPTION_TYPE_LENGTH;
283     if (tvb_get_guint8(tvb, offset + len) > 11)
284         sub_options = TRUE;
285     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
286         IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
287     len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
288     status = tvb_get_guint8(tvb, offset + len);
289     switch (status) {
290     case BA_OK:
291         status_text = "- Binding Update accepted";
292         break;
293     case BA_REAS_UNSPEC:
294         status_text = "- Binding Update was rejected - Reason unspecified";
295         break;
296     case BA_ADMIN_PROH:
297         status_text = "- Binding Update was rejected - Administratively prohibited";
298         break;
299     case BA_INSUF_RES:
300         status_text = "- Binding Update was rejected - Insufficient resources";
301         break;
302     case BA_NO_HR:
303         status_text = "- Binding Update was rejected - Home registration not supported";
304         break;
305     case BA_NO_SUBNET:
306         status_text = "- Binding Update was rejected - Not home subnet";
307         break;
308     case BA_ERR_ID_LEN:
309         status_text = "- Binding Update was rejected - Incorrect interface identifier length";
310         break;
311     case BA_NO_HA:
312         status_text = "- Binding Update was rejected - Not home agent for this mobile node";
313         break;
314     case BA_DUPL_ADDR:
315         status_text = "- Binding Update was rejected - Duplicate Address Detection failed";
316         break;
317     default:
318         status_text = NULL;
319         break;
320     }
321     if (!status_text) {
322         if (status > 128)
323             status_text = "- Binding Update was rejected";
324         else
325             status_text = "";
326     }
327     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_status,
328         tvb, offset + len, IP6_MIPv6_STATUS_LENGTH,
329         tvb_get_guint8(tvb, offset + len),
330         "Status: %u %s", tvb_get_guint8(tvb, offset + len), status_text);
331     len += IP6_MIPv6_STATUS_LENGTH;
332     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number,
333         tvb, offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
334         tvb_get_ntohs(tvb, offset + len));
335     len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
336     if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
337         proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time,
338             tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
339             tvb_get_ntohl(tvb, offset + len),
340             "Life Time: %u - Infinity", tvb_get_ntohl(tvb, offset + len));
341     } else {
342         proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time,
343             tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
344             tvb_get_ntohl(tvb, offset + len));
345     }
346     len += IP6_MIPv6_LIFE_TIME_LENGTH;
347     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_refresh, tvb,
348         offset + len, IP6_MIPv6_REFRESH_LENGTH,
349         tvb_get_ntohl(tvb, offset + len));
350     len += IP6_MIPv6_REFRESH_LENGTH;
351     /* sub - options */
352     if (sub_options)
353         proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
354     return len;
355 }
356
357 static int
358 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
359 {
360     int len = 0;
361     gboolean sub_options = FALSE;
362
363     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset,
364         IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb, offset),
365         "Option Type: %u (0x%02x) - Binding Update",
366         tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset));
367     len += IP6_MIPv6_OPTION_TYPE_LENGTH;
368     if (tvb_get_guint8(tvb, offset + len) > 8)
369         sub_options = TRUE;
370     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
371         IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
372     len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
373     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_a_flag, tvb, offset + len,
374         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
375     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_h_flag, tvb, offset + len,
376         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
377     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_r_flag, tvb, offset + len,
378         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
379     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_d_flag, tvb, offset + len,
380         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
381     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_m_flag, tvb, offset + len,
382         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
383     proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_b_flag, tvb, offset + len,
384         IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
385     len += IP6_MIPv6_FLAGS_LENGTH;
386     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_prefix_length, tvb,
387         offset + len,
388         IP6_MIPv6_PREFIX_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
389     len += IP6_MIPv6_PREFIX_LENGTH_LENGTH;
390     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb,
391         offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
392         tvb_get_ntohs(tvb, offset + len));
393     len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
394     if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
395     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
396         offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
397         tvb_get_ntohl(tvb, offset + len), "Life Time: %u - Infinity",
398         tvb_get_ntohl(tvb, offset + len));
399     } else {
400         proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
401             offset + len, IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,
402             offset + len));
403     }
404     len += IP6_MIPv6_LIFE_TIME_LENGTH;
405     /* sub - options */
406     if (sub_options)
407         proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
408     return len;
409 }
410
411 static int
412 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
413 {
414     int len = 0;
415     gboolean sub_options = FALSE;
416
417     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
418         offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
419         tvb_get_guint8(tvb, offset + len),
420         "Option Type: %u (0x%02x) - Home Address",
421         tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
422     len += IP6_MIPv6_OPTION_TYPE_LENGTH;
423     if (tvb_get_guint8(tvb, offset + len) > 16)
424         sub_options = TRUE;
425     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
426         IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
427     len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
428     proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_home_address, tvb,
429         offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH,
430         tvb_get_ptr(tvb, offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH));
431     len += IP6_MIPv6_HOME_ADDRESS_LENGTH;
432     /* sub - options */
433     if (sub_options)
434         proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
435     return len;
436 }
437
438 static int
439 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
440 {
441     int len = 0;
442     gboolean sub_options = FALSE;
443
444     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
445         offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
446         tvb_get_guint8(tvb, offset + len),
447         "Option Type: %u (0x%02x) - Binding Request",
448         tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
449     len += IP6_MIPv6_OPTION_TYPE_LENGTH;
450     if (tvb_get_guint8(tvb, offset + len) > 0)
451         sub_options = TRUE;
452     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
453         IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
454     len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
455     /* sub - options */
456     if (sub_options)
457         proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
458     return len;
459 }
460
461 static int
462 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
463 {
464     int len = 0;
465                         
466     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
467         offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
468         tvb_get_guint8(tvb, offset + len),
469         "Sub-Option Type: %u (0x%02x) - Unique Identifier Sub-Option",
470         tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
471     len += IP6_MIPv6_SUB_TYPE_LENGTH;
472     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
473         offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
474         tvb_get_guint8(tvb, offset + len));
475     len += IP6_MIPv6_SUB_LENGTH_LENGTH;
476     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_unique_ID, tvb,
477         offset + len, IP6_MIPv6_SUB_UNIQUE_ID_LENGTH,
478         tvb_get_ntohs(tvb, offset + len));
479     len += IP6_MIPv6_SUB_UNIQUE_ID_LENGTH;
480     return len;
481 }
482
483 static int
484 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
485 {
486     int len = 0;
487
488     proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_type, tvb,
489         offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
490         tvb_get_guint8(tvb, offset + len),
491         "Sub-Option Type: %u (0x%02x) - Alternative Care Of Address",
492         tvb_get_guint8(tvb, offset + len),
493     tvb_get_guint8(tvb, offset + len));
494     len += IP6_MIPv6_SUB_TYPE_LENGTH;
495     proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
496         offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
497         tvb_get_guint8(tvb, offset + len));
498     len += IP6_MIPv6_SUB_LENGTH_LENGTH;
499     proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_sub_alternative_COA, tvb,
500         offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH,
501         tvb_get_ptr(tvb, offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH));
502     len += IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH;
503     return len;
504 }
505
506 static const value_string rtalertvals[] = {
507     { IP6OPT_RTALERT_MLD, "MLD" },
508     { IP6OPT_RTALERT_RSVP, "RSVP" },
509     { 0, NULL },
510 };
511
512 static int
513 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, char *optname)
514 {
515     struct ip6_ext ext;
516     int len;
517     proto_tree *dstopt_tree;
518     proto_item *ti;
519     gint p;
520     guint8 tmp;
521     int mip_offset = 0, delta = 0;
522
523     tvb_memcpy(tvb, (guint8 *)&ext, offset, sizeof(ext));
524     len = (ext.ip6e_len + 1) << 3;
525
526     if (tree) {
527         /* !!! specify length */
528         ti = proto_tree_add_text(tree, tvb, offset, len, "%s Header ", optname);
529
530         dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
531
532         proto_tree_add_text(dstopt_tree, tvb,
533             offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
534             "Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt), ext.ip6e_nxt);
535         proto_tree_add_text(dstopt_tree, tvb,
536             offset + offsetof(struct ip6_ext, ip6e_len), 1,
537             "Length: %u (%d bytes)", ext.ip6e_len, len);
538
539         mip_offset = offset;
540         mip_offset += 2;
541
542         p = offset + 2;
543
544         while (p < offset + len) {
545             switch (tvb_get_guint8(tvb, p)) {
546             case IP6OPT_PAD1:
547                 proto_tree_add_text(dstopt_tree, tvb, p, 1, "Pad1");
548                 p++;
549                 mip_offset++;
550                 break;
551             case IP6OPT_PADN:
552                 tmp = tvb_get_guint8(tvb, p + 1);
553                 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
554                     "PadN: %u bytes", tmp + 2);
555                 p += tmp;
556                 p += 2;
557                 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
558                 break;
559             case IP6OPT_JUMBO:
560                 tmp = tvb_get_guint8(tvb, p + 1);
561                 if (tmp == 4) {
562                     proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
563                         "Jumbo payload: %u (%u bytes)",
564                         tvb_get_ntohl(tvb, p + 2), tmp + 2);
565                 } else {
566                     proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
567                         "Jumbo payload: Invalid length (%u bytes)",
568                         tmp + 2);
569                 }
570                 p += tmp;
571                 p += 2;
572                 mip_offset += tvb_get_guint8(tvb, mip_offset+1)+2;
573                 break;
574             case IP6OPT_RTALERT:
575               {
576                 char *rta;
577
578                 tmp = tvb_get_guint8(tvb, p + 1);
579                 if (tmp == 2) {
580                     rta = val_to_str(tvb_get_ntohs(tvb, p + 2), rtalertvals,
581                         "Unknown");
582                 } else
583                     rta = "Invalid length";
584                 ti = proto_tree_add_text(dstopt_tree, tvb, p , tmp + 2,
585                     "Router alert: %s (%u bytes)", rta, tmp + 2);
586                 p += tmp;
587                 p += 2;
588                 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
589                 break;
590               }
591             case IP6OPT_BINDING_UPDATE :
592                 delta = dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
593                 p += delta;
594                 mip_offset += delta;
595                 break;
596             case IP6OPT_BINDING_ACK :
597                 delta = dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
598                 p += delta;
599                 mip_offset += delta;
600                 break;
601             case IP6OPT_HOME_ADDRESS :
602                 delta = dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
603                 p += delta;
604                 mip_offset += delta;
605                 break;
606             case IP6OPT_BINDING_REQUEST :
607                 delta = dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
608                 p += delta;
609                 mip_offset += delta;
610                 break;
611             case IP6OPT_MIPv6_UNIQUE_ID_SUB :
612                 delta = dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
613                 p += delta;
614                 mip_offset += delta;
615                 break;
616             case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
617                 delta = dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
618                 p += delta;
619                 mip_offset += delta;
620                 break;
621             default:
622                 p = offset + len;
623                 break;
624             }
625         }
626
627         /* decode... */
628     }
629     return len;
630 }
631
632 static int
633 dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree)
634 {
635     return dissect_opts(tvb, offset, tree, "Hop-by-hop Option");
636 }
637
638 static int
639 dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree)
640 {
641     return dissect_opts(tvb, offset, tree, "Destination Option");
642 }
643
644 static void
645 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
646 {
647   proto_tree *ipv6_tree = NULL;
648   proto_item *ti;
649   guint8 nxt;
650   int advance;
651   int poffset;
652   guint16 plen;
653   gboolean frag;
654   guint16 offlg;
655   guint32 ident;
656   int offset;
657   fragment_data *ipfd_head;
658   tvbuff_t   *next_tvb;
659   gboolean update_col_info = TRUE;
660   gboolean save_fragmented;
661
662   struct ip6_hdr ipv6;
663
664   if (check_col(pinfo->cinfo, COL_PROTOCOL))
665     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPv6");
666   if (check_col(pinfo->cinfo, COL_INFO))
667     col_clear(pinfo->cinfo, COL_INFO);
668
669   offset = 0;
670   tvb_memcpy(tvb, (guint8 *)&ipv6, offset, sizeof(ipv6));
671
672   pinfo->ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
673
674   /* Get the payload length */
675   plen = ntohs(ipv6.ip6_plen);
676
677   /* Adjust the length of this tvbuff to include only the IPv6 datagram. */
678   set_actual_length(tvb, plen + sizeof (struct ip6_hdr));
679
680   SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
681   SET_ADDRESS(&pinfo->src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
682   SET_ADDRESS(&pinfo->net_dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
683   SET_ADDRESS(&pinfo->dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
684
685   if (tree) {
686     /* !!! specify length */
687     ti = proto_tree_add_item(tree, proto_ipv6, tvb, offset, 40, FALSE);
688     ipv6_tree = proto_item_add_subtree(ti, ett_ipv6);
689
690     /* !!! warning: version also contains 4 Bit priority */
691     proto_tree_add_uint(ipv6_tree, hf_ipv6_version, tvb,
692                 offset + offsetof(struct ip6_hdr, ip6_vfc), 1,
693                 (ipv6.ip6_vfc >> 4) & 0x0f);
694
695     proto_tree_add_uint(ipv6_tree, hf_ipv6_class, tvb,
696                 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
697                 (guint8)((ntohl(ipv6.ip6_flow) >> 20) & 0xff));
698
699     /*
700      * there should be no alignment problems for ip6_flow, since it's the first
701      * guint32 in the ipv6 struct
702      */
703     proto_tree_add_uint_format(ipv6_tree, hf_ipv6_flow, tvb,
704                 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
705                 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK),
706                 "Flowlabel: 0x%05lx",
707                 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK));
708
709     proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, tvb,
710                 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
711                 plen);
712
713     proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, tvb,
714                 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
715                 ipv6.ip6_nxt,
716                 "Next header: %s (0x%02x)",
717                 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
718
719     proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, tvb,
720                 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
721                 ipv6.ip6_hlim);
722
723     proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
724                                offset + offsetof(struct ip6_hdr, ip6_src), 16,
725                                ipv6.ip6_src.s6_addr8);
726     proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
727                                offset + offsetof(struct ip6_hdr, ip6_dst), 16,
728                                ipv6.ip6_dst.s6_addr8);
729
730     proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_src, tvb,
731                 offset + offsetof(struct ip6_hdr, ip6_src), 16,
732                 (guint8 *)&ipv6.ip6_src,
733 #ifdef INET6
734                 "Source address: %s (%s)",
735                 get_hostname6(&ipv6.ip6_src),
736 #else
737                 "Source address: %s",
738 #endif
739                 ip6_to_str(&ipv6.ip6_src));
740
741     proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_dst, tvb,
742                 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
743                 (guint8 *)&ipv6.ip6_dst,
744 #ifdef INET6
745                 "Destination address: %s (%s)",
746                 get_hostname6(&ipv6.ip6_dst),
747 #else
748                 "Destination address: %s",
749 #endif
750                 ip6_to_str(&ipv6.ip6_dst));
751   }
752
753   /* start of the new header (could be a extension header) */
754   poffset = offset + offsetof(struct ip6_hdr, ip6_nxt);
755   nxt = tvb_get_guint8(tvb, poffset);
756   offset += sizeof(struct ip6_hdr);
757   offlg = 0;
758   ident = 0;
759
760 /* start out assuming this isn't fragmented */
761   frag = FALSE;
762
763 again:
764    switch (nxt) {
765    case IP_PROTO_HOPOPTS:
766                         advance = dissect_hopopts(tvb, offset, tree);
767                         nxt = tvb_get_guint8(tvb, offset);
768                         poffset = offset;
769                         offset += advance;
770                         plen -= advance;
771                         goto again;
772     case IP_PROTO_ROUTING:
773                         advance = dissect_routing6(tvb, offset, tree);
774                         nxt = tvb_get_guint8(tvb, offset);
775                         poffset = offset;
776                         offset += advance;
777                         plen -= advance;
778                         goto again;
779     case IP_PROTO_FRAGMENT:
780                         frag = TRUE;
781                         advance = dissect_frag6(tvb, offset, pinfo, tree,
782                             &offlg, &ident);
783                         nxt = tvb_get_guint8(tvb, offset);
784                         poffset = offset;
785                         offset += advance;
786                         plen -= advance;
787                         goto again;
788     case IP_PROTO_AH:
789                         advance = dissect_ah_header(
790                                   tvb_new_subset(tvb, offset, -1, -1),
791                                   pinfo, tree, NULL, NULL);
792                         nxt = tvb_get_guint8(tvb, offset);
793                         poffset = offset;
794                         offset += advance;
795                         plen -= advance;
796                         goto again;
797     case IP_PROTO_DSTOPTS:
798                         advance = dissect_dstopts(tvb, offset, tree);
799                         nxt = tvb_get_guint8(tvb, offset);
800                         poffset = offset;
801                         offset += advance;
802                         plen -= advance;
803                         goto again;
804     }
805
806 #ifdef TEST_FINALHDR
807   proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, tvb, poffset, 1, nxt);
808 #endif
809
810   /* If ipv6_reassemble is on, this is a fragment, and we have all the data
811    * in the fragment, then just add the fragment to the hashtable.
812    */
813   save_fragmented = pinfo->fragmented;
814   if (ipv6_reassemble && frag && tvb_reported_length(tvb) <= tvb_length(tvb)) {
815     ipfd_head = fragment_add(tvb, offset, pinfo, ident,
816                              ipv6_fragment_table,
817                              offlg & IP6F_OFF_MASK,
818                              plen,
819                              offlg & IP6F_MORE_FRAG);
820
821     if (ipfd_head != NULL) {
822       fragment_data *ipfd;
823       proto_tree *ft = NULL;
824       proto_item *fi = NULL;
825
826       /* OK, we have the complete reassembled payload.
827          Allocate a new tvbuff, referring to the reassembled payload. */
828       next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
829         ipfd_head->datalen);
830
831       /* Add the tvbuff to the list of tvbuffs to which the tvbuff we
832          were handed refers, so it'll get cleaned up when that tvbuff
833          is cleaned up. */
834       tvb_set_child_real_data_tvbuff(tvb, next_tvb);
835
836       /* Add the defragmented data to the data source list. */
837       add_new_data_source(pinfo->fd, next_tvb, "Reassembled IPv6");
838
839       /* It's not fragmented. */
840       pinfo->fragmented = FALSE;
841
842       /* show all fragments */
843       fi = proto_tree_add_item(ipv6_tree, hf_ipv6_fragments,
844                 next_tvb, 0, -1, FALSE);
845       ft = proto_item_add_subtree(fi, ett_ipv6_fragments);
846       for (ipfd = ipfd_head->next; ipfd; ipfd = ipfd->next){
847         if (ipfd->flags & (FD_OVERLAP|FD_OVERLAPCONFLICT
848                           |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
849           /* this fragment has some flags set, create a subtree
850            * for it and display the flags.
851            */
852           proto_tree *fet = NULL;
853           proto_item *fei = NULL;
854           int hf;
855
856           if (ipfd->flags & (FD_OVERLAPCONFLICT
857                       |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
858             hf = hf_ipv6_fragment_error;
859           } else {
860             hf = hf_ipv6_fragment;
861           }
862           fei = proto_tree_add_none_format(ft, hf,
863                    next_tvb, ipfd->offset, ipfd->len,
864                    "Frame:%u payload:%u-%u",
865                    ipfd->frame,
866                    ipfd->offset,
867                    ipfd->offset+ipfd->len-1
868           );
869           fet = proto_item_add_subtree(fei, ett_ipv6_fragment);
870           if (ipfd->flags&FD_OVERLAP) {
871             proto_tree_add_boolean(fet,
872                  hf_ipv6_fragment_overlap, next_tvb, 0, 0,
873                  TRUE);
874           }
875           if (ipfd->flags&FD_OVERLAPCONFLICT) {
876             proto_tree_add_boolean(fet,
877                  hf_ipv6_fragment_overlap_conflict, next_tvb, 0, 0,
878                  TRUE);
879           }
880           if (ipfd->flags&FD_MULTIPLETAILS) {
881             proto_tree_add_boolean(fet,
882                  hf_ipv6_fragment_multiple_tails, next_tvb, 0, 0,
883                  TRUE);
884           }
885           if (ipfd->flags&FD_TOOLONGFRAGMENT) {
886             proto_tree_add_boolean(fet,
887                  hf_ipv6_fragment_too_long_fragment, next_tvb, 0, 0,
888                  TRUE);
889           }
890         } else {
891           /* nothing of interest for this fragment */
892           proto_tree_add_none_format(ft, hf_ipv6_fragment,
893                    next_tvb, ipfd->offset, ipfd->len,
894                    "Frame:%u payload:%u-%u",
895                    ipfd->frame,
896                    ipfd->offset,
897                    ipfd->offset+ipfd->len-1
898           );
899         }
900       }
901       if (ipfd_head->flags & (FD_OVERLAPCONFLICT
902                         |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
903         if (check_col(pinfo->cinfo, COL_INFO)) {
904           col_set_str(pinfo->cinfo, COL_INFO, "[Illegal fragments]");
905           update_col_info = FALSE;
906         }
907       }
908     } else {
909       /* We don't have the complete reassembled payload. */
910       next_tvb = NULL;
911     }
912   } else {
913     /* If this is the first fragment, dissect its contents, otherwise
914        just show it as a fragment.
915
916        XXX - if we eventually don't save the reassembled contents of all
917        fragmented datagrams, we may want to always reassemble. */
918     if (offlg & IP6F_OFF_MASK) {
919       /* Not the first fragment - don't dissect it. */
920       next_tvb = NULL;
921     } else {
922       /* First fragment, or not fragmented.  Dissect what we have here. */
923
924       /* Get a tvbuff for the payload. */
925       next_tvb = tvb_new_subset(tvb, offset, -1, -1);
926
927       /*
928        * If this is the first fragment, but not the only fragment,
929        * tell the next protocol that.
930        */
931       if (offlg & IP6F_MORE_FRAG)
932         pinfo->fragmented = TRUE;
933       else
934         pinfo->fragmented = FALSE;
935     }
936   }
937
938   if (next_tvb == NULL) {
939     /* Just show this as a fragment. */
940     /* COL_INFO was filled in by "dissect_frag6()" */
941     call_dissector(data_handle,tvb_new_subset(tvb, offset, -1,tvb_reported_length_remaining(tvb,offset)),pinfo, tree);
942
943     /* As we haven't reassembled anything, we haven't changed "pi", so
944        we don't have to restore it. */
945     pinfo->fragmented = save_fragmented;
946     return;
947   }
948
949   /* do lookup with the subdissector table */
950   if (!dissector_try_port(ip_dissector_table, nxt, next_tvb, pinfo, tree)) {
951     /* Unknown protocol */
952     if (check_col(pinfo->cinfo, COL_INFO))
953       col_add_fstr(pinfo->cinfo, COL_INFO, "%s (0x%02x)", ipprotostr(nxt),nxt);
954     call_dissector(data_handle,next_tvb, pinfo, tree);
955   }
956   pinfo->fragmented = save_fragmented;
957 }
958
959 static void
960 dissect_ipv6_none(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
961 {
962     if (hf_ipv6_mipv6_length != -1) {
963         if (check_col(pinfo->cinfo, COL_INFO))
964             col_add_fstr(pinfo->cinfo, COL_INFO, "Mobile IPv6 Destination Option");
965     } else {
966         if (check_col(pinfo->cinfo, COL_INFO))
967             col_add_fstr(pinfo->cinfo, COL_INFO, "IPv6 no next header");
968     }
969     /* XXX - dissect the payload as padding? */
970 }
971
972 void
973 proto_register_ipv6(void)
974 {
975   static hf_register_info hf[] = {
976     { &hf_ipv6_version,
977       { "Version",              "ipv6.version",
978                                 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
979     { &hf_ipv6_class,
980       { "Traffic class",        "ipv6.class",
981                                 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
982     { &hf_ipv6_flow,
983       { "Flowlabel",            "ipv6.flow",
984                                 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
985     { &hf_ipv6_plen,
986       { "Payload length",       "ipv6.plen",
987                                 FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
988     { &hf_ipv6_nxt,
989       { "Next header",          "ipv6.nxt",
990                                 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
991     { &hf_ipv6_hlim,
992       { "Hop limit",            "ipv6.hlim",
993                                 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
994     { &hf_ipv6_src,
995       { "Source",               "ipv6.src",
996                                 FT_IPv6, BASE_NONE, NULL, 0x0,
997                                 "Source IPv6 Address", HFILL }},
998     { &hf_ipv6_dst,
999       { "Destination",          "ipv6.dst",
1000                                 FT_IPv6, BASE_NONE, NULL, 0x0,
1001                                 "Destination IPv6 Address", HFILL }},
1002     { &hf_ipv6_addr,
1003       { "Address",              "ipv6.addr",
1004                                 FT_IPv6, BASE_NONE, NULL, 0x0,
1005                                 "Source or Destination IPv6 Address", HFILL }},
1006
1007     { &hf_ipv6_fragment_overlap,
1008       { "Fragment overlap",     "ipv6.fragment.overlap",
1009                                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1010                                 "Fragment overlaps with other fragments", HFILL }},
1011
1012     { &hf_ipv6_fragment_overlap_conflict,
1013       { "Conflicting data in fragment overlap", "ipv6.fragment.overlap.conflict",
1014                                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1015                                 "Overlapping fragments contained conflicting data", HFILL }},
1016
1017     { &hf_ipv6_fragment_multiple_tails,
1018       { "Multiple tail fragments found", "ipv6.fragment.multipletails",
1019                                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1020                                 "Several tails were found when defragmenting the packet", HFILL }},
1021
1022     { &hf_ipv6_fragment_too_long_fragment,
1023       { "Fragment too long",    "ipv6.fragment.toolongfragment",
1024                                 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1025                                 "Fragment contained data past end of packet", HFILL }},
1026
1027     { &hf_ipv6_fragment_error,
1028       { "Defragmentation error", "ipv6.fragment.error",
1029                                 FT_NONE, BASE_NONE, NULL, 0x0,
1030                                 "Defragmentation error due to illegal fragments", HFILL }},
1031
1032     { &hf_ipv6_fragment,
1033       { "IPv6 Fragment",        "ipv6.fragment",
1034                                 FT_NONE, BASE_NONE, NULL, 0x0,
1035                                 "IPv6 Fragment", HFILL }},
1036
1037     { &hf_ipv6_fragments,
1038       { "IPv6 Fragments",       "ipv6.fragments",
1039                                 FT_NONE, BASE_NONE, NULL, 0x0,
1040                                 "IPv6 Fragments", HFILL }},
1041
1042     /* BT INSERT BEGIN */
1043     { &hf_ipv6_mipv6_type,
1044       { "Option Type ",         "ipv6.mipv6_type",
1045                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1046                                 "", HFILL }},
1047     { &hf_ipv6_mipv6_length,
1048       { "Option Length ",               "ipv6.mipv6_length",
1049                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1050                                 "", HFILL }},
1051     { &hf_ipv6_mipv6_a_flag,
1052       { "Acknowledge (A) ",             "ipv6.mipv6_a_flag",
1053                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_a_flag_value),
1054                                 IP6_MIPv6_BU_A_FLAG,
1055                                 "", HFILL }},
1056     { &hf_ipv6_mipv6_h_flag,
1057       { "Home Registration (H) ",               "ipv6.mipv6_h_flag",
1058                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_h_flag_value),
1059                                 IP6_MIPv6_BU_H_FLAG,
1060                                 "", HFILL }},
1061     { &hf_ipv6_mipv6_r_flag,
1062       { "Router (R) ",          "ipv6.mipv6_r_flag",
1063                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_r_flag_value),
1064                                 IP6_MIPv6_BU_R_FLAG,
1065                                 "", HFILL }},
1066     { &hf_ipv6_mipv6_d_flag,
1067       { "Duplicate Address Detection (D) ",             "ipv6.mipv6_d_flag",
1068                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_d_flag_value),
1069                                 IP6_MIPv6_BU_D_FLAG,
1070                                 "", HFILL }},
1071     { &hf_ipv6_mipv6_m_flag,
1072       { "MAP Registration (M) ",                "ipv6.mipv6_m_flag",
1073                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_m_flag_value),
1074                                 IP6_MIPv6_BU_M_FLAG,
1075                                 "", HFILL }},
1076     { &hf_ipv6_mipv6_b_flag,
1077       { "Bicasting all (B) ",           "ipv6.mipv6_b_flag",
1078                                 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_b_flag_value),
1079                                 IP6_MIPv6_BU_B_FLAG,
1080                                 "", HFILL }},
1081     { &hf_ipv6_mipv6_prefix_length,
1082       { "Prefix Length ",               "ipv6.mipv6_prefix_length",
1083                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1084                                 "", HFILL }},
1085     { &hf_ipv6_mipv6_sequence_number,
1086       { "Sequence Number ",             "ipv6.mipv6_sequence_number",
1087                                 FT_UINT16, BASE_DEC, NULL, 0x0,
1088                                 "", HFILL }},
1089     { &hf_ipv6_mipv6_life_time,
1090       { "Life Time ",           "ipv6.mipv6_life_time",
1091                                 FT_UINT32, BASE_DEC, NULL, 0x0,
1092                                 "", HFILL }},
1093     { &hf_ipv6_mipv6_status,
1094       { "Status ",              "ipv6.mipv6_status",
1095                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1096                                 "", HFILL }},
1097     { &hf_ipv6_mipv6_refresh,
1098       { "Refresh ",             "ipv6.mipv6_refresh",
1099                                 FT_UINT32, BASE_DEC, NULL, 0x0,
1100                                 "", HFILL }},
1101     { &hf_ipv6_mipv6_home_address,
1102       { "Home Address ",                "ipv6.mipv6_home_address",
1103                                 FT_IPv6, BASE_HEX, NULL, 0x0,
1104                                 "", HFILL }},
1105     { &hf_ipv6_mipv6_sub_type,
1106       { "Sub-Option Type ",             "ipv6.mipv6_sub_type",
1107                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1108                                 "", HFILL }},
1109     { &hf_ipv6_mipv6_sub_length,
1110       { "Sub-Option Length ",           "ipv6.mipv6_sub_length",
1111                                 FT_UINT8, BASE_DEC, NULL, 0x0,
1112                                 "", HFILL }},
1113     { &hf_ipv6_mipv6_sub_unique_ID,
1114       { "Unique Identifier ",           "ipv6.mipv6_sub_unique_ID",
1115                                 FT_UINT16, BASE_DEC, NULL, 0x0,
1116                                 "", HFILL }},
1117     { &hf_ipv6_mipv6_sub_alternative_COA,
1118       { "Alternative Care of Address ",         "ipv6.mipv6_sub_alternative_COA",
1119                                 FT_IPv6, BASE_HEX, NULL, 0x0,
1120                                 "", HFILL }},
1121
1122     /* BT INSERT END */
1123 #ifdef TEST_FINALHDR
1124     { &hf_ipv6_final,
1125       { "Final next header",    "ipv6.final",
1126                                 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1127 #endif
1128   };
1129   static gint *ett[] = {
1130     &ett_ipv6,
1131     &ett_ipv6_fragments,
1132     &ett_ipv6_fragment,
1133   };
1134   module_t *ipv6_module;
1135
1136   proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
1137   proto_register_field_array(proto_ipv6, hf, array_length(hf));
1138   proto_register_subtree_array(ett, array_length(ett));
1139
1140   /* Register configuration options */
1141   ipv6_module = prefs_register_protocol(proto_ipv6, NULL);
1142   prefs_register_bool_preference(ipv6_module, "defragment",
1143         "Reassemble fragmented IPv6 datagrams",
1144         "Whether fragmented IPv6 datagrams should be reassembled",
1145         &ipv6_reassemble);
1146
1147   register_dissector("ipv6", dissect_ipv6, proto_ipv6);
1148   register_init_routine(ipv6_reassemble_init);
1149 }
1150
1151 void
1152 proto_reg_handoff_ipv6(void)
1153 {
1154   dissector_handle_t ipv6_handle, ipv6_none_handle;
1155
1156   data_handle = find_dissector("data");
1157   ipv6_handle = find_dissector("ipv6");
1158   dissector_add("ethertype", ETHERTYPE_IPv6, ipv6_handle);
1159   dissector_add("ppp.protocol", PPP_IPV6, ipv6_handle);
1160   dissector_add("ppp.protocol", ETHERTYPE_IPv6, ipv6_handle);
1161   dissector_add("gre.proto", ETHERTYPE_IPv6, ipv6_handle);
1162   dissector_add("ip.proto", IP_PROTO_IPV6, ipv6_handle);
1163   ipv6_none_handle = create_dissector_handle(dissect_ipv6_none, proto_ipv6);
1164   dissector_add("ip.proto", IP_PROTO_NONE, ipv6_none_handle);
1165   dissector_add("null.type", BSD_AF_INET6_BSD, ipv6_handle);
1166   dissector_add("null.type", BSD_AF_INET6_FREEBSD, ipv6_handle);
1167   dissector_add("chdlctype", ETHERTYPE_IPv6, ipv6_handle);
1168   dissector_add("fr.ietf", NLPID_IP6, ipv6_handle);
1169   dissector_add("x.25.spi", NLPID_IP6, ipv6_handle);
1170 }