From: Willy Tarreau Date: Sun, 2 Dec 2018 12:09:09 +0000 (+0100) Subject: MINOR: config: make sure to associate the proper mux to bind and servers X-Git-Tag: v1.9-dev9~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76a551de2e3bb41313f8cdc808ed12f982076549;p=thirdparty%2Fhaproxy.git MINOR: config: make sure to associate the proper mux to bind and servers Currently a mux may be forced on a bind or server line by specifying the "proto" keyword. The problem is that the mux may depend on the proxy's mode, which is not known when parsing this keyword, so a wrong mux could be picked. Let's simply update the mux entry while checking its validity. We do have the name and the side, we only need to see if a better mux fits based on the proxy's mode. It also requires to remove the side check while parsing the "proto" keyword since a wrong mux could be picked. This way it becomes possible to declare multiple muxes with the same protocol names and different sides or modes. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index d754dd55e0..c4db29c155 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3319,6 +3319,7 @@ out_uri_auth_compat: * attached to the current proxy */ list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); + const struct mux_proto_list *mux_ent; /* Special case for HTX because it is still experimental */ if (curproxy->options2 & PR_O2_USE_HTX) @@ -3326,7 +3327,14 @@ out_uri_auth_compat: if (!bind_conf->mux_proto) continue; - if (!(bind_conf->mux_proto->mode & mode)) { + + /* it is possible that an incorrect mux was referenced + * due to the proxy's mode not being taken into account + * on first pass. Let's adjust it now. + */ + mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode); + + if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) { ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n", proxy_type_str(curproxy), curproxy->id, (int)bind_conf->mux_proto->token.len, @@ -3334,9 +3342,13 @@ out_uri_auth_compat: bind_conf->arg, bind_conf->file, bind_conf->line); cfgerr++; } + + /* update the mux */ + bind_conf->mux_proto = mux_ent; } for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { int mode = (1 << (curproxy->mode == PR_MODE_HTTP)); + const struct mux_proto_list *mux_ent; /* Special case for HTX because it is still experimental */ if (curproxy->options2 & PR_O2_USE_HTX) @@ -3344,7 +3356,14 @@ out_uri_auth_compat: if (!newsrv->mux_proto) continue; - if (!(newsrv->mux_proto->mode & mode)) { + + /* it is possible that an incorrect mux was referenced + * due to the proxy's mode not being taken into account + * on first pass. Let's adjust it now. + */ + mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode); + + if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) { ha_alert("config : %s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n", proxy_type_str(curproxy), curproxy->id, (int)newsrv->mux_proto->token.len, @@ -3352,6 +3371,9 @@ out_uri_auth_compat: newsrv->id, newsrv->conf.file, newsrv->conf.line); cfgerr++; } + + /* update the mux */ + newsrv->mux_proto = mux_ent; } } diff --git a/src/listener.c b/src/listener.c index 37466d44ec..2c885e998c 100644 --- a/src/listener.c +++ b/src/listener.c @@ -999,11 +999,6 @@ static int bind_parse_proto(char **args, int cur_arg, struct proxy *px, struct b memprintf(err, "'%s' : unknown MUX protocol '%s'", args[cur_arg], args[cur_arg+1]); return ERR_ALERT | ERR_FATAL; } - else if (!(conf->mux_proto->side & PROTO_SIDE_FE)) { - memprintf(err, "'%s' : MUX protocol '%s' cannot be used for incoming connections", - args[cur_arg], args[cur_arg+1]); - return ERR_ALERT | ERR_FATAL; - } return 0; } diff --git a/src/server.c b/src/server.c index eb2bc6e9cd..53b9177be1 100644 --- a/src/server.c +++ b/src/server.c @@ -520,11 +520,6 @@ static int srv_parse_proto(char **args, int *cur_arg, memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]); return ERR_ALERT | ERR_FATAL; } - else if (!(newsrv->mux_proto->side & PROTO_SIDE_BE)) { - memprintf(err, "'%s' : MUX protocol '%s' cannot be used for outgoing connections", - args[*cur_arg], args[*cur_arg+1]); - return ERR_ALERT | ERR_FATAL; - } return 0; }