X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fdevices%2Faf_packet%2Faf_packet_api.c;h=80a2d9222c6446040de53c2b6a8818ce8731d1ca;hb=7d0e30bc6;hp=3dc18b1e96aa41c11c3fa763357720c7ceb9d82e;hpb=b7b929931a07fbb27b43d5cd105f366c3e29807e;p=vpp.git diff --git a/src/vnet/devices/af_packet/af_packet_api.c b/src/vnet/devices/af_packet/af_packet_api.c index 3dc18b1e96a..80a2d9222c6 100644 --- a/src/vnet/devices/af_packet/af_packet_api.c +++ b/src/vnet/devices/af_packet/af_packet_api.c @@ -24,60 +24,73 @@ #include #include -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#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 +#include +#include +#include +#define REPLY_MSG_ID_BASE msg_id_base #include -#define foreach_vpe_api_msg \ -_(AF_PACKET_CREATE, af_packet_create) \ -_(AF_PACKET_DELETE, af_packet_delete) \ -_(AF_PACKET_SET_L4_CKSUM_OFFLOAD, af_packet_set_l4_cksum_offload) \ -_(AF_PACKET_DUMP, af_packet_dump) +static u16 msg_id_base; static void vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp) { - vlib_main_t *vm = vlib_get_main (); + af_packet_create_if_arg_t _arg, *arg = &_arg; vl_api_af_packet_create_reply_t *rmp; int rv = 0; - u8 *host_if_name = NULL; - u32 sw_if_index; - host_if_name = format (0, "%s", mp->host_if_name); - vec_add1 (host_if_name, 0); + clib_memset (arg, 0, sizeof (*arg)); - rv = af_packet_create_if (vm, host_if_name, - mp->use_random_hw_addr ? 0 : mp->hw_addr, - &sw_if_index); + arg->host_if_name = format (0, "%s", mp->host_if_name); + vec_add1 (arg->host_if_name, 0); - vec_free (host_if_name); + arg->hw_addr = mp->use_random_hw_addr ? 0 : mp->hw_addr; + rv = af_packet_create_if (arg); - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_AF_PACKET_CREATE_REPLY, - ({ - rmp->sw_if_index = clib_host_to_net_u32(sw_if_index); - })); - /* *INDENT-ON* */ + vec_free (arg->host_if_name); + + REPLY_MACRO2 (VL_API_AF_PACKET_CREATE_REPLY, ({ + rmp->sw_if_index = clib_host_to_net_u32 (arg->sw_if_index); + })); +} + +static void +vl_api_af_packet_create_v2_t_handler (vl_api_af_packet_create_v2_t *mp) +{ + af_packet_create_if_arg_t _arg, *arg = &_arg; + vl_api_af_packet_create_v2_reply_t *rmp; + int rv = 0; + + clib_memset (arg, 0, sizeof (*arg)); + + arg->host_if_name = format (0, "%s", mp->host_if_name); + vec_add1 (arg->host_if_name, 0); + + arg->rx_frame_size = clib_net_to_host_u32 (mp->rx_frame_size); + arg->tx_frame_size = clib_net_to_host_u32 (mp->tx_frame_size); + arg->rx_frames_per_block = clib_net_to_host_u32 (mp->rx_frames_per_block); + arg->tx_frames_per_block = clib_net_to_host_u32 (mp->tx_frames_per_block); + arg->hw_addr = mp->use_random_hw_addr ? 0 : mp->hw_addr; + + if (mp->num_rx_queues > 1) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto out; + } + + rv = af_packet_create_if (arg); + +out: + vec_free (arg->host_if_name); + REPLY_MACRO2 (VL_API_AF_PACKET_CREATE_V2_REPLY, ({ + rmp->sw_if_index = clib_host_to_net_u32 (arg->sw_if_index); + })); } static void vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp) { - vlib_main_t *vm = vlib_get_main (); vl_api_af_packet_delete_reply_t *rmp; int rv = 0; u8 *host_if_name = NULL; @@ -85,7 +98,7 @@ vl_api_af_packet_delete_t_handler (vl_api_af_packet_delete_t * mp) host_if_name = format (0, "%s", mp->host_if_name); vec_add1 (host_if_name, 0); - rv = af_packet_delete_if (vm, host_if_name); + rv = af_packet_delete_if (host_if_name); vec_free (host_if_name); @@ -96,11 +109,10 @@ static void vl_api_af_packet_set_l4_cksum_offload_t_handler (vl_api_af_packet_set_l4_cksum_offload_t * mp) { - vlib_main_t *vm = vlib_get_main (); vl_api_af_packet_delete_reply_t *rmp; int rv = 0; - rv = af_packet_set_l4_cksum_offload (vm, mp->sw_if_index, mp->set); + rv = af_packet_set_l4_cksum_offload (ntohl (mp->sw_if_index), mp->set); REPLY_MACRO (VL_API_AF_PACKET_SET_L4_CKSUM_OFFLOAD_REPLY); } @@ -112,7 +124,7 @@ af_packet_send_details (vpe_api_main_t * am, vl_api_af_packet_details_t *mp; mp = vl_msg_api_alloc (sizeof (*mp)); clib_memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = htons (VL_API_AF_PACKET_DETAILS); + mp->_vl_msg_id = htons (REPLY_MSG_ID_BASE + VL_API_AF_PACKET_DETAILS); mp->sw_if_index = htonl (af_packet_if->sw_if_index); clib_memcpy (mp->host_if_name, af_packet_if->host_if_name, MIN (ARRAY_LEN (mp->host_if_name) - 1, @@ -148,44 +160,14 @@ vl_api_af_packet_dump_t_handler (vl_api_af_packet_dump_t * mp) vec_free (out_af_packet_ifs); } -/* - * af_packet_api_hookup - * Add vpe's API message handlers to the table. - * vlib has alread mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_af_packet; -#undef _ -} - +#include static clib_error_t * af_packet_api_hookup (vlib_main_t * vm) { - api_main_t *am = &api_main; - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #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_vpe_api_msg; -#undef _ - /* * Set up the (msg_name, crc, message-id) table */ - setup_message_id_table (am); + REPLY_MSG_ID_BASE = setup_message_id_table (); return 0; }