Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 7 | #include <linux/netfilter/x_tables.h> |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 8 | #include <net/netfilter/nf_conntrack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 10 | MODULE_LICENSE("GPL"); |
| 11 | MODULE_ALIAS("ipt_NOTRACK"); |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | static unsigned int |
| 14 | target(struct sk_buff **pskb, |
| 15 | const struct net_device *in, |
| 16 | const struct net_device *out, |
| 17 | unsigned int hooknum, |
Patrick McHardy | c498673 | 2006-03-20 18:02:56 -0800 | [diff] [blame] | 18 | const struct xt_target *target, |
Patrick McHardy | fe1cb10 | 2006-08-22 00:35:47 -0700 | [diff] [blame] | 19 | const void *targinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { |
| 21 | /* Previously seen (loopback)? Ignore. */ |
| 22 | if ((*pskb)->nfct != NULL) |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 23 | return XT_CONTINUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
YOSHIFUJI Hideaki | 601e68e | 2007-02-12 11:15:49 -0800 | [diff] [blame] | 25 | /* Attach fake conntrack entry. |
| 26 | If there is a real ct entry correspondig to this packet, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | it'll hang aroun till timing out. We don't deal with it |
| 28 | for performance reasons. JK */ |
Patrick McHardy | 587aa64 | 2007-03-14 16:37:25 -0700 | [diff] [blame] | 29 | (*pskb)->nfct = &nf_conntrack_untracked.ct_general; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | (*pskb)->nfctinfo = IP_CT_NEW; |
| 31 | nf_conntrack_get((*pskb)->nfct); |
| 32 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 33 | return XT_CONTINUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Patrick McHardy | 4470bbc | 2006-08-22 00:34:04 -0700 | [diff] [blame] | 36 | static struct xt_target xt_notrack_target[] = { |
| 37 | { |
| 38 | .name = "NOTRACK", |
| 39 | .family = AF_INET, |
| 40 | .target = target, |
| 41 | .table = "raw", |
| 42 | .me = THIS_MODULE, |
| 43 | }, |
| 44 | { |
| 45 | .name = "NOTRACK", |
| 46 | .family = AF_INET6, |
| 47 | .target = target, |
| 48 | .table = "raw", |
| 49 | .me = THIS_MODULE, |
| 50 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 53 | static int __init xt_notrack_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Patrick McHardy | 4470bbc | 2006-08-22 00:34:04 -0700 | [diff] [blame] | 55 | return xt_register_targets(xt_notrack_target, |
| 56 | ARRAY_SIZE(xt_notrack_target)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 59 | static void __exit xt_notrack_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Patrick McHardy | 4470bbc | 2006-08-22 00:34:04 -0700 | [diff] [blame] | 61 | xt_unregister_targets(xt_notrack_target, ARRAY_SIZE(xt_notrack_target)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 64 | module_init(xt_notrack_init); |
| 65 | module_exit(xt_notrack_fini); |