]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipaddress.c
iproute2: support listing devices by group
[mirror_iproute2.git] / ip / ipaddress.c
index a775ecd38c4443517fe95d555b929d788e91cb1a..e4748e3ddcc05d395da6eac3c139739d9e36168f 100644 (file)
@@ -49,6 +49,7 @@ static struct
        char *flushb;
        int flushp;
        int flushe;
+       int group;
 } filter;
 
 static int do_link;
@@ -246,6 +247,12 @@ int print_linkinfo(const struct sockaddr_nl *who,
            fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
                return 0;
 
+       if (tb[IFLA_GROUP]) {
+               int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
+               if (group != filter.group)
+                       return -1;
+       }
+
        if (n->nlmsg_type == RTM_DELLINK)
                fprintf(fp, "Deleted ");
 
@@ -718,9 +725,12 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush)
        if (filter.family == AF_UNSPEC)
                filter.family = preferred_family;
 
+       filter.group = INIT_NETDEV_GROUP;
+
        if (flush) {
                if (argc <= 0) {
                        fprintf(stderr, "Flush requires arguments.\n");
+
                        return -1;
                }
                if (filter.family == AF_PACKET) {
@@ -779,6 +789,10 @@ static int ipaddr_list_or_flush(int argc, char **argv, int flush)
                } else if (strcmp(*argv, "label") == 0) {
                        NEXT_ARG();
                        filter.label = *argv;
+               } else if (strcmp(*argv, "group") == 0) {
+                       NEXT_ARG();
+                       if (rtnl_group_a2n(&filter.group, *argv))
+                               invarg("Invalid \"group\" value\n", *argv);
                } else {
                        if (strcmp(*argv, "dev") == 0) {
                                NEXT_ARG();