xref: /freebsd/sys/net/bpfdesc.h (revision cea1da3be2dd73c9fb2a1bd844f1959cb10c172b)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1990, 1991, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from the Stanford/CMU enet packet filter,
6df8bae1dSRodney W. Grimes  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7df8bae1dSRodney W. Grimes  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8df8bae1dSRodney W. Grimes  * Berkeley Laboratory.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  *      @(#)bpfdesc.h	8.1 (Berkeley) 6/10/93
39df8bae1dSRodney W. Grimes  *
40cea1da3bSPaul Richards  * $Id: bpfdesc.h,v 1.3 1994/08/02 07:46:00 davidg Exp $
41df8bae1dSRodney W. Grimes  */
42df8bae1dSRodney W. Grimes 
43cea1da3bSPaul Richards #ifndef _NET_BPFDESC_H_
44cea1da3bSPaul Richards #define _NET_BPFDESC_H_
45cea1da3bSPaul Richards 
4626f9a767SRodney W. Grimes #include <sys/select.h>
4726f9a767SRodney W. Grimes 
48df8bae1dSRodney W. Grimes /*
49df8bae1dSRodney W. Grimes  * Descriptor associated with each open bpf file.
50df8bae1dSRodney W. Grimes  */
51df8bae1dSRodney W. Grimes struct bpf_d {
52df8bae1dSRodney W. Grimes 	struct bpf_d	*bd_next;	/* Linked list of descriptors */
53df8bae1dSRodney W. Grimes 	/*
54df8bae1dSRodney W. Grimes 	 * Buffer slots: two mbuf clusters buffer the incoming packets.
55df8bae1dSRodney W. Grimes 	 *   The model has three slots.  Sbuf is always occupied.
56df8bae1dSRodney W. Grimes 	 *   sbuf (store) - Receive interrupt puts packets here.
57df8bae1dSRodney W. Grimes 	 *   hbuf (hold) - When sbuf is full, put cluster here and
58df8bae1dSRodney W. Grimes 	 *                 wakeup read (replace sbuf with fbuf).
59df8bae1dSRodney W. Grimes 	 *   fbuf (free) - When read is done, put cluster here.
60df8bae1dSRodney W. Grimes 	 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
61df8bae1dSRodney W. Grimes 	 */
62df8bae1dSRodney W. Grimes 	caddr_t		bd_sbuf;	/* store slot */
63df8bae1dSRodney W. Grimes 	caddr_t		bd_hbuf;	/* hold slot */
64df8bae1dSRodney W. Grimes 	caddr_t		bd_fbuf;	/* free slot */
65df8bae1dSRodney W. Grimes 	int 		bd_slen;	/* current length of store buffer */
66df8bae1dSRodney W. Grimes 	int 		bd_hlen;	/* current length of hold buffer */
67df8bae1dSRodney W. Grimes 
68df8bae1dSRodney W. Grimes 	int		bd_bufsize;	/* absolute length of buffers */
69df8bae1dSRodney W. Grimes 
70df8bae1dSRodney W. Grimes 	struct bpf_if *	bd_bif;		/* interface descriptor */
71df8bae1dSRodney W. Grimes 	u_long		bd_rtout;	/* Read timeout in 'ticks' */
72df8bae1dSRodney W. Grimes 	struct bpf_insn *bd_filter; 	/* filter code */
73df8bae1dSRodney W. Grimes 	u_long		bd_rcount;	/* number of packets received */
74df8bae1dSRodney W. Grimes 	u_long		bd_dcount;	/* number of packets dropped */
75df8bae1dSRodney W. Grimes 
76df8bae1dSRodney W. Grimes 	u_char		bd_promisc;	/* true if listening promiscuously */
77df8bae1dSRodney W. Grimes 	u_char		bd_state;	/* idle, waiting, or timed out */
78df8bae1dSRodney W. Grimes 	u_char		bd_immediate;	/* true to return on packet arrival */
79df8bae1dSRodney W. Grimes #if BSD < 199103
80df8bae1dSRodney W. Grimes 	u_char		bd_selcoll;	/* true if selects collide */
81df8bae1dSRodney W. Grimes 	int		bd_timedout;
82df8bae1dSRodney W. Grimes 	struct proc *	bd_selproc;	/* process that last selected us */
83df8bae1dSRodney W. Grimes #else
84df8bae1dSRodney W. Grimes 	u_char		bd_pad;		/* explicit alignment */
85df8bae1dSRodney W. Grimes 	struct selinfo	bd_sel;		/* bsd select info */
86df8bae1dSRodney W. Grimes #endif
87df8bae1dSRodney W. Grimes };
88df8bae1dSRodney W. Grimes 
89df8bae1dSRodney W. Grimes /*
90df8bae1dSRodney W. Grimes  * Descriptor associated with each attached hardware interface.
91df8bae1dSRodney W. Grimes  */
92df8bae1dSRodney W. Grimes struct bpf_if {
93df8bae1dSRodney W. Grimes 	struct bpf_if *bif_next;	/* list of all interfaces */
94df8bae1dSRodney W. Grimes 	struct bpf_d *bif_dlist;	/* descriptor list */
95df8bae1dSRodney W. Grimes 	struct bpf_if **bif_driverp;	/* pointer into softc */
96df8bae1dSRodney W. Grimes 	u_int bif_dlt;			/* link layer type */
97df8bae1dSRodney W. Grimes 	u_int bif_hdrlen;		/* length of header (with padding) */
98df8bae1dSRodney W. Grimes 	struct ifnet *bif_ifp;		/* correspoding interface */
99df8bae1dSRodney W. Grimes };
100df8bae1dSRodney W. Grimes 
101df8bae1dSRodney W. Grimes #ifdef KERNEL
102df8bae1dSRodney W. Grimes int	 bpf_setf __P((struct bpf_d *, struct bpf_program *));
103df8bae1dSRodney W. Grimes #endif
104cea1da3bSPaul Richards 
105cea1da3bSPaul Richards #endif
106