]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: define conn_select_mux_fe()
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 18 May 2026 14:57:05 +0000 (16:57 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 19 May 2026 16:33:54 +0000 (18:33 +0200)
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
src/connection.c

index dfd816344c0f1b7396933383976e2f8bc1229a69..f47e3bcc48468305d4f38929c86eb88934cf7b6b 100644 (file)
@@ -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);
index 50fc6c45750d5335a682968b43322a43e3b971f7..d4fb9e54cbbdf4f168835c1c27f46ead60436ff5 100644 (file)
@@ -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 <conn> 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 <conn> using the upper context
  * <ctx>. 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.