Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src npf: Make sure to initialize portmap_lock only once.



details:   https://anonhg.NetBSD.org/src/rev/55a0ddae6193
branches:  trunk
changeset: 975355:55a0ddae6193
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 27 18:50:25 2020 +0000

description:
npf: Make sure to initialize portmap_lock only once.

PR kern/55586

diffstat:

 sys/net/npf/npf.c                               |   6 +++++-
 sys/net/npf/npf_impl.h                          |   3 +++
 sys/net/npf/npf_portmap.c                       |  22 +++++++++++++++++++---
 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c |   3 +--
 4 files changed, 28 insertions(+), 6 deletions(-)

diffs (122 lines):

diff -r 531eb40f0d50 -r 55a0ddae6193 sys/net/npf/npf.c
--- a/sys/net/npf/npf.c Thu Aug 27 18:49:36 2020 +0000
+++ b/sys/net/npf/npf.c Thu Aug 27 18:50:25 2020 +0000
@@ -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 @@
 __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();
diff -r 531eb40f0d50 -r 55a0ddae6193 sys/net/npf/npf_impl.h
--- a/sys/net/npf/npf_impl.h    Thu Aug 27 18:49:36 2020 +0000
+++ b/sys/net/npf/npf_impl.h    Thu Aug 27 18:50:25 2020 +0000
@@ -472,6 +472,9 @@
 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 *);
 
diff -r 531eb40f0d50 -r 55a0ddae6193 sys/net/npf/npf_portmap.c
--- a/sys/net/npf/npf_portmap.c Thu Aug 27 18:49:36 2020 +0000
+++ b/sys/net/npf/npf_portmap.c Thu Aug 27 18:50:25 2020 +0000
@@ -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>
@@ -109,6 +109,22 @@
 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)
 {
        npf_portmap_t *pm = npf_portmap_create(
@@ -127,16 +143,16 @@
                        .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
 }
 
diff -r 531eb40f0d50 -r 55a0ddae6193 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c
--- a/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c   Thu Aug 27 18:49:36 2020 +0000
+++ b/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c   Thu Aug 27 18:50:25 2020 +0000
@@ -71,7 +71,6 @@
                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 @@
 npf_test_fini(void)
 {
        npf_t *npf = npf_getkernctx();
+
        npfk_thread_unregister(npf);
        npfk_destroy(npf);
-       npfk_sysfini();
 }
 
 int



Home | Main Index | Thread Index | Old Index