[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5012d081-eae1-4424-9588-3dd8fc7d933e@blackwall.org>
Date: Fri, 20 Dec 2024 14:28:00 +0200
From: Nikolay Aleksandrov <razor@...ckwall.org>
To: Petr Machata <petrm@...dia.com>, "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>,
bridge@...ts.linux.dev, Ido Schimmel <idosch@...dia.com>, mlxsw@...dia.com,
Shuah Khan <shuah@...nel.org>, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH net-next 3/4] selftests: net: lib: Add a couple autodefer
helpers
On 12/18/24 19:15, Petr Machata wrote:
> 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 "$@"
> +}
Acked-by: Nikolay Aleksandrov <razor@...ckwall.org>
Powered by blists - more mailing lists