Added out message queue for imv_msg receive method
authorAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 29 Aug 2014 04:23:16 +0000 (06:23 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 5 Oct 2014 10:55:37 +0000 (12:55 +0200)
src/libimcv/imc/imc_msg.c
src/libimcv/imv/imv_msg.c
src/libimcv/imv/imv_msg.h
src/libimcv/plugins/imv_os/imv_os_agent.c
src/libimcv/plugins/imv_scanner/imv_scanner_agent.c
src/libimcv/plugins/imv_test/imv_test_agent.c
src/libpts/plugins/imv_attestation/imv_attestation_agent.c
src/libpts/plugins/imv_swid/imv_swid_agent.c

index 3f2d7ae..ce628e4 100644 (file)
@@ -435,7 +435,7 @@ METHOD(imc_msg_t, receive, TNC_Result,
                                if (!contract)
                                {
                                        /* TODO no contract - generate error message */
-                                       DBG2(DBG_IMC, "no contract for received next segment "
+                                       DBG1(DBG_IMC, "no contract for received next segment "
                                                 "request with base attribute ID %u", base_attr_id);
                                        continue;
                                }
index b32b01c..d5f86ba 100644 (file)
@@ -268,7 +268,7 @@ METHOD(imv_msg_t, send_assessment, TNC_Result,
 }
 
 METHOD(imv_msg_t, receive, TNC_Result,
-       private_imv_msg_t *this, bool *fatal_error)
+       private_imv_msg_t *this, imv_msg_t *out_msg, bool *fatal_error)
 {
        TNC_Result result = TNC_RESULT_SUCCESS;
        linked_list_t *non_fatal_types;
@@ -310,25 +310,13 @@ METHOD(imv_msg_t, receive, TNC_Result,
                        break;
                case VERIFY_ERROR:
                {
-                       imv_msg_t *error_msg;
-
-                       error_msg = imv_msg_create_as_reply(&this->public);
-
                        /* extract and copy by reference all error attributes */
                        enumerator = this->pa_msg->create_error_enumerator(this->pa_msg);
                        while (enumerator->enumerate(enumerator, &attr))
                        {
-                               error_msg->add_attribute(error_msg, attr->get_ref(attr));
+                               out_msg->add_attribute(out_msg, attr->get_ref(attr));
                        }
                        enumerator->destroy(enumerator);
-
-                       /*
-                        * send the PA-TNC message containing all error attributes
-                        * with the excl flag set
-                        */
-                       result = error_msg->send(error_msg, TRUE);
-                       error_msg->destroy(error_msg);
-                       return result;
                }
                case FAILED:
                default:
@@ -340,7 +328,6 @@ METHOD(imv_msg_t, receive, TNC_Result,
        while (enumerator->enumerate(enumerator, &attr))
        {
                uint32_t max_attr_size, max_seg_size, my_max_attr_size, my_max_seg_size;
-               imv_msg_t *out_msg;
                seg_contract_manager_t *contracts;
                seg_contract_t *contract;
                char buf[BUF_LEN];
@@ -399,17 +386,10 @@ METHOD(imv_msg_t, receive, TNC_Result,
                                                 max_seg_size);
                                }
 
-                               /* Send Maximum Attribute Size Response */
-                               out_msg = imv_msg_create_as_reply(&this->public);
+                               /* Add Maximum Attribute Size Response attribute */
                                attr = tcg_seg_attr_max_size_create(max_attr_size,
                                                                                                        max_seg_size, FALSE);
                                out_msg->add_attribute(out_msg, attr);
-                               result = out_msg->send(out_msg, TRUE);
-                               out_msg->destroy(out_msg);
-                               if (result != TNC_RESULT_SUCCESS)
-                               {
-                                       break;
-                               }
                                break;
                        }
                        case TCG_SEG_MAX_ATTR_SIZE_RESP:
@@ -463,10 +443,7 @@ METHOD(imv_msg_t, receive, TNC_Result,
                                attr = contract->add_segment(contract, attr, &error, &more);
                                if (error)
                                {
-                                       out_msg = imv_msg_create_as_reply(&this->public);
                                        out_msg->add_attribute(out_msg, error);
-                                       result = out_msg->send(out_msg, TRUE);
-                                       out_msg->destroy(out_msg);
                                }
                                if (attr)
                                {
@@ -475,11 +452,8 @@ METHOD(imv_msg_t, receive, TNC_Result,
                                if (more)
                                {
                                        /* Send Next Segment Request */
-                                       out_msg = imv_msg_create_as_reply(&this->public);
                                        attr = tcg_seg_attr_next_seg_create(base_attr_id, FALSE);
                                        out_msg->add_attribute(out_msg, attr);
-                                       result = out_msg->send(out_msg, TRUE);
-                                       out_msg->destroy(out_msg);
                                }
                                break;
                        }
@@ -496,21 +470,20 @@ METHOD(imv_msg_t, receive, TNC_Result,
                                if (!contract)
                                {
                                        /* TODO no contract - generate error message */
-                                       DBG2(DBG_IMV, "no contract for received next segment "
+                                       DBG1(DBG_IMV, "no contract for received next segment "
                                                 "request with base attribute ID %u", base_attr_id);
                                        continue;
                                }
                                attr = contract->next_segment(contract, base_attr_id);
                                if (attr)
                                {
-                                       out_msg = imv_msg_create_as_reply(&this->public);
                                        out_msg->add_attribute(out_msg, attr);
-                                       result = out_msg->send(out_msg, TRUE);
-                                       out_msg->destroy(out_msg);
                                }
                                else
                                {
                                        /* TODO no more segments - generate error message */
+                                       DBG1(DBG_IMV, "no more segments found for "
+                                                "base attribute ID %u", base_attr_id);
                                }
                                break;
                        }
index 6f93e12..43b91e9 100644 (file)
@@ -79,10 +79,12 @@ struct imv_msg_t {
        /**
         * Processes a received PA-TNC message
         *
+        * @param out_msg                       outgoing PA-TN message
         * @param fatal_error           TRUE if IMC sent a fatal error message
         * @return                                      TNC result code
         */
-       TNC_Result (*receive)(imv_msg_t *this, bool *fatal_error);
+       TNC_Result (*receive)(imv_msg_t *this, imv_msg_t *out_msg,
+                                                 bool *fatal_error);
 
        /**
         * Add a PA-TNC attribute to the send queue
index ca8bac6..8f92531 100644 (file)
@@ -171,15 +171,17 @@ static TNC_Result receive_msg(private_imv_os_agent_t *this, imv_state_t *state,
        session = state->get_session(state);
        os_info = session->get_os_info(session);
 
+       /* generate an outgoing PA-TNC message - we might need it */
+       out_msg = imv_msg_create_as_reply(in_msg);
+
        /* parse received PA-TNC message and handle local and remote errors */
-       result = in_msg->receive(in_msg, &fatal_error);
+       result = in_msg->receive(in_msg,out_msg, &fatal_error);
        if (result != TNC_RESULT_SUCCESS)
        {
+               out_msg->destroy(out_msg);
                return result;
        }
 
-       out_msg = imv_msg_create_as_reply(in_msg);
-
        /* analyze PA-TNC attributes */
        enumerator = in_msg->create_attribute_enumerator(in_msg);
        while (enumerator->enumerate(enumerator, &attr))
@@ -394,20 +396,20 @@ static TNC_Result receive_msg(private_imv_os_agent_t *this, imv_state_t *state,
        {
                os_state->set_handshake_state(os_state, IMV_OS_STATE_END);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
        }
-
-       /* send PA-TNC message with excl flag set */
-       result = out_msg->send(out_msg, TRUE);
+       else
+       {
+               /* send PA-TNC message with the EXCL flag set */
+               result = out_msg->send(out_msg, TRUE);
+       }
        out_msg->destroy(out_msg);
 
        return result;
- }
+}
 
 METHOD(imv_agent_if_t, receive_message, TNC_Result,
        private_imv_os_agent_t *this, TNC_ConnectionID id,
index 85ef23b..cbabc80 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Andreas Steffen
+ * Copyright (C) 2013-2014 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -94,10 +94,14 @@ static TNC_Result receive_msg(private_imv_scanner_agent_t *this,
        ietf_attr_port_filter_t *port_filter_attr;
        bool fatal_error = FALSE;
 
+       /* generate an outgoing PA-TNC message - we might need it */
+       out_msg = imv_msg_create_as_reply(in_msg);
+
        /* parse received PA-TNC message and handle local and remote errors */
-       result = in_msg->receive(in_msg, &fatal_error);
+       result = in_msg->receive(in_msg, out_msg, &fatal_error);
        if (result != TNC_RESULT_SUCCESS)
        {
+               out_msg->destroy(out_msg);
                return result;
        }
 
@@ -121,17 +125,20 @@ static TNC_Result receive_msg(private_imv_scanner_agent_t *this,
                state->set_recommendation(state,
                                                                TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                                                                TNC_IMV_EVALUATION_RESULT_ERROR);
-               out_msg = imv_msg_create_as_reply(in_msg);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
        }
+       else
+       {
+               /* send PA-TNC message with the EXCL flag set */
+               result = out_msg->send(out_msg, TRUE);
+       }
+       out_msg->destroy(out_msg);
 
-       return TNC_RESULT_SUCCESS;
+       return result;
 }
 
 METHOD(imv_agent_if_t, receive_message, TNC_Result,
index 4263000..5e4b486 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Andreas Steffen
+ * Copyright (C) 2013-2014 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -94,10 +94,14 @@ static TNC_Result receive_msg(private_imv_test_agent_t *this, imv_state_t *state
        int rounds;
        bool fatal_error = FALSE, received_command = FALSE, retry = FALSE;
 
+       /* generate an outgoing PA-TNC message - we might need it */
+       out_msg = imv_msg_create_as_reply(in_msg);
+
        /* parse received PA-TNC message and handle local and remote errors */
-       result = in_msg->receive(in_msg, &fatal_error);
+       result = in_msg->receive(in_msg, out_msg, &fatal_error);
        if (result != TNC_RESULT_SUCCESS)
        {
+               out_msg->destroy(out_msg);
                return result;
        }
 
@@ -172,14 +176,12 @@ static TNC_Result receive_msg(private_imv_test_agent_t *this, imv_state_t *state
                state->set_recommendation(state,
                                                        TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                                                        TNC_IMV_EVALUATION_RESULT_ERROR);
-               out_msg = imv_msg_create_as_reply(in_msg);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
+               return result;
        }
 
        /* request a handshake retry ? */
@@ -195,7 +197,6 @@ static TNC_Result receive_msg(private_imv_test_agent_t *this, imv_state_t *state
        /* repeat the measurement ? */
        if (test_state->another_round(test_state, in_msg->get_src_id(in_msg)))
        {
-               out_msg = imv_msg_create_as_reply(in_msg);
                attr = ita_attr_command_create("repeat");
                out_msg->add_attribute(out_msg, attr);
 
@@ -208,19 +209,20 @@ static TNC_Result receive_msg(private_imv_test_agent_t *this, imv_state_t *state
 
        if (received_command)
        {
-               out_msg = imv_msg_create_as_reply(in_msg);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
        }
        else
        {
-               return TNC_RESULT_SUCCESS;
+               /* send PA-TNC message with the EXCL flag set */
+               result = out_msg->send(out_msg, TRUE);
        }
+       out_msg->destroy(out_msg);
+
+       return result;
  }
 
 METHOD(imv_agent_if_t, receive_message, TNC_Result,
index fcfee31..ead3cc8 100644 (file)
@@ -176,19 +176,21 @@ static TNC_Result receive_msg(private_imv_attestation_agent_t *this,
        chunk_t os_name, os_version;
        bool fatal_error = FALSE;
 
+       /* generate an outgoing PA-TNC message - we might need it */
+       out_msg = imv_msg_create_as_reply(in_msg);
+       out_msg->set_msg_type(out_msg, msg_types[0]);
+
        /* parse received PA-TNC message and handle local and remote errors */
-       result = in_msg->receive(in_msg, &fatal_error);
+       result = in_msg->receive(in_msg, out_msg, &fatal_error);
        if (result != TNC_RESULT_SUCCESS)
        {
+               out_msg->destroy(out_msg);
                return result;
        }
 
        session = state->get_session(state);
        os_info = session->get_os_info(session);
 
-       out_msg = imv_msg_create_as_reply(in_msg);
-       out_msg->set_msg_type(out_msg, msg_types[0]);
-
        /* analyze PA-TNC attributes */
        enumerator = in_msg->create_attribute_enumerator(in_msg);
        while (enumerator->enumerate(enumerator, &attr))
@@ -305,16 +307,16 @@ static TNC_Result receive_msg(private_imv_attestation_agent_t *this,
                                                                TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                                                                TNC_IMV_EVALUATION_RESULT_ERROR);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
        }
-
-       /* send PA-TNC message with excl flag set */
-       result = out_msg->send(out_msg, TRUE);
+       else
+       {
+               /* send PA-TNC message with the EXCL flag set */
+               result = out_msg->send(out_msg, TRUE);
+       }
        out_msg->destroy(out_msg);
 
        return result;
index 80b4453..71c601c 100644 (file)
@@ -119,10 +119,14 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
        TNC_Result result;
        bool fatal_error = FALSE;
 
+       /* generate an outgoing PA-TNC message - we might need it */
+       out_msg = imv_msg_create_as_reply(in_msg);
+
        /* parse received PA-TNC message and handle local and remote errors */
-       result = in_msg->receive(in_msg, &fatal_error);
+       result = in_msg->receive(in_msg, out_msg, &fatal_error);
        if (result != TNC_RESULT_SUCCESS)
        {
+               out_msg->destroy(out_msg);
                return result;
        }
 
@@ -305,17 +309,20 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
                state->set_recommendation(state,
                                                                TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                                                                TNC_IMV_EVALUATION_RESULT_ERROR);
-               out_msg = imv_msg_create_as_reply(in_msg);
                result = out_msg->send_assessment(out_msg);
-               out_msg->destroy(out_msg);
-               if (result != TNC_RESULT_SUCCESS)
+               if (result == TNC_RESULT_SUCCESS)
                {
-                       return result;
+                       result = this->agent->provide_recommendation(this->agent, state);
                }
-               return this->agent->provide_recommendation(this->agent, state);
        }
+       else
+       {
+               /* send PA-TNC message with the EXCL flag set */
+               result = out_msg->send(out_msg, TRUE);
+       }
+       out_msg->destroy(out_msg);
 
-       return TNC_RESULT_SUCCESS;
+       return result;
 }
 
 METHOD(imv_agent_if_t, receive_message, TNC_Result,