2 * Copyright (c) 2018 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.
16 #include <vnet/vnet.h>
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vpp/app/version.h>
20 #include <tlsopenssl/tls_openssl.h>
22 /* define message IDs */
23 #include <tlsopenssl/tls_openssl_msg_enum.h>
25 /* define message structures */
27 #include <tlsopenssl/tls_openssl_all_api_h.h>
30 /* define generated endian-swappers */
32 #include <tlsopenssl/tls_openssl_all_api_h.h>
35 /* instantiate all the print functions we know about */
36 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #include <tlsopenssl/tls_openssl_all_api_h.h>
41 /* Get the API version number */
42 #define vl_api_version(n, v) static u32 api_version = (v);
43 #include <tlsopenssl/tls_openssl_all_api_h.h>
46 #define REPLY_MSG_ID_BASE om->msg_id_base
47 #include <vlibapi/api_helper_macros.h>
49 /* List of message types that this plugin understands */
51 #define foreach_tls_openssl_plugin_api_msg \
52 _ (TLS_OPENSSL_SET_ENGINE, tls_openssl_set_engine)
54 extern openssl_main_t openssl_main;
56 /* API message handler */
58 vl_api_tls_openssl_set_engine_t_handler (vl_api_tls_openssl_set_engine_t *mp)
60 vl_api_tls_openssl_set_engine_reply_t *rmp;
61 openssl_main_t *om = &openssl_main;
62 char *engine, *alg, *ciphers;
65 engine = (char *)&mp->engine;
66 alg = (char *)&mp->algorithm;
67 ciphers = (char *)&mp->ciphers;
72 openssl_async_node_enable_disable (1);
76 tls_openssl_set_ciphers (ciphers);
77 rv = openssl_engine_register (engine, alg);
79 REPLY_MACRO (VL_API_TLS_OPENSSL_SET_ENGINE_REPLY);
82 /* Set up the API message handling tables */
83 static clib_error_t *tls_openssl_plugin_api_hookup (vlib_main_t *vm)
85 openssl_main_t *om = &openssl_main;
87 vl_msg_api_set_handlers ((VL_API_##N + om->msg_id_base), #n, \
88 vl_api_##n##_t_handler, vl_noop_handler, \
89 vl_api_##n##_t_endian, vl_api_##n##_t_print, \
90 sizeof (vl_api_##n##_t), 1);
91 foreach_tls_openssl_plugin_api_msg;
97 #define vl_msg_name_crc_list
98 #include <tlsopenssl/tls_openssl_all_api_h.h>
99 #undef vl_msg_name_crc_list
101 static void setup_message_id_table (openssl_main_t *om, api_main_t *am)
103 #define _(id, n, crc) \
104 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + om->msg_id_base);
105 foreach_vl_msg_name_crc_tls_openssl;
109 clib_error_t *tls_openssl_api_init (vlib_main_t *vm)
111 openssl_main_t *om = &openssl_main;
112 clib_error_t *error = 0;
115 name = format (0, "tls_openssl_%08x%c", api_version, 0);
117 /* Ask for a correctly-sized block of API message decode slots */
119 vl_msg_api_get_msg_ids ((char *)name, VL_MSG_FIRST_AVAILABLE);
121 error = tls_openssl_plugin_api_hookup (vm);
123 /* Add our API messages to the global name_crc hash table */
124 setup_message_id_table (om, &api_main);