From d8f4b07e4020aee2aed7fbaf589155f202d6c587 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 18 Sep 2024 17:37:17 +0200 Subject: [PATCH] MEDIUM: cfgparse: warn about colliding names between defaults and proxies In order to complete the checks added in 303a66573d ("MEDIUM: cfgparse: warn about proxies having the same names"), we also need to warn about regular proxies having the same name as defaults sections as well as defaults sections having the same name as proxies, since defaults sections are inherently proxies, albeit stored in a separate list for now. --- src/cfgparse-listen.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 7f3e138ab..e5945d8e2 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -285,16 +285,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) curproxy->id, curproxy->conf.file, curproxy->conf.line); err_code |= ERR_ALERT | ERR_FATAL; } - else { - curproxy = proxy_find_by_name(args[1], 0, 0); - if (curproxy) { - /* different capabilities but still same name: forbidden soon */ - ha_warning("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d. This is dangerous and will not be supported anymore in version 3.3.\n", - file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), - curproxy->id, curproxy->conf.file, curproxy->conf.line); - err_code |= ERR_WARN; - } - } curproxy = log_forward_by_name(args[1]); if (curproxy) { @@ -316,6 +306,19 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) const char *name = args[1]; int arg = 2; + curproxy = proxy_find_by_name(args[1], 0, 0); + if (!curproxy && !(rc & PR_CAP_DEF)) + curproxy = proxy_find_by_name(args[1], PR_CAP_DEF, 0); + + if (curproxy) { + /* different capabilities but still same name: forbidden soon */ + ha_warning("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d." + " This is dangerous and will not be supported anymore in version 3.3.\n", + file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), + curproxy->id, curproxy->conf.file, curproxy->conf.line); + err_code |= ERR_WARN; + } + if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) { // also support "defaults from blah" (no name then) arg = 1;