The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=4aa79010bceafdeecb11c2d95bba48d0f6b295f5
commit 4aa79010bceafdeecb11c2d95bba48d0f6b295f5 Author: Kristof Provost <[email protected]> AuthorDate: 2025-12-02 16:24:44 +0000 Commit: Kristof Provost <[email protected]> CommitDate: 2025-12-05 12:24:51 +0000 pfctl: move astats query into libpfctl Sponsored by: Rubicon Communications, LLC ("Netgate") --- lib/libpfctl/libpfctl.c | 22 ++++++++++++++++++++++ lib/libpfctl/libpfctl.h | 3 +++ sbin/pfctl/pfctl_radix.c | 20 +------------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 3db596d6fd38..11377897ebb3 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -3751,4 +3751,26 @@ pfctl_clear_addrs(struct pfctl_handle *h, const struct pfr_table *filter, return (e.error); } +int +pfctl_get_astats(struct pfctl_handle *h, const struct pfr_table *tbl, + struct pfr_astats *addr, int *size, int flags) +{ + struct pfioc_table io; + if (tbl == NULL || size == NULL || *size < 0 || + (*size && addr == NULL)) { + errno = EINVAL; + return (-1); + } + bzero(&io, sizeof io); + io.pfrio_flags = flags; + io.pfrio_table = *tbl; + io.pfrio_buffer = addr; + io.pfrio_esize = sizeof(*addr); + io.pfrio_size = *size; + if (ioctl(h->fd, DIOCRGETASTATS, &io)) { + return (-1); + } + *size = io.pfrio_size; + return (0); +} diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h index a5b7e1c23bd0..9cb596c1b280 100644 --- a/lib/libpfctl/libpfctl.h +++ b/lib/libpfctl/libpfctl.h @@ -584,4 +584,7 @@ int pfctl_clear_tstats(struct pfctl_handle *h, const struct pfr_table *filter, int pfctl_clear_addrs(struct pfctl_handle *h, const struct pfr_table *filter, int *ndel, int flags); +int pfctl_get_astats(struct pfctl_handle *h, const struct pfr_table *tbl, + struct pfr_astats *addr, int *size, int flags); + #endif diff --git a/sbin/pfctl/pfctl_radix.c b/sbin/pfctl/pfctl_radix.c index 823921953eaf..3ea127dd2451 100644 --- a/sbin/pfctl/pfctl_radix.c +++ b/sbin/pfctl/pfctl_radix.c @@ -194,25 +194,7 @@ int pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size, int flags) { - struct pfioc_table io; - - if (tbl == NULL || size == NULL || *size < 0 || - (*size && addr == NULL)) { - errno = EINVAL; - return (-1); - } - bzero(&io, sizeof io); - io.pfrio_flags = flags; - io.pfrio_table = *tbl; - io.pfrio_buffer = addr; - io.pfrio_esize = sizeof(*addr); - io.pfrio_size = *size; - if (ioctl(dev, DIOCRGETASTATS, &io)) { - pfr_report_error(tbl, &io, "get astats from"); - return (-1); - } - *size = io.pfrio_size; - return (0); + return (pfctl_get_astats(pfh, tbl, addr, size, flags)); } int
