Commit 5f17f8e3 authored by Matthieu Baerts's avatar Matthieu Baerts Committed by Jakub Kicinski

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: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent de239202
...@@ -22,6 +22,7 @@ add_mark_rules() ...@@ -22,6 +22,7 @@ add_mark_rules()
local ns=$1 local ns=$1
local m=$2 local m=$2
local t
for t in iptables ip6tables; do for t in iptables ip6tables; do
# just to debug: check we have multiple subflows connection requests # just to debug: check we have multiple subflows connection requests
ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT ip netns exec $ns $t -A OUTPUT -p tcp --syn -m mark --mark $m -j ACCEPT
...@@ -36,6 +37,7 @@ add_mark_rules() ...@@ -36,6 +37,7 @@ add_mark_rules()
init() init()
{ {
local netns
for netns in "$ns1" "$ns2" "$ns_sbox";do for netns in "$ns1" "$ns2" "$ns_sbox";do
ip netns add $netns || exit $ksft_skip ip netns add $netns || exit $ksft_skip
ip -net $netns link set lo up ip -net $netns link set lo up
...@@ -44,6 +46,7 @@ init() ...@@ -44,6 +46,7 @@ init()
ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0 ip netns exec $netns sysctl -q net.ipv4.conf.default.rp_filter=0
done done
local i
for i in `seq 1 4`; do for i in `seq 1 4`; do
ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2" ip link add ns1eth$i netns "$ns1" type veth peer name ns2eth$i netns "$ns2"
ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i ip -net "$ns1" addr add 10.0.$i.1/24 dev ns1eth$i
...@@ -73,6 +76,7 @@ init() ...@@ -73,6 +76,7 @@ init()
cleanup() cleanup()
{ {
local netns
for netns in "$ns1" "$ns2" "$ns_sbox"; do for netns in "$ns1" "$ns2" "$ns_sbox"; do
ip netns del $netns ip netns del $netns
done done
...@@ -103,15 +107,17 @@ check_mark() ...@@ -103,15 +107,17 @@ check_mark()
local ns=$1 local ns=$1
local af=$2 local af=$2
tables=iptables local tables=iptables
if [ $af -eq 6 ];then if [ $af -eq 6 ];then
tables=ip6tables tables=ip6tables
fi fi
local counters values
counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP) counters=$(ip netns exec $ns $tables -v -L OUTPUT | grep DROP)
values=${counters%DROP*} values=${counters%DROP*}
local v
for v in $values; do for v in $values; do
if [ $v -ne 0 ]; then if [ $v -ne 0 ]; then
echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2 echo "FAIL: got $tables $values in ns $ns , not 0 - not all expected packets marked" 1>&2
...@@ -131,9 +137,9 @@ print_file_err() ...@@ -131,9 +137,9 @@ print_file_err()
check_transfer() check_transfer()
{ {
in=$1 local in=$1
out=$2 local out=$2
what=$3 local what=$3
cmp "$in" "$out" > /dev/null 2>&1 cmp "$in" "$out" > /dev/null 2>&1
if [ $? -ne 0 ] ;then if [ $? -ne 0 ] ;then
...@@ -156,18 +162,18 @@ is_v6() ...@@ -156,18 +162,18 @@ is_v6()
do_transfer() do_transfer()
{ {
listener_ns="$1" local listener_ns="$1"
connector_ns="$2" local connector_ns="$2"
cl_proto="$3" local cl_proto="$3"
srv_proto="$4" local srv_proto="$4"
connect_addr="$5" local connect_addr="$5"
port=12001 local port=12001
:> "$cout" :> "$cout"
:> "$sout" :> "$sout"
mptcp_connect="./mptcp_connect -r 20" local mptcp_connect="./mptcp_connect -r 20"
local local_addr local local_addr
if is_v6 "${connect_addr}"; then if is_v6 "${connect_addr}"; then
...@@ -180,7 +186,7 @@ do_transfer() ...@@ -180,7 +186,7 @@ do_transfer()
ip netns exec ${listener_ns} \ ip netns exec ${listener_ns} \
$mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \ $mptcp_connect -t ${timeout_poll} -l -M 1 -p $port -s ${srv_proto} -c TIMESTAMPNS,TCPINQ \
${local_addr} < "$sin" > "$sout" & ${local_addr} < "$sin" > "$sout" &
spid=$! local spid=$!
sleep 1 sleep 1
...@@ -189,12 +195,12 @@ do_transfer() ...@@ -189,12 +195,12 @@ do_transfer()
$mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \ $mptcp_connect -t ${timeout_poll} -M 2 -p $port -s ${cl_proto} -c TIMESTAMPNS,TCPINQ \
$connect_addr < "$cin" > "$cout" & $connect_addr < "$cin" > "$cout" &
cpid=$! local cpid=$!
wait $cpid wait $cpid
retc=$? local retc=$?
wait $spid wait $spid
rets=$? local rets=$?
if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then if [ ${rets} -ne 0 ] || [ ${retc} -ne 0 ]; then
echo " client exit code $retc, server $rets" 1>&2 echo " client exit code $retc, server $rets" 1>&2
...@@ -229,9 +235,9 @@ do_transfer() ...@@ -229,9 +235,9 @@ do_transfer()
make_file() make_file()
{ {
name=$1 local name=$1
who=$2 local who=$2
size=$3 local size=$3
dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null dd if=/dev/urandom of="$name" bs=1024 count=$size 2> /dev/null
echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name" echo -e "\nMPTCP_TEST_FILE_END_MARKER" >> "$name"
...@@ -264,9 +270,9 @@ do_mptcp_sockopt_tests() ...@@ -264,9 +270,9 @@ do_mptcp_sockopt_tests()
run_tests() run_tests()
{ {
listener_ns="$1" local listener_ns="$1"
connector_ns="$2" local connector_ns="$2"
connect_addr="$3" local connect_addr="$3"
local lret=0 local lret=0
do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr} do_transfer ${listener_ns} ${connector_ns} MPTCP MPTCP ${connect_addr}
...@@ -282,7 +288,7 @@ run_tests() ...@@ -282,7 +288,7 @@ run_tests()
do_tcpinq_test() do_tcpinq_test()
{ {
ip netns exec "$ns_sbox" ./mptcp_inq "$@" ip netns exec "$ns_sbox" ./mptcp_inq "$@"
lret=$? local lret=$?
if [ $lret -ne 0 ];then if [ $lret -ne 0 ];then
ret=$lret ret=$lret
echo "FAIL: mptcp_inq $@" 1>&2 echo "FAIL: mptcp_inq $@" 1>&2
...@@ -297,6 +303,7 @@ do_tcpinq_tests() ...@@ -297,6 +303,7 @@ do_tcpinq_tests()
{ {
local lret=0 local lret=0
local args
for args in "-t tcp" "-r tcp"; do for args in "-t tcp" "-r tcp"; do
do_tcpinq_test $args do_tcpinq_test $args
lret=$? lret=$?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment