dev: add option to specify device-id(s) in "show device" 91/43791/2
authorDamjan Marion <[email protected]>
Mon, 29 Sep 2025 15:03:57 +0000 (17:03 +0200)
committerFlorin Coras <[email protected]>
Mon, 29 Sep 2025 17:04:56 +0000 (17:04 +0000)
Type: improvement
Change-Id: Id0caddd67997fadb86ec493c01da7966146266c3
Signed-off-by: Damjan Marion <[email protected]>
src/vnet/dev/cli.c
src/vnet/dev/dev.h
src/vnet/dev/format.c

index 06d0bf5..6b86a82 100644 (file)
@@ -316,21 +316,28 @@ show_devices_cmd_fn (vlib_main_t *vm, unformat_input_t *input,
 {
   vnet_dev_main_t *dm = &vnet_dev_main;
   vnet_dev_format_args_t fa = {}, *a = &fa;
+  vnet_dev_t **devs = 0;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
       if (unformat (input, "counters"))
        fa.counters = 1;
-      else if (unformat (input, "all"))
-       fa.show_zero_counters = 1;
+      else if (unformat (input, "zero-counters"))
+       fa.show_zero_counters = fa.counters = 1;
       else if (unformat (input, "debug"))
        fa.debug = 1;
+      else if (unformat (input, "%U", unformat_vnet_dev_vector, &devs))
+       ;
       else
        return clib_error_return (0, "unknown input `%U'",
                                  format_unformat_error, input);
     }
 
-  pool_foreach_pointer (dev, dm->devices)
+  if (vec_len (devs) == 0)
+    pool_foreach_pointer (dev, dm->devices)
+      vec_add1 (devs, dev);
+
+  vec_foreach_pointer (dev, devs)
     {
       vlib_cli_output (vm, "device '%s':", dev->device_id);
       vlib_cli_output (vm, "  %U", format_vnet_dev_info, a, dev);
@@ -362,7 +369,8 @@ show_devices_cmd_fn (vlib_main_t *vm, unformat_input_t *input,
 
 VLIB_CLI_COMMAND (show_devices_cmd, static) = {
   .path = "show device",
-  .short_help = "show device [counters] [zero-counters] [debug]",
+  .short_help =
+    "show device [counters] [zero-counters] [debug] [<device-id> ...]",
   .function = show_devices_cmd_fn,
   .is_mp_safe = 1,
 };
index 144003c..01454c5 100644 (file)
@@ -764,6 +764,7 @@ format_function_t format_vnet_dev_rv;
 format_function_t format_vnet_dev_rx_queue_info;
 format_function_t format_vnet_dev_tx_queue_info;
 format_function_t format_vnet_dev_flow;
+unformat_function_t unformat_vnet_dev_vector;
 unformat_function_t unformat_vnet_dev_flags;
 unformat_function_t unformat_vnet_dev_port_flags;
 unformat_function_t unformat_vnet_dev_rss_key;
index eda1c7c..6bd7301 100644 (file)
@@ -548,3 +548,24 @@ unformat_vnet_dev_rss_key (unformat_input_t *input, va_list *args)
   k->length = len;
   return 1;
 }
+uword
+unformat_vnet_dev_vector (unformat_input_t *in, va_list *args)
+{
+  vnet_dev_t *dev, ***devs = va_arg (*args, vnet_dev_t ***);
+  u8 *s = 0;
+  uword rv = 0;
+
+  while (unformat (in, "%s", &s))
+    {
+      dev = vnet_dev_by_id ((char *) s);
+      if (!dev)
+       break;
+
+      vec_add1 (*devs, dev);
+      vec_reset_length (s);
+      rv++;
+    }
+
+  vec_free (s);
+  return rv;
+}