]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: cfgparse: factor proxy vs log-forward collisions
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Sep 2024 12:13:14 +0000 (14:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Sep 2024 12:13:14 +0000 (14:13 +0200)
This simplifies the check added in 1a38684fbc ("MEDIUM: cfgparse:
detect collisions between defaults and log-forward"), by factoring it
with the other existing one.

The tests are ugly in that code because a first block tests pure
proxies, a second one proxies or defaults and inside that one we
have special cases for defaults. Let's just move the tests to the
"any proxy type" block.

src/cfgparse-listen.c

index 60f20ecd2c605a1552af0f5d8ef3be5fa458f24a..72d08e887560253087bcd8ffd604dbc36a744006 100644 (file)
@@ -286,14 +286,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                err_code |= ERR_ALERT | ERR_FATAL;
                }
 
-               curproxy = log_forward_by_name(args[1]);
-               if (curproxy) {
-                       ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
-                                file, linenum, proxy_cap_str(rc), args[1],
-                                curproxy->id, curproxy->conf.file, curproxy->conf.line);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-               }
-
                if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) ||
                    alertif_too_many_args(3, file, linenum, args, &err_code)) {
                        if (rc & PR_CAP_FE)
@@ -306,6 +298,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                const char *name = args[1];
                int arg = 2;
 
+               /* conflict with log-forward forbidden for listen/frontend/backend/defaults */
+               curproxy = log_forward_by_name(args[1]);
+               if (curproxy) {
+                       ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n",
+                                file, linenum, proxy_cap_str(rc), args[1],
+                                curproxy->id, curproxy->conf.file, curproxy->conf.line);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+               }
+
                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);
@@ -318,19 +319,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_WARN;
                }
-               else if (rc & PR_CAP_DEF) {
-                       /* only defaults need to be checked here, other proxies
-                        * have already been above.
-                        */
-                       curproxy = log_forward_by_name(args[1]);
-                       if (curproxy) {
-                               ha_warning("Parsing [%s:%d]: %s '%s' has the same name as log-forward section '%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],
-                                          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)