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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <vlib/vlib.h>
18 #include <vnet/crypto/crypto.h>
21 show_crypto_engines_command_fn (vlib_main_t * vm,
22 unformat_input_t * input,
23 vlib_cli_command_t * cmd)
25 unformat_input_t _line_input, *line_input = &_line_input;
26 vnet_crypto_main_t *cm = &crypto_main;
27 vnet_crypto_engine_t *p;
29 if (unformat_user (input, unformat_line_input, line_input))
30 unformat_free (line_input);
32 if (vec_len (cm->engines) == 0)
34 vlib_cli_output (vm, "No crypto engines registered");
38 vlib_cli_output (vm, "%-20s%-8s%s", "Name", "Prio", "Description");
40 vec_foreach (p, cm->engines)
42 vlib_cli_output (vm, "%-20s%-8u%s", p->name, p->priority, p->desc);
49 VLIB_CLI_COMMAND (show_crypto_engines_command, static) =
51 .path = "show crypto engines",
52 .short_help = "show crypto engines",
53 .function = show_crypto_engines_command_fn,
57 format_vnet_crypto_handlers (u8 * s, va_list * args)
59 vnet_crypto_alg_t alg = va_arg (*args, vnet_crypto_alg_t);
60 vnet_crypto_main_t *cm = &crypto_main;
61 vnet_crypto_alg_data_t *d = vec_elt_at_index (cm->algs, alg);
62 u32 indent = format_get_indent (s);
65 for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
67 vnet_crypto_op_data_t *od;
68 vnet_crypto_engine_t *e;
69 vnet_crypto_op_id_t id = d->op_by_type[i];
74 od = vec_elt_at_index (cm->opt_data, id);
76 s = format (s, "\n%U", format_white_space, indent);
77 s = format (s, "%-20U%-20U", format_vnet_crypto_op_type, od->type,
78 format_vnet_crypto_engine, od->active_engine_index,s);
80 vec_foreach (e, cm->engines)
82 if (e->ops_handlers[id] != 0)
83 s = format (s, "%U ", format_vnet_crypto_engine, e - cm->engines);
92 show_crypto_handlers_command_fn (vlib_main_t * vm,
93 unformat_input_t * input, vlib_cli_command_t * cmd)
95 unformat_input_t _line_input, *line_input = &_line_input;
98 if (unformat_user (input, unformat_line_input, line_input))
99 unformat_free (line_input);
101 vlib_cli_output (vm, "%-20s%-20s%-20s%s", "Algo", "Type", "Active",
104 for (i = 0; i < VNET_CRYPTO_N_ALGS; i++)
105 vlib_cli_output (vm, "%-20U%U", format_vnet_crypto_alg, i,
106 format_vnet_crypto_handlers, i);
112 VLIB_CLI_COMMAND (show_crypto_handlers_command, static) =
114 .path = "show crypto handlers",
115 .short_help = "show crypto handlers",
116 .function = show_crypto_handlers_command_fn,
120 static clib_error_t *
121 set_crypto_handler_command_fn (vlib_main_t * vm,
122 unformat_input_t * input,
123 vlib_cli_command_t * cmd)
125 unformat_input_t _line_input, *line_input = &_line_input;
126 vnet_crypto_main_t *cm = &crypto_main;
128 char **args = 0, *s, **arg, *engine = 0;
130 clib_error_t *error = 0;
132 if (!unformat_user (input, unformat_line_input, line_input))
135 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
137 if (unformat (line_input, "all"))
139 else if (unformat (line_input, "%s", &s))
143 error = clib_error_return (0, "invalid params");
148 if ((vec_len (args) < 2 && !all) || (vec_len (args) == 0 && all))
150 error = clib_error_return (0, "missing cipher or engine!");
154 engine = vec_elt_at_index (args, vec_len (args) - 1)[0];
155 vec_del1 (args, vec_len (args) - 1);
163 hash_foreach_mem (key, value, cm->alg_index_by_name,
166 rc += vnet_crypto_set_handler (key, engine);
171 vlib_cli_output (vm, "failed to set crypto engine!");
175 vec_foreach (arg, args)
177 rc = vnet_crypto_set_handler (arg[0], engine);
180 vlib_cli_output (vm, "failed to set engine %s for %s!",
188 vec_foreach (arg, args) vec_free (arg[0]);
190 unformat_free (line_input);
195 VLIB_CLI_COMMAND (set_crypto_handler_command, static) =
197 .path = "set crypto handler",
198 .short_help = "set crypto handler cipher [cipher2 cipher3 ...] engine",
199 .function = set_crypto_handler_command_fn,
204 * fd.io coding-style-patch-verification: ON
207 * eval: (c-set-style "gnu")