]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip link: Show devices by type
authorVadim Kochan <vadim4j@gmail.com>
Wed, 10 Dec 2014 08:11:29 +0000 (10:11 +0200)
committerStephen Hemminger <shemming@brocade.com>
Wed, 24 Dec 2014 20:19:14 +0000 (12:19 -0800)
Added new option 'type' to 'ip link show'
command which allows to filter devices by type:

    ip link show type bridge
    ip link show type vlan

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
ip/ipaddress.c
ip/iplink.c
man/man8/ip-link.8.in

index a07157267b44929ae0ecf523855861b1756335ff..28dfe8cedfbdcbb9e921d682432d4a4ba0716e74 100644 (file)
@@ -57,6 +57,7 @@ static struct
        int flushe;
        int group;
        int master;
+       char *kind;
 } filter;
 
 static int do_link;
@@ -189,6 +190,18 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
                fprintf(f, "mode %s ", link_modes[mode]);
 }
 
+static char *parse_link_kind(struct rtattr *tb)
+{
+       struct rtattr *linkinfo[IFLA_INFO_MAX+1];
+
+       parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
+
+       if (linkinfo[IFLA_INFO_KIND])
+               return RTA_DATA(linkinfo[IFLA_INFO_KIND]);
+
+       return "";
+}
+
 static void print_linktype(FILE *fp, struct rtattr *tb)
 {
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
@@ -551,6 +564,17 @@ int print_linkinfo(const struct sockaddr_nl *who,
        else if (filter.master > 0)
                return -1;
 
+       if (filter.kind) {
+               if (tb[IFLA_LINKINFO]) {
+                       char *kind = parse_link_kind(tb[IFLA_LINKINFO]);
+
+                       if (strcmp(kind, filter.kind))
+                               return -1;
+               } else {
+                       return -1;
+               }
+       }
+
        if (n->nlmsg_type == RTM_DELLINK)
                fprintf(fp, "Deleted ");
 
@@ -1302,6 +1326,9 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                        if (!ifindex)
                                invarg("Device does not exist\n", *argv);
                        filter.master = ifindex;
+               } else if (do_link && strcmp(*argv, "type") == 0) {
+                       NEXT_ARG();
+                       filter.kind = *argv;
                } else {
                        if (strcmp(*argv, "dev") == 0) {
                                NEXT_ARG();
index ce6eb3e1f7c906678c79e9f3be30eaf11efbc479..f9a75d55eeba2a78e3796bcd2bb0ccd5b1fa3846 100644 (file)
@@ -82,7 +82,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] [master DEV]\n");
+       fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]\n");
 
        if (iplink_have_newlink()) {
                fprintf(stderr, "       ip link help [ TYPE ]\n");
index 6fd8de6fdeb84b056f8670a7c7889eb63840b6fe..5134e28191fcd73f93d4a9ca71034ef6696ce475 100644 (file)
@@ -148,7 +148,9 @@ ip-link \- network device configuration
 .IR GROUP " | "
 .BR up " | "
 .B master
-.IR DEVICE " ]"
+.IR DEVICE " | "
+.B type
+.IR TYPE " ]"
 
 .ti -8
 .B ip link help
@@ -688,6 +690,11 @@ only display running interfaces.
 .I DEVICE
 specifies the master device which enslaves devices to show.
 
+.TP
+.BI type " TYPE "
+.I TYPE
+specifies the type of devices to show.
+
 .TP
 The show command has additional formatting options:
 
@@ -722,6 +729,16 @@ ip link show
 Shows the state of all network interfaces on the system.
 .RE
 .PP
+ip link show type bridge
+.RS 4
+Shows the bridge devices.
+.RE
+.PP
+ip link show type vlan
+.RS 4
+Shows the vlan devices.
+.RE
+.PP
 ip link set dev ppp0 mtu 1400
 .RS 4
 Change the MTU the ppp0 device.