+ 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;
+ }
+ if (session->session_state >= STATE_VPP_CLOSING)
+ return sid;
+
+ /* Caught a reset before actually accepting the session */
+ if (session->session_state == STATE_LISTEN)
+ {
+
+ if (!vcl_flag_accepted_session (session, reset_msg->handle,
+ VCL_ACCEPTED_F_RESET))
+ VDBG (0, "session was not accepted!");
+ return VCL_INVALID_SESSION_INDEX;
+ }
+
+ session->session_state = STATE_DISCONNECT;
+ VDBG (0, "reset session %u [0x%llx]", sid, reset_msg->handle);
+ 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 (0, "session %u [0x%llx]: listen succeeded!", sid, mp->handle);
+ return sid;
+}
+
+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 handle overlap %lu!", msg->handle);
+
+ 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->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;
+ }
+
+ /* 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;
+ }
+
+ session->session_state = STATE_VPP_CLOSING;
+ return session;
+}
+
+static int
+vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
+{
+ session_disconnected_msg_t *disconnected_msg;
+ vcl_session_t *session;
+