2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* ebtable_broute
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* April, 2002
|
|
|
|
*
|
|
|
|
* This table lets you choose between routing and bridging for frames
|
|
|
|
* entering on a bridge enslaved nic. This table is traversed before any
|
|
|
|
* other ebtables table. See net/bridge/br_input.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/if_bridge.h>
|
|
|
|
|
|
|
|
/* EBT_ACCEPT means the frame will be bridged
|
|
|
|
* EBT_DROP means the frame will be routed
|
|
|
|
*/
|
|
|
|
static struct ebt_entries initial_chain = {
|
|
|
|
.name = "BROUTING",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
};
|
|
|
|
|
2006-12-01 04:28:48 +01:00
|
|
|
static struct ebt_replace_kernel initial_table =
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
.name = "broute",
|
|
|
|
.valid_hooks = 1 << NF_BR_BROUTING,
|
|
|
|
.entries_size = sizeof(struct ebt_entries),
|
|
|
|
.hook_entry = {
|
|
|
|
[NF_BR_BROUTING] = &initial_chain,
|
|
|
|
},
|
|
|
|
.entries = (char *)&initial_chain,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
|
|
|
|
{
|
|
|
|
if (valid_hooks & ~(1 << NF_BR_BROUTING))
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-24 14:56:30 +02:00
|
|
|
static const struct ebt_table broute_table =
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
.name = "broute",
|
|
|
|
.table = &initial_table,
|
|
|
|
.valid_hooks = 1 << NF_BR_BROUTING,
|
|
|
|
.check = check,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
static int ebt_broute(struct sk_buff *skb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2007-10-15 09:53:15 +02:00
|
|
|
ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL,
|
2008-11-04 14:29:03 +01:00
|
|
|
dev_net(skb->dev)->xt.broute_table);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (ret == NF_DROP)
|
|
|
|
return 1; /* route it */
|
|
|
|
return 0; /* bridge it */
|
|
|
|
}
|
|
|
|
|
2008-11-04 14:29:03 +01:00
|
|
|
static int __net_init broute_net_init(struct net *net)
|
|
|
|
{
|
|
|
|
net->xt.broute_table = ebt_register_table(net, &broute_table);
|
|
|
|
if (IS_ERR(net->xt.broute_table))
|
|
|
|
return PTR_ERR(net->xt.broute_table);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit broute_net_exit(struct net *net)
|
|
|
|
{
|
2010-01-18 08:25:47 +01:00
|
|
|
ebt_unregister_table(net, net->xt.broute_table);
|
2008-11-04 14:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations broute_net_ops = {
|
|
|
|
.init = broute_net_init,
|
|
|
|
.exit = broute_net_exit,
|
|
|
|
};
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static int __init ebtable_broute_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-11-04 14:29:03 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = register_pernet_subsys(&broute_net_ops);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2005-04-17 00:20:36 +02:00
|
|
|
/* see br_input.c */
|
2010-11-15 07:38:11 +01:00
|
|
|
rcu_assign_pointer(br_should_route_hook,
|
|
|
|
(br_should_route_hook_t *)ebt_broute);
|
2008-11-04 14:27:15 +01:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
static void __exit ebtable_broute_fini(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-11-29 13:58:58 +01:00
|
|
|
rcu_assign_pointer(br_should_route_hook, NULL);
|
2005-04-17 00:20:36 +02:00
|
|
|
synchronize_net();
|
2008-11-04 14:29:03 +01:00
|
|
|
unregister_pernet_subsys(&broute_net_ops);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2006-03-29 02:37:06 +02:00
|
|
|
module_init(ebtable_broute_init);
|
|
|
|
module_exit(ebtable_broute_fini);
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_LICENSE("GPL");
|