xref: /xnu-10002.81.5/bsd/sys/kpi_socket.h (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions /*
2*5e3eaea3SApple OSS Distributions  * Copyright (c) 2008-2017 Apple Inc. All rights reserved.
3*5e3eaea3SApple OSS Distributions  *
4*5e3eaea3SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5e3eaea3SApple OSS Distributions  *
6*5e3eaea3SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*5e3eaea3SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*5e3eaea3SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*5e3eaea3SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*5e3eaea3SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*5e3eaea3SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*5e3eaea3SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*5e3eaea3SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*5e3eaea3SApple OSS Distributions  *
15*5e3eaea3SApple OSS Distributions  * Please obtain a copy of the License at
16*5e3eaea3SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5e3eaea3SApple OSS Distributions  *
18*5e3eaea3SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*5e3eaea3SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5e3eaea3SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5e3eaea3SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5e3eaea3SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5e3eaea3SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*5e3eaea3SApple OSS Distributions  * limitations under the License.
25*5e3eaea3SApple OSS Distributions  *
26*5e3eaea3SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5e3eaea3SApple OSS Distributions  */
28*5e3eaea3SApple OSS Distributions /*!
29*5e3eaea3SApple OSS Distributions  *       @header kpi_socket.h
30*5e3eaea3SApple OSS Distributions  *       This header defines an API for creating and interacting with sockets
31*5e3eaea3SApple OSS Distributions  *       in the kernel. It is possible to create sockets in the kernel
32*5e3eaea3SApple OSS Distributions  *       without an associated file descriptor. In some cases, a reference to
33*5e3eaea3SApple OSS Distributions  *       the socket may be known while the file descriptor is not. These
34*5e3eaea3SApple OSS Distributions  *       functions can be used for interacting with sockets in the kernel.
35*5e3eaea3SApple OSS Distributions  *       The API is similar to the user space socket API.
36*5e3eaea3SApple OSS Distributions  */
37*5e3eaea3SApple OSS Distributions #ifndef __KPI_SOCKET__
38*5e3eaea3SApple OSS Distributions #define __KPI_SOCKET__
39*5e3eaea3SApple OSS Distributions 
40*5e3eaea3SApple OSS Distributions #include <sys/types.h>
41*5e3eaea3SApple OSS Distributions #include <sys/kernel_types.h>
42*5e3eaea3SApple OSS Distributions #include <sys/socket.h>
43*5e3eaea3SApple OSS Distributions 
44*5e3eaea3SApple OSS Distributions #ifndef PRIVATE
45*5e3eaea3SApple OSS Distributions #include <Availability.h>
46*5e3eaea3SApple OSS Distributions #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15))
47*5e3eaea3SApple OSS Distributions #else
48*5e3eaea3SApple OSS Distributions #define __NKE_API_DEPRECATED
49*5e3eaea3SApple OSS Distributions #endif /* PRIVATE */
50*5e3eaea3SApple OSS Distributions 
51*5e3eaea3SApple OSS Distributions __BEGIN_DECLS
52*5e3eaea3SApple OSS Distributions 
53*5e3eaea3SApple OSS Distributions struct timeval;
54*5e3eaea3SApple OSS Distributions 
55*5e3eaea3SApple OSS Distributions /*!
56*5e3eaea3SApple OSS Distributions  *       @typedef sock_upcall
57*5e3eaea3SApple OSS Distributions  *
58*5e3eaea3SApple OSS Distributions  *       @discussion sock_upcall is used by a socket to notify an in kernel
59*5e3eaea3SApple OSS Distributions  *               client that data is waiting. Instead of making blocking calls in
60*5e3eaea3SApple OSS Distributions  *               the kernel, a client can specify an upcall which will be called
61*5e3eaea3SApple OSS Distributions  *               when data is available or the socket is ready for sending.
62*5e3eaea3SApple OSS Distributions  *
63*5e3eaea3SApple OSS Distributions  *               Calls to your upcall function are not serialized and may be
64*5e3eaea3SApple OSS Distributions  *               called concurrently from multiple threads in the kernel.
65*5e3eaea3SApple OSS Distributions  *
66*5e3eaea3SApple OSS Distributions  *               Your upcall function will be called:
67*5e3eaea3SApple OSS Distributions  *                   when there is data more than the low water mark for reading,
68*5e3eaea3SApple OSS Distributions  *                   or when there is space for a write,
69*5e3eaea3SApple OSS Distributions  *                   or when there is a connection to accept,
70*5e3eaea3SApple OSS Distributions  *                   or when a socket is connected,
71*5e3eaea3SApple OSS Distributions  *                   or when a socket is closed or disconnected
72*5e3eaea3SApple OSS Distributions  *
73*5e3eaea3SApple OSS Distributions  *       @param so A reference to the socket that's ready.
74*5e3eaea3SApple OSS Distributions  *       @param cookie The cookie passed in when the socket was created.
75*5e3eaea3SApple OSS Distributions  *       @param waitf Indicates whether or not it's safe to block.
76*5e3eaea3SApple OSS Distributions  */
77*5e3eaea3SApple OSS Distributions typedef void (*sock_upcall)(socket_t so, void *cookie, int waitf);
78*5e3eaea3SApple OSS Distributions 
79*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
80*5e3eaea3SApple OSS Distributions /*!
81*5e3eaea3SApple OSS Distributions  *       @typedef sock_evupcall
82*5e3eaea3SApple OSS Distributions  *
83*5e3eaea3SApple OSS Distributions  *       @discussion sock_evupcall is used by a socket to notify an in kernel
84*5e3eaea3SApple OSS Distributions  *               client when an event occurs. Instead of making blocking calls in
85*5e3eaea3SApple OSS Distributions  *               the kernel, a client can specify an upcall which will be called
86*5e3eaea3SApple OSS Distributions  *               when an event status is available.
87*5e3eaea3SApple OSS Distributions  *       @param so A reference to the socket that's ready.
88*5e3eaea3SApple OSS Distributions  *       @param cookie The cookie passed in when the socket was created.
89*5e3eaea3SApple OSS Distributions  *       @param event Indicates the event as defined by SO_FILT_HINT_*
90*5e3eaea3SApple OSS Distributions  */
91*5e3eaea3SApple OSS Distributions typedef void (*sock_evupcall)(socket_t so, void *cookie, uint32_t event);
92*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
93*5e3eaea3SApple OSS Distributions 
94*5e3eaea3SApple OSS Distributions /*!
95*5e3eaea3SApple OSS Distributions  *       @function sock_accept
96*5e3eaea3SApple OSS Distributions  *       @discussion Accepts an incoming connection on a socket. See 'man 2
97*5e3eaea3SApple OSS Distributions  *               accept' for more information. Allocating a socket in this manner
98*5e3eaea3SApple OSS Distributions  *               creates a socket with no associated file descriptor.
99*5e3eaea3SApple OSS Distributions  *       @param so The listening socket you'd like to accept a connection on.
100*5e3eaea3SApple OSS Distributions  *       @param from A pointer to a socket address that will be filled in
101*5e3eaea3SApple OSS Distributions  *               with the address the connection is from.
102*5e3eaea3SApple OSS Distributions  *       @param fromlen Maximum length of from.
103*5e3eaea3SApple OSS Distributions  *       @param flags Supports MSG_DONTWAIT and MSG_USEUPCALL. If
104*5e3eaea3SApple OSS Distributions  *               MSG_DONTWAIT is set, accept will return EWOULDBLOCK if there are
105*5e3eaea3SApple OSS Distributions  *               no connections ready to be accepted. If MSG_USEUPCALL is set,
106*5e3eaea3SApple OSS Distributions  *               the created socket will use the same upcall function attached to
107*5e3eaea3SApple OSS Distributions  *               the original socket.
108*5e3eaea3SApple OSS Distributions  *       @param callback A notifier function to be called when an event
109*5e3eaea3SApple OSS Distributions  *               occurs on the socket. This may be NULL.
110*5e3eaea3SApple OSS Distributions  *       @param cookie A cookie passed directly to the callback.
111*5e3eaea3SApple OSS Distributions  *       @param new_so Upon success, *new_so will be a reference to a new
112*5e3eaea3SApple OSS Distributions  *               socket for tracking the connection.
113*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
114*5e3eaea3SApple OSS Distributions  */
115*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
116*5e3eaea3SApple OSS Distributions extern errno_t sock_accept_internal(socket_t so, struct sockaddr *from, int fromlen,
117*5e3eaea3SApple OSS Distributions     int flags, sock_upcall callback, void *cookie, socket_t *new_so);
118*5e3eaea3SApple OSS Distributions 
119*5e3eaea3SApple OSS Distributions #define sock_accept(so, from, fromlen, flags, callback, cookie, new_so) \
120*5e3eaea3SApple OSS Distributions 	sock_accept_internal((so), (from), (fromlen), (flags), (callback), \
121*5e3eaea3SApple OSS Distributions 	(cookie), (new_so))
122*5e3eaea3SApple OSS Distributions #else
123*5e3eaea3SApple OSS Distributions extern errno_t sock_accept(socket_t so, struct sockaddr *from, int fromlen,
124*5e3eaea3SApple OSS Distributions     int flags, sock_upcall callback, void *cookie, socket_t *new_so)
125*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
126*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
127*5e3eaea3SApple OSS Distributions 
128*5e3eaea3SApple OSS Distributions /*!
129*5e3eaea3SApple OSS Distributions  *       @function sock_bind
130*5e3eaea3SApple OSS Distributions  *       @discussion Binds a socket to a specific address. See 'man 2 bind'
131*5e3eaea3SApple OSS Distributions  *               for more information.
132*5e3eaea3SApple OSS Distributions  *       @param so The socket to be bound.
133*5e3eaea3SApple OSS Distributions  *       @param to The local address the socket should be bound to.
134*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
135*5e3eaea3SApple OSS Distributions  */
136*5e3eaea3SApple OSS Distributions extern errno_t sock_bind(socket_t so, const struct sockaddr *to)
137*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
138*5e3eaea3SApple OSS Distributions 
139*5e3eaea3SApple OSS Distributions /*!
140*5e3eaea3SApple OSS Distributions  *       @function sock_connect
141*5e3eaea3SApple OSS Distributions  *       @discussion Initiates a connection on the socket. See 'man 2
142*5e3eaea3SApple OSS Distributions  *               connect' for more information.
143*5e3eaea3SApple OSS Distributions  *       @param so The socket to be connect.
144*5e3eaea3SApple OSS Distributions  *       @param to The remote address the socket should connect to.
145*5e3eaea3SApple OSS Distributions  *       @param flags Flags for connecting. The only flag supported so far is
146*5e3eaea3SApple OSS Distributions  *               MSG_DONTWAIT. MSG_DONTWAIT will perform a non-blocking connect.
147*5e3eaea3SApple OSS Distributions  *               sock_connect will return immediately with EINPROGRESS. The
148*5e3eaea3SApple OSS Distributions  *               upcall, if supplied, will be called when the connection is
149*5e3eaea3SApple OSS Distributions  *               completed.
150*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EINPROGRESS for a non-blocking connect that
151*5e3eaea3SApple OSS Distributions  *               has not completed, otherwise the errno error.
152*5e3eaea3SApple OSS Distributions  */
153*5e3eaea3SApple OSS Distributions extern errno_t sock_connect(socket_t so, const struct sockaddr *to, int flags)
154*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
155*5e3eaea3SApple OSS Distributions 
156*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
157*5e3eaea3SApple OSS Distributions /*
158*5e3eaea3SApple OSS Distributions  *       This function was added to support NFS. NFS does something funny,
159*5e3eaea3SApple OSS Distributions  *       setting a short timeout and checking to see if it should abort the
160*5e3eaea3SApple OSS Distributions  *       connect every two seconds. Ideally, NFS would use the upcall to be
161*5e3eaea3SApple OSS Distributions  *       notified when the connect is complete.
162*5e3eaea3SApple OSS Distributions  *
163*5e3eaea3SApple OSS Distributions  *       If you feel you need to use this function, please contact us to
164*5e3eaea3SApple OSS Distributions  *       explain why.
165*5e3eaea3SApple OSS Distributions  *
166*5e3eaea3SApple OSS Distributions  *       @function sock_connectwait
167*5e3eaea3SApple OSS Distributions  *       @discussion Allows a caller to wait on a socket connect.
168*5e3eaea3SApple OSS Distributions  *       @param so The socket being connected.
169*5e3eaea3SApple OSS Distributions  *       @param tv The amount of time to wait.
170*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error. EINPROGRESS will be
171*5e3eaea3SApple OSS Distributions  *               returned if the connection did not complete in the timeout
172*5e3eaea3SApple OSS Distributions  *               specified.
173*5e3eaea3SApple OSS Distributions  */
174*5e3eaea3SApple OSS Distributions extern errno_t sock_connectwait(socket_t so, const struct timeval *tv);
175*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
176*5e3eaea3SApple OSS Distributions 
177*5e3eaea3SApple OSS Distributions /*!
178*5e3eaea3SApple OSS Distributions  *       @function sock_getpeername
179*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves the remote address of a connected socket. See
180*5e3eaea3SApple OSS Distributions  *               'man 2 getpeername'.
181*5e3eaea3SApple OSS Distributions  *       @param so The socket.
182*5e3eaea3SApple OSS Distributions  *       @param peername Storage for the peer name.
183*5e3eaea3SApple OSS Distributions  *       @param peernamelen Length of storage for the peer name.
184*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
185*5e3eaea3SApple OSS Distributions  */
186*5e3eaea3SApple OSS Distributions extern errno_t sock_getpeername(socket_t so, struct sockaddr *peername,
187*5e3eaea3SApple OSS Distributions     int peernamelen)
188*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
189*5e3eaea3SApple OSS Distributions 
190*5e3eaea3SApple OSS Distributions /*!
191*5e3eaea3SApple OSS Distributions  *       @function sock_getsockname
192*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves the local address of a socket. See 'man 2
193*5e3eaea3SApple OSS Distributions  *               getsockname'.
194*5e3eaea3SApple OSS Distributions  *       @param so The socket.
195*5e3eaea3SApple OSS Distributions  *       @param sockname Storage for the local name.
196*5e3eaea3SApple OSS Distributions  *       @param socknamelen Length of storage for the socket name.
197*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
198*5e3eaea3SApple OSS Distributions  */
199*5e3eaea3SApple OSS Distributions extern errno_t sock_getsockname(socket_t so, struct sockaddr *sockname,
200*5e3eaea3SApple OSS Distributions     int socknamelen)
201*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
202*5e3eaea3SApple OSS Distributions 
203*5e3eaea3SApple OSS Distributions /*!
204*5e3eaea3SApple OSS Distributions  *       @function sock_getsockopt
205*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves a socket option. See 'man 2 getsockopt'.
206*5e3eaea3SApple OSS Distributions  *       @param so The socket.
207*5e3eaea3SApple OSS Distributions  *       @param level Level of the socket option.
208*5e3eaea3SApple OSS Distributions  *       @param optname The option name.
209*5e3eaea3SApple OSS Distributions  *       @param optval The option value.
210*5e3eaea3SApple OSS Distributions  *       @param optlen The length of optval, returns the actual length.
211*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
212*5e3eaea3SApple OSS Distributions  */
213*5e3eaea3SApple OSS Distributions extern errno_t sock_getsockopt(socket_t so, int level, int optname,
214*5e3eaea3SApple OSS Distributions     void *optval, int *optlen)
215*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
216*5e3eaea3SApple OSS Distributions 
217*5e3eaea3SApple OSS Distributions /*!
218*5e3eaea3SApple OSS Distributions  *       @function sock_ioctl
219*5e3eaea3SApple OSS Distributions  *       @discussion Performs an ioctl operation on a socket. See 'man 2 ioctl'.
220*5e3eaea3SApple OSS Distributions  *       @param so The socket.
221*5e3eaea3SApple OSS Distributions  *       @param request The ioctl name.
222*5e3eaea3SApple OSS Distributions  *       @param argp The argument.
223*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
224*5e3eaea3SApple OSS Distributions  */
225*5e3eaea3SApple OSS Distributions extern errno_t sock_ioctl(socket_t so, unsigned long request, void *argp)
226*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
227*5e3eaea3SApple OSS Distributions 
228*5e3eaea3SApple OSS Distributions /*!
229*5e3eaea3SApple OSS Distributions  *       @function sock_setsockopt
230*5e3eaea3SApple OSS Distributions  *       @discussion Sets a socket option. See 'man 2 setsockopt'.
231*5e3eaea3SApple OSS Distributions  *       @param so The socket.
232*5e3eaea3SApple OSS Distributions  *       @param level Level of the socket option.
233*5e3eaea3SApple OSS Distributions  *       @param optname The option name.
234*5e3eaea3SApple OSS Distributions  *       @param optval The option value.
235*5e3eaea3SApple OSS Distributions  *       @param optlen The length of optval.
236*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
237*5e3eaea3SApple OSS Distributions  */
238*5e3eaea3SApple OSS Distributions extern errno_t sock_setsockopt(socket_t so, int level, int optname,
239*5e3eaea3SApple OSS Distributions     const void *optval, int optlen)
240*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
241*5e3eaea3SApple OSS Distributions 
242*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
243*5e3eaea3SApple OSS Distributions /*
244*5e3eaea3SApple OSS Distributions  *       This function was added to support AFP setting the traffic class
245*5e3eaea3SApple OSS Distributions  *       for a backup stream within a wireless LAN or over link-local address.
246*5e3eaea3SApple OSS Distributions  *
247*5e3eaea3SApple OSS Distributions  *       If you feel you need to use this function, please contact us to
248*5e3eaea3SApple OSS Distributions  *       explain why.
249*5e3eaea3SApple OSS Distributions  *
250*5e3eaea3SApple OSS Distributions  *       @function sock_settclassopt
251*5e3eaea3SApple OSS Distributions  *       @discussion Allows a caller to set the traffic class.
252*5e3eaea3SApple OSS Distributions  *       @param so The socket.
253*5e3eaea3SApple OSS Distributions  *       @param optval The option value.
254*5e3eaea3SApple OSS Distributions  *       @param optlen The length of optval.
255*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
256*5e3eaea3SApple OSS Distributions  */
257*5e3eaea3SApple OSS Distributions extern errno_t sock_settclassopt(socket_t so, const void* optval, size_t optlen);
258*5e3eaea3SApple OSS Distributions 
259*5e3eaea3SApple OSS Distributions /*
260*5e3eaea3SApple OSS Distributions  *       This function was added to support AFP getting the traffic class
261*5e3eaea3SApple OSS Distributions  *       set on a stream.
262*5e3eaea3SApple OSS Distributions  *
263*5e3eaea3SApple OSS Distributions  *       This is also a private API, please contact us if you need to use it.
264*5e3eaea3SApple OSS Distributions  *
265*5e3eaea3SApple OSS Distributions  *       @function sockgettclassopt
266*5e3eaea3SApple OSS Distributions  *       @discussion Allows a caller to get the traffic class.
267*5e3eaea3SApple OSS Distributions  *       @param so The socket.
268*5e3eaea3SApple OSS Distributions  *       @param optval The option value.
269*5e3eaea3SApple OSS Distributions  *       @param optlen The length of optval, returns the actual length.
270*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
271*5e3eaea3SApple OSS Distributions  */
272*5e3eaea3SApple OSS Distributions extern errno_t sock_gettclassopt(socket_t so, void* optval, size_t* optlen);
273*5e3eaea3SApple OSS Distributions 
274*5e3eaea3SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
275*5e3eaea3SApple OSS Distributions extern void socket_set_traffic_mgt_flags_locked(socket_t so, u_int8_t flags);
276*5e3eaea3SApple OSS Distributions extern void socket_clear_traffic_mgt_flags_locked(socket_t so, u_int8_t flags);
277*5e3eaea3SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
278*5e3eaea3SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
279*5e3eaea3SApple OSS Distributions extern void socket_set_traffic_mgt_flags(socket_t so, u_int8_t flags);
280*5e3eaea3SApple OSS Distributions extern void socket_clear_traffic_mgt_flags(socket_t so, u_int8_t flags);
281*5e3eaea3SApple OSS Distributions extern errno_t socket_defunct(struct proc *, socket_t so, int);
282*5e3eaea3SApple OSS Distributions extern errno_t sock_receive_internal(socket_t, struct msghdr *, mbuf_t *,
283*5e3eaea3SApple OSS Distributions     int, size_t *);
284*5e3eaea3SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
285*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
286*5e3eaea3SApple OSS Distributions 
287*5e3eaea3SApple OSS Distributions /*!
288*5e3eaea3SApple OSS Distributions  *       @function sock_listen
289*5e3eaea3SApple OSS Distributions  *       @discussion Indicate that the socket should start accepting incoming
290*5e3eaea3SApple OSS Distributions  *               connections. See 'man 2 listen'.
291*5e3eaea3SApple OSS Distributions  *       @param so The socket.
292*5e3eaea3SApple OSS Distributions  *       @param backlog The maximum length of the queue of pending connections.
293*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
294*5e3eaea3SApple OSS Distributions  */
295*5e3eaea3SApple OSS Distributions extern errno_t sock_listen(socket_t so, int backlog)
296*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
297*5e3eaea3SApple OSS Distributions 
298*5e3eaea3SApple OSS Distributions /*!
299*5e3eaea3SApple OSS Distributions  *       @function sock_receive
300*5e3eaea3SApple OSS Distributions  *       @discussion Receive data from a socket. Similar to recvmsg. See 'man
301*5e3eaea3SApple OSS Distributions  *               2 recvmsg' for more information about receiving data.
302*5e3eaea3SApple OSS Distributions  *       @param so The socket.
303*5e3eaea3SApple OSS Distributions  *       @param msg The msg describing how the data should be received.
304*5e3eaea3SApple OSS Distributions  *       @param flags See 'man 2 recvmsg'.
305*5e3eaea3SApple OSS Distributions  *       @param recvdlen Number of bytes received, same as return value of
306*5e3eaea3SApple OSS Distributions  *               userland recvmsg.
307*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EWOULDBLOCK if non-blocking and operation
308*5e3eaea3SApple OSS Distributions  *               would cause the thread to block, otherwise the errno error.
309*5e3eaea3SApple OSS Distributions  */
310*5e3eaea3SApple OSS Distributions extern errno_t sock_receive(socket_t so, struct msghdr *msg, int flags,
311*5e3eaea3SApple OSS Distributions     size_t *recvdlen)
312*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
313*5e3eaea3SApple OSS Distributions 
314*5e3eaea3SApple OSS Distributions /*!
315*5e3eaea3SApple OSS Distributions  *       @function sock_receivembuf
316*5e3eaea3SApple OSS Distributions  *       @discussion Receive data from a socket. Similar to sock_receive
317*5e3eaea3SApple OSS Distributions  *               though data is returned as a chain of mbufs. See 'man 2 recvmsg'
318*5e3eaea3SApple OSS Distributions  *               for more information about receiving data.
319*5e3eaea3SApple OSS Distributions  *       @param so The socket.
320*5e3eaea3SApple OSS Distributions  *       @param msg The msg describing how the data should be received. May
321*5e3eaea3SApple OSS Distributions  *               be NULL. The msg_iov is ignored.
322*5e3eaea3SApple OSS Distributions  *       @param data Upon return *data will be a reference to an mbuf chain
323*5e3eaea3SApple OSS Distributions  *               containing the data received. This eliminates copying the data
324*5e3eaea3SApple OSS Distributions  *               out of the mbufs. Caller is responsible for freeing the mbufs.
325*5e3eaea3SApple OSS Distributions  *       @param flags See 'man 2 recvmsg'.
326*5e3eaea3SApple OSS Distributions  *       @param recvlen Maximum number of bytes to receive in the mbuf chain.
327*5e3eaea3SApple OSS Distributions  *               Upon return, this value will be set to the number of bytes
328*5e3eaea3SApple OSS Distributions  *               received, same as return value of userland recvmsg.
329*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EWOULDBLOCK if non-blocking and operation
330*5e3eaea3SApple OSS Distributions  *               would cause the thread to block, otherwise the errno error.
331*5e3eaea3SApple OSS Distributions  */
332*5e3eaea3SApple OSS Distributions extern errno_t sock_receivembuf(socket_t so, struct msghdr *msg, mbuf_t *data,
333*5e3eaea3SApple OSS Distributions     int flags, size_t *recvlen)
334*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
335*5e3eaea3SApple OSS Distributions 
336*5e3eaea3SApple OSS Distributions /*!
337*5e3eaea3SApple OSS Distributions  *       @function sock_send
338*5e3eaea3SApple OSS Distributions  *       @discussion Send data on a socket. Similar to sendmsg. See 'man 2
339*5e3eaea3SApple OSS Distributions  *               sendmsg' for more information about sending data.
340*5e3eaea3SApple OSS Distributions  *       @param so The socket.
341*5e3eaea3SApple OSS Distributions  *       @param msg The msg describing how the data should be sent. Any
342*5e3eaea3SApple OSS Distributions  *               pointers must point to data in the kernel.
343*5e3eaea3SApple OSS Distributions  *       @param flags See 'man 2 sendmsg'.
344*5e3eaea3SApple OSS Distributions  *       @param sentlen The number of bytes sent.
345*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EWOULDBLOCK if non-blocking and operation
346*5e3eaea3SApple OSS Distributions  *               would cause the thread to block, otherwise the errno error.
347*5e3eaea3SApple OSS Distributions  */
348*5e3eaea3SApple OSS Distributions extern errno_t sock_send(socket_t so, const struct msghdr *msg, int flags,
349*5e3eaea3SApple OSS Distributions     size_t *sentlen)
350*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
351*5e3eaea3SApple OSS Distributions 
352*5e3eaea3SApple OSS Distributions /*!
353*5e3eaea3SApple OSS Distributions  *       @function sock_sendmbuf
354*5e3eaea3SApple OSS Distributions  *       @discussion Send data in an mbuf on a socket. Similar to sock_send
355*5e3eaea3SApple OSS Distributions  *               only the data to be sent is taken from the mbuf chain.
356*5e3eaea3SApple OSS Distributions  *       @param so The socket.
357*5e3eaea3SApple OSS Distributions  *       @param msg The msg describing how the data should be sent. The
358*5e3eaea3SApple OSS Distributions  *               msg_iov is ignored. msg may be NULL.
359*5e3eaea3SApple OSS Distributions  *       @param data The mbuf chain of data to send.
360*5e3eaea3SApple OSS Distributions  *       @param flags See 'man 2 sendmsg'.
361*5e3eaea3SApple OSS Distributions  *       @param sentlen The number of bytes sent.
362*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EWOULDBLOCK if non-blocking and operation
363*5e3eaea3SApple OSS Distributions  *               would cause the thread to block, otherwise the errno error.
364*5e3eaea3SApple OSS Distributions  *               Regardless of return value, the mbuf chain 'data' will be freed.
365*5e3eaea3SApple OSS Distributions  */
366*5e3eaea3SApple OSS Distributions extern errno_t sock_sendmbuf(socket_t so, const struct msghdr *msg, mbuf_t data,
367*5e3eaea3SApple OSS Distributions     int flags, size_t *sentlen)
368*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
369*5e3eaea3SApple OSS Distributions 
370*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
371*5e3eaea3SApple OSS Distributions /*!
372*5e3eaea3SApple OSS Distributions  *       @function sock_sendmbuf_can_wait
373*5e3eaea3SApple OSS Distributions  *       @discussion Variation of sock_sendmbuf that can wait for the send socket
374*5e3eaea3SApple OSS Distributions  *               buffer to drain when it is full instead of returning EMSGSIZE.
375*5e3eaea3SApple OSS Distributions  *       @param so The socket.
376*5e3eaea3SApple OSS Distributions  *       @param msg The msg describing how the data should be sent. The
377*5e3eaea3SApple OSS Distributions  *               msg_iov is ignored. msg may be NULL.
378*5e3eaea3SApple OSS Distributions  *       @param data The mbuf chain of data to send.
379*5e3eaea3SApple OSS Distributions  *       @param flags See 'man 2 sendmsg'.
380*5e3eaea3SApple OSS Distributions  *       @param sentlen The number of bytes sent.
381*5e3eaea3SApple OSS Distributions  *       @result 0 on success, EWOULDBLOCK if non-blocking and operation
382*5e3eaea3SApple OSS Distributions  *               would cause the thread to block, otherwise the errno error.
383*5e3eaea3SApple OSS Distributions  *               Regardless of return value, the mbuf chain 'data' will be freed.
384*5e3eaea3SApple OSS Distributions  */
385*5e3eaea3SApple OSS Distributions extern errno_t sock_sendmbuf_can_wait(socket_t so, const struct msghdr *msg, mbuf_t data,
386*5e3eaea3SApple OSS Distributions     int flags, size_t *sentlen);
387*5e3eaea3SApple OSS Distributions #define HAS_SOCK_SENDMBUF_CAN_WAIT 1
388*5e3eaea3SApple OSS Distributions 
389*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
390*5e3eaea3SApple OSS Distributions 
391*5e3eaea3SApple OSS Distributions /*!
392*5e3eaea3SApple OSS Distributions  *       @function sock_shutdown
393*5e3eaea3SApple OSS Distributions  *       @discussion Shutdown one or both directions of a connection. See
394*5e3eaea3SApple OSS Distributions  *               'man 2 shutdown' for more information.
395*5e3eaea3SApple OSS Distributions  *       @param so The socket.
396*5e3eaea3SApple OSS Distributions  *       @param how SHUT_RD - shutdown receive.
397*5e3eaea3SApple OSS Distributions  *               SHUT_WR - shutdown send.
398*5e3eaea3SApple OSS Distributions  *               SHUT_RDWR - shutdown both.
399*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
400*5e3eaea3SApple OSS Distributions  */
401*5e3eaea3SApple OSS Distributions extern errno_t sock_shutdown(socket_t so, int how)
402*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
403*5e3eaea3SApple OSS Distributions 
404*5e3eaea3SApple OSS Distributions /*!
405*5e3eaea3SApple OSS Distributions  *       @function sock_socket
406*5e3eaea3SApple OSS Distributions  *       @discussion Allocate a socket. Allocating a socket in this manner
407*5e3eaea3SApple OSS Distributions  *               creates a socket with no associated file descriptor. For more
408*5e3eaea3SApple OSS Distributions  *               information, see 'man 2 socket'.
409*5e3eaea3SApple OSS Distributions  *       @param domain The socket domain (PF_INET, etc...).
410*5e3eaea3SApple OSS Distributions  *       @param type The socket type (SOCK_STREAM, SOCK_DGRAM, etc...).
411*5e3eaea3SApple OSS Distributions  *       @param protocol The socket protocol.
412*5e3eaea3SApple OSS Distributions  *       @param callback A notifier function to be called when an event
413*5e3eaea3SApple OSS Distributions  *               occurs on the socket. This may be NULL.
414*5e3eaea3SApple OSS Distributions  *       @param cookie A cookie passed directly to the callback.
415*5e3eaea3SApple OSS Distributions  *       @param new_so Upon success, a reference to the new socket.
416*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
417*5e3eaea3SApple OSS Distributions  */
418*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
419*5e3eaea3SApple OSS Distributions extern errno_t sock_socket_internal(int domain, int type, int protocol,
420*5e3eaea3SApple OSS Distributions     sock_upcall callback, void *cookie, socket_t *new_so);
421*5e3eaea3SApple OSS Distributions 
422*5e3eaea3SApple OSS Distributions #define sock_socket(domain, type, protocol, callback, cookie, new_so) \
423*5e3eaea3SApple OSS Distributions 	sock_socket_internal((domain), (type), (protocol), \
424*5e3eaea3SApple OSS Distributions 	(callback), (cookie), (new_so))
425*5e3eaea3SApple OSS Distributions #else
426*5e3eaea3SApple OSS Distributions extern errno_t sock_socket(int domain, int type, int protocol,
427*5e3eaea3SApple OSS Distributions     sock_upcall callback, void *cookie, socket_t *new_so)
428*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
429*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
430*5e3eaea3SApple OSS Distributions 
431*5e3eaea3SApple OSS Distributions /*!
432*5e3eaea3SApple OSS Distributions  *       @function sock_close
433*5e3eaea3SApple OSS Distributions  *       @discussion Close the socket.
434*5e3eaea3SApple OSS Distributions  *       @param so The socket to close. This should only ever be a socket
435*5e3eaea3SApple OSS Distributions  *               created with sock_socket. Closing a socket created in user space
436*5e3eaea3SApple OSS Distributions  *               using sock_close may leave a file descriptor pointing to the
437*5e3eaea3SApple OSS Distributions  *               closed socket, resulting in undefined behavior.
438*5e3eaea3SApple OSS Distributions  */
439*5e3eaea3SApple OSS Distributions extern void sock_close(socket_t so)
440*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
441*5e3eaea3SApple OSS Distributions 
442*5e3eaea3SApple OSS Distributions /*
443*5e3eaea3SApple OSS Distributions  *       @function sock_retain
444*5e3eaea3SApple OSS Distributions  *       @discussion Prevents the socket from closing
445*5e3eaea3SApple OSS Distributions  *       @param so The socket to close.  Increment a retain count on the
446*5e3eaea3SApple OSS Distributions  *               socket, preventing it from being closed when sock_close is
447*5e3eaea3SApple OSS Distributions  *               called. This is used when a File Descriptor is passed (and
448*5e3eaea3SApple OSS Distributions  *               closed) from userland and the kext wants to keep ownership of
449*5e3eaea3SApple OSS Distributions  *               that socket. It is used in conjunction with
450*5e3eaea3SApple OSS Distributions  *               sock_release(socket_t so).
451*5e3eaea3SApple OSS Distributions  */
452*5e3eaea3SApple OSS Distributions extern void sock_retain(socket_t so)
453*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
454*5e3eaea3SApple OSS Distributions 
455*5e3eaea3SApple OSS Distributions /*
456*5e3eaea3SApple OSS Distributions  *       @function sock_release
457*5e3eaea3SApple OSS Distributions  *       @discussion Decrement the retain count and close the socket if the
458*5e3eaea3SApple OSS Distributions  *               retain count reaches zero.
459*5e3eaea3SApple OSS Distributions  *       @param so The socket to release. This is used to release ownership
460*5e3eaea3SApple OSS Distributions  *               on a socket acquired with sock_retain. When the last retain
461*5e3eaea3SApple OSS Distributions  *               count is reached, this will call sock_close to close the socket.
462*5e3eaea3SApple OSS Distributions  */
463*5e3eaea3SApple OSS Distributions extern void sock_release(socket_t so)
464*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
465*5e3eaea3SApple OSS Distributions 
466*5e3eaea3SApple OSS Distributions /*!
467*5e3eaea3SApple OSS Distributions  *       @function sock_setpriv
468*5e3eaea3SApple OSS Distributions  *       @discussion Set the privileged bit in the socket. Allows for
469*5e3eaea3SApple OSS Distributions  *               operations that require root privileges.
470*5e3eaea3SApple OSS Distributions  *       @param so The socket on which to modify the SS_PRIV flag.
471*5e3eaea3SApple OSS Distributions  *       @param on Indicate whether or not the SS_PRIV flag should be set.
472*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
473*5e3eaea3SApple OSS Distributions  */
474*5e3eaea3SApple OSS Distributions extern errno_t sock_setpriv(socket_t so, int on)
475*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
476*5e3eaea3SApple OSS Distributions 
477*5e3eaea3SApple OSS Distributions /*!
478*5e3eaea3SApple OSS Distributions  *       @function sock_isconnected
479*5e3eaea3SApple OSS Distributions  *       @discussion Returns whether or not the socket is connected.
480*5e3eaea3SApple OSS Distributions  *       @param so The socket to check.
481*5e3eaea3SApple OSS Distributions  *       @result 0 - socket is not connected. 1 - socket is connected.
482*5e3eaea3SApple OSS Distributions  */
483*5e3eaea3SApple OSS Distributions extern int sock_isconnected(socket_t so)
484*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
485*5e3eaea3SApple OSS Distributions 
486*5e3eaea3SApple OSS Distributions /*!
487*5e3eaea3SApple OSS Distributions  *       @function sock_isnonblocking
488*5e3eaea3SApple OSS Distributions  *       @discussion Returns whether or not the socket is non-blocking. In
489*5e3eaea3SApple OSS Distributions  *               the context of this KPI, non-blocking means that functions to
490*5e3eaea3SApple OSS Distributions  *               perform operations on a socket will not wait for completion.
491*5e3eaea3SApple OSS Distributions  *
492*5e3eaea3SApple OSS Distributions  *               To enable or disable blocking, use the FIONBIO ioctl. The
493*5e3eaea3SApple OSS Distributions  *               parameter is an int. If the int is zero, the socket will block.
494*5e3eaea3SApple OSS Distributions  *               If the parameter is non-zero, the socket will not block.
495*5e3eaea3SApple OSS Distributions  *       @result 0 - socket will block. 1 - socket will not block.
496*5e3eaea3SApple OSS Distributions  */
497*5e3eaea3SApple OSS Distributions extern int sock_isnonblocking(socket_t so)
498*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
499*5e3eaea3SApple OSS Distributions 
500*5e3eaea3SApple OSS Distributions /*!
501*5e3eaea3SApple OSS Distributions  *       @function sock_gettype
502*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves information about the socket. This is the same
503*5e3eaea3SApple OSS Distributions  *               information that was used to create the socket. If any of the
504*5e3eaea3SApple OSS Distributions  *               parameters following so are NULL, that information is not
505*5e3eaea3SApple OSS Distributions  *               retrieved.
506*5e3eaea3SApple OSS Distributions  *       @param so The socket to check.
507*5e3eaea3SApple OSS Distributions  *       @param domain The domain of the socket (PF_INET, ...). May be NULL.
508*5e3eaea3SApple OSS Distributions  *       @param type The socket type (SOCK_STREAM, SOCK_DGRAM, ...). May be NULL.
509*5e3eaea3SApple OSS Distributions  *       @param protocol The socket protocol. May be NULL.
510*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
511*5e3eaea3SApple OSS Distributions  */
512*5e3eaea3SApple OSS Distributions extern errno_t sock_gettype(socket_t so, int *domain, int *type, int *protocol)
513*5e3eaea3SApple OSS Distributions __NKE_API_DEPRECATED;
514*5e3eaea3SApple OSS Distributions 
515*5e3eaea3SApple OSS Distributions #ifdef KERNEL_PRIVATE
516*5e3eaea3SApple OSS Distributions /*
517*5e3eaea3SApple OSS Distributions  *       @function sock_nointerrupt
518*5e3eaea3SApple OSS Distributions  *       @discussion Disables interrupt on socket buffers (sets SB_NOINTR on
519*5e3eaea3SApple OSS Distributions  *               send and receive socket buffers).
520*5e3eaea3SApple OSS Distributions  *       @param so The socket to modify.
521*5e3eaea3SApple OSS Distributions  *       @param on Indicate whether or not the SB_NOINTR flag should be set.
522*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
523*5e3eaea3SApple OSS Distributions  */
524*5e3eaea3SApple OSS Distributions extern errno_t sock_nointerrupt(socket_t so, int on);
525*5e3eaea3SApple OSS Distributions 
526*5e3eaea3SApple OSS Distributions /*
527*5e3eaea3SApple OSS Distributions  *       @function sock_getlistener
528*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves the listening socket of a pre-accepted socket,
529*5e3eaea3SApple OSS Distributions  *               i.e. a socket which is still in the incomplete/completed list.
530*5e3eaea3SApple OSS Distributions  *               Once a socket has been accepted, the information pertaining
531*5e3eaea3SApple OSS Distributions  *               to its listener is no longer available.  Therefore, modules
532*5e3eaea3SApple OSS Distributions  *               interested in finding out the listening socket should install
533*5e3eaea3SApple OSS Distributions  *               the appropriate socket filter callback (sf_attach) which gets
534*5e3eaea3SApple OSS Distributions  *               invoked prior to the socket being fully accepted, and call
535*5e3eaea3SApple OSS Distributions  *               this routine at such a time to obtain the listener.  Callers
536*5e3eaea3SApple OSS Distributions  *               are guaranteed that the listener socket will not go away
537*5e3eaea3SApple OSS Distributions  *               during the sf_attach callback, and therefore the value is
538*5e3eaea3SApple OSS Distributions  *               safe to be used only in that callback context.  Callers should
539*5e3eaea3SApple OSS Distributions  *               therefore take note that the listening socket's lock will be
540*5e3eaea3SApple OSS Distributions  *               held throughout the duration of the callback.
541*5e3eaea3SApple OSS Distributions  *       @param so The pre-accepted socket.
542*5e3eaea3SApple OSS Distributions  *       @result Non-NULL value which indicates the listening socket; otherwise,
543*5e3eaea3SApple OSS Distributions  *               NULL if the socket is not in the incomplete/completed list
544*5e3eaea3SApple OSS Distributions  *               of a listener.
545*5e3eaea3SApple OSS Distributions  */
546*5e3eaea3SApple OSS Distributions extern socket_t sock_getlistener(socket_t so);
547*5e3eaea3SApple OSS Distributions 
548*5e3eaea3SApple OSS Distributions /*
549*5e3eaea3SApple OSS Distributions  *       @function sock_getaddr
550*5e3eaea3SApple OSS Distributions  *       @discussion Retrieves the local or remote address of a socket.
551*5e3eaea3SApple OSS Distributions  *               This is a composite of sock_getpeername and sock_getsockname,
552*5e3eaea3SApple OSS Distributions  *               except that the allocated socket address is returned to the
553*5e3eaea3SApple OSS Distributions  *               caller, and that the caller is reponsible for calling
554*5e3eaea3SApple OSS Distributions  *               sock_freeaddr once finished with it.
555*5e3eaea3SApple OSS Distributions  *       @param so The socket.
556*5e3eaea3SApple OSS Distributions  *       @param psockname Pointer to the storage for the socket name.
557*5e3eaea3SApple OSS Distributions  *       @param peername 0 for local address, and non-zero for peer address.
558*5e3eaea3SApple OSS Distributions  *       @result 0 on success otherwise the errno error.
559*5e3eaea3SApple OSS Distributions  */
560*5e3eaea3SApple OSS Distributions extern errno_t sock_getaddr(socket_t so, struct sockaddr **psockname,
561*5e3eaea3SApple OSS Distributions     int peername);
562*5e3eaea3SApple OSS Distributions 
563*5e3eaea3SApple OSS Distributions /*
564*5e3eaea3SApple OSS Distributions  *       @function sock_freeaddr
565*5e3eaea3SApple OSS Distributions  *       @discussion Frees the socket address allocated by sock_getaddr.
566*5e3eaea3SApple OSS Distributions  *       @param sockname The socket name to be freed.
567*5e3eaea3SApple OSS Distributions  */
568*5e3eaea3SApple OSS Distributions extern void sock_freeaddr(struct sockaddr *sockname);
569*5e3eaea3SApple OSS Distributions 
570*5e3eaea3SApple OSS Distributions /*
571*5e3eaea3SApple OSS Distributions  *       @function sock_setupcall
572*5e3eaea3SApple OSS Distributions  *       @discussion Set the notifier function to be called when an event
573*5e3eaea3SApple OSS Distributions  *               occurs on the socket. This may be set to NULL to disable
574*5e3eaea3SApple OSS Distributions  *               further notifications. Setting the function does not
575*5e3eaea3SApple OSS Distributions  *               affect currently notifications about to be sent or being sent.
576*5e3eaea3SApple OSS Distributions  *               Note: When this function is used on a socket passed from
577*5e3eaea3SApple OSS Distributions  *               userspace it is crucial to call sock_retain() on the socket
578*5e3eaea3SApple OSS Distributions  *               otherwise a callback could be dispatched on a closed socket
579*5e3eaea3SApple OSS Distributions  *               and cause a crash.
580*5e3eaea3SApple OSS Distributions  *       @param sock The socket.
581*5e3eaea3SApple OSS Distributions  *       @param callback The notifier function
582*5e3eaea3SApple OSS Distributions  *       @param context A cookie passed directly to the callback
583*5e3eaea3SApple OSS Distributions  */
584*5e3eaea3SApple OSS Distributions extern errno_t sock_setupcall(socket_t sock, sock_upcall callback,
585*5e3eaea3SApple OSS Distributions     void *context);
586*5e3eaea3SApple OSS Distributions 
587*5e3eaea3SApple OSS Distributions /*
588*5e3eaea3SApple OSS Distributions  *       @function sock_setupcalls
589*5e3eaea3SApple OSS Distributions  *       @discussion Set the notifier function to be called when an event
590*5e3eaea3SApple OSS Distributions  *               occurs on the socket. This may be set to NULL to disable
591*5e3eaea3SApple OSS Distributions  *               further notifications. Setting the function does not
592*5e3eaea3SApple OSS Distributions  *               affect currently notifications about to be sent or being sent.
593*5e3eaea3SApple OSS Distributions  *               Note: When this function is used on a socket passed from
594*5e3eaea3SApple OSS Distributions  *               userspace it is crucial to call sock_retain() on the socket
595*5e3eaea3SApple OSS Distributions  *               otherwise a callback could be dispatched on a closed socket
596*5e3eaea3SApple OSS Distributions  *               and cause a crash.
597*5e3eaea3SApple OSS Distributions  *       @param sock The socket.
598*5e3eaea3SApple OSS Distributions  *       @param read_callback The read notifier function
599*5e3eaea3SApple OSS Distributions  *       @param read_context A cookie passed directly to the read callback
600*5e3eaea3SApple OSS Distributions  *       @param write_callback The write notifier function
601*5e3eaea3SApple OSS Distributions  *       @param write_context A cookie passed directly to the write callback
602*5e3eaea3SApple OSS Distributions  */
603*5e3eaea3SApple OSS Distributions extern errno_t sock_setupcalls(socket_t sock, sock_upcall read_callback,
604*5e3eaea3SApple OSS Distributions     void *read_context, sock_upcall write_callback, void *write_context);
605*5e3eaea3SApple OSS Distributions 
606*5e3eaea3SApple OSS Distributions /*
607*5e3eaea3SApple OSS Distributions  *       @function sock_setupcalls_locked
608*5e3eaea3SApple OSS Distributions  *       @discussion The locked version of sock_setupcalls
609*5e3eaea3SApple OSS Distributions  *       @param locked: When sets, indicates that the callbacks expect to be
610*5e3eaea3SApple OSS Distributions  *                      on a locked socket. Thus, no unlock is done prior to
611*5e3eaea3SApple OSS Distributions  *                      calling the callback.
612*5e3eaea3SApple OSS Distributions  */
613*5e3eaea3SApple OSS Distributions extern void sock_setupcalls_locked(socket_t sock,
614*5e3eaea3SApple OSS Distributions     sock_upcall rcallback, void *rcontext,
615*5e3eaea3SApple OSS Distributions     sock_upcall wcallback, void *wcontext, int locked);
616*5e3eaea3SApple OSS Distributions 
617*5e3eaea3SApple OSS Distributions /*
618*5e3eaea3SApple OSS Distributions  *       @function sock_catchevents
619*5e3eaea3SApple OSS Distributions  *       @discussion Set the notifier function to be called when an event
620*5e3eaea3SApple OSS Distributions  *               occurs on the socket. This may be set to NULL to disable
621*5e3eaea3SApple OSS Distributions  *               further notifications. Setting the function does not
622*5e3eaea3SApple OSS Distributions  *               affect currently notifications about to be sent or being sent.
623*5e3eaea3SApple OSS Distributions  *       @param sock The socket.
624*5e3eaea3SApple OSS Distributions  *       @param event_callback The event notifier function
625*5e3eaea3SApple OSS Distributions  *       @param event_context A cookie passed directly to the event callback
626*5e3eaea3SApple OSS Distributions  *       @param event_mask One or more SO_FILT_HINT_* values OR'ed together,
627*5e3eaea3SApple OSS Distributions  *               indicating the registered event(s).
628*5e3eaea3SApple OSS Distributions  */
629*5e3eaea3SApple OSS Distributions extern errno_t sock_catchevents(socket_t sock, sock_evupcall event_callback,
630*5e3eaea3SApple OSS Distributions     void *event_context, uint32_t event_mask);
631*5e3eaea3SApple OSS Distributions 
632*5e3eaea3SApple OSS Distributions extern void sock_catchevents_locked(socket_t sock, sock_evupcall ecallback,
633*5e3eaea3SApple OSS Distributions     void *econtext, uint32_t emask);
634*5e3eaea3SApple OSS Distributions 
635*5e3eaea3SApple OSS Distributions 
636*5e3eaea3SApple OSS Distributions /*
637*5e3eaea3SApple OSS Distributions  *       @function sock_iskernel
638*5e3eaea3SApple OSS Distributions  *       @discussion Returns true if the socket was created by the kernel or
639*5e3eaea3SApple OSS Distributions  *               is owned by the kernel.
640*5e3eaea3SApple OSS Distributions  *       @param sock The socket.
641*5e3eaea3SApple OSS Distributions  *       @result True if the kernel owns the socket.
642*5e3eaea3SApple OSS Distributions  */
643*5e3eaea3SApple OSS Distributions extern int sock_iskernel(socket_t);
644*5e3eaea3SApple OSS Distributions #endif /* KERNEL_PRIVATE */
645*5e3eaea3SApple OSS Distributions 
646*5e3eaea3SApple OSS Distributions __END_DECLS
647*5e3eaea3SApple OSS Distributions #undef __NKE_API_DEPRECATED
648*5e3eaea3SApple OSS Distributions #endif /* __KPI_SOCKET__ */
649