From: Amaury Denoyelle Date: Thu, 7 Dec 2023 16:43:07 +0000 (+0100) Subject: CLEANUP: mux-quic: clean up app ops callback definitions X-Git-Tag: v3.0-dev1~105 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e772d3f40ff492bd9ec0efee568300aed013d382;p=thirdparty%2Fhaproxy.git CLEANUP: mux-quic: clean up app ops callback definitions 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. --- diff --git a/include/haproxy/mux_quic-t.h b/include/haproxy/mux_quic-t.h index abfc20a506..543df319e6 100644 --- a/include/haproxy/mux_quic-t.h +++ b/include/haproxy/mux_quic-t.h @@ -185,17 +185,35 @@ enum qcc_app_ops_close_side { /* QUIC application layer operations */ struct qcc_app_ops { + /* Initialize connection app context. */ int (*init)(struct qcc *qcc); + /* Finish connection initialization if prelude required. */ + int (*finalize)(void *ctx); + + /* Initialize 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 stream closure. */ int (*close)(struct qcs *qcs, enum qcc_app_ops_close_side side); + /* Free 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); }; diff --git a/src/h3.c b/src/h3.c index ba488f26f7..e7cbac445d 100644 --- 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 remotely initiated bidi-stream. must be set to indicate - * that we received the last data of the stream. +/* Transcode HTTP/3 payload received in buffer to HTX data for stream + * . If 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 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, diff --git a/src/hq_interop.c b/src/hq_interop.c index ba2f0c7db5..14f83b79df 100644 --- a/src/hq_interop.c +++ b/src/hq_interop.c @@ -9,7 +9,7 @@ #include #include -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, diff --git a/src/mux_quic.c b/src/mux_quic.c index 4422e0ba15..9d00b3b311 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -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;