Commit f265d311 authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: lib: use setup/cleanup_ns helpers

This patch includes lib.sh into mptcp_lib.sh, uses setup_ns helper
defined in lib.sh to set up namespaces in mptcp_lib_ns_init(), and
uses cleanup_ns to delete namespaces in mptcp_lib_ns_exit().
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240607-upstream-net-next-20240607-selftests-mptcp-net-lib-v1-5-e36986faac94@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f8a2d2f8
#! /bin/bash #! /bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
. "$(dirname "${0}")/../lib.sh"
readonly KSFT_PASS=0 readonly KSFT_PASS=0
readonly KSFT_FAIL=1 readonly KSFT_FAIL=1
readonly KSFT_SKIP=4 readonly KSFT_SKIP=4
...@@ -438,17 +440,13 @@ mptcp_lib_check_tools() { ...@@ -438,17 +440,13 @@ mptcp_lib_check_tools() {
} }
mptcp_lib_ns_init() { mptcp_lib_ns_init() {
local sec rndh if ! setup_ns ${@}; then
mptcp_lib_pr_fail "Failed to setup namespace ${@}"
sec=$(date +%s) exit ${KSFT_FAIL}
rndh=$(printf %x "${sec}")-$(mktemp -u XXXXXX) fi
local netns local netns
for netns in "${@}"; do for netns in "${@}"; do
eval "${netns}=${netns}-${rndh}"
ip netns add "${!netns}" || exit ${KSFT_SKIP}
ip -net "${!netns}" link set lo up
ip netns exec "${!netns}" sysctl -q net.mptcp.enabled=1 ip netns exec "${!netns}" sysctl -q net.mptcp.enabled=1
ip netns exec "${!netns}" sysctl -q net.ipv4.conf.all.rp_filter=0 ip netns exec "${!netns}" sysctl -q net.ipv4.conf.all.rp_filter=0
ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=0 ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=0
...@@ -456,9 +454,10 @@ mptcp_lib_ns_init() { ...@@ -456,9 +454,10 @@ mptcp_lib_ns_init() {
} }
mptcp_lib_ns_exit() { mptcp_lib_ns_exit() {
cleanup_ns "${@}"
local netns local netns
for netns in "${@}"; do for netns in "${@}"; do
ip netns del "${netns}"
rm -f /tmp/"${netns}".{nstat,out} rm -f /tmp/"${netns}".{nstat,out}
done done
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment