1*33de042dSApple OSS Distributions /* 2*33de042dSApple OSS Distributions * Copyright (c) 2008-2021 Apple Computer, Inc. All rights reserved. 3*33de042dSApple OSS Distributions * 4*33de042dSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*33de042dSApple OSS Distributions * 6*33de042dSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*33de042dSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*33de042dSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*33de042dSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*33de042dSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*33de042dSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*33de042dSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*33de042dSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*33de042dSApple OSS Distributions * 15*33de042dSApple OSS Distributions * Please obtain a copy of the License at 16*33de042dSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*33de042dSApple OSS Distributions * 18*33de042dSApple OSS Distributions * The Original Code and all software distributed under the License are 19*33de042dSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*33de042dSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*33de042dSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*33de042dSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*33de042dSApple OSS Distributions * Please see the License for the specific language governing rights and 24*33de042dSApple OSS Distributions * limitations under the License. 25*33de042dSApple OSS Distributions * 26*33de042dSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*33de042dSApple OSS Distributions */ 28*33de042dSApple OSS Distributions /*! 29*33de042dSApple OSS Distributions * @header kpi_socketfilter.h 30*33de042dSApple OSS Distributions * This header defines an API for intercepting communications at the 31*33de042dSApple OSS Distributions * socket layer. 32*33de042dSApple OSS Distributions * 33*33de042dSApple OSS Distributions * For the most part, socket filters want to do three things: Filter 34*33de042dSApple OSS Distributions * data in and out, watch for state changes, and intercept a few calls 35*33de042dSApple OSS Distributions * for security. The number of function pointers supplied by a socket 36*33de042dSApple OSS Distributions * filter has been significantly reduced. The filter no longer has any 37*33de042dSApple OSS Distributions * knowledge of socket buffers. The filter no longer intercepts nearly 38*33de042dSApple OSS Distributions * every internal socket call. There are two data filters, an in 39*33de042dSApple OSS Distributions * filter, and an out filter. The in filter occurs before data is 40*33de042dSApple OSS Distributions * placed in the receive socket buffer. This is done to avoid waking 41*33de042dSApple OSS Distributions * the process unnecessarily. The out filter occurs before the data is 42*33de042dSApple OSS Distributions * appended to the send socket buffer. This should cover inbound and 43*33de042dSApple OSS Distributions * outbound data. For monitoring state changes, we've added a notify 44*33de042dSApple OSS Distributions * function that will be called when various events that the filter can 45*33de042dSApple OSS Distributions * not intercept occur. In addition, we've added a few functions that a 46*33de042dSApple OSS Distributions * filter may use to intercept common operations. These functions are: 47*33de042dSApple OSS Distributions * connect (inbound), connect (outbound), bind, set socket option, 48*33de042dSApple OSS Distributions * get socket option, and listen. Bind, listen, connect in, and connect 49*33de042dSApple OSS Distributions * out could be used together to build a fairly comprehensive firewall 50*33de042dSApple OSS Distributions * without having to do much with individual packets. 51*33de042dSApple OSS Distributions */ 52*33de042dSApple OSS Distributions #ifndef __KPI_SOCKETFILTER__ 53*33de042dSApple OSS Distributions #define __KPI_SOCKETFILTER__ 54*33de042dSApple OSS Distributions 55*33de042dSApple OSS Distributions #include <sys/kernel_types.h> 56*33de042dSApple OSS Distributions #include <sys/kpi_socket.h> 57*33de042dSApple OSS Distributions #include <sys/ioccom.h> 58*33de042dSApple OSS Distributions 59*33de042dSApple OSS Distributions #ifndef PRIVATE 60*33de042dSApple OSS Distributions #include <Availability.h> 61*33de042dSApple OSS Distributions #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15)) 62*33de042dSApple OSS Distributions #else 63*33de042dSApple OSS Distributions #define __NKE_API_DEPRECATED 64*33de042dSApple OSS Distributions #endif /* PRIVATE */ 65*33de042dSApple OSS Distributions 66*33de042dSApple OSS Distributions struct sockaddr; 67*33de042dSApple OSS Distributions 68*33de042dSApple OSS Distributions /*! 69*33de042dSApple OSS Distributions * @enum sflt_flags 70*33de042dSApple OSS Distributions * @abstract Constants defining mbuf flags. Only the flags listed below 71*33de042dSApple OSS Distributions * can be set or retrieved. 72*33de042dSApple OSS Distributions * @constant SFLT_GLOBAL Indicates this socket filter should be 73*33de042dSApple OSS Distributions * attached to all new sockets when they're created. 74*33de042dSApple OSS Distributions * @constant SFLT_PROG Indicates this socket filter should be attached 75*33de042dSApple OSS Distributions * only when request by the application using the SO_NKE socket 76*33de042dSApple OSS Distributions * option. 77*33de042dSApple OSS Distributions * @constant SFLT_EXTENDED Indicates that this socket filter utilizes 78*33de042dSApple OSS Distributions * the extended fields within the sflt_filter structure. 79*33de042dSApple OSS Distributions * @constant SFLT_EXTENDED_REGISTRY Indicates that this socket filter 80*33de042dSApple OSS Distributions * wants to attach to all the sockets already present on the 81*33de042dSApple OSS Distributions * system. It will also receive notifications for these sockets. 82*33de042dSApple OSS Distributions */ 83*33de042dSApple OSS Distributions enum { 84*33de042dSApple OSS Distributions SFLT_GLOBAL = 0x01, 85*33de042dSApple OSS Distributions SFLT_PROG = 0x02, 86*33de042dSApple OSS Distributions SFLT_EXTENDED = 0x04, 87*33de042dSApple OSS Distributions SFLT_EXTENDED_REGISTRY = 0x08 88*33de042dSApple OSS Distributions }; 89*33de042dSApple OSS Distributions typedef u_int32_t sflt_flags; 90*33de042dSApple OSS Distributions 91*33de042dSApple OSS Distributions /*! 92*33de042dSApple OSS Distributions * @typedef sflt_handle 93*33de042dSApple OSS Distributions * @abstract A 4 byte identifier used with the SO_NKE socket option to 94*33de042dSApple OSS Distributions * identify the socket filter to be attached. 95*33de042dSApple OSS Distributions */ 96*33de042dSApple OSS Distributions typedef u_int32_t sflt_handle; 97*33de042dSApple OSS Distributions 98*33de042dSApple OSS Distributions /*! 99*33de042dSApple OSS Distributions * @enum sflt_event_t 100*33de042dSApple OSS Distributions * @abstract Events notify a filter of state changes and other various 101*33de042dSApple OSS Distributions * events related to the socket. These events cannot be prevented 102*33de042dSApple OSS Distributions * or intercepted, only observed. 103*33de042dSApple OSS Distributions * @constant sock_evt_connected Indicates this socket has moved to the 104*33de042dSApple OSS Distributions * connected state. 105*33de042dSApple OSS Distributions * @constant sock_evt_disconnected Indicates this socket has moved to 106*33de042dSApple OSS Distributions * the disconnected state. 107*33de042dSApple OSS Distributions * @constant sock_evt_flush_read The read socket buffer has been 108*33de042dSApple OSS Distributions * flushed. 109*33de042dSApple OSS Distributions * @constant sock_evt_shutdown The read and or write side(s) of the 110*33de042dSApple OSS Distributions * connection have been shutdown. The param will point to an 111*33de042dSApple OSS Distributions * integer that indicates the direction that has been shutdown. See 112*33de042dSApple OSS Distributions * 'man 2 shutdown' for more information. 113*33de042dSApple OSS Distributions * @constant sock_evt_cantrecvmore Indicates the socket cannot receive 114*33de042dSApple OSS Distributions * more data. 115*33de042dSApple OSS Distributions * @constant sock_evt_cantsendmore Indicates the socket cannot send 116*33de042dSApple OSS Distributions * more data. 117*33de042dSApple OSS Distributions * @constant sock_evt_closing Indicates the socket is closing. 118*33de042dSApple OSS Distributions * @constant sock_evt_bound Indicates this socket has moved to the 119*33de042dSApple OSS Distributions * bound state (only for PF_INET/PF_INET6 domain). 120*33de042dSApple OSS Distributions */ 121*33de042dSApple OSS Distributions enum { 122*33de042dSApple OSS Distributions sock_evt_connecting = 1, 123*33de042dSApple OSS Distributions sock_evt_connected = 2, 124*33de042dSApple OSS Distributions sock_evt_disconnecting = 3, 125*33de042dSApple OSS Distributions sock_evt_disconnected = 4, 126*33de042dSApple OSS Distributions sock_evt_flush_read = 5, 127*33de042dSApple OSS Distributions sock_evt_shutdown = 6, /* param points to an integer specifying how (read, write, or both) see man 2 shutdown */ 128*33de042dSApple OSS Distributions sock_evt_cantrecvmore = 7, 129*33de042dSApple OSS Distributions sock_evt_cantsendmore = 8, 130*33de042dSApple OSS Distributions sock_evt_closing = 9, 131*33de042dSApple OSS Distributions sock_evt_bound = 10 132*33de042dSApple OSS Distributions }; 133*33de042dSApple OSS Distributions typedef u_int32_t sflt_event_t; 134*33de042dSApple OSS Distributions 135*33de042dSApple OSS Distributions /*! 136*33de042dSApple OSS Distributions * @enum sflt_data_flag_t 137*33de042dSApple OSS Distributions * @abstract Inbound and outbound data filters may handle many 138*33de042dSApple OSS Distributions * different types of incoming and outgoing data. These flags help 139*33de042dSApple OSS Distributions * distinguish between normal data, out-of-band data, and records. 140*33de042dSApple OSS Distributions * @constant sock_data_filt_flag_oob Indicates this data is out-of-band 141*33de042dSApple OSS Distributions * data. 142*33de042dSApple OSS Distributions * @constant sock_data_filt_flag_record Indicates this data is a 143*33de042dSApple OSS Distributions * record. This flag is only ever seen on inbound data. 144*33de042dSApple OSS Distributions */ 145*33de042dSApple OSS Distributions enum { 146*33de042dSApple OSS Distributions sock_data_filt_flag_oob = 1, 147*33de042dSApple OSS Distributions sock_data_filt_flag_record = 2 148*33de042dSApple OSS Distributions }; 149*33de042dSApple OSS Distributions typedef u_int32_t sflt_data_flag_t; 150*33de042dSApple OSS Distributions 151*33de042dSApple OSS Distributions __BEGIN_DECLS 152*33de042dSApple OSS Distributions 153*33de042dSApple OSS Distributions /*! 154*33de042dSApple OSS Distributions * @typedef sf_unregistered_func 155*33de042dSApple OSS Distributions * 156*33de042dSApple OSS Distributions * @discussion sf_unregistered_func is called to notify the filter it 157*33de042dSApple OSS Distributions * has been unregistered. This is the last function the stack will 158*33de042dSApple OSS Distributions * call and this function will only be called once all other 159*33de042dSApple OSS Distributions * function calls in to your filter have completed. Once this 160*33de042dSApple OSS Distributions * function has been called, your kext may safely unload. 161*33de042dSApple OSS Distributions * @param handle The socket filter handle used to identify this filter. 162*33de042dSApple OSS Distributions */ 163*33de042dSApple OSS Distributions typedef void (*sf_unregistered_func)(sflt_handle handle); 164*33de042dSApple OSS Distributions 165*33de042dSApple OSS Distributions /*! 166*33de042dSApple OSS Distributions * @typedef sf_attach_func 167*33de042dSApple OSS Distributions * 168*33de042dSApple OSS Distributions * @discussion sf_attach_func is called to notify the filter it has 169*33de042dSApple OSS Distributions * been attached to a socket. The filter may allocate memory for 170*33de042dSApple OSS Distributions * this attachment and use the cookie to track it. This filter is 171*33de042dSApple OSS Distributions * called in one of two cases: 172*33de042dSApple OSS Distributions * 1) You've installed a global filter and a new socket was created. 173*33de042dSApple OSS Distributions * 2) Your non-global socket filter is being attached using the SO_NKE 174*33de042dSApple OSS Distributions * socket option. 175*33de042dSApple OSS Distributions * @param cookie Used to allow the socket filter to set the cookie for 176*33de042dSApple OSS Distributions * this attachment. 177*33de042dSApple OSS Distributions * @param so The socket the filter is being attached to. 178*33de042dSApple OSS Distributions * @result If you return a non-zero value, your filter will not be 179*33de042dSApple OSS Distributions * attached to this socket. 180*33de042dSApple OSS Distributions */ 181*33de042dSApple OSS Distributions typedef errno_t (*sf_attach_func)(void **cookie, socket_t so); 182*33de042dSApple OSS Distributions 183*33de042dSApple OSS Distributions /*! 184*33de042dSApple OSS Distributions * @typedef sf_detach_func 185*33de042dSApple OSS Distributions * 186*33de042dSApple OSS Distributions * @discussion sf_detach_func is called to notify the filter it has 187*33de042dSApple OSS Distributions * been detached from a socket. If the filter allocated any memory 188*33de042dSApple OSS Distributions * for this attachment, it should be freed. This function will 189*33de042dSApple OSS Distributions * be called when the socket is disposed of. 190*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 191*33de042dSApple OSS Distributions * called. 192*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 193*33de042dSApple OSS Distributions * @discussion If you return a non-zero value, your filter will not be 194*33de042dSApple OSS Distributions * attached to this socket. 195*33de042dSApple OSS Distributions */ 196*33de042dSApple OSS Distributions typedef void (*sf_detach_func)(void *cookie, socket_t so); 197*33de042dSApple OSS Distributions 198*33de042dSApple OSS Distributions /*! 199*33de042dSApple OSS Distributions * @typedef sf_notify_func 200*33de042dSApple OSS Distributions * 201*33de042dSApple OSS Distributions * @discussion sf_notify_func is called to notify the filter of various 202*33de042dSApple OSS Distributions * state changes and other events occuring on the socket. 203*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 204*33de042dSApple OSS Distributions * called. 205*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 206*33de042dSApple OSS Distributions * @param event The type of event that has occurred. 207*33de042dSApple OSS Distributions * @param param Additional information about the event. 208*33de042dSApple OSS Distributions */ 209*33de042dSApple OSS Distributions typedef void (*sf_notify_func)(void *cookie, socket_t so, sflt_event_t event, 210*33de042dSApple OSS Distributions void *param); 211*33de042dSApple OSS Distributions 212*33de042dSApple OSS Distributions /*! 213*33de042dSApple OSS Distributions * @typedef sf_getpeername_func 214*33de042dSApple OSS Distributions * 215*33de042dSApple OSS Distributions * @discussion sf_getpeername_func is called to allow a filter to 216*33de042dSApple OSS Distributions * to intercept the getpeername function. When called, sa will 217*33de042dSApple OSS Distributions * point to a pointer to a socket address that was malloced 218*33de042dSApple OSS Distributions * in zone M_SONAME. If you want to replace this address, either 219*33de042dSApple OSS Distributions * modify the currenty copy or allocate a new one and free the 220*33de042dSApple OSS Distributions * old one. 221*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 222*33de042dSApple OSS Distributions * called. 223*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 224*33de042dSApple OSS Distributions * @param sa A pointer to a socket address pointer. 225*33de042dSApple OSS Distributions * @result If you return a non-zero value, processing will stop. If 226*33de042dSApple OSS Distributions * you return EJUSTRETURN, no further filters will be called 227*33de042dSApple OSS Distributions * but a result of zero will be returned to the caller of 228*33de042dSApple OSS Distributions * getpeername. 229*33de042dSApple OSS Distributions */ 230*33de042dSApple OSS Distributions typedef int (*sf_getpeername_func)(void *cookie, socket_t so, 231*33de042dSApple OSS Distributions struct sockaddr **sa); 232*33de042dSApple OSS Distributions 233*33de042dSApple OSS Distributions /*! 234*33de042dSApple OSS Distributions * @typedef sf_getsockname_func 235*33de042dSApple OSS Distributions * 236*33de042dSApple OSS Distributions * @discussion sf_getsockname_func is called to allow a filter to 237*33de042dSApple OSS Distributions * to intercept the getsockname function. When called, sa will 238*33de042dSApple OSS Distributions * point to a pointer to a socket address that was malloced 239*33de042dSApple OSS Distributions * in zone M_SONAME. If you want to replace this address, either 240*33de042dSApple OSS Distributions * modify the currenty copy or allocate a new one and free the 241*33de042dSApple OSS Distributions * old one. 242*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 243*33de042dSApple OSS Distributions * called. 244*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 245*33de042dSApple OSS Distributions * @param sa A pointer to a socket address pointer. 246*33de042dSApple OSS Distributions * @result If you return a non-zero value, processing will stop. If 247*33de042dSApple OSS Distributions * you return EJUSTRETURN, no further filters will be called 248*33de042dSApple OSS Distributions * but a result of zero will be returned to the caller of 249*33de042dSApple OSS Distributions * getsockname. 250*33de042dSApple OSS Distributions */ 251*33de042dSApple OSS Distributions typedef int (*sf_getsockname_func)(void *cookie, socket_t so, 252*33de042dSApple OSS Distributions struct sockaddr **sa); 253*33de042dSApple OSS Distributions 254*33de042dSApple OSS Distributions /*! 255*33de042dSApple OSS Distributions * @typedef sf_data_in_func 256*33de042dSApple OSS Distributions * 257*33de042dSApple OSS Distributions * @discussion sf_data_in_func is called to filter incoming data. If your 258*33de042dSApple OSS Distributions * filter intercepts data for later reinjection, it must queue 259*33de042dSApple OSS Distributions * all incoming data to preserve the order of the data. Use 260*33de042dSApple OSS Distributions * sock_inject_data_in to later reinject this data if you return 261*33de042dSApple OSS Distributions * EJUSTRETURN. Warning: This filter is on the data path. Do not 262*33de042dSApple OSS Distributions * spend excesive time. Do not wait for data on another socket. 263*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 264*33de042dSApple OSS Distributions * called. 265*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 266*33de042dSApple OSS Distributions * @param from The addres the data is from, may be NULL if the socket 267*33de042dSApple OSS Distributions * is connected. 268*33de042dSApple OSS Distributions * @param data The data being received. Control data may appear in the 269*33de042dSApple OSS Distributions * mbuf chain, be sure to check the mbuf types to find control 270*33de042dSApple OSS Distributions * data. 271*33de042dSApple OSS Distributions * @param control Control data being passed separately from the data. 272*33de042dSApple OSS Distributions * @param flags Flags to indicate if this is out of band data or a 273*33de042dSApple OSS Distributions * record. 274*33de042dSApple OSS Distributions * @result Return: 275*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the data. 276*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will stop processing the data, the 277*33de042dSApple OSS Distributions * data will not be freed. 278*33de042dSApple OSS Distributions * Anything Else - The caller will free the data and stop 279*33de042dSApple OSS Distributions * processing. 280*33de042dSApple OSS Distributions */ 281*33de042dSApple OSS Distributions typedef errno_t (*sf_data_in_func)(void *cookie, socket_t so, 282*33de042dSApple OSS Distributions const struct sockaddr *from, mbuf_t *data, mbuf_t *control, 283*33de042dSApple OSS Distributions sflt_data_flag_t flags); 284*33de042dSApple OSS Distributions 285*33de042dSApple OSS Distributions /*! 286*33de042dSApple OSS Distributions * @typedef sf_data_out_func 287*33de042dSApple OSS Distributions * 288*33de042dSApple OSS Distributions * @discussion sf_data_out_func is called to filter outbound data. If 289*33de042dSApple OSS Distributions * your filter intercepts data for later reinjection, it must queue 290*33de042dSApple OSS Distributions * all outbound data to preserve the order of the data when 291*33de042dSApple OSS Distributions * reinjecting. Use sock_inject_data_out to later reinject this 292*33de042dSApple OSS Distributions * data. 293*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 294*33de042dSApple OSS Distributions * called. 295*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 296*33de042dSApple OSS Distributions * @param to The address the data is to, may be NULL if the socket 297*33de042dSApple OSS Distributions * is connected. 298*33de042dSApple OSS Distributions * @param data The data being received. Control data may appear in the 299*33de042dSApple OSS Distributions * mbuf chain, be sure to check the mbuf types to find control 300*33de042dSApple OSS Distributions * data. 301*33de042dSApple OSS Distributions * @param control Control data being passed separately from the data. 302*33de042dSApple OSS Distributions * @param flags Flags to indicate if this is out of band data or a 303*33de042dSApple OSS Distributions * record. 304*33de042dSApple OSS Distributions * @result Return: 305*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the data. 306*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will stop processing the data, 307*33de042dSApple OSS Distributions * the data will not be freed. 308*33de042dSApple OSS Distributions * Anything Else - The caller will free the data and stop 309*33de042dSApple OSS Distributions * processing. 310*33de042dSApple OSS Distributions */ 311*33de042dSApple OSS Distributions typedef errno_t (*sf_data_out_func)(void *cookie, socket_t so, 312*33de042dSApple OSS Distributions const struct sockaddr *to, mbuf_t *data, mbuf_t *control, 313*33de042dSApple OSS Distributions sflt_data_flag_t flags); 314*33de042dSApple OSS Distributions 315*33de042dSApple OSS Distributions /*! 316*33de042dSApple OSS Distributions * @typedef sf_connect_in_func 317*33de042dSApple OSS Distributions * 318*33de042dSApple OSS Distributions * @discussion sf_connect_in_func is called to filter inbound connections. 319*33de042dSApple OSS Distributions * A protocol will call this before accepting an incoming 320*33de042dSApple OSS Distributions * connection and placing it on the queue of completed connections. 321*33de042dSApple OSS Distributions * Warning: This filter is on the data path. Do not spend excesive 322*33de042dSApple OSS Distributions * time. Do not wait for data on another socket. 323*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 324*33de042dSApple OSS Distributions * called. 325*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 326*33de042dSApple OSS Distributions * @param from The address the incoming connection is from. 327*33de042dSApple OSS Distributions * @result Return: 328*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the 329*33de042dSApple OSS Distributions * connection. 330*33de042dSApple OSS Distributions * Anything Else - The caller will rejecting the incoming 331*33de042dSApple OSS Distributions * connection. 332*33de042dSApple OSS Distributions */ 333*33de042dSApple OSS Distributions typedef errno_t (*sf_connect_in_func)(void *cookie, socket_t so, 334*33de042dSApple OSS Distributions const struct sockaddr *from); 335*33de042dSApple OSS Distributions 336*33de042dSApple OSS Distributions /*! 337*33de042dSApple OSS Distributions * @typedef sf_connect_out_func 338*33de042dSApple OSS Distributions * 339*33de042dSApple OSS Distributions * @discussion sf_connect_out_func is called to filter outbound 340*33de042dSApple OSS Distributions * connections. A protocol will call this before initiating an 341*33de042dSApple OSS Distributions * outbound connection. 342*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 343*33de042dSApple OSS Distributions * called. 344*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 345*33de042dSApple OSS Distributions * @param to The remote address of the outbound connection. 346*33de042dSApple OSS Distributions * @result Return: 347*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the 348*33de042dSApple OSS Distributions * connection. 349*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 350*33de042dSApple OSS Distributions * from that point without further processing the connect command. The 351*33de042dSApple OSS Distributions * protocol layer will not see the call. 352*33de042dSApple OSS Distributions * Anything Else - The caller will rejecting the outbound 353*33de042dSApple OSS Distributions * connection. 354*33de042dSApple OSS Distributions */ 355*33de042dSApple OSS Distributions typedef errno_t (*sf_connect_out_func)(void *cookie, socket_t so, 356*33de042dSApple OSS Distributions const struct sockaddr *to); 357*33de042dSApple OSS Distributions 358*33de042dSApple OSS Distributions /*! 359*33de042dSApple OSS Distributions * @typedef sf_bind_func 360*33de042dSApple OSS Distributions * 361*33de042dSApple OSS Distributions * @discussion sf_bind_func is called before performing a bind 362*33de042dSApple OSS Distributions * operation on a socket. 363*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 364*33de042dSApple OSS Distributions * called. 365*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 366*33de042dSApple OSS Distributions * @param to The local address of the socket will be bound to. 367*33de042dSApple OSS Distributions * @result Return: 368*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the bind. 369*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 370*33de042dSApple OSS Distributions * from that point without further processing the bind command. The 371*33de042dSApple OSS Distributions * protocol layer will not see the call. 372*33de042dSApple OSS Distributions * Anything Else - The caller will rejecting the bind. 373*33de042dSApple OSS Distributions */ 374*33de042dSApple OSS Distributions typedef errno_t (*sf_bind_func)(void *cookie, socket_t so, 375*33de042dSApple OSS Distributions const struct sockaddr *to); 376*33de042dSApple OSS Distributions 377*33de042dSApple OSS Distributions /*! 378*33de042dSApple OSS Distributions * @typedef sf_setoption_func 379*33de042dSApple OSS Distributions * 380*33de042dSApple OSS Distributions * @discussion sf_setoption_func is called before performing setsockopt 381*33de042dSApple OSS Distributions * on a socket. 382*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 383*33de042dSApple OSS Distributions * called. 384*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 385*33de042dSApple OSS Distributions * @param opt The socket option to set. 386*33de042dSApple OSS Distributions * @result Return: 387*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the 388*33de042dSApple OSS Distributions * setsockopt. 389*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 390*33de042dSApple OSS Distributions * from that point without further propagating the set option 391*33de042dSApple OSS Distributions * command. The socket and protocol layers will not see the call. 392*33de042dSApple OSS Distributions * Anything Else - The caller will stop processing and return 393*33de042dSApple OSS Distributions * this error. 394*33de042dSApple OSS Distributions */ 395*33de042dSApple OSS Distributions typedef errno_t (*sf_setoption_func)(void *cookie, socket_t so, sockopt_t opt); 396*33de042dSApple OSS Distributions 397*33de042dSApple OSS Distributions /*! 398*33de042dSApple OSS Distributions * @typedef sf_getoption_func 399*33de042dSApple OSS Distributions * 400*33de042dSApple OSS Distributions * @discussion sf_getoption_func is called before performing getsockopt 401*33de042dSApple OSS Distributions * on a socket. 402*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 403*33de042dSApple OSS Distributions * called. 404*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 405*33de042dSApple OSS Distributions * @param opt The socket option to get. 406*33de042dSApple OSS Distributions * @result Return: 407*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of the 408*33de042dSApple OSS Distributions * getsockopt. 409*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 410*33de042dSApple OSS Distributions * from that point without further propagating the get option 411*33de042dSApple OSS Distributions * command. The socket and protocol layers will not see the call. 412*33de042dSApple OSS Distributions * Anything Else - The caller will stop processing and return 413*33de042dSApple OSS Distributions * this error. 414*33de042dSApple OSS Distributions */ 415*33de042dSApple OSS Distributions typedef errno_t (*sf_getoption_func)(void *cookie, socket_t so, sockopt_t opt); 416*33de042dSApple OSS Distributions 417*33de042dSApple OSS Distributions /*! 418*33de042dSApple OSS Distributions * @typedef sf_listen_func 419*33de042dSApple OSS Distributions * 420*33de042dSApple OSS Distributions * @discussion sf_listen_func is called before performing listen 421*33de042dSApple OSS Distributions * on a socket. 422*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 423*33de042dSApple OSS Distributions * called. 424*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 425*33de042dSApple OSS Distributions * @result Return: 426*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of listen. 427*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 428*33de042dSApple OSS Distributions * from that point without further processing the listen command. The 429*33de042dSApple OSS Distributions * protocol will not see the call. 430*33de042dSApple OSS Distributions * Anything Else - The caller will stop processing and return 431*33de042dSApple OSS Distributions * this error. 432*33de042dSApple OSS Distributions */ 433*33de042dSApple OSS Distributions typedef errno_t (*sf_listen_func)(void *cookie, socket_t so); 434*33de042dSApple OSS Distributions 435*33de042dSApple OSS Distributions /*! 436*33de042dSApple OSS Distributions * @typedef sf_ioctl_func 437*33de042dSApple OSS Distributions * 438*33de042dSApple OSS Distributions * @discussion sf_ioctl_func is called before performing an ioctl 439*33de042dSApple OSS Distributions * on a socket. 440*33de042dSApple OSS Distributions * 441*33de042dSApple OSS Distributions * All undefined ioctls are reserved for future use by Apple. If 442*33de042dSApple OSS Distributions * you need to communicate with your kext using an ioctl, please 443*33de042dSApple OSS Distributions * use SIOCSIFKPI and SIOCGIFKPI. 444*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was 445*33de042dSApple OSS Distributions * called. 446*33de042dSApple OSS Distributions * @param so The socket the filter is attached to. 447*33de042dSApple OSS Distributions * @param request The ioctl name. 448*33de042dSApple OSS Distributions * @param argp A pointer to the ioctl parameter. 449*33de042dSApple OSS Distributions * @result Return: 450*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of 451*33de042dSApple OSS Distributions * this ioctl. 452*33de042dSApple OSS Distributions * EJUSTRETURN - The caller will return with a value of 0 (no error) 453*33de042dSApple OSS Distributions * from that point without further processing or propogating 454*33de042dSApple OSS Distributions * the ioctl. 455*33de042dSApple OSS Distributions * Anything Else - The caller will stop processing and return 456*33de042dSApple OSS Distributions * this error. 457*33de042dSApple OSS Distributions */ 458*33de042dSApple OSS Distributions typedef errno_t (*sf_ioctl_func)(void *cookie, socket_t so, 459*33de042dSApple OSS Distributions unsigned long request, const char*__sized_by(IOCPARM_LEN(request)) argp); 460*33de042dSApple OSS Distributions 461*33de042dSApple OSS Distributions /*! 462*33de042dSApple OSS Distributions * @typedef sf_accept_func 463*33de042dSApple OSS Distributions * 464*33de042dSApple OSS Distributions * @discussion sf_accept_func is called after a socket is dequeued 465*33de042dSApple OSS Distributions * off the completed (incoming) connection list and before 466*33de042dSApple OSS Distributions * the file descriptor is associated with it. A filter can 467*33de042dSApple OSS Distributions * utilize this callback to intercept the accepted socket 468*33de042dSApple OSS Distributions * in order to examine it, prior to returning the socket to 469*33de042dSApple OSS Distributions * the caller of accept. Such a filter may also choose to 470*33de042dSApple OSS Distributions * discard the accepted socket if it wishes to do so. 471*33de042dSApple OSS Distributions * @param cookie Cookie value specified when the filter attach was called. 472*33de042dSApple OSS Distributions * @param so_listen The listening socket. 473*33de042dSApple OSS Distributions * @param so The socket that is about to be accepted. 474*33de042dSApple OSS Distributions * @param local The local address of the about to be accepted socket. 475*33de042dSApple OSS Distributions * @param remote The remote address of the about to be accepted socket. 476*33de042dSApple OSS Distributions * @result Return: 477*33de042dSApple OSS Distributions * 0 - The caller will continue with normal processing of accept. 478*33de042dSApple OSS Distributions * EJUSTRETURN - The to be accepted socket will be disconnected 479*33de042dSApple OSS Distributions * prior to being returned to the caller of accept. No further 480*33de042dSApple OSS Distributions * control or data operations on the socket will be allowed. 481*33de042dSApple OSS Distributions * This is the recommended return value as it has the least 482*33de042dSApple OSS Distributions * amount of impact, especially to applications which don't 483*33de042dSApple OSS Distributions * check the error value returned by accept. 484*33de042dSApple OSS Distributions * Anything Else - The to be accepted socket will be closed and 485*33de042dSApple OSS Distributions * the error will be returned to the caller of accept. 486*33de042dSApple OSS Distributions * Note that socket filter developers are advised to exercise 487*33de042dSApple OSS Distributions * caution when returning non-zero values to the caller, 488*33de042dSApple OSS Distributions * since some applications don't check the error value 489*33de042dSApple OSS Distributions * returned by accept and therefore risk breakage. 490*33de042dSApple OSS Distributions */ 491*33de042dSApple OSS Distributions typedef errno_t (*sf_accept_func)(void *cookie, socket_t so_listen, socket_t so, 492*33de042dSApple OSS Distributions const struct sockaddr *local, const struct sockaddr *remote); 493*33de042dSApple OSS Distributions 494*33de042dSApple OSS Distributions /*! 495*33de042dSApple OSS Distributions * @struct sflt_filter 496*33de042dSApple OSS Distributions * @discussion This structure is used to define a socket filter. 497*33de042dSApple OSS Distributions * @field sf_handle A value used to find socket filters by 498*33de042dSApple OSS Distributions * applications. An application can use this value to specify that 499*33de042dSApple OSS Distributions * this filter should be attached when using the SO_NKE socket 500*33de042dSApple OSS Distributions * option. 501*33de042dSApple OSS Distributions * @field sf_flags Indicate whether this filter should be attached to 502*33de042dSApple OSS Distributions * all new sockets or just those that request the filter be 503*33de042dSApple OSS Distributions * attached using the SO_NKE socket option. If this filter 504*33de042dSApple OSS Distributions * utilizes the socket filter extension fields, it must also 505*33de042dSApple OSS Distributions * set SFLT_EXTENDED. 506*33de042dSApple OSS Distributions * @field sf_name A name used for debug purposes. 507*33de042dSApple OSS Distributions * @field sf_unregistered Your function for being notified when your 508*33de042dSApple OSS Distributions * filter has been unregistered. 509*33de042dSApple OSS Distributions * @field sf_attach Your function for handling attaches to sockets. 510*33de042dSApple OSS Distributions * @field sf_detach Your function for handling detaches from sockets. 511*33de042dSApple OSS Distributions * @field sf_notify Your function for handling events. May be null. 512*33de042dSApple OSS Distributions * @field sf_data_in Your function for handling incoming data. May be 513*33de042dSApple OSS Distributions * null. 514*33de042dSApple OSS Distributions * @field sf_data_out Your function for handling outgoing data. May be 515*33de042dSApple OSS Distributions * null. 516*33de042dSApple OSS Distributions * @field sf_connect_in Your function for handling inbound 517*33de042dSApple OSS Distributions * connections. May be null. 518*33de042dSApple OSS Distributions * @field sf_connect_out Your function for handling outbound 519*33de042dSApple OSS Distributions * connections. May be null. 520*33de042dSApple OSS Distributions * @field sf_bind Your function for handling binds. May be null. 521*33de042dSApple OSS Distributions * @field sf_setoption Your function for handling setsockopt. May be null. 522*33de042dSApple OSS Distributions * @field sf_getoption Your function for handling getsockopt. May be null. 523*33de042dSApple OSS Distributions * @field sf_listen Your function for handling listen. May be null. 524*33de042dSApple OSS Distributions * @field sf_ioctl Your function for handling ioctls. May be null. 525*33de042dSApple OSS Distributions * @field sf_len Length of socket filter extension structure; developers 526*33de042dSApple OSS Distributions * must initialize this to sizeof sflt_filter_ext structure. 527*33de042dSApple OSS Distributions * This field and all fields following it will only be valid 528*33de042dSApple OSS Distributions * if SFLT_EXTENDED flag is set in sf_flags field. 529*33de042dSApple OSS Distributions * @field sf_ext_accept Your function for handling inbound connections 530*33de042dSApple OSS Distributions * at accept time. May be null. 531*33de042dSApple OSS Distributions * @field sf_ext_rsvd Reserved for future use; you must initialize 532*33de042dSApple OSS Distributions * the reserved fields with zeroes. 533*33de042dSApple OSS Distributions */ 534*33de042dSApple OSS Distributions struct sflt_filter { 535*33de042dSApple OSS Distributions sflt_handle sf_handle; 536*33de042dSApple OSS Distributions int sf_flags; 537*33de042dSApple OSS Distributions char *sf_name; 538*33de042dSApple OSS Distributions 539*33de042dSApple OSS Distributions sf_unregistered_func sf_unregistered; 540*33de042dSApple OSS Distributions sf_attach_func sf_attach; 541*33de042dSApple OSS Distributions sf_detach_func sf_detach; 542*33de042dSApple OSS Distributions 543*33de042dSApple OSS Distributions sf_notify_func sf_notify; 544*33de042dSApple OSS Distributions sf_getpeername_func sf_getpeername; 545*33de042dSApple OSS Distributions sf_getsockname_func sf_getsockname; 546*33de042dSApple OSS Distributions sf_data_in_func sf_data_in; 547*33de042dSApple OSS Distributions sf_data_out_func sf_data_out; 548*33de042dSApple OSS Distributions sf_connect_in_func sf_connect_in; 549*33de042dSApple OSS Distributions sf_connect_out_func sf_connect_out; 550*33de042dSApple OSS Distributions sf_bind_func sf_bind; 551*33de042dSApple OSS Distributions sf_setoption_func sf_setoption; 552*33de042dSApple OSS Distributions sf_getoption_func sf_getoption; 553*33de042dSApple OSS Distributions sf_listen_func sf_listen; 554*33de042dSApple OSS Distributions sf_ioctl_func sf_ioctl; 555*33de042dSApple OSS Distributions /* 556*33de042dSApple OSS Distributions * The following are valid only if SFLT_EXTENDED flag is set. 557*33de042dSApple OSS Distributions * Initialize sf_ext_len to sizeof sflt_filter_ext structure. 558*33de042dSApple OSS Distributions * Filters must also initialize reserved fields with zeroes. 559*33de042dSApple OSS Distributions */ 560*33de042dSApple OSS Distributions struct sflt_filter_ext { 561*33de042dSApple OSS Distributions unsigned int sf_ext_len; 562*33de042dSApple OSS Distributions sf_accept_func sf_ext_accept; 563*33de042dSApple OSS Distributions void *sf_ext_rsvd[5]; /* Reserved */ 564*33de042dSApple OSS Distributions } sf_ext; 565*33de042dSApple OSS Distributions #define sf_len sf_ext.sf_ext_len 566*33de042dSApple OSS Distributions #define sf_accept sf_ext.sf_ext_accept 567*33de042dSApple OSS Distributions }; 568*33de042dSApple OSS Distributions 569*33de042dSApple OSS Distributions /*! 570*33de042dSApple OSS Distributions * @function sflt_register 571*33de042dSApple OSS Distributions * @discussion Registers a socket filter. See 'man 2 socket' for a 572*33de042dSApple OSS Distributions * desciption of domain, type, and protocol. 573*33de042dSApple OSS Distributions * @param filter A structure describing the filter. 574*33de042dSApple OSS Distributions * @param domain The protocol domain these filters will be attached to. 575*33de042dSApple OSS Distributions * Only PF_INET & PF_INET6 domains are supported. 576*33de042dSApple OSS Distributions * @param type The socket type these filters will be attached to. 577*33de042dSApple OSS Distributions * @param protocol The protocol these filters will be attached to. 578*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. 579*33de042dSApple OSS Distributions */ 580*33de042dSApple OSS Distributions #ifdef KERNEL_PRIVATE 581*33de042dSApple OSS Distributions extern errno_t sflt_register_internal(const struct sflt_filter *filter, 582*33de042dSApple OSS Distributions int domain, int type, int protocol); 583*33de042dSApple OSS Distributions 584*33de042dSApple OSS Distributions #define sflt_register(filter, domain, type, protocol) \ 585*33de042dSApple OSS Distributions sflt_register_internal((filter), (domain), (type), (protocol)) 586*33de042dSApple OSS Distributions #else 587*33de042dSApple OSS Distributions extern errno_t sflt_register(const struct sflt_filter *filter, int domain, 588*33de042dSApple OSS Distributions int type, int protocol) 589*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 590*33de042dSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 591*33de042dSApple OSS Distributions 592*33de042dSApple OSS Distributions /*! 593*33de042dSApple OSS Distributions * @function sflt_unregister 594*33de042dSApple OSS Distributions * @discussion Unregisters a socket filter. This will not detach the 595*33de042dSApple OSS Distributions * socket filter from all sockets it may be attached to at the 596*33de042dSApple OSS Distributions * time, it will just prevent the socket filter from being attached 597*33de042dSApple OSS Distributions * to any new sockets. 598*33de042dSApple OSS Distributions * @param handle The sf_handle of the socket filter to unregister. 599*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. 600*33de042dSApple OSS Distributions */ 601*33de042dSApple OSS Distributions extern errno_t sflt_unregister(sflt_handle handle) 602*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 603*33de042dSApple OSS Distributions 604*33de042dSApple OSS Distributions /*! 605*33de042dSApple OSS Distributions * @function sflt_attach 606*33de042dSApple OSS Distributions * @discussion Attaches a socket filter to the specified socket. A 607*33de042dSApple OSS Distributions * filter must be registered before it can be attached. 608*33de042dSApple OSS Distributions * @param socket The socket the filter should be attached to. 609*33de042dSApple OSS Distributions * @param handle The handle of the registered filter to be attached. 610*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. 611*33de042dSApple OSS Distributions */ 612*33de042dSApple OSS Distributions extern errno_t sflt_attach(socket_t socket, sflt_handle handle) 613*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 614*33de042dSApple OSS Distributions 615*33de042dSApple OSS Distributions /*! 616*33de042dSApple OSS Distributions * @function sflt_detach 617*33de042dSApple OSS Distributions * @discussion Detaches a socket filter from a specified socket. 618*33de042dSApple OSS Distributions * @param socket The socket the filter should be detached from. 619*33de042dSApple OSS Distributions * @param handle The handle of the registered filter to be detached. 620*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. 621*33de042dSApple OSS Distributions */ 622*33de042dSApple OSS Distributions extern errno_t sflt_detach(socket_t socket, sflt_handle handle) 623*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 624*33de042dSApple OSS Distributions 625*33de042dSApple OSS Distributions /* Functions for manipulating sockets */ 626*33de042dSApple OSS Distributions /* 627*33de042dSApple OSS Distributions * Inject data in to the receive buffer of the socket as if it 628*33de042dSApple OSS Distributions * had come from the network. 629*33de042dSApple OSS Distributions * 630*33de042dSApple OSS Distributions * flags should match sflt_data_flag_t 631*33de042dSApple OSS Distributions */ 632*33de042dSApple OSS Distributions 633*33de042dSApple OSS Distributions /*! 634*33de042dSApple OSS Distributions * @function sock_inject_data_in 635*33de042dSApple OSS Distributions * @discussion Inject data in to the receive buffer of the socket as if 636*33de042dSApple OSS Distributions * it had come from the network. 637*33de042dSApple OSS Distributions * @param so The socket to inject the data on. 638*33de042dSApple OSS Distributions * @param from The address the data is from, only necessary on 639*33de042dSApple OSS Distributions * un-connected sockets. A copy of the address will be made, caller 640*33de042dSApple OSS Distributions * is responsible for freeing the address after calling this 641*33de042dSApple OSS Distributions * function. 642*33de042dSApple OSS Distributions * @param data The data and possibly control mbufs. 643*33de042dSApple OSS Distributions * @param control The separate control mbufs. 644*33de042dSApple OSS Distributions * @param flags Flags indicating the type of data. 645*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. If the function 646*33de042dSApple OSS Distributions * returns an error, the caller is responsible for freeing the 647*33de042dSApple OSS Distributions * mbuf. 648*33de042dSApple OSS Distributions */ 649*33de042dSApple OSS Distributions extern errno_t sock_inject_data_in(socket_t so, const struct sockaddr *from, 650*33de042dSApple OSS Distributions mbuf_t data, mbuf_t control, sflt_data_flag_t flags) 651*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 652*33de042dSApple OSS Distributions 653*33de042dSApple OSS Distributions /*! 654*33de042dSApple OSS Distributions * @function sock_inject_data_out 655*33de042dSApple OSS Distributions * @discussion Inject data in to the send buffer of the socket as if it 656*33de042dSApple OSS Distributions * had come from the client. 657*33de042dSApple OSS Distributions * @param so The socket to inject the data on. 658*33de042dSApple OSS Distributions * @param to The address the data should be sent to, only necessary on 659*33de042dSApple OSS Distributions * un-connected sockets. The caller is responsible for freeing the 660*33de042dSApple OSS Distributions * to address after sock_inject_data_out returns. 661*33de042dSApple OSS Distributions * @param data The data and possibly control mbufs. 662*33de042dSApple OSS Distributions * @param control The separate control mbufs. 663*33de042dSApple OSS Distributions * @param flags Flags indicating the type of data. 664*33de042dSApple OSS Distributions * @result 0 on success otherwise the errno error. The data and control 665*33de042dSApple OSS Distributions * values are always freed regardless of return value. 666*33de042dSApple OSS Distributions */ 667*33de042dSApple OSS Distributions extern errno_t sock_inject_data_out(socket_t so, const struct sockaddr *to, 668*33de042dSApple OSS Distributions mbuf_t data, mbuf_t control, sflt_data_flag_t flags) 669*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 670*33de042dSApple OSS Distributions 671*33de042dSApple OSS Distributions 672*33de042dSApple OSS Distributions /* 673*33de042dSApple OSS Distributions * sockopt_t accessors 674*33de042dSApple OSS Distributions */ 675*33de042dSApple OSS Distributions 676*33de042dSApple OSS Distributions enum { 677*33de042dSApple OSS Distributions sockopt_get = 1, 678*33de042dSApple OSS Distributions sockopt_set = 2 679*33de042dSApple OSS Distributions }; 680*33de042dSApple OSS Distributions typedef u_int8_t sockopt_dir; 681*33de042dSApple OSS Distributions 682*33de042dSApple OSS Distributions /*! 683*33de042dSApple OSS Distributions * @function sockopt_direction 684*33de042dSApple OSS Distributions * @discussion Retrieves the direction of the socket option (Get or 685*33de042dSApple OSS Distributions * Set). 686*33de042dSApple OSS Distributions * @param sopt The socket option. 687*33de042dSApple OSS Distributions * @result sock_opt_get or sock_opt_set. 688*33de042dSApple OSS Distributions */ 689*33de042dSApple OSS Distributions extern sockopt_dir sockopt_direction(sockopt_t sopt) 690*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 691*33de042dSApple OSS Distributions 692*33de042dSApple OSS Distributions /*! 693*33de042dSApple OSS Distributions * @function sockopt_level 694*33de042dSApple OSS Distributions * @discussion Retrieves the socket option level. (SOL_SOCKET, etc). 695*33de042dSApple OSS Distributions * @param sopt The socket option. 696*33de042dSApple OSS Distributions * @result The socket option level. See man 2 setsockopt 697*33de042dSApple OSS Distributions */ 698*33de042dSApple OSS Distributions extern int sockopt_level(sockopt_t sopt) 699*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 700*33de042dSApple OSS Distributions 701*33de042dSApple OSS Distributions /*! 702*33de042dSApple OSS Distributions * @function sockopt_name 703*33de042dSApple OSS Distributions * @discussion Retrieves the socket option name. (SO_SNDBUF, etc). 704*33de042dSApple OSS Distributions * @param sopt The socket option. 705*33de042dSApple OSS Distributions * @result The socket option name. See man 2 setsockopt 706*33de042dSApple OSS Distributions */ 707*33de042dSApple OSS Distributions extern int sockopt_name(sockopt_t sopt) 708*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 709*33de042dSApple OSS Distributions 710*33de042dSApple OSS Distributions /*! 711*33de042dSApple OSS Distributions * @function sockopt_valsize 712*33de042dSApple OSS Distributions * @discussion Retrieves the size of the socket option data. 713*33de042dSApple OSS Distributions * @param sopt The socket option. 714*33de042dSApple OSS Distributions * @result The length, in bytes, of the data. 715*33de042dSApple OSS Distributions */ 716*33de042dSApple OSS Distributions extern size_t sockopt_valsize(sockopt_t sopt) 717*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 718*33de042dSApple OSS Distributions 719*33de042dSApple OSS Distributions /*! 720*33de042dSApple OSS Distributions * @function sockopt_copyin 721*33de042dSApple OSS Distributions * @discussion Copies the data from the socket option to a buffer. 722*33de042dSApple OSS Distributions * @param sopt The socket option. 723*33de042dSApple OSS Distributions * @param data A pointer to the buffer to copy the data in to. 724*33de042dSApple OSS Distributions * @param length The number of bytes to copy. 725*33de042dSApple OSS Distributions * @result An errno error or zero upon success. 726*33de042dSApple OSS Distributions */ 727*33de042dSApple OSS Distributions extern errno_t sockopt_copyin(sockopt_t sopt, void *__sized_by(length) data, size_t length) 728*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 729*33de042dSApple OSS Distributions 730*33de042dSApple OSS Distributions /*! 731*33de042dSApple OSS Distributions * @function sockopt_copyout 732*33de042dSApple OSS Distributions * @discussion Copies the data from a buffer to a socket option. 733*33de042dSApple OSS Distributions * @param sopt The socket option. 734*33de042dSApple OSS Distributions * @param data A pointer to the buffer to copy the data out of. 735*33de042dSApple OSS Distributions * @param length The number of bytes to copy. 736*33de042dSApple OSS Distributions * @result An errno error or zero upon success. 737*33de042dSApple OSS Distributions */ 738*33de042dSApple OSS Distributions extern errno_t sockopt_copyout(sockopt_t sopt, void *__sized_by(length) data, size_t length) 739*33de042dSApple OSS Distributions __NKE_API_DEPRECATED; 740*33de042dSApple OSS Distributions 741*33de042dSApple OSS Distributions #undef __NKE_API_DEPRECATED 742*33de042dSApple OSS Distributions __END_DECLS 743*33de042dSApple OSS Distributions #endif /* __KPI_SOCKETFILTER__ */ 744