From 625d73913b8546b368e538343c991cd653852ef7 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Sat, 3 May 2025 17:25:21 -0400 Subject: [PATCH] tcp: reuse and refactor use of del function Rename tcp_connection_del to tcp_connection_cleanup_and_notify and use where needed. Type: refactor Change-Id: I6007205a63620f1bbf20b59999e833b6d6f631d4 Signed-off-by: Florin Coras --- src/vnet/tcp/tcp.c | 11 +++++------ src/vnet/tcp/tcp.h | 2 +- src/vnet/tcp/tcp_input.c | 11 +++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c index ed8c514ae8e..0fb1c1cf616 100644 --- a/src/vnet/tcp/tcp.c +++ b/src/vnet/tcp/tcp.c @@ -283,7 +283,7 @@ tcp_connection_cleanup (tcp_connection_t * tc) * just remove the connection, call tcp_connection_cleanup instead. */ void -tcp_connection_del (tcp_connection_t * tc) +tcp_connection_cleanup_and_notify (tcp_connection_t *tc) { session_transport_delete_notify (&tc->connection); tcp_connection_cleanup (tc); @@ -356,11 +356,10 @@ tcp_program_cleanup (tcp_worker_ctx_t * wrk, tcp_connection_t * tc) * If at the end the connection is not in CLOSED state, it is not removed. * Instead, we rely on on TCP to advance through state machine to either * 1) LAST_ACK (passive close) whereby when the last ACK is received - * tcp_connection_del is called. This notifies session of the delete and - * calls cleanup. - * 2) TIME_WAIT (active close) whereby after 2MSL the 2MSL timer triggers - * and cleanup is called. - * + * tcp_connection_cleanup_and_notify is called. This notifies session of the + * delete and calls cleanup. + * 2) TIME_WAIT (active close) whereby after 2MSL the 2MSL timer triggers and + * cleanup is called. */ void tcp_connection_close (tcp_connection_t * tc) diff --git a/src/vnet/tcp/tcp.h b/src/vnet/tcp/tcp.h index 67dc7407e91..ad2f63a8533 100644 --- a/src/vnet/tcp/tcp.h +++ b/src/vnet/tcp/tcp.h @@ -311,7 +311,7 @@ tcp_connection_t *tcp_connection_alloc_w_base (u8 thread_index, void tcp_connection_free (tcp_connection_t * tc); void tcp_connection_close (tcp_connection_t * tc); void tcp_connection_cleanup (tcp_connection_t * tc); -void tcp_connection_del (tcp_connection_t * tc); +void tcp_connection_cleanup_and_notify (tcp_connection_t *tc); int tcp_half_open_connection_cleanup (tcp_connection_t * tc); void tcp_send_reset_w_pkt (tcp_connection_t *tc, vlib_buffer_t *pkt, diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c index 47ae8513f62..404afb18764 100644 --- a/src/vnet/tcp/tcp_input.c +++ b/src/vnet/tcp/tcp_input.c @@ -117,9 +117,9 @@ tcp_handle_rst (tcp_connection_t * tc) switch (tc->rst_state) { case TCP_STATE_SYN_RCVD: - /* Cleanup everything. App wasn't notified yet */ - session_transport_delete_notify (&tc->connection); - tcp_connection_cleanup (tc); + /* Cleanup everything. App wasn't notified yet, but session layer must be + * notified that the session needs to be cleaned up. */ + tcp_connection_cleanup_and_notify (tc); break; case TCP_STATE_SYN_SENT: session_stream_connect_notify (&tc->connection, SESSION_E_REFUSED); @@ -2163,8 +2163,7 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, { error = TCP_ERROR_MSG_QUEUE_FULL; tcp_send_reset (tc); - session_transport_delete_notify (&tc->connection); - tcp_connection_cleanup (tc); + tcp_connection_cleanup_and_notify (tc); goto drop; } error = TCP_ERROR_CONN_ACCEPTED; @@ -2589,7 +2588,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, lc = tcp_lookup_listener (b[0], tc->c_fib_index, is_ip4); /* clean up the old session */ - tcp_connection_del (tc); + tcp_connection_cleanup_and_notify (tc); /* listener was cleaned up */ if (!lc) { -- 2.16.6