]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: Add "down" filter for "ip addr/link show"
authorYedaya Katsman <yedaya.ka@gmail.com>
Sun, 13 Oct 2024 18:53:08 +0000 (21:53 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 25 Oct 2024 16:50:35 +0000 (16:50 +0000)
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 <yedaya.ka@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ip_common.h
ip/ipaddress.c
ip/iplink.c
man/man8/ip-address.8.in
man/man8/ip-link.8.in

index 350806d9d0cc7173c1a25a447676850a19455ac9..3804261fdb363f1d0c4c2d995f348d393c308ab8 100644 (file)
@@ -16,6 +16,7 @@ struct link_filter {
        int scope, scopemask;
        int flags, flagmask;
        int up;
+       int down;
        char *label;
        int flushed;
        char *flushb;
index f7bd14847477e0aed724a0d120ec629941647e22..d90ba94d11c557c7e5fbc544a4524b8f93aef920 100644 (file)
@@ -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) {
index 0dd83ff448461c97ac3a15edd24ef6619f51b272..2fdd73e5b8bec8b92d7ee9ca1813e846159f5e97 100644 (file)
@@ -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"
index 6c3f07f1173a0c105107208a5b16d0253df1d251..79942c1a72338cb8c043f7f160db91d149e55ced 100644 (file)
@@ -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.
index eabca4903302fd0a073db50a3f3050014a89fc09..64b5ba21c222e12b9b0f6e087f85bddf7e374a4b 100644 (file)
@@ -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