]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/ip6.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / netinet / ip6.h
CommitLineData
1c79356b 1/*
0a7de745 2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
9bccf70c 28/* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $*/
1c79356b
A
29
30/*
31 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
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.
45 *
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
56 * SUCH DAMAGE.
57 */
58
59/*
60 * Copyright (c) 1982, 1986, 1993
61 * The Regents of the University of California. All rights reserved.
62 *
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
65 * are met:
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.
78 *
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
89 * SUCH DAMAGE.
90 *
91 * @(#)ip.h 8.1 (Berkeley) 6/10/93
92 */
93
94#ifndef _NETINET_IP6_H_
95#define _NETINET_IP6_H_
f427ee49 96#ifndef DRIVERKIT
9bccf70c 97#include <sys/appleapiopts.h>
f427ee49
A
98#else
99#include <sys/_types.h>
100#include <netinet/in.h>
101#include <machine/endian.h>
102#endif /* DRIVERKIT */
1c79356b
A
103
104/*
105 * Definition for internet protocol version 6.
106 * RFC 2460
107 */
108
109struct ip6_hdr {
110 union {
111 struct ip6_hdrctl {
0a7de745
A
112 u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
113 u_int16_t ip6_un1_plen; /* payload length */
114 u_int8_t ip6_un1_nxt; /* next header */
115 u_int8_t ip6_un1_hlim; /* hop limit */
1c79356b 116 } ip6_un1;
0a7de745 117 u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
1c79356b 118 } ip6_ctlun;
0a7de745
A
119 struct in6_addr ip6_src; /* source address */
120 struct in6_addr ip6_dst; /* destination address */
9bccf70c 121} __attribute__((__packed__));
1c79356b 122
0a7de745
A
123#define ip6_vfc ip6_ctlun.ip6_un2_vfc
124#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
125#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
126#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
127#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
128#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
1c79356b 129
0a7de745
A
130#define IPV6_VERSION 0x60
131#define IPV6_VERSION_MASK 0xf0
1c79356b
A
132
133#if BYTE_ORDER == BIG_ENDIAN
0a7de745
A
134#define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
135#define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
136#define IPV6_FLOW_ECN_MASK 0x00300000 /* the 2 ECN bits */
1c79356b
A
137#else
138#if BYTE_ORDER == LITTLE_ENDIAN
0a7de745
A
139#define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
140#define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
141#define IPV6_FLOW_ECN_MASK 0x00003000 /* the 2 ECN bits */
1c79356b
A
142#endif /* LITTLE_ENDIAN */
143#endif
144#if 1
145/* ECN bits proposed by Sally Floyd */
0a7de745
A
146#define IP6TOS_CE 0x01 /* congestion experienced */
147#define IP6TOS_ECT 0x02 /* ECN-capable transport */
1c79356b
A
148#endif
149
39037602
A
150/*
151 * To access the 6 bits of the DSCP value in the 32 bits ip6_flow field
152 */
0a7de745
A
153#define IP6FLOW_DSCP_MASK 0x0fc00000
154#define IP6FLOW_DSCP_SHIFT 22
39037602 155
1c79356b
A
156/*
157 * Extension Headers
158 */
159
0a7de745 160struct ip6_ext {
9bccf70c
A
161 u_int8_t ip6e_nxt;
162 u_int8_t ip6e_len;
163} __attribute__((__packed__));
1c79356b
A
164
165/* Hop-by-Hop options header */
166/* XXX should we pad it to force alignment on an 8-byte boundary? */
167struct ip6_hbh {
0a7de745
A
168 u_int8_t ip6h_nxt; /* next header */
169 u_int8_t ip6h_len; /* length in units of 8 octets */
1c79356b 170 /* followed by options */
9bccf70c 171} __attribute__((__packed__));
1c79356b
A
172
173/* Destination options header */
174/* XXX should we pad it to force alignment on an 8-byte boundary? */
175struct ip6_dest {
0a7de745
A
176 u_int8_t ip6d_nxt; /* next header */
177 u_int8_t ip6d_len; /* length in units of 8 octets */
1c79356b 178 /* followed by options */
9bccf70c 179} __attribute__((__packed__));
1c79356b
A
180
181/* Option types and related macros */
0a7de745
A
182#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
183#define IP6OPT_PADN 0x01 /* 00 0 00001 */
184#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
185#define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */
186#define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */
6d2010ae 187#ifndef KERNEL_PRIVATE
0a7de745 188#define IP6OPT_RTALERT 0x05 /* 00 0 00101 (KAME definition) */
6d2010ae 189#endif
0a7de745 190#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 (RFC3542, recommended) */
1c79356b 191
0a7de745
A
192#define IP6OPT_RTALERT_LEN 4
193#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
194#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
195#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
196#define IP6OPT_MINLEN 2
1c79356b 197
0a7de745 198#define IP6OPT_EID 0x8a /* 10 0 01010 */
1c79356b 199
0a7de745
A
200#define IP6OPT_TYPE(o) ((o) & 0xC0)
201#define IP6OPT_TYPE_SKIP 0x00
202#define IP6OPT_TYPE_DISCARD 0x40
203#define IP6OPT_TYPE_FORCEICMP 0x80
204#define IP6OPT_TYPE_ICMP 0xC0
1c79356b 205
0a7de745 206#define IP6OPT_MUTABLE 0x20
1c79356b 207
6d2010ae
A
208/* IPv6 options: common part */
209struct ip6_opt {
210 u_int8_t ip6o_type;
211 u_int8_t ip6o_len;
212} __attribute__((__packed__));
213
214/* Jumbo Payload Option */
215struct ip6_opt_jumbo {
216 u_int8_t ip6oj_type;
217 u_int8_t ip6oj_len;
218 u_int8_t ip6oj_jumbo_len[4];
219} __attribute__((__packed__));
0a7de745 220#define IP6OPT_JUMBO_LEN 6
1c79356b 221
6d2010ae
A
222/* NSAP Address Option */
223struct ip6_opt_nsap {
224 u_int8_t ip6on_type;
225 u_int8_t ip6on_len;
226 u_int8_t ip6on_src_nsap_len;
227 u_int8_t ip6on_dst_nsap_len;
228 /* followed by source NSAP */
229 /* followed by destination NSAP */
230}__attribute__((__packed__));
231
232/* Tunnel Limit Option */
233struct ip6_opt_tunnel {
234 u_int8_t ip6ot_type;
235 u_int8_t ip6ot_len;
236 u_int8_t ip6ot_encap_limit;
237}__attribute__((__packed__));
238
239/* Router Alert Option */
240struct ip6_opt_router {
241 u_int8_t ip6or_type;
242 u_int8_t ip6or_len;
243 u_int8_t ip6or_value[2];
244}__attribute__((__packed__));
245/* Router alert values (in network byte order) */
246#if BYTE_ORDER == BIG_ENDIAN
0a7de745
A
247#define IP6_ALERT_MLD 0x0000
248#define IP6_ALERT_RSVP 0x0001
249#define IP6_ALERT_AN 0x0002
6d2010ae
A
250#else
251#if BYTE_ORDER == LITTLE_ENDIAN
0a7de745
A
252#define IP6_ALERT_MLD 0x0000
253#define IP6_ALERT_RSVP 0x0100
254#define IP6_ALERT_AN 0x0200
6d2010ae
A
255#endif /* LITTLE_ENDIAN */
256#endif
257
1c79356b
A
258/* Routing header */
259struct ip6_rthdr {
0a7de745
A
260 u_int8_t ip6r_nxt; /* next header */
261 u_int8_t ip6r_len; /* length in units of 8 octets */
262 u_int8_t ip6r_type; /* routing type */
263 u_int8_t ip6r_segleft; /* segments left */
1c79356b 264 /* followed by routing type specific data */
9bccf70c 265} __attribute__((__packed__));
1c79356b 266
0a7de745 267/* Type 0 Routing header, deprecated by RFC 5095. */
1c79356b 268struct ip6_rthdr0 {
0a7de745
A
269 u_int8_t ip6r0_nxt; /* next header */
270 u_int8_t ip6r0_len; /* length in units of 8 octets */
271 u_int8_t ip6r0_type; /* always zero */
272 u_int8_t ip6r0_segleft; /* segments left */
273 u_int32_t ip6r0_reserved; /* reserved field */
274 /* followed by up to 127 struct in6_addr */
9bccf70c 275} __attribute__((__packed__));
1c79356b
A
276
277/* Fragment header */
278struct ip6_frag {
0a7de745
A
279 u_int8_t ip6f_nxt; /* next header */
280 u_int8_t ip6f_reserved; /* reserved field */
281 u_int16_t ip6f_offlg; /* offset, reserved, and flag */
282 u_int32_t ip6f_ident; /* identification */
9bccf70c 283} __attribute__((__packed__));
1c79356b
A
284
285#if BYTE_ORDER == BIG_ENDIAN
0a7de745
A
286#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
287#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
288#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
1c79356b 289#else /* BYTE_ORDER == LITTLE_ENDIAN */
0a7de745
A
290#define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
291#define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
292#define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
1c79356b
A
293#endif /* BYTE_ORDER == LITTLE_ENDIAN */
294
295/*
296 * Internet implementation parameters.
297 */
0a7de745
A
298#define IPV6_MAXHLIM 255 /* maximum hoplimit */
299#define IPV6_DEFHLIM 64 /* default hlim */
300#define IPV6_FRAGTTL 60 /* ttl for fragment packets (seconds) */
301#define IPV6_HLIMDEC 1 /* subtracted when forwarding */
1c79356b 302
0a7de745
A
303#define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
304#define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
305#define IPV6_MAXOPTHDR 2048 /* max option header size, 256 64-bit words */
1c79356b 306
39236c6e 307#ifdef BSD_KERNEL_PRIVATE
1c79356b
A
308/*
309 * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
310 * target header (including IPv6 itself, extension headers and
311 * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
312 * to store incoming data into one internal mbuf or one or more external
313 * mbufs(never into two or more internal mbufs). Thus, the third case is
314 * supposed to never be matched but is prepared just in case.
315 */
316
0a7de745
A
317#define IP6_EXTHDR_CHECK(m, off, hlen, action) \
318do { \
319 if ((m)->m_next != NULL) { \
320 if (((m)->m_flags & M_LOOP) && \
321 ((m)->m_len < (off) + (hlen)) && \
322 (((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \
323 ip6stat.ip6s_exthdrtoolong++; \
324 action; \
325 } else if ((m)->m_flags & M_EXT) { \
326 if ((m)->m_len < (off) + (hlen)) { \
327 ip6stat.ip6s_exthdrtoolong++; \
328 m_freem(m); \
329 (m) = NULL; \
330 action; \
331 } \
332 } else { \
333 if ((m)->m_len < (off) + (hlen)) { \
334 ip6stat.ip6s_exthdrtoolong++; \
335 m_freem(m); \
336 (m) = NULL; \
337 action; \
338 } \
339 } \
340 } else { \
341 if ((m)->m_len < (off) + (hlen)) { \
342 ip6stat.ip6s_tooshort++; \
343 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
344 m_freem(m); \
345 (m) = NULL; \
346 action; \
347 } \
348 } \
1c79356b
A
349} while (0)
350
351/*
352 * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
353 * "len") is located in single mbuf, on contiguous memory region.
354 * The pointer to the region will be returned to pointer variable "val",
355 * with type "typ".
356 * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
357 * very top of mbuf. GET0 is likely to make memory copy than GET.
1c79356b 358 */
0a7de745 359#define IP6_EXTHDR_GET(val, typ, m, off, len) \
6d2010ae 360 M_STRUCT_GET(val, typ, m, off, len)
1c79356b 361
0a7de745 362#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
6d2010ae 363 M_STRUCT_GET0(val, typ, m, off, len)
1c79356b 364
39236c6e 365#endif /* BSD_KERNEL_PRIVATE */
b0d623f7 366#endif /* !_NETINET_IP6_H_ */