From f5ae57784ba805d0e8b11db1a7b2c17c5a07dd70 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 3 May 2018 12:36:59 +0200 Subject: selftests: forwarding: lib: Add sysctl_set(), sysctl_restore() Add two helper functions: sysctl_set() to change the value of a given sysctl setting, and sysctl_restore() to change it back to what it was. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: David S. Miller --- tools/testing/selftests/net/forwarding/lib.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index 061c87bbf77c..e49e78b5cd3d 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -381,6 +381,23 @@ bridge_ageing_time_get() echo $((ageing_time / 100)) } +declare -A SYSCTL_ORIG +sysctl_set() +{ + local key=$1; shift + local value=$1; shift + + SYSCTL_ORIG[$key]=$(sysctl -n $key) + sysctl -qw $key=$value +} + +sysctl_restore() +{ + local key=$1; shift + + sysctl -qw $key=${SYSCTL_ORIG["$key"]} +} + forwarding_enable() { ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding) -- cgit v1.2.3 From d51d10aa1dbdedd9254874bf37e8b0cd96ea3bde Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 3 May 2018 12:37:13 +0200 Subject: selftests: forwarding: Use sysctl_set(), sysctl_restore() Instead of hand-managing the sysctl set and restore, use the wrappers sysctl_set() and sysctl_restore() to do the bookkeeping automatically. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: David S. Miller --- tools/testing/selftests/net/forwarding/lib.sh | 11 ++++------- tools/testing/selftests/net/forwarding/mirror_gre_changes.sh | 7 ++----- tools/testing/selftests/net/forwarding/router_multipath.sh | 12 ++++-------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index e49e78b5cd3d..91041c49655b 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -400,17 +400,14 @@ sysctl_restore() forwarding_enable() { - ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding) - ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding) - - sysctl -q -w net.ipv4.conf.all.forwarding=1 - sysctl -q -w net.ipv6.conf.all.forwarding=1 + sysctl_set net.ipv4.conf.all.forwarding 1 + sysctl_set net.ipv6.conf.all.forwarding 1 } forwarding_restore() { - sysctl -q -w net.ipv6.conf.all.forwarding=$ipv6_fwd - sysctl -q -w net.ipv4.conf.all.forwarding=$ipv4_fwd + sysctl_restore net.ipv6.conf.all.forwarding + sysctl_restore net.ipv4.conf.all.forwarding } tc_offload_check() diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh b/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh index fdb612f69613..50ab3462af0c 100755 --- a/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh +++ b/tools/testing/selftests/net/forwarding/mirror_gre_changes.sh @@ -36,9 +36,7 @@ setup_prepare() # This test downs $swp3, which deletes the configured IPv6 address # unless this sysctl is set. - local key=net.ipv6.conf.$swp3.keep_addr_on_down - SWP3_KEEP_ADDR_ON_DOWN=$(sysctl -n $key) - sysctl -qw $key=1 + sysctl_set net.ipv6.conf.$swp3.keep_addr_on_down 1 ip address add dev $swp3 192.0.2.129/28 ip address add dev $h3 192.0.2.130/28 @@ -57,8 +55,7 @@ cleanup() ip address del dev $h3 192.0.2.130/28 ip address del dev $swp3 192.0.2.129/28 - local key=net.ipv6.conf.$swp3.keep_addr_on_down - sysctl -qw $key=$SWP3_KEEP_ADDR_ON_DOWN + sysctl_restore net.ipv6.conf.$swp3.keep_addr_on_down mirror_gre_topo_destroy vrf_cleanup diff --git a/tools/testing/selftests/net/forwarding/router_multipath.sh b/tools/testing/selftests/net/forwarding/router_multipath.sh index 6c4376289695..8b6d0fb6d604 100755 --- a/tools/testing/selftests/net/forwarding/router_multipath.sh +++ b/tools/testing/selftests/net/forwarding/router_multipath.sh @@ -205,13 +205,11 @@ multipath4_test() local weight_rp13=$3 local t0_rp12 t0_rp13 t1_rp12 t1_rp13 local packets_rp12 packets_rp13 - local hash_policy # Transmit multiple flows from h1 to h2 and make sure they are # distributed between both multipath links (rp12 and rp13) # according to the configured weights. - hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy) - sysctl -q -w net.ipv4.fib_multipath_hash_policy=1 + sysctl_set net.ipv4.fib_multipath_hash_policy 1 ip route replace 198.51.100.0/24 vrf vrf-r1 \ nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \ nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13 @@ -233,7 +231,7 @@ multipath4_test() ip route replace 198.51.100.0/24 vrf vrf-r1 \ nexthop via 169.254.2.22 dev $rp12 \ nexthop via 169.254.3.23 dev $rp13 - sysctl -q -w net.ipv4.fib_multipath_hash_policy=$hash_policy + sysctl_restore net.ipv4.fib_multipath_hash_policy } multipath6_l4_test() @@ -243,13 +241,11 @@ multipath6_l4_test() local weight_rp13=$3 local t0_rp12 t0_rp13 t1_rp12 t1_rp13 local packets_rp12 packets_rp13 - local hash_policy # Transmit multiple flows from h1 to h2 and make sure they are # distributed between both multipath links (rp12 and rp13) # according to the configured weights. - hash_policy=$(sysctl -n net.ipv6.fib_multipath_hash_policy) - sysctl -q -w net.ipv6.fib_multipath_hash_policy=1 + sysctl_set net.ipv6.fib_multipath_hash_policy 1 ip route replace 2001:db8:2::/64 vrf vrf-r1 \ nexthop via fe80:2::22 dev $rp12 weight $weight_rp12 \ @@ -272,7 +268,7 @@ multipath6_l4_test() nexthop via fe80:2::22 dev $rp12 \ nexthop via fe80:3::23 dev $rp13 - sysctl -q -w net.ipv6.fib_multipath_hash_policy=$hash_policy + sysctl_restore net.ipv6.fib_multipath_hash_policy } multipath6_test() -- cgit v1.2.3 From 7eaaf0bc52127401f7f39c9f7950f3f624763c90 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 3 May 2018 12:37:21 +0200 Subject: selftests: forwarding: mirror_gre_nh: Unset RP filter The test fails to work if reverse-path filtering is in effect on the mirrored-to host interface, or for all interfaces. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: David S. Miller --- tools/testing/selftests/net/forwarding/mirror_gre_nh.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/net/forwarding/mirror_gre_nh.sh b/tools/testing/selftests/net/forwarding/mirror_gre_nh.sh index a0d1ad46a2bc..8fa681eb90e7 100755 --- a/tools/testing/selftests/net/forwarding/mirror_gre_nh.sh +++ b/tools/testing/selftests/net/forwarding/mirror_gre_nh.sh @@ -29,6 +29,9 @@ setup_prepare() swp3=${NETIFS[p5]} h3=${NETIFS[p6]} + sysctl_set net.ipv4.conf.all.rp_filter 0 + sysctl_set net.ipv4.conf.$h3.rp_filter 0 + vrf_prepare mirror_gre_topo_create @@ -60,6 +63,9 @@ cleanup() mirror_gre_topo_destroy vrf_cleanup + + sysctl_restore net.ipv4.conf.$h3.rp_filter + sysctl_restore net.ipv4.conf.all.rp_filter } test_gretap() -- cgit v1.2.3