Moved processed_rcds and unprocessed_rcds from s->d1 to s->rlayer.d
authorMatt Caswell <matt@openssl.org>
Tue, 3 Feb 2015 16:05:28 +0000 (16:05 +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/record/ssl3_record.c
ssl/ssl_locl.h

index 79c65905b350e70dbbc85fc27403d2b669ad67c3..6ffbf5fc833ddaa517d3875f5dbd61c1221d15cc 100644 (file)
@@ -138,8 +138,6 @@ int dtls1_new(SSL *s)
         return 0;
     }
 
-    d1->unprocessed_rcds.q = pqueue_new();
-    d1->processed_rcds.q = pqueue_new();
     d1->buffered_messages = pqueue_new();
     d1->sent_messages = pqueue_new();
     d1->buffered_app_data.q = pqueue_new();
@@ -151,13 +149,8 @@ int dtls1_new(SSL *s)
     d1->link_mtu = 0;
     d1->mtu = 0;
 
-    if (!d1->unprocessed_rcds.q || !d1->processed_rcds.q
-        || !d1->buffered_messages || !d1->sent_messages
+    if (!d1->buffered_messages || !d1->sent_messages
         || !d1->buffered_app_data.q) {
-        if (d1->unprocessed_rcds.q)
-            pqueue_free(d1->unprocessed_rcds.q);
-        if (d1->processed_rcds.q)
-            pqueue_free(d1->processed_rcds.q);
         if (d1->buffered_messages)
             pqueue_free(d1->buffered_messages);
         if (d1->sent_messages)
@@ -180,24 +173,6 @@ static void dtls1_clear_queues(SSL *s)
     hm_fragment *frag = NULL;
     DTLS1_RECORD_DATA *rdata;
 
-    while ((item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) {
-        rdata = (DTLS1_RECORD_DATA *)item->data;
-        if (rdata->rbuf.buf) {
-            OPENSSL_free(rdata->rbuf.buf);
-        }
-        OPENSSL_free(item->data);
-        pitem_free(item);
-    }
-
-    while ((item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) {
-        rdata = (DTLS1_RECORD_DATA *)item->data;
-        if (rdata->rbuf.buf) {
-            OPENSSL_free(rdata->rbuf.buf);
-        }
-        OPENSSL_free(item->data);
-        pitem_free(item);
-    }
-
     while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL) {
         frag = (hm_fragment *)item->data;
         dtls1_hm_fragment_free(frag);
@@ -228,8 +203,6 @@ void dtls1_free(SSL *s)
 
     dtls1_clear_queues(s);
 
-    pqueue_free(s->d1->unprocessed_rcds.q);
-    pqueue_free(s->d1->processed_rcds.q);
     pqueue_free(s->d1->buffered_messages);
     pqueue_free(s->d1->sent_messages);
     pqueue_free(s->d1->buffered_app_data.q);
@@ -240,8 +213,6 @@ void dtls1_free(SSL *s)
 
 void dtls1_clear(SSL *s)
 {
-    pqueue unprocessed_rcds;
-    pqueue processed_rcds;
     pqueue buffered_messages;
     pqueue sent_messages;
     pqueue buffered_app_data;
@@ -251,8 +222,6 @@ void dtls1_clear(SSL *s)
     DTLS_RECORD_LAYER_clear(&s->rlayer);
 
     if (s->d1) {
-        unprocessed_rcds = s->d1->unprocessed_rcds.q;
-        processed_rcds = s->d1->processed_rcds.q;
         buffered_messages = s->d1->buffered_messages;
         sent_messages = s->d1->sent_messages;
         buffered_app_data = s->d1->buffered_app_data.q;
@@ -272,8 +241,6 @@ void dtls1_clear(SSL *s)
             s->d1->link_mtu = link_mtu;
         }
 
-        s->d1->unprocessed_rcds.q = unprocessed_rcds;
-        s->d1->processed_rcds.q = processed_rcds;
         s->d1->buffered_messages = buffered_messages;
         s->d1->sent_messages = sent_messages;
         s->d1->buffered_app_data.q = buffered_app_data;
index a9947ffbf5903ac4164a822d875119f2edce305f..5d0adb9c4e36c337f202110a1d727990b423a0eb 100644 (file)
@@ -131,14 +131,31 @@ int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)
         return (0);
     }
 
+
     rl->d = d;
     DTLS_RECORD_LAYER_clear(rl);
+    
+    d->unprocessed_rcds.q = pqueue_new();
+    d->processed_rcds.q = pqueue_new();
+
+    if (!d->unprocessed_rcds.q || !d->processed_rcds.q) {
+        if (d->unprocessed_rcds.q)
+            pqueue_free(d->unprocessed_rcds.q);
+        if (d->processed_rcds.q)
+            pqueue_free(d->processed_rcds.q);
+        OPENSSL_free(d);
+        rl->d = NULL;
+        return (0);
+    }
 
     return 1;
 }
 
 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);
     OPENSSL_free(rl->d);
     rl->d = NULL;
 }
