crypto: Crypto set handler API to support set all as CLI
[vpp.git] / src / vnet / crypto / crypto_api.c
1 /*
2  * Copyright (c) 2020 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 <stddef.h>
17
18 #include <vnet/vnet.h>
19
20 #include <vnet/ip/ip_types_api.h>
21 #include <vpp/app/version.h>
22
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25
26 #include <vnet/crypto/crypto.h>
27
28 /* define message IDs */
29 #include <vnet/format_fns.h>
30 #include <vnet/crypto/crypto.api_enum.h>
31 #include <vnet/crypto/crypto.api_types.h>
32
33 /**
34  * Base message ID fot the plugin
35  */
36 static u32 crypto_base_msg_id;
37
38 #define REPLY_MSG_ID_BASE crypto_base_msg_id
39
40 #include <vlibapi/api_helper_macros.h>
41
42 static void
43 vl_api_crypto_set_async_dispatch_t_handler (vl_api_crypto_set_async_dispatch_t
44                                             * mp)
45 {
46   vl_api_crypto_set_async_dispatch_reply_t *rmp;
47   int rv = 0;
48
49   vnet_crypto_set_async_dispatch_mode ((u8) mp->mode);
50
51   REPLY_MACRO (VL_API_CRYPTO_SET_ASYNC_DISPATCH_REPLY);
52 }
53
54 static void
55 vl_api_crypto_set_handler_t_handler (vl_api_crypto_set_handler_t * mp)
56 {
57   vnet_crypto_main_t *cm = &crypto_main;
58   vl_api_crypto_set_handler_reply_t *rmp;
59   int rv = 0;
60   char *engine;
61   char *alg_name;
62   crypto_op_class_type_t oct;
63
64   engine = (char *) mp->engine;
65   alg_name = (char *) mp->alg_name;
66   oct = (crypto_op_class_type_t) mp->oct;
67
68   if (strcmp ("all", alg_name) == 0)
69     {
70       if (mp->is_async)
71         {
72           char *key;
73           u8 *value;
74
75           /* *INDENT-OFF* */
76           hash_foreach_mem (key, value, cm->async_alg_index_by_name,
77           ({
78             (void) value;
79             rv += vnet_crypto_set_async_handler2 (key, engine);
80           }));
81           /* *INDENT-ON* */
82         }
83       else
84         {
85           char *key;
86           u8 *value;
87
88           /* *INDENT-OFF* */
89           hash_foreach_mem (key, value, cm->alg_index_by_name,
90           ({
91             (void) value;
92             rv += vnet_crypto_set_handler2 (key, engine, oct);
93           }));
94           /* *INDENT-ON* */
95         }
96     }
97   else
98     {
99       if (mp->is_async)
100         rv = vnet_crypto_set_async_handler2 (alg_name, engine);
101       else
102         rv = vnet_crypto_set_handler2 (alg_name, engine, oct);
103     }
104
105   REPLY_MACRO (VL_API_CRYPTO_SET_HANDLER_REPLY);
106 }
107
108 #include <vnet/crypto/crypto.api.c>
109
110 clib_error_t *
111 crypto_api_hookup (vlib_main_t * vm)
112 {
113   /* Ask for a correctly-sized block of API message decode slots */
114   crypto_base_msg_id = setup_message_id_table ();
115
116   return 0;
117 }
118
119 VLIB_API_INIT_FUNCTION (crypto_api_hookup);
120
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "gnu")
126  * End:
127  */