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.
This commit is contained in:
Amaury Denoyelle 2022-01-19 11:29:25 +01:00
parent 0b1f93127f
commit 4b40f19f92
3 changed files with 23 additions and 12 deletions

View File

@ -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 <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 */

View File

@ -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 */

View File

@ -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;