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