session: use teps in accept/connect notifications
[vpp.git] / src / vnet / session / session_api.c
index 81654e4..0a7781f 100755 (executable)
@@ -49,8 +49,6 @@ _(UNBIND_URI, unbind_uri)                                               \
 _(CONNECT_URI, connect_uri)                                             \
 _(DISCONNECT_SESSION, disconnect_session)                               \
 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply)                   \
-_(ACCEPT_SESSION_REPLY, accept_session_reply)                           \
-_(RESET_SESSION_REPLY, reset_session_reply)                            \
 _(BIND_SOCK, bind_sock)                                                        \
 _(UNBIND_SOCK, unbind_sock)                                             \
 _(CONNECT_SOCK, connect_sock)                                                  \
@@ -151,237 +149,6 @@ send_del_segment_callback (u32 api_client_index, u64 segment_handle)
   return 0;
 }
 
-static int
-send_app_cut_through_registration_add (u32 api_client_index,
-                                      u32 wrk_map_index, u64 mq_addr,
-                                      u64 peer_mq_addr)
-{
-  vl_api_app_cut_through_registration_add_t *mp;
-  vl_api_registration_t *reg;
-  svm_msg_q_t *mq, *peer_mq;
-  int fds[2];
-
-  reg = vl_mem_api_client_index_to_registration (api_client_index);
-  if (!reg)
-    {
-      clib_warning ("no registration: %u", api_client_index);
-      return -1;
-    }
-
-  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id =
-    clib_host_to_net_u16 (VL_API_APP_CUT_THROUGH_REGISTRATION_ADD);
-
-  mp->evt_q_address = mq_addr;
-  mp->peer_evt_q_address = peer_mq_addr;
-  mp->wrk_index = wrk_map_index;
-
-  mq = uword_to_pointer (mq_addr, svm_msg_q_t *);
-  peer_mq = uword_to_pointer (peer_mq_addr, svm_msg_q_t *);
-
-  if (svm_msg_q_get_producer_eventfd (mq) != -1)
-    {
-      mp->fd_flags |= SESSION_FD_F_MQ_EVENTFD;
-      mp->n_fds = 2;
-      /* app will overwrite exactly the fds we pass here. So
-       * when we swap mq with peer_mq (accept vs connect) the
-       * fds will still be valid */
-      fds[0] = svm_msg_q_get_consumer_eventfd (mq);
-      fds[1] = svm_msg_q_get_producer_eventfd (peer_mq);
-    }
-
-  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
-
-  if (mp->n_fds != 0)
-    session_send_fds (reg, fds, mp->n_fds);
-
-  return 0;
-}
-
-static int
-send_session_accept_callback (session_t * s)
-{
-  app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
-  vl_api_accept_session_t *mp;
-  vl_api_registration_t *reg;
-  transport_connection_t *tc;
-  session_t *listener;
-  svm_msg_q_t *vpp_queue;
-  application_t *server;
-  app_listener_t *al;
-
-  server = application_get (server_wrk->app_index);
-  reg =
-    vl_mem_api_client_index_to_registration (server_wrk->api_client_index);
-  if (!reg)
-    {
-      clib_warning ("no registration: %u", server_wrk->api_client_index);
-      return -1;
-    }
-
-  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-
-  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
-  mp->context = server_wrk->wrk_index;
-  mp->server_rx_fifo = pointer_to_uword (s->rx_fifo);
-  mp->server_tx_fifo = pointer_to_uword (s->tx_fifo);
-
-  if (session_has_transport (s))
-    {
-      listener = listen_session_get (s->listener_index);
-      al = app_listener_get (server, listener->al_index);
-      mp->listener_handle = app_listener_handle (al);
-      if (application_is_proxy (server))
-       {
-         listener =
-           app_worker_first_listener (server_wrk, session_get_fib_proto (s),
-                                      session_get_transport_proto (s));
-         if (listener)
-           mp->listener_handle = listen_session_get_handle (listener);
-       }
-      vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
-      mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
-      mp->handle = session_handle (s);
-      tc = transport_get_connection (session_get_transport_proto (s),
-                                    s->connection_index, s->thread_index);
-      mp->port = tc->rmt_port;
-      mp->is_ip4 = tc->is_ip4;
-      clib_memcpy_fast (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
-    }
-  else
-    {
-      ct_connection_t *ct;
-      ct = (ct_connection_t *) session_get_transport (s);
-      listener = listen_session_get (s->listener_index);
-      al = app_listener_get (server, listener->al_index);
-      mp->listener_handle = app_listener_handle (al);
-      mp->is_ip4 = session_type_is_ip4 (listener->session_type);
-      mp->handle = session_handle (s);
-      mp->port = ct->c_rmt_port;
-      mp->vpp_event_queue_address = ct->client_evt_q;
-      mp->server_event_queue_address = ct->server_evt_q;
-    }
-  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
-
-  return 0;
-}
-
-static void
-send_session_disconnect_callback (session_t * s)
-{
-  app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
-  vl_api_disconnect_session_t *mp;
-  vl_api_registration_t *reg;
-
-  reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
-  if (!reg)
-    {
-      clib_warning ("no registration: %u", app_wrk->api_client_index);
-      return;
-    }
-
-  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
-  mp->handle = session_handle (s);
-  mp->context = app_wrk->api_client_index;
-  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
-}
-
-static void
-send_session_reset_callback (session_t * s)
-{
-  app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
-  vl_api_registration_t *reg;
-  vl_api_reset_session_t *mp;
-
-  reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
-  if (!reg)
-    {
-      clib_warning ("no registration: %u", app_wrk->api_client_index);
-      return;
-    }
-
-  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
-  mp->handle = session_handle (s);
-  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
-}
-
-int
-send_session_connected_callback (u32 app_wrk_index, u32 api_context,
-                                session_t * s, u8 is_fail)
-{
-  vl_api_connect_session_reply_t *mp;
-  transport_connection_t *tc;
-  vl_api_registration_t *reg;
-  svm_msg_q_t *vpp_queue;
-  app_worker_t *app_wrk;
-
-  app_wrk = app_worker_get (app_wrk_index);
-  reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
-  if (!reg)
-    {
-      clib_warning ("no registration: %u", app_wrk->api_client_index);
-      return -1;
-    }
-
-  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
-  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
-  mp->context = api_context;
-
-  if (is_fail)
-    goto done;
-
-  if (session_has_transport (s))
-    {
-      tc = session_get_transport (s);
-      if (!tc)
-       {
-         is_fail = 1;
-         goto done;
-       }
-
-      vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
-      mp->handle = session_handle (s);
-      mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
-      clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
-      mp->is_ip4 = tc->is_ip4;
-      mp->lcl_port = tc->lcl_port;
-      mp->server_rx_fifo = pointer_to_uword (s->rx_fifo);
-      mp->server_tx_fifo = pointer_to_uword (s->tx_fifo);
-    }
-  else
-    {
-      ct_connection_t *ct;
-      ct = (ct_connection_t *) session_get_transport (s);
-      mp->handle = session_handle (s);
-      mp->lcl_port = ct->c_lcl_port;
-      mp->vpp_event_queue_address = ct->server_evt_q;
-      mp->client_event_queue_address = ct->client_evt_q;
-      mp->server_rx_fifo = pointer_to_uword (s->tx_fifo);
-      mp->server_tx_fifo = pointer_to_uword (s->rx_fifo);
-    }
-
-done:
-  mp->retval = is_fail ?
-    clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
-  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
-  return 0;
-}
-
-static session_cb_vft_t session_cb_vft = {
-  .session_accept_callback = send_session_accept_callback,
-  .session_disconnect_callback = send_session_disconnect_callback,
-  .session_connected_callback = send_session_connected_callback,
-  .session_reset_callback = send_session_reset_callback,
-  .add_segment_callback = send_add_segment_callback,
-  .del_segment_callback = send_del_segment_callback,
-};
-
 static int
 mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg)
 {
@@ -407,7 +174,6 @@ mq_send_session_accepted_cb (session_t * s)
   app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
   svm_msg_q_msg_t _msg, *msg = &_msg;
   svm_msg_q_t *vpp_queue, *app_mq;
-  transport_connection_t *tc;
   session_t *listener;
   session_accepted_msg_t *mp;
   session_event_t *evt;
@@ -442,36 +208,25 @@ mq_send_session_accepted_cb (session_t * s)
          if (listener)
            mp->listener_handle = listen_session_get_handle (listener);
        }
