blob: 4e0b0c3593250bd8a1be0cdafca49ce7e4684f94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ebt_dnat
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * June, 2002
8 *
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <net/sock.h>
Jan Engelhardt18219d32008-10-08 11:35:13 +020012#include <linux/netfilter.h>
13#include <linux/netfilter/x_tables.h>
14#include <linux/netfilter_bridge/ebtables.h>
15#include <linux/netfilter_bridge/ebt_nat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020017static unsigned int
Jan Engelhardt4b560b42009-07-05 19:43:26 +020018ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020020 const struct ebt_nat_info *info = par->targinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Joonwoo Parkeb1197b2008-02-19 17:18:47 -080022 if (!skb_make_writable(skb, 0))
Joonwoo Park1b04ab42008-02-23 20:22:27 -080023 return EBT_DROP;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Joe Perches04091142014-02-23 00:05:26 -080025 ether_addr_copy(eth_hdr(skb)->h_dest, info->mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 return info->target;
27}
28
Jan Engelhardt135367b2010-03-19 17:16:42 +010029static int ebt_dnat_tg_check(const struct xt_tgchk_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020031 const struct ebt_nat_info *info = par->targinfo;
32 unsigned int hook_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34 if (BASE_CHAIN && info->target == EBT_RETURN)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010035 return -EINVAL;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020036
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)))
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010043 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 if (INVALID_TARGET)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010045 return -EINVAL;
46 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Jan Engelhardt043ef462008-10-08 11:35:15 +020049static struct xt_target ebt_dnat_tg_reg __read_mostly = {
50 .name = "dnat",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020051 .revision = 0,
52 .family = NFPROTO_BRIDGE,
Jan Engelhardtf2ff5252008-10-08 11:35:15 +020053 .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
54 (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020055 .target = ebt_dnat_tg,
56 .checkentry = ebt_dnat_tg_check,
Florian Westphalfc0e3df2010-02-15 18:16:26 +010057 .targetsize = sizeof(struct ebt_nat_info),
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 .me = THIS_MODULE,
59};
60
Andrew Morton65b4b4e2006-03-28 16:37:06 -080061static int __init ebt_dnat_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Jan Engelhardt043ef462008-10-08 11:35:15 +020063 return xt_register_target(&ebt_dnat_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Andrew Morton65b4b4e2006-03-28 16:37:06 -080066static void __exit ebt_dnat_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Jan Engelhardt043ef462008-10-08 11:35:15 +020068 xt_unregister_target(&ebt_dnat_tg_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Andrew Morton65b4b4e2006-03-28 16:37:06 -080071module_init(ebt_dnat_init);
72module_exit(ebt_dnat_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080073MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_LICENSE("GPL");