]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_drr.c
tc: B.W limits can now be specified in %.
[mirror_iproute2.git] / tc / q_drr.c
1 /*
2 * q_drr.c DRR.
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: Patrick McHardy <kaber@trash.net>
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
25 static void explain(void)
26 {
27 fprintf(stderr, "Usage: ... drr\n");
28 }
29
30 static void explain2(void)
31 {
32 fprintf(stderr, "Usage: ... drr quantum SIZE\n");
33 }
34
35
36 static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
37 {
38 while (argc) {
39 if (strcmp(*argv, "help") == 0) {
40 explain();
41 return -1;
42 } else {
43 fprintf(stderr, "What is \"%s\"?\n", *argv);
44 explain();
45 return -1;
46 }
47 }
48 return 0;
49 }
50
51 static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
52 struct nlmsghdr *n, const char *dev)
53 {
54 struct rtattr *tail;
55 __u32 tmp;
56
57 tail = NLMSG_TAIL(n);
58 addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
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 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;
80 return 0;
81 }
82
83 static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
84 {
85 struct rtattr *tb[TCA_DRR_MAX + 1];
86
87 SPRINT_BUF(b1);
88
89 if (opt == NULL)
90 return 0;
91
92 parse_rtattr_nested(tb, TCA_DRR_MAX, opt);
93
94 if (tb[TCA_DRR_QUANTUM])
95 fprintf(f, "quantum %s ",
96 sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1));
97 return 0;
98 }
99
100 static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
101 {
102 struct tc_drr_stats *x;
103
104 SPRINT_BUF(b1);
105
106 if (xstats == NULL)
107 return 0;
108 if (RTA_PAYLOAD(xstats) < sizeof(*x))
109 return -1;
110 x = RTA_DATA(xstats);
111
112 fprintf(f, " deficit %s ", sprint_size(x->deficit, b1));
113 return 0;
114 }
115
116 struct qdisc_util drr_qdisc_util = {
117 .id = "drr",
118 .parse_qopt = drr_parse_opt,
119 .print_qopt = drr_print_opt,
120 .print_xstats = drr_print_xstats,
121 .parse_copt = drr_parse_class_opt,
122 .print_copt = drr_print_opt,
123 };