Home | History | Annotate | Download | only in net
History log of /src/sys/net/bpfdesc.h
RevisionDateAuthorComments
 1.50  19-Aug-2024  ozaki-r bpf: protect selnotify and selrecord with bd_buf_mtx

We have to make updates and checks of buffers and calls of
selnotify/selrecord atomic to satisfy constraints of sel* API.

Also, bd_state and bd_cv are protected by bd_buf_mtx now.

Fix issue #3 of PR#58596

Part of the fix is inspired by riastradh's patch.
 1.49  19-Aug-2024  ozaki-r bpf: restore wakeup softint

This change fixes the issue that fownsignal which can take an
adaptive mutex is called inside a pserialize read section in
bpf_deliver.

Fix issue #4 (only the latter of two) in PR#58596
 1.48  09-Jun-2021  martin branches: 1.48.10;
Add a bpf_register_track_event() function (and deregister equivalent)
that allows a driver to track listeners attaching/detaching from tap
points.

This is usefull for drivers that would have to do extra work for some
taps and can not easily decide (at the driver level) if the work would
be needed further up the stack.

An example is providing radiotap headers for IEEE 802.11 frames.
 1.47  11-Jun-2020  roy branches: 1.47.6;
bpf(4): Add ioctls BIOCSETWF and BIOCLOCK

Once BIOCLOCK is executed, the device becomes locked which prevents the
execution of ioctl(2) commands which can change the underlying parameters
of the bpf(4) device. An example might be the setting of bpf(4) filter
programs or attaching to different network interfaces.

BIOCSETWF can be used to set write filters for outgoing packets.
Currently if a bpf(4) consumer is compromised, the bpf(4) descriptor can
essentially be used as a raw socket, regardless of consumer's UID.
Write filters give users the ability to constrain which packets can be sent
through the bpf(4) descriptor.

Taken from OpenBSD.
 1.46  26-Jun-2018  msaitoh branches: 1.46.6;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.45  25-Jan-2018  ozaki-r branches: 1.45.2;
Abandon unnecessary softint

The softint was introduced to defer fownsignal that was called in bpf_wakeup to
softint at v1.139, but now bpf_wakeup always runs in softint so we don't need
the softint anymore.
 1.44  09-Feb-2017  ozaki-r branches: 1.44.6;
Make bpf MP-safe

By the change, bpf_mtap can run without any locks as long as its bpf filter
doesn't match a target packet. Pushing data to a bpf buffer still needs
a lock. Removing the lock requires big changes and it's a future work.

Another known issue is that we need to remain some obsolete variables to
avoid breaking kvm(3) users such as netstat and fstat. One problem for
MP-ification is that in order to keep statistic counters of bpf_d we need
to use atomic operations for them. Once we retire the kvm(3) users, we
should make the counters per-CPU and remove the atomic operations.
 1.43  01-Feb-2017  ozaki-r Kill tsleep/wakeup and use cv
 1.42  01-Feb-2017  ozaki-r Use pslist(9) instead of queue(9) for psz/psref

As usual some member variables of struct bpf_d and bpf_if remain to avoid
breaking kvm(3) users (netstat and fstat).
 1.41  01-Feb-2017  ozaki-r Use kmem(9) instead of malloc/free
 1.40  24-Jan-2017  ozaki-r Defer bpf_mtap in Rx interrupt context to softint

bpf_mtap of some drivers is still called in hardware interrupt context.
We want to run them in softint as well as bpf_mtap of most drivers
(see if_percpuq_softint and if_input).

To this end, bpf_mtap_softint mechanism is implemented; it defers
bpf_mtap processing to a dedicated softint for a target driver.
By using the machanism, we can move bpf_mtap processing to softint
without changing target drivers much while it adds some overhead
on CPU and memory. Once target drivers are changed to softint-based,
we should return to normal bpf_mtap.

