|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
9 #define MAX_QUEUE 12000
10 #define PTLS_MAX_PLAINTEXT_RECORD_SIZE 16384
13 #ifdef PTLS_OPENSSL_HAVE_X25519
16 #ifdef PTLS_OPENSSL_HAVE_SECP256R1
17 &ptls_openssl_secp256r1,
19 #ifdef PTLS_OPENSSL_HAVE_SECP384R1
20 &ptls_openssl_secp384r1,
22 #ifdef PTLS_OPENSSL_HAVE_SECP521R1
23 &ptls_openssl_secp521r1
39 (*ctx)->ctx.c_thread_index = thread_id;
42 (*ctx)->ptls_ctx_idx =
ctx - pm->
ctx_pool[thread_id];
96 return ptls_handshake_is_complete (ptls_ctx->
tls);
103 u32 enq_max, enq_now;
117 enq_now =
clib_min (enq_now, buf_left);
128 ptls_context_t *ptls_ctx;
133 if (!ckpair || !ckpair->
cert || !ckpair->
key)
135 TLS_DBG (1,
"tls cert and/or key not configured %d",
136 lctx->parent_app_wrk_index);
142 ptls_ctx =
malloc (
sizeof (ptls_context_t));
145 memset (ptls_ctx, 0,
sizeof (ptls_context_t));
146 ptls_ctx->update_open_count = NULL;
156 ptls_ctx->random_bytes = ptls_openssl_random_bytes;
158 ptls_ctx->get_time = &ptls_get_time;
160 lctx->tls_ssl_ctx = ptls_lctx_idx;
171 ptls_lctx_index = lctx->tls_ssl_ctx;
183 ctx->no_app_session = 1;
204 ptls_free (ptls_ctx->
tls);
225 u8 * input,
int input_len)
227 ptls_t *tls = ptls_ctx->
tls;
229 int rv = PTLS_ERROR_IN_PROGRESS;
237 ptls_buffer_init (&
buf,
"", 0);
238 size_t consumed = input_len -
off;
239 rv = ptls_handshake (tls, &
buf, input +
off, &consumed, NULL);
242 if ((
rv == 0 ||
rv == PTLS_ERROR_IN_PROGRESS) &&
buf.off != 0)
247 ptls_buffer_dispose (&
buf);
249 while (
rv == PTLS_ERROR_IN_PROGRESS && input_len !=
off);
251 while (
rv == PTLS_ERROR_IN_PROGRESS);
260 int from_tls_len = 0,
off, crypto_len, ret;
261 u32 deq_max, deq_now;
267 tls_rx_fifo = tls_session->
rx_fifo;
286 ret = ptls_is_server (ptls_ctx->
tls) ?
296 app_rx_fifo = app_session->
rx_fifo;
301 ptls_buffer_init (
buf,
"", 0);
323 (
size_t *) & deq_now);
340 size_t consumed = crypto_len -
off;
342 ptls_receive (ptls_ctx->
tls,
buf,
347 while (ret == 0 &&
off < crypto_len);
368 ptls_buffer_dispose (
buf);
383 int total_record_overhead,
int is_no_copy)
386 int total_length = content_len + total_record_overhead;
398 to_dst_len =
buf->off;
420 u32 deq_max, deq_now;
421 u32 enq_max, enq_now;
422 int from_app_len = 0, to_tls_len = 0, is_nocopy = 0;
426 int record_overhead = ptls_get_record_overhead (ptls_ctx->
tls);
427 int num_records, total_overhead;
430 tls_tx_fifo = tls_session->
tx_fifo;
431 app_tx_fifo = app_session->
tx_fifo;
443 app_session->
flags |= SESSION_F_CUSTOM_TX;
450 app_session->
flags |= SESSION_F_CUSTOM_TX;
470 if (enq_max <= record_overhead)
472 app_session->
flags |= SESSION_F_CUSTOM_TX;
479 if (enq_now > record_overhead)
482 from_app_len =
clib_min (deq_now, enq_now);
485 total_overhead = num_records * record_overhead;
486 if (from_app_len + total_overhead > enq_now)
487 from_app_len = enq_now - total_overhead;
491 from_app_len =
clib_min (deq_now, enq_max);
494 total_overhead = num_records * record_overhead;
495 if (from_app_len + total_overhead > enq_max)
496 from_app_len = enq_max - total_overhead;
501 from_app_len, total_overhead, is_nocopy);
515 app_session->
flags |= SESSION_F_CUSTOM_TX;
527 u32 ptls_lctx_idx =
ctx->tls_ssl_ctx;
532 if (ptls_ctx->
tls == NULL)
534 TLS_DBG (1,
"Failed to initialize ptls_ssl structure");
551 ptls_handshake_properties_t hsprop = { { { { NULL } } } };
554 ptls_buffer_t hs_buf;
556 ptls_ctx->
tls = ptls_new (client_ptls_ctx, 0);
557 if (ptls_ctx->
tls == NULL)
559 TLS_DBG (1,
"Failed to initialize ptls_ssl structure");
567 ptls_buffer_init (&hs_buf,
"", 0);
568 if (ptls_handshake (ptls_ctx->
tls, &hs_buf, NULL, NULL, &hsprop) !=
569 PTLS_ERROR_IN_PROGRESS)
571 TLS_DBG (1,
"Failed to initialize tls connection");
576 ptls_buffer_dispose (&hs_buf);
593 memset (*client_ptls_ctx, 0,
sizeof (ptls_context_t));
595 (*client_ptls_ctx)->update_open_count = NULL;
597 (*client_ptls_ctx)->random_bytes = ptls_openssl_random_bytes;
599 (*client_ptls_ctx)->get_time = &ptls_get_time;
649 .version = VPP_BUILD_VER,
650 .description =
"Transport Layer Security (TLS) Engine, Picotls Based",
int picotls_init_client_ptls_ctx(ptls_context_t **client_ptls_ctx)
static int picotls_try_handshake_write(picotls_ctx_t *ptls_ctx, session_t *tls_session, ptls_buffer_t *buf)
int session_dequeue_notify(session_t *s)
static void picotls_listen_ctx_free(picotls_listen_ctx_t *lctx)
int tls_notify_app_connected(tls_ctx_t *ctx, session_error_t err)
ptls_context_t * ptls_ctx
static int picotls_ctx_init_server(tls_ctx_t *ctx)
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define TLS_WRITE_OFFSET(x)
static int picotls_app_close(tls_ctx_t *ctx)
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
int load_bio_certificate_chain(ptls_context_t *ctx, const char *cert_data)
#define TLS_RX_LEFT_LEN(x)
u32 svm_fifo_max_read_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be read.
int tls_notify_app_accept(tls_ctx_t *ctx)
void tls_notify_app_enqueue(tls_ctx_t *ctx, session_t *app_session)
#define SESSION_INVALID_INDEX
#define TLS_READ_IS_LEFT(x)
ptls_context_t * client_ptls_ctx
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that it is closed.
static u8 picotls_handshake_is_over(tls_ctx_t *ctx)
int load_bio_private_key(ptls_context_t *ctx, const char *pk_data)
static int picotls_content_process(picotls_ctx_t *ptls_ctx, svm_fifo_t *src_fifo, svm_fifo_t *dst_fifo, int content_len, int total_record_overhead, int is_no_copy)
void session_free(session_t *s)
#define pool_put_index(p, i)
Free pool element with given index.
picotls_main_t picotls_main
tls_ctx_t * picotls_ctx_get_w_thread(u32 ctx_index, u8 thread_index)
ptls_cipher_suite_t * ptls_vpp_crypto_cipher_suites[]
void tls_disconnect_transport(tls_ctx_t *ctx)
ptls_buffer_t read_buffer
struct _svm_fifo svm_fifo_t
#define TLS_DBG(_lvl, _fmt, _args...)
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
int tls_add_vpp_q_builtin_rx_evt(session_t *s)
tls_ctx_t * picotls_ctx_get(u32 ctx_index)
int svm_fifo_dequeue(svm_fifo_t *f, u32 len, u8 *dst)
Dequeue data from fifo.
void svm_fifo_enqueue_nocopy(svm_fifo_t *f, u32 len)
Advance tail.
clib_rwlock_t crypto_keys_rw_lock
static int picotls_transport_close(tls_ctx_t *ctx)
static_always_inline uword vlib_get_thread_index(void)
#define TLS_RX_IS_LEFT(x)
picotls_listen_ctx_t * picotls_lctx_get(u32 lctx_index)
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
u32 svm_fifo_max_write_chunk(svm_fifo_t *f)
Max contiguous chunk of data that can be written.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static session_t * session_get_from_handle(session_handle_t handle)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
static u32 picotls_ctx_alloc(void)
static u32 picotls_listen_ctx_alloc(void)
static session_t * session_get(u32 si, u32 thread_index)
static void clib_rwlock_init(clib_rwlock_t *p)
static int picotls_ctx_init_client(tls_ctx_t *ctx)
static clib_error_t * tls_picotls_init(vlib_main_t *vm)
static int picotls_start_listen(tls_ctx_t *lctx)
static ptls_key_exchange_algorithm_t * default_key_exchange[]
static int picotls_ctx_write(tls_ctx_t *ctx, session_t *app_session, transport_send_params_t *sp)
#define vec_free(V)
Free vector's memory (no header).
static void picotls_handle_handshake_failure(tls_ctx_t *ctx)
static u8 * svm_fifo_tail(svm_fifo_t *f)
Fifo tail pointer getter.
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
#define TLS_READ_OFFSET(x)
#define VLIB_INIT_FUNCTION(x)
static int picotls_do_handshake(picotls_ctx_t *ptls_ctx, session_t *tls_session, u8 *input, int input_len)
#define SESSION_INVALID_HANDLE
int tls_add_vpp_q_tx_evt(session_t *s)
#define TLS_READ_LEFT_LEN(x)
#define TLS_WRITE_IS_LEFT(x)
picotls_ctx_t *** ctx_pool
ptls_buffer_t write_buffer
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
picotls_listen_ctx_t * lctx_pool
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
void * malloc(size_t size)
static u8 * svm_fifo_head(svm_fifo_t *f)
Fifo head pointer getter.
app_cert_key_pair_t * app_cert_key_pair_get_if_valid(u32 index)
static int picotls_stop_listen(tls_ctx_t *lctx)
const static tls_engine_vft_t picotls_engine
static int picotls_ctx_read(tls_ctx_t *ctx, session_t *tls_session)
void tls_register_engine(const tls_engine_vft_t *vft, crypto_engine_type_t type)
static vlib_thread_main_t * vlib_get_thread_main()
static u32 svm_fifo_max_dequeue_cons(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for consumer.
volatile u8 session_state
State in session layer state machine.
static void picotls_ctx_free(tls_ctx_t *ctx)
static void * clib_mem_alloc(uword size)
static void picotls_confirm_app_close(tls_ctx_t *ctx)
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
Fifo max bytes to dequeue.
#define PTLS_MAX_PLAINTEXT_RECORD_SIZE