crypto: introduce crypto infra
[vpp.git] / src / vnet / crypto / cli.c
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 static clib_error_t *
21 show_crypto_engines_command_fn (vlib_main_t * vm,
22                                 unformat_input_t * input,
23                                 vlib_cli_command_t * cmd)
24 {
25   unformat_input_t _line_input, *line_input = &_line_input;
26   vnet_crypto_main_t *cm = &crypto_main;
27   vnet_crypto_engine_t *p;
28
29   if (unformat_user (input, unformat_line_input, line_input))
30     unformat_free (line_input);
31
32   if (vec_len (cm->engines) == 0)
33     {
34       vlib_cli_output (vm, "No crypto engines registered");
35       return 0;
36     }
37
38   vlib_cli_output (vm, "%-20s%-8s%s", "Name", "Prio", "Description");
39   /* *INDENT-OFF* */
40   vec_foreach (p, cm->engines)
41     {
42       vlib_cli_output (vm, "%-20s%-8u%s", p->name, p->priority, p->desc);
43     }
44   /* *INDENT-ON* */
45   return 0;
46 }
47
48 /* *INDENT-OFF* */
49 VLIB_CLI_COMMAND (show_crypto_engines_command, static) =
50 {
51   .path = "show crypto engines",
52   .short_help = "show crypto engines",
53   .function = show_crypto_engines_command_fn,
54 };
55
56 static clib_error_t *
57 show_crypto_handlers_command_fn (vlib_main_t * vm,
58                         unformat_input_t * input, vlib_cli_command_t * cmd)
59 {
60   vnet_crypto_main_t *cm = &crypto_main;
61   unformat_input_t _line_input, *line_input = &_line_input;
62   u8 *s = 0;
63
64   if (unformat_user (input, unformat_line_input, line_input))
65     unformat_free (line_input);
66
67   vlib_cli_output (vm, "%-40s%-20s%s", "Name", "Active", "Candidates");
68   for (int i = 1; i < VNET_CRYPTO_N_OP_TYPES; i++)
69     {
70       vnet_crypto_op_type_data_t *otd = cm->opt_data + i;
71       vnet_crypto_engine_t *e;
72
73       vec_reset_length (s);
74       vec_foreach (e, cm->engines)
75         {
76           if (e->ops_handlers[i] != 0)
77             s = format (s, "%U ", format_vnet_crypto_engine, e - cm->engines);
78         }
79       vlib_cli_output (vm, "%-40U%-20U%v", format_vnet_crypto_op, i,
80                        format_vnet_crypto_engine, otd->active_engine_index,s);
81     }
82   vec_free (s);
83   return 0;
84 }
85
86 /* *INDENT-OFF* */
87 VLIB_CLI_COMMAND (show_crypto_handlers_command, static) =
88 {
89   .path = "show crypto handlers",
90   .short_help = "show crypto handlers",
91   .function = show_crypto_handlers_command_fn,
92 };
93 /* *INDENT-ON* */
94
95 /*
96  * fd.io coding-style-patch-verification: ON
97  *
98  * Local Variables:
99  * eval: (c-set-style "gnu")
100  * End:
101  */