*/
ike_sa_t *ike_sa;
+ /**
+ * RNG to create message IDs
+ */
+ rng_t *rng;
+
/**
* Exchange we are currently handling as responder
*/
*/
linked_list_t *passive_tasks;
- /**
- * the task manager has been reset
- */
- bool reset;
-
/**
* Number of times we retransmit messages before giving up
*/
message_t *message;
host_t *me, *other;
status_t status;
- exchange_type_t exchange = 0;
+ exchange_type_t exchange = EXCHANGE_TYPE_UNDEFINED;
+
+ if (!this->rng)
+ {
+ DBG1(DBG_IKE, "no RNG supported");
+ return FAILED;
+ }
if (this->initiating.type != EXCHANGE_TYPE_UNDEFINED)
{
enumerator->destroy(enumerator);
}
- if (exchange == 0)
+ if (exchange == EXCHANGE_TYPE_UNDEFINED)
{
DBG2(DBG_IKE, "nothing to initiate");
/* nothing to do yet... */
message = message_create(IKEV1_MAJOR_VERSION, IKEV1_MINOR_VERSION);
if (exchange != ID_PROT)
{
- /* TODO-IKEv1: Set random message id */
+ this->rng->get_bytes(this->rng, sizeof(this->initiating.mid),
+ (void*)&this->initiating.mid);
+ message->set_message_id(message, this->initiating.mid);
}
message->set_source(message, me->clone(me));
message->set_destination(message, other->clone(other));
/* send response along the path the request came in */
message->set_source(message, me->clone(me));
message->set_destination(message, other->clone(other));
- message->set_message_id(message, this->responding.mid);
+ message->set_message_id(message, request->get_message_id(request));
message->set_request(message, FALSE);
enumerator = this->passive_tasks->create_enumerator(this->passive_tasks);
METHOD(task_manager_t, process_message, status_t,
private_task_manager_t *this, message_t *msg)
{
- if (this->active_tasks->get_count(this->active_tasks) == 0)
+ u_int32_t hash, mid;
+
+ mid = msg->get_message_id(msg);
+ hash = chunk_hash(msg->get_packet_data(msg));
+
+ if ((mid && mid == this->initiating.mid) ||
+ (this->initiating.mid == 0 &&
+ this->active_tasks->get_count(this->active_tasks)))
{
- /* TODO-IKEv1: detect mainmode retransmission */
- charon->bus->message(charon->bus, msg, TRUE);
- if (process_request(this, msg) != SUCCESS)
+ charon->bus->message(charon->bus, msg, FALSE);
+ if (process_response(this, msg) != SUCCESS)
{
flush(this);
return DESTROY_ME;
}
else
{
- charon->bus->message(charon->bus, msg, FALSE);
- if (process_response(this, msg) != SUCCESS)
+ if ((mid && mid == this->responding.mid) ||
+ hash == this->responding.mid)
+ {
+ DBG1(DBG_IKE, "received retransmit of request with ID %d, "
+ "retransmitting response", mid);
+ charon->sender->send(charon->sender,
+ this->responding.packet->clone(this->responding.packet));
+ return SUCCESS;
+ }
+
+ charon->bus->message(charon->bus, msg, TRUE);
+ if (process_request(this, msg) != SUCCESS)
{
flush(this);
return DESTROY_ME;
}
+
+ if (!mid)
+ {
+ mid = hash;
+ }
+ this->responding.mid = mid;
}
return SUCCESS;
}
METHOD(task_manager_t, incr_mid, void,
private_task_manager_t *this, bool initiate)
{
- if (initiate)
- {
- this->initiating.mid++;
- }
- else
- {
- this->responding.mid++;
- }
}
METHOD(task_manager_t, reset, void,
private_task_manager_t *this, u_int32_t initiate, u_int32_t respond)
{
-
}
METHOD(task_manager_t, create_task_enumerator, enumerator_t*,
DESTROY_IF(this->responding.packet);
DESTROY_IF(this->initiating.packet);
+ DESTROY_IF(this->rng);
free(this);
}
},
.ike_sa = ike_sa,
.initiating.type = EXCHANGE_TYPE_UNDEFINED,
+ .rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK),
.queued_tasks = linked_list_create(),
.active_tasks = linked_list_create(),
.passive_tasks = linked_list_create(),