diff options
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/error.c | 31 | ||||
-rw-r--r-- | src/vlib/error.h | 4 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/vlib/error.c b/src/vlib/error.c index 99664c618a9..1a84e7e6801 100644 --- a/src/vlib/error.c +++ b/src/vlib/error.c @@ -210,6 +210,37 @@ vlib_register_errors (vlib_main_t * vm, } } +uword +unformat_vlib_error (unformat_input_t *input, va_list *args) +{ + vlib_main_t *vm = va_arg (*args, vlib_main_t *); + const vlib_error_main_t *em = &vm->error_main; + vlib_error_t *error_index = va_arg (*args, vlib_error_t *); + const vlib_node_t *node; + char *error_name; + u32 node_index; + vlib_error_t i; + + if (!unformat (input, "%U.%s", unformat_vlib_node, vm, &node_index, + &error_name)) + return 0; + + node = vlib_get_node (vm, node_index); + for (i = 0; i < node->n_errors; i++) + { + vlib_error_t ei = node->error_heap_index + i; + if (strcmp (em->counters_heap[ei].name, error_name) == 0) + { + *error_index = ei; + vec_free (error_name); + return 1; + } + } + + vec_free (error_name); + return 0; +} + static char * sev2str (enum vl_counter_severity_e s) { diff --git a/src/vlib/error.h b/src/vlib/error.h index 11757e05f67..2bffc6b9367 100644 --- a/src/vlib/error.h +++ b/src/vlib/error.h @@ -40,6 +40,8 @@ #ifndef included_vlib_error_h #define included_vlib_error_h +#include <vppinfra/format.h> + typedef u16 vlib_error_t; enum vl_counter_severity_e @@ -75,6 +77,8 @@ void vlib_register_errors (struct vlib_main_t *vm, u32 n_errors, char *error_strings[], vl_counter_t counters[]); +unformat_function_t unformat_vlib_error; + #endif /* included_vlib_error_h */ /* |