From 07d29a9b4fff9486c4d4077c714086c895951e02 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 16 Jun 2016 16:40:15 +0200 Subject: [PATCH] ip link: Allow to filter devices by master dev Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1341343 Upstream Status: iproute2.git commit 1b94414854d71 Conflicts: Changes in ip-link.8.in due to previously applied patches 134080cff35e3 ("man: ip, ip-link: Fix ip option location") and ca611d6408c9b ("man: ip-link.8: Fix and improve synopsis"). commit 1b94414854d71a6b6df367644ae9b06a54278daf Author: Vadim Kochan Date: Sat Nov 29 11:27:41 2014 -0800 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 --- ip/ipaddress.c | 16 ++++++++++++++++ ip/iplink.c | 2 +- man/man8/ip-link.8.in | 8 +++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index ffcc076..3d9e47f 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -57,6 +57,7 @@ static struct int flushp; int flushe; int group; + int master; } filter; static int do_link; @@ -560,6 +561,14 @@ int print_linkinfo(const struct sockaddr_nl *who, 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 "); @@ -1292,6 +1301,13 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) 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(); diff --git a/ip/iplink.c b/ip/iplink.c index 787d743..1d93229 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -84,7 +84,7 @@ void iplink_usage(void) fprintf(stderr, " [ master DEVICE ]\n"); fprintf(stderr, " [ nomaster ]\n"); fprintf(stderr, " [ addrgenmode { eui64 | none } ]\n"); - fprintf(stderr, " ip link show [ DEVICE | group GROUP ] [up]\n"); + fprintf(stderr, " ip link show [ DEVICE | group GROUP ] [up] [master DEV]\n"); if (iplink_have_newlink()) { fprintf(stderr, " ip link help [ TYPE ]\n"); diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 744a8af..09ea2f7 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -141,7 +141,9 @@ ip-link \- network device configuration .RI "[ " DEVICE " | " .B group .IR GROUP " ] [" -.BR up " ]" +.BR up " ] [" +.B master +.IR DEVICE " ]" .ti -8 .B ip link help @@ -915,6 +917,10 @@ specifies what group of devices to show. .B up only display running interfaces. +.TP +.BI master " DEVICE " +.I DEVICE +specifies the master device which enslaves devices to show. .SS ip link help - display help -- 1.8.3.1