MINOR: connection: add conn_pr_mode_to_proto_mode() helper func

This function allows to safely map proxy mode to corresponding proto_mode

This will allow for easier code maintenance and prevent mixups between
proxy mode and proto mode.
This commit is contained in:
Aurelien DARRAGON 2023-10-19 16:06:03 +02:00 committed by Christopher Faulet
parent 29b76cae47
commit 66795bd721
3 changed files with 22 additions and 3 deletions

View File

@ -605,6 +605,10 @@ void list_mux_proto(FILE *out);
* HTTP). <mux_proto> can be empty. Will fall back to the first compatible mux
* with exactly the same <proto_mode> or with an empty name. May return
* null if the code improperly registered the default mux to use as a fallback.
*
* <proto_mode> expects PROTO_MODE_* value only: PROXY_MODE_* values should
* never be used directly here (but you may use conn_pr_mode_to_proto_mode()
* to map proxy mode to corresponding proto mode before calling the function).
*/
static inline const struct mux_proto_list *conn_get_best_mux_entry(
const struct ist mux_proto,
@ -733,6 +737,21 @@ static inline void set_tlv_arg(int tlv_type, struct arg *tlv_arg)
tlv_arg->data.sint = tlv_type;
}
/*
* Map proxy mode (PR_MODE_*) to equivalent proto_proxy_mode (PROTO_MODE_*)
*/
static inline int conn_pr_mode_to_proto_mode(int proxy_mode)
{
int mode;
/* for now we only support TCP and HTTP proto_modes, so we
* consider that if it's not HTTP, then it's TCP
*/
mode = 1 << (proxy_mode == PR_MODE_HTTP);
return mode;
}
#endif /* _HAPROXY_CONNECTION_H */
/*

View File

@ -4007,7 +4007,7 @@ out_uri_auth_compat:
/* Check the mux protocols, if any, for each listener and server
* attached to the current proxy */
list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) {
int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
int mode = conn_pr_mode_to_proto_mode(curproxy->mode);
const struct mux_proto_list *mux_ent;
if (!bind_conf->mux_proto) {
@ -4058,7 +4058,7 @@ out_uri_auth_compat:
bind_conf->mux_proto = mux_ent;
}
for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
int mode = (1 << (curproxy->mode == PR_MODE_HTTP));
int mode = conn_pr_mode_to_proto_mode(curproxy->mode);
const struct mux_proto_list *mux_ent;
if (!newsrv->mux_proto)

View File

@ -2947,7 +2947,7 @@ static int check_tcp_switch_stream_mode(struct act_rule *rule, struct proxy *px,
const struct mux_proto_list *mux_ent;
const struct mux_proto_list *mux_proto = rule->arg.act.p[1];
enum pr_mode pr_mode = (uintptr_t)rule->arg.act.p[0];
enum proto_proxy_mode mode = (1 << (pr_mode == PR_MODE_HTTP));
enum proto_proxy_mode mode = conn_pr_mode_to_proto_mode(pr_mode);
if (pr_mode == PR_MODE_HTTP)
px->options |= PR_O_HTTP_UPG;