[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <856d9e01725fdba21b7f6716358f645b19131af2.1734540770.git.petrm@nvidia.com>
Date: Wed, 18 Dec 2024 18:15:58 +0100
From: Petr Machata <petrm@...dia.com>
To: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, <netdev@...r.kernel.org>
CC: Simon Horman <horms@...nel.org>, Roopa Prabhu <roopa@...dia.com>, "Nikolay
Aleksandrov" <razor@...ckwall.org>, <bridge@...ts.linux.dev>, Ido Schimmel
<idosch@...dia.com>, Petr Machata <petrm@...dia.com>, <mlxsw@...dia.com>,
Shuah Khan <shuah@...nel.org>, <linux-kselftest@...r.kernel.org>
Subject: [PATCH net-next 3/4] selftests: net: lib: Add a couple autodefer helpers
Alongside the helper ip_link_set_up(), one to set the link down will be
useful as well. Add a helper to determine the link state as well,
ip_link_is_up(), and use it to short-circuit any changes if the state is
already the desired one.
Furthermore, add a helper bridge_vlan_add().
Signed-off-by: Petr Machata <petrm@...dia.com>
Reviewed-by: Ido Schimmel <idosch@...dia.com>
---
CC: Shuah Khan <shuah@...nel.org>
CC: linux-kselftest@...r.kernel.org
---
tools/testing/selftests/net/lib.sh | 31 ++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh
index 2cd5c743b2d9..0bd9a038a1f0 100644
--- a/tools/testing/selftests/net/lib.sh
+++ b/tools/testing/selftests/net/lib.sh
@@ -477,12 +477,33 @@ ip_link_set_addr()
defer ip link set dev "$name" address "$old_addr"
}
+ip_link_is_up()
+{
+ local name=$1; shift
+
+ local state=$(ip -j link show "$name" |
+ jq -r '(.[].flags[] | select(. == "UP")) // "DOWN"')
+ [[ $state == "UP" ]]
+}
+
ip_link_set_up()
{
local name=$1; shift
- ip link set dev "$name" up
- defer ip link set dev "$name" down
+ if ! ip_link_is_up "$name"; then
+ ip link set dev "$name" up
+ defer ip link set dev "$name" down
+ fi
+}
+
+ip_link_set_down()
+{
+ local name=$1; shift
+
+ if ip_link_is_up "$name"; then
+ ip link set dev "$name" down
+ defer ip link set dev "$name" up
+ fi
}
ip_addr_add()
@@ -498,3 +519,9 @@ ip_route_add()
ip route add "$@"
defer ip route del "$@"
}
+
+bridge_vlan_add()
+{
+ bridge vlan add "$@"
+ defer bridge vlan del "$@"
+}
--
2.47.0
Powered by blists - more mailing lists