diff options
author | 2020-01-15 22:31:51 +0000 | |
---|---|---|
committer | 2020-01-15 22:31:51 +0000 | |
commit | e5c920154c2024677fa8b335bbe529eaa6a4e705 (patch) | |
tree | be88df8e3160ac578ed206c43d5fc09cb9569239 | |
parent | Sprinkle splnet() around the ringbuffer accesses, otherwise the (diff) | |
download | wireguard-openbsd-e5c920154c2024677fa8b335bbe529eaa6a4e705.tar.xz wireguard-openbsd-e5c920154c2024677fa8b335bbe529eaa6a4e705.zip |
Unify error message for nonexisting anchors
pf(4) returns EINVAL for DIOCGETRULE, DIOCGETRULES and DIOCGETRULESET if
the specified anchor does not exist.
Extend and rename {pfr -> pf}_strerror() to make error message more
consistent.
There are other occasions as well but those need additional tweaks;
that's stuff for another diff.
OK and rename from sashan
-rw-r--r-- | sbin/pfctl/pfctl.c | 24 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_optimize.c | 6 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_radix.c | 15 |
3 files changed, 23 insertions, 22 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index 23e3bfbef6c..7bedc88db6e 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl.c,v 1.379 2020/01/15 13:42:39 kn Exp $ */ +/* $OpenBSD: pfctl.c,v 1.380 2020/01/15 22:31:51 kn Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -863,7 +863,7 @@ pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format, if (opts & PF_OPT_SHOWALL) { pr.rule.action = PF_PASS; if (ioctl(dev, DIOCGETRULES, &pr) == -1) { - warn("DIOCGETRULES"); + warnx("%s", pfr_strerror(errno)); ret = -1; goto error; } @@ -878,7 +878,7 @@ pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format, pr.rule.action = PF_PASS; if (ioctl(dev, DIOCGETRULES, &pr) == -1) { - warn("DIOCGETRULES"); + warnx("%s", pfr_strerror(errno)); ret = -1; goto error; } @@ -979,7 +979,7 @@ pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format, for (nr = 0; nr < mnr; ++nr) { prs.nr = nr; if (ioctl(dev, DIOCGETRULESET, &prs) == -1) - err(1, "DIOCGETRULESET"); + errx(1, "%s", pfr_strerror(errno)); INDENT(depth, !(opts & PF_OPT_VERBOSE)); printf("anchor \"%s\" all {\n", prs.name); pfctl_show_rules(dev, npath, opts, @@ -2219,7 +2219,7 @@ pfctl_walk_anchors(int dev, int opts, const char *anchor, pr.nr = nr; if (ioctl(dev, DIOCGETRULESET, &pr) == -1) - err(1, "DIOCGETRULESET"); + errx(1, "%s", pfr_strerror(errno)); if (!strcmp(pr.name, PF_RESERVED_ANCHOR)) continue; sub[0] = '\0'; @@ -2893,3 +2893,17 @@ main(int argc, char *argv[]) exit(exit_val); } + +char * +pfr_strerror(int errnum) +{ + switch (errnum) { + case ESRCH: + return "Table does not exist"; + case EINVAL: + case ENOENT: + return "Anchor does not exist"; + default: + return strerror(errnum); + } +} diff --git a/sbin/pfctl/pfctl_optimize.c b/sbin/pfctl/pfctl_optimize.c index 446cda0560a..e9cdb1bb948 100644 --- a/sbin/pfctl/pfctl_optimize.c +++ b/sbin/pfctl/pfctl_optimize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_optimize.c,v 1.43 2019/12/12 21:00:51 kn Exp $ */ +/* $OpenBSD: pfctl_optimize.c,v 1.44 2020/01/15 22:31:51 kn Exp $ */ /* * Copyright (c) 2004 Mike Frantzen <frantzen@openbsd.org> @@ -873,7 +873,7 @@ load_feedback_profile(struct pfctl *pf, struct superblocks *superblocks) memset(&pr, 0, sizeof(pr)); pr.rule.action = PF_PASS; if (ioctl(pf->dev, DIOCGETRULES, &pr) == -1) { - warn("DIOCGETRULES"); + warnx("%s", pfr_strerror(errno)); return (1); } mnr = pr.nr; @@ -887,7 +887,7 @@ load_feedback_profile(struct pfctl *pf, struct superblocks *superblocks) } pr.nr = nr; if (ioctl(pf->dev, DIOCGETRULE, &pr) == -1) { - warn("DIOCGETRULES"); + warnx("%s", pfr_strerror(errno)); free(por); return (1); } diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c index a48e3616b44..b30b36df302 100644 --- a/sbin/pfctl/pfctl_radix.c +++ b/sbin/pfctl/pfctl_radix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_radix.c,v 1.36 2020/01/15 16:15:08 kn Exp $ */ +/* $OpenBSD: pfctl_radix.c,v 1.37 2020/01/15 22:31:51 kn Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -560,16 +560,3 @@ pfr_next_token(char buf[BUF_SIZE], FILE *fp) buf[i] = '\0'; return (1); } - -char * -pfr_strerror(int errnum) -{ - switch (errnum) { - case ESRCH: - return "Table does not exist"; - case ENOENT: - return "Anchor does not exist"; - default: - return strerror(errnum); - } -} |