2 * Definitions for IPv6 packet disassembly
4 * $Id: packet-ipv6.h,v 1.32 2003/12/19 23:20:53 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * MobileIPv6 support added by Tomislav Borosa <tomislav.borosa@siemens.hr>
13 * HMIPv6 support added by Martti Kuparinen <martti.kuparinen@iki.fi>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifndef __PACKET_IPV6_H_DEFINED__
31 #define __PACKET_IPV6_H_DEFINED__
33 #include <epan/ipv6-utils.h>
35 #define INET6_ADDRSTRLEN 46
38 * Definition for internet protocol version 6.
44 guint32 ip6_un1_flow; /* 20 bits of flow-ID */
45 guint16 ip6_un1_plen; /* payload length */
46 guint8 ip6_un1_nxt; /* next header */
47 guint8 ip6_un1_hlim; /* hop limit */
49 guint8 ip6_un2_vfc; /* 4 bits version, 4 bits class */
51 struct e_in6_addr ip6_src; /* source address */
52 struct e_in6_addr ip6_dst; /* destination address */
55 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
56 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
57 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
58 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
59 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
60 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
62 /* Offsets of fields within an IPv6 header. */
64 #define IP6H_CTL_FLOW 0
65 #define IP6H_CTL_PLEN 4
66 #define IP6H_CTL_NXT 6
67 #define IP6H_CTL_HLIM 7
68 #define IP6H_CTL_VFC 0
72 #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
73 #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
84 /* Hop-by-Hop options header */
85 /* XXX should we pad it to force alignment on an 8-byte boundary? */
87 guint8 ip6h_nxt; /* next header */
88 guint8 ip6h_len; /* length in units of 8 octets */
89 /* followed by options */
92 /* Destination options header */
93 /* XXX should we pad it to force alignment on an 8-byte boundary? */
95 guint8 ip6d_nxt; /* next header */
96 guint8 ip6d_len; /* length in units of 8 octets */
97 /* followed by options */
100 /* Option types and related macros */
101 #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
102 #define IP6OPT_PADN 0x01 /* 00 0 00001 */
103 #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
104 #define IP6OPT_JUMBO_LEN 6
105 #define IP6OPT_RTALERT 0x05 /* 00 0 00101 */
107 #define IP6OPT_RTALERT_LEN 4
108 #define IP6OPT_RTALERT_MLD 0 /* Datagram contains MLD message */
109 #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains RSVP message */
110 #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
111 #define IP6OPT_MINLEN 2
113 #define IP6OPT_HOME_ADDRESS 0xC9 /* 11 0 01001 */
115 #define IP6OPT_TYPE(o) ((o) & 0xC0)
116 #define IP6OPT_TYPE_SKIP 0x00
117 #define IP6OPT_TYPE_DISCARD 0x40
118 #define IP6OPT_TYPE_FORCEICMP 0x80
119 #define IP6OPT_TYPE_ICMP 0xC0
121 #define IP6OPT_MUTABLE 0x20
125 guint8 ip6r_nxt; /* next header */
126 guint8 ip6r_len; /* length in units of 8 octets */
127 guint8 ip6r_type; /* routing type */
128 guint8 ip6r_segleft; /* segments left */
129 /* followed by routing type specific data */
132 /* Type 0 Routing header */
134 guint8 ip6r0_nxt; /* next header */
135 guint8 ip6r0_len; /* length in units of 8 octets */
136 guint8 ip6r0_type; /* always zero */
137 guint8 ip6r0_segleft; /* segments left */
138 guint8 ip6r0_reserved; /* reserved field */
139 guint8 ip6r0_slmap[3]; /* strict/loose bit map */
140 struct e_in6_addr ip6r0_addr[1]; /* up to 23 addresses */
143 /* Fragment header */
145 guint8 ip6f_nxt; /* next header */
146 guint8 ip6f_reserved; /* reserved field */
147 guint16 ip6f_offlg; /* offset, reserved, and flag */
148 guint32 ip6f_ident; /* identification */
151 #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
152 #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
153 #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
156 * Definition for ICMPv6.
160 #define ICMPV6_PLD_MAXLEN 1232 /* IPV6_MMTU - sizeof(struct ip6_hdr)
161 - sizeof(struct icmp6_hdr) */
164 guint8 icmp6_type; /* type field */
165 guint8 icmp6_code; /* code field */
166 guint16 icmp6_cksum; /* checksum field */
168 guint32 icmp6_un_data32[1]; /* type-specific field */
169 guint16 icmp6_un_data16[2]; /* type-specific field */
170 guint8 icmp6_un_data8[4]; /* type-specific field */
174 #define icmp6_data32 icmp6_dataun.icmp6_un_data32
175 #define icmp6_data16 icmp6_dataun.icmp6_un_data16
176 #define icmp6_data8 icmp6_dataun.icmp6_un_data8
177 #define icmp6_pptr icmp6_data32[0] /* parameter prob */
178 #define icmp6_mtu icmp6_data32[0] /* packet too big */
179 #define icmp6_id icmp6_data16[0] /* echo request/reply */
180 #define icmp6_seq icmp6_data16[1] /* echo request/reply */
181 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */
183 #define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */
184 #define ICMP6_PACKET_TOO_BIG 2 /* packet too big */
185 #define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */
186 #define ICMP6_PARAM_PROB 4 /* ip6 header bad */
188 #define ICMP6_ECHO_REQUEST 128 /* echo service */
189 #define ICMP6_ECHO_REPLY 129 /* echo reply */
190 #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */
191 #define MLD6_LISTENER_QUERY 130 /* multicast listener query */
192 #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */
193 #define MLD6_LISTENER_REPORT 131 /* multicast listener report */
194 #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */
195 #define MLD6_LISTENER_DONE 132 /* multicast listener done */
197 #define ND_ROUTER_SOLICIT 133 /* router solicitation */
198 #define ND_ROUTER_ADVERT 134 /* router advertisment */
199 #define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */
200 #define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisment */
201 #define ND_REDIRECT 137 /* redirect */
203 #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */
205 #define ICMP6_WRUREQUEST 139 /* who are you request */
206 #define ICMP6_WRUREPLY 140 /* who are you reply */
207 #define ICMP6_FQDN_QUERY 139 /* FQDN query */
208 #define ICMP6_FQDN_REPLY 140 /* FQDN reply */
209 #define ICMP6_NI_QUERY 139 /* node information request */
210 #define ICMP6_NI_REPLY 140 /* node information reply */
212 /* The definitions below are experimental. TBA */
213 #define MLD6_MTRACE_RESP 141 /* mtrace response(to sender) */
214 #define MLD6_MTRACE 142 /* mtrace messages */
216 #define ICMP6_MIP6_DHAAD_REQUEST 144 /* Mobile IPv6 DHAAD */
217 #define ICMP6_MIP6_DHAAD_REPLY 145 /* Mobile IPv6 DHAAD */
218 #define ICMP6_MIP6_MPS 146 /* Mobile IPv6 MPS */
219 #define ICMP6_MIP6_MPA 147 /* Mobile IPv6 MPA */
221 #define ICMP6_MLDV2_REPORT 206 /* MLD v2 report message : draft-vida-mld-v2-03.txt */
222 #define ICMP6_MAXTYPE 153
224 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
225 #define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */
226 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */
227 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
228 #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */
229 #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */
231 #define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */
232 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */
234 #define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */
235 #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */
236 #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */
238 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */
240 #define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */
241 #define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */
242 #define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */
244 #define ICMP6_NI_SUCCESS 0 /* node information successful reply */
245 #define ICMP6_NI_REFUSED 1 /* node information request is refused */
246 #define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */
248 #define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */
249 #define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */
250 #define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */
253 * Multicast Listener Discovery
256 struct icmp6_hdr mld6_hdr;
257 struct e_in6_addr mld6_addr; /* multicast address */
260 #define mld6_type mld6_hdr.icmp6_type
261 #define mld6_code mld6_hdr.icmp6_code
262 #define mld6_cksum mld6_hdr.icmp6_cksum
263 #define mld6_maxdelay mld6_hdr.icmp6_data16[0]
264 #define mld6_reserved mld6_hdr.icmp6_data16[1]
270 struct nd_router_solicit { /* router solicitation */
271 struct icmp6_hdr nd_rs_hdr;
272 /* could be followed by options */
275 #define nd_rs_type nd_rs_hdr.icmp6_type
276 #define nd_rs_code nd_rs_hdr.icmp6_code
277 #define nd_rs_cksum nd_rs_hdr.icmp6_cksum
278 #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
280 struct nd_router_advert { /* router advertisement */
281 struct icmp6_hdr nd_ra_hdr;
282 guint32 nd_ra_reachable; /* reachable time */
283 guint32 nd_ra_retransmit; /* retransmit timer */
284 /* could be followed by options */
287 #define nd_ra_type nd_ra_hdr.icmp6_type
288 #define nd_ra_code nd_ra_hdr.icmp6_code
289 #define nd_ra_cksum nd_ra_hdr.icmp6_cksum
290 #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0]
291 #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
292 #define ND_RA_FLAG_MANAGED 0x80
293 #define ND_RA_FLAG_OTHER 0x40
294 #define ND_RA_FLAG_HOME_AGENT 0x20
297 * Router preference values based on draft-draves-ipngwg-router-selection-01.
298 * These are non-standard definitions.
300 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
302 #define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
303 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
304 #define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
305 #define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
307 #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
309 struct nd_neighbor_solicit { /* neighbor solicitation */
310 struct icmp6_hdr nd_ns_hdr;
311 struct e_in6_addr nd_ns_target; /*target address */
312 /* could be followed by options */
315 #define nd_ns_type nd_ns_hdr.icmp6_type
316 #define nd_ns_code nd_ns_hdr.icmp6_code
317 #define nd_ns_cksum nd_ns_hdr.icmp6_cksum
318 #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0]
320 struct nd_neighbor_advert { /* neighbor advertisement */
321 struct icmp6_hdr nd_na_hdr;
322 struct e_in6_addr nd_na_target; /* target address */
323 /* could be followed by options */
326 #define nd_na_type nd_na_hdr.icmp6_type
327 #define nd_na_code nd_na_hdr.icmp6_code
328 #define nd_na_cksum nd_na_hdr.icmp6_cksum
329 #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0]
330 #define ND_NA_FLAG_ROUTER 0x80000000
331 #define ND_NA_FLAG_SOLICITED 0x40000000
332 #define ND_NA_FLAG_OVERRIDE 0x20000000
334 struct nd_redirect { /* redirect */
335 struct icmp6_hdr nd_rd_hdr;
336 struct e_in6_addr nd_rd_target; /* target address */
337 struct e_in6_addr nd_rd_dst; /* destination address */
338 /* could be followed by options */
341 #define nd_rd_type nd_rd_hdr.icmp6_type
342 #define nd_rd_code nd_rd_hdr.icmp6_code
343 #define nd_rd_cksum nd_rd_hdr.icmp6_cksum
344 #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
346 struct nd_opt_hdr { /* Neighbor discovery option header */
349 /* followed by option specific data*/
352 #define ND_OPT_SOURCE_LINKADDR 1
353 #define ND_OPT_TARGET_LINKADDR 2
354 #define ND_OPT_PREFIX_INFORMATION 3
355 #define ND_OPT_REDIRECTED_HEADER 4
357 #define ND_OPT_ADVINTERVAL 7
358 #define ND_OPT_HOMEAGENT_INFO 8
359 #define ND_OPT_SOURCE_ADDRLIST 9
360 #define ND_OPT_TARGET_ADDRLIST 10
362 /* draft-ietf-ipngwg-router-preference, not officially assigned yet */
363 #define ND_OPT_ROUTE_INFO 200
364 /* draft-ietf-mobileip-hmipv6, not officially assigned yet */
365 #define ND_OPT_MAP 201
367 struct nd_opt_prefix_info { /* prefix information */
368 guint8 nd_opt_pi_type;
369 guint8 nd_opt_pi_len;
370 guint8 nd_opt_pi_prefix_len;
371 guint8 nd_opt_pi_flags_reserved;
372 guint32 nd_opt_pi_valid_time;
373 guint32 nd_opt_pi_preferred_time;
374 guint32 nd_opt_pi_reserved2;
375 struct e_in6_addr nd_opt_pi_prefix;
378 #define ND_OPT_PI_FLAG_ONLINK 0x80
379 #define ND_OPT_PI_FLAG_AUTO 0x40
380 #define ND_OPT_PI_FLAG_ROUTER 0x20
381 #define ND_OPT_PI_FLAG_SITEPREF 0x10
383 struct nd_opt_rd_hdr { /* redirected header */
384 guint8 nd_opt_rh_type;
385 guint8 nd_opt_rh_len;
386 guint16 nd_opt_rh_reserved1;
387 guint32 nd_opt_rh_reserved2;
388 /* followed by IP header and data */
391 struct nd_opt_mtu { /* MTU option */
392 guint8 nd_opt_mtu_type;
393 guint8 nd_opt_mtu_len;
394 guint16 nd_opt_mtu_reserved;
395 guint32 nd_opt_mtu_mtu;
398 struct nd_opt_adv_int { /* Advertisement Interval option */
399 guint8 nd_opt_adv_int_type;
400 guint8 nd_opt_adv_int_len;
401 guint16 nd_opt_adv_int_reserved;
402 guint32 nd_opt_adv_int_advint;
405 struct nd_opt_ha_info { /* Home Agent Information option */
406 guint8 nd_opt_ha_info_type;
407 guint8 nd_opt_ha_info_len;
408 guint16 nd_opt_ha_info_reserved;
409 guint16 nd_opt_ha_info_ha_pref;
410 guint16 nd_opt_ha_info_ha_life;
413 struct nd_opt_route_info { /* route info */
414 guint8 nd_opt_rti_type;
415 guint8 nd_opt_rti_len;
416 guint8 nd_opt_rti_prefixlen;
417 guint8 nd_opt_rti_flags;
418 guint32 nd_opt_rti_lifetime;
422 struct nd_opt_map_info { /* HMIPv6 MAP option */
423 guint8 nd_opt_map_type;
424 guint8 nd_opt_map_len;
425 guint8 nd_opt_map_dist_and_pref;
426 guint8 nd_opt_map_flags;
427 guint32 nd_opt_map_lifetime;
428 struct e_in6_addr nd_opt_map_address;
431 #define ND_OPT_MAP_FLAG_R 0x80
432 #define ND_OPT_MAP_FLAG_M 0x40
433 #define ND_OPT_MAP_FLAG_I 0x20
434 #define ND_OPT_MAP_FLAG_T 0x10
435 #define ND_OPT_MAP_FLAG_P 0x08
436 #define ND_OPT_MAP_FLAG_V 0x04
439 * icmp6 node information
441 struct icmp6_nodeinfo {
442 struct icmp6_hdr icmp6_ni_hdr;
443 guint8 icmp6_ni_nonce[8];
444 /* could be followed by reply data */
447 #define ni_type icmp6_ni_hdr.icmp6_type
448 #define ni_code icmp6_ni_hdr.icmp6_code
449 #define ni_cksum icmp6_ni_hdr.icmp6_cksum
450 #define ni_qtype icmp6_ni_hdr.icmp6_data16[0]
451 #define ni_flags icmp6_ni_hdr.icmp6_data16[1]
453 #define NI_QTYPE_NOOP 0 /* NOOP */
454 #define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */
455 #define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */
456 #define NI_QTYPE_DNSNAME 2 /* DNS Name */
457 #define NI_QTYPE_NODEADDR 3 /* Node Addresses */
458 #define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */
460 #define NI_SUPTYPE_FLAG_COMPRESS 0x1
461 #define NI_FQDN_FLAG_VALIDTTL 0x1
463 #define NI_NODEADDR_FLAG_TRUNCATE 0x1
464 #define NI_NODEADDR_FLAG_ALL 0x2
465 #define NI_NODEADDR_FLAG_COMPAT 0x4
466 #define NI_NODEADDR_FLAG_LINKLOCAL 0x8
467 #define NI_NODEADDR_FLAG_SITELOCAL 0x10
468 #define NI_NODEADDR_FLAG_GLOBAL 0x20
469 #define NI_NODEADDR_FLAG_ANYCAST 0x40 /* just experimental. not in spec */
471 struct ni_reply_fqdn {
472 guint32 ni_fqdn_ttl; /* TTL */
473 guint8 ni_fqdn_namelen; /* length in octets of the FQDN */
474 guint8 ni_fqdn_name[3]; /* XXX: alignment */
478 * Router Renumbering. as router-renum-05.txt
480 struct icmp6_router_renum { /* router renumbering header */
481 struct icmp6_hdr rr_hdr;
488 #define rr_type rr_hdr.icmp6_type
489 #define rr_code rr_hdr.icmp6_code
490 #define rr_cksum rr_hdr.icmp6_cksum
491 #define rr_seqnum rr_hdr.icmp6_data32[0]
493 struct rr_pco_match { /* match prefix part */
500 guint16 rpm_reserved;
501 struct e_in6_addr rpm_prefix;
504 #define RPM_PCO_ADD 1
505 #define RPM_PCO_CHANGE 2
506 #define RPM_PCO_SETGLOBAL 3
507 #define RPM_PCO_MAX 4
509 struct rr_pco_use { /* use prefix part */
517 struct e_in6_addr rpu_prefix;
520 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80
521 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40
524 #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
525 #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
527 struct rr_result { /* router renumbering result message */
530 guint8 rrr_matchedlen;
532 struct e_in6_addr rrr_prefix;
536 #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002
537 #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
539 void capture_ipv6(const guchar *, int, int, packet_counts *);
542 #endif /* __PACKET_IPV6_H_DEFINED__ */