Proposed on tech-kern and tech-net
 1.39  23-Jan-2017  ozaki-r Make bpf_setf static
 1.38  15-Nov-2013  rmind branches: 1.38.6; 1.38.10; 1.38.14;
- Add bpf_args_t and convert bpf_filter_ext() to use it. This allows the
caller to initialise (and re-use) the memory store.
- Add bpf_jit_generate() and bpf_jit_freecode() wrappers.
 1.37  28-Oct-2012  alnsn branches: 1.37.2;
Comment bd_jitcode member.
 1.36  27-Oct-2012  alnsn Add bpfjit and enable it for amd64.
 1.35  27-Sep-2012  alnsn Remove bpf_jit which was ported from FreeBSD recently.

It will soon be replaced with the new bpfjit kernel module.
 1.34  01-Aug-2012  rmind branches: 1.34.2;
Add BPF JIT compiler, currently supporting amd64 and i386. Code obtained
from FreeBSD. Also, make few BPF fixes and simplifications while here.
Note that bpf_jit_enable is false for now.

OK dyoung@, some feedback from matt@
 1.33  30-Aug-2011  bouyer branches: 1.33.2;
Provide netbsd32 compat for bpf. Beside the ioctls, the structure
returned to userland by read(2) also needs to be converted.
For this, the bpf descriptor is flagged as compat32 (or not) in the
open and ioctl functions (where the user process's pid is also updated
in the descriptor). When the bpf buffer is filled in, the 32bits or native
header is used depending on the information stored in the descriptor.

This won't work if a 64bit binary does the open and ioctls, and then
exec a 32bit program which will do the read. But this is very
unlikely to happen in real life ...

Tested on i386 and loongson; with these changes my loongson can run
dhclient and tcpdump with a n32 userland.
 1.32  13-Mar-2010  christos add BIOC{G,S}FEEDBACK which allows one to receive injected outgoing packets
via bpf.
 1.31  21-Jan-2010  dyoung branches: 1.31.2;
Spelling fix: correspoding -> corresponding.
 1.30  11-Apr-2009  christos Fix PR/37878 and PR/37550: Provide stat(2) for all devices and don't use
fbadop_stat.
 1.29  14-Mar-2009  dsl Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.28  24-Apr-2008  ad branches: 1.28.2; 1.28.10; 1.28.16;
Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.27  20-Feb-2008  matt branches: 1.27.6; 1.27.8;
s/u_\(int[0-9]*_t\)/u\1/g
(change u_int*_t to uint*_t)
 1.26  09-Jul-2007  ad branches: 1.26.8;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.25  04-Mar-2007  christos branches: 1.25.2; 1.25.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.24  10-Dec-2005  elad branches: 1.24.26;
Multiple inclusion protection, as suggested by christos@ on tech-kern@
few days ago.
 1.23  04-Aug-2005  rpaulo Implemented the kernel part of BPF statistics and BPF peers, net.bpf.stats
and net.bpf.peers sysctls respectively.

A new structure was added to describe the external (user viewable)
representation of a BPF file; a new entry was added to the bpf_d
structure to store the PID of the calling process; a simple_lock was added
to protect the insert/removal from the net.bpf.peers sysctl handler.

This idea came from FreeBSD (Christian S.J. Peron) but while it is
implemented with sysctl's it differs a bit.

Reviewed by: christos@ and atatat@ (who gave me the tip for the net.bpf.peers
sysctl helper function).
 1.22  17-Mar-2005  kleink branches: 1.22.2;
A couple of <sys/select.h>-related changes:
* Factor out struct selinfo and its header dependencies into its own header,
<sys/selinfo.h>, to avoid namespace pollution.
* Include <sys/selinfo.h> in user-visible headers where necessary.
 1.21  30-Nov-2004  christos branches: 1.21.4; 1.21.6;
