blob: b9ee268b37c34a1ea0beb9687ddf6d2afeb8d34f [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 Engelhardtd3c5ee62007-12-04 23:24:03 -080016notrack_tg(struct sk_buff *skb, const struct net_device *in,
17 const struct net_device *out, unsigned int hooknum,
18 const struct xt_target *target, const void *targinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
20 /* Previously seen (loopback)? Ignore. */
Herbert Xu3db05fe2007-10-15 00:53:15 -070021 if (skb->nfct != NULL)
Harald Welte2e4e6a12006-01-12 13:30:04 -080022 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080024 /* Attach fake conntrack entry.
25 If there is a real ct entry correspondig to this packet,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 it'll hang aroun till timing out. We don't deal with it
27 for performance reasons. JK */
Herbert Xu3db05fe2007-10-15 00:53:15 -070028 skb->nfct = &nf_conntrack_untracked.ct_general;
29 skb->nfctinfo = IP_CT_NEW;
30 nf_conntrack_get(skb->nfct);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Harald Welte2e4e6a12006-01-12 13:30:04 -080032 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080035static struct xt_target notrack_tg_reg[] __read_mostly = {
Patrick McHardy4470bbc2006-08-22 00:34:04 -070036 {
37 .name = "NOTRACK",
Jan Engelhardtee999d82008-10-08 11:35:01 +020038 .family = NFPROTO_IPV4,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080039 .target = notrack_tg,
Patrick McHardy4470bbc2006-08-22 00:34:04 -070040 .table = "raw",
41 .me = THIS_MODULE,
42 },
43 {
44 .name = "NOTRACK",
Jan Engelhardtee999d82008-10-08 11:35:01 +020045 .family = NFPROTO_IPV6,
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080046 .target = notrack_tg,
Patrick McHardy4470bbc2006-08-22 00:34:04 -070047 .table = "raw",
48 .me = THIS_MODULE,
49 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080052static int __init notrack_tg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080054 return xt_register_targets(notrack_tg_reg, ARRAY_SIZE(notrack_tg_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080057static void __exit notrack_tg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080059 xt_unregister_targets(notrack_tg_reg, ARRAY_SIZE(notrack_tg_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080062module_init(notrack_tg_init);
63module_exit(notrack_tg_exit);