]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux_quic: limit avail_streams() to 2^62
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 15 Apr 2026 14:32:48 +0000 (16:32 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 17 Apr 2026 09:36:01 +0000 (11:36 +0200)
QUIC streams ID are encoded as 62-bit integer and cannot reuse an ID
within a connection. This is necessary to take into account this
limitation for backend connections.

This patch implements this via qmux_avail_streams() callback. In the
case where the connection is approaching the encoding limit, reduce the
advertised value until the limit is reached. Note that this is very
unlikely to happen as the value is pretty high.

This should be backported up to 3.3.

include/haproxy/mux_quic.h
src/mux_quic.c

index 2c808629781f021bbf905cfc798ad330f113d3e0..0ab083018e51720c421c0160c8166bf29b291f68 100644 (file)
@@ -62,6 +62,9 @@ static inline int qmux_stream_rx_bufsz(void)
 /* This bit is set for unidirectional streams */
 #define QCS_ID_DIR_BIT           0x2
 
+/* Maximum bidirectional stream ID that a client can opened. */
+#define QCS_ID_MAX_STRM_CL_BIDI (QUIC_VARINT_8_BYTE_MAX - 3)
+
 static inline enum qcs_type qcs_id_type(uint64_t id)
 {
        return id & QCS_ID_TYPE_MASK;
index d0c84ccbe50f868c11a2330d829b0d266d7f78ed..0bd9327f08628e3b1bafa4f693da7c0eb2c024b4 100644 (file)
@@ -3212,18 +3212,21 @@ static int qmux_avail_streams(struct connection *conn)
 {
        struct server *srv = __objt_server(conn->target);
        struct qcc *qcc = conn->ctx;
-       int max_fctl, max_reuse = 0;
+       int ret, max_reuse = 0;
 
-       max_fctl = qcc_fctl_avail_streams(qcc, 1);
+       ret = qcc_fctl_avail_streams(qcc, 1);
 
        if (srv->max_reuse >= 0) {
                max_reuse = qcc->tot_sc <= srv->max_reuse ?
                  srv->max_reuse - qcc->tot_sc + 1: 0;
-               return MIN(max_fctl, max_reuse);
-       }
-       else {
-               return max_fctl;
+               ret = MIN(ret, max_reuse);
        }
+
+       /* Ensure we do not exceed the maximum usable stream ID. */
+       if (unlikely(ret > QCS_ID_MAX_STRM_CL_BIDI - qcc->next_bidi_l))
+               ret = QCS_ID_MAX_STRM_CL_BIDI - qcc->next_bidi_l;
+
+       return ret;
 }
 
 /* Returns the number of streams currently attached into <conn> connection.