All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft 1/4] evaluate: add and use parse_ctx_init() helper method
Date: Fri, 25 Aug 2023 15:24:17 +0200	[thread overview]
Message-ID: <20230825132942.2733840-2-thaller@redhat.com> (raw)
In-Reply-To: <20230825132942.2733840-1-thaller@redhat.com>

Another field to parse_ctx will be added, that should be initialized.
As initializing the parse_ctx struct gets more involved, move the
duplicated code to a separate function.

Having a dedicated function, also  makes it easier to grep of all the
places where a parse context gets set up.

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 src/evaluate.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 1ae2ef0de10c..fdd2433b4780 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -40,6 +40,20 @@
 #include <utils.h>
 #include <xt.h>
 
+static struct parse_ctx *parse_ctx_init(struct parse_ctx *parse_ctx, const struct eval_ctx *ctx)
+{
+	struct parse_ctx tmp = {
+		.tbl	= &ctx->nft->output.tbl,
+		.input	= &ctx->nft->input,
+	};
+
+	/* "tmp" only exists, so we can search for "/struct parse_ctx .*=/" and find the location
+	 * where the parse context gets initialized. */
+
+	*parse_ctx = tmp;
+	return parse_ctx;
+}
+
 struct proto_ctx *eval_proto_ctx(struct eval_ctx *ctx)
 {
 	uint8_t idx = ctx->inner_desc ? 1 : 0;
@@ -278,15 +292,14 @@ static int flowtable_not_found(struct eval_ctx *ctx, const struct location *loc,
  */
 static int expr_evaluate_symbol(struct eval_ctx *ctx, struct expr **expr)
 {
-	struct parse_ctx parse_ctx = {
-		.tbl	= &ctx->nft->output.tbl,
-		.input	= &ctx->nft->input,
-	};
+	struct parse_ctx parse_ctx;
 	struct error_record *erec;
 	struct table *table;
 	struct set *set;
 	struct expr *new;
 
+	parse_ctx_init(&parse_ctx, ctx);
+
 	switch ((*expr)->symtype) {
 	case SYMBOL_VALUE:
 		datatype_set(*expr, ctx->ectx.dtype);
@@ -3454,13 +3467,12 @@ static int stmt_evaluate_reject_default(struct eval_ctx *ctx,
 
 static int stmt_evaluate_reject_icmp(struct eval_ctx *ctx, struct stmt *stmt)
 {
-	struct parse_ctx parse_ctx = {
-		.tbl	= &ctx->nft->output.tbl,
-		.input	= &ctx->nft->input,
-	};
+	struct parse_ctx parse_ctx;
 	struct error_record *erec;
 	struct expr *code;
 
+	parse_ctx_init(&parse_ctx, ctx);
+
 	erec = symbol_parse(&parse_ctx, stmt->reject.expr, &code);
 	if (erec != NULL) {
 		erec_queue(erec, ctx->msgs);
-- 
2.41.0


  reply	other threads:[~2023-08-25 13:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25 13:24 [PATCH nft 0/4] add operation cache for timestamp Thomas Haller
2023-08-25 13:24 ` Thomas Haller [this message]
2023-08-25 13:24 ` [PATCH nft 2/4] src: add ops_cache struct for caching information during parsing Thomas Haller
2023-08-28 15:00   ` Pablo Neira Ayuso
2023-08-25 13:24 ` [PATCH nft 3/4] src: cache result of time() during parsing/output Thomas Haller
2023-08-28 15:02   ` Pablo Neira Ayuso
2023-08-25 13:24 ` [PATCH nft 4/4] src: cache GMT offset for current time " Thomas Haller
2023-08-29 15:38 ` [PATCH nft 0/4] add operation cache for timestamp Pablo Neira Ayuso

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=20230825132942.2733840-2-thaller@redhat.com \
    --to=thaller@redhat.com \
    --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.