void
tcp_connection_cleanup (tcp_connection_t * tc)
{
- tcp_main_t *tm = &tcp_main;
-
TCP_EVT (TCP_EVT_DELETE, tc);
/* Cleanup local endpoint if this was an active connect */
- transport_endpoint_cleanup (TRANSPORT_PROTO_TCP, &tc->c_lcl_ip,
- tc->c_lcl_port);
+ if (!(tc->cfg_flags & TCP_CFG_F_NO_ENDPOINT))
+ transport_endpoint_cleanup (TRANSPORT_PROTO_TCP, &tc->c_lcl_ip,
+ tc->c_lcl_port);
/* Check if connection is not yet fully established */
if (tc->state == TCP_STATE_SYN_SENT)
}
else
{
- int thread_index = tc->c_thread_index;
-
/* Make sure all timers are cleared */
tcp_connection_timers_reset (tc);
if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE)
tcp_bt_cleanup (tc);
- /* Poison the entry */
- if (CLIB_DEBUG > 0)
- clib_memset (tc, 0xFA, sizeof (*tc));
- pool_put (tm->connections[thread_index], tc);
+ tcp_connection_free (tc);
}
}
tcp_connection_t *
tcp_connection_alloc (u8 thread_index)
{
- tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
tcp_connection_t *tc;
- pool_get (tm->connections[thread_index], tc);
+ pool_get (wrk->connections, tc);
clib_memset (tc, 0, sizeof (*tc));
- tc->c_c_index = tc - tm->connections[thread_index];
+ tc->c_c_index = tc - wrk->connections;
tc->c_thread_index = thread_index;
return tc;
}
tcp_connection_t *
tcp_connection_alloc_w_base (u8 thread_index, tcp_connection_t * base)
{
- tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index);
tcp_connection_t *tc;
- pool_get (tm->connections[thread_index], tc);
+ pool_get (wrk->connections, tc);
clib_memcpy_fast (tc, base, sizeof (*tc));
- tc->c_c_index = tc - tm->connections[thread_index];
+ tc->c_c_index = tc - wrk->connections;
tc->c_thread_index = thread_index;
return tc;
}
void
tcp_connection_free (tcp_connection_t * tc)
{
- tcp_main_t *tm = &tcp_main;
+ tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index);
if (CLIB_DEBUG)
{
- u8 thread_index = tc->c_thread_index;
clib_memset (tc, 0xFA, sizeof (*tc));
- pool_put (tm->connections[thread_index], tc);
+ pool_put (wrk->connections, tc);
return;
}
- pool_put (tm->connections[tc->c_thread_index], tc);
-}
-
-/** Notify session that connection has been reset.
- *
- * Switch state to closed and wait for session to call cleanup.
- */
-void
-tcp_connection_reset (tcp_connection_t * tc)
-{
- TCP_EVT (TCP_EVT_RST_RCVD, tc);
- switch (tc->state)
- {
- case TCP_STATE_SYN_RCVD:
- /* Cleanup everything. App wasn't notified yet */
- session_transport_delete_notify (&tc->connection);
- tcp_connection_cleanup (tc);
- break;
- case TCP_STATE_SYN_SENT:
- session_stream_connect_notify (&tc->connection, 1 /* fail */ );
- tcp_connection_cleanup (tc);
- break;
- case TCP_STATE_ESTABLISHED:
- tcp_connection_timers_reset (tc);
- /* Set the cleanup timer, in case the session layer/app don't
- * cleanly close the connection */
- tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time);
- session_transport_reset_notify (&tc->connection);
- tcp_cong_recovery_off (tc);
- tcp_connection_set_state (tc, TCP_STATE_CLOSED);
- session_transport_closed_notify (&tc->connection);
- break;
- case TCP_STATE_CLOSE_WAIT:
- case TCP_STATE_FIN_WAIT_1:
- case TCP_STATE_FIN_WAIT_2:
- case TCP_STATE_CLOSING:
- case TCP_STATE_LAST_ACK:
- tcp_connection_timers_reset (tc);
- tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time);
- tcp_cong_recovery_off (tc);
- /* Make sure we mark the session as closed. In some states we may
- * be still trying to send data */
- tcp_connection_set_state (tc, TCP_STATE_CLOSED);
- session_transport_closed_notify (&tc->connection);
- break;
- case TCP_STATE_CLOSED:
- case TCP_STATE_TIME_WAIT:
- break;
- default:
- TCP_DBG ("reset state: %u", tc->state);
- }
+ pool_put (wrk->connections, tc);
}
/**
u32 num_threads, n_workers, prealloc_conn_per_wrk;
tcp_connection_t *tc __attribute__ ((unused));
tcp_main_t *tm = vnet_get_tcp_main ();
+ tcp_worker_ctx_t *wrk;
clib_error_t *error = 0;
int thread;
*/
num_threads = 1 /* main thread */ + vtm->n_threads;
- vec_validate (tm->connections, num_threads - 1);
vec_validate (tm->wrk_ctx, num_threads - 1);
n_workers = num_threads == 1 ? 1 : vtm->n_threads;
prealloc_conn_per_wrk = tcp_cfg.preallocated_connections / n_workers;
for (thread = 0; thread < num_threads; thread++)
{
- vec_validate (tm->wrk_ctx[thread].pending_deq_acked, 255);
- vec_validate (tm->wrk_ctx[thread].pending_disconnects, 255);
- vec_reset_length (tm->wrk_ctx[thread].pending_deq_acked);
- vec_reset_length (tm->wrk_ctx[thread].pending_disconnects);
- tm->wrk_ctx[thread].vm = vlib_mains[thread];
+ wrk = &tm->wrk_ctx[thread];
+
+ vec_validate (wrk->pending_deq_acked, 255);
+ vec_validate (wrk->pending_disconnects, 255);
+ vec_validate (wrk->pending_resets, 255);
+ vec_reset_length (wrk->pending_deq_acked);
+ vec_reset_length (wrk->pending_disconnects);
+ vec_reset_length (wrk->pending_resets);
+ wrk->vm = vlib_mains[thread];
/*
* Preallocate connections. Assume that thread 0 won't
* use preallocated threads when running multi-core
*/
if ((thread > 0 || num_threads == 1) && prealloc_conn_per_wrk)
- pool_init_fixed (tm->connections[thread], prealloc_conn_per_wrk);
+ pool_init_fixed (wrk->connections, prealloc_conn_per_wrk);
}
/*