From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft 1/2] evaluate: compact STMT_F_STATEFUL checks
Date: Mon, 31 Mar 2025 20:02:02 +0200 [thread overview]
Message-ID: <Z-rYmg3U7CgQu3_f@calendula> (raw)
In-Reply-To: <20250331152323.31093-1-fw@strlen.de>
On Mon, Mar 31, 2025 at 05:23:19PM +0200, Florian Westphal wrote:
> We'll gain another F_STATEFUL check in a followup patch,
> so lets condense the pattern into a helper to reduce copypaste.
This series LGTM, thanks Florian.
> Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> src/evaluate.c | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/src/evaluate.c b/src/evaluate.c
> index e4a7b5ceaafa..e9ab829b6bbb 100644
> --- a/src/evaluate.c
> +++ b/src/evaluate.c
> @@ -3453,6 +3453,17 @@ static int stmt_evaluate_payload(struct eval_ctx *ctx, struct stmt *stmt)
> return expr_evaluate(ctx, &stmt->payload.val);
> }
>
> +static int stmt_evaluate_stateful(struct eval_ctx *ctx, struct stmt *stmt, const char *name)
> +{
> + if (stmt_evaluate(ctx, stmt) < 0)
> + return -1;
> +
> + if (!(stmt->flags & STMT_F_STATEFUL))
> + return stmt_error(ctx, stmt, "%s statement must be stateful", name);
> +
> + return 0;
> +}
> +
> static int stmt_evaluate_meter(struct eval_ctx *ctx, struct stmt *stmt)
> {
> struct expr *key, *setref;
> @@ -3526,11 +3537,8 @@ static int stmt_evaluate_meter(struct eval_ctx *ctx, struct stmt *stmt)
>
> stmt->meter.set = setref;
>
> - if (stmt_evaluate(ctx, stmt->meter.stmt) < 0)
> + if (stmt_evaluate_stateful(ctx, stmt->meter.stmt, "meter") < 0)
> return -1;
> - if (!(stmt->meter.stmt->flags & STMT_F_STATEFUL))
> - return stmt_binary_error(ctx, stmt->meter.stmt, stmt,
> - "meter statement must be stateful");
>
> return 0;
> }
> @@ -4662,11 +4670,8 @@ static int stmt_evaluate_set(struct eval_ctx *ctx, struct stmt *stmt)
> return expr_error(ctx->msgs, stmt->set.key,
> "Key expression comments are not supported");
> list_for_each_entry(this, &stmt->set.stmt_list, list) {
> - if (stmt_evaluate(ctx, this) < 0)
> + if (stmt_evaluate_stateful(ctx, this, "set") < 0)
> return -1;
> - if (!(this->flags & STMT_F_STATEFUL))
> - return stmt_error(ctx, this,
> - "statement must be stateful");
> }
>
> this_set = stmt->set.set->set;
> @@ -4726,11 +4731,8 @@ static int stmt_evaluate_map(struct eval_ctx *ctx, struct stmt *stmt)
> "Data expression timeouts are not supported");
>
> list_for_each_entry(this, &stmt->map.stmt_list, list) {
> - if (stmt_evaluate(ctx, this) < 0)
> + if (stmt_evaluate_stateful(ctx, this, "map") < 0)
> return -1;
> - if (!(this->flags & STMT_F_STATEFUL))
> - return stmt_error(ctx, this,
> - "statement must be stateful");
> }
>
> return 0;
> --
> 2.49.0
>
>
prev parent reply other threads:[~2025-03-31 18:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 15:23 [PATCH nft 1/2] evaluate: compact STMT_F_STATEFUL checks Florian Westphal
2025-03-31 15:23 ` [PATCH nft 2/2] evaluate: only allow stateful statements in set and map definitions Florian Westphal
2025-03-31 16:15 ` Florian Westphal
2025-03-31 16:31 ` Pablo Neira Ayuso
2025-03-31 18:02 ` Pablo Neira Ayuso [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z-rYmg3U7CgQu3_f@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.