blob: 79c81a22c3d27a8b5f4b01b88b14c3ad951fe9b7 [file] [log] [blame]
Patrick McHardyc86f3492008-11-19 16:08:05 +01001/*
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
Patrick McHardyc86f3492008-11-19 16:08:05 +010036
37static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
38{
Petr Sabata5582c0c2011-06-10 03:19:07 +000039 while (argc) {
Patrick McHardyc86f3492008-11-19 16:08:05 +010040 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 }
Patrick McHardyc86f3492008-11-19 16:08:05 +010048 }
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];
Stephen Hemminger32a121c2016-03-21 11:48:36 -070087
Patrick McHardyc86f3492008-11-19 16:08:05 +010088 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 ",
Stephen Hemmingerff247462012-04-10 08:47:55 -070097 sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1));
Patrick McHardyc86f3492008-11-19 16:08:05 +010098 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;
Stephen Hemminger32a121c2016-03-21 11:48:36 -0700104
Patrick McHardyc86f3492008-11-19 16:08:05 +0100105 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};