blob: e7a0a54fd4eae42f268ee91262532e00fa84199b [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>
Patrick McHardy587aa642007-03-14 16:37:25 -07008#include <net/netfilter/nf_conntrack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080010MODULE_DESCRIPTION("Xtables: Disabling connection tracking for packets");
Harald Welte2e4e6a12006-01-12 13:30:04 -080011MODULE_LICENSE("GPL");
12MODULE_ALIAS("ipt_NOTRACK");
Jan Engelhardt73aaf932007-10-11 14:36:40 -070013MODULE_ALIAS("ip6t_NOTRACK");
Harald Welte2e4e6a12006-01-12 13:30:04 -080014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static unsigned int
Jan Engelhardt7eb35582008-10-08 11:35:19 +020016notrack_tg(struct sk_buff *skb, const struct xt_target_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017{
18 /* Previously seen (loopback)? Ignore. */
Herbert Xu3db05fe2007-10-15 00:53:15 -070019 if (skb->nfct != NULL)
Harald Welte2e4e6a12006-01-12 13:30:04 -080020 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080022 /* Attach fake conntrack entry.
23 If there is a real ct entry correspondig to this packet,
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 it'll hang aroun till timing out. We don't deal with it
25 for performance reasons. JK */
Herbert Xu3db05fe2007-10-15 00:53:15 -070026 skb->nfct = &nf_conntrack_untracked.ct_general;
27 skb->nfctinfo = IP_CT_NEW;
28 nf_conntrack_get(skb->nfct);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Harald Welte2e4e6a12006-01-12 13:30:04 -080030 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
Jan Engelhardtab4f21e2008-10-08 11:35:20 +020033static struct xt_target notrack_tg_reg __read_mostly = {
34 .name = "NOTRACK",
35 .revision = 0,
36 .family = NFPROTO_UNSPEC,
37 .target = notrack_tg,
38 .table = "raw",
39 .me = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080042static int __init notrack_tg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Jan Engelhardtab4f21e2008-10-08 11:35:20 +020044 return xt_register_target(&notrack_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080047static void __exit notrack_tg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Jan Engelhardtab4f21e2008-10-08 11:35:20 +020049 xt_unregister_target(&notrack_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080052module_init(notrack_tg_init);
53module_exit(notrack_tg_exit);