delete-child-sa-job: Add new constructor that takes the unique ID of a CHILD_SA

This makes sure we delete the right SA in case the addresses got updated
in the mean time.
This commit is contained in:
Tobias Brunner
2017-05-23 18:46:49 +02:00
parent 0cbf75eb94
commit ba0796fe75
2 changed files with 69 additions and 13 deletions
@@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2017 Tobias Brunner
* Copyright (C) 2006 Martin Willi * Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil * HSR Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@@ -24,19 +25,19 @@ typedef struct private_delete_child_sa_job_t private_delete_child_sa_job_t;
* Private data of an delete_child_sa_job_t object. * Private data of an delete_child_sa_job_t object.
*/ */
struct private_delete_child_sa_job_t { struct private_delete_child_sa_job_t {
/**
/**
* Public delete_child_sa_job_t interface. * Public delete_child_sa_job_t interface.
*/ */
delete_child_sa_job_t public; delete_child_sa_job_t public;
/** /**
* protocol of the CHILD_SA (ESP/AH) * Protocol of the CHILD_SA (ESP/AH)
*/ */
protocol_id_t protocol; protocol_id_t protocol;
/** /**
* inbound SPI of the CHILD_SA * Inbound SPI of the CHILD_SA
*/ */
uint32_t spi; uint32_t spi;
@@ -49,12 +50,17 @@ struct private_delete_child_sa_job_t {
* Delete for an expired CHILD_SA * Delete for an expired CHILD_SA
*/ */
bool expired; bool expired;
/**
* Unique ID of the CHILD_SA
*/
uint32_t id;
}; };
METHOD(job_t, destroy, void, METHOD(job_t, destroy, void,
private_delete_child_sa_job_t *this) private_delete_child_sa_job_t *this)
{ {
this->dst->destroy(this->dst); DESTROY_IF(this->dst);
free(this); free(this);
} }
@@ -63,17 +69,37 @@ METHOD(job_t, execute, job_requeue_t,
{ {
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
ike_sa = charon->child_sa_manager->checkout(charon->child_sa_manager, if (this->id)
this->protocol, this->spi, this->dst, NULL);
if (ike_sa == NULL)
{ {
DBG1(DBG_JOB, "CHILD_SA %N/0x%08x/%H not found for delete", child_sa_t *child_sa;
protocol_id_names, this->protocol, htonl(this->spi), this->dst);
ike_sa = charon->child_sa_manager->checkout_by_id(
charon->child_sa_manager, this->id, &child_sa);
if (!ike_sa)
{
DBG1(DBG_JOB, "CHILD_SA {%d} not found for delete", this->id);
}
else
{
this->spi = child_sa->get_spi(child_sa, TRUE);
this->protocol = child_sa->get_protocol(child_sa);
}
} }
else else
{ {
ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi, this->expired); ike_sa = charon->child_sa_manager->checkout(charon->child_sa_manager,
this->protocol, this->spi, this->dst, NULL);
if (!ike_sa)
{
DBG1(DBG_JOB, "CHILD_SA %N/0x%08x/%H not found for delete",
protocol_id_names, this->protocol, htonl(this->spi), this->dst);
}
}
if (ike_sa)
{
ike_sa->delete_child_sa(ike_sa, this->protocol, this->spi,
this->expired);
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
} }
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
@@ -109,3 +135,24 @@ delete_child_sa_job_t *delete_child_sa_job_create(protocol_id_t protocol,
return &this->public; return &this->public;
} }
/*
* Described in header
*/
delete_child_sa_job_t *delete_child_sa_job_create_id(uint32_t id)
{
private_delete_child_sa_job_t *this;
INIT(this,
.public = {
.job_interface = {
.execute = _execute,
.get_priority = _get_priority,
.destroy = _destroy,
},
},
.id = id,
);
return &this->public;
}
@@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2017 Tobias Brunner
* Copyright (C) 2006 Martin Willi * Copyright (C) 2006 Martin Willi
* Hochschule fuer Technik Rapperswil * HSR Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@@ -42,7 +43,7 @@ struct delete_child_sa_job_t {
}; };
/** /**
* Creates a job of type DELETE_CHILD_SA. * Creates a job that deletes a CHILD_SA.
* *
* @param protocol protocol of the CHILD_SA * @param protocol protocol of the CHILD_SA
* @param spi security parameter index of the CHILD_SA * @param spi security parameter index of the CHILD_SA
@@ -53,4 +54,12 @@ struct delete_child_sa_job_t {
delete_child_sa_job_t *delete_child_sa_job_create(protocol_id_t protocol, delete_child_sa_job_t *delete_child_sa_job_create(protocol_id_t protocol,
uint32_t spi, host_t *dst, bool expired); uint32_t spi, host_t *dst, bool expired);
/**
* Creates a job that deletes a CHILD_SA identified by its unique ID.
*
* @param id unique ID of the CHILD_SA
* @return delete_child_sa_job_t object
*/
delete_child_sa_job_t *delete_child_sa_job_create_id(uint32_t id);
#endif /** DELETE_CHILD_SA_JOB_H_ @}*/ #endif /** DELETE_CHILD_SA_JOB_H_ @}*/