- if ((rv = vnet_bind_i (a->api_client_index, &ip46, port_host_order, sst,
- a->options, a->session_cb_vft, &server,
- &a->segment_name_length, a->segment_name)))
- return rv;
+/**
+ * Attach application to vpp
+ *
+ * Allocates a vpp app, i.e., a structure that keeps back pointers
+ * to external app and a segment manager for shared memory fifo based
+ * communication with the external app.
+ */
+clib_error_t *
+vnet_application_attach (vnet_app_attach_args_t * a)
+{
+ svm_fifo_segment_private_t *fs;
+ application_t *app = 0;
+ segment_manager_t *sm;
+ u32 app_ns_index = 0;
+ u64 secret;
+ int rv;
+
+ app = application_lookup (a->api_client_index);
+ if (app)
+ 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,
+ &app_ns_index)))
+ 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,
+ a->session_cb_vft)))
+ return clib_error_return_code (0, rv, 0, "app init: %d", rv);
+
+ a->app_event_queue_address = pointer_to_uword (app->event_queue);
+ sm = segment_manager_get (app->first_segment_manager);
+ fs = segment_manager_get_segment (sm->segment_indices[0]);
+
+ if (application_is_proxy (app))
+ application_setup_proxy (app);
+
+ ASSERT (vec_len (fs->ssvm.name) <= 128);
+ a->segment = &fs->ssvm;
+ a->app_index = app->index;