lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 15 Mar 2018 17:18:23 +0100
From:   Stefano Brivio <sbrivio@...hat.com>
To:     "David S . Miller" <davem@...emloft.net>
Cc:     Sabrina Dubroca <sd@...asysnail.net>,
        Steffen Klassert <steffen.klassert@...unet.com>,
        netdev@...r.kernel.org
Subject: [PATCH net-next 3/9] selftests: pmtu: Introduce support for multiple tests

Introduce list of tests and loop on it in main body.

Tests will now just take care of calling setup with a list of
"units" they need, and return 0 for failure, 1 for success, 2 if
the test had to be skipped.

Main script body will take care of displaying results and
cleaning up after every test. Introduce guard variable so that
we don't clean up twice in case of interrupts or unexpected
failures.

Signed-off-by: Stefano Brivio <sbrivio@...hat.com>
---
 tools/testing/selftests/net/pmtu.sh | 58 ++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh
index fc79cc6f49a6..feebb6fcff21 100755
--- a/tools/testing/selftests/net/pmtu.sh
+++ b/tools/testing/selftests/net/pmtu.sh
@@ -5,13 +5,15 @@
 #
 # Tests currently implemented:
 #
-# - test_pmtu_vti6_exception
+# - pmtu_vti6_exception
 #	Set up vti6 tunnel on top of veth, with xfrm states and policies, in two
 #	namespaces with matching endpoints. Check that route exception is
 #	created by exceeding link layer MTU with ping to other endpoint. Then
 #	decrease and increase MTU of tunnel, checking that route exception PMTU
 #	changes accordingly
 
+tests="pmtu_vti6_exception"
+
 NS_A="ns-$(mktemp -u XXXXXX)"
 NS_B="ns-$(mktemp -u XXXXXX)"
 ns_a="ip netns exec ${NS_A}"
@@ -25,6 +27,8 @@ vti6_a_addr="fd00:2::a"
 vti6_b_addr="fd00:2::b"
 vti6_mask="64"
 
+cleanup_done=1
+
 setup_namespaces() {
 	ip netns add ${NS_A} || return 0
 	ip netns add ${NS_B}
@@ -75,26 +79,21 @@ setup_xfrm() {
 }
 
 setup() {
-	tunnel_type="$1"
+	[ "$(id -u)" -ne 0 ] && echo "  need to run as root" && return 0
 
-	[ "$(id -u)" -ne 0 ] && echo "SKIP: need to run as root" && exit 0
-
-	setup_namespaces && echo "SKIP: namespaces not supported" && exit 0
-	setup_veth && echo "SKIP: veth not supported" && exit 0
+	cleanup_done=0
+	for arg do
+		eval setup_${arg} && echo "  ${arg} not supported" && return 0
+	done
 
-	case ${tunnel_type} in
-	"vti6")
-		setup_vti6 && echo "SKIP: vti6 not supported" && exit 0
-		setup_xfrm && echo "SKIP: xfrm not supported" && exit 0
-		;;
-	*)
-		;;
-	esac
+	return 1
 }
 
 cleanup() {
+	[ ${cleanup_done} -eq 1 ] && return
 	ip netns del ${NS_A} 2 > /dev/null
 	ip netns del ${NS_B} 2 > /dev/null
+	cleanup_done=1
 }
 
 mtu() {
@@ -130,7 +129,7 @@ route_get_dst_pmtu_from_exception() {
 }
 
 test_pmtu_vti6_exception() {
-	setup vti6
+	setup namespaces veth vti6 xfrm && return 2
 
 	# Create route exception by exceeding link layer MTU
 	mtu "${ns_a}" veth_a 4000
@@ -141,30 +140,41 @@ test_pmtu_vti6_exception() {
 
 	# Check that exception was created
 	if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" = "" ]; then
-		echo "FAIL: Tunnel exceeding link layer MTU didn't create route exception"
-		exit 1
+		echo "  tunnel exceeding link layer MTU didn't create route exception"
+		return 0
 	fi
 
 	# Decrease tunnel MTU, check for PMTU decrease in route exception
 	mtu "${ns_a}" vti_a 3000
 
 	if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" -ne 3000 ]; then
-		echo "FAIL: Decreasing tunnel MTU didn't decrease route exception PMTU"
-		exit 1
+		echo "  decreasing tunnel MTU didn't decrease route exception PMTU"
+		return 0
 	fi
 
 	# Increase tunnel MTU, check for PMTU increase in route exception
 	mtu "${ns_a}" vti_a 9000
 	if [ "$(route_get_dst_pmtu_from_exception "${ns_a}" ${vti6_b_addr})" -ne 9000 ]; then
-		echo "FAIL: Increasing tunnel MTU didn't increase route exception PMTU"
-		exit 1
+		echo "  increasing tunnel MTU didn't increase route exception PMTU"
+		return 0
 	fi
 
-	echo "PASS"
+	return 1
 }
 
 trap cleanup EXIT
 
-test_pmtu_vti6_exception
+exitcode=0
+for name in ${tests}; do
+	echo "${name}: START"
+	eval test_${name}
+	ret=$?
+	cleanup
+
+	if [ $ret -eq 0 ]; then echo "${name}: FAIL"; exitcode=1
+	elif [ $ret -eq 1 ]; then echo "${name}: PASS"
+	elif [ $ret -eq 2 ]; then echo "${name}: SKIP"
+	fi
+done
 
-exit 0
+exit ${exitcode}
-- 
2.15.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