Commit 11113e19 authored by Patrick McHardy's avatar Patrick McHardy Committed by Pablo Neira Ayuso

netfilter: nf_tables: support different set binding types

Currently a set binding is assumed to be related to a lookup and, in
case of maps, a data load.

In order to use bindings for set updates, the loop detection checks
must be restricted to map operations only. Add a flags member to the
binding struct to hold the set "action" flags such as NFT_SET_MAP,
and perform loop detection based on these.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 3dd0673a
...@@ -316,6 +316,7 @@ static inline unsigned long nft_set_gc_interval(const struct nft_set *set) ...@@ -316,6 +316,7 @@ static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
* *
* @list: set bindings list node * @list: set bindings list node
* @chain: chain containing the rule bound to the set * @chain: chain containing the rule bound to the set
* @flags: set action flags
* *
* A set binding contains all information necessary for validation * A set binding contains all information necessary for validation
* of new elements added to a bound set. * of new elements added to a bound set.
...@@ -323,6 +324,7 @@ static inline unsigned long nft_set_gc_interval(const struct nft_set *set) ...@@ -323,6 +324,7 @@ static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
struct nft_set_binding { struct nft_set_binding {
struct list_head list; struct list_head list;
const struct nft_chain *chain; const struct nft_chain *chain;
u32 flags;
}; };
int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
......
...@@ -2811,12 +2811,13 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, ...@@ -2811,12 +2811,13 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
if (!list_empty(&set->bindings) && set->flags & NFT_SET_ANONYMOUS) if (!list_empty(&set->bindings) && set->flags & NFT_SET_ANONYMOUS)
return -EBUSY; return -EBUSY;
if (set->flags & NFT_SET_MAP) { if (binding->flags & NFT_SET_MAP) {
/* If the set is already bound to the same chain all /* If the set is already bound to the same chain all
* jumps are already validated for that chain. * jumps are already validated for that chain.
*/ */
list_for_each_entry(i, &set->bindings, list) { list_for_each_entry(i, &set->bindings, list) {
if (i->chain == binding->chain) if (binding->flags & NFT_SET_MAP &&
i->chain == binding->chain)
goto bind; goto bind;
} }
...@@ -3312,6 +3313,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, ...@@ -3312,6 +3313,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
.chain = (struct nft_chain *)binding->chain, .chain = (struct nft_chain *)binding->chain,
}; };
if (!(binding->flags & NFT_SET_MAP))
continue;
err = nft_validate_data_load(&bind_ctx, dreg, err = nft_validate_data_load(&bind_ctx, dreg,
&data, d2.type); &data, d2.type);
if (err < 0) if (err < 0)
...@@ -4063,7 +4067,8 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx, ...@@ -4063,7 +4067,8 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,
continue; continue;
list_for_each_entry(binding, &set->bindings, list) { list_for_each_entry(binding, &set->bindings, list) {
if (binding->chain != chain) if (!(binding->flags & NFT_SET_MAP) ||
binding->chain != chain)
continue; continue;
iter.skip = 0; iter.skip = 0;
......
...@@ -92,6 +92,8 @@ static int nft_lookup_init(const struct nft_ctx *ctx, ...@@ -92,6 +92,8 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
} else if (set->flags & NFT_SET_MAP) } else if (set->flags & NFT_SET_MAP)
return -EINVAL; return -EINVAL;
priv->binding.flags = set->flags & NFT_SET_MAP;
err = nf_tables_bind_set(ctx, set, &priv->binding); err = nf_tables_bind_set(ctx, set, &priv->binding);
if (err < 0) if (err < 0)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment