Skip to content

Commit

Permalink
netfilter: nft_set_hash: add nft_hash_buckets()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pablo Neira Ayuso committed May 29, 2017
1 parent 347b408 commit 2111515
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/netfilter/nft_set_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2111515

Please sign in to comment.