bpfdesc.h revision 1.43 1 /* $NetBSD: bpfdesc.h,v 1.43 2017/02/01 08:16:42 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 #endif
53
54 /*
55 * Descriptor associated with each open bpf file.
56 */
57 struct bpf_d {
58 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
59 struct bpf_d *_bd_next; /* Linked list of descriptors */
60 /*
61 * Buffer slots: two mbuf clusters buffer the incoming packets.
62 * The model has three slots. Sbuf is always occupied.
63 * sbuf (store) - Receive interrupt puts packets here.
64 * hbuf (hold) - When sbuf is full, put cluster here and
65 * wakeup read (replace sbuf with fbuf).
66 * fbuf (free) - When read is done, put cluster here.
67 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
68 */
69 void * bd_sbuf; /* store slot */
70 void * bd_hbuf; /* hold slot */
71 void * bd_fbuf; /* free slot */
72 int bd_slen; /* current length of store buffer */
73 int bd_hlen; /* current length of hold buffer */
74
75 int bd_bufsize; /* absolute length of buffers */
76
77 struct bpf_if * bd_bif; /* interface descriptor */
78 u_long bd_rtout; /* Read timeout in 'ticks' */
79 struct bpf_insn *bd_filter; /* filter code */
80 u_long bd_rcount; /* number of packets received */
81 u_long bd_dcount; /* number of packets dropped */
82 u_long bd_ccount; /* number of packets captured */
83
84 u_char bd_promisc; /* true if listening promiscuously */
85 u_char bd_state; /* idle, waiting, or timed out */
86 u_char bd_immediate; /* true to return on packet arrival */
87 int bd_hdrcmplt; /* false to fill in src lladdr */
88 int bd_seesent; /* true if bpf should see sent packets */
89 int bd_feedback; /* true to feed back sent packets */
90 int bd_async; /* non-zero if packet reception should generate signal */
91 pid_t bd_pgid; /* process or group id for signal */
92 #if BSD < 199103
93 u_char bd_selcoll; /* true if selects collide */
94 int bd_timedout;
95 struct proc * bd_selproc; /* process that last selected us */
96 #else
97 u_char bd_pad; /* explicit alignment */
98 struct selinfo bd_sel; /* bsd select info */
99 #endif
100 callout_t bd_callout; /* for BPF timeouts with select */
101 pid_t bd_pid; /* corresponding PID */
102 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
103 LIST_ENTRY(bpf_d) _bd_list; /* list of all BPF's */
104 void *bd_sih; /* soft interrupt handle */
105 struct timespec bd_atime; /* access time */
106 struct timespec bd_mtime; /* modification time */
107 struct timespec bd_btime; /* birth time */
108 #ifdef _LP64
109 int bd_compat32; /* 32-bit stream on LP64 system */
110 #endif
111 bpfjit_func_t bd_jitcode; /* compiled filter program */
112 size_t bd_filter_size;
113 #ifdef _KERNEL
114 struct pslist_entry bd_bif_dlist_entry; /* For bpf_if */
115 struct pslist_entry bd_bpf_dlist_entry; /* For the global list */
116 kmutex_t *bd_mtx;
117 kcondvar_t bd_cv;
118 #endif
119 };
120
121
122 /* Values for bd_state */
123 #define BPF_IDLE 0 /* no select in progress */
124 #define BPF_WAITING 1 /* waiting for read timeout in select */
125 #define BPF_TIMED_OUT 2 /* read timeout has expired in select */
126
127 /*
128 * Description associated with the external representation of each
129 * open bpf file.
130 */
131 struct bpf_d_ext {
132 int32_t bde_bufsize;
133 uint8_t bde_promisc;
134 uint8_t bde_state;
135 uint8_t bde_immediate;
136 int32_t bde_hdrcmplt;
137 int32_t bde_seesent;
138 pid_t bde_pid;
139 uint64_t bde_rcount; /* number of packets received */
140 uint64_t bde_dcount; /* number of packets dropped */
141 uint64_t bde_ccount; /* number of packets captured */
142 char bde_ifname[IFNAMSIZ];
143 };
144
145
146 /*
147 * Descriptor associated with each attached hardware interface.
148 */
149 struct bpf_if {
150 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
151 struct bpf_if *_bif_next; /* list of all interfaces */
152 struct bpf_d *_bif_dlist; /* descriptor list */
153 struct bpf_if **bif_driverp; /* pointer into softc */
154 u_int bif_dlt; /* link layer type */
155 u_int bif_hdrlen; /* length of header (with padding) */
156 struct ifnet *bif_ifp; /* corresponding interface */
157 void *bif_si;
158 struct mbuf *bif_mbuf_head;
159 struct mbuf *bif_mbuf_tail;
160 #ifdef _KERNEL
161 struct pslist_entry bif_iflist_entry;
162 struct pslist_head bif_dlist_head;
163 #endif
164 };
165
166 #endif /* !_NET_BPFDESC_H_ */
167