public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: Martin Doucha <martin.doucha@suse.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 1/3] tst_net.sh: Fix for disabled IPv6
Date: Tue, 10 May 2022 14:14:18 +0200	[thread overview]
Message-ID: <YnpXGnJyjjZhxuRN@yuki> (raw)
In-Reply-To: <20220510065104.1199-2-pvorel@suse.cz>

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-05-10 12:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10  6:51 [LTP] [PATCH v3 0/3] shell: Fixes for disabled IPv6 Petr Vorel
2022-05-10  6:51 ` [LTP] [PATCH v3 1/3] tst_net.sh: Fix " Petr Vorel
2022-05-10 12:14   ` Cyril Hrubis [this message]
2022-05-10 13:06     ` Petr Vorel
2022-05-10 13:21       ` Cyril Hrubis
2022-05-10 14:04         ` Petr Vorel
2022-05-10  6:51 ` [LTP] [PATCH v3 2/3] netns: Rewrite to use tst_net.sh Petr Vorel
2022-05-10 13:08   ` Cyril Hrubis
2022-05-10 14:00     ` Petr Vorel
2022-05-10  6:51 ` [LTP] [PATCH v3 3/3] netns: Rename netns_helper.sh -> netns_lib.sh Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YnpXGnJyjjZhxuRN@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=martin.doucha@suse.com \
    --cc=pvorel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox