]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-quic: complete functions to detect stream type
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 7 Feb 2022 10:44:17 +0000 (11:44 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 4 Mar 2022 16:00:12 +0000 (17:00 +0100)
Improve the functions used to detect the stream characteristics :
uni/bidirectional and local/remote initiated.

Most notably, these functions are now designed to work transparently for
a MUX in the frontend or backend side. For this, we use the connection
to determine the current MUX side. This will be useful if QUIC is
implemented on the server side.

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

index 4e588bc3e5f755c124085437a1be8fd7d6a8f62a..56bbad5db7f800db9bf9b1df50113bc784a98705 100644 (file)
@@ -7,6 +7,7 @@
 #endif
 
 #include <haproxy/api.h>
+#include <haproxy/connection.h>
 #include <haproxy/mux_quic-t.h>
 #include <haproxy/xprt_quic-t.h>
 
@@ -42,12 +43,26 @@ static inline enum qcs_type qcs_id_type(uint64_t id)
        return id & QCS_ID_TYPE_MASK;
 }
 
-/* Return 1 if the stream with <id> as ID attached to <qcc> connection
- * has been locally initiated, 0 if not.
- */
-static inline int qc_local_stream_id(struct qcc *qcc, uint64_t id)
+/* Return true if stream has been opened locally. */
+static inline int quic_stream_is_local(struct qcc *qcc, uint64_t id)
+{
+       return conn_is_back(qcc->conn) == !(id & QCS_ID_SRV_INTIATOR_BIT);
+}
+
+/* Return true if stream is opened by peer. */
+static inline int quic_stream_is_remote(struct qcc *qcc, uint64_t id)
+{
+       return !quic_stream_is_local(qcc, id);
+}
+
+static inline int quic_stream_is_uni(uint64_t id)
+{
+       return id & QCS_ID_DIR_BIT;
+}
+
+static inline int quic_stream_is_bidi(uint64_t id)
 {
-       return id & QCS_ID_SRV_INTIATOR_BIT;
+       return !quic_stream_is_uni(id);
 }
 
 struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id);
index c16e3d2c6124d7c6895cd90e0419f0a50422a076..7c52ac0136840f18d8c78a1eaa96e17cb4ebd139 100644 (file)
@@ -113,7 +113,7 @@ struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id)
        strm_type = id & QCS_ID_TYPE_MASK;
        sub_id = id >> QCS_ID_TYPE_SHIFT;
        strm_node = NULL;
-       if (qc_local_stream_id(qcc, id)) {
+       if (quic_stream_is_local(qcc, id)) {
                /* Local streams: this stream must be already opened. */
                strm_node = eb64_lookup(&qcc->streams_by_id, id);
                if (!strm_node) {