git: f14b540dc4c1 - stable/14 - pfsync: Correctly check if bpf peers are present
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 17 Jun 2024 04:03:31 UTC
The branch stable/14 has been updated by zlei:
URL: https://cgit.FreeBSD.org/src/commit/?id=f14b540dc4c17f6b60e23274153985fb7a2f0cb7
commit f14b540dc4c17f6b60e23274153985fb7a2f0cb7
Author: Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-06-09 01:05:22 +0000
Commit: Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-06-17 04:00:02 +0000
pfsync: Correctly check if bpf peers are present
On creating the pfsync(4) interface, pfsync_clone_create() does an
unconditional bpfattach(). Use bpf_peers_present() which was introduced
in commit 16d878cc99ef [1] to check the presence of bpf peers.
This will save a little CPU cycles and memory usage when the
synchronisation interface is not configured and there is no bpf peers
present. There should be no functional change.
1. 16d878cc99ef Fix the following bpf(4) race condition which can result in a panic
Reviewed by: kp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D45533
(cherry picked from commit 2671bde99295d9e01d10316d0f3fb8b6d21f0f4d)
---
sys/netpfil/pf/if_pfsync.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index def06cd0c113..b188813cb8d1 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -1796,7 +1796,7 @@ pfsync_sendout(int schedswi, int c)
("%s: sc_len %zu", __func__, b->b_len));
PFSYNC_BUCKET_LOCK_ASSERT(b);
- if (ifp->if_bpf == NULL && sc->sc_sync_if == NULL) {
+ if (!bpf_peers_present(ifp->if_bpf) && sc->sc_sync_if == NULL) {
pfsync_drop(sc);
return;
}
@@ -1925,10 +1925,10 @@ pfsync_sendout(int schedswi, int c)
V_pfsyncstats.pfsyncs_oacts[PFSYNC_ACT_EOF]++;
/* we're done, let's put it on the wire */
- if (ifp->if_bpf) {
+ if (bpf_peers_present(ifp->if_bpf)) {
m->m_data += aflen;
m->m_len = m->m_pkthdr.len = len - aflen;
- BPF_MTAP(ifp, m);
+ bpf_mtap(ifp->if_bpf, m);
m->m_data -= aflen;
m->m_len = m->m_pkthdr.len = len;
}