[TWSK]: Grab the module refcount for timewait sockets
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>
Tue, 11 Oct 2005 04:25:23 +0000 (21:25 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 11 Oct 2005 04:25:23 +0000 (21:25 -0700)
This is required to avoid unloading a module that has active timewait
sockets, such as DCCP.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_timewait_sock.h
net/ipv4/inet_timewait_sock.c

index 4ade56ef3a4da8894a42978a7663d883219cc3df..28f7b2103505edc6cd4389e96aeca02845b1192d 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <linux/ip.h>
 #include <linux/list.h>
+#include <linux/module.h>
 #include <linux/timer.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
@@ -193,11 +194,13 @@ static inline u32 inet_rcv_saddr(const struct sock *sk)
 static inline void inet_twsk_put(struct inet_timewait_sock *tw)
 {
        if (atomic_dec_and_test(&tw->tw_refcnt)) {
+               struct module *owner = tw->tw_prot->owner;
 #ifdef SOCK_REFCNT_DEBUG
                printk(KERN_DEBUG "%s timewait_sock %p released\n",
                       tw->tw_prot->name, tw);
 #endif
                kmem_cache_free(tw->tw_prot->twsk_slab, tw);
+               module_put(owner);
        }
 }
 
index f9076ef3a1a810b54ef5671d9620b5960cff8ac0..a010e9a68811cf325f75b6b894849cd2a58303cc 100644 (file)
@@ -111,6 +111,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
                tw->tw_prot         = sk->sk_prot_creator;
                atomic_set(&tw->tw_refcnt, 1);
                inet_twsk_dead_node_init(tw);
+               __module_get(tw->tw_prot->owner);
        }
 
        return tw;