]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: Add quic_set_app_ops() function
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 14 Dec 2021 18:34:08 +0000 (19:34 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 17 Dec 2021 07:38:43 +0000 (08:38 +0100)
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
src/xprt_quic.c

index 97625b4406bfd26190db7eb8f2d365ea4c7a6079..826ee77009621d074678f1b74781e7d8727f280d 100644 (file)
@@ -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);
 
index d1f1c5beca2f7c0869c9b783b87088918f892861..b4669dba757c8db4c81b87a67a2e1f3a89df74ab 100644 (file)
@@ -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 <qc> 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;