1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* iplink_stats.c Extended statistics commands
*
* 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_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask,
NULL, NULL) < 0) {
perror("Cannot send dump request");
return -1;
}
new_json_obj(json);
if (rtnl_dump_filter(&rth, lu->print_ifla_xstats, stdout) < 0) {
delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -1;
}
delete_json_obj();
return 0;
}
|