+static void
+vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data)
+{
+ session_unlisten_reply_msg_t *mp = (session_unlisten_reply_msg_t *) data;
+ vcl_session_t *s;
+
+ s = vcl_session_get_w_vpp_handle (wrk, mp->handle);
+ if (!s || s->session_state != STATE_DISCONNECT)
+ {
+ VDBG (0, "Unlisten reply with wrong handle %llx", mp->handle);
+ return;
+ }
+
+ if (mp->retval)
+ VDBG (0, "ERROR: session %u [0xllx]: unlisten failed: %U",
+ s->session_index, mp->handle, format_api_error, ntohl (mp->retval));
+
+ if (mp->context != wrk->wrk_index)
+ VDBG (0, "wrong context");
+
+ vcl_session_table_del_vpp_handle (wrk, mp->handle);
+ vcl_session_free (wrk, s);
+}
+
+static void
+vcl_session_migrated_handler (vcl_worker_t * wrk, void *data)
+{
+ session_migrated_msg_t *mp = (session_migrated_msg_t *) data;
+ vcl_session_t *s;
+
+ s = vcl_session_get_w_vpp_handle (wrk, mp->handle);
+ if (!s)
+ {
+ VDBG (0, "Migrated notification with wrong handle %llx", mp->handle);
+ return;
+ }
+
+ s->vpp_thread_index = mp->vpp_thread_index;
+ s->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
+
+ vec_validate (wrk->vpp_event_queues, s->vpp_thread_index);
+ wrk->vpp_event_queues[s->vpp_thread_index] = s->vpp_evt_q;
+
+ vcl_session_table_del_vpp_handle (wrk, mp->handle);
+ vcl_session_table_add_vpp_handle (wrk, mp->new_handle, s->session_index);
+
+ /* Generate new tx event if we have outstanding data */
+ if (svm_fifo_has_event (s->tx_fifo))
+ app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index,
+ SESSION_IO_EVT_TX, SVM_Q_WAIT);
+
+ VDBG (0, "Migrated 0x%x to thread %u", mp->handle, s->vpp_thread_index);
+}
+
+static vcl_session_t *
+vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg)
+{
+ vcl_session_msg_t *vcl_msg;
+ vcl_session_t *session;
+
+ session = vcl_session_get_w_vpp_handle (wrk, msg->handle);
+ if (PREDICT_FALSE (session != 0))
+ VWRN ("session overlap handle %lu state %u!", msg->handle,
+ session->session_state);
+
+ session = vcl_session_table_lookup_listener (wrk, msg->listener_handle);
+ if (!session)
+ {
+ VERR ("couldn't find listen session: listener handle %llx",
+ msg->listener_handle);
+ return 0;
+ }
+
+ clib_fifo_add2 (session->accept_evts_fifo, vcl_msg);
+ vcl_msg->flags = 0;
+ vcl_msg->accepted_msg = *msg;
+ /* Session handle points to listener until fully accepted by app */
+ vcl_session_table_add_vpp_handle (wrk, msg->handle, session->session_index);
+
+ return session;
+}
+
+static vcl_session_t *
+vcl_session_disconnected_handler (vcl_worker_t * wrk,
+ session_disconnected_msg_t * msg)
+{
+ vcl_session_t *session;
+
+ session = vcl_session_get_w_vpp_handle (wrk, msg->handle);
+ if (!session)
+ {
+ VDBG (0, "request to disconnect unknown handle 0x%llx", msg->handle);
+ return 0;
+ }
+
+ /* Late disconnect notification on a session that has been closed */
+ if (session->session_state == STATE_CLOSED)
+ return 0;
+
+ /* Caught a disconnect before actually accepting the session */
+ if (session->session_state == STATE_LISTEN)
+ {
+ if (!vcl_flag_accepted_session (session, msg->handle,
+ VCL_ACCEPTED_F_CLOSED))
+ VDBG (0, "session was not accepted!");
+ return 0;
+ }
+
+ /* If not already reset change state */
+ if (session->session_state != STATE_DISCONNECT)
+ session->session_state = STATE_VPP_CLOSING;
+
+ return session;
+}
+
+static void
+vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data)
+{
+ session_cleanup_msg_t *msg;
+ vcl_session_t *session;
+
+ msg = (session_cleanup_msg_t *) data;
+ session = vcl_session_get_w_vpp_handle (wrk, msg->handle);
+ if (!session)
+ {
+ VDBG (0, "disconnect confirmed for unknown handle 0x%llx", msg->handle);
+ return;
+ }
+
+ vcl_session_table_del_vpp_handle (wrk, msg->handle);
+ /* Should not happen. App did not close the connection so don't free it. */
+ if (session->session_state != STATE_CLOSED)
+ {
+ VDBG (0, "app did not close session %d", session->session_index);
+ session->session_state = STATE_DETACHED;
+ session->vpp_handle = VCL_INVALID_SESSION_HANDLE;
+ return;
+ }
+ vcl_session_free (wrk, session);
+}
+
+static void
+vcl_session_req_worker_update_handler (vcl_worker_t * wrk, void *data)
+{
+ session_req_worker_update_msg_t *msg;
+ vcl_session_t *s;
+
+ msg = (session_req_worker_update_msg_t *) data;
+ s = vcl_session_get_w_vpp_handle (wrk, msg->session_handle);
+ if (!s)
+ return;
+
+ vec_add1 (wrk->pending_session_wrk_updates, s->session_index);
+}
+
+static void
+vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
+{
+ session_worker_update_reply_msg_t *msg;
+ vcl_session_t *s;
+
+ msg = (session_worker_update_reply_msg_t *) data;
+ s = vcl_session_get_w_vpp_handle (wrk, msg->handle);
+ if (!s)
+ {
+ VDBG (0, "unknown handle 0x%llx", msg->handle);
+ return;
+ }
+ if (vcl_segment_is_not_mounted (wrk, msg->segment_handle))
+ {
+ clib_warning ("segment for session %u is not mounted!",
+ s->session_index);
+ return;
+ }
+
+ if (s->rx_fifo)
+ {
+ s->rx_fifo = uword_to_pointer (msg->rx_fifo, svm_fifo_t *);
+ s->tx_fifo = uword_to_pointer (msg->tx_fifo, svm_fifo_t *);
+ s->rx_fifo->client_session_index = s->session_index;
+ s->tx_fifo->client_session_index = s->session_index;
+ s->rx_fifo->client_thread_index = wrk->wrk_index;
+ s->tx_fifo->client_thread_index = wrk->wrk_index;
+ }
+ s->session_state = STATE_UPDATED;
+
+ VDBG (0, "session %u[0x%llx] moved to worker %u", s->session_index,
+ s->vpp_handle, wrk->wrk_index);
+}
+
+static void
+vcl_session_app_add_segment_handler (vcl_worker_t * wrk, void *data)
+{
+ ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM;
+ session_app_add_segment_msg_t *msg;
+ u64 segment_handle;
+ int fd = -1;
+
+ msg = (session_app_add_segment_msg_t *) data;
+
+ if (msg->fd_flags)
+ {
+ vl_socket_client_recv_fd_msg2 (&wrk->bapi_sock_ctx, &fd, 1, 5);
+ seg_type = SSVM_SEGMENT_MEMFD;
+ }
+
+ segment_handle = msg->segment_handle;
+ if (segment_handle == VCL_INVALID_SEGMENT_HANDLE)
+ {
+ clib_warning ("invalid segment handle");
+ return;
+ }
+
+ if (vcl_segment_attach (segment_handle, (char *) msg->segment_name,
+ seg_type, fd))
+ {
+ VDBG (0, "vcl_segment_attach ('%s') failed", msg->segment_name);
+ return;
+ }
+
+ VDBG (1, "mapped new segment '%s' size %d", msg->segment_name,
+ msg->segment_size);
+}
+
+static void
+vcl_session_app_del_segment_handler (vcl_worker_t * wrk, void *data)
+{
+ session_app_del_segment_msg_t *msg = (session_app_del_segment_msg_t *) data;
+ vcl_segment_detach (msg->segment_handle);
+ VDBG (1, "Unmapped segment: %d", msg->segment_handle);
+}
+