Skip to content

Commit d51d10a

Browse files
pmachatadavem330
authored andcommitted
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 <petrm@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f5ae577 commit d51d10a

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,14 @@ sysctl_restore()
400400

401401
forwarding_enable()
402402
{
403-
ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding)
404-
ipv6_fwd=$(sysctl -n net.ipv6.conf.all.forwarding)
405-
406-
sysctl -q -w net.ipv4.conf.all.forwarding=1
407-
sysctl -q -w net.ipv6.conf.all.forwarding=1
403+
sysctl_set net.ipv4.conf.all.forwarding 1
404+
sysctl_set net.ipv6.conf.all.forwarding 1
408405
}
409406

410407
forwarding_restore()
411408
{
412-
sysctl -q -w net.ipv6.conf.all.forwarding=$ipv6_fwd
413-
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
414411
}
415412

416413
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/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)