refactored message handling
This commit is contained in:
@@ -116,13 +116,7 @@ METHOD(tnccs_t, send_message, void,
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static status_t handle_messages(private_tnccs_20_t *this, pb_tnc_batch_t *batch)
|
static void handle_message(private_tnccs_20_t *this, pb_tnc_message_t *msg)
|
||||||
{
|
|
||||||
enumerator_t *enumerator;
|
|
||||||
pb_tnc_message_t *msg;
|
|
||||||
|
|
||||||
enumerator = batch->create_msg_enumerator(batch);
|
|
||||||
while (enumerator->enumerate(enumerator, &msg))
|
|
||||||
{
|
{
|
||||||
switch (msg->get_type(msg))
|
switch (msg->get_type(msg))
|
||||||
{
|
{
|
||||||
@@ -239,8 +233,7 @@ static status_t handle_messages(private_tnccs_20_t *this, pb_tnc_batch_t *batch)
|
|||||||
lang_msg = (pb_language_preference_message_t*)msg;
|
lang_msg = (pb_language_preference_message_t*)msg;
|
||||||
lang = lang_msg->get_language_preference(lang_msg);
|
lang = lang_msg->get_language_preference(lang_msg);
|
||||||
|
|
||||||
DBG2(DBG_TNC, "setting language preference '%.*s'",
|
DBG2(DBG_TNC, "setting language preference '%.*s'", lang.len, lang.ptr);
|
||||||
lang.len, lang.ptr);
|
|
||||||
this->recs->set_preferred_language(this->recs, lang);
|
this->recs->set_preferred_language(this->recs, lang);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -262,10 +255,6 @@ static status_t handle_messages(private_tnccs_20_t *this, pb_tnc_batch_t *batch)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(tls_t, process, status_t,
|
METHOD(tls_t, process, status_t,
|
||||||
private_tnccs_20_t *this, void *buf, size_t buflen)
|
private_tnccs_20_t *this, void *buf, size_t buflen)
|
||||||
@@ -296,10 +285,50 @@ METHOD(tls_t, process, status_t,
|
|||||||
batch = pb_tnc_batch_create_from_data(this->is_server, data);
|
batch = pb_tnc_batch_create_from_data(this->is_server, data);
|
||||||
status = batch->process(batch, this->state_machine);
|
status = batch->process(batch, this->state_machine);
|
||||||
|
|
||||||
switch (status)
|
if (status != FAILED)
|
||||||
{
|
{
|
||||||
case SUCCESS:
|
enumerator_t *enumerator;
|
||||||
handle_messages(this, batch);
|
pb_tnc_message_t *msg;
|
||||||
|
pb_tnc_batch_type_t batch_type;
|
||||||
|
bool empty = TRUE;
|
||||||
|
|
||||||
|
batch_type = batch->get_type(batch);
|
||||||
|
|
||||||
|
if (batch_type == PB_BATCH_CRETRY)
|
||||||
|
{
|
||||||
|
this->mutex->lock(this->mutex);
|
||||||
|
if (this->batch)
|
||||||
|
{
|
||||||
|
DBG1(DBG_TNC, "cancelling PB-TNC %N Batch",
|
||||||
|
pb_tnc_batch_type_names, this->batch->get_type(this->batch));
|
||||||
|
this->batch->destroy(this->batch);
|
||||||
|
}
|
||||||
|
this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_SRETRY);
|
||||||
|
this->mutex->unlock(this->mutex);
|
||||||
|
}
|
||||||
|
else if (batch_type == PB_BATCH_SRETRY)
|
||||||
|
{
|
||||||
|
/* Restart the measurements */
|
||||||
|
charon->imcs->notify_connection_change(charon->imcs,
|
||||||
|
this->connection_id, TNC_CONNECTION_STATE_HANDSHAKE);
|
||||||
|
charon->imcs->begin_handshake(charon->imcs, this->connection_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
enumerator = batch->create_msg_enumerator(batch);
|
||||||
|
while (enumerator->enumerate(enumerator, &msg))
|
||||||
|
{
|
||||||
|
handle_message(this, msg);
|
||||||
|
empty = FALSE;
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
/* received an empty CLOSE Batch from PB-TNC Client */
|
||||||
|
if (this->is_server && batch_type == PB_BATCH_CLOSE && empty)
|
||||||
|
{
|
||||||
|
batch->destroy(batch);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->is_server)
|
if (this->is_server)
|
||||||
{
|
{
|
||||||
charon->imvs->batch_ending(charon->imvs, this->connection_id);
|
charon->imvs->batch_ending(charon->imvs, this->connection_id);
|
||||||
@@ -308,7 +337,10 @@ METHOD(tls_t, process, status_t,
|
|||||||
{
|
{
|
||||||
charon->imcs->batch_ending(charon->imcs, this->connection_id);
|
charon->imcs->batch_ending(charon->imcs, this->connection_id);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
case FAILED:
|
case FAILED:
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
if (this->batch)
|
if (this->batch)
|
||||||
@@ -319,7 +351,7 @@ METHOD(tls_t, process, status_t,
|
|||||||
}
|
}
|
||||||
this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CLOSE);
|
this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CLOSE);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
/* fall through */
|
/* fall through to add error messages to outbound batch */
|
||||||
case VERIFY_ERROR:
|
case VERIFY_ERROR:
|
||||||
enumerator = batch->create_error_enumerator(batch);
|
enumerator = batch->create_error_enumerator(batch);
|
||||||
while (enumerator->enumerate(enumerator, &msg))
|
while (enumerator->enumerate(enumerator, &msg))
|
||||||
@@ -329,6 +361,8 @@ METHOD(tls_t, process, status_t,
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -340,6 +374,8 @@ METHOD(tls_t, process, status_t,
|
|||||||
METHOD(tls_t, build, status_t,
|
METHOD(tls_t, build, status_t,
|
||||||
private_tnccs_20_t *this, void *buf, size_t *buflen, size_t *msglen)
|
private_tnccs_20_t *this, void *buf, size_t *buflen, size_t *msglen)
|
||||||
{
|
{
|
||||||
|
status_t status;
|
||||||
|
|
||||||
if (!this->is_server && !this->connection_id)
|
if (!this->is_server && !this->connection_id)
|
||||||
{
|
{
|
||||||
pb_tnc_message_t *msg;
|
pb_tnc_message_t *msg;
|
||||||
@@ -369,13 +405,24 @@ METHOD(tls_t, build, status_t,
|
|||||||
charon->imcs->begin_handshake(charon->imcs, this->connection_id);
|
charon->imcs->begin_handshake(charon->imcs, this->connection_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Do not allow any asynchronous IMCs or IMVs to add additional messages */
|
||||||
|
this->mutex->lock(this->mutex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if the DECIDED state has been reached, close down the TNCCS connection
|
||||||
|
* by sending an empty CLOSE batch unless a CRETRY batch is under way
|
||||||
|
*/
|
||||||
|
if (this->state_machine->get_state(this->state_machine) == PB_STATE_DECIDED &&
|
||||||
|
!this->batch)
|
||||||
|
{
|
||||||
|
this->batch = pb_tnc_batch_create(this->is_server, PB_BATCH_CLOSE);
|
||||||
|
}
|
||||||
|
|
||||||
if (this->batch)
|
if (this->batch)
|
||||||
{
|
{
|
||||||
pb_tnc_batch_type_t batch_type;
|
pb_tnc_batch_type_t batch_type;
|
||||||
status_t status;
|
|
||||||
chunk_t data;
|
chunk_t data;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
|
||||||
batch_type = this->batch->get_type(this->batch);
|
batch_type = this->batch->get_type(this->batch);
|
||||||
|
|
||||||
if (this->state_machine->send_batch(this->state_machine, batch_type))
|
if (this->state_machine->send_batch(this->state_machine, batch_type))
|
||||||
@@ -401,15 +448,15 @@ METHOD(tls_t, build, status_t,
|
|||||||
|
|
||||||
this->batch->destroy(this->batch);
|
this->batch->destroy(this->batch);
|
||||||
this->batch = NULL;
|
this->batch = NULL;
|
||||||
this->mutex->unlock(this->mutex);
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "no TNCCS Batch to send");
|
DBG1(DBG_TNC, "no TNCCS Batch to send");
|
||||||
return INVALID_STATE;
|
status = INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
this->mutex->unlock(this->mutex);
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(tls_t, is_server, bool,
|
METHOD(tls_t, is_server, bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user