tests: change code to avoid gcc-11 warning
[vpp.git] / src / plugins / nsh / nsh_api.c
index cf9fd57..1faaea3 100644 (file)
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 #include <vpp/app/version.h>
-
-/* define message IDs */
-#define vl_msg_id(n,h) n,
-typedef enum
-{
-#include <nsh/nsh.api.h>
-  /* We'll want to know how many messages IDs we need... */
-  VL_MSG_FIRST_AVAILABLE,
-} vl_msg_id_t;
-#undef vl_msg_id
-
-/* define message structures */
-#define vl_typedefs
-#include <nsh/nsh.api.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <nsh/nsh.api.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 <nsh/nsh.api.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <nsh/nsh.api.h>
-#undef vl_api_version
-
-#define vl_msg_name_crc_list
-#include <nsh/nsh.api.h>
-#undef vl_msg_name_crc_list
-
-#define REPLY_MSG_ID_BASE nm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-/* List of message types that this plugin understands */
-
-#define foreach_nsh_plugin_api_msg             \
-  _(NSH_ADD_DEL_ENTRY, nsh_add_del_entry)      \
-  _(NSH_ENTRY_DUMP, nsh_entry_dump)             \
-  _(NSH_ADD_DEL_MAP, nsh_add_del_map)           \
-  _(NSH_MAP_DUMP, nsh_map_dump)
+#include <plugins/nsh/nsh.api_enum.h>
+#include <plugins/nsh/nsh.api_types.h>
 
 /**
  * @brief CLI function for NSH admin up/down
@@ -90,14 +48,6 @@ nsh_interface_admin_up_down (vnet_main_t * vnm, u32 nsh_hw_if, u32 flags)
   return 0;
 }
 
-static uword
-dummy_interface_tx (vlib_main_t * vm,
-                   vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
-  clib_warning ("you shouldn't be here, leaking buffers...");
-  return frame->n_vectors;
-}
-
 /**
  * @brief Naming for NSH tunnel
  *
@@ -118,13 +68,12 @@ format_nsh_name (u8 * s, va_list * args)
 VNET_DEVICE_CLASS (nsh_device_class, static) = {
   .name = "NSH",
   .format_device_name = format_nsh_name,
-  .tx_function = dummy_interface_tx,
   .admin_up_down_function = nsh_interface_admin_up_down,
 };
 /* *INDENT-ON* */
 
 static void send_nsh_entry_details
-  (nsh_entry_t * t, unix_shared_memory_queue_t * q, u32 context)
+  (nsh_entry_t * t, vl_api_registration_t * rp, u32 context)
 {
   vl_api_nsh_entry_details_t *rmp;
   nsh_main_t *nm = &nsh_main;
@@ -157,11 +106,11 @@ static void send_nsh_entry_details
 
   rmp->context = context;
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void send_nsh_map_details
-  (nsh_map_t * t, unix_shared_memory_queue_t * q, u32 context)
+  (nsh_map_t * t, vl_api_registration_t * rp, u32 context)
 {
   vl_api_nsh_map_details_t *rmp;
   nsh_main_t *nm = &nsh_main;
@@ -179,33 +128,29 @@ static void send_nsh_map_details
 
   rmp->context = context;
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void
 vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
   nsh_main_t *nm = &nsh_main;
   nsh_map_t *t;
   u32 map_index;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   map_index = ntohl (mp->map_index);
 
   if (~0 == map_index)
     {
-      pool_foreach (t, nm->nsh_mappings, (
-                                          {
-                                          send_nsh_map_details (t, q,
-                                                                mp->context);
-                                          }
-                   ));
+      pool_foreach (t, nm->nsh_mappings)
+      {
+       send_nsh_map_details (t, rp, mp->context);
+      }
     }
   else
     {
@@ -214,7 +159,7 @@ vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
          return;
        }
       t = &nm->nsh_mappings[map_index];
-      send_nsh_map_details (t, q, mp->context);
+      send_nsh_map_details (t, rp, mp->context);
     }
 }
 
@@ -223,7 +168,6 @@ static void
 vl_api_nsh_add_del_map_t_handler (vl_api_nsh_add_del_map_t * mp)
 {
   vl_api_nsh_add_del_map_reply_t *rmp;
-  nsh_main_t *nm = &nsh_main;
   int rv;
   nsh_add_del_map_args_t _a, *a = &_a;
   u32 map_index = ~0;
@@ -605,7 +549,6 @@ static void vl_api_nsh_add_del_entry_t_handler
   (vl_api_nsh_add_del_entry_t * mp)
 {
   vl_api_nsh_add_del_entry_reply_t *rmp;
-  nsh_main_t *nm = &nsh_main;
   int rv;
   nsh_add_del_entry_args_t _a, *a = &_a;
   u32 entry_index = ~0;
@@ -650,27 +593,23 @@ static void vl_api_nsh_add_del_entry_t_handler
 static void
 vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
   nsh_main_t *nm = &nsh_main;
   nsh_entry_t *t;
   u32 entry_index;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   entry_index = ntohl (mp->entry_index);
 
   if (~0 == entry_index)
     {
-      pool_foreach (t, nm->nsh_entries, (
-                                         {
-                                         send_nsh_entry_details (t, q,
-                                                                 mp->context);
-                                         }
-                   ));
+      pool_foreach (t, nm->nsh_entries)
+      {
+       send_nsh_entry_details (t, rp, mp->context);
+      }
     }
   else
     {
@@ -679,58 +618,20 @@ vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
          return;
        }
       t = &nm->nsh_entries[entry_index];
-      send_nsh_entry_details (t, q, mp->context);
+      send_nsh_entry_details (t, rp, mp->context);
     }
 }
 
-static void
-setup_message_id_table (nsh_main_t * nm, api_main_t * am)
-{
-#define _(id,n,crc) \
-  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nm->msg_id_base);
-  foreach_vl_msg_name_crc_nsh;
-#undef _
-}
+#include <nsh/nsh.api.c>
 
 /* Set up the API message handling tables */
-static clib_error_t *
-nsh_plugin_api_hookup (vlib_main_t * vm)
-{
-  nsh_main_t *nm __attribute__ ((unused)) = &nsh_main;
-#define _(N,n)                                                  \
-  vl_msg_api_set_handlers((VL_API_##N + nm->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_nsh_plugin_api_msg;
-#undef _
-
-  return 0;
-}
-
 clib_error_t *
 nsh_api_init (vlib_main_t * vm, nsh_main_t * nm)
 {
-  clib_error_t *error;
-  u8 *name;
-
-  name = format (0, "nsh_%08x%c", api_version, 0);
-
-  /* Set up the API */
-  nm->msg_id_base = vl_msg_api_get_msg_ids
-    ((char *) name, VL_MSG_FIRST_AVAILABLE);
-
-  error = nsh_plugin_api_hookup (vm);
-
   /* Add our API messages to the global name_crc hash table */
-  setup_message_id_table (nm, &api_main);
-
-  vec_free (name);
+  nm->msg_id_base = setup_message_id_table ();
 
-  return error;
+  return 0;
 }
 
 /*