git: cbea6b60da00 - stable/13 - pflog: Correctly check if bpf peers are present
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 17 Jun 2024 04:28:02 UTC
The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=cbea6b60da007bff698e508a10dd632c80c22b22 commit cbea6b60da007bff698e508a10dd632c80c22b22 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:10:35 +0000 pflog: Correctly check if bpf peers are present On creating the pflog(4) interface, pflog_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 when 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/D45532 (cherry picked from commit ebc2bab04823c24c524f913457d6b88dc7ea9fac) (cherry picked from commit 954e548b7e88b7490aa5b23d16df7972c407bef1) --- sys/netpfil/pf/if_pflog.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/netpfil/pf/if_pflog.c b/sys/netpfil/pf/if_pflog.c index 0f9c18654077..541625709494 100644 --- a/sys/netpfil/pf/if_pflog.c +++ b/sys/netpfil/pf/if_pflog.c @@ -207,9 +207,10 @@ pflog_packet(struct pfi_kkif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir, struct pfloghdr hdr; if (kif == NULL || m == NULL || rm == NULL || pd == NULL) - return ( 1); + return (1); - if ((ifn = V_pflogifs[rm->logif]) == NULL || !ifn->if_bpf) + ifn = V_pflogifs[rm->logif]; + if (ifn == NULL || !bpf_peers_present(ifn->if_bpf)) return (0); bzero(&hdr, sizeof(hdr)); @@ -258,7 +259,7 @@ pflog_packet(struct pfi_kkif *kif, struct mbuf *m, sa_family_t af, u_int8_t dir, if_inc_counter(ifn, IFCOUNTER_OPACKETS, 1); if_inc_counter(ifn, IFCOUNTER_OBYTES, m->m_pkthdr.len); - BPF_MTAP2(ifn, &hdr, PFLOG_HDRLEN, m); + bpf_mtap2(ifn->if_bpf, &hdr, PFLOG_HDRLEN, m); return (0); }