Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ebt_dnat |
| 3 | * |
| 4 | * Authors: |
| 5 | * Bart De Schuymer <bdschuym@pandora.be> |
| 6 | * |
| 7 | * June, 2002 |
| 8 | * |
| 9 | */ |
| 10 | |
Herbert Xu | 2ca7b0a | 2007-10-14 00:39:55 -0700 | [diff] [blame] | 11 | #include <linux/netfilter.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/netfilter_bridge/ebtables.h> |
| 13 | #include <linux/netfilter_bridge/ebt_nat.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <net/sock.h> |
| 16 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame^] | 17 | static int ebt_target_dnat(struct sk_buff *skb, unsigned int hooknr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | const struct net_device *in, const struct net_device *out, |
| 19 | const void *data, unsigned int datalen) |
| 20 | { |
| 21 | struct ebt_nat_info *info = (struct ebt_nat_info *)data; |
| 22 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame^] | 23 | if (skb_make_writable(skb, 0)) |
Herbert Xu | 2ca7b0a | 2007-10-14 00:39:55 -0700 | [diff] [blame] | 24 | return NF_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame^] | 26 | memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | return info->target; |
| 28 | } |
| 29 | |
| 30 | static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask, |
| 31 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 32 | { |
| 33 | struct ebt_nat_info *info = (struct ebt_nat_info *)data; |
| 34 | |
| 35 | if (BASE_CHAIN && info->target == EBT_RETURN) |
| 36 | return -EINVAL; |
| 37 | CLEAR_BASE_CHAIN_BIT; |
| 38 | if ( (strcmp(tablename, "nat") || |
| 39 | (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) && |
| 40 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) |
| 41 | return -EINVAL; |
| 42 | if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info))) |
| 43 | return -EINVAL; |
| 44 | if (INVALID_TARGET) |
| 45 | return -EINVAL; |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static struct ebt_target dnat = |
| 50 | { |
| 51 | .name = EBT_DNAT_TARGET, |
| 52 | .target = ebt_target_dnat, |
| 53 | .check = ebt_target_dnat_check, |
| 54 | .me = THIS_MODULE, |
| 55 | }; |
| 56 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 57 | static int __init ebt_dnat_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | return ebt_register_target(&dnat); |
| 60 | } |
| 61 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 62 | static void __exit ebt_dnat_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | ebt_unregister_target(&dnat); |
| 65 | } |
| 66 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 67 | module_init(ebt_dnat_init); |
| 68 | module_exit(ebt_dnat_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | MODULE_LICENSE("GPL"); |