MINOR: connection: add alternative mux_ops param for conn_install_mux_be

Add a new parameter force_mux_ops. This will be useful to specify an
alternative to the srv->mux_proto field. If non-NULL, it will be use to
force the mux protocol wether srv->mux_proto is set or not.

This argument will become useful to install a mux for non-standard
streams, most notably websocket streams.
This commit is contained in:
Amaury Denoyelle 2021-10-28 16:36:11 +02:00
parent 2454bda140
commit ac03ef26e8
3 changed files with 16 additions and 7 deletions

View File

@ -76,7 +76,8 @@ 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);
int conn_install_mux_fe(struct connection *conn, void *ctx);
int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess);
int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess,
const struct mux_ops *force_mux_ops);
int conn_install_mux_chk(struct connection *conn, void *ctx, struct session *sess);
void conn_delete_from_tree(struct ebmb_node *node);

View File

@ -1645,7 +1645,7 @@ skip_reuse:
* fail, and flag the connection as CO_FL_ERROR.
*/
if (init_mux) {
if (conn_install_mux_be(srv_conn, srv_cs, s->sess) < 0) {
if (conn_install_mux_be(srv_conn, srv_cs, s->sess, NULL) < 0) {
conn_full_close(srv_conn);
return SF_ERR_INTERNAL;
}

View File

@ -70,7 +70,7 @@ int conn_create_mux(struct connection *conn)
if (conn_install_mux_chk(conn, conn->ctx, sess) < 0)
goto fail;
}
else if (conn_install_mux_be(conn, conn->ctx, sess) < 0)
else if (conn_install_mux_be(conn, conn->ctx, sess, NULL) < 0)
goto fail;
srv = objt_server(conn->target);
@ -247,10 +247,14 @@ int conn_install_mux_fe(struct connection *conn, void *ctx)
}
/* installs the best mux for outgoing connection <conn> using the upper context
* <ctx>. If the mux protocol is forced, we use it to find the best mux. Returns
* < 0 on error.
* <ctx>. If the server mux protocol is forced, we use it to find the best mux.
* It's also possible to specify an alternative mux protocol <force_mux_ops>,
* in which case it will be used instead of the default server mux protocol.
*
* Returns < 0 on error.
*/
int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess)
int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess,
const struct mux_ops *force_mux_ops)
{
struct server *srv = objt_server(conn->target);
struct proxy *prx = objt_proxy(conn->target);
@ -262,8 +266,12 @@ int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess
if (!prx) // target must be either proxy or server
return -1;
if (srv && srv->mux_proto)
if (srv && srv->mux_proto && likely(!force_mux_ops)) {
mux_ops = srv->mux_proto->mux;
}
else if (srv && unlikely(force_mux_ops)) {
mux_ops = force_mux_ops;
}
else {
struct ist mux_proto;
const char *alpn_str = NULL;