2 * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $*/
31 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. Neither the name of the project nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * Copyright (c) 1982, 1986, 1993
61 * The Regents of the University of California. All rights reserved.
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
66 * 1. Redistributions of source code must retain the above copyright
67 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in the
70 * documentation and/or other materials provided with the distribution.
71 * 3. All advertising materials mentioning features or use of this software
72 * must display the following acknowledgement:
73 * This product includes software developed by the University of
74 * California, Berkeley and its contributors.
75 * 4. Neither the name of the University nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 * @(#)ip.h 8.1 (Berkeley) 6/10/93
94 #ifndef _NETINET_IP6_H_
95 #define _NETINET_IP6_H_
96 #include <sys/appleapiopts.h>
99 * Definition for internet protocol version 6.
106 u_int32_t ip6_un1_flow
; /* 20 bits of flow-ID */
107 u_int16_t ip6_un1_plen
; /* payload length */
108 u_int8_t ip6_un1_nxt
; /* next header */
109 u_int8_t ip6_un1_hlim
; /* hop limit */
111 u_int8_t ip6_un2_vfc
; /* 4 bits version, top 4 bits class */
113 struct in6_addr ip6_src
; /* source address */
114 struct in6_addr ip6_dst
; /* destination address */
115 } __attribute__((__packed__
));
117 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
118 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
119 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
120 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
121 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
122 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
124 #define IPV6_VERSION 0x60
125 #define IPV6_VERSION_MASK 0xf0
127 #if BYTE_ORDER == BIG_ENDIAN
128 #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
129 #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
131 #if BYTE_ORDER == LITTLE_ENDIAN
132 #define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
133 #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
134 #endif /* LITTLE_ENDIAN */
137 /* ECN bits proposed by Sally Floyd */
138 #define IP6TOS_CE 0x01 /* congestion experienced */
139 #define IP6TOS_ECT 0x02 /* ECN-capable transport */
149 } __attribute__((__packed__
));
151 /* Hop-by-Hop options header */
152 /* XXX should we pad it to force alignment on an 8-byte boundary? */
154 u_int8_t ip6h_nxt
; /* next header */
155 u_int8_t ip6h_len
; /* length in units of 8 octets */
156 /* followed by options */
157 } __attribute__((__packed__
));
159 /* Destination options header */
160 /* XXX should we pad it to force alignment on an 8-byte boundary? */
162 u_int8_t ip6d_nxt
; /* next header */
163 u_int8_t ip6d_len
; /* length in units of 8 octets */
164 /* followed by options */
165 } __attribute__((__packed__
));
167 /* Option types and related macros */
168 #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
169 #define IP6OPT_PADN 0x01 /* 00 0 00001 */
170 #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
171 #define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */
172 #define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */
173 #ifndef KERNEL_PRIVATE
174 #define IP6OPT_RTALERT 0x05 /* 00 0 00101 (KAME definition) */
176 #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 (RFC3542, recommended) */
178 #define IP6OPT_RTALERT_LEN 4
179 #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
180 #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
181 #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
182 #define IP6OPT_MINLEN 2
184 #define IP6OPT_EID 0x8a /* 10 0 01010 */
186 #define IP6OPT_TYPE(o) ((o) & 0xC0)
187 #define IP6OPT_TYPE_SKIP 0x00
188 #define IP6OPT_TYPE_DISCARD 0x40
189 #define IP6OPT_TYPE_FORCEICMP 0x80
190 #define IP6OPT_TYPE_ICMP 0xC0
192 #define IP6OPT_MUTABLE 0x20
194 /* IPv6 options: common part */
198 } __attribute__((__packed__
));
200 /* Jumbo Payload Option */
201 struct ip6_opt_jumbo
{
204 u_int8_t ip6oj_jumbo_len
[4];
205 } __attribute__((__packed__
));
206 #define IP6OPT_JUMBO_LEN 6
208 /* NSAP Address Option */
209 struct ip6_opt_nsap
{
212 u_int8_t ip6on_src_nsap_len
;
213 u_int8_t ip6on_dst_nsap_len
;
214 /* followed by source NSAP */
215 /* followed by destination NSAP */
216 }__attribute__((__packed__
));
218 /* Tunnel Limit Option */
219 struct ip6_opt_tunnel
{
222 u_int8_t ip6ot_encap_limit
;
223 }__attribute__((__packed__
));
225 /* Router Alert Option */
226 struct ip6_opt_router
{
229 u_int8_t ip6or_value
[2];
230 }__attribute__((__packed__
));
231 /* Router alert values (in network byte order) */
232 #if BYTE_ORDER == BIG_ENDIAN
233 #define IP6_ALERT_MLD 0x0000
234 #define IP6_ALERT_RSVP 0x0001
235 #define IP6_ALERT_AN 0x0002
237 #if BYTE_ORDER == LITTLE_ENDIAN
238 #define IP6_ALERT_MLD 0x0000
239 #define IP6_ALERT_RSVP 0x0100
240 #define IP6_ALERT_AN 0x0200
241 #endif /* LITTLE_ENDIAN */
246 u_int8_t ip6r_nxt
; /* next header */
247 u_int8_t ip6r_len
; /* length in units of 8 octets */
248 u_int8_t ip6r_type
; /* routing type */
249 u_int8_t ip6r_segleft
; /* segments left */
250 /* followed by routing type specific data */
251 } __attribute__((__packed__
));
253 /* Type 0 Routing header */
255 u_int8_t ip6r0_nxt
; /* next header */
256 u_int8_t ip6r0_len
; /* length in units of 8 octets */
257 u_int8_t ip6r0_type
; /* always zero */
258 u_int8_t ip6r0_segleft
; /* segments left */
259 u_int8_t ip6r0_reserved
; /* reserved field */
260 u_int8_t ip6r0_slmap
[3]; /* strict/loose bit map */
261 struct in6_addr ip6r0_addr
[1]; /* up to 23 addresses */
262 } __attribute__((__packed__
));
264 /* Fragment header */
266 u_int8_t ip6f_nxt
; /* next header */
267 u_int8_t ip6f_reserved
; /* reserved field */
268 u_int16_t ip6f_offlg
; /* offset, reserved, and flag */
269 u_int32_t ip6f_ident
; /* identification */
270 } __attribute__((__packed__
));
272 #if BYTE_ORDER == BIG_ENDIAN
273 #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
274 #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
275 #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
276 #else /* BYTE_ORDER == LITTLE_ENDIAN */
277 #define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
278 #define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
279 #define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
280 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
283 * Internet implementation parameters.
285 #define IPV6_MAXHLIM 255 /* maximum hoplimit */
286 #define IPV6_DEFHLIM 64 /* default hlim */
287 #define IPV6_FRAGTTL 60 /* ttl for fragment packets (seconds) */
288 #define IPV6_HLIMDEC 1 /* subtracted when forwarding */
290 #define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
291 #define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
292 #define IPV6_MAXOPTHDR 2048 /* max option header size, 256 64-bit words */
294 #ifdef BSD_KERNEL_PRIVATE
296 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
297 * target header (including IPv6 itself, extension headers and
298 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
299 * to store incoming data into one internal mbuf or one or more external
300 * mbufs(never into two or more internal mbufs). Thus, the third case is
301 * supposed to never be matched but is prepared just in case.
304 #define IP6_EXTHDR_CHECK(m, off, hlen, action) \
306 if ((m)->m_next != NULL) { \
307 if (((m)->m_flags & M_LOOP) && \
308 ((m)->m_len < (off) + (hlen)) && \
309 (((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \
310 ip6stat.ip6s_exthdrtoolong++; \
312 } else if ((m)->m_flags & M_EXT) { \
313 if ((m)->m_len < (off) + (hlen)) { \
314 ip6stat.ip6s_exthdrtoolong++; \
320 if ((m)->m_len < (off) + (hlen)) { \
321 ip6stat.ip6s_exthdrtoolong++; \
328 if ((m)->m_len < (off) + (hlen)) { \
329 ip6stat.ip6s_tooshort++; \
330 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
339 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
340 * "len") is located in single mbuf, on contiguous memory region.
341 * The pointer to the region will be returned to pointer variable "val",
343 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
344 * very top of mbuf. GET0 is likely to make memory copy than GET.
346 #define IP6_EXTHDR_GET(val, typ, m, off, len) \
347 M_STRUCT_GET(val, typ, m, off, len)
349 #define IP6_EXTHDR_GET0(val, typ, m, off, len) \
350 M_STRUCT_GET0(val, typ, m, off, len)
352 #endif /* BSD_KERNEL_PRIVATE */
353 #endif /* !_NETINET_IP6_H_ */