naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0153-ip-link-Show-devices-by-type.patch

049c96
From 1483dbd11fe093100866a1bad822941e12d10c6a Mon Sep 17 00:00:00 2001
049c96
From: Phil Sutter <psutter@redhat.com>
049c96
Date: Thu, 16 Jun 2016 16:41:37 +0200
049c96
Subject: [PATCH] ip link: Show devices by type
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1341343
049c96
Upstream Status: iproute2.git commit 712249d8fac88
049c96
Conflicts: Changes in ip-link.8.in due to previously applied patches
049c96
           134080cff35e3 ("man: ip, ip-link: Fix ip option location")
049c96
	   and ca611d6408c9b ("man: ip-link.8: Fix and improve
049c96
	   synopsis").
049c96
049c96
commit 712249d8fac88bcf3a9fd0b1de2263074075873b
049c96
Author: Vadim Kochan <vadim4j@gmail.com>
049c96
Date:   Wed Dec 10 10:11:29 2014 +0200
049c96
049c96
    ip link: Show devices by type
049c96
049c96
    Added new option 'type' to 'ip link show'
049c96
    command which allows to filter devices by type:
049c96
049c96
        ip link show type bridge
049c96
        ip link show type vlan
049c96
049c96
    Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
049c96
---
049c96
 ip/ipaddress.c        | 27 +++++++++++++++++++++++++++
049c96
 ip/iplink.c           |  2 +-
049c96
 man/man8/ip-link.8.in | 19 ++++++++++++++++++-
049c96
 3 files changed, 46 insertions(+), 2 deletions(-)
049c96
049c96
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
049c96
index 3d9e47f..4720de0 100644
049c96
--- a/ip/ipaddress.c
049c96
+++ b/ip/ipaddress.c
049c96
@@ -58,6 +58,7 @@ static struct
049c96
 	int flushe;
049c96
 	int group;
049c96
 	int master;
049c96
+	char *kind;
049c96
 } filter;
049c96
 
049c96
 static int do_link;
049c96
@@ -190,6 +191,18 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
049c96
 		fprintf(f, "mode %s ", link_modes[mode]);
049c96
 }
049c96
 
049c96
+static char *parse_link_kind(struct rtattr *tb)
049c96
+{
049c96
+	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
049c96
+
049c96
+	parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
049c96
+
049c96
+	if (linkinfo[IFLA_INFO_KIND])
049c96
+		return RTA_DATA(linkinfo[IFLA_INFO_KIND]);
049c96
+
049c96
+	return "";
049c96
+}
049c96
+
049c96
 static void print_linktype(FILE *fp, struct rtattr *tb)
049c96
 {
049c96
 	struct rtattr *linkinfo[IFLA_INFO_MAX+1];
049c96
@@ -569,6 +582,17 @@ int print_linkinfo(const struct sockaddr_nl *who,
049c96
 	else if (filter.master > 0)
049c96
 		return -1;
049c96
 
049c96
+	if (filter.kind) {
049c96
+		if (tb[IFLA_LINKINFO]) {
049c96
+			char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
049c96
+
049c96
+			if (strcmp(kind, filter.kind))
049c96
+				return -1;
049c96
+		} else {
049c96
+			return -1;
049c96
+		}
049c96
+	}
049c96
+
049c96
 	if (n->nlmsg_type == RTM_DELLINK)
049c96
 		fprintf(fp, "Deleted ");
049c96
 
049c96
@@ -1308,6 +1332,9 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
049c96
 			if (!ifindex)
049c96
 				invarg("Device does not exist\n", *argv);
049c96
 			filter.master = ifindex;
049c96
+		} else if (do_link && strcmp(*argv, "type") == 0) {
049c96
+			NEXT_ARG();
049c96
+			filter.kind = *argv;
049c96
 		} else {
049c96
 			if (strcmp(*argv, "dev") == 0) {
049c96
 				NEXT_ARG();
049c96
diff --git a/ip/iplink.c b/ip/iplink.c
049c96
index 1d93229..0f91043 100644
049c96
--- a/ip/iplink.c
049c96
+++ b/ip/iplink.c
049c96
@@ -84,7 +84,7 @@ void iplink_usage(void)
049c96
 	fprintf(stderr, "			  [ master DEVICE ]\n");
049c96
 	fprintf(stderr, "			  [ nomaster ]\n");
049c96
 	fprintf(stderr, "			  [ addrgenmode { eui64 | none } ]\n");
049c96
-	fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV]\n");
049c96
+	fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]\n");
049c96
 
049c96
 	if (iplink_have_newlink()) {
049c96
 		fprintf(stderr, "       ip link help [ TYPE ]\n");
049c96
diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
049c96
index 09ea2f7..f968e49 100644
049c96
--- a/man/man8/ip-link.8.in
049c96
+++ b/man/man8/ip-link.8.in
049c96
@@ -143,7 +143,9 @@ ip-link \- network device configuration
049c96
 .IR GROUP " ] ["
049c96
 .BR up " ] ["
049c96
 .B master
049c96
-.IR DEVICE " ]"
049c96
+.IR DEVICE " ] ["
049c96
+.B type
049c96
+.IR TYPE " ]"
049c96
 
049c96
 .ti -8
049c96
 .B ip link help
049c96
@@ -922,6 +924,11 @@ only display running interfaces.
049c96
 .I DEVICE
049c96
 specifies the master device which enslaves devices to show.
049c96
 
049c96
+.TP
049c96
+.BI type " TYPE "
049c96
+.I TYPE
049c96
+specifies the type of devices to show.
049c96
+
049c96
 .SS  ip link help - display help
049c96
 
049c96
 .PP
049c96
@@ -935,6 +942,16 @@ ip link show
049c96
 Shows the state of all network interfaces on the system.
049c96
 .RE
049c96
 .PP
049c96
+ip link show type bridge
049c96
+.RS 4
049c96
+Shows the bridge devices.
049c96
+.RE
049c96
+.PP
049c96
+ip link show type vlan
049c96
+.RS 4
049c96
+Shows the vlan devices.
049c96
+.RE
049c96
+.PP
049c96
 ip link set dev ppp0 mtu 1400
049c96
 .RS 4
049c96
 Change the MTU the ppp0 device.
049c96
-- 
049c96
1.8.3.1
049c96