]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: make sure to associate the proper mux to bind and servers
authorWilly Tarreau <w@1wt.eu>
Sun, 2 Dec 2018 12:09:09 +0000 (13:09 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Dec 2018 12:29:35 +0000 (13:29 +0100)
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.

src/cfgparse.c
src/listener.c
src/server.c

index d754dd55e06584fd7861f572c8404d6b6ecc5a56..c4db29c1558f0276d2f2aa138b06ca8f78fd47b1 100644 (file)
@@ -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;
                }
        }
 
index 37466d44ecaa81ac396bd3847af1958e659d5074..2c885e998cf5127d12d27bf2268e7554464a3b79 100644 (file)
@@ -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;
 }
 
index eb2bc6e9cd2bfadda5bbc6e5b4d10be6caa3a208..53b9177be11c8e06547cd746861ab66037a0053f 100644 (file)
@@ -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;
 }