From fb8588d2cb449518a9e8dc75ef34ed2094c68835 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Thu, 18 Nov 2021 20:24:46 -0800 Subject: [PATCH] tcp_timewait: use on stack struct tcptw as last resort In case we failed to uma_zalloc() and also failed to reuse with tcp_tw_2msl_scan(), then just use on stack tcptw. This will allow to run through tcp_twrespond() and standard tcpcb discard routine. Reviewed by: rrs Differential revision: https://reviews.freebsd.org/D32965 --- sys/netinet/tcp_timewait.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c index 9d397d62424..73a84a40714 100644 --- a/sys/netinet/tcp_timewait.c +++ b/sys/netinet/tcp_timewait.c @@ -275,16 +275,17 @@ tcp_twstart(struct tcpcb *tp) * Reached limit on total number of TIMEWAIT connections * allowed. Remove a connection from TIMEWAIT queue in LRU * fashion to make room for this connection. + * If that fails, use on stack tw at least to be able to + * run through tcp_twrespond() and standard tcpcb discard + * routine. * * XXX: Check if it possible to always have enough room * in advance based on guarantees provided by uma_zalloc(). */ tw = tcp_tw_2msl_scan(1); if (tw == NULL) { - tp = tcp_close(tp); - if (tp != NULL) - INP_WUNLOCK(inp); - return; + tw = &twlocal; + local = true; } } /* -- 2.45.0