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