git: 8cc376735c65 - stable/14 - pfsync: Allocate and initialize buckets before attaching the interface
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Jul 2025 10:07:07 UTC
The branch stable/14 has been updated by zlei:
URL: https://cgit.FreeBSD.org/src/commit/?id=8cc376735c65a18c53a70c30957a5f56dd066b79
commit 8cc376735c65a18c53a70c30957a5f56dd066b79
Author: Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2025-06-28 15:46:51 +0000
Commit: Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-07-07 10:05:10 +0000
pfsync: Allocate and initialize buckets before attaching the interface
This prevents a potential race that the ioctl threads see NULL or
uninitialized buckets.
Reviewed by: kp
Fixes: 4fc65bcbe3fb pfsync: Performance improvement
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D51064
(cherry picked from commit edc307eca9a9a9b0ce7445cff513b48f6489e5c6)
---
sys/netpfil/pf/if_pfsync.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index b75cc4e08029..64c938ee52ee 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -395,23 +395,6 @@ pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
sc->sc_flags |= PFSYNCF_OK;
sc->sc_maxupdates = 128;
sc->sc_version = PFSYNC_MSG_VERSION_DEFAULT;
-
- ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
- if_initname(ifp, pfsyncname, unit);
- ifp->if_softc = sc;
- ifp->if_ioctl = pfsyncioctl;
- ifp->if_output = pfsyncoutput;
- ifp->if_hdrlen = sizeof(struct pfsync_header);
- ifp->if_mtu = ETHERMTU;
- mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
- mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
- callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
- callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
-
- if_attach(ifp);
-
- bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);
-
sc->sc_buckets = mallocarray(pfsync_buckets, sizeof(*sc->sc_buckets),
M_PFSYNC, M_ZERO | M_WAITOK);
for (c = 0; c < pfsync_buckets; c++) {
@@ -433,6 +416,22 @@ pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
b->b_snd.ifq_maxlen = ifqmaxlen;
}
+ ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
+ if_initname(ifp, pfsyncname, unit);
+ ifp->if_softc = sc;
+ ifp->if_ioctl = pfsyncioctl;
+ ifp->if_output = pfsyncoutput;
+ ifp->if_hdrlen = sizeof(struct pfsync_header);
+ ifp->if_mtu = ETHERMTU;
+ mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
+ mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
+ callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
+ callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
+
+ if_attach(ifp);
+
+ bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);
+
V_pfsyncif = sc;
return (0);