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