Only decrease refcnt once when flushing SPD entries, to

avoid flushing entries which are still used.

Approved by:	gnn(mentor)
Obtained from:	NETASQ
MFC after:	1 month
This commit is contained in:
VANHULLEBUS Yvan 2009-05-27 09:31:50 +00:00
parent 7c66482c29
commit cff5821a61
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=192880

View File

@ -4103,10 +4103,21 @@ key_flush_spd(time_t now)
if (sp->scangen == gen) /* previously handled */
continue;
sp->scangen = gen;
if (sp->state == IPSEC_SPSTATE_DEAD) {
/* NB: clean entries created by key_spdflush */
if (sp->state == IPSEC_SPSTATE_DEAD &&
sp->refcnt == 1) {
/*
* Ensure that we only decrease refcnt once,
* when we're the last consumer.
* Directly call SP_DELREF/key_delsp instead
* of KEY_FREESP to avoid unlocking/relocking
* SPTREE_LOCK before key_delsp: may refcnt
* be increased again during that time ?
* NB: also clean entries created by
* key_spdflush
*/
SP_DELREF(sp);
key_delsp(sp);
SPTREE_UNLOCK();
KEY_FREESP(&sp);
goto restart;
}
if (sp->lifetime == 0 && sp->validtime == 0)
@ -4116,7 +4127,6 @@ key_flush_spd(time_t now)
sp->state = IPSEC_SPSTATE_DEAD;
SPTREE_UNLOCK();
key_spdexpire(sp);
KEY_FREESP(&sp);
goto restart;
}
}