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;
/*
* We can only handle messages from the next epoch if we have already
* processed all of the unprocessed records from the previous epoch
* Check if the message is from the next epoch
*/
else if (rr->epoch == (unsigned long)(rl->epoch + 1)
&& rl->unprocessed_rcds.epoch != rl->epoch) {
else if (rr->epoch == rl->epoch + 1) {
*is_next_epoch = 1;
return &rl->next_bitmap;
}
@ -280,14 +278,14 @@ static int dtls_process_record(OSSL_RECORD_LAYER *rl, DTLS_BITMAP *bitmap)
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)
{
DTLS_RLAYER_RECORD_DATA *rdata;
pitem *item;
/* Limit the size of the queue to prevent DOS attacks */
if (pqueue_size(queue->q) >= 100)
if (pqueue_size(queue) >= 100)
return 0;
rdata = OPENSSL_malloc(sizeof(*rdata));
@ -319,7 +317,7 @@ static int dtls_rlayer_buffer_record(OSSL_RECORD_LAYER *rl, record_pqueue *queue
return -1;
}
if (pqueue_insert(queue->q, item) == NULL) {
if (pqueue_insert(queue, item) == NULL) {
/* Must be a duplicate so ignore it */
OPENSSL_free(rdata->rbuf.buf);
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,
record_pqueue *queue)
struct pqueue_st *queue)
{
pitem *item;
item = pqueue_pop(queue->q);
item = pqueue_pop(queue);
if (item) {
dtls_copy_rlayer_record(rl, item);
@ -401,7 +399,7 @@ int dtls_get_more_records(OSSL_RECORD_LAYER *rl)
again:
/* 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;
return OSSL_RECORD_RETURN_SUCCESS;
}
@ -547,7 +545,7 @@ int dtls_get_more_records(OSSL_RECORD_LAYER *rl)
*/
if (is_next_epoch) {
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) {
/* RLAYERfatal() already called */
return OSSL_RECORD_RETURN_FATAL;
@ -597,8 +595,8 @@ static int dtls_free(OSSL_RECORD_LAYER *rl)
rbuf->left = 0;
}
if (rl->unprocessed_rcds.q != NULL) {
while ((item = pqueue_pop(rl->unprocessed_rcds.q)) != NULL) {
if (rl->unprocessed_rcds != NULL) {
while ((item = pqueue_pop(rl->unprocessed_rcds)) != NULL) {
rdata = (DTLS_RLAYER_RECORD_DATA *)item->data;
/* Push to the next record layer */
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);
pitem_free(item);
}
pqueue_free(rl->unprocessed_rcds.q);
pqueue_free(rl->unprocessed_rcds);
}
if (rl->processed_rcds.q != NULL) {
while ((item = pqueue_pop(rl->processed_rcds.q)) != NULL) {
if (rl->processed_rcds!= NULL) {
while ((item = pqueue_pop(rl->processed_rcds)) != NULL) {
rdata = (DTLS_RLAYER_RECORD_DATA *)item->data;
OPENSSL_free(rdata->rbuf.buf);
OPENSSL_free(item->data);
pitem_free(item);
}
pqueue_free(rl->processed_rcds.q);
pqueue_free(rl->processed_rcds);
}
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)
return ret;
(*retrl)->unprocessed_rcds.q = pqueue_new();
(*retrl)->processed_rcds.q = pqueue_new();
if ((*retrl)->unprocessed_rcds.q == NULL
|| (*retrl)->processed_rcds.q == NULL) {
(*retrl)->unprocessed_rcds = pqueue_new();
(*retrl)->processed_rcds = pqueue_new();
if ((*retrl)->unprocessed_rcds == NULL
|| (*retrl)->processed_rcds == NULL) {
dtls_free(*retrl);
*retrl = NULL;
ERR_raise(ERR_LIB_SSL, ERR_R_SSL_LIB);
return OSSL_RECORD_RETURN_FATAL;
}
(*retrl)->unprocessed_rcds.epoch = epoch + 1;
(*retrl)->processed_rcds.epoch = epoch;
(*retrl)->isdtls = 1;
(*retrl)->epoch = epoch;
(*retrl)->in_init = 1;

View File

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

View File

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

View File

@ -179,7 +179,7 @@ size_t ssl3_pending(const SSL *s)
TLS_RECORD *rdata;
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) {
rdata = item->data;
num += rdata->length;

View File

@ -43,11 +43,6 @@ typedef struct tls_record_st {
#endif
} TLS_RECORD;
typedef struct record_pqueue_st {
uint16_t epoch;
struct pqueue_st *q;
} record_pqueue;
typedef struct dtls_record_layer_st {
/*
* 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
* loss.
*/
record_pqueue buffered_app_data;
struct pqueue_st *buffered_app_data;
} DTLS_RECORD_LAYER;
/*****************************************************************************

View File

@ -1917,7 +1917,7 @@ int SSL_has_pending(const SSL *s)
TLS_RECORD *rdata;
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) {
rdata = item->data;
if (rdata->length > 0)

View File

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