session: API cleanup
[vpp.git] / src / plugins / hs_apps / sapi / vpp_echo_bapi.c
index 04eba24..784d741 100644 (file)
@@ -44,9 +44,7 @@ echo_send_attach (echo_main_t * em)
   bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = em->evt_q_size;
   if (em->appns_id)
     {
-      bmp->namespace_id_len = vec_len (em->appns_id);
-      clib_memcpy_fast (bmp->namespace_id, em->appns_id,
-                       bmp->namespace_id_len);
+      vl_api_vec_to_api_string (em->appns_id, &bmp->namespace_id);
       bmp->options[APP_OPTIONS_FLAGS] |= em->appns_flags;
       bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = em->appns_secret;
     }
@@ -198,8 +196,8 @@ echo_send_disconnect_session (echo_main_t * em, void *args)
  *
  */
 
-static int
-ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
+int
+echo_ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
 {
   fifo_segment_create_args_t _a, *a = &_a;
   fifo_segment_main_t *sm = &echo_main.segment_main;
@@ -218,7 +216,7 @@ ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
   return 0;
 }
 
-static inline void
+void
 echo_segment_handle_add_del (echo_main_t * em, u64 segment_handle, u8 add)
 {
   clib_spinlock_lock (&em->segment_handles_lock);
@@ -276,9 +274,11 @@ static void
 vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
 {
   echo_main_t *em = &echo_main;
-  int *fds = 0, i;
+  int *fds = 0, i, rv;
   u32 n_fds = 0;
   u64 segment_handle;
+  char *segment_name = 0;
+
   segment_handle = clib_net_to_host_u64 (mp->segment_handle);
   ECHO_LOG (2, "Attached returned app %u", htons (mp->app_index));
 
@@ -289,13 +289,6 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
       return;
     }
 
-  if (mp->segment_name_length == 0)
-    {
-      ECHO_FAIL (ECHO_FAIL_VL_API_MISSING_SEGMENT_NAME,
-                "segment_name_length zero");
-      return;
-    }
-
   if (!mp->app_mq)
     {
       ECHO_FAIL (ECHO_FAIL_VL_API_NULL_APP_MQ, "NULL app_mq");
@@ -315,7 +308,7 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
        }
 
       if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT)
-       if (ssvm_segment_attach (0, SSVM_SEGMENT_MEMFD, fds[n_fds++]))
+       if (echo_ssvm_segment_attach (0, SSVM_SEGMENT_MEMFD, fds[n_fds++]))
          {
            ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
                       "svm_fifo_segment_attach failed on SSVM_SEGMENT_MEMFD");
@@ -323,14 +316,21 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
          }
 
       if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
-       if (ssvm_segment_attach ((char *) mp->segment_name,
-                                SSVM_SEGMENT_MEMFD, fds[n_fds++]))
-         {
-           ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
-                      "svm_fifo_segment_attach ('%s') "
-                      "failed on SSVM_SEGMENT_MEMFD", mp->segment_name);
-           goto failed;
-         }
+       {
+         segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
+         rv = echo_ssvm_segment_attach (segment_name,
+                                        SSVM_SEGMENT_MEMFD, fds[n_fds++]);
+         if (rv != 0)
+           {
+             ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
+                        "svm_fifo_segment_attach ('%s') "
+                        "failed on SSVM_SEGMENT_MEMFD", segment_name);
+             vec_free (segment_name);
+             goto failed;
+           }
+         vec_free (segment_name);
+       }
+
       if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)
        svm_msg_q_set_consumer_eventfd (em->app_mq, fds[n_fds++]);
 
@@ -338,14 +338,17 @@ vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
     }
   else
     {
-      if (ssvm_segment_attach ((char *) mp->segment_name, SSVM_SEGMENT_SHM,
-                              -1))
+      segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
+      rv = echo_ssvm_segment_attach (segment_name, SSVM_SEGMENT_SHM, -1);
+      if (rv != 0)
        {
          ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
                     "svm_fifo_segment_attach ('%s') "
-                    "failed on SSVM_SEGMENT_SHM", mp->segment_name);
-         return;
+                    "failed on SSVM_SEGMENT_SHM", segment_name);
+         vec_free (segment_name);
+         goto failed;
        }
+      vec_free (segment_name);
     }
   echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
   ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
@@ -371,74 +374,11 @@ vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
   echo_main.state = STATE_DETACHED;
 }
 
-static void
-vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
-{
-  echo_main_t *em = &echo_main;
-  u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
-  echo_segment_handle_add_del (em, segment_handle, 0 /* add */ );
-  ECHO_LOG (2, "Unmaped segment 0x%lx", segment_handle);
-}
-
-static void
-vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
-{
-  fifo_segment_main_t *sm = &echo_main.segment_main;
-  fifo_segment_create_args_t _a, *a = &_a;
-  echo_main_t *em = &echo_main;
-  int *fds = 0, i;
-  char *seg_name = (char *) mp->segment_name;
-  u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle);
-
-  if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
-    {
-      vec_validate (fds, 1);
-      if (vl_socket_client_recv_fd_msg (fds, 1, 5))
-       {
-         ECHO_FAIL (ECHO_FAIL_VL_API_RECV_FD_MSG,
-                    "vl_socket_client_recv_fd_msg failed");
-         goto failed;
-       }
-
-      if (ssvm_segment_attach (seg_name, SSVM_SEGMENT_MEMFD, fds[0]))
-       {
-         ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
-                    "svm_fifo_segment_attach ('%s') "
-                    "failed on SSVM_SEGMENT_MEMFD", seg_name);
-         goto failed;
-       }
-      vec_free (fds);
-    }
-  else
-    {
-      clib_memset (a, 0, sizeof (*a));
-      a->segment_name = seg_name;
-      a->segment_size = mp->segment_size;
-      /* Attach to the segment vpp created */
-      if (fifo_segment_attach (sm, a))
-       {
-         ECHO_FAIL (ECHO_FAIL_VL_API_FIFO_SEG_ATTACH,
-                    "fifo_segment_attach ('%s') failed", seg_name);
-         goto failed;
-       }
-    }
-  echo_segment_handle_add_del (em, segment_handle, 1 /* add */ );
-  ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
-  return;
-
-failed:
-  for (i = 0; i < vec_len (fds); i++)
-    close (fds[i]);
-  vec_free (fds);
-}
-
 #define foreach_quic_echo_msg                                    \
 _(APP_ATTACH_REPLY, app_attach_reply)                            \
 _(APPLICATION_DETACH_REPLY, application_detach_reply)            \
-_(MAP_ANOTHER_SEGMENT, map_another_segment)                      \
 _(APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply)      \
-_(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)      \
-_(UNMAP_SEGMENT, unmap_segment)
+_(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
 
 void
 echo_api_hookup (echo_main_t * em)