[8.09] kernel: refresh patches
[openwrt/svn-archive/archive.git] / target / linux / generic-2.6 / patches-2.6.24 / 150-netfilter_imq.patch
1 --- /dev/null
2 +++ b/drivers/net/imq.c
3 @@ -0,0 +1,409 @@
4 +/*
5 + * Pseudo-driver for the intermediate queue device.
6 + *
7 + * This program is free software; you can redistribute it and/or
8 + * modify it under the terms of the GNU General Public License
9 + * as published by the Free Software Foundation; either version
10 + * 2 of the License, or (at your option) any later version.
11 + *
12 + * Authors: Patrick McHardy, <kaber@trash.net>
13 + *
14 + * The first version was written by Martin Devera, <devik@cdi.cz>
15 + *
16 + * Credits: Jan Rafaj <imq2t@cedric.vabo.cz>
17 + * - Update patch to 2.4.21
18 + * Sebastian Strollo <sstrollo@nortelnetworks.com>
19 + * - Fix "Dead-loop on netdevice imq"-issue
20 + * Marcel Sebek <sebek64@post.cz>
21 + * - Update to 2.6.2-rc1
22 + *
23 + * After some time of inactivity there is a group taking care
24 + * of IMQ again: http://www.linuximq.net
25 + *
26 + *
27 + * 2004/06/30 - New version of IMQ patch to kernels <=2.6.7 including
28 + * the following changes:
29 + *
30 + * - Correction of ipv6 support "+"s issue (Hasso Tepper)
31 + * - Correction of imq_init_devs() issue that resulted in
32 + * kernel OOPS unloading IMQ as module (Norbert Buchmuller)
33 + * - Addition of functionality to choose number of IMQ devices
34 + * during kernel config (Andre Correa)
35 + * - Addition of functionality to choose how IMQ hooks on
36 + * PRE and POSTROUTING (after or before NAT) (Andre Correa)
37 + * - Cosmetic corrections (Norbert Buchmuller) (Andre Correa)
38 + *
39 + *
40 + * 2005/12/16 - IMQ versions between 2.6.7 and 2.6.13 were
41 + * released with almost no problems. 2.6.14-x was released
42 + * with some important changes: nfcache was removed; After
43 + * some weeks of trouble we figured out that some IMQ fields
44 + * in skb were missing in skbuff.c - skb_clone and copy_skb_header.
45 + * These functions are correctly patched by this new patch version.
46 + *
47 + * Thanks for all who helped to figure out all the problems with
48 + * 2.6.14.x: Patrick McHardy, Rune Kock, VeNoMouS, Max CtRiX,
49 + * Kevin Shanahan, Richard Lucassen, Valery Dachev (hopefully
50 + * I didn't forget anybody). I apologize again for my lack of time.
51 + *
52 + * More info at: http://www.linuximq.net/ (Andre Correa)
53 + */
54 +
55 +#include <linux/module.h>
56 +#include <linux/kernel.h>
57 +#include <linux/moduleparam.h>
58 +#include <linux/skbuff.h>
59 +#include <linux/netdevice.h>
60 +#include <linux/rtnetlink.h>
61 +#include <linux/if_arp.h>
62 +#include <linux/netfilter.h>
63 +#include <linux/netfilter_ipv4.h>
64 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
65 + #include <linux/netfilter_ipv6.h>
66 +#endif
67 +#include <linux/imq.h>
68 +#include <net/pkt_sched.h>
69 +
70 +extern int qdisc_restart1(struct net_device *dev);
71 +
72 +static nf_hookfn imq_nf_hook;
73 +
74 +static struct nf_hook_ops imq_ingress_ipv4 = {
75 + .hook = imq_nf_hook,
76 + .owner = THIS_MODULE,
77 + .pf = PF_INET,
78 + .hooknum = NF_IP_PRE_ROUTING,
79 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
80 + .priority = NF_IP_PRI_MANGLE + 1
81 +#else
82 + .priority = NF_IP_PRI_NAT_DST + 1
83 +#endif
84 +};
85 +
86 +static struct nf_hook_ops imq_egress_ipv4 = {
87 + .hook = imq_nf_hook,
88 + .owner = THIS_MODULE,
89 + .pf = PF_INET,
90 + .hooknum = NF_IP_POST_ROUTING,
91 +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
92 + .priority = NF_IP_PRI_LAST
93 +#else
94 + .priority = NF_IP_PRI_NAT_SRC - 1
95 +#endif
96 +};
97 +
98 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
99 +static struct nf_hook_ops imq_ingress_ipv6 = {
100 + .hook = imq_nf_hook,
101 + .owner = THIS_MODULE,
102 + .pf = PF_INET6,
103 + .hooknum = NF_IP6_PRE_ROUTING,
104 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
105 + .priority = NF_IP6_PRI_MANGLE + 1
106 +#else
107 + .priority = NF_IP6_PRI_NAT_DST + 1
108 +#endif
109 +};
110 +
111 +static struct nf_hook_ops imq_egress_ipv6 = {
112 + .hook = imq_nf_hook,
113 + .owner = THIS_MODULE,
114 + .pf = PF_INET6,
115 + .hooknum = NF_IP6_POST_ROUTING,
116 +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
117 + .priority = NF_IP6_PRI_LAST
118 +#else
119 + .priority = NF_IP6_PRI_NAT_SRC - 1
120 +#endif
121 +};
122 +#endif
123 +
124 +#if defined(CONFIG_IMQ_NUM_DEVS)
125 +static unsigned int numdevs = CONFIG_IMQ_NUM_DEVS;
126 +#else
127 +static unsigned int numdevs = 16;
128 +#endif
129 +
130 +static struct net_device *imq_devs;
131 +
132 +static struct net_device_stats *imq_get_stats(struct net_device *dev)
133 +{
134 + return (struct net_device_stats *)dev->priv;
135 +}
136 +
137 +/* called for packets kfree'd in qdiscs at places other than enqueue */
138 +static void imq_skb_destructor(struct sk_buff *skb)
139 +{
140 + struct nf_info *info = skb->nf_info;
141 +
142 + if (info) {
143 + if (info->indev)
144 + dev_put(info->indev);
145 + if (info->outdev)
146 + dev_put(info->outdev);
147 + kfree(info);
148 + }
149 +}
150 +
151 +static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
152 +{
153 + struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
154 +
155 + stats->tx_bytes += skb->len;
156 + stats->tx_packets++;
157 +
158 + skb->imq_flags = 0;
159 + skb->destructor = NULL;
160 +
161 + dev->trans_start = jiffies;
162 + nf_reinject(skb, skb->nf_info, NF_ACCEPT);
163 + return 0;
164 +}
165 +
166 +static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info, unsigned queue_num, void *data)
167 +{
168 + struct net_device *dev;
169 + struct net_device_stats *stats;
170 + struct sk_buff *skb2 = NULL;
171 + struct Qdisc *q;
172 + unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
173 + int ret = -1;
174 +
175 + if (index > numdevs)
176 + return -1;
177 +
178 + dev = imq_devs + index;
179 + if (!(dev->flags & IFF_UP)) {
180 + skb->imq_flags = 0;
181 + nf_reinject(skb, info, NF_ACCEPT);
182 + return 0;
183 + }
184 + dev->last_rx = jiffies;
185 +
186 + if (skb->destructor) {
187 + skb2 = skb;
188 + skb = skb_clone(skb, GFP_ATOMIC);
189 + if (!skb)
190 + return -1;
191 + }
192 + skb->nf_info = info;
193 +
194 + stats = (struct net_device_stats *)dev->priv;
195 + stats->rx_bytes+= skb->len;
196 + stats->rx_packets++;
197 +
198 + spin_lock_bh(&dev->queue_lock);
199 + q = dev->qdisc;
200 + if (q->enqueue) {
201 + q->enqueue(skb_get(skb), q);
202 + if (skb_shared(skb)) {
203 + skb->destructor = imq_skb_destructor;
204 + kfree_skb(skb);
205 + ret = 0;
206 + }
207 + }
208 + if (spin_is_locked(&dev->_xmit_lock))
209 + netif_schedule(dev);
210 + else
211 + while (!netif_queue_stopped(dev) && qdisc_restart1(dev) < 0)
212 + /* NOTHING */;
213 +
214 + spin_unlock_bh(&dev->queue_lock);
215 +
216 + if (skb2)
217 + kfree_skb(ret ? skb : skb2);
218 +
219 + return ret;
220 +}
221 +
222 +static struct nf_queue_handler nfqh = {
223 + .name = "imq",
224 + .outfn = imq_nf_queue,
225 +};
226 +
227 +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff *pskb,
228 + const struct net_device *indev,
229 + const struct net_device *outdev,
230 + int (*okfn)(struct sk_buff *))
231 +{
232 + if (pskb->imq_flags & IMQ_F_ENQUEUE)
233 + return NF_QUEUE;
234 +
235 + return NF_ACCEPT;
236 +}
237 +
238 +
239 +static int __init imq_init_hooks(void)
240 +{
241 + int err;
242 +
243 + err = nf_register_queue_handler(PF_INET, &nfqh);
244 + if (err > 0)
245 + goto err1;
246 + if ((err = nf_register_hook(&imq_ingress_ipv4)))
247 + goto err2;
248 + if ((err = nf_register_hook(&imq_egress_ipv4)))
249 + goto err3;
250 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
251 + if ((err = nf_register_queue_handler(PF_INET6, &nfqh)))
252 + goto err4;
253 + if ((err = nf_register_hook(&imq_ingress_ipv6)))
254 + goto err5;
255 + if ((err = nf_register_hook(&imq_egress_ipv6)))
256 + goto err6;
257 +#endif
258 +
259 + return 0;
260 +
261 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
262 +err6:
263 + nf_unregister_hook(&imq_ingress_ipv6);
264 +err5:
265 + nf_unregister_queue_handler(PF_INET6, &nfqh);
266 +err4:
267 + nf_unregister_hook(&imq_egress_ipv4);
268 +#endif
269 +err3:
270 + nf_unregister_hook(&imq_ingress_ipv4);
271 +err2:
272 + nf_unregister_queue_handler(PF_INET, &nfqh);
273 +err1:
274 + return err;
275 +}
276 +
277 +static void __exit imq_unhook(void)
278 +{
279 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
280 + nf_unregister_hook(&imq_ingress_ipv6);
281 + nf_unregister_hook(&imq_egress_ipv6);
282 + nf_unregister_queue_handler(PF_INET6, &nfqh);
283 +#endif
284 + nf_unregister_hook(&imq_ingress_ipv4);
285 + nf_unregister_hook(&imq_egress_ipv4);
286 + nf_unregister_queue_handler(PF_INET, &nfqh);
287 +}
288 +
289 +static int __init imq_dev_init(struct net_device *dev)
290 +{
291 + dev->hard_start_xmit = imq_dev_xmit;
292 + dev->type = ARPHRD_VOID;
293 + dev->mtu = 16000;
294 + dev->tx_queue_len = 11000;
295 + dev->flags = IFF_NOARP;
296 + dev->priv = kzalloc(sizeof(struct net_device_stats), GFP_KERNEL);
297 + if (dev->priv == NULL)
298 + return -ENOMEM;
299 + dev->get_stats = imq_get_stats;
300 +
301 + return 0;
302 +}
303 +
304 +static void imq_dev_uninit(struct net_device *dev)
305 +{
306 + kfree(dev->priv);
307 +}
308 +
309 +static int __init imq_init_devs(struct net *net)
310 +{
311 + struct net_device *dev;
312 + int i,j;
313 + j = numdevs;
314 +
315 + if (!numdevs || numdevs > IMQ_MAX_DEVS) {
316 + printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n",
317 + IMQ_MAX_DEVS);
318 + return -EINVAL;
319 + }
320 +
321 + imq_devs = kzalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
322 + if (!imq_devs)
323 + return -ENOMEM;
324 +
325 + /* we start counting at zero */
326 + numdevs--;
327 +
328 + for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
329 + strcpy(dev->name, "imq%d");
330 + dev->init = imq_dev_init;
331 + dev->uninit = imq_dev_uninit;
332 + dev->nd_net = net;
333 +
334 + if (register_netdev(dev) < 0)
335 + goto err_register;
336 + }
337 + printk(KERN_INFO "IMQ starting with %u devices...\n", j);
338 + return 0;
339 +
340 +err_register:
341 + for (; i; i--)
342 + unregister_netdev(--dev);
343 + kfree(imq_devs);
344 + return -EIO;
345 +}
346 +
347 +static void imq_cleanup_devs(void)
348 +{
349 + int i;
350 + struct net_device *dev = imq_devs;
351 +
352 + for (i = 0; i <= numdevs; i++)
353 + unregister_netdev(dev++);
354 +
355 + kfree(imq_devs);
356 +}
357 +
358 +static __net_init int imq_init_module(struct net *net)
359 +{
360 + int err;
361 +
362 + if ((err = imq_init_devs(net))) {
363 + printk(KERN_ERR "IMQ: Error trying imq_init_devs(net)\n");
364 + return err;
365 + }
366 + if ((err = imq_init_hooks())) {
367 + printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
368 + imq_cleanup_devs();
369 + return err;
370 + }
371 +
372 + printk(KERN_INFO "IMQ driver loaded successfully.\n");
373 +
374 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
375 + printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n");
376 +#else
377 + printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n");
378 +#endif
379 +#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
380 + printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n");
381 +#else
382 + printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n");
383 +#endif
384 +
385 + return 0;
386 +}
387 +
388 +static __net_exit void imq_exit_module(struct net *net)
389 +{
390 + imq_unhook();
391 + imq_cleanup_devs();
392 + printk(KERN_INFO "IMQ driver unloaded successfully.\n");
393 +}
394 +
395 +static struct pernet_operations __net_initdata imq_net_ops = {
396 + .init = imq_init_module,
397 + .exit = imq_exit_module,
398 +};
399 +
400 +static int __init imq_init(void)
401 +{
402 + return register_pernet_device(&imq_net_ops);
403 +}
404 +
405 +module_init(imq_init);
406 +//module_exit(imq_cleanup_module);
407 +
408 +module_param(numdevs, int, 0);
409 +MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)");
410 +MODULE_AUTHOR("http://www.linuximq.net");
411 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
412 +MODULE_LICENSE("GPL");
413 --- a/drivers/net/Kconfig
414 +++ b/drivers/net/Kconfig
415 @@ -112,6 +112,129 @@ config EQUALIZER
416 To compile this driver as a module, choose M here: the module
417 will be called eql. If unsure, say N.
418
419 +config IMQ
420 + tristate "IMQ (intermediate queueing device) support"
421 + depends on NETDEVICES && NETFILTER
422 + ---help---
423 + The IMQ device(s) is used as placeholder for QoS queueing
424 + disciplines. Every packet entering/leaving the IP stack can be
425 + directed through the IMQ device where it's enqueued/dequeued to the
426 + attached qdisc. This allows you to treat network devices as classes
427 + and distribute bandwidth among them. Iptables is used to specify
428 + through which IMQ device, if any, packets travel.
429 +
430 + More information at: http://www.linuximq.net/
431 +
432 + To compile this driver as a module, choose M here: the module
433 + will be called imq. If unsure, say N.
434 +
435 +choice
436 + prompt "IMQ behavior (PRE/POSTROUTING)"
437 + depends on IMQ
438 + default IMQ_BEHAVIOR_BB
439 + help
440 +
441 + This settings defines how IMQ behaves in respect to its
442 + hooking in PREROUTING and POSTROUTING.
443 +
444 + IMQ can work in any of the following ways:
445 +
446 + PREROUTING | POSTROUTING
447 + -----------------|-------------------
448 + #1 After NAT | After NAT
449 + #2 After NAT | Before NAT
450 + #3 Before NAT | After NAT
451 + #4 Before NAT | Before NAT
452 +
453 + The default behavior is to hook before NAT on PREROUTING
454 + and after NAT on POSTROUTING (#3).
455 +
456 + This settings are specially usefull when trying to use IMQ
457 + to shape NATed clients.
458 +
459 + More information can be found at: www.linuximq.net
460 +
461 + If not sure leave the default settings alone.
462 +
463 +config IMQ_BEHAVIOR_AA
464 + bool "IMQ AA"
465 + help
466 + This settings defines how IMQ behaves in respect to its
467 + hooking in PREROUTING and POSTROUTING.
468 +
469 + Choosing this option will make IMQ hook like this:
470 +
471 + PREROUTING: After NAT
472 + POSTROUTING: After NAT
473 +
474 + More information can be found at: www.linuximq.net
475 +
476 + If not sure leave the default settings alone.
477 +
478 +config IMQ_BEHAVIOR_AB
479 + bool "IMQ AB"
480 + help
481 + This settings defines how IMQ behaves in respect to its
482 + hooking in PREROUTING and POSTROUTING.
483 +
484 + Choosing this option will make IMQ hook like this:
485 +
486 + PREROUTING: After NAT
487 + POSTROUTING: Before NAT
488 +
489 + More information can be found at: www.linuximq.net
490 +
491 + If not sure leave the default settings alone.
492 +
493 +config IMQ_BEHAVIOR_BA
494 + bool "IMQ BA"
495 + help
496 + This settings defines how IMQ behaves in respect to its
497 + hooking in PREROUTING and POSTROUTING.
498 +
499 + Choosing this option will make IMQ hook like this:
500 +
501 + PREROUTING: Before NAT
502 + POSTROUTING: After NAT
503 +
504 + More information can be found at: www.linuximq.net
505 +
506 + If not sure leave the default settings alone.
507 +
508 +config IMQ_BEHAVIOR_BB
509 + bool "IMQ BB"
510 + help
511 + This settings defines how IMQ behaves in respect to its
512 + hooking in PREROUTING and POSTROUTING.
513 +
514 + Choosing this option will make IMQ hook like this:
515 +
516 + PREROUTING: Before NAT
517 + POSTROUTING: Before NAT
518 +
519 + More information can be found at: www.linuximq.net
520 +
521 + If not sure leave the default settings alone.
522 +
523 +endchoice
524 +
525 +config IMQ_NUM_DEVS
526 +
527 + int "Number of IMQ devices"
528 + range 2 16
529 + depends on IMQ
530 + default "16"
531 + help
532 +
533 + This settings defines how many IMQ devices will be
534 + created.
535 +
536 + The default value is 16.
537 +
538 + More information can be found at: www.linuximq.net
539 +
540 + If not sure leave the default settings alone.
541 +
542 config TUN
543 tristate "Universal TUN/TAP device driver support"
544 select CRC32
545 --- a/drivers/net/Makefile
546 +++ b/drivers/net/Makefile
547 @@ -139,6 +139,7 @@ obj-$(CONFIG_SLHC) += slhc.o
548 obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
549
550 obj-$(CONFIG_DUMMY) += dummy.o
551 +obj-$(CONFIG_IMQ) += imq.o
552 obj-$(CONFIG_IFB) += ifb.o
553 obj-$(CONFIG_MACVLAN) += macvlan.o
554 obj-$(CONFIG_DE600) += de600.o
555 --- /dev/null
556 +++ b/include/linux/imq.h
557 @@ -0,0 +1,9 @@
558 +#ifndef _IMQ_H
559 +#define _IMQ_H
560 +
561 +#define IMQ_MAX_DEVS 16
562 +
563 +#define IMQ_F_IFMASK 0x7f
564 +#define IMQ_F_ENQUEUE 0x80
565 +
566 +#endif /* _IMQ_H */
567 --- /dev/null
568 +++ b/include/linux/netfilter_ipv4/ipt_IMQ.h
569 @@ -0,0 +1,8 @@
570 +#ifndef _IPT_IMQ_H
571 +#define _IPT_IMQ_H
572 +
573 +struct ipt_imq_info {
574 + unsigned int todev; /* target imq device */
575 +};
576 +
577 +#endif /* _IPT_IMQ_H */
578 --- /dev/null
579 +++ b/include/linux/netfilter_ipv6/ip6t_IMQ.h
580 @@ -0,0 +1,8 @@
581 +#ifndef _IP6T_IMQ_H
582 +#define _IP6T_IMQ_H
583 +
584 +struct ip6t_imq_info {
585 + unsigned int todev; /* target imq device */
586 +};
587 +
588 +#endif /* _IP6T_IMQ_H */
589 --- a/include/linux/skbuff.h
590 +++ b/include/linux/skbuff.h
591 @@ -295,6 +295,10 @@ struct sk_buff {
592 struct nf_conntrack *nfct;
593 struct sk_buff *nfct_reasm;
594 #endif
595 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
596 + unsigned char imq_flags;
597 + struct nf_info *nf_info;
598 +#endif
599 #ifdef CONFIG_BRIDGE_NETFILTER
600 struct nf_bridge_info *nf_bridge;
601 #endif
602 @@ -1728,6 +1732,10 @@ static inline void __nf_copy(struct sk_b
603 dst->nfct_reasm = src->nfct_reasm;
604 nf_conntrack_get_reasm(src->nfct_reasm);
605 #endif
606 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
607 + dst->imq_flags = src->imq_flags;
608 + dst->nf_info = src->nf_info;
609 +#endif
610 #ifdef CONFIG_BRIDGE_NETFILTER
611 dst->nf_bridge = src->nf_bridge;
612 nf_bridge_get(src->nf_bridge);
613 --- a/net/core/dev.c
614 +++ b/net/core/dev.c
615 @@ -95,6 +95,9 @@
616 #include <net/net_namespace.h>
617 #include <net/sock.h>
618 #include <linux/rtnetlink.h>
619 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
620 +#include <linux/imq.h>
621 +#endif
622 #include <linux/proc_fs.h>
623 #include <linux/seq_file.h>
624 #include <linux/stat.h>
625 @@ -1533,7 +1536,11 @@ static int dev_gso_segment(struct sk_buf
626 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
627 {
628 if (likely(!skb->next)) {
629 - if (!list_empty(&ptype_all))
630 + if (!list_empty(&ptype_all)
631 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
632 + && !(skb->imq_flags & IMQ_F_ENQUEUE)
633 +#endif
634 + )
635 dev_queue_xmit_nit(skb, dev);
636
637 if (netif_needs_gso(dev, skb)) {
638 --- /dev/null
639 +++ b/net/ipv4/netfilter/ipt_IMQ.c
640 @@ -0,0 +1,69 @@
641 +/*
642 + * This target marks packets to be enqueued to an imq device
643 + */
644 +#include <linux/module.h>
645 +#include <linux/skbuff.h>
646 +#include <linux/netfilter_ipv4/ip_tables.h>
647 +#include <linux/netfilter_ipv4/ipt_IMQ.h>
648 +#include <linux/imq.h>
649 +
650 +static unsigned int imq_target(struct sk_buff *pskb,
651 + const struct net_device *in,
652 + const struct net_device *out,
653 + unsigned int hooknum,
654 + const struct xt_target *target,
655 + const void *targinfo)
656 +{
657 + struct ipt_imq_info *mr = (struct ipt_imq_info*)targinfo;
658 +
659 + pskb->imq_flags = mr->todev | IMQ_F_ENQUEUE;
660 +
661 + return XT_CONTINUE;
662 +}
663 +
664 +static bool imq_checkentry(const char *tablename,
665 + const void *e,
666 + const struct xt_target *target,
667 + void *targinfo,
668 + unsigned int hook_mask)
669 +{
670 + struct ipt_imq_info *mr;
671 +
672 + mr = (struct ipt_imq_info*)targinfo;
673 +
674 + if (mr->todev > IMQ_MAX_DEVS) {
675 + printk(KERN_WARNING
676 + "IMQ: invalid device specified, highest is %u\n",
677 + IMQ_MAX_DEVS);
678 + return 0;
679 + }
680 +
681 + return 1;
682 +}
683 +
684 +static struct xt_target ipt_imq_reg = {
685 + .name = "IMQ",
686 + .family = AF_INET,
687 + .target = imq_target,
688 + .targetsize = sizeof(struct ipt_imq_info),
689 + .checkentry = imq_checkentry,
690 + .me = THIS_MODULE,
691 + .table = "mangle"
692 +};
693 +
694 +static int __init init(void)
695 +{
696 + return xt_register_target(&ipt_imq_reg);
697 +}
698 +
699 +static void __exit fini(void)
700 +{
701 + xt_unregister_target(&ipt_imq_reg);
702 +}
703 +
704 +module_init(init);
705 +module_exit(fini);
706 +
707 +MODULE_AUTHOR("http://www.linuximq.net");
708 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
709 +MODULE_LICENSE("GPL");
710 --- a/net/ipv4/netfilter/Kconfig
711 +++ b/net/ipv4/netfilter/Kconfig
712 @@ -317,6 +317,17 @@ config IP_NF_MANGLE
713
714 To compile it as a module, choose M here. If unsure, say N.
715
716 +config IP_NF_TARGET_IMQ
717 + tristate "IMQ target support"
718 + depends on IP_NF_MANGLE
719 + help
720 + This option adds a `IMQ' target which is used to specify if and
721 + to which IMQ device packets should get enqueued/dequeued.
722 +
723 + For more information visit: http://www.linuximq.net/
724 +
725 + To compile it as a module, choose M here. If unsure, say N.
726 +
727 config IP_NF_TARGET_TOS
728 tristate "TOS target support"
729 depends on IP_NF_MANGLE
730 --- a/net/ipv4/netfilter/Makefile
731 +++ b/net/ipv4/netfilter/Makefile
732 @@ -57,6 +57,7 @@ obj-$(CONFIG_IP_NF_MATCH_IPP2P) += ipt_i
733 obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
734 obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
735 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
736 +obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
737 obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
738 obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
739 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
740 --- /dev/null
741 +++ b/net/ipv6/netfilter/ip6t_IMQ.c
742 @@ -0,0 +1,69 @@
743 +/*
744 + * This target marks packets to be enqueued to an imq device
745 + */
746 +#include <linux/module.h>
747 +#include <linux/skbuff.h>
748 +#include <linux/netfilter_ipv6/ip6_tables.h>
749 +#include <linux/netfilter_ipv6/ip6t_IMQ.h>
750 +#include <linux/imq.h>
751 +
752 +static unsigned int imq_target(struct sk_buff *pskb,
753 + const struct net_device *in,
754 + const struct net_device *out,
755 + unsigned int hooknum,
756 + const struct xt_target *target,
757 + const void *targinfo)
758 +{
759 + struct ip6t_imq_info *mr = (struct ip6t_imq_info*)targinfo;
760 +
761 + pskb->imq_flags = mr->todev | IMQ_F_ENQUEUE;
762 +
763 + return XT_CONTINUE;
764 +}
765 +
766 +static bool imq_checkentry(const char *tablename,
767 + const void *entry,
768 + const struct xt_target *target,
769 + void *targinfo,
770 + unsigned int hook_mask)
771 +{
772 + struct ip6t_imq_info *mr;
773 +
774 + mr = (struct ip6t_imq_info*)targinfo;
775 +
776 + if (mr->todev > IMQ_MAX_DEVS) {
777 + printk(KERN_WARNING
778 + "IMQ: invalid device specified, highest is %u\n",
779 + IMQ_MAX_DEVS);
780 + return 0;
781 + }
782 +
783 + return 1;
784 +}
785 +
786 +static struct xt_target ip6t_imq_reg = {
787 + .name = "IMQ",
788 + .family = AF_INET6,
789 + .target = imq_target,
790 + .targetsize = sizeof(struct ip6t_imq_info),
791 + .table = "mangle",
792 + .checkentry = imq_checkentry,
793 + .me = THIS_MODULE
794 +};
795 +
796 +static int __init init(void)
797 +{
798 + return xt_register_target(&ip6t_imq_reg);
799 +}
800 +
801 +static void __exit fini(void)
802 +{
803 + xt_unregister_target(&ip6t_imq_reg);
804 +}
805 +
806 +module_init(init);
807 +module_exit(fini);
808 +
809 +MODULE_AUTHOR("http://www.linuximq.net");
810 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
811 +MODULE_LICENSE("GPL");
812 --- a/net/ipv6/netfilter/Kconfig
813 +++ b/net/ipv6/netfilter/Kconfig
814 @@ -173,6 +173,15 @@ config IP6_NF_MANGLE
815
816 To compile it as a module, choose M here. If unsure, say N.
817
818 +config IP6_NF_TARGET_IMQ
819 + tristate "IMQ target support"
820 + depends on IP6_NF_MANGLE
821 + help
822 + This option adds a `IMQ' target which is used to specify if and
823 + to which imq device packets should get enqueued/dequeued.
824 +
825 + To compile it as a module, choose M here. If unsure, say N.
826 +
827 config IP6_NF_TARGET_HL
828 tristate 'HL (hoplimit) target support'
829 depends on IP6_NF_MANGLE
830 --- a/net/ipv6/netfilter/Makefile
831 +++ b/net/ipv6/netfilter/Makefile
832 @@ -6,6 +6,7 @@
833 obj-$(CONFIG_IP6_NF_IPTABLES) += ip6_tables.o
834 obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
835 obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
836 +obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
837 obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
838 obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
839
840 --- a/net/sched/sch_generic.c
841 +++ b/net/sched/sch_generic.c
842 @@ -176,6 +176,11 @@ static inline int qdisc_restart(struct n
843 return ret;
844 }
845
846 +int qdisc_restart1(struct net_device *dev)
847 +{
848 + return qdisc_restart(dev);
849 +}
850 +
851 void __qdisc_run(struct net_device *dev)
852 {
853 unsigned long start_time = jiffies;
854 @@ -650,3 +655,4 @@ EXPORT_SYMBOL(qdisc_destroy);
855 EXPORT_SYMBOL(qdisc_reset);
856 EXPORT_SYMBOL(qdisc_lock_tree);
857 EXPORT_SYMBOL(qdisc_unlock_tree);
858 +EXPORT_SYMBOL(qdisc_restart1);