nearly completed PA-TNC error handling
This commit is contained in:
@@ -271,6 +271,61 @@ METHOD(imc_agent_t, send_message, TNC_Result,
|
||||
this->type);
|
||||
}
|
||||
|
||||
METHOD(imc_agent_t, receive_message, TNC_Result,
|
||||
private_imc_agent_t *this, TNC_ConnectionID connection_id, chunk_t msg,
|
||||
TNC_MessageType msg_type, pa_tnc_msg_t **pa_tnc_msg)
|
||||
{
|
||||
pa_tnc_msg_t *pa_msg, *error_msg;
|
||||
pa_tnc_attr_t *error_attr;
|
||||
enumerator_t *enumerator;
|
||||
TNC_Result result;
|
||||
|
||||
DBG2(DBG_IMV, "IMC %u \"%s\" received message type 0x%08x for Connection ID %u",
|
||||
this->id, this->name, msg_type, connection_id);
|
||||
|
||||
*pa_tnc_msg = NULL;
|
||||
pa_msg = pa_tnc_msg_create_from_data(msg);
|
||||
|
||||
switch (pa_msg->process(pa_msg))
|
||||
{
|
||||
case SUCCESS:
|
||||
*pa_tnc_msg = pa_msg;
|
||||
break;
|
||||
case VERIFY_ERROR:
|
||||
if (!this->send_message)
|
||||
{
|
||||
/* TNCC doen't have a SendMessage() function */
|
||||
return TNC_RESULT_FATAL;
|
||||
}
|
||||
|
||||
/* build error message */
|
||||
error_msg = pa_tnc_msg_create();
|
||||
enumerator = pa_msg->create_error_enumerator(pa_msg);
|
||||
while (enumerator->enumerate(enumerator, &error_attr))
|
||||
{
|
||||
error_msg->add_attribute(error_msg,
|
||||
error_attr->get_ref(error_attr));
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
error_msg->build(error_msg);
|
||||
|
||||
/* send error message */
|
||||
msg = error_msg->get_encoding(error_msg);
|
||||
result = this->send_message(this->id, connection_id,
|
||||
msg.ptr, msg.len, msg_type);
|
||||
|
||||
/* clean up */
|
||||
error_msg->destroy(error_msg);
|
||||
pa_msg->destroy(pa_msg);
|
||||
return result;
|
||||
case FAILED:
|
||||
default:
|
||||
pa_msg->destroy(pa_msg);
|
||||
return TNC_RESULT_FATAL;
|
||||
}
|
||||
return TNC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
METHOD(imc_agent_t, destroy, void,
|
||||
private_imc_agent_t *this)
|
||||
{
|
||||
@@ -306,6 +361,7 @@ imc_agent_t *imc_agent_create(const char *name,
|
||||
.change_state = _change_state,
|
||||
.get_state = _get_state,
|
||||
.send_message = _send_message,
|
||||
.receive_message = _receive_message,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.name = name,
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define IMC_AGENT_H_
|
||||
|
||||
#include "imc_state.h"
|
||||
#include "pa_tnc/pa_tnc_msg.h"
|
||||
|
||||
#include <tncifimc.h>
|
||||
#include <pen/pen.h>
|
||||
@@ -95,7 +96,7 @@ struct imc_agent_t {
|
||||
TNC_ConnectionID connection_id, imc_state_t **state);
|
||||
|
||||
/**
|
||||
* Call when an IMC-IMV message is to be sent
|
||||
* Call when an PA-TNC message is to be sent
|
||||
*
|
||||
* @param connection_id network connection ID assigned by TNCC
|
||||
* @param msg message to send
|
||||
@@ -105,6 +106,20 @@ struct imc_agent_t {
|
||||
TNC_ConnectionID connection_id,
|
||||
chunk_t msg);
|
||||
|
||||
/**
|
||||
* Call when a PA-TNC message was received
|
||||
*
|
||||
* @param connection_id network connection ID assigned by TNCC
|
||||
* @param msg received unparsed message
|
||||
* @param msg_type message type of the received message
|
||||
* @param pa_tnc_message parsed PA-TNC message or NULL if an error occurred
|
||||
* @return TNC result code
|
||||
*/
|
||||
TNC_Result (*receive_message)(imc_agent_t *this,
|
||||
TNC_ConnectionID connection_id, chunk_t msg,
|
||||
TNC_MessageType msg_type,
|
||||
pa_tnc_msg_t **pa_tnc_msg);
|
||||
|
||||
/**
|
||||
* Destroys an imc_agent_t object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user