git: 514039bb9085 - main - libpfct: Return errno from pfctl_add_eth_rule()

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Wed, 30 Mar 2022 09:17:23 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=514039bb90853473078acd2fbba1b1bfb359aab5

commit 514039bb90853473078acd2fbba1b1bfb359aab5
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-03-29 12:15:47 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-03-30 08:28:19 +0000

    libpfct: Return errno from pfctl_add_eth_rule()
    
    If the pfctl_add_eth_rule() ioctl fails return the errno, not the error
    returned by ioctl(). That will give us slightly more insight into what
    went wrong, because ioctl() would always return -1.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 lib/libpfctl/libpfctl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 1e1a90594210..8696ef1ace25 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -786,7 +786,7 @@ pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r, const char *anchor,
 	struct pfioc_nv nv;
 	nvlist_t *nvl, *addr;
 	void *packed;
-	int error;
+	int error = 0;
 	size_t size;
 
 	nvl = nvlist_create(0);
@@ -838,7 +838,8 @@ pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r, const char *anchor,
 	nv.size = size;
 	nv.data = packed;
 
-	error = ioctl(dev, DIOCADDETHRULE, &nv);
+	if (ioctl(dev, DIOCADDETHRULE, &nv) != 0)
+		error = errno;
 
 	free(packed);
 	nvlist_destroy(nvl);