ip link: Allow to filter devices by master dev
Added 'master' option to 'ip link show' command
to filter devices by master dev.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index c95aa6d..4d99324 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -56,6 +56,7 @@
int flushp;
int flushe;
int group;
+ int master;
} filter;
static int do_link;
@@ -542,6 +543,14 @@
return -1;
}
+ if (tb[IFLA_MASTER]) {
+ int master = *(int*)RTA_DATA(tb[IFLA_MASTER]);
+ if (filter.master > 0 && master != filter.master)
+ return -1;
+ }
+ else if (filter.master > 0)
+ return -1;
+
if (n->nlmsg_type == RTM_DELLINK)
fprintf(fp, "Deleted ");
@@ -1277,6 +1286,13 @@
NEXT_ARG();
if (rtnl_group_a2n(&filter.group, *argv))
invarg("Invalid \"group\" value\n", *argv);
+ } else if (strcmp(*argv, "master") == 0) {
+ int ifindex;
+ NEXT_ARG();
+ ifindex = ll_name_to_index(*argv);
+ if (!ifindex)
+ invarg("Device does not exist\n", *argv);
+ filter.master = ifindex;
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();