1 diff -uNrbB v22-org/include/linux/pkt_sched.h v22-new/include/linux/pkt_sched.h
2 --- v22-org/include/linux/pkt_sched.h Tue Apr 28 20:10:10 1998
3 +++ v22-new/include/linux/pkt_sched.h Sun Sep 9 14:34:14 2001
6 #define TCA_CBQ_MAX TCA_CBQ_POLICE
11 +#include <linux/if_ether.h>
13 +// A sub weight and of a class
14 +// All numbers are represented as parts of (2^64-1).
15 +struct tc_wrr_class_weight {
16 + __u64 val; // Current value (0 is not valid)
17 + __u64 decr; // Value pr bytes (2^64-1 is not valid)
18 + __u64 incr; // Value pr seconds (2^64-1 is not valid)
19 + __u64 min; // Minimal value (0 is not valid)
20 + __u64 max; // Minimal value (0 is not valid)
22 + // The time where the above information was correct:
26 +// Pakcet send when modifying a class:
27 +struct tc_wrr_class_modf {
28 + // Not-valid values are ignored.
29 + struct tc_wrr_class_weight weight1;
30 + struct tc_wrr_class_weight weight2;
33 +// Packet returned when quering a class:
34 +struct tc_wrr_class_stats {
35 + char used; // If this is false the information below is invalid
37 + struct tc_wrr_class_modf class_modf;
39 + unsigned char addr[ETH_ALEN];
40 + char usemac; // True if addr is a MAC address, else it is an IP address
41 + // (this value is only for convience, it is always the same
42 + // value as in the qdisc)
43 + int heappos; // Current heap position or 0 if not in heap
44 + __u64 penal_ls; // Penalty value in heap (ls)
45 + __u64 penal_ms; // Penalty value in heap (ms)
48 +// Qdisc-wide penalty information (boolean values - 2 not valid)
49 +struct tc_wrr_qdisc_weight {
50 + char weight_mode; // 0=No automatic change to weight
51 + // 1=Decrease normally
52 + // 2=Also multiply with number of machines
53 + // 3=Instead multiply with priority divided
54 + // with priority of the other.
58 +// Packet send when modifing a qdisc:
59 +struct tc_wrr_qdisc_modf {
60 + // Not-valid values are ignored:
61 + struct tc_wrr_qdisc_weight weight1;
62 + struct tc_wrr_qdisc_weight weight2;
65 +// Packet send when creating a qdisc:
66 +struct tc_wrr_qdisc_crt {
67 + struct tc_wrr_qdisc_modf qdisc_modf;
69 + char srcaddr; // 1=lookup source, 0=lookup destination
70 + char usemac; // 1=Classify on MAC addresses, 0=classify on IP
71 + char usemasq; // 1=Classify based on masqgrading - only valid
72 + // if usemac is zero
73 + int bands_max; // Maximal number of bands (i.e.: classes)
74 + int proxy_maxconn; // If differnt from 0 then we support proxy remapping
75 + // of packets. And this is the number of maximal
76 + // concurrent proxy connections.
79 +// Packet returned when quering a qdisc:
80 +struct tc_wrr_qdisc_stats {
81 + struct tc_wrr_qdisc_crt qdisc_crt;
83 + int nodes_in_heap; // Current number of bands wanting to send something
84 + int bands_cur; // Current number of bands used (i.e.: MAC/IP addresses seen)
85 + int bands_reused; // Number of times this band has been reused.
86 + int packets_requed; // Number of times packets have been requeued.
87 + __u64 priosum; // Sum of priorities in heap where 1 is 2^32
90 +struct tc_wrr_qdisc_modf_std {
91 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
92 + char proxy; // 0=This struct
94 + // Should we also change a class?
97 + // Only valid if change_class is false
98 + struct tc_wrr_qdisc_modf qdisc_modf;
100 + // Only valid if change_class is true:
101 + unsigned char addr[ETH_ALEN]; // Class to change (non-used bytes should be 0)
102 + struct tc_wrr_class_modf class_modf; // The change
105 +// Used for proxyrempping:
106 +struct tc_wrr_qdisc_modf_proxy {
107 + // This indicates which of the tc_wrr_qdisc_modf structers this is:
108 + char proxy; // 1=This struct
110 + // This is 1 if the proxyremap information should be reset
113 + // changec is the number of elements in changes.
116 + // This is an array of type ProxyRemapBlock:
121 diff -uNrbB v22-org/net/sched/Config.in v22-new/net/sched/Config.in
122 --- v22-org/net/sched/Config.in Sun Mar 21 16:22:00 1999
123 +++ v22-new/net/sched/Config.in Thu Dec 20 08:43:08 2001
125 #tristate 'H-PFQ packet scheduler' CONFIG_NET_SCH_HPFQ
126 #tristate 'H-FSC packet scheduler' CONFIG_NET_SCH_HFCS
127 tristate 'The simplest PRIO pseudoscheduler' CONFIG_NET_SCH_PRIO
128 +tristate 'WRR packet scheduler' CONFIG_NET_SCH_WRR
129 tristate 'RED queue' CONFIG_NET_SCH_RED
130 tristate 'SFQ queue' CONFIG_NET_SCH_SFQ
131 tristate 'TEQL queue' CONFIG_NET_SCH_TEQL
132 diff -uNrbB v22-org/net/sched/Makefile v22-new/net/sched/Makefile
133 --- v22-org/net/sched/Makefile Sun Mar 21 16:22:00 1999
134 +++ v22-new/net/sched/Makefile Thu Dec 20 08:42:42 2001
139 +ifeq ($(CONFIG_NET_SCH_WRR), y)
140 + O_OBJS += sch_wrr.o
142 + ifeq ($(CONFIG_NET_SCH_WRR), m)
143 + M_OBJS += sch_wrr.o
147 ifeq ($(CONFIG_NET_SCH_TEQL), y)
150 diff -uNrbB v22-org/net/sched/proxydict.c v22-new/net/sched/proxydict.c
151 --- v22-org/net/sched/proxydict.c Thu Jan 1 01:00:00 1970
152 +++ v22-new/net/sched/proxydict.c Thu Mar 1 20:33:02 2001
156 +#include <netinet/in.h>
159 +#include "proxyremap.h"
160 +#include "proxydict.h"
163 +/*--------------------------------------------------------------------------
168 +#define hash_fnc(m,server,port,proto) \
169 + (((proto)*7+(server)*13+(port)*5)%m->hash_size)
171 +// Size of hash table given maximal number of connections:
172 +#define hash_size_max_con(max_con) (2*(max_con))
174 +// The memory area we maintain:
183 + // int hash_table[hash_size];
184 + // int next[max_con];
185 + // ProxyRemapBlock info[max_con];
187 + // The idea is the following:
188 + // Given a connection we map it by hash_fnc into hash_table. This gives an
189 + // index in next which contains a -1 terminated linked list of connections
190 + // mapping to that hash value.
192 + // The entries in next not allocated is also in linked list where
193 + // the first free index is free_first.
196 +#define Memory(m) ((memory*)m)
197 +#define Hash_table(m) ((int*)(((char*)m)+sizeof(memory)))
198 +#define Next(m) ((int*)(((char*)m)+sizeof(memory)+ \
199 + sizeof(int)*((memory*)m)->hash_size))
200 +#define Info(m) ((ProxyRemapBlock*)(((char*)m)+ \
202 + sizeof(int)*((memory*)m)->hash_size+\
203 + sizeof(int)*((memory*)m)->max_con \
206 +int proxyGetMemSize(int max_con) {
207 + return sizeof(memory)+
208 + sizeof(int)*hash_size_max_con(max_con)+
209 + sizeof(int)*max_con+
210 + sizeof(ProxyRemapBlock)*max_con;
213 +void proxyInitMem(void* data, int max_con) {
215 + memory* m=Memory(data);
216 + m->max_con=max_con;
218 + m->hash_size=hash_size_max_con(max_con);
222 + int* hash_table=Hash_table(data);
223 + int* next=Next(data);
226 + // Init the hash table:
227 + for(i=0; i<m->hash_size; i++) hash_table[i]=-1;
229 + // Init the free-list
230 + for(i=0; i<m->max_con; i++) next[i]=i+1;
235 +int proxyGetCurConn(void* data) {
236 + return Memory(data)->cur_con;
239 +int proxyGetMaxConn(void* data) {
240 + return Memory(data)->max_con;
243 +ProxyRemapBlock* proxyLookup(void* data, unsigned ipaddr, unsigned short port, char proto) {
244 + memory* m=Memory(data);
245 + int* hash_table=Hash_table(m);
247 + ProxyRemapBlock* info=Info(m);
250 + for(i=hash_table[hash_fnc(m,ipaddr,port,proto)]; i!=-1; i=next[i]) {
251 + if(info[i].proto==proto &&
252 + info[i].sport==port &&
253 + info[i].saddr==ipaddr) return &info[i];
259 +int proxyConsumeBlock(void* data, ProxyRemapBlock* blk) {
260 + memory* m=Memory(data);
261 + int* hash_table=Hash_table(m);
263 + ProxyRemapBlock* info=Info(m);
264 + int hash=hash_fnc(m,blk->saddr,blk->sport,blk->proto);
268 + if(m->cur_con == m->max_con) return -1;
270 + // Insert the block at a free entry:
271 + info[m->free_first]=*blk;
274 + foo=next[m->free_first];
276 + // And insert it in the hash tabel:
277 + next[m->free_first]=hash_table[hash];
278 + hash_table[hash]=m->free_first;
284 + for(toupdate=&hash_table[hash];
286 + toupdate=&next[*toupdate]) {
287 + if(info[*toupdate].proto==blk->proto &&
288 + info[*toupdate].sport==blk->sport &&
289 + info[*toupdate].saddr==blk->saddr) break;
291 + if(*toupdate==-1) return -1;
295 + // Delete it from the hashing list:
296 + *toupdate=next[*toupdate];
298 + // And put it on the free list:
299 + next[foo]=m->free_first;
307 diff -uNrbB v22-org/net/sched/proxydict.h v22-new/net/sched/proxydict.h
308 --- v22-org/net/sched/proxydict.h Thu Jan 1 01:00:00 1970
309 +++ v22-new/net/sched/proxydict.h Tue Feb 13 22:47:00 2001
315 +/*--------------------------------------------------------------------------
316 +This is common code for for handling the tabels containing information about
317 +which proxyserver connections are associated with which machines..
320 +// Returns the number of bytes that should be available in the area
321 +// maintained by this module given the maximal number of concurrent
323 +int proxyGetMemSize(int max_connections);
325 +// Initializes a memory area to use. There must be as many bytes
326 +// available as returned by getMemSize.
327 +void proxyInitMem(void* data, int max_connections);
330 +int proxyGetCurConn(void* data); // Returns current number of connections
331 +int proxyMaxCurConn(void* data); // Returns maximal number of connections
333 +// This is called to open and close conenctions. Returns -1 if
334 +// a protocol error occores (i.e.: If it is discovered)
335 +int proxyConsumeBlock(void* data, ProxyRemapBlock*);
337 +// Returns the RemapBlock associated with this connection or 0:
338 +ProxyRemapBlock* proxyLookup(void* data, unsigned ipaddr, unsigned short port, char proto);
343 diff -uNrbB v22-org/net/sched/proxyremap.h v22-new/net/sched/proxyremap.h
344 --- v22-org/net/sched/proxyremap.h Thu Jan 1 01:00:00 1970
345 +++ v22-new/net/sched/proxyremap.h Thu May 17 10:54:11 2001
347 +#ifndef PROXYREMAP_H
348 +#define PROXYREMAP_H
350 +// This describes the information that is written in proxyremap.log and which
351 +// are used in the communication between proxyremapserver and proxyremapclient.
352 +// Everything is in network order.
354 +// First this header is send:
355 +#define PROXY_WELCOME_LINE "ProxyRemap 1.02. This is a binary protocol.\r\n"
357 +// Then this block is send every time a connection is opened or closed.
358 +// Note how it is alligned to use small space usage - arrays of this
359 +// structure are saved in many places.
361 + // Server endpoint of connection:
363 + unsigned short sport;
365 + // IP protocol for this connection (typically udp or tcp):
366 + unsigned char proto;
368 + // Is the connection opened or closed?
369 + unsigned char open;
371 + // Client the packets should be accounted to:
373 + unsigned char macaddr[6]; // Might be 0.
375 + // An informal two-charecter code from the proxyserver. Used for debugging.
380 diff -uNrbB v22-org/net/sched/sch_wrr.c v22-new/net/sched/sch_wrr.c
381 --- v22-org/net/sched/sch_wrr.c Thu Jan 1 01:00:00 1970
382 +++ v22-new/net/sched/sch_wrr.c Mon Apr 1 17:07:51 2002
384 +/*-----------------------------------------------------------------------------
385 +Weighted Round Robin scheduler.
387 +Written by Christian Worm Mortensen, cworm@it-c.dk.
391 +This module implements a weighted round robin queue with build-in classifier.
392 +The classifier currently map each MAC or IP address (configurable either MAC
393 +or IP and either source or destination) to different classes. Each such class
394 +is called a band. Whan using MAC addresses only bridged packets can be
395 +classified other packets go to a default MAC address.
397 +Each band has a weight value, where 0<weight<=1. The bandwidth each band
398 +get is proportional to the weight as can be deduced from the next section.
403 +Each band has a penalty value. Bands having something to sent are kept in
404 +a heap according to this value. The band with the lowest penalty value
405 +is in the root of the heap. The penalty value is a 128 bit number. Initially
406 +no bands are in the heap.
408 +Two global 64 bit values counter_low_penal and couter_high_penal are initialized
409 +to 0 and to 2^63 respectively.
412 + The packet is inserted in the queue for the band it belongs to. If the band
413 + is not in the heap it is inserted into it. In this case, the upper 64 bits
414 + of its penalty value is set to the same as for the root-band of the heap.
415 + If the heap is empty 0 is used. The lower 64 bit is set to couter_low_penal
416 + and couter_low_penal is incremented by 1.
419 + If the heap is empty we have nothing to send.
421 + If the root band has a non-empty queue a packet is dequeued from that.
422 + The upper 64 bit of the penalty value of the band is incremented by the
423 + packet size divided with the weight of the band. The lower 64 bit is set to
424 + couter_high_penal and couter_high_penal is incremented by 1.
426 + If the root element for some reason has an empty queue it is removed from
427 + the heap and we try to dequeue again.
429 +The effect of the heap and the upper 64 bit of the penalty values is to
430 +implement a weighted round robin queue. The effect of counter_low_penal,
431 +counter_high_penal and the lower 64 bit of the penalty value is primarily to
432 +stabilize the queue and to give better quality of service to machines only
433 +sending a packet now and then. For example machines which have a single
434 +interactive connection such as telnet or simple text chatting.
439 +The weight value can be changed dynamically by the queue itself. The weight
440 +value and how it is changed is described by the two members weight1 and
441 +weight2 which has type tc_wrr_class_weight and which are in each class. And
442 +by the two integer value members of the qdisc called penalfact1 and penalfact2.
443 +The structure is defined as:
445 + struct tc_wrr_class_weight {
446 + // All are represented as parts of (2^64-1).
447 + __u64 val; // Current value (0 is not valid)
448 + __u64 decr; // Value pr bytes (2^64-1 is not valid)
449 + __u64 incr; // Value pr seconds (2^64-1 is not valid)
450 + __u64 min; // Minimal value (0 is not valid)
451 + __u64 max; // Minimal value (0 is not valid)
453 + // The time where the above information was correct:
457 +The weight value used by the dequeue operations is calculated as
458 +weight1.val*weight2.val. weight1 and weight2 and handled independently and in the
459 +same way as will be described now.
461 +Every second, the val parameter is incremented by incr.
463 +Every time a packet is transmitted the value is increment by decr times
464 +the packet size. Depending on the value of the weight_mode parameter it
465 +is also mulitplied with other numbers. This makes it possible to give
466 +penalty to machines transferring much data.
468 +-----------------------------------------------------------------------------*/
470 +#include <linux/config.h>
471 +#include <linux/module.h>
472 +#include <asm/uaccess.h>
473 +#include <asm/system.h>
474 +#include <asm/bitops.h>
475 +#include <linux/types.h>
476 +#include <linux/kernel.h>
477 +#include <linux/sched.h>
478 +#include <linux/string.h>
479 +#include <linux/mm.h>
480 +#include <linux/socket.h>
481 +#include <linux/sockios.h>
482 +#include <linux/in.h>
483 +#include <linux/errno.h>
484 +#include <linux/interrupt.h>
485 +#include <linux/if_ether.h>
486 +#include <linux/inet.h>
487 +#include <linux/netdevice.h>
488 +#include <linux/etherdevice.h>
489 +#include <linux/notifier.h>
491 +#include <net/route.h>
492 +#include <linux/skbuff.h>
493 +#include <net/sock.h>
494 +#include <net/pkt_sched.h>
496 +#include <linux/if_arp.h>
497 +#include <linux/version.h>
499 +// Kernel depend stuff:
500 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
505 + #define LOCK_START start_bh_atomic();
506 + #define LOCK_END end_bh_atomic();
507 + #define ENQUEUE_SUCCESS 1
508 + #define ENQUEUE_FAIL 0
509 + #ifdef CONFIG_IP_MASQUERADE
510 + #include <net/ip_masq.h>
511 + #define MASQ_SUPPORT
514 + #define LOCK_START sch_tree_lock(sch);
515 + #define LOCK_END sch_tree_unlock(sch);
516 + #define ENQUEUE_SUCCESS 0
517 + #define ENQUEUE_FAIL NET_XMIT_DROP
518 + #ifdef CONFIG_NETFILTER
519 + #include <linux/netfilter_ipv4/ip_conntrack.h>
520 + #define MASQ_SUPPORT
524 +#include "proxydict.c"
526 +// The penalty (priority) type:
527 +typedef u64 penalty_base_t;
528 +#define penalty_base_t_max ((penalty_base_t)-1)
529 +typedef struct penalty_t {
533 +#define penalty_leq(a,b) (a.ms<b.ms || (a.ms==b.ms && a.ls<=b.ls))
534 +#define penalty_le(a,b) (a.ms<b.ms || (a.ms==b.ms && a.ls<b.ls))
535 +static penalty_t penalty_max={penalty_base_t_max,penalty_base_t_max};
537 +//-----------------------------------------------------------------------------
541 +struct heap_element;
543 +// Initializes an empty heap:
544 +// he: A pointer to an unintialized heap structure identifying the heap
545 +// size: Maximal number of elements the heap can contain
546 +// poll: An array of size "size" used by the heap.
547 +static void heap_init(struct heap* he,int size, struct heap_element* poll);
549 +// Each element in the heap is identified by a user-assigned id which
550 +// should be a non negative integer less than the size argument
551 +// given to heap_init.
552 +static void heap_insert(struct heap*, int id, penalty_t);
553 +static void heap_remove(struct heap*, int id);
554 +static void heap_set_penalty(struct heap*, int id, penalty_t);
556 +// Retreviewing information:
557 +static char heap_empty(struct heap*); // Heap empty?
558 +static char heap_contains(struct heap*, int id); // Does heap contain
560 +static int heap_root(struct heap*); // Returns the id of the root
561 +static penalty_t heap_get_penalty(struct heap*, int id); // Returns penaly
564 +//--------------------
565 +// Heap implementation
567 +struct heap_element {
569 + int id; // The user-assigned id of this element
570 + int id2idx; // Maps from user-assigned ids to indices in root_1
574 + struct heap_element* root_1;
578 +// Heap implementation:
579 +static void heap_init(struct heap* h, int size, struct heap_element* poll) {
585 + for(i=0; i<size; i++) poll[i].id2idx=0;
588 +static char heap_empty(struct heap* h) {
589 + return h->elements==0;
592 +static char heap_contains(struct heap* h, int id) {
593 + return h->root_1[id+1].id2idx!=0;
596 +static int heap_root(struct heap* h) {
597 + return h->root_1[1].id;
600 +static penalty_t heap_get_penalty(struct heap* h, int id) {
601 + return h->root_1[ h->root_1[id+1].id2idx ].penalty;
604 +static void heap_penalty_changed_internal(struct heap* h,int idx);
606 +static void heap_set_penalty(struct heap* h, int id, penalty_t p) {
607 + int idx=h->root_1[id+1].id2idx;
608 + h->root_1[idx].penalty=p;
609 + heap_penalty_changed_internal(h,idx);
612 +static void heap_insert(struct heap* h, int id, penalty_t p) {
613 + // Insert at the end of the heap:
615 + h->root_1[h->elements].id=id;
616 + h->root_1[h->elements].penalty=p;
617 + h->root_1[id+1].id2idx=h->elements;
619 + // And put it in the right position:
620 + heap_penalty_changed_internal(h,h->elements);
623 +static void heap_remove(struct heap* h, int id) {
624 + int idx=h->root_1[id+1].id2idx;
626 + h->root_1[id+1].id2idx=0;
628 + if(h->elements==idx) { h->elements--; return; }
630 + mvid=h->root_1[h->elements].id;
631 + h->root_1[idx].id=mvid;
632 + h->root_1[idx].penalty=h->root_1[h->elements].penalty;
633 + h->root_1[mvid+1].id2idx=idx;
636 + heap_penalty_changed_internal(h,idx);
639 +static void heap_swap(struct heap* h, int idx0, int idx1) {
645 + tmp_p=h->root_1[idx0].penalty;
646 + tmp_id=h->root_1[idx0].id;
647 + h->root_1[idx0].penalty=h->root_1[idx1].penalty;
648 + h->root_1[idx0].id=h->root_1[idx1].id;
649 + h->root_1[idx1].penalty=tmp_p;
650 + h->root_1[idx1].id=tmp_id;
652 + // Update reverse pointers:
653 + id0=h->root_1[idx0].id;
654 + id1=h->root_1[idx1].id;
655 + h->root_1[id0+1].id2idx=idx0;
656 + h->root_1[id1+1].id2idx=idx1;
659 +static void heap_penalty_changed_internal(struct heap* h,int cur) {
660 + if(cur==1 || penalty_leq(h->root_1[cur>>1].penalty,h->root_1[cur].penalty)) {
661 + // We are in heap order upwards - so we should move the element down
665 + penalty_t pen_c=h->root_1[cur].penalty;
666 + penalty_t pen_0=nxt0<=h->elements ? h->root_1[nxt0].penalty : penalty_max;
667 + penalty_t pen_1=nxt1<=h->elements ? h->root_1[nxt1].penalty : penalty_max;
669 + if(penalty_le(pen_0,pen_c) && penalty_leq(pen_0,pen_1)) {
670 + // Swap with child 0:
671 + heap_swap(h,cur,nxt0);
673 + } else if(penalty_le(pen_1,pen_c)) {
674 + // Swap with child 1:
675 + heap_swap(h,cur,nxt1);
678 + // Heap in heap order:
683 + // We are not in heap order upwards (and thus we must be it downwards).
685 + while(cur!=1) { // While not root
687 + if(penalty_leq(h->root_1[nxt].penalty,h->root_1[cur].penalty)) return;
688 + heap_swap(h,cur,nxt);
694 +//-----------------------------------------------------------------------------
695 +// Classification based on MAC or IP adresses. Note that of historical reason
696 +// these are prefixed with mac_ since originally only MAC bases classification
699 +// This code should be in a separate filter module - but it isn't.
705 +// Initialices/destroys the structure we maintain.
706 +// Returns -1 on error
707 +static int mac_init(struct mac_head*, int max_macs, char srcaddr,
708 + char usemac, char usemasq, void* proxyremap);
709 +static void mac_done(struct mac_head*);
710 +static void mac_reset(struct mac_head*);
712 +// Classify a packet. Returns a number n where 0<=n<max_macs. Or -1 if
713 +// the packet should be dropped.
714 +static int mac_classify(struct mac_head*, struct sk_buff *skb);
720 + unsigned char addr[ETH_ALEN]; // Address of this band (last two are 0 on IP)
721 + unsigned long lastused; // Last time a packet was encountered
722 + int class; // Classid of this band (0<=classid<max_macs)
725 +static int mac_compare(const void* a, const void* b) {
726 + return memcmp(a,b,ETH_ALEN);
730 + int mac_max; // Maximal number of MAC addresses/classes allowed
731 + int mac_cur; // Current number of MAC addresses/classes
732 + int mac_reused; // Number of times we have reused a class with a new
735 + char srcaddr; // True if we classify on the source address of packets,
736 + // else we use destination address.
737 + char usemac; // If true we use mac, else we use IP
738 + char usemasq; // If true we try to demasqgrade
739 + struct mac_addr* macs; // Allocated mac_max elements, used max_cur
740 + char* cls2mac; // Mapping from classnumbers to addresses -
741 + // there is 6 bytes in each entry
743 + void* proxyremap; // Information on proxy remapping of data or 0
746 +// This is as the standard C library function with the same name:
747 +static const void* bsearch(const void* key, const void* base, int nmemb,
749 + int (*compare)(const void*, const void*)) {
754 + if(nmemb<=0) return 0;
757 + m_ptr=((const char*)base)+m_idx*size;
759 + i=compare(key,m_ptr);
760 + if(i<0) // key is less
761 + return bsearch(key,base,m_idx,size,compare);
763 + return bsearch(key,((const char*)m_ptr)+size,nmemb-m_idx-1,size,compare);
768 +static int mac_init(struct mac_head* h, int max_macs, char srcaddr,
769 + char usemac, char usemasq,void* proxyremap) {
773 + h->srcaddr=srcaddr;
775 + h->usemasq=usemasq;
776 + h->mac_max=max_macs;
777 + h->proxyremap=proxyremap;
779 + h->macs=(struct mac_addr*)
780 + kmalloc( sizeof(struct mac_addr)*max_macs, GFP_KERNEL);
781 + h->cls2mac=(char*)kmalloc( 6*max_macs, GFP_KERNEL);
782 + if(!h->macs || !h->cls2mac) {
783 + if(h->macs) kfree(h->macs);
784 + if(h->cls2mac) kfree(h->cls2mac);
790 +static void mac_done(struct mac_head* h) {
795 +static void mac_reset(struct mac_head* h) {
801 +static int lookup_mac(struct mac_head* h, unsigned char* addr) {
805 + // First try to find the address in the table:
806 + struct mac_addr* m=(struct mac_addr*)
807 + bsearch(addr,h->macs,h->mac_cur,sizeof(struct mac_addr),mac_compare);
810 + m->lastused=h->incr_time++;
814 + // Okay - the MAC adress was not in table
815 + if(h->mac_cur==h->mac_max) {
816 + // And the table is full - delete the oldest entry:
818 + // Find the oldest entry:
821 + for(i=1; i<h->mac_cur; i++)
822 + if(h->macs[i].lastused < h->macs[lowidx].lastused) lowidx=i;
824 + class=h->macs[lowidx].class;
827 + memmove(&h->macs[lowidx],&h->macs[lowidx+1],
828 + (h->mac_cur-lowidx-1)*sizeof(struct mac_addr));
835 + // The table is now not full - find the position we should put the address in:
836 + for(i=0; i<h->mac_cur; i++) if(mac_compare(addr,&h->macs[i])<0) break;
838 + // We should insert at position i:
839 + memmove(&h->macs[i+1],&h->macs[i],(h->mac_cur-i)*sizeof(struct mac_addr));
841 + memcpy(m->addr,addr,ETH_ALEN);
842 + m->lastused=h->incr_time++;
846 + // Finally update the cls2mac variabel:
847 + memcpy(h->cls2mac+ETH_ALEN*class,addr,ETH_ALEN);
852 +int valid_ip_checksum(struct iphdr* ip, int size) {
853 + __u16 header_len=ip->ihl<<2;
855 + __u16* ipu=(u16*)ip;
858 + // We require 4 bytes in the packet since we access the port numbers:
859 + if((size<header_len) || size<sizeof(struct iphdr)+4) return 0;
861 + for(a=0; a<(header_len>>1); a++, ipu++) {
862 + if(a!=5) { // If not the checksum field
869 + return ip->check==(__u16)~c;
872 +static int mac_classify(struct mac_head* head, struct sk_buff *skb)
874 + // We set this to the address we map to. In case we map to an IP
875 + // address the last two entries are set to 0.
876 + unsigned char addr[ETH_ALEN];
879 + // This is the size of the network part of the packet, I think:
880 + int size=((char*)skb->data+skb->len)-((char*)skb->nh.iph);
882 + // Set a default value for the address:
883 + memset(addr,0,ETH_ALEN);
885 + // Accept IP-ARP traffic with big-enough packets:
886 + if(ntohs(skb->protocol)==ETH_P_ARP &&
887 + ntohs(skb->nh.arph->ar_pro)==ETH_P_IP) {
888 + // Map all ARP trafic to a default adress to make sure
890 + } else if ((ntohs(skb->protocol)==ETH_P_IP) &&
891 + valid_ip_checksum(skb->nh.iph,size)) {
892 + // Accept IP packets which have correct checksum.
894 + // This is the IP header:
895 + struct iphdr* iph=skb->nh.iph;
897 + // And this is the port numbers:
898 + const __u16 *portp = (__u16 *)&(((char *)iph)[iph->ihl*4]);
899 + __u16 sport=portp[0];
900 + __u16 dport=portp[1];
902 + // We will set this to the IP address of the packet that should be
907 + ProxyRemapBlock* prm;
916 + // Update ipaddr if packet is masqgraded:
917 + if(head->usemasq) {
919 + struct ip_masq* src;
922 + // ip_masq_in_get must be called for packets comming from the outside
923 + // to the firewall. We have a a packet which is comming from the
924 + // firewall to the outside - so we switch the parameters:
925 + if((src=ip_masq_in_get(
928 + iph->saddr,sport))) {
929 + // Use masqgraded address:
932 + // It seems like we must put it back:
936 + // Thanks to Rusty Russell for help with the following code:
937 + enum ip_conntrack_info ctinfo;
938 + struct ip_conntrack *ct;
939 + ct = ip_conntrack_get(skb, &ctinfo);
942 + ipaddr=ct->tuplehash[CTINFO2DIR(ctinfo)].tuple.src.ip;
944 + ipaddr=ct->tuplehash[CTINFO2DIR(ctinfo)].tuple.dst.ip;
950 + // Set prm based on ipaddr:
952 + if(head->proxyremap) {
953 + if(head->srcaddr) {
954 + prm=proxyLookup(head->proxyremap,ipaddr,sport,skb->nh.iph->protocol);
956 + prm=proxyLookup(head->proxyremap,ipaddr,dport,skb->nh.iph->protocol);
960 + // And finally set addr to the address:
961 + memset(addr,0,ETH_ALEN);
963 + // This package should be remapped:
965 + memcpy(addr,prm->macaddr,ETH_ALEN);
967 + memcpy(addr,&prm->caddr,sizeof(unsigned));
970 + // This packet should not be remapped:
972 + // We should find MAC address of packet.
973 + // Unfortunatly, this is not always available.
974 + // On bridged packets it always is, however..
976 + if(skb->pkt_bridged) {
977 + if(head->srcaddr) {
978 + memcpy(addr,skb->mac.ethernet->h_source,ETH_ALEN);
980 + memcpy(addr,skb->mac.ethernet->h_dest,ETH_ALEN);
985 + memcpy(addr,&ipaddr,4);
989 + // All other traffic is dropped - this ensures that packets
990 + // we consider probably have valid addresses so we don't
991 + // get to many strange addresses into our table. And that we
992 + // don't use bandwidth on strange packets..
996 + return lookup_mac(head,addr);
999 +//-----------------------------------------------------------------------------
1000 +// The qdisc itself
1002 +// Pr-class information.
1003 +struct wrrc_sched_data {
1004 + struct Qdisc* que; // The queue for this class
1005 + struct tc_wrr_class_modf class_modf; // Information about the class.
1007 + // For classes in the heap this is the priority value priosum
1008 + // was updated with for this class:
1012 +// Pr-qdisc information:
1013 +struct wrr_sched_data
1015 + // A heap containing all the bands that will send something
1017 + struct heap_element* poll; // bandc elements
1019 + // The sum of the prioities of the elements in the heap where
1020 + // a priority of 1 is saved as 2^32
1023 + // A class for each band
1024 + struct wrrc_sched_data* bands; // bandc elements
1026 + // Information maintained by the proxydict module of 0 if we
1027 + // have no proxy remapping
1030 + // Always incrementning counters, we always have that any value of
1031 + // counter_low_penal < any value of counter_high_penal.
1032 + penalty_base_t counter_low_penal;
1033 + penalty_base_t counter_high_penal;
1035 + // Penalty updating:
1036 + struct tc_wrr_qdisc_modf qdisc_modf;
1039 + int packets_requed;
1042 + struct mac_head filter;
1043 + int bandc; // Number of bands
1046 +// Priority handling.
1047 +// weight is in interval [0..2^32]
1048 +// priosum has whole numbers in the upper and fragments in the lower 32 bits.
1049 +static void weight_transmit(struct tc_wrr_class_weight* p,
1050 + struct tc_wrr_qdisc_weight q,
1051 + unsigned heapsize,
1052 + u64 priosum, u64 weight,
1055 + unsigned long now=jiffies/HZ;
1057 + // Penalty for transmitting:
1062 + switch(q.weight_mode) {
1063 + case 1: change=p->decr*size; break;
1064 + case 2: change=p->decr*size*heapsize; break;
1065 + case 3: // Note: 64 bit division is not always available..
1066 + divisor=(u32)(weight>>16);
1067 + if(divisor<=0) divisor=1;
1068 + change=p->decr*size*(((u32)(priosum>>16))/divisor); break;
1072 + if(p->val>old || p->val<p->min) p->val=p->min;
1074 + // Credit for time went:
1075 + change=(now-p->tim)*p->incr;
1079 + if(p->val<old || p->val>p->max) p->val=p->max;
1082 +static void weight_setdefault(struct tc_wrr_class_weight* p) {
1088 + p->tim=jiffies/HZ;
1091 +static void weight_setvalue(struct tc_wrr_class_weight* dst,
1092 + struct tc_wrr_class_weight* src) {
1094 + dst->val=src->val;
1095 + dst->tim=jiffies/HZ;
1097 + if(src->min!=0) dst->min=src->min;
1098 + if(src->max!=0) dst->max=src->max;
1099 + if(src->decr!=((u64)-1)) dst->decr=src->decr;
1100 + if(src->incr!=((u64)-1)) dst->incr=src->incr;
1101 + if(dst->val<dst->min) dst->val=dst->min;
1102 + if(dst->val>dst->max) dst->val=dst->max;
1105 +static void wrr_destroy(struct Qdisc *sch)
1107 + struct wrr_sched_data *q=(struct wrr_sched_data *)sch->data;
1110 + // Destroy our filter:
1111 + mac_done(&q->filter);
1113 + // Destroy all our childre ques:
1114 + for(i=0; i<q->bandc; i++)
1115 + qdisc_destroy(q->bands[i].que);
1117 + // And free memory:
1120 + if(q->proxydict) kfree(q->proxydict);
1122 + MOD_DEC_USE_COUNT;
1125 +static int wrr_init(struct Qdisc *sch, struct rtattr *opt)
1127 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1130 + struct tc_wrr_qdisc_crt *qopt;
1133 + if (!opt) return -EINVAL; // Options must be specified
1134 + if (opt->rta_len < RTA_LENGTH(sizeof(*qopt))) return -EINVAL;
1135 + qopt = RTA_DATA(opt);
1137 + if(qopt->bands_max>2048|| qopt->bands_max<2) {
1138 + // More than 2048 queues or less than 2? That cannot be true - it must be
1143 + if(qopt->proxy_maxconn<0 || qopt->proxy_maxconn>20000) {
1144 + // More than this number of maximal concurrent connections is unrealistic
1148 +#ifndef MASQ_SUPPORT
1149 + if(qopt->usemasq) {
1155 + if(qopt->usemac) { // Not supported - please fix this!
1160 + q->bandc=qopt->bands_max;
1161 + q->qdisc_modf=qopt->qdisc_modf;
1163 + // Create structures:
1164 + q->poll=(struct heap_element*)
1165 + kmalloc( sizeof(struct heap_element)*q->bandc, GFP_KERNEL);
1166 + q->bands=(struct wrrc_sched_data*)
1167 + kmalloc( sizeof(struct wrrc_sched_data)*q->bandc, GFP_KERNEL);
1169 + if(qopt->proxy_maxconn>0) {
1170 + q->proxydict=kmalloc(proxyGetMemSize(qopt->proxy_maxconn),GFP_KERNEL);
1175 + // Init mac module:
1176 + maciniterr=mac_init(&q->filter,qopt->bands_max,qopt->srcaddr,
1177 + qopt->usemac,qopt->usemasq,q->proxydict);
1179 + // See if we got the memory we wanted:
1180 + if(!q->poll || !q->bands ||
1181 + (qopt->proxy_maxconn>0 && !q->proxydict) || maciniterr<0) {
1182 + if(q->poll) kfree(q->poll);
1183 + if(q->bands) kfree(q->bands);
1184 + if(q->proxydict) kfree(q->proxydict);
1185 + if(maciniterr>=0) mac_done(&q->filter);
1189 + // Initialize proxy:
1190 + if(q->proxydict) {
1191 + proxyInitMem(q->proxydict,qopt->proxy_maxconn);
1194 + // Initialize values:
1195 + q->counter_low_penal=0;
1196 + q->counter_high_penal=penalty_base_t_max>>1;
1197 + q->packets_requed=0;
1199 + // Initialize empty heap:
1200 + heap_init(&q->h,q->bandc,q->poll);
1203 + // Initialize each band:
1205 + for (i=0; i<q->bandc; i++) {
1206 + weight_setdefault(&q->bands[i].class_modf.weight1);
1207 + weight_setdefault(&q->bands[i].class_modf.weight2);
1209 + struct Qdisc *child=qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops);
1211 + q->bands[i].que = child;
1213 + // Queue couldn't be created :-(
1217 + if(crterr) q->bands[i].que = &noop_qdisc;
1220 + MOD_INC_USE_COUNT;
1231 +static void wrr_reset(struct Qdisc* sch)
1233 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1236 + // Reset own values:
1237 + q->counter_low_penal=0;
1238 + q->counter_high_penal=penalty_base_t_max>>1;
1239 + q->packets_requed=0;
1242 + mac_reset(&q->filter);
1244 + // Reinitialize heap:
1245 + heap_init(&q->h,q->bandc,q->poll);
1248 + // Reset all bands:
1249 + for (i=0; i<q->bandc; i++) {
1250 + weight_setdefault(&q->bands[i].class_modf.weight1);
1251 + weight_setdefault(&q->bands[i].class_modf.weight2);
1252 + qdisc_reset(q->bands[i].que);
1255 + // Reset proxy remapping information:
1257 + proxyInitMem(q->proxydict,proxyGetMaxConn(q->proxydict));
1260 +static int wrr_enqueue(struct sk_buff *skb, struct Qdisc* sch)
1262 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1263 + int retvalue=ENQUEUE_FAIL;
1265 + // The packet is in skb.
1266 + int band=mac_classify(&q->filter,skb);
1269 + // Enque packet for this band:
1270 + struct Qdisc* qdisc = q->bands[band].que;
1272 + if ((retvalue=qdisc->enqueue(skb, qdisc)) == ENQUEUE_SUCCESS) {
1274 + sch->stats.bytes += skb->len;
1275 + sch->stats.packets++;
1278 + // Insert band into heap if not already there:
1279 + if(!heap_contains(&q->h,band)) {
1281 + if(!heap_empty(&q->h))
1282 + p.ms=heap_get_penalty(&q->h,heap_root(&q->h)).ms;
1285 + p.ls=q->counter_low_penal++;
1286 + heap_insert(&q->h,band,p);
1287 + q->bands[band].priosum_val=
1288 + ((q->bands[band].class_modf.weight1.val>>48)+1)*
1289 + ((q->bands[band].class_modf.weight2.val>>48)+1);
1290 + q->priosum+=q->bands[band].priosum_val;
1294 + // If we decide not to enque it seems like we also need to free the packet:
1298 + if(retvalue!=ENQUEUE_SUCCESS) {
1299 + // Packet not enqued:
1300 + sch->stats.drops++;
1306 +static struct sk_buff *wrr_dequeue(struct Qdisc* sch)
1308 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1309 + struct sk_buff* skb;
1311 + u64 weight,priosum;
1312 + struct wrrc_sched_data* b;
1314 + // Return if heap is empty:
1315 + if(heap_empty(&q->h)) return 0;
1317 + // Find root element:
1318 + band=heap_root(&q->h);
1320 + // Find priority of this element in interval [1;2^32]
1321 + b=&q->bands[band];
1322 + weight=((b->class_modf.weight1.val>>48)+1)*
1323 + ((b->class_modf.weight2.val>>48)+1); //weight is in interval [1;2^32]
1324 + priosum=q->priosum;
1325 + q->priosum-=q->bands[band].priosum_val;
1327 + // Deque the packet from the root:
1328 + skb=q->bands[band].que->dequeue(q->bands[band].que);
1331 + // There was a packet in this que.
1335 + // Find length of packet adjusted with priority:
1336 + adjlen=(u32)(weight>>(32-16));
1337 + if(adjlen==0) adjlen=1;
1338 + adjlen=(skb->len<<16)/adjlen;
1340 + // Update penalty information for this class:
1341 + weight_transmit(&b->class_modf.weight1,q->qdisc_modf.weight1,q->h.elements,priosum,weight,skb->len);
1342 + weight_transmit(&b->class_modf.weight2,q->qdisc_modf.weight2,q->h.elements,priosum,weight,skb->len);
1343 + q->bands[band].priosum_val=((b->class_modf.weight1.val>>48)+1)*
1344 + ((b->class_modf.weight2.val>>48)+1);
1345 + q->priosum+=q->bands[band].priosum_val;
1347 + // And update the class in the heap
1348 + p=heap_get_penalty(&q->h,band);
1350 + p.ls=q->counter_high_penal++;
1351 + heap_set_penalty(&q->h,band,p);
1358 + // No packet - so machine should be removed from heap:
1359 + heap_remove(&q->h,band);
1362 + return wrr_dequeue(sch);
1365 +static int wrr_requeue(struct sk_buff *skb, struct Qdisc* sch)
1367 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1368 + struct Qdisc* qdisc;
1371 + // Find band we took it from:
1372 + int band=mac_classify(&q->filter,skb);
1374 + // Who should now free the pakcet?
1375 + printk(KERN_DEBUG "sch_wrr: Oops - packet requed could never have been queued.\n");
1376 + sch->stats.drops++;
1377 + return ENQUEUE_FAIL;
1380 + q->packets_requed++;
1382 + // Try to requeue it on that machine:
1383 + qdisc=q->bands[band].que;
1385 + if((ret=qdisc->ops->requeue(skb,qdisc))==ENQUEUE_SUCCESS) {
1389 + // We should restore priority information - but we don't
1391 + // p=heap_get_penalty(&q->h,band);
1393 + // heap_set_penalty(&q->h,band,p);
1395 + return ENQUEUE_SUCCESS;
1397 + sch->stats.drops++;
1402 +static int wrr_drop(struct Qdisc* sch)
1404 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1406 + // Ugly... Drop button up in heap:
1409 + for(i=q->h.elements; i>=1; i--) {
1410 + int band=q->h.root_1[i].id;
1411 + if(q->bands[band].que->ops->drop(q->bands[band].que)) {
1421 +#ifdef CONFIG_RTNETLINK
1422 +static int wrr_dump(struct Qdisc *sch, struct sk_buff *skb)
1424 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1425 + unsigned char *b = skb->tail;
1426 + struct tc_wrr_qdisc_stats opt;
1428 + opt.qdisc_crt.qdisc_modf=q->qdisc_modf;
1429 + opt.qdisc_crt.srcaddr=q->filter.srcaddr;
1430 + opt.qdisc_crt.usemac=q->filter.usemac;
1431 + opt.qdisc_crt.usemasq=q->filter.usemasq;
1432 + opt.qdisc_crt.bands_max=q->filter.mac_max;
1433 + opt.nodes_in_heap=q->h.elements;
1434 + opt.bands_cur=q->filter.mac_cur;
1435 + opt.bands_reused=q->filter.mac_reused;
1436 + opt.packets_requed=q->packets_requed;
1437 + opt.priosum=q->priosum;
1439 + if(q->proxydict) {
1440 + opt.qdisc_crt.proxy_maxconn=proxyGetMaxConn(q->proxydict);
1441 + opt.proxy_curconn=proxyGetCurConn(q->proxydict);
1443 + opt.qdisc_crt.proxy_maxconn=0;
1444 + opt.proxy_curconn=0;
1447 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
1450 +rtattr_failure: // seems like RTA_PUT jump to this label..
1451 + skb_trim(skb, b - skb->data);
1456 +static int wrr_tune_std(struct Qdisc *sch, struct rtattr *opt)
1458 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1459 + struct tc_wrr_qdisc_modf_std *qopt = RTA_DATA(opt);
1461 + if(opt->rta_len < RTA_LENGTH(sizeof(*qopt))) return -EINVAL;
1465 + if(qopt->change_class) {
1466 + int idx=lookup_mac(&q->filter,qopt->addr);
1468 + (&q->bands[idx].class_modf.weight1,&qopt->class_modf.weight1);
1470 + (&q->bands[idx].class_modf.weight2,&qopt->class_modf.weight2);
1472 + if(qopt->qdisc_modf.weight1.weight_mode!=-1)
1473 + q->qdisc_modf.weight1.weight_mode=qopt->qdisc_modf.weight1.weight_mode;
1474 + if(qopt->qdisc_modf.weight2.weight_mode!=-1)
1475 + q->qdisc_modf.weight2.weight_mode=qopt->qdisc_modf.weight2.weight_mode;
1483 +static int wrr_tune_proxy(struct Qdisc *sch, struct rtattr *opt)
1485 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1486 + struct tc_wrr_qdisc_modf_proxy *qopt = RTA_DATA(opt);
1489 + // Return if we are not configured with proxy support:
1490 + if(!q->proxydict) return -ENOSYS;
1492 + // Return if not enough data given:
1493 + if(opt->rta_len<RTA_LENGTH(sizeof(*qopt)) ||
1495 + RTA_LENGTH(sizeof(*qopt)+sizeof(ProxyRemapBlock)*qopt->changec))
1501 + proxyInitMem(q->proxydict,proxyGetMaxConn(q->proxydict));
1504 + // Do all the changes:
1505 + for(i=0; i<qopt->changec; i++) {
1506 + proxyConsumeBlock(q->proxydict,&((ProxyRemapBlock*)&qopt->changes)[i]);
1514 +static int wrr_tune(struct Qdisc *sch, struct rtattr *opt) {
1515 + if(((struct tc_wrr_qdisc_modf_std*)RTA_DATA(opt))->proxy) {
1516 + return wrr_tune_proxy(sch,opt);
1518 + return wrr_tune_std(sch,opt);
1522 +//-----------------------------------------------------------------------------
1524 +// External and internal IDs are equal. They are the band number plus 1.
1526 +// Replace a class with another:
1527 +static int wrr_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1528 + struct Qdisc **old)
1530 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1531 + if(arg>q->bandc || arg==0) return -EINVAL;
1535 + new = &noop_qdisc;
1538 + *old = xchg(&q->bands[arg].que, new);
1541 + *old = q->bands[arg].que;
1542 + q->bands[arg].que = new;
1543 + qdisc_reset(*old);
1550 +// Returns the qdisc for a class:
1551 +static struct Qdisc * wrr_leaf(struct Qdisc *sch, unsigned long arg)
1553 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1554 + if(arg>q->bandc || arg==0) return NULL;
1556 + return q->bands[arg].que;
1559 +static unsigned long wrr_get(struct Qdisc *sch, u32 classid)
1561 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1562 + unsigned long band = TC_H_MIN(classid);
1563 + if(band>q->bandc || band==0) return 0;
1567 +static void wrr_put(struct Qdisc *q, unsigned long cl)
1572 +static int wrr_delete(struct Qdisc *sch, unsigned long cl)
1574 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1575 + if(cl==0 || cl>q->bandc) return -ENOENT;
1581 +#ifdef CONFIG_RTNETLINK
1582 +static int wrr_dump_class(struct Qdisc *sch, unsigned long cl,
1583 + struct sk_buff *skb, struct tcmsg *tcm)
1585 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1586 + unsigned char *b = skb->tail;
1587 + struct tc_wrr_class_stats opt;
1589 + // Handle of this class:
1590 + tcm->tcm_handle = sch->handle|cl;
1592 + if(cl==0 || cl>q->bandc)
1593 + goto rtattr_failure;
1596 + if(cl>=q->filter.mac_cur) {
1597 + // Band is unused:
1598 + memset(&opt,0,sizeof(opt));
1602 + opt.class_modf.weight1=q->bands[cl].class_modf.weight1;
1603 + opt.class_modf.weight2=q->bands[cl].class_modf.weight2;
1604 + weight_transmit(&opt.class_modf.weight1,q->qdisc_modf.weight1,0,0,0,0);
1605 + weight_transmit(&opt.class_modf.weight2,q->qdisc_modf.weight2,0,0,0,0);
1606 + memcpy(opt.addr,q->filter.cls2mac+cl*ETH_ALEN,ETH_ALEN);
1607 + opt.usemac=q->filter.usemac;
1608 + opt.heappos=q->h.root_1[cl+1].id2idx;
1609 + if(opt.heappos!=0) { // Is in heap
1610 + opt.penal_ls=heap_get_penalty(&q->h,cl).ls;
1611 + opt.penal_ms=heap_get_penalty(&q->h,cl).ms;
1618 + // Put quing information:
1619 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
1623 + skb_trim(skb, b - skb->data);
1628 +static int wrr_change(struct Qdisc *sch, u32 handle, u32 parent,
1629 + struct rtattr **tca, unsigned long *arg)
1631 + unsigned long cl = *arg;
1632 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1633 + struct rtattr *opt = tca[TCA_OPTIONS-1];
1634 + struct tc_wrr_class_modf *copt = RTA_DATA(opt);
1636 + if(cl==0 || cl>q->bandc) return -EINVAL;
1639 + if (opt->rta_len < RTA_LENGTH(sizeof(*copt))) return -EINVAL;
1643 + weight_setvalue(&q->bands[cl].class_modf.weight1,&copt->weight1);
1644 + weight_setvalue(&q->bands[cl].class_modf.weight2,&copt->weight2);
1651 +static void wrr_walk(struct Qdisc *sch, struct qdisc_walker *arg)
1653 + struct wrr_sched_data *q = (struct wrr_sched_data *)sch->data;
1656 + if (arg->stop) return;
1658 + for (prio = 1; prio <= q->bandc; prio++) {
1659 + if (arg->count < arg->skip) {
1663 + if (arg->fn(sch, prio, arg) < 0) {
1671 +static struct tcf_proto ** wrr_find_tcf(struct Qdisc *sch, unsigned long cl)
1676 +static unsigned long wrr_bind(struct Qdisc *sch,
1677 + unsigned long parent, u32 classid)
1679 + return wrr_get(sch, classid);
1682 +//-----------------------------------------------------------------------------
1685 +static struct Qdisc_class_ops wrr_class_ops =
1700 +#ifdef CONFIG_RTNETLINK
1705 +struct Qdisc_ops wrr_qdisc_ops =
1710 + sizeof(struct wrr_sched_data),
1722 +#ifdef CONFIG_RTNETLINK
1729 +int init_module(void)
1731 + return register_qdisc(&wrr_qdisc_ops);
1734 +void cleanup_module(void)
1736 + unregister_qdisc(&wrr_qdisc_ops);