xref: /xnu-12377.81.4/bsd/netinet6/in6_private.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2008-2020 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 /*
30  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 3. Neither the name of the project nor the names of its contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  */
57 
58 /*
59  * Copyright (c) 1982, 1986, 1990, 1993
60  *	The Regents of the University of California.  All rights reserved.
61  *
62  * Redistribution and use in source and binary forms, with or without
63  * modification, are permitted provided that the following conditions
64  * are met:
65  * 1. Redistributions of source code must retain the above copyright
66  *    notice, this list of conditions and the following disclaimer.
67  * 2. Redistributions in binary form must reproduce the above copyright
68  *    notice, this list of conditions and the following disclaimer in the
69  *    documentation and/or other materials provided with the distribution.
70  * 3. All advertising materials mentioning features or use of this software
71  *    must display the following acknowledgement:
72  *	This product includes software developed by the University of
73  *	California, Berkeley and its contributors.
74  * 4. Neither the name of the University nor the names of its contributors
75  *    may be used to endorse or promote products derived from this software
76  *    without specific prior written permission.
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
79  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
81  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88  * SUCH DAMAGE.
89  *
90  *	@(#)in.h	8.3 (Berkeley) 1/3/94
91  */
92 
93 #ifndef DRIVERKIT
94 #ifndef __KAME_NETINET_IN_PRIVATE_H_INCLUDED_
95 #error "do not include netinet6/in6_private.h directly, include netinet/in_private.h. " \
96         " see RFC2553"
97 #endif
98 #endif /* DRIVERKIT */
99 
100 #ifndef _NETINET6_IN6_PRIVATE_H_
101 #define _NETINET6_IN6_PRIVATE_H_
102 
103 #include <netinet/in.h>
104 #include <stdint.h>
105 #ifdef BSD_KERNEL_PRIVATE
106 #include <sys/eventhandler.h>
107 #endif
108 #include <sys/types.h>
109 #include <uuid/uuid.h>
110 
111 #ifndef XNU_PLATFORM_DriverKit
112 
113 #ifdef KERNEL_PRIVATE
114 extern const struct sockaddr_in6 sa6_any;
115 
116 extern const struct in6_addr in6mask0;
117 extern const struct in6_addr in6mask7;
118 extern const struct in6_addr in6mask16;
119 extern const struct in6_addr in6mask32;
120 extern const struct in6_addr in6mask64;
121 extern const struct in6_addr in6mask96;
122 extern const struct in6_addr in6mask128;
123 
124 #define SIN6(s)         ((struct sockaddr_in6 *)(void *)s)
125 #define satosin6(sa)    SIN6(sa)
126 #define sin6tosa(sin6)  ((struct sockaddr *)(void *)(sin6))
127 #define SIN6IFSCOPE(s)  SIN6(s)
128 #endif /* KERNEL_PRIVATE */
129 
130 struct route_in6_old {
131 	void            *ro_rt;
132 	uint32_t        ro_flags;
133 	struct sockaddr_in6 ro_dst;
134 };
135 
136 #ifdef BSD_KERNEL_PRIVATE
137 #include <sys/eventhandler.h>
138 
139 /*
140  * IP6 route structure
141  *
142  * A route consists of a destination address and a reference
143  * to a routing entry.  These are often held by protocols
144  * in their control blocks, e.g. inpcb.
145  */
146 struct route_in6 {
147 	/*
148 	 * N.B: struct route_in6 must begin with ro_{rt,srcia,flags}
149 	 * because the code does some casts of a 'struct route_in6 *'
150 	 * to a 'struct route *'.
151 	 */
152 	struct rtentry  *ro_rt;
153 
154 	struct ifaddr   *ro_srcia;
155 	uint32_t        ro_flags;       /* route flags */
156 	struct sockaddr_in6 ro_dst;
157 };
158 #endif /* BSD_KERNEL_PRIVATE */
159 
160 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
161 
162 /*
163  * Options for use with [gs]etsockopt at the IPV6 level.
164  * First word of comment is data type; bool is stored in int.
165  */
166 #define IPV6_NO_IFT_CELLULAR            6969 /* for internal use only */
167 #define IPV6_OUT_IF                     9696 /* for internal use only */
168 
169 #define IPV6_RECV_LINK_ADDR_TYPE        9697 /* bool: receive the type of the link level address */
170 
171 /*
172  * Values for IPV6_RECV_LINK_ADDR_TYPE in ancillary messages are the same as
173  * IP6_RECV_LINK_ADDR_TYPE -- see netinet/in_private.h
174  */
175 
176 #ifdef BSD_KERNEL_PRIVATE
177 #define CTL_IPV6PROTO_NAMES { \
178     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
179     { 0, 0 }, \
180     { "tcp6", CTLTYPE_NODE }, \
181     { 0, 0 }, \
182     { 0, 0 }, \
183     { 0, 0 }, \
184     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
185     { 0, 0 }, \
186     { 0, 0 }, \
187     { "udp6", CTLTYPE_NODE }, \
188     { 0, 0 }, \
189     { 0, 0 }, \
190     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
191     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
192     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
193     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
194     { 0, 0 }, \
195     { "ip6", CTLTYPE_NODE }, \
196     { 0, 0 }, \
197     { 0, 0 }, \
198     { 0, 0 }, \
199     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
200     { 0, 0 }, \
201     { "ipsec6", CTLTYPE_NODE }, \
202     { 0, 0 }, \
203     { 0, 0 }, \
204     { 0, 0 }, \
205     { 0, 0 }, \
206     { 0, 0 }, \
207     { 0, 0 }, \
208     { "icmp6", CTLTYPE_NODE }, \
209     { 0, 0 }, \
210     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
211     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
212     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
213     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
214     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
215     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
216     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
217     { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
218     { 0, 0 }, \
219     { 0, 0 }, \
220     { 0, 0 }, \
221     { 0, 0 }, \
222 }
223 /*
224  * Redefinition of mbuf flags
225  */
226 #define M_AUTHIPHDR     M_PROTO2
227 #define M_DECRYPTED     M_PROTO3
228 #define M_AUTHIPDGM     M_PROTO5
229 
230 struct cmsghdr;
231 struct mbuf;
232 struct ifnet;
233 struct in6_aliasreq;
234 struct lltable;
235 
236 extern struct lltable * in6_lltattach(struct ifnet *ifp);
237 extern uint16_t in6_pseudo(const struct in6_addr *, const struct in6_addr *,
238     uint32_t);
239 extern u_int16_t inet6_cksum(struct mbuf *, uint32_t, uint32_t, uint32_t);
240 extern u_int16_t inet6_cksum_buffer(const uint8_t * __sized_by(len)buffer, uint32_t,
241     uint32_t, uint32_t, uint32_t len);
242 
243 #define in6_cksum(_m, _n, _o, _l)                       \
244     inet6_cksum(_m, _n, _o, _l)
245 #define in6_cksum_buffer(_b, _n, _o, _l, _t)            \
246     inet6_cksum_buffer(_b, _n, _o, _l, _t)
247 
248 extern int in6_addrscope(struct in6_addr *);
249 extern struct in6_ifaddr *in6_ifawithscope(struct ifnet *, struct in6_addr *);
250 extern struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
251 
252 struct sockaddr;
253 
254 extern void in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6);
255 extern void in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
256     struct sockaddr_in6 *sin6);
257 extern void in6_sin6_2_sin_in_sock(struct sockaddr *nam);
258 extern int in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam);
259 
260 extern uint32_t in6_finalize_cksum(struct mbuf *, uint32_t, int32_t,
261     int32_t, uint32_t);
262 
263 #define in6_delayed_cksum(_m)                   \
264     ((void) in6_finalize_cksum(_m, 0, 0, -1, CSUM_DELAY_IPV6_DATA))
265 #define in6_delayed_cksum_offset(_m, _o, _s, _p)        \
266     ((void) in6_finalize_cksum(_m, _o, _s, _p, CSUM_DELAY_IPV6_DATA))
267 
268 /* IPv6 protocol events */
269 extern struct eventhandler_lists_ctxt in6_evhdlr_ctxt;
270 /*
271  * XXX Avoid reordering the enum values below.
272  * If the order is changed, please make sure
273  * in6_event2kev_array is also changed to reflect the
274  * change in order of the enums
275  */
276 typedef enum {
277 	/* Address events */
278 	/*
279 	 * XXX To avoid duplicacy and also for correctness
280 	 * only report these for link local and stable addresses
281 	 * NOTE: Link local address can never be marked detached
282 	 * or duplicated.
283 	 */
284 	IN6_ADDR_MARKED_DUPLICATED,
285 	IN6_ADDR_MARKED_DETACHED,
286 	IN6_ADDR_MARKED_DEPRECATED,
287 
288 	/* Expiry events */
289 	IN6_NDP_RTR_EXPIRY,
290 	IN6_NDP_PFX_EXPIRY,
291 	IN6_NDP_ADDR_EXPIRY,
292 
293 	/* XXX DNS expiry needs to be handled by user-space */
294 	/* MAX */
295 	IN6_EVENT_MAX,
296 } in6_evhdlr_code_t;
297 
298 struct in6_event2kev {
299 	in6_evhdlr_code_t       in6_event_code;
300 	uint32_t                in6_event_kev_subclass;
301 	uint32_t                in6_event_kev_code;
302 	const char              *in6_event_str;
303 };
304 extern struct in6_event2kev in6_event2kev_array[IN6_EVENT_MAX];
305 extern void in6_eventhdlr_callback(struct eventhandler_entry_arg, in6_evhdlr_code_t,
306     struct ifnet *, struct in6_addr *, uint32_t);
307 extern void in6_event_enqueue_nwk_wq_entry(in6_evhdlr_code_t,
308     struct ifnet *, struct in6_addr *, uint32_t);
309 
310 typedef void (*in6_event_fn) (struct eventhandler_entry_arg, in6_evhdlr_code_t,
311     struct ifnet *, struct in6_addr *, uint32_t);
312 EVENTHANDLER_DECLARE(in6_event, in6_event_fn);
313 
314 extern const char *in6_evhdlr_code2str(in6_evhdlr_code_t);
315 #endif /* BSD_KERNEL_PRIVATE */
316 
317 /* CLAT46 events */
318 typedef enum in6_clat46_evhdlr_code_t {
319 	IN6_CLAT46_EVENT_V4_FLOW,
320 	IN6_CLAT46_EVENT_V6_ADDR_CONFFAIL,
321 } in6_clat46_evhdlr_code_t;
322 
323 struct kev_netevent_clat46_data {
324 	in6_clat46_evhdlr_code_t clat46_event_code;
325 	pid_t epid;
326 	uuid_t euuid;
327 };
328 
329 #ifdef BSD_KERNEL_PRIVATE
330 /* CLAT46 events */
331 extern struct eventhandler_lists_ctxt in6_clat46_evhdlr_ctxt;
332 extern void in6_clat46_eventhdlr_callback(struct eventhandler_entry_arg,
333     in6_clat46_evhdlr_code_t, pid_t, uuid_t);
334 extern void in6_clat46_event_enqueue_nwk_wq_entry(in6_clat46_evhdlr_code_t,
335     pid_t, uuid_t);
336 
337 typedef void (*in6_clat46_event_fn) (struct eventhandler_entry_arg, in6_clat46_evhdlr_code_t,
338     pid_t, uuid_t);
339 EVENTHANDLER_DECLARE(in6_clat46_event, in6_clat46_event_fn);
340 
341 extern const char* in6_clat46_evhdlr_code2str(enum in6_clat46_evhdlr_code_t);
342 #endif /* BSD_KERNEL_PRIVATE */
343 
344 #ifdef KERNEL_PRIVATE
345 /* exporte for ApplicationFirewall */
346 extern int in6_localaddr(struct in6_addr *);
347 extern int in6addr_local(struct in6_addr *);
348 #endif /* KERNEL_PRIVATE */
349 
350 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
351 #endif /* XNU_PLATFORM_DriverKit */
352 
353 #endif /* !_NETINET6_IN6_PRIVATE_H_ */
354