blob: 7ae32962132ade00256678e9ece059998c106638 [file] [log] [blame]
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001/* 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
8static char *error_strings[] = {
9#define _(a, b, c) [-(b)] = c,
10 foreach_vnet_error
11#undef _
12};
13
14clib_error_t *
15vnet_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
36u8 *
37format_vnet_api_errno (u8 *s, va_list *args)
38{
39 vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
Klement Sekera35729112024-04-14 13:45:42 +020040
41 if (0 == api_error)
42 return format (s, "Success");
43
Damjan Marion81bb6fc2022-01-16 22:47:55 +010044#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}