interface: allow an interface's index to be given in 'sh int'
[vpp.git] / src / vnet / interface_cli.c
index 73b2757..2f231c1 100644 (file)
@@ -319,6 +319,21 @@ show_sw_interfaces (vlib_main_t * vm,
            show_vtr = 1;
          else if (unformat (linput, "verbose"))
            verbose = 1;
+         else if (unformat (linput, "%d", &sw_if_index))
+           {
+             if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
+               {
+                 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
+                 vec_add1 (sorted_sis, si[0]);
+               }
+             else
+               {
+                 vec_free (sorted_sis);
+                 error = clib_error_return (0, "unknown interface index `%d'",
+                                            sw_if_index);
+                 goto done;
+               }
+           }
          else
            {
              vec_free (sorted_sis);
@@ -448,11 +463,11 @@ show_sw_interfaces (vlib_main_t * vm,
                                      1 /* honor unnumbered */,
        ({
          ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
-         if (fib4->table_id)
-           vlib_cli_output (vm, "  L3 %U/%d ip4 table-id %d fib-idx %d",
-                            format_ip4_address, r4, ia->address_length,
-                            fib4->table_id,
-                            ip4_fib_index_from_table_id (fib4->table_id));
+         if (fib4->hash.table_id)
+           vlib_cli_output (
+             vm, "  L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
+             r4, ia->address_length, fib4->hash.table_id,
+             ip4_fib_index_from_table_id (fib4->hash.table_id));
          else
            vlib_cli_output (vm, "  L3 %U/%d",
                             format_ip4_address, r4, ia->address_length);
@@ -976,8 +991,23 @@ set_unnumbered (vlib_main_t * vm,
     return clib_error_return (0, "When enabling unnumbered specify the"
                              " IP enabled interface that it uses");
 
-  vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
-                                      inherit_from_sw_if_index, enable);
+  int rv = vnet_sw_interface_update_unnumbered (
+    unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
+
+  switch (rv)
+    {
+    case 0:
+      break;
+
+    case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
+      return clib_error_return (
+       0,
+       "When enabling unnumbered both interfaces must be in the same tables");
+
+    default:
+      return clib_error_return (
+       0, "vnet_sw_interface_update_unnumbered returned %d", rv);
+    }
 
   return (NULL);
 }
@@ -2387,6 +2417,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
  *