-      vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
+      vpp_queue = session_main_get_vpp_event_queue (s->thread_index);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
       mp->handle = session_handle (s);
-      tc = transport_get_connection (session_get_transport_proto (s),
-                                    s->connection_index, s->thread_index);
-      mp->port = tc->rmt_port;
-      mp->is_ip4 = tc->is_ip4;
-      clib_memcpy_fast (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
+
+      session_get_endpoint (s, &mp->rmt, 0 /* is_lcl */ );
     }
   else
     {
-      u8 main_thread = vlib_num_workers ()? 1 : 0;
       ct_connection_t *ct;
 
       ct = (ct_connection_t *) session_get_transport (s);
-      send_app_cut_through_registration_add (app_wrk->api_client_index,
-                                            app_wrk->wrk_map_index,
-                                            ct->server_evt_q,
-                                            ct->client_evt_q);
-
       listener = listen_session_get (s->listener_index);
       al = app_listener_get (app, listener->al_index);
       mp->listener_handle = app_listener_handle (al);
-      mp->is_ip4 = session_type_is_ip4 (listener->session_type);
+      mp->rmt.is_ip4 = session_type_is_ip4 (listener->session_type);
+      mp->rmt.port = ct->c_rmt_port;
       mp->handle = session_handle (s);
-      mp->port = ct->c_rmt_port;
-      vpp_queue = session_manager_get_vpp_event_queue (main_thread);
+      vpp_queue = session_main_get_vpp_event_queue (0);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
-      mp->client_event_queue_address = ct->client_evt_q;
-      mp->server_event_queue_address = ct->server_evt_q;
     }
   svm_msg_q_add_and_unlock (app_mq, msg);
 
