api: binary api cleanup
[vpp.git] / src / plugins / memif / memif_api.c
index a4137e4..ebe7a35 100644 (file)
 #include <memif/memif_all_api_h.h>
 #undef vl_api_version
 
-/*
- * 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 {                                                            \
-    svm_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 = htons ((t)+mm->msg_id_base);              \
-    rmp->context = mp->context;                                 \
-    rmp->retval = htonl (rv);                                   \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
-#define REPLY_MACRO2(t, body)                                   \
-do {                                                            \
-    svm_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 = htons ((t)+mm->msg_id_base);              \
-    rmp->context = mp->context;                                 \
-    rmp->retval = htonl (rv);                                   \
-    do {body;} while (0);                                       \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
+#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)        \
@@ -243,11 +209,14 @@ vl_api_memif_delete_t_handler (vl_api_memif_delete_t * mp)
   vlib_main_t *vm = vlib_get_main ();
   vnet_main_t *vnm = vnet_get_main ();
   vl_api_memif_delete_reply_t *rmp;
-  vnet_hw_interface_t *hi =
-    vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
+  vnet_hw_interface_t *hi;
   memif_if_t *mif;
   int rv = 0;
 
+  hi =
+    vnet_get_sup_hw_interface_api_visible_or_null (vnm,
+                                                  ntohl (mp->sw_if_index));
+
   if (hi == NULL || memif_device_class.index != hi->dev_class_index)
     rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
   else
@@ -274,7 +243,7 @@ send_memif_details (vl_api_registration_t * reg,
   hwif = vnet_get_sup_hw_interface (vnm, swif->sw_if_index);
 
   mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
 
   mp->_vl_msg_id = htons (VL_API_MEMIF_DETAILS + mm->msg_id_base);
   mp->context = context;
@@ -347,7 +316,7 @@ send_memif_socket_filename_details (vl_api_registration_t * reg,
   memif_main_t *mm = &memif_main;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
 
   mp->_vl_msg_id = htons (VL_API_MEMIF_SOCKET_FILENAME_DETAILS
                          + mm->msg_id_base);