]>
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 | ||
194 | #define DLIL_DESC_RAW 1 | |
195 | #define DLIL_DESC_802_2 2 | |
196 | #define DLIL_DESC_802_2_SNAP 3 | |
197 | ||
198 | struct dlil_demux_desc { | |
199 | TAILQ_ENTRY(dlil_demux_desc) next; | |
200 | int type; | |
201 | ||
202 | u_char *native_type; | |
203 | union { | |
204 | struct { | |
205 | u_long proto_id_length; /* IN LONGWORDS!!! */ | |
206 | u_char *proto_id; | |
207 | u_char *proto_id_mask; | |
208 | ||
209 | } bitmask; | |
210 | ||
211 | struct { | |
212 | u_char dsap; | |
213 | u_char ssap; | |
214 | u_char control_code; | |
215 | u_char pad; | |
216 | } desc_802_2; | |
217 | ||
218 | struct { | |
219 | u_char dsap; | |
220 | u_char ssap; | |
221 | u_char control_code; | |
222 | u_char org[3]; | |
223 | u_short protocol_type; | |
224 | } desc_802_2_SNAP; | |
225 | } variants; | |
226 | }; | |
227 | ||
228 | TAILQ_HEAD(ddesc_head_str, dlil_demux_desc); | |
229 | ||
230 | ||
231 | struct dlil_proto_reg_str { | |
232 | struct ddesc_head_str demux_desc_head; | |
233 | u_long interface_family; | |
234 | u_long protocol_family; | |
235 | short unit_number; | |
236 | int default_proto; /* 0 or 1 */ | |
237 | dl_input_func input; | |
238 | dl_pre_output_func pre_output; | |
239 | dl_event_func event; | |
240 | dl_offer_func offer; | |
241 | dl_ioctl_func ioctl; | |
0b4e3aa0 | 242 | u_long reserved[4]; |
1c79356b A |
243 | }; |
244 | ||
245 | ||
246 | int dlil_attach_interface_filter(struct ifnet *ifnet_ptr, | |
247 | struct dlil_if_flt_str *interface_filter, | |
248 | u_long *filter_id, | |
249 | int insertion_point); | |
250 | ||
251 | int | |
252 | dlil_input(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail); | |
253 | ||
254 | int | |
255 | dlil_output(u_long dl_tag, | |
256 | struct mbuf *m, | |
257 | caddr_t route, | |
258 | struct sockaddr *dest, | |
259 | int raw); | |
260 | ||
261 | ||
262 | int | |
263 | dlil_ioctl(u_long proto_family, | |
264 | struct ifnet *ifp, | |
265 | u_long ioctl_code, | |
266 | caddr_t ioctl_arg); | |
267 | ||
268 | int | |
269 | dlil_attach_protocol(struct dlil_proto_reg_str *proto, | |
270 | u_long *dl_tag); | |
271 | ||
272 | int | |
273 | dlil_detach_protocol(u_long dl_tag); | |
274 | ||
275 | int | |
276 | dlil_if_attach(struct ifnet *ifp); | |
277 | ||
278 | int | |
279 | dlil_attach_protocol_filter(u_long dl_tag, | |
280 | struct dlil_pr_flt_str *proto_filter, | |
281 | u_long *filter_id, | |
282 | int insertion_point); | |
283 | int | |
284 | dlil_detach_filter(u_long filter_id); | |
285 | ||
286 | struct dlil_ifmod_reg_str { | |
287 | int (*add_if)(struct ifnet *ifp); | |
288 | int (*del_if)(struct ifnet *ifp); | |
289 | int (*add_proto)(struct ddesc_head_str *demux_desc_head, | |
290 | struct if_proto *proto, u_long dl_tag); | |
291 | int (*del_proto)(struct if_proto *proto, u_long dl_tag); | |
292 | int (*ifmod_ioctl)(struct ifnet *ifp, u_long ioctl_cmd, caddr_t data); | |
293 | int (*shutdown)(); | |
0b4e3aa0 | 294 | u_long reserved[4]; |
1c79356b A |
295 | }; |
296 | ||
297 | ||
298 | int dlil_reg_if_modules(u_long interface_family, | |
299 | struct dlil_ifmod_reg_str *ifmod_reg); | |
300 | ||
301 | int | |
302 | dlil_inject_if_input(struct mbuf *m, char *frame_header, u_long from_id); | |
303 | ||
304 | int | |
305 | dlil_inject_pr_input(struct mbuf *m, char *frame_header, u_long from_id); | |
306 | ||
307 | int | |
308 | dlil_inject_pr_output(struct mbuf *m, | |
309 | struct sockaddr *dest, | |
310 | int raw, | |
311 | char *frame_type, | |
312 | char *dst_linkaddr, | |
313 | u_long from_id); | |
314 | ||
315 | int | |
316 | dlil_inject_if_output(struct mbuf *m, u_long from_id); | |
317 | ||
318 | int | |
319 | dlil_find_dltag(u_long if_family, short unit, u_long proto_family, u_long *dl_tag); | |
320 | ||
321 | ||
322 | int | |
323 | dlil_event(struct ifnet *ifp, struct kern_event_msg *event); | |
324 | ||
325 | int dlil_dereg_if_modules(u_long interface_family); | |
326 | ||
327 | int | |
328 | dlil_if_detach(struct ifnet *ifp); | |
329 | ||
330 | #endif /* DLIL_H */ |