17b4569a85db2359dade82f9aca259ede06acabf
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.22 / 150-netfilter_imq.patch
1 --- /dev/null
2 +++ b/drivers/net/imq.c
3 @@ -0,0 +1,402 @@
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 = 2;
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);
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);
273 +err1:
274 +       return err;
275 +}
276 +
277 +static void __exit imq_unhook(void)
278 +{
279 +       nf_unregister_hook(&imq_ingress_ipv4);
280 +       nf_unregister_hook(&imq_egress_ipv4);
281 +       nf_unregister_queue_handler(PF_INET);
282 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
283 +       nf_unregister_hook(&imq_ingress_ipv6);
284 +       nf_unregister_hook(&imq_egress_ipv6);
285 +       nf_unregister_queue_handler(PF_INET6);
286 +#endif
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                = 1500;
294 +       dev->tx_queue_len       = 30;
295 +       dev->flags              = IFF_NOARP;
296 +       dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
297 +       if (dev->priv == NULL)
298 +               return -ENOMEM;
299 +       memset(dev->priv, 0, sizeof(struct net_device_stats));
300 +       dev->get_stats          = imq_get_stats;
301 +
302 +       return 0;
303 +}
304 +
305 +static void imq_dev_uninit(struct net_device *dev)
306 +{
307 +       kfree(dev->priv);
308 +}
309 +
310 +static int __init imq_init_devs(void)
311 +{
312 +       struct net_device *dev;
313 +       int i,j;
314 +       j = numdevs;
315 +
316 +       if (!numdevs || numdevs > IMQ_MAX_DEVS) {
317 +               printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n",
318 +                      IMQ_MAX_DEVS);
319 +               return -EINVAL;
320 +       }
321 +
322 +       imq_devs = kmalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
323 +       if (!imq_devs)
324 +               return -ENOMEM;
325 +       memset(imq_devs, 0, sizeof(struct net_device) * numdevs);
326 +
327 +       /* we start counting at zero */
328 +       numdevs--;
329 +
330 +       for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
331 +               SET_MODULE_OWNER(dev);
332 +               strcpy(dev->name, "imq%d");
333 +               dev->init   = imq_dev_init;
334 +               dev->uninit = imq_dev_uninit;
335 +
336 +               if (register_netdev(dev) < 0)
337 +                       goto err_register;
338 +       }
339 +       printk(KERN_INFO "IMQ starting with %u devices...\n", j);
340 +       return 0;
341 +
342 +err_register:
343 +       for (; i; i--)
344 +               unregister_netdev(--dev);
345 +       kfree(imq_devs);
346 +       return -EIO;
347 +}
348 +
349 +static void imq_cleanup_devs(void)
350 +{
351 +       int i;
352 +       struct net_device *dev = imq_devs;
353 +
354 +       for (i = 0; i <= numdevs; i++)
355 +               unregister_netdev(dev++);
356 +
357 +       kfree(imq_devs);
358 +}
359 +
360 +static int __init imq_init_module(void)
361 +{
362 +       int err;
363 +
364 +       if ((err = imq_init_devs())) {
365 +               printk(KERN_ERR "IMQ: Error trying imq_init_devs()\n");
366 +               return err;
367 +       }
368 +       if ((err = imq_init_hooks())) {
369 +               printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
370 +               imq_cleanup_devs();
371 +               return err;
372 +       }
373 +
374 +       printk(KERN_INFO "IMQ driver loaded successfully.\n");
375 +
376 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
377 +       printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n");
378 +#else
379 +       printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n");
380 +#endif
381 +#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
382 +       printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n");
383 +#else
384 +       printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n");
385 +#endif
386 +
387 +       return 0;
388 +}
389 +
390 +static void __exit imq_cleanup_module(void)
391 +{
392 +       imq_unhook();
393 +       imq_cleanup_devs();
394 +       printk(KERN_INFO "IMQ driver unloaded successfully.\n");
395 +}
396 +
397 +
398 +module_init(imq_init_module);
399 +module_exit(imq_cleanup_module);
400 +
401 +module_param(numdevs, int, 0);
402 +MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)");
403 +MODULE_AUTHOR("http://www.linuximq.net");
404 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
405 +MODULE_LICENSE("GPL");
406 --- a/drivers/net/Kconfig
407 +++ b/drivers/net/Kconfig
408 @@ -96,6 +96,129 @@
409           To compile this driver as a module, choose M here: the module
410           will be called eql.  If unsure, say N.
411  
412 +config IMQ
413 +       tristate "IMQ (intermediate queueing device) support"
414 +       depends on NETDEVICES && NETFILTER
415 +       ---help---
416 +         The IMQ device(s) is used as placeholder for QoS queueing
417 +         disciplines. Every packet entering/leaving the IP stack can be
418 +         directed through the IMQ device where it's enqueued/dequeued to the
419 +         attached qdisc. This allows you to treat network devices as classes
420 +         and distribute bandwidth among them. Iptables is used to specify
421 +         through which IMQ device, if any, packets travel.
422 +
423 +         More information at: http://www.linuximq.net/
424 +
425 +         To compile this driver as a module, choose M here: the module
426 +         will be called imq.  If unsure, say N.
427 +
428 +choice
429 +       prompt "IMQ behavior (PRE/POSTROUTING)"
430 +       depends on IMQ
431 +       default IMQ_BEHAVIOR_BA
432 +       help
433 +
434 +               This settings defines how IMQ behaves in respect to its
435 +               hooking in PREROUTING and POSTROUTING.
436 +
437 +               IMQ can work in any of the following ways:
438 +
439 +                   PREROUTING   |      POSTROUTING
440 +               -----------------|-------------------
441 +               #1  After NAT    |      After NAT
442 +               #2  After NAT    |      Before NAT
443 +               #3  Before NAT   |      After NAT
444 +               #4  Before NAT   |      Before NAT
445 +
446 +               The default behavior is to hook before NAT on PREROUTING
447 +               and after NAT on POSTROUTING (#3).
448 +
449 +               This settings are specially usefull when trying to use IMQ
450 +               to shape NATed clients.
451 +
452 +               More information can be found at: www.linuximq.net
453 +
454 +               If not sure leave the default settings alone.
455 +
456 +config IMQ_BEHAVIOR_AA
457 +       bool "IMQ AA"
458 +       help
459 +               This settings defines how IMQ behaves in respect to its
460 +               hooking in PREROUTING and POSTROUTING.
461 +
462 +               Choosing this option will make IMQ hook like this:
463 +
464 +               PREROUTING:   After NAT
465 +               POSTROUTING:  After NAT
466 +
467 +               More information can be found at: www.linuximq.net
468 +
469 +               If not sure leave the default settings alone.
470 +
471 +config IMQ_BEHAVIOR_AB
472 +       bool "IMQ AB"
473 +       help
474 +               This settings defines how IMQ behaves in respect to its
475 +               hooking in PREROUTING and POSTROUTING.
476 +
477 +               Choosing this option will make IMQ hook like this:
478 +
479 +               PREROUTING:   After NAT
480 +               POSTROUTING:  Before NAT
481 +
482 +               More information can be found at: www.linuximq.net
483 +
484 +               If not sure leave the default settings alone.
485 +
486 +config IMQ_BEHAVIOR_BA
487 +       bool "IMQ BA"
488 +       help
489 +               This settings defines how IMQ behaves in respect to its
490 +               hooking in PREROUTING and POSTROUTING.
491 +
492 +               Choosing this option will make IMQ hook like this:
493 +
494 +               PREROUTING:   Before NAT
495 +               POSTROUTING:  After NAT
496 +
497 +               More information can be found at: www.linuximq.net
498 +
499 +               If not sure leave the default settings alone.
500 +
501 +config IMQ_BEHAVIOR_BB
502 +       bool "IMQ BB"
503 +       help
504 +               This settings defines how IMQ behaves in respect to its
505 +               hooking in PREROUTING and POSTROUTING.
506 +
507 +               Choosing this option will make IMQ hook like this:
508 +
509 +               PREROUTING:   Before NAT
510 +               POSTROUTING:  Before NAT
511 +
512 +               More information can be found at: www.linuximq.net
513 +
514 +               If not sure leave the default settings alone.
515 +
516 +endchoice
517 +
518 +config IMQ_NUM_DEVS
519 +
520 +       int "Number of IMQ devices"
521 +       range 2 8
522 +       depends on IMQ
523 +       default "2"
524 +       help
525 +
526 +               This settings defines how many IMQ devices will be
527 +               created.
528 +
529 +               The default value is 2.
530 +
531 +               More information can be found at: www.linuximq.net
532 +
533 +               If not sure leave the default settings alone.
534 +
535  config TUN
536         tristate "Universal TUN/TAP device driver support"
537         select CRC32
538 --- a/drivers/net/Makefile
539 +++ b/drivers/net/Makefile
540 @@ -124,6 +124,7 @@
541  obj-$(CONFIG_SLHC) += slhc.o
542  
543  obj-$(CONFIG_DUMMY) += dummy.o
544 +obj-$(CONFIG_IMQ) += imq.o
545  obj-$(CONFIG_IFB) += ifb.o
546  obj-$(CONFIG_DE600) += de600.o
547  obj-$(CONFIG_DE620) += de620.o
548 --- /dev/null
549 +++ b/include/linux/imq.h
550 @@ -0,0 +1,9 @@
551 +#ifndef _IMQ_H
552 +#define _IMQ_H
553 +
554 +#define IMQ_MAX_DEVS   16
555 +
556 +#define IMQ_F_IFMASK   0x7f
557 +#define IMQ_F_ENQUEUE  0x80
558 +
559 +#endif /* _IMQ_H */
560 --- /dev/null
561 +++ b/include/linux/netfilter_ipv4/ipt_IMQ.h
562 @@ -0,0 +1,8 @@
563 +#ifndef _IPT_IMQ_H
564 +#define _IPT_IMQ_H
565 +
566 +struct ipt_imq_info {
567 +       unsigned int todev;     /* target imq device */
568 +};
569 +
570 +#endif /* _IPT_IMQ_H */
571 --- /dev/null
572 +++ b/include/linux/netfilter_ipv6/ip6t_IMQ.h
573 @@ -0,0 +1,8 @@
574 +#ifndef _IP6T_IMQ_H
575 +#define _IP6T_IMQ_H
576 +
577 +struct ip6t_imq_info {
578 +       unsigned int todev;     /* target imq device */
579 +};
580 +
581 +#endif /* _IP6T_IMQ_H */
582 --- a/include/linux/skbuff.h
583 +++ b/include/linux/skbuff.h
584 @@ -285,6 +285,10 @@
585         struct nf_conntrack     *nfct;
586         struct sk_buff          *nfct_reasm;
587  #endif
588 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
589 +       unsigned char           imq_flags;
590 +       struct nf_info          *nf_info;
591 +#endif
592  #ifdef CONFIG_BRIDGE_NETFILTER
593         struct nf_bridge_info   *nf_bridge;
594  #endif
595 --- a/net/core/dev.c
596 +++ b/net/core/dev.c
597 @@ -94,6 +94,9 @@
598  #include <linux/skbuff.h>
599  #include <net/sock.h>
600  #include <linux/rtnetlink.h>
601 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
602 +#include <linux/imq.h>
603 +#endif
604  #include <linux/proc_fs.h>
605  #include <linux/seq_file.h>
606  #include <linux/stat.h>
607 @@ -1404,6 +1407,9 @@
608  {
609         if (likely(!skb->next)) {
610                 if (!list_empty(&ptype_all))
611 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
612 +                   if (!(skb->imq_flags & IMQ_F_ENQUEUE))
613 +#endif
614                         dev_queue_xmit_nit(skb, dev);
615  
616                 if (netif_needs_gso(dev, skb)) {
617 --- a/net/core/skbuff.c
618 +++ b/net/core/skbuff.c
619 @@ -419,6 +419,10 @@
620         C(pkt_type);
621         C(ip_summed);
622         C(priority);
623 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
624 +       C(imq_flags);
625 +       C(nf_info);
626 +#endif /*CONFIG_IMQ*/
627  #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
628         C(ipvs_property);
629  #endif
630 @@ -485,6 +489,10 @@
631  #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
632         new->ipvs_property = old->ipvs_property;
633  #endif
634 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
635 +       new->imq_flags  = old->imq_flags;
636 +       new->nf_info    = old->nf_info;
637 +#endif /*CONFIG_IMQ*/
638  #ifdef CONFIG_NET_SCHED
639  #ifdef CONFIG_NET_CLS_ACT
640         new->tc_verd = old->tc_verd;
641 --- /dev/null
642 +++ b/net/ipv4/netfilter/ipt_IMQ.c
643 @@ -0,0 +1,69 @@
644 +/*
645 + * This target marks packets to be enqueued to an imq device
646 + */
647 +#include <linux/module.h>
648 +#include <linux/skbuff.h>
649 +#include <linux/netfilter_ipv4/ip_tables.h>
650 +#include <linux/netfilter_ipv4/ipt_IMQ.h>
651 +#include <linux/imq.h>
652 +
653 +static unsigned int imq_target(struct sk_buff **pskb,
654 +                              const struct net_device *in,
655 +                              const struct net_device *out,
656 +                              unsigned int hooknum,
657 +                              const struct xt_target *target,
658 +                              const void *targinfo)
659 +{
660 +       struct ipt_imq_info *mr = (struct ipt_imq_info*)targinfo;
661 +
662 +       (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
663 +
664 +       return XT_CONTINUE;
665 +}
666 +
667 +static int imq_checkentry(const char *tablename,
668 +                         const void *e,
669 +                         const struct xt_target *target,
670 +                         void *targinfo,
671 +                         unsigned int hook_mask)
672 +{
673 +       struct ipt_imq_info *mr;
674 +
675 +       mr = (struct ipt_imq_info*)targinfo;
676 +
677 +       if (mr->todev > IMQ_MAX_DEVS) {
678 +               printk(KERN_WARNING
679 +                      "IMQ: invalid device specified, highest is %u\n",
680 +                      IMQ_MAX_DEVS);
681 +               return 0;
682 +       }
683 +
684 +       return 1;
685 +}
686 +
687 +static struct xt_target ipt_imq_reg = {
688 +       .name           = "IMQ",
689 +       .family         = AF_INET,
690 +       .target         = imq_target,
691 +       .targetsize     = sizeof(struct ipt_imq_info),
692 +       .checkentry     = imq_checkentry,
693 +       .me             = THIS_MODULE,
694 +       .table          = "mangle"
695 +};
696 +
697 +static int __init init(void)
698 +{
699 +       return xt_register_target(&ipt_imq_reg);
700 +}
701 +
702 +static void __exit fini(void)
703 +{
704 +       xt_unregister_target(&ipt_imq_reg);
705 +}
706 +
707 +module_init(init);
708 +module_exit(fini);
709 +
710 +MODULE_AUTHOR("http://www.linuximq.net");
711 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
712 +MODULE_LICENSE("GPL");
713 --- a/net/ipv4/netfilter/Kconfig
714 +++ b/net/ipv4/netfilter/Kconfig
715 @@ -333,6 +333,17 @@
716  
717           To compile it as a module, choose M here.  If unsure, say N.
718  
719 +config IP_NF_TARGET_IMQ
720 +       tristate "IMQ target support"
721 +       depends on IP_NF_MANGLE
722 +       help
723 +         This option adds a `IMQ' target which is used to specify if and
724 +         to which IMQ device packets should get enqueued/dequeued.
725 +
726 +        For more information visit: http://www.linuximq.net/
727 +
728 +         To compile it as a module, choose M here.  If unsure, say N.
729 +
730  config IP_NF_TARGET_TOS
731         tristate "TOS target support"
732         depends on IP_NF_MANGLE
733 --- a/net/ipv4/netfilter/Makefile
734 +++ b/net/ipv4/netfilter/Makefile
735 @@ -57,6 +57,7 @@
736  obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
737  obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
738  obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
739 +obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
740  obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
741  obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
742  obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
743 --- /dev/null
744 +++ b/net/ipv6/netfilter/ip6t_IMQ.c
745 @@ -0,0 +1,69 @@
746 +/*
747 + * This target marks packets to be enqueued to an imq device
748 + */
749 +#include <linux/module.h>
750 +#include <linux/skbuff.h>
751 +#include <linux/netfilter_ipv6/ip6_tables.h>
752 +#include <linux/netfilter_ipv6/ip6t_IMQ.h>
753 +#include <linux/imq.h>
754 +
755 +static unsigned int imq_target(struct sk_buff **pskb,
756 +                              const struct net_device *in,
757 +                              const struct net_device *out,
758 +                              unsigned int hooknum,
759 +                              const struct xt_target *target,
760 +                              const void *targinfo)
761 +{
762 +       struct ip6t_imq_info *mr = (struct ip6t_imq_info*)targinfo;
763 +
764 +       (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
765 +
766 +       return XT_CONTINUE;
767 +}
768 +
769 +static int imq_checkentry(const char *tablename,
770 +                         const void *entry,
771 +                         const struct xt_target *target,
772 +                         void *targinfo,
773 +                         unsigned int hook_mask)
774 +{
775 +       struct ip6t_imq_info *mr;
776 +
777 +       mr = (struct ip6t_imq_info*)targinfo;
778 +
779 +       if (mr->todev > IMQ_MAX_DEVS) {
780 +               printk(KERN_WARNING
781 +                      "IMQ: invalid device specified, highest is %u\n",
782 +                      IMQ_MAX_DEVS);
783 +               return 0;
784 +       }
785 +
786 +       return 1;
787 +}
788 +
789 +static struct xt_target ip6t_imq_reg = {
790 +       .name           = "IMQ",
791 +       .family         = AF_INET6,
792 +       .target         = imq_target,
793 +       .targetsize     = sizeof(struct ip6t_imq_info),
794 +       .table          = "mangle",
795 +       .checkentry     = imq_checkentry,
796 +       .me             = THIS_MODULE
797 +};
798 +
799 +static int __init init(void)
800 +{
801 +       return xt_register_target(&ip6t_imq_reg);
802 +}
803 +
804 +static void __exit fini(void)
805 +{
806 +       xt_unregister_target(&ip6t_imq_reg);
807 +}
808 +
809 +module_init(init);
810 +module_exit(fini);
811 +
812 +MODULE_AUTHOR("http://www.linuximq.net");
813 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
814 +MODULE_LICENSE("GPL");
815 --- a/net/ipv6/netfilter/Kconfig
816 +++ b/net/ipv6/netfilter/Kconfig
817 @@ -173,6 +173,15 @@
818  
819           To compile it as a module, choose M here.  If unsure, say N.
820  
821 +config IP6_NF_TARGET_IMQ
822 +       tristate "IMQ target support"
823 +       depends on IP6_NF_MANGLE
824 +       help
825 +          This option adds a `IMQ' target which is used to specify if and
826 +          to which imq device packets should get enqueued/dequeued.
827 +
828 +          To compile it as a module, choose M here.  If unsure, say N.
829 +
830  config IP6_NF_TARGET_HL
831         tristate  'HL (hoplimit) target support'
832         depends on IP6_NF_MANGLE
833 --- a/net/ipv6/netfilter/Makefile
834 +++ b/net/ipv6/netfilter/Makefile
835 @@ -13,6 +13,7 @@
836  obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
837  obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
838  obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
839 +obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
840  obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
841  obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
842  obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
843 --- a/net/sched/sch_generic.c
844 +++ b/net/sched/sch_generic.c
845 @@ -77,7 +77,6 @@
846  
847     NOTE: Called under dev->queue_lock with locally disabled BH.
848  */
849 -
850  static inline int qdisc_restart(struct net_device *dev)
851  {
852         struct Qdisc *q = dev->qdisc;
853 @@ -177,6 +176,11 @@
854         return q->q.qlen;
855  }
856  
857 +int qdisc_restart1(struct net_device *dev)
858 +{
859 +       return qdisc_restart(dev);
860 +}
861 +
862  void __qdisc_run(struct net_device *dev)
863  {
864         do {
865 @@ -608,3 +612,4 @@
866  EXPORT_SYMBOL(qdisc_reset);
867  EXPORT_SYMBOL(qdisc_lock_tree);
868  EXPORT_SYMBOL(qdisc_unlock_tree);
869 +EXPORT_SYMBOL(qdisc_restart1);