Commit 0edcf282 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Pablo Neira Ayuso

netfilter: Factor out the hook list selection from nf_register_hook

- Add a new function find_nf_hook_list to select the nf_hook_list

- Fail nf_register_hook when asked for a per netdevice hook list when
  support for per netdevice hook lists is not built into the kernel.

- Move the hook list head selection outside of nf_hook_mutex as
  nothing in the selection requires the hook list, and error handling
  is simpler if a mutex is not held.
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 4c091156
...@@ -62,27 +62,31 @@ EXPORT_SYMBOL(nf_hooks_needed); ...@@ -62,27 +62,31 @@ EXPORT_SYMBOL(nf_hooks_needed);
static DEFINE_MUTEX(nf_hook_mutex); static DEFINE_MUTEX(nf_hook_mutex);
int nf_register_hook(struct nf_hook_ops *reg) static struct list_head *find_nf_hook_list(const struct nf_hook_ops *reg)
{ {
struct list_head *nf_hook_list; struct list_head *nf_hook_list = NULL;
struct nf_hook_ops *elem;
mutex_lock(&nf_hook_mutex); if (reg->pf != NFPROTO_NETDEV)
switch (reg->pf) { nf_hook_list = &nf_hooks[reg->pf][reg->hooknum];
case NFPROTO_NETDEV: else if (reg->hooknum == NF_NETDEV_INGRESS) {
#ifdef CONFIG_NETFILTER_INGRESS #ifdef CONFIG_NETFILTER_INGRESS
if (reg->hooknum == NF_NETDEV_INGRESS) { if (reg->dev)
BUG_ON(reg->dev == NULL);
nf_hook_list = &reg->dev->nf_hooks_ingress; nf_hook_list = &reg->dev->nf_hooks_ingress;
break;
}
#endif #endif
/* Fall through. */
default:
nf_hook_list = &nf_hooks[reg->pf][reg->hooknum];
break;
} }
return nf_hook_list;
}
int nf_register_hook(struct nf_hook_ops *reg)
{
struct list_head *nf_hook_list;
struct nf_hook_ops *elem;
nf_hook_list = find_nf_hook_list(reg);
if (!nf_hook_list)
return -ENOENT;
mutex_lock(&nf_hook_mutex);
list_for_each_entry(elem, nf_hook_list, list) { list_for_each_entry(elem, nf_hook_list, list) {
if (reg->priority < elem->priority) if (reg->priority < elem->priority)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment