]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: Add a function to install a mux for a health-check
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 21 Apr 2020 10:18:05 +0000 (12:18 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:38 +0000 (09:39 +0200)
This function is unused for now. But it will have be used to install a mux for
an outgoing connection openned in a health-check context. In this case, the
session's origin is the check itself, and it is used to know the mode, HTTP or
TCP, depending on the tcp-check type and not the proxy mode. The check is also
used to get the mux protocol if configured.

include/proto/connection.h

index 97c789964b6fec952da0c454aac9e8a1c72cefbb..86294388c114cb9818114e1fffa744189d522640 100644 (file)
@@ -998,6 +998,49 @@ static inline int conn_install_mux_be(struct connection *conn, void *ctx, struct
        return conn_install_mux(conn, mux_ops, ctx, prx, sess);
 }
 
+/* installs the best mux for outgoing connection <conn> for a check using the
+ * upper context <ctx>. If the mux protocol is forced by the check, we use it to
+ * find the best mux. Returns < 0 on error.
+ */
+static inline int conn_install_mux_chk(struct connection *conn, void *ctx, struct session *sess)
+{
+       struct check *check = objt_check(sess->origin);
+       struct server *srv = objt_server(conn->target);
+       struct proxy *prx = objt_proxy(conn->target);
+       const struct mux_ops *mux_ops;
+
+       if (!check) // Check must be defined
+               return -1;
+
+       if (srv)
+               prx = srv->proxy;
+
+       if (!prx) // target must be either proxy or server
+               return -1;
+
+       if (check->mux_proto)
+               mux_ops = check->mux_proto->mux;
+       else {
+               struct ist mux_proto;
+               const char *alpn_str = NULL;
+               int alpn_len = 0;
+               int mode;
+
+               if ((check->tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK) == TCPCHK_RULES_HTTP_CHK)
+                       mode = PROTO_MODE_HTTP;
+               else
+                       mode = PROTO_MODE_TCP;
+
+               conn_get_alpn(conn, &alpn_str, &alpn_len);
+               mux_proto = ist2(alpn_str, alpn_len);
+
+               mux_ops = conn_get_best_mux(conn, mux_proto, PROTO_SIDE_BE, mode);
+               if (!mux_ops)
+                       return -1;
+       }
+       return conn_install_mux(conn, mux_ops, ctx, prx, sess);
+}
+
 /* Change the mux for the connection.
  * The caller should make sure he's not subscribed to the underlying XPRT.
  */