[LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
Cyril Hrubis
chrubis@suse.cz
Wed Mar 22 14:08:15 CET 2023
Hi!
> 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>
> ---
> 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"
Doesn't this happen also in the unlikely case that CONFIG_IPV6 is not
set?
So maybe "IPv6 disabled on kernel commandline or not compiled in"
> + return
> + fi
> +
> + cmd='sysctl -n net.ipv6.conf.all.disable_ipv6'
I'm not sure why we should use sysctl when this the same as doing
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
Or is there any added value from the sysctl command?
> + 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
>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list