summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Hope <shope@cisco.com>2016-03-09 00:35:21 -0500
committerGerrit Code Review <gerrit@fd.io>2016-04-11 13:18:02 +0000
commit608d1edf745d29ff03fc39da7351a593bf11eb5b (patch)
tree35a23ec05adca78c92d9070b60bd4fc478ff01e1
parent5ba5f83b797c2629b89cabbefea1c8bb4dccbbcd (diff)
Add vnet_rename_interface API
Change-Id: I9a8e1ed310aa9a72644540856426c77f61f4b4bb Signed-off-by: Todd Foggoa <tfoggoa@cisco.com>
-rw-r--r--vnet/vnet/interface.c37
-rw-r--r--vnet/vnet/interface_funcs.h4
2 files changed, 41 insertions, 0 deletions
diff --git a/vnet/vnet/interface.c b/vnet/vnet/interface.c
index 9189a418..d36f7811 100644
--- a/vnet/vnet/interface.c
+++ b/vnet/vnet/interface.c
@@ -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;
+}
diff --git a/vnet/vnet/interface_funcs.h b/vnet/vnet/interface_funcs.h
index 7761bf76..ab89b94e 100644
--- a/vnet/vnet/interface_funcs.h
+++ b/vnet/vnet/interface_funcs.h
@@ -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;