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