logs
This commit is contained in:
1 parent
2f06979f17
commit
61d575f09b
6 files changed
+51
-90
No files matched your search
+18
-24
@@ -622,54 +622,48 @@ void print_config(const struct utun_config *cfg) {
|
||||
const struct global_config *g = &cfg->global;
|
||||
char ip_buffer[64];
|
||||
|
||||
printf("Global:\n");
|
||||
printf(" Private key: %s\n", g->my_private_key_hex);
|
||||
printf(" Public key: %s\n", g->my_public_key_hex);
|
||||
printf(" Node ID: %llx\n", (unsigned long long)g->my_node_id);
|
||||
printf(" TUN interface: %s\n", g->tun_ifname[0] ? g->tun_ifname : "auto");
|
||||
printf(" TUN IP: %s\n", ip_to_string(&g->tun_ip, ip_buffer, sizeof(ip_buffer)));
|
||||
printf(" MTU: %d\n", g->mtu);
|
||||
printf(" Keepalive timeout: %d ms\n", g->keepalive_timeout);
|
||||
printf(" TUN test mode: %s\n", g->tun_test_mode ? "enabled" : "disabled");
|
||||
printf(" Net debug: %d\n", g->net_debug);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Global: priv_key=%s, pub_key=%s, node_id=%llx, tun_if=%s, tun_ip=%s, mtu=%d, keepalive=%d, test_mode=%d, net_debug=%d",
|
||||
g->my_private_key_hex, g->my_public_key_hex,
|
||||
(unsigned long long)g->my_node_id,
|
||||
g->tun_ifname[0] ? g->tun_ifname : "auto",
|
||||
ip_to_string(&g->tun_ip, ip_buffer, sizeof(ip_buffer)),
|
||||
g->mtu, g->keepalive_timeout, g->tun_test_mode, g->net_debug);
|
||||
|
||||
printf("\nServers:\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Servers:");
|
||||
struct CFG_SERVER *s = cfg->servers;
|
||||
while (s) {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)&s->ip;
|
||||
printf(" %s: %s:%d (mark=%d, netif=%u, type=%u)\n",
|
||||
s->name, ip_to_str(&sin->sin_addr, AF_INET).str, ntohs(sin->sin_port),
|
||||
s->so_mark, s->netif_index, s->type);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: %s:%d (mark=%d, netif=%u, type=%u)",
|
||||
s->name, ip_to_str(&sin->sin_addr, AF_INET).str, ntohs(sin->sin_port),
|
||||
s->so_mark, s->netif_index, s->type);
|
||||
s = s->next;
|
||||
}
|
||||
|
||||
printf("\nClients:\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Clients:");
|
||||
struct CFG_CLIENT *c = cfg->clients;
|
||||
while (c) {
|
||||
printf(" %s:\n", c->name);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s: peer_key=%s, keepalive=%d", c->name, c->peer_public_key_hex, c->keepalive);
|
||||
struct CFG_CLIENT_LINK *link = c->links;
|
||||
int link_num = 1;
|
||||
while (link) {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)&link->remote_addr;
|
||||
printf(" Link %d: %s:%d (via %s)\n", link_num++, ip_to_str(&sin->sin_addr, AF_INET).str, ntohs(sin->sin_port), link->local_srv->name);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " Link: %s:%d (via %s)",
|
||||
ip_to_str(&sin->sin_addr, AF_INET).str, ntohs(sin->sin_port), link->local_srv->name);
|
||||
link = link->next;
|
||||
}
|
||||
printf(" Peer key: %s\n", c->peer_public_key_hex);
|
||||
printf(" Keepalive: %d\n", c->keepalive);
|
||||
c = c->next;
|
||||
}
|
||||
|
||||
printf("\nRoute Subnets:\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Route Subnets:");
|
||||
struct CFG_ROUTE_ENTRY *allowed = cfg->route_subnets;
|
||||
while (allowed) {
|
||||
printf(" %s/%d\n", ip_to_string(&allowed->ip, ip_buffer, sizeof(ip_buffer)), allowed->netmask);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s/%d", ip_to_string(&allowed->ip, ip_buffer, sizeof(ip_buffer)), allowed->netmask);
|
||||
allowed = allowed->next;
|
||||
}
|
||||
|
||||
printf("\nMy Subnets:\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "My Subnets:");
|
||||
struct CFG_ROUTE_ENTRY *my = cfg->my_subnets;
|
||||
while (my) {
|
||||
printf(" %s/%d\n", ip_to_string(&my->ip, ip_buffer, sizeof(ip_buffer)), my->netmask);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, " %s/%d", ip_to_string(&my->ip, ip_buffer, sizeof(ip_buffer)), my->netmask);
|
||||
my = my->next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,12 +682,10 @@ static void etcp_link_reset(struct ETCP_LINK* link) {
|
||||
|
||||
int etcp_encrypt_send(struct ETCP_DGRAM* dgram) {
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_CONNECTION, "");
|
||||
// DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "etcp_encrypt_send called, link=%p", dgram ? dgram->link : NULL);
|
||||
// printf("[ETCP DEBUG] etcp_encrypt_send: ENTERING FUNCTION\n");
|
||||
|
||||
if (!dgram || !dgram->link) return -1;
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "[%s] Send rk=%d lk=%d up=%d",
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "[%s] Send rk=%d lk=%d up=%d",
|
||||
dgram->link->etcp->log_name, dgram->link->recv_keepalive, dgram->link->remote_keepalive, dgram->link->link_status);
|
||||
|
||||
// Mark that packet was sent (for keepalive logic)
|
||||
@@ -764,8 +762,6 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
struct ETCP_SOCKET* e_sock = (struct ETCP_SOCKET*)arg;
|
||||
if (!e_sock) return;
|
||||
|
||||
// printf("[ETCP] Read callback triggered for fd=%d, socket=%p\n", fd, e_sock);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
uint8_t data[PACKET_DATA_SIZE];
|
||||
socklen_t addr_len=sizeof(addr);
|
||||
@@ -777,8 +773,6 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("[ETCP] Received packet: %zd bytes from address\n", recv_len);
|
||||
|
||||
// DUMP: Show received packet content
|
||||
if (debug_should_output(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_CRYPTO)) log_dump("RECV in:", data, recv_len); // link unknown at this point
|
||||
|
||||
@@ -788,7 +782,6 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
int errorcode=0;
|
||||
|
||||
struct ETCP_LINK* link=etcp_link_find_by_addr(e_sock, &addr);
|
||||
// printf("[ETCP DEBUG] Received packet, link=%p, recv_len=%zd\n", link, recv_len);
|
||||
|
||||
// Try normal decryption first if we have an established link with session keys
|
||||
// This is the common case for data packets and responses
|
||||
@@ -959,7 +952,6 @@ static void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "Sending INIT RESPONSE, link=%p, local_link_id=%d, remote_link_id=%d", link, link->local_link_id, link->remote_link_id);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[ETCP DEBUG] Send INIT RESPONSE");
|
||||
etcp_encrypt_send(pkt);
|
||||
// printf("[ETCP DEBUG] Send INIT RESPONSE ok\n");
|
||||
|
||||
memory_pool_free(e_sock->instance->pkt_pool, pkt);
|
||||
link->initialized = 1;// получен init request (server), считаем линк уже готовым к работе
|
||||
|
||||
+2
-2
@@ -155,7 +155,7 @@ static struct ROUTE_ARRAY* cache_lookup(uint32_t dest_ip) {
|
||||
g_route_cache.access_time[i] = current_time;
|
||||
char ip_str[16];
|
||||
ip_to_string(dest_ip, ip_str);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Cache hit for IP %s", ip_str);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ROUTING, "Cache hit for IP %s", ip_str);
|
||||
return g_route_cache.entries[i];
|
||||
}
|
||||
}
|
||||
@@ -538,7 +538,7 @@ struct ROUTE_ARRAY* route_table_lookup(struct ROUTE_TABLE *table, uint32_t dest_
|
||||
|
||||
char ip_str[16];
|
||||
ip_to_string(dest_ip, ip_str);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "No route found for destination IP %s", ip_str);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "No route found for destination IP %s", ip_str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -273,8 +273,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
// debug_set_level(DEBUG_LEVEL_INFO);
|
||||
// debug_set_categories(DEBUG_CATEGORY_ALL & ~DEBUG_CATEGORY_UASYNC & ~DEBUG_CATEGORY_TIMERS & ~DEBUG_CATEGORY_CRYPTO & ~DEBUG_CATEGORY_ETCP & ~DEBUG_CATEGORY_CONNECTION); // Enable all except uasync
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL & ~DEBUG_CATEGORY_UASYNC);// & ~DEBUG_CATEGORY_TIMERS
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL & ~DEBUG_CATEGORY_UASYNC & ~DEBUG_CATEGORY_TIMERS);//
|
||||
debug_enable_function_name(1);
|
||||
|
||||
if (args.debug_config) {
|
||||
@@ -304,9 +305,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (!is_admin) {
|
||||
fprintf(stderr, "FATAL ERROR: Administrator privileges required\n");
|
||||
fprintf(stderr, "Please run utun.exe as Administrator (right-click -> Run as administrator)\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Administrator privileges required");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Administrator privileges required. Please run utun.exe as Administrator");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -325,8 +324,7 @@ int main(int argc, char *argv[]) {
|
||||
#ifdef _WIN32
|
||||
// Check for wintun.dll before enabling TUN
|
||||
if (access("wintun.dll", F_OK) != 0) {
|
||||
fprintf(stderr, "FATAL ERROR: wintun.dll not found in current directory\n");
|
||||
fprintf(stderr, "Please ensure wintun.dll is located in the same directory as utun.exe\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "wintun.dll not found. Please ensure wintun.dll is in the same directory as utun.exe");
|
||||
uasync_destroy(ua, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
+25
-49
@@ -338,23 +338,18 @@ int utun_instance_init(struct UTUN_INSTANCE *instance) {
|
||||
// Note: TUN socket is already registered in tun_init()
|
||||
|
||||
// Initialize connections
|
||||
// Добавляем прямой вывод для отладки проблемы double free
|
||||
fprintf(stderr, "DEBUG: utun_instance_init() calling init_connections() for instance %p\n", instance);
|
||||
fflush(stderr);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "utun_instance_init() calling init_connections() for instance %p", instance);
|
||||
|
||||
int conn_result = init_connections(instance);
|
||||
|
||||
fprintf(stderr, "DEBUG: init_connections() returned: %d\n", conn_result);
|
||||
fflush(stderr);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "init_connections() returned: %d", conn_result);
|
||||
|
||||
if (conn_result < 0) {
|
||||
fprintf(stderr, "DEBUG: Failed to initialize connections, returning error\n");
|
||||
fflush(stderr);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize connections, error=%d", conn_result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "DEBUG: Connections initialized successfully, count=%d\n", instance->connections_count);
|
||||
fflush(stderr);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "Connections initialized successfully, count=%d", instance->connections_count);
|
||||
|
||||
// Initialize control server if configured
|
||||
if (instance->config->global.control_sock.ss_family != 0) {
|
||||
@@ -416,54 +411,35 @@ void utun_instance_diagnose_leaks(struct UTUN_INSTANCE *instance, const char *ph
|
||||
conn = conn->next;
|
||||
}
|
||||
|
||||
printf("\n🔍 [UTUN_INSTANCE LEAK DIAGNOSIS] Phase: %s\n", phase);
|
||||
printf(" Instance: %p\n", instance);
|
||||
printf(" Node ID: %llu\n", (unsigned long long)instance->node_id);
|
||||
printf(" UA instance: %p\n", instance->ua);
|
||||
printf(" Running: %d\n", instance->running);
|
||||
|
||||
printf("\n📊 STRUCTURE COUNTS:\n");
|
||||
printf(" ETCP Sockets: %d active\n", report.etcp_sockets_count);
|
||||
printf(" ETCP Connections: %d active\n", report.etcp_connections_count);
|
||||
printf(" ETCP Links: %d total\n", report.etcp_links_count);
|
||||
|
||||
printf("\n🔧 RESOURCE STATUS:\n");
|
||||
printf(" Memory Pool: %s\n", instance->pkt_pool ? "ALLOCATED" : "NULL");
|
||||
printf(" TUN Interface: %s\n", instance->tun ? instance->tun->ifname : "NULL");
|
||||
printf(" TUN FD: %d\n", instance->tun ? instance->tun->fd : -1);
|
||||
printf(" Connections list: %p\n", instance->connections);
|
||||
printf(" ETCP Sockets list: %p\n", instance->etcp_sockets);
|
||||
|
||||
printf("\n⚠️ POTENTIAL LEAKS:\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "[LEAK DIAGNOSIS] Phase: %s", phase);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Instance: %p, Node ID: %llu, UA: %p, Running: %d",
|
||||
instance, (unsigned long long)instance->node_id, instance->ua, instance->running);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "STRUCTURE COUNTS - ETCP Sockets: %d, ETCP Connections: %d, ETCP Links: %d",
|
||||
report.etcp_sockets_count, report.etcp_connections_count, report.etcp_links_count);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "RESOURCE STATUS - Memory Pool: %s, TUN: %s, TUN FD: %d",
|
||||
instance->pkt_pool ? "ALLOCATED" : "NULL",
|
||||
instance->tun ? instance->tun->ifname : "NULL",
|
||||
instance->tun ? instance->tun->fd : -1);
|
||||
|
||||
if (instance->pkt_pool) {
|
||||
printf(" ❌ Memory Pool not freed\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: Memory Pool not freed");
|
||||
}
|
||||
if (instance->tun) {
|
||||
printf(" ❌ TUN interface not closed\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: TUN interface not closed");
|
||||
}
|
||||
if (report.etcp_sockets_count > 0) {
|
||||
printf(" ❌ %d ETCP sockets still allocated\n", report.etcp_sockets_count);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP sockets still allocated", report.etcp_sockets_count);
|
||||
}
|
||||
if (report.etcp_connections_count > 0) {
|
||||
printf(" ❌ %d ETCP connections still allocated\n", report.etcp_connections_count);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP connections still allocated", report.etcp_connections_count);
|
||||
}
|
||||
if (report.etcp_links_count > 0) {
|
||||
printf(" ❌ %d ETCP links still allocated\n", report.etcp_links_count);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "POTENTIAL LEAK: %d ETCP links still allocated", report.etcp_links_count);
|
||||
}
|
||||
|
||||
printf("\n📋 RECOMMENDATIONS:\n");
|
||||
if (instance->pkt_pool) {
|
||||
printf(" → Call memory_pool_destroy() before freeing instance\n");
|
||||
}
|
||||
if (instance->tun) {
|
||||
printf(" → Call tun_close() to close TUN interface\n");
|
||||
}
|
||||
if (report.etcp_sockets_count > 0) {
|
||||
printf(" → Iterate and call etcp_socket_remove() for each socket\n");
|
||||
}
|
||||
if (report.etcp_connections_count > 0) {
|
||||
printf(" → Iterate and call etcp_connection_close() for each connection\n");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "[LEAK DIAGNOSIS] Recommendations: pkt_pool=%d, tun=%d, sockets=%d, connections=%d",
|
||||
instance->pkt_pool ? 1 : 0,
|
||||
instance->tun ? 1 : 0,
|
||||
report.etcp_sockets_count,
|
||||
report.etcp_connections_count);
|
||||
}
|
||||
Reference in new issue
Block a user