summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-08-05 02:37:36 +0000
committerrwatson <rwatson@FreeBSD.org>2004-08-05 02:37:36 +0000
commit00b755c2a702c024f580d625172d0400fe21313f (patch)
treefea66d1c5fa13445e0ce4c3f63e17bee3e584bf9 /sys/net
parente4fbd5d17285aa77573a1d717ddf675761c44511 (diff)
downloadFreeBSD-src-00b755c2a702c024f580d625172d0400fe21313f.zip
FreeBSD-src-00b755c2a702c024f580d625172d0400fe21313f.tar.gz
Do a lockless read of the BPF interface structure descriptor list head
before grabbing BPF locks to see if there are any entries in order to avoid the cost of locking if there aren't any. Avoids a mutex lock/ unlock for each packet received if there are no BPF listeners.
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/bpf.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 7c00b9c..6f6c9fe 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1147,6 +1147,13 @@ bpf_tap(bp, pkt, pktlen)
struct bpf_d *d;
u_int slen;
+ /*
+ * Lockless read to avoid cost of locking the interface if there are
+ * no descriptors attached.
+ */
+ if (bp->bif_dlist == NULL)
+ return;
+
BPFIF_LOCK(bp);
for (d = bp->bif_dlist; d != NULL; d = d->bd_next) {
BPFD_LOCK(d);
@@ -1201,6 +1208,13 @@ bpf_mtap(bp, m)
struct bpf_d *d;
u_int pktlen, slen;
+ /*
+ * Lockless read to avoid cost of locking the interface if there are
+ * no descriptors attached.
+ */
+ if (bp->bif_dlist == NULL)
+ return;
+
pktlen = m_length(m, NULL);
if (pktlen == m->m_len) {
bpf_tap(bp, mtod(m, u_char *), pktlen);
@@ -1240,6 +1254,13 @@ bpf_mtap2(bp, data, dlen, m)
struct bpf_d *d;
u_int pktlen, slen;
+ /*
+ * Lockless read to avoid cost of locking the interface if there are
+ * no descriptors attached.
+ */
+ if (bp->bif_dlist == NULL)
+ return;
+
pktlen = m_length(m, NULL);
/*
* Craft on-stack mbuf suitable for passing to bpf_filter.
OpenPOWER on IntegriCloud