]> git.kaiwu.me - haproxy.git/commitdiff
CLEANUP: quic: use QUIC_PACKET_PN_MAXLEN instead of the magic 4
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 4 Nov 2026 16:42:51 +0000 (17:42 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 5 Nov 2026 08:58:36 +0000 (09:58 +0100)
Both fast retransmission functions account for the packet number increase
when comparing the size of the packets to be retransmitted with the
anti-amplification limit. They use a plain 4 for this, while
quic_conn-t.h defines QUIC_PACKET_PN_MAXLEN for this exact purpose, as
already used in quic_tx.c for the header protection sample.

Replace the magic value in qc_prep_fast_retrans() and
qc_prep_hdshk_fast_retrans().

No functional change, no need to backport.

src/quic_retransmit.c

index b9509527975a1a8cf26e7a6d5ad50fe8b213ab08..7082984dde4bf98f1b36a46eac010181a316e0ec 100644 (file)
@@ -180,7 +180,7 @@ void qc_prep_fast_retrans(struct quic_conn *qc,
         * packet size is the packet number. And the maximum increase is 4 bytes.
         */
        if (!quic_peer_validated_addr(qc) && !qc_is_back(qc) &&
-           pkt->len + 4 > quic_may_send_bytes(qc)) {
+           pkt->len + QUIC_PACKET_PN_MAXLEN > quic_may_send_bytes(qc)) {
                qc->flags |= QUIC_FL_CONN_ANTI_AMPLIFICATION_REACHED;
                TRACE_PROTO("anti-amplification limit would be reached", QUIC_EV_CONN_SPPKTS, qc, pkt);
                goto leave;
@@ -244,11 +244,11 @@ void qc_prep_hdshk_fast_retrans(struct quic_conn *qc,
         * packet size is the packet number. And the maximum increase is 4 bytes.
         */
        if (!quic_peer_validated_addr(qc) && !qc_is_back(qc)) {
-               size_t dglen = pkt->len + 4;
+               size_t dglen = pkt->len + QUIC_PACKET_PN_MAXLEN;
                size_t may_send;
 
                may_send = quic_may_send_bytes(qc);
-               dglen += pkt->next ? pkt->next->len + 4 : 0;
+               dglen += pkt->next ? pkt->next->len + QUIC_PACKET_PN_MAXLEN : 0;
                if (dglen > may_send) {
                        qc->flags |= QUIC_FL_CONN_ANTI_AMPLIFICATION_REACHED;
                        TRACE_PROTO("anti-amplification limit would be reached", QUIC_EV_CONN_SPPKTS, qc, pkt);