nbd's makefile/menuconfig rewrite
[openwrt.git] / package / iproute2 / patches / debian-patches-3.patch
1 --- iproute-20041019.orig/ip/Makefile
2 +++ iproute-20041019/ip/Makefile
3 @@ -6,7 +6,7 @@
4  RTMONOBJ=rtmon.o
5  
6  ALLOBJ=$(IPOBJ) $(RTMONOBJ)
7 -TARGETS=ip rtmon ifcfg rtpr
8 +TARGETS=ip rtmon
9  
10  all: $(TARGETS)
11  
12 --- iproute-20041019.orig/tc/q_htb.c
13 +++ iproute-20041019/tc/q_htb.c
14 @@ -1,3 +1,311 @@
15 +#if 0
16 +/*
17 + * q_htb.c             HTB.
18 + *
19 + *             This program is free software; you can redistribute it and/or
20 + *             modify it under the terms of the GNU General Public License
21 + *             as published by the Free Software Foundation; either version
22 + *             2 of the License, or (at your option) any later version.
23 + *
24 + * Authors:    Martin Devera, devik@cdi.cz
25 + *
26 + */
27 +
28 +#include <stdio.h>
29 +#include <stdlib.h>
30 +#include <unistd.h>
31 +#include <syslog.h>
32 +#include <fcntl.h>
33 +#include <sys/socket.h>
34 +#include <netinet/in.h>
35 +#include <arpa/inet.h>
36 +#include <string.h>
37 +
38 +#include "utils.h"
39 +#include "tc_util.h"
40 +
41 +#define HTB_TC_VER 0x30003
42 +#if HTB_TC_VER >> 16 != TC_HTB_PROTOVER
43 +#error "Different kernel and TC HTB versions"
44 +#endif
45 +
46 +static void explain(void)
47 +{
48 +       fprintf(stderr, "Usage: ... qdisc add ... htb [default N] [r2q N]\n"
49 +               " default  minor id of class to which unclassified packets are sent {0}\n"
50 +               " r2q      DRR quantums are computed as rate in Bps/r2q {10}\n"
51 +               " debug    string of 16 numbers each 0-3 {0}\n\n"
52 +               "... class add ... htb rate R1 burst B1 [prio P] [slot S] [pslot PS]\n"
53 +               "                      [ceil R2] [cburst B2] [mtu MTU] [quantum Q]\n"
54 +               " rate     rate allocated to this class (class can still borrow)\n"
55 +               " burst    max bytes burst which can be accumulated during idle period {computed}\n"
56 +               " ceil     definite upper class rate (no borrows) {rate}\n"
57 +               " cburst   burst but for ceil {computed}\n"
58 +               " mtu      max packet size we create rate map for {1600}\n"
59 +               " prio     priority of leaf; lower are served first {0}\n"
60 +               " quantum  how much bytes to serve from leaf at once {use r2q}\n"
61 +               "\nTC HTB version %d.%d\n",HTB_TC_VER>>16,HTB_TC_VER&0xffff
62 +               );
63 +}
64 +
65 +static void explain1(char *arg)
66 +{
67 +    fprintf(stderr, "Illegal \"%s\"\n", arg);
68 +    explain();
69 +}
70 +
71 +
72 +#define usage() return(-1)
73 +
74 +static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
75 +{
76 +       struct tc_htb_glob opt;
77 +       struct rtattr *tail;
78 +       unsigned i; char *p;
79 +       memset(&opt,0,sizeof(opt));
80 +       opt.rate2quantum = 10;
81 +       opt.version = 3;
82 +
83 +       while (argc > 0) {
84 +               if (matches(*argv, "r2q") == 0) {
85 +                   NEXT_ARG();
86 +                   if (get_u32(&opt.rate2quantum, *argv, 10)) {
87 +                       explain1("r2q"); return -1;
88 +                   }
89 +               } else if (matches(*argv, "default") == 0) {
90 +                   NEXT_ARG();
91 +                   if (get_u32(&opt.defcls, *argv, 16)) {
92 +                       explain1("default"); return -1;
93 +                   }
94 +               } else if (matches(*argv, "debug") == 0) {
95 +                   NEXT_ARG(); p = *argv;
96 +                   for (i=0; i<16; i++,p++) {
97 +                       if (*p<'0' || *p>'3') break;
98 +                       opt.debug |= (*p-'0')<<(2*i);
99 +                   }
100 +               } else {
101 +                       fprintf(stderr, "What is \"%s\"?\n", *argv);
102 +                       explain();
103 +                       return -1;
104 +               }
105 +               argc--; argv++;
106 +       }
107 +       tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
108 +       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
109 +       addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
110 +       tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
111 +       return 0;
112 +}
113 +
114 +static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
115 +{
116 +       int ok=0;
117 +       struct tc_htb_opt opt;
118 +       __u32 rtab[256],ctab[256];
119 +       unsigned buffer=0,cbuffer=0;
120 +       int cell_log=-1,ccell_log = -1,mtu;
121 +       struct rtattr *tail;
122 +
123 +       memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
124 +
125 +       while (argc > 0) {
126 +               if (matches(*argv, "prio") == 0) {
127 +                       NEXT_ARG();
128 +                       if (get_u32(&opt.prio, *argv, 10)) {
129 +                               explain1("prio"); return -1;
130 +                       }
131 +                       ok++;
132 +               } else if (matches(*argv, "mtu") == 0) {
133 +                       NEXT_ARG();
134 +                       if (get_u32(&mtu, *argv, 10)) {
135 +                               explain1("mtu"); return -1;
136 +                       }
137 +               } else if (matches(*argv, "quantum") == 0) {
138 +                       NEXT_ARG();
139 +                       if (get_u32(&opt.quantum, *argv, 10)) {
140 +                               explain1("quantum"); return -1;
141 +                       }
142 +               } else if (matches(*argv, "burst") == 0 ||
143 +                       strcmp(*argv, "buffer") == 0 ||
144 +                       strcmp(*argv, "maxburst") == 0) {
145 +                       NEXT_ARG();
146 +                       if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) {
147 +                               explain1("buffer");
148 +                               return -1;
149 +                       }
150 +                       ok++;
151 +               } else if (matches(*argv, "cburst") == 0 ||
152 +                       strcmp(*argv, "cbuffer") == 0 ||
153 +                       strcmp(*argv, "cmaxburst") == 0) {
154 +                       NEXT_ARG();
155 +                       if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) {
156 +                               explain1("cbuffer");
157 +                               return -1;
158 +                       }
159 +                       ok++;
160 +               } else if (strcmp(*argv, "ceil") == 0) {
161 +                       NEXT_ARG();
162 +                       if (opt.ceil.rate) {
163 +                               fprintf(stderr, "Double \"ceil\" spec\n");
164 +                               return -1;
165 +                       }
166 +                       if (get_rate(&opt.ceil.rate, *argv)) {
167 +                               explain1("ceil");
168 +                               return -1;
169 +                       }
170 +                       ok++;
171 +               } else if (strcmp(*argv, "rate") == 0) {
172 +                       NEXT_ARG();
173 +                       if (opt.rate.rate) {
174 +                               fprintf(stderr, "Double \"rate\" spec\n");
175 +                               return -1;
176 +                       }
177 +                       if (get_rate(&opt.rate.rate, *argv)) {
178 +                               explain1("rate");
179 +                               return -1;
180 +                       }
181 +                       ok++;
182 +               } else if (strcmp(*argv, "help") == 0) {
183 +                       explain();
184 +                       return -1;
185 +               } else {
186 +                       fprintf(stderr, "What is \"%s\"?\n", *argv);
187 +                       explain();
188 +                       return -1;
189 +               }
190 +               argc--; argv++;
191 +       }
192 +
193 +/*     if (!ok)
194 +               return 0;*/
195 +
196 +       if (opt.rate.rate == 0) {
197 +               fprintf(stderr, "\"rate\" is required.\n");
198 +               return -1;
199 +       }
200 +       /* if ceil params are missing, use the same as rate */
201 +       if (!opt.ceil.rate) opt.ceil = opt.rate;
202 +
203 +       /* compute minimal allowed burst from rate; mtu is added here to make
204 +          sute that buffer is larger than mtu and to have some safeguard space */
205 +       if (!buffer) buffer = opt.rate.rate / HZ + mtu;
206 +       if (!cbuffer) cbuffer = opt.ceil.rate / HZ + mtu;
207 +
208 +       if ((cell_log = tc_calc_rtable(opt.rate.rate, rtab, cell_log, mtu, 0)) < 0) {
209 +               fprintf(stderr, "htb: failed to calculate rate table.\n");
210 +               return -1;
211 +       }
212 +       opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer);
213 +       opt.rate.cell_log = cell_log;
214 +       
215 +       if ((ccell_log = tc_calc_rtable(opt.ceil.rate, ctab, cell_log, mtu, 0)) < 0) {
216 +               fprintf(stderr, "htb: failed to calculate ceil rate table.\n");
217 +               return -1;
218 +       }
219 +       opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
220 +       opt.ceil.cell_log = ccell_log;
221 +
222 +       tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
223 +       addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
224 +       addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
225 +       addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
226 +       addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
227 +       tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
228 +       return 0;
229 +}
230 +
231 +static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
232 +{
233 +       struct rtattr *tb[TCA_HTB_RTAB+1];
234 +       struct tc_htb_opt *hopt;
235 +       struct tc_htb_glob *gopt;
236 +       double buffer,cbuffer;
237 +       SPRINT_BUF(b1);
238 +       SPRINT_BUF(b2);
239 +
240 +       if (opt == NULL)
241 +               return 0;
242 +
243 +       memset(tb, 0, sizeof(tb));
244 +       parse_rtattr(tb, TCA_HTB_RTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));
245 +
246 +       if (tb[TCA_HTB_PARMS]) {
247 +
248 +           hopt = RTA_DATA(tb[TCA_HTB_PARMS]);
249 +           if (RTA_PAYLOAD(tb[TCA_HTB_PARMS])  < sizeof(*hopt)) return -1;
250 +
251 +               if (!hopt->level) {
252 +                       fprintf(f, "prio %d ", (int)hopt->prio);
253 +                       if (show_details)
254 +                               fprintf(f, "quantum %d ", (int)hopt->quantum);
255 +               }
256 +           fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
257 +           buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
258 +           fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
259 +           cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
260 +           if (show_details) {
261 +               fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
262 +                       1<<hopt->rate.cell_log, sprint_size(hopt->rate.mpu, b2));
263 +               fprintf(f, "cburst %s/%u mpu %s ", sprint_size(cbuffer, b1),
264 +                       1<<hopt->ceil.cell_log, sprint_size(hopt->ceil.mpu, b2));
265 +               fprintf(f, "level %d ", (int)hopt->level);
266 +           } else {
267 +               fprintf(f, "burst %s ", sprint_size(buffer, b1));
268 +               fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
269 +           }
270 +           if (show_raw)
271 +               fprintf(f, "buffer [%08x] cbuffer [%08x] ", 
272 +                       hopt->buffer,hopt->cbuffer);
273 +       }
274 +       if (tb[TCA_HTB_INIT]) {
275 +           gopt = RTA_DATA(tb[TCA_HTB_INIT]);
276 +           if (RTA_PAYLOAD(tb[TCA_HTB_INIT])  < sizeof(*gopt)) return -1;
277 +
278 +           fprintf(f, "r2q %d default %x direct_packets_stat %u", 
279 +                   gopt->rate2quantum,gopt->defcls,gopt->direct_pkts);
280 +               if (show_details)
281 +                       fprintf(f," ver %d.%d",gopt->version >> 16,gopt->version & 0xffff);
282 +       }
283 +       return 0;
284 +}
285 +
286 +static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
287 +{
288 +       struct tc_htb_xstats *st;
289 +       if (xstats == NULL)
290 +               return 0;
291 +
292 +       if (RTA_PAYLOAD(xstats) < sizeof(*st))
293 +               return -1;
294 +
295 +       st = RTA_DATA(xstats);
296 +       fprintf(f, " lended: %u borrowed: %u giants: %u\n", 
297 +               st->lends,st->borrows,st->giants);
298 +       fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
299 +       return 0;
300 +}
301 +
302 +struct qdisc_util htb_util = {
303 +       NULL,
304 +       "htb",
305 +       htb_parse_opt,
306 +       htb_print_opt,
307 +       htb_print_xstats,
308 +       htb_parse_class_opt,
309 +       htb_print_opt,
310 +};
311 +
312 +/* for testing of old one */
313 +struct qdisc_util htb2_util = {
314 +       NULL,
315 +       "htb2",
316 +       htb_parse_opt,
317 +       htb_print_opt,
318 +       htb_print_xstats,
319 +       htb_parse_class_opt,
320 +       htb_print_opt,
321 +};
322 +#endif
323  /*
324   * q_htb.c             HTB.
325   *
326 --- iproute-20041019.orig/doc/Makefile
327 +++ iproute-20041019/doc/Makefile
328 @@ -14,6 +14,7 @@
329  PAGESPERPAGE=2
330  
331  HTMLFILES=$(subst .sgml,.html,$(shell echo *.sgml))
332 +TXTFILES=$(subst .sgml,.txt,$(shell echo *.sgml))
333  DVIFILES=$(subst .ps,.dvi,$(PSFILES))
334  
335  
336 @@ -23,6 +24,8 @@
337  
338  html: $(HTMLFILES)
339  
340 +txt: $(TXTFILES)
341 +
342  dvi: $(DVIFILES)
343  
344  print: $(PSFILES)
345 @@ -42,16 +45,17 @@
346         done
347  
348  %.ps: %.dvi
349 -       $(DVIPS) $< -o $@.tmp
350 -       ./do-psnup $@.tmp $@ $(PAGESIZE) $(PAGESPERPAGE)
351 -       rm -f $@.tmp
352 +       $(DVIPS) $< -o $@
353  
354  %.html: %.sgml
355         $(SGML2HTML) $<
356  
357 +%.txt: %.html
358 +       lynx -nolist -dump $< > $@
359 +
360  install:
361         install -m 0644 $(shell echo *.tex) $(DESTDIR)$(DOCDIR)
362         install -m 0644 $(shell echo *.sgml) $(DESTDIR)$(DOCDIR)
363  
364  clean:
365 -       rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html
366 +       rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html $(TXTFILES)
367 --- iproute-20041019.orig/misc/Makefile
368 +++ iproute-20041019/misc/Makefile
369 @@ -1,7 +1,8 @@
370  SSOBJ=ss.o ssfilter.o
371  LNSTATOBJ=lnstat.o lnstat_util.o
372  
373 -TARGETS=ss nstat ifstat rtacct arpd lnstat
374 +#TARGETS=ss nstat ifstat rtacct arpd lnstat
375 +TARGETS=ss nstat rtacct lnstat
376  
377  include ../Config
378  
379 --- iproute-20041019.orig/misc/netbug
380 +++ iproute-20041019/misc/netbug
381 @@ -1,23 +1,16 @@
382  #! /bin/bash
383  
384 +set -e
385 +
386  echo -n "Send network configuration summary to [ENTER means kuznet@ms2.inr.ac.ru] "
387  IFS="" read mail || exit 1
388  [ -z "$mail" ] && mail=kuznet@ms2.inr.ac.ru
389  
390 +netbug=`mktemp -d -t netbug.XXXXXX` || {echo "$0: Cannot create temporary directory" >&2; exit 1;  }
391 +netbugtar=`tempfile -d $netbug --suffix=tar.gz` || {echo "$0: Cannot create temporary file" >&2; exit 1;  }
392 +tmppath=$netbug
393 +trap "/bin/rm -rf $netbug $netbugtar" 0 1 2 3 13 15
394  
395 -netbug=""
396 -while [ "$netbug" = "" ]; do
397 -       netbug=`echo netbug.$$.$RANDOM`
398 -       if [ -e /tmp/$netbug ]; then
399 -               netbug=""
400 -       fi
401 -done
402 -
403 -tmppath=/tmp/$netbug
404 -
405 -trap "rm -rf $tmppath $tmppath.tar.gz" 0 SIGINT
406 -
407 -mkdir $tmppath
408  mkdir $tmppath/net
409  
410  cat /proc/slabinfo > $tmppath/slabinfo
411 @@ -44,9 +37,8 @@
412  fi
413  
414  cd /tmp
415 -tar c $netbug | gzip -9c > $netbug.tar.gz
416 -
417 -uuencode $netbug.tar.gz $netbug.tar.gz | mail -s $netbug "$mail"
418 +tar c $tmppath | gzip -9c > $netbugtar
419 +uuencode $netbugtar $netbugtar | mail -s $netbug "$mail"
420  
421  echo "Sending to <$mail>; subject is $netbug"
422  
423 --- iproute-20041019.orig/Makefile
424 +++ iproute-20041019/Makefile
425 @@ -30,7 +30,7 @@
426  LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a
427  
428  all: Config
429 -       @for i in $(SUBDIRS); \
430 +       @set -e; for i in $(SUBDIRS); \
431         do $(MAKE) $(MFLAGS) -C $$i; done
432  
433  Config:
434 @@ -45,7 +45,7 @@
435                 $(DESTDIR)$(DOCDIR)/examples
436         install -m 0644 $(shell find examples/diffserv -type f -maxdepth 1) \
437                 $(DESTDIR)$(DOCDIR)/examples/diffserv
438 -       @for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done
439 +       @set -e; for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done
440         install -m 0644 $(shell find etc/iproute2 -type f -maxdepth 1) $(DESTDIR)$(CONFDIR)
441         install -m 0755 -d $(DESTDIR)$(MANDIR)/man8
442         install -m 0644 $(shell find man/man8 -type f -maxdepth 1) $(DESTDIR)$(MANDIR)/man8
443 @@ -53,7 +53,7 @@
444         ln -sf $(MANDIR)/man8/tc-pbfifo.8  $(DESTDIR)$(MANDIR)/man8/tc-pfifo.8
445  
446  clean:
447 -       @for i in $(SUBDIRS) doc; \
448 +       @set -e; for i in $(SUBDIRS) doc; \
449         do $(MAKE) $(MFLAGS) -C $$i clean; done
450  
451  clobber: clean
452 --- iproute-20041019.orig/include/linux/pkt_sched.h
453 +++ iproute-20041019/include/linux/pkt_sched.h
454 @@ -1,3 +1,409 @@
455 +#if 0
456 +#ifndef __LINUX_PKT_SCHED_H
457 +#define __LINUX_PKT_SCHED_H
458 +
459 +/* Logical priority bands not depending on specific packet scheduler.
460 +   Every scheduler will map them to real traffic classes, if it has
461 +   no more precise mechanism to classify packets.
462 +
463 +   These numbers have no special meaning, though their coincidence
464 +   with obsolete IPv6 values is not occasional :-). New IPv6 drafts
465 +   preferred full anarchy inspired by diffserv group.
466 +
467 +   Note: TC_PRIO_BESTEFFORT does not mean that it is the most unhappy
468 +   class, actually, as rule it will be handled with more care than
469 +   filler or even bulk.
470 + */
471 +
472 +#define TC_PRIO_BESTEFFORT             0
473 +#define TC_PRIO_FILLER                 1
474 +#define TC_PRIO_BULK                   2
475 +#define TC_PRIO_INTERACTIVE_BULK       4
476 +#define TC_PRIO_INTERACTIVE            6
477 +#define TC_PRIO_CONTROL                        7
478 +
479 +#define TC_PRIO_MAX                    15
480 +
481 +/* Generic queue statistics, available for all the elements.
482 +   Particular schedulers may have also their private records.
483 + */
484 +
485 +struct tc_stats
486 +{
487 +       __u64   bytes;                  /* NUmber of enqueues bytes */
488 +       __u32   packets;                /* Number of enqueued packets   */
489 +       __u32   drops;                  /* Packets dropped because of lack of resources */
490 +       __u32   overlimits;             /* Number of throttle events when this
491 +                                        * flow goes out of allocated bandwidth */
492 +       __u32   bps;                    /* Current flow byte rate */
493 +       __u32   pps;                    /* Current flow packet rate */
494 +       __u32   qlen;
495 +       __u32   backlog;
496 +#ifdef __KERNEL__
497 +       spinlock_t *lock;
498 +#endif
499 +};
500 +
501 +struct tc_estimator
502 +{
503 +       char            interval;
504 +       unsigned char   ewma_log;
505 +};
506 +
507 +/* "Handles"
508 +   ---------
509 +
510 +    All the traffic control objects have 32bit identifiers, or "handles".
511 +
512 +    They can be considered as opaque numbers from user API viewpoint,
513 +    but actually they always consist of two fields: major and
514 +    minor numbers, which are interpreted by kernel specially,
515 +    that may be used by applications, though not recommended.
516 +
517 +    F.e. qdisc handles always have minor number equal to zero,
518 +    classes (or flows) have major equal to parent qdisc major, and
519 +    minor uniquely identifying class inside qdisc.
520 +
521 +    Macros to manipulate handles:
522 + */
523 +
524 +#define TC_H_MAJ_MASK (0xFFFF0000U)
525 +#define TC_H_MIN_MASK (0x0000FFFFU)
526 +#define TC_H_MAJ(h) ((h)&TC_H_MAJ_MASK)
527 +#define TC_H_MIN(h) ((h)&TC_H_MIN_MASK)
528 +#define TC_H_MAKE(maj,min) (((maj)&TC_H_MAJ_MASK)|((min)&TC_H_MIN_MASK))
529 +
530 +#define TC_H_UNSPEC    (0U)
531 +#define TC_H_ROOT      (0xFFFFFFFFU)
532 +#define TC_H_INGRESS    (0xFFFFFFF1U)
533 +
534 +struct tc_ratespec
535 +{
536 +       unsigned char   cell_log;
537 +       unsigned char   __reserved;
538 +       unsigned short  feature;
539 +       short           addend;
540 +       unsigned short  mpu;
541 +       __u32           rate;
542 +};
543 +
544 +/* FIFO section */
545 +
546 +struct tc_fifo_qopt
547 +{
548 +       __u32   limit;  /* Queue length: bytes for bfifo, packets for pfifo */
549 +};
550 +
551 +/* PRIO section */
552 +
553 +#define TCQ_PRIO_BANDS 16
554 +
555 +struct tc_prio_qopt
556 +{
557 +       int     bands;                  /* Number of bands */
558 +       __u8    priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */
559 +};
560 +
561 +/* CSZ section */
562 +
563 +struct tc_csz_qopt
564 +{
565 +       int             flows;          /* Maximal number of guaranteed flows */
566 +       unsigned char   R_log;          /* Fixed point position for round number */
567 +       unsigned char   delta_log;      /* Log of maximal managed time interval */
568 +       __u8            priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> CSZ band */
569 +};
570 +
571 +struct tc_csz_copt
572 +{
573 +       struct tc_ratespec slice;
574 +       struct tc_ratespec rate;
575 +       struct tc_ratespec peakrate;
576 +       __u32           limit;
577 +       __u32           buffer;
578 +       __u32           mtu;
579 +};
580 +
581 +enum
582 +{
583 +       TCA_CSZ_UNSPEC,
584 +       TCA_CSZ_PARMS,
585 +       TCA_CSZ_RTAB,
586 +       TCA_CSZ_PTAB,
587 +};
588 +
589 +/* TBF section */
590 +
591 +struct tc_tbf_qopt
592 +{
593 +       struct tc_ratespec rate;
594 +       struct tc_ratespec peakrate;
595 +       __u32           limit;
596 +       __u32           buffer;
597 +       __u32           mtu;
598 +};
599 +
600 +enum
601 +{
602 +       TCA_TBF_UNSPEC,
603 +       TCA_TBF_PARMS,
604 +       TCA_TBF_RTAB,
605 +       TCA_TBF_PTAB,
606 +};
607 +
608 +
609 +/* TEQL section */
610 +
611 +/* TEQL does not require any parameters */
612 +
613 +/* SFQ section */
614 +
615 +struct tc_sfq_qopt
616 +{
617 +       unsigned        quantum;        /* Bytes per round allocated to flow */
618 +       int             perturb_period; /* Period of hash perturbation */
619 +       __u32           limit;          /* Maximal packets in queue */
620 +       unsigned        divisor;        /* Hash divisor  */
621 +       unsigned        flows;          /* Maximal number of flows  */
622 +};
623 +
624 +/*
625 + *  NOTE: limit, divisor and flows are hardwired to code at the moment.
626 + *
627 + *     limit=flows=128, divisor=1024;
628 + *
629 + *     The only reason for this is efficiency, it is possible
630 + *     to change these parameters in compile time.
631 + */
632 +
633 +/* RED section */
634 +
635 +enum
636 +{
637 +       TCA_RED_UNSPEC,
638 +       TCA_RED_PARMS,
639 +       TCA_RED_STAB,
640 +};
641 +
642 +struct tc_red_qopt
643 +{
644 +       __u32           limit;          /* HARD maximal queue length (bytes)    */
645 +       __u32           qth_min;        /* Min average length threshold (bytes) */
646 +       __u32           qth_max;        /* Max average length threshold (bytes) */
647 +       unsigned char   Wlog;           /* log(W)               */
648 +       unsigned char   Plog;           /* log(P_max/(qth_max-qth_min)) */
649 +       unsigned char   Scell_log;      /* cell size for idle damping */
650 +       unsigned char   flags;
651 +#define TC_RED_ECN     1
652 +};
653 +
654 +struct tc_red_xstats
655 +{
656 +       __u32           early;          /* Early drops */
657 +       __u32           pdrop;          /* Drops due to queue limits */
658 +       __u32           other;          /* Drops due to drop() calls */
659 +       __u32           marked;         /* Marked packets */
660 +};
661 +
662 +/* GRED section */
663 +
664 +#define MAX_DPs 16
665 +
666 +enum
667 +{
668 +       TCA_GRED_UNSPEC,
669 +       TCA_GRED_PARMS,
670 +       TCA_GRED_STAB,
671 +       TCA_GRED_DPS,
672 +};
673 +
674 +#define TCA_SET_OFF TCA_GRED_PARMS
675 +struct tc_gred_qopt
676 +{
677 +       __u32           limit;          /* HARD maximal queue length (bytes)    
678 +*/
679 +       __u32           qth_min;        /* Min average length threshold (bytes) 
680 +*/
681 +       __u32           qth_max;        /* Max average length threshold (bytes) 
682 +*/
683 +       __u32           DP;             /* upto 2^32 DPs */
684 +       __u32           backlog;        
685 +       __u32           qave;   
686 +       __u32           forced; 
687 +       __u32           early;  
688 +       __u32           other;  
689 +       __u32           pdrop;  
690 +
691 +       unsigned char   Wlog;           /* log(W)               */
692 +       unsigned char   Plog;           /* log(P_max/(qth_max-qth_min)) */
693 +       unsigned char   Scell_log;      /* cell size for idle damping */
694 +       __u8            prio;           /* prio of this VQ */
695 +       __u32   packets;
696 +       __u32   bytesin;
697 +};
698 +/* gred setup */
699 +struct tc_gred_sopt
700 +{
701 +       __u32           DPs;
702 +       __u32           def_DP;
703 +       __u8            grio;
704 +};
705 +
706 +/* HTB section */
707 +#define TC_HTB_NUMPRIO         8
708 +#define TC_HTB_MAXDEPTH                8
709 +#define TC_HTB_PROTOVER                3 /* the same as HTB and TC's major */
710 +
711 +struct tc_htb_opt
712 +{
713 +       struct tc_ratespec      rate;
714 +       struct tc_ratespec      ceil;
715 +       __u32   buffer;
716 +       __u32   cbuffer;
717 +       __u32   quantum;
718 +       __u32   level;          /* out only */
719 +       __u32   prio;
720 +};
721 +struct tc_htb_glob
722 +{
723 +       __u32 version;          /* to match HTB/TC */
724 +       __u32 rate2quantum;     /* bps->quantum divisor */
725 +       __u32 defcls;           /* default class number */
726 +       __u32 debug;            /* debug flags */
727 +
728 +       /* stats */
729 +       __u32 direct_pkts; /* count of non shapped packets */
730 +};
731 +enum
732 +{
733 +       TCA_HTB_UNSPEC,
734 +       TCA_HTB_PARMS,
735 +       TCA_HTB_INIT,
736 +       TCA_HTB_CTAB,
737 +       TCA_HTB_RTAB,
738 +};
739 +struct tc_htb_xstats
740 +{
741 +       __u32 lends;
742 +       __u32 borrows;
743 +       __u32 giants;   /* too big packets (rate will not be accurate) */
744 +       __u32 tokens;
745 +       __u32 ctokens;
746 +};
747 +
748 +/* CBQ section */
749 +
750 +#define TC_CBQ_MAXPRIO         8
751 +#define TC_CBQ_MAXLEVEL                8
752 +#define TC_CBQ_DEF_EWMA                5
753 +
754 +struct tc_cbq_lssopt
755 +{
756 +       unsigned char   change;
757 +       unsigned char   flags;
758 +#define TCF_CBQ_LSS_BOUNDED    1
759 +#define TCF_CBQ_LSS_ISOLATED   2
760 +       unsigned char   ewma_log;
761 +       unsigned char   level;
762 +#define TCF_CBQ_LSS_FLAGS      1
763 +#define TCF_CBQ_LSS_EWMA       2
764 +#define TCF_CBQ_LSS_MAXIDLE    4
765 +#define TCF_CBQ_LSS_MINIDLE    8
766 +#define TCF_CBQ_LSS_OFFTIME    0x10
767 +#define TCF_CBQ_LSS_AVPKT      0x20
768 +       __u32           maxidle;
769 +       __u32           minidle;
770 +       __u32           offtime;
771 +       __u32           avpkt;
772 +};
773 +
774 +struct tc_cbq_wrropt
775 +{
776 +       unsigned char   flags;
777 +       unsigned char   priority;
778 +       unsigned char   cpriority;
779 +       unsigned char   __reserved;
780 +       __u32           allot;
781 +       __u32           weight;
782 +};
783 +
784 +struct tc_cbq_ovl
785 +{
786 +       unsigned char   strategy;
787 +#define        TC_CBQ_OVL_CLASSIC      0
788 +#define        TC_CBQ_OVL_DELAY        1
789 +#define        TC_CBQ_OVL_LOWPRIO      2
790 +#define        TC_CBQ_OVL_DROP         3
791 +#define        TC_CBQ_OVL_RCLASSIC     4
792 +       unsigned char   priority2;
793 +       __u32           penalty;
794 +};
795 +
796 +struct tc_cbq_police
797 +{
798 +       unsigned char   police;
799 +       unsigned char   __res1;
800 +       unsigned short  __res2;
801 +};
802 +
803 +struct tc_cbq_fopt
804 +{
805 +       __u32           split;
806 +       __u32           defmap;
807 +       __u32           defchange;
808 +};
809 +
810 +struct tc_cbq_xstats
811 +{
812 +       __u32           borrows;
813 +       __u32           overactions;
814 +       __s32           avgidle;
815 +       __s32           undertime;
816 +};
817 +
818 +enum
819 +{
820 +       TCA_CBQ_UNSPEC,
821 +       TCA_CBQ_LSSOPT,
822 +       TCA_CBQ_WRROPT,
823 +       TCA_CBQ_FOPT,
824 +       TCA_CBQ_OVL_STRATEGY,
825 +       TCA_CBQ_RATE,
826 +       TCA_CBQ_RTAB,
827 +       TCA_CBQ_POLICE,
828 +};
829 +
830 +#define TCA_CBQ_MAX    TCA_CBQ_POLICE
831 +
832 +/* dsmark section */
833 +
834 +enum {
835 +       TCA_DSMARK_UNSPEC,
836 +       TCA_DSMARK_INDICES,
837 +       TCA_DSMARK_DEFAULT_INDEX,
838 +       TCA_DSMARK_SET_TC_INDEX,
839 +       TCA_DSMARK_MASK,
840 +       TCA_DSMARK_VALUE
841 +};
842 +
843 +#define TCA_DSMARK_MAX TCA_DSMARK_VALUE
844 +
845 +/* ATM  section */
846 +
847 +enum {
848 +       TCA_ATM_UNSPEC,
849 +       TCA_ATM_FD,             /* file/socket descriptor */
850 +       TCA_ATM_PTR,            /* pointer to descriptor - later */
851 +       TCA_ATM_HDR,            /* LL header */
852 +       TCA_ATM_EXCESS,         /* excess traffic class (0 for CLP)  */
853 +       TCA_ATM_ADDR,           /* PVC address (for output only) */
854 +       TCA_ATM_STATE           /* VC state (ATM_VS_*; for output only) */
855 +};
856 +
857 +#define TCA_ATM_MAX    TCA_ATM_STATE
858 +
859 +#endif
860 +#endif
861  #ifndef __LINUX_PKT_SCHED_H
862  #define __LINUX_PKT_SCHED_H
863  
864 --- iproute-20010824/ip/iproute.c
865 +++ iproute-20010824/ip/iproute.c
866 @@ -57,7 +57,7 @@
867         fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ]\n");
868         fprintf(stderr, "           [ rtt NUMBER ] [ rttvar NUMBER ]\n");
869         fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ ssthresh REALM ]\n");
870 -       fprintf(stderr, "           [ realms REALM ]\n");
871 +       fprintf(stderr, "           [ realms REALM ] [ hoplimit NUMBER ] [ initcwnd NUMBER ]\n");
872         fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
873         fprintf(stderr, "          unreachable | prohibit | blackhole | nat ]\n");
874         fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
875 @@ -481,6 +481,8 @@
876                                 "cwnd",
877                                 "advmss",
878                                 "reordering",
879 +                               "hoplimit",
880 +                               "initcwnd",
881                         };
882                         static int hz;
883                         if (mxrta[i] == NULL)
884 @@ -750,6 +752,30 @@
885                                 invarg("\"reordering\" value is invalid\n", *argv);
886                         rta_addattr32(mxrta, sizeof(mxbuf), RTAX_REORDERING, reord);
887  #endif
888 +#ifdef RTAX_HOPLIMIT
889 +               } else if (strcmp(*argv, "hoplimit") == 0) {
890 +                       unsigned hoplim;
891 +                       NEXT_ARG();
892 +                       if (strcmp(*argv, "lock") == 0) {
893 +                               mxlock |= (1<<RTAX_HOPLIMIT);
894 +                               NEXT_ARG();
895 +                       }
896 +                       if (get_unsigned(&hoplim, *argv, 0))
897 +                               invarg("\"hoplimit\" value is invalid\n", *argv);
898 +                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_HOPLIMIT, hoplim);
899 +#endif
900 +#ifdef RTAX_INITCWND
901 +               } else if (strcmp(*argv, "initcwnd") == 0) {
902 +                       unsigned initcwnd;
903 +                       NEXT_ARG();
904 +                       if (strcmp(*argv, "lock") == 0) {
905 +                               mxlock |= (1<<RTAX_HOPLIMIT);
906 +                               NEXT_ARG();
907 +                       }
908 +                       if (get_unsigned(&initcwnd, *argv, 0))
909 +                               invarg("\"initcwnd\" value is invalid\n", *argv);
910 +                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, initcwnd);
911 +#endif
912                 } else if (strcmp(*argv, "rtt") == 0) {
913                         unsigned rtt;
914                         NEXT_ARG();
915 --- iproute-20010824.orig/doc/ip-cref.tex
916 +++ iproute-20010824/doc/ip-cref.tex
917 @@ -1324,2 +1324,15 @@
918  
919 +\item \verb|hoplimit NUMBER|
920 +
921 +--- [2.5.74+ only] Hop limit on the path to this destination. If it is not
922 +    given, Linux uses the value selected with \verb|sysctl| variable
923 +    \verb|net/ipv4/ip_default_ttl|.
924 +
925 +\item \verb|initcwnd NUMBER|
926 +
927 +--- [2.5.70+ only] Initial congestion window size when establishing
928 +    connections to this destination. This value is multiplied with the
929 +    MSS (``Maximal Segment Size'') for the connection to get the actual
930 +    window size. If it is not given (or set to zero), Linux uses the
931 +    values specified in~\cite{RFC2414}.
932  
933 @@ -2653,2 +2666,5 @@
934  
935 +\bibitem{RFC2414}  M.~Allman, S.~Floyd, C.~Partridge.
936 +``Increasing TCP's Initial Window'', RFC-2414.
937 +
938  \end{thebibliography}
939 #! /bin/sh -e
940 ## 
941 ## All lines beginning with `## DP:' are a description of the patch.
942 ## DP: add references to lartc
943 ## DP: also drop bogus reference to tc-filters
944
945 [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
946 patch_opts="${patch_opts:--f --no-backup-if-mismatch}"
947
948 if [ $# -ne 1 ]; then
949     echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
950     exit 1
951 fi
952 case "$1" in
953        -patch) patch $patch_opts -p1 < $0;;
954        -unpatch) patch $patch_opts -p1 -R < $0;;
955         *)
956                 echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
957                 exit 1;;
958 esac
959
960 exit 0
961 @DPATCH@
962 diff -Nur old/man/man8/ip.8 new/man/man8/ip.8
963 --- old/man/man8/ip.8   2005-01-05 22:40:29.000000000 +0000
964 +++ new/man/man8/ip.8   2005-01-05 22:47:03.000000000 +0000
965 @@ -1803,6 +1803,8 @@
966  .RB "IP Command reference " ip-cref.ps
967  .br
968  .RB "IP tunnels " ip-cref.ps
969 +.br
970 +.RB http://lartc.org/
971  
972  .SH AUTHOR
973  
974 diff -Nur old/man/man8/tc.8 new/man/man8/tc.8
975 --- old/man/man8/tc.8   2004-10-19 20:49:02.000000000 +0000
976 +++ new/man/man8/tc.8   2005-01-05 22:46:15.000000000 +0000
977 @@ -341,7 +341,7 @@
978  .BR tc-pfifo (8),
979  .BR tc-bfifo (8),
980  .BR tc-pfifo_fast (8),
981 -.BR tc-filters (8)
982 +.BR http://lartc.org/
983  
984  .SH AUTHOR
985  Manpage maintained by bert hubert (ahu@ds9a.nl)
986 #! /bin/sh -e
987 ## 
988 ## All lines beginning with `## DP:' are a description of the patch.
989 ## DP: fixes typo
990
991 [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
992 patch_opts="${patch_opts:--f --no-backup-if-mismatch}"
993
994 if [ $# -ne 1 ]; then
995     echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
996     exit 1
997 fi
998 case "$1" in
999        -patch) patch $patch_opts -p1 < $0;;
1000        -unpatch) patch $patch_opts -p1 -R < $0;;
1001         *)
1002                 echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
1003                 exit 1;;
1004 esac
1005
1006 exit 0
1007 @DPATCH@
1008 --- iproute/ip/iptunnel.c.orig  2003-07-10 11:47:06.000000000 +1000
1009 +++ iproute/ip/iptunnel.c       2003-07-10 11:47:11.000000000 +1000
1010 @@ -221,7 +221,7 @@
1011                         NEXT_ARG();
1012                         p->i_flags |= GRE_KEY;
1013                         if (strchr(*argv, '.'))
1014 -                               p->o_key = get_addr32(*argv);
1015 +                               p->i_key = get_addr32(*argv);
1016                         else {
1017                                 if (get_unsigned(&uval, *argv, 0)<0) {
1018                                         fprintf(stderr, "invalid value of \"ikey\"\n");
1019 #! /bin/sh -e
1020 ## 
1021 ## All lines beginning with `## DP:' are a description of the patch.
1022 ## DP: add the wrr qdisc scheduler, see #198414
1023
1024 [ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
1025 patch_opts="${patch_opts:--f --no-backup-if-mismatch}"
1026
1027 if [ $# -ne 1 ]; then
1028     echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
1029     exit 1
1030 fi
1031 case "$1" in
1032        -patch) patch $patch_opts -p1 < $0;;
1033        -unpatch) patch $patch_opts -p1 -R < $0;;
1034         *)
1035                 echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
1036                 exit 1;;
1037 esac
1038
1039 exit 0
1040 @DPATCH@
1041 diff -urN iproute-20041019.orig/include/linux/pkt_sched.h iproute-20041019/include/linux/pkt_sched.h
1042 --- iproute-20041019.orig/include/linux/pkt_sched.h     2005-01-06 00:42:42.000000000 +0100
1043 +++ iproute-20041019/include/linux/pkt_sched.h  2005-01-06 00:38:06.000000000 +0100
1044 @@ -837,4 +837,116 @@
1045  
1046  #define NETEM_DIST_SCALE       8192
1047  
1048 +/* WRR section */
1049 +
1050 +/* Other includes */
1051 +#include <linux/if_ether.h>
1052 +
1053 +// A sub weight and of a class
1054 +// All numbers are represented as parts of (2^64-1).
1055 +struct tc_wrr_class_weight {
1056 +       __u64 val;      // Current value                        (0 is not valid)
1057 +       __u64 decr;     // Value pr bytes                       (2^64-1 is not valid)
1058 +       __u64 incr;     // Value pr seconds                     (2^64-1 is not valid)
1059 +       __u64 min;      // Minimal value                        (0 is not valid)
1060 +       __u64 max;      // Minimal value                        (0 is not valid)
1061 +
1062 +// The time where the above information was correct:
1063 +       time_t tim;
1064 +};
1065 +
1066 +// Packet send when modifying a class:
1067 +struct tc_wrr_class_modf {
1068 +       // Not-valid values are ignored.
1069 +       struct tc_wrr_class_weight weight1;
1070 +       struct tc_wrr_class_weight weight2;
1071 +};
1072 +
1073 +// Packet returned when quering a class:
1074 +struct tc_wrr_class_stats {
1075 +       char used;      // If this is false the information below is invalid
1076 +
1077 +       struct tc_wrr_class_modf class_modf;
1078 +
1079 +       unsigned char addr[ETH_ALEN];
1080 +       char usemac;    // True if addr is a MAC address, else it is an IP address
1081 +                       // (this value is only for convience, it is always the same
1082 +                       //  value as in the qdisc)
1083 +       int heappos;    // Current heap position or 0 if not in heap
1084 +       __u64 penal_ls; // Penalty value in heap (ls)
1085 +       __u64 penal_ms; // Penalty value in heap (ms)
1086 +};
1087 +
1088 +// Qdisc-wide penalty information (boolean values - 2 not valid)
1089 +struct tc_wrr_qdisc_weight {
1090 +       char weight_mode;       // 0=No automatic change to weight
1091 +                               // 1=Decrease normally
1092 +                               // 2=Also multiply with number of machines
1093 +                               // 3=Instead multiply with priority divided
1094 +                               //   with priority of the other.
1095 +                               // -1=no change
1096 +};
1097 +
1098 +// Packet send when modifing a qdisc:
1099 +struct tc_wrr_qdisc_modf {
1100 +       // Not-valid values are ignored:
1101 +       struct tc_wrr_qdisc_weight weight1;
1102 +       struct tc_wrr_qdisc_weight weight2;
1103 +};
1104 +
1105 +// Packet send when creating a qdisc:
1106 +struct tc_wrr_qdisc_crt {
1107 +       struct tc_wrr_qdisc_modf qdisc_modf;
1108 +
1109 +       char srcaddr;   // 1=lookup source, 0=lookup destination
1110 +       char usemac;    // 1=Classify on MAC addresses, 0=classify on IP
1111 +       char usemasq;   // 1=Classify based on masqgrading - only valid
1112 +                       //   if usemac is zero
1113 +       int bands_max;  // Maximal number of bands (i.e.: classes)
1114 +       int proxy_maxconn;// If differnt from 0 then we support proxy remapping
1115 +                       // of packets. And this is the number of maximal
1116 +                       // concurrent proxy connections.
1117 +};
1118 +
1119 +// Packet returned when quering a qdisc:
1120 +struct tc_wrr_qdisc_stats {
1121 +       struct tc_wrr_qdisc_crt qdisc_crt;
1122 +       int proxy_curconn;
1123 +       int nodes_in_heap;      // Current number of bands wanting to send something
1124 +       int bands_cur;          // Current number of bands used (i.e.: MAC/IP addresses seen)
1125 +       int bands_reused;       // Number of times this band has been reused.
1126 +       int packets_requed;     // Number of times packets have been requeued.
1127 +       __u64 priosum;          // Sum of priorities in heap where 1 is 2^32
1128 +};
1129 +
1130 +struct tc_wrr_qdisc_modf_std {
1131 +       // This indicates which of the tc_wrr_qdisc_modf structers this is:
1132 +       char proxy; // 0=This struct
1133 +
1134 +       // Should we also change a class?
1135 +       char change_class;
1136 +
1137 +       // Only valid if change_class is false
1138 +       struct tc_wrr_qdisc_modf qdisc_modf;
1139 +
1140 +       // Only valid if change_class is true:
1141 +       unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
1142 +       struct tc_wrr_class_modf class_modf; // The change
1143 +};
1144 +
1145 +// Used for proxyrempping:
1146 +struct tc_wrr_qdisc_modf_proxy {
1147 +       // This indicates which of the tc_wrr_qdisc_modf structers this is:
1148 +       char proxy;     // 1=This struct
1149 +
1150 +       // This is 1 if the proxyremap information should be reset
1151 +       char reset;
1152 +
1153 +       // changec is the number of elements in changes.
1154 +       int changec;
1155 +
1156 +       // This is an array of type ProxyRemapBlock:
1157 +       long changes[0];
1158 +};
1159 +
1160  #endif
1161 diff -urN iproute-20041019.orig/tc/Makefile iproute-20041019/tc/Makefile
1162 --- iproute-20041019.orig/tc/Makefile   2004-10-19 22:49:02.000000000 +0200
1163 +++ iproute-20041019/tc/Makefile        2005-01-06 00:33:47.000000000 +0100
1164 @@ -10,6 +10,7 @@
1165  TCMODULES += q_prio.o
1166  TCMODULES += q_tbf.o
1167  TCMODULES += q_cbq.o
1168 +TCMODULES += q_wrr.o
1169  TCMODULES += f_rsvp.o
1170  TCMODULES += f_u32.o
1171  TCMODULES += f_route.o
1172 diff -urN iproute-20041019.orig/tc/q_wrr.c iproute-20041019/tc/q_wrr.c
1173 --- iproute-20041019.orig/tc/q_wrr.c    1970-01-01 01:00:00.000000000 +0100
1174 +++ iproute-20041019/tc/q_wrr.c 2005-01-06 00:34:06.000000000 +0100
1175 @@ -0,0 +1,322 @@
1176 +#include <stdio.h>
1177 +#include <stdlib.h>
1178 +#include <unistd.h>
1179 +#include <syslog.h>
1180 +#include <fcntl.h>
1181 +#include <sys/socket.h>
1182 +#include <netinet/in.h>
1183 +#include <arpa/inet.h>
1184 +#include <string.h>
1185 +#include <math.h>
1186 +
1187 +#include "utils.h"
1188 +#include "tc_util.h"
1189 +
1190 +#define usage() return(-1)
1191 +
1192 +// Returns -1 on error
1193 +static int wrr_parse_qdisc_weight(int argc, char** argv, 
1194 +                              struct tc_wrr_qdisc_modf* opt) {
1195 +  int i;
1196 +  
1197 +  opt->weight1.weight_mode=-1;
1198 +  opt->weight2.weight_mode=-1;
1199 +  
1200 +  for(i=0; i<argc; i++) {  
1201 +    if(!memcmp(argv[i],"wmode1=",7)) {
1202 +      opt->weight1.weight_mode=atoi(argv[i]+7);            
1203 +    } else if(!memcmp(argv[i],"wmode2=",7)) {
1204 +      opt->weight2.weight_mode=atoi(argv[i]+7);
1205 +    } else {
1206 +      printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
1207 +      return -1;
1208 +    }
1209 +  }
1210 +  return 0;
1211 +}
1212 +
1213 +static int wrr_parse_class_modf(int argc, char** argv, 
1214 +                                struct tc_wrr_class_modf* modf) {
1215 +  int i;
1216 +  
1217 +  if(argc<1) {
1218 +    fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
1219 +    fprintf(stderr, "  The values can be floating point like 0.42 or divisions like 42/100\n");
1220 +    return -1;
1221 +  }
1222 +  
1223 +  // Set meaningless values:
1224 +  modf->weight1.val=0;
1225 +  modf->weight1.decr=(__u64)-1;
1226 +  modf->weight1.incr=(__u64)-1;
1227 +  modf->weight1.min=0;
1228 +  modf->weight1.max=0;
1229 +  modf->weight2.val=0;
1230 +  modf->weight2.decr=(__u64)-1;
1231 +  modf->weight2.incr=(__u64)-1;
1232 +  modf->weight2.min=0;
1233 +  modf->weight2.max=0;
1234 +  
1235 +  // And read values:
1236 +  for(i=0; i<argc; i++) {
1237 +    char arg[80];
1238 +    char* name,*value1=0,*value2=0;
1239 +    long double f_val1,f_val2=1,value;
1240 +    if(strlen(argv[i])>=sizeof(arg)) {
1241 +      fprintf(stderr,"Argument too long: %s\n",argv[i]);
1242 +      return -1;
1243 +    }
1244 +    strcpy(arg,argv[i]);
1245 +    
1246 +    name=strtok(arg,"=");
1247 +    if(name) value1=strtok(0,"/");
1248 +    if(value1) value2=strtok(0,"");
1249 +    
1250 +    if(!value1) {
1251 +      fprintf(stderr,"No = found in argument: %s\n",argv[i]);
1252 +      return -1;
1253 +    }
1254 +    
1255 +    f_val1=atof(value1);
1256 +    if(value2) f_val2=atof(value2);    
1257 +    
1258 +    if(f_val2==0)  {
1259 +      fprintf(stderr,"Division by 0\n");
1260 +      return -1;
1261 +    }
1262 +        
1263 +    value=f_val1/f_val2;    
1264 +    if(value>1) value=1;
1265 +    if(value<0) value=0;            
1266 +    value*=((__u64)-1);
1267 +    
1268 +    // And find the value set
1269 +    if(!strcmp(name,"weight1"))    modf->weight1.val=value;
1270 +    else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
1271 +    else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
1272 +    else if(!strcmp(name,"min1"))  modf->weight1.min=value;
1273 +    else if(!strcmp(name,"max1"))  modf->weight1.max=value;
1274 +    else if(!strcmp(name,"weight2")) modf->weight2.val=value;
1275 +    else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
1276 +    else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
1277 +    else if(!strcmp(name,"min2"))  modf->weight2.min=value;
1278 +    else if(!strcmp(name,"max2"))  modf->weight2.max=value;
1279 +    else {
1280 +      fprintf(stderr,"illegal value: %s\n",name);
1281 +      return -1;
1282 +    }
1283 +  }    
1284 +
1285 +  return 0;
1286 +}
1287 +
1288 +static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
1289 +{
1290 +  if(n->nlmsg_flags & NLM_F_CREATE) {
1291 +    // This is a create request:
1292 +    struct tc_wrr_qdisc_crt opt;
1293 +       
1294 +    int sour,dest,ip,mac,masq;
1295 +
1296 +    if(argc<4) {
1297 +      fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
1298 +      return -1;
1299 +    }    
1300 +  
1301 +    // Read sour/dest:
1302 +    memset(&opt,0,sizeof(opt));
1303 +    sour=!strcmp(argv[0],"sour");
1304 +    dest=!strcmp(argv[0],"dest");      
1305 +       
1306 +    if(!sour && !dest) {
1307 +      fprintf(stderr,"sour or dest must be specified\n");
1308 +      return -1;
1309 +    }  
1310 +
1311 +    // Read ip/mac
1312 +    ip=!strcmp(argv[1],"ip");
1313 +    mac=!strcmp(argv[1],"mac");        
1314 +    masq=!strcmp(argv[1],"masq");      
1315 +
1316 +    if(!ip && !mac && !masq) {
1317 +      fprintf(stderr,"ip, masq or mac must be specified\n");
1318 +      return -1;
1319 +    }  
1320 +
1321 +    opt.srcaddr=sour;          
1322 +    opt.usemac=mac;
1323 +    opt.usemasq=masq;          
1324 +    opt.bands_max=atoi(argv[2]);
1325 +    
1326 +    opt.proxy_maxconn=atoi(argv[3]);
1327 +    
1328 +    // Read weights:
1329 +    if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
1330 +    if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
1331 +    if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
1332 +               
1333 +    addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1334 +  } else {
1335 +    struct tc_wrr_qdisc_modf_std opt;
1336 +    char qdisc,class;
1337 +    
1338 +    // This is a modify request:
1339 +    if(argc<1) {
1340 +      fprintf(stderr,"... qdisc ... or ... class ...\n");
1341 +      return -1;
1342 +    }
1343 +            
1344 +    qdisc=!strcmp(argv[0],"qdisc");
1345 +    class=!strcmp(argv[0],"class");
1346 +
1347 +    if(!qdisc && !class) {
1348 +      fprintf(stderr,"qdisc or class must be specified\n");
1349 +      return -1;
1350 +    }
1351 +      
1352 +    argc--;
1353 +    argv++;
1354 +      
1355 +    opt.proxy=0;
1356 +    
1357 +    if(qdisc) {
1358 +      opt.change_class=0;
1359 +      if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
1360 +    } else {
1361 +      int a0,a1,a2,a3,a4=0,a5=0;      
1362 +
1363 +      opt.change_class=1;
1364 +      
1365 +      if(argc<1) {
1366 +        fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
1367 +        return -1;
1368 +      }
1369 +      memset(opt.addr,0,sizeof(opt.addr));
1370 +
1371 +      if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
1372 +         (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
1373 +       fprintf(stderr,"Wrong format of mac or ip address\n");
1374 +       return -1;
1375 +      }
1376 +      
1377 +      opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
1378 +      opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
1379 +
1380 +      if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
1381 +    }  
1382 +  
1383 +    addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1384 +  }
1385 +  return 0;
1386 +}
1387 +
1388 +static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
1389 +  struct tc_wrr_class_modf opt;
1390 +  
1391 +  memset(&opt,0,sizeof(opt));
1392 +  if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
1393 +  
1394 +  addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
1395 +  return 0;  
1396 +}  
1397 +
1398 +static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1399 +{
1400 +       struct tc_wrr_qdisc_stats *qopt;
1401 +
1402 +       if (opt == NULL)
1403 +               return 0;
1404 +
1405 +       if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
1406 +               return -1;
1407 +       qopt = RTA_DATA(opt);
1408 +       
1409 +       fprintf(f,"\n  (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
1410 +         qopt->qdisc_crt.srcaddr ? "sour" : "dest",
1411 +         qopt->qdisc_crt.usemac  ? "mac"  : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),   
1412 +         qopt->qdisc_crt.bands_max,                      
1413 +         qopt->bands_cur,
1414 +         qopt->bands_reused
1415 +         );
1416 +         
1417 +       if(qopt->qdisc_crt.proxy_maxconn) {
1418 +         fprintf(f,"  (proxy maxcon %i) (proxy curcon %i)\n",
1419 +           qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
1420 +       }
1421 +       
1422 +       fprintf(f,"  (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
1423 +         qopt->nodes_in_heap,
1424 +         qopt->packets_requed,
1425 +         qopt->priosum/((long double)((__u32)-1))
1426 +         );
1427 +
1428 +       fprintf(f,"  (wmode1 %i) (wmode2 %i) \n",
1429 +         qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
1430 +         qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
1431 +         
1432 +       return 0;
1433 +}
1434 +
1435 +static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
1436 +  struct tc_wrr_class_stats *copt;
1437 +  long double d=(__u64)-1;
1438 +
1439 +  if (opt == NULL) return 0;
1440 +
1441 +  if (RTA_PAYLOAD(opt)  < sizeof(*copt))
1442 +    return -1;
1443 +  copt = RTA_DATA(opt);
1444 +
1445 +  if(!copt->used) {
1446 +    fprintf(f,"(unused)");
1447 +    return 0;
1448 +  }
1449 +  
1450 +  if(copt->usemac) {
1451 +    fprintf(f,"\n  (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
1452 +      copt->addr[0],copt->addr[1],copt->addr[2],
1453 +      copt->addr[3],copt->addr[4],copt->addr[5]);
1454 +  } else {     
1455 +    fprintf(f,"\n  (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
1456 +  }    
1457 +  
1458 +  fprintf(f,"  (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
1459 +    (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
1460 +    copt->heappos,
1461 +    (unsigned)(copt->penal_ms>>32),
1462 +    (unsigned)(copt->penal_ms & 0xffffffffU),
1463 +    (unsigned)(copt->penal_ls>>32),
1464 +    (unsigned)(copt->penal_ls & 0xffffffffU)
1465 +    );
1466 +    
1467 +  fprintf(f,"  Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
1468 +    copt->class_modf.weight1.val/d,
1469 +    copt->class_modf.weight1.decr/d,
1470 +    copt->class_modf.weight1.incr/d,
1471 +    copt->class_modf.weight1.min/d,
1472 +    copt->class_modf.weight1.max/d);
1473 +
1474 +  fprintf(f,"  Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
1475 +    copt->class_modf.weight2.val/d,
1476 +    copt->class_modf.weight2.decr/d,
1477 +    copt->class_modf.weight2.incr/d,
1478 +    copt->class_modf.weight2.min/d,
1479 +    copt->class_modf.weight2.max/d);
1480 +  
1481 +  return 0;
1482 +}
1483 +
1484 +static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
1485 +{
1486 +       return 0;
1487 +}
1488 +
1489 +
1490 +struct qdisc_util wrr_qdisc_util = {
1491 +       .id = "wrr",
1492 +       .parse_qopt = wrr_parse_opt,
1493 +       .print_qopt = wrr_print_opt,
1494 +       .print_xstats = wrr_print_xstats,
1495 +       .parse_copt = wrr_parse_copt,
1496 +       .print_copt = wrr_print_copt
1497 +};