Skip to content

Commit 540408f

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 so that each newly parsed frame is dynamically allocated using existing qc_frm_alloc() / qc_frm_free(). This commit does bring any functional changes. However, it will be useful to extend packet parsing. In particular, it will be necessary to support several parsing iteration with saved frames instances.
1 parent efbb67f commit 540408f

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;
772772
const unsigned char *pos, *end;
773773
int fast_retrans = 0;
774774

@@ -792,12 +792,18 @@ 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+
frm = qc_frm_alloc(0);
796+
if (!frm) {
797+
TRACE_ERROR("cannot allocate frame", QUIC_EV_CONN_PRSHPKT, qc);
798+
goto err;
799+
}
800+
801+
if (!qc_parse_frm(frm, pkt, &pos, end, qc)) {
796802
// trace already emitted by function above
797803
goto err;
798804
}
799805

800-
switch (frm.type) {
806+
switch (frm->type) {
801807
case QUIC_FT_PADDING:
802808
break;
803809
case QUIC_FT_PING:
@@ -808,7 +814,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
808814
unsigned int rtt_sample;
809815
rtt_sample = UINT_MAX;
810816

811-
if (!qc_parse_ack_frm(qc, &frm, qel, &rtt_sample, &pos, end)) {
817+
if (!qc_parse_ack_frm(qc, frm, qel, &rtt_sample, &pos, end)) {
812818
// trace already emitted by function above
813819
goto err;
814820
}
@@ -818,21 +824,21 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
818824

819825
ack_delay = !quic_application_pktns(qel->pktns, qc) ? 0 :
820826
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));
827+
MS_TO_TICKS(QUIC_MIN(quic_ack_delay_ms(&frm->ack, qc), qc->max_ack_delay)) :
828+
MS_TO_TICKS(quic_ack_delay_ms(&frm->ack, qc));
823829
quic_loss_srtt_update(&qc->path->loss, rtt_sample, ack_delay, qc);
824830
}
825831
break;
826832
}
827833
case QUIC_FT_RESET_STREAM:
828834
if (qc->mux_state == QC_MUX_READY) {
829-
struct qf_reset_stream *rs_frm = &frm.reset_stream;
835+
struct qf_reset_stream *rs_frm = &frm->reset_stream;
830836
qcc_recv_reset_stream(qc->qcc, rs_frm->id, rs_frm->app_error_code, rs_frm->final_size);
831837
}
832838
break;
833839
case QUIC_FT_STOP_SENDING:
834840
{
835-
struct qf_stop_sending *ss_frm = &frm.stop_sending;
841+
struct qf_stop_sending *ss_frm = &frm->stop_sending;
836842
if (qc->mux_state == QC_MUX_READY) {
837843
if (qcc_recv_stop_sending(qc->qcc, ss_frm->id,
838844
ss_frm->app_error_code)) {
@@ -843,17 +849,17 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
843849
break;
844850
}
845851
case QUIC_FT_CRYPTO:
846-
if (!qc_handle_crypto_frm(qc, &frm.crypto, pkt, qel, &fast_retrans))
852+
if (!qc_handle_crypto_frm(qc, &frm->crypto, pkt, qel, &fast_retrans))
847853
goto err;
848854
break;
849855
case QUIC_FT_NEW_TOKEN:
850856
/* TODO */
851857
break;
852858
case QUIC_FT_STREAM_8 ... QUIC_FT_STREAM_F:
853859
{
854-
struct qf_stream *strm_frm = &frm.stream;
860+
struct qf_stream *strm_frm = &frm->stream;
855861
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;
862+
const char fin = frm->type & QUIC_STREAM_FRAME_TYPE_FIN_BIT;
857863

858864
/* The upper layer may not be allocated. */
859865
if (qc->mux_state != QC_MUX_READY) {
@@ -887,13 +893,13 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
887893
}
888894
case QUIC_FT_MAX_DATA:
889895
if (qc->mux_state == QC_MUX_READY) {
890-
struct qf_max_data *md_frm = &frm.max_data;
896+
struct qf_max_data *md_frm = &frm->max_data;
891897
qcc_recv_max_data(qc->qcc, md_frm->max_data);
892898
}
893899
break;
894900
case QUIC_FT_MAX_STREAM_DATA:
895901
if (qc->mux_state == QC_MUX_READY) {
896-
struct qf_max_stream_data *msd_frm = &frm.max_stream_data;
902+
struct qf_max_stream_data *msd_frm = &frm->max_stream_data;
897903
if (qcc_recv_max_stream_data(qc->qcc, msd_frm->id,
898904
msd_frm->max_stream_data)) {
899905
TRACE_ERROR("qcc_recv_max_stream_data() failed", QUIC_EV_CONN_PRSHPKT, qc);
@@ -923,7 +929,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
923929
{
924930
struct quic_connection_id *conn_id = NULL;
925931

926-
if (!qc_handle_retire_connection_id_frm(qc, &frm, &pkt->dcid, &conn_id))
932+
if (!qc_handle_retire_connection_id_frm(qc, frm, &pkt->dcid, &conn_id))
927933
goto err;
928934

929935
if (!conn_id)
@@ -951,7 +957,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
951957
case QUIC_FT_CONNECTION_CLOSE:
952958
case QUIC_FT_CONNECTION_CLOSE_APP:
953959
/* Increment the error counters */
954-
quic_conn_closed_err_count_inc(qc, &frm);
960+
quic_conn_closed_err_count_inc(qc, frm);
955961
if (!(qc->flags & QUIC_FL_CONN_DRAINING)) {
956962
TRACE_STATE("Entering draining state", QUIC_EV_CONN_PRSHPKT, qc);
957963
/* RFC 9000 10.2. Immediate Close:
@@ -990,6 +996,8 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
990996
/* Unknown frame type must be rejected by qc_parse_frm(). */
991997
ABORT_NOW();
992998
}
999+
1000+
qc_frm_free(qc, &frm);
9931001
}
9941002

9951003
if (fast_retrans && qc->iel && 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)