2 * Routines for IPv6 packet disassembly
4 * $Id: packet-ipv6.c,v 1.51 2001/01/23 02:49:55 gerald 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>
51 #include "packet-ip.h"
52 #include "packet-ipsec.h"
53 #include "packet-ipv6.h"
54 #include "packet-tcp.h"
55 #include "packet-udp.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;
79 static int hf_ipv6_mipv6_type = -1;
80 static int hf_ipv6_mipv6_length = -1;
81 static int hf_ipv6_mipv6_a_flag = -1;
82 static int hf_ipv6_mipv6_h_flag = -1;
83 static int hf_ipv6_mipv6_r_flag = -1;
84 static int hf_ipv6_mipv6_d_flag = -1;
85 static int hf_ipv6_mipv6_m_flag = -1;
86 static int hf_ipv6_mipv6_b_flag = -1;
87 static int hf_ipv6_mipv6_prefix_length = -1;
88 static int hf_ipv6_mipv6_sequence_number = -1;
89 static int hf_ipv6_mipv6_life_time = -1;
90 static int hf_ipv6_mipv6_status = -1;
91 static int hf_ipv6_mipv6_refresh = -1;
92 static int hf_ipv6_mipv6_home_address = -1;
93 static int hf_ipv6_mipv6_sub_type = -1;
94 static int hf_ipv6_mipv6_sub_length = -1;
95 static int hf_ipv6_mipv6_sub_unique_ID = -1;
96 static int hf_ipv6_mipv6_sub_alternative_COA = -1;
99 static gint ett_ipv6 = -1;
102 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
106 dissect_routing6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
109 proto_tree *rthdr_tree;
111 char buf[sizeof(struct ip6_rthdr0) + sizeof(struct e_in6_addr) * 23];
113 memcpy(&rt, (void *) &pd[offset], sizeof(rt));
114 len = (rt.ip6r_len + 1) << 3;
117 /* !!! specify length */
118 ti = proto_tree_add_text(tree, NullTVB, offset, len,
119 "Routing Header, Type %u", rt.ip6r_type);
120 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
122 proto_tree_add_text(rthdr_tree, NullTVB,
123 offset + offsetof(struct ip6_rthdr, ip6r_nxt), 1,
124 "Next header: %s (0x%02x)", ipprotostr(rt.ip6r_nxt), rt.ip6r_nxt);
125 proto_tree_add_text(rthdr_tree, NullTVB,
126 offset + offsetof(struct ip6_rthdr, ip6r_len), 1,
127 "Length: %u (%d bytes)", rt.ip6r_len, len);
128 proto_tree_add_text(rthdr_tree, NullTVB,
129 offset + offsetof(struct ip6_rthdr, ip6r_type), 1,
130 "Type: %u", rt.ip6r_type);
131 proto_tree_add_text(rthdr_tree, NullTVB,
132 offset + offsetof(struct ip6_rthdr, ip6r_segleft), 1,
133 "Segments left: %u", rt.ip6r_segleft);
135 if (rt.ip6r_type == 0 && len <= sizeof(buf)) {
136 struct e_in6_addr *a;
138 struct ip6_rthdr0 *rt0;
140 memcpy(buf, (void *) &pd[offset], len);
141 rt0 = (struct ip6_rthdr0 *)buf;
142 for (a = rt0->ip6r0_addr, n = 0;
143 a < (struct e_in6_addr *)(buf + len);
145 proto_tree_add_text(rthdr_tree, NullTVB,
146 offset + offsetof(struct ip6_rthdr0, ip6r0_addr) + n * sizeof(struct e_in6_addr),
147 sizeof(struct e_in6_addr),
149 "address %d: %s (%s)",
150 n, get_hostname6(a), ip6_to_str(a)
152 "address %d: %s", n, ip6_to_str(a)
165 dissect_frag6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
167 struct ip6_frag frag;
170 proto_tree *rthdr_tree;
172 memcpy(&frag, (void *) &pd[offset], sizeof(frag));
174 frag.ip6f_offlg = ntohs(frag.ip6f_offlg);
175 *fragstart = frag.ip6f_offlg & IP6F_OFF_MASK;
176 if (check_col(fd, COL_INFO)) {
177 col_add_fstr(fd, COL_INFO,
178 "IPv6 fragment (nxt=%s (0x%02x) off=%u id=0x%x)",
179 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
180 *fragstart, frag.ip6f_ident);
183 ti = proto_tree_add_text(tree, NullTVB, offset, len,
184 "Fragmention Header");
185 rthdr_tree = proto_item_add_subtree(ti, ett_ipv6);
187 proto_tree_add_text(rthdr_tree, NullTVB,
188 offset + offsetof(struct ip6_frag, ip6f_nxt), 1,
189 "Next header: %s (0x%02x)",
190 ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt);
193 proto_tree_add_text(rthdr_tree, NullTVB,
194 offset + offsetof(struct ip6_frag, ip6f_reserved), 1,
199 proto_tree_add_text(rthdr_tree, NullTVB,
200 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
202 frag.ip6f_offlg & IP6F_OFF_MASK);
204 proto_tree_add_text(rthdr_tree, NullTVB,
205 offset + offsetof(struct ip6_frag, ip6f_offlg), 2,
206 "More fragments: %s",
207 frag.ip6f_offlg & IP6F_MORE_FRAG ?
210 proto_tree_add_text(rthdr_tree, NullTVB,
211 offset + offsetof(struct ip6_frag, ip6f_ident), 4,
212 "Identification: 0x%08x",
218 /* BT INSERT BEGIN */
220 dissect_mipv6_ba(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
221 guint8 status, len=0;
222 gchar status_text[80]="";
223 gboolean sub_options=FALSE;
225 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset+len,
226 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb,offset+len),
227 "Option Type: %u (0x%02x) - Binding Acknowledgement", tvb_get_guint8(tvb,offset+len),
228 tvb_get_guint8(tvb,offset+len));
229 len+=IP6_MIPv6_OPTION_TYPE_LENGTH;
230 if (tvb_get_guint8(tvb,offset+len)>11)
232 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset+len,
233 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
234 len+=IP6_MIPv6_OPTION_LENGTH_LENGTH;
235 status = tvb_get_guint8(tvb,offset+len);
238 strcpy(status_text,"- Binding Update accepted");
241 strcpy(status_text,"- Binding Update was rejected - Reason unspecified");
244 strcpy(status_text,"- Binding Update was rejected - Administratively prohibited");
247 strcpy(status_text,"- Binding Update was rejected - Insufficient resources");
250 strcpy(status_text,"- Binding Update was rejected - Home registration not supported");
253 strcpy(status_text,"- Binding Update was rejected - Not home subnet");
256 strcpy(status_text,"- Binding Update was rejected - Incorrect interface identifier length");
259 strcpy(status_text,"- Binding Update was rejected - Not home agent for this mobile node");
262 strcpy(status_text,"- Binding Update was rejected - Duplicate Address Detection failed");
265 strcpy(status_text,"");
268 if ((status>128)&&(strlen(status_text)==0))
269 strcpy(status_text,"- Binding Update was rejected");
270 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_status, tvb, offset+len,
271 IP6_MIPv6_STATUS_LENGTH, tvb_get_guint8(tvb,offset+len),
272 "Status: %u %s", tvb_get_guint8(tvb,offset+len), status_text);
273 len+=IP6_MIPv6_STATUS_LENGTH;
274 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb, offset+len,
275 IP6_MIPv6_SEQUENCE_NUMBER_LENGTH, tvb_get_ntohs(tvb,offset+len));
276 len+=IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
277 if (tvb_get_ntohl(tvb,offset+len)==0xffffffff)
279 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb, offset+len,
280 IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,offset+len),
281 "Life Time: %u - Infinity", tvb_get_ntohl(tvb,offset+len));
284 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb, offset+len,
285 IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,offset+len));
287 len+=IP6_MIPv6_LIFE_TIME_LENGTH;
288 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_refresh, tvb, offset+len,
289 IP6_MIPv6_REFRESH_LENGTH, tvb_get_ntohl(tvb,offset+len));
290 len+=IP6_MIPv6_REFRESH_LENGTH;
294 proto_tree_add_text(dstopt_tree, NullTVB, offset+len, 1, "Sub-Options");
300 dissect_mipv6_bu(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
302 gboolean sub_options=FALSE;
304 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset,
305 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb,offset),
306 "Option Type: %u (0x%02x) - Binding Update", tvb_get_guint8(tvb,offset),
307 tvb_get_guint8(tvb,offset));
308 len+=IP6_MIPv6_OPTION_TYPE_LENGTH;
309 if (tvb_get_guint8(tvb,offset+len)>8)
311 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset+len,
312 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
313 len+=IP6_MIPv6_OPTION_LENGTH_LENGTH;
314 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_a_flag, tvb, offset+len,
315 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
316 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_h_flag, tvb, offset+len,
317 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
318 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_r_flag, tvb, offset+len,
319 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
320 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_d_flag, tvb, offset+len,
321 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
322 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_m_flag, tvb, offset+len,
323 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
324 proto_tree_add_boolean(dstopt_tree, hf_ipv6_mipv6_b_flag, tvb, offset+len,
325 IP6_MIPv6_FLAGS_LENGTH, tvb_get_guint8(tvb, offset+len));
326 len+=IP6_MIPv6_FLAGS_LENGTH;
327 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_prefix_length, tvb, offset+len,
328 IP6_MIPv6_PREFIX_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
329 len+=IP6_MIPv6_PREFIX_LENGTH_LENGTH;
330 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sequence_number, tvb, offset+len,
331 IP6_MIPv6_SEQUENCE_NUMBER_LENGTH, tvb_get_ntohs(tvb,offset+len));
332 len+=IP6_MIPv6_SEQUENCE_NUMBER_LENGTH;
333 if (tvb_get_ntohl(tvb,offset+len)==0xffffffff)
335 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_life_time, tvb, offset+len,
336 IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,offset+len),
337 "Life Time: %u - Infinity", tvb_get_ntohl(tvb,offset+len));
340 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_life_time, tvb, offset+len,
341 IP6_MIPv6_LIFE_TIME_LENGTH, tvb_get_ntohl(tvb,offset+len));
343 len+=IP6_MIPv6_LIFE_TIME_LENGTH;
347 proto_tree_add_text(dstopt_tree, NullTVB, offset+len, 1, "Sub-Options");
353 dissect_mipv6_ha(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
355 gboolean sub_options=FALSE;
357 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset+len,
358 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb,offset+len),
359 "Option Type: %u (0x%02x) - Home Address", tvb_get_guint8(tvb,offset+len),
360 tvb_get_guint8(tvb,offset+len));
361 len+=IP6_MIPv6_OPTION_TYPE_LENGTH;
362 if (tvb_get_guint8(tvb,offset+len)>16)
364 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset+len,
365 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
366 len+=IP6_MIPv6_OPTION_LENGTH_LENGTH;
367 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_home_address, tvb, offset+len,
368 IP6_MIPv6_HOME_ADDRESS_LENGTH, tvb_get_ptr(tvb,offset+len,IP6_MIPv6_HOME_ADDRESS_LENGTH));
369 len+=IP6_MIPv6_HOME_ADDRESS_LENGTH;
373 proto_tree_add_text(dstopt_tree, NullTVB, offset+len, 1, "Sub-Options");
379 dissect_mipv6_br(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
381 gboolean sub_options=FALSE;
383 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_type, tvb, offset+len,
384 IP6_MIPv6_OPTION_TYPE_LENGTH, tvb_get_guint8(tvb,offset+len),
385 "Option Type: %u (0x%02x) - Binding Request", tvb_get_guint8(tvb,offset+len),
386 tvb_get_guint8(tvb,offset+len));
387 len+=IP6_MIPv6_OPTION_TYPE_LENGTH;
388 if (tvb_get_guint8(tvb,offset+len)>0)
390 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_length, tvb, offset+len,
391 IP6_MIPv6_OPTION_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
392 len+=IP6_MIPv6_OPTION_LENGTH_LENGTH;
396 proto_tree_add_text(dstopt_tree, NullTVB, offset+len, 1, "Sub-Options");
402 dissect_mipv6_sub_u(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
405 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb, offset+len,
406 IP6_MIPv6_SUB_TYPE_LENGTH, tvb_get_guint8(tvb,offset+len),
407 "Sub-Option Type: %u (0x%02x) - Unique Identifier Sub-Option", tvb_get_guint8(tvb,offset+len),
408 tvb_get_guint8(tvb,offset+len));
409 len+=IP6_MIPv6_SUB_TYPE_LENGTH;
410 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb, offset+len,
411 IP6_MIPv6_SUB_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
412 len+=IP6_MIPv6_SUB_LENGTH_LENGTH;
413 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_unique_ID, tvb, offset+len,
414 IP6_MIPv6_SUB_UNIQUE_ID_LENGTH, tvb_get_ntohs(tvb,offset+len));
415 len+=IP6_MIPv6_SUB_UNIQUE_ID_LENGTH;
420 dissect_mipv6_sub_a_coa(tvbuff_t *tvb, proto_tree *dstopt_tree, int offset) {
423 proto_tree_add_uint_format(dstopt_tree, hf_ipv6_mipv6_sub_type, tvb, offset+len,
424 IP6_MIPv6_SUB_TYPE_LENGTH, tvb_get_guint8(tvb,offset+len),
425 "Sub-Option Type: %u (0x%02x) - Alternative Care Of Address", tvb_get_guint8(tvb,offset+len),
426 tvb_get_guint8(tvb,offset+len));
427 len+=IP6_MIPv6_SUB_TYPE_LENGTH;
428 proto_tree_add_uint(dstopt_tree, hf_ipv6_mipv6_sub_length, tvb, offset+len,
429 IP6_MIPv6_SUB_LENGTH_LENGTH, tvb_get_guint8(tvb,offset+len));
430 len+=IP6_MIPv6_SUB_LENGTH_LENGTH;
431 proto_tree_add_ipv6(dstopt_tree, hf_ipv6_mipv6_sub_alternative_COA, tvb, offset+len,
432 IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH, tvb_get_ptr(tvb,offset+len,IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH));
433 len+=IP6_MIPv6_SUB_ALTERNATIVE_COA_LENGTH;
439 dissect_opts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree,
443 proto_tree *dstopt_tree;
447 /* BT INSERT BEGIN */
449 int mip_offset=0, delta=0;
452 static const value_string rtalertvals[] = {
453 { IP6OPT_RTALERT_MLD, "MLD" },
454 { IP6OPT_RTALERT_RSVP, "RSVP" },
458 memcpy(&ext, (void *) &pd[offset], sizeof(ext));
459 len = (ext.ip6e_len + 1) << 3;
461 /* BT INSERT BEGIN */
462 tvb = tvb_create_from_top(offset);
466 /* !!! specify length */
467 ti = proto_tree_add_text(tree, NullTVB, offset, len,
468 "%s Header ", optname);
470 dstopt_tree = proto_item_add_subtree(ti, ett_ipv6);
472 proto_tree_add_text(dstopt_tree, NullTVB,
473 offset + offsetof(struct ip6_ext, ip6e_nxt), 1,
474 "Next header: %s (0x%02x)", ipprotostr(ext.ip6e_nxt),ext.ip6e_nxt);
475 proto_tree_add_text(dstopt_tree, NullTVB,
476 offset + offsetof(struct ip6_ext, ip6e_len), 1,
477 "Length: %u (%d bytes)", ext.ip6e_len, len);
479 /* BT INSERT BEGIN */
483 p = (u_char *)(pd + offset + 2);
485 while (p < pd + offset + len) {
488 proto_tree_add_text(dstopt_tree, NullTVB, p - pd, 1,
491 /* BT INSERT BEGIN */
496 proto_tree_add_text(dstopt_tree, NullTVB, p - pd, p[1] + 2,
497 "PadN: %u bytes", p[1] + 2);
500 /* BT INSERT BEGIN */
501 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
506 proto_tree_add_text(dstopt_tree, NullTVB, p - pd, p[1] + 2,
507 "Jumbo payload: %u (%u bytes)",
508 pntohl(&p[2]), p[1] + 2);
510 proto_tree_add_text(dstopt_tree, NullTVB, p - pd, p[1] + 2,
511 "Jumbo payload: Invalid length (%u bytes)",
516 /* BT INSERT BEGIN */
517 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
525 rta = val_to_str(pntohs(&p[2]), rtalertvals,
528 rta = "Invalid length";
529 ti = proto_tree_add_text(dstopt_tree, NullTVB, p - pd, p[1] + 2,
530 "Router alert: %s (%u bytes)", rta, p[1] + 2);
533 /* BT INSERT BEGIN */
534 mip_offset+=tvb_get_guint8(tvb,mip_offset+1)+2;
538 /* BT INSERT BEGIN */
539 case IP6OPT_BINDING_UPDATE :
541 delta=dissect_mipv6_bu(tvb, dstopt_tree, mip_offset);
546 case IP6OPT_BINDING_ACK :
548 delta=dissect_mipv6_ba(tvb, dstopt_tree, mip_offset);
553 case IP6OPT_HOME_ADDRESS :
555 delta=dissect_mipv6_ha(tvb, dstopt_tree, mip_offset);
560 case IP6OPT_BINDING_REQUEST :
562 delta=dissect_mipv6_br(tvb, dstopt_tree, mip_offset);
567 case IP6OPT_MIPv6_UNIQUE_ID_SUB :
569 delta=dissect_mipv6_sub_u(tvb, dstopt_tree, mip_offset);
574 case IP6OPT_MIPv6_ALTERNATIVE_COA_SUB :
576 delta=dissect_mipv6_sub_a_coa(tvb, dstopt_tree, mip_offset);
583 p = (u_char *)(pd + offset + len);
595 dissect_hopopts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
596 return dissect_opts(pd, offset, fd, tree, "Hop-by-hop Option");
600 dissect_dstopts(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
601 return dissect_opts(pd, offset, fd, tree, "Destination Option");
605 dissect_ipv6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
606 proto_tree *ipv6_tree;
615 OLD_CHECK_DISPLAY_AS_DATA(proto_ipv6, pd, offset, fd, tree);
617 memcpy(&ipv6, (void *) &pd[offset], sizeof(ipv6));
619 pi.ipproto = ipv6.ip6_nxt; /* XXX make work TCP follow (ipproto = 6) */
621 SET_ADDRESS(&pi.net_src, AT_IPv6, 16, &pd[offset + IP6H_SRC]);
622 SET_ADDRESS(&pi.src, AT_IPv6, 16, &pd[offset + IP6H_SRC]);
623 SET_ADDRESS(&pi.net_dst, AT_IPv6, 16, &pd[offset + IP6H_DST]);
624 SET_ADDRESS(&pi.dst, AT_IPv6, 16, &pd[offset + IP6H_DST]);
627 /* !!! specify length */
628 ti = proto_tree_add_item(tree, proto_ipv6, NullTVB, offset, 40, FALSE);
629 ipv6_tree = proto_item_add_subtree(ti, ett_ipv6);
631 /* !!! warning: version also contains 4 Bit priority */
632 proto_tree_add_uint(ipv6_tree, hf_ipv6_version, NullTVB,
633 offset + offsetof(struct ip6_hdr, ip6_vfc), 1,
634 (ipv6.ip6_vfc >> 4) & 0x0f);
637 proto_tree_add_uint(ipv6_tree, hf_ipv6_class, NullTVB,
638 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
639 (guint8)((ntohl(ipv6.ip6_flow) >> 20) & 0xff));
642 * there should be no alignment problems for ip6_flow, since it's the first
643 * guint32 in the ipv6 struct
645 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_flow, NullTVB,
646 offset + offsetof(struct ip6_hdr, ip6_flow), 4,
647 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK),
648 "Flowlabel: 0x%05lx",
649 (unsigned long)(ntohl(ipv6.ip6_flow) & IPV6_FLOWLABEL_MASK));
651 proto_tree_add_uint(ipv6_tree, hf_ipv6_plen, NullTVB,
652 offset + offsetof(struct ip6_hdr, ip6_plen), 2,
653 ntohs(ipv6.ip6_plen));
655 proto_tree_add_uint_format(ipv6_tree, hf_ipv6_nxt, NullTVB,
656 offset + offsetof(struct ip6_hdr, ip6_nxt), 1,
658 "Next header: %s (0x%02x)",
659 ipprotostr(ipv6.ip6_nxt), ipv6.ip6_nxt);
661 proto_tree_add_uint(ipv6_tree, hf_ipv6_hlim, NullTVB,
662 offset + offsetof(struct ip6_hdr, ip6_hlim), 1,
665 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, NullTVB,
666 offset + offsetof(struct ip6_hdr, ip6_src), 16,
667 ipv6.ip6_src.s6_addr8);
668 proto_tree_add_ipv6_hidden(ipv6_tree, hf_ipv6_addr, NullTVB,
669 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
670 ipv6.ip6_dst.s6_addr8);
672 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_src, NullTVB,
673 offset + offsetof(struct ip6_hdr, ip6_src), 16,
674 (guint8 *)&ipv6.ip6_src,
676 "Source address: %s (%s)",
677 get_hostname6(&ipv6.ip6_src),
679 "Source address: %s",
681 ip6_to_str(&ipv6.ip6_src));
683 proto_tree_add_ipv6_format(ipv6_tree, hf_ipv6_dst, NullTVB,
684 offset + offsetof(struct ip6_hdr, ip6_dst), 16,
685 (guint8 *)&ipv6.ip6_dst,
687 "Destination address: %s (%s)",
688 get_hostname6(&ipv6.ip6_dst),
690 "Destination address: %s",
692 ip6_to_str(&ipv6.ip6_dst));
695 /* start of the new header (could be a extension header) */
696 nxt = pd[poffset = offset + offsetof(struct ip6_hdr, ip6_nxt)];
697 offset += sizeof(struct ip6_hdr);
700 /* start out assuming this insn't fragmented */
701 pi.fragmented = FALSE;
705 case IP_PROTO_HOPOPTS:
706 advance = dissect_hopopts(pd, offset, fd, tree);
707 nxt = pd[poffset = offset];
710 case IP_PROTO_ROUTING:
711 advance = dissect_routing6(pd, offset, fd, tree);
712 nxt = pd[poffset = offset];
715 case IP_PROTO_FRAGMENT:
716 pi.fragmented = TRUE;
717 advance = dissect_frag6(pd, offset, fd, tree, &frag);
718 nxt = pd[poffset = offset];
722 advance = dissect_ah_old(pd, offset, fd, tree);
723 nxt = pd[poffset = offset];
726 case IP_PROTO_DSTOPTS:
727 advance = dissect_dstopts(pd, offset, fd, tree);
728 nxt = pd[poffset = offset];
734 proto_tree_add_uint_hidden(ipv6_tree, hf_ipv6_final, NullTVB, poffset, 1, nxt);
738 if (check_col(fd, COL_PROTOCOL))
739 col_set_str(fd, COL_PROTOCOL, "IPv6");
740 /* COL_INFO was filled in by "dissect_frag6()" */
741 old_dissect_data(pd, offset, fd, tree);
743 /* do lookup with the subdissector table */
744 if (!old_dissector_try_port(ip_dissector_table, nxt, pd, offset, fd, tree)) {
745 /* Unknown protocol */
746 if (check_col(fd, COL_PROTOCOL))
747 col_set_str(fd, COL_PROTOCOL, "IPv6");
748 if (check_col(fd, COL_INFO))
749 col_add_fstr(fd, COL_INFO, "%s (0x%02x)", ipprotostr(nxt),nxt);
750 old_dissect_data(pd, offset, fd, tree);
756 dissect_ipv6_none(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
757 /* BT INSERT BEGIN */
758 if (hf_ipv6_mipv6_length!=-1) {
759 if (check_col(fd, COL_PROTOCOL))
760 col_set_str(fd, COL_PROTOCOL, "IPv6");
761 if (check_col(fd, COL_INFO))
762 col_add_fstr(fd, COL_INFO, "MobileIPv6 Destination Option");
765 if (check_col(fd, COL_INFO))
766 col_add_fstr(fd, COL_INFO, "IPv6 no next header");
768 /* XXX - dissect the payload as padding? */
772 proto_register_ipv6(void)
774 static hf_register_info hf[] = {
776 { "Version", "ipv6.version",
777 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
779 { "Traffic class", "ipv6.class",
780 FT_UINT8, BASE_HEX, NULL, 0x0, "" }},
782 { "Flowlabel", "ipv6.flow",
783 FT_UINT32, BASE_HEX, NULL, 0x0, "" }},
785 { "Payload length", "ipv6.plen",
786 FT_UINT16, BASE_DEC, NULL, 0x0, "" }},
788 { "Next header", "ipv6.nxt",
789 FT_UINT8, BASE_HEX, NULL, 0x0, "" }},
791 { "Hop limit", "ipv6.hlim",
792 FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
794 { "Source", "ipv6.src",
795 FT_IPv6, BASE_NONE, NULL, 0x0,
796 "Source IPv6 Address" }},
798 { "Destination", "ipv6.dst",
799 FT_IPv6, BASE_NONE, NULL, 0x0,
800 "Destination IPv6 Address" }},
802 { "Address", "ipv6.addr",
803 FT_IPv6, BASE_NONE, NULL, 0x0,
804 "Source or Destination IPv6 Address" }},
806 /* BT INSERT BEGIN */
807 { &hf_ipv6_mipv6_type,
808 { "Option Type ", "ipv6.mipv6_type",
809 FT_UINT8, BASE_DEC, NULL, 0x0,
811 { &hf_ipv6_mipv6_length,
812 { "Option Length ", "ipv6.mipv6_length",
813 FT_UINT8, BASE_DEC, NULL, 0x0,
815 { &hf_ipv6_mipv6_a_flag,
816 { "Acknowledge (A) ", "ipv6.mipv6_a_flag",
817 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_a_flag_value),
820 { &hf_ipv6_mipv6_h_flag,
821 { "Home Registration (H) ", "ipv6.mipv6_h_flag",
822 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_h_flag_value),
825 { &hf_ipv6_mipv6_r_flag,
826 { "Router (R) ", "ipv6.mipv6_r_flag",
827 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_r_flag_value),
830 { &hf_ipv6_mipv6_d_flag,
831 { "Duplicate Address Detection (D) ", "ipv6.mipv6_d_flag",
832 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_d_flag_value),
835 { &hf_ipv6_mipv6_m_flag,
836 { "MAP Registration (M) ", "ipv6.mipv6_m_flag",
837 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_m_flag_value),
840 { &hf_ipv6_mipv6_b_flag,
841 { "Bicasting all (B) ", "ipv6.mipv6_b_flag",
842 FT_BOOLEAN, 8, TFS(&ipv6_mipv6_bu_b_flag_value),
845 { &hf_ipv6_mipv6_prefix_length,
846 { "Prefix Length ", "ipv6.mipv6_prefix_length",
847 FT_UINT8, BASE_DEC, NULL, 0x0,
849 { &hf_ipv6_mipv6_sequence_number,
850 { "Sequence Number ", "ipv6.mipv6_sequence_number",
851 FT_UINT16, BASE_DEC, NULL, 0x0,
853 { &hf_ipv6_mipv6_life_time,
854 { "Life Time ", "ipv6.mipv6_life_time",
855 FT_UINT32, BASE_DEC, NULL, 0x0,
857 { &hf_ipv6_mipv6_status,
858 { "Status ", "ipv6.mipv6_status",
859 FT_UINT8, BASE_DEC, NULL, 0x0,
861 { &hf_ipv6_mipv6_refresh,
862 { "Refresh ", "ipv6.mipv6_refresh",
863 FT_UINT32, BASE_DEC, NULL, 0x0,
865 { &hf_ipv6_mipv6_home_address,
866 { "Home Address ", "ipv6.mipv6_home_address",
867 FT_IPv6, BASE_HEX, NULL, 0x0,
869 { &hf_ipv6_mipv6_sub_type,
870 { "Sub-Option Type ", "ipv6.mipv6_sub_type",
871 FT_UINT8, BASE_NONE, NULL, 0x0,
873 { &hf_ipv6_mipv6_sub_length,
874 { "Sub-Option Length ", "ipv6.mipv6_sub_length",
875 FT_UINT8, BASE_NONE, NULL, 0x0,
877 { &hf_ipv6_mipv6_sub_unique_ID,
878 { "Unique Identifier ", "ipv6.mipv6_sub_unique_ID",
879 FT_UINT16, BASE_NONE, NULL, 0x0,
881 { &hf_ipv6_mipv6_sub_alternative_COA,
882 { "Alternative Care of Address ", "ipv6.mipv6_sub_alternative_COA",
883 FT_IPv6, BASE_HEX, NULL, 0x0,
889 { "Final next header", "ipv6.final",
890 FT_UINT8, BASE_HEX, NULL, 0x0, "" }},
893 static gint *ett[] = {
897 proto_ipv6 = proto_register_protocol("Internet Protocol Version 6", "IPv6", "ipv6");
898 proto_register_field_array(proto_ipv6, hf, array_length(hf));
899 proto_register_subtree_array(ett, array_length(ett));
903 proto_reg_handoff_ipv6(void)
905 old_dissector_add("ethertype", ETHERTYPE_IPv6, dissect_ipv6, proto_ipv6);
906 old_dissector_add("ppp.protocol", PPP_IPV6, dissect_ipv6, proto_ipv6);
907 old_dissector_add("ip.proto", IP_PROTO_IPV6, dissect_ipv6, proto_ipv6);
908 old_dissector_add("null.type", BSD_AF_INET6_BSD, dissect_ipv6, proto_ipv6);
909 old_dissector_add("null.type", BSD_AF_INET6_FREEBSD, dissect_ipv6, proto_ipv6);
910 old_dissector_add("ip.proto", IP_PROTO_NONE, dissect_ipv6_none, proto_ipv6);