2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ebtable_nat
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* April, 2002
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
|
|
|
|
(1 << NF_BR_POST_ROUTING))
|
|
|
|
|
2013-12-19 06:28:14 +01:00
|
|
|
static struct ebt_entries initial_chains[] = {
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
.name = "PREROUTING",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "OUTPUT",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "POSTROUTING",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-19 06:28:14 +01:00
|
|
|
static struct ebt_replace_kernel initial_table = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.name = "nat",
|
|
|
|
.valid_hooks = NAT_VALID_HOOKS,
|
|
|
|
.entries_size = 3 * sizeof(struct ebt_entries),
|
|
|
|
.hook_entry = {
|
|
|
|
[NF_BR_PRE_ROUTING] = &initial_chains[0],
|
|
|
|
[NF_BR_LOCAL_OUT] = &initial_chains[1],
|
|
|
|
[NF_BR_POST_ROUTING] = &initial_chains[2],
|
|
|
|
},
|
|
|
|
.entries = (char *)initial_chains,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
|
|
|
|
{
|
|
|
|
if (valid_hooks & ~NAT_VALID_HOOKS)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-19 06:28:14 +01:00
|
|
|
static struct ebt_table frame_nat = {
|
2005-04-17 00:20:36 +02:00
|
|
|
.name = "nat",
|
|
|
|
.table = &initial_table,
|
|
|
|
.valid_hooks = NAT_VALID_HOOKS,
|
|
|
|
.check = check,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int
|
2013-10-10 09:21:55 +02:00
|
|
|
ebt_nat_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
|
|
|
const struct net_device *in, const struct net_device *out,
|
|
|
|
int (*okfn)(struct sk_buff *))
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2013-10-10 09:21:55 +02:00
|
|
|
return ebt_do_table(ops->hooknum, skb, in, out,
|
|
|
|
dev_net(in)->xt.frame_nat);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2013-10-10 09:21:55 +02:00
|
|
|
ebt_nat_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
|
|
|
|
const struct net_device *in, const struct net_device *out,
|
|
|
|
int (*okfn)(struct sk_buff *))
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2013-10-10 09:21:55 +02:00
|
|
|
return ebt_do_table(ops->hooknum, skb, in, out,
|
|
|
|
dev_net(out)->xt.frame_nat);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 10:23:00 +01:00
|
|
|
static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-11-04 14:30:46 +01:00
|
|
|
.hook = ebt_nat_out,
|
2005-04-17 00:20:36 +02:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-13 06:20:29 +02:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-17 00:20:36 +02:00
|
|
|
.hooknum = NF_BR_LOCAL_OUT,
|
|
|
|
.priority = NF_BR_PRI_NAT_DST_OTHER,
|
|
|
|
},
|
|
|
|
{
|
2008-11-04 14:30:46 +01:00
|
|
|
.hook = ebt_nat_out,
|
2005-04-17 00:20:36 +02:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-13 06:20:29 +02:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-17 00:20:36 +02:00
|
|
|
.hooknum = NF_BR_POST_ROUTING,
|
|
|
|
.priority = NF_BR_PRI_NAT_SRC,
|
|
|
|
},
|
|
|
|
{
|
2008-11-04 14:30:46 +01:00
|
|
|
.hook = ebt_nat_in,
|
2005-04-17 00:20:36 +02:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-13 06:20:29 +02:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-17 00:20:36 +02:00
|
|
|
.hooknum = NF_BR_PRE_ROUTING,
|
|
|
|
.priority = NF_BR_PRI_NAT_DST_BRIDGED,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-11-04 14:30:46 +01:00
|
|
|
static int __net_init frame_nat_net_init(struct net *net)
|
|
|
|
{
|
|
|
|
net->xt.frame_nat = ebt_register_table(net, &frame_nat);
|
2013-07-15 03:50:32 +02:00
|
|
|
return PTR_ERR_OR_ZERO(net->xt.frame_nat);
|
2008-11-04 14:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit frame_nat_net_exit(struct net *net)
|
|
|
|
{
|
2010-01-18 08:25:47 +01:00
|
|
|
ebt_unregister_table(net, net->xt.frame_nat);
|
2008-11-04 14:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations frame_nat_net_ops = {
|
|
|
|
.init = frame_nat_net_init,
|
|
|
|
.exit = frame_nat_net_exit,
|
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init ebtable_nat_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-27 02:47:53 +02:00
|
|
|
int ret;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-11-04 14:30:46 +01:00
|
|
|
ret = register_pernet_subsys(&frame_nat_net_ops);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-07-27 02:47:53 +02:00
|
|
|
ret = nf_register_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
|
|
|
|
if (ret < 0)
|
2008-11-04 14:30:46 +01:00
|
|
|
unregister_pernet_subsys(&frame_nat_net_ops);
|
2005-04-17 00:20:36 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit ebtable_nat_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-27 02:47:53 +02:00
|
|
|
nf_unregister_hooks(ebt_ops_nat, ARRAY_SIZE(ebt_ops_nat));
|
2008-11-04 14:30:46 +01:00
|
|
|
unregister_pernet_subsys(&frame_nat_net_ops);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(ebtable_nat_init);
|
|
|
|
module_exit(ebtable_nat_fini);
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_LICENSE("GPL");
|