Improve memory administration for tx/rx packet manager

This commit is contained in:
vemax78
2013-05-27 21:33:23 +02:00
parent 9157cc278b
commit 6c55b4d71f
126 changed files with 5383 additions and 7894 deletions

View File

@ -4,57 +4,48 @@
#include "wtp_dfa.h"
/* */
static unsigned long wtp_datacheck_ac(struct capwap_element_changestateevent_response* changestateresponse) {
static unsigned long wtp_datacheck_ac(struct capwap_parsed_packet* packet) {
/* TODO: gestione richiesta */
return CAPWAP_DATA_CHECK_TO_RUN_STATE;
}
/* */
int wtp_dfa_state_datacheck(struct capwap_packet* packet, struct timeout_control* timeout) {
int wtp_dfa_state_datacheck(struct capwap_parsed_packet* packet, struct timeout_control* timeout) {
int status = WTP_DFA_ACCEPT_PACKET;
ASSERT(timeout != NULL);
if (packet) {
if (!capwap_compare_ip(&g_wtp.acctrladdress, &packet->remoteaddr)) {
struct capwap_build_packet* buildpacket;
if (!capwap_compare_ip(&g_wtp.acctrladdress, &packet->connection->remoteaddr)) {
unsigned short binding;
/* Parsing packet */
buildpacket = capwap_rx_packet_create((void*)packet->header, packet->packetsize, packet->socket.isctrlsocket);
if (buildpacket) {
if (!capwap_build_packet_validate(buildpacket, NULL)) {
unsigned short binding;
/* */
binding = GET_WBID_HEADER(&buildpacket->header);
if ((binding == g_wtp.binding) && (ntohl(buildpacket->ctrlmsg.type) == CAPWAP_CHANGE_STATE_EVENT_RESPONSE) && ((g_wtp.localseqnumber - 1) == buildpacket->ctrlmsg.seq)) {
struct capwap_element_changestateevent_response changestateresponse;
/* Valid packet, free request packet */
wtp_free_reference_last_request();
/* Configuration status response info */
capwap_init_element_changestateevent_response(&changestateresponse, binding);
/* Parsing elements list */
if (capwap_parsing_element_changestateevent_response(&changestateresponse, buildpacket->elementslist->first)) {
wtp_dfa_change_state(wtp_datacheck_ac(&changestateresponse));
status = WTP_DFA_NO_PACKET;
/* */
binding = GET_WBID_HEADER(packet->rxmngpacket->header);
if (packet->rxmngpacket->isctrlpacket) {
if (binding == g_wtp.binding) {
if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CHANGE_STATE_EVENT_RESPONSE) {
if ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq) {
if (packet->rxmngpacket->packetlength > 0) {
int a = packet->rxmngpacket->packetlength;
a++;
}
}
/* Free join response */
capwap_free_element_changestateevent_response(&changestateresponse, binding);
}
}
}
/* Free */
capwap_build_packet_free(buildpacket);
if (packet->rxmngpacket->isctrlpacket && (binding == g_wtp.binding) && (packet->rxmngpacket->ctrlmsg.type == CAPWAP_CHANGE_STATE_EVENT_RESPONSE) && ((g_wtp.localseqnumber - 1) == packet->rxmngpacket->ctrlmsg.seq)) {
/* Valid packet, free request packet */
wtp_free_reference_last_request();
/* Parsing response values */
wtp_dfa_change_state(wtp_datacheck_ac(packet));
status = WTP_DFA_NO_PACKET;
}
}
} else {
int i;
/* No change state response received */
g_wtp.dfa.rfcRetransmitCount++;
if (g_wtp.dfa.rfcRetransmitCount >= g_wtp.dfa.rfcMaxRetransmit) {
@ -64,16 +55,10 @@ int wtp_dfa_state_datacheck(struct capwap_packet* packet, struct timeout_control
status = WTP_DFA_NO_PACKET;
} else {
/* Retransmit change state request */
for (i = 0; i < g_wtp.requestfragmentpacket->count; i++) {
struct capwap_packet* txpacket = (struct capwap_packet*)capwap_array_get_item_pointer(g_wtp.requestfragmentpacket, i);
ASSERT(txpacket != NULL);
if (!capwap_crypt_sendto(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], txpacket->header, txpacket->packetsize, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
capwap_logging_debug("Warning: error to send change state request packet");
break;
}
if (!capwap_crypt_sendto_fragmentpacket(&g_wtp.ctrldtls, g_wtp.acctrlsock.socket[g_wtp.acctrlsock.type], g_wtp.requestfragmentpacket, &g_wtp.wtpctrladdress, &g_wtp.acctrladdress)) {
capwap_logging_debug("Warning: error to send change state request packet");
}
/* Update timeout */
capwap_set_timeout(g_wtp.dfa.rfcRetransmitInterval, timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
}
@ -83,12 +68,12 @@ int wtp_dfa_state_datacheck(struct capwap_packet* packet, struct timeout_control
}
/* */
int wtp_dfa_state_datacheck_to_run(struct capwap_packet* packet, struct timeout_control* timeout) {
int result;
int wtp_dfa_state_datacheck_to_run(struct capwap_parsed_packet* packet, struct timeout_control* timeout) {
struct capwap_list* txfragpacket;
struct capwap_header_data capwapheader;
struct capwap_packet_txmng* txmngpacket;
int status = WTP_DFA_ACCEPT_PACKET;
struct capwap_build_packet* buildpacket;
capwap_fragment_packet_array* txfragpacket;
ASSERT(timeout != NULL);
ASSERT(packet == NULL);
@ -112,52 +97,47 @@ int wtp_dfa_state_datacheck_to_run(struct capwap_packet* packet, struct timeout_
return WTP_DFA_NO_PACKET;
}
}
/* Build packet */
buildpacket = capwap_tx_packet_create(CAPWAP_RADIOID_NONE, CAPWAP_WIRELESS_BINDING_NONE);
buildpacket->isctrlmsg = 0;
/* */
SET_FLAG_K_HEADER(&buildpacket->header, 1);
capwap_build_packet_add_message_element(buildpacket, CAPWAP_CREATE_SESSIONID_ELEMENT(&g_wtp.sessionid));
capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, g_wtp.binding);
capwap_header_set_keepalive_flag(&capwapheader, 1);
txmngpacket = capwap_packet_txmng_create_data_message(&capwapheader, g_wtp.mtu); /* CAPWAP_DONT_FRAGMENT */
txfragpacket = capwap_array_create(sizeof(struct capwap_packet), 0);
result = capwap_fragment_build_packet(buildpacket, txfragpacket, CAPWAP_DONT_FRAGMENT, 0);
if (!result) {
struct capwap_packet* txpacket;
ASSERT(txfragpacket->count == 1);
txpacket = (struct capwap_packet*)capwap_array_get_item_pointer(txfragpacket, 0);
ASSERT(txpacket != NULL);
if (!capwap_crypt_sendto(&g_wtp.datadtls, g_wtp.acdatasock.socket[g_wtp.acdatasock.type], txpacket->header, txpacket->packetsize, &g_wtp.wtpdataaddress, &g_wtp.acdataaddress)) {
/* Add message element */
capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_SESSIONID, &g_wtp.sessionid);
/* Data keepalive complete, get fragment packets into local list */
txfragpacket = capwap_list_create();
capwap_packet_txmng_get_fragment_packets(txmngpacket, txfragpacket, 0);
if (txfragpacket->count == 1) {
/* Send Data keepalive to AC */
if (capwap_crypt_sendto_fragmentpacket(&g_wtp.datadtls, g_wtp.acdatasock.socket[g_wtp.acdatasock.type], txfragpacket, &g_wtp.wtpdataaddress, &g_wtp.acdataaddress)) {
capwap_kill_timeout(timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
capwap_set_timeout(g_wtp.dfa.rfcEchoInterval, timeout, CAPWAP_TIMER_CONTROL_ECHO);
capwap_set_timeout(g_wtp.dfa.rfcDataChannelDeadInterval, timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
wtp_dfa_change_state(CAPWAP_RUN_STATE);
} else {
/* Error to send packets */
capwap_logging_debug("Warning: error to send data channel keepalive packet");
result = -1;
wtp_dfa_change_state(CAPWAP_DATA_CHECK_TO_DTLS_TEARDOWN_STATE);
status = WTP_DFA_NO_PACKET;
}
}
capwap_fragment_free(txfragpacket);
capwap_array_free(txfragpacket);
capwap_build_packet_free(buildpacket);
/* Send Configuration Status request to AC */
if (!result) {
capwap_kill_timeout(timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
capwap_set_timeout(g_wtp.dfa.rfcEchoInterval, timeout, CAPWAP_TIMER_CONTROL_ECHO);
capwap_set_timeout(g_wtp.dfa.rfcDataChannelDeadInterval, timeout, CAPWAP_TIMER_DATA_KEEPALIVEDEAD);
wtp_dfa_change_state(CAPWAP_RUN_STATE);
} else {
capwap_logging_debug("Warning: error to send data channel keepalive packet, fragment packet");
wtp_dfa_change_state(CAPWAP_DATA_CHECK_TO_DTLS_TEARDOWN_STATE);
status = WTP_DFA_NO_PACKET;
}
/* Free packets manager */
capwap_list_free(txfragpacket);
capwap_packet_txmng_free(txmngpacket);
/* */
return status;
}
/* */
int wtp_dfa_state_datacheck_to_dtlsteardown(struct capwap_packet* packet, struct timeout_control* timeout) {
int wtp_dfa_state_datacheck_to_dtlsteardown(struct capwap_parsed_packet* packet, struct timeout_control* timeout) {
ASSERT(packet == NULL);
ASSERT(timeout != NULL);