blob: 51ae99ebfcbe742f6032d44b20726a9cf8958091 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Health-checks functions.
3 *
Willy Tarreau26c25062009-03-08 09:38:41 +01004 * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02005 * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreaubaaee002006-06-26 02:48:02 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
Willy Tarreaub8816082008-01-18 12:18:15 +010014#include <assert.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020015#include <ctype.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020016#include <errno.h>
17#include <fcntl.h>
Simon Horman0ba0e4a2015-01-30 11:23:00 +090018#include <stdarg.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020019#include <stdio.h>
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +020020#include <stdlib.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020021#include <string.h>
Krzysztof Oledzkib304dc72007-10-14 23:40:01 +020022#include <time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020023#include <unistd.h>
Willy Tarreau9f6dc722019-03-01 11:15:10 +010024#include <sys/resource.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020025#include <sys/socket.h>
Dmitry Sivachenkocaf58982009-08-24 15:11:06 +040026#include <sys/types.h>
Simon Horman98637e52014-06-20 12:30:16 +090027#include <sys/wait.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020028#include <netinet/in.h>
Willy Tarreau1274bc42009-07-15 07:16:31 +020029#include <netinet/tcp.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030#include <arpa/inet.h>
31
Willy Tarreau122eba92020-06-04 10:15:32 +020032#include <haproxy/action.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020033#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020034#include <haproxy/arg.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020035#include <haproxy/cfgparse.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020036#include <haproxy/check.h>
Willy Tarreauc13ed532020-06-02 10:22:45 +020037#include <haproxy/chunk.h>
Willy Tarreau7c18b542020-06-11 09:23:02 +020038#include <haproxy/dgram.h>
Willy Tarreaueb92deb2020-06-04 10:53:16 +020039#include <haproxy/dns.h>
Christopher Fauletb381a502020-11-25 13:47:00 +010040#include <haproxy/dynbuf-t.h>
Willy Tarreaubcc67332020-06-05 15:31:31 +020041#include <haproxy/extcheck.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020042#include <haproxy/fd.h>
43#include <haproxy/global.h>
44#include <haproxy/h1.h>
Willy Tarreaucd72d8c2020-06-02 19:11:26 +020045#include <haproxy/http.h>
Willy Tarreau87735332020-06-04 09:08:41 +020046#include <haproxy/http_htx.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020047#include <haproxy/htx.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020048#include <haproxy/istbuf.h>
49#include <haproxy/list.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020050#include <haproxy/log.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020051#include <haproxy/mailers.h>
52#include <haproxy/port_range.h>
53#include <haproxy/proto_tcp.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020054#include <haproxy/protocol.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020055#include <haproxy/proxy.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020056#include <haproxy/queue.h>
57#include <haproxy/regex.h>
58#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020059#include <haproxy/server.h>
Willy Tarreau209108d2020-06-04 20:30:20 +020060#include <haproxy/ssl_sock.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020061#include <haproxy/stats-t.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020062#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020063#include <haproxy/task.h>
Willy Tarreau51cd5952020-06-05 12:25:38 +020064#include <haproxy/tcpcheck.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020065#include <haproxy/thread.h>
66#include <haproxy/time.h>
67#include <haproxy/tools.h>
Willy Tarreaua1718922020-06-04 16:25:31 +020068#include <haproxy/vars.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020069
Olivier Houchard9130a962017-10-17 17:33:43 +020070
Christopher Faulet61cc8522020-04-20 14:54:42 +020071static int wake_srv_chk(struct conn_stream *cs);
72struct data_cb check_conn_cb = {
73 .wake = wake_srv_chk,
74 .name = "CHCK",
75};
Christopher Fauletd7e63962020-04-17 20:15:59 +020076
Christopher Faulet5d503fc2020-03-30 20:34:34 +020077
Gaetan Rivet05d692d2020-02-14 17:42:54 +010078/* Dummy frontend used to create all checks sessions. */
Willy Tarreau51cd5952020-06-05 12:25:38 +020079struct proxy checks_fe;
Christopher Faulet31dff9b2017-10-23 15:45:20 +020080
Christopher Faulet61cc8522020-04-20 14:54:42 +020081/**************************************************************************/
82/************************ Handle check results ****************************/
83/**************************************************************************/
84struct check_status {
85 short result; /* one of SRV_CHK_* */
86 char *info; /* human readable short info */
87 char *desc; /* long description */
88};
89
90struct analyze_status {
91 char *desc; /* description */
92 unsigned char lr[HANA_OBS_SIZE]; /* result for l4/l7: 0 = ignore, 1 - error, 2 - OK */
93};
94
Simon Horman63a4a822012-03-19 07:24:41 +090095static const struct check_status check_statuses[HCHK_STATUS_SIZE] = {
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010096 [HCHK_STATUS_UNKNOWN] = { CHK_RES_UNKNOWN, "UNK", "Unknown" },
97 [HCHK_STATUS_INI] = { CHK_RES_UNKNOWN, "INI", "Initializing" },
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020098 [HCHK_STATUS_START] = { /* SPECIAL STATUS*/ },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020099
Willy Tarreau23964182014-05-20 20:56:30 +0200100 /* Below we have finished checks */
101 [HCHK_STATUS_CHECKED] = { CHK_RES_NEUTRAL, "CHECKED", "No status change" },
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100102 [HCHK_STATUS_HANA] = { CHK_RES_FAILED, "HANA", "Health analyze" },
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100103
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100104 [HCHK_STATUS_SOCKERR] = { CHK_RES_FAILED, "SOCKERR", "Socket error" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200105
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100106 [HCHK_STATUS_L4OK] = { CHK_RES_PASSED, "L4OK", "Layer4 check passed" },
107 [HCHK_STATUS_L4TOUT] = { CHK_RES_FAILED, "L4TOUT", "Layer4 timeout" },
108 [HCHK_STATUS_L4CON] = { CHK_RES_FAILED, "L4CON", "Layer4 connection problem" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200109
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100110 [HCHK_STATUS_L6OK] = { CHK_RES_PASSED, "L6OK", "Layer6 check passed" },
111 [HCHK_STATUS_L6TOUT] = { CHK_RES_FAILED, "L6TOUT", "Layer6 timeout" },
112 [HCHK_STATUS_L6RSP] = { CHK_RES_FAILED, "L6RSP", "Layer6 invalid response" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200113
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100114 [HCHK_STATUS_L7TOUT] = { CHK_RES_FAILED, "L7TOUT", "Layer7 timeout" },
115 [HCHK_STATUS_L7RSP] = { CHK_RES_FAILED, "L7RSP", "Layer7 invalid response" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200116
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200117 [HCHK_STATUS_L57DATA] = { /* DUMMY STATUS */ },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200118
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100119 [HCHK_STATUS_L7OKD] = { CHK_RES_PASSED, "L7OK", "Layer7 check passed" },
120 [HCHK_STATUS_L7OKCD] = { CHK_RES_CONDPASS, "L7OKC", "Layer7 check conditionally passed" },
121 [HCHK_STATUS_L7STS] = { CHK_RES_FAILED, "L7STS", "Layer7 wrong status" },
Simon Horman98637e52014-06-20 12:30:16 +0900122
123 [HCHK_STATUS_PROCERR] = { CHK_RES_FAILED, "PROCERR", "External check error" },
124 [HCHK_STATUS_PROCTOUT] = { CHK_RES_FAILED, "PROCTOUT", "External check timeout" },
Cyril Bonté77010d82014-08-07 01:55:37 +0200125 [HCHK_STATUS_PROCOK] = { CHK_RES_PASSED, "PROCOK", "External check passed" },
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200126};
127
Simon Horman63a4a822012-03-19 07:24:41 +0900128static const struct analyze_status analyze_statuses[HANA_STATUS_SIZE] = { /* 0: ignore, 1: error, 2: OK */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100129 [HANA_STATUS_UNKNOWN] = { "Unknown", { 0, 0 }},
130
131 [HANA_STATUS_L4_OK] = { "L4 successful connection", { 2, 0 }},
132 [HANA_STATUS_L4_ERR] = { "L4 unsuccessful connection", { 1, 1 }},
133
134 [HANA_STATUS_HTTP_OK] = { "Correct http response", { 0, 2 }},
135 [HANA_STATUS_HTTP_STS] = { "Wrong http response", { 0, 1 }},
136 [HANA_STATUS_HTTP_HDRRSP] = { "Invalid http response (headers)", { 0, 1 }},
137 [HANA_STATUS_HTTP_RSP] = { "Invalid http response", { 0, 1 }},
138
139 [HANA_STATUS_HTTP_READ_ERROR] = { "Read error (http)", { 0, 1 }},
140 [HANA_STATUS_HTTP_READ_TIMEOUT] = { "Read timeout (http)", { 0, 1 }},
141 [HANA_STATUS_HTTP_BROKEN_PIPE] = { "Close from server (http)", { 0, 1 }},
142};
143
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100144/* checks if <err> is a real error for errno or one that can be ignored, and
145 * return 0 for these ones or <err> for real ones.
146 */
147static inline int unclean_errno(int err)
148{
149 if (err == EAGAIN || err == EINPROGRESS ||
150 err == EISCONN || err == EALREADY)
151 return 0;
152 return err;
153}
154
Christopher Faulet61cc8522020-04-20 14:54:42 +0200155/* Converts check_status code to description */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200156const char *get_check_status_description(short check_status) {
157
158 const char *desc;
159
160 if (check_status < HCHK_STATUS_SIZE)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200161 desc = check_statuses[check_status].desc;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200162 else
163 desc = NULL;
164
165 if (desc && *desc)
166 return desc;
167 else
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200168 return check_statuses[HCHK_STATUS_UNKNOWN].desc;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200169}
170
Christopher Faulet61cc8522020-04-20 14:54:42 +0200171/* Converts check_status code to short info */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200172const char *get_check_status_info(short check_status) {
173
174 const char *info;
175
176 if (check_status < HCHK_STATUS_SIZE)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200177 info = check_statuses[check_status].info;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200178 else
179 info = NULL;
180
181 if (info && *info)
182 return info;
183 else
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200184 return check_statuses[HCHK_STATUS_UNKNOWN].info;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200185}
186
Christopher Faulet61cc8522020-04-20 14:54:42 +0200187/* Convert analyze_status to description */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100188const char *get_analyze_status(short analyze_status) {
189
190 const char *desc;
191
192 if (analyze_status < HANA_STATUS_SIZE)
193 desc = analyze_statuses[analyze_status].desc;
194 else
195 desc = NULL;
196
197 if (desc && *desc)
198 return desc;
199 else
200 return analyze_statuses[HANA_STATUS_UNKNOWN].desc;
201}
202
Christopher Faulet61cc8522020-04-20 14:54:42 +0200203/* Sets check->status, update check->duration and fill check->result with an
204 * adequate CHK_RES_* value. The new check->health is computed based on the
205 * result.
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200206 *
Christopher Faulet61cc8522020-04-20 14:54:42 +0200207 * Shows information in logs about failed health check if server is UP or
208 * succeeded health checks if server is DOWN.
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200209 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200210void set_server_check_status(struct check *check, short status, const char *desc)
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100211{
Simon Horman4a741432013-02-23 15:35:38 +0900212 struct server *s = check->server;
Willy Tarreaubef1b322014-05-13 21:01:39 +0200213 short prev_status = check->status;
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200214 int report = 0;
Simon Horman4a741432013-02-23 15:35:38 +0900215
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200216 if (status == HCHK_STATUS_START) {
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100217 check->result = CHK_RES_UNKNOWN; /* no result yet */
Simon Horman4a741432013-02-23 15:35:38 +0900218 check->desc[0] = '\0';
219 check->start = now;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200220 return;
221 }
222
Simon Horman4a741432013-02-23 15:35:38 +0900223 if (!check->status)
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200224 return;
225
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200226 if (desc && *desc) {
Simon Horman4a741432013-02-23 15:35:38 +0900227 strncpy(check->desc, desc, HCHK_DESC_LEN-1);
228 check->desc[HCHK_DESC_LEN-1] = '\0';
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200229 } else
Simon Horman4a741432013-02-23 15:35:38 +0900230 check->desc[0] = '\0';
Krzysztof Piotr Oledzkif7089f52009-10-10 21:06:49 +0200231
Simon Horman4a741432013-02-23 15:35:38 +0900232 check->status = status;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200233 if (check_statuses[status].result)
Simon Horman4a741432013-02-23 15:35:38 +0900234 check->result = check_statuses[status].result;
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200235
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100236 if (status == HCHK_STATUS_HANA)
Simon Horman4a741432013-02-23 15:35:38 +0900237 check->duration = -1;
238 else if (!tv_iszero(&check->start)) {
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200239 /* set_server_check_status() may be called more than once */
Simon Horman4a741432013-02-23 15:35:38 +0900240 check->duration = tv_ms_elapsed(&check->start, &now);
241 tv_zero(&check->start);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200242 }
243
Willy Tarreau23964182014-05-20 20:56:30 +0200244 /* no change is expected if no state change occurred */
245 if (check->result == CHK_RES_NEUTRAL)
246 return;
247
Olivier Houchard0923fa42019-01-11 18:43:04 +0100248 /* If the check was really just sending a mail, it won't have an
249 * associated server, so we're done now.
250 */
251 if (!s)
252 return;
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200253 report = 0;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200254
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200255 switch (check->result) {
256 case CHK_RES_FAILED:
Willy Tarreau12634e12014-05-23 11:32:36 +0200257 /* Failure to connect to the agent as a secondary check should not
258 * cause the server to be marked down.
259 */
260 if ((!(check->state & CHK_ST_AGENT) ||
Simon Hormaneaabd522015-02-26 11:26:17 +0900261 (check->status >= HCHK_STATUS_L57DATA)) &&
Christopher Fauletb119a792018-05-02 12:12:45 +0200262 (check->health > 0)) {
Olivier Houchard7059c552019-03-08 18:49:32 +0100263 _HA_ATOMIC_ADD(&s->counters.failed_checks, 1);
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200264 report = 1;
265 check->health--;
266 if (check->health < check->rise)
267 check->health = 0;
268 }
269 break;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200270
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200271 case CHK_RES_PASSED:
Christopher Faulet1e527cb2020-11-20 18:13:02 +0100272 case CHK_RES_CONDPASS:
273 if (check->health < check->rise + check->fall - 1) {
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200274 report = 1;
275 check->health++;
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200276
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200277 if (check->health >= check->rise)
278 check->health = check->rise + check->fall - 1; /* OK now */
279 }
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200280
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200281 /* clear consecutive_errors if observing is enabled */
282 if (s->onerror)
283 s->consecutive_errors = 0;
284 break;
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100285
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200286 default:
287 break;
288 }
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200289
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200290 if (s->proxy->options2 & PR_O2_LOGHCHKS &&
291 (status != prev_status || report)) {
292 chunk_printf(&trash,
Willy Tarreau12634e12014-05-23 11:32:36 +0200293 "%s check for %sserver %s/%s %s%s",
294 (check->state & CHK_ST_AGENT) ? "Agent" : "Health",
Willy Tarreauc93cd162014-05-13 15:54:22 +0200295 s->flags & SRV_F_BACKUP ? "backup " : "",
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100296 s->proxy->id, s->id,
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100297 (check->result == CHK_RES_CONDPASS) ? "conditionally ":"",
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200298 (check->result >= CHK_RES_PASSED) ? "succeeded" : "failed");
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200299
Emeric Brun5a133512017-10-19 14:42:30 +0200300 srv_append_status(&trash, s, check, -1, 0);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200301
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100302 chunk_appendf(&trash, ", status: %d/%d %s",
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200303 (check->health >= check->rise) ? check->health - check->rise + 1 : check->health,
304 (check->health >= check->rise) ? check->fall : check->rise,
305 (check->health >= check->rise) ? (s->uweight ? "UP" : "DRAIN") : "DOWN");
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200306
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200307 ha_warning("%s.\n", trash.area);
308 send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.area);
309 send_email_alert(s, LOG_INFO, "%s", trash.area);
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200310 }
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200311}
312
Willy Tarreau4eec5472014-05-20 22:32:27 +0200313/* Marks the check <check>'s server down if the current check is already failed
314 * and the server is not down yet nor in maintenance.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200315 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200316void check_notify_failure(struct check *check)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200317{
Simon Horman4a741432013-02-23 15:35:38 +0900318 struct server *s = check->server;
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900319
Willy Tarreau7b1d47c2014-05-20 14:55:13 +0200320 /* The agent secondary check should only cause a server to be marked
321 * as down if check->status is HCHK_STATUS_L7STS, which indicates
322 * that the agent returned "fail", "stopped" or "down".
323 * The implication here is that failure to connect to the agent
324 * as a secondary check should not cause the server to be marked
325 * down. */
326 if ((check->state & CHK_ST_AGENT) && check->status != HCHK_STATUS_L7STS)
327 return;
328
Willy Tarreau4eec5472014-05-20 22:32:27 +0200329 if (check->health > 0)
330 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100331
Willy Tarreau4eec5472014-05-20 22:32:27 +0200332 /* We only report a reason for the check if we did not do so previously */
Emeric Brun5a133512017-10-19 14:42:30 +0200333 srv_set_stopped(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200334}
335
Willy Tarreauaf549582014-05-16 17:37:50 +0200336/* Marks the check <check> as valid and tries to set its server up, provided
Willy Tarreau3e048382014-05-21 10:30:54 +0200337 * it isn't in maintenance, it is not tracking a down server and other checks
338 * comply. The rule is simple : by default, a server is up, unless any of the
339 * following conditions is true :
340 * - health check failed (check->health < rise)
341 * - agent check failed (agent->health < rise)
342 * - the server tracks a down server (track && track->state == STOPPED)
343 * Note that if the server has a slowstart, it will switch to STARTING instead
344 * of RUNNING. Also, only the health checks support the nolb mode, so the
345 * agent's success may not take the server out of this mode.
Willy Tarreauaf549582014-05-16 17:37:50 +0200346 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200347void check_notify_success(struct check *check)
Willy Tarreauaf549582014-05-16 17:37:50 +0200348{
Simon Horman4a741432013-02-23 15:35:38 +0900349 struct server *s = check->server;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100350
Emeric Brun52a91d32017-08-31 14:41:55 +0200351 if (s->next_admin & SRV_ADMF_MAINT)
Willy Tarreauaf549582014-05-16 17:37:50 +0200352 return;
Cyril Bontécd19e512010-01-31 22:34:03 +0100353
Emeric Brun52a91d32017-08-31 14:41:55 +0200354 if (s->track && s->track->next_state == SRV_ST_STOPPED)
Willy Tarreauaf549582014-05-16 17:37:50 +0200355 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100356
Willy Tarreau3e048382014-05-21 10:30:54 +0200357 if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise))
358 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100359
Willy Tarreau3e048382014-05-21 10:30:54 +0200360 if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise))
361 return;
Willy Tarreauaf549582014-05-16 17:37:50 +0200362
Emeric Brun52a91d32017-08-31 14:41:55 +0200363 if ((check->state & CHK_ST_AGENT) && s->next_state == SRV_ST_STOPPING)
Willy Tarreau3e048382014-05-21 10:30:54 +0200364 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100365
Emeric Brun5a133512017-10-19 14:42:30 +0200366 srv_set_running(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100367}
368
Willy Tarreaudb58b792014-05-21 13:57:23 +0200369/* Marks the check <check> as valid and tries to set its server into stopping mode
370 * if it was running or starting, and provided it isn't in maintenance and other
371 * checks comply. The conditions for the server to be marked in stopping mode are
372 * the same as for it to be turned up. Also, only the health checks support the
373 * nolb mode.
Willy Tarreauaf549582014-05-16 17:37:50 +0200374 */
Willy Tarreaubcc67332020-06-05 15:31:31 +0200375void check_notify_stopping(struct check *check)
Willy Tarreauaf549582014-05-16 17:37:50 +0200376{
Simon Horman4a741432013-02-23 15:35:38 +0900377 struct server *s = check->server;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100378
Emeric Brun52a91d32017-08-31 14:41:55 +0200379 if (s->next_admin & SRV_ADMF_MAINT)
Willy Tarreauaf549582014-05-16 17:37:50 +0200380 return;
381
Willy Tarreaudb58b792014-05-21 13:57:23 +0200382 if (check->state & CHK_ST_AGENT)
383 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100384
Emeric Brun52a91d32017-08-31 14:41:55 +0200385 if (s->track && s->track->next_state == SRV_ST_STOPPED)
Willy Tarreaudb58b792014-05-21 13:57:23 +0200386 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100387
Willy Tarreaudb58b792014-05-21 13:57:23 +0200388 if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise))
389 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100390
Willy Tarreaudb58b792014-05-21 13:57:23 +0200391 if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise))
392 return;
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100393
Willy Tarreaub26881a2017-12-23 11:16:49 +0100394 srv_set_stopping(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL);
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100395}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200396
Willy Tarreau9fe7aae2013-12-31 23:47:37 +0100397/* note: use health_adjust() only, which first checks that the observe mode is
398 * enabled.
399 */
400void __health_adjust(struct server *s, short status)
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100401{
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100402 int failed;
403 int expire;
404
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100405 if (s->observe >= HANA_OBS_SIZE)
406 return;
407
Willy Tarreaubb956662013-01-24 00:37:39 +0100408 if (status >= HANA_STATUS_SIZE || !analyze_statuses[status].desc)
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100409 return;
410
411 switch (analyze_statuses[status].lr[s->observe - 1]) {
412 case 1:
413 failed = 1;
414 break;
415
416 case 2:
417 failed = 0;
418 break;
419
420 default:
421 return;
422 }
423
424 if (!failed) {
425 /* good: clear consecutive_errors */
426 s->consecutive_errors = 0;
427 return;
428 }
429
Olivier Houchard7059c552019-03-08 18:49:32 +0100430 _HA_ATOMIC_ADD(&s->consecutive_errors, 1);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100431
432 if (s->consecutive_errors < s->consecutive_errors_limit)
433 return;
434
Willy Tarreau19d14ef2012-10-29 16:51:55 +0100435 chunk_printf(&trash, "Detected %d consecutive errors, last one was: %s",
436 s->consecutive_errors, get_analyze_status(status));
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100437
438 switch (s->onerror) {
439 case HANA_ONERR_FASTINTER:
440 /* force fastinter - nothing to do here as all modes force it */
441 break;
442
443 case HANA_ONERR_SUDDTH:
444 /* simulate a pre-fatal failed health check */
Simon Horman58c32972013-11-25 10:46:38 +0900445 if (s->check.health > s->check.rise)
446 s->check.health = s->check.rise + 1;
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100447
Tim Duesterhus588b3142020-05-29 14:35:51 +0200448 /* fall through */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100449
450 case HANA_ONERR_FAILCHK:
451 /* simulate a failed health check */
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200452 set_server_check_status(&s->check, HCHK_STATUS_HANA,
453 trash.area);
Willy Tarreau4eec5472014-05-20 22:32:27 +0200454 check_notify_failure(&s->check);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100455 break;
456
457 case HANA_ONERR_MARKDWN:
458 /* mark server down */
Simon Horman58c32972013-11-25 10:46:38 +0900459 s->check.health = s->check.rise;
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200460 set_server_check_status(&s->check, HCHK_STATUS_HANA,
461 trash.area);
Willy Tarreau4eec5472014-05-20 22:32:27 +0200462 check_notify_failure(&s->check);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100463 break;
464
465 default:
466 /* write a warning? */
467 break;
468 }
469
470 s->consecutive_errors = 0;
Olivier Houchard7059c552019-03-08 18:49:32 +0100471 _HA_ATOMIC_ADD(&s->counters.failed_hana, 1);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100472
Simon Horman66183002013-02-23 10:16:43 +0900473 if (s->check.fastinter) {
474 expire = tick_add(now_ms, MS_TO_TICKS(s->check.fastinter));
Sergiy Prykhodko1d57e502013-09-21 12:05:00 +0300475 if (s->check.task->expire > expire) {
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200476 s->check.task->expire = expire;
Sergiy Prykhodko1d57e502013-09-21 12:05:00 +0300477 /* requeue check task with new expire */
478 task_queue(s->check.task);
479 }
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100480 }
Willy Tarreauef781042010-01-27 11:53:01 +0100481}
482
Christopher Faulet61cc8522020-04-20 14:54:42 +0200483/* Checks the connection. If an error has already been reported or the socket is
Willy Tarreau20a18342013-12-05 00:31:46 +0100484 * closed, keep errno intact as it is supposed to contain the valid error code.
485 * If no error is reported, check the socket's error queue using getsockopt().
486 * Warning, this must be done only once when returning from poll, and never
487 * after an I/O error was attempted, otherwise the error queue might contain
488 * inconsistent errors. If an error is detected, the CO_FL_ERROR is set on the
489 * socket. Returns non-zero if an error was reported, zero if everything is
490 * clean (including a properly closed socket).
491 */
492static int retrieve_errno_from_socket(struct connection *conn)
493{
494 int skerr;
495 socklen_t lskerr = sizeof(skerr);
496
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100497 if (conn->flags & CO_FL_ERROR && (unclean_errno(errno) || !conn->ctrl))
Willy Tarreau20a18342013-12-05 00:31:46 +0100498 return 1;
499
Willy Tarreau3c728722014-01-23 13:50:42 +0100500 if (!conn_ctrl_ready(conn))
Willy Tarreau20a18342013-12-05 00:31:46 +0100501 return 0;
502
Willy Tarreau585744b2017-08-24 14:31:19 +0200503 if (getsockopt(conn->handle.fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == 0)
Willy Tarreau20a18342013-12-05 00:31:46 +0100504 errno = skerr;
505
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100506 errno = unclean_errno(errno);
Willy Tarreau20a18342013-12-05 00:31:46 +0100507
508 if (!errno) {
509 /* we could not retrieve an error, that does not mean there is
510 * none. Just don't change anything and only report the prior
511 * error if any.
512 */
513 if (conn->flags & CO_FL_ERROR)
514 return 1;
515 else
516 return 0;
517 }
518
519 conn->flags |= CO_FL_ERROR | CO_FL_SOCK_WR_SH | CO_FL_SOCK_RD_SH;
520 return 1;
521}
522
Christopher Faulet61cc8522020-04-20 14:54:42 +0200523/* Tries to collect as much information as possible on the connection status,
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100524 * and adjust the server status accordingly. It may make use of <errno_bck>
525 * if non-null when the caller is absolutely certain of its validity (eg:
526 * checked just after a syscall). If the caller doesn't have a valid errno,
527 * it can pass zero, and retrieve_errno_from_socket() will be called to try
528 * to extract errno from the socket. If no error is reported, it will consider
529 * the <expired> flag. This is intended to be used when a connection error was
530 * reported in conn->flags or when a timeout was reported in <expired>. The
531 * function takes care of not updating a server status which was already set.
532 * All situations where at least one of <expired> or CO_FL_ERROR are set
533 * produce a status.
534 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200535void chk_report_conn_err(struct check *check, int errno_bck, int expired)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100536{
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200537 struct conn_stream *cs = check->cs;
538 struct connection *conn = cs_conn(cs);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100539 const char *err_msg;
Willy Tarreau83061a82018-07-13 11:56:34 +0200540 struct buffer *chk;
Willy Tarreau213c6782014-10-02 14:51:02 +0200541 int step;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100542
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100543 if (check->result != CHK_RES_UNKNOWN)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100544 return;
545
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100546 errno = unclean_errno(errno_bck);
547 if (conn && errno)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100548 retrieve_errno_from_socket(conn);
549
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200550 if (conn && !(conn->flags & CO_FL_ERROR) &&
551 !(cs->flags & CS_FL_ERROR) && !expired)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100552 return;
553
554 /* we'll try to build a meaningful error message depending on the
555 * context of the error possibly present in conn->err_code, and the
556 * socket error possibly collected above. This is useful to know the
557 * exact step of the L6 layer (eg: SSL handshake).
558 */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200559 chk = get_trash_chunk();
560
Christopher Faulet799f3a42020-04-07 12:06:14 +0200561 if (check->type == PR_O2_TCPCHK_CHK &&
Christopher Fauletd7e63962020-04-17 20:15:59 +0200562 (check->tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK) == TCPCHK_RULES_TCP_CHK) {
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200563 step = tcpcheck_get_step_id(check, NULL);
Willy Tarreau213c6782014-10-02 14:51:02 +0200564 if (!step)
565 chunk_printf(chk, " at initial connection step of tcp-check");
566 else {
567 chunk_printf(chk, " at step %d of tcp-check", step);
568 /* we were looking for a string */
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200569 if (check->current_step && check->current_step->action == TCPCHK_ACT_CONNECT) {
570 if (check->current_step->connect.port)
571 chunk_appendf(chk, " (connect port %d)" ,check->current_step->connect.port);
Willy Tarreau213c6782014-10-02 14:51:02 +0200572 else
573 chunk_appendf(chk, " (connect)");
574 }
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200575 else if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT) {
576 struct tcpcheck_expect *expect = &check->current_step->expect;
Gaetan Rivetb616add2020-02-07 15:37:17 +0100577
578 switch (expect->type) {
579 case TCPCHK_EXPECT_STRING:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200580 chunk_appendf(chk, " (expect string '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Gaetan Rivetb616add2020-02-07 15:37:17 +0100581 break;
582 case TCPCHK_EXPECT_BINARY:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200583 chunk_appendf(chk, " (expect binary '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Gaetan Rivetb616add2020-02-07 15:37:17 +0100584 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200585 case TCPCHK_EXPECT_STRING_REGEX:
Willy Tarreau213c6782014-10-02 14:51:02 +0200586 chunk_appendf(chk, " (expect regex)");
Gaetan Rivetb616add2020-02-07 15:37:17 +0100587 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200588 case TCPCHK_EXPECT_BINARY_REGEX:
Gaetan Rivetefab6c62020-02-07 15:37:17 +0100589 chunk_appendf(chk, " (expect binary regex)");
590 break;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200591 case TCPCHK_EXPECT_STRING_LF:
592 chunk_appendf(chk, " (expect log-format string)");
593 break;
594 case TCPCHK_EXPECT_BINARY_LF:
595 chunk_appendf(chk, " (expect log-format binary)");
596 break;
Christopher Faulete5870d82020-04-15 11:32:03 +0200597 case TCPCHK_EXPECT_HTTP_STATUS:
Christopher Faulet8021a5f2020-04-24 13:53:12 +0200598 chunk_appendf(chk, " (expect HTTP status codes)");
Christopher Faulete5870d82020-04-15 11:32:03 +0200599 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200600 case TCPCHK_EXPECT_HTTP_STATUS_REGEX:
Christopher Faulete5870d82020-04-15 11:32:03 +0200601 chunk_appendf(chk, " (expect HTTP status regex)");
602 break;
Christopher Faulet39708192020-05-05 10:47:36 +0200603 case TCPCHK_EXPECT_HTTP_HEADER:
604 chunk_appendf(chk, " (expect HTTP header pattern)");
605 break;
Christopher Faulete5870d82020-04-15 11:32:03 +0200606 case TCPCHK_EXPECT_HTTP_BODY:
Christopher Fauletb61caf42020-04-21 10:57:42 +0200607 chunk_appendf(chk, " (expect HTTP body content '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data));
Christopher Faulete5870d82020-04-15 11:32:03 +0200608 break;
Christopher Faulet67a23452020-05-05 18:10:01 +0200609 case TCPCHK_EXPECT_HTTP_BODY_REGEX:
Christopher Faulete5870d82020-04-15 11:32:03 +0200610 chunk_appendf(chk, " (expect HTTP body regex)");
611 break;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200612 case TCPCHK_EXPECT_HTTP_BODY_LF:
613 chunk_appendf(chk, " (expect log-format HTTP body)");
614 break;
Christopher Faulet9e6ed152020-04-03 15:24:06 +0200615 case TCPCHK_EXPECT_CUSTOM:
616 chunk_appendf(chk, " (expect custom function)");
617 break;
Gaetan Rivetb616add2020-02-07 15:37:17 +0100618 case TCPCHK_EXPECT_UNDEF:
619 chunk_appendf(chk, " (undefined expect!)");
620 break;
621 }
Willy Tarreau213c6782014-10-02 14:51:02 +0200622 }
Christopher Fauletb2c2e0f2020-03-30 11:05:10 +0200623 else if (check->current_step && check->current_step->action == TCPCHK_ACT_SEND) {
Willy Tarreau213c6782014-10-02 14:51:02 +0200624 chunk_appendf(chk, " (send)");
625 }
Baptiste Assmann22b09d22015-05-01 08:03:04 +0200626
Christopher Faulet6f2a5e42020-04-01 13:11:41 +0200627 if (check->current_step && check->current_step->comment)
628 chunk_appendf(chk, " comment: '%s'", check->current_step->comment);
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200629 }
630 }
631
Willy Tarreau00149122017-10-04 18:05:01 +0200632 if (conn && conn->err_code) {
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100633 if (unclean_errno(errno))
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200634 chunk_printf(&trash, "%s (%s)%s", conn_err_code_str(conn), strerror(errno),
635 chk->area);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100636 else
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200637 chunk_printf(&trash, "%s%s", conn_err_code_str(conn),
638 chk->area);
639 err_msg = trash.area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100640 }
641 else {
Willy Tarreauc8dc20a2019-12-27 12:03:27 +0100642 if (unclean_errno(errno)) {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200643 chunk_printf(&trash, "%s%s", strerror(errno),
644 chk->area);
645 err_msg = trash.area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100646 }
647 else {
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200648 err_msg = chk->area;
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100649 }
650 }
651
Willy Tarreau00149122017-10-04 18:05:01 +0200652 if (check->state & CHK_ST_PORT_MISS) {
Baptiste Assmann95db2bc2016-06-13 14:15:41 +0200653 /* NOTE: this is reported after <fall> tries */
654 chunk_printf(chk, "No port available for the TCP connection");
655 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
656 }
657
Christopher Faulet5e293762020-10-26 11:10:49 +0100658 if (!conn || !conn->ctrl) {
659 /* error before any connection attempt (connection allocation error or no control layer) */
Willy Tarreau00149122017-10-04 18:05:01 +0200660 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
661 }
Willy Tarreauc192b0a2020-01-23 09:11:58 +0100662 else if (conn->flags & CO_FL_WAIT_L4_CONN) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100663 /* L4 not established (yet) */
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200664 if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100665 set_server_check_status(check, HCHK_STATUS_L4CON, err_msg);
666 else if (expired)
667 set_server_check_status(check, HCHK_STATUS_L4TOUT, err_msg);
Baptiste Assmanna68ca962015-04-14 01:15:08 +0200668
669 /*
670 * might be due to a server IP change.
671 * Let's trigger a DNS resolution if none are currently running.
672 */
Olivier Houchard0923fa42019-01-11 18:43:04 +0100673 if (check->server)
674 dns_trigger_resolution(check->server->dns_requester);
Baptiste Assmanna68ca962015-04-14 01:15:08 +0200675
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100676 }
Willy Tarreauc192b0a2020-01-23 09:11:58 +0100677 else if (conn->flags & CO_FL_WAIT_L6_CONN) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100678 /* L6 not established (yet) */
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200679 if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100680 set_server_check_status(check, HCHK_STATUS_L6RSP, err_msg);
681 else if (expired)
682 set_server_check_status(check, HCHK_STATUS_L6TOUT, err_msg);
683 }
Willy Tarreau4ff3b892017-10-16 15:17:17 +0200684 else if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) {
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100685 /* I/O error after connection was established and before we could diagnose */
686 set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
687 }
688 else if (expired) {
Christopher Fauletcf80f2f2020-04-01 11:04:52 +0200689 enum healthcheck_status tout = HCHK_STATUS_L7TOUT;
690
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100691 /* connection established but expired check */
Christopher Faulet1941bab2020-05-05 07:55:50 +0200692 if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT &&
693 check->current_step->expect.tout_status != HCHK_STATUS_UNKNOWN)
Christopher Faulet811f78c2020-04-01 11:10:27 +0200694 tout = check->current_step->expect.tout_status;
695 set_server_check_status(check, tout, err_msg);
Willy Tarreau25e2ab52013-12-04 11:17:05 +0100696 }
697
698 return;
699}
700
Simon Horman98637e52014-06-20 12:30:16 +0900701
Christopher Faulet61cc8522020-04-20 14:54:42 +0200702/* Builds the server state header used by HTTP health-checks */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200703int httpchk_build_status_header(struct server *s, struct buffer *buf)
Simon Horman98637e52014-06-20 12:30:16 +0900704{
Christopher Faulet61cc8522020-04-20 14:54:42 +0200705 int sv_state;
706 int ratio;
707 char addr[46];
708 char port[6];
709 const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d",
710 "UP %d/%d", "UP",
711 "NOLB %d/%d", "NOLB",
712 "no check" };
Simon Horman98637e52014-06-20 12:30:16 +0900713
Christopher Faulet61cc8522020-04-20 14:54:42 +0200714 if (!(s->check.state & CHK_ST_ENABLED))
715 sv_state = 6;
716 else if (s->cur_state != SRV_ST_STOPPED) {
717 if (s->check.health == s->check.rise + s->check.fall - 1)
718 sv_state = 3; /* UP */
719 else
720 sv_state = 2; /* going down */
Simon Horman98637e52014-06-20 12:30:16 +0900721
Christopher Faulet61cc8522020-04-20 14:54:42 +0200722 if (s->cur_state == SRV_ST_STOPPING)
723 sv_state += 2;
724 } else {
725 if (s->check.health)
726 sv_state = 1; /* going up */
727 else
728 sv_state = 0; /* DOWN */
Simon Horman98637e52014-06-20 12:30:16 +0900729 }
Willy Tarreaub7b24782016-06-21 15:32:29 +0200730
Christopher Faulet61cc8522020-04-20 14:54:42 +0200731 chunk_appendf(buf, srv_hlt_st[sv_state],
732 (s->cur_state != SRV_ST_STOPPED) ? (s->check.health - s->check.rise + 1) : (s->check.health),
733 (s->cur_state != SRV_ST_STOPPED) ? (s->check.fall) : (s->check.rise));
Willy Tarreaub7b24782016-06-21 15:32:29 +0200734
Christopher Faulet61cc8522020-04-20 14:54:42 +0200735 addr_to_str(&s->addr, addr, sizeof(addr));
736 if (s->addr.ss_family == AF_INET || s->addr.ss_family == AF_INET6)
737 snprintf(port, sizeof(port), "%u", s->svc_port);
738 else
739 *port = 0;
Willy Tarreaub7b24782016-06-21 15:32:29 +0200740
Christopher Faulet61cc8522020-04-20 14:54:42 +0200741 chunk_appendf(buf, "; address=%s; port=%s; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d",
742 addr, port, s->proxy->id, s->id,
743 global.node,
744 (s->cur_eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
745 (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv,
746 s->cur_sess, s->proxy->beconn - s->proxy->nbpend,
747 s->nbpend);
Willy Tarreau9f6dc722019-03-01 11:15:10 +0100748
Christopher Faulet61cc8522020-04-20 14:54:42 +0200749 if ((s->cur_state == SRV_ST_STARTING) &&
750 now.tv_sec < s->last_change + s->slowstart &&
751 now.tv_sec >= s->last_change) {
752 ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart);
753 chunk_appendf(buf, "; throttle=%d%%", ratio);
754 }
Christopher Fauletaaae9a02020-04-26 09:50:31 +0200755
Christopher Faulet61cc8522020-04-20 14:54:42 +0200756 return b_data(buf);
757}
Christopher Fauletaaae9a02020-04-26 09:50:31 +0200758
Willy Tarreau51cd5952020-06-05 12:25:38 +0200759/**************************************************************************/
Willy Tarreau51cd5952020-06-05 12:25:38 +0200760/***************** Health-checks based on connections *********************/
761/**************************************************************************/
762/* This function is used only for server health-checks. It handles connection
763 * status updates including errors. If necessary, it wakes the check task up.
764 * It returns 0 on normal cases, <0 if at least one close() has happened on the
765 * connection (eg: reconnect). It relies on tcpcheck_main().
Christopher Faulet61cc8522020-04-20 14:54:42 +0200766 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200767static int wake_srv_chk(struct conn_stream *cs)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200768{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200769 struct connection *conn = cs->conn;
770 struct check *check = cs->data;
771 struct email_alertq *q = container_of(check, typeof(*q), check);
772 int ret = 0;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200773
Willy Tarreau51cd5952020-06-05 12:25:38 +0200774 if (check->server)
775 HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock);
776 else
777 HA_SPIN_LOCK(EMAIL_ALERTS_LOCK, &q->lock);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200778
Willy Tarreau51cd5952020-06-05 12:25:38 +0200779 /* we may have to make progress on the TCP checks */
780 ret = tcpcheck_main(check);
Christopher Fauletaaab0832020-05-05 15:54:22 +0200781
Willy Tarreau51cd5952020-06-05 12:25:38 +0200782 cs = check->cs;
783 conn = cs->conn;
Christopher Fauletaaab0832020-05-05 15:54:22 +0200784
Willy Tarreau51cd5952020-06-05 12:25:38 +0200785 if (unlikely(conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)) {
786 /* We may get error reports bypassing the I/O handlers, typically
787 * the case when sending a pure TCP check which fails, then the I/O
788 * handlers above are not called. This is completely handled by the
789 * main processing task so let's simply wake it up. If we get here,
790 * we expect errno to still be valid.
791 */
792 chk_report_conn_err(check, errno, 0);
793 task_wakeup(check->task, TASK_WOKEN_IO);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200794 }
795
Willy Tarreau51cd5952020-06-05 12:25:38 +0200796 if (check->result != CHK_RES_UNKNOWN) {
797 /* Check complete or aborted. If connection not yet closed do it
798 * now and wake the check task up to be sure the result is
799 * handled ASAP. */
Willy Tarreau30bd4ef2020-12-11 11:09:29 +0100800 cs_drain_and_close(cs);
Willy Tarreau51cd5952020-06-05 12:25:38 +0200801 ret = -1;
802 /* We may have been scheduled to run, and the
803 * I/O handler expects to have a cs, so remove
804 * the tasklet
805 */
806 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
807 task_wakeup(check->task, TASK_WOKEN_IO);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200808 }
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200809
Willy Tarreau51cd5952020-06-05 12:25:38 +0200810 if (check->server)
811 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
812 else
813 HA_SPIN_UNLOCK(EMAIL_ALERTS_LOCK, &q->lock);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200814
Christopher Faulet61cc8522020-04-20 14:54:42 +0200815 return ret;
816}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200817
Willy Tarreau51cd5952020-06-05 12:25:38 +0200818/* This function checks if any I/O is wanted, and if so, attempts to do so */
819static struct task *event_srv_chk_io(struct task *t, void *ctx, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200820{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200821 struct check *check = ctx;
822 struct conn_stream *cs = check->cs;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200823
Willy Tarreau51cd5952020-06-05 12:25:38 +0200824 wake_srv_chk(cs);
825 return NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200826}
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200827
Willy Tarreau51cd5952020-06-05 12:25:38 +0200828/* manages a server health-check that uses a connection. Returns
829 * the time the task accepts to wait, or TIME_ETERNITY for infinity.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200830 *
831 * Please do NOT place any return statement in this function and only leave
Willy Tarreau51cd5952020-06-05 12:25:38 +0200832 * via the out_unlock label.
Christopher Faulet61cc8522020-04-20 14:54:42 +0200833 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200834static struct task *process_chk_conn(struct task *t, void *context, unsigned short state)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200835{
Willy Tarreau51cd5952020-06-05 12:25:38 +0200836 struct check *check = context;
837 struct proxy *proxy = check->proxy;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200838 struct conn_stream *cs = check->cs;
839 struct connection *conn = cs_conn(cs);
Willy Tarreau51cd5952020-06-05 12:25:38 +0200840 int rv;
841 int expired = tick_is_expired(t->expire, now_ms);
Willy Tarreaudeccd112018-06-14 18:38:55 +0200842
Willy Tarreau51cd5952020-06-05 12:25:38 +0200843 if (check->server)
844 HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock);
845 if (!(check->state & CHK_ST_INPROGRESS)) {
846 /* no check currently running */
847 if (!expired) /* woke up too early */
848 goto out_unlock;
Willy Tarreauabca5b62013-12-06 14:19:25 +0100849
Willy Tarreau51cd5952020-06-05 12:25:38 +0200850 /* we don't send any health-checks when the proxy is
851 * stopped, the server should not be checked or the check
852 * is disabled.
853 */
854 if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) ||
Willy Tarreauc3914d42020-09-24 08:39:22 +0200855 proxy->disabled)
Willy Tarreau51cd5952020-06-05 12:25:38 +0200856 goto reschedule;
Christopher Faulet404f9192020-04-09 23:13:54 +0200857
Willy Tarreau51cd5952020-06-05 12:25:38 +0200858 /* we'll initiate a new check */
859 set_server_check_status(check, HCHK_STATUS_START, NULL);
Christopher Faulet404f9192020-04-09 23:13:54 +0200860
Willy Tarreau51cd5952020-06-05 12:25:38 +0200861 check->state |= CHK_ST_INPROGRESS;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200862
Willy Tarreau51cd5952020-06-05 12:25:38 +0200863 task_set_affinity(t, tid_bit);
864
865 check->current_step = NULL;
866 tcpcheck_main(check);
867 goto out_unlock;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200868 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200869 else {
870 /* there was a test running.
871 * First, let's check whether there was an uncaught error,
872 * which can happen on connect timeout or error.
873 */
874 if (check->result == CHK_RES_UNKNOWN) {
Christopher Fauletb1bb0692020-11-25 16:47:30 +0100875 /* Here the connection must be defined. Otherwise the
876 * error would have already been detected
877 */
Willy Tarreau51cd5952020-06-05 12:25:38 +0200878 if ((conn->flags & CO_FL_ERROR) || cs->flags & CS_FL_ERROR || expired) {
879 chk_report_conn_err(check, 0, expired);
880 }
881 else
882 goto out_unlock; /* timeout not reached, wait again */
Christopher Faulet61cc8522020-04-20 14:54:42 +0200883 }
Christopher Faulet404f9192020-04-09 23:13:54 +0200884
Willy Tarreau51cd5952020-06-05 12:25:38 +0200885 /* check complete or aborted */
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200886
Willy Tarreau51cd5952020-06-05 12:25:38 +0200887 check->current_step = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200888
Willy Tarreau51cd5952020-06-05 12:25:38 +0200889 if (conn && conn->xprt) {
890 /* The check was aborted and the connection was not yet closed.
891 * This can happen upon timeout, or when an external event such
892 * as a failed response coupled with "observe layer7" caused the
893 * server state to be suddenly changed.
894 */
Willy Tarreau30bd4ef2020-12-11 11:09:29 +0100895 cs_drain_and_close(cs);
Christopher Faulet61cc8522020-04-20 14:54:42 +0200896 }
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200897
Willy Tarreau51cd5952020-06-05 12:25:38 +0200898 if (cs) {
899 if (check->wait_list.events)
900 cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list);
901 /* We may have been scheduled to run, and the
902 * I/O handler expects to have a cs, so remove
903 * the tasklet
904 */
905 tasklet_remove_from_tasklet_list(check->wait_list.tasklet);
906 cs_destroy(cs);
907 cs = check->cs = NULL;
908 conn = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200909 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200910
911 if (check->sess != NULL) {
912 vars_prune(&check->vars, check->sess, NULL);
913 session_free(check->sess);
914 check->sess = NULL;
Christopher Faulet61cc8522020-04-20 14:54:42 +0200915 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200916
917 if (check->server) {
918 if (check->result == CHK_RES_FAILED) {
919 /* a failure or timeout detected */
920 check_notify_failure(check);
921 }
922 else if (check->result == CHK_RES_CONDPASS) {
923 /* check is OK but asks for stopping mode */
924 check_notify_stopping(check);
925 }
926 else if (check->result == CHK_RES_PASSED) {
927 /* a success was detected */
928 check_notify_success(check);
929 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200930 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200931 task_set_affinity(t, MAX_THREADS_MASK);
Christopher Fauletb381a502020-11-25 13:47:00 +0100932 check_release_buf(check, &check->bi);
933 check_release_buf(check, &check->bo);
934 check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200935
Willy Tarreau51cd5952020-06-05 12:25:38 +0200936 if (check->server) {
937 rv = 0;
938 if (global.spread_checks > 0) {
939 rv = srv_getinter(check) * global.spread_checks / 100;
940 rv -= (int) (2 * rv * (ha_random32() / 4294967295.0));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200941 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200942 t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(check) + rv));
Christopher Faulet61cc8522020-04-20 14:54:42 +0200943 }
Christopher Faulet61cc8522020-04-20 14:54:42 +0200944 }
Willy Tarreau51cd5952020-06-05 12:25:38 +0200945
946 reschedule:
947 while (tick_is_expired(t->expire, now_ms))
948 t->expire = tick_add(t->expire, MS_TO_TICKS(check->inter));
949 out_unlock:
950 if (check->server)
951 HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock);
952 return t;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200953}
954
Willy Tarreau51cd5952020-06-05 12:25:38 +0200955
Christopher Faulet61cc8522020-04-20 14:54:42 +0200956/**************************************************************************/
957/************************** Init/deinit checks ****************************/
958/**************************************************************************/
Christopher Fauletb381a502020-11-25 13:47:00 +0100959/*
960 * Tries to grab a buffer and to re-enables processing on check <target>. The
961 * check flags are used to figure what buffer was requested. It returns 1 if the
962 * allocation succeeds, in which case the I/O tasklet is woken up, or 0 if it's
963 * impossible to wake up and we prefer to be woken up later.
964 */
965int check_buf_available(void *target)
Christopher Faulet61cc8522020-04-20 14:54:42 +0200966{
Christopher Fauletb381a502020-11-25 13:47:00 +0100967 struct check *check = target;
968
969 if ((check->state & CHK_ST_IN_ALLOC) && b_alloc_margin(&check->bi, 0)) {
970 check->state &= ~CHK_ST_IN_ALLOC;
971 tasklet_wakeup(check->wait_list.tasklet);
972 return 1;
973 }
974 if ((check->state & CHK_ST_OUT_ALLOC) && b_alloc_margin(&check->bo, 0)) {
975 check->state &= ~CHK_ST_OUT_ALLOC;
976 tasklet_wakeup(check->wait_list.tasklet);
977 return 1;
978 }
979
980 return 0;
981}
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200982
Christopher Fauletb381a502020-11-25 13:47:00 +0100983/*
984 * Allocate a buffer. If if fails, it adds the check in buffer wait queue.
985 */
986struct buffer *check_get_buf(struct check *check, struct buffer *bptr)
987{
988 struct buffer *buf = NULL;
Christopher Fauletba3c68f2020-04-01 16:27:05 +0200989
Christopher Fauletb381a502020-11-25 13:47:00 +0100990 if (likely(!MT_LIST_ADDED(&check->buf_wait.list)) &&
991 unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) {
992 check->buf_wait.target = check;
993 check->buf_wait.wakeup_cb = check_buf_available;
994 MT_LIST_ADDQ(&buffer_wq, &check->buf_wait.list);
995 }
996 return buf;
997}
998
999/*
1000 * Release a buffer, if any, and try to wake up entities waiting in the buffer
1001 * wait queue.
1002 */
1003void check_release_buf(struct check *check, struct buffer *bptr)
1004{
1005 if (bptr->size) {
1006 b_free(bptr);
1007 offer_buffers(check->buf_wait.target, tasks_run_queue);
1008 }
1009}
1010
1011const char *init_check(struct check *check, int type)
1012{
1013 check->type = type;
Christopher Fauletba3c68f2020-04-01 16:27:05 +02001014
Christopher Fauletb381a502020-11-25 13:47:00 +01001015 check->bi = BUF_NULL;
1016 check->bo = BUF_NULL;
1017 MT_LIST_INIT(&check->buf_wait.list);
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001018
Christopher Faulet61cc8522020-04-20 14:54:42 +02001019 check->wait_list.tasklet = tasklet_new();
1020 if (!check->wait_list.tasklet)
1021 return "out of memory while allocating check tasklet";
1022 check->wait_list.events = 0;
1023 check->wait_list.tasklet->process = event_srv_chk_io;
1024 check->wait_list.tasklet->context = check;
1025 return NULL;
1026}
1027
1028void free_check(struct check *check)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001029{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001030 task_destroy(check->task);
1031 if (check->wait_list.tasklet)
1032 tasklet_free(check->wait_list.tasklet);
1033
Christopher Fauletb381a502020-11-25 13:47:00 +01001034 check_release_buf(check, &check->bi);
1035 check_release_buf(check, &check->bo);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001036 if (check->cs) {
1037 free(check->cs->conn);
1038 check->cs->conn = NULL;
1039 cs_free(check->cs);
1040 check->cs = NULL;
1041 }
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001042}
1043
Christopher Faulet61cc8522020-04-20 14:54:42 +02001044/* manages a server health-check. Returns the time the task accepts to wait, or
1045 * TIME_ETERNITY for infinity.
1046 */
Willy Tarreaucee013e2020-06-05 11:40:38 +02001047struct task *process_chk(struct task *t, void *context, unsigned short state)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001048{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001049 struct check *check = context;
1050
1051 if (check->type == PR_O2_EXT_CHK)
1052 return process_chk_proc(t, context, state);
1053 return process_chk_conn(t, context, state);
1054
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001055}
1056
Christopher Faulet61cc8522020-04-20 14:54:42 +02001057
1058static int start_check_task(struct check *check, int mininter,
1059 int nbcheck, int srvpos)
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001060{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001061 struct task *t;
1062 unsigned long thread_mask = MAX_THREADS_MASK;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001063
Christopher Faulet61cc8522020-04-20 14:54:42 +02001064 if (check->type == PR_O2_EXT_CHK)
1065 thread_mask = 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001066
Christopher Faulet61cc8522020-04-20 14:54:42 +02001067 /* task for the check */
1068 if ((t = task_new(thread_mask)) == NULL) {
1069 ha_alert("Starting [%s:%s] check: out of memory.\n",
1070 check->server->proxy->id, check->server->id);
1071 return 0;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001072 }
1073
Christopher Faulet61cc8522020-04-20 14:54:42 +02001074 check->task = t;
1075 t->process = process_chk;
1076 t->context = check;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001077
Christopher Faulet61cc8522020-04-20 14:54:42 +02001078 if (mininter < srv_getinter(check))
1079 mininter = srv_getinter(check);
1080
1081 if (global.max_spread_checks && mininter > global.max_spread_checks)
1082 mininter = global.max_spread_checks;
1083
1084 /* check this every ms */
1085 t->expire = tick_add(now_ms, MS_TO_TICKS(mininter * srvpos / nbcheck));
1086 check->start = now;
1087 task_queue(t);
1088
1089 return 1;
Gaetan Rivet707b52f2020-02-21 18:14:59 +01001090}
1091
Christopher Faulet61cc8522020-04-20 14:54:42 +02001092/* updates the server's weight during a warmup stage. Once the final weight is
1093 * reached, the task automatically stops. Note that any server status change
1094 * must have updated s->last_change accordingly.
1095 */
1096static struct task *server_warmup(struct task *t, void *context, unsigned short state)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001097{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001098 struct server *s = context;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001099
Christopher Faulet61cc8522020-04-20 14:54:42 +02001100 /* by default, plan on stopping the task */
1101 t->expire = TICK_ETERNITY;
1102 if ((s->next_admin & SRV_ADMF_MAINT) ||
1103 (s->next_state != SRV_ST_STARTING))
1104 return t;
Christopher Faulete5870d82020-04-15 11:32:03 +02001105
Christopher Faulet61cc8522020-04-20 14:54:42 +02001106 HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001107
Christopher Faulet61cc8522020-04-20 14:54:42 +02001108 /* recalculate the weights and update the state */
1109 server_recalc_eweight(s, 1);
Christopher Faulet5c288742020-03-31 08:15:58 +02001110
Christopher Faulet61cc8522020-04-20 14:54:42 +02001111 /* probably that we can refill this server with a bit more connections */
1112 pendconn_grab_from_px(s);
Christopher Faulet5c288742020-03-31 08:15:58 +02001113
Christopher Faulet61cc8522020-04-20 14:54:42 +02001114 HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
Christopher Faulet5c288742020-03-31 08:15:58 +02001115
Christopher Faulet61cc8522020-04-20 14:54:42 +02001116 /* get back there in 1 second or 1/20th of the slowstart interval,
1117 * whichever is greater, resulting in small 5% steps.
1118 */
1119 if (s->next_state == SRV_ST_STARTING)
1120 t->expire = tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20)));
1121 return t;
1122}
1123
1124/*
1125 * Start health-check.
1126 * Returns 0 if OK, ERR_FATAL on error, and prints the error in this case.
1127 */
1128static int start_checks()
1129{
1130
1131 struct proxy *px;
1132 struct server *s;
1133 struct task *t;
1134 int nbcheck=0, mininter=0, srvpos=0;
1135
1136 /* 0- init the dummy frontend used to create all checks sessions */
1137 init_new_proxy(&checks_fe);
1138 checks_fe.cap = PR_CAP_FE | PR_CAP_BE;
1139 checks_fe.mode = PR_MODE_TCP;
1140 checks_fe.maxconn = 0;
1141 checks_fe.conn_retries = CONN_RETRIES;
1142 checks_fe.options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC;
1143 checks_fe.timeout.client = TICK_ETERNITY;
1144
1145 /* 1- count the checkers to run simultaneously.
1146 * We also determine the minimum interval among all of those which
1147 * have an interval larger than SRV_CHK_INTER_THRES. This interval
1148 * will be used to spread their start-up date. Those which have
1149 * a shorter interval will start independently and will not dictate
1150 * too short an interval for all others.
1151 */
1152 for (px = proxies_list; px; px = px->next) {
1153 for (s = px->srv; s; s = s->next) {
1154 if (s->slowstart) {
1155 if ((t = task_new(MAX_THREADS_MASK)) == NULL) {
1156 ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
1157 return ERR_ALERT | ERR_FATAL;
1158 }
1159 /* We need a warmup task that will be called when the server
1160 * state switches from down to up.
1161 */
1162 s->warmup = t;
1163 t->process = server_warmup;
1164 t->context = s;
1165 /* server can be in this state only because of */
1166 if (s->next_state == SRV_ST_STARTING)
1167 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 +02001168 }
1169
Christopher Faulet61cc8522020-04-20 14:54:42 +02001170 if (s->check.state & CHK_ST_CONFIGURED) {
1171 nbcheck++;
1172 if ((srv_getinter(&s->check) >= SRV_CHK_INTER_THRES) &&
1173 (!mininter || mininter > srv_getinter(&s->check)))
1174 mininter = srv_getinter(&s->check);
Christopher Faulet5c288742020-03-31 08:15:58 +02001175 }
1176
Christopher Faulet61cc8522020-04-20 14:54:42 +02001177 if (s->agent.state & CHK_ST_CONFIGURED) {
1178 nbcheck++;
1179 if ((srv_getinter(&s->agent) >= SRV_CHK_INTER_THRES) &&
1180 (!mininter || mininter > srv_getinter(&s->agent)))
1181 mininter = srv_getinter(&s->agent);
1182 }
Christopher Faulet5c288742020-03-31 08:15:58 +02001183 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001184 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001185
Christopher Faulet61cc8522020-04-20 14:54:42 +02001186 if (!nbcheck)
Christopher Fauletfc633b62020-11-06 15:24:23 +01001187 return ERR_NONE;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001188
Christopher Faulet61cc8522020-04-20 14:54:42 +02001189 srand((unsigned)time(NULL));
Christopher Fauletb7d30092020-03-30 15:19:03 +02001190
Christopher Faulet61cc8522020-04-20 14:54:42 +02001191 /*
1192 * 2- start them as far as possible from each others. For this, we will
1193 * start them after their interval set to the min interval divided by
1194 * the number of servers, weighted by the server's position in the list.
1195 */
1196 for (px = proxies_list; px; px = px->next) {
1197 if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) {
1198 if (init_pid_list()) {
1199 ha_alert("Starting [%s] check: out of memory.\n", px->id);
1200 return ERR_ALERT | ERR_FATAL;
1201 }
1202 }
Christopher Fauletb7d30092020-03-30 15:19:03 +02001203
Christopher Faulet61cc8522020-04-20 14:54:42 +02001204 for (s = px->srv; s; s = s->next) {
1205 /* A task for the main check */
1206 if (s->check.state & CHK_ST_CONFIGURED) {
1207 if (s->check.type == PR_O2_EXT_CHK) {
1208 if (!prepare_external_check(&s->check))
1209 return ERR_ALERT | ERR_FATAL;
Christopher Fauletb7d30092020-03-30 15:19:03 +02001210 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001211 if (!start_check_task(&s->check, mininter, nbcheck, srvpos))
1212 return ERR_ALERT | ERR_FATAL;
1213 srvpos++;
Christopher Faulet98572322020-03-30 13:16:44 +02001214 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001215
Christopher Faulet61cc8522020-04-20 14:54:42 +02001216 /* A task for a auxiliary agent check */
1217 if (s->agent.state & CHK_ST_CONFIGURED) {
1218 if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) {
1219 return ERR_ALERT | ERR_FATAL;
1220 }
1221 srvpos++;
1222 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001223 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001224 }
Christopher Fauletfc633b62020-11-06 15:24:23 +01001225 return ERR_NONE;
Christopher Faulet61cc8522020-04-20 14:54:42 +02001226}
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001227
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001228
Christopher Faulet61cc8522020-04-20 14:54:42 +02001229/*
1230 * Return value:
1231 * the port to be used for the health check
1232 * 0 in case no port could be found for the check
1233 */
1234static int srv_check_healthcheck_port(struct check *chk)
1235{
1236 int i = 0;
1237 struct server *srv = NULL;
1238
1239 srv = chk->server;
1240
1241 /* by default, we use the health check port ocnfigured */
1242 if (chk->port > 0)
1243 return chk->port;
1244
1245 /* try to get the port from check_core.addr if check.port not set */
1246 i = get_host_port(&chk->addr);
1247 if (i > 0)
1248 return i;
1249
1250 /* try to get the port from server address */
1251 /* prevent MAPPORTS from working at this point, since checks could
1252 * not be performed in such case (MAPPORTS impose a relative ports
1253 * based on live traffic)
1254 */
1255 if (srv->flags & SRV_F_MAPPORTS)
1256 return 0;
1257
1258 i = srv->svc_port; /* by default */
1259 if (i > 0)
1260 return i;
1261
1262 return 0;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001263}
1264
Christopher Faulet61cc8522020-04-20 14:54:42 +02001265/* Initializes an health-check attached to the server <srv>. Non-zero is returned
1266 * if an error occurred.
1267 */
1268static int init_srv_check(struct server *srv)
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001269{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001270 const char *err;
1271 struct tcpcheck_rule *r;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001272 int ret = ERR_NONE;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001273 int check_type;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001274
Christopher Faulet61cc8522020-04-20 14:54:42 +02001275 if (!srv->do_check)
1276 goto out;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001277
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001278 check_type = srv->check.tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001279
Christopher Faulet61cc8522020-04-20 14:54:42 +02001280 /* If neither a port nor an addr was specified and no check transport
1281 * layer is forced, then the transport layer used by the checks is the
1282 * same as for the production traffic. Otherwise we use raw_sock by
1283 * default, unless one is specified.
1284 */
1285 if (!srv->check.port && !is_addr(&srv->check.addr)) {
1286 if (!srv->check.use_ssl && srv->use_ssl != -1) {
1287 srv->check.use_ssl = srv->use_ssl;
1288 srv->check.xprt = srv->xprt;
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001289 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001290 else if (srv->check.use_ssl == 1)
1291 srv->check.xprt = xprt_get(XPRT_SSL);
1292 srv->check.send_proxy |= (srv->pp_opts);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001293 }
Christopher Faulet66163ec2020-05-20 22:36:24 +02001294 else if (srv->check.use_ssl == 1)
1295 srv->check.xprt = xprt_get(XPRT_SSL);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001296
Christopher Faulet12882cf2020-04-23 15:50:18 +02001297 /* Inherit the mux protocol from the server if not already defined for
1298 * the check
1299 */
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001300 if (srv->mux_proto && !srv->check.mux_proto &&
1301 ((srv->mux_proto->mode == PROTO_MODE_HTTP && check_type == TCPCHK_RULES_HTTP_CHK) ||
1302 (srv->mux_proto->mode == PROTO_MODE_TCP && check_type != TCPCHK_RULES_HTTP_CHK))) {
Christopher Faulet12882cf2020-04-23 15:50:18 +02001303 srv->check.mux_proto = srv->mux_proto;
Amaury Denoyelle0519bd42020-11-13 12:34:56 +01001304 }
Amaury Denoyelle7c148902020-11-13 12:34:57 +01001305 /* test that check proto is valid if explicitly defined */
1306 else if (srv->check.mux_proto &&
1307 ((srv->check.mux_proto->mode == PROTO_MODE_HTTP && check_type != TCPCHK_RULES_HTTP_CHK) ||
1308 (srv->check.mux_proto->mode == PROTO_MODE_TCP && check_type == TCPCHK_RULES_HTTP_CHK))) {
1309 ha_alert("config: %s '%s': server '%s' uses an incompatible MUX protocol for the selected check type\n",
1310 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1311 ret |= ERR_ALERT | ERR_FATAL;
1312 goto out;
1313 }
Christopher Faulet12882cf2020-04-23 15:50:18 +02001314
Christopher Faulet61cc8522020-04-20 14:54:42 +02001315 /* validate <srv> server health-check settings */
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001316
Christopher Faulet61cc8522020-04-20 14:54:42 +02001317 /* We need at least a service port, a check port or the first tcp-check
1318 * rule must be a 'connect' one when checking an IPv4/IPv6 server.
1319 */
1320 if ((srv_check_healthcheck_port(&srv->check) != 0) ||
1321 (!is_inet_addr(&srv->check.addr) && (is_addr(&srv->check.addr) || !is_inet_addr(&srv->addr))))
1322 goto init;
Christopher Fauletf50f4e92020-03-30 19:52:29 +02001323
Christopher Faulet61cc8522020-04-20 14:54:42 +02001324 if (!srv->proxy->tcpcheck_rules.list || LIST_ISEMPTY(srv->proxy->tcpcheck_rules.list)) {
1325 ha_alert("config: %s '%s': server '%s' has neither service port nor check port.\n",
1326 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1327 ret |= ERR_ALERT | ERR_ABORT;
1328 goto out;
1329 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001330
Christopher Faulet61cc8522020-04-20 14:54:42 +02001331 /* search the first action (connect / send / expect) in the list */
1332 r = get_first_tcpcheck_rule(&srv->proxy->tcpcheck_rules);
1333 if (!r || (r->action != TCPCHK_ACT_CONNECT) || (!r->connect.port && !get_host_port(&r->connect.addr))) {
1334 ha_alert("config: %s '%s': server '%s' has neither service port nor check port "
1335 "nor tcp_check rule 'connect' with port information.\n",
1336 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1337 ret |= ERR_ALERT | ERR_ABORT;
1338 goto out;
1339 }
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001340
Christopher Faulet61cc8522020-04-20 14:54:42 +02001341 /* scan the tcp-check ruleset to ensure a port has been configured */
1342 list_for_each_entry(r, srv->proxy->tcpcheck_rules.list, list) {
1343 if ((r->action == TCPCHK_ACT_CONNECT) && (!r->connect.port || !get_host_port(&r->connect.addr))) {
1344 ha_alert("config: %s '%s': server '%s' has neither service port nor check port, "
1345 "and a tcp_check rule 'connect' with no port information.\n",
1346 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1347 ret |= ERR_ALERT | ERR_ABORT;
1348 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001349 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001350 }
1351
Christopher Faulet61cc8522020-04-20 14:54:42 +02001352 init:
1353 if (!(srv->proxy->options2 & PR_O2_CHK_ANY)) {
1354 struct tcpcheck_ruleset *rs = NULL;
1355 struct tcpcheck_rules *rules = &srv->proxy->tcpcheck_rules;
1356 //char *errmsg = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001357
Christopher Faulet61cc8522020-04-20 14:54:42 +02001358 srv->proxy->options2 &= ~PR_O2_CHK_ANY;
1359 srv->proxy->options2 |= PR_O2_TCPCHK_CHK;
Christopher Faulete5870d82020-04-15 11:32:03 +02001360
Christopher Faulet61cc8522020-04-20 14:54:42 +02001361 rs = find_tcpcheck_ruleset("*tcp-check");
1362 if (!rs) {
1363 rs = create_tcpcheck_ruleset("*tcp-check");
1364 if (rs == NULL) {
1365 ha_alert("config: %s '%s': out of memory.\n",
1366 proxy_type_str(srv->proxy), srv->proxy->id);
1367 ret |= ERR_ALERT | ERR_FATAL;
1368 goto out;
1369 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001370 }
1371
Christopher Faulet61cc8522020-04-20 14:54:42 +02001372 free_tcpcheck_vars(&rules->preset_vars);
1373 rules->list = &rs->rules;
1374 rules->flags = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001375 }
1376
Christopher Faulet61cc8522020-04-20 14:54:42 +02001377 err = init_check(&srv->check, srv->proxy->options2 & PR_O2_CHK_ANY);
1378 if (err) {
1379 ha_alert("config: %s '%s': unable to init check for server '%s' (%s).\n",
1380 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1381 ret |= ERR_ALERT | ERR_ABORT;
1382 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001383 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001384 srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
1385 global.maxsock++;
Christopher Faulete5870d82020-04-15 11:32:03 +02001386
Christopher Faulet61cc8522020-04-20 14:54:42 +02001387 out:
1388 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001389}
1390
Christopher Faulet61cc8522020-04-20 14:54:42 +02001391/* Initializes an agent-check attached to the server <srv>. Non-zero is returned
1392 * if an error occurred.
1393 */
1394static int init_srv_agent_check(struct server *srv)
Christopher Faulete5870d82020-04-15 11:32:03 +02001395{
Christopher Faulet61cc8522020-04-20 14:54:42 +02001396 struct tcpcheck_rule *chk;
1397 const char *err;
Christopher Fauletfc633b62020-11-06 15:24:23 +01001398 int ret = ERR_NONE;
Christopher Faulete5870d82020-04-15 11:32:03 +02001399
Christopher Faulet61cc8522020-04-20 14:54:42 +02001400 if (!srv->do_agent)
1401 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001402
Ilya Shipitsinc02a23f2020-05-06 00:53:22 +05001403 /* If there is no connect rule preceding all send / expect rules, an
Christopher Faulet61cc8522020-04-20 14:54:42 +02001404 * implicit one is inserted before all others.
1405 */
1406 chk = get_first_tcpcheck_rule(srv->agent.tcpcheck_rules);
1407 if (!chk || chk->action != TCPCHK_ACT_CONNECT) {
1408 chk = calloc(1, sizeof(*chk));
1409 if (!chk) {
1410 ha_alert("config : %s '%s': unable to add implicit tcp-check connect rule"
1411 " to agent-check for server '%s' (out of memory).\n",
1412 proxy_type_str(srv->proxy), srv->proxy->id, srv->id);
1413 ret |= ERR_ALERT | ERR_FATAL;
1414 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001415 }
Christopher Faulet61cc8522020-04-20 14:54:42 +02001416 chk->action = TCPCHK_ACT_CONNECT;
1417 chk->connect.options = (TCPCHK_OPT_DEFAULT_CONNECT|TCPCHK_OPT_IMPLICIT);
1418 LIST_ADD(srv->agent.tcpcheck_rules->list, &chk->list);
Christopher Faulete5870d82020-04-15 11:32:03 +02001419 }
1420
Christopher Faulete5870d82020-04-15 11:32:03 +02001421
Christopher Faulet61cc8522020-04-20 14:54:42 +02001422 err = init_check(&srv->agent, PR_O2_TCPCHK_CHK);
1423 if (err) {
1424 ha_alert("config: %s '%s': unable to init agent-check for server '%s' (%s).\n",
1425 proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err);
1426 ret |= ERR_ALERT | ERR_ABORT;
1427 goto out;
Christopher Faulete5870d82020-04-15 11:32:03 +02001428 }
1429
Christopher Faulet61cc8522020-04-20 14:54:42 +02001430 if (!srv->agent.inter)
1431 srv->agent.inter = srv->check.inter;
1432
1433 srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
1434 global.maxsock++;
1435
1436 out:
1437 return ret;
Christopher Faulete5870d82020-04-15 11:32:03 +02001438}
1439
Christopher Faulet61cc8522020-04-20 14:54:42 +02001440static void deinit_srv_check(struct server *srv)
1441{
1442 if (srv->check.state & CHK_ST_CONFIGURED)
1443 free_check(&srv->check);
1444 srv->check.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED;
1445 srv->do_check = 0;
1446}
Christopher Faulete5870d82020-04-15 11:32:03 +02001447
Christopher Faulet61cc8522020-04-20 14:54:42 +02001448
1449static void deinit_srv_agent_check(struct server *srv)
1450{
1451 if (srv->agent.tcpcheck_rules) {
1452 free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars);
1453 free(srv->agent.tcpcheck_rules);
1454 srv->agent.tcpcheck_rules = NULL;
Christopher Faulete5870d82020-04-15 11:32:03 +02001455 }
Christopher Faulete5870d82020-04-15 11:32:03 +02001456
Christopher Faulet61cc8522020-04-20 14:54:42 +02001457 if (srv->agent.state & CHK_ST_CONFIGURED)
1458 free_check(&srv->agent);
1459
1460 srv->agent.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED & ~CHK_ST_AGENT;
1461 srv->do_agent = 0;
Christopher Faulete5870d82020-04-15 11:32:03 +02001462}
1463
Willy Tarreaucee013e2020-06-05 11:40:38 +02001464REGISTER_POST_SERVER_CHECK(init_srv_check);
1465REGISTER_POST_SERVER_CHECK(init_srv_agent_check);
Willy Tarreaucee013e2020-06-05 11:40:38 +02001466REGISTER_POST_CHECK(start_checks);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001467
Willy Tarreaucee013e2020-06-05 11:40:38 +02001468REGISTER_SERVER_DEINIT(deinit_srv_check);
1469REGISTER_SERVER_DEINIT(deinit_srv_agent_check);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001470
Christopher Faulet61cc8522020-04-20 14:54:42 +02001471
1472/**************************************************************************/
1473/************************** Check sample fetches **************************/
1474/**************************************************************************/
Christopher Fauletfd6c2292020-03-25 18:20:15 +01001475
Christopher Faulet61cc8522020-04-20 14:54:42 +02001476static struct sample_fetch_kw_list smp_kws = {ILH, {
Christopher Faulet61cc8522020-04-20 14:54:42 +02001477 { /* END */ },
1478}};
1479
1480INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
1481
1482
1483/**************************************************************************/
1484/************************ Check's parsing functions ***********************/
1485/**************************************************************************/
Christopher Fauletce8111e2020-04-06 15:04:11 +02001486/* Parse the "addr" server keyword */
1487static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1488 char **errmsg)
1489{
1490 struct sockaddr_storage *sk;
Christopher Fauletce8111e2020-04-06 15:04:11 +02001491 int port1, port2, err_code = 0;
1492
1493
1494 if (!*args[*cur_arg+1]) {
1495 memprintf(errmsg, "'%s' expects <ipv4|ipv6> as argument.", args[*cur_arg]);
1496 goto error;
1497 }
1498
Willy Tarreau65ec4e32020-09-16 19:17:08 +02001499 sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, errmsg, NULL, NULL,
1500 PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
Christopher Fauletce8111e2020-04-06 15:04:11 +02001501 if (!sk) {
1502 memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
1503 goto error;
1504 }
1505
Christopher Fauletce8111e2020-04-06 15:04:11 +02001506 srv->check.addr = srv->agent.addr = *sk;
1507 srv->flags |= SRV_F_CHECKADDR;
1508 srv->flags |= SRV_F_AGENTADDR;
1509
1510 out:
1511 return err_code;
1512
1513 error:
1514 err_code |= ERR_ALERT | ERR_FATAL;
1515 goto out;
1516}
1517
1518
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001519/* Parse the "agent-addr" server keyword */
1520static int srv_parse_agent_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1521 char **errmsg)
1522{
1523 int err_code = 0;
1524
1525 if (!*(args[*cur_arg+1])) {
1526 memprintf(errmsg, "'%s' expects an address as argument.", args[*cur_arg]);
1527 goto error;
1528 }
1529 if(str2ip(args[*cur_arg+1], &srv->agent.addr) == NULL) {
1530 memprintf(errmsg, "parsing agent-addr failed. Check if '%s' is correct address.", args[*cur_arg+1]);
1531 goto error;
1532 }
1533
1534 out:
1535 return err_code;
1536
1537 error:
1538 err_code |= ERR_ALERT | ERR_FATAL;
1539 goto out;
1540}
1541
1542/* Parse the "agent-check" server keyword */
1543static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1544 char **errmsg)
1545{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001546 struct tcpcheck_ruleset *rs = NULL;
1547 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1548 struct tcpcheck_rule *chk;
1549 int err_code = 0;
1550
1551 if (srv->do_agent)
1552 goto out;
1553
1554 if (!rules) {
1555 rules = calloc(1, sizeof(*rules));
1556 if (!rules) {
1557 memprintf(errmsg, "out of memory.");
1558 goto error;
1559 }
1560 LIST_INIT(&rules->preset_vars);
1561 srv->agent.tcpcheck_rules = rules;
1562 }
1563 rules->list = NULL;
1564 rules->flags = 0;
1565
Christopher Faulet61cc8522020-04-20 14:54:42 +02001566 rs = find_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001567 if (rs)
1568 goto ruleset_found;
1569
Christopher Faulet61cc8522020-04-20 14:54:42 +02001570 rs = create_tcpcheck_ruleset("*agent-check");
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001571 if (rs == NULL) {
1572 memprintf(errmsg, "out of memory.");
1573 goto error;
1574 }
1575
Christopher Fauletb50b3e62020-05-05 18:43:43 +02001576 chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", "%[var(check.agent_string)]", ""},
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001577 1, curpx, &rs->rules, srv->conf.file, srv->conf.line, errmsg);
1578 if (!chk) {
1579 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1580 goto error;
1581 }
1582 chk->index = 0;
1583 LIST_ADDQ(&rs->rules, &chk->list);
1584
1585 chk = parse_tcpcheck_expect((char *[]){"tcp-check", "expect", "custom", ""},
Christopher Faulete5870d82020-04-15 11:32:03 +02001586 1, curpx, &rs->rules, TCPCHK_RULES_AGENT_CHK,
1587 srv->conf.file, srv->conf.line, errmsg);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001588 if (!chk) {
1589 memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);
1590 goto error;
1591 }
1592 chk->expect.custom = tcpcheck_agent_expect_reply;
1593 chk->index = 1;
1594 LIST_ADDQ(&rs->rules, &chk->list);
1595
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001596 ruleset_found:
1597 rules->list = &rs->rules;
Christopher Faulet1faf18a2020-11-25 16:43:12 +01001598 rules->flags &= ~(TCPCHK_RULES_PROTO_CHK|TCPCHK_RULES_UNUSED_RS);
Christopher Faulet404f9192020-04-09 23:13:54 +02001599 rules->flags |= TCPCHK_RULES_AGENT_CHK;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001600 srv->do_agent = 1;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001601
1602 out:
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001603 return 0;
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001604
1605 error:
1606 deinit_srv_agent_check(srv);
Christopher Faulet61cc8522020-04-20 14:54:42 +02001607 free_tcpcheck_ruleset(rs);
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001608 err_code |= ERR_ALERT | ERR_FATAL;
1609 goto out;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001610}
1611
1612/* Parse the "agent-inter" server keyword */
1613static int srv_parse_agent_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1614 char **errmsg)
1615{
1616 const char *err = NULL;
1617 unsigned int delay;
1618 int err_code = 0;
1619
1620 if (!*(args[*cur_arg+1])) {
1621 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1622 goto error;
1623 }
1624
1625 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1626 if (err == PARSE_TIME_OVER) {
1627 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1628 args[*cur_arg+1], args[*cur_arg], srv->id);
1629 goto error;
1630 }
1631 else if (err == PARSE_TIME_UNDER) {
1632 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1633 args[*cur_arg+1], args[*cur_arg], srv->id);
1634 goto error;
1635 }
1636 else if (err) {
1637 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1638 *err, srv->id);
1639 goto error;
1640 }
1641 if (delay <= 0) {
1642 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1643 delay, args[*cur_arg], srv->id);
1644 goto error;
1645 }
1646 srv->agent.inter = delay;
1647
1648 out:
1649 return err_code;
1650
1651 error:
1652 err_code |= ERR_ALERT | ERR_FATAL;
1653 goto out;
1654}
1655
1656/* Parse the "agent-port" server keyword */
1657static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1658 char **errmsg)
1659{
1660 int err_code = 0;
1661
1662 if (!*(args[*cur_arg+1])) {
1663 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
1664 goto error;
1665 }
1666
1667 global.maxsock++;
1668 srv->agent.port = atol(args[*cur_arg+1]);
1669
1670 out:
1671 return err_code;
1672
1673 error:
1674 err_code |= ERR_ALERT | ERR_FATAL;
1675 goto out;
1676}
1677
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001678int set_srv_agent_send(struct server *srv, const char *send)
1679{
1680 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
1681 struct tcpcheck_var *var = NULL;
1682 char *str;
1683
1684 str = strdup(send);
Christopher Fauletb61caf42020-04-21 10:57:42 +02001685 var = create_tcpcheck_var(ist("check.agent_string"));
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001686 if (str == NULL || var == NULL)
1687 goto error;
1688
1689 free_tcpcheck_vars(&rules->preset_vars);
1690
1691 var->data.type = SMP_T_STR;
1692 var->data.u.str.area = str;
1693 var->data.u.str.data = strlen(str);
1694 LIST_INIT(&var->list);
1695 LIST_ADDQ(&rules->preset_vars, &var->list);
1696
1697 return 1;
1698
1699 error:
1700 free(str);
1701 free(var);
1702 return 0;
1703}
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001704
1705/* Parse the "agent-send" server keyword */
1706static int srv_parse_agent_send(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1707 char **errmsg)
1708{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001709 struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules;
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001710 int err_code = 0;
1711
1712 if (!*(args[*cur_arg+1])) {
1713 memprintf(errmsg, "'%s' expects a string as argument.", args[*cur_arg]);
1714 goto error;
1715 }
1716
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001717 if (!rules) {
1718 rules = calloc(1, sizeof(*rules));
1719 if (!rules) {
1720 memprintf(errmsg, "out of memory.");
1721 goto error;
1722 }
1723 LIST_INIT(&rules->preset_vars);
1724 srv->agent.tcpcheck_rules = rules;
1725 }
1726
1727 if (!set_srv_agent_send(srv, args[*cur_arg+1])) {
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001728 memprintf(errmsg, "out of memory.");
1729 goto error;
1730 }
1731
1732 out:
1733 return err_code;
1734
1735 error:
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001736 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001737 err_code |= ERR_ALERT | ERR_FATAL;
1738 goto out;
1739}
1740
1741/* Parse the "no-agent-send" server keyword */
1742static int srv_parse_no_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1743 char **errmsg)
1744{
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +02001745 deinit_srv_agent_check(srv);
Christopher Fauletcbba66c2020-04-06 14:26:30 +02001746 return 0;
1747}
1748
Christopher Fauletce8111e2020-04-06 15:04:11 +02001749/* Parse the "check" server keyword */
1750static int srv_parse_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1751 char **errmsg)
1752{
1753 srv->do_check = 1;
1754 return 0;
1755}
1756
1757/* Parse the "check-send-proxy" server keyword */
1758static int srv_parse_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1759 char **errmsg)
1760{
1761 srv->check.send_proxy = 1;
1762 return 0;
1763}
1764
1765/* Parse the "check-via-socks4" server keyword */
1766static int srv_parse_check_via_socks4(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1767 char **errmsg)
1768{
1769 srv->check.via_socks4 = 1;
1770 return 0;
1771}
1772
1773/* Parse the "no-check" server keyword */
1774static int srv_parse_no_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1775 char **errmsg)
1776{
1777 deinit_srv_check(srv);
1778 return 0;
1779}
1780
1781/* Parse the "no-check-send-proxy" server keyword */
1782static int srv_parse_no_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1783 char **errmsg)
1784{
1785 srv->check.send_proxy = 0;
1786 return 0;
1787}
1788
Christopher Fauletedc6ed92020-04-23 16:27:59 +02001789/* parse the "check-proto" server keyword */
1790static int srv_parse_check_proto(char **args, int *cur_arg,
1791 struct proxy *px, struct server *newsrv, char **err)
1792{
1793 int err_code = 0;
1794
1795 if (!*args[*cur_arg + 1]) {
1796 memprintf(err, "'%s' : missing value", args[*cur_arg]);
1797 goto error;
1798 }
1799 newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1])));
1800 if (!newsrv->check.mux_proto) {
1801 memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]);
1802 goto error;
1803 }
1804
1805 out:
1806 return err_code;
1807
1808 error:
1809 err_code |= ERR_ALERT | ERR_FATAL;
1810 goto out;
1811}
1812
1813
Christopher Fauletce8111e2020-04-06 15:04:11 +02001814/* Parse the "rise" server keyword */
1815static int srv_parse_check_rise(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1816 char **errmsg)
1817{
1818 int err_code = 0;
1819
1820 if (!*args[*cur_arg + 1]) {
1821 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1822 goto error;
1823 }
1824
1825 srv->check.rise = atol(args[*cur_arg+1]);
1826 if (srv->check.rise <= 0) {
1827 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1828 goto error;
1829 }
1830
1831 if (srv->check.health)
1832 srv->check.health = srv->check.rise;
1833
1834 out:
1835 return err_code;
1836
1837 error:
1838 deinit_srv_agent_check(srv);
1839 err_code |= ERR_ALERT | ERR_FATAL;
1840 goto out;
1841 return 0;
1842}
1843
1844/* Parse the "fall" server keyword */
1845static int srv_parse_check_fall(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1846 char **errmsg)
1847{
1848 int err_code = 0;
1849
1850 if (!*args[*cur_arg + 1]) {
1851 memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]);
1852 goto error;
1853 }
1854
1855 srv->check.fall = atol(args[*cur_arg+1]);
1856 if (srv->check.fall <= 0) {
1857 memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]);
1858 goto error;
1859 }
1860
1861 out:
1862 return err_code;
1863
1864 error:
1865 deinit_srv_agent_check(srv);
1866 err_code |= ERR_ALERT | ERR_FATAL;
1867 goto out;
1868 return 0;
1869}
1870
1871/* Parse the "inter" server keyword */
1872static int srv_parse_check_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1873 char **errmsg)
1874{
1875 const char *err = NULL;
1876 unsigned int delay;
1877 int err_code = 0;
1878
1879 if (!*(args[*cur_arg+1])) {
1880 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1881 goto error;
1882 }
1883
1884 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1885 if (err == PARSE_TIME_OVER) {
1886 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1887 args[*cur_arg+1], args[*cur_arg], srv->id);
1888 goto error;
1889 }
1890 else if (err == PARSE_TIME_UNDER) {
1891 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1892 args[*cur_arg+1], args[*cur_arg], srv->id);
1893 goto error;
1894 }
1895 else if (err) {
1896 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1897 *err, srv->id);
1898 goto error;
1899 }
1900 if (delay <= 0) {
1901 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1902 delay, args[*cur_arg], srv->id);
1903 goto error;
1904 }
1905 srv->check.inter = delay;
1906
1907 out:
1908 return err_code;
1909
1910 error:
1911 err_code |= ERR_ALERT | ERR_FATAL;
1912 goto out;
1913}
1914
1915
1916/* Parse the "fastinter" server keyword */
1917static int srv_parse_check_fastinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1918 char **errmsg)
1919{
1920 const char *err = NULL;
1921 unsigned int delay;
1922 int err_code = 0;
1923
1924 if (!*(args[*cur_arg+1])) {
1925 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1926 goto error;
1927 }
1928
1929 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1930 if (err == PARSE_TIME_OVER) {
1931 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1932 args[*cur_arg+1], args[*cur_arg], srv->id);
1933 goto error;
1934 }
1935 else if (err == PARSE_TIME_UNDER) {
1936 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1937 args[*cur_arg+1], args[*cur_arg], srv->id);
1938 goto error;
1939 }
1940 else if (err) {
1941 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1942 *err, srv->id);
1943 goto error;
1944 }
1945 if (delay <= 0) {
1946 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1947 delay, args[*cur_arg], srv->id);
1948 goto error;
1949 }
1950 srv->check.fastinter = delay;
1951
1952 out:
1953 return err_code;
1954
1955 error:
1956 err_code |= ERR_ALERT | ERR_FATAL;
1957 goto out;
1958}
1959
1960
1961/* Parse the "downinter" server keyword */
1962static int srv_parse_check_downinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
1963 char **errmsg)
1964{
1965 const char *err = NULL;
1966 unsigned int delay;
1967 int err_code = 0;
1968
1969 if (!*(args[*cur_arg+1])) {
1970 memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]);
1971 goto error;
1972 }
1973
1974 err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS);
1975 if (err == PARSE_TIME_OVER) {
1976 memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).",
1977 args[*cur_arg+1], args[*cur_arg], srv->id);
1978 goto error;
1979 }
1980 else if (err == PARSE_TIME_UNDER) {
1981 memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.",
1982 args[*cur_arg+1], args[*cur_arg], srv->id);
1983 goto error;
1984 }
1985 else if (err) {
1986 memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.",
1987 *err, srv->id);
1988 goto error;
1989 }
1990 if (delay <= 0) {
1991 memprintf(errmsg, "invalid value %d for argument '%s' of server %s.",
1992 delay, args[*cur_arg], srv->id);
1993 goto error;
1994 }
1995 srv->check.downinter = delay;
1996
1997 out:
1998 return err_code;
1999
2000 error:
2001 err_code |= ERR_ALERT | ERR_FATAL;
2002 goto out;
2003}
2004
2005/* Parse the "port" server keyword */
2006static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
2007 char **errmsg)
2008{
2009 int err_code = 0;
2010
2011 if (!*(args[*cur_arg+1])) {
2012 memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]);
2013 goto error;
2014 }
2015
2016 global.maxsock++;
2017 srv->check.port = atol(args[*cur_arg+1]);
2018 srv->flags |= SRV_F_CHECKPORT;
2019
2020 out:
2021 return err_code;
2022
2023 error:
2024 err_code |= ERR_ALERT | ERR_FATAL;
2025 goto out;
2026}
2027
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002028static struct srv_kw_list srv_kws = { "CHK", { }, {
Christopher Fauletce8111e2020-04-06 15:04:11 +02002029 { "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 +02002030 { "agent-addr", srv_parse_agent_addr, 1, 1 }, /* Enable an auxiliary agent check */
2031 { "agent-check", srv_parse_agent_check, 0, 1 }, /* Enable agent checks */
2032 { "agent-inter", srv_parse_agent_inter, 1, 1 }, /* Set the interval between two agent checks */
2033 { "agent-port", srv_parse_agent_port, 1, 1 }, /* Set the TCP port used for agent checks. */
2034 { "agent-send", srv_parse_agent_send, 1, 1 }, /* Set string to send to agent. */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002035 { "check", srv_parse_check, 0, 1 }, /* Enable health checks */
Christopher Fauletedc6ed92020-04-23 16:27:59 +02002036 { "check-proto", srv_parse_check_proto, 1, 1 }, /* Set the mux protocol for health checks */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002037 { "check-send-proxy", srv_parse_check_send_proxy, 0, 1 }, /* Enable PROXY protocol for health checks */
2038 { "check-via-socks4", srv_parse_check_via_socks4, 0, 1 }, /* Enable socks4 proxy for health checks */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002039 { "no-agent-check", srv_parse_no_agent_check, 0, 1 }, /* Do not enable any auxiliary agent check */
Christopher Fauletce8111e2020-04-06 15:04:11 +02002040 { "no-check", srv_parse_no_check, 0, 1 }, /* Disable health checks */
2041 { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0, 1 }, /* Disable PROXY protol for health checks */
2042 { "rise", srv_parse_check_rise, 1, 1 }, /* Set rise value for health checks */
2043 { "fall", srv_parse_check_fall, 1, 1 }, /* Set fall value for health checks */
2044 { "inter", srv_parse_check_inter, 1, 1 }, /* Set inter value for health checks */
2045 { "fastinter", srv_parse_check_fastinter, 1, 1 }, /* Set fastinter value for health checks */
2046 { "downinter", srv_parse_check_downinter, 1, 1 }, /* Set downinter value for health checks */
2047 { "port", srv_parse_check_port, 1, 1 }, /* Set the TCP port used for health checks. */
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002048 { NULL, NULL, 0 },
2049}};
2050
Christopher Fauletcbba66c2020-04-06 14:26:30 +02002051INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws);
Christopher Fauletfd6c2292020-03-25 18:20:15 +01002052
Willy Tarreaubd741542010-03-16 18:46:54 +01002053/*
Willy Tarreaubaaee002006-06-26 02:48:02 +02002054 * Local variables:
2055 * c-indent-level: 8
2056 * c-basic-offset: 8
2057 * End:
2058 */