Move buffered_app_data from s->d1 to s->rlayer.d
authorMatt Caswell <matt@openssl.org>
Wed, 4 Feb 2015 10:27:43 +0000 (10:27 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 26 Mar 2015 15:02:00 +0000 (15:02 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
ssl/d1_lib.c
ssl/record/d1_pkt.c
ssl/record/rec_layer.h
ssl/ssl_locl.h

index f95994211367d99b6b9ea7f266a78dbba0d7711f..eac271d27b0374eba366466e38352ab03d2bd74d 100644 (file)
@@ -138,7 +138,6 @@ int dtls1_new(SSL *s)
 
     d1->buffered_messages = pqueue_new();
     d1->sent_messages = pqueue_new();
-    d1->buffered_app_data.q = pqueue_new();
 
     if (s->server) {
         d1->cookie_len = sizeof(s->d1->cookie);
@@ -147,14 +146,11 @@ int dtls1_new(SSL *s)
     d1->link_mtu = 0;
     d1->mtu = 0;
 
-    if (!d1->buffered_messages || !d1->sent_messages
-        || !d1->buffered_app_data.q) {
+    if (!d1->buffered_messages || !d1->sent_messages) {
         if (d1->buffered_messages)
             pqueue_free(d1->buffered_messages);
         if (d1->sent_messages)
             pqueue_free(d1->sent_messages);
-        if (d1->buffered_app_data.q)
-            pqueue_free(d1->buffered_app_data.q);
         OPENSSL_free(d1);
         ssl3_free(s);
         return (0);
@@ -169,7 +165,6 @@ static void dtls1_clear_queues(SSL *s)
 {
     pitem *item = NULL;
     hm_fragment *frag = NULL;
-    DTLS1_RECORD_DATA *rdata;
 
     while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL) {
         frag = (hm_fragment *)item->data;
@@ -182,15 +177,6 @@ static void dtls1_clear_queues(SSL *s)
         dtls1_hm_fragment_free(frag);
         pitem_free(item);
     }
-
-    while ((item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL) {
-        rdata = (DTLS1_RECORD_DATA *)item->data;
-        if (rdata->rbuf.buf) {
-            OPENSSL_free(rdata->rbuf.buf);
-        }
-        OPENSSL_free(item->data);
-        pitem_free(item);
-    }
 }
 
 void dtls1_free(SSL *s)
@@ -203,7 +189,6 @@ void dtls1_free(SSL *s)
 
     pqueue_free(s->d1->buffered_messages);
     pqueue_free(s->d1->sent_messages);
-    pqueue_free(s->d1->buffered_app_data.q);
 
     OPENSSL_free(s->d1);
     s->d1 = NULL;
@@ -213,7 +198,6 @@ void dtls1_clear(SSL *s)
 {
     pqueue buffered_messages;
     pqueue sent_messages;
-    pqueue buffered_app_data;
     unsigned int mtu;
     unsigned int link_mtu;
 
@@ -222,7 +206,6 @@ void dtls1_clear(SSL *s)
     if (s->d1) {
         buffered_messages = s->d1->buffered_messages;
         sent_messages = s->d1->sent_messages;
-        buffered_app_data = s->d1->buffered_app_data.q;
         mtu = s->d1->mtu;
         link_mtu = s->d1->link_mtu;
 
@@ -241,7 +224,6 @@ void dtls1_clear(SSL *s)
 
         s->d1->buffered_messages = buffered_messages;
         s->d1->sent_messages = sent_messages;
-        s->d1->buffered_app_data.q = buffered_app_data;
     }
 
     ssl3_clear(s);
index 7803273c1181858bd5cdedc21861a584e2aa37d6..76bea7a29b42d7398dbb892b4acf5d6736e920ed 100644 (file)
@@ -136,12 +136,16 @@ int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)
 
     d->unprocessed_rcds.q = pqueue_new();
     d->processed_rcds.q = pqueue_new();
+    d->buffered_app_data.q = pqueue_new();
 
-    if (!d->unprocessed_rcds.q || !d->processed_rcds.q) {
+    if (!d->unprocessed_rcds.q || !d->processed_rcds.q
+        || !d->buffered_app_data.q) {
         if (d->unprocessed_rcds.q)
             pqueue_free(d->unprocessed_rcds.q);
         if (d->processed_rcds.q)
             pqueue_free(d->processed_rcds.q);
+        if (d->buffered_app_data.q)
+            pqueue_free(d->buffered_app_data.q);
         OPENSSL_free(d);
         rl->d = NULL;
         return (0);
@@ -155,6 +159,7 @@ void DTLS_RECORD_LAYER_free(RECORD_LAYER *rl)
     DTLS_RECORD_LAYER_clear(rl);
     pqueue_free(rl->d->unprocessed_rcds.q);
     pqueue_free(rl->d->processed_rcds.q);
+    pqueue_free(rl->d->buffered_app_data.q);
     OPENSSL_free(rl->d);
     rl->d = NULL;
 }
@@ -166,6 +171,7 @@ void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
     DTLS1_RECORD_DATA *rdata;
     pqueue unprocessed_rcds;
     pqueue processed_rcds;
+    pqueue buffered_app_data;
 
     d = rl->d;
     
@@ -187,11 +193,22 @@ void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
         pitem_free(item);
     }
 
+    while ((item = pqueue_pop(d->buffered_app_data.q)) != NULL) {
+        rdata = (DTLS1_RECORD_DATA *)item->data;
+        if (rdata->rbuf.buf) {
+            OPENSSL_free(rdata->rbuf.buf);
+        }
+        OPENSSL_free(item->data);
+        pitem_free(item);
+    }
+
     unprocessed_rcds = d->unprocessed_rcds.q;
     processed_rcds = d->processed_rcds.q;
+    buffered_app_data = d->buffered_app_data.q;
     memset(d, 0, sizeof *d);
     d->unprocessed_rcds.q = unprocessed_rcds;
     d->processed_rcds.q = processed_rcds;
+    d->buffered_app_data.q = buffered_app_data;
 }
 
 static int have_handshake_fragment(SSL *s, int type, unsigned char *buf,
@@ -441,7 +458,7 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
      */
     if (s->state == SSL_ST_OK && rr->length == 0) {
         pitem *item;
-        item = pqueue_pop(s->d1->buffered_app_data.q);
+        item = pqueue_pop(s->rlayer.d->buffered_app_data.q);
         if (item) {
 #ifndef OPENSSL_NO_SCTP
             /* Restore bio_dgram_sctp_rcvinfo struct */
@@ -491,8 +508,8 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
          * the packets were reordered on their way, so buffer the application
          * data for later processing rather than dropping the connection.
          */
-        if (dtls1_buffer_record(s, &(s->d1->buffered_app_data), rr->seq_num) <
-            0) {
+        if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data),
+            rr->seq_num) < 0) {
             SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);
             return -1;
         }
index 62e2b01d49222dc37cf7c41bfcdfdb0824cfda1f..1367487e3ac4978a8d669ff7764f1363cee74c34 100644 (file)
@@ -151,7 +151,12 @@ typedef struct dtls_record_layer_st {
     /* Received handshake records (processed and unprocessed) */
     record_pqueue unprocessed_rcds;
     record_pqueue processed_rcds;
-
+    /*
+     * Buffered application records. Only for records between CCS and
+     * Finished to prevent either protocol violation or unnecessary message
+     * loss.
+     */
+    record_pqueue buffered_app_data;
     /*
      * storage for Alert/Handshake protocol data received but not yet
      * processed by ssl3_read_bytes:
index 87b103dec93f82da3664ea25666552b8f5d02cda..4ee0ddd79c575528a0ebf91c77f3b6c1bb3fe4cf 100644 (file)
@@ -1415,12 +1415,7 @@ typedef struct dtls1_state_st {
     pqueue buffered_messages;
     /* Buffered (sent) handshake records */
     pqueue sent_messages;
-    /*
-     * Buffered application records. Only for records between CCS and
-     * Finished to prevent either protocol violation or unnecessary message
-     * loss.
-     */
-    record_pqueue buffered_app_data;
+
     /* Is set when listening for new connections with dtls1_listen() */
     unsigned int listen;
     unsigned int link_mtu;      /* max on-the-wire DTLS packet size */