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