Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2022 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #include <vppinfra/error.h> |
| 6 | #include <vnet/api_errno.h> |
| 7 | |
| 8 | static char *error_strings[] = { |
| 9 | #define _(a, b, c) [-(b)] = c, |
| 10 | foreach_vnet_error |
| 11 | #undef _ |
| 12 | }; |
| 13 | |
| 14 | clib_error_t * |
| 15 | vnet_error (vnet_error_t rv, char *fmt, ...) |
| 16 | { |
| 17 | clib_error_t *e, *err = 0; |
| 18 | va_list va; |
| 19 | vec_add2 (err, e, 1); |
| 20 | e->what = format (e->what, "%s", error_strings[-rv]); |
| 21 | |
| 22 | if (fmt) |
| 23 | { |
| 24 | vec_add1 (e->what, ' '); |
| 25 | vec_add1 (e->what, '('); |
| 26 | va_start (va, fmt); |
| 27 | e->what = va_format (e->what, fmt, &va); |
| 28 | vec_add1 (e->what, ')'); |
| 29 | va_end (va); |
| 30 | } |
| 31 | |
| 32 | e->code = rv; |
| 33 | return err; |
| 34 | } |
| 35 | |
| 36 | u8 * |
| 37 | format_vnet_api_errno (u8 *s, va_list *args) |
| 38 | { |
| 39 | vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t); |
Klement Sekera | 3572911 | 2024-04-14 13:45:42 +0200 | [diff] [blame^] | 40 | |
| 41 | if (0 == api_error) |
| 42 | return format (s, "Success"); |
| 43 | |
Damjan Marion | 81bb6fc | 2022-01-16 22:47:55 +0100 | [diff] [blame] | 44 | #ifdef _ |
| 45 | #undef _ |
| 46 | #endif |
| 47 | #define _(a, b, c) \ |
| 48 | case b: \ |
| 49 | s = format (s, "%s", c); \ |
| 50 | break; |
| 51 | switch (api_error) |
| 52 | { |
| 53 | foreach_vnet_error default : s = format (s, "UNKNOWN"); |
| 54 | break; |
| 55 | } |
| 56 | return s; |
| 57 | #undef _ |
| 58 | } |