MINOR: quic: refactor app-ops initialization
Add a new function in mux-quic to install app-ops. For now this
functions is called during the ALPN negotiation of the QUIC handshake.
This change will be useful when the connection accept queue will be
implemented. It will be thus required to delay the app-ops
initialization because the mux won't be allocated anymore during the
QUIC handshake.
diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h
index c3eee86..5abb1df 100644
--- a/include/haproxy/mux_quic.h
+++ b/include/haproxy/mux_quic.h
@@ -54,6 +54,22 @@
struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id);
+/* Install the <app_ops> applicative layer of a QUIC connection on mux <qcc>.
+ * Returns 0 on success else non-zero.
+ */
+static inline int qcc_install_app_ops(struct qcc *qcc,
+ const struct qcc_app_ops *app_ops)
+{
+ qcc->app_ops = app_ops;
+ if (qcc->app_ops->init && !qcc->app_ops->init(qcc))
+ return 1;
+
+ if (qcc->app_ops->finalize)
+ qcc->app_ops->finalize(qcc->ctx);
+
+ return 0;
+}
+
#endif /* USE_QUIC */
#endif /* _HAPROXY_MUX_QUIC_H */
diff --git a/include/haproxy/xprt_quic-t.h b/include/haproxy/xprt_quic-t.h
index 562d22c..23f641a 100644
--- a/include/haproxy/xprt_quic-t.h
+++ b/include/haproxy/xprt_quic-t.h
@@ -735,6 +735,8 @@
struct task *timer_task;
unsigned int timer;
unsigned int flags;
+
+ const struct qcc_app_ops *app_ops;
};
#endif /* USE_QUIC */
diff --git a/src/xprt_quic.c b/src/xprt_quic.c
index 3683350..33eb021 100644
--- a/src/xprt_quic.c
+++ b/src/xprt_quic.c
@@ -1041,23 +1041,16 @@
*/
int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len)
{
- const struct qcc_app_ops *app_ops;
-
- if (alpn_len >= 2 && memcmp(alpn, "h3", 2) == 0) {
- app_ops = qc->qcc->app_ops = &h3_ops;
- }
- else if (alpn_len >= 10 && memcmp(alpn, "hq-interop", 10) == 0) {
- app_ops = qc->qcc->app_ops = &hq_interop_ops;
- }
+ if (alpn_len >= 2 && memcmp(alpn, "h3", 2) == 0)
+ qc->app_ops = &h3_ops;
+ else if (alpn_len >= 10 && memcmp(alpn, "hq-interop", 10) == 0)
+ qc->app_ops = &hq_interop_ops;
else
return 0;
- if (app_ops->init && !app_ops->init(qc->qcc))
+ if (qcc_install_app_ops(qc->qcc, qc->app_ops))
return 0;
- if (app_ops->finalize)
- app_ops->finalize(qc->qcc->ctx);
-
/* mux-quic can now be considered ready. */
qc->mux_state = QC_MUX_READY;