summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-02-03 16:05:28 +0000
committerMatt Caswell <matt@openssl.org>2015-03-26 15:02:00 +0000
commitcb2ce7abfd3e2e641851e0ed9dff1a883b38037e (patch)
tree26190f68bbbe81f4f1c400430bd9010e77e51576
parent91f93f69ef59bbe9ad8d191eed5a88b2125fba26 (diff)
Moved processed_rcds and unprocessed_rcds from s->d1 to s->rlayer.d
Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r--ssl/d1_lib.c35
-rw-r--r--ssl/record/d1_pkt.c60
-rw-r--r--ssl/record/rec_layer.h8
-rw-r--r--ssl/record/ssl3_record.c5
-rw-r--r--ssl/ssl_locl.h3
5 files changed, 64 insertions, 47 deletions
diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c
index 79c65905b3..6ffbf5fc83 100644
--- a/ssl/d1_lib.c
+++ b/ssl/d1_lib.c
@@ -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;
diff --git a/ssl/record/d1_pkt.c b/ssl/record/d1_pkt.c
index a9947ffbf5..5d0adb9c4e 100644
--- a/ssl/record/d1_pkt.c
+++ b/ssl/record/d1_pkt.c
@@ -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);
}
diff --git a/ssl/record/rec_layer.h b/ssl/record/rec_layer.h
index 4830318c65..2159041bfe 100644
--- a/ssl/record/rec_layer.h
+++ b/ssl/record/rec_layer.h
@@ -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);
diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c
index e3652705ea..be5bb22ae0 100644
--- a/ssl/record/ssl3_record.c
+++ b/ssl/record/ssl3_record.c
@@ -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);
diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
index 0b267faf96..e5fb64c078 100644
--- a/ssl/ssl_locl.h
+++ b/ssl/ssl_locl.h
@@ -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 */