From: Yedaya Katsman Date: Sun, 13 Oct 2024 18:53:08 +0000 (+0300) Subject: ip: Add "down" filter for "ip addr/link show" X-Git-Tag: v6.13.0~15^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9953ebde0cffaea2f5706b1178bfebade834e9ae;p=thirdparty%2Fiproute2.git 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 Signed-off-by: David Ahern --- diff --git a/ip/ip_common.h b/ip/ip_common.h index 350806d9..3804261f 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -16,6 +16,7 @@ struct link_filter { int scope, scopemask; int flags, flagmask; int up; + int down; char *label; int flushed; char *flushb; diff --git a/ip/ipaddress.c b/ip/ipaddress.c index f7bd1484..d90ba94d 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -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) { diff --git a/ip/iplink.c b/ip/iplink.c index 0dd83ff4..2fdd73e5 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -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" diff --git a/man/man8/ip-address.8.in b/man/man8/ip-address.8.in index 6c3f07f1..79942c1a 100644 --- a/man/man8/ip-address.8.in +++ b/man/man8/ip-address.8.in @@ -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 " ] ]" @@ -381,6 +381,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. diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index eabca490..64b5ba21 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -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