Skip to contentSkip to conversation

netfilter: nf_conntrack: remove the unneed check for *bucket

PATCH In review Weidong Wang 3 participants 4 messages Jan 30, 2016 – Feb 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nf_conntrack: remove the unneed check for *bucket

In the 'for(...) {}', the *bucket alwasy < net->ct.htable_size, so remove the check

---
 net/netfilter/nf_conntrack_core.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
net/netfilter/nf_conntrack_core.c +6 -8
index 3cb3cb8..cd7d5c8 100644
@@ -1383,14 +1383,12 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
 		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
 		local_bh_disable();
 		spin_lock(lockp);
-		if (*bucket < net->ct.htable_size) {
-			hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) {
-				if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-					continue;
-				ct = nf_ct_tuplehash_to_ctrack(h);
-				if (iter(ct, data))
-					goto found;
-			}
+		hlist_nulls_for_each_entry(h, n, &net->ct.hash[*bucket], hnnode) {
+			if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+				continue;
+			ct = nf_ct_tuplehash_to_ctrack(h);
+			if (iter(ct, data))
+				goto found;
 		}
 		spin_unlock(lockp);
 		local_bh_enable();
Signature · 1 line
2.7.0
maintainer
#1 lore raw

net/netfilter/nf_conntrack_core.c get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data), · line 1386

Quoted 7 lines · Weidong Wang

In the 'for(...) {}', the *bucket alwasy < net->ct.htable_size, so remove the check

net/netfilter/nf_conntrack_core.c +0 -1
@@ -1383,14 +1383,12 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
 		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
 		local_bh_disable();
 		spin_lock(lockp);
-		if (*bucket < net->ct.htable_size) {

AFAIU net->ct.htable_size can shrink between for-test and aquiring the bucket lockp, so this additional if-test is needed.

#2 lore raw
Quoted 12 lines · Florian Westphal

net/netfilter/nf_conntrack_core.c get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data), · line 1386

Quoted 7 lines · Weidong Wang

In the 'for(...) {}', the *bucket alwasy < net->ct.htable_size, so remove the check

net/netfilter/nf_conntrack_core.c +0 -1
@@ -1383,14 +1383,12 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
 		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
 		local_bh_disable();
 		spin_lock(lockp);
-		if (*bucket < net->ct.htable_size) {

AFAIU net->ct.htable_size can shrink between for-test and aquiring the bucket lockp, so this additional if-test is needed.

ok, Got it.
So ignore this patch.

Regards,
Weidong

Quoted 2 lines

.

#3 lore raw
In reply to Florian Westphal

From: Florian Westphal

Quoted 12 lines

Sent: 30 January 2016 21:30

net/netfilter/nf_conntrack_core.c get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data), · line 1386

Quoted 7 lines · Weidong Wang

In the 'for(...) {}', the *bucket alwasy < net->ct.htable_size, so remove the check

net/netfilter/nf_conntrack_core.c +0 -1
@@ -1383,14 +1383,12 @@ get_next_corpse(struct net *net, int (*iter)(struct nf_conn *i, void *data),
 		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
 		local_bh_disable();
 		spin_lock(lockp);
-		if (*bucket < net->ct.htable_size) {

AFAIU net->ct.htable_size can shrink between for-test and aquiring the bucket lockp, so this additional if-test is needed.

If the table can shrink, can it not also grow - in which case the references bucket will be incorrect?

David