Skip to content

Commit

Permalink
QUIC LCIDM: Minor updates in response to feedback
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22673)
  • Loading branch information
hlandau committed Dec 6, 2023
1 parent 2773749 commit 4c62c56
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions ssl/quic/quic_lcidm.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static void lcidm_delete_conn_lcid(QUIC_LCIDM *lcidm, QUIC_LCID *lcid_obj)
{
lh_QUIC_LCID_delete(lcidm->lcids, lcid_obj);
lh_QUIC_LCID_delete(lcid_obj->conn->lcids, lcid_obj);
assert(lcid_obj->conn->num_active_lcid > 0);
--lcid_obj->conn->num_active_lcid;
OPENSSL_free(lcid_obj);
}
Expand Down Expand Up @@ -311,6 +312,8 @@ static int lcidm_generate(QUIC_LCIDM *lcidm,
{
QUIC_LCIDM_CONN *conn;
QUIC_LCID key, *lcid_obj;
size_t i;
#define MAX_RETRIES 8

if ((conn = lcidm_upsert_conn(lcidm, opaque)) == NULL)
return 0;
Expand All @@ -319,12 +322,21 @@ static int lcidm_generate(QUIC_LCIDM *lcidm,
|| conn->next_seq_num > OSSL_QUIC_VLINT_MAX)
return 0;

if (!lcidm_generate_cid(lcidm, lcid_out))
return 0;

key.cid = *lcid_out;
if (lh_QUIC_LCID_retrieve(lcidm->lcids, &key) != NULL)
return 0;
i = 0;
do {
if (i++ >= MAX_RETRIES)
/*
* Too many retries; should not happen but if it does, don't loop
* endlessly.
*/
return 0;

if (!lcidm_generate_cid(lcidm, lcid_out))
return 0;

key.cid = *lcid_out;
/* If a collision occurs, retry. */
} while (lh_QUIC_LCID_retrieve(lcidm->lcids, &key) != NULL);

if ((lcid_obj = lcidm_conn_new_lcid(lcidm, conn, lcid_out)) == NULL)
return 0;
Expand Down

0 comments on commit 4c62c56

Please sign in to comment.