1 --- iproute2-5.10.0/tc/Makefile.orig 2021-02-24 19:25:55.137480328 +0100
2 +++ iproute2-5.10.0/tc/Makefile 2021-02-24 19:26:32.562746684 +0100
11 --- iproute2-5.10.0/include/uapi/linux/pkt_sched.h.orig 2021-02-24 19:26:51.060368757 +0100
12 +++ iproute2-5.10.0/include/uapi/linux/pkt_sched.h 2021-02-24 19:28:08.234354809 +0100
14 #define NETEM_DIST_SCALE 8192
15 #define NETEM_DIST_MAX 16384
20 +#include <linux/if_ether.h>
21 +#include <sys/time.h>
23 +// A sub weight and of a class
24 +// All numbers are represented as parts of (2^64-1).
25 +struct tc_wrr_class_weight {
26 + __u64 val; // Current value (0 is not valid)
27 + __u64 decr; // Value pr bytes (2^64-1 is not valid)
28 + __u64 incr; // Value pr seconds (2^64-1 is not valid)
29 + __u64 min; // Minimal value (0 is not valid)
30 + __u64 max; // Minimal value (0 is not valid)
32 +// The time where the above information was correct:
36 +// Packet send when modifying a class:
37 +struct tc_wrr_class_modf {
38 + // Not-valid values are ignored.
39 + struct tc_wrr_class_weight weight1;
40 + struct tc_wrr_class_weight weight2;
43 +// Packet returned when quering a class:
44 +struct tc_wrr_class_stats {
45 + char used; // If this is false the information below is invalid
47 + struct tc_wrr_class_modf class_modf;
49 + unsigned char addr[ETH_ALEN];
50 + char usemac; // True if addr is a MAC address, else it is an IP address
51 + // (this value is only for convience, it is always the same
52 + // value as in the qdisc)
53 + int heappos; // Current heap position or 0 if not in heap
54 + __u64 penal_ls; // Penalty value in heap (ls)
55 + __u64 penal_ms; // Penalty value in heap (ms)
58 +// Qdisc-wide penalty information (boolean values - 2 not valid)
59 +struct tc_wrr_qdisc_weight {
60 + char weight_mode; // 0=No automatic change to weight
61 + // 1=Decrease normally
62 + // 2=Also multiply with number of machines
63 + // 3=Instead multiply with priority divided
64 + // with priority of the other.
68 +// Packet send when modifing a qdisc:
69 +struct tc_wrr_qdisc_modf {
70 + // Not-valid values are ignored:
71 + struct tc_wrr_qdisc_weight weight1;
72 + struct tc_wrr_qdisc_weight weight2;
75 +// Packet send when creating a qdisc:
76 +struct tc_wrr_qdisc_crt {
77 + struct tc_wrr_qdisc_modf qdisc_modf;
79 + char srcaddr; // 1=lookup source, 0=lookup destination
80 + char usemac; // 1=Classify on MAC addresses, 0=classify on IP
81 + char usemasq; // 1=Classify based on masqgrading - only valid
82 + // if usemac is zero
83 + int bands_max; // Maximal number of bands (i.e.: classes)
84 + int proxy_maxconn;// If differnt from 0 then we support proxy remapping
85 + // of packets. And this is the number of maximal
86 + // concurrent proxy connections.
89 +// Packet returned when quering a qdisc:
90 +struct tc_wrr_qdisc_stats {
91 + struct tc_wrr_qdisc_crt qdisc_crt;
93 + int nodes_in_heap; // Current number of bands wanting to send something
94 + int bands_cur; // Current number of bands used (i.e.: MAC/IP addresses seen)
95 + int bands_reused; // Number of times this band has been reused.
96 + int packets_requed; // Number of times packets have been requeued.
97 + __u64 priosum; // Sum of priorities in heap where 1 is 2^32
100 +struct tc_wrr_qdisc_modf_std {
101 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
102 + char proxy; // 0=This struct
104 + // Should we also change a class?
107 + // Only valid if change_class is false
108 + struct tc_wrr_qdisc_modf qdisc_modf;
110 + // Only valid if change_class is true:
111 + unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
112 + struct tc_wrr_class_modf class_modf; // The change
115 +// Used for proxyrempping:
116 +struct tc_wrr_qdisc_modf_proxy {
117 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
118 + char proxy; // 1=This struct
120 + // This is 1 if the proxyremap information should be reset
123 + // changec is the number of elements in changes.
126 + // This is an array of type ProxyRemapBlock:
133 diff -urN iproute-2.6.20-070313-orig/tc/q_wrr.c iproute-2.6.20-070313/tc/q_wrr.c
134 --- iproute-2.6.20-070313-orig/tc/q_wrr.c 1970-01-01 01:00:00.000000000 +0100
135 +++ iproute-2.6.20-070313/tc/q_wrr.c 2007-04-15 20:52:33.000000000 +0200
142 +#include <sys/socket.h>
143 +#include <netinet/in.h>
144 +#include <arpa/inet.h>
149 +#include "tc_util.h"
151 +#define usage() return(-1)
153 +// Returns -1 on error
154 +static int wrr_parse_qdisc_weight(int argc, char** argv,
155 + struct tc_wrr_qdisc_modf* opt) {
158 + opt->weight1.weight_mode=-1;
159 + opt->weight2.weight_mode=-1;
161 + for(i=0; i<argc; i++) {
162 + if(!memcmp(argv[i],"wmode1=",7)) {
163 + opt->weight1.weight_mode=atoi(argv[i]+7);
164 + } else if(!memcmp(argv[i],"wmode2=",7)) {
165 + opt->weight2.weight_mode=atoi(argv[i]+7);
167 + printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
174 +static int wrr_parse_class_modf(int argc, char** argv,
175 + struct tc_wrr_class_modf* modf) {
179 + fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
180 + fprintf(stderr, " The values can be floating point like 0.42 or divisions like 42/100\n");
184 + // Set meaningless values:
185 + modf->weight1.val=0;
186 + modf->weight1.decr=(__u64)-1;
187 + modf->weight1.incr=(__u64)-1;
188 + modf->weight1.min=0;
189 + modf->weight1.max=0;
190 + modf->weight2.val=0;
191 + modf->weight2.decr=(__u64)-1;
192 + modf->weight2.incr=(__u64)-1;
193 + modf->weight2.min=0;
194 + modf->weight2.max=0;
196 + // And read values:
197 + for(i=0; i<argc; i++) {
199 + char* name,*value1=0,*value2=0;
200 + long double f_val1,f_val2=1,value;
201 + if(strlen(argv[i])>=sizeof(arg)) {
202 + fprintf(stderr,"Argument too long: %s\n",argv[i]);
205 + strcpy(arg,argv[i]);
207 + name=strtok(arg,"=");
208 + if(name) value1=strtok(0,"/");
209 + if(value1) value2=strtok(0,"");
212 + fprintf(stderr,"No = found in argument: %s\n",argv[i]);
216 + f_val1=atof(value1);
217 + if(value2) f_val2=atof(value2);
220 + fprintf(stderr,"Division by 0\n");
224 + value=f_val1/f_val2;
225 + if(value>1) value=1;
226 + if(value<0) value=0;
227 + value*=((__u64)-1);
229 + // And find the value set
230 + if(!strcmp(name,"weight1")) modf->weight1.val=value;
231 + else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
232 + else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
233 + else if(!strcmp(name,"min1")) modf->weight1.min=value;
234 + else if(!strcmp(name,"max1")) modf->weight1.max=value;
235 + else if(!strcmp(name,"weight2")) modf->weight2.val=value;
236 + else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
237 + else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
238 + else if(!strcmp(name,"min2")) modf->weight2.min=value;
239 + else if(!strcmp(name,"max2")) modf->weight2.max=value;
241 + fprintf(stderr,"illegal value: %s\n",name);
249 +static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
251 + if(n->nlmsg_flags & NLM_F_CREATE) {
252 + // This is a create request:
253 + struct tc_wrr_qdisc_crt opt;
255 + int sour,dest,ip,mac,masq;
258 + fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
263 + memset(&opt,0,sizeof(opt));
264 + sour=!strcmp(argv[0],"sour");
265 + dest=!strcmp(argv[0],"dest");
267 + if(!sour && !dest) {
268 + fprintf(stderr,"sour or dest must be specified\n");
273 + ip=!strcmp(argv[1],"ip");
274 + mac=!strcmp(argv[1],"mac");
275 + masq=!strcmp(argv[1],"masq");
277 + if(!ip && !mac && !masq) {
278 + fprintf(stderr,"ip, masq or mac must be specified\n");
285 + opt.bands_max=atoi(argv[2]);
287 + opt.proxy_maxconn=atoi(argv[3]);
290 + if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
291 + if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
292 + if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
294 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
296 + struct tc_wrr_qdisc_modf_std opt;
299 + // This is a modify request:
301 + fprintf(stderr,"... qdisc ... or ... class ...\n");
305 + qdisc=!strcmp(argv[0],"qdisc");
306 + class=!strcmp(argv[0],"class");
308 + if(!qdisc && !class) {
309 + fprintf(stderr,"qdisc or class must be specified\n");
319 + opt.change_class=0;
320 + if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
322 + int a0,a1,a2,a3,a4=0,a5=0;
324 + opt.change_class=1;
327 + fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
330 + memset(opt.addr,0,sizeof(opt.addr));
332 + if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
333 + (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
334 + fprintf(stderr,"Wrong format of mac or ip address\n");
338 + opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
339 + opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
341 + if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
344 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
349 +static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
350 + struct tc_wrr_class_modf opt;
352 + memset(&opt,0,sizeof(opt));
353 + if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
355 + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
359 +static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
361 + struct tc_wrr_qdisc_stats *qopt;
366 + if (RTA_PAYLOAD(opt) < sizeof(*qopt))
368 + qopt = RTA_DATA(opt);
370 + fprintf(f,"\n (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
371 + qopt->qdisc_crt.srcaddr ? "sour" : "dest",
372 + qopt->qdisc_crt.usemac ? "mac" : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),
373 + qopt->qdisc_crt.bands_max,
378 + if(qopt->qdisc_crt.proxy_maxconn) {
379 + fprintf(f," (proxy maxcon %i) (proxy curcon %i)\n",
380 + qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
383 + fprintf(f," (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
384 + qopt->nodes_in_heap,
385 + qopt->packets_requed,
386 + qopt->priosum/((long double)((__u32)-1))
389 + fprintf(f," (wmode1 %i) (wmode2 %i) \n",
390 + qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
391 + qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
396 +static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
397 + struct tc_wrr_class_stats *copt;
398 + long double d=(__u64)-1;
400 + if (opt == NULL) return 0;
402 + if (RTA_PAYLOAD(opt) < sizeof(*copt))
404 + copt = RTA_DATA(opt);
407 + fprintf(f,"(unused)");
412 + fprintf(f,"\n (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
413 + copt->addr[0],copt->addr[1],copt->addr[2],
414 + copt->addr[3],copt->addr[4],copt->addr[5]);
416 + fprintf(f,"\n (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
419 + fprintf(f," (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
420 + (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
422 + (unsigned)(copt->penal_ms>>32),
423 + (unsigned)(copt->penal_ms & 0xffffffffU),
424 + (unsigned)(copt->penal_ls>>32),
425 + (unsigned)(copt->penal_ls & 0xffffffffU)
428 + fprintf(f," Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
429 + copt->class_modf.weight1.val/d,
430 + copt->class_modf.weight1.decr/d,
431 + copt->class_modf.weight1.incr/d,
432 + copt->class_modf.weight1.min/d,
433 + copt->class_modf.weight1.max/d);
435 + fprintf(f," Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
436 + copt->class_modf.weight2.val/d,
437 + copt->class_modf.weight2.decr/d,
438 + copt->class_modf.weight2.incr/d,
439 + copt->class_modf.weight2.min/d,
440 + copt->class_modf.weight2.max/d);
445 +static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
451 +struct qdisc_util wrr_qdisc_util = {
453 + .parse_qopt = wrr_parse_opt,
454 + .print_qopt = wrr_print_opt,
455 + .print_xstats = wrr_print_xstats,
456 + .parse_copt = wrr_parse_copt,
457 + .print_copt = wrr_print_copt