netfilter: nf_tables: fix set size with rbtree backend
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 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.
---
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
@@ -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