From 86ffbaa0f52b55c379a96fecf9728cd196355932 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Mon, 18 May 2026 16:57:05 +0200 Subject: [PATCH] MINOR: connection: define conn_select_mux_fe() Define a new function conn_select_mux_fe(). The objective is to have a preliminary function to determine the MUX which will be used without initializing it. This will be useful for MUX which relies on a specific XPRT handshake prior to its startup, which is the case for QMux protocol. The code of conn_select_mux_fe() is identical to the beginning of conn_install_mux_fe() with a similar MUX selection logic. However, connection MUX initialization is not performed in this case. In a future patch, both functions should be merged together to reduce code duplication. --- include/haproxy/connection.h | 1 + src/connection.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index dfd816344..f47e3bcc4 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -86,6 +86,7 @@ int conn_create_mux(struct connection *conn, int *closed_connection); int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake); int conn_upgrade_mux_fe(struct connection *conn, void *ctx, struct buffer *buf, struct ist mux_proto, int mode); +const struct mux_proto_list *conn_select_mux_fe(const struct connection *conn); int conn_install_mux_fe(struct connection *conn, void *ctx); int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess, const struct mux_ops *force_mux_ops); diff --git a/src/connection.c b/src/connection.c index 50fc6c457..d4fb9e54c 100644 --- a/src/connection.c +++ b/src/connection.c @@ -319,6 +319,29 @@ int conn_upgrade_mux_fe(struct connection *conn, void *ctx, struct buffer *buf, return 0; } +/* Returns the mux_proto_list entry compatible with frontend connection + * or NULL if nothing eligible. + * TODO duplicate code to merge with conn_install_mux_fe(). + */ +const struct mux_proto_list *conn_select_mux_fe(const struct connection *conn) +{ + struct bind_conf *bind_conf; + const char *alpn_str = NULL; + struct ist alpn; + int alpn_len = 0, mode; + + bind_conf = __objt_listener(conn->target)->bind_conf; + + if (bind_conf->mux_proto) + return bind_conf->mux_proto; + + mode = conn_pr_mode_to_proto_mode(bind_conf->frontend->mode); + conn_get_alpn(conn, &alpn_str, &alpn_len); + alpn = ist2(alpn_str, alpn_len); + return conn_get_best_mux_entry(IST_NULL, alpn, PROTO_SIDE_FE, + proto_is_quic(conn->ctrl), mode); +} + /* installs the best mux for incoming connection using the upper context * . If the mux protocol is forced, we use it to find the best * mux. Otherwise we use the ALPN name, if any. Returns < 0 on error.