]> err.no Git - linux-2.6/commitdiff
[NETFILTER]: nf_conntrack: use RCU for conntrack helpers
authorPatrick McHardy <kaber@trash.net>
Thu, 31 Jan 2008 12:36:54 +0000 (04:36 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Feb 2008 03:27:51 +0000 (19:27 -0800)
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netfilter/nf_conntrack_helper.h
net/netfilter/nf_conntrack_helper.c
net/netfilter/nf_conntrack_netlink.c

index 2f3af00643cf92166c1898740d45c56334d0c55c..4ca125e9b3ce30870cfde5182d4b8000c4925920 100644 (file)
@@ -42,13 +42,9 @@ struct nf_conntrack_helper
 extern struct nf_conntrack_helper *
 __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple);
 
-extern struct nf_conntrack_helper *
-nf_ct_helper_find_get( const struct nf_conntrack_tuple *tuple);
-
 extern struct nf_conntrack_helper *
 __nf_conntrack_helper_find_byname(const char *name);
 
-extern void nf_ct_helper_put(struct nf_conntrack_helper *helper);
 extern int nf_conntrack_helper_register(struct nf_conntrack_helper *);
 extern void nf_conntrack_helper_unregister(struct nf_conntrack_helper *);
 
index 96aa637c09327e6c79a85ec6a76cd86228aa908a..42f781fcba649bbe783523d2a1d547296fb379e8 100644 (file)
@@ -28,6 +28,7 @@
 #include <net/netfilter/nf_conntrack_core.h>
 #include <net/netfilter/nf_conntrack_extend.h>
 
+static DEFINE_MUTEX(nf_ct_helper_mutex);
 static struct hlist_head *nf_ct_helper_hash __read_mostly;
 static unsigned int nf_ct_helper_hsize __read_mostly;
 static unsigned int nf_ct_helper_count __read_mostly;
@@ -54,42 +55,13 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
                return NULL;
 
        h = helper_hash(tuple);
-       hlist_for_each_entry(helper, n, &nf_ct_helper_hash[h], hnode) {
+       hlist_for_each_entry_rcu(helper, n, &nf_ct_helper_hash[h], hnode) {
                if (nf_ct_tuple_src_mask_cmp(tuple, &helper->tuple, &mask))
                        return helper;
        }
        return NULL;
 }
-
-struct nf_conntrack_helper *
-nf_ct_helper_find_get(const struct nf_conntrack_tuple *tuple)
-{
-       struct nf_conntrack_helper *helper;
-
-       /* need nf_conntrack_lock to assure that helper exists until
-        * try_module_get() is called */
-       read_lock_bh(&nf_conntrack_lock);
-
-       helper = __nf_ct_helper_find(tuple);
-       if (helper) {
-               /* need to increase module usage count to assure helper will
-                * not go away while the caller is e.g. busy putting a
-                * conntrack in the hash that uses the helper */
-               if (!try_module_get(helper->me))
-                       helper = NULL;
-       }
-
-       read_unlock_bh(&nf_conntrack_lock);
-
-       return helper;
-}
-EXPORT_SYMBOL_GPL(nf_ct_helper_find_get);
-
-void nf_ct_helper_put(struct nf_conntrack_helper *helper)
-{
-       module_put(helper->me);
-}
-EXPORT_SYMBOL_GPL(nf_ct_helper_put);
+EXPORT_SYMBOL_GPL(__nf_ct_helper_find);
 
 struct nf_conntrack_helper *
 __nf_conntrack_helper_find_byname(const char *name)
@@ -99,7 +71,7 @@ __nf_conntrack_helper_find_byname(const char *name)
        unsigned int i;
 
        for (i = 0; i < nf_ct_helper_hsize; i++) {
-               hlist_for_each_entry(h, n, &nf_ct_helper_hash[i], hnode) {
+               hlist_for_each_entry_rcu(h, n, &nf_ct_helper_hash[i], hnode) {
                        if (!strcmp(h->name, name))
                                return h;
                }
@@ -140,10 +112,10 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me)
 
        BUG_ON(me->timeout == 0);
 
-       write_lock_bh(&nf_conntrack_lock);
-       hlist_add_head(&me->hnode, &nf_ct_helper_hash[h]);
+       mutex_lock(&nf_ct_helper_mutex);
+       hlist_add_head_rcu(&me->hnode, &nf_ct_helper_hash[h]);
        nf_ct_helper_count++;
-       write_unlock_bh(&nf_conntrack_lock);
+       mutex_unlock(&nf_ct_helper_mutex);
 
        return 0;
 }
@@ -156,10 +128,17 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
        struct hlist_node *n, *next;
        unsigned int i;
 
-       /* Need write lock here, to delete helper. */
-       write_lock_bh(&nf_conntrack_lock);
-       hlist_del(&me->hnode);
+       mutex_lock(&nf_ct_helper_mutex);
+       hlist_del_rcu(&me->hnode);
        nf_ct_helper_count--;
+       mutex_unlock(&nf_ct_helper_mutex);
+
+       /* Make sure every nothing is still using the helper unless its a
+        * connection in the hash.
+        */
+       synchronize_rcu();
+
+       write_lock_bh(&nf_conntrack_lock);
 
        /* Get rid of expectations */
        for (i = 0; i < nf_ct_expect_hsize; i++) {
@@ -182,9 +161,6 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)
                        unhelp(h, me);
        }
        write_unlock_bh(&nf_conntrack_lock);
-
-       /* Someone could be still looking at the helper in a bh. */
-       synchronize_net();
 }
 EXPORT_SYMBOL_GPL(nf_conntrack_helper_unregister);
 
index bdae2924d4252384f459c2fb4dbe531013381e70..b6c0935e09dfbfb8ca7526e130a469546468b4ae 100644 (file)
@@ -1167,11 +1167,12 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
                ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
 #endif
 
-       helper = nf_ct_helper_find_get(rtuple);
+       rcu_read_lock();
+       helper = __nf_ct_helper_find(rtuple);
        if (helper) {
                help = nf_ct_helper_ext_add(ct, GFP_KERNEL);
                if (help == NULL) {
-                       nf_ct_helper_put(helper);
+                       rcu_read_unlock();
                        err = -ENOMEM;
                        goto err;
                }
@@ -1187,9 +1188,7 @@ ctnetlink_create_conntrack(struct nlattr *cda[],
 
        add_timer(&ct->timeout);
        nf_conntrack_hash_insert(ct);
-
-       if (helper)
-               nf_ct_helper_put(helper);
+       rcu_read_unlock();
 
        return 0;