ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/2] tst_net.sh IPv6 sysctl fixes
@ 2023-02-17 15:10 Petr Vorel
  2023-02-17 15:10 ` [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct Petr Vorel
  2023-02-17 15:10 ` [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl Petr Vorel
  0 siblings, 2 replies; 11+ messages in thread
From: Petr Vorel @ 2023-02-17 15:10 UTC (permalink / raw)
  To: ltp

NOTE: previous version:
[PATCH 8/9] tst_net.sh: Harden on disabled IPv6 via sysctl
https://lore.kernel.org/ltp/20230126215401.29101-9-pvorel@suse.cz/

Changes v1->v2:
* add check for net.ipv6.conf.all.disable_ipv6=1 (first commit)
* add net.ipv6.conf.$iface.disable_ipv6=1 check also to tst_add_ipaddr

Petr Vorel (2):
  tst_net.sh: Detect IPv6 disabled via sysct
  tst_net.sh: Detect IPv6 disabled on interface via sysctl

 testcases/lib/tst_net.sh | 72 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 5 deletions(-)

-- 
2.39.1


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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-02-17 15:10 [LTP] [PATCH v2 0/2] tst_net.sh IPv6 sysctl fixes Petr Vorel
@ 2023-02-17 15:10 ` Petr Vorel
  2023-03-07 12:59   ` Richard Palethorpe
  2023-03-22 13:08   ` Cyril Hrubis
  2023-02-17 15:10 ` [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl Petr Vorel
  1 sibling, 2 replies; 11+ messages in thread
From: Petr Vorel @ 2023-02-17 15:10 UTC (permalink / raw)
  To: ltp

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"
+		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


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl
  2023-02-17 15:10 [LTP] [PATCH v2 0/2] tst_net.sh IPv6 sysctl fixes Petr Vorel
  2023-02-17 15:10 ` [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct Petr Vorel
@ 2023-02-17 15:10 ` Petr Vorel
  2023-03-07 13:01   ` Richard Palethorpe
  2023-03-22 13:10   ` Cyril Hrubis
  1 sibling, 2 replies; 11+ messages in thread
From: Petr Vorel @ 2023-02-17 15:10 UTC (permalink / raw)
  To: ltp

IPv6 on interface can be also disabled by sysctl
net.ipv6.conf.$iface.disable_ipv6=1. This is better to be checked:
* for all interfaces before run (can be disabled even for netns
  interface previously created).
* before ip addr command tries to work with IPv6 (in tst_init_iface()
  and tst_add_ipaddr(), other functions should run these before)

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_net.sh | 46 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index 96eed50793..f414dd9359 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -121,6 +121,47 @@ tst_net_detect_ipv6()
 	TST_NET_IPV6_ENABLED=1
 }
 
+# Detect IPv6 disabled on interface via sysctl
+# net.ipv6.conf.$iface.disable_ipv6=1.
+# $TST_NET_IPV6_ENABLED: 1 on IPv6 enabled, 0 on IPv6 disabled.
+# return: 0 on IPv6 enabled, 1 on IPv6 disabled.
+tst_net_detect_ipv6_iface()
+{
+	[ "$TST_NET_IPV6_ENABLED" = 1 ] || return 1
+
+	local iface="$1"
+	local type="${2:-lhost}"
+	local check="sysctl -n net.ipv6.conf.$iface.disable_ipv6"
+	local disabled
+
+	if [ "$type" = "lhost" ]; then
+		disabled=$($check)
+	else
+		disabled=$(tst_rhost_run -c "$check")
+	fi
+	if [ $disabled = 1 ]; then
+		tst_res_ TINFO "IPv6 disabled on $type on $iface"
+		TST_NET_IPV6_ENABLED=0
+		return 1
+	fi
+
+	return 0
+}
+
+# Detect IPv6 disabled on used interfaces.
+tst_net_check_ifaces_ipv6()
+{
+	local iface
+
+	for iface in $(tst_get_ifaces); do
+		tst_net_detect_ipv6_iface || return
+	done
+
+	for iface in $(tst_get_ifaces rhost); do
+		tst_net_detect_ipv6_iface $iface rhost || return
+	done
+}
+
 tst_net_require_ipv6()
 {
 	[ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
@@ -531,7 +572,9 @@ tst_init_iface()
 	local type="${1:-lhost}"
 	local link_num="${2:-0}"
 	local iface="$(tst_iface $type $link_num)"
+
 	tst_res_ TINFO "initialize '$type' '$iface' interface"
+	tst_net_detect_ipv6_iface $iface $type
 
 	if [ "$type" = "lhost" ]; then
 		if ip xfrm state 1>/dev/null 2>&1; then
@@ -591,6 +634,8 @@ tst_add_ipaddr()
 	local link_num="${2:-0}"
 	local iface=$(tst_iface $type $link_num)
 
+	tst_net_detect_ipv6_iface $iface $type
+
 	if [ "$TST_IPV6" ]; then
 		dad="nodad"
 		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
@@ -1005,6 +1050,7 @@ tst_net_setup_network()
 		$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
 
 	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		tst_net_check_ifaces_ipv6
 		eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
 		eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
 			|| echo "exit $?")
-- 
2.39.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-02-17 15:10 ` [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct Petr Vorel
@ 2023-03-07 12:59   ` Richard Palethorpe
  2023-03-22 13:08   ` Cyril Hrubis
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2023-03-07 12:59 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

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.

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl
  2023-02-17 15:10 ` [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl Petr Vorel
@ 2023-03-07 13:01   ` Richard Palethorpe
  2023-03-22 13:10   ` Cyril Hrubis
  1 sibling, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2023-03-07 13:01 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp


Petr Vorel <pvorel@suse.cz> writes:

> IPv6 on interface can be also disabled by sysctl
> net.ipv6.conf.$iface.disable_ipv6=1. This is better to be checked:
> * for all interfaces before run (can be disabled even for netns
>   interface previously created).
> * before ip addr command tries to work with IPv6 (in tst_init_iface()
>   and tst_add_ipaddr(), other functions should run these before)
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>

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

> ---
>  testcases/lib/tst_net.sh | 46 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index 96eed50793..f414dd9359 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -121,6 +121,47 @@ tst_net_detect_ipv6()
>  	TST_NET_IPV6_ENABLED=1
>  }
>  
> +# Detect IPv6 disabled on interface via sysctl
> +# net.ipv6.conf.$iface.disable_ipv6=1.
> +# $TST_NET_IPV6_ENABLED: 1 on IPv6 enabled, 0 on IPv6 disabled.
> +# return: 0 on IPv6 enabled, 1 on IPv6 disabled.
> +tst_net_detect_ipv6_iface()
> +{
> +	[ "$TST_NET_IPV6_ENABLED" = 1 ] || return 1
> +
> +	local iface="$1"
> +	local type="${2:-lhost}"
> +	local check="sysctl -n net.ipv6.conf.$iface.disable_ipv6"
> +	local disabled
> +
> +	if [ "$type" = "lhost" ]; then
> +		disabled=$($check)
> +	else
> +		disabled=$(tst_rhost_run -c "$check")
> +	fi
> +	if [ $disabled = 1 ]; then
> +		tst_res_ TINFO "IPv6 disabled on $type on $iface"
> +		TST_NET_IPV6_ENABLED=0
> +		return 1
> +	fi
> +
> +	return 0
> +}
> +
> +# Detect IPv6 disabled on used interfaces.
> +tst_net_check_ifaces_ipv6()
> +{
> +	local iface
> +
> +	for iface in $(tst_get_ifaces); do
> +		tst_net_detect_ipv6_iface || return
> +	done
> +
> +	for iface in $(tst_get_ifaces rhost); do
> +		tst_net_detect_ipv6_iface $iface rhost || return
> +	done
> +}
> +
>  tst_net_require_ipv6()
>  {
>  	[ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
> @@ -531,7 +572,9 @@ tst_init_iface()
>  	local type="${1:-lhost}"
>  	local link_num="${2:-0}"
>  	local iface="$(tst_iface $type $link_num)"
> +
>  	tst_res_ TINFO "initialize '$type' '$iface' interface"
> +	tst_net_detect_ipv6_iface $iface $type
>  
>  	if [ "$type" = "lhost" ]; then
>  		if ip xfrm state 1>/dev/null 2>&1; then
> @@ -591,6 +634,8 @@ tst_add_ipaddr()
>  	local link_num="${2:-0}"
>  	local iface=$(tst_iface $type $link_num)
>  
> +	tst_net_detect_ipv6_iface $iface $type
> +
>  	if [ "$TST_IPV6" ]; then
>  		dad="nodad"
>  		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
> @@ -1005,6 +1050,7 @@ tst_net_setup_network()
>  		$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
>  
>  	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> +		tst_net_check_ifaces_ipv6
>  		eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
>  		eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
>  			|| echo "exit $?")
> -- 
> 2.39.1


-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-02-17 15:10 ` [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct Petr Vorel
  2023-03-07 12:59   ` Richard Palethorpe
@ 2023-03-22 13:08   ` Cyril Hrubis
  2023-03-22 16:20     ` Petr Vorel
  1 sibling, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2023-03-22 13:08 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

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

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl
  2023-02-17 15:10 ` [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl Petr Vorel
  2023-03-07 13:01   ` Richard Palethorpe
@ 2023-03-22 13:10   ` Cyril Hrubis
  1 sibling, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2023-03-22 13:10 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> IPv6 on interface can be also disabled by sysctl
> net.ipv6.conf.$iface.disable_ipv6=1. This is better to be checked:
> * for all interfaces before run (can be disabled even for netns
>   interface previously created).
> * before ip addr command tries to work with IPv6 (in tst_init_iface()
>   and tst_add_ipaddr(), other functions should run these before)
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_net.sh | 46 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index 96eed50793..f414dd9359 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -121,6 +121,47 @@ tst_net_detect_ipv6()
>  	TST_NET_IPV6_ENABLED=1
>  }
>  
> +# Detect IPv6 disabled on interface via sysctl
> +# net.ipv6.conf.$iface.disable_ipv6=1.
> +# $TST_NET_IPV6_ENABLED: 1 on IPv6 enabled, 0 on IPv6 disabled.
> +# return: 0 on IPv6 enabled, 1 on IPv6 disabled.
> +tst_net_detect_ipv6_iface()
> +{
> +	[ "$TST_NET_IPV6_ENABLED" = 1 ] || return 1
> +
> +	local iface="$1"
> +	local type="${2:-lhost}"
> +	local check="sysctl -n net.ipv6.conf.$iface.disable_ipv6"

Here as well.

> +	local disabled
> +
> +	if [ "$type" = "lhost" ]; then
> +		disabled=$($check)
> +	else
> +		disabled=$(tst_rhost_run -c "$check")
> +	fi
> +	if [ $disabled = 1 ]; then
> +		tst_res_ TINFO "IPv6 disabled on $type on $iface"
> +		TST_NET_IPV6_ENABLED=0
> +		return 1
> +	fi
> +
> +	return 0
> +}
> +
> +# Detect IPv6 disabled on used interfaces.
> +tst_net_check_ifaces_ipv6()
> +{
> +	local iface
> +
> +	for iface in $(tst_get_ifaces); do
> +		tst_net_detect_ipv6_iface || return
                                          ^
					  $iface
> +	done
> +
> +	for iface in $(tst_get_ifaces rhost); do
> +		tst_net_detect_ipv6_iface $iface rhost || return
> +	done
> +}
> +
>  tst_net_require_ipv6()
>  {
>  	[ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
> @@ -531,7 +572,9 @@ tst_init_iface()
>  	local type="${1:-lhost}"
>  	local link_num="${2:-0}"
>  	local iface="$(tst_iface $type $link_num)"
> +
>  	tst_res_ TINFO "initialize '$type' '$iface' interface"
> +	tst_net_detect_ipv6_iface $iface $type
>  
>  	if [ "$type" = "lhost" ]; then
>  		if ip xfrm state 1>/dev/null 2>&1; then
> @@ -591,6 +634,8 @@ tst_add_ipaddr()
>  	local link_num="${2:-0}"
>  	local iface=$(tst_iface $type $link_num)
>  
> +	tst_net_detect_ipv6_iface $iface $type
> +
>  	if [ "$TST_IPV6" ]; then
>  		dad="nodad"
>  		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
> @@ -1005,6 +1050,7 @@ tst_net_setup_network()
>  		$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
>  
>  	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
> +		tst_net_check_ifaces_ipv6
>  		eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
>  		eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
>  			|| echo "exit $?")
> -- 
> 2.39.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-03-22 13:08   ` Cyril Hrubis
@ 2023-03-22 16:20     ` Petr Vorel
  2023-03-22 16:35       ` Petr Vorel
  2023-03-22 16:35       ` Cyril Hrubis
  0 siblings, 2 replies; 11+ messages in thread
From: Petr Vorel @ 2023-03-22 16:20 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

...
> > +	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"
Indeed, You're right, I'll use (to show where it was disabled):

tst_res_ TINFO "IPv6 disabled on $type via kernel command line 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?

No, but we already use sysctl in tst_init_iface():
sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?

and we don't check for sysctl (expecting is everywhere). I'd also allow using
sysctl (and then add a check via tst_require_cmds) or change also these with
cat for reading and echo ... > for writing. WDYT?

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-03-22 16:20     ` Petr Vorel
@ 2023-03-22 16:35       ` Petr Vorel
  2023-03-22 16:35       ` Cyril Hrubis
  1 sibling, 0 replies; 11+ messages in thread
From: Petr Vorel @ 2023-03-22 16:35 UTC (permalink / raw)
  To: Cyril Hrubis, ltp

Hi Cyril,

> > > +	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?

> No, but we already use sysctl in tst_init_iface():
> sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
> tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?

> and we don't check for sysctl (expecting is everywhere). I'd also allow using
> sysctl (and then add a check via tst_require_cmds) or change also these with
> cat for reading and echo ... > for writing. WDYT?

BTW tst_set_sysctl() and it's use would need to be rewritten to get benefit of
getting rid of using sysctl. But I can use cat in this case to not extending
sysctl dependency.

Kind regards,
Petr

> Kind regards,
> Petr

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-03-22 16:20     ` Petr Vorel
  2023-03-22 16:35       ` Petr Vorel
@ 2023-03-22 16:35       ` Cyril Hrubis
  2023-03-23  5:17         ` Petr Vorel
  1 sibling, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2023-03-22 16:35 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> No, but we already use sysctl in tst_init_iface():
> sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
> tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
>
> and we don't check for sysctl (expecting is everywhere). I'd also allow using
> sysctl (and then add a check via tst_require_cmds) or change also these with
> cat for reading and echo ... > for writing. WDYT?

I would say that sysctl is useful when you have a config file with a
bunch of values to be changed, but I would avoid using it in scripts,
because all it does in that cases to perepend the proc part of the path
and converts dots into slashes. And sometimes, when a path component
contains a dot, it fails to replace the right dots into slashes too:

http://lists.busybox.net/pipermail/busybox-cvs/2008-October/028382.html

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct
  2023-03-22 16:35       ` Cyril Hrubis
@ 2023-03-23  5:17         ` Petr Vorel
  0 siblings, 0 replies; 11+ messages in thread
From: Petr Vorel @ 2023-03-23  5:17 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

> Hi!
> > No, but we already use sysctl in tst_init_iface():
> > sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
> > tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?

> > and we don't check for sysctl (expecting is everywhere). I'd also allow using
> > sysctl (and then add a check via tst_require_cmds) or change also these with
> > cat for reading and echo ... > for writing. WDYT?

> I would say that sysctl is useful when you have a config file with a
> bunch of values to be changed, but I would avoid using it in scripts,
> because all it does in that cases to perepend the proc part of the path
> and converts dots into slashes. And sometimes, when a path component
> contains a dot, it fails to replace the right dots into slashes too:

> http://lists.busybox.net/pipermail/busybox-cvs/2008-October/028382.html

Well, bug from 2008 (fixed in svn, probably that year). But I agree that
it's better to get rid of sysctl. I'll use cat here and prepare fix for the rest
of tst_net.sh sysctl usage.

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-03-23  5:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17 15:10 [LTP] [PATCH v2 0/2] tst_net.sh IPv6 sysctl fixes Petr Vorel
2023-02-17 15:10 ` [LTP] [PATCH v2 1/2] tst_net.sh: Detect IPv6 disabled via sysct Petr Vorel
2023-03-07 12:59   ` Richard Palethorpe
2023-03-22 13:08   ` Cyril Hrubis
2023-03-22 16:20     ` Petr Vorel
2023-03-22 16:35       ` Petr Vorel
2023-03-22 16:35       ` Cyril Hrubis
2023-03-23  5:17         ` Petr Vorel
2023-02-17 15:10 ` [LTP] [PATCH v2 2/2] tst_net.sh: Detect IPv6 disabled on interface via sysctl Petr Vorel
2023-03-07 13:01   ` Richard Palethorpe
2023-03-22 13:10   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).