@@ -588,38 +343,34 @@ mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
          goto done;
        }
 
-      vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
+      vpp_mq = session_main_get_vpp_event_queue (s->thread_index);
       mp->handle = session_handle (s);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
-      clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
-      mp->is_ip4 = tc->is_ip4;
-      mp->lcl_port = tc->lcl_port;
+
+      session_get_endpoint (s, &mp->lcl, 1 /* is_lcl */ );
+
       mp->server_rx_fifo = pointer_to_uword (s->rx_fifo);
       mp->server_tx_fifo = pointer_to_uword (s->tx_fifo);
       mp->segment_handle = session_segment_handle (s);
     }
   else
     {
-      u8 main_thread = vlib_num_workers ()? 1 : 0;
       ct_connection_t *cct;
       session_t *ss;
 
       cct = (ct_connection_t *) session_get_transport (s);
-      send_app_cut_through_registration_add (app_wrk->api_client_index,
-                                            app_wrk->wrk_map_index,
-                                            cct->client_evt_q,
-                                            cct->server_evt_q);
-
       mp->handle = session_handle (s);
-      mp->lcl_port = cct->c_lcl_port;
-      vpp_mq = session_manager_get_vpp_event_queue (main_thread);
+      mp->lcl.port = cct->c_lcl_port;
+      mp->lcl.is_ip4 = cct->c_is_ip4;
+      vpp_mq = session_main_get_vpp_event_queue (0);
       mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
-      mp->client_event_queue_address = cct->client_evt_q;
-      mp->server_event_queue_address = cct->server_evt_q;
+      mp->server_rx_fifo = pointer_to_uword (s->rx_fifo);
+      mp->server_tx_fifo = pointer_to_uword (s->tx_fifo);
+      mp->segment_handle = session_segment_handle (s);
       ss = ct_session_get_peer (s);
-      mp->server_rx_fifo = pointer_to_uword (ss->tx_fifo);
-      mp->server_tx_fifo = pointer_to_uword (ss->rx_fifo);
-      mp->segment_handle = session_segment_handle (ss);
+      mp->ct_rx_fifo = pointer_to_uword (ss->tx_fifo);
+      mp->ct_tx_fifo = pointer_to_uword (ss->rx_fifo);
+      mp->ct_segment_handle = session_segment_handle (ss);
     }
 
 done:
@@ -642,7 +393,6 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
   session_event_t *evt;
   app_listener_t *al;
   session_t *ls = 0;
-
   app_wrk = app_worker_get (app_wrk_index);
   app_mq = app_wrk->event_queue;
   if (!app_mq)
@@ -675,7 +425,7 @@ mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
   mp->lcl_is_ip4 = tc->is_ip4;
   clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
 
