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