ip: Add "down" filter for "ip addr/link show"
Subsystems (2)
PATCH 1/1 ip: Add "down" filter for "ip addr/link show"
Currently there is an "up" option, which allows showing only devices that are up and running. Add a corresponding "down" option.
Also change the usage and man pages accordingly.
Signed-off-by Yedaya Katsman <[email protected]>
--- ip/ip_common.h | 1 + ip/ipaddress.c | 13 ++++++++++--- ip/iplink.c | 4 ++-- man/man8/ip-address.8.in | 10 +++++++--- man/man8/ip-link.8.in | 8 ++++++-- 5 files changed, 26 insertions(+), 10 deletions(-)
ip/ip_common.h +1 -0
@@ -16,6 +16,7 @@ struct link_filter {int scope, scopemask;int flags, flagmask;int up; +int down;char *label;int flushed;char *flushb;
ip/ipaddress.c +10 -3
@@ -52,12 +52,12 @@ static void usage(void)"Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n" " [ CONFFLAG-LIST ]\n" " ip address del IFADDR dev IFNAME [mngtmpaddr]\n" -" ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]\n" -" [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]\n" +" ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ] [ to PREFIX ]\n" +" [ FLAG-LIST ] [ label LABEL ] [ { up | down } ]\n" " ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]\n" " [ nomaster ]\n" " [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]\n" -" [ label LABEL ] [up] [ vrf NAME ]\n" +" [ label LABEL ] [ { up | down } ] [ vrf NAME ]\n" " [ proto ADDRPROTO ] ]\n" " ip address {showdump|restore}\n" "IFADDR := PREFIX | ADDR peer PREFIX\n"
@@ -981,6 +981,8 @@ int print_linkinfo(struct nlmsghdr *n, void *arg)return -1 ;if (filter.up && !(ifi->ifi_flags&IFF_UP ))return -1 ; +if (filter.down && ifi->ifi_flags&IFF_UP ) +return -1 ;parse_rtattr_flags (tb,IFLA_MAX ,IFLA_RTA (ifi), len,NLA_F_NESTED );
@@ -1720,6 +1722,9 @@ static int print_selected_addrinfo(struct ifinfomsg *ifi,if (filter.up && !(ifi->ifi_flags&IFF_UP ))continue ; +if (filter.down && ifi->ifi_flags&IFF_UP ) +continue ; +open_json_object (NULL );print_addrinfo (n, fp);close_json_object ();
@@ -2140,6 +2145,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) filter.scope = scope; }else if (strcmp (*argv,"up" ) ==0 ) { filter.up =1 ; + }else if (strcmp (*argv,"down" ) ==0 ) { + filter.down =1 ; }else if (get_filter (*argv) ==0 ) { }else if (strcmp (*argv,"label" ) ==0 ) {
ip/iplink.c +2 -2
@@ -110,8 +110,8 @@ void iplink_usage(void)" [ gso_max_size BYTES ] [ gso_ipv4_max_size BYTES ] [ gso_max_segs PACKETS ]\n" " [ gro_max_size BYTES ] [ gro_ipv4_max_size BYTES ]\n" "\n" -" ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]\n" -" [nomaster] [ novf ]\n" +" ip link show [ DEVICE | group GROUP ] [ { up | down } ] [master DEV] [vrf NAME]\n" +" [type TYPE] [nomaster] [ novf ]\n" "\n" " ip link xstats type TYPE [ ARGS ]\n" "\n"
man/man8/ip-address.8.in +7 -3
@@ -32,7 +32,7 @@ ip-address \- protocol address management .B to .IR PREFIX " ] [ " FLAG-LIST " ] [ " .B label -.IR PATTERN " ] [ " up " ]" +.IR PATTERN " ] [ { " up " | " down " } ]" .ti -8 .BR "ip address" " [ " show " [ " dev
@@ -48,8 +48,8 @@ ip-address \- protocol address management .B type .IR TYPE " ] [ " .B vrf -.IR NAME " ] [ " -.BR up " ] [" +.IR NAME " ] [ { " +.BR up " | " down " } ] [" .BR nomaster " ]" .B proto .IR ADDRPROTO " ] ]"
@@ -378,6 +378,10 @@ output. .B up only list running interfaces. +.TP +.B down +only list not running interfaces. + .TP .B nomaster only list interfaces with no master.
man/man8/ip-link.8.in +6 -2
@@ -194,8 +194,8 @@ ip-link \- network device configuration .B ip link show .RI "[ " DEVICE " | " .B group -.IR GROUP " ] [" -.BR up " ] [" +.IR GROUP " ] [ { " +.BR up " | " down " } ] [" .B master .IR DEVICE " ] [" .B type
@@ -2903,6 +2903,10 @@ specifies what group of devices to show. .B up only display running interfaces. +.TP +.B down +only display not running interfaces. + .TP .BI master " DEVICE " .I DEVICE
Signature · 1 line
2.34.1
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 8 lines · On Sun, 13 Oct 2024 21:53:08 +0300 you wrote:
Currently there is an "up" option, which allows showing only devices that are up and running. Add a corresponding "down" option.
Also change the usage and man pages accordingly.
Signed-off-by Yedaya Katsman <[email protected]>[...]
Here is the summary with links:
- ip: Add "down" filter for "ip addr/link show"
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=9953ebde0cff
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html