Review port shadow selftest
Phil Sutter
reviewercover 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
Phil Sutter
reviewerPATCH 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.
--- tools/testing/selftests/netfilter/nft_nat.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/netfilter/nft_nat.sh +4 -2
@@ -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
Phil Sutter
reviewerPATCH 2/2 selftests: nft_nat: Simplify port shadow notrack test
In reply to Phil SutterThe 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
@@ -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
Pablo Neira Ayuso
maintainerQuoted 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.