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