2 * Routines for IPv6 packet disassembly
4 * $Id: packet-ipv6.c,v 1.60 2001/06/26 17:31:36 itojun 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;
88 static int hf_ipv6_mipv6_type = -1;
89 static int hf_ipv6_mipv6_length = -1;
90 static int hf_ipv6_mipv6_a_flag = -1;
91 static int hf_ipv6_mipv6_h_flag = -1;
92 static int hf_ipv6_mipv6_r_flag = -1;
93 static int hf_ipv6_mipv6_d_flag = -1;
94 static int hf_ipv6_mipv6_m_flag = -1;
95 static int hf_ipv6_mipv6_b_flag = -1;
96 static int hf_ipv6_mipv6_prefix_length = -1;
97 static int hf_ipv6_mipv6_sequence_number = -1;
98 static int hf_ipv6_mipv6_life_time = -1;
99 static int hf_ipv6_mipv6_status = -1;
100 static int hf_ipv6_mipv6_refresh = -1;
101 static int hf_ipv6_mipv6_home_address = -1;
102 static int hf_ipv6_mipv6_sub_type = -1;
103 static int hf_ipv6_mipv6_sub_length = -1;
104 static int hf_ipv6_mipv6_sub_unique_ID = -1;
105 static int hf_ipv6_mipv6_sub_alternative_COA = -1;
107 static gint ett_ipv6 = -1;
108 static gint ett_ipv6_fragments = -1;
109 static gint ett_ipv6_fragment = -1;
111 /* Reassemble fragmented datagrams */
112 static gboolean ipv6_reassemble = FALSE;
115 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
119 * defragmentation of IPv6
121 static GHashTable *ipv6_fragment_table = NULL;
124 ipv6_reassemble_init(void)
126 fragment_table_init(&ipv6_fragment_table);
130 dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree) {
133 proto_tree *rthdr_tree;
135 char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
137 tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
138 len = (rt.ip6r_len + 1) << 3;
141 /* !!! specify length */
142 ti = proto_tree_add_text(tree, tvb, offset, len,
143 "Routing Header, Type %u", rt.ip6r_type);
144 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
146 proto_tree_add_text(rthdr_tree, tvb,
147 offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
148 "Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
149 proto_tree_add_text(rthdr_tree, tvb,
150 offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
151 "Length: %u (%d bytes)", rt.ip6r_len, len);
152 proto_tree_add_text(rthdr_tree, tvb,
153 offset + offsetof(struct ip6_rthdr, ip6r_type), 1,
154 "Type: %u", rt.ip6r_type);
155 proto_tree_add_text(rthdr_tree, tvb,
156 offset + offsetof(struct ip6_rthdr, ip6r_segleft), 1,
157 "Segments left: %u", rt.ip6r_segleft);
159 if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
160 struct e_in6_addr *a;
162 struct ip6_rthdr0 *rt0;
164 tvb_memcpy(tvb, buf, offset, len);
165 rt0 = (struct ip6_rthdr0 *)buf;
166 for (a = rt0->ip6r0_addr, n = 0;
167 a < (struct e_in6_addr *)(buf + len);
169 proto_tree_add_text(rthdr_tree, tvb,
170 offset + offsetof(struct ip6_rthdr0, ip6r0_addr) + n * sizeof(struct e_in6_addr),
171 sizeof(struct e_in6_addr),
173 "address %d: %s (%s)",
174 n, get_hostname6(a), ip6_to_str(a)
176 "address %d: %s", n, ip6_to_str(a)
189 dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
190 guint16 *offlg, guint32 *ident) {
191 struct ip6_frag frag;
194 proto_tree *rthdr_tree;
196 tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
198 frag.ip6f_offlg = ntohs(frag.ip6f_offlg);
199 *offlg = frag.ip6f_offlg;
200 *ident = frag.ip6f_ident;
201 if (check_col(pinfo->fd, COL_INFO)) {
202 col_add_fstr(pinfo->fd, COL_INFO,
203 "IPv6 fragment (nxt=%s (0x%02x) off=%u id=0x%x)",
204 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
205 frag.ip6f_offlg & IP6F_OFF_MASK, frag.ip6f_ident);
208 ti = proto_tree_add_text(tree, tvb, offset, len,
209 "Fragmention Header");
210 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
212 proto_tree_add_text(rthdr_tree, tvb,
213 offset + offsetof(struct ip6_frag, ip6f_nxt), 1,
214 "Next header: %s (0x%02x)",
215 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt);
218 proto_tree_add_text(rthdr_tree, tvb,
219 offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
224 proto_tree_add_text(rthdr_tree, tvb,
225 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
227 frag.ip6f_offlg & IP6F_OFF_MASK);
229 proto_tree_add_text(rthdr_tree, tvb,
230 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
231 "More fragments: %s",
232 frag.ip6f_offlg & IP6F_MORE_FRAG ?
235 proto_tree_add_text(rthdr_tree, tvb,
236 offset + offsetof(struct ip6_frag, ip6f_ident), 4,
237 "Identification: 0x%08x",
243 /* Binding Update flag description */
244 static const true_false_string ipv6_mipv6_bu_a_flag_value = {
245 "Binding Acknowledgement requested",
246 "Binding Acknowledgement not requested"
248 static const true_false_string ipv6_mipv6_bu_h_flag_value = {
250 "No Home Registration"
252 static const true_false_string ipv6_mipv6_bu_r_flag_value = {
256 static const true_false_string ipv6_mipv6_bu_d_flag_value = {
257 "Perform Duplicate Address Detection",
258 "Do not perform Duplicate Address Detection"
260 static const true_false_string ipv6_mipv6_bu_m_flag_value = {
262 "No MAP Registration"
264 static const true_false_string ipv6_mipv6_bu_b_flag_value = {
265 "Request for bicasting",
266 "Do not request for bicasting"
270 dissect_mipv6_ba(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
272 guint8 status, len = 0;
273 const char *status_text;
274 gboolean sub_options = FALSE;
276 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
277 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
278 tvb_get_guint8(tvb, offset + len),
279 "Option Type: %u (0x%02x) - Binding Acknowledgement",
280 tvb_get_guint8(tvb, offset + len),
281 tvb_get_guint8(tvb, offset + len));
282 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
283 if (tvb_get_guint8(tvb, offset + len) > 11)
285 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
286 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
287 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
288 status = tvb_get_guint8(tvb, offset + len);
291 status_text = "- Binding Update accepted";
294 status_text = "- Binding Update was rejected - Reason unspecified";
297 status_text = "- Binding Update was rejected - Administratively prohibited";
300 status_text = "- Binding Update was rejected - Insufficient resources";
303 status_text = "- Binding Update was rejected - Home registration not supported";
306 status_text = "- Binding Update was rejected - Not home subnet";
309 status_text = "- Binding Update was rejected - Incorrect interface identifier length";
312 status_text = "- Binding Update was rejected - Not home agent for this mobile node";
315 status_text = "- Binding Update was rejected - Duplicate Address Detection failed";
323 status_text = "- Binding Update was rejected";
327 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_status,
328 tvb, offset + len, IP6_MIPv6_STATUS_LENGTH,
329 tvb_get_guint8(tvb, offset + len),
330 "Status: %u %s", tvb_get_guint8(tvb, offset + len), status_text);
331 len += IP6_MIPv6_STATUS_LENGTH;
332 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number,
333 tvb, offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
334 tvb_get_ntohs(tvb, offset + len));
335 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
336 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
337 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time,
338 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
339 tvb_get_ntohl(tvb, offset + len),
340 "Life Time: %u - Infinity", tvb_get_ntohl(tvb, offset + len));
342 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time,
343 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
344 tvb_get_ntohl(tvb, offset + len));
346 len += IP6_MIPv6_LIFE_TIME_LENGTH;
347 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_refresh, tvb,
348 offset + len, IP6_MIPv6_REFRESH_LENGTH,
349 tvb_get_ntohl(tvb, offset + len));
350 len += IP6_MIPv6_REFRESH_LENGTH;
353 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
358 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
361 gboolean sub_options = FALSE;
363 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset,
364 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb, offset),
365 "Option Type: %u (0x%02x) - Binding Update",
366 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset));
367 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
368 if (tvb_get_guint8(tvb, offset + len) > 8)
370 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
371 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
372 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
373 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_a_flag, tvb, offset + len,
374 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
375 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_h_flag, tvb, offset + len,
376 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
377 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_r_flag, tvb, offset + len,
378 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
379 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_d_flag, tvb, offset + len,
380 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
381 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_m_flag, tvb, offset + len,
382 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
383 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_b_flag, tvb, offset + len,
384 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
385 len += IP6_MIPv6_FLAGS_LENGTH;
386 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_prefix_length, tvb,
388 IP6_MIPv6_PREFIX_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
389 len += IP6_MIPv6_PREFIX_LENGTH_LENGTH;
390 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb,
391 offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
392 tvb_get_ntohs(tvb, offset + len));
393 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
394 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
395 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
396 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
397 tvb_get_ntohl(tvb, offset + len), "Life Time: %u - Infinity",
398 tvb_get_ntohl(tvb, offset + len));
400 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
401 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,
404 len += IP6_MIPv6_LIFE_TIME_LENGTH;
407 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
412 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
415 gboolean sub_options = FALSE;
417 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
418 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
419 tvb_get_guint8(tvb, offset + len),
420 "Option Type: %u (0x%02x) - Home Address",
421 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
422 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
423 if (tvb_get_guint8(tvb, offset + len) > 16)
425 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
426 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
427 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
428 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_home_address, tvb,
429 offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH,
430 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH));
431 len += IP6_MIPv6_HOME_ADDRESS_LENGTH;
434 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
439 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
442 gboolean sub_options = FALSE;
444 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
445 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
446 tvb_get_guint8(tvb, offset + len),
447 "Option Type: %u (0x%02x) - Binding Request",
448 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
449 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
450 if (tvb_get_guint8(tvb, offset + len) > 0)
452 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
453 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
454 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
457 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
462 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
466 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
467 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
468 tvb_get_guint8(tvb, offset + len),
469 "Sub-Option Type: %u (0x%02x) - Unique Identifier Sub-Option",
470 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
471 len += IP6_MIPv6_SUB_TYPE_LENGTH;
472 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
473 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
474 tvb_get_guint8(tvb, offset + len));
475 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
476 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_unique_ID, tvb,
477 offset + len, IP6_MIPv6_SUB_UNIQUE_ID_LENGTH,
478 tvb_get_ntohs(tvb, offset + len));
479 len += IP6_MIPv6_SUB_UNIQUE_ID_LENGTH;
484 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
488 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_type, tvb,
489 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
490 tvb_get_guint8(tvb, offset + len),
491 "Sub-Option Type: %u (0x%02x) - Alternative Care Of Address",
492 tvb_get_guint8(tvb, offset + len),
493 tvb_get_guint8(tvb, offset + len));
494 len += IP6_MIPv6_SUB_TYPE_LENGTH;
495 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
496 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
497 tvb_get_guint8(tvb, offset + len));
498 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
499 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_sub_alternative_COA, tvb,
500 offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH,
501 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH));
502 len += IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH;
506 static const value_string rtalertvals[] = {
507 { IP6OPT_RTALERT_MLD, "MLD" },
508 { IP6OPT_RTALERT_RSVP, "RSVP" },
513 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, char *optname)
517 proto_tree *dstopt_tree;
521 int mip_offset = 0, delta = 0;
523 tvb_memcpy(tvb, (guint8 *)&ext, offset, sizeof(ext));
524 len = (ext.ip6e_len + 1) << 3;
527 /* !!! specify length */
528 ti = proto_tree_add_text(tree, tvb, offset, len, "%s Header ", optname);
530 dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
532 proto_tree_add_text(dstopt_tree, tvb,
533 offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
534 "Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt), ext.ip6e_nxt);
535 proto_tree_add_text(dstopt_tree, tvb,
536 offset + offsetof(struct ip6_ext, ip6e_len), 1,
537 "Length: %u (%d bytes)", ext.ip6e_len, len);
544 while (p < offset + len) {
545 switch (tvb_get_guint8(tvb, p)) {
547 proto_tree_add_text(dstopt_tree, tvb, p, 1, "Pad1");
552 tmp = tvb_get_guint8(tvb, p + 1);
553 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
554 "PadN: %u bytes", tmp + 2);
557 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
560 tmp = tvb_get_guint8(tvb, p + 1);
562 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
563 "Jumbo payload: %u (%u bytes)",
564 tvb_get_ntohl(tvb, p + 2), tmp + 2);
566 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
567 "Jumbo payload: Invalid length (%u bytes)",
572 mip_offset += tvb_get_guint8(tvb, mip_offset+1)+2;
578 tmp = tvb_get_guint8(tvb, p + 1);
580 rta = val_to_str(tvb_get_ntohs(tvb, p + 2), rtalertvals,
583 rta = "Invalid length";
584 ti = proto_tree_add_text(dstopt_tree, tvb, p , tmp + 2,
585 "Router alert: %s (%u bytes)", rta, tmp + 2);
588 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
591 case IP6OPT_BINDING_UPDATE :
592 delta = dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
596 case IP6OPT_BINDING_ACK :
597 delta = dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
601 case IP6OPT_HOME_ADDRESS :
602 delta = dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
606 case IP6OPT_BINDING_REQUEST :
607 delta = dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
611 case IP6OPT_MIPv6_UNIQUE_ID_SUB :
612 delta = dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
616 case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
617 delta = dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
633 dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree)
635 return dissect_opts(tvb, offset, tree, "Hop-by-hop Option");
639 dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree)
641 return dissect_opts(tvb, offset, tree, "Destination Option");
645 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
647 proto_tree *ipv6_tree = NULL;
657 fragment_data *ipfd_head;
660 gboolean must_restore_pi = FALSE;
661 gboolean update_col_info = TRUE;
665 if (check_col(pinfo->fd, COL_PROTOCOL))
666 col_set_str(pinfo->fd, COL_PROTOCOL, "IPv6");
667 if (check_col(pinfo->fd, COL_INFO))
668 col_clear(pinfo->fd, COL_INFO);
671 tvb_memcpy(tvb, (guint8 *)&ipv6, offset, sizeof(ipv6));
673 pinfo->ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
675 /* Get the payload length */
676 plen = ntohs(ipv6.ip6_plen);
678 /* Check for trailer (not part of IPv6 packet) */
679 if (plen + sizeof (struct ip6_hdr) < tvb_reported_length(tvb))
680 tvb_set_reported_length(tvb, plen + sizeof (struct ip6_hdr));
682 SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
683 SET_ADDRESS(&pinfo->src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
684 SET_ADDRESS(&pinfo->net_dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
685 SET_ADDRESS(&pinfo->dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
688 /* !!! specify length */
689 ti = proto_tree_add_item(tree, proto_ipv6, tvb, offset, 40, FALSE);
690 ipv6_tree = proto_item_add_subtree(ti, ett_ipv6);
692 /* !!! warning: version also contains 4 Bit priority */
693 proto_tree_add_uint(ipv6_tree, hf_ipv6_version, tvb,
694 offset + offsetof(struct ip6_hdr, ip6_vfc), 1,
695 (ipv6.ip6_vfc >> 4) & 0x0f);
697 proto_tree_add_uint(ipv6_tree, hf_ipv6_class, tvb,
698 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
699 (guint8)((ntohl(ipv6.ip6_flow) >> 20) & 0xff));
702 * there should be no alignment problems for ip6_flow, since it's the first
703 * guint32 in the ipv6 struct
705 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_flow, tvb,
706 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
707 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK),
708 "Flowlabel: 0x%05lx",
709 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK));
711 proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, tvb,
712 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
715 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, tvb,
716 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
718 "Next header: %s (0x%02x)",
719 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
721 proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, tvb,
722 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
725 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
726 offset + offsetof(struct ip6_hdr, ip6_src), 16,
727 ipv6.ip6_src.s6_addr8);
728 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
729 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
730 ipv6.ip6_dst.s6_addr8);
732 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_src, tvb,
733 offset + offsetof(struct ip6_hdr, ip6_src), 16,
734 (guint8 *)&ipv6.ip6_src,
736 "Source address: %s (%s)",
737 get_hostname6(&ipv6.ip6_src),
739 "Source address: %s",
741 ip6_to_str(&ipv6.ip6_src));
743 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_dst, tvb,
744 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
745 (guint8 *)&ipv6.ip6_dst,
747 "Destination address: %s (%s)",
748 get_hostname6(&ipv6.ip6_dst),
750 "Destination address: %s",
752 ip6_to_str(&ipv6.ip6_dst));
755 /* start of the new header (could be a extension header) */
756 poffset = offset + offsetof(struct ip6_hdr, ip6_nxt);
757 nxt = tvb_get_guint8(tvb, poffset);
758 offset += sizeof(struct ip6_hdr);
762 /* start out assuming this isn't fragmented */
767 case IP_PROTO_HOPOPTS:
768 advance = dissect_hopopts(tvb, offset, tree);
769 nxt = tvb_get_guint8(tvb, offset);
774 case IP_PROTO_ROUTING:
775 advance = dissect_routing6(tvb, offset, tree);
776 nxt = tvb_get_guint8(tvb, offset);
781 case IP_PROTO_FRAGMENT:
783 advance = dissect_frag6(tvb, offset, pinfo, tree,
785 nxt = tvb_get_guint8(tvb, offset);
791 advance = dissect_ah_header(
792 tvb_new_subset(tvb, offset, -1, -1),
793 pinfo, tree, NULL, NULL);
794 nxt = tvb_get_guint8(tvb, offset);
799 case IP_PROTO_DSTOPTS:
800 advance = dissect_dstopts(tvb, offset, tree);
801 nxt = tvb_get_guint8(tvb, offset);
809 proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, tvb, poffset, 1, nxt);
812 /* If ipv6_reassemble is on and this is a fragment, then just add the fragment
815 if (ipv6_reassemble && frag) {
816 /* We're reassembling, and this is part of a fragmented datagram.
817 Add the fragment to the hash table if the frame isn't truncated. */
818 if (tvb_reported_length(tvb) <= tvb_length(tvb)) {
819 ipfd_head = fragment_add(tvb, offset, pinfo, ident,
821 offlg & IP6F_OFF_MASK,
823 offlg & IP6F_MORE_FRAG);
828 if (ipfd_head != NULL) {
830 proto_tree *ft = NULL;
831 proto_item *fi = NULL;
833 /* OK, we have the complete reassembled payload. */
834 /* show all fragments */
835 fi = proto_tree_add_item(ipv6_tree, hf_ipv6_fragments,
837 ft = proto_item_add_subtree(fi, ett_ipv6_fragments);
838 for (ipfd = ipfd_head->next; ipfd; ipfd = ipfd->next){
839 if (ipfd->flags & (FD_OVERLAP|FD_OVERLAPCONFLICT
840 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
841 /* this fragment has some flags set, create a subtree
842 * for it and display the flags.
844 proto_tree *fet = NULL;
845 proto_item *fei = NULL;
848 if (ipfd->flags & (FD_OVERLAPCONFLICT
849 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
850 hf = hf_ipv6_fragment_error;
852 hf = hf_ipv6_fragment;
854 fei = proto_tree_add_none_format(ft, hf,
856 "Frame:%d payload:%d-%d",
859 ipfd->offset+ipfd->len-1
861 fet = proto_item_add_subtree(fei, ett_ipv6_fragment);
862 if (ipfd->flags&FD_OVERLAP) {
863 proto_tree_add_boolean(fet,
864 hf_ipv6_fragment_overlap, tvb, 0, 0,
867 if (ipfd->flags&FD_OVERLAPCONFLICT) {
868 proto_tree_add_boolean(fet,
869 hf_ipv6_fragment_overlap_conflict, tvb, 0, 0,
872 if (ipfd->flags&FD_MULTIPLETAILS) {
873 proto_tree_add_boolean(fet,
874 hf_ipv6_fragment_multiple_tails, tvb, 0, 0,
877 if (ipfd->flags&FD_TOOLONGFRAGMENT) {
878 proto_tree_add_boolean(fet,
879 hf_ipv6_fragment_too_long_fragment, tvb, 0, 0,
883 /* nothing of interest for this fragment */
884 proto_tree_add_none_format(ft, hf_ipv6_fragment,
886 "Frame:%d payload:%d-%d",
889 ipfd->offset+ipfd->len-1
893 if (ipfd_head->flags & (FD_OVERLAPCONFLICT
894 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
895 if (check_col(pinfo->fd, COL_INFO)) {
896 col_set_str(pinfo->fd, COL_INFO, "[Illegal fragments]");
897 update_col_info = FALSE;
901 /* Allocate a new tvbuff, referring to the reassembled payload. */
902 next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
903 ipfd_head->datalen, "Reassembled");
905 /* Add the tvbuff to the list of tvbuffs to which the tvbuff we
906 were handed refers, so it'll get cleaned up when that tvbuff
908 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
910 /* Add the defragmented data to the data source list. */
911 pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
913 /* It's not fragmented. */
914 pinfo->fragmented = FALSE;
916 /* Save the current value of "pi", and adjust certain fields to
917 reflect the new tvbuff. */
919 pi.compat_top_tvb = next_tvb;
920 pi.len = tvb_reported_length(next_tvb);
921 pi.captured_len = tvb_length(next_tvb);
922 must_restore_pi = TRUE;
924 /* We don't have the complete reassembled payload. */
928 /* If this is the first fragment, dissect its contents, otherwise
929 just show it as a fragment.
931 XXX - if we eventually don't save the reassembled contents of all
932 fragmented datagrams, we may want to always reassemble. */
933 if (offlg & IP6F_OFF_MASK) {
934 /* Not the first fragment - don't dissect it. */
937 /* First fragment, or not fragmented. Dissect what we have here. */
939 /* Get a tvbuff for the payload. */
940 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
943 * If this is the first fragment, but not the only fragment,
944 * tell the next protocol that.
946 if (offlg & IP6F_MORE_FRAG)
947 pinfo->fragmented = TRUE;
949 pinfo->fragmented = FALSE;
953 if (next_tvb == NULL) {
954 /* Just show this as a fragment. */
955 /* COL_INFO was filled in by "dissect_frag6()" */
956 dissect_data(tvb, offset, pinfo, tree);
958 /* As we haven't reassembled anything, we haven't changed "pi", so
959 we don't have to restore it. */
963 /* do lookup with the subdissector table */
964 if (!dissector_try_port(ip_dissector_table, nxt, next_tvb, pinfo, tree)) {
965 /* Unknown protocol */
966 if (check_col(pinfo->fd, COL_INFO))
967 col_add_fstr(pinfo->fd, COL_INFO, "%s (0x%02x)", ipprotostr(nxt),nxt);
968 dissect_data(next_tvb, 0, pinfo, tree);
973 dissect_ipv6_none(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
975 if (hf_ipv6_mipv6_length != -1) {
976 if (check_col(pinfo->fd, COL_INFO))
977 col_add_fstr(pinfo->fd, COL_INFO, "MobileIPv6 Destination Option");
979 if (check_col(pinfo->fd, COL_INFO))
980 col_add_fstr(pinfo->fd, COL_INFO, "IPv6 no next header");
982 /* XXX - dissect the payload as padding? */
986 proto_register_ipv6(void)
988 static hf_register_info hf[] = {
990 { "Version", "ipv6.version",
991 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
993 { "Traffic class", "ipv6.class",
994 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
996 { "Flowlabel", "ipv6.flow",
997 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
999 { "Payload length", "ipv6.plen",
1000 FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
1002 { "Next header", "ipv6.nxt",
1003 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1005 { "Hop limit", "ipv6.hlim",
1006 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
1008 { "Source", "ipv6.src",
1009 FT_IPv6, BASE_NONE, NULL, 0x0,
1010 "Source IPv6 Address", HFILL }},
1012 { "Destination", "ipv6.dst",
1013 FT_IPv6, BASE_NONE, NULL, 0x0,
1014 "Destination IPv6 Address", HFILL }},
1016 { "Address", "ipv6.addr",
1017 FT_IPv6, BASE_NONE, NULL, 0x0,
1018 "Source or Destination IPv6 Address", HFILL }},
1020 { &hf_ipv6_fragment_overlap,
1021 { "Fragment overlap", "ipv6.fragment.overlap",
1022 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1023 "Fragment overlaps with other fragments", HFILL }},
1025 { &hf_ipv6_fragment_overlap_conflict,
1026 { "Conflicting data in fragment overlap", "ipv6.fragment.overlap.conflict",
1027 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1028 "Overlapping fragments contained conflicting data", HFILL }},
1030 { &hf_ipv6_fragment_multiple_tails,
1031 { "Multiple tail fragments found", "ipv6.fragment.multipletails",
1032 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1033 "Several tails were found when defragmenting the packet", HFILL }},
1035 { &hf_ipv6_fragment_too_long_fragment,
1036 { "Fragment too long", "ipv6.fragment.toolongfragment",
1037 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
1038 "Fragment contained data past end of packet", HFILL }},
1040 { &hf_ipv6_fragment_error,
1041 { "Defragmentation error", "ipv6.fragment.error",
1042 FT_NONE, BASE_NONE, NULL, 0x0,
1043 "Defragmentation error due to illegal fragments", HFILL }},
1045 { &hf_ipv6_fragment,
1046 { "IPv6 Fragment", "ipv6.fragment",
1047 FT_NONE, BASE_NONE, NULL, 0x0,
1048 "IPv6 Fragment", HFILL }},
1050 { &hf_ipv6_fragments,
1051 { "IPv6 Fragments", "ipv6.fragments",
1052 FT_NONE, BASE_NONE, NULL, 0x0,
1053 "IPv6 Fragments", HFILL }},
1055 /* BT INSERT BEGIN */
1056 { &hf_ipv6_mipv6_type,
1057 { "Option Type ", "ipv6.mipv6_type",
1058 FT_UINT8, BASE_DEC, NULL, 0x0,
1060 { &hf_ipv6_mipv6_length,
1061 { "Option Length ", "ipv6.mipv6_length",
1062 FT_UINT8, BASE_DEC, NULL, 0x0,
1064 { &hf_ipv6_mipv6_a_flag,
1065 { "Acknowledge (A) ", "ipv6.mipv6_a_flag",
1066 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_a_flag_value),
1067 IP6_MIPv6_BU_A_FLAG,
1069 { &hf_ipv6_mipv6_h_flag,
1070 { "Home Registration (H) ", "ipv6.mipv6_h_flag",
1071 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_h_flag_value),
1072 IP6_MIPv6_BU_H_FLAG,
1074 { &hf_ipv6_mipv6_r_flag,
1075 { "Router (R) ", "ipv6.mipv6_r_flag",
1076 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_r_flag_value),
1077 IP6_MIPv6_BU_R_FLAG,
1079 { &hf_ipv6_mipv6_d_flag,
1080 { "Duplicate Address Detection (D) ", "ipv6.mipv6_d_flag",
1081 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_d_flag_value),
1082 IP6_MIPv6_BU_D_FLAG,
1084 { &hf_ipv6_mipv6_m_flag,
1085 { "MAP Registration (M) ", "ipv6.mipv6_m_flag",
1086 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_m_flag_value),
1087 IP6_MIPv6_BU_M_FLAG,
1089 { &hf_ipv6_mipv6_b_flag,
1090 { "Bicasting all (B) ", "ipv6.mipv6_b_flag",
1091 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_b_flag_value),
1092 IP6_MIPv6_BU_B_FLAG,
1094 { &hf_ipv6_mipv6_prefix_length,
1095 { "Prefix Length ", "ipv6.mipv6_prefix_length",
1096 FT_UINT8, BASE_DEC, NULL, 0x0,
1098 { &hf_ipv6_mipv6_sequence_number,
1099 { "Sequence Number ", "ipv6.mipv6_sequence_number",
1100 FT_UINT16, BASE_DEC, NULL, 0x0,
1102 { &hf_ipv6_mipv6_life_time,
1103 { "Life Time ", "ipv6.mipv6_life_time",
1104 FT_UINT32, BASE_DEC, NULL, 0x0,
1106 { &hf_ipv6_mipv6_status,
1107 { "Status ", "ipv6.mipv6_status",
1108 FT_UINT8, BASE_DEC, NULL, 0x0,
1110 { &hf_ipv6_mipv6_refresh,
1111 { "Refresh ", "ipv6.mipv6_refresh",
1112 FT_UINT32, BASE_DEC, NULL, 0x0,
1114 { &hf_ipv6_mipv6_home_address,
1115 { "Home Address ", "ipv6.mipv6_home_address",
1116 FT_IPv6, BASE_HEX, NULL, 0x0,
1118 { &hf_ipv6_mipv6_sub_type,
1119 { "Sub-Option Type ", "ipv6.mipv6_sub_type",
1120 FT_UINT8, BASE_DEC, NULL, 0x0,
1122 { &hf_ipv6_mipv6_sub_length,
1123 { "Sub-Option Length ", "ipv6.mipv6_sub_length",
1124 FT_UINT8, BASE_DEC, NULL, 0x0,
1126 { &hf_ipv6_mipv6_sub_unique_ID,
1127 { "Unique Identifier ", "ipv6.mipv6_sub_unique_ID",
1128 FT_UINT16, BASE_DEC, NULL, 0x0,
1130 { &hf_ipv6_mipv6_sub_alternative_COA,
1131 { "Alternative Care of Address ", "ipv6.mipv6_sub_alternative_COA",
1132 FT_IPv6, BASE_HEX, NULL, 0x0,
1136 #ifdef TEST_FINALHDR
1138 { "Final next header", "ipv6.final",
1139 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1142 static gint *ett[] = {
1144 &ett_ipv6_fragments,
1147 module_t *ipv6_module;
1149 proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
1150 proto_register_field_array(proto_ipv6, hf, array_length(hf));
1151 proto_register_subtree_array(ett, array_length(ett));
1153 /* Register configuration options */
1154 ipv6_module = prefs_register_protocol(proto_ipv6, NULL);
1155 prefs_register_bool_preference(ipv6_module, "defragment",
1156 "Reassemble fragmented IPv6 datagrams",
1157 "Whether fragmented IPv6 datagrams should be reassembled",
1160 register_dissector("ipv6", dissect_ipv6, proto_ipv6);
1161 register_init_routine(ipv6_reassemble_init);
1165 proto_reg_handoff_ipv6(void)
1167 dissector_add("ethertype", ETHERTYPE_IPv6, dissect_ipv6, proto_ipv6);
1168 dissector_add("ppp.protocol", PPP_IPV6, dissect_ipv6, proto_ipv6);
1169 dissector_add("ip.proto", IP_PROTO_IPV6, dissect_ipv6, proto_ipv6);
1170 dissector_add("null.type", BSD_AF_INET6_BSD, dissect_ipv6, proto_ipv6);
1171 dissector_add("null.type", BSD_AF_INET6_FREEBSD, dissect_ipv6, proto_ipv6);
1172 dissector_add("ip.proto", IP_PROTO_NONE, dissect_ipv6_none, proto_ipv6);