xnu-344.21.74.tar.gz
[apple/xnu.git] / bsd / netinet / ip6.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
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
13 * file.
14 *
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
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.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
9bccf70c 25/* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $*/
1c79356b
A
26
27/*
28 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
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.
42 *
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
53 * SUCH DAMAGE.
54 */
55
56/*
57 * Copyright (c) 1982, 1986, 1993
58 * The Regents of the University of California. All rights reserved.
59 *
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
62 * are met:
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.
75 *
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
86 * SUCH DAMAGE.
87 *
88 * @(#)ip.h 8.1 (Berkeley) 6/10/93
89 */
90
91#ifndef _NETINET_IP6_H_
92#define _NETINET_IP6_H_
9bccf70c 93#include <sys/appleapiopts.h>
1c79356b
A
94
95/*
96 * Definition for internet protocol version 6.
97 * RFC 2460
98 */
99
100struct ip6_hdr {
101 union {
102 struct ip6_hdrctl {
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 */
107 } ip6_un1;
108 u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
109 } ip6_ctlun;
110 struct in6_addr ip6_src; /* source address */
111 struct in6_addr ip6_dst; /* destination address */
9bccf70c 112} __attribute__((__packed__));
1c79356b
A
113
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
120
121#define IPV6_VERSION 0x60
122#define IPV6_VERSION_MASK 0xf0
123
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) */
127#else
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 */
132#endif
133#if 1
134/* ECN bits proposed by Sally Floyd */
135#define IP6TOS_CE 0x01 /* congestion experienced */
136#define IP6TOS_ECT 0x02 /* ECN-capable transport */
137#endif
138
139/*
140 * Extension Headers
141 */
142
143struct ip6_ext {
9bccf70c
A
144 u_int8_t ip6e_nxt;
145 u_int8_t ip6e_len;
146} __attribute__((__packed__));
1c79356b
A
147
148/* Hop-by-Hop options header */
149/* XXX should we pad it to force alignment on an 8-byte boundary? */
150struct ip6_hbh {
151 u_int8_t ip6h_nxt; /* next header */
152 u_int8_t ip6h_len; /* length in units of 8 octets */
153 /* followed by options */
9bccf70c 154} __attribute__((__packed__));
1c79356b
A
155
156/* Destination options header */
157/* XXX should we pad it to force alignment on an 8-byte boundary? */
158struct ip6_dest {
159 u_int8_t ip6d_nxt; /* next header */
160 u_int8_t ip6d_len; /* length in units of 8 octets */
161 /* followed by options */
9bccf70c 162} __attribute__((__packed__));
1c79356b
A
163
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) */
1c79356b
A
171
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
177
9bccf70c
A
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 */
1c79356b
A
183
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
189
190#define IP6OPT_MUTABLE 0x20
191
9bccf70c 192#define IP6OPT_JUMBO_LEN 6
1c79356b
A
193
194/* Routing header */
195struct ip6_rthdr {
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 */
9bccf70c 201} __attribute__((__packed__));
1c79356b
A
202
203/* Type 0 Routing header */
204struct ip6_rthdr0 {
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 */
9bccf70c
A
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__));
1c79356b
A
213
214/* Fragment header */
215struct ip6_frag {
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 */
9bccf70c 220} __attribute__((__packed__));
1c79356b
A
221
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 */
231
232/*
233 * Internet implementation parameters.
234 */
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 */
239
240#define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
241#define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
242
243#ifdef KERNEL
9bccf70c 244#ifdef __APPLE_API_PRIVATE
1c79356b
A
245/*
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.
252 */
253
254#define IP6_EXTHDR_CHECK(m, off, hlen, ret) \
255do { \
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++; \
261 return ret; \
262 } else if ((m)->m_flags & M_EXT) { \
263 if ((m)->m_len < (off) + (hlen)) { \
264 ip6stat.ip6s_exthdrtoolong++; \
265 m_freem(m); \
266 return ret; \
267 } \
268 } else { \
269 if ((m)->m_len < (off) + (hlen)) { \
270 ip6stat.ip6s_exthdrtoolong++; \
271 m_freem(m); \
272 return ret; \
273 } \
274 } \
9bccf70c 275 } else { \
1c79356b
A
276 if ((m)->m_len < (off) + (hlen)) { \
277 ip6stat.ip6s_tooshort++; \
278 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
279 m_freem(m); \
280 return ret; \
281 } \
282 } \
283} while (0)
284
285/*
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",
289 * with type "typ".
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.
292 *
293 * XXX we're now testing this, needs m_pulldown()
294 */
295#define IP6_EXTHDR_GET(val, typ, m, off, len) \
296do { \
297 struct mbuf *t; \
298 int tmp; \
1c79356b
A
299 if ((m)->m_len >= (off) + (len)) \
300 (val) = (typ)(mtod((m), caddr_t) + (off)); \
301 else { \
302 t = m_pulldown((m), (off), (len), &tmp); \
303 if (t) { \
304 if (t->m_len < tmp + (len)) \
305 panic("m_pulldown malfunction"); \
306 (val) = (typ)(mtod(t, caddr_t) + tmp); \
307 } else { \
308 (val) = (typ)NULL; \
309 (m) = NULL; \
310 } \
311 } \
312} while (0)
313
314#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
315do { \
316 struct mbuf *t; \
1c79356b
A
317 if ((off) == 0) \
318 (val) = (typ)mtod(m, caddr_t); \
319 else { \
320 t = m_pulldown((m), (off), (len), NULL); \
321 if (t) { \
322 if (t->m_len < (len)) \
323 panic("m_pulldown malfunction"); \
324 (val) = (typ)mtod(t, caddr_t); \
325 } else { \
326 (val) = (typ)NULL; \
327 (m) = NULL; \
328 } \
329 } \
330} while (0)
9bccf70c 331#endif /* __APPLE_API_PRIVATE */
1c79356b
A
332#endif /*KERNEL*/
333
334#endif /* not _NETINET_IP6_H_ */