]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_drr.c
tc: code cleanup
[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>
16#include <syslog.h>
17#include <fcntl.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_util.h"
25
26static void explain(void)
27{
28 fprintf(stderr, "Usage: ... drr\n");
29}
30
31static void explain2(void)
32{
33 fprintf(stderr, "Usage: ... drr quantum SIZE\n");
34}
35
c86f3494
PM
36
37static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
38{
5582c0cf 39 while (argc) {
c86f3494
PM
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 }
c86f3494
PM
48 }
49 return 0;
50}
51
52static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
53 struct nlmsghdr *n)
54{
55 struct rtattr *tail;
56 __u32 tmp;
57
58 tail = NLMSG_TAIL(n);
59 addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
60
61 while (argc > 0) {
62 if (strcmp(*argv, "quantum") == 0) {
63 NEXT_ARG();
64 if (get_size(&tmp, *argv)) {
65 fprintf(stderr, "Illegal \"quantum\"\n");
66 return -1;
67 }
68 addattr_l(n, 1024, TCA_DRR_QUANTUM, &tmp, sizeof(tmp));
69 } else if (strcmp(*argv, "help") == 0) {
70 explain2();
71 return -1;
72 } else {
73 fprintf(stderr, "What is \"%s\"?\n", *argv);
74 explain2();
75 return -1;
76 }
77 argc--; argv++;
78 }
79
80 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail;
81 return 0;
82}
83
84static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
85{
86 struct rtattr *tb[TCA_DRR_MAX + 1];
32a121cb 87
c86f3494
PM
88 SPRINT_BUF(b1);
89
90 if (opt == NULL)
91 return 0;
92
93 parse_rtattr_nested(tb, TCA_DRR_MAX, opt);
94
95 if (tb[TCA_DRR_QUANTUM])
96 fprintf(f, "quantum %s ",
ff24746c 97 sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1));
c86f3494
PM
98 return 0;
99}
100
101static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
102{
103 struct tc_drr_stats *x;
32a121cb 104
c86f3494
PM
105 SPRINT_BUF(b1);
106
107 if (xstats == NULL)
108 return 0;
109 if (RTA_PAYLOAD(xstats) < sizeof(*x))
110 return -1;
111 x = RTA_DATA(xstats);
112
113 fprintf(f, " deficit %s ", sprint_size(x->deficit, b1));
114 return 0;
115}
116
117struct qdisc_util drr_qdisc_util = {
118 .id = "drr",
119 .parse_qopt = drr_parse_opt,
120 .print_qopt = drr_print_opt,
121 .print_xstats = drr_print_xstats,
122 .parse_copt = drr_parse_class_opt,
123 .print_copt = drr_print_opt,
124};