Improved the WTP application to exit

This commit is contained in:
vemax78 2013-06-05 19:39:03 +02:00
parent 4d2292b7f0
commit 49bf2dc5c9
5 changed files with 30 additions and 19 deletions

View File

@ -59,6 +59,17 @@ long capwap_get_timeout(struct timeout_control* timeout, long* index) {
return delta;
}
void capwap_wait_timeout(struct timeout_control* timeout, unsigned long index) {
ASSERT(timeout != NULL);
ASSERT(index < CAPWAP_MAX_TIMER);
if (timeout->items[index].enable) {
for (capwap_update_timeout(timeout); timeout->items[index].delta > 0; capwap_update_timeout(timeout)) {
usleep((useconds_t)timeout->items[index].delta * 1000);
}
}
}
int capwap_is_enable_timeout(struct timeout_control* timeout, unsigned long index) {
ASSERT(timeout != NULL);
ASSERT(index < CAPWAP_MAX_TIMER);

View File

@ -87,6 +87,7 @@ long capwap_get_timeout(struct timeout_control* timeout, long* index);
void capwap_update_timeout(struct timeout_control* timeout);
void capwap_set_timeout(unsigned long value, struct timeout_control* timeout, unsigned long index);
void capwap_kill_timeout(struct timeout_control* timeout, unsigned long index);
void capwap_wait_timeout(struct timeout_control* timeout, unsigned long index);
void capwap_killall_timeout(struct timeout_control* timeout);
int capwap_is_enable_timeout(struct timeout_control* timeout, unsigned long index);
int capwap_is_timeout(struct timeout_control* timeout, unsigned long index);

View File

@ -35,7 +35,7 @@ static struct capwap_packet_rxmng* wtp_get_packet_rxmng(int isctrlmsg) {
}
/* */
static void wtp_free_packet_rxmng(int isctrlmsg) {
void wtp_free_packet_rxmng(int isctrlmsg) {
if (isctrlmsg && g_wtp.rxmngctrlpacket) {
capwap_packet_rxmng_free(g_wtp.rxmngctrlpacket);
g_wtp.rxmngctrlpacket = NULL;
@ -370,7 +370,7 @@ int wtp_dfa_running(void) {
signal(SIGINT, wtp_signal_handler);
signal(SIGTERM, wtp_signal_handler);
for (;;) {
while (action != WTP_DFA_EXIT) {
/* If request wait packet from AC */
isrecvpacket = 0;
if ((action == WTP_DFA_ACCEPT_PACKET) || (action == WTP_DFA_DROP_PACKET)) {
@ -378,7 +378,14 @@ int wtp_dfa_running(void) {
buffersize = CAPWAP_MAX_PACKET_SIZE;
index = capwap_recvfrom(fds, fdscount, buffer, &buffersize, &recvfromaddr, &recvtoaddr, &timeout);
if (!g_wtp.running) {
break;
capwap_logging_debug("Closing WTP, Teardown connection");
/* Manual teardown */
index = CAPWAP_RECV_ERROR_TIMEOUT;
wtp_teardown_connection(&timeout);
/* Wait RFC teardown timeout */
capwap_wait_timeout(&timeout, CAPWAP_TIMER_CONTROL_CONNECTION);
}
if (index >= 0) {
@ -547,21 +554,7 @@ int wtp_dfa_running(void) {
}
}
/* Free DTSL Control */
if (g_wtp.ctrldtls.enable) {
capwap_crypt_close(&g_wtp.ctrldtls);
capwap_crypt_freesession(&g_wtp.ctrldtls);
}
/* Free DTLS Data */
if (g_wtp.datadtls.enable) {
capwap_crypt_close(&g_wtp.datadtls);
capwap_crypt_freesession(&g_wtp.datadtls);
}
/* Free memory */
wtp_free_packet_rxmng(0);
wtp_free_packet_rxmng(1);
capwap_free(fds);
return result;

View File

@ -10,6 +10,7 @@
#define WTP_DFA_NO_PACKET 1
#define WTP_DFA_ACCEPT_PACKET 2
#define WTP_DFA_DROP_PACKET 3
#define WTP_DFA_EXIT 4
/* */ /* TODO da rifare */
struct wtp_discovery_response {
@ -26,6 +27,7 @@ int wtp_bio_send(struct capwap_dtls* dtls, char* buffer, int length, void* param
int wtp_teardown_connection(struct timeout_control* timeout);
/* */
void wtp_free_packet_rxmng(int isctrlmsg);
void wtp_free_reference_last_request(void);
void wtp_free_reference_last_response(void);

View File

@ -90,9 +90,13 @@ int wtp_dfa_state_dtlsteardown(struct capwap_parsed_packet* packet, struct timeo
/* */
wtp_free_reference_last_request();
wtp_free_reference_last_response();
wtp_free_packet_rxmng(0);
wtp_free_packet_rxmng(1);
/* */
if ((g_wtp.dfa.rfcFailedDTLSSessionCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry) || (g_wtp.dfa.rfcFailedDTLSAuthFailCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry)) {
/* */
if (!g_wtp.running) {
return WTP_DFA_EXIT;
} else if ((g_wtp.dfa.rfcFailedDTLSSessionCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry) || (g_wtp.dfa.rfcFailedDTLSAuthFailCount >= g_wtp.dfa.rfcMaxFailedDTLSSessionRetry)) {
wtp_dfa_change_state(CAPWAP_DTLS_TEARDOWN_TO_SULKING_STATE);
} else {
wtp_dfa_change_state(CAPWAP_DTLS_TEARDOWN_TO_IDLE_STATE);