+ rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
+ tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
+ if (vcl_wait_for_segment (mp->segment_handle))
+ {
+ clib_warning ("segment for session %u couldn't be mounted!",
+ session->session_index);
+ return VCL_INVALID_SESSION_INDEX;
+ }
+
+ rx_fifo->client_session_index = session_index;
+ tx_fifo->client_session_index = session_index;
+ rx_fifo->client_thread_index = vcl_get_worker_index ();
+ tx_fifo->client_thread_index = vcl_get_worker_index ();
+
+ if (mp->client_event_queue_address)
+ {
+ session->vpp_evt_q = uword_to_pointer (mp->server_event_queue_address,
+ svm_msg_q_t *);
+ session->our_evt_q = uword_to_pointer (mp->client_event_queue_address,
+ svm_msg_q_t *);
+
+ vec_validate (wrk->vpp_event_queues, 0);
+ evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *);
+ wrk->vpp_event_queues[0] = evt_q;
+ }
+ else
+ {
+ session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
+ svm_msg_q_t *);
+ vpp_wrk_index = tx_fifo->master_thread_index;
+ vec_validate (wrk->vpp_event_queues, vpp_wrk_index);
+ wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q;
+ }
+
+ session->rx_fifo = rx_fifo;
+ session->tx_fifo = tx_fifo;
+ session->vpp_handle = mp->handle;
+ session->transport.is_ip4 = mp->is_ip4;
+ clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip,
+ sizeof (session->transport.lcl_ip));
+ session->transport.lcl_port = mp->lcl_port;
+ session->session_state = STATE_CONNECT;
+
+ /* Add it to lookup table */
+ hash_set (wrk->session_index_by_vpp_handles, mp->handle, session_index);
+
+ VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded! "
+ "session_rx_fifo %p, refcnt %d, session_tx_fifo %p, refcnt %d",
+ getpid (), mp->handle, session_index, session->rx_fifo,
+ session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt);
+
+ return session_index;
+}
+
+static u32
+vcl_session_reset_handler (vcl_worker_t * wrk,
+ session_reset_msg_t * reset_msg)
+{
+ vcl_session_t *session;
+ u32 sid;
+
+ sid = vcl_session_index_from_vpp_handle (wrk, reset_msg->handle);
+ session = vcl_session_get (wrk, sid);
+ if (!session)
+ {
+ VDBG (0, "request to reset unknown handle 0x%llx", reset_msg->handle);
+ return VCL_INVALID_SESSION_INDEX;
+ }
+ session->session_state = STATE_CLOSE_ON_EMPTY;
+ VDBG (0, "reset handle 0x%llx, sid %u ", reset_msg->handle, sid);
+ vcl_send_session_reset_reply (vcl_session_vpp_evt_q (wrk, session),
+ wrk->my_client_index, reset_msg->handle, 0);
+ return sid;
+}
+
+static u32
+vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp)
+{
+ vcl_session_t *session;
+ u32 sid = mp->context;
+
+ session = vcl_session_get (wrk, sid);
+ if (mp->retval)
+ {
+ VERR ("vpp handle 0x%llx, sid %u: bind failed: %U", mp->handle, sid,
+ format_api_error, mp->retval);
+ if (session)
+ {
+ session->session_state = STATE_FAILED;
+ session->vpp_handle = mp->handle;
+ return sid;
+ }
+ else
+ {
+ clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
+ "Invalid session index (%u)!",
+ getpid (), mp->handle, sid);
+ return VCL_INVALID_SESSION_INDEX;
+ }
+ }
+
+ session->vpp_handle = mp->handle;
+ session->transport.is_ip4 = mp->lcl_is_ip4;
+ clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip,
+ sizeof (ip46_address_t));
+ session->transport.lcl_port = mp->lcl_port;
+ vcl_session_table_add_listener (wrk, mp->handle, sid);
+ session->session_state = STATE_LISTEN;
+
+ if (session->is_dgram)
+ {
+ svm_fifo_t *rx_fifo, *tx_fifo;
+ session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
+ rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *);
+ rx_fifo->client_session_index = sid;
+ tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *);
+ tx_fifo->client_session_index = sid;
+ session->rx_fifo = rx_fifo;
+ session->tx_fifo = tx_fifo;
+ }
+
+ VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!",
+ getpid (), mp->handle, sid);
+ return sid;
+}
+
+static int
+vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
+{
+ session_accepted_msg_t *accepted_msg;
+ session_disconnected_msg_t *disconnected_msg;
+ vcl_session_msg_t *vcl_msg;
+ vcl_session_t *session;
+ u64 handle;
+ u32 sid;
+
+ switch (e->event_type)
+ {
+ case FIFO_EVENT_APP_RX:
+ case FIFO_EVENT_APP_TX:
+ case SESSION_IO_EVT_CT_RX:
+ case SESSION_IO_EVT_CT_TX:
+ vec_add1 (wrk->unhandled_evts_vector, *e);
+ break;
+ case SESSION_CTRL_EVT_ACCEPTED:
+ accepted_msg = (session_accepted_msg_t *) e->data;
+ handle = accepted_msg->listener_handle;
+ session = vcl_session_table_lookup_listener (wrk, handle);
+ if (!session)
+ {
+ clib_warning ("VCL<%d>: ERROR: couldn't find listen session:"
+ "listener handle %llx", getpid (), handle);
+ break;
+ }
+
+ clib_fifo_add2 (session->accept_evts_fifo, vcl_msg);
+ vcl_msg->accepted_msg = *accepted_msg;
+ break;
+ case SESSION_CTRL_EVT_CONNECTED:
+ vcl_session_connected_handler (wrk,
+ (session_connected_msg_t *) e->data);
+ break;
+ case SESSION_CTRL_EVT_DISCONNECTED:
+ disconnected_msg = (session_disconnected_msg_t *) e->data;
+ sid = vcl_session_index_from_vpp_handle (wrk, disconnected_msg->handle);
+ session = vcl_session_get (wrk, sid);
+ if (!session)
+ {
+ VDBG (0, "request to disconnect unknown handle 0x%llx",
+ disconnected_msg->handle);
+ break;
+ }
+ session->session_state = STATE_DISCONNECT;
+ VDBG (0, "disconnected handle 0x%llx, sid %u", disconnected_msg->handle,
+ sid);
+ break;
+ case SESSION_CTRL_EVT_RESET:
+ vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data);
+ break;
+ case SESSION_CTRL_EVT_BOUND:
+ vcl_session_bound_handler (wrk, (session_bound_msg_t *) e->data);
+ break;
+ default:
+ clib_warning ("unhandled %u", e->event_type);
+ }
+ return VPPCOM_OK;