diff options
Diffstat (limited to 'src/libimcv/plugins/imc_test/imc_test.c')
-rw-r--r-- | src/libimcv/plugins/imc_test/imc_test.c | 103 |
1 files changed, 83 insertions, 20 deletions
diff --git a/src/libimcv/plugins/imc_test/imc_test.c b/src/libimcv/plugins/imc_test/imc_test.c index fe005ed4a..ee8e5b206 100644 --- a/src/libimcv/plugins/imc_test/imc_test.c +++ b/src/libimcv/plugins/imc_test/imc_test.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil + * Copyright (C) 2011-2012 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -18,10 +19,11 @@ #include <pa_tnc/pa_tnc_msg.h> #include <ietf/ietf_attr.h> #include <ietf/ietf_attr_pa_tnc_error.h> +#include <ietf/ietf_attr_assess_result.h> #include <ita/ita_attr.h> #include <ita/ita_attr_command.h> +#include <ita/ita_attr_dummy.h> -#include <tncif_names.h> #include <tncif_pa_subtypes.h> #include <pen/pen.h> @@ -73,9 +75,12 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, imc_state_t *state; imc_test_state_t *test_state; TNC_Result result; + TNC_UInt32 additional_id; char *command; bool retry; - int additional_ids; + void *pointer; + enumerator_t *enumerator; + int dummy_size, additional_ids; if (!imc_test) { @@ -88,9 +93,12 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, case TNC_CONNECTION_STATE_CREATE: command = lib->settings->get_str(lib->settings, "libimcv.plugins.imc-test.command", "none"); + dummy_size = lib->settings->get_int(lib->settings, + "libimcv.plugins.imc-test.dummy_size", 0); retry = lib->settings->get_bool(lib->settings, "libimcv.plugins.imc-test.retry", FALSE); - state = imc_test_state_create(connection_id, command, retry); + state = imc_test_state_create(connection_id, command, dummy_size, + retry); result = imc_test->create_state(imc_test, state); if (result != TNC_RESULT_SUCCESS) @@ -124,6 +132,26 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, test_state->get_command(test_state)); test_state->set_command(test_state, command); } + + state->set_result(state, imc_id, TNC_IMV_EVALUATION_RESULT_DONT_KNOW); + + /* Exit if there are no additional IMC IDs */ + if (!imc_test->count_additional_ids(imc_test)) + { + return result; + } + + enumerator = imc_test->create_id_enumerator(imc_test); + while (enumerator->enumerate(enumerator, &pointer)) + { + /* interpret pointer as scalar value */ + additional_id = (TNC_UInt32)pointer; + + state->set_result(state, additional_id, + TNC_IMV_EVALUATION_RESULT_DONT_KNOW); + } + enumerator->destroy(enumerator); + return TNC_RESULT_SUCCESS; case TNC_CONNECTION_STATE_DELETE: @@ -158,23 +186,30 @@ static TNC_Result send_message(imc_state_t *state, TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id) { imc_test_state_t *test_state; - pa_tnc_msg_t *msg; + linked_list_t *attr_list; pa_tnc_attr_t *attr; bool excl; TNC_ConnectionID connection_id; TNC_Result result; + attr_list = linked_list_create(); connection_id = state->get_connection_id(state); test_state = (imc_test_state_t*)state; + + if (test_state->get_dummy_size(test_state)) + { + attr = ita_attr_dummy_create(test_state->get_dummy_size(test_state)); + attr->set_noskip_flag(attr, TRUE); + attr_list->insert_last(attr_list, attr); + } attr = ita_attr_command_create(test_state->get_command(test_state)); attr->set_noskip_flag(attr, TRUE); - msg = pa_tnc_msg_create(); - msg->add_attribute(msg, attr); - msg->build(msg); + attr_list->insert_last(attr_list, attr); + excl = dst_imv_id != TNC_IMVID_ANY; result = imc_test->send_message(imc_test, connection_id, excl, src_imc_id, - dst_imv_id, msg->get_encoding(msg)); - msg->destroy(msg); + dst_imv_id, attr_list); + attr_list->destroy(attr_list); return result; } @@ -245,9 +280,11 @@ static TNC_Result receive_message(TNC_IMCID imc_id, { pa_tnc_msg_t *pa_tnc_msg; pa_tnc_attr_t *attr; + pen_type_t attr_type; imc_state_t *state; enumerator_t *enumerator; TNC_Result result; + TNC_UInt32 target_imc_id; bool fatal_error = FALSE; if (!imc_test) @@ -271,6 +308,7 @@ static TNC_Result receive_message(TNC_IMCID imc_id, { return result; } + target_imc_id = (dst_imc_id == TNC_IMCID_ANY) ? imc_id : dst_imc_id; /* preprocess any IETF standard error attributes */ fatal_error = pa_tnc_msg->process_ietf_std_errors(pa_tnc_msg); @@ -279,22 +317,47 @@ static TNC_Result receive_message(TNC_IMCID imc_id, enumerator = pa_tnc_msg->create_attribute_enumerator(pa_tnc_msg); while (enumerator->enumerate(enumerator, &attr)) { - if (attr->get_vendor_id(attr) == PEN_ITA && - attr->get_type(attr) == ITA_ATTR_COMMAND) + attr_type = attr->get_type(attr); + + if (attr_type.vendor_id == PEN_IETF) { - ita_attr_command_t *ita_attr; - char *command; - - ita_attr = (ita_attr_command_t*)attr; - command = ita_attr->get_command(ita_attr); + ietf_attr_assess_result_t *ietf_attr; + + ietf_attr = (ietf_attr_assess_result_t*)attr; + state->set_result(state, target_imc_id, + ietf_attr->get_result(ietf_attr)); + } + else if (attr_type.vendor_id == PEN_ITA) + { + if (attr_type.type == ITA_ATTR_COMMAND) + { + ita_attr_command_t *ita_attr; + + ita_attr = (ita_attr_command_t*)attr; + DBG1(DBG_IMC, "received command '%s'", + ita_attr->get_command(ita_attr)); + } + else if (attr_type.type == ITA_ATTR_DUMMY) + { + ita_attr_dummy_t *ita_attr; + + ita_attr = (ita_attr_dummy_t*)attr; + DBG1(DBG_IMC, "received dummy attribute value (%d bytes)", + ita_attr->get_size(ita_attr)); + } } } enumerator->destroy(enumerator); pa_tnc_msg->destroy(pa_tnc_msg); - /* if no error occurred then always return the same response */ - return fatal_error ? TNC_RESULT_FATAL : - send_message(state, dst_imc_id, src_imv_id); + if (fatal_error) + { + return TNC_RESULT_FATAL; + } + + /* if no assessment result is known then repeat the measurement */ + return state->get_result(state, target_imc_id, NULL) ? + TNC_RESULT_SUCCESS : send_message(state, dst_imc_id, src_imv_id); } /** |