session: cleanup use of api_client_index
[vpp.git] / src / vnet / session / application_interface.c
index 1f5c6ff..2a09909 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;
@@ -496,11 +496,21 @@ 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;
 
   if (a->api_client_index != APP_INVALID_INDEX)
-    app = application_lookup (a->api_client_index);
+    {
+      app = application_lookup (a->api_client_index);
+      if (!app)
+       {
+         vl_api_registration_t *regp;
+         regp = vl_api_client_index_to_registration (a->api_client_index);
+         app_name = format (0, "%s%c", regp->name, 0);
+         a->name = app_name;
+       }
+    }
   else if (a->name)
     app = application_lookup_name (a->name);
   else
@@ -524,6 +534,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);
 
@@ -534,7 +545,7 @@ vnet_application_attach (vnet_app_attach_args_t * a)
   a->segment = &fs->ssvm;
 
   segment_manager_segment_reader_unlock (sm);
-
+  vec_free (app_name);
   return 0;
 }
 
@@ -554,7 +565,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;
 }