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