Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf - npf_mk_rules: enforce unique names for the dyn...



details:   https://anonhg.NetBSD.org/src/rev/6414ee5d83c4
branches:  trunk
changeset: 828362:6414ee5d83c4
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Dec 10 01:18:21 2017 +0000

description:
- npf_mk_rules: enforce unique names for the dynamic rulesets.
- npf_worker_unregister: merge fix for the standalone NPF.

diffstat:

 sys/net/npf/npf_ctl.c     |  12 +++++++++---
 sys/net/npf/npf_impl.h    |   3 ++-
 sys/net/npf/npf_ruleset.c |   6 +++---
 sys/net/npf/npf_worker.c  |   9 ++++++---
 4 files changed, 20 insertions(+), 10 deletions(-)

diffs (114 lines):

diff -r 2319eb92010b -r 6414ee5d83c4 sys/net/npf/npf_ctl.c
--- a/sys/net/npf/npf_ctl.c     Sun Dec 10 00:43:05 2017 +0000
+++ b/sys/net/npf/npf_ctl.c     Sun Dec 10 01:18:21 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_ctl.c,v 1.49 2017/10/30 03:02:35 ozaki-r Exp $     */
+/*     $NetBSD: npf_ctl.c,v 1.50 2017/12/10 01:18:21 rmind Exp $       */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.49 2017/10/30 03:02:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.50 2017/12/10 01:18:21 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -371,12 +371,18 @@
        it = prop_array_iterator(rules);
        while ((rldict = prop_object_iterator_next(it)) != NULL) {
                npf_rule_t *rl = NULL;
+               const char *name;
 
-               /* Generate a single rule. */
                error = npf_mk_singlerule(npf, rldict, rpset, &rl, errdict);
                if (error) {
                        break;
                }
+               if (prop_dictionary_get_cstring_nocopy(rldict, "name", &name) &&
+                   npf_ruleset_lookup(rlset, name) != NULL) {
+                       NPF_ERR_DEBUG(errdict);
+                       npf_rule_free(rl);
+                       return EEXIST;
+               }
                npf_ruleset_insert(rlset, rl);
        }
        prop_object_iterator_release(it);
diff -r 2319eb92010b -r 6414ee5d83c4 sys/net/npf/npf_impl.h
--- a/sys/net/npf/npf_impl.h    Sun Dec 10 00:43:05 2017 +0000
+++ b/sys/net/npf/npf_impl.h    Sun Dec 10 01:18:21 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_impl.h,v 1.69 2017/02/19 02:11:19 christos Exp $   */
+/*     $NetBSD: npf_impl.h,v 1.70 2017/12/10 01:18:21 rmind Exp $      */
 
 /*-
  * Copyright (c) 2009-2014 The NetBSD Foundation, Inc.
@@ -330,6 +330,7 @@
 void           npf_ruleset_freealg(npf_ruleset_t *, npf_alg_t *);
 int            npf_ruleset_export(npf_t *, const npf_ruleset_t *, prop_array_t);
 
+npf_rule_t *   npf_ruleset_lookup(npf_ruleset_t *, const char *);
 int            npf_ruleset_add(npf_ruleset_t *, const char *, npf_rule_t *);
 int            npf_ruleset_remove(npf_ruleset_t *, const char *, uint64_t);
 int            npf_ruleset_remkey(npf_ruleset_t *, const char *,
diff -r 2319eb92010b -r 6414ee5d83c4 sys/net/npf/npf_ruleset.c
--- a/sys/net/npf/npf_ruleset.c Sun Dec 10 00:43:05 2017 +0000
+++ b/sys/net/npf/npf_ruleset.c Sun Dec 10 01:18:21 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_ruleset.c,v 1.45 2017/01/29 00:15:54 christos Exp $        */
+/*     $NetBSD: npf_ruleset.c,v 1.46 2017/12/10 01:18:21 rmind Exp $   */
 
 /*-
  * Copyright (c) 2009-2015 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.45 2017/01/29 00:15:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ruleset.c,v 1.46 2017/12/10 01:18:21 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -208,7 +208,7 @@
        }
 }
 
-static npf_rule_t *
+npf_rule_t *
 npf_ruleset_lookup(npf_ruleset_t *rlset, const char *name)
 {
        npf_rule_t *rl;
diff -r 2319eb92010b -r 6414ee5d83c4 sys/net/npf/npf_worker.c
--- a/sys/net/npf/npf_worker.c  Sun Dec 10 00:43:05 2017 +0000
+++ b/sys/net/npf/npf_worker.c  Sun Dec 10 01:18:21 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npf_worker.c,v 1.3 2017/01/02 21:49:51 rmind Exp $     */
+/*     $NetBSD: npf_worker.c,v 1.4 2017/12/10 01:18:21 rmind Exp $     */
 
 /*-
  * Copyright (c) 2010-2015 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_worker.c,v 1.3 2017/01/02 21:49:51 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_worker.c,v 1.4 2017/12/10 01:18:21 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -148,9 +148,12 @@
 npf_worker_unregister(npf_t *npf, npf_workfunc_t func)
 {
        const unsigned idx = npf->worker_id;
-       npf_worker_t *wrk = &npf_workers[idx];
+       npf_worker_t *wrk;
        npf_t *instance;
 
+       if (!npf_worker_count)
+               return;
+       wrk = &npf_workers[idx];
        mutex_enter(&wrk->worker_lock);
        npf_worker_testset(wrk, func, NULL);
        if ((instance = wrk->instances) == npf) {



Home | Main Index | Thread Index | Old Index