aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2025-12-02 16:24:44 +0000
committerKristof Provost <kp@FreeBSD.org>2025-12-05 12:24:51 +0000
commit4aa79010bceafdeecb11c2d95bba48d0f6b295f5 (patch)
tree544f9e715452329044b6bc92aed7445423691126
parent836a0d46320c18d83029bf138b630b6ce5ebe6ae (diff)
pfctl: move astats query into libpfctl
Sponsored by: Rubicon Communications, LLC ("Netgate")
-rw-r--r--lib/libpfctl/libpfctl.c22
-rw-r--r--lib/libpfctl/libpfctl.h3
-rw-r--r--sbin/pfctl/pfctl_radix.c20
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