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 | #ifdef BSD_KERNEL_PRIVATE |
170 | #define CTL_IPV6PROTO_NAMES { \ |
171 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
172 | { 0, 0 }, \ |
173 | { "tcp6", CTLTYPE_NODE }, \ |
174 | { 0, 0 }, \ |
175 | { 0, 0 }, \ |
176 | { 0, 0 }, \ |
177 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
178 | { 0, 0 }, \ |
179 | { 0, 0 }, \ |
180 | { "udp6", CTLTYPE_NODE }, \ |
181 | { 0, 0 }, \ |
182 | { 0, 0 }, \ |
183 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
184 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
185 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
186 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
187 | { 0, 0 }, \ |
188 | { "ip6", CTLTYPE_NODE }, \ |
189 | { 0, 0 }, \ |
190 | { 0, 0 }, \ |
191 | { 0, 0 }, \ |
192 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
193 | { 0, 0 }, \ |
194 | { "ipsec6", CTLTYPE_NODE }, \ |
195 | { 0, 0 }, \ |
196 | { 0, 0 }, \ |
197 | { 0, 0 }, \ |
198 | { 0, 0 }, \ |
199 | { 0, 0 }, \ |
200 | { 0, 0 }, \ |
201 | { "icmp6", CTLTYPE_NODE }, \ |
202 | { 0, 0 }, \ |
203 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
204 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
205 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
206 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
207 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
208 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
209 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
210 | { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ |
211 | { 0, 0 }, \ |
212 | { 0, 0 }, \ |
213 | { 0, 0 }, \ |
214 | { 0, 0 }, \ |
215 | } |
216 | /* |
217 | * Redefinition of mbuf flags |
218 | */ |
219 | #define M_AUTHIPHDR M_PROTO2 |
220 | #define M_DECRYPTED M_PROTO3 |
221 | #define M_AUTHIPDGM M_PROTO5 |
222 | |
223 | struct cmsghdr; |
224 | struct mbuf; |
225 | struct ifnet; |
226 | struct in6_aliasreq; |
227 | struct lltable; |
228 | |
229 | extern struct lltable * in6_lltattach(struct ifnet *ifp); |
230 | extern uint16_t in6_pseudo(const struct in6_addr *, const struct in6_addr *, |
231 | uint32_t); |
232 | extern u_int16_t inet6_cksum(struct mbuf *, uint32_t, uint32_t, uint32_t); |
233 | extern u_int16_t inet6_cksum_buffer(const uint8_t *, uint32_t, uint32_t, |
234 | uint32_t); |
235 | |
236 | #define in6_cksum(_m, _n, _o, _l) \ |
237 | inet6_cksum(_m, _n, _o, _l) |
238 | #define in6_cksum_buffer(_b, _n, _o, _l) \ |
239 | inet6_cksum_buffer(_b, _n, _o, _l) |
240 | |
241 | extern int in6_addrscope(struct in6_addr *); |
242 | extern struct in6_ifaddr *in6_ifawithscope(struct ifnet *, struct in6_addr *); |
243 | extern struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); |
244 | |
245 | struct sockaddr; |
246 | |
247 | extern void in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6); |
248 | extern void in6_sin_2_v4mapsin6(struct sockaddr_in *sin, |
249 | struct sockaddr_in6 *sin6); |
250 | extern void in6_sin6_2_sin_in_sock(struct sockaddr *nam); |
251 | extern int in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam); |
252 | |
253 | extern uint32_t in6_finalize_cksum(struct mbuf *, uint32_t, int32_t, |
254 | int32_t, uint32_t); |
255 | |
256 | #define in6_delayed_cksum(_m) \ |
257 | ((void) in6_finalize_cksum(_m, 0, 0, -1, CSUM_DELAY_IPV6_DATA)) |
258 | #define in6_delayed_cksum_offset(_m, _o, _s, _p) \ |
259 | ((void) in6_finalize_cksum(_m, _o, _s, _p, CSUM_DELAY_IPV6_DATA)) |
260 | |
261 | /* IPv6 protocol events */ |
262 | extern struct eventhandler_lists_ctxt in6_evhdlr_ctxt; |
263 | /* |
264 | * XXX Avoid reordering the enum values below. |
265 | * If the order is changed, please make sure |
266 | * in6_event2kev_array is also changed to reflect the |
267 | * change in order of the enums |
268 | */ |
269 | typedef enum { |
270 | /* Address events */ |
271 | /* |
272 | * XXX To avoid duplicacy and also for correctness |
273 | * only report these for link local and stable addresses |
274 | * NOTE: Link local address can never be marked detached |
275 | * or duplicated. |
276 | */ |
277 | IN6_ADDR_MARKED_DUPLICATED, |
278 | IN6_ADDR_MARKED_DETACHED, |
279 | IN6_ADDR_MARKED_DEPRECATED, |
280 | |
281 | /* Expiry events */ |
282 | IN6_NDP_RTR_EXPIRY, |
283 | IN6_NDP_PFX_EXPIRY, |
284 | IN6_NDP_ADDR_EXPIRY, |
285 | |
286 | /* XXX DNS expiry needs to be handled by user-space */ |
287 | /* MAX */ |
288 | IN6_EVENT_MAX, |
289 | } in6_evhdlr_code_t; |
290 | |
291 | struct in6_event2kev { |
292 | in6_evhdlr_code_t in6_event_code; |
293 | uint32_t in6_event_kev_subclass; |
294 | uint32_t in6_event_kev_code; |
295 | const char *in6_event_str; |
296 | }; |
297 | extern struct in6_event2kev in6_event2kev_array[]; |
298 | extern void in6_eventhdlr_callback(struct eventhandler_entry_arg, in6_evhdlr_code_t, |
299 | struct ifnet *, struct in6_addr *, uint32_t); |
300 | extern void in6_event_enqueue_nwk_wq_entry(in6_evhdlr_code_t, |
301 | struct ifnet *, struct in6_addr *, uint32_t); |
302 | |
303 | typedef void (*in6_event_fn) (struct eventhandler_entry_arg, in6_evhdlr_code_t, |
304 | struct ifnet *, struct in6_addr *, uint32_t); |
305 | EVENTHANDLER_DECLARE(in6_event, in6_event_fn); |
306 | #endif /* BSD_KERNEL_PRIVATE */ |
307 | |
308 | /* CLAT46 events */ |
309 | typedef enum in6_clat46_evhdlr_code_t { |
310 | IN6_CLAT46_EVENT_V4_FLOW, |
311 | IN6_CLAT46_EVENT_V6_ADDR_CONFFAIL, |
312 | } in6_clat46_evhdlr_code_t; |
313 | |
314 | struct kev_netevent_clat46_data { |
315 | in6_clat46_evhdlr_code_t clat46_event_code; |
316 | pid_t epid; |
317 | uuid_t euuid; |
318 | }; |
319 | |
320 | #ifdef BSD_KERNEL_PRIVATE |
321 | /* CLAT46 events */ |
322 | extern struct eventhandler_lists_ctxt in6_clat46_evhdlr_ctxt; |
323 | extern void in6_clat46_eventhdlr_callback(struct eventhandler_entry_arg, |
324 | in6_clat46_evhdlr_code_t, pid_t, uuid_t); |
325 | extern void in6_clat46_event_enqueue_nwk_wq_entry(in6_clat46_evhdlr_code_t, |
326 | pid_t, uuid_t); |
327 | |
328 | typedef void (*in6_clat46_event_fn) (struct eventhandler_entry_arg, in6_clat46_evhdlr_code_t, |
329 | pid_t, uuid_t); |
330 | EVENTHANDLER_DECLARE(in6_clat46_event, in6_clat46_event_fn); |
331 | #endif /* BSD_KERNEL_PRIVATE */ |
332 | |
333 | #ifdef KERNEL_PRIVATE |
334 | /* exporte for ApplicationFirewall */ |
335 | extern int in6_localaddr(struct in6_addr *); |
336 | extern int in6addr_local(struct in6_addr *); |
337 | #endif /* KERNEL_PRIVATE */ |
338 | |
339 | #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ |
340 | #endif /* XNU_PLATFORM_DriverKit */ |
341 | |
342 | #endif /* !_NETINET6_IN6_PRIVATE_H_ */ |
343 | |