npf: Make sure to initialize portmap_lock only once.
PR kern/55586
This commit is contained in:
parent
82242297a7
commit
fdedb3494c
@ -33,7 +33,7 @@
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.43 2020/05/30 14:16:56 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.44 2020/08/27 18:50:25 riastradh Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
@ -52,16 +52,20 @@ static __read_mostly npf_t * npf_kernel_ctx = NULL;
|
||||
__dso_public int
|
||||
npfk_sysinit(unsigned nworkers)
|
||||
{
|
||||
|
||||
npf_bpf_sysinit();
|
||||
npf_tableset_sysinit();
|
||||
npf_nat_sysinit();
|
||||
npf_portmap_sysinit();
|
||||
return npf_worker_sysinit(nworkers);
|
||||
}
|
||||
|
||||
__dso_public void
|
||||
npfk_sysfini(void)
|
||||
{
|
||||
|
||||
npf_worker_sysfini();
|
||||
npf_portmap_sysfini();
|
||||
npf_nat_sysfini();
|
||||
npf_tableset_sysfini();
|
||||
npf_bpf_sysfini();
|
||||
|
@ -472,6 +472,9 @@ bool npf_state_tcp(npf_cache_t *, npf_state_t *, npf_flow_t);
|
||||
int npf_state_tcp_timeout(npf_t *, const npf_state_t *);
|
||||
|
||||
/* Portmap. */
|
||||
void npf_portmap_sysinit(void);
|
||||
void npf_portmap_sysfini(void);
|
||||
|
||||
void npf_portmap_init(npf_t *);
|
||||
void npf_portmap_fini(npf_t *);
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.5 2020/05/30 14:16:56 rmind Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.6 2020/08/27 18:50:25 riastradh Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
@ -108,6 +108,22 @@ struct npf_portmap {
|
||||
|
||||
static kmutex_t portmap_lock;
|
||||
|
||||
void
|
||||
npf_portmap_sysinit(void)
|
||||
{
|
||||
|
||||
mutex_init(&portmap_lock, MUTEX_DEFAULT, IPL_SOFTNET);
|
||||
__insn_barrier();
|
||||
}
|
||||
|
||||
void
|
||||
npf_portmap_sysfini(void)
|
||||
{
|
||||
|
||||
mutex_destroy(&portmap_lock);
|
||||
__insn_barrier();
|
||||
}
|
||||
|
||||
void
|
||||
npf_portmap_init(npf_t *npf)
|
||||
{
|
||||
@ -127,16 +143,16 @@ npf_portmap_init(npf_t *npf)
|
||||
.min = 1024, .max = 65535
|
||||
}
|
||||
};
|
||||
|
||||
npf_param_register(npf, param_map, __arraycount(param_map));
|
||||
mutex_init(&portmap_lock, MUTEX_DEFAULT, IPL_SOFTNET);
|
||||
npf->portmap = pm;
|
||||
}
|
||||
|
||||
void
|
||||
npf_portmap_fini(npf_t *npf)
|
||||
{
|
||||
|
||||
npf_portmap_destroy(npf->portmap);
|
||||
mutex_destroy(&portmap_lock);
|
||||
npf->portmap = NULL; // diagnostic
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,6 @@ npf_test_init(int (*pton_func)(int, const char *, void *),
|
||||
npf_worker_sysfini();
|
||||
}
|
||||
#endif
|
||||
npfk_sysinit(0);
|
||||
npf = npfk_create(0, &npftest_mbufops, &npftest_ifops, NULL);
|
||||
npfk_thread_register(npf);
|
||||
npf_setkernctx(npf);
|
||||
@ -88,9 +87,9 @@ void
|
||||
npf_test_fini(void)
|
||||
{
|
||||
npf_t *npf = npf_getkernctx();
|
||||
|
||||
npfk_thread_unregister(npf);
|
||||
npfk_destroy(npf);
|
||||
npfk_sysfini();
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
Reference in New Issue
Block a user