2 * tls_openssl_test.c - skeleton vpp-api-test plug-in
4 * Copyright (c) 2019 Intel Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
23 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
25 /* Declare message IDs */
26 #include <tlsopenssl/tls_openssl_msg_enum.h>
28 /* define message structures */
30 #include <tlsopenssl/tls_openssl_all_api_h.h>
33 /* declare message handlers for each api */
35 #define vl_endianfun /* define message structures */
36 #include <tlsopenssl/tls_openssl_all_api_h.h>
39 /* instantiate all the print functions we know about */
40 #define vl_print(handle, ...)
42 #include <tlsopenssl/tls_openssl_all_api_h.h>
45 /* Get the API version number. */
46 #define vl_api_version(n,v) static u32 api_version=(v);
47 #include <tlsopenssl/tls_openssl_all_api_h.h>
52 /* API message ID base */
55 } tls_openssl_test_main_t;
57 tls_openssl_test_main_t tls_openssl_test_main;
59 #define __plugin_msg_base tls_openssl_test_main.msg_id_base
60 #include <vlibapi/vat_helper_macros.h>
62 #define foreach_standard_reply_retval_handler \
63 _(tls_openssl_set_engine_reply)
66 static void vl_api_##n##_t_handler \
67 (vl_api_##n##_t * mp) \
69 vat_main_t * vam = tls_openssl_test_main.vat_main; \
70 i32 retval = ntohl(mp->retval); \
71 if (vam->async_mode) { \
72 vam->async_errors += (retval < 0); \
74 vam->retval = retval; \
75 vam->result_ready = 1; \
78 foreach_standard_reply_retval_handler;
82 * Table of message reply handlers, must include boilerplate handlers
85 #define foreach_vpe_api_reply_msg \
86 _(TLS_OPENSSL_SET_ENGINE_REPLY, tls_openssl_set_engine_reply)
90 api_tls_openssl_set_engine (vat_main_t * vam)
92 unformat_input_t *line_input = vam->input;
93 vl_api_tls_openssl_set_engine_t *mp;
100 /* Parse args required to build the message */
101 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
103 if (unformat (line_input, "engine %s", &engine_name))
105 else if (unformat (line_input, "async"))
109 else if (unformat (line_input, "alg %s", &engine_alg))
111 else if (unformat (line_input, "ciphers %s", &ciphers))
115 errmsg ("unknown input `%U'", format_unformat_error, line_input);
120 if (engine_name == 0)
122 errmsg ("Must specify engine name");
127 engine_alg = format (0, "ALL");
130 for (int i = 0; i < strnlen ((char *) engine_alg, 63); i++)
131 engine_alg[i] = toupper (engine_alg[i]);
135 /* Construct the API message */
136 M (TLS_OPENSSL_SET_ENGINE, mp);
137 mp->async_enable = async;
139 clib_memcpy_fast (mp->engine, engine_name,
140 strnlen ((const char *) engine_name, 63));
142 clib_memcpy_fast (mp->algorithm, engine_alg,
143 strnlen ((const char *) engine_alg, 63));
146 clib_memcpy_fast (mp->ciphers, ciphers,
147 strnlen ((const char *) ciphers, 63));
152 /* Wait for a reply... */
158 * List of messages that the api test plugin sends,
159 * and that the data plane plugin processes
161 #define foreach_vpe_api_msg \
162 _(tls_openssl_set_engine, "tls openssl set [engine <engine name>]" \
163 "[alg [algorithm] [async]\n")
166 tls_openssl_api_hookup (vat_main_t * vam)
168 tls_openssl_test_main_t *htmp = &tls_openssl_test_main;
169 /* Hook up handlers for replies from the data plane plug-in */
171 vl_msg_api_set_handlers((VL_API_##N + htmp->msg_id_base), \
173 vl_api_##n##_t_handler, \
175 vl_api_##n##_t_endian, \
176 vl_api_##n##_t_print, \
177 sizeof(vl_api_##n##_t), 1);
178 foreach_vpe_api_reply_msg;
181 /* API messages we can send */
182 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
187 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
192 VAT_PLUGIN_REGISTER (tls_openssl);
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "gnu")