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