- if (session_manager_is_enabled () == 0)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
- sizeof (mp->options),
- "Out of options, fix api message definition");
-
- memset (a, 0, sizeof (*a));
- a->api_client_index = mp->client_index;
- a->options = mp->options;
-
- if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
- a->session_cb_vft = &session_mq_cb_vft;
- else
- a->session_cb_vft = &session_cb_vft;
-
- if (mp->namespace_id_len > 64)
- {
- rv = VNET_API_ERROR_INVALID_VALUE;
- goto done;
- }
-
- if (mp->namespace_id_len)
- {
- vec_validate (a->namespace_id, mp->namespace_id_len - 1);
- clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
- }
-
- if ((error = vnet_application_attach (a)))
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- vec_free (a->namespace_id);
- goto done;
- }
- vec_free (a->namespace_id);
-
- /* Send event queues segment */
- if ((evt_q_segment = session_manager_get_evt_q_segment ()))
- {
- fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
- fds[n_fds] = evt_q_segment->fd;
- n_fds += 1;
- }
- /* Send fifo segment fd if needed */
- if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
- {
- fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
- fds[n_fds] = a->segment->fd;
- n_fds += 1;
- }
- if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
- {
- fd_flags |= SESSION_FD_F_MQ_EVENTFD;
- fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
- n_fds += 1;
- }
-
-done:
-
- /* *INDENT-OFF* */
- REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
- if (!rv)
- {
- segp = a->segment;
- rmp->segment_name_length = 0;
- rmp->segment_size = segp->ssvm_size;
- if (vec_len (segp->name))
- {
- memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
- rmp->segment_name_length = vec_len (segp->name);
- }
- rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q);
- rmp->n_fds = n_fds;
- rmp->fd_flags = fd_flags;
- }
- }));
- /* *INDENT-ON* */
-
- if (n_fds)
- session_send_fds (reg, fds, n_fds);
-}
-
-static void
-vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
-{
- vl_api_application_detach_reply_t *rmp;
- int rv = VNET_API_ERROR_INVALID_VALUE_2;
- vnet_app_detach_args_t _a, *a = &_a;
- application_t *app;
-
- if (session_manager_is_enabled () == 0)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- app = application_lookup (mp->client_index);
- if (app)
- {
- a->app_index = app->app_index;
- rv = vnet_application_detach (a);
- }
-
-done:
- REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);