The branch stable/15 has been updated by kp:

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

commit f95439f6c9d0e0a4af6a834ec7a0c7fb5279406d
Author:     Kristof Provost <[email protected]>
AuthorDate: 2026-06-11 12:53:31 +0000
Commit:     Kristof Provost <[email protected]>
CommitDate: 2026-06-26 23:02:04 +0000

    libpfctl: retrieve family id only once
    
    Look up the pfctl family id when we open the handle, rather than for
    every function call.
    This saves us a lot of netlink calls, at the expense of storing one
    extra int in the handle.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit 2a478dfc7f9cd60037939e121026bf26a01e8c41)
---
 lib/libpfctl/libpfctl.c | 260 +++++++++++++-----------------------------------
 1 file changed, 68 insertions(+), 192 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 74d319cd2ad1..a97ca92e5144 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -59,6 +59,7 @@
 struct pfctl_handle {
        int fd;
        struct snl_state ss;
+       int family_id;
 };
 
 const char* PFCTL_SYNCOOKIES_MODE_NAMES[] = {
@@ -84,6 +85,10 @@ pfctl_open(const char *pf_device)
        if (!snl_init(&h->ss, NETLINK_GENERIC))
                goto error;
 
+       h->family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
+       if (h->family_id == 0)
+               goto error;
+
        return (h);
 error:
        if (h->fd != -1)
@@ -115,14 +120,9 @@ pfctl_do_netlink_cmd(struct pfctl_handle *h, uint cmd)
        struct snl_writer nw;
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, cmd);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id, cmd);
 
        hdr = snl_finalize_msg(&nw);
        if (hdr == NULL)
@@ -407,16 +407,12 @@ pfctl_get_status_h(struct pfctl_handle *h)
        struct nlmsghdr *hdr;
        struct snl_writer nw;
        uint32_t seq_id;
-       int family_id;
 
        SNL_VERIFY_PARSERS(stat_parser);
 
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (NULL);
-
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_STATUS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_STATUS);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        hdr = snl_finalize_msg(&nw);
@@ -1342,14 +1338,10 @@ pfctl_add_rule_h(struct pfctl_handle *h, const struct 
pfctl_rule *r,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_ADDRULE);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_ADDRULE);
        hdr->nlmsg_flags |= NLM_F_DUMP;
        snl_add_msg_attr_u32(&nw, PF_ART_TICKET, ticket);
        snl_add_msg_attr_u32(&nw, PF_ART_POOL_TICKET, pool_ticket);
@@ -1390,14 +1382,10 @@ pfctl_get_rules_info_h(struct pfctl_handle *h, struct 
pfctl_rules_info *rules, u
        struct nlmsghdr *hdr;
        struct snl_writer nw;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETRULES);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GETRULES);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_string(&nw, PF_GR_ANCHOR, path);
@@ -1716,14 +1704,10 @@ pfctl_get_clear_rule_h(struct pfctl_handle *h, uint32_t 
nr, uint32_t ticket,
        struct nlmsghdr *hdr;
        struct snl_writer nw;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETRULE);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GETRULE);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_string(&nw, PF_GR_ANCHOR, anchor);
@@ -1819,35 +1803,30 @@ static struct snl_attr_parser ap_creators[] = {
 #undef _OUT
 SNL_DECLARE_PARSER(creator_parser, struct genlmsghdr, snl_f_p_empty, 
ap_creators);
 
-static int
-pfctl_get_creators_nl(struct snl_state *ss, uint32_t *creators, size_t *len)
+int
+pfctl_get_creatorids(struct pfctl_handle *h, uint32_t *creators, size_t *len)
 {
-
-       int family_id = snl_get_genl_family(ss, PFNL_FAMILY_NAME);
-       size_t i = 0;
-
        struct nlmsghdr *hdr;
        struct snl_writer nw;
+       size_t i = 0;
 
-       if (family_id == 0)
-               return (ENOTSUP);
-
-       snl_init_writer(ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETCREATORS);
+       snl_init_writer(&h->ss, &nw);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GETCREATORS);
        hdr->nlmsg_flags |= NLM_F_DUMP;
        hdr = snl_finalize_msg(&nw);
        if (hdr == NULL)
                return (ENOMEM);
        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_creator c;
                bzero(&c, sizeof(c));
 
-               if (!snl_parse_nlmsg(ss, hdr, &creator_parser, &c))
+               if (!snl_parse_nlmsg(&h->ss, hdr, &creator_parser, &c))
                        continue;
 
                creators[i] = c.id;
@@ -1861,16 +1840,6 @@ pfctl_get_creators_nl(struct snl_state *ss, uint32_t 
*creators, size_t *len)
        return (0);
 }
 
