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