]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: mux-quic: export HTTP related function in a dedicated file
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 19 Sep 2022 15:02:28 +0000 (17:02 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 20 Sep 2022 13:35:23 +0000 (15:35 +0200)
Extract function dealing with HTX outside of MUX QUIC. For the moment,
only rcv_buf stream operation is concerned.

The main objective is to be able to support both TCP and HTTP proxy mode
with a common base and add specialized modules on top of it.

This should be backported up to 2.6.

Makefile
include/haproxy/qmux_http.h [new file with mode: 0644]
src/mux_quic.c
src/qmux_http.c [new file with mode: 0644]

index 08d080473c9b3cfe82e6570fdcfe4ef8f8b9e7c5..12a3c142f5e4d6dbe6105b759ff67a0557910932 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -646,7 +646,7 @@ OPTIONS_OBJS += src/quic_sock.o src/proto_quic.o src/xprt_quic.o src/quic_tls.o
                 src/cbuf.o src/qpack-dec.o src/qpack-tbl.o src/h3.o src/qpack-enc.o \
                 src/hq_interop.o src/cfgparse-quic.o src/quic_loss.o \
                 src/quic_tp.o src/quic_stream.o src/quic_stats.o src/h3_stats.o \
-                src/quic_cc_cubic.o src/qmux_trace.o
+                src/quic_cc_cubic.o src/qmux_trace.o src/qmux_http.o
 endif
 
 ifneq ($(USE_LUA),)
diff --git a/include/haproxy/qmux_http.h b/include/haproxy/qmux_http.h
new file mode 100644 (file)
index 0000000..776725d
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _HAPROXY_MUX_QUIC_HTTP_H
+#define _HAPROXY_MUX_QUIC_HTTP_H
+
+#ifdef USE_QUIC
+
+#include <haproxy/buf.h>
+#include <haproxy/mux_quic.h>
+
+size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+                        char *fin);
+
+#endif /* USE_QUIC */
+
+#endif /* _HAPROXY_MUX_QUIC_HTTP_H */
index 44f449a9f7322c28ff0041960cd08c759deba8c0..ef113474393bffb8b23f9ba363dd6b2b24d6284d 100644 (file)
@@ -5,10 +5,10 @@
 #include <haproxy/api.h>
 #include <haproxy/connection.h>
 #include <haproxy/dynbuf.h>
-#include <haproxy/htx.h>
 #include <haproxy/list.h>
 #include <haproxy/ncbuf.h>
 #include <haproxy/pool.h>
+#include <haproxy/qmux_http.h>
 #include <haproxy/qmux_trace.h>
 #include <haproxy/quic_stream.h>
 #include <haproxy/quic_tp-t.h>
@@ -2062,49 +2062,13 @@ static size_t qc_rcv_buf(struct stconn *sc, struct buffer *buf,
                          size_t count, int flags)
 {
        struct qcs *qcs = __sc_mux_strm(sc);
-       struct htx *qcs_htx = NULL;
-       struct htx *cs_htx = NULL;
        size_t ret = 0;
        char fin = 0;
 
        TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
 
-       qcs_htx = htx_from_buf(&qcs->rx.app_buf);
-       if (htx_is_empty(qcs_htx)) {
-               /* Set buffer data to 0 as HTX is empty. */
-               htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-               goto end;
-       }
-
-       ret = qcs_htx->data;
-
-       cs_htx = htx_from_buf(buf);
-       if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
-               /* EOM will be copied to cs_htx via b_xfer(). */
-               if (qcs_htx->flags & HTX_FL_EOM)
-                       fin = 1;
-
-               htx_to_buf(cs_htx, buf);
-               htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-               b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
-               goto end;
-       }
+       ret = qcs_http_rcv_buf(qcs, buf, count, &fin);
 
-       htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
-       BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
-
-       /* Copy EOM from src to dst buffer if all data copied. */
-       if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
-               cs_htx->flags |= HTX_FL_EOM;
-               fin = 1;
-       }
-
-       cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
-       htx_to_buf(cs_htx, buf);
-       htx_to_buf(qcs_htx, &qcs->rx.app_buf);
-       ret -= qcs_htx->data;
-
- end:
        if (b_data(&qcs->rx.app_buf)) {
                se_fl_set(qcs->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
        }
diff --git a/src/qmux_http.c b/src/qmux_http.c
new file mode 100644 (file)
index 0000000..bf53df0
--- /dev/null
@@ -0,0 +1,63 @@
+#include <haproxy/qmux_http.h>
+
+#include <haproxy/api-t.h>
+#include <haproxy/htx.h>
+#include <haproxy/qmux_trace.h>
+
+/* QUIC MUX rcv_buf operation using HTX data. Received data from stream <qcs>
+ * will be transferred as HTX in <buf>. Output buffer is expected to be of
+ * length <count>. <fin> will be set to signal the last data to receive on this
+ * stream.
+ *
+ * Return the size in bytes of transferred data.
+ */
+size_t qcs_http_rcv_buf(struct qcs *qcs, struct buffer *buf, size_t count,
+                        char *fin)
+{
+       struct htx *qcs_htx = NULL;
+       struct htx *cs_htx = NULL;
+       size_t ret = 0;
+
+       TRACE_ENTER(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
+
+       *fin = 0;
+       qcs_htx = htx_from_buf(&qcs->rx.app_buf);
+       if (htx_is_empty(qcs_htx)) {
+               /* Set buffer data to 0 as HTX is empty. */
+               htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+               goto end;
+       }
+
+       ret = qcs_htx->data;
+
+       cs_htx = htx_from_buf(buf);
+       if (htx_is_empty(cs_htx) && htx_used_space(qcs_htx) <= count) {
+               /* EOM will be copied to cs_htx via b_xfer(). */
+               if (qcs_htx->flags & HTX_FL_EOM)
+                       *fin = 1;
+
+               htx_to_buf(cs_htx, buf);
+               htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+               b_xfer(buf, &qcs->rx.app_buf, b_data(&qcs->rx.app_buf));
+               goto end;
+       }
+
+       htx_xfer_blks(cs_htx, qcs_htx, count, HTX_BLK_UNUSED);
+       BUG_ON(qcs_htx->flags & HTX_FL_PARSING_ERROR);
+
+       /* Copy EOM from src to dst buffer if all data copied. */
+       if (htx_is_empty(qcs_htx) && (qcs_htx->flags & HTX_FL_EOM)) {
+               cs_htx->flags |= HTX_FL_EOM;
+               *fin = 1;
+       }
+
+       cs_htx->extra = qcs_htx->extra ? (qcs_htx->data + qcs_htx->extra) : 0;
+       htx_to_buf(cs_htx, buf);
+       htx_to_buf(qcs_htx, &qcs->rx.app_buf);
+       ret -= qcs_htx->data;
+
+ end:
+       TRACE_LEAVE(QMUX_EV_STRM_RECV, qcs->qcc->conn, qcs);
+
+       return ret;
+}