]> git.kaiwu.me - haproxy.git/commitdiff
[PATCH] use backends only with use_backend directive
authorKrzysztof Oledzki <ole@ans.pl>
Wed, 31 Oct 2007 08:07:24 +0000 (09:07 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 31 Oct 2007 08:07:41 +0000 (09:07 +0100)
Hello,

As it is possible to use the same name for two proxies, make sure that
use_backed & friends does not match wrong proxy when used with use_backend/
default_backend/setbe. For example, without this patch, when there is a
backend and frontend with the same name (first backend and then frontend
trying to use specific backend), the application will likely try to use
frontend instead of backend, complaining loudly about a loop.

Best regards,

                                 Krzysztof Oledzki

src/cfgparse.c

index 7483a9c6cb071998c6deb8a44233ed1131295597..d722b0ba0a6714c850415c4be4772e5bd6f154c2 100644 (file)
@@ -2525,20 +2525,16 @@ int readcfgfile(const char *file)
                        struct proxy *target;
 
                        for (target = proxy; target != NULL; target = target->next) {
-                               if (strcmp(target->id, curproxy->defbe.name) == 0)
+                               if ((target->cap & PR_CAP_BE) && !strcmp(target->id, curproxy->defbe.name))
                                        break;
                        }
                        if (target == NULL) {
-                               Alert("parsing %s : default backend '%s' in HTTP %s '%s' was not found !\n", 
+                               Alert("parsing %s: default proxy '%s' with backend capability in HTTP %s '%s' was not found!\n", 
                                      file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
                                cfgerr++;
                        } else if (target == curproxy) {
                                Alert("parsing %s : loop detected for default backend %s !\n", file, curproxy->defbe.name);
                                cfgerr++;
-                       } else if (!(target->cap & PR_CAP_BE)) {
-                               Alert("parsing %s : default backend '%s' in HTTP %s '%s' has no backend capability !\n",
-                                     file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
-                               cfgerr++;
                        } else if (target->mode != curproxy->mode) {
                                Alert("parsing %s : default backend '%s' in HTTP %s '%s' is not of same mode (tcp/http) !\n",
                                      file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
@@ -2558,20 +2554,16 @@ int readcfgfile(const char *file)
                                if (exp->action != ACT_SETBE)
                                        continue;
                                for (target = proxy; target != NULL; target = target->next) {
-                                       if (strcmp(target->id, exp->replace) == 0)
+                                       if ((target->cap & PR_CAP_BE) && !strcmp(target->id, exp->replace))
                                                break;
                                }
                                if (target == NULL) {
-                                       Alert("parsing %s : backend '%s' in HTTP %s '%s' was not found !\n", 
+                                       Alert("parsing %s: proxy '%s' with backend capability in HTTP %s '%s' was not found!\n", 
                                              file, exp->replace, proxy_type_str(curproxy), curproxy->id);
                                        cfgerr++;
                                } else if (target == curproxy) {
                                        Alert("parsing %s : loop detected for backend %s !\n", file, exp->replace);
                                        cfgerr++;
-                               } else if (!(target->cap & PR_CAP_BE)) {
-                                       Alert("parsing %s : target '%s' in HTTP %s '%s' has no backend capability !\n",
-                                             file, exp->replace, proxy_type_str(curproxy), curproxy->id);
-                                       cfgerr++;
                                } else if (target->mode != PR_MODE_HTTP) {
                                        Alert("parsing %s : backend '%s' in HTTP %s '%s' is not HTTP (use 'mode http') !\n",
                                              file, exp->replace, proxy_type_str(curproxy), curproxy->id);
@@ -2589,21 +2581,17 @@ int readcfgfile(const char *file)
                        struct proxy *target;
 
                        for (target = proxy; target != NULL; target = target->next) {
-                               if (strcmp(target->id, rule->be.name) == 0)
+                               if ((target->cap & PR_CAP_BE) && !strcmp(target->id, rule->be.name))
                                        break;
                        }
 
                        if (target == NULL) {
-                               Alert("parsing %s : backend '%s' in HTTP %s '%s' was not found !\n", 
+                               Alert("parsing %s: proxy '%s' with backend capability in HTTP %s '%s' was not found!\n", 
                                      file, rule->be.name, proxy_type_str(curproxy), curproxy->id);
                                cfgerr++;
                        } else if (target == curproxy) {
                                Alert("parsing %s : loop detected for backend %s !\n", file, rule->be.name);
                                cfgerr++;
-                       } else if (!(target->cap & PR_CAP_BE)) {
-                               Alert("parsing %s : target '%s' in HTTP %s '%s' has no backend capability !\n",
-                                     file, rule->be.name, proxy_type_str(curproxy), curproxy->id);
-                               cfgerr++;
                        } else if (target->mode != curproxy->mode) {
                                Alert("parsing %s : backend '%s' referenced in %s '%s' is of different mode !\n",
                                      file, rule->be.name, proxy_type_str(curproxy), curproxy->id);