]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: mux-quic: clean up app ops callback definitions
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 7 Dec 2023 16:43:07 +0000 (17:43 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 11 Dec 2023 15:15:13 +0000 (16:15 +0100)
qcc_app_ops is a set of callbacks used to unify application protocol
running over QUIC. This commit introduces some changes to clarify its
API :
* write simple comment to reflect each callback purpose
* rename decode_qcs to rcv_buf as this name is more common and is
  similar to already existing snd_buf
* finalize is moved up as it is used during connection init stage

All these changes are ported to HTTP/3 layer. Also function comments
have been extended to highlight HTTP/3 special characteristics.

include/haproxy/mux_quic-t.h
src/h3.c
src/hq_interop.c
src/mux_quic.c

index abfc20a506ce611a31045aab965fa72c19c70524..543df319e6fe1efbabf44989dfe8375199942c85 100644 (file)
@@ -185,17 +185,35 @@ enum qcc_app_ops_close_side {
 
 /* QUIC application layer operations */
 struct qcc_app_ops {
+       /* Initialize <qcc> connection app context. */
        int (*init)(struct qcc *qcc);
+       /* Finish connection initialization if prelude required. */
+       int (*finalize)(void *ctx);
+
+       /* Initialize <qcs> stream app context or leave it to NULL if rejected. */
        int (*attach)(struct qcs *qcs, void *conn_ctx);
-       ssize_t (*decode_qcs)(struct qcs *qcs, struct buffer *b, int fin);
-       size_t (*snd_buf)(struct qcs *qcs, struct buffer *buf, size_t count);
+
+       /* Convert received HTTP payload to HTX. */
+       ssize_t (*rcv_buf)(struct qcs *qcs, struct buffer *b, int fin);
+
+       /* Convert HTX to HTTP payload for sending. */
+       size_t (*snd_buf)(struct qcs *qcs, struct buffer *b, size_t count);
+
+       /* Negotiate and commit fast-forward data from opposite MUX. */
        size_t (*nego_ff)(struct qcs *qcs, size_t count);
        size_t (*done_ff)(struct qcs *qcs);
+
+       /* Notify about <qcs> stream closure. */
        int (*close)(struct qcs *qcs, enum qcc_app_ops_close_side side);
+       /* Free <qcs> stream app context. */
        void (*detach)(struct qcs *qcs);
-       int (*finalize)(void *ctx);
-       void (*shutdown)(void *ctx);                    /* Close a connection. */
+
+       /* Perform graceful shutdown. */
+       void (*shutdown)(void *ctx);
+       /* Free connection app context. */
        void (*release)(void *ctx);
+
+       /* Increment app counters on CONNECTION_CLOSE_APP reception. */
        void (*inc_err_cnt)(void *ctx, int err_code);
 };
 
index ba488f26f7c3743c2210e1ae879b8fc59c865f0a..e7cbac445d8a609ffba1140ce49f6013a6f7a6e0 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -1205,12 +1205,12 @@ static ssize_t h3_parse_settings_frm(struct h3c *h3c, const struct buffer *buf,
        return ret;
 }
 
-/* Decode <qcs> remotely initiated bidi-stream. <fin> must be set to indicate
- * that we received the last data of the stream.
+/* Transcode HTTP/3 payload received in buffer <b> to HTX data for stream
+ * <qcs>. If <fin> is set, it indicates that no more data will arrive after.
  *
  * Returns 0 on success else non-zero.
  */
-static ssize_t h3_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
+static ssize_t h3_rcv_buf(struct qcs *qcs, struct buffer *b, int fin)
 {
        struct h3s *h3s = qcs->ctx;
        struct h3c *h3c = h3s->h3c;
@@ -2105,25 +2105,6 @@ static void h3_detach(struct qcs *qcs)
        TRACE_LEAVE(H3_EV_H3S_END, qcs->qcc->conn, qcs);
 }
 
-/* Initialize H3 control stream and prepare SETTINGS emission.
- *
- * Returns 0 on success else non-zero.
- */
-static int h3_finalize(void *ctx)
-{
-       struct h3c *h3c = ctx;
-       struct qcs *qcs;
-
-       qcs = qcc_init_stream_local(h3c->qcc, 0);
-       if (!qcs)
-               return 1;
-
-       h3_control_send(qcs, h3c);
-       h3c->ctrl_strm = qcs;
-
-       return 0;
-}
-
 /* Generate a GOAWAY frame for <h3c> connection on the control stream.
  *
  * Returns 0 on success else non-zero.
@@ -2202,6 +2183,25 @@ static int h3_init(struct qcc *qcc)
        return 0;
 }
 
+/* Initialize H3 control stream and prepare SETTINGS emission.
+ *
+ * Returns 0 on success else non-zero.
+ */
+static int h3_finalize(void *ctx)
+{
+       struct h3c *h3c = ctx;
+       struct qcs *qcs;
+
+       qcs = qcc_init_stream_local(h3c->qcc, 0);
+       if (!qcs)
+               return 1;
+
+       h3_control_send(qcs, h3c);
+       h3c->ctrl_strm = qcs;
+
+       return 0;
+}
+
 /* Send a HTTP/3 GOAWAY followed by a CONNECTION_CLOSE_APP. */
 static void h3_shutdown(void *ctx)
 {
@@ -2289,14 +2289,14 @@ static void h3_trace(enum trace_level level, uint64_t mask,
 /* HTTP/3 application layer operations */
 const struct qcc_app_ops h3_ops = {
        .init        = h3_init,
+       .finalize    = h3_finalize,
        .attach      = h3_attach,
-       .decode_qcs  = h3_decode_qcs,
+       .rcv_buf     = h3_rcv_buf,
        .snd_buf     = h3_snd_buf,
        .nego_ff     = h3_nego_ff,
        .done_ff     = h3_done_ff,
        .close       = h3_close,
        .detach      = h3_detach,
-       .finalize    = h3_finalize,
        .shutdown    = h3_shutdown,
        .inc_err_cnt = h3_stats_inc_err_cnt,
        .release     = h3_release,
index ba2f0c7db53bf707065c420e59b601c1360abf4e..14f83b79df81bee1c984d86864ee76ed1989a7c2 100644 (file)
@@ -9,7 +9,7 @@
 #include <haproxy/mux_quic.h>
 #include <haproxy/qmux_http.h>
 
-static ssize_t hq_interop_decode_qcs(struct qcs *qcs, struct buffer *b, int fin)
+static ssize_t hq_interop_rcv_buf(struct qcs *qcs, struct buffer *b, int fin)
 {
        struct htx *htx;
        struct htx_sl *sl;
@@ -191,7 +191,7 @@ static int hq_interop_attach(struct qcs *qcs, void *conn_ctx)
 }
 
 const struct qcc_app_ops hq_interop_ops = {
-       .decode_qcs = hq_interop_decode_qcs,
+       .rcv_buf    = hq_interop_rcv_buf,
        .snd_buf    = hq_interop_snd_buf,
        .nego_ff    = hq_interop_nego_ff,
        .done_ff    = hq_interop_done_ff,
index 4422e0ba157bfdf7524b21a59e4d84f42e1762fa..9d00b3b311a9af4f637224f2bebcf6e7198f4132 100644 (file)
@@ -874,7 +874,7 @@ static int qcc_decode_qcs(struct qcc *qcc, struct qcs *qcs)
                fin = 1;
 
        if (!(qcs->flags & QC_SF_READ_ABORTED)) {
-               ret = qcc->app_ops->decode_qcs(qcs, &b, fin);
+               ret = qcc->app_ops->rcv_buf(qcs, &b, fin);
                if (ret < 0) {
                        TRACE_ERROR("decoding error", QMUX_EV_QCS_RECV, qcc->conn, qcs);
                        goto err;