🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Zhiqi Zhang Tue, 24 Nov 2026 07:19
[PATCH] selftests: netfilter: fix missing echo in nft_nat_zones.sh
#21570
Author: Zhiqi Zhang
Date: Tue, 24 Nov 2026 07:19
34 lines
12335 bytes
The ping failure path tries to execute the failure message as a command
because the echo command is missing. This reports a confusing "command not
found" error and returns 127 from that command instead of printing the
intended diagnostic.

Add the missing echo so the ping failure is reported consistently with the
other failure paths in the script.

I found this bug manually. OpenAI Codex generated the one-line code
change. I wrote the reproducer/test case, reviewed the generated change,
and tested the patch.

Fixes: d6905f088d2b ("selftests: netfilter: nft_nat_zones.sh: shellcheck cleanups")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
 tools/testing/selftests/net/netfilter/nft_nat_zones.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
index d935c967dd..f15bfd3373 100755
--- a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
+++ b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
@@ -171,7 +171,7 @@ done
 
 wait || ret=1
 
-[ "$ret" -ne 0 ] && "FAIL: Ping failure from $cl" 1>&2
+[ "$ret" -ne 0 ] && echo "FAIL: Ping failure from $cl" 1>&2
 
 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
-- 
2.54.0 (Apple Git-157)
Re: [PATCH] selftests: netfilter: fix missing echo in nft_nat_zones.sh
#21740
Author: Florian Westphal
Date: Tue, 24 Nov 2026 09:21
36 lines
8519 bytes
@netdev maintainers:

feel free to take this one directly.

Zhiqi Zhang <zhiqizhangg@gmail.com> wrote:
> The ping failure path tries to execute the failure message as a command
> because the echo command is missing. This reports a confusing "command not
> found" error and returns 127 from that command instead of printing the
> intended diagnostic.
> 
> Add the missing echo so the ping failure is reported consistently with the
> other failure paths in the script.
> 
> I found this bug manually. OpenAI Codex generated the one-line code
> change. I wrote the reproducer/test case, reviewed the generated change,
> and tested the patch.
> 
> Fixes: d6905f088d2b ("selftests: netfilter: nft_nat_zones.sh: shellcheck cleanups")
> Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
> ---
>  tools/testing/selftests/net/netfilter/nft_nat_zones.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> index d935c967dd..f15bfd3373 100755
> --- a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> +++ b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> @@ -171,7 +171,7 @@ done
>  
>  wait || ret=1
>  
> -[ "$ret" -ne 0 ] && "FAIL: Ping failure from $cl" 1>&2
> +[ "$ret" -ne 0 ] && echo "FAIL: Ping failure from $cl" 1>&2

Acked-by: Florian Westphal <fw@strlen.de>
Re: [PATCH] selftests: netfilter: fix missing echo in nft_nat_zones.sh
#22359
Author: netdev-bot+sashiko
Date: Wed, 25 Nov 2026 07:44
114 lines
12447 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0 (1)

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch fixes a statement that can never run, so it does not
  do what the commit message says.
- [Medium] The diagnostic this patch turns into a real message, `echo
  "FAIL: Ping failure from $cl"` on line 174 of…

Pre-existing issues:
- [Low] On the veth0 icmp counter-mismatch path in
  tools/testing/selftests/net/netfilter/nft_nat_zones.sh, the check on…

--

selftests: netfilter: fix missing echo in nft_nat_zones.sh

The patch adds a missing echo to the ping failure diagnostic in
nft_nat_zones.sh. Without it, the shell tries to run the message string
as a command. The commit message says this makes ping failures get
reported the same way as the script's other failure paths.

> diff --git a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> index d935c967dd13b..f15bfd33739f1 100755
> --- a/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> +++ b/tools/testing/selftests/net/netfilter/nft_nat_zones.sh
> @@ -171,7 +171,7 @@ done
>  
>  wait || ret=1
>  
> -[ "$ret" -ne 0 ] && "FAIL: Ping failure from $cl" 1>&2
> +[ "$ret" -ne 0 ] && echo "FAIL: Ping failure from $cl" 1>&2

[Severity: High]

Can this echo ever run? The script is #!/bin/bash, and the loop above
starts the pings in the background without saving their PIDs:

  ip netns exec "$cl" ping -i 0.5 -q -c 3 10.3.0.99 > /dev/null 2>&1 &

In bash, a bare wait with no arguments returns zero once all background
jobs finish, whatever their exit status. The only trap in the script is
on EXIT, so no trapped signal can make wait fail either. That means
"wait || ret=1" never sets ret.

ret is set to 0 near the top of nft_nat_zones.sh, and nothing else
assigns it before this check. All the other ret=1 assignments come
later. So [ "$ret" -ne 0 ] looks to be always false, both before and
after this patch.

If that's right, the "command not found" and 127 symptom described in
the commit message can't happen on an unmodified run. A failed client
ping would also still go unreported here.

Would it make more sense to replace "wait || ret=1" with a per-PID wait?
For example, save pids[$i]=$! in the ping loop, then call
wait "${pids[$i]}" for each client and set ret and print the failure on
error. nft_flowtable.sh in the same directory uses wait $lpid this way.

Also, before d6905f088d2b the loop checked $? right after "ping ... &".
That is also always 0, so it looks like ping failure detection never
worked at this point. Backporting with the current Fixes: tag would not
bring back any ping failure detection.

[Severity: Medium]

Which client will this message name? cl is the loop variable from the
background ping loop:

  for i in $(seq 1 "$maxclients"); do
    cl=$(eval echo \$cl"$i")
    ip netns exec "$cl" ping ... &
  done

After the loop, cl always holds the namespace for i == maxclients (100,
or 40 with KSFT_MACHINE_SLOW=yes). A failure from client 5, for example,
would be reported as coming from the last client.

The socat failure path later in the script prints $cl inside its loop,
so it names the correct client:

  echo "FAIL: Failure to connect for $cl" 1>&2

The wrong name came in with d6905f088d2b, when the message moved out of
the loop. Since this patch presents the line as the fix for ping failure
reporting, could the respin also report from inside a per-client wait
loop?

[ ... ]

[Severity: Low]

This is a pre-existing issue, and this patch did not introduce it. It is
in the same script, outside the quoted hunk. On the veth0 icmp counter
mismatch path, the check looks up one key and the debug dump looks up a
different one:

  if ! ip netns exec "$gw" nft get element inet raw inicmp "{ 10.3.0.99 . \"veth0\" . 10.3.0.1 }" | grep -q ...
      ...
      ip netns exec "$gw" nft get element inet raw inicmp "{ 10.3.99 . \"veth0\" . 10.3.0.1 }" 1>&2

Should 10.3.99 in the debug dump be 10.3.0.99, to match the key that was
checked?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124071926.8818-1-zhiqizhangg%40gmail.com
[PATCH v2] selftests: netfilter: fix nft_nat_zones.sh diagnostics
#22388
Author: Zhiqi Zhang
Date: Wed, 25 Nov 2026 08:44
64 lines
13884 bytes
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@gmail.com>
---
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)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads