diff --git a/Makefile b/Makefile index 0a6b3a9ec..30616c196 100644 --- a/Makefile +++ b/Makefile @@ -645,7 +645,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 index 000000000..776725d71 --- /dev/null +++ b/include/haproxy/qmux_http.h @@ -0,0 +1,14 @@ +#ifndef _HAPROXY_MUX_QUIC_HTTP_H +#define _HAPROXY_MUX_QUIC_HTTP_H + +#ifdef USE_QUIC + +#include +#include + +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 */ diff --git a/src/mux_quic.c b/src/mux_quic.c index 742a2ad0b..c65b76358 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -5,10 +5,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -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_http_rcv_buf(qcs, buf, count, &fin); - 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: 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 index 000000000..bf53df039 --- /dev/null +++ b/src/qmux_http.c @@ -0,0 +1,63 @@ +#include + +#include +#include +#include + +/* QUIC MUX rcv_buf operation using HTX data. Received data from stream + * will be transferred as HTX in . Output buffer is expected to be of + * length . 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; +}