Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ebt_snat |
| 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_snat(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_source, info->mac, ETH_ALEN); |
| 34 | return info->target; |
| 35 | } |
| 36 | |
| 37 | static int ebt_target_snat_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 (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info))) |
| 43 | return -EINVAL; |
| 44 | if (BASE_CHAIN && info->target == EBT_RETURN) |
| 45 | return -EINVAL; |
| 46 | CLEAR_BASE_CHAIN_BIT; |
| 47 | if (strcmp(tablename, "nat")) |
| 48 | return -EINVAL; |
| 49 | if (hookmask & ~(1 << NF_BR_POST_ROUTING)) |
| 50 | return -EINVAL; |
| 51 | if (INVALID_TARGET) |
| 52 | return -EINVAL; |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static struct ebt_target snat = |
| 57 | { |
| 58 | .name = EBT_SNAT_TARGET, |
| 59 | .target = ebt_target_snat, |
| 60 | .check = ebt_target_snat_check, |
| 61 | .me = THIS_MODULE, |
| 62 | }; |
| 63 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame^] | 64 | static int __init ebt_snat_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | return ebt_register_target(&snat); |
| 67 | } |
| 68 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame^] | 69 | static void __exit ebt_snat_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | ebt_unregister_target(&snat); |
| 72 | } |
| 73 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame^] | 74 | module_init(ebt_snat_init); |
| 75 | module_exit(ebt_snat_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | MODULE_LICENSE("GPL"); |