Skip to content

Commit

Permalink
[~] validate cid after receiving a RC frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Kulsk committed Apr 23, 2024
1 parent 6587daa commit e847b52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/transport/xqc_cid.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ xqc_int_t
xqc_cid_switch_to_next_state(xqc_cid_set_t *cid_set, xqc_cid_inner_t *cid, xqc_cid_state_t next_state)
{
if (xqc_cid_in_cid_set(cid_set, &cid->cid) == NULL) {
return XQC_OK;
return -XQC_ECONN_CID_NOT_FOUND;
}

xqc_cid_state_t current_state = cid->state;
Expand All @@ -259,7 +259,7 @@ xqc_cid_switch_to_next_state(xqc_cid_set_t *cid_set, xqc_cid_inner_t *cid, xqc_c
return XQC_OK;

} else if (current_state > next_state) {
return XQC_OK;
return -XQC_ECID_STATE;
}

/* current_state < next_state */
Expand Down Expand Up @@ -341,3 +341,19 @@ xqc_get_inner_cid_by_seq(xqc_cid_set_t *cid_set, uint64_t seq_num)

return NULL;
}

xqc_bool_t
xqc_validate_retire_cid_frame(xqc_cid_set_t *cid_set, xqc_cid_inner_t *cid)
{
/* maybe retired already */
if (xqc_cid_in_cid_set(cid_set, &cid->cid) == NULL) {
return XQC_FALSE;
}

/* the cid is retired already */
if (cid->state >= XQC_CID_RETIRED) {
return XQC_FALSE;
}

return XQC_TRUE;
}
1 change: 1 addition & 0 deletions src/transport/xqc_cid.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ xqc_cid_inner_t *xqc_cid_in_cid_set(const xqc_cid_set_t *cid_set, xqc_cid_t *cid
xqc_int_t xqc_cid_switch_to_next_state(xqc_cid_set_t *cid_set, xqc_cid_inner_t *cid, xqc_cid_state_t state);
xqc_int_t xqc_get_unused_cid(xqc_cid_set_t *cid_set, xqc_cid_t *cid);

xqc_bool_t xqc_validate_retire_cid_frame(xqc_cid_set_t *cid_set, xqc_cid_inner_t *cid);

unsigned char *xqc_sr_token_str(const char *sr_token);

Expand Down
7 changes: 7 additions & 0 deletions src/transport/xqc_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,13 @@ xqc_process_retire_conn_id_frame(xqc_connection_t *conn, xqc_packet_in_t *packet
return XQC_OK;
}

/* skip if cid not available anymore */
if (!xqc_validate_retire_cid_frame(&conn->scid_set.cid_set, inner_cid)) {
xqc_log(conn->log, XQC_LOG_DEBUG, "|cid not valid any more|seq_num:%ui",
seq_num);
return XQC_OK;
}

if (XQC_OK == xqc_cid_is_equal(&inner_cid->cid, &packet_in->pi_pkt.pkt_dcid)) {
/*
* The sequence number specified in a RETIRE_CONNECTION_ID frame MUST NOT refer to
Expand Down

0 comments on commit e847b52

Please sign in to comment.