branch_general'.
Sprout from master 2004-04-06 02:44:42 UTC Paweł Sikora <pluto@pld-linux.org> '- HFSC support.'
Cherrypick from master 2002-07-23 13:14:27 UTC Jakub Bogusz <qboosh@pld-linux.org> '- added headers from wrr-linux-2.4.9 (in ifdef)':
iproute2-label.patch -> 1.1
iproute2-latest.patch -> 1.1
iproute2-make.patch -> 1.4
iproute2-uClibc.patch -> 1.2
wrr-iproute2-2.2.4.patch -> 1.2
Delete:
iproute2-2.6.0-t7-test.patch
iproute2-htb2_tc.patch
iproute2-stats.patch
iproute2.spec
+++ /dev/null
-diff -Nur iproute2.org/tc/q_esfq.c iproute2/tc/q_esfq.c
---- iproute2.org/tc/q_esfq.c 2003-10-12 12:19:27.537543736 +0200
-+++ iproute2/tc/q_esfq.c 2003-10-12 12:07:04.928437480 +0200
-@@ -42,7 +42,7 @@
-
- memset(&opt, 0, sizeof(opt));
-
-- opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
-+// opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
-
- while (argc > 0) {
- if (strcmp(*argv, "quantum") == 0) {
-@@ -85,22 +85,22 @@
- return -1;
- }
- ok++;
-- } else if (strcmp(*argv, "hash") == 0) {
-- NEXT_ARG();
-- if(strcmp(*argv,"classic") == 0) {
-- opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
-- } else
-- if(strcmp(*argv,"dst") == 0) {
-- opt.hash_kind= TCA_SFQ_HASH_DST;
-- } else
-- if(strcmp(*argv,"src") == 0) {
-- opt.hash_kind= TCA_SFQ_HASH_SRC;
-- } else {
-- fprintf(stderr, "Illegal \"hash\"\n");
-- explain();
-- return -1;
-- }
-- ok++;
-+// } else if (strcmp(*argv, "hash") == 0) {
-+// NEXT_ARG();
-+// if(strcmp(*argv,"classic") == 0) {
-+// opt.hash_kind= TCA_SFQ_HASH_CLASSIC;
-+// } else
-+// if(strcmp(*argv,"dst") == 0) {
-+// opt.hash_kind= TCA_SFQ_HASH_DST;
-+// } else
-+// if(strcmp(*argv,"src") == 0) {
-+// opt.hash_kind= TCA_SFQ_HASH_SRC;
-+// } else {
-+// fprintf(stderr, "Illegal \"hash\"\n");
-+// explain();
-+// return -1;
-+// }
-+// ok++;
- } else if (strcmp(*argv, "help") == 0) {
- explain();
- return -1;
-@@ -136,22 +136,22 @@
- if (qopt->perturb_period)
- fprintf(f, "perturb %dsec ", qopt->perturb_period);
-
-- fprintf(f,"hash: ");
-- switch(qopt->hash_kind)
-- {
-- case TCA_SFQ_HASH_CLASSIC:
-- fprintf(f,"classic");
-- break;
-- case TCA_SFQ_HASH_DST:
-- fprintf(f,"dst");
-- break;
-- case TCA_SFQ_HASH_SRC:
-- fprintf(f,"src");
-- break;
-- default:
-- fprintf(f,"Unknown");
-- }
-- return 0;
-+// fprintf(f,"hash: ");
-+// switch(qopt->hash_kind)
-+// {
-+// case TCA_SFQ_HASH_CLASSIC:
-+// fprintf(f,"classic");
-+// break;
-+// case TCA_SFQ_HASH_DST:
-+// fprintf(f,"dst");
-+// break;
-+// case TCA_SFQ_HASH_SRC:
-+// fprintf(f,"src");
-+// break;
-+// default:
-+// fprintf(f,"Unknown");
-+// }
-+// return 0;
- }
-
- static int esfq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
-diff -Nur iproute2.org/tc/q_htb.c iproute2/tc/q_htb.c
---- iproute2.org/tc/q_htb.c 2003-10-12 12:19:27.462555136 +0200
-+++ iproute2/tc/q_htb.c 2003-10-12 12:16:53.721927264 +0200
-@@ -108,7 +108,8 @@
- struct tc_htb_glob opt;
- struct rtattr *tail;
- unsigned i; char *p;
-- opt.rate2quantum = 10; opt.defcls = 1; opt.use_dcache = 0;
-+ opt.rate2quantum = 10; opt.defcls = 1;
-+// opt.use_dcache = 0;
- opt.debug = 0;
-
- while (argc > 0) {
-@@ -128,8 +129,8 @@
- if (*p<'0' || *p>'3') break;
- opt.debug |= (*p-'0')<<(2*i);
- }
-- } else if (matches(*argv, "dcache") == 0) {
-- opt.use_dcache = 1;
-+// } else if (matches(*argv, "dcache") == 0) {
-+// opt.use_dcache = 1;
- } else {
- fprintf(stderr, "What is \"%s\"?\n", *argv);
- explain();
-@@ -154,7 +155,7 @@
- struct rtattr *tail;
-
- memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
-- opt.injectd = 100; /* disable injecting */
-+// opt.injectd = 100; /* disable injecting */
-
- while (argc > 0) {
- if (matches(*argv, "prio") == 0) {
-@@ -168,11 +169,11 @@
- if (get_u32(&mtu, *argv, 10)) {
- explain1("mtu"); return -1;
- }
-- } else if (matches(*argv, "inject") == 0) {
-- NEXT_ARG();
-- if (get_u8(&opt.injectd, *argv, 10)) {
-- explain1("inject"); return -1;
-- }
-+// } else if (matches(*argv, "inject") == 0) {
-+// NEXT_ARG();
-+// if (get_u8(&opt.injectd, *argv, 10)) {
-+// explain1("inject"); return -1;
-+// }
- } else if (matches(*argv, "burst") == 0 ||
- strcmp(*argv, "buffer") == 0 ||
- strcmp(*argv, "maxburst") == 0) {
-@@ -306,10 +307,10 @@
- gopt = RTA_DATA(tb[TCA_HTB_INIT]);
- if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
-
-- fprintf(f, "r2q %d default %x dcache %d\n"
-- " deq_util 1/%d deq_rate %d trials_per_deq %d\n dcache_hits %u direct_packets %u",
-- gopt->rate2quantum,gopt->defcls,gopt->use_dcache,1000000/(1+gopt->utilz),
-- gopt->deq_rate, gopt->trials/(1+gopt->deq_rate),gopt->dcache_hits,gopt->direct_pkts);
-+// fprintf(f, "r2q %d default %x dcache %d\n"
-+// " deq_util 1/%d deq_rate %d trials_per_deq %d\n dcache_hits %u direct_packets %u",
-+// gopt->rate2quantum,gopt->defcls,gopt->use_dcache,1000000/(1+gopt->utilz),
-+// gopt->deq_rate, gopt->trials/(1+gopt->deq_rate),gopt->dcache_hits,gopt->direct_pkts);
- }
- return 0;
- }
-@@ -324,8 +325,8 @@
- return -1;
-
- st = RTA_DATA(xstats);
-- fprintf(f, " lended: %u borrowed: %u giants: %u injects: %u\n",
-- st->lends,st->borrows,st->giants,st->injects);
-+ fprintf(f, " lended: %u borrowed: %u giants: %u\n",
-+ st->lends,st->borrows,st->giants);
- fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
- return 0;
- }
+++ /dev/null
---- iproute2/tc/q_htb.c Sun Oct 21 22:07:29 2001
-+++ iproute2new/tc/q_htb.c Wed Dec 19 16:51:41 2001
-@@ -0,0 +1,342 @@
-+/*
-+ * q_htb.c HTB.
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License
-+ * as published by the Free Software Foundation; either version
-+ * 2 of the License, or (at your option) any later version.
-+ *
-+ * Authors: Martin Devera, devik@cdi.cz
-+ *
-+ */
-+
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <unistd.h>
-+#include <syslog.h>
-+#include <fcntl.h>
-+#include <sys/socket.h>
-+#include <netinet/in.h>
-+#include <arpa/inet.h>
-+#include <string.h>
-+
-+#include "utils.h"
-+#include "tc_util.h"
-+
-+#ifndef TC_HTB_NUMPRIO
-+/* HTB section */
-+#define TC_HTB_NUMPRIO 4
-+#define TC_HTB_MAXDEPTH 4
-+
-+struct tc_htb_opt
-+{
-+ struct tc_ratespec rate;
-+ struct tc_ratespec ceil;
-+ __u32 buffer;
-+ __u32 cbuffer;
-+ __u32 quantum; /* out only */
-+ __u32 level; /* out only */
-+ __u8 prio;
-+ __u8 injectd; /* inject class distance */
-+ __u8 pad[2];
-+};
-+struct tc_htb_glob
-+{
-+ __u32 rate2quantum; /* bps->quantum divisor */
-+ __u32 defcls; /* default class number */
-+ __u32 use_dcache; /* use dequeue cache ? */
-+ __u32 debug; /* debug flags */
-+
-+
-+ /* stats */
-+ __u32 deq_rate; /* dequeue rate */
-+ __u32 utilz; /* dequeue utilization */
-+ __u32 trials; /* deq_prio trials per dequeue */
-+ __u32 dcache_hits;
-+ __u32 direct_pkts; /* count of non shapped packets */
-+};
-+enum
-+{
-+ TCA_HTB_UNSPEC,
-+ TCA_HTB_PARMS,
-+ TCA_HTB_INIT,
-+ TCA_HTB_CTAB,
-+ TCA_HTB_RTAB,
-+};
-+struct tc_htb_xstats
-+{
-+ __u32 lends;
-+ __u32 borrows;
-+ __u32 giants; /* too big packets (rate will not be accurate) */
-+ __u32 injects; /* how many times leaf used injected bw */
-+ __u32 tokens;
-+ __u32 ctokens;
-+};
-+#endif
-+
-+static void explain(void)
-+{
-+ fprintf(stderr, "Usage: ... qdisc add ... htb [default N] [r2q N]\n"
-+ " default number of class to which unclassified packets are sent {1}\n"
-+ " dcache whether to use dequeue cache; it limits fairness but makes\n"
-+ " possible to use HTB on very fast devices\n"
-+ " r2q DRR quantums are computed as rate in Bps/r2q {10}\n"
-+ " debug string of 16 numbers each 0-3 {0}\n\n"
-+ "... class add ... htb rate R1 burst B1 [prio P] [slot S] [pslot PS]\n"
-+ " [ceil R2] [cburst B2] [gated]\n"
-+ " rate rate allocated to this class (class can still borrow)\n"
-+ " burst max bytes burst which can be accumulated during idle period {computed}\n"
-+ " ceil definite upper class rate (no borrows) {rate}\n"
-+ " cburst burst but for ceil {computed}\n"
-+ " mtu max packet size {1600}\n"
-+ " prio priority of leaf; lower are served first {0}\n"
-+ " inject distance to parent we inject bandwidth to {100}\n"
-+ );
-+}
-+
-+static void explain1(char *arg)
-+{
-+ fprintf(stderr, "Illegal \"%s\"\n", arg);
-+ explain();
-+}
-+
-+
-+#define usage() return(-1)
-+
-+static int htb_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-+{
-+ struct tc_htb_glob opt;
-+ struct rtattr *tail;
-+ unsigned i; char *p;
-+ opt.rate2quantum = 10; opt.defcls = 1; opt.use_dcache = 0;
-+ opt.debug = 0;
-+
-+ while (argc > 0) {
-+ if (matches(*argv, "r2q") == 0) {
-+ NEXT_ARG();
-+ if (get_u32(&opt.rate2quantum, *argv, 10)) {
-+ explain1("r2q"); return -1;
-+ }
-+ } else if (matches(*argv, "default") == 0) {
-+ NEXT_ARG();
-+ if (get_u32(&opt.defcls, *argv, 16)) {
-+ explain1("default"); return -1;
-+ }
-+ } else if (matches(*argv, "debug") == 0) {
-+ NEXT_ARG(); p = *argv;
-+ for (i=0; i<16; i++,p++) {
-+ if (*p<'0' || *p>'3') break;
-+ opt.debug |= (*p-'0')<<(2*i);
-+ }
-+ } else if (matches(*argv, "dcache") == 0) {
-+ opt.use_dcache = 1;
-+ } else {
-+ fprintf(stderr, "What is \"%s\"?\n", *argv);
-+ explain();
-+ return -1;
-+ }
-+ argc--; argv++;
-+ }
-+ tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
-+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-+ addattr_l(n, 2024, TCA_HTB_INIT, &opt, NLMSG_ALIGN(sizeof(opt)));
-+ tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
-+ return 0;
-+}
-+
-+static int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
-+{
-+ int ok=0;
-+ struct tc_htb_opt opt;
-+ __u32 rtab[256],ctab[256];
-+ unsigned buffer=0,cbuffer=0;
-+ int cell_log=-1,ccell_log = -1,mtu;
-+ struct rtattr *tail;
-+
-+ memset(&opt, 0, sizeof(opt)); mtu = 1600; /* eth packet len */
-+ opt.injectd = 100; /* disable injecting */
-+
-+ while (argc > 0) {
-+ if (matches(*argv, "prio") == 0) {
-+ NEXT_ARG();
-+ if (get_u8(&opt.prio, *argv, 10)) {
-+ explain1("prio"); return -1;
-+ }
-+ ok++;
-+ } else if (matches(*argv, "mtu") == 0) {
-+ NEXT_ARG();
-+ if (get_u32(&mtu, *argv, 10)) {
-+ explain1("mtu"); return -1;
-+ }
-+ } else if (matches(*argv, "inject") == 0) {
-+ NEXT_ARG();
-+ if (get_u8(&opt.injectd, *argv, 10)) {
-+ explain1("inject"); return -1;
-+ }
-+ } else if (matches(*argv, "burst") == 0 ||
-+ strcmp(*argv, "buffer") == 0 ||
-+ strcmp(*argv, "maxburst") == 0) {
-+ NEXT_ARG();
-+ if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) {
-+ explain1("buffer");
-+ return -1;
-+ }
-+ ok++;
-+ } else if (matches(*argv, "cburst") == 0 ||
-+ strcmp(*argv, "cbuffer") == 0 ||
-+ strcmp(*argv, "cmaxburst") == 0) {
-+ NEXT_ARG();
-+ if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) {
-+ explain1("cbuffer");
-+ return -1;
-+ }
-+ ok++;
-+ } else if (strcmp(*argv, "ceil") == 0) {
-+ NEXT_ARG();
-+ if (opt.ceil.rate) {
-+ fprintf(stderr, "Double \"ceil\" spec\n");
-+ return -1;
-+ }
-+ if (get_rate(&opt.ceil.rate, *argv)) {
-+ explain1("ceil");
-+ return -1;
-+ }
-+ ok++;
-+ } else if (strcmp(*argv, "rate") == 0) {
-+ NEXT_ARG();
-+ if (opt.rate.rate) {
-+ fprintf(stderr, "Double \"rate\" spec\n");
-+ return -1;
-+ }
-+ if (get_rate(&opt.rate.rate, *argv)) {
-+ explain1("rate");
-+ return -1;
-+ }
-+ ok++;
-+ } else if (strcmp(*argv, "help") == 0) {
-+ explain();
-+ return -1;
-+ } else {
-+ fprintf(stderr, "What is \"%s\"?\n", *argv);
-+ explain();
-+ return -1;
-+ }
-+ argc--; argv++;
-+ }
-+
-+/* if (!ok)
-+ return 0;*/
-+
-+ if (opt.rate.rate == 0) {
-+ fprintf(stderr, "\"rate\" is required.\n");
-+ return -1;
-+ }
-+ /* if ceil params are missing, use the same as rate */
-+ if (!opt.ceil.rate) opt.ceil = opt.rate;
-+
-+ /* compute minimal allowed burst from rate; mtu is added here to make
-+ sute that buffer is larger than mtu and to have some safeguard space */
-+ if (!buffer) buffer = opt.rate.rate / HZ + mtu;
-+ if (!cbuffer) cbuffer = opt.ceil.rate / HZ + mtu;
-+
-+ if ((cell_log = tc_calc_rtable(opt.rate.rate, rtab, cell_log, mtu, 0)) < 0) {
-+ fprintf(stderr, "htb: failed to calculate rate table.\n");
-+ return -1;
-+ }
-+ opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer);
-+ opt.rate.cell_log = cell_log;
-+
-+ if ((ccell_log = tc_calc_rtable(opt.ceil.rate, ctab, cell_log, mtu, 0)) < 0) {
-+ fprintf(stderr, "htb: failed to calculate ceil rate table.\n");
-+ return -1;
-+ }
-+ opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer);
-+ opt.ceil.cell_log = ccell_log;
-+
-+ tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len));
-+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
-+ addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt));
-+ addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024);
-+ addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024);
-+ tail->rta_len = (((void*)n)+NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
-+ return 0;
-+}
-+
-+static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
-+{
-+ struct rtattr *tb[TCA_HTB_RTAB+1];
-+ struct tc_htb_opt *hopt;
-+ struct tc_htb_glob *gopt;
-+ double buffer,cbuffer;
-+ SPRINT_BUF(b1);
-+ SPRINT_BUF(b2);
-+
-+ if (opt == NULL)
-+ return 0;
-+
-+ memset(tb, 0, sizeof(tb));
-+ parse_rtattr(tb, TCA_HTB_RTAB, RTA_DATA(opt), RTA_PAYLOAD(opt));
-+
-+ if (tb[TCA_HTB_PARMS]) {
-+
-+ hopt = RTA_DATA(tb[TCA_HTB_PARMS]);
-+ if (RTA_PAYLOAD(tb[TCA_HTB_PARMS]) < sizeof(*hopt)) return -1;
-+
-+ fprintf(f, "prio %d ", (int)hopt->prio);
-+ fprintf(f, "rate %s ", sprint_rate(hopt->rate.rate, b1));
-+ buffer = ((double)hopt->rate.rate*tc_core_tick2usec(hopt->buffer))/1000000;
-+ fprintf(f, "ceil %s ", sprint_rate(hopt->ceil.rate, b1));
-+ cbuffer = ((double)hopt->ceil.rate*tc_core_tick2usec(hopt->cbuffer))/1000000;
-+ if (show_details) {
-+ fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
-+ 1<<hopt->rate.cell_log, sprint_size(hopt->rate.mpu, b2));
-+ fprintf(f, "cburst %s/%u mpu %s ", sprint_size(cbuffer, b1),
-+ 1<<hopt->ceil.cell_log, sprint_size(hopt->ceil.mpu, b2));
-+ fprintf(f, "quantum %d ", (int)hopt->quantum);
-+ fprintf(f, "level %d ", (int)hopt->level);
-+ } else {
-+ fprintf(f, "burst %s ", sprint_size(buffer, b1));
-+ fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
-+ }
-+ if (show_raw)
-+ fprintf(f, "buffer [%08x] cbuffer [%08x] ",
-+ hopt->buffer,hopt->cbuffer);
-+ }
-+ if (tb[TCA_HTB_INIT]) {
-+ gopt = RTA_DATA(tb[TCA_HTB_INIT]);
-+ if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
-+
-+ fprintf(f, "r2q %d default %x dcache %d\n"
-+ " deq_util 1/%d deq_rate %d trials_per_deq %d\n dcache_hits %u direct_packets %u",
-+ gopt->rate2quantum,gopt->defcls,gopt->use_dcache,1000000/(1+gopt->utilz),
-+ gopt->deq_rate, gopt->trials/(1+gopt->deq_rate),gopt->dcache_hits,gopt->direct_pkts);
-+ }
-+ return 0;
-+}
-+
-+static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
-+{
-+ struct tc_htb_xstats *st;
-+ if (xstats == NULL)
-+ return 0;
-+
-+ if (RTA_PAYLOAD(xstats) < sizeof(*st))
-+ return -1;
-+
-+ st = RTA_DATA(xstats);
-+ fprintf(f, " lended: %u borrowed: %u giants: %u injects: %u\n",
-+ st->lends,st->borrows,st->giants,st->injects);
-+ fprintf(f, " tokens: %d ctokens: %d\n", st->tokens,st->ctokens);
-+ return 0;
-+}
-+
-+struct qdisc_util htb_util = {
-+ NULL,
-+ "htb",
-+ htb_parse_opt,
-+ htb_print_opt,
-+ htb_print_xstats,
-+ htb_parse_class_opt,
-+ htb_print_opt,
-+};
-+
-diff -uNr iproute2.pld/tc/Makefile iproute2/tc/Makefile
---- iproute2.pld/tc/Makefile Sun Apr 16 19:42:53 2000
-+++ iproute2/tc/Makefile Thu Feb 28 21:09:16 2002
-@@ -25,6 +25,7 @@
- endif
-
- #TCMODULES += q_csz.o
-+TCMODULES += q_htb.o
- #TCMODULES += q_hpfq.o
- #TCMODULES += q_hfsc.o
-
--- /dev/null
+--- iproute2/lib/utils.c~ Thu Aug 2 05:32:44 2001
++++ iproute2/lib/utils.c Mon Dec 10 21:56:05 2001
+@@ -390,7 +390,6 @@
+ len = 2;
+ break;
+ #endif
+- default:
+ }
+ }
+ if (len > 0 &&
--- /dev/null
+diff -urN iproute2.old/ip/ipaddress.c iproute2/ip/ipaddress.c
+--- iproute2.old/ip/ipaddress.c Sun Sep 10 21:03:26 2000
++++ iproute2/ip/ipaddress.c Thu Aug 23 06:07:46 2001
+@@ -719,6 +719,15 @@
+ filter.oneline = oneline;
+ }
+
++int default_scope(inet_prefix *lcl)
++{
++ if (lcl->family == AF_INET) {
++ if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127)
++ return RT_SCOPE_HOST;
++ }
++ return 0;
++}
++
+ int ipaddr_modify(int cmd, int argc, char **argv)
+ {
+ struct rtnl_handle rth;
+@@ -735,6 +744,7 @@
+ int peer_len = 0;
+ int brd_len = 0;
+ int any_len = 0;
++ int scoped = 0;
+
+ memset(&req, 0, sizeof(req));
+
+@@ -789,6 +799,7 @@
+ if (rtnl_rtscope_a2n(&scope, *argv))
+ invarg(*argv, "invalid scope value.");
+ req.ifa.ifa_scope = scope;
++ scoped = 1;
+ } else if (strcmp(*argv, "dev") == 0) {
+ NEXT_ARG();
+ d = *argv;
+@@ -847,6 +858,8 @@
+ brd_len = brd.bytelen;
+ }
+ }
++ if (!scoped && cmd != RTM_DELADDR)
++ req.ifa.ifa_scope = default_scope(&lcl);
+
+ if (rtnl_open(&rth, 0) < 0)
+ exit(1);
+diff -urN iproute2.old/ip/ipmaddr.c iproute2/ip/ipmaddr.c
+--- iproute2.old/ip/ipmaddr.c Sun Apr 16 19:42:51 2000
++++ iproute2/ip/ipmaddr.c Mon Dec 24 23:33:02 2001
+@@ -191,7 +191,7 @@
+
+ static void print_maddr(FILE *fp, struct ma_info *list)
+ {
+- fprintf(fp, "%s\t", _SL_);
++ fprintf(fp, "\t");
+
+ if (list->addr.family == AF_PACKET) {
+ SPRINT_BUF(b1);
+@@ -230,7 +230,8 @@
+
+ for (; list; list = list->next) {
+ if (oneline) {
+- fprintf(fp, "%d:\t%s", cur_index, list->name);
++ cur_index = list->index;
++ fprintf(fp, "%d:\t%s%s", cur_index, list->name, _SL_);
+ } else if (cur_index != list->index) {
+ cur_index = list->index;
+ fprintf(fp, "%d:\t%s\n", cur_index, list->name);
+diff -urN iproute2.old/ip/ipmroute.c iproute2/ip/ipmroute.c
+--- iproute2.old/ip/ipmroute.c Sun Apr 16 19:42:51 2000
++++ iproute2/ip/ipmroute.c Mon Dec 24 22:38:55 2001
+@@ -108,9 +108,9 @@
+ if (filter.msrc.family && inet_addr_match(&msrc, &filter.msrc, filter.msrc.bitlen))
+ continue;
+
+- format_host(AF_INET, 4, &msrc.data[0], sbuf, sizeof(sbuf));
+- format_host(AF_INET, 4, &maddr.data[0], mbuf, sizeof(mbuf));
+- snprintf(obuf, sizeof(obuf), "(%s, %s)", sbuf, mbuf);
++ snprintf(obuf, sizeof(obuf), "(%s, %s)",
++ format_host(AF_INET, 4, &msrc.data[0], sbuf, sizeof(sbuf)),
++ format_host(AF_INET, 4, &maddr.data[0], mbuf, sizeof(mbuf)));
+
+ fprintf(ofp, "%-32s Iif: ", obuf);
+
+@@ -162,7 +162,7 @@
+ while (argc > 0) {
+ if (strcmp(*argv, "iif") == 0) {
+ NEXT_ARG();
+- strcpy(filter_dev, *argv);
++ strncpy(filter_dev, *argv, sizeof(filter_dev)-1);
+ } else if (matches(*argv, "from") == 0) {
+ NEXT_ARG();
+ get_prefix(&filter.msrc, *argv, AF_INET);
+diff -urN iproute2.old/ip/iproute.c iproute2/ip/iproute.c
+--- iproute2.old/ip/iproute.c Thu Aug 2 06:32:09 2001
++++ iproute2/ip/iproute.c Thu Jan 10 03:12:16 2002
+@@ -617,8 +618,8 @@
+ fprintf(stderr, "Error: unexpected end of line after \"nexthop\"\n");
+ exit(-1);
+ }
++ memset(rtnh, 0, sizeof(*rtnh));
+ rtnh->rtnh_len = sizeof(*rtnh);
+- rtnh->rtnh_ifindex = 0;
+ rta->rta_len += rtnh->rtnh_len;
+ parse_one_nh(rta, rtnh, &argc, &argv);
+ rtnh = RTNH_NEXT(rtnh);
+diff -urN iproute2.old/ip/iptunnel.c iproute2/ip/iptunnel.c
+--- iproute2.old/ip/iptunnel.c Sun Apr 16 19:42:51 2000
++++ iproute2/ip/iptunnel.c Mon Dec 24 22:29:41 2001
+@@ -399,31 +399,36 @@
+
+ void print_tunnel(struct ip_tunnel_parm *p)
+ {
+- char s1[256];
+- char s2[256];
++ char s1[1024];
++ char s2[1024];
+ char s3[64];
+ char s4[64];
+
+- format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
+- format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
+ inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
+ inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
+
++ /* Do not use format_host() for local addr,
++ * symbolic name will not be useful.
++ */
+ printf("%s: %s/ip remote %s local %s ",
+ p->name,
+ p->iph.protocol == IPPROTO_IPIP ? "ip" :
+ (p->iph.protocol == IPPROTO_GRE ? "gre" :
+ (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")),
+- p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any");
++ p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
++ p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
++
+ if (p->link) {
+ char *n = do_ioctl_get_ifname(p->link);
+ if (n)
+ printf(" dev %s ", n);
+ }
++
+ if (p->iph.ttl)
+ printf(" ttl %d ", p->iph.ttl);
+ else
+ printf(" ttl inherit ");
++
+ if (p->iph.tos) {
+ SPRINT_BUF(b1);
+ printf(" tos");
+@@ -433,6 +438,7 @@
+ printf("%c%s ", p->iph.tos&1 ? '/' : ' ',
+ rtnl_dsfield_n2a(p->iph.tos&~1, b1, sizeof(b1)));
+ }
++
+ if (!(p->iph.frag_off&htons(IP_DF)))
+ printf(" nopmtudisc");
+
+diff -urN iproute2.old/lib/libnetlink.c iproute2/lib/libnetlink.c
+--- iproute2.old/lib/libnetlink.c Fri Aug 3 00:43:41 2001
++++ iproute2/lib/libnetlink.c Fri Aug 24 21:32:05 2001
+@@ -241,6 +241,7 @@
+ iov.iov_base = buf;
+
+ while (1) {
++ iov.iov_len = sizeof(buf);
+ status = recvmsg(rtnl->fd, &msg, 0);
+
+ if (status < 0) {
+diff -urN iproute2.old/lib/utils.c iproute2/lib/utils.c
+--- iproute2.old/lib/utils.c Thu Aug 2 05:32:44 2001
++++ iproute2/lib/utils.c Thu Jan 10 03:33:53 2002
+@@ -193,7 +193,9 @@
+
+ memset(dst, 0, sizeof(*dst));
+
+- if (strcmp(arg, "default") == 0 || strcmp(arg, "any") == 0) {
++ if (strcmp(arg, "default") == 0 ||
++ strcmp(arg, "any") == 0 ||
++ strcmp(arg, "all") == 0) {
+ if (family == AF_DECnet)
+ return -1;
+ dst->family = family;
+@@ -332,8 +334,21 @@
+
+ int __get_hz(void)
+ {
++ char name[1024];
+ int hz = 0;
+- FILE *fp = fopen("/proc/net/psched", "r");
++ FILE *fp;
++
++ if (getenv("HZ"))
++ return atoi(getenv("HZ")) ? : HZ;
++
++ if (getenv("PROC_NET_PSCHED")) {
++ snprintf(name, sizeof(name)-1, "%s", getenv("PROC_NET_PSCHED"));
++ } else if (getenv("PROC_ROOT")) {
++ snprintf(name, sizeof(name)-1, "%s/net/psched", getenv("PROC_ROOT"));
++ } else {
++ strcpy(name, "/proc/net/psched");
++ }
++ fp = fopen(name, "r");
+
+ if (fp) {
+ unsigned nom, denom;
+
--- /dev/null
+--- iproute2/Makefile~ Tue Aug 7 15:58:27 2001
++++ iproute2/Makefile Tue Aug 7 15:58:55 2001
+@@ -28,7 +28,7 @@
+ endif
+
+ CC = gcc
+-CCOPTS = -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -Werror -g
++CCOPTS = -D_GNU_SOURCE $(OPT) -Wstrict-prototypes -Wall -g
+ CFLAGS = $(CCOPTS) $(GLIBCFIX) -I$(KERNEL_INCLUDE) -I../include $(DEFINES)
+
+ LDLIBS += -L../lib -lnetlink -lutil
+++ /dev/null
-diff -urN iproute2/ip/ipaddress.c.orig iproute2/ip/ipaddress.c
---- iproute2/ip/ipaddress.c.orig Sat Sep 27 03:56:06 2003
-+++ iproute2/ip/ipaddress.c Sat Sep 27 04:02:40 2003
-@@ -220,9 +220,9 @@
- s = &slocal;
- }
- fprintf(fp, "%s", _SL_);
-- fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s",
-+ fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s",
- s->rx_compressed ? "compressed" : "", _SL_);
-- fprintf(fp, " %-10lu %-8lu %-7lu %-7lu %-7lu %-7lu",
-+ fprintf(fp, " %-14llu %-8lu %-7lu %-7lu %-7lu %-7lu",
- s->rx_bytes, s->rx_packets, s->rx_errors,
- s->rx_dropped, s->rx_over_errors,
- s->multicast
-@@ -232,7 +232,7 @@
- if (show_stats > 1) {
- fprintf(fp, "%s", _SL_);
- fprintf(fp, " RX errors: length crc frame fifo missed%s", _SL_);
-- fprintf(fp, " %-7lu %-7lu %-7lu %-7lu %-7lu",
-+ fprintf(fp, " %-7lu %-7lu %-7lu %-7lu %-7lu",
- s->rx_length_errors,
- s->rx_crc_errors,
- s->rx_frame_errors,
-@@ -241,9 +241,9 @@
- );
- }
- fprintf(fp, "%s", _SL_);
-- fprintf(fp, " TX: bytes packets errors dropped carrier collsns %s%s",
-+ fprintf(fp, " TX: bytes packets errors dropped carrier collsns %s%s",
- s->tx_compressed ? "compressed" : "", _SL_);
-- fprintf(fp, " %-10lu %-8lu %-7lu %-7lu %-7lu %-7lu",
-+ fprintf(fp, " %-14llu %-8lu %-7lu %-7lu %-7lu %-7lu",
- s->tx_bytes, s->tx_packets, s->tx_errors,
- s->tx_dropped, s->tx_carrier_errors, s->collisions);
- if (s->tx_compressed)
-@@ -251,7 +251,7 @@
- if (show_stats > 1) {
- fprintf(fp, "%s", _SL_);
- fprintf(fp, " TX errors: aborted fifo window heartbeat%s", _SL_);
-- fprintf(fp, " %-7lu %-7lu %-7lu %-7lu",
-+ fprintf(fp, " %-7lu %-7lu %-7lu %-7lu",
- s->tx_aborted_errors,
- s->tx_fifo_errors,
- s->tx_window_errors,
diff -Nur --exclude *~ iproute2/lib/inet_ntop.c iproute2.new/lib/inet_ntop.c
--- iproute2/lib/inet_ntop.c Sun Apr 16 19:42:52 2000
+++ iproute2.new/lib/inet_ntop.c Sun Apr 15 14:11:19 2001
-@@ -28,10 +28,10 @@
+@@ -28,8 +28,8 @@
#include <errno.h>
#include <stdio.h>
-#include <linux/in6.h>
--#ifndef IN6ADDRSZ
-#define IN6ADDRSZ sizeof(struct in6_addr)
--#endif
+/* #include <linux/in6.h> */
-+/* #ifndef IN6ADDRSZ */
+/* #define IN6ADDRSZ sizeof(struct in6_addr) */
-+/* #endif */
#ifdef SPRINTF_CHAR
# define SPRINTF(x) strlen(sprintf/**/x)
/*
* WARNING: Don't even consider trying to compile this on a system where
+diff -Nur --exclude *~ iproute2/ip/Makefile iproute2.new/ip/Makefile
+--- iproute2/ip/Makefile Sun Apr 16 19:42:50 2000
++++ iproute2.new/ip/Makefile Sun Apr 15 14:26:48 2001
+@@ -14,7 +14,7 @@
+
+ rtmon: $(RTMONOBJ) $(LIBNETLINK)
+
+-rtacct: $(RTACCTOBJ)
++rtacct: $(RTACCTOBJ) $(LIBNETLINK)
+
+ clean:
+ rm -f $(IPOBJ) $(RTMONOBJ) $(RTACCTOBJ) ip rtmon rtacct
+++ /dev/null
-#
-# Conditional build
-%bcond_without doc # don't build documentation
-%bcond_without tc # don't build tc program (it breaks static linkage)
-%bcond_with uClibc # do some hacks to build with uClibc
-#
-Summary: Utility to control Networking behavior in 2.2.X kernels
-Summary(es): Herramientas para encaminamiento avanzado y configuración de interfaces de red
-Summary(pl): Narzêdzie do kontrolowania Sieci w kernelach 2.2
-Summary(pt_BR): Ferramentas para roteamento avançado e configuração de interfaces de rede
-Name: iproute2
-%define mainver 2.4.7
-%define snapshot ss020116
-Version: %{mainver}.%{snapshot}
-Release: 16
-License: GPL
-Vendor: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
-Group: Networking/Admin
-Source0: ftp://ftp.inr.ac.ru/ip-routing/%{name}-%{mainver}-now-%{snapshot}.tar.gz
-# Source0-md5: 2c7e5f3a10e703745ecdc613f7a7d187
-Source1: %{name}-owl-man.tar.bz2
-# Source1-md5: cd4425df972a4ab001db31a5eb1c5da5
-Patch0: %{name}-Makefile.patch
-Patch1: %{name}-llh.patch
-Patch2: %{name}-diffserv-config.patch
-Patch3: %{name}-netlink.patch
-Patch4: %{name}-ipaddress.patch
-Patch5: %{name}-iprule.patch
-# uClibc hacks
-Patch6: %{name}-uClibc.patch
-# extensions
-Patch10: %{name}-htb3.6_tc.patch
-Patch11: %{name}-2.2.4-wrr.patch
-Patch12: %{name}-2.2.4-esfq.patch
-Patch13: %{name}-hfsc.patch
-BuildRequires: bison
-BuildRequires: linux-libc-headers >= 7:2.6.4.0-3
-%if %{with doc}
-BuildRequires: psutils
-BuildRequires: sgml-tools
-BuildRequires: tetex-dvips
-BuildRequires: tetex-latex
-BuildRequires: tetex-tex-babel
-%endif
-Obsoletes: iproute
-BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
-
-%define _sbindir /sbin
-%define _sysconfdir /etc/iproute2
-
-%description
-Linux 2.2 maintains compatibility with the basic configuration
-utilities of the network (ifconfig, route) but a new utility is
-required to exploit the new characteristics and features of the
-kernel. This package includes the new utilities.
-
-%description -l es
-Linux mantiene compatibilidad con los utilitarios estándares de
-configuración de la red, pero se necesitan nuevos utilitarios para
-usar los recursos y características del nuevo núcleo. Este paquete
-incluye los nuevos utilitarios.
-
-%description -l pl
-Ten pakiet zawiera programy pozwalaj±ce na kontrolê routingu i innych
-aspektów dotycz±cych sieci.
-
-%description -l pt_BR
-O Linux mantém compatibilidade com os utilitários padrão de
-configuração da rede, mas novos utilitários são necessários para fazer
-uso das características e recursos da nova kernel. This package
-includes the new utilities.
-
-%package -n libnetlink-devel
-Summary: Library for the netlink interface
-Summary(pl): Biblioteka do interfejsu netlink
-Group: Development/Libraries
-
-%description -n libnetlink-devel
-This library provides an interface for kernel-user netlink interface.
-
-%description -n libnetlink-devel -l pl
-Ta biblioteka udostêpnia interfejs do interfejsu netlink miêdzy j±drem
-a przestrzeni± u¿ytkownika.
-
-%prep
-%setup -q -n %{name} -a1
-rm -rf include-glibc
-%patch0 -p1
-%patch1 -p1
-%patch2 -p1
-%patch3 -p1
-%patch4 -p1
-%patch5 -p1
-%{?with_uClibc:%patch6 -p1}
-%patch10 -p1
-%patch11 -p1
-%patch12 -p1
-%patch13 -p1
-
-%build
-%{__make} \
- CC="%{__cc}" \
- OPT="%{rpmcflags}" \
- %{!?with_tc:SUBDIRS="lib ip misc" LDFLAGS="%{rpmldflags}"}
-
-%{?with_doc:%{__make} -C doc}
-
-%install
-rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_sbindir},%{_sysconfdir},%{_mandir}/man8,%{_libdir},%{_includedir}}
-
-install ip/{ip,rtmon,routel} %{?with_tc:tc/tc} misc/{rtacct,rtstat,ss,ifstat} $RPM_BUILD_ROOT%{_sbindir}
-install etc/iproute2/rt_protos \
- etc/iproute2/rt_realms \
- etc/iproute2/rt_scopes \
- etc/iproute2/rt_tables \
- $RPM_BUILD_ROOT%{_sysconfdir}
-install man/* $RPM_BUILD_ROOT%{_mandir}/man8
-install lib/libnetlink.a $RPM_BUILD_ROOT%{_libdir}
-install include/libnetlink.h $RPM_BUILD_ROOT%{_includedir}
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%files
-%defattr(644,root,root,755)
-%doc README README.iproute2+tc RELNOTES %{?with_doc:doc/*.ps}
-%attr(755,root,root) %{_sbindir}/*
-%dir %{_sysconfdir}
-%config(noreplace) %verify(not md5 size mtime) %{_sysconfdir}/*
-%{_mandir}/man8/*
-
-%files -n libnetlink-devel
-%defattr(644,root,root,755)
-%{_libdir}/lib*.a
-%{_includedir}/*.h
--- /dev/null
+diff -uNrbB org/tc/Makefile new/tc/Makefile
+--- org/tc/Makefile Fri Feb 25 20:51:57 2000
++++ new/tc/Makefile Mon Feb 12 17:24:48 2001
+@@ -9,6 +9,7 @@
+ TCMODULES += q_prio.o
+ TCMODULES += q_tbf.o
+ TCMODULES += q_cbq.o
++TCMODULES += q_wrr.o
+ TCMODULES += f_rsvp.o
+ TCMODULES += f_u32.o
+ TCMODULES += f_route.o
+diff -uNrbB org/tc/q_wrr.c new/tc/q_wrr.c
+--- org/tc/q_wrr.c Thu Jan 1 01:00:00 1970
++++ new/tc/q_wrr.c Sun Sep 9 12:44:28 2001
+@@ -0,0 +1,437 @@
++#include <stdio.h>
++#include <stdlib.h>
++#include <unistd.h>
++#include <syslog.h>
++#include <fcntl.h>
++#include <sys/socket.h>
++#include <netinet/in.h>
++#include <arpa/inet.h>
++#include <string.h>
++#include <math.h>
++
++#include "utils.h"
++#include "tc_util.h"
++
++#define usage() return(-1)
++
++#ifdef NEED_WRR_DEFS
++/* WRR section */
++
++/* Other includes */
++#include <linux/if_ether.h>
++
++// A sub weight and of a class
++// All numbers are represented as parts of (2^64-1).
++struct tc_wrr_class_weight {
++ __u64 val; // Current value (0 is not valid)
++ __u64 decr; // Value pr bytes (2^64-1 is not valid)
++ __u64 incr; // Value pr seconds (2^64-1 is not valid)
++ __u64 min; // Minimal value (0 is not valid)
++ __u64 max; // Minimal value (0 is not valid)
++
++ // The time where the above information was correct:
++ time_t tim;
++};
++
++// Pakcet send when modifying a class:
++struct tc_wrr_class_modf {
++ // Not-valid values are ignored.
++ struct tc_wrr_class_weight weight1;
++ struct tc_wrr_class_weight weight2;
++};
++
++// Packet returned when quering a class:
++struct tc_wrr_class_stats {
++ char used; // If this is false the information below is invalid
++
++ struct tc_wrr_class_modf class_modf;
++
++ unsigned char addr[ETH_ALEN];
++ char usemac; // True if addr is a MAC address, else it is an IP address
++ // (this value is only for convience, it is always the same
++ // value as in the qdisc)
++ int heappos; // Current heap position or 0 if not in heap
++ __u64 penal_ls; // Penalty value in heap (ls)
++ __u64 penal_ms; // Penalty value in heap (ms)
++};
++
++// Qdisc-wide penalty information (boolean values - 2 not valid)
++struct tc_wrr_qdisc_weight {
++ char weight_mode; // 0=No automatic change to weight
++ // 1=Decrease normally
++ // 2=Also multiply with number of machines
++ // 3=Instead multiply with priority divided
++ // with priority of the other.
++ // -1=no change
++};
++
++// Packet send when modifing a qdisc:
++struct tc_wrr_qdisc_modf {
++ // Not-valid values are ignored:
++ struct tc_wrr_qdisc_weight weight1;
++ struct tc_wrr_qdisc_weight weight2;
++};
++
++// Packet send when creating a qdisc:
++struct tc_wrr_qdisc_crt {
++ struct tc_wrr_qdisc_modf qdisc_modf;
++
++ char srcaddr; // 1=lookup source, 0=lookup destination
++ char usemac; // 1=Classify on MAC addresses, 0=classify on IP
++ char usemasq; // 1=Classify based on masqgrading - only valid
++ // if usemac is zero
++ int bands_max; // Maximal number of bands (i.e.: classes)
++ int proxy_maxconn; // If differnt from 0 then we support proxy remapping
++ // of packets. And this is the number of maximal
++ // concurrent proxy connections.
++};
++
++// Packet returned when quering a qdisc:
++struct tc_wrr_qdisc_stats {
++ struct tc_wrr_qdisc_crt qdisc_crt;
++ int proxy_curconn;
++ int nodes_in_heap; // Current number of bands wanting to send something
++ int bands_cur; // Current number of bands used (i.e.: MAC/IP addresses seen)
++ int bands_reused; // Number of times this band has been reused.
++ int packets_requed; // Number of times packets have been requeued.
++ __u64 priosum; // Sum of priorities in heap where 1 is 2^32
++};
++
++struct tc_wrr_qdisc_modf_std {
++ // This indicates which of the tc_wrr_qdisc_modf structers this is:
++ char proxy; // 0=This struct
++
++ // Should we also change a class?
++ char change_class;
++
++ // Only valid if change_class is false
++ struct tc_wrr_qdisc_modf qdisc_modf;
++
++ // Only valid if change_class is true:
++ unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
++ struct tc_wrr_class_modf class_modf; // The change
++};
++
++// Used for proxyrempping:
++struct tc_wrr_qdisc_modf_proxy {
++ // This indicates which of the tc_wrr_qdisc_modf structers this is:
++ char proxy; // 1=This struct
++
++ // This is 1 if the proxyremap information should be reset
++ char reset;
++
++ // changec is the number of elements in changes.
++ int changec;
++
++ // This is an array of type ProxyRemapBlock:
++ long changes[0];
++};
++#endif /* NEED_WRR_DEFS */
++
++// Returns -1 on error
++static int wrr_parse_qdisc_weight(int argc, char** argv,
++ struct tc_wrr_qdisc_modf* opt) {
++ int i;
++
++ opt->weight1.weight_mode=-1;
++ opt->weight2.weight_mode=-1;
++
++ for(i=0; i<argc; i++) {
++ if(!memcmp(argv[i],"wmode1=",7)) {
++ opt->weight1.weight_mode=atoi(argv[i]+7);
++ } else if(!memcmp(argv[i],"wmode2=",7)) {
++ opt->weight2.weight_mode=atoi(argv[i]+7);
++ } else {
++ printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
++ return -1;
++ }
++ }
++ return 0;
++}
++
++static int wrr_parse_class_modf(int argc, char** argv,
++ struct tc_wrr_class_modf* modf) {
++ int i;
++
++ if(argc<1) {
++ fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
++ fprintf(stderr, " The values can be floating point like 0.42 or divisions like 42/100\n");
++ return -1;
++ }
++
++ // Set meaningless values:
++ modf->weight1.val=0;
++ modf->weight1.decr=(__u64)-1;
++ modf->weight1.incr=(__u64)-1;
++ modf->weight1.min=0;
++ modf->weight1.max=0;
++ modf->weight2.val=0;
++ modf->weight2.decr=(__u64)-1;
++ modf->weight2.incr=(__u64)-1;
++ modf->weight2.min=0;
++ modf->weight2.max=0;
++
++ // And read values:
++ for(i=0; i<argc; i++) {
++ char arg[80];
++ char* name,*value1=0,*value2=0;
++ long double f_val1,f_val2=1,value;
++ if(strlen(argv[i])>=sizeof(arg)) {
++ fprintf(stderr,"Argument too long: %s\n",argv[i]);
++ return -1;
++ }
++ strcpy(arg,argv[i]);
++
++ name=strtok(arg,"=");
++ if(name) value1=strtok(0,"/");
++ if(value1) value2=strtok(0,"");
++
++ if(!value1) {
++ fprintf(stderr,"No = found in argument: %s\n",argv[i]);
++ return -1;
++ }
++
++ f_val1=atof(value1);
++ if(value2) f_val2=atof(value2);
++
++ if(f_val2==0) {
++ fprintf(stderr,"Division by 0\n");
++ return -1;
++ }
++
++ value=f_val1/f_val2;
++ if(value>1) value=1;
++ if(value<0) value=0;
++ value*=((__u64)-1);
++
++ // And find the value set
++ if(!strcmp(name,"weight1")) modf->weight1.val=value;
++ else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
++ else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
++ else if(!strcmp(name,"min1")) modf->weight1.min=value;
++ else if(!strcmp(name,"max1")) modf->weight1.max=value;
++ else if(!strcmp(name,"weight2")) modf->weight2.val=value;
++ else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
++ else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
++ else if(!strcmp(name,"min2")) modf->weight2.min=value;
++ else if(!strcmp(name,"max2")) modf->weight2.max=value;
++ else {
++ fprintf(stderr,"illegal value: %s\n",name);
++ return -1;
++ }
++ }
++
++ return 0;
++}
++
++static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
++{
++ if(n->nlmsg_flags & NLM_F_CREATE) {
++ // This is a create request:
++ struct tc_wrr_qdisc_crt opt;
++
++ int sour,dest,ip,mac,masq;
++
++ if(argc<4) {
++ fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
++ return -1;
++ }
++
++ // Read sour/dest:
++ memset(&opt,0,sizeof(opt));
++ sour=!strcmp(argv[0],"sour");
++ dest=!strcmp(argv[0],"dest");
++
++ if(!sour && !dest) {
++ fprintf(stderr,"sour or dest must be specified\n");
++ return -1;
++ }
++
++ // Read ip/mac
++ ip=!strcmp(argv[1],"ip");
++ mac=!strcmp(argv[1],"mac");
++ masq=!strcmp(argv[1],"masq");
++
++ if(!ip && !mac && !masq) {
++ fprintf(stderr,"ip, masq or mac must be specified\n");
++ return -1;
++ }
++
++ opt.srcaddr=sour;
++ opt.usemac=mac;
++ opt.usemasq=masq;
++ opt.bands_max=atoi(argv[2]);
++
++ opt.proxy_maxconn=atoi(argv[3]);
++
++ // Read weights:
++ if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
++ if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
++ if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
++
++ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
++ } else {
++ struct tc_wrr_qdisc_modf_std opt;
++ char qdisc,class;
++
++ // This is a modify request:
++ if(argc<1) {
++ fprintf(stderr,"... qdisc ... or ... class ...\n");
++ return -1;
++ }
++
++ qdisc=!strcmp(argv[0],"qdisc");
++ class=!strcmp(argv[0],"class");
++
++ if(!qdisc && !class) {
++ fprintf(stderr,"qdisc or class must be specified\n");
++ return -1;
++ }
++
++ argc--;
++ argv++;
++
++ opt.proxy=0;
++
++ if(qdisc) {
++ opt.change_class=0;
++ if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
++ } else {
++ int a0,a1,a2,a3,a4=0,a5=0;
++
++ opt.change_class=1;
++
++ if(argc<1) {
++ fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
++ return -1;
++ }
++ memset(opt.addr,0,sizeof(opt.addr));
++
++ if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
++ (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
++ fprintf(stderr,"Wrong format of mac or ip address\n");
++ return -1;
++ }
++
++ opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
++ opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
++
++ if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
++ }
++
++ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
++ }
++ return 0;
++}
++
++static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
++ struct tc_wrr_class_modf opt;
++
++ memset(&opt,0,sizeof(opt));
++ if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
++
++ addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
++ return 0;
++}
++
++static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
++{
++ struct tc_wrr_qdisc_stats *qopt;
++
++ if (opt == NULL)
++ return 0;
++
++ if (RTA_PAYLOAD(opt) < sizeof(*qopt))
++ return -1;
++ qopt = RTA_DATA(opt);
++
++ fprintf(f,"\n (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
++ qopt->qdisc_crt.srcaddr ? "sour" : "dest",
++ qopt->qdisc_crt.usemac ? "mac" : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),
++ qopt->qdisc_crt.bands_max,
++ qopt->bands_cur,
++ qopt->bands_reused
++ );
++
++ if(qopt->qdisc_crt.proxy_maxconn) {
++ fprintf(f," (proxy maxcon %i) (proxy curcon %i)\n",
++ qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
++ }
++
++ fprintf(f," (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
++ qopt->nodes_in_heap,
++ qopt->packets_requed,
++ qopt->priosum/((long double)((__u32)-1))
++ );
++
++ fprintf(f," (wmode1 %i) (wmode2 %i) \n",
++ qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
++ qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
++
++ return 0;
++}
++
++static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
++ struct tc_wrr_class_stats *copt;
++ long double d=(__u64)-1;
++
++ if (opt == NULL) return 0;
++
++ if (RTA_PAYLOAD(opt) < sizeof(*copt))
++ return -1;
++ copt = RTA_DATA(opt);
++
++ if(!copt->used) {
++ fprintf(f,"(unused)");
++ return 0;
++ }
++
++ if(copt->usemac) {
++ fprintf(f,"\n (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
++ copt->addr[0],copt->addr[1],copt->addr[2],
++ copt->addr[3],copt->addr[4],copt->addr[5]);
++ } else {
++ fprintf(f,"\n (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
++ }
++
++ fprintf(f," (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
++ (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
++ copt->heappos,
++ (unsigned)(copt->penal_ms>>32),
++ (unsigned)(copt->penal_ms & 0xffffffffU),
++ (unsigned)(copt->penal_ls>>32),
++ (unsigned)(copt->penal_ls & 0xffffffffU)
++ );
++
++ fprintf(f," Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
++ copt->class_modf.weight1.val/d,
++ copt->class_modf.weight1.decr/d,
++ copt->class_modf.weight1.incr/d,
++ copt->class_modf.weight1.min/d,
++ copt->class_modf.weight1.max/d);
++
++ fprintf(f," Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
++ copt->class_modf.weight2.val/d,
++ copt->class_modf.weight2.decr/d,
++ copt->class_modf.weight2.incr/d,
++ copt->class_modf.weight2.min/d,
++ copt->class_modf.weight2.max/d);
++
++ return 0;
++}
++
++static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
++{
++ return 0;
++}
++
++
++struct qdisc_util wrr_util = {
++ NULL,
++ "wrr",
++ wrr_parse_opt,
++ wrr_print_opt,
++ wrr_print_xstats,
++ wrr_parse_copt,
++ wrr_print_copt
++};