]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip link: fix display of interface groups
authorStefan Tomanek <stefan.tomanek@wertarbyte.de>
Sat, 3 Aug 2013 12:20:53 +0000 (14:20 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Sun, 4 Aug 2013 18:50:38 +0000 (11:50 -0700)
This change adds the interface group to the output of "ip link show".

It also makes "ip link" print _all_ devices if no group filter is specified;
previously, only interfaces of the default group (0) were shown.

Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
include/rt_names.h
ip/ipaddress.c
lib/rt_names.c

index 37adbd3493e247ec170aa305b472e47ed8a42bd3..56b649a318c04c1b75a93faa20146139ec311605 100644 (file)
@@ -8,6 +8,7 @@ const char *rtnl_rtscope_n2a(int id, char *buf, int len);
 const char *rtnl_rttable_n2a(__u32 id, char *buf, int len);
 const char *rtnl_rtrealm_n2a(int id, char *buf, int len);
 const char *rtnl_dsfield_n2a(int id, char *buf, int len);
+const char *rtnl_group_n2a(int id, char *buf, int len);
 
 int rtnl_rtprot_a2n(__u32 *id, const char *arg);
 int rtnl_rtscope_a2n(__u32 *id, const char *arg);
index 013b4cbd151684cee09d27839f9f238f287098f6..1c3e4da0d0dae050c50a6b99d74af3f2d46d7adc 100644 (file)
@@ -418,7 +418,7 @@ int print_linkinfo(const struct sockaddr_nl *who,
 
        if (tb[IFLA_GROUP]) {
                int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
-               if (group != filter.group)
+               if (filter.group != -1 && group != filter.group)
                        return -1;
        }
 
@@ -458,6 +458,12 @@ int print_linkinfo(const struct sockaddr_nl *who,
        if (do_link && tb[IFLA_LINKMODE])
                print_linkmode(fp, tb[IFLA_LINKMODE]);
 
+       if (tb[IFLA_GROUP]) {
+               SPRINT_BUF(b1);
+               int group = *(int*)RTA_DATA(tb[IFLA_GROUP]);
+               fprintf(fp, "group %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
+       }
+
        if (filter.showqueue)
                print_queuelen(fp, tb);
 
@@ -1050,7 +1056,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
        if (filter.family == AF_UNSPEC)
                filter.family = preferred_family;
 
-       filter.group = INIT_NETDEV_GROUP;
+       filter.group = -1;
 
        if (action == IPADD_FLUSH) {
                if (argc <= 0) {
index 02f1417563d8400f3e223f4f2c5617a36129df8a..67e4c49f44d28759af4fee5603a52402bd3c1049 100644 (file)
@@ -500,3 +500,22 @@ int rtnl_group_a2n(int *id, const char *arg)
        *id = i;
        return 0;
 }
+
+const char *rtnl_group_n2a(int id, char *buf, int len)
+{
+       struct rtnl_hash_entry *entry;
+       int i;
+
+       if (!rtnl_group_init)
+               rtnl_group_initialize();
+
+       for (i=0; i<256; i++) {
+               entry = rtnl_group_hash[i];
+               if (entry && entry->id == id) {
+                       return entry->name;
+               }
+       }
+
+       snprintf(buf, len, "%d", id);
+       return buf;
+}