Commit Graph
595 Commits
Author SHA1 Message Date
Evgeny fc0d8715d9 Crypto: Refactored ETCP header size calculations with offsetof-based defines, increased CCM tag to 16 bytes 2026-04-24 16:03:07 +03:00
Evgeny 92aee12850 Crypto: Added SHA256-based KDF for session key derivation from ECDH shared secret 2026-04-24 15:43:58 +03:00
Evgeny eba3bb2be2 Fix compiler warnings: remove incorrect address-of operator and add getpid for Windows
- etcp_connections.c:1142: remove & before addr in sockaddr_storage_to_str call
- test_etcp_simple_traffic.c: add #include <process.h> and #define getpid _getpid for Windows
2026-04-24 14:48:29 +03:00
Evgeny 983c8ebdf3 Add htobe32/be32toh macros for Windows build 2026-04-24 14:44:24 +03:00
Evgeny e67b6a6dd5 Fix getmyip.h Windows build: use winsock2.h instead of sys/socket.h 2026-04-24 14:39:12 +03:00
Evgeny 2f62bd6024 Fix allowed_keys check to only apply to ETCP_INIT packets, not PING/PONG
The allowed_keys authorization was incorrectly checking all INIT-decrypted
packets including PING/PONG. Moved the check after packet type validation
so it only applies to ETCP_INIT_REQUEST/NOINIT (incoming connection requests).

Fixes test_etcp_ping and test_nat_detection failures.
2026-04-24 14:37:08 +03:00
Evgeny 95053c6cd5 Replace buggy get_default_route_ip() with get_outgoing_local_ip() for reliable local IP detection
- Add lib/getmyip.c/h with get_outgoing_local_ip() using UDP connect+getsockname
- Update etcp_socket_add() to use new function for 0.0.0.0 and :: bindings
- Support both IPv4 (8.8.8.8) and IPv6 (2001:4860:4860::8888) auto-detection
- Remove broken get_default_route_ip() from platform_compat (it returned gateway IP, not local IP)
- Keep get_interface_ip_by_index() for explicit interface bindings
- Update Makefile.am to include new getmyip module
2026-04-24 14:07:41 +03:00
Evgeny eea596f8fd Add getmyip module for reliable local IP detection
- New lib/getmyip.c/h with get_outgoing_ip(), get_default_local_ip(), get_local_ip_by_index()
- Uses UDP connect + getsockname instead of /proc/net/route parsing
- Supports both IPv4 and IPv6
- Updated etcp_socket_add() to use new functions for interface_addr detection
2026-04-24 13:58:24 +03:00
Evgeny a6857d6267 Socket info: show config and netif IP in log, monitor shows interface IP 2026-04-24 01:23:52 +03:00
jeka ee265494a7 1 2026-04-24 00:43:59 +03:00
Evgeny 49af818f5a Config: Added [allowed_keys] section to sample config with documentation 2026-04-24 00:21:00 +03:00
Evgeny e39cbc41ab Config: Added [allowed_keys] section for client public key authorization on server
- Added CFG_ALLOWED_KEY struct with binary key storage (64 bytes) for fast memcmp comparison
- Implemented parsing of [allowed_keys] section with allow_all flag and per-key entries
- Added key validation in etcp_connections.c server handler (errorcode=8 for rejected keys)
- Default behavior: deny all if [allowed_keys] section is missing or allow_all=0 with no keys
- Added proper memory cleanup and debug logging for allowed_keys configuration
- Updated all test configs to include [allowed_keys] allow_all=1 for backward compatibility
2026-04-24 00:16:30 +03:00
Evgeny 015403cda8 Restart NAT check when client address changes in INIT_REQUEST 2026-04-23 23:56:49 +03:00
Evgeny 0688a9801d NODEINFO: Add nat_addr/nat_port fields, use interface_addr for addr/port 2026-04-23 23:21:12 +03:00
Evgeny 0e7cccd81b Add socket type (public/nat/private) to handshake and skip private nodes in NAT detection 2026-04-23 22:44:43 +03:00
Evgeny 3122bb5800 GUI: Widen sockets list 1.5x, shrink action field, move Send below 2026-04-23 22:11:02 +03:00
Evgeny 31fab3b1c7 GUI: Add NAT address to socket display in etcpmon 2026-04-23 22:02:42 +03:00
Evgeny 305d485cc1 Reset NAT check status on etcp_conn_reinit when session_id changes
When peer's random session_id changes, etcp_conn_reinit() is called.
Previously NAT check status was not reset, so route_bgp_new_conn()
skipped NAT re-detection because nat_check_status was still
NAT_CHECK_IN_PROGRESS from the previous session.

