tls: prealloc chunks for dtls dgram enq 17/32417/4
authorFlorin Coras <fcoras@cisco.com>
Sat, 22 May 2021 01:26:30 +0000 (18:26 -0700)
committerDave Barach <openvpp@barachs.net>
Sat, 22 May 2021 16:45:00 +0000 (16:45 +0000)
Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ib25598f72f6539c07de1acee1e6049ecd28f35cc

src/plugins/tlsopenssl/dtls_bio.c
src/plugins/tlsopenssl/tls_openssl.c

index 7cd2abd..39e9435 100644 (file)
@@ -110,7 +110,7 @@ bio_dtls_write (BIO *b, const char *in, int inl)
   rv = app_send_dgram_raw (s->tx_fifo, &at, mq, (u8 *) in, inl,
                           SESSION_IO_EVT_TX, 1 /* do_evt */, 0 /* noblock */);
 
-  if (rv < 0)
+  if (rv <= 0)
     {
       BIO_set_retry_read (b);
       errno = EAGAIN;
index 7a840f1..496d777 100644 (file)
@@ -422,10 +422,10 @@ openssl_ctx_write_dtls (tls_ctx_t *ctx, session_t *app_session,
 {
   openssl_main_t *om = &openssl_main;
   openssl_ctx_t *oc = (openssl_ctx_t *) ctx;
+  u32 read = 0, to_deq, dgram_sz, enq_max;
   session_dgram_pre_hdr_t hdr;
   session_t *us;
   int wrote, rv;
-  u32 read = 0, to_deq, dgram_sz;
   u8 *buf;
 
   us = session_get_from_handle (ctx->tls_session_handle);
@@ -440,7 +440,9 @@ openssl_ctx_write_dtls (tls_ctx_t *ctx, session_t *app_session,
       ASSERT (to_deq >= hdr.data_length + SESSION_CONN_HDR_LEN);
 
       dgram_sz = hdr.data_length + SESSION_CONN_HDR_LEN;
-      if (svm_fifo_max_enqueue_prod (us->tx_fifo) < dgram_sz + TLSO_CTRL_BYTES)
+      enq_max = dgram_sz + TLSO_CTRL_BYTES;
+      if (svm_fifo_max_enqueue_prod (us->tx_fifo) < enq_max ||
+         svm_fifo_provision_chunks (us->tx_fifo, 0, 0, enq_max))
        {
          svm_fifo_add_want_deq_ntf (us->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF);
          transport_connection_deschedule (&ctx->connection);