diff options
author | Florin Coras <fcoras@cisco.com> | 2024-05-31 12:04:41 -0700 |
---|---|---|
committer | Florin Coras <fcoras@cisco.com> | 2024-07-09 02:04:49 -0700 |
commit | 3fe610a2aae76263b44864b8239c22951c67e752 (patch) | |
tree | 797fcf0b5a887ad7e62cd7d6fa0ac30fc10c585e /src/vnet/tls/tls.c | |
parent | 129ff04e3c564f040a8c00783ebe7f28cfadcbff (diff) |
tls: refactor vft functionsn to allow for reuse
Type: refactor
Change-Id: I3d7ff64e2e54b113f8d4b26f2dbf5b9c67b80976
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/tls/tls.c')
-rw-r--r-- | src/vnet/tls/tls.c | 156 |
1 files changed, 17 insertions, 139 deletions
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c index 5f00e6e302d..9bc9323732e 100644 --- a/src/vnet/tls/tls.c +++ b/src/vnet/tls/tls.c @@ -16,13 +16,10 @@ #include <vnet/session/application_interface.h> #include <vppinfra/lock.h> #include <vnet/tls/tls.h> +#include <vnet/tls/tls_inlines.h> static tls_main_t tls_main; -static tls_engine_vft_t *tls_vfts; - -#define TLS_INVALID_HANDLE ~0 -#define TLS_IDX_MASK 0x00FFFFFF -#define TLS_ENGINE_TYPE_SHIFT 28 +tls_engine_vft_t *tls_vfts; void tls_disconnect (u32 ctx_handle, u32 thread_index); @@ -50,6 +47,21 @@ tls_get_available_engine (void) return CRYPTO_ENGINE_NONE; } +static crypto_engine_type_t +tls_get_engine_type (crypto_engine_type_t requested, + crypto_engine_type_t preferred) +{ + if (requested != CRYPTO_ENGINE_NONE) + { + if (tls_vfts[requested].ctx_alloc) + return requested; + return CRYPTO_ENGINE_NONE; + } + if (!tls_vfts[preferred].ctx_alloc) + return tls_get_available_engine (); + return preferred; +} + int tls_add_vpp_q_rx_evt (session_t * s) { @@ -295,140 +307,6 @@ send_reply: ctx->parent_app_api_context); } -static inline void -tls_ctx_parse_handle (u32 ctx_handle, u32 * ctx_index, u32 * engine_type) -{ - *ctx_index = ctx_handle & TLS_IDX_MASK; - *engine_type = ctx_handle >> TLS_ENGINE_TYPE_SHIFT; -} - -static inline crypto_engine_type_t -tls_get_engine_type (crypto_engine_type_t requested, - crypto_engine_type_t preferred) -{ - if (requested != CRYPTO_ENGINE_NONE) - { - if (tls_vfts[requested].ctx_alloc) - return requested; - return CRYPTO_ENGINE_NONE; - } - if (!tls_vfts[preferred].ctx_alloc) - return tls_get_available_engine (); - return preferred; -} - -static inline u32 -tls_ctx_alloc (crypto_engine_type_t engine_type) -{ - u32 ctx_index; - ctx_index = tls_vfts[engine_type].ctx_alloc (); - return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); -} - -static inline u32 -tls_ctx_alloc_w_thread (crypto_engine_type_t engine_type, u32 thread_index) -{ - u32 ctx_index; - ctx_index = tls_vfts[engine_type].ctx_alloc_w_thread (thread_index); - return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); -} - -static inline u32 -tls_ctx_attach (crypto_engine_type_t engine_type, u32 thread_index, void *ctx) -{ - u32 ctx_index; - ctx_index = tls_vfts[engine_type].ctx_attach (thread_index, ctx); - return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); -} - -static inline void * -tls_ctx_detach (tls_ctx_t *ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_detach (ctx); -} - -static inline tls_ctx_t * -tls_ctx_get (u32 ctx_handle) -{ - u32 ctx_index, engine_type; - tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); - return tls_vfts[engine_type].ctx_get (ctx_index); -} - -static inline tls_ctx_t * -tls_ctx_get_w_thread (u32 ctx_handle, u8 thread_index) -{ - u32 ctx_index, engine_type; - tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); - return tls_vfts[engine_type].ctx_get_w_thread (ctx_index, thread_index); -} - -static inline int -tls_ctx_init_server (tls_ctx_t * ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_init_server (ctx); -} - -static inline int -tls_ctx_init_client (tls_ctx_t * ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_init_client (ctx); -} - -static inline int -tls_ctx_write (tls_ctx_t * ctx, session_t * app_session, - transport_send_params_t * sp) -{ - u32 n_wrote; - - sp->max_burst_size = sp->max_burst_size * TRANSPORT_PACER_MIN_MSS; - n_wrote = tls_vfts[ctx->tls_ctx_engine].ctx_write (ctx, app_session, sp); - sp->bytes_dequeued = n_wrote; - return n_wrote > 0 ? clib_max (n_wrote / TRANSPORT_PACER_MIN_MSS, 1) : 0; -} - -static inline int -tls_ctx_read (tls_ctx_t * ctx, session_t * tls_session) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_read (ctx, tls_session); -} - -static inline int -tls_ctx_transport_close (tls_ctx_t * ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_transport_close (ctx); -} - -static inline int -tls_ctx_transport_reset (tls_ctx_t *ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_transport_reset (ctx); -} - -static inline int -tls_ctx_app_close (tls_ctx_t * ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_app_close (ctx); -} - -void -tls_ctx_free (tls_ctx_t * ctx) -{ - tls_vfts[ctx->tls_ctx_engine].ctx_free (ctx); -} - -u8 -tls_ctx_handshake_is_over (tls_ctx_t * ctx) -{ - return tls_vfts[ctx->tls_ctx_engine].ctx_handshake_is_over (ctx); -} - -int -tls_reinit_ca_chain (crypto_engine_type_t tls_engine_id) -{ - return tls_vfts[tls_engine_id].ctx_reinit_cachain (); -} - void tls_notify_app_io_error (tls_ctx_t *ctx) { |