]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tcpcheck: Deal with disable-on-404 and send-state in the tcp-check itself
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 26 Mar 2026 08:14:58 +0000 (09:14 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Apr 2026 14:34:37 +0000 (16:34 +0200)
disable-on-404 and send-state options, configured on an HTTP healtcheck,
were handled as proxy options. Now, these options are handled in the
tcp-check itself. So the corresponding PR_O and PR_02 flags are removed.

include/haproxy/proxy-t.h
include/haproxy/tcpcheck-t.h
src/proxy.c
src/server.c
src/tcpcheck.c

index 0960de70b6c4387e9fc2d77d422bbc42c28b1672..4ab6fccb07dfbb07b5ea589c5a9e14b218fb8d03 100644 (file)
@@ -119,8 +119,7 @@ enum PR_SRV_STATE_FILE {
 
 #define PR_O_TCPCHK_SSL 0x10000000      /* at least one TCPCHECK connect rule requires SSL */
 #define PR_O_CONTSTATS  0x20000000      /* continuous counters */
-#define PR_O_DISABLE404 0x40000000      /* Disable a server on a 404 response to a health-check */
-/* unused: 0x80000000 */
+/* unused: 0x40000000..0x80000000 */
 
 /* bits for proxy->options2 */
 #define PR_O2_SPLIC_REQ        0x00000001      /* transfer requests using linux kernel's splice() */
@@ -145,7 +144,7 @@ enum PR_SRV_STATE_FILE {
 
 #define PR_O2_NODELAY   0x00020000      /* fully interactive mode, never delay outgoing data */
 #define PR_O2_USE_PXHDR 0x00040000      /* use Proxy-Connection for proxy requests */
-#define PR_O2_CHK_SNDST 0x00080000      /* send the state of each server along with HTTP health checks */
+/* unused: 0x00080000 */
 
 #define PR_O2_SRC_ADDR 0x00100000      /* get the source ip and port for logs */
 
index b35d60c7fbecff210508e9fc665c327f06223e54..a0879b65d7ca19bc0c1bdcef155902df019f0eaa 100644 (file)
@@ -109,6 +109,10 @@ enum tcpcheck_rule_type {
 #define TCPCHK_FL_UNUSED_HTTP_RS 0x00000002 /* An unused http-check ruleset exists for the current proxy  */
 #define TCPCHK_FL_UNUSED_RS      0x00000003 /* Mask for unused ruleset */
 
+#define TCPCHK_RULES_NONE         0x00000000
+#define TCPCHK_RULES_DISABLE404   0x00000001 /* Disable a server on a 404 response wht HTTP health checks */
+#define TCPCHK_RULES_SNDST        0x00000002 /* send the state of each server along with HTTP health checks */
+
 #define TCPCHK_RULES_PGSQL_CHK   0x00000010
 #define TCPCHK_RULES_REDIS_CHK   0x00000020
 #define TCPCHK_RULES_SMTP_CHK    0x00000030
index e9f9021a9898199af756a5eda0e7f0b8d954403e..494f4f5d6f90fd1490bad2ed7ad45067c23123ab 100644 (file)
@@ -1882,22 +1882,6 @@ int proxy_finalize(struct proxy *px, int *err_code)
                *err_code |= ERR_WARN;
        }
 
-       if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK &&
-           px->tcpcheck.rs && (px->tcpcheck.rs->flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) {
-               if (px->options & PR_O_DISABLE404) {
-                       ha_warning("'%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
-                                  "disable-on-404", proxy_type_str(px), px->id);
-                       *err_code |= ERR_WARN;
-                       px->options &= ~PR_O_DISABLE404;
-               }
-               if (px->options2 & PR_O2_CHK_SNDST) {
-                       ha_warning("'%s' will be ignored for %s '%s' (requires 'option httpchk').\n",
-                                  "send-state", proxy_type_str(px), px->id);
-                       *err_code |= ERR_WARN;
-                       px->options2 &= ~PR_O2_CHK_SNDST;
-               }
-       }
-
        if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
                if (!global.external_check) {
                        ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n",
index aaa04abfe4fa663ebaeda7475ba6224ad24c6110..1dcf62841282baeec7b8d2e4ca29dcaf24910300 100644 (file)
@@ -6686,12 +6686,16 @@ int srv_apply_track(struct server *srv, struct proxy *curproxy)
                return 1;
        }
 
-       if (curproxy != px &&
-           (curproxy->options & PR_O_DISABLE404) != (px->options & PR_O_DISABLE404)) {
-               ha_alert("unable to use %s/%s for"
-                        "tracking: disable-on-404 option inconsistency.\n",
-                        px->id, strack->id);
-               return 1;
+       if (curproxy != px) {
+               int val1 = curproxy->tcpcheck.rs && (curproxy->tcpcheck.rs->flags & TCPCHK_RULES_DISABLE404);
+               int val2 = px->tcpcheck.rs && (px->tcpcheck.rs->flags & TCPCHK_RULES_DISABLE404);
+
+               if (val1 != val2) {
+                       ha_alert("unable to use %s/%s for"
+                                "tracking: disable-on-404 option inconsistency.\n",
+                                px->id, strack->id);
+                       return 1;
+               }
        }
 
        srv->track = strack;
index 5844860486b3a14828ce2d5a6ccad69e1b412e44..57b13b415f0895d10c62a6a556479d4b4d3748d2 100644 (file)
@@ -1781,7 +1781,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
                        }
 
                }
-               if (check->proxy->options2 & PR_O2_CHK_SNDST) {
+               if (check->tcpcheck->rs->flags & TCPCHK_RULES_SNDST) {
                        chunk_reset(tmp);
                        httpchk_build_status_header(check->server, tmp);
                        if (!htx_add_header(htx, ist("X-Haproxy-Server-State"), ist2(b_orig(tmp), b_data(tmp))))
@@ -2005,7 +2005,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_expect_http(struct check *check, struct tcp
        check->code = sl->info.res.status;
 
        if (check->server &&
-           (check->server->proxy->options & PR_O_DISABLE404) &&
+           (check->tcpcheck->rs->flags & TCPCHK_RULES_DISABLE404) &&
            (check->server->next_state != SRV_ST_STOPPED) &&
            (check->code == 404)) {
                /* 404 may be accepted as "stopping" only if the server was up */
@@ -2611,7 +2611,7 @@ int tcpcheck_main(struct check *check)
                        enum healthcheck_status status;
 
                        if (check->server &&
-                           (check->server->proxy->options & PR_O_DISABLE404) &&
+                           (check->tcpcheck->rs->flags & TCPCHK_RULES_DISABLE404) &&
                            (check->server->next_state != SRV_ST_STOPPED) &&
                            (check->code == 404)) {
                                set_server_check_status(check, HCHK_STATUS_L7OKCD, NULL);
@@ -4350,22 +4350,6 @@ static int proxy_parse_httpcheck(char **args, int section, struct proxy *curpx,
        if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[0], NULL))
                ret = 1;
 
-       cur_arg = 1;
-       if (strcmp(args[cur_arg], "disable-on-404") == 0) {
-               /* enable a graceful server shutdown on an HTTP 404 response */
-               curpx->options |= PR_O_DISABLE404;
-               if (too_many_args(1, args, errmsg, NULL))
-                       goto error;
-               goto out;
-       }
-       else if (strcmp(args[cur_arg], "send-state") == 0) {
-               /* enable emission of the apparent state of a server in HTTP checks */
-               curpx->options2 |= PR_O2_CHK_SNDST;
-               if (too_many_args(1, args, errmsg, NULL))
-                       goto error;
-               goto out;
-       }
-
        /* Deduce the ruleset name from the proxy info */
        chunk_printf(&trash, "*http-check-%s_%s-%d",
                     ((curpx == defpx) ? "defaults" : curpx->id),
@@ -4380,6 +4364,21 @@ static int proxy_parse_httpcheck(char **args, int section, struct proxy *curpx,
                }
                rs->flags |= TCPCHK_RULES_HTTP_CHK;
        }
+       cur_arg = 1;
+       if (strcmp(args[cur_arg], "disable-on-404") == 0) {
+               /* enable a graceful server shutdown on an HTTP 404 response */
+               rs->flags |= TCPCHK_RULES_DISABLE404;
+               if (too_many_args(1, args, errmsg, NULL))
+                       goto error;
+               goto out;
+       }
+       else if (strcmp(args[cur_arg], "send-state") == 0) {
+               /* enable emission of the apparent state of a server in HTTP checks */
+               rs->flags |= TCPCHK_RULES_SNDST;
+               if (too_many_args(1, args, errmsg, NULL))
+                       goto error;
+               goto out;
+       }
 
        index = 0;
        if (!LIST_ISEMPTY(&rs->rules)) {