Skip to content

Commit

Permalink
selftests: mptcp: lib: use setup/cleanup_ns helpers
Browse files Browse the repository at this point in the history
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: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240607-upstream-net-next-20240607-selftests-mptcp-net-lib-v1-5-e36986faac94@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Geliang Tang authored and Jakub Kicinski committed Jun 12, 2024
1 parent f8a2d2f commit f265d31
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/../lib.sh"

readonly KSFT_PASS=0
readonly KSFT_FAIL=1
readonly KSFT_SKIP=4
Expand Down Expand Up @@ -438,27 +440,24 @@ mptcp_lib_check_tools() {
}

mptcp_lib_ns_init() {
local sec rndh

sec=$(date +%s)
rndh=$(printf %x "${sec}")-$(mktemp -u XXXXXX)
if ! setup_ns ${@}; then
mptcp_lib_pr_fail "Failed to setup namespace ${@}"
exit ${KSFT_FAIL}
fi

local netns
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.ipv4.conf.all.rp_filter=0
ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=0
done
}

mptcp_lib_ns_exit() {
cleanup_ns "${@}"

local netns
for netns in "${@}"; do
ip netns del "${netns}"
rm -f /tmp/"${netns}".{nstat,out}
done
}
Expand Down

0 comments on commit f265d31

Please sign in to comment.