Skip to content

Commit 2e51855

Browse files
committed
Merge branch 'selftests-forwarding-sysctl'
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>
2 parents 41f4054 + 7eaaf0b commit 2e51855

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,19 +381,33 @@ bridge_ageing_time_get()
381381
echo $((ageing_time / 100))
382382
}
383383

384-
forwarding_enable()
384+
declare -A SYSCTL_ORIG
385+
sysctl_set()
386+
{
387+
local key=$1; shift
388+
local value=$1; shift
389+
390+
SYSCTL_ORIG[$key]=$(sysctl -n $key)
391+
sysctl -qw $key=$value
392+
}
393+
394+
sysctl_restore()
385395
{
386-
ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding)
387-
ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding)
396+
local key=$1; shift
388397

389-
sysctl -q -w net.ipv4.conf.all.forwarding=1
390-
sysctl -q -w net.ipv6.conf.all.forwarding=1
398+
sysctl -qw $key=${SYSCTL_ORIG["$key"]}
399+
}
400+
401+
forwarding_enable()
402+
{
403+
sysctl_set net.ipv4.conf.all.forwarding 1
404+
sysctl_set net.ipv6.conf.all.forwarding 1
391405
}
392406

393407
forwarding_restore()
394408
{
395-
sysctl -q -w net.ipv6.conf.all.forwarding=$ipv6_fwd
396-
sysctl -q -w net.ipv4.conf.all.forwarding=$ipv4_fwd
409+
sysctl_restore net.ipv6.conf.all.forwarding
410+
sysctl_restore net.ipv4.conf.all.forwarding
397411
}
398412

399413
tc_offload_check()

tools/testing/selftests/net/forwarding/mirror_gre_changes.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ setup_prepare()
3636

3737
# This test downs $swp3, which deletes the configured IPv6 address
3838
# unless this sysctl is set.
39-
local key=net.ipv6.conf.$swp3.keep_addr_on_down
40-
SWP3_KEEP_ADDR_ON_DOWN=$(sysctl -n $key)
41-
sysctl -qw $key=1
39+
sysctl_set net.ipv6.conf.$swp3.keep_addr_on_down 1
4240

4341
ip address add dev $swp3 192.0.2.129/28
4442
ip address add dev $h3 192.0.2.130/28
@@ -57,8 +55,7 @@ cleanup()
5755
ip address del dev $h3 192.0.2.130/28
5856
ip address del dev $swp3 192.0.2.129/28
5957

60-
local key=net.ipv6.conf.$swp3.keep_addr_on_down
61-
sysctl -qw $key=$SWP3_KEEP_ADDR_ON_DOWN
58+
sysctl_restore net.ipv6.conf.$swp3.keep_addr_on_down
6259

6360
mirror_gre_topo_destroy
6461
vrf_cleanup

tools/testing/selftests/net/forwarding/mirror_gre_nh.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ setup_prepare()
2929
swp3=${NETIFS[p5]}
3030
h3=${NETIFS[p6]}
3131

32+
sysctl_set net.ipv4.conf.all.rp_filter 0
33+
sysctl_set net.ipv4.conf.$h3.rp_filter 0
34+
3235
vrf_prepare
3336
mirror_gre_topo_create
3437

@@ -60,6 +63,9 @@ cleanup()
6063

6164
mirror_gre_topo_destroy
6265
vrf_cleanup
66+
67+
sysctl_restore net.ipv4.conf.$h3.rp_filter
68+
sysctl_restore net.ipv4.conf.all.rp_filter
6369
}
6470

6571
test_gretap()

tools/testing/selftests/net/forwarding/router_multipath.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,11 @@ multipath4_test()
205205
local weight_rp13=$3
206206
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
207207
local packets_rp12 packets_rp13
208-
local hash_policy
209208

210209
# Transmit multiple flows from h1 to h2 and make sure they are
211210
# distributed between both multipath links (rp12 and rp13)
212211
# according to the configured weights.
213-
hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
214-
sysctl -q -w net.ipv4.fib_multipath_hash_policy=1
212+
sysctl_set net.ipv4.fib_multipath_hash_policy 1
215213
ip route replace 198.51.100.0/24 vrf vrf-r1 \
216214
nexthop via 169.254.2.22 dev $rp12 weight $weight_rp12 \
217215
nexthop via 169.254.3.23 dev $rp13 weight $weight_rp13
@@ -233,7 +231,7 @@ multipath4_test()
233231
ip route replace 198.51.100.0/24 vrf vrf-r1 \
234232
nexthop via 169.254.2.22 dev $rp12 \
235233
nexthop via 169.254.3.23 dev $rp13
236-
sysctl -q -w net.ipv4.fib_multipath_hash_policy=$hash_policy
234+
sysctl_restore net.ipv4.fib_multipath_hash_policy
237235
}
238236

239237
multipath6_l4_test()
@@ -243,13 +241,11 @@ multipath6_l4_test()
243241
local weight_rp13=$3
244242
local t0_rp12 t0_rp13 t1_rp12 t1_rp13
245243
local packets_rp12 packets_rp13
246-
local hash_policy
247244

248245
# Transmit multiple flows from h1 to h2 and make sure they are
249246
# distributed between both multipath links (rp12 and rp13)
250247
# according to the configured weights.
251-
hash_policy=$(sysctl -n net.ipv6.fib_multipath_hash_policy)
252-
sysctl -q -w net.ipv6.fib_multipath_hash_policy=1
248+
sysctl_set net.ipv6.fib_multipath_hash_policy 1
253249

254250
ip route replace 2001:db8:2::/64 vrf vrf-r1 \
255251
nexthop via fe80:2::22 dev $rp12 weight $weight_rp12 \
@@ -272,7 +268,7 @@ multipath6_l4_test()
272268
nexthop via fe80:2::22 dev $rp12 \
273269
nexthop via fe80:3::23 dev $rp13
274270

275-
sysctl -q -w net.ipv6.fib_multipath_hash_policy=$hash_policy
271+
sysctl_restore net.ipv6.fib_multipath_hash_policy
276272
}
277273

278274
multipath6_test()

0 commit comments

Comments
 (0)