MINOR: log/backend: ensure log exclusive params are not used in other modes
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 15 Nov 2023 11:18:52 +0000 (12:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 18 Nov 2023 10:16:21 +0000 (11:16 +0100)
add proxy_cfg_ensure_no_log() function (similar to
proxy_cfg_ensure_no_http()) to ensure at the end of proxy parsing that
no log exclusive options are found if the proxy is not in log mode.

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

index 783154a..83c13bd 100644 (file)
@@ -62,6 +62,7 @@ struct server *findserver(const struct proxy *px, const char *name);
 struct server *findserver_unique_id(const struct proxy *px, int puid, uint32_t rid);
 struct server *findserver_unique_name(const struct proxy *px, const char *name, uint32_t rid);
 int proxy_cfg_ensure_no_http(struct proxy *curproxy);
+int proxy_cfg_ensure_no_log(struct proxy *curproxy);
 void init_new_proxy(struct proxy *p);
 void proxy_preset_defaults(struct proxy *defproxy);
 void proxy_free_defaults(struct proxy *defproxy);
index 312b1d7..d61b04e 100644 (file)
@@ -2939,14 +2939,17 @@ init_proxies_list_stage1:
                switch (curproxy->mode) {
                case PR_MODE_TCP:
                        cfgerr += proxy_cfg_ensure_no_http(curproxy);
+                       cfgerr += proxy_cfg_ensure_no_log(curproxy);
                        break;
 
                case PR_MODE_HTTP:
+                       cfgerr += proxy_cfg_ensure_no_log(curproxy);
                        curproxy->http_needed = 1;
                        break;
 
                case PR_MODE_CLI:
                        cfgerr += proxy_cfg_ensure_no_http(curproxy);
+                       cfgerr += proxy_cfg_ensure_no_log(curproxy);
                        break;
 
                case PR_MODE_SYSLOG:
index 6a0096b..fae11ac 100644 (file)
@@ -1375,6 +1375,24 @@ int proxy_cfg_ensure_no_http(struct proxy *curproxy)
        return 0;
 }
 
+/* This function checks that the designated proxy has no log 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 log mode.
+ * The <file> argument is used to construct the error message.
+ */
+int proxy_cfg_ensure_no_log(struct proxy *curproxy)
+{
+       if (curproxy->lbprm.algo & BE_LB_NEED_LOG) {
+               curproxy->lbprm.algo &= ~BE_LB_ALGO;
+               curproxy->lbprm.algo |= BE_LB_ALGO_RR;
+               ha_warning("Unusable balance algorithm for %s '%s' (needs 'mode log'). Falling back to round robin.\n",
+                          proxy_type_str(curproxy), curproxy->id);
+       }
+
+       return 0;
+}
+
 /* Perform the most basic initialization of a proxy :
  * memset(), list_init(*), reset_timeouts(*).
  * Any new proxy or peer should be initialized via this function.