]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/kpi_interfacefilter.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / net / kpi_interfacefilter.h
CommitLineData
91447636 1/*
5d5c5d0d
A
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
27 */
28/*!
29 @header kpi_interfacefilter.h
30 This header defines an API to attach interface filters. Interface
31 filters may be attached to a specific interface. The filters can
32 intercept all packets in to and out of the specific interface. In
33 addition, the filters may intercept interface specific events and
34 ioctls.
35 */
36
37#ifndef __KPI_INTERFACEFILTER__
38#define __KPI_INTERFACEFILTER__
39#include <sys/kernel_types.h>
40#include <net/kpi_interface.h>
41
42struct kev_msg;
43
44/*!
45 @typedef iff_input_func
46
47 @discussion iff_input_func is used to filter incoming packets. The
48 interface is only valid for the duration of the filter call. If
49 you need to keep a reference to the interface, be sure to call
50 ifnet_reference and ifnet_release. The packets passed to the
51 inbound filter are different from those passed to the outbound
52 filter. Packets to the inbound filter have the frame header
53 passed in separately from the rest of the packet. The outbound
54 data filters is passed the whole packet including the frame
55 header.
56
57 The frame header usually preceeds the data in the mbuf. This
58 ensures that the frame header will be a valid pointer as long as
59 the mbuf is not freed. If you need to change the frame header to
60 point somewhere else, the recommended method is to prepend a new
61 frame header to the mbuf chain (mbuf_prepend), set the header to
62 point to that data, then call mbuf_adj to move the mbuf data
63 pointer back to the start of the packet payload.
64 @param cookie The cookie specified when this filter was attached.
65 @param interface The interface the packet was recieved on.
66 @param protocol The protocol of this packet. If you specified a
67 protocol when attaching your filter, the protocol will only ever
68 be the protocol you specified.
69 @param data The inbound packet, after the frame header as determined
70 by the interface.
71 @param frame_ptr A pointer to the pointer to the frame header. The
72 frame header length can be found by inspecting the interface's
73 frame header length (ifnet_hdrlen).
74 @result Return:
75 0 - The caller will continue with normal processing of the packet.
76 EJUSTRETURN - The caller will stop processing the packet, the packet will not be freed.
77 Anything Else - The caller will free the packet and stop processing.
78*/
79typedef errno_t (*iff_input_func)(void* cookie, ifnet_t interface, protocol_family_t protocol,
80 mbuf_t *data, char **frame_ptr);
81
82/*!
83 @typedef iff_output_func
84
85 @discussion iff_output_func is used to filter fully formed outbound
86 packets. The interface is only valid for the duration of the
87 filter call. If you need to keep a reference to the interface,
88 be sure to call ifnet_reference and ifnet_release.
89 @param cookie The cookie specified when this filter was attached.
90 @param interface The interface the packet is being transmitted on.
91 @param data The fully formed outbound packet in a chain of mbufs.
92 The frame header is already included. The filter function may
93 modify the packet or return a different mbuf chain.
94 @result Return:
95 0 - The caller will continue with normal processing of the packet.
96 EJUSTRETURN - The caller will stop processing the packet, the packet will not be freed.
97 Anything Else - The caller will free the packet and stop processing.
98*/
99typedef errno_t (*iff_output_func)(void* cookie, ifnet_t interface, protocol_family_t protocol,
100 mbuf_t *data);
101
102/*!
103 @typedef iff_event_func
104
105 @discussion iff_event_func is used to filter interface specific
106 events. The interface is only valid for the duration of the
107 filter call. If you need to keep a reference to the interface,
108 be sure to call ifnet_reference and ifnet_release.
109 @param cookie The cookie specified when this filter was attached.
110 @param interface The interface the packet is being transmitted on.
111 @param event_msg The kernel event, may not be changed.
112*/
113typedef void (*iff_event_func)(void* cookie, ifnet_t interface, protocol_family_t protocol,
114 const struct kev_msg *event_msg);
115
116/*!
117 @typedef iff_ioctl_func
118
119 @discussion iff_ioctl_func is used to filter ioctls sent to an
120 interface. The interface is only valid for the duration of the
121 filter call. If you need to keep a reference to the interface,
122 be sure to call ifnet_reference and ifnet_release.
123 @param cookie The cookie specified when this filter was attached.
124 @param interface The interface the packet is being transmitted on.
125 @param ioctl_cmd The ioctl command.
126 @param ioctl_arg A pointer to the ioctl argument.
127 @result Return:
128 0 - The caller will continue with normal processing of the packet.
129 EJUSTRETURN - The caller will stop processing the packet, the packet will not be freed.
130 Anything Else - The caller will free the packet and stop processing.
131*/
132typedef errno_t (*iff_ioctl_func)(void* cookie, ifnet_t interface, protocol_family_t protocol,
133 u_long ioctl_cmd, void* ioctl_arg);
134
135/*!
136 @typedef iff_detached_func
137
138 @discussion iff_detached_func is called to notify the filter that it
139 has been detached from an interface. This is the last call to
140 the filter that will be made. A filter may be detached if the
141 interface is detached or the detach filter function is called.
142 In the case that the interface is being detached, your filter's
143 event function will be called with the interface detaching event
144 before the your detached function will be called.
145 @param cookie The cookie specified when this filter was attached.
146 @param interface The interface this filter was detached from.
147*/
148typedef void (*iff_detached_func)(void* cookie, ifnet_t interface);
149
150/*!
151 @struct iff_filter
152 @discussion This structure is used to define an interface filter for
153 use with the iflt_attach function.
154 @field iff_cookie A kext defined cookie that will be passed to all
155 filter functions.
156 @field iff_name A filter name used for debugging purposes.
157 @field iff_protocol The protocol of the packets this filter is
158 interested in. If you specify zero, packets from all protocols
159 will be passed to the filter.
160 @field iff_input The filter function to handle inbound packets, may
161 be NULL.
162 @field iff_output The filter function to handle outbound packets,
163 may be NULL.
164 @field iff_event The filter function to handle interface events, may
165 be null.
166 @field iff_ioctl The filter function to handle interface ioctls, may
167 be null.
168 @field iff_detached The filter function used to notify the filter that
169 it has been detached.
170*/
171
172struct iff_filter {
173 void* iff_cookie;
174 const char* iff_name;
175 protocol_family_t iff_protocol;
176 iff_input_func iff_input;
177 iff_output_func iff_output;
178 iff_event_func iff_event;
179 iff_ioctl_func iff_ioctl;
180 iff_detached_func iff_detached;
181};
182
183/*!
184 @function iflt_attach
185 @discussion Attaches an interface filter to an interface.
186 @param interface The interface the filter should be attached to.
187 @param filter A structure defining the filter.
188 @param filter_ref A reference to the filter used to detach.
189 @result 0 on success otherwise the errno error.
190 */
191errno_t iflt_attach(ifnet_t interface, const struct iff_filter* filter,
192 interface_filter_t *filter_ref);
193
194/*!
195 @function iflt_detach
196 @discussion Detaches an interface filter from an interface.
197 @param filter_ref The reference to the filter from iflt_attach.
198 */
199void iflt_detach(interface_filter_t filter_ref);
200
201#endif