- added build_message to ike_sa
authorMartin Willi <martin@strongswan.org>
Fri, 18 Nov 2005 12:01:53 +0000 (12:01 -0000)
committerMartin Willi <martin@strongswan.org>
Fri, 18 Nov 2005 12:01:53 +0000 (12:01 -0000)
- removed is_initiator in message, flag is stored in ike_sa_id

Source/charon/ike_sa.c
Source/charon/message.c

index 9a13381..c4751d1 100644 (file)
@@ -103,6 +103,8 @@ struct private_ike_sa_s {
        status_t (*build_nonce_payload) (private_ike_sa_t *this, nonce_payload_t **payload);
        status_t (*build_ke_payload) (private_ike_sa_t *this, ke_payload_t **payload);
        
        status_t (*build_nonce_payload) (private_ike_sa_t *this, nonce_payload_t **payload);
        status_t (*build_ke_payload) (private_ike_sa_t *this, ke_payload_t **payload);
        
+       status_t (*build_message) (private_ike_sa_t *this, exchange_type_t type, bool request);
+       
        status_t (*transto_ike_sa_init_responded) (private_ike_sa_t *this, message_t *message);
        status_t (*transto_ike_auth_requested) (private_ike_sa_t *this, message_t *message);
 
        status_t (*transto_ike_sa_init_responded) (private_ike_sa_t *this, message_t *message);
        status_t (*transto_ike_auth_requested) (private_ike_sa_t *this, message_t *message);
 
@@ -144,6 +146,9 @@ struct private_ike_sa_s {
        
        diffie_hellman_t *diffie_hellman;
        
        
        diffie_hellman_t *diffie_hellman;
        
+       u_int32_t message_id_in;
+       u_int32_t message_id_out;
+       
        /**
         * a logger for this IKE_SA
         */
        /**
         * a logger for this IKE_SA
         */
@@ -205,10 +210,41 @@ static status_t process_message (private_ike_sa_t *this, message_t *message)
 }
 
 
 }
 
 
+static status_t build_message(private_ike_sa_t *this, exchange_type_t type, bool request)
+{
+       status_t status;
+       message_t *message;
+       host_t *source, *destination;
+       
+       message = message_create();     
+       if (message == NULL)
+       {
+               return OUT_OF_RES;
+       }
+       
+       status  = this->me.host->clone(this->me.host, &source);
+       status |= this->other.host->clone(this->other.host, &destination);      
+       if (status != SUCCESS)
+       {
+               message->destroy(message);
+               return status;  
+       }
+       message->set_source(message, source);
+       message->set_destination(message, destination);
+       
+       message->set_exchange_type(message, type);
+       message->set_request(message, request);
+       
+       message->set_ike_sa_id(message, this->ike_sa_id);
+       
+       return SUCCESS;
+}
+
 static status_t transto_ike_sa_init_responded(private_ike_sa_t *this, message_t *message)
 {
        status_t status;
        linked_list_iterator_t *payloads;
 static status_t transto_ike_sa_init_responded(private_ike_sa_t *this, message_t *message)
 {
        status_t status;
        linked_list_iterator_t *payloads;
+       message_t *respond;
        
        status = message->parse_body(message);
        if (status != SUCCESS)
        
        status = message->parse_body(message);
        if (status != SUCCESS)
@@ -216,9 +252,14 @@ static status_t transto_ike_sa_init_responded(private_ike_sa_t *this, message_t
                return status;  
        }
        
                return status;  
        }
        
+
+       
+       
+       
        status = message->get_payload_iterator(message, &payloads);
        if (status != SUCCESS)
        {
        status = message->get_payload_iterator(message, &payloads);
        if (status != SUCCESS)
        {
+               respond->destroy(respond);
                return status;  
        }
        while (payloads->has_next(payloads))
                return status;  
        }
        while (payloads->has_next(payloads))
@@ -239,7 +280,7 @@ static status_t transto_ike_sa_init_responded(private_ike_sa_t *this, message_t
                                        payloads->destroy(payloads);
                                        return status;
                                }
                                        payloads->destroy(payloads);
                                        return status;
                                }
-                               //global_configuration_manager->select_prop
+                               //global_configuration_manager->select_proposals_for_host
                                
                                break;
                        }
                                
                                break;
                        }
@@ -325,7 +366,7 @@ static status_t initialize_connection(private_ike_sa_t *this, char *name)
 
        message->set_exchange_type(message, IKE_SA_INIT);
        message->set_original_initiator(message, this->original_initiator);
 
        message->set_exchange_type(message, IKE_SA_INIT);
        message->set_original_initiator(message, this->original_initiator);
-       message->set_message_id(message, 0);
+       message->set_message_id(message, this->message_id_out++);
        message->set_ike_sa_id(message, this->ike_sa_id);
        message->set_request(message, TRUE);
        
        message->set_ike_sa_id(message, this->ike_sa_id);
        message->set_request(message, TRUE);
        
@@ -527,11 +568,11 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->build_ke_payload = build_ke_payload;
        this->build_nonce_payload = build_nonce_payload;
        
        this->build_ke_payload = build_ke_payload;
        this->build_nonce_payload = build_nonce_payload;
        
-       
+       this->build_message = build_message;
        this->transto_ike_sa_init_responded = transto_ike_sa_init_responded;
        this->transto_ike_auth_requested = transto_ike_auth_requested;
 
        this->transto_ike_sa_init_responded = transto_ike_sa_init_responded;
        this->transto_ike_auth_requested = transto_ike_auth_requested;
 
