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 | |
| 11 | #include <linux/netfilter_bridge/ebtables.h> |
| 12 | #include <linux/netfilter_bridge/ebt_nat.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <net/sock.h> |
| 15 | |
| 16 | static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr, |
| 17 | const struct net_device *in, const struct net_device *out, |
| 18 | const void *data, unsigned int datalen) |
| 19 | { |
| 20 | struct ebt_nat_info *info = (struct ebt_nat_info *)data; |
| 21 | |
| 22 | if (skb_shared(*pskb) || skb_cloned(*pskb)) { |
| 23 | struct sk_buff *nskb; |
| 24 | |
| 25 | nskb = skb_copy(*pskb, GFP_ATOMIC); |
| 26 | if (!nskb) |
| 27 | return NF_DROP; |
| 28 | if ((*pskb)->sk) |
| 29 | skb_set_owner_w(nskb, (*pskb)->sk); |
| 30 | kfree_skb(*pskb); |
| 31 | *pskb = nskb; |
| 32 | } |
| 33 | memcpy(eth_hdr(*pskb)->h_dest, info->mac, ETH_ALEN); |
| 34 | return info->target; |
| 35 | } |
| 36 | |
| 37 | static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask, |
| 38 | const struct ebt_entry *e, void *data, unsigned int datalen) |
| 39 | { |
| 40 | struct ebt_nat_info *info = (struct ebt_nat_info *)data; |
| 41 | |
| 42 | if (BASE_CHAIN && info->target == EBT_RETURN) |
| 43 | return -EINVAL; |
| 44 | CLEAR_BASE_CHAIN_BIT; |
| 45 | if ( (strcmp(tablename, "nat") || |
| 46 | (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) && |
| 47 | (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) ) |
| 48 | return -EINVAL; |
| 49 | if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info))) |
| 50 | return -EINVAL; |
| 51 | if (INVALID_TARGET) |
| 52 | return -EINVAL; |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static struct ebt_target dnat = |
| 57 | { |
| 58 | .name = EBT_DNAT_TARGET, |
| 59 | .target = ebt_target_dnat, |
| 60 | .check = ebt_target_dnat_check, |
| 61 | .me = THIS_MODULE, |
| 62 | }; |
| 63 | |
| 64 | static int __init init(void) |
| 65 | { |
| 66 | return ebt_register_target(&dnat); |
| 67 | } |
| 68 | |
| 69 | static void __exit fini(void) |
| 70 | { |
| 71 | ebt_unregister_target(&dnat); |
| 72 | } |
| 73 | |
| 74 | module_init(init); |
| 75 | module_exit(fini); |
| 76 | MODULE_LICENSE("GPL"); |