1 diff -urN linux-2.4.18-clean/Documentation/Configure.help linux-2.4.18-imq/Documentation/Configure.help
2 --- linux-2.4.18-clean/Documentation/Configure.help Mon Feb 25 20:37:51 2002
3 +++ linux-2.4.18-imq/Documentation/Configure.help Thu May 23 14:15:12 2002
5 say M here and read <file:Documentation/modules.txt>. The module
6 will be called bonding.o.
8 +Intermediate queueing device support
10 + The imq device(s) is used as placeholder for QoS queueing disciplines.
11 + Every packet entering/leaving the ip stack can be directed through
12 + the imq device where it's enqueued/dequeued to the attached qdisc.
13 + This allows you to treat network devices as classes and distribute
14 + bandwidth among them. Iptables is used to specify through which imq
15 + device, if any, packets travel.
17 + If you want to compile this as a module ( = code which ca be
18 + inserted in and removed from the running kernel whenever you want),
19 + say M here and read <file:Documentation/modules.txt>. The module
20 + will be called imq.o
22 SLIP (serial line) support
24 Say Y if you intend to use SLIP or CSLIP (compressed SLIP) to
25 diff -urN linux-2.4.18-clean/drivers/net/Config.in linux-2.4.18-imq/drivers/net/Config.in
26 --- linux-2.4.18-clean/drivers/net/Config.in Mon Feb 25 20:37:59 2002
27 +++ linux-2.4.18-imq/drivers/net/Config.in Thu May 23 14:15:12 2002
29 tristate 'Dummy net driver support' CONFIG_DUMMY
30 tristate 'Bonding driver support' CONFIG_BONDING
31 tristate 'EQL (serial line load balancing) support' CONFIG_EQUALIZER
32 +if [ "$CONFIG_NETFILTER" = "y" ]; then
33 + tristate 'IMQ (intermediate queueing device) support' CONFIG_IMQ
35 + comment 'IMQ needs CONFIG_NETFILTER enabled'
37 tristate 'Universal TUN/TAP device driver support' CONFIG_TUN
38 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
39 tristate 'Ethertap network tap (OBSOLETE)' CONFIG_ETHERTAP
40 diff -urN linux-2.4.18-clean/drivers/net/Makefile linux-2.4.18-imq/drivers/net/Makefile
41 --- linux-2.4.18-clean/drivers/net/Makefile Mon Feb 25 20:37:59 2002
42 +++ linux-2.4.18-imq/drivers/net/Makefile Thu May 23 14:15:12 2002
45 obj-$(CONFIG_STRIP) += strip.o
46 obj-$(CONFIG_DUMMY) += dummy.o
47 +obj-$(CONFIG_IMQ) += imq.o
48 obj-$(CONFIG_DE600) += de600.o
49 obj-$(CONFIG_DE620) += de620.o
50 obj-$(CONFIG_AT1500) += lance.o
51 diff -urN linux-2.4.18-clean/drivers/net/imq.c linux-2.4.18-imq/drivers/net/imq.c
52 --- linux-2.4.18-clean/drivers/net/imq.c Thu Jan 1 01:00:00 1970
53 +++ linux-2.4.18-imq/drivers/net/imq.c Thu May 23 14:07:49 2002
56 + * Pseudo-driver for the intermediate queue device.
58 + * Authors: Patrick McHardy, <kaber@trash.net>
60 + * The first version was written by Martin Devera, <devik@cdi.cz>
62 + * This program is free software; you can redistribute it and/or
63 + * modify it under the terms of the GNU General Public License
64 + * as published by the Free Software Foundation; either version
65 + * 2 of the License, or (at your option) any later version.
68 +#include <linux/kernel.h>
69 +#include <linux/module.h>
70 +#include <linux/config.h>
71 +#include <linux/skbuff.h>
72 +#include <linux/netdevice.h>
73 +#include <linux/rtnetlink.h>
74 +#include <linux/if_arp.h>
75 +#include <linux/netfilter.h>
76 +#include <linux/netfilter_ipv4.h>
77 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
78 +#include <linux/netfilter_ipv6.h>
80 +#include <linux/imq.h>
81 +#include <net/pkt_sched.h>
83 +#define IMQ_HH_LEN(info) (((info)->hook == NF_IP_PRE_ROUTING) ? \
84 + (info)->indev->hard_header_len : \
85 + (info)->outdev->hard_header_len)
87 +static nf_hookfn imq_nf_hook;
89 +static struct nf_hook_ops imq_ingress_ipv4 = {
94 + NF_IP_PRI_MANGLE + 1
97 +static struct nf_hook_ops imq_egress_ipv4 = {
101 + NF_IP_POST_ROUTING,
105 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
106 +static struct nf_hook_ops imq_ingress_ipv6 = {
110 + NF_IP6_PRE_ROUTING,
111 + NF_IP6_PRI_MANGLE + 1
114 +static struct nf_hook_ops imq_egress_ipv6 = {
118 + NF_IP6_POST_ROUTING,
123 +static unsigned int numdevs = 2;
125 +MODULE_PARM(numdevs, "i");
126 +MODULE_PARM_DESC(numdevs, "number of imq devices");
128 +static struct net_device *imq_devs;
131 +static struct net_device_stats *imq_get_stats(struct net_device *dev)
133 + return (struct net_device_stats *)dev->priv;
136 +/* called for packets kfree'd in qdiscs at places other than enqueue */
137 +static void imq_skb_destructor(struct sk_buff *skb)
139 + struct nf_info *info = skb->nf_info;
143 + dev_put(info->indev);
145 + dev_put(info->outdev);
150 +static int imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
152 + struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
154 + stats->tx_bytes += skb->len;
155 + stats->tx_packets++;
157 + skb_pull(skb, IMQ_HH_LEN(skb->nf_info));
159 + skb->imq_flags = 0;
160 + skb->destructor = NULL;
162 + dev->trans_start = jiffies;
163 + nf_reinject(skb, skb->nf_info, NF_ACCEPT);
168 +static int imq_nf_queue(struct sk_buff *skb, struct nf_info *info,
171 + struct net_device *dev;
172 + struct net_device_stats *stats;
173 + struct sk_buff *skb2 = NULL;
175 + unsigned int index = skb->imq_flags&IMQ_F_IFMASK;
178 + if (index > numdevs)
181 + dev = imq_devs + index;
182 + if (!(dev->flags & IFF_UP)) {
183 + skb->imq_flags = 0;
184 + nf_reinject(skb, info, NF_ACCEPT);
187 + dev->last_rx = jiffies;
189 + if (skb->destructor) {
191 + skb = skb_clone(skb, GFP_ATOMIC);
195 + skb_push(skb, IMQ_HH_LEN(info));
196 + skb->nf_info = info;
198 + stats = (struct net_device_stats *)dev->priv;
199 + stats->rx_bytes+= skb->len;
200 + stats->rx_packets++;
202 + spin_lock_bh(&dev->queue_lock);
206 + q->enqueue(skb_get(skb), q);
208 + if (skb_shared(skb)) {
209 + skb->destructor = imq_skb_destructor;
216 + spin_unlock_bh(&dev->queue_lock);
219 + kfree_skb(ret ? skb : skb2);
224 +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff **pskb,
225 + const struct net_device *indev,
226 + const struct net_device *outdev,
227 + int (*okfn)(struct sk_buff *))
229 + if ((*pskb)->imq_flags & IMQ_F_ENQUEUE)
236 +static int __init imq_init_hooks(void)
240 + if ((err = nf_register_queue_handler(PF_INET, imq_nf_queue, NULL)))
242 + if ((err = nf_register_hook(&imq_ingress_ipv4)))
244 + if ((err = nf_register_hook(&imq_egress_ipv4)))
246 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
247 + if ((err = nf_register_queue_handler(PF_INET6, imq_nf_queue, NULL)))
249 + if ((err = nf_register_hook(&imq_ingress_ipv6)))
251 + if ((err = nf_register_hook(&imq_egress_ipv6)))
257 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
259 + nf_unregister_hook(&imq_ingress_ipv6);
261 + nf_unregister_queue_handler(PF_INET6);
263 + nf_unregister_hook(&imq_egress_ipv4);
266 + nf_unregister_hook(&imq_ingress_ipv4);
268 + nf_unregister_queue_handler(PF_INET);
273 +static void __exit imq_unhook(void)
275 + nf_unregister_hook(&imq_ingress_ipv4);
276 + nf_unregister_hook(&imq_egress_ipv4);
277 + nf_unregister_queue_handler(PF_INET);
278 +#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
279 + nf_unregister_hook(&imq_ingress_ipv6);
280 + nf_unregister_hook(&imq_egress_ipv6);
281 + nf_unregister_queue_handler(PF_INET6);
285 +static int __init imq_dev_init(struct net_device *dev)
287 + dev->hard_start_xmit = imq_dev_xmit;
288 + dev->type = ARPHRD_VOID;
290 + dev->tx_queue_len = 30;
291 + dev->flags = IFF_NOARP;
292 + dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
293 + if (dev->priv == NULL)
295 + memset(dev->priv, 0, sizeof(struct net_device_stats));
296 + dev->get_stats = imq_get_stats;
301 +static void imq_dev_uninit(struct net_device *dev)
306 +static int __init imq_init_devs(void)
308 + struct net_device *dev;
311 + if (!numdevs || numdevs > IMQ_MAX_DEVS) {
312 + printk(KERN_ERR "numdevs has to be betweed 1 and %u\n",
317 + imq_devs = kmalloc(sizeof(struct net_device) * numdevs, GFP_KERNEL);
320 + memset(imq_devs, 0, sizeof(struct net_device) * numdevs);
322 + /* we start counting at zero */
325 + for (i = 0, dev = imq_devs; i <= numdevs; i++, dev++) {
326 + SET_MODULE_OWNER(dev);
327 + strcpy(dev->name, "imq%d");
328 + dev->init = imq_dev_init;
329 + dev->uninit = imq_dev_uninit;
331 + if (register_netdev(dev) < 0)
338 + unregister_netdev(--dev);
343 +static void imq_cleanup_devs(void)
346 + struct net_device *dev = imq_devs;
348 + for (i = 0; i <= numdevs; i++)
349 + unregister_netdev(dev++);
354 +static int __init imq_init_module(void)
358 + if ((err = imq_init_devs()))
360 + if ((err = imq_init_hooks())) {
361 + imq_cleanup_devs();
365 + printk(KERN_INFO "imq driver loaded.\n");
370 +static void __exit imq_cleanup_module(void)
373 + imq_cleanup_devs();
376 +module_init(imq_init_module);
377 +module_exit(imq_cleanup_module);
378 +MODULE_LICENSE("GPL");
379 diff -urN linux-2.4.18-clean/include/linux/imq.h linux-2.4.18-imq/include/linux/imq.h
380 --- linux-2.4.18-clean/include/linux/imq.h Thu Jan 1 01:00:00 1970
381 +++ linux-2.4.18-imq/include/linux/imq.h Thu May 23 14:15:12 2002
386 +#define IMQ_MAX_DEVS 16
388 +#define IMQ_F_IFMASK 0x7f
389 +#define IMQ_F_ENQUEUE 0x80
392 diff -urN linux-2.4.18-clean/include/linux/skbuff.h linux-2.4.18-imq/include/linux/skbuff.h
393 --- linux-2.4.18-clean/include/linux/skbuff.h Thu Nov 22 20:46:26 2001
394 +++ linux-2.4.18-imq/include/linux/skbuff.h Thu May 23 14:15:12 2002
396 struct nf_conntrack *master;
399 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
403 struct sk_buff_head {
404 /* These two members must be first. */
406 unsigned int len; /* Length of actual data */
407 unsigned int data_len;
408 unsigned int csum; /* Checksum */
409 - unsigned char __unused, /* Dead field, may be reused */
410 + unsigned char imq_flags, /* intermediate queueing device */
411 cloned, /* head may be cloned (check refcnt to be sure). */
412 pkt_type, /* Packet class */
413 ip_summed; /* Driver fed us an IP checksum */
416 #ifdef CONFIG_NET_SCHED
417 __u32 tc_index; /* traffic control index */
419 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
420 + struct nf_info *nf_info;
424 diff -urN linux-2.4.18-clean/net/core/skbuff.c linux-2.4.18-imq/net/core/skbuff.c
425 --- linux-2.4.18-clean/net/core/skbuff.c Fri Dec 21 18:42:05 2001
426 +++ linux-2.4.18-imq/net/core/skbuff.c Thu May 23 14:15:12 2002
428 /* Set up other state */
431 +#if defined(CONFIG_IMQ) || defined (CONFIG_IMQ_MODULE)
432 + skb->imq_flags = 0;
433 + skb->nf_info = NULL;
437 atomic_set(&skb->users, 1);
439 #ifdef CONFIG_NET_SCHED
442 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
443 + skb->imq_flags = 0;
444 + skb->nf_info = NULL;
448 static void skb_drop_fraglist(struct sk_buff *skb)
450 #ifdef CONFIG_NET_SCHED
453 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
458 atomic_inc(&(skb_shinfo(skb)->dataref));
462 #ifdef CONFIG_NET_SCHED
463 new->tc_index = old->tc_index;
465 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
466 + new->imq_flags=old->imq_flags;
467 + new->nf_info=old->nf_info;
471 diff -urN linux-2.4.18-clean/net/sched/sch_generic.c linux-2.4.18-imq/net/sched/sch_generic.c
472 --- linux-2.4.18-clean/net/sched/sch_generic.c Fri Aug 18 19:26:25 2000
473 +++ linux-2.4.18-imq/net/sched/sch_generic.c Thu May 23 14:15:12 2002
475 #include <linux/skbuff.h>
476 #include <linux/rtnetlink.h>
477 #include <linux/init.h>
478 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
479 +#include <linux/imq.h>
481 #include <net/sock.h>
482 #include <net/pkt_sched.h>
485 spin_unlock(&dev->queue_lock);
487 if (!netif_queue_stopped(dev)) {
490 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
491 + && !(skb->imq_flags & IMQ_F_ENQUEUE)
494 dev_queue_xmit_nit(skb, dev);
496 if (dev->hard_start_xmit(skb, dev) == 0) {