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 <net/if_llatbl.h> 138 #include <sys/eventhandler.h> 139 140 /* 141 * IP6 route structure 142 * 143 * A route consists of a destination address and a reference 144 * to a routing entry. These are often held by protocols 145 * in their control blocks, e.g. inpcb. 146 */ 147 struct route_in6 { 148 /* 149 * N.B: struct route_in6 must begin with ro_{rt,srcia,flags} 150 * because the code does some casts of a 'struct route_in6 *' 151 * to a 'struct route *'. 152 */ 153 struct rtentry *ro_rt; 154 struct llentry *ro_lle; 155 156 struct ifaddr *ro_srcia; 157 uint32_t ro_flags; /* route flags */ 158 struct sockaddr_in6 ro_dst; 159 }; 160 #endif /* BSD_KERNEL_PRIVATE */ 161 162 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 163 164 /* 165 * Options for use with [gs]etsockopt at the IPV6 level. 166 * First word of comment is data type; bool is stored in int. 167 */ 168 #define IPV6_NO_IFT_CELLULAR 6969 /* for internal use only */ 169 #define IPV6_OUT_IF 9696 /* for internal use only */ 170 171 #ifdef BSD_KERNEL_PRIVATE 172 #define CTL_IPV6PROTO_NAMES { \ 173 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 174 { 0, 0 }, \ 175 { "tcp6", CTLTYPE_NODE }, \ 176 { 0, 0 }, \ 177 { 0, 0 }, \ 178 { 0, 0 }, \ 179 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 180 { 0, 0 }, \ 181 { 0, 0 }, \ 182 { "udp6", CTLTYPE_NODE }, \ 183 { 0, 0 }, \ 184 { 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 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 188 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 189 { 0, 0 }, \ 190 { "ip6", CTLTYPE_NODE }, \ 191 { 0, 0 }, \ 192 { 0, 0 }, \ 193 { 0, 0 }, \ 194 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 195 { 0, 0 }, \ 196 { "ipsec6", CTLTYPE_NODE }, \ 197 { 0, 0 }, \ 198 { 0, 0 }, \ 199 { 0, 0 }, \ 200 { 0, 0 }, \ 201 { 0, 0 }, \ 202 { 0, 0 }, \ 203 { "icmp6", CTLTYPE_NODE }, \ 204 { 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 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 212 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 213 { 0, 0 }, \ 214 { 0, 0 }, \ 215 { 0, 0 }, \ 216 { 0, 0 }, \ 217 } 218 /* 219 * Redefinition of mbuf flags 220 */ 221 #define M_AUTHIPHDR M_PROTO2 222 #define M_DECRYPTED M_PROTO3 223 #define M_AUTHIPDGM M_PROTO5 224 225 struct cmsghdr; 226 struct mbuf; 227 struct ifnet; 228 struct in6_aliasreq; 229 struct lltable; 230 231 extern struct lltable * in6_lltattach(struct ifnet *ifp); 232 extern uint16_t in6_pseudo(const struct in6_addr *, const struct in6_addr *, 233 uint32_t); 234 extern u_int16_t inet6_cksum(struct mbuf *, uint32_t, uint32_t, uint32_t); 235 extern u_int16_t inet6_cksum_buffer(const uint8_t *, uint32_t, uint32_t, 236 uint32_t); 237 238 #define in6_cksum(_m, _n, _o, _l) \ 239 inet6_cksum(_m, _n, _o, _l) 240 #define in6_cksum_buffer(_b, _n, _o, _l) \ 241 inet6_cksum_buffer(_b, _n, _o, _l) 242 243 extern int in6_addrscope(struct in6_addr *); 244 extern struct in6_ifaddr *in6_ifawithscope(struct ifnet *, struct in6_addr *); 245 extern struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *); 246 247 struct sockaddr; 248 249 extern void in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6); 250 extern void in6_sin_2_v4mapsin6(struct sockaddr_in *sin, 251 struct sockaddr_in6 *sin6); 252 extern void in6_sin6_2_sin_in_sock(struct sockaddr *nam); 253 extern int in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam); 254 255 extern uint32_t in6_finalize_cksum(struct mbuf *, uint32_t, int32_t, 256 int32_t, uint32_t); 257 258 #define in6_delayed_cksum(_m) \ 259 ((void) in6_finalize_cksum(_m, 0, 0, -1, CSUM_DELAY_IPV6_DATA)) 260 #define in6_delayed_cksum_offset(_m, _o, _s, _p) \ 261 ((void) in6_finalize_cksum(_m, _o, _s, _p, CSUM_DELAY_IPV6_DATA)) 262 263 /* IPv6 protocol events */ 264 extern struct eventhandler_lists_ctxt in6_evhdlr_ctxt; 265 /* 266 * XXX Avoid reordering the enum values below. 267 * If the order is changed, please make sure 268 * in6_event2kev_array is also changed to reflect the 269 * change in order of the enums 270 */ 271 typedef enum { 272 /* Address events */ 273 /* 274 * XXX To avoid duplicacy and also for correctness 275 * only report these for link local and stable addresses 276 * NOTE: Link local address can never be marked detached 277 * or duplicated. 278 */ 279 IN6_ADDR_MARKED_DUPLICATED, 280 IN6_ADDR_MARKED_DETACHED, 281 IN6_ADDR_MARKED_DEPRECATED, 282 283 /* Expiry events */ 284 IN6_NDP_RTR_EXPIRY, 285 IN6_NDP_PFX_EXPIRY, 286 IN6_NDP_ADDR_EXPIRY, 287 288 /* XXX DNS expiry needs to be handled by user-space */ 289 /* MAX */ 290 IN6_EVENT_MAX, 291 } in6_evhdlr_code_t; 292 293 struct in6_event2kev { 294 in6_evhdlr_code_t in6_event_code; 295 uint32_t in6_event_kev_subclass; 296 uint32_t in6_event_kev_code; 297 const char *in6_event_str; 298 }; 299 extern struct in6_event2kev in6_event2kev_array[]; 300 extern void in6_eventhdlr_callback(struct eventhandler_entry_arg, in6_evhdlr_code_t, 301 struct ifnet *, struct in6_addr *, uint32_t); 302 extern void in6_event_enqueue_nwk_wq_entry(in6_evhdlr_code_t, 303 struct ifnet *, struct in6_addr *, uint32_t); 304 305 typedef void (*in6_event_fn) (struct eventhandler_entry_arg, in6_evhdlr_code_t, 306 struct ifnet *, struct in6_addr *, uint32_t); 307 EVENTHANDLER_DECLARE(in6_event, in6_event_fn); 308 #endif /* BSD_KERNEL_PRIVATE */ 309 310 /* CLAT46 events */ 311 typedef enum in6_clat46_evhdlr_code_t { 312 IN6_CLAT46_EVENT_V4_FLOW, 313 IN6_CLAT46_EVENT_V6_ADDR_CONFFAIL, 314 } in6_clat46_evhdlr_code_t; 315 316 struct kev_netevent_clat46_data { 317 in6_clat46_evhdlr_code_t clat46_event_code; 318 pid_t epid; 319 uuid_t euuid; 320 }; 321 322 #ifdef BSD_KERNEL_PRIVATE 323 /* CLAT46 events */ 324 extern struct eventhandler_lists_ctxt in6_clat46_evhdlr_ctxt; 325 extern void in6_clat46_eventhdlr_callback(struct eventhandler_entry_arg, 326 in6_clat46_evhdlr_code_t, pid_t, uuid_t); 327 extern void in6_clat46_event_enqueue_nwk_wq_entry(in6_clat46_evhdlr_code_t, 328 pid_t, uuid_t); 329 330 typedef void (*in6_clat46_event_fn) (struct eventhandler_entry_arg, in6_clat46_evhdlr_code_t, 331 pid_t, uuid_t); 332 EVENTHANDLER_DECLARE(in6_clat46_event, in6_clat46_event_fn); 333 #endif /* BSD_KERNEL_PRIVATE */ 334 335 #ifdef KERNEL_PRIVATE 336 /* exporte for ApplicationFirewall */ 337 extern int in6_localaddr(struct in6_addr *); 338 extern int in6addr_local(struct in6_addr *); 339 #endif /* KERNEL_PRIVATE */ 340 341 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 342 #endif /* XNU_PLATFORM_DriverKit */ 343 344 #endif /* !_NETINET6_IN6_PRIVATE_H_ */ 345