aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2023-11-06 10:57:35 +0000
committerKristof Provost <kp@FreeBSD.org>2023-11-06 12:53:56 +0000
commit497ccc21ef9378f92e30867fa2b473759fd64b45 (patch)
treefd55c78d4d2810f719c4cec7bb46b8b742e3aec3
parentbce728719e7f57272d99b6d039f10b4c636fa024 (diff)
libpfctl: handle the 'pfctl' netlink family not being supported
If we fail to find the pfctl family we should not attempt to make the call. That means that either pf is not loaded, or it's a very old (i.e. pre-netlink) version. Reported by: manu Sponsored by: Rubicon Communications, LLC ("Netgate")
-rw-r--r--lib/libpfctl/libpfctl.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 1554b81acf59..12b7c1df7ee8 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -189,6 +189,8 @@ pfctl_startstop(int start)
snl_init(&ss, NETLINK_GENERIC);
family_id = snl_get_genl_family(&ss, PFNL_FAMILY_NAME);
+ if (family_id == 0)
+ return (ENOTSUP);
snl_init_writer(&ss, &nw);
hdr = snl_create_genl_msg_request(&nw, family_id,
@@ -1077,6 +1079,8 @@ pfctl_add_rule(int dev __unused, const struct pfctl_rule *r, const char *anchor,
snl_init(&ss, NETLINK_GENERIC);
family_id = snl_get_genl_family(&ss, PFNL_FAMILY_NAME);
+ if (family_id == 0)
+ return (ENOTSUP);
snl_init_writer(&ss, &nw);
hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_ADDRULE);
@@ -1213,6 +1217,9 @@ pfctl_get_creators_nl(struct snl_state *ss, uint32_t *creators, size_t *len)
struct nlmsghdr *hdr;
struct snl_writer nw;
+ if (family_id == 0)
+ return (ENOTSUP);
+
snl_init_writer(ss, &nw);
hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETCREATORS);
hdr->nlmsg_flags |= NLM_F_DUMP;
@@ -1363,6 +1370,9 @@ pfctl_get_states_nl(struct pfctl_state_filter *filter, struct snl_state *ss, pfc
struct nlmsghdr *hdr;
struct snl_writer nw;
+ if (family_id == 0)
+ return (ENOTSUP);
+
snl_init_writer(ss, &nw);
hdr = snl_create_genl_msg_request(&nw, family_id, PFNL_CMD_GETSTATES);
hdr->nlmsg_flags |= NLM_F_DUMP;