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