]> err.no Git - linux-2.6/blobdiff - net/netfilter/nf_conntrack_core.c
[NETFILTER]: nfnetlink: use mutex instead of semaphore
[linux-2.6] / net / netfilter / nf_conntrack_core.c
index d59640e2377beec28138ffff908ce8ff6a524075..9858bcb29aa05d4cb39560d84b46d0ed927a03e9 100644 (file)
@@ -318,6 +318,7 @@ destroy_conntrack(struct nf_conntrack *nfct)
        struct nf_conn_help *help = nfct_help(ct);
        struct nf_conntrack_l3proto *l3proto;
        struct nf_conntrack_l4proto *l4proto;
+       typeof(nf_conntrack_destroyed) destroyed;
 
        DEBUGP("destroy_conntrack(%p)\n", ct);
        NF_CT_ASSERT(atomic_read(&nfct->use) == 0);
@@ -341,10 +342,12 @@ destroy_conntrack(struct nf_conntrack *nfct)
                                       ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.protonum);
        if (l4proto && l4proto->destroy)
                l4proto->destroy(ct);
-       rcu_read_unlock();
 
-       if (nf_conntrack_destroyed)
-               nf_conntrack_destroyed(ct);
+       destroyed = rcu_dereference(nf_conntrack_destroyed);
+       if (destroyed)
+               destroyed(ct);
+
+       rcu_read_unlock();
 
        write_lock_bh(&nf_conntrack_lock);
        /* Expectations will have been removed in clean_from_lists,
@@ -421,7 +424,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_find_get);
 
 static void __nf_conntrack_hash_insert(struct nf_conn *ct,
                                       unsigned int hash,
-                                      unsigned int repl_hash) 
+                                      unsigned int repl_hash)
 {
        ct->id = ++nf_conntrack_next_id;
        list_add(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list,
@@ -765,7 +768,7 @@ resolve_normal_ct(struct sk_buff *skb,
        struct nf_conntrack_tuple_hash *h;
        struct nf_conn *ct;
 
-       if (!nf_ct_get_tuple(skb, (unsigned int)(skb->nh.raw - skb->data),
+       if (!nf_ct_get_tuple(skb, skb_network_offset(skb),
                             dataoff, l3num, protonum, &tuple, l3proto,
                             l4proto)) {
                DEBUGP("resolve_normal_ct: Can't get tuple\n");
@@ -957,7 +960,7 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
        if (do_acct) {
                ct->counters[CTINFO2DIR(ctinfo)].packets++;
                ct->counters[CTINFO2DIR(ctinfo)].bytes +=
-                       skb->len - (unsigned int)(skb->nh.raw - skb->data);
+                       skb->len - skb_network_offset(skb);
 
                if ((ct->counters[CTINFO2DIR(ctinfo)].packets & 0x80000000)
                    || (ct->counters[CTINFO2DIR(ctinfo)].bytes & 0x80000000))
@@ -973,8 +976,7 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
 }
 EXPORT_SYMBOL_GPL(__nf_ct_refresh_acct);
 
-#if defined(CONFIG_NF_CT_NETLINK) || \
-    defined(CONFIG_NF_CT_NETLINK_MODULE)
+#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
 
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nfnetlink_conntrack.h>
@@ -1063,11 +1065,11 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
                        if (iter(ct, data))
                                goto found;
                }
-       }
+       }
        list_for_each_entry(h, &unconfirmed, list) {
                ct = nf_ct_tuplehash_to_ctrack(h);
                if (iter(ct, data))
-                       goto found;
+                       set_bit(IPS_DYING_BIT, &ct->status);
        }
        write_unlock_bh(&nf_conntrack_lock);
        return NULL;
@@ -1104,7 +1106,7 @@ static void free_conntrack_hash(struct list_head *hash, int vmalloced, int size)
        if (vmalloced)
                vfree(hash);
        else
-               free_pages((unsigned long)hash, 
+               free_pages((unsigned long)hash,
                           get_order(sizeof(struct list_head) * size));
 }
 
@@ -1150,14 +1152,7 @@ void nf_conntrack_cleanup(void)
        free_conntrack_hash(nf_conntrack_hash, nf_conntrack_vmalloc,
                            nf_conntrack_htable_size);
 
-       nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_generic);
-
-       /* free l3proto protocol tables */
-       for (i = 0; i < PF_MAX; i++)
-               if (nf_ct_protos[i]) {
-                       kfree(nf_ct_protos[i]);
-                       nf_ct_protos[i] = NULL;
-               }
+       nf_conntrack_proto_fini();
 }
 
 static struct list_head *alloc_hashtable(int size, int *vmalloced)
@@ -1165,18 +1160,18 @@ static struct list_head *alloc_hashtable(int size, int *vmalloced)
        struct list_head *hash;
        unsigned int i;
 
-       *vmalloced = 0; 
-       hash = (void*)__get_free_pages(GFP_KERNEL, 
+       *vmalloced = 0;
+       hash = (void*)__get_free_pages(GFP_KERNEL,
                                       get_order(sizeof(struct list_head)
                                                 * size));
-       if (!hash) { 
+       if (!hash) {
                *vmalloced = 1;
                printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
                hash = vmalloc(sizeof(struct list_head) * size);
        }
 
        if (hash)
-               for (i = 0; i < size; i++) 
+               for (i = 0; i < size; i++)
                        INIT_LIST_HEAD(&hash[i]);
 
        return hash;
@@ -1235,7 +1230,6 @@ module_param_call(hashsize, set_hashsize, param_get_uint,
 
 int __init nf_conntrack_init(void)
 {
-       unsigned int i;
        int ret;
 
        /* Idea from tcp.c: use 1/16384 of memory.  On i386: 32MB
@@ -1277,16 +1271,10 @@ int __init nf_conntrack_init(void)
                goto err_free_conntrack_slab;
        }
 
-       ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_generic);
+       ret = nf_conntrack_proto_init();
        if (ret < 0)
                goto out_free_expect_slab;
 
-       /* Don't NEED lock here, but good form anyway. */
-       write_lock_bh(&nf_conntrack_lock);
-        for (i = 0; i < AF_MAX; i++)
-               nf_ct_l3protos[i] = &nf_conntrack_l3proto_generic;
-        write_unlock_bh(&nf_conntrack_lock);
-
        /* For use by REJECT target */
        rcu_assign_pointer(ip_ct_attach, __nf_conntrack_attach);