QUIC CFQ Fixes

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19206)
This commit is contained in:
Hugo Landau 2022-10-12 17:44:40 +01:00
parent 0ede517cfa
commit 6db5cb8448
5 changed files with 30 additions and 25 deletions

View File

@ -37,19 +37,19 @@ struct quic_cfq_item_st {
#define QUIC_CFQ_STATE_TX 1
/* Returns the frame type of a CFQ item. */
uint64_t ossl_quic_cfq_item_get_frame_type(QUIC_CFQ_ITEM *item);
uint64_t ossl_quic_cfq_item_get_frame_type(const QUIC_CFQ_ITEM *item);
/* Returns a pointer to the encoded buffer of a CFQ item. */
const unsigned char *ossl_quic_cfq_item_get_encoded(QUIC_CFQ_ITEM *item);
const unsigned char *ossl_quic_cfq_item_get_encoded(const QUIC_CFQ_ITEM *item);
/* Returns the length of the encoded buffer in bytes. */
size_t ossl_quic_cfq_item_get_encoded_len(QUIC_CFQ_ITEM *item);
size_t ossl_quic_cfq_item_get_encoded_len(const QUIC_CFQ_ITEM *item);
/* Returns the CFQ item state, a QUIC_CFQ_STATE_* value. */
int ossl_quic_cfq_item_get_state(QUIC_CFQ_ITEM *item);
int ossl_quic_cfq_item_get_state(const QUIC_CFQ_ITEM *item);
/* Returns the PN space for the CFQ item. */
uint32_t ossl_quic_cfq_item_get_pn_space(QUIC_CFQ_ITEM *item);
uint32_t ossl_quic_cfq_item_get_pn_space(const QUIC_CFQ_ITEM *item);
/*
* QUIC Control Frame Queue
@ -126,7 +126,8 @@ void ossl_quic_cfq_release(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item);
* Gets the highest priority CFQ item in the given PN space awaiting
* transmission. If there are none, returns NULL.
*/
QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(QUIC_CFQ *cfq, uint32_t pn_space);
QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(const QUIC_CFQ *cfq,
uint32_t pn_space);
/*
* Given a CFQ item, gets the next CFQ item awaiting transmission in priority
@ -134,7 +135,7 @@ QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(QUIC_CFQ *cfq, uint32_t pn_space)
* ossl_quic_cfq_get_priority_head(), returns the next-lower priority item.
* Returns NULL if the given item is the last item in priority order.
*/
QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(QUIC_CFQ_ITEM *item,
QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(const QUIC_CFQ_ITEM *item,
uint32_t pn_space);
#endif

View File

@ -99,18 +99,18 @@ void ossl_quic_txpim_pkt_add_cfq_item(QUIC_TXPIM_PKT *fpkt,
*
* The chunks are sorted by (stream_id, start) in ascending order.
*/
const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(QUIC_TXPIM_PKT *fpkt);
const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(const QUIC_TXPIM_PKT *fpkt);
/*
* Returns the number of entries in the array returned by
* ossl_quic_txpim_pkt_get_chunks().
*/
size_t ossl_quic_txpim_pkt_get_num_chunks(QUIC_TXPIM_PKT *fpkt);
size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt);
/*
* Returns the number of QUIC_TXPIM_PKTs allocated by the given TXPIM that have
* yet to be returned to the TXPIM.
*/
size_t ossl_quic_txpim_get_in_use(QUIC_TXPIM *txpim);
size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim);
#endif

View File

@ -20,38 +20,38 @@ struct quic_cfq_item_ex_st {
uint64_t frame_type;
size_t encoded_len;
uint32_t priority, pn_space;
char state;
int state;
};
uint64_t ossl_quic_cfq_item_get_frame_type(QUIC_CFQ_ITEM *item)
uint64_t ossl_quic_cfq_item_get_frame_type(const QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
return ex->frame_type;
}
const unsigned char *ossl_quic_cfq_item_get_encoded(QUIC_CFQ_ITEM *item)
const unsigned char *ossl_quic_cfq_item_get_encoded(const QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
return ex->encoded;
}
size_t ossl_quic_cfq_item_get_encoded_len(QUIC_CFQ_ITEM *item)
size_t ossl_quic_cfq_item_get_encoded_len(const QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
return ex->encoded_len;
}
int ossl_quic_cfq_item_get_state(QUIC_CFQ_ITEM *item)
int ossl_quic_cfq_item_get_state(const QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
return ex->state;
}
uint32_t ossl_quic_cfq_item_get_pn_space(QUIC_CFQ_ITEM *item)
uint32_t ossl_quic_cfq_item_get_pn_space(const QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
@ -161,6 +161,7 @@ static void list_insert_sorted(QUIC_CFQ_ITEM_LIST *l, QUIC_CFQ_ITEM_EX *n,
QUIC_CFQ *ossl_quic_cfq_new(void)
{
QUIC_CFQ *cfq = OPENSSL_zalloc(sizeof(*cfq));
if (cfq == NULL)
return NULL;
@ -297,6 +298,7 @@ void ossl_quic_cfq_mark_lost(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item,
void ossl_quic_cfq_release(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;
switch (ex->state) {
case QUIC_CFQ_STATE_NEW:
list_remove(&cfq->new_list, ex);
@ -314,19 +316,20 @@ void ossl_quic_cfq_release(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item)
}
}
QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(QUIC_CFQ *cfq, uint32_t pn_space)
QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(const QUIC_CFQ *cfq,
uint32_t pn_space)
{
QUIC_CFQ_ITEM_EX *item = cfq->new_list.head;
for (; item != NULL && item->pn_space != pn_space; item = item->next);
if (item == NULL)
return NULL; /* ubsan */
return NULL;
return &item->public;
}
QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(QUIC_CFQ_ITEM *item,
QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(const QUIC_CFQ_ITEM *item,
uint32_t pn_space)
{
QUIC_CFQ_ITEM_EX *ex = (QUIC_CFQ_ITEM_EX *)item;

View File

@ -34,6 +34,7 @@ struct quic_txpim_st {
QUIC_TXPIM *ossl_quic_txpim_new(void)
{
QUIC_TXPIM *txpim = OPENSSL_zalloc(sizeof(*txpim));
if (txpim == NULL)
return NULL;
@ -198,7 +199,7 @@ static int compare(const void *a, const void *b)
return 0;
}
const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(QUIC_TXPIM_PKT *fpkt)
const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(const QUIC_TXPIM_PKT *fpkt)
{
QUIC_TXPIM_PKT_EX *ex = (QUIC_TXPIM_PKT_EX *)fpkt;
@ -214,14 +215,14 @@ const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(QUIC_TXPIM_PKT *fpkt)
return ex->chunks;
}
size_t ossl_quic_txpim_pkt_get_num_chunks(QUIC_TXPIM_PKT *fpkt)
size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt)
{
QUIC_TXPIM_PKT_EX *ex = (QUIC_TXPIM_PKT_EX *)fpkt;
return ex->num_chunks;
}
size_t ossl_quic_txpim_get_in_use(QUIC_TXPIM *txpim)
size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim)
{
return txpim->in_use;
}

View File

@ -43,7 +43,7 @@ static const uint64_t ref_frame_type[] = {
OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID,
};
static const uint32_t expect[QUIC_PN_SPACE_NUM][11] = {
@ -123,8 +123,8 @@ static int test_cfq(void)
QUIC_CFQ_STATE_NEW)
|| !TEST_uint_eq(ossl_quic_cfq_item_get_pn_space(item),
ref_pn_space[i])
|| !TEST_uint_eq(ossl_quic_cfq_item_get_frame_type(item),
ref_frame_type[i])
|| !TEST_uint64_t_eq(ossl_quic_cfq_item_get_frame_type(item),
ref_frame_type[i])
|| !TEST_ptr_eq(ossl_quic_cfq_item_get_encoded(item),
ref_buf + i)
|| !TEST_size_t_eq(ossl_quic_cfq_item_get_encoded_len(item),