large target/linux cleanup
[openwrt.git] / target / linux / generic-2.4 / patches / 616-netfilter_imq.patch
1 diff -aurN linux-2.4.28-orig/Documentation/Configure.help linux-2.4.28/Documentation/Configure.help
2 --- linux-2.4.28-orig/Documentation/Configure.help      2004-11-17 11:54:20.000000000 +0000
3 +++ linux-2.4.28/Documentation/Configure.help   2004-12-14 11:43:42.000000000 +0000
4 @@ -3147,6 +3147,22 @@
5    If you want to compile it as a module, say M here and read
6    <file:Documentation/modules.txt>.  If unsure, say `N'.
7  
8 +IMQ target support
9 +CONFIG_IP_NF_TARGET_IMQ
10 +  This option adds a `IMQ' target which is used to specify if and
11 +  to which imq device packets should get enqueued/dequeued.
12 +
13 +  If you want to compile it as a module, say M here and read
14 +  <file:Documentation/modules.txt>.  If unsure, say `N'.
15 +
16 +IMQ target support
17 +CONFIG_IP6_NF_TARGET_IMQ
18 +  This option adds a `IMQ' target which is used to specify if and
19 +  to which imq device packets should get enqueued/dequeued.
20 +
21 +  If you want to compile it as a module, say M here and read
22 +  <file:Documentation/modules.txt>.  If unsure, say `N'.
23 +
24  MARK target support
25  CONFIG_IP_NF_TARGET_MARK
26    This option adds a `MARK' target, which allows you to create rules
27 @@ -9799,6 +9815,20 @@
28    say M here and read <file:Documentation/modules.txt>.  The module
29    will be called bonding.o.
30  
31 +Intermediate queueing device support
32 +CONFIG_IMQ
33 +  The imq device(s) is used as placeholder for QoS queueing disciplines.
34 +  Every packet entering/leaving the ip stack can be directed through
35 +  the imq device where it's enqueued/dequeued to the attached qdisc.
36 +  This allows you to treat network devices as classes and distribute
37 +  bandwidth among them. Iptables is used to specify through which imq
38 +  device, if any, packets travel.
39 +
40 +  If you want to compile this as a module ( = code which ca be
41 +  inserted in and removed from the running kernel whenever you want),
42 +  say M here and read <file:Documentation/modules.txt>.  The module
43 +  will be called imq.o
44 +
45  SLIP (serial line) support
46  CONFIG_SLIP
47    Say Y if you intend to use SLIP or CSLIP (compressed SLIP) to
48 diff -aurN linux-2.4.28-orig/drivers/net/Config.in linux-2.4.28/drivers/net/Config.in
49 --- linux-2.4.28-orig/drivers/net/Config.in     2004-08-07 23:26:04.000000000 +0000
50 +++ linux-2.4.28/drivers/net/Config.in  2004-12-14 11:43:42.000000000 +0000
51 @@ -7,6 +7,11 @@
52  tristate 'Dummy net driver support' CONFIG_DUMMY
53  tristate 'Bonding driver support' CONFIG_BONDING
54  tristate 'EQL (serial line load balancing) support' CONFIG_EQUALIZER
55 +if [ "$CONFIG_NETFILTER" = "y" ]; then
56 +  tristate 'IMQ (intermediate queueing device) support' CONFIG_IMQ
57 +else
58 +  comment 'IMQ needs CONFIG_NETFILTER enabled'
59 +fi
60  tristate 'Universal TUN/TAP device driver support' CONFIG_TUN
61  if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
62     tristate 'Ethertap network tap (OBSOLETE)' CONFIG_ETHERTAP
63 diff -aurN linux-2.4.28-orig/drivers/net/Makefile linux-2.4.28/drivers/net/Makefile
64 --- linux-2.4.28-orig/drivers/net/Makefile      2004-08-07 23:26:04.000000000 +0000
65 +++ linux-2.4.28/drivers/net/Makefile   2004-12-14 11:43:42.000000000 +0000
66 @@ -170,6 +170,7 @@
67  
68  obj-$(CONFIG_STRIP) += strip.o
69  obj-$(CONFIG_DUMMY) += dummy.o
70 +obj-$(CONFIG_IMQ) += imq.o
71  obj-$(CONFIG_DE600) += de600.o
72  obj-$(CONFIG_DE620) += de620.o
73  obj-$(CONFIG_AT1500) += lance.o
74 diff -aurN linux-2.4.28-orig/drivers/net/imq.c linux-2.4.28/drivers/net/imq.c
75 --- linux-2.4.28-orig/drivers/net/imq.c 1970-01-01 00:00:00.000000000 +0000
76 +++ linux-2.4.28/drivers/net/imq.c      2004-12-14 11:43:42.000000000 +0000
77 @@ -0,0 +1,321 @@
78 +/*
79 + *             Pseudo-driver for the intermediate queue device.
80 + *
81 + *             This program is free software; you can redistribute it and/or
82 + *             modify it under the terms of the GNU General Public License
83 + *             as published by the Free Software Foundation; either version
84 + *             2 of the License, or (at your option) any later version.
85 + *
86 + * Authors:    Patrick McHardy, <kaber@trash.net>
87 + *
88 + *            The first version was written by Martin Devera, <devik@cdi.cz>
89 + *
90 + * Credits:    Jan Rafaj <imq2t@cedric.vabo.cz>
91 + *              - Update patch to 2.4.21
92 + *             Sebastian Strollo <sstrollo@nortelnetworks.com>
93 + *              - Fix "Dead-loop on netdevice imq"-issue
94 + */
95 +
96 +#include <linux/kernel.h>
97 +#include <linux/module.h>
98 +#include <linux/config.h>
99 +#include <linux/skbuff.h>
100 +#include <linux/netdevice.h>
101 +#include <linux/rtnetlink.h>
102 +#include <linux/if_arp.h>
103 +#include <linux/netfilter.h>
104 +#include <linux/netfilter_ipv4.h>
105 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
106 +#include <linux/netfilter_ipv6.h>
107 +#endif
108 +#include <linux/imq.h>
109 +#include <net/pkt_sched.h>
110 +
111 +static nf_hookfn imq_nf_hook;
112 +
113 +static struct nf_hook_ops imq_ingress_ipv4 = {
114 +       { NULL, NULL},
115 +       imq_nf_hook,
116 +       PF_INET,
117 +       NF_IP_PRE_ROUTING,
118 +       NF_IP_PRI_MANGLE + 1
119 +};
120 +
121 +static struct nf_hook_ops imq_egress_ipv4 = {
122 +       { NULL, NULL},
123 +       imq_nf_hook,
124 +       PF_INET,
125 +       NF_IP_POST_ROUTING,
126 +       NF_IP_PRI_LAST
127 +};
128 +
129 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
130 +static struct nf_hook_ops imq_ingress_ipv6 = {
131 +       { NULL, NULL},
132 +       imq_nf_hook,
133 +       PF_INET6,
134 +       NF_IP6_PRE_ROUTING,
135 +       NF_IP6_PRI_MANGLE + 1
136 +};
137 +
138 +static struct nf_hook_ops imq_egress_ipv6 = {
139 +       { NULL, NULL},
140 +       imq_nf_hook,
141 +       PF_INET6,
142 +       NF_IP6_POST_ROUTING,
143 +       NF_IP6_PRI_LAST
144 +};
145 +#endif
146 +
147 +static unsigned int numdevs = 2;
148 +
149 +MODULE_PARM(numdevs, "i");
150 +MODULE_PARM_DESC(numdevs, "number of imq devices");
151 +
152 +static struct net_device *imq_devs;
153 +
154 +
155 +static struct net_device_stats *imq_get_stats(struct net_device *dev)
156 +{
157 +       return (struct net_device_stats *)dev->priv;
158 +}
159 +
160 +/* called for packets kfree'd in qdiscs at places other than enqueue */
161 +static void imq_skb_destructor(struct sk_buff *skb)
162 +{
163 +       struct nf_info *info = skb->nf_info;
164 +
165 +       if (info) {
166 +               if (info->indev)
167 +                       dev_put(info->indev);
168 +               if (info->outdev)
169 +                       dev_put(info->outdev);
170 +               kfree(info);
171 +       }
172 +}
173 +
174 +static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
175 +{
176 +       struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
177 +       
178 +       stats->tx_bytes += skb->len;
179 +       stats->tx_packets++;
180 +
181 +       skb->imq_flags = 0;
182 +       skb->destructor = NULL;
183 +       
184 +       dev->trans_start = jiffies;
185 +       nf_reinject(skb, skb->nf_info, NF_ACCEPT);
186 +       return 0;
187 +}
188 +
189 +static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info,
190 +                       void *data)
191 +{
192 +       struct net_device *dev;
193 +       struct net_device_stats *stats;
194 +       struct sk_buff *skb2 = NULL;
195 +       struct Qdisc *q;
196 +       unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
197 +       int ret = -1;
198 +
199 +       if (index > numdevs) 
200 +               return -1;
201 +       
202 +       dev = imq_devs + index;
203 +       if (!(dev->flags & IFF_UP)) {
204 +               skb->imq_flags = 0;
205 +               nf_reinject(skb, info, NF_ACCEPT);
206 +               return 0;
207 +       }
208 +       dev->last_rx = jiffies;
209 +
210 +       if (skb->destructor) {
211 +               skb2 = skb;
212 +               skb = skb_clone(skb, GFP_ATOMIC);
213 +               if (!skb)
214 +                       return -1;
215 +       }
216 +       skb->nf_info = info;
217 +
218 +       stats = (struct net_device_stats *)dev->priv;
219 +       stats->rx_bytes+= skb->len;
220 +       stats->rx_packets++;
221 +       
222 +       spin_lock_bh(&dev->queue_lock);
223 +       q = dev->qdisc;
224 +       if (q->enqueue) {
225 +               q->enqueue(skb_get(skb), q);
226 +               if (skb_shared(skb)) {
227 +                       skb->destructor = imq_skb_destructor;
228 +                       kfree_skb(skb);
229 +                       ret = 0;
230 +               }
231 +       }
232 +       if (spin_is_locked(&dev->xmit_lock))
233 +               netif_schedule(dev);
234 +       else
235 +               qdisc_run(dev);
236 +       spin_unlock_bh(&dev->queue_lock);
237 +
238 +       if (skb2)
239 +               kfree_skb(ret ? skb : skb2);
240 +
241 +       return ret;
242 +}
243 +
244 +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff **pskb,
245 +                  const struct net_device *indev,
246 +                  const struct net_device *outdev,
247 +                  int (*okfn)(struct sk_buff *))
248 +{
249 +       if ((*pskb)->imq_flags & IMQ_F_ENQUEUE)
250 +               return NF_QUEUE;
251 +
252 +       return NF_ACCEPT;
253 +}
254 +
255 +
256 +static int __init imq_init_hooks(void)
257 +{
258 +       int err;
259 +
260 +       if ((err = nf_register_queue_handler(PF_INET, imq_nf_queue, NULL)))
261 +               goto err1;
262 +       if ((err = nf_register_hook(&imq_ingress_ipv4)))
263 +               goto err2;
264 +       if ((err = nf_register_hook(&imq_egress_ipv4)))
265 +               goto err3;
266 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
267 +       if ((err = nf_register_queue_handler(PF_INET6, imq_nf_queue, NULL)))
268 +               goto err4;
269 +       if ((err = nf_register_hook(&imq_ingress_ipv6)))
270 +               goto err5;
271 +       if ((err = nf_register_hook(&imq_egress_ipv6)))
272 +               goto err6;
273 +#endif
274 +       
275 +       return 0;
276 +       
277 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
278 +err6:
279 +       nf_unregister_hook(&imq_ingress_ipv6);
280 +err5:
281 +       nf_unregister_queue_handler(PF_INET6);
282 +err4:
283 +       nf_unregister_hook(&imq_egress_ipv4);
284 +#endif
285 +err3:
286 +       nf_unregister_hook(&imq_ingress_ipv4);
287 +err2:
288 +       nf_unregister_queue_handler(PF_INET);
289 +err1:
290 +       return err;
291 +}
292 +
293 +static void __exit imq_unhook(void)
294 +{
295 +       nf_unregister_hook(&imq_ingress_ipv4);
296 +       nf_unregister_hook(&imq_egress_ipv4);
297 +       nf_unregister_queue_handler(PF_INET);
298 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
299 +       nf_unregister_hook(&imq_ingress_ipv6);
300 +       nf_unregister_hook(&imq_egress_ipv6);
301 +       nf_unregister_queue_handler(PF_INET6);
302 +#endif
303 +}
304 +
305 +static int __init imq_dev_init(struct net_device *dev)
306 +{
307 +       dev->hard_start_xmit    = imq_dev_xmit;
308 +       dev->type               = ARPHRD_VOID;
309 +       dev->mtu                = 1500;
310 +       dev->tx_queue_len       = 30;
311 +       dev->flags              = IFF_NOARP;
312 +       dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
313 +       if (dev->priv == NULL)
314 +               return -ENOMEM;
315 +       memset(dev->priv, 0, sizeof(struct net_device_stats));
316 +       dev->get_stats          = imq_get_stats;
317 +
318 +       return 0;
319 +}
320 +
321 +static void imq_dev_uninit(struct net_device *dev)
322 +{
323 +       kfree(dev->priv);
324 +}
325 +
326 +static int __init imq_init_devs(void)
327 +{
328 +       struct net_device *dev;
329 +       int i;
330 +
331 +       if (!numdevs || numdevs > IMQ_MAX_DEVS) {
332 +               printk(KERN_ERR "numdevs has to be betweed 1 and %u\n",
333 +                      IMQ_MAX_DEVS);
334 +               return -EINVAL;
335 +       }
336 +
337 +       imq_devs = kmalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
338 +       if (!imq_devs)
339 +               return -ENOMEM;
340 +       memset(imq_devs, 0, sizeof(struct net_device) * numdevs);
341 +
342 +       /* we start counting at zero */
343 +       numdevs--;
344 +
345 +       for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
346 +               SET_MODULE_OWNER(dev);
347 +               strcpy(dev->name, "imq%d");
348 +               dev->init   = imq_dev_init;
349 +               dev->uninit = imq_dev_uninit;
350 +
351 +               if (register_netdev(dev) < 0)
352 +                       goto err_register;
353 +       }
354 +       return 0;
355 +
356 +err_register:
357 +       for (; i; i--)
358 +               unregister_netdev(--dev);
359 +       kfree(imq_devs);
360 +       return -EIO;
361 +}
362 +
363 +static void imq_cleanup_devs(void)
364 +{
365 +       int i;
366 +       struct net_device *dev = imq_devs;
367 +       
368 +       for (i = 0; i <= numdevs; i++)
369 +               unregister_netdev(dev++);
370 +
371 +       kfree(imq_devs);
372 +}
373 +
374 +static int __init imq_init_module(void)
375 +{
376 +       int err;
377 +
378 +       if ((err = imq_init_devs()))
379 +               return err;
380 +       if ((err = imq_init_hooks())) {
381 +               imq_cleanup_devs();
382 +               return err;
383 +       }
384 +
385 +       printk(KERN_INFO "imq driver loaded.\n");
386 +
387 +       return 0;
388 +}
389 +
390 +static void __exit imq_cleanup_module(void)
391 +{
392 +       imq_unhook();
393 +       imq_cleanup_devs();
394 +}
395 +
396 +module_init(imq_init_module);
397 +module_exit(imq_cleanup_module);
398 +MODULE_LICENSE("GPL");
399 diff -aurN linux-2.4.28-orig/include/linux/imq.h linux-2.4.28/include/linux/imq.h
400 --- linux-2.4.28-orig/include/linux/imq.h       1970-01-01 00:00:00.000000000 +0000
401 +++ linux-2.4.28/include/linux/imq.h    2004-12-14 11:43:42.000000000 +0000
402 @@ -0,0 +1,9 @@
403 +#ifndef _IMQ_H
404 +#define _IMQ_H
405 +
406 +#define IMQ_MAX_DEVS   16
407 +
408 +#define IMQ_F_IFMASK   0x7f
409 +#define IMQ_F_ENQUEUE  0x80
410 +
411 +#endif /* _IMQ_H */
412 diff -aurN linux-2.4.28-orig/include/linux/netfilter_ipv4/ipt_IMQ.h linux-2.4.28/include/linux/netfilter_ipv4/ipt_IMQ.h
413 --- linux-2.4.28-orig/include/linux/netfilter_ipv4/ipt_IMQ.h    1970-01-01 00:00:00.000000000 +0000
414 +++ linux-2.4.28/include/linux/netfilter_ipv4/ipt_IMQ.h 2004-12-14 11:43:42.000000000 +0000
415 @@ -0,0 +1,8 @@
416 +#ifndef _IPT_IMQ_H
417 +#define _IPT_IMQ_H
418 +
419 +struct ipt_imq_info {
420 +       unsigned int todev;     /* target imq device */
421 +};
422 +
423 +#endif /* _IPT_IMQ_H */
424 diff -aurN linux-2.4.28-orig/include/linux/netfilter_ipv6/ip6t_IMQ.h linux-2.4.28/include/linux/netfilter_ipv6/ip6t_IMQ.h
425 --- linux-2.4.28-orig/include/linux/netfilter_ipv6/ip6t_IMQ.h   1970-01-01 00:00:00.000000000 +0000
426 +++ linux-2.4.28/include/linux/netfilter_ipv6/ip6t_IMQ.h        2004-12-14 11:43:42.000000000 +0000
427 @@ -0,0 +1,8 @@
428 +#ifndef _IP6T_IMQ_H
429 +#define _IP6T_IMQ_H
430 +
431 +struct ip6t_imq_info {
432 +       unsigned int todev;     /* target imq device */
433 +};
434 +
435 +#endif /* _IP6T_IMQ_H */
436 diff -aurN linux-2.4.28-orig/include/linux/skbuff.h linux-2.4.28/include/linux/skbuff.h
437 --- linux-2.4.28-orig/include/linux/skbuff.h    2004-08-07 23:26:06.000000000 +0000
438 +++ linux-2.4.28/include/linux/skbuff.h 2004-12-14 11:43:42.000000000 +0000
439 @@ -93,6 +93,9 @@
440         struct nf_conntrack *master;
441  };
442  #endif
443 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
444 +struct nf_info;
445 +#endif
446  
447  struct sk_buff_head {
448         /* These two members must be first. */
449 @@ -182,7 +185,7 @@
450         unsigned int    len;                    /* Length of actual data                        */
451         unsigned int    data_len;
452         unsigned int    csum;                   /* Checksum                                     */
453 -       unsigned char   __unused,               /* Dead field, may be reused                    */
454 +       unsigned char   imq_flags,              /* intermediate queueing device */
455                         cloned,                 /* head may be cloned (check refcnt to be sure). */
456                         pkt_type,               /* Packet class                                 */
457                         ip_summed;              /* Driver fed us an IP checksum                 */
458 @@ -219,6 +222,9 @@
459  #ifdef CONFIG_NET_SCHED
460         __u32           tc_index;               /* traffic control index */
461  #endif
462 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
463 +       struct nf_info  *nf_info;
464 +#endif
465  };
466  
467  #ifdef __KERNEL__
468 diff -aurN linux-2.4.28-orig/net/core/skbuff.c linux-2.4.28/net/core/skbuff.c
469 --- linux-2.4.28-orig/net/core/skbuff.c 2003-08-25 11:44:44.000000000 +0000
470 +++ linux-2.4.28/net/core/skbuff.c      2004-12-14 11:43:42.000000000 +0000
471 @@ -202,6 +202,10 @@
472         /* Set up other state */
473         skb->len = 0;
474         skb->cloned = 0;
475 +#if defined(CONFIG_IMQ) || defined (CONFIG_IMQ_MODULE)
476 +       skb->imq_flags = 0;
477 +       skb->nf_info = NULL;
478 +#endif
479         skb->data_len = 0;
480  
481         atomic_set(&skb->users, 1); 
482 @@ -250,6 +254,10 @@
483  #ifdef CONFIG_NET_SCHED
484         skb->tc_index = 0;
485  #endif
486 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
487 +       skb->imq_flags = 0;
488 +       skb->nf_info = NULL;
489 +#endif
490  }
491  
492  static void skb_drop_fraglist(struct sk_buff *skb)
493 @@ -400,6 +408,10 @@
494  #ifdef CONFIG_NET_SCHED
495         C(tc_index);
496  #endif
497 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
498 +       C(imq_flags);
499 +       C(nf_info);
500 +#endif
501  
502         atomic_inc(&(skb_shinfo(skb)->dataref));
503         skb->cloned = 1;
504 @@ -444,6 +456,10 @@
505  #ifdef CONFIG_NET_SCHED
506         new->tc_index = old->tc_index;
507  #endif
508 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
509 +       new->imq_flags=old->imq_flags;
510 +       new->nf_info=old->nf_info;
511 +#endif
512  }
513  
514  /**
515 diff -aurN linux-2.4.28-orig/net/ipv4/netfilter/Config.in linux-2.4.28/net/ipv4/netfilter/Config.in
516 --- linux-2.4.28-orig/net/ipv4/netfilter/Config.in      2003-08-25 11:44:44.000000000 +0000
517 +++ linux-2.4.28/net/ipv4/netfilter/Config.in   2004-12-14 11:43:43.000000000 +0000
518 @@ -104,6 +104,7 @@
519      dep_tristate '    DSCP target support' CONFIG_IP_NF_TARGET_DSCP $CONFIG_IP_NF_MANGLE
520   
521      dep_tristate '    MARK target support' CONFIG_IP_NF_TARGET_MARK $CONFIG_IP_NF_MANGLE
522 +    dep_tristate '    IMQ target support' CONFIG_IP_NF_TARGET_IMQ $CONFIG_IP_NF_MANGLE
523    fi
524    dep_tristate '  LOG target support' CONFIG_IP_NF_TARGET_LOG $CONFIG_IP_NF_IPTABLES
525    dep_tristate '  ULOG target support' CONFIG_IP_NF_TARGET_ULOG $CONFIG_IP_NF_IPTABLES
526 diff -aurN linux-2.4.28-orig/net/ipv4/netfilter/Makefile linux-2.4.28/net/ipv4/netfilter/Makefile
527 --- linux-2.4.28-orig/net/ipv4/netfilter/Makefile       2003-08-25 11:44:44.000000000 +0000
528 +++ linux-2.4.28/net/ipv4/netfilter/Makefile    2004-12-14 11:43:43.000000000 +0000
529 @@ -94,6 +94,7 @@
530  obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
531  obj-$(CONFIG_IP_NF_TARGET_DSCP) += ipt_DSCP.o
532  obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
533 +obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
534  obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
535  obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
536  obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
537 diff -aurN linux-2.4.28-orig/net/ipv4/netfilter/ipt_IMQ.c linux-2.4.28/net/ipv4/netfilter/ipt_IMQ.c
538 --- linux-2.4.28-orig/net/ipv4/netfilter/ipt_IMQ.c      1970-01-01 00:00:00.000000000 +0000
539 +++ linux-2.4.28/net/ipv4/netfilter/ipt_IMQ.c   2004-12-14 11:43:43.000000000 +0000
540 @@ -0,0 +1,78 @@
541 +/* This target marks packets to be enqueued to an imq device */
542 +#include <linux/module.h>
543 +#include <linux/skbuff.h>
544 +#include <linux/netfilter_ipv4/ip_tables.h>
545 +#include <linux/netfilter_ipv4/ipt_IMQ.h>
546 +#include <linux/imq.h>
547 +
548 +static unsigned int imq_target(struct sk_buff **pskb,
549 +                              unsigned int hooknum,
550 +                              const struct net_device *in,
551 +                              const struct net_device *out,
552 +                              const void *targinfo,
553 +                              void *userinfo)
554 +{
555 +       struct ipt_imq_info *mr = (struct ipt_imq_info*)targinfo;
556 +
557 +       (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
558 +       (*pskb)->nfcache |= NFC_ALTERED;
559 +
560 +       return IPT_CONTINUE;
561 +}
562 +
563 +static int imq_checkentry(const char *tablename,
564 +                         const struct ipt_entry *e,
565 +                         void *targinfo,
566 +                         unsigned int targinfosize,
567 +                         unsigned int hook_mask)
568 +{
569 +       struct ipt_imq_info *mr;
570 +
571 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_imq_info))) {
572 +               printk(KERN_WARNING "IMQ: invalid targinfosize\n");
573 +               return 0;
574 +       }
575 +       mr = (struct ipt_imq_info*)targinfo;
576 +
577 +       if (strcmp(tablename, "mangle") != 0) {
578 +               printk(KERN_WARNING
579 +                      "IMQ: IMQ can only be called from \"mangle\" table, not \"%s\"\n",
580 +                      tablename);
581 +               return 0;
582 +       }
583 +       
584 +       if (mr->todev > IMQ_MAX_DEVS) {
585 +               printk(KERN_WARNING
586 +                      "IMQ: invalid device specified, highest is %u\n",
587 +                      IMQ_MAX_DEVS);
588 +               return 0;
589 +       }
590 +       
591 +       return 1;
592 +}
593 +
594 +static struct ipt_target ipt_imq_reg = {
595 +       { NULL, NULL},
596 +       "IMQ",
597 +       imq_target,
598 +       imq_checkentry,
599 +       NULL,
600 +       THIS_MODULE
601 +};
602 +
603 +static int __init init(void)
604 +{
605 +       if (ipt_register_target(&ipt_imq_reg))
606 +               return -EINVAL;
607 +
608 +       return 0;
609 +}
610 +
611 +static void __exit fini(void)
612 +{
613 +       ipt_unregister_target(&ipt_imq_reg);
614 +}
615 +
616 +module_init(init);
617 +module_exit(fini);
618 +MODULE_LICENSE("GPL");
619 diff -aurN linux-2.4.28-orig/net/ipv6/netfilter/Config.in linux-2.4.28/net/ipv6/netfilter/Config.in
620 --- linux-2.4.28-orig/net/ipv6/netfilter/Config.in      2003-06-13 14:51:39.000000000 +0000
621 +++ linux-2.4.28/net/ipv6/netfilter/Config.in   2004-12-14 11:43:43.000000000 +0000
622 @@ -71,6 +71,7 @@
623    if [ "$CONFIG_IP6_NF_MANGLE" != "n" ]; then
624  #    dep_tristate '    TOS target support' CONFIG_IP6_NF_TARGET_TOS $CONFIG_IP_NF_MANGLE
625      dep_tristate '    MARK target support' CONFIG_IP6_NF_TARGET_MARK $CONFIG_IP6_NF_MANGLE
626 +    dep_tristate '    IMQ target support' CONFIG_IP6_NF_TARGET_IMQ $CONFIG_IP6_NF_MANGLE
627    fi
628    #dep_tristate '  LOG target support' CONFIG_IP6_NF_TARGET_LOG $CONFIG_IP6_NF_IPTABLES
629  fi
630 diff -aurN linux-2.4.28-orig/net/ipv6/netfilter/Makefile linux-2.4.28/net/ipv6/netfilter/Makefile
631 --- linux-2.4.28-orig/net/ipv6/netfilter/Makefile       2003-06-13 14:51:39.000000000 +0000
632 +++ linux-2.4.28/net/ipv6/netfilter/Makefile    2004-12-14 11:43:43.000000000 +0000
633 @@ -28,6 +28,7 @@
634  obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
635  obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
636  obj-$(CONFIG_IP6_NF_TARGET_MARK) += ip6t_MARK.o
637 +obj-$(CONFIG_IP6_NF_TARGET_IMQ) += ip6t_IMQ.o
638  obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
639  obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
640  obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
641 diff -aurN linux-2.4.28-orig/net/ipv6/netfilter/ip6t_IMQ.c linux-2.4.28/net/ipv6/netfilter/ip6t_IMQ.c
642 --- linux-2.4.28-orig/net/ipv6/netfilter/ip6t_IMQ.c     1970-01-01 00:00:00.000000000 +0000
643 +++ linux-2.4.28/net/ipv6/netfilter/ip6t_IMQ.c  2004-12-14 11:43:43.000000000 +0000
644 @@ -0,0 +1,78 @@
645 +/* This target marks packets to be enqueued to an imq device */
646 +#include <linux/module.h>
647 +#include <linux/skbuff.h>
648 +#include <linux/netfilter_ipv6/ip6_tables.h>
649 +#include <linux/netfilter_ipv6/ip6t_IMQ.h>
650 +#include <linux/imq.h>
651 +
652 +static unsigned int imq_target(struct sk_buff **pskb,
653 +                              unsigned int hooknum,
654 +                              const struct net_device *in,
655 +                              const struct net_device *out,
656 +                              const void *targinfo,
657 +                              void *userinfo)
658 +{
659 +       struct ip6t_imq_info *mr = (struct ip6t_imq_info*)targinfo;
660 +
661 +       (*pskb)->imq_flags = mr->todev | IMQ_F_ENQUEUE;
662 +       (*pskb)->nfcache |= NFC_ALTERED;
663 +
664 +       return IP6T_CONTINUE;
665 +}
666 +
667 +static int imq_checkentry(const char *tablename,
668 +                         const struct ip6t_entry *e,
669 +                         void *targinfo,
670 +                         unsigned int targinfosize,
671 +                         unsigned int hook_mask)
672 +{
673 +       struct ip6t_imq_info *mr;
674 +
675 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_imq_info))) {
676 +               printk(KERN_WARNING "IMQ: invalid targinfosize\n");
677 +               return 0;
678 +       }
679 +       mr = (struct ip6t_imq_info*)targinfo;
680 +
681 +       if (strcmp(tablename, "mangle") != 0) {
682 +               printk(KERN_WARNING
683 +                      "IMQ: IMQ can only be called from \"mangle\" table, not \"%s\"\n",
684 +                      tablename);
685 +               return 0;
686 +       }
687 +       
688 +       if (mr->todev > IMQ_MAX_DEVS) {
689 +               printk(KERN_WARNING
690 +                      "IMQ: invalid device specified, highest is %u\n",
691 +                      IMQ_MAX_DEVS);
692 +               return 0;
693 +       }
694 +       
695 +       return 1;
696 +}
697 +
698 +static struct ip6t_target ip6t_imq_reg = {
699 +       { NULL, NULL},
700 +       "IMQ",
701 +       imq_target,
702 +       imq_checkentry,
703 +       NULL,
704 +       THIS_MODULE
705 +};
706 +
707 +static int __init init(void)
708 +{
709 +       if (ip6t_register_target(&ip6t_imq_reg))
710 +               return -EINVAL;
711 +
712 +       return 0;
713 +}
714 +
715 +static void __exit fini(void)
716 +{
717 +       ip6t_unregister_target(&ip6t_imq_reg);
718 +}
719 +
720 +module_init(init);
721 +module_exit(fini);
722 +MODULE_LICENSE("GPL");
723 diff -aurN linux-2.4.28-orig/net/sched/sch_generic.c linux-2.4.28/net/sched/sch_generic.c
724 --- linux-2.4.28-orig/net/sched/sch_generic.c   2004-11-17 11:54:22.000000000 +0000
725 +++ linux-2.4.28/net/sched/sch_generic.c        2004-12-14 11:44:27.000000000 +0000
726 @@ -29,6 +29,9 @@
727  #include <linux/skbuff.h>
728  #include <linux/rtnetlink.h>
729  #include <linux/init.h>
730 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
731 +#include <linux/imq.h>
732 +#endif
733  #include <linux/list.h>
734  #include <net/sock.h>
735  #include <net/pkt_sched.h>
736 @@ -90,7 +93,11 @@
737                         spin_unlock(&dev->queue_lock);
738  
739                         if (!netif_queue_stopped(dev)) {
740 -                               if (netdev_nit)
741 +                               if (netdev_nit
742 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
743 +                                   && !(skb->imq_flags & IMQ_F_ENQUEUE)
744 +#endif
745 +                                   )
746                                         dev_queue_xmit_nit(skb, dev);
747  
748                                 if (dev->hard_start_xmit(skb, dev) == 0) {