The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=34e155336f0dd10efa8261b971fd540d92817339

commit 34e155336f0dd10efa8261b971fd540d92817339
Author:     Mark Johnston <[email protected]>
AuthorDate: 2026-06-16 19:37:35 +0000
Commit:     Mark Johnston <[email protected]>
CommitDate: 2026-06-16 20:19:44 +0000

    pfctl: pfctl_get_astats() doesn't set errno
    
    After commit 08f54dfca197 pfctl_get_astats() doesn't set errno anymore,
    except in one place.  Fix up that one place and adjust callers
    appropriately.
    
    Reviewed by:    kp
    Fixes:          08f54dfca197 ("pf: convert DIOCRGETASTATS to netlink")
    Differential Revision:  https://reviews.freebsd.org/D57608
---
 lib/libpfctl/libpfctl.c                   | 6 ++----
 sbin/pfctl/pfctl_radix.c                  | 9 ++++++++-
 usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c | 6 +++---
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 839693269102..50d85a7869c9 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -3877,10 +3877,8 @@ pfctl_get_astats(struct pfctl_handle *h, const struct 
pfr_table *tbl,
        uint32_t seq_id;
 
        if (tbl == NULL || size == NULL || *size < 0 ||
-           (*size && as == NULL)) {
-               errno = EINVAL;
-               return (-1);
-       }
+           (*size && as == NULL))
+               return (EINVAL);
 
        snl_init_writer(&h->ss, &nw);
        hdr = snl_create_genl_msg_request(&nw, h->family_id,
diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c
index 608c22141ae8..db6153941cca 100644
--- a/sbin/pfctl/pfctl_radix.c
+++ b/sbin/pfctl/pfctl_radix.c
@@ -194,7 +194,14 @@ int
 pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
     int flags)
 {
-       return (pfctl_get_astats(pfh, tbl, addr, size, flags));
+       int ret;
+
+       ret = pfctl_get_astats(pfh, tbl, addr, size, flags);
+       if (ret) {
+               errno = ret;
+               return (-1);
+       }
+       return (0);
 }
 
 int
diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c 
b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
index f01218bee5f8..8221bbac812f 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
@@ -1355,7 +1355,7 @@ pfa_table_addrs(u_int sidx, struct pfr_table *pt)
        struct pfr_table tbl = { 0 };
        struct pfr_astats *t = NULL;
        struct pfa_entry *e;
-       int i, numaddrs = 1, outnum;
+       int error, i, numaddrs = 1, outnum;
 
        if (pt == NULL)
                return (-1);
@@ -1373,9 +1373,9 @@ pfa_table_addrs(u_int sidx, struct pfr_table *pt)
                }
 
                outnum = numaddrs;
-               if (pfctl_get_astats(pfh, &tbl, t, &outnum, 0) != 0) {
+               if ((error = pfctl_get_astats(pfh, &tbl, t, &outnum, 0)) != 0) {
                        syslog(LOG_ERR, "pfa_table_addrs(): ioctl() on %s: %s",
-                           pt->pfrt_name, strerror(errno));
+                           pt->pfrt_name, strerror(error));
                        numaddrs = -1;
                        break;
                }

Reply via email to