]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip address: Change print_linkinfo_brief to take filter as an input
authorDavid Ahern <dsahern@gmail.com>
Sat, 27 May 2017 23:34:49 +0000 (17:34 -0600)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 31 May 2017 00:54:03 +0000 (17:54 -0700)
Change print_linkinfo_brief to take the filter as an input arg.
If the arg is NULL, use the global filter in ipaddress.c.

Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ip_common.h
ip/ipaddress.c
ip/iplink.c

index 2b3cf7049b65a726db3dfd12de0cdddf07fe39f7..77e9dd06b8641f53931f9b56d234e287b5960e7d 100644 (file)
@@ -22,7 +22,8 @@ int get_operstate(const char *name);
 int print_linkinfo(const struct sockaddr_nl *who,
                   struct nlmsghdr *n, void *arg);
 int print_linkinfo_brief(const struct sockaddr_nl *who,
-                        struct nlmsghdr *n, void *arg);
+                        struct nlmsghdr *n, void *arg,
+                        struct link_filter *filter);
 int print_addrinfo(const struct sockaddr_nl *who,
                   struct nlmsghdr *n, void *arg);
 int print_addrlabel(const struct sockaddr_nl *who,
index 3e2c38a8e53e4658d87fb44e4eda1b4ed3d5abf1..4900dce09df87cab21e079b1837046908b7f812b 100644 (file)
@@ -634,7 +634,8 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
 }
 
 int print_linkinfo_brief(const struct sockaddr_nl *who,
-                               struct nlmsghdr *n, void *arg)
+                        struct nlmsghdr *n, void *arg,
+                        struct link_filter *pfilter)
 {
        FILE *fp = (FILE *)arg;
        struct ifinfomsg *ifi = NLMSG_DATA(n);
@@ -651,9 +652,12 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
        if (len < 0)
                return -1;
 
-       if (filter.ifindex && ifi->ifi_index != filter.ifindex)
+       if (!pfilter)
+               pfilter = &filter;
+
+       if (pfilter->ifindex && ifi->ifi_index != pfilter->ifindex)
                return -1;
-       if (filter.up && !(ifi->ifi_flags&IFF_UP))
+       if (pfilter->up && !(ifi->ifi_flags&IFF_UP))
                return -1;
 
        parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
@@ -664,30 +668,30 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
                name = rta_getattr_str(tb[IFLA_IFNAME]);
        }
 
-       if (filter.label &&
-           (!filter.family || filter.family == AF_PACKET) &&
-           fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
+       if (pfilter->label &&
+           (!pfilter->family || pfilter->family == AF_PACKET) &&
+           fnmatch(pfilter->label, RTA_DATA(tb[IFLA_IFNAME]), 0))
                return -1;
 
        if (tb[IFLA_GROUP]) {
                int group = rta_getattr_u32(tb[IFLA_GROUP]);
 
-               if (filter.group != -1 && group != filter.group)
+               if (pfilter->group != -1 && group != pfilter->group)
                        return -1;
        }
 
        if (tb[IFLA_MASTER]) {
                int master = rta_getattr_u32(tb[IFLA_MASTER]);
 
-               if (filter.master > 0 && master != filter.master)
+               if (pfilter->master > 0 && master != pfilter->master)
                        return -1;
-       } else if (filter.master > 0)
+       } else if (pfilter->master > 0)
                return -1;
 
-       if (filter.kind && match_link_kind(tb, filter.kind, 0))
+       if (pfilter->kind && match_link_kind(tb, pfilter->kind, 0))
                return -1;
 
-       if (filter.slave_kind && match_link_kind(tb, filter.slave_kind, 1))
+       if (pfilter->slave_kind && match_link_kind(tb, pfilter->slave_kind, 1))
                return -1;
 
        if (n->nlmsg_type == RTM_DELLINK)
@@ -713,7 +717,7 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
        if (tb[IFLA_OPERSTATE])
                print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
 
-       if (filter.family == AF_PACKET) {
+       if (pfilter->family == AF_PACKET) {
                SPRINT_BUF(b1);
                if (tb[IFLA_ADDRESS]) {
                        color_fprintf(fp, COLOR_MAC, "%s ",
@@ -724,10 +728,10 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
                }
        }
 
-       if (filter.family == AF_PACKET)
+       if (pfilter->family == AF_PACKET)
                print_link_flags(fp, ifi->ifi_flags, m_flag);
 
-       if (filter.family == AF_PACKET)
+       if (pfilter->family == AF_PACKET)
                fprintf(fp, "\n");
        fflush(fp);
        return 0;
@@ -1736,7 +1740,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
 
                if (brief) {
-                       if (print_linkinfo_brief(NULL, &l->h, stdout) == 0)
+                       if (print_linkinfo_brief(NULL, &l->h,
+                                                stdout, NULL) == 0)
                                if (filter.family != AF_PACKET)
                                        print_selected_addrinfo(ifi,
                                                                ainfo->head,
index ae1c70ebcc814cb8bf11985879d773796fa084d8..58af402cc5ebb1202d860ccfc51e1e59750d2c7c 100644 (file)
@@ -1036,7 +1036,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
                return -2;
 
        if (brief)
-               print_linkinfo_brief(NULL, &answer.n, stdout);
+               print_linkinfo_brief(NULL, &answer.n, stdout, NULL);
        else
                print_linkinfo(NULL, &answer.n, stdout);