]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ebt_dnat | |
3 | * | |
4 | * Authors: | |
5 | * Bart De Schuymer <bdschuym@pandora.be> | |
6 | * | |
7 | * June, 2002 | |
8 | * | |
9 | */ | |
18219d3f JE |
10 | #include <linux/module.h> |
11 | #include <net/sock.h> | |
2ca7b0ac | 12 | #include <linux/netfilter.h> |
18219d3f | 13 | #include <linux/netfilter/x_tables.h> |
1da177e4 LT |
14 | #include <linux/netfilter_bridge/ebtables.h> |
15 | #include <linux/netfilter_bridge/ebt_nat.h> | |
1da177e4 | 16 | |
2d06d4a5 | 17 | static unsigned int |
4b560b44 | 18 | ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par) |
1da177e4 | 19 | { |
7eb35586 | 20 | const struct ebt_nat_info *info = par->targinfo; |
1da177e4 | 21 | |
eb1197bc | 22 | if (!skb_make_writable(skb, 0)) |
1b04ab45 | 23 | return EBT_DROP; |
1da177e4 | 24 | |
3db05fea | 25 | memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN); |
1da177e4 LT |
26 | return info->target; |
27 | } | |
28 | ||
135367b8 | 29 | static int ebt_dnat_tg_check(const struct xt_tgchk_param *par) |
1da177e4 | 30 | { |
af5d6dc2 JE |
31 | const struct ebt_nat_info *info = par->targinfo; |
32 | unsigned int hook_mask; | |
1da177e4 LT |
33 | |
34 | if (BASE_CHAIN && info->target == EBT_RETURN) | |
d6b00a53 | 35 | return -EINVAL; |
af5d6dc2 JE |
36 | |
37 | hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS); | |
38 | if ((strcmp(par->table, "nat") != 0 || | |
39 | (hook_mask & ~((1 << NF_BR_PRE_ROUTING) | | |
40 | (1 << NF_BR_LOCAL_OUT)))) && | |
41 | (strcmp(par->table, "broute") != 0 || | |
42 | hook_mask & ~(1 << NF_BR_BROUTING))) | |
d6b00a53 | 43 | return -EINVAL; |
1da177e4 | 44 | if (INVALID_TARGET) |
d6b00a53 JE |
45 | return -EINVAL; |
46 | return 0; | |
1da177e4 LT |
47 | } |
48 | ||
043ef46c JE |
49 | static struct xt_target ebt_dnat_tg_reg __read_mostly = { |
50 | .name = "dnat", | |
001a18d3 JE |
51 | .revision = 0, |
52 | .family = NFPROTO_BRIDGE, | |
f2ff525c JE |
53 | .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) | |
54 | (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING), | |
2d06d4a5 JE |
55 | .target = ebt_dnat_tg, |
56 | .checkentry = ebt_dnat_tg_check, | |
fc0e3df4 | 57 | .targetsize = sizeof(struct ebt_nat_info), |
1da177e4 LT |
58 | .me = THIS_MODULE, |
59 | }; | |
60 | ||
65b4b4e8 | 61 | static int __init ebt_dnat_init(void) |
1da177e4 | 62 | { |
043ef46c | 63 | return xt_register_target(&ebt_dnat_tg_reg); |
1da177e4 LT |
64 | } |
65 | ||
65b4b4e8 | 66 | static void __exit ebt_dnat_fini(void) |
1da177e4 | 67 | { |
043ef46c | 68 | xt_unregister_target(&ebt_dnat_tg_reg); |
1da177e4 LT |
69 | } |
70 | ||
65b4b4e8 AM |
71 | module_init(ebt_dnat_init); |
72 | module_exit(ebt_dnat_fini); | |
f776c4cd | 73 | MODULE_DESCRIPTION("Ebtables: Destination MAC address translation"); |
1da177e4 | 74 | MODULE_LICENSE("GPL"); |