]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[PATCH]: Check for duplicated conflicting proxies
authorKrzysztof Oledzki <ole@ans.pl>
Sun, 21 Oct 2007 00:55:17 +0000 (02:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 21 Oct 2007 08:16:27 +0000 (10:16 +0200)
Currently haproxy accepts a config with duplicated proxies
(listen/fronted/backed/ruleset). This patch fix this, so the application
will complain when there is an error.

With this modification it is still possible to use the same name for two
proxies (for example frontend&backend) as long there is no conflict:

                 listen backend frontend ruleset
listen             -      -       -        -
backend            -      -       OK       -
frontend           -      OK      -        -
ruleset            -      -       -        -

Best regards,

  Krzysztof Oledzki

src/cfgparse.c

index d9e01a7a4e2aca1ac8441da36d1f42cd643436a9..7483a9c6cb071998c6deb8a44233ed1131295597 100644 (file)
@@ -523,7 +523,28 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
                              file, linenum, args[0]);
                        return -1;
                }
-       
+
+               for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) {
+                       /*
+                        * If there are two proxies with the same name only following
+                        * combinations are allowed:
+                        *
+                        *                      listen backend frontend ruleset
+                        *      listen             -      -       -        -
+                        *      backend            -      -       OK       -
+                        *      frontend           -      OK      -        -
+                        *      ruleset            -      -       -        -
+                        */
+
+                       if (!strcmp(curproxy->id, args[1]) &&
+                               (rc!=(PR_CAP_FE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_BE|PR_CAP_RS)) &&
+                               (rc!=(PR_CAP_BE|PR_CAP_RS) || curproxy->cap!=(PR_CAP_FE|PR_CAP_RS))) {
+                               Alert("parsing %s: duplicated proxy %s with conflicting capabilities: %X/%X!\n",
+                                       file, args[1], curproxy->cap, rc);
+                               return -1;
+                       }
+               }
+
                if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
                        Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
                        return -1;