-int
-pfctl_get_creatorids(struct pfctl_handle *h, uint32_t *creators, size_t *len)
-{
-       int error;
-
-       error = pfctl_get_creators_nl(&h->ss, creators, len);
-
-       return (error);
-}
-
 static inline bool
 snl_attr_get_pfaddr(struct snl_state *ss __unused, struct nlattr *nla,
     const void *arg __unused, void *target)
@@ -2089,14 +2058,9 @@ _pfctl_clear_states_h(struct pfctl_handle *h, const 
struct pfctl_kill *kill,
        struct pfctl_nl_clear_states attrs = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, cmd);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id, cmd);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_u64(&nw, PF_CS_CMP_ID, kill->cmp.id);
@@ -2450,14 +2414,10 @@ _pfctl_table_add_addrs_h(struct pfctl_handle *h, struct 
pfr_table *tbl, struct p
        struct nlmsghdr *hdr;
        uint32_t seq_id;
        uint32_t added;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_TABLE_ADD_ADDR);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_TABLE_ADD_ADDR);
 
        snl_add_msg_attr_table(&nw, PF_TA_TABLE, tbl);
        snl_add_msg_attr_u32(&nw, PF_TA_FLAGS, flags);
@@ -2517,14 +2477,10 @@ _pfctl_table_del_addrs_h(struct pfctl_handle *h, struct 
pfr_table *tbl, struct p
        struct nlmsghdr *hdr;
        uint32_t seq_id;
        uint32_t deleted;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_TABLE_DEL_ADDR);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_TABLE_DEL_ADDR);
 
        snl_add_msg_attr_table(&nw, PF_TA_TABLE, tbl);
        snl_add_msg_attr_u32(&nw, PF_TA_FLAGS, flags);
@@ -2652,14 +2608,10 @@ pfctl_set_statusif(struct pfctl_handle *h, const char 
*ifname)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_SET_STATUSIF);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_SET_STATUSIF);
 
        snl_add_msg_attr_string(&nw, PF_SS_IFNAME, ifname);
 
@@ -2697,14 +2649,10 @@ pfctl_natlook(struct pfctl_handle *h, const struct 
pfctl_natlook_key *k,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_NATLOOK);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_NATLOOK);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_u8(&nw, PF_NL_AF, k->af);
@@ -2738,14 +2686,10 @@ pfctl_set_debug(struct pfctl_handle *h, uint32_t level)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_SET_DEBUG);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_SET_DEBUG);
 
        snl_add_msg_attr_u32(&nw, PF_SD_LEVEL, level);
 
@@ -2770,14 +2714,10 @@ pfctl_set_timeout(struct pfctl_handle *h, uint32_t 
timeout, uint32_t seconds)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_SET_TIMEOUT);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_SET_TIMEOUT);
 
        snl_add_msg_attr_u32(&nw, PF_TO_TIMEOUT, timeout);
        snl_add_msg_attr_u32(&nw, PF_TO_SECONDS, seconds);
@@ -2814,14 +2754,10 @@ pfctl_get_timeout(struct pfctl_handle *h, uint32_t 
timeout, uint32_t *seconds)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_TIMEOUT);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_TIMEOUT);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_u32(&nw, PF_TO_TIMEOUT, timeout);
@@ -2852,14 +2788,10 @@ pfctl_set_limit(struct pfctl_handle *h, const int 
index, const uint limit)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_SET_LIMIT);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_SET_LIMIT);
 
        snl_add_msg_attr_u32(&nw, PF_LI_INDEX, index);
        snl_add_msg_attr_u32(&nw, PF_LI_LIMIT, limit);
@@ -2896,14 +2828,10 @@ pfctl_get_limit(struct pfctl_handle *h, const int 
index, uint *limit)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_LIMIT);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_LIMIT);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        snl_add_msg_attr_u32(&nw, PF_LI_INDEX, index);
@@ -2945,14 +2873,10 @@ pfctl_begin_addrs(struct pfctl_handle *h, uint32_t 
*ticket)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_BEGIN_ADDRS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_BEGIN_ADDRS);
        hdr->nlmsg_flags |= NLM_F_DUMP;
 
        if ((hdr = snl_finalize_msg(&nw)) == NULL)
