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