From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 3/4] src: convert set to list expression
Date: Wed, 9 Jul 2025 01:23:53 +0200 [thread overview]
Message-ID: <20250708232354.2189045-4-pablo@netfilter.org> (raw)
In-Reply-To: <20250708232354.2189045-1-pablo@netfilter.org>
The following definition:
define xyz = { "dummy0", "dummy1" }
is represented as a set expression to ease integration with sets.
However, this definition can be used in chains and flowtables to specify
the devices, for instance:
table netdev x {
chain y {
type filter hook ingress devices = $xyz priority 0; policy drop;
}
}
in this context, $xyz defines a _list_ of devices, not a set.
Transform the set to list expression from the evaluation step for chains
and flowtables.
This patch also handles:
define xyz = { "dummy0", $abc }
where $abc is also transformed to a list expression in the context of
chains and flowtables.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 66 +++++++++++++++++++++++++++++++++++++++++++-------
src/mnl.c | 1 -
2 files changed, 57 insertions(+), 10 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index f4f72ee4a4f7..fb6c4e06ae32 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -5393,9 +5393,54 @@ static bool evaluate_expr_variable(struct eval_ctx *ctx, struct expr **exprp)
return true;
}
-static bool evaluate_device_expr(struct eval_ctx *ctx, struct expr **dev_expr)
+static struct expr *expr_set_to_list(struct eval_ctx *ctx, struct expr *dev_expr)
{
struct expr *expr, *next, *key;
+ struct location loc;
+ LIST_HEAD(tmp);
+
+ list_for_each_entry_safe(expr, next, &dev_expr->expressions, list) {
+ list_del(&expr->list);
+
+ switch (expr->etype) {
+ case EXPR_VARIABLE:
+ expr_set_context(&ctx->ectx, &ifname_type,
+ IFNAMSIZ * BITS_PER_BYTE);
+ if (!evaluate_expr_variable(ctx, &expr))
+ return false;
+
+ if (expr->etype == EXPR_SET) {
+ expr = expr_set_to_list(ctx, expr);
+ list_splice_init(&expr->expressions, &tmp);
+ expr_free(expr);
+ continue;
+ }
+ break;
+ case EXPR_SET_ELEM:
+ key = expr_clone(expr->key);
+ expr_free(expr);
+ expr = key;
+ break;
+ case EXPR_VALUE:
+ break;
+ default:
+ break;
+ }
+
+ list_add(&expr->list, &tmp);
+ }
+
+ loc = dev_expr->location;
+ expr_free(dev_expr);
+ dev_expr = compound_expr_alloc(&loc, EXPR_LIST);
+ list_splice_init(&tmp, &dev_expr->expressions);
+
+ return dev_expr;
+}
+
+static bool evaluate_device_expr(struct eval_ctx *ctx, struct expr **dev_expr)
+{
+ struct expr *expr, *next;
LIST_HEAD(tmp);
if ((*dev_expr)->etype == EXPR_VARIABLE) {
@@ -5405,9 +5450,10 @@ static bool evaluate_device_expr(struct eval_ctx *ctx, struct expr **dev_expr)
return false;
}
- if ((*dev_expr)->etype != EXPR_SET &&
- (*dev_expr)->etype != EXPR_LIST)
- return true;
+ if ((*dev_expr)->etype == EXPR_SET)
+ *dev_expr = expr_set_to_list(ctx, *dev_expr);
+
+ assert((*dev_expr)->etype == EXPR_LIST);
list_for_each_entry_safe(expr, next, &(*dev_expr)->expressions, list) {
list_del(&expr->list);
@@ -5418,11 +5464,13 @@ static bool evaluate_device_expr(struct eval_ctx *ctx, struct expr **dev_expr)
IFNAMSIZ * BITS_PER_BYTE);
if (!evaluate_expr_variable(ctx, &expr))
return false;
- break;
- case EXPR_SET_ELEM:
- key = expr_clone(expr->key);
- expr_free(expr);
- expr = key;
+
+ if (expr->etype == EXPR_SET) {
+ expr = expr_set_to_list(ctx, expr);
+ list_splice_init(&expr->expressions, &tmp);
+ expr_free(expr);
+ continue;
+ }
break;
case EXPR_VALUE:
break;
diff --git a/src/mnl.c b/src/mnl.c
index 8a8dc4d6ef1c..cc20908fd636 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -757,7 +757,6 @@ static struct nft_dev *nft_dev_array(const struct expr *dev_expr, int *num_devs)
struct expr *expr;
switch (dev_expr->etype) {
- case EXPR_SET:
case EXPR_LIST:
list_for_each_entry(expr, &dev_expr->expressions, list)
len++;
--
2.30.2
next prev parent reply other threads:[~2025-07-08 23:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 23:23 [PATCH nft 0/4] detach concat, list and set expression layouts Pablo Neira Ayuso
2025-07-08 23:23 ` [PATCH nft 1/4] evaluate: mappings require set expression Pablo Neira Ayuso
2025-07-08 23:23 ` [PATCH nft 2/4] evaluate: validate set expression type before accessing flags Pablo Neira Ayuso
2025-07-08 23:23 ` Pablo Neira Ayuso [this message]
2025-07-08 23:23 ` [PATCH nft 4/4] src: detach set, list and concatenation expression layout Pablo Neira Ayuso
2025-07-09 13:58 ` [PATCH nft 0/4] detach concat, list and set expression layouts Florian Westphal
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=20250708232354.2189045-4-pablo@netfilter.org \
--to=pablo@netfilter.org \
--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.