[LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct

Richard Palethorpe rpalethorpe@suse.de
Tue Mar 7 13:59:43 CET 2023


Hello,

Petr Vorel <pvorel@suse.cz> writes:

> net.ipv6.conf.all.disable_ipv6=1 disables IPv6 on all interfaces
> (including both already created and later created).
>
> The check prevent failures on IPv6 tests, and error messages on both
> IPv4 and IPv4 tests:
>
>     # sysctl -w net.ipv6.conf.all.disable_ipv6=1
>     # ./ping02.sh -6
>     ping02 1 TINFO: tst_rhost_run: cmd: [ -f /proc/net/if_inet6 ]
>     ping02 1 TINFO: NETNS: sh -c " [ -f /proc/net/if_inet6 ] || echo RTERR" 2>&1
>     ping02 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
>     ping02 1 TINFO: add local addr 10.0.0.2/24
>     ping02 1 TINFO: add local addr fd00:1:1:1::2/64
>     RTNETLINK answers: Permission denied
>     ping02 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
>     ...
>     ping02 1 TINFO: timeout per run is 0h 5m 0s
>     ping6: connect: Network is unreachable
>     ping02 1 TFAIL: ping6 -I ltp_ns_veth2 -c 3 -s 8 -f -p 000102030405060708090a0b0c0d0e0f fd00:1:1:1::1 >/dev/null failed unexpectedly
>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>

Acked-by: Richard Palethorpe <rpalethorpe@suse.com>

> ---
>  testcases/lib/tst_net.sh | 26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index fc64a588ae..96eed50793 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -84,25 +84,41 @@ tst_brk_()
>  	[ -z "$TST_USE_LEGACY_API" ] && tst_brk $@ || tst_brkm $@
>  }
>  
> +# Detect IPv6 disabled via ipv6.disable=1 kernel cmdline parameter
> +# or sysctl net.ipv6.conf.all.disable_ipv6=1 (disables IPv6 on all
> +# interfaces (including both already created and later created).
> +# $TST_NET_IPV6_ENABLED: 1 on IPv6 enabled, 0 on IPv6 disabled.
>  tst_net_detect_ipv6()
>  {
>  	local type="${1:-lhost}"
>  	local cmd='[ -f /proc/net/if_inet6 ]'
> -	local ret
> +	local disabled iface ret
>  
>  	if [ "$type" = "lhost" ]; then
>  		$cmd
>  	else
>  		tst_rhost_run -c "$cmd"
>  	fi
> -	ret=$?
>  
> -	if [ $ret -eq 0 ]; then
> -		TST_NET_IPV6_ENABLED=1
> +	if [ $? -ne 0 ]; then
> +		TST_NET_IPV6_ENABLED=0
> +		tst_res_ TINFO "IPv6 disabled on $type via ipv6.disable=1"
> +		return
> +	fi
> +
> +	cmd='sysctl -n net.ipv6.conf.all.disable_ipv6'
> +	if [ "$type" = "lhost" ]; then
> +		disabled=$($cmd)
>  	else
> +		disabled=$(tst_rhost_run -c "$cmd")
> +	fi
> +	if [ $disabled = 1 ]; then
> +		tst_res_ TINFO "IPv6 disabled on $type net.ipv6.conf.all.disable_ipv6=1"
>  		TST_NET_IPV6_ENABLED=0
> -		tst_res_ TINFO "IPv6 disabled on $type"
> +		return
>  	fi
> +
> +	TST_NET_IPV6_ENABLED=1
>  }
>  
>  tst_net_require_ipv6()
> -- 
> 2.39.1


-- 
Thank you,
Richard.


More information about the ltp mailing list