diff --git a/include/haproxy/mux_quic.h b/include/haproxy/mux_quic.h index c3eee86e5..5abb1df9f 100644 --- a/include/haproxy/mux_quic.h +++ b/include/haproxy/mux_quic.h @@ -54,6 +54,22 @@ static inline int qcs_get_next_id(struct qcc *qcc, enum qcs_type type) struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id); +/* Install the applicative layer of a QUIC connection on mux . + * 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 562d22cab..23f641a2f 100644 --- a/include/haproxy/xprt_quic-t.h +++ b/include/haproxy/xprt_quic-t.h @@ -735,6 +735,8 @@ struct quic_conn { 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 3683350a5..33eb02181 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -1041,23 +1041,16 @@ void quic_set_tls_alert(struct quic_conn *qc, int alert) */ 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;