]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add alternative mux_ops param for conn_install_mux_be
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 28 Oct 2021 14:36:11 +0000 (16:36 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 3 Nov 2021 15:24:48 +0000 (16:24 +0100)
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.

include/haproxy/connection.h
src/backend.c
src/connection.c

index a4bef3df7301847a09ad50ad7d03675962642fe6..49f5d3f0fa2eb110ba793db9bca3bd9f6b209fb3 100644 (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);
index ee6e2b840c198117b1dcf239965e072e6b0a18d5..ae63d937ef772b5e6738cd1631286fba891c6a35 100644 (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;
                }
index a1472f681216110fd0ab70a9919bf9edfa94c201..270ae11a116807ee86bc824695074e0a1c358166 100644 (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;