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.