]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/linux-2.6.27.21-imq-test3-xen.patch
f9401dbf8eb75ef9c8cad16ac59304a563312037
[people/pmueller/ipfire-2.x.git] / src / patches / linux-2.6.27.21-imq-test3-xen.patch
1 diff -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 +
571 diff -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
704 diff -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
715 diff -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 +
732 diff -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);
743 diff -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 +
756 diff -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 +
770 diff -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 +
784 diff -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
785 --- linux-2.6.27.21/include/net/netfilter/nf_queue.h 2009-03-24 00:04:09.000000000 +0200
786 +++ linux-2.6.27.21-imq/include/net/netfilter/nf_queue.h 2009-04-20 23:48:35.704017144 +0300
787 @@ -13,6 +13,12 @@
788 struct net_device *indev;
789 struct net_device *outdev;
790 int (*okfn)(struct sk_buff *);
791 +
792 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
793 + int (*next_outfn)(struct nf_queue_entry *entry,
794 + unsigned int queuenum);
795 + unsigned int next_queuenum;
796 +#endif
797 };
798
799 #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry))
800 @@ -30,5 +36,11 @@
801 const struct nf_queue_handler *qh);
802 extern void nf_unregister_queue_handlers(const struct nf_queue_handler *qh);
803 extern void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
804 +extern void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
805 +
806 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
807 +extern void nf_register_queue_imq_handler(const struct nf_queue_handler *qh);
808 +extern void nf_unregister_queue_imq_handler(void);
809 +#endif
810
811 #endif /* _NF_QUEUE_H */
812 diff -uNr --exclude='*~' linux-2.6.27.21/net/core/dev.c linux-2.6.27.21-imq/net/core/dev.c
813 --- linux-2.6.27.21/net/core/dev.c 2009-03-24 00:04:09.000000000 +0200
814 +++ linux-2.6.27.21-imq/net/core/dev.c 2009-04-20 23:48:35.706016975 +0300
815 @@ -96,6 +96,9 @@
816 #include <net/net_namespace.h>
817 #include <net/sock.h>
818 #include <linux/rtnetlink.h>
819 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
820 +#include <linux/imq.h>
821 +#endif
822 #include <linux/proc_fs.h>
823 #include <linux/seq_file.h>
824 #include <linux/stat.h>
825 @@ -1624,7 +1627,11 @@
826 struct netdev_queue *txq)
827 {
828 if (likely(!skb->next)) {
829 - if (!list_empty(&ptype_all))
830 + if (!list_empty(&ptype_all)
831 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
832 + && !(skb->imq_flags & IMQ_F_ENQUEUE)
833 +#endif
834 + )
835 dev_queue_xmit_nit(skb, dev);
836
837 if (netif_needs_gso(dev, skb)) {
838 @@ -1715,8 +1722,7 @@
839 return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
840 }
841
842 -static struct netdev_queue *dev_pick_tx(struct net_device *dev,
843 - struct sk_buff *skb)
844 +struct netdev_queue *dev_pick_tx(struct net_device *dev, struct sk_buff *skb)
845 {
846 u16 queue_index = 0;
847
848 @@ -1728,6 +1734,7 @@
849 skb_set_queue_mapping(skb, queue_index);
850 return netdev_get_tx_queue(dev, queue_index);
851 }
852 +EXPORT_SYMBOL(dev_pick_tx);
853
854 /**
855 * dev_queue_xmit - transmit a buffer
856 diff -uNr --exclude='*~' linux-2.6.27.21/net/core/skbuff.c linux-2.6.27.21-imq/net/core/skbuff.c
857 --- linux-2.6.27.21/net/core/skbuff.c 2009-03-24 00:04:09.000000000 +0200
858 +++ linux-2.6.27.21-imq/net/core/skbuff.c 2009-04-20 23:48:35.707017089 +0300
859 @@ -69,6 +69,9 @@
860
861 static struct kmem_cache *skbuff_head_cache __read_mostly;
862 static struct kmem_cache *skbuff_fclone_cache __read_mostly;
863 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
864 +static struct kmem_cache *skbuff_cb_store_cache __read_mostly;
865 +#endif
866
867 static void sock_pipe_buf_release(struct pipe_inode_info *pipe,
868 struct pipe_buffer *buf)
869 @@ -88,6 +91,80 @@
870 return 1;
871 }
872
873 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
874 +/* Control buffer save/restore for IMQ devices */
875 +struct skb_cb_table {
876 + void *cb_next;
877 + atomic_t refcnt;
878 + char cb[48];
879 +};
880 +
881 +static DEFINE_SPINLOCK(skb_cb_store_lock);
882 +
883 +int skb_save_cb(struct sk_buff *skb)
884 +{
885 + struct skb_cb_table *next;
886 +
887 + next = kmem_cache_alloc(skbuff_cb_store_cache, GFP_ATOMIC);
888 + if (!next)
889 + return -ENOMEM;
890 +
891 + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
892 +
893 + memcpy(next->cb, skb->cb, sizeof(skb->cb));
894 + next->cb_next = skb->cb_next;
895 +
896 + atomic_set(&next->refcnt, 1);
897 +
898 + skb->cb_next = next;
899 + return 0;
900 +}
901 +EXPORT_SYMBOL(skb_save_cb);
902 +
903 +int skb_restore_cb(struct sk_buff *skb)
904 +{
905 + struct skb_cb_table *next;
906 +
907 + if (!skb->cb_next)
908 + return 0;
909 +
910 + next = skb->cb_next;
911 +
912 + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
913 +
914 + memcpy(skb->cb, next->cb, sizeof(skb->cb));
915 + skb->cb_next = next->cb_next;
916 +
917 + spin_lock(&skb_cb_store_lock);
918 +
919 + if (atomic_dec_and_test(&next->refcnt)) {
920 + kmem_cache_free(skbuff_cb_store_cache, next);
921 + }
922 +
923 + spin_unlock(&skb_cb_store_lock);
924 +
925 + return 0;
926 +}
927 +EXPORT_SYMBOL(skb_restore_cb);
928 +
929 +static void skb_copy_stored_cb(struct sk_buff *new, struct sk_buff *old)
930 +{
931 + struct skb_cb_table *next;
932 +
933 + if (!old->cb_next) {
934 + new->cb_next = 0;
935 + return;
936 + }
937 +
938 + spin_lock(&skb_cb_store_lock);
939 +
940 + next = old->cb_next;
941 + atomic_inc(&next->refcnt);
942 + new->cb_next = next;
943 +
944 + spin_unlock(&skb_cb_store_lock);
945 +}
946 +#endif
947
948 /* Pipe buffer operations for a socket. */
949 static struct pipe_buf_operations sock_pipe_buf_ops = {
950 @@ -362,6 +439,15 @@
951 WARN_ON(in_irq());
952 skb->destructor(skb);
953 }
954 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
955 + /* This should not happen. When it does, avoid memleak by restoring
956 + the chain of cb-backups. */
957 + while(skb->cb_next != NULL) {
958 + printk(KERN_WARNING "kfree_skb: skb->cb_next: %08x\n",
959 + skb->cb_next);
960 + skb_restore_cb(skb);
961 + }
962 +#endif
963 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
964 nf_conntrack_put(skb->nfct);
965 nf_conntrack_put_reasm(skb->nfct_reasm);
966 @@ -424,6 +510,9 @@
967 new->sp = secpath_get(old->sp);
968 #endif
969 memcpy(new->cb, old->cb, sizeof(old->cb));
970 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
971 + skb_copy_stored_cb(new, old);
972 +#endif
973 new->csum_start = old->csum_start;
974 new->csum_offset = old->csum_offset;
975 new->local_df = old->local_df;
976 @@ -2326,6 +2415,13 @@
977 0,
978 SLAB_HWCACHE_ALIGN|SLAB_PANIC,
979 NULL);
980 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
981 + skbuff_cb_store_cache = kmem_cache_create("skbuff_cb_store_cache",
982 + sizeof(struct skb_cb_table),
983 + 0,
984 + SLAB_HWCACHE_ALIGN|SLAB_PANIC,
985 + NULL);
986 +#endif
987 }
988
989 /**
990 diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/Kconfig linux-2.6.27.21-imq/net/netfilter/Kconfig
991 --- linux-2.6.27.21/net/netfilter/Kconfig 2009-03-24 00:04:09.000000000 +0200
992 +++ linux-2.6.27.21-imq/net/netfilter/Kconfig 2009-04-20 23:48:35.707017089 +0300
993 @@ -342,6 +342,18 @@
994
995 To compile it as a module, choose M here. If unsure, say N.
996
997 +config NETFILTER_XT_TARGET_IMQ
998 + tristate '"IMQ" target support'
999 + depends on NETFILTER_XTABLES
1000 + depends on IP_NF_MANGLE || IP6_NF_MANGLE
1001 + select IMQ
1002 + default m if NETFILTER_ADVANCED=n
1003 + help
1004 + This option adds a `IMQ' target which is used to specify if and
1005 + to which imq device packets should get enqueued/dequeued.
1006 +
1007 + To compile it as a module, choose M here. If unsure, say N.
1008 +
1009 config NETFILTER_XT_TARGET_MARK
1010 tristate '"MARK" target support'
1011 depends on NETFILTER_XTABLES
1012 diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/Makefile linux-2.6.27.21-imq/net/netfilter/Makefile
1013 --- linux-2.6.27.21/net/netfilter/Makefile 2009-03-24 00:04:09.000000000 +0200
1014 +++ linux-2.6.27.21-imq/net/netfilter/Makefile 2009-04-20 23:48:35.707017089 +0300
1015 @@ -42,6 +42,7 @@
1016 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
1017 obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o
1018 obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
1019 +obj-$(CONFIG_NETFILTER_XT_TARGET_IMQ) += xt_IMQ.o
1020 obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o
1021 obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
1022 obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
1023 diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/nf_queue.c linux-2.6.27.21-imq/net/netfilter/nf_queue.c
1024 --- linux-2.6.27.21/net/netfilter/nf_queue.c 2009-03-24 00:04:09.000000000 +0200
1025 +++ linux-2.6.27.21-imq/net/netfilter/nf_queue.c 2009-04-20 23:48:35.708017126 +0300
1026 @@ -20,6 +20,26 @@
1027
1028 static DEFINE_MUTEX(queue_handler_mutex);
1029
1030 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1031 +static const struct nf_queue_handler *queue_imq_handler;
1032 +
1033 +void nf_register_queue_imq_handler(const struct nf_queue_handler *qh)
1034 +{
1035 + mutex_lock(&queue_handler_mutex);
1036 + rcu_assign_pointer(queue_imq_handler, qh);
1037 + mutex_unlock(&queue_handler_mutex);
1038 +}
1039 +EXPORT_SYMBOL(nf_register_queue_imq_handler);
1040 +
1041 +void nf_unregister_queue_imq_handler(void)
1042 +{
1043 + mutex_lock(&queue_handler_mutex);
1044 + rcu_assign_pointer(queue_imq_handler, NULL);
1045 + mutex_unlock(&queue_handler_mutex);
1046 +}
1047 +EXPORT_SYMBOL(nf_unregister_queue_imq_handler);
1048 +#endif
1049 +
1050 /* return EBUSY when somebody else is registered, return EEXIST if the
1051 * same handler is registered, return 0 in case of success. */
1052 int nf_register_queue_handler(int pf, const struct nf_queue_handler *qh)
1053 @@ -80,7 +100,7 @@
1054 }
1055 EXPORT_SYMBOL_GPL(nf_unregister_queue_handlers);
1056
1057 -static void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
1058 +void nf_queue_entry_release_refs(struct nf_queue_entry *entry)
1059 {
1060 /* Release those devices we held, or Alexey will kill me. */
1061 if (entry->indev)
1062 @@ -100,6 +120,7 @@
1063 /* Drop reference to owner of hook which queued us. */
1064 module_put(entry->elem->owner);
1065 }
1066 +EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs);
1067
1068 /*
1069 * Any packet that leaves via this function must come back
1070 @@ -121,12 +142,26 @@
1071 #endif
1072 const struct nf_afinfo *afinfo;
1073 const struct nf_queue_handler *qh;
1074 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1075 + const struct nf_queue_handler *qih = NULL;
1076 +#endif
1077
1078 /* QUEUE == DROP if noone is waiting, to be safe. */
1079 rcu_read_lock();
1080
1081 qh = rcu_dereference(queue_handler[pf]);
1082 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1083 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
1084 + if (pf == PF_INET || pf == PF_INET6)
1085 +#else
1086 + if (pf == PF_INET)
1087 +#endif
1088 + qih = rcu_dereference(queue_imq_handler);
1089 +
1090 + if (!qh && !qih)
1091 +#else /* !IMQ */
1092 if (!qh)
1093 +#endif
1094 goto err_unlock;
1095
1096 afinfo = nf_get_afinfo(pf);
1097 @@ -145,6 +180,10 @@
1098 .indev = indev,
1099 .outdev = outdev,
1100 .okfn = okfn,
1101 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1102 + .next_outfn = qh ? qh->outfn : NULL,
1103 + .next_queuenum = queuenum,
1104 +#endif
1105 };
1106
1107 /* If it's going away, ignore hook. */
1108 @@ -170,8 +209,19 @@
1109 }
1110 #endif
1111 afinfo->saveroute(skb, entry);
1112 +
1113 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1114 + if (qih) {
1115 + status = qih->outfn(entry, queuenum);
1116 + goto imq_skip_queue;
1117 + }
1118 +#endif
1119 +
1120 status = qh->outfn(entry, queuenum);
1121
1122 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1123 +imq_skip_queue:
1124 +#endif
1125 rcu_read_unlock();
1126
1127 if (status < 0) {
1128 diff -uNr --exclude='*~' linux-2.6.27.21/net/netfilter/xt_IMQ.c linux-2.6.27.21-imq/net/netfilter/xt_IMQ.c
1129 --- linux-2.6.27.21/net/netfilter/xt_IMQ.c 1970-01-01 02:00:00.000000000 +0200
1130 +++ linux-2.6.27.21-imq/net/netfilter/xt_IMQ.c 2009-04-20 23:48:35.708017126 +0300
1131 @@ -0,0 +1,81 @@
1132 +/*
1133 + * This target marks packets to be enqueued to an imq device
1134 + */
1135 +#include <linux/module.h>
1136 +#include <linux/skbuff.h>
1137 +#include <linux/netfilter/x_tables.h>
1138 +#include <linux/netfilter/xt_IMQ.h>
1139 +#include <linux/imq.h>
1140 +
1141 +static unsigned int imq_target(struct sk_buff *pskb,
1142 + const struct net_device *in,
1143 + const struct net_device *out,
1144 + unsigned int hooknum,
1145 + const struct xt_target *target,
1146 + const void *targinfo)
1147 +{
1148 + const struct xt_imq_info *mr = targinfo;
1149 +
1150 + pskb->imq_flags = (mr->todev & IMQ_F_IFMASK) | IMQ_F_ENQUEUE;
1151 +
1152 + return XT_CONTINUE;
1153 +}
1154 +
1155 +static bool imq_checkentry(const char *tablename,
1156 + const void *entry,
1157 + const struct xt_target *target,
1158 + void *targinfo,
1159 + unsigned int hook_mask)
1160 +{
1161 + struct xt_imq_info *mr = targinfo;
1162 +
1163 + if (mr->todev > IMQ_MAX_DEVS - 1) {
1164 + printk(KERN_WARNING
1165 + "IMQ: invalid device specified, highest is %u\n",
1166 + IMQ_MAX_DEVS - 1);
1167 + return 0;
1168 + }
1169 +
1170 + return 1;
1171 +}
1172 +
1173 +static struct xt_target xt_imq_reg[] __read_mostly = {
1174 + {
1175 + .name = "IMQ",
1176 + .family = AF_INET,
1177 + .target = imq_target,
1178 + .targetsize = sizeof(struct xt_imq_info),
1179 + .table = "mangle",
1180 + .checkentry = imq_checkentry,
1181 + .me = THIS_MODULE
1182 + },
1183 + {
1184 + .name = "IMQ",
1185 + .family = AF_INET6,
1186 + .target = imq_target,
1187 + .targetsize = sizeof(struct xt_imq_info),
1188 + .table = "mangle",
1189 + .checkentry = imq_checkentry,
1190 + .me = THIS_MODULE
1191 + },
1192 +};
1193 +
1194 +static int __init imq_init(void)
1195 +{
1196 + return xt_register_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1197 +}
1198 +
1199 +static void __exit imq_fini(void)
1200 +{
1201 + xt_unregister_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1202 +}
1203 +
1204 +module_init(imq_init);
1205 +module_exit(imq_fini);
1206 +
1207 +MODULE_AUTHOR("http://www.linuximq.net");
1208 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
1209 +MODULE_LICENSE("GPL");
1210 +MODULE_ALIAS("ipt_IMQ");
1211 +MODULE_ALIAS("ip6t_IMQ");
1212 +