blob: 2c0a0aceb19a8970bcd74da8e71f472e84b430fe [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
Christopher Faulet8f100422021-01-18 15:47:03 +0100796 if (check->result != CHK_RES_UNKNOWN || ret == -1) {
Willy Tarreau51cd5952020-06-05 12:25:38 +0200797 /* 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. */
Willy Tarreau30bd4ef2020-12-11 11:09:29 +0100800 cs_drain_and_close(cs);
Willy Tarreau51cd5952020-06-05 12:25:38 +0200801 ret = -1;
Christopher Faulet8f100422021-01-18 15:47:03 +0100802
803 if (check->wait_list.events)
804 cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
805
Willy Tarreau51cd5952020-06-05 12:25:38 +0200806 /* We may have been scheduled to run, and the
807 * I/O handler expects to have a cs, so remove
808 * the tasklet
809 */
810 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
811 task_wakeup(check->task, TASK_WOKEN_IO);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200812 }
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200813
Willy Tarreau51cd5952020-06-05 12:25:38 +0200814 if (check->server)
815 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
816 else
817 HA_SPIN_UNLOCK(EMAIL_ALERTS_LOCK, &q->lock);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200818
Christopher Faulet61cc8522020-04-20 14:54:42 +0200819 return ret;
820}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200821
Willy Tarreau51cd5952020-06-05 12:25:38 +0200822/* This function checks if any I/O is wanted, and if so, attempts to do so */
823static struct task *event_srv_chk_io(struct task *t, void *ctx, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200824{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200825 struct check *check = ctx;
826 struct conn_stream *cs = check->cs;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200827
Willy Tarreau51cd5952020-06-05 12:25:38 +0200828 wake_srv_chk(cs);
829 return NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200830}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200831
Willy Tarreau51cd5952020-06-05 12:25:38 +0200832/* manages a server health-check that uses a connection. Returns
833 * the time the task accepts to wait, or TIME_ETERNITY for infinity.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200834 *
835 * Please do NOT place any return statement in this function and only leave
Willy Tarreau51cd5952020-06-05 12:25:38 +0200836 * via the out_unlock label.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200837 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200838static struct task *process_chk_conn(struct task *t, void *context, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200839{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200840 struct check *check = context;
841 struct proxy *proxy = check->proxy;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200842 struct conn_stream *cs = check->cs;
843 struct connection *conn = cs_conn(cs);
Willy Tarreau51cd5952020-06-05 12:25:38 +0200844 int rv;
845 int expired = tick_is_expired(t->expire, now_ms);
Willy Tarreaudeccd112018-06-14 18:38:55 +0200846
Willy Tarreau51cd5952020-06-05 12:25:38 +0200847 if (check->server)
848 HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock);
849 if (!(check->state & CHK_ST_INPROGRESS)) {
850 /* no check currently running */
851 if (!expired) /* woke up too early */
852 goto out_unlock;
Willy Tarreauabca5b62013-12-06 14:19:25 +0100853
Willy Tarreau51cd5952020-06-05 12:25:38 +0200854 /* we don't send any health-checks when the proxy is
855 * stopped, the server should not be checked or the check
856 * is disabled.
857 */
858 if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) ||
Willy Tarreauc3914d42020-09-24 08:39:22 +0200859 proxy->disabled)
Willy Tarreau51cd5952020-06-05 12:25:38 +0200860 goto reschedule;
Christopher Faulet404f9192020-04-09 23:13:54 +0200861
Willy Tarreau51cd5952020-06-05 12:25:38 +0200862 /* we'll initiate a new check */
863 set_server_check_status(check, HCHK_STATUS_START, NULL);
Christopher Faulet404f9192020-04-09 23:13:54 +0200864
Willy Tarreau51cd5952020-06-05 12:25:38 +0200865 check->state |= CHK_ST_INPROGRESS;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200866
Willy Tarreau51cd5952020-06-05 12:25:38 +0200867 task_set_affinity(t, tid_bit);
868
869 check->current_step = NULL;
870 tcpcheck_main(check);
871 goto out_unlock;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200872 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200873 else {
874 /* there was a test running.
875 * First, let's check whether there was an uncaught error,
876 * which can happen on connect timeout or error.
877 */
878 if (check->result == CHK_RES_UNKNOWN) {
Christopher Fauletb1bb0692020-11-25 16:47:30 +0100879 /* Here the connection must be defined. Otherwise the
880 * error would have already been detected
881 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200882 if ((conn->flags & CO_FL_ERROR) || cs->flags & CS_FL_ERROR || expired) {
883 chk_report_conn_err(check, 0, expired);
884 }
Christopher Faulet8f100422021-01-18 15:47:03 +0100885 else {
886 if (check->state & CHK_ST_CLOSE_CONN) {
887 cs_destroy(cs);
888 cs = NULL;
889 conn = NULL;
890 check->cs = NULL;
891 check->state &= ~CHK_ST_CLOSE_CONN;
892 tcpcheck_main(check);
893 }
894 if (check->result == CHK_RES_UNKNOWN)
895 goto out_unlock; /* timeout not reached, wait again */
896 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200897 }
Christopher Faulet404f9192020-04-09 23:13:54 +0200898
Willy Tarreau51cd5952020-06-05 12:25:38 +0200899 /* check complete or aborted */
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200900
Willy Tarreau51cd5952020-06-05 12:25:38 +0200901 check->current_step = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200902
Willy Tarreau51cd5952020-06-05 12:25:38 +0200903 if (conn && conn->xprt) {
904 /* The check was aborted and the connection was not yet closed.
905 * This can happen upon timeout, or when an external event such
906 * as a failed response coupled with "observe layer7" caused the
907 * server state to be suddenly changed.
908 */
Willy Tarreau30bd4ef2020-12-11 11:09:29 +0100909 cs_drain_and_close(cs);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200910 }
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200911
Willy Tarreau51cd5952020-06-05 12:25:38 +0200912 if (cs) {
913 if (check->wait_list.events)
914 cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
915 /* We may have been scheduled to run, and the
916 * I/O handler expects to have a cs, so remove
917 * the tasklet
918 */
919 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
920 cs_destroy(cs);
921 cs = check->cs = NULL;
922 conn = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200923 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200924
925 if (check->sess != NULL) {
926 vars_prune(&check->vars, check->sess, NULL);
927 session_free(check->sess);
928 check->sess = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200929 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200930
931 if (check->server) {
932 if (check->result == CHK_RES_FAILED) {
933 /* a failure or timeout detected */
934 check_notify_failure(check);
935 }
936 else if (check->result == CHK_RES_CONDPASS) {
937 /* check is OK but asks for stopping mode */
938 check_notify_stopping(check);
939 }
940 else if (check->result == CHK_RES_PASSED) {
941 /* a success was detected */
942 check_notify_success(check);
943 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200944 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200945 task_set_affinity(t, MAX_THREADS_MASK);
Christopher Fauletb381a502020-11-25 13:47:00 +0100946 check_release_buf(check, &check->bi);
947 check_release_buf(check, &check->bo);
948 check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200949
Willy Tarreau51cd5952020-06-05 12:25:38 +0200950 if (check->server) {
951 rv = 0;
952 if (global.spread_checks > 0) {
953 rv = srv_getinter(check) * global.spread_checks / 100;
954 rv -= (int) (2 * rv * (ha_random32() / 4294967295.0));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200955 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200956 t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(check) + rv));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200957 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200958 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200959
960 reschedule:
961 while (tick_is_expired(t->expire, now_ms))
962 t->expire = tick_add(t->expire, MS_TO_TICKS(check->inter));
963 out_unlock:
964 if (check->server)
965 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
966 return t;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200967}
968
Willy Tarreau51cd5952020-06-05 12:25:38 +0200969
Christopher Faulet61cc8522020-04-20 14:54:42 +0200970/**************************************************************************/
971/************************** Init/deinit checks ****************************/
972/**************************************************************************/
Christopher Fauletb381a502020-11-25 13:47:00 +0100973/*
974 * Tries to grab a buffer and to re-enables processing on check <target>. The
975 * check flags are used to figure what buffer was requested. It returns 1 if the
976 * allocation succeeds, in which case the I/O tasklet is woken up, or 0 if it's
977 * impossible to wake up and we prefer to be woken up later.
978 */
979int check_buf_available(void *target)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200980{
Christopher Fauletb381a502020-11-25 13:47:00 +0100981 struct check *check = target;
982
983 if ((check->state & CHK_ST_IN_ALLOC) && b_alloc_margin(&check->bi, 0)) {
984 check->state &= ~CHK_ST_IN_ALLOC;
985 tasklet_wakeup(check->wait_list.tasklet);
986 return 1;
987 }
988 if ((check->state & CHK_ST_OUT_ALLOC) && b_alloc_margin(&check->bo, 0)) {
989 check->state &= ~CHK_ST_OUT_ALLOC;
990 tasklet_wakeup(check->wait_list.tasklet);
991 return 1;
992 }
993
994 return 0;
995}
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200996
Christopher Fauletb381a502020-11-25 13:47:00 +0100997/*
998 * Allocate a buffer. If if fails, it adds the check in buffer wait queue.
999 */
1000struct buffer *check_get_buf(struct check *check, struct buffer *bptr)
1001{
1002 struct buffer *buf = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +02001003
Christopher Fauletb381a502020-11-25 13:47:00 +01001004 if (likely(!MT_LIST_ADDED(&check->buf_wait.list)) &&
1005 unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) {
1006 check->buf_wait.target = check;
1007 check->buf_wait.wakeup_cb = check_buf_available;
1008 MT_LIST_ADDQ(&buffer_wq, &check->buf_wait.list);
1009 }
1010 return buf;
1011}
1012
1013/*
1014 * Release a buffer, if any, and try to wake up entities waiting in the buffer
1015 * wait queue.
1016 */
1017void check_release_buf(struct check *check, struct buffer *bptr)
1018{
1019 if (bptr->size) {
1020 b_free(bptr);
1021 offer_buffers(check->buf_wait.target, tasks_run_queue);
1022 }
1023}
1024
1025const char *init_check(struct check *check, int type)
1026{
1027 check->type = type;
Christopher Fauletba3c68f2020-04-01 16:27:05 +02001028
Christopher Fauletb381a502020-11-25 13:47:00 +01001029 check->bi = BUF_NULL;
1030 check->bo = BUF_NULL;
1031 MT_LIST_INIT(&check->buf_wait.list);
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001032
Christopher Faulet61cc8522020-04-20 14:54:42 +02001033 check->wait_list.tasklet = tasklet_new();
1034 if (!check->wait_list.tasklet)
1035 return "out of memory while allocating check tasklet";
1036 check->wait_list.events = 0;
1037 check->wait_list.tasklet->process = event_srv_chk_io;
1038 check->wait_list.tasklet->context = check;
1039 return NULL;
1040}
1041
1042void free_check(struct check *check)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001043{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001044 task_destroy(check->task);
1045 if (check->wait_list.tasklet)
1046 tasklet_free(check->wait_list.tasklet);
1047
Christopher Fauletb381a502020-11-25 13:47:00 +01001048 check_release_buf(check, &check->bi);
1049 check_release_buf(check, &check->bo);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001050 if (check->cs) {
1051 free(check->cs->conn);
1052 check->cs->conn = NULL;
1053 cs_free(check->cs);
1054 check->cs = NULL;
1055 }
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001056}
1057
Christopher Faulet61cc8522020-04-20 14:54:42 +02001058/* manages a server health-check. Returns the time the task accepts to wait, or
1059 * TIME_ETERNITY for infinity.
1060 */
Willy Tarreaucee013e2020-06-05 11:40:38 +02001061struct task *process_chk(struct task *t, void *context, unsigned short state)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001062{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001063 struct check *check = context;
1064
1065 if (check->type == PR_O2_EXT_CHK)
1066 return process_chk_proc(t, context, state);
1067 return process_chk_conn(t, context, state);
1068
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001069}
1070
Christopher Faulet61cc8522020-04-20 14:54:42 +02001071
1072static int start_check_task(struct check *check, int mininter,
1073 int nbcheck, int srvpos)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001074{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001075 struct task *t;
1076 unsigned long thread_mask = MAX_THREADS_MASK;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001077
Christopher Faulet61cc8522020-04-20 14:54:42 +02001078 if (check->type == PR_O2_EXT_CHK)
1079 thread_mask = 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001080
Christopher Faulet61cc8522020-04-20 14:54:42 +02001081 /* task for the check */
1082 if ((t = task_new(thread_mask)) == NULL) {
1083 ha_alert("Starting [%s:%s] check: out of memory.\n",
1084 check->server->proxy->id, check->server->id);
1085 return 0;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001086 }
1087
Christopher Faulet61cc8522020-04-20 14:54:42 +02001088 check->task = t;
1089 t->process = process_chk;
1090 t->context = check;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001091
Christopher Faulet61cc8522020-04-20 14:54:42 +02001092 if (mininter < srv_getinter(check))
1093 mininter = srv_getinter(check);
1094
1095 if (global.max_spread_checks && mininter > global.max_spread_checks)
1096 mininter = global.max_spread_checks;
1097
1098 /* check this every ms */
1099 t->expire = tick_add(now_ms, MS_TO_TICKS(mininter * srvpos / nbcheck));
1100 check->start = now;
1101 task_queue(t);
1102
1103 return 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001104}
1105
Christopher Faulet61cc8522020-04-20 14:54:42 +02001106/* updates the server's weight during a warmup stage. Once the final weight is
1107 * reached, the task automatically stops. Note that any server status change
1108 * must have updated s->last_change accordingly.
1109 */
1110static struct task *server_warmup(struct task *t, void *context, unsigned short state)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001111{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001112 struct server *s = context;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001113
Christopher Faulet61cc8522020-04-20 14:54:42 +02001114 /* by default, plan on stopping the task */
1115 t->expire = TICK_ETERNITY;
1116 if ((s->next_admin & SRV_ADMF_MAINT) ||
1117 (s->next_state != SRV_ST_STARTING))
1118 return t;
Christopher Faulete5870d82020-04-15 11:32:03 +02001119
Christopher Faulet61cc8522020-04-20 14:54:42 +02001120 HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001121
Christopher Faulet61cc8522020-04-20 14:54:42 +02001122 /* recalculate the weights and update the state */
1123 server_recalc_eweight(s, 1);
Christopher Faulet5c288742020-03-31 08:15:58 +02001124
Christopher Faulet61cc8522020-04-20 14:54:42 +02001125 /* probably that we can refill this server with a bit more connections */
1126 pendconn_grab_from_px(s);
Christopher Faulet5c288742020-03-31 08:15:58 +02001127
Christopher Faulet61cc8522020-04-20 14:54:42 +02001128 HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
Christopher Faulet5c288742020-03-31 08:15:58 +02001129
Christopher Faulet61cc8522020-04-20 14:54:42 +02001130 /* get back there in 1 second or 1/20th of the slowstart interval,
1131 * whichever is greater, resulting in small 5% steps.
1132 */
1133 if (s->next_state == SRV_ST_STARTING)
1134 t->expire = tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20)));
1135 return t;
1136}
1137
1138/*
1139 * Start health-check.
1140 * Returns 0 if OK, ERR_FATAL on error, and prints the error in this case.
1141 */
1142static int start_checks()
1143{
1144
1145 struct proxy *px;
1146 struct server *s;
1147 struct task *t;
1148 int nbcheck=0, mininter=0, srvpos=0;
1149
1150 /* 0- init the dummy frontend used to create all checks sessions */
1151 init_new_proxy(&checks_fe);
1152 checks_fe.cap = PR_CAP_FE | PR_CAP_BE;
1153 checks_fe.mode = PR_MODE_TCP;
1154 checks_fe.maxconn = 0;
1155 checks_fe.conn_retries = CONN_RETRIES;
1156 checks_fe.options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC;
1157 checks_fe.timeout.client = TICK_ETERNITY;
1158
1159 /* 1- count the checkers to run simultaneously.
1160 * We also determine the minimum interval among all of those which
1161 * have an interval larger than SRV_CHK_INTER_THRES. This interval
1162 * will be used to spread their start-up date. Those which have
1163 * a shorter interval will start independently and will not dictate
1164 * too short an interval for all others.
1165 */
1166 for (px = proxies_list; px; px = px->next) {
1167 for (s = px->srv; s; s = s->next) {
1168 if (s->slowstart) {
1169 if ((t = task_new(MAX_THREADS_MASK)) == NULL) {
1170 ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
1171 return ERR_ALERT | ERR_FATAL;
1172 }
1173 /* We need a warmup task that will be called when the server
1174 * state switches from down to up.
1175 */
1176 s->warmup = t;
1177 t->process = server_warmup;
1178 t->context = s;
1179 /* server can be in this state only because of */
1180 if (s->next_state == SRV_ST_STARTING)
1181 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 +02001182 }
1183
Christopher Faulet61cc8522020-04-20 14:54:42 +02001184 if (s->check.state & CHK_ST_CONFIGURED) {
1185 nbcheck++;
1186 if ((srv_getinter(&s->check) >= SRV_CHK_INTER_THRES) &&
1187 (!mininter || mininter > srv_getinter(&s->check)))
1188 mininter = srv_getinter(&s->check);
Christopher Faulet5c288742020-03-31 08:15:58 +02001189 }
1190
Christopher Faulet61cc8522020-04-20 14:54:42 +02001191 if (s->agent.state & CHK_ST_CONFIGURED) {
1192 nbcheck++;
1193 if ((srv_getinter(&s->agent) >= SRV_CHK_INTER_THRES) &&
1194 (!mininter || mininter > srv_getinter(&s->agent)))
1195 mininter = srv_getinter(&s->agent);
1196 }
Christopher Faulet5c288742020-03-31 08:15:58 +02001197 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001198 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001199
Christopher Faulet61cc8522020-04-20 14:54:42 +02001200 if (!nbcheck)
Christopher Fauletfc633b62020-11-06 15:24:23 +01001201 return ERR_NONE;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001202
Christopher Faulet61cc8522020-04-20 14:54:42 +02001203 srand((unsigned)time(NULL));
Christopher Fauletb7d30092020-03-30 15:19:03 +02001204
Christopher Faulet61cc8522020-04-20 14:54:42 +02001205 /*
1206 * 2- start them as far as possible from each others. For this, we will
1207 * start them after their interval set to the min interval divided by
1208 * the number of servers, weighted by the server's position in the list.
1209 */
1210 for (px = proxies_list; px; px = px->next) {
1211 if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
1212 if (init_pid_list()) {
1213 ha_alert("Starting [%s] check: out of memory.\n", px->id);
1214 return ERR_ALERT | ERR_FATAL;
1215 }
1216 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001217
Christopher Faulet61cc8522020-04-20 14:54:42 +02001218 for (s = px->srv; s; s = s->next) {
1219 /* A task for the main check */
1220 if (s->check.state & CHK_ST_CONFIGURED) {
1221 if (s->check.type == PR_O2_EXT_CHK) {
1222 if (!prepare_external_check(&s->check))
1223 return ERR_ALERT | ERR_FATAL;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001224 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001225 if (!start_check_task(&s->check, mininter, nbcheck, srvpos))
1226 return ERR_ALERT | ERR_FATAL;
1227 srvpos++;
Christopher Faulet98572322020-03-30 13:16:44 +02001228 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001229
Christopher Faulet61cc8522020-04-20 14:54:42 +02001230 /* A task for a auxiliary agent check */
1231 if (s->agent.state & CHK_ST_CONFIGURED) {
1232 if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) {
1233 return ERR_ALERT | ERR_FATAL;
1234 }
1235 srvpos++;
1236 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001237 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001238 }
Christopher Fauletfc633b62020-11-06 15:24:23 +01001239 return ERR_NONE;
Christopher Faulet61cc8522020-04-20 14:54:42 +02001240}
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001241
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001242
Christopher Faulet61cc8522020-04-20 14:54:42 +02001243/*
1244 * Return value:
1245 * the port to be used for the health check
1246 * 0 in case no port could be found for the check
1247 */
1248static int srv_check_healthcheck_port(struct check *chk)
1249{
1250 int i = 0;
1251 struct server *srv = NULL;
1252
1253 srv = chk->server;
1254
1255 /* by default, we use the health check port ocnfigured */
1256 if (chk->port > 0)
1257 return chk->port;
1258
1259 /* try to get the port from check_core.addr if check.port not set */
1260 i = get_host_port(&chk->addr);
1261 if (i > 0)
1262 return i;
1263
1264 /* try to get the port from server address */
1265 /* prevent MAPPORTS from working at this point, since checks could
1266 * not be performed in such case (MAPPORTS impose a relative ports
1267 * based on live traffic)
1268 */
1269 if (srv->flags & SRV_F_MAPPORTS)
1270 return 0;
1271
1272 i = srv->svc_port; /* by default */
1273 if (i > 0)
1274 return i;
1275
1276 return 0;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001277}
1278
Christopher Faulet61cc8522020-04-20 14:54:42 +02001279/* Initializes an health-check attached to the server <srv>. Non-zero is returned
1280 * if an error occurred.
1281 */
1282static int init_srv_check(struct server *srv)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001283{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001284 const char *err;
1285 struct tcpcheck_rule *r;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001286 int ret = ERR_NONE;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001287 int check_type;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001288
Christopher Faulet6ecd5932021-01-12 17:29:45 +01001289 if (!srv->do_check || !(srv->proxy->cap & PR_CAP_BE))
Christopher Faulet61cc8522020-04-20 14:54:42 +02001290 goto out;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001291
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001292 check_type = srv->check.tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001293
Christopher Faulet61cc8522020-04-20 14:54:42 +02001294 /* If neither a port nor an addr was specified and no check transport
1295 * layer is forced, then the transport layer used by the checks is the
1296 * same as for the production traffic. Otherwise we use raw_sock by
1297 * default, unless one is specified.
1298 */
1299 if (!srv->check.port && !is_addr(&srv->check.addr)) {
1300 if (!srv->check.use_ssl && srv->use_ssl != -1) {
1301 srv->check.use_ssl = srv->use_ssl;
1302 srv->check.xprt = srv->xprt;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001303 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001304 else if (srv->check.use_ssl == 1)
1305 srv->check.xprt = xprt_get(XPRT_SSL);
1306 srv->check.send_proxy |= (srv->pp_opts);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001307 }
Christopher Faulet66163ec2020-05-20 22:36:24 +02001308 else if (srv->check.use_ssl == 1)
1309 srv->check.xprt = xprt_get(XPRT_SSL);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001310
Christopher Faulet12882cf2020-04-23 15:50:18 +02001311 /* Inherit the mux protocol from the server if not already defined for
1312 * the check
1313 */
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001314 if (srv->mux_proto && !srv->check.mux_proto &&
1315 ((srv->mux_proto->mode == PROTO_MODE_HTTP && check_type == TCPCHK_RULES_HTTP_CHK) ||
1316 (srv->mux_proto->mode == PROTO_MODE_TCP && check_type != TCPCHK_RULES_HTTP_CHK))) {
Christopher Faulet12882cf2020-04-23 15:50:18 +02001317 srv->check.mux_proto = srv->mux_proto;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001318 }
Amaury Denoyelle7c148902020-11-13 12:34:57 +01001319 /* test that check proto is valid if explicitly defined */
1320 else if (srv->check.mux_proto &&
1321 ((srv->check.mux_proto->mode == PROTO_MODE_HTTP && check_type != TCPCHK_RULES_HTTP_CHK) ||
1322 (srv->check.mux_proto->mode == PROTO_MODE_TCP && check_type == TCPCHK_RULES_HTTP_CHK))) {
1323 ha_alert("config: %s '%s': server '%s' uses an incompatible MUX protocol for the selected check type\n",
1324 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1325 ret |= ERR_ALERT | ERR_FATAL;
1326 goto out;
1327 }
Christopher Faulet12882cf2020-04-23 15:50:18 +02001328
Christopher Faulet61cc8522020-04-20 14:54:42 +02001329 /* validate <srv> server health-check settings */
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001330
Christopher Faulet61cc8522020-04-20 14:54:42 +02001331 /* We need at least a service port, a check port or the first tcp-check
1332 * rule must be a 'connect' one when checking an IPv4/IPv6 server.
1333 */
1334 if ((srv_check_healthcheck_port(&srv->check) != 0) ||
1335 (!is_inet_addr(&srv->check.addr) && (is_addr(&srv->check.addr) || !is_inet_addr(&srv->addr))))
1336 goto init;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001337
Christopher Faulet61cc8522020-04-20 14:54:42 +02001338 if (!srv->proxy->tcpcheck_rules.list || LIST_ISEMPTY(srv->proxy->tcpcheck_rules.list)) {
1339 ha_alert("config: %s '%s': server '%s' has neither service port nor check port.\n",
1340 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1341 ret |= ERR_ALERT | ERR_ABORT;
1342 goto out;
1343 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001344
Christopher Faulet61cc8522020-04-20 14:54:42 +02001345 /* search the first action (connect / send / expect) in the list */
1346 r = get_first_tcpcheck_rule(&srv->proxy->tcpcheck_rules);
1347 if (!r || (r->action != TCPCHK_ACT_CONNECT) || (!r->connect.port && !get_host_port(&r->connect.addr))) {
1348 ha_alert("config: %s '%s': server '%s' has neither service port nor check port "
1349 "nor tcp_check rule 'connect' with port information.\n",
1350 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1351 ret |= ERR_ALERT | ERR_ABORT;
1352 goto out;
1353 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001354
Christopher Faulet61cc8522020-04-20 14:54:42 +02001355 /* scan the tcp-check ruleset to ensure a port has been configured */
1356 list_for_each_entry(r, srv->proxy->tcpcheck_rules.list, list) {
1357 if ((r->action == TCPCHK_ACT_CONNECT) && (!r->connect.port || !get_host_port(&r->connect.addr))) {
1358 ha_alert("config: %s '%s': server '%s' has neither service port nor check port, "
1359 "and a tcp_check rule 'connect' with no port information.\n",
1360 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1361 ret |= ERR_ALERT | ERR_ABORT;
1362 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001363 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001364 }
1365
Christopher Faulet61cc8522020-04-20 14:54:42 +02001366 init:
1367 if (!(srv->proxy->options2 & PR_O2_CHK_ANY)) {
1368 struct tcpcheck_ruleset *rs = NULL;
1369 struct tcpcheck_rules *rules = &srv->proxy->tcpcheck_rules;
1370 //char *errmsg = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001371
Christopher Faulet61cc8522020-04-20 14:54:42 +02001372 srv->proxy->options2 &= ~PR_O2_CHK_ANY;
1373 srv->proxy->options2 |= PR_O2_TCPCHK_CHK;
Christopher Faulete5870d82020-04-15 11:32:03 +02001374
Christopher Faulet61cc8522020-04-20 14:54:42 +02001375 rs = find_tcpcheck_ruleset("*tcp-check");
1376 if (!rs) {
1377 rs = create_tcpcheck_ruleset("*tcp-check");
1378 if (rs == NULL) {
1379 ha_alert("config: %s '%s': out of memory.\n",
1380 proxy_type_str(srv->proxy), srv->proxy->id);
1381 ret |= ERR_ALERT | ERR_FATAL;
1382 goto out;
1383 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001384 }
1385
Christopher Faulet61cc8522020-04-20 14:54:42 +02001386 free_tcpcheck_vars(&rules->preset_vars);
1387 rules->list = &rs->rules;
1388 rules->flags = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001389 }
1390
Christopher Faulet61cc8522020-04-20 14:54:42 +02001391 err = init_check(&srv->check, srv->proxy->options2 & PR_O2_CHK_ANY);
1392 if (err) {
1393 ha_alert("config: %s '%s': unable to init check for server '%s' (%s).\n",
1394 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1395 ret |= ERR_ALERT | ERR_ABORT;
1396 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001397 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001398 srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
1399 global.maxsock++;
Christopher Faulete5870d82020-04-15 11:32:03 +02001400
Christopher Faulet61cc8522020-04-20 14:54:42 +02001401 out:
1402 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001403}
1404
Christopher Faulet61cc8522020-04-20 14:54:42 +02001405/* Initializes an agent-check attached to the server <srv>. Non-zero is returned
1406 * if an error occurred.
1407 */
1408static int init_srv_agent_check(struct server *srv)
Christopher Faulete5870d82020-04-15 11:32:03 +02001409{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001410 struct tcpcheck_rule *chk;
1411 const char *err;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001412 int ret = ERR_NONE;
Christopher Faulete5870d82020-04-15 11:32:03 +02001413
Christopher Faulet6ecd5932021-01-12 17:29:45 +01001414 if (!srv->do_agent || !(srv->proxy->cap & PR_CAP_BE))
Christopher Faulet61cc8522020-04-20 14:54:42 +02001415 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001416
Ilya Shipitsinc02a23f2020-05-06 00:53:22 +05001417 /* If there is no connect rule preceding all send / expect rules, an
Christopher Faulet61cc8522020-04-20 14:54:42 +02001418 * implicit one is inserted before all others.
1419 */
1420 chk = get_first_tcpcheck_rule(srv->agent.tcpcheck_rules);
1421 if (!chk || chk->action != TCPCHK_ACT_CONNECT) {
1422 chk = calloc(1, sizeof(*chk));
1423 if (!chk) {
1424 ha_alert("config : %s '%s': unable to add implicit tcp-check connect rule"
1425 " to agent-check for server '%s' (out of memory).\n",
1426 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1427 ret |= ERR_ALERT | ERR_FATAL;
1428 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001429 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001430 chk->action = TCPCHK_ACT_CONNECT;
1431 chk->connect.options = (TCPCHK_OPT_DEFAULT_CONNECT|TCPCHK_OPT_IMPLICIT);
1432 LIST_ADD(srv->agent.tcpcheck_rules->list, &chk->list);
Christopher Faulete5870d82020-04-15 11:32:03 +02001433 }
1434
Christopher Faulete5870d82020-04-15 11:32:03 +02001435
Christopher Faulet61cc8522020-04-20 14:54:42 +02001436 err = init_check(&srv->agent, PR_O2_TCPCHK_CHK);
1437 if (err) {
1438 ha_alert("config: %s '%s': unable to init agent-check for server '%s' (%s).\n",
1439 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1440 ret |= ERR_ALERT | ERR_ABORT;
1441 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001442 }
1443
Christopher Faulet61cc8522020-04-20 14:54:42 +02001444 if (!srv->agent.inter)
1445 srv->agent.inter = srv->check.inter;
1446
1447 srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
1448 global.maxsock++;
1449
1450 out:
1451 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001452}
1453
Christopher Faulet61cc8522020-04-20 14:54:42 +02001454static void deinit_srv_check(struct server *srv)
1455{
1456 if (srv->check.state & CHK_ST_CONFIGURED)
1457 free_check(&srv->check);
1458 srv->check.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED;
1459 srv->do_check = 0;
1460}
Christopher Faulete5870d82020-04-15 11:32:03 +02001461
Christopher Faulet61cc8522020-04-20 14:54:42 +02001462
1463static void deinit_srv_agent_check(struct server *srv)
1464{
1465 if (srv->agent.tcpcheck_rules) {
1466 free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars);
1467 free(srv->agent.tcpcheck_rules);
1468 srv->agent.tcpcheck_rules = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001469 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001470
Christopher Faulet61cc8522020-04-20 14:54:42 +02001471 if (srv->agent.state & CHK_ST_CONFIGURED)
1472 free_check(&srv->agent);
1473
1474 srv->agent.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED & ~CHK_ST_AGENT;
1475 srv->do_agent = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001476}
1477
Willy Tarreaucee013e2020-06-05 11:40:38 +02001478REGISTER_POST_SERVER_CHECK(init_srv_check);
1479REGISTER_POST_SERVER_CHECK(init_srv_agent_check);
Willy Tarreaucee013e2020-06-05 11:40:38 +02001480REGISTER_POST_CHECK(start_checks);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001481
Willy Tarreaucee013e2020-06-05 11:40:38 +02001482REGISTER_SERVER_DEINIT(deinit_srv_check);
1483REGISTER_SERVER_DEINIT(deinit_srv_agent_check);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001484
Christopher Faulet61cc8522020-04-20 14:54:42 +02001485
1486/**************************************************************************/
1487/************************** Check sample fetches **************************/
1488/**************************************************************************/
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001489
Christopher Faulet61cc8522020-04-20 14:54:42 +02001490static struct sample_fetch_kw_list smp_kws = {ILH, {
Christopher Faulet61cc8522020-04-20 14:54:42 +02001491 { /* END */ },
1492}};
1493
1494INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1495
1496
1497/**************************************************************************/
1498/************************ Check's parsing functions ***********************/
1499/**************************************************************************/
Christopher Fauletce8111e2020-04-06 15:04:11 +02001500/* Parse the "addr" server keyword */
1501static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1502 char **errmsg)
1503{
1504 struct sockaddr_storage *sk;
Christopher Fauletce8111e2020-04-06 15:04:11 +02001505 int port1, port2, err_code = 0;
1506
1507
1508 if (!*args[*cur_arg+1]) {
1509 memprintf(errmsg, "'%s' expects <ipv4|ipv6> as argument.", args[*cur_arg]);
1510 goto error;
1511 }
1512
Willy Tarreau65ec4e32020-09-16 19:17:08 +02001513 sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, errmsg, NULL, NULL,
1514 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Christopher Fauletce8111e2020-04-06 15:04:11 +02001515 if (!sk) {
1516 memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
1517 goto error;
1518 }
1519
Christopher Fauletce8111e2020-04-06 15:04:11 +02001520 srv->check.addr = srv->agent.addr = *sk;
1521 srv->flags |= SRV_F_CHECKADDR;
1522 srv->flags |= SRV_F_AGENTADDR;
1523
1524 out:
1525 return err_code;
1526
1527 error:
1528 err_code |= ERR_ALERT | ERR_FATAL;
1529 goto out;
1530}
1531
1532
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001533/* Parse the "agent-addr" server keyword */
1534static int srv_parse_agent_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1535 char **errmsg)
1536{
1537 int err_code = 0;
1538
1539 if (!*(args[*cur_arg+1])) {
1540 memprintf(errmsg, "'%s' expects an address as argument.", args[*cur_arg]);
1541 goto error;
1542 }
1543 if(str2ip(args[*cur_arg+1], &srv->agent.addr) == NULL) {
1544 memprintf(errmsg, "parsing agent-addr failed. Check if '%s' is correct address.", args[*cur_arg+1]);
1545 goto error;
1546 }
1547
1548 out:
1549 return err_code;
1550
1551 error:
1552 err_code |= ERR_ALERT | ERR_FATAL;
1553 goto out;
1554}
1555
1556/* Parse the "agent-check" server keyword */
1557static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1558 char **errmsg)
1559{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001560 struct tcpcheck_ruleset *rs = NULL;
1561 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1562 struct tcpcheck_rule *chk;
1563 int err_code = 0;
1564
1565 if (srv->do_agent)
1566 goto out;
1567
Christopher Faulet6ecd5932021-01-12 17:29:45 +01001568 if (!(curpx->cap & PR_CAP_BE)) {
1569 memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability",
1570 args[*cur_arg], proxy_type_str(curpx), curpx->id);
1571 return ERR_WARN;
1572 }
1573
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001574 if (!rules) {
1575 rules = calloc(1, sizeof(*rules));
1576 if (!rules) {
1577 memprintf(errmsg, "out of memory.");
1578 goto error;
1579 }
1580 LIST_INIT(&rules->preset_vars);
1581 srv->agent.tcpcheck_rules = rules;
1582 }
1583 rules->list = NULL;
1584 rules->flags = 0;
1585
Christopher Faulet61cc8522020-04-20 14:54:42 +02001586 rs = find_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001587 if (rs)
1588 goto ruleset_found;
1589
Christopher Faulet61cc8522020-04-20 14:54:42 +02001590 rs = create_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001591 if (rs == NULL) {
1592 memprintf(errmsg, "out of memory.");
1593 goto error;
1594 }
1595
Christopher Fauletb50b3e62020-05-05 18:43:43 +02001596 chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", "%[var(check.agent_string)]", ""},
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001597 1, curpx, &rs->rules, srv->conf.file, srv->conf.line, errmsg);
1598 if (!chk) {
1599 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1600 goto error;
1601 }
1602 chk->index = 0;
1603 LIST_ADDQ(&rs->rules, &chk->list);
1604
1605 chk = parse_tcpcheck_expect((char *[]){"tcp-check", "expect", "custom", ""},
Christopher Faulete5870d82020-04-15 11:32:03 +02001606 1, curpx, &rs->rules, TCPCHK_RULES_AGENT_CHK,
1607 srv->conf.file, srv->conf.line, errmsg);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001608 if (!chk) {
1609 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1610 goto error;
1611 }
1612 chk->expect.custom = tcpcheck_agent_expect_reply;
1613 chk->index = 1;
1614 LIST_ADDQ(&rs->rules, &chk->list);
1615
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001616 ruleset_found:
1617 rules->list = &rs->rules;
Christopher Faulet1faf18a2020-11-25 16:43:12 +01001618 rules->flags &= ~(TCPCHK_RULES_PROTO_CHK|TCPCHK_RULES_UNUSED_RS);
Christopher Faulet404f9192020-04-09 23:13:54 +02001619 rules->flags |= TCPCHK_RULES_AGENT_CHK;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001620 srv->do_agent = 1;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001621
1622 out:
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001623 return 0;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001624
1625 error:
1626 deinit_srv_agent_check(srv);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001627 free_tcpcheck_ruleset(rs);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001628 err_code |= ERR_ALERT | ERR_FATAL;
1629 goto out;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001630}
1631
1632/* Parse the "agent-inter" server keyword */
1633static int srv_parse_agent_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1634 char **errmsg)
1635{
1636 const char *err = NULL;
1637 unsigned int delay;
1638 int err_code = 0;
1639
1640 if (!*(args[*cur_arg+1])) {
1641 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1642 goto error;
1643 }
1644
1645 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1646 if (err == PARSE_TIME_OVER) {
1647 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1648 args[*cur_arg+1], args[*cur_arg], srv->id);
1649 goto error;
1650 }
1651 else if (err == PARSE_TIME_UNDER) {
1652 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1653 args[*cur_arg+1], args[*cur_arg], srv->id);
1654 goto error;
1655 }
1656 else if (err) {
1657 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1658 *err, srv->id);
1659 goto error;
1660 }
1661 if (delay <= 0) {
1662 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1663 delay, args[*cur_arg], srv->id);
1664 goto error;
1665 }
1666 srv->agent.inter = delay;
1667
1668 out:
1669 return err_code;
1670
1671 error:
1672 err_code |= ERR_ALERT | ERR_FATAL;
1673 goto out;
1674}
1675
1676/* Parse the "agent-port" server keyword */
1677static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1678 char **errmsg)
1679{
1680 int err_code = 0;
1681
1682 if (!*(args[*cur_arg+1])) {
1683 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
1684 goto error;
1685 }
1686
1687 global.maxsock++;
1688 srv->agent.port = atol(args[*cur_arg+1]);
1689
1690 out:
1691 return err_code;
1692
1693 error:
1694 err_code |= ERR_ALERT | ERR_FATAL;
1695 goto out;
1696}
1697
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001698int set_srv_agent_send(struct server *srv, const char *send)
1699{
1700 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1701 struct tcpcheck_var *var = NULL;
1702 char *str;
1703
1704 str = strdup(send);
Christopher Fauletb61caf42020-04-21 10:57:42 +02001705 var = create_tcpcheck_var(ist("check.agent_string"));
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001706 if (str == NULL || var == NULL)
1707 goto error;
1708
1709 free_tcpcheck_vars(&rules->preset_vars);
1710
1711 var->data.type = SMP_T_STR;
1712 var->data.u.str.area = str;
1713 var->data.u.str.data = strlen(str);
1714 LIST_INIT(&var->list);
1715 LIST_ADDQ(&rules->preset_vars, &var->list);
1716
1717 return 1;
1718
1719 error:
1720 free(str);
1721 free(var);
1722 return 0;
1723}
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001724
1725/* Parse the "agent-send" server keyword */
1726static int srv_parse_agent_send(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1727 char **errmsg)
1728{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001729 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001730 int err_code = 0;
1731
1732 if (!*(args[*cur_arg+1])) {
1733 memprintf(errmsg, "'%s' expects a string as argument.", args[*cur_arg]);
1734 goto error;
1735 }
1736
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001737 if (!rules) {
1738 rules = calloc(1, sizeof(*rules));
1739 if (!rules) {
1740 memprintf(errmsg, "out of memory.");
1741 goto error;
1742 }
1743 LIST_INIT(&rules->preset_vars);
1744 srv->agent.tcpcheck_rules = rules;
1745 }
1746
1747 if (!set_srv_agent_send(srv, args[*cur_arg+1])) {
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001748 memprintf(errmsg, "out of memory.");
1749 goto error;
1750 }
1751
1752 out:
1753 return err_code;
1754
1755 error:
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001756 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001757 err_code |= ERR_ALERT | ERR_FATAL;
1758 goto out;
1759}
1760
1761/* Parse the "no-agent-send" server keyword */
1762static int srv_parse_no_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1763 char **errmsg)
1764{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001765 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001766 return 0;
1767}
1768
Christopher Fauletce8111e2020-04-06 15:04:11 +02001769/* Parse the "check" server keyword */
1770static int srv_parse_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1771 char **errmsg)
1772{
Christopher Faulet6ecd5932021-01-12 17:29:45 +01001773 if (!(curpx->cap & PR_CAP_BE)) {
1774 memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability",
1775 args[*cur_arg], proxy_type_str(curpx), curpx->id);
1776 return ERR_WARN;
1777 }
1778
Christopher Fauletce8111e2020-04-06 15:04:11 +02001779 srv->do_check = 1;
1780 return 0;
1781}
1782
1783/* Parse the "check-send-proxy" server keyword */
1784static int srv_parse_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1785 char **errmsg)
1786{
1787 srv->check.send_proxy = 1;
1788 return 0;
1789}
1790
1791/* Parse the "check-via-socks4" server keyword */
1792static int srv_parse_check_via_socks4(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1793 char **errmsg)
1794{
1795 srv->check.via_socks4 = 1;
1796 return 0;
1797}
1798
1799/* Parse the "no-check" server keyword */
1800static int srv_parse_no_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1801 char **errmsg)
1802{
1803 deinit_srv_check(srv);
1804 return 0;
1805}
1806
1807/* Parse the "no-check-send-proxy" server keyword */
1808static int srv_parse_no_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1809 char **errmsg)
1810{
1811 srv->check.send_proxy = 0;
1812 return 0;
1813}
1814
Christopher Fauletedc6ed92020-04-23 16:27:59 +02001815/* parse the "check-proto" server keyword */
1816static int srv_parse_check_proto(char **args, int *cur_arg,
1817 struct proxy *px, struct server *newsrv, char **err)
1818{
1819 int err_code = 0;
1820
1821 if (!*args[*cur_arg + 1]) {
1822 memprintf(err, "'%s' : missing value", args[*cur_arg]);
1823 goto error;
1824 }
1825 newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1])));
1826 if (!newsrv->check.mux_proto) {
1827 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
1828 goto error;
1829 }
1830
1831 out:
1832 return err_code;
1833
1834 error:
1835 err_code |= ERR_ALERT | ERR_FATAL;
1836 goto out;
1837}
1838
1839
Christopher Fauletce8111e2020-04-06 15:04:11 +02001840/* Parse the "rise" server keyword */
1841static int srv_parse_check_rise(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1842 char **errmsg)
1843{
1844 int err_code = 0;
1845
1846 if (!*args[*cur_arg + 1]) {
1847 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1848 goto error;
1849 }
1850
1851 srv->check.rise = atol(args[*cur_arg+1]);
1852 if (srv->check.rise <= 0) {
1853 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1854 goto error;
1855 }
1856
1857 if (srv->check.health)
1858 srv->check.health = srv->check.rise;
1859
1860 out:
1861 return err_code;
1862
1863 error:
1864 deinit_srv_agent_check(srv);
1865 err_code |= ERR_ALERT | ERR_FATAL;
1866 goto out;
1867 return 0;
1868}
1869
1870/* Parse the "fall" server keyword */
1871static int srv_parse_check_fall(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1872 char **errmsg)
1873{
1874 int err_code = 0;
1875
1876 if (!*args[*cur_arg + 1]) {
1877 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1878 goto error;
1879 }
1880
1881 srv->check.fall = atol(args[*cur_arg+1]);
1882 if (srv->check.fall <= 0) {
1883 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1884 goto error;
1885 }
1886
1887 out:
1888 return err_code;
1889
1890 error:
1891 deinit_srv_agent_check(srv);
1892 err_code |= ERR_ALERT | ERR_FATAL;
1893 goto out;
1894 return 0;
1895}
1896
1897/* Parse the "inter" server keyword */
1898static int srv_parse_check_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1899 char **errmsg)
1900{
1901 const char *err = NULL;
1902 unsigned int delay;
1903 int err_code = 0;
1904
1905 if (!*(args[*cur_arg+1])) {
1906 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1907 goto error;
1908 }
1909
1910 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1911 if (err == PARSE_TIME_OVER) {
1912 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1913 args[*cur_arg+1], args[*cur_arg], srv->id);
1914 goto error;
1915 }
1916 else if (err == PARSE_TIME_UNDER) {
1917 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1918 args[*cur_arg+1], args[*cur_arg], srv->id);
1919 goto error;
1920 }
1921 else if (err) {
1922 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1923 *err, srv->id);
1924 goto error;
1925 }
1926 if (delay <= 0) {
1927 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1928 delay, args[*cur_arg], srv->id);
1929 goto error;
1930 }
1931 srv->check.inter = delay;
1932
1933 out:
1934 return err_code;
1935
1936 error:
1937 err_code |= ERR_ALERT | ERR_FATAL;
1938 goto out;
1939}
1940
1941
1942/* Parse the "fastinter" server keyword */
1943static int srv_parse_check_fastinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1944 char **errmsg)
1945{
1946 const char *err = NULL;
1947 unsigned int delay;
1948 int err_code = 0;
1949
1950 if (!*(args[*cur_arg+1])) {
1951 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1952 goto error;
1953 }
1954
1955 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1956 if (err == PARSE_TIME_OVER) {
1957 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1958 args[*cur_arg+1], args[*cur_arg], srv->id);
1959 goto error;
1960 }
1961 else if (err == PARSE_TIME_UNDER) {
1962 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1963 args[*cur_arg+1], args[*cur_arg], srv->id);
1964 goto error;
1965 }
1966 else if (err) {
1967 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1968 *err, srv->id);
1969 goto error;
1970 }
1971 if (delay <= 0) {
1972 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1973 delay, args[*cur_arg], srv->id);
1974 goto error;
1975 }
1976 srv->check.fastinter = delay;
1977
1978 out:
1979 return err_code;
1980
1981 error:
1982 err_code |= ERR_ALERT | ERR_FATAL;
1983 goto out;
1984}
1985
1986
1987/* Parse the "downinter" server keyword */
1988static int srv_parse_check_downinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1989 char **errmsg)
1990{
1991 const char *err = NULL;
1992 unsigned int delay;
1993 int err_code = 0;
1994
1995 if (!*(args[*cur_arg+1])) {
1996 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1997 goto error;
1998 }
1999
2000 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
2001 if (err == PARSE_TIME_OVER) {
2002 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
2003 args[*cur_arg+1], args[*cur_arg], srv->id);
2004 goto error;
2005 }
2006 else if (err == PARSE_TIME_UNDER) {
2007 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
2008 args[*cur_arg+1], args[*cur_arg], srv->id);
2009 goto error;
2010 }
2011 else if (err) {
2012 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
2013 *err, srv->id);
2014 goto error;
2015 }
2016 if (delay <= 0) {
2017 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
2018 delay, args[*cur_arg], srv->id);
2019 goto error;
2020 }
2021 srv->check.downinter = delay;
2022
2023 out:
2024 return err_code;
2025
2026 error:
2027 err_code |= ERR_ALERT | ERR_FATAL;
2028 goto out;
2029}
2030
2031/* Parse the "port" server keyword */
2032static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
2033 char **errmsg)
2034{
2035 int err_code = 0;
2036
2037 if (!*(args[*cur_arg+1])) {
2038 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
2039 goto error;
2040 }
2041
2042 global.maxsock++;
2043 srv->check.port = atol(args[*cur_arg+1]);
2044 srv->flags |= SRV_F_CHECKPORT;
2045
2046 out:
2047 return err_code;
2048
2049 error:
2050 err_code |= ERR_ALERT | ERR_FATAL;
2051 goto out;
2052}
2053
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002054static struct srv_kw_list srv_kws = { "CHK", { }, {
Christopher Fauletce8111e2020-04-06 15:04:11 +02002055 { "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 +02002056 { "agent-addr", srv_parse_agent_addr, 1, 1 }, /* Enable an auxiliary agent check */
2057 { "agent-check", srv_parse_agent_check, 0, 1 }, /* Enable agent checks */
2058 { "agent-inter", srv_parse_agent_inter, 1, 1 }, /* Set the interval between two agent checks */
2059 { "agent-port", srv_parse_agent_port, 1, 1 }, /* Set the TCP port used for agent checks. */
2060 { "agent-send", srv_parse_agent_send, 1, 1 }, /* Set string to send to agent. */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002061 { "check", srv_parse_check, 0, 1 }, /* Enable health checks */
Christopher Fauletedc6ed92020-04-23 16:27:59 +02002062 { "check-proto", srv_parse_check_proto, 1, 1 }, /* Set the mux protocol for health checks */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002063 { "check-send-proxy", srv_parse_check_send_proxy, 0, 1 }, /* Enable PROXY protocol for health checks */
2064 { "check-via-socks4", srv_parse_check_via_socks4, 0, 1 }, /* Enable socks4 proxy for health checks */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002065 { "no-agent-check", srv_parse_no_agent_check, 0, 1 }, /* Do not enable any auxiliary agent check */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002066 { "no-check", srv_parse_no_check, 0, 1 }, /* Disable health checks */
2067 { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0, 1 }, /* Disable PROXY protol for health checks */
2068 { "rise", srv_parse_check_rise, 1, 1 }, /* Set rise value for health checks */
2069 { "fall", srv_parse_check_fall, 1, 1 }, /* Set fall value for health checks */
2070 { "inter", srv_parse_check_inter, 1, 1 }, /* Set inter value for health checks */
2071 { "fastinter", srv_parse_check_fastinter, 1, 1 }, /* Set fastinter value for health checks */
2072 { "downinter", srv_parse_check_downinter, 1, 1 }, /* Set downinter value for health checks */
2073 { "port", srv_parse_check_port, 1, 1 }, /* Set the TCP port used for health checks. */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002074 { NULL, NULL, 0 },
2075}};
2076
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002077INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01002078
Willy Tarreaubd741542010-03-16 18:46:54 +01002079/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02002080 * Local variables:
2081 * c-indent-level: 8
2082 * c-basic-offset: 8
2083 * End:
2084 */