Commit Graph
5375 Commits
Author SHA1 Message Date
Evgeny 0dbebc0ddb fix use-after-free in queue_entry_free/dgram_free ordering + add tcp_proxy stress test + proxy diagnostics logging
- Fix queue_entry_free before queue_dgram_free in all proxy files (UAF bug causing segfault)
- Add PROXY/RP prefixed diagnostic logs for transparent proxy flow tracking
- Add tcp_proxy integration test: real utun instances, ETCP, remote_proxy, DNAT routing
- 7 test scenarios: basic_1mb, concurrent_5, concurrent_20, half_close, idle, conn_refused, stress (10 threads x 20 iterations)
- stress_client.py with --verbose per-thread phase timing (connect/send/recv)
2026-05-30 20:01:05 +03:00
Evgeny 5a0f35953e set FreeBSD TUN remote address to 192.0.2.1 instead of same as local 2026-05-30 13:13:08 +03:00
Evgeny 4511ece7e6 disable BACKTRACE_ENABLED to fix lld linker error with backtrace symbols 2026-05-30 02:17:46 +03:00
Evgeny 72704dfa04 fix compiler warnings: C23 label+declaration, uint16_t overflow check 2026-05-30 02:12:47 +03:00
Evgeny aca73c5e66 add lwIP TCP stack test with fixes: rcv_wnd tracking, FIN compensation, tmr_phase dual-counter, trace ring buffer, stats counters 2026-05-30 01:39:34 +03:00
Evgeny f8ba1d2755 update timeout_heap and u_async: O(1) cancel, heap cancel bubble-up fix, epoll callback safety, uasync_stop, socket_array u_realloc 2026-05-29 01:11:37 +03:00
Evgeny 3193eed907 fix route_bgp etcp_send leaks and etcp_socket_remove infinite loop on link->conn==NULL 2026-05-14 03:52:13 +03:00
Evgeny ae7d61fe4d fix INIT bounds checks and eim_nat port uint16_t wrap 2026-05-14 03:50:01 +03:00
Evgeny 1b469424c5 fix route_bgp/route_ping: old paths queue leak, etcp_send fail leak, nat_check_arg leak on cancel 2026-05-14 03:40:24 +03:00
Evgeny 5a72fc4d07 fix pkt_normalizer: null deref on alloc fail, mtu underflow, unchecked pn_buf_renew in loop 2026-05-14 03:38:21 +03:00
Evgeny 971d62c256 fix ETCP: dgram leak on inflight pool exhaustion, cancel dangling timers on link close/new 2026-05-14 03:35:26 +03:00
Evgeny ddf59aab3f fix uasync: posted_tasks delivery on Linux, create cleanup leaks, atomic array expand 2026-05-14 03:32:23 +03:00
Evgeny 06684e874a add audit findings document (51 issues across 12 modules) 2026-05-14 03:25:57 +03:00
Evgeny 1617c05a74 fix stale pointer after realloc in uasync socket/event handlers 2026-05-14 01:24:06 +03:00
Evgeny 79ae966994 add 16-bit seq to TCP proxy DATA for loss/duplicate detection 2026-05-13 13:28:05 +03:00
Evgeny 0314668629 fix use-after-free in tests: swap queue_entry_free/queue_dgram_free order, fix dangling timer handles and stack args; add ETCP MTU bounds, assembly overflow check, etcp_update_mtu 2026-05-13 12:38:20 +03:00
Evgeny ce9ab2ee2e fix TCP data stall: feed transport_to_uip on ETCP recv, tcp_poll interval 0→2 for close detection 2026-05-13 10:31:38 +03:00
Evgeny 256b629877 add periodic cleanup timers for ICMP pending requests and UDP flows 2026-05-13 09:02:24 +03:00
Evgeny 8686350b5b redesign TCP close: closing_tun/closing_rem flags, poll-driven cleanup, proper half-close 2026-05-13 03:18:29 +03:00
Evgeny 71117786a4 fix remote_proxy: cleanup socket on EOF/error/connect-fail to prevent infinite callback loop 2026-05-13 02:32:26 +03:00
Evgeny ec9ccc95fb fix lwIP TCP checksums on LE: remove htons from pseudo-header sum, add htons to return values 2026-05-13 02:11:59 +03:00
Evgeny 9ae1b92d37 fix tcp_pseudo_checksum: add ntohs() to correctly extract 16-bit IP halfwords from NBO on LE 2026-05-13 01:55:14 +03:00
Evgeny c9de5cdc2a fix tcp_proxy_ensure_outbound_listen: pass network byte order port to tcp_bind 2026-05-13 01:37:59 +03:00
Evgeny 7872e11444 add transparent outbound TCP proxying: dynamic listen on unknown ports, fwd to exit 2026-05-13 00:47:40 +03:00
Evgeny fab4c9506d fix TCP close: properly close lwIP pcb on both sides, fix use-after-free, add poll close path 2026-05-13 00:16:35 +03:00
Evgeny 000c3ef016 fix missing IP checksum in icmp/udp deliver_reply, fix udp output_queue->input_queue 2026-05-12 23:38:35 +03:00
Evgeny f1cc5f2b36 fix icmp_proxy: write reply to input_queue (not output_queue) to reach TUN device 2026-05-12 23:19:56 +03:00
Evgeny 0dd5ff8c87 add orig_src_ip to ICMP proxy protocol, fix deliver_reply dst_ip (was wrong tun_ip_addr) 2026-05-12 23:03:49 +03:00
Evgeny 4ba9157ca8 add etcp_router INFO logs for ICMP_PROXY reply path (send+deliver) 2026-05-12 22:45:57 +03:00
Evgeny 1a10c9607b add icmp_proxy diagnostic logging on all reply path stages 2026-05-12 22:30:16 +03:00
Evgeny 6a35e53e31 fix icmp: use SOCK_RAW for FreeBSD compat, add socket diagnostic logging 2026-05-12 22:08:30 +03:00
Evgeny 19603b83ee fix lwip_tcp_priv.h: use #ifndef _WIN32 for arpa/inet.h (FreeBSD compat) 2026-05-12 22:00:41 +03:00
Evgeny b49b81a5a8 replace fake ICMP echo reply with test_loopback flag, honest error when no raw socket 2026-05-12 21:46:16 +03:00
Evgeny f83faf02d2 add framed read for raw fd (2-byte len prefix), TCP_NODELAY, fix test half-close ordering 2026-05-12 19:43:44 +03:00
Evgeny 7fb63608da fix uasync set_timeout(0) ordering, dummynet shaper initial delay, add tests
- uasync_set_timeout(0): use FIFO immediate_queue instead of timeout_heap
  to guarantee execution AFTER all currently-expired heap timers
