summaryrefslogtreecommitdiffstats
path: root/src/plugins/tlspicotls/tls_picotls.c
diff options
context:
space:
mode:
authorSimon Zhang <yuwei1.zhang@intel.com>2020-01-13 00:59:08 +0800
committerFlorin Coras <florin.coras@gmail.com>2020-02-11 16:11:13 +0000
commit619179cfcdb087acb0864d273c4fbd3b7396974c (patch)
tree7e2c0741a025741a4d4d3191d7ddb16c0f97bc5c /src/plugins/tlspicotls/tls_picotls.c
parent6fe8998fefdc900af714a23d4152ffef9edbd3b4 (diff)
tls: refactor picotls ctx_read process to improve CPS
Type: refactor Signed-off-by: Simon Zhang <yuwei1.zhang@intel.com> Change-Id: I2bb675b4df3c4151f4b0791efcfe05b1d0f87a33 Signed-off-by: Simon Zhang <yuwei1.zhang@intel.com>
Diffstat (limited to 'src/plugins/tlspicotls/tls_picotls.c')
-rw-r--r--src/plugins/tlspicotls/tls_picotls.c107
1 files changed, 49 insertions, 58 deletions
diff --git a/src/plugins/tlspicotls/tls_picotls.c b/src/plugins/tlspicotls/tls_picotls.c
index d475e9cf71d..6e18551f6d5 100644
--- a/src/plugins/tlspicotls/tls_picotls.c
+++ b/src/plugins/tlspicotls/tls_picotls.c
@@ -235,6 +235,7 @@ picotls_do_handshake (picotls_ctx_t * ptls_ctx, session_t * tls_session,
size_t consumed = input_len - off;
rv = ptls_handshake (tls, &buf, input + off, &consumed, NULL);
off += consumed;
+ ptls_ctx->rx_offset += consumed;
if ((rv == 0 || rv == PTLS_ERROR_IN_PROGRESS) && buf.off != 0)
{
write = picotls_try_handshake_write (ptls_ctx, tls_session,
@@ -253,8 +254,7 @@ static inline int
picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
{
picotls_ctx_t *ptls_ctx = (picotls_ctx_t *) ctx;
- u8 *input;
- int to_read, from_tls_len = 0, to_app_len = 0, crypto_len, ret;
+ int from_tls_len = 0, to_app_len = 0, crypto_len, ret;
u32 deq_max, deq_now;
u32 enq_max, enq_now;
ptls_buffer_t _buf, *buf = &_buf;
@@ -266,14 +266,12 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
if (!picotls_handshake_is_over (ctx))
{
deq_max = svm_fifo_max_dequeue_cons (tls_rx_fifo);
- input = clib_mem_alloc (deq_max);
- memset (input, 0, deq_max);
-
deq_now = clib_min (deq_max, svm_fifo_max_read_chunk (tls_rx_fifo));
if (!deq_now)
goto done_hs;
- from_tls_len += svm_fifo_dequeue (tls_rx_fifo, deq_now, input);
+ from_tls_len +=
+ svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
if (from_tls_len <= 0)
{
tls_add_vpp_q_builtin_rx_evt (tls_session);
@@ -284,15 +282,17 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
deq_now = clib_min (svm_fifo_max_read_chunk (tls_rx_fifo),
deq_max - from_tls_len);
from_tls_len += svm_fifo_dequeue (tls_rx_fifo, deq_now,
- input + from_tls_len);
+ TLS_RX_LEN (ptls_ctx));
}
- picotls_do_handshake (ptls_ctx, tls_session, input, from_tls_len);
+ ptls_ctx->rx_len += from_tls_len;
+ picotls_do_handshake (ptls_ctx, tls_session, TLS_RX_OFFSET (ptls_ctx),
+ from_tls_len);
if (picotls_handshake_is_over (ctx))
tls_notify_app_accept (ctx);
done_hs:
- clib_mem_free (input);
- return 0;
+ if (!TLS_RX_IS_LEFT (ptls_ctx))
+ return 0;
}
app_session = session_get_from_handle (ctx->app_session_handle);
@@ -300,47 +300,34 @@ picotls_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
ptls_buffer_init (buf, "", 0);
- deq_max = svm_fifo_max_dequeue_cons (tls_rx_fifo);
-
- if (!deq_max || deq_max > MAX_QUEUE - ptls_ctx->rx_len)
+ if (!TLS_RX_IS_LEFT (ptls_ctx))
{
- goto app_fifo;
- }
+ deq_max = svm_fifo_max_dequeue_cons (tls_rx_fifo);
+ if (!deq_max)
+ goto app_fifo;
- deq_now = clib_min (deq_max, svm_fifo_max_read_chunk (tls_rx_fifo));
+ deq_now = clib_min (deq_max, svm_fifo_max_read_chunk (tls_rx_fifo));
- from_tls_len =
- svm_fifo_dequeue (tls_rx_fifo, deq_now,
- ptls_ctx->rx_content + ptls_ctx->rx_len);
- if (from_tls_len <= 0)
- {
- tls_add_vpp_q_builtin_rx_evt (tls_session);
- goto app_fifo;
- }
- if (from_tls_len < deq_max)
- {
- deq_now =
- clib_min (svm_fifo_max_read_chunk (tls_rx_fifo),
- deq_max - from_tls_len);
- from_tls_len +=
- svm_fifo_dequeue (tls_rx_fifo, deq_now,
- ptls_ctx->rx_content + ptls_ctx->rx_len +
- from_tls_len);
- }
- ptls_ctx->rx_len += from_tls_len;
+ from_tls_len =
+ svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
-app_fifo:
- if (ptls_ctx->rx_len <= 0 || ptls_ctx->rx_offset == ptls_ctx->rx_len)
- {
- if (ptls_ctx->rx_len != 0)
+ if (from_tls_len < deq_max)
{
- ptls_ctx->rx_len = 0;
- ptls_ctx->rx_offset = 0;
- tls_add_vpp_q_builtin_rx_evt (tls_session);
+ deq_now =
+ clib_min (svm_fifo_max_read_chunk (tls_rx_fifo),
+ deq_max - from_tls_len);
+ from_tls_len +=
+ svm_fifo_dequeue (tls_rx_fifo, deq_now, TLS_RX_LEN (ptls_ctx));
}
- return from_tls_len;
+
+ ptls_ctx->rx_len += from_tls_len;
+
+ if (from_tls_len < deq_max)
+ tls_add_vpp_q_builtin_rx_evt (tls_session);
}
+app_fifo:
+
enq_max = svm_fifo_max_enqueue_prod (app_rx_fifo);
if (!enq_max)
{
@@ -348,8 +335,7 @@ app_fifo:
goto final;
}
- crypto_len = clib_min (enq_max, ptls_ctx->rx_len - ptls_ctx->rx_offset);
- crypto_len = clib_min (crypto_len, from_tls_len);
+ crypto_len = clib_min (enq_max, TLS_RX_LEFT_LEN (ptls_ctx));
int off = 0;
do
@@ -357,18 +343,15 @@ app_fifo:
size_t consumed = crypto_len - off;
ret =
ptls_receive (ptls_ctx->tls, buf,
- ptls_ctx->rx_content + ptls_ctx->rx_offset + off,
- &consumed);
+ TLS_RX_OFFSET (ptls_ctx), &consumed);
off += consumed;
+ ptls_ctx->rx_offset += consumed;
}
while (ret == 0 && off < crypto_len);
if (ret == 0)
{
- ptls_ctx->rx_offset += crypto_len;
-
- to_read = clib_min (enq_max, buf->off);
- enq_now = clib_min (to_read, svm_fifo_max_write_chunk (app_rx_fifo));
+ enq_now = clib_min (buf->off, svm_fifo_max_write_chunk (app_rx_fifo));
to_app_len = svm_fifo_enqueue (app_rx_fifo, enq_now, buf->base);
if (to_app_len < buf->off)
{
@@ -380,15 +363,21 @@ app_fifo:
}
}
-final:
- ptls_buffer_dispose (buf);
- if (ctx->app_closed)
+ if (ptls_ctx->rx_len != 0 && !TLS_RX_IS_LEFT (ptls_ctx))
{
- picotls_confirm_app_close (ctx);
- return from_tls_len;
+ ptls_ctx->rx_len = 0;
+ ptls_ctx->rx_offset = 0;
}
- tls_notify_app_enqueue (ctx, app_session);
+final:
+ ptls_buffer_dispose (buf);
+
+ if (app_session->session_state >= SESSION_STATE_READY)
+ tls_notify_app_enqueue (ctx, app_session);
+
+ if (TLS_RX_IS_LEFT (ptls_ctx))
+ tls_add_vpp_q_builtin_rx_evt (tls_session);
+
return from_tls_len;
}
@@ -496,7 +485,9 @@ picotls_ctx_write (tls_ctx_t * ctx, session_t * app_session)
if (to_tls_len)
tls_add_vpp_q_tx_evt (tls_session);
- tls_add_vpp_q_builtin_tx_evt (app_session);
+
+ if (from_app_len < deq_max)
+ tls_add_vpp_q_builtin_tx_evt (app_session);
if (ctx->app_closed)
picotls_app_close (ctx);