]>
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_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $*/
28 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. Neither the name of the project nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * Copyright (c) 1982, 1986, 1993
58 * The Regents of the University of California. All rights reserved.
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
63 * 1. Redistributions of source code must retain the above copyright
64 * notice, this list of conditions and the following disclaimer.
65 * 2. Redistributions in binary form must reproduce the above copyright
66 * notice, this list of conditions and the following disclaimer in the
67 * documentation and/or other materials provided with the distribution.
68 * 3. All advertising materials mentioning features or use of this software
69 * must display the following acknowledgement:
70 * This product includes software developed by the University of
71 * California, Berkeley and its contributors.
72 * 4. Neither the name of the University nor the names of its contributors
73 * may be used to endorse or promote products derived from this software
74 * without specific prior written permission.
76 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
77 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
80 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * @(#)ip.h 8.1 (Berkeley) 6/10/93
91 #ifndef _NETINET_IP6_H_
92 #define _NETINET_IP6_H_
93 #include <sys/appleapiopts.h>
96 * Definition for internet protocol version 6.
103 u_int32_t ip6_un1_flow
; /* 20 bits of flow-ID */
104 u_int16_t ip6_un1_plen
; /* payload length */
105 u_int8_t ip6_un1_nxt
; /* next header */
106 u_int8_t ip6_un1_hlim
; /* hop limit */
108 u_int8_t ip6_un2_vfc
; /* 4 bits version, top 4 bits class */
110 struct in6_addr ip6_src
; /* source address */
111 struct in6_addr ip6_dst
; /* destination address */
112 } __attribute__((__packed__
));
114 #define ip6_vfc ip6_ctlun.ip6_un2_vfc
115 #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
116 #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
117 #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
118 #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
119 #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
121 #define IPV6_VERSION 0x60
122 #define IPV6_VERSION_MASK 0xf0
124 #if BYTE_ORDER == BIG_ENDIAN
125 #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
126 #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
128 #if BYTE_ORDER == LITTLE_ENDIAN
129 #define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
130 #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
131 #endif /* LITTLE_ENDIAN */
134 /* ECN bits proposed by Sally Floyd */
135 #define IP6TOS_CE 0x01 /* congestion experienced */
136 #define IP6TOS_ECT 0x02 /* ECN-capable transport */
146 } __attribute__((__packed__
));
148 /* Hop-by-Hop options header */
149 /* XXX should we pad it to force alignment on an 8-byte boundary? */
151 u_int8_t ip6h_nxt
; /* next header */
152 u_int8_t ip6h_len
; /* length in units of 8 octets */
153 /* followed by options */
154 } __attribute__((__packed__
));
156 /* Destination options header */
157 /* XXX should we pad it to force alignment on an 8-byte boundary? */
159 u_int8_t ip6d_nxt
; /* next header */
160 u_int8_t ip6d_len
; /* length in units of 8 octets */
161 /* followed by options */
162 } __attribute__((__packed__
));
164 /* Option types and related macros */
165 #define IP6OPT_PAD1 0x00 /* 00 0 00000 */
166 #define IP6OPT_PADN 0x01 /* 00 0 00001 */
167 #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
168 #define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */
169 #define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */
170 #define IP6OPT_RTALERT 0x05 /* 00 0 00101 (KAME definition) */
172 #define IP6OPT_RTALERT_LEN 4
173 #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
174 #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
175 #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
176 #define IP6OPT_MINLEN 2
178 #define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
179 #define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
180 #define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
181 #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
182 #define IP6OPT_EID 0x8a /* 10 0 01010 */
184 #define IP6OPT_TYPE(o) ((o) & 0xC0)
185 #define IP6OPT_TYPE_SKIP 0x00
186 #define IP6OPT_TYPE_DISCARD 0x40
187 #define IP6OPT_TYPE_FORCEICMP 0x80
188 #define IP6OPT_TYPE_ICMP 0xC0
190 #define IP6OPT_MUTABLE 0x20
192 #define IP6OPT_JUMBO_LEN 6
196 u_int8_t ip6r_nxt
; /* next header */
197 u_int8_t ip6r_len
; /* length in units of 8 octets */
198 u_int8_t ip6r_type
; /* routing type */
199 u_int8_t ip6r_segleft
; /* segments left */
200 /* followed by routing type specific data */
201 } __attribute__((__packed__
));
203 /* Type 0 Routing header */
205 u_int8_t ip6r0_nxt
; /* next header */
206 u_int8_t ip6r0_len
; /* length in units of 8 octets */
207 u_int8_t ip6r0_type
; /* always zero */
208 u_int8_t ip6r0_segleft
; /* segments left */
209 u_int8_t ip6r0_reserved
; /* reserved field */
210 u_int8_t ip6r0_slmap
[3]; /* strict/loose bit map */
211 struct in6_addr ip6r0_addr
[1]; /* up to 23 addresses */
212 } __attribute__((__packed__
));
214 /* Fragment header */
216 u_int8_t ip6f_nxt
; /* next header */
217 u_int8_t ip6f_reserved
; /* reserved field */
218 u_int16_t ip6f_offlg
; /* offset, reserved, and flag */
219 u_int32_t ip6f_ident
; /* identification */
220 } __attribute__((__packed__
));
222 #if BYTE_ORDER == BIG_ENDIAN
223 #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
224 #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
225 #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
226 #else /* BYTE_ORDER == LITTLE_ENDIAN */
227 #define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
228 #define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
229 #define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
230 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
233 * Internet implementation parameters.
235 #define IPV6_MAXHLIM 255 /* maximun hoplimit */
236 #define IPV6_DEFHLIM 64 /* default hlim */
237 #define IPV6_FRAGTTL 120 /* ttl for fragment packets, in slowtimo tick */
238 #define IPV6_HLIMDEC 1 /* subtracted when forwaeding */
240 #define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
241 #define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
244 #ifdef __APPLE_API_PRIVATE
246 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
247 * target header (including IPv6 itself, extension headers and
248 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
249 * to store incoming data into one internal mbuf or one or more external
250 * mbufs(never into two or more internal mbufs). Thus, the third case is
251 * supposed to never be matched but is prepared just in case.
254 #define IP6_EXTHDR_CHECK(m, off, hlen, ret) \
256 if ((m)->m_next != NULL) { \
257 if (((m)->m_flags & M_LOOP) && \
258 ((m)->m_len < (off) + (hlen)) && \
259 (((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \
260 ip6stat.ip6s_exthdrtoolong++; \
262 } else if ((m)->m_flags & M_EXT) { \
263 if ((m)->m_len < (off) + (hlen)) { \
264 ip6stat.ip6s_exthdrtoolong++; \
269 if ((m)->m_len < (off) + (hlen)) { \
270 ip6stat.ip6s_exthdrtoolong++; \
276 if ((m)->m_len < (off) + (hlen)) { \
277 ip6stat.ip6s_tooshort++; \
278 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
286 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
287 * "len") is located in single mbuf, on contiguous memory region.
288 * The pointer to the region will be returned to pointer variable "val",
290 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
291 * very top of mbuf. GET0 is likely to make memory copy than GET.
293 * XXX we're now testing this, needs m_pulldown()
295 #define IP6_EXTHDR_GET(val, typ, m, off, len) \
299 if ((m)->m_len >= (off) + (len)) \
300 (val) = (typ)(mtod((m), caddr_t) + (off)); \
302 t = m_pulldown((m), (off), (len), &tmp); \
304 if (t->m_len < tmp + (len)) \
305 panic("m_pulldown malfunction"); \
306 (val) = (typ)(mtod(t, caddr_t) + tmp); \
314 #define IP6_EXTHDR_GET0(val, typ, m, off, len) \
318 (val) = (typ)mtod(m, caddr_t); \
320 t = m_pulldown((m), (off), (len), NULL); \
322 if (t->m_len < (len)) \
323 panic("m_pulldown malfunction"); \
324 (val) = (typ)mtod(t, caddr_t); \
331 #endif /* __APPLE_API_PRIVATE */
334 #endif /* not _NETINET_IP6_H_ */