Clonify bpf. I am not changing /dev/bpfX -> /dev/bpf until all userland
programs have been fixed.
 1.20  29-May-2004  darrenr back out previous change - these diffs aren't what I'd tested.
 1.19  29-May-2004  darrenr add mmap(2) interface to bpf(4) devices, along with BIOCMMAPINFO ioctl call
for applications to interact with the bpf device for the purpose of using
mmap to examinen captured data.
 1.18  15-Apr-2004  darrenr Add a count of the number of packets that match the bpf filter applied to a
particule device. In doing this, make a new the bpf_stat structure with
members that are u_long rather than u_int, matching the counters in the bpf_d.
the original bpf_stat is now bpf_stat_old and so to the original ioctl
is preserved as BIOCGSTATSOLD.
 1.17  10-Apr-2004  darrenr Fix bpf so that select will return for a timeout (from FreeBSD.)

Fix the behaviour of BIOCIMMEDIATE (fix from LBL BPF code via FreeBSD.)

In bpf_mtap(), optimise the calling of bpf_filter() and catchpacket()
based on whether or not the entire packet is in one mbuf (based on
similar change FreeBSD but fixes BIOC*SEESENT issue with that.)

Copy the implementation of BIOCSSEESENT, BIOCGSEESENT by FreeBSD.

Review Assistance: Guy Harris

PRs: kern/8674, kern/12170
 1.16  07-Aug-2003  agc branches: 1.16.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.15  30-Apr-1998  thorpej branches: 1.15.48;
Implement two new BPF ioctls: BPFGHDRCMPLT and BPFSHDRCMPLT, to get/set
the "header already complete" flag. This allows BPF writers to spoof
layer 2 source addresses (providing the layer 2 in use supports it) in
applications where this is necessary. From Greg Smith <greg@nas.nasa.gov>.
 1.14  09-Feb-1998  perry add multiple inclusion protection (and cleanup).
 1.13  09-Oct-1997  christos GC bd_sig
 1.12  09-Oct-1997  christos - add their rcsid
- add ifdef to match current code
 1.11  27-Sep-1995  thorpej branches: 1.11.14;
Enhancements to the bpf from Stu Grossman <grossman@cygnus.com>:
* grok FIONBIO, FIOASYNC, and TIOC{G,S}PGRP
* add BIOC{G,S}RSIG; get/set the signal to be delivered
to the process or process group upon packet reception.
Defaults to SIGIO.
 1.10  26-Mar-1995  jtc KERNEL -> _KERNEL
 1.9  29-Jun-1994  cgd New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'
 1.8  13-May-1994  mycroft Update to 4.4-Lite networking code, with a few local changes.
 1.7  23-Nov-1993  cgd defines change
 1.6  09-Sep-1993  davidg branches: 1.6.2;
