]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/linux-2.6.27.21-imq-test3.patch
Add some patches to grub.
[people/pmueller/ipfire-2.x.git] / src / patches / linux-2.6.27.21-imq-test3.patch
CommitLineData
3a65a332
BS
1diff -uNr --exclude='*~' linux-2.6.27.21/drivers/net/imq.c linux-2.6.27.21-imq/drivers/net/imq.c
2--- linux-2.6.27.21/drivers/net/imq.c 1970-01-01 02:00:00.000000000 +0200
3+++ linux-2.6.27.21-imq/drivers/net/imq.c 2009-04-20 23:52:22.712017559 +0300
4@@ -0,0 +1,566 @@
5+/*
6+ * Pseudo-driver for the intermediate queue device.
7+ *
8+ * This program is free software; you can redistribute it and/or
9+ * modify it under the terms of the GNU General Public License
10+ * as published by the Free Software Foundation; either version
11+ * 2 of the License, or (at your option) any later version.
12+ *
13+ * Authors: Patrick McHardy, <kaber@trash.net>
14+ *
15+ * The first version was written by Martin Devera, <devik@cdi.cz>
16+ *
17+ * Credits: Jan Rafaj <imq2t@cedric.vabo.cz>
18+ * - Update patch to 2.4.21
19+ * Sebastian Strollo <sstrollo@nortelnetworks.com>
20+ * - Fix "Dead-loop on netdevice imq"-issue
21+ * Marcel Sebek <sebek64@post.cz>
22+ * - Update to 2.6.2-rc1
23+ *
24+ * After some time of inactivity there is a group taking care
25+ * of IMQ again: http://www.linuximq.net
26+ *
27+ *
28+ * 2004/06/30 - New version of IMQ patch to kernels <=2.6.7
29+ * including the following changes:
30+ *
31+ * - Correction of ipv6 support "+"s issue (Hasso Tepper)
32+ * - Correction of imq_init_devs() issue that resulted in
33+ * kernel OOPS unloading IMQ as module (Norbert Buchmuller)
34+ * - Addition of functionality to choose number of IMQ devices
35+ * during kernel config (Andre Correa)
36+ * - Addition of functionality to choose how IMQ hooks on
37+ * PRE and POSTROUTING (after or before NAT) (Andre Correa)
38+ * - Cosmetic corrections (Norbert Buchmuller) (Andre Correa)
39+ *
40+ *
41+ * 2005/12/16 - IMQ versions between 2.6.7 and 2.6.13 were
42+ * released with almost no problems. 2.6.14-x was released
43+ * with some important changes: nfcache was removed; After
44+ * some weeks of trouble we figured out that some IMQ fields
45+ * in skb were missing in skbuff.c - skb_clone and copy_skb_header.
46+ * These functions are correctly patched by this new patch version.
47+ *
48+ * Thanks for all who helped to figure out all the problems with
49+ * 2.6.14.x: Patrick McHardy, Rune Kock, VeNoMouS, Max CtRiX,
50+ * Kevin Shanahan, Richard Lucassen, Valery Dachev (hopefully
51+ * I didn't forget anybody). I apologize again for my lack of time.
52+ *
53+ *
54+ * 2008/06/17 - 2.6.25 - Changed imq.c to use qdisc_run() instead
55+ * of qdisc_restart() and moved qdisc_run() to tasklet to avoid
56+ * recursive locking. New initialization routines to fix 'rmmod' not
57+ * working anymore. Used code from ifb.c. (Jussi Kivilinna)
58+ *
59+ * 2008/08/06 - 2.6.26 - (JK)
60+ * - Replaced tasklet with 'netif_schedule()'.
61+ * - Cleaned up and added comments for imq_nf_queue().
62+ *
63+ * 2009/04/12
64+ * - Add skb_save_cb/skb_restore_cb helper functions for backuping
65+ * control buffer. This is needed because qdisc-layer on kernels
66+ * 2.6.27 and newer overwrite control buffer. (Jussi Kivilinna)
67+ * - Add better locking for IMQ device. Hopefully this will solve
68+ * SMP issues. (Jussi Kivilinna)
69+ * - Port to 2.6.27
70+ *
71+ * 2009/04/20 - (Jussi Kivilinna)
72+ * - Fix rmmod not working
73+ * - Use netdevice feature flags to avoid extra packet handling
74+ * by core networking layer and possibly increase performance.
75+ *
76+ * Also, many thanks to pablo Sebastian Greco for making the initial
77+ * patch and to those who helped the testing.
78+ *
79+ * More info at: http://www.linuximq.net/ (Andre Correa)
80+ */
81+
82+#include <linux/module.h>
83+#include <linux/kernel.h>
84+#include <linux/moduleparam.h>
85+#include <linux/list.h>
86+#include <linux/skbuff.h>
87+#include <linux/netdevice.h>
88+#include <linux/etherdevice.h>
89+#include <linux/rtnetlink.h>
90+#include <linux/if_arp.h>
91+#include <linux/netfilter.h>
92+#include <linux/netfilter_ipv4.h>
93+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
94+ #include <linux/netfilter_ipv6.h>
95+#endif
96+#include <linux/imq.h>
97+#include <net/pkt_sched.h>
98+#include <net/netfilter/nf_queue.h>
99+
100+static nf_hookfn imq_nf_hook;
101+
102+static struct nf_hook_ops imq_ingress_ipv4 = {
103+ .hook = imq_nf_hook,
104+ .owner = THIS_MODULE,
105+ .pf = PF_INET,
106+ .hooknum = NF_INET_PRE_ROUTING,
107+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
108+ .priority = NF_IP_PRI_MANGLE + 1
109+#else
110+ .priority = NF_IP_PRI_NAT_DST + 1
111+#endif
112+};
113+
114+static struct nf_hook_ops imq_egress_ipv4 = {
115+ .hook = imq_nf_hook,
116+ .owner = THIS_MODULE,
117+ .pf = PF_INET,
118+ .hooknum = NF_INET_POST_ROUTING,
119+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
120+ .priority = NF_IP_PRI_LAST
121+#else
122+ .priority = NF_IP_PRI_NAT_SRC - 1
123+#endif
124+};
125+
126+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
127+static struct nf_hook_ops imq_ingress_ipv6 = {
128+ .hook = imq_nf_hook,
129+ .owner = THIS_MODULE,
130+ .pf = PF_INET6,
131+ .hooknum = NF_INET_PRE_ROUTING,
132+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
133+ .priority = NF_IP6_PRI_MANGLE + 1
134+#else
135+ .priority = NF_IP6_PRI_NAT_DST + 1
136+#endif
137+};
138+
139+static struct nf_hook_ops imq_egress_ipv6 = {
140+ .hook = imq_nf_hook,
141+ .owner = THIS_MODULE,
142+ .pf = PF_INET6,
143+ .hooknum = NF_INET_POST_ROUTING,
144+#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
145+ .priority = NF_IP6_PRI_LAST
146+#else
147+ .priority = NF_IP6_PRI_NAT_SRC - 1
148+#endif
149+};
150+#endif
151+
152+#if defined(CONFIG_IMQ_NUM_DEVS)
153+static unsigned int numdevs = CONFIG_IMQ_NUM_DEVS;
154+#else
155+static unsigned int numdevs = IMQ_MAX_DEVS;
156+#endif
157+
158+static DEFINE_SPINLOCK(imq_nf_queue_lock);
159+
160+static struct net_device *imq_devs_cache[IMQ_MAX_DEVS];
161+
162+
163+static struct net_device_stats *imq_get_stats(struct net_device *dev)
164+{
165+ return &dev->stats;
166+}
167+
168+/* called for packets kfree'd in qdiscs at places other than enqueue */
169+static void imq_skb_destructor(struct sk_buff *skb)
170+{
171+ struct nf_queue_entry *entry = skb->nf_queue_entry;
172+
173+ if (entry) {
174+ nf_queue_entry_release_refs(entry);
175+ kfree(entry);
176+ }
177+
178+ skb_restore_cb(skb); /* kfree backup */
179+}
180+
181+static void imq_nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
182+{
183+ int status;
184+
185+ if (!entry->next_outfn) {
186+ spin_lock_bh(&imq_nf_queue_lock);
187+ nf_reinject(entry, verdict);
188+ spin_unlock_bh(&imq_nf_queue_lock);
189+ return;
190+ }
191+
192+ rcu_read_lock();
193+ local_bh_disable();
194+ status = entry->next_outfn(entry, entry->next_queuenum);
195+ local_bh_enable();
196+ if (status < 0) {
197+ nf_queue_entry_release_refs(entry);
198+ kfree_skb(entry->skb);
199+ kfree(entry);
200+ }
201+
202+ rcu_read_unlock();
203+}
204+
205+static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
206+{
207+ dev->stats.tx_bytes += skb->len;
208+ dev->stats.tx_packets++;
209+
210+ skb->imq_flags = 0;
211+ skb->destructor = NULL;
212+
213+ skb_restore_cb(skb); /* restore skb->cb */
214+
215+ dev->trans_start = jiffies;
216+ imq_nf_reinject(skb->nf_queue_entry, NF_ACCEPT);
217+ return 0;
218+}
219+
220+static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num)
221+{
222+ struct net_device *dev;
223+ struct sk_buff *skb_orig, *skb, *skb_shared;
224+ struct Qdisc *q;
225+ struct netdev_queue *txq;
226+ int users, index;
227+ int retval = -EINVAL;
228+
229+ index = entry->skb->imq_flags & IMQ_F_IFMASK;
230+ if (unlikely(index > numdevs - 1)) {
231+ if (net_ratelimit())
232+ printk(KERN_WARNING
233+ "IMQ: invalid device specified, highest is %u\n",
234+ numdevs - 1);
235+ retval = -EINVAL;
236+ goto out;
237+ }
238+
239+ /* check for imq device by index from cache */
240+ dev = imq_devs_cache[index];
241+ if (unlikely(!dev)) {
242+ char buf[8];
243+
244+ /* get device by name and cache result */
245+ snprintf(buf, sizeof(buf), "imq%d", index);
246+ dev = dev_get_by_name(&init_net, buf);
247+ if (!dev) {
248+ /* not found ?!*/
249+ BUG();
250+ retval = -ENODEV;
251+ goto out;
252+ }
253+
254+ imq_devs_cache[index] = dev;
255+ dev_put(dev);
256+ }
257+
258+ if (unlikely(!(dev->flags & IFF_UP))) {
259+ entry->skb->imq_flags = 0;
260+ imq_nf_reinject(entry, NF_ACCEPT);
261+ retval = 0;
262+ goto out;
263+ }
264+ dev->last_rx = jiffies;
265+
266+ skb = entry->skb;
267+ skb_orig = NULL;
268+
269+ /* skb has owner? => make clone */
270+ if (unlikely(skb->destructor)) {
271+ skb_orig = skb;
272+ skb = skb_clone(skb, GFP_ATOMIC);
273+ if (!skb) {
274+ retval = -ENOMEM;
275+ goto out;
276+ }
277+ entry->skb = skb;
278+ }
279+
280+ skb->nf_queue_entry = entry;
281+
282+ dev->stats.rx_bytes += skb->len;
283+ dev->stats.rx_packets++;
284+
285+ txq = dev_pick_tx(dev, skb);
286+
287+ q = rcu_dereference(txq->qdisc);
288+ if (unlikely(!q->enqueue))
289+ goto packet_not_eaten_by_imq_dev;
290+
291+ spin_lock_bh(qdisc_lock(q));
292+
293+ users = atomic_read(&skb->users);
294+
295+ skb_shared = skb_get(skb); /* increase reference count by one */
296+ skb_save_cb(skb_shared); /* backup skb->cb, as qdisc layer will
297+ overwrite it */
298+ qdisc_enqueue_root(skb_shared, q); /* might kfree_skb */
299+
300+ if (likely(atomic_read(&skb_shared->users) == users + 1)) {
301+ kfree_skb(skb_shared); /* decrease reference count by one */
302+
303+ skb->destructor = &imq_skb_destructor;
304+
305+ /* cloned? */
306+ if (skb_orig)
307+ kfree_skb(skb_orig); /* free original */
308+
309+ spin_unlock_bh(qdisc_lock(q));
310+
311+ /* schedule qdisc dequeue */
312+ __netif_schedule(q);
313+
314+ retval = 0;
315+ goto out;
316+ } else {
317+ skb_restore_cb(skb_shared); /* restore skb->cb */
318+ /* qdisc dropped packet and decreased skb reference count of
319+ * skb, so we don't really want to and try refree as that would
320+ * actually destroy the skb. */
321+ spin_unlock_bh(qdisc_lock(q));
322+ goto packet_not_eaten_by_imq_dev;
323+ }
324+
325+packet_not_eaten_by_imq_dev:
326+ /* cloned? restore original */
327+ if (skb_orig) {
328+ kfree_skb(skb);
329+ entry->skb = skb_orig;
330+ }
331+ retval = -1;
332+out:
333+ return retval;
334+}
335+
336+static struct nf_queue_handler nfqh = {
337+ .name = "imq",
338+ .outfn = imq_nf_queue,
339+};
340+
341+static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff *pskb,
342+ const struct net_device *indev,
343+ const struct net_device *outdev,
344+ int (*okfn)(struct sk_buff *))
345+{
346+ if (pskb->imq_flags & IMQ_F_ENQUEUE)
347+ return NF_QUEUE;
348+
349+ return NF_ACCEPT;
350+}
351+
352+static int imq_close(struct net_device *dev)
353+{
354+ netif_stop_queue(dev);
355+ return 0;
356+}
357+
358+static int imq_open(struct net_device *dev)
359+{
360+ netif_start_queue(dev);
361+ return 0;
362+}
363+
364+static void imq_setup(struct net_device *dev)
365+{
366+ dev->hard_start_xmit = imq_dev_xmit;
367+ dev->open = imq_open;
368+ dev->get_stats = imq_get_stats;
369+ dev->stop = imq_close;
370+ dev->type = ARPHRD_VOID;
371+ dev->mtu = 16000;
372+ dev->tx_queue_len = 11000;
373+ dev->flags = IFF_NOARP;
374+ dev->features = NETIF_F_SG | NETIF_F_FRAGLIST |
375+ NETIF_F_GSO | NETIF_F_HW_CSUM |
376+ NETIF_F_HIGHDMA;
377+}
378+
379+static int imq_validate(struct nlattr *tb[], struct nlattr *data[])
380+{
381+ int ret = 0;
382+
383+ if (tb[IFLA_ADDRESS]) {
384+ if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
385+ ret = -EINVAL;
386+ goto end;
387+ }
388+ if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
389+ ret = -EADDRNOTAVAIL;
390+ goto end;
391+ }
392+ }
393+ return 0;
394+end:
395+ printk(KERN_WARNING "IMQ: imq_validate failed (%d)\n", ret);
396+ return ret;
397+}
398+
399+static struct rtnl_link_ops imq_link_ops __read_mostly = {
400+ .kind = "imq",
401+ .priv_size = 0,
402+ .setup = imq_setup,
403+ .validate = imq_validate,
404+};
405+
406+static int __init imq_init_hooks(void)
407+{
408+ int err;
409+
410+ nf_register_queue_imq_handler(&nfqh);
411+
412+ err = nf_register_hook(&imq_ingress_ipv4);
413+ if (err)
414+ goto err1;
415+
416+ err = nf_register_hook(&imq_egress_ipv4);
417+ if (err)
418+ goto err2;
419+
420+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
421+ err = nf_register_hook(&imq_ingress_ipv6);
422+ if (err)
423+ goto err3;
424+
425+ err = nf_register_hook(&imq_egress_ipv6);
426+ if (err)
427+ goto err4;
428+#endif
429+
430+ return 0;
431+
432+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
433+err4:
434+ nf_unregister_hook(&imq_ingress_ipv6);
435+err3:
436+ nf_unregister_hook(&imq_egress_ipv4);
437+#endif
438+err2:
439+ nf_unregister_hook(&imq_ingress_ipv4);
440+err1:
441+ nf_unregister_queue_imq_handler();
442+ return err;
443+}
444+
445+static int __init imq_init_one(int index)
446+{
447+ struct net_device *dev;
448+ int ret;
449+
450+ dev = alloc_netdev(0, "imq%d", imq_setup);
451+ if (!dev)
452+ return -ENOMEM;
453+
454+ ret = dev_alloc_name(dev, dev->name);
455+ if (ret < 0)
456+ goto fail;
457+
458+ dev->rtnl_link_ops = &imq_link_ops;
459+ ret = register_netdevice(dev);
460+ if (ret < 0)
461+ goto fail;
462+
463+ return 0;
464+fail:
465+ free_netdev(dev);
466+ return ret;
467+}
468+
469+static int __init imq_init_devs(void)
470+{
471+ int err, i;
472+
473+ if (numdevs < 1 || numdevs > IMQ_MAX_DEVS) {
474+ printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n",
475+ IMQ_MAX_DEVS);
476+ return -EINVAL;
477+ }
478+
479+ rtnl_lock();
480+ err = __rtnl_link_register(&imq_link_ops);
481+
482+ for (i = 0; i < numdevs && !err; i++)
483+ err = imq_init_one(i);
484+
485+ if (err) {
486+ __rtnl_link_unregister(&imq_link_ops);
487+ memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
488+ }
489+ rtnl_unlock();
490+
491+ return err;
492+}
493+
494+static int __init imq_init_module(void)
495+{
496+ int err;
497+
498+#if defined(CONFIG_IMQ_NUM_DEVS)
499+ BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS > 16);
500+ BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS < 2);
501+ BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS - 1 > IMQ_F_IFMASK);
502+#endif
503+
504+ err = imq_init_devs();
505+ if (err) {
506+ printk(KERN_ERR "IMQ: Error trying imq_init_devs(net)\n");
507+ return err;
508+ }
509+
510+ err = imq_init_hooks();
511+ if (err) {
512+ printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
513+ rtnl_link_unregister(&imq_link_ops);
514+ memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
515+ return err;
516+ }
517+
518+ printk(KERN_INFO "IMQ driver loaded successfully.\n");
519+
520+#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
521+ printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n");
522+#else
523+ printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n");
524+#endif
525+#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
526+ printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n");
527+#else
528+ printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n");
529+#endif
530+
531+ return 0;
532+}
533+
534+static void __exit imq_unhook(void)
535+{
536+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
537+ nf_unregister_hook(&imq_ingress_ipv6);
538+ nf_unregister_hook(&imq_egress_ipv6);
539+#endif
540+ nf_unregister_hook(&imq_ingress_ipv4);
541+ nf_unregister_hook(&imq_egress_ipv4);
542+
543+ nf_unregister_queue_imq_handler();
544+}
545+
546+static void __exit imq_cleanup_devs(void)
547+{
548+ rtnl_link_unregister(&imq_link_ops);
549+ memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
550+}
551+
552+static void __exit imq_exit_module(void)
553+{
554+ imq_unhook();
555+ imq_cleanup_devs();
556+ printk(KERN_INFO "IMQ driver unloaded successfully.\n");
557+}
558+
559+module_init(imq_init_module);
560+module_exit(imq_exit_module);
561+
562+module_param(numdevs, int, 0);
563+MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will "
564+ "be created)");
565+MODULE_AUTHOR("http://www.linuximq.net");
566+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See "
567+ "http://www.linuximq.net/ for more information.");
568+MODULE_LICENSE("GPL");
569+MODULE_ALIAS_RTNL_LINK("imq");
570+
571diff -uNr --exclude='*~' linux-2.6.27.21/drivers/net/Kconfig linux-2.6.27.21-imq/drivers/net/Kconfig
572--- linux-2.6.27.21/drivers/net/Kconfig 2009-03-24 00:04:09.000000000 +0200
573+++ linux-2.6.27.21-imq/drivers/net/Kconfig 2009-04-20 23:48:35.702017146 +0300
574@@ -109,6 +109,129 @@
575 To compile this driver as a module, choose M here: the module
576 will be called eql. If unsure, say N.
577
578+config IMQ
579+ tristate "IMQ (intermediate queueing device) support"
580+ depends on NETDEVICES && NETFILTER
581+ ---help---
582+ The IMQ device(s) is used as placeholder for QoS queueing
583+ disciplines. Every packet entering/leaving the IP stack can be
584+ directed through the IMQ device where it's enqueued/dequeued to the
585+ attached qdisc. This allows you to treat network devices as classes
586+ and distribute bandwidth among them. Iptables is used to specify
587+ through which IMQ device, if any, packets travel.
588+
589+ More information at: http://www.linuximq.net/
590+
591+ To compile this driver as a module, choose M here: the module
592+ will be called imq. If unsure, say N.
593+
594+choice
595+ prompt "IMQ behavior (PRE/POSTROUTING)"
596+ depends on IMQ
597+ default IMQ_BEHAVIOR_AB
598+ help
599+
600+ This settings defines how IMQ behaves in respect to its
601+ hooking in PREROUTING and POSTROUTING.
602+
603+ IMQ can work in any of the following ways:
604+
605+ PREROUTING | POSTROUTING
606+ -----------------|-------------------
607+ #1 After NAT | After NAT
608+ #2 After NAT | Before NAT
609+ #3 Before NAT | After NAT
610+ #4 Before NAT | Before NAT
611+
612+ The default behavior is to hook before NAT on PREROUTING
613+ and after NAT on POSTROUTING (#3).
614+
615+ This settings are specially usefull when trying to use IMQ
616+ to shape NATed clients.
617+
618+ More information can be found at: www.linuximq.net
619+
620+ If not sure leave the default settings alone.
621+
622+config IMQ_BEHAVIOR_AA
623+ bool "IMQ AA"
624+ help
625+ This settings defines how IMQ behaves in respect to its
626+ hooking in PREROUTING and POSTROUTING.
627+
628+ Choosing this option will make IMQ hook like this:
629+
630+ PREROUTING: After NAT
631+ POSTROUTING: After NAT
632+
633+ More information can be found at: www.linuximq.net
634+
635+ If not sure leave the default settings alone.
636+
637+config IMQ_BEHAVIOR_AB
638+ bool "IMQ AB"
639+ help
640+ This settings defines how IMQ behaves in respect to its
641+ hooking in PREROUTING and POSTROUTING.
642+
643+ Choosing this option will make IMQ hook like this:
644+
645+ PREROUTING: After NAT
646+ POSTROUTING: Before NAT
647+
648+ More information can be found at: www.linuximq.net
649+
650+ If not sure leave the default settings alone.
651+
652+config IMQ_BEHAVIOR_BA
653+ bool "IMQ BA"
654+ help
655+ This settings defines how IMQ behaves in respect to its
656+ hooking in PREROUTING and POSTROUTING.
657+
658+ Choosing this option will make IMQ hook like this:
659+
660+ PREROUTING: Before NAT
661+ POSTROUTING: After NAT
662+
663+ More information can be found at: www.linuximq.net
664+
665+ If not sure leave the default settings alone.
666+
667+config IMQ_BEHAVIOR_BB
668+ bool "IMQ BB"
669+ help
670+ This settings defines how IMQ behaves in respect to its
671+ hooking in PREROUTING and POSTROUTING.
672+
673+ Choosing this option will make IMQ hook like this:
674+
675+ PREROUTING: Before NAT
676+ POSTROUTING: Before NAT
677+
678+ More information can be found at: www.linuximq.net
679+
680+ If not sure leave the default settings alone.
681+
682+endchoice
683+
684+config IMQ_NUM_DEVS
685+
686+ int "Number of IMQ devices"
687+ range 2 16
688+ depends on IMQ
689+ default "16"
690+ help
691+
692+ This settings defines how many IMQ devices will be
693+ created.
694+
695+ The default value is 16.
696+
697+ More information can be found at: www.linuximq.net
698+
699+ If not sure leave the default settings alone.
700+
701 config TUN
702 tristate "Universal TUN/TAP device driver support"
703 select CRC32
704diff -uNr --exclude='*~' linux-2.6.27.21/drivers/net/Makefile linux-2.6.27.21-imq/drivers/net/Makefile
705--- linux-2.6.27.21/drivers/net/Makefile 2009-03-24 00:04:09.000000000 +0200
706+++ linux-2.6.27.21-imq/drivers/net/Makefile 2009-04-20 23:48:35.702017146 +0300
707@@ -144,6 +144,7 @@
708 obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
709
710 obj-$(CONFIG_DUMMY) += dummy.o
711+obj-$(CONFIG_IMQ) += imq.o
712 obj-$(CONFIG_IFB) += ifb.o
713 obj-$(CONFIG_MACVLAN) += macvlan.o
714 obj-$(CONFIG_DE600) += de600.o
715diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/imq.h linux-2.6.27.21-imq/include/linux/imq.h
716--- linux-2.6.27.21/include/linux/imq.h 1970-01-01 02:00:00.000000000 +0200
717+++ linux-2.6.27.21-imq/include/linux/imq.h 2009-04-20 23:48:35.702017146 +0300
718@@ -0,0 +1,13 @@
719+#ifndef _IMQ_H
720+#define _IMQ_H
721+
722+/* IFMASK (16 device indexes, 0 to 15) and flag(s) fit in 5 bits */
723+#define IMQ_F_BITS 5
724+
725+#define IMQ_F_IFMASK 0x0f
726+#define IMQ_F_ENQUEUE 0x10
727+
728+#define IMQ_MAX_DEVS (IMQ_F_IFMASK + 1)
729+
730+#endif /* _IMQ_H */
731+
732diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/netdevice.h linux-2.6.27.21-imq/include/linux/netdevice.h
733--- linux-2.6.27.21/include/linux/netdevice.h 2009-03-24 00:04:09.000000000 +0200
734+++ linux-2.6.27.21-imq/include/linux/netdevice.h 2009-04-20 23:48:35.703017245 +0300
735@@ -915,6 +915,7 @@
736 extern int dev_open(struct net_device *dev);
737 extern int dev_close(struct net_device *dev);
738 extern void dev_disable_lro(struct net_device *dev);
739+extern struct netdev_queue *dev_pick_tx(struct net_device *dev, struct sk_buff *skb);
740 extern int dev_queue_xmit(struct sk_buff *skb);
741 extern int register_netdevice(struct net_device *dev);
742 extern void unregister_netdevice(struct net_device *dev);
743diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/netfilter/xt_IMQ.h linux-2.6.27.21-imq/include/linux/netfilter/xt_IMQ.h
744--- linux-2.6.27.21/include/linux/netfilter/xt_IMQ.h 1970-01-01 02:00:00.000000000 +0200
745+++ linux-2.6.27.21-imq/include/linux/netfilter/xt_IMQ.h 2009-04-20 23:48:35.703017245 +0300
746@@ -0,0 +1,9 @@
747+#ifndef _XT_IMQ_H
748+#define _XT_IMQ_H
749+
750+struct xt_imq_info {
751+ unsigned int todev; /* target imq device */
752+};
753+
754+#endif /* _XT_IMQ_H */
755+
756diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/netfilter_ipv4/ipt_IMQ.h linux-2.6.27.21-imq/include/linux/netfilter_ipv4/ipt_IMQ.h
757--- linux-2.6.27.21/include/linux/netfilter_ipv4/ipt_IMQ.h 1970-01-01 02:00:00.000000000 +0200
758+++ linux-2.6.27.21-imq/include/linux/netfilter_ipv4/ipt_IMQ.h 2009-04-20 23:48:35.703017245 +0300
759@@ -0,0 +1,10 @@
760+#ifndef _IPT_IMQ_H
761+#define _IPT_IMQ_H
762+
763+/* Backwards compatibility for old userspace */
764+#include <linux/netfilter/xt_IMQ.h>
765+
766+#define ipt_imq_info xt_imq_info
767+
768+#endif /* _IPT_IMQ_H */
769+
770diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/netfilter_ipv6/ip6t_IMQ.h linux-2.6.27.21-imq/include/linux/netfilter_ipv6/ip6t_IMQ.h
771--- linux-2.6.27.21/include/linux/netfilter_ipv6/ip6t_IMQ.h 1970-01-01 02:00:00.000000000 +0200
772+++ linux-2.6.27.21-imq/include/linux/netfilter_ipv6/ip6t_IMQ.h 2009-04-20 23:48:35.704017144 +0300
773@@ -0,0 +1,10 @@
774+#ifndef _IP6T_IMQ_H
775+#define _IP6T_IMQ_H
776+
777+/* Backwards compatibility for old userspace */
778+#include <linux/netfilter/xt_IMQ.h>
779+
780+#define ip6t_imq_info xt_imq_info
781+
782+#endif /* _IP6T_IMQ_H */
783+
784diff -uNr --exclude='*~' linux-2.6.27.21/include/linux/skbuff.h linux-2.6.27.21-imq/include/linux/skbuff.h
785--- linux-2.6.27.21/include/linux/skbuff.h 2009-03-24 00:04:09.000000000 +0200
786+++ linux-2.6.27.21-imq/include/linux/skbuff.h 2009-04-20 23:48:35.704017144 +0300
787@@ -28,6 +28,9 @@
788 #include <linux/rcupdate.h>
789 #include <linux/dmaengine.h>
790 #include <linux/hrtimer.h>
791+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
792+#include <linux/imq.h>
793+#endif
794
795 #define HAVE_ALLOC_SKB /* For the drivers to know */
796 #define HAVE_ALIGNABLE_SKB /* Ditto 8) */
797@@ -272,6 +275,9 @@
798 * first. This is owned by whoever has the skb queued ATM.
799 */
800 char cb[48];
801+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
802+ void *cb_next;
803+#endif
804
805 unsigned int len,
806 data_len;
807@@ -302,6 +308,9 @@
808 struct nf_conntrack *nfct;
809 struct sk_buff *nfct_reasm;
810 #endif
811+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
812+ struct nf_queue_entry *nf_queue_entry;
813+#endif
814 #ifdef CONFIG_BRIDGE_NETFILTER
815 struct nf_bridge_info *nf_bridge;
816 #endif
817@@ -321,6 +330,9 @@
818 __u8 do_not_encrypt:1;
819 #endif
820 /* 0/13/14 bit hole */
821+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
822+ __u8 imq_flags:IMQ_F_BITS;
823+#endif
824
825 #ifdef CONFIG_NET_DMA
826 dma_cookie_t dma_cookie;
827@@ -353,6 +365,12 @@
828
829 #include <asm/system.h>
830
831+
832+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
833+extern int skb_save_cb(struct sk_buff *skb);
834+extern int skb_restore_cb(struct sk_buff *skb);
835+#endif
836+
837 extern void kfree_skb(struct sk_buff *skb);
838 extern void __kfree_skb(struct sk_buff *skb);
839 extern struct sk_buff *__alloc_skb(unsigned int size,
840@@ -1633,6 +1651,10 @@
841 dst->nfct_reasm = src->nfct_reasm;
842 nf_conntrack_get_reasm(src->nfct_reasm);
843 #endif
844+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
845+ dst->imq_flags = src->imq_flags;
846+ dst->nf_queue_entry = src->nf_queue_entry;
847+#endif
848 #ifdef CONFIG_BRIDGE_NETFILTER
849 dst->nf_bridge = src->nf_bridge;
850 nf_bridge_get(src->nf_bridge);
851diff -uNr --exclude='*~' linux-2.6.27.21/include/net/netfilter/nf_queue.h linux-2.6.27.21-imq/include/net/netfilter/nf_queue.h
852--- linux-2.6.27.21/include/net/netfilter/nf_queue.h 2009-03-24 00:04:09.000000000 +0200
853+++ linux-2.6.27.21-imq/include/net/netfilter/nf_queue.h 2009-04-20 23:48:35.704017144 +0300
854@@ -13,6 +13,12 @@
855 struct net_device *indev;
856 struct net_device *outdev;
857 int (*okfn)(struct sk_buff *);
858+
859+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
860+ int (*next_outfn)(struct nf_queue_entry *entry,
861+ unsigned int queuenum);
862+ unsigned int next_queuenum;
863+#endif
864 };
865
866 #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry))
867@@ -30,5 +36,11 @@
868 const struct nf_queue_handler *qh);
869 extern void nf_unregister_queue_handlers(const struct nf_queue_handler *qh);
870 extern void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
871+extern void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
872+
873+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
874+extern void nf_register_queue_imq_handler(const struct nf_queue_handler *qh);
875+extern void nf_unregister_queue_imq_handler(void);
876+#endif
877
878 #endif /* _NF_QUEUE_H */
879diff -uNr --exclude='*~' linux-2.6.27.21/net/core/dev.c linux-2.6.27.21-imq/net/core/dev.c
880--- linux-2.6.27.21/net/core/dev.c 2009-03-24 00:04:09.000000000 +0200
881+++ linux-2.6.27.21-imq/net/core/dev.c 2009-04-20 23:48:35.706016975 +0300
882@@ -96,6 +96,9 @@
883 #include <net/net_namespace.h>
884 #include <net/sock.h>
885 #include <linux/rtnetlink.h>
886+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
887+#include <linux/imq.h>
888+#endif
889 #include <linux/proc_fs.h>
890 #include <linux/seq_file.h>
891 #include <linux/stat.h>
892@@ -1624,7 +1627,11 @@
893 struct netdev_queue *txq)
894 {
895 if (likely(!skb->next)) {
896- if (!list_empty(&ptype_all))
897+ if (!list_empty(&ptype_all)
898+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
899+ && !(skb->imq_flags & IMQ_F_ENQUEUE)
900+#endif
901+ )
902 dev_queue_xmit_nit(skb, dev);
903
904 if (netif_needs_gso(dev, skb)) {
905@@ -1715,8 +1722,7 @@
906 return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
907 }
908
909-static struct netdev_queue *dev_pick_tx(struct net_device *dev,
910- struct sk_buff *skb)
911+struct netdev_queue *dev_pick_tx(struct net_device *dev, struct sk_buff *skb)
912 {
913 u16 queue_index = 0;
914
915@@ -1728,6 +1734,7 @@
916 skb_set_queue_mapping(skb, queue_index);
917 return netdev_get_tx_queue(dev, queue_index);
918 }
919+EXPORT_SYMBOL(dev_pick_tx);
920
921 /**
922 * dev_queue_xmit - transmit a buffer
923diff -uNr --exclude='*~' linux-2.6.27.21/net/core/skbuff.c linux-2.6.27.21-imq/net/core/skbuff.c
924--- linux-2.6.27.21/net/core/skbuff.c 2009-03-24 00:04:09.000000000 +0200
925+++ linux-2.6.27.21-imq/net/core/skbuff.c 2009-04-20 23:48:35.707017089 +0300
926@@ -69,6 +69,9 @@
927
928 static struct kmem_cache *skbuff_head_cache __read_mostly;
929 static struct kmem_cache *skbuff_fclone_cache __read_mostly;
930+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
931+static struct kmem_cache *skbuff_cb_store_cache __read_mostly;
932+#endif
933
934 static void sock_pipe_buf_release(struct pipe_inode_info *pipe,
935 struct pipe_buffer *buf)
936@@ -88,6 +91,80 @@
937 return 1;
938 }
939
940+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
941+/* Control buffer save/restore for IMQ devices */
942+struct skb_cb_table {
943+ void *cb_next;
944+ atomic_t refcnt;
945+ char cb[48];
946+};
947+
948+static DEFINE_SPINLOCK(skb_cb_store_lock);
949+
950+int skb_save_cb(struct sk_buff *skb)
951+{
952+ struct skb_cb_table *next;
953+
954+ next = kmem_cache_alloc(skbuff_cb_store_cache, GFP_ATOMIC);
955+ if (!next)
956+ return -ENOMEM;
957+
958+ BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
959+
960+ memcpy(next->cb, skb->cb, sizeof(skb->cb));
961+ next->cb_next = skb->cb_next;
962+
963+ atomic_set(&next->refcnt, 1);
964+
965+ skb->cb_next = next;
966+ return 0;
967+}
968+EXPORT_SYMBOL(skb_save_cb);
969+
970+int skb_restore_cb(struct sk_buff *skb)
971+{
972+ struct skb_cb_table *next;
973+
974+ if (!skb->cb_next)
975+ return 0;
976+
977+ next = skb->cb_next;
978+
979+ BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
980+
981+ memcpy(skb->cb, next->cb, sizeof(skb->cb));
982+ skb->cb_next = next->cb_next;
983+
984+ spin_lock(&skb_cb_store_lock);
985+
986+ if (atomic_dec_and_test(&next->refcnt)) {
987+ kmem_cache_free(skbuff_cb_store_cache, next);
988+ }
989+
990+ spin_unlock(&skb_cb_store_lock);
991+
992+ return 0;
993+}
994+EXPORT_SYMBOL(skb_restore_cb);
995+
996+static void skb_copy_stored_cb(struct sk_buff *new, struct sk_buff *old)
997+{
998+ struct skb_cb_table *next;
999+
1000+ if (!old->cb_next) {
1001+ new->cb_next = 0;
1002+ return;
1003+ }
1004+
1005+ spin_lock(&skb_cb_store_lock);
1006+
1007+ next = old->cb_next;
1008+ atomic_inc(&next->refcnt);
1009+ new->cb_next = next;
1010+
1011+ spin_unlock(&skb_cb_store_lock);
1012+}
1013+#endif
1014
1015 /* Pipe buffer operations for a socket. */
1016 static struct pipe_buf_operations sock_pipe_buf_ops = {
1017@@ -362,6 +439,15 @@
1018 WARN_ON(in_irq());
1019 skb->destructor(skb);
1020 }
1021+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1022+ /* This should not happen. When it does, avoid memleak by restoring
1023+ the chain of cb-backups. */
1024+ while(skb->cb_next != NULL) {
1025+ printk(KERN_WARNING "kfree_skb: skb->cb_next: %08x\n",
1026+ skb->cb_next);
1027+ skb_restore_cb(skb);
1028+ }
1029+#endif
1030 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1031 nf_conntrack_put(skb->nfct);
1032 nf_conntrack_put_reasm(skb->nfct_reasm);
1033@@ -424,6 +510,9 @@
1034 new->sp = secpath_get(old->sp);
1035 #endif
1036 memcpy(new->cb, old->cb, sizeof(old->cb));
1037+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1038+ skb_copy_stored_cb(new, old);
1039+#endif
1040 new->csum_start = old->csum_start;
1041 new->csum_offset = old->csum_offset;
1042 new->local_df = old->local_df;
1043@@ -2326,6 +2415,13 @@
1044 0,
1045 SLAB_HWCACHE_ALIGN|SLAB_PANIC,
1046 NULL);
1047+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1048+ skbuff_cb_store_cache = kmem_cache_create("skbuff_cb_store_cache",
1049+ sizeof(struct skb_cb_table),
1050+ 0,
1051+ SLAB_HWCACHE_ALIGN|SLAB_PANIC,
1052+ NULL);
1053+#endif
1054 }
1055
1056 /**
1057diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/Kconfig linux-2.6.27.21-imq/net/netfilter/Kconfig
1058--- linux-2.6.27.21/net/netfilter/Kconfig 2009-03-24 00:04:09.000000000 +0200
1059+++ linux-2.6.27.21-imq/net/netfilter/Kconfig 2009-04-20 23:48:35.707017089 +0300
1060@@ -342,6 +342,18 @@
1061
1062 To compile it as a module, choose M here. If unsure, say N.
1063
1064+config NETFILTER_XT_TARGET_IMQ
1065+ tristate '"IMQ" target support'
1066+ depends on NETFILTER_XTABLES
1067+ depends on IP_NF_MANGLE || IP6_NF_MANGLE
1068+ select IMQ
1069+ default m if NETFILTER_ADVANCED=n
1070+ help
1071+ This option adds a `IMQ' target which is used to specify if and
1072+ to which imq device packets should get enqueued/dequeued.
1073+
1074+ To compile it as a module, choose M here. If unsure, say N.
1075+
1076 config NETFILTER_XT_TARGET_MARK
1077 tristate '"MARK" target support'
1078 depends on NETFILTER_XTABLES
1079diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/Makefile linux-2.6.27.21-imq/net/netfilter/Makefile
1080--- linux-2.6.27.21/net/netfilter/Makefile 2009-03-24 00:04:09.000000000 +0200
1081+++ linux-2.6.27.21-imq/net/netfilter/Makefile 2009-04-20 23:48:35.707017089 +0300
1082@@ -42,6 +42,7 @@
1083 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
1084 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
1085 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
1086+obj-$(CONFIG_NETFILTER_XT_TARGET_IMQ) += xt_IMQ.o
1087 obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o
1088 obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
1089 obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
1090diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/nf_queue.c linux-2.6.27.21-imq/net/netfilter/nf_queue.c
1091--- linux-2.6.27.21/net/netfilter/nf_queue.c 2009-03-24 00:04:09.000000000 +0200
1092+++ linux-2.6.27.21-imq/net/netfilter/nf_queue.c 2009-04-20 23:48:35.708017126 +0300
1093@@ -20,6 +20,26 @@
1094
1095 static DEFINE_MUTEX(queue_handler_mutex);
1096
1097+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1098+static const struct nf_queue_handler *queue_imq_handler;
1099+
1100+void nf_register_queue_imq_handler(const struct nf_queue_handler *qh)
1101+{
1102+ mutex_lock(&queue_handler_mutex);
1103+ rcu_assign_pointer(queue_imq_handler, qh);
1104+ mutex_unlock(&queue_handler_mutex);
1105+}
1106+EXPORT_SYMBOL(nf_register_queue_imq_handler);
1107+
1108+void nf_unregister_queue_imq_handler(void)
1109+{
1110+ mutex_lock(&queue_handler_mutex);
1111+ rcu_assign_pointer(queue_imq_handler, NULL);
1112+ mutex_unlock(&queue_handler_mutex);
1113+}
1114+EXPORT_SYMBOL(nf_unregister_queue_imq_handler);
1115+#endif
1116+
1117 /* return EBUSY when somebody else is registered, return EEXIST if the
1118 * same handler is registered, return 0 in case of success. */
1119 int nf_register_queue_handler(int pf, const struct nf_queue_handler *qh)
1120@@ -80,7 +100,7 @@
1121 }
1122 EXPORT_SYMBOL_GPL(nf_unregister_queue_handlers);
1123
1124-static void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
1125+void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
1126 {
1127 /* Release those devices we held, or Alexey will kill me. */
1128 if (entry->indev)
1129@@ -100,6 +120,7 @@
1130 /* Drop reference to owner of hook which queued us. */
1131 module_put(entry->elem->owner);
1132 }
1133+EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
1134
1135 /*
1136 * Any packet that leaves via this function must come back
1137@@ -121,12 +142,26 @@
1138 #endif
1139 const struct nf_afinfo *afinfo;
1140 const struct nf_queue_handler *qh;
1141+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1142+ const struct nf_queue_handler *qih = NULL;
1143+#endif
1144
1145 /* QUEUE == DROP if noone is waiting, to be safe. */
1146 rcu_read_lock();
1147
1148 qh = rcu_dereference(queue_handler[pf]);
1149+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1150+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1151+ if (pf == PF_INET || pf == PF_INET6)
1152+#else
1153+ if (pf == PF_INET)
1154+#endif
1155+ qih = rcu_dereference(queue_imq_handler);
1156+
1157+ if (!qh && !qih)
1158+#else /* !IMQ */
1159 if (!qh)
1160+#endif
1161 goto err_unlock;
1162
1163 afinfo = nf_get_afinfo(pf);
1164@@ -145,6 +180,10 @@
1165 .indev = indev,
1166 .outdev = outdev,
1167 .okfn = okfn,
1168+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1169+ .next_outfn = qh ? qh->outfn : NULL,
1170+ .next_queuenum = queuenum,
1171+#endif
1172 };
1173
1174 /* If it's going away, ignore hook. */
1175@@ -170,8 +209,19 @@
1176 }
1177 #endif
1178 afinfo->saveroute(skb, entry);
1179+
1180+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1181+ if (qih) {
1182+ status = qih->outfn(entry, queuenum);
1183+ goto imq_skip_queue;
1184+ }
1185+#endif
1186+
1187 status = qh->outfn(entry, queuenum);
1188
1189+#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1190+imq_skip_queue:
1191+#endif
1192 rcu_read_unlock();
1193
1194 if (status < 0) {
1195diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/xt_IMQ.c linux-2.6.27.21-imq/net/netfilter/xt_IMQ.c
1196--- linux-2.6.27.21/net/netfilter/xt_IMQ.c 1970-01-01 02:00:00.000000000 +0200
1197+++ linux-2.6.27.21-imq/net/netfilter/xt_IMQ.c 2009-04-20 23:48:35.708017126 +0300
1198@@ -0,0 +1,81 @@
1199+/*
1200+ * This target marks packets to be enqueued to an imq device
1201+ */
1202+#include <linux/module.h>
1203+#include <linux/skbuff.h>
1204+#include <linux/netfilter/x_tables.h>
1205+#include <linux/netfilter/xt_IMQ.h>
1206+#include <linux/imq.h>
1207+
1208+static unsigned int imq_target(struct sk_buff *pskb,
1209+ const struct net_device *in,
1210+ const struct net_device *out,
1211+ unsigned int hooknum,
1212+ const struct xt_target *target,
1213+ const void *targinfo)
1214+{
1215+ const struct xt_imq_info *mr = targinfo;
1216+
1217+ pskb->imq_flags = (mr->todev & IMQ_F_IFMASK) | IMQ_F_ENQUEUE;
1218+
1219+ return XT_CONTINUE;
1220+}
1221+
1222+static bool imq_checkentry(const char *tablename,
1223+ const void *entry,
1224+ const struct xt_target *target,
1225+ void *targinfo,
1226+ unsigned int hook_mask)
1227+{
1228+ struct xt_imq_info *mr = targinfo;
1229+
1230+ if (mr->todev > IMQ_MAX_DEVS - 1) {
1231+ printk(KERN_WARNING
1232+ "IMQ: invalid device specified, highest is %u\n",
1233+ IMQ_MAX_DEVS - 1);
1234+ return 0;
1235+ }
1236+
1237+ return 1;
1238+}
1239+
1240+static struct xt_target xt_imq_reg[] __read_mostly = {
1241+ {
1242+ .name = "IMQ",
1243+ .family = AF_INET,
1244+ .target = imq_target,
1245+ .targetsize = sizeof(struct xt_imq_info),
1246+ .table = "mangle",
1247+ .checkentry = imq_checkentry,
1248+ .me = THIS_MODULE
1249+ },
1250+ {
1251+ .name = "IMQ",
1252+ .family = AF_INET6,
1253+ .target = imq_target,
1254+ .targetsize = sizeof(struct xt_imq_info),
1255+ .table = "mangle",
1256+ .checkentry = imq_checkentry,
1257+ .me = THIS_MODULE
1258+ },
1259+};
1260+
1261+static int __init imq_init(void)
1262+{
1263+ return xt_register_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1264+}
1265+
1266+static void __exit imq_fini(void)
1267+{
1268+ xt_unregister_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1269+}
1270+
1271+module_init(imq_init);
1272+module_exit(imq_fini);
1273+
1274+MODULE_AUTHOR("http://www.linuximq.net");
1275+MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
1276+MODULE_LICENSE("GPL");
1277+MODULE_ALIAS("ipt_IMQ");
1278+MODULE_ALIAS("ip6t_IMQ");
1279+