lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241013185308.12280-1-yedaya.ka@gmail.com>
Date: Sun, 13 Oct 2024 21:53:08 +0300
From: Yedaya Katsman <yedaya.ka@...il.com>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>,
	Yedaya Katsman <yedaya.ka@...il.com>
Subject: [PATCH] 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 <yedaya.ka@...il.com>
---
 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(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index 350806d9d0cc..3804261fdb36 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 f7bd14847477..d90ba94d11c5 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 0dd83ff44846..2fdd73e5b8be 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 d37dddb7b1a9..92ebdfe69ded 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 " ] ]"
@@ -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.
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
index eabca4903302..64b5ba21c222 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
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