Skip to contentSkip to conversation

tests: monitor: fix up test case breakage

PATCH In review Florian Westphal 3 participants 8 messages Oct 29, 2024 – Oct 31, 2024 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 tests: monitor: fix up test case breakage

Monitor test fails:

echo: running tests from file set-simple.t
echo output differs!

tmp/tmp.FGtiyL99bB/tmp.A5rp0Z0dBJ 2024-10-29 20:54:41.317293201 +0100 renamed from tmp/tmp.FGtiyL99bB/tmp.2QxLSjzQqk 2024-10-29 20:54:41.308293201 +0100 +2 -1
@@ -1,2 +1,3 @@
-add element ip t portrange { 1024-65535 }
 add element ip t portrange { 100-200 }
+add element ip t portrange { 1024-65535 }
+# new generation 510 by process 129009 (nft)

I also noticed -j mode did not work correctly, add missing json annotations in set-concat-interval.t while at it.

Fixes 20f1c60ac8c8 ("src: collapse set element commands from parser")
---
 tests/monitor/testcases/set-concat-interval.t | 3 +++
 tests/monitor/testcases/set-simple.t          | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)
tests/monitor/testcases/set-concat-interval.t +3 -0
index 763dc319f0d1..75f38280bf82 100644
@@ -10,3 +10,6 @@ I add map ip t s { typeof udp length . @ih,32,32 : verdict; flags interval; elem
 O add map ip t s { typeof udp length . @ih,32,32 : verdict; flags interval; }
 O add element ip t s { 20-80 . 0x14 : accept }
 O add element ip t s { 1-10 . 0xa : drop }
+J {"add": {"map": {"family": "ip", "name": "s", "table": "t", "type": ["integer", "integer"], "handle": 0, "map": "verdict", "flags": ["interval"]}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "s", "elem": {"set": [[{"concat": [{"range": [20, 80]}, 20]}, {"accept": null}]]}}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "s", "elem": {"set": [[{"concat": [{"range": [1, 10]}, 10]}, {"drop": null}]]}}}}
tests/monitor/testcases/set-simple.t +3 -2
index 8ca4f32463fd..6853a0ebbb0c 100644
@@ -37,9 +37,10 @@ J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem"
 # make sure half open before other element works
 I add element ip t portrange { 1024-65535 }
 I add element ip t portrange { 100-200 }
-O -
-J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}
+O add element ip t portrange { 100-200 }
+O add element ip t portrange { 1024-65535 }
 J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [100, 200]}]}}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}
 
 # make sure deletion of elements works
 I delete element ip t portrange { 0-10 }
Signature · 1 line
2.45.2
#1 lore raw
Quoted 12 lines · Florian Westphal

Monitor test fails:

echo: running tests from file set-simple.t
echo output differs!

tmp/tmp.FGtiyL99bB/tmp.A5rp0Z0dBJ 2024-10-29 20:54:41.317293201 +0100 renamed from tmp/tmp.FGtiyL99bB/tmp.2QxLSjzQqk 2024-10-29 20:54:41.308293201 +0100 +2 -1
@@ -1,2 +1,3 @@
-add element ip t portrange { 1024-65535 }
 add element ip t portrange { 100-200 }
+add element ip t portrange { 1024-65535 }
+# new generation 510 by process 129009 (nft)
Quoted 2 lines

I also noticed -j mode did not work correctly, add missing json annotations in set-concat-interval.t while at it.

Thanks for fixing up tests.

reviewer
#2 lore raw
In reply to Florian Westphal

On Tue, Oct 29, 2024 at 09:12:19PM +0100, Florian Westphal wrote:
[...]

Quoted 5 lines
tests/monitor/testcases/set-simple.t +0 -0
index 8ca4f32463fd..6853a0ebbb0c 100644

tests/monitor/testcases/set-simple.t J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem" · line 43

Quoted 9 lines
tests/monitor/testcases/set-simple.t +3 -2
@@ -37,9 +37,10 @@ J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem"
 # make sure half open before other element works
 I add element ip t portrange { 1024-65535 }
 I add element ip t portrange { 100-200 }
-O -
-J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}
+O add element ip t portrange { 100-200 }
+O add element ip t portrange { 1024-65535 }
 J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [100, 200]}]}}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}

