aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/interface_cli.c
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2021-07-26 13:38:05 -0700
committerDamjan Marion <dmarion@me.com>2021-09-08 14:35:54 +0000
commitf49734d3b9afb27e3f527e1477fee4952d546f9a (patch)
tree2d67c929ffe367c881134b3e87e558c08b88bb0d /src/vnet/interface_cli.c
parent0c373fc928316ef9928f4171b7c602c259c60d77 (diff)
interface: add custom interface name support
add CLI "set interface name <current-int-name> <new-int-name> and the corresponding binary API to allow custom interface name setting for any interface. Type: feature Signed-off-by: Steven Luong <sluong@cisco.com> Change-Id: I2b39da59879fd4526bcb5aa5854b6bd21e72ea73
Diffstat (limited to 'src/vnet/interface_cli.c')
-rw-r--r--src/vnet/interface_cli.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c
index 2bddf29b70f..8475225b525 100644
--- a/src/vnet/interface_cli.c
+++ b/src/vnet/interface_cli.c
@@ -2402,6 +2402,55 @@ VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
};
/* *INDENT-ON* */
+static clib_error_t *
+set_interface_name (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ clib_error_t *error = 0;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ vnet_main_t *vnm = vnet_get_main ();
+ u32 hw_if_index = ~0;
+ char *name = 0;
+
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
+ &hw_if_index, &name))
+ ;
+ else
+ {
+ error = clib_error_return (0, "parse error: '%U'",
+ format_unformat_error, line_input);
+ unformat_free (line_input);
+ vec_free (name);
+ return error;
+ }
+ }
+
+ unformat_free (line_input);
+
+ if (hw_if_index == (u32) ~0 || name == 0)
+ {
+ vec_free (name);
+ error = clib_error_return (0, "please specify valid interface name");
+ return error;
+ }
+
+ error = vnet_rename_interface (vnm, hw_if_index, name);
+ vec_free (name);
+
+ return (error);
+}
+
+VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
+ .path = "set interface name",
+ .short_help = "set interface name <interface-name> <new-interface-name>",
+ .function = set_interface_name,
+ .is_mp_safe = 1,
+};
/*
* fd.io coding-style-patch-verification: ON
*