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