-
+       
 
        /* initialize private fields */
        if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
 
        /* initialize private fields */
        if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
@@ -574,6 +615,8 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->me.host = NULL;
        this->other.host = NULL;
        this->diffie_hellman = NULL;
        this->me.host = NULL;
        this->other.host = NULL;
        this->diffie_hellman = NULL;
+       this->message_id_out = 0;
+       this->message_id_in = 0;
 
 
        /* at creation time, IKE_SA isn't in a specific state */
 
 
        /* at creation time, IKE_SA isn't in a specific state */
index f290b83..07e85a2 100644 (file)
@@ -155,11 +155,7 @@ struct private_message_s {
         * Assigned exchange type
         */
        exchange_type_t exchange_type;
         * Assigned exchange type
         */
        exchange_type_t exchange_type;
-       
-       /**
-        * TRUE if message is from original initiator, FALSE otherwise.
-        */
-       bool original_initiator;
+
 
        /**
         * TRUE if message is request.
 
        /**
         * TRUE if message is request.
@@ -350,24 +346,6 @@ static exchange_type_t get_exchange_type (private_message_t *this)
        return this->exchange_type;
 }
 
        return this->exchange_type;
 }
 
-/**
- * Implements message_t's set_original_initiator function.
- * See #message_s.set_original_initiator.
- */
-static status_t set_original_initiator (private_message_t *this,bool original_initiator)
-{
-       this->original_initiator = original_initiator;
-       return SUCCESS;
-}
-
-/**
- * Implements message_t's get_original_initiator function.
- * See #message_s.get_original_initiator.
- */
-static exchange_type_t get_original_initiator (private_message_t *this)
-{
-       return this->original_initiator;
-}
 
 /**
  * Implements message_t's set_request function.
 
 /**
  * Implements message_t's set_request function.
@@ -470,7 +448,7 @@ static status_t generate(private_message_t *this, packet_t **packet)
        this->ike_sa_id->get_values(this->ike_sa_id, &initiator_spi, &responder_spi, &is_initiator); 
        
        ike_header->set_exchange_type(ike_header, this->exchange_type);
        this->ike_sa_id->get_values(this->ike_sa_id, &initiator_spi, &responder_spi, &is_initiator); 
        
        ike_header->set_exchange_type(ike_header, this->exchange_type);
-       ike_header->set_initiator_flag(ike_header, this->original_initiator);
+       ike_header->set_initiator_flag(ike_header, is_initiator);
        ike_header->set_message_id(ike_header, this->message_id);
        ike_header->set_response_flag(ike_header, !this->is_request);
        ike_header->set_initiator_flag(ike_header, is_initiator);
        ike_header->set_message_id(ike_header, this->message_id);
        ike_header->set_response_flag(ike_header, !this->is_request);
        ike_header->set_initiator_flag(ike_header, is_initiator);
@@ -567,9 +545,10 @@ static status_t parse_header (private_message_t *this)
        {
                this->ike_sa_id->destroy(this->ike_sa_id);
        }
        {
                this->ike_sa_id->destroy(this->ike_sa_id);
        }
-       this->original_initiator = (!ike_header->get_initiator_flag(ike_header));
        
        
-       this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),ike_header->get_responder_spi(ike_header),this->original_initiator);
+       this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),
+                                                                          ike_header->get_responder_spi(ike_header),
+                                                                          !ike_header->get_initiator_flag(ike_header));
        if (this->ike_sa_id == NULL)
        {
                this->logger->log(this->logger, ERROR, "Could not creaee ike_sa_id object");
        if (this->ike_sa_id == NULL)
        {
                this->logger->log(this->logger, ERROR, "Could not creaee ike_sa_id object");
@@ -772,8 +751,6 @@ message_t *message_create_from_packet(packet_t *packet)
        this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id;
        this->public.set_exchange_type = (status_t(*)(message_t*, exchange_type_t))set_exchange_type;
        this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type;
        this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id;
        this->public.set_exchange_type = (status_t(*)(message_t*, exchange_type_t))set_exchange_type;
        this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type;
-       this->public.set_original_initiator = (status_t(*)(message_t*, bool))set_original_initiator;
-       this->public.get_original_initiator = (bool(*)(message_t*))get_original_initiator;
        this->public.set_request = (status_t(*)(message_t*, bool))set_request;
        this->public.get_request = (bool(*)(message_t*))get_request;
        this->public.add_payload = (status_t(*)(message_t*,payload_t*))add_payload;
        this->public.set_request = (status_t(*)(message_t*, bool))set_request;
        this->public.get_request = (bool(*)(message_t*))get_request;
        this->public.add_payload = (status_t(*)(message_t*,payload_t*))add_payload;
@@ -789,7 +766,6 @@ message_t *message_create_from_packet(packet_t *packet)
                
        /* public values */
        this->exchange_type = EXCHANGE_TYPE_UNDEFINED;
                
        /* public values */
        this->exchange_type = EXCHANGE_TYPE_UNDEFINED;
-       this->original_initiator = TRUE;
        this->is_request = TRUE;
        this->ike_sa_id = NULL;
        this->first_payload = NO_PAYLOAD;
        this->is_request = TRUE;
        this->ike_sa_id = NULL;
        this->first_payload = NO_PAYLOAD;