pfctl: move astats query into libpfctl

Sponsored by:	Rubicon Communications, LLC ("Netgate")
This commit is contained in:
Kristof Provost
2025-12-02 17:24:44 +01:00
parent 836a0d4632
commit 4aa79010bc
3 changed files with 26 additions and 19 deletions
+22
View File
@@ -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);
}
+3
View File
@@ -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
+1 -19
View File
@@ -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