aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2024-09-20 09:36:22 +0000
committerKristof Provost <kp@FreeBSD.org>2024-09-21 22:55:46 +0000
commit93e96359c980ccf318fe089b30b863f7c910b622 (patch)
treebc57a84f83b2e7cd6a716af9cc9f0465c31fa785
parent66fcbd9556b0053253a945638ae360ffc9040c82 (diff)
downloadsrc-93e96359c980.tar.gz
src-93e96359c980.zip
libpfctl: ensure we return useful error codes
Return errno rather than -1 on error. This allows pfctl to report much more useful errors. Reported by: Alexander Leidinger <Alexander@Leidinger.net> MFC after: 1 week
-rw-r--r--lib/libpfctl/libpfctl.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 11984a301336..c8eeb913e912 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -2164,8 +2164,12 @@ pfctl_clear_rules(int dev, const char *anchorname)
ret = ioctl(dev, DIOCXBEGIN, &trans);
if (ret != 0)
- return (ret);
- return ioctl(dev, DIOCXCOMMIT, &trans);
+ return (errno);
+ ret = ioctl(dev, DIOCXCOMMIT, &trans);
+ if (ret != 0)
+ return (errno);
+
+ return (0);
}
int
@@ -2199,9 +2203,14 @@ pfctl_clear_nat(int dev, const char *anchorname)
ret = ioctl(dev, DIOCXBEGIN, &trans);
if (ret != 0)
- return (ret);
- return ioctl(dev, DIOCXCOMMIT, &trans);
+ return (errno);
+ ret = ioctl(dev, DIOCXCOMMIT, &trans);
+ if (ret != 0)
+ return (errno);
+
+ return (0);
}
+
int
pfctl_clear_eth_rules(int dev, const char *anchorname)
{
@@ -2223,8 +2232,12 @@ pfctl_clear_eth_rules(int dev, const char *anchorname)
ret = ioctl(dev, DIOCXBEGIN, &trans);
if (ret != 0)
- return (ret);
- return ioctl(dev, DIOCXCOMMIT, &trans);
+ return (errno);
+ ret = ioctl(dev, DIOCXCOMMIT, &trans);
+ if (ret != 0)
+ return (errno);
+
+ return (0);
}
static int
@@ -2278,7 +2291,10 @@ pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s)
ret = ioctl(dev, DIOCSETSYNCOOKIES, &nv);
free(nv.data);
- return (ret);
+ if (ret != 0)
+ return (errno);
+
+ return (0);
}
int
@@ -2386,7 +2402,7 @@ pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
io.pfrio_size = size;
io.pfrio_size2 = (size2 != NULL) ? *size2 : 0;
if (ioctl(dev, DIOCRSETADDRS, &io))
- return (-1);
+ return (errno);
if (nadd != NULL)
*nadd = io.pfrio_nadd;
if (ndel != NULL)
@@ -2414,7 +2430,7 @@ int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr *addr,
io.pfrio_esize = sizeof(*addr);
io.pfrio_size = *size;
if (ioctl(dev, DIOCRGETADDRS, &io))
- return (-1);
+ return (errno);
*size = io.pfrio_size;
return (0);
}