From 910c1624b7c8385feabe17bbffdd6d96dfc57ef0 Mon Sep 17 00:00:00 2001 From: evgeny Date: Sun, 25 Oct 2026 17:55:34 +0100 Subject: [PATCH] Respect SOCKS policy and report LAN lookup failures precisely --- src/routing_layer/topo_node_sqlite.c | 6 ++++-- src/transport_layer/node_conn_direct.c | 6 +++++- src/transport_layer/node_conn_direct.h | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/routing_layer/topo_node_sqlite.c b/src/routing_layer/topo_node_sqlite.c index fb54d4708..223863b96 100644 --- a/src/routing_layer/topo_node_sqlite.c +++ b/src/routing_layer/topo_node_sqlite.c @@ -991,8 +991,10 @@ int topo_node_sqlite_get_ed25519_pubkey(sqlite3* db, uint64_t node_id, uint8_t p } int final_rc = sqlite3_finalize(stmt); if (final_rc != SQLITE_OK) rc = -1; - if (rc) DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "get_ed25519_pubkey: unavailable node=%016llx sql=%d finalize=%d: %s", - (unsigned long long)node_id, sql_rc, final_rc, sqlite3_errmsg(db)); + if (rc && sql_rc == SQLITE_DONE && final_rc == SQLITE_OK) + DEBUG_DEBUG(DEBUG_CATEGORY_ROUTING, "get_ed25519_pubkey: unknown node=%016llx", (unsigned long long)node_id); + else if (rc) DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "get_ed25519_pubkey: unavailable node=%016llx sql=%d finalize=%d: %s", + (unsigned long long)node_id, sql_rc, final_rc, sqlite3_errmsg(db)); return rc; } diff --git a/src/transport_layer/node_conn_direct.c b/src/transport_layer/node_conn_direct.c index a11a58292..1642b6499 100644 --- a/src/transport_layer/node_conn_direct.c +++ b/src/transport_layer/node_conn_direct.c @@ -315,6 +315,10 @@ static int ncd_create_lan_links(struct ncd_entry* entry, const struct TOPO_NODE* int count = 0; struct local_route route; for (size_t i = 0; local_transport_route(inst->local_transport, id, i, &route); i++) { + if ((route.socket.protocol & LOCAL_ROUTE_TCP) && inst->config && inst->config->global.socks_enabled) { + DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] LAN TCP skipped node=%016llx socket=%u reason=global SOCKS policy", + (unsigned long long)id, route.socket.socket_id); continue; + } const struct TOPO_REALITY_SOCK* reality = NULL; if (route.socket.protocol & LOCAL_ROUTE_REALITY) { reality = topo_node_find_reality_sock(ni, route.socket.socket_id); @@ -585,7 +589,7 @@ int node_conn_direct_update_local(struct UTUN_INSTANCE* inst, uint64_t node_id) struct TOPO_NODE* known = ncd_lookup_node(inst, node_id); struct TOPO_NODE* copy = known ? ncd_copy_node(inst, known) : NULL; if (known) topo_node_registry_unref(inst->topo_groups, node_id); - int result = copy ? ncd_create_lan_links(entry, copy, NULL, NULL) : 0; + int result = copy ? ncd_create_lan_links(entry, copy, NULL, NULL) : known ? -1 : 0; if (!copy) ncd_prune_lan(entry, 0); topo_node_destroy(inst->topo_groups, copy); entry->active_calls--; ncd_collect(entry); etcp_conn_ref_free(conn); diff --git a/src/transport_layer/node_conn_direct.h b/src/transport_layer/node_conn_direct.h index d84c361cd..ff3463122 100644 --- a/src/transport_layer/node_conn_direct.h +++ b/src/transport_layer/node_conn_direct.h @@ -51,6 +51,7 @@ struct NODE_CONN_DIRECT; * Без линков/handles/таймеров/проб. Исходящие пары — тот же обход, что open; reverse — sock_match/публикуемые адреса. * Учитывает IPv6 и исходящий TCP fallback; 1 — кандидат есть, 0 — нет/ошибка. SQLite не загружает. * Для подтверждённого LAN-кандидата может прочитать идентичность из SQLite без регистрации. + * LAN TCP соблюдает глобальную SOCKS-политику: при включённом SOCKS прямые LAN TCP-пробы не создаются. * Возможность попытки не доказывает достижимость и не подтверждает готовность группы. */ int node_conn_direct_compatible(struct UTUN_INSTANCE* inst, uint64_t node_id);