2 * Routines for IPv6 packet disassembly
4 * $Id: packet-ipv6.c,v 1.64 2001/10/26 18:28:16 gram 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>
47 #include "packet-ip.h"
48 #include "packet-ipsec.h"
49 #include "packet-ipv6.h"
52 #include "reassemble.h"
59 * NOTE: ipv6.nxt is not very useful as we will have chained header.
60 * now testing ipv6.final, but it raises SEGV.
64 static int proto_ipv6 = -1;
65 static int hf_ipv6_version = -1;
66 static int hf_ipv6_class = -1;
67 static int hf_ipv6_flow = -1;
68 static int hf_ipv6_plen = -1;
69 static int hf_ipv6_nxt = -1;
70 static int hf_ipv6_hlim = -1;
71 static int hf_ipv6_src = -1;
72 static int hf_ipv6_dst = -1;
73 static int hf_ipv6_addr = -1;
75 static int hf_ipv6_final = -1;
77 static int hf_ipv6_fragments = -1;
78 static int hf_ipv6_fragment = -1;
79 static int hf_ipv6_fragment_overlap = -1;
80 static int hf_ipv6_fragment_overlap_conflict = -1;
81 static int hf_ipv6_fragment_multiple_tails = -1;
82 static int hf_ipv6_fragment_too_long_fragment = -1;
83 static int hf_ipv6_fragment_error = -1;
85 static int hf_ipv6_mipv6_type = -1;
86 static int hf_ipv6_mipv6_length = -1;
87 static int hf_ipv6_mipv6_a_flag = -1;
88 static int hf_ipv6_mipv6_h_flag = -1;
89 static int hf_ipv6_mipv6_r_flag = -1;
90 static int hf_ipv6_mipv6_d_flag = -1;
91 static int hf_ipv6_mipv6_m_flag = -1;
92 static int hf_ipv6_mipv6_b_flag = -1;
93 static int hf_ipv6_mipv6_prefix_length = -1;
94 static int hf_ipv6_mipv6_sequence_number = -1;
95 static int hf_ipv6_mipv6_life_time = -1;
96 static int hf_ipv6_mipv6_status = -1;
97 static int hf_ipv6_mipv6_refresh = -1;
98 static int hf_ipv6_mipv6_home_address = -1;
99 static int hf_ipv6_mipv6_sub_type = -1;
100 static int hf_ipv6_mipv6_sub_length = -1;
101 static int hf_ipv6_mipv6_sub_unique_ID = -1;
102 static int hf_ipv6_mipv6_sub_alternative_COA = -1;
104 static gint ett_ipv6 = -1;
105 static gint ett_ipv6_fragments = -1;
106 static gint ett_ipv6_fragment = -1;
108 /* Reassemble fragmented datagrams */
109 static gboolean ipv6_reassemble = FALSE;
112 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
116 * defragmentation of IPv6
118 static GHashTable *ipv6_fragment_table = NULL;
121 ipv6_reassemble_init(void)
123 fragment_table_init(&ipv6_fragment_table);
127 dissect_routing6(tvbuff_t *tvb, int offset, proto_tree *tree) {
130 proto_tree *rthdr_tree;
132 char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
134 tvb_memcpy(tvb, (guint8 *)&rt, offset, sizeof(rt));
135 len = (rt.ip6r_len + 1) << 3;
138 /* !!! specify length */
139 ti = proto_tree_add_text(tree, tvb, offset, len,
140 "Routing Header, Type %u", rt.ip6r_type);
141 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
143 proto_tree_add_text(rthdr_tree, tvb,
144 offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
145 "Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
146 proto_tree_add_text(rthdr_tree, tvb,
147 offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
148 "Length: %u (%d bytes)", rt.ip6r_len, len);
149 proto_tree_add_text(rthdr_tree, tvb,
150 offset + offsetof(struct ip6_rthdr, ip6r_type), 1,
151 "Type: %u", rt.ip6r_type);
152 proto_tree_add_text(rthdr_tree, tvb,
153 offset + offsetof(struct ip6_rthdr, ip6r_segleft), 1,
154 "Segments left: %u", rt.ip6r_segleft);
156 if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
157 struct e_in6_addr *a;
159 struct ip6_rthdr0 *rt0;
161 tvb_memcpy(tvb, buf, offset, len);
162 rt0 = (struct ip6_rthdr0 *)buf;
163 for (a = rt0->ip6r0_addr, n = 0;
164 a < (struct e_in6_addr *)(buf + len);
166 proto_tree_add_text(rthdr_tree, tvb,
167 offset + offsetof(struct ip6_rthdr0, ip6r0_addr) + n * sizeof(struct e_in6_addr),
168 sizeof(struct e_in6_addr),
170 "address %d: %s (%s)",
171 n, get_hostname6(a), ip6_to_str(a)
173 "address %d: %s", n, ip6_to_str(a)
186 dissect_frag6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
187 guint16 *offlg, guint32 *ident) {
188 struct ip6_frag frag;
191 proto_tree *rthdr_tree;
193 tvb_memcpy(tvb, (guint8 *)&frag, offset, sizeof(frag));
195 frag.ip6f_offlg = ntohs(frag.ip6f_offlg);
196 *offlg = frag.ip6f_offlg;
197 *ident = frag.ip6f_ident;
198 if (check_col(pinfo->fd, COL_INFO)) {
199 col_add_fstr(pinfo->fd, COL_INFO,
200 "IPv6 fragment (nxt=%s (0x%02x) off=%u id=0x%x)",
201 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
202 frag.ip6f_offlg & IP6F_OFF_MASK, frag.ip6f_ident);
205 ti = proto_tree_add_text(tree, tvb, offset, len,
206 "Fragmention Header");
207 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
209 proto_tree_add_text(rthdr_tree, tvb,
210 offset + offsetof(struct ip6_frag, ip6f_nxt), 1,
211 "Next header: %s (0x%02x)",
212 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt);
215 proto_tree_add_text(rthdr_tree, tvb,
216 offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
221 proto_tree_add_text(rthdr_tree, tvb,
222 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
224 frag.ip6f_offlg & IP6F_OFF_MASK);
226 proto_tree_add_text(rthdr_tree, tvb,
227 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
228 "More fragments: %s",
229 frag.ip6f_offlg & IP6F_MORE_FRAG ?
232 proto_tree_add_text(rthdr_tree, tvb,
233 offset + offsetof(struct ip6_frag, ip6f_ident), 4,
234 "Identification: 0x%08x",
240 /* Binding Update flag description */
241 static const true_false_string ipv6_mipv6_bu_a_flag_value = {
242 "Binding Acknowledgement requested",
243 "Binding Acknowledgement not requested"
245 static const true_false_string ipv6_mipv6_bu_h_flag_value = {
247 "No Home Registration"
249 static const true_false_string ipv6_mipv6_bu_r_flag_value = {
253 static const true_false_string ipv6_mipv6_bu_d_flag_value = {
254 "Perform Duplicate Address Detection",
255 "Do not perform Duplicate Address Detection"
257 static const true_false_string ipv6_mipv6_bu_m_flag_value = {
259 "No MAP Registration"
261 static const true_false_string ipv6_mipv6_bu_b_flag_value = {
262 "Request for bicasting",
263 "Do not request for bicasting"
267 dissect_mipv6_ba(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
269 guint8 status, len = 0;
270 const char *status_text;
271 gboolean sub_options = FALSE;
273 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
274 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
275 tvb_get_guint8(tvb, offset + len),
276 "Option Type: %u (0x%02x) - Binding Acknowledgement",
277 tvb_get_guint8(tvb, offset + len),
278 tvb_get_guint8(tvb, offset + len));
279 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
280 if (tvb_get_guint8(tvb, offset + len) > 11)
282 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
283 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
284 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
285 status = tvb_get_guint8(tvb, offset + len);
288 status_text = "- Binding Update accepted";
291 status_text = "- Binding Update was rejected - Reason unspecified";
294 status_text = "- Binding Update was rejected - Administratively prohibited";
297 status_text = "- Binding Update was rejected - Insufficient resources";
300 status_text = "- Binding Update was rejected - Home registration not supported";
303 status_text = "- Binding Update was rejected - Not home subnet";
306 status_text = "- Binding Update was rejected - Incorrect interface identifier length";
309 status_text = "- Binding Update was rejected - Not home agent for this mobile node";
312 status_text = "- Binding Update was rejected - Duplicate Address Detection failed";
320 status_text = "- Binding Update was rejected";
324 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_status,
325 tvb, offset + len, IP6_MIPv6_STATUS_LENGTH,
326 tvb_get_guint8(tvb, offset + len),
327 "Status: %u %s", tvb_get_guint8(tvb, offset + len), status_text);
328 len += IP6_MIPv6_STATUS_LENGTH;
329 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number,
330 tvb, offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
331 tvb_get_ntohs(tvb, offset + len));
332 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
333 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
334 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time,
335 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
336 tvb_get_ntohl(tvb, offset + len),
337 "Life Time: %u - Infinity", tvb_get_ntohl(tvb, offset + len));
339 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time,
340 tvb, offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
341 tvb_get_ntohl(tvb, offset + len));
343 len += IP6_MIPv6_LIFE_TIME_LENGTH;
344 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_refresh, tvb,
345 offset + len, IP6_MIPv6_REFRESH_LENGTH,
346 tvb_get_ntohl(tvb, offset + len));
347 len += IP6_MIPv6_REFRESH_LENGTH;
350 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
355 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
358 gboolean sub_options = FALSE;
360 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset,
361 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb, offset),
362 "Option Type: %u (0x%02x) - Binding Update",
363 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset));
364 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
365 if (tvb_get_guint8(tvb, offset + len) > 8)
367 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
368 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
369 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
370 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_a_flag, tvb, offset + len,
371 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
372 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_h_flag, tvb, offset + len,
373 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
374 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_r_flag, tvb, offset + len,
375 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
376 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_d_flag, tvb, offset + len,
377 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
378 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_m_flag, tvb, offset + len,
379 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
380 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_b_flag, tvb, offset + len,
381 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset + len));
382 len += IP6_MIPv6_FLAGS_LENGTH;
383 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_prefix_length, tvb,
385 IP6_MIPv6_PREFIX_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
386 len += IP6_MIPv6_PREFIX_LENGTH_LENGTH;
387 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb,
388 offset + len, IP6_MIPv6_SEQUENCE_NUMBER_LENGTH,
389 tvb_get_ntohs(tvb, offset + len));
390 len += IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
391 if (tvb_get_ntohl(tvb, offset + len) == 0xffffffff) {
392 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
393 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH,
394 tvb_get_ntohl(tvb, offset + len), "Life Time: %u - Infinity",
395 tvb_get_ntohl(tvb, offset + len));
397 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb,
398 offset + len, IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,
401 len += IP6_MIPv6_LIFE_TIME_LENGTH;
404 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
409 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
412 gboolean sub_options = FALSE;
414 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
415 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
416 tvb_get_guint8(tvb, offset + len),
417 "Option Type: %u (0x%02x) - Home Address",
418 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
419 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
420 if (tvb_get_guint8(tvb, offset + len) > 16)
422 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
423 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
424 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
425 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_home_address, tvb,
426 offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH,
427 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_HOME_ADDRESS_LENGTH));
428 len += IP6_MIPv6_HOME_ADDRESS_LENGTH;
431 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
436 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
439 gboolean sub_options = FALSE;
441 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb,
442 offset + len, IP6_MIPv6_OPTION_TYPE_LENGTH,
443 tvb_get_guint8(tvb, offset + len),
444 "Option Type: %u (0x%02x) - Binding Request",
445 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
446 len += IP6_MIPv6_OPTION_TYPE_LENGTH;
447 if (tvb_get_guint8(tvb, offset + len) > 0)
449 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset + len,
450 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb, offset + len));
451 len += IP6_MIPv6_OPTION_LENGTH_LENGTH;
454 proto_tree_add_text(dstopt_tree, tvb, offset + len, 1, "Sub-Options");
459 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
463 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
464 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
465 tvb_get_guint8(tvb, offset + len),
466 "Sub-Option Type: %u (0x%02x) - Unique Identifier Sub-Option",
467 tvb_get_guint8(tvb, offset + len), tvb_get_guint8(tvb, offset + len));
468 len += IP6_MIPv6_SUB_TYPE_LENGTH;
469 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
470 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
471 tvb_get_guint8(tvb, offset + len));
472 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
473 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_unique_ID, tvb,
474 offset + len, IP6_MIPv6_SUB_UNIQUE_ID_LENGTH,
475 tvb_get_ntohs(tvb, offset + len));
476 len += IP6_MIPv6_SUB_UNIQUE_ID_LENGTH;
481 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset)
485 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_type, tvb,
486 offset + len, IP6_MIPv6_SUB_TYPE_LENGTH,
487 tvb_get_guint8(tvb, offset + len),
488 "Sub-Option Type: %u (0x%02x) - Alternative Care Of Address",
489 tvb_get_guint8(tvb, offset + len),
490 tvb_get_guint8(tvb, offset + len));
491 len += IP6_MIPv6_SUB_TYPE_LENGTH;
492 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb,
493 offset + len, IP6_MIPv6_SUB_LENGTH_LENGTH,
494 tvb_get_guint8(tvb, offset + len));
495 len += IP6_MIPv6_SUB_LENGTH_LENGTH;
496 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_sub_alternative_COA, tvb,
497 offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH,
498 tvb_get_ptr(tvb, offset + len, IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH));
499 len += IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH;
503 static const value_string rtalertvals[] = {
504 { IP6OPT_RTALERT_MLD, "MLD" },
505 { IP6OPT_RTALERT_RSVP, "RSVP" },
510 dissect_opts(tvbuff_t *tvb, int offset, proto_tree *tree, char *optname)
514 proto_tree *dstopt_tree;
518 int mip_offset = 0, delta = 0;
520 tvb_memcpy(tvb, (guint8 *)&ext, offset, sizeof(ext));
521 len = (ext.ip6e_len + 1) << 3;
524 /* !!! specify length */
525 ti = proto_tree_add_text(tree, tvb, offset, len, "%s Header ", optname);
527 dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
529 proto_tree_add_text(dstopt_tree, tvb,
530 offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
531 "Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt), ext.ip6e_nxt);
532 proto_tree_add_text(dstopt_tree, tvb,
533 offset + offsetof(struct ip6_ext, ip6e_len), 1,
534 "Length: %u (%d bytes)", ext.ip6e_len, len);
541 while (p < offset + len) {
542 switch (tvb_get_guint8(tvb, p)) {
544 proto_tree_add_text(dstopt_tree, tvb, p, 1, "Pad1");
549 tmp = tvb_get_guint8(tvb, p + 1);
550 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
551 "PadN: %u bytes", tmp + 2);
554 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
557 tmp = tvb_get_guint8(tvb, p + 1);
559 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
560 "Jumbo payload: %u (%u bytes)",
561 tvb_get_ntohl(tvb, p + 2), tmp + 2);
563 proto_tree_add_text(dstopt_tree, tvb, p, tmp + 2,
564 "Jumbo payload: Invalid length (%u bytes)",
569 mip_offset += tvb_get_guint8(tvb, mip_offset+1)+2;
575 tmp = tvb_get_guint8(tvb, p + 1);
577 rta = val_to_str(tvb_get_ntohs(tvb, p + 2), rtalertvals,
580 rta = "Invalid length";
581 ti = proto_tree_add_text(dstopt_tree, tvb, p , tmp + 2,
582 "Router alert: %s (%u bytes)", rta, tmp + 2);
585 mip_offset += tvb_get_guint8(tvb, mip_offset + 1) + 2;
588 case IP6OPT_BINDING_UPDATE :
589 delta = dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
593 case IP6OPT_BINDING_ACK :
594 delta = dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
598 case IP6OPT_HOME_ADDRESS :
599 delta = dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
603 case IP6OPT_BINDING_REQUEST :
604 delta = dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
608 case IP6OPT_MIPv6_UNIQUE_ID_SUB :
609 delta = dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
613 case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
614 delta = dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
630 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)
638 return dissect_opts(tvb, offset, tree, "Destination Option");
642 dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
644 proto_tree *ipv6_tree = NULL;
654 fragment_data *ipfd_head;
657 gboolean must_restore_pi = FALSE;
658 gboolean update_col_info = TRUE;
662 if (check_col(pinfo->fd, COL_PROTOCOL))
663 col_set_str(pinfo->fd, COL_PROTOCOL, "IPv6");
664 if (check_col(pinfo->fd, COL_INFO))
665 col_clear(pinfo->fd, COL_INFO);
668 tvb_memcpy(tvb, (guint8 *)&ipv6, offset, sizeof(ipv6));
670 pinfo->ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
672 /* Get the payload length */
673 plen = ntohs(ipv6.ip6_plen);
675 /* Adjust the length of this tvbuff to include only the IPv6 datagram. */
676 set_actual_length(tvb, pinfo, plen + sizeof (struct ip6_hdr));
678 SET_ADDRESS(&pinfo->net_src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
679 SET_ADDRESS(&pinfo->src, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_SRC, 16));
680 SET_ADDRESS(&pinfo->net_dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
681 SET_ADDRESS(&pinfo->dst, AT_IPv6, 16, tvb_get_ptr(tvb, offset + IP6H_DST, 16));
684 /* !!! specify length */
685 ti = proto_tree_add_item(tree, proto_ipv6, tvb, offset, 40, FALSE);
686 ipv6_tree = proto_item_add_subtree(ti, ett_ipv6);
688 /* !!! warning: version also contains 4 Bit priority */
689 proto_tree_add_uint(ipv6_tree, hf_ipv6_version, tvb,
690 offset + offsetof(struct ip6_hdr, ip6_vfc), 1,
691 (ipv6.ip6_vfc >> 4) & 0x0f);
693 proto_tree_add_uint(ipv6_tree, hf_ipv6_class, tvb,
694 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
695 (guint8)((ntohl(ipv6.ip6_flow) >> 20) & 0xff));
698 * there should be no alignment problems for ip6_flow, since it's the first
699 * guint32 in the ipv6 struct
701 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_flow, tvb,
702 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
703 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK),
704 "Flowlabel: 0x%05lx",
705 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK));
707 proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, tvb,
708 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
711 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, tvb,
712 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
714 "Next header: %s (0x%02x)",
715 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
717 proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, tvb,
718 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
721 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
722 offset + offsetof(struct ip6_hdr, ip6_src), 16,
723 ipv6.ip6_src.s6_addr8);
724 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, tvb,
725 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
726 ipv6.ip6_dst.s6_addr8);
728 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_src, tvb,
729 offset + offsetof(struct ip6_hdr, ip6_src), 16,
730 (guint8 *)&ipv6.ip6_src,
732 "Source address: %s (%s)",
733 get_hostname6(&ipv6.ip6_src),
735 "Source address: %s",
737 ip6_to_str(&ipv6.ip6_src));
739 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_dst, tvb,
740 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
741 (guint8 *)&ipv6.ip6_dst,
743 "Destination address: %s (%s)",
744 get_hostname6(&ipv6.ip6_dst),
746 "Destination address: %s",
748 ip6_to_str(&ipv6.ip6_dst));
751 /* start of the new header (could be a extension header) */
752 poffset = offset + offsetof(struct ip6_hdr, ip6_nxt);
753 nxt = tvb_get_guint8(tvb, poffset);
754 offset += sizeof(struct ip6_hdr);
758 /* start out assuming this isn't fragmented */
763 case IP_PROTO_HOPOPTS:
764 advance = dissect_hopopts(tvb, offset, tree);
765 nxt = tvb_get_guint8(tvb, offset);
770 case IP_PROTO_ROUTING:
771 advance = dissect_routing6(tvb, offset, tree);
772 nxt = tvb_get_guint8(tvb, offset);
777 case IP_PROTO_FRAGMENT:
779 advance = dissect_frag6(tvb, offset, pinfo, tree,
781 nxt = tvb_get_guint8(tvb, offset);
787 advance = dissect_ah_header(
788 tvb_new_subset(tvb, offset, -1, -1),
789 pinfo, tree, NULL, NULL);
790 nxt = tvb_get_guint8(tvb, offset);
795 case IP_PROTO_DSTOPTS:
796 advance = dissect_dstopts(tvb, offset, tree);
797 nxt = tvb_get_guint8(tvb, offset);
805 proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, tvb, poffset, 1, nxt);
808 /* If ipv6_reassemble is on and this is a fragment, then just add the fragment
811 if (ipv6_reassemble && frag) {
812 /* We're reassembling, and this is part of a fragmented datagram.
813 Add the fragment to the hash table if the frame isn't truncated. */
814 if (tvb_reported_length(tvb) <= tvb_length(tvb)) {
815 ipfd_head = fragment_add(tvb, offset, pinfo, ident,
817 offlg & IP6F_OFF_MASK,
819 offlg & IP6F_MORE_FRAG);
824 if (ipfd_head != NULL) {
826 proto_tree *ft = NULL;
827 proto_item *fi = NULL;
829 /* OK, we have the complete reassembled payload. */
830 /* show all fragments */
831 fi = proto_tree_add_item(ipv6_tree, hf_ipv6_fragments,
833 ft = proto_item_add_subtree(fi, ett_ipv6_fragments);
834 for (ipfd = ipfd_head->next; ipfd; ipfd = ipfd->next){
835 if (ipfd->flags & (FD_OVERLAP|FD_OVERLAPCONFLICT
836 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
837 /* this fragment has some flags set, create a subtree
838 * for it and display the flags.
840 proto_tree *fet = NULL;
841 proto_item *fei = NULL;
844 if (ipfd->flags & (FD_OVERLAPCONFLICT
845 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
846 hf = hf_ipv6_fragment_error;
848 hf = hf_ipv6_fragment;
850 fei = proto_tree_add_none_format(ft, hf,
852 "Frame:%d payload:%d-%d",
855 ipfd->offset+ipfd->len-1
857 fet = proto_item_add_subtree(fei, ett_ipv6_fragment);
858 if (ipfd->flags&FD_OVERLAP) {
859 proto_tree_add_boolean(fet,
860 hf_ipv6_fragment_overlap, tvb, 0, 0,
863 if (ipfd->flags&FD_OVERLAPCONFLICT) {
864 proto_tree_add_boolean(fet,
865 hf_ipv6_fragment_overlap_conflict, tvb, 0, 0,
868 if (ipfd->flags&FD_MULTIPLETAILS) {
869 proto_tree_add_boolean(fet,
870 hf_ipv6_fragment_multiple_tails, tvb, 0, 0,
873 if (ipfd->flags&FD_TOOLONGFRAGMENT) {
874 proto_tree_add_boolean(fet,
875 hf_ipv6_fragment_too_long_fragment, tvb, 0, 0,
879 /* nothing of interest for this fragment */
880 proto_tree_add_none_format(ft, hf_ipv6_fragment,
882 "Frame:%d payload:%d-%d",
885 ipfd->offset+ipfd->len-1
889 if (ipfd_head->flags & (FD_OVERLAPCONFLICT
890 |FD_MULTIPLETAILS|FD_TOOLONGFRAGMENT) ) {
891 if (check_col(pinfo->fd, COL_INFO)) {
892 col_set_str(pinfo->fd, COL_INFO, "[Illegal fragments]");
893 update_col_info = FALSE;
897 /* Allocate a new tvbuff, referring to the reassembled payload. */
898 next_tvb = tvb_new_real_data(ipfd_head->data, ipfd_head->datalen,
899 ipfd_head->datalen, "Reassembled");
901 /* Add the tvbuff to the list of tvbuffs to which the tvbuff we
902 were handed refers, so it'll get cleaned up when that tvbuff
904 tvb_set_child_real_data_tvbuff(tvb, next_tvb);
906 /* Add the defragmented data to the data source list. */
907 pinfo->fd->data_src = g_slist_append(pinfo->fd->data_src, next_tvb);
909 /* It's not fragmented. */
910 pinfo->fragmented = FALSE;
912 /* Save the current value of "pi", and adjust certain fields to
913 reflect the new tvbuff. */
915 pi.compat_top_tvb = next_tvb;
916 pi.len = tvb_reported_length(next_tvb);
917 pi.captured_len = tvb_length(next_tvb);
918 must_restore_pi = TRUE;
920 /* We don't have the complete reassembled payload. */
924 /* If this is the first fragment, dissect its contents, otherwise
925 just show it as a fragment.
927 XXX - if we eventually don't save the reassembled contents of all
928 fragmented datagrams, we may want to always reassemble. */
929 if (offlg & IP6F_OFF_MASK) {
930 /* Not the first fragment - don't dissect it. */
933 /* First fragment, or not fragmented. Dissect what we have here. */
935 /* Get a tvbuff for the payload. */
936 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
939 * If this is the first fragment, but not the only fragment,
940 * tell the next protocol that.
942 if (offlg & IP6F_MORE_FRAG)
943 pinfo->fragmented = TRUE;
945 pinfo->fragmented = FALSE;
949 if (next_tvb == NULL) {
950 /* Just show this as a fragment. */
951 /* COL_INFO was filled in by "dissect_frag6()" */
952 dissect_data(tvb, offset, pinfo, tree);
954 /* As we haven't reassembled anything, we haven't changed "pi", so
955 we don't have to restore it. */
959 /* do lookup with the subdissector table */
960 if (!dissector_try_port(ip_dissector_table, nxt, next_tvb, pinfo, tree)) {
961 /* Unknown protocol */
962 if (check_col(pinfo->fd, COL_INFO))
963 col_add_fstr(pinfo->fd, COL_INFO, "%s (0x%02x)", ipprotostr(nxt),nxt);
964 dissect_data(next_tvb, 0, pinfo, tree);
969 dissect_ipv6_none(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
971 if (hf_ipv6_mipv6_length != -1) {
972 if (check_col(pinfo->fd, COL_INFO))
973 col_add_fstr(pinfo->fd, COL_INFO, "Mobile IPv6 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);