xref: /openbsd-src/sys/net/bpfdesc.h (revision 1511e544c2133eb425911df1402f18e15bb5ab0c)
1*1511e544Sdlg /*	$OpenBSD: bpfdesc.h,v 1.50 2024/11/19 23:26:35 dlg Exp $	*/
2df930be7Sderaadt /*	$NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1990, 1991, 1993
6df930be7Sderaadt  *	The Regents of the University of California.  All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * This code is derived from the Stanford/CMU enet packet filter,
9df930be7Sderaadt  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
10df930be7Sderaadt  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
11df930be7Sderaadt  * Berkeley Laboratory.
12df930be7Sderaadt  *
13df930be7Sderaadt  * Redistribution and use in source and binary forms, with or without
14df930be7Sderaadt  * modification, are permitted provided that the following conditions
15df930be7Sderaadt  * are met:
16df930be7Sderaadt  * 1. Redistributions of source code must retain the above copyright
17df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer.
18df930be7Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
19df930be7Sderaadt  *    notice, this list of conditions and the following disclaimer in the
20df930be7Sderaadt  *    documentation and/or other materials provided with the distribution.
2129295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
22df930be7Sderaadt  *    may be used to endorse or promote products derived from this software
23df930be7Sderaadt  *    without specific prior written permission.
24df930be7Sderaadt  *
25df930be7Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26df930be7Sderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27df930be7Sderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28df930be7Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29df930be7Sderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30df930be7Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31df930be7Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32df930be7Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33df930be7Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34df930be7Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35df930be7Sderaadt  * SUCH DAMAGE.
36df930be7Sderaadt  *
37df930be7Sderaadt  *	@(#)bpfdesc.h	8.1 (Berkeley) 6/10/93
38df930be7Sderaadt  */
39df930be7Sderaadt 
40e04c8cc2Sangelos #ifndef _NET_BPFDESC_H_
41e04c8cc2Sangelos #define _NET_BPFDESC_H_
42e04c8cc2Sangelos 
43a0e69eb0Sderaadt #ifdef _KERNEL
44a0e69eb0Sderaadt 
4554b38311Scheloha /*
4654b38311Scheloha  * Locks used to protect struct members in this file:
4754b38311Scheloha  *
4854b38311Scheloha  *	m	the per-descriptor mutex (bpf_d.bd_mtx)
4954b38311Scheloha  */
5054b38311Scheloha 
511985f0acSsashan struct bpf_program_smr {
521985f0acSsashan 	struct bpf_program	bps_bf;
531985f0acSsashan 	struct smr_entry	bps_smr;
541985f0acSsashan };
551985f0acSsashan 
56df930be7Sderaadt /*
57df930be7Sderaadt  * Descriptor associated with each open bpf file.
58df930be7Sderaadt  */
59df930be7Sderaadt struct bpf_d {
601985f0acSsashan 	SMR_SLIST_ENTRY(bpf_d) bd_next;	/* Linked list of descriptors */
61df930be7Sderaadt 	/*
62df930be7Sderaadt 	 * Buffer slots: two mbuf clusters buffer the incoming packets.
63df930be7Sderaadt 	 *   The model has three slots.  Sbuf is always occupied.
64df930be7Sderaadt 	 *   sbuf (store) - Receive interrupt puts packets here.
65df930be7Sderaadt 	 *   hbuf (hold) - When sbuf is full, put cluster here and
66df930be7Sderaadt 	 *                 wakeup read (replace sbuf with fbuf).
67df930be7Sderaadt 	 *   fbuf (free) - When read is done, put cluster here.
68df930be7Sderaadt 	 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
69df930be7Sderaadt 	 */
70818507ecSmpi 	struct mutex	bd_mtx;		/* protect buffer slots below */
71df930be7Sderaadt 	caddr_t		bd_sbuf;	/* store slot */
72df930be7Sderaadt 	caddr_t		bd_hbuf;	/* hold slot */
73df930be7Sderaadt 	caddr_t		bd_fbuf;	/* free slot */
74df930be7Sderaadt 	int		bd_slen;	/* current length of store buffer */
75df930be7Sderaadt 	int		bd_hlen;	/* current length of hold buffer */
7687ae5947Smpi 	int		bd_bufsize;	/* absolute length of buffers */
77e00eb003Smpi 
78818507ecSmpi 	int		bd_in_uiomove;	/* for debugging purpose */
79818507ecSmpi 
80df930be7Sderaadt 	struct bpf_if  *bd_bif;		/* interface descriptor */
815c0cf745Scheloha 	uint64_t	bd_rtout;	/* [m] Read timeout in nanoseconds */
82b9a6c834Sdlg 	uint64_t	bd_wtout;	/* [m] Wait time in nanoseconds */
831775b5e9Scheloha 	u_long		bd_nreaders;	/* [m] # threads asleep in bpfread() */
841985f0acSsashan 	struct bpf_program_smr
851985f0acSsashan 		       *bd_rfilter;	/* read filter code */
861985f0acSsashan 	struct bpf_program_smr
871985f0acSsashan 		       *bd_wfilter;	/* write filter code */
88df930be7Sderaadt 	u_long		bd_rcount;	/* number of packets received */
89df930be7Sderaadt 	u_long		bd_dcount;	/* number of packets dropped */
90df930be7Sderaadt 
91df930be7Sderaadt 	u_char		bd_promisc;	/* true if listening promiscuously */
92b9a6c834Sdlg 	u_char		bd_state;	/* [m] idle, waiting, or timed out */
9312054a8cScanacar 	u_char		bd_locked;	/* true if descriptor is locked */
947f231149Scanacar 	u_char		bd_fildrop;	/* true if filtered packets will be dropped */
95c4acdf64Sdjm 	u_char		bd_dirfilt;	/* direction filter */
96a2c9c1a6Sdugsong 	int		bd_hdrcmplt;	/* false to fill in src lladdr automatically */
97df930be7Sderaadt 	int		bd_async;	/* non-zero if packet reception should generate signal */
98df930be7Sderaadt 	int		bd_sig;		/* signal to send upon packet reception */
998864b422Sclaudio 	struct sigio_ref
1008864b422Sclaudio 			bd_sigio;	/* async I/O registration */
1018f99bf68Svisa 	struct refcnt	bd_refcnt;	/* reference count */
102a820167aSvisa 	struct klist	bd_klist;	/* list of knotes */
1036d5d8f80Sgrange 	int		bd_unit;	/* logical unit number */
1046d5d8f80Sgrange 	LIST_ENTRY(bpf_d) bd_list;	/* descriptor list */
1059d96c75bSmpi 
106b9a6c834Sdlg 	struct task	bd_wake_task;	/* defer pgsigio() and selwakeup() */
107b9a6c834Sdlg 	struct timeout	bd_wait_tmo;	/* delay wakeup after catching pkt */
1081985f0acSsashan 
1091985f0acSsashan 	struct smr_entry
1101985f0acSsashan 			bd_smr;
111df930be7Sderaadt };
112df930be7Sderaadt 
113df930be7Sderaadt /*
114df930be7Sderaadt  * Descriptor associated with each attached hardware interface.
115df930be7Sderaadt  */
116df930be7Sderaadt struct bpf_if {
117*1511e544Sdlg 	TAILQ_ENTRY(bpf_if) bif_next;	/* list of all interfaces */
1181985f0acSsashan 	SMR_SLIST_HEAD(, bpf_d) bif_dlist;		/* descriptor list */
119df930be7Sderaadt 	struct bpf_if **bif_driverp;	/* pointer into softc */
120df930be7Sderaadt 	u_int bif_dlt;			/* link layer type */
121df930be7Sderaadt 	u_int bif_hdrlen;		/* length of header (with padding) */
122a60ac7a2Sdlg 	const char *bif_name;		/* name of "subsystem" */
1237574e102Slteo 	struct ifnet *bif_ifp;		/* corresponding interface */
124df930be7Sderaadt };
125df930be7Sderaadt 
126e88074f0Sdlg int	 bpf_setf(struct bpf_d *, struct bpf_program *, u_long);
127e04c8cc2Sangelos #endif /* _KERNEL */
128e04c8cc2Sangelos #endif /* _NET_BPFDESC_H_ */
129