blob: b8634e3f616955854db853c96de47fa972472b8d [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",
42 .me = THIS_MODULE,
Harald Welte2e4e6a12006-01-12 13:30:04 -080043};
Patrick McHardy5d04bff2006-03-20 18:01:58 -080044
45static struct xt_target notrack6_reg = {
46 .name = "NOTRACK",
47 .target = target,
48 .targetsize = 0,
49 .table = "raw",
50 .me = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
53static int __init init(void)
54{
Harald Welte2e4e6a12006-01-12 13:30:04 -080055 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Harald Welte2e4e6a12006-01-12 13:30:04 -080057 ret = xt_register_target(AF_INET, &notrack_reg);
58 if (ret)
59 return ret;
60
61 ret = xt_register_target(AF_INET6, &notrack6_reg);
62 if (ret)
63 xt_unregister_target(AF_INET, &notrack_reg);
64
65 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68static void __exit fini(void)
69{
Harald Welte2e4e6a12006-01-12 13:30:04 -080070 xt_unregister_target(AF_INET6, &notrack6_reg);
71 xt_unregister_target(AF_INET, &notrack_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74module_init(init);
75module_exit(fini);