19d819974bb27fe5f4b2ab4e7a3225a2df6c76be
[openwrt/staging/chunkeey.git] / package / network / utils / iproute2 / patches / 200-add-tc_esfq.patch
1 --- a/tc/Makefile
2 +++ b/tc/Makefile
3 @@ -8,6 +8,7 @@ SHARED_LIBS ?= y
4 TCMODULES :=
5 TCMODULES += q_fifo.o
6 TCMODULES += q_sfq.o
7 +TCMODULES += q_esfq.o
8 TCMODULES += q_red.o
9 TCMODULES += q_prio.o
10 TCMODULES += q_tbf.o
11 --- a/include/linux/pkt_sched.h
12 +++ b/include/linux/pkt_sched.h
13 @@ -226,6 +226,33 @@ struct tc_sfq_xstats {
14 __s32 allot;
15 };
16
17 +/* ESFQ section */
18 +
19 +enum
20 +{
21 + /* traditional */
22 + TCA_SFQ_HASH_CLASSIC,
23 + TCA_SFQ_HASH_DST,
24 + TCA_SFQ_HASH_SRC,
25 + TCA_SFQ_HASH_FWMARK,
26 + /* conntrack */
27 + TCA_SFQ_HASH_CTORIGDST,
28 + TCA_SFQ_HASH_CTORIGSRC,
29 + TCA_SFQ_HASH_CTREPLDST,
30 + TCA_SFQ_HASH_CTREPLSRC,
31 + TCA_SFQ_HASH_CTNATCHG,
32 +};
33 +
34 +struct tc_esfq_qopt
35 +{
36 + unsigned quantum; /* Bytes per round allocated to flow */
37 + int perturb_period; /* Period of hash perturbation */
38 + __u32 limit; /* Maximal packets in queue */
39 + unsigned divisor; /* Hash divisor */
40 + unsigned flows; /* Maximal number of flows */
41 + unsigned hash_kind; /* Hash function to use for flow identification */
42 +};
43 +
44 /* RED section */
45
46 enum {
47 --- /dev/null
48 +++ b/tc/q_esfq.c
49 @@ -0,0 +1,200 @@
50 +/*
51 + * q_esfq.c ESFQ.
52 + *
53 + * This program is free software; you can redistribute it and/or
54 + * modify it under the terms of the GNU General Public License
55 + * as published by the Free Software Foundation; either version
56 + * 2 of the License, or (at your option) any later version.
57 + *
58 + * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
59 + *
60 + * Changes: Alexander Atanasov, <alex@ssi.bg>
61 + * Alexander Clouter, <alex@digriz.org.uk>
62 + * Corey Hickey, <bugfood-c@fatooh.org>
63 + *
64 + */
65 +
66 +#include <stdio.h>
67 +#include <stdlib.h>
68 +#include <unistd.h>
69 +#include <syslog.h>
70 +#include <fcntl.h>
71 +#include <math.h>
72 +#include <sys/socket.h>
73 +#include <netinet/in.h>
74 +#include <arpa/inet.h>
75 +#include <string.h>
76 +
77 +#include "utils.h"
78 +#include "tc_util.h"
79 +
80 +static void explain(void)
81 +{
82 + fprintf(stderr, "Usage: ... esfq [ perturb SECS ] [ quantum BYTES ] [ depth FLOWS ]\n\t[ divisor HASHBITS ] [ limit PKTS ] [ hash HASHTYPE]\n");
83 + fprintf(stderr,"Where: \n");
84 + fprintf(stderr,"HASHTYPE := { classic | src | dst | ctorigdst | ctorigsrc | ctrepldst | ctreplsrc | ctnatchg }\n");
85 +}
86 +
87 +#define usage() return(-1)
88 +
89 +static int esfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
90 +{
91 + int ok=0;
92 + struct tc_esfq_qopt opt;
93 +
94 + memset(&opt, 0, sizeof(opt));
95 +
96 + opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
97 +
98 + while (argc > 0) {
99 + if (strcmp(*argv, "quantum") == 0) {
100 + NEXT_ARG();
101 + if (get_size(&opt.quantum, *argv)) {
102 + fprintf(stderr, "Illegal \"quantum\"\n");
103 + return -1;
104 + }
105 + ok++;
106 + } else if (strcmp(*argv, "perturb") == 0) {
107 + NEXT_ARG();
108 + if (get_integer(&opt.perturb_period, *argv, 0)) {
109 + fprintf(stderr, "Illegal \"perturb\"\n");
110 + return -1;
111 + }
112 + ok++;
113 + } else if (strcmp(*argv, "depth") == 0) {
114 + NEXT_ARG();
115 + if (get_integer((int *) &opt.flows, *argv, 0)) {
116 + fprintf(stderr, "Illegal \"depth\"\n");
117 + return -1;
118 + }
119 + ok++;
120 + } else if (strcmp(*argv, "divisor") == 0) {
121 + NEXT_ARG();
122 + if (get_integer((int *) &opt.divisor, *argv, 0)) {
123 + fprintf(stderr, "Illegal \"divisor\"\n");
124 + return -1;
125 + }
126 + if(opt.divisor >= 14) {
127 + fprintf(stderr, "Illegal \"divisor\": must be < 14\n");
128 + return -1;
129 + }
130 + opt.divisor=pow(2,opt.divisor);
131 + ok++;
132 + } else if (strcmp(*argv, "limit") == 0) {
133 + NEXT_ARG();
134 + if (get_integer((int *) &opt.limit, *argv, 0)) {
135 + fprintf(stderr, "Illegal \"limit\"\n");
136 + return -1;
137 + }
138 + ok++;
139 + } else if (strcmp(*argv, "hash") == 0) {
140 + NEXT_ARG();
141 + if(strcmp(*argv, "classic") == 0) {
142 + opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
143 + } else
144 + if(strcmp(*argv, "dst") == 0) {
145 + opt.hash_kind= TCA_SFQ_HASH_DST;
146 + } else
147 + if(strcmp(*argv, "src") == 0) {
148 + opt.hash_kind= TCA_SFQ_HASH_SRC;
149 + } else
150 + if(strcmp(*argv, "ctorigsrc") == 0) {
151 + opt.hash_kind= TCA_SFQ_HASH_CTORIGSRC;
152 + } else
153 + if(strcmp(*argv, "ctorigdst") == 0) {
154 + opt.hash_kind= TCA_SFQ_HASH_CTORIGDST;
155 + } else
156 + if(strcmp(*argv, "ctreplsrc") == 0) {
157 + opt.hash_kind= TCA_SFQ_HASH_CTREPLSRC;
158 + } else
159 + if(strcmp(*argv, "ctrepldst") == 0) {
160 + opt.hash_kind= TCA_SFQ_HASH_CTREPLDST;
161 + } else
162 + if(strcmp(*argv, "ctnatchg") == 0) {
163 + opt.hash_kind= TCA_SFQ_HASH_CTNATCHG;
164 + } else {
165 + fprintf(stderr, "Illegal \"hash\"\n");
166 + explain();
167 + return -1;
168 + }
169 + ok++;
170 + } else if (strcmp(*argv, "help") == 0) {
171 + explain();
172 + return -1;
173 + } else {
174 + fprintf(stderr, "What is \"%s\"?\n", *argv);
175 + explain();
176 + return -1;
177 + }
178 + argc--; argv++;
179 + }
180 +
181 + if (ok)
182 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
183 + return 0;
184 +}
185 +
186 +static int esfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
187 +{
188 + struct tc_esfq_qopt *qopt;
189 + SPRINT_BUF(b1);
190 +
191 + if (opt == NULL)
192 + return 0;
193 +
194 + if (RTA_PAYLOAD(opt) < sizeof(*qopt))
195 + return -1;
196 + qopt = RTA_DATA(opt);
197 + fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
198 + if (show_details) {
199 + fprintf(f, "limit %up flows %u/%u ",
200 + qopt->limit, qopt->flows, qopt->divisor);
201 + }
202 + if (qopt->perturb_period)
203 + fprintf(f, "perturb %dsec ", qopt->perturb_period);
204 +
205 + fprintf(f,"hash: ");
206 + switch(qopt->hash_kind)
207 + {
208 + case TCA_SFQ_HASH_CLASSIC:
209 + fprintf(f,"classic");
210 + break;
211 + case TCA_SFQ_HASH_DST:
212 + fprintf(f,"dst");
213 + break;
214 + case TCA_SFQ_HASH_SRC:
215 + fprintf(f,"src");
216 + break;
217 + case TCA_SFQ_HASH_CTORIGSRC:
218 + fprintf(f,"ctorigsrc");
219 + break;
220 + case TCA_SFQ_HASH_CTORIGDST:
221 + fprintf(f,"ctorigdst");
222 + break;
223 + case TCA_SFQ_HASH_CTREPLSRC:
224 + fprintf(f,"ctreplsrc");
225 + break;
226 + case TCA_SFQ_HASH_CTREPLDST:
227 + fprintf(f,"ctrepldst");
228 + break;
229 + case TCA_SFQ_HASH_CTNATCHG:
230 + fprintf(f,"ctnatchg");
231 + break;
232 + default:
233 + fprintf(f,"Unknown");
234 + }
235 + return 0;
236 +}
237 +
238 +static int esfq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
239 +{
240 + return 0;
241 +}
242 +
243 +
244 +struct qdisc_util esfq_qdisc_util = {
245 + .id = "esfq",
246 + .parse_qopt = esfq_parse_opt,
247 + .print_qopt = esfq_print_opt,
248 + .print_xstats = esfq_print_xstats,
249 +};