2 * Routines for IPv6 packet disassembly
4 * $Id: packet-ipv6.c,v 1.83 2002/06/07 10:11:39 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_SYS_SOCKET_h
36 #include <sys/socket.h>
39 #ifdef HAVE_NETINET_IN_H
40 # include <netinet/in.h>
46 #include <epan/packet.h>
47 #include "packet-ip.h"
48 #include "packet-ipsec.h"
49 #include "packet-ipv6.h"
50 #include <epan/resolv.h>
52 #include "reassemble.h"
60 * NOTE: ipv6.nxt is not very useful as we will have chained header.
61 * now testing ipv6.final, but it raises SEGV.
65 static int proto_ipv6 = -1;
66 static int hf_ipv6_version = -1;
67 static int hf_ipv6_class = -1;
68 static int hf_ipv6_flow = -1;
69 static int hf_ipv6_plen = -1;
70 static int hf_ipv6_nxt = -1;
71 static int hf_ipv6_hlim = -1;
72 static int hf_ipv6_src = -1;
73 static int hf_ipv6_dst = -1;
74 static int hf_ipv6_addr = -1;
76 static int hf_ipv6_final = -1;
78 static int hf_ipv6_fragments = -1;
79 static int hf_ipv6_fragment = -1;
80 static int hf_ipv6_fragment_overlap = -1;
81 static int hf_ipv6_fragment_overlap_conflict = -1;
82 static int hf_ipv6_fragment_multiple_tails = -1;
83 static int hf_ipv6_fragment_too_long_fragment = -1;
84 static int hf_ipv6_fragment_error = -1;
86 static int hf_ipv6_mipv6_type = -1;
87 static int hf_ipv6_mipv6_length = -1;
88 static int hf_ipv6_mipv6_a_flag = -1;
89 static int hf_ipv6_mipv6_h_flag = -1;
90 static int hf_ipv6_mipv6_r_flag = -1;
91 static int hf_ipv6_mipv6_d_flag = -1;
92 static int hf_ipv6_mipv6_m_flag = -1;
93 static int hf_ipv6_mipv6_b_flag = -1;
94 static int hf_ipv6_mipv6_prefix_length = -1;
95 static int hf_ipv6_mipv6_sequence_number = -1;
96 static int hf_ipv6_mipv6_life_time = -1;
97 static int hf_ipv6_mipv6_status = -1;
98 static int hf_ipv6_mipv6_refresh = -1;
99 static int hf_ipv6_mipv6_home_address = -1;
100 static int hf_ipv6_mipv6_sub_type = -1;
101 static int hf_ipv6_mipv6_sub_length = -1;
102 static int hf_ipv6_mipv6_sub_unique_ID = -1;
103 static int hf_ipv6_mipv6_sub_alternative_COA = -1;
105 static gint ett_ipv6 = -1;
106 static gint ett_ipv6_fragments = -1;
107 static gint ett_ipv6_fragment = -1;
109 fragment_items ipv6_frag_items = {
114 &hf_ipv6_fragment_overlap,
115 &hf_ipv6_fragment_overlap_conflict,
116 &hf_ipv6_fragment_multiple_tails,
117 &hf_ipv6_fragment_too_long_fragment,
118 &hf_ipv6_fragment_error,
122 static dissector_handle_t data_handle;
124 /* Reassemble fragmented datagrams */
125 static gboolean ipv6_reassemble = FALSE;
128 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
132 * defragmentation of IPv6
134 static GHashTable *ipv6_fragment_table = NULL;
137 ipv6_reassemble_init(void)
139 fragment_table_init(&ipv6_fragment_table);
143 dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree) {
146 proto_tree *rthdr_tree;
148 char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
150 tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
151 len = (rt.ip6r_len + 1) << 3;
154 /* !!! specify length */
155 ti = proto_tree_add_text(tree, tvb, offset, len,
156 "Routing Header, Type %u", rt.ip6r_type);
157 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
159 proto_tree_add_text(rthdr_tree, tvb,
160 offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
161 "Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
162 proto_tree_add_text(rthdr_tree, tvb,
163 offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
164 "Length: %u (%d bytes)", rt.ip6r_len, len);
165 proto_tree_add_text(rthdr_tree, tvb,
166 offset + offsetof(struct ip6_rthdr, ip6r_type), 1,
167 "Type: %u", rt.ip6r_type);
168 proto_tree_add_text(rthdr_tree, tvb,
169 offset + offsetof(struct ip6_rthdr, ip6r_segleft), 1,
170 "Segments left: %u", rt.ip6r_segleft);
172 if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
173 struct e_in6_addr *a;
175 struct ip6_rthdr0 *rt0;
177 tvb_memcpy(tvb, buf, offset, len);
178 rt0 = (struct ip6_rthdr0 *)buf;
179 for (a = rt0->ip6r0_addr, n = 0;
180 a < (struct e_in6_addr *)(buf + len);
182 proto_tree_add_text(rthdr_tree, tvb,
183 offset + offsetof(struct ip6_rthdr0, ip6r0_addr) + n * sizeof(struct e_in6_addr),
184 sizeof(struct e_in6_addr),
186 "address %d: %s (%s)",
187 n, get_hostname6(a), ip6_to_str(a)
189 "address %d: %s", n, ip6_to_str(a)
202 dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
203 guint16 *offlg, guint32 *ident) {
204 struct ip6_frag frag;
207 proto_tree *rthdr_tree;
209 tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
211 frag.ip6f_offlg = ntohs(frag.ip6f_offlg);
212 *offlg = frag.ip6f_offlg;
213 *ident = frag.ip6f_ident;
214 if (check_col(pinfo->cinfo, COL_INFO)) {
215 col_add_fstr(pinfo->cinfo, COL_INFO,
216 "IPv6 fragment (nxt=%s (0x%02x) off=%u id=0x%x)",
217 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
218 frag.ip6f_offlg & IP6F_OFF_MASK, frag.ip6f_ident);
221 ti = proto_tree_add_text(tree, tvb, offset, len,
222 "Fragmention Header");
223 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
225 proto_tree_add_text(rthdr_tree, tvb,
226 offset + offsetof(struct ip6_frag, ip6f_nxt), 1,
227 "Next header: %s (0x%02x)",
228 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt);
231 proto_tree_add_text(rthdr_tree, tvb,
232 offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
237 proto_tree_add_text(rthdr_tree, tvb,
238 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
240 frag.ip6f_offlg & IP6F_OFF_MASK);
242 proto_tree_add_text(rthdr_tree, tvb,
243 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
244 "More fragments: %s",
245 frag.ip6f_offlg & IP6F_MORE_FRAG ?
248 proto_tree_add_text(rthdr_tree, tvb,
249 offset + offsetof(struct ip6_frag, ip6f_ident), 4,
250 "Identification: 0x%08x",
256 /* Binding Update flag description */
257 static const true_false_string ipv6_mipv6_bu_a_flag_value = {
258 "Binding Acknowledgement requested",
259 "Binding Acknowledgement not requested"
261 static const true_false_string ipv6_mipv6_bu_h_flag_value = {
263 "No Home Registration"
265 static const true_false_string ipv6_mipv6_bu_r_flag_value = {
269 static const true_false_string ipv6_mipv6_bu_d_flag_value = {
270 "Perform Duplicate Address Detection",
271 "Do not perform Duplicate Address Detection"
273 static const true_false_string ipv6_mipv6_bu_m_flag_value = {
275 "No MAP Registration"
277 static const true_false_string ipv6_mipv6_bu_b_flag_value = {
278 "Request for bicasting",
279 "Do not request for bicasting"
283 dissect_mipv6_ba(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
285 guint8 status, len = 0;
286 const char *status_text;
287 gboolean sub_options = FALSE;
289 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
290 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
291 tvb_get_guint8(tvb, offset + len),
292 "Option Type: %u (0x%02x) - Binding Acknowledgement",
293 tvb_get_guint8(tvb, offset + len),
294 tvb_get_guint8(tvb, offset + len));
295 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
296 if (tvb_get_guint8(tvb, offset + len) > 11)
298 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
299 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
300 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
301 status = tvb_get_guint8(tvb, offset + len);
304 status_text = "- Binding Update accepted";
307 status_text = "- Binding Update was rejected - Reason unspecified";
310 status_text = "- Binding Update was rejected - Administratively prohibited";
313 status_text = "- Binding Update was rejected - Insufficient resources";
316 status_text = "- Binding Update was rejected - Home registration not supported";
319 status_text = "- Binding Update was rejected - Not home subnet";
322 status_text = "- Binding Update was rejected - Incorrect interface identifier length";
325 status_text = "- Binding Update was rejected - Not home agent for this mobile node";
328 status_text = "- Binding Update was rejected - Duplicate Address Detection failed";
336 status_text = "- Binding Update was rejected";
340 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_status,
341 tvb, offset + len, IP6_MIPv6_STATUS_LENGTH,
342 tvb_get_guint8(tvb, offset + len),
343 "Status: %u %s", tvb_get_guint8(tvb, offset + len), status_text);
344 len += IP6_MIPv6_STATUS_LENGTH;
345 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number,
346 tvb, offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
347 tvb_get_ntohs(tvb, offset + len));
348 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
349 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
350 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time,
351 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
352 tvb_get_ntohl(tvb, offset + len),
353 "Life Time: %u - Infinity", tvb_get_ntohl(tvb, offset + len));
355 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time,
356 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
357 tvb_get_ntohl(tvb, offset + len));
359 len += IP6_MIPv6_LIFE_TIME_LENGTH;
360 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_refresh, tvb,
361 offset + len, IP6_MIPv6_REFRESH_LENGTH,
362 tvb_get_ntohl(tvb, offset + len));
363 len += IP6_MIPv6_REFRESH_LENGTH;
366 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
371 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
374 gboolean sub_options = FALSE;
376 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset,
377 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb, offset),
378 "Option Type: %u (0x%02x) - Binding Update",
379 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset));
380 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
381 if (tvb_get_guint8(tvb, offset + len) > 8)
383 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
384 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
385 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
386 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_a_flag, tvb, offset + len,
387 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
388 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_h_flag, tvb, offset + len,
389 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
390 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_r_flag, tvb, offset + len,
391 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
392 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_d_flag, tvb, offset + len,
393 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
394 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_m_flag, tvb, offset + len,
395 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
396 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_b_flag, tvb, offset + len,
397 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
398 len += IP6_MIPv6_FLAGS_LENGTH;
399 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_prefix_length, tvb,
401 IP6_MIPv6_PREFIX_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
402 len += IP6_MIPv6_PREFIX_LENGTH_LENGTH;
403 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb,
404 offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
405 tvb_get_ntohs(tvb, offset + len));
406 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
407 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
408 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
409 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
410 tvb_get_ntohl(tvb, offset + len), "Life Time: %u - Infinity",
411 tvb_get_ntohl(tvb, offset + len));
413 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
414 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,
417 len += IP6_MIPv6_LIFE_TIME_LENGTH;
420 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
425 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
428 gboolean sub_options = FALSE;
430 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
431 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
432 tvb_get_guint8(tvb, offset + len),
433 "Option Type: %u (0x%02x) - Home Address",
434 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
435 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
436 if (tvb_get_guint8(tvb, offset + len) > 16)
438 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
439 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
440 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
441 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_home_address, tvb,
442 offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH,
443 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH));
444 len += IP6_MIPv6_HOME_ADDRESS_LENGTH;
447 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
452 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
455 gboolean sub_options = FALSE;
457 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
458 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
459 tvb_get_guint8(tvb, offset + len),
460 "Option Type: %u (0x%02x) - Binding Request",
461 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
462 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
463 if (tvb_get_guint8(tvb, offset + len) > 0)
465 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
466 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
467 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
470 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
475 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
479 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
480 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
481 tvb_get_guint8(tvb, offset + len),
482 "Sub-Option Type: %u (0x%02x) - Unique Identifier Sub-Option",
483 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
484 len += IP6_MIPv6_SUB_TYPE_LENGTH;
485 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
486 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
487 tvb_get_guint8(tvb, offset + len));
488 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
489 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_unique_ID, tvb,
490 offset + len, IP6_MIPv6_SUB_UNIQUE_ID_LENGTH,
491 tvb_get_ntohs(tvb, offset + len));
492 len += IP6_MIPv6_SUB_UNIQUE_ID_LENGTH;
497 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
501 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_type, tvb,
502 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
503 tvb_get_guint8(tvb, offset + len),
504 "Sub-Option Type: %u (0x%02x) - Alternative Care Of Address",
505 tvb_get_guint8(tvb, offset + len),
506 tvb_get_guint8(tvb, offset + len));
507 len += IP6_MIPv6_SUB_TYPE_LENGTH;
508 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
509 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
510 tvb_get_guint8(tvb, offset + len));
511 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
512 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_sub_alternative_COA, tvb,
513 offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH,
514 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH));
515 len += IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH;
519 static const value_string rtalertvals[] = {
520 { IP6OPT_RTALERT_MLD, "MLD" },
521 { IP6OPT_RTALERT_RSVP, "RSVP" },
526 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, char *optname)
530 proto_tree *dstopt_tree;
534 int mip_offset = 0, delta = 0;
536 tvb_memcpy(tvb, (guint8 *)&ext, offset, sizeof(ext));
537 len = (ext.ip6e_len + 1) << 3;
540 /* !!! specify length */
541 ti = proto_tree_add_text(tree, tvb, offset, len, "%s Header ", optname);
543 dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
545 proto_tree_add_text(dstopt_tree, tvb,
546 offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
547 "Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt), ext.ip6e_nxt);
548 proto_tree_add_text(dstopt_tree, tvb,
549 offset + offsetof(struct ip6_ext, ip6e_len), 1,
550 "Length: %u (%d bytes)", ext.ip6e_len, len);
557 while (p < offset + len) {
558 switch (tvb_get_guint8(tvb, p)) {
560 proto_tree_add_text(dstopt_tree, tvb, p, 1, "Pad1");
565 tmp = tvb_get_guint8(tvb, p + 1);
566 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
567 "PadN: %u bytes", tmp + 2);
570 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
573 tmp = tvb_get_guint8(tvb, p + 1);
575 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
576 "Jumbo payload: %u (%u bytes)",
577 tvb_get_ntohl(tvb, p + 2), tmp + 2);
579 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
580 "Jumbo payload: Invalid length (%u bytes)",
585 mip_offset += tvb_get_guint8(tvb, mip_offset+1)+2;
591 tmp = tvb_get_guint8(tvb, p + 1);
593 rta = val_to_str(tvb_get_ntohs(tvb, p + 2), rtalertvals,
596 rta = "Invalid length";
597 ti = proto_tree_add_text(dstopt_tree, tvb, p , tmp + 2,
598 "Router alert: %s (%u bytes)", rta, tmp + 2);
601 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
604 case IP6OPT_BINDING_UPDATE :
605 delta = dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
609 case IP6OPT_BINDING_ACK :
610 delta = dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
614 case IP6OPT_HOME_ADDRESS :
615 delta = dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
619 case IP6OPT_BINDING_REQUEST :
620 delta = dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
624 case IP6OPT_MIPv6_UNIQUE_ID_SUB :
625 delta = dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
629 case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
630 delta = dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
646 dissect_hopopts(tvbuff_t *tvb, int offset, proto_tree *tree)
648 return dissect_opts(tvb, offset, tree, "Hop-by-hop Option");
652 dissect_dstopts(tvbuff_t *tvb, int offset, proto_tree *tree)
654 return dissect_opts(tvb, offset, tree, "Destination Option");
658 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
660 proto_tree *ipv6_tree = NULL;
666 gboolean hopopts, routing, frag, ah, dstopts;
670 fragment_data *ipfd_head;
672 gboolean update_col_info = TRUE;
673 gboolean save_fragmented;
677 if (check_col(pinfo->cinfo, COL_PROTOCOL))
678 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPv6");
679 if (check_col(pinfo->cinfo, COL_INFO))
680 col_clear(pinfo->cinfo, COL_INFO);
683 tvb_memcpy(tvb, (guint8 *)&ipv6, offset, sizeof(ipv6));
685 pinfo->ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
687 /* Get the payload length */
688 plen = ntohs(ipv6.ip6_plen);
690 /* Adjust the length of this tvbuff to include only the IPv6 datagram. */
691 set_actual_length(tvb, plen + sizeof (struct ip6_hdr));
693 SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
694 SET_ADDRESS(&pinfo->src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
695 SET_ADDRESS(&pinfo->net_dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
696 SET_ADDRESS(&pinfo->dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
699 /* !!! specify length */
700 ti = proto_tree_add_item(tree, proto_ipv6, tvb, offset, 40, FALSE);
701 ipv6_tree = proto_item_add_subtree(ti, ett_ipv6);
703 /* !!! warning: version also contains 4 Bit priority */
704 proto_tree_add_uint(ipv6_tree, hf_ipv6_version, tvb,
705 offset + offsetof(struct ip6_hdr, ip6_vfc), 1,
706 (ipv6.ip6_vfc >> 4) & 0x0f);
708 proto_tree_add_uint(ipv6_tree, hf_ipv6_class, tvb,
709 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
710 (guint8)((ntohl(ipv6.ip6_flow) >> 20) & 0xff));
713 * there should be no alignment problems for ip6_flow, since it's the first
714 * guint32 in the ipv6 struct
716 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_flow, tvb,
717 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
718 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK),
719 "Flowlabel: 0x%05lx",
720 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK));
722 proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, tvb,
723 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
726 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, tvb,
727 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
729 "Next header: %s (0x%02x)",
730 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
732 proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, tvb,
733 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
736 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
737 offset + offsetof(struct ip6_hdr, ip6_src), 16,
738 ipv6.ip6_src.s6_addr8);
739 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
740 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
741 ipv6.ip6_dst.s6_addr8);
743 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_src, tvb,
744 offset + offsetof(struct ip6_hdr, ip6_src), 16,
745 (guint8 *)&ipv6.ip6_src,
747 "Source address: %s (%s)",
748 get_hostname6(&ipv6.ip6_src),
750 "Source address: %s",
752 ip6_to_str(&ipv6.ip6_src));
754 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_dst, tvb,
755 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
756 (guint8 *)&ipv6.ip6_dst,
758 "Destination address: %s (%s)",
759 get_hostname6(&ipv6.ip6_dst),
761 "Destination address: %s",
763 ip6_to_str(&ipv6.ip6_dst));
766 /* start of the new header (could be a extension header) */
767 poffset = offset + offsetof(struct ip6_hdr, ip6_nxt);
768 nxt = tvb_get_guint8(tvb, poffset);
769 offset += sizeof(struct ip6_hdr);
773 /* start out assuming this isn't fragmented, and has none of the other
783 case IP_PROTO_HOPOPTS:
785 advance = dissect_hopopts(tvb, offset, tree);
786 nxt = tvb_get_guint8(tvb, offset);
791 case IP_PROTO_ROUTING:
793 advance = dissect_routing6(tvb, offset, tree);
794 nxt = tvb_get_guint8(tvb, offset);
799 case IP_PROTO_FRAGMENT:
801 advance = dissect_frag6(tvb, offset, pinfo, tree,
803 nxt = tvb_get_guint8(tvb, offset);
810 advance = dissect_ah_header(
811 tvb_new_subset(tvb, offset, -1, -1),
812 pinfo, tree, NULL, NULL);
813 nxt = tvb_get_guint8(tvb, offset);
818 case IP_PROTO_DSTOPTS:
820 advance = dissect_dstopts(tvb, offset, tree);
821 nxt = tvb_get_guint8(tvb, offset);
829 proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, tvb, poffset, 1, nxt);
832 /* If ipv6_reassemble is on, this is a fragment, and we have all the data
833 * in the fragment, then just add the fragment to the hashtable.
835 save_fragmented = pinfo->fragmented;
836 if (ipv6_reassemble && frag && tvb_reported_length(tvb) <= tvb_length(tvb)) {
837 ipfd_head = fragment_add(tvb, offset, pinfo, ident,
839 offlg & IP6F_OFF_MASK,
841 offlg & IP6F_MORE_FRAG);
843 if (ipfd_head != NULL) {
844 /* OK, we have the complete reassembled payload.
845 Allocate a new tvbuff, referring to the reassembled payload. */
846 next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
849 /* Add the tvbuff to the list of tvbuffs to which the tvbuff we
850 were handed refers, so it'll get cleaned up when that tvbuff
852 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
854 /* Add the defragmented data to the data source list. */
855 add_new_data_source(pinfo, next_tvb, "Reassembled IPv6");
857 /* show all fragments */
858 update_col_info = !show_fragment_tree(ipfd_head, &ipv6_frag_items,
859 ipv6_tree, pinfo, next_tvb);
861 /* We don't have the complete reassembled payload. */
865 /* If this is the first fragment, dissect its contents, otherwise
866 just show it as a fragment.
868 XXX - if we eventually don't save the reassembled contents of all
869 fragmented datagrams, we may want to always reassemble. */
870 if (offlg & IP6F_OFF_MASK) {
871 /* Not the first fragment - don't dissect it. */
874 /* First fragment, or not fragmented. Dissect what we have here. */
876 /* Get a tvbuff for the payload. */
877 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
880 * If this is the first fragment, but not the only fragment,
881 * tell the next protocol that.
883 if (offlg & IP6F_MORE_FRAG)
884 pinfo->fragmented = TRUE;
886 pinfo->fragmented = FALSE;
890 if (next_tvb == NULL) {
891 /* Just show this as a fragment. */
892 /* COL_INFO was filled in by "dissect_frag6()" */
893 call_dissector(data_handle, tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
895 /* As we haven't reassembled anything, we haven't changed "pi", so
896 we don't have to restore it. */
897 pinfo->fragmented = save_fragmented;
901 /* do lookup with the subdissector table */
902 if (!dissector_try_port(ip_dissector_table, nxt, next_tvb, pinfo, tree)) {
904 Handle "no next header" specially. */
905 if (nxt == IP_PROTO_NONE) {
906 if (check_col(pinfo->cinfo, COL_INFO)) {
907 /* If we had an Authentication Header, the AH dissector already
908 put something in the Info column; leave it there. */
910 if (hopopts || routing || dstopts) {
913 col_append_fstr(pinfo->cinfo, COL_INFO, "%shop-by-hop options",
918 col_append_fstr(pinfo->cinfo, COL_INFO, "%srouting", sep);
922 col_append_fstr(pinfo->cinfo, COL_INFO, "%sdestination options",
926 col_set_str(pinfo->cinfo, COL_INFO, "IPv6 no next header");
930 if (check_col(pinfo->cinfo, COL_INFO))
931 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (0x%02x)", ipprotostr(nxt),nxt);
933 call_dissector(data_handle, next_tvb, pinfo, tree);
935 pinfo->fragmented = save_fragmented;
939 proto_register_ipv6(void)
941 static hf_register_info hf[] = {
943 { "Version", "ipv6.version",
944 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
946 { "Traffic class", "ipv6.class",
947 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
949 { "Flowlabel", "ipv6.flow",
950 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
952 { "Payload length", "ipv6.plen",
953 FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
955 { "Next header", "ipv6.nxt",
956 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
958 { "Hop limit", "ipv6.hlim",
959 FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
961 { "Source", "ipv6.src",
962 FT_IPv6, BASE_NONE, NULL, 0x0,
963 "Source IPv6 Address", HFILL }},
965 { "Destination", "ipv6.dst",
966 FT_IPv6, BASE_NONE, NULL, 0x0,
967 "Destination IPv6 Address", HFILL }},
969 { "Address", "ipv6.addr",
970 FT_IPv6, BASE_NONE, NULL, 0x0,
971 "Source or Destination IPv6 Address", HFILL }},
973 { &hf_ipv6_fragment_overlap,
974 { "Fragment overlap", "ipv6.fragment.overlap",
975 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
976 "Fragment overlaps with other fragments", HFILL }},
978 { &hf_ipv6_fragment_overlap_conflict,
979 { "Conflicting data in fragment overlap", "ipv6.fragment.overlap.conflict",
980 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
981 "Overlapping fragments contained conflicting data", HFILL }},
983 { &hf_ipv6_fragment_multiple_tails,
984 { "Multiple tail fragments found", "ipv6.fragment.multipletails",
985 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
986 "Several tails were found when defragmenting the packet", HFILL }},
988 { &hf_ipv6_fragment_too_long_fragment,
989 { "Fragment too long", "ipv6.fragment.toolongfragment",
990 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
991 "Fragment contained data past end of packet", HFILL }},
993 { &hf_ipv6_fragment_error,
994 { "Defragmentation error", "ipv6.fragment.error",
995 FT_NONE, BASE_NONE, NULL, 0x0,
996 "Defragmentation error due to illegal fragments", HFILL }},
999 { "IPv6 Fragment", "ipv6.fragment",
1000 FT_NONE, BASE_NONE, NULL, 0x0,
1001 "IPv6 Fragment", HFILL }},
1003 { &hf_ipv6_fragments,
1004 { "IPv6 Fragments", "ipv6.fragments",
1005 FT_NONE, BASE_NONE, NULL, 0x0,
1006 "IPv6 Fragments", HFILL }},
1008 /* BT INSERT BEGIN */
1009 { &hf_ipv6_mipv6_type,
1010 { "Option Type ", "ipv6.mipv6_type",
1011 FT_UINT8, BASE_DEC, NULL, 0x0,
1013 { &hf_ipv6_mipv6_length,
1014 { "Option Length ", "ipv6.mipv6_length",
1015 FT_UINT8, BASE_DEC, NULL, 0x0,
1017 { &hf_ipv6_mipv6_a_flag,
1018 { "Acknowledge (A) ", "ipv6.mipv6_a_flag",
1019 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_a_flag_value),
1020 IP6_MIPv6_BU_A_FLAG,
1022 { &hf_ipv6_mipv6_h_flag,
1023 { "Home Registration (H) ", "ipv6.mipv6_h_flag",
1024 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_h_flag_value),
1025 IP6_MIPv6_BU_H_FLAG,
1027 { &hf_ipv6_mipv6_r_flag,
1028 { "Router (R) ", "ipv6.mipv6_r_flag",
1029 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_r_flag_value),
1030 IP6_MIPv6_BU_R_FLAG,
1032 { &hf_ipv6_mipv6_d_flag,
1033 { "Duplicate Address Detection (D) ", "ipv6.mipv6_d_flag",
1034 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_d_flag_value),
1035 IP6_MIPv6_BU_D_FLAG,
1037 { &hf_ipv6_mipv6_m_flag,
1038 { "MAP Registration (M) ", "ipv6.mipv6_m_flag",
1039 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_m_flag_value),
1040 IP6_MIPv6_BU_M_FLAG,
1042 { &hf_ipv6_mipv6_b_flag,
1043 { "Bicasting all (B) ", "ipv6.mipv6_b_flag",
1044 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_b_flag_value),
1045 IP6_MIPv6_BU_B_FLAG,
1047 { &hf_ipv6_mipv6_prefix_length,
1048 { "Prefix Length ", "ipv6.mipv6_prefix_length",
1049 FT_UINT8, BASE_DEC, NULL, 0x0,
1051 { &hf_ipv6_mipv6_sequence_number,
1052 { "Sequence Number ", "ipv6.mipv6_sequence_number",
1053 FT_UINT16, BASE_DEC, NULL, 0x0,
1055 { &hf_ipv6_mipv6_life_time,
1056 { "Life Time ", "ipv6.mipv6_life_time",
1057 FT_UINT32, BASE_DEC, NULL, 0x0,
1059 { &hf_ipv6_mipv6_status,
1060 { "Status ", "ipv6.mipv6_status",
1061 FT_UINT8, BASE_DEC, NULL, 0x0,
1063 { &hf_ipv6_mipv6_refresh,
1064 { "Refresh ", "ipv6.mipv6_refresh",
1065 FT_UINT32, BASE_DEC, NULL, 0x0,
1067 { &hf_ipv6_mipv6_home_address,
1068 { "Home Address ", "ipv6.mipv6_home_address",
1069 FT_IPv6, BASE_HEX, NULL, 0x0,
1071 { &hf_ipv6_mipv6_sub_type,
1072 { "Sub-Option Type ", "ipv6.mipv6_sub_type",
1073 FT_UINT8, BASE_DEC, NULL, 0x0,
1075 { &hf_ipv6_mipv6_sub_length,
1076 { "Sub-Option Length ", "ipv6.mipv6_sub_length",
1077 FT_UINT8, BASE_DEC, NULL, 0x0,
1079 { &hf_ipv6_mipv6_sub_unique_ID,
1080 { "Unique Identifier ", "ipv6.mipv6_sub_unique_ID",
1081 FT_UINT16, BASE_DEC, NULL, 0x0,
1083 { &hf_ipv6_mipv6_sub_alternative_COA,
1084 { "Alternative Care of Address ", "ipv6.mipv6_sub_alternative_COA",
1085 FT_IPv6, BASE_HEX, NULL, 0x0,
1089 #ifdef TEST_FINALHDR
1091 { "Final next header", "ipv6.final",
1092 FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }},
1095 static gint *ett[] = {
1097 &ett_ipv6_fragments,
1100 module_t *ipv6_module;
1102 proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
1103 proto_register_field_array(proto_ipv6, hf, array_length(hf));
1104 proto_register_subtree_array(ett, array_length(ett));
1106 /* Register configuration options */
1107 ipv6_module = prefs_register_protocol(proto_ipv6, NULL);
1108 prefs_register_bool_preference(ipv6_module, "defragment",
1109 "Reassemble fragmented IPv6 datagrams",
1110 "Whether fragmented IPv6 datagrams should be reassembled",
1113 register_dissector("ipv6", dissect_ipv6, proto_ipv6);
1114 register_init_routine(ipv6_reassemble_init);
1118 proto_reg_handoff_ipv6(void)
1120 dissector_handle_t ipv6_handle;
1122 data_handle = find_dissector("data");
1123 ipv6_handle = find_dissector("ipv6");
1124 dissector_add("ethertype", ETHERTYPE_IPv6, ipv6_handle);
1125 dissector_add("ppp.protocol", PPP_IPV6, ipv6_handle);
1126 dissector_add("ppp.protocol", ETHERTYPE_IPv6, ipv6_handle);
1127 dissector_add("gre.proto", ETHERTYPE_IPv6, ipv6_handle);
1128 dissector_add("ip.proto", IP_PROTO_IPV6, ipv6_handle);
1129 dissector_add("null.type", BSD_AF_INET6_BSD, ipv6_handle);
1130 dissector_add("null.type", BSD_AF_INET6_FREEBSD, ipv6_handle);
1131 dissector_add("chdlctype", ETHERTYPE_IPv6, ipv6_handle);
1132 dissector_add("fr.ietf", NLPID_IP6, ipv6_handle);
1133 dissector_add("x.25.spi", NLPID_IP6, ipv6_handle);