tap: add option to specify interface name 28/43428/2
authorDamjan Marion <[email protected]>
Thu, 10 Jul 2025 09:47:05 +0000 (11:47 +0200)
committerAndrew Yourtchenko <[email protected]>
Wed, 16 Jul 2025 13:47:19 +0000 (13:47 +0000)
Type: feature
Change-Id: If3f8b082a2750f2786724f0e55f501df3c7d4991
Signed-off-by: Damjan Marion <[email protected]>
src/vnet/devices/tap/cli.c
src/vnet/devices/tap/tap.c
src/vnet/devices/tap/tap.h
src/vnet/devices/virtio/format.c
src/vnet/devices/virtio/virtio.h

index 5738ef2..ff6af2c 100644 (file)
@@ -50,6 +50,8 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
        {
          if (unformat (line_input, "id %u", &args.id))
            ;
+         else if (unformat (line_input, "if-name %s", &args.if_name))
+           ;
          else
            if (unformat (line_input, "host-if-name %s", &args.host_if_name))
            ;
@@ -130,6 +132,7 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
     vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
                     vnet_get_main (), args.sw_if_index);
 
+  vec_free (args.if_name);
   vec_free (args.host_if_name);
   vec_free (args.host_namespace);
   vec_free (args.host_bridge);
@@ -141,7 +144,7 @@ tap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
 VLIB_CLI_COMMAND (tap_create_command, static) = {
   .path = "create tap",
   .short_help =
-    "create tap {id <if-id>} [hw-addr <mac-address>] "
+    "create tap {id <if-id>} [hw-addr <mac-address>] [if-name <if-name>] "
     "[num-rx-queues <n>] [num-tx-queues <n>] [rx-ring-size <size>] "
     "[tx-ring-size <size>] [host-ns <netns>] [host-bridge <bridge-name>] "
     "[host-ip4-addr <ip4addr/mask>] [host-ip6-addr <ip6-addr>] "
index 8f39204..38ece0a 100644 (file)
@@ -117,6 +117,7 @@ error:
   vec_free (vif->rxq_vrings);
   vec_free (vif->txq_vrings);
   vec_free (vif->host_if_name);
+  vec_free (vif->initial_if_name);
   vec_free (vif->net_ns);
   vec_free (vif->host_bridge);
   clib_error_free (vif->error);
@@ -202,6 +203,9 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
   vif->num_txqs = clib_max (args->num_tx_queues, thm->n_vlib_mains);
   vif->num_rxqs = clib_max (args->num_rx_queues, 1);
 
+  if (args->if_name)
+    CLIB_SWAP (args->if_name, vif->initial_if_name);
+
   if (args->tap_flags & TAP_FLAG_ATTACH)
     {
       if (args->host_if_name == NULL)
index 66f5576..7b92818 100644 (file)
@@ -52,6 +52,7 @@ typedef struct
   u16 tx_ring_sz;
   u32 tap_flags;
   u8 *host_namespace;
+  u8 *if_name;
   u8 *host_if_name;
   mac_address_t host_mac_addr;
   u8 *host_bridge;
@@ -65,6 +66,7 @@ typedef struct
   u8 host_ip6_gw_set;
   u8 host_mtu_set;
   u32 host_mtu_size;
+
   /* return */
   u32 sw_if_index;
   int rv;
index fe46d92..d463a6f 100644 (file)
@@ -30,6 +30,9 @@ format_virtio_device_name (u8 * s, va_list * args)
   virtio_main_t *mm = &virtio_main;
   virtio_if_t *vif = pool_elt_at_index (mm->interfaces, dev_instance);
 
+  if (vif->initial_if_name)
+    return format (s, "%s", vif->initial_if_name);
+
   if (vif->type == VIRTIO_IF_TYPE_TAP)
     s = format (s, "tap%u", vif->id);
   else if (vif->type == VIRTIO_IF_TYPE_PCI)
index fb72051..9e75b69 100644 (file)
@@ -155,8 +155,9 @@ typedef struct
 
   u32 hw_if_index;
   u32 sw_if_index;
+  u8 *initial_if_name;
 
-    CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
+  CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
   int packet_coalesce;
   int packet_buffering;
   u32 dev_instance;