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