From: Gang Yan <yangang@kylinos.cn>
This patch introduce a minimal, non-fatal detection helper that subsequent
patches will use to guard the v6 paths:
- MPTCP_LIB_IPV6_AVAILABLE: cached flag, default 1 (optimistic).
- mptcp_lib_check_ipv6(): looks for "mptcpv6_init(\.|$)" in
/proc/kallsyms. That symbol is registered by subsys_initcall() in
net/mptcp/ctrl.c only when both CONFIG_IPV6=y and
CONFIG_MPTCP_IPV6=y, so it is a precise runtime proxy.
- mptcp_lib_is_v6_enabled(): cheap accessor wrapping the flag.
No existing caller is changed.
Assisted-by: GLM:5.1 Z.ai
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
.../testing/selftests/net/mptcp/mptcp_lib.sh | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 5ef6033775c8..67545cd70cc5 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -32,6 +32,7 @@ MPTCP_LIB_SUBTESTS_LAST_TS_NS=
MPTCP_LIB_TEST_COUNTER=0
MPTCP_LIB_TEST_FORMAT="%02u %-50s"
MPTCP_LIB_IP_MPTCP=0
+MPTCP_LIB_IPV6_AVAILABLE=1
# only if supported (or forced) and not disabled, see no-color.org
if { [ -t 1 ] || [ "${SELFTESTS_MPTCP_LIB_COLOR_FORCE:-}" = "1" ]; } &&
@@ -178,6 +179,23 @@ mptcp_lib_check_kallsyms() {
fi
}
+# Detect whether the MPTCP IPv6 subsystem is available in the running kernel.
+mptcp_lib_check_ipv6() {
+ if ! mptcp_lib_has_file "/proc/kallsyms"; then
+ MPTCP_LIB_IPV6_AVAILABLE=0
+ return 1
+ fi
+
+ if ! grep -qE " mptcpv6_init(\.|$)" /proc/kallsyms; then
+ MPTCP_LIB_IPV6_AVAILABLE=0
+ mptcp_lib_pr_skip "MPTCP IPv6 support is not available"
+ return 1
+ fi
+
+ MPTCP_LIB_IPV6_AVAILABLE=1
+ return 0
+}
+
# Internal: use mptcp_lib_kallsyms_has() instead
__mptcp_lib_kallsyms_has() {
local sym="${1}"
@@ -398,6 +416,11 @@ mptcp_lib_is_v6() {
[ -z "${1##*:*}" ]
}
+# Returns 0 (true) if the kernel has MPTCP IPv6 support, 1 (false) otherwise.
+mptcp_lib_is_v6_enabled() {
+ [ "${MPTCP_LIB_IPV6_AVAILABLE}" = "1" ]
+}
+
mptcp_lib_nstat_init() {
local ns="${1}"
--
2.43.0