]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] cfgparse: some cleanups in the consistency checks
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Mar 2009 12:46:16 +0000 (13:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 15 Mar 2009 12:46:16 +0000 (13:46 +0100)
Check for servers in health mode, for health mode in pure-backends.
Some code have been refactored for better organization.

include/proto/proxy.h
src/cfgparse.c
src/proxy.c

index 012c1b27fe4b52b5e549eb16d9b3a1903ce19593..e56de12319a368fc031b3642fbd3435133b12f08 100644 (file)
@@ -40,6 +40,7 @@ const char *proxy_cap_str(int cap);
 const char *proxy_mode_str(int mode);
 struct proxy *findproxy(const char *name, int mode, int cap);
 struct server *findserver(const struct proxy *px, const char *name);
+int proxy_cfg_ensure_no_http(struct proxy *curproxy, const char *file);
 
 /*
  * This function returns a string containing the type of the proxy in a format
index f34d0e31170f5170246b5d2d34ff31563348256f..ec2c182bbb0deddd785b10a9b7ab3fc0e820df2c 100644 (file)
@@ -3113,16 +3113,44 @@ int readcfgfile(const char *file)
                        continue;
                }
 
-               if (curproxy->cap & PR_CAP_FE && curproxy->listen == NULL)  {
+               switch (curproxy->mode) {
+               case PR_MODE_HEALTH:
+                       cfgerr += proxy_cfg_ensure_no_http(curproxy, file);
+                       if (!(curproxy->cap & PR_CAP_FE)) {
+                               Alert("parsing %s : %s '%s' cannot be in health mode as it has no frontend capability.\n",
+                                     file, proxy_type_str(curproxy), curproxy->id);
+                               cfgerr++;
+                       }
+
+                       if (curproxy->srv != NULL)
+                               Warning("parsing %s : servers will be ignored for %s '%s'.\n",
+                                       file, proxy_type_str(curproxy), curproxy->id);
+                       break;
+
+               case PR_MODE_TCP:
+                       cfgerr += proxy_cfg_ensure_no_http(curproxy, file);
+                       break;
+
+               case PR_MODE_HTTP:
+                       if ((curproxy->cookie_name != NULL) && (curproxy->srv == NULL)) {
+                               Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n",
+                                     file, curproxy->id);
+                               cfgerr++;
+                       }
+                       break;
+               }
+
+               if ((curproxy->cap & PR_CAP_FE) && (curproxy->listen == NULL))  {
                        Alert("parsing %s : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n",
                              file, proxy_type_str(curproxy), curproxy->id);
                        cfgerr++;
                }
-               else if (curproxy->cap & PR_CAP_BE &&
-                        ((curproxy->mode != PR_MODE_HEALTH) &&
-                         !(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) &&
-                         !(curproxy->lbprm.algo & BE_LB_ALGO) &&
-                         (*(int *)&curproxy->dispatch_addr.sin_addr == 0))) {
+
+               if (curproxy->cap & PR_CAP_BE &&
+                   ((curproxy->mode != PR_MODE_HEALTH) &&
+                    !(curproxy->options & (PR_O_TRANSP | PR_O_HTTP_PROXY)) &&
+                    !(curproxy->lbprm.algo & BE_LB_ALGO) &&
+                    (*(int *)&curproxy->dispatch_addr.sin_addr == 0))) {
                        Alert("parsing %s : %s '%s' has no dispatch address and is not in transparent or balance mode.\n",
                              file, proxy_type_str(curproxy), curproxy->id);
                        cfgerr++;
@@ -3147,47 +3175,6 @@ int readcfgfile(const char *file)
                        }
                }
 
-               if (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */
-                       if (curproxy->cookie_name != NULL) {
-                               Warning("parsing %s : cookie will be ignored for %s '%s'.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-                       if (curproxy->rsp_exp != NULL) {
-                               Warning("parsing %s : server regular expressions will be ignored for %s '%s'.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-                       if (curproxy->req_exp != NULL) {
-                               Warning("parsing %s : client regular expressions will be ignored for %s '%s'.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-                       if (curproxy->monitor_uri != NULL) {
-                               Warning("parsing %s : monitor-uri will be ignored for %s '%s'.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-                       if (curproxy->lbprm.algo & BE_LB_PROP_L7) {
-                               curproxy->lbprm.algo &= ~BE_LB_ALGO;
-                               curproxy->lbprm.algo |= BE_LB_ALGO_RR;
-
-                               Warning("parsing %s : Layer 7 hash not possible for %s '%s'. Falling back to round robin.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-               }
-
-               if (curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */
-                       if ((newsrv = curproxy->srv) != NULL) {
-                               Warning("parsing %s : servers will be ignored for %s '%s'.\n",
-                                       file, proxy_type_str(curproxy), curproxy->id);
-                       }
-               }
-
-               if (curproxy->mode == PR_MODE_HTTP) { /* HTTP PROXY */
-                       if ((curproxy->cookie_name != NULL) && ((newsrv = curproxy->srv) == NULL)) {
-                               Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n",
-                                     file, curproxy->id);
-                               cfgerr++;
-                       }
-               }
-
                if ((curproxy->options & PR_O_DISABLE404) && !(curproxy->options & PR_O_HTTP_CHK)) {
                        curproxy->options &= ~PR_O_DISABLE404;
                        Warning("parsing %s : '%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
index 018ce786c4eee4001357331e523f193d7159fe16..a64bd0c88bff09c614815000a2ca4f64c78e0c9f 100644 (file)
@@ -297,6 +297,39 @@ struct server *findserver(const struct proxy *px, const char *name) {
        return target;
 }
 
+/* This function checks that the designated proxy has no http directives
+ * enabled. It will output a warning if there are, and will fix some of them.
+ * It returns the number of fatal errors encountered. This should be called
+ * at the end of the configuration parsing if the proxy is not in http mode.
+ * The <file> argument is used to construct the error message.
+ */
+int proxy_cfg_ensure_no_http(struct proxy *curproxy, const char *file)
+{
+       if (curproxy->cookie_name != NULL) {
+               Warning("parsing %s : cookie will be ignored for %s '%s' (needs 'mode http').\n",
+                       file, proxy_type_str(curproxy), curproxy->id);
+       }
+       if (curproxy->rsp_exp != NULL) {
+               Warning("parsing %s : server regular expressions will be ignored for %s '%s' (needs 'mode http').\n",
+                       file, proxy_type_str(curproxy), curproxy->id);
+       }
+       if (curproxy->req_exp != NULL) {
+               Warning("parsing %s : client regular expressions will be ignored for %s '%s' (needs 'mode http').\n",
+                       file, proxy_type_str(curproxy), curproxy->id);
+       }
+       if (curproxy->monitor_uri != NULL) {
+               Warning("parsing %s : monitor-uri will be ignored for %s '%s' (needs 'mode http').\n",
+                       file, proxy_type_str(curproxy), curproxy->id);
+       }
+       if (curproxy->lbprm.algo & BE_LB_PROP_L7) {
+               curproxy->lbprm.algo &= ~BE_LB_ALGO;
+               curproxy->lbprm.algo |= BE_LB_ALGO_RR;
+               Warning("parsing %s : Layer 7 hash not possible for %s '%s' (needs 'mode http'). Falling back to round robin.\n",
+                       file, proxy_type_str(curproxy), curproxy->id);
+       }
+       return 0;
+}
+
 /*
  * This function creates all proxy sockets. It should be done very early,
  * typically before privileges are dropped. The sockets will be registered