]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend/balance: "balance" requires TCP or HTTP mode
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 19 Sep 2023 15:39:25 +0000 (17:39 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Oct 2023 13:34:30 +0000 (15:34 +0200)
Prevent the use of "balance" and associated keywords when proxy is neither
in tcp or http mode.

src/cfgparse-listen.c

index 78ccd98a9af75aa77de9ae0d189a0a533d5b6c18..f513207e61b76eebf05a2dfff46a09e141e444d9 100644 (file)
@@ -2502,6 +2502,12 @@ stats_error_parsing:
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        err_code |= ERR_WARN;
 
+               if (curproxy->mode != PR_MODE_TCP && curproxy->mode != PR_MODE_HTTP) {
+                       ha_alert("parsing [%s:%d] : '%s' requires TCP or HTTP mode.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
                if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) {
                        ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg);
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -2517,6 +2523,12 @@ stats_error_parsing:
                 */
                curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD);
 
+               if (curproxy->mode != PR_MODE_TCP && curproxy->mode != PR_MODE_HTTP) {
+                       ha_alert("parsing [%s:%d] : '%s' requires TCP or HTTP mode.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        err_code |= ERR_WARN;
 
@@ -2577,6 +2589,12 @@ stats_error_parsing:
                }
        }
        else if (strcmp(args[0], "hash-balance-factor") == 0) {
+               if (curproxy->mode != PR_MODE_TCP && curproxy->mode != PR_MODE_HTTP) {
+                       ha_alert("parsing [%s:%d] : '%s' requires TCP or HTTP mode.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
                if (*(args[1]) == 0) {
                        ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;