2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ebt_dnat
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* June, 2002
|
|
|
|
*
|
|
|
|
*/
|
2008-10-08 11:35:13 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <net/sock.h>
|
2007-10-14 09:39:55 +02:00
|
|
|
#include <linux/netfilter.h>
|
2008-10-08 11:35:13 +02:00
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebt_nat.h>
|
|
|
|
|
2008-10-08 11:35:15 +02:00
|
|
|
static unsigned int
|
2008-10-08 11:35:19 +02:00
|
|
|
ebt_dnat_tg(struct sk_buff *skb, const struct xt_target_param *par)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:19 +02:00
|
|
|
const struct ebt_nat_info *info = par->targinfo;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-02-20 02:18:47 +01:00
|
|
|
if (!skb_make_writable(skb, 0))
|
2008-02-24 05:22:27 +01:00
|
|
|
return EBT_DROP;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN);
|
2005-04-17 00:20:36 +02:00
|
|
|
return info->target;
|
|
|
|
}
|
|
|
|
|
2008-10-08 11:35:19 +02:00
|
|
|
static bool ebt_dnat_tg_check(const struct xt_tgchk_param *par)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:19 +02:00
|
|
|
const struct ebt_nat_info *info = par->targinfo;
|
|
|
|
unsigned int hook_mask;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (BASE_CHAIN && info->target == EBT_RETURN)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2008-10-08 11:35:19 +02:00
|
|
|
|
|
|
|
hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
|
|
|
|
if ((strcmp(par->table, "nat") != 0 ||
|
|
|
|
(hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
|
|
|
|
(1 << NF_BR_LOCAL_OUT)))) &&
|
|
|
|
(strcmp(par->table, "broute") != 0 ||
|
|
|
|
hook_mask & ~(1 << NF_BR_BROUTING)))
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
2005-04-17 00:20:36 +02:00
|
|
|
if (INVALID_TARGET)
|
2008-10-08 11:35:13 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 11:35:15 +02:00
|
|
|
static struct xt_target ebt_dnat_tg_reg __read_mostly = {
|
|
|
|
.name = "dnat",
|
2008-10-08 11:35:14 +02:00
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_BRIDGE,
|
2008-10-08 11:35:15 +02:00
|
|
|
.hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
|
|
|
|
(1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
|
2008-10-08 11:35:15 +02:00
|
|
|
.target = ebt_dnat_tg,
|
|
|
|
.checkentry = ebt_dnat_tg_check,
|
2008-10-08 11:35:13 +02:00
|
|
|
.targetsize = XT_ALIGN(sizeof(struct ebt_nat_info)),
|
2005-04-17 00:20:36 +02:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init ebt_dnat_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:15 +02:00
|
|
|
return xt_register_target(&ebt_dnat_tg_reg);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit ebt_dnat_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-10-08 11:35:15 +02:00
|
|
|
xt_unregister_target(&ebt_dnat_tg_reg);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(ebt_dnat_init);
|
|
|
|
module_exit(ebt_dnat_fini);
|
2008-01-31 13:00:30 +01:00
|
|
|
MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_LICENSE("GPL");
|