Skip to content

Commit 190fc97

Browse files
committed
MINOR: quic: use dynamically allocated frame on parsing
qc_parse_pkt_frms() is the function responsible to parse a received QUIC packet. Payload is decoded and splitted into individual frames which are then handled individually. Previously, frame was used as locally stack allocated. Change this to work on a dynamically allocated frame. This commit does bring any functional changes. However, it will be useful to extend packet parsing. In particular, it will be necessary to save some frames during parsing to reparse them after the others.
1 parent 498a99a commit 190fc97

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/quic_rx.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ static inline unsigned int quic_ack_delay_ms(struct qf_ack *ack_frm,
768768
static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
769769
struct quic_enc_level *qel)
770770
{
771-
struct quic_frame frm;
771+
struct quic_frame *frm = NULL;
772772
const unsigned char *pos, *end;
773773
int fast_retrans = 0;
774774

@@ -792,12 +792,17 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
792792
}
793793

794794
while (pos < end) {
795-
if (!qc_parse_frm(&frm, pkt, &pos, end, qc)) {
795+
if (!frm && !(frm = qc_frm_alloc(0))) {
796+
TRACE_ERROR("cannot allocate frame", QUIC_EV_CONN_PRSHPKT, qc);
797+
goto err;
798+
}
799+
800+
if (!qc_parse_frm(frm, pkt, &pos, end, qc)) {
796801
// trace already emitted by function above
797802
goto err;
798803
}
799804

800-
switch (frm.type) {
805+
switch (frm->type) {
801806
case QUIC_FT_PADDING:
802807
break;
803808
case QUIC_FT_PING:
@@ -808,7 +813,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
808813
unsigned int rtt_sample;
809814
rtt_sample = UINT_MAX;
810815

811-
if (!qc_parse_ack_frm(qc, &frm, qel, &rtt_sample, &pos, end)) {
816+
if (!qc_parse_ack_frm(qc, frm, qel, &rtt_sample, &pos, end)) {
812817
// trace already emitted by function above
813818
goto err;
814819
}
@@ -818,21 +823,21 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
818823

819824
ack_delay = !quic_application_pktns(qel->pktns, qc) ? 0 :
820825
qc->state >= QUIC_HS_ST_CONFIRMED ?
821-
MS_TO_TICKS(QUIC_MIN(quic_ack_delay_ms(&frm.ack, qc), qc->max_ack_delay)) :
822-
MS_TO_TICKS(quic_ack_delay_ms(&frm.ack, qc));
826+
MS_TO_TICKS(QUIC_MIN(quic_ack_delay_ms(&frm->ack, qc), qc->max_ack_delay)) :
827+
MS_TO_TICKS(quic_ack_delay_ms(&frm->ack, qc));
823828
quic_loss_srtt_update(&qc->path->loss, rtt_sample, ack_delay, qc);
824829
}
825830
break;
826831
}
827832
case QUIC_FT_RESET_STREAM:
828833
if (qc->mux_state == QC_MUX_READY) {
829-
struct qf_reset_stream *rs_frm = &frm.reset_stream;
834+
struct qf_reset_stream *rs_frm = &frm->reset_stream;
830835
qcc_recv_reset_stream(qc->qcc, rs_frm->id, rs_frm->app_error_code, rs_frm->final_size);
831836
}
832837
break;
833838
case QUIC_FT_STOP_SENDING:
834839
{
835-
struct qf_stop_sending *ss_frm = &frm.stop_sending;
840+
struct qf_stop_sending *ss_frm = &frm->stop_sending;
836841
if (qc->mux_state == QC_MUX_READY) {
837842
if (qcc_recv_stop_sending(qc->qcc, ss_frm->id,
838843
ss_frm->app_error_code)) {
@@ -843,17 +848,17 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
843848
break;
844849
}
845850
case QUIC_FT_CRYPTO:
846-
if (!qc_handle_crypto_frm(qc, &frm.crypto, pkt, qel, &fast_retrans))
851+
if (!qc_handle_crypto_frm(qc, &frm->crypto, pkt, qel, &fast_retrans))
847852
goto err;
848853
break;
849854
case QUIC_FT_NEW_TOKEN:
850855
/* TODO */
851856
break;
852857
case QUIC_FT_STREAM_8 ... QUIC_FT_STREAM_F:
853858
{
854-
struct qf_stream *strm_frm = &frm.stream;
859+
struct qf_stream *strm_frm = &frm->stream;
855860
unsigned nb_streams = qc->rx.strms[qcs_id_type(strm_frm->id)].nb_streams;
856-
const char fin = frm.type & QUIC_STREAM_FRAME_TYPE_FIN_BIT;
861+
const char fin = frm->type & QUIC_STREAM_FRAME_TYPE_FIN_BIT;
857862

858863
/* The upper layer may not be allocated. */
859864
if (qc->mux_state != QC_MUX_READY) {
@@ -887,13 +892,13 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
887892
}
888893
case QUIC_FT_MAX_DATA:
889894
if (qc->mux_state == QC_MUX_READY) {
890-
struct qf_max_data *md_frm = &frm.max_data;
895+
struct qf_max_data *md_frm = &frm->max_data;
891896
qcc_recv_max_data(qc->qcc, md_frm->max_data);
892897
}
893898
break;
894899
case QUIC_FT_MAX_STREAM_DATA:
895900
if (qc->mux_state == QC_MUX_READY) {
896-
struct qf_max_stream_data *msd_frm = &frm.max_stream_data;
901+
struct qf_max_stream_data *msd_frm = &frm->max_stream_data;
897902
if (qcc_recv_max_stream_data(qc->qcc, msd_frm->id,
898903
msd_frm->max_stream_data)) {
899904
TRACE_ERROR("qcc_recv_max_stream_data() failed", QUIC_EV_CONN_PRSHPKT, qc);
@@ -923,7 +928,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
923928
{
924929
struct quic_connection_id *conn_id = NULL;
925930

926-
if (!qc_handle_retire_connection_id_frm(qc, &frm, &pkt->dcid, &conn_id))
931+
if (!qc_handle_retire_connection_id_frm(qc, frm, &pkt->dcid, &conn_id))
927932
goto err;
928933

929934
if (!conn_id)
@@ -951,7 +956,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
951956
case QUIC_FT_CONNECTION_CLOSE:
952957
case QUIC_FT_CONNECTION_CLOSE_APP:
953958
/* Increment the error counters */
954-
quic_conn_closed_err_count_inc(qc, &frm);
959+
quic_conn_closed_err_count_inc(qc, frm);
955960
if (!(qc->flags & QUIC_FL_CONN_DRAINING)) {
956961
TRACE_STATE("Entering draining state", QUIC_EV_CONN_PRSHPKT, qc);
957962
/* RFC 9000 10.2. Immediate Close:
@@ -992,6 +997,9 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
992997
}
993998
}
994999

1000+
if (frm)
1001+
qc_frm_free(qc, &frm);
1002+
9951003
if (fast_retrans && qc->iel && qc->hel) {
9961004
struct quic_enc_level *iqel = qc->iel;
9971005
struct quic_enc_level *hqel = qc->hel;
@@ -1024,6 +1032,8 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
10241032
return 1;
10251033

10261034
err:
1035+
if (frm)
1036+
qc_frm_free(qc, &frm);
10271037
TRACE_DEVEL("leaving on error", QUIC_EV_CONN_PRSHPKT, qc);
10281038
return 0;
10291039
}

0 commit comments

Comments
 (0)