- ip46 = (ip46_address_t *) mp->ip;
- clib_memset (a, 0, sizeof (*a));
- a->sep.is_ip4 = mp->is_ip4;
- a->sep.ip = *ip46;
- a->sep.port = mp->port;
- a->sep.fib_index = mp->vrf;
- a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
- a->sep.transport_proto = mp->proto;
- a->app_index = app->app_index;
- a->wrk_map_index = mp->wrk_index;
-
- if ((error = vnet_bind (a)))
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- }
-
-done:
- /* *INDENT-OFF* */
- REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
- if (!rv)
- {
- rmp->handle = a->handle;
- rmp->lcl_port = mp->port;
- rmp->lcl_is_ip4 = mp->is_ip4;
- if (app && application_has_global_scope (app))
- {
- s = listen_session_get_from_handle (a->handle);
- tc = listen_session_get_transport (s);
- clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
- if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
- {
- rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
- rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
- vpp_evt_q = session_manager_get_vpp_event_queue (0);
- rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
- }
- }
- }
- }));
- /* *INDENT-ON* */
-
- /* If app uses mq for control messages, send an mq message as well */
- if (app && application_use_mq_for_ctrl (app))
- {
- app_wrk = application_get_worker (app, mp->wrk_index);
- mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
- rv);
- }
-}
-
-static void
-vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
-{
- vl_api_unbind_sock_reply_t *rmp;
- vnet_unbind_args_t _a, *a = &_a;
- application_t *app;
- clib_error_t *error;
- int rv = 0;
-
- 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;
- a->handle = mp->handle;
- a->wrk_map_index = mp->wrk_index;
- if ((error = vnet_unbind (a)))
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- }
- }
-
-done:
- REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
-}
-
-static void
-vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
-{
- vl_api_connect_session_reply_t *rmp;
- vnet_connect_args_t _a, *a = &_a;
- application_t *app = 0;
- clib_error_t *error = 0;
- int rv = 0;
-
- if (session_manager_is_enabled () == 0)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- app = application_lookup (mp->client_index);
- if (app)
- {
- svm_queue_t *client_q;
- ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
-
- clib_memset (a, 0, sizeof (*a));
- client_q = vl_api_client_index_to_input_queue (mp->client_index);
- mp->client_queue_address = pointer_to_uword (client_q);
- a->sep.is_ip4 = mp->is_ip4;
- a->sep.ip = *ip46;
- a->sep.port = mp->port;
- a->sep.transport_proto = mp->proto;
- a->sep.fib_index = mp->vrf;
- a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
- if (mp->hostname_len)
- {
- vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
- clib_memcpy (a->sep_ext.hostname, mp->hostname, mp->hostname_len);
- }
- a->api_context = mp->context;
- a->app_index = app->app_index;
- a->wrk_map_index = mp->wrk_index;
- if ((error = vnet_connect (a)))
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- }
- vec_free (a->sep_ext.hostname);
- }
- else
- {
- rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
- }
-
- if (rv == 0)
- return;
-
- /* Got some error, relay it */
-
-done:
- REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
-
- if (app && application_use_mq_for_ctrl (app))
- {
- app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index);
- mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1);
- }
-}
-
-static void
-vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
-{
- int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
- vl_api_app_worker_add_del_reply_t *rmp;
- vl_api_registration_t *reg;
- clib_error_t *error = 0;
- application_t *app;
- u8 fd_flags = 0;
-
- if (!session_manager_is_enabled ())
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- reg = vl_api_client_index_to_registration (mp->client_index);
- if (!reg)
- return;
-
- app = application_lookup (clib_net_to_host_u32 (mp->app_api_index));
- if (!app)
- {
- rv = VNET_API_ERROR_INVALID_VALUE;
- goto done;
- }
-
- vnet_app_worker_add_del_args_t args = {
- .app_index = app->app_index,
- .wrk_index = clib_net_to_host_u32 (mp->wrk_index),
- .is_add = mp->is_add
- };
- error = vnet_app_worker_add_del (&args);
- if (error)
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- goto done;
- }
-
- if (!mp->is_add)
- goto done;
-
- /* Send fifo segment fd if needed */
- if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
- {
- fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
- fds[n_fds] = args.segment->fd;
- n_fds += 1;
- }
- if (application_segment_manager_properties (app)->use_mq_eventfd)
- {
- fd_flags |= SESSION_FD_F_MQ_EVENTFD;
- fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q);
- n_fds += 1;
- }
-
- /* *INDENT-OFF* */
-done:
- REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
- rmp->is_add = mp->is_add;
- rmp->wrk_index = clib_host_to_net_u32 (args.wrk_index);
- if (!rv && mp->is_add)
- {
- if (vec_len (args.segment->name))
- {
- memcpy (rmp->segment_name, args.segment->name,
- vec_len (args.segment->name));
- rmp->segment_name_length = vec_len (args.segment->name);
- }
- rmp->app_event_queue_address = pointer_to_uword (args.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_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
-{
- vl_api_app_namespace_add_del_reply_t *rmp;
- clib_error_t *error = 0;
- u32 appns_index = 0;
- u8 *ns_id = 0;
- int rv = 0;
- if (!session_manager_is_enabled ())
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
- {
- rv = VNET_API_ERROR_INVALID_VALUE;
- goto done;
- }
-
- vec_validate (ns_id, mp->namespace_id_len - 1);
- clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
- vnet_app_namespace_add_del_args_t args = {
- .ns_id = ns_id,
- .secret = clib_net_to_host_u64 (mp->secret),
- .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
- .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
- .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
- .is_add = 1
- };
- error = vnet_app_namespace_add_del (&args);
- if (error)
- {
- rv = clib_error_get_code (error);
- clib_error_report (error);
- }
- else
- {
- appns_index = app_namespace_index_from_id (ns_id);
- if (appns_index == APP_NAMESPACE_INVALID_INDEX)
- {
- clib_warning ("app ns lookup failed");
- rv = VNET_API_ERROR_UNSPECIFIED;
- }
- }
- vec_free (ns_id);
-
- /* *INDENT-OFF* */
-done:
- REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
- if (!rv)
- rmp->appns_index = clib_host_to_net_u32 (appns_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
-{
- vl_api_session_rule_add_del_reply_t *rmp;
- session_rule_add_del_args_t args;
- session_rule_table_add_del_args_t *table_args = &args.table_args;
- clib_error_t *error;
- u8 fib_proto;
- int rv = 0;
-
- clib_memset (&args, 0, sizeof (args));
- fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
-
- table_args->lcl.fp_len = mp->lcl_plen;
- table_args->lcl.fp_proto = fib_proto;
- table_args->rmt.fp_len = mp->rmt_plen;
- table_args->rmt.fp_proto = fib_proto;