Stephen Hemminger | 2b99748 | 2017-02-20 08:53:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * iplink_stats.c Extended statistics commands |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> |
| 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | #include <linux/if_link.h> |
| 16 | #include <netinet/ether.h> |
| 17 | |
| 18 | #include "utils.h" |
| 19 | #include "ip_common.h" |
| 20 | |
| 21 | static void print_explain(FILE *f) |
| 22 | { |
| 23 | fprintf(f, "Usage: ... xstats type TYPE [ ARGS ]\n"); |
| 24 | } |
| 25 | |
| 26 | int iplink_ifla_xstats(int argc, char **argv) |
| 27 | { |
| 28 | struct link_util *lu = NULL; |
| 29 | __u32 filt_mask; |
| 30 | |
| 31 | if (!argc) { |
| 32 | fprintf(stderr, "xstats: missing argument\n"); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | if (matches(*argv, "type") == 0) { |
| 37 | NEXT_ARG(); |
| 38 | lu = get_link_kind(*argv); |
| 39 | if (!lu) |
| 40 | invarg("invalid type", *argv); |
| 41 | } else if (matches(*argv, "help") == 0) { |
| 42 | print_explain(stdout); |
| 43 | return 0; |
| 44 | } else { |
| 45 | invarg("unknown argument", *argv); |
| 46 | } |
| 47 | |
| 48 | if (!lu) { |
| 49 | print_explain(stderr); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | if (!lu->print_ifla_xstats) { |
| 54 | fprintf(stderr, "xstats: link type %s doesn't support xstats\n", |
| 55 | lu->id); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | if (lu->parse_ifla_xstats && |
| 60 | lu->parse_ifla_xstats(lu, argc-1, argv+1)) |
| 61 | return -1; |
| 62 | |
| 63 | if (strstr(lu->id, "_slave")) |
| 64 | filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE); |
| 65 | else |
| 66 | filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS); |
| 67 | |
| 68 | if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, |
| 69 | RTM_GETSTATS, |
| 70 | filt_mask) < 0) { |
| 71 | perror("Cannont send dump request"); |
| 72 | return -1; |
| 73 | } |
| 74 | |
| 75 | if (rtnl_dump_filter(&rth, lu->print_ifla_xstats, stdout) < 0) { |
| 76 | fprintf(stderr, "Dump terminated\n"); |
| 77 | return -1; |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |