]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/dlil.h
xnu-123.5.tar.gz
[apple/xnu.git] / bsd / net / dlil.h
1 /*
2 * Copyright (c) 2000 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 * Copyright (c) 1999 Apple Computer, Inc.
24 *
25 * Data Link Inteface Layer
26 * Author: Ted Walker
27 */
28
29
30 #ifndef DLIL_H
31 #define DLIL_H
32
33 #if __STDC__
34
35 struct ifnet;
36 struct mbuf;
37 struct ether_header;
38
39 #endif
40
41
42
43 #define DLIL_LAST_FILTER -1
44 #define DLIL_NULL_FILTER -2
45
46 #define DLIL_WAIT_FOR_FREE -2
47
48 #define DLIL_BLUEBOX 1
49
50
51
52 #include <net/if.h>
53 #include <net/if_var.h>
54 #include <sys/kern_event.h>
55
56 enum {
57 BPF_TAP_DISABLE,
58 BPF_TAP_INPUT,
59 BPF_TAP_OUTPUT,
60 BPF_TAP_INPUT_OUTPUT
61 };
62
63
64 struct dl_tag_attr_str {
65 u_long dl_tag;
66 short if_flags;
67 short if_unit;
68 u_long if_family;
69 u_long protocol_family;
70 };
71
72
73 struct dlil_pr_flt_str {
74 caddr_t cookie;
75
76 int (*filter_dl_input)(caddr_t cookie,
77 struct mbuf **m,
78 char **frame_header,
79 struct ifnet **ifp);
80
81
82 int (*filter_dl_output)(caddr_t cookie,
83 struct mbuf **m,
84 struct ifnet **ifp,
85 struct sockaddr **dest,
86 char *dest_linkaddr,
87 char *frame_type);
88
89 int (*filter_dl_event)(caddr_t cookie,
90 struct kern_event_msg *event_msg);
91
92 int (*filter_dl_ioctl)(caddr_t cookie,
93 struct ifnet *ifp,
94 u_long ioctl_cmd,
95 caddr_t ioctl_arg);
96
97 int (*filter_detach)(caddr_t cookie);
98 };
99
100 struct dlil_if_flt_str {
101 caddr_t cookie;
102 int (*filter_if_input)(caddr_t cookie,
103 struct ifnet **ifnet_ptr,
104 struct mbuf **mbuf_ptr,
105 char **frame_ptr);
106
107 int (*filter_if_event)(caddr_t cookie,
108 struct ifnet **ifnet_ptr,
109 struct kern_event_msg **event_msg_ptr);
110
111 int (*filter_if_output)(caddr_t cookie,
112 struct ifnet **ifnet_ptr,
113 struct mbuf **mbuf_ptr);
114
115
116 int (*filter_if_ioctl)(caddr_t cookie,
117 struct ifnet *ifnet_ptr,
118 u_long ioctl_code_ptr,
119 caddr_t ioctl_arg_ptr);
120
121 int (*filter_if_free)(caddr_t cookie,
122 struct ifnet *ifnet_ptr);
123
124 int (*filter_detach)(caddr_t cookie);
125 };
126
127
128 #define DLIL_PR_FILTER 1
129 #define DLIL_IF_FILTER 2
130
131
132
133 typedef int (*dl_input_func)(struct mbuf *m, char *frame_header,
134 struct ifnet *ifp, u_long dl_tag, int sync_ok);
135 typedef int (*dl_pre_output_func)(struct ifnet *ifp,
136 struct mbuf **m,
137 struct sockaddr *dest,
138 caddr_t route_entry,
139 char *frame_type,
140 char *dst_addr,
141 u_long dl_tag);
142
143 typedef int (*dl_event_func)(struct kern_event_msg *event,
144 u_long dl_tag);
145
146 typedef int (*dl_offer_func)(struct mbuf *m, char *frame_header);
147 typedef int (*dl_ioctl_func)(u_long dl_tag,
148 struct ifnet *ifp,
149 u_long ioctl_cmd,
150 caddr_t ioctl_arg);
151
152
153
154 struct dlil_filterq_entry {
155 TAILQ_ENTRY(dlil_filterq_entry) que;
156 u_long filter_id;
157 int type;
158 union {
159 struct dlil_if_flt_str if_filter;
160 struct dlil_pr_flt_str pr_filter;
161 } variants;
162 };
163
164
165 TAILQ_HEAD(dlil_filterq_head, dlil_filterq_entry);
166
167
168 struct if_proto {
169 TAILQ_ENTRY(if_proto) next;
170 u_long dl_tag;
171 struct dlil_filterq_head pr_flt_head;
172 struct ifnet *ifp;
173 dl_input_func dl_input;
174 dl_pre_output_func dl_pre_output;
175 dl_event_func dl_event;
176 dl_offer_func dl_offer;
177 dl_ioctl_func dl_ioctl;
178 u_long protocol_family;
179
180 };
181
182 TAILQ_HEAD(dlil_proto_head, if_proto);
183
184 struct dlil_tag_list_entry {
185 TAILQ_ENTRY(dlil_tag_list_entry) next;
186 struct ifnet *ifp;
187 u_long dl_tag;
188 };
189
190
191 #define DLIL_DESC_RAW 1
192 #define DLIL_DESC_802_2 2
193 #define DLIL_DESC_802_2_SNAP 3
194
195 struct dlil_demux_desc {
196 TAILQ_ENTRY(dlil_demux_desc) next;
197 int type;
198
199 u_char *native_type;
200 union {
201 struct {
202 u_long proto_id_length; /* IN LONGWORDS!!! */
203 u_char *proto_id;
204 u_char *proto_id_mask;
205
206 } bitmask;
207
208 struct {
209 u_char dsap;
210 u_char ssap;
211 u_char control_code;
212 u_char pad;
213 } desc_802_2;
214
215 struct {
216 u_char dsap;
217 u_char ssap;
218 u_char control_code;
219 u_char org[3];
220 u_short protocol_type;
221 } desc_802_2_SNAP;
222 } variants;
223 };
224
225 TAILQ_HEAD(ddesc_head_str, dlil_demux_desc);
226
227
228 struct dlil_proto_reg_str {
229 struct ddesc_head_str demux_desc_head;
230 u_long interface_family;
231 u_long protocol_family;
232 short unit_number;
233 int default_proto; /* 0 or 1 */
234 dl_input_func input;
235 dl_pre_output_func pre_output;
236 dl_event_func event;
237 dl_offer_func offer;
238 dl_ioctl_func ioctl;
239 };
240
241
242 int dlil_attach_interface_filter(struct ifnet *ifnet_ptr,
243 struct dlil_if_flt_str *interface_filter,
244 u_long *filter_id,
245 int insertion_point);
246
247 int
248 dlil_input(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail);
249
250 int
251 dlil_output(u_long dl_tag,
252 struct mbuf *m,
253 caddr_t route,
254 struct sockaddr *dest,
255 int raw);
256
257
258 int
259 dlil_ioctl(u_long proto_family,
260 struct ifnet *ifp,
261 u_long ioctl_code,
262 caddr_t ioctl_arg);
263
264 int
265 dlil_attach_protocol(struct dlil_proto_reg_str *proto,
266 u_long *dl_tag);
267
268 int
269 dlil_detach_protocol(u_long dl_tag);
270
271 int
272 dlil_if_attach(struct ifnet *ifp);
273
274 int
275 dlil_attach_protocol_filter(u_long dl_tag,
276 struct dlil_pr_flt_str *proto_filter,
277 u_long *filter_id,
278 int insertion_point);
279 int
280 dlil_detach_filter(u_long filter_id);
281
282 struct dlil_ifmod_reg_str {
283 int (*add_if)(struct ifnet *ifp);
284 int (*del_if)(struct ifnet *ifp);
285 int (*add_proto)(struct ddesc_head_str *demux_desc_head,
286 struct if_proto *proto, u_long dl_tag);
287 int (*del_proto)(struct if_proto *proto, u_long dl_tag);
288 int (*ifmod_ioctl)(struct ifnet *ifp, u_long ioctl_cmd, caddr_t data);
289 int (*shutdown)();
290 };
291
292
293 int dlil_reg_if_modules(u_long interface_family,
294 struct dlil_ifmod_reg_str *ifmod_reg);
295
296 int
297 dlil_inject_if_input(struct mbuf *m, char *frame_header, u_long from_id);
298
299 int
300 dlil_inject_pr_input(struct mbuf *m, char *frame_header, u_long from_id);
301
302 int
303 dlil_inject_pr_output(struct mbuf *m,
304 struct sockaddr *dest,
305 int raw,
306 char *frame_type,
307 char *dst_linkaddr,
308 u_long from_id);
309
310 int
311 dlil_inject_if_output(struct mbuf *m, u_long from_id);
312
313 int
314 dlil_find_dltag(u_long if_family, short unit, u_long proto_family, u_long *dl_tag);
315
316
317 int
318 dlil_event(struct ifnet *ifp, struct kern_event_msg *event);
319
320 int dlil_dereg_if_modules(u_long interface_family);
321
322 int
323 dlil_if_detach(struct ifnet *ifp);
324
325 #endif /* DLIL_H */