#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ip/ip4_packet.h>
#include <vlib/unix/unix.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ip/ip4_packet.h>
{
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error = clib_error_return (0, "interface already exists");
{
args->rv = VNET_API_ERROR_INVALID_INTERFACE;
args->error = clib_error_return (0, "interface already exists");
- if (!tries)
- {
- args->rv = VNET_API_ERROR_UNSPECIFIED;
- args->error =
- clib_error_return (0, "cannot find free interface id");
- return;
- }
+ if (args->id > TAP_MAX_INSTANCE)
+ {
+ args->rv = VNET_API_ERROR_UNSPECIFIED;
+ args->error = clib_error_return (0, "cannot find free interface id");
+ return;
pool_get (vim->interfaces, vif);
vif->dev_instance = vif - vim->interfaces;
vif->tap_fd = -1;
pool_get (vim->interfaces, vif);
vif->dev_instance = vif - vim->interfaces;
vif->tap_fd = -1;
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
{
args->rv = VNET_API_ERROR_UNSUPPORTED;
args->error = clib_error_return (0, "vhost-net backend doesn't support "
- vif->features |= 1ULL << VIRTIO_NET_F_MRG_RXBUF;
- vif->features |= 1ULL << VIRTIO_F_VERSION_1;
- vif->features |= 1ULL << VIRTIO_RING_F_INDIRECT_DESC;
+ vif->features |= VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF);
+ vif->features |= VIRTIO_FEATURE (VIRTIO_F_VERSION_1);
+ vif->features |= VIRTIO_FEATURE (VIRTIO_RING_F_INDIRECT_DESC);
+
+ virtio_set_net_hdr_size (vif);
old_netns_fd = open ("/proc/self/ns/net", O_RDONLY);
if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1)
{
old_netns_fd = open ("/proc/self/ns/net", O_RDONLY);
if ((fd = open_netns_fd ((char *) args->host_namespace)) == -1)
{
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
args->error = clib_error_return_unix (0, "setns '%s'",
args->host_namespace);
goto error;
}
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
args->error = clib_error_return_unix (0, "setns '%s'",
args->host_namespace);
goto error;
}
if ((vif->ifindex = if_nametoindex ((char *) args->host_if_name)) == 0)
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
if ((vif->ifindex = if_nametoindex ((char *) args->host_if_name)) == 0)
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_3;
/* Set vhost memory table */
i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region);
vhost_mem = clib_mem_alloc (i);
/* Set vhost memory table */
i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region);
vhost_mem = clib_mem_alloc (i);
vhost_mem->nregions = 1;
vhost_mem->regions[0].memory_size = (1ULL << 47) - 4096;
_IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem);
vhost_mem->nregions = 1;
vhost_mem->regions[0].memory_size = (1ULL << 47) - 4096;
_IOCTL (vif->fd, VHOST_SET_MEM_TABLE, vhost_mem);
}
vif->rx_ring_sz = args->rx_ring_sz != 0 ? args->rx_ring_sz : 256;
vif->tx_ring_sz = args->tx_ring_sz != 0 ? args->tx_ring_sz : 256;
}
vif->rx_ring_sz = args->rx_ring_sz != 0 ? args->rx_ring_sz : 256;
vif->tx_ring_sz = args->tx_ring_sz != 0 ? args->tx_ring_sz : 256;
if (args->host_ip6_prefix_len)
clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16);
if (args->host_ip6_prefix_len)
clib_memcpy (&vif->host_ip6_addr, &args->host_ip6_addr, 16);
sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
vif->sw_if_index = sw->sw_if_index;
args->sw_if_index = vif->sw_if_index;
sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
vif->sw_if_index = sw->sw_if_index;
args->sw_if_index = vif->sw_if_index;
vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, 0,
VNET_HW_INTERFACE_RX_MODE_DEFAULT);
vif->per_interface_next_index = ~0;
vnet_hw_interface_set_rx_mode (vnm, vif->hw_if_index, 0,
VNET_HW_INTERFACE_RX_MODE_DEFAULT);
vif->per_interface_next_index = ~0;
vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
VNET_HW_INTERFACE_FLAG_LINK_UP);
vif->flags |= VIRTIO_IF_FLAG_ADMIN_UP;
vnet_hw_interface_set_flags (vnm, vif->hw_if_index,
VNET_HW_INTERFACE_FLAG_LINK_UP);
if (vif->fd != -1)
close (vif->fd);
vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
if (vif->fd != -1)
close (vif->fd);
vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
- memset (vif, 0, sizeof (virtio_if_t));
+ vec_free (vif->vrings);
+ clib_memset (vif, 0, sizeof (virtio_if_t));
/* bring down the interface */
vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
vnet_sw_interface_set_flags (vnm, vif->sw_if_index, 0);
/* bring down the interface */
vnet_hw_interface_set_flags (vnm, vif->hw_if_index, 0);
vnet_sw_interface_set_flags (vnm, vif->sw_if_index, 0);
vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
vec_free (vif->vrings);
vec_foreach_index (i, vif->vrings) virtio_vring_free (vm, vif, i);
vec_free (vif->vrings);
tapid->id = vif->id;
tapid->sw_if_index = vif->sw_if_index;
hi = vnet_get_hw_interface (vnm, vif->hw_if_index);
tapid->id = vif->id;
tapid->sw_if_index = vif->sw_if_index;
hi = vnet_get_hw_interface (vnm, vif->hw_if_index);