[PATCH v2] selftests: netfilter: fix nft_nat_zones.sh diagnostics

From: Zhiqi Zhang

Date: Wed Nov 25 2026 - 03:44:30 EST


nft_nat_zones.sh starts all client pings in the background and then
uses a bare wait to collect them. In bash, wait with no arguments
returns zero after all known children have been waited for, so a ping
failure does not set ret. The diagnostic after that wait is also outside
the client loop, so it would name only the final client even if it ran.

Store each ping PID and wait for it next to the matching client
namespace. This makes failed pings set ret and reports the client that
actually failed.

The veth0 ICMP counter mismatch path checks the 10.3.0.99 key but dumps
10.3.99 for debugging. Dump the same key that was checked.

OpenAI Codex helped analyze the Sashiko review and draft this respin. I
reviewed the changes.

Signed-off-by: Zhiqi Zhang <zhiqizhangg@xxxxxxxxx>
---
Changes in v2:
- Track each ping PID and wait per client instead of adding echo after a
bare wait.
- Report the client whose ping failed instead of reusing the final loop
value.
- Fix the veth0 ICMP debug dump key from 10.3.99 to 10.3.0.99.

.../selftests/net/netfilter/nft_nat_zones.sh | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
index d935c967dd..9397f09d0c 100755
--- a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
+++ b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
@@ -167,11 +167,16 @@ ip netns exec "$gw" sysctl -q net.ipv6.fwmark_reflect=1 > /dev/null
for i in $(seq 1 "$maxclients"); do
cl=$(eval echo \$cl"$i")
ip netns exec "$cl" ping -i 0.5 -q -c 3 10.3.0.99 > /dev/null 2>&1 &
+ ping_pids[$i]=$!
done

-wait || ret=1
-
-[ "$ret" -ne 0 ] && "FAIL: Ping failure from $cl" 1>&2
+for i in $(seq 1 "$maxclients"); do
+ cl=$(eval echo \$cl"$i")
+ if ! wait "${ping_pids[$i]}"; then
+ ret=1
+ echo "FAIL: Ping failure from $cl" 1>&2
+ fi
+done

for i in $(seq 1 "$maxclients"); do
if ! ip netns exec "$gw" nft get element inet raw inicmp "{ 10.1.0.3 . \"veth$i\" . 10.3.0.99 }" | grep -q "{ 10.1.0.3 . \"veth$i\" . 10.3.0.99 counter packets 3 bytes 252 }"; then
@@ -185,7 +190,7 @@ done
if ! ip netns exec "$gw" nft get element inet raw inicmp "{ 10.3.0.99 . \"veth0\" . 10.3.0.1 }" | grep -q "{ 10.3.0.99 . \"veth0\" . 10.3.0.1 counter packets $((3 * maxclients)) bytes $((252 * maxclients)) }"; then
ret=1
echo "FAIL: counter icmp mismatch for veth0: { 10.3.0.99 . \"veth0\" . 10.3.0.1 counter packets $((3 * maxclients)) bytes $((252 * maxclients)) }"
- ip netns exec "$gw" nft get element inet raw inicmp "{ 10.3.99 . \"veth0\" . 10.3.0.1 }" 1>&2
+ ip netns exec "$gw" nft get element inet raw inicmp "{ 10.3.0.99 . \"veth0\" . 10.3.0.1 }" 1>&2
fi

if [ $ret -eq 0 ]; then
--
2.54.0 (Apple Git-157)