-  vpp_evt_q = session_manager_get_vpp_event_queue (0);
+  vpp_evt_q = session_main_get_vpp_event_queue (0);
   mp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
 
   if (session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
@@ -724,7 +474,7 @@ vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
   if (!reg)
     return;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -737,12 +487,7 @@ vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
   clib_memset (a, 0, sizeof (*a));
   a->api_client_index = mp->client_index;
   a->options = mp->options;
-
-  if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
-    a->session_cb_vft = &session_mq_cb_vft;
-  else
-    a->session_cb_vft = &session_cb_vft;
-
+  a->session_cb_vft = &session_mq_cb_vft;
   if (mp->namespace_id_len > 64)
     {
       rv = VNET_API_ERROR_INVALID_VALUE;
@@ -765,7 +510,7 @@ vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
   vec_free (a->namespace_id);
 
   /* Send event queues segment */
-  if ((evt_q_segment = session_manager_get_evt_q_segment ()))
+  if ((evt_q_segment = session_main_get_evt_q_segment ()))
     {
       fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
       fds[n_fds] = evt_q_segment->fd;
@@ -820,7 +565,7 @@ vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
   vnet_app_detach_args_t _a, *a = &_a;
   application_t *app;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -841,16 +586,13 @@ done:
 static void
 vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
 {
-  transport_connection_t *tc = 0;
-  vnet_listen_args_t _a, *a = &_a;
   vl_api_bind_uri_reply_t *rmp;
-  session_t *s;
+  vnet_listen_args_t _a, *a = &_a;
   application_t *app = 0;
-  svm_msg_q_t *vpp_evt_q;
   app_worker_t *app_wrk;
   int rv;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -871,33 +613,9 @@ vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
 
 done:
 
-  /* *INDENT-OFF* */
-  REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
-    if (!rv)
-      {
-        rmp->handle = a->handle;
-        if (app && application_has_global_scope (app))
-            {
-              app_listener_t* al = app_listener_get_w_handle(a->handle);
-              s = app_listener_get_session(al);
-              tc = listen_session_get_transport (s);
-              rmp->lcl_is_ip4 = tc->is_ip4;
-              rmp->lcl_port = tc->lcl_port;
-              clib_memcpy_fast (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
-              if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
-                {
-                  rmp->rx_fifo = pointer_to_uword (s->rx_fifo);
-                  rmp->tx_fifo = pointer_to_uword (s->tx_fifo);
-                  vpp_evt_q = session_manager_get_vpp_event_queue (0);
-                  rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
-                }
-            }
-      }
-  }));
-  /* *INDENT-ON* */
+  REPLY_MACRO (VL_API_BIND_URI_REPLY);
 
-  /* If app uses mq for control messages, send an mq message as well */
-  if (app && application_use_mq_for_ctrl (app))
+  if (app)
     {
       app_wrk = application_get_worker (app, 0);
       mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
@@ -913,7 +631,7 @@ vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
   vnet_unlisten_args_t _a, *a = &_a;
   int rv;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -938,12 +656,12 @@ done:
 static void
 vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
 {
-  vl_api_connect_session_reply_t *rmp;
+  vl_api_connect_uri_reply_t *rmp;
   vnet_connect_args_t _a, *a = &_a;
   application_t *app;
   int rv = 0;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -973,9 +691,7 @@ vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
     return;
 
 done:
-  /* *INDENT-OFF* */
-  REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
-  /* *INDENT-ON* */
+  REPLY_MACRO (VL_API_CONNECT_URI_REPLY);
 }
 
 static void
@@ -986,7 +702,7 @@ vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
   application_t *app;
   int rv = 0;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1032,81 +748,6 @@ vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
     }
 }
 
-static void
-vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
-{
-  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
-  app_worker_t *app_wrk;
-  application_t *app;
-  session_t *s;
-  u32 index, thread_index;
-
-  app = application_lookup (mp->context);
-  if (!app)
-    return;
-
-  session_parse_handle (mp->handle, &index, &thread_index);
-  s = session_get_if_valid (index, thread_index);
-  if (!s)
-    {
-      clib_warning ("Invalid session!");
-      return;
-    }
-
-  app_wrk = app_worker_get (s->app_wrk_index);
-  if (app_wrk->app_index != app->app_index)
-    {
-      clib_warning ("app %u does not own handle 0x%lx", app->app_index,
-                   mp->handle);
-      return;
-    }
-
-  /* Client objected to resetting the session, log and continue */
-  if (mp->retval)
-    {
-      clib_warning ("client retval %d", mp->retval);
-      return;
-    }
-
-  /* This comes as a response to a reset, transport only waiting for
-   * confirmation to remove connection state, no need to disconnect */
-  a->handle = mp->handle;
-  a->app_index = app->app_index;
-  vnet_disconnect_session (a);
-}
-
-static void
-vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
-{
-  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
-  session_t *s;
-
-  /* Server isn't interested, kill the session */
-  if (mp->retval)
-    {
-      a->app_index = mp->context;
-      a->handle = mp->handle;
-      vnet_disconnect_session (a);
-      return;
-    }
-
-  s = session_get_from_handle_if_valid (mp->handle);
-  if (!s)
-    {
-      clib_warning ("session doesn't exist");
-      return;
-    }
-  if (s->app_wrk_index != mp->context)
-    {
-      clib_warning ("app doesn't own session");
-      return;
-    }
-  s->session_state = SESSION_STATE_READY;
-
-  if (!session_has_transport (s))
-    ct_session_connect_notify (s);
-}
-
 static void
 vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
                                            * mp)
