FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
format.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdbool.h>
17 #include <vlib/vlib.h>
18 #include <vnet/crypto/crypto.h>
19 
20 u8 *
21 format_vnet_crypto_alg (u8 * s, va_list * args)
22 {
23  vnet_crypto_alg_t alg = va_arg (*args, vnet_crypto_alg_t);
25  vnet_crypto_alg_data_t *d = vec_elt_at_index (cm->algs, alg);
26  return format (s, "%s", d->name);
27 }
28 
29 uword
30 unformat_vnet_crypto_alg (unformat_input_t * input, va_list * args)
31 {
33  vnet_crypto_alg_t *alg = va_arg (*args, vnet_crypto_alg_t *);
34  uword *p;
35  u8 *name;
36 
37  if (!unformat (input, "%s", &name))
38  return 0;
39 
40  p = hash_get_mem (cm->alg_index_by_name, name);
41  vec_free (name);
42  if (p == 0)
43  return 0;
44 
45  *alg = p[0];
46 
47  return 1;
48 }
49 
50 u8 *
51 format_vnet_crypto_op (u8 * s, va_list * args)
52 {
54  vnet_crypto_op_id_t op = va_arg (*args, int); // vnet_crypto_op_id_t);
55  vnet_crypto_op_data_t *otd = cm->opt_data + op;
56 
57  return format (s, "%U-%U", format_vnet_crypto_op_type, otd->type,
59 }
60 
61 u8 *
62 format_vnet_crypto_op_type (u8 * s, va_list * args)
63 {
64  vnet_crypto_op_type_t opt = va_arg (*args, vnet_crypto_op_type_t);
65  char *strings[] = {
66 #define _(n, s) [VNET_CRYPTO_OP_TYPE_##n] = s,
68 #undef _
69  };
70 
71  if (opt >= VNET_CRYPTO_OP_N_TYPES)
72  return format (s, "unknown");
73 
74  return format (s, "%s", strings[opt]);
75 }
76 
77 u8 *
78 format_vnet_crypto_op_status (u8 * s, va_list * args)
79 {
81  char *strings[] = {
82 #define _(n, s) [VNET_CRYPTO_OP_STATUS_##n] = s,
84 #undef _
85  };
86 
87  if (st >= VNET_CRYPTO_OP_N_STATUS)
88  return format (s, "unknown");
89 
90  return format (s, "%s", strings[st]);
91 }
92 
93 u8 *
94 format_vnet_crypto_engine (u8 * s, va_list * args)
95 {
97  u32 crypto_engine_index = va_arg (*args, u32);
99 
100  if (crypto_engine_index == ~0)
101  return s;
102 
103  e = vec_elt_at_index (cm->engines, crypto_engine_index);
104 
105  return format (s, "%s", e->name);
106 }
107 
108 u8 *
110 {
112  va_arg (*args, vnet_crypto_async_op_type_t);
113  char *strings[] = {
114 #define _(n, s) [VNET_CRYPTO_ASYNC_OP_TYPE_##n] = s,
116 #undef _
117  };
118 
119  if (opt >= VNET_CRYPTO_ASYNC_OP_N_TYPES)
120  return format (s, "unknown");
121 
122  return format (s, "%s", strings[opt]);
123 }
124 
125 u8 *
126 format_vnet_crypto_async_alg (u8 * s, va_list * args)
127 {
128  vnet_crypto_async_alg_t alg = va_arg (*args, vnet_crypto_async_alg_t);
130  vnet_crypto_async_alg_data_t *d = vec_elt_at_index (cm->async_algs, alg);
131  return format (s, "%s", d->name);
132 }
133 
134 u8 *
135 format_vnet_crypto_async_op (u8 * s, va_list * args)
136 {
139  vnet_crypto_async_op_data_t *otd = cm->async_opt_data + op;
140 
141  return format (s, "%U-%U", format_vnet_crypto_async_op_type, otd->type,
143 }
144 
145 /*
146  * fd.io coding-style-patch-verification: ON
147  *
148  * Local Variables:
149  * eval: (c-set-style "gnu")
150  * End:
151  */
vnet_crypto_engine_t
Definition: crypto.h:432
vlib.h
format_vnet_crypto_op
u8 * format_vnet_crypto_op(u8 *s, va_list *args)
Definition: format.c:51
vnet_crypto_async_alg_data_t
Definition: crypto.h:320
vnet_crypto_alg_data_t::name
char * name
Definition: crypto.h:244
format_vnet_crypto_async_op
u8 * format_vnet_crypto_async_op(u8 *s, va_list *args)
Definition: format.c:135
foreach_crypto_op_status
#define foreach_crypto_op_status
Definition: crypto.h:73
crypto.h
VNET_CRYPTO_ASYNC_OP_N_TYPES
@ VNET_CRYPTO_ASYNC_OP_N_TYPES
Definition: crypto.h:165
name
string name[64]
Definition: fib.api:25
vnet_crypto_main_t
Definition: crypto.h:451
vnet_crypto_async_alg_t
vnet_crypto_async_alg_t
Definition: crypto.h:168
format_vnet_crypto_engine
u8 * format_vnet_crypto_engine(u8 *s, va_list *args)
Definition: format.c:94
VNET_CRYPTO_OP_N_TYPES
@ VNET_CRYPTO_OP_N_TYPES
Definition: crypto.h:70
foreach_crypto_async_op_type
#define foreach_crypto_async_op_type
Definition: crypto.h:125
unformat_input_t
struct _unformat_input_t unformat_input_t
format_vnet_crypto_async_alg
u8 * format_vnet_crypto_async_alg(u8 *s, va_list *args)
Definition: format.c:126
vnet_crypto_alg_data_t
Definition: crypto.h:242
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vnet_crypto_async_op_data_t::type
vnet_crypto_async_op_type_t type
Definition: crypto.h:315
vnet_crypto_async_op_type_t
vnet_crypto_async_op_type_t
Definition: crypto.h:160
vnet_crypto_op_data_t
Definition: crypto.h:305
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_crypto_op_data_t::alg
vnet_crypto_alg_t alg
Definition: crypto.h:308
vnet_crypto_op_type_t
vnet_crypto_op_type_t
Definition: crypto.h:65
format_vnet_crypto_alg
u8 * format_vnet_crypto_alg(u8 *s, va_list *args)
Definition: format.c:21
unformat_vnet_crypto_alg
uword unformat_vnet_crypto_alg(unformat_input_t *input, va_list *args)
Definition: format.c:30
uword
u64 uword
Definition: types.h:112
format_vnet_crypto_async_op_type
u8 * format_vnet_crypto_async_op_type(u8 *s, va_list *args)
Definition: format.c:109
vnet_crypto_op_id_t
vnet_crypto_op_id_t
Definition: crypto.h:219
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
VNET_CRYPTO_OP_N_STATUS
@ VNET_CRYPTO_OP_N_STATUS
Definition: crypto.h:141
format
__clib_export u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:428
crypto_main
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
foreach_crypto_op_type
#define foreach_crypto_op_type
Definition: crypto.h:57
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vnet_crypto_op_data_t::type
vnet_crypto_op_type_t type
Definition: crypto.h:307
format_vnet_crypto_op_status
u8 * format_vnet_crypto_op_status(u8 *s, va_list *args)
Definition: format.c:78
vnet_crypto_async_op_data_t
Definition: crypto.h:313
u32
unsigned int u32
Definition: types.h:88
vnet_crypto_async_alg_data_t::name
char * name
Definition: crypto.h:322
u8
unsigned char u8
Definition: types.h:56
vnet_crypto_async_op_id_t
vnet_crypto_async_op_id_t
Definition: crypto.h:182
vnet_crypto_engine_t::name
char * name
Definition: crypto.h:434
format_vnet_crypto_op_type
u8 * format_vnet_crypto_op_type(u8 *s, va_list *args)
Definition: format.c:62
vnet_crypto_alg_t
vnet_crypto_alg_t
Definition: crypto.h:145
vnet_crypto_op_status_t
vnet_crypto_op_status_t
Definition: crypto.h:136
vnet_crypto_async_op_data_t::alg
vnet_crypto_async_alg_t alg
Definition: crypto.h:316