]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: evaluate: reset context maxlen value before prio evaluation
authorFlorian Westphal <fw@strlen.de>
Tue, 26 Jan 2021 15:42:33 +0000 (16:42 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 26 Jan 2021 15:44:09 +0000 (16:44 +0100)
unshare -n tests/shell/run-tests.sh tests/shell/testcases/nft-f/0024priority_0
W: [FAILED]     tests/shell/testcases/nft-f/0024priority_0: got 1
/dev/stdin:8:47-49: Error: Value 100 exceeds valid range 0-15
        type filter hook postrouting priority 100

Reported-by: Andreas Schultz <andreas.schultz@travelping.com
Signed-off-by: Florian Westphal <fw@strlen.de>
src/evaluate.c
tests/shell/testcases/nft-f/0024priority_0 [new file with mode: 0755]
tests/shell/testcases/nft-f/dumps/0024priority_0.nft [new file with mode: 0644]

index 7d6f55fe0872beac86924f427a5046e50677006c..3a91e9ea42edf8d3612eccc33b8f5da6e959f26b 100644 (file)
@@ -3789,8 +3789,8 @@ static bool evaluate_priority(struct eval_ctx *ctx, struct prio_spec *prio,
        int prio_snd;
        char op;
 
-       ctx->ectx.dtype = &priority_type;
-       ctx->ectx.len = NFT_NAME_MAXLEN * BITS_PER_BYTE;
+       expr_set_context(&ctx->ectx, &priority_type, NFT_NAME_MAXLEN * BITS_PER_BYTE);
+
        if (expr_evaluate(ctx, &prio->expr) < 0)
                return false;
        if (prio->expr->etype != EXPR_VALUE) {
diff --git a/tests/shell/testcases/nft-f/0024priority_0 b/tests/shell/testcases/nft-f/0024priority_0
new file mode 100755 (executable)
index 0000000..586f5c3
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+RULESET="
+table inet statelessnat {
+    chain prerouting {
+        type filter hook prerouting priority -100;
+        ip daddr set numgen inc mod 16 map { 0-7 : 10.0.1.1, 8- 15 : 10.0.1.2 }
+    }
+    chain postrouting {
+        type filter hook postrouting priority 100
+    }
+}"
+
+exec $NFT -f - <<< "$RULESET"
diff --git a/tests/shell/testcases/nft-f/dumps/0024priority_0.nft b/tests/shell/testcases/nft-f/dumps/0024priority_0.nft
new file mode 100644 (file)
index 0000000..cd7fc50
--- /dev/null
@@ -0,0 +1,10 @@
+table inet statelessnat {
+       chain prerouting {
+               type filter hook prerouting priority dstnat; policy accept;
+               ip daddr set numgen inc mod 16 map { 0-7 : 10.0.1.1, 8-15 : 10.0.1.2 }
+       }
+
+       chain postrouting {
+               type filter hook postrouting priority srcnat; policy accept;
+       }
+}