From 82fc5fd447ec2b140f1d6a8641106361176f1b80 Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Fri, 13 Sep 2019 10:20:15 +0200 Subject: [PATCH] hsa: use crypto_engine_type_t for TLS Type: refactor This patch does the following conversions TLS_ENGINE_X -> CRYPTO_ENGINE_X tls_engine_type_t -> crypto_engine_t It does not change numbering of engines Change-Id: I872dfaec3a6713bf4229c84d1ffd98b8b2419995 Signed-off-by: Nathan Skrzypczak --- src/plugins/hs_apps/echo_client.c | 2 +- src/plugins/hs_apps/echo_server.c | 2 +- src/plugins/hs_apps/sapi/vpp_echo.c | 4 ++-- src/plugins/hs_apps/sapi/vpp_echo_common.c | 8 ++++---- src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c | 2 +- src/plugins/hs_apps/sapi/vpp_echo_proto_tcp.c | 4 ++-- src/plugins/http_static/static_server.c | 2 +- src/plugins/quic/quic.c | 2 +- src/plugins/tlsmbedtls/tls_mbedtls.c | 4 ++-- src/plugins/tlsopenssl/tls_openssl.c | 4 ++-- src/vcl/vcl_bapi.c | 2 +- src/vnet/session/application_interface.h | 12 ++++++------ src/vnet/tls/tls.c | 22 +++++++++++----------- src/vnet/tls/tls.h | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/plugins/hs_apps/echo_client.c b/src/plugins/hs_apps/echo_client.c index 076fca22deb..0f8d9c5f748 100644 --- a/src/plugins/hs_apps/echo_client.c +++ b/src/plugins/hs_apps/echo_client.c @@ -775,7 +775,7 @@ echo_clients_command_fn (vlib_main_t * vm, ecm->test_bytes = 0; ecm->test_failed = 0; ecm->vlib_main = vm; - ecm->tls_engine = TLS_ENGINE_OPENSSL; + ecm->tls_engine = CRYPTO_ENGINE_OPENSSL; ecm->no_copy = 0; ecm->run_test = ECHO_CLIENTS_STARTING; diff --git a/src/plugins/hs_apps/echo_server.c b/src/plugins/hs_apps/echo_server.c index b7a74818cca..dc15185c75b 100644 --- a/src/plugins/hs_apps/echo_server.c +++ b/src/plugins/hs_apps/echo_server.c @@ -471,7 +471,7 @@ echo_server_create_command_fn (vlib_main_t * vm, unformat_input_t * input, esm->prealloc_fifos = 0; esm->private_segment_count = 0; esm->private_segment_size = 0; - esm->tls_engine = TLS_ENGINE_OPENSSL; + esm->tls_engine = CRYPTO_ENGINE_OPENSSL; vec_free (esm->server_uri); while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) diff --git a/src/plugins/hs_apps/sapi/vpp_echo.c b/src/plugins/hs_apps/sapi/vpp_echo.c index 085b0fe6083..4392168aff2 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo.c +++ b/src/plugins/hs_apps/sapi/vpp_echo.c @@ -1100,7 +1100,7 @@ main (int argc, char **argv) em->tx_buf_size = 1 << 20; em->data_source = ECHO_INVALID_DATA_SOURCE; em->uri = format (0, "%s%c", "tcp://0.0.0.0/1234", 0); - em->crypto_ctx_engine = TLS_ENGINE_NONE; + em->crypto_ctx_engine = CRYPTO_ENGINE_NONE; echo_set_each_proto_defaults_before_opts (em); echo_process_opts (argc, argv); echo_process_uri (em); @@ -1161,7 +1161,7 @@ main (int argc, char **argv) goto exit_on_error; } - if (em->crypto_ctx_engine == TLS_ENGINE_NONE) + if (em->crypto_ctx_engine == CRYPTO_ENGINE_NONE) /* when no crypto engine specified, dont expect crypto ctx */ em->state = STATE_ATTACHED; else diff --git a/src/plugins/hs_apps/sapi/vpp_echo_common.c b/src/plugins/hs_apps/sapi/vpp_echo_common.c index dbe8d92661f..06ce45c66c9 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_common.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_common.c @@ -487,9 +487,9 @@ u8 * echo_format_crypto_engine (u8 * s, va_list * args) { u32 state = va_arg (*args, u32); - if (state == TLS_ENGINE_MBEDTLS) + if (state == CRYPTO_ENGINE_MBEDTLS) return format (s, "mbedtls"); - if (state == TLS_ENGINE_OPENSSL) + if (state == CRYPTO_ENGINE_OPENSSL) return format (s, "openssl"); if (state == CRYPTO_ENGINE_PICOTLS) return format (s, "picotls"); @@ -504,9 +504,9 @@ echo_unformat_crypto_engine (unformat_input_t * input, va_list * args) { u8 *a = va_arg (*args, u8 *); if (unformat (input, "mbedtls")) - *a = TLS_ENGINE_MBEDTLS; + *a = CRYPTO_ENGINE_MBEDTLS; else if (unformat (input, "openssl")) - *a = TLS_ENGINE_OPENSSL; + *a = CRYPTO_ENGINE_OPENSSL; else if (unformat (input, "picotls")) *a = CRYPTO_ENGINE_PICOTLS; else if (unformat (input, "vpp")) diff --git a/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c b/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c index a78f949a0ef..78cedbb2c6f 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_proto_quic.c @@ -462,7 +462,7 @@ quic_echo_set_defaults_after_opts_cb () echo_main_t *em = &echo_main; u8 default_f_active; - if (em->crypto_ctx_engine == TLS_ENGINE_NONE) + if (em->crypto_ctx_engine == CRYPTO_ENGINE_NONE) em->crypto_ctx_engine = CRYPTO_ENGINE_PICOTLS; em->n_connects = em->n_clients; em->n_sessions = diff --git a/src/plugins/hs_apps/sapi/vpp_echo_proto_tcp.c b/src/plugins/hs_apps/sapi/vpp_echo_proto_tcp.c index 0854d489a41..5cb3fa667e8 100644 --- a/src/plugins/hs_apps/sapi/vpp_echo_proto_tcp.c +++ b/src/plugins/hs_apps/sapi/vpp_echo_proto_tcp.c @@ -126,8 +126,8 @@ static void tls_echo_set_defaults_after_opts_cb () { echo_main_t *em = &echo_main; - if (em->crypto_ctx_engine == TLS_ENGINE_NONE) - em->crypto_ctx_engine = TLS_ENGINE_OPENSSL; + if (em->crypto_ctx_engine == CRYPTO_ENGINE_NONE) + em->crypto_ctx_engine = CRYPTO_ENGINE_OPENSSL; } echo_proto_cb_vft_t echo_tcp_proto_cb_vft = { diff --git a/src/plugins/http_static/static_server.c b/src/plugins/http_static/static_server.c index ef9d3d77e41..610ab78f817 100644 --- a/src/plugins/http_static/static_server.c +++ b/src/plugins/http_static/static_server.c @@ -1169,7 +1169,7 @@ http_static_server_attach () hsm->fifo_size ? hsm->fifo_size : 32 << 10; a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = hsm->prealloc_fifos; - a->options[APP_OPTIONS_TLS_ENGINE] = TLS_ENGINE_OPENSSL; + a->options[APP_OPTIONS_TLS_ENGINE] = CRYPTO_ENGINE_OPENSSL; if (vnet_application_attach (a)) { diff --git a/src/plugins/quic/quic.c b/src/plugins/quic/quic.c index 6648a413e65..dcab5e34c9a 100644 --- a/src/plugins/quic/quic.c +++ b/src/plugins/quic/quic.c @@ -2079,7 +2079,7 @@ static const transport_proto_vft_t quic_proto = { /* *INDENT-ON* */ static void -quic_register_cipher_suite (tls_engine_type_t type, +quic_register_cipher_suite (crypto_engine_type_t type, ptls_cipher_suite_t ** ciphers) { quic_main_t *qm = &quic_main; diff --git a/src/plugins/tlsmbedtls/tls_mbedtls.c b/src/plugins/tlsmbedtls/tls_mbedtls.c index 7a2abaf39b9..dafb0900805 100644 --- a/src/plugins/tlsmbedtls/tls_mbedtls.c +++ b/src/plugins/tlsmbedtls/tls_mbedtls.c @@ -80,7 +80,7 @@ mbedtls_ctx_alloc (void) clib_memset (*ctx, 0, sizeof (mbedtls_ctx_t)); (*ctx)->ctx.c_thread_index = thread_index; - (*ctx)->ctx.tls_ctx_engine = TLS_ENGINE_MBEDTLS; + (*ctx)->ctx.tls_ctx_engine = CRYPTO_ENGINE_MBEDTLS; (*ctx)->mbedtls_ctx_index = ctx - tm->ctx_pool[thread_index]; return ((*ctx)->mbedtls_ctx_index); } @@ -657,7 +657,7 @@ tls_mbedtls_init (vlib_main_t * vm) vec_validate (mm->rx_bufs, num_threads - 1); vec_validate (mm->tx_bufs, num_threads - 1); - tls_register_engine (&mbedtls_engine, TLS_ENGINE_MBEDTLS); + tls_register_engine (&mbedtls_engine, CRYPTO_ENGINE_MBEDTLS); return 0; } diff --git a/src/plugins/tlsopenssl/tls_openssl.c b/src/plugins/tlsopenssl/tls_openssl.c index c383cf3561d..981e36b327c 100644 --- a/src/plugins/tlsopenssl/tls_openssl.c +++ b/src/plugins/tlsopenssl/tls_openssl.c @@ -43,7 +43,7 @@ openssl_ctx_alloc (void) clib_memset (*ctx, 0, sizeof (openssl_ctx_t)); (*ctx)->ctx.c_thread_index = thread_index; - (*ctx)->ctx.tls_ctx_engine = TLS_ENGINE_OPENSSL; + (*ctx)->ctx.tls_ctx_engine = CRYPTO_ENGINE_OPENSSL; (*ctx)->ctx.app_session_handle = SESSION_INVALID_HANDLE; (*ctx)->openssl_ctx_index = ctx - tm->ctx_pool[thread_index]; return ((*ctx)->openssl_ctx_index); @@ -892,7 +892,7 @@ tls_openssl_init (vlib_main_t * vm) vec_validate (om->ctx_pool, num_threads - 1); - tls_register_engine (&openssl_engine, TLS_ENGINE_OPENSSL); + tls_register_engine (&openssl_engine, CRYPTO_ENGINE_OPENSSL); om->engine_init = 0; diff --git a/src/vcl/vcl_bapi.c b/src/vcl/vcl_bapi.c index 2091a71abfb..7e745c1da90 100644 --- a/src/vcl/vcl_bapi.c +++ b/src/vcl/vcl_bapi.c @@ -387,7 +387,7 @@ vppcom_app_send_attach (void) bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = vcm->cfg.preallocated_fifo_pairs; bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size; - bmp->options[APP_OPTIONS_TLS_ENGINE] = TLS_ENGINE_OPENSSL; + bmp->options[APP_OPTIONS_TLS_ENGINE] = CRYPTO_ENGINE_OPENSSL; if (nsid_len) { bmp->namespace_id_len = nsid_len; diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h index fa6206a5279..17864029d6b 100644 --- a/src/vnet/session/application_interface.h +++ b/src/vnet/session/application_interface.h @@ -159,15 +159,15 @@ typedef struct _vnet_application_add_tls_key_args_t u8 *key; } vnet_app_add_tls_key_args_t; -typedef enum tls_engine_type_ +typedef enum crypto_engine_type_ { - TLS_ENGINE_NONE, - TLS_ENGINE_MBEDTLS, - TLS_ENGINE_OPENSSL, + CRYPTO_ENGINE_NONE, + CRYPTO_ENGINE_MBEDTLS, + CRYPTO_ENGINE_OPENSSL, CRYPTO_ENGINE_VPP, CRYPTO_ENGINE_PICOTLS, - TLS_N_ENGINES -} tls_engine_type_t; + CRYPTO_N_ENGINES +} crypto_engine_type_t; typedef struct _vnet_app_add_cert_key_pair_args_ { diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c index c512517f9e5..304819007d5 100644 --- a/src/vnet/tls/tls.c +++ b/src/vnet/tls/tls.c @@ -38,7 +38,7 @@ tls_disconnect_transport (tls_ctx_t * ctx) clib_warning ("disconnect returned"); } -tls_engine_type_t +crypto_engine_type_t tls_get_available_engine (void) { int i; @@ -47,7 +47,7 @@ tls_get_available_engine (void) if (tls_vfts[i].ctx_alloc) return i; } - return TLS_ENGINE_NONE; + return CRYPTO_ENGINE_NONE; } int @@ -274,8 +274,8 @@ tls_ctx_parse_handle (u32 ctx_handle, u32 * ctx_index, u32 * engine_type) *engine_type = ctx_handle >> TLS_ENGINE_TYPE_SHIFT; } -static inline tls_engine_type_t -tls_get_engine_type (tls_engine_type_t preferred) +static inline crypto_engine_type_t +tls_get_engine_type (crypto_engine_type_t preferred) { if (!tls_vfts[preferred].ctx_alloc) return tls_get_available_engine (); @@ -283,7 +283,7 @@ tls_get_engine_type (tls_engine_type_t preferred) } static inline u32 -tls_ctx_alloc (tls_engine_type_t engine_type) +tls_ctx_alloc (crypto_engine_type_t engine_type) { u32 ctx_index; ctx_index = tls_vfts[engine_type].ctx_alloc (); @@ -522,7 +522,7 @@ tls_connect (transport_endpoint_cfg_t * tep) { vnet_connect_args_t _cargs = { {}, }, *cargs = &_cargs; session_endpoint_cfg_t *sep; - tls_engine_type_t engine_type; + crypto_engine_type_t engine_type; tls_main_t *tm = &tls_main; app_worker_t *app_wrk; application_t *app; @@ -534,7 +534,7 @@ tls_connect (transport_endpoint_cfg_t * tep) app_wrk = app_worker_get (sep->app_wrk_index); app = application_get (app_wrk->app_index); engine_type = tls_get_engine_type (app->tls_engine); - if (engine_type == TLS_ENGINE_NONE) + if (engine_type == CRYPTO_ENGINE_NONE) { clib_warning ("No tls engine_type available"); return -1; @@ -588,7 +588,7 @@ tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep) session_endpoint_cfg_t *sep; session_t *tls_listener; session_t *app_listener; - tls_engine_type_t engine_type; + crypto_engine_type_t engine_type; application_t *app; app_listener_t *al; tls_ctx_t *lctx; @@ -598,7 +598,7 @@ tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep) app_wrk = app_worker_get (sep->app_wrk_index); app = application_get (app_wrk->app_index); engine_type = tls_get_engine_type (app->tls_engine); - if (engine_type == TLS_ENGINE_NONE) + if (engine_type == CRYPTO_ENGINE_NONE) { clib_warning ("No tls engine_type available"); return -1; @@ -649,7 +649,7 @@ tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep) u32 tls_stop_listen (u32 lctx_index) { - tls_engine_type_t engine_type; + crypto_engine_type_t engine_type; tls_ctx_t *lctx; int rv; @@ -817,7 +817,7 @@ static const transport_proto_vft_t tls_proto = { /* *INDENT-ON* */ void -tls_register_engine (const tls_engine_vft_t * vft, tls_engine_type_t type) +tls_register_engine (const tls_engine_vft_t * vft, crypto_engine_type_t type) { vec_validate (tls_vfts, type); tls_vfts[type] = *vft; diff --git a/src/vnet/tls/tls.h b/src/vnet/tls/tls.h index 8b1db9890cb..31572e8c463 100644 --- a/src/vnet/tls/tls.h +++ b/src/vnet/tls/tls.h @@ -119,7 +119,7 @@ typedef struct tls_engine_vft_ tls_main_t *vnet_tls_get_main (void); void tls_register_engine (const tls_engine_vft_t * vft, - tls_engine_type_t type); + crypto_engine_type_t type); int tls_add_vpp_q_rx_evt (session_t * s); int tls_add_vpp_q_tx_evt (session_t * s); int tls_add_vpp_q_builtin_tx_evt (session_t * s); -- 2.16.6