From: Damjan Marion Date: Mon, 29 Sep 2025 15:03:57 +0000 (+0200) Subject: dev: add option to specify device-id(s) in "show device" X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F91%2F43791%2F2;p=vpp.git dev: add option to specify device-id(s) in "show device" Type: improvement Change-Id: Id0caddd67997fadb86ec493c01da7966146266c3 Signed-off-by: Damjan Marion --- diff --git a/src/vnet/dev/cli.c b/src/vnet/dev/cli.c index 06d0bf5ee35..6b86a827e3d 100644 --- a/src/vnet/dev/cli.c +++ b/src/vnet/dev/cli.c @@ -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] [ ...]", .function = show_devices_cmd_fn, .is_mp_safe = 1, }; diff --git a/src/vnet/dev/dev.h b/src/vnet/dev/dev.h index 144003c89bd..01454c57500 100644 --- a/src/vnet/dev/dev.h +++ b/src/vnet/dev/dev.h @@ -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; diff --git a/src/vnet/dev/format.c b/src/vnet/dev/format.c index eda1c7cb859..6bd730166f2 100644 --- a/src/vnet/dev/format.c +++ b/src/vnet/dev/format.c @@ -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; +}