MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pfsync_clone_create

Function pfsync_clone_create

freebsd/netpfil/pf/if_pfsync.c:323–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

321#define V_pfsync_cloner VNET(pfsync_cloner)
322
323static int
324pfsync_clone_create(struct if_clone *ifc, int unit, caddr_t param)
325{
326 struct pfsync_softc *sc;
327 struct ifnet *ifp;
328 struct pfsync_bucket *b;
329 int c, q;
330
331 if (unit != 0)
332 return (EINVAL);
333
334 if (! pfsync_buckets)
335 pfsync_buckets = mp_ncpus * 2;
336
337 sc = malloc(sizeof(struct pfsync_softc), M_PFSYNC, M_WAITOK | M_ZERO);
338 sc->sc_flags |= PFSYNCF_OK;
339 sc->sc_maxupdates = 128;
340
341 ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
342 if (ifp == NULL) {
343 free(sc, M_PFSYNC);
344 return (ENOSPC);
345 }
346 if_initname(ifp, pfsyncname, unit);
347 ifp->if_softc = sc;
348 ifp->if_ioctl = pfsyncioctl;
349 ifp->if_output = pfsyncoutput;
350 ifp->if_type = IFT_PFSYNC;
351 ifp->if_hdrlen = sizeof(struct pfsync_header);
352 ifp->if_mtu = ETHERMTU;
353 mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
354 mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
355 callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
356 callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
357
358 if_attach(ifp);
359
360 bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);
361
362 sc->sc_buckets = mallocarray(pfsync_buckets, sizeof(*sc->sc_buckets),
363 M_PFSYNC, M_ZERO | M_WAITOK);
364 for (c = 0; c < pfsync_buckets; c++) {
365 b = &sc->sc_buckets[c];
366 mtx_init(&b->b_mtx, "pfsync bucket", NULL, MTX_DEF);
367
368 b->b_id = c;
369 b->b_sc = sc;
370 b->b_len = PFSYNC_MINPKT;
371
372 for (q = 0; q < PFSYNC_S_COUNT; q++)
373 TAILQ_INIT(&b->b_qs[q]);
374
375 TAILQ_INIT(&b->b_upd_req_list);
376 TAILQ_INIT(&b->b_deferrals);
377
378 callout_init(&b->b_tmo, 1);
379
380 b->b_snd.ifq_maxlen = ifqmaxlen;

Callers

nothing calls this directly

Calls 9

mallocFunction · 0.85
if_allocFunction · 0.85
if_initnameFunction · 0.85
mtx_initFunction · 0.85
if_attachFunction · 0.85
bpfattachFunction · 0.85
freeFunction · 0.50
mallocarrayFunction · 0.50
callout_initFunction · 0.50

Tested by

no test coverage detected