@@ -2981,14 +2905,10 @@ pfctl_add_addr(struct pfctl_handle *h, const struct 
pfioc_pooladdr *pa, int whic
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_ADD_ADDR);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_ADD_ADDR);
 
        snl_add_msg_attr_u32(&nw, PF_AA_ACTION, pa->action);
        snl_add_msg_attr_u32(&nw, PF_AA_TICKET, pa->ticket);
@@ -3028,14 +2948,10 @@ pfctl_get_addrs(struct pfctl_handle *h, uint32_t 
ticket, uint32_t r_num,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_ADDRS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_ADDRS);
 
        snl_add_msg_attr_u32(&nw, PF_AA_TICKET, ticket);
        snl_add_msg_attr_u32(&nw, PF_AA_R_NUM, r_num);
@@ -3091,14 +3007,10 @@ pfctl_get_addr(struct pfctl_handle *h, uint32_t ticket, 
uint32_t r_num,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id =snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_ADDR);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_ADDR);
 
        snl_add_msg_attr_u32(&nw, PF_AA_TICKET, ticket);
        snl_add_msg_attr_u32(&nw, PF_AA_R_NUM, r_num);
@@ -3139,14 +3051,10 @@ pfctl_get_rulesets(struct pfctl_handle *h, const char 
*path, uint32_t *nr)
        struct nlmsghdr *hdr;
        struct pfioc_ruleset rs = {};
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_GET_RULESETS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_RULESETS);
 
        snl_add_msg_attr_string(&nw, PF_RS_PATH, path);
 
@@ -3175,14 +3083,10 @@ pfctl_get_ruleset(struct pfctl_handle *h, const char 
*path, uint32_t nr, struct
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_RULESET);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_RULESET);
 
        snl_add_msg_attr_string(&nw, PF_RS_PATH, path);
        snl_add_msg_attr_u32(&nw, PF_RS_NR, nr);
@@ -3236,15 +3140,11 @@ pfctl_get_srcnodes(struct pfctl_handle *h, 
pfctl_get_srcnode_fn fn, void *arg)
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
        int ret;
 
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
-
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_GET_SRCNODES);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_SRCNODES);
 
        if ((hdr = snl_finalize_msg(&nw)) == NULL)
                return (ENXIO);
@@ -3280,14 +3180,10 @@ pfctl_clear_tables(struct pfctl_handle *h, struct 
pfr_table *filter,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, 
PFNL_CMD_CLEAR_TABLES);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_CLEAR_TABLES);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, filter->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, filter->pfrt_name);
@@ -3322,14 +3218,10 @@ pfctl_add_table(struct pfctl_handle *h, struct 
pfr_table *table,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_ADD_TABLE);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_ADD_TABLE);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, table->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, table->pfrt_name);
@@ -3360,14 +3252,10 @@ pfctl_del_table(struct pfctl_handle *h, struct 
pfr_table *table,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_DEL_TABLE);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_DEL_TABLE);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, table->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, table->pfrt_name);
@@ -3445,15 +3333,11 @@ pfctl_get_tstats(struct pfctl_handle *h, const struct 
pfr_table *filter,
        struct snl_errmsg_data e = {};
        struct nlmsghdr *hdr;
        uint32_t seq_id;
-       int family_id;
        int ret;
 
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
-
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GET_TSTATS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_GET_TSTATS);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, filter->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, filter->pfrt_name);
@@ -3495,14 +3379,10 @@ pfctl_clear_tstats(struct pfctl_handle *h, const struct 
pfr_table *filter,
        struct nlmsghdr *hdr;
        uint64_t zero;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_CLR_TSTATS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_CLR_TSTATS);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, filter->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, filter->pfrt_name);
@@ -3541,14 +3421,10 @@ pfctl_clear_addrs(struct pfctl_handle *h, const struct 
pfr_table *filter,
        struct nlmsghdr *hdr;
        uint64_t del;
        uint32_t seq_id;
-       int family_id;
-
-       family_id = snl_get_genl_family(&h->ss, PFNL_FAMILY_NAME);
-       if (family_id == 0)
-               return (ENOTSUP);
 
        snl_init_writer(&h->ss, &nw);
-       hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_CLR_ADDRS);
+       hdr = snl_create_genl_msg_request(&nw, h->family_id,
+           PFNL_CMD_CLR_ADDRS);
 
        snl_add_msg_attr_string(&nw, PF_T_ANCHOR, filter->pfrt_anchor);
        snl_add_msg_attr_string(&nw, PF_T_NAME, filter->pfrt_name);

Reply via email to