1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#ifndef DLIL_H
29#define DLIL_H
30#ifdef KERNEL
31#include <sys/kernel_types.h>
32#include <net/kpi_interface.h>
33
34#if __STDC__
35
36struct ifnet;
37struct mbuf;
38struct ether_header;
39struct sockaddr_dl;
40
41#endif
42
43
44#ifdef KERNEL_PRIVATE
45#define DLIL_LAST_FILTER -1
46#define DLIL_NULL_FILTER -2
47
48#define DLIL_WAIT_FOR_FREE -2
49
50#define DLIL_BLUEBOX 1
51
52
53
54#include <net/if.h>
55#include <net/if_var.h>
56#include <sys/kern_event.h>
57
58#endif KERNEL_PRIVATE
59
60enum {
61 BPF_TAP_DISABLE,
62 BPF_TAP_INPUT,
63 BPF_TAP_OUTPUT,
64 BPF_TAP_INPUT_OUTPUT
65};
66
67#ifdef KERNEL_PRIVATE
68struct kev_msg;
69struct iff_filter;
70
71struct dlil_if_flt_str {
72 caddr_t cookie;
73 int (*filter_if_input)(caddr_t cookie,
74 struct ifnet **ifp,
75 struct mbuf **mbuf_ptr,
76 char **frame_ptr);
77
78 int (*filter_if_event)(caddr_t cookie,
79 struct ifnet *ifp,
80 struct kev_msg *event_msg_ptr);
81
82 int (*filter_if_output)(caddr_t cookie,
83 struct ifnet **ifp,
84 struct mbuf **mbuf_ptr);
85
86
87 int (*filter_if_ioctl)(caddr_t cookie,
88 struct ifnet *ifp,
89 u_long ioctl_code_ptr,
90 caddr_t ioctl_arg_ptr);
91
92 int (*filter_if_free)(caddr_t cookie,
93 struct ifnet *ifp);
94
95 int (*filter_detach)(caddr_t cookie);
96 u_long reserved[2];
97};
98
99#define DLIL_PR_FILTER 1
100#define DLIL_IF_FILTER 2
101
102
103
104typedef int (*dl_input_func)(struct mbuf *m, char *frame_header,
105 struct ifnet *ifp, u_long protocol_family, int sync_ok);
106typedef int (*dl_pre_output_func)(struct ifnet *ifp,
107 u_long protocol_family,
108 struct mbuf **m,
109 const struct sockaddr *dest,
110 caddr_t route_entry,
111 char *frame_type,
112 char *dst_addr);
113
114typedef void (*dl_event_func)(struct ifnet *ifp, struct kev_msg *event);
115
116typedef int (*dl_offer_func)(struct mbuf *m, char *frame_header);
117typedef int (*dl_ioctl_func)(u_long protocol_family,
118 struct ifnet *ifp,
119 u_long ioctl_cmd,
120 caddr_t ioctl_arg);
121typedef int (*dl_detached_func)(u_long protocol_family, struct ifnet *ifp);
122
123
124#define DLIL_DESC_RAW 1
125#define DLIL_DESC_802_2 2
126#define DLIL_DESC_802_2_SNAP 3
127
128
129
130
131
132
133
134
135#endif KERNEL_PRIVATE
136
137
138#define DLIL_DESC_ETYPE2 4
139#define DLIL_DESC_SAP 5
140#define DLIL_DESC_SNAP 6
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157#ifdef KERNEL_PRIVATE
158struct dlil_demux_desc {
159 TAILQ_ENTRY(dlil_demux_desc) next;
160
161 int type;
162 u_char *native_type;
163
164 union {
165
166
167 struct {
168 u_long proto_id_length;
169 u_char *proto_id;
170 u_char *proto_id_mask;
171 } bitmask;
172
173 struct {
174 u_char dsap;
175 u_char ssap;
176 u_char control_code;
177 u_char pad;
178 } desc_802_2;
179
180 struct {
181 u_char dsap;
182 u_char ssap;
183 u_char control_code;
184 u_char org[3];
185 u_short protocol_type;
186 } desc_802_2_SNAP;
187
188
189 u_int32_t native_type_length;
190 } variants;
191};
192
193TAILQ_HEAD(ddesc_head_str, dlil_demux_desc);
194
195struct dlil_proto_reg_str {
196 struct ddesc_head_str demux_desc_head;
197 u_long interface_family;
198 u_long protocol_family;
199 short unit_number;
200 int default_proto;
201 dl_input_func input;
202 dl_pre_output_func pre_output;
203 dl_event_func event;
204 dl_offer_func offer;
205 dl_ioctl_func ioctl;
206 dl_detached_func detached;
207 u_long reserved[3];
208};
209
210
211int dlil_attach_filter(struct ifnet *ifp, const struct iff_filter *if_filter,
212 interface_filter_t *filter_ref);
213
214struct ifnet_stat_increment_param;
215
216int
217dlil_input_with_stats(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail,
218 const struct ifnet_stat_increment_param *stats);
219
220int
221dlil_input(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail);
222
223int
224dlil_output_list(
225 struct ifnet *ifp,
226 u_long protocol_family,
227 struct mbuf *packetlist,
228 caddr_t route,
229 const struct sockaddr *dest,
230 int raw);
231
232int
233dlil_output(
234 struct ifnet *ifp,
235 u_long protocol_family,
236 struct mbuf *m,
237 caddr_t route,
238 const struct sockaddr *dest,
239 int raw);
240
241
242int
243dlil_ioctl(u_long proto_family,
244 struct ifnet *ifp,
245 u_long ioctl_code,
246 caddr_t ioctl_arg);
247
248errno_t
249dlil_resolve_multi(
250 struct ifnet *ifp,
251 const struct sockaddr *proto_addr,
252 struct sockaddr *ll_addr,
253 size_t ll_len);
254
255
256
257
258
259errno_t
260dlil_send_arp_internal(
261 ifnet_t ifp,
262 u_int16_t arpop,
263 const struct sockaddr_dl* sender_hw,
264 const struct sockaddr* sender_proto,
265 const struct sockaddr_dl* target_hw,
266 const struct sockaddr* target_proto);
267
268errno_t
269dlil_send_arp(
270 ifnet_t ifp,
271 u_int16_t arpop,
272 const struct sockaddr_dl* sender_hw,
273 const struct sockaddr* sender_proto,
274 const struct sockaddr_dl* target_hw,
275 const struct sockaddr* target_proto);
276
277int
278dlil_ioctl_locked(u_long proto_family,
279 struct ifnet *ifp,
280 u_long ioctl_code,
281 caddr_t ioctl_arg);
282
283int
284dlil_attach_protocol(struct dlil_proto_reg_str *proto);
285
286int
287dlil_detach_protocol(struct ifnet *ifp, u_long protocol_family);
288
289int
290dlil_if_attach(struct ifnet *ifp);
291
292#ifdef BSD_KERNEL_PRIVATE
293
294int
295dlil_if_attach_with_address(
296 struct ifnet *ifp,
297 const struct sockaddr_dl *ll_addr);
298
299int
300dlil_attach_protocol_kpi(ifnet_t ifp, protocol_family_t protocol,
301 const struct ifnet_attach_proto_param *proto_details);
302
303errno_t dlil_set_bpf_tap(ifnet_t ifp, bpf_tap_mode mode,
304 bpf_packet_func callback);
305
306#endif
307
308void
309dlil_detach_filter(interface_filter_t filter);
310
311struct dlil_ifmod_reg_str {
312 int (*add_if)(struct ifnet *ifp);
313 int (*del_if)(struct ifnet *ifp);
314 int (*add_proto)(struct ifnet *ifp, u_long protocol_family,
315 struct ddesc_head_str *demux_desc_head);
316#ifdef __KPI_INTERFACE__
317 ifnet_del_proto_func del_proto;
318 ifnet_ioctl_func ifmod_ioctl;
319#else
320 void* del_proto;
321 void* ifmod_ioctl;
322#endif
323 int (*shutdown)(void);
324 int (*init_if)(struct ifnet *ifp);
325 u_long reserved[3];
326};
327
328
329int dlil_reg_if_modules(u_long interface_family,
330 struct dlil_ifmod_reg_str *ifmod_reg);
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374int dlil_reg_proto_module(u_long protocol_family, u_long interface_family,
375 int (*attach)(struct ifnet *ifp, u_long protocol_family),
376 int (*detach)(struct ifnet *ifp, u_long protocol_family));
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404int dlil_dereg_proto_module(u_long protocol_family, u_long interface_family);
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433int dlil_plumb_protocol(u_long protocol_family, struct ifnet *ifp);
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463int dlil_unplumb_protocol(u_long protocol_family, struct ifnet *ifp);
464
465int
466dlil_inject_if_input(struct mbuf *m, char *frame_header, u_long from_id);
467
468int
469dlil_inject_pr_input(struct mbuf *m, char *frame_header, u_long from_id);
470
471int
472dlil_inject_pr_output(struct mbuf *m,
473 struct sockaddr *dest,
474 int raw,
475 char *frame_type,
476 char *dst_linkaddr,
477 u_long from_id);
478
479int
480dlil_inject_if_output(struct mbuf *m, u_long from_id);
481
482#ifdef KERNEL_PRIVATE
483void
484dlil_post_msg(struct ifnet *ifp,u_long event_subclass, u_long event_code,
485 struct net_event_data *event_data, u_long event_data_len);
486#endif
487
488int
489dlil_event(struct ifnet *ifp, struct kern_event_msg *event);
490
491int dlil_dereg_if_modules(u_long interface_family);
492
493int
494dlil_if_detach(struct ifnet *ifp);
495
496void
497ifp_reference(struct ifnet *ifp);
498
499void
500ifp_release(struct ifnet *ifp);
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581int dlil_if_acquire(u_long family, const void *uniqueid, size_t uniqueid_len,
582 struct ifnet **ifp);
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606void dlil_if_release(struct ifnet *ifp);
607
608#endif
609#endif
610#endif
611