]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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); | |
0b4e3aa0 | 98 | u_long reserved[2]; |
1c79356b A |
99 | }; |
100 | ||
101 | struct dlil_if_flt_str { | |
102 | caddr_t cookie; | |
103 | int (*filter_if_input)(caddr_t cookie, | |
104 | struct ifnet **ifnet_ptr, | |
105 | struct mbuf **mbuf_ptr, | |
106 | char **frame_ptr); | |
107 | ||
108 | int (*filter_if_event)(caddr_t cookie, | |
109 | struct ifnet **ifnet_ptr, | |
110 | struct kern_event_msg **event_msg_ptr); | |
111 | ||
112 | int (*filter_if_output)(caddr_t cookie, | |
113 | struct ifnet **ifnet_ptr, | |
114 | struct mbuf **mbuf_ptr); | |
115 | ||
116 | ||
117 | int (*filter_if_ioctl)(caddr_t cookie, | |
118 | struct ifnet *ifnet_ptr, | |
119 | u_long ioctl_code_ptr, | |
120 | caddr_t ioctl_arg_ptr); | |
121 | ||
122 | int (*filter_if_free)(caddr_t cookie, | |
123 | struct ifnet *ifnet_ptr); | |
124 | ||
0b4e3aa0 A |
125 | int (*filter_detach)(caddr_t cookie); |
126 | u_long reserved[2]; | |
1c79356b A |
127 | }; |
128 | ||
129 | ||
130 | #define DLIL_PR_FILTER 1 | |
131 | #define DLIL_IF_FILTER 2 | |
132 | ||
133 | ||
134 | ||
135 | typedef int (*dl_input_func)(struct mbuf *m, char *frame_header, | |
136 | struct ifnet *ifp, u_long dl_tag, int sync_ok); | |
137 | typedef int (*dl_pre_output_func)(struct ifnet *ifp, | |
138 | struct mbuf **m, | |
139 | struct sockaddr *dest, | |
140 | caddr_t route_entry, | |
141 | char *frame_type, | |
142 | char *dst_addr, | |
143 | u_long dl_tag); | |
144 | ||
145 | typedef int (*dl_event_func)(struct kern_event_msg *event, | |
146 | u_long dl_tag); | |
147 | ||
148 | typedef int (*dl_offer_func)(struct mbuf *m, char *frame_header); | |
149 | typedef int (*dl_ioctl_func)(u_long dl_tag, | |
150 | struct ifnet *ifp, | |
151 | u_long ioctl_cmd, | |
152 | caddr_t ioctl_arg); | |
153 | ||
154 | ||
155 | ||
156 | struct dlil_filterq_entry { | |
157 | TAILQ_ENTRY(dlil_filterq_entry) que; | |
158 | u_long filter_id; | |
159 | int type; | |
160 | union { | |
161 | struct dlil_if_flt_str if_filter; | |
162 | struct dlil_pr_flt_str pr_filter; | |
163 | } variants; | |
164 | }; | |
165 | ||
166 | ||
167 | TAILQ_HEAD(dlil_filterq_head, dlil_filterq_entry); | |
168 | ||
169 | ||
170 | struct if_proto { | |
171 | TAILQ_ENTRY(if_proto) next; | |
172 | u_long dl_tag; | |
173 | struct dlil_filterq_head pr_flt_head; | |
174 | struct ifnet *ifp; | |
175 | dl_input_func dl_input; | |
176 | dl_pre_output_func dl_pre_output; | |
177 | dl_event_func dl_event; | |
178 | dl_offer_func dl_offer; | |
179 | dl_ioctl_func dl_ioctl; | |
180 | u_long protocol_family; | |
0b4e3aa0 | 181 | u_long reserved[4]; |
1c79356b A |
182 | |
183 | }; | |
184 | ||
185 | TAILQ_HEAD(dlil_proto_head, if_proto); | |
186 | ||
187 | struct dlil_tag_list_entry { | |
188 | TAILQ_ENTRY(dlil_tag_list_entry) next; | |
189 | struct ifnet *ifp; | |
190 | u_long dl_tag; | |
191 | }; | |
192 | ||
193 | ||
7b1edb79 | 194 | /* Obsolete types */ |
1c79356b A |
195 | #define DLIL_DESC_RAW 1 |
196 | #define DLIL_DESC_802_2 2 | |
197 | #define DLIL_DESC_802_2_SNAP 3 | |
7b1edb79 A |
198 | /* |
199 | * DLIL_DESC_RAW - obsolete type, data in variants.bitmask or native_type | |
200 | * if variants.bitmask.proto_id_length, native_type in host | |
201 | * byte order. | |
202 | * DLIL_DESC_802_2 - obsolete, data in variants.desc_802_2 | |
203 | * DLIL_DESC_802_2_SNAP - obsolete, data in variants.desc_802_2_SNAP | |
204 | * protocol field in host byte order | |
205 | */ | |
206 | ||
207 | /* Ehernet specific types */ | |
208 | #define DLIL_DESC_ETYPE2 4 | |
209 | #define DLIL_DESC_SAP 5 | |
210 | #define DLIL_DESC_SNAP 6 | |
211 | /* | |
212 | * DLIL_DESC_ETYPE2 - native_type must point to 2 byte ethernet raw protocol, | |
213 | * variants.native_type_length must be set to 2 | |
214 | * DLIL_DESC_SAP - native_type must point to 3 byte SAP protocol | |
215 | * variants.native_type_length must be set to 3 | |
216 | * DLIL_DESC_SNAP - native_type must point to 5 byte SNAP protocol | |
217 | * variants.native_type_length must be set to 5 | |
218 | * | |
219 | * All protocols must be in Network byte order. | |
220 | * | |
221 | * Future interface families may define more protocol types they know about. | |
222 | * The type implies the offset and context of the protocol data at native_type. | |
223 | * The length of the protocol data specified at native_type must be set in | |
224 | * variants.native_type_length. | |
225 | */ | |
1c79356b A |
226 | |
227 | struct dlil_demux_desc { | |
228 | TAILQ_ENTRY(dlil_demux_desc) next; | |
7b1edb79 A |
229 | |
230 | int type; | |
231 | u_char *native_type; | |
232 | ||
1c79356b | 233 | union { |
7b1edb79 A |
234 | /* Structs in this union are obsolete. They exist for binary compatability only */ |
235 | /* Only the native_type_length is used */ | |
236 | struct { | |
237 | u_long proto_id_length; /* IN LONGWORDS!!! */ | |
238 | u_char *proto_id; /* No longer supported by Ethernet family */ | |
239 | u_char *proto_id_mask; | |
240 | } bitmask; | |
241 | ||
242 | struct { | |
243 | u_char dsap; | |
244 | u_char ssap; | |
245 | u_char control_code; | |
246 | u_char pad; | |
247 | } desc_802_2; | |
248 | ||
249 | struct { | |
250 | u_char dsap; /* Ignored, assumed to be 0xAA */ | |
251 | u_char ssap; /* Ignored, assumed to be 0xAA */ | |
252 | u_char control_code; /* Ignored, assumed to be 0x03 */ | |
253 | u_char org[3]; | |
254 | u_short protocol_type; /* In host byte order */ | |
255 | } desc_802_2_SNAP; | |
256 | ||
257 | /* Length of data pointed to by native_type, must be set correctly */ | |
258 | u_int32_t native_type_length; | |
1c79356b A |
259 | } variants; |
260 | }; | |
261 | ||
262 | TAILQ_HEAD(ddesc_head_str, dlil_demux_desc); | |
263 | ||
264 | ||
265 | struct dlil_proto_reg_str { | |
266 | struct ddesc_head_str demux_desc_head; | |
267 | u_long interface_family; | |
268 | u_long protocol_family; | |
269 | short unit_number; | |
270 | int default_proto; /* 0 or 1 */ | |
271 | dl_input_func input; | |
7b1edb79 | 272 | dl_pre_output_func pre_output; |
1c79356b A |
273 | dl_event_func event; |
274 | dl_offer_func offer; | |
275 | dl_ioctl_func ioctl; | |
0b4e3aa0 | 276 | u_long reserved[4]; |
1c79356b A |
277 | }; |
278 | ||
279 | ||
280 | int dlil_attach_interface_filter(struct ifnet *ifnet_ptr, | |
281 | struct dlil_if_flt_str *interface_filter, | |
282 | u_long *filter_id, | |
283 | int insertion_point); | |
284 | ||
285 | int | |
286 | dlil_input(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail); | |
287 | ||
288 | int | |
289 | dlil_output(u_long dl_tag, | |
290 | struct mbuf *m, | |
291 | caddr_t route, | |
292 | struct sockaddr *dest, | |
293 | int raw); | |
294 | ||
295 | ||
296 | int | |
297 | dlil_ioctl(u_long proto_family, | |
298 | struct ifnet *ifp, | |
299 | u_long ioctl_code, | |
300 | caddr_t ioctl_arg); | |
301 | ||
302 | int | |
303 | dlil_attach_protocol(struct dlil_proto_reg_str *proto, | |
304 | u_long *dl_tag); | |
305 | ||
306 | int | |
307 | dlil_detach_protocol(u_long dl_tag); | |
308 | ||
309 | int | |
310 | dlil_if_attach(struct ifnet *ifp); | |
311 | ||
312 | int | |
313 | dlil_attach_protocol_filter(u_long dl_tag, | |
314 | struct dlil_pr_flt_str *proto_filter, | |
315 | u_long *filter_id, | |
316 | int insertion_point); | |
317 | int | |
318 | dlil_detach_filter(u_long filter_id); | |
319 | ||
320 | struct dlil_ifmod_reg_str { | |
321 | int (*add_if)(struct ifnet *ifp); | |
322 | int (*del_if)(struct ifnet *ifp); | |
323 | int (*add_proto)(struct ddesc_head_str *demux_desc_head, | |
324 | struct if_proto *proto, u_long dl_tag); | |
325 | int (*del_proto)(struct if_proto *proto, u_long dl_tag); | |
326 | int (*ifmod_ioctl)(struct ifnet *ifp, u_long ioctl_cmd, caddr_t data); | |
327 | int (*shutdown)(); | |
0b4e3aa0 | 328 | u_long reserved[4]; |
1c79356b A |
329 | }; |
330 | ||
331 | ||
332 | int dlil_reg_if_modules(u_long interface_family, | |
333 | struct dlil_ifmod_reg_str *ifmod_reg); | |
334 | ||
335 | int | |
336 | dlil_inject_if_input(struct mbuf *m, char *frame_header, u_long from_id); | |
337 | ||
338 | int | |
339 | dlil_inject_pr_input(struct mbuf *m, char *frame_header, u_long from_id); | |
340 | ||
341 | int | |
342 | dlil_inject_pr_output(struct mbuf *m, | |
343 | struct sockaddr *dest, | |
344 | int raw, | |
345 | char *frame_type, | |
346 | char *dst_linkaddr, | |
347 | u_long from_id); | |
348 | ||
349 | int | |
350 | dlil_inject_if_output(struct mbuf *m, u_long from_id); | |
351 | ||
352 | int | |
353 | dlil_find_dltag(u_long if_family, short unit, u_long proto_family, u_long *dl_tag); | |
354 | ||
355 | ||
356 | int | |
357 | dlil_event(struct ifnet *ifp, struct kern_event_msg *event); | |
358 | ||
359 | int dlil_dereg_if_modules(u_long interface_family); | |
360 | ||
361 | int | |
362 | dlil_if_detach(struct ifnet *ifp); | |
363 | ||
364 | #endif /* DLIL_H */ |