- added new job type retransmit_request_job_t

- fixed memory leaks
This commit is contained in:
Jan Hutter
2005-12-02 13:20:20 +00:00
parent f2d4a4475a
commit 5534ee8476
13 changed files with 439 additions and 138 deletions
+77 -31
View File
@@ -407,24 +407,37 @@ static void compute_secrets(private_ike_sa_t *this,chunk_t dh_shared_secret,chun
}
/**
* Implements protected_ike_sa_t.resend_last_reply.
* Implementation of private_ike_sa_t.resend_last_reply.
*/
static status_t resend_last_reply(private_ike_sa_t *this)
{
packet_t *packet;
status_t status;
status = this->last_responded_message->generate(this->last_responded_message, NULL, NULL, &packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not generate message to resent");
return status;
}
packet = this->last_responded_message->get_packet(this->last_responded_message);
charon->send_queue->add(charon->send_queue, packet);
return SUCCESS;
}
/**
* Implementation of ike_sa_t.retransmit_request.
*/
status_t retransmit_request (private_ike_sa_t *this, u_int32_t message_id)
{
packet_t *packet;
if ((this->message_id_out -1) != message_id)
{
return NOT_FOUND;
}
packet = this->last_responded_message->get_packet(this->last_responded_message);
charon->send_queue->add(charon->send_queue, packet);
return SUCCESS;
}
/**
* Implements protected_ike_sa_t.resend_last_reply.
*/
@@ -615,6 +628,9 @@ static signer_t *get_signer_initiator (private_ike_sa_t *this)
}
/**
<<<<<<< .mine
* Implementation of protected_ike_sa_t.send_request.
=======
* Implementation of protected_ike_sa_t.get_crypter_responder.
*/
static crypter_t *get_crypter_responder(private_ike_sa_t *this)
@@ -633,50 +649,82 @@ static signer_t *get_signer_responder (private_ike_sa_t *this)
/**
* Implementation of protected_ike_sa_t.set_last_requested_message.
>>>>>>> .r660
*/
static status_t set_last_requested_message (private_ike_sa_t *this,message_t * message)
static status_t send_request (private_ike_sa_t *this,message_t * message)
{
packet_t *packet;
status_t status;
if (message->get_message_id(message) != this->message_id_out)
{
this->logger->log(this->logger, ERROR, "Message could not be sent cause id was not as expected");
return FAILED;
}
/* generate packet */
this->logger->log(this->logger, CONTROL|MOST, "Generate packet from message");
status = message->generate(message, this->crypter_initiator,this->signer_initiator, &packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not generate packet from message");
return FAILED;
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
charon->send_queue->add(charon->send_queue, packet);
if (this->last_requested_message != NULL)
{
/* destroy message */
this->last_requested_message->destroy(this->last_requested_message);
}
}
if (message->get_message_id(message) != this->message_id_out)
{
this->logger->log(this->logger, CONTROL|MOST, "last requested message could not be set cause id was not as expected");
return FAILED;
}
this->logger->log(this->logger, CONTROL|MOST, "replace last requested message with new one");
this->last_requested_message = message;
/* message counter can now be increased */
this->logger->log(this->logger, CONTROL|MOST, "Increate message counter for outgoing messages");
this->logger->log(this->logger, CONTROL|MOST, "Increase message counter for outgoing messages");
this->message_id_out++;
return SUCCESS;
}
/**
* Implementation of protected_ike_sa_t.set_last_responded_message.
* Implementation of protected_ike_sa_t.send_response.
*/
static status_t set_last_responded_message (private_ike_sa_t *this,message_t * message)
static status_t send_response (private_ike_sa_t *this,message_t * message)
{
packet_t *packet;
status_t status;
if (message->get_message_id(message) != this->message_id_in)
{
this->logger->log(this->logger, CONTROL|MOST, "Message could not be sent cause id was not as expected");
return FAILED;
}
status = message->generate(message, this->crypter_initiator,this->signer_initiator, &packet);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not generate packet from message");
return FAILED;
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
charon->send_queue->add(charon->send_queue, packet);
if (this->last_responded_message != NULL)
{
/* destroy message */
this->last_responded_message->destroy(this->last_responded_message);
}
if (message->get_message_id(message) != this->message_id_in)
{
this->logger->log(this->logger, CONTROL|MOST, "last responded message could not be set cause id was not as expected");
return FAILED;
}
this->logger->log(this->logger, CONTROL|MOST, "replace last responded message with new one");
this->last_responded_message = message;
/* message counter can now be increased */
this->logger->log(this->logger, CONTROL|MOST, "Increate message counter for incoming messages");
this->logger->log(this->logger, CONTROL|MOST, "Increase message counter for incoming messages");
this->message_id_in++;
return SUCCESS;
@@ -811,6 +859,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
this->protected.public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
this->protected.public.initialize_connection = (status_t(*)(ike_sa_t*, char*)) initialize_connection;
this->protected.public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
this->protected.public.retransmit_request = (status_t (*) (ike_sa_t *, u_int32_t)) retransmit_request;
this->protected.public.destroy = (void(*)(ike_sa_t*))destroy;
/* protected functions */
@@ -826,8 +875,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
this->protected.set_my_host = (void(*) (protected_ike_sa_t *,host_t *)) set_my_host;
this->protected.set_other_host = (void(*) (protected_ike_sa_t *, host_t *)) set_other_host;
this->protected.get_randomizer = (randomizer_t *(*) (protected_ike_sa_t *)) get_randomizer;
this->protected.set_last_requested_message = (status_t (*) (protected_ike_sa_t *,message_t *)) set_last_requested_message;
this->protected.set_last_responded_message = (status_t (*) (protected_ike_sa_t *,message_t *)) set_last_responded_message;
this->protected.send_request = (status_t (*) (protected_ike_sa_t *,message_t *)) send_request;
this->protected.send_response = (status_t (*) (protected_ike_sa_t *,message_t *)) send_response;
this->protected.create_transforms_from_proposal = (status_t (*) (protected_ike_sa_t *,ike_proposal_t *)) create_transforms_from_proposal;
this->protected.set_new_state = (void (*) (protected_ike_sa_t *,state_t *)) set_new_state;
this->protected.get_crypter_initiator = (crypter_t *(*) (protected_ike_sa_t *)) get_crypter_initiator;
@@ -840,9 +889,6 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
this->resend_last_reply = resend_last_reply;
this->create_delete_job = create_delete_job;
/* initialize private fields */
this->logger = charon->logger_manager->create_logger(charon->logger_manager, IKE_SA, NULL);
+21 -8
View File
@@ -71,6 +71,17 @@ struct ike_sa_t {
* @return TODO
*/
status_t (*initialize_connection) (ike_sa_t *this, char *name);
/**
* @brief Retransmits a request.
*
* @param this calling object
* @param message_id ID of the request to retransmit
* @return
* - SUCCESS
* - NOT_FOUND if request doesn't have to be retransmited
*/
status_t (*retransmit_request) (ike_sa_t *this, u_int32_t message_id);
/**
* @brief Get the id of the SA.
@@ -223,30 +234,32 @@ struct protected_ike_sa_t {
status_t (*create_transforms_from_proposal) (protected_ike_sa_t *this,ike_proposal_t * proposal);
/**
* Sets the last requested message.
* Sends the next request message.
*
* Allready set last requested message gets destroyed. object gets not cloned!
* Also the first retransmit job is created.
*
* Stored requested message gets destroyed. object gets not cloned!
*
* @param this calling object
* @param message pointer to the new last requested message
* @param message pointer to the message which should be sent
* @return
* - SUCCESS
* - FAILED if message id is not next expected one
*/
status_t (*set_last_requested_message) (protected_ike_sa_t *this,message_t * message);
status_t (*send_request) (protected_ike_sa_t *this,message_t * message);
/**
* Sets the last responded message.
* Sends the next response message.
*
* Allready set last requested message gets destroyed. object gets not cloned!
* Stored responded message gets destroyed. object gets not cloned!
*
* @param this calling object
* @param message pointer to the new last responded message
* @param message pointer to the message which should be sent
* return
* - SUCCESS
* - FAILED if message id is not next expected one
*/
status_t (*set_last_responded_message) (protected_ike_sa_t *this,message_t * message);
status_t (*send_response) (protected_ike_sa_t *this,message_t * message);
/**
* Gets the internal stored randomizer_t object.
@@ -162,7 +162,6 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
ike_sa_id_t *ike_sa_id;
iterator_t *payloads;
message_t *request;
packet_t *packet;
status_t status;
/*
@@ -384,34 +383,18 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
/* build the complete IKE_AUTH request */
this->build_ike_auth_request (this,&request);
/* generate packet */
this->logger->log(this->logger, CONTROL|MOST, "Generate packet from message");
status = request->generate(request, this->ike_sa->get_crypter_initiator(this->ike_sa), this->ike_sa->get_signer_initiator(this->ike_sa), &packet);
/* message can now be sent (must not be destroyed) */
status = this->ike_sa->send_request(this->ike_sa, request);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not generate packet from message");
this->logger->log(this->logger, ERROR, "Could not send request message");
request->destroy(request);
return DELETE_ME;
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
charon->send_queue->add(charon->send_queue, packet);
/* state can now be changed */
this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
next_state = ike_auth_requested_create(this->ike_sa,this->sent_nonce,this->received_nonce);
/* last messages can now be set */
status = this->ike_sa->set_last_requested_message(this->ike_sa, request);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not set last requested message");
(next_state->state_interface).destroy(&(next_state->state_interface));
request->destroy(request);
return DELETE_ME;
}
/* state can now be changed */
this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
@@ -579,7 +562,7 @@ static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie hellman object");
this->diffie_hellman->destroy(this->diffie_hellman);
this->logger->log(this->logger, CONTROL | MOST, "Destroy shared secret (secrets allready derived)");
allocator_free(this->shared_secret.ptr);
allocator_free_chunk(&(this->shared_secret));
this->logger->log(this->logger, CONTROL | MOST, "Destroy object itself");
allocator_free(this);
}
@@ -598,7 +581,7 @@ static void destroy(private_ike_sa_init_requested_t *this)
this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
allocator_free(this->received_nonce.ptr);
this->logger->log(this->logger, CONTROL | MOST, "Destroy shared secret (secrets allready derived)");
allocator_free(this->shared_secret.ptr);
allocator_free_chunk(&(this->shared_secret));
this->logger->log(this->logger, CONTROL | MOST, "Destroy object itself");
allocator_free(this);
}
@@ -83,7 +83,6 @@ static status_t process_message(private_ike_sa_init_responded_t *this, message_t
sa_payload_t *sa_request;
ts_payload_t *tsi_request, *tsr_request;
message_t *response;
packet_t *response_packet;
exchange_type = request->get_exchange_type(request);
if (exchange_type != IKE_AUTH)
@@ -210,25 +209,18 @@ static status_t process_message(private_ike_sa_init_responded_t *this, message_t
this->logger->log(this->logger, ERROR, "Building tsr payload failed");
response->destroy(response);
return status;
}
/* generate response, get transfroms first */
signer = this->ike_sa->get_signer_responder(this->ike_sa);
crypter = this->ike_sa->get_crypter_responder(this->ike_sa);
status = response->generate(response, crypter, signer, &response_packet);
}
this->logger->log(this->logger, CONTROL | MORE, "IKE_AUTH request successfully handled. Sending reply.");
status = this->ike_sa->send_response(this->ike_sa, response);
/* message can now be sent (must not be destroyed) */
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Error in message generation");
this->logger->log(this->logger, ERROR, "Could not send response message");
response->destroy(response);
return status;
return DELETE_ME;
}
/* send it out */
this->logger->log(this->logger, CONTROL | MORE, "IKE_AUTH request successfully handled. Sending reply.");
charon->send_queue->add(charon->send_queue, response_packet);
/* store for timeout reply */
this->ike_sa->set_last_responded_message(this->ike_sa, response);
/* create new state */
this->ike_sa->set_new_state(this->ike_sa, (state_t*)ike_sa_established_create(this->ike_sa));
+8 -21
View File
@@ -27,6 +27,7 @@
#include <sa/states/state.h>
#include <sa/states/ike_sa_init_requested.h>
#include <utils/allocator.h>
#include <queues/jobs/retransmit_request_job.h>
#include <transforms/diffie_hellman.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/ke_payload.h>
@@ -179,7 +180,6 @@ status_t retry_initiate_connection (private_initiator_init_t *this, int dh_group
init_config_t *init_config;
randomizer_t *randomizer;
message_t *message;
packet_t *packet;
status_t status;
ike_sa_id_t *ike_sa_id;
@@ -201,49 +201,36 @@ status_t retry_initiate_connection (private_initiator_init_t *this, int dh_group
this->logger->log(this->logger, CONTROL|MOST, "Get pseudo random bytes for nonce");
randomizer = this->ike_sa->get_randomizer(this->ike_sa);
allocator_free_chunk(&(this->sent_nonce));
randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce));
this->logger->log(this->logger, RAW|MOST, "Nonce",&(this->sent_nonce));
this->build_ike_sa_init_request (this,&message);
/* generate packet */
this->logger->log(this->logger, CONTROL|MOST, "generate packet from message");
status = message->generate(message, NULL, NULL, &packet);
/* message can now be sent (must not be destroyed) */
status = this->ike_sa->send_request(this->ike_sa, message);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "could not generate packet from message");
this->logger->log(this->logger, ERROR, "Could not send request message");
message->destroy(message);
return DELETE_ME;
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
charon->send_queue->add(charon->send_queue, packet);
/* state can now be changed */
this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
next_state = ike_sa_init_requested_create(this->ike_sa, this->dh_group_priority, this->diffie_hellman, this->sent_nonce);
/* last message can now be set */
status = this->ike_sa->set_last_requested_message(this->ike_sa, message);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not set last requested message");
(next_state->state_interface).destroy(&(next_state->state_interface));
message->destroy(message);
return DELETE_ME;
}
/* state can now be changed */
this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
/* state has NOW changed :-) */
this->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s", mapping_find(ike_sa_state_m,INITIATOR_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED) );
this->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
this->destroy_after_state_change(this);
return SUCCESS;
}
+17 -22
View File
@@ -163,7 +163,6 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
iterator_t *payloads;
message_t *response;
host_t *other_host;
packet_t *packet;
host_t *my_host;
status_t status;
@@ -344,36 +343,27 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->received_nonce, this->sent_nonce);
/* not used anymore */
allocator_free_chunk(&shared_secret);
this->build_ike_sa_init_reply(this,&response);
/* generate packet */
this->logger->log(this->logger, CONTROL|MOST, "generate packet from message");
status = response->generate(response, NULL, NULL, &packet);
/* message can now be sent (must not be destroyed) */
status = this->ike_sa->send_response(this->ike_sa, response);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "could not generate packet from message");
this->logger->log(this->logger, ERROR, "Could not send response message");
response->destroy(response);
return DELETE_ME;
}
this->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
charon->send_queue->add(charon->send_queue, packet);
/* state can now be changed */
this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
next_state = ike_sa_init_responded_create(this->ike_sa);
/* last message can now be set */
status = this->ike_sa->set_last_responded_message(this->ike_sa, response);
if (status != SUCCESS)
{
this->logger->log(this->logger, ERROR, "Could not set last responded message");
response->destroy(response);
(next_state->state_interface).destroy(&(next_state->state_interface));
return DELETE_ME;
}
/* state can now be changed */
this->ike_sa->set_new_state(this->ike_sa, (state_t *) next_state);
/* state has NOW changed :-) */
@@ -517,9 +507,9 @@ static void destroy(private_responder_init_t *this)
this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder init state object");
this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
allocator_free(this->sent_nonce.ptr);
allocator_free_chunk(&(this->sent_nonce));
this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
allocator_free(this->received_nonce.ptr);
allocator_free_chunk(&(this->received_nonce));
if (this->diffie_hellman != NULL)
{
@@ -543,6 +533,11 @@ static void destroy_after_state_change (private_responder_init_t *this)
this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
this->diffie_hellman->destroy(this->diffie_hellman);
}
this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
allocator_free_chunk(&(this->sent_nonce));
this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
allocator_free_chunk(&(this->received_nonce));
this->logger->log(this->logger, CONTROL | MOST, "Destroy object");
allocator_free(this);