Implemented responder retransmission, currently enabled for quick mode only
This commit is contained in:
@@ -1071,7 +1071,7 @@ METHOD(ike_sa_manager_t, checkout_by_message, ike_sa_t*,
|
|||||||
if (message->get_request(message) &&
|
if (message->get_request(message) &&
|
||||||
message->get_message_id(message) == entry->message_id)
|
message->get_message_id(message) == entry->message_id)
|
||||||
{
|
{
|
||||||
DBG1(DBG_MGR, "ignoring request with ID %d, already processing",
|
DBG1(DBG_MGR, "ignoring request with ID %u, already processing",
|
||||||
entry->message_id);
|
entry->message_id);
|
||||||
}
|
}
|
||||||
else if (wait_for_entry(this, entry, segment))
|
else if (wait_for_entry(this, entry, segment))
|
||||||
|
|||||||
@@ -42,6 +42,14 @@
|
|||||||
*/
|
*/
|
||||||
#define MAX_OLD_HASHES 2
|
#define MAX_OLD_HASHES 2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First sequence number of responding packets.
|
||||||
|
*
|
||||||
|
* To distinguish retransmission jobs for initiating and responding packets,
|
||||||
|
* we split up the sequence counter and use the upper half for responding.
|
||||||
|
*/
|
||||||
|
#define RESPONDING_SEQ INT_MAX
|
||||||
|
|
||||||
typedef struct exchange_t exchange_t;
|
typedef struct exchange_t exchange_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,6 +94,11 @@ struct private_task_manager_t {
|
|||||||
* Exchange we are currently handling as responder
|
* Exchange we are currently handling as responder
|
||||||
*/
|
*/
|
||||||
struct {
|
struct {
|
||||||
|
/**
|
||||||
|
* Message ID of the last response
|
||||||
|
*/
|
||||||
|
u_int32_t mid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash of a previously received message
|
* Hash of a previously received message
|
||||||
*/
|
*/
|
||||||
@@ -96,6 +109,16 @@ struct private_task_manager_t {
|
|||||||
*/
|
*/
|
||||||
packet_t *packet;
|
packet_t *packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sequence number of the last sent message
|
||||||
|
*/
|
||||||
|
u_int32_t seqnr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* how many times we have retransmitted so far
|
||||||
|
*/
|
||||||
|
u_int retransmitted;
|
||||||
|
|
||||||
} responding;
|
} responding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,46 +251,63 @@ static bool activate_task(private_task_manager_t *this, task_type_t type)
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(task_manager_t, retransmit, status_t,
|
/**
|
||||||
private_task_manager_t *this, u_int32_t message_seqnr)
|
* Retransmit a packet, either as initiator or as responder
|
||||||
|
*/
|
||||||
|
static status_t retransmit_packet(private_task_manager_t *this, u_int32_t seqnr,
|
||||||
|
u_int mid, u_int retransmitted, packet_t *packet)
|
||||||
{
|
{
|
||||||
/* this.initiating packet used as marker for received response */
|
u_int32_t t;
|
||||||
if (message_seqnr == this->initiating.seqnr && this->initiating.packet )
|
|
||||||
|
if (retransmitted > this->retransmit_tries)
|
||||||
{
|
{
|
||||||
u_int32_t timeout;
|
DBG1(DBG_IKE, "giving up after %u retransmits", retransmitted - 1);
|
||||||
packet_t *packet;
|
if (this->ike_sa->get_state(this->ike_sa) != IKE_CONNECTING)
|
||||||
job_t *job;
|
|
||||||
|
|
||||||
if (this->initiating.retransmitted <= this->retransmit_tries)
|
|
||||||
{
|
{
|
||||||
timeout = (u_int32_t)(this->retransmit_timeout * 1000.0 *
|
charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
|
||||||
pow(this->retransmit_base, this->initiating.retransmitted));
|
|
||||||
}
|
}
|
||||||
else
|
return DESTROY_ME;
|
||||||
{
|
|
||||||
DBG1(DBG_IKE, "giving up after %d retransmits",
|
|
||||||
this->initiating.retransmitted - 1);
|
|
||||||
if (this->ike_sa->get_state(this->ike_sa) != IKE_CONNECTING)
|
|
||||||
{
|
|
||||||
charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
|
|
||||||
}
|
|
||||||
return DESTROY_ME;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->initiating.retransmitted)
|
|
||||||
{
|
|
||||||
DBG1(DBG_IKE, "retransmit %d of request with message ID %u seqnr (%d)",
|
|
||||||
this->initiating.retransmitted, this->initiating.mid, message_seqnr);
|
|
||||||
}
|
|
||||||
packet = this->initiating.packet->clone(this->initiating.packet);
|
|
||||||
charon->sender->send(charon->sender, packet);
|
|
||||||
|
|
||||||
this->initiating.retransmitted++;
|
|
||||||
job = (job_t*)retransmit_job_create(this->initiating.seqnr,
|
|
||||||
this->ike_sa->get_id(this->ike_sa));
|
|
||||||
lib->scheduler->schedule_job_ms(lib->scheduler, job, timeout);
|
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
t = (u_int32_t)(this->retransmit_timeout * 1000.0 *
|
||||||
|
pow(this->retransmit_base, retransmitted));
|
||||||
|
if (retransmitted)
|
||||||
|
{
|
||||||
|
DBG1(DBG_IKE, "sending retransmit %u of %s message ID %u, seq %u",
|
||||||
|
retransmitted, seqnr < RESPONDING_SEQ ? "request" : "response",
|
||||||
|
mid, seqnr < RESPONDING_SEQ ? seqnr : seqnr - RESPONDING_SEQ);
|
||||||
|
}
|
||||||
|
charon->sender->send(charon->sender, packet->clone(packet));
|
||||||
|
lib->scheduler->schedule_job_ms(lib->scheduler, (job_t*)
|
||||||
|
retransmit_job_create(seqnr, this->ike_sa->get_id(this->ike_sa)), t);
|
||||||
|
return NEED_MORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(task_manager_t, retransmit, status_t,
|
||||||
|
private_task_manager_t *this, u_int32_t seqnr)
|
||||||
|
{
|
||||||
|
status_t status = SUCCESS;
|
||||||
|
|
||||||
|
if (seqnr == this->initiating.seqnr && this->initiating.packet)
|
||||||
|
{
|
||||||
|
status = retransmit_packet(this, seqnr, this->initiating.mid,
|
||||||
|
this->initiating.retransmitted, this->initiating.packet);
|
||||||
|
if (status == NEED_MORE)
|
||||||
|
{
|
||||||
|
this->initiating.retransmitted++;
|
||||||
|
status = SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (seqnr == this->responding.seqnr && this->responding.packet)
|
||||||
|
{
|
||||||
|
status = retransmit_packet(this, seqnr, this->responding.mid,
|
||||||
|
this->responding.retransmitted, this->responding.packet);
|
||||||
|
if (status == NEED_MORE)
|
||||||
|
{
|
||||||
|
this->responding.retransmitted++;
|
||||||
|
status = SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(task_manager_t, initiate, status_t,
|
METHOD(task_manager_t, initiate, status_t,
|
||||||
@@ -461,8 +501,8 @@ METHOD(task_manager_t, initiate, status_t,
|
|||||||
message->destroy(message);
|
message->destroy(message);
|
||||||
return initiate(this);
|
return initiate(this);
|
||||||
}
|
}
|
||||||
this->initiating.seqnr++;
|
|
||||||
|
|
||||||
|
DESTROY_IF(this->initiating.packet);
|
||||||
status = this->ike_sa->generate_message(this->ike_sa, message,
|
status = this->ike_sa->generate_message(this->ike_sa, message,
|
||||||
&this->initiating.packet);
|
&this->initiating.packet);
|
||||||
if (status != SUCCESS)
|
if (status != SUCCESS)
|
||||||
@@ -474,16 +514,25 @@ METHOD(task_manager_t, initiate, status_t,
|
|||||||
charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
|
charon->bus->ike_updown(charon->bus, this->ike_sa, FALSE);
|
||||||
return DESTROY_ME;
|
return DESTROY_ME;
|
||||||
}
|
}
|
||||||
message->destroy(message);
|
|
||||||
|
|
||||||
|
this->initiating.seqnr++;
|
||||||
if (expect_response)
|
if (expect_response)
|
||||||
{
|
{
|
||||||
|
message->destroy(message);
|
||||||
return retransmit(this, this->initiating.seqnr);
|
return retransmit(this, this->initiating.seqnr);
|
||||||
}
|
}
|
||||||
charon->sender->send(charon->sender,
|
if (message->get_exchange_type(message) == QUICK_MODE)
|
||||||
this->initiating.packet->clone(this->initiating.packet));
|
{ /* keep the packet for retransmission in quick mode. The responder
|
||||||
this->initiating.packet->destroy(this->initiating.packet);
|
* might request a retransmission */
|
||||||
this->initiating.packet = NULL;
|
charon->sender->send(charon->sender,
|
||||||
|
this->initiating.packet->clone(this->initiating.packet));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
charon->sender->send(charon->sender, this->initiating.packet);
|
||||||
|
this->initiating.packet = NULL;
|
||||||
|
}
|
||||||
|
message->destroy(message);
|
||||||
|
|
||||||
if (exchange == INFORMATIONAL_V1)
|
if (exchange == INFORMATIONAL_V1)
|
||||||
{
|
{
|
||||||
@@ -502,14 +551,6 @@ METHOD(task_manager_t, initiate, status_t,
|
|||||||
return initiate(this);
|
return initiate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* handle exchange collisions
|
|
||||||
*/
|
|
||||||
static bool handle_collisions(private_task_manager_t *this, task_t *task)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build a response depending on the "passive" task list
|
* build a response depending on the "passive" task list
|
||||||
*/
|
*/
|
||||||
@@ -519,7 +560,7 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
|
|||||||
task_t *task;
|
task_t *task;
|
||||||
message_t *message;
|
message_t *message;
|
||||||
host_t *me, *other;
|
host_t *me, *other;
|
||||||
bool delete = FALSE, flushed = FALSE;
|
bool delete = FALSE, flushed = FALSE, expect_request = FALSE;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
me = request->get_destination(request);
|
me = request->get_destination(request);
|
||||||
@@ -533,6 +574,10 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
|
|||||||
message->set_message_id(message, request->get_message_id(request));
|
message->set_message_id(message, request->get_message_id(request));
|
||||||
message->set_request(message, FALSE);
|
message->set_request(message, FALSE);
|
||||||
|
|
||||||
|
this->responding.mid = request->get_message_id(request);
|
||||||
|
this->responding.retransmitted = 0;
|
||||||
|
this->responding.seqnr++;
|
||||||
|
|
||||||
enumerator = this->passive_tasks->create_enumerator(this->passive_tasks);
|
enumerator = this->passive_tasks->create_enumerator(this->passive_tasks);
|
||||||
while (enumerator->enumerate(enumerator, (void*)&task))
|
while (enumerator->enumerate(enumerator, (void*)&task))
|
||||||
{
|
{
|
||||||
@@ -541,17 +586,14 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
|
|||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
/* task completed, remove it */
|
/* task completed, remove it */
|
||||||
this->passive_tasks->remove_at(this->passive_tasks, enumerator);
|
this->passive_tasks->remove_at(this->passive_tasks, enumerator);
|
||||||
if (!handle_collisions(this, task))
|
task->destroy(task);
|
||||||
{
|
|
||||||
task->destroy(task);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
case NEED_MORE:
|
case NEED_MORE:
|
||||||
/* processed, but task needs another exchange */
|
/* processed, but task needs another exchange */
|
||||||
if (handle_collisions(this, task))
|
if (task->get_type(task) == TASK_QUICK_MODE)
|
||||||
{
|
{ /* we rely on initiator retransmission, except for
|
||||||
this->passive_tasks->remove_at(this->passive_tasks,
|
* three-message exchanges */
|
||||||
enumerator);
|
expect_request = TRUE;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
case ALREADY_DONE:
|
case ALREADY_DONE:
|
||||||
@@ -587,8 +629,12 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
|
|||||||
return DESTROY_ME;
|
return DESTROY_ME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expect_request && !delete)
|
||||||
|
{
|
||||||
|
return retransmit(this, this->responding.seqnr);
|
||||||
|
}
|
||||||
charon->sender->send(charon->sender,
|
charon->sender->send(charon->sender,
|
||||||
this->responding.packet->clone(this->responding.packet));
|
this->responding.packet->clone(this->responding.packet));
|
||||||
if (delete)
|
if (delete)
|
||||||
{
|
{
|
||||||
return DESTROY_ME;
|
return DESTROY_ME;
|
||||||
@@ -895,6 +941,16 @@ METHOD(task_manager_t, process_message, status_t,
|
|||||||
{
|
{
|
||||||
if (this->initiating.old_hashes[i] == hash)
|
if (this->initiating.old_hashes[i] == hash)
|
||||||
{
|
{
|
||||||
|
if (this->initiating.packet &&
|
||||||
|
i == (this->initiating.old_hash_pos % MAX_OLD_HASHES) &&
|
||||||
|
msg->get_exchange_type(msg) == QUICK_MODE)
|
||||||
|
{
|
||||||
|
DBG1(DBG_IKE, "received retransmit of response with ID %u, "
|
||||||
|
"resending last request", mid);
|
||||||
|
charon->sender->send(charon->sender,
|
||||||
|
this->initiating.packet->clone(this->initiating.packet));
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
DBG1(DBG_IKE, "received retransmit of response with ID %u, "
|
DBG1(DBG_IKE, "received retransmit of response with ID %u, "
|
||||||
"but next request already sent", mid);
|
"but next request already sent", mid);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
@@ -921,7 +977,7 @@ METHOD(task_manager_t, process_message, status_t,
|
|||||||
flush(this);
|
flush(this);
|
||||||
return DESTROY_ME;
|
return DESTROY_ME;
|
||||||
}
|
}
|
||||||
this->initiating.old_hashes[(this->initiating.old_hash_pos++) %
|
this->initiating.old_hashes[(++this->initiating.old_hash_pos) %
|
||||||
MAX_OLD_HASHES] = hash;
|
MAX_OLD_HASHES] = hash;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -975,6 +1031,7 @@ METHOD(task_manager_t, process_message, status_t,
|
|||||||
ike_sa_id_t *ike_sa_id;
|
ike_sa_id_t *ike_sa_id;
|
||||||
ike_cfg_t *ike_cfg;
|
ike_cfg_t *ike_cfg;
|
||||||
job_t *job;
|
job_t *job;
|
||||||
|
|
||||||
ike_cfg = charon->backends->get_ike_cfg(charon->backends, me, other);
|
ike_cfg = charon->backends->get_ike_cfg(charon->backends, me, other);
|
||||||
if (ike_cfg == NULL)
|
if (ike_cfg == NULL)
|
||||||
{
|
{
|
||||||
@@ -1160,6 +1217,8 @@ METHOD(task_manager_t, reset, void,
|
|||||||
DESTROY_IF(this->responding.packet);
|
DESTROY_IF(this->responding.packet);
|
||||||
DESTROY_IF(this->initiating.packet);
|
DESTROY_IF(this->initiating.packet);
|
||||||
this->responding.packet = NULL;
|
this->responding.packet = NULL;
|
||||||
|
this->responding.seqnr = RESPONDING_SEQ;
|
||||||
|
this->responding.retransmitted = 0;
|
||||||
this->initiating.packet = NULL;
|
this->initiating.packet = NULL;
|
||||||
this->initiating.mid = 0;
|
this->initiating.mid = 0;
|
||||||
this->initiating.seqnr = 0;
|
this->initiating.seqnr = 0;
|
||||||
@@ -1248,6 +1307,7 @@ task_manager_v1_t *task_manager_v1_create(ike_sa_t *ike_sa)
|
|||||||
},
|
},
|
||||||
.ike_sa = ike_sa,
|
.ike_sa = ike_sa,
|
||||||
.initiating.type = EXCHANGE_TYPE_UNDEFINED,
|
.initiating.type = EXCHANGE_TYPE_UNDEFINED,
|
||||||
|
.responding.seqnr = RESPONDING_SEQ,
|
||||||
.rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK),
|
.rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK),
|
||||||
.queued_tasks = linked_list_create(),
|
.queued_tasks = linked_list_create(),
|
||||||
.active_tasks = linked_list_create(),
|
.active_tasks = linked_list_create(),
|
||||||
|
|||||||
Reference in New Issue
Block a user