API:replaced all REPLY_MACRO's with api_helper_macros.h 65/5765/2
authorEyal Bari <ebari@cisco.com>
Thu, 16 Mar 2017 08:02:57 +0000 (10:02 +0200)
committerJohn Lo <loj@cisco.com>
Thu, 16 Mar 2017 15:15:16 +0000 (15:15 +0000)
Change-Id: I08ab1fd0abdd1db4aff11a38c9c0134b01368e11
Signed-off-by: Eyal Bari <ebari@cisco.com>
src/examples/sample-plugin/sample/sample.c
src/plugins/acl/acl.c
src/plugins/flowperpkt/flowperpkt.c
src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c
src/plugins/ioam/export/ioam_export.c
src/plugins/ioam/ip6/ioam_cache.c
src/plugins/ioam/lib-pot/pot_api.c
src/plugins/ioam/udp-ping/udp_ping_api.c
src/plugins/lb/api.c
src/plugins/snat/snat.c
src/vlibapi/api_helper_macros.h

index 7588dbc..0185274 100644 (file)
 #include <sample/sample_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 {                                                            \
-    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)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
+#define REPLY_MSG_ID_BASE sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
 
index b6af738..0d06531 100644 (file)
 
 acl_main_t acl_main;
 
-/*
- * 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)+sm->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)+am->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_MACRO3(t, n, 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) + n);                 \
-    rmp->_vl_msg_id = ntohs((t)+am->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 am->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
 
@@ -1409,7 +1356,7 @@ vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp)
 static void
 vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
 {
-  acl_main_t *sm = &acl_main;
+  acl_main_t *am = &acl_main;
   vl_api_acl_del_reply_t *rmp;
   int rv;
 
@@ -1421,8 +1368,8 @@ vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
 static void
 vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp)
 {
-  acl_main_t *sm = &acl_main;
-  vnet_interface_main_t *im = &sm->vnet_main->interface_main;
+  acl_main_t *am = &acl_main;
+  vnet_interface_main_t *im = &am->vnet_main->interface_main;
   u32 sw_if_index = ntohl (mp->sw_if_index);
   vl_api_acl_interface_add_del_reply_t *rmp;
   int rv = -1;
@@ -1441,11 +1388,11 @@ static void
 vl_api_acl_interface_set_acl_list_t_handler
   (vl_api_acl_interface_set_acl_list_t * mp)
 {
-  acl_main_t *sm = &acl_main;
+  acl_main_t *am = &acl_main;
   vl_api_acl_interface_set_acl_list_reply_t *rmp;
   int rv = 0;
   int i;
-  vnet_interface_main_t *im = &sm->vnet_main->interface_main;
+  vnet_interface_main_t *im = &am->vnet_main->interface_main;
   u32 sw_if_index = ntohl (mp->sw_if_index);
 
   if (pool_is_free_index(im->sw_interfaces, sw_if_index))
@@ -1667,7 +1614,7 @@ vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp)
 static void
 vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp)
 {
-  acl_main_t *sm = &acl_main;
+  acl_main_t *am = &acl_main;
   vl_api_macip_acl_del_reply_t *rmp;
   int rv;
 
@@ -1680,10 +1627,10 @@ static void
 vl_api_macip_acl_interface_add_del_t_handler
   (vl_api_macip_acl_interface_add_del_t * mp)
 {
-  acl_main_t *sm = &acl_main;
+  acl_main_t *am = &acl_main;
   vl_api_macip_acl_interface_add_del_reply_t *rmp;
   int rv = -1;
-  vnet_interface_main_t *im = &sm->vnet_main->interface_main;
+  vnet_interface_main_t *im = &am->vnet_main->interface_main;
   u32 sw_if_index = ntohl (mp->sw_if_index);
 
   if (pool_is_free_index(im->sw_interfaces, sw_if_index))
@@ -1819,9 +1766,9 @@ vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t *
 static clib_error_t *
 acl_plugin_api_hookup (vlib_main_t * vm)
 {
-  acl_main_t *sm = &acl_main;
+  acl_main_t *am = &acl_main;
 #define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base),     \
+    vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base),     \
                            #n,                                 \
                            vl_api_##n##_t_handler,              \
                            vl_noop_handler,                     \
@@ -1839,10 +1786,10 @@ acl_plugin_api_hookup (vlib_main_t * vm)
 #undef vl_msg_name_crc_list
 
 static void
-setup_message_id_table (acl_main_t * sm, api_main_t * am)
+setup_message_id_table (acl_main_t * am, api_main_t * apim)
 {
 #define _(id,n,crc) \
-  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
+  vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base);
   foreach_vl_msg_name_crc_acl;
 #undef _
 }
@@ -1852,11 +1799,11 @@ register_match_action_nexts (u32 next_in_ip4, u32 next_in_ip6,
                             u32 next_out_ip4, u32 next_out_ip6)
 {
   acl_main_t *am = &acl_main;
-  u32 act = am->n_match_actions;
   if (am->n_match_actions == 255)
     {
       return ~0;
     }
+  u32 act = am->n_match_actions;
   am->n_match_actions++;
   am->acl_in_ip4_match_next[act] = next_in_ip4;
   am->acl_in_ip6_match_next[act] = next_in_ip6;
index 6b292ee..587972f 100644 (file)
@@ -58,6 +58,9 @@ flowperpkt_main_t flowperpkt_main;
 #include <flowperpkt/flowperpkt_all_api_h.h>
 #undef vl_api_version
 
+#define REPLY_MSG_ID_BASE fm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
+
 /* Define the per-interface configurable features */
 /* *INDENT-OFF* */
 VNET_FEATURE_INIT (flow_perpacket_ipv4, static) =
