[PATCH] VM: add page_state info to per-node meminfo
[linux-ginger.git] / net / bridge / netfilter / ebt_snat.c
blob1529bdcb9a48525c58da62500d936a2bcbc401d0
1 /*
2 * ebt_snat
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
7 * June, 2002
9 */
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>
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)
20 struct ebt_nat_info *info = (struct ebt_nat_info *) data;
22 if (skb_shared(*pskb) || skb_cloned(*pskb)) {
23 struct sk_buff *nskb;
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;
33 memcpy(eth_hdr(*pskb)->h_source, info->mac, ETH_ALEN);
34 return info->target;
37 static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
38 const struct ebt_entry *e, void *data, unsigned int datalen)
40 struct ebt_nat_info *info = (struct ebt_nat_info *) data;
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;
56 static struct ebt_target snat =
58 .name = EBT_SNAT_TARGET,
59 .target = ebt_target_snat,
60 .check = ebt_target_snat_check,
61 .me = THIS_MODULE,
64 static int __init init(void)
66 return ebt_register_target(&snat);
69 static void __exit fini(void)
71 ebt_unregister_target(&snat);
74 module_init(init);
75 module_exit(fini);
76 MODULE_LICENSE("GPL");