Skip to content

Commit 4baa1d3

Browse files
pmachatakuba-moo
authored andcommitted
selftests: net: lib: Add ip_link_has_flag()
Add a helper to determine whether a given netdevice has a given flag. Rewrite ip_link_is_up() in terms of the new helper. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Link: https://patch.msgid.link/e1eb174a411f9d24735d095984c731d1d4a5a592.1750113335.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2a719b7 commit 4baa1d3

File tree

1 file changed

+9
-3
lines changed
  • tools/testing/selftests/net

1 file changed

+9
-3
lines changed

tools/testing/selftests/net/lib.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,19 @@ ip_link_set_addr()
547547
defer ip link set dev "$name" address "$old_addr"
548548
}
549549

550-
ip_link_is_up()
550+
ip_link_has_flag()
551551
{
552552
local name=$1; shift
553+
local flag=$1; shift
553554

554555
local state=$(ip -j link show "$name" |
555-
jq -r '(.[].flags[] | select(. == "UP")) // "DOWN"')
556-
[[ $state == "UP" ]]
556+
jq --arg flag "$flag" 'any(.[].flags.[]; . == $flag)')
557+
[[ $state == true ]]
558+
}
559+
560+
ip_link_is_up()
561+
{
562+
ip_link_has_flag "$1" UP
557563
}
558564

559565
ip_link_set_up()

0 commit comments

Comments
 (0)