Debian Codegraph @

tc/q_drr.c

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * q_drr.c DRR.
4 *
5 * Authors: Patrick McHardy <[email protected]>
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <string.h>
16
17 #include "utils.h"
18 #include "tc_util.h"
19
20 static void explain(void)
21 {
22 fprintf(stderr, "Usage: ... drr\n");
23 }
24
25 static void explain2(void)
26 {
27 fprintf(stderr, "Usage: ... drr quantum SIZE\n");
28 }
29
30
31 static int drr_parse_opt(const struct qdisc_util *qu, int argc, char **argv,
32 struct nlmsghdr *n, const char *dev)
33 {
34 while (argc) {
35 if (strcmp(*argv, "help") == 0) {
36 explain();
37 return -1;
38 } else {
39 fprintf(stderr, "What is \"%s\"?\n", *argv);
40 explain();
41 return -1;
42 }
43 }
44 return 0;
45 }
46
47 static int drr_parse_class_opt(const struct qdisc_util *qu, int argc, char **argv,
48 struct nlmsghdr *n, const char *dev)
49 {
50 struct rtattr *tail;
51 __u32 tmp;
52
53 tail = addattr_nest(n, 1024, TCA_OPTIONS);
54
55 while (argc > 0) {
56 if (strcmp(*argv, "quantum") == 0) {
57 NEXT_ARG();
58 if (get_size(&tmp, *argv)) {
59 fprintf(stderr, "Illegal \"quantum\"\n");
60 return -1;
61 }
62 addattr_l(n, 1024, TCA_DRR_QUANTUM, &tmp, sizeof(tmp));
63 } else if (strcmp(*argv, "help") == 0) {
64 explain2();
65 return -1;
66 } else {
67 fprintf(stderr, "What is \"%s\"?\n", *argv);
68 explain2();
69 return -1;
70 }
71 argc--; argv++;
72 }
73
74 addattr_nest_end(n, tail);
75 return 0;
76 }
77
78 static int drr_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt)
79 {
80 struct rtattr *tb[TCA_DRR_MAX + 1];
81
82 if (opt == NULL)
83 return 0;
84
85 parse_rtattr_nested(tb, TCA_DRR_MAX, opt);
86
87 if (tb[TCA_DRR_QUANTUM])
88 print_size(PRINT_FP, NULL, "quantum %s ",
89 rta_getattr_u32(tb[TCA_DRR_QUANTUM]));
90 return 0;
91 }
92
93 static int drr_print_xstats(const struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
94 {
95 struct tc_drr_stats *x;
96
97 if (xstats == NULL)
98 return 0;
99 if (RTA_PAYLOAD(xstats) < sizeof(*x))
100 return -1;
101 x = RTA_DATA(xstats);
102
103 print_size(PRINT_FP, NULL, " deficit %s ", x->deficit);
104 return 0;
105 }
106
107 struct qdisc_util drr_qdisc_util = {
108 .id = "drr",
109 .parse_qopt = drr_parse_opt,
110 .print_qopt = drr_print_opt,
111 .print_xstats = drr_print_xstats,
112 .parse_copt = drr_parse_class_opt,
113 .print_copt = drr_print_opt,
114 };