2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* ebtable_filter
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* April, 2002
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
|
|
|
|
(1 << NF_BR_LOCAL_OUT))
|
|
|
|
|
|
|
|
static struct ebt_entries initial_chains[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
.name = "INPUT",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "FORWARD",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "OUTPUT",
|
|
|
|
.policy = EBT_ACCEPT,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2006-11-30 20:28:48 -07:00
|
|
|
static struct ebt_replace_kernel initial_table =
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
.name = "filter",
|
|
|
|
.valid_hooks = FILTER_VALID_HOOKS,
|
|
|
|
.entries_size = 3 * sizeof(struct ebt_entries),
|
|
|
|
.hook_entry = {
|
|
|
|
[NF_BR_LOCAL_IN] = &initial_chains[0],
|
|
|
|
[NF_BR_FORWARD] = &initial_chains[1],
|
|
|
|
[NF_BR_LOCAL_OUT] = &initial_chains[2],
|
|
|
|
},
|
|
|
|
.entries = (char *)initial_chains,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
|
|
|
|
{
|
|
|
|
if (valid_hooks & ~FILTER_VALID_HOOKS)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-24 06:56:30 -06:00
|
|
|
static const struct ebt_table frame_filter =
|
2007-02-09 07:24:35 -07:00
|
|
|
{
|
2005-04-16 16:20:36 -06:00
|
|
|
.name = "filter",
|
|
|
|
.table = &initial_table,
|
2007-02-09 07:24:35 -07:00
|
|
|
.valid_hooks = FILTER_VALID_HOOKS,
|
2005-04-16 16:20:36 -06:00
|
|
|
.check = check,
|
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int
|
2008-11-04 06:29:58 -07:00
|
|
|
ebt_in_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in,
|
2005-04-16 16:20:36 -06:00
|
|
|
const struct net_device *out, int (*okfn)(struct sk_buff *))
|
|
|
|
{
|
2008-11-04 06:29:58 -07:00
|
|
|
return ebt_do_table(hook, skb, in, out, dev_net(in)->xt.frame_filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
ebt_out_hook(unsigned int hook, struct sk_buff *skb, const struct net_device *in,
|
|
|
|
const struct net_device *out, int (*okfn)(struct sk_buff *))
|
|
|
|
{
|
|
|
|
return ebt_do_table(hook, skb, in, out, dev_net(out)->xt.frame_filter);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 02:23:00 -07:00
|
|
|
static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-11-04 06:29:58 -07:00
|
|
|
.hook = ebt_in_hook,
|
2005-04-16 16:20:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-12 22:20:29 -06:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-16 16:20:36 -06:00
|
|
|
.hooknum = NF_BR_LOCAL_IN,
|
|
|
|
.priority = NF_BR_PRI_FILTER_BRIDGED,
|
|
|
|
},
|
|
|
|
{
|
2008-11-04 06:29:58 -07:00
|
|
|
.hook = ebt_in_hook,
|
2005-04-16 16:20:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-12 22:20:29 -06:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-16 16:20:36 -06:00
|
|
|
.hooknum = NF_BR_FORWARD,
|
|
|
|
.priority = NF_BR_PRI_FILTER_BRIDGED,
|
|
|
|
},
|
|
|
|
{
|
2008-11-04 06:29:58 -07:00
|
|
|
.hook = ebt_out_hook,
|
2005-04-16 16:20:36 -06:00
|
|
|
.owner = THIS_MODULE,
|
2009-06-12 22:20:29 -06:00
|
|
|
.pf = NFPROTO_BRIDGE,
|
2005-04-16 16:20:36 -06:00
|
|
|
.hooknum = NF_BR_LOCAL_OUT,
|
|
|
|
.priority = NF_BR_PRI_FILTER_OTHER,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2008-11-04 06:29:58 -07:00
|
|
|
static int __net_init frame_filter_net_init(struct net *net)
|
|
|
|
{
|
|
|
|
net->xt.frame_filter = ebt_register_table(net, &frame_filter);
|
2013-07-14 19:50:32 -06:00
|
|
|
return PTR_ERR_OR_ZERO(net->xt.frame_filter);
|
2008-11-04 06:29:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit frame_filter_net_exit(struct net *net)
|
|
|
|
{
|
2010-01-18 00:25:47 -07:00
|
|
|
ebt_unregister_table(net, net->xt.frame_filter);
|
2008-11-04 06:29:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations frame_filter_net_ops = {
|
|
|
|
.init = frame_filter_net_init,
|
|
|
|
.exit = frame_filter_net_exit,
|
|
|
|
};
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static int __init ebtable_filter_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-07-26 18:47:53 -06:00
|
|
|
int ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-11-04 06:29:58 -07:00
|
|
|
ret = register_pernet_subsys(&frame_filter_net_ops);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-07-26 18:47:53 -06:00
|
|
|
ret = nf_register_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
|
|
|
|
if (ret < 0)
|
2008-11-04 06:29:58 -07:00
|
|
|
unregister_pernet_subsys(&frame_filter_net_ops);
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static void __exit ebtable_filter_fini(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-07-26 18:47:53 -06:00
|
|
|
nf_unregister_hooks(ebt_ops_filter, ARRAY_SIZE(ebt_ops_filter));
|
2008-11-04 06:29:58 -07:00
|
|
|
unregister_pernet_subsys(&frame_filter_net_ops);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
module_init(ebtable_filter_init);
|
|
|
|
module_exit(ebtable_filter_fini);
|
2005-04-16 16:20:36 -06:00
|
|
|
MODULE_LICENSE("GPL");
|