Skip to content

Commit 5f17f8e

Browse files
matttbekuba-moo
authored andcommitted
selftests: mptcp: declare var as local
Just to avoid classical Bash pitfall where variables are accidentally overridden by other functions because the proper scope has not been defined. That's also what is done in other MPTCP selftests scripts where all non local variables are defined at the beginning of the script and the others are defined with the "local" keyword. Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: Matthieu Baerts <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent de23920 commit 5f17f8e

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

tools/testing/selftests/net/mptcp/mptcp_sockopt.sh

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_mark_rules()
2222
local ns=$1
2323
local m=$2
2424

25+
local t
2526
for t in iptables ip6tables; do
2627
# just to debug: check we have multiple subflows connection requests
2728
ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
@@ -36,6 +37,7 @@ add_mark_rules()
3637

3738
init()
3839
{
40+
local netns
3941
for netns in "$ns1" "$ns2" "$ns_sbox";do
4042
ip netns add $netns || exit $ksft_skip
4143
ip -net $netns link set lo up
@@ -44,6 +46,7 @@ init()
4446
ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
4547
done
4648

49+
local i
4750
for i in `seq 1 4`; do
4851
ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
4952
ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
@@ -73,6 +76,7 @@ init()
7376

7477
cleanup()
7578
{
79+
local netns
7680
for netns in "$ns1" "$ns2" "$ns_sbox"; do
7781
ip netns del $netns
7882
done
@@ -103,15 +107,17 @@ check_mark()
103107
local ns=$1
104108
local af=$2
105109

106-
tables=iptables
110+
local tables=iptables
107111

108112
if [ $af -eq 6 ];then
109113
tables=ip6tables
110114
fi
111115

116+
local counters values
112117
counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
113118
values=${counters%DROP*}
114119

120+
local v
115121
for v in $values; do
116122
if [ $v -ne 0 ]; then
117123
echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
@@ -131,9 +137,9 @@ print_file_err()
131137

132138
check_transfer()
133139
{
134-
in=$1
135-
out=$2
136-
what=$3
140+
local in=$1
141+
local out=$2
142+
local what=$3
137143

138144
cmp "$in" "$out" > /dev/null 2>&1
139145
if [ $? -ne 0 ] ;then
@@ -156,18 +162,18 @@ is_v6()
156162

157163
do_transfer()
158164
{
159-
listener_ns="$1"
160-
connector_ns="$2"
161-
cl_proto="$3"
162-
srv_proto="$4"
163-
connect_addr="$5"
165+
local listener_ns="$1"
166+
local connector_ns="$2"
167+
local cl_proto="$3"
168+
local srv_proto="$4"
169+
local connect_addr="$5"
164170

165-
port=12001
171+
local port=12001
166172

167173
:> "$cout"
168174
:> "$sout"
169175

170-
mptcp_connect="./mptcp_connect -r 20"
176+
local mptcp_connect="./mptcp_connect -r 20"
171177

172178
local local_addr
173179
if is_v6 "${connect_addr}"; then
@@ -180,7 +186,7 @@ do_transfer()
180186
ip netns exec ${listener_ns} \
181187
$mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \
182188
${local_addr} < "$sin" > "$sout" &
183-
spid=$!
189+
local spid=$!
184190

185191
sleep 1
186192

@@ -189,12 +195,12 @@ do_transfer()
189195
$mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \
190196
$connect_addr < "$cin" > "$cout" &
191197

192-
cpid=$!
198+
local cpid=$!
193199

194200
wait $cpid
195-
retc=$?
201+
local retc=$?
196202
wait $spid
197-
rets=$?
203+
local rets=$?
198204

199205
if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
200206
echo " client exit code $retc, server $rets" 1>&2
@@ -229,9 +235,9 @@ do_transfer()
229235

230236
make_file()
231237
{
232-
name=$1
233-
who=$2
234-
size=$3
238+
local name=$1
239+
local who=$2
240+
local size=$3
235241

236242
dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
237243
echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
@@ -264,9 +270,9 @@ do_mptcp_sockopt_tests()
264270

265271
run_tests()
266272
{
267-
listener_ns="$1"
268-
connector_ns="$2"
269-
connect_addr="$3"
273+
local listener_ns="$1"
274+
local connector_ns="$2"
275+
local connect_addr="$3"
270276
local lret=0
271277

272278
do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
@@ -282,7 +288,7 @@ run_tests()
282288
do_tcpinq_test()
283289
{
284290
ip netns exec "$ns_sbox" ./mptcp_inq "$@"
285-
lret=$?
291+
local lret=$?
286292
if [ $lret -ne 0 ];then
287293
ret=$lret
288294
echo "FAIL: mptcp_inq $@" 1>&2
@@ -297,6 +303,7 @@ do_tcpinq_tests()
297303
{
298304
local lret=0
299305

306+
local args
300307
for args in "-t tcp" "-r tcp"; do
301308
do_tcpinq_test $args
302309
lret=$?

0 commit comments

Comments
 (0)