]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log/balance: detect if user tries to use unsupported algo
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 28 Mar 2024 15:06:58 +0000 (16:06 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 29 Mar 2024 16:08:36 +0000 (17:08 +0100)
b61147fd ("MEDIUM: log/balance: merge tcp/http algo with log ones")
introduced some ambiguities, because while it shares some algos with the
ones from mode {tcp,http}, we forgot report an error when the user tries
to use an algorithm that is not available in this mode (as per the doc).

Because of that, haproxy would silently drop log messages during runtime.

To fix that, we ensure that algo is one of the supported ones during log
backend postparsing. If the algo is not supported, we raise an error.

This should be backported in 2.9 with b61147fd

src/log.c

index a25a5cfd963b09f25796022793a6e55abed2a0c0..c1e44779b254b6f7f9d72fa4bd4de50e15df1018 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -921,6 +921,7 @@ static void log_backend_srv_down(struct server *srv)
 static int _postcheck_log_backend_compat(struct proxy *be)
 {
        int err_code = ERR_NONE;
+       int balance_algo = (be->lbprm.algo & BE_LB_ALGO);
 
        if (!LIST_ISEMPTY(&be->tcp_req.inspect_rules) ||
            !LIST_ISEMPTY(&be->tcp_req.l4_rules) ||
@@ -978,6 +979,13 @@ static int _postcheck_log_backend_compat(struct proxy *be)
                err_code |= ERR_WARN;
                free_server_rules(&be->server_rules);
        }
+       if (balance_algo != BE_LB_ALGO_RR &&
+           balance_algo != BE_LB_ALGO_RND &&
+           balance_algo != BE_LB_ALGO_LS &&
+           balance_algo != BE_LB_ALGO_LH) {
+               ha_alert("in %s '%s': \"balance\" only supports 'roundrobin', 'random', 'sticky' and 'log-hash'.\n", proxy_type_str(be), be->id);
+               err_code |= ERR_ALERT | ERR_FATAL;
+       }
        return err_code;
 }