session_free_w_fifos (s);
}
+void
+session_cleanup_half_open (transport_proto_t tp, session_handle_t ho_handle)
+{
+ transport_cleanup_half_open (tp, session_handle_index (ho_handle));
+}
+
+void
+session_half_open_delete_notify (transport_proto_t tp,
+ session_handle_t ho_handle)
+{
+ app_worker_t *app_wrk = app_worker_get (session_handle_data (ho_handle));
+ app_worker_del_half_open (app_wrk, tp, ho_handle);
+}
+
session_t *
session_alloc_for_connection (transport_connection_t * tc)
{
SESSION_EVT (SESSION_EVT_ENQ, s, svm_fifo_max_dequeue_prod (s->rx_fifo));
s->flags &= ~SESSION_F_RX_EVT;
+
+ /* Application didn't confirm accept yet */
+ if (PREDICT_FALSE (s->session_state == SESSION_STATE_ACCEPTING))
+ return 0;
+
if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
SESSION_IO_EVT_RX)))
return -1;
return errors;
}
-static inline int
-session_stream_connect_notify_inline (transport_connection_t * tc,
- session_error_t err,
- session_state_t opened_state)
+int
+session_stream_connect_notify (transport_connection_t * tc,
+ session_error_t err)
{
+ session_handle_t ho_handle, wrk_handle;
u32 opaque = 0, new_ti, new_si;
app_worker_t *app_wrk;
session_t *s = 0;
- u64 ho_handle;
/*
* Find connection handle and cleanup half-open table
/* Get the app's index from the handle we stored when opening connection
* and the opaque (api_context for external apps) from transport session
* index */
- app_wrk = app_worker_get_if_valid (ho_handle >> 32);
+ app_wrk = app_worker_get_if_valid (session_handle_data (ho_handle));
if (!app_wrk)
return -1;
- opaque = tc->s_index;
+ wrk_handle = app_worker_lookup_half_open (app_wrk, tc->proto, ho_handle);
+ if (wrk_handle == SESSION_INVALID_HANDLE)
+ return -1;
+
+ /* Make sure this is the same half-open index */
+ if (session_handle_index (wrk_handle) != session_handle_index (ho_handle))
+ return -1;
+
+ opaque = session_handle_data (wrk_handle);
if (err)
return app_worker_connect_notify (app_wrk, s, err, opaque);
}
s = session_get (new_si, new_ti);
- s->session_state = opened_state;
+ s->session_state = SESSION_STATE_READY;
session_lookup_add_connection (tc, session_handle (s));
if (app_worker_connect_notify (app_wrk, s, SESSION_E_NONE, opaque))
{
+ session_lookup_del_connection (tc);
+ /* Avoid notifying app about rejected session cleanup */
s = session_get (new_si, new_ti);
- session_free_w_fifos (s);
+ segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo);
+ session_free (s);
return -1;
}
return 0;
}
-int
-session_stream_connect_notify (transport_connection_t * tc,
- session_error_t err)
-{
- return session_stream_connect_notify_inline (tc, err, SESSION_STATE_READY);
-}
-
-int
-session_ho_stream_connect_notify (transport_connection_t * tc,
- session_error_t err)
-{
- return session_stream_connect_notify_inline (tc, err, SESSION_STATE_OPENED);
-}
-
static void
session_switch_pool_reply (void *arg)
{
{
transport_connection_t *tc;
transport_endpoint_cfg_t *tep;
- u64 handle;
+ u64 handle, wrk_handle;
int rv;
tep = session_endpoint_to_transport_cfg (rmt);
* is needed when the connect notify comes and we have to notify the
* external app
*/
- handle = (((u64) app_wrk_index) << 32) | (u64) tc->c_index;
+ handle = session_make_handle (tc->c_index, app_wrk_index);
session_lookup_add_half_open (tc, handle);
- /* Store api_context (opaque) for when the reply comes. Not the nicest
- * thing but better than allocating a separate half-open pool.
+ /* Store the half-open handle in the connection. Transport will use it
+ * when cleaning up @ref session_half_open_delete_notify
*/
- tc->s_index = opaque;
- if (transport_half_open_has_fifos (rmt->transport_proto))
- return session_ho_stream_connect_notify (tc, 0 /* is_fail */ );
+ tc->s_ho_handle = handle;
+
+ /* Track the half-open connections in case we want to forcefully
+ * clean them up @ref session_cleanup_half_open
+ */
+ wrk_handle = session_make_handle (tc->c_index, opaque);
+ app_worker_add_half_open (app_worker_get (app_wrk_index),
+ rmt->transport_proto, handle, wrk_handle);
+
return 0;
}
eqs_size = smm->evt_qs_segment_size;
eqs->ssvm_size = eqs_size;
- eqs->i_am_master = 1;
eqs->my_pid = vpp_pid;
- eqs->name = format (0, "%s%c", "evt-qs-segment", 0);
- eqs->requested_va = smm->session_baseva;
+ eqs->name = format (0, "%s%c", "session: evt-qs-segment", 0);
+ /* clib_mem_vm_map_shared consumes first page before requested_va */
+ eqs->requested_va = smm->session_baseva + clib_mem_get_page_size ();
- if (ssvm_master_init (eqs, SSVM_SEGMENT_MEMFD))
+ if (ssvm_server_init (eqs, SSVM_SEGMENT_MEMFD))
{
clib_warning ("failed to initialize queue segment");
return;
session_main_t *smm = &session_main;
vlib_thread_main_t *vtm = vlib_get_thread_main ();
u32 num_threads, preallocated_sessions_per_worker;
+ uword margin = 8 << 12;
session_worker_t *wrk;
int i;
+ /* We only initialize once and do not de-initialized on disable */
+ if (smm->is_initialized)
+ goto done;
+
num_threads = 1 /* main thread */ + vtm->n_threads;
if (num_threads < 1)
wrk->new_head = clib_llist_make_head (wrk->event_elts, evt_list);
wrk->old_head = clib_llist_make_head (wrk->event_elts, evt_list);
wrk->vm = vlib_mains[i];
- wrk->last_vlib_time = vlib_time_now (vlib_mains[i]);
+ wrk->last_vlib_time = vlib_time_now (vm);
wrk->last_vlib_us_time = wrk->last_vlib_time * CLIB_US_TIME_FREQ;
vec_validate (wrk->session_to_enqueue, smm->last_transport_proto_type);
session_vpp_event_queues_allocate (smm);
/* Initialize fifo segment main baseva and timeout */
- sm_args->baseva = smm->session_baseva + smm->evt_qs_segment_size;
+ sm_args->baseva = smm->session_baseva + smm->evt_qs_segment_size + margin;
sm_args->size = smm->session_va_space_size;
segment_manager_main_init (sm_args);
session_lookup_init ();
app_namespaces_init ();
transport_init ();
+ smm->is_initialized = 1;
+
+done:
smm->is_enabled = 1;
return 0;
}
+static void
+session_manager_main_disable (vlib_main_t * vm)
+{
+ transport_enable_disable (vm, 0 /* is_en */ );
+}
+
void
session_node_enable_disable (u8 is_en)
{
foreach_vlib_main (({
if (have_workers && ii == 0)
{
- vlib_node_set_state (this_vlib_main, session_queue_process_node.index,
- state);
if (is_en)
{
+ vlib_node_set_state (this_vlib_main,
+ session_queue_process_node.index, state);
vlib_node_t *n = vlib_get_node (this_vlib_main,
session_queue_process_node.index);
vlib_start_process (this_vlib_main, n->runtime_index);
else
{
session_main.is_enabled = 0;
+ session_manager_main_disable (vm);
session_node_enable_disable (is_en);
}
#endif
smm->last_transport_proto_type = TRANSPORT_PROTO_QUIC;
+ smm->evt_qs_use_memfd_seg = 1;
return 0;
}
;
else if (unformat (input, "enable"))
smm->session_enable_asap = 1;
+ else if (unformat (input, "segment-baseva 0x%lx", &smm->session_baseva))
+ ;
+ else if (unformat (input, "use-app-socket-api"))
+ appns_sapi_enable ();
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);