nat: use correct data types for memory sizes
[vpp.git] / src / plugins / nsh / nsh_api.c
index ccae554..2f40f31 100644 (file)
@@ -57,44 +57,8 @@ typedef enum
 #include <nsh/nsh.api.h>
 #undef vl_msg_name_crc_list
 
-/*
- * A handy macro to set up a message reply.
- * Assumes that the following variables are available:
- * mp - pointer to request message
- * rmp - pointer to reply message type
- * rv - return value
- */
-
-#define REPLY_MACRO(t)                                          \
-  do {                                                         \
-    unix_shared_memory_queue_t * q =                            \
-      vl_api_client_index_to_input_queue (mp->client_index);   \
-    if (!q)                                                     \
-      return;                                                  \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+nm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-  } while(0);
-
-#define REPLY_MACRO2(t, body)                                   \
-  do {                                                          \
-    unix_shared_memory_queue_t * q;                             \
-    rv = vl_msg_api_pd_handler (mp, rv);                        \
-    q = vl_api_client_index_to_input_queue (mp->client_index);  \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+nm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-    do {body;} while (0);                                       \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-  } while(0);
+#define REPLY_MSG_ID_BASE nm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
 
@@ -126,14 +90,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
  *
@@ -154,13 +110,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;
@@ -193,11 +148,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;
@@ -215,22 +170,20 @@ 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);
 
@@ -238,7 +191,7 @@ vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
     {
       pool_foreach (t, nm->nsh_mappings, (
                                           {
-                                          send_nsh_map_details (t, q,
+                                          send_nsh_map_details (t, rp,
                                                                 mp->context);
                                           }
                    ));
@@ -250,7 +203,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);
     }
 }
 
@@ -686,16 +639,14 @@ 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);
 
@@ -703,7 +654,7 @@ vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
     {
       pool_foreach (t, nm->nsh_entries, (
                                          {
-                                         send_nsh_entry_details (t, q,
+                                         send_nsh_entry_details (t, rp,
                                                                  mp->context);
                                          }
                    ));
@@ -715,7 +666,7 @@ 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);
     }
 }
 
@@ -762,7 +713,7 @@ nsh_api_init (vlib_main_t * vm, nsh_main_t * nm)
   error = nsh_plugin_api_hookup (vm);
 
   /* Add our API messages to the global name_crc hash table */
-  setup_message_id_table (nm, &api_main);
+  setup_message_id_table (nm, vlibapi_get_main ());
 
   vec_free (name);