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