added IMC/IMV support for send_message_long() and reserve_additional_id() functions
This commit is contained in:
@@ -73,8 +73,10 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
|
||||
imc_state_t *state;
|
||||
imc_test_state_t *test_state;
|
||||
TNC_Result result;
|
||||
TNC_UInt32 new_imc_id;
|
||||
char *command;
|
||||
bool retry;
|
||||
int additional_ids;
|
||||
|
||||
if (!imc_test)
|
||||
{
|
||||
@@ -85,11 +87,48 @@ 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");
|
||||
"libimcv.plugins.imc-test.command", "none");
|
||||
retry = lib->settings->get_bool(lib->settings,
|
||||
"libimcv.plugins.imc-test.retry", FALSE);
|
||||
state = imc_test_state_create(connection_id, command, retry);
|
||||
return imc_test->create_state(imc_test, state);
|
||||
|
||||
result = imc_test->create_state(imc_test, state);
|
||||
if (result != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Do we want to reserve additional IMC IDs? */
|
||||
additional_ids = lib->settings->get_int(lib->settings,
|
||||
"libimcv.plugins.imc-test.additional_ids", 0);
|
||||
if (additional_ids < 1)
|
||||
{
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
if (!state->has_long(state))
|
||||
{
|
||||
DBG1(DBG_IMC, "IMC %u \"%s\" did not detect support of "
|
||||
"multiple IMC IDs", imc_id, imc_name);
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
test_state = (imc_test_state_t*)state;
|
||||
|
||||
while (additional_ids-- > 0)
|
||||
{
|
||||
if (imc_test->reserve_additional_id(imc_test, &new_imc_id) !=
|
||||
TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IMC, "IMC %u \"%s\" failed to reserve "
|
||||
"%d additional IMC IDs",
|
||||
imc_id, imc_name, additional_ids);
|
||||
break;
|
||||
}
|
||||
DBG2(DBG_IMC, "IMC %u \"%s\" reserved additional ID %u",
|
||||
imc_id, imc_name, new_imc_id);
|
||||
test_state->add_id(test_state, new_imc_id);
|
||||
}
|
||||
return TNC_RESULT_SUCCESS;
|
||||
|
||||
case TNC_CONNECTION_STATE_HANDSHAKE:
|
||||
/* get updated IMC state */
|
||||
@@ -145,6 +184,9 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
|
||||
pa_tnc_attr_t *attr;
|
||||
imc_state_t *state;
|
||||
imc_test_state_t *test_state;
|
||||
enumerator_t *enumerator;
|
||||
void *pointer;
|
||||
TNC_UInt32 imc_id;
|
||||
TNC_Result result;
|
||||
|
||||
if (!imc_test->get_state(imc_test, connection_id, &state))
|
||||
@@ -152,15 +194,36 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
|
||||
return TNC_RESULT_FATAL;
|
||||
}
|
||||
test_state = (imc_test_state_t*)state;
|
||||
|
||||
/* send PA message for primary IMC ID */
|
||||
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);
|
||||
result = imc_test->send_message(imc_test, connection_id,
|
||||
msg->get_encoding(msg));
|
||||
result = imc_test->send_message(imc_test, connection_id, FALSE, 0,
|
||||
TNC_IMVID_ANY, msg->get_encoding(msg));
|
||||
msg->destroy(msg);
|
||||
|
||||
/* send PA messages for additional IMC IDs */
|
||||
enumerator = test_state->create_id_enumerator(test_state);
|
||||
while (result == TNC_RESULT_SUCCESS &&
|
||||
enumerator->enumerate(enumerator, &pointer))
|
||||
{
|
||||
/* interpret pointer as scalar value */
|
||||
imc_id = (TNC_UInt32)pointer;
|
||||
|
||||
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);
|
||||
result = imc_test->send_message(imc_test, connection_id, FALSE, imc_id,
|
||||
TNC_IMVID_ANY, msg->get_encoding(msg));
|
||||
msg->destroy(msg);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "imc_test_state.h"
|
||||
|
||||
#include <debug.h>
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
typedef struct private_imc_test_state_t private_imc_test_state_t;
|
||||
|
||||
@@ -62,6 +63,12 @@ struct private_imc_test_state_t {
|
||||
* Do a handshake retry
|
||||
*/
|
||||
bool handshake_retry;
|
||||
|
||||
/**
|
||||
* List of additional IMC IDs
|
||||
*/
|
||||
linked_list_t *additional_ids;
|
||||
|
||||
};
|
||||
|
||||
METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
|
||||
@@ -98,6 +105,7 @@ METHOD(imc_state_t, change_state, void,
|
||||
METHOD(imc_state_t, destroy, void,
|
||||
private_imc_test_state_t *this)
|
||||
{
|
||||
this->additional_ids->destroy(this->additional_ids);
|
||||
free(this->command);
|
||||
free(this);
|
||||
}
|
||||
@@ -140,6 +148,22 @@ METHOD(imc_test_state_t, do_handshake_retry, bool,
|
||||
return retry;
|
||||
}
|
||||
|
||||
METHOD(imc_test_state_t, add_id, void,
|
||||
private_imc_test_state_t *this, TNC_IMCID id)
|
||||
{
|
||||
void *pointer;
|
||||
|
||||
/* store the scalar value in the pointer */
|
||||
pointer = (void*)id;
|
||||
this->additional_ids->insert_last(this->additional_ids, pointer);
|
||||
}
|
||||
|
||||
METHOD(imc_test_state_t, create_id_enumerator, enumerator_t*,
|
||||
private_imc_test_state_t *this)
|
||||
{
|
||||
return this->additional_ids->create_enumerator(this->additional_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -162,12 +186,15 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
|
||||
.set_command = _set_command,
|
||||
.is_first_handshake = _is_first_handshake,
|
||||
.do_handshake_retry = _do_handshake_retry,
|
||||
.add_id = _add_id,
|
||||
.create_id_enumerator = _create_id_enumerator,
|
||||
},
|
||||
.state = TNC_CONNECTION_STATE_CREATE,
|
||||
.connection_id = connection_id,
|
||||
.command = strdup(command),
|
||||
.first_handshake = TRUE,
|
||||
.handshake_retry = retry,
|
||||
.additional_ids = linked_list_create(),
|
||||
);
|
||||
|
||||
return &this->public.interface;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef IMC_TEST_STATE_H_
|
||||
#define IMC_TEST_STATE_H_
|
||||
|
||||
#include <tncifimc.h>
|
||||
#include <imc/imc_state.h>
|
||||
#include <library.h>
|
||||
|
||||
@@ -63,6 +64,18 @@ struct imc_test_state_t {
|
||||
* @return TRUE if a handshake retry should be done
|
||||
*/
|
||||
bool (*do_handshake_retry)(imc_test_state_t *this);
|
||||
|
||||
/**
|
||||
* Add and additional IMC ID
|
||||
*
|
||||
* @param id Additional IMC ID
|
||||
*/
|
||||
void (*add_id)(imc_test_state_t *this, TNC_IMCID id);
|
||||
|
||||
/**
|
||||
* Create an enumerator for additional IMC IDs
|
||||
*/
|
||||
enumerator_t* (*create_id_enumerator)(imc_test_state_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user