From 7c668b5d6ca7abfcc5bb17b47d78bec95e48ac61 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sat, 30 May 2026 22:40:31 +0300 Subject: [PATCH] add lwIP state diagnostics: tcp_alloc cwnd/sndbuf, proxy_poll_cb cwnd/unsent/unacked, active_pcbs counter --- src/lwip_tcp/lwip_tcp.c | 1 + src/tcp_proxy.c | 20 +++++++++++++++----- tests/tcp_proxy_full/client.conf | 4 ++-- tests/tcp_proxy_full/exit.conf | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/lwip_tcp/lwip_tcp.c b/src/lwip_tcp/lwip_tcp.c index 6cf92dc3..e5583b03 100644 --- a/src/lwip_tcp/lwip_tcp.c +++ b/src/lwip_tcp/lwip_tcp.c @@ -1084,6 +1084,7 @@ struct tcp_pcb *tcp_alloc(struct lwip_tcp_ctx *ctx, uint8_t prio) pcb->sv = 3000 / TCP_SLOW_INTERVAL; pcb->rtime = -1; pcb->cwnd = 1; + DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "tcp_alloc: cwnd=%u snd_buf=%u mss=%u snd_wnd=%u", pcb->cwnd, pcb->snd_buf, pcb->mss, pcb->snd_wnd); pcb->tmr = ctx->ticks; pcb->last_timer = ctx->slowtmr_ctr; pcb->ssthresh = TCP_SND_BUF; diff --git a/src/tcp_proxy.c b/src/tcp_proxy.c index 9adacf83..642b7147 100644 --- a/src/tcp_proxy.c +++ b/src/tcp_proxy.c @@ -314,14 +314,16 @@ static err_t proxy_poll_cb(void *arg, struct tcp_pcb *pcb) { int done = (pending == 0 && pc->pcb->unsent == NULL && pc->pcb->unacked == NULL); uint32_t sndbuf = tcp_sndbuf(pc->pcb); if (done || sndbuf == 0) { - DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "PROXY CLOSE stream=%016llx tun=1 pending=%u done=%d sndbuf=%u", - (unsigned long long)pc->remote_stream_id, pending, done, sndbuf); + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "PROXY CLOSE stream=%016llx tun=1 pending=%u done=%d sndbuf=%u cwnd=%u unsent=%p unacked=%p", + (unsigned long long)pc->remote_stream_id, pending, done, sndbuf, + pc->pcb->cwnd, (void*)pc->pcb->unsent, (void*)pc->pcb->unacked); pc->transport->ops->close(pc->transport); } } if (pc->closing_tun && (pc->closing_rem || pc->closing_sent) && pc->pcb) { - DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "PROXY CLEANUP stream=%016llx tun=1 rem=%d sent=%d", - (unsigned long long)pc->remote_stream_id, pc->closing_rem, pc->closing_sent); + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "PROXY CLEANUP stream=%016llx tun=1 rem=%d sent=%d cwnd=%u sndbuf=%u unsent=%p unacked=%p", + (unsigned long long)pc->remote_stream_id, pc->closing_rem, pc->closing_sent, + pc->pcb->cwnd, pc->pcb->snd_buf, (void*)pc->pcb->unsent, (void*)pc->pcb->unacked); struct tcp_pcb *save = pc->pcb; tcp_arg(save, NULL); pc->pcb = NULL; tcp_close(save); struct tcp_proxy *proxy = pc->proxy; @@ -728,7 +730,15 @@ void tcp_proxy_etcp_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) { if (delta > 1) { DEBUG_ERROR(DEBUG_CATEGORY_SOCKET, "TCP proxy: seq gap seq=%u last=%u stream=%016llx, tearing down", seq, et->recv_last_seq, (unsigned long long)stream_id); pc->closing_rem = 1; - if (pc->transport) { pc->transport->ops->destroy(pc->transport); pc->transport = NULL; } + if (pc->transport) { pc->transport->ops->destroy(pc->transport); pc->transport = NULL; } + { + int n_active = 0, n_tw = 0; + struct tcp_pcb* pcb2; + for (pcb2 = proxy->lwip->active_pcbs; pcb2; pcb2 = pcb2->next) n_active++; + for (pcb2 = proxy->lwip->tw_pcbs; pcb2; pcb2 = pcb2->next) n_tw++; + DEBUG_INFO(DEBUG_CATEGORY_SOCKET, "PROXY CLEANUP done stream=%016llx active_pcbs=%d tw_pcbs=%d", + (unsigned long long)pc->remote_stream_id, n_active, n_tw); + } queue_dgram_free(entry); queue_entry_free(entry); return; } et->recv_last_seq = seq; diff --git a/tests/tcp_proxy_full/client.conf b/tests/tcp_proxy_full/client.conf index f6e4c1d7..fdbd7bab 100644 --- a/tests/tcp_proxy_full/client.conf +++ b/tests/tcp_proxy_full/client.conf @@ -25,5 +25,5 @@ via_node=0xAAAA000000000001 connection=info socket=info general=info -traffic=info -tun=info +traffic=debug +tun=debug diff --git a/tests/tcp_proxy_full/exit.conf b/tests/tcp_proxy_full/exit.conf index bb7e896e..7b7feffc 100644 --- a/tests/tcp_proxy_full/exit.conf +++ b/tests/tcp_proxy_full/exit.conf @@ -20,5 +20,5 @@ enabled=yes connection=info socket=info general=info -traffic=info -tun=info +traffic=debug +tun=debug