aboutsummaryrefslogtreecommitdiffstats
path: root/net/netfilter/nft_set_hash.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-05-22 17:47:56 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2017-05-29 12:46:19 +0200
commit2111515abc46cb3e18b22d8551067029acfd1f55 (patch)
treec5d35f1856b9007aa4c2eedd71923cb790cb40f7 /net/netfilter/nft_set_hash.c
parentnetfilter: nf_tables: pass set description to ->privsize (diff)
downloadlinux-dev-2111515abc46cb3e18b22d8551067029acfd1f55.tar.xz
linux-dev-2111515abc46cb3e18b22d8551067029acfd1f55.zip
netfilter: nft_set_hash: add nft_hash_buckets()
Add nft_hash_buckets() helper function to calculate the number of hashtable buckets based on the elements. This function can be reused from the follow up patch to add non-resizable hashtables. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/netfilter/nft_set_hash.c')
-rw-r--r--net/netfilter/nft_set_hash.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/net/netfilter/nft_set_hash.c b/net/netfilter/nft_set_hash.c
index 455a11ce8cd0..466cb7092dfa 100644
--- a/net/netfilter/nft_set_hash.c
+++ b/net/netfilter/nft_set_hash.c
@@ -363,12 +363,17 @@ static void nft_rhash_destroy(const struct nft_set *set)
(void *)set);
}
+static u32 nft_hash_buckets(u32 size)
+{
+ return roundup_pow_of_two(size * 4 / 3);
+}
+
static bool nft_rhash_estimate(const struct nft_set_desc *desc, u32 features,
struct nft_set_estimate *est)
{
if (desc->size)
est->size = sizeof(struct nft_rhash) +
- roundup_pow_of_two(desc->size * 4 / 3) *
+ nft_hash_buckets(desc->size) *
sizeof(struct nft_rhash_elem *) +
desc->size * sizeof(struct nft_rhash_elem);
else