Removes record_queue struct which is no longer useful.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23571)
This commit is contained in:
Frederik Wedel-Heinen 2024-02-13 13:21:52 +01:00 committed by Tomas Mraz
parent 28c7f52612
commit 715a74a6ad
7 changed files with 35 additions and 45 deletions

View File

@ -90,11 +90,9 @@ static DTLS_BITMAP *dtls_get_bitmap(OSSL_RECORD_LAYER *rl, TLS_RL_RECORD *rr,
return &rl->bitmap; return &rl->bitmap;
/* /*
* We can only handle messages from the next epoch if we have already * Check if the message is from the next epoch
* processed all of the unprocessed records from the previous epoch
*/ */
else if (rr->epoch == (unsigned long)(rl->epoch + 1) else if (rr->epoch == rl->epoch + 1) {
&& rl->unprocessed_rcds.epoch != rl->epoch) {
*is_next_epoch = 1; *is_next_epoch = 1;
return &rl->next_bitmap; return &rl->next_bitmap;
} }
@ -280,14 +278,14 @@ static int dtls_process_record(OSSL_RECORD_LAYER *rl, DTLS_BITMAP *bitmap)
return ret; return ret;
} }
static int dtls_rlayer_buffer_record(OSSL_RECORD_LAYER *rl, record_pqueue *queue, static int dtls_rlayer_buffer_record(OSSL_RECORD_LAYER *rl, struct pqueue_st *queue,
unsigned char *priority) unsigned char *priority)
{ {
DTLS_RLAYER_RECORD_DATA *rdata; DTLS_RLAYER_RECORD_DATA *rdata;
pitem *item; pitem *item;
/* Limit the size of the queue to prevent DOS attacks */ /* Limit the size of the queue to prevent DOS attacks */
if (pqueue_size(queue->q) >= 100) if (pqueue_size(queue) >= 100)
return 0; return 0;
rdata = OPENSSL_malloc(sizeof(*rdata)); rdata = OPENSSL_malloc(sizeof(*rdata));
@ -319,7 +317,7 @@ static int dtls_rlayer_buffer_record(OSSL_RECORD_LAYER *rl, record_pqueue *queue
return -1; return -1;
} }
if (pqueue_insert(queue->q, item) == NULL) { if (pqueue_insert(queue, item) == NULL) {
/* Must be a duplicate so ignore it */ /* Must be a duplicate so ignore it */
OPENSSL_free(rdata->rbuf.buf); OPENSSL_free(rdata->rbuf.buf);
OPENSSL_free(rdata); OPENSSL_free(rdata);
@ -350,11 +348,11 @@ static int dtls_copy_rlayer_record(OSSL_RECORD_LAYER *rl, pitem *item)
} }
static int dtls_retrieve_rlayer_buffered_record(OSSL_RECORD_LAYER *rl, static int dtls_retrieve_rlayer_buffered_record(OSSL_RECORD_LAYER *rl,
record_pqueue *queue) struct pqueue_st *queue)
{ {
pitem *item; pitem *item;
item = pqueue_pop(queue->q); item = pqueue_pop(queue);
if (item) { if (item) {
dtls_copy_rlayer_record(rl, item); dtls_copy_rlayer_record(rl, item);
@ -401,7 +399,7 @@ int dtls_get_more_records(OSSL_RECORD_LAYER *rl)
again: again:
/* if we're renegotiating, then there may be buffered records */ /* if we're renegotiating, then there may be buffered records */
if (dtls_retrieve_rlayer_buffered_record(rl, &rl->processed_rcds)) { if (dtls_retrieve_rlayer_buffered_record(rl, rl->processed_rcds)) {
rl->num_recs = 1; rl->num_recs = 1;
return OSSL_RECORD_RETURN_SUCCESS; return OSSL_RECORD_RETURN_SUCCESS;
} }
@ -547,7 +545,7 @@ int dtls_get_more_records(OSSL_RECORD_LAYER *rl)
*/ */
if (is_next_epoch) { if (is_next_epoch) {
if (rl->in_init) { if (rl->in_init) {
if (dtls_rlayer_buffer_record(rl, &(rl->unprocessed_rcds), if (dtls_rlayer_buffer_record(rl, rl->unprocessed_rcds,
rr->seq_num) < 0) { rr->seq_num) < 0) {
/* RLAYERfatal() already called */ /* RLAYERfatal() already called */
return OSSL_RECORD_RETURN_FATAL; return OSSL_RECORD_RETURN_FATAL;
@ -597,8 +595,8 @@ static int dtls_free(OSSL_RECORD_LAYER *rl)
rbuf->left = 0; rbuf->left = 0;
} }
if (rl->unprocessed_rcds.q != NULL) { if (rl->unprocessed_rcds != NULL) {
while ((item = pqueue_pop(rl->unprocessed_rcds.q)) != NULL) { while ((item = pqueue_pop(rl->unprocessed_rcds)) != NULL) {
rdata = (DTLS_RLAYER_RECORD_DATA *)item->data; rdata = (DTLS_RLAYER_RECORD_DATA *)item->data;
/* Push to the next record layer */ /* Push to the next record layer */
ret &= BIO_write_ex(rl->next, rdata->packet, rdata->packet_length, ret &= BIO_write_ex(rl->next, rdata->packet, rdata->packet_length,
@ -607,17 +605,17 @@ static int dtls_free(OSSL_RECORD_LAYER *rl)
OPENSSL_free(item->data); OPENSSL_free(item->data);
pitem_free(item); pitem_free(item);
} }
pqueue_free(rl->unprocessed_rcds.q); pqueue_free(rl->unprocessed_rcds);
} }
if (rl->processed_rcds.q != NULL) { if (rl->processed_rcds!= NULL) {
while ((item = pqueue_pop(rl->processed_rcds.q)) != NULL) { while ((item = pqueue_pop(rl->processed_rcds)) != NULL) {
rdata = (DTLS_RLAYER_RECORD_DATA *)item->data; rdata = (DTLS_RLAYER_RECORD_DATA *)item->data;
OPENSSL_free(rdata->rbuf.buf); OPENSSL_free(rdata->rbuf.buf);
OPENSSL_free(item->data); OPENSSL_free(item->data);
pitem_free(item); pitem_free(item);
} }
pqueue_free(rl->processed_rcds.q); pqueue_free(rl->processed_rcds);
} }
return tls_free(rl) && ret; return tls_free(rl) && ret;
@ -648,19 +646,17 @@ dtls_new_record_layer(OSSL_LIB_CTX *libctx, const char *propq, int vers,
if (ret != OSSL_RECORD_RETURN_SUCCESS) if (ret != OSSL_RECORD_RETURN_SUCCESS)
return ret; return ret;
(*retrl)->unprocessed_rcds.q = pqueue_new(); (*retrl)->unprocessed_rcds = pqueue_new();
(*retrl)->processed_rcds.q = pqueue_new(); (*retrl)->processed_rcds = pqueue_new();
if ((*retrl)->unprocessed_rcds.q == NULL
|| (*retrl)->processed_rcds.q == NULL) { if ((*retrl)->unprocessed_rcds == NULL
|| (*retrl)->processed_rcds == NULL) {
dtls_free(*retrl); dtls_free(*retrl);
*retrl = NULL; *retrl = NULL;
ERR_raise(ERR_LIB_SSL, ERR_R_SSL_LIB); ERR_raise(ERR_LIB_SSL, ERR_R_SSL_LIB);
return OSSL_RECORD_RETURN_FATAL; return OSSL_RECORD_RETURN_FATAL;
} }
(*retrl)->unprocessed_rcds.epoch = epoch + 1;
(*retrl)->processed_rcds.epoch = epoch;
(*retrl)->isdtls = 1; (*retrl)->isdtls = 1;
(*retrl)->epoch = epoch; (*retrl)->epoch = epoch;
(*retrl)->in_init = 1; (*retrl)->in_init = 1;

View File

@ -344,8 +344,8 @@ struct ossl_record_layer_st
size_t taglen; size_t taglen;
/* DTLS received handshake records (processed and unprocessed) */ /* DTLS received handshake records (processed and unprocessed) */
record_pqueue unprocessed_rcds; struct pqueue_st *unprocessed_rcds;
record_pqueue processed_rcds; struct pqueue_st *processed_rcds;
/* records being received in the current epoch */ /* records being received in the current epoch */
DTLS_BITMAP bitmap; DTLS_BITMAP bitmap;

View File

@ -25,9 +25,9 @@ int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)
rl->d = d; rl->d = d;
d->buffered_app_data.q = pqueue_new(); d->buffered_app_data = pqueue_new();
if (d->buffered_app_data.q == NULL) { if (d->buffered_app_data == NULL) {
OPENSSL_free(d); OPENSSL_free(d);
rl->d = NULL; rl->d = NULL;
return 0; return 0;
@ -42,7 +42,7 @@ void DTLS_RECORD_LAYER_free(RECORD_LAYER *rl)
return; return;
DTLS_RECORD_LAYER_clear(rl); DTLS_RECORD_LAYER_clear(rl);
pqueue_free(rl->d->buffered_app_data.q); pqueue_free(rl->d->buffered_app_data);
OPENSSL_free(rl->d); OPENSSL_free(rl->d);
rl->d = NULL; rl->d = NULL;
} }
@ -56,7 +56,7 @@ void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
d = rl->d; d = rl->d;
while ((item = pqueue_pop(d->buffered_app_data.q)) != NULL) { while ((item = pqueue_pop(d->buffered_app_data)) != NULL) {
rec = (TLS_RECORD *)item->data; rec = (TLS_RECORD *)item->data;
if (rl->s->options & SSL_OP_CLEANSE_PLAINTEXT) if (rl->s->options & SSL_OP_CLEANSE_PLAINTEXT)
@ -66,19 +66,19 @@ void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
pitem_free(item); pitem_free(item);
} }
buffered_app_data = d->buffered_app_data.q; buffered_app_data = d->buffered_app_data;
memset(d, 0, sizeof(*d)); memset(d, 0, sizeof(*d));
d->buffered_app_data.q = buffered_app_data; d->buffered_app_data = buffered_app_data;
} }
static int dtls_buffer_record(SSL_CONNECTION *s, TLS_RECORD *rec) static int dtls_buffer_record(SSL_CONNECTION *s, TLS_RECORD *rec)
{ {
TLS_RECORD *rdata; TLS_RECORD *rdata;
pitem *item; pitem *item;
record_pqueue *queue = &(s->rlayer.d->buffered_app_data); struct pqueue_st *queue = s->rlayer.d->buffered_app_data;
/* Limit the size of the queue to prevent DOS attacks */ /* Limit the size of the queue to prevent DOS attacks */
if (pqueue_size(queue->q) >= 100) if (pqueue_size(queue) >= 100)
return 0; return 0;
/* We don't buffer partially read records */ /* We don't buffer partially read records */
@ -125,7 +125,7 @@ static int dtls_buffer_record(SSL_CONNECTION *s, TLS_RECORD *rec)
} }
#endif #endif
if (pqueue_insert(queue->q, item) == NULL) { if (pqueue_insert(queue, item) == NULL) {
/* Must be a duplicate so ignore it */ /* Must be a duplicate so ignore it */
OPENSSL_free(rdata->allocdata); OPENSSL_free(rdata->allocdata);
OPENSSL_free(rdata); OPENSSL_free(rdata);
@ -145,7 +145,7 @@ static void dtls_unbuffer_record(SSL_CONNECTION *s)
if (s->rlayer.curr_rec < s->rlayer.num_recs) if (s->rlayer.curr_rec < s->rlayer.num_recs)
return; return;
item = pqueue_pop(s->rlayer.d->buffered_app_data.q); item = pqueue_pop(s->rlayer.d->buffered_app_data);
if (item != NULL) { if (item != NULL) {
rdata = (TLS_RECORD *)item->data; rdata = (TLS_RECORD *)item->data;

View File

@ -179,7 +179,7 @@ size_t ssl3_pending(const SSL *s)
TLS_RECORD *rdata; TLS_RECORD *rdata;
pitem *item, *iter; pitem *item, *iter;
iter = pqueue_iterator(sc->rlayer.d->buffered_app_data.q); iter = pqueue_iterator(sc->rlayer.d->buffered_app_data);
while ((item = pqueue_next(&iter)) != NULL) { while ((item = pqueue_next(&iter)) != NULL) {
rdata = item->data; rdata = item->data;
num += rdata->length; num += rdata->length;

View File

@ -43,11 +43,6 @@ typedef struct tls_record_st {
#endif #endif
} TLS_RECORD; } TLS_RECORD;
typedef struct record_pqueue_st {
uint16_t epoch;
struct pqueue_st *q;
} record_pqueue;
typedef struct dtls_record_layer_st { typedef struct dtls_record_layer_st {
/* /*
* The current data and handshake epoch. This is initially * The current data and handshake epoch. This is initially
@ -62,7 +57,7 @@ typedef struct dtls_record_layer_st {
* Finished to prevent either protocol violation or unnecessary message * Finished to prevent either protocol violation or unnecessary message
* loss. * loss.
*/ */
record_pqueue buffered_app_data; struct pqueue_st *buffered_app_data;
} DTLS_RECORD_LAYER; } DTLS_RECORD_LAYER;
/***************************************************************************** /*****************************************************************************

View File

@ -1917,7 +1917,7 @@ int SSL_has_pending(const SSL *s)
TLS_RECORD *rdata; TLS_RECORD *rdata;
pitem *item, *iter; pitem *item, *iter;
iter = pqueue_iterator(sc->rlayer.d->buffered_app_data.q); iter = pqueue_iterator(sc->rlayer.d->buffered_app_data);
while ((item = pqueue_next(&iter)) != NULL) { while ((item = pqueue_next(&iter)) != NULL) {
rdata = item->data; rdata = item->data;
if (rdata->length > 0) if (rdata->length > 0)

View File

@ -600,7 +600,6 @@
-T clock_t -T clock_t
-T custom_ext_methods -T custom_ext_methods
-T hm_fragment -T hm_fragment
-T record_pqueue
-T ssl_ctx_st -T ssl_ctx_st
-T ssl_flag_tbl -T ssl_flag_tbl
-T ssl_st -T ssl_st