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