| 1 | /* |
| 2 | * Copyright (c) 2000-2018 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 | * Copyright (c) 1982, 1986, 1990, 1993 |
| 30 | * The Regents of the University of California. All rights reserved. |
| 31 | * |
| 32 | * Redistribution and use in source and binary forms, with or without |
| 33 | * modification, are permitted provided that the following conditions |
| 34 | * are met: |
| 35 | * 1. Redistributions of source code must retain the above copyright |
| 36 | * notice, this list of conditions and the following disclaimer. |
| 37 | * 2. Redistributions in binary form must reproduce the above copyright |
| 38 | * notice, this list of conditions and the following disclaimer in the |
| 39 | * documentation and/or other materials provided with the distribution. |
| 40 | * 3. All advertising materials mentioning features or use of this software |
| 41 | * must display the following acknowledgement: |
| 42 | * This product includes software developed by the University of |
| 43 | * California, Berkeley and its contributors. |
| 44 | * 4. Neither the name of the University nor the names of its contributors |
| 45 | * may be used to endorse or promote products derived from this software |
| 46 | * without specific prior written permission. |
| 47 | * |
| 48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 58 | * SUCH DAMAGE. |
| 59 | * |
| 60 | * @(#)in.h 8.3 (Berkeley) 1/3/94 |
| 61 | * $FreeBSD: src/sys/netinet/in.h,v 1.48.2.2 2001/04/21 14:53:06 ume Exp $ |
| 62 | */ |
| 63 | |
| 64 | #ifndef _NETINET_IN_PRIVATE_H_ |
| 65 | #define _NETINET_IN_PRIVATE_H_ |
| 66 | |
| 67 | #include <netinet/in.h> |
| 68 | #include <sys/socket.h> |
| 69 | #include <sys/types.h> |
| 70 | |
| 71 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 72 | /* 253-254: Experimentation and testing; 255: Reserved (RFC3692) */ |
| 73 | /* BSD Private, local use, namespace incursion */ |
| 74 | #define IPPROTO_QUIC 253 /* QUIC protocol (Over UDP) */ |
| 75 | |
| 76 | #ifdef __APPLE__ |
| 77 | #define IN_SHARED_ADDRESS_SPACE(i) ((((u_int32_t)(i)) & (u_int32_t)0xffc00000) \ |
| 78 | == (u_int32_t)0x64400000) |
| 79 | |
| 80 | #define IN_DS_LITE(i) ((((u_int32_t)(i)) & (u_int32_t)0xfffffff8) == (u_int32_t)0xc0000000) |
| 81 | |
| 82 | #define IN_6TO4_RELAY_ANYCAST(i) ((((u_int32_t)(i)) & (u_int32_t)IN_CLASSC_NET) == (u_int32_t)0xc0586300) |
| 83 | #endif /* __APPLE__ */ |
| 84 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 85 | |
| 86 | /* |
| 87 | * sockaddr_in with scope ID field; this is used internally to keep |
| 88 | * track of scoped route entries in the routing table. The fact that |
| 89 | * such a value is embedded in the structure is an artifact of the |
| 90 | * current implementation which could change in future. |
| 91 | */ |
| 92 | struct sockaddr_inifscope { |
| 93 | __uint8_t sin_len; |
| 94 | sa_family_t sin_family; |
| 95 | in_port_t sin_port; |
| 96 | struct in_addr sin_addr; |
| 97 | /* |
| 98 | * To avoid possible conflict with an overlaid sockaddr_inarp |
| 99 | * having sin_other set to SIN_PROXY, we use the first 4-bytes |
| 100 | * of sin_zero since sin_srcaddr is one of the unused fields |
| 101 | * in sockaddr_inarp. |
| 102 | */ |
| 103 | union { |
| 104 | char sin_zero[8]; |
| 105 | struct { |
| 106 | __uint32_t ifscope; |
| 107 | } _in_index; |
| 108 | } un; |
| 109 | #define sin_scope_id un._in_index.ifscope |
| 110 | }; |
| 111 | |
| 112 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 113 | |
| 114 | /* |
| 115 | * Options for use with [gs]etsockopt at the IP level. |
| 116 | * First word of comment is data type; bool is stored in int. |
| 117 | */ |
| 118 | #define IP_NO_IFT_CELLULAR 6969 /* for internal use only */ |
| 119 | #define IP_NO_IFT_PDP IP_NO_IFT_CELLULAR /* deprecated */ |
| 120 | #define IP_OUT_IF 9696 /* for internal use only */ |
| 121 | |
| 122 | #ifdef BSD_KERNEL_PRIVATE |
| 123 | #define CTL_IPPROTO_NAMES { \ |
| 124 | { "ip", CTLTYPE_NODE }, \ |
| 125 | { "icmp", CTLTYPE_NODE }, \ |
| 126 | { "igmp", CTLTYPE_NODE }, \ |
| 127 | { "ggp", CTLTYPE_NODE }, \ |
| 128 | { 0, 0 }, \ |
| 129 | { 0, 0 }, \ |
| 130 | { "tcp", CTLTYPE_NODE }, \ |
| 131 | { 0, 0 }, \ |
| 132 | { "egp", CTLTYPE_NODE }, \ |
| 133 | { 0, 0 }, \ |
| 134 | { 0, 0 }, \ |
| 135 | { 0, 0 }, \ |
| 136 | { "pup", CTLTYPE_NODE }, \ |
| 137 | { 0, 0 }, \ |
| 138 | { 0, 0 }, \ |
| 139 | { 0, 0 }, \ |
| 140 | { 0, 0 }, \ |
| 141 | { "udp", CTLTYPE_NODE }, \ |
| 142 | { 0, 0 }, \ |
| 143 | { 0, 0 }, \ |
| 144 | { 0, 0 }, \ |
| 145 | { 0, 0 }, \ |
| 146 | { "idp", CTLTYPE_NODE }, \ |
| 147 | { 0, 0 }, \ |
| 148 | { 0, 0 }, \ |
| 149 | { 0, 0 }, \ |
| 150 | { 0, 0 }, \ |
| 151 | { 0, 0 }, \ |
| 152 | { 0, 0 }, \ |
| 153 | { 0, 0 }, \ |
| 154 | { 0, 0 }, \ |
| 155 | { 0, 0 }, \ |
| 156 | { 0, 0 }, \ |
| 157 | { 0, 0 }, \ |
| 158 | { 0, 0 }, \ |
| 159 | { 0, 0 }, \ |
| 160 | { 0, 0 }, \ |
| 161 | { 0, 0 }, \ |
| 162 | { 0, 0 }, \ |
| 163 | { 0, 0 }, \ |
| 164 | { 0, 0 }, \ |
| 165 | { 0, 0 }, \ |
| 166 | { 0, 0 }, \ |
| 167 | { 0, 0 }, \ |
| 168 | { 0, 0 }, \ |
| 169 | { 0, 0 }, \ |
| 170 | { 0, 0 }, \ |
| 171 | { 0, 0 }, \ |
| 172 | { 0, 0 }, \ |
| 173 | { 0, 0 }, \ |
| 174 | { 0, 0 }, \ |
| 175 | { "ipsec", CTLTYPE_NODE }, \ |
| 176 | } |
| 177 | |
| 178 | #define IPCTL_NAMES { \ |
| 179 | { 0, 0 }, \ |
| 180 | { "forwarding", CTLTYPE_INT }, \ |
| 181 | { "redirect", CTLTYPE_INT }, \ |
| 182 | { "ttl", CTLTYPE_INT }, \ |
| 183 | { "mtu", CTLTYPE_INT }, \ |
| 184 | { "rtexpire", CTLTYPE_INT }, \ |
| 185 | { "rtminexpire", CTLTYPE_INT }, \ |
| 186 | { "rtmaxcache", CTLTYPE_INT }, \ |
| 187 | { "sourceroute", CTLTYPE_INT }, \ |
| 188 | { "directed-broadcast", CTLTYPE_INT }, \ |
| 189 | { "intr-queue-maxlen", CTLTYPE_INT }, \ |
| 190 | { "intr-queue-drops", CTLTYPE_INT }, \ |
| 191 | { "stats", CTLTYPE_STRUCT }, \ |
| 192 | { "accept_sourceroute", CTLTYPE_INT }, \ |
| 193 | { "fastforwarding", CTLTYPE_INT }, \ |
| 194 | { "keepfaith", CTLTYPE_INT }, \ |
| 195 | { "gifttl", CTLTYPE_INT }, \ |
| 196 | } |
| 197 | #endif /* BSD_KERNEL_PRIVATE */ |
| 198 | |
| 199 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 200 | |
| 201 | /* INET6 stuff */ |
| 202 | #define __KAME_NETINET_IN_PRIVATE_H_INCLUDED_ |
| 203 | #include <netinet6/in6_private.h> |
| 204 | #undef __KAME_NETINET_IN_PRIVATE_H_INCLUDED_ |
| 205 | |
| 206 | /* |
| 207 | * Minimal sized structure to hold an IPv4 or IPv6 socket address |
| 208 | * as sockaddr_storage can waste memory |
| 209 | */ |
| 210 | |
| 211 | union sockaddr_in_4_6 { |
| 212 | struct sockaddr sa; |
| 213 | struct __sockaddr_header sah; |
| 214 | struct sockaddr_in sin; |
| 215 | struct sockaddr_in6 sin6; |
| 216 | }; |
| 217 | #define CLAT46_HDR_EXPANSION_OVERHD (sizeof(struct ip6_hdr) - sizeof(struct ip)) |
| 218 | |
| 219 | /* |
| 220 | * Recommended DiffServ Code Point values |
| 221 | */ |
| 222 | |
| 223 | #define _DSCP_DF 0 /* RFC 2474 */ |
| 224 | |
| 225 | #define _DSCP_CS0 0 /* RFC 2474 */ |
| 226 | #define _DSCP_CS1 8 /* RFC 2474 */ |
| 227 | #define _DSCP_CS2 16 /* RFC 2474 */ |
| 228 | #define _DSCP_CS3 24 /* RFC 2474 */ |
| 229 | #define _DSCP_CS4 32 /* RFC 2474 */ |
| 230 | #define _DSCP_CS5 40 /* RFC 2474 */ |
| 231 | #define _DSCP_CS6 48 /* RFC 2474 */ |
| 232 | #define _DSCP_CS7 56 /* RFC 2474 */ |
| 233 | |
| 234 | #define _DSCP_EF 46 /* RFC 2474 */ |
| 235 | #define _DSCP_VA 44 /* RFC 5865 */ |
| 236 | |
| 237 | #define _DSCP_AF11 10 /* RFC 2597 */ |
| 238 | #define _DSCP_AF12 12 /* RFC 2597 */ |
| 239 | #define _DSCP_AF13 14 /* RFC 2597 */ |
| 240 | #define _DSCP_AF21 18 /* RFC 2597 */ |
| 241 | #define _DSCP_AF22 20 /* RFC 2597 */ |
| 242 | #define _DSCP_AF23 22 /* RFC 2597 */ |
| 243 | #define _DSCP_AF31 26 /* RFC 2597 */ |
| 244 | #define _DSCP_AF32 28 /* RFC 2597 */ |
| 245 | #define _DSCP_AF33 30 /* RFC 2597 */ |
| 246 | #define _DSCP_AF41 34 /* RFC 2597 */ |
| 247 | #define _DSCP_AF42 36 /* RFC 2597 */ |
| 248 | #define _DSCP_AF43 38 /* RFC 2597 */ |
| 249 | |
| 250 | #define _DSCP_52 52 /* Wi-Fi WMM Certification: Sigma */ |
| 251 | |
| 252 | #define _MAX_DSCP 63 /* coded on 6 bits */ |
| 253 | |
| 254 | #ifndef XNU_PLATFORM_DriverKit |
| 255 | #ifdef KERNEL |
| 256 | #ifdef BSD_KERNEL_PRIVATE |
| 257 | #include <mach/boolean.h> |
| 258 | |
| 259 | struct ip; |
| 260 | struct ifnet; |
| 261 | struct mbuf; |
| 262 | |
| 263 | extern boolean_t in_broadcast(struct in_addr, struct ifnet *); |
| 264 | extern boolean_t in_canforward(struct in_addr); |
| 265 | extern u_int32_t in_netof(struct in_addr); |
| 266 | |
| 267 | extern uint32_t os_cpu_in_cksum_mbuf(struct mbuf *m, int len, int off, |
| 268 | uint32_t initial_sum); |
| 269 | |
| 270 | extern uint16_t inet_cksum(struct mbuf *, uint32_t, uint32_t, uint32_t); |
| 271 | extern uint16_t inet_cksum_buffer(const void *__sized_by(__len), uint32_t, uint32_t, uint32_t __len); |
| 272 | extern uint16_t in_addword(uint16_t, uint16_t); |
| 273 | extern uint16_t in_pseudo(uint32_t, uint32_t, uint32_t); |
| 274 | extern uint16_t in_pseudo64(uint64_t, uint64_t, uint64_t); |
| 275 | extern uint16_t in_cksum_hdr_opt(const struct ip *); |
| 276 | extern uint16_t ip_cksum_hdr_dir(struct mbuf *, uint32_t, int); |
| 277 | extern uint16_t ip_cksum_hdr_dir_buffer(const void *__sized_by(__len), uint32_t, uint32_t __len, int); |
| 278 | extern uint32_t in_finalize_cksum(struct mbuf *, uint32_t, uint32_t); |
| 279 | extern uint16_t b_sum16(const void *__sized_by(len)buf, int len); |
| 280 | #if DEBUG || DEVELOPMENT |
| 281 | extern uint32_t in_cksum_mbuf_ref(struct mbuf *, int, int, uint32_t); |
| 282 | #endif /* DEBUG || DEVELOPMENT */ |
| 283 | |
| 284 | extern int in_getconninfo(struct socket *, sae_connid_t, uint32_t *, |
| 285 | uint32_t *, int32_t *, user_addr_t, socklen_t *, user_addr_t, socklen_t *, |
| 286 | uint32_t *, user_addr_t, uint32_t *); |
| 287 | extern struct in_ifaddr * inifa_ifpwithflag(struct ifnet *, uint32_t); |
| 288 | extern struct in_ifaddr * inifa_ifpclatv4(struct ifnet *); |
| 289 | |
| 290 | #define in_cksum(_m, _l) \ |
| 291 | inet_cksum(_m, 0, 0, _l) |
| 292 | #define in_cksum_buffer(_b, _l) \ |
| 293 | inet_cksum_buffer(_b, 0, 0, _l) |
| 294 | #define ip_cksum_hdr_in(_m, _l) \ |
| 295 | ip_cksum_hdr_dir(_m, _l, 0) |
| 296 | #define ip_cksum_hdr_out(_m, _l) \ |
| 297 | ip_cksum_hdr_dir(_m, _l, 1) |
| 298 | |
| 299 | #define in_cksum_hdr(_ip) \ |
| 300 | (~b_sum16(_ip, sizeof (struct ip)) & 0xffff) |
| 301 | |
| 302 | #define in_cksum_offset(_m, _o) \ |
| 303 | ((void) in_finalize_cksum(_m, _o, CSUM_DELAY_IP)) |
| 304 | #define in_delayed_cksum(_m) \ |
| 305 | ((void) in_finalize_cksum(_m, 0, CSUM_DELAY_DATA)) |
| 306 | #define in_delayed_cksum_offset(_m, _o) \ |
| 307 | ((void) in_finalize_cksum(_m, _o, CSUM_DELAY_DATA)) |
| 308 | |
| 309 | #define in_hosteq(s, t) ((s).s_addr == (t).s_addr) |
| 310 | #define in_nullhost(x) ((x).s_addr == INADDR_ANY) |
| 311 | #define in_allhosts(x) ((x).s_addr == htonl(INADDR_ALLHOSTS_GROUP)) |
| 312 | |
| 313 | #define SIN(s) ((struct sockaddr_in *)(void *)s) |
| 314 | #define satosin(sa) SIN(sa) |
| 315 | #define sintosa(sin) ((struct sockaddr *)(void *)(sin)) |
| 316 | #define SINIFSCOPE(s) ((struct sockaddr_inifscope *)(void *)(s)) |
| 317 | |
| 318 | #define IPTOS_UNSPEC (-1) /* TOS byte not set */ |
| 319 | #define IPTOS_MASK 0xFF /* TOS byte mask */ |
| 320 | #endif /* BSD_KERNEL_PRIVATE */ |
| 321 | |
| 322 | #ifdef KERNEL_PRIVATE |
| 323 | /* exported for ApplicationFirewall */ |
| 324 | extern int in_localaddr(struct in_addr); |
| 325 | extern int inaddr_local(struct in_addr); |
| 326 | |
| 327 | extern char *inet_ntoa(struct in_addr); |
| 328 | extern char *inet_ntoa_r(struct in_addr ina, char *buf, |
| 329 | size_t buflen); |
| 330 | extern int inet_pton(int af, const char *, void *); |
| 331 | #endif /* KERNEL_PRIVATE */ |
| 332 | |
| 333 | #endif /* KERNEL */ |
| 334 | #endif /* XNU_PLATFORM_DriverKit */ |
| 335 | |
| 336 | #endif /* _NETINET_IN_PRIVATE_H_ */ |
| 337 | |