X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlibapi%2Fapi_helper_macros.h;h=137348962984ff0ea29b28748d58756fa9f2e48c;hb=2019748a0ef815852281aae0a603f0e970fa9d91;hp=16f34cfc762ef1bacd8307c9838539d7f7984b1a;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vlibapi/api_helper_macros.h b/src/vlibapi/api_helper_macros.h index 16f34cfc762..13734896298 100644 --- a/src/vlibapi/api_helper_macros.h +++ b/src/vlibapi/api_helper_macros.h @@ -17,13 +17,16 @@ *------------------------------------------------------------------ */ - #ifndef __api_helper_macros_h__ #define __api_helper_macros_h__ #define f64_endian(a) #define f64_print(a,b) +#ifndef REPLY_MSG_ID_BASE +#define REPLY_MSG_ID_BASE 0 +#endif + #define REPLY_MACRO(t) \ do { \ unix_shared_memory_queue_t * q; \ @@ -33,7 +36,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ \ @@ -49,7 +52,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -65,7 +68,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \ - rmp->_vl_msg_id = ntohs((t)); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -94,7 +97,7 @@ do { \ rv = VNET_API_ERROR_TABLE_TOO_BIG; \ is_error = 1; \ } \ - rmp->_vl_msg_id = ntohs((t)); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ if (!is_error) \ @@ -104,11 +107,15 @@ do { \ /* "trust, but verify" */ +static inline uword +vnet_sw_if_index_is_api_valid (u32 sw_if_index) +{ + return vnet_sw_interface_is_api_valid (vnet_get_main (), sw_if_index); +} + #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)) { \ + if (!vnet_sw_if_index_is_api_valid(__sw_if_index)) { \ rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \ goto bad_sw_if_index; \ } \ @@ -122,9 +129,7 @@ bad_sw_if_index: \ #define VALIDATE_RX_SW_IF_INDEX(mp) \ do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \ - vnet_main_t *__vnm = vnet_get_main(); \ - if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \ - __rx_sw_if_index)) { \ + if (!vnet_sw_if_index_is_api_valid(__rx_sw_if_index)) { \ rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \ goto bad_rx_sw_if_index; \ } \ @@ -138,9 +143,7 @@ bad_rx_sw_if_index: \ #define VALIDATE_TX_SW_IF_INDEX(mp) \ do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \ - vnet_main_t *__vnm = vnet_get_main(); \ - if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \ - __tx_sw_if_index)) { \ + if (!vnet_sw_if_index_is_api_valid(__tx_sw_if_index)) { \ rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \ goto bad_tx_sw_if_index; \ } \ @@ -152,6 +155,20 @@ bad_tx_sw_if_index: \ ; \ } while (0); +#define VALIDATE_BD_ID(mp) \ + do { u32 __rx_bd_id = ntohl(mp->bd_id); \ + if (__rx_bd_id > L2_BD_ID_MAX) { \ + rv = VNET_API_ERROR_BD_ID_EXCEED_MAX; \ + goto bad_bd_id; \ + } \ +} while(0); + +#define BAD_BD_ID_LABEL \ +do { \ +bad_bd_id: \ + ; \ +} while (0); + #define pub_sub_handler(lca,UCA) \ static void vl_api_want_##lca##_t_handler ( \ vl_api_want_##lca##_t *mp) \ @@ -198,9 +215,9 @@ _(from_netconf_server) \ _(to_netconf_client) \ _(from_netconf_client) \ _(oam_events) \ -_(bfd_events) +_(bfd_events) \ +_(wc_ip4_arp_events) -/* WARNING: replicated in vpp/stats.h */ typedef struct { u32 client_index; /* in memclnt registration pool */