From nobody Fri Jun 26 23:02:14 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gnB5L2jDSz6j6N1 for ; Fri, 26 Jun 2026 23:02:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gnB5L2DhPz3ws3 for ; Fri, 26 Jun 2026 23:02:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782514934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/wRmQ5p/UwGJ7uqGMYP5IQh4hwbrnSa8YBJTUwN/g18=; b=j9J5cVgzv/8zeLvoL9/xtTB+X5MPlG/RU+eLzsn9mM1z1JiBx1Xz98FBHV2CjtpQJ/qysu s+J4MnaLN/RRXOU9d63xitxiGS790DVpP+ALNttcD7wgVxpfMqPKwrgmlbCyhNyMFsJ+G+ DGUo/TJVQ7o2MbC7tAfPUGHoPnrhjt4pg8RwYw3emka04OCa0O4vJsxtvPri5CSt9er5us qLECCYLC/lVjMrDm7YcsSdlqEjqUjUadmQ+ZZr1DXFsYaHv3SpGBc6LoL/V64thYgCVj2t GYcXQ7gSZ2EaS5z0mvzc53zWXG2ikakuV/DSlryabyBPH2XV//zzKHkGZ1w26Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782514934; a=rsa-sha256; cv=none; b=tHsqLyCepotvHrNmk+8bGP8C5WmHAH7m3HRsiTazU/O26TyMhrM1IVyfkWc+e1rI9O6SJr 0XcYdQPVfhtLK/ebCtVSJ5nu5i3ZUBUVJ7uTh3HfrZ9p0WNMbOoFIon4BfcxOmdODQs9sY vjwy/5oSgWOlfHB5pWilTztQkcqCIQlmy1QTo/HOzBuJMo4vMVgpE0gf8iiUqZbbT/zpN3 /ZOC0OL2Z8SL4En5q2i36bkfXAxX0qVwwfWnUhToih0KyX9rgoGROYT4zgjDu/udNZPuZd A9Fw7+laLKptsWNccq8ZHEwVV6goQkudWu1PJggjLMdtnP2YId5u7IMy5mA+dA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782514934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/wRmQ5p/UwGJ7uqGMYP5IQh4hwbrnSa8YBJTUwN/g18=; b=sNAQ1hlPCgTol/zYlsg6aGw6pZiBEYT1bPY/pyqGxQ+L7M+uRUtMnbwd11PXhVSDnTnjfQ 53+Y6QHBPfT8a68EdgrTU0bgh6NowzMSBYXNe1WnUq/iPHpOFqnjiJQdToNTnfedaqGe85 HrcmlPBlMkjM3vzQ9tlK569Mo2yKDn+t8CGVDRVLz609UGJb8PoSG0B66hccBNTl8yNdB8 00/59C9sYo1+fuz8VBM5ddweFFK5h+R33T8F+IVSBILou04m8AAp3JqLIu4wEMXeBzZR32 nzfO41chYtsqXVN5T+Oq+5W440IkoD3MhO6i5BvlU6WatwGUTWTwNJsje4UGBw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gnB5L0nbTzyX2 for ; Fri, 26 Jun 2026 23:02:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 36072 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 26 Jun 2026 23:02:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: f95439f6c9d0 - stable/15 - libpfctl: retrieve family id only once List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: f95439f6c9d0e0a4af6a834ec7a0c7fb5279406d Auto-Submitted: auto-generated Date: Fri, 26 Jun 2026 23:02:14 +0000 Message-Id: <6a3f04f6.36072.383de072@gitrepo.freebsd.org> The branch stable/15 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f95439f6c9d0e0a4af6a834ec7a0c7fb5279406d commit f95439f6c9d0e0a4af6a834ec7a0c7fb5279406d Author: Kristof Provost AuthorDate: 2026-06-11 12:53:31 +0000 Commit: Kristof Provost 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);