2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1990, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from the Stanford/CMU enet packet filter,
|
|
|
|
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
|
|
|
|
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
|
|
|
|
* Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)bpfdesc.h 8.1 (Berkeley) 6/10/93
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
1994-08-21 05:11:48 +00:00
|
|
|
#ifndef _NET_BPFDESC_H_
|
|
|
|
#define _NET_BPFDESC_H_
|
|
|
|
|
2001-12-14 22:17:54 +00:00
|
|
|
#include <sys/callout.h>
|
2001-01-09 04:33:49 +00:00
|
|
|
#include <sys/selinfo.h>
|
2004-09-09 00:19:27 +00:00
|
|
|
#include <sys/queue.h>
|
2005-07-24 17:21:17 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <net/if.h>
|
1994-05-25 09:21:21 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Descriptor associated with each open bpf file.
|
|
|
|
*/
|
|
|
|
struct bpf_d {
|
2004-09-09 00:19:27 +00:00
|
|
|
LIST_ENTRY(bpf_d) bd_next; /* Linked list of descriptors */
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
2007-01-29 14:41:03 +00:00
|
|
|
* Buffer slots: two malloc buffers store the incoming packets.
|
1994-05-24 10:09:53 +00:00
|
|
|
* The model has three slots. Sbuf is always occupied.
|
|
|
|
* sbuf (store) - Receive interrupt puts packets here.
|
2007-01-29 14:41:03 +00:00
|
|
|
* hbuf (hold) - When sbuf is full, put buffer here and
|
1994-05-24 10:09:53 +00:00
|
|
|
* wakeup read (replace sbuf with fbuf).
|
2007-01-29 14:41:03 +00:00
|
|
|
* fbuf (free) - When read is done, put buffer here.
|
1994-05-24 10:09:53 +00:00
|
|
|
* On receiving, if sbuf is full and fbuf is 0, packet is dropped.
|
|
|
|
*/
|
|
|
|
caddr_t bd_sbuf; /* store slot */
|
|
|
|
caddr_t bd_hbuf; /* hold slot */
|
|
|
|
caddr_t bd_fbuf; /* free slot */
|
|
|
|
int bd_slen; /* current length of store buffer */
|
|
|
|
int bd_hlen; /* current length of hold buffer */
|
|
|
|
|
|
|
|
int bd_bufsize; /* absolute length of buffers */
|
|
|
|
|
|
|
|
struct bpf_if * bd_bif; /* interface descriptor */
|
|
|
|
u_long bd_rtout; /* Read timeout in 'ticks' */
|
2005-08-22 19:35:48 +00:00
|
|
|
struct bpf_insn *bd_rfilter; /* read filter code */
|
|
|
|
struct bpf_insn *bd_wfilter; /* write filter code */
|
2005-12-06 02:58:12 +00:00
|
|
|
#ifdef BPF_JITTER
|
|
|
|
bpf_jit_filter *bd_bfilter; /* binary filter code */
|
|
|
|
#endif
|
1994-05-24 10:09:53 +00:00
|
|
|
u_long bd_rcount; /* number of packets received */
|
|
|
|
u_long bd_dcount; /* number of packets dropped */
|
|
|
|
|
|
|
|
u_char bd_promisc; /* true if listening promiscuously */
|
|
|
|
u_char bd_state; /* idle, waiting, or timed out */
|
|
|
|
u_char bd_immediate; /* true to return on packet arrival */
|
1999-10-15 05:07:00 +00:00
|
|
|
int bd_hdrcmplt; /* false to fill in src lladdr automatically */
|
2007-02-26 22:24:14 +00:00
|
|
|
int bd_direction; /* select packet direction */
|
|
|
|
int bd_feedback; /* true to feed back sent packets */
|
1995-06-15 18:11:00 +00:00
|
|
|
int bd_async; /* non-zero if packet reception should generate signal */
|
|
|
|
int bd_sig; /* signal to send upon packet reception */
|
1998-11-11 10:56:07 +00:00
|
|
|
struct sigio * bd_sigio; /* information for async I/O */
|
1994-05-24 10:09:53 +00:00
|
|
|
struct selinfo bd_sel; /* bsd select info */
|
2001-02-16 17:10:28 +00:00
|
|
|
struct mtx bd_mtx; /* mutex for this descriptor */
|
2001-12-14 22:17:54 +00:00
|
|
|
struct callout bd_callout; /* for BPF timeouts with select */
|
Modify the MAC Framework so that instead of embedding a (struct label)
in various kernel objects to represent security data, we embed a
(struct label *) pointer, which now references labels allocated using
a UMA zone (mac_label.c). This allows the size and shape of struct
label to be varied without changing the size and shape of these kernel
objects, which become part of the frozen ABI with 5-STABLE. This opens
the door for boot-time selection of the number of label slots, and hence
changes to the bound on the number of simultaneous labeled policies
at boot-time instead of compile-time. This also makes it easier to
embed label references in new objects as required for locking/caching
with fine-grained network stack locking, such as inpcb structures.
This change also moves us further in the direction of hiding the
structure of kernel objects from MAC policy modules, not to mention
dramatically reducing the number of '&' symbols appearing in both the
MAC Framework and MAC policy modules, and improving readability.
While this results in minimal performance change with MAC enabled, it
will observably shrink the size of a number of critical kernel data
structures for the !MAC case, and should have a small (but measurable)
performance benefit (i.e., struct vnode, struct socket) do to memory
conservation and reduced cost of zeroing memory.
NOTE: Users of MAC must recompile their kernel and all MAC modules as a
result of this change. Because this is an API change, third party
MAC modules will also need to be updated to make less use of the '&'
symbol.
Suggestions from: bmilekic
Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories
2003-11-12 03:14:31 +00:00
|
|
|
struct label *bd_label; /* MAC label for descriptor */
|
2005-07-24 17:21:17 +00:00
|
|
|
u_long bd_fcount; /* number of packets which matched filter */
|
|
|
|
pid_t bd_pid; /* PID which created descriptor */
|
2005-08-22 19:35:48 +00:00
|
|
|
int bd_locked; /* true if descriptor is locked */
|
1994-05-24 10:09:53 +00:00
|
|
|
};
|
|
|
|
|
2001-12-14 22:17:54 +00:00
|
|
|
/* Values for bd_state */
|
|
|
|
#define BPF_IDLE 0 /* no select in progress */
|
|
|
|
#define BPF_WAITING 1 /* waiting for read timeout in select */
|
|
|
|
#define BPF_TIMED_OUT 2 /* read timeout has expired in select */
|
|
|
|
|
2001-02-16 17:10:28 +00:00
|
|
|
#define BPFD_LOCK(bd) mtx_lock(&(bd)->bd_mtx)
|
|
|
|
#define BPFD_UNLOCK(bd) mtx_unlock(&(bd)->bd_mtx)
|
2007-08-06 14:26:03 +00:00
|
|
|
#define BPFD_LOCK_ASSERT(bd) mtx_assert(&(bd)->bd_mtx, MA_OWNED);
|
2001-02-16 17:10:28 +00:00
|
|
|
|
2003-08-05 07:12:49 +00:00
|
|
|
/* Test whether a BPF is ready for read(). */
|
|
|
|
#define bpf_ready(bd) \
|
|
|
|
((bd)->bd_hlen != 0 || \
|
|
|
|
(((bd)->bd_immediate || (bd)->bd_state == BPF_TIMED_OUT) && \
|
|
|
|
(bd)->bd_slen != 0))
|
|
|
|
|
2005-07-24 17:21:17 +00:00
|
|
|
/*
|
|
|
|
* External representation of the bpf descriptor
|
|
|
|
*/
|
|
|
|
struct xbpf_d {
|
|
|
|
u_char bd_promisc;
|
|
|
|
u_char bd_immediate;
|
|
|
|
int bd_hdrcmplt;
|
2007-02-26 22:24:14 +00:00
|
|
|
int bd_direction;
|
|
|
|
int bd_feedback;
|
2005-07-24 17:21:17 +00:00
|
|
|
int bd_async;
|
|
|
|
u_long bd_rcount;
|
|
|
|
u_long bd_dcount;
|
|
|
|
u_long bd_fcount;
|
|
|
|
int bd_sig;
|
|
|
|
int bd_slen;
|
|
|
|
int bd_hlen;
|
|
|
|
int bd_bufsize;
|
|
|
|
pid_t bd_pid;
|
|
|
|
char bd_ifname[IFNAMSIZ];
|
2005-08-22 19:35:48 +00:00
|
|
|
int bd_locked;
|
2005-07-24 17:21:17 +00:00
|
|
|
};
|
|
|
|
|
2001-02-16 17:10:28 +00:00
|
|
|
#define BPFIF_LOCK(bif) mtx_lock(&(bif)->bif_mtx)
|
|
|
|
#define BPFIF_UNLOCK(bif) mtx_unlock(&(bif)->bif_mtx)
|
|
|
|
|
1994-08-21 05:11:48 +00:00
|
|
|
#endif
|