Skip to content

Commit

Permalink
selftests: forwarding: lib: Add sysctl_set(), sysctl_restore()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Petr Machata authored and David S. Miller committed May 3, 2018
1 parent 41f4054 commit f5ae577
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5ae577

Please sign in to comment.