@@ -153,12 +153,14 @@ struct nft_set_iter {
*
* @klen: key length
* @dlen: data length
- * @size: number of set elements
+ * @size: max number of set elements
+ * @init_size: initial set size
*/
struct nft_set_desc {
unsigned int klen;
unsigned int dlen;
unsigned int size;
+ unsigned int init_size;
};
/**
@@ -230,10 +230,12 @@ enum nft_set_policies {
* enum nft_set_desc_attributes - set element description
*
* @NFTA_SET_DESC_SIZE: number of elements in set (NLA_U32)
+ * @NFTA_SET_DESC_INIT_SIZE: initial set size (NLA_U32)
*/
enum nft_set_desc_attributes {
NFTA_SET_DESC_UNSPEC,
NFTA_SET_DESC_SIZE,
+ NFTA_SET_DESC_INIT_SIZE,
__NFTA_SET_DESC_MAX
};
#define NFTA_SET_DESC_MAX (__NFTA_SET_DESC_MAX - 1)
@@ -2211,6 +2211,7 @@ static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
static const struct nla_policy nft_set_desc_policy[NFTA_SET_DESC_MAX + 1] = {
[NFTA_SET_DESC_SIZE] = { .type = NLA_U32 },
+ [NFTA_SET_DESC_INIT_SIZE] = { .type = NLA_U32 },
};
static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,
@@ -2552,6 +2553,9 @@ static int nf_tables_set_desc_parse(const struct nft_ctx *ctx,
if (da[NFTA_SET_DESC_SIZE] != NULL)
desc->size = ntohl(nla_get_be32(da[NFTA_SET_DESC_SIZE]));
+ if (da[NFTA_SET_DESC_INIT_SIZE] != NULL)
+ desc->init_size = ntohl(nla_get_be32(da[NFTA_SET_DESC_INIT_SIZE]));
+
return 0;
}
@@ -190,7 +190,7 @@ static int nft_hash_init(const struct nft_set *set,
{
struct rhashtable *priv = nft_set_priv(set);
struct rhashtable_params params = {
- .nelem_hint = desc->size ? : NFT_HASH_ELEMENT_HINT,
+ .nelem_hint = desc->init_size ? : NFT_HASH_ELEMENT_HINT,
.head_offset = offsetof(struct nft_hash_elem, node),
.key_offset = offsetof(struct nft_hash_elem, key),
.key_len = set->klen,
Currently nft_hash is using desc->size to both set a ceiling on the number of entries a set can have, and as the nelem_hint for rhashtable. This not correct since nelem_hint defines the # of initial buckets for the set to use. It is not used to enforce a maximum size on the table. That's done through max_shift. This creates a new parameter 'init_size' to pass as the nelem_hint to rhashtable as the # of buckets you would like to initialize the table with. Signed-off-by: Josh Hunt <johunt@akamai.com> --- include/net/netfilter/nf_tables.h | 4 +++- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 4 ++++ net/netfilter/nft_hash.c | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-)