From nobody Mon Feb 9 03:13:46 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a05:6402:2547:0:0:0:0 with SMTP id l7csp459253edb; Wed, 9 Mar 2022 11:17:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKKvrwiC8vIiG7a1bzR1kjKgjr4FPhSQ6uwYHqfdmzlfKYFpdpG3r7uW0zFHSUWcOwtfi5 X-Received: by 2002:a63:e747:0:b0:372:c757:c569 with SMTP id j7-20020a63e747000000b00372c757c569mr997242pgk.516.1646853420587; Wed, 09 Mar 2022 11:17:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646853420; cv=none; d=google.com; s=arc-20160816; b=tj2EDTNOrObvL3FJ2TuzDBeHUh+efsR2efcFZsqsZu4BQeMtROS++IGb49KCxJIBFC EspXUlw4pjqmv48lP3f75IHvKipYLnyIR8SN4Bwh9kC6jJYP0mhfYaUhlct8sH8w9LXD oU1kR6mCLOqeviMHgjsLNMVp9mkNSfpoBBs3ChofREWRAT2jwel2UYUxaA0D0wsucXXZ iBFJsrQoq1bE03W0VRZZ61ZCMvUxx+4pyQQmPJ7yo5pqkgtShFZOETA508T5rnCsL1Mq 9ZyePMouO2P88COg5QpxslwxdsJIa6nOkjuuajNbI/B1z8PWmG2q/2hgsf/TOiDLE7lR 0yXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=xHB0B7vLeL2uiCTtyWL3hrW5egKZ3x2WJNsWs/0WEz4=; b=LCC15lRYgcknL/5ofvAz1t/ZqKuCdaHq1Oz5zANLGe1KUay9aXvr6oXrjzSuBRrzYg Oxj8v7O/8U2cgHQixW2uLoZB/nwtu1ciwdKJT1V06PXOPNxeXynQeg1QV9GbahMIJXZI NkZtrPklbATKsgNgUx779a2+2iUZ2CHMxH3s977wxlWlXGzBrUXJLFtxShngRxRlegrf zAxnwbzN5HMRQgo/327350Uvl8C71CvMBtSNsmhwV1oah8qVXxMqHXqlB3Pxje5SNDao RkvN/vhhc+KFmntSdDQnWAZqP8/8ffypz2lpod+X10LxSOyHBuucOs4HTSOuCLcMALJS 6GAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=L2Nn5GrA; spf=pass (google.com: domain of mptcp+bounces-4195-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-4195-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id l8-20020a056a00140800b004f0e9eac948si2786060pfu.233.2022.03.09.11.17.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Mar 2022 11:17:00 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-4195-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=L2Nn5GrA; spf=pass (google.com: domain of mptcp+bounces-4195-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-4195-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sjc.edge.kernel.org (Postfix) with ESMTPS id 8212F3E0F4F for ; Wed, 9 Mar 2022 19:16:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40D395107; Wed, 9 Mar 2022 19:16:56 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 934385118 for ; Wed, 9 Mar 2022 19:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646853414; x=1678389414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pwS+P7GhhUTjI45SEYthGKFuL5gNqe6mm6FuLnmZ+bc=; b=L2Nn5GrAewz5cdBaOL7voICzXP85KqKVMGuxHnoj8EF5mUcwr/ZqF4+E 7dhoouxVxi+QBxkQTBZqevHEqtApKxCdeK/ePahpmQnH2xsjJaDUuSug8 xbMD3kEWgJ/pgHeKBh0/7pJPhLWjHgku93isDh3g1DItfI+QLxIKQI1bI T1CwcVp+b+sl1bYQmVvctsZgZ2HvdfSs/NFq6G8uMG/ekgoubrRh88FYR lz8qDz5pKKrTBw+HlX92FbPaJi5clWkgn2093XJYtVVGRG0egmfvpV8e6 uZLy039fjIPqpvfFCVzu3bp0NnbmwMPo4FFYIfz2vxqRNPQydiqVOm8Rj A==; X-IronPort-AV: E=McAfee;i="6200,9189,10281"; a="255011990" X-IronPort-AV: E=Sophos;i="5.90,168,1643702400"; d="scan'208";a="255011990" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2022 11:16:46 -0800 X-IronPort-AV: E=Sophos;i="5.90,168,1643702400"; d="scan'208";a="495957063" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.212.194.198]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2022 11:16:46 -0800 From: Mat Martineau To: netdev@vger.kernel.org Cc: Matthieu Baerts , davem@davemloft.net, kuba@kernel.org, mptcp@lists.linux.dev, Mat Martineau Subject: [PATCH net-next 08/10] selftests: mptcp: join: clarify local/global vars Date: Wed, 9 Mar 2022 11:16:34 -0800 Message-Id: <20220309191636.258232-9-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220309191636.258232-1-mathew.j.martineau@linux.intel.com> References: <20220309191636.258232-1-mathew.j.martineau@linux.intel.com> 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: Matthieu Baerts Some vars are redefined in different places. Best to avoid this classical Bash pitfall where variables are accidentally overridden by other functions because the proper scope has not been defined. Most issues are with loops: typically 'i' is used in for-loops but if it is not global, calling a function from a for-loop also doing a for-loop with the same non local 'i' variable causes troubles because the first 'i' will be assigned to another value. To prevent such issues, the iterator variable is now declared as local just before the loop. If it is always done like this, issues are avoided. To distinct between local and non local variables, all non local ones are defined at the beginning of the script. The others are now defined with the "local" keyword. Signed-off-by: Matthieu Baerts Signed-off-by: Mat Martineau --- .../testing/selftests/net/mptcp/mptcp_join.sh | 135 +++++++++++------- 1 file changed, 83 insertions(+), 52 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 5223f2a752b9..d8dc36fcdb56 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -9,6 +9,9 @@ cin=3D"" cinfail=3D"" cinsent=3D"" cout=3D"" +capout=3D"" +ns1=3D"" +ns2=3D"" ksft_skip=3D4 timeout_poll=3D30 timeout_test=3D$((timeout_poll * 2 + 1)) @@ -51,12 +54,14 @@ init_partial() { capout=3D$(mktemp) =20 + local rndh rndh=3D$(mktemp -u XXXXXX) =20 ns1=3D"ns1-$rndh" ns2=3D"ns2-$rndh" =20 - for netns in "$ns1" "$ns2";do + 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 @@ -77,6 +82,7 @@ init_partial() # ns1eth3 ns2eth3 # ns1eth4 ns2eth4 =20 + 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" ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i @@ -95,6 +101,7 @@ init_partial() =20 init_shapers() { + local i for i in `seq 1 4`; do tc -n $ns1 qdisc add dev ns1eth$i root netem rate 20mbit delay 1 tc -n $ns2 qdisc add dev ns2eth$i root netem rate 20mbit delay 1 @@ -105,6 +112,7 @@ cleanup_partial() { rm -f "$capout" =20 + local netns for netns in "$ns1" "$ns2"; do ip netns del $netns rm -f /tmp/$netns.{nstat,out} @@ -201,7 +209,8 @@ reset_with_cookies() { reset "${1}" || return 1 =20 - for netns in "$ns1" "$ns2";do + local netns + for netns in "$ns1" "$ns2"; do ip netns exec $netns sysctl -q net.ipv4.tcp_syncookies=3D2 done } @@ -276,10 +285,11 @@ print_file_err() =20 check_transfer() { - in=3D$1 - out=3D$2 - what=3D$3 + local in=3D$1 + local out=3D$2 + local what=3D$3 =20 + local line cmp -l "$in" "$out" | while read line; do local arr=3D($line) =20 @@ -301,9 +311,9 @@ check_transfer() =20 do_ping() { - listener_ns=3D"$1" - connector_ns=3D"$2" - connect_addr=3D"$3" + local listener_ns=3D"$1" + local connector_ns=3D"$2" + local connect_addr=3D"$3" =20 ip netns exec ${connector_ns} ping -q -c 1 $connect_addr >/dev/null if [ $? -ne 0 ] ; then @@ -314,15 +324,16 @@ do_ping() =20 link_failure() { - ns=3D"$1" + local ns=3D"$1" =20 if [ -z "$FAILING_LINKS" ]; then l=3D$((RANDOM%4)) FAILING_LINKS=3D$((l+1)) fi =20 + local l for l in $FAILING_LINKS; do - veth=3D"ns1eth$l" + local veth=3D"ns1eth$l" ip -net "$ns" link set "$veth" down done } @@ -339,9 +350,10 @@ wait_local_port_listen() local listener_ns=3D"${1}" local port=3D"${2}" =20 - local port_hex i - + local port_hex port_hex=3D"$(printf "%04X" "${port}")" + + local i for i in $(seq 10); do ip netns exec "${listener_ns}" cat /proc/net/tcp* | \ awk "BEGIN {rc=3D1} {if (\$2 ~ /:${port_hex}\$/ && \$4 ~ /0A/) {rc=3D0;= exit}} END {exit rc}" && @@ -352,7 +364,7 @@ wait_local_port_listen() =20 rm_addr_count() { - ns=3D${1} + local ns=3D${1} =20 ip netns exec ${ns} nstat -as | grep MPTcpExtRmAddr | awk '{print $2}' } @@ -363,8 +375,8 @@ wait_rm_addr() local ns=3D"${1}" local old_cnt=3D"${2}" local cnt - local i =20 + local i for i in $(seq 10); do cnt=3D$(rm_addr_count ${ns}) [ "$cnt" =3D "${old_cnt}" ] || break @@ -404,12 +416,13 @@ pm_nl_add_endpoint() { local ns=3D$1 local addr=3D$2 - local flags - local port - local dev - local id + local flags _flags + local port _port + local dev _dev + local id _id local nr=3D2 =20 + local p for p in $@ do if [ $p =3D "flags" ]; then @@ -572,24 +585,26 @@ filter_tcp_from() =20 do_transfer() { - listener_ns=3D"$1" - connector_ns=3D"$2" - cl_proto=3D"$3" - srv_proto=3D"$4" - connect_addr=3D"$5" - test_link_fail=3D"$6" - addr_nr_ns1=3D"$7" - addr_nr_ns2=3D"$8" - speed=3D"$9" - sflags=3D"${10}" - - port=3D$((10000+$TEST_COUNT-1)) + local listener_ns=3D"$1" + local connector_ns=3D"$2" + local cl_proto=3D"$3" + local srv_proto=3D"$4" + local connect_addr=3D"$5" + local test_link_fail=3D"$6" + local addr_nr_ns1=3D"$7" + local addr_nr_ns2=3D"$8" + local speed=3D"$9" + local sflags=3D"${10}" + + local port=3D$((10000 + TEST_COUNT - 1)) + local cappid =20 :> "$cout" :> "$sout" :> "$capout" =20 if [ $capture -eq 1 ]; then + local capuser if [ -z $SUDO_USER ] ; then capuser=3D"" else @@ -643,7 +658,7 @@ do_transfer() ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ $extra_args ${local_addr} < "$sin" > "$sout" & fi - spid=3D$! + local spid=3D$! =20 wait_local_port_listen "${listener_ns}" "${port}" =20 @@ -666,15 +681,16 @@ do_transfer() ./mptcp_connect -t ${timeout_poll} -p $port -s ${cl_proto} \ $extra_args $connect_addr > "$cout" & fi - cpid=3D$! + local cpid=3D$! =20 # let the mptcp subflow be established in background before # do endpoint manipulation [ $addr_nr_ns1 =3D "0" -a $addr_nr_ns2 =3D "0" ] || sleep 1 =20 if [ $addr_nr_ns1 -gt 0 ]; then + local counter=3D2 + local add_nr_ns1 let add_nr_ns1=3Daddr_nr_ns1 - counter=3D2 while [ $add_nr_ns1 -gt 0 ]; do local addr if is_v6 "${connect_addr}"; then @@ -687,13 +703,16 @@ do_transfer() let add_nr_ns1-=3D1 done elif [ $addr_nr_ns1 -lt 0 ]; then + local rm_nr_ns1 let rm_nr_ns1=3D-addr_nr_ns1 if [ $rm_nr_ns1 -lt 8 ]; then - counter=3D0 + local counter=3D0 + local line pm_nl_show_endpoints ${listener_ns} | while read line; do local arr=3D($line) local nr=3D0 =20 + local i for i in ${arr[@]}; do if [ $i =3D "id" ]; then if [ $counter -eq $rm_nr_ns1 ]; then @@ -715,7 +734,7 @@ do_transfer() fi fi =20 - flags=3D"subflow" + local flags=3D"subflow" if [[ "${addr_nr_ns2}" =3D "fullmesh_"* ]]; then flags=3D"${flags},fullmesh" addr_nr_ns2=3D${addr_nr_ns2:9} @@ -726,8 +745,9 @@ do_transfer() [ $addr_nr_ns1 -gt 0 -a $addr_nr_ns2 -lt 0 ] && sleep 1 =20 if [ $addr_nr_ns2 -gt 0 ]; then + local add_nr_ns2 let add_nr_ns2=3Daddr_nr_ns2 - counter=3D3 + local counter=3D3 while [ $add_nr_ns2 -gt 0 ]; do local addr if is_v6 "${connect_addr}"; then @@ -740,18 +760,21 @@ do_transfer() let add_nr_ns2-=3D1 done elif [ $addr_nr_ns2 -lt 0 ]; then - let rm_nr_ns2=3D-addr_nr_ns2 + local rm_nr_ns2 if [ $rm_nr_ns2 -lt 8 ]; then - counter=3D0 + local counter=3D0 + local line pm_nl_show_endpoints ${connector_ns} | while read line; do local arr=3D($line) local nr=3D0 =20 + local i for i in ${arr[@]}; do if [ $i =3D "id" ]; then if [ $counter -eq $rm_nr_ns2 ]; then break fi + local id rm_addr # rm_addr are serialized, allow the previous one to # complete id=3D${arr[$nr+1]} @@ -778,12 +801,16 @@ do_transfer() =20 if [ ! -z $sflags ]; then sleep 1 + + local netns for netns in "$ns1" "$ns2"; do + local line pm_nl_show_endpoints $netns | while read line; do local arr=3D($line) local nr=3D0 local id =20 + local i for i in ${arr[@]}; do if [ $i =3D "id" ]; then id=3D${arr[$nr+1]} @@ -796,9 +823,9 @@ do_transfer() fi =20 wait $cpid - retc=3D$? + local retc=3D$? wait $spid - rets=3D$? + local rets=3D$? =20 if [ $capture -eq 1 ]; then sleep 1 @@ -848,9 +875,9 @@ do_transfer() =20 make_file() { - name=3D$1 - who=3D$2 - size=3D$3 + local name=3D$1 + local who=3D$2 + local size=3D$3 =20 dd if=3D/dev/urandom of=3D"$name" bs=3D1024 count=3D$size 2> /dev/null echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" @@ -860,14 +887,16 @@ make_file() =20 run_tests() { - listener_ns=3D"$1" - connector_ns=3D"$2" - connect_addr=3D"$3" - test_linkfail=3D"${4:-0}" - addr_nr_ns1=3D"${5:-0}" - addr_nr_ns2=3D"${6:-0}" - speed=3D"${7:-fast}" - sflags=3D"${8:-""}" + local listener_ns=3D"$1" + local connector_ns=3D"$2" + local connect_addr=3D"$3" + local test_linkfail=3D"${4:-0}" + local addr_nr_ns1=3D"${5:-0}" + local addr_nr_ns2=3D"${6:-0}" + local speed=3D"${7:-fast}" + local sflags=3D"${8:-""}" + + local size =20 # The values above 2 are reused to make test files # with the given sizes (KB) @@ -1437,7 +1466,9 @@ wait_attempt_fail() local ns=3D$1 =20 while [ $time -lt $timeout_ms ]; do - local cnt=3D$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAtte= mptFails | awk '{print $2}') + local cnt + + cnt=3D$(ip netns exec $ns nstat -as TcpAttemptFails | grep TcpAttemptFai= ls | awk '{print $2}') =20 [ "$cnt" =3D 1 ] && return 1 time=3D$((time + 100)) --=20 2.35.1