Now etcp_conn_reinit():
- Cancels pending NAT-ping requests via route_ping_cancel_for_conn()
- Resets nat_type and nat_check_status to UNKNOWN/NONE for all links

This ensures NAT type is re-detected for all links after reinit.
2026-04-23 20:00:09 +03:00
Evgeny fef1409a68 Debug: Add diagnostic logging for PONG handling to trace ping response issues 2026-04-23 13:18:59 +03:00
Charlie Root 3bc900bc4b 1 2026-04-22 23:15:41 +00:00
Evgeny 54df89d062 Fix two more UAF in route_bgp: move DEBUG_INFO before etcp_send
- route_bgp_send_nat_info: moved ip_to_str(pkt->nat_ip) log before etcp_send
- route_bgp_send_nat_check_req: moved ip_to_str(pkt->interface_ip) log before etcp_send

Both were reading from pkt memory that could be freed by etcp_send callback.
2026-04-23 02:09:09 +03:00
Evgeny dc16549d8e Fix use-after-free: read request_id before etcp_send frees req_pkt
req_pkt memory could be freed by etcp_send callback before pending->request_id
was assigned. Store request_id in local variable and use it for pending.
2026-04-23 01:59:41 +03:00
Evgeny 83c8da8f25 Add debug logging for request_id tracking and pending list dump 2026-04-23 01:48:16 +03:00
Evgeny ba3c3cdd82 Fix unaligned uint64_t access in packed struct causing garbage request_id
- Changed request_id from uint64_t to uint32_t in BGP_PING_REQUEST/RESPONSE
- Added uint16_t reserved field after subcmd for proper alignment
- Updated next_ping_req_id from uint64_t to uint32_t in ROUTE_BGP
- Fixed all log format strings from %016llx to %08x
- All 26 tests passing
2026-04-23 01:38:17 +03:00
Evgeny 2db961ec16 1 2026-04-23 01:15:15 +03:00
Evgeny 51571529fd ETCP: add session_id to prevent false reinit on new link addition
- Added 32-bit session_id to ETCP_CONN struct (random per client)
- Session_id transmitted in INIT_REQUEST/RESPONSE after node_id
- Server: skip reinit if session_id matches existing connection
- Server: send INIT_RESPONSE (0x03) only when reinit actually done
- Server: send INIT_RESPONSE_NOINIT (0x05) for same session
- Client: ignore INIT_RESPONSE with wrong session_id
- Fixed tx_state initialization in etcp_conn_ready for noinit case
- All 26 tests passing
2026-04-22 23:53:25 +03:00
Evgeny 0b54da7248 NAT: полное решение для отмены pending при падении conn
1. Добавлен via_conn в struct route_ping_pending - отслеживает через
   какое соединение (third_conn) отправлен запрос на ping
2. route_ping_cancel_for_conn теперь отменяет pending при падении ЛЮБОГО
   из двух conn: владельца линка (link->etcp) ИЛИ third_conn (via_conn)
3. nat_link_check_cb проверяет link->nat_check_status == IN_PROGRESS
   перед обработкой - защита от race condition когда conn упал раньше
   чем пришел ответ
4. Убраны избыточные DEBUG-логи, оставлены только информативные
2026-04-22 23:08:55 +03:00
Evgeny 9a5f87ed4a NAT: исправлена ошибка в route_ping_cancel_for_conn + добавлен дебаг
- Исправлена критическая ошибка: использовалось na->link->conn вместо
  na->link->etcp (struct ETCP_LINK.conn = ETCP_SOCKET*, а .etcp = ETCP_CONN*)
- Добавлен подробный дебаг в 4 места:
  * route_ping_send_req_addr - при создании pending
  * route_ping_cancel_for_conn - при поиске и отмене
  * route_bgp_remove_conn - состояние линков перед отменой
  * etcp_connection_close - очистка линков при закрытии
2026-04-22 22:58:36 +03:00
Evgeny 6cf0de18fe NAT: отмена pending NAT checks при удалении соединения
- route_bgp_remove_conn теперь отменяет pending NAT checks перед удалением
- Добавлена route_ping_cancel_for_conn: ищет pending запросы для conn,
  отменяет таймеры, сбрасывает arg->link = NULL, удаляет из списка
