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