summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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