@@ -146,9 +163,36 @@ void DTLS_RECORD_LAYER_free(RECORD_LAYER *rl)
 void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
 {
     DTLS_RECORD_LAYER *d;
-    
+    pitem *item = NULL;
+    DTLS1_RECORD_DATA *rdata;
+    pqueue unprocessed_rcds;
+    pqueue processed_rcds;
+
     d = rl->d;
+    
+    while ((item = pqueue_pop(d->unprocessed_rcds.q)) != NULL) {
+        rdata = (DTLS1_RECORD_DATA *)item->data;
+        if (rdata->rbuf.buf) {
+            OPENSSL_free(rdata->rbuf.buf);
+        }
+        OPENSSL_free(item->data);
+        pitem_free(item);
+    }
+
+    while ((item = pqueue_pop(d->processed_rcds.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;
     memset(d, 0, sizeof *d);
+    d->unprocessed_rcds.q = unprocessed_rcds;
+    d->processed_rcds.q = processed_rcds;
 }
 
 static int have_handshake_fragment(SSL *s, int type, unsigned char *buf,
@@ -263,25 +307,25 @@ int dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue)
  */
 #define dtls1_get_unprocessed_record(s) \
                    dtls1_retrieve_buffered_record((s), \
-                   &((s)->d1->unprocessed_rcds))
+                   &((s)->rlayer.d->unprocessed_rcds))
 
 
 int dtls1_process_buffered_records(SSL *s)
 {
     pitem *item;
 
-    item = pqueue_peek(s->d1->unprocessed_rcds.q);
+    item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);
     if (item) {
         /* Check if epoch is current. */
-        if (s->d1->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)
+        if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)
             return (1);         /* Nothing to do. */
 
         /* Process all the records. */
-        while (pqueue_peek(s->d1->unprocessed_rcds.q)) {
+        while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {
             dtls1_get_unprocessed_record(s);
             if (!dtls1_process_record(s))
                 return (0);
-            if (dtls1_buffer_record(s, &(s->d1->processed_rcds),
+            if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),
                 SSL3_RECORD_get_seq_num(&s->rlayer.rrec)) < 0)
                 return -1;
         }
@@ -291,8 +335,8 @@ int dtls1_process_buffered_records(SSL *s)
      * sync epoch numbers once all the unprocessed records have been
      * processed
      */
-    s->d1->processed_rcds.epoch = s->rlayer.d->r_epoch;
-    s->d1->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;
+    s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;
+    s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;
 
     return (1);
 }
index 4830318c65a7653b4d3eea814e3057f03b1929df..2159041bfe8d577a9b6b8c5fda8c75572990bd44 100644 (file)
@@ -147,6 +147,10 @@ typedef struct dtls_record_layer_st {
     DTLS1_BITMAP bitmap;
     /* renegotiation starts a new set of sequence numbers */
     DTLS1_BITMAP next_bitmap;
+
+    /* Received handshake records (processed and unprocessed) */
+    record_pqueue unprocessed_rcds;
+    record_pqueue processed_rcds;
 } DTLS_RECORD_LAYER;
 
 typedef struct record_layer_st {
@@ -216,6 +220,10 @@ typedef struct record_layer_st {
 #define RECORD_LAYER_get_write_sequence(rl)     ((rl)->write_sequence)
 #define DTLS_RECORD_LAYER_get_w_epoch(rl)       ((rl)->d->w_epoch)
 #define DTLS_RECORD_LAYER_set_w_epoch(rl, e)    ((rl)->d->w_epoch = (e))
+#define DTLS_RECORD_LAYER_get_processed_rcds(rl) \
+                                                ((rl)->d->processed_rcds)
+#define DTLS_RECORD_LAYER_get_unprocessed_rcds(rl) \
+                                                ((rl)->d->unprocessed_rcds)
 
 void RECORD_LAYER_init(RECORD_LAYER *rl, SSL *s);
 void RECORD_LAYER_clear(RECORD_LAYER *rl);
index e3652705ea6131f36720883622cdb8ea194cc78c..be5bb22ae056a1eb77df97661c6ca411dafd5606 100644 (file)
@@ -1366,7 +1366,7 @@ int dtls1_process_record(SSL *s)
  */
 #define dtls1_get_processed_record(s) \
                    dtls1_retrieve_buffered_record((s), \
-                   &((s)->d1->processed_rcds))
+                   &(DTLS_RECORD_LAYER_get_processed_rcds(&s->rlayer)))
 
 /*-
  * Call this to get a new input record.
@@ -1533,7 +1533,8 @@ int dtls1_get_record(SSL *s)
     if (is_next_epoch) {
         if ((SSL_in_init(s) || s->in_handshake) && !s->d1->listen) {
             if (dtls1_buffer_record
-                (s, &(s->d1->unprocessed_rcds), rr->seq_num) < 0)
+                (s, &(DTLS_RECORD_LAYER_get_unprocessed_rcds(&s->rlayer)),
+                rr->seq_num) < 0)
                 return -1;
             /* Mark receipt of record. */
             dtls1_record_bitmap_update(s, bitmap);
index 0b267faf96671755a8d70d73766d1a784797debe..e5fb64c07872163e42fb4e357d0210cfee594ed6 100644 (file)
@@ -1411,9 +1411,6 @@ typedef struct dtls1_state_st {
     unsigned short handshake_read_seq;
     /* save last sequence number for retransmissions */
     unsigned char last_write_sequence[8];
-    /* Received handshake records (processed and unprocessed) */
-    record_pqueue unprocessed_rcds;
-    record_pqueue processed_rcds;
     /* Buffered handshake messages */
     pqueue buffered_messages;
     /* Buffered (sent) handshake records */