added include of select.h to bpfdesc.h because it now has a reference to
struct selinfo.
 1.5  18-May-1993  cgd make kernel select interface be one-stop shopping & clean it all up.
 1.4  19-Apr-1993  mycroft Add consistent multiple-inclusion protection.
 1.3  06-Apr-1993  deraadt commit damnit!
 1.2  25-Mar-1993  cgd added BPF support, as provided by David Greenman (davidg@implode.rain.com)
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  01-Mar-1998  fvdl Import 4.4BSD-Lite for reference
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.1  23-Nov-1993  cgd defines change
 1.11.14.1  14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.15.48.7  11-Dec-2005  christos Sync with head.
 1.15.48.6  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.15.48.5  01-Apr-2005  skrll Sync with HEAD.
 1.15.48.4  18-Dec-2004  skrll Sync with HEAD.
 1.15.48.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.15.48.2  18-Sep-2004  skrll Sync with HEAD.
 1.15.48.1  03-Aug-2004  skrll Sync with HEAD
 1.16.2.1  21-Apr-2004  jmc Pullup rev 1.17-1.18 (requested by darrenr in ticket #167)

Reduce bpf buffer to 32k from 1M to reduce kernel memory usage from userland
binaries.
Fix bpf so that select will return for a timeout.
Fix the behaviour of BIOCIMMEDIATE.
In bpf_mtap(), optimise the calling of bpf_filter() and catchpacket()
based on whether or not the entire packet is in one mbuf.
Various other bpf fixes, including PR#8674, PR#12170
 1.21.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.21.4.1  29-Apr-2005  kent sync with -current
 1.22.2.3  27-Feb-2008  yamt sync with head.
 1.22.2.2  03-Sep-2007  yamt sync with head.
 1.22.2.1  21-Jun-2006  yamt sync with head.
 1.24.26.1  12-Mar-2007  rmind Sync with HEAD.
 1.25.4.1  11-Jul-2007  mjf Sync with head.
 1.25.2.1  01-Jul-2007  ad Adapt to callout API change.
 1.26.8.1  23-Mar-2008  matt sync with HEAD
 1.27.8.1  18-May-2008  yamt sync with head.
 1.27.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.28.16.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.28.10.1  28-Apr-2009  skrll Sync with HEAD.
 1.28.2.3  11-Aug-2010  yamt sync with head.
 1.28.2.2  11-Mar-2010  yamt sync with head
 1.28.2.1  04-May-2009  yamt sync with head.
 1.31.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.33.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.33.2.1  30-Oct-2012  yamt sync with head
 1.34.2.3  03-Dec-2017  jdolecek update from HEAD
 1.34.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.37.2.1  18-May-2014  rmind sync with head
 1.38.14.1  21-Apr-2017  bouyer Sync with HEAD
 1.38.10.1  20-Mar-2017  pgoyette Sync with HEAD
 1.38.6.2  28-Aug-2017  skrll Sync with HEAD
 1.38.6.1  05-Feb-2017  skrll Sync with HEAD
 1.44.6.1  05-Feb-2018  martin Pull up following revision(s) (requested by ozaki-r in ticket #526):
sys/net/bpfdesc.h: revision 1.45
sys/net/bpf.c: revision 1.223
Abandon unnecessary softint
The softint was introduced to defer fownsignal that was called in bpf_wakeup to
softint at v1.139, but now bpf_wakeup always runs in softint so we don't need
the softint anymore.
 1.45.2.1  28-Jul-2018  pgoyette Sync with HEAD
 1.46.6.1  13-Sep-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #1886):

sys/net/bpfdesc.h: revision 1.49
sys/net/bpf.c: revision 1.256
sys/net/bpf.c: revision 1.257
sys/net/bpfdesc.h: revision 1.50

bpf: restore wakeup softint

This change fixes the issue that fownsignal which can take an
adaptive mutex is called inside a pserialize read section in
bpf_deliver.

Fix issue #4 (only the latter of two) in PR#58596
bpf: protect selnotify and selrecord with bd_buf_mtx

We have to make updates and checks of buffers and calls of
selnotify/selrecord atomic to satisfy constraints of sel* API.

Also, bd_state and bd_cv are protected by bd_buf_mtx now.

Fix issue #3 of PR#58596

Part of the fix is inspired by riastradh's patch.
 1.47.6.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.48.10.1  13-Sep-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #858):

sys/net/bpfdesc.h: revision 1.49
sys/net/bpf.c: revision 1.256
sys/net/bpf.c: revision 1.257
sys/net/bpfdesc.h: revision 1.50

bpf: restore wakeup softint

This change fixes the issue that fownsignal which can take an
adaptive mutex is called inside a pserialize read section in
bpf_deliver.

Fix issue #4 (only the latter of two) in PR#58596
bpf: protect selnotify and selrecord with bd_buf_mtx

We have to make updates and checks of buffers and calls of
selnotify/selrecord atomic to satisfy constraints of sel* API.

Also, bd_state and bd_cv are protected by bd_buf_mtx now.

Fix issue #3 of PR#58596

Part of the fix is inspired by riastradh's patch.

RSS XML Feed