blob: 715941e0ee744c165b704417010bc593675cddee [file] [log] [blame]
Damjan Marion91f17dc2019-03-18 18:59:25 +01001/*
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
20u8 *
21format_vnet_crypto_alg (u8 * s, va_list * args)
22{
23 vnet_crypto_alg_t alg = va_arg (*args, vnet_crypto_alg_t);
24 vnet_crypto_main_t *cm = &crypto_main;
25 vnet_crypto_alg_data_t *d = vec_elt_at_index (cm->algs, alg);
26 return format (s, "%s", d->name);
27}
28
Damjan Marion61c0a3d2019-04-05 19:42:21 +020029uword
30unformat_vnet_crypto_alg (unformat_input_t * input, va_list * args)
31{
32 vnet_crypto_main_t *cm = &crypto_main;
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
Damjan Marion91f17dc2019-03-18 18:59:25 +010050u8 *
51format_vnet_crypto_op (u8 * s, va_list * args)
52{
53 vnet_crypto_main_t *cm = &crypto_main;
Damjan Marion060bfb92019-03-29 13:47:54 +010054 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;
Damjan Marion91f17dc2019-03-18 18:59:25 +010056
Damjan Marion060bfb92019-03-29 13:47:54 +010057 return format (s, "%U-%U", format_vnet_crypto_op_type, otd->type,
58 format_vnet_crypto_alg, otd->alg);
59}
60
61u8 *
62format_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,
67 foreach_crypto_op_type
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
77u8 *
78format_vnet_crypto_op_status (u8 * s, va_list * args)
79{
80 vnet_crypto_op_status_t st = va_arg (*args, vnet_crypto_op_status_t);
81 char *strings[] = {
82#define _(n, s) [VNET_CRYPTO_OP_STATUS_##n] = s,
83 foreach_crypto_op_status
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]);
Damjan Marion91f17dc2019-03-18 18:59:25 +010091}
92
93u8 *
94format_vnet_crypto_engine (u8 * s, va_list * args)
95{
96 vnet_crypto_main_t *cm = &crypto_main;
97 u32 crypto_engine_index = va_arg (*args, u32);
98 vnet_crypto_engine_t *e;
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
109/*
110 * fd.io coding-style-patch-verification: ON
111 *
112 * Local Variables:
113 * eval: (c-set-style "gnu")
114 * End:
115 */