diff options
author | Florin Coras <fcoras@cisco.com> | 2020-02-26 05:18:47 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2020-02-26 12:02:42 +0000 |
commit | 3017af9ab2bc83f4b909e3858e20fbf5259ec00a (patch) | |
tree | 12f31a1d649c381071ce2a60f32566c1d5680127 | |
parent | aab0604c47f9d6e3fadb894b3f081085833f62b3 (diff) |
tls: fix bulk bio read/write
Type: fix
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I1f981e909c45f1731ce4bdfa959b41d349e22ef1
-rw-r--r-- | src/plugins/tlsopenssl/tls_openssl.c | 76 |
1 files changed, 29 insertions, 47 deletions
diff --git a/src/plugins/tlsopenssl/tls_openssl.c b/src/plugins/tlsopenssl/tls_openssl.c index f897b64800b..f25ac9f580d 100644 --- a/src/plugins/tlsopenssl/tls_openssl.c +++ b/src/plugins/tlsopenssl/tls_openssl.c @@ -130,19 +130,15 @@ openssl_read_from_bio_into_fifo (svm_fifo_t * f, BIO * bio) if (read <= 0) return 0; - if (read == enq_now) + c = svm_fifo_tail_chunk (f); + while ((c = c->next) && read < enq_max) { - c = svm_fifo_tail_chunk (f); - while (read < enq_max) - { - c = c->next; - enq_now = clib_min (c->length, enq_max - read); - rv = BIO_read (bio, c->data, enq_now); - read += rv > 0 ? rv : 0; + enq_now = clib_min (c->length, enq_max - read); + rv = BIO_read (bio, c->data, enq_now); + read += rv > 0 ? rv : 0; - if (rv < enq_now) - break; - } + if (rv < enq_now) + break; } svm_fifo_enqueue_nocopy (f, read); @@ -171,21 +167,15 @@ openssl_read_from_ssl_into_fifo (svm_fifo_t * f, SSL * ssl) if (read <= 0) return 0; - if (read == enq_now) + c = svm_fifo_tail_chunk (f); + while ((c = c->next) && read < enq_max) { - c = svm_fifo_tail_chunk (f); - while (read < enq_max) - { - c = c->next; - if (!c) - break; - enq_now = clib_min (c->length, enq_max - read); - rv = SSL_read (ssl, c->data, enq_now); - read += rv > 0 ? rv : 0; - - if (rv < enq_now) - break; - } + enq_now = clib_min (c->length, enq_max - read); + rv = SSL_read (ssl, c->data, enq_now); + read += rv > 0 ? rv : 0; + + if (rv < enq_now) + break; } svm_fifo_enqueue_nocopy (f, read); @@ -205,19 +195,15 @@ openssl_write_from_fifo_into_bio (svm_fifo_t * f, BIO * bio, u32 len) if (wrote <= 0) return 0; - if (wrote == deq_now) + c = svm_fifo_head_chunk (f); + while ((c = c->next) && wrote < len) { - c = svm_fifo_head_chunk (f); - while (wrote < len) - { - c = c->next; - deq_now = clib_min (c->length, len - wrote); - rv = BIO_write (bio, c->data, deq_now); - wrote += rv > 0 ? rv : 0; + deq_now = clib_min (c->length, len - wrote); + rv = BIO_write (bio, c->data, deq_now); + wrote += rv > 0 ? rv : 0; - if (rv < deq_now) - break; - } + if (rv < deq_now) + break; } svm_fifo_dequeue_drop (f, wrote); @@ -237,19 +223,15 @@ openssl_write_from_fifo_into_ssl (svm_fifo_t * f, SSL * ssl, u32 len) if (wrote <= 0) return 0; - if (wrote == deq_now) + c = svm_fifo_head_chunk (f); + while ((c = c->next) && wrote < len) { - c = svm_fifo_head_chunk (f); - while (wrote < len) - { - c = c->next; - deq_now = clib_min (c->length, len - wrote); - rv = SSL_write (ssl, c->data, deq_now); - wrote += rv > 0 ? rv : 0; + deq_now = clib_min (c->length, len - wrote); + rv = SSL_write (ssl, c->data, deq_now); + wrote += rv > 0 ? rv : 0; - if (rv < deq_now) - break; - } + if (rv < deq_now) + break; } svm_fifo_dequeue_drop (f, wrote); |