From 6a29888f60c3ece1f054020d4f153be69efd5436 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Wed, 15 Nov 2023 12:18:52 +0100 Subject: [PATCH] MINOR: log/backend: ensure log exclusive params are not used in other modes 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 | 1 + src/cfgparse.c | 3 +++ src/proxy.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 783154a..83c13bd 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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); diff --git a/src/cfgparse.c b/src/cfgparse.c index 312b1d7..d61b04e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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: diff --git a/src/proxy.c b/src/proxy.c index 6a0096b..fae11ac 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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 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. -- 1.7.10.4