xref: /xnu-10063.141.1/bsd/sys/socket.h (revision d8b80295118ef25ac3a784134bcf95cd8e88109f)
1*d8b80295SApple OSS Distributions /*
2*d8b80295SApple OSS Distributions  * Copyright (c) 2000-2022 Apple Inc. All rights reserved.
3*d8b80295SApple OSS Distributions  *
4*d8b80295SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*d8b80295SApple OSS Distributions  *
6*d8b80295SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*d8b80295SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*d8b80295SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*d8b80295SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*d8b80295SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*d8b80295SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*d8b80295SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*d8b80295SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*d8b80295SApple OSS Distributions  *
15*d8b80295SApple OSS Distributions  * Please obtain a copy of the License at
16*d8b80295SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*d8b80295SApple OSS Distributions  *
18*d8b80295SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*d8b80295SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*d8b80295SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*d8b80295SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*d8b80295SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*d8b80295SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*d8b80295SApple OSS Distributions  * limitations under the License.
25*d8b80295SApple OSS Distributions  *
26*d8b80295SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*d8b80295SApple OSS Distributions  */
28*d8b80295SApple OSS Distributions /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29*d8b80295SApple OSS Distributions /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30*d8b80295SApple OSS Distributions /*
31*d8b80295SApple OSS Distributions  * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
32*d8b80295SApple OSS Distributions  *	The Regents of the University of California.  All rights reserved.
33*d8b80295SApple OSS Distributions  *
34*d8b80295SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
35*d8b80295SApple OSS Distributions  * modification, are permitted provided that the following conditions
36*d8b80295SApple OSS Distributions  * are met:
37*d8b80295SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
38*d8b80295SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
39*d8b80295SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
40*d8b80295SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
41*d8b80295SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
42*d8b80295SApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
43*d8b80295SApple OSS Distributions  *    must display the following acknowledgement:
44*d8b80295SApple OSS Distributions  *	This product includes software developed by the University of
45*d8b80295SApple OSS Distributions  *	California, Berkeley and its contributors.
46*d8b80295SApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
47*d8b80295SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
48*d8b80295SApple OSS Distributions  *    without specific prior written permission.
49*d8b80295SApple OSS Distributions  *
50*d8b80295SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51*d8b80295SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52*d8b80295SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53*d8b80295SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54*d8b80295SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55*d8b80295SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56*d8b80295SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57*d8b80295SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58*d8b80295SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59*d8b80295SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60*d8b80295SApple OSS Distributions  * SUCH DAMAGE.
61*d8b80295SApple OSS Distributions  *
62*d8b80295SApple OSS Distributions  *	@(#)socket.h	8.4 (Berkeley) 2/21/94
63*d8b80295SApple OSS Distributions  * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $
64*d8b80295SApple OSS Distributions  */
65*d8b80295SApple OSS Distributions /*
66*d8b80295SApple OSS Distributions  * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
67*d8b80295SApple OSS Distributions  * support for mandatory and extensible security protections.  This notice
68*d8b80295SApple OSS Distributions  * is included in support of clause 2.2 (b) of the Apple Public License,
69*d8b80295SApple OSS Distributions  * Version 2.0.
70*d8b80295SApple OSS Distributions  */
71*d8b80295SApple OSS Distributions 
72*d8b80295SApple OSS Distributions #ifndef _SYS_SOCKET_H_
73*d8b80295SApple OSS Distributions #define _SYS_SOCKET_H_
74*d8b80295SApple OSS Distributions 
75*d8b80295SApple OSS Distributions #include <sys/types.h>
76*d8b80295SApple OSS Distributions #include <sys/cdefs.h>
77*d8b80295SApple OSS Distributions #include <sys/constrained_ctypes.h>
78*d8b80295SApple OSS Distributions #include <machine/_param.h>
79*d8b80295SApple OSS Distributions #include <net/net_kev.h>
80*d8b80295SApple OSS Distributions 
81*d8b80295SApple OSS Distributions #ifdef PRIVATE
82*d8b80295SApple OSS Distributions #include <sys/param.h>
83*d8b80295SApple OSS Distributions #include <uuid/uuid.h>
84*d8b80295SApple OSS Distributions #endif /* PRIVATE */
85*d8b80295SApple OSS Distributions 
86*d8b80295SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
87*d8b80295SApple OSS Distributions #include <kern/assert.h>
88*d8b80295SApple OSS Distributions #include <kern/kalloc.h>
89*d8b80295SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
90*d8b80295SApple OSS Distributions 
91*d8b80295SApple OSS Distributions #ifndef KERNEL
92*d8b80295SApple OSS Distributions #include <Availability.h>
93*d8b80295SApple OSS Distributions #endif
94*d8b80295SApple OSS Distributions 
95*d8b80295SApple OSS Distributions /*
96*d8b80295SApple OSS Distributions  * Definitions related to sockets: types, address families, options.
97*d8b80295SApple OSS Distributions  */
98*d8b80295SApple OSS Distributions 
99*d8b80295SApple OSS Distributions /*
100*d8b80295SApple OSS Distributions  * Data types.
101*d8b80295SApple OSS Distributions  */
102*d8b80295SApple OSS Distributions 
103*d8b80295SApple OSS Distributions #include <sys/_types/_gid_t.h>
104*d8b80295SApple OSS Distributions #include <sys/_types/_off_t.h>
105*d8b80295SApple OSS Distributions #include <sys/_types/_pid_t.h>
106*d8b80295SApple OSS Distributions #include <sys/_types/_sa_family_t.h>
107*d8b80295SApple OSS Distributions #include <sys/_types/_socklen_t.h>
108*d8b80295SApple OSS Distributions 
109*d8b80295SApple OSS Distributions /* XXX Not explicitly defined by POSIX, but function return types are */
110*d8b80295SApple OSS Distributions #include <sys/_types/_size_t.h>
111*d8b80295SApple OSS Distributions 
112*d8b80295SApple OSS Distributions /* XXX Not explicitly defined by POSIX, but function return types are */
113*d8b80295SApple OSS Distributions #include <sys/_types/_ssize_t.h>
114*d8b80295SApple OSS Distributions 
115*d8b80295SApple OSS Distributions /*
116*d8b80295SApple OSS Distributions  * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
117*d8b80295SApple OSS Distributions  */
118*d8b80295SApple OSS Distributions #include <sys/_types/_iovec_t.h>
119*d8b80295SApple OSS Distributions 
120*d8b80295SApple OSS Distributions /*
121*d8b80295SApple OSS Distributions  * Types
122*d8b80295SApple OSS Distributions  */
123*d8b80295SApple OSS Distributions #define SOCK_STREAM     1               /* stream socket */
124*d8b80295SApple OSS Distributions #define SOCK_DGRAM      2               /* datagram socket */
125*d8b80295SApple OSS Distributions #define SOCK_RAW        3               /* raw-protocol interface */
126*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
127*d8b80295SApple OSS Distributions #define SOCK_RDM        4               /* reliably-delivered message */
128*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
129*d8b80295SApple OSS Distributions #define SOCK_SEQPACKET  5               /* sequenced packet stream */
130*d8b80295SApple OSS Distributions 
131*d8b80295SApple OSS Distributions /*
132*d8b80295SApple OSS Distributions  * Option flags per-socket.
133*d8b80295SApple OSS Distributions  */
134*d8b80295SApple OSS Distributions #define SO_DEBUG        0x0001          /* turn on debugging info recording */
135*d8b80295SApple OSS Distributions #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
136*d8b80295SApple OSS Distributions #define SO_REUSEADDR    0x0004          /* allow local address reuse */
137*d8b80295SApple OSS Distributions #define SO_KEEPALIVE    0x0008          /* keep connections alive */
138*d8b80295SApple OSS Distributions #define SO_DONTROUTE    0x0010          /* just use interface addresses */
139*d8b80295SApple OSS Distributions #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
140*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
141*d8b80295SApple OSS Distributions #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
142*d8b80295SApple OSS Distributions #define SO_LINGER       0x0080          /* linger on close if data present (in ticks) */
143*d8b80295SApple OSS Distributions #define SO_LINGER_SEC   0x1080          /* linger on close if data present (in seconds) */
144*d8b80295SApple OSS Distributions #else
145*d8b80295SApple OSS Distributions #define SO_LINGER       0x1080          /* linger on close if data present (in seconds) */
146*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
147*d8b80295SApple OSS Distributions #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
148*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
149*d8b80295SApple OSS Distributions #define SO_REUSEPORT    0x0200          /* allow local address & port reuse */
150*d8b80295SApple OSS Distributions #define SO_TIMESTAMP    0x0400          /* timestamp received dgram traffic */
151*d8b80295SApple OSS Distributions #define SO_TIMESTAMP_MONOTONIC  0x0800  /* Monotonically increasing timestamp on rcvd dgram */
152*d8b80295SApple OSS Distributions #ifndef __APPLE__
153*d8b80295SApple OSS Distributions #define SO_ACCEPTFILTER 0x1000          /* there is an accept filter */
154*d8b80295SApple OSS Distributions #else
155*d8b80295SApple OSS Distributions #define SO_DONTTRUNC    0x2000          /* APPLE: Retain unread data */
156*d8b80295SApple OSS Distributions                                         /*  (ATOMIC proto) */
157*d8b80295SApple OSS Distributions #define SO_WANTMORE     0x4000          /* APPLE: Give hint when more data ready */
158*d8b80295SApple OSS Distributions #define SO_WANTOOBFLAG  0x8000          /* APPLE: Want OOB in MSG_FLAG on receive */
159*d8b80295SApple OSS Distributions 
160*d8b80295SApple OSS Distributions #ifdef PRIVATE
161*d8b80295SApple OSS Distributions #define SO_NOWAKEFROMSLEEP      0x10000 /* Don't wake for traffic to this socket */
162*d8b80295SApple OSS Distributions #define SO_NOAPNFALLBK          0x20000 /* Don't attempt APN fallback for the socket */
163*d8b80295SApple OSS Distributions #define SO_TIMESTAMP_CONTINUOUS 0x40000 /* Continuous monotonic timestamp on rcvd dgram */
164*d8b80295SApple OSS Distributions #endif
165*d8b80295SApple OSS Distributions 
166*d8b80295SApple OSS Distributions #endif  /* (!__APPLE__) */
167*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
168*d8b80295SApple OSS Distributions 
169*d8b80295SApple OSS Distributions /*
170*d8b80295SApple OSS Distributions  * Additional options, not kept in so_options.
171*d8b80295SApple OSS Distributions  */
172*d8b80295SApple OSS Distributions #define SO_SNDBUF       0x1001          /* send buffer size */
173*d8b80295SApple OSS Distributions #define SO_RCVBUF       0x1002          /* receive buffer size */
174*d8b80295SApple OSS Distributions #define SO_SNDLOWAT     0x1003          /* send low-water mark */
175*d8b80295SApple OSS Distributions #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
176*d8b80295SApple OSS Distributions #define SO_SNDTIMEO     0x1005          /* send timeout */
177*d8b80295SApple OSS Distributions #define SO_RCVTIMEO     0x1006          /* receive timeout */
178*d8b80295SApple OSS Distributions #define SO_ERROR        0x1007          /* get error status and clear */
179*d8b80295SApple OSS Distributions #define SO_TYPE         0x1008          /* get socket type */
180*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
181*d8b80295SApple OSS Distributions #define SO_LABEL        0x1010          /* deprecated */
182*d8b80295SApple OSS Distributions #define SO_PEERLABEL    0x1011          /* deprecated */
183*d8b80295SApple OSS Distributions #ifdef __APPLE__
184*d8b80295SApple OSS Distributions #define SO_NREAD        0x1020          /* APPLE: get 1st-packet byte count */
185*d8b80295SApple OSS Distributions #define SO_NKE          0x1021          /* APPLE: Install socket-level NKE */
186*d8b80295SApple OSS Distributions #define SO_NOSIGPIPE    0x1022          /* APPLE: No SIGPIPE on EPIPE */
187*d8b80295SApple OSS Distributions #define SO_NOADDRERR    0x1023          /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
188*d8b80295SApple OSS Distributions #define SO_NWRITE       0x1024          /* APPLE: Get number of bytes currently in send socket buffer */
189*d8b80295SApple OSS Distributions #define SO_REUSESHAREUID        0x1025          /* APPLE: Allow reuse of port/socket by different userids */
190*d8b80295SApple OSS Distributions #ifdef __APPLE_API_PRIVATE
191*d8b80295SApple OSS Distributions #define SO_NOTIFYCONFLICT       0x1026  /* APPLE: send notification if there is a bind on a port which is already in use */
192*d8b80295SApple OSS Distributions #define SO_UPCALLCLOSEWAIT      0x1027  /* APPLE: block on close until an upcall returns */
193*d8b80295SApple OSS Distributions #endif
194*d8b80295SApple OSS Distributions #ifdef PRIVATE
195*d8b80295SApple OSS Distributions #define SO_RESTRICTIONS 0x1081          /* APPLE: deny flag set */
196*d8b80295SApple OSS Distributions #define  SO_RESTRICT_DENY_IN    0x1     /* deny inbound (trapdoor) */
197*d8b80295SApple OSS Distributions #define  SO_RESTRICT_DENY_OUT   0x2     /* deny outbound (trapdoor) */
198*d8b80295SApple OSS Distributions #define  SO_RESTRICT_DENY_CELLULAR 0x4  /* deny use of cellular (trapdoor) */
199*d8b80295SApple OSS Distributions #define  SO_RESTRICT_DENY_EXPENSIVE 0x8 /* deny use of expensive if (trapdoor) */
200*d8b80295SApple OSS Distributions #define  SO_RESTRICT_DENY_CONSTRAINED 0x10 /* deny use of expensive if (trapdoor) */
201*d8b80295SApple OSS Distributions #endif /* PRIVATE */
202*d8b80295SApple OSS Distributions #define SO_RANDOMPORT   0x1082  /* APPLE: request local port randomization */
203*d8b80295SApple OSS Distributions #define SO_NP_EXTENSIONS        0x1083  /* To turn off some POSIX behavior */
204*d8b80295SApple OSS Distributions #endif
205*d8b80295SApple OSS Distributions 
206*d8b80295SApple OSS Distributions #ifdef PRIVATE
207*d8b80295SApple OSS Distributions #define SO_EXECPATH     0x1085          /* Application Firewall Socket option */
208*d8b80295SApple OSS Distributions 
209*d8b80295SApple OSS Distributions /*
210*d8b80295SApple OSS Distributions  * Traffic service class definitions (lowest to highest):
211*d8b80295SApple OSS Distributions  *
212*d8b80295SApple OSS Distributions  * SO_TC_BK_SYS
213*d8b80295SApple OSS Distributions  *	"Background System-Initiated", high delay tolerant, high loss
214*d8b80295SApple OSS Distributions  *	tolerant, elastic flow, variable size & long-lived.  E.g: system-
215*d8b80295SApple OSS Distributions  *	initiated iCloud synching or Time Capsule backup, for which there
216*d8b80295SApple OSS Distributions  *	is no progress feedbacks.
217*d8b80295SApple OSS Distributions  *
218*d8b80295SApple OSS Distributions  * SO_TC_BK
219*d8b80295SApple OSS Distributions  *	"Background", user-initiated, high delay tolerant, high loss tolerant,
220*d8b80295SApple OSS Distributions  *	elastic flow, variable size.  E.g. user-initiated iCloud synching or
221*d8b80295SApple OSS Distributions  *	Time Capsule backup; or traffics of background applications, for which
222*d8b80295SApple OSS Distributions  *	there is some progress feedbacks.
223*d8b80295SApple OSS Distributions  *
224*d8b80295SApple OSS Distributions  * SO_TC_BE
225*d8b80295SApple OSS Distributions  *	"Best Effort", unclassified/standard.  This is the default service
226*d8b80295SApple OSS Distributions  *	class; pretty much a mix of everything.
227*d8b80295SApple OSS Distributions  *
228*d8b80295SApple OSS Distributions  * SO_TC_RD
229*d8b80295SApple OSS Distributions  *	"Responsive Data", a notch higher than "Best Effort", medium delay
230*d8b80295SApple OSS Distributions  *	tolerant, elastic & inelastic flow, bursty, long-lived.  E.g. email,
231*d8b80295SApple OSS Distributions  *	instant messaging, for which there is a sense of interactivity and
232*d8b80295SApple OSS Distributions  *	urgency (user waiting for output).
233*d8b80295SApple OSS Distributions  *
234*d8b80295SApple OSS Distributions  * SO_TC_OAM
235*d8b80295SApple OSS Distributions  *	"Operations, Administration, and Management", medium delay tolerant,
236*d8b80295SApple OSS Distributions  *	low-medium loss tolerant, elastic & inelastic flows, variable size.
237*d8b80295SApple OSS Distributions  *	E.g. VPN tunnels.
238*d8b80295SApple OSS Distributions  *
239*d8b80295SApple OSS Distributions  * SO_TC_AV
240*d8b80295SApple OSS Distributions  *	"Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
241*d8b80295SApple OSS Distributions  *	loss tolerant, elastic flow, constant packet interval, variable rate &
242*d8b80295SApple OSS Distributions  *	size.  E.g. AirPlay playback (both video and audio).
243*d8b80295SApple OSS Distributions  *
244*d8b80295SApple OSS Distributions  * SO_TC_RV
245*d8b80295SApple OSS Distributions  *	"Responsive Multimedia Audio/Video", low delay tolerant, low-medium
246*d8b80295SApple OSS Distributions  *	loss tolerant, elastic flow, variable packet interval, rate and size.
247*d8b80295SApple OSS Distributions  *	E.g. AirPlay mirroring, screen sharing.
248*d8b80295SApple OSS Distributions  *
249*d8b80295SApple OSS Distributions  * SO_TC_VI
250*d8b80295SApple OSS Distributions  *	"Interactive Video", low delay tolerant, low-medium loss tolerant,
251*d8b80295SApple OSS Distributions  *	elastic flow, constant packet interval, variable rate & size.  E.g.
252*d8b80295SApple OSS Distributions  *	FaceTime video.
253*d8b80295SApple OSS Distributions  *
254*d8b80295SApple OSS Distributions  * SO_TC_VO
255*d8b80295SApple OSS Distributions  *	"Interactive Voice", low delay tolerant, low loss tolerant, inelastic
256*d8b80295SApple OSS Distributions  *	flow, constant packet rate, somewhat fixed size.  E.g. VoIP including
257*d8b80295SApple OSS Distributions  *	FaceTime audio.
258*d8b80295SApple OSS Distributions  *
259*d8b80295SApple OSS Distributions  * SO_TC_CTL
260*d8b80295SApple OSS Distributions  *	"Network Control", low delay tolerant, low loss tolerant, inelastic
261*d8b80295SApple OSS Distributions  *	flow, rate is bursty but short, variable size.  E.g. DNS queries;
262*d8b80295SApple OSS Distributions  *	certain types of locally-originated ICMP, ICMPv6; IGMP/MLD join/leave,
263*d8b80295SApple OSS Distributions  *	ARP.
264*d8b80295SApple OSS Distributions  */
265*d8b80295SApple OSS Distributions #define SO_TRAFFIC_CLASS        0x1086  /* Traffic service class (int) */
266*d8b80295SApple OSS Distributions #define SO_TC_BK_SYS    100             /* lowest class */
267*d8b80295SApple OSS Distributions #define SO_TC_BK        200
268*d8b80295SApple OSS Distributions #define SO_TC_BE        0
269*d8b80295SApple OSS Distributions #define SO_TC_RD        300
270*d8b80295SApple OSS Distributions #define SO_TC_OAM       400
271*d8b80295SApple OSS Distributions #define SO_TC_AV        500
272*d8b80295SApple OSS Distributions #define SO_TC_RV        600
273*d8b80295SApple OSS Distributions #define SO_TC_VI        700
274*d8b80295SApple OSS Distributions #define SO_TC_VO        800
275*d8b80295SApple OSS Distributions #define SO_TC_CTL       900             /* highest class */
276*d8b80295SApple OSS Distributions #define SO_TC_MAX       10              /* Total # of traffic classes */
277*d8b80295SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
278*d8b80295SApple OSS Distributions #define _SO_TC_BK       1               /* deprecated */
279*d8b80295SApple OSS Distributions #define _SO_TC_VI       2               /* deprecated */
280*d8b80295SApple OSS Distributions #define _SO_TC_VO       3               /* deprecated */
281*d8b80295SApple OSS Distributions #define _SO_TC_MAX      4               /* deprecated */
282*d8b80295SApple OSS Distributions 
283*d8b80295SApple OSS Distributions #define SO_VALID_TC(c)                                                  \
284*d8b80295SApple OSS Distributions 	(c == SO_TC_BK_SYS || c == SO_TC_BK || c == SO_TC_BE ||         \
285*d8b80295SApple OSS Distributions 	c == SO_TC_RD || c == SO_TC_OAM || c == SO_TC_AV ||             \
286*d8b80295SApple OSS Distributions 	c == SO_TC_RV || c == SO_TC_VI || c == SO_TC_VO ||              \
287*d8b80295SApple OSS Distributions 	c == SO_TC_CTL || c == SO_TC_NETSVC_SIG)
288*d8b80295SApple OSS Distributions 
289*d8b80295SApple OSS Distributions #define SO_TC_UNSPEC    ((int)-1)               /* Traffic class not specified */
290*d8b80295SApple OSS Distributions 
291*d8b80295SApple OSS Distributions #define SO_TC_SIG       SO_TC_VI                /* to be removed XXX */
292*d8b80295SApple OSS Distributions 
293*d8b80295SApple OSS Distributions #define SOTCIX_BK_SYS   0
294*d8b80295SApple OSS Distributions #define SOTCIX_BK       1
295*d8b80295SApple OSS Distributions #define SOTCIX_BE       2
296*d8b80295SApple OSS Distributions #define SOTCIX_RD       3
297*d8b80295SApple OSS Distributions #define SOTCIX_OAM      4
298*d8b80295SApple OSS Distributions #define SOTCIX_AV       5
299*d8b80295SApple OSS Distributions #define SOTCIX_RV       6
300*d8b80295SApple OSS Distributions #define SOTCIX_VI       7
301*d8b80295SApple OSS Distributions #define SOTCIX_VO       8
302*d8b80295SApple OSS Distributions #define SOTCIX_CTL      9
303*d8b80295SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
304*d8b80295SApple OSS Distributions 
305*d8b80295SApple OSS Distributions /* Background socket configuration flags  */
306*d8b80295SApple OSS Distributions #define TRAFFIC_MGT_SO_BACKGROUND       0x0001  /* background socket */
307*d8b80295SApple OSS Distributions #define TRAFFIC_MGT_TCP_RECVBG          0x0002  /* Only TCP sockets, receiver throttling */
308*d8b80295SApple OSS Distributions 
309*d8b80295SApple OSS Distributions #define SO_RECV_TRAFFIC_CLASS   0x1087          /* Receive traffic class (bool) */
310*d8b80295SApple OSS Distributions #define SO_TRAFFIC_CLASS_DBG    0x1088          /* Debug traffic class (struct so_tcdbg) */
311*d8b80295SApple OSS Distributions #define SO_OPTION_UNUSED_0      0x1089          /* Traffic class statistics */
312*d8b80295SApple OSS Distributions #define SO_PRIVILEGED_TRAFFIC_CLASS 0x1090      /* Privileged traffic class (bool) */
313*d8b80295SApple OSS Distributions #define SO_DEFUNCTIT    0x1091          /* Defunct a socket (only in internal builds) */
314*d8b80295SApple OSS Distributions #define SO_DEFUNCTOK    0x1100          /* can be defunct'd */
315*d8b80295SApple OSS Distributions #define SO_ISDEFUNCT    0x1101          /* get defunct status */
316*d8b80295SApple OSS Distributions 
317*d8b80295SApple OSS Distributions #define SO_OPPORTUNISTIC        0x1102  /* deprecated; use SO_TRAFFIC_CLASS */
318*d8b80295SApple OSS Distributions 
319*d8b80295SApple OSS Distributions /*
320*d8b80295SApple OSS Distributions  * SO_FLUSH flushes any unsent data generated by a given socket.  It takes
321*d8b80295SApple OSS Distributions  * an integer parameter, which can be any of the SO_TC traffic class values,
322*d8b80295SApple OSS Distributions  * or the special SO_TC_ALL value.
323*d8b80295SApple OSS Distributions  */
324*d8b80295SApple OSS Distributions #define SO_FLUSH        0x1103          /* flush unsent data (int) */
325*d8b80295SApple OSS Distributions #define  SO_TC_ALL      (-1)
326*d8b80295SApple OSS Distributions 
327*d8b80295SApple OSS Distributions #define SO_RECV_ANYIF   0x1104          /* unrestricted inbound processing */
328*d8b80295SApple OSS Distributions #define SO_TRAFFIC_MGT_BACKGROUND       0x1105  /* Background traffic management */
329*d8b80295SApple OSS Distributions 
330*d8b80295SApple OSS Distributions #define SO_FLOW_DIVERT_TOKEN    0x1106  /* flow divert token */
331*d8b80295SApple OSS Distributions 
332*d8b80295SApple OSS Distributions #define SO_DELEGATED            0x1107  /* set socket as delegate (pid_t) */
333*d8b80295SApple OSS Distributions #define SO_DELEGATED_UUID       0x1108  /* set socket as delegate (uuid_t) */
334*d8b80295SApple OSS Distributions #define SO_NECP_ATTRIBUTES      0x1109  /* NECP socket attributes (domain, account, etc.) */
335*d8b80295SApple OSS Distributions #define SO_CFIL_SOCK_ID         0x1110  /* get content filter socket ID (cfil_sock_id_t) */
336*d8b80295SApple OSS Distributions #define SO_NECP_CLIENTUUID      0x1111  /* NECP Client uuid */
337*d8b80295SApple OSS Distributions #endif /* PRIVATE */
338*d8b80295SApple OSS Distributions #define SO_NUMRCVPKT            0x1112  /* number of datagrams in receive socket buffer */
339*d8b80295SApple OSS Distributions #ifdef PRIVATE
340*d8b80295SApple OSS Distributions #define SO_AWDL_UNRESTRICTED    0x1113  /* try to use AWDL in restricted mode */
341*d8b80295SApple OSS Distributions #define SO_EXTENDED_BK_IDLE     0x1114  /* extended time to keep socket idle after app is suspended (int) */
342*d8b80295SApple OSS Distributions #define SO_MARK_CELLFALLBACK    0x1115  /* Mark as initiated by cell fallback */
343*d8b80295SApple OSS Distributions #endif /* PRIVATE */
344*d8b80295SApple OSS Distributions #define SO_NET_SERVICE_TYPE     0x1116  /* Network service type */
345*d8b80295SApple OSS Distributions 
346*d8b80295SApple OSS Distributions #ifdef PRIVATE
347*d8b80295SApple OSS Distributions #define SO_QOSMARKING_POLICY_OVERRIDE   0x1117  /* int */
348*d8b80295SApple OSS Distributions #define SO_INTCOPROC_ALLOW              0x1118  /* Try to use internal co-processor interfaces. */
349*d8b80295SApple OSS Distributions #endif /* PRIVATE */
350*d8b80295SApple OSS Distributions 
351*d8b80295SApple OSS Distributions #define SO_NETSVC_MARKING_LEVEL    0x1119  /* Get QoS marking in effect for socket */
352*d8b80295SApple OSS Distributions 
353*d8b80295SApple OSS Distributions #ifdef PRIVATE
354*d8b80295SApple OSS Distributions #define SO_NECP_LISTENUUID         0x1120  /* NECP client UUID for listener */
355*d8b80295SApple OSS Distributions #define SO_MPKL_SEND_INFO          0x1122  /* (struct so_mpkl_send_info) */
356*d8b80295SApple OSS Distributions #define SO_STATISTICS_EVENT        0x1123  /* int64 argument, an event in statistics collection */
357*d8b80295SApple OSS Distributions #define SO_WANT_KEV_SOCKET_CLOSED  0x1124  /* want delivery of KEV_SOCKET_CLOSED (int) */
358*d8b80295SApple OSS Distributions #define SO_MARK_KNOWN_TRACKER      0x1125  /* Mark as a connection to a known tracker */
359*d8b80295SApple OSS Distributions #define SO_MARK_KNOWN_TRACKER_NON_APP_INITIATED 0x1126  /* Mark tracker connection to be non-app initiated */
360*d8b80295SApple OSS Distributions #define SO_MARK_WAKE_PKT           0x1127  /* Mark next packet as a wake packet, one shot (int) */
361*d8b80295SApple OSS Distributions #define SO_RECV_WAKE_PKT           0x1128  /* Receive wake packet indication as ancillary data (int) */
362*d8b80295SApple OSS Distributions #define SO_MARK_APPROVED_APP_DOMAIN 0x1129 /* Mark connection as being for an approved associated app domain */
363*d8b80295SApple OSS Distributions #define SO_FALLBACK_MODE           0x1130  /* Indicates the mode of fallback used */
364*d8b80295SApple OSS Distributions #endif /* PRIVATE */
365*d8b80295SApple OSS Distributions 
366*d8b80295SApple OSS Distributions #define SO_RESOLVER_SIGNATURE      0x1131  /* A signed data blob from the system resolver */
367*d8b80295SApple OSS Distributions #ifdef PRIVATE
368*d8b80295SApple OSS Distributions #define SO_MARK_CELLFALLBACK_UUID  0x1132  /* Mark as initiated by cell fallback using UUID of the connection */
369*d8b80295SApple OSS Distributions #define SO_APPLICATION_ID          0x1133  /* ID of attributing app - so_application_id_t */
370*d8b80295SApple OSS Distributions 
371*d8b80295SApple OSS Distributions struct so_mark_cellfallback_uuid_args {
372*d8b80295SApple OSS Distributions 	uuid_t flow_uuid;
373*d8b80295SApple OSS Distributions 	int flow_cellfallback;
374*d8b80295SApple OSS Distributions };
375*d8b80295SApple OSS Distributions 
376*d8b80295SApple OSS Distributions typedef struct {
377*d8b80295SApple OSS Distributions 	uid_t               uid;
378*d8b80295SApple OSS Distributions 	uuid_t              effective_uuid;
379*d8b80295SApple OSS Distributions 	uid_t               persona_id;
380*d8b80295SApple OSS Distributions } so_application_id_t;
381*d8b80295SApple OSS Distributions 
382*d8b80295SApple OSS Distributions #endif
383*d8b80295SApple OSS Distributions 
384*d8b80295SApple OSS Distributions #ifdef PRIVATE
385*d8b80295SApple OSS Distributions /* Note gap for SO_BINDTODEVICE at 0x1134 */
386*d8b80295SApple OSS Distributions 
387*d8b80295SApple OSS Distributions #define SO_MARK_DOMAIN_INFO_SILENT 0x1135  /* Domain information should be silently withheld */
388*d8b80295SApple OSS Distributions #endif
389*d8b80295SApple OSS Distributions 
390*d8b80295SApple OSS Distributions /* When adding new socket-options, you need to make sure MPTCP supports these as well! */
391*d8b80295SApple OSS Distributions 
392*d8b80295SApple OSS Distributions /*
393*d8b80295SApple OSS Distributions  * Network Service Type for option SO_NET_SERVICE_TYPE
394*d8b80295SApple OSS Distributions  *
395*d8b80295SApple OSS Distributions  * The vast majority of sockets should use Best Effort that is the default
396*d8b80295SApple OSS Distributions  * Network Service Type. Other Network Service Types have to be used only if
397*d8b80295SApple OSS Distributions  * the traffic actually matches the description of the Network Service Type.
398*d8b80295SApple OSS Distributions  *
399*d8b80295SApple OSS Distributions  * Network Service Types do not represent priorities but rather describe
400*d8b80295SApple OSS Distributions  * different categories of delay, jitter and loss parameters.
401*d8b80295SApple OSS Distributions  * Those parameters may influence protocols from layer 4 protocols like TCP
402*d8b80295SApple OSS Distributions  * to layer 2 protocols like Wi-Fi. The Network Service Type can determine
403*d8b80295SApple OSS Distributions  * how the traffic is queued and scheduled by the host networking stack and
404*d8b80295SApple OSS Distributions  * by other entities on the network like switches and routers. For example
405*d8b80295SApple OSS Distributions  * for Wi-Fi, the Network Service Type can select the marking of the
406*d8b80295SApple OSS Distributions  * layer 2 packet with the appropriate WMM Access Category.
407*d8b80295SApple OSS Distributions  *
408*d8b80295SApple OSS Distributions  * There is no point in attempting to game the system and use
409*d8b80295SApple OSS Distributions  * a Network Service Type that does not correspond to the actual
410*d8b80295SApple OSS Distributions  * traffic characteristic but one that seems to have a higher precedence.
411*d8b80295SApple OSS Distributions  * The reason is that for service classes that have lower tolerance
412*d8b80295SApple OSS Distributions  * for delay and jitter, the queues size is lower than for service
413*d8b80295SApple OSS Distributions  * classes that are more tolerant to delay and jitter.
414*d8b80295SApple OSS Distributions  *
415*d8b80295SApple OSS Distributions  * For example using a voice service type for bulk data transfer will lead
416*d8b80295SApple OSS Distributions  * to disastrous results as soon as congestion happens because the voice
417*d8b80295SApple OSS Distributions  * queue overflows and packets get dropped. This is not only bad for the bulk
418*d8b80295SApple OSS Distributions  * data transfer but it is also bad for VoIP apps that legitimately are using
419*d8b80295SApple OSS Distributions  * the voice  service type.
420*d8b80295SApple OSS Distributions  *
421*d8b80295SApple OSS Distributions  * The characteristics of the Network Service Types are based on the service
422*d8b80295SApple OSS Distributions  * classes defined in RFC 4594 "Configuration Guidelines for DiffServ Service
423*d8b80295SApple OSS Distributions  * Classes"
424*d8b80295SApple OSS Distributions  *
425*d8b80295SApple OSS Distributions  * When system detects the outgoing interface belongs to a DiffServ domain
426*d8b80295SApple OSS Distributions  * that follows the recommendation of the IETF draft "Guidelines for DiffServ to
427*d8b80295SApple OSS Distributions  * IEEE 802.11 Mapping", the packet will marked at layer 3 with a DSCP value
428*d8b80295SApple OSS Distributions  * that corresponds to Network Service Type.
429*d8b80295SApple OSS Distributions  *
430*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_BE
431*d8b80295SApple OSS Distributions  *	"Best Effort", unclassified/standard.  This is the default service
432*d8b80295SApple OSS Distributions  *	class and cover the majority of the traffic.
433*d8b80295SApple OSS Distributions  *
434*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_BK
435*d8b80295SApple OSS Distributions  *	"Background", high delay tolerant, loss tolerant. elastic flow,
436*d8b80295SApple OSS Distributions  *	variable size & long-lived. E.g: non-interactive network bulk transfer
437*d8b80295SApple OSS Distributions  *	like synching or backup.
438*d8b80295SApple OSS Distributions  *
439*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_RD
440*d8b80295SApple OSS Distributions  *	"Responsive Data", a notch higher than "Best Effort", medium delay
441*d8b80295SApple OSS Distributions  *	tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
442*d8b80295SApple OSS Distributions  *	instant messaging, for which there is a sense of interactivity and
443*d8b80295SApple OSS Distributions  *	urgency (user waiting for output).
444*d8b80295SApple OSS Distributions  *
445*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_OAM
446*d8b80295SApple OSS Distributions  *	"Operations, Administration, and Management", medium delay tolerant,
447*d8b80295SApple OSS Distributions  *	low-medium loss tolerant, elastic & inelastic flows, variable size.
448*d8b80295SApple OSS Distributions  *	E.g. VPN tunnels.
449*d8b80295SApple OSS Distributions  *
450*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_AV
451*d8b80295SApple OSS Distributions  *	"Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
452*d8b80295SApple OSS Distributions  *	loss tolerant, elastic flow, constant packet interval, variable rate
453*d8b80295SApple OSS Distributions  *	and size. E.g. video and audio playback with buffering.
454*d8b80295SApple OSS Distributions  *
455*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_RV
456*d8b80295SApple OSS Distributions  *	"Responsive Multimedia Audio/Video", low delay tolerant, low-medium
457*d8b80295SApple OSS Distributions  *	loss tolerant, elastic flow, variable packet interval, rate and size.
458*d8b80295SApple OSS Distributions  *	E.g. screen sharing.
459*d8b80295SApple OSS Distributions  *
460*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_VI
461*d8b80295SApple OSS Distributions  *	"Interactive Video", low delay tolerant, low-medium loss tolerant,
462*d8b80295SApple OSS Distributions  *	elastic flow, constant packet interval, variable rate & size. E.g.
463*d8b80295SApple OSS Distributions  *	video telephony.
464*d8b80295SApple OSS Distributions  *
465*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_SIG
466*d8b80295SApple OSS Distributions  *	"Signaling", low delay tolerant, low loss tolerant, inelastic flow,
467*d8b80295SApple OSS Distributions  *	jitter tolerant, rate is bursty but short, variable size. E.g. SIP.
468*d8b80295SApple OSS Distributions  *
469*d8b80295SApple OSS Distributions  * NET_SERVICE_TYPE_VO
470*d8b80295SApple OSS Distributions  *	"Interactive Voice", very low delay tolerant, very low loss tolerant,
471*d8b80295SApple OSS Distributions  *	inelastic flow, constant packet rate, somewhat fixed size.
472*d8b80295SApple OSS Distributions  *	E.g. VoIP.
473*d8b80295SApple OSS Distributions  */
474*d8b80295SApple OSS Distributions 
475*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_BE     0 /* Best effort */
476*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_BK     1 /* Background system initiated */
477*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_SIG    2 /* Signaling */
478*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_VI     3 /* Interactive Video */
479*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_VO     4 /* Interactive Voice */
480*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_RV     5 /* Responsive Multimedia Audio/Video */
481*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_AV     6 /* Multimedia Audio/Video Streaming */
482*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_OAM    7 /* Operations, Administration, and Management */
483*d8b80295SApple OSS Distributions #define NET_SERVICE_TYPE_RD     8 /* Responsive Data */
484*d8b80295SApple OSS Distributions 
485*d8b80295SApple OSS Distributions #if PRIVATE
486*d8b80295SApple OSS Distributions #define _NET_SERVICE_TYPE_COUNT 9
487*d8b80295SApple OSS Distributions #define _NET_SERVICE_TYPE_UNSPEC        ((int)-1)
488*d8b80295SApple OSS Distributions 
489*d8b80295SApple OSS Distributions #define IS_VALID_NET_SERVICE_TYPE(c)                            \
490*d8b80295SApple OSS Distributions 	(c >= NET_SERVICE_TYPE_BE && c <= NET_SERVICE_TYPE_RD)
491*d8b80295SApple OSS Distributions 
492*d8b80295SApple OSS Distributions extern const int sotc_by_netservicetype[_NET_SERVICE_TYPE_COUNT];
493*d8b80295SApple OSS Distributions 
494*d8b80295SApple OSS Distributions /*
495*d8b80295SApple OSS Distributions  * Facility to pass Network Service Type values using SO_TRAFFIC_CLASS
496*d8b80295SApple OSS Distributions  * Mostly useful to simplify implementation of frameworks to adopt the new
497*d8b80295SApple OSS Distributions  * Network Service Type values for Signaling.
498*d8b80295SApple OSS Distributions  */
499*d8b80295SApple OSS Distributions #define SO_TC_NET_SERVICE_OFFSET        10000
500*d8b80295SApple OSS Distributions #define SO_TC_NETSVC_SIG        (SO_TC_NET_SERVICE_OFFSET + NET_SERVICE_TYPE_SIG)
501*d8b80295SApple OSS Distributions #endif /* PRIVATE */
502*d8b80295SApple OSS Distributions 
503*d8b80295SApple OSS Distributions /* These are supported values for SO_NETSVC_MARKING_LEVEL */
504*d8b80295SApple OSS Distributions #define NETSVC_MRKNG_UNKNOWN            0       /* The outgoing network interface is not known */
505*d8b80295SApple OSS Distributions #define NETSVC_MRKNG_LVL_L2             1       /* Default marking at layer 2 (for example Wi-Fi WMM) */
506*d8b80295SApple OSS Distributions #define NETSVC_MRKNG_LVL_L3L2_ALL       2       /* Layer 3 DSCP marking and layer 2 marking for all Network Service Types */
507*d8b80295SApple OSS Distributions #define NETSVC_MRKNG_LVL_L3L2_BK        3       /* The system policy limits layer 3 DSCP marking and layer 2 marking
508*d8b80295SApple OSS Distributions 	                                         * to background Network Service Types */
509*d8b80295SApple OSS Distributions 
510*d8b80295SApple OSS Distributions 
511*d8b80295SApple OSS Distributions typedef __uint32_t sae_associd_t;
512*d8b80295SApple OSS Distributions #define SAE_ASSOCID_ANY 0
513*d8b80295SApple OSS Distributions #define SAE_ASSOCID_ALL ((sae_associd_t)(-1ULL))
514*d8b80295SApple OSS Distributions 
515*d8b80295SApple OSS Distributions typedef __uint32_t sae_connid_t;
516*d8b80295SApple OSS Distributions #define SAE_CONNID_ANY  0
517*d8b80295SApple OSS Distributions #define SAE_CONNID_ALL  ((sae_connid_t)(-1ULL))
518*d8b80295SApple OSS Distributions 
519*d8b80295SApple OSS Distributions /* connectx() flag parameters */
520*d8b80295SApple OSS Distributions #define CONNECT_RESUME_ON_READ_WRITE    0x1 /* resume connect() on read/write */
521*d8b80295SApple OSS Distributions #define CONNECT_DATA_IDEMPOTENT         0x2 /* data is idempotent */
522*d8b80295SApple OSS Distributions #define CONNECT_DATA_AUTHENTICATED      0x4 /* data includes security that replaces the TFO-cookie */
523*d8b80295SApple OSS Distributions 
524*d8b80295SApple OSS Distributions /* sockaddr endpoints */
525*d8b80295SApple OSS Distributions typedef struct sa_endpoints {
526*d8b80295SApple OSS Distributions 	unsigned int            sae_srcif;      /* optional source interface */
527*d8b80295SApple OSS Distributions 	const struct sockaddr   *sae_srcaddr;   /* optional source address */
528*d8b80295SApple OSS Distributions 	socklen_t               sae_srcaddrlen; /* size of source address */
529*d8b80295SApple OSS Distributions 	const struct sockaddr   *sae_dstaddr;   /* destination address */
530*d8b80295SApple OSS Distributions 	socklen_t               sae_dstaddrlen; /* size of destination address */
531*d8b80295SApple OSS Distributions } sa_endpoints_t;
532*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
533*d8b80295SApple OSS Distributions 
534*d8b80295SApple OSS Distributions /*
535*d8b80295SApple OSS Distributions  * Structure used for manipulating linger option.
536*d8b80295SApple OSS Distributions  */
537*d8b80295SApple OSS Distributions struct  linger {
538*d8b80295SApple OSS Distributions 	int     l_onoff;                /* option on/off */
539*d8b80295SApple OSS Distributions 	int     l_linger;               /* linger time */
540*d8b80295SApple OSS Distributions };
541*d8b80295SApple OSS Distributions 
542*d8b80295SApple OSS Distributions #ifndef __APPLE__
543*d8b80295SApple OSS Distributions struct  accept_filter_arg {
544*d8b80295SApple OSS Distributions 	char    af_name[16];
545*d8b80295SApple OSS Distributions 	char    af_arg[256 - 16];
546*d8b80295SApple OSS Distributions };
547*d8b80295SApple OSS Distributions #endif
548*d8b80295SApple OSS Distributions 
549*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
550*d8b80295SApple OSS Distributions #ifdef __APPLE__
551*d8b80295SApple OSS Distributions 
552*d8b80295SApple OSS Distributions /*
553*d8b80295SApple OSS Distributions  * Structure to control non-portable Sockets extension to POSIX
554*d8b80295SApple OSS Distributions  */
555*d8b80295SApple OSS Distributions struct so_np_extensions {
556*d8b80295SApple OSS Distributions 	u_int32_t       npx_flags;
557*d8b80295SApple OSS Distributions 	u_int32_t       npx_mask;
558*d8b80295SApple OSS Distributions };
559*d8b80295SApple OSS Distributions 
560*d8b80295SApple OSS Distributions #define SONPX_SETOPTSHUT        0x000000001     /* flag for allowing setsockopt after shutdown */
561*d8b80295SApple OSS Distributions 
562*d8b80295SApple OSS Distributions 
563*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
564*d8b80295SApple OSS Distributions #define SONPX_MASK_VALID                (SONPX_SETOPTSHUT)
565*d8b80295SApple OSS Distributions #define IS_SO_TC_BACKGROUND(_tc_) ((_tc_) == SO_TC_BK || (_tc_) == SO_TC_BK_SYS)
566*d8b80295SApple OSS Distributions #define IS_SO_TC_BACKGROUNDSYSTEM(_tc_) ((_tc_) == SO_TC_BK_SYS)
567*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
568*d8b80295SApple OSS Distributions 
569*d8b80295SApple OSS Distributions #endif
570*d8b80295SApple OSS Distributions #endif
571*d8b80295SApple OSS Distributions 
572*d8b80295SApple OSS Distributions /*
573*d8b80295SApple OSS Distributions  * Level number for (get/set)sockopt() to apply to socket itself.
574*d8b80295SApple OSS Distributions  */
575*d8b80295SApple OSS Distributions #define SOL_SOCKET      0xffff          /* options for socket level */
576*d8b80295SApple OSS Distributions 
577*d8b80295SApple OSS Distributions 
578*d8b80295SApple OSS Distributions /*
579*d8b80295SApple OSS Distributions  * Address families.
580*d8b80295SApple OSS Distributions  */
581*d8b80295SApple OSS Distributions #define AF_UNSPEC       0               /* unspecified */
582*d8b80295SApple OSS Distributions #define AF_UNIX         1               /* local to host (pipes) */
583*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
584*d8b80295SApple OSS Distributions #define AF_LOCAL        AF_UNIX         /* backward compatibility */
585*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
586*d8b80295SApple OSS Distributions #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
587*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
588*d8b80295SApple OSS Distributions #define AF_IMPLINK      3               /* arpanet imp addresses */
589*d8b80295SApple OSS Distributions #define AF_PUP          4               /* pup protocols: e.g. BSP */
590*d8b80295SApple OSS Distributions #define AF_CHAOS        5               /* mit CHAOS protocols */
591*d8b80295SApple OSS Distributions #define AF_NS           6               /* XEROX NS protocols */
592*d8b80295SApple OSS Distributions #define AF_ISO          7               /* ISO protocols */
593*d8b80295SApple OSS Distributions #define AF_OSI          AF_ISO
594*d8b80295SApple OSS Distributions #define AF_ECMA         8               /* European computer manufacturers */
595*d8b80295SApple OSS Distributions #define AF_DATAKIT      9               /* datakit protocols */
596*d8b80295SApple OSS Distributions #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
597*d8b80295SApple OSS Distributions #define AF_SNA          11              /* IBM SNA */
598*d8b80295SApple OSS Distributions #define AF_DECnet       12              /* DECnet */
599*d8b80295SApple OSS Distributions #define AF_DLI          13              /* DEC Direct data link interface */
600*d8b80295SApple OSS Distributions #define AF_LAT          14              /* LAT */
601*d8b80295SApple OSS Distributions #define AF_HYLINK       15              /* NSC Hyperchannel */
602*d8b80295SApple OSS Distributions #define AF_APPLETALK    16              /* Apple Talk */
603*d8b80295SApple OSS Distributions #define AF_ROUTE        17              /* Internal Routing Protocol */
604*d8b80295SApple OSS Distributions #define AF_LINK         18              /* Link layer interface */
605*d8b80295SApple OSS Distributions #define pseudo_AF_XTP   19              /* eXpress Transfer Protocol (no AF) */
606*d8b80295SApple OSS Distributions #define AF_COIP         20              /* connection-oriented IP, aka ST II */
607*d8b80295SApple OSS Distributions #define AF_CNT          21              /* Computer Network Technology */
608*d8b80295SApple OSS Distributions #define pseudo_AF_RTIP  22              /* Help Identify RTIP packets */
609*d8b80295SApple OSS Distributions #define AF_IPX          23              /* Novell Internet Protocol */
610*d8b80295SApple OSS Distributions #define AF_SIP          24              /* Simple Internet Protocol */
611*d8b80295SApple OSS Distributions #define pseudo_AF_PIP   25              /* Help Identify PIP packets */
612*d8b80295SApple OSS Distributions #define AF_NDRV         27              /* Network Driver 'raw' access */
613*d8b80295SApple OSS Distributions #define AF_ISDN         28              /* Integrated Services Digital Network */
614*d8b80295SApple OSS Distributions #define AF_E164         AF_ISDN         /* CCITT E.164 recommendation */
615*d8b80295SApple OSS Distributions #define pseudo_AF_KEY   29              /* Internal key-management function */
616*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
617*d8b80295SApple OSS Distributions #define AF_INET6        30              /* IPv6 */
618*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
619*d8b80295SApple OSS Distributions #define AF_NATM         31              /* native ATM access */
620*d8b80295SApple OSS Distributions #define AF_SYSTEM       32              /* Kernel event messages */
621*d8b80295SApple OSS Distributions #define AF_NETBIOS      33              /* NetBIOS */
622*d8b80295SApple OSS Distributions #define AF_PPP          34              /* PPP communication protocol */
623*d8b80295SApple OSS Distributions #define pseudo_AF_HDRCMPLT 35           /* Used by BPF to not rewrite headers
624*d8b80295SApple OSS Distributions 	                                 *  in interface output routine */
625*d8b80295SApple OSS Distributions #ifdef PRIVATE
626*d8b80295SApple OSS Distributions #define AF_AFP  36                      /* Used by AFP */
627*d8b80295SApple OSS Distributions #else
628*d8b80295SApple OSS Distributions #define AF_RESERVED_36  36              /* Reserved for internal usage */
629*d8b80295SApple OSS Distributions #endif
630*d8b80295SApple OSS Distributions #define AF_IEEE80211    37              /* IEEE 802.11 protocol */
631*d8b80295SApple OSS Distributions #define AF_UTUN         38
632*d8b80295SApple OSS Distributions #ifdef PRIVATE
633*d8b80295SApple OSS Distributions #define AF_MULTIPATH    39
634*d8b80295SApple OSS Distributions #endif /* PRIVATE */
635*d8b80295SApple OSS Distributions #define AF_VSOCK        40              /* VM Sockets */
636*d8b80295SApple OSS Distributions #define AF_MAX          41
637*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
638*d8b80295SApple OSS Distributions 
639*d8b80295SApple OSS Distributions /*
640*d8b80295SApple OSS Distributions  * [XSI] Structure used by kernel to store most addresses.
641*d8b80295SApple OSS Distributions  */
642*d8b80295SApple OSS Distributions struct sockaddr {
643*d8b80295SApple OSS Distributions 	__uint8_t       sa_len;         /* total length */
644*d8b80295SApple OSS Distributions 	sa_family_t     sa_family;      /* [XSI] address family */
645*d8b80295SApple OSS Distributions 	char            sa_data[14];    /* [XSI] addr value */
646*d8b80295SApple OSS Distributions };
647*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct sockaddr, sockaddr);
648*d8b80295SApple OSS Distributions 
649*d8b80295SApple OSS Distributions /*
650*d8b80295SApple OSS Distributions  * Least amount of information that a sockaddr requires.
651*d8b80295SApple OSS Distributions  * Sockaddr_header is a compatible prefix structure of
652*d8b80295SApple OSS Distributions  * all sockaddr objects.
653*d8b80295SApple OSS Distributions  */
654*d8b80295SApple OSS Distributions struct __sockaddr_header {
655*d8b80295SApple OSS Distributions 	__uint8_t           sa_len;
656*d8b80295SApple OSS Distributions 	sa_family_t         sa_family;
657*d8b80295SApple OSS Distributions };
658*d8b80295SApple OSS Distributions 
659*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
660*d8b80295SApple OSS Distributions #define SOCK_MAXADDRLEN 255             /* longest possible addresses */
661*d8b80295SApple OSS Distributions 
662*d8b80295SApple OSS Distributions /*
663*d8b80295SApple OSS Distributions  * Structure used by kernel to pass protocol
664*d8b80295SApple OSS Distributions  * information in raw sockets.
665*d8b80295SApple OSS Distributions  */
666*d8b80295SApple OSS Distributions struct sockproto {
667*d8b80295SApple OSS Distributions 	__uint16_t      sp_family;              /* address family */
668*d8b80295SApple OSS Distributions 	__uint16_t      sp_protocol;            /* protocol */
669*d8b80295SApple OSS Distributions };
670*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
671*d8b80295SApple OSS Distributions 
672*d8b80295SApple OSS Distributions /*
673*d8b80295SApple OSS Distributions  * RFC 2553: protocol-independent placeholder for socket addresses
674*d8b80295SApple OSS Distributions  */
675*d8b80295SApple OSS Distributions #define _SS_MAXSIZE     128
676*d8b80295SApple OSS Distributions #define _SS_ALIGNSIZE   (sizeof(__int64_t))
677*d8b80295SApple OSS Distributions #define _SS_PAD1SIZE    \
678*d8b80295SApple OSS Distributions 	        (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
679*d8b80295SApple OSS Distributions #define _SS_PAD2SIZE    \
680*d8b80295SApple OSS Distributions 	        (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
681*d8b80295SApple OSS Distributions 	                        _SS_PAD1SIZE - _SS_ALIGNSIZE)
682*d8b80295SApple OSS Distributions 
683*d8b80295SApple OSS Distributions /*
684*d8b80295SApple OSS Distributions  * [XSI] sockaddr_storage
685*d8b80295SApple OSS Distributions  */
686*d8b80295SApple OSS Distributions struct sockaddr_storage {
687*d8b80295SApple OSS Distributions 	__uint8_t       ss_len;         /* address length */
688*d8b80295SApple OSS Distributions 	sa_family_t     ss_family;      /* [XSI] address family */
689*d8b80295SApple OSS Distributions 	char                    __ss_pad1[_SS_PAD1SIZE];
690*d8b80295SApple OSS Distributions 	__int64_t       __ss_align;     /* force structure storage alignment */
691*d8b80295SApple OSS Distributions 	char                    __ss_pad2[_SS_PAD2SIZE];
692*d8b80295SApple OSS Distributions };
693*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct sockaddr_storage, sockaddr_storage);
694*d8b80295SApple OSS Distributions 
695*d8b80295SApple OSS Distributions /*
696*d8b80295SApple OSS Distributions  * Protocol families, same as address families for now.
697*d8b80295SApple OSS Distributions  */
698*d8b80295SApple OSS Distributions #define PF_UNSPEC       AF_UNSPEC
699*d8b80295SApple OSS Distributions #define PF_LOCAL        AF_LOCAL
700*d8b80295SApple OSS Distributions #define PF_UNIX         PF_LOCAL        /* backward compatibility */
701*d8b80295SApple OSS Distributions #define PF_INET         AF_INET
702*d8b80295SApple OSS Distributions #define PF_IMPLINK      AF_IMPLINK
703*d8b80295SApple OSS Distributions #define PF_PUP          AF_PUP
704*d8b80295SApple OSS Distributions #define PF_CHAOS        AF_CHAOS
705*d8b80295SApple OSS Distributions #define PF_NS           AF_NS
706*d8b80295SApple OSS Distributions #define PF_ISO          AF_ISO
707*d8b80295SApple OSS Distributions #define PF_OSI          AF_ISO
708*d8b80295SApple OSS Distributions #define PF_ECMA         AF_ECMA
709*d8b80295SApple OSS Distributions #define PF_DATAKIT      AF_DATAKIT
710*d8b80295SApple OSS Distributions #define PF_CCITT        AF_CCITT
711*d8b80295SApple OSS Distributions #define PF_SNA          AF_SNA
712*d8b80295SApple OSS Distributions #define PF_DECnet       AF_DECnet
713*d8b80295SApple OSS Distributions #define PF_DLI          AF_DLI
714*d8b80295SApple OSS Distributions #define PF_LAT          AF_LAT
715*d8b80295SApple OSS Distributions #define PF_HYLINK       AF_HYLINK
716*d8b80295SApple OSS Distributions #define PF_APPLETALK    AF_APPLETALK
717*d8b80295SApple OSS Distributions #define PF_ROUTE        AF_ROUTE
718*d8b80295SApple OSS Distributions #define PF_LINK         AF_LINK
719*d8b80295SApple OSS Distributions #define PF_XTP          pseudo_AF_XTP   /* really just proto family, no AF */
720*d8b80295SApple OSS Distributions #define PF_COIP         AF_COIP
721*d8b80295SApple OSS Distributions #define PF_CNT          AF_CNT
722*d8b80295SApple OSS Distributions #define PF_SIP          AF_SIP
723*d8b80295SApple OSS Distributions #define PF_IPX          AF_IPX          /* same format as AF_NS */
724*d8b80295SApple OSS Distributions #define PF_RTIP         pseudo_AF_RTIP  /* same format as AF_INET */
725*d8b80295SApple OSS Distributions #define PF_PIP          pseudo_AF_PIP
726*d8b80295SApple OSS Distributions #define PF_NDRV         AF_NDRV
727*d8b80295SApple OSS Distributions #define PF_ISDN         AF_ISDN
728*d8b80295SApple OSS Distributions #define PF_KEY          pseudo_AF_KEY
729*d8b80295SApple OSS Distributions #define PF_INET6        AF_INET6
730*d8b80295SApple OSS Distributions #define PF_NATM         AF_NATM
731*d8b80295SApple OSS Distributions #define PF_SYSTEM       AF_SYSTEM
732*d8b80295SApple OSS Distributions #define PF_NETBIOS      AF_NETBIOS
733*d8b80295SApple OSS Distributions #define PF_PPP          AF_PPP
734*d8b80295SApple OSS Distributions #ifdef PRIVATE
735*d8b80295SApple OSS Distributions #define PF_AFP          AF_AFP
736*d8b80295SApple OSS Distributions #else
737*d8b80295SApple OSS Distributions #define PF_RESERVED_36  AF_RESERVED_36
738*d8b80295SApple OSS Distributions #endif
739*d8b80295SApple OSS Distributions #define PF_UTUN         AF_UTUN
740*d8b80295SApple OSS Distributions #ifdef PRIVATE
741*d8b80295SApple OSS Distributions #define PF_MULTIPATH    AF_MULTIPATH
742*d8b80295SApple OSS Distributions #endif /* PRIVATE */
743*d8b80295SApple OSS Distributions #define PF_VSOCK        AF_VSOCK
744*d8b80295SApple OSS Distributions #define PF_MAX          AF_MAX
745*d8b80295SApple OSS Distributions 
746*d8b80295SApple OSS Distributions /*
747*d8b80295SApple OSS Distributions  * These do not have socket-layer support:
748*d8b80295SApple OSS Distributions  */
749*d8b80295SApple OSS Distributions #define PF_VLAN         ((uint32_t)0x766c616e)  /* 'vlan' */
750*d8b80295SApple OSS Distributions #define PF_BOND         ((uint32_t)0x626f6e64)  /* 'bond' */
751*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
752*d8b80295SApple OSS Distributions #define PF_BRIDGE       ((uint32_t)0x62726467)  /* 'brdg' */
753*d8b80295SApple OSS Distributions #define PF_NULL         ((uint32_t)0x6e756c6c)  /* 'null' */
754*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
755*d8b80295SApple OSS Distributions 
756*d8b80295SApple OSS Distributions /*
757*d8b80295SApple OSS Distributions  * Definitions for network related sysctl, CTL_NET.
758*d8b80295SApple OSS Distributions  *
759*d8b80295SApple OSS Distributions  * Second level is protocol family.
760*d8b80295SApple OSS Distributions  * Third level is protocol number.
761*d8b80295SApple OSS Distributions  *
762*d8b80295SApple OSS Distributions  * Further levels are defined by the individual families below.
763*d8b80295SApple OSS Distributions  */
764*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
765*d8b80295SApple OSS Distributions #define NET_MAXID       AF_MAX
766*d8b80295SApple OSS Distributions #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
767*d8b80295SApple OSS Distributions 
768*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
769*d8b80295SApple OSS Distributions #define CTL_NET_NAMES { \
770*d8b80295SApple OSS Distributions 	{ 0, 0 }, \
771*d8b80295SApple OSS Distributions 	{ "local", CTLTYPE_NODE }, \
772*d8b80295SApple OSS Distributions 	{ "inet", CTLTYPE_NODE }, \
773*d8b80295SApple OSS Distributions 	{ "implink", CTLTYPE_NODE }, \
774*d8b80295SApple OSS Distributions 	{ "pup", CTLTYPE_NODE }, \
775*d8b80295SApple OSS Distributions 	{ "chaos", CTLTYPE_NODE }, \
776*d8b80295SApple OSS Distributions 	{ "xerox_ns", CTLTYPE_NODE }, \
777*d8b80295SApple OSS Distributions 	{ "iso", CTLTYPE_NODE }, \
778*d8b80295SApple OSS Distributions 	{ "emca", CTLTYPE_NODE }, \
779*d8b80295SApple OSS Distributions 	{ "datakit", CTLTYPE_NODE }, \
780*d8b80295SApple OSS Distributions 	{ "ccitt", CTLTYPE_NODE }, \
781*d8b80295SApple OSS Distributions 	{ "ibm_sna", CTLTYPE_NODE }, \
782*d8b80295SApple OSS Distributions 	{ "decnet", CTLTYPE_NODE }, \
783*d8b80295SApple OSS Distributions 	{ "dec_dli", CTLTYPE_NODE }, \
784*d8b80295SApple OSS Distributions 	{ "lat", CTLTYPE_NODE }, \
785*d8b80295SApple OSS Distributions 	{ "hylink", CTLTYPE_NODE }, \
786*d8b80295SApple OSS Distributions 	{ "appletalk", CTLTYPE_NODE }, \
787*d8b80295SApple OSS Distributions 	{ "route", CTLTYPE_NODE }, \
788*d8b80295SApple OSS Distributions 	{ "link_layer", CTLTYPE_NODE }, \
789*d8b80295SApple OSS Distributions 	{ "xtp", CTLTYPE_NODE }, \
790*d8b80295SApple OSS Distributions 	{ "coip", CTLTYPE_NODE }, \
791*d8b80295SApple OSS Distributions 	{ "cnt", CTLTYPE_NODE }, \
792*d8b80295SApple OSS Distributions 	{ "rtip", CTLTYPE_NODE }, \
793*d8b80295SApple OSS Distributions 	{ "ipx", CTLTYPE_NODE }, \
794*d8b80295SApple OSS Distributions 	{ "sip", CTLTYPE_NODE }, \
795*d8b80295SApple OSS Distributions 	{ "pip", CTLTYPE_NODE }, \
796*d8b80295SApple OSS Distributions 	{ 0, 0 }, \
797*d8b80295SApple OSS Distributions 	{ "ndrv", CTLTYPE_NODE }, \
798*d8b80295SApple OSS Distributions 	{ "isdn", CTLTYPE_NODE }, \
799*d8b80295SApple OSS Distributions 	{ "key", CTLTYPE_NODE }, \
800*d8b80295SApple OSS Distributions 	{ "inet6", CTLTYPE_NODE }, \
801*d8b80295SApple OSS Distributions 	{ "natm", CTLTYPE_NODE }, \
802*d8b80295SApple OSS Distributions 	{ "sys", CTLTYPE_NODE }, \
803*d8b80295SApple OSS Distributions 	{ "netbios", CTLTYPE_NODE }, \
804*d8b80295SApple OSS Distributions 	{ "ppp", CTLTYPE_NODE }, \
805*d8b80295SApple OSS Distributions 	{ "hdrcomplete", CTLTYPE_NODE }, \
806*d8b80295SApple OSS Distributions 	{ "vsock", CTLTYPE_NODE }, \
807*d8b80295SApple OSS Distributions }
808*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
809*d8b80295SApple OSS Distributions 
810*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
811*d8b80295SApple OSS Distributions /*
812*d8b80295SApple OSS Distributions  * PF_ROUTE - Routing table
813*d8b80295SApple OSS Distributions  *
814*d8b80295SApple OSS Distributions  * Three additional levels are defined:
815*d8b80295SApple OSS Distributions  *	Fourth: address family, 0 is wildcard
816*d8b80295SApple OSS Distributions  *	Fifth: type of info, defined below
817*d8b80295SApple OSS Distributions  *	Sixth: flag(s) to mask with for NET_RT_FLAGS
818*d8b80295SApple OSS Distributions  */
819*d8b80295SApple OSS Distributions #define NET_RT_DUMP             1       /* dump; may limit to a.f. */
820*d8b80295SApple OSS Distributions #define NET_RT_FLAGS            2       /* by flags, e.g. RESOLVING */
821*d8b80295SApple OSS Distributions #define NET_RT_IFLIST           3       /* survey interface list */
822*d8b80295SApple OSS Distributions #define NET_RT_STAT             4       /* routing statistics */
823*d8b80295SApple OSS Distributions #define NET_RT_TRASH            5       /* routes not in table but not freed */
824*d8b80295SApple OSS Distributions #define NET_RT_IFLIST2          6       /* interface list with addresses */
825*d8b80295SApple OSS Distributions #define NET_RT_DUMP2            7       /* dump; may limit to a.f. */
826*d8b80295SApple OSS Distributions #ifdef PRIVATE
827*d8b80295SApple OSS Distributions #define NET_RT_DUMPX            8       /* private */
828*d8b80295SApple OSS Distributions #define NET_RT_DUMPX_FLAGS      9       /* private */
829*d8b80295SApple OSS Distributions #endif /* PRIVATE */
830*d8b80295SApple OSS Distributions /*
831*d8b80295SApple OSS Distributions  * Allows read access non-local host's MAC address
832*d8b80295SApple OSS Distributions  * if the process has neighbor cache entitlement.
833*d8b80295SApple OSS Distributions  */
834*d8b80295SApple OSS Distributions #define NET_RT_FLAGS_PRIV       10
835*d8b80295SApple OSS Distributions #define NET_RT_MAXID            11
836*d8b80295SApple OSS Distributions #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
837*d8b80295SApple OSS Distributions 
838*d8b80295SApple OSS Distributions #ifdef PRIVATE
839*d8b80295SApple OSS Distributions /* These are supported values for SO_STATISTICS_EVENT */
840*d8b80295SApple OSS Distributions #define SO_STATISTICS_EVENT_ENTER_CELLFALLBACK (1 << 0)
841*d8b80295SApple OSS Distributions #define SO_STATISTICS_EVENT_EXIT_CELLFALLBACK  (1 << 1)
842*d8b80295SApple OSS Distributions #define SO_STATISTICS_EVENT_ATTRIBUTION_CHANGE (1 << 2)
843*d8b80295SApple OSS Distributions #define SO_STATISTICS_EVENT_RESERVED_2         (1 << 3)
844*d8b80295SApple OSS Distributions #endif /* PRIVATE */
845*d8b80295SApple OSS Distributions 
846*d8b80295SApple OSS Distributions 
847*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
848*d8b80295SApple OSS Distributions #define CTL_NET_RT_NAMES { \
849*d8b80295SApple OSS Distributions 	{ 0, 0 }, \
850*d8b80295SApple OSS Distributions 	{ "dump", CTLTYPE_STRUCT }, \
851*d8b80295SApple OSS Distributions 	{ "flags", CTLTYPE_STRUCT }, \
852*d8b80295SApple OSS Distributions 	{ "iflist", CTLTYPE_STRUCT }, \
853*d8b80295SApple OSS Distributions 	{ "stat", CTLTYPE_STRUCT }, \
854*d8b80295SApple OSS Distributions 	{ "trash", CTLTYPE_INT }, \
855*d8b80295SApple OSS Distributions 	{ "iflist2", CTLTYPE_STRUCT }, \
856*d8b80295SApple OSS Distributions 	{ "dump2", CTLTYPE_STRUCT }, \
857*d8b80295SApple OSS Distributions 	{ "dumpx", CTLTYPE_STRUCT }, \
858*d8b80295SApple OSS Distributions 	{ "dumpx_flags", CTLTYPE_STRUCT }, \
859*d8b80295SApple OSS Distributions }
860*d8b80295SApple OSS Distributions 
861*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
862*d8b80295SApple OSS Distributions 
863*d8b80295SApple OSS Distributions /*
864*d8b80295SApple OSS Distributions  * Maximum queue length specifiable by listen.
865*d8b80295SApple OSS Distributions  */
866*d8b80295SApple OSS Distributions #define SOMAXCONN       128
867*d8b80295SApple OSS Distributions 
868*d8b80295SApple OSS Distributions /*
869*d8b80295SApple OSS Distributions  * [XSI] Message header for recvmsg and sendmsg calls.
870*d8b80295SApple OSS Distributions  * Used value-result for recvmsg, value only for sendmsg.
871*d8b80295SApple OSS Distributions  */
872*d8b80295SApple OSS Distributions struct msghdr {
873*d8b80295SApple OSS Distributions 	void            *msg_name;      /* [XSI] optional address */
874*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* [XSI] size of address */
875*d8b80295SApple OSS Distributions 	struct          iovec *msg_iov; /* [XSI] scatter/gather array */
876*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* [XSI] # elements in msg_iov */
877*d8b80295SApple OSS Distributions 	void            *msg_control;   /* [XSI] ancillary data, see below */
878*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* [XSI] ancillary data buffer len */
879*d8b80295SApple OSS Distributions 	int             msg_flags;      /* [XSI] flags on received message */
880*d8b80295SApple OSS Distributions };
881*d8b80295SApple OSS Distributions 
882*d8b80295SApple OSS Distributions #ifdef PRIVATE
883*d8b80295SApple OSS Distributions /*
884*d8b80295SApple OSS Distributions  * Extended version for sendmsg_x() and recvmsg_x() calls
885*d8b80295SApple OSS Distributions  *
886*d8b80295SApple OSS Distributions  * For recvmsg_x(), the size of the data received is given by the field
887*d8b80295SApple OSS Distributions  * msg_datalen.
888*d8b80295SApple OSS Distributions  *
889*d8b80295SApple OSS Distributions  * For sendmsg_x(), the size of the data to send is given by the length of
890*d8b80295SApple OSS Distributions  * the iovec array -- like sendmsg(). The field msg_datalen is ignored.
891*d8b80295SApple OSS Distributions  */
892*d8b80295SApple OSS Distributions struct msghdr_x {
893*d8b80295SApple OSS Distributions 	void            *msg_name;      /* optional address */
894*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* size of address */
895*d8b80295SApple OSS Distributions 	struct iovec    *msg_iov;       /* scatter/gather array */
896*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* # elements in msg_iov */
897*d8b80295SApple OSS Distributions 	void            *msg_control;   /* ancillary data, see below */
898*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* ancillary data buffer len */
899*d8b80295SApple OSS Distributions 	int             msg_flags;      /* flags on received message */
900*d8b80295SApple OSS Distributions 	size_t          msg_datalen;    /* byte length of buffer in msg_iov */
901*d8b80295SApple OSS Distributions };
902*d8b80295SApple OSS Distributions #endif /* PRIVATE */
903*d8b80295SApple OSS Distributions 
904*d8b80295SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
905*d8b80295SApple OSS Distributions /*
906*d8b80295SApple OSS Distributions  * In-kernel representation of "struct msghdr" from
907*d8b80295SApple OSS Distributions  * userspace. Has enough precision for 32-bit or
908*d8b80295SApple OSS Distributions  * 64-bit clients, but does not need to be packed.
909*d8b80295SApple OSS Distributions  */
910*d8b80295SApple OSS Distributions 
911*d8b80295SApple OSS Distributions struct user_msghdr {
912*d8b80295SApple OSS Distributions 	user_addr_t     msg_name;               /* optional address */
913*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;            /* size of address */
914*d8b80295SApple OSS Distributions 	vm_address_t    msg_iov;                /* scatter/gather array */
915*d8b80295SApple OSS Distributions 	int             msg_iovlen;             /* # elements in msg_iov */
916*d8b80295SApple OSS Distributions 	user_addr_t     msg_control;            /* ancillary data, see below */
917*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen;         /* ancillary data buffer len */
918*d8b80295SApple OSS Distributions 	int             msg_flags;              /* flags on received message */
919*d8b80295SApple OSS Distributions };
920*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user_msghdr, user_msghdr);
921*d8b80295SApple OSS Distributions 
922*d8b80295SApple OSS Distributions /*
923*d8b80295SApple OSS Distributions  * LP64 user version of struct msghdr.
924*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct msghdr
925*d8b80295SApple OSS Distributions  */
926*d8b80295SApple OSS Distributions 
927*d8b80295SApple OSS Distributions struct user64_msghdr {
928*d8b80295SApple OSS Distributions 	user64_addr_t   msg_name;               /* optional address */
929*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;            /* size of address */
930*d8b80295SApple OSS Distributions 	user64_addr_t   msg_iov;                /* scatter/gather array */
931*d8b80295SApple OSS Distributions 	int             msg_iovlen;             /* # elements in msg_iov */
932*d8b80295SApple OSS Distributions 	user64_addr_t   msg_control;            /* ancillary data, see below */
933*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen;         /* ancillary data buffer len */
934*d8b80295SApple OSS Distributions 	int             msg_flags;              /* flags on received message */
935*d8b80295SApple OSS Distributions };
936*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user64_msghdr, user64_msghdr);
937*d8b80295SApple OSS Distributions 
938*d8b80295SApple OSS Distributions /*
939*d8b80295SApple OSS Distributions  * ILP32 user version of struct msghdr.
940*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct msghdr
941*d8b80295SApple OSS Distributions  */
942*d8b80295SApple OSS Distributions 
943*d8b80295SApple OSS Distributions struct user32_msghdr {
944*d8b80295SApple OSS Distributions 	user32_addr_t   msg_name;       /* optional address */
945*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* size of address */
946*d8b80295SApple OSS Distributions 	user32_addr_t   msg_iov;        /* scatter/gather array */
947*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* # elements in msg_iov */
948*d8b80295SApple OSS Distributions 	user32_addr_t   msg_control;    /* ancillary data, see below */
949*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* ancillary data buffer len */
950*d8b80295SApple OSS Distributions 	int             msg_flags;      /* flags on received message */
951*d8b80295SApple OSS Distributions };
952*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user32_msghdr, user32_msghdr);
953*d8b80295SApple OSS Distributions 
954*d8b80295SApple OSS Distributions /*
955*d8b80295SApple OSS Distributions  * In-kernel representation of "struct msghdr_x" from
956*d8b80295SApple OSS Distributions  * userspace. Has enough precision for 32-bit or
957*d8b80295SApple OSS Distributions  * 64-bit clients, but does not need to be packed.
958*d8b80295SApple OSS Distributions  */
959*d8b80295SApple OSS Distributions 
960*d8b80295SApple OSS Distributions struct user_msghdr_x {
961*d8b80295SApple OSS Distributions 	user_addr_t     msg_name;       /* optional address */
962*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* size of address */
963*d8b80295SApple OSS Distributions 	vm_address_t    msg_iov;        /* scatter/gather array */
964*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* # elements in msg_iov */
965*d8b80295SApple OSS Distributions 	user_addr_t     msg_control;    /* ancillary data, see below */
966*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* ancillary data buffer len */
967*d8b80295SApple OSS Distributions 	int             msg_flags;      /* flags on received message */
968*d8b80295SApple OSS Distributions 	size_t          msg_datalen;    /* byte length of buffer in msg_iov */
969*d8b80295SApple OSS Distributions };
970*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user_msghdr_x, user_msghdr_x);
971*d8b80295SApple OSS Distributions 
972*d8b80295SApple OSS Distributions 
973*d8b80295SApple OSS Distributions /*
974*d8b80295SApple OSS Distributions  * LP64 user version of struct msghdr_x
975*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct msghdr_x
976*d8b80295SApple OSS Distributions  */
977*d8b80295SApple OSS Distributions 
978*d8b80295SApple OSS Distributions struct user64_msghdr_x {
979*d8b80295SApple OSS Distributions 	user64_addr_t   msg_name;       /* optional address */
980*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* size of address */
981*d8b80295SApple OSS Distributions 	user64_addr_t   msg_iov;        /* scatter/gather array */
982*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* # elements in msg_iov */
983*d8b80295SApple OSS Distributions 	user64_addr_t   msg_control;    /* ancillary data, see below */
984*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* ancillary data buffer len */
985*d8b80295SApple OSS Distributions 	int             msg_flags;      /* flags on received message */
986*d8b80295SApple OSS Distributions 	user64_size_t   msg_datalen;    /* byte length of buffer in msg_iov */
987*d8b80295SApple OSS Distributions };
988*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user64_msghdr_x, user64_msghdr_x);
989*d8b80295SApple OSS Distributions 
990*d8b80295SApple OSS Distributions /*
991*d8b80295SApple OSS Distributions  * ILP32 user version of struct msghdr_x
992*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct msghdr_x
993*d8b80295SApple OSS Distributions  */
994*d8b80295SApple OSS Distributions 
995*d8b80295SApple OSS Distributions struct user32_msghdr_x {
996*d8b80295SApple OSS Distributions 	user32_addr_t   msg_name;       /* optional address */
997*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;    /* size of address */
998*d8b80295SApple OSS Distributions 	user32_addr_t   msg_iov;        /* scatter/gather array */
999*d8b80295SApple OSS Distributions 	int             msg_iovlen;     /* # elements in msg_iov */
1000*d8b80295SApple OSS Distributions 	user32_addr_t   msg_control;    /* ancillary data, see below */
1001*d8b80295SApple OSS Distributions 	socklen_t       msg_controllen; /* ancillary data buffer len */
1002*d8b80295SApple OSS Distributions 	int             msg_flags;      /* flags on received message */
1003*d8b80295SApple OSS Distributions 	user32_size_t   msg_datalen;    /* byte length of buffer in msg_iov */
1004*d8b80295SApple OSS Distributions };
1005*d8b80295SApple OSS Distributions __CCT_DECLARE_CONSTRAINED_PTR_TYPES(struct user32_msghdr_x, user32_msghdr_x);
1006*d8b80295SApple OSS Distributions 
1007*d8b80295SApple OSS Distributions /*
1008*d8b80295SApple OSS Distributions  * In-kernel representation of "struct sa_endpoints" from
1009*d8b80295SApple OSS Distributions  * userspace. Has enough precision for 32-bit or
1010*d8b80295SApple OSS Distributions  * 64-bit clients, but does not need to be packed.
1011*d8b80295SApple OSS Distributions  */
1012*d8b80295SApple OSS Distributions 
1013*d8b80295SApple OSS Distributions struct user_sa_endpoints {
1014*d8b80295SApple OSS Distributions 	unsigned int    sae_srcif;      /* optional source interface */
1015*d8b80295SApple OSS Distributions 	user_addr_t     sae_srcaddr;    /* optional source address */
1016*d8b80295SApple OSS Distributions 	socklen_t       sae_srcaddrlen; /* size of source address */
1017*d8b80295SApple OSS Distributions 	user_addr_t     sae_dstaddr;    /* destination address */
1018*d8b80295SApple OSS Distributions 	socklen_t       sae_dstaddrlen; /* size of destination address */
1019*d8b80295SApple OSS Distributions };
1020*d8b80295SApple OSS Distributions 
1021*d8b80295SApple OSS Distributions /*
1022*d8b80295SApple OSS Distributions  * LP64 user version of struct sa_endpoints
1023*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct sa_endpoints
1024*d8b80295SApple OSS Distributions  */
1025*d8b80295SApple OSS Distributions 
1026*d8b80295SApple OSS Distributions struct user64_sa_endpoints {
1027*d8b80295SApple OSS Distributions 	unsigned int    sae_srcif;      /* optional source interface */
1028*d8b80295SApple OSS Distributions 	user64_addr_t   sae_srcaddr;    /* optional source address */
1029*d8b80295SApple OSS Distributions 	socklen_t       sae_srcaddrlen; /* size of source address */
1030*d8b80295SApple OSS Distributions 	user64_addr_t   sae_dstaddr;    /* destination address */
1031*d8b80295SApple OSS Distributions 	socklen_t       sae_dstaddrlen; /* size of destination address */
1032*d8b80295SApple OSS Distributions };
1033*d8b80295SApple OSS Distributions 
1034*d8b80295SApple OSS Distributions /*
1035*d8b80295SApple OSS Distributions  * ILP32 user version of struct sa_endpoints
1036*d8b80295SApple OSS Distributions  * WARNING - keep in sync with struct sa_endpoints
1037*d8b80295SApple OSS Distributions  */
1038*d8b80295SApple OSS Distributions 
1039*d8b80295SApple OSS Distributions struct user32_sa_endpoints {
1040*d8b80295SApple OSS Distributions 	unsigned int    sae_srcif;      /* optional source interface */
1041*d8b80295SApple OSS Distributions 	user32_addr_t   sae_srcaddr;    /* optional source address */
1042*d8b80295SApple OSS Distributions 	socklen_t       sae_srcaddrlen; /* size of source address */
1043*d8b80295SApple OSS Distributions 	user32_addr_t   sae_dstaddr;    /* destination address */
1044*d8b80295SApple OSS Distributions 	socklen_t       sae_dstaddrlen; /* size of destination address */
1045*d8b80295SApple OSS Distributions };
1046*d8b80295SApple OSS Distributions 
1047*d8b80295SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
1048*d8b80295SApple OSS Distributions 
1049*d8b80295SApple OSS Distributions #define MSG_OOB         0x1             /* process out-of-band data */
1050*d8b80295SApple OSS Distributions #define MSG_PEEK        0x2             /* peek at incoming message */
1051*d8b80295SApple OSS Distributions #define MSG_DONTROUTE   0x4             /* send without using routing tables */
1052*d8b80295SApple OSS Distributions #define MSG_EOR         0x8             /* data completes record */
1053*d8b80295SApple OSS Distributions #define MSG_TRUNC       0x10            /* data discarded before delivery */
1054*d8b80295SApple OSS Distributions #define MSG_CTRUNC      0x20            /* control data lost before delivery */
1055*d8b80295SApple OSS Distributions #define MSG_WAITALL     0x40            /* wait for full request or error */
1056*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1057*d8b80295SApple OSS Distributions #define MSG_DONTWAIT    0x80            /* this message should be nonblocking */
1058*d8b80295SApple OSS Distributions #define MSG_EOF         0x100           /* data completes connection */
1059*d8b80295SApple OSS Distributions #ifdef __APPLE__
1060*d8b80295SApple OSS Distributions #ifndef PRIVATE
1061*d8b80295SApple OSS Distributions #ifdef __APPLE_API_OBSOLETE
1062*d8b80295SApple OSS Distributions #define MSG_WAITSTREAM  0x200           /* wait up to full request.. may return partial */
1063*d8b80295SApple OSS Distributions #endif
1064*d8b80295SApple OSS Distributions #else
1065*d8b80295SApple OSS Distributions #define MSG_WAITSTREAM  0x200           /* wait up to full request.. may return partial */
1066*d8b80295SApple OSS Distributions #endif
1067*d8b80295SApple OSS Distributions #define MSG_FLUSH       0x400           /* Start of 'hold' seq; dump so_temp, deprecated */
1068*d8b80295SApple OSS Distributions #define MSG_HOLD        0x800           /* Hold frag in so_temp, deprecated */
1069*d8b80295SApple OSS Distributions #define MSG_SEND        0x1000          /* Send the packet in so_temp, deprecated */
1070*d8b80295SApple OSS Distributions #define MSG_HAVEMORE    0x2000          /* Data ready to be read */
1071*d8b80295SApple OSS Distributions #define MSG_RCVMORE     0x4000          /* Data remains in current pkt */
1072*d8b80295SApple OSS Distributions #endif
1073*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
1074*d8b80295SApple OSS Distributions #define MSG_COMPAT      0x8000          /* deprecated */
1075*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
1076*d8b80295SApple OSS Distributions #define MSG_NEEDSA      0x10000         /* Fail receive if socket address cannot be allocated */
1077*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
1078*d8b80295SApple OSS Distributions #define MSG_NBIO        0x20000         /* FIONBIO mode, used by fifofs */
1079*d8b80295SApple OSS Distributions #define MSG_SKIPCFIL    0x40000         /* skip pass content filter */
1080*d8b80295SApple OSS Distributions #endif
1081*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1082*d8b80295SApple OSS Distributions 
1083*d8b80295SApple OSS Distributions #if __DARWIN_C_LEVEL >= 200809L
1084*d8b80295SApple OSS Distributions #define MSG_NOSIGNAL    0x80000         /* do not generate SIGPIPE on EOF */
1085*d8b80295SApple OSS Distributions #endif /* __DARWIN_C_LEVEL */
1086*d8b80295SApple OSS Distributions 
1087*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1088*d8b80295SApple OSS Distributions #ifdef  KERNEL
1089*d8b80295SApple OSS Distributions #define MSG_USEUPCALL   0x80000000      /* Inherit upcall in sock_accept */
1090*d8b80295SApple OSS Distributions #endif
1091*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1092*d8b80295SApple OSS Distributions 
1093*d8b80295SApple OSS Distributions /*
1094*d8b80295SApple OSS Distributions  * Header for ancillary data objects in msg_control buffer.
1095*d8b80295SApple OSS Distributions  * Used for additional information with/about a datagram
1096*d8b80295SApple OSS Distributions  * not expressible by flags.  The format is a sequence
1097*d8b80295SApple OSS Distributions  * of message elements headed by cmsghdr structures.
1098*d8b80295SApple OSS Distributions  */
1099*d8b80295SApple OSS Distributions struct cmsghdr {
1100*d8b80295SApple OSS Distributions 	socklen_t       cmsg_len;       /* [XSI] data byte count, including hdr */
1101*d8b80295SApple OSS Distributions 	int             cmsg_level;     /* [XSI] originating protocol */
1102*d8b80295SApple OSS Distributions 	int             cmsg_type;      /* [XSI] protocol-specific type */
1103*d8b80295SApple OSS Distributions /* followed by	unsigned char  cmsg_data[]; */
1104*d8b80295SApple OSS Distributions };
1105*d8b80295SApple OSS Distributions 
1106*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1107*d8b80295SApple OSS Distributions #ifndef __APPLE__
1108*d8b80295SApple OSS Distributions /*
1109*d8b80295SApple OSS Distributions  * While we may have more groups than this, the cmsgcred struct must
1110*d8b80295SApple OSS Distributions  * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
1111*d8b80295SApple OSS Distributions  * this.
1112*d8b80295SApple OSS Distributions  */
1113*d8b80295SApple OSS Distributions #define CMGROUP_MAX 16
1114*d8b80295SApple OSS Distributions 
1115*d8b80295SApple OSS Distributions /*
1116*d8b80295SApple OSS Distributions  * Credentials structure, used to verify the identity of a peer
1117*d8b80295SApple OSS Distributions  * process that has sent us a message. This is allocated by the
1118*d8b80295SApple OSS Distributions  * peer process but filled in by the kernel. This prevents the
1119*d8b80295SApple OSS Distributions  * peer from lying about its identity. (Note that cmcred_groups[0]
1120*d8b80295SApple OSS Distributions  * is the effective GID.)
1121*d8b80295SApple OSS Distributions  */
1122*d8b80295SApple OSS Distributions struct cmsgcred {
1123*d8b80295SApple OSS Distributions 	pid_t   cmcred_pid;             /* PID of sending process */
1124*d8b80295SApple OSS Distributions 	uid_t   cmcred_uid;             /* real UID of sending process */
1125*d8b80295SApple OSS Distributions 	uid_t   cmcred_euid;            /* effective UID of sending process */
1126*d8b80295SApple OSS Distributions 	gid_t   cmcred_gid;             /* real GID of sending process */
1127*d8b80295SApple OSS Distributions 	short   cmcred_ngroups;         /* number or groups */
1128*d8b80295SApple OSS Distributions 	gid_t   cmcred_groups[CMGROUP_MAX];     /* groups */
1129*d8b80295SApple OSS Distributions };
1130*d8b80295SApple OSS Distributions #endif
1131*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1132*d8b80295SApple OSS Distributions 
1133*d8b80295SApple OSS Distributions /* given pointer to struct cmsghdr, return pointer to data */
1134*d8b80295SApple OSS Distributions #define CMSG_DATA(cmsg)         ((unsigned char *)(cmsg) + \
1135*d8b80295SApple OSS Distributions 	__DARWIN_ALIGN32(sizeof(struct cmsghdr)))
1136*d8b80295SApple OSS Distributions 
1137*d8b80295SApple OSS Distributions /*
1138*d8b80295SApple OSS Distributions  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
1139*d8b80295SApple OSS Distributions  * an empty list for some reasons.
1140*d8b80295SApple OSS Distributions  */
1141*d8b80295SApple OSS Distributions #define CMSG_FIRSTHDR(mhdr) \
1142*d8b80295SApple OSS Distributions 	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
1143*d8b80295SApple OSS Distributions 	    (struct cmsghdr *)(mhdr)->msg_control : \
1144*d8b80295SApple OSS Distributions 	    (struct cmsghdr *)0L)
1145*d8b80295SApple OSS Distributions 
1146*d8b80295SApple OSS Distributions 
1147*d8b80295SApple OSS Distributions /*
1148*d8b80295SApple OSS Distributions  * Given pointer to struct cmsghdr, return pointer to next cmsghdr
1149*d8b80295SApple OSS Distributions  * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
1150*d8b80295SApple OSS Distributions  */
1151*d8b80295SApple OSS Distributions #define CMSG_NXTHDR(mhdr, cmsg)                                         \
1152*d8b80295SApple OSS Distributions 	((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) :           \
1153*d8b80295SApple OSS Distributions 	    ((((unsigned char *)(cmsg) +                                \
1154*d8b80295SApple OSS Distributions 	    __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) +            \
1155*d8b80295SApple OSS Distributions 	    __DARWIN_ALIGN32(sizeof(struct cmsghdr))) >                 \
1156*d8b80295SApple OSS Distributions 	    ((unsigned char *)(mhdr)->msg_control +                     \
1157*d8b80295SApple OSS Distributions 	    (mhdr)->msg_controllen)) ?                                  \
1158*d8b80295SApple OSS Distributions 	        (struct cmsghdr *)0L /* NULL */ :                       \
1159*d8b80295SApple OSS Distributions 	        (struct cmsghdr *)(void *)((unsigned char *)(cmsg) +    \
1160*d8b80295SApple OSS Distributions 	            __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
1161*d8b80295SApple OSS Distributions 
1162*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1163*d8b80295SApple OSS Distributions /* RFC 2292 additions */
1164*d8b80295SApple OSS Distributions #define CMSG_SPACE(l)           (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
1165*d8b80295SApple OSS Distributions #define CMSG_LEN(l)             (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
1166*d8b80295SApple OSS Distributions 
1167*d8b80295SApple OSS Distributions #ifdef KERNEL
1168*d8b80295SApple OSS Distributions #define CMSG_ALIGN(n)   ((typeof(n))__DARWIN_ALIGN32(n))
1169*d8b80295SApple OSS Distributions #endif
1170*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1171*d8b80295SApple OSS Distributions 
1172*d8b80295SApple OSS Distributions /* "Socket"-level control message types: */
1173*d8b80295SApple OSS Distributions #define SCM_RIGHTS                      0x01    /* access rights (array of int) */
1174*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1175*d8b80295SApple OSS Distributions #define SCM_TIMESTAMP                   0x02    /* timestamp (struct timeval) */
1176*d8b80295SApple OSS Distributions #define SCM_CREDS                       0x03    /* process creds (struct cmsgcred) */
1177*d8b80295SApple OSS Distributions #define SCM_TIMESTAMP_MONOTONIC         0x04    /* timestamp (uint64_t) */
1178*d8b80295SApple OSS Distributions 
1179*d8b80295SApple OSS Distributions #ifdef PRIVATE
1180*d8b80295SApple OSS Distributions #define SCM_TIMESTAMP_CONTINUOUS        0x07    /* timestamp (uint64_t) */
1181*d8b80295SApple OSS Distributions #define SCM_MPKL_SEND_INFO              0x08    /* send info for multi-layer packet logging (struct so_mpkl_send_info) */
1182*d8b80295SApple OSS Distributions #define SCM_MPKL_RECV_INFO              0x09    /* receive info for multi-layer packet logging (struct so_mpkl_recv_info */
1183*d8b80295SApple OSS Distributions #endif /* PRIVATE */
1184*d8b80295SApple OSS Distributions 
1185*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE
1186*d8b80295SApple OSS Distributions /*
1187*d8b80295SApple OSS Distributions  * 4.3 compat sockaddr (deprecated)
1188*d8b80295SApple OSS Distributions  */
1189*d8b80295SApple OSS Distributions struct osockaddr {
1190*d8b80295SApple OSS Distributions 	__uint16_t      sa_family;      /* address family */
1191*d8b80295SApple OSS Distributions 	char    sa_data[14];            /* up to 14 bytes of direct address */
1192*d8b80295SApple OSS Distributions };
1193*d8b80295SApple OSS Distributions 
1194*d8b80295SApple OSS Distributions /*
1195*d8b80295SApple OSS Distributions  * 4.3-compat message header (deprecated)
1196*d8b80295SApple OSS Distributions  */
1197*d8b80295SApple OSS Distributions struct omsghdr {
1198*d8b80295SApple OSS Distributions 	void            *msg_name;              /* optional address */
1199*d8b80295SApple OSS Distributions 	socklen_t       msg_namelen;            /* size of address */
1200*d8b80295SApple OSS Distributions 	struct  iovec   *msg_iov;               /* scatter/gather array */
1201*d8b80295SApple OSS Distributions 	int             msg_iovlen;             /* # elements in msg_iov */
1202*d8b80295SApple OSS Distributions 	void            *msg_accrights;         /* access rights sent/rcvd */
1203*d8b80295SApple OSS Distributions 	int             msg_accrightslen;
1204*d8b80295SApple OSS Distributions };
1205*d8b80295SApple OSS Distributions 
1206*d8b80295SApple OSS Distributions #define SA(s)   ((struct sockaddr *)(void *)(s))
1207*d8b80295SApple OSS Distributions #endif /* KERNEL_PRIVATE */
1208*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1209*d8b80295SApple OSS Distributions 
1210*d8b80295SApple OSS Distributions /*
1211*d8b80295SApple OSS Distributions  * howto arguments for shutdown(2), specified by Posix.1g.
1212*d8b80295SApple OSS Distributions  */
1213*d8b80295SApple OSS Distributions #define SHUT_RD         0               /* shut down the reading side */
1214*d8b80295SApple OSS Distributions #define SHUT_WR         1               /* shut down the writing side */
1215*d8b80295SApple OSS Distributions #define SHUT_RDWR       2               /* shut down both sides */
1216*d8b80295SApple OSS Distributions 
1217*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1218*d8b80295SApple OSS Distributions /*
1219*d8b80295SApple OSS Distributions  * sendfile(2) header/trailer struct
1220*d8b80295SApple OSS Distributions  */
1221*d8b80295SApple OSS Distributions struct sf_hdtr {
1222*d8b80295SApple OSS Distributions 	struct iovec *headers;  /* pointer to an array of header struct iovec's */
1223*d8b80295SApple OSS Distributions 	int hdr_cnt;            /* number of header iovec's */
1224*d8b80295SApple OSS Distributions 	struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
1225*d8b80295SApple OSS Distributions 	int trl_cnt;            /* number of trailer iovec's */
1226*d8b80295SApple OSS Distributions };
1227*d8b80295SApple OSS Distributions 
1228*d8b80295SApple OSS Distributions #ifdef KERNEL
1229*d8b80295SApple OSS Distributions 
1230*d8b80295SApple OSS Distributions /* In-kernel representation */
1231*d8b80295SApple OSS Distributions struct user_sf_hdtr {
1232*d8b80295SApple OSS Distributions 	user_addr_t headers;    /* pointer to an array of header struct iovec's */
1233*d8b80295SApple OSS Distributions 	int hdr_cnt;            /* number of header iovec's */
1234*d8b80295SApple OSS Distributions 	user_addr_t trailers;   /* pointer to an array of trailer struct iovec's */
1235*d8b80295SApple OSS Distributions 	int trl_cnt;            /* number of trailer iovec's */
1236*d8b80295SApple OSS Distributions };
1237*d8b80295SApple OSS Distributions 
1238*d8b80295SApple OSS Distributions /* LP64 user version of struct sf_hdtr */
1239*d8b80295SApple OSS Distributions struct user64_sf_hdtr {
1240*d8b80295SApple OSS Distributions 	user64_addr_t headers;  /* pointer to an array of header struct iovec's */
1241*d8b80295SApple OSS Distributions 	int hdr_cnt;            /* number of header iovec's */
1242*d8b80295SApple OSS Distributions 	user64_addr_t trailers; /* pointer to an array of trailer struct iovec's */
1243*d8b80295SApple OSS Distributions 	int trl_cnt;            /* number of trailer iovec's */
1244*d8b80295SApple OSS Distributions };
1245*d8b80295SApple OSS Distributions 
1246*d8b80295SApple OSS Distributions /* ILP32 user version of struct sf_hdtr */
1247*d8b80295SApple OSS Distributions struct user32_sf_hdtr {
1248*d8b80295SApple OSS Distributions 	user32_addr_t headers;  /* pointer to an array of header struct iovec's */
1249*d8b80295SApple OSS Distributions 	int hdr_cnt;            /* number of header iovec's */
1250*d8b80295SApple OSS Distributions 	user32_addr_t trailers; /* pointer to an array of trailer struct iovec's */
1251*d8b80295SApple OSS Distributions 	int trl_cnt;            /* number of trailer iovec's */
1252*d8b80295SApple OSS Distributions };
1253*d8b80295SApple OSS Distributions 
1254*d8b80295SApple OSS Distributions #endif /* KERNEL */
1255*d8b80295SApple OSS Distributions 
1256*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1257*d8b80295SApple OSS Distributions 
1258*d8b80295SApple OSS Distributions #ifdef PRIVATE
1259*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1260*d8b80295SApple OSS Distributions 
1261*d8b80295SApple OSS Distributions /*
1262*d8b80295SApple OSS Distributions  * Structure for SIOCGASSOCIDS
1263*d8b80295SApple OSS Distributions  */
1264*d8b80295SApple OSS Distributions struct so_aidreq {
1265*d8b80295SApple OSS Distributions 	__uint32_t      sar_cnt;        /* number of associations */
1266*d8b80295SApple OSS Distributions 	sae_associd_t   *sar_aidp;      /* array of association IDs */
1267*d8b80295SApple OSS Distributions };
1268*d8b80295SApple OSS Distributions 
1269*d8b80295SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
1270*d8b80295SApple OSS Distributions struct so_aidreq32 {
1271*d8b80295SApple OSS Distributions 	__uint32_t      sar_cnt;
1272*d8b80295SApple OSS Distributions 	user32_addr_t   sar_aidp;
1273*d8b80295SApple OSS Distributions };
1274*d8b80295SApple OSS Distributions 
1275*d8b80295SApple OSS Distributions struct so_aidreq64 {
1276*d8b80295SApple OSS Distributions 	__uint32_t      sar_cnt;
1277*d8b80295SApple OSS Distributions 	user64_addr_t   sar_aidp __attribute__((aligned(8)));
1278*d8b80295SApple OSS Distributions };
1279*d8b80295SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
1280*d8b80295SApple OSS Distributions 
1281*d8b80295SApple OSS Distributions /*
1282*d8b80295SApple OSS Distributions  * Structure for SIOCGCONNIDS
1283*d8b80295SApple OSS Distributions  */
1284*d8b80295SApple OSS Distributions struct so_cidreq {
1285*d8b80295SApple OSS Distributions 	sae_associd_t   scr_aid;        /* association ID */
1286*d8b80295SApple OSS Distributions 	__uint32_t      scr_cnt;        /* number of connections */
1287*d8b80295SApple OSS Distributions 	sae_connid_t    *scr_cidp;      /* array of connection IDs */
1288*d8b80295SApple OSS Distributions };
1289*d8b80295SApple OSS Distributions 
1290*d8b80295SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
1291*d8b80295SApple OSS Distributions struct so_cidreq32 {
1292*d8b80295SApple OSS Distributions 	sae_associd_t   scr_aid;
1293*d8b80295SApple OSS Distributions 	__uint32_t      scr_cnt;
1294*d8b80295SApple OSS Distributions 	user32_addr_t   scr_cidp;
1295*d8b80295SApple OSS Distributions };
1296*d8b80295SApple OSS Distributions 
1297*d8b80295SApple OSS Distributions struct so_cidreq64 {
1298*d8b80295SApple OSS Distributions 	sae_associd_t   scr_aid;
1299*d8b80295SApple OSS Distributions 	__uint32_t      scr_cnt;
1300*d8b80295SApple OSS Distributions 	user64_addr_t   scr_cidp __attribute__((aligned(8)));
1301*d8b80295SApple OSS Distributions };
1302*d8b80295SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
1303*d8b80295SApple OSS Distributions 
1304*d8b80295SApple OSS Distributions /*
1305*d8b80295SApple OSS Distributions  * Structure for SIOCGCONNINFO
1306*d8b80295SApple OSS Distributions  */
1307*d8b80295SApple OSS Distributions struct so_cinforeq {
1308*d8b80295SApple OSS Distributions 	sae_connid_t    scir_cid;               /* connection ID */
1309*d8b80295SApple OSS Distributions 	__uint32_t      scir_flags;             /* see flags below */
1310*d8b80295SApple OSS Distributions 	__uint32_t      scir_ifindex;           /* (last) outbound interface */
1311*d8b80295SApple OSS Distributions 	__int32_t       scir_error;             /* most recent error */
1312*d8b80295SApple OSS Distributions 	struct sockaddr *scir_src;              /* source address */
1313*d8b80295SApple OSS Distributions 	socklen_t       scir_src_len;           /* source address len */
1314*d8b80295SApple OSS Distributions 	struct sockaddr *scir_dst;              /* destination address */
1315*d8b80295SApple OSS Distributions 	socklen_t       scir_dst_len;           /* destination address len */
1316*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_type;          /* aux data type (CIAUX) */
1317*d8b80295SApple OSS Distributions 	void            *scir_aux_data;         /* aux data */
1318*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_len;           /* aux data len */
1319*d8b80295SApple OSS Distributions };
1320*d8b80295SApple OSS Distributions 
1321*d8b80295SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
1322*d8b80295SApple OSS Distributions struct so_cinforeq32 {
1323*d8b80295SApple OSS Distributions 	sae_connid_t    scir_cid;
1324*d8b80295SApple OSS Distributions 	__uint32_t      scir_flags;
1325*d8b80295SApple OSS Distributions 	__uint32_t      scir_ifindex;
1326*d8b80295SApple OSS Distributions 	__int32_t       scir_error;
1327*d8b80295SApple OSS Distributions 	user32_addr_t   scir_src;
1328*d8b80295SApple OSS Distributions 	socklen_t       scir_src_len;
1329*d8b80295SApple OSS Distributions 	user32_addr_t   scir_dst;
1330*d8b80295SApple OSS Distributions 	socklen_t       scir_dst_len;
1331*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_type;
1332*d8b80295SApple OSS Distributions 	user32_addr_t   scir_aux_data;
1333*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_len;
1334*d8b80295SApple OSS Distributions };
1335*d8b80295SApple OSS Distributions 
1336*d8b80295SApple OSS Distributions struct so_cinforeq64 {
1337*d8b80295SApple OSS Distributions 	sae_connid_t    scir_cid;
1338*d8b80295SApple OSS Distributions 	__uint32_t      scir_flags;
1339*d8b80295SApple OSS Distributions 	__uint32_t      scir_ifindex;
1340*d8b80295SApple OSS Distributions 	__int32_t       scir_error;
1341*d8b80295SApple OSS Distributions 	user64_addr_t   scir_src        __attribute__((aligned(8)));
1342*d8b80295SApple OSS Distributions 	socklen_t       scir_src_len;
1343*d8b80295SApple OSS Distributions 	user64_addr_t   scir_dst        __attribute__((aligned(8)));
1344*d8b80295SApple OSS Distributions 	socklen_t       scir_dst_len;
1345*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_type;
1346*d8b80295SApple OSS Distributions 	user64_addr_t   scir_aux_data   __attribute__((aligned(8)));
1347*d8b80295SApple OSS Distributions 	__uint32_t      scir_aux_len;
1348*d8b80295SApple OSS Distributions };
1349*d8b80295SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
1350*d8b80295SApple OSS Distributions 
1351*d8b80295SApple OSS Distributions /* valid connection info flags */
1352*d8b80295SApple OSS Distributions #define CIF_CONNECTING          0x1     /* connection was attempted */
1353*d8b80295SApple OSS Distributions #define CIF_CONNECTED           0x2     /* connection is established */
1354*d8b80295SApple OSS Distributions #define CIF_DISCONNECTING       0x4     /* disconnection was attempted */
1355*d8b80295SApple OSS Distributions #define CIF_DISCONNECTED        0x8     /* has been disconnected */
1356*d8b80295SApple OSS Distributions #define CIF_BOUND_IF            0x10    /* bound to an interface */
1357*d8b80295SApple OSS Distributions #define CIF_BOUND_IP            0x20    /* bound to a src address */
1358*d8b80295SApple OSS Distributions #define CIF_BOUND_PORT          0x40    /* bound to a src port */
1359*d8b80295SApple OSS Distributions #define CIF_PREFERRED           0x80    /* connection is primary/preferred */
1360*d8b80295SApple OSS Distributions #define CIF_MP_CAPABLE          0x100   /* supports multipath protocol */
1361*d8b80295SApple OSS Distributions #define CIF_MP_READY            0x200   /* multipath protocol confirmed */
1362*d8b80295SApple OSS Distributions #define CIF_MP_DEGRADED         0x400   /* has lost its multipath capability */
1363*d8b80295SApple OSS Distributions #define CIF_MP_ACTIVE           0x800   /* this is the active subflow */
1364*d8b80295SApple OSS Distributions #define CIF_MP_V1               0x1000  /* MPTCP v1 is used */
1365*d8b80295SApple OSS Distributions 
1366*d8b80295SApple OSS Distributions /* valid connection info auxiliary data types */
1367*d8b80295SApple OSS Distributions #define CIAUX_TCP       0x1     /* TCP auxiliary data (conninfo_tcp_t) */
1368*d8b80295SApple OSS Distributions #define CIAUX_MPTCP     0x2     /* MPTCP auxiliary data (conninfo_multipathtcp) */
1369*d8b80295SApple OSS Distributions 
1370*d8b80295SApple OSS Distributions /*
1371*d8b80295SApple OSS Distributions  * Structure for SIOC{S,G}CONNORDER
1372*d8b80295SApple OSS Distributions  */
1373*d8b80295SApple OSS Distributions struct so_cordreq {
1374*d8b80295SApple OSS Distributions 	sae_connid_t    sco_cid;                /* connection ID */
1375*d8b80295SApple OSS Distributions 	__uint32_t      sco_rank;               /* rank (0 means unspecified) */
1376*d8b80295SApple OSS Distributions };
1377*d8b80295SApple OSS Distributions 
1378*d8b80295SApple OSS Distributions /*
1379*d8b80295SApple OSS Distributions  * Common structure for KEV_NETPOLICY_SUBCLASS
1380*d8b80295SApple OSS Distributions  */
1381*d8b80295SApple OSS Distributions struct netpolicy_event_data {
1382*d8b80295SApple OSS Distributions 	__uint64_t      eupid;          /* effective unique PID */
1383*d8b80295SApple OSS Distributions 	__uint64_t      epid;           /* effective PID */
1384*d8b80295SApple OSS Distributions 	uuid_t          euuid;          /* effective UUID */
1385*d8b80295SApple OSS Distributions };
1386*d8b80295SApple OSS Distributions 
1387*d8b80295SApple OSS Distributions /*
1388*d8b80295SApple OSS Distributions  * NETPOLICY_IFDENIED event structure
1389*d8b80295SApple OSS Distributions  */
1390*d8b80295SApple OSS Distributions struct kev_netpolicy_ifdenied {
1391*d8b80295SApple OSS Distributions 	struct netpolicy_event_data     ev_data;
1392*d8b80295SApple OSS Distributions 	__uint32_t ev_if_functional_type;
1393*d8b80295SApple OSS Distributions };
1394*d8b80295SApple OSS Distributions 
1395*d8b80295SApple OSS Distributions /*
1396*d8b80295SApple OSS Distributions  * KEV_NETPOLICY_NETDENIED event structure
1397*d8b80295SApple OSS Distributions  */
1398*d8b80295SApple OSS Distributions struct kev_netpolicy_netdenied {
1399*d8b80295SApple OSS Distributions 	struct netpolicy_event_data     ev_data;
1400*d8b80295SApple OSS Distributions 	__uint32_t ev_network_type;
1401*d8b80295SApple OSS Distributions };
1402*d8b80295SApple OSS Distributions 
1403*d8b80295SApple OSS Distributions /*
1404*d8b80295SApple OSS Distributions  * Network Service Type to DiffServ Code Point mapping
1405*d8b80295SApple OSS Distributions  */
1406*d8b80295SApple OSS Distributions struct netsvctype_dscp_map {
1407*d8b80295SApple OSS Distributions 	int             netsvctype;
1408*d8b80295SApple OSS Distributions 	u_int8_t        dscp; /* 6 bits diffserv code point */
1409*d8b80295SApple OSS Distributions };
1410*d8b80295SApple OSS Distributions 
1411*d8b80295SApple OSS Distributions /*
1412*d8b80295SApple OSS Distributions  * Multi-layer packet logging require SO_MPK_LOG to be set
1413*d8b80295SApple OSS Distributions  */
1414*d8b80295SApple OSS Distributions struct so_mpkl_send_info {
1415*d8b80295SApple OSS Distributions 	uuid_t          mpkl_uuid;
1416*d8b80295SApple OSS Distributions 	__uint8_t       mpkl_proto;     /* see net/multi_layer_pkt_log.h */
1417*d8b80295SApple OSS Distributions };
1418*d8b80295SApple OSS Distributions 
1419*d8b80295SApple OSS Distributions struct so_mpkl_recv_info {
1420*d8b80295SApple OSS Distributions 	__uint32_t      mpkl_seq;
1421*d8b80295SApple OSS Distributions 	__uint8_t       mpkl_proto;     /* see net/multi_layer_pkt_log.h */
1422*d8b80295SApple OSS Distributions };
1423*d8b80295SApple OSS Distributions 
1424*d8b80295SApple OSS Distributions #ifndef KERNEL
1425*d8b80295SApple OSS Distributions __BEGIN_DECLS
1426*d8b80295SApple OSS Distributions 
1427*d8b80295SApple OSS Distributions extern int peeloff(int s, sae_associd_t);
1428*d8b80295SApple OSS Distributions extern int socket_delegate(int, int, int, pid_t);
1429*d8b80295SApple OSS Distributions 
1430*d8b80295SApple OSS Distributions /*
1431*d8b80295SApple OSS Distributions  * recvmsg_x() is a system call similar to recvmsg(2) to receive
1432*d8b80295SApple OSS Distributions  * several datagrams at once in the array of message headers "msgp".
1433*d8b80295SApple OSS Distributions  *
1434*d8b80295SApple OSS Distributions  * recvmsg_x() can be used only with protocols handlers that have been specially
1435*d8b80295SApple OSS Distributions  * modified to support sending and receiving several datagrams at once.
1436*d8b80295SApple OSS Distributions  *
1437*d8b80295SApple OSS Distributions  * The size of the array "msgp" is given by the argument "cnt".
1438*d8b80295SApple OSS Distributions  *
1439*d8b80295SApple OSS Distributions  * The "flags" arguments supports only the value MSG_DONTWAIT.
1440*d8b80295SApple OSS Distributions  *
1441*d8b80295SApple OSS Distributions  * Each member of "msgp" array is of type "struct msghdr_x".
1442*d8b80295SApple OSS Distributions  *
1443*d8b80295SApple OSS Distributions  * The "msg_iov" and "msg_iovlen" are input parameters that describe where to
1444*d8b80295SApple OSS Distributions  * store a datagram in a scatter gather locations of buffers -- see recvmsg(2).
1445*d8b80295SApple OSS Distributions  * On output the field "msg_datalen" gives the length of the received datagram.
1446*d8b80295SApple OSS Distributions  *
1447*d8b80295SApple OSS Distributions  * The field "msg_flags" must be set to zero on input. On output, "msg_flags"
1448*d8b80295SApple OSS Distributions  * may have MSG_TRUNC set to indicate the trailing portion of the datagram was
1449*d8b80295SApple OSS Distributions  * discarded because the datagram was larger than the buffer supplied.
1450*d8b80295SApple OSS Distributions  * recvmsg_x() returns as soon as a datagram is truncated.
1451*d8b80295SApple OSS Distributions  *
1452*d8b80295SApple OSS Distributions  * recvmsg_x() may return with less than "cnt" datagrams received based on
1453*d8b80295SApple OSS Distributions  * the low water mark and the amount of data pending in the socket buffer.
1454*d8b80295SApple OSS Distributions  *
1455*d8b80295SApple OSS Distributions  * recvmsg_x() returns the number of datagrams that have been received,
1456*d8b80295SApple OSS Distributions  * or -1 if an error occurred.
1457*d8b80295SApple OSS Distributions  *
1458*d8b80295SApple OSS Distributions  * NOTE: This a private system call, the API is subject to change.
1459*d8b80295SApple OSS Distributions  */
1460*d8b80295SApple OSS Distributions ssize_t recvmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags);
1461*d8b80295SApple OSS Distributions 
1462*d8b80295SApple OSS Distributions /*
1463*d8b80295SApple OSS Distributions  * sendmsg_x() is a system call similar to send(2) to send
1464*d8b80295SApple OSS Distributions  * several datagrams at once in the array of message headers "msgp".
1465*d8b80295SApple OSS Distributions  *
1466*d8b80295SApple OSS Distributions  * sendmsg_x() can be used only with protocols handlers that have been specially
1467*d8b80295SApple OSS Distributions  * modified to support sending and receiving several datagrams at once.
1468*d8b80295SApple OSS Distributions  *
1469*d8b80295SApple OSS Distributions  * The size of the array "msgp" is given by the argument "cnt".
1470*d8b80295SApple OSS Distributions  *
1471*d8b80295SApple OSS Distributions  * The "flags" arguments supports only the value MSG_DONTWAIT.
1472*d8b80295SApple OSS Distributions  *
1473*d8b80295SApple OSS Distributions  * Each member of "msgp" array is of type "struct msghdr_x".
1474*d8b80295SApple OSS Distributions  *
1475*d8b80295SApple OSS Distributions  * The "msg_iov" and "msg_iovlen" are input parameters that specify the
1476*d8b80295SApple OSS Distributions  * data to be sent in a scatter gather locations of buffers -- see sendmsg(2).
1477*d8b80295SApple OSS Distributions  *
1478*d8b80295SApple OSS Distributions  * sendmsg_x() fails with EMSGSIZE if the sum of the length of the datagrams
1479*d8b80295SApple OSS Distributions  * is greater than the high water mark.
1480*d8b80295SApple OSS Distributions  *
1481*d8b80295SApple OSS Distributions  * Address and ancillary data are not supported so the following fields
1482*d8b80295SApple OSS Distributions  * must be set to zero on input:
1483*d8b80295SApple OSS Distributions  *   "msg_name", "msg_namelen", "msg_control" and "msg_controllen".
1484*d8b80295SApple OSS Distributions  *
1485*d8b80295SApple OSS Distributions  * The field "msg_flags" and "msg_datalen" must be set to zero on input.
1486*d8b80295SApple OSS Distributions  *
1487*d8b80295SApple OSS Distributions  * sendmsg_x() returns the number of datagrams that have been sent,
1488*d8b80295SApple OSS Distributions  * or -1 if an error occurred.
1489*d8b80295SApple OSS Distributions  *
1490*d8b80295SApple OSS Distributions  * NOTE: This a private system call, the API is subject to change.
1491*d8b80295SApple OSS Distributions  */
1492*d8b80295SApple OSS Distributions ssize_t sendmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags);
1493*d8b80295SApple OSS Distributions __END_DECLS
1494*d8b80295SApple OSS Distributions #endif /* !KERNEL */
1495*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1496*d8b80295SApple OSS Distributions #endif /* PRIVATE */
1497*d8b80295SApple OSS Distributions 
1498*d8b80295SApple OSS Distributions #ifndef KERNEL
1499*d8b80295SApple OSS Distributions __BEGIN_DECLS
1500*d8b80295SApple OSS Distributions 
1501*d8b80295SApple OSS Distributions int     accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
1502*d8b80295SApple OSS Distributions __DARWIN_ALIAS_C(accept);
1503*d8b80295SApple OSS Distributions int     bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
1504*d8b80295SApple OSS Distributions int     connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(connect);
1505*d8b80295SApple OSS Distributions int     getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
1506*d8b80295SApple OSS Distributions __DARWIN_ALIAS(getpeername);
1507*d8b80295SApple OSS Distributions int     getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
1508*d8b80295SApple OSS Distributions __DARWIN_ALIAS(getsockname);
1509*d8b80295SApple OSS Distributions int     getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
1510*d8b80295SApple OSS Distributions int     listen(int, int) __DARWIN_ALIAS(listen);
1511*d8b80295SApple OSS Distributions ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv);
1512*d8b80295SApple OSS Distributions ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
1513*d8b80295SApple OSS Distributions     socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
1514*d8b80295SApple OSS Distributions ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg);
1515*d8b80295SApple OSS Distributions ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);
1516*d8b80295SApple OSS Distributions ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg);
1517*d8b80295SApple OSS Distributions ssize_t sendto(int, const void *, size_t,
1518*d8b80295SApple OSS Distributions     int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto);
1519*d8b80295SApple OSS Distributions int     setsockopt(int, int, int, const void *, socklen_t);
1520*d8b80295SApple OSS Distributions int     shutdown(int, int);
1521*d8b80295SApple OSS Distributions int     sockatmark(int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
1522*d8b80295SApple OSS Distributions int     socket(int, int, int);
1523*d8b80295SApple OSS Distributions int     socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
1524*d8b80295SApple OSS Distributions 
1525*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE)
1526*d8b80295SApple OSS Distributions int     sendfile(int, int, off_t, off_t *, struct sf_hdtr *, int);
1527*d8b80295SApple OSS Distributions #endif  /* !_POSIX_C_SOURCE */
1528*d8b80295SApple OSS Distributions 
1529*d8b80295SApple OSS Distributions #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1530*d8b80295SApple OSS Distributions void    pfctlinput(int, struct sockaddr *);
1531*d8b80295SApple OSS Distributions 
1532*d8b80295SApple OSS Distributions __API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
1533*d8b80295SApple OSS Distributions int connectx(int, const sa_endpoints_t *, sae_associd_t, unsigned int,
1534*d8b80295SApple OSS Distributions     const struct iovec *, unsigned int, size_t *, sae_connid_t *);
1535*d8b80295SApple OSS Distributions 
1536*d8b80295SApple OSS Distributions __API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
1537*d8b80295SApple OSS Distributions int disconnectx(int, sae_associd_t, sae_connid_t);
1538*d8b80295SApple OSS Distributions #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1539*d8b80295SApple OSS Distributions __END_DECLS
1540*d8b80295SApple OSS Distributions #endif /* !KERNEL */
1541*d8b80295SApple OSS Distributions 
1542*d8b80295SApple OSS Distributions #ifdef KERNEL
1543*d8b80295SApple OSS Distributions #include <sys/kpi_socket.h>
1544*d8b80295SApple OSS Distributions #endif
1545*d8b80295SApple OSS Distributions 
1546*d8b80295SApple OSS Distributions #endif /* !_SYS_SOCKET_H_ */
1547