X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fmemif%2Fmemif_api.c;h=a50e7ce88824ca1952bc0b4b16aae30b68b72637;hb=b2c31b685fd2cf28436ca32bc93e23eb24c74878;hp=77a87cc709d81fc0735e0cd437bb3ceac825f64c;hpb=b7b929931a07fbb27b43d5cd105f366c3e29807e;p=vpp.git diff --git a/src/plugins/memif/memif_api.c b/src/plugins/memif/memif_api.c index 77a87cc709d..a50e7ce8882 100644 --- a/src/plugins/memif/memif_api.c +++ b/src/plugins/memif/memif_api.c @@ -26,75 +26,16 @@ #include #include +#include +#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 - -/* - * 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 foreach_memif_plugin_api_msg \ -_(MEMIF_SOCKET_FILENAME_ADD_DEL, memif_socket_filename_add_del) \ -_(MEMIF_CREATE, memif_create) \ -_(MEMIF_DELETE, memif_delete) \ -_(MEMIF_SOCKET_FILENAME_DUMP, memif_socket_filename_dump) \ -_(MEMIF_DUMP, memif_dump) \ +#include +#include +#include +#define REPLY_MSG_ID_BASE mm->msg_id_base +#include /** * @brief Message handler for memif_socket_filename_add_del API. @@ -127,7 +68,7 @@ void socket_filename = 0; mp->socket_filename[ARRAY_LEN (mp->socket_filename) - 1] = 0; len = strlen ((char *) mp->socket_filename); - if (len > 0) + if (mp->is_add) { vec_validate (socket_filename, len); memcpy (socket_filename, mp->socket_filename, len); @@ -156,6 +97,7 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp) u32 ring_size = MEMIF_DEFAULT_RING_SIZE; static const u8 empty_hw_addr[6]; int rv = 0; + mac_address_t mac; /* id */ args.id = clib_net_to_host_u32 (mp->id); @@ -173,10 +115,12 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp) } /* role */ - args.is_master = (mp->role == 0); + args.is_master = (ntohl (mp->role) == MEMIF_ROLE_API_MASTER); /* mode */ - args.mode = mp->mode; + args.mode = ntohl (mp->mode); + + args.is_zero_copy = mp->no_zero_copy ? 0 : 1; /* rx/tx queues */ if (args.is_master == 0) @@ -213,9 +157,10 @@ vl_api_memif_create_t_handler (vl_api_memif_create_t * mp) } /* MAC address */ - if (memcmp (mp->hw_addr, empty_hw_addr, 6) != 0) + mac_address_decode (mp->hw_addr, &mac); + if (memcmp (&mac, empty_hw_addr, 6) != 0) { - memcpy (args.hw_addr, mp->hw_addr, 6); + memcpy (args.hw_addr, &mac, 6); args.hw_addr_set = 1; } @@ -243,11 +188,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 @@ -285,7 +233,7 @@ send_memif_details (vl_api_registration_t * reg, if (hwif->hw_address) { - memcpy (mp->hw_addr, hwif->hw_address, ARRAY_LEN (mp->hw_addr)); + mac_address_encode ((mac_address_t *) hwif->hw_address, mp->hw_addr); } mp->id = clib_host_to_net_u32 (mif->id); @@ -293,12 +241,22 @@ send_memif_details (vl_api_registration_t * reg, msf = pool_elt_at_index (mm->socket_files, mif->socket_file_index); mp->socket_id = clib_host_to_net_u32 (msf->socket_id); - mp->role = (mif->flags & MEMIF_IF_FLAG_IS_SLAVE) ? 1 : 0; + mp->role = + (mif->flags & MEMIF_IF_FLAG_IS_SLAVE) ? MEMIF_ROLE_API_SLAVE : + MEMIF_ROLE_API_MASTER; + mp->role = htonl (mp->role); + mp->mode = htonl (mif->mode); mp->ring_size = htonl (1 << mif->run.log2_ring_size); mp->buffer_size = htons (mif->run.buffer_size); + mp->zero_copy = (mif->flags & MEMIF_IF_FLAG_ZERO_COPY) ? 1 : 0; + + mp->flags = 0; + mp->flags |= (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? + IF_STATUS_API_FLAG_ADMIN_UP : 0; + mp->flags |= (hwif->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? + IF_STATUS_API_FLAG_LINK_UP : 0; + mp->flags = htonl (mp->flags); - mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0; - mp->link_up_down = (hwif->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0; vl_api_send_msg (reg, (u8 *) mp); } @@ -322,8 +280,8 @@ vl_api_memif_dump_t_handler (vl_api_memif_dump_t * mp) return; /* *INDENT-OFF* */ - pool_foreach (mif, mm->interfaces, - ({ + pool_foreach (mif, mm->interfaces) + { swif = vnet_get_sw_interface (vnm, mif->sw_if_index); if_name = format (if_name, "%U%c", @@ -332,7 +290,7 @@ vl_api_memif_dump_t_handler (vl_api_memif_dump_t * mp) send_memif_details (reg, mif, swif, if_name, mp->context); _vec_len (if_name) = 0; - })); + } /* *INDENT-ON* */ vec_free (if_name); @@ -390,51 +348,15 @@ void /* *INDENT-ON* */ } -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (memif_main_t * mm, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base); - foreach_vl_msg_name_crc_memif; -#undef _ -} - /* Set up the API message handling tables */ +#include clib_error_t * memif_plugin_api_hookup (vlib_main_t * vm) { memif_main_t *mm = &memif_main; - api_main_t *am = &api_main; - u8 *name; - - /* Construct the API name */ - name = format (0, "memif_%08x%c", api_version, 0); /* Ask for a correctly-sized block of API message decode slots */ - mm->msg_id_base = vl_msg_api_get_msg_ids - ((char *) name, VL_MSG_FIRST_AVAILABLE); - -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_base), \ - #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_memif_plugin_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (mm, am); - - vec_free (name); + mm->msg_id_base = setup_message_id_table (); return 0; }