Message ID | 20230217151036.10295-2-pvorel@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | tst_net.sh IPv6 sysctl fixes | expand |
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
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 >
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
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
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
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
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()
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(-)