- int rv = 0;
- vl_api_create_vhost_user_if_reply_t *rmp;
- u32 sw_if_index = (u32) ~ 0;
-
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
-
- rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
- mp->is_server, &sw_if_index, (u64) ~ 0,
- mp->renumber, ntohl (mp->custom_dev_instance),
- (mp->use_custom_mac) ? mp->mac_address : NULL);
-
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
- ({
- rmp->sw_if_index = ntohl (sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void
-vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp)
-{
- int rv = 0;
- vl_api_modify_vhost_user_if_reply_t *rmp;
- u32 sw_if_index = ntohl (mp->sw_if_index);
-
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
-
- rv = vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename,
- mp->is_server, sw_if_index, (u64) ~ 0,
- mp->renumber, ntohl (mp->custom_dev_instance));
- REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY);
-}
-
-static void
-vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
-{
- int rv = 0;
- vl_api_delete_vhost_user_if_reply_t *rmp;
- vpe_api_main_t *vam = &vpe_api_main;
- u32 sw_if_index = ntohl (mp->sw_if_index);
-
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
-
- rv = vhost_user_delete_if (vnm, vm, sw_if_index);
-
- REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY);
- if (!rv)
- {
- unix_shared_memory_queue_t *q =
- vl_api_client_index_to_input_queue (mp->client_index);
- if (!q)
- return;
-
- send_sw_interface_flags_deleted (vam, q, sw_if_index);
- }
-}
-
-static void
- vl_api_sw_interface_vhost_user_details_t_handler
- (vl_api_sw_interface_vhost_user_details_t * mp)
-{
- clib_warning ("BUG");
-}
-
-static void
-send_sw_interface_vhost_user_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- vhost_user_intf_details_t * vui,
- u32 context)
-{
- vl_api_sw_interface_vhost_user_details_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
- mp->sw_if_index = ntohl (vui->sw_if_index);
- mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
- mp->features = clib_net_to_host_u64 (vui->features);
- mp->is_server = vui->is_server;
- mp->num_regions = ntohl (vui->num_regions);
- mp->sock_errno = ntohl (vui->sock_errno);
- mp->context = context;
-
- strncpy ((char *) mp->sock_filename,
- (char *) vui->sock_filename, ARRAY_LEN (mp->sock_filename) - 1);
- strncpy ((char *) mp->interface_name,
- (char *) vui->if_name, ARRAY_LEN (mp->interface_name) - 1);
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
- vl_api_sw_interface_vhost_user_dump_t_handler
- (vl_api_sw_interface_vhost_user_dump_t * mp)
-{
- int rv = 0;
- vpe_api_main_t *am = &vpe_api_main;
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
- vhost_user_intf_details_t *ifaces = NULL;
- vhost_user_intf_details_t *vuid = NULL;
- unix_shared_memory_queue_t *q;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- return;
-
- rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
- if (rv)
- return;
-
- vec_foreach (vuid, ifaces)
- {
- send_sw_interface_vhost_user_details (am, q, vuid, mp->context);
- }
- vec_free (ifaces);
-}
-
-static void
-send_sw_if_l2tpv3_tunnel_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- l2t_session_t * s,
- l2t_main_t * lm, u32 context)
-{
- vl_api_sw_if_l2tpv3_tunnel_details_t *mp;
- u8 *if_name = NULL;
- vnet_sw_interface_t *si = NULL;
-
- si = vnet_get_hw_sw_interface (lm->vnet_main, s->hw_if_index);
-
- if_name = format (if_name, "%U",
- format_vnet_sw_interface_name, lm->vnet_main, si);
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_IF_L2TPV3_TUNNEL_DETAILS);
- strncpy ((char *) mp->interface_name,
- (char *) if_name, ARRAY_LEN (mp->interface_name) - 1);
- mp->sw_if_index = ntohl (si->sw_if_index);
- mp->local_session_id = s->local_session_id;
- mp->remote_session_id = s->remote_session_id;
- mp->local_cookie[0] = s->local_cookie[0];
- mp->local_cookie[1] = s->local_cookie[1];
- mp->remote_cookie = s->remote_cookie;
- clib_memcpy (mp->client_address, &s->client_address,
- sizeof (s->client_address));
- clib_memcpy (mp->our_address, &s->our_address, sizeof (s->our_address));
- mp->l2_sublayer_present = s->l2_sublayer_present;
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-send_ip_address_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- u8 * ip, u16 prefix_length, u8 is_ipv6, u32 context)
-{
- vl_api_ip_address_details_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS);
-
- if (is_ipv6)
- {
- clib_memcpy (&mp->ip, ip, sizeof (mp->ip));
- }
- else
- {
- u32 *tp = (u32 *) mp->ip;
- *tp = ntohl (*(u32 *) ip);
- }
- mp->prefix_length = prefix_length;
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- unix_shared_memory_queue_t *q;
- ip6_address_t *r6;
- ip4_address_t *r4;
- ip6_main_t *im6 = &ip6_main;
- ip4_main_t *im4 = &ip4_main;
- ip_lookup_main_t *lm6 = &im6->lookup_main;
- ip_lookup_main_t *lm4 = &im4->lookup_main;
- ip_interface_address_t *ia = 0;
- u32 sw_if_index = ~0;
- int rv __attribute__ ((unused)) = 0;
-
- VALIDATE_SW_IF_INDEX (mp);
-
- sw_if_index = ntohl (mp->sw_if_index);
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- if (mp->is_ipv6)
- {
- /* *INDENT-OFF* */
- foreach_ip_interface_address (lm6, ia, sw_if_index,
- 1 /* honor unnumbered */,
- ({
- r6 = ip_interface_address_get_address (lm6, ia);
- u16 prefix_length = ia->address_length;
- send_ip_address_details(am, q, (u8*)r6, prefix_length, 1, mp->context);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- /* *INDENT-OFF* */
- foreach_ip_interface_address (lm4, ia, sw_if_index,
- 1 /* honor unnumbered */,
- ({
- r4 = ip_interface_address_get_address (lm4, ia);
- u16 prefix_length = ia->address_length;
- send_ip_address_details(am, q, (u8*)r4, prefix_length, 0, mp->context);
- }));
- /* *INDENT-ON* */
- }
- BAD_SW_IF_INDEX_LABEL;
-}
-
-static void
-send_ip_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q, u32 sw_if_index, u32 context)
-{
- vl_api_ip_details_t *mp;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS);
-
- mp->sw_if_index = ntohl (sw_if_index);
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-vl_api_sw_if_l2tpv3_tunnel_dump_t_handler (vl_api_sw_if_l2tpv3_tunnel_dump_t *
- mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- l2t_main_t *lm = &l2t_main;
- unix_shared_memory_queue_t *q;
- l2t_session_t *session;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- return;
-
- /* *INDENT-OFF* */
- pool_foreach (session, lm->sessions,
- ({
- send_sw_if_l2tpv3_tunnel_details (am, q, session, lm, mp->context);
- }));
- /* *INDENT-ON* */
-}
-
-
-static void
-send_sw_interface_tap_details (vpe_api_main_t * am,
- unix_shared_memory_queue_t * q,
- tapcli_interface_details_t * tap_if,
- u32 context)
-{
- vl_api_sw_interface_tap_details_t *mp;
- mp = vl_msg_api_alloc (sizeof (*mp));
- memset (mp, 0, sizeof (*mp));
- mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_TAP_DETAILS);
- mp->sw_if_index = ntohl (tap_if->sw_if_index);
- strncpy ((char *) mp->dev_name,
- (char *) tap_if->dev_name, ARRAY_LEN (mp->dev_name) - 1);
- mp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
-static void
-vl_api_sw_interface_tap_dump_t_handler (vl_api_sw_interface_tap_dump_t * mp)
-{
- int rv = 0;
- vpe_api_main_t *am = &vpe_api_main;
- unix_shared_memory_queue_t *q;
- tapcli_interface_details_t *tapifs = NULL;
- tapcli_interface_details_t *tap_if = NULL;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- return;
-
- rv = vnet_tap_dump_ifs (&tapifs);
- if (rv)
- return;
-
- vec_foreach (tap_if, tapifs)
- {
- send_sw_interface_tap_details (am, q, tap_if, mp->context);
- }
-
- vec_free (tapifs);
-}
-
-static void
-vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp)
-{
- vpe_api_main_t *am = &vpe_api_main;
- vnet_main_t *vnm = vnet_get_main ();
- vlib_main_t *vm = vlib_get_main ();
- vnet_interface_main_t *im = &vnm->interface_main;
- unix_shared_memory_queue_t *q;
- vnet_sw_interface_t *si, *sorted_sis;
- u32 sw_if_index = ~0;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- /* Gather interfaces. */
- sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
- _vec_len (sorted_sis) = 0;
- /* *INDENT-OFF* */
- pool_foreach (si, im->sw_interfaces,
- ({
- vec_add1 (sorted_sis, si[0]);
- }));
- /* *INDENT-ON* */
-
- vec_foreach (si, sorted_sis)
- {
- if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
- {
- if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index))
- {
- continue;
- }
- sw_if_index = si->sw_if_index;
- send_ip_details (am, q, sw_if_index, mp->context);
- }
- }
-}
-
-static void
-vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
-{
- clib_warning ("BUG");
-}