@@ -1118,17 +759,13 @@ static void
 vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
 {
   vnet_listen_args_t _a, *a = &_a;
-  transport_connection_t *tc = 0;
   vl_api_bind_sock_reply_t *rmp;
-  svm_msg_q_t *vpp_evt_q;
   application_t *app = 0;
   app_worker_t *app_wrk;
   ip46_address_t *ip46;
-  app_listener_t *al;
-  session_t *s;
   int rv = 0;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1156,33 +793,10 @@ vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
     clib_warning ("listen returned: %d", rv);
 
 done:
-  /* *INDENT-OFF* */
-  REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
-    if (!rv)
-      {
-       rmp->handle = a->handle;
-        rmp->lcl_port = mp->port;
-       rmp->lcl_is_ip4 = mp->is_ip4;
-       if (app && application_has_global_scope (app))
-         {
-           al = app_listener_get_w_handle (a->handle);
-           s = app_listener_get_session (al);
-           tc = listen_session_get_transport (s);
-            clib_memcpy_fast (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
-            if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
-              {
-               rmp->rx_fifo = pointer_to_uword (s->rx_fifo);
-               rmp->tx_fifo = pointer_to_uword (s->tx_fifo);
-               vpp_evt_q = session_manager_get_vpp_event_queue (0);
-               rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
-              }
-         }
-      }
-  }));
-  /* *INDENT-ON* */
+  /* Actual reply sent only over mq */
+  REPLY_MACRO (VL_API_BIND_SOCK_REPLY);
 
-  /* If app uses mq for control messages, send an mq message as well */
-  if (app && application_use_mq_for_ctrl (app))
+  if (app)
     {
       app_wrk = application_get_worker (app, mp->wrk_index);
       mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
@@ -1199,7 +813,7 @@ vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
   application_t *app = 0;
   int rv = 0;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1250,12 +864,12 @@ done:
 static void
 vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
 {
-  vl_api_connect_session_reply_t *rmp;
+  vl_api_connect_sock_reply_t *rmp;
   vnet_connect_args_t _a, *a = &_a;
   application_t *app = 0;
   int rv = 0;
 
-  if (session_manager_is_enabled () == 0)
+  if (session_main_is_enabled () == 0)
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1300,9 +914,9 @@ vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
   /* Got some error, relay it */
 
 done:
-  REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
+  REPLY_MACRO (VL_API_CONNECT_SOCK_REPLY);
 
-  if (app && application_use_mq_for_ctrl (app))
+  if (app)
     {
       app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index);
       mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1);
@@ -1318,7 +932,7 @@ vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
   application_t *app;
   u8 fd_flags = 0;
 
-  if (!session_manager_is_enabled ())
+  if (!session_main_is_enabled ())
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1397,7 +1011,7 @@ vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
   u32 appns_index = 0;
   u8 *ns_id = 0;
   int rv = 0;
-  if (!session_manager_is_enabled ())
+  if (!session_main_is_enabled ())
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1624,7 +1238,7 @@ vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
   application_t *app;
   u32 cert_len;
   int rv = 0;
-  if (!session_manager_is_enabled ())
+  if (!session_main_is_enabled ())
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1664,7 +1278,7 @@ vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
   application_t *app;
   u32 key_len;
   int rv = 0;
-  if (!session_manager_is_enabled ())
+  if (!session_main_is_enabled ())
     {
       rv = VNET_API_ERROR_FEATURE_DISABLED;
       goto done;
@@ -1725,7 +1339,7 @@ setup_message_id_table (api_main_t * am)
 /*
  * session_api_hookup
  * Add uri's API message handlers to the table.
- * vlib has alread mapped shared memory and
+ * vlib has already mapped shared memory and
  * added the client registration handlers.
  * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
  */