Skip to content

Commit 88cb3a2

Browse files
committed
netfilter: nf_tables: export set count and backend name to userspace
JIRA: https://issues.redhat.com/browse/RHEL-115582 Upstream Status: commit 0014af8 commit 0014af8 Author: Florian Westphal <fw@strlen.de> Date: Tue Apr 8 15:55:53 2025 +0200 netfilter: nf_tables: export set count and backend name to userspace nf_tables picks a suitable set backend implementation (bitmap, hash, rbtree..) based on the userspace requirements. Figuring out the chosen backend requires information about the set flags and the kernel version. Export this to userspace so nft can include this information in '--debug=netlink' output. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent 2e1d366 commit 88cb3a2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ enum nft_set_field_attributes {
394394
* @NFTA_SET_HANDLE: set handle (NLA_U64)
395395
* @NFTA_SET_EXPR: set expression (NLA_NESTED: nft_expr_attributes)
396396
* @NFTA_SET_EXPRESSIONS: list of expressions (NLA_NESTED: nft_list_attributes)
397+
* @NFTA_SET_TYPE: set backend type (NLA_STRING)
398+
* @NFTA_SET_COUNT: number of set elements (NLA_U32)
397399
*/
398400
enum nft_set_attributes {
399401
NFTA_SET_UNSPEC,
@@ -415,6 +417,8 @@ enum nft_set_attributes {
415417
NFTA_SET_HANDLE,
416418
NFTA_SET_EXPR,
417419
NFTA_SET_EXPRESSIONS,
420+
NFTA_SET_TYPE,
421+
NFTA_SET_COUNT,
418422
__NFTA_SET_MAX
419423
};
420424
#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)

net/netfilter/nf_tables_api.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,6 +4564,8 @@ static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
45644564
[NFTA_SET_HANDLE] = { .type = NLA_U64 },
45654565
[NFTA_SET_EXPR] = { .type = NLA_NESTED },
45664566
[NFTA_SET_EXPRESSIONS] = NLA_POLICY_NESTED_ARRAY(nft_expr_policy),
4567+
[NFTA_SET_TYPE] = { .type = NLA_REJECT },
4568+
[NFTA_SET_COUNT] = { .type = NLA_REJECT },
45674569
};
45684570

45694571
static const struct nla_policy nft_concat_policy[NFTA_SET_FIELD_MAX + 1] = {
@@ -4758,6 +4760,27 @@ static u32 nft_set_userspace_size(const struct nft_set_ops *ops, u32 size)
47584760
return size;
47594761
}
47604762

4763+
static noinline_for_stack int
4764+
nf_tables_fill_set_info(struct sk_buff *skb, const struct nft_set *set)
4765+
{
4766+
unsigned int nelems;
4767+
char str[40];
4768+
int ret;
4769+
4770+
ret = snprintf(str, sizeof(str), "%ps", set->ops);
4771+
4772+
/* Not expected to happen and harmless: NFTA_SET_TYPE is dumped
4773+
* to userspace purely for informational/debug purposes.
4774+
*/
4775+
DEBUG_NET_WARN_ON_ONCE(ret >= sizeof(str));
4776+
4777+
if (nla_put_string(skb, NFTA_SET_TYPE, str))
4778+
return -EMSGSIZE;
4779+
4780+
nelems = nft_set_userspace_size(set->ops, atomic_read(&set->nelems));
4781+
return nla_put_be32(skb, NFTA_SET_COUNT, htonl(nelems));
4782+
}
4783+
47614784
static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
47624785
const struct nft_set *set, u16 event, u16 flags)
47634786
{
@@ -4838,6 +4861,9 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
48384861

48394862
nla_nest_end(skb, nest);
48404863

4864+
if (nf_tables_fill_set_info(skb, set))
4865+
goto nla_put_failure;
4866+
48414867
if (set->num_exprs == 1) {
48424868
nest = nla_nest_start_noflag(skb, NFTA_SET_EXPR);
48434869
if (nf_tables_fill_expr_info(skb, set->exprs[0], false) < 0)

0 commit comments

Comments
 (0)