]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit - net/netfilter/nft_set_hash.c
netfilter: nf_tables: implement proper set selection
authorPatrick McHardy <kaber@trash.net>
Fri, 28 Mar 2014 10:19:47 +0000 (10:19 +0000)
committerPablo Neira Ayuso <pablo@gnumonks.org>
Wed, 2 Apr 2014 19:32:57 +0000 (21:32 +0200)
commitc50b960ccc5981627628302701e93e6aceccdb1c
tree3621dae1299222f46a2096694cb8c936abc02f5e
parentfe92ca45a170cb8d09c163db23d46634110b3c2f
netfilter: nf_tables: implement proper set selection

The current set selection simply choses the first set type that provides
the requested features, which always results in the rbtree being chosen
by virtue of being the first set in the list.

What we actually want to do is choose the implementation that can provide
the requested features and is optimal from either a performance or memory
perspective depending on the characteristics of the elements and the
preferences specified by the user.

The elements are not known when creating a set. Even if we would provide
them for anonymous (literal) sets, we'd still have standalone sets where
the elements are not known in advance. We therefore need an abstract
description of the data charcteristics.

The kernel already knows the size of the key, this patch starts by
introducing a nested set description which so far contains only the maximum
amount of elements. Based on this the set implementations are changed to
provide an estimate of the required amount of memory and the lookup
complexity class.

The set ops have a new callback ->estimate() that is invoked during set
selection. It receives a structure containing the attributes known to the
kernel and is supposed to populate a struct nft_set_estimate with the
complexity class and, in case the size is known, the complete amount of
memory required, or the amount of memory required per element otherwise.

Based on the policy specified by the user (performance/memory, defaulting
to performance) the kernel will then select the best suited implementation.

Even if the set implementation would allow to add more than the specified
maximum amount of elements, they are enforced since new implementations
might not be able to add more than maximum based on which they were
selected.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_tables.h
include/uapi/linux/netfilter/nf_tables.h
net/netfilter/nf_tables_api.c
net/netfilter/nft_hash.c
net/netfilter/nft_rbtree.c