]>
Commit | Line | Data |
---|---|---|
14f08cd0 | 1 | diff -U 5 -Nr linux-2.6.32/drivers/net/imq.c linux-2.6.32-imq/drivers/net/imq.c |
2 | --- linux-2.6.32/drivers/net/imq.c 1970-01-01 02:00:00.000000000 +0200 | |
3 | +++ linux-2.6.32-imq/drivers/net/imq.c 2009-12-11 15:08:01.958734740 +0200 | |
4 | @@ -0,0 +1,632 @@ | |
2380c486 JR |
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 | |
7f07242b | 55 | + * of qdisc_restart() and moved qdisc_run() to tasklet to avoid |
2380c486 JR |
56 | + * recursive locking. New initialization routines to fix 'rmmod' not |
57 | + * working anymore. Used code from ifb.c. (Jussi Kivilinna) | |
7f07242b | 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 | + * - Port to 2.6.28 | |
71 | + * - Port to 2.6.29 + fix rmmod not working | |
72 | + * | |
73 | + * 2009/04/20 - (Jussi Kivilinna) | |
74 | + * - Use netdevice feature flags to avoid extra packet handling | |
75 | + * by core networking layer and possibly increase performance. | |
76 | + * | |
14f08cd0 | 77 | + * 2009/09/26 - (Jussi Kivilinna) |
78 | + * - Add imq_nf_reinject_lockless to fix deadlock with | |
79 | + * imq_nf_queue/imq_nf_reinject. | |
80 | + * | |
81 | + * 2009/12/08 - (Jussi Kivilinna) | |
82 | + * - Port to 2.6.32 | |
83 | + * - Add check for skb->nf_queue_entry==NULL in imq_dev_xmit() | |
84 | + * - Also add better error checking for skb->nf_queue_entry usage | |
85 | + * | |
2380c486 JR |
86 | + * Also, many thanks to pablo Sebastian Greco for making the initial |
87 | + * patch and to those who helped the testing. | |
88 | + * | |
89 | + * More info at: http://www.linuximq.net/ (Andre Correa) | |
90 | + */ | |
91 | + | |
92 | +#include <linux/module.h> | |
93 | +#include <linux/kernel.h> | |
94 | +#include <linux/moduleparam.h> | |
7f07242b | 95 | +#include <linux/list.h> |
2380c486 JR |
96 | +#include <linux/skbuff.h> |
97 | +#include <linux/netdevice.h> | |
7f07242b | 98 | +#include <linux/etherdevice.h> |
2380c486 JR |
99 | +#include <linux/rtnetlink.h> |
100 | +#include <linux/if_arp.h> | |
101 | +#include <linux/netfilter.h> | |
102 | +#include <linux/netfilter_ipv4.h> | |
103 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
104 | + #include <linux/netfilter_ipv6.h> | |
105 | +#endif | |
106 | +#include <linux/imq.h> | |
107 | +#include <net/pkt_sched.h> | |
108 | +#include <net/netfilter/nf_queue.h> | |
109 | + | |
2380c486 JR |
110 | +static nf_hookfn imq_nf_hook; |
111 | + | |
112 | +static struct nf_hook_ops imq_ingress_ipv4 = { | |
113 | + .hook = imq_nf_hook, | |
114 | + .owner = THIS_MODULE, | |
115 | + .pf = PF_INET, | |
116 | + .hooknum = NF_INET_PRE_ROUTING, | |
117 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) | |
118 | + .priority = NF_IP_PRI_MANGLE + 1 | |
119 | +#else | |
120 | + .priority = NF_IP_PRI_NAT_DST + 1 | |
121 | +#endif | |
122 | +}; | |
123 | + | |
124 | +static struct nf_hook_ops imq_egress_ipv4 = { | |
125 | + .hook = imq_nf_hook, | |
126 | + .owner = THIS_MODULE, | |
127 | + .pf = PF_INET, | |
128 | + .hooknum = NF_INET_POST_ROUTING, | |
129 | +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA) | |
130 | + .priority = NF_IP_PRI_LAST | |
131 | +#else | |
132 | + .priority = NF_IP_PRI_NAT_SRC - 1 | |
133 | +#endif | |
134 | +}; | |
135 | + | |
136 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
137 | +static struct nf_hook_ops imq_ingress_ipv6 = { | |
138 | + .hook = imq_nf_hook, | |
139 | + .owner = THIS_MODULE, | |
140 | + .pf = PF_INET6, | |
141 | + .hooknum = NF_INET_PRE_ROUTING, | |
142 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) | |
143 | + .priority = NF_IP6_PRI_MANGLE + 1 | |
144 | +#else | |
145 | + .priority = NF_IP6_PRI_NAT_DST + 1 | |
146 | +#endif | |
147 | +}; | |
148 | + | |
149 | +static struct nf_hook_ops imq_egress_ipv6 = { | |
150 | + .hook = imq_nf_hook, | |
151 | + .owner = THIS_MODULE, | |
152 | + .pf = PF_INET6, | |
153 | + .hooknum = NF_INET_POST_ROUTING, | |
154 | +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA) | |
155 | + .priority = NF_IP6_PRI_LAST | |
156 | +#else | |
157 | + .priority = NF_IP6_PRI_NAT_SRC - 1 | |
158 | +#endif | |
159 | +}; | |
160 | +#endif | |
161 | + | |
162 | +#if defined(CONFIG_IMQ_NUM_DEVS) | |
163 | +static unsigned int numdevs = CONFIG_IMQ_NUM_DEVS; | |
164 | +#else | |
165 | +static unsigned int numdevs = IMQ_MAX_DEVS; | |
166 | +#endif | |
167 | + | |
7f07242b | 168 | +static DEFINE_SPINLOCK(imq_nf_queue_lock); |
169 | + | |
2380c486 JR |
170 | +static struct net_device *imq_devs_cache[IMQ_MAX_DEVS]; |
171 | + | |
7f07242b | 172 | + |
2380c486 JR |
173 | +static struct net_device_stats *imq_get_stats(struct net_device *dev) |
174 | +{ | |
175 | + return &dev->stats; | |
176 | +} | |
177 | + | |
178 | +/* called for packets kfree'd in qdiscs at places other than enqueue */ | |
179 | +static void imq_skb_destructor(struct sk_buff *skb) | |
180 | +{ | |
181 | + struct nf_queue_entry *entry = skb->nf_queue_entry; | |
182 | + | |
14f08cd0 | 183 | + skb->nf_queue_entry = NULL; |
184 | + | |
2380c486 | 185 | + if (entry) { |
7f07242b | 186 | + nf_queue_entry_release_refs(entry); |
187 | + kfree(entry); | |
188 | + } | |
189 | + | |
190 | + skb_restore_cb(skb); /* kfree backup */ | |
191 | +} | |
192 | + | |
14f08cd0 | 193 | +/* locking not needed when called from imq_nf_queue */ |
194 | +static void imq_nf_reinject_lockless(struct nf_queue_entry *entry, | |
195 | + unsigned int verdict) | |
196 | +{ | |
197 | + int status; | |
198 | + | |
199 | + if (!entry->next_outfn) { | |
200 | + nf_reinject(entry, verdict); | |
201 | + return; | |
202 | + } | |
203 | + | |
204 | + status = entry->next_outfn(entry, entry->next_queuenum); | |
205 | + if (status < 0) { | |
206 | + nf_queue_entry_release_refs(entry); | |
207 | + kfree_skb(entry->skb); | |
208 | + kfree(entry); | |
209 | + } | |
210 | +} | |
211 | + | |
7f07242b | 212 | +static void imq_nf_reinject(struct nf_queue_entry *entry, unsigned int verdict) |
213 | +{ | |
214 | + int status; | |
215 | + | |
216 | + if (!entry->next_outfn) { | |
217 | + spin_lock_bh(&imq_nf_queue_lock); | |
218 | + nf_reinject(entry, verdict); | |
219 | + spin_unlock_bh(&imq_nf_queue_lock); | |
220 | + return; | |
221 | + } | |
222 | + | |
223 | + rcu_read_lock(); | |
224 | + local_bh_disable(); | |
225 | + status = entry->next_outfn(entry, entry->next_queuenum); | |
226 | + local_bh_enable(); | |
227 | + if (status < 0) { | |
228 | + nf_queue_entry_release_refs(entry); | |
229 | + kfree_skb(entry->skb); | |
2380c486 JR |
230 | + kfree(entry); |
231 | + } | |
7f07242b | 232 | + |
233 | + rcu_read_unlock(); | |
2380c486 JR |
234 | +} |
235 | + | |
14f08cd0 | 236 | +static netdev_tx_t imq_dev_xmit(struct sk_buff *skb, struct net_device *dev) |
2380c486 | 237 | +{ |
14f08cd0 | 238 | + struct nf_queue_entry *entry = skb->nf_queue_entry; |
239 | + | |
240 | + skb->nf_queue_entry = NULL; | |
241 | + dev->trans_start = jiffies; | |
242 | + | |
2380c486 JR |
243 | + dev->stats.tx_bytes += skb->len; |
244 | + dev->stats.tx_packets++; | |
245 | + | |
14f08cd0 | 246 | + if (entry == NULL) { |
247 | + /* We don't know what is going on here.. packet is queued for | |
248 | + * imq device, but (probably) not by us. | |
249 | + * | |
250 | + * If this packet was not send here by imq_nf_queue(), then | |
251 | + * skb_save_cb() was not used and skb_free() should not show: | |
252 | + * WARNING: IMQ: kfree_skb: skb->cb_next:.. | |
253 | + * and/or | |
254 | + * WARNING: IMQ: kfree_skb: skb->nf_queue_entry... | |
255 | + * | |
256 | + * However if this message is shown, then IMQ is somehow broken | |
257 | + * and you should report this to linuximq.net. | |
258 | + */ | |
259 | + | |
260 | + /* imq_dev_xmit is black hole that eats all packets, report that | |
261 | + * we eat this packet happily and increase dropped counters. | |
262 | + */ | |
263 | + | |
264 | + dev->stats.tx_dropped++; | |
265 | + dev_kfree_skb(skb); | |
266 | + | |
267 | + return NETDEV_TX_OK; | |
268 | + } | |
269 | + | |
270 | + skb_restore_cb(skb); /* restore skb->cb */ | |
271 | + | |
2380c486 JR |
272 | + skb->imq_flags = 0; |
273 | + skb->destructor = NULL; | |
274 | + | |
14f08cd0 | 275 | + imq_nf_reinject(entry, NF_ACCEPT); |
7f07242b | 276 | + |
14f08cd0 | 277 | + return NETDEV_TX_OK; |
2380c486 JR |
278 | +} |
279 | + | |
280 | +static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num) | |
281 | +{ | |
282 | + struct net_device *dev; | |
7f07242b | 283 | + struct sk_buff *skb_orig, *skb, *skb_shared; |
2380c486 | 284 | + struct Qdisc *q; |
7f07242b | 285 | + struct netdev_queue *txq; |
286 | + int users, index; | |
287 | + int retval = -EINVAL; | |
288 | + | |
289 | + index = entry->skb->imq_flags & IMQ_F_IFMASK; | |
290 | + if (unlikely(index > numdevs - 1)) { | |
291 | + if (net_ratelimit()) | |
292 | + printk(KERN_WARNING | |
293 | + "IMQ: invalid device specified, highest is %u\n", | |
294 | + numdevs - 1); | |
295 | + retval = -EINVAL; | |
296 | + goto out; | |
297 | + } | |
2380c486 JR |
298 | + |
299 | + /* check for imq device by index from cache */ | |
300 | + dev = imq_devs_cache[index]; | |
7f07242b | 301 | + if (unlikely(!dev)) { |
2380c486 JR |
302 | + char buf[8]; |
303 | + | |
304 | + /* get device by name and cache result */ | |
305 | + snprintf(buf, sizeof(buf), "imq%d", index); | |
306 | + dev = dev_get_by_name(&init_net, buf); | |
307 | + if (!dev) { | |
308 | + /* not found ?!*/ | |
309 | + BUG(); | |
7f07242b | 310 | + retval = -ENODEV; |
311 | + goto out; | |
2380c486 JR |
312 | + } |
313 | + | |
314 | + imq_devs_cache[index] = dev; | |
7f07242b | 315 | + dev_put(dev); |
2380c486 JR |
316 | + } |
317 | + | |
7f07242b | 318 | + if (unlikely(!(dev->flags & IFF_UP))) { |
2380c486 | 319 | + entry->skb->imq_flags = 0; |
14f08cd0 | 320 | + imq_nf_reinject_lockless(entry, NF_ACCEPT); |
7f07242b | 321 | + retval = 0; |
322 | + goto out; | |
2380c486 JR |
323 | + } |
324 | + dev->last_rx = jiffies; | |
325 | + | |
7f07242b | 326 | + skb = entry->skb; |
327 | + skb_orig = NULL; | |
328 | + | |
329 | + /* skb has owner? => make clone */ | |
330 | + if (unlikely(skb->destructor)) { | |
331 | + skb_orig = skb; | |
332 | + skb = skb_clone(skb, GFP_ATOMIC); | |
333 | + if (!skb) { | |
334 | + retval = -ENOMEM; | |
335 | + goto out; | |
336 | + } | |
337 | + entry->skb = skb; | |
2380c486 | 338 | + } |
2380c486 | 339 | + |
7f07242b | 340 | + skb->nf_queue_entry = entry; |
341 | + | |
342 | + dev->stats.rx_bytes += skb->len; | |
2380c486 JR |
343 | + dev->stats.rx_packets++; |
344 | + | |
7f07242b | 345 | + txq = dev_pick_tx(dev, skb); |
2380c486 | 346 | + |
7f07242b | 347 | + q = rcu_dereference(txq->qdisc); |
348 | + if (unlikely(!q->enqueue)) | |
349 | + goto packet_not_eaten_by_imq_dev; | |
2380c486 | 350 | + |
7f07242b | 351 | + spin_lock_bh(qdisc_lock(q)); |
352 | + | |
353 | + users = atomic_read(&skb->users); | |
354 | + | |
355 | + skb_shared = skb_get(skb); /* increase reference count by one */ | |
356 | + skb_save_cb(skb_shared); /* backup skb->cb, as qdisc layer will | |
357 | + overwrite it */ | |
358 | + qdisc_enqueue_root(skb_shared, q); /* might kfree_skb */ | |
359 | + | |
360 | + if (likely(atomic_read(&skb_shared->users) == users + 1)) { | |
361 | + kfree_skb(skb_shared); /* decrease reference count by one */ | |
362 | + | |
363 | + skb->destructor = &imq_skb_destructor; | |
364 | + | |
365 | + /* cloned? */ | |
366 | + if (skb_orig) | |
367 | + kfree_skb(skb_orig); /* free original */ | |
368 | + | |
369 | + spin_unlock_bh(qdisc_lock(q)); | |
370 | + | |
371 | + /* schedule qdisc dequeue */ | |
372 | + __netif_schedule(q); | |
373 | + | |
374 | + retval = 0; | |
375 | + goto out; | |
376 | + } else { | |
377 | + skb_restore_cb(skb_shared); /* restore skb->cb */ | |
14f08cd0 | 378 | + skb->nf_queue_entry = NULL; |
7f07242b | 379 | + /* qdisc dropped packet and decreased skb reference count of |
380 | + * skb, so we don't really want to and try refree as that would | |
381 | + * actually destroy the skb. */ | |
382 | + spin_unlock_bh(qdisc_lock(q)); | |
383 | + goto packet_not_eaten_by_imq_dev; | |
384 | + } | |
385 | + | |
386 | +packet_not_eaten_by_imq_dev: | |
387 | + /* cloned? restore original */ | |
388 | + if (skb_orig) { | |
389 | + kfree_skb(skb); | |
390 | + entry->skb = skb_orig; | |
391 | + } | |
392 | + retval = -1; | |
393 | +out: | |
394 | + return retval; | |
2380c486 JR |
395 | +} |
396 | + | |
397 | +static struct nf_queue_handler nfqh = { | |
398 | + .name = "imq", | |
399 | + .outfn = imq_nf_queue, | |
400 | +}; | |
401 | + | |
2380c486 JR |
402 | +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff *pskb, |
403 | + const struct net_device *indev, | |
404 | + const struct net_device *outdev, | |
405 | + int (*okfn)(struct sk_buff *)) | |
406 | +{ | |
407 | + if (pskb->imq_flags & IMQ_F_ENQUEUE) | |
408 | + return NF_QUEUE; | |
409 | + | |
410 | + return NF_ACCEPT; | |
411 | +} | |
412 | + | |
413 | +static int imq_close(struct net_device *dev) | |
414 | +{ | |
2380c486 | 415 | + netif_stop_queue(dev); |
2380c486 JR |
416 | + return 0; |
417 | +} | |
418 | + | |
419 | +static int imq_open(struct net_device *dev) | |
420 | +{ | |
2380c486 | 421 | + netif_start_queue(dev); |
2380c486 JR |
422 | + return 0; |
423 | +} | |
424 | + | |
7f07242b | 425 | +static const struct net_device_ops imq_netdev_ops = { |
426 | + .ndo_open = imq_open, | |
427 | + .ndo_stop = imq_close, | |
428 | + .ndo_start_xmit = imq_dev_xmit, | |
429 | + .ndo_get_stats = imq_get_stats, | |
430 | +}; | |
431 | + | |
2380c486 JR |
432 | +static void imq_setup(struct net_device *dev) |
433 | +{ | |
7f07242b | 434 | + dev->netdev_ops = &imq_netdev_ops; |
2380c486 JR |
435 | + dev->type = ARPHRD_VOID; |
436 | + dev->mtu = 16000; | |
437 | + dev->tx_queue_len = 11000; | |
438 | + dev->flags = IFF_NOARP; | |
7f07242b | 439 | + dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | |
440 | + NETIF_F_GSO | NETIF_F_HW_CSUM | | |
441 | + NETIF_F_HIGHDMA; | |
14f08cd0 | 442 | + dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; |
7f07242b | 443 | +} |
444 | + | |
445 | +static int imq_validate(struct nlattr *tb[], struct nlattr *data[]) | |
446 | +{ | |
447 | + int ret = 0; | |
448 | + | |
449 | + if (tb[IFLA_ADDRESS]) { | |
450 | + if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) { | |
451 | + ret = -EINVAL; | |
452 | + goto end; | |
453 | + } | |
454 | + if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) { | |
455 | + ret = -EADDRNOTAVAIL; | |
456 | + goto end; | |
457 | + } | |
458 | + } | |
459 | + return 0; | |
460 | +end: | |
461 | + printk(KERN_WARNING "IMQ: imq_validate failed (%d)\n", ret); | |
462 | + return ret; | |
2380c486 JR |
463 | +} |
464 | + | |
465 | +static struct rtnl_link_ops imq_link_ops __read_mostly = { | |
466 | + .kind = "imq", | |
7f07242b | 467 | + .priv_size = 0, |
2380c486 | 468 | + .setup = imq_setup, |
7f07242b | 469 | + .validate = imq_validate, |
2380c486 JR |
470 | +}; |
471 | + | |
472 | +static int __init imq_init_hooks(void) | |
473 | +{ | |
474 | + int err; | |
475 | + | |
7f07242b | 476 | + nf_register_queue_imq_handler(&nfqh); |
2380c486 JR |
477 | + |
478 | + err = nf_register_hook(&imq_ingress_ipv4); | |
479 | + if (err) | |
7f07242b | 480 | + goto err1; |
2380c486 JR |
481 | + |
482 | + err = nf_register_hook(&imq_egress_ipv4); | |
483 | + if (err) | |
7f07242b | 484 | + goto err2; |
2380c486 JR |
485 | + |
486 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
2380c486 JR |
487 | + err = nf_register_hook(&imq_ingress_ipv6); |
488 | + if (err) | |
7f07242b | 489 | + goto err3; |
2380c486 JR |
490 | + |
491 | + err = nf_register_hook(&imq_egress_ipv6); | |
492 | + if (err) | |
7f07242b | 493 | + goto err4; |
2380c486 JR |
494 | +#endif |
495 | + | |
496 | + return 0; | |
497 | + | |
498 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
2380c486 | 499 | +err4: |
7f07242b | 500 | + nf_unregister_hook(&imq_ingress_ipv6); |
501 | +err3: | |
2380c486 JR |
502 | + nf_unregister_hook(&imq_egress_ipv4); |
503 | +#endif | |
2380c486 | 504 | +err2: |
7f07242b | 505 | + nf_unregister_hook(&imq_ingress_ipv4); |
2380c486 | 506 | +err1: |
7f07242b | 507 | + nf_unregister_queue_imq_handler(); |
2380c486 JR |
508 | + return err; |
509 | +} | |
510 | + | |
511 | +static int __init imq_init_one(int index) | |
512 | +{ | |
513 | + struct net_device *dev; | |
514 | + int ret; | |
515 | + | |
7f07242b | 516 | + dev = alloc_netdev(0, "imq%d", imq_setup); |
2380c486 JR |
517 | + if (!dev) |
518 | + return -ENOMEM; | |
519 | + | |
520 | + ret = dev_alloc_name(dev, dev->name); | |
521 | + if (ret < 0) | |
522 | + goto fail; | |
523 | + | |
524 | + dev->rtnl_link_ops = &imq_link_ops; | |
525 | + ret = register_netdevice(dev); | |
526 | + if (ret < 0) | |
527 | + goto fail; | |
528 | + | |
529 | + return 0; | |
530 | +fail: | |
531 | + free_netdev(dev); | |
532 | + return ret; | |
533 | +} | |
534 | + | |
535 | +static int __init imq_init_devs(void) | |
536 | +{ | |
537 | + int err, i; | |
538 | + | |
7f07242b | 539 | + if (numdevs < 1 || numdevs > IMQ_MAX_DEVS) { |
2380c486 JR |
540 | + printk(KERN_ERR "IMQ: numdevs has to be betweed 1 and %u\n", |
541 | + IMQ_MAX_DEVS); | |
542 | + return -EINVAL; | |
543 | + } | |
544 | + | |
545 | + rtnl_lock(); | |
546 | + err = __rtnl_link_register(&imq_link_ops); | |
547 | + | |
548 | + for (i = 0; i < numdevs && !err; i++) | |
549 | + err = imq_init_one(i); | |
550 | + | |
551 | + if (err) { | |
552 | + __rtnl_link_unregister(&imq_link_ops); | |
553 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); | |
554 | + } | |
555 | + rtnl_unlock(); | |
556 | + | |
557 | + return err; | |
558 | +} | |
559 | + | |
560 | +static int __init imq_init_module(void) | |
561 | +{ | |
562 | + int err; | |
563 | + | |
7f07242b | 564 | +#if defined(CONFIG_IMQ_NUM_DEVS) |
565 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS > 16); | |
566 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS < 2); | |
567 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS - 1 > IMQ_F_IFMASK); | |
568 | +#endif | |
569 | + | |
2380c486 JR |
570 | + err = imq_init_devs(); |
571 | + if (err) { | |
572 | + printk(KERN_ERR "IMQ: Error trying imq_init_devs(net)\n"); | |
573 | + return err; | |
574 | + } | |
575 | + | |
576 | + err = imq_init_hooks(); | |
577 | + if (err) { | |
578 | + printk(KERN_ERR "IMQ: Error trying imq_init_hooks()\n"); | |
579 | + rtnl_link_unregister(&imq_link_ops); | |
580 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); | |
581 | + return err; | |
582 | + } | |
583 | + | |
584 | + printk(KERN_INFO "IMQ driver loaded successfully.\n"); | |
585 | + | |
586 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) | |
587 | + printk(KERN_INFO "\tHooking IMQ before NAT on PREROUTING.\n"); | |
588 | +#else | |
589 | + printk(KERN_INFO "\tHooking IMQ after NAT on PREROUTING.\n"); | |
590 | +#endif | |
591 | +#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB) | |
592 | + printk(KERN_INFO "\tHooking IMQ before NAT on POSTROUTING.\n"); | |
593 | +#else | |
594 | + printk(KERN_INFO "\tHooking IMQ after NAT on POSTROUTING.\n"); | |
595 | +#endif | |
596 | + | |
597 | + return 0; | |
598 | +} | |
599 | + | |
600 | +static void __exit imq_unhook(void) | |
601 | +{ | |
602 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
603 | + nf_unregister_hook(&imq_ingress_ipv6); | |
604 | + nf_unregister_hook(&imq_egress_ipv6); | |
2380c486 JR |
605 | +#endif |
606 | + nf_unregister_hook(&imq_ingress_ipv4); | |
607 | + nf_unregister_hook(&imq_egress_ipv4); | |
7f07242b | 608 | + |
609 | + nf_unregister_queue_imq_handler(); | |
2380c486 JR |
610 | +} |
611 | + | |
612 | +static void __exit imq_cleanup_devs(void) | |
613 | +{ | |
614 | + rtnl_link_unregister(&imq_link_ops); | |
615 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); | |
616 | +} | |
617 | + | |
618 | +static void __exit imq_exit_module(void) | |
619 | +{ | |
620 | + imq_unhook(); | |
621 | + imq_cleanup_devs(); | |
622 | + printk(KERN_INFO "IMQ driver unloaded successfully.\n"); | |
623 | +} | |
624 | + | |
625 | +module_init(imq_init_module); | |
626 | +module_exit(imq_exit_module); | |
627 | + | |
628 | +module_param(numdevs, int, 0); | |
629 | +MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will " | |
630 | + "be created)"); | |
631 | +MODULE_AUTHOR("http://www.linuximq.net"); | |
632 | +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See " | |
633 | + "http://www.linuximq.net/ for more information."); | |
634 | +MODULE_LICENSE("GPL"); | |
635 | +MODULE_ALIAS_RTNL_LINK("imq"); | |
636 | + | |
14f08cd0 | 637 | diff -U 5 -Nr linux-2.6.32/drivers/net/Kconfig linux-2.6.32-imq/drivers/net/Kconfig |
638 | --- linux-2.6.32/drivers/net/Kconfig 2009-12-03 05:51:21.000000000 +0200 | |
639 | +++ linux-2.6.32-imq/drivers/net/Kconfig 2009-12-11 14:16:42.678730699 +0200 | |
640 | @@ -107,10 +107,133 @@ | |
641 | <http://www.tldp.org/docs.html#howto>. | |
642 | ||
2380c486 JR |
643 | To compile this driver as a module, choose M here: the module |
644 | will be called eql. If unsure, say N. | |
645 | ||
646 | +config IMQ | |
647 | + tristate "IMQ (intermediate queueing device) support" | |
648 | + depends on NETDEVICES && NETFILTER | |
649 | + ---help--- | |
650 | + The IMQ device(s) is used as placeholder for QoS queueing | |
651 | + disciplines. Every packet entering/leaving the IP stack can be | |
652 | + directed through the IMQ device where it's enqueued/dequeued to the | |
653 | + attached qdisc. This allows you to treat network devices as classes | |
654 | + and distribute bandwidth among them. Iptables is used to specify | |
655 | + through which IMQ device, if any, packets travel. | |
656 | + | |
657 | + More information at: http://www.linuximq.net/ | |
658 | + | |
659 | + To compile this driver as a module, choose M here: the module | |
660 | + will be called imq. If unsure, say N. | |
661 | + | |
662 | +choice | |
663 | + prompt "IMQ behavior (PRE/POSTROUTING)" | |
664 | + depends on IMQ | |
665 | + default IMQ_BEHAVIOR_AB | |
666 | + help | |
667 | + | |
668 | + This settings defines how IMQ behaves in respect to its | |
669 | + hooking in PREROUTING and POSTROUTING. | |
670 | + | |
671 | + IMQ can work in any of the following ways: | |
672 | + | |
673 | + PREROUTING | POSTROUTING | |
674 | + -----------------|------------------- | |
675 | + #1 After NAT | After NAT | |
676 | + #2 After NAT | Before NAT | |
677 | + #3 Before NAT | After NAT | |
678 | + #4 Before NAT | Before NAT | |
679 | + | |
680 | + The default behavior is to hook before NAT on PREROUTING | |
681 | + and after NAT on POSTROUTING (#3). | |
682 | + | |
683 | + This settings are specially usefull when trying to use IMQ | |
684 | + to shape NATed clients. | |
685 | + | |
686 | + More information can be found at: www.linuximq.net | |
687 | + | |
688 | + If not sure leave the default settings alone. | |
689 | + | |
690 | +config IMQ_BEHAVIOR_AA | |
691 | + bool "IMQ AA" | |
692 | + help | |
693 | + This settings defines how IMQ behaves in respect to its | |
694 | + hooking in PREROUTING and POSTROUTING. | |
695 | + | |
696 | + Choosing this option will make IMQ hook like this: | |
697 | + | |
698 | + PREROUTING: After NAT | |
699 | + POSTROUTING: After NAT | |
700 | + | |
701 | + More information can be found at: www.linuximq.net | |
702 | + | |
703 | + If not sure leave the default settings alone. | |
704 | + | |
705 | +config IMQ_BEHAVIOR_AB | |
706 | + bool "IMQ AB" | |
707 | + help | |
708 | + This settings defines how IMQ behaves in respect to its | |
709 | + hooking in PREROUTING and POSTROUTING. | |
710 | + | |
711 | + Choosing this option will make IMQ hook like this: | |
712 | + | |
713 | + PREROUTING: After NAT | |
714 | + POSTROUTING: Before NAT | |
715 | + | |
716 | + More information can be found at: www.linuximq.net | |
717 | + | |
718 | + If not sure leave the default settings alone. | |
719 | + | |
720 | +config IMQ_BEHAVIOR_BA | |
721 | + bool "IMQ BA" | |
722 | + help | |
723 | + This settings defines how IMQ behaves in respect to its | |
724 | + hooking in PREROUTING and POSTROUTING. | |
725 | + | |
726 | + Choosing this option will make IMQ hook like this: | |
727 | + | |
728 | + PREROUTING: Before NAT | |
729 | + POSTROUTING: After NAT | |
730 | + | |
731 | + More information can be found at: www.linuximq.net | |
732 | + | |
733 | + If not sure leave the default settings alone. | |
734 | + | |
735 | +config IMQ_BEHAVIOR_BB | |
736 | + bool "IMQ BB" | |
737 | + help | |
738 | + This settings defines how IMQ behaves in respect to its | |
739 | + hooking in PREROUTING and POSTROUTING. | |
740 | + | |
741 | + Choosing this option will make IMQ hook like this: | |
742 | + | |
743 | + PREROUTING: Before NAT | |
744 | + POSTROUTING: Before NAT | |
745 | + | |
746 | + More information can be found at: www.linuximq.net | |
747 | + | |
748 | + If not sure leave the default settings alone. | |
749 | + | |
750 | +endchoice | |
751 | + | |
752 | +config IMQ_NUM_DEVS | |
753 | + | |
754 | + int "Number of IMQ devices" | |
755 | + range 2 16 | |
756 | + depends on IMQ | |
757 | + default "16" | |
758 | + help | |
759 | + | |
760 | + This settings defines how many IMQ devices will be | |
761 | + created. | |
762 | + | |
763 | + The default value is 16. | |
764 | + | |
765 | + More information can be found at: www.linuximq.net | |
766 | + | |
767 | + If not sure leave the default settings alone. | |
768 | + | |
769 | config TUN | |
770 | tristate "Universal TUN/TAP device driver support" | |
771 | select CRC32 | |
14f08cd0 | 772 | ---help--- |
773 | TUN/TAP provides packet reception and transmission for user space | |
774 | diff -U 5 -Nr linux-2.6.32/drivers/net/Makefile linux-2.6.32-imq/drivers/net/Makefile | |
775 | --- linux-2.6.32/drivers/net/Makefile 2009-12-03 05:51:21.000000000 +0200 | |
776 | +++ linux-2.6.32-imq/drivers/net/Makefile 2009-12-11 14:16:42.678730699 +0200 | |
777 | @@ -163,10 +163,11 @@ | |
778 | obj-$(CONFIG_SLHC) += slhc.o | |
779 | ||
2380c486 JR |
780 | obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o |
781 | ||
782 | obj-$(CONFIG_DUMMY) += dummy.o | |
783 | +obj-$(CONFIG_IMQ) += imq.o | |
784 | obj-$(CONFIG_IFB) += ifb.o | |
785 | obj-$(CONFIG_MACVLAN) += macvlan.o | |
786 | obj-$(CONFIG_DE600) += de600.o | |
14f08cd0 | 787 | obj-$(CONFIG_DE620) += de620.o |
788 | obj-$(CONFIG_LANCE) += lance.o | |
789 | diff -U 5 -Nr linux-2.6.32/include/linux/imq.h linux-2.6.32-imq/include/linux/imq.h | |
790 | --- linux-2.6.32/include/linux/imq.h 1970-01-01 02:00:00.000000000 +0200 | |
791 | +++ linux-2.6.32-imq/include/linux/imq.h 2009-12-11 14:16:42.678730699 +0200 | |
7f07242b | 792 | @@ -0,0 +1,13 @@ |
2380c486 JR |
793 | +#ifndef _IMQ_H |
794 | +#define _IMQ_H | |
795 | + | |
7f07242b | 796 | +/* IFMASK (16 device indexes, 0 to 15) and flag(s) fit in 5 bits */ |
797 | +#define IMQ_F_BITS 5 | |
798 | + | |
799 | +#define IMQ_F_IFMASK 0x0f | |
800 | +#define IMQ_F_ENQUEUE 0x10 | |
2380c486 | 801 | + |
7f07242b | 802 | +#define IMQ_MAX_DEVS (IMQ_F_IFMASK + 1) |
2380c486 JR |
803 | + |
804 | +#endif /* _IMQ_H */ | |
2380c486 | 805 | + |
14f08cd0 | 806 | diff -U 5 -Nr linux-2.6.32/include/linux/netdevice.h linux-2.6.32-imq/include/linux/netdevice.h |
807 | --- linux-2.6.32/include/linux/netdevice.h 2009-12-03 05:51:21.000000000 +0200 | |
808 | +++ linux-2.6.32-imq/include/linux/netdevice.h 2009-12-11 14:16:42.679730960 +0200 | |
809 | @@ -1112,10 +1112,11 @@ | |
810 | extern struct net_device *__dev_get_by_name(struct net *net, const char *name); | |
811 | extern int dev_alloc_name(struct net_device *dev, const char *name); | |
7f07242b | 812 | extern int dev_open(struct net_device *dev); |
813 | extern int dev_close(struct net_device *dev); | |
814 | extern void dev_disable_lro(struct net_device *dev); | |
815 | +extern struct netdev_queue *dev_pick_tx(struct net_device *dev, struct sk_buff *skb); | |
816 | extern int dev_queue_xmit(struct sk_buff *skb); | |
817 | extern int register_netdevice(struct net_device *dev); | |
5379d87d AM |
818 | extern void unregister_netdevice_queue(struct net_device *dev, |
819 | struct list_head *head); | |
820 | extern void unregister_netdevice_many(struct list_head *head); | |
14f08cd0 | 821 | diff -U 5 -Nr linux-2.6.32/include/linux/netfilter/xt_IMQ.h linux-2.6.32-imq/include/linux/netfilter/xt_IMQ.h |
822 | --- linux-2.6.32/include/linux/netfilter/xt_IMQ.h 1970-01-01 02:00:00.000000000 +0200 | |
823 | +++ linux-2.6.32-imq/include/linux/netfilter/xt_IMQ.h 2009-12-11 14:16:42.679730960 +0200 | |
7f07242b | 824 | @@ -0,0 +1,9 @@ |
825 | +#ifndef _XT_IMQ_H | |
826 | +#define _XT_IMQ_H | |
827 | + | |
828 | +struct xt_imq_info { | |
2380c486 JR |
829 | + unsigned int todev; /* target imq device */ |
830 | +}; | |
831 | + | |
7f07242b | 832 | +#endif /* _XT_IMQ_H */ |
833 | + | |
14f08cd0 | 834 | diff -U 5 -Nr linux-2.6.32/include/linux/netfilter_ipv4/ipt_IMQ.h linux-2.6.32-imq/include/linux/netfilter_ipv4/ipt_IMQ.h |
835 | --- linux-2.6.32/include/linux/netfilter_ipv4/ipt_IMQ.h 1970-01-01 02:00:00.000000000 +0200 | |
836 | +++ linux-2.6.32-imq/include/linux/netfilter_ipv4/ipt_IMQ.h 2009-12-11 14:16:42.679730960 +0200 | |
7f07242b | 837 | @@ -0,0 +1,10 @@ |
838 | +#ifndef _IPT_IMQ_H | |
839 | +#define _IPT_IMQ_H | |
840 | + | |
841 | +/* Backwards compatibility for old userspace */ | |
842 | +#include <linux/netfilter/xt_IMQ.h> | |
843 | + | |
844 | +#define ipt_imq_info xt_imq_info | |
845 | + | |
2380c486 | 846 | +#endif /* _IPT_IMQ_H */ |
7f07242b | 847 | + |
14f08cd0 | 848 | diff -U 5 -Nr linux-2.6.32/include/linux/netfilter_ipv6/ip6t_IMQ.h linux-2.6.32-imq/include/linux/netfilter_ipv6/ip6t_IMQ.h |
849 | --- linux-2.6.32/include/linux/netfilter_ipv6/ip6t_IMQ.h 1970-01-01 02:00:00.000000000 +0200 | |
850 | +++ linux-2.6.32-imq/include/linux/netfilter_ipv6/ip6t_IMQ.h 2009-12-11 14:16:42.679730960 +0200 | |
7f07242b | 851 | @@ -0,0 +1,10 @@ |
2380c486 JR |
852 | +#ifndef _IP6T_IMQ_H |
853 | +#define _IP6T_IMQ_H | |
854 | + | |
7f07242b | 855 | +/* Backwards compatibility for old userspace */ |
856 | +#include <linux/netfilter/xt_IMQ.h> | |
857 | + | |
858 | +#define ip6t_imq_info xt_imq_info | |
2380c486 JR |
859 | + |
860 | +#endif /* _IP6T_IMQ_H */ | |
7f07242b | 861 | + |
14f08cd0 | 862 | diff -U 5 -Nr linux-2.6.32/include/linux/skbuff.h linux-2.6.32-imq/include/linux/skbuff.h |
863 | --- linux-2.6.32/include/linux/skbuff.h 2009-12-03 05:51:21.000000000 +0200 | |
864 | +++ linux-2.6.32-imq/include/linux/skbuff.h 2009-12-11 14:16:42.680730834 +0200 | |
865 | @@ -27,10 +27,13 @@ | |
866 | #include <linux/textsearch.h> | |
867 | #include <net/checksum.h> | |
7f07242b | 868 | #include <linux/rcupdate.h> |
869 | #include <linux/dmaengine.h> | |
870 | #include <linux/hrtimer.h> | |
871 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
872 | +#include <linux/imq.h> | |
873 | +#endif | |
874 | ||
14f08cd0 | 875 | /* Don't change this without changing skb_csum_unnecessary! */ |
876 | #define CHECKSUM_NONE 0 | |
877 | #define CHECKSUM_UNNECESSARY 1 | |
878 | #define CHECKSUM_COMPLETE 2 | |
879 | @@ -328,10 +331,13 @@ | |
880 | * layer. Please put your private variables there. If you | |
881 | * want to keep them across layers you have to do a skb_clone() | |
7f07242b | 882 | * first. This is owned by whoever has the skb queued ATM. |
883 | */ | |
884 | char cb[48]; | |
885 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
886 | + void *cb_next; | |
887 | +#endif | |
888 | ||
889 | unsigned int len, | |
890 | data_len; | |
14f08cd0 | 891 | __u16 mac_len, |
892 | hdr_len; | |
893 | @@ -360,10 +366,13 @@ | |
894 | void (*destructor)(struct sk_buff *skb); | |
895 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | |
2380c486 JR |
896 | struct nf_conntrack *nfct; |
897 | struct sk_buff *nfct_reasm; | |
898 | #endif | |
899 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
2380c486 JR |
900 | + struct nf_queue_entry *nf_queue_entry; |
901 | +#endif | |
902 | #ifdef CONFIG_BRIDGE_NETFILTER | |
903 | struct nf_bridge_info *nf_bridge; | |
904 | #endif | |
14f08cd0 | 905 | |
906 | int iif; | |
907 | @@ -381,10 +390,14 @@ | |
7f07242b | 908 | #endif |
14f08cd0 | 909 | kmemcheck_bitfield_end(flags2); |
910 | ||
7e46296a | 911 | /* 0/14 bit hole */ |
14f08cd0 | 912 | |
7f07242b | 913 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
914 | + __u8 imq_flags:IMQ_F_BITS; | |
915 | +#endif | |
14f08cd0 | 916 | + |
7f07242b | 917 | #ifdef CONFIG_NET_DMA |
918 | dma_cookie_t dma_cookie; | |
7f07242b | 919 | #endif |
14f08cd0 | 920 | #ifdef CONFIG_NETWORK_SECMARK |
921 | __u32 secmark; | |
922 | @@ -435,10 +448,16 @@ | |
923 | static inline struct rtable *skb_rtable(const struct sk_buff *skb) | |
924 | { | |
925 | return (struct rtable *)skb_dst(skb); | |
926 | } | |
7f07242b | 927 | |
928 | + | |
929 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
930 | +extern int skb_save_cb(struct sk_buff *skb); | |
931 | +extern int skb_restore_cb(struct sk_buff *skb); | |
932 | +#endif | |
933 | + | |
934 | extern void kfree_skb(struct sk_buff *skb); | |
14f08cd0 | 935 | extern void consume_skb(struct sk_buff *skb); |
7f07242b | 936 | extern void __kfree_skb(struct sk_buff *skb); |
937 | extern struct sk_buff *__alloc_skb(unsigned int size, | |
14f08cd0 | 938 | gfp_t priority, int fclone, int node); |
939 | @@ -1970,10 +1989,14 @@ | |
940 | nf_conntrack_get(src->nfct); | |
941 | dst->nfctinfo = src->nfctinfo; | |
2380c486 JR |
942 | dst->nfct_reasm = src->nfct_reasm; |
943 | nf_conntrack_get_reasm(src->nfct_reasm); | |
944 | #endif | |
945 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
946 | + dst->imq_flags = src->imq_flags; | |
947 | + dst->nf_queue_entry = src->nf_queue_entry; | |
948 | +#endif | |
949 | #ifdef CONFIG_BRIDGE_NETFILTER | |
950 | dst->nf_bridge = src->nf_bridge; | |
951 | nf_bridge_get(src->nf_bridge); | |
14f08cd0 | 952 | #endif |
953 | } | |
954 | diff -U 5 -Nr linux-2.6.32/include/net/netfilter/nf_queue.h linux-2.6.32-imq/include/net/netfilter/nf_queue.h | |
955 | --- linux-2.6.32/include/net/netfilter/nf_queue.h 2009-12-03 05:51:21.000000000 +0200 | |
956 | +++ linux-2.6.32-imq/include/net/netfilter/nf_queue.h 2009-12-11 14:16:42.680730834 +0200 | |
957 | @@ -11,10 +11,16 @@ | |
958 | u_int8_t pf; | |
959 | unsigned int hook; | |
7f07242b | 960 | struct net_device *indev; |
961 | struct net_device *outdev; | |
962 | int (*okfn)(struct sk_buff *); | |
963 | + | |
964 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
965 | + int (*next_outfn)(struct nf_queue_entry *entry, | |
966 | + unsigned int queuenum); | |
967 | + unsigned int next_queuenum; | |
968 | +#endif | |
969 | }; | |
970 | ||
971 | #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry)) | |
14f08cd0 | 972 | |
973 | /* Packet queuing */ | |
974 | @@ -28,7 +34,13 @@ | |
975 | const struct nf_queue_handler *qh); | |
976 | extern int nf_unregister_queue_handler(u_int8_t pf, | |
7f07242b | 977 | const struct nf_queue_handler *qh); |
978 | extern void nf_unregister_queue_handlers(const struct nf_queue_handler *qh); | |
979 | extern void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict); | |
980 | +extern void nf_queue_entry_release_refs(struct nf_queue_entry *entry); | |
981 | + | |
982 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
983 | +extern void nf_register_queue_imq_handler(const struct nf_queue_handler *qh); | |
984 | +extern void nf_unregister_queue_imq_handler(void); | |
985 | +#endif | |
986 | ||
987 | #endif /* _NF_QUEUE_H */ | |
14f08cd0 | 988 | diff -U 5 -Nr linux-2.6.32/net/core/dev.c linux-2.6.32-imq/net/core/dev.c |
989 | --- linux-2.6.32/net/core/dev.c 2009-12-03 05:51:21.000000000 +0200 | |
990 | +++ linux-2.6.32-imq/net/core/dev.c 2009-12-11 14:16:42.681731014 +0200 | |
991 | @@ -94,10 +94,13 @@ | |
992 | #include <linux/notifier.h> | |
993 | #include <linux/skbuff.h> | |
2380c486 JR |
994 | #include <net/net_namespace.h> |
995 | #include <net/sock.h> | |
996 | #include <linux/rtnetlink.h> | |
997 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
998 | +#include <linux/imq.h> | |
999 | +#endif | |
1000 | #include <linux/proc_fs.h> | |
1001 | #include <linux/seq_file.h> | |
1002 | #include <linux/stat.h> | |
14f08cd0 | 1003 | #include <linux/if_bridge.h> |
1004 | #include <linux/if_macvlan.h> | |
1005 | @@ -1702,11 +1705,15 @@ | |
1006 | { | |
1007 | const struct net_device_ops *ops = dev->netdev_ops; | |
5379d87d | 1008 | int rc = NETDEV_TX_OK; |
7f07242b | 1009 | |
2380c486 JR |
1010 | if (likely(!skb->next)) { |
1011 | - if (!list_empty(&ptype_all)) | |
1012 | + if (!list_empty(&ptype_all) | |
1013 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1014 | + && !(skb->imq_flags & IMQ_F_ENQUEUE) | |
1015 | +#endif | |
1016 | + ) | |
1017 | dev_queue_xmit_nit(skb, dev); | |
1018 | ||
1019 | if (netif_needs_gso(dev, skb)) { | |
14f08cd0 | 1020 | if (unlikely(dev_gso_segment(skb))) |
1021 | goto out_kfree_skb; | |
5379d87d AM |
1022 | @@ -1787,7 +1794,7 @@ |
1023 | return queue_index; | |
7f07242b | 1024 | } |
1025 | ||
1026 | -static struct netdev_queue *dev_pick_tx(struct net_device *dev, | |
5379d87d AM |
1027 | +struct netdev_queue *dev_pick_tx(struct net_device *dev, |
1028 | struct sk_buff *skb) | |
7f07242b | 1029 | { |
5379d87d | 1030 | u16 queue_index; |
14f08cd0 | 1031 | @@ -1801,10 +1807,11 @@ |
1032 | queue_index = skb_tx_hash(dev, skb); | |
1033 | ||
7f07242b | 1034 | skb_set_queue_mapping(skb, queue_index); |
1035 | return netdev_get_tx_queue(dev, queue_index); | |
1036 | } | |
1037 | +EXPORT_SYMBOL(dev_pick_tx); | |
1038 | ||
14f08cd0 | 1039 | static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, |
1040 | struct net_device *dev, | |
1041 | struct netdev_queue *txq) | |
1042 | { | |
1043 | diff -U 5 -Nr linux-2.6.32/net/core/skbuff.c linux-2.6.32-imq/net/core/skbuff.c | |
1044 | --- linux-2.6.32/net/core/skbuff.c 2009-12-03 05:51:21.000000000 +0200 | |
1045 | +++ linux-2.6.32-imq/net/core/skbuff.c 2009-12-11 15:12:39.294981618 +0200 | |
1046 | @@ -70,10 +70,13 @@ | |
1047 | ||
1048 | #include "kmap_skb.h" | |
7f07242b | 1049 | |
1050 | static struct kmem_cache *skbuff_head_cache __read_mostly; | |
1051 | static struct kmem_cache *skbuff_fclone_cache __read_mostly; | |
1052 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1053 | +static struct kmem_cache *skbuff_cb_store_cache __read_mostly; | |
1054 | +#endif | |
1055 | ||
1056 | static void sock_pipe_buf_release(struct pipe_inode_info *pipe, | |
1057 | struct pipe_buffer *buf) | |
14f08cd0 | 1058 | { |
1059 | put_page(buf->page); | |
1060 | @@ -89,10 +92,87 @@ | |
1061 | struct pipe_buffer *buf) | |
1062 | { | |
7f07242b | 1063 | return 1; |
1064 | } | |
1065 | ||
1066 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1067 | +/* Control buffer save/restore for IMQ devices */ | |
1068 | +struct skb_cb_table { | |
1069 | + void *cb_next; | |
1070 | + atomic_t refcnt; | |
1071 | + char cb[48]; | |
1072 | +}; | |
2380c486 | 1073 | + |
7f07242b | 1074 | +static DEFINE_SPINLOCK(skb_cb_store_lock); |
1075 | + | |
1076 | +int skb_save_cb(struct sk_buff *skb) | |
2380c486 | 1077 | +{ |
7f07242b | 1078 | + struct skb_cb_table *next; |
1079 | + | |
1080 | + next = kmem_cache_alloc(skbuff_cb_store_cache, GFP_ATOMIC); | |
1081 | + if (!next) | |
1082 | + return -ENOMEM; | |
2380c486 | 1083 | + |
7f07242b | 1084 | + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb)); |
2380c486 | 1085 | + |
7f07242b | 1086 | + memcpy(next->cb, skb->cb, sizeof(skb->cb)); |
1087 | + next->cb_next = skb->cb_next; | |
1088 | + | |
1089 | + atomic_set(&next->refcnt, 1); | |
1090 | + | |
1091 | + skb->cb_next = next; | |
1092 | + return 0; | |
2380c486 | 1093 | +} |
7f07242b | 1094 | +EXPORT_SYMBOL(skb_save_cb); |
2380c486 | 1095 | + |
7f07242b | 1096 | +int skb_restore_cb(struct sk_buff *skb) |
2380c486 | 1097 | +{ |
7f07242b | 1098 | + struct skb_cb_table *next; |
2380c486 | 1099 | + |
7f07242b | 1100 | + if (!skb->cb_next) |
2380c486 | 1101 | + return 0; |
7f07242b | 1102 | + |
1103 | + next = skb->cb_next; | |
1104 | + | |
1105 | + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb)); | |
1106 | + | |
1107 | + memcpy(skb->cb, next->cb, sizeof(skb->cb)); | |
1108 | + skb->cb_next = next->cb_next; | |
1109 | + | |
1110 | + spin_lock(&skb_cb_store_lock); | |
1111 | + | |
1112 | + if (atomic_dec_and_test(&next->refcnt)) { | |
1113 | + kmem_cache_free(skbuff_cb_store_cache, next); | |
2380c486 JR |
1114 | + } |
1115 | + | |
7f07242b | 1116 | + spin_unlock(&skb_cb_store_lock); |
1117 | + | |
1118 | + return 0; | |
2380c486 | 1119 | +} |
7f07242b | 1120 | +EXPORT_SYMBOL(skb_restore_cb); |
2380c486 | 1121 | + |
14f08cd0 | 1122 | +static void skb_copy_stored_cb(struct sk_buff *new, const struct sk_buff *__old) |
7f07242b | 1123 | +{ |
1124 | + struct skb_cb_table *next; | |
14f08cd0 | 1125 | + struct sk_buff *old; |
7f07242b | 1126 | + |
14f08cd0 | 1127 | + if (!__old->cb_next) { |
1128 | + new->cb_next = NULL; | |
7f07242b | 1129 | + return; |
1130 | + } | |
1131 | + | |
1132 | + spin_lock(&skb_cb_store_lock); | |
1133 | + | |
14f08cd0 | 1134 | + old = (struct sk_buff *)__old; |
1135 | + | |
7f07242b | 1136 | + next = old->cb_next; |
1137 | + atomic_inc(&next->refcnt); | |
1138 | + new->cb_next = next; | |
1139 | + | |
1140 | + spin_unlock(&skb_cb_store_lock); | |
1141 | +} | |
1142 | +#endif | |
1143 | ||
1144 | /* Pipe buffer operations for a socket. */ | |
5379d87d | 1145 | static const struct pipe_buf_operations sock_pipe_buf_ops = { |
14f08cd0 | 1146 | .can_merge = 0, |
1147 | .map = generic_pipe_buf_map, | |
1148 | @@ -396,10 +476,30 @@ | |
1149 | #endif | |
1150 | if (skb->destructor) { | |
7f07242b | 1151 | WARN_ON(in_irq()); |
1152 | skb->destructor(skb); | |
1153 | } | |
1154 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1155 | + /* This should not happen. When it does, avoid memleak by restoring | |
1156 | + the chain of cb-backups. */ | |
1157 | + while(skb->cb_next != NULL) { | |
14f08cd0 | 1158 | + if (net_ratelimit()) |
1159 | + printk(KERN_WARNING "IMQ: kfree_skb: skb->cb_next: " | |
1160 | + "%08x\n", (unsigned int)skb->cb_next); | |
1161 | + | |
7f07242b | 1162 | + skb_restore_cb(skb); |
1163 | + } | |
14f08cd0 | 1164 | + /* This should not happen either, nf_queue_entry is nullified in |
1165 | + * imq_dev_xmit(). If we have non-NULL nf_queue_entry then we are | |
1166 | + * leaking entry pointers, maybe memory. We don't know if this is | |
1167 | + * pointer to already freed memory, or should this be freed. | |
1168 | + * If this happens we need to add refcounting, etc for nf_queue_entry. | |
1169 | + */ | |
1170 | + if (skb->nf_queue_entry && net_ratelimit()) | |
1171 | + printk(KERN_WARNING | |
1172 | + "IMQ: kfree_skb: skb->nf_queue_entry != NULL"); | |
7f07242b | 1173 | +#endif |
1174 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) | |
1175 | nf_conntrack_put(skb->nfct); | |
1176 | nf_conntrack_put_reasm(skb->nfct_reasm); | |
14f08cd0 | 1177 | #endif |
1178 | #ifdef CONFIG_BRIDGE_NETFILTER | |
1179 | @@ -533,10 +633,13 @@ | |
1180 | skb_dst_set(new, dst_clone(skb_dst(old))); | |
1181 | #ifdef CONFIG_XFRM | |
7f07242b | 1182 | new->sp = secpath_get(old->sp); |
1183 | #endif | |
1184 | memcpy(new->cb, old->cb, sizeof(old->cb)); | |
1185 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1186 | + skb_copy_stored_cb(new, old); | |
1187 | +#endif | |
13e5c3b1 | 1188 | new->csum = old->csum; |
7f07242b | 1189 | new->local_df = old->local_df; |
13e5c3b1 | 1190 | new->pkt_type = old->pkt_type; |
14f08cd0 | 1191 | new->ip_summed = old->ip_summed; |
1192 | skb_copy_queue_mapping(new, old); | |
1193 | @@ -2774,10 +2877,17 @@ | |
1194 | (2*sizeof(struct sk_buff)) + | |
1195 | sizeof(atomic_t), | |
7f07242b | 1196 | 0, |
1197 | SLAB_HWCACHE_ALIGN|SLAB_PANIC, | |
1198 | NULL); | |
1199 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1200 | + skbuff_cb_store_cache = kmem_cache_create("skbuff_cb_store_cache", | |
1201 | + sizeof(struct skb_cb_table), | |
1202 | + 0, | |
1203 | + SLAB_HWCACHE_ALIGN|SLAB_PANIC, | |
1204 | + NULL); | |
1205 | +#endif | |
1206 | } | |
1207 | ||
1208 | /** | |
14f08cd0 | 1209 | * skb_to_sgvec - Fill a scatter-gather list from a socket buffer |
1210 | * @skb: Socket buffer containing the buffers to be mapped | |
1211 | diff -U 5 -Nr linux-2.6.32/net/netfilter/Kconfig linux-2.6.32-imq/net/netfilter/Kconfig | |
1212 | --- linux-2.6.32/net/netfilter/Kconfig 2009-12-03 05:51:21.000000000 +0200 | |
1213 | +++ linux-2.6.32-imq/net/netfilter/Kconfig 2009-12-11 14:16:42.681731014 +0200 | |
1214 | @@ -394,10 +394,22 @@ | |
1215 | echo netfilter-ssh > /sys/class/leds/<ledname>/trigger | |
7f07242b | 1216 | |
14f08cd0 | 1217 | For more information on the LEDs available on your system, see |
1218 | Documentation/leds-class.txt | |
7f07242b | 1219 | |
1220 | +config NETFILTER_XT_TARGET_IMQ | |
1221 | + tristate '"IMQ" target support' | |
1222 | + depends on NETFILTER_XTABLES | |
1223 | + depends on IP_NF_MANGLE || IP6_NF_MANGLE | |
1224 | + select IMQ | |
1225 | + default m if NETFILTER_ADVANCED=n | |
1226 | + help | |
1227 | + This option adds a `IMQ' target which is used to specify if and | |
1228 | + to which imq device packets should get enqueued/dequeued. | |
2380c486 | 1229 | + |
7f07242b | 1230 | + To compile it as a module, choose M here. If unsure, say N. |
1231 | + | |
1232 | config NETFILTER_XT_TARGET_MARK | |
1233 | tristate '"MARK" target support' | |
1234 | default m if NETFILTER_ADVANCED=n | |
14f08cd0 | 1235 | help |
1236 | This option adds a `MARK' target, which allows you to create rules | |
1237 | diff -U 5 -Nr linux-2.6.32/net/netfilter/Makefile linux-2.6.32-imq/net/netfilter/Makefile | |
1238 | --- linux-2.6.32/net/netfilter/Makefile 2009-12-03 05:51:21.000000000 +0200 | |
1239 | +++ linux-2.6.32-imq/net/netfilter/Makefile 2009-12-11 14:16:42.681731014 +0200 | |
1240 | @@ -44,10 +44,11 @@ | |
1241 | obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o | |
1242 | obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o | |
1243 | obj-$(CONFIG_NETFILTER_XT_TARGET_CONNSECMARK) += xt_CONNSECMARK.o | |
7f07242b | 1244 | obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o |
1245 | obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o | |
7f07242b | 1246 | +obj-$(CONFIG_NETFILTER_XT_TARGET_IMQ) += xt_IMQ.o |
14f08cd0 | 1247 | obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o |
7f07242b | 1248 | obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o |
1249 | obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o | |
1250 | obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o | |
14f08cd0 | 1251 | obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o |
1252 | diff -U 5 -Nr linux-2.6.32/net/netfilter/nf_queue.c linux-2.6.32-imq/net/netfilter/nf_queue.c | |
1253 | --- linux-2.6.32/net/netfilter/nf_queue.c 2009-12-03 05:51:21.000000000 +0200 | |
1254 | +++ linux-2.6.32-imq/net/netfilter/nf_queue.c 2009-12-11 14:16:42.681731014 +0200 | |
1255 | @@ -18,10 +18,30 @@ | |
1256 | */ | |
1257 | static const struct nf_queue_handler *queue_handler[NFPROTO_NUMPROTO] __read_mostly; | |
7f07242b | 1258 | |
1259 | static DEFINE_MUTEX(queue_handler_mutex); | |
1260 | ||
1261 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1262 | +static const struct nf_queue_handler *queue_imq_handler; | |
1263 | + | |
1264 | +void nf_register_queue_imq_handler(const struct nf_queue_handler *qh) | |
2380c486 | 1265 | +{ |
7f07242b | 1266 | + mutex_lock(&queue_handler_mutex); |
1267 | + rcu_assign_pointer(queue_imq_handler, qh); | |
1268 | + mutex_unlock(&queue_handler_mutex); | |
2380c486 | 1269 | +} |
7f07242b | 1270 | +EXPORT_SYMBOL(nf_register_queue_imq_handler); |
2380c486 | 1271 | + |
7f07242b | 1272 | +void nf_unregister_queue_imq_handler(void) |
2380c486 | 1273 | +{ |
7f07242b | 1274 | + mutex_lock(&queue_handler_mutex); |
1275 | + rcu_assign_pointer(queue_imq_handler, NULL); | |
1276 | + mutex_unlock(&queue_handler_mutex); | |
2380c486 | 1277 | +} |
7f07242b | 1278 | +EXPORT_SYMBOL(nf_unregister_queue_imq_handler); |
1279 | +#endif | |
2380c486 | 1280 | + |
7f07242b | 1281 | /* return EBUSY when somebody else is registered, return EEXIST if the |
1282 | * same handler is registered, return 0 in case of success. */ | |
1283 | int nf_register_queue_handler(u_int8_t pf, const struct nf_queue_handler *qh) | |
14f08cd0 | 1284 | { |
1285 | int ret; | |
1286 | @@ -78,11 +98,11 @@ | |
1287 | ||
1288 | synchronize_rcu(); | |
7f07242b | 1289 | } |
1290 | EXPORT_SYMBOL_GPL(nf_unregister_queue_handlers); | |
1291 | ||
1292 | -static void nf_queue_entry_release_refs(struct nf_queue_entry *entry) | |
1293 | +void nf_queue_entry_release_refs(struct nf_queue_entry *entry) | |
1294 | { | |
1295 | /* Release those devices we held, or Alexey will kill me. */ | |
1296 | if (entry->indev) | |
14f08cd0 | 1297 | dev_put(entry->indev); |
1298 | if (entry->outdev) | |
1299 | @@ -98,10 +118,11 @@ | |
1300 | } | |
1301 | #endif | |
7f07242b | 1302 | /* Drop reference to owner of hook which queued us. */ |
1303 | module_put(entry->elem->owner); | |
1304 | } | |
1305 | +EXPORT_SYMBOL_GPL(nf_queue_entry_release_refs); | |
1306 | ||
1307 | /* | |
1308 | * Any packet that leaves via this function must come back | |
14f08cd0 | 1309 | * through nf_reinject(). |
1310 | */ | |
1311 | @@ -119,16 +140,30 @@ | |
1312 | struct net_device *physindev; | |
1313 | struct net_device *physoutdev; | |
7f07242b | 1314 | #endif |
1315 | const struct nf_afinfo *afinfo; | |
1316 | const struct nf_queue_handler *qh; | |
1317 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1318 | + const struct nf_queue_handler *qih = NULL; | |
1319 | +#endif | |
1320 | ||
1321 | /* QUEUE == DROP if noone is waiting, to be safe. */ | |
1322 | rcu_read_lock(); | |
1323 | ||
1324 | qh = rcu_dereference(queue_handler[pf]); | |
1325 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1326 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
1327 | + if (pf == PF_INET || pf == PF_INET6) | |
1328 | +#else | |
1329 | + if (pf == PF_INET) | |
1330 | +#endif | |
1331 | + qih = rcu_dereference(queue_imq_handler); | |
2380c486 | 1332 | + |
7f07242b | 1333 | + if (!qh && !qih) |
1334 | +#else /* !IMQ */ | |
1335 | if (!qh) | |
1336 | +#endif | |
1337 | goto err_unlock; | |
2380c486 | 1338 | |
7f07242b | 1339 | afinfo = nf_get_afinfo(pf); |
14f08cd0 | 1340 | if (!afinfo) |
1341 | goto err_unlock; | |
1342 | @@ -143,10 +178,14 @@ | |
1343 | .pf = pf, | |
1344 | .hook = hook, | |
7f07242b | 1345 | .indev = indev, |
1346 | .outdev = outdev, | |
1347 | .okfn = okfn, | |
1348 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1349 | + .next_outfn = qh ? qh->outfn : NULL, | |
1350 | + .next_queuenum = queuenum, | |
1351 | +#endif | |
1352 | }; | |
2380c486 | 1353 | |
7f07242b | 1354 | /* If it's going away, ignore hook. */ |
14f08cd0 | 1355 | if (!try_module_get(entry->elem->owner)) { |
1356 | rcu_read_unlock(); | |
1357 | @@ -168,12 +207,23 @@ | |
1358 | if (physoutdev) | |
1359 | dev_hold(physoutdev); | |
7f07242b | 1360 | } |
1361 | #endif | |
1362 | afinfo->saveroute(skb, entry); | |
1363 | + | |
1364 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1365 | + if (qih) { | |
1366 | + status = qih->outfn(entry, queuenum); | |
1367 | + goto imq_skip_queue; | |
1368 | + } | |
1369 | +#endif | |
1370 | + | |
1371 | status = qh->outfn(entry, queuenum); | |
1372 | ||
1373 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) | |
1374 | +imq_skip_queue: | |
1375 | +#endif | |
1376 | rcu_read_unlock(); | |
1377 | ||
1378 | if (status < 0) { | |
14f08cd0 | 1379 | nf_queue_entry_release_refs(entry); |
1380 | goto err; | |
1381 | diff -U 5 -Nr linux-2.6.32/net/netfilter/xt_IMQ.c linux-2.6.32-imq/net/netfilter/xt_IMQ.c | |
1382 | --- linux-2.6.32/net/netfilter/xt_IMQ.c 1970-01-01 02:00:00.000000000 +0200 | |
1383 | +++ linux-2.6.32-imq/net/netfilter/xt_IMQ.c 2009-12-11 14:16:42.681731014 +0200 | |
7f07242b | 1384 | @@ -0,0 +1,73 @@ |
2380c486 JR |
1385 | +/* |
1386 | + * This target marks packets to be enqueued to an imq device | |
1387 | + */ | |
1388 | +#include <linux/module.h> | |
1389 | +#include <linux/skbuff.h> | |
7f07242b | 1390 | +#include <linux/netfilter/x_tables.h> |
1391 | +#include <linux/netfilter/xt_IMQ.h> | |
2380c486 JR |
1392 | +#include <linux/imq.h> |
1393 | + | |
1394 | +static unsigned int imq_target(struct sk_buff *pskb, | |
7f07242b | 1395 | + const struct xt_target_param *par) |
2380c486 | 1396 | +{ |
7f07242b | 1397 | + const struct xt_imq_info *mr = par->targinfo; |
2380c486 | 1398 | + |
7f07242b | 1399 | + pskb->imq_flags = (mr->todev & IMQ_F_IFMASK) | IMQ_F_ENQUEUE; |
2380c486 JR |
1400 | + |
1401 | + return XT_CONTINUE; | |
1402 | +} | |
1403 | + | |
7f07242b | 1404 | +static bool imq_checkentry(const struct xt_tgchk_param *par) |
2380c486 | 1405 | +{ |
7f07242b | 1406 | + struct xt_imq_info *mr = par->targinfo; |
2380c486 | 1407 | + |
7f07242b | 1408 | + if (mr->todev > IMQ_MAX_DEVS - 1) { |
2380c486 JR |
1409 | + printk(KERN_WARNING |
1410 | + "IMQ: invalid device specified, highest is %u\n", | |
7f07242b | 1411 | + IMQ_MAX_DEVS - 1); |
2380c486 JR |
1412 | + return 0; |
1413 | + } | |
1414 | + | |
1415 | + return 1; | |
1416 | +} | |
1417 | + | |
7f07242b | 1418 | +static struct xt_target xt_imq_reg[] __read_mostly = { |
1419 | + { | |
1420 | + .name = "IMQ", | |
1421 | + .family = AF_INET, | |
1422 | + .checkentry = imq_checkentry, | |
1423 | + .target = imq_target, | |
1424 | + .targetsize = sizeof(struct xt_imq_info), | |
1425 | + .table = "mangle", | |
1426 | + .me = THIS_MODULE | |
1427 | + }, | |
1428 | + { | |
1429 | + .name = "IMQ", | |
1430 | + .family = AF_INET6, | |
1431 | + .checkentry = imq_checkentry, | |
1432 | + .target = imq_target, | |
1433 | + .targetsize = sizeof(struct xt_imq_info), | |
1434 | + .table = "mangle", | |
1435 | + .me = THIS_MODULE | |
1436 | + }, | |
2380c486 JR |
1437 | +}; |
1438 | + | |
7f07242b | 1439 | +static int __init imq_init(void) |
2380c486 | 1440 | +{ |
7f07242b | 1441 | + return xt_register_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg)); |
2380c486 JR |
1442 | +} |
1443 | + | |
7f07242b | 1444 | +static void __exit imq_fini(void) |
2380c486 | 1445 | +{ |
7f07242b | 1446 | + xt_unregister_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg)); |
2380c486 JR |
1447 | +} |
1448 | + | |
7f07242b | 1449 | +module_init(imq_init); |
1450 | +module_exit(imq_fini); | |
2380c486 JR |
1451 | + |
1452 | +MODULE_AUTHOR("http://www.linuximq.net"); | |
1453 | +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information."); | |
1454 | +MODULE_LICENSE("GPL"); | |
7f07242b | 1455 | +MODULE_ALIAS("ipt_IMQ"); |
1456 | +MODULE_ALIAS("ip6t_IMQ"); | |
2380c486 | 1457 | + |