Commit | Line | Data |
---|---|---|
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 | 19 | static unsigned int |
7eb35586 | 20 | ebt_snat_tg(struct sk_buff *skb, const struct xt_target_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 | } | |
41 | out: | |
42 | return info->target | ~EBT_VERDICT_BITS; | |
1da177e4 LT |
43 | } |
44 | ||
2d06d4a5 JE |
45 | static bool |
46 | ebt_snat_tg_check(const char *tablename, const void *e, | |
47 | const struct xt_target *target, void *data, | |
48 | unsigned int hookmask) | |
1da177e4 | 49 | { |
abfdf1c4 | 50 | const struct ebt_nat_info *info = data; |
d12cdc3c | 51 | int tmp; |
1da177e4 | 52 | |
d12cdc3c BDS |
53 | tmp = info->target | ~EBT_VERDICT_BITS; |
54 | if (BASE_CHAIN && tmp == EBT_RETURN) | |
19eda879 | 55 | return false; |
1da177e4 | 56 | CLEAR_BASE_CHAIN_BIT; |
d12cdc3c BDS |
57 | |
58 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) | |
19eda879 | 59 | return false; |
d12cdc3c BDS |
60 | tmp = info->target | EBT_VERDICT_BITS; |
61 | if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT) | |
19eda879 JE |
62 | return false; |
63 | return true; | |
1da177e4 LT |
64 | } |
65 | ||
043ef46c JE |
66 | static struct xt_target ebt_snat_tg_reg __read_mostly = { |
67 | .name = "snat", | |
001a18d3 JE |
68 | .revision = 0, |
69 | .family = NFPROTO_BRIDGE, | |
f2ff525c JE |
70 | .table = "nat", |
71 | .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING), | |
2d06d4a5 JE |
72 | .target = ebt_snat_tg, |
73 | .checkentry = ebt_snat_tg_check, | |
18219d3f | 74 | .targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)), |
1da177e4 LT |
75 | .me = THIS_MODULE, |
76 | }; | |
77 | ||
65b4b4e8 | 78 | static int __init ebt_snat_init(void) |
1da177e4 | 79 | { |
043ef46c | 80 | return xt_register_target(&ebt_snat_tg_reg); |
1da177e4 LT |
81 | } |
82 | ||
65b4b4e8 | 83 | static void __exit ebt_snat_fini(void) |
1da177e4 | 84 | { |
043ef46c | 85 | xt_unregister_target(&ebt_snat_tg_reg); |
1da177e4 LT |
86 | } |
87 | ||
65b4b4e8 AM |
88 | module_init(ebt_snat_init); |
89 | module_exit(ebt_snat_fini); | |
f776c4cd | 90 | MODULE_DESCRIPTION("Ebtables: Source MAC address translation"); |
1da177e4 | 91 | MODULE_LICENSE("GPL"); |