- uasync_cancel_timeout: search immediate_queue for timeout=0 timers
- dummynet: start initial shaper with bandwidth-based delay instead of 0
  (prevents queue from never filling up when packets arrive sequentially)
- test_dummynet: rename get_time_us -> now_us (conflict with u_async.h)
- test_u_async_comprehensive: fix immediate_timeouts, add timeout_ordering test
2026-05-12 13:42:16 +03:00
Evgeny 94cf07ee3d fix lwip_tcp port byte order (double-htons), mapping lookup, socket error handling
- Fix port encoding: PCB stores ports in host byte order, tcp_create_segment uses htons
- Fix tcp_bind/tcp_connect: ntohs incoming network-order ports
- Fix demux comparisons: use host-order sport/dport statics instead of in-place ntohs
- Fix tcp_output_alloc_header_common: htons for port output
- Add static sport/dport variables (host byte order) to avoid tcphdr corruption
- Fix sock_transport_error_callback: handle EPOLLERR during non-blocking connect
- Fix mapping local_port: store host-order port for find_mapping_by_port
- Fix tcp_proxy_raw_read/tun_input: use IP total length for packet boundaries
- test_tcp_proxy: reduce size to 2KB, fix port, add debug_init, add echo server log
- test_tcp_proxy handshake and basic data flow now working (known: cwnd/poll throughput tuning needed)
2026-05-12 12:16:09 +03:00
Evgeny 442ff81dbb replace uIP with adapted lwIP TCP stack (lwip_tcp)
- Replace uIP (src/uip/) with adapted lwIP 2.1.x TCP module
- Remove original src/lwip/ (replaced by src/lwip_tcp/)
- New src/lwip_tcp/ module: lwip_pbuf, lwip_tcp core/in/out
- Full TCP state machine, sliding window, congestion control
- Fast retransmit/recovery, Van Jacobson RTT estimation
- Nagle algorithm (TF_NODELAY), delayed ACK
- OOSEQ reassembly, TIME-WAIT handling
- Memory: memory_pool for PCB, listen PCB, tcp_seg
- Timers: uasync periodic timer drives fast/slow timers
- Output: callback-based IP packet output (TUN/raw-fd)
- Error codes: LERR_ prefix to avoid conflicts
- pbuf: simplified PBUF_RAM with proper header space reservation
- Integrate into tcp_proxy.c/h with per-pcb callbacks
- Active connection API: struct proxy_conn* instead of int conn_idx
- Makefile: remove uip, add lwip_tcp files
- test_tcp_proxy updated for new API; test_tcp_proxy_remote disabled
- Known: test_tcp_proxy data transfer needs flow tuning (WIP)
2026-05-11 22:51:48 +03:00
Evgeny 2937d81638 add UDP/ICMP proxy, refactor tcp_proxy via_node to instance-level
- UDP proxy: datagram relay client↔exit over ETCP
- ICMP proxy: echo ping relay client↔exit over ETCP
- Move via_node_id from per-forward-mapping to global tcp_proxy setting
- Support multiple concurrent tcp_proxy instances (no singleton g_tcp_proxy)
- Cap handshake padding to stay within 1472+overhead
- Handle non-TCP packets (UDP/ICMP) in tcp_proxy raw/tun input paths
- Add utun_instance_create_from_str() for test config creation
2026-05-11 18:37:36 +03:00
Evgeny 0224667491 add tcp_proxy and remote_proxy sections to sample config 2026-05-11 00:57:21 +03:00
Evgeny 8d1a240e3f fix remaining pointer-sign warnings in sc_set_peer_public_key callers 2026-05-10 19:03:42 +03:00
Evgeny bf56fa22b2 fix all compiler warnings: array-bool, pointer-sign, tautological, unsequenced 2026-05-10 18:56:06 +03:00
Evgeny 2c41a4d8a8 migrate NAT and DATA to etcp_router, fix warnings and destroy order 2026-05-10 14:00:49 +03:00
Evgeny bd3697c0bd revert unnecessary return -1 in void-test ASSERT macros; only test_bgp_route_exchange uses ASSERT in int main() 2026-05-10 00:49:46 +03:00
Evgeny 74e88a40d1 fix ASSERT macros: return -1 instead of bare return in int main() (FreeBSD -Wreturn-mismatch) 2026-05-10 00:44:59 +03:00
Evgeny e2f6aeebe1 fix .gitignore: stop ignoring test_*.c source files; add missing test_ipv6_sockets, test_tcp_proxy, test_radix, test_route6_lib sources 2026-05-10 00:34:28 +03:00
Evgeny fd72c6eed6 add IPv6 default route interface auto-detection for permanent/temporary IPv6 without netif
- get_default_route_netif_index(): UDP connect trick + getifaddrs to find default route iface
- etcp_socket_add(): auto-detect netif_index when not specified in config
- queue_new() API: explicit index_offset/index_size params instead of implicit from hash_size
- radix: cleanup types (uint8_t*), replace bzero/bcmp with memset/memcmp, remove kernel ifdefs
- route6_lib: new IPv6 routing library + get_node_v6_routes()
2026-05-10 00:05:23 +03:00
Charlie Root bedeac612a radix 2026-05-09 12:19:20 +03:00
Evgeny e3b78543a4 add uIP TCP/IP stack (minimal — only files needed for tcp_proxy build) 2026-04-29 00:20:09 +03:00
Evgeny ad8997e06c add etcp_router service routing layer + remote TCP proxy (uip+socket via router)
etcp_router: routable service packets with dst/src node_id
- etcp_router_bind/unbind: per-instance service handler registry
- etcp_route_send: send to node by id via BGP routing
- multi-hop forwarding through intermediate nodes
- loopback optimization (dst==self dispatches directly)

remote_proxy: exit node creating OS sockets on demand
- handles CONNECT/DATA/CLOSE via etcp_router
- non-blocking socket connect with uasync callbacks
- echo back response data to requesting node

tcp_proxy: etcp_transport for remote proxy
- via_node_id in mapping selects between sock/etcp transport
- unified handler for both tcp_proxy and remote_proxy roles
- config: forward = port -> ip:port via NODE_HEX [remote_proxy] section

tests: test_etcp_router (20 pkts bidirectional), test_remote_proxy (echo)
2026-04-28 20:01:12 +03:00
Evgeny b8e29c18e3 mass_update: log all sessions to files, terminal output only for errors 2026-04-28 00:00:40 +03:00