linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / netfilter / xt_NFQUEUE.c
1 /* iptables module for using new netfilter netlink queue
2  *
3  * (C) 2005 by Harald Welte <laforge@netfilter.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as 
7  * published by the Free Software Foundation.
8  * 
9  */
10
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13
14 #include <linux/netfilter.h>
15 #include <linux/netfilter_arp.h>
16 #include <linux/netfilter/x_tables.h>
17 #include <linux/netfilter/xt_NFQUEUE.h>
18
19 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
20 MODULE_DESCRIPTION("[ip,ip6,arp]_tables NFQUEUE target");
21 MODULE_LICENSE("GPL");
22 MODULE_ALIAS("ipt_NFQUEUE");
23 MODULE_ALIAS("ip6t_NFQUEUE");
24 MODULE_ALIAS("arpt_NFQUEUE");
25
26 static unsigned int
27 target(struct sk_buff **pskb,
28        const struct net_device *in,
29        const struct net_device *out,
30        unsigned int hooknum,
31        const void *targinfo,
32        void *userinfo)
33 {
34         const struct xt_NFQ_info *tinfo = targinfo;
35
36         return NF_QUEUE_NR(tinfo->queuenum);
37 }
38
39 static int
40 checkentry(const char *tablename,
41            const void *entry,
42            void *targinfo,
43            unsigned int targinfosize,
44            unsigned int hook_mask)
45 {
46         if (targinfosize != XT_ALIGN(sizeof(struct xt_NFQ_info))) {
47                 printk(KERN_WARNING "NFQUEUE: targinfosize %u != %Zu\n",
48                        targinfosize,
49                        XT_ALIGN(sizeof(struct xt_NFQ_info)));
50                 return 0;
51         }
52
53         return 1;
54 }
55
56 static struct xt_target ipt_NFQ_reg = {
57         .name           = "NFQUEUE",
58         .target         = target,
59         .checkentry     = checkentry,
60         .me             = THIS_MODULE,
61 };
62
63 static struct xt_target ip6t_NFQ_reg = {
64         .name           = "NFQUEUE",
65         .target         = target,
66         .checkentry     = checkentry,
67         .me             = THIS_MODULE,
68 };
69
70 static struct xt_target arpt_NFQ_reg = {
71         .name           = "NFQUEUE",
72         .target         = target,
73         .checkentry     = checkentry,
74         .me             = THIS_MODULE,
75 };
76
77 static int __init init(void)
78 {
79         int ret;
80         ret = xt_register_target(AF_INET, &ipt_NFQ_reg);
81         if (ret)
82                 return ret;
83         ret = xt_register_target(AF_INET6, &ip6t_NFQ_reg);
84         if (ret)
85                 goto out_ip;
86         ret = xt_register_target(NF_ARP, &arpt_NFQ_reg);
87         if (ret)
88                 goto out_ip6;
89
90         return ret;
91 out_ip6:
92         xt_unregister_target(AF_INET6, &ip6t_NFQ_reg);
93 out_ip:
94         xt_unregister_target(AF_INET, &ipt_NFQ_reg);
95
96         return ret;
97 }
98
99 static void __exit fini(void)
100 {
101         xt_unregister_target(NF_ARP, &arpt_NFQ_reg);
102         xt_unregister_target(AF_INET6, &ip6t_NFQ_reg);
103         xt_unregister_target(AF_INET, &ipt_NFQ_reg);
104 }
105
106 module_init(init);
107 module_exit(fini);