From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] optimize: skip variables in nat statements
Date: Thu, 18 Jul 2024 18:17:03 +0200 [thread overview]
Message-ID: <20240718161703.27613-1-pablo@netfilter.org> (raw)
Do not hit assert():
nft: optimize.c:486: rule_build_stmt_matrix_stmts: Assertion `k >= 0' failed.
variables are not supported by -o/--optimize at this stage.
Fixes: 9be404a153bc ("optimize: ignore existing nat mapping")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/optimize.c | 6 ++-
tests/shell/testcases/optimizations/variables | 52 ++++++++++++++++---
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/src/optimize.c b/src/optimize.c
index 62dd9082a587..9f0965cd5fe9 100644
--- a/src/optimize.c
+++ b/src/optimize.c
@@ -408,9 +408,11 @@ static int rule_collect_stmts(struct optimize_ctx *ctx, struct rule *rule)
break;
case STMT_NAT:
if ((stmt->nat.addr &&
- stmt->nat.addr->etype == EXPR_MAP) ||
+ (stmt->nat.addr->etype == EXPR_MAP ||
+ stmt->nat.addr->etype == EXPR_VARIABLE)) ||
(stmt->nat.proto &&
- stmt->nat.proto->etype == EXPR_MAP)) {
+ (stmt->nat.proto->etype == EXPR_MAP ||
+ stmt->nat.proto->etype == EXPR_VARIABLE))) {
clone->ops = &unsupported_stmt_ops;
break;
}
diff --git a/tests/shell/testcases/optimizations/variables b/tests/shell/testcases/optimizations/variables
index fa986065006b..4cb322dbc73c 100755
--- a/tests/shell/testcases/optimizations/variables
+++ b/tests/shell/testcases/optimizations/variables
@@ -2,14 +2,52 @@
set -e
-RULESET="define addrv4_vpnnet = 10.1.0.0/16
+RULESET='define addrv4_vpnnet = 10.1.0.0/16
+define wan = "eth0"
+define lan = "eth1"
+define vpn = "tun0"
+define server = "10.10.10.1"
-table ip nat {
- chain postrouting {
- type nat hook postrouting priority 0; policy accept;
+table inet filter {
+ chain input {
+ type filter hook input priority 0; policy drop;
+ }
+ chain forward {
+ type filter hook forward priority 1; policy drop;
- ip saddr \$addrv4_vpnnet counter masquerade fully-random comment \"masquerade ipv4\"
- }
-}"
+ iifname $lan oifname $lan accept;
+
+ iifname $lan oifname $wan ct state new accept
+ iifname $lan oifname $wan ct state {established, related} accept
+
+ iifname $wan oifname $lan ct state {established, related} accept
+
+ iifname $vpn oifname $wan accept
+ iifname $wan oifname $vpn accept
+ iifname $lan oifname $vpn accept
+ iifname $vpn oifname $lan accept
+
+ iifname $lan oifname $server accept
+ iifname $server oifname $lan accept
+ iifname $server oifname $wan accept
+ iifname $wan oifname $server accept
+ }
+ chain output {
+ type filter hook output priority 0; policy drop;
+ }
+}
+
+table nat {
+ chain prerouting {
+ type nat hook prerouting priority -100; policy accept;
+ iifname $wan tcp dport 10000 dnat to $server:10000;
+ }
+ chain postrouting {
+ type nat hook postrouting priority 100; policy accept;
+ ip saddr $addrv4_vpnnet counter masquerade fully-random comment "masquerade ipv4"
+ oifname $vpn masquerade
+ oifname $wan masquerade
+ }
+}'
$NFT -c -o -f - <<< $RULESET
--
2.30.2
reply other threads:[~2024-07-18 16:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240718161703.27613-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox