Florin Coras | 3fe610a | 2024-05-31 12:04:41 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2024 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #ifndef SRC_VNET_TLS_TLS_INLINES_H_ |
| 6 | #define SRC_VNET_TLS_TLS_INLINES_H_ |
| 7 | |
| 8 | #include <vnet/tls/tls.h> |
| 9 | |
| 10 | static inline void |
| 11 | tls_ctx_parse_handle (u32 ctx_handle, u32 *ctx_index, u32 *engine_type) |
| 12 | { |
| 13 | *ctx_index = ctx_handle & TLS_IDX_MASK; |
| 14 | *engine_type = ctx_handle >> TLS_ENGINE_TYPE_SHIFT; |
| 15 | } |
| 16 | |
| 17 | static inline u32 |
| 18 | tls_ctx_alloc (crypto_engine_type_t engine_type) |
| 19 | { |
| 20 | u32 ctx_index; |
| 21 | ctx_index = tls_vfts[engine_type].ctx_alloc (); |
| 22 | return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); |
| 23 | } |
| 24 | |
| 25 | static inline u32 |
| 26 | tls_ctx_alloc_w_thread (crypto_engine_type_t engine_type, u32 thread_index) |
| 27 | { |
| 28 | u32 ctx_index; |
| 29 | ctx_index = tls_vfts[engine_type].ctx_alloc_w_thread (thread_index); |
| 30 | return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); |
| 31 | } |
| 32 | |
| 33 | static inline tls_ctx_t * |
| 34 | tls_ctx_get (u32 ctx_handle) |
| 35 | { |
| 36 | u32 ctx_index, engine_type; |
| 37 | tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); |
| 38 | return tls_vfts[engine_type].ctx_get (ctx_index); |
| 39 | } |
| 40 | |
| 41 | static inline tls_ctx_t * |
| 42 | tls_ctx_get_w_thread (u32 ctx_handle, u8 thread_index) |
| 43 | { |
| 44 | u32 ctx_index, engine_type; |
| 45 | tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); |
| 46 | return tls_vfts[engine_type].ctx_get_w_thread (ctx_index, thread_index); |
| 47 | } |
| 48 | |
| 49 | static inline void |
| 50 | tls_ctx_free (tls_ctx_t *ctx) |
| 51 | { |
| 52 | tls_vfts[ctx->tls_ctx_engine].ctx_free (ctx); |
| 53 | } |
| 54 | |
| 55 | static inline int |
| 56 | tls_ctx_init_server (tls_ctx_t *ctx) |
| 57 | { |
| 58 | return tls_vfts[ctx->tls_ctx_engine].ctx_init_server (ctx); |
| 59 | } |
| 60 | |
| 61 | static inline int |
| 62 | tls_ctx_init_client (tls_ctx_t *ctx) |
| 63 | { |
| 64 | return tls_vfts[ctx->tls_ctx_engine].ctx_init_client (ctx); |
| 65 | } |
| 66 | |
| 67 | static inline u32 |
| 68 | tls_ctx_attach (crypto_engine_type_t engine_type, u32 thread_index, void *ctx) |
| 69 | { |
| 70 | u32 ctx_index; |
| 71 | ctx_index = tls_vfts[engine_type].ctx_attach (thread_index, ctx); |
| 72 | return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); |
| 73 | } |
| 74 | |
| 75 | static inline void * |
| 76 | tls_ctx_detach (tls_ctx_t *ctx) |
| 77 | { |
| 78 | return tls_vfts[ctx->tls_ctx_engine].ctx_detach (ctx); |
| 79 | } |
| 80 | |
| 81 | static inline int |
| 82 | tls_ctx_write (tls_ctx_t *ctx, session_t *app_session, |
| 83 | transport_send_params_t *sp) |
| 84 | { |
| 85 | u32 n_wrote; |
| 86 | |
| 87 | sp->max_burst_size = sp->max_burst_size * TRANSPORT_PACER_MIN_MSS; |
| 88 | n_wrote = tls_vfts[ctx->tls_ctx_engine].ctx_write (ctx, app_session, sp); |
| 89 | sp->bytes_dequeued = n_wrote; |
| 90 | return n_wrote > 0 ? clib_max (n_wrote / TRANSPORT_PACER_MIN_MSS, 1) : 0; |
| 91 | } |
| 92 | |
| 93 | static inline int |
| 94 | tls_ctx_read (tls_ctx_t *ctx, session_t *tls_session) |
| 95 | { |
| 96 | return tls_vfts[ctx->tls_ctx_engine].ctx_read (ctx, tls_session); |
| 97 | } |
| 98 | |
| 99 | static inline int |
| 100 | tls_ctx_transport_close (tls_ctx_t *ctx) |
| 101 | { |
| 102 | return tls_vfts[ctx->tls_ctx_engine].ctx_transport_close (ctx); |
| 103 | } |
| 104 | |
| 105 | static inline int |
| 106 | tls_ctx_transport_reset (tls_ctx_t *ctx) |
| 107 | { |
| 108 | return tls_vfts[ctx->tls_ctx_engine].ctx_transport_reset (ctx); |
| 109 | } |
| 110 | |
| 111 | static inline int |
| 112 | tls_ctx_app_close (tls_ctx_t *ctx) |
| 113 | { |
| 114 | return tls_vfts[ctx->tls_ctx_engine].ctx_app_close (ctx); |
| 115 | } |
| 116 | |
| 117 | static inline u8 |
| 118 | tls_ctx_handshake_is_over (tls_ctx_t *ctx) |
| 119 | { |
| 120 | return tls_vfts[ctx->tls_ctx_engine].ctx_handshake_is_over (ctx); |
| 121 | } |
| 122 | |
| 123 | static inline int |
| 124 | tls_reinit_ca_chain (crypto_engine_type_t tls_engine_id) |
| 125 | { |
| 126 | return tls_vfts[tls_engine_id].ctx_reinit_cachain (); |
| 127 | } |
| 128 | |
| 129 | #endif /* SRC_VNET_TLS_TLS_INLINES_H_ */ |