|
|
|
@ -24,7 +24,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg); |
|
|
|
static void etcp_link_remove_from_connections(struct ETCP_SOCKET* conn, struct ETCP_LINK* link); |
|
|
|
static void etcp_link_remove_from_connections(struct ETCP_SOCKET* conn, struct ETCP_LINK* link); |
|
|
|
|
|
|
|
|
|
|
|
static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset); |
|
|
|
static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset); |
|
|
|
static int etcp_link_send_reset(struct ETCP_LINK* link); |
|
|
|
//static int etcp_link_send_reset(struct ETCP_LINK* link);
|
|
|
|
static void etcp_link_init_timer_cbk(void* arg); |
|
|
|
static void etcp_link_init_timer_cbk(void* arg); |
|
|
|
static void etcp_link_send_keepalive(struct ETCP_LINK* link); |
|
|
|
static void etcp_link_send_keepalive(struct ETCP_LINK* link); |
|
|
|
static void keepalive_timer_cb(void* arg); |
|
|
|
static void keepalive_timer_cb(void* arg); |
|
|
|
@ -185,22 +185,6 @@ static int etcp_all_links_down(struct ETCP_CONN* etcp) { |
|
|
|
return 1; // All links are down
|
|
|
|
return 1; // All links are down
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Cancel init_timer for all links of an ETCP_CONN
|
|
|
|
|
|
|
|
static void etcp_cancel_all_init_timers(struct ETCP_CONN* etcp) { |
|
|
|
|
|
|
|
if (!etcp) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ETCP_LINK* link = etcp->links; |
|
|
|
|
|
|
|
while (link) { |
|
|
|
|
|
|
|
if (link->init_timer) { |
|
|
|
|
|
|
|
uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer); |
|
|
|
|
|
|
|
link->init_timer = NULL; |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Cancelled init_timer on link %p", |
|
|
|
|
|
|
|
etcp->log_name, link); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
link = link->next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Keepalive timer callback
|
|
|
|
// Keepalive timer callback
|
|
|
|
static void keepalive_timer_cb(void* arg) { |
|
|
|
static void keepalive_timer_cb(void* arg) { |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
@ -261,27 +245,6 @@ restart_timer: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int etcp_link_send_reset(struct ETCP_LINK* link) { |
|
|
|
|
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
|
|
|
|
if (!link) return -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ETCP_DGRAM* dgram = u_malloc(sizeof(struct ETCP_DGRAM) + 4); |
|
|
|
|
|
|
|
if (!dgram) { |
|
|
|
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "etcp_link_send_reset: malloc failed"); |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dgram->link = link; |
|
|
|
|
|
|
|
dgram->data_len = 1; |
|
|
|
|
|
|
|
dgram->noencrypt_len = 0; |
|
|
|
|
|
|
|
dgram->data[0] = 0x06; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "Sending RESET to link"); |
|
|
|
|
|
|
|
int ret = etcp_encrypt_send(dgram); |
|
|
|
|
|
|
|
u_free(dgram); |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t sockaddr_hash(struct sockaddr_storage* addr) { |
|
|
|
static uint32_t sockaddr_hash(struct sockaddr_storage* addr) { |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
socklen_t addr_len = (addr->ss_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); |
|
|
|
socklen_t addr_len = (addr->ss_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); |
|
|
|
@ -645,46 +608,6 @@ void etcp_link_close(struct ETCP_LINK* link) { |
|
|
|
u_free(link); |
|
|
|
u_free(link); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Reset link state (for INIT_RESPONSE with reset)
|
|
|
|
|
|
|
|
static void etcp_link_reset(struct ETCP_LINK* link) { |
|
|
|
|
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
|
|
|
|
if (!link) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Resetting link %p (local_id=%d)", |
|
|
|
|
|
|
|
link->etcp->log_name, link, link->local_link_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cancel all timers
|
|
|
|
|
|
|
|
if (link->init_timer) { |
|
|
|
|
|
|
|
uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer); |
|
|
|
|
|
|
|
link->init_timer = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (link->shaper_timer) { |
|
|
|
|
|
|
|
uasync_cancel_timeout(link->etcp->instance->ua, link->shaper_timer); |
|
|
|
|
|
|
|
link->shaper_timer = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reset state
|
|
|
|
|
|
|
|
link->initialized = 0; |
|
|
|
|
|
|
|
link->link_status = 0; |
|
|
|
|
|
|
|
link->recv_keepalive = 0; |
|
|
|
|
|
|
|
link->remote_keepalive = 0; |
|
|
|
|
|
|
|
link->init_retry_count = 0; |
|
|
|
|
|
|
|
link->init_timeout = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reset shaper state
|
|
|
|
|
|
|
|
link->shaper_load_time_tb = 0; |
|
|
|
|
|
|
|
link->shaper_sub_nanotime = 0; |
|
|
|
|
|
|
|
link->shaper_state = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reset counters
|
|
|
|
|
|
|
|
link->encrypt_errors = 0; |
|
|
|
|
|
|
|
link->decrypt_errors = 0; |
|
|
|
|
|
|
|
link->send_errors = 0; |
|
|
|
|
|
|
|
link->recv_errors = 0; |
|
|
|
|
|
|
|
link->total_encrypted = 0; |
|
|
|
|
|
|
|
link->total_decrypted = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int etcp_encrypt_send(struct ETCP_DGRAM* dgram) { |
|
|
|
int etcp_encrypt_send(struct ETCP_DGRAM* dgram) { |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, ""); |
|
|
|
|
|
|
|
|
|
|
|
@ -1019,9 +942,6 @@ process_decrypted: |
|
|
|
link->keepalive_recv_count++; |
|
|
|
link->keepalive_recv_count++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Cancel all init timers - link is alive, no need for recovery
|
|
|
|
|
|
|
|
etcp_cancel_all_init_timers(link->etcp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t offset = 0; |
|
|
|
size_t offset = 0; |
|
|
|
uint8_t code = pkt->data[offset++]; |
|
|
|
uint8_t code = pkt->data[offset++]; |
|
|
|
|
|
|
|
|
|
|
|
@ -1123,9 +1043,19 @@ process_decrypted: |
|
|
|
return; // INIT_RESPONSE is handled, no further processing needed
|
|
|
|
return; // INIT_RESPONSE is handled, no further processing needed
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (link->link_state == 2) {// из recovery получен нормальный пакет - восстанавливаем линк в нормальный режим
|
|
|
|
|
|
|
|
if (link->init_timer) {// cancel init timer
|
|
|
|
|
|
|
|
uasync_cancel_timeout(link->etcp->instance->ua, link->init_timer); |
|
|
|
|
|
|
|
link->init_timer = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
etcp_link_send_keepalive(link); // Start keepalive timer
|
|
|
|
|
|
|
|
link->link_state = 3; // connected
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// log_dump("RECV decrypted:", pkt->data, pkt->data_len, link);
|
|
|
|
// log_dump("RECV decrypted:", pkt->data, pkt->data_len, link);
|
|
|
|
|
|
|
|
|
|
|
|
etcp_conn_input(pkt); |
|
|
|
if (link->link_state == 3) etcp_conn_input(pkt); |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
ec_fr: |
|
|
|
ec_fr: |
|
|
|
|