]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: refactor app-ops initialization
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 19 Jan 2022 10:29:25 +0000 (11:29 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 26 Jan 2022 09:59:33 +0000 (10:59 +0100)
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.

include/haproxy/mux_quic.h
include/haproxy/xprt_quic-t.h
src/xprt_quic.c

index c3eee86e55a8c15cc73c114e984426d63036af85..5abb1df9fa2bfa88791bfb5a885fcbe964ac2ee7 100644 (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 */
index 562d22cab2110617dccdb5cd1054fbf593379f59..23f641a2f038c554c10cefcb3c10f93087d883f9 100644 (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 */
index 3683350a5cf734e9ec4919a3534ab32794ea1101..33eb02181805b6d5e61f98f13c5a5875a14d612f 100644 (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;