Skip to content

Commit 76adfaf

Browse files
committed
netfilter: nf_tables: add nft_set_elem_update_expr() helper function
This helper function runs the eval path of the stateful expression of an existing set element. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4094445 commit 76adfaf

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,18 @@ static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)
890890
return (void *)&rule->data[rule->dlen];
891891
}
892892

893+
static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
894+
struct nft_regs *regs,
895+
const struct nft_pktinfo *pkt)
896+
{
897+
struct nft_expr *expr;
898+
899+
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPR)) {
900+
expr = nft_set_ext_expr(ext);
901+
expr->ops->eval(expr, regs, pkt);
902+
}
903+
}
904+
893905
/*
894906
* The last pointer isn't really necessary, but the compiler isn't able to
895907
* determine that the result of nft_expr_last() is always the same since it

net/netfilter/nft_dynset.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ void nft_dynset_eval(const struct nft_expr *expr,
8181
const struct nft_dynset *priv = nft_expr_priv(expr);
8282
struct nft_set *set = priv->set;
8383
const struct nft_set_ext *ext;
84-
const struct nft_expr *sexpr;
8584
u64 timeout;
8685

8786
if (priv->op == NFT_DYNSET_OP_DELETE) {
@@ -91,18 +90,13 @@ void nft_dynset_eval(const struct nft_expr *expr,
9190

9291
if (set->ops->update(set, &regs->data[priv->sreg_key], nft_dynset_new,
9392
expr, regs, &ext)) {
94-
sexpr = NULL;
95-
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPR))
96-
sexpr = nft_set_ext_expr(ext);
97-
9893
if (priv->op == NFT_DYNSET_OP_UPDATE &&
9994
nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION)) {
10095
timeout = priv->timeout ? : set->timeout;
10196
*nft_set_ext_expiration(ext) = get_jiffies_64() + timeout;
10297
}
10398

104-
if (sexpr != NULL)
105-
sexpr->ops->eval(sexpr, regs, pkt);
99+
nft_set_elem_update_expr(ext, regs, pkt);
106100

107101
if (priv->invert)
108102
regs->verdict.code = NFT_BREAK;

0 commit comments

Comments
 (0)