Skip to contentSkip to conversation

Review port shadow selftest

PATCH In review Phil Sutter 2 participants 4 messages Nov 3, 2021 – Nov 8, 2021

Subsystems (2)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover Review port shadow selftest

Trying the test on a local VM I noticed spurious errors from nc, complaining about an address being already in use. Patch 1 fixes this. Validating the notrack workaround led to the minor simplifications in patch 2.

Phil Sutter (2):
selftests: nft_nat: Improve port shadow test stability
selftests: nft_nat: Simplify port shadow notrack test

 tools/testing/selftests/netfilter/nft_nat.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.33.0
author reviewer
#1 lore raw

PATCH 1/2 selftests: nft_nat: Improve port shadow test stability

Setup phase in test_port_shadow() relied upon a race-condition:
Listening nc on port 1405 was started in background before attempting to create the fake conntrack entry using the same source port. If listening nc won, fake conntrack entry could not be created causing wrong behaviour. Reorder nc calls to fix this and introduce a short delay before testing the setup to wait for listening nc process startup.

Fixes 465f15a6d1a8f ("selftests: nft_nat: add udp hole punch test case")
---
 tools/testing/selftests/netfilter/nft_nat.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/netfilter/nft_nat.sh +4 -2
index da1c1e4b6c86b..905c033db74dc 100755
@@ -759,14 +759,16 @@ test_port_shadow()
 	local result=""
 	local logmsg=""
 
+	# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.
+	echo "fake-entry" | ip netns exec "$ns2" nc -w 1 -p 1405 -u "$daddrc" 41404 > /dev/null
+
 	echo ROUTER | ip netns exec "$ns0" nc -w 5 -u -l -p 1405 >/dev/null 2>&1 &
 	nc_r=$!
 
 	echo CLIENT | ip netns exec "$ns2" nc -w 5 -u -l -p 1405 >/dev/null 2>&1 &
 	nc_c=$!
 
-	# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.
-	echo "fake-entry" | ip netns exec "$ns2" nc -w 1 -p 1405 -u "$daddrc" 41404 > /dev/null
+	sleep 0.3
 
 	# ns1 tries to connect to ns0:1405.  With default settings this should connect
 	# to client, it matches the conntrack entry created above.
Signature · 1 line
2.33.0
author reviewer
#2 lore raw

PATCH 2/2 selftests: nft_nat: Simplify port shadow notrack test

In reply to Phil Sutter

The second rule in prerouting chain was probably a leftover: The router listens on veth0, so not tracking connections via that interface is sufficient. Likewise, the rule in output chain can be limited to that interface as well.

---
 tools/testing/selftests/netfilter/nft_nat.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/netfilter/nft_nat.sh +1 -2
index 905c033db74dc..c62e4e26252c1 100755
@@ -818,11 +818,10 @@ table $family raw {
 	chain prerouting {
 		type filter hook prerouting priority -300; policy accept;
 		meta iif veth0 udp dport 1405 notrack
-		udp dport 1405 notrack
 	}
 	chain output {
 		type filter hook output priority -300; policy accept;
-		udp sport 1405 notrack
+		meta oif veth0 udp sport 1405 notrack
 	}
 }
 EOF
Signature · 1 line
2.33.0
#3 lore raw
In reply to Phil Sutter
Quoted 4 lines · Phil Sutter

Trying the test on a local VM I noticed spurious errors from nc, complaining about an address being already in use. Patch 1 fixes this. Validating the notrack workaround led to the minor simplifications in patch 2.

Series applied, thanks.