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