This is odd: Why does monitor output reverse input? If nft reorders input, the test ("make sure half open before other element works") is probably moot anyway.

Cheers, Phil

author maintainer
#3 lore raw
Quoted 3 lines · Phil Sutter

This is odd: Why does monitor output reverse input? If nft reorders input, the test ("make sure half open before other element works") is probably moot anyway.

No idea. It happens since 20f1c60ac8c8

#4 lore raw
In reply to Phil Sutter
Quoted 12 lines · Phil Sutter

On Tue, Oct 29, 2024 at 09:12:19PM +0100, Florian Westphal wrote:
[...]

Quoted 10 lines
tests/monitor/testcases/set-simple.t +0 -2
index 8ca4f32463fd..6853a0ebbb0c 100644
@@ -37,9 +37,10 @@ J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem"
 # make sure half open before other element works
 I add element ip t portrange { 1024-65535 }
 I add element ip t portrange { 100-200 }
-O -
-J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}
Quoted 8 lines

tests/monitor/testcases/set-simple.t J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem" · line 43

Quoted 4 lines
tests/monitor/testcases/set-simple.t +3 -0
+O add element ip t portrange { 100-200 }
+O add element ip t portrange { 1024-65535 }
 J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [100, 200]}]}}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}

This is odd: Why does monitor output reverse input? If nft reorders input, the test ("make sure half open before other element works") is probably moot anyway.

Because elements are collapsed in one single command.

I add element ip t portrange { 1024-65535 }
I add element ip t portrange { 100-200 }

and there is qsort() to search for interval overlaps.

this becomes one single command with { 100-200, 1024-65535 }

I have a patch to remove the overlap check using qsort() from userspace which should remove this reordering, but it seems there is a overlap case that kernel does not handle yet.

#5 lore raw
Quoted 27 lines · Pablo Neira Ayuso
Quoted 12 lines · Phil Sutter

On Tue, Oct 29, 2024 at 09:12:19PM +0100, Florian Westphal wrote:
[...]

Quoted 10 lines
tests/monitor/testcases/set-simple.t +0 -2
index 8ca4f32463fd..6853a0ebbb0c 100644
@@ -37,9 +37,10 @@ J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem"
 # make sure half open before other element works
 I add element ip t portrange { 1024-65535 }
 I add element ip t portrange { 100-200 }
-O -
-J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}
Quoted 8 lines

tests/monitor/testcases/set-simple.t J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem" · line 43

Quoted 4 lines
tests/monitor/testcases/set-simple.t +3 -0
+O add element ip t portrange { 100-200 }
+O add element ip t portrange { 1024-65535 }
 J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [100, 200]}]}}}}
+J {"add": {"element": {"family": "ip", "table": "t", "name": "portrange", "elem": {"set": [{"range": [1024, 65535]}]}}}}

This is odd: Why does monitor output reverse input? If nft reorders input, the test ("make sure half open before other element works") is probably moot anyway.

Because elements are collapsed in one single command.

I add element ip t portrange { 1024-65535 }
I add element ip t portrange { 100-200 }

Quoted 7 lines

and there is qsort() to search for interval overlaps.

this becomes one single command with { 100-200, 1024-65535 }

I have a patch to remove the overlap check using qsort() from userspace which should remove this reordering, but it seems there is a overlap case that kernel does not handle yet.

I can also revert the patch if you don't like, but it is saving _a lot_ of memory from userspace for the silly one element per line case.

author maintainer
#6 lore raw
Quoted 2 lines · Pablo Neira Ayuso

I can also revert the patch if you don't like, but it is saving _a lot_ of memory from userspace for the silly one element per line case.

I think your patch is fine, the question is if we should ditch the test case instead of reordering the expected output.

reviewer
#7 lore raw
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Pablo Neira Ayuso

I can also revert the patch if you don't like, but it is saving _a lot_ of memory from userspace for the silly one element per line case.

I think your patch is fine, the question is if we should ditch the test case instead of reordering the expected output.

ACK, that was my thought. Looking at the test case and seeing how later tests depend on these elements being present, dropping it is not practical though. We could reorder the I lines to match output, but the commit is upstream already, so ... nevermind. :)

Thanks for the fix and clarification, guys!

Cheers, Phil