Skip to content

Commit f5ae577

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

File tree

1 file changed

+17
-0
lines changed
  • tools/testing/selftests/net/forwarding

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ bridge_ageing_time_get()
381381
echo $((ageing_time / 100))
382382
}
383383

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()
395+
{
396+
local key=$1; shift
397+
398+
sysctl -qw $key=${SYSCTL_ORIG["$key"]}
399+
}
400+
384401
forwarding_enable()
385402
{
386403
ipv4_fwd=$(sysctl -n net.ipv4.conf.all.forwarding)

0 commit comments

Comments
 (0)