X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=blobdiff_plain;f=src%2Fplugins%2Fsvs%2Fsvs_api.c;h=628acd01b018bd28701745667d51aa00560abed0;hp=b6c8117064d9373544cb4b06b9534a5e1f896e3d;hb=7dd63e5cc;hpb=ccc70f6c6e1f35e5103bd959ff5cdf7b4457756c diff --git a/src/plugins/svs/svs_api.c b/src/plugins/svs/svs_api.c index b6c8117064d..628acd01b01 100644 --- a/src/plugins/svs/svs_api.c +++ b/src/plugins/svs/svs_api.c @@ -27,67 +27,36 @@ #include /* define message IDs */ -#include - -/* define message structures */ -#define vl_typedefs -#include -#undef vl_typedefs - -/* define generated endian-swappers */ -#define vl_endianfun -#include -#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 -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version +#include +#include +#include /** * Base message ID fot the plugin */ static u32 svs_base_msg_id; - #include -/* List of message types that this plugin understands */ - -#define foreach_svs_plugin_api_msg \ - _(SVS_PLUGIN_GET_VERSION, svs_plugin_get_version) \ - _(SVS_TABLE_ADD_DEL, svs_table_add_del) \ - _(SVS_ROUTE_ADD_DEL, svs_route_add_del) \ - _(SVS_ENABLE_DISABLE, svs_enable_disable) \ - _(SVS_DUMP, svs_dump) - static void vl_api_svs_plugin_get_version_t_handler (vl_api_svs_plugin_get_version_t * mp) { vl_api_svs_plugin_get_version_reply_t *rmp; int msg_size = sizeof (*rmp); - unix_shared_memory_queue_t *q; + 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; rmp = vl_msg_api_alloc (msg_size); - memset (rmp, 0, msg_size); + clib_memset (rmp, 0, msg_size); rmp->_vl_msg_id = ntohs (VL_API_SVS_PLUGIN_GET_VERSION_REPLY + svs_base_msg_id); rmp->context = mp->context; rmp->major = htonl (SVS_PLUGIN_VERSION_MAJOR); rmp->minor = htonl (SVS_PLUGIN_VERSION_MINOR); - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (rp, (u8 *) rmp); } static void @@ -97,7 +66,9 @@ vl_api_svs_table_add_del_t_handler (vl_api_svs_table_add_del_t * mp) fib_protocol_t fproto; int rv = 0; - fproto = fib_proto_from_api_address_family (mp->af); + rv = fib_proto_from_api_address_family (mp->af, &fproto); + if (rv < 0) + goto error; if (mp->is_add) { @@ -108,6 +79,7 @@ vl_api_svs_table_add_del_t_handler (vl_api_svs_table_add_del_t * mp) rv = svs_table_delete (fproto, ntohl (mp->table_id)); } +error: REPLY_MACRO (VL_API_SVS_TABLE_ADD_DEL_REPLY + svs_base_msg_id); } @@ -142,7 +114,9 @@ vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp) VALIDATE_SW_IF_INDEX (mp); - fproto = fib_proto_from_api_address_family (mp->af); + rv = fib_proto_from_api_address_family (mp->af, &fproto); + if (rv < 0) + goto error; if (mp->is_enable) { @@ -155,12 +129,13 @@ vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp) } BAD_SW_IF_INDEX_LABEL; +error: REPLY_MACRO (VL_API_SVS_ENABLE_DISABLE_REPLY + svs_base_msg_id); } typedef struct svs_dump_walk_ctx_t_ { - unix_shared_memory_queue_t *q; + vl_api_registration_t *rp; u32 context; } svs_dump_walk_ctx_t; @@ -182,7 +157,7 @@ svs_send_details (fib_protocol_t fproto, mp->table_id = htonl (table_id); mp->af = fib_proto_to_api_address_family (fproto); - vl_msg_api_send_shmem (ctx->q, (u8 *) & mp); + vl_api_send_msg (ctx->rp, (u8 *) mp); return (WALK_CONTINUE); } @@ -190,72 +165,28 @@ svs_send_details (fib_protocol_t fproto, static void vl_api_svs_dump_t_handler (vl_api_svs_dump_t * mp) { - unix_shared_memory_queue_t *q; + 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; svs_dump_walk_ctx_t ctx = { - .q = q, + .rp = rp, .context = mp->context, }; svs_walk (svs_send_details, &ctx); } -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -/* Set up the API message handling tables */ -static clib_error_t * -svs_plugin_api_hookup (vlib_main_t * vm) -{ -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + svs_base_msg_id), \ - #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_svs_plugin_api_msg; -#undef _ - - return 0; -} - -static void -setup_message_id_table (api_main_t * apim) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + svs_base_msg_id); - foreach_vl_msg_name_crc_svs; -#undef _ -} - +#include static clib_error_t * svs_api_init (vlib_main_t * vm) { - clib_error_t *error = 0; - - u8 *name = format (0, "svs_%08x%c", api_version, 0); - /* Ask for a correctly-sized block of API message decode slots */ - svs_base_msg_id = vl_msg_api_get_msg_ids ((char *) name, - VL_MSG_FIRST_AVAILABLE); - - error = svs_plugin_api_hookup (vm); + svs_base_msg_id = setup_message_id_table (); - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (&api_main); - - vec_free (name); - - return error; + return 0; } VLIB_INIT_FUNCTION (svs_api_init); @@ -263,7 +194,7 @@ VLIB_INIT_FUNCTION (svs_api_init); /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, - .description = "Source VRF Select", + .description = "Source Virtual Routing and Fowarding (VRF) Select", }; /* *INDENT-ON* */