blob: 98f4b5363ce8e8e4adcce549cfe63119c24db610 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Harald Welte2e4e6a12006-01-12 13:30:04 -08007#include <linux/netfilter/x_tables.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08008#include <net/netfilter/nf_conntrack_compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Harald Welte2e4e6a12006-01-12 13:30:04 -080010MODULE_LICENSE("GPL");
11MODULE_ALIAS("ipt_NOTRACK");
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013static unsigned int
14target(struct sk_buff **pskb,
15 const struct net_device *in,
16 const struct net_device *out,
17 unsigned int hooknum,
Patrick McHardyc4986732006-03-20 18:02:56 -080018 const struct xt_target *target,
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 const void *targinfo,
20 void *userinfo)
21{
22 /* Previously seen (loopback)? Ignore. */
23 if ((*pskb)->nfct != NULL)
Harald Welte2e4e6a12006-01-12 13:30:04 -080024 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26 /* Attach fake conntrack entry.
27 If there is a real ct entry correspondig to this packet,
28 it'll hang aroun till timing out. We don't deal with it
29 for performance reasons. JK */
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030 nf_ct_untrack(*pskb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 (*pskb)->nfctinfo = IP_CT_NEW;
32 nf_conntrack_get((*pskb)->nfct);
33
Harald Welte2e4e6a12006-01-12 13:30:04 -080034 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
Patrick McHardy5d04bff2006-03-20 18:01:58 -080037static struct xt_target notrack_reg = {
38 .name = "NOTRACK",
39 .target = target,
40 .targetsize = 0,
41 .table = "raw",
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080042 .family = AF_INET,
Patrick McHardy5d04bff2006-03-20 18:01:58 -080043 .me = THIS_MODULE,
Harald Welte2e4e6a12006-01-12 13:30:04 -080044};
Patrick McHardy5d04bff2006-03-20 18:01:58 -080045
46static struct xt_target notrack6_reg = {
47 .name = "NOTRACK",
48 .target = target,
49 .targetsize = 0,
50 .table = "raw",
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080051 .family = AF_INET6,
Patrick McHardy5d04bff2006-03-20 18:01:58 -080052 .me = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
Andrew Morton65b4b4e2006-03-28 16:37:06 -080055static int __init xt_notrack_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Harald Welte2e4e6a12006-01-12 13:30:04 -080057 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080059 ret = xt_register_target(&notrack_reg);
Harald Welte2e4e6a12006-01-12 13:30:04 -080060 if (ret)
61 return ret;
62
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080063 ret = xt_register_target(&notrack6_reg);
Harald Welte2e4e6a12006-01-12 13:30:04 -080064 if (ret)
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080065 xt_unregister_target(&notrack_reg);
Harald Welte2e4e6a12006-01-12 13:30:04 -080066
67 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Andrew Morton65b4b4e2006-03-28 16:37:06 -080070static void __exit xt_notrack_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080072 xt_unregister_target(&notrack6_reg);
73 xt_unregister_target(&notrack_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Andrew Morton65b4b4e2006-03-28 16:37:06 -080076module_init(xt_notrack_init);
77module_exit(xt_notrack_fini);