[LTP] [PATCH v3 1/3] tst_net.sh: Fix for disabled IPv6
Cyril Hrubis
chrubis@suse.cz
Tue May 10 14:14:18 CEST 2022
Hi!
> +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"
> +}
> +
> init_ltp_netspace()
> {
> local pid
> @@ -515,7 +542,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
> @@ -527,7 +556,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"
> }
>
> @@ -604,7 +635,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
> @@ -936,6 +969,10 @@ tst_default_max_pkt()
> }
>
> [ -n "$TST_USE_LEGACY_API" ] && . test.sh || . tst_test.sh
> +
> +# detect IPv6 support on lhost for tests which don't use test links
> +tst_net_detect_ipv6
> +
> [ -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
>
> # Management Link
> @@ -970,8 +1007,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
If I'm looking right at this piece of code we do run the
tst_net_detect_ipv6 twice once for lhost and once for rhost when the
script is sourced and we only set the TST_NET_IPV6_ENABLED when the
check succeeds, right?
Shouldn't we also unset it when the check fails because otherwise the
check for rhost is basically no-op as long as the lhost supports ipv6?
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list