udp/session: refactor to support dgram mode
[vpp.git] / src / vnet / session / session_api.c
index ca739fa..67c42fa 100755 (executable)
@@ -174,7 +174,7 @@ send_session_accept_callback (stream_session_t * s)
 
   if (session_has_transport (s))
     {
-      listener = listen_session_get (s->session_type, s->listener_index);
+      listener = listen_session_get (s->listener_index);
       mp->listener_handle = listen_session_get_handle (listener);
       if (application_is_proxy (server))
        {
@@ -199,8 +199,7 @@ send_session_accept_callback (stream_session_t * s)
       local_session_t *ll;
       if (application_local_session_listener_has_transport (ls))
        {
-         listener = listen_session_get (ls->listener_session_type,
-                                        ls->listener_index);
+         listener = listen_session_get (ls->listener_index);
          mp->listener_handle = listen_session_get_handle (listener);
          mp->is_ip4 = session_type_is_ip4 (listener->session_type);
        }
@@ -210,8 +209,7 @@ send_session_accept_callback (stream_session_t * s)
                                                     ls->listener_index);
          if (ll->transport_listener_index != ~0)
            {
-             listener = listen_session_get (ll->listener_session_type,
-                                            ll->transport_listener_index);
+             listener = listen_session_get (ll->transport_listener_index);
              mp->listener_handle = listen_session_get_handle (listener);
            }
          else
@@ -482,9 +480,12 @@ done:
 static void
 vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
 {
-  vl_api_bind_uri_reply_t *rmp;
+  transport_connection_t *tc = 0;
   vnet_bind_args_t _a, *a = &_a;
-  application_t *app;
+  vl_api_bind_uri_reply_t *rmp;
+  stream_session_t *s;
+  application_t *app = 0;
+  svm_queue_t *vpp_evt_q;
   int rv;
 
   if (session_manager_is_enabled () == 0)
@@ -507,7 +508,30 @@ vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
     }
 
 done:
-  REPLY_MACRO (VL_API_BIND_URI_REPLY);
+
+  /* *INDENT-OFF* */
+  REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
+    if (!rv)
+      {
+        rmp->handle = a->handle;
+       rmp->lcl_is_ip4 = tc->is_ip4;
+       rmp->lcl_port = tc->lcl_port;
+        if (app && application_has_global_scope (app))
+            {
+              s = listen_session_get_from_handle (a->handle);
+              tc = listen_session_get_transport (s);
+              clib_memcpy (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->server_rx_fifo);
+                  rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
+                  vpp_evt_q = session_manager_get_vpp_event_queue (0);
+                  rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
+                }
+            }
+      }
+  }));
+  /* *INDENT-ON* */
 }
 
 static void
@@ -735,6 +759,7 @@ vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
   stream_session_t *s;
   transport_connection_t *tc = 0;
   ip46_address_t *ip46;
+  svm_queue_t *vpp_evt_q;
 
   if (session_manager_is_enabled () == 0)
     {
@@ -777,8 +802,14 @@ done:
          {
            s = listen_session_get_from_handle (a->handle);
            tc = listen_session_get_transport (s);
-            rmp->lcl_is_ip4 = tc->is_ip4;
             clib_memcpy (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->server_rx_fifo);
+               rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
+               vpp_evt_q = session_manager_get_vpp_event_queue (0);
+               rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
+              }
          }
       }
   }));
@@ -1131,6 +1162,11 @@ vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
   memset (a, 0, sizeof (*a));
   a->app_index = app->index;
   cert_len = clib_net_to_host_u16 (mp->cert_len);
+  if (cert_len > 10000)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto done;
+    }
   vec_validate (a->cert, cert_len);
   clib_memcpy (a->cert, mp->cert, cert_len);
   if ((error = vnet_app_add_tls_cert (a)))
@@ -1166,6 +1202,11 @@ vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
   memset (a, 0, sizeof (*a));
   a->app_index = app->index;
   key_len = clib_net_to_host_u16 (mp->key_len);
+  if (key_len > 10000)
+    {
+      rv = VNET_API_ERROR_INVALID_VALUE;
+      goto done;
+    }
   vec_validate (a->key, key_len);
   clib_memcpy (a->key, mp->key, key_len);
   if ((error = vnet_app_add_tls_key (a)))