- struct nat_check_arg вынесена в route_bgp.h для видимости из route_ping.c
- После отмены pending, статусы линков с NAT_CHECK_IN_PROGRESS сбрасываются в NONE
2026-04-22 22:16:06 +03:00
Evgeny 1a3232e4d9 Backup before NAT cancel fix 2026-04-22 22:07:33 +03:00
Evgeny f587e9842f 1 2026-04-22 21:16:46 +03:00
Evgeny 6cd13fdbf2 GUI: поле действия и кнопка Send для отправки команд в utun
- Добавлен ETCPMON_CMD_ACTION в протокол (32 байта текст)
- В GUI добавлено поле ввода и кнопка Send правее блока Sockets
- Добавлен etcpmon_client_send_action для отправки команд
- Обработка action 'nat' в control_server: запускает NAT check для всех линков
- Сделана route_bgp_start_link_nat_check не-static
- Добавлена route_bgp_request_nat_check_all
- Исправлен баг route_ping.c (request_id -> nonce)
- Исправлена линковка tests/Makefile.am
2026-04-22 20:52:30 +03:00
Evgeny 29b295298f 1 2026-04-22 20:35:05 +03:00
Evgeny f44fbb0eb0 mass_update: по умолчанию запускает fast без аргументов 2026-04-22 18:29:31 +03:00
Evgeny 4a9ca67200 Исправлен byte order для IP адресов в NAT detection flow
- etcp_connections.c: парсинг NAT IP через memcpy (сохраняет NBO)
- route_bgp.c: убраны ntohl() для IP в NAT detection и route_bgp_send_nat_info
- route_ping.c: убран htonl() для IP в ping request
- тесты: обновлены ожидания NBO для nat_ip
2026-04-22 18:23:32 +03:00
Evgeny a0daaca9f3 Добавлено поле interface_addr в ETCP_SOCKET и interface_ip/port в BGP_NAT_CHECK_REQ
- platform_compat: get_interface_ip_by_index() для получения IP по ifindex
- ETCP_SOCKET: interface_addr заполняется из конфига/interface/default route
- BGP_NAT_CHECK_REQ: добавлены interface_ip/interface_port (network byte order)
- route_bgp_send_nat_check_req: отправляет interface_addr линка
- route_bgp_handle_nat_check_req: принимает interface данные в sockaddr-заглушку
2026-04-22 18:16:49 +03:00
Evgeny 1d0a0ea4ff Add RX/TX dup counters to ETCP monitor GUI
- Add IDC_EDIT_ETCP_RX_DUP and IDC_EDIT_ETCP_TX_DUP controls
- Insert RX Dup / TX Dup fields after Retrans in ETCP Metrics group
- Update tooltips, metrics display and clear functions
2026-04-22 16:28:33 +03:00
Evgeny e440e8cde0 Add duplicate packet counter to ACK frames
- Add rx_dup_count (local) and tx_dup_count (remote via ACK) to ETCP_CONN
- Extend ACK section format: add 16-bit rx_dup_count after last_delivered_id
- Reconstruct 32-bit tx_dup_count from received 16-bit diff
- Update etcpmon protocol and control_server to expose counters
- Update packet dumper for new ACK format
2026-04-22 16:04:11 +03:00
Evgeny ac56b1da3e Update: mass_update.py - config in script dir, per-server SSH keys 2026-04-22 14:37:10 +03:00
Evgeny 8e57446f4c Fix: read PID from pidfile instead of using shell $! 2026-04-22 13:16:26 +03:00
Evgeny 5e639ebe9b Suppress route command output to console 2026-04-22 12:42:52 +03:00
Evgeny e465206071 1 2026-04-22 12:37:02 +03:00
Evgeny 2449b1f221 1 2026-04-22 12:35:51 +03:00
Evgeny 98dcd2fd4a Add remote update scripts for mass deployment
- utun_update.sh: Shell script for updating single instance
  * fast mode: git pull + make clean + make
  * full mode: complete rebuild with autotools
  * Auto-detects project root from script location
  * Handles PID-based process stop/start
  * Supports Linux and BSD (nproc/sysctl)
  * Returns proper exit codes (0-4)

- mass_update.py: Python script for parallel SSH updates
  * Parallel execution via ThreadPoolExecutor
  * Configurable via JSON (~/.utun_servers.json)
  * Supports custom port/user per server
  * Timeout and error handling
  * Summary output per server

Tools for remote mass deployment of uTun updates via SSH.
2026-04-22 12:24:48 +03:00
Evgeny dbb147c966 Update .gitignore to prevent accidental binary commits 2026-04-22 11:47:34 +03:00
Evgeny 665f72d7ce Remove accidentally committed binaries and temp files 2026-04-22 11:45:54 +03:00
Evgeny 8c0904e00c Merge branch 'master' of http://git.syqiq.tech/jeka/utun2 2026-04-22 11:40:24 +03:00
Evgeny ec1e3fab9d Fix: round-robin link selection + byte order fixes + local_node update 2026-04-22 11:39:50 +03:00
Evgeny f45508628e WIP: debug byte order diagnostics 2026-04-22 02:14:47 +03:00
jeka fc954581c1 1 2026-04-22 00:46:00 +03:00