[LTP] [PATCH v2 1/3] tst_net.sh: Fix for disabled IPv6
Cyril Hrubis
chrubis@suse.cz
Wed Mar 2 12:00:59 CET 2022
Hi!
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/lib/tst_net.sh | 71 +++++++++++++++++++++++++++++++++-------
> 1 file changed, 60 insertions(+), 11 deletions(-)
>
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index 047686dc39..15fd595942 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -24,7 +24,9 @@ TST_IPV6_FLAG=${TST_IPV6_FLAG:-}
> tst_net_parse_args()
> {
> case $1 in
> - 6) TST_IPV6=6 TST_IPVER=6 TST_IPV6_FLAG="-6";;
> + 6) tst_net_require_ipv6
> + TST_IPV6=6 TST_IPVER=6 TST_IPV6_FLAG="-6"
> + ;;
> *) [ "$TST_PARSE_ARGS_CALLER" ] && $TST_PARSE_ARGS_CALLER "$1" "$2";;
> esac
> }
> @@ -100,6 +102,32 @@ tst_brk_()
> [ -z "$TST_USE_LEGACY_API" ] && tst_brk $@ || tst_brkm $@
> }
>
> +
> +tst_net_detect_ipv6()
> +{
> + local type="${1:-lhost}"
> + local cmd='[ -f /proc/net/if_inet6 ]'
> + local ret
> +
> + if [ "$type" = "lhost" ]; then
> + $cmd
> + else
> + tst_rhost_run -c "$cmd"
> + fi
> + ret=$?
> +
> + if [ $ret -eq 0 ]; then
> + TST_NET_IPV6_ENABLED=1
> + else
> + tst_res TINFO "IPv6 disabled on $type"
> + fi
> +}
> +
> +tst_net_require_ipv6()
> +{
> + [ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
> +}
Shouldn't we detect support for IPv6 on both lhost and rhost in the
tst_net_detect_ipv6() function? I would say that it's pretty obvious
that we need the support on both machines.
> init_ltp_netspace()
> {
> local pid
> @@ -517,7 +545,9 @@ tst_init_iface()
> ip link set $iface down || return $?
> ip route flush dev $iface || return $?
> ip addr flush dev $iface || return $?
> - sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
> + fi
> ip link set $iface up
> return $?
> fi
> @@ -529,7 +559,9 @@ tst_init_iface()
> tst_rhost_run -c "ip link set $iface down" || return $?
> tst_rhost_run -c "ip route flush dev $iface" || return $?
> tst_rhost_run -c "ip addr flush dev $iface" || return $?
> - tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
> + fi
> tst_rhost_run -c "ip link set $iface up"
> }
>
> @@ -606,7 +638,9 @@ tst_restore_ipaddr()
> local ret=0
> local backup_tst_ipv6=$TST_IPV6
> TST_IPV6= tst_add_ipaddr $type $link_num || ret=$?
> - TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$?
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$?
> + fi
> TST_IPV6=$backup_tst_ipv6
>
> return $ret
> @@ -937,6 +971,9 @@ tst_default_max_pkt()
> echo "$((mtu + mtu / 10))"
> }
>
> +# detect IPv6 support on lhost for tests which don't use test links
> +tst_net_detect_ipv6
> +
> [ -n "$TST_PRINT_HELP" -o -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
>
> # Management Link
> @@ -971,8 +1008,13 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
> if [ -z "$_tst_net_parse_variables" ]; then
> eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
> eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
> - eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
> - eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
> +
> + tst_net_detect_ipv6 rhost
> +
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
> + eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
> + fi
> fi
>
> [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
> @@ -981,19 +1023,26 @@ if [ -z "$_tst_net_parse_variables" ]; then
> eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
> eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
> || echo "exit $?")
> - eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
> - eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
> - || echo "exit $?")
> +
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
> + eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
> + || echo "exit $?")
> + fi
>
> eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX \
> $IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
> - eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
> - $IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
> +
> + if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> + eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
> + $IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
> + fi
>
> tst_res_ TINFO "Network config (local -- remote):"
> tst_res_ TINFO "$LHOST_IFACES -- $RHOST_IFACES"
> tst_res_ TINFO "$IPV4_LHOST/$IPV4_LPREFIX -- $IPV4_RHOST/$IPV4_RPREFIX"
> tst_res_ TINFO "$IPV6_LHOST/$IPV6_LPREFIX -- $IPV6_RHOST/$IPV6_RPREFIX"
> +
> export _tst_net_parse_variables="yes"
> fi
>
> --
> 2.35.1
>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list