blob: edcaf327c820780e52aa8bb24857348513ca619d [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Health-checks functions.
3 *
Willy Tarreau26c25062009-03-08 09:38:41 +01004 * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02005 * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreaubaaee002006-06-26 02:48:02 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
Willy Tarreaub8816082008-01-18 12:18:15 +010014#include <assert.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020015#include <ctype.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020016#include <errno.h>
17#include <fcntl.h>
Simon Horman0ba0e4a2015-01-30 11:23:00 +090018#include <stdarg.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020019#include <stdio.h>
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +020020#include <stdlib.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020021#include <string.h>
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +020022#include <time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020023#include <unistd.h>
Willy Tarreau9f6dc722019-03-01 11:15:10 +010024#include <sys/resource.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020025#include <sys/socket.h>
Dmitry Sivachenkocaf58982009-08-24 15:11:06 +040026#include <sys/types.h>
Simon Horman98637e52014-06-20 12:30:16 +090027#include <sys/wait.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020028#include <netinet/in.h>
Willy Tarreau1274bc42009-07-15 07:16:31 +020029#include <netinet/tcp.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030#include <arpa/inet.h>
31
Willy Tarreau122eba92020-06-04 10:15:32 +020032#include <haproxy/action.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020033#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020034#include <haproxy/arg.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020035#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020036#include <haproxy/check.h>
Willy Tarreauc13ed532020-06-02 10:22:45 +020037#include <haproxy/chunk.h>
Willy Tarreau7c18b542020-06-11 09:23:02 +020038#include <haproxy/dgram.h>
Willy Tarreaueb92deb2020-06-04 10:53:16 +020039#include <haproxy/dns.h>
Christopher Fauletb381a502020-11-25 13:47:00 +010040#include <haproxy/dynbuf-t.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020041#include <haproxy/extcheck.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020042#include <haproxy/fd.h>
43#include <haproxy/global.h>
44#include <haproxy/h1.h>
Willy Tarreaucd72d8c2020-06-02 19:11:26 +020045#include <haproxy/http.h>
Willy Tarreau87735332020-06-04 09:08:41 +020046#include <haproxy/http_htx.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020047#include <haproxy/htx.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020048#include <haproxy/istbuf.h>
49#include <haproxy/list.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020050#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020051#include <haproxy/mailers.h>
52#include <haproxy/port_range.h>
53#include <haproxy/proto_tcp.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020054#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020055#include <haproxy/proxy.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020056#include <haproxy/queue.h>
57#include <haproxy/regex.h>
58#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020059#include <haproxy/server.h>
Willy Tarreau209108d2020-06-04 20:30:20 +020060#include <haproxy/ssl_sock.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020061#include <haproxy/stats-t.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020062#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020063#include <haproxy/task.h>
Willy Tarreau51cd5952020-06-05 12:25:38 +020064#include <haproxy/tcpcheck.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020065#include <haproxy/thread.h>
66#include <haproxy/time.h>
67#include <haproxy/tools.h>
Willy Tarreaua1718922020-06-04 16:25:31 +020068#include <haproxy/vars.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020069
Olivier Houchard9130a962017-10-17 17:33:43 +020070
Christopher Faulet61cc8522020-04-20 14:54:42 +020071static int wake_srv_chk(struct conn_stream *cs);
72struct data_cb check_conn_cb = {
73 .wake = wake_srv_chk,
74 .name = "CHCK",
75};
Christopher Fauletd7e63962020-04-17 20:15:59 +020076
Christopher Faulet5d503fc2020-03-30 20:34:34 +020077
Gaetan Rivet05d692d2020-02-14 17:42:54 +010078/* Dummy frontend used to create all checks sessions. */
Willy Tarreau51cd5952020-06-05 12:25:38 +020079struct proxy checks_fe;
Christopher Faulet31dff9b2017-10-23 15:45:20 +020080
Christopher Faulet61cc8522020-04-20 14:54:42 +020081/**************************************************************************/
82/************************ Handle check results ****************************/
83/**************************************************************************/
84struct check_status {
85 short result; /* one of SRV_CHK_* */
86 char *info; /* human readable short info */
87 char *desc; /* long description */
88};
89
90struct analyze_status {
91 char *desc; /* description */
92 unsigned char lr[HANA_OBS_SIZE]; /* result for l4/l7: 0 = ignore, 1 - error, 2 - OK */
93};
94
Simon Horman63a4a822012-03-19 07:24:41 +090095static const struct check_status check_statuses[HCHK_STATUS_SIZE] = {
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010096 [HCHK_STATUS_UNKNOWN] = { CHK_RES_UNKNOWN, "UNK", "Unknown" },
97 [HCHK_STATUS_INI] = { CHK_RES_UNKNOWN, "INI", "Initializing" },
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020098 [HCHK_STATUS_START] = { /* SPECIAL STATUS*/ },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020099
Willy Tarreau23964182014-05-20 20:56:30 +0200100 /* Below we have finished checks */
101 [HCHK_STATUS_CHECKED] = { CHK_RES_NEUTRAL, "CHECKED", "No status change" },
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100102 [HCHK_STATUS_HANA] = { CHK_RES_FAILED, "HANA", "Health analyze" },
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100103
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100104 [HCHK_STATUS_SOCKERR] = { CHK_RES_FAILED, "SOCKERR", "Socket error" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200105
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100106 [HCHK_STATUS_L4OK] = { CHK_RES_PASSED, "L4OK", "Layer4 check passed" },
107 [HCHK_STATUS_L4TOUT] = { CHK_RES_FAILED, "L4TOUT", "Layer4 timeout" },
108 [HCHK_STATUS_L4CON] = { CHK_RES_FAILED, "L4CON", "Layer4 connection problem" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200109
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100110 [HCHK_STATUS_L6OK] = { CHK_RES_PASSED, "L6OK", "Layer6 check passed" },
111 [HCHK_STATUS_L6TOUT] = { CHK_RES_FAILED, "L6TOUT", "Layer6 timeout" },
112 [HCHK_STATUS_L6RSP] = { CHK_RES_FAILED, "L6RSP", "Layer6 invalid response" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200113
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100114 [HCHK_STATUS_L7TOUT] = { CHK_RES_FAILED, "L7TOUT", "Layer7 timeout" },
115 [HCHK_STATUS_L7RSP] = { CHK_RES_FAILED, "L7RSP", "Layer7 invalid response" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200116
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200117 [HCHK_STATUS_L57DATA] = { /* DUMMY STATUS */ },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200118
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100119 [HCHK_STATUS_L7OKD] = { CHK_RES_PASSED, "L7OK", "Layer7 check passed" },
120 [HCHK_STATUS_L7OKCD] = { CHK_RES_CONDPASS, "L7OKC", "Layer7 check conditionally passed" },
121 [HCHK_STATUS_L7STS] = { CHK_RES_FAILED, "L7STS", "Layer7 wrong status" },
Simon Horman98637e52014-06-20 12:30:16 +0900122
123 [HCHK_STATUS_PROCERR] = { CHK_RES_FAILED, "PROCERR", "External check error" },
124 [HCHK_STATUS_PROCTOUT] = { CHK_RES_FAILED, "PROCTOUT", "External check timeout" },
Cyril Bonté77010d82014-08-07 01:55:37 +0200125 [HCHK_STATUS_PROCOK] = { CHK_RES_PASSED, "PROCOK", "External check passed" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200126};
127
Simon Horman63a4a822012-03-19 07:24:41 +0900128static const struct analyze_status analyze_statuses[HANA_STATUS_SIZE] = { /* 0: ignore, 1: error, 2: OK */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100129 [HANA_STATUS_UNKNOWN] = { "Unknown", { 0, 0 }},
130
131 [HANA_STATUS_L4_OK] = { "L4 successful connection", { 2, 0 }},
132 [HANA_STATUS_L4_ERR] = { "L4 unsuccessful connection", { 1, 1 }},
133
134 [HANA_STATUS_HTTP_OK] = { "Correct http response", { 0, 2 }},
135 [HANA_STATUS_HTTP_STS] = { "Wrong http response", { 0, 1 }},
136 [HANA_STATUS_HTTP_HDRRSP] = { "Invalid http response (headers)", { 0, 1 }},
137 [HANA_STATUS_HTTP_RSP] = { "Invalid http response", { 0, 1 }},
138
139 [HANA_STATUS_HTTP_READ_ERROR] = { "Read error (http)", { 0, 1 }},
140 [HANA_STATUS_HTTP_READ_TIMEOUT] = { "Read timeout (http)", { 0, 1 }},
141 [HANA_STATUS_HTTP_BROKEN_PIPE] = { "Close from server (http)", { 0, 1 }},
142};
143
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100144/* checks if <err> is a real error for errno or one that can be ignored, and
145 * return 0 for these ones or <err> for real ones.
146 */
147static inline int unclean_errno(int err)
148{
149 if (err == EAGAIN || err == EINPROGRESS ||
150 err == EISCONN || err == EALREADY)
151 return 0;
152 return err;
153}
154
Christopher Faulet61cc8522020-04-20 14:54:42 +0200155/* Converts check_status code to description */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200156const char *get_check_status_description(short check_status) {
157
158 const char *desc;
159
160 if (check_status < HCHK_STATUS_SIZE)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200161 desc = check_statuses[check_status].desc;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200162 else
163 desc = NULL;
164
165 if (desc && *desc)
166 return desc;
167 else
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200168 return check_statuses[HCHK_STATUS_UNKNOWN].desc;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200169}
170
Christopher Faulet61cc8522020-04-20 14:54:42 +0200171/* Converts check_status code to short info */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200172const char *get_check_status_info(short check_status) {
173
174 const char *info;
175
176 if (check_status < HCHK_STATUS_SIZE)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200177 info = check_statuses[check_status].info;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200178 else
179 info = NULL;
180
181 if (info && *info)
182 return info;
183 else
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200184 return check_statuses[HCHK_STATUS_UNKNOWN].info;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200185}
186
Christopher Faulet61cc8522020-04-20 14:54:42 +0200187/* Convert analyze_status to description */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100188const char *get_analyze_status(short analyze_status) {
189
190 const char *desc;
191
192 if (analyze_status < HANA_STATUS_SIZE)
193 desc = analyze_statuses[analyze_status].desc;
194 else
195 desc = NULL;
196
197 if (desc && *desc)
198 return desc;
199 else
200 return analyze_statuses[HANA_STATUS_UNKNOWN].desc;
201}
202
Christopher Faulet61cc8522020-04-20 14:54:42 +0200203/* Sets check->status, update check->duration and fill check->result with an
204 * adequate CHK_RES_* value. The new check->health is computed based on the
205 * result.
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200206 *
Christopher Faulet61cc8522020-04-20 14:54:42 +0200207 * Shows information in logs about failed health check if server is UP or
208 * succeeded health checks if server is DOWN.
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200209 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200210void set_server_check_status(struct check *check, short status, const char *desc)
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100211{
Simon Horman4a741432013-02-23 15:35:38 +0900212 struct server *s = check->server;
Willy Tarreaubef1b322014-05-13 21:01:39 +0200213 short prev_status = check->status;
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200214 int report = 0;
Simon Horman4a741432013-02-23 15:35:38 +0900215
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200216 if (status == HCHK_STATUS_START) {
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100217 check->result = CHK_RES_UNKNOWN; /* no result yet */
Simon Horman4a741432013-02-23 15:35:38 +0900218 check->desc[0] = '\0';
219 check->start = now;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200220 return;
221 }
222
Simon Horman4a741432013-02-23 15:35:38 +0900223 if (!check->status)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200224 return;
225
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200226 if (desc && *desc) {
Simon Horman4a741432013-02-23 15:35:38 +0900227 strncpy(check->desc, desc, HCHK_DESC_LEN-1);
228 check->desc[HCHK_DESC_LEN-1] = '\0';
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200229 } else
Simon Horman4a741432013-02-23 15:35:38 +0900230 check->desc[0] = '\0';
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200231
Simon Horman4a741432013-02-23 15:35:38 +0900232 check->status = status;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200233 if (check_statuses[status].result)
Simon Horman4a741432013-02-23 15:35:38 +0900234 check->result = check_statuses[status].result;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200235
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100236 if (status == HCHK_STATUS_HANA)
Simon Horman4a741432013-02-23 15:35:38 +0900237 check->duration = -1;
238 else if (!tv_iszero(&check->start)) {
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200239 /* set_server_check_status() may be called more than once */
Simon Horman4a741432013-02-23 15:35:38 +0900240 check->duration = tv_ms_elapsed(&check->start, &now);
241 tv_zero(&check->start);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200242 }
243
Willy Tarreau23964182014-05-20 20:56:30 +0200244 /* no change is expected if no state change occurred */
245 if (check->result == CHK_RES_NEUTRAL)
246 return;
247
Olivier Houchard0923fa42019-01-11 18:43:04 +0100248 /* If the check was really just sending a mail, it won't have an
249 * associated server, so we're done now.
250 */
251 if (!s)
252 return;
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200253 report = 0;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200254
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200255 switch (check->result) {
256 case CHK_RES_FAILED:
Willy Tarreau12634e12014-05-23 11:32:36 +0200257 /* Failure to connect to the agent as a secondary check should not
258 * cause the server to be marked down.
259 */
260 if ((!(check->state & CHK_ST_AGENT) ||
Simon Hormaneaabd522015-02-26 11:26:17 +0900261 (check->status >= HCHK_STATUS_L57DATA)) &&
Christopher Fauletb119a792018-05-02 12:12:45 +0200262 (check->health > 0)) {
Olivier Houchard7059c552019-03-08 18:49:32 +0100263 _HA_ATOMIC_ADD(&s->counters.failed_checks, 1);
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200264 report = 1;
265 check->health--;
266 if (check->health < check->rise)
267 check->health = 0;
268 }
269 break;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200270
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200271 case CHK_RES_PASSED:
Christopher Faulet1e527cb2020-11-20 18:13:02 +0100272 case CHK_RES_CONDPASS:
273 if (check->health < check->rise + check->fall - 1) {
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200274 report = 1;
275 check->health++;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200276
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200277 if (check->health >= check->rise)
278 check->health = check->rise + check->fall - 1; /* OK now */
279 }
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200280
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200281 /* clear consecutive_errors if observing is enabled */
282 if (s->onerror)
283 s->consecutive_errors = 0;
284 break;
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100285
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200286 default:
287 break;
288 }
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200289
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200290 if (s->proxy->options2 & PR_O2_LOGHCHKS &&
291 (status != prev_status || report)) {
292 chunk_printf(&trash,
Willy Tarreau12634e12014-05-23 11:32:36 +0200293 "%s check for %sserver %s/%s %s%s",
294 (check->state & CHK_ST_AGENT) ? "Agent" : "Health",
Willy Tarreauc93cd162014-05-13 15:54:22 +0200295 s->flags & SRV_F_BACKUP ? "backup " : "",
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100296 s->proxy->id, s->id,
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100297 (check->result == CHK_RES_CONDPASS) ? "conditionally ":"",
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200298 (check->result >= CHK_RES_PASSED) ? "succeeded" : "failed");
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200299
Emeric Brun5a133512017-10-19 14:42:30 +0200300 srv_append_status(&trash, s, check, -1, 0);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200301
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100302 chunk_appendf(&trash, ", status: %d/%d %s",
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200303 (check->health >= check->rise) ? check->health - check->rise + 1 : check->health,
304 (check->health >= check->rise) ? check->fall : check->rise,
305 (check->health >= check->rise) ? (s->uweight ? "UP" : "DRAIN") : "DOWN");
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200306
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200307 ha_warning("%s.\n", trash.area);
308 send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.area);
309 send_email_alert(s, LOG_INFO, "%s", trash.area);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200310 }
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200311}
312
Willy Tarreau4eec5472014-05-20 22:32:27 +0200313/* Marks the check <check>'s server down if the current check is already failed
314 * and the server is not down yet nor in maintenance.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200315 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200316void check_notify_failure(struct check *check)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200317{
Simon Horman4a741432013-02-23 15:35:38 +0900318 struct server *s = check->server;
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900319
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200320 /* The agent secondary check should only cause a server to be marked
321 * as down if check->status is HCHK_STATUS_L7STS, which indicates
322 * that the agent returned "fail", "stopped" or "down".
323 * The implication here is that failure to connect to the agent
324 * as a secondary check should not cause the server to be marked
325 * down. */
326 if ((check->state & CHK_ST_AGENT) && check->status != HCHK_STATUS_L7STS)
327 return;
328
Willy Tarreau4eec5472014-05-20 22:32:27 +0200329 if (check->health > 0)
330 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100331
Willy Tarreau4eec5472014-05-20 22:32:27 +0200332 /* We only report a reason for the check if we did not do so previously */
Emeric Brun5a133512017-10-19 14:42:30 +0200333 srv_set_stopped(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200334}
335
Willy Tarreauaf549582014-05-16 17:37:50 +0200336/* Marks the check <check> as valid and tries to set its server up, provided
Willy Tarreau3e048382014-05-21 10:30:54 +0200337 * it isn't in maintenance, it is not tracking a down server and other checks
338 * comply. The rule is simple : by default, a server is up, unless any of the
339 * following conditions is true :
340 * - health check failed (check->health < rise)
341 * - agent check failed (agent->health < rise)
342 * - the server tracks a down server (track && track->state == STOPPED)
343 * Note that if the server has a slowstart, it will switch to STARTING instead
344 * of RUNNING. Also, only the health checks support the nolb mode, so the
345 * agent's success may not take the server out of this mode.
Willy Tarreauaf549582014-05-16 17:37:50 +0200346 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200347void check_notify_success(struct check *check)
Willy Tarreauaf549582014-05-16 17:37:50 +0200348{
Simon Horman4a741432013-02-23 15:35:38 +0900349 struct server *s = check->server;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100350
Emeric Brun52a91d32017-08-31 14:41:55 +0200351 if (s->next_admin & SRV_ADMF_MAINT)
Willy Tarreauaf549582014-05-16 17:37:50 +0200352 return;
Cyril Bontécd19e512010-01-31 22:34:03 +0100353
Emeric Brun52a91d32017-08-31 14:41:55 +0200354 if (s->track && s->track->next_state == SRV_ST_STOPPED)
Willy Tarreauaf549582014-05-16 17:37:50 +0200355 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100356
Willy Tarreau3e048382014-05-21 10:30:54 +0200357 if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise))
358 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100359
Willy Tarreau3e048382014-05-21 10:30:54 +0200360 if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise))
361 return;
Willy Tarreauaf549582014-05-16 17:37:50 +0200362
Emeric Brun52a91d32017-08-31 14:41:55 +0200363 if ((check->state & CHK_ST_AGENT) && s->next_state == SRV_ST_STOPPING)
Willy Tarreau3e048382014-05-21 10:30:54 +0200364 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100365
Emeric Brun5a133512017-10-19 14:42:30 +0200366 srv_set_running(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100367}
368
Willy Tarreaudb58b792014-05-21 13:57:23 +0200369/* Marks the check <check> as valid and tries to set its server into stopping mode
370 * if it was running or starting, and provided it isn't in maintenance and other
371 * checks comply. The conditions for the server to be marked in stopping mode are
372 * the same as for it to be turned up. Also, only the health checks support the
373 * nolb mode.
Willy Tarreauaf549582014-05-16 17:37:50 +0200374 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200375void check_notify_stopping(struct check *check)
Willy Tarreauaf549582014-05-16 17:37:50 +0200376{
Simon Horman4a741432013-02-23 15:35:38 +0900377 struct server *s = check->server;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100378
Emeric Brun52a91d32017-08-31 14:41:55 +0200379 if (s->next_admin & SRV_ADMF_MAINT)
Willy Tarreauaf549582014-05-16 17:37:50 +0200380 return;
381
Willy Tarreaudb58b792014-05-21 13:57:23 +0200382 if (check->state & CHK_ST_AGENT)
383 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100384
Emeric Brun52a91d32017-08-31 14:41:55 +0200385 if (s->track && s->track->next_state == SRV_ST_STOPPED)
Willy Tarreaudb58b792014-05-21 13:57:23 +0200386 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100387
Willy Tarreaudb58b792014-05-21 13:57:23 +0200388 if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise))
389 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100390
Willy Tarreaudb58b792014-05-21 13:57:23 +0200391 if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise))
392 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100393
Willy Tarreaub26881a2017-12-23 11:16:49 +0100394 srv_set_stopping(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100395}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200396
Willy Tarreau9fe7aae2013-12-31 23:47:37 +0100397/* note: use health_adjust() only, which first checks that the observe mode is
398 * enabled.
399 */
400void __health_adjust(struct server *s, short status)
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100401{
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100402 int failed;
403 int expire;
404
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100405 if (s->observe >= HANA_OBS_SIZE)
406 return;
407
Willy Tarreaubb956662013-01-24 00:37:39 +0100408 if (status >= HANA_STATUS_SIZE || !analyze_statuses[status].desc)
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100409 return;
410
411 switch (analyze_statuses[status].lr[s->observe - 1]) {
412 case 1:
413 failed = 1;
414 break;
415
416 case 2:
417 failed = 0;
418 break;
419
420 default:
421 return;
422 }
423
424 if (!failed) {
425 /* good: clear consecutive_errors */
426 s->consecutive_errors = 0;
427 return;
428 }
429
Olivier Houchard7059c552019-03-08 18:49:32 +0100430 _HA_ATOMIC_ADD(&s->consecutive_errors, 1);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100431
432 if (s->consecutive_errors < s->consecutive_errors_limit)
433 return;
434
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100435 chunk_printf(&trash, "Detected %d consecutive errors, last one was: %s",
436 s->consecutive_errors, get_analyze_status(status));
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100437
438 switch (s->onerror) {
439 case HANA_ONERR_FASTINTER:
440 /* force fastinter - nothing to do here as all modes force it */
441 break;
442
443 case HANA_ONERR_SUDDTH:
444 /* simulate a pre-fatal failed health check */
Simon Horman58c32972013-11-25 10:46:38 +0900445 if (s->check.health > s->check.rise)
446 s->check.health = s->check.rise + 1;
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100447
Tim Duesterhus588b3142020-05-29 14:35:51 +0200448 /* fall through */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100449
450 case HANA_ONERR_FAILCHK:
451 /* simulate a failed health check */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200452 set_server_check_status(&s->check, HCHK_STATUS_HANA,
453 trash.area);
Willy Tarreau4eec5472014-05-20 22:32:27 +0200454 check_notify_failure(&s->check);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100455 break;
456
457 case HANA_ONERR_MARKDWN:
458 /* mark server down */
Simon Horman58c32972013-11-25 10:46:38 +0900459 s->check.health = s->check.rise;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200460 set_server_check_status(&s->check, HCHK_STATUS_HANA,
461 trash.area);
Willy Tarreau4eec5472014-05-20 22:32:27 +0200462 check_notify_failure(&s->check);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100463 break;
464
465 default:
466 /* write a warning? */
467 break;
468 }
469
470 s->consecutive_errors = 0;
Olivier Houchard7059c552019-03-08 18:49:32 +0100471 _HA_ATOMIC_ADD(&s->counters.failed_hana, 1);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100472
Simon Horman66183002013-02-23 10:16:43 +0900473 if (s->check.fastinter) {
474 expire = tick_add(now_ms, MS_TO_TICKS(s->check.fastinter));
Sergiy Prykhodko1d57e502013-09-21 12:05:00 +0300475 if (s->check.task->expire > expire) {
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200476 s->check.task->expire = expire;
Sergiy Prykhodko1d57e502013-09-21 12:05:00 +0300477 /* requeue check task with new expire */
478 task_queue(s->check.task);
479 }
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100480 }
Willy Tarreauef781042010-01-27 11:53:01 +0100481}
482
Christopher Faulet61cc8522020-04-20 14:54:42 +0200483/* Checks the connection. If an error has already been reported or the socket is
Willy Tarreau20a18342013-12-05 00:31:46 +0100484 * closed, keep errno intact as it is supposed to contain the valid error code.
485 * If no error is reported, check the socket's error queue using getsockopt().
486 * Warning, this must be done only once when returning from poll, and never
487 * after an I/O error was attempted, otherwise the error queue might contain
488 * inconsistent errors. If an error is detected, the CO_FL_ERROR is set on the
489 * socket. Returns non-zero if an error was reported, zero if everything is
490 * clean (including a properly closed socket).
491 */
492static int retrieve_errno_from_socket(struct connection *conn)
493{
494 int skerr;
495 socklen_t lskerr = sizeof(skerr);
496
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100497 if (conn->flags & CO_FL_ERROR && (unclean_errno(errno) || !conn->ctrl))
Willy Tarreau20a18342013-12-05 00:31:46 +0100498 return 1;
499
Willy Tarreau3c728722014-01-23 13:50:42 +0100500 if (!conn_ctrl_ready(conn))
Willy Tarreau20a18342013-12-05 00:31:46 +0100501 return 0;
502
Willy Tarreau585744b2017-08-24 14:31:19 +0200503 if (getsockopt(conn->handle.fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == 0)
Willy Tarreau20a18342013-12-05 00:31:46 +0100504 errno = skerr;
505
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100506 errno = unclean_errno(errno);
Willy Tarreau20a18342013-12-05 00:31:46 +0100507
508 if (!errno) {
509 /* we could not retrieve an error, that does not mean there is
510 * none. Just don't change anything and only report the prior
511 * error if any.
512 */
513 if (conn->flags & CO_FL_ERROR)
514 return 1;
515 else
516 return 0;
517 }
518
519 conn->flags |= CO_FL_ERROR | CO_FL_SOCK_WR_SH | CO_FL_SOCK_RD_SH;
520 return 1;
521}
522
Christopher Faulet61cc8522020-04-20 14:54:42 +0200523/* Tries to collect as much information as possible on the connection status,
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100524 * and adjust the server status accordingly. It may make use of <errno_bck>
525 * if non-null when the caller is absolutely certain of its validity (eg:
526 * checked just after a syscall). If the caller doesn't have a valid errno,
527 * it can pass zero, and retrieve_errno_from_socket() will be called to try
528 * to extract errno from the socket. If no error is reported, it will consider
529 * the <expired> flag. This is intended to be used when a connection error was
530 * reported in conn->flags or when a timeout was reported in <expired>. The
531 * function takes care of not updating a server status which was already set.
532 * All situations where at least one of <expired> or CO_FL_ERROR are set
533 * produce a status.
534 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200535void chk_report_conn_err(struct check *check, int errno_bck, int expired)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100536{
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200537 struct conn_stream *cs = check->cs;
538 struct connection *conn = cs_conn(cs);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100539 const char *err_msg;
Willy Tarreau83061a82018-07-13 11:56:34 +0200540 struct buffer *chk;
Willy Tarreau213c6782014-10-02 14:51:02 +0200541 int step;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100542
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100543 if (check->result != CHK_RES_UNKNOWN)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100544 return;
545
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100546 errno = unclean_errno(errno_bck);
547 if (conn && errno)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100548 retrieve_errno_from_socket(conn);
549
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200550 if (conn && !(conn->flags & CO_FL_ERROR) &&
551 !(cs->flags & CS_FL_ERROR) && !expired)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100552 return;
553
554 /* we'll try to build a meaningful error message depending on the
555 * context of the error possibly present in conn->err_code, and the
556 * socket error possibly collected above. This is useful to know the
557 * exact step of the L6 layer (eg: SSL handshake).
558 */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200559 chk = get_trash_chunk();
560
Christopher Faulet799f3a42020-04-07 12:06:14 +0200561 if (check->type == PR_O2_TCPCHK_CHK &&
Christopher Fauletd7e63962020-04-17 20:15:59 +0200562 (check->tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK) == TCPCHK_RULES_TCP_CHK) {
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200563 step = tcpcheck_get_step_id(check, NULL);
Willy Tarreau213c6782014-10-02 14:51:02 +0200564 if (!step)
565 chunk_printf(chk, " at initial connection step of tcp-check");
566 else {
567 chunk_printf(chk, " at step %d of tcp-check", step);
568 /* we were looking for a string */
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200569 if (check->current_step && check->current_step->action == TCPCHK_ACT_CONNECT) {
570 if (check->current_step->connect.port)
571 chunk_appendf(chk, " (connect port %d)" ,check->current_step->connect.port);
Willy Tarreau213c6782014-10-02 14:51:02 +0200572 else
573 chunk_appendf(chk, " (connect)");
574 }
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200575 else if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT) {
576 struct tcpcheck_expect *expect = &check->current_step->expect;
Gaetan Rivetb616add2020-02-07 15:37:17 +0100577
578 switch (expect->type) {
579 case TCPCHK_EXPECT_STRING:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200580 chunk_appendf(chk, " (expect string '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Gaetan Rivetb616add2020-02-07 15:37:17 +0100581 break;
582 case TCPCHK_EXPECT_BINARY:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200583 chunk_appendf(chk, " (expect binary '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Gaetan Rivetb616add2020-02-07 15:37:17 +0100584 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200585 case TCPCHK_EXPECT_STRING_REGEX:
Willy Tarreau213c6782014-10-02 14:51:02 +0200586 chunk_appendf(chk, " (expect regex)");
Gaetan Rivetb616add2020-02-07 15:37:17 +0100587 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200588 case TCPCHK_EXPECT_BINARY_REGEX:
Gaetan Rivetefab6c62020-02-07 15:37:17 +0100589 chunk_appendf(chk, " (expect binary regex)");
590 break;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200591 case TCPCHK_EXPECT_STRING_LF:
592 chunk_appendf(chk, " (expect log-format string)");
593 break;
594 case TCPCHK_EXPECT_BINARY_LF:
595 chunk_appendf(chk, " (expect log-format binary)");
596 break;
Christopher Faulete5870d82020-04-15 11:32:03 +0200597 case TCPCHK_EXPECT_HTTP_STATUS:
Christopher Faulet8021a5f2020-04-24 13:53:12 +0200598 chunk_appendf(chk, " (expect HTTP status codes)");
Christopher Faulete5870d82020-04-15 11:32:03 +0200599 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200600 case TCPCHK_EXPECT_HTTP_STATUS_REGEX:
Christopher Faulete5870d82020-04-15 11:32:03 +0200601 chunk_appendf(chk, " (expect HTTP status regex)");
602 break;
Christopher Faulet39708192020-05-05 10:47:36 +0200603 case TCPCHK_EXPECT_HTTP_HEADER:
604 chunk_appendf(chk, " (expect HTTP header pattern)");
605 break;
Christopher Faulete5870d82020-04-15 11:32:03 +0200606 case TCPCHK_EXPECT_HTTP_BODY:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200607 chunk_appendf(chk, " (expect HTTP body content '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Christopher Faulete5870d82020-04-15 11:32:03 +0200608 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200609 case TCPCHK_EXPECT_HTTP_BODY_REGEX:
Christopher Faulete5870d82020-04-15 11:32:03 +0200610 chunk_appendf(chk, " (expect HTTP body regex)");
611 break;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200612 case TCPCHK_EXPECT_HTTP_BODY_LF:
613 chunk_appendf(chk, " (expect log-format HTTP body)");
614 break;
Christopher Faulet9e6ed152020-04-03 15:24:06 +0200615 case TCPCHK_EXPECT_CUSTOM:
616 chunk_appendf(chk, " (expect custom function)");
617 break;
Gaetan Rivetb616add2020-02-07 15:37:17 +0100618 case TCPCHK_EXPECT_UNDEF:
619 chunk_appendf(chk, " (undefined expect!)");
620 break;
621 }
Willy Tarreau213c6782014-10-02 14:51:02 +0200622 }
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200623 else if (check->current_step && check->current_step->action == TCPCHK_ACT_SEND) {
Willy Tarreau213c6782014-10-02 14:51:02 +0200624 chunk_appendf(chk, " (send)");
625 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +0200626
Christopher Faulet6f2a5e42020-04-01 13:11:41 +0200627 if (check->current_step && check->current_step->comment)
628 chunk_appendf(chk, " comment: '%s'", check->current_step->comment);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200629 }
630 }
631
Willy Tarreau00149122017-10-04 18:05:01 +0200632 if (conn && conn->err_code) {
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100633 if (unclean_errno(errno))
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200634 chunk_printf(&trash, "%s (%s)%s", conn_err_code_str(conn), strerror(errno),
635 chk->area);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100636 else
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200637 chunk_printf(&trash, "%s%s", conn_err_code_str(conn),
638 chk->area);
639 err_msg = trash.area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100640 }
641 else {
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100642 if (unclean_errno(errno)) {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200643 chunk_printf(&trash, "%s%s", strerror(errno),
644 chk->area);
645 err_msg = trash.area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100646 }
647 else {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200648 err_msg = chk->area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100649 }
650 }
651
Willy Tarreau00149122017-10-04 18:05:01 +0200652 if (check->state & CHK_ST_PORT_MISS) {
Baptiste Assmann95db2bc2016-06-13 14:15:41 +0200653 /* NOTE: this is reported after <fall> tries */
654 chunk_printf(chk, "No port available for the TCP connection");
655 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
656 }
657
Christopher Faulet5e293762020-10-26 11:10:49 +0100658 if (!conn || !conn->ctrl) {
659 /* error before any connection attempt (connection allocation error or no control layer) */
Willy Tarreau00149122017-10-04 18:05:01 +0200660 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
661 }
Willy Tarreauc192b0a2020-01-23 09:11:58 +0100662 else if (conn->flags & CO_FL_WAIT_L4_CONN) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100663 /* L4 not established (yet) */
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200664 if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100665 set_server_check_status(check, HCHK_STATUS_L4CON, err_msg);
666 else if (expired)
667 set_server_check_status(check, HCHK_STATUS_L4TOUT, err_msg);
Baptiste Assmanna68ca962015-04-14 01:15:08 +0200668
669 /*
670 * might be due to a server IP change.
671 * Let's trigger a DNS resolution if none are currently running.
672 */
Olivier Houchard0923fa42019-01-11 18:43:04 +0100673 if (check->server)
674 dns_trigger_resolution(check->server->dns_requester);
Baptiste Assmanna68ca962015-04-14 01:15:08 +0200675
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100676 }
Willy Tarreauc192b0a2020-01-23 09:11:58 +0100677 else if (conn->flags & CO_FL_WAIT_L6_CONN) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100678 /* L6 not established (yet) */
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200679 if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100680 set_server_check_status(check, HCHK_STATUS_L6RSP, err_msg);
681 else if (expired)
682 set_server_check_status(check, HCHK_STATUS_L6TOUT, err_msg);
683 }
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200684 else if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100685 /* I/O error after connection was established and before we could diagnose */
686 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
687 }
688 else if (expired) {
Christopher Fauletcf80f2f2020-04-01 11:04:52 +0200689 enum healthcheck_status tout = HCHK_STATUS_L7TOUT;
690
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100691 /* connection established but expired check */
Christopher Faulet1941bab2020-05-05 07:55:50 +0200692 if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT &&
693 check->current_step->expect.tout_status != HCHK_STATUS_UNKNOWN)
Christopher Faulet811f78c2020-04-01 11:10:27 +0200694 tout = check->current_step->expect.tout_status;
695 set_server_check_status(check, tout, err_msg);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100696 }
697
698 return;
699}
700
Simon Horman98637e52014-06-20 12:30:16 +0900701
Christopher Faulet61cc8522020-04-20 14:54:42 +0200702/* Builds the server state header used by HTTP health-checks */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200703int httpchk_build_status_header(struct server *s, struct buffer *buf)
Simon Horman98637e52014-06-20 12:30:16 +0900704{
Christopher Faulet61cc8522020-04-20 14:54:42 +0200705 int sv_state;
706 int ratio;
707 char addr[46];
708 char port[6];
709 const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d",
710 "UP %d/%d", "UP",
711 "NOLB %d/%d", "NOLB",
712 "no check" };
Simon Horman98637e52014-06-20 12:30:16 +0900713
Christopher Faulet61cc8522020-04-20 14:54:42 +0200714 if (!(s->check.state & CHK_ST_ENABLED))
715 sv_state = 6;
716 else if (s->cur_state != SRV_ST_STOPPED) {
717 if (s->check.health == s->check.rise + s->check.fall - 1)
718 sv_state = 3; /* UP */
719 else
720 sv_state = 2; /* going down */
Simon Horman98637e52014-06-20 12:30:16 +0900721
Christopher Faulet61cc8522020-04-20 14:54:42 +0200722 if (s->cur_state == SRV_ST_STOPPING)
723 sv_state += 2;
724 } else {
725 if (s->check.health)
726 sv_state = 1; /* going up */
727 else
728 sv_state = 0; /* DOWN */
Simon Horman98637e52014-06-20 12:30:16 +0900729 }
Willy Tarreaub7b24782016-06-21 15:32:29 +0200730
Christopher Faulet61cc8522020-04-20 14:54:42 +0200731 chunk_appendf(buf, srv_hlt_st[sv_state],
732 (s->cur_state != SRV_ST_STOPPED) ? (s->check.health - s->check.rise + 1) : (s->check.health),
733 (s->cur_state != SRV_ST_STOPPED) ? (s->check.fall) : (s->check.rise));
Willy Tarreaub7b24782016-06-21 15:32:29 +0200734
Christopher Faulet61cc8522020-04-20 14:54:42 +0200735 addr_to_str(&s->addr, addr, sizeof(addr));
736 if (s->addr.ss_family == AF_INET || s->addr.ss_family == AF_INET6)
737 snprintf(port, sizeof(port), "%u", s->svc_port);
738 else
739 *port = 0;
Willy Tarreaub7b24782016-06-21 15:32:29 +0200740
Christopher Faulet61cc8522020-04-20 14:54:42 +0200741 chunk_appendf(buf, "; address=%s; port=%s; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d",
742 addr, port, s->proxy->id, s->id,
743 global.node,
744 (s->cur_eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
745 (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
746 s->cur_sess, s->proxy->beconn - s->proxy->nbpend,
747 s->nbpend);
Willy Tarreau9f6dc722019-03-01 11:15:10 +0100748
Christopher Faulet61cc8522020-04-20 14:54:42 +0200749 if ((s->cur_state == SRV_ST_STARTING) &&
750 now.tv_sec < s->last_change + s->slowstart &&
751 now.tv_sec >= s->last_change) {
752 ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart);
753 chunk_appendf(buf, "; throttle=%d%%", ratio);
754 }
Christopher Fauletaaae9a02020-04-26 09:50:31 +0200755
Christopher Faulet61cc8522020-04-20 14:54:42 +0200756 return b_data(buf);
757}
Christopher Fauletaaae9a02020-04-26 09:50:31 +0200758
Willy Tarreau51cd5952020-06-05 12:25:38 +0200759/**************************************************************************/
Willy Tarreau51cd5952020-06-05 12:25:38 +0200760/***************** Health-checks based on connections *********************/
761/**************************************************************************/
762/* This function is used only for server health-checks. It handles connection
763 * status updates including errors. If necessary, it wakes the check task up.
764 * It returns 0 on normal cases, <0 if at least one close() has happened on the
765 * connection (eg: reconnect). It relies on tcpcheck_main().
Christopher Faulet61cc8522020-04-20 14:54:42 +0200766 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200767static int wake_srv_chk(struct conn_stream *cs)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200768{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200769 struct connection *conn = cs->conn;
770 struct check *check = cs->data;
771 struct email_alertq *q = container_of(check, typeof(*q), check);
772 int ret = 0;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200773
Willy Tarreau51cd5952020-06-05 12:25:38 +0200774 if (check->server)
775 HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock);
776 else
777 HA_SPIN_LOCK(EMAIL_ALERTS_LOCK, &q->lock);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200778
Willy Tarreau51cd5952020-06-05 12:25:38 +0200779 /* we may have to make progress on the TCP checks */
780 ret = tcpcheck_main(check);
Christopher Fauletaaab0832020-05-05 15:54:22 +0200781
Willy Tarreau51cd5952020-06-05 12:25:38 +0200782 cs = check->cs;
783 conn = cs->conn;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200784
Willy Tarreau51cd5952020-06-05 12:25:38 +0200785 if (unlikely(conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)) {
786 /* We may get error reports bypassing the I/O handlers, typically
787 * the case when sending a pure TCP check which fails, then the I/O
788 * handlers above are not called. This is completely handled by the
789 * main processing task so let's simply wake it up. If we get here,
790 * we expect errno to still be valid.
791 */
792 chk_report_conn_err(check, errno, 0);
793 task_wakeup(check->task, TASK_WOKEN_IO);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200794 }
795
Willy Tarreau51cd5952020-06-05 12:25:38 +0200796 if (check->result != CHK_RES_UNKNOWN) {
797 /* Check complete or aborted. If connection not yet closed do it
798 * now and wake the check task up to be sure the result is
799 * handled ASAP. */
800 conn_sock_drain(conn);
801 cs_close(cs);
802 ret = -1;
803 /* We may have been scheduled to run, and the
804 * I/O handler expects to have a cs, so remove
805 * the tasklet
806 */
807 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
808 task_wakeup(check->task, TASK_WOKEN_IO);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200809 }
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200810
Willy Tarreau51cd5952020-06-05 12:25:38 +0200811 if (check->server)
812 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
813 else
814 HA_SPIN_UNLOCK(EMAIL_ALERTS_LOCK, &q->lock);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200815
Willy Tarreau51cd5952020-06-05 12:25:38 +0200816 /* if a connection got replaced, we must absolutely prevent the connection
817 * handler from touching its fd, and perform the FD polling updates ourselves
818 */
819 if (ret < 0)
820 conn_cond_update_polling(conn);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200821
Christopher Faulet61cc8522020-04-20 14:54:42 +0200822 return ret;
823}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200824
Willy Tarreau51cd5952020-06-05 12:25:38 +0200825/* This function checks if any I/O is wanted, and if so, attempts to do so */
826static struct task *event_srv_chk_io(struct task *t, void *ctx, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200827{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200828 struct check *check = ctx;
829 struct conn_stream *cs = check->cs;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200830
Willy Tarreau51cd5952020-06-05 12:25:38 +0200831 wake_srv_chk(cs);
832 return NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200833}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200834
Willy Tarreau51cd5952020-06-05 12:25:38 +0200835/* manages a server health-check that uses a connection. Returns
836 * the time the task accepts to wait, or TIME_ETERNITY for infinity.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200837 *
838 * Please do NOT place any return statement in this function and only leave
Willy Tarreau51cd5952020-06-05 12:25:38 +0200839 * via the out_unlock label.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200840 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200841static struct task *process_chk_conn(struct task *t, void *context, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200842{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200843 struct check *check = context;
844 struct proxy *proxy = check->proxy;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200845 struct conn_stream *cs = check->cs;
846 struct connection *conn = cs_conn(cs);
Willy Tarreau51cd5952020-06-05 12:25:38 +0200847 int rv;
848 int expired = tick_is_expired(t->expire, now_ms);
Willy Tarreaudeccd112018-06-14 18:38:55 +0200849
Willy Tarreau51cd5952020-06-05 12:25:38 +0200850 if (check->server)
851 HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock);
852 if (!(check->state & CHK_ST_INPROGRESS)) {
853 /* no check currently running */
854 if (!expired) /* woke up too early */
855 goto out_unlock;
Willy Tarreauabca5b62013-12-06 14:19:25 +0100856
Willy Tarreau51cd5952020-06-05 12:25:38 +0200857 /* we don't send any health-checks when the proxy is
858 * stopped, the server should not be checked or the check
859 * is disabled.
860 */
861 if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) ||
Willy Tarreauc3914d42020-09-24 08:39:22 +0200862 proxy->disabled)
Willy Tarreau51cd5952020-06-05 12:25:38 +0200863 goto reschedule;
Christopher Faulet404f9192020-04-09 23:13:54 +0200864
Willy Tarreau51cd5952020-06-05 12:25:38 +0200865 /* we'll initiate a new check */
866 set_server_check_status(check, HCHK_STATUS_START, NULL);
Christopher Faulet404f9192020-04-09 23:13:54 +0200867
Willy Tarreau51cd5952020-06-05 12:25:38 +0200868 check->state |= CHK_ST_INPROGRESS;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200869
Willy Tarreau51cd5952020-06-05 12:25:38 +0200870 task_set_affinity(t, tid_bit);
871
872 check->current_step = NULL;
873 tcpcheck_main(check);
874 goto out_unlock;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200875 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200876 else {
877 /* there was a test running.
878 * First, let's check whether there was an uncaught error,
879 * which can happen on connect timeout or error.
880 */
881 if (check->result == CHK_RES_UNKNOWN) {
Christopher Fauletb1bb0692020-11-25 16:47:30 +0100882 /* Here the connection must be defined. Otherwise the
883 * error would have already been detected
884 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200885 if ((conn->flags & CO_FL_ERROR) || cs->flags & CS_FL_ERROR || expired) {
886 chk_report_conn_err(check, 0, expired);
887 }
888 else
889 goto out_unlock; /* timeout not reached, wait again */
Christopher Faulet61cc8522020-04-20 14:54:42 +0200890 }
Christopher Faulet404f9192020-04-09 23:13:54 +0200891
Willy Tarreau51cd5952020-06-05 12:25:38 +0200892 /* check complete or aborted */
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200893
Willy Tarreau51cd5952020-06-05 12:25:38 +0200894 check->current_step = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200895
Willy Tarreau51cd5952020-06-05 12:25:38 +0200896 if (conn && conn->xprt) {
897 /* The check was aborted and the connection was not yet closed.
898 * This can happen upon timeout, or when an external event such
899 * as a failed response coupled with "observe layer7" caused the
900 * server state to be suddenly changed.
901 */
902 conn_sock_drain(conn);
903 cs_close(cs);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200904 }
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200905
Willy Tarreau51cd5952020-06-05 12:25:38 +0200906 if (cs) {
907 if (check->wait_list.events)
908 cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
909 /* We may have been scheduled to run, and the
910 * I/O handler expects to have a cs, so remove
911 * the tasklet
912 */
913 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
914 cs_destroy(cs);
915 cs = check->cs = NULL;
916 conn = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200917 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200918
919 if (check->sess != NULL) {
920 vars_prune(&check->vars, check->sess, NULL);
921 session_free(check->sess);
922 check->sess = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200923 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200924
925 if (check->server) {
926 if (check->result == CHK_RES_FAILED) {
927 /* a failure or timeout detected */
928 check_notify_failure(check);
929 }
930 else if (check->result == CHK_RES_CONDPASS) {
931 /* check is OK but asks for stopping mode */
932 check_notify_stopping(check);
933 }
934 else if (check->result == CHK_RES_PASSED) {
935 /* a success was detected */
936 check_notify_success(check);
937 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200938 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200939 task_set_affinity(t, MAX_THREADS_MASK);
Christopher Fauletb381a502020-11-25 13:47:00 +0100940 check_release_buf(check, &check->bi);
941 check_release_buf(check, &check->bo);
942 check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200943
Willy Tarreau51cd5952020-06-05 12:25:38 +0200944 if (check->server) {
945 rv = 0;
946 if (global.spread_checks > 0) {
947 rv = srv_getinter(check) * global.spread_checks / 100;
948 rv -= (int) (2 * rv * (ha_random32() / 4294967295.0));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200949 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200950 t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(check) + rv));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200951 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200952 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200953
954 reschedule:
955 while (tick_is_expired(t->expire, now_ms))
956 t->expire = tick_add(t->expire, MS_TO_TICKS(check->inter));
957 out_unlock:
958 if (check->server)
959 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
960 return t;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200961}
962
Willy Tarreau51cd5952020-06-05 12:25:38 +0200963
Christopher Faulet61cc8522020-04-20 14:54:42 +0200964/**************************************************************************/
965/************************** Init/deinit checks ****************************/
966/**************************************************************************/
Christopher Fauletb381a502020-11-25 13:47:00 +0100967/*
968 * Tries to grab a buffer and to re-enables processing on check <target>. The
969 * check flags are used to figure what buffer was requested. It returns 1 if the
970 * allocation succeeds, in which case the I/O tasklet is woken up, or 0 if it's
971 * impossible to wake up and we prefer to be woken up later.
972 */
973int check_buf_available(void *target)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200974{
Christopher Fauletb381a502020-11-25 13:47:00 +0100975 struct check *check = target;
976
977 if ((check->state & CHK_ST_IN_ALLOC) && b_alloc_margin(&check->bi, 0)) {
978 check->state &= ~CHK_ST_IN_ALLOC;
979 tasklet_wakeup(check->wait_list.tasklet);
980 return 1;
981 }
982 if ((check->state & CHK_ST_OUT_ALLOC) && b_alloc_margin(&check->bo, 0)) {
983 check->state &= ~CHK_ST_OUT_ALLOC;
984 tasklet_wakeup(check->wait_list.tasklet);
985 return 1;
986 }
987
988 return 0;
989}
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200990
Christopher Fauletb381a502020-11-25 13:47:00 +0100991/*
992 * Allocate a buffer. If if fails, it adds the check in buffer wait queue.
993 */
994struct buffer *check_get_buf(struct check *check, struct buffer *bptr)
995{
996 struct buffer *buf = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200997
Christopher Fauletb381a502020-11-25 13:47:00 +0100998 if (likely(!MT_LIST_ADDED(&check->buf_wait.list)) &&
999 unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) {
1000 check->buf_wait.target = check;
1001 check->buf_wait.wakeup_cb = check_buf_available;
1002 MT_LIST_ADDQ(&buffer_wq, &check->buf_wait.list);
1003 }
1004 return buf;
1005}
1006
1007/*
1008 * Release a buffer, if any, and try to wake up entities waiting in the buffer
1009 * wait queue.
1010 */
1011void check_release_buf(struct check *check, struct buffer *bptr)
1012{
1013 if (bptr->size) {
1014 b_free(bptr);
1015 offer_buffers(check->buf_wait.target, tasks_run_queue);
1016 }
1017}
1018
1019const char *init_check(struct check *check, int type)
1020{
1021 check->type = type;
Christopher Fauletba3c68f2020-04-01 16:27:05 +02001022
Christopher Fauletb381a502020-11-25 13:47:00 +01001023 check->bi = BUF_NULL;
1024 check->bo = BUF_NULL;
1025 MT_LIST_INIT(&check->buf_wait.list);
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001026
Christopher Faulet61cc8522020-04-20 14:54:42 +02001027 check->wait_list.tasklet = tasklet_new();
1028 if (!check->wait_list.tasklet)
1029 return "out of memory while allocating check tasklet";
1030 check->wait_list.events = 0;
1031 check->wait_list.tasklet->process = event_srv_chk_io;
1032 check->wait_list.tasklet->context = check;
1033 return NULL;
1034}
1035
1036void free_check(struct check *check)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001037{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001038 task_destroy(check->task);
1039 if (check->wait_list.tasklet)
1040 tasklet_free(check->wait_list.tasklet);
1041
Christopher Fauletb381a502020-11-25 13:47:00 +01001042 check_release_buf(check, &check->bi);
1043 check_release_buf(check, &check->bo);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001044 if (check->cs) {
1045 free(check->cs->conn);
1046 check->cs->conn = NULL;
1047 cs_free(check->cs);
1048 check->cs = NULL;
1049 }
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001050}
1051
Christopher Faulet61cc8522020-04-20 14:54:42 +02001052/* manages a server health-check. Returns the time the task accepts to wait, or
1053 * TIME_ETERNITY for infinity.
1054 */
Willy Tarreaucee013e2020-06-05 11:40:38 +02001055struct task *process_chk(struct task *t, void *context, unsigned short state)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001056{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001057 struct check *check = context;
1058
1059 if (check->type == PR_O2_EXT_CHK)
1060 return process_chk_proc(t, context, state);
1061 return process_chk_conn(t, context, state);
1062
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001063}
1064
Christopher Faulet61cc8522020-04-20 14:54:42 +02001065
1066static int start_check_task(struct check *check, int mininter,
1067 int nbcheck, int srvpos)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001068{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001069 struct task *t;
1070 unsigned long thread_mask = MAX_THREADS_MASK;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001071
Christopher Faulet61cc8522020-04-20 14:54:42 +02001072 if (check->type == PR_O2_EXT_CHK)
1073 thread_mask = 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001074
Christopher Faulet61cc8522020-04-20 14:54:42 +02001075 /* task for the check */
1076 if ((t = task_new(thread_mask)) == NULL) {
1077 ha_alert("Starting [%s:%s] check: out of memory.\n",
1078 check->server->proxy->id, check->server->id);
1079 return 0;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001080 }
1081
Christopher Faulet61cc8522020-04-20 14:54:42 +02001082 check->task = t;
1083 t->process = process_chk;
1084 t->context = check;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001085
Christopher Faulet61cc8522020-04-20 14:54:42 +02001086 if (mininter < srv_getinter(check))
1087 mininter = srv_getinter(check);
1088
1089 if (global.max_spread_checks && mininter > global.max_spread_checks)
1090 mininter = global.max_spread_checks;
1091
1092 /* check this every ms */
1093 t->expire = tick_add(now_ms, MS_TO_TICKS(mininter * srvpos / nbcheck));
1094 check->start = now;
1095 task_queue(t);
1096
1097 return 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001098}
1099
Christopher Faulet61cc8522020-04-20 14:54:42 +02001100/* updates the server's weight during a warmup stage. Once the final weight is
1101 * reached, the task automatically stops. Note that any server status change
1102 * must have updated s->last_change accordingly.
1103 */
1104static struct task *server_warmup(struct task *t, void *context, unsigned short state)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001105{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001106 struct server *s = context;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001107
Christopher Faulet61cc8522020-04-20 14:54:42 +02001108 /* by default, plan on stopping the task */
1109 t->expire = TICK_ETERNITY;
1110 if ((s->next_admin & SRV_ADMF_MAINT) ||
1111 (s->next_state != SRV_ST_STARTING))
1112 return t;
Christopher Faulete5870d82020-04-15 11:32:03 +02001113
Christopher Faulet61cc8522020-04-20 14:54:42 +02001114 HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001115
Christopher Faulet61cc8522020-04-20 14:54:42 +02001116 /* recalculate the weights and update the state */
1117 server_recalc_eweight(s, 1);
Christopher Faulet5c288742020-03-31 08:15:58 +02001118
Christopher Faulet61cc8522020-04-20 14:54:42 +02001119 /* probably that we can refill this server with a bit more connections */
1120 pendconn_grab_from_px(s);
Christopher Faulet5c288742020-03-31 08:15:58 +02001121
Christopher Faulet61cc8522020-04-20 14:54:42 +02001122 HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
Christopher Faulet5c288742020-03-31 08:15:58 +02001123
Christopher Faulet61cc8522020-04-20 14:54:42 +02001124 /* get back there in 1 second or 1/20th of the slowstart interval,
1125 * whichever is greater, resulting in small 5% steps.
1126 */
1127 if (s->next_state == SRV_ST_STARTING)
1128 t->expire = tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20)));
1129 return t;
1130}
1131
1132/*
1133 * Start health-check.
1134 * Returns 0 if OK, ERR_FATAL on error, and prints the error in this case.
1135 */
1136static int start_checks()
1137{
1138
1139 struct proxy *px;
1140 struct server *s;
1141 struct task *t;
1142 int nbcheck=0, mininter=0, srvpos=0;
1143
1144 /* 0- init the dummy frontend used to create all checks sessions */
1145 init_new_proxy(&checks_fe);
1146 checks_fe.cap = PR_CAP_FE | PR_CAP_BE;
1147 checks_fe.mode = PR_MODE_TCP;
1148 checks_fe.maxconn = 0;
1149 checks_fe.conn_retries = CONN_RETRIES;
1150 checks_fe.options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC;
1151 checks_fe.timeout.client = TICK_ETERNITY;
1152
1153 /* 1- count the checkers to run simultaneously.
1154 * We also determine the minimum interval among all of those which
1155 * have an interval larger than SRV_CHK_INTER_THRES. This interval
1156 * will be used to spread their start-up date. Those which have
1157 * a shorter interval will start independently and will not dictate
1158 * too short an interval for all others.
1159 */
1160 for (px = proxies_list; px; px = px->next) {
1161 for (s = px->srv; s; s = s->next) {
1162 if (s->slowstart) {
1163 if ((t = task_new(MAX_THREADS_MASK)) == NULL) {
1164 ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
1165 return ERR_ALERT | ERR_FATAL;
1166 }
1167 /* We need a warmup task that will be called when the server
1168 * state switches from down to up.
1169 */
1170 s->warmup = t;
1171 t->process = server_warmup;
1172 t->context = s;
1173 /* server can be in this state only because of */
1174 if (s->next_state == SRV_ST_STARTING)
1175 task_schedule(s->warmup, tick_add(now_ms, MS_TO_TICKS(MAX(1000, (now.tv_sec - s->last_change)) / 20)));
Christopher Faulet5c288742020-03-31 08:15:58 +02001176 }
1177
Christopher Faulet61cc8522020-04-20 14:54:42 +02001178 if (s->check.state & CHK_ST_CONFIGURED) {
1179 nbcheck++;
1180 if ((srv_getinter(&s->check) >= SRV_CHK_INTER_THRES) &&
1181 (!mininter || mininter > srv_getinter(&s->check)))
1182 mininter = srv_getinter(&s->check);
Christopher Faulet5c288742020-03-31 08:15:58 +02001183 }
1184
Christopher Faulet61cc8522020-04-20 14:54:42 +02001185 if (s->agent.state & CHK_ST_CONFIGURED) {
1186 nbcheck++;
1187 if ((srv_getinter(&s->agent) >= SRV_CHK_INTER_THRES) &&
1188 (!mininter || mininter > srv_getinter(&s->agent)))
1189 mininter = srv_getinter(&s->agent);
1190 }
Christopher Faulet5c288742020-03-31 08:15:58 +02001191 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001192 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001193
Christopher Faulet61cc8522020-04-20 14:54:42 +02001194 if (!nbcheck)
Christopher Fauletfc633b62020-11-06 15:24:23 +01001195 return ERR_NONE;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001196
Christopher Faulet61cc8522020-04-20 14:54:42 +02001197 srand((unsigned)time(NULL));
Christopher Fauletb7d30092020-03-30 15:19:03 +02001198
Christopher Faulet61cc8522020-04-20 14:54:42 +02001199 /*
1200 * 2- start them as far as possible from each others. For this, we will
1201 * start them after their interval set to the min interval divided by
1202 * the number of servers, weighted by the server's position in the list.
1203 */
1204 for (px = proxies_list; px; px = px->next) {
1205 if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
1206 if (init_pid_list()) {
1207 ha_alert("Starting [%s] check: out of memory.\n", px->id);
1208 return ERR_ALERT | ERR_FATAL;
1209 }
1210 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001211
Christopher Faulet61cc8522020-04-20 14:54:42 +02001212 for (s = px->srv; s; s = s->next) {
1213 /* A task for the main check */
1214 if (s->check.state & CHK_ST_CONFIGURED) {
1215 if (s->check.type == PR_O2_EXT_CHK) {
1216 if (!prepare_external_check(&s->check))
1217 return ERR_ALERT | ERR_FATAL;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001218 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001219 if (!start_check_task(&s->check, mininter, nbcheck, srvpos))
1220 return ERR_ALERT | ERR_FATAL;
1221 srvpos++;
Christopher Faulet98572322020-03-30 13:16:44 +02001222 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001223
Christopher Faulet61cc8522020-04-20 14:54:42 +02001224 /* A task for a auxiliary agent check */
1225 if (s->agent.state & CHK_ST_CONFIGURED) {
1226 if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) {
1227 return ERR_ALERT | ERR_FATAL;
1228 }
1229 srvpos++;
1230 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001231 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001232 }
Christopher Fauletfc633b62020-11-06 15:24:23 +01001233 return ERR_NONE;
Christopher Faulet61cc8522020-04-20 14:54:42 +02001234}
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001235
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001236
Christopher Faulet61cc8522020-04-20 14:54:42 +02001237/*
1238 * Return value:
1239 * the port to be used for the health check
1240 * 0 in case no port could be found for the check
1241 */
1242static int srv_check_healthcheck_port(struct check *chk)
1243{
1244 int i = 0;
1245 struct server *srv = NULL;
1246
1247 srv = chk->server;
1248
1249 /* by default, we use the health check port ocnfigured */
1250 if (chk->port > 0)
1251 return chk->port;
1252
1253 /* try to get the port from check_core.addr if check.port not set */
1254 i = get_host_port(&chk->addr);
1255 if (i > 0)
1256 return i;
1257
1258 /* try to get the port from server address */
1259 /* prevent MAPPORTS from working at this point, since checks could
1260 * not be performed in such case (MAPPORTS impose a relative ports
1261 * based on live traffic)
1262 */
1263 if (srv->flags & SRV_F_MAPPORTS)
1264 return 0;
1265
1266 i = srv->svc_port; /* by default */
1267 if (i > 0)
1268 return i;
1269
1270 return 0;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001271}
1272
Christopher Faulet61cc8522020-04-20 14:54:42 +02001273/* Initializes an health-check attached to the server <srv>. Non-zero is returned
1274 * if an error occurred.
1275 */
1276static int init_srv_check(struct server *srv)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001277{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001278 const char *err;
1279 struct tcpcheck_rule *r;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001280 int ret = ERR_NONE;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001281 int check_type;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001282
Christopher Faulet61cc8522020-04-20 14:54:42 +02001283 if (!srv->do_check)
1284 goto out;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001285
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001286 check_type = srv->check.tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001287
Christopher Faulet61cc8522020-04-20 14:54:42 +02001288 /* If neither a port nor an addr was specified and no check transport
1289 * layer is forced, then the transport layer used by the checks is the
1290 * same as for the production traffic. Otherwise we use raw_sock by
1291 * default, unless one is specified.
1292 */
1293 if (!srv->check.port && !is_addr(&srv->check.addr)) {
1294 if (!srv->check.use_ssl && srv->use_ssl != -1) {
1295 srv->check.use_ssl = srv->use_ssl;
1296 srv->check.xprt = srv->xprt;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001297 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001298 else if (srv->check.use_ssl == 1)
1299 srv->check.xprt = xprt_get(XPRT_SSL);
1300 srv->check.send_proxy |= (srv->pp_opts);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001301 }
Christopher Faulet66163ec2020-05-20 22:36:24 +02001302 else if (srv->check.use_ssl == 1)
1303 srv->check.xprt = xprt_get(XPRT_SSL);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001304
Christopher Faulet12882cf2020-04-23 15:50:18 +02001305 /* Inherit the mux protocol from the server if not already defined for
1306 * the check
1307 */
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001308 if (srv->mux_proto && !srv->check.mux_proto &&
1309 ((srv->mux_proto->mode == PROTO_MODE_HTTP && check_type == TCPCHK_RULES_HTTP_CHK) ||
1310 (srv->mux_proto->mode == PROTO_MODE_TCP && check_type != TCPCHK_RULES_HTTP_CHK))) {
Christopher Faulet12882cf2020-04-23 15:50:18 +02001311 srv->check.mux_proto = srv->mux_proto;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001312 }
Amaury Denoyelle7c148902020-11-13 12:34:57 +01001313 /* test that check proto is valid if explicitly defined */
1314 else if (srv->check.mux_proto &&
1315 ((srv->check.mux_proto->mode == PROTO_MODE_HTTP && check_type != TCPCHK_RULES_HTTP_CHK) ||
1316 (srv->check.mux_proto->mode == PROTO_MODE_TCP && check_type == TCPCHK_RULES_HTTP_CHK))) {
1317 ha_alert("config: %s '%s': server '%s' uses an incompatible MUX protocol for the selected check type\n",
1318 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1319 ret |= ERR_ALERT | ERR_FATAL;
1320 goto out;
1321 }
Christopher Faulet12882cf2020-04-23 15:50:18 +02001322
Christopher Faulet61cc8522020-04-20 14:54:42 +02001323 /* validate <srv> server health-check settings */
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001324
Christopher Faulet61cc8522020-04-20 14:54:42 +02001325 /* We need at least a service port, a check port or the first tcp-check
1326 * rule must be a 'connect' one when checking an IPv4/IPv6 server.
1327 */
1328 if ((srv_check_healthcheck_port(&srv->check) != 0) ||
1329 (!is_inet_addr(&srv->check.addr) && (is_addr(&srv->check.addr) || !is_inet_addr(&srv->addr))))
1330 goto init;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001331
Christopher Faulet61cc8522020-04-20 14:54:42 +02001332 if (!srv->proxy->tcpcheck_rules.list || LIST_ISEMPTY(srv->proxy->tcpcheck_rules.list)) {
1333 ha_alert("config: %s '%s': server '%s' has neither service port nor check port.\n",
1334 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1335 ret |= ERR_ALERT | ERR_ABORT;
1336 goto out;
1337 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001338
Christopher Faulet61cc8522020-04-20 14:54:42 +02001339 /* search the first action (connect / send / expect) in the list */
1340 r = get_first_tcpcheck_rule(&srv->proxy->tcpcheck_rules);
1341 if (!r || (r->action != TCPCHK_ACT_CONNECT) || (!r->connect.port && !get_host_port(&r->connect.addr))) {
1342 ha_alert("config: %s '%s': server '%s' has neither service port nor check port "
1343 "nor tcp_check rule 'connect' with port information.\n",
1344 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1345 ret |= ERR_ALERT | ERR_ABORT;
1346 goto out;
1347 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001348
Christopher Faulet61cc8522020-04-20 14:54:42 +02001349 /* scan the tcp-check ruleset to ensure a port has been configured */
1350 list_for_each_entry(r, srv->proxy->tcpcheck_rules.list, list) {
1351 if ((r->action == TCPCHK_ACT_CONNECT) && (!r->connect.port || !get_host_port(&r->connect.addr))) {
1352 ha_alert("config: %s '%s': server '%s' has neither service port nor check port, "
1353 "and a tcp_check rule 'connect' with no port information.\n",
1354 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1355 ret |= ERR_ALERT | ERR_ABORT;
1356 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001357 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001358 }
1359
Christopher Faulet61cc8522020-04-20 14:54:42 +02001360 init:
1361 if (!(srv->proxy->options2 & PR_O2_CHK_ANY)) {
1362 struct tcpcheck_ruleset *rs = NULL;
1363 struct tcpcheck_rules *rules = &srv->proxy->tcpcheck_rules;
1364 //char *errmsg = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001365
Christopher Faulet61cc8522020-04-20 14:54:42 +02001366 srv->proxy->options2 &= ~PR_O2_CHK_ANY;
1367 srv->proxy->options2 |= PR_O2_TCPCHK_CHK;
Christopher Faulete5870d82020-04-15 11:32:03 +02001368
Christopher Faulet61cc8522020-04-20 14:54:42 +02001369 rs = find_tcpcheck_ruleset("*tcp-check");
1370 if (!rs) {
1371 rs = create_tcpcheck_ruleset("*tcp-check");
1372 if (rs == NULL) {
1373 ha_alert("config: %s '%s': out of memory.\n",
1374 proxy_type_str(srv->proxy), srv->proxy->id);
1375 ret |= ERR_ALERT | ERR_FATAL;
1376 goto out;
1377 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001378 }
1379
Christopher Faulet61cc8522020-04-20 14:54:42 +02001380 free_tcpcheck_vars(&rules->preset_vars);
1381 rules->list = &rs->rules;
1382 rules->flags = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001383 }
1384
Christopher Faulet61cc8522020-04-20 14:54:42 +02001385 err = init_check(&srv->check, srv->proxy->options2 & PR_O2_CHK_ANY);
1386 if (err) {
1387 ha_alert("config: %s '%s': unable to init check for server '%s' (%s).\n",
1388 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1389 ret |= ERR_ALERT | ERR_ABORT;
1390 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001391 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001392 srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
1393 global.maxsock++;
Christopher Faulete5870d82020-04-15 11:32:03 +02001394
Christopher Faulet61cc8522020-04-20 14:54:42 +02001395 out:
1396 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001397}
1398
Christopher Faulet61cc8522020-04-20 14:54:42 +02001399/* Initializes an agent-check attached to the server <srv>. Non-zero is returned
1400 * if an error occurred.
1401 */
1402static int init_srv_agent_check(struct server *srv)
Christopher Faulete5870d82020-04-15 11:32:03 +02001403{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001404 struct tcpcheck_rule *chk;
1405 const char *err;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001406 int ret = ERR_NONE;
Christopher Faulete5870d82020-04-15 11:32:03 +02001407
Christopher Faulet61cc8522020-04-20 14:54:42 +02001408 if (!srv->do_agent)
1409 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001410
Ilya Shipitsinc02a23f2020-05-06 00:53:22 +05001411 /* If there is no connect rule preceding all send / expect rules, an
Christopher Faulet61cc8522020-04-20 14:54:42 +02001412 * implicit one is inserted before all others.
1413 */
1414 chk = get_first_tcpcheck_rule(srv->agent.tcpcheck_rules);
1415 if (!chk || chk->action != TCPCHK_ACT_CONNECT) {
1416 chk = calloc(1, sizeof(*chk));
1417 if (!chk) {
1418 ha_alert("config : %s '%s': unable to add implicit tcp-check connect rule"
1419 " to agent-check for server '%s' (out of memory).\n",
1420 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1421 ret |= ERR_ALERT | ERR_FATAL;
1422 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001423 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001424 chk->action = TCPCHK_ACT_CONNECT;
1425 chk->connect.options = (TCPCHK_OPT_DEFAULT_CONNECT|TCPCHK_OPT_IMPLICIT);
1426 LIST_ADD(srv->agent.tcpcheck_rules->list, &chk->list);
Christopher Faulete5870d82020-04-15 11:32:03 +02001427 }
1428
Christopher Faulete5870d82020-04-15 11:32:03 +02001429
Christopher Faulet61cc8522020-04-20 14:54:42 +02001430 err = init_check(&srv->agent, PR_O2_TCPCHK_CHK);
1431 if (err) {
1432 ha_alert("config: %s '%s': unable to init agent-check for server '%s' (%s).\n",
1433 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1434 ret |= ERR_ALERT | ERR_ABORT;
1435 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001436 }
1437
Christopher Faulet61cc8522020-04-20 14:54:42 +02001438 if (!srv->agent.inter)
1439 srv->agent.inter = srv->check.inter;
1440
1441 srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
1442 global.maxsock++;
1443
1444 out:
1445 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001446}
1447
Christopher Faulet61cc8522020-04-20 14:54:42 +02001448static void deinit_srv_check(struct server *srv)
1449{
1450 if (srv->check.state & CHK_ST_CONFIGURED)
1451 free_check(&srv->check);
1452 srv->check.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED;
1453 srv->do_check = 0;
1454}
Christopher Faulete5870d82020-04-15 11:32:03 +02001455
Christopher Faulet61cc8522020-04-20 14:54:42 +02001456
1457static void deinit_srv_agent_check(struct server *srv)
1458{
1459 if (srv->agent.tcpcheck_rules) {
1460 free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars);
1461 free(srv->agent.tcpcheck_rules);
1462 srv->agent.tcpcheck_rules = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001463 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001464
Christopher Faulet61cc8522020-04-20 14:54:42 +02001465 if (srv->agent.state & CHK_ST_CONFIGURED)
1466 free_check(&srv->agent);
1467
1468 srv->agent.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED & ~CHK_ST_AGENT;
1469 srv->do_agent = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001470}
1471
Willy Tarreaucee013e2020-06-05 11:40:38 +02001472REGISTER_POST_SERVER_CHECK(init_srv_check);
1473REGISTER_POST_SERVER_CHECK(init_srv_agent_check);
Willy Tarreaucee013e2020-06-05 11:40:38 +02001474REGISTER_POST_CHECK(start_checks);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001475
Willy Tarreaucee013e2020-06-05 11:40:38 +02001476REGISTER_SERVER_DEINIT(deinit_srv_check);
1477REGISTER_SERVER_DEINIT(deinit_srv_agent_check);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001478
Christopher Faulet61cc8522020-04-20 14:54:42 +02001479
1480/**************************************************************************/
1481/************************** Check sample fetches **************************/
1482/**************************************************************************/
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001483
Christopher Faulet61cc8522020-04-20 14:54:42 +02001484static struct sample_fetch_kw_list smp_kws = {ILH, {
Christopher Faulet61cc8522020-04-20 14:54:42 +02001485 { /* END */ },
1486}};
1487
1488INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1489
1490
1491/**************************************************************************/
1492/************************ Check's parsing functions ***********************/
1493/**************************************************************************/
Christopher Fauletce8111e2020-04-06 15:04:11 +02001494/* Parse the "addr" server keyword */
1495static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1496 char **errmsg)
1497{
1498 struct sockaddr_storage *sk;
Christopher Fauletce8111e2020-04-06 15:04:11 +02001499 int port1, port2, err_code = 0;
1500
1501
1502 if (!*args[*cur_arg+1]) {
1503 memprintf(errmsg, "'%s' expects <ipv4|ipv6> as argument.", args[*cur_arg]);
1504 goto error;
1505 }
1506
Willy Tarreau65ec4e32020-09-16 19:17:08 +02001507 sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, errmsg, NULL, NULL,
1508 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Christopher Fauletce8111e2020-04-06 15:04:11 +02001509 if (!sk) {
1510 memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
1511 goto error;
1512 }
1513
Christopher Fauletce8111e2020-04-06 15:04:11 +02001514 srv->check.addr = srv->agent.addr = *sk;
1515 srv->flags |= SRV_F_CHECKADDR;
1516 srv->flags |= SRV_F_AGENTADDR;
1517
1518 out:
1519 return err_code;
1520
1521 error:
1522 err_code |= ERR_ALERT | ERR_FATAL;
1523 goto out;
1524}
1525
1526
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001527/* Parse the "agent-addr" server keyword */
1528static int srv_parse_agent_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1529 char **errmsg)
1530{
1531 int err_code = 0;
1532
1533 if (!*(args[*cur_arg+1])) {
1534 memprintf(errmsg, "'%s' expects an address as argument.", args[*cur_arg]);
1535 goto error;
1536 }
1537 if(str2ip(args[*cur_arg+1], &srv->agent.addr) == NULL) {
1538 memprintf(errmsg, "parsing agent-addr failed. Check if '%s' is correct address.", args[*cur_arg+1]);
1539 goto error;
1540 }
1541
1542 out:
1543 return err_code;
1544
1545 error:
1546 err_code |= ERR_ALERT | ERR_FATAL;
1547 goto out;
1548}
1549
1550/* Parse the "agent-check" server keyword */
1551static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1552 char **errmsg)
1553{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001554 struct tcpcheck_ruleset *rs = NULL;
1555 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1556 struct tcpcheck_rule *chk;
1557 int err_code = 0;
1558
1559 if (srv->do_agent)
1560 goto out;
1561
1562 if (!rules) {
1563 rules = calloc(1, sizeof(*rules));
1564 if (!rules) {
1565 memprintf(errmsg, "out of memory.");
1566 goto error;
1567 }
1568 LIST_INIT(&rules->preset_vars);
1569 srv->agent.tcpcheck_rules = rules;
1570 }
1571 rules->list = NULL;
1572 rules->flags = 0;
1573
Christopher Faulet61cc8522020-04-20 14:54:42 +02001574 rs = find_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001575 if (rs)
1576 goto ruleset_found;
1577
Christopher Faulet61cc8522020-04-20 14:54:42 +02001578 rs = create_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001579 if (rs == NULL) {
1580 memprintf(errmsg, "out of memory.");
1581 goto error;
1582 }
1583
Christopher Fauletb50b3e62020-05-05 18:43:43 +02001584 chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", "%[var(check.agent_string)]", ""},
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001585 1, curpx, &rs->rules, srv->conf.file, srv->conf.line, errmsg);
1586 if (!chk) {
1587 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1588 goto error;
1589 }
1590 chk->index = 0;
1591 LIST_ADDQ(&rs->rules, &chk->list);
1592
1593 chk = parse_tcpcheck_expect((char *[]){"tcp-check", "expect", "custom", ""},
Christopher Faulete5870d82020-04-15 11:32:03 +02001594 1, curpx, &rs->rules, TCPCHK_RULES_AGENT_CHK,
1595 srv->conf.file, srv->conf.line, errmsg);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001596 if (!chk) {
1597 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1598 goto error;
1599 }
1600 chk->expect.custom = tcpcheck_agent_expect_reply;
1601 chk->index = 1;
1602 LIST_ADDQ(&rs->rules, &chk->list);
1603
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001604 ruleset_found:
1605 rules->list = &rs->rules;
Christopher Faulet1faf18a2020-11-25 16:43:12 +01001606 rules->flags &= ~(TCPCHK_RULES_PROTO_CHK|TCPCHK_RULES_UNUSED_RS);
Christopher Faulet404f9192020-04-09 23:13:54 +02001607 rules->flags |= TCPCHK_RULES_AGENT_CHK;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001608 srv->do_agent = 1;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001609
1610 out:
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001611 return 0;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001612
1613 error:
1614 deinit_srv_agent_check(srv);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001615 free_tcpcheck_ruleset(rs);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001616 err_code |= ERR_ALERT | ERR_FATAL;
1617 goto out;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001618}
1619
1620/* Parse the "agent-inter" server keyword */
1621static int srv_parse_agent_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1622 char **errmsg)
1623{
1624 const char *err = NULL;
1625 unsigned int delay;
1626 int err_code = 0;
1627
1628 if (!*(args[*cur_arg+1])) {
1629 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1630 goto error;
1631 }
1632
1633 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1634 if (err == PARSE_TIME_OVER) {
1635 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1636 args[*cur_arg+1], args[*cur_arg], srv->id);
1637 goto error;
1638 }
1639 else if (err == PARSE_TIME_UNDER) {
1640 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1641 args[*cur_arg+1], args[*cur_arg], srv->id);
1642 goto error;
1643 }
1644 else if (err) {
1645 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1646 *err, srv->id);
1647 goto error;
1648 }
1649 if (delay <= 0) {
1650 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1651 delay, args[*cur_arg], srv->id);
1652 goto error;
1653 }
1654 srv->agent.inter = delay;
1655
1656 out:
1657 return err_code;
1658
1659 error:
1660 err_code |= ERR_ALERT | ERR_FATAL;
1661 goto out;
1662}
1663
1664/* Parse the "agent-port" server keyword */
1665static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1666 char **errmsg)
1667{
1668 int err_code = 0;
1669
1670 if (!*(args[*cur_arg+1])) {
1671 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
1672 goto error;
1673 }
1674
1675 global.maxsock++;
1676 srv->agent.port = atol(args[*cur_arg+1]);
1677
1678 out:
1679 return err_code;
1680
1681 error:
1682 err_code |= ERR_ALERT | ERR_FATAL;
1683 goto out;
1684}
1685
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001686int set_srv_agent_send(struct server *srv, const char *send)
1687{
1688 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1689 struct tcpcheck_var *var = NULL;
1690 char *str;
1691
1692 str = strdup(send);
Christopher Fauletb61caf42020-04-21 10:57:42 +02001693 var = create_tcpcheck_var(ist("check.agent_string"));
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001694 if (str == NULL || var == NULL)
1695 goto error;
1696
1697 free_tcpcheck_vars(&rules->preset_vars);
1698
1699 var->data.type = SMP_T_STR;
1700 var->data.u.str.area = str;
1701 var->data.u.str.data = strlen(str);
1702 LIST_INIT(&var->list);
1703 LIST_ADDQ(&rules->preset_vars, &var->list);
1704
1705 return 1;
1706
1707 error:
1708 free(str);
1709 free(var);
1710 return 0;
1711}
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001712
1713/* Parse the "agent-send" server keyword */
1714static int srv_parse_agent_send(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1715 char **errmsg)
1716{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001717 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001718 int err_code = 0;
1719
1720 if (!*(args[*cur_arg+1])) {
1721 memprintf(errmsg, "'%s' expects a string as argument.", args[*cur_arg]);
1722 goto error;
1723 }
1724
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001725 if (!rules) {
1726 rules = calloc(1, sizeof(*rules));
1727 if (!rules) {
1728 memprintf(errmsg, "out of memory.");
1729 goto error;
1730 }
1731 LIST_INIT(&rules->preset_vars);
1732 srv->agent.tcpcheck_rules = rules;
1733 }
1734
1735 if (!set_srv_agent_send(srv, args[*cur_arg+1])) {
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001736 memprintf(errmsg, "out of memory.");
1737 goto error;
1738 }
1739
1740 out:
1741 return err_code;
1742
1743 error:
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001744 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001745 err_code |= ERR_ALERT | ERR_FATAL;
1746 goto out;
1747}
1748
1749/* Parse the "no-agent-send" server keyword */
1750static int srv_parse_no_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1751 char **errmsg)
1752{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001753 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001754 return 0;
1755}
1756
Christopher Fauletce8111e2020-04-06 15:04:11 +02001757/* Parse the "check" server keyword */
1758static int srv_parse_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1759 char **errmsg)
1760{
1761 srv->do_check = 1;
1762 return 0;
1763}
1764
1765/* Parse the "check-send-proxy" server keyword */
1766static int srv_parse_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1767 char **errmsg)
1768{
1769 srv->check.send_proxy = 1;
1770 return 0;
1771}
1772
1773/* Parse the "check-via-socks4" server keyword */
1774static int srv_parse_check_via_socks4(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1775 char **errmsg)
1776{
1777 srv->check.via_socks4 = 1;
1778 return 0;
1779}
1780
1781/* Parse the "no-check" server keyword */
1782static int srv_parse_no_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1783 char **errmsg)
1784{
1785 deinit_srv_check(srv);
1786 return 0;
1787}
1788
1789/* Parse the "no-check-send-proxy" server keyword */
1790static int srv_parse_no_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1791 char **errmsg)
1792{
1793 srv->check.send_proxy = 0;
1794 return 0;
1795}
1796
Christopher Fauletedc6ed92020-04-23 16:27:59 +02001797/* parse the "check-proto" server keyword */
1798static int srv_parse_check_proto(char **args, int *cur_arg,
1799 struct proxy *px, struct server *newsrv, char **err)
1800{
1801 int err_code = 0;
1802
1803 if (!*args[*cur_arg + 1]) {
1804 memprintf(err, "'%s' : missing value", args[*cur_arg]);
1805 goto error;
1806 }
1807 newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1])));
1808 if (!newsrv->check.mux_proto) {
1809 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
1810 goto error;
1811 }
1812
1813 out:
1814 return err_code;
1815
1816 error:
1817 err_code |= ERR_ALERT | ERR_FATAL;
1818 goto out;
1819}
1820
1821
Christopher Fauletce8111e2020-04-06 15:04:11 +02001822/* Parse the "rise" server keyword */
1823static int srv_parse_check_rise(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1824 char **errmsg)
1825{
1826 int err_code = 0;
1827
1828 if (!*args[*cur_arg + 1]) {
1829 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1830 goto error;
1831 }
1832
1833 srv->check.rise = atol(args[*cur_arg+1]);
1834 if (srv->check.rise <= 0) {
1835 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1836 goto error;
1837 }
1838
1839 if (srv->check.health)
1840 srv->check.health = srv->check.rise;
1841
1842 out:
1843 return err_code;
1844
1845 error:
1846 deinit_srv_agent_check(srv);
1847 err_code |= ERR_ALERT | ERR_FATAL;
1848 goto out;
1849 return 0;
1850}
1851
1852/* Parse the "fall" server keyword */
1853static int srv_parse_check_fall(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1854 char **errmsg)
1855{
1856 int err_code = 0;
1857
1858 if (!*args[*cur_arg + 1]) {
1859 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1860 goto error;
1861 }
1862
1863 srv->check.fall = atol(args[*cur_arg+1]);
1864 if (srv->check.fall <= 0) {
1865 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1866 goto error;
1867 }
1868
1869 out:
1870 return err_code;
1871
1872 error:
1873 deinit_srv_agent_check(srv);
1874 err_code |= ERR_ALERT | ERR_FATAL;
1875 goto out;
1876 return 0;
1877}
1878
1879/* Parse the "inter" server keyword */
1880static int srv_parse_check_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1881 char **errmsg)
1882{
1883 const char *err = NULL;
1884 unsigned int delay;
1885 int err_code = 0;
1886
1887 if (!*(args[*cur_arg+1])) {
1888 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1889 goto error;
1890 }
1891
1892 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1893 if (err == PARSE_TIME_OVER) {
1894 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1895 args[*cur_arg+1], args[*cur_arg], srv->id);
1896 goto error;
1897 }
1898 else if (err == PARSE_TIME_UNDER) {
1899 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1900 args[*cur_arg+1], args[*cur_arg], srv->id);
1901 goto error;
1902 }
1903 else if (err) {
1904 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1905 *err, srv->id);
1906 goto error;
1907 }
1908 if (delay <= 0) {
1909 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1910 delay, args[*cur_arg], srv->id);
1911 goto error;
1912 }
1913 srv->check.inter = delay;
1914
1915 out:
1916 return err_code;
1917
1918 error:
1919 err_code |= ERR_ALERT | ERR_FATAL;
1920 goto out;
1921}
1922
1923
1924/* Parse the "fastinter" server keyword */
1925static int srv_parse_check_fastinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1926 char **errmsg)
1927{
1928 const char *err = NULL;
1929 unsigned int delay;
1930 int err_code = 0;
1931
1932 if (!*(args[*cur_arg+1])) {
1933 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1934 goto error;
1935 }
1936
1937 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1938 if (err == PARSE_TIME_OVER) {
1939 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1940 args[*cur_arg+1], args[*cur_arg], srv->id);
1941 goto error;
1942 }
1943 else if (err == PARSE_TIME_UNDER) {
1944 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1945 args[*cur_arg+1], args[*cur_arg], srv->id);
1946 goto error;
1947 }
1948 else if (err) {
1949 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1950 *err, srv->id);
1951 goto error;
1952 }
1953 if (delay <= 0) {
1954 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1955 delay, args[*cur_arg], srv->id);
1956 goto error;
1957 }
1958 srv->check.fastinter = delay;
1959
1960 out:
1961 return err_code;
1962
1963 error:
1964 err_code |= ERR_ALERT | ERR_FATAL;
1965 goto out;
1966}
1967
1968
1969/* Parse the "downinter" server keyword */
1970static int srv_parse_check_downinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1971 char **errmsg)
1972{
1973 const char *err = NULL;
1974 unsigned int delay;
1975 int err_code = 0;
1976
1977 if (!*(args[*cur_arg+1])) {
1978 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1979 goto error;
1980 }
1981
1982 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1983 if (err == PARSE_TIME_OVER) {
1984 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1985 args[*cur_arg+1], args[*cur_arg], srv->id);
1986 goto error;
1987 }
1988 else if (err == PARSE_TIME_UNDER) {
1989 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1990 args[*cur_arg+1], args[*cur_arg], srv->id);
1991 goto error;
1992 }
1993 else if (err) {
1994 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1995 *err, srv->id);
1996 goto error;
1997 }
1998 if (delay <= 0) {
1999 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
2000 delay, args[*cur_arg], srv->id);
2001 goto error;
2002 }
2003 srv->check.downinter = delay;
2004
2005 out:
2006 return err_code;
2007
2008 error:
2009 err_code |= ERR_ALERT | ERR_FATAL;
2010 goto out;
2011}
2012
2013/* Parse the "port" server keyword */
2014static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
2015 char **errmsg)
2016{
2017 int err_code = 0;
2018
2019 if (!*(args[*cur_arg+1])) {
2020 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
2021 goto error;
2022 }
2023
2024 global.maxsock++;
2025 srv->check.port = atol(args[*cur_arg+1]);
2026 srv->flags |= SRV_F_CHECKPORT;
2027
2028 out:
2029 return err_code;
2030
2031 error:
2032 err_code |= ERR_ALERT | ERR_FATAL;
2033 goto out;
2034}
2035
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002036static struct srv_kw_list srv_kws = { "CHK", { }, {
Christopher Fauletce8111e2020-04-06 15:04:11 +02002037 { "addr", srv_parse_addr, 1, 1 }, /* IP address to send health to or to probe from agent-check */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002038 { "agent-addr", srv_parse_agent_addr, 1, 1 }, /* Enable an auxiliary agent check */
2039 { "agent-check", srv_parse_agent_check, 0, 1 }, /* Enable agent checks */
2040 { "agent-inter", srv_parse_agent_inter, 1, 1 }, /* Set the interval between two agent checks */
2041 { "agent-port", srv_parse_agent_port, 1, 1 }, /* Set the TCP port used for agent checks. */
2042 { "agent-send", srv_parse_agent_send, 1, 1 }, /* Set string to send to agent. */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002043 { "check", srv_parse_check, 0, 1 }, /* Enable health checks */
Christopher Fauletedc6ed92020-04-23 16:27:59 +02002044 { "check-proto", srv_parse_check_proto, 1, 1 }, /* Set the mux protocol for health checks */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002045 { "check-send-proxy", srv_parse_check_send_proxy, 0, 1 }, /* Enable PROXY protocol for health checks */
2046 { "check-via-socks4", srv_parse_check_via_socks4, 0, 1 }, /* Enable socks4 proxy for health checks */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002047 { "no-agent-check", srv_parse_no_agent_check, 0, 1 }, /* Do not enable any auxiliary agent check */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002048 { "no-check", srv_parse_no_check, 0, 1 }, /* Disable health checks */
2049 { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0, 1 }, /* Disable PROXY protol for health checks */
2050 { "rise", srv_parse_check_rise, 1, 1 }, /* Set rise value for health checks */
2051 { "fall", srv_parse_check_fall, 1, 1 }, /* Set fall value for health checks */
2052 { "inter", srv_parse_check_inter, 1, 1 }, /* Set inter value for health checks */
2053 { "fastinter", srv_parse_check_fastinter, 1, 1 }, /* Set fastinter value for health checks */
2054 { "downinter", srv_parse_check_downinter, 1, 1 }, /* Set downinter value for health checks */
2055 { "port", srv_parse_check_port, 1, 1 }, /* Set the TCP port used for health checks. */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002056 { NULL, NULL, 0 },
2057}};
2058
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002059INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01002060
Willy Tarreaubd741542010-03-16 18:46:54 +01002061/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02002062 * Local variables:
2063 * c-indent-level: 8
2064 * c-basic-offset: 8
2065 * End:
2066 */