From: Christopher Faulet Date: Tue, 21 Apr 2020 10:18:05 +0000 (+0200) Subject: MINOR: connection: Add a function to install a mux for a health-check X-Git-Tag: v2.2-dev7~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9e1c4c7c27b892b6b4f13ff0d0a96508970d2a9;p=thirdparty%2Fhaproxy.git MINOR: connection: Add a function to install a mux for a health-check 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. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index 97c789964b..86294388c1 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -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 for a check using the + * upper context . 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. */