From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>, devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v3 3/5] selftests: netfilter: add the veth pair from inside the namespace
Date: Thu, 24 Sep 2026 13:06:08 +0200 [thread overview]
Message-ID: <20260924-b4-prep-netfilter-v3-3-e6a17b8f193f@virtuozzo.com> (raw)
In-Reply-To: <20260924-b4-prep-netfilter-v3-0-e6a17b8f193f@virtuozzo.com>
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Both tests add a veth by name while running in the initial namespace.
The name of the new device is taken there, not in the namespace passed to
netns, so a device of that name left behind by another test makes the add
fail and the test then runs with no connectivity at all:
# RTNETLINK answers: File exists
# Cannot find device "veth1"
# FAIL: socat cannot connect via NAT'd address
Add the pair from inside one of the namespaces instead. Those are made
by setup_ns and are empty, and the peer is created directly in its own
namespace, so no name from the initial namespace is in the way.
br_netfilter.sh checked only the first of its four adds, so a failure of
any of the others was silent and turned up much later as a ping to a
namespace that had no interface. Check all four.
https://virtuozzo.atlassian.net/browse/VSTOR-139651
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Reviewed-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
v3: one-line comments instead of a retelling of this message; drop
the line count from the text.
---
tools/testing/selftests/net/netfilter/br_netfilter.sh | 17 +++++++++--------
tools/testing/selftests/net/netfilter/nf_nat_edemux.sh | 9 +++++----
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/net/netfilter/br_netfilter.sh b/tools/testing/selftests/net/netfilter/br_netfilter.sh
index 011de87630940..8648f07871090 100755
--- a/tools/testing/selftests/net/netfilter/br_netfilter.sh
+++ b/tools/testing/selftests/net/netfilter/br_netfilter.sh
@@ -60,14 +60,15 @@ bcast_ping()
done
}
-if ! ip link add veth1 netns "$ns0" type veth peer name eth0 netns "$ns1"; then
- echo "SKIP: Can't create veth device"
- exit $ksft_skip
-fi
-
-ip link add veth2 netns "$ns0" type veth peer name eth0 netns "$ns2"
-ip link add veth3 netns "$ns0" type veth peer name eth0 netns "$ns3"
-ip link add veth4 netns "$ns0" type veth peer name eth0 netns "$ns4"
+# add from inside the netns so a stale vethN in init_net cannot get in the way
+for i in $(seq 1 4); do
+ nsvar="ns$i"
+ if ! ip -net "$ns0" link add "veth$i" type veth \
+ peer name eth0 netns "${!nsvar}"; then
+ echo "SKIP: Can't create veth device"
+ exit $ksft_skip
+ fi
+done
for i in $(seq 1 4); do
ip -net "$ns0" link set "veth$i" up
diff --git a/tools/testing/selftests/net/netfilter/nf_nat_edemux.sh b/tools/testing/selftests/net/netfilter/nf_nat_edemux.sh
index 1014551dd7694..0ddea0f79e55c 100755
--- a/tools/testing/selftests/net/netfilter/nf_nat_edemux.sh
+++ b/tools/testing/selftests/net/netfilter/nf_nat_edemux.sh
@@ -22,10 +22,11 @@ trap cleanup EXIT
setup_ns ns1 ns2
-# Connect the namespaces using a veth pair
-ip link add name veth2 type veth peer name veth1
-ip link set netns "$ns1" dev veth1
-ip link set netns "$ns2" dev veth2
+# add from inside the netns so a stale veth1 in init_net cannot get in the way
+if ! ip -net "$ns1" link add name veth1 type veth peer name veth2 netns "$ns2"; then
+ echo "SKIP: Can't create veth device"
+ exit $ksft_skip
+fi
ip netns exec "$ns1" ip link set up dev lo
ip netns exec "$ns1" ip link set up dev veth1
--
2.43.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-09-24 11:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 11:06 [Devel] [PATCH hci-8.1 v3 0/5] selftests: netfilter: make the suite pass on a routing host Konstantin Khorenko
2026-09-24 11:06 ` [Devel] [PATCH hci-8.1 v3 1/5] selftests: net: turn ip_forward off in setup_ns Konstantin Khorenko
2026-09-24 11:06 ` [Devel] [PATCH hci-8.1 v3 2/5] selftests: netfilter: let the router send redirects Konstantin Khorenko
2026-09-24 11:06 ` Konstantin Khorenko [this message]
2026-09-24 11:06 ` [Devel] [PATCH hci-8.1 v3 4/5] selftests: netfilter: skip rpath.sh without the nft tool Konstantin Khorenko
2026-09-24 11:06 ` [Devel] [PATCH hci-8.1 v3 5/5] selftests: netfilter: account for a per-namespace nf_conntrack_expect_max Konstantin Khorenko
2026-09-24 11:09 ` [Devel] [PATCH hci-8.1 v3 0/5] selftests: netfilter: make the suite pass on a routing host Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924-b4-prep-netfilter-v3-3-e6a17b8f193f@virtuozzo.com \
--to=khorenko@virtuozzo.com \
--cc=devel@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox