Skip to content

Commit

Permalink
Removes record_queue struct which is no longer useful.
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh-dc committed Feb 13, 2024
1 parent 925118e commit a254940
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 45 deletions.
44 changes: 20 additions & 24 deletions ssl/record/methods/dtls_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ssl/record/methods/recmethod_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions ssl/record/rec_layer_d1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ssl/record/rec_layer_s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions ssl/record/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

/*****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion ssl/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion util/indent.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a254940

Please sign in to comment.