MINOR: check: allocate default check ruleset for every backends
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 23 Jul 2021 13:46:46 +0000 (15:46 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 6 Aug 2021 09:08:04 +0000 (11:08 +0200)
Allocate default tcp ruleset for every backend without explicit rules
defined, even if no server in the backend use check. This change is
required to implement checks for dynamic servers.

This allocation is done on check_config_validity. It must absolutely be
called before check_proxy_tcpcheck (called via post proxy check) which
allocate the implicit tcp connect rule.

src/cfgparse.c
src/check.c

index f7eac97..fafe7f7 100644 (file)
@@ -80,6 +80,7 @@
 #include <haproxy/stream.h>
 #include <haproxy/task.h>
 #include <haproxy/tcp_rules.h>
+#include <haproxy/tcpcheck.h>
 #include <haproxy/thread.h>
 #include <haproxy/time.h>
 #include <haproxy/tools.h>
@@ -3588,6 +3589,32 @@ out_uri_auth_compat:
                        /* update the mux */
                        newsrv->mux_proto = mux_ent;
                }
+
+               /* Allocate default tcp-check rules for proxies without
+                * explicit rules.
+                */
+               if (curproxy->cap & PR_CAP_BE) {
+                       if (!(curproxy->options2 & PR_O2_CHK_ANY)) {
+                               struct tcpcheck_ruleset *rs = NULL;
+                               struct tcpcheck_rules *rules = &curproxy->tcpcheck_rules;
+
+                               curproxy->options2 |= PR_O2_TCPCHK_CHK;
+
+                               rs = find_tcpcheck_ruleset("*tcp-check");
+                               if (!rs) {
+                                       rs = create_tcpcheck_ruleset("*tcp-check");
+                                       if (rs == NULL) {
+                                               ha_alert("config: %s '%s': out of memory.\n",
+                                                        proxy_type_str(curproxy), curproxy->id);
+                                               cfgerr++;
+                                       }
+                               }
+
+                               free_tcpcheck_vars(&rules->preset_vars);
+                               rules->list = &rs->rules;
+                               rules->flags = 0;
+                       }
+               }
        }
 
        /***********************************************************/
index 2d8a3bc..dbd9f56 100644 (file)
@@ -1639,30 +1639,6 @@ static int init_srv_check(struct server *srv)
        }
 
   init:
-       if (!(srv->proxy->options2 & PR_O2_CHK_ANY)) {
-               struct tcpcheck_ruleset *rs = NULL;
-               struct tcpcheck_rules *rules = &srv->proxy->tcpcheck_rules;
-               //char *errmsg = NULL;
-
-               srv->proxy->options2 &= ~PR_O2_CHK_ANY;
-               srv->proxy->options2 |= PR_O2_TCPCHK_CHK;
-
-               rs = find_tcpcheck_ruleset("*tcp-check");
-               if (!rs) {
-                       rs = create_tcpcheck_ruleset("*tcp-check");
-                       if (rs == NULL) {
-                               ha_alert("config: %s '%s': out of memory.\n",
-                                        proxy_type_str(srv->proxy), srv->proxy->id);
-                               ret |= ERR_ALERT | ERR_FATAL;
-                               goto out;
-                       }
-               }
-
-               free_tcpcheck_vars(&rules->preset_vars);
-               rules->list = &rs->rules;
-               rules->flags = 0;
-       }
-
        err = init_check(&srv->check, srv->proxy->options2 & PR_O2_CHK_ANY);
        if (err) {
                ha_alert("config: %s '%s': unable to init check for server '%s' (%s).\n",