- app = application_lookup (mp->client_index);
- if (app)
- {
- a->handle = mp->handle;
- a->app_index = app->app_index;
- rv = vnet_disconnect_session (a);
- }
- else
- {
- rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
- }
-
-done:
- REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
-}
-
-static void
-vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
- mp)
-{
- vnet_disconnect_args_t _a, *a = &_a;
- application_t *app;
-
- /* Client objected to disconnecting the session, log and continue */
- if (mp->retval)
- {
- clib_warning ("client retval %d", mp->retval);
- return;
- }
-
- /* Disconnect has been confirmed. Confirm close to transport */
- app = application_lookup (mp->context);
- if (app)
- {
- a->handle = mp->handle;
- a->app_index = app->app_index;
- vnet_disconnect_session (a);
- }
-}
-
-static void
-vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
-{
- vnet_disconnect_args_t _a = { 0 }, *a = &_a;
- app_worker_t *app_wrk;
- application_t *app;
- session_t *s;
- u32 index, thread_index;
-
- app = application_lookup (mp->context);
- if (!app)
- return;
-
- session_parse_handle (mp->handle, &index, &thread_index);
- s = session_get_if_valid (index, thread_index);
- if (!s)
- {
- clib_warning ("Invalid session!");
- return;
- }
-
- app_wrk = app_worker_get (s->app_wrk_index);
- if (app_wrk->app_index != app->app_index)
- {
- clib_warning ("app %u does not own handle 0x%lx", app->app_index,
- mp->handle);
- return;
- }
-
- /* Client objected to resetting the session, log and continue */
- if (mp->retval)
- {
- clib_warning ("client retval %d", mp->retval);
- return;
- }
-
- /* This comes as a response to a reset, transport only waiting for
- * confirmation to remove connection state, no need to disconnect */
- a->handle = mp->handle;
- a->app_index = app->app_index;
- vnet_disconnect_session (a);
-}
-
-static void
-vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
-{
- vnet_disconnect_args_t _a = { 0 }, *a = &_a;
- local_session_t *ls;
- session_t *s;
-
- /* Server isn't interested, kill the session */
- if (mp->retval)
- {
- a->app_index = mp->context;
- a->handle = mp->handle;
- vnet_disconnect_session (a);
- return;
- }
-
- if (session_handle_is_local (mp->handle))
- {
- ls = app_worker_get_local_session_from_handle (mp->handle);
- if (!ls || ls->app_wrk_index != mp->context)
- {
- clib_warning ("server %u doesn't own local handle %llu",
- mp->context, mp->handle);
- return;
- }
- if (app_worker_local_session_connect_notify (ls))
- return;
- ls->session_state = SESSION_STATE_READY;
- }
- else
- {
- s = session_get_from_handle_if_valid (mp->handle);
- if (!s)
- {
- clib_warning ("session doesn't exist");
- return;
- }
- if (s->app_wrk_index != mp->context)
- {
- clib_warning ("app doesn't own session");
- return;
- }
- s->session_state = SESSION_STATE_READY;
- }
-}
-
-static void
-vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
- * mp)
-{
- clib_warning ("not implemented");
-}
-
-static void
-vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
-{
- vl_api_bind_sock_reply_t *rmp;
- vnet_bind_args_t _a, *a = &_a;
- int rv = 0;
- clib_error_t *error;
- application_t *app = 0;
- app_worker_t *app_wrk;
- session_t *s;
- transport_connection_t *tc = 0;
- ip46_address_t *ip46;
- svm_msg_q_t *vpp_evt_q;
-
- if (session_manager_is_enabled () == 0)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto done;
- }
-
- app = application_lookup (mp->client_index);
- if (!app)
- {
- rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
- goto done;
- }
-
- 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_fast (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->rx_fifo);
- rmp->tx_fifo = pointer_to_uword (s->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;
- }