8bacbe14afb5714143d74ef5cbe7b11dc930155b
[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 struct xt_target notrack_reg = {
37         .name           = "NOTRACK",
38         .target         = target,
39         .targetsize     = 0,
40         .table          = "raw",
41         .me             = THIS_MODULE,
42 };
43
44 static struct xt_target notrack6_reg = {
45         .name           = "NOTRACK",
46         .target         = target,
47         .targetsize     = 0,
48         .table          = "raw",
49         .me             = THIS_MODULE,
50 };
51
52 static int __init init(void)
53 {
54         int ret;
55
56         ret = xt_register_target(AF_INET, &notrack_reg);
57         if (ret)
58                 return ret;
59
60         ret = xt_register_target(AF_INET6, &notrack6_reg);
61         if (ret)
62                 xt_unregister_target(AF_INET, &notrack_reg);
63
64         return ret;
65 }
66
67 static void __exit fini(void)
68 {
69         xt_unregister_target(AF_INET6, &notrack6_reg);
70         xt_unregister_target(AF_INET, &notrack_reg);
71 }
72
73 module_init(init);
74 module_exit(fini);