[PATCH] for_each_possible_cpu: network codes
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_core.c
index c288406..e581190 100644 (file)
@@ -23,6 +23,8 @@
  * 26 Jan 2006: Harald Welte <laforge@netfilter.org>
  *     - restructure nf_conn (introduce nf_conn_help)
  *     - redesign 'features' how they were originally intended
+ * 26 Feb 2006: Pablo Neira Ayuso <pablo@eurodev.net>
+ *     - add support for L3 protocol module load on demand.
  *
  * Derived from net/ipv4/netfilter/ip_conntrack_core.c
  */
@@ -88,8 +90,8 @@ static int nf_conntrack_vmalloc;
 static unsigned int nf_conntrack_next_id;
 static unsigned int nf_conntrack_expect_next_id;
 #ifdef CONFIG_NF_CONNTRACK_EVENTS
-struct notifier_block *nf_conntrack_chain;
-struct notifier_block *nf_conntrack_expect_chain;
+ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);
+ATOMIC_NOTIFIER_HEAD(nf_conntrack_expect_chain);
 
 DEFINE_PER_CPU(struct nf_conntrack_ecache, nf_conntrack_ecache);
 
@@ -101,7 +103,7 @@ __nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
        DEBUGP("ecache: delivering events for %p\n", ecache->ct);
        if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
            && ecache->events)
-               notifier_call_chain(&nf_conntrack_chain, ecache->events,
+               atomic_notifier_call_chain(&nf_conntrack_chain, ecache->events,
                                    ecache->ct);
 
        ecache->events = 0;
@@ -144,7 +146,7 @@ static void nf_ct_event_cache_flush(void)
        struct nf_conntrack_ecache *ecache;
        int cpu;
 
-       for_each_cpu(cpu) {
+       for_each_possible_cpu(cpu) {
                ecache = &per_cpu(nf_conntrack_ecache, cpu);
                if (ecache->ct)
                        nf_ct_put(ecache->ct);
@@ -241,6 +243,35 @@ void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p)
        module_put(p->me);
 }
 
+int
+nf_ct_l3proto_try_module_get(unsigned short l3proto)
+{
+       int ret;
+       struct nf_conntrack_l3proto *p;
+
+retry: p = nf_ct_l3proto_find_get(l3proto);
+       if (p == &nf_conntrack_generic_l3proto) {
+               ret = request_module("nf_conntrack-%d", l3proto);
+               if (!ret)
+                       goto retry;
+
+               return -EPROTOTYPE;
+       }
+
+       return 0;
+}
+
+void nf_ct_l3proto_module_put(unsigned short l3proto)
+{
+       struct nf_conntrack_l3proto *p;
+
+       preempt_disable();
+       p = __nf_ct_l3proto_find(l3proto);
+       preempt_enable();
+
+       module_put(p->me);
+}
+
 static int nf_conntrack_hash_rnd_initted;
 static unsigned int nf_conntrack_hash_rnd;