xref: /original-bsd/sys/net/bpfdesc.h (revision ba762ddc)
1 /*
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code distributions
7  * retain the above copyright notice and this paragraph in its entirety, (2)
8  * distributions including binary code include the above copyright notice and
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the University of California,
13  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14  * the University nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior
16  * written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * @(#) $Header: bpfdesc.h,v 1.7 90/12/04 01:05:01 mccanne Exp $ (LBL)
22  *
23  * This code is derived from the Stanford/CMU enet packet filter,
24  * (net/enetdefs.h) distributed in 4.3BSD Unix.
25  */
26 
27 /*
28  * Descriptor associated with each open bpf file.
29  */
30 struct bpf_d {
31 	struct bpf_d	*bd_next;	/* Linked list of descriptors */
32 	/*
33 	 * Buffer slots: two mbuf clusters buffer the incoming packets.
34 	 *   The model has three slots.  Sbuf is always occupied.
35 	 *   sbuf (store) - Receive interrupt puts packets here.
36 	 *   hbuf (hold) - When sbuf is full, put cluster here and
37 	 *                 wakeup read (replace sbuf with fbuf).
38 	 *   fbuf (free) - When read is done, put cluster here.
39 	 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
40 	 */
41 	caddr_t		bd_sbuf;	/* store slot */
42 	caddr_t		bd_hbuf;	/* hold slot */
43 	caddr_t		bd_fbuf;	/* free slot */
44 	int 		bd_slen;	/* current length of store buffer */
45 	int 		bd_hlen;	/* current length of hold buffer */
46 
47 	int		bd_bufsize;	/* absolute length of buffers */
48 
49 	struct bpf_if *	bd_bif;		/* interface descriptor */
50 	u_long		bd_rtout;	/* Read timeout in 'ticks' */
51 	struct bpf_insn *bd_filter; 	/* filter code */
52 	u_long		bd_rcount;	/* number of packets received */
53 	u_long		bd_dcount;	/* number of packets dropped */
54 	struct proc *	bd_selproc;	/* process that last selected us */
55 
56 	u_char		bd_promisc;	/* true if listening promiscuously */
57 	u_char		bd_state;	/* idle, waiting, or timed out */
58 	u_char		bd_selcoll;	/* true if selects collide */
59 	u_char		bd_immediate;	/* true to return on packet arrival */
60 };
61 
62 /*
63  * Descriptor associated with each attached hardware interface.
64  */
65 struct bpf_if {
66 	/* List of descriptors listening on this interface. */
67 	struct bpf_d *bif_dlist;
68 
69 	/* Pointer to the device driver's softc bpf field. */
70 	struct bpf_if **bif_driverp;
71 
72 	/* Device parameters, see bpf.h. */
73 	struct bpf_devp bif_devp;
74 
75 	/* Length of bpf header (bpf_hdr + padding). */
76 	u_int bif_hdrlen;
77 
78 	/* 'ifnet' of associated interface. */
79 	struct ifnet *bif_ifp;
80 };
81