mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-10 03:02:28 +00:00
MEDIUM: connection: Add conn_upgrade_mux_fe() to handle mux upgrades
This function will handle mux upgrades, for frontend connections only. It will retrieve the best mux in the same way than conn_install_mux_fe except that the mode and optionnally the proto are forced. The new multiplexer is initialized using a new context and a specific input buffer. Then, the old one is destroyed. If an error occurred, everything is rolled back.
This commit is contained in:
parent
39a96ee16e
commit
c0016d8119
@ -1158,6 +1158,47 @@ static inline int conn_install_mux_be(struct connection *conn, void *ctx, struct
|
|||||||
return conn_install_mux(conn, mux_ops, ctx, prx, sess);
|
return conn_install_mux(conn, mux_ops, ctx, prx, sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int conn_upgrade_mux_fe(struct connection *conn, void *ctx, struct buffer *buf,
|
||||||
|
struct ist mux_proto, int mode)
|
||||||
|
{
|
||||||
|
struct bind_conf *bind_conf = __objt_listener(conn->target)->bind_conf;
|
||||||
|
const struct mux_ops *old_mux, *new_mux;
|
||||||
|
void *old_mux_ctx;
|
||||||
|
const char *alpn_str = NULL;
|
||||||
|
int alpn_len = 0;
|
||||||
|
|
||||||
|
if (!mux_proto.len) {
|
||||||
|
conn_get_alpn(conn, &alpn_str, &alpn_len);
|
||||||
|
mux_proto = ist2(alpn_str, alpn_len);
|
||||||
|
}
|
||||||
|
new_mux = conn_get_best_mux(conn, mux_proto, PROTO_SIDE_FE, mode);
|
||||||
|
old_mux = conn->mux;
|
||||||
|
|
||||||
|
/* No mux found */
|
||||||
|
if (!new_mux)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Same mux, nothing to do */
|
||||||
|
if (old_mux == new_mux)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
old_mux_ctx = conn->ctx;
|
||||||
|
conn->mux = new_mux;
|
||||||
|
conn->ctx = ctx;
|
||||||
|
conn_force_unsubscribe(conn);
|
||||||
|
if (new_mux->init(conn, bind_conf->frontend, conn->owner, buf) == -1) {
|
||||||
|
/* The mux upgrade failed, so restore the old mux */
|
||||||
|
conn->ctx = old_mux_ctx;
|
||||||
|
conn->mux = old_mux;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The mux was upgraded, destroy the old one */
|
||||||
|
*buf = BUF_NULL;
|
||||||
|
old_mux->destroy(old_mux_ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_CONNECTION_H */
|
#endif /* _PROTO_CONNECTION_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user