tap: print the interface name on cli when created
[vpp.git] / src / vnet / devices / tap / tap.c
index 35f1f2a..6c6d2ca 100644 (file)
@@ -208,7 +208,7 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
   vif->ifindex = if_nametoindex (ifr.ifr_ifrn.ifrn_name);
 
   if (!args->host_if_name)
-    args->host_if_name = (u8 *) ifr.ifr_ifrn.ifrn_name;
+    args->host_if_name = (void *) ifr.ifr_ifrn.ifrn_name;
 
   unsigned int offload = 0;
   hdrsz = sizeof (struct virtio_net_hdr_v1);
@@ -361,6 +361,29 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
        }
     }
 
+  if (args->host_mtu_set)
+    {
+      args->error =
+       vnet_netlink_set_link_mtu (vif->ifindex, args->host_mtu_size);
+      if (args->error)
+       {
+         args->rv = VNET_API_ERROR_NETLINK_ERROR;
+         goto error;
+       }
+    }
+  else if (tm->host_mtu_size != 0)
+    {
+      args->error =
+       vnet_netlink_set_link_mtu (vif->ifindex, tm->host_mtu_size);
+      if (args->error)
+       {
+         args->rv = VNET_API_ERROR_NETLINK_ERROR;
+         goto error;
+       }
+      args->host_mtu_set = 1;
+      args->host_mtu_size = tm->host_mtu_size;
+    }
+
   /* Set vhost memory table */
   i = sizeof (struct vhost_memory) + sizeof (struct vhost_memory_region);
   vhost_mem = clib_mem_alloc (i);
@@ -390,12 +413,10 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
 
   clib_memcpy (vif->mac_addr, args->mac_addr, 6);
 
-  vif->host_if_name = args->host_if_name;
-  args->host_if_name = 0;
-  vif->net_ns = args->host_namespace;
-  args->host_namespace = 0;
-  vif->host_bridge = args->host_bridge;
-  args->host_bridge = 0;
+  vif->host_if_name = format (0, "%s%c", args->host_if_name, 0);
+  vif->net_ns = format (0, "%s%c", args->host_namespace, 0);
+  vif->host_bridge = format (0, "%s%c", args->host_bridge, 0);
+  vif->host_mtu_size = args->host_mtu_size;
   clib_memcpy (vif->host_mac_addr, args->host_mac_addr, 6);
   vif->host_ip4_prefix_len = args->host_ip4_prefix_len;
   vif->host_ip6_prefix_len = args->host_ip6_prefix_len;
@@ -420,6 +441,7 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
   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;
+  args->rv = 0;
   hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
   hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
   if (args->tap_flags & TAP_FLAG_GSO)
@@ -466,6 +488,11 @@ error:
                                                               TX_QUEUE (i));
   vec_free (vif->rxq_vrings);
   vec_free (vif->txq_vrings);
+
+  vec_free (vif->host_if_name);
+  vec_free (vif->net_ns);
+  vec_free (vif->host_bridge);
+
   clib_memset (vif, 0, sizeof (virtio_if_t));
   pool_put (vim->interfaces, vif);
 
@@ -488,7 +515,7 @@ tap_delete_if (vlib_main_t * vm, u32 sw_if_index)
   virtio_if_t *vif;
   vnet_hw_interface_t *hw;
 
-  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
   if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
 
@@ -522,6 +549,10 @@ tap_delete_if (vlib_main_t * vm, u32 sw_if_index)
   vec_free (vif->rxq_vrings);
   vec_free (vif->txq_vrings);
 
+  vec_free (vif->host_if_name);
+  vec_free (vif->net_ns);
+  vec_free (vif->host_bridge);
+
   tm->tap_ids = clib_bitmap_set (tm->tap_ids, vif->id, 0);
   clib_memset (vif, 0, sizeof (*vif));
   pool_put (mm->interfaces, vif);
@@ -535,9 +566,11 @@ tap_gso_enable_disable (vlib_main_t * vm, u32 sw_if_index, int enable_disable)
   vnet_main_t *vnm = vnet_get_main ();
   virtio_main_t *mm = &virtio_main;
   virtio_if_t *vif;
-  vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
+  vnet_hw_interface_t *hw;
   clib_error_t *err = 0;
 
+  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
+
   if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
 
@@ -627,6 +660,7 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids)
     if (vif->host_ip6_prefix_len)
       clib_memcpy(tapid->host_ip6_addr, &vif->host_ip6_addr, 16);
     tapid->host_ip6_prefix_len = vif->host_ip6_prefix_len;
+    tapid->host_mtu_size = vif->host_mtu_size;
   );
   /* *INDENT-ON* */
 
@@ -635,6 +669,26 @@ tap_dump_ifs (tap_interface_details_t ** out_tapids)
   return 0;
 }
 
+static clib_error_t *
+tap_mtu_config (vlib_main_t * vm, unformat_input_t * input)
+{
+  tap_main_t *tm = &tap_main;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "host-mtu %d", &tm->host_mtu_size))
+       ;
+      else
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
+    }
+
+  return 0;
+}
+
+/* tap { host-mtu <size> } configuration. */
+VLIB_CONFIG_FUNCTION (tap_mtu_config, "tap");
+
 static clib_error_t *
 tap_init (vlib_main_t * vm)
 {
@@ -644,6 +698,8 @@ tap_init (vlib_main_t * vm)
   tm->log_default = vlib_log_register_class ("tap", 0);
   vlib_log_debug (tm->log_default, "initialized");
 
+  tm->host_mtu_size = 0;
+
   return error;
 }