Commit b850f2c7 authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

selftests: mptcp: add mptcp_lib_is_v6

To avoid duplicated code in different MPTCP selftests, we can add
and use helpers defined in mptcp_lib.sh.

is_v6() helper is defined in mptcp_connect.sh, mptcp_join.sh and
mptcp_sockopt.sh, so export it into mptcp_lib.sh and rename it as
mptcp_lib_is_v6(). Use this new helper in all scripts.
Reviewed-by: default avatarMatthieu Baerts <matttbe@kernel.org>
Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
Signed-off-by: default avatarMat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-10-8d6b94150f6b@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bdbef0a6
...@@ -310,12 +310,6 @@ check_mptcp_disabled() ...@@ -310,12 +310,6 @@ check_mptcp_disabled()
return 0 return 0
} }
# $1: IP address
is_v6()
{
[ -z "${1##*:*}" ]
}
do_ping() do_ping()
{ {
local listener_ns="$1" local listener_ns="$1"
...@@ -324,7 +318,7 @@ do_ping() ...@@ -324,7 +318,7 @@ do_ping()
local ping_args="-q -c 1" local ping_args="-q -c 1"
local rc=0 local rc=0
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
$ipv6 || return 0 $ipv6 || return 0
ping_args="${ping_args} -6" ping_args="${ping_args} -6"
fi fi
...@@ -635,12 +629,12 @@ run_tests_lo() ...@@ -635,12 +629,12 @@ run_tests_lo()
fi fi
# skip if we don't want v6 # skip if we don't want v6
if ! $ipv6 && is_v6 "${connect_addr}"; then if ! $ipv6 && mptcp_lib_is_v6 "${connect_addr}"; then
return 0 return 0
fi fi
local local_addr local local_addr
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
local_addr="::" local_addr="::"
else else
local_addr="0.0.0.0" local_addr="0.0.0.0"
...@@ -708,7 +702,7 @@ run_test_transparent() ...@@ -708,7 +702,7 @@ run_test_transparent()
TEST_GROUP="${msg}" TEST_GROUP="${msg}"
# skip if we don't want v6 # skip if we don't want v6
if ! $ipv6 && is_v6 "${connect_addr}"; then if ! $ipv6 && mptcp_lib_is_v6 "${connect_addr}"; then
return 0 return 0
fi fi
...@@ -741,7 +735,7 @@ EOF ...@@ -741,7 +735,7 @@ EOF
fi fi
local local_addr local local_addr
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
local_addr="::" local_addr="::"
r6flag="-6" r6flag="-6"
else else
......
...@@ -587,12 +587,6 @@ link_failure() ...@@ -587,12 +587,6 @@ link_failure()
done done
} }
# $1: IP address
is_v6()
{
[ -z "${1##*:*}" ]
}
# $1: ns, $2: port # $1: ns, $2: port
wait_local_port_listen() wait_local_port_listen()
{ {
...@@ -895,7 +889,7 @@ pm_nl_set_endpoint() ...@@ -895,7 +889,7 @@ pm_nl_set_endpoint()
local id=10 local id=10
while [ $add_nr_ns1 -gt 0 ]; do while [ $add_nr_ns1 -gt 0 ]; do
local addr local addr
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
addr="dead:beef:$counter::1" addr="dead:beef:$counter::1"
else else
addr="10.0.$counter.1" addr="10.0.$counter.1"
...@@ -947,7 +941,7 @@ pm_nl_set_endpoint() ...@@ -947,7 +941,7 @@ pm_nl_set_endpoint()
local id=20 local id=20
while [ $add_nr_ns2 -gt 0 ]; do while [ $add_nr_ns2 -gt 0 ]; do
local addr local addr
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
addr="dead:beef:$counter::2" addr="dead:beef:$counter::2"
else else
addr="10.0.$counter.2" addr="10.0.$counter.2"
...@@ -989,7 +983,7 @@ pm_nl_set_endpoint() ...@@ -989,7 +983,7 @@ pm_nl_set_endpoint()
pm_nl_flush_endpoint ${connector_ns} pm_nl_flush_endpoint ${connector_ns}
elif [ $rm_nr_ns2 -eq 9 ]; then elif [ $rm_nr_ns2 -eq 9 ]; then
local addr local addr
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
addr="dead:beef:1::2" addr="dead:beef:1::2"
else else
addr="10.0.1.2" addr="10.0.1.2"
...@@ -3357,7 +3351,7 @@ userspace_pm_rm_sf() ...@@ -3357,7 +3351,7 @@ userspace_pm_rm_sf()
local cnt local cnt
[ "$1" == "$ns2" ] && evts=$evts_ns2 [ "$1" == "$ns2" ] && evts=$evts_ns2
if is_v6 $2; then ip=6; fi if mptcp_lib_is_v6 $2; then ip=6; fi
tk=$(mptcp_lib_evts_get_info token "$evts") tk=$(mptcp_lib_evts_get_info token "$evts")
da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t) da=$(mptcp_lib_evts_get_info "daddr$ip" "$evts" $t)
dp=$(mptcp_lib_evts_get_info dport "$evts" $t) dp=$(mptcp_lib_evts_get_info dport "$evts" $t)
......
...@@ -226,3 +226,8 @@ mptcp_lib_kill_wait() { ...@@ -226,3 +226,8 @@ mptcp_lib_kill_wait() {
kill "${1}" > /dev/null 2>&1 kill "${1}" > /dev/null 2>&1
wait "${1}" 2>/dev/null wait "${1}" 2>/dev/null
} }
# $1: IP address
mptcp_lib_is_v6() {
[ -z "${1##*:*}" ]
}
...@@ -161,12 +161,6 @@ check_transfer() ...@@ -161,12 +161,6 @@ check_transfer()
return 0 return 0
} }
# $1: IP address
is_v6()
{
[ -z "${1##*:*}" ]
}
do_transfer() do_transfer()
{ {
local listener_ns="$1" local listener_ns="$1"
...@@ -183,7 +177,7 @@ do_transfer() ...@@ -183,7 +177,7 @@ do_transfer()
local mptcp_connect="./mptcp_connect -r 20" local mptcp_connect="./mptcp_connect -r 20"
local local_addr ip local local_addr ip
if is_v6 "${connect_addr}"; then if mptcp_lib_is_v6 "${connect_addr}"; then
local_addr="::" local_addr="::"
ip=ipv6 ip=ipv6
else else
......
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