]>
Commit | Line | Data |
---|---|---|
14f0972a JR |
1 | diff -urN linux-2.4.18-clean/Documentation/Configure.help linux-2.4.18-imq/Documentation/Configure.help |
2 | --- linux-2.4.18-clean/Documentation/Configure.help Mon Feb 25 20:37:51 2002 | |
3 | +++ linux-2.4.18-imq/Documentation/Configure.help Thu May 23 14:15:12 2002 | |
4 | @@ -8356,6 +8356,20 @@ | |
5 | say M here and read <file:Documentation/modules.txt>. The module | |
6 | will be called bonding.o. | |
7 | ||
8 | +Intermediate queueing device support | |
9 | +CONFIG_IMQ | |
10 | + The imq device(s) is used as placeholder for QoS queueing disciplines. | |
11 | + Every packet entering/leaving the ip stack can be directed through | |
12 | + the imq device where it's enqueued/dequeued to the attached qdisc. | |
13 | + This allows you to treat network devices as classes and distribute | |
14 | + bandwidth among them. Iptables is used to specify through which imq | |
15 | + device, if any, packets travel. | |
16 | + | |
17 | + If you want to compile this as a module ( = code which ca be | |
18 | + inserted in and removed from the running kernel whenever you want), | |
19 | + say M here and read <file:Documentation/modules.txt>. The module | |
20 | + will be called imq.o | |
21 | + | |
22 | SLIP (serial line) support | |
23 | CONFIG_SLIP | |
24 | Say Y if you intend to use SLIP or CSLIP (compressed SLIP) to | |
25 | diff -urN linux-2.4.18-clean/drivers/net/Config.in linux-2.4.18-imq/drivers/net/Config.in | |
26 | --- linux-2.4.18-clean/drivers/net/Config.in Mon Feb 25 20:37:59 2002 | |
27 | +++ linux-2.4.18-imq/drivers/net/Config.in Thu May 23 14:15:12 2002 | |
28 | @@ -8,6 +8,11 @@ | |
29 | tristate 'Dummy net driver support' CONFIG_DUMMY | |
30 | tristate 'Bonding driver support' CONFIG_BONDING | |
31 | tristate 'EQL (serial line load balancing) support' CONFIG_EQUALIZER | |
32 | +if [ "$CONFIG_NETFILTER" = "y" ]; then | |
33 | + tristate 'IMQ (intermediate queueing device) support' CONFIG_IMQ | |
34 | +else | |
35 | + comment 'IMQ needs CONFIG_NETFILTER enabled' | |
36 | +fi | |
37 | tristate 'Universal TUN/TAP device driver support' CONFIG_TUN | |
38 | if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then | |
39 | tristate 'Ethertap network tap (OBSOLETE)' CONFIG_ETHERTAP | |
40 | diff -urN linux-2.4.18-clean/drivers/net/Makefile linux-2.4.18-imq/drivers/net/Makefile | |
41 | --- linux-2.4.18-clean/drivers/net/Makefile Mon Feb 25 20:37:59 2002 | |
42 | +++ linux-2.4.18-imq/drivers/net/Makefile Thu May 23 14:15:12 2002 | |
43 | @@ -145,6 +145,7 @@ | |
a3854b07 | 44 | |
14f0972a JR |
45 | obj-$(CONFIG_STRIP) += strip.o |
46 | obj-$(CONFIG_DUMMY) += dummy.o | |
14f0972a JR |
47 | +obj-$(CONFIG_IMQ) += imq.o |
48 | obj-$(CONFIG_DE600) += de600.o | |
49 | obj-$(CONFIG_DE620) += de620.o | |
50 | obj-$(CONFIG_AT1500) += lance.o | |
51 | diff -urN linux-2.4.18-clean/drivers/net/imq.c linux-2.4.18-imq/drivers/net/imq.c | |
52 | --- linux-2.4.18-clean/drivers/net/imq.c Thu Jan 1 01:00:00 1970 | |
53 | +++ linux-2.4.18-imq/drivers/net/imq.c Thu May 23 14:07:49 2002 | |
54 | @@ -0,0 +1,324 @@ | |
55 | +/* | |
56 | + * Pseudo-driver for the intermediate queue device. | |
57 | + * | |
58 | + * Authors: Patrick McHardy, <kaber@trash.net> | |
59 | + * | |
60 | + * The first version was written by Martin Devera, <devik@cdi.cz> | |
61 | + * | |
62 | + * This program is free software; you can redistribute it and/or | |
63 | + * modify it under the terms of the GNU General Public License | |
64 | + * as published by the Free Software Foundation; either version | |
65 | + * 2 of the License, or (at your option) any later version. | |
66 | + */ | |
67 | + | |
68 | +#include <linux/kernel.h> | |
69 | +#include <linux/module.h> | |
70 | +#include <linux/config.h> | |
71 | +#include <linux/skbuff.h> | |
72 | +#include <linux/netdevice.h> | |
73 | +#include <linux/rtnetlink.h> | |
74 | +#include <linux/if_arp.h> | |
75 | +#include <linux/netfilter.h> | |
76 | +#include <linux/netfilter_ipv4.h> | |
77 | +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | |
78 | +#include <linux/netfilter_ipv6.h> | |
79 | +#endif | |
80 | +#include <linux/imq.h> | |
81 | +#include <net/pkt_sched.h> | |
82 | + | |
83 | +#define IMQ_HH_LEN(info) (((info)->hook == NF_IP_PRE_ROUTING) ? \ | |
84 | + (info)->indev->hard_header_len : \ | |
85 | + (info)->outdev->hard_header_len) | |
86 | + | |
87 | +static nf_hookfn imq_nf_hook; | |
88 | + | |
89 | +static struct nf_hook_ops imq_ingress_ipv4 = { | |
90 | + { NULL, NULL}, | |
91 | + imq_nf_hook, | |
92 | + PF_INET, | |
93 | + NF_IP_PRE_ROUTING, | |
94 | + NF_IP_PRI_MANGLE + 1 | |
95 | +}; | |
96 | + | |
97 | +static struct nf_hook_ops imq_egress_ipv4 = { | |
98 | + { NULL, NULL}, | |
99 | + imq_nf_hook, | |
100 | + PF_INET, | |
101 | + NF_IP_POST_ROUTING, | |
102 | + NF_IP_PRI_LAST | |
103 | +}; | |
104 | + | |
105 | +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | |
106 | +static struct nf_hook_ops imq_ingress_ipv6 = { | |
107 | + { NULL, NULL}, | |
108 | + imq_nf_hook, | |
109 | + PF_INET6, | |
110 | + NF_IP6_PRE_ROUTING, | |
111 | + NF_IP6_PRI_MANGLE + 1 | |
112 | +}; | |
113 | + | |
114 | +static struct nf_hook_ops imq_egress_ipv6 = { | |
115 | + { NULL, NULL}, | |
116 | + imq_nf_hook, | |
117 | + PF_INET6, | |
118 | + NF_IP6_POST_ROUTING, | |
119 | + NF_IP6_PRI_LAST | |
120 | +}; | |
121 | +#endif | |
122 | + | |
123 | +static unsigned int numdevs = 2; | |
124 | + | |
125 | +MODULE_PARM(numdevs, "i"); | |
126 | +MODULE_PARM_DESC(numdevs, "number of imq devices"); | |
127 | + | |
128 | +static struct net_device *imq_devs; | |
129 | + | |
130 | + | |
131 | +static struct net_device_stats *imq_get_stats(struct net_device *dev) | |
132 | +{ | |
133 | + return (struct net_device_stats *)dev->priv; | |
134 | +} | |
135 | + | |
136 | +/* called for packets kfree'd in qdiscs at places other than enqueue */ | |
137 | +static void imq_skb_destructor(struct sk_buff *skb) | |
138 | +{ | |
139 | + struct nf_info *info = skb->nf_info; | |
140 | + | |
141 | + if (info) { | |
142 | + if (info->indev) | |
143 | + dev_put(info->indev); | |
144 | + if (info->outdev) | |
145 | + dev_put(info->outdev); | |
146 | + kfree(info); | |
147 | + } | |
148 | +} | |
149 | + | |
150 | +static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev) | |
151 | +{ | |
152 | + struct net_device_stats *stats = (struct net_device_stats*) dev->priv; | |
153 | + | |
154 | + stats->tx_bytes += skb->len; | |
155 | + stats->tx_packets++; | |
156 | + | |
157 | + skb_pull(skb, IMQ_HH_LEN(skb->nf_info)); | |
158 | + | |
159 | + skb->imq_flags = 0; | |
160 | + skb->destructor = NULL; | |
161 | + | |
162 | + dev->trans_start = jiffies; | |
163 | + nf_reinject(skb, skb->nf_info, NF_ACCEPT); | |
164 | + | |
165 | + return 0; | |
166 | +} | |
167 | + | |
168 | +static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info, | |
169 | + void *data) | |
170 | +{ | |
171 | + struct net_device *dev; | |
172 | + struct net_device_stats *stats; | |
173 | + struct sk_buff *skb2 = NULL; | |
174 | + struct Qdisc *q; | |
175 | + unsigned int index = skb->imq_flags&IMQ_F_IFMASK; | |
176 | + int ret = -1; | |
177 | + | |
178 | + if (index > numdevs) | |
179 | + return -1; | |
180 | + | |
181 | + dev = imq_devs + index; | |
182 | + if (!(dev->flags & IFF_UP)) { | |
183 | + skb->imq_flags = 0; | |
184 | + nf_reinject(skb, info, NF_ACCEPT); | |
185 | + return 0; | |
186 | + } | |
187 | + dev->last_rx = jiffies; | |
188 | + | |
189 | + if (skb->destructor) { | |
190 | + skb2 = skb; | |
191 | + skb = skb_clone(skb, GFP_ATOMIC); | |
192 | + if (!skb) | |
193 | + return -1; | |
194 | + } | |
195 | + skb_push(skb, IMQ_HH_LEN(info)); | |
196 | + skb->nf_info = info; | |
197 | + | |
198 | + stats = (struct net_device_stats *)dev->priv; | |
199 | + stats->rx_bytes+= skb->len; | |
200 | + stats->rx_packets++; | |
201 | + | |
202 | + spin_lock_bh(&dev->queue_lock); | |
203 | + | |
204 | + q = dev->qdisc; | |
205 | + if (q->enqueue) { | |
206 | + q->enqueue(skb_get(skb), q); | |
207 | + | |
208 | + if (skb_shared(skb)) { | |
209 | + skb->destructor = imq_skb_destructor; | |
210 | + kfree_skb(skb); | |
211 | + ret = 0; | |
212 | + } | |
213 | + } | |
214 | + | |
215 | + qdisc_run(dev); | |
216 | + spin_unlock_bh(&dev->queue_lock); | |
217 | + | |
218 | + if (skb2) | |
219 | + kfree_skb(ret ? skb : skb2); | |
220 | + | |
221 | + return ret; | |
222 | +} | |
223 | + | |
224 | +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff **pskb, | |
225 | + const struct net_device *indev, | |
226 | + const struct net_device *outdev, | |
227 | + int (*okfn)(struct sk_buff *)) | |
228 | +{ | |
229 | + if ((*pskb)->imq_flags & IMQ_F_ENQUEUE) | |
230 | + return NF_QUEUE; | |
231 | + | |
232 | + return NF_ACCEPT; | |
233 | +} | |
234 | + | |
235 | + | |
236 | +static int __init imq_init_hooks(void) | |
237 | +{ | |
238 | + int err; | |
239 | + | |
240 | + if ((err = nf_register_queue_handler(PF_INET, imq_nf_queue, NULL))) | |
241 | + goto err1; | |
242 | + if ((err = nf_register_hook(&imq_ingress_ipv4))) | |
243 | + goto err2; | |
244 | + if ((err = nf_register_hook(&imq_egress_ipv4))) | |
245 | + goto err3; | |
246 | +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | |
247 | + if ((err = nf_register_queue_handler(PF_INET6, imq_nf_queue, NULL))) | |
248 | + goto err4; | |
249 | + if ((err = nf_register_hook(&imq_ingress_ipv6))) | |
250 | + goto err5; | |
251 | + if ((err = nf_register_hook(&imq_egress_ipv6))) | |
252 | + goto err6; | |
253 | +#endif | |
254 | + | |
255 | + return 0; | |
256 | + | |
257 | +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | |
258 | +err6: | |
259 | + nf_unregister_hook(&imq_ingress_ipv6); | |
260 | +err5: | |
261 | + nf_unregister_queue_handler(PF_INET6); | |
262 | +err4: | |
263 | + nf_unregister_hook(&imq_egress_ipv4); | |
264 | +#endif | |
265 | +err3: | |
266 | + nf_unregister_hook(&imq_ingress_ipv4); | |
267 | +err2: | |
268 | + nf_unregister_queue_handler(PF_INET); | |
269 | +err1: | |
270 | + return err; | |
271 | +} | |
272 | + | |
273 | +static void __exit imq_unhook(void) | |
274 | +{ | |
275 | + nf_unregister_hook(&imq_ingress_ipv4); | |
276 | + nf_unregister_hook(&imq_egress_ipv4); | |
277 | + nf_unregister_queue_handler(PF_INET); | |
278 | +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | |
279 | + nf_unregister_hook(&imq_ingress_ipv6); | |
280 | + nf_unregister_hook(&imq_egress_ipv6); | |
281 | + nf_unregister_queue_handler(PF_INET6); | |
282 | +#endif | |
283 | +} | |
284 | + | |
285 | +static int __init imq_dev_init(struct net_device *dev) | |
286 | +{ | |
287 | + dev->hard_start_xmit = imq_dev_xmit; | |
288 | + dev->type = ARPHRD_VOID; | |
289 | + dev->mtu = 1500; | |
290 | + dev->tx_queue_len = 30; | |
291 | + dev->flags = IFF_NOARP; | |
292 | + dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL); | |
293 | + if (dev->priv == NULL) | |
294 | + return -ENOMEM; | |
295 | + memset(dev->priv, 0, sizeof(struct net_device_stats)); | |
296 | + dev->get_stats = imq_get_stats; | |
297 | + | |
298 | + return 0; | |
299 | +} | |
300 | + | |
301 | +static void imq_dev_uninit(struct net_device *dev) | |
302 | +{ | |
303 | + kfree(dev->priv); | |
304 | +} | |
305 | + | |
306 | +static int __init imq_init_devs(void) | |
307 | +{ | |
308 | + struct net_device *dev; | |
309 | + int i; | |
310 | + | |
311 | + if (!numdevs || numdevs > IMQ_MAX_DEVS) { | |
312 | + printk(KERN_ERR "numdevs has to be betweed 1 and %u\n", | |
313 | + IMQ_MAX_DEVS); | |
314 | + return -EINVAL; | |
315 | + } | |
316 | + | |
317 | + imq_devs = kmalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL); | |
318 | + if (!imq_devs) | |
319 | + return -ENOMEM; | |
320 | + memset(imq_devs, 0, sizeof(struct net_device) * numdevs); | |
321 | + | |
322 | + /* we start counting at zero */ | |
323 | + numdevs--; | |
324 | + | |
325 | + for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) { | |
326 | + SET_MODULE_OWNER(dev); | |
327 | + strcpy(dev->name, "imq%d"); | |
328 | + dev->init = imq_dev_init; | |
329 | + dev->uninit = imq_dev_uninit; | |
330 | + | |
331 | + if (register_netdev(dev) < 0) | |
332 | + goto err_register; | |
333 | + } | |
334 | + return 0; | |
335 | + | |
336 | +err_register: | |
337 | + for (; i; i--) | |
338 | + unregister_netdev(--dev); | |
339 | + kfree(imq_devs); | |
340 | + return -EIO; | |
341 | +} | |
342 | + | |
343 | +static void imq_cleanup_devs(void) | |
344 | +{ | |
345 | + int i; | |
346 | + struct net_device *dev = imq_devs; | |
347 | + | |
348 | + for (i = 0; i <= numdevs; i++) | |
349 | + unregister_netdev(dev++); | |
350 | + | |
351 | + kfree(imq_devs); | |
352 | +} | |
353 | + | |
354 | +static int __init imq_init_module(void) | |
355 | +{ | |
356 | + int err; | |
357 | + | |
358 | + if ((err = imq_init_devs())) | |
359 | + return err; | |
360 | + if ((err = imq_init_hooks())) { | |
361 | + imq_cleanup_devs(); | |
362 | + return err; | |
363 | + } | |
364 | + | |
365 | + printk(KERN_INFO "imq driver loaded.\n"); | |
366 | + | |
367 | + return 0; | |
368 | +} | |
369 | + | |
370 | +static void __exit imq_cleanup_module(void) | |
371 | +{ | |
372 | + imq_unhook(); | |
373 | + imq_cleanup_devs(); | |
374 | +} | |
375 | + | |
376 | +module_init(imq_init_module); | |
377 | +module_exit(imq_cleanup_module); | |
378 | +MODULE_LICENSE("GPL"); | |
379 | diff -urN linux-2.4.18-clean/include/linux/imq.h linux-2.4.18-imq/include/linux/imq.h | |
380 | --- linux-2.4.18-clean/include/linux/imq.h Thu Jan 1 01:00:00 1970 | |
381 | +++ linux-2.4.18-imq/include/linux/imq.h Thu May 23 14:15:12 2002 | |
382 | @@ -0,0 +1,9 @@ | |
383 | +#ifndef _IMQ_H | |
384 | +#define _IMQ_H | |
385 | + | |
386 | +#define IMQ_MAX_DEVS 16 | |
387 | + | |
388 | +#define IMQ_F_IFMASK 0x7f | |
389 | +#define IMQ_F_ENQUEUE 0x80 | |
390 | + | |
391 | +#endif /* _IMQ_H */ | |
392 | diff -urN linux-2.4.18-clean/include/linux/skbuff.h linux-2.4.18-imq/include/linux/skbuff.h | |
393 | --- linux-2.4.18-clean/include/linux/skbuff.h Thu Nov 22 20:46:26 2001 | |
394 | +++ linux-2.4.18-imq/include/linux/skbuff.h Thu May 23 14:15:12 2002 | |
395 | @@ -93,6 +93,9 @@ | |
396 | struct nf_conntrack *master; | |
397 | }; | |
398 | #endif | |
399 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
400 | +struct nf_info; | |
401 | +#endif | |
402 | ||
403 | struct sk_buff_head { | |
404 | /* These two members must be first. */ | |
405 | @@ -178,7 +181,7 @@ | |
406 | unsigned int len; /* Length of actual data */ | |
407 | unsigned int data_len; | |
408 | unsigned int csum; /* Checksum */ | |
409 | - unsigned char __unused, /* Dead field, may be reused */ | |
410 | + unsigned char imq_flags, /* intermediate queueing device */ | |
411 | cloned, /* head may be cloned (check refcnt to be sure). */ | |
412 | pkt_type, /* Packet class */ | |
413 | ip_summed; /* Driver fed us an IP checksum */ | |
414 | @@ -214,6 +217,9 @@ | |
415 | ||
416 | #ifdef CONFIG_NET_SCHED | |
417 | __u32 tc_index; /* traffic control index */ | |
418 | +#endif | |
419 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
420 | + struct nf_info *nf_info; | |
421 | #endif | |
422 | }; | |
423 | ||
424 | diff -urN linux-2.4.18-clean/net/core/skbuff.c linux-2.4.18-imq/net/core/skbuff.c | |
425 | --- linux-2.4.18-clean/net/core/skbuff.c Fri Dec 21 18:42:05 2001 | |
426 | +++ linux-2.4.18-imq/net/core/skbuff.c Thu May 23 14:15:12 2002 | |
427 | @@ -202,6 +202,10 @@ | |
428 | /* Set up other state */ | |
429 | skb->len = 0; | |
430 | skb->cloned = 0; | |
431 | +#if defined(CONFIG_IMQ) || defined (CONFIG_IMQ_MODULE) | |
432 | + skb->imq_flags = 0; | |
433 | + skb->nf_info = NULL; | |
434 | +#endif | |
435 | skb->data_len = 0; | |
436 | ||
437 | atomic_set(&skb->users, 1); | |
438 | @@ -249,6 +253,10 @@ | |
439 | #ifdef CONFIG_NET_SCHED | |
440 | skb->tc_index = 0; | |
441 | #endif | |
442 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
443 | + skb->imq_flags = 0; | |
444 | + skb->nf_info = NULL; | |
445 | +#endif | |
446 | } | |
447 | ||
448 | static void skb_drop_fraglist(struct sk_buff *skb) | |
449 | @@ -398,6 +406,10 @@ | |
450 | #ifdef CONFIG_NET_SCHED | |
451 | C(tc_index); | |
452 | #endif | |
453 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
454 | + C(imq_flags); | |
455 | + C(nf_info); | |
456 | +#endif | |
457 | ||
458 | atomic_inc(&(skb_shinfo(skb)->dataref)); | |
459 | skb->cloned = 1; | |
460 | @@ -440,6 +452,10 @@ | |
461 | #endif | |
462 | #ifdef CONFIG_NET_SCHED | |
463 | new->tc_index = old->tc_index; | |
464 | +#endif | |
465 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
466 | + new->imq_flags=old->imq_flags; | |
467 | + new->nf_info=old->nf_info; | |
468 | #endif | |
469 | } | |
470 | ||
471 | diff -urN linux-2.4.18-clean/net/sched/sch_generic.c linux-2.4.18-imq/net/sched/sch_generic.c | |
472 | --- linux-2.4.18-clean/net/sched/sch_generic.c Fri Aug 18 19:26:25 2000 | |
473 | +++ linux-2.4.18-imq/net/sched/sch_generic.c Thu May 23 14:15:12 2002 | |
474 | @@ -29,6 +29,9 @@ | |
475 | #include <linux/skbuff.h> | |
476 | #include <linux/rtnetlink.h> | |
477 | #include <linux/init.h> | |
478 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
479 | +#include <linux/imq.h> | |
480 | +#endif | |
481 | #include <net/sock.h> | |
482 | #include <net/pkt_sched.h> | |
483 | ||
484 | @@ -89,7 +92,11 @@ | |
485 | spin_unlock(&dev->queue_lock); | |
486 | ||
487 | if (!netif_queue_stopped(dev)) { | |
488 | - if (netdev_nit) | |
489 | + if (netdev_nit | |
490 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
491 | + && !(skb->imq_flags & IMQ_F_ENQUEUE) | |
492 | +#endif | |
493 | + ) | |
494 | dev_queue_xmit_nit(skb, dev); | |
495 | ||
496 | if (dev->hard_start_xmit(skb, dev) == 0) { |