Skip to contentSkip to conversation

: Fix xfrm_state accounting

XFRM Applied Patrick McHardy 2 participants 2 messages Oct 24, 2006

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

[XFRM]: Fix xfrm_state accounting

xfrm_state_num needs to be increased for XFRM_STATE_ACQ states created by xfrm_state_find() to prevent the counter from going negative when the state is destroyed.

---
commit d514f03d17b5f7615a549fbe2eb7b57a15aff609
tree 08a95a113236a858dafd3e57afcb959232164cac
parent 5c8ca15198f39a6d346f7573405dcff5c365805e
author Patrick McHardy <[email protected]> Wed, 25 Oct 2006 00:00:03 +0200 committer Patrick McHardy <[email protected]> Wed, 25 Oct 2006 00:00:03 +0200

 net/xfrm/xfrm_state.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
net/xfrm/xfrm_state.c +10 -8
index 84bbf84..899de9e 100644
@@ -505,6 +505,14 @@ __xfrm_state_locate(struct xfrm_state *x
 						  x->id.proto, family);
 }
 
+static void xfrm_hash_grow_check(int have_hash_collision)
+{
+	if (have_hash_collision &&
+	    (xfrm_state_hmask + 1) < xfrm_state_hashmax &&
+	    xfrm_state_num > xfrm_state_hmask)
+		schedule_work(&xfrm_hash_work);
+}
+
 struct xfrm_state *
 xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, 
 		struct flowi *fl, struct xfrm_tmpl *tmpl,
@@ -598,6 +606,8 @@ xfrm_state_find(xfrm_address_t *daddr, x
 			x->lft.hard_add_expires_seconds = XFRM_ACQ_EXPIRES;
 			x->timer.expires = jiffies + XFRM_ACQ_EXPIRES*HZ;
 			add_timer(&x->timer);
+			xfrm_state_num++;
+			xfrm_hash_grow_check(x->bydst.next != NULL);
 		} else {
 			x->km.state = XFRM_STATE_DEAD;
 			xfrm_state_put(x);
@@ -614,14 +624,6 @@ out:
 	return x;
 }
 
-static void xfrm_hash_grow_check(int have_hash_collision)
-{
-	if (have_hash_collision &&
-	    (xfrm_state_hmask + 1) < xfrm_state_hashmax &&
-	    xfrm_state_num > xfrm_state_hmask)
-		schedule_work(&xfrm_hash_work);
-}
-
 static void __xfrm_state_insert(struct xfrm_state *x)
 {
 	unsigned int h;
maintainer Applied
#1 lore raw

From: Patrick McHardy <[email protected]>
Date: Wed, 25 Oct 2006 00:00:58 +0200

Quoted 7 lines

[XFRM]: Fix xfrm_state accounting

xfrm_state_num needs to be increased for XFRM_STATE_ACQ states created by xfrm_state_find() to prevent the counter from going negative when the state is destroyed.

Good catch, we've had a few of these lately :-)

Applied, thanks Patrick.