@@ -75,28 +78,6 @@ VNET_FEATURE_INIT (flow_perpacket_l2, static) =
 };
 /* *INDENT-ON* */
 
-/*
- * 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)+fm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
 /* Macro to finish up custom dump fns */
 #define FINISH                                  \
     vec_add1 (s, 0);                            \
@@ -104,22 +85,6 @@ do {                                                            \
     vec_free (s);                               \
     return handle;
 
-#define VALIDATE_SW_IF_INDEX(mp)                               \
- do { u32 __sw_if_index = ntohl(mp->sw_if_index);              \
-    vnet_main_t *__vnm = vnet_get_main();                       \
-    if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
-                           __sw_if_index)) {                    \
-        rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;                \
-        goto bad_sw_if_index;                                   \
-    }                                                           \
-} while(0);
-
-#define BAD_SW_IF_INDEX_LABEL                   \
-do {                                            \
-bad_sw_if_index:                                \
-    ;                                           \
-} while (0);
-
 /**
  * @brief Create an IPFIX template packet rewrite string
  * @param frm flow_report_main_t *
index f05b530..b703b8d 100644 (file)
 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_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 {                                                            \
-    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)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
+#define REPLY_MSG_ID_BASE sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
-
-
 #define foreach_vxlan_gpe_ioam_export_plugin_api_msg                        \
 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable)
 
index eeeb973..46ac3d4 100644 (file)
 #include <ioam/export/ioam_export_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 {                                                            \
-    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)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
+#define REPLY_MSG_ID_BASE sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
-
 #define foreach_ioam_export_plugin_api_msg                        \
 _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable)
 
index 9e90ff9..a4079e8 100644 (file)
 #include <ioam/ip6/ioam_cache_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 {                                                            \
-    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)+cm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
+#define REPLY_MSG_ID_BASE cm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
-
 #define foreach_ioam_cache_plugin_api_msg                        \
 _(IOAM_CACHE_IP6_ENABLE_DISABLE, ioam_cache_ip6_enable_disable)
 
index 04c2aaa..cc1b7b7 100644 (file)
 #include <ioam/lib-pot/pot_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 {                                                            \
-    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)+sm->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)+sm->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 sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
-
 #define foreach_pot_plugin_api_msg                                      \
 _(POT_PROFILE_ADD, pot_profile_add)                                     \
 _(POT_PROFILE_ACTIVATE, pot_profile_activate)                           \
index 8cb8cc9..6e5ef61 100644 (file)
 #include <ioam/udp-ping/udp_ping_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 {                                                            \
-        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)+sm->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));                               \
-        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 sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this module understands */
-
 #define foreach_udp_ping_api_msg                                      \
     _(UDP_PING_ADD_DEL_REQ, udp_ping_add_del_req)                                     \
     _(UDP_PING_EXPORT_REQ, udp_ping_export_req)                                     \
index 06c53fa..9e3bcd6 100644 (file)
@@ -51,6 +51,10 @@ typedef enum {
 #include <lb/lb.api.h>
 #undef vl_msg_name_crc_list
 
+
+#define REPLY_MSG_ID_BASE lbm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
+
 static void
 setup_message_id_table (lb_main_t * lbm, api_main_t * am)
 {
@@ -67,29 +71,6 @@ setup_message_id_table (lb_main_t * lbm, api_main_t * am)
     vec_free (s);                               \
     return handle;
 
-/*
- * 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)+lbm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
 static void
 vl_api_lb_conf_t_handler
 (vl_api_lb_conf_t * mp)
index 57274bb..d42303f 100644 (file)
@@ -47,7 +47,7 @@ snat_main_t snat_main;
 
 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
-#define REPLY_MSG_ID_BASE (sm->msg_id_base)
+#define REPLY_MSG_ID_BASE sm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
 /* Get the API version number */
index aacea7c..a492c3f 100644 (file)
@@ -36,7 +36,7 @@ do {                                                            \
         return;                                                 \
                                                                 \
     rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE);             \
+    rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE));           \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
                                                                 \
@@ -52,7 +52,7 @@ do {                                                            \
         return;                                                 \
                                                                 \
     rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE);             \
+    rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE));           \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
     do {body;} while (0);                                       \
@@ -68,7 +68,7 @@ do {                                                            \
         return;                                                 \
                                                                 \
     rmp = vl_msg_api_alloc (sizeof (*rmp) + n);                 \
-    rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE);             \
+    rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE));           \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
     do {body;} while (0);                                       \
@@ -97,7 +97,7 @@ do {                                                            \
         rv = VNET_API_ERROR_TABLE_TOO_BIG;                      \
         is_error = 1;                                           \
       }                                                         \
-    rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE);             \
+    rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE));           \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
     if (!is_error)                                              \