Skip to contentSkip to conversation

netfilter: nf_tables: fix set size with rbtree backend

PATCH New Pablo Neira Ayuso 1 participant 1 message Jan 6, 2025

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 netfilter: nf_tables: fix set size with rbtree backend

The existing rbtree implementation uses singleton elements to represent ranges, however, userspace provides a set size according to the number of ranges in the set.

Adjust provided userspace set size to the number of singleton elements in the kernel by multiplying the range by two.

Check if the no-match all-zero element is already in the set, in such case release one slot in the set size.

Fixes 0ed6389c483d ("netfilter: nf_tables: rename set implementations")

---
v2: make no assumptions on no-match all-zero element which was
inconditionally added in the previous patch, check instead if it is present in the set, then adjust the available element slots by one accordingly.

@Florian: Would you rebase your

netfilter: nf_tables: export set count and backend name to userspace

on top of this patch? The idea would be to use .usize to expose the set size through 'nft list ruleset' as we discussed, instead of only displaying this via --debug. Thanks.

 include/net/netfilter/nf_tables.h |  3 ++
 net/netfilter/nf_tables_api.c     | 49 +++++++++++++++++++++++++++++--
 net/netfilter/nft_set_rbtree.c    | 43 +++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables.h +3 -0
index 0027beca5cd5..7dcea247f853 100644
@@ -495,6 +495,9 @@ struct nft_set_ops {
 					       const struct nft_set *set,
 					       const struct nft_set_elem *elem,
 					       unsigned int flags);
+	u32				(*ksize)(u32 size);
+	u32				(*usize)(u32 size);
+	u32				(*adjust_maxsize)(const struct nft_set *set);
 	void				(*commit)(struct nft_set *set);
 	void				(*abort)(const struct nft_set *set);
 	u64				(*privsize)(const struct nlattr * const nla[],
net/netfilter/nf_tables_api.c +47 -2

91 lines not on this page · raw message

net/netfilter/nft_set_rbtree.c +43 -0

54 lines not on this page · raw message

Signature · 1 line
2.30.2