Skip to content

Commit

Permalink
selftests: mptcp: use setup_ns helper in lib.sh
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(). Then for
each namespace in NS_LIST, run all sysctl commands. This can drop some
duplicate code.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed May 23, 2024
1 parent e63a3b5 commit 5bf6df5
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 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 @@ -412,20 +414,13 @@ mptcp_lib_check_tools() {
}

mptcp_lib_ns_init() {
local sec rndh

sec=$(date +%s)
rndh=$(printf %x "${sec}")-$(mktemp -u XXXXXX)
setup_ns "${@}"

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
for netns in $NS_LIST; do
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
}

Expand Down

0 comments on commit 5bf6df5

Please sign in to comment.