memif: improve error reporting
[vpp.git] / src / plugins / memif / memif_api.c
index 5dafea3..04c2c8d 100644 (file)
 #include <vnet/ethernet/ethernet_types_api.h>
 
 /* define message IDs */
-#include <memif/memif_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <memif/memif_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <memif/memif_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <memif/memif_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <memif/memif_all_api_h.h>
-#undef vl_api_version
+#include <vnet/format_fns.h>
+#include <memif/memif.api_enum.h>
+#include <memif/memif.api_types.h>
 
 #define REPLY_MSG_ID_BASE mm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-#define foreach_memif_plugin_api_msg                                   \
-_(MEMIF_SOCKET_FILENAME_ADD_DEL, memif_socket_filename_add_del)        \
-_(MEMIF_CREATE, memif_create)                                          \
-_(MEMIF_DELETE, memif_delete)                                          \
-_(MEMIF_SOCKET_FILENAME_DUMP, memif_socket_filename_dump)              \
-_(MEMIF_DUMP, memif_dump)                                              \
-
-
 /**
  * @brief Message handler for memif_socket_filename_add_del API.
  * @param mp the vl_api_memif_socket_filename_add_del_t API message
@@ -101,7 +74,8 @@ void
       memcpy (socket_filename, mp->socket_filename, len);
     }
 
-  rv = memif_socket_filename_add_del (is_add, socket_id, socket_filename);
+  rv = vnet_api_error (
+    memif_socket_filename_add_del (is_add, socket_id, socket_filename));
 
   vec_free (socket_filename);
 
@@ -149,9 +123,6 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp)
 
   args.is_zero_copy = mp->no_zero_copy ? 0 : 1;
 
-  /* enable zero-copy */
-  args.is_zero_copy = 1;
-
   /* rx/tx queues */
   if (args.is_master == 0)
     {
@@ -194,7 +165,7 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp)
       args.hw_addr_set = 1;
     }
 
-  rv = memif_create_if (vm, &args);
+  rv = vnet_api_error (memif_create_if (vm, &args));
 
   vec_free (args.secret);
 
@@ -231,7 +202,7 @@ vl_api_memif_delete_t_handler (vl_api_memif_delete_t * mp)
   else
     {
       mif = pool_elt_at_index (mm->interfaces, hi->dev_instance);
-      rv = memif_delete_if (vm, mif);
+      rv = vnet_api_error (memif_delete_if (vm, mif));
     }
 
   REPLY_MACRO (VL_API_MEMIF_DELETE_REPLY);
@@ -310,8 +281,8 @@ vl_api_memif_dump_t_handler (vl_api_memif_dump_t * mp)
     return;
 
   /* *INDENT-OFF* */
-  pool_foreach (mif, mm->interfaces,
-    ({
+  pool_foreach (mif, mm->interfaces)
+     {
       swif = vnet_get_sw_interface (vnm, mif->sw_if_index);
 
       if_name = format (if_name, "%U%c",
@@ -319,8 +290,8 @@ vl_api_memif_dump_t_handler (vl_api_memif_dump_t * mp)
                        vnm, swif, 0);
 
       send_memif_details (reg, mif, swif, if_name, mp->context);
-      _vec_len (if_name) = 0;
-    }));
+      vec_set_len (if_name, 0);
+    }
   /* *INDENT-ON* */
 
   vec_free (if_name);
@@ -378,51 +349,15 @@ void
   /* *INDENT-ON* */
 }
 
-#define vl_msg_name_crc_list
-#include <memif/memif_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (memif_main_t * mm, api_main_t * am)
-{
-#define _(id,n,crc) \
-  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base);
-  foreach_vl_msg_name_crc_memif;
-#undef _
-}
-
 /* Set up the API message handling tables */
+#include <memif/memif.api.c>
 clib_error_t *
 memif_plugin_api_hookup (vlib_main_t * vm)
 {
   memif_main_t *mm = &memif_main;
-  api_main_t *am = &api_main;
-  u8 *name;
-
-  /* Construct the API name */
-  name = format (0, "memif_%08x%c", api_version, 0);
 
   /* Ask for a correctly-sized block of API message decode slots */
-  mm->msg_id_base = vl_msg_api_get_msg_ids
-    ((char *) name, VL_MSG_FIRST_AVAILABLE);
-
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_base),     \
-                           #n,                                  \
-                           vl_api_##n##_t_handler,              \
-                           vl_noop_handler,                     \
-                           vl_api_##n##_t_endian,               \
-                           vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1);
-  foreach_memif_plugin_api_msg;
-#undef _
-
-  /*
-   * Set up the (msg_name, crc, message-id) table
-   */
-  setup_message_id_table (mm, am);
-
-  vec_free (name);
+  mm->msg_id_base = setup_message_id_table ();
   return 0;
 }