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