From b0bd62db2316d2e0cf729060f631200fa6a5b620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Tue, 14 Dec 2021 19:34:08 +0100 Subject: [PATCH] MINOR: quic: Add quic_set_app_ops() function Export the code responsible which set the ->app_ops structure into quic_set_app_ops() function. It must be called by the TLS callback which selects the application (ssl_sock_advertise_alpn_protos) so that to be able to build application packets after having received 0-RTT data. --- include/haproxy/xprt_quic.h | 1 + src/xprt_quic.c | 51 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/haproxy/xprt_quic.h b/include/haproxy/xprt_quic.h index 97625b440..826ee7700 100644 --- a/include/haproxy/xprt_quic.h +++ b/include/haproxy/xprt_quic.h @@ -1132,6 +1132,7 @@ static inline void qc_el_rx_pkts_del(struct quic_enc_level *qel) } 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); ssize_t quic_lstnr_dgram_read(struct buffer *buf, size_t len, void *owner, struct sockaddr_storage *saddr); diff --git a/src/xprt_quic.c b/src/xprt_quic.c index d1f1c5bec..b4669dba7 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -1055,6 +1055,31 @@ void quic_set_tls_alert(struct quic_conn *qc, int alert) TRACE_PROTO("Alert set", QUIC_EV_CONN_SSLDATA, qc->conn); } +/* Set the application for QUIC connection. + * Return 1 if succeeded, 0 if not. + */ +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; + } + else + return 0; + + if (app_ops->init && !app_ops->init(qc->qcc)) + return 0; + + if (app_ops->finalize) + app_ops->finalize(qc->qcc->ctx); + + return 1; +} + /* ->add_handshake_data QUIC TLS callback used by the QUIC TLS stack when it * wants to provide the QUIC layer with CRYPTO data. * Returns 1 if succeeded, 0 if not. @@ -1836,9 +1861,6 @@ static inline int qc_provide_cdata(struct quic_enc_level *el, { int ssl_err, state; struct quic_conn *qc; - const struct qcc_app_ops *app_ops; - const char *alpn; - int alpn_len; TRACE_ENTER(QUIC_EV_CONN_SSLDATA, ctx->conn); ssl_err = SSL_ERROR_NONE; @@ -1895,29 +1917,6 @@ static inline int qc_provide_cdata(struct quic_enc_level *el, QUIC_EV_CONN_HDSHK, ctx->conn, &state); } - conn_get_alpn(ctx->conn, &alpn, &alpn_len); - 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; - } - else { - /* TODO RFC9001 8.1. Protocol Negotiation - * must return no_application_protocol TLS alert - */ - TRACE_PROTO("No matching ALPN", QUIC_EV_CONN_SSLDATA, ctx->conn); - goto err; - } - - if (app_ops->init) { - if (!app_ops->init(qc->qcc)) - goto err; - } - - if (app_ops->finalize) - app_ops->finalize(qc->qcc->ctx); - out: TRACE_LEAVE(QUIC_EV_CONN_SSLDATA, ctx->conn); return 1;