Skip to content

Commit 930cdb0

Browse files
author
CKI Backport Bot
committed
selftests: net: lib: Add a couple autodefer helpers
JIRA: https://issues.redhat.com/browse/RHEL-96617 commit 976d248 Author: Petr Machata <petrm@nvidia.com> Date: Wed Dec 18 18:15:58 2024 +0100 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@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Link: https://patch.msgid.link/856d9e01725fdba21b7f6716358f645b19131af2.1734540770.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent d1deb9c commit 930cdb0

File tree

1 file changed

+29
-2
lines changed
  • tools/testing/selftests/net

1 file changed

+29
-2
lines changed

tools/testing/selftests/net/lib.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,33 @@ ip_link_set_addr()
477477
defer ip link set dev "$name" address "$old_addr"
478478
}
479479

480+
ip_link_is_up()
481+
{
482+
local name=$1; shift
483+
484+
local state=$(ip -j link show "$name" |
485+
jq -r '(.[].flags[] | select(. == "UP")) // "DOWN"')
486+
[[ $state == "UP" ]]
487+
}
488+
480489
ip_link_set_up()
481490
{
482491
local name=$1; shift
483492

484-
ip link set dev "$name" up
485-
defer ip link set dev "$name" down
493+
if ! ip_link_is_up "$name"; then
494+
ip link set dev "$name" up
495+
defer ip link set dev "$name" down
496+
fi
497+
}
498+
499+
ip_link_set_down()
500+
{
501+
local name=$1; shift
502+
503+
if ip_link_is_up "$name"; then
504+
ip link set dev "$name" down
505+
defer ip link set dev "$name" up
506+
fi
486507
}
487508

488509
ip_addr_add()
@@ -498,3 +519,9 @@ ip_route_add()
498519
ip route add "$@"
499520
defer ip route del "$@"
500521
}
522+
523+
bridge_vlan_add()
524+
{
525+
bridge vlan add "$@"
526+
defer bridge vlan del "$@"
527+
}

0 commit comments

Comments
 (0)