Skip to contentSkip to conversation

remove write lock in ip_conntrack_hash_insert

PATCH In review Pablo Neira Ayuso 1 participant 1 message Jul 7, 2006

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 4/10 remove write lock in ip_conntrack_hash_insert

The insertion into hashes is composed of two steps: insertion itself and timer activation, this two steps process must be atomic. Therefore, the ip_conntrack_hash_insert call and timer activation must be done inside appropiate write lock.

This patch depends on [PATCH 3/10]

Signature · 1 line
The dawn of the fourth age of Linux firewalling is coming; a time of great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

[CONNTRACK] remove write lock in ip_conntrack_hash_insert

The insertion into hashes is composed of two steps: insertion itself and timer activation, this two steps process must be atomic. Therefore, the ip_conntrack_hash_insert call and timer activation must be done inside appropiate write lock.

net/ipv4/netfilter/ip_conntrack_core.c +2 -2
Index: net-2.6/net/ipv4/netfilter/ip_conntrack_core.c
===================================================================
@@ -428,12 +428,12 @@ void ip_conntrack_hash_insert(struct ip_
 {
 	unsigned int hash, repl_hash;
 
+	ASSERT_WRITE_LOCK(&ip_conntrack_lock);
+	
 	hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
 	repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
 
-	write_lock_bh(&ip_conntrack_lock);
 	__ip_conntrack_hash_insert(ct, hash, repl_hash);
-	write_unlock_bh(&ip_conntrack_lock);
 }
 
 /* Confirm a connection given skb; places it in hash table */
net/netfilter/nf_conntrack_core.c +2 -2
Index: net-2.6/net/netfilter/nf_conntrack_core.c
===================================================================
@@ -678,12 +678,12 @@ void nf_conntrack_hash_insert(struct nf_
 {
 	unsigned int hash, repl_hash;
 
+	ASSERT_WRITE_LOCK(&nf_conntrack_lock);
+
 	hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
 	repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
 
-	write_lock_bh(&nf_conntrack_lock);
 	__nf_conntrack_hash_insert(ct, hash, repl_hash);
-	write_unlock_bh(&nf_conntrack_lock);
 }
 
 /* Confirm a connection given skb; places it in hash table */