2 * Routines for IPv6 packet disassembly
4 * $Id: packet-ipv6.c,v 1.59 2001/06/18 02:17:47 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
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.
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.
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.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
36 #ifdef HAVE_SYS_SOCKET_h
37 #include <sys/socket.h>
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.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"
55 #include "reassemble.h"
62 * NOTE: ipv6.nxt is not very useful as we will have chained header.
63 * now testing ipv6.final, but it raises SEGV.
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;
78 static int hf_ipv6_final = -1;
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;
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;
109 static gint ett_ipv6 = -1;
110 static gint ett_ipv6_fragments = -1;
111 static gint ett_ipv6_fragment = -1;
113 /* Reassemble fragmented datagrams */
114 static gboolean ipv6_reassemble = FALSE;
117 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
121 * defragmentation of IPv6
123 static GHashTable *ipv6_fragment_table = NULL;
126 ipv6_reassemble_init(void)
128 fragment_table_init(&ipv6_fragment_table);
132 dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree) {
135 proto_tree *rthdr_tree;
137 char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
139 tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
140 len = (rt.ip6r_len + 1) << 3;
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);
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);
161 if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
162 struct e_in6_addr *a;
164 struct ip6_rthdr0 *rt0;
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);
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),
175 "address %d: %s (%s)",
176 n, get_hostname6(a), ip6_to_str(a)
178 "address %d: %s", n, ip6_to_str(a)
191 dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
192 guint16 *offlg, guint32 *ident) {
193 struct ip6_frag frag;
196 proto_tree *rthdr_tree;
198 tvb_memcpy(tvb, (guint8 *)&frag, offset, 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);
210 ti = proto_tree_add_text(tree, tvb, offset, len,
211 "Fragmention Header");
212 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
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);
220 proto_tree_add_text(rthdr_tree, tvb,
221 offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
226 proto_tree_add_text(rthdr_tree, tvb,
227 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
229 frag.ip6f_offlg & IP6F_OFF_MASK);
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 ?
237 proto_tree_add_text(rthdr_tree, tvb,
238 offset + offsetof(struct ip6_frag, ip6f_ident), 4,
239 "Identification: 0x%08x",
245 /* BT INSERT BEGIN */
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;
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)
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);
265 strcpy(status_text,"- Binding Update accepted");
268 strcpy(status_text,"- Binding Update was rejected - Reason unspecified");
271 strcpy(status_text,"- Binding Update was rejected - Administratively prohibited");
274 strcpy(status_text,"- Binding Update was rejected - Insufficient resources");
277 strcpy(status_text,"- Binding Update was rejected - Home registration not supported");
280 strcpy(status_text,"- Binding Update was rejected - Not home subnet");
283 strcpy(status_text,"- Binding Update was rejected - Incorrect interface identifier length");
286 strcpy(status_text,"- Binding Update was rejected - Not home agent for this mobile node");
289 strcpy(status_text,"- Binding Update was rejected - Duplicate Address Detection failed");
292 strcpy(status_text,"");
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)
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));
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));
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;
321 proto_tree_add_text(dstopt_tree, tvb, offset+len, 1, "Sub-Options");
327 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
329 gboolean sub_options=FALSE;
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)
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)
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));
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));
370 len+=IP6_MIPv6_LIFE_TIME_LENGTH;
374 proto_tree_add_text(dstopt_tree, tvb, offset+len, 1, "Sub-Options");
380 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
382 gboolean sub_options=FALSE;
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)
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;
400 proto_tree_add_text(dstopt_tree, tvb, offset+len, 1, "Sub-Options");
406 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
408 gboolean sub_options=FALSE;
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)
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;
423 proto_tree_add_text(dstopt_tree, tvb, offset+len, 1, "Sub-Options");
429 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
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;
447 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
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;
466 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree,
470 proto_tree *dstopt_tree;
475 /* BT INSERT BEGIN */
479 int mip_offset=0, delta=0;
482 static const value_string rtalertvals[] = {
483 { IP6OPT_RTALERT_MLD, "MLD" },
484 { IP6OPT_RTALERT_RSVP, "RSVP" },
488 tvb_memcpy(tvb, (guint8 *)&ext, offset, sizeof(ext));
489 len = (ext.ip6e_len + 1) << 3;
491 /* BT INSERT BEGIN */
493 tvb = tvb_create_from_top(offset);
498 /* !!! specify length */
499 ti = proto_tree_add_text(tree, tvb, offset, len,
500 "%s Header ", optname);
502 dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
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);
511 /* BT INSERT BEGIN */
518 while (p < offset + len) {
519 switch (tvb_get_guint8(tvb, p)) {
521 proto_tree_add_text(dstopt_tree, tvb, p, 1,
524 /* BT INSERT BEGIN */
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);
534 /* BT INSERT BEGIN */
535 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
539 tmp = tvb_get_guint8(tvb, p + 1);
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);
545 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
546 "Jumbo payload: Invalid length (%u bytes)",
551 /* BT INSERT BEGIN */
552 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
559 tmp = tvb_get_guint8(tvb, p + 1);
561 rta = val_to_str(tvb_get_ntohs(tvb, p + 2), rtalertvals,
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);
569 /* BT INSERT BEGIN */
570 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
574 /* BT INSERT BEGIN */
575 case IP6OPT_BINDING_UPDATE :
577 delta=dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
582 case IP6OPT_BINDING_ACK :
584 delta=dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
589 case IP6OPT_HOME_ADDRESS :
591 delta=dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
596 case IP6OPT_BINDING_REQUEST :
598 delta=dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
603 case IP6OPT_MIPv6_UNIQUE_ID_SUB :
605 delta=dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
610 case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
612 delta=dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
631 dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree) {
632 return dissect_opts(tvb, offset, tree, "Hop-by-hop Option");
636 dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree) {
637 return dissect_opts(tvb, offset, tree, "Destination Option");
641 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
642 proto_tree *ipv6_tree = NULL;
652 fragment_data *ipfd_head;
655 gboolean must_restore_pi = FALSE;
656 gboolean update_col_info = TRUE;
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);
666 tvb_memcpy(tvb, (guint8 *)&ipv6, offset, sizeof(ipv6));
668 pinfo->ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
670 /* Get the payload length */
671 plen = ntohs(ipv6.ip6_plen);
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));
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));
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);
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);
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));
697 * there should be no alignment problems for ip6_flow, since it's the first
698 * guint32 in the ipv6 struct
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));
706 proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, tvb,
707 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
710 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, tvb,
711 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
713 "Next header: %s (0x%02x)",
714 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
716 proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, tvb,
717 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
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);
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,
731 "Source address: %s (%s)",
732 get_hostname6(&ipv6.ip6_src),
734 "Source address: %s",
736 ip6_to_str(&ipv6.ip6_src));
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,
742 "Destination address: %s (%s)",
743 get_hostname6(&ipv6.ip6_dst),
745 "Destination address: %s",
747 ip6_to_str(&ipv6.ip6_dst));
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);
757 /* start out assuming this isn't fragmented */
762 case IP_PROTO_HOPOPTS:
763 advance = dissect_hopopts(tvb, offset, tree);
764 nxt = tvb_get_guint8(tvb, offset);
769 case IP_PROTO_ROUTING:
770 advance = dissect_routing6(tvb, offset, tree);
771 nxt = tvb_get_guint8(tvb, offset);
776 case IP_PROTO_FRAGMENT:
778 advance = dissect_frag6(tvb, offset, pinfo, tree,
780 nxt = tvb_get_guint8(tvb, offset);
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);
794 case IP_PROTO_DSTOPTS:
795 advance = dissect_dstopts(tvb, offset, tree);
796 nxt = tvb_get_guint8(tvb, offset);
804 proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, tvb, poffset, 1, nxt);
807 /* If ipv6_reassemble is on and this is a fragment, then just add the fragment
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,
816 offlg & IP6F_OFF_MASK,
818 offlg & IP6F_MORE_FRAG);
823 if (ipfd_head != NULL) {
828 /* OK, we have the complete reassembled payload. */
829 /* show all fragments */
830 fi = proto_tree_add_item(ipv6_tree, hf_ipv6_fragments,
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.
839 proto_tree *fet=NULL;
840 proto_item *fei=NULL;
843 if (ipfd->flags & (FD_OVERLAPCONFLICT
844 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
845 hf = hf_ipv6_fragment_error;
847 hf = hf_ipv6_fragment;
849 fei = proto_tree_add_none_format(ft, hf,
851 "Frame:%d payload:%d-%d",
854 ipfd->offset+ipfd->len-1
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,
862 if (ipfd->flags&FD_OVERLAPCONFLICT) {
863 proto_tree_add_boolean(fet,
864 hf_ipv6_fragment_overlap_conflict, tvb, 0, 0,
867 if (ipfd->flags&FD_MULTIPLETAILS) {
868 proto_tree_add_boolean(fet,
869 hf_ipv6_fragment_multiple_tails, tvb, 0, 0,
872 if (ipfd->flags&FD_TOOLONGFRAGMENT) {
873 proto_tree_add_boolean(fet,
874 hf_ipv6_fragment_too_long_fragment, tvb, 0, 0,
878 /* nothing of interest for this fragment */
879 proto_tree_add_none_format(ft, hf_ipv6_fragment,
881 "Frame:%d payload:%d-%d",
884 ipfd->offset+ipfd->len-1
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;
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");
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
903 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
905 /* Add the defragmented data to the data source list. */
906 pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
908 /* It's not fragmented. */
909 pinfo->fragmented = FALSE;
911 /* Save the current value of "pi", and adjust certain fields to
912 reflect the new tvbuff. */
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;
919 /* We don't have the complete reassembled payload. */
923 /* If this is the first fragment, dissect its contents, otherwise
924 just show it as a fragment.
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. */
932 /* First fragment, or not fragmented. Dissect what we have here. */
934 /* Get a tvbuff for the payload. */
935 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
938 * If this is the first fragment, but not the only fragment,
939 * tell the next protocol that.
941 if (offlg & IP6F_MORE_FRAG)
942 pinfo->fragmented = TRUE;
944 pinfo->fragmented = FALSE;
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);
953 /* As we haven't reassembled anything, we haven't changed "pi", so
954 we don't have to restore it. */
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);
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");
975 if (check_col(pinfo->fd, COL_INFO))
976 col_add_fstr(pinfo->fd, COL_INFO, "IPv6 no next header");
978 /* XXX - dissect the payload as padding? */
982 proto_register_ipv6(void)
984 static hf_register_info hf[] = {
986 { "Version", "ipv6.version",
987 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
989 { "Traffic class", "ipv6.class",
990 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
992 { "Flowlabel", "ipv6.flow",
993 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
995 { "Payload length", "ipv6.plen",
996 FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
998 { "Next header", "ipv6.nxt",
999 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1001 { "Hop limit", "ipv6.hlim",
1002 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
1004 { "Source", "ipv6.src",
1005 FT_IPv6, BASE_NONE, NULL, 0x0,
1006 "Source IPv6 Address", HFILL }},
1008 { "Destination", "ipv6.dst",
1009 FT_IPv6, BASE_NONE, NULL, 0x0,
1010 "Destination IPv6 Address", HFILL }},
1012 { "Address", "ipv6.addr",
1013 FT_IPv6, BASE_NONE, NULL, 0x0,
1014 "Source or Destination IPv6 Address", HFILL }},
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 }},
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 }},
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 }},
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 }},
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 }},
1041 { &hf_ipv6_fragment,
1042 { "IPv6 Fragment", "ipv6.fragment",
1043 FT_NONE, BASE_NONE, NULL, 0x0,
1044 "IPv6 Fragment", HFILL }},
1046 { &hf_ipv6_fragments,
1047 { "IPv6 Fragments", "ipv6.fragments",
1048 FT_NONE, BASE_NONE, NULL, 0x0,
1049 "IPv6 Fragments", HFILL }},
1051 /* BT INSERT BEGIN */
1052 { &hf_ipv6_mipv6_type,
1053 { "Option Type ", "ipv6.mipv6_type",
1054 FT_UINT8, BASE_DEC, NULL, 0x0,
1056 { &hf_ipv6_mipv6_length,
1057 { "Option Length ", "ipv6.mipv6_length",
1058 FT_UINT8, BASE_DEC, NULL, 0x0,
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,
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,
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,
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,
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,
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,
1090 { &hf_ipv6_mipv6_prefix_length,
1091 { "Prefix Length ", "ipv6.mipv6_prefix_length",
1092 FT_UINT8, BASE_DEC, NULL, 0x0,
1094 { &hf_ipv6_mipv6_sequence_number,
1095 { "Sequence Number ", "ipv6.mipv6_sequence_number",
1096 FT_UINT16, BASE_DEC, NULL, 0x0,
1098 { &hf_ipv6_mipv6_life_time,
1099 { "Life Time ", "ipv6.mipv6_life_time",
1100 FT_UINT32, BASE_DEC, NULL, 0x0,
1102 { &hf_ipv6_mipv6_status,
1103 { "Status ", "ipv6.mipv6_status",
1104 FT_UINT8, BASE_DEC, NULL, 0x0,
1106 { &hf_ipv6_mipv6_refresh,
1107 { "Refresh ", "ipv6.mipv6_refresh",
1108 FT_UINT32, BASE_DEC, NULL, 0x0,
1110 { &hf_ipv6_mipv6_home_address,
1111 { "Home Address ", "ipv6.mipv6_home_address",
1112 FT_IPv6, BASE_HEX, NULL, 0x0,
1114 { &hf_ipv6_mipv6_sub_type,
1115 { "Sub-Option Type ", "ipv6.mipv6_sub_type",
1116 FT_UINT8, BASE_DEC, NULL, 0x0,
1118 { &hf_ipv6_mipv6_sub_length,
1119 { "Sub-Option Length ", "ipv6.mipv6_sub_length",
1120 FT_UINT8, BASE_DEC, NULL, 0x0,
1122 { &hf_ipv6_mipv6_sub_unique_ID,
1123 { "Unique Identifier ", "ipv6.mipv6_sub_unique_ID",
1124 FT_UINT16, BASE_DEC, NULL, 0x0,
1126 { &hf_ipv6_mipv6_sub_alternative_COA,
1127 { "Alternative Care of Address ", "ipv6.mipv6_sub_alternative_COA",
1128 FT_IPv6, BASE_HEX, NULL, 0x0,
1132 #ifdef TEST_FINALHDR
1134 { "Final next header", "ipv6.final",
1135 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1138 static gint *ett[] = {
1140 &ett_ipv6_fragments,
1143 module_t *ipv6_module;
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));
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",
1156 register_dissector("ipv6", dissect_ipv6, proto_ipv6);
1157 register_init_routine(ipv6_reassemble_init);
1161 proto_reg_handoff_ipv6(void)
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);