]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: quic: fill whole Tx buffer if needed
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 5 Jun 2024 15:26:14 +0000 (17:26 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 12 Jun 2024 16:05:40 +0000 (18:05 +0200)
Previously, packets encoding was stopped as soon as buffer room left is
less than UDP MTU. This is suboptimal if the next packet would be
smaller than that.

To improve this, only check if there is at least enough room for the
mandatory packet header. qc_build_pkt() would ensure there is thus
responsible to return QC_BUILD_PKT_ERR_BUFROOM as soon as buffer left is
insufficient to stop packets encoding. An extra check is added to ensure
end pointer would never exceed buffer end.

This should not have any significant impact on the performance. However,
this renders the code intention clearer.

src/quic_tx.c

index 84e9f3267faefded7f73c2720d4556993ac7234a..a21e61d54f124bad805bdd2d7db092510b44f7ad 100644 (file)
@@ -532,8 +532,7 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
                 * Each datagram is prepended with its length followed by the address
                 * of the first packet in the datagram (QUIC_DGRAM_HEADLEN).
                 */
-               while ((!cc && b_contig_space(buf) >= (int)qc->path->mtu + QUIC_DGRAM_HEADLEN) ||
-                       (cc && b_contig_space(buf) >= QUIC_MIN_CC_PKTSIZE + QUIC_DGRAM_HEADLEN) || prv_pkt) {
+               while (b_contig_space(buf) > QUIC_DGRAM_HEADLEN || prv_pkt) {
                        int err, probe, must_ack;
                        enum quic_pkt_type pkt_type;
                        struct quic_tx_packet *cur_pkt;
@@ -562,18 +561,21 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
                                break;
                        }
 
-                       if (!prv_pkt) {
-                               /* Leave room for the datagram header */
+                       /* On starting a new datagram, calculate end max offset
+                        * to stay under MTU limit.
+                        */
+                       if (!first_pkt) {
                                pos += QUIC_DGRAM_HEADLEN;
-                               if (cc) {
+                               if (cc)
                                        end = pos + QUIC_MIN_CC_PKTSIZE;
-                               }
-                               else if (!quic_peer_validated_addr(qc) && qc_is_listener(qc)) {
+                               else if (!quic_peer_validated_addr(qc) && qc_is_listener(qc))
                                        end = pos + QUIC_MIN(qc->path->mtu, quic_may_send_bytes(qc));
-                               }
-                               else {
+                               else
                                        end = pos + qc->path->mtu;
-                               }
+
+                               /* Ensure end does not go beyond buffer */
+                               if (end > (unsigned char *)b_wrap(buf))
+                                       end = (unsigned char *)b_wrap(buf);
                        }
 
                        /* RFC 9000 14.1 Initial datagram size