1 /* 2 * Copyright (c) 2023 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 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */ 29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ 30 /* 31 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 32 * The Regents of the University of California. All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. All advertising materials mentioning features or use of this software 43 * must display the following acknowledgement: 44 * This product includes software developed by the University of 45 * California, Berkeley and its contributors. 46 * 4. Neither the name of the University nor the names of its contributors 47 * may be used to endorse or promote products derived from this software 48 * without specific prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 * 62 * @(#)socket.h 8.4 (Berkeley) 2/21/94 63 * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $ 64 */ 65 /* 66 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce 67 * support for mandatory and extensible security protections. This notice 68 * is included in support of clause 2.2 (b) of the Apple Public License, 69 * Version 2.0. 70 */ 71 72 #ifndef _SYS_SOCKET_PRIVATE_H_ 73 #define _SYS_SOCKET_PRIVATE_H_ 74 75 #include <sys/types.h> 76 #include <sys/cdefs.h> 77 #include <sys/constrained_ctypes.h> 78 #include <sys/socket.h> 79 80 #include <sys/param.h> 81 #include <uuid/uuid.h> 82 83 #ifdef XNU_KERNEL_PRIVATE 84 #include <kern/assert.h> 85 #include <kern/kalloc.h> 86 #endif /* XNU_KERNEL_PRIVATE */ 87 88 /* 89 * Option flags per-socket. 90 */ 91 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 92 #ifdef __APPLE__ 93 #define SO_NOWAKEFROMSLEEP 0x10000 /* Don't wake for traffic to this socket */ 94 #define SO_NOAPNFALLBK 0x20000 /* Don't attempt APN fallback for the socket */ 95 #define SO_TIMESTAMP_CONTINUOUS 0x40000 /* Continuous monotonic timestamp on rcvd dgram */ 96 97 /* 98 * Additional options, not kept in so_options. 99 */ 100 #define SO_RESTRICTIONS 0x1081 /* APPLE: deny flag set */ 101 #define SO_RESTRICT_DENY_IN 0x1 /* deny inbound (trapdoor) */ 102 #define SO_RESTRICT_DENY_OUT 0x2 /* deny outbound (trapdoor) */ 103 #define SO_RESTRICT_DENY_CELLULAR 0x4 /* deny use of cellular (trapdoor) */ 104 #define SO_RESTRICT_DENY_EXPENSIVE 0x8 /* deny use of expensive if (trapdoor) */ 105 #define SO_RESTRICT_DENY_CONSTRAINED 0x10 /* deny use of expensive if (trapdoor) */ 106 #endif 107 108 #define SO_EXECPATH 0x1085 /* Application Firewall Socket option */ 109 110 /* 111 * Traffic service class definitions (lowest to highest): 112 * 113 * SO_TC_BK_SYS 114 * "Background System-Initiated", high delay tolerant, high loss 115 * tolerant, elastic flow, variable size & long-lived. E.g: system- 116 * initiated iCloud synching or Time Capsule backup, for which there 117 * is no progress feedbacks. 118 * 119 * SO_TC_BK 120 * "Background", user-initiated, high delay tolerant, high loss tolerant, 121 * elastic flow, variable size. E.g. user-initiated iCloud synching or 122 * Time Capsule backup; or traffics of background applications, for which 123 * there is some progress feedbacks. 124 * 125 * SO_TC_BE 126 * "Best Effort", unclassified/standard. This is the default service 127 * class; pretty much a mix of everything. 128 * 129 * SO_TC_RD 130 * "Responsive Data", a notch higher than "Best Effort", medium delay 131 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email, 132 * instant messaging, for which there is a sense of interactivity and 133 * urgency (user waiting for output). 134 * 135 * SO_TC_OAM 136 * "Operations, Administration, and Management", medium delay tolerant, 137 * low-medium loss tolerant, elastic & inelastic flows, variable size. 138 * E.g. VPN tunnels. 139 * 140 * SO_TC_AV 141 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium 142 * loss tolerant, elastic flow, constant packet interval, variable rate & 143 * size. E.g. AirPlay playback (both video and audio). 144 * 145 * SO_TC_RV 146 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium 147 * loss tolerant, elastic flow, variable packet interval, rate and size. 148 * E.g. AirPlay mirroring, screen sharing. 149 * 150 * SO_TC_VI 151 * "Interactive Video", low delay tolerant, low-medium loss tolerant, 152 * elastic flow, constant packet interval, variable rate & size. E.g. 153 * FaceTime video. 154 * 155 * SO_TC_VO 156 * "Interactive Voice", low delay tolerant, low loss tolerant, inelastic 157 * flow, constant packet rate, somewhat fixed size. E.g. VoIP including 158 * FaceTime audio. 159 * 160 * SO_TC_CTL 161 * "Network Control", low delay tolerant, low loss tolerant, inelastic 162 * flow, rate is bursty but short, variable size. E.g. DNS queries; 163 * certain types of locally-originated ICMP, ICMPv6; IGMP/MLD join/leave, 164 * ARP. 165 */ 166 #define SO_TRAFFIC_CLASS 0x1086 /* Traffic service class (int) */ 167 #define SO_TC_BK_SYS 100 /* lowest class */ 168 #define SO_TC_BK 200 169 #define SO_TC_BE 0 170 #define SO_TC_RD 300 171 #define SO_TC_OAM 400 172 #define SO_TC_AV 500 173 #define SO_TC_RV 600 174 #define SO_TC_VI 700 175 #define SO_TC_VO 800 176 #define SO_TC_CTL 900 /* highest class */ 177 #define SO_TC_MAX 10 /* Total # of traffic classes */ 178 #ifdef XNU_KERNEL_PRIVATE 179 #define _SO_TC_BK 1 /* deprecated */ 180 #define _SO_TC_VI 2 /* deprecated */ 181 #define _SO_TC_VO 3 /* deprecated */ 182 #define _SO_TC_MAX 4 /* deprecated */ 183 184 #define SO_VALID_TC(c) \ 185 (c == SO_TC_BK_SYS || c == SO_TC_BK || c == SO_TC_BE || \ 186 c == SO_TC_RD || c == SO_TC_OAM || c == SO_TC_AV || \ 187 c == SO_TC_RV || c == SO_TC_VI || c == SO_TC_VO || \ 188 c == SO_TC_CTL || c == SO_TC_NETSVC_SIG) 189 190 #define SO_TC_UNSPEC ((int)-1) /* Traffic class not specified */ 191 192 #define SO_TC_SIG SO_TC_VI /* to be removed XXX */ 193 194 #define SOTCIX_BK_SYS 0 195 #define SOTCIX_BK 1 196 #define SOTCIX_BE 2 197 #define SOTCIX_RD 3 198 #define SOTCIX_OAM 4 199 #define SOTCIX_AV 5 200 #define SOTCIX_RV 6 201 #define SOTCIX_VI 7 202 #define SOTCIX_VO 8 203 #define SOTCIX_CTL 9 204 #endif /* XNU_KERNEL_PRIVATE */ 205 206 /* Background socket configuration flags */ 207 #define TRAFFIC_MGT_SO_BACKGROUND 0x0001 /* background socket */ 208 #define TRAFFIC_MGT_TCP_RECVBG 0x0002 /* Only TCP sockets, receiver throttling */ 209 210 #define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool) */ 211 #define SO_TRAFFIC_CLASS_DBG 0x1088 /* Debug traffic class (struct so_tcdbg) */ 212 #define SO_OPTION_UNUSED_0 0x1089 /* Traffic class statistics */ 213 #define SO_PRIVILEGED_TRAFFIC_CLASS 0x1090 /* Privileged traffic class (bool) */ 214 #define SO_DEFUNCTIT 0x1091 /* Defunct a socket (only in internal builds) */ 215 #define SO_DEFUNCTOK 0x1100 /* can be defunct'd */ 216 #define SO_ISDEFUNCT 0x1101 /* get defunct status */ 217 218 #define SO_OPPORTUNISTIC 0x1102 /* deprecated; use SO_TRAFFIC_CLASS */ 219 220 /* 221 * SO_FLUSH flushes any unsent data generated by a given socket. It takes 222 * an integer parameter, which can be any of the SO_TC traffic class values, 223 * or the special SO_TC_ALL value. 224 */ 225 #define SO_FLUSH 0x1103 /* flush unsent data (int) */ 226 #define SO_TC_ALL (-1) 227 228 #define SO_RECV_ANYIF 0x1104 /* unrestricted inbound processing */ 229 #define SO_TRAFFIC_MGT_BACKGROUND 0x1105 /* Background traffic management */ 230 231 #define SO_FLOW_DIVERT_TOKEN 0x1106 /* flow divert token */ 232 233 #define SO_DELEGATED 0x1107 /* set socket as delegate (pid_t) */ 234 #define SO_DELEGATED_UUID 0x1108 /* set socket as delegate (uuid_t) */ 235 #define SO_NECP_ATTRIBUTES 0x1109 /* NECP socket attributes (domain, account, etc.) */ 236 #define SO_CFIL_SOCK_ID 0x1110 /* get content filter socket ID (cfil_sock_id_t) */ 237 #define SO_NECP_CLIENTUUID 0x1111 /* NECP Client uuid */ 238 239 #define SO_AWDL_UNRESTRICTED 0x1113 /* try to use AWDL in restricted mode */ 240 #define SO_EXTENDED_BK_IDLE 0x1114 /* extended time to keep socket idle after app is suspended (int) */ 241 #define SO_MARK_CELLFALLBACK 0x1115 /* Mark as initiated by cell fallback */ 242 243 #define SO_QOSMARKING_POLICY_OVERRIDE 0x1117 /* int */ 244 #define SO_INTCOPROC_ALLOW 0x1118 /* Try to use internal co-processor interfaces. */ 245 246 #define SO_NECP_LISTENUUID 0x1120 /* NECP client UUID for listener */ 247 #define SO_MPKL_SEND_INFO 0x1122 /* (struct so_mpkl_send_info) */ 248 #define SO_STATISTICS_EVENT 0x1123 /* int64 argument, an event in statistics collection */ 249 #define SO_WANT_KEV_SOCKET_CLOSED 0x1124 /* want delivery of KEV_SOCKET_CLOSED (int) */ 250 #define SO_MARK_KNOWN_TRACKER 0x1125 /* Mark as a connection to a known tracker */ 251 #define SO_MARK_KNOWN_TRACKER_NON_APP_INITIATED 0x1126 /* Mark tracker connection to be non-app initiated */ 252 #define SO_MARK_WAKE_PKT 0x1127 /* Mark next packet as a wake packet, one shot (int) */ 253 #define SO_RECV_WAKE_PKT 0x1128 /* Receive wake packet indication as ancillary data (int) */ 254 #define SO_MARK_APPROVED_APP_DOMAIN 0x1129 /* Mark connection as being for an approved associated app domain */ 255 #define SO_FALLBACK_MODE 0x1130 /* Indicates the mode of fallback used */ 256 257 #define SO_MARK_CELLFALLBACK_UUID 0x1132 /* Mark as initiated by cell fallback using UUID of the connection */ 258 #define SO_APPLICATION_ID 0x1133 /* ID of attributing app - so_application_id_t */ 259 /* 0x1134 is SO_BINDTODEVICE, see socket.h */ 260 #define SO_MARK_DOMAIN_INFO_SILENT 0x1135 /* Domain information should be silently withheld */ 261 #define SO_MAX_PACING_RATE 0x1136 /* Define per-socket maximum pacing rate in bytes/sec */ 262 #define SO_CONNECTION_IDLE 0x1137 /* Connection is idle (int) */ 263 264 struct so_mark_cellfallback_uuid_args { 265 uuid_t flow_uuid; 266 int flow_cellfallback; 267 }; 268 269 typedef struct { 270 uid_t uid; 271 uuid_t effective_uuid; 272 uid_t persona_id; 273 } so_application_id_t; 274 275 #define _NET_SERVICE_TYPE_COUNT 9 276 #define _NET_SERVICE_TYPE_UNSPEC ((int)-1) 277 278 #define IS_VALID_NET_SERVICE_TYPE(c) \ 279 (c >= NET_SERVICE_TYPE_BE && c <= NET_SERVICE_TYPE_RD) 280 281 extern const int sotc_by_netservicetype[_NET_SERVICE_TYPE_COUNT]; 282 283 /* 284 * Facility to pass Network Service Type values using SO_TRAFFIC_CLASS 285 * Mostly useful to simplify implementation of frameworks to adopt the new 286 * Network Service Type values for Signaling. 287 */ 288 #define SO_TC_NET_SERVICE_OFFSET 10000 289 #define SO_TC_NETSVC_SIG (SO_TC_NET_SERVICE_OFFSET + NET_SERVICE_TYPE_SIG) 290 291 #ifdef __APPLE__ 292 293 #ifdef KERNEL_PRIVATE 294 #define SONPX_MASK_VALID (SONPX_SETOPTSHUT) 295 #define IS_SO_TC_BACKGROUND(_tc_) ((_tc_) == SO_TC_BK || (_tc_) == SO_TC_BK_SYS) 296 #define IS_SO_TC_BACKGROUNDSYSTEM(_tc_) ((_tc_) == SO_TC_BK_SYS) 297 #endif /* KERNEL_PRIVATE */ 298 299 #endif 300 301 /* 302 * Address families. 303 */ 304 #define AF_AFP 36 /* Used by AFP */ 305 #define AF_MULTIPATH 39 306 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 307 308 /* 309 * Protocol families, same as address families for now. 310 */ 311 #define PF_AFP AF_AFP 312 #define PF_MULTIPATH AF_MULTIPATH 313 314 #ifdef KERNEL_PRIVATE 315 #define PF_BRIDGE ((uint32_t)0x62726467) /* 'brdg' */ 316 #define PF_NULL ((uint32_t)0x6e756c6c) /* 'null' */ 317 318 #define CTL_NET_NAMES { \ 319 { 0, 0 }, \ 320 { "local", CTLTYPE_NODE }, \ 321 { "inet", CTLTYPE_NODE }, \ 322 { "implink", CTLTYPE_NODE }, \ 323 { "pup", CTLTYPE_NODE }, \ 324 { "chaos", CTLTYPE_NODE }, \ 325 { "xerox_ns", CTLTYPE_NODE }, \ 326 { "iso", CTLTYPE_NODE }, \ 327 { "emca", CTLTYPE_NODE }, \ 328 { "datakit", CTLTYPE_NODE }, \ 329 { "ccitt", CTLTYPE_NODE }, \ 330 { "ibm_sna", CTLTYPE_NODE }, \ 331 { "decnet", CTLTYPE_NODE }, \ 332 { "dec_dli", CTLTYPE_NODE }, \ 333 { "lat", CTLTYPE_NODE }, \ 334 { "hylink", CTLTYPE_NODE }, \ 335 { "appletalk", CTLTYPE_NODE }, \ 336 { "route", CTLTYPE_NODE }, \ 337 { "link_layer", CTLTYPE_NODE }, \ 338 { "xtp", CTLTYPE_NODE }, \ 339 { "coip", CTLTYPE_NODE }, \ 340 { "cnt", CTLTYPE_NODE }, \ 341 { "rtip", CTLTYPE_NODE }, \ 342 { "ipx", CTLTYPE_NODE }, \ 343 { "sip", CTLTYPE_NODE }, \ 344 { "pip", CTLTYPE_NODE }, \ 345 { 0, 0 }, \ 346 { "ndrv", CTLTYPE_NODE }, \ 347 { "isdn", CTLTYPE_NODE }, \ 348 { "key", CTLTYPE_NODE }, \ 349 { "inet6", CTLTYPE_NODE }, \ 350 { "natm", CTLTYPE_NODE }, \ 351 { "sys", CTLTYPE_NODE }, \ 352 { "netbios", CTLTYPE_NODE }, \ 353 { "ppp", CTLTYPE_NODE }, \ 354 { "hdrcomplete", CTLTYPE_NODE }, \ 355 { "vsock", CTLTYPE_NODE }, \ 356 } 357 #endif /* KERNEL_PRIVATE */ 358 359 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 360 /* 361 * PF_ROUTE - Routing table 362 * 363 * Three additional levels are defined: 364 * Fourth: address family, 0 is wildcard 365 * Fifth: type of info, defined below 366 * Sixth: flag(s) to mask with for NET_RT_FLAGS 367 */ 368 #define NET_RT_DUMPX 8 /* private */ 369 #define NET_RT_DUMPX_FLAGS 9 /* private */ 370 #define NET_RT_STAT_64 11 /* private */ 371 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 372 373 /* These are supported values for SO_STATISTICS_EVENT */ 374 #define SO_STATISTICS_EVENT_ENTER_CELLFALLBACK (1 << 0) 375 #define SO_STATISTICS_EVENT_EXIT_CELLFALLBACK (1 << 1) 376 #define SO_STATISTICS_EVENT_RESERVED_1 (1 << 2) 377 #define SO_STATISTICS_EVENT_RESERVED_2 (1 << 3) 378 379 380 #ifdef KERNEL_PRIVATE 381 #define CTL_NET_RT_NAMES { \ 382 { 0, 0 }, \ 383 { "dump", CTLTYPE_STRUCT }, \ 384 { "flags", CTLTYPE_STRUCT }, \ 385 { "iflist", CTLTYPE_STRUCT }, \ 386 { "stat", CTLTYPE_STRUCT }, \ 387 { "trash", CTLTYPE_INT }, \ 388 { "iflist2", CTLTYPE_STRUCT }, \ 389 { "dump2", CTLTYPE_STRUCT }, \ 390 { "dumpx", CTLTYPE_STRUCT }, \ 391 { "dumpx_flags", CTLTYPE_STRUCT }, \ 392 } 393 394 #endif /* KERNEL_PRIVATE */ 395 396 /* 397 * Extended version for sendmsg_x() and recvmsg_x() calls 398 * 399 * For recvmsg_x(), the size of the data received is given by the field 400 * msg_datalen. 401 * 402 * For sendmsg_x(), the size of the data to send is given by the length of 403 * the iovec array -- like sendmsg(). The field msg_datalen is ignored. 404 */ 405 struct msghdr_x { 406 void *__sized_by(msg_namelen) msg_name; /* optional address */ 407 socklen_t msg_namelen; /* size of address */ 408 struct iovec *msg_iov; /* scatter/gather array */ 409 int msg_iovlen; /* # elements in msg_iov */ 410 void *__sized_by(msg_controllen) msg_control; /* ancillary data, see below */ 411 socklen_t msg_controllen; /* ancillary data buffer len */ 412 int msg_flags; /* flags on received message */ 413 size_t msg_datalen; /* byte length of buffer in msg_iov */ 414 }; 415 416 #ifdef XNU_KERNEL_PRIVATE 417 /* 418 * In-kernel representation of "struct msghdr" from 419 * userspace. Has enough precision for 32-bit or 420 * 64-bit clients, but does not need to be packed. 421 */ 422 423 struct user_msghdr { 424 user_addr_t msg_name; /* optional address */ 425 socklen_t msg_namelen; /* size of address */ 426 vm_address_t msg_iov; /* scatter/gather array */ 427 int msg_iovlen; /* # elements in msg_iov */ 428 user_addr_t msg_control; /* ancillary data, see below */ 429 socklen_t msg_controllen; /* ancillary data buffer len */ 430 int msg_flags; /* flags on received message */ 431 }; 432 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user_msghdr, user_msghdr); 433 434 /* 435 * LP64 user version of struct msghdr. 436 * WARNING - keep in sync with struct msghdr 437 */ 438 439 struct user64_msghdr { 440 user64_addr_t msg_name; /* optional address */ 441 socklen_t msg_namelen; /* size of address */ 442 user64_addr_t msg_iov; /* scatter/gather array */ 443 int msg_iovlen; /* # elements in msg_iov */ 444 user64_addr_t msg_control; /* ancillary data, see below */ 445 socklen_t msg_controllen; /* ancillary data buffer len */ 446 int msg_flags; /* flags on received message */ 447 }; 448 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user64_msghdr, user64_msghdr); 449 450 /* 451 * ILP32 user version of struct msghdr. 452 * WARNING - keep in sync with struct msghdr 453 */ 454 455 struct user32_msghdr { 456 user32_addr_t msg_name; /* optional address */ 457 socklen_t msg_namelen; /* size of address */ 458 user32_addr_t msg_iov; /* scatter/gather array */ 459 int msg_iovlen; /* # elements in msg_iov */ 460 user32_addr_t msg_control; /* ancillary data, see below */ 461 socklen_t msg_controllen; /* ancillary data buffer len */ 462 int msg_flags; /* flags on received message */ 463 }; 464 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user32_msghdr, user32_msghdr); 465 466 /* 467 * In-kernel representation of "struct msghdr_x" from 468 * userspace. Has enough precision for 32-bit or 469 * 64-bit clients, but does not need to be packed. 470 */ 471 472 struct user_msghdr_x { 473 user_addr_t msg_name; /* optional address */ 474 socklen_t msg_namelen; /* size of address */ 475 vm_address_t msg_iov; /* scatter/gather array */ 476 int msg_iovlen; /* # elements in msg_iov */ 477 user_addr_t msg_control; /* ancillary data, see below */ 478 socklen_t msg_controllen; /* ancillary data buffer len */ 479 int msg_flags; /* flags on received message */ 480 size_t msg_datalen; /* byte length of buffer in msg_iov */ 481 }; 482 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user_msghdr_x, user_msghdr_x); 483 484 485 /* 486 * LP64 user version of struct msghdr_x 487 * WARNING - keep in sync with struct msghdr_x 488 */ 489 490 struct user64_msghdr_x { 491 user64_addr_t msg_name; /* optional address */ 492 socklen_t msg_namelen; /* size of address */ 493 user64_addr_t msg_iov; /* scatter/gather array */ 494 int msg_iovlen; /* # elements in msg_iov */ 495 user64_addr_t msg_control; /* ancillary data, see below */ 496 socklen_t msg_controllen; /* ancillary data buffer len */ 497 int msg_flags; /* flags on received message */ 498 user64_size_t msg_datalen; /* byte length of buffer in msg_iov */ 499 }; 500 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user64_msghdr_x, user64_msghdr_x); 501 502 /* 503 * ILP32 user version of struct msghdr_x 504 * WARNING - keep in sync with struct msghdr_x 505 */ 506 507 struct user32_msghdr_x { 508 user32_addr_t msg_name; /* optional address */ 509 socklen_t msg_namelen; /* size of address */ 510 user32_addr_t msg_iov; /* scatter/gather array */ 511 int msg_iovlen; /* # elements in msg_iov */ 512 user32_addr_t msg_control; /* ancillary data, see below */ 513 socklen_t msg_controllen; /* ancillary data buffer len */ 514 int msg_flags; /* flags on received message */ 515 user32_size_t msg_datalen; /* byte length of buffer in msg_iov */ 516 }; 517 __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user32_msghdr_x, user32_msghdr_x); 518 519 /* 520 * In-kernel representation of "struct sa_endpoints" from 521 * userspace. Has enough precision for 32-bit or 522 * 64-bit clients, but does not need to be packed. 523 */ 524 525 struct user_sa_endpoints { 526 unsigned int sae_srcif; /* optional source interface */ 527 user_addr_t sae_srcaddr; /* optional source address */ 528 socklen_t sae_srcaddrlen; /* size of source address */ 529 user_addr_t sae_dstaddr; /* destination address */ 530 socklen_t sae_dstaddrlen; /* size of destination address */ 531 }; 532 533 /* 534 * LP64 user version of struct sa_endpoints 535 * WARNING - keep in sync with struct sa_endpoints 536 */ 537 538 struct user64_sa_endpoints { 539 unsigned int sae_srcif; /* optional source interface */ 540 user64_addr_t sae_srcaddr; /* optional source address */ 541 socklen_t sae_srcaddrlen; /* size of source address */ 542 user64_addr_t sae_dstaddr; /* destination address */ 543 socklen_t sae_dstaddrlen; /* size of destination address */ 544 }; 545 546 /* 547 * ILP32 user version of struct sa_endpoints 548 * WARNING - keep in sync with struct sa_endpoints 549 */ 550 551 struct user32_sa_endpoints { 552 unsigned int sae_srcif; /* optional source interface */ 553 user32_addr_t sae_srcaddr; /* optional source address */ 554 socklen_t sae_srcaddrlen; /* size of source address */ 555 user32_addr_t sae_dstaddr; /* destination address */ 556 socklen_t sae_dstaddrlen; /* size of destination address */ 557 }; 558 559 #endif /* XNU_KERNEL_PRIVATE */ 560 561 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 562 #ifdef __APPLE__ 563 #ifndef __APPLE_API_OBSOLETE 564 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */ 565 #endif 566 #endif 567 #ifdef KERNEL_PRIVATE 568 #define MSG_COMPAT 0x8000 /* deprecated */ 569 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */ 570 #define MSG_SKIPCFIL 0x40000 /* skip pass content filter */ 571 #endif 572 573 #define SCM_TIMESTAMP_CONTINUOUS 0x07 /* timestamp (uint64_t) */ 574 #define SCM_MPKL_SEND_INFO 0x08 /* send info for multi-layer packet logging (struct so_mpkl_send_info) */ 575 #define SCM_MPKL_RECV_INFO 0x09 /* receive info for multi-layer packet logging (struct so_mpkl_recv_info */ 576 #define SCM_TXTIME 0x10 /* Set expected transmit time in absolute-time nanoseconds */ 577 578 #ifdef KERNEL_PRIVATE 579 /* 580 * 4.3 compat sockaddr (deprecated) 581 */ 582 struct osockaddr { 583 __uint16_t sa_family; /* address family */ 584 char sa_data[14]; /* up to 14 bytes of direct address */ 585 }; 586 587 /* 588 * 4.3-compat message header (deprecated) 589 */ 590 struct omsghdr { 591 void *msg_name; /* optional address */ 592 socklen_t msg_namelen; /* size of address */ 593 struct iovec *msg_iov; /* scatter/gather array */ 594 int msg_iovlen; /* # elements in msg_iov */ 595 void *msg_accrights; /* access rights sent/rcvd */ 596 int msg_accrightslen; 597 }; 598 599 #define SA(s) ((struct sockaddr *)(void *)(s)) 600 #endif /* KERNEL_PRIVATE */ 601 602 603 /* 604 * Structure for SIOCGASSOCIDS 605 */ 606 struct so_aidreq { 607 __uint32_t sar_cnt; /* number of associations */ 608 sae_associd_t *sar_aidp; /* array of association IDs */ 609 }; 610 611 #ifdef BSD_KERNEL_PRIVATE 612 struct so_aidreq32 { 613 __uint32_t sar_cnt; 614 user32_addr_t sar_aidp; 615 }; 616 617 struct so_aidreq64 { 618 __uint32_t sar_cnt; 619 user64_addr_t sar_aidp __attribute__((aligned(8))); 620 }; 621 #endif /* BSD_KERNEL_PRIVATE */ 622 623 /* 624 * Structure for SIOCGCONNIDS 625 */ 626 struct so_cidreq { 627 sae_associd_t scr_aid; /* association ID */ 628 __uint32_t scr_cnt; /* number of connections */ 629 sae_connid_t *scr_cidp; /* array of connection IDs */ 630 }; 631 632 #ifdef BSD_KERNEL_PRIVATE 633 struct so_cidreq32 { 634 sae_associd_t scr_aid; 635 __uint32_t scr_cnt; 636 user32_addr_t scr_cidp; 637 }; 638 639 struct so_cidreq64 { 640 sae_associd_t scr_aid; 641 __uint32_t scr_cnt; 642 user64_addr_t scr_cidp __attribute__((aligned(8))); 643 }; 644 #endif /* BSD_KERNEL_PRIVATE */ 645 646 /* 647 * Structure for SIOCGCONNINFO 648 */ 649 struct so_cinforeq { 650 sae_connid_t scir_cid; /* connection ID */ 651 __uint32_t scir_flags; /* see flags below */ 652 __uint32_t scir_ifindex; /* (last) outbound interface */ 653 __int32_t scir_error; /* most recent error */ 654 struct sockaddr *scir_src; /* source address */ 655 socklen_t scir_src_len; /* source address len */ 656 struct sockaddr *scir_dst; /* destination address */ 657 socklen_t scir_dst_len; /* destination address len */ 658 __uint32_t scir_aux_type; /* aux data type (CIAUX) */ 659 void *scir_aux_data; /* aux data */ 660 __uint32_t scir_aux_len; /* aux data len */ 661 }; 662 663 #ifdef BSD_KERNEL_PRIVATE 664 struct so_cinforeq32 { 665 sae_connid_t scir_cid; 666 __uint32_t scir_flags; 667 __uint32_t scir_ifindex; 668 __int32_t scir_error; 669 user32_addr_t scir_src; 670 socklen_t scir_src_len; 671 user32_addr_t scir_dst; 672 socklen_t scir_dst_len; 673 __uint32_t scir_aux_type; 674 user32_addr_t scir_aux_data; 675 __uint32_t scir_aux_len; 676 }; 677 678 struct so_cinforeq64 { 679 sae_connid_t scir_cid; 680 __uint32_t scir_flags; 681 __uint32_t scir_ifindex; 682 __int32_t scir_error; 683 user64_addr_t scir_src __attribute__((aligned(8))); 684 socklen_t scir_src_len; 685 user64_addr_t scir_dst __attribute__((aligned(8))); 686 socklen_t scir_dst_len; 687 __uint32_t scir_aux_type; 688 user64_addr_t scir_aux_data __attribute__((aligned(8))); 689 __uint32_t scir_aux_len; 690 }; 691 692 #endif /* BSD_KERNEL_PRIVATE */ 693 694 /* valid connection info flags */ 695 #define CIF_CONNECTING 0x1 /* connection was attempted */ 696 #define CIF_CONNECTED 0x2 /* connection is established */ 697 #define CIF_DISCONNECTING 0x4 /* disconnection was attempted */ 698 #define CIF_DISCONNECTED 0x8 /* has been disconnected */ 699 #define CIF_BOUND_IF 0x10 /* bound to an interface */ 700 #define CIF_BOUND_IP 0x20 /* bound to a src address */ 701 #define CIF_BOUND_PORT 0x40 /* bound to a src port */ 702 #define CIF_PREFERRED 0x80 /* connection is primary/preferred */ 703 #define CIF_MP_CAPABLE 0x100 /* supports multipath protocol */ 704 #define CIF_MP_READY 0x200 /* multipath protocol confirmed */ 705 #define CIF_MP_DEGRADED 0x400 /* has lost its multipath capability */ 706 #define CIF_MP_ACTIVE 0x800 /* this is the active subflow */ 707 #define CIF_MP_V1 0x1000 /* MPTCP v1 is used */ 708 709 /* valid connection info auxiliary data types */ 710 #define CIAUX_TCP 0x1 /* TCP auxiliary data (conninfo_tcp_t) */ 711 #define CIAUX_MPTCP 0x2 /* MPTCP auxiliary data (conninfo_multipathtcp) */ 712 713 /* 714 * Structure for SIOC{S,G}CONNORDER 715 */ 716 struct so_cordreq { 717 sae_connid_t sco_cid; /* connection ID */ 718 __uint32_t sco_rank; /* rank (0 means unspecified) */ 719 }; 720 721 /* 722 * Common structure for KEV_NETPOLICY_SUBCLASS 723 */ 724 struct netpolicy_event_data { 725 __uint64_t eupid; /* effective unique PID */ 726 __uint64_t epid; /* effective PID */ 727 uuid_t euuid; /* effective UUID */ 728 }; 729 730 /* 731 * NETPOLICY_IFDENIED event structure 732 */ 733 struct kev_netpolicy_ifdenied { 734 struct netpolicy_event_data ev_data; 735 __uint32_t ev_if_functional_type; 736 }; 737 738 /* 739 * KEV_NETPOLICY_NETDENIED event structure 740 */ 741 struct kev_netpolicy_netdenied { 742 struct netpolicy_event_data ev_data; 743 __uint32_t ev_network_type; 744 }; 745 746 /* 747 * Network Service Type to DiffServ Code Point mapping 748 */ 749 struct netsvctype_dscp_map { 750 int netsvctype; 751 u_int8_t dscp; /* 6 bits diffserv code point */ 752 }; 753 754 /* 755 * Multi-layer packet logging require SO_MPK_LOG to be set 756 */ 757 struct so_mpkl_send_info { 758 uuid_t mpkl_uuid; 759 __uint8_t mpkl_proto; /* see net/multi_layer_pkt_log.h */ 760 }; 761 762 struct so_mpkl_recv_info { 763 __uint32_t mpkl_seq; 764 __uint8_t mpkl_proto; /* see net/multi_layer_pkt_log.h */ 765 }; 766 767 #ifndef KERNEL 768 __BEGIN_DECLS 769 770 extern int peeloff(int s, sae_associd_t); 771 extern int socket_delegate(int, int, int, pid_t); 772 773 /* 774 * recvmsg_x() is a system call similar to recvmsg(2) to receive 775 * several datagrams at once in the array of message headers "msgp". 776 * 777 * recvmsg_x() can be used only with protocols handlers that have been specially 778 * modified to support sending and receiving several datagrams at once. 779 * 780 * The size of the array "msgp" is given by the argument "cnt". 781 * 782 * The "flags" arguments supports only the value MSG_DONTWAIT. 783 * 784 * Each member of "msgp" array is of type "struct msghdr_x". 785 * 786 * The "msg_iov" and "msg_iovlen" are input parameters that describe where to 787 * store a datagram in a scatter gather locations of buffers -- see recvmsg(2). 788 * On output the field "msg_datalen" gives the length of the received datagram. 789 * 790 * The field "msg_flags" must be set to zero on input. On output, "msg_flags" 791 * may have MSG_TRUNC set to indicate the trailing portion of the datagram was 792 * discarded because the datagram was larger than the buffer supplied. 793 * recvmsg_x() returns as soon as a datagram is truncated. 794 * 795 * recvmsg_x() may return with less than "cnt" datagrams received based on 796 * the low water mark and the amount of data pending in the socket buffer. 797 * 798 * recvmsg_x() returns the number of datagrams that have been received, 799 * or -1 if an error occurred. 800 * 801 * NOTE: This a private system call, the API is subject to change. 802 */ 803 ssize_t recvmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags); 804 805 /* 806 * sendmsg_x() is a system call similar to send(2) to send 807 * several datagrams at once in the array of message headers "msgp". 808 * 809 * sendmsg_x() can be used only with protocols handlers that have been specially 810 * modified to support sending and receiving several datagrams at once. 811 * 812 * The size of the array "msgp" is given by the argument "cnt". 813 * 814 * The "flags" arguments supports only the value MSG_DONTWAIT. 815 * 816 * Each member of "msgp" array is of type "struct msghdr_x". 817 * 818 * The "msg_iov" and "msg_iovlen" are input parameters that specify the 819 * data to be sent in a scatter gather locations of buffers -- see sendmsg(2). 820 * 821 * sendmsg_x() fails with EMSGSIZE if the sum of the length of the datagrams 822 * is greater than the high water mark. 823 * 824 * Address and ancillary data are not supported so the following fields 825 * must be set to zero on input: 826 * "msg_name", "msg_namelen", "msg_control" and "msg_controllen". 827 * 828 * The field "msg_flags" and "msg_datalen" must be set to zero on input. 829 * 830 * sendmsg_x() returns the number of datagrams that have been sent, 831 * or -1 if an error occurred. 832 * 833 * NOTE: This a private system call, the API is subject to change. 834 */ 835 ssize_t sendmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags); 836 __END_DECLS 837 #endif /* !KERNEL */ 838 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 839 840 #endif /* !_SYS_SOCKET_PRIVATE_H_ */ 841