]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_drr.c
tc: B.W limits can now be specified in %.
[mirror_iproute2.git] / tc / q_drr.c
CommitLineData
c86f3494
PM
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>
c86f3494
PM
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
c86f3494 35
927e3cfb 36static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev)
c86f3494 37{
5582c0cf 38 while (argc) {
c86f3494
PM
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 }
c86f3494
PM
47 }
48 return 0;
49}
50
51static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
927e3cfb 52 struct nlmsghdr *n, const char *dev)
c86f3494
PM
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
83static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
84{
85 struct rtattr *tb[TCA_DRR_MAX + 1];
32a121cb 86
c86f3494
PM
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 ",
ff24746c 96 sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1));
c86f3494
PM
97 return 0;
98}
99
100static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
101{
102 struct tc_drr_stats *x;
32a121cb 103
c86f3494
PM
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
116struct 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};