blob: 18002730a30892b16bde12547afd1d19e3db5400 [file] [log] [blame]
Florin Coras3fe610a2024-05-31 12:04:41 -07001/* 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
10static inline void
11tls_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
17static inline u32
18tls_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
25static inline u32
26tls_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
33static inline tls_ctx_t *
34tls_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
41static inline tls_ctx_t *
42tls_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
49static inline void
50tls_ctx_free (tls_ctx_t *ctx)
51{
52 tls_vfts[ctx->tls_ctx_engine].ctx_free (ctx);
53}
54
55static inline int
56tls_ctx_init_server (tls_ctx_t *ctx)
57{
58 return tls_vfts[ctx->tls_ctx_engine].ctx_init_server (ctx);
59}
60
61static inline int
62tls_ctx_init_client (tls_ctx_t *ctx)
63{
64 return tls_vfts[ctx->tls_ctx_engine].ctx_init_client (ctx);
65}
66
67static inline u32
68tls_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
75static inline void *
76tls_ctx_detach (tls_ctx_t *ctx)
77{
78 return tls_vfts[ctx->tls_ctx_engine].ctx_detach (ctx);
79}
80
81static inline int
82tls_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
93static inline int
94tls_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
99static inline int
100tls_ctx_transport_close (tls_ctx_t *ctx)
101{
102 return tls_vfts[ctx->tls_ctx_engine].ctx_transport_close (ctx);
103}
104
105static inline int
106tls_ctx_transport_reset (tls_ctx_t *ctx)
107{
108 return tls_vfts[ctx->tls_ctx_engine].ctx_transport_reset (ctx);
109}
110
111static inline int
112tls_ctx_app_close (tls_ctx_t *ctx)
113{
114 return tls_vfts[ctx->tls_ctx_engine].ctx_app_close (ctx);
115}
116
117static inline u8
118tls_ctx_handshake_is_over (tls_ctx_t *ctx)
119{
120 return tls_vfts[ctx->tls_ctx_engine].ctx_handshake_is_over (ctx);
121}
122
123static inline int
124tls_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_ */