]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
add missing iplink_xstats.c
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 20 Feb 2017 16:53:25 +0000 (08:53 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 20 Feb 2017 16:53:40 +0000 (08:53 -0800)
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iplink_xstats.c [new file with mode: 0644]

diff --git a/ip/iplink_xstats.c b/ip/iplink_xstats.c
new file mode 100644 (file)
index 0000000..10f953b
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * iplink_stats.c       Extended statistics commands
+ *
+ *              This program is free software; you can redistribute it and/or
+ *              modify it under the terms of the GNU General Public License
+ *              as published by the Free Software Foundation; either version
+ *              2 of the License, or (at your option) any later version.
+ *
+ * Authors:     Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/if_link.h>
+#include <netinet/ether.h>
+
+#include "utils.h"
+#include "ip_common.h"
+
+static void print_explain(FILE *f)
+{
+       fprintf(f, "Usage: ... xstats type TYPE [ ARGS ]\n");
+}
+
+int iplink_ifla_xstats(int argc, char **argv)
+{
+       struct link_util *lu = NULL;
+       __u32 filt_mask;
+
+       if (!argc) {
+               fprintf(stderr, "xstats: missing argument\n");
+               return -1;
+       }
+
+       if (matches(*argv, "type") == 0) {
+               NEXT_ARG();
+               lu = get_link_kind(*argv);
+               if (!lu)
+                       invarg("invalid type", *argv);
+       } else if (matches(*argv, "help") == 0) {
+               print_explain(stdout);
+               return 0;
+       } else {
+               invarg("unknown argument", *argv);
+       }
+
+       if (!lu) {
+               print_explain(stderr);
+               return -1;
+       }
+
+       if (!lu->print_ifla_xstats) {
+               fprintf(stderr, "xstats: link type %s doesn't support xstats\n",
+                       lu->id);
+               return -1;
+       }
+
+       if (lu->parse_ifla_xstats &&
+           lu->parse_ifla_xstats(lu, argc-1, argv+1))
+               return -1;
+
+       if (strstr(lu->id, "_slave"))
+               filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE);
+       else
+               filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS);
+
+       if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC,
+                                          RTM_GETSTATS,
+                                          filt_mask) < 0) {
+               perror("Cannont send dump request");
+               return -1;
+       }
+
+       if (rtnl_dump_filter(&rth, lu->print_ifla_xstats, stdout) < 0) {
+               fprintf(stderr, "Dump terminated\n");
+               return -1;
+       }
+
+       return 0;
+}