From nobody Tue May 14 22:40:21 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0443C28EF for ; Thu, 22 Feb 2024 03:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573263; cv=none; b=WN+4q4ce4spg85mk/NaNl0LI+KB9GHneE1qsr1Ht1SfeAgqurux+yxKZP7YCxjV8ZhR51Oie+cFE/iy+6QDpmWjk8AKHvSUeYz434dRtrIcuHjZIE6MnxN09X3SnR3Uo2d/EIQUv0xiyRgBEaEhXjLpVqqxhbzDWVoRyXTskBF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573263; c=relaxed/simple; bh=2Ziz4GxdXaBA8SvNT8LKVv/bOei7SGEgH2pOCTqXEJU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ME/SG7XFWFLZwfqWOXAXJ+N6Vot20cEvU2VNzTo72Ce1hrsJ5X0/gAa+rFetelXzjMITyVr4YzNkJPY+hYRb4PbjheawdZuogSwKhh2/T5checon27fTg8MXAK73UZEfIDWX6t1yUsckZeWTq7i9eoieZCOh/LxGjvPNBlOEhmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ayf4kmd3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ayf4kmd3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B41F7C43390; Thu, 22 Feb 2024 03:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708573262; bh=2Ziz4GxdXaBA8SvNT8LKVv/bOei7SGEgH2pOCTqXEJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ayf4kmd37AZcdKeY9ePGZBLiFdl8QF/NaySmonRZCdiN4yxH23ejaepTWc/vuQ9Zn iS9rElseE+KiXp7rzp+RfYhcveO8k7nxOjO7/FGGGjVupuAGdNgjtGXNxABDX4gEg5 3FdM9Wftajj2A2au7tbKL1UvC725hibmtBGju/+hrmb7IIwmje5hKvGS3BqUuIZAzR CdTouuy00qdTP5v9hAxgHojyzad9DhO8u/YonIpHtVAwpgiupK3g0Kd3QbzV1X34w4 Bkr+uhYwG8Z4QMDwNzvJxo1Sn61Ie8C6aZPDKo96CYb0IQJlCUaPKPhiROtKvs2+V3 J54ix0yigo+kg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 1/4] selftests: mptcp: add local variables rndh Date: Thu, 22 Feb 2024 11:40:33 +0800 Message-Id: <7745872ec10f1db522ce3b48ee989a1367b94469.1708572320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds local variables rndh in do_transfer() functions both in mptcp_connect.sh and simult_flows.sh, setting it with ${ns1:4}, not the global variable rndh. The global one is hidden in the next commit. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 1 + tools/testing/selftests/net/mptcp/simult_flows.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_connect.sh index ea52110c3fbc..b609649311f6 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -348,6 +348,7 @@ do_transfer() =20 if $capture; then local capuser + local rndh=3D"${connector_ns:4}" if [ -z $SUDO_USER ] ; then capuser=3D"" else diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/test= ing/selftests/net/mptcp/simult_flows.sh index 7d8388ecc966..8a4520f29601 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -139,6 +139,7 @@ do_transfer() =20 if $capture; then local capuser + local rndh=3D"${ns1:4}" if [ -z $SUDO_USER ] ; then capuser=3D"" else --=20 2.40.1 From nobody Tue May 14 22:40:21 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53EA928EF for ; Thu, 22 Feb 2024 03:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573264; cv=none; b=cG9LBesQMN0oD28NdLh5z0kndIsjH9b124J1SbCkwsqQi6yX1S2KuB3ZfBzTsVKMqdiSHMQlZWk1wYbshcKxU7m66Vxt8pGMr8Zp5HkDR5VxDjTqq10U1CtF+Ga39kwRO9D2zet7xin4UCNH9EXXqLBl6hf1b82uKXZiWyO+rJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573264; c=relaxed/simple; bh=3fjpydKHWSOu9XgmRtvP8HbM0nxEj7fOfu4BP8gpsyg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kbYs+JN87oH96XYY3tTBj3lOBS2Y/qOwo0AEYd0Bimsmil/hJBErDHOyX4Xwjsz7H1RqgwE07J5gnCILSRD0jZDHwn1vjaZrK8WHIB2/uwRvlWK+KpMnKiTNj9qRZ8OPN7LecG+PYm+LSik5AiF9V0ZlqzUvhAQ0eaYmhMtWOn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CTlLui/8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CTlLui/8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BE35C433C7; Thu, 22 Feb 2024 03:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708573264; bh=3fjpydKHWSOu9XgmRtvP8HbM0nxEj7fOfu4BP8gpsyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTlLui/8gXrsHiPLaWi3kh2vjn8OKq0enf/NxMRzr/dvd/Zg6Ku093xElHeiExmaN obVXnhIoNfSlJQMzntyyB7Zow+EKueqozef8UkCqIvyxRFeDlutMELezTFAbUYX8sO Zm4/F7eQ7NNOXIlaSEKK5XYwLhNvi+FxzqLLQsMKn1PMJkmGNuNSWgfL960Zt0EwFC mkvbKEgYnCllu+XhbdbNHj7HGts3LIhX0oaBmnr4vWLoibP/DeYL76Rb3Fdh+BbNil fsJOkA2Wotrcd2s9S23QzszJIGeBvCakKFN0mO9g0zocAHXUNkUCC97x3QNVAGSt0B FF5vaCRwb3Zmw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 2/4] selftests: mptcp: add mptcp_lib_ns_init/exit helpers Date: Thu, 22 Feb 2024 11:40:34 +0800 Message-Id: <4518f97e63707f493123c76dd36d217a8eb42d35.1708572320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Add helpers mptcp_lib_ns_init() and mptcp_lib_ns_exit() in mptcp_lib.sh to initialize and delete the given namespaces. Then every test script can invoke these helpers and use all namespaces. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/diag.sh | 9 +++----- .../selftests/net/mptcp/mptcp_connect.sh | 23 ++++++++----------- .../testing/selftests/net/mptcp/mptcp_join.sh | 11 ++------- .../testing/selftests/net/mptcp/mptcp_lib.sh | 22 ++++++++++++++++++ .../selftests/net/mptcp/mptcp_sockopt.sh | 17 +++++--------- .../testing/selftests/net/mptcp/pm_netlink.sh | 9 +++----- .../selftests/net/mptcp/simult_flows.sh | 16 ++++--------- .../selftests/net/mptcp/userspace_pm.sh | 14 ++++------- 8 files changed, 54 insertions(+), 67 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/self= tests/net/mptcp/diag.sh index 60a7009ce1b5..24cffd94baae 100755 --- a/tools/testing/selftests/net/mptcp/diag.sh +++ b/tools/testing/selftests/net/mptcp/diag.sh @@ -3,9 +3,7 @@ =20 . "$(dirname "${0}")/mptcp_lib.sh" =20 -sec=3D$(date +%s) -rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) -ns=3D"ns1-$rndh" +ns=3D"" ksft_skip=3D4 test_cnt=3D1 timeout_poll=3D30 @@ -30,7 +28,7 @@ cleanup() { ip netns pids "${ns}" | xargs --no-run-if-empty kill -SIGKILL &>/dev/null =20 - ip netns del $ns + mptcp_lib_ns_exit "${ns}" } =20 mptcp_lib_check_mptcp @@ -205,8 +203,7 @@ wait_connected() } =20 trap cleanup EXIT -ip netns add $ns -ip -n $ns link set dev lo up +mptcp_lib_ns_init ns =20 echo "a" | \ timeout ${timeout_test} \ diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_connect.sh index b609649311f6..92f6260ba9f3 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -121,12 +121,10 @@ while getopts "$optstring" option;do esac done =20 -sec=3D$(date +%s) -rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) -ns1=3D"ns1-$rndh" -ns2=3D"ns2-$rndh" -ns3=3D"ns3-$rndh" -ns4=3D"ns4-$rndh" +ns1=3D"" +ns2=3D"" +ns3=3D"" +ns4=3D"" =20 TEST_COUNT=3D0 TEST_GROUP=3D"" @@ -140,9 +138,9 @@ cleanup() =20 local netns for netns in "$ns1" "$ns2" "$ns3" "$ns4";do - ip netns del $netns rm -f /tmp/$netns.{nstat,out} done + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" "${ns4}" } =20 mptcp_lib_check_mptcp @@ -158,10 +156,7 @@ cin_disconnect=3D"$cin".disconnect cout_disconnect=3D"$cout".disconnect trap cleanup EXIT =20 -for i in "$ns1" "$ns2" "$ns3" "$ns4";do - ip netns add $i || exit $ksft_skip - ip -net $i link set lo up -done +mptcp_lib_ns_init ns1 ns2 ns3 ns4 =20 # "$ns1" ns2 ns3 ns4 # ns1eth2 ns2eth1 ns2eth3 ns3eth2 ns3eth4 ns4eth3 @@ -251,8 +246,8 @@ fi =20 check_mptcp_disabled() { - local disabled_ns=3D"ns_disabled-$rndh" - ip netns add ${disabled_ns} || exit $ksft_skip + local disabled_ns + mptcp_lib_ns_init disabled_ns =20 # net.mptcp.enabled should be enabled by default if [ "$(ip netns exec ${disabled_ns} sysctl net.mptcp.enabled | awk '{ pr= int $3 }')" -ne 1 ]; then @@ -266,7 +261,7 @@ check_mptcp_disabled() local err=3D0 LC_ALL=3DC ip netns exec ${disabled_ns} ./mptcp_connect -p 10000 -s MPTCP= 127.0.0.1 < "$cin" 2>&1 | \ grep -q "^socket: Protocol not available$" && err=3D1 - ip netns delete ${disabled_ns} + mptcp_lib_ns_exit "${disabled_ns}" =20 if [ ${err} -eq 0 ]; then echo -e "New MPTCP socket cannot be blocked via sysctl\t\t[ FAIL ]" diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index aedc5698f26a..612470244c58 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -86,17 +86,10 @@ init_partial() { capout=3D$(mktemp) =20 - local sec rndh - sec=3D$(date +%s) - rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) - - ns1=3D"ns1-$rndh" - ns2=3D"ns2-$rndh" + mptcp_lib_ns_init ns1 ns2 =20 local netns for netns in "$ns1" "$ns2"; do - ip netns add $netns || exit $ksft_skip - ip -net $netns link set lo up ip netns exec $netns sysctl -q net.mptcp.enabled=3D1 ip netns exec $netns sysctl -q net.mptcp.pm_type=3D0 2>/dev/null || true ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=3D0 @@ -147,9 +140,9 @@ cleanup_partial() =20 local netns for netns in "$ns1" "$ns2"; do - ip netns del $netns rm -f /tmp/$netns.{nstat,out} done + mptcp_lib_ns_exit "${ns1}" "${ns2}" } =20 init() { diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing= /selftests/net/mptcp/mptcp_lib.sh index 556a7d9784d7..fcb3afb4d51f 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -373,3 +373,25 @@ mptcp_lib_check_output() { return 1 fi } + +mptcp_lib_ns_init() { + local sec rndh + + sec=3D$(date +%s) + rndh=3D$(printf %x "$sec")-$(mktemp -u XXXXXX) + + local netns + for netns in "${@}"; do + eval "${netns}=3D${netns}-${rndh}" + + ip netns add "${!netns}" || exit ${KSFT_SKIP} + ip -net "${!netns}" link set lo up + done +} + +mptcp_lib_ns_exit() { + local netns + for netns in "${@}"; do + ip netns del "$netns" + done +} diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_sockopt.sh index fd7de1b3dc55..5fa5fa8cab71 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -14,11 +14,9 @@ timeout_test=3D$((timeout_poll * 2 + 1)) iptables=3D"iptables" ip6tables=3D"ip6tables" =20 -sec=3D$(date +%s) -rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) -ns1=3D"ns1-$rndh" -ns2=3D"ns2-$rndh" -ns_sbox=3D"ns_sbox-$rndh" +ns1=3D"" +ns2=3D"" +ns_sbox=3D"" =20 add_mark_rules() { @@ -40,10 +38,10 @@ add_mark_rules() =20 init() { + mptcp_lib_ns_init ns1 ns2 ns_sbox + local netns for netns in "$ns1" "$ns2" "$ns_sbox";do - ip netns add $netns || exit $ksft_skip - ip -net $netns link set lo up ip netns exec $netns sysctl -q net.mptcp.enabled=3D1 ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=3D0 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=3D0 @@ -79,10 +77,7 @@ init() =20 cleanup() { - local netns - for netns in "$ns1" "$ns2" "$ns_sbox"; do - ip netns del $netns - done + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns_sbox}" rm -f "$cin" "$cout" rm -f "$sin" "$sout" } diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testin= g/selftests/net/mptcp/pm_netlink.sh index 1ec9d8622fc9..30ec0ec3d68f 100755 --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh @@ -24,15 +24,13 @@ while getopts "$optstring" option;do esac done =20 -sec=3D$(date +%s) -rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) -ns1=3D"ns1-$rndh" +ns1=3D"" err=3D$(mktemp) =20 cleanup() { rm -f $err - ip netns del $ns1 + mptcp_lib_ns_exit "${ns1}" } =20 mptcp_lib_check_mptcp @@ -40,8 +38,7 @@ mptcp_lib_check_tools ip =20 trap cleanup EXIT =20 -ip netns add $ns1 || exit $ksft_skip -ip -net $ns1 link set lo up +mptcp_lib_ns_init ns1 ip netns exec $ns1 sysctl -q net.mptcp.enabled=3D1 =20 check() diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/test= ing/selftests/net/mptcp/simult_flows.sh index 8a4520f29601..c5128d690c46 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -3,11 +3,9 @@ =20 . "$(dirname "${0}")/mptcp_lib.sh" =20 -sec=3D$(date +%s) -rndh=3D$(printf %x $sec)-$(mktemp -u XXXXXX) -ns1=3D"ns1-$rndh" -ns2=3D"ns2-$rndh" -ns3=3D"ns3-$rndh" +ns1=3D"" +ns2=3D"" +ns3=3D"" capture=3Dfalse ksft_skip=3D4 timeout_poll=3D30 @@ -36,10 +34,7 @@ cleanup() rm -f "$large" "$small" rm -f "$capout" =20 - local netns - for netns in "$ns1" "$ns2" "$ns3";do - ip netns del $netns - done + mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" } =20 mptcp_lib_check_mptcp @@ -65,9 +60,8 @@ setup() =20 trap cleanup EXIT =20 + mptcp_lib_ns_init ns1 ns2 ns3 for i in "$ns1" "$ns2" "$ns3";do - ip netns add $i || exit $ksft_skip - ip -net $i link set lo up ip netns exec $i sysctl -q net.ipv4.conf.all.rp_filter=3D0 ip netns exec $i sysctl -q net.ipv4.conf.default.rp_filter=3D0 done diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/test= ing/selftests/net/mptcp/userspace_pm.sh index 629fc5d0ecc5..e3092696d2de 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -50,10 +50,8 @@ app6_port=3D50004 client_addr_id=3D${RANDOM:0:2} server_addr_id=3D${RANDOM:0:2} =20 -sec=3D$(date +%s) -rndh=3D$(printf %x "$sec")-$(mktemp -u XXXXXX) -ns1=3D"ns1-$rndh" -ns2=3D"ns2-$rndh" +ns1=3D"" +ns2=3D"" ret=3D0 test_name=3D"" =20 @@ -118,10 +116,7 @@ cleanup() mptcp_lib_kill_wait $pid done =20 - local netns - for netns in "$ns1" "$ns2" ;do - ip netns del "$netns" - done + mptcp_lib_ns_exit "${ns1}" "${ns2}" =20 rm -rf $file $client_evts $server_evts =20 @@ -131,9 +126,8 @@ cleanup() trap cleanup EXIT =20 # Create and configure network namespaces for testing +mptcp_lib_ns_init ns1 ns2 for i in "$ns1" "$ns2" ;do - ip netns add "$i" || exit 1 - ip -net "$i" link set lo up ip netns exec "$i" sysctl -q net.mptcp.enabled=3D1 ip netns exec "$i" sysctl -q net.mptcp.pm_type=3D1 done --=20 2.40.1 From nobody Tue May 14 22:40:21 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3B401755C for ; Thu, 22 Feb 2024 03:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573266; cv=none; b=aMMsiD5qTivHMcfEkCYo8iU8yvdMOmauo/qqqKkA4I3oJqAqvq2rHKKocQI38d87xa3ZBgcf1WVkYaieXTKz0jiwZ0s8DaK4wRnoxhyMYgUBNTIFBU3tyO1zOCPT2/QAS/gRSsV/piT7knfkPcEgexJoWTYZHfUUQpIB2be568M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573266; c=relaxed/simple; bh=uqVTDGJRVjofl8ez+4tsIn2lArwdOMuIST5qC4YR+to=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SP2H9a9YGDovL1sUoDZpBdxxepMvH8gAmXXaLLOlfsRJkmY+453HOpR/EWY8ISYYv538vo2BZfislQ0YILSK/orc9gE7oQIp/sEzUsxWQgGt0Xsmyol0goJdIUbdHTTmRak7p4vA9gjoVHwSW8IjkBGJFnzH42pOks+P46jzw3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tBW6AZjb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tBW6AZjb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1B2AC433F1; Thu, 22 Feb 2024 03:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708573265; bh=uqVTDGJRVjofl8ez+4tsIn2lArwdOMuIST5qC4YR+to=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tBW6AZjbyc+4xlbINDjoAiD4KTUYfG5HQUXYjvztU/VIll6EgDK9EDd3a8OPsQ6C6 w4t4gUK5pZauxx8kGDuSbvGJedFCyR21H/SOavQJkwSxOmchnCjd0dqh4PC6F3Wlrl Z6469PqW278VK0qaIh2lIRqt14OR1mGMezenBp0S2oc4l3qCAzRNT2PAsAlrt938bV 1HJUR4HuDG85gnJ5a1vHsDcuEAZUdBK0XlNWR0Df6lkoSLaDKte4bhtivjjurMjJbh bRL9a9se3RjybCdvB7p6RRlpXzKkhY5bSPxZKsyY2flB43XPlXYfF8bfV1thVllyyH fw25JiENYoJFw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 3/4] selftests: mptcp: more operations in ns_init/exit Date: Thu, 22 Feb 2024 11:40:35 +0800 Message-Id: <9886ac0fe4205b00b05d51cd225b5c72da076359.1708572320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Set more the default sysctl values in mptcp_lib_ns_init(). It is fine to do that everywhere, because they could be overridden latter if needed. mptcp_lib_ns_exit() now also try to remove temp netns files used for the stats even for selftests not using them. That's fine to do that because these files have a unique name. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_connect.sh | 4 ---- tools/testing/selftests/net/mptcp/mptcp_join.sh | 7 ------- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 4 ++++ tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 7 ------- tools/testing/selftests/net/mptcp/pm_netlink.sh | 1 - tools/testing/selftests/net/mptcp/simult_flows.sh | 4 ---- tools/testing/selftests/net/mptcp/userspace_pm.sh | 1 - 7 files changed, 4 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_connect.sh index 92f6260ba9f3..b53ae64ec08c 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -136,10 +136,6 @@ cleanup() rm -f "$sin" "$sout" rm -f "$capout" =20 - local netns - for netns in "$ns1" "$ns2" "$ns3" "$ns4";do - rm -f /tmp/$netns.{nstat,out} - done mptcp_lib_ns_exit "${ns1}" "${ns2}" "${ns3}" "${ns4}" } =20 diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 612470244c58..2d9cf6f3bbf3 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -90,10 +90,7 @@ init_partial() =20 local netns for netns in "$ns1" "$ns2"; do - ip netns exec $netns sysctl -q net.mptcp.enabled=3D1 ip netns exec $netns sysctl -q net.mptcp.pm_type=3D0 2>/dev/null || true - ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=3D0 - ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=3D0 if $checksum; then ip netns exec $netns sysctl -q net.mptcp.checksum_enabled=3D1 fi @@ -138,10 +135,6 @@ cleanup_partial() { rm -f "$capout" =20 - local netns - for netns in "$ns1" "$ns2"; do - rm -f /tmp/$netns.{nstat,out} - done mptcp_lib_ns_exit "${ns1}" "${ns2}" } =20 diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing= /selftests/net/mptcp/mptcp_lib.sh index fcb3afb4d51f..f65a31594829 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -386,6 +386,9 @@ mptcp_lib_ns_init() { =20 ip netns add "${!netns}" || exit ${KSFT_SKIP} ip -net "${!netns}" link set lo up + ip netns exec "${!netns}" sysctl -q net.mptcp.enabled=3D1 + ip netns exec "${!netns}" sysctl -q net.ipv4.conf.all.rp_filter=3D0 + ip netns exec "${!netns}" sysctl -q net.ipv4.conf.default.rp_filter=3D0 done } =20 @@ -393,5 +396,6 @@ mptcp_lib_ns_exit() { local netns for netns in "${@}"; do ip netns del "$netns" + rm -f /tmp/"$netns".{nstat,out} done } diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_sockopt.sh index 5fa5fa8cab71..7dd0e5467d35 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh @@ -40,13 +40,6 @@ init() { mptcp_lib_ns_init ns1 ns2 ns_sbox =20 - local netns - for netns in "$ns1" "$ns2" "$ns_sbox";do - ip netns exec $netns sysctl -q net.mptcp.enabled=3D1 - ip netns exec $netns sysctl -q net.ipv4.conf.all.rp_filter=3D0 - ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=3D0 - done - local i for i in `seq 1 4`; do ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$n= s2" diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testin= g/selftests/net/mptcp/pm_netlink.sh index 30ec0ec3d68f..c7c46152f6fd 100755 --- a/tools/testing/selftests/net/mptcp/pm_netlink.sh +++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh @@ -39,7 +39,6 @@ mptcp_lib_check_tools ip trap cleanup EXIT =20 mptcp_lib_ns_init ns1 -ip netns exec $ns1 sysctl -q net.mptcp.enabled=3D1 =20 check() { diff --git a/tools/testing/selftests/net/mptcp/simult_flows.sh b/tools/test= ing/selftests/net/mptcp/simult_flows.sh index c5128d690c46..bc8f107357ac 100755 --- a/tools/testing/selftests/net/mptcp/simult_flows.sh +++ b/tools/testing/selftests/net/mptcp/simult_flows.sh @@ -61,10 +61,6 @@ setup() trap cleanup EXIT =20 mptcp_lib_ns_init ns1 ns2 ns3 - for i in "$ns1" "$ns2" "$ns3";do - ip netns exec $i sysctl -q net.ipv4.conf.all.rp_filter=3D0 - ip netns exec $i sysctl -q net.ipv4.conf.default.rp_filter=3D0 - done =20 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2" ip link add ns1eth2 netns "$ns1" type veth peer name ns2eth2 netns "$ns2" diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/test= ing/selftests/net/mptcp/userspace_pm.sh index e3092696d2de..6d71bf36a1b9 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -128,7 +128,6 @@ trap cleanup EXIT # Create and configure network namespaces for testing mptcp_lib_ns_init ns1 ns2 for i in "$ns1" "$ns2" ;do - ip netns exec "$i" sysctl -q net.mptcp.enabled=3D1 ip netns exec "$i" sysctl -q net.mptcp.pm_type=3D1 done =20 --=20 2.40.1 From nobody Tue May 14 22:40:21 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 511CC1799E for ; Thu, 22 Feb 2024 03:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573267; cv=none; b=KDlqI2BOCktX3QK9WyEnY5cR9bfOaxlWTBouGdapWB7Nz2Rzl2MovB9XOcfeTNLfQXNsZgfqARVrrg0Ngcmd+3ptN7vwkkBV7GcI6XgUO9i8xVNAWjnaDMXQg0LbCT4chBhPQDX2pQ6aedOEUzJFasqUuzdozixNy0blJGMrrKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708573267; c=relaxed/simple; bh=DES3Ueuh+5AM6YDRu68i++P2y0+tRMpJeNRreeTIY0c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tv9nRKdS72EF3oTaBSZvIIcKcAu7GG+jAczteGeNoURG8/gYrQCedOztDzB3d6A3iKI0ilhyLVFrhFSNu8Tp8YxmO/KXkHk3ZpBycLRy7GdIp5W7e6E3wGv23vjfd+h1bJBa52RZ8A2ws2wUoVsRQQ5SMsRSG2Ds335W+pvgqHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mWLAe0F9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mWLAe0F9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C8D1C43390; Thu, 22 Feb 2024 03:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708573266; bh=DES3Ueuh+5AM6YDRu68i++P2y0+tRMpJeNRreeTIY0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWLAe0F9aeAabilVPz4W2q/cah92CTxfCVGcUx+O9iadcmaelKU9eKX/81LlGgKTo j2HV/OLSTUbb1M6/FSVtqCneQfozKDoR4hLX303EDny0/Ysmy7Xay3ipUGhsN5gkE9 YFXyiFZPsLtxZacr7KPkkqiCKO96MXXm4klIl+jOH/MICCGLfAHyPnB+f5fn755uUI xORPwA4cVCv6xm69y/2eHtO9WTxnhlc1M/MH1QhvasDRVn8Msl35JKEhOg5hK5MixA NmCo9OwqG6sMkbFlzJrcQ1wEXDhXEeplMFjTXns0UHQWF5HZ/EijGfySayeK1Fvcg5 1c3RktwxbAzbQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v4 4/4] selftests: mptcp: add mptcp_lib_events helper Date: Thu, 22 Feb 2024 11:40:36 +0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang To avoid duplicated code in different MPTCP selftests, we can add and use helpers defined in mptcp_lib.sh. This patch unifies "pm_nl_ctl events" related code in userspace_pm.sh and mptcp_join.sh into a helper mptcp_lib_events(). Define it in mptcp_lib.sh and use it in both scripts. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 8 ++------ tools/testing/selftests/net/mptcp/mptcp_lib.sh | 14 ++++++++++++++ tools/testing/selftests/net/mptcp/userspace_pm.sh | 14 ++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 2d9cf6f3bbf3..292fccb1f7f4 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -430,12 +430,8 @@ reset_with_events() { reset "${1}" || return 1 =20 - :> "$evts_ns1" - :> "$evts_ns2" - ip netns exec $ns1 ./pm_nl_ctl events >> "$evts_ns1" 2>&1 & - evts_ns1_pid=3D$! - ip netns exec $ns2 ./pm_nl_ctl events >> "$evts_ns2" 2>&1 & - evts_ns2_pid=3D$! + mptcp_lib_events "${ns1}" "${evts_ns1}" evts_ns1_pid + mptcp_lib_events "${ns2}" "${evts_ns2}" evts_ns2_pid } =20 reset_with_tcp_filter() diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing= /selftests/net/mptcp/mptcp_lib.sh index f65a31594829..5b5ad9947c21 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -399,3 +399,17 @@ mptcp_lib_ns_exit() { rm -f /tmp/"$netns".{nstat,out} done } + +mptcp_lib_events() { + local ns=3D"${1}" + local evts=3D"${2}" + declare -n pid=3D"${3}" + + :>"${evts}" + + if [ ${pid} -ne 0 ]; then + mptcp_lib_kill_wait "${pid}" + fi + ip netns exec "${ns}" ./pm_nl_ctl events >> "${evts}" 2>&1 & + pid=3D$! +} diff --git a/tools/testing/selftests/net/mptcp/userspace_pm.sh b/tools/test= ing/selftests/net/mptcp/userspace_pm.sh index 6d71bf36a1b9..3200d0b96d53 100755 --- a/tools/testing/selftests/net/mptcp/userspace_pm.sh +++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh @@ -178,21 +178,11 @@ make_connection() if [ -z "$client_evts" ]; then client_evts=3D$(mktemp) fi - :>"$client_evts" - if [ $client_evts_pid -ne 0 ]; then - mptcp_lib_kill_wait $client_evts_pid - fi - ip netns exec "$ns2" ./pm_nl_ctl events >> "$client_evts" 2>&1 & - client_evts_pid=3D$! + mptcp_lib_events "${ns2}" "${client_evts}" client_evts_pid if [ -z "$server_evts" ]; then server_evts=3D$(mktemp) fi - :>"$server_evts" - if [ $server_evts_pid -ne 0 ]; then - mptcp_lib_kill_wait $server_evts_pid - fi - ip netns exec "$ns1" ./pm_nl_ctl events >> "$server_evts" 2>&1 & - server_evts_pid=3D$! + mptcp_lib_events "${ns1}" "${server_evts}" server_evts_pid sleep 0.5 =20 # Run the server --=20 2.40.1