vcl: wait for segments with segment handle
[vpp.git] / src / vnet / session / application_interface.c
index 1f5c6ff..d254b9b 100644 (file)
@@ -125,10 +125,10 @@ api_parse_session_handle (u64 handle, u32 * session_index, u32 * thread_index)
   *thread_index = handle & 0xFFFFFFFF;
   *session_index = handle >> 32;
 
-  if (*thread_index >= vec_len (smm->sessions))
+  if (*thread_index >= vec_len (smm->wrk))
     return VNET_API_ERROR_INVALID_VALUE;
 
-  pool = smm->sessions[*thread_index];
+  pool = smm->wrk[*thread_index].sessions;
 
   if (pool_is_free_index (pool, *session_index))
     return VNET_API_ERROR_INVALID_VALUE_2;
@@ -163,7 +163,12 @@ session_endpoint_update_for_app (session_endpoint_cfg_t * sep,
    * that "supports" app's namespace. This will fix our local connection
    * endpoint.
    */
-  fib_index = sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
+
+  /* If in default namespace and user requested a fib index use it */
+  if (ns_index == 0 && sep->fib_index != ENDPOINT_INVALID_INDEX)
+    fib_index = sep->fib_index;
+  else
+    fib_index = sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
   sep->peer.fib_index = fib_index;
   sep->fib_index = fib_index;
 
@@ -481,6 +486,19 @@ app_validate_namespace (u8 * namespace_id, u64 secret, u32 * app_ns_index)
   return 0;
 }
 
+static u8 *
+app_name_from_api_index (u32 api_client_index)
+{
+  vl_api_registration_t *regp;
+  regp = vl_api_client_index_to_registration (api_client_index);
+  if (regp)
+    return format (0, "%s%c", regp->name, 0);
+
+  clib_warning ("api client index %u does not have an api registration!",
+               api_client_index);
+  return format (0, "unknown%c", 0);
+}
+
 /**
  * Attach application to vpp
  *
@@ -496,6 +514,7 @@ vnet_application_attach (vnet_app_attach_args_t * a)
   app_worker_t *app_wrk;
   segment_manager_t *sm;
   u32 app_ns_index = 0;
+  u8 *app_name = 0;
   u64 secret;
   int rv;
 
@@ -511,6 +530,12 @@ vnet_application_attach (vnet_app_attach_args_t * a)
     return clib_error_return_code (0, VNET_API_ERROR_APP_ALREADY_ATTACHED, 0,
                                   "app already attached");
 
+  if (a->api_client_index != APP_INVALID_INDEX)
+    {
+      app_name = app_name_from_api_index (a->api_client_index);
+      a->name = app_name;
+    }
+
   secret = a->options[APP_OPTIONS_NAMESPACE_SECRET];
   if ((rv = app_validate_namespace (a->namespace_id, secret, &app_ns_index)))
     return clib_error_return_code (0, rv, 0, "namespace validation: %d", rv);
@@ -524,6 +549,7 @@ vnet_application_attach (vnet_app_attach_args_t * a)
     return clib_error_return_code (0, rv, 0, "app default wrk init: %d", rv);
 
   a->app_evt_q = app_wrk->event_queue;
+  app_wrk->api_client_index = a->api_client_index;
   sm = segment_manager_get (app_wrk->first_segment_manager);
   fs = segment_manager_get_segment_w_lock (sm, 0);
 
@@ -532,9 +558,10 @@ vnet_application_attach (vnet_app_attach_args_t * a)
 
   ASSERT (vec_len (fs->ssvm.name) <= 128);
   a->segment = &fs->ssvm;
+  a->segment_handle = segment_manager_segment_handle (sm, fs);
 
   segment_manager_segment_reader_unlock (sm);
-
+  vec_free (app_name);
   return 0;
 }
 
@@ -554,7 +581,7 @@ vnet_application_detach (vnet_app_detach_args_t * a)
     }
 
   app_interface_check_thread_and_barrier (vnet_application_detach, a);
-  application_free (app);
+  application_detach_process (app, a->api_client_index);
   return 0;
 }