From: Gang Yan <yangang@kylinos.cn>
Make the IPv6 path optional at runtime:
- Right after the existing mptcp_lib_check_* calls, query the new
mptcp_lib_check_ipv6() helper. If the kernel does not support
MPTCP/IPv6 and the user did not already pass -4 on the command line,
transparently flip the internal ${ipv6} flag to false and print one
informational line so the user knows v4-only mode kicked in.
- Guard every "ip -6 addr add", "ip -6 route add" and the v6
forwarding sysctl with "if $ipv6; then ... fi".
The -4 command-line option (handled earlier in the same script) keeps
priority: when the user explicitly asks for v4-only mode the new check
is a no-op. In a fully featured kernel ${ipv6} stays true and the
script behaves exactly as before.
Assisted-by: GLM:5.1 Z.ai
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
.../selftests/net/mptcp/mptcp_connect.sh | 42 +++++++++++++------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
index 7a2a851fa0ad..0e5690d6f68c 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh
@@ -149,6 +149,14 @@ mptcp_lib_check_mptcp
mptcp_lib_check_kallsyms
mptcp_lib_check_tools ip tc
+# If MPTCP IPv6 is not available in the running kernel, transparently
+# downgrade to v4-only mode (unless the user already passed -4).
+# This keeps v4 tests running in IPV6=m / MPTCP_IPV6=n kernels.
+if ! mptcp_lib_check_ipv6 && ${ipv6}; then
+ ipv6=false
+ mptcp_lib_pr_info "MPTCP IPv6 not available, running IPv4-only tests"
+fi
+
sin=$(mktemp)
sout=$(mktemp)
cin=$(mktemp)
@@ -169,41 +177,51 @@ ip link add ns2eth3 netns "$ns2" type veth peer name ns3eth2 netns "$ns3"
ip link add ns3eth4 netns "$ns3" type veth peer name ns4eth3 netns "$ns4"
ip -net "$ns1" addr add 10.0.1.1/24 dev ns1eth2
-ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
ip -net "$ns1" link set ns1eth2 up
ip -net "$ns1" route add default via 10.0.1.2
-ip -net "$ns1" route add default via dead:beef:1::2
ip -net "$ns2" addr add 10.0.1.2/24 dev ns2eth1
-ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
ip -net "$ns2" link set ns2eth1 up
ip -net "$ns2" addr add 10.0.2.1/24 dev ns2eth3
-ip -net "$ns2" addr add dead:beef:2::1/64 dev ns2eth3 nodad
ip -net "$ns2" link set ns2eth3 up
ip -net "$ns2" route add default via 10.0.2.2
-ip -net "$ns2" route add default via dead:beef:2::2
ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1
-ip netns exec "$ns2" sysctl -q net.ipv6.conf.all.forwarding=1
ip -net "$ns3" addr add 10.0.2.2/24 dev ns3eth2
-ip -net "$ns3" addr add dead:beef:2::2/64 dev ns3eth2 nodad
ip -net "$ns3" link set ns3eth2 up
ip -net "$ns3" addr add 10.0.3.2/24 dev ns3eth4
-ip -net "$ns3" addr add dead:beef:3::2/64 dev ns3eth4 nodad
ip -net "$ns3" link set ns3eth4 up
ip -net "$ns3" route add default via 10.0.2.1
-ip -net "$ns3" route add default via dead:beef:2::1
ip netns exec "$ns3" sysctl -q net.ipv4.ip_forward=1
-ip netns exec "$ns3" sysctl -q net.ipv6.conf.all.forwarding=1
ip -net "$ns4" addr add 10.0.3.1/24 dev ns4eth3
-ip -net "$ns4" addr add dead:beef:3::1/64 dev ns4eth3 nodad
ip -net "$ns4" link set ns4eth3 up
ip -net "$ns4" route add default via 10.0.3.2
-ip -net "$ns4" route add default via dead:beef:3::2
+
+# IPv6 topology: only configured if MPTCP IPv6 is supported by the
+# running kernel (CONFIG_MPTCP_IPV6=y). On a kernel without it, "ip -6
+# addr add" and the v6 forwarding sysctl would fail and abort the
+# script, taking the v4 tests down with them.
+if $ipv6; then
+ ip -net "$ns1" addr add dead:beef:1::1/64 dev ns1eth2 nodad
+ ip -net "$ns1" route add default via dead:beef:1::2
+
+ ip -net "$ns2" addr add dead:beef:1::2/64 dev ns2eth1 nodad
+ ip -net "$ns2" addr add dead:beef:2::1/64 dev ns2eth3 nodad
+ ip -net "$ns2" route add default via dead:beef:2::2
+ ip netns exec "$ns2" sysctl -q net.ipv6.conf.all.forwarding=1
+
+ ip -net "$ns3" addr add dead:beef:2::2/64 dev ns3eth2 nodad
+ ip -net "$ns3" addr add dead:beef:3::2/64 dev ns3eth4 nodad
+ ip -net "$ns3" route add default via dead:beef:2::1
+ ip netns exec "$ns3" sysctl -q net.ipv6.conf.all.forwarding=1
+
+ ip -net "$ns4" addr add dead:beef:3::1/64 dev ns4eth3 nodad
+ ip -net "$ns4" route add default via dead:beef:3::2
+fi
if $checksum; then
for i in "$ns1" "$ns2" "$ns3" "$ns4";do
--
2.43.0