restrict PA-TNC messages to maximum size

This commit is contained in:
Andreas Steffen
2012-07-12 21:26:18 +02:00
parent c5d2e61802
commit 968c83cdeb
15 changed files with 243 additions and 29 deletions
+29 -12
View File
@@ -47,11 +47,6 @@ struct private_imc_agent_t {
*/
TNC_MessageSubtype subtype;
/**
* Maximum PA-TNC Message size
*/
size_t max_msg_len;
/**
* ID of IMC as assigned by TNCC
*/
@@ -337,12 +332,31 @@ static char* get_str_attribute(private_imc_agent_t *this, TNC_ConnectionID id,
return NULL;
}
/**
* Read an UInt32 attribute
*/
static u_int32_t get_uint_attribute(private_imc_agent_t *this, TNC_ConnectionID id,
TNC_AttributeID attribute_id)
{
TNC_UInt32 len;
char buf[4];
if (this->get_attribute &&
this->get_attribute(this->id, id, attribute_id, 4, buf, &len) ==
TNC_RESULT_SUCCESS && len == 4)
{
return untoh32(buf);
}
return 0;
}
METHOD(imc_agent_t, create_state, TNC_Result,
private_imc_agent_t *this, imc_state_t *state)
{
TNC_ConnectionID conn_id;
char *tnccs_p = NULL, *tnccs_v = NULL, *t_p = NULL, *t_v = NULL;
bool has_long = FALSE, has_excl = FALSE, has_soh = FALSE;
u_int32_t max_msg_len;
conn_id = state->get_connection_id(state);
if (find_connection(this, conn_id))
@@ -361,14 +375,18 @@ METHOD(imc_agent_t, create_state, TNC_Result,
tnccs_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFTNCCS_VERSION);
t_p = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_PROTOCOL);
t_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_VERSION);
max_msg_len = get_uint_attribute(this, conn_id, TNC_ATTRIBUTEID_MAX_MESSAGE_SIZE);
state->set_flags(state, has_long, has_excl);
state->set_max_msg_len(state, max_msg_len);
DBG2(DBG_IMC, "IMC %u \"%s\" created a state for %s %s Connection ID %u: "
"%slong %sexcl %ssoh", this->id, this->name,
tnccs_p ? tnccs_p:"?", tnccs_v ? tnccs_v:"?", conn_id,
has_long ? "+":"-", has_excl ? "+":"-", has_soh ? "+":"-");
DBG2(DBG_IMC, " over %s %s with maximum PA-TNC msg size of %u bytes",
t_p ? t_p:"?", t_v ? t_v :"?", max_msg_len);
DBG2(DBG_IMC, "IMC %u \"%s\" created a state for Connection ID %u: "
"%s %s with %slong %sexcl %ssoh over %s %s",
this->id, this->name, conn_id, tnccs_p ? tnccs_p:"?",
tnccs_v ? tnccs_v:"?", has_long ? "+":"-", has_excl ? "+":"-",
has_soh ? "+":"-", t_p ? t_p:"?", t_v ? t_v :"?");
free(tnccs_p);
free(tnccs_v);
free(t_p);
@@ -478,7 +496,7 @@ METHOD(imc_agent_t, send_message, TNC_Result,
while (attr_list->get_count(attr_list))
{
pa_tnc_msg = pa_tnc_msg_create(this->max_msg_len);
pa_tnc_msg = pa_tnc_msg_create(state->get_max_msg_len(state));
enumerator = attr_list->create_enumerator(attr_list);
while (enumerator->enumerate(enumerator, &attr))
@@ -688,7 +706,6 @@ imc_agent_t *imc_agent_create(const char *name,
.name = name,
.vendor_id = vendor_id,
.subtype = subtype,
.max_msg_len = 65490,
.id = id,
.additional_ids = linked_list_create(),
.connections = linked_list_create(),
+14
View File
@@ -63,6 +63,20 @@ D attached to the state
*/
void (*set_flags)(imc_state_t *this, bool has_long, bool has_excl);
/**
* Set the maximum size of a PA-TNC message for this TNCCS connection
*
* @max_msg_len maximum size of a PA-TNC message
*/
void (*set_max_msg_len)(imc_state_t *this, u_int32_t max_msg_len);
/**
* Get the maximum size of a PA-TNC message for this TNCCS connection
*
* @return maximum size of a PA-TNC message
*/
u_int32_t (*get_max_msg_len)(imc_state_t *this);
/**
* Change the connection state
*
+28 -5
View File
@@ -355,12 +355,31 @@ static char* get_str_attribute(private_imv_agent_t *this, TNC_ConnectionID id,
return NULL;
}
/**
* Read an UInt32 attribute
*/
static u_int32_t get_uint_attribute(private_imv_agent_t *this, TNC_ConnectionID id,
TNC_AttributeID attribute_id)
{
TNC_UInt32 len;
char buf[4];
if (this->get_attribute &&
this->get_attribute(this->id, id, attribute_id, 4, buf, &len) ==
TNC_RESULT_SUCCESS && len == 4)
{
return untoh32(buf);
}
return 0;
}
METHOD(imv_agent_t, create_state, TNC_Result,
private_imv_agent_t *this, imv_state_t *state)
{
TNC_ConnectionID conn_id;
char *tnccs_p = NULL, *tnccs_v = NULL, *t_p = NULL, *t_v = NULL;
bool has_long = FALSE, has_excl = FALSE, has_soh = FALSE;
u_int32_t max_msg_len;
conn_id = state->get_connection_id(state);
if (find_connection(this, conn_id))
@@ -379,14 +398,18 @@ METHOD(imv_agent_t, create_state, TNC_Result,
tnccs_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFTNCCS_VERSION);
t_p = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_PROTOCOL);
t_v = get_str_attribute(this, conn_id, TNC_ATTRIBUTEID_IFT_VERSION);
max_msg_len = get_uint_attribute(this, conn_id, TNC_ATTRIBUTEID_MAX_MESSAGE_SIZE);
state->set_flags(state, has_long, has_excl);
state->set_max_msg_len(state, max_msg_len);
DBG2(DBG_IMV, "IMV %u \"%s\" created a state for %s %s Connection ID %u: "
"%slong %sexcl %ssoh", this->id, this->name,
tnccs_p ? tnccs_p:"?", tnccs_v ? tnccs_v:"?", conn_id,
has_long ? "+":"-", has_excl ? "+":"-", has_soh ? "+":"-");
DBG2(DBG_IMV, " over %s %s with maximum PA-TNC msg size of %u bytes",
t_p ? t_p:"?", t_v ? t_v :"?", max_msg_len);
DBG2(DBG_IMV, "IMV %u \"%s\" created a state for Connection ID %u: "
"%s %s with %slong %sexcl %ssoh over %s %s",
this->id, this->name, conn_id, tnccs_p ? tnccs_p:"?",
tnccs_v ? tnccs_v:"?", has_long ? "+":"-", has_excl ? "+":"-",
has_soh ? "+":"-", t_p ? t_p:"?", t_v ? t_v :"?");
free(tnccs_p);
free(tnccs_v);
free(t_p);
+14
View File
@@ -62,6 +62,20 @@ struct imv_state_t {
*/
void (*set_flags)(imv_state_t *this, bool has_long, bool has_excl);
/**
* Set the maximum size of a PA-TNC message for this TNCCS connection
*
* @max_msg_len maximum size of a PA-TNC message
*/
void (*set_max_msg_len)(imv_state_t *this, u_int32_t max_msg_len);
/**
* Get the maximum size of a PA-TNC message for this TNCCS connection
*
* @return maximum size of a PA-TNC message
*/
u_int32_t (*get_max_msg_len)(imv_state_t *this);
/**
* Change the connection state
*
@@ -48,6 +48,10 @@ struct private_imc_scanner_state_t {
*/
bool has_excl;
/**
* Maximum PA-TNC message size for this TNCCS connection
*/
u_int32_t max_msg_len;
};
METHOD(imc_state_t, get_connection_id, TNC_ConnectionID,
@@ -75,6 +79,18 @@ METHOD(imc_state_t, set_flags, void,
this->has_excl = has_excl;
}
METHOD(imc_state_t, set_max_msg_len, void,
private_imc_scanner_state_t *this, u_int32_t max_msg_len)
{
this->max_msg_len = max_msg_len;
}
METHOD(imc_state_t, get_max_msg_len, u_int32_t,
private_imc_scanner_state_t *this)
{
return this->max_msg_len;
}
METHOD(imc_state_t, change_state, void,
private_imc_scanner_state_t *this, TNC_ConnectionState new_state)
{
@@ -101,6 +117,8 @@ imc_state_t *imc_scanner_state_create(TNC_ConnectionID connection_id)
.has_long = _has_long,
.has_excl = _has_excl,
.set_flags = _set_flags,
.set_max_msg_len = _set_max_msg_len,
.get_max_msg_len = _get_max_msg_len,
.change_state = _change_state,
.destroy = _destroy,
},
@@ -49,6 +49,11 @@ struct private_imc_test_state_t {
*/
bool has_excl;
/**
* Maximum PA-TNC message size for this TNCCS connection
*/
u_int32_t max_msg_len;
/**
* Command to transmit to IMV
*/
@@ -96,6 +101,18 @@ METHOD(imc_state_t, set_flags, void,
this->has_excl = has_excl;
}
METHOD(imc_state_t, set_max_msg_len, void,
private_imc_test_state_t *this, u_int32_t max_msg_len)
{
this->max_msg_len = max_msg_len;
}
METHOD(imc_state_t, get_max_msg_len, u_int32_t,
private_imc_test_state_t *this)
{
return this->max_msg_len;
}
METHOD(imc_state_t, change_state, void,
private_imc_test_state_t *this, TNC_ConnectionState new_state)
{
@@ -169,6 +186,8 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
.has_long = _has_long,
.has_excl = _has_excl,
.set_flags = _set_flags,
.set_max_msg_len = _set_max_msg_len,
.get_max_msg_len = _get_max_msg_len,
.change_state = _change_state,
.destroy = _destroy,
},
@@ -49,6 +49,11 @@ struct private_imv_scanner_state_t {
*/
bool has_excl;
/**
* Maximum PA-TNC message size for this TNCCS connection
*/
u_int32_t max_msg_len;
/**
* IMV action recommendation
*/
@@ -115,6 +120,18 @@ METHOD(imv_state_t, set_flags, void,
this->has_excl = has_excl;
}
METHOD(imv_state_t, set_max_msg_len, void,
private_imv_scanner_state_t *this, u_int32_t max_msg_len)
{
this->max_msg_len = max_msg_len;
}
METHOD(imv_state_t, get_max_msg_len, u_int32_t,
private_imv_scanner_state_t *this)
{
return this->max_msg_len;
}
METHOD(imv_state_t, change_state, void,
private_imv_scanner_state_t *this, TNC_ConnectionState new_state)
{
@@ -223,6 +240,8 @@ imv_state_t *imv_scanner_state_create(TNC_ConnectionID connection_id)
.has_long = _has_long,
.has_excl = _has_excl,
.set_flags = _set_flags,
.set_max_msg_len = _set_max_msg_len,
.get_max_msg_len = _get_max_msg_len,
.change_state = _change_state,
.get_recommendation = _get_recommendation,
.set_recommendation = _set_recommendation,
@@ -50,6 +50,11 @@ struct private_imv_test_state_t {
*/
bool has_excl;
/**
* Maximum PA-TNC message size for this TNCCS connection
*/
u_int32_t max_msg_len;
/**
* IMV action recommendation
*/
@@ -122,6 +127,18 @@ METHOD(imv_state_t, set_flags, void,
this->has_excl = has_excl;
}
METHOD(imv_state_t, set_max_msg_len, void,
private_imv_test_state_t *this, u_int32_t max_msg_len)
{
this->max_msg_len = max_msg_len;
}
METHOD(imv_state_t, get_max_msg_len, u_int32_t,
private_imv_test_state_t *this)
{
return this->max_msg_len;
}
METHOD(imv_state_t, change_state, void,
private_imv_test_state_t *this, TNC_ConnectionState new_state)
{
@@ -274,6 +291,8 @@ imv_state_t *imv_test_state_create(TNC_ConnectionID connection_id)
.has_long = _has_long,
.has_excl = _has_excl,
.set_flags = _set_flags,
.set_max_msg_len = _set_max_msg_len,
.get_max_msg_len = _get_max_msg_len,
.change_state = _change_state,
.get_recommendation = _get_recommendation,
.set_recommendation = _set_recommendation,