FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
tls.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
18 #include <vnet/session/session.h>
19 #include <vppinfra/lock.h>
20 
21 #ifndef SRC_VNET_TLS_TLS_H_
22 #define SRC_VNET_TLS_TLS_H_
23 
24 #define TLS_DEBUG 0
25 #define TLS_DEBUG_LEVEL_CLIENT 0
26 #define TLS_DEBUG_LEVEL_SERVER 0
27 
28 #define TLS_CHUNK_SIZE (1 << 14)
29 #define TLS_CA_CERT_PATH "/etc/ssl/certs/ca-certificates.crt"
30 
31 #if TLS_DEBUG
32 #define TLS_DBG(_lvl, _fmt, _args...) \
33  if (_lvl <= TLS_DEBUG) \
34  clib_warning (_fmt, ##_args)
35 #else
36 #define TLS_DBG(_lvl, _fmt, _args...)
37 #endif
38 
39 /* *INDENT-OFF* */
40 typedef struct tls_cxt_id_
41 {
42  union {
45  };
47  void *migrate_ctx;
53 } tls_ctx_id_t;
54 /* *INDENT-ON* */
55 
57  "ctx id must be less than TRANSPORT_CONN_ID_LEN");
58 
59 typedef struct tls_ctx_
60 {
61  union
62  {
65  };
66 #define parent_app_wrk_index c_tls_ctx_id.parent_app_wrk_index
67 #define app_session_handle c_tls_ctx_id.app_session_handle
68 #define tls_session_handle c_tls_ctx_id.tls_session_handle
69 #define listener_ctx_index c_tls_ctx_id.listener_ctx_index
70 #define tcp_is_ip4 c_tls_ctx_id.tcp_is_ip4
71 #define tls_ctx_engine c_tls_ctx_id.tls_engine_id
72 #define tls_ssl_ctx c_tls_ctx_id.ssl_ctx
73 #define tls_ctx_handle c_c_index
74  /* Temporary storage for session open opaque. Overwritten once
75  * underlying tcp connection is established */
76 #define parent_app_api_context c_tls_ctx_id.parent_app_api_ctx
77 #define migration_ctx c_tls_ctx_id.migrate_ctx
78 
88 } tls_ctx_t;
89 
90 typedef struct tls_main_
91 {
98 
99  /*
100  * Config
101  */
106 } tls_main_t;
107 
108 typedef struct tls_engine_vft_
109 {
110  u32 (*ctx_alloc) (void);
112  void (*ctx_free) (tls_ctx_t * ctx);
113  void *(*ctx_detach) (tls_ctx_t *ctx);
115  tls_ctx_t *(*ctx_get) (u32 ctx_index);
116  tls_ctx_t *(*ctx_get_w_thread) (u32 ctx_index, u8 thread_index);
119  int (*ctx_read) (tls_ctx_t * ctx, session_t * tls_session);
120  int (*ctx_write) (tls_ctx_t * ctx, session_t * app_session,
128 
130 void tls_register_engine (const tls_engine_vft_t * vft,
138 void tls_notify_app_enqueue (tls_ctx_t * ctx, session_t * app_session);
140 #endif /* SRC_VNET_TLS_TLS_H_ */
141 
142 /*
143  * fd.io coding-style-patch-verification: ON
144  *
145  * Local Variables:
146  * eval: (c-set-style "gnu")
147  * End:
148  */
tls_main_
Definition: tls.h:90
crypto_engine_type_t
enum crypto_engine_type_ crypto_engine_type_t
session_error_t
enum session_error_ session_error_t
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
tls_cxt_id_
Definition: tls.h:40
tls_engine_vft_::ctx_write
int(* ctx_write)(tls_ctx_t *ctx, session_t *app_session, transport_send_params_t *sp)
Definition: tls.h:120
tls_engine_vft_::ctx_app_close
int(* ctx_app_close)(tls_ctx_t *ctx)
Definition: tls.h:126
tls_add_vpp_q_rx_evt
int tls_add_vpp_q_rx_evt(session_t *s)
Definition: tls.c:54
tls_main_::app_index
u32 app_index
Definition: tls.h:92
tls_main_::listener_ctx_pool
tls_ctx_t * listener_ctx_pool
Definition: tls.h:93
tls_main_::tx_bufs
u8 ** tx_bufs
Definition: tls.h:97
tls_notify_app_accept
int tls_notify_app_accept(tls_ctx_t *ctx)
Definition: tls.c:182
tls_notify_app_enqueue
void tls_notify_app_enqueue(tls_ctx_t *ctx, session_t *app_session)
Definition: tls.c:173
session_
Definition: session_types.h:175
tls_engine_vft_::ctx_start_listen
int(* ctx_start_listen)(tls_ctx_t *ctx)
Definition: tls.h:123
u8
#define u8
Padding.
Definition: clib.h:121
tls_disconnect_transport
void tls_disconnect_transport(tls_ctx_t *ctx)
Definition: tls.c:30
session_handle_t
u64 session_handle_t
Definition: session_types.h:111
tls_cxt_id_::parent_app_api_ctx
u32 parent_app_api_ctx
Definition: tls.h:44
tls_ctx_::tls_type
transport_proto_t tls_type
Definition: tls.h:87
tls_notify_app_connected
int tls_notify_app_connected(tls_ctx_t *ctx, session_error_t err)
Definition: tls.c:212
tls_ctx_::no_app_session
u8 no_app_session
Definition: tls.h:82
tls_engine_vft_
Definition: tls.h:108
tls_cxt_id_::tcp_is_ip4
u8 tcp_is_ip4
Definition: tls.h:51
transport_connection_t
struct _transport_connection transport_connection_t
tls_ctx_::is_passive_close
u8 is_passive_close
Definition: tls.h:79
tls_add_vpp_q_builtin_tx_evt
int tls_add_vpp_q_builtin_tx_evt(session_t *s)
tls_main_::use_test_cert_in_ca
u8 use_test_cert_in_ca
Definition: tls.h:102
tls_main_::ca_cert_path
char * ca_cert_path
Definition: tls.h:103
tls_engine_vft_::ctx_stop_listen
int(* ctx_stop_listen)(tls_ctx_t *ctx)
Definition: tls.h:124
tls_ctx_
Definition: tls.h:59
tls_ctx_::c_tls_ctx_id
tls_ctx_id_t c_tls_ctx_id
Definition: tls.h:64
lock.h
tls_main_::first_seg_size
u64 first_seg_size
Definition: tls.h:104
vnet_tls_get_main
tls_main_t * vnet_tls_get_main(void)
Definition: tls.c:1366
clib_rw_lock_
Definition: lock.h:139
tls_ctx_::connection
transport_connection_t connection
Definition: tls.h:63
tls_engine_vft_::ctx_free
void(* ctx_free)(tls_ctx_t *ctx)
Definition: tls.h:112
tls_engine_vft_t
struct tls_engine_vft_ tls_engine_vft_t
tls_main_::fifo_size
u32 fifo_size
Definition: tls.h:105
tls_cxt_id_::app_session_handle
session_handle_t app_session_handle
Definition: tls.h:43
tls_cxt_id_::parent_app_wrk_index
u32 parent_app_wrk_index
Definition: tls.h:48
tls_main_::half_open_ctx_pool
tls_ctx_t * half_open_ctx_pool
Definition: tls.h:94
tls_cxt_id_::migrate_ctx
void * migrate_ctx
Definition: tls.h:47
transport_send_params_
Definition: transport.h:45
tls_engine_vft_::ctx_init_server
int(* ctx_init_server)(tls_ctx_t *ctx)
Definition: tls.h:118
tls_engine_vft_::ctx_transport_close
int(* ctx_transport_close)(tls_ctx_t *ctx)
Definition: tls.h:125
tls_main_t
struct tls_main_ tls_main_t
u64
unsigned long u64
Definition: types.h:89
tls_cxt_id_::listener_ctx_index
u32 listener_ctx_index
Definition: tls.h:50
tls_engine_vft_::ctx_init_client
int(* ctx_init_client)(tls_ctx_t *ctx)
Definition: tls.h:117
tls_ctx_::ckpair_index
u32 ckpair_index
Definition: tls.h:86
u32
unsigned int u32
Definition: types.h:88
tls_ctx_::resume
u8 resume
Definition: tls.h:80
transport_proto_t
enum _transport_proto transport_proto_t
tls_ctx_::srv_hostname
u8 * srv_hostname
Definition: tls.h:84
tls_engine_vft_::ctx_read
int(* ctx_read)(tls_ctx_t *ctx, session_t *tls_session)
Definition: tls.h:119
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
tls_cxt_id_::tls_session_handle
session_handle_t tls_session_handle
Definition: tls.h:46
tls_cxt_id_::ssl_ctx
u32 ssl_ctx
Definition: tls.h:49
tls_ctx_::evt_index
u32 evt_index
Definition: tls.h:85
tls_cxt_id_::tls_engine_id
u8 tls_engine_id
Definition: tls.h:52
tls_ctx_id_t
struct tls_cxt_id_ tls_ctx_id_t
tls_main_::rx_bufs
u8 ** rx_bufs
Definition: tls.h:96
application_interface.h
u8
unsigned char u8
Definition: types.h:56
session.h
tls_engine_vft_::ctx_alloc
u32(* ctx_alloc)(void)
Definition: tls.h:110
tls_ctx_t
struct tls_ctx_ tls_ctx_t
tls_engine_vft_::ctx_alloc_w_thread
u32(* ctx_alloc_w_thread)(u32 thread_index)
Definition: tls.h:111
tls_engine_vft_::ctx_attach
u32(* ctx_attach)(u32 thread_index, void *ctx)
Definition: tls.h:114
tls_add_vpp_q_tx_evt
int tls_add_vpp_q_tx_evt(session_t *s)
Definition: tls.c:70
tls_ctx_::is_migrated
u8 is_migrated
Definition: tls.h:83
tls_engine_vft_::ctx_handshake_is_over
u8(* ctx_handshake_is_over)(tls_ctx_t *ctx)
Definition: tls.h:122
tls_main_::half_open_rwlock
clib_rwlock_t half_open_rwlock
Definition: tls.h:95
TRANSPORT_CONN_ID_LEN
#define TRANSPORT_CONN_ID_LEN
Definition: transport_types.h:74
tls_register_engine
void tls_register_engine(const tls_engine_vft_t *vft, crypto_engine_type_t type)
Definition: tls.c:1296
tls_ctx_::app_closed
u8 app_closed
Definition: tls.h:81
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
STATIC_ASSERT
STATIC_ASSERT(sizeof(tls_ctx_id_t)<=TRANSPORT_CONN_ID_LEN, "ctx id must be less than TRANSPORT_CONN_ID_LEN")
tls_add_vpp_q_builtin_rx_evt
int tls_add_vpp_q_builtin_rx_evt(session_t *s)
Definition: tls.c:62
application.h