Evgeny
8756f561be
build: extract libutun.a from src/ + add db_sync module + etcp API, BBR improvements
...
- Add libutun.a (noinst) containing all src/*.c except utun.c
- utun binary now links libutun.a + libuasync.a
- tests/Makefile.am simplified: all tests link libutun.a instead of
manual .o file lists (removed ~70 lines of boilerplate)
- Add db_sync module: distributed content-addressed DB with LMDB
backend, peer-to-peer sync via etcp_router (svc 0x20)
- etcp API: etcp_send_in_order(), etcp_clear_inflight_queues(),
verify_packet_signature(), BBR getters
- BBR: adaptive threshold (1/4 of pipe-min instead of hardcoded)
- route_bgp/etcp_connect: STCP transport support in NODEINFO
- conn_mgr: NODEINFO_ADDRS doc for nat_type/transport/proto fields
- Cleanup: removed AUDIT_FINDINGS.txt, filelist.txt, nat.txt
3 months ago
jeka
7139969acd
fix: Windows/MSYS2 build compatibility
...
- proxy/icmp_proxy.c: define struct icmp/ip + ICMP constants for _WIN32
- lwip_tcp_priv.h: use #include <winsock2.h> instead of #define htonl/htons
- lwip_tcp.h/c: rename poll field to pollfn (avoid WSAPoll macro conflict)
- tests: guard Unix-only headers with #ifndef _WIN32, skip fork/socketpair tests
3 months ago
Evgeny
59d307f98b
conn_mgr.h: document in ll_queue style; config_parser/utun_instance updates
3 months ago
Evgeny
90ad64a106
stcp: add protocol field to NODEINFO addr structs, TCP support in etcp_connect, stcp traffic test
...
- route_node.h: add NODE_PROTO_UDP/NODE_PROTO_TCP constants, protocol field in NODEINFO_IPV4_ADDR/NODEINFO_IPV6_ADDR
- route_node.c: fill protocol for UDP sockets + TCP servers from config, update dumps
- etcp_connect.c: create stcp_link for TCP-capable addresses, ready/close callbacks, cleanup
- etcp_connections.c: store stcp_server_listen result in instance->stcp_server, fix socket init checks for TCP-only configs
- utun_instance.c: use stcp_link_server_destroy (high-level API) instead of stcp_server_destroy
- tests/test_stcp_traffic.c: 2 nodes via etcp_connect+TCP, 1MB bidirectional traffic (10-1800 byte pkts)
3 months ago
Evgeny
4914348557
etcp_router: транзитные очереди per (src,dst) с backpressure + унификация etcp_send
...
- TRANSIT_QUEUE: отдельная очередь на каждую пару src+dst узлов
- ll_queue с хеш-индексом для быстрого поиска transit-очередей
- backpressure через waiter на send_input_q (threshold=0, один пакет за вызов, round-robin)
- Очередь создаётся при первом пакете который не получается отправить напрямую, удаляется при опустошении
- Унифицирован etcp_send: единый путь queue_data_put(send_input_q) для UDP (normalizer->input) и STCP (tx_queue)
- Убран STCP-ветвления из router_forward_transit/drain_cb
- Исправлено перекрытие ll.data и tq->q в TRANSIT_QUEUE (добавлены явные поля src_node_id/dst_node_id)
- Фикс лика dgram в tx_queue_cb/client_tx_queue_cb (добавлен queue_dgram_free)
- transit_queues живут внутри ETCP_CONN, инициализируются лениво, очищаются в etcp_connection_close (до pn_deinit) и stcp_link_close
3 months ago
Evgeny
55fa5c7759
fix: add retry_timer fallback in tcp_proxy_server for backpressure stall
...
waiter-based backpressure (commit ba14e31e ) could starve HTTPS CONNECT
worker under concurrent 4-worker load — send_q never drained below threshold
fast enough for the waiter to fire before curl timed out (exit=28).
Add retry_timer (500ms, force=1) alongside etcp_router_on_send_ready
waiter: waiter gives instant wake when send_q drains, timer guarantees
delivery via force=1 if waiter hasn't fired in time.
Also improve socks_proxy DEBUG diagnostics in backpressure branches.
3 months ago
Evgeny
0b5a710fe6
etcp_connect + BGP_READY callbacks + router reconnect test
...
- etcp_connect.c: async connect API with EARLY/LATE/BGP_READY callbacks
- etcp_connect.h: declaration (via etcp_api.h)
- connect_deliver: fix to preserve unfired callback nodes
- etcp_set_routing_exchange_state: fires bgp_ready_cbk on TABLE_COMPLETE
- route_bgp: TABLE_COMPLETE handler + route_bgp_send_table_complete
- etcp.c: connections_count tracking, cleanup on close
- test_etcp_router_reconnect: a-b-c topology with b restart (etcp_connect)
- test_etcp_connect: unit tests for async connect API
- etcp_router: inflight/retrans/close improvements
- Various proxy/NAT/router cleanups
3 months ago
Evgeny
f1f533a552
move CLOSE/RST flags from hdr->seq to hdr->flags
...
- ROUTER_SEQ_CLOSE_FLAG (0x80000000) → ROUTER_FLAG_CLOSE (0x02 in flags)
- ROUTER_SEQ_RST_FLAG (0x40000000) → ROUTER_FLAG_RST (0x40 in flags, already existed)
- router_send_one_flags: uint32_t seq_flags → uint8_t flag_bits
- router_send_to: uint32_t seq_flags → uint8_t flag_bits, hdr->seq=0, hdr->flags=flag_bits
- etcp_router_recv_cb: check hdr->flags instead of hdr->seq for CLOSE/RST
3 months ago
Evgeny
03490cfc00
refactor: extract etcp_router_recv_cb into 5 functions + fix send_q threshold
...
- router_verify_signature — Ed25519 signature verification
- router_handle_ack — ACK processing + drain on send_blocked
- router_forward_transit — packet forwarding
- router_check_peer_restart — session restart + RST detection
- router_handle_data_packet — reorder/assembly/dedup
- free_entry helper
- etcp_router_recv_cb: 198 → 42 lines
- ROUTER_MAX_SEND_Q_PACKETS threshold: MAX/2 → MAX-1 (min wait)
3 months ago
Evgeny
ba14e31e09
fix: remove retry_timer, use waiter-based round-robin on send_q for fairness
...
- tcp_proxy_server: drain_cb uses etcp_router_on_send_ready instead of retry_timer
- socks_proxy: on_read_cb + tx_waiter_cb use etcp_router_on_send_ready instead of waiter_register
- Result: FIFO round-robin via ll_queue waiters on send_q, all streams get fair share
- No timers — wakeup is event-driven via queue_data_get → check_waiters
- TCP backpressure: read_queue callback_suspended prevents over-reading
3 months ago
Evgeny
5b850ea5da
test: add profiling (MB/s per file per worker) to socks_http_proxy
3 months ago
Evgeny
2fba5c31c4
fix: backpressure data loss in socks/http proxy + comprehensive test
...
socks_proxy (client side):
- tx_buf buffering on send_data failure in RELAY path, retry in tx_waiter_cb
- process_http_request: version_str null-term fix (memcpy(vlen)+explicit \0)
- process_http_request: assemble hdr+body+extra into heap pkt, atomic send
- socks_proxy_handle_etcp: alloc failure logs write_queue state + byte counters
tcp_proxy_server (exit node):
- read_queue_drain_cb: tx_buf buffering on backpressure, retry_timer (500ms, force=1)
- on_fin_cb: defer FIN when read_queue+tx_buf has pending data (dst_fin_deferred)
- handle_data + drain_cb: per-stream byte counters (sent/recv/relayed/drain_count)
- on_fin_cb/on_error_cb: detailed state logging (counters, queues, buffers)
test_socks_http_proxy:
- 4 workers: socks_ipv4, socks_domain (DNS resolution via SOCKS), http_proxy, https_connect
- 4 file sizes: 1KB, 100KB, 1MB, 10MB — deterministic content, byte-by-byte cmp -s
- HTTPS server with self-signed cert, POST/echo, HEAD, OPTIONS
- 51/51 tests PASS
3 months ago
jeka
4f168c93f6
1
3 months ago
Evgeny
6c938ed2ba
test_etcp_router: dummynet congestion test + timer leak fixes
...
- test_etcp_router: full rewrite with dummynet proxy, congestion cycles
(fill inflight to backpressure, push 20 packets through, release shaper)
bitmap tracking (0 loss, 0 dup, 0 corrupt checks), timing diagnostics
- Makefile.am: add utun-dummynet.o to test_etcp_router LDADD
- conn_mgr: fix cm_exch_probe timer leak (NULL callback → retry_cb),
clean exchange_pending in cm_entry_destroy + conn_mgr_destroy
- utun_instance: add stcp_server_destroy() call in utun_instance_destroy
3 months ago
Evgeny
2cb85cbc3d
socks_proxy: поддержка HTTP-прокси (GET/POST/HEAD/OPTIONS/...) — не только CONNECT
...
process_http_request() теперь обрабатывает любые HTTP-методы:
- CONNECT — туннель как раньше, без изменений
- GET/POST/PUT/HEAD/OPTIONS/... — парсинг абсолютного URL, DNS,
send_connect + пересборка строки с относительным путём + тело DATA
test_socks_http_proxy: +3-й worker (http_proxy через -x без --proxytunnel),
+проверки POST (echo), HEAD (200 OK), OPTIONS (Allow). Все 78 проверок — PASS.
3 months ago
Evgeny
754c08e9c2
etcpmon: widen sockets list by ~100px (15 chars), shift action section
3 months ago
Evgeny
71ccccc2d5
etcpmon: widen sockets list +15px, shift action section right
3 months ago
Evgeny
c6d1ebeeaf
debug: log etcpmon socket_list NAT values in send_socket_list
3 months ago
Evgeny
eea0ed0a48
debug: add NAT category logging to self-detect, init_resp nat update, and NAT_INFO receive paths
3 months ago
Evgeny
0738dcfd5a
fix: self-detection uses interface_addr instead of local_addr (works with 0.0.0.0 bind); don't overwrite nat_addr in handle_init_response_client if NAT already verified
3 months ago
Evgeny
4862c30261
add CFG_SERVER_TYPE_LOCAL (type=local) and UNKNOWN semantics: PRIVATE/LOCAL hidden from nodeinfo, PRIVATE blocks incoming INIT, LOCAL accepts; UNKNOWN treated as PUBLIC; self-detection of PUBLIC IP on incoming INIT; filter LOCAL from NAT checks and connectivity
3 months ago
Evgeny
3c5d82a6ee
add cross-build-win.sh for Windows cross-compilation; gitignore build-win/ build artifacts only
3 months ago
Evgeny
389ef00da6
refactor: split socket meta 'type' into config_type and nat_type — separate config (PUBLIC/NAT/PRIVATE) from detected NAT (EIM/STRICT/DIRECT) across NODEINFO, conn_mgr, route_bgp, route_node, etcpmon; win32 compat fixes (memmem, SHUT_WR, tun test_mode, tcp_proxy guards)
3 months ago
Evgeny
487cb8718e
fix: preserve newlines in config_updater insert/update — no extra newlines on key replacement, add leading nl when inserting at end without trailing nl
3 months ago
Evgeny
42d96f118d
fix: swap queue_entry_free/queue_dgram_free order in 27 places — prevents UAF when dgram_free accesses freed entry
...
uasync: replace raw socket_node* handle with packed index — fixes UAF after socket_array realloc
tcp_io: defer u_free in tcp_conn_destroy via uasync_call_soon — prevents callback-chain UAF
tcp_io: guard read_cb/write_cb with NULL queue checks after deferred destroy
tcp_io: save read_queue to local before queue_data_put + NULL guard after
route_connectivity: linked-list probe_ctx — cancel all parallel probes before nq free
3 months ago
Evgeny
8962f58ea4
uasync: replace raw socket_node pointer with index-based handle — fix UAF after realloc
3 months ago
Evgeny
1f541d6432
tcp_io: save read_queue to local var before queue_data_put, add NULL guard after
3 months ago
Evgeny
e66156eb49
tcp_io: deferred free in tcp_conn_destroy to prevent UAF in callback chain
3 months ago
Evgeny
2cd38988e6
AGENTS: add ASAN build instructions
3 months ago
Evgeny
d58b532741
gitignore: add utun.pid
3 months ago
Evgeny
4716e54069
build: add --asan flag to build.sh, tcp_io: null sock/queues in destroy + guard read_cb/write_cb
3 months ago
Evgeny
aa73e9d8cb
route_connectivity: fix UAF in conn_probe_finish — break ctx->nq on cancel_node, always free ctx in finish
3 months ago
Evgeny
993c265125
control_server: add idle timeout (30s) on client socket + large output queue warning
3 months ago
Evgeny
5ca0bbf9e7
tcp_io: place write_monitor=0 before queue_resume_callback to prevent busy-loop when waiter_defer=1
3 months ago
Evgeny
0ef7ee597c
tcp_io: fix write_cb busy-loop with deferred callback — turn off write_monitor after flush when waiter_defer=1
3 months ago
Evgeny
7d460ca156
fix: ASAN-detected UAFs and buffer overflows across 6 modules
...
- etcp_connections: fix link leak & UAF in etcp_socket_remove — remove_link inside etcp_link_close shifts array, skip NULL set and i++
- stcp_server: fix UAF in stcp_conn_process_recv — defer free via uasync_call_soon after stcp_conn_do_close
- etcp: save pkt_len before queue_data_put to output_queue (callback may free entry synchronously)
- socks_proxy: add pool bounds check before memcpy, UINT16_MAX truncation guard, freed flag
- tcp_proxy_server: reorder cleanup (cancel waiters before tcp_conn_destroy), UINT16_MAX guard
- test_route6_lib: increase nodes[] array to STRESS_NODES + STRESS_OPS
3 months ago
Evgeny
b738b2ff1b
etcp_router: add u_check guards at send_q/recv_q entry points to detect memory corruption
3 months ago
Evgeny
cc5289e37c
etcp_router: don't reset start_sent in reactive restart — prevents START-flag cascade on multi-hop restart detection
3 months ago
Evgeny
0c5f25c96d
etcp_router: fix restart cascade — sync peer_sess_id on auto-create, remove sess_id increment on reactive restart
3 months ago
Evgeny
b53758bdbe
etcp_router: cancel timers in conn_restart, reset last_ack_sent_tb — fix use-after-free SIGSEGV
3 months ago
Evgeny
f5b1c3e789
etcp_router: fix OOB drops after restart — add peer_sync_done to sync rx_seq with first incoming seq
3 months ago
Evgeny
0edd21e335
etcpmon: lift Router to y=1181 (tight to Queues), shrink window to 1400
3 months ago
Evgeny
e0c38676e7
etcpmon: compress Queues h 300->280, lift Router y 1260->1240
3 months ago
Evgeny
fefd2bcc52
etcpmon: fix layout — restore Debug Levels y=485, lift Links to y=710, compress Queues h=300 y=900
3 months ago
Evgeny
8427e18c98
control_server: fix infinite loop in router_conns aggregation — use read-only head->next traversal instead of get/put
3 months ago
Evgeny
7329fa65f1
etcp_router: add congestion counters, fix tx_seq rollback on etcp_send failure, add router metrics to etcpmon GUI
...
- etcp_router.h: add 9 per-conn counters (pkts_sent/err/rcvd, ack_sent/recv/stale, dup/oob/sign_fail)
- etcp_router.c: increment counters at 13 event points; fix tx_seq rollback on etcp_send failure (was causing phantom inflight=256 deadlock); add DEBUG_ERROR on all 5 ignored etcp_send returns; fix router_ack_do_send to update timestamps only on success
- etcpmon_protocol.h: add etcpmon_router_metrics (14 aggregated fields)
- control_server.c: iterate router_conns to fill aggregated router metrics
- etcpmon_gui: new 'Router Congestion' block with queue depths and all counters, Debug Levels shifted down, window 1300->1440
- test_etcp_router_unit: fix test_ack_timer for correct no-BGP-route behavior
3 months ago
Evgeny
de8cce521a
all 51 tests pass: fd=0 protection + clean socks_http_proxy test
...
- socket_compat: never close fd=0
- socks_http_proxy: rewritten cleanly, 2 workers, 25 reqs each, up to 100KB
- uasync_socket_race: dup2-based fd=0 reservation
- u_async: removed DIAG spam
- tcp_io: removed debug fprintf
Result: 51/51 tests pass.
3 months ago
Evgeny
f06ebd2ab4
fix: protect fd 0 from close in socket_close_wrapper + dup2 reserve in tests
...
- socket_close_wrapper: never close sock==0 (prevents fd 0 reuse cycle)
- test_uasync_socket_race: dup2-based fd 0 reservation, pass 800/800
- tcp_io: SOCKET_INVALID before on_error (previous commit)
- Plus earlier fixes: uasync gen counter, ll_queue call_soon_id, pkt_normalizer
Result: test_uasync_socket_race PASSES, 50/51 tests pass
3 months ago
Evgeny
a97a38d867
fix: set tc->sock=SOCKET_INVALID before on_error in handle_error
...
В одном epoll_wait batch три события для fd: EPOLLERR (освобождает tc),
EPOLLIN (read_cb), EPOLLOUT (write_cb). read_cb/write_cb guard проверяет
tc->sock==SOCKET_INVALID, но sock обнулялся ПОСЛЕ on_error.
Перенос sock=SOCKET_INVALID до on_error защищает от use-after-free.
Доказано: без фикса segfault на tcp_io.c:374 (write_cb → tc->connected).
С фиксом тест работает без крашей.
3 months ago
Evgeny
aff3b2d00f
fix: always remove socket from epoll in tcp_conn_handle_error
...
tcp_conn_handle_error гвардил uasync_remove_socket_t по tc->socket_id,
пропуская повторный вызов. В одном epoll_wait batch два события
(EPOLLERR + EPOLLOUT) на один fd: первое делает remove (socket_id=NULL),
второе проходит guard и dispatch'ит write_cb на освобождённом tc.
Фикс: всегда вызывать uasync_remove_socket_t + epoll_ctl(DEL),
независимо от socket_id.
3 months ago