[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
[safe/jmp/linux-2.6] / net / netfilter / xt_NOTRACK.c
1 /* This is a module which is used for setting up fake conntracks
2  * on packets so that they are not seen by the conntrack/NAT code.
3  */
4 #include <linux/module.h>
5 #include <linux/skbuff.h>
6
7 #include <linux/netfilter/x_tables.h>
8 #include <net/netfilter/nf_conntrack_compat.h>
9
10 MODULE_LICENSE("GPL");
11 MODULE_ALIAS("ipt_NOTRACK");
12
13 static unsigned int
14 target(struct sk_buff **pskb,
15        const struct net_device *in,
16        const struct net_device *out,
17        unsigned int hooknum,
18        const void *targinfo,
19        void *userinfo)
20 {
21         /* Previously seen (loopback)? Ignore. */
22         if ((*pskb)->nfct != NULL)
23                 return XT_CONTINUE;
24
25         /* Attach fake conntrack entry. 
26            If there is a real ct entry correspondig to this packet, 
27            it'll hang aroun till timing out. We don't deal with it
28            for performance reasons. JK */
29         nf_ct_untrack(*pskb);
30         (*pskb)->nfctinfo = IP_CT_NEW;
31         nf_conntrack_get((*pskb)->nfct);
32
33         return XT_CONTINUE;
34 }
35
36 static int
37 checkentry(const char *tablename,
38            const void *entry,
39            void *targinfo,
40            unsigned int targinfosize,
41            unsigned int hook_mask)
42 {
43         if (targinfosize != 0) {
44                 printk(KERN_WARNING "NOTRACK: targinfosize %u != 0\n",
45                        targinfosize);
46                 return 0;
47         }
48
49         if (strcmp(tablename, "raw") != 0) {
50                 printk(KERN_WARNING "NOTRACK: can only be called from \"raw\" table, not \"%s\"\n", tablename);
51                 return 0;
52         }
53
54         return 1;
55 }
56
57 static struct xt_target notrack_reg = { 
58         .name = "NOTRACK", 
59         .target = target, 
60         .checkentry = checkentry,
61         .me = THIS_MODULE,
62 };
63 static struct xt_target notrack6_reg = { 
64         .name = "NOTRACK", 
65         .target = target, 
66         .checkentry = checkentry,
67         .me = THIS_MODULE,
68 };
69
70 static int __init init(void)
71 {
72         int ret;
73
74         ret = xt_register_target(AF_INET, &notrack_reg);
75         if (ret)
76                 return ret;
77
78         ret = xt_register_target(AF_INET6, &notrack6_reg);
79         if (ret)
80                 xt_unregister_target(AF_INET, &notrack_reg);
81
82         return ret;
83 }
84
85 static void __exit fini(void)
86 {
87         xt_unregister_target(AF_INET6, &notrack6_reg);
88         xt_unregister_target(AF_INET, &notrack_reg);
89 }
90
91 module_init(init);
92 module_exit(fini);