compile fixes
This commit is contained in:
1 parent
1947810cb0
commit
8502451ec7
11 files changed
+43
-254
No files matched your search
@@ -282,6 +282,10 @@ static int parse_global(const char *key, const char *value, struct global_config
|
||||
global->keepalive_timeout = atoi(value);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "keepalive_interval") == 0) {
|
||||
global->keepalive_interval = atoi(value);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(key, "control_ip") == 0) {
|
||||
// Store for later processing with control_port
|
||||
return 0; // We'll handle this when we see control_port
|
||||
|
||||
@@ -78,6 +78,7 @@ struct global_config {
|
||||
|
||||
int tun_test_mode; // test mode: 1 = don't open real TUN, queues only
|
||||
int keepalive_timeout; // keepalive timeout in ms (default: 2000)
|
||||
int keepalive_interval; // keepalive interval in ms (default: 200)
|
||||
};
|
||||
|
||||
struct utun_config {
|
||||
|
||||
+7
-12
@@ -236,20 +236,18 @@ void control_server_shutdown(struct control_server* server) {
|
||||
while (server->clients) {
|
||||
close_client(server, server->clients);
|
||||
}
|
||||
|
||||
/* Close listening socket */
|
||||
|
||||
#ifdef _WIN32
|
||||
if (server->listen_fd != INVALID_SOCKET) {
|
||||
uasync_remove_socket_t(server->ua, server->listen_fd);
|
||||
server->listen_socket_id = NULL;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (server->listen_fd != INVALID_SOCKET) {
|
||||
closesocket(server->listen_fd);
|
||||
server->listen_fd = INVALID_SOCKET;
|
||||
}
|
||||
#else
|
||||
if (server->listen_fd >= 0) {
|
||||
uasync_remove_socket_t(server->ua, server->listen_fd);
|
||||
server->listen_socket_id = NULL;
|
||||
close(server->listen_fd);
|
||||
server->listen_fd = -1;
|
||||
}
|
||||
@@ -506,19 +504,16 @@ static void close_client(struct control_server* server, struct control_client* c
|
||||
(unsigned long long)get_timestamp_ms());
|
||||
fflush(server->log_file);
|
||||
}
|
||||
|
||||
/* Remove from uasync */
|
||||
if (client->fd != INVALID_SOCKET) {
|
||||
uasync_remove_socket_t(server->ua, client->fd);
|
||||
}
|
||||
|
||||
|
||||
/* Close socket */
|
||||
#ifdef _WIN32
|
||||
if (client->fd != INVALID_SOCKET) {
|
||||
uasync_remove_socket_t(server->ua, client->fd);
|
||||
closesocket(client->fd);
|
||||
}
|
||||
#else
|
||||
if (client->fd >= 0) {
|
||||
uasync_remove_socket_t(server->ua, client->fd);
|
||||
close(client->fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ int etcp_bind(struct UTUN_INSTANCE* inst, uint8_t id, etcp_recv_fn callback);
|
||||
int etcp_unbind(struct UTUN_INSTANCE* inst, uint8_t id);
|
||||
|
||||
/**
|
||||
* @brief Коллбэк для очередей output ll_queue normalizer
|
||||
* @brief Внутренняя функция etcp: Коллбэк для очередей output ll_queue normalizer
|
||||
*
|
||||
* Собирает пакеты из всех подключений и отправляет в bind->cbk
|
||||
* по ID (первый байт кодограммы).
|
||||
|
||||
+25
-40
@@ -33,7 +33,7 @@ static void packet_dump(const char* prefix, const uint8_t* data, size_t len, str
|
||||
log_dump(prefix, data, len);
|
||||
}
|
||||
|
||||
static void etcp_link_send_init(struct ETCP_LINK* link);
|
||||
static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset);
|
||||
static int etcp_link_send_reset(struct ETCP_LINK* link);
|
||||
static void etcp_link_init_timer_cbk(void* arg);
|
||||
static void etcp_link_send_keepalive(struct ETCP_LINK* link);
|
||||
@@ -42,7 +42,7 @@ static void keepalive_timer_cb(void* arg);
|
||||
#define INIT_TIMEOUT_INITIAL 500
|
||||
#define INIT_TIMEOUT_MAX 50000
|
||||
|
||||
static void etcp_link_send_init_internal(struct ETCP_LINK* link, uint8_t reset) {
|
||||
static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "etcp_link_send_init link=%p, is_server=%d, reset=%d", link, link ? link->is_server : -1, reset);
|
||||
if (!link || !link->etcp || !link->etcp->instance) return;
|
||||
@@ -111,23 +111,13 @@ static void etcp_link_send_init_internal(struct ETCP_LINK* link, uint8_t reset)
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for backward compatibility - sends init WITH reset (0x02)
|
||||
static void etcp_link_send_init(struct ETCP_LINK* link) {
|
||||
etcp_link_send_init_internal(link, 1);
|
||||
}
|
||||
|
||||
// Send init WITHOUT reset (0x04) - for link recovery
|
||||
static void etcp_link_send_channel_init(struct ETCP_LINK* link) {
|
||||
etcp_link_send_init_internal(link, 0);
|
||||
}
|
||||
|
||||
static void etcp_link_init_timer_cbk(void* arg) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
struct ETCP_LINK* link = (struct ETCP_LINK*)arg;
|
||||
if (!link || link->initialized || link->is_server != 0) return;
|
||||
|
||||
link->init_timer = NULL;
|
||||
etcp_link_send_init(link);
|
||||
etcp_link_send_init(link,1);
|
||||
}
|
||||
|
||||
// Send empty keepalive packet (only timestamp, no sections)
|
||||
@@ -169,24 +159,19 @@ static int etcp_all_links_down(struct ETCP_CONN* etcp) {
|
||||
}
|
||||
|
||||
// Start link recovery process - send CHANNEL_INIT (0x04) on all links
|
||||
static void etcp_start_link_recovery(struct ETCP_CONN* etcp) {
|
||||
if (!etcp) return;
|
||||
static void etcp_start_link_recovery(struct ETCP_LINK* link) {
|
||||
if (!link) return;
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Starting link recovery - all links are down",
|
||||
etcp->log_name ? etcp->log_name : "????→????");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Starting link recovery - all links are down", link->etcp->log_name ? link->etcp->log_name : "????→????");
|
||||
|
||||
struct ETCP_LINK* link = etcp->links;
|
||||
while (link) {
|
||||
if (link->is_server == 0) { // Only client links
|
||||
// Reset link state for recovery
|
||||
link->initialized = 0;
|
||||
// Send CHANNEL_INIT (0x04) without reset
|
||||
etcp_link_send_channel_init(link);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Sent CHANNEL_INIT on link %p for recovery",
|
||||
etcp->log_name, link);
|
||||
}
|
||||
link = link->next;
|
||||
struct ETCP_CONN* etcp = link->etcp;
|
||||
if (link->is_server == 0) { // Only client links
|
||||
// Send CHANNEL_INIT (0x04) without reset
|
||||
etcp_link_send_init(link, 0);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Sent CHANNEL_INIT on link %p for recovery",
|
||||
etcp->log_name, link);
|
||||
}
|
||||
link = link->next;
|
||||
}
|
||||
|
||||
// Cancel init_timer for all links of an ETCP_CONN
|
||||
@@ -215,10 +200,10 @@ static void keepalive_timer_cb(void* arg) {
|
||||
|
||||
// Check if all links are down and start recovery if needed (client only)
|
||||
if (link->is_server == 0 && etcp_all_links_down(link->etcp)) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "[%s] All links are down, starting recovery",
|
||||
link->etcp->log_name);
|
||||
etcp_start_link_recovery(link->etcp);
|
||||
// Don't restart keepalive timer during recovery
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "[%s] All links are down, starting recovery", link->etcp->log_name);
|
||||
etcp_start_link_recovery(link);
|
||||
if (link->recovery_interval==0) link->recovery_interval=link->keepalive_interval*10;
|
||||
link->keepalive_timer = uasync_set_timeout(link->etcp->instance->ua, link->recovery_interval, link, keepalive_timer_cb);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,8 +232,7 @@ static void keepalive_timer_cb(void* arg) {
|
||||
if (link->recv_keepalive != 1) {
|
||||
link->recv_keepalive = 1; // up
|
||||
// loadbalancer_link_ready(link);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Link %p (local_id=%d) recv status changed to UP",
|
||||
link->etcp->log_name, link, link->local_link_id);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Link %p (local_id=%d) recv status changed to UP", link->etcp->log_name, link, link->local_link_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,8 +240,8 @@ static void keepalive_timer_cb(void* arg) {
|
||||
if (!link->pkt_sent_since_keepalive) {
|
||||
etcp_link_send_keepalive(link);
|
||||
} else {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Keepalive skipped - packet sent since last tick",
|
||||
link->etcp->log_name);
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Keepalive skipped - packet sent since last tick", link->etcp->log_name);
|
||||
link->recovery_interval=0;
|
||||
}
|
||||
|
||||
// Reset flag for next interval
|
||||
@@ -567,7 +551,6 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
link->etcp = etcp;
|
||||
link->is_server = is_server;
|
||||
link->mtu = 1500;
|
||||
link->keepalive_interval = 30;
|
||||
link->initialized = 0;
|
||||
link->init_timer = NULL;
|
||||
link->init_timeout = 0;
|
||||
@@ -577,8 +560,10 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
// Initialize keepalive timeout from global config
|
||||
if (etcp->instance && etcp->instance->config) {
|
||||
link->keepalive_timeout = etcp->instance->config->global.keepalive_timeout;
|
||||
link->keepalive_interval = etcp->instance->config->global.keepalive_interval;
|
||||
} else {
|
||||
link->keepalive_timeout = 2000; // Default 2 seconds
|
||||
link->keepalive_interval = 200; // Default 0.2 s
|
||||
}
|
||||
|
||||
// Выделяем свободный local_link_id
|
||||
@@ -604,7 +589,7 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
|
||||
if (is_server == 0) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "etcp_link_new: client link, calling etcp_link_send_init");
|
||||
etcp_link_send_init(link);
|
||||
etcp_link_send_init(link,1);
|
||||
}
|
||||
|
||||
return link;
|
||||
@@ -806,7 +791,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
}
|
||||
|
||||
if (link!=NULL && link->etcp!=NULL && link->etcp->crypto_ctx.session_ready) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Decrypt start (normal)");
|
||||
// DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Decrypt start (normal)");
|
||||
if (!sc_decrypt(&link->etcp->crypto_ctx, data, recv_len, (uint8_t*)&pkt->timestamp, &pkt_len)) {
|
||||
// Normal decryption succeeded - process packet normally
|
||||
goto process_decrypted;
|
||||
@@ -992,7 +977,7 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
return;
|
||||
|
||||
process_decrypted:
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Decrypt end");
|
||||
// DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Decrypt end");
|
||||
if (pkt_len<3) { errorcode=46; DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "etcp_connections_read_callback: decrypted packet too small, size=%zu", pkt_len); goto ec_fr; }
|
||||
pkt->data_len=pkt_len-3;
|
||||
pkt->noencrypt_len=0;
|
||||
|
||||
@@ -58,7 +58,8 @@ struct ETCP_LINK {
|
||||
|
||||
// Параметры соединения
|
||||
uint16_t mtu; // MTU удаленного узла
|
||||
uint16_t keepalive_interval; // Keepalive интервал
|
||||
uint16_t keepalive_interval; // Keepalive интервал (x1ms)
|
||||
uint32_t recovery_interval; // recovery интервал (x0.1ms)
|
||||
uint8_t is_server; // инициирует подключение клиент
|
||||
uint8_t initialized; // Флаг инициализации (1=подтверждено или получен request)
|
||||
uint8_t local_link_id; // id моего линка
|
||||
|
||||
Reference in new issue
Block a user