FreeBSD/sys/netipsec/key.c
/*
 * delete SA index and all SA registerd.
 */
delete SA index and all SA registerd.
delete SA index and all SA registerd .
static void
key_delsah(struct secashead *sah)
{
	struct secasvar *sav, *nextsav;
	u_int stateidx;
	int zombie = 0;
	IPSEC_ASSERT(sah != NULL, ("NULL sah"));
	SAHTREE_LOCK_ASSERT();
	for (stateidx = 0;
	     stateidx < _ARRAYLEN(saorder_state_any);
	     stateidx++) {
		u_int state = saorder_state_any[stateidx];
		LIST_FOREACH_SAFE(sav, &sah->savtree[state], chain, nextsav) {
			if (sav->refcnt == 0) {
				KEY_CHKSASTATE(state, sav->state, __func__);
				key_delsav(sav);
			} else {
				zombie++;
			}
		}
	}
	if (!zombie) {		
		if (__LIST_CHAINED(sah))
			LIST_REMOVE(sah, chain);
		free(sah, M_IPSEC_SAH);
	}
}
static void key_delsah ( struct secashead * sah ) { struct secasvar * sav , * nextsav ; u_int stateidx ; int zombie = 0 ; IPSEC_ASSERT ( sah != NULL , ( " " ) ) ; SAHTREE_LOCK_ASSERT ( ) ; for ( stateidx = 0 ; stateidx < _ARRAYLEN ( saorder_state_any ) ; stateidx ++ ) { u_int state = saorder_state_any [ stateidx ] ; LIST_FOREACH_SAFE ( sav , & sah -> savtree [ state ] , chain , nextsav ) { if ( sav -> refcnt == 0 ) { KEY_CHKSASTATE ( state , sav -> state , __func__ ) ; key_delsav ( sav ) ; } else { zombie ++ ; } } } if ( ! zombie ) { if ( __LIST_CHAINED ( sah ) ) LIST_REMOVE ( sah , chain ) ; free ( sah , M_IPSEC_SAH ) ; } }
delete SA index and all SA registerd.
delete SA index and all SA registerd .
/* searching all SA registerd in the secindex. */ /* sanity check */ /* 
				 * do NOT call KEY_FREESAV here:
				 * it will only delete the sav if refcnt == 1,
				 * where we already know that refcnt == 0
				 */ /* give up to delete this sa */ /* delete only if there are savs */ /* remove from tree of SA index */