Commit Graph
2210 Commits
Author SHA1 Message Date
Evgeny 0adff0253d bbr: исправить отображение сырых BW-значений (bw_latest/bw_lo/bw_hi) с /125 на /2097
BW_RAW_TO_KBPS = bw_raw * 8000 / BW_UNIT = bw_raw / 2097.152
pacing_rate / 125 остаётся без изменений (уже в bytes/sec после bbr_rate_bytes_per_sec)
2026-06-01 18:13:07 +03:00
Evgeny 4f0baa37db bbr: исправить передачу потерь в BBR + пол для cwnd на уровне BBR_CWND_MIN_TARGET*mss
- etcp.c: rs->lost из link->bbr_loss_since_ack (был хардкод 0), вызов bbr_note_loss при ретрансмите
- etcp_connections.h: поле bbr_loss_since_ack для per-link учёта потерь в байтах
- etcp_bbr.c: везде где BBR_CWND_MIN_TARGET — умножить на mss (юнит-мизматч пакеты/байты)
  - bbr_quantization_budget, bbr_set_cwnd, bbr_bound_cwnd_for_inflight_model, bbr_probe_rtt_cwnd
  - bbr_init_lower_bounds: инициализация inflight_hi из cwnd (был ~0U навсегда)
- control_server.c + etcpmon: экспорт BBR-метрик (bw_hi/lo, inflight_hi/lo, режим, потери)
- tests/bbr_integration: интеграционный тест BBR (15с, 50ms/5%loss/1Mbit) с таблицей метрик
- устранён death spiral BBR при высоких потерях: cwnd теперь не падает ниже 4*mss
2026-06-01 17:50:16 +03:00
Evgeny 6c79939db3 congestion: заменить AIMD на BBR v3 (per-link), добавить юнит-тесты BBR
- Новые файлы: src/etcp_bbr.h/c — полный порт BBR v3 из BBR/bbr_v3.c (референс сохранён)
- struct ETCP_LINK: удалены AIMD-поля (rtt_history, rtt_swm, stat_win, stats_timer, inflight_phase...), добавлены bbr*, delivered_bytes, bbr_pacing_rate
- struct INFLIGHT_PACKET: +3 поля для rate_sample (delivered_at_send, inflight_at_send, is_app_limited)
- etcp_ack_recv: вызов bbr_main() с rate_sample, обновление inflight_lim_bytes и pacing
- etcp_request_pkt: заполнение BBR rate_sample полей при отправке
- Шейпер: bandwidth обновляется из bbr_pacing_rate
- Конфиг: inflight_min/max заменены на bbr_max_cwnd
- Дамп: BBR поля (mode, cycle, pacing, min_rtt_us, bw_hi/lo, inflight_hi/lo)
- Time injection: bbr->now_tb для детерминированных тестов
- tests/test_etcp_bbr.c: 8 юнит-тестов (init, startup, full_bw/drain, loss, cwnd cap, loss cut, fast_path, probe_rtt)
- Отключены test_etcp_congestion и test_etcp_reinit_inflight (старый congestion control)
- 40/40 тестов пройдено
2026-06-01 12:58:31 +03:00
Evgeny a80ba30b06 test_etcp_router_unit: fix FAIL macro — bare return in non-void function 2026-06-01 10:39:33 +03:00
Evgeny ed6b4d1046 debug: выделить link keepalive в отдельную категорию KEEPALIVE (21), добавить DEBUG_DEBUG при приёме keepalive-пакета 2026-06-01 10:03:14 +03:00
Evgeny 803387f2b4 router close_all_for_node: integrate with BGP remove_conn, fail fast on no route, stop PAUSE cycle
- route_bgp_remove_conn: call etcp_router_conn_close_all_for_node() when node loses all paths
- etcp_route_send: check BGP route before creating conn (return -1 early, no conn leak)
- remote_proxy: check rp_send_msg return value, close conn on error to break PAUSE↔FLUSH cycle
2026-06-01 01:44:29 +03:00
Evgeny 53d3f26e87 etcp_router: CLOSE/RST signaling flags in seq, close notification to services
- ROUTER_SEQ_CLOSE_FLAG (0x80000000): normal conn close
- ROUTER_SEQ_RST_FLAG   (0x40000000): conn not found
- router_send_to(): SVC_ROUTE with flags, no conn needed
- router_send_close_to_service(): notify local service [svc_id],len=1
- router_close_and_notify(): CLOSE to remote + close to local + cleanup
- etcp_router_conn_close(): sends CLOSE to remote before cleanup
- etcp_router_conn_close_all_for_node(): close all conns for dead peer
- recv_cb: flags checked only when pl_len==0 (avoid seq collision)
- etcp_router_destroy: close notification to each service
2026-06-01 01:12:52 +03:00
Evgeny 21cfe2d381 etcp_router: remove legacy, auto-conn for all services, send_q inflight control, remove tcp_proxy internal seq
- All SVC_ROUTE traffic now auto-creates ETCP_ROUTER_CONN, no legacy path
- etcp_route_send: auto-conn + seq + inflight check → send_q if full
- Inflight control via send_q: queue instead of drop, drain on ACK, retry timer 50ms
- router_send_one(): unified SVC_ROUTE wrapper with seq assignment
- router_deliver/try_assembly: pass real ETCP_CONN* to handlers (NAT needs it)
- tcp_proxy: remove internal 16-bit seq (send_seq/recv_last_seq/recv_init), shrink HDR 8→6
- remote_proxy: same seq removal, HDR/constants adjusted
- conn init/close/destroy: manage send_q, send_resume_timer lifecycle
- test_etcp_router_unit: −legacy, +send_q inflight test (18 tests)
2026-05-31 22:55:23 +03:00
Evgeny ac3cdd7739 etcp_router: simplified TCP — reorder recv_q, dedup, ACK timers, inflight control, per-(remote,svc) conn state
- New SVC_ROUTE_HDR (packed struct, 22 bytes): cmd+dst+src+seq+svc_id
- ETCP_ROUTER_CONN: state per (remote_node_id, svc_id), hash-indexed in router_conns
- Reorder via recv_q (hash by seq), dedup with 32-bit circular compare
- Periodic ACK (100ms), idle ACK (500ms), inflight limit via tx_seq - rx_acked
- Legacy mode: no conn → direct delivery without reorder
- etcp_router_conn_get/send/close API for seq-managed connections
- Unit test test_etcp_router_unit: 18 tests, 3ms, no ETCP/sockets/BGP
2026-05-31 21:59:46 +03:00
Evgeny 0f0857c22a add non-blocking send with EAGAIN+retry timer, normalizer flow control on recv, remove client-side send_buf buffering 2026-05-31 18:09:50 +03:00
Evgeny c4e80e6fd7 add traffic debug: PROXY RECV/SEND/FEED for full DATA path tracing on client 2026-05-31 17:21:47 +03:00
Evgeny 9d4c5b00f4 fix: stop forwarding after CLOSE, send CLOSE for non-existent conn in proxy data handlers 2026-05-31 16:54:36 +03:00
Evgeny f691c01b45 перевод комментариев tcp/udp/icmp proxy на русский 2026-05-31 16:32:10 +03:00
Evgeny 9a5d8797af tun: socket pair in test_mode, remove ip_fd_mode from tcp_proxy, fix test_remote_proxy stream_id size 2026-05-31 15:58:30 +03:00
Evgeny d1c9ef8377 ag 2026-05-31 13:44:55 +03:00
Evgeny e5d11ef9c1 refactor tcp_proxy: remove local socket mode, simplify architecture
- remove sock_transport, transport abstraction, active connections API
- simplify proxy_conn to 13 fields (was 15), remove tcp_proxy_mapping linked list
- new protocol: stream_id 4B, seq 2B cyclic, HDR_SIZE 8B
- add ERROR subcmd for immediate abort, CLOSE for graceful half-close
- proper half-close: shutdown SHUT_WR, keep reading, no timer
- exhaustive DEBUG_ERROR/WARN on all error/unusual branches
- config parser: report unknown options with filename:line and valid keys
2026-05-31 13:35:26 +03:00
Evgeny c3eccd7b35 add backpressure support: uip_retry_timer, feed drain at closing_tun/sent, send buffering with retry
- proxy_uip_retry_cb: retry send from uip_to_transport every 5ms
- proxy_recv_cb: buffer to uip_to_transport when send fails, set retry timer
- proxy_feed: drain transport_to_uip when closing_tun || closing_sent (prevents RST)
- proxy_recv_cb(p==NULL): only tcp_recved + closing_tun, no drain
- proxy_poll_cb/tcp_proxy_destroy: cancel retry timer on cleanup
- uip_retry_timer field in proxy_conn
2026-05-31 03:31:03 +03:00
Evgeny 616986457f add DEBUG_ERROR in all silent proxy error paths: NULL checks, alloc fails, transport send fail, data drop 2026-05-31 01:58:44 +03:00
Evgeny 10b9c93fcb add SOCK:EVENT unified diagnostics on exit: NEW/CONN/SEND/RECV/CLOSE/TIMER with fd, stream, total count 2026-05-31 01:31:59 +03:00
Evgeny be791ee7b2 drain transport_to_uip at FIN to prevent data delivery after close (eliminates RST storm) 2026-05-31 01:05:12 +03:00
Evgeny 01254406d8 fix tun_platform_write return value on FreeBSD: subtract 4-byte AF_INET header from writev result 2026-05-31 00:53:19 +03:00
Evgeny c4b1436919 add TUN write hex dump diagnostic (ip_total, ver_ihl, proto, first 32 bytes hex) in traffic category 2026-05-31 00:44:17 +03:00
Evgeny f708b1d095 add TUN write diagnostic: log tun_platform_write errors 2026-05-31 00:31:47 +03:00
Evgeny deaeae747a remove feed block after CLOSE: feed must remain active for streaming and half_close after FIN 2026-05-31 00:14:42 +03:00
Evgeny 4b7a1656fc final RST fix: tcp_recved before closing_tun, feed stop after CLOSE, free unsent before tcp_close, proxy_try_close helper
- proxy_recv_cb(p==NULL): tcp_recved(pcb,gap) before closing_tun
- proxy_feed_from_transport: stop when closing_sent
- proxy_poll_cb cleanup: free unsent before tcp_close
- proxy_try_close helper: shared between poll_cb (500ms) and recv_cb
- pending_out check: don't close if data still queued for exit
- Configs: traffic=info, tun=info for diagnostics
2026-05-31 00:02:01 +03:00
Evgeny 40d35ee2a5 fix RST storm: stop proxy_feed after CLOSE sent + free unsent before tcp_close 2026-05-30 23:38:42 +03:00
Evgeny 80e4e4fd5d fix RST on FIN: tcp_recved in proxy_recv_cb BEFORE closing_tun, guard proxy_err_cb with !closing_sent 2026-05-30 23:24:37 +03:00
Evgeny 8de8b5bb41 fix RST storm: tcp_recved before tcp_close in proxy_poll_cb cleanup 2026-05-30 23:06:28 +03:00
Evgeny 7c668b5d6c add lwIP state diagnostics: tcp_alloc cwnd/sndbuf, proxy_poll_cb cwnd/unsent/unacked, active_pcbs counter 2026-05-30 22:40:31 +03:00
Evgeny ba03cab182 fix tcp_proxy connection lifecycle: closing_sent, destroy transport, shutdown+timer on exit
- Add closing_sent flag to proxy_conn (CLOSE sent to exit, no need to wait for reply)
- proxy_poll_cb: send CLOSE when done || sndbuf==0; cleanup when tun && (rem||sent)
- Destroy transport in proxy_poll_cb cleanup (fix 56-byte leak)
- remote_proxy_handle_close: shutdown(SHUT_WR) + 2s timer instead of immediate rp_conn_free
- Remove SHUTDOWN subcommand entirely (not needed with new lifecycle)
2026-05-30 22:03:37 +03:00
Evgeny ca3215ab91 fix half_close: send CLOSE from proxy_poll_cb when no pending data, shutdown not close on exit 2026-05-30 20:52:25 +03:00
Evgeny f9d5495993 fix tcp_proxy deadlock: send CLOSE on TUN FIN + full proxy diagnostics
- proxy_recv_cb(p=NULL): now calls transport->close() to signal exit side
- Add PROXY FIN/CLOSE/CONNECTED/DATA/FEED/TCP_IN/TCP_OUT logs
- Add RP RECV/SEND/CLOSE logs on exit side
- Fix queue_dgram_free/queue_entry_free ordering (UAF) in all proxy files
- Change TRAFFIC logs from ERROR to INFO level
- Add 2 extra 1MB tests in run_test.sh to verify no post-stress stall
- stress_client.py: add --verbose per-thread timing (connect/send/recv ms)
- mem.c: zero freed memory for early UAF detection
2026-05-30 20:42:44 +03:00
Evgeny 4e6d57e371 clear freed memory in u_free_impl to catch UAF earlier 2026-05-30 20:03:33 +03:00
Evgeny a02c474b94 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 2585ef6f29 set FreeBSD TUN remote address to 192.0.2.1 instead of same as local 2026-05-30 13:13:08 +03:00
Evgeny 6521451493 disable BACKTRACE_ENABLED to fix lld linker error with backtrace symbols 2026-05-30 02:17:46 +03:00
Evgeny 2144eea46f fix compiler warnings: C23 label+declaration, uint16_t overflow check 2026-05-30 02:12:47 +03:00
Evgeny 7c71ef683c 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 8994d7a834 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 2d516bf16e 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 6c2aeb69a1 fix INIT bounds checks and eim_nat port uint16_t wrap 2026-05-14 03:50:01 +03:00
Evgeny d6c6ca9eb3 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 5aa9bdbd64 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 194c8398c1 fix ETCP: dgram leak on inflight pool exhaustion, cancel dangling timers on link close/new 2026-05-14 03:35:26 +03:00
Evgeny 4d5afe5ae9 fix uasync: posted_tasks delivery on Linux, create cleanup leaks, atomic array expand 2026-05-14 03:32:23 +03:00
Evgeny 06b94d37e8 add audit findings document (51 issues across 12 modules) 2026-05-14 03:25:57 +03:00
Evgeny 1a4b0a9de6 fix stale pointer after realloc in uasync socket/event handlers 2026-05-14 01:24:06 +03:00
Evgeny f18037ece2 add 16-bit seq to TCP proxy DATA for loss/duplicate detection 2026-05-13 13:28:05 +03:00
Evgeny b829ff7001 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 60cebb2535 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