]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
link dump filter
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Wed, 16 Jul 2014 14:13:25 +0000 (07:13 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 4 Aug 2014 16:32:13 +0000 (09:32 -0700)
This patch avoids a full link wildump request when the user has specified
a single link. Uses RTM_GETLINK without the NLM_F_DUMP flag.

This helps on a system with large number of interfaces.

This patch currently only uses the link ifindex in the filter.
Hoping to provide a subsequent kernel patch to do link dump filtering on
other attributes in the kernel.

In iplink_get, to be safe, this patch currently sets the answer buffer
size to the max size that libnetlink rtnl_talk can copy. The current api
does not seem to provide a way to indicate the answer buf size.

changelog from RFC to v1:
    - incorporated comments from stephen (fixed comment and fixed if/else block)

changelog from v1 to v2:
    - fix whitespaces error

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
ip/ip_common.h
ip/ipaddress.c
ip/iplink.c

index ac1e4c195e00de60617bc89451a28529ede4153f..e56d1ac505a56bc0c663e3520a6fc4302333e0a0 100644 (file)
@@ -51,6 +51,7 @@ extern int do_ipl2tp(int argc, char **argv);
 extern int do_tcp_metrics(int argc, char **argv);
 extern int do_ipnetconf(int argc, char **argv);
 extern int do_iptoken(int argc, char **argv);
+extern int iplink_get(unsigned int flags, char *name, __u32 filt_mask);
 
 static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
 {
index 8bb8511977adfe5ca85bf43da81aaa37f1c90d95..245df39179a911cc28ddde5fa3201d22d238224b 100644 (file)
@@ -1241,6 +1241,19 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
                exit(0);
        }
 
+       /*
+        * If only filter_dev present and none of the other
+        * link filters are present, use RTM_GETLINK to get
+        * the link device
+        */
+       if (filter_dev && filter.group == -1 && do_link == 1) {
+               if (iplink_get(0, filter_dev, RTEXT_FILTER_VF) < 0) {
+                       perror("Cannot send link get request");
+                       exit(1);
+               }
+               exit(0);
+       }
+
        if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
                perror("Cannot send dump request");
                exit(1);
index 5e428da59bfbe32336c20a5ec9ef49f2da51d041..18fb1ccd779a8f4305d8d82b2d58f3d83fae565a 100644 (file)
@@ -709,6 +709,38 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
        return 0;
 }
 
+int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
+{
+       int len;
+       struct iplink_req req;
+       char answer[16384];
+
+       memset(&req, 0, sizeof(req));
+
+       req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+       req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+       req.n.nlmsg_type = RTM_GETLINK;
+       req.i.ifi_family = preferred_family;
+
+       if (name) {
+               len = strlen(name) + 1;
+               if (len == 1)
+                       invarg("\"\" is not a valid device identifier\n",
+                                  "name");
+               if (len > IFNAMSIZ)
+                       invarg("\"name\" too long\n", name);
+               addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name, len);
+       }
+       addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
+
+       if (rtnl_talk(&rth, &req.n, 0, 0, (struct nlmsghdr *)answer) < 0)
+               return -2;
+
+       print_linkinfo(NULL, (struct nlmsghdr *)answer, stdout);
+
+       return 0;
+}
+
 #if IPLINK_IOCTL_COMPAT
 static int get_ctl_fd(void)
 {