net: Add _nf_(un)register_hooks symbols
authorMahesh Bandewar <maheshb@google.com>
Fri, 16 Sep 2016 19:59:13 +0000 (12:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 19 Sep 2016 05:25:22 +0000 (01:25 -0400)
Add _nf_register_hooks() and _nf_unregister_hooks() calls which allow
caller to hold RTNL mutex.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
CC: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netfilter.h
net/netfilter/core.c

index 9230f9aee896facb508fcf23df9e48e842a976c9..e82b76781bf65fe503c8493621bd094e5af1381c 100644 (file)
@@ -133,6 +133,8 @@ int nf_register_hook(struct nf_hook_ops *reg);
 void nf_unregister_hook(struct nf_hook_ops *reg);
 int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
 void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
+int _nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
+void _nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
 
 /* Functions to register get/setsockopt ranges (non-inclusive).  You
    need to check permissions yourself! */
index f39276d1c2d76788dfc018f2ebdc07d2855f977d..2c5327e43a88a3906e8f9653ebcb72e1882cb7f9 100644 (file)
@@ -188,19 +188,17 @@ EXPORT_SYMBOL(nf_unregister_net_hooks);
 
 static LIST_HEAD(nf_hook_list);
 
-int nf_register_hook(struct nf_hook_ops *reg)
+static int _nf_register_hook(struct nf_hook_ops *reg)
 {
        struct net *net, *last;
        int ret;
 
-       rtnl_lock();
        for_each_net(net) {
                ret = nf_register_net_hook(net, reg);
                if (ret && ret != -ENOENT)
                        goto rollback;
        }
        list_add_tail(&reg->list, &nf_hook_list);
-       rtnl_unlock();
 
        return 0;
 rollback:
@@ -210,19 +208,34 @@ rollback:
                        break;
                nf_unregister_net_hook(net, reg);
        }
+       return ret;
+}
+
+int nf_register_hook(struct nf_hook_ops *reg)
+{
+       int ret;
+
+       rtnl_lock();
+       ret = _nf_register_hook(reg);
        rtnl_unlock();
+
        return ret;
 }
 EXPORT_SYMBOL(nf_register_hook);
 
-void nf_unregister_hook(struct nf_hook_ops *reg)
+static void _nf_unregister_hook(struct nf_hook_ops *reg)
 {
        struct net *net;
 
-       rtnl_lock();
        list_del(&reg->list);
        for_each_net(net)
                nf_unregister_net_hook(net, reg);
+}
+
+void nf_unregister_hook(struct nf_hook_ops *reg)
+{
+       rtnl_lock();
+       _nf_unregister_hook(reg);
        rtnl_unlock();
 }
 EXPORT_SYMBOL(nf_unregister_hook);
@@ -246,6 +259,26 @@ err:
 }
 EXPORT_SYMBOL(nf_register_hooks);
 
+/* Caller MUST take rtnl_lock() */
+int _nf_register_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+       unsigned int i;
+       int err = 0;
+
+       for (i = 0; i < n; i++) {
+               err = _nf_register_hook(&reg[i]);
+               if (err)
+                       goto err;
+       }
+       return err;
+
+err:
+       if (i > 0)
+               _nf_unregister_hooks(reg, i);
+       return err;
+}
+EXPORT_SYMBOL(_nf_register_hooks);
+
 void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
 {
        while (n-- > 0)
@@ -253,6 +286,14 @@ void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
 }
 EXPORT_SYMBOL(nf_unregister_hooks);
 
+/* Caller MUST take rtnl_lock */
+void _nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)
+{
+       while (n-- > 0)
+               _nf_unregister_hook(&reg[n]);
+}
+EXPORT_SYMBOL(_nf_unregister_hooks);
+
 unsigned int nf_iterate(struct list_head *head,
                        struct sk_buff *skb,
                        struct nf_hook_state *state,