]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/ip6.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $*/
33 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the project nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * Copyright (c) 1982, 1986, 1993
63 * The Regents of the University of California. All rights reserved.
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution.
73 * 3. All advertising materials mentioning features or use of this software
74 * must display the following acknowledgement:
75 * This product includes software developed by the University of
76 * California, Berkeley and its contributors.
77 * 4. Neither the name of the University nor the names of its contributors
78 * may be used to endorse or promote products derived from this software
79 * without specific prior written permission.
81 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
82 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93 * @(#)ip.h 8.1 (Berkeley) 6/10/93
96 #ifndef _NETINET_IP6_H_
97 #define _NETINET_IP6_H_
98 #include <sys/appleapiopts.h>
101 * Definition for internet protocol version 6.
108 u_int32_t ip6_un1_flow
; /* 20 bits of flow-ID */
109 u_int16_t ip6_un1_plen
; /* payload length */
110 u_int8_t ip6_un1_nxt
; /* next header */
111 u_int8_t ip6_un1_hlim
; /* hop limit */
113 u_int8_t ip6_un2_vfc
; /* 4 bits version, top 4 bits class */
115 struct in6_addr ip6_src
; /* source address */
116 struct in6_addr ip6_dst
; /* destination address */
117 } __attribute__((__packed__
));
119 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
120 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
121 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
122 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
123 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
124 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
126 #define IPV6_VERSION 0x60
127 #define IPV6_VERSION_MASK 0xf0
129 #if BYTE_ORDER == BIG_ENDIAN
130 #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
131 #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
133 #if BYTE_ORDER == LITTLE_ENDIAN
134 #define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
135 #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
136 #endif /* LITTLE_ENDIAN */
139 /* ECN bits proposed by Sally Floyd */
140 #define IP6TOS_CE 0x01 /* congestion experienced */
141 #define IP6TOS_ECT 0x02 /* ECN-capable transport */
151 } __attribute__((__packed__
));
153 /* Hop-by-Hop options header */
154 /* XXX should we pad it to force alignment on an 8-byte boundary? */
156 u_int8_t ip6h_nxt
; /* next header */
157 u_int8_t ip6h_len
; /* length in units of 8 octets */
158 /* followed by options */
159 } __attribute__((__packed__
));
161 /* Destination options header */
162 /* XXX should we pad it to force alignment on an 8-byte boundary? */
164 u_int8_t ip6d_nxt
; /* next header */
165 u_int8_t ip6d_len
; /* length in units of 8 octets */
166 /* followed by options */
167 } __attribute__((__packed__
));
169 /* Option types and related macros */
170 #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
171 #define IP6OPT_PADN 0x01 /* 00 0 00001 */
172 #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
173 #define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */
174 #define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */
175 #define IP6OPT_RTALERT 0x05 /* 00 0 00101 (KAME definition) */
177 #define IP6OPT_RTALERT_LEN 4
178 #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
179 #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
180 #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
181 #define IP6OPT_MINLEN 2
183 #define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
184 #define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
185 #define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
186 #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
187 #define IP6OPT_EID 0x8a /* 10 0 01010 */
189 #define IP6OPT_TYPE(o) ((o) & 0xC0)
190 #define IP6OPT_TYPE_SKIP 0x00
191 #define IP6OPT_TYPE_DISCARD 0x40
192 #define IP6OPT_TYPE_FORCEICMP 0x80
193 #define IP6OPT_TYPE_ICMP 0xC0
195 #define IP6OPT_MUTABLE 0x20
197 #define IP6OPT_JUMBO_LEN 6
201 u_int8_t ip6r_nxt
; /* next header */
202 u_int8_t ip6r_len
; /* length in units of 8 octets */
203 u_int8_t ip6r_type
; /* routing type */
204 u_int8_t ip6r_segleft
; /* segments left */
205 /* followed by routing type specific data */
206 } __attribute__((__packed__
));
208 /* Type 0 Routing header */
210 u_int8_t ip6r0_nxt
; /* next header */
211 u_int8_t ip6r0_len
; /* length in units of 8 octets */
212 u_int8_t ip6r0_type
; /* always zero */
213 u_int8_t ip6r0_segleft
; /* segments left */
214 u_int8_t ip6r0_reserved
; /* reserved field */
215 u_int8_t ip6r0_slmap
[3]; /* strict/loose bit map */
216 struct in6_addr ip6r0_addr
[1]; /* up to 23 addresses */
217 } __attribute__((__packed__
));
219 /* Fragment header */
221 u_int8_t ip6f_nxt
; /* next header */
222 u_int8_t ip6f_reserved
; /* reserved field */
223 u_int16_t ip6f_offlg
; /* offset, reserved, and flag */
224 u_int32_t ip6f_ident
; /* identification */
225 } __attribute__((__packed__
));
227 #if BYTE_ORDER == BIG_ENDIAN
228 #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
229 #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
230 #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
231 #else /* BYTE_ORDER == LITTLE_ENDIAN */
232 #define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
233 #define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
234 #define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
235 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
238 * Internet implementation parameters.
240 #define IPV6_MAXHLIM 255 /* maximun hoplimit */
241 #define IPV6_DEFHLIM 64 /* default hlim */
242 #define IPV6_FRAGTTL 120 /* ttl for fragment packets, in slowtimo tick */
243 #define IPV6_HLIMDEC 1 /* subtracted when forwaeding */
245 #define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
246 #define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
248 #ifdef KERNEL_PRIVATE
250 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
251 * target header (including IPv6 itself, extension headers and
252 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
253 * to store incoming data into one internal mbuf or one or more external
254 * mbufs(never into two or more internal mbufs). Thus, the third case is
255 * supposed to never be matched but is prepared just in case.
258 #define IP6_EXTHDR_CHECK(m, off, hlen, action) \
260 if ((m)->m_next != NULL) { \
261 if (((m)->m_flags & M_LOOP) && \
262 ((m)->m_len < (off) + (hlen)) && \
263 (((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \
264 ip6stat.ip6s_exthdrtoolong++; \
266 } else if ((m)->m_flags & M_EXT) { \
267 if ((m)->m_len < (off) + (hlen)) { \
268 ip6stat.ip6s_exthdrtoolong++; \
273 if ((m)->m_len < (off) + (hlen)) { \
274 ip6stat.ip6s_exthdrtoolong++; \
280 if ((m)->m_len < (off) + (hlen)) { \
281 ip6stat.ip6s_tooshort++; \
282 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
290 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
291 * "len") is located in single mbuf, on contiguous memory region.
292 * The pointer to the region will be returned to pointer variable "val",
294 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
295 * very top of mbuf. GET0 is likely to make memory copy than GET.
297 * XXX we're now testing this, needs m_pulldown()
299 #define IP6_EXTHDR_GET(val, typ, m, off, len) \
303 if ((m)->m_len >= (off) + (len)) \
304 (val) = (typ)(mtod((m), caddr_t) + (off)); \
306 t = m_pulldown((m), (off), (len), &tmp); \
308 if (t->m_len < tmp + (len)) \
309 panic("m_pulldown malfunction"); \
310 (val) = (typ)(mtod(t, caddr_t) + tmp); \
318 #define IP6_EXTHDR_GET0(val, typ, m, off, len) \
322 (val) = (typ)mtod(m, caddr_t); \
324 t = m_pulldown((m), (off), (len), NULL); \
326 if (t->m_len < (len)) \
327 panic("m_pulldown malfunction"); \
328 (val) = (typ)mtod(t, caddr_t); \
336 #endif KERNEL_PRIVATE
337 #endif !_NETINET_IP6_H_