ipsec-sa-mgr: Delete pre-allocated SPI if creating CHILD_SA fails

Fixes: 914479370e ("Added IPsec SA manager")
This commit is contained in:
Tobias Brunner
2026-07-23 10:26:08 +02:00
parent 87f0bc2a6c
commit 2cea90423a
+11
View File
@@ -618,6 +618,7 @@ METHOD(ipsec_sa_mgr_t, del_sa, status_t,
{ {
ipsec_sa_entry_t *current, *found = NULL; ipsec_sa_entry_t *current, *found = NULL;
enumerator_t *enumerator; enumerator_t *enumerator;
uint32_t *spi_alloc = NULL;
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
enumerator = this->sas->create_enumerator(this->sas); enumerator = this->sas->create_enumerator(this->sas);
@@ -634,6 +635,10 @@ METHOD(ipsec_sa_mgr_t, del_sa, status_t,
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
if (!found)
{
spi_alloc = this->allocated_spis->remove(this->allocated_spis, &spi);
}
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
if (found) if (found)
@@ -643,6 +648,12 @@ METHOD(ipsec_sa_mgr_t, del_sa, status_t,
destroy_entry(found); destroy_entry(found);
return SUCCESS; return SUCCESS;
} }
else if (spi_alloc)
{
DBG2(DBG_ESP, "deleted pre-allocated SPI %.8x", ntohl(spi));
free(spi_alloc);
return SUCCESS;
}
return FAILED; return FAILED;
} }