MINOR: tcpcheck: Deal with disable-on-404 and send-state in the tcp-check itself

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.
This commit is contained in:
Christopher Faulet 2026-03-26 09:14:58 +01:00
parent dc7c8bd2f8
commit 978119caa6
5 changed files with 34 additions and 44 deletions

View 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 */

View 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

View 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",

View 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;

View 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)) {