Skip to content

Commit 7c6c6e9

Browse files
kaberummakynes
authored andcommitted
netfilter: nf_tables: add flag to indicate set contains expressions
Add a set flag to indicate that the set is used as a state table and contains expressions for evaluation. This operation is mutually exclusive with the mapping operation, so sets specifying both are rejected. The lookup expression also rejects binding to state tables since it only deals with loopup and map operations. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 151d799 commit 7c6c6e9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ enum nft_rule_compat_attributes {
238238
* @NFT_SET_INTERVAL: set contains intervals
239239
* @NFT_SET_MAP: set is used as a dictionary
240240
* @NFT_SET_TIMEOUT: set uses timeouts
241+
* @NFT_SET_EVAL: set contains expressions for evaluation
241242
*/
242243
enum nft_set_flags {
243244
NFT_SET_ANONYMOUS = 0x1,
244245
NFT_SET_CONSTANT = 0x2,
245246
NFT_SET_INTERVAL = 0x4,
246247
NFT_SET_MAP = 0x8,
247248
NFT_SET_TIMEOUT = 0x10,
249+
NFT_SET_EVAL = 0x20,
248250
};
249251

250252
/**

net/netfilter/nf_tables_api.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,9 +2661,13 @@ static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb,
26612661
if (nla[NFTA_SET_FLAGS] != NULL) {
26622662
flags = ntohl(nla_get_be32(nla[NFTA_SET_FLAGS]));
26632663
if (flags & ~(NFT_SET_ANONYMOUS | NFT_SET_CONSTANT |
2664-
NFT_SET_INTERVAL | NFT_SET_MAP |
2665-
NFT_SET_TIMEOUT))
2664+
NFT_SET_INTERVAL | NFT_SET_TIMEOUT |
2665+
NFT_SET_MAP | NFT_SET_EVAL))
26662666
return -EINVAL;
2667+
/* Only one of both operations is supported */
2668+
if ((flags & (NFT_SET_MAP | NFT_SET_EVAL)) ==
2669+
(NFT_SET_MAP | NFT_SET_EVAL))
2670+
return -EOPNOTSUPP;
26672671
}
26682672

26692673
dtype = 0;

net/netfilter/nft_lookup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
7171
return PTR_ERR(set);
7272
}
7373

74+
if (set->flags & NFT_SET_EVAL)
75+
return -EOPNOTSUPP;
76+
7477
priv->sreg = nft_parse_register(tb[NFTA_LOOKUP_SREG]);
7578
err = nft_validate_register_load(priv->sreg, set->klen);
7679
if (err < 0)

0 commit comments

Comments
 (0)