git: 2671bde99295 - main - pfsync: Correctly check if bpf peers are present
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 09 Jun 2024 01:06:48 UTC
The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=2671bde99295d9e01d10316d0f3fb8b6d21f0f4d commit 2671bde99295d9e01d10316d0f3fb8b6d21f0f4d Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2024-06-09 01:05:22 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2024-06-09 01:05:22 +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 --- 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 c22a6a5982a9..80d6fddc709c 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; }