]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
netfilter: use rcu_dereference_protected()
authorPatrick McHardy <kaber@trash.net>
Mon, 10 May 2010 16:47:57 +0000 (18:47 +0200)
committerPatrick McHardy <kaber@trash.net>
Mon, 10 May 2010 16:47:57 +0000 (18:47 +0200)
Restore the rcu_dereference() calls in conntrack/expectation notifier
and logger registration/unregistration, but use the _protected variant,
which will be required by the upcoming __rcu annotations.

Based on patch by Eric Dumazet <eric.dumazet@gmail.com>

Signed-off-by: Patrick McHardy <kaber@trash.net>
net/netfilter/nf_conntrack_ecache.c
net/netfilter/nf_log.c

index a94ac3ad02cb5f35a8aab38d6232be04f967ac7f..cdcc7649476b60e0e8584a7c2b2d31e7509a4bd4 100644 (file)
@@ -82,9 +82,12 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
 int nf_conntrack_register_notifier(struct nf_ct_event_notifier *new)
 {
        int ret = 0;
+       struct nf_ct_event_notifier *notify;
 
        mutex_lock(&nf_ct_ecache_mutex);
-       if (nf_conntrack_event_cb != NULL) {
+       notify = rcu_dereference_protected(nf_conntrack_event_cb,
+                                          lockdep_is_held(&nf_ct_ecache_mutex));
+       if (notify != NULL) {
                ret = -EBUSY;
                goto out_unlock;
        }
@@ -100,8 +103,12 @@ EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
 
 void nf_conntrack_unregister_notifier(struct nf_ct_event_notifier *new)
 {
+       struct nf_ct_event_notifier *notify;
+
        mutex_lock(&nf_ct_ecache_mutex);
-       BUG_ON(nf_conntrack_event_cb != new);
+       notify = rcu_dereference_protected(nf_conntrack_event_cb,
+                                          lockdep_is_held(&nf_ct_ecache_mutex));
+       BUG_ON(notify != new);
        rcu_assign_pointer(nf_conntrack_event_cb, NULL);
        mutex_unlock(&nf_ct_ecache_mutex);
 }
@@ -110,9 +117,12 @@ EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
 int nf_ct_expect_register_notifier(struct nf_exp_event_notifier *new)
 {
        int ret = 0;
+       struct nf_exp_event_notifier *notify;
 
        mutex_lock(&nf_ct_ecache_mutex);
-       if (nf_expect_event_cb != NULL) {
+       notify = rcu_dereference_protected(nf_expect_event_cb,
+                                          lockdep_is_held(&nf_ct_ecache_mutex));
+       if (notify != NULL) {
                ret = -EBUSY;
                goto out_unlock;
        }
@@ -128,8 +138,12 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_register_notifier);
 
 void nf_ct_expect_unregister_notifier(struct nf_exp_event_notifier *new)
 {
+       struct nf_exp_event_notifier *notify;
+
        mutex_lock(&nf_ct_ecache_mutex);
-       BUG_ON(nf_expect_event_cb != new);
+       notify = rcu_dereference_protected(nf_expect_event_cb,
+                                          lockdep_is_held(&nf_ct_ecache_mutex));
+       BUG_ON(notify != new);
        rcu_assign_pointer(nf_expect_event_cb, NULL);
        mutex_unlock(&nf_ct_ecache_mutex);
 }
index 908f59935fbb63064ee9b5feec061748d22b0cbc..7df37fd786bc19406a5ed8a8558df95cd26d93be 100644 (file)
@@ -35,6 +35,7 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
 /* return EEXIST if the same logger is registred, 0 on success. */
 int nf_log_register(u_int8_t pf, struct nf_logger *logger)
 {
+       const struct nf_logger *llog;
        int i;
 
        if (pf >= ARRAY_SIZE(nf_loggers))
@@ -51,7 +52,9 @@ int nf_log_register(u_int8_t pf, struct nf_logger *logger)
        } else {
                /* register at end of list to honor first register win */
                list_add_tail(&logger->list[pf], &nf_loggers_l[pf]);
-               if (nf_loggers[pf] == NULL)
+               llog = rcu_dereference_protected(nf_loggers[pf],
+                                                lockdep_is_held(&nf_log_mutex));
+               if (llog == NULL)
                        rcu_assign_pointer(nf_loggers[pf], logger);
        }
 
@@ -63,11 +66,14 @@ EXPORT_SYMBOL(nf_log_register);
 
 void nf_log_unregister(struct nf_logger *logger)
 {
+       const struct nf_logger *c_logger;
        int i;
 
        mutex_lock(&nf_log_mutex);
        for (i = 0; i < ARRAY_SIZE(nf_loggers); i++) {
-               if (nf_loggers[i] == logger)
+               c_logger = rcu_dereference_protected(nf_loggers[i],
+                                                    lockdep_is_held(&nf_log_mutex));
+               if (c_logger == logger)
                        rcu_assign_pointer(nf_loggers[i], NULL);
                list_del(&logger->list[i]);
        }