Date: Sun, 21 Dec 2025 17:33:37 +0000 From: Kristof Provost <kp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 823ebd7c4f89 - main - libpfctl: export a get states variant that takes a pfctl_handle Message-ID: <69482f71.24980.389b2a8e@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=823ebd7c4f897b1c620b6f21a68221da1cef7449 commit 823ebd7c4f897b1c620b6f21a68221da1cef7449 Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2025-12-21 11:12:17 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2025-12-21 17:33:06 +0000 libpfctl: export a get states variant that takes a pfctl_handle Sponsored by: Rubicon Communications, LLC ("Netgate") --- lib/libpfctl/libpfctl.c | 22 +++++++++++----------- lib/libpfctl/libpfctl.h | 1 + sbin/pfctl/pfctl.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 1959f7bebc39..7e5a07ccd55a 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -1961,11 +1961,11 @@ static const struct snl_hdr_parser *all_parsers[] = { &creator_parser, &getrules_parser }; -static int -pfctl_get_states_nl(struct pfctl_state_filter *filter, struct snl_state *ss, pfctl_get_state_fn f, void *arg) +int +pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg) { SNL_VERIFY_PARSERS(all_parsers); - int family_id = snl_get_genl_family(ss, PFNL_FAMILY_NAME); + int family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME); int ret; struct nlmsghdr *hdr; @@ -1974,7 +1974,7 @@ pfctl_get_states_nl(struct pfctl_state_filter *filter, struct snl_state *ss, pfc if (family_id == 0) return (ENOTSUP); - snl_init_writer(ss, &nw); + snl_init_writer(&h->ss, &nw); hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETSTATES); hdr->nlmsg_flags |= NLM_F_DUMP; snl_add_msg_attr_string(&nw, PF_ST_IFNAME, filter->ifname); @@ -1989,13 +1989,13 @@ pfctl_get_states_nl(struct pfctl_state_filter *filter, struct snl_state *ss, pfc uint32_t seq_id = hdr->nlmsg_seq; - snl_send_message(ss, hdr); + snl_send_message(&h->ss, hdr); struct snl_errmsg_data e = {}; - while ((hdr = snl_read_reply_multi(ss, seq_id, &e)) != NULL) { + while ((hdr = snl_read_reply_multi(&h->ss, seq_id, &e)) != NULL) { struct pfctl_state s; bzero(&s, sizeof(s)); - if (!snl_parse_nlmsg(ss, hdr, &state_parser, &s)) + if (!snl_parse_nlmsg(&h->ss, hdr, &state_parser, &s)) continue; ret = f(&s, arg); @@ -2016,12 +2016,12 @@ pfctl_get_states_iter(pfctl_get_state_fn f, void *arg) int pfctl_get_filtered_states_iter(struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg) { - struct snl_state ss = {}; + struct pfctl_handle h = {}; int error; - snl_init(&ss, NETLINK_GENERIC); - error = pfctl_get_states_nl(filter, &ss, f, arg); - snl_free(&ss); + snl_init(&h.ss, NETLINK_GENERIC); + error = pfctl_get_states_h(&h, filter, f, arg); + snl_free(&h.ss); return (error); } diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h index 9cb596c1b280..9576118fe146 100644 --- a/lib/libpfctl/libpfctl.h +++ b/lib/libpfctl/libpfctl.h @@ -499,6 +499,7 @@ struct pfctl_state_filter { }; typedef int (*pfctl_get_state_fn)(struct pfctl_state *, void *); int pfctl_get_states_iter(pfctl_get_state_fn f, void *arg); +int pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg); int pfctl_get_filtered_states_iter(struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg); int pfctl_get_states(int dev, struct pfctl_states *states); void pfctl_free_states(struct pfctl_states *states); diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index 5ab4687dd35f..da27afb0a179 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -1700,7 +1700,7 @@ pfctl_show_states(int dev, const char *iface, int opts) arg.dotitle = opts & PF_OPT_SHOWALL; arg.iface = iface; - if (pfctl_get_filtered_states_iter(&filter, pfctl_show_state, &arg)) + if (pfctl_get_states_h(pfh, &filter, pfctl_show_state, &arg)) return (-1); return (0);help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69482f71.24980.389b2a8e>
