diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2012-07-12 20:01:32 +0200 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2012-07-12 21:26:18 +0200 |
commit | 968c83cdebc9e24e75e02069feda9d745c03bf4b (patch) | |
tree | 944297be41719208df709b97aad00be2af02d136 /src/libimcv/imc | |
parent | c5d2e61802c86c8649f703ae22a2dd3c83074e49 (diff) | |
download | strongswan-968c83cdebc9e24e75e02069feda9d745c03bf4b.tar.bz2 strongswan-968c83cdebc9e24e75e02069feda9d745c03bf4b.tar.xz |
restrict PA-TNC messages to maximum size
Diffstat (limited to 'src/libimcv/imc')
-rw-r--r-- | src/libimcv/imc/imc_agent.c | 41 | ||||
-rw-r--r-- | src/libimcv/imc/imc_state.h | 14 |
2 files changed, 43 insertions, 12 deletions
diff --git a/src/libimcv/imc/imc_agent.c b/src/libimcv/imc/imc_agent.c index 2d181c3c2..b372c4c57 100644 --- a/src/libimcv/imc/imc_agent.c +++ b/src/libimcv/imc/imc_agent.c @@ -48,11 +48,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 */ TNC_IMCID id; @@ -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(), diff --git a/src/libimcv/imc/imc_state.h b/src/libimcv/imc/imc_state.h index f1b0358c9..0e46ad51a 100644 --- a/src/libimcv/imc/imc_state.h +++ b/src/libimcv/imc/imc_state.h @@ -64,6 +64,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 * * @param new_state new connection state |