From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 8/9] tst_net.sh: Harden on disabled IPv6 via sysctl
Date: Thu, 26 Jan 2023 22:54:00 +0100 [thread overview]
Message-ID: <20230126215401.29101-9-pvorel@suse.cz> (raw)
In-Reply-To: <20230126215401.29101-1-pvorel@suse.cz>
Detect IPv6 can be disabled via sysctl (for both netns or on ssh based
links) and tests than fails:
# sysctl net.ipv6.conf.ltp_ns_veth2.disable_ipv6=1
# TST_NET_RHOST_RUN_DEBUG=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
Therefore detect IPv6 disabled via sysctl:
1) tst_init_iface - to avoid setting net.ipv6.conf.$iface.accept_dad=0.
tst_init_iface is called by tst_restore_ipaddr, which is called by
init_ltp_netspace (netns) at the start of testing.
2) For ssh are all devices tested at the start.
There are guards in both functions to avoid repeated checks (e.g.
tst_restore_ipaddr() it's also cleanup function for some tests therefore
called by both netns and ssh).
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/lib/tst_net.sh | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index 518a3ed579..7ee8594a54 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -126,6 +126,43 @@ tst_net_require_ipv6()
[ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
}
+# Detect IPv6 disabled via sysctl.
+tst_net_detect_ipv6_sysctl()
+{
+ [ "$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
+}
+
+tst_net_check_ifaces_ipv6()
+{
+ local iface
+
+ for iface in $(tst_get_ifaces); do
+ tst_net_detect_ipv6_sysctl || return
+ done
+
+ for iface in $(tst_get_ifaces rhost); do
+ tst_net_detect_ipv6_sysctl $iface rhost || return
+ done
+}
+
init_ltp_netspace()
{
local pid
@@ -531,7 +568,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_sysctl $iface $type
if [ "$type" = "lhost" ]; then
if ip xfrm state 1>/dev/null 2>&1; then
@@ -1015,6 +1054,7 @@ if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
fi
tst_net_use_netns && init_ltp_netspace
+tst_net_check_ifaces_ipv6
eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-01-26 21:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 21:53 [LTP] [PATCH 0/9] tst_net.sh fixes + cleanup Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 1/9] tst_net.sh: Use tst_res_() Petr Vorel
2023-02-01 11:08 ` Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 2/9] tst_net.sh: Check for disabled IPv6 in legacy tests Petr Vorel
2023-02-01 10:49 ` Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 3/9] tst_net.sh: Remove unneeded $_tst_net_parse_variables Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 4/9] tst_net.sh: Remove unneeded $TST_INIT_NETNS variable Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 5/9] tst_net.sh: Add more tst_require_cmds check Petr Vorel
2023-02-01 11:39 ` Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 6/9] tst_net.sh: Rename function + add doc Petr Vorel
2023-02-08 10:18 ` Cyril Hrubis
2023-02-08 13:45 ` Petr Vorel
2023-02-08 14:05 ` Cyril Hrubis
2023-02-08 14:50 ` Petr Vorel
2023-02-17 12:28 ` Petr Vorel
2023-01-26 21:53 ` [LTP] [PATCH 7/9] tst_net.sh: Remove unused variable ret Petr Vorel
2023-01-26 21:54 ` Petr Vorel [this message]
2023-01-26 21:54 ` [LTP] [PATCH 9/9] tst_net.sh: Move net setup into separate function Petr Vorel
2023-02-17 11:34 ` 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=20230126215401.29101-9-pvorel@suse.cz \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
/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;
as well as URLs for NNTP newsgroup(s).