add options to make ppp connect faster
[openwrt.git] / obsolete-buildroot / sources / iproute2-htb3.6_tc.patch
1 --- iproute2/tc/q_htb.c Sun Oct 21 22:07:29 2001
2 +++ iproute2new/tc/q_htb.c Sun May 12 22:18:27 2002
3 @@ -0,0 +1,306 @@
4 +/*
5 + * q_htb.c HTB.
6 + *
7 + * This program is free software; you can redistribute it and/or
8 + * modify it under the terms of the GNU General Public License
9 + * as published by the Free Software Foundation; either version
10 + * 2 of the License, or (at your option) any later version.
11 + *
12 + * Authors: Martin Devera, devik@cdi.cz
13 + *
14 + */
15 +
16 +#include <stdio.h>
17 +#include <stdlib.h>
18 +#include <unistd.h>
19 +#include <syslog.h>
20 +#include <fcntl.h>
21 +#include <sys/socket.h>
22 +#include <netinet/in.h>
23 +#include <arpa/inet.h>
24 +#include <string.h>
25 +
26 +#include "utils.h"
27 +#include "tc_util.h"
28 +
29 +#define HTB_TC_VER 0x30003
30 +#if HTB_TC_VER >> 16 != TC_HTB_PROTOVER
31 +#error "Different kernel and TC HTB versions"
32 +#endif
33 +
34 +static void explain(void)
35 +{
36 + fprintf(stderr, "Usage: ... qdisc add ... htb [default N] [r2q N]\n"
37 + " default minor id of class to which unclassified packets are sent {0}\n"
38 + " r2q DRR quantums are computed as rate in Bps/r2q {10}\n"
39 + " debug string of 16 numbers each 0-3 {0}\n\n"
40 + "... class add ... htb rate R1 burst B1 [prio P] [slot S] [pslot PS]\n"
41 + " [ceil R2] [cburst B2] [mtu MTU] [quantum Q]\n"
42 + " rate rate allocated to this class (class can still borrow)\n"
43 + " burst max bytes burst which can be accumulated during idle period {computed}\n"
44 + " ceil definite upper class rate (no borrows) {rate}\n"
45 + " cburst burst but for ceil {computed}\n"
46 + " mtu max packet size we create rate map for {1600}\n"
47 + " prio priority of leaf; lower are served first {0}\n"
48 + " quantum how much bytes to serve from leaf at once {use r2q}\n"
49 + "\nTC HTB version %d.%d\n",HTB_TC_VER>>16,HTB_TC_VER&0xffff
50 + );
51 +}
52 +
53 +static void explain1(char *arg)
54 +{
55 + fprintf(stderr, "Illegal \"%s\"\n", arg);
56 + explain();
57 +}
58 +
59 +
60 +#define usage() return(-1)
61 +
62 +static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
63 +{
64 + struct tc_htb_glob opt;
65 + struct rtattr *tail;
66 + unsigned i; char *p;
67 + memset(&opt,0,sizeof(opt));
68 + opt.rate2quantum = 10;
69 + opt.version = 3;
70 +
71 + while (argc > 0) {
72 + if (matches(*argv, "r2q") == 0) {
73 + NEXT_ARG();
74 + if (get_u32(&opt.rate2quantum, *argv, 10)) {
75 + explain1("r2q"); return -1;
76 + }
77 + } else if (matches(*argv, "default") == 0) {
78 + NEXT_ARG();
79 + if (get_u32(&opt.defcls, *argv, 16)) {
80 + explain1("default"); return -1;
81 + }
82 + } else if (matches(*argv, "debug") == 0) {
83 + NEXT_ARG(); p = *argv;
84 + for (i=0; i<16; i++,p++) {
85 + if (*p<'0' || *p>'3') break;
86 + opt.debug |= (*p-'0')<<(2*i);
87 + }
88 + } else {
89 + fprintf(stderr, "What is \"%s\"?\n", *argv);
90 + explain();
91 + return -1;
92 + }
93 + argc--; argv++;
94 + }
95 + tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
96 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
97 + addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
98 + tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
99 + return 0;
100 +}
101 +
102 +static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
103 +{
104 + int ok=0;
105 + struct tc_htb_opt opt;
106 + __u32 rtab[256],ctab[256];
107 + unsigned buffer=0,cbuffer=0;
108 + int cell_log=-1,ccell_log = -1,mtu;
109 + struct rtattr *tail;
110 +
111 + memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
112 +
113 + while (argc > 0) {
114 + if (matches(*argv, "prio") == 0) {
115 + NEXT_ARG();
116 + if (get_u32(&opt.prio, *argv, 10)) {
117 + explain1("prio"); return -1;
118 + }
119 + ok++;
120 + } else if (matches(*argv, "mtu") == 0) {
121 + NEXT_ARG();
122 + if (get_u32(&mtu, *argv, 10)) {
123 + explain1("mtu"); return -1;
124 + }
125 + } else if (matches(*argv, "quantum") == 0) {
126 + NEXT_ARG();
127 + if (get_u32(&opt.quantum, *argv, 10)) {
128 + explain1("quantum"); return -1;
129 + }
130 + } else if (matches(*argv, "burst") == 0 ||
131 + strcmp(*argv, "buffer") == 0 ||
132 + strcmp(*argv, "maxburst") == 0) {
133 + NEXT_ARG();
134 + if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) {
135 + explain1("buffer");
136 + return -1;
137 + }
138 + ok++;
139 + } else if (matches(*argv, "cburst") == 0 ||
140 + strcmp(*argv, "cbuffer") == 0 ||
141 + strcmp(*argv, "cmaxburst") == 0) {
142 + NEXT_ARG();
143 + if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) {
144 + explain1("cbuffer");
145 + return -1;
146 + }
147 + ok++;
148 + } else if (strcmp(*argv, "ceil") == 0) {
149 + NEXT_ARG();
150 + if (opt.ceil.rate) {
151 + fprintf(stderr, "Double \"ceil\" spec\n");
152 + return -1;
153 + }
154 + if (get_rate(&opt.ceil.rate, *argv)) {
155 + explain1("ceil");
156 + return -1;
157 + }
158 + ok++;
159 + } else if (strcmp(*argv, "rate") == 0) {
160 + NEXT_ARG();
161 + if (opt.rate.rate) {
162 + fprintf(stderr, "Double \"rate\" spec\n");
163 + return -1;
164 + }
165 + if (get_rate(&opt.rate.rate, *argv)) {
166 + explain1("rate");
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 + return 0;*/
183 +
184 + if (opt.rate.rate == 0) {
185 + fprintf(stderr, "\"rate\" is required.\n");
186 + return -1;
187 + }
188 + /* if ceil params are missing, use the same as rate */
189 + if (!opt.ceil.rate) opt.ceil = opt.rate;
190 +
191 + /* compute minimal allowed burst from rate; mtu is added here to make
192 + sute that buffer is larger than mtu and to have some safeguard space */
193 + if (!buffer) buffer = opt.rate.rate / HZ + mtu;
194 + if (!cbuffer) cbuffer = opt.ceil.rate / HZ + mtu;
195 +
196 + if ((cell_log = tc_calc_rtable(opt.rate.rate, rtab, cell_log, mtu, 0)) < 0) {
197 + fprintf(stderr, "htb: failed to calculate rate table.\n");
198 + return -1;
199 + }
200 + opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer);
201 + opt.rate.cell_log = cell_log;
202 +
203 + if ((ccell_log = tc_calc_rtable(opt.ceil.rate, ctab, cell_log, mtu, 0)) < 0) {
204 + fprintf(stderr, "htb: failed to calculate ceil rate table.\n");
205 + return -1;
206 + }
207 + opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
208 + opt.ceil.cell_log = ccell_log;
209 +
210 + tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
211 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
212 + addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
213 + addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
214 + addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
215 + tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
216 + return 0;
217 +}
218 +
219 +static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
220 +{
221 + struct rtattr *tb[TCA_HTB_RTAB+1];
222 + struct tc_htb_opt *hopt;
223 + struct tc_htb_glob *gopt;
224 + double buffer,cbuffer;
225 + SPRINT_BUF(b1);
226 + SPRINT_BUF(b2);
227 +
228 + if (opt == NULL)
229 + return 0;
230 +
231 + memset(tb, 0, sizeof(tb));
232 + parse_rtattr(tb, TCA_HTB_RTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));
233 +
234 + if (tb[TCA_HTB_PARMS]) {
235 +
236 + hopt = RTA_DATA(tb[TCA_HTB_PARMS]);
237 + if (RTA_PAYLOAD(tb[TCA_HTB_PARMS]) < sizeof(*hopt)) return -1;
238 +
239 + if (!hopt->level) {
240 + fprintf(f, "prio %d ", (int)hopt->prio);
241 + if (show_details)
242 + fprintf(f, "quantum %d ", (int)hopt->quantum);
243 + }
244 + fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
245 + buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
246 + fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
247 + cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
248 + if (show_details) {
249 + fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
250 + 1<<hopt->rate.cell_log, sprint_size(hopt->rate.mpu, b2));
251 + fprintf(f, "cburst %s/%u mpu %s ", sprint_size(cbuffer, b1),
252 + 1<<hopt->ceil.cell_log, sprint_size(hopt->ceil.mpu, b2));
253 + fprintf(f, "level %d ", (int)hopt->level);
254 + } else {
255 + fprintf(f, "burst %s ", sprint_size(buffer, b1));
256 + fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
257 + }
258 + if (show_raw)
259 + fprintf(f, "buffer [%08x] cbuffer [%08x] ",
260 + hopt->buffer,hopt->cbuffer);
261 + }
262 + if (tb[TCA_HTB_INIT]) {
263 + gopt = RTA_DATA(tb[TCA_HTB_INIT]);
264 + if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
265 +
266 + fprintf(f, "r2q %d default %x direct_packets_stat %u",
267 + gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
268 + if (show_details)
269 + fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
270 + }
271 + return 0;
272 +}
273 +
274 +static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
275 +{
276 + struct tc_htb_xstats *st;
277 + if (xstats == NULL)
278 + return 0;
279 +
280 + if (RTA_PAYLOAD(xstats) < sizeof(*st))
281 + return -1;
282 +
283 + st = RTA_DATA(xstats);
284 + fprintf(f, " lended: %u borrowed: %u giants: %u\n",
285 + st->lends,st->borrows,st->giants);
286 + fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
287 + return 0;
288 +}
289 +
290 +struct qdisc_util htb_util = {
291 + NULL,
292 + "htb",
293 + htb_parse_opt,
294 + htb_print_opt,
295 + htb_print_xstats,
296 + htb_parse_class_opt,
297 + htb_print_opt,
298 +};
299 +
300 +/* for testing of old one */
301 +struct qdisc_util htb2_util = {
302 + NULL,
303 + "htb2",
304 + htb_parse_opt,
305 + htb_print_opt,
306 + htb_print_xstats,
307 + htb_parse_class_opt,
308 + htb_print_opt,
309 +};
310 --- iproute2/tc/Makefile Tue Jul 6 18:13:07 1999
311 +++ iproute2new/tc/Makefile Thu May 9 12:34:19 2002
312 @@ -21,6 +21,7 @@ ifeq ($(TC_CONFIG_DIFFSERV),y)
313 endif
314
315 #TCMODULES += q_csz.o
316 +TCMODULES += q_htb.o
317 #TCMODULES += q_hpfq.o
318 #TCMODULES += q_hfsc.o
319
This page took 0.061048 seconds and 5 git commands to generate.