History

netfilter: nf_tables: enable set expiration time for set elements

Currently, the expiration of every element in a set or map is a read-only parameter generated at kernel side. This change will permit to set a certain expiration date per element that will be required, for example, during stateful replication among several nodes. This patch handles the NFTA_SET_ELEM_EXPIRATION in order to configure the expiration parameter per element, or will use the timeout in the case that the expiration is not set.

Laura Garcia Liebana committed 7 years ago

Commit 79ebb5b1 parent 2f0513d3 files · +22 −8Browse files

Unified · Split

3 files
  1. include/net/netfilter/nf_tables.h +1 −1
  2. net/netfilter/nf_tables_api.c +20 −6
  3. net/netfilter/nft_dynset.c +1 −1
include/net/netfilter/nf_tables.h+1−1
@@ -636,7 +636,7 @@ static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext) · 635 unmodified lines
636636 void *nft_set_elem_init(const struct nft_set *set,
637637 const struct nft_set_ext_tmpl *tmpl,
638638 const u32 *key, const u32 *data,
639− u64 timeout, gfp_t gfp);
639+ u64 timeout, u64 expiration, gfp_t gfp);
640640 void nft_set_elem_destroy(const struct nft_set *set, void *elem,
641641 bool destroy_expr);
642642
net/netfilter/nf_tables_api.c+20−6
@@ -3873,6 +3873,7 @@ static const struct nla_policy nft_set_elem_policy[NFTA_SET_ELEM_MAX + 1] = { · 3872 unmodified lines
38733873 [NFTA_SET_ELEM_DATA] = { .type = NLA_NESTED },
38743874 [NFTA_SET_ELEM_FLAGS] = { .type = NLA_U32 },
38753875 [NFTA_SET_ELEM_TIMEOUT] = { .type = NLA_U64 },
3876+ [NFTA_SET_ELEM_EXPIRATION] = { .type = NLA_U64 },
38763877 [NFTA_SET_ELEM_USERDATA] = { .type = NLA_BINARY,
38773878 .len = NFT_USERDATA_MAXLEN },
38783879 [NFTA_SET_ELEM_EXPR] = { .type = NLA_NESTED },
@@ -4326,7 +4327,7 @@ static struct nft_trans *nft_trans_elem_alloc(struct nft_ctx *ctx, · 447 unmodified lines
43264327 void *nft_set_elem_init(const struct nft_set *set,
43274328 const struct nft_set_ext_tmpl *tmpl,
43284329 const u32 *key, const u32 *data,
4329− u64 timeout, gfp_t gfp)
4330+ u64 timeout, u64 expiration, gfp_t gfp)
43304331 {
43314332 struct nft_set_ext *ext;
43324333 void *elem;
@@ -4341,9 +4342,11 @@ void *nft_set_elem_init(const struct nft_set *set, · 8 unmodified lines
43414342 memcpy(nft_set_ext_key(ext), key, set->klen);
43424343 if (nft_set_ext_exists(ext, NFT_SET_EXT_DATA))
43434344 memcpy(nft_set_ext_data(ext), data, set->dlen);
4344− if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION))
4345− *nft_set_ext_expiration(ext) =
4346− get_jiffies_64() + timeout;
4345+ if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION)) {
4346+ *nft_set_ext_expiration(ext) = get_jiffies_64() + expiration;
4347+ if (expiration == 0)
4348+ *nft_set_ext_expiration(ext) += timeout;
4349+ }
43474350 if (nft_set_ext_exists(ext, NFT_SET_EXT_TIMEOUT))
43484351 *nft_set_ext_timeout(ext) = timeout;
43494352
@@ -4408,6 +4411,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 58 unmodified lines
44084411 struct nft_trans *trans;
44094412 u32 flags = 0;
44104413 u64 timeout;
4414+ u64 expiration;
44114415 u8 ulen;
44124416 int err;
44134417
@@ -4451,6 +4455,16 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 37 unmodified lines
44514455 timeout = set->timeout;
44524456 }
44534457
4458+ expiration = 0;
4459+ if (nla[NFTA_SET_ELEM_EXPIRATION] != NULL) {
4460+ if (!(set->flags & NFT_SET_TIMEOUT))
4461+ return -EINVAL;
4462+ err = nf_msecs_to_jiffies64(nla[NFTA_SET_ELEM_EXPIRATION],
4463+ &expiration);
4464+ if (err)
4465+ return err;
4466+ }
4467+
44544468 err = nft_data_init(ctx, &elem.key.val, sizeof(elem.key), &d1,
44554469 nla[NFTA_SET_ELEM_KEY]);
44564470 if (err < 0)
@@ -4533,7 +4547,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 76 unmodified lines
45334547
45344548 err = -ENOMEM;
45354549 elem.priv = nft_set_elem_init(set, &tmpl, elem.key.val.data, data.data,
4536− timeout, GFP_KERNEL);
4550+ timeout, expiration, GFP_KERNEL);
45374551 if (elem.priv == NULL)
45384552 goto err3;
45394553
@@ -4735,7 +4749,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set, · 195 unmodified lines
47354749
47364750 err = -ENOMEM;
47374751 elem.priv = nft_set_elem_init(set, &tmpl, elem.key.val.data, NULL, 0,
4738− GFP_KERNEL);
4752+ 0, GFP_KERNEL);
47394753 if (elem.priv == NULL)
47404754 goto err2;
47414755
net/netfilter/nft_dynset.c+1−1
@@ -60,7 +60,7 @@ static void *nft_dynset_new(struct nft_set *set, const struct nft_expr *expr, · 59 unmodified lines
6060 elem = nft_set_elem_init(set, &priv->tmpl,
6161 &regs->data[priv->sreg_key],
6262 &regs->data[priv->sreg_data],
63− timeout, GFP_ATOMIC);
63+ timeout, 0, GFP_ATOMIC);
6464 if (elem == NULL)
6565 goto err1;
6666

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t