BUG/MINOR: check: Don't perform any check on servers defined in a frontend
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Jan 2021 16:29:45 +0000 (17:29 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Jan 2021 12:44:04 +0000 (13:44 +0100)
If a server is defined in a frontend, thus a proxy without the backend
capability, the 'check' and 'agent-check' keywords are ignored. This way, no
check is performed on an ignored server. This avoids a segfault because some
part of the tcpchecks are not fully initialized (or released for frontends
during the post-check).

In addition, an test on the server's proxy capabilities is performed when
checks or agent-checks are initialized and nothing is performed for servers
attached to a non-backend proxy.

This patch should fix the issue #1043. It must be backported as far as 2.2.

(cherry picked from commit 6ecd59326f7416dcba215f05a6674d4b9f970749)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/check.c

index 337030f..f56854b 100644 (file)
@@ -1278,7 +1278,7 @@ static int init_srv_check(struct server *srv)
        int ret = 0;
        int check_type;
 
-       if (!srv->do_check)
+       if (!srv->do_check || !(srv->proxy->cap & PR_CAP_BE))
                goto out;
 
        check_type = srv->check.tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK;
@@ -1403,7 +1403,7 @@ static int init_srv_agent_check(struct server *srv)
        const char *err;
        int ret = 0;
 
-       if (!srv->do_agent)
+       if (!srv->do_agent || !(srv->proxy->cap & PR_CAP_BE))
                goto out;
 
        /* If there is no connect rule preceding all send / expect rules, an
@@ -2763,6 +2763,12 @@ static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx,
        if (srv->do_agent)
                goto out;
 
+       if (!(curpx->cap & PR_CAP_BE)) {
+               memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability",
+                         args[*cur_arg], proxy_type_str(curpx), curpx->id);
+               return ERR_WARN;
+       }
+
        if (!rules) {
                rules = calloc(1, sizeof(*rules));
                if (!rules) {
@@ -2962,6 +2968,12 @@ static int srv_parse_no_agent_check(char **args, int *cur_arg, struct proxy *cur
 static int srv_parse_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
                           char **errmsg)
 {
+       if (!(curpx->cap & PR_CAP_BE)) {
+               memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability",
+                         args[*cur_arg], proxy_type_str(curpx), curpx->id);
+               return ERR_WARN;
+       }
+
        srv->do_check = 1;
        return 0;
 }