]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/bridge/netfilter/ebt_snat.c
netfilter: xtables: substitute temporary defines by final name
[net-next-2.6.git] / net / bridge / netfilter / ebt_snat.c
CommitLineData
1da177e4
LT
1/*
2 * ebt_snat
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * June, 2002
8 *
9 */
1da177e4
LT
10#include <linux/module.h>
11#include <net/sock.h>
d12cdc3c
BDS
12#include <linux/if_arp.h>
13#include <net/arp.h>
18219d3f
JE
14#include <linux/netfilter.h>
15#include <linux/netfilter/x_tables.h>
16#include <linux/netfilter_bridge/ebtables.h>
17#include <linux/netfilter_bridge/ebt_nat.h>
1da177e4 18
2d06d4a5 19static unsigned int
4b560b44 20ebt_snat_tg(struct sk_buff *skb, const struct xt_action_param *par)
1da177e4 21{
7eb35586 22 const struct ebt_nat_info *info = par->targinfo;
1da177e4 23
eb1197bc 24 if (!skb_make_writable(skb, 0))
1b04ab45 25 return EBT_DROP;
1da177e4 26
3db05fea 27 memcpy(eth_hdr(skb)->h_source, info->mac, ETH_ALEN);
d12cdc3c 28 if (!(info->target & NAT_ARP_BIT) &&
3db05fea 29 eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) {
abfdf1c4
JE
30 const struct arphdr *ap;
31 struct arphdr _ah;
d12cdc3c 32
3db05fea 33 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
d12cdc3c
BDS
34 if (ap == NULL)
35 return EBT_DROP;
36 if (ap->ar_hln != ETH_ALEN)
37 goto out;
3db05fea 38 if (skb_store_bits(skb, sizeof(_ah), info->mac,ETH_ALEN))
d12cdc3c
BDS
39 return EBT_DROP;
40 }
41out:
42 return info->target | ~EBT_VERDICT_BITS;
1da177e4
LT
43}
44
135367b8 45static int ebt_snat_tg_check(const struct xt_tgchk_param *par)
1da177e4 46{
af5d6dc2 47 const struct ebt_nat_info *info = par->targinfo;
d12cdc3c 48 int tmp;
1da177e4 49
d12cdc3c
BDS
50 tmp = info->target | ~EBT_VERDICT_BITS;
51 if (BASE_CHAIN && tmp == EBT_RETURN)
d6b00a53 52 return -EINVAL;
d12cdc3c
BDS
53
54 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
d6b00a53 55 return -EINVAL;
d12cdc3c
BDS
56 tmp = info->target | EBT_VERDICT_BITS;
57 if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT)
d6b00a53
JE
58 return -EINVAL;
59 return 0;
1da177e4
LT
60}
61
043ef46c
JE
62static struct xt_target ebt_snat_tg_reg __read_mostly = {
63 .name = "snat",
001a18d3
JE
64 .revision = 0,
65 .family = NFPROTO_BRIDGE,
f2ff525c
JE
66 .table = "nat",
67 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING),
2d06d4a5
JE
68 .target = ebt_snat_tg,
69 .checkentry = ebt_snat_tg_check,
fc0e3df4 70 .targetsize = sizeof(struct ebt_nat_info),
1da177e4
LT
71 .me = THIS_MODULE,
72};
73
65b4b4e8 74static int __init ebt_snat_init(void)
1da177e4 75{
043ef46c 76 return xt_register_target(&ebt_snat_tg_reg);
1da177e4
LT
77}
78
65b4b4e8 79static void __exit ebt_snat_fini(void)
1da177e4 80{
043ef46c 81 xt_unregister_target(&ebt_snat_tg_reg);
1da177e4
LT
82}
83
65b4b4e8
AM
84module_init(ebt_snat_init);
85module_exit(ebt_snat_fini);
f776c4cd 86MODULE_DESCRIPTION("Ebtables: Source MAC address translation");
1da177e4 87MODULE_LICENSE("GPL");