Skip to content

Commit 11113e1

Browse files
kaberummakynes
authored andcommitted
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: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 3dd0673 commit 11113e1

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎include/net/netfilter/nf_tables.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,15 @@ static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
316316
*
317317
* @list: set bindings list node
318318
* @chain: chain containing the rule bound to the set
319+
* @flags: set action flags
319320
*
320321
* A set binding contains all information necessary for validation
321322
* of new elements added to a bound set.
322323
*/
323324
struct nft_set_binding {
324325
struct list_head list;
325326
const struct nft_chain *chain;
327+
u32 flags;
326328
};
327329

328330
int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,

‎net/netfilter/nf_tables_api.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,12 +2811,13 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
28112811
if (!list_empty(&set->bindings) && set->flags & NFT_SET_ANONYMOUS)
28122812
return -EBUSY;
28132813

2814-
if (set->flags & NFT_SET_MAP) {
2814+
if (binding->flags & NFT_SET_MAP) {
28152815
/* If the set is already bound to the same chain all
28162816
* jumps are already validated for that chain.
28172817
*/
28182818
list_for_each_entry(i, &set->bindings, list) {
2819-
if (i->chain == binding->chain)
2819+
if (binding->flags & NFT_SET_MAP &&
2820+
i->chain == binding->chain)
28202821
goto bind;
28212822
}
28222823

@@ -3312,6 +3313,9 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
33123313
.chain = (struct nft_chain *)binding->chain,
33133314
};
33143315

3316+
if (!(binding->flags & NFT_SET_MAP))
3317+
continue;
3318+
33153319
err = nft_validate_data_load(&bind_ctx, dreg,
33163320
&data, d2.type);
33173321
if (err < 0)
@@ -4063,7 +4067,8 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,
40634067
continue;
40644068

40654069
list_for_each_entry(binding, &set->bindings, list) {
4066-
if (binding->chain != chain)
4070+
if (!(binding->flags & NFT_SET_MAP) ||
4071+
binding->chain != chain)
40674072
continue;
40684073

40694074
iter.skip = 0;

‎net/netfilter/nft_lookup.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
9292
} else if (set->flags & NFT_SET_MAP)
9393
return -EINVAL;
9494

95+
priv->binding.flags = set->flags & NFT_SET_MAP;
96+
9597
err = nf_tables_bind_set(ctx, set, &priv->binding);
9698
if (err < 0)
9799
return err;

0 commit comments

Comments
 (0)