Move numwpipes in the write record layer
authorMatt Caswell <matt@openssl.org>
Thu, 25 Aug 2022 16:34:48 +0000 (17:34 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 23 Sep 2022 13:54:49 +0000 (14:54 +0100)
We retain a numwpipes for now in the old record layer structure for use
by DTLS. This will eventually be removed when DTLS moves over to the new
way of doing things.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19198)

ssl/record/methods/recmethod_local.h
ssl/record/methods/tls_common.c
ssl/record/rec_layer_d1.c
ssl/record/record.h

index 475fb7c047fa2d4829f6f4e9eb5578677478f274..289f2e83330dd6b5d9949f85869d5c816dc2a907 100644 (file)
@@ -102,6 +102,9 @@ struct ossl_record_layer_st
     /* Next wbuf with pending data still to write */
     size_t nextwbuf;
 
+    /* How many pipelines can be used to write data */
+    size_t numwpipes;
+
     /* read IO goes into here */
     SSL3_BUFFER rbuf;
     /* each decoded record goes in here */
index 5e1f1bb01b15cd64e8848c58b2b88b3f53d75ca4..d56184f81622965b5e5956a0232f7618ccf104fc 100644 (file)
@@ -103,7 +103,7 @@ static int tls_setup_write_buffer(OSSL_RECORD_LAYER *rl, size_t numwpipes,
     size_t currpipe;
     SSL_CONNECTION *s = (SSL_CONNECTION *)rl->cbarg;
 
-    s->rlayer.numwpipes = numwpipes;
+    rl->numwpipes = numwpipes;
 
     if (len == 0) {
         if (SSL_CONNECTION_IS_DTLS(s))
@@ -138,7 +138,7 @@ static int tls_setup_write_buffer(OSSL_RECORD_LAYER *rl, size_t numwpipes,
             if (s->wbio == NULL || !BIO_get_ktls_send(s->wbio)) {
                 p = OPENSSL_malloc(len);
                 if (p == NULL) {
-                    s->rlayer.numwpipes = currpipe;
+                    rl->numwpipes = currpipe;
                     /*
                      * We've got a malloc failure, and we're still initialising
                      * buffers. We assume we're so doomed that we won't even be able
@@ -163,9 +163,8 @@ static void tls_release_write_buffer(OSSL_RECORD_LAYER *rl)
 {
     SSL3_BUFFER *wb;
     size_t pipes;
-    SSL_CONNECTION *s = (SSL_CONNECTION *)rl->cbarg;
 
-    pipes = (s == NULL) ? 0 : s->rlayer.numwpipes;
+    pipes = rl->numwpipes;
 
     while (pipes > 0) {
         wb = &rl->wbuf[pipes - 1];
@@ -177,9 +176,8 @@ static void tls_release_write_buffer(OSSL_RECORD_LAYER *rl)
         wb->buf = NULL;
         pipes--;
     }
-    /* TODO(RECLAYER): REMOVE ME */
-    if (rl->direction == OSSL_RECORD_DIRECTION_WRITE)
-        s->rlayer.numwpipes = 0;
+
+    rl->numwpipes = 0;
 }
 
 int tls_setup_read_buffer(OSSL_RECORD_LAYER *rl)
@@ -1415,7 +1413,7 @@ int tls_write_records(OSSL_RECORD_LAYER *rl, OSSL_RECORD_TEMPLATE *templates,
     OSSL_RECORD_TEMPLATE *thistempl;
 
     /* Check we don't have pending data waiting to write */
-    if (!ossl_assert(rl->nextwbuf >= s->rlayer.numwpipes
+    if (!ossl_assert(rl->nextwbuf >= rl->numwpipes
                      || SSL3_BUFFER_get_left(&rl->wbuf[rl->nextwbuf]) == 0)) {
         SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
         goto err;
@@ -1446,7 +1444,7 @@ int tls_write_records(OSSL_RECORD_LAYER *rl, OSSL_RECORD_TEMPLATE *templates,
              && !s->s3.empty_fragment_done
              && templates[0].type == SSL3_RT_APPLICATION_DATA;
 
-    if (s->rlayer.numwpipes < numtempl + prefix) {
+    if (rl->numwpipes < numtempl + prefix) {
         /*
          * TODO(RECLAYER): In the prefix case the first buffer can be a lot
          * smaller. It is wasteful to allocate a full sized buffer here
@@ -1864,7 +1862,7 @@ int tls_retry_write_records(OSSL_RECORD_LAYER *rl)
     size_t tmpwrit = 0;
     SSL_CONNECTION *s = rl->cbarg;
 
-    if (rl->nextwbuf >= s->rlayer.numwpipes)
+    if (rl->nextwbuf >= rl->numwpipes)
         return 1;
 
     for (;;) {
@@ -1906,7 +1904,7 @@ int tls_retry_write_records(OSSL_RECORD_LAYER *rl)
         if (i >= 0 && tmpwrit == SSL3_BUFFER_get_left(thiswb)) {
             SSL3_BUFFER_set_left(thiswb, 0);
             SSL3_BUFFER_add_offset(thiswb, tmpwrit);
-            if (++(rl->nextwbuf) < s->rlayer.numwpipes)
+            if (++(rl->nextwbuf) < rl->numwpipes)
                 continue;
             s->rwstate = SSL_NOTHING;
             /*
@@ -1915,7 +1913,7 @@ int tls_retry_write_records(OSSL_RECORD_LAYER *rl)
              */
             s->s3.empty_fragment_done = 0;
 
-            if (rl->nextwbuf == s->rlayer.numwpipes
+            if (rl->nextwbuf == rl->numwpipes
                     && (rl->mode & SSL_MODE_RELEASE_BUFFERS) != 0)
                 tls_release_write_buffer(rl);
 
@@ -1927,7 +1925,7 @@ int tls_retry_write_records(OSSL_RECORD_LAYER *rl)
                  * using a datagram service
                  */
                 SSL3_BUFFER_set_left(thiswb, 0);
-                if (++(rl->nextwbuf) == s->rlayer.numwpipes
+                if (++(rl->nextwbuf) == rl->numwpipes
                         && (rl->mode & SSL_MODE_RELEASE_BUFFERS) != 0)
                     tls_release_write_buffer(rl);
 
index b72fab0fc7bf7ef554b0b87fe1add4e2c9088ab3..cad2ddda2dedb8afa23346fc00e0642bb42cad93 100644 (file)
@@ -662,12 +662,6 @@ static int ssl3_write_pending(SSL_CONNECTION *s, int type,
     }
 
     for (;;) {
-        /* Loop until we find a buffer we haven't written out yet */
-        if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0
-            && currbuf < s->rlayer.numwpipes - 1) {
-            currbuf++;
-            continue;
-        }
         clear_sys_error();
         if (s->wbio != NULL) {
             s->rwstate = SSL_WRITING;
@@ -703,8 +697,6 @@ static int ssl3_write_pending(SSL_CONNECTION *s, int type,
         if (i >= 0 && tmpwrit == SSL3_BUFFER_get_left(&wb[currbuf])) {
             SSL3_BUFFER_set_left(&wb[currbuf], 0);
             SSL3_BUFFER_add_offset(&wb[currbuf], tmpwrit);
-            if (currbuf + 1 < s->rlayer.numwpipes)
-                continue;
             s->rwstate = SSL_NOTHING;
             *written = s->rlayer.wpend_ret;
             return 1;
index 1442b8cb67ed40b5db48a738c61b89e29559f4f1..a5d8fd3670776498796a7f3e540d0b8152c401b6 100644 (file)
@@ -149,6 +149,10 @@ typedef struct record_layer_st {
      * non-blocking reads)
      */
     int read_ahead;
+    /*
+     * TODO(RECLAYER): These next 2 fields can be removed when DTLS is moved to
+     * the new write record layer architecture.
+     */
     /* How many pipelines can be used to write data */
     size_t numwpipes;
     /* write IO goes into here */