bpfdesc.h revision 1.45 1 /* $NetBSD: bpfdesc.h,v 1.45 2018/01/25 02:45:02 ozaki-r Exp $ */
2
3 /*
4 * Copyright (c) 1990, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from the Stanford/CMU enet packet filter,
8 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10 * Berkeley Laboratory.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)bpfdesc.h 8.1 (Berkeley) 6/10/93
37 *
38 * @(#) Header: bpfdesc.h,v 1.14 96/06/16 22:28:07 leres Exp (LBL)
39 */
40
41 #ifndef _NET_BPFDESC_H_
42 #define _NET_BPFDESC_H_
43
44 #include <sys/callout.h>
45 #include <sys/selinfo.h> /* for struct selinfo */
46 #include <net/if.h> /* for IFNAMSIZ */
47 #include <net/bpfjit.h> /* for bpfjit_function_t */
48 #ifdef _KERNEL
49 #include <sys/pslist.h>
50 #include <sys/mutex.h>
51 #include <sys/condvar.h>
52 #include <sys/psref.h>
53 #endif
54
55 struct bpf_filter {
56 struct bpf_insn *bf_insn; /* filter code */
57 size_t bf_size;
58 bpfjit_func_t bf_jitcode; /* compiled filter program */
59 };
60
61 /*
62 * Descriptor associated with each open bpf file.
63 */
64 struct bpf_d {
65 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
66 struct bpf_d *_bd_next; /* Linked list of descriptors */
67 /*
68 * Buffer slots: two mbuf clusters buffer the incoming packets.
69 * The model has three slots. Sbuf is always occupied.
70 * sbuf (store) - Receive interrupt puts packets here.
71 * hbuf (hold) - When sbuf is full, put cluster here and
72 * wakeup read (replace sbuf with fbuf).
73 * fbuf (free) - When read is done, put cluster here.
74 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
75 */
76 void * bd_sbuf; /* store slot */
77 void * bd_hbuf; /* hold slot */
78 void * bd_fbuf; /* free slot */
79 int bd_slen; /* current length of store buffer */
80 int bd_hlen; /* current length of hold buffer */
81
82 int bd_bufsize; /* absolute length of buffers */
83
84 struct bpf_if * bd_bif; /* interface descriptor */
85 u_long bd_rtout; /* Read timeout in 'ticks' */
86 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
87 struct bpf_insn *_bd_filter; /* filter code */
88 /*
89 * XXX we should make the counters per-CPU once we retire kvm(3) users
90 * that directly access them.
91 */
92 u_long bd_rcount; /* number of packets received */
93 u_long bd_dcount; /* number of packets dropped */
94 u_long bd_ccount; /* number of packets captured */
95
96 u_char bd_promisc; /* true if listening promiscuously */
97 u_char bd_state; /* idle, waiting, or timed out */
98 u_char bd_immediate; /* true to return on packet arrival */
99 int bd_hdrcmplt; /* false to fill in src lladdr */
100 int bd_seesent; /* true if bpf should see sent packets */
101 int bd_feedback; /* true to feed back sent packets */
102 int bd_async; /* non-zero if packet reception should generate signal */
103 pid_t bd_pgid; /* process or group id for signal */
104 #if BSD < 199103
105 u_char bd_selcoll; /* true if selects collide */
106 int bd_timedout;
107 struct proc * bd_selproc; /* process that last selected us */
108 #else
109 u_char bd_pad; /* explicit alignment */
110 struct selinfo bd_sel; /* bsd select info */
111 #endif
112 callout_t bd_callout; /* for BPF timeouts with select */
113 pid_t bd_pid; /* corresponding PID */
114 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
115 LIST_ENTRY(bpf_d) _bd_list; /* list of all BPF's */
116 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
117 void *bd_sih; /* soft interrupt handle */
118 struct timespec bd_atime; /* access time */
119 struct timespec bd_mtime; /* modification time */
120 struct timespec bd_btime; /* birth time */
121 #ifdef _LP64
122 int bd_compat32; /* 32-bit stream on LP64 system */
123 #endif
124 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
125 bpfjit_func_t bd_jitcode; /* compiled filter program */
126 struct bpf_filter *bd_filter;
127 #ifdef _KERNEL
128 struct pslist_entry bd_bif_dlist_entry; /* For bpf_if */
129 struct pslist_entry bd_bpf_dlist_entry; /* For the global list */
130 kmutex_t *bd_mtx;
131 kmutex_t *bd_buf_mtx;
132 kcondvar_t bd_cv;
133 #endif
134 };
135
136
137 /* Values for bd_state */
138 #define BPF_IDLE 0 /* no select in progress */
139 #define BPF_WAITING 1 /* waiting for read timeout in select */
140 #define BPF_TIMED_OUT 2 /* read timeout has expired in select */
141
142 /*
143 * Description associated with the external representation of each
144 * open bpf file.
145 */
146 struct bpf_d_ext {
147 int32_t bde_bufsize;
148 uint8_t bde_promisc;
149 uint8_t bde_state;
150 uint8_t bde_immediate;
151 int32_t bde_hdrcmplt;
152 int32_t bde_seesent;
153 pid_t bde_pid;
154 uint64_t bde_rcount; /* number of packets received */
155 uint64_t bde_dcount; /* number of packets dropped */
156 uint64_t bde_ccount; /* number of packets captured */
157 char bde_ifname[IFNAMSIZ];
158 };
159
160
161 /*
162 * Descriptor associated with each attached hardware interface.
163 */
164 struct bpf_if {
165 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
166 struct bpf_if *_bif_next; /* list of all interfaces */
167 struct bpf_d *_bif_dlist; /* descriptor list */
168 struct bpf_if **bif_driverp; /* pointer into softc */
169 u_int bif_dlt; /* link layer type */
170 u_int bif_hdrlen; /* length of header (with padding) */
171 struct ifnet *bif_ifp; /* corresponding interface */
172 void *bif_si;
173 struct mbuf *bif_mbuf_head;
174 struct mbuf *bif_mbuf_tail;
175 #ifdef _KERNEL
176 struct pslist_entry bif_iflist_entry;
177 struct pslist_head bif_dlist_head;
178 struct psref_target bif_psref;
179 #endif
180 };
181
182 #endif /* !_NET_BPFDESC_H_ */
183