]>
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 | */ | |
10 | ||
2ca7b0ac | 11 | #include <linux/netfilter.h> |
1da177e4 LT |
12 | #include <linux/netfilter_bridge/ebtables.h> |
13 | #include <linux/netfilter_bridge/ebt_nat.h> | |
14 | #include <linux/module.h> | |
15 | #include <net/sock.h> | |
d12cdc3c BDS |
16 | #include <linux/if_arp.h> |
17 | #include <net/arp.h> | |
1da177e4 | 18 | |
3db05fea | 19 | static int ebt_target_snat(struct sk_buff *skb, unsigned int hooknr, |
1da177e4 LT |
20 | const struct net_device *in, const struct net_device *out, |
21 | const void *data, unsigned int datalen) | |
22 | { | |
abfdf1c4 | 23 | const struct ebt_nat_info *info = data; |
1da177e4 | 24 | |
3db05fea | 25 | if (skb_make_writable(skb, 0)) |
2ca7b0ac | 26 | return NF_DROP; |
1da177e4 | 27 | |
3db05fea | 28 | memcpy(eth_hdr(skb)->h_source, info->mac, ETH_ALEN); |
d12cdc3c | 29 | if (!(info->target & NAT_ARP_BIT) && |
3db05fea | 30 | eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) { |
abfdf1c4 JE |
31 | const struct arphdr *ap; |
32 | struct arphdr _ah; | |
d12cdc3c | 33 | |
3db05fea | 34 | ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah); |
d12cdc3c BDS |
35 | if (ap == NULL) |
36 | return EBT_DROP; | |
37 | if (ap->ar_hln != ETH_ALEN) | |
38 | goto out; | |
3db05fea | 39 | if (skb_store_bits(skb, sizeof(_ah), info->mac,ETH_ALEN)) |
d12cdc3c BDS |
40 | return EBT_DROP; |
41 | } | |
42 | out: | |
43 | return info->target | ~EBT_VERDICT_BITS; | |
1da177e4 LT |
44 | } |
45 | ||
46 | static int ebt_target_snat_check(const char *tablename, unsigned int hookmask, | |
47 | const struct ebt_entry *e, void *data, unsigned int datalen) | |
48 | { | |
abfdf1c4 | 49 | const struct ebt_nat_info *info = data; |
d12cdc3c | 50 | int tmp; |
1da177e4 LT |
51 | |
52 | if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info))) | |
53 | return -EINVAL; | |
d12cdc3c BDS |
54 | tmp = info->target | ~EBT_VERDICT_BITS; |
55 | if (BASE_CHAIN && tmp == EBT_RETURN) | |
1da177e4 LT |
56 | return -EINVAL; |
57 | CLEAR_BASE_CHAIN_BIT; | |
58 | if (strcmp(tablename, "nat")) | |
59 | return -EINVAL; | |
60 | if (hookmask & ~(1 << NF_BR_POST_ROUTING)) | |
61 | return -EINVAL; | |
d12cdc3c BDS |
62 | |
63 | if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0) | |
64 | return -EINVAL; | |
65 | tmp = info->target | EBT_VERDICT_BITS; | |
66 | if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT) | |
1da177e4 LT |
67 | return -EINVAL; |
68 | return 0; | |
69 | } | |
70 | ||
71 | static struct ebt_target snat = | |
72 | { | |
73 | .name = EBT_SNAT_TARGET, | |
74 | .target = ebt_target_snat, | |
75 | .check = ebt_target_snat_check, | |
76 | .me = THIS_MODULE, | |
77 | }; | |
78 | ||
65b4b4e8 | 79 | static int __init ebt_snat_init(void) |
1da177e4 LT |
80 | { |
81 | return ebt_register_target(&snat); | |
82 | } | |
83 | ||
65b4b4e8 | 84 | static void __exit ebt_snat_fini(void) |
1da177e4 LT |
85 | { |
86 | ebt_unregister_target(&snat); | |
87 | } | |
88 | ||
65b4b4e8 AM |
89 | module_init(ebt_snat_init); |
90 | module_exit(ebt_snat_fini); | |
1da177e4 | 91 | MODULE_LICENSE("GPL"); |