ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / ipv4 / netfilter / ipt_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_ipv4/ip_tables.h>
8 #include <linux/netfilter_ipv4/ip_conntrack.h>
9
10 static unsigned int
11 target(struct sk_buff **pskb,
12        const struct net_device *in,
13        const struct net_device *out,
14        unsigned int hooknum,
15        const void *targinfo,
16        void *userinfo)
17 {
18         /* Previously seen (loopback)? Ignore. */
19         if ((*pskb)->nfct != NULL)
20                 return IPT_CONTINUE;
21
22         /* Attach fake conntrack entry. 
23            If there is a real ct entry correspondig to this packet, 
24            it'll hang aroun till timing out. We don't deal with it
25            for performance reasons. JK */
26         (*pskb)->nfct = &ip_conntrack_untracked.infos[IP_CT_NEW];
27         nf_conntrack_get((*pskb)->nfct);
28
29         return IPT_CONTINUE;
30 }
31
32 static int
33 checkentry(const char *tablename,
34            const struct ipt_entry *e,
35            void *targinfo,
36            unsigned int targinfosize,
37            unsigned int hook_mask)
38 {
39         if (targinfosize != 0) {
40                 printk(KERN_WARNING "NOTRACK: targinfosize %u != 0\n",
41                        targinfosize);
42                 return 0;
43         }
44
45         if (strcmp(tablename, "raw") != 0) {
46                 printk(KERN_WARNING "NOTRACK: can only be called from \"raw\" table, not \"%s\"\n", tablename);
47                 return 0;
48         }
49
50         return 1;
51 }
52
53 static struct ipt_target ipt_notrack_reg = { 
54         .name = "NOTRACK", 
55         .target = target, 
56         .checkentry = checkentry,
57         .me = THIS_MODULE 
58 };
59
60 static int __init init(void)
61 {
62         if (ipt_register_target(&ipt_notrack_reg))
63                 return -EINVAL;
64
65         return 0;
66 }
67
68 static void __exit fini(void)
69 {
70         ipt_unregister_target(&ipt_notrack_reg);
71 }
72
73 module_init(init);
74 module_exit(fini);
75 MODULE_LICENSE("GPL");