summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2018-12-27 16:54:01 +0000
committerkn <kn@openbsd.org>2018-12-27 16:54:01 +0000
commit55038654e1dfdc12cf3c83df52b344c5ad9366a2 (patch)
tree22b1b7341197d3449eef2512b52f58a7d6a76212
parentZap duplicate struct declaration (diff)
downloadwireguard-openbsd-55038654e1dfdc12cf3c83df52b344c5ad9366a2.tar.xz
wireguard-openbsd-55038654e1dfdc12cf3c83df52b344c5ad9366a2.zip
Check for main ruleset explicitly
All rulesets reference their parent anchor, except for the special cased main anchor containing the main ruleset, which's reference is always NULL since initialization and never changes. Replacing nullity tests with clearer equality checks makes the code less ambigious and easier to understand. OK sashan
-rw-r--r--sys/net/pf_ioctl.c6
-rw-r--r--sys/net/pf_ruleset.c8
2 files changed, 7 insertions, 7 deletions
diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c
index a4c7fceed47..5220cd02ed0 100644
--- a/sys/net/pf_ioctl.c
+++ b/sys/net/pf_ioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_ioctl.c,v 1.341 2018/12/17 15:37:41 kn Exp $ */
+/* $OpenBSD: pf_ioctl.c,v 1.342 2018/12/27 16:54:01 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -1945,7 +1945,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
break;
}
pr->nr = 0;
- if (ruleset->anchor == NULL) {
+ if (ruleset == &pf_main_ruleset) {
/* XXX kludge for pf_main_ruleset */
RB_FOREACH(anchor, pf_anchor_global, &pf_anchors)
if (anchor->parent == NULL)
@@ -1973,7 +1973,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
break;
}
pr->name[0] = 0;
- if (ruleset->anchor == NULL) {
+ if (ruleset == &pf_main_ruleset) {
/* XXX kludge for pf_main_ruleset */
RB_FOREACH(anchor, pf_anchor_global, &pf_anchors)
if (anchor->parent == NULL && nr++ == pr->nr) {
diff --git a/sys/net/pf_ruleset.c b/sys/net/pf_ruleset.c
index 11233e4069d..f1e35b9410a 100644
--- a/sys/net/pf_ruleset.c
+++ b/sys/net/pf_ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_ruleset.c,v 1.17 2018/12/17 15:37:41 kn Exp $ */
+/* $OpenBSD: pf_ruleset.c,v 1.18 2018/12/27 16:54:01 kn Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -287,7 +287,7 @@ pf_remove_if_empty_ruleset(struct pf_ruleset *ruleset)
struct pf_anchor *parent;
while (ruleset != NULL) {
- if (ruleset == &pf_main_ruleset || ruleset->anchor == NULL ||
+ if (ruleset == &pf_main_ruleset ||
!RB_EMPTY(&ruleset->anchor->children) ||
ruleset->anchor->refcnt > 0 || ruleset->tables > 0 ||
ruleset->topen)
@@ -355,7 +355,7 @@ pf_anchor_setup(struct pf_rule *r, const struct pf_ruleset *s,
}
ruleset = pf_find_or_create_ruleset(path);
rs_free(path, MAXPATHLEN);
- if (ruleset == NULL || ruleset->anchor == NULL) {
+ if (ruleset == NULL || ruleset == &pf_main_ruleset) {
DPFPRINTF(LOG_NOTICE,
"pf_anchor_setup: ruleset");
return (1);
@@ -383,7 +383,7 @@ pf_anchor_copyout(const struct pf_ruleset *rs, const struct pf_rule *r,
a = rs_malloc(MAXPATHLEN);
if (a == NULL)
return (1);
- if (rs->anchor == NULL)
+ if (rs == &pf_main_ruleset)
a[0] = 0;
else
strlcpy(a, rs->anchor->path, MAXPATHLEN);