Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 72961 | Differences between
and this patch

Collapse All | Expand All

(-)iproute2-2.6.9.orig/include/linux/pkt_sched.h (+112 lines)
Lines 375-380 Link Here
375
375
376
#define TCA_CBQ_MAX	TCA_CBQ_POLICE
376
#define TCA_CBQ_MAX	TCA_CBQ_POLICE
377
377
378
/* WRR section */
379
380
/* Other includes */
381
#include <linux/if_ether.h>
382
383
// A sub weight and of a class
384
// All numbers are represented as parts of (2^64-1).
385
struct tc_wrr_class_weight {
386
  __u64 val;  // Current value                        (0 is not valid)
387
  __u64 decr; // Value pr bytes                       (2^64-1 is not valid)
388
  __u64 incr; // Value pr seconds                     (2^64-1 is not valid)
389
  __u64 min;  // Minimal value                        (0 is not valid)
390
  __u64 max;  // Minimal value                        (0 is not valid)
391
392
  // The time where the above information was correct:
393
  time_t tim;
394
};
395
396
// Pakcet send when modifying a class:
397
struct tc_wrr_class_modf {
398
  // Not-valid values are ignored.
399
  struct tc_wrr_class_weight weight1;
400
  struct tc_wrr_class_weight weight2;
401
};
402
403
// Packet returned when quering a class:
404
struct tc_wrr_class_stats {
405
  char used; // If this is false the information below is invalid
406
407
  struct tc_wrr_class_modf class_modf;
408
409
  unsigned char addr[ETH_ALEN];
410
  char usemac;    // True if addr is a MAC address, else it is an IP address
411
                  // (this value is only for convience, it is always the same
412
                //  value as in the qdisc)
413
  int heappos;    // Current heap position or 0 if not in heap
414
  __u64 penal_ls; // Penalty value in heap (ls)
415
  __u64 penal_ms; // Penalty value in heap (ms)
416
};
417
418
// Qdisc-wide penalty information (boolean values - 2 not valid)
419
struct tc_wrr_qdisc_weight {
420
  char weight_mode; // 0=No automatic change to weight
421
                    // 1=Decrease normally
422
                  // 2=Also multiply with number of machines
423
                  // 3=Instead multiply with priority divided
424
                  //   with priority of the other.
425
                  // -1=no change
426
};
427
428
// Packet send when modifing a qdisc:
429
struct tc_wrr_qdisc_modf {
430
  // Not-valid values are ignored:
431
  struct tc_wrr_qdisc_weight weight1;
432
  struct tc_wrr_qdisc_weight weight2;
433
};
434
435
// Packet send when creating a qdisc:
436
struct tc_wrr_qdisc_crt {
437
  struct tc_wrr_qdisc_modf qdisc_modf;
438
439
  char srcaddr;      // 1=lookup source, 0=lookup destination
440
  char usemac;       // 1=Classify on MAC addresses, 0=classify on IP
441
  char usemasq;      // 1=Classify based on masqgrading - only valid
442
                     //   if usemac is zero
443
  int bands_max;     // Maximal number of bands (i.e.: classes)
444
  int proxy_maxconn; // If differnt from 0 then we support proxy remapping
445
                     // of packets. And this is the number of maximal
446
                   // concurrent proxy connections.
447
};
448
449
// Packet returned when quering a qdisc:
450
struct tc_wrr_qdisc_stats {
451
  struct tc_wrr_qdisc_crt qdisc_crt;
452
  int proxy_curconn;
453
  int nodes_in_heap;  // Current number of bands wanting to send something
454
  int bands_cur;      // Current number of bands used (i.e.: MAC/IP addresses seen)
455
  int bands_reused;   // Number of times this band has been reused.
456
  int packets_requed; // Number of times packets have been requeued.
457
  __u64 priosum;      // Sum of priorities in heap where 1 is 2^32
458
};
459
460
struct tc_wrr_qdisc_modf_std {
461
  // This indicates which of the tc_wrr_qdisc_modf structers this is:
462
  char proxy; // 0=This struct
463
464
  // Should we also change a class?
465
  char change_class;
466
467
  // Only valid if change_class is false
468
  struct tc_wrr_qdisc_modf qdisc_modf;
469
470
  // Only valid if change_class is true:
471
  unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
472
  struct tc_wrr_class_modf class_modf; // The change
473
};
474
475
// Used for proxyrempping:
476
struct tc_wrr_qdisc_modf_proxy {
477
  // This indicates which of the tc_wrr_qdisc_modf structers this is:
478
  char proxy; // 1=This struct
479
480
  // This is 1 if the proxyremap information should be reset
481
  char reset;
482
483
  // changec is the number of elements in changes.
484
  int changec;
485
486
  // This is an array of type ProxyRemapBlock:
487
  long changes[0];
488
};
489
378
/* dsmark section */
490
/* dsmark section */
379
491
380
enum {
492
enum {
(-)iproute2-2.6.9.orig/tc/Makefile (+1 lines)
Lines 10-15 Link Here
10
TCMODULES += q_prio.o
10
TCMODULES += q_prio.o
11
TCMODULES += q_tbf.o
11
TCMODULES += q_tbf.o
12
TCMODULES += q_cbq.o
12
TCMODULES += q_cbq.o
13
TCMODULES += q_wrr.o
13
TCMODULES += f_rsvp.o
14
TCMODULES += f_rsvp.o
14
TCMODULES += f_u32.o
15
TCMODULES += f_u32.o
15
TCMODULES += f_route.o
16
TCMODULES += f_route.o
(-)iproute2-2.6.9.orig/tc/q_wrr.c (+322 lines)
Line 0 Link Here
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <unistd.h>
4
#include <syslog.h>
5
#include <fcntl.h>
6
#include <sys/socket.h>
7
#include <netinet/in.h>
8
#include <arpa/inet.h>
9
#include <string.h>
10
#include <math.h>
11
12
#include "utils.h"
13
#include "tc_util.h"
14
15
#define usage() return(-1)
16
17
// Returns -1 on error
18
static int wrr_parse_qdisc_weight(int argc, char** argv, 
19
                              struct tc_wrr_qdisc_modf* opt) {
20
  int i;
21
  
22
  opt->weight1.weight_mode=-1;
23
  opt->weight2.weight_mode=-1;
24
  
25
  for(i=0; i<argc; i++) {  
26
    if(!memcmp(argv[i],"wmode1=",7)) {
27
      opt->weight1.weight_mode=atoi(argv[i]+7);            
28
    } else if(!memcmp(argv[i],"wmode2=",7)) {
29
      opt->weight2.weight_mode=atoi(argv[i]+7);
30
    } else {
31
      printf("Usage: ... [wmode1=0|1|2|3] [wmode2=0|1|2|3]\n");
32
      return -1;
33
    }
34
  }
35
  return 0;
36
}
37
38
static int wrr_parse_class_modf(int argc, char** argv, 
39
                                struct tc_wrr_class_modf* modf) {
40
  int i;
41
  
42
  if(argc<1) {
43
    fprintf(stderr, "Usage: ... [weight1=val] [decr1=val] [incr1=val] [min1=val] [max1=val] [val2=val] ...\n");
44
    fprintf(stderr, "  The values can be floating point like 0.42 or divisions like 42/100\n");
45
    return -1;
46
  }
47
  
48
  // Set meaningless values:
49
  modf->weight1.val=0;
50
  modf->weight1.decr=(__u64)-1;
51
  modf->weight1.incr=(__u64)-1;
52
  modf->weight1.min=0;
53
  modf->weight1.max=0;
54
  modf->weight2.val=0;
55
  modf->weight2.decr=(__u64)-1;
56
  modf->weight2.incr=(__u64)-1;
57
  modf->weight2.min=0;
58
  modf->weight2.max=0;
59
  
60
  // And read values:
61
  for(i=0; i<argc; i++) {
62
    char arg[80];
63
    char* name,*value1=0,*value2=0;
64
    long double f_val1,f_val2=1,value;
65
    if(strlen(argv[i])>=sizeof(arg)) {
66
      fprintf(stderr,"Argument too long: %s\n",argv[i]);
67
      return -1;
68
    }
69
    strcpy(arg,argv[i]);
70
    
71
    name=strtok(arg,"=");
72
    if(name) value1=strtok(0,"/");
73
    if(value1) value2=strtok(0,"");
74
    
75
    if(!value1) {
76
      fprintf(stderr,"No = found in argument: %s\n",argv[i]);
77
      return -1;
78
    }
79
    
80
    f_val1=atof(value1);
81
    if(value2) f_val2=atof(value2);    
82
    
83
    if(f_val2==0)  {
84
      fprintf(stderr,"Division by 0\n");
85
      return -1;
86
    }
87
        
88
    value=f_val1/f_val2;    
89
    if(value>1) value=1;
90
    if(value<0) value=0;            
91
    value*=((__u64)-1);
92
    
93
    // And find the value set
94
    if(!strcmp(name,"weight1"))    modf->weight1.val=value;
95
    else if(!strcmp(name,"decr1")) modf->weight1.decr=value;
96
    else if(!strcmp(name,"incr1")) modf->weight1.incr=value;
97
    else if(!strcmp(name,"min1"))  modf->weight1.min=value;
98
    else if(!strcmp(name,"max1"))  modf->weight1.max=value;
99
    else if(!strcmp(name,"weight2")) modf->weight2.val=value;
100
    else if(!strcmp(name,"decr2")) modf->weight2.decr=value;
101
    else if(!strcmp(name,"incr2")) modf->weight2.incr=value;
102
    else if(!strcmp(name,"min2"))  modf->weight2.min=value;
103
    else if(!strcmp(name,"max2"))  modf->weight2.max=value;
104
    else {
105
      fprintf(stderr,"illegal value: %s\n",name);
106
      return -1;
107
    }
108
  }    
109
110
  return 0;
111
}
112
113
static int wrr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
114
{
115
  if(n->nlmsg_flags & NLM_F_CREATE) {
116
    // This is a create request:
117
    struct tc_wrr_qdisc_crt opt;
118
	
119
    int sour,dest,ip,mac,masq;
120
121
    if(argc<4) {
122
      fprintf(stderr, "Usage: ... wrr sour|dest ip|masq|mac maxclasses proxymaxcon [penalty-setup]\n");
123
      return -1;
124
    }	  
125
  
126
    // Read sour/dest:
127
    memset(&opt,0,sizeof(opt));
128
    sour=!strcmp(argv[0],"sour");
129
    dest=!strcmp(argv[0],"dest");	
130
	
131
    if(!sour && !dest) {
132
      fprintf(stderr,"sour or dest must be specified\n");
133
      return -1;
134
    }	
135
136
    // Read ip/mac
137
    ip=!strcmp(argv[1],"ip");
138
    mac=!strcmp(argv[1],"mac");	
139
    masq=!strcmp(argv[1],"masq");	
140
141
    if(!ip && !mac && !masq) {
142
      fprintf(stderr,"ip, masq or mac must be specified\n");
143
      return -1;
144
    }	
145
146
    opt.srcaddr=sour;		
147
    opt.usemac=mac;
148
    opt.usemasq=masq;		
149
    opt.bands_max=atoi(argv[2]);
150
    
151
    opt.proxy_maxconn=atoi(argv[3]);
152
    
153
    // Read weights:
154
    if(wrr_parse_qdisc_weight(argc-4,argv+4,&opt.qdisc_modf)<0) return -1;
155
    if(opt.qdisc_modf.weight1.weight_mode==-1) opt.qdisc_modf.weight1.weight_mode=0;
156
    if(opt.qdisc_modf.weight2.weight_mode==-1) opt.qdisc_modf.weight2.weight_mode=0;
157
		
158
    addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
159
  } else {
160
    struct tc_wrr_qdisc_modf_std opt;
161
    char qdisc,class;
162
    
163
    // This is a modify request:
164
    if(argc<1) {
165
      fprintf(stderr,"... qdisc ... or ... class ...\n");
166
      return -1;
167
    }
168
            
169
    qdisc=!strcmp(argv[0],"qdisc");
170
    class=!strcmp(argv[0],"class");
171
172
    if(!qdisc && !class) {
173
      fprintf(stderr,"qdisc or class must be specified\n");
174
      return -1;
175
    }
176
      
177
    argc--;
178
    argv++;
179
      
180
    opt.proxy=0;
181
    
182
    if(qdisc) {
183
      opt.change_class=0;
184
      if(wrr_parse_qdisc_weight(argc, argv, &opt.qdisc_modf)<0) return -1;
185
    } else {
186
      int a0,a1,a2,a3,a4=0,a5=0;      
187
188
      opt.change_class=1;
189
      
190
      if(argc<1) {
191
        fprintf(stderr,"... <mac>|<ip>|<masq> ...\n");
192
        return -1;
193
      }
194
      memset(opt.addr,0,sizeof(opt.addr));
195
196
      if((sscanf(argv[0],"%i.%i.%i.%i",&a0,&a1,&a2,&a3)!=4) &&
197
         (sscanf(argv[0],"%x:%x:%x:%x:%x:%x",&a0,&a1,&a2,&a3,&a4,&a5)!=6)) {
198
	fprintf(stderr,"Wrong format of mac or ip address\n");
199
	return -1;
200
      }
201
      
202
      opt.addr[0]=a0; opt.addr[1]=a1; opt.addr[2]=a2;
203
      opt.addr[3]=a3; opt.addr[4]=a4; opt.addr[5]=a5;
204
205
      if(wrr_parse_class_modf(argc-1, argv+1, &opt.class_modf)<0) return -1;
206
    }  
207
  
208
    addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
209
  }
210
  return 0;
211
}
212
213
static int wrr_parse_copt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) {
214
  struct tc_wrr_class_modf opt;
215
  
216
  memset(&opt,0,sizeof(opt));
217
  if(wrr_parse_class_modf(argc,argv,&opt)<0) return -1;
218
  
219
  addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
220
  return 0;  
221
}  
222
223
static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
224
{
225
	struct tc_wrr_qdisc_stats *qopt;
226
227
	if (opt == NULL)
228
		return 0;
229
230
	if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
231
		return -1;
232
	qopt = RTA_DATA(opt);
233
	
234
	fprintf(f,"\n  (%s/%s) (maxclasses %i) (usedclasses %i) (reused classes %i)\n",
235
	  qopt->qdisc_crt.srcaddr ? "sour" : "dest",
236
	  qopt->qdisc_crt.usemac  ? "mac"  : (qopt->qdisc_crt.usemasq ? "masq" : "ip"),	  
237
	  qopt->qdisc_crt.bands_max,	  	  	  
238
	  qopt->bands_cur,
239
	  qopt->bands_reused
240
	  );
241
	  
242
	if(qopt->qdisc_crt.proxy_maxconn) {
243
	  fprintf(f,"  (proxy maxcon %i) (proxy curcon %i)\n",
244
	    qopt->qdisc_crt.proxy_maxconn,qopt->proxy_curconn);
245
	}
246
	
247
	fprintf(f,"  (waiting classes %i) (packets requeued %i) (priosum: %Lg)\n",
248
	  qopt->nodes_in_heap,
249
	  qopt->packets_requed,
250
	  qopt->priosum/((long double)((__u32)-1))
251
	  );
252
253
	fprintf(f,"  (wmode1 %i) (wmode2 %i) \n",
254
	  qopt->qdisc_crt.qdisc_modf.weight1.weight_mode,
255
	  qopt->qdisc_crt.qdisc_modf.weight2.weight_mode);
256
	  
257
	return 0;
258
}
259
260
static int wrr_print_copt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) {
261
  struct tc_wrr_class_stats *copt;
262
  long double d=(__u64)-1;
263
264
  if (opt == NULL) return 0;
265
266
  if (RTA_PAYLOAD(opt)  < sizeof(*copt))
267
    return -1;
268
  copt = RTA_DATA(opt);
269
270
  if(!copt->used) {
271
    fprintf(f,"(unused)");
272
    return 0;
273
  }
274
  
275
  if(copt->usemac) {
276
    fprintf(f,"\n  (address: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X)\n",
277
      copt->addr[0],copt->addr[1],copt->addr[2],
278
      copt->addr[3],copt->addr[4],copt->addr[5]);
279
  } else {     
280
    fprintf(f,"\n  (address: %i.%i.%i.%i)\n",copt->addr[0],copt->addr[1],copt->addr[2],copt->addr[3]);
281
  }    
282
  
283
  fprintf(f,"  (total weight: %Lg) (current position: %i) (counters: %u %u : %u %u)\n",
284
    (copt->class_modf.weight1.val/d)*(copt->class_modf.weight2.val/d),
285
    copt->heappos,
286
    (unsigned)(copt->penal_ms>>32),
287
    (unsigned)(copt->penal_ms & 0xffffffffU),
288
    (unsigned)(copt->penal_ls>>32),
289
    (unsigned)(copt->penal_ls & 0xffffffffU)
290
    );
291
    
292
  fprintf(f,"  Pars 1: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)\n",
293
    copt->class_modf.weight1.val/d,
294
    copt->class_modf.weight1.decr/d,
295
    copt->class_modf.weight1.incr/d,
296
    copt->class_modf.weight1.min/d,
297
    copt->class_modf.weight1.max/d);
298
299
  fprintf(f,"  Pars 2: (weight %Lg) (decr: %Lg) (incr: %Lg) (min: %Lg) (max: %Lg)",
300
    copt->class_modf.weight2.val/d,
301
    copt->class_modf.weight2.decr/d,
302
    copt->class_modf.weight2.incr/d,
303
    copt->class_modf.weight2.min/d,
304
    copt->class_modf.weight2.max/d);
305
  
306
  return 0;
307
}
308
309
static int wrr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
310
{
311
	return 0;
312
}
313
314
315
struct qdisc_util wrr_util = {
316
	.id = "wrr",
317
	.parse_qopt = wrr_parse_opt,
318
	.print_qopt = wrr_print_opt,
319
	.print_xstats = wrr_print_xstats,
320
	.parse_copt = wrr_parse_copt,
321
	.print_copt = wrr_print_copt
322
};

Return to bug 72961