]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: simplify qc_parse_pkt_frms() return path
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 4 Nov 2024 17:17:01 +0000 (18:17 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 6 Nov 2024 13:28:14 +0000 (14:28 +0100)
Change qc_parse_pkt_frms() return path for normal and error cases. Most
notably, it allows to remove local variable ret as now return value is
hardcoded on normal and err label. This also allows to define a
different trace for error leaving code.

src/quic_rx.c

index 3eaf8704504061d6a7b38bd0a761fe3fff27d442..9e8bdec37b06b8b981495ebd7a16dbc70c4a0a77 100644 (file)
@@ -770,7 +770,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
 {
        struct quic_frame frm;
        const unsigned char *pos, *end;
-       int fast_retrans = 0, ret = 0;
+       int fast_retrans = 0;
 
        TRACE_ENTER(QUIC_EV_CONN_PRSHPKT, qc);
        /* Skip the AAD */
@@ -788,13 +788,13 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                 * a single QUIC packet and cannot span multiple packets.
                 */
                quic_set_connection_close(qc, quic_err_transport(QC_ERR_PROTOCOL_VIOLATION));
-               goto leave;
+               goto err;
        }
 
        while (pos < end) {
                if (!qc_parse_frm(&frm, pkt, &pos, end, qc)) {
                        // trace already emitted by function above
-                       goto leave;
+                       goto err;
                }
 
                switch (frm.type) {
@@ -810,7 +810,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
 
                        if (!qc_parse_ack_frm(qc, &frm, qel, &rtt_sample, &pos, end)) {
                                // trace already emitted by function above
-                               goto leave;
+                               goto err;
                        }
 
                        if (rtt_sample != UINT_MAX) {
@@ -837,14 +837,14 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                                if (qcc_recv_stop_sending(qc->qcc, ss_frm->id,
                                                          ss_frm->app_error_code)) {
                                        TRACE_ERROR("qcc_recv_stop_sending() failed", QUIC_EV_CONN_PRSHPKT, qc);
-                                       goto leave;
+                                       goto err;
                                }
                        }
                        break;
                }
                case QUIC_FT_CRYPTO:
                        if (!qc_handle_crypto_frm(qc, &frm.crypto, pkt, qel, &fast_retrans))
-                               goto leave;
+                               goto err;
                        break;
                case QUIC_FT_NEW_TOKEN:
                        /* TODO */
@@ -866,12 +866,12 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                                                if (!qc_h3_request_reject(qc, strm_frm->id)) {
                                                        TRACE_ERROR("error on request rejection", QUIC_EV_CONN_PRSHPKT, qc);
                                                        /* This packet will not be acknowledged */
-                                                       goto leave;
+                                                       goto err;
                                                }
                                        }
                                        else {
                                                /* This packet will not be acknowledged */
-                                               goto leave;
+                                               goto err;
                                        }
                                }
 
@@ -880,7 +880,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
 
                        if (!qc_handle_strm_frm(pkt, strm_frm, qc, fin)) {
                                TRACE_ERROR("qc_handle_strm_frm() failed", QUIC_EV_CONN_PRSHPKT, qc);
-                               goto leave;
+                               goto err;
                        }
 
                        break;
@@ -897,7 +897,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                                if (qcc_recv_max_stream_data(qc->qcc, msd_frm->id,
                                                              msd_frm->max_stream_data)) {
                                        TRACE_ERROR("qcc_recv_max_stream_data() failed", QUIC_EV_CONN_PRSHPKT, qc);
-                                       goto leave;
+                                       goto err;
                                }
                        }
                        break;
@@ -924,7 +924,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                        struct quic_connection_id *conn_id = NULL;
 
                        if (!qc_handle_retire_connection_id_frm(qc, &frm, &pkt->dcid, &conn_id))
-                               goto leave;
+                               goto err;
 
                        if (!conn_id)
                                break;
@@ -981,7 +981,7 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
                                 * error of type PROTOCOL_VIOLATION.
                                 */
                                quic_set_connection_close(qc, quic_err_transport(QC_ERR_PROTOCOL_VIOLATION));
-                               goto leave;
+                               goto err;
                        }
 
                        qc->state = QUIC_HS_ST_CONFIRMED;
@@ -1020,10 +1020,12 @@ static int qc_parse_pkt_frms(struct quic_conn *qc, struct quic_rx_packet *pkt,
            }
        }
 
-       ret = 1;
- leave:
        TRACE_LEAVE(QUIC_EV_CONN_PRSHPKT, qc);
-       return ret;
+       return 1;
+
+ err:
+       TRACE_DEVEL("leaving on error", QUIC_EV_CONN_PRSHPKT, qc);
+       return 0;
 }
 
 /* Detect the value of the spin bit to be used. */