Add vnet_rename_interface API 02/702/2
authorSean Hope <shope@cisco.com>
Wed, 9 Mar 2016 05:35:21 +0000 (00:35 -0500)
committerGerrit Code Review <gerrit@fd.io>
Mon, 11 Apr 2016 13:18:02 +0000 (13:18 +0000)
Change-Id: I9a8e1ed310aa9a72644540856426c77f61f4b4bb
Signed-off-by: Todd Foggoa <tfoggoa@cisco.com>
vnet/vnet/interface.c
vnet/vnet/interface_funcs.h

index 9189a41..d36f781 100644 (file)
@@ -1078,3 +1078,40 @@ int vnet_interface_add_del_feature(vnet_main_t * vnm,
   return 0;
 }
 
+clib_error_t *
+vnet_rename_interface (vnet_main_t * vnm,
+                       u32           hw_if_index,
+                       char *        new_name)
+{
+  vnet_interface_main_t * im = &vnm->interface_main;
+  vlib_main_t * vm = vnm->vlib_main;
+  vnet_hw_interface_t* hw;
+  u8* old_name;
+  clib_error_t * error = 0;
+
+  hw = vnet_get_hw_interface(vnm, hw_if_index);
+  if (!hw)
+    {
+      return clib_error_return (0,
+                                "unable to find hw interface for index %u",
+                                 hw_if_index);
+    }
+
+  old_name = hw->name;
+
+  // set new hw->name
+  hw->name = format (0, "%s", new_name);
+
+  // remove the old name to hw_if_index mapping and install the new one
+  hash_unset_mem (im->hw_interface_by_name, old_name);
+  hash_set_mem (im->hw_interface_by_name, hw->name, hw_if_index);
+
+  // rename tx/output nodes
+  vlib_node_rename (vm, hw->tx_node_index, "%v-tx", hw->name);
+  vlib_node_rename (vm, hw->output_node_index, "%v-output", hw->name);
+
+  // free the old name vector
+  vec_free (old_name);
+
+  return error;
+}
index 7761bf7..ab89b94 100644 (file)
@@ -150,6 +150,10 @@ int vnet_hw_interface_rx_redirect_to_node (vnet_main_t * vnm, u32 hw_if_index,
 
 void vnet_hw_interface_init_for_class (vnet_main_t * vnm, u32 hw_if_index, u32 hw_class_index, u32 hw_instance);
 
+/* Rename interface */
+clib_error_t *
+vnet_rename_interface (vnet_main_t * vnm, u32  hw_if_index, char * new_name);
+
 /* Formats sw/hw interface. */
 format_function_t format_vnet_hw_interface;
 format_function_t format_vnet_sw_interface;