]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-imq.patch
- fix function redefinition
[packages/kernel.git] / kernel-imq.patch
1 net: add Intermediate Queueing Device (imq)
2
3 From: Jussi Kivilinna <jussi.kivilinna@iki.fi>
4
5 This patch is for kernel version 3.12.4+.
6
7 See: http://linuximq.net/
8
9 Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
10 ---
11  drivers/net/Kconfig                     |  119 ++++
12  drivers/net/Makefile                    |    1 
13  drivers/net/imq.c                       | 1007 +++++++++++++++++++++++++++++++
14  include/linux/imq.h                     |   13 
15  include/linux/netfilter/xt_IMQ.h        |    9 
16  include/linux/netfilter_ipv4/ipt_IMQ.h  |   10 
17  include/linux/netfilter_ipv6/ip6t_IMQ.h |   10 
18  include/linux/skbuff.h                  |   22 +
19  include/net/netfilter/nf_queue.h        |    6 
20  include/uapi/linux/netfilter.h          |    3 
21  net/core/dev.c                          |    8 
22  net/core/skbuff.c                       |  112 +++
23  net/ipv6/ip6_output.c                   |   10 
24  net/netfilter/Kconfig                   |   12 
25  net/netfilter/Makefile                  |    1 
26  net/netfilter/core.c                    |    6 
27  net/netfilter/nf_internals.h            |    2 
28  net/netfilter/nf_queue.c                |   36 +
29  net/netfilter/xt_IMQ.c                  |   72 ++
30  19 files changed, 1449 insertions(+), 10 deletions(-)
31  create mode 100644 drivers/net/imq.c
32  create mode 100644 include/linux/imq.h
33  create mode 100644 include/linux/netfilter/xt_IMQ.h
34  create mode 100644 include/linux/netfilter_ipv4/ipt_IMQ.h
35  create mode 100644 include/linux/netfilter_ipv6/ip6t_IMQ.h
36  create mode 100644 net/netfilter/xt_IMQ.c
37
38 diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
39 index b45b240..5a20da0 100644
40 --- a/drivers/net/Kconfig
41 +++ b/drivers/net/Kconfig
42 @@ -203,6 +203,125 @@ config RIONET_RX_SIZE
43         depends on RIONET
44         default "128"
45  
46 +config IMQ
47 +       tristate "IMQ (intermediate queueing device) support"
48 +       depends on NETDEVICES && NETFILTER
49 +       ---help---
50 +         The IMQ device(s) is used as placeholder for QoS queueing
51 +         disciplines. Every packet entering/leaving the IP stack can be
52 +         directed through the IMQ device where it's enqueued/dequeued to the
53 +         attached qdisc. This allows you to treat network devices as classes
54 +         and distribute bandwidth among them. Iptables is used to specify
55 +         through which IMQ device, if any, packets travel.
56 +
57 +         More information at: http://www.linuximq.net/
58 +
59 +         To compile this driver as a module, choose M here: the module
60 +         will be called imq.  If unsure, say N.
61 +
62 +choice
63 +       prompt "IMQ behavior (PRE/POSTROUTING)"
64 +       depends on IMQ
65 +       default IMQ_BEHAVIOR_AB
66 +       help
67 +         This setting defines how IMQ behaves in respect to its
68 +         hooking in PREROUTING and POSTROUTING.
69 +
70 +         IMQ can work in any of the following ways:
71 +
72 +             PREROUTING   |      POSTROUTING
73 +         -----------------|-------------------
74 +         #1  After NAT    |      After NAT
75 +         #2  After NAT    |      Before NAT
76 +         #3  Before NAT   |      After NAT
77 +         #4  Before NAT   |      Before NAT
78 +
79 +         The default behavior is to hook before NAT on PREROUTING
80 +         and after NAT on POSTROUTING (#3).
81 +
82 +         This settings are specially usefull when trying to use IMQ
83 +         to shape NATed clients.
84 +
85 +         More information can be found at: www.linuximq.net
86 +
87 +         If not sure leave the default settings alone.
88 +
89 +config IMQ_BEHAVIOR_AA
90 +       bool "IMQ AA"
91 +       help
92 +         This setting defines how IMQ behaves in respect to its
93 +         hooking in PREROUTING and POSTROUTING.
94 +
95 +         Choosing this option will make IMQ hook like this:
96 +
97 +         PREROUTING:   After NAT
98 +         POSTROUTING:  After NAT
99 +
100 +         More information can be found at: www.linuximq.net
101 +
102 +         If not sure leave the default settings alone.
103 +
104 +config IMQ_BEHAVIOR_AB
105 +       bool "IMQ AB"
106 +       help
107 +         This setting defines how IMQ behaves in respect to its
108 +         hooking in PREROUTING and POSTROUTING.
109 +
110 +         Choosing this option will make IMQ hook like this:
111 +
112 +         PREROUTING:   After NAT
113 +         POSTROUTING:  Before NAT
114 +
115 +         More information can be found at: www.linuximq.net
116 +
117 +         If not sure leave the default settings alone.
118 +
119 +config IMQ_BEHAVIOR_BA
120 +       bool "IMQ BA"
121 +       help
122 +         This setting defines how IMQ behaves in respect to its
123 +         hooking in PREROUTING and POSTROUTING.
124 +
125 +         Choosing this option will make IMQ hook like this:
126 +
127 +         PREROUTING:   Before NAT
128 +         POSTROUTING:  After NAT
129 +
130 +         More information can be found at: www.linuximq.net
131 +
132 +         If not sure leave the default settings alone.
133 +
134 +config IMQ_BEHAVIOR_BB
135 +       bool "IMQ BB"
136 +       help
137 +         This setting defines how IMQ behaves in respect to its
138 +         hooking in PREROUTING and POSTROUTING.
139 +
140 +         Choosing this option will make IMQ hook like this:
141 +
142 +         PREROUTING:   Before NAT
143 +         POSTROUTING:  Before NAT
144 +
145 +         More information can be found at: www.linuximq.net
146 +
147 +         If not sure leave the default settings alone.
148 +
149 +endchoice
150 +
151 +config IMQ_NUM_DEVS
152 +       int "Number of IMQ devices"
153 +       range 2 16
154 +       depends on IMQ
155 +       default "16"
156 +       help
157 +         This setting defines how many IMQ devices will be created.
158 +
159 +         The default value is 16.
160 +
161 +         More information can be found at: www.linuximq.net
162 +
163 +         If not sure leave the default settings alone.
164 +
165  config TUN
166         tristate "Universal TUN/TAP device driver support"
167         select CRC32
168 diff --git a/drivers/net/Makefile b/drivers/net/Makefile
169 index 3fef8a8..12dafc0 100644
170 --- a/drivers/net/Makefile
171 +++ b/drivers/net/Makefile
172 @@ -9,6 +9,7 @@ obj-$(CONFIG_BONDING) += bonding/
173  obj-$(CONFIG_DUMMY) += dummy.o
174  obj-$(CONFIG_EQUALIZER) += eql.o
175  obj-$(CONFIG_IFB) += ifb.o
176 +obj-$(CONFIG_IMQ) += imq.o
177  obj-$(CONFIG_MACVLAN) += macvlan.o
178  obj-$(CONFIG_MACVTAP) += macvtap.o
179  obj-$(CONFIG_MII) += mii.o
180 diff --git a/drivers/net/imq.c b/drivers/net/imq.c
181 new file mode 100644
182 index 0000000..801bc8c
183 --- /dev/null
184 +++ b/drivers/net/imq.c
185 @@ -0,0 +1,1010 @@
186 +/*
187 + *             Pseudo-driver for the intermediate queue device.
188 + *
189 + *             This program is free software; you can redistribute it and/or
190 + *             modify it under the terms of the GNU General Public License
191 + *             as published by the Free Software Foundation; either version
192 + *             2 of the License, or (at your option) any later version.
193 + *
194 + * Authors:    Patrick McHardy, <kaber@trash.net>
195 + *
196 + *            The first version was written by Martin Devera, <devik@cdi.cz>
197 + *
198 + * Credits:    Jan Rafaj <imq2t@cedric.vabo.cz>
199 + *              - Update patch to 2.4.21
200 + *             Sebastian Strollo <sstrollo@nortelnetworks.com>
201 + *              - Fix "Dead-loop on netdevice imq"-issue
202 + *             Marcel Sebek <sebek64@post.cz>
203 + *              - Update to 2.6.2-rc1
204 + *
205 + *            After some time of inactivity there is a group taking care
206 + *            of IMQ again: http://www.linuximq.net
207 + *
208 + *
209 + *            2004/06/30 - New version of IMQ patch to kernels <=2.6.7
210 + *             including the following changes:
211 + *
212 + *            - Correction of ipv6 support "+"s issue (Hasso Tepper)
213 + *            - Correction of imq_init_devs() issue that resulted in
214 + *            kernel OOPS unloading IMQ as module (Norbert Buchmuller)
215 + *            - Addition of functionality to choose number of IMQ devices
216 + *            during kernel config (Andre Correa)
217 + *            - Addition of functionality to choose how IMQ hooks on
218 + *            PRE and POSTROUTING (after or before NAT) (Andre Correa)
219 + *            - Cosmetic corrections (Norbert Buchmuller) (Andre Correa)
220 + *
221 + *
222 + *             2005/12/16 - IMQ versions between 2.6.7 and 2.6.13 were
223 + *             released with almost no problems. 2.6.14-x was released
224 + *             with some important changes: nfcache was removed; After
225 + *             some weeks of trouble we figured out that some IMQ fields
226 + *             in skb were missing in skbuff.c - skb_clone and copy_skb_header.
227 + *             These functions are correctly patched by this new patch version.
228 + *
229 + *             Thanks for all who helped to figure out all the problems with
230 + *             2.6.14.x: Patrick McHardy, Rune Kock, VeNoMouS, Max CtRiX,
231 + *             Kevin Shanahan, Richard Lucassen, Valery Dachev (hopefully
232 + *             I didn't forget anybody). I apologize again for my lack of time.
233 + *
234 + *
235 + *             2008/06/17 - 2.6.25 - Changed imq.c to use qdisc_run() instead
236 + *             of qdisc_restart() and moved qdisc_run() to tasklet to avoid
237 + *             recursive locking. New initialization routines to fix 'rmmod' not
238 + *             working anymore. Used code from ifb.c. (Jussi Kivilinna)
239 + *
240 + *             2008/08/06 - 2.6.26 - (JK)
241 + *              - Replaced tasklet with 'netif_schedule()'.
242 + *              - Cleaned up and added comments for imq_nf_queue().
243 + *
244 + *             2009/04/12
245 + *              - Add skb_save_cb/skb_restore_cb helper functions for backuping
246 + *                control buffer. This is needed because qdisc-layer on kernels
247 + *                2.6.27 and newer overwrite control buffer. (Jussi Kivilinna)
248 + *              - Add better locking for IMQ device. Hopefully this will solve
249 + *                SMP issues. (Jussi Kivilinna)
250 + *              - Port to 2.6.27
251 + *              - Port to 2.6.28
252 + *              - Port to 2.6.29 + fix rmmod not working
253 + *
254 + *             2009/04/20 - (Jussi Kivilinna)
255 + *              - Use netdevice feature flags to avoid extra packet handling
256 + *                by core networking layer and possibly increase performance.
257 + *
258 + *             2009/09/26 - (Jussi Kivilinna)
259 + *              - Add imq_nf_reinject_lockless to fix deadlock with
260 + *                imq_nf_queue/imq_nf_reinject.
261 + *
262 + *             2009/12/08 - (Jussi Kivilinna)
263 + *              - Port to 2.6.32
264 + *              - Add check for skb->nf_queue_entry==NULL in imq_dev_xmit()
265 + *              - Also add better error checking for skb->nf_queue_entry usage
266 + *
267 + *             2010/02/25 - (Jussi Kivilinna)
268 + *              - Port to 2.6.33
269 + *
270 + *             2010/08/15 - (Jussi Kivilinna)
271 + *              - Port to 2.6.35
272 + *              - Simplify hook registration by using nf_register_hooks.
273 + *              - nf_reinject doesn't need spinlock around it, therefore remove
274 + *                imq_nf_reinject function. Other nf_reinject users protect
275 + *                their own data with spinlock. With IMQ however all data is
276 + *                needed is stored per skbuff, so no locking is needed.
277 + *              - Changed IMQ to use 'separate' NF_IMQ_QUEUE instead of
278 + *                NF_QUEUE, this allows working coexistance of IMQ and other
279 + *                NF_QUEUE users.
280 + *              - Make IMQ multi-queue. Number of IMQ device queues can be
281 + *                increased with 'numqueues' module parameters. Default number
282 + *                of queues is 1, in other words by default IMQ works as
283 + *                single-queue device. Multi-queue selection is based on
284 + *                IFB multi-queue patch by Changli Gao <xiaosuo@gmail.com>.
285 + *
286 + *             2011/03/18 - (Jussi Kivilinna)
287 + *              - Port to 2.6.38
288 + *
289 + *             2011/07/12 - (syoder89@gmail.com)
290 + *              - Crash fix that happens when the receiving interface has more
291 + *                than one queue (add missing skb_set_queue_mapping in
292 + *                imq_select_queue).
293 + *
294 + *             2011/07/26 - (Jussi Kivilinna)
295 + *              - Add queue mapping checks for packets exiting IMQ.
296 + *              - Port to 3.0
297 + *
298 + *             2011/08/16 - (Jussi Kivilinna)
299 + *              - Clear IFF_TX_SKB_SHARING flag that was added for linux 3.0.2
300 + *
301 + *             2011/11/03 - Germano Michel <germanomichel@gmail.com>
302 + *              - Fix IMQ for net namespaces
303 + *
304 + *             2011/11/04 - Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
305 + *              - Port to 3.1
306 + *              - Clean-up, move 'get imq device pointer by imqX name' to
307 + *                separate function from imq_nf_queue().
308 + *
309 + *             2012/01/05 - Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
310 + *              - Port to 3.2
311 + *
312 + *             2012/03/19 - Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
313 + *              - Port to 3.3
314 + *
315 + *             2012/12/12 - Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
316 + *              - Port to 3.7
317 + *              - Fix checkpatch.pl warnings
318 + *
319 + *             2013/09/10 - Jussi Kivilinna <jussi.kivilinna@iki.fi>
320 + *              - Fixed GSO handling for 3.10, see imq_nf_queue() for comments.
321 + *              - Don't copy skb->cb_next when copying or cloning skbuffs.
322 + *
323 + *             2013/09/16 - Jussi Kivilinna <jussi.kivilinna@iki.fi>
324 + *              - Port to 3.11
325 + *
326 + *             2013/11/12 - Jussi Kivilinna <jussi.kivilinna@iki.fi>
327 + *              - Port to 3.12
328 + *
329 + *            Also, many thanks to pablo Sebastian Greco for making the initial
330 + *            patch and to those who helped the testing.
331 + *
332 + *             More info at: http://www.linuximq.net/ (Andre Correa)
333 + */
334 +
335 +#include <linux/module.h>
336 +#include <linux/kernel.h>
337 +#include <linux/moduleparam.h>
338 +#include <linux/list.h>
339 +#include <linux/skbuff.h>
340 +#include <linux/netdevice.h>
341 +#include <linux/etherdevice.h>
342 +#include <linux/rtnetlink.h>
343 +#include <linux/if_arp.h>
344 +#include <linux/netfilter.h>
345 +#include <linux/netfilter_ipv4.h>
346 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
347 +       #include <linux/netfilter_ipv6.h>
348 +#endif
349 +#include <linux/imq.h>
350 +#include <net/pkt_sched.h>
351 +#include <net/netfilter/nf_queue.h>
352 +#include <net/sock.h>
353 +#include <linux/ip.h>
354 +#include <linux/ipv6.h>
355 +#include <linux/if_vlan.h>
356 +#include <linux/if_pppox.h>
357 +#include <net/ip.h>
358 +#include <net/ipv6.h>
359 +
360 +static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num);
361 +
362 +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff *pskb,
363 +                               const struct net_device *indev,
364 +                               const struct net_device *outdev,
365 +                               int (*okfn)(struct sk_buff *));
366 +
367 +static struct nf_hook_ops imq_ops[] = {
368 +       {
369 +       /* imq_ingress_ipv4 */
370 +               .hook           = imq_nf_hook,
371 +               .owner          = THIS_MODULE,
372 +               .pf             = PF_INET,
373 +               .hooknum        = NF_INET_PRE_ROUTING,
374 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
375 +               .priority       = NF_IP_PRI_MANGLE + 1,
376 +#else
377 +               .priority       = NF_IP_PRI_NAT_DST + 1,
378 +#endif
379 +       },
380 +       {
381 +       /* imq_egress_ipv4 */
382 +               .hook           = imq_nf_hook,
383 +               .owner          = THIS_MODULE,
384 +               .pf             = PF_INET,
385 +               .hooknum        = NF_INET_POST_ROUTING,
386 +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
387 +               .priority       = NF_IP_PRI_LAST,
388 +#else
389 +               .priority       = NF_IP_PRI_NAT_SRC - 1,
390 +#endif
391 +       },
392 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
393 +       {
394 +       /* imq_ingress_ipv6 */
395 +               .hook           = imq_nf_hook,
396 +               .owner          = THIS_MODULE,
397 +               .pf             = PF_INET6,
398 +               .hooknum        = NF_INET_PRE_ROUTING,
399 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
400 +               .priority       = NF_IP6_PRI_MANGLE + 1,
401 +#else
402 +               .priority       = NF_IP6_PRI_NAT_DST + 1,
403 +#endif
404 +       },
405 +       {
406 +       /* imq_egress_ipv6 */
407 +               .hook           = imq_nf_hook,
408 +               .owner          = THIS_MODULE,
409 +               .pf             = PF_INET6,
410 +               .hooknum        = NF_INET_POST_ROUTING,
411 +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA)
412 +               .priority       = NF_IP6_PRI_LAST,
413 +#else
414 +               .priority       = NF_IP6_PRI_NAT_SRC - 1,
415 +#endif
416 +       },
417 +#endif
418 +};
419 +
420 +#if defined(CONFIG_IMQ_NUM_DEVS)
421 +static int numdevs = CONFIG_IMQ_NUM_DEVS;
422 +#else
423 +static int numdevs = IMQ_MAX_DEVS;
424 +#endif
425 +
426 +static struct net_device *imq_devs_cache[IMQ_MAX_DEVS];
427 +
428 +#define IMQ_MAX_QUEUES 32
429 +static int numqueues = 1;
430 +static u32 imq_hashrnd;
431 +
432 +static inline __be16 pppoe_proto(const struct sk_buff *skb)
433 +{
434 +       return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN +
435 +                       sizeof(struct pppoe_hdr)));
436 +}
437 +
438 +static u16 imq_hash(struct net_device *dev, struct sk_buff *skb)
439 +{
440 +       unsigned int pull_len;
441 +       u16 protocol = skb->protocol;
442 +       u32 addr1, addr2;
443 +       u32 hash, ihl = 0;
444 +       union {
445 +               u16 in16[2];
446 +               u32 in32;
447 +       } ports;
448 +       u8 ip_proto;
449 +
450 +       pull_len = 0;
451 +
452 +recheck:
453 +       switch (protocol) {
454 +       case htons(ETH_P_8021Q): {
455 +               if (unlikely(skb_pull(skb, VLAN_HLEN) == NULL))
456 +                       goto other;
457 +
458 +               pull_len += VLAN_HLEN;
459 +               skb->network_header += VLAN_HLEN;
460 +
461 +               protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
462 +               goto recheck;
463 +       }
464 +
465 +       case htons(ETH_P_PPP_SES): {
466 +               if (unlikely(skb_pull(skb, PPPOE_SES_HLEN) == NULL))
467 +                       goto other;
468 +
469 +               pull_len += PPPOE_SES_HLEN;
470 +               skb->network_header += PPPOE_SES_HLEN;
471 +
472 +               protocol = pppoe_proto(skb);
473 +               goto recheck;
474 +       }
475 +
476 +       case htons(ETH_P_IP): {
477 +               const struct iphdr *iph = ip_hdr(skb);
478 +
479 +               if (unlikely(!pskb_may_pull(skb, sizeof(struct iphdr))))
480 +                       goto other;
481 +
482 +               addr1 = iph->daddr;
483 +               addr2 = iph->saddr;
484 +
485 +               ip_proto = !(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) ?
486 +                                iph->protocol : 0;
487 +               ihl = ip_hdrlen(skb);
488 +
489 +               break;
490 +       }
491 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
492 +       case htons(ETH_P_IPV6): {
493 +               const struct ipv6hdr *iph = ipv6_hdr(skb);
494 +               __be16 fo = 0;
495 +
496 +               if (unlikely(!pskb_may_pull(skb, sizeof(struct ipv6hdr))))
497 +                       goto other;
498 +
499 +               addr1 = iph->daddr.s6_addr32[3];
500 +               addr2 = iph->saddr.s6_addr32[3];
501 +               ihl = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &ip_proto,
502 +                                      &fo);
503 +               if (unlikely(ihl < 0))
504 +                       goto other;
505 +
506 +               break;
507 +       }
508 +#endif
509 +       default:
510 +other:
511 +               if (pull_len != 0) {
512 +                       skb_push(skb, pull_len);
513 +                       skb->network_header -= pull_len;
514 +               }
515 +
516 +               return (u16)(ntohs(protocol) % dev->real_num_tx_queues);
517 +       }
518 +
519 +       if (addr1 > addr2)
520 +               swap(addr1, addr2);
521 +
522 +       switch (ip_proto) {
523 +       case IPPROTO_TCP:
524 +       case IPPROTO_UDP:
525 +       case IPPROTO_DCCP:
526 +       case IPPROTO_ESP:
527 +       case IPPROTO_AH:
528 +       case IPPROTO_SCTP:
529 +       case IPPROTO_UDPLITE: {
530 +               if (likely(skb_copy_bits(skb, ihl, &ports.in32, 4) >= 0)) {
531 +                       if (ports.in16[0] > ports.in16[1])
532 +                               swap(ports.in16[0], ports.in16[1]);
533 +                       break;
534 +               }
535 +               /* fall-through */
536 +       }
537 +       default:
538 +               ports.in32 = 0;
539 +               break;
540 +       }
541 +
542 +       if (pull_len != 0) {
543 +               skb_push(skb, pull_len);
544 +               skb->network_header -= pull_len;
545 +       }
546 +
547 +       hash = jhash_3words(addr1, addr2, ports.in32, imq_hashrnd ^ ip_proto);
548 +
549 +       return (u16)(((u64)hash * dev->real_num_tx_queues) >> 32);
550 +}
551 +
552 +static inline bool sk_tx_queue_recorded(struct sock *sk)
553 +{
554 +       return (sk_tx_queue_get(sk) >= 0);
555 +}
556 +
557 +static struct netdev_queue *imq_select_queue(struct net_device *dev,
558 +                                               struct sk_buff *skb)
559 +{
560 +       u16 queue_index = 0;
561 +       u32 hash;
562 +
563 +       if (likely(dev->real_num_tx_queues == 1))
564 +               goto out;
565 +
566 +       /* IMQ can be receiving ingress or engress packets. */
567 +
568 +       /* Check first for if rx_queue is set */
569 +       if (skb_rx_queue_recorded(skb)) {
570 +               queue_index = skb_get_rx_queue(skb);
571 +               goto out;
572 +       }
573 +
574 +       /* Check if socket has tx_queue set */
575 +       if (sk_tx_queue_recorded(skb->sk)) {
576 +               queue_index = sk_tx_queue_get(skb->sk);
577 +               goto out;
578 +       }
579 +
580 +       /* Try use socket hash */
581 +       if (skb->sk && skb->sk->sk_hash) {
582 +               hash = skb->sk->sk_hash;
583 +               queue_index =
584 +                       (u16)(((u64)hash * dev->real_num_tx_queues) >> 32);
585 +               goto out;
586 +       }
587 +
588 +       /* Generate hash from packet data */
589 +       queue_index = imq_hash(dev, skb);
590 +
591 +out:
592 +       if (unlikely(queue_index >= dev->real_num_tx_queues))
593 +               queue_index = (u16)((u32)queue_index % dev->real_num_tx_queues);
594 +
595 +       skb_set_queue_mapping(skb, queue_index);
596 +       return netdev_get_tx_queue(dev, queue_index);
597 +}
598 +
599 +static struct net_device_stats *imq_get_stats(struct net_device *dev)
600 +{
601 +       return &dev->stats;
602 +}
603 +
604 +/* called for packets kfree'd in qdiscs at places other than enqueue */
605 +static void imq_skb_destructor(struct sk_buff *skb)
606 +{
607 +       struct nf_queue_entry *entry = skb->nf_queue_entry;
608 +
609 +       skb->nf_queue_entry = NULL;
610 +
611 +       if (entry) {
612 +               nf_queue_entry_release_refs(entry);
613 +               kfree(entry);
614 +       }
615 +
616 +       skb_restore_cb(skb); /* kfree backup */
617 +}
618 +
619 +static void imq_done_check_queue_mapping(struct sk_buff *skb,
620 +                                        struct net_device *dev)
621 +{
622 +       unsigned int queue_index;
623 +
624 +       /* Don't let queue_mapping be left too large after exiting IMQ */
625 +       if (likely(skb->dev != dev && skb->dev != NULL)) {
626 +               queue_index = skb_get_queue_mapping(skb);
627 +               if (unlikely(queue_index >= skb->dev->real_num_tx_queues)) {
628 +                       queue_index = (u16)((u32)queue_index %
629 +                                               skb->dev->real_num_tx_queues);
630 +                       skb_set_queue_mapping(skb, queue_index);
631 +               }
632 +       } else {
633 +               /* skb->dev was IMQ device itself or NULL, be on safe side and
634 +                * just clear queue mapping.
635 +                */
636 +               skb_set_queue_mapping(skb, 0);
637 +       }
638 +}
639 +
640 +static netdev_tx_t imq_dev_xmit(struct sk_buff *skb, struct net_device *dev)
641 +{
642 +       struct nf_queue_entry *entry = skb->nf_queue_entry;
643 +
644 +       skb->nf_queue_entry = NULL;
645 +       dev->trans_start = jiffies;
646 +
647 +       dev->stats.tx_bytes += skb->len;
648 +       dev->stats.tx_packets++;
649 +
650 +       if (unlikely(entry == NULL)) {
651 +               /* We don't know what is going on here.. packet is queued for
652 +                * imq device, but (probably) not by us.
653 +                *
654 +                * If this packet was not send here by imq_nf_queue(), then
655 +                * skb_save_cb() was not used and skb_free() should not show:
656 +                *   WARNING: IMQ: kfree_skb: skb->cb_next:..
657 +                * and/or
658 +                *   WARNING: IMQ: kfree_skb: skb->nf_queue_entry...
659 +                *
660 +                * However if this message is shown, then IMQ is somehow broken
661 +                * and you should report this to linuximq.net.
662 +                */
663 +
664 +               /* imq_dev_xmit is black hole that eats all packets, report that
665 +                * we eat this packet happily and increase dropped counters.
666 +                */
667 +
668 +               dev->stats.tx_dropped++;
669 +               dev_kfree_skb(skb);
670 +
671 +               return NETDEV_TX_OK;
672 +       }
673 +
674 +       skb_restore_cb(skb); /* restore skb->cb */
675 +
676 +       skb->imq_flags = 0;
677 +       skb->destructor = NULL;
678 +
679 +       imq_done_check_queue_mapping(skb, dev);
680 +
681 +       nf_reinject(entry, NF_ACCEPT);
682 +
683 +       return NETDEV_TX_OK;
684 +}
685 +
686 +static struct net_device *get_imq_device_by_index(int index)
687 +{
688 +       struct net_device *dev = NULL;
689 +       struct net *net;
690 +       char buf[8];
691 +
692 +       /* get device by name and cache result */
693 +       snprintf(buf, sizeof(buf), "imq%d", index);
694 +
695 +       /* Search device from all namespaces. */
696 +       for_each_net(net) {
697 +               dev = dev_get_by_name(net, buf);
698 +               if (dev)
699 +                       break;
700 +       }
701 +
702 +       if (WARN_ON_ONCE(dev == NULL)) {
703 +               /* IMQ device not found. Exotic config? */
704 +               return ERR_PTR(-ENODEV);
705 +       }
706 +
707 +       imq_devs_cache[index] = dev;
708 +       dev_put(dev);
709 +
710 +       return dev;
711 +}
712 +
713 +static struct nf_queue_entry *nf_queue_entry_dup(struct nf_queue_entry *e)
714 +{
715 +       struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC);
716 +       if (entry) {
717 +               if (nf_queue_entry_get_refs(entry))
718 +                       return entry;
719 +               kfree(entry);
720 +       }
721 +       return NULL;
722 +}
723 +
724 +#ifdef CONFIG_BRIDGE_NETFILTER
725 +/* When called from bridge netfilter, skb->data must point to MAC header
726 + * before calling skb_gso_segment(). Else, original MAC header is lost
727 + * and segmented skbs will be sent to wrong destination.
728 + */
729 +static void nf_bridge_adjust_skb_data(struct sk_buff *skb)
730 +{
731 +       if (skb->nf_bridge)
732 +               __skb_push(skb, skb->network_header - skb->mac_header);
733 +}
734 +
735 +static void nf_bridge_adjust_segmented_data(struct sk_buff *skb)
736 +{
737 +       if (skb->nf_bridge)
738 +               __skb_pull(skb, skb->network_header - skb->mac_header);
739 +}
740 +#else
741 +#define nf_bridge_adjust_skb_data(s) do {} while (0)
742 +#define nf_bridge_adjust_segmented_data(s) do {} while (0)
743 +#endif
744 +
745 +static void free_entry(struct nf_queue_entry *entry)
746 +{
747 +       nf_queue_entry_release_refs(entry);
748 +       kfree(entry);
749 +}
750 +
751 +static int __imq_nf_queue(struct nf_queue_entry *entry, struct net_device *dev);
752 +
753 +static int __imq_nf_queue_gso(struct nf_queue_entry *entry,
754 +                             struct net_device *dev, struct sk_buff *skb)
755 +{
756 +       int ret = -ENOMEM;
757 +       struct nf_queue_entry *entry_seg;
758 +
759 +       nf_bridge_adjust_segmented_data(skb);
760 +
761 +       if (skb->next == NULL) { /* last packet, no need to copy entry */
762 +               struct sk_buff *gso_skb = entry->skb;
763 +               entry->skb = skb;
764 +               ret = __imq_nf_queue(entry, dev);
765 +               if (ret)
766 +                       entry->skb = gso_skb;
767 +               return ret;
768 +       }
769 +
770 +       skb->next = NULL;
771 +
772 +       entry_seg = nf_queue_entry_dup(entry);
773 +       if (entry_seg) {
774 +               entry_seg->skb = skb;
775 +               ret = __imq_nf_queue(entry_seg, dev);
776 +               if (ret)
777 +                       free_entry(entry_seg);
778 +       }
779 +       return ret;
780 +}
781 +
782 +static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num)
783 +{
784 +       struct sk_buff *skb, *segs;
785 +       struct net_device *dev;
786 +       unsigned int queued;
787 +       int index, retval, err;
788 +
789 +       index = entry->skb->imq_flags & IMQ_F_IFMASK;
790 +       if (unlikely(index > numdevs - 1)) {
791 +               if (net_ratelimit())
792 +                       pr_warn("IMQ: invalid device specified, highest is %u\n",
793 +                               numdevs - 1);
794 +               retval = -EINVAL;
795 +               goto out_no_dev;
796 +       }
797 +
798 +       /* check for imq device by index from cache */
799 +       dev = imq_devs_cache[index];
800 +       if (unlikely(!dev)) {
801 +               dev = get_imq_device_by_index(index);
802 +               if (IS_ERR(dev)) {
803 +                       retval = PTR_ERR(dev);
804 +                       goto out_no_dev;
805 +               }
806 +       }
807 +
808 +       if (unlikely(!(dev->flags & IFF_UP))) {
809 +               entry->skb->imq_flags = 0;
810 +               retval = -ECANCELED;
811 +               goto out_no_dev;
812 +       }
813 +
814 +       if (!skb_is_gso(entry->skb))
815 +               return __imq_nf_queue(entry, dev);
816 +
817 +       /* Since 3.10.x, GSO handling moved here as result of upstream commit
818 +        * a5fedd43d5f6c94c71053a66e4c3d2e35f1731a2 (netfilter: move
819 +        * skb_gso_segment into nfnetlink_queue module).
820 +        *
821 +        * Following code replicates the gso handling from
822 +        * 'net/netfilter/nfnetlink_queue_core.c':nfqnl_enqueue_packet().
823 +        */
824 +
825 +       skb = entry->skb;
826 +
827 +       switch (entry->pf) {
828 +       case NFPROTO_IPV4:
829 +               skb->protocol = htons(ETH_P_IP);
830 +               break;
831 +       case NFPROTO_IPV6:
832 +               skb->protocol = htons(ETH_P_IPV6);
833 +               break;
834 +       }
835 +
836 +       nf_bridge_adjust_skb_data(skb);
837 +       segs = skb_gso_segment(skb, 0);
838 +       /* Does not use PTR_ERR to limit the number of error codes that can be
839 +        * returned by nf_queue.  For instance, callers rely on -ECANCELED to
840 +        * mean 'ignore this hook'.
841 +        */
842 +       err = -ENOBUFS;
843 +       if (IS_ERR(segs))
844 +               goto out_err;
845 +       queued = 0;
846 +       err = 0;
847 +       do {
848 +               struct sk_buff *nskb = segs->next;
849 +               if (nskb && nskb->next)
850 +                       nskb->cb_next = NULL;
851 +               if (err == 0)
852 +                       err = __imq_nf_queue_gso(entry, dev, segs);
853 +               if (err == 0)
854 +                       queued++;
855 +               else
856 +                       kfree_skb(segs);
857 +               segs = nskb;
858 +       } while (segs);
859 +
860 +       if (queued) {
861 +               if (err) /* some segments are already queued */
862 +                       free_entry(entry);
863 +               kfree_skb(skb);
864 +               return 0;
865 +       }
866 +
867 +out_err:
868 +       nf_bridge_adjust_segmented_data(skb);
869 +       retval = err;
870 +out_no_dev:
871 +       return retval;
872 +}
873 +
874 +static int __imq_nf_queue(struct nf_queue_entry *entry, struct net_device *dev)
875 +{
876 +       struct sk_buff *skb_orig, *skb, *skb_shared;
877 +       struct Qdisc *q;
878 +       struct netdev_queue *txq;
879 +       spinlock_t *root_lock;
880 +       int users;
881 +       int retval = -EINVAL;
882 +       unsigned int orig_queue_index;
883 +
884 +       dev->last_rx = jiffies;
885 +
886 +       skb = entry->skb;
887 +       skb_orig = NULL;
888 +
889 +       /* skb has owner? => make clone */
890 +       if (unlikely(skb->destructor)) {
891 +               skb_orig = skb;
892 +               skb = skb_clone(skb, GFP_ATOMIC);
893 +               if (unlikely(!skb)) {
894 +                       retval = -ENOMEM;
895 +                       goto out;
896 +               }
897 +               skb->cb_next = NULL;
898 +               entry->skb = skb;
899 +       }
900 +
901 +       skb->nf_queue_entry = entry;
902 +
903 +       dev->stats.rx_bytes += skb->len;
904 +       dev->stats.rx_packets++;
905 +
906 +       if (!skb->dev) {
907 +               /* skb->dev == NULL causes problems, try the find cause. */
908 +               if (net_ratelimit()) {
909 +                       dev_warn(&dev->dev,
910 +                                "received packet with skb->dev == NULL\n");
911 +                       dump_stack();
912 +               }
913 +
914 +               skb->dev = dev;
915 +       }
916 +
917 +       /* Disables softirqs for lock below */
918 +       rcu_read_lock_bh();
919 +
920 +       /* Multi-queue selection */
921 +       orig_queue_index = skb_get_queue_mapping(skb);
922 +       txq = imq_select_queue(dev, skb);
923 +
924 +       q = rcu_dereference(txq->qdisc);
925 +       if (unlikely(!q->enqueue))
926 +               goto packet_not_eaten_by_imq_dev;
927 +
928 +       root_lock = qdisc_lock(q);
929 +       spin_lock(root_lock);
930 +
931 +       users = atomic_read(&skb->users);
932 +
933 +       skb_shared = skb_get(skb); /* increase reference count by one */
934 +
935 +       /* backup skb->cb, as qdisc layer will overwrite it */
936 +       skb_save_cb(skb_shared);
937 +       qdisc_enqueue_root(skb_shared, q); /* might kfree_skb */
938 +
939 +       if (likely(atomic_read(&skb_shared->users) == users + 1)) {
940 +               kfree_skb(skb_shared); /* decrease reference count by one */
941 +
942 +               skb->destructor = &imq_skb_destructor;
943 +
944 +               /* cloned? */
945 +               if (unlikely(skb_orig))
946 +                       kfree_skb(skb_orig); /* free original */
947 +
948 +               spin_unlock(root_lock);
949 +               rcu_read_unlock_bh();
950 +
951 +               /* schedule qdisc dequeue */
952 +               __netif_schedule(q);
953 +
954 +               retval = 0;
955 +               goto out;
956 +       } else {
957 +               skb_restore_cb(skb_shared); /* restore skb->cb */
958 +               skb->nf_queue_entry = NULL;
959 +               /*
960 +                * qdisc dropped packet and decreased skb reference count of
961 +                * skb, so we don't really want to and try refree as that would
962 +                * actually destroy the skb.
963 +                */
964 +               spin_unlock(root_lock);
965 +               goto packet_not_eaten_by_imq_dev;
966 +       }
967 +
968 +packet_not_eaten_by_imq_dev:
969 +       skb_set_queue_mapping(skb, orig_queue_index);
970 +       rcu_read_unlock_bh();
971 +
972 +       /* cloned? restore original */
973 +       if (unlikely(skb_orig)) {
974 +               kfree_skb(skb);
975 +               entry->skb = skb_orig;
976 +       }
977 +       retval = -1;
978 +out:
979 +       return retval;
980 +}
981 +
982 +static unsigned int imq_nf_hook(unsigned int hook, struct sk_buff *pskb,
983 +                               const struct net_device *indev,
984 +                               const struct net_device *outdev,
985 +                               int (*okfn)(struct sk_buff *))
986 +{
987 +       return (pskb->imq_flags & IMQ_F_ENQUEUE) ? NF_IMQ_QUEUE : NF_ACCEPT;
988 +}
989 +
990 +static int imq_close(struct net_device *dev)
991 +{
992 +       netif_stop_queue(dev);
993 +       return 0;
994 +}
995 +
996 +static int imq_open(struct net_device *dev)
997 +{
998 +       netif_start_queue(dev);
999 +       return 0;
1000 +}
1001 +
1002 +static const struct net_device_ops imq_netdev_ops = {
1003 +       .ndo_open               = imq_open,
1004 +       .ndo_stop               = imq_close,
1005 +       .ndo_start_xmit         = imq_dev_xmit,
1006 +       .ndo_get_stats          = imq_get_stats,
1007 +};
1008 +
1009 +static void imq_setup(struct net_device *dev)
1010 +{
1011 +       dev->netdev_ops         = &imq_netdev_ops;
1012 +       dev->type               = ARPHRD_VOID;
1013 +       dev->mtu                = 16000; /* too small? */
1014 +       dev->tx_queue_len       = 11000; /* too big? */
1015 +       dev->flags              = IFF_NOARP;
1016 +       dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST |
1017 +                                 NETIF_F_GSO | NETIF_F_HW_CSUM |
1018 +                                 NETIF_F_HIGHDMA;
1019 +       dev->priv_flags         &= ~(IFF_XMIT_DST_RELEASE |
1020 +                                    IFF_TX_SKB_SHARING);
1021 +}
1022 +
1023 +static int imq_validate(struct nlattr *tb[], struct nlattr *data[])
1024 +{
1025 +       int ret = 0;
1026 +
1027 +       if (tb[IFLA_ADDRESS]) {
1028 +               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
1029 +                       ret = -EINVAL;
1030 +                       goto end;
1031 +               }
1032 +               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
1033 +                       ret = -EADDRNOTAVAIL;
1034 +                       goto end;
1035 +               }
1036 +       }
1037 +       return 0;
1038 +end:
1039 +       pr_warn("IMQ: imq_validate failed (%d)\n", ret);
1040 +       return ret;
1041 +}
1042 +
1043 +static struct rtnl_link_ops imq_link_ops __read_mostly = {
1044 +       .kind           = "imq",
1045 +       .priv_size      = 0,
1046 +       .setup          = imq_setup,
1047 +       .validate       = imq_validate,
1048 +};
1049 +
1050 +static const struct nf_queue_handler imq_nfqh = {
1051 +       .outfn = imq_nf_queue,
1052 +};
1053 +
1054 +static int __init imq_init_hooks(void)
1055 +{
1056 +       int ret;
1057 +
1058 +       nf_register_queue_imq_handler(&imq_nfqh);
1059 +
1060 +       ret = nf_register_hooks(imq_ops, ARRAY_SIZE(imq_ops));
1061 +       if (ret < 0)
1062 +               nf_unregister_queue_imq_handler();
1063 +
1064 +       return ret;
1065 +}
1066 +
1067 +static int __init imq_init_one(int index)
1068 +{
1069 +       struct net_device *dev;
1070 +       int ret;
1071 +
1072 +       dev = alloc_netdev_mq(0, "imq%d", imq_setup, numqueues);
1073 +       if (!dev)
1074 +               return -ENOMEM;
1075 +
1076 +       ret = dev_alloc_name(dev, dev->name);
1077 +       if (ret < 0)
1078 +               goto fail;
1079 +
1080 +       dev->rtnl_link_ops = &imq_link_ops;
1081 +       ret = register_netdevice(dev);
1082 +       if (ret < 0)
1083 +               goto fail;
1084 +
1085 +       return 0;
1086 +fail:
1087 +       free_netdev(dev);
1088 +       return ret;
1089 +}
1090 +
1091 +static int __init imq_init_devs(void)
1092 +{
1093 +       int err, i;
1094 +
1095 +       if (numdevs < 1 || numdevs > IMQ_MAX_DEVS) {
1096 +               pr_err("IMQ: numdevs has to be betweed 1 and %u\n",
1097 +                      IMQ_MAX_DEVS);
1098 +               return -EINVAL;
1099 +       }
1100 +
1101 +       if (numqueues < 1 || numqueues > IMQ_MAX_QUEUES) {
1102 +               pr_err("IMQ: numqueues has to be betweed 1 and %u\n",
1103 +                      IMQ_MAX_QUEUES);
1104 +               return -EINVAL;
1105 +       }
1106 +
1107 +       get_random_bytes(&imq_hashrnd, sizeof(imq_hashrnd));
1108 +
1109 +       rtnl_lock();
1110 +       err = __rtnl_link_register(&imq_link_ops);
1111 +
1112 +       for (i = 0; i < numdevs && !err; i++)
1113 +               err = imq_init_one(i);
1114 +
1115 +       if (err) {
1116 +               __rtnl_link_unregister(&imq_link_ops);
1117 +               memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
1118 +       }
1119 +       rtnl_unlock();
1120 +
1121 +       return err;
1122 +}
1123 +
1124 +static int __init imq_init_module(void)
1125 +{
1126 +       int err;
1127 +
1128 +#if defined(CONFIG_IMQ_NUM_DEVS)
1129 +       BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS > 16);
1130 +       BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS < 2);
1131 +       BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS - 1 > IMQ_F_IFMASK);
1132 +#endif
1133 +
1134 +       err = imq_init_devs();
1135 +       if (err) {
1136 +               pr_err("IMQ: Error trying imq_init_devs(net)\n");
1137 +               return err;
1138 +       }
1139 +
1140 +       err = imq_init_hooks();
1141 +       if (err) {
1142 +               pr_err(KERN_ERR "IMQ: Error trying imq_init_hooks()\n");
1143 +               rtnl_link_unregister(&imq_link_ops);
1144 +               memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
1145 +               return err;
1146 +       }
1147 +
1148 +       pr_info("IMQ driver loaded successfully. (numdevs = %d, numqueues = %d)\n",
1149 +               numdevs, numqueues);
1150 +
1151 +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB)
1152 +       pr_info("\tHooking IMQ before NAT on PREROUTING.\n");
1153 +#else
1154 +       pr_info("\tHooking IMQ after NAT on PREROUTING.\n");
1155 +#endif
1156 +#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB)
1157 +       pr_info("\tHooking IMQ before NAT on POSTROUTING.\n");
1158 +#else
1159 +       pr_info("\tHooking IMQ after NAT on POSTROUTING.\n");
1160 +#endif
1161 +
1162 +       return 0;
1163 +}
1164 +
1165 +static void __exit imq_unhook(void)
1166 +{
1167 +       nf_unregister_hooks(imq_ops, ARRAY_SIZE(imq_ops));
1168 +       nf_unregister_queue_imq_handler();
1169 +}
1170 +
1171 +static void __exit imq_cleanup_devs(void)
1172 +{
1173 +       rtnl_link_unregister(&imq_link_ops);
1174 +       memset(imq_devs_cache, 0, sizeof(imq_devs_cache));
1175 +}
1176 +
1177 +static void __exit imq_exit_module(void)
1178 +{
1179 +       imq_unhook();
1180 +       imq_cleanup_devs();
1181 +       pr_info("IMQ driver unloaded successfully.\n");
1182 +}
1183 +
1184 +module_init(imq_init_module);
1185 +module_exit(imq_exit_module);
1186 +
1187 +module_param(numdevs, int, 0);
1188 +module_param(numqueues, int, 0);
1189 +MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)");
1190 +MODULE_PARM_DESC(numqueues, "number of queues per IMQ device");
1191 +MODULE_AUTHOR("http://www.linuximq.net");
1192 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
1193 +MODULE_LICENSE("GPL");
1194 +MODULE_ALIAS_RTNL_LINK("imq");
1195 +
1196 diff --git a/include/linux/imq.h b/include/linux/imq.h
1197 new file mode 100644
1198 index 0000000..1babb09
1199 --- /dev/null
1200 +++ b/include/linux/imq.h
1201 @@ -0,0 +1,13 @@
1202 +#ifndef _IMQ_H
1203 +#define _IMQ_H
1204 +
1205 +/* IFMASK (16 device indexes, 0 to 15) and flag(s) fit in 5 bits */
1206 +#define IMQ_F_BITS     5
1207 +
1208 +#define IMQ_F_IFMASK   0x0f
1209 +#define IMQ_F_ENQUEUE  0x10
1210 +
1211 +#define IMQ_MAX_DEVS   (IMQ_F_IFMASK + 1)
1212 +
1213 +#endif /* _IMQ_H */
1214 +
1215 diff --git a/include/linux/netfilter/xt_IMQ.h b/include/linux/netfilter/xt_IMQ.h
1216 new file mode 100644
1217 index 0000000..9b07230
1218 --- /dev/null
1219 +++ b/include/linux/netfilter/xt_IMQ.h
1220 @@ -0,0 +1,9 @@
1221 +#ifndef _XT_IMQ_H
1222 +#define _XT_IMQ_H
1223 +
1224 +struct xt_imq_info {
1225 +       unsigned int todev;     /* target imq device */
1226 +};
1227 +
1228 +#endif /* _XT_IMQ_H */
1229 +
1230 diff --git a/include/linux/netfilter_ipv4/ipt_IMQ.h b/include/linux/netfilter_ipv4/ipt_IMQ.h
1231 new file mode 100644
1232 index 0000000..7af320f
1233 --- /dev/null
1234 +++ b/include/linux/netfilter_ipv4/ipt_IMQ.h
1235 @@ -0,0 +1,10 @@
1236 +#ifndef _IPT_IMQ_H
1237 +#define _IPT_IMQ_H
1238 +
1239 +/* Backwards compatibility for old userspace */
1240 +#include <linux/netfilter/xt_IMQ.h>
1241 +
1242 +#define ipt_imq_info xt_imq_info
1243 +
1244 +#endif /* _IPT_IMQ_H */
1245 +
1246 diff --git a/include/linux/netfilter_ipv6/ip6t_IMQ.h b/include/linux/netfilter_ipv6/ip6t_IMQ.h
1247 new file mode 100644
1248 index 0000000..198ac01
1249 --- /dev/null
1250 +++ b/include/linux/netfilter_ipv6/ip6t_IMQ.h
1251 @@ -0,0 +1,10 @@
1252 +#ifndef _IP6T_IMQ_H
1253 +#define _IP6T_IMQ_H
1254 +
1255 +/* Backwards compatibility for old userspace */
1256 +#include <linux/netfilter/xt_IMQ.h>
1257 +
1258 +#define ip6t_imq_info xt_imq_info
1259 +
1260 +#endif /* _IP6T_IMQ_H */
1261 +
1262 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
1263 index f66f346..d699b19 100644
1264 --- a/include/linux/skbuff.h
1265 +++ b/include/linux/skbuff.h
1266 @@ -33,6 +33,9 @@
1267  #include <linux/dma-mapping.h>
1268  #include <linux/netdev_features.h>
1269  #include <net/flow_keys.h>
1270 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1271 +#include <linux/imq.h>
1272 +#endif
1273  
1274  /* Don't change this without changing skb_csum_unnecessary! */
1275  #define CHECKSUM_NONE 0
1276 @@ -418,6 +421,9 @@ struct sk_buff {
1277          * first. This is owned by whoever has the skb queued ATM.
1278          */
1279         char                    cb[48] __aligned(8);
1280 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1281 +       void                    *cb_next;
1282 +#endif
1283  
1284         unsigned long           _skb_refdst;
1285  #ifdef CONFIG_XFRM
1286 @@ -453,6 +459,9 @@ struct sk_buff {
1287  #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1288         struct nf_conntrack     *nfct;
1289  #endif
1290 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1291 +       struct nf_queue_entry   *nf_queue_entry;
1292 +#endif
1293  #ifdef CONFIG_BRIDGE_NETFILTER
1294         struct nf_bridge_info   *nf_bridge;
1295  #endif
1296 @@ -490,6 +499,9 @@ struct sk_buff {
1297          */
1298         __u8                    encapsulation:1;
1299         /* 6/8 bit hole (depending on ndisc_nodetype presence) */
1300 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1301 +       __u8                    imq_flags:IMQ_F_BITS;
1302 +#endif
1303         kmemcheck_bitfield_end(flags2);
1304  
1305  #if defined CONFIG_NET_DMA || defined CONFIG_NET_RX_BUSY_POLL
1306 @@ -625,6 +637,12 @@ static inline struct rtable *skb_rtable(const struct sk_buff *skb)
1307         return (struct rtable *)skb_dst(skb);
1308  }
1309  
1310 +
1311 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1312 +extern int skb_save_cb(struct sk_buff *skb);
1313 +extern int skb_restore_cb(struct sk_buff *skb);
1314 +#endif
1315 +
1316  void kfree_skb(struct sk_buff *skb);
1317  void kfree_skb_list(struct sk_buff *segs);
1318  void skb_tx_error(struct sk_buff *skb);
1319 @@ -2635,6 +2653,10 @@ static inline void __nf_copy(struct sk_buff *dst, const struct sk_buff *src)
1320         nf_conntrack_get(src->nfct);
1321         dst->nfctinfo = src->nfctinfo;
1322  #endif
1323 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1324 +       dst->imq_flags = src->imq_flags;
1325 +       dst->nf_queue_entry = src->nf_queue_entry;
1326 +#endif
1327  #ifdef CONFIG_BRIDGE_NETFILTER
1328         dst->nf_bridge  = src->nf_bridge;
1329         nf_bridge_get(src->nf_bridge);
1330 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
1331 index aaba4bb..f6e92a4 100644
1332 --- a/include/net/netfilter/nf_queue.h
1333 +++ b/include/net/netfilter/nf_queue.h
1334 @@ -29,6 +29,12 @@ struct nf_queue_handler {
1335  void nf_register_queue_handler(const struct nf_queue_handler *qh);
1336  void nf_unregister_queue_handler(void);
1337  void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
1338 +extern void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
1339 +
1340 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1341 +extern void nf_register_queue_imq_handler(const struct nf_queue_handler *qh);
1342 +extern void nf_unregister_queue_imq_handler(void);
1343 +#endif
1344  
1345  bool nf_queue_entry_get_refs(struct nf_queue_entry *entry);
1346  void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
1347 diff --git a/include/uapi/linux/netfilter.h b/include/uapi/linux/netfilter.h
1348 index f7dc0eb..58c46a9 100644
1349 --- a/include/uapi/linux/netfilter.h
1350 +++ b/include/uapi/linux/netfilter.h
1351 @@ -13,7 +13,8 @@
1352  #define NF_QUEUE 3
1353  #define NF_REPEAT 4
1354  #define NF_STOP 5
1355 -#define NF_MAX_VERDICT NF_STOP
1356 +#define NF_IMQ_QUEUE 6
1357 +#define NF_MAX_VERDICT NF_IMQ_QUEUE
1358  
1359  /* we overload the higher bits for encoding auxiliary data such as the queue
1360   * number or errno values. Not nice, but better than additional function
1361 diff --git a/net/core/dev.c b/net/core/dev.c
1362 index 3d13874..9842f21 100644
1363 --- a/net/core/dev.c
1364 +++ b/net/core/dev.c
1365 @@ -131,6 +131,9 @@
1366  #include <linux/hashtable.h>
1367  #include <linux/vmalloc.h>
1368  #include <linux/if_macvlan.h>
1369 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1370 +#include <linux/imq.h>
1371 +#endif
1372  
1373  #include "net-sysfs.h"
1374  
1375 @@ -2595,7 +2598,12 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1376                         }
1377                 }
1378  
1379 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1380 +               if (!list_empty(&ptype_all) &&
1381 +                                       !(skb->imq_flags & IMQ_F_ENQUEUE))
1382 +#else
1383                 if (!list_empty(&ptype_all))
1384 +#endif
1385                         dev_queue_xmit_nit(skb, dev);
1386  
1387                 skb_len = skb->len;
1388 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
1389 index c28c7fe..a5f1888 100644
1390 --- a/net/core/skbuff.c
1391 +++ b/net/core/skbuff.c
1392 @@ -73,6 +73,9 @@
1393  
1394  struct kmem_cache *skbuff_head_cache __read_mostly;
1395  static struct kmem_cache *skbuff_fclone_cache __read_mostly;
1396 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1397 +static struct kmem_cache *skbuff_cb_store_cache __read_mostly;
1398 +#endif
1399  
1400  static void sock_pipe_buf_release(struct pipe_inode_info *pipe,
1401                                   struct pipe_buffer *buf)
1402 @@ -92,6 +95,82 @@ static int sock_pipe_buf_steal(struct pipe_inode_info *pipe,
1403         return 1;
1404  }
1405  
1406 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1407 +/* Control buffer save/restore for IMQ devices */
1408 +struct skb_cb_table {
1409 +       char                    cb[48] __aligned(8);
1410 +       void                    *cb_next;
1411 +       atomic_t                refcnt;
1412 +};
1413 +
1414 +static DEFINE_SPINLOCK(skb_cb_store_lock);
1415 +
1416 +int skb_save_cb(struct sk_buff *skb)
1417 +{
1418 +       struct skb_cb_table *next;
1419 +
1420 +       next = kmem_cache_alloc(skbuff_cb_store_cache, GFP_ATOMIC);
1421 +       if (!next)
1422 +               return -ENOMEM;
1423 +
1424 +       BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
1425 +
1426 +       memcpy(next->cb, skb->cb, sizeof(skb->cb));
1427 +       next->cb_next = skb->cb_next;
1428 +
1429 +       atomic_set(&next->refcnt, 1);
1430 +
1431 +       skb->cb_next = next;
1432 +       return 0;
1433 +}
1434 +EXPORT_SYMBOL(skb_save_cb);
1435 +
1436 +int skb_restore_cb(struct sk_buff *skb)
1437 +{
1438 +       struct skb_cb_table *next;
1439 +
1440 +       if (!skb->cb_next)
1441 +               return 0;
1442 +
1443 +       next = skb->cb_next;
1444 +
1445 +       BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb));
1446 +
1447 +       memcpy(skb->cb, next->cb, sizeof(skb->cb));
1448 +       skb->cb_next = next->cb_next;
1449 +
1450 +       spin_lock(&skb_cb_store_lock);
1451 +
1452 +       if (atomic_dec_and_test(&next->refcnt))
1453 +               kmem_cache_free(skbuff_cb_store_cache, next);
1454 +
1455 +       spin_unlock(&skb_cb_store_lock);
1456 +
1457 +       return 0;
1458 +}
1459 +EXPORT_SYMBOL(skb_restore_cb);
1460 +
1461 +static void skb_copy_stored_cb(struct sk_buff *new, const struct sk_buff *__old)
1462 +{
1463 +       struct skb_cb_table *next;
1464 +       struct sk_buff *old;
1465 +
1466 +       if (!__old->cb_next) {
1467 +               new->cb_next = NULL;
1468 +               return;
1469 +       }
1470 +
1471 +       spin_lock(&skb_cb_store_lock);
1472 +
1473 +       old = (struct sk_buff *)__old;
1474 +
1475 +       next = old->cb_next;
1476 +       atomic_inc(&next->refcnt);
1477 +       new->cb_next = next;
1478 +
1479 +       spin_unlock(&skb_cb_store_lock);
1480 +}
1481 +#endif
1482  
1483  /* Pipe buffer operations for a socket. */
1484  static const struct pipe_buf_operations sock_pipe_buf_ops = {
1485 @@ -577,6 +656,28 @@ static void skb_release_head_state(struct sk_buff *skb)
1486                 WARN_ON(in_irq());
1487                 skb->destructor(skb);
1488         }
1489 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1490 +       /*
1491 +        * This should not happen. When it does, avoid memleak by restoring
1492 +        * the chain of cb-backups.
1493 +        */
1494 +       while (skb->cb_next != NULL) {
1495 +               if (net_ratelimit())
1496 +                       pr_warn("IMQ: kfree_skb: skb->cb_next: %08x\n",
1497 +                               (unsigned int)skb->cb_next);
1498 +
1499 +               skb_restore_cb(skb);
1500 +       }
1501 +       /*
1502 +        * This should not happen either, nf_queue_entry is nullified in
1503 +        * imq_dev_xmit(). If we have non-NULL nf_queue_entry then we are
1504 +        * leaking entry pointers, maybe memory. We don't know if this is
1505 +        * pointer to already freed memory, or should this be freed.
1506 +        * If this happens we need to add refcounting, etc for nf_queue_entry.
1507 +        */
1508 +       if (skb->nf_queue_entry && net_ratelimit())
1509 +               pr_warn("%s\n", "IMQ: kfree_skb: skb->nf_queue_entry != NULL");
1510 +#endif
1511  #if IS_ENABLED(CONFIG_NF_CONNTRACK)
1512         nf_conntrack_put(skb->nfct);
1513  #endif
1514 @@ -709,6 +810,10 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
1515         new->sp                 = secpath_get(old->sp);
1516  #endif
1517         memcpy(new->cb, old->cb, sizeof(old->cb));
1518 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1519 +       new->cb_next = NULL;
1520 +       /*skb_copy_stored_cb(new, old);*/
1521 +#endif
1522         new->csum               = old->csum;
1523         new->local_df           = old->local_df;
1524         new->pkt_type           = old->pkt_type;
1525 @@ -3112,6 +3217,13 @@ void __init skb_init(void)
1526                                                 0,
1527                                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC,
1528                                                 NULL);
1529 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1530 +       skbuff_cb_store_cache = kmem_cache_create("skbuff_cb_store_cache",
1531 +                                                 sizeof(struct skb_cb_table),
1532 +                                                 0,
1533 +                                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC,
1534 +                                                 NULL);
1535 +#endif
1536  }
1537  
1538  /**
1539 diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
1540 index b6fa35e..08dcfef 100644
1541 --- a/net/ipv6/ip6_output.c
1542 +++ b/net/ipv6/ip6_output.c
1543 @@ -64,9 +64,6 @@ static int ip6_finish_output2(struct sk_buff *skb)
1544         struct in6_addr *nexthop;
1545         int ret;
1546  
1547 -       skb->protocol = htons(ETH_P_IPV6);
1548 -       skb->dev = dev;
1549 -
1550         if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr)) {
1551                 struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
1552  
1553 @@ -143,6 +140,13 @@ int ip6_output(struct sk_buff *skb)
1554                 return 0;
1555         }
1556  
1557 +       /*
1558 +        * IMQ-patch: moved setting skb->dev and skb->protocol from
1559 +        * ip6_finish_output2 to fix crashing at netif_skb_features().
1560 +        */
1561 +       skb->protocol = htons(ETH_P_IPV6);
1562 +       skb->dev = dev;
1563 +
1564         return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, skb, NULL, dev,
1565                             ip6_finish_output,
1566                             !(IP6CB(skb)->flags & IP6SKB_REROUTED));
1567 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
1568 index 6e839b6..45ac31c 100644
1569 --- a/net/netfilter/Kconfig
1570 +++ b/net/netfilter/Kconfig
1571 @@ -630,6 +630,18 @@ config NETFILTER_XT_TARGET_LOG
1572  
1573           To compile it as a module, choose M here.  If unsure, say N.
1574  
1575 +config NETFILTER_XT_TARGET_IMQ
1576 +        tristate '"IMQ" target support'
1577 +       depends on NETFILTER_XTABLES
1578 +       depends on IP_NF_MANGLE || IP6_NF_MANGLE
1579 +       select IMQ
1580 +       default m if NETFILTER_ADVANCED=n
1581 +        help
1582 +          This option adds a `IMQ' target which is used to specify if and
1583 +          to which imq device packets should get enqueued/dequeued.
1584 +
1585 +          To compile it as a module, choose M here.  If unsure, say N.
1586 +
1587  config NETFILTER_XT_TARGET_MARK
1588         tristate '"MARK" target support'
1589         depends on NETFILTER_ADVANCED
1590 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
1591 index c3a0a12..9647f06 100644
1592 --- a/net/netfilter/Makefile
1593 +++ b/net/netfilter/Makefile
1594 @@ -82,6 +82,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o
1595  obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
1596  obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o
1597  obj-$(CONFIG_NETFILTER_XT_TARGET_HMARK) += xt_HMARK.o
1598 +obj-$(CONFIG_NETFILTER_XT_TARGET_IMQ) += xt_IMQ.o
1599  obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
1600  obj-$(CONFIG_NETFILTER_XT_TARGET_LOG) += xt_LOG.o
1601  obj-$(CONFIG_NETFILTER_XT_TARGET_NETMAP) += xt_NETMAP.o
1602 diff --git a/net/netfilter/core.c b/net/netfilter/core.c
1603 index 593b16e..740cd69 100644
1604 --- a/net/netfilter/core.c
1605 +++ b/net/netfilter/core.c
1606 @@ -191,9 +191,11 @@ next_hook:
1607                 ret = NF_DROP_GETERR(verdict);
1608                 if (ret == 0)
1609                         ret = -EPERM;
1610 -       } else if ((verdict & NF_VERDICT_MASK) == NF_QUEUE) {
1611 +       } else if ((verdict & NF_VERDICT_MASK) == NF_QUEUE ||
1612 +                  (verdict & NF_VERDICT_MASK) == NF_IMQ_QUEUE) {
1613                 int err = nf_queue(skb, elem, pf, hook, indev, outdev, okfn,
1614 -                                               verdict >> NF_VERDICT_QBITS);
1615 +                                               verdict >> NF_VERDICT_QBITS,
1616 +                                               verdict & NF_VERDICT_MASK);
1617                 if (err < 0) {
1618                         if (err == -ECANCELED)
1619                                 goto next_hook;
1620 diff --git a/net/netfilter/nf_internals.h b/net/netfilter/nf_internals.h
1621 index 3deec99..c1a1397 100644
1622 --- a/net/netfilter/nf_internals.h
1623 +++ b/net/netfilter/nf_internals.h
1624 @@ -29,7 +29,7 @@ extern int nf_queue(struct sk_buff *skb,
1625  int nf_queue(struct sk_buff *skb, struct nf_hook_ops *elem, u_int8_t pf,
1626              unsigned int hook, struct net_device *indev,
1627              struct net_device *outdev, int (*okfn)(struct sk_buff *),
1628 -            unsigned int queuenum);
1629 +            unsigned int queuenum, unsigned int queuetype);
1630  int __init netfilter_queue_init(void);
1631  
1632  /* nf_log.c */
1633 diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
1634 index 5d24b1f..28317dc 100644
1635 --- a/net/netfilter/nf_queue.c
1636 +++ b/net/netfilter/nf_queue.c
1637 @@ -27,6 +27,23 @@
1638   */
1639  static const struct nf_queue_handler __rcu *queue_handler __read_mostly;
1640  
1641 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1642 +static const struct nf_queue_handler __rcu *queue_imq_handler __read_mostly;
1643 +
1644 +void nf_register_queue_imq_handler(const struct nf_queue_handler *qh)
1645 +{
1646 +       rcu_assign_pointer(queue_imq_handler, qh);
1647 +}
1648 +EXPORT_SYMBOL_GPL(nf_register_queue_imq_handler);
1649 +
1650 +void nf_unregister_queue_imq_handler(void)
1651 +{
1652 +       RCU_INIT_POINTER(queue_imq_handler, NULL);
1653 +       synchronize_rcu();
1654 +}
1655 +EXPORT_SYMBOL_GPL(nf_unregister_queue_imq_handler);
1656 +#endif
1657 +
1658  /* return EBUSY when somebody else is registered, return EEXIST if the
1659   * same handler is registered, return 0 in case of success. */
1660  void nf_register_queue_handler(const struct nf_queue_handler *qh)
1661 @@ -105,7 +122,8 @@ int nf_queue(struct sk_buff *skb,
1662                       struct net_device *indev,
1663                       struct net_device *outdev,
1664                       int (*okfn)(struct sk_buff *),
1665 -                     unsigned int queuenum)
1666 +                     unsigned int queuenum,
1667 +                     unsigned int queuetype)
1668  {
1669         int status = -ENOENT;
1670         struct nf_queue_entry *entry = NULL;
1671 @@ -115,7 +133,17 @@ int nf_queue(struct sk_buff *skb,
1672         /* QUEUE == DROP if no one is waiting, to be safe. */
1673         rcu_read_lock();
1674  
1675 -       qh = rcu_dereference(queue_handler);
1676 +       if (queuetype == NF_IMQ_QUEUE) {
1677 +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1678 +               qh = rcu_dereference(queue_imq_handler);
1679 +#else
1680 +               BUG();
1681 +               goto err_unlock;
1682 +#endif
1683 +       } else {
1684 +               qh = rcu_dereference(queue_handler);
1685 +       }
1686 +
1687         if (!qh) {
1688                 status = -ESRCH;
1689                 goto err_unlock;
1690 @@ -205,9 +233,11 @@ void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
1691                 local_bh_enable();
1692                 break;
1693         case NF_QUEUE:
1694 +       case NF_IMQ_QUEUE:
1695                 err = nf_queue(skb, elem, entry->pf, entry->hook,
1696                                 entry->indev, entry->outdev, entry->okfn,
1697 -                               verdict >> NF_VERDICT_QBITS);
1698 +                               verdict >> NF_VERDICT_QBITS,
1699 +                               verdict & NF_VERDICT_MASK);
1700                 if (err < 0) {
1701                         if (err == -ECANCELED)
1702                                 goto next_hook;
1703 diff --git a/net/netfilter/xt_IMQ.c b/net/netfilter/xt_IMQ.c
1704 new file mode 100644
1705 index 0000000..1c3cd66
1706 --- /dev/null
1707 +++ b/net/netfilter/xt_IMQ.c
1708 @@ -0,0 +1,72 @@
1709 +/*
1710 + * This target marks packets to be enqueued to an imq device
1711 + */
1712 +#include <linux/module.h>
1713 +#include <linux/skbuff.h>
1714 +#include <linux/netfilter/x_tables.h>
1715 +#include <linux/netfilter/xt_IMQ.h>
1716 +#include <linux/imq.h>
1717 +
1718 +static unsigned int imq_target(struct sk_buff *pskb,
1719 +                               const struct xt_action_param *par)
1720 +{
1721 +       const struct xt_imq_info *mr = par->targinfo;
1722 +
1723 +       pskb->imq_flags = (mr->todev & IMQ_F_IFMASK) | IMQ_F_ENQUEUE;
1724 +
1725 +       return XT_CONTINUE;
1726 +}
1727 +
1728 +static int imq_checkentry(const struct xt_tgchk_param *par)
1729 +{
1730 +       struct xt_imq_info *mr = par->targinfo;
1731 +
1732 +       if (mr->todev > IMQ_MAX_DEVS - 1) {
1733 +               pr_warn("IMQ: invalid device specified, highest is %u\n",
1734 +                       IMQ_MAX_DEVS - 1);
1735 +               return -EINVAL;
1736 +       }
1737 +
1738 +       return 0;
1739 +}
1740 +
1741 +static struct xt_target xt_imq_reg[] __read_mostly = {
1742 +       {
1743 +               .name           = "IMQ",
1744 +               .family         = AF_INET,
1745 +               .checkentry     = imq_checkentry,
1746 +               .target         = imq_target,
1747 +               .targetsize     = sizeof(struct xt_imq_info),
1748 +               .table          = "mangle",
1749 +               .me             = THIS_MODULE
1750 +       },
1751 +       {
1752 +               .name           = "IMQ",
1753 +               .family         = AF_INET6,
1754 +               .checkentry     = imq_checkentry,
1755 +               .target         = imq_target,
1756 +               .targetsize     = sizeof(struct xt_imq_info),
1757 +               .table          = "mangle",
1758 +               .me             = THIS_MODULE
1759 +       },
1760 +};
1761 +
1762 +static int __init imq_init(void)
1763 +{
1764 +       return xt_register_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1765 +}
1766 +
1767 +static void __exit imq_fini(void)
1768 +{
1769 +       xt_unregister_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg));
1770 +}
1771 +
1772 +module_init(imq_init);
1773 +module_exit(imq_fini);
1774 +
1775 +MODULE_AUTHOR("http://www.linuximq.net");
1776 +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See http://www.linuximq.net/ for more information.");
1777 +MODULE_LICENSE("GPL");
1778 +MODULE_ALIAS("ipt_IMQ");
1779 +MODULE_ALIAS("ip6t_IMQ");
1780 +
This page took 0.223943 seconds and 4 git commands to generate.