Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | |
| 16 | #include <vnet/session/application_interface.h> |
| 17 | #include <vppinfra/lock.h> |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 18 | #include <vnet/tls/tls.h> |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 19 | |
| 20 | static tls_main_t tls_main; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 21 | static tls_engine_vft_t *tls_vfts; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 22 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 23 | #define TLS_INVALID_HANDLE ~0 |
| 24 | #define TLS_IDX_MASK 0x00FFFFFF |
| 25 | #define TLS_ENGINE_TYPE_SHIFT 29 |
| 26 | |
| 27 | void tls_disconnect (u32 ctx_handle, u32 thread_index); |
| 28 | |
| 29 | tls_engine_type_t |
| 30 | tls_get_available_engine (void) |
| 31 | { |
| 32 | int i; |
| 33 | for (i = 0; i < vec_len (tls_vfts); i++) |
| 34 | { |
| 35 | if (tls_vfts[i].ctx_alloc) |
| 36 | return i; |
| 37 | } |
| 38 | return TLS_ENGINE_NONE; |
| 39 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 40 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 41 | int |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 42 | tls_add_vpp_q_evt (svm_fifo_t * f, u8 evt_type) |
| 43 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 44 | if (svm_fifo_set_event (f)) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 45 | session_send_io_evt_to_thread (f, evt_type); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static inline int |
| 50 | tls_add_app_q_evt (application_t * app, stream_session_t * app_session) |
| 51 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 52 | return application_send_event (app, app_session, FIFO_EVENT_APP_RX); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | u32 |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 56 | tls_listener_ctx_alloc (void) |
| 57 | { |
| 58 | tls_main_t *tm = &tls_main; |
| 59 | tls_ctx_t *ctx; |
| 60 | |
| 61 | pool_get (tm->listener_ctx_pool, ctx); |
| 62 | memset (ctx, 0, sizeof (*ctx)); |
| 63 | return ctx - tm->listener_ctx_pool; |
| 64 | } |
| 65 | |
| 66 | void |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 67 | tls_listener_ctx_free (tls_ctx_t * ctx) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 68 | { |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 69 | pool_put (tls_main.listener_ctx_pool, ctx); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | tls_ctx_t * |
| 73 | tls_listener_ctx_get (u32 ctx_index) |
| 74 | { |
| 75 | return pool_elt_at_index (tls_main.listener_ctx_pool, ctx_index); |
| 76 | } |
| 77 | |
| 78 | u32 |
| 79 | tls_listener_ctx_index (tls_ctx_t * ctx) |
| 80 | { |
| 81 | return (ctx - tls_main.listener_ctx_pool); |
| 82 | } |
| 83 | |
| 84 | u32 |
| 85 | tls_ctx_half_open_alloc (void) |
| 86 | { |
| 87 | tls_main_t *tm = &tls_main; |
| 88 | u8 will_expand = 0; |
| 89 | tls_ctx_t *ctx; |
| 90 | u32 ctx_index; |
| 91 | |
| 92 | pool_get_aligned_will_expand (tm->half_open_ctx_pool, will_expand, 0); |
| 93 | if (PREDICT_FALSE (will_expand && vlib_num_workers ())) |
| 94 | { |
| 95 | clib_rwlock_writer_lock (&tm->half_open_rwlock); |
| 96 | pool_get (tm->half_open_ctx_pool, ctx); |
| 97 | memset (ctx, 0, sizeof (*ctx)); |
| 98 | ctx_index = ctx - tm->half_open_ctx_pool; |
| 99 | clib_rwlock_writer_unlock (&tm->half_open_rwlock); |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | pool_get (tm->half_open_ctx_pool, ctx); |
| 104 | memset (ctx, 0, sizeof (*ctx)); |
| 105 | ctx_index = ctx - tm->half_open_ctx_pool; |
| 106 | } |
| 107 | return ctx_index; |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | tls_ctx_half_open_free (u32 ho_index) |
| 112 | { |
| 113 | tls_main_t *tm = &tls_main; |
| 114 | clib_rwlock_writer_lock (&tm->half_open_rwlock); |
| 115 | pool_put_index (tls_main.half_open_ctx_pool, ho_index); |
| 116 | clib_rwlock_writer_unlock (&tm->half_open_rwlock); |
| 117 | } |
| 118 | |
| 119 | tls_ctx_t * |
| 120 | tls_ctx_half_open_get (u32 ctx_index) |
| 121 | { |
| 122 | tls_main_t *tm = &tls_main; |
| 123 | clib_rwlock_reader_lock (&tm->half_open_rwlock); |
| 124 | return pool_elt_at_index (tm->half_open_ctx_pool, ctx_index); |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | tls_ctx_half_open_reader_unlock () |
| 129 | { |
| 130 | clib_rwlock_reader_unlock (&tls_main.half_open_rwlock); |
| 131 | } |
| 132 | |
| 133 | u32 |
| 134 | tls_ctx_half_open_index (tls_ctx_t * ctx) |
| 135 | { |
| 136 | return (ctx - tls_main.half_open_ctx_pool); |
| 137 | } |
| 138 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 139 | void |
| 140 | tls_notify_app_enqueue (tls_ctx_t * ctx, stream_session_t * app_session) |
| 141 | { |
| 142 | application_t *app; |
| 143 | app = application_get_if_valid (app_session->app_index); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 144 | if (PREDICT_TRUE (app != 0)) |
| 145 | tls_add_app_q_evt (app, app_session); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | int |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 149 | tls_notify_app_accept (tls_ctx_t * ctx) |
| 150 | { |
| 151 | stream_session_t *app_listener, *app_session; |
| 152 | segment_manager_t *sm; |
| 153 | application_t *app; |
| 154 | tls_ctx_t *lctx; |
| 155 | int rv; |
| 156 | |
| 157 | app = application_get (ctx->parent_app_index); |
| 158 | lctx = tls_listener_ctx_get (ctx->listener_ctx_index); |
| 159 | app_listener = listen_session_get_from_handle (lctx->app_session_handle); |
| 160 | sm = application_get_listen_segment_manager (app, app_listener); |
| 161 | |
| 162 | app_session = session_alloc (vlib_get_thread_index ()); |
| 163 | app_session->app_index = ctx->parent_app_index; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 164 | app_session->connection_index = ctx->tls_ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 165 | app_session->session_type = app_listener->session_type; |
| 166 | app_session->listener_index = app_listener->session_index; |
| 167 | if ((rv = session_alloc_fifos (sm, app_session))) |
| 168 | { |
| 169 | TLS_DBG (1, "failed to allocate fifos"); |
| 170 | return rv; |
| 171 | } |
| 172 | ctx->c_s_index = app_session->session_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 173 | ctx->app_session_handle = session_handle (app_session); |
| 174 | return app->cb_fns.session_accept_callback (app_session); |
| 175 | } |
| 176 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 177 | int |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 178 | tls_notify_app_connected (tls_ctx_t * ctx, u8 is_failed) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 179 | { |
| 180 | int (*cb_fn) (u32, u32, stream_session_t *, u8); |
| 181 | stream_session_t *app_session; |
| 182 | segment_manager_t *sm; |
| 183 | application_t *app; |
| 184 | |
| 185 | app = application_get (ctx->parent_app_index); |
| 186 | cb_fn = app->cb_fns.session_connected_callback; |
| 187 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 188 | if (is_failed) |
| 189 | goto failed; |
| 190 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 191 | sm = application_get_connect_segment_manager (app); |
| 192 | app_session = session_alloc (vlib_get_thread_index ()); |
| 193 | app_session->app_index = ctx->parent_app_index; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 194 | app_session->connection_index = ctx->tls_ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 195 | app_session->session_type = |
| 196 | session_type_from_proto_and_ip (TRANSPORT_PROTO_TLS, ctx->tcp_is_ip4); |
| 197 | if (session_alloc_fifos (sm, app_session)) |
| 198 | goto failed; |
| 199 | |
| 200 | ctx->app_session_handle = session_handle (app_session); |
| 201 | ctx->c_s_index = app_session->session_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 202 | app_session->session_state = SESSION_STATE_READY; |
| 203 | if (cb_fn (ctx->parent_app_index, ctx->parent_app_api_context, |
| 204 | app_session, 0 /* not failed */ )) |
| 205 | { |
| 206 | TLS_DBG (1, "failed to notify app"); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 207 | tls_disconnect (ctx->tls_ctx_handle, vlib_get_thread_index ()); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return 0; |
| 211 | |
| 212 | failed: |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 213 | tls_disconnect (ctx->tls_ctx_handle, vlib_get_thread_index ()); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 214 | return cb_fn (ctx->parent_app_index, ctx->parent_app_api_context, 0, |
| 215 | 1 /* failed */ ); |
| 216 | } |
| 217 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 218 | static inline void |
| 219 | tls_ctx_parse_handle (u32 ctx_handle, u32 * ctx_index, u32 * engine_type) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 220 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 221 | *ctx_index = ctx_handle & TLS_IDX_MASK; |
| 222 | *engine_type = ctx_handle >> TLS_ENGINE_TYPE_SHIFT; |
| 223 | } |
| 224 | |
| 225 | static inline tls_engine_type_t |
| 226 | tls_get_engine_type (tls_engine_type_t preferred) |
| 227 | { |
| 228 | if (!tls_vfts[preferred].ctx_alloc) |
| 229 | return tls_get_available_engine (); |
| 230 | return preferred; |
| 231 | } |
| 232 | |
| 233 | static inline u32 |
| 234 | tls_ctx_alloc (tls_engine_type_t engine_type) |
| 235 | { |
| 236 | u32 ctx_index; |
| 237 | ctx_index = tls_vfts[engine_type].ctx_alloc (); |
| 238 | return (((u32) engine_type << TLS_ENGINE_TYPE_SHIFT) | ctx_index); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static inline void |
| 242 | tls_ctx_free (tls_ctx_t * ctx) |
| 243 | { |
| 244 | vec_free (ctx->srv_hostname); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 245 | tls_vfts[ctx->tls_ctx_engine].ctx_free (ctx); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static inline tls_ctx_t * |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 249 | tls_ctx_get (u32 ctx_handle) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 250 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 251 | u32 ctx_index, engine_type; |
| 252 | tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); |
| 253 | return tls_vfts[engine_type].ctx_get (ctx_index); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static inline tls_ctx_t * |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 257 | tls_ctx_get_w_thread (u32 ctx_handle, u8 thread_index) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 258 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 259 | u32 ctx_index, engine_type; |
| 260 | tls_ctx_parse_handle (ctx_handle, &ctx_index, &engine_type); |
| 261 | return tls_vfts[engine_type].ctx_get_w_thread (ctx_index, thread_index); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static inline int |
| 265 | tls_ctx_init_server (tls_ctx_t * ctx) |
| 266 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 267 | return tls_vfts[ctx->tls_ctx_engine].ctx_init_server (ctx); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static inline int |
| 271 | tls_ctx_init_client (tls_ctx_t * ctx) |
| 272 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 273 | return tls_vfts[ctx->tls_ctx_engine].ctx_init_client (ctx); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static inline int |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 277 | tls_ctx_write (tls_ctx_t * ctx, stream_session_t * app_session) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 278 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 279 | return tls_vfts[ctx->tls_ctx_engine].ctx_write (ctx, app_session); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static inline int |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 283 | tls_ctx_read (tls_ctx_t * ctx, stream_session_t * tls_session) |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 284 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 285 | return tls_vfts[ctx->tls_ctx_engine].ctx_read (ctx, tls_session); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static inline u8 |
| 289 | tls_ctx_handshake_is_over (tls_ctx_t * ctx) |
| 290 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 291 | return tls_vfts[ctx->tls_ctx_engine].ctx_handshake_is_over (ctx); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void |
| 295 | tls_session_reset_callback (stream_session_t * s) |
| 296 | { |
| 297 | clib_warning ("called..."); |
| 298 | } |
| 299 | |
| 300 | int |
| 301 | tls_add_segment_callback (u32 client_index, const ssvm_private_t * fs) |
| 302 | { |
| 303 | /* No-op for builtin */ |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | int |
| 308 | tls_del_segment_callback (u32 client_index, const ssvm_private_t * fs) |
| 309 | { |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | void |
| 314 | tls_session_disconnect_callback (stream_session_t * tls_session) |
| 315 | { |
| 316 | stream_session_t *app_session; |
| 317 | tls_ctx_t *ctx; |
| 318 | application_t *app; |
| 319 | |
| 320 | ctx = tls_ctx_get (tls_session->opaque); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 321 | if (!tls_ctx_handshake_is_over (ctx)) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 322 | { |
| 323 | stream_session_disconnect (tls_session); |
| 324 | return; |
| 325 | } |
| 326 | ctx->is_passive_close = 1; |
| 327 | app = application_get (ctx->parent_app_index); |
| 328 | app_session = session_get_from_handle (ctx->app_session_handle); |
| 329 | app->cb_fns.session_disconnect_callback (app_session); |
| 330 | } |
| 331 | |
| 332 | int |
| 333 | tls_session_accept_callback (stream_session_t * tls_session) |
| 334 | { |
| 335 | stream_session_t *tls_listener; |
| 336 | tls_ctx_t *lctx, *ctx; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 337 | u32 ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 338 | |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 339 | tls_listener = listen_session_get (tls_session->listener_index); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 340 | lctx = tls_listener_ctx_get (tls_listener->opaque); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 341 | |
| 342 | ctx_handle = tls_ctx_alloc (lctx->tls_ctx_engine); |
| 343 | ctx = tls_ctx_get (ctx_handle); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 344 | memcpy (ctx, lctx, sizeof (*lctx)); |
| 345 | ctx->c_thread_index = vlib_get_thread_index (); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 346 | ctx->tls_ctx_handle = ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 347 | tls_session->session_state = SESSION_STATE_READY; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 348 | tls_session->opaque = ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 349 | ctx->tls_session_handle = session_handle (tls_session); |
| 350 | ctx->listener_ctx_index = tls_listener->opaque; |
| 351 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 352 | TLS_DBG (1, "Accept on listener %u new connection [%u]%x", |
| 353 | tls_listener->opaque, vlib_get_thread_index (), ctx_handle); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 354 | |
| 355 | return tls_ctx_init_server (ctx); |
| 356 | } |
| 357 | |
| 358 | int |
| 359 | tls_app_tx_callback (stream_session_t * app_session) |
| 360 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 361 | tls_ctx_t *ctx; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 362 | if (PREDICT_FALSE (app_session->session_state == SESSION_STATE_CLOSED)) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 363 | return 0; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 364 | ctx = tls_ctx_get (app_session->connection_index); |
| 365 | tls_ctx_write (ctx, app_session); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | int |
| 370 | tls_app_rx_callback (stream_session_t * tls_session) |
| 371 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 372 | tls_ctx_t *ctx; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 373 | |
| 374 | ctx = tls_ctx_get (tls_session->opaque); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 375 | tls_ctx_read (ctx, tls_session); |
| 376 | return 0; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | int |
| 380 | tls_session_connected_callback (u32 tls_app_index, u32 ho_ctx_index, |
| 381 | stream_session_t * tls_session, u8 is_fail) |
| 382 | { |
| 383 | int (*cb_fn) (u32, u32, stream_session_t *, u8); |
| 384 | application_t *app; |
| 385 | tls_ctx_t *ho_ctx, *ctx; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 386 | u32 ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 387 | |
| 388 | ho_ctx = tls_ctx_half_open_get (ho_ctx_index); |
| 389 | app = application_get (ho_ctx->parent_app_index); |
| 390 | cb_fn = app->cb_fns.session_connected_callback; |
| 391 | |
| 392 | if (is_fail) |
Florin Coras | dcde927 | 2018-03-02 09:23:42 -0800 | [diff] [blame] | 393 | { |
| 394 | tls_ctx_half_open_reader_unlock (); |
| 395 | tls_ctx_half_open_free (ho_ctx_index); |
| 396 | return cb_fn (ho_ctx->parent_app_index, ho_ctx->c_s_index, 0, |
| 397 | 1 /* failed */ ); |
| 398 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 399 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 400 | ctx_handle = tls_ctx_alloc (ho_ctx->tls_ctx_engine); |
| 401 | ctx = tls_ctx_get (ctx_handle); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 402 | clib_memcpy (ctx, ho_ctx, sizeof (*ctx)); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 403 | tls_ctx_half_open_reader_unlock (); |
| 404 | tls_ctx_half_open_free (ho_ctx_index); |
| 405 | |
Florin Coras | dcde927 | 2018-03-02 09:23:42 -0800 | [diff] [blame] | 406 | ctx->c_thread_index = vlib_get_thread_index (); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 407 | ctx->tls_ctx_handle = ctx_handle; |
Florin Coras | dcde927 | 2018-03-02 09:23:42 -0800 | [diff] [blame] | 408 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 409 | TLS_DBG (1, "TCP connect for %u returned %u. New connection [%u]%x", |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 410 | ho_ctx_index, is_fail, vlib_get_thread_index (), |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 411 | (ctx) ? ctx_handle : ~0); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 412 | |
| 413 | ctx->tls_session_handle = session_handle (tls_session); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 414 | tls_session->opaque = ctx_handle; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 415 | tls_session->session_state = SESSION_STATE_READY; |
| 416 | |
| 417 | return tls_ctx_init_client (ctx); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /* *INDENT-OFF* */ |
| 421 | static session_cb_vft_t tls_app_cb_vft = { |
| 422 | .session_accept_callback = tls_session_accept_callback, |
| 423 | .session_disconnect_callback = tls_session_disconnect_callback, |
| 424 | .session_connected_callback = tls_session_connected_callback, |
| 425 | .session_reset_callback = tls_session_reset_callback, |
| 426 | .add_segment_callback = tls_add_segment_callback, |
| 427 | .del_segment_callback = tls_del_segment_callback, |
| 428 | .builtin_app_rx_callback = tls_app_rx_callback, |
| 429 | .builtin_app_tx_callback = tls_app_tx_callback, |
| 430 | }; |
| 431 | /* *INDENT-ON* */ |
| 432 | |
| 433 | int |
| 434 | tls_connect (transport_endpoint_t * tep) |
| 435 | { |
| 436 | session_endpoint_extended_t *sep; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 437 | tls_engine_type_t engine_type; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 438 | session_endpoint_t tls_sep; |
| 439 | tls_main_t *tm = &tls_main; |
| 440 | application_t *app; |
| 441 | tls_ctx_t *ctx; |
| 442 | u32 ctx_index; |
| 443 | int rv; |
| 444 | |
| 445 | sep = (session_endpoint_extended_t *) tep; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 446 | app = application_get (sep->app_index); |
| 447 | engine_type = tls_get_engine_type (app->tls_engine); |
| 448 | if (engine_type == TLS_ENGINE_NONE) |
| 449 | { |
| 450 | clib_warning ("No tls engine_type available"); |
| 451 | return -1; |
| 452 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 453 | |
| 454 | ctx_index = tls_ctx_half_open_alloc (); |
| 455 | ctx = tls_ctx_half_open_get (ctx_index); |
| 456 | ctx->parent_app_index = sep->app_index; |
| 457 | ctx->parent_app_api_context = sep->opaque; |
| 458 | ctx->tcp_is_ip4 = sep->is_ip4; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 459 | if (sep->hostname) |
| 460 | { |
| 461 | ctx->srv_hostname = format (0, "%v", sep->hostname); |
| 462 | vec_terminate_c_string (ctx->srv_hostname); |
| 463 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 464 | tls_ctx_half_open_reader_unlock (); |
| 465 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 466 | application_alloc_connects_segment_manager (app); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 467 | ctx->tls_ctx_engine = engine_type; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 468 | |
| 469 | clib_memcpy (&tls_sep, sep, sizeof (tls_sep)); |
| 470 | tls_sep.transport_proto = TRANSPORT_PROTO_TCP; |
| 471 | if ((rv = application_connect (tm->app_index, ctx_index, &tls_sep))) |
| 472 | return rv; |
| 473 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 474 | TLS_DBG (1, "New connect request %u engine %d", ctx_index, engine_type); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | void |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 479 | tls_disconnect (u32 ctx_handle, u32 thread_index) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 480 | { |
| 481 | stream_session_t *tls_session, *app_session; |
| 482 | tls_ctx_t *ctx; |
| 483 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 484 | TLS_DBG (1, "Disconnecting %x", ctx_handle); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 485 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 486 | ctx = tls_ctx_get (ctx_handle); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 487 | tls_session = session_get_from_handle (ctx->tls_session_handle); |
| 488 | stream_session_disconnect (tls_session); |
| 489 | |
| 490 | app_session = session_get_from_handle_if_valid (ctx->app_session_handle); |
| 491 | if (app_session) |
| 492 | { |
| 493 | segment_manager_dealloc_fifos (app_session->svm_segment_index, |
| 494 | app_session->server_rx_fifo, |
| 495 | app_session->server_tx_fifo); |
| 496 | session_free (app_session); |
| 497 | } |
| 498 | tls_ctx_free (ctx); |
| 499 | } |
| 500 | |
| 501 | u32 |
| 502 | tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep) |
| 503 | { |
| 504 | tls_main_t *tm = &tls_main; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 505 | application_t *tls_app, *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 506 | session_handle_t tls_handle; |
| 507 | session_endpoint_extended_t *sep; |
| 508 | stream_session_t *tls_listener; |
| 509 | tls_ctx_t *lctx; |
| 510 | u32 lctx_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 511 | stream_session_t *app_listener; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 512 | tls_engine_type_t engine_type; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 513 | |
| 514 | sep = (session_endpoint_extended_t *) tep; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 515 | app = application_get (sep->app_index); |
| 516 | engine_type = tls_get_engine_type (app->tls_engine); |
| 517 | if (engine_type == TLS_ENGINE_NONE) |
| 518 | { |
| 519 | clib_warning ("No tls engine_type available"); |
| 520 | return -1; |
| 521 | } |
| 522 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 523 | lctx_index = tls_listener_ctx_alloc (); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 524 | |
| 525 | tls_app = application_get (tm->app_index); |
| 526 | sep->transport_proto = TRANSPORT_PROTO_TCP; |
| 527 | if (application_start_listen (tls_app, (session_endpoint_t *) sep, |
| 528 | &tls_handle)) |
| 529 | return ~0; |
| 530 | |
| 531 | tls_listener = listen_session_get_from_handle (tls_handle); |
| 532 | tls_listener->opaque = lctx_index; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 533 | |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 534 | app_listener = listen_session_get (app_listener_index); |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 535 | |
| 536 | lctx = tls_listener_ctx_get (lctx_index); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 537 | lctx->parent_app_index = sep->app_index; |
| 538 | lctx->tls_session_handle = tls_handle; |
| 539 | lctx->app_session_handle = listen_session_get_handle (app_listener); |
| 540 | lctx->tcp_is_ip4 = sep->is_ip4; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 541 | lctx->tls_ctx_engine = engine_type; |
| 542 | |
| 543 | TLS_DBG (1, "Started listening %d, engine type %d", lctx_index, |
| 544 | engine_type); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 545 | return lctx_index; |
| 546 | } |
| 547 | |
| 548 | u32 |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 549 | tls_stop_listen (u32 lctx_index) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 550 | { |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 551 | tls_main_t *tm = &tls_main; |
| 552 | application_t *tls_app; |
| 553 | tls_ctx_t *lctx; |
| 554 | lctx = tls_listener_ctx_get (lctx_index); |
| 555 | tls_app = application_get (tm->app_index); |
| 556 | application_stop_listen (tls_app, lctx->tls_session_handle); |
| 557 | tls_listener_ctx_free (lctx); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | transport_connection_t * |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 562 | tls_connection_get (u32 ctx_index, u32 thread_index) |
| 563 | { |
| 564 | tls_ctx_t *ctx; |
| 565 | ctx = tls_ctx_get_w_thread (ctx_index, thread_index); |
| 566 | return &ctx->connection; |
| 567 | } |
| 568 | |
| 569 | transport_connection_t * |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 570 | tls_listener_get (u32 listener_index) |
| 571 | { |
| 572 | tls_ctx_t *ctx; |
| 573 | ctx = tls_listener_ctx_get (listener_index); |
| 574 | return &ctx->connection; |
| 575 | } |
| 576 | |
| 577 | u8 * |
| 578 | format_tls_ctx (u8 * s, va_list * args) |
| 579 | { |
| 580 | tls_ctx_t *ctx = va_arg (*args, tls_ctx_t *); |
| 581 | u32 thread_index = va_arg (*args, u32); |
| 582 | u32 child_si, child_ti; |
| 583 | |
| 584 | session_parse_handle (ctx->tls_session_handle, &child_si, &child_ti); |
| 585 | if (thread_index != child_ti) |
| 586 | clib_warning ("app and tls sessions are on different threads!"); |
| 587 | |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 588 | s = format (s, "[#%d][TLS] app %u child %u", child_ti, |
| 589 | ctx->parent_app_index, child_si); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 590 | return s; |
| 591 | } |
| 592 | |
| 593 | u8 * |
| 594 | format_tls_connection (u8 * s, va_list * args) |
| 595 | { |
| 596 | u32 ctx_index = va_arg (*args, u32); |
| 597 | u32 thread_index = va_arg (*args, u32); |
| 598 | u32 verbose = va_arg (*args, u32); |
| 599 | tls_ctx_t *ctx; |
| 600 | |
| 601 | ctx = tls_ctx_get_w_thread (ctx_index, thread_index); |
| 602 | if (!ctx) |
| 603 | return s; |
| 604 | |
| 605 | s = format (s, "%-50U", format_tls_ctx, ctx, thread_index); |
| 606 | if (verbose) |
| 607 | { |
| 608 | s = format (s, "%-15s", "state"); |
| 609 | if (verbose > 1) |
| 610 | s = format (s, "\n"); |
| 611 | } |
| 612 | return s; |
| 613 | } |
| 614 | |
| 615 | u8 * |
| 616 | format_tls_listener (u8 * s, va_list * args) |
| 617 | { |
| 618 | u32 tc_index = va_arg (*args, u32); |
| 619 | tls_ctx_t *ctx = tls_listener_ctx_get (tc_index); |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 620 | u32 listener_index, thread_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 621 | |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 622 | listen_session_parse_handle (ctx->tls_session_handle, &listener_index, |
| 623 | &thread_index); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 624 | return format (s, "[TLS] listener app %u child %u", ctx->parent_app_index, |
| 625 | listener_index); |
| 626 | } |
| 627 | |
| 628 | u8 * |
| 629 | format_tls_half_open (u8 * s, va_list * args) |
| 630 | { |
| 631 | u32 tc_index = va_arg (*args, u32); |
| 632 | tls_ctx_t *ctx = tls_ctx_half_open_get (tc_index); |
| 633 | s = format (s, "[TLS] half-open app %u", ctx->parent_app_index); |
| 634 | tls_ctx_half_open_reader_unlock (); |
| 635 | return s; |
| 636 | } |
| 637 | |
| 638 | /* *INDENT-OFF* */ |
| 639 | const static transport_proto_vft_t tls_proto = { |
| 640 | .open = tls_connect, |
| 641 | .close = tls_disconnect, |
| 642 | .bind = tls_start_listen, |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 643 | .get_connection = tls_connection_get, |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 644 | .get_listener = tls_listener_get, |
| 645 | .unbind = tls_stop_listen, |
| 646 | .tx_type = TRANSPORT_TX_INTERNAL, |
| 647 | .service_type = TRANSPORT_SERVICE_APP, |
| 648 | .format_connection = format_tls_connection, |
| 649 | .format_half_open = format_tls_half_open, |
| 650 | .format_listener = format_tls_listener, |
| 651 | }; |
| 652 | /* *INDENT-ON* */ |
| 653 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 654 | void |
| 655 | tls_register_engine (const tls_engine_vft_t * vft, tls_engine_type_t type) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 656 | { |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 657 | vec_validate (tls_vfts, type); |
| 658 | tls_vfts[type] = *vft; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Dave Barach | cc5677b | 2018-03-28 19:08:45 -0400 | [diff] [blame] | 661 | static clib_error_t * |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 662 | tls_init (vlib_main_t * vm) |
| 663 | { |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 664 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 665 | vnet_app_attach_args_t _a, *a = &_a; |
| 666 | u64 options[APP_OPTIONS_N_OPTIONS]; |
| 667 | u32 segment_size = 512 << 20; |
| 668 | tls_main_t *tm = &tls_main; |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 669 | u32 fifo_size = 64 << 10; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 670 | u32 num_threads; |
| 671 | |
| 672 | num_threads = 1 /* main thread */ + vtm->n_threads; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 673 | |
| 674 | memset (a, 0, sizeof (*a)); |
| 675 | memset (options, 0, sizeof (options)); |
| 676 | |
| 677 | a->session_cb_vft = &tls_app_cb_vft; |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 678 | a->api_client_index = APP_INVALID_INDEX; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 679 | a->options = options; |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 680 | a->name = format (0, "tls"); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 681 | a->options[APP_OPTIONS_SEGMENT_SIZE] = segment_size; |
| 682 | a->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size; |
| 683 | a->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size; |
| 684 | a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; |
| 685 | a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; |
| 686 | |
| 687 | if (vnet_application_attach (a)) |
| 688 | { |
| 689 | clib_warning ("failed to attach tls app"); |
| 690 | return clib_error_return (0, "failed to attach tls app"); |
| 691 | } |
| 692 | |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 693 | if (!tm->ca_cert_path) |
| 694 | tm->ca_cert_path = TLS_CA_CERT_PATH; |
| 695 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 696 | tm->app_index = a->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 697 | clib_rwlock_init (&tm->half_open_rwlock); |
| 698 | |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 699 | vec_validate (tm->rx_bufs, num_threads - 1); |
| 700 | vec_validate (tm->tx_bufs, num_threads - 1); |
| 701 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 702 | transport_register_protocol (TRANSPORT_PROTO_TLS, &tls_proto, |
| 703 | FIB_PROTOCOL_IP4, ~0); |
| 704 | transport_register_protocol (TRANSPORT_PROTO_TLS, &tls_proto, |
| 705 | FIB_PROTOCOL_IP6, ~0); |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 706 | vec_free (a->name); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | VLIB_INIT_FUNCTION (tls_init); |
| 711 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 712 | static clib_error_t * |
| 713 | tls_config_fn (vlib_main_t * vm, unformat_input_t * input) |
| 714 | { |
| 715 | tls_main_t *tm = &tls_main; |
| 716 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 717 | { |
| 718 | if (unformat (input, "use-test-cert-in-ca")) |
| 719 | tm->use_test_cert_in_ca = 1; |
| 720 | else if (unformat (input, "ca-cert-path %s", &tm->ca_cert_path)) |
| 721 | ; |
| 722 | else |
| 723 | return clib_error_return (0, "unknown input `%U'", |
| 724 | format_unformat_error, input); |
| 725 | } |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | VLIB_EARLY_CONFIG_FUNCTION (tls_config_fn, "tls"); |
Florin Coras | d77eee6 | 2018-03-07 08:49:27 -0800 | [diff] [blame] | 730 | |
| 731 | tls_main_t * |
| 732 | vnet_tls_get_main (void) |
| 733 | { |
| 734 | return &tls_main; |
| 735 | } |
| 736 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 737 | /* |
| 738 | * fd.io coding-style-patch-verification: ON |
| 739 | * |
| 740 | * Local Variables: |
| 741 | * eval: (c-set-style "gnu") |
| 742 | * End: |
| 743 | */ |