aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhenlei Huang <zlei@FreeBSD.org>2025-06-28 15:46:51 +0000
committerZhenlei Huang <zlei@FreeBSD.org>2025-07-08 10:03:29 +0000
commit0a5e8108bf20d9d40d473f3a7f04cff7abb1ffa8 (patch)
tree040835f224be5335936198977e6baa25ae06448b
parent9d53e7eaab9e2e75491941dc035a345bc0f39c99 (diff)
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) (cherry picked from commit 8cc376735c65a18c53a70c30957a5f56dd066b79)
-rw-r--r--sys/netpfil/pf/if_pfsync.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index 9eef37ff9005..e071197f17ce 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -340,23 +340,6 @@ pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
sc = malloc(sizeof(struct pfsync_softc), M_PFSYNC, M_WAITOK | M_ZERO);
sc->sc_flags |= PFSYNCF_OK;
sc->sc_maxupdates = 128;
-
- 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++) {
@@ -378,6 +361,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);