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