Skip to content

Commit

Permalink
Merge branch 'selftests-forwarding-sysctl'
Browse files Browse the repository at this point in the history
Petr Machata says:

====================
selftests: forwarding: Updates to sysctl handling

Some selftests need to adjust sysctl settings. In order to be neutral to
the system that the test is run on, it is a good practice to change back
to the original setting after the test ends. That involves some
boilerplate that can be abstracted away.

In patch #1, introduce two functions, sysctl_set() and sysctl_restore().
The former stores the current value of a given setting, and sets a new
value. The latter restores the setting to the previously-stored value.

In patch #2, use these wrappers in a number of tests.

Additionally in patch #3, fix a problem in mirror_gre_nh.sh, which
neglected to set a sysctl that's crucial for the test to work.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed May 3, 2018
2 parents 41f4054 + 7eaaf0b commit 2e51855
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
28 changes: 21 additions & 7 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,33 @@ bridge_ageing_time_get()
echo $((ageing_time / 100))
}

forwarding_enable()
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()
{
ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding)
ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding)
local key=$1; shift

sysctl -q -w net.ipv4.conf.all.forwarding=1
sysctl -q -w net.ipv6.conf.all.forwarding=1
sysctl -qw $key=${SYSCTL_ORIG["$key"]}
}

forwarding_enable()
{
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()
Expand Down
7 changes: 2 additions & 5 deletions tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tools/testing/selftests/net/forwarding/mirror_gre_nh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
12 changes: 4 additions & 8 deletions tools/testing/selftests/net/forwarding/router_multipath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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 \
Expand All @@ -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()
Expand Down

0 comments on commit 2e51855

Please sign in to comment.