session: allow builtin apps to register names

Change-Id: I4b428e170436671b329657283cf7653befc85c9f
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/session/application_interface.c b/src/vnet/session/application_interface.c
index f069b28..ecdbe16 100644
--- a/src/vnet/session/application_interface.c
+++ b/src/vnet/session/application_interface.c
@@ -453,10 +453,17 @@
   u64 secret;
   int rv;
 
-  app = application_lookup (a->api_client_index);
+  if (a->api_client_index != APP_INVALID_INDEX)
+    app = application_lookup (a->api_client_index);
+  else if (a->name)
+    app = application_lookup_name (a->name);
+  else
+    return clib_error_return_code (0, VNET_API_ERROR_INVALID_VALUE, 0,
+				   "api index or name must be provided");
+
   if (app)
-    return clib_error_return_code (0, VNET_API_ERROR_APP_ALREADY_ATTACHED,
-				   0, "app already attached");
+    return clib_error_return_code (0, VNET_API_ERROR_APP_ALREADY_ATTACHED, 0,
+				   "app already attached");
 
   secret = a->options[APP_OPTIONS_NAMESPACE_SECRET];
   if ((rv = session_validate_namespace (a->namespace_id, secret,
@@ -464,7 +471,7 @@
     return clib_error_return_code (0, rv, 0, "namespace validation: %d", rv);
   a->options[APP_OPTIONS_NAMESPACE] = app_ns_index;
   app = application_new ();
-  if ((rv = application_init (app, a->api_client_index, a->options,
+  if ((rv = application_init (app, a->api_client_index, a->name, a->options,
 			      a->session_cb_vft)))
     return clib_error_return_code (0, rv, 0, "app init: %d", rv);