]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_drr.c
vdpa: add .gitignore
[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
859af0a5
SH
36static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv,
37 struct nlmsghdr *n, const char *dev)
c86f3494 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,
927e3cfb 53 struct nlmsghdr *n, const char *dev)
c86f3494
PM
54{
55 struct rtattr *tail;
56 __u32 tmp;
57
c14f9d92 58 tail = addattr_nest(n, 1024, TCA_OPTIONS);
c86f3494
PM
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
c14f9d92 79 addattr_nest_end(n, tail);
c86f3494
PM
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 if (opt == NULL)
88 return 0;
89
90 parse_rtattr_nested(tb, TCA_DRR_MAX, opt);
91
92 if (tb[TCA_DRR_QUANTUM])
adbe5de9
PM
93 print_size(PRINT_FP, NULL, "quantum %s ",
94 rta_getattr_u32(tb[TCA_DRR_QUANTUM]));
c86f3494
PM
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;
32a121cb 101
c86f3494
PM
102 if (xstats == NULL)
103 return 0;
104 if (RTA_PAYLOAD(xstats) < sizeof(*x))
105 return -1;
106 x = RTA_DATA(xstats);
107
adbe5de9 108 print_size(PRINT_FP, NULL, " deficit %s ", x->deficit);
c86f3494
PM
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};