Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Health-checks functions. |
| 3 | * |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 4 | * Copyright 2000-2009 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6 | * |
| 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 Tarreau | b881608 | 2008-01-18 12:18:15 +0100 | [diff] [blame] | 14 | #include <assert.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 15 | #include <ctype.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
Simon Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 18 | #include <stdarg.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 19 | #include <stdio.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 20 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 21 | #include <string.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 22 | #include <time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | #include <unistd.h> |
Willy Tarreau | 9f6dc72 | 2019-03-01 11:15:10 +0100 | [diff] [blame] | 24 | #include <sys/resource.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | #include <sys/socket.h> |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 26 | #include <sys/types.h> |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 27 | #include <sys/wait.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 28 | #include <netinet/in.h> |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 29 | #include <netinet/tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | #include <arpa/inet.h> |
| 31 | |
Willy Tarreau | 122eba9 | 2020-06-04 10:15:32 +0200 | [diff] [blame] | 32 | #include <haproxy/action.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 33 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 34 | #include <haproxy/arg.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 35 | #include <haproxy/cfgparse.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 36 | #include <haproxy/check.h> |
Willy Tarreau | c13ed53 | 2020-06-02 10:22:45 +0200 | [diff] [blame] | 37 | #include <haproxy/chunk.h> |
Willy Tarreau | 7c18b54 | 2020-06-11 09:23:02 +0200 | [diff] [blame] | 38 | #include <haproxy/dgram.h> |
Willy Tarreau | eb92deb | 2020-06-04 10:53:16 +0200 | [diff] [blame] | 39 | #include <haproxy/dns.h> |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 40 | #include <haproxy/dynbuf-t.h> |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 41 | #include <haproxy/extcheck.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 42 | #include <haproxy/fd.h> |
| 43 | #include <haproxy/global.h> |
| 44 | #include <haproxy/h1.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 45 | #include <haproxy/http.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 46 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 47 | #include <haproxy/htx.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 48 | #include <haproxy/istbuf.h> |
| 49 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 50 | #include <haproxy/log.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 51 | #include <haproxy/mailers.h> |
| 52 | #include <haproxy/port_range.h> |
| 53 | #include <haproxy/proto_tcp.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 54 | #include <haproxy/protocol.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 55 | #include <haproxy/proxy.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 56 | #include <haproxy/queue.h> |
| 57 | #include <haproxy/regex.h> |
| 58 | #include <haproxy/sample.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 59 | #include <haproxy/server.h> |
Willy Tarreau | 209108d | 2020-06-04 20:30:20 +0200 | [diff] [blame] | 60 | #include <haproxy/ssl_sock.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 61 | #include <haproxy/stats-t.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 62 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 63 | #include <haproxy/task.h> |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 64 | #include <haproxy/tcpcheck.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 65 | #include <haproxy/thread.h> |
| 66 | #include <haproxy/time.h> |
| 67 | #include <haproxy/tools.h> |
Willy Tarreau | a171892 | 2020-06-04 16:25:31 +0200 | [diff] [blame] | 68 | #include <haproxy/vars.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 69 | |
Olivier Houchard | 9130a96 | 2017-10-17 17:33:43 +0200 | [diff] [blame] | 70 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 71 | static int wake_srv_chk(struct conn_stream *cs); |
| 72 | struct data_cb check_conn_cb = { |
| 73 | .wake = wake_srv_chk, |
| 74 | .name = "CHCK", |
| 75 | }; |
Christopher Faulet | d7e6396 | 2020-04-17 20:15:59 +0200 | [diff] [blame] | 76 | |
Christopher Faulet | 5d503fc | 2020-03-30 20:34:34 +0200 | [diff] [blame] | 77 | |
Gaetan Rivet | 05d692d | 2020-02-14 17:42:54 +0100 | [diff] [blame] | 78 | /* Dummy frontend used to create all checks sessions. */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 79 | struct proxy checks_fe; |
Christopher Faulet | 31dff9b | 2017-10-23 15:45:20 +0200 | [diff] [blame] | 80 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 81 | /**************************************************************************/ |
| 82 | /************************ Handle check results ****************************/ |
| 83 | /**************************************************************************/ |
| 84 | struct check_status { |
| 85 | short result; /* one of SRV_CHK_* */ |
| 86 | char *info; /* human readable short info */ |
| 87 | char *desc; /* long description */ |
| 88 | }; |
| 89 | |
| 90 | struct 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 Horman | 63a4a82 | 2012-03-19 07:24:41 +0900 | [diff] [blame] | 95 | static const struct check_status check_statuses[HCHK_STATUS_SIZE] = { |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 96 | [HCHK_STATUS_UNKNOWN] = { CHK_RES_UNKNOWN, "UNK", "Unknown" }, |
| 97 | [HCHK_STATUS_INI] = { CHK_RES_UNKNOWN, "INI", "Initializing" }, |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 98 | [HCHK_STATUS_START] = { /* SPECIAL STATUS*/ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 99 | |
Willy Tarreau | 2396418 | 2014-05-20 20:56:30 +0200 | [diff] [blame] | 100 | /* Below we have finished checks */ |
| 101 | [HCHK_STATUS_CHECKED] = { CHK_RES_NEUTRAL, "CHECKED", "No status change" }, |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 102 | [HCHK_STATUS_HANA] = { CHK_RES_FAILED, "HANA", "Health analyze" }, |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 103 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 104 | [HCHK_STATUS_SOCKERR] = { CHK_RES_FAILED, "SOCKERR", "Socket error" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 105 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 106 | [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 Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 109 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 110 | [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 Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 113 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 114 | [HCHK_STATUS_L7TOUT] = { CHK_RES_FAILED, "L7TOUT", "Layer7 timeout" }, |
| 115 | [HCHK_STATUS_L7RSP] = { CHK_RES_FAILED, "L7RSP", "Layer7 invalid response" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 116 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 117 | [HCHK_STATUS_L57DATA] = { /* DUMMY STATUS */ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 118 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 119 | [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 Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 122 | |
| 123 | [HCHK_STATUS_PROCERR] = { CHK_RES_FAILED, "PROCERR", "External check error" }, |
| 124 | [HCHK_STATUS_PROCTOUT] = { CHK_RES_FAILED, "PROCTOUT", "External check timeout" }, |
Cyril Bonté | 77010d8 | 2014-08-07 01:55:37 +0200 | [diff] [blame] | 125 | [HCHK_STATUS_PROCOK] = { CHK_RES_PASSED, "PROCOK", "External check passed" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
Simon Horman | 63a4a82 | 2012-03-19 07:24:41 +0900 | [diff] [blame] | 128 | static const struct analyze_status analyze_statuses[HANA_STATUS_SIZE] = { /* 0: ignore, 1: error, 2: OK */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 129 | [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 Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 144 | /* 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 | */ |
| 147 | static 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 Faulet | 7aa3271 | 2021-02-01 13:11:50 +0100 | [diff] [blame] | 155 | /* Converts check_status code to result code */ |
| 156 | short get_check_status_result(short check_status) |
| 157 | { |
| 158 | if (check_status < HCHK_STATUS_SIZE) |
| 159 | return check_statuses[check_status].result; |
| 160 | else |
| 161 | return check_statuses[HCHK_STATUS_UNKNOWN].result; |
| 162 | } |
| 163 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 164 | /* Converts check_status code to description */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 165 | const char *get_check_status_description(short check_status) { |
| 166 | |
| 167 | const char *desc; |
| 168 | |
| 169 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 170 | desc = check_statuses[check_status].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 171 | else |
| 172 | desc = NULL; |
| 173 | |
| 174 | if (desc && *desc) |
| 175 | return desc; |
| 176 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 177 | return check_statuses[HCHK_STATUS_UNKNOWN].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 180 | /* Converts check_status code to short info */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 181 | const char *get_check_status_info(short check_status) { |
| 182 | |
| 183 | const char *info; |
| 184 | |
| 185 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 186 | info = check_statuses[check_status].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 187 | else |
| 188 | info = NULL; |
| 189 | |
| 190 | if (info && *info) |
| 191 | return info; |
| 192 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 193 | return check_statuses[HCHK_STATUS_UNKNOWN].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 196 | /* Convert analyze_status to description */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 197 | const char *get_analyze_status(short analyze_status) { |
| 198 | |
| 199 | const char *desc; |
| 200 | |
| 201 | if (analyze_status < HANA_STATUS_SIZE) |
| 202 | desc = analyze_statuses[analyze_status].desc; |
| 203 | else |
| 204 | desc = NULL; |
| 205 | |
| 206 | if (desc && *desc) |
| 207 | return desc; |
| 208 | else |
| 209 | return analyze_statuses[HANA_STATUS_UNKNOWN].desc; |
| 210 | } |
| 211 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 212 | /* Sets check->status, update check->duration and fill check->result with an |
| 213 | * adequate CHK_RES_* value. The new check->health is computed based on the |
| 214 | * result. |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 215 | * |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 216 | * Shows information in logs about failed health check if server is UP or |
| 217 | * succeeded health checks if server is DOWN. |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 218 | */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 219 | void set_server_check_status(struct check *check, short status, const char *desc) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 220 | { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 221 | struct server *s = check->server; |
Willy Tarreau | bef1b32 | 2014-05-13 21:01:39 +0200 | [diff] [blame] | 222 | short prev_status = check->status; |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 223 | int report = 0; |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 224 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 225 | if (status == HCHK_STATUS_START) { |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 226 | check->result = CHK_RES_UNKNOWN; /* no result yet */ |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 227 | check->desc[0] = '\0'; |
| 228 | check->start = now; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 232 | if (!check->status) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 233 | return; |
| 234 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 235 | if (desc && *desc) { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 236 | strncpy(check->desc, desc, HCHK_DESC_LEN-1); |
| 237 | check->desc[HCHK_DESC_LEN-1] = '\0'; |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 238 | } else |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 239 | check->desc[0] = '\0'; |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 240 | |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 241 | check->status = status; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 242 | if (check_statuses[status].result) |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 243 | check->result = check_statuses[status].result; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 244 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 245 | if (status == HCHK_STATUS_HANA) |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 246 | check->duration = -1; |
| 247 | else if (!tv_iszero(&check->start)) { |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 248 | /* set_server_check_status() may be called more than once */ |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 249 | check->duration = tv_ms_elapsed(&check->start, &now); |
| 250 | tv_zero(&check->start); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Willy Tarreau | 2396418 | 2014-05-20 20:56:30 +0200 | [diff] [blame] | 253 | /* no change is expected if no state change occurred */ |
| 254 | if (check->result == CHK_RES_NEUTRAL) |
| 255 | return; |
| 256 | |
Olivier Houchard | 0923fa4 | 2019-01-11 18:43:04 +0100 | [diff] [blame] | 257 | /* If the check was really just sending a mail, it won't have an |
| 258 | * associated server, so we're done now. |
| 259 | */ |
| 260 | if (!s) |
| 261 | return; |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 262 | report = 0; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 263 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 264 | switch (check->result) { |
| 265 | case CHK_RES_FAILED: |
Willy Tarreau | 12634e1 | 2014-05-23 11:32:36 +0200 | [diff] [blame] | 266 | /* Failure to connect to the agent as a secondary check should not |
| 267 | * cause the server to be marked down. |
| 268 | */ |
| 269 | if ((!(check->state & CHK_ST_AGENT) || |
Simon Horman | eaabd52 | 2015-02-26 11:26:17 +0900 | [diff] [blame] | 270 | (check->status >= HCHK_STATUS_L57DATA)) && |
Christopher Faulet | b119a79 | 2018-05-02 12:12:45 +0200 | [diff] [blame] | 271 | (check->health > 0)) { |
Olivier Houchard | 7059c55 | 2019-03-08 18:49:32 +0100 | [diff] [blame] | 272 | _HA_ATOMIC_ADD(&s->counters.failed_checks, 1); |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 273 | report = 1; |
| 274 | check->health--; |
| 275 | if (check->health < check->rise) |
| 276 | check->health = 0; |
| 277 | } |
| 278 | break; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 279 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 280 | case CHK_RES_PASSED: |
Christopher Faulet | 1e527cb | 2020-11-20 18:13:02 +0100 | [diff] [blame] | 281 | case CHK_RES_CONDPASS: |
| 282 | if (check->health < check->rise + check->fall - 1) { |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 283 | report = 1; |
| 284 | check->health++; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 286 | if (check->health >= check->rise) |
| 287 | check->health = check->rise + check->fall - 1; /* OK now */ |
| 288 | } |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 289 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 290 | /* clear consecutive_errors if observing is enabled */ |
| 291 | if (s->onerror) |
| 292 | s->consecutive_errors = 0; |
| 293 | break; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 294 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 295 | default: |
| 296 | break; |
| 297 | } |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 298 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 299 | if (s->proxy->options2 & PR_O2_LOGHCHKS && |
| 300 | (status != prev_status || report)) { |
| 301 | chunk_printf(&trash, |
Willy Tarreau | 12634e1 | 2014-05-23 11:32:36 +0200 | [diff] [blame] | 302 | "%s check for %sserver %s/%s %s%s", |
| 303 | (check->state & CHK_ST_AGENT) ? "Agent" : "Health", |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 304 | s->flags & SRV_F_BACKUP ? "backup " : "", |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 305 | s->proxy->id, s->id, |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 306 | (check->result == CHK_RES_CONDPASS) ? "conditionally ":"", |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 307 | (check->result >= CHK_RES_PASSED) ? "succeeded" : "failed"); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 308 | |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 309 | srv_append_status(&trash, s, check, -1, 0); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 310 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 311 | chunk_appendf(&trash, ", status: %d/%d %s", |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 312 | (check->health >= check->rise) ? check->health - check->rise + 1 : check->health, |
| 313 | (check->health >= check->rise) ? check->fall : check->rise, |
| 314 | (check->health >= check->rise) ? (s->uweight ? "UP" : "DRAIN") : "DOWN"); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 315 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 316 | ha_warning("%s.\n", trash.area); |
| 317 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.area); |
| 318 | send_email_alert(s, LOG_INFO, "%s", trash.area); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 319 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Willy Tarreau | 4eec547 | 2014-05-20 22:32:27 +0200 | [diff] [blame] | 322 | /* Marks the check <check>'s server down if the current check is already failed |
| 323 | * and the server is not down yet nor in maintenance. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 324 | */ |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 325 | void check_notify_failure(struct check *check) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 326 | { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 327 | struct server *s = check->server; |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 328 | |
Willy Tarreau | 7b1d47c | 2014-05-20 14:55:13 +0200 | [diff] [blame] | 329 | /* The agent secondary check should only cause a server to be marked |
| 330 | * as down if check->status is HCHK_STATUS_L7STS, which indicates |
| 331 | * that the agent returned "fail", "stopped" or "down". |
| 332 | * The implication here is that failure to connect to the agent |
| 333 | * as a secondary check should not cause the server to be marked |
| 334 | * down. */ |
| 335 | if ((check->state & CHK_ST_AGENT) && check->status != HCHK_STATUS_L7STS) |
| 336 | return; |
| 337 | |
Willy Tarreau | 4eec547 | 2014-05-20 22:32:27 +0200 | [diff] [blame] | 338 | if (check->health > 0) |
| 339 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 340 | |
Willy Tarreau | 4eec547 | 2014-05-20 22:32:27 +0200 | [diff] [blame] | 341 | /* We only report a reason for the check if we did not do so previously */ |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 342 | srv_set_stopped(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 345 | /* Marks the check <check> as valid and tries to set its server up, provided |
Willy Tarreau | 3e04838 | 2014-05-21 10:30:54 +0200 | [diff] [blame] | 346 | * it isn't in maintenance, it is not tracking a down server and other checks |
| 347 | * comply. The rule is simple : by default, a server is up, unless any of the |
| 348 | * following conditions is true : |
| 349 | * - health check failed (check->health < rise) |
| 350 | * - agent check failed (agent->health < rise) |
| 351 | * - the server tracks a down server (track && track->state == STOPPED) |
| 352 | * Note that if the server has a slowstart, it will switch to STARTING instead |
| 353 | * of RUNNING. Also, only the health checks support the nolb mode, so the |
| 354 | * agent's success may not take the server out of this mode. |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 355 | */ |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 356 | void check_notify_success(struct check *check) |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 357 | { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 358 | struct server *s = check->server; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 359 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 360 | if (s->next_admin & SRV_ADMF_MAINT) |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 361 | return; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 362 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 363 | if (s->track && s->track->next_state == SRV_ST_STOPPED) |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 364 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 365 | |
Willy Tarreau | 3e04838 | 2014-05-21 10:30:54 +0200 | [diff] [blame] | 366 | if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise)) |
| 367 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 368 | |
Willy Tarreau | 3e04838 | 2014-05-21 10:30:54 +0200 | [diff] [blame] | 369 | if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise)) |
| 370 | return; |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 371 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 372 | if ((check->state & CHK_ST_AGENT) && s->next_state == SRV_ST_STOPPING) |
Willy Tarreau | 3e04838 | 2014-05-21 10:30:54 +0200 | [diff] [blame] | 373 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 374 | |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 375 | srv_set_running(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 376 | } |
| 377 | |
Willy Tarreau | db58b79 | 2014-05-21 13:57:23 +0200 | [diff] [blame] | 378 | /* Marks the check <check> as valid and tries to set its server into stopping mode |
| 379 | * if it was running or starting, and provided it isn't in maintenance and other |
| 380 | * checks comply. The conditions for the server to be marked in stopping mode are |
| 381 | * the same as for it to be turned up. Also, only the health checks support the |
| 382 | * nolb mode. |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 383 | */ |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 384 | void check_notify_stopping(struct check *check) |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 385 | { |
Simon Horman | 4a74143 | 2013-02-23 15:35:38 +0900 | [diff] [blame] | 386 | struct server *s = check->server; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 387 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 388 | if (s->next_admin & SRV_ADMF_MAINT) |
Willy Tarreau | af54958 | 2014-05-16 17:37:50 +0200 | [diff] [blame] | 389 | return; |
| 390 | |
Willy Tarreau | db58b79 | 2014-05-21 13:57:23 +0200 | [diff] [blame] | 391 | if (check->state & CHK_ST_AGENT) |
| 392 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 393 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 394 | if (s->track && s->track->next_state == SRV_ST_STOPPED) |
Willy Tarreau | db58b79 | 2014-05-21 13:57:23 +0200 | [diff] [blame] | 395 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 396 | |
Willy Tarreau | db58b79 | 2014-05-21 13:57:23 +0200 | [diff] [blame] | 397 | if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise)) |
| 398 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 399 | |
Willy Tarreau | db58b79 | 2014-05-21 13:57:23 +0200 | [diff] [blame] | 400 | if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise)) |
| 401 | return; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 402 | |
Willy Tarreau | b26881a | 2017-12-23 11:16:49 +0100 | [diff] [blame] | 403 | srv_set_stopping(s, NULL, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check : NULL); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 404 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 405 | |
Willy Tarreau | 9fe7aae | 2013-12-31 23:47:37 +0100 | [diff] [blame] | 406 | /* note: use health_adjust() only, which first checks that the observe mode is |
| 407 | * enabled. |
| 408 | */ |
| 409 | void __health_adjust(struct server *s, short status) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 410 | { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 411 | int failed; |
| 412 | int expire; |
| 413 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 414 | if (s->observe >= HANA_OBS_SIZE) |
| 415 | return; |
| 416 | |
Willy Tarreau | bb95666 | 2013-01-24 00:37:39 +0100 | [diff] [blame] | 417 | if (status >= HANA_STATUS_SIZE || !analyze_statuses[status].desc) |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 418 | return; |
| 419 | |
| 420 | switch (analyze_statuses[status].lr[s->observe - 1]) { |
| 421 | case 1: |
| 422 | failed = 1; |
| 423 | break; |
| 424 | |
| 425 | case 2: |
| 426 | failed = 0; |
| 427 | break; |
| 428 | |
| 429 | default: |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | if (!failed) { |
| 434 | /* good: clear consecutive_errors */ |
| 435 | s->consecutive_errors = 0; |
| 436 | return; |
| 437 | } |
| 438 | |
Olivier Houchard | 7059c55 | 2019-03-08 18:49:32 +0100 | [diff] [blame] | 439 | _HA_ATOMIC_ADD(&s->consecutive_errors, 1); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 440 | |
| 441 | if (s->consecutive_errors < s->consecutive_errors_limit) |
| 442 | return; |
| 443 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 444 | chunk_printf(&trash, "Detected %d consecutive errors, last one was: %s", |
| 445 | s->consecutive_errors, get_analyze_status(status)); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 446 | |
| 447 | switch (s->onerror) { |
| 448 | case HANA_ONERR_FASTINTER: |
| 449 | /* force fastinter - nothing to do here as all modes force it */ |
| 450 | break; |
| 451 | |
| 452 | case HANA_ONERR_SUDDTH: |
| 453 | /* simulate a pre-fatal failed health check */ |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 454 | if (s->check.health > s->check.rise) |
| 455 | s->check.health = s->check.rise + 1; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 456 | |
Tim Duesterhus | 588b314 | 2020-05-29 14:35:51 +0200 | [diff] [blame] | 457 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 458 | |
| 459 | case HANA_ONERR_FAILCHK: |
| 460 | /* simulate a failed health check */ |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 461 | set_server_check_status(&s->check, HCHK_STATUS_HANA, |
| 462 | trash.area); |
Willy Tarreau | 4eec547 | 2014-05-20 22:32:27 +0200 | [diff] [blame] | 463 | check_notify_failure(&s->check); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 464 | break; |
| 465 | |
| 466 | case HANA_ONERR_MARKDWN: |
| 467 | /* mark server down */ |
Simon Horman | 58c3297 | 2013-11-25 10:46:38 +0900 | [diff] [blame] | 468 | s->check.health = s->check.rise; |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 469 | set_server_check_status(&s->check, HCHK_STATUS_HANA, |
| 470 | trash.area); |
Willy Tarreau | 4eec547 | 2014-05-20 22:32:27 +0200 | [diff] [blame] | 471 | check_notify_failure(&s->check); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 472 | break; |
| 473 | |
| 474 | default: |
| 475 | /* write a warning? */ |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | s->consecutive_errors = 0; |
Olivier Houchard | 7059c55 | 2019-03-08 18:49:32 +0100 | [diff] [blame] | 480 | _HA_ATOMIC_ADD(&s->counters.failed_hana, 1); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 481 | |
Simon Horman | 6618300 | 2013-02-23 10:16:43 +0900 | [diff] [blame] | 482 | if (s->check.fastinter) { |
| 483 | expire = tick_add(now_ms, MS_TO_TICKS(s->check.fastinter)); |
Sergiy Prykhodko | 1d57e50 | 2013-09-21 12:05:00 +0300 | [diff] [blame] | 484 | if (s->check.task->expire > expire) { |
Willy Tarreau | 5b3a202 | 2012-09-28 15:01:02 +0200 | [diff] [blame] | 485 | s->check.task->expire = expire; |
Sergiy Prykhodko | 1d57e50 | 2013-09-21 12:05:00 +0300 | [diff] [blame] | 486 | /* requeue check task with new expire */ |
| 487 | task_queue(s->check.task); |
| 488 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 489 | } |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 490 | } |
| 491 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 492 | /* Checks the connection. If an error has already been reported or the socket is |
Willy Tarreau | 20a1834 | 2013-12-05 00:31:46 +0100 | [diff] [blame] | 493 | * closed, keep errno intact as it is supposed to contain the valid error code. |
| 494 | * If no error is reported, check the socket's error queue using getsockopt(). |
| 495 | * Warning, this must be done only once when returning from poll, and never |
| 496 | * after an I/O error was attempted, otherwise the error queue might contain |
| 497 | * inconsistent errors. If an error is detected, the CO_FL_ERROR is set on the |
| 498 | * socket. Returns non-zero if an error was reported, zero if everything is |
| 499 | * clean (including a properly closed socket). |
| 500 | */ |
| 501 | static int retrieve_errno_from_socket(struct connection *conn) |
| 502 | { |
| 503 | int skerr; |
| 504 | socklen_t lskerr = sizeof(skerr); |
| 505 | |
Willy Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 506 | if (conn->flags & CO_FL_ERROR && (unclean_errno(errno) || !conn->ctrl)) |
Willy Tarreau | 20a1834 | 2013-12-05 00:31:46 +0100 | [diff] [blame] | 507 | return 1; |
| 508 | |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 509 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 20a1834 | 2013-12-05 00:31:46 +0100 | [diff] [blame] | 510 | return 0; |
| 511 | |
Willy Tarreau | 585744b | 2017-08-24 14:31:19 +0200 | [diff] [blame] | 512 | if (getsockopt(conn->handle.fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == 0) |
Willy Tarreau | 20a1834 | 2013-12-05 00:31:46 +0100 | [diff] [blame] | 513 | errno = skerr; |
| 514 | |
Willy Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 515 | errno = unclean_errno(errno); |
Willy Tarreau | 20a1834 | 2013-12-05 00:31:46 +0100 | [diff] [blame] | 516 | |
| 517 | if (!errno) { |
| 518 | /* we could not retrieve an error, that does not mean there is |
| 519 | * none. Just don't change anything and only report the prior |
| 520 | * error if any. |
| 521 | */ |
| 522 | if (conn->flags & CO_FL_ERROR) |
| 523 | return 1; |
| 524 | else |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | conn->flags |= CO_FL_ERROR | CO_FL_SOCK_WR_SH | CO_FL_SOCK_RD_SH; |
| 529 | return 1; |
| 530 | } |
| 531 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 532 | /* Tries to collect as much information as possible on the connection status, |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 533 | * and adjust the server status accordingly. It may make use of <errno_bck> |
| 534 | * if non-null when the caller is absolutely certain of its validity (eg: |
| 535 | * checked just after a syscall). If the caller doesn't have a valid errno, |
| 536 | * it can pass zero, and retrieve_errno_from_socket() will be called to try |
| 537 | * to extract errno from the socket. If no error is reported, it will consider |
| 538 | * the <expired> flag. This is intended to be used when a connection error was |
| 539 | * reported in conn->flags or when a timeout was reported in <expired>. The |
| 540 | * function takes care of not updating a server status which was already set. |
| 541 | * All situations where at least one of <expired> or CO_FL_ERROR are set |
| 542 | * produce a status. |
| 543 | */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 544 | void chk_report_conn_err(struct check *check, int errno_bck, int expired) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 545 | { |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 546 | struct conn_stream *cs = check->cs; |
| 547 | struct connection *conn = cs_conn(cs); |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 548 | const char *err_msg; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 549 | struct buffer *chk; |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 550 | int step; |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 551 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 552 | if (check->result != CHK_RES_UNKNOWN) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 553 | return; |
| 554 | |
Willy Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 555 | errno = unclean_errno(errno_bck); |
| 556 | if (conn && errno) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 557 | retrieve_errno_from_socket(conn); |
| 558 | |
Willy Tarreau | 4ff3b89 | 2017-10-16 15:17:17 +0200 | [diff] [blame] | 559 | if (conn && !(conn->flags & CO_FL_ERROR) && |
| 560 | !(cs->flags & CS_FL_ERROR) && !expired) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 561 | return; |
| 562 | |
| 563 | /* we'll try to build a meaningful error message depending on the |
| 564 | * context of the error possibly present in conn->err_code, and the |
| 565 | * socket error possibly collected above. This is useful to know the |
| 566 | * exact step of the L6 layer (eg: SSL handshake). |
| 567 | */ |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 568 | chk = get_trash_chunk(); |
| 569 | |
Christopher Faulet | 799f3a4 | 2020-04-07 12:06:14 +0200 | [diff] [blame] | 570 | if (check->type == PR_O2_TCPCHK_CHK && |
Christopher Faulet | d7e6396 | 2020-04-17 20:15:59 +0200 | [diff] [blame] | 571 | (check->tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK) == TCPCHK_RULES_TCP_CHK) { |
Christopher Faulet | b2c2e0f | 2020-03-30 11:05:10 +0200 | [diff] [blame] | 572 | step = tcpcheck_get_step_id(check, NULL); |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 573 | if (!step) |
| 574 | chunk_printf(chk, " at initial connection step of tcp-check"); |
| 575 | else { |
| 576 | chunk_printf(chk, " at step %d of tcp-check", step); |
| 577 | /* we were looking for a string */ |
Christopher Faulet | b2c2e0f | 2020-03-30 11:05:10 +0200 | [diff] [blame] | 578 | if (check->current_step && check->current_step->action == TCPCHK_ACT_CONNECT) { |
| 579 | if (check->current_step->connect.port) |
| 580 | chunk_appendf(chk, " (connect port %d)" ,check->current_step->connect.port); |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 581 | else |
| 582 | chunk_appendf(chk, " (connect)"); |
| 583 | } |
Christopher Faulet | b2c2e0f | 2020-03-30 11:05:10 +0200 | [diff] [blame] | 584 | else if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT) { |
| 585 | struct tcpcheck_expect *expect = &check->current_step->expect; |
Gaetan Rivet | b616add | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 586 | |
| 587 | switch (expect->type) { |
| 588 | case TCPCHK_EXPECT_STRING: |
Christopher Faulet | b61caf4 | 2020-04-21 10:57:42 +0200 | [diff] [blame] | 589 | chunk_appendf(chk, " (expect string '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data)); |
Gaetan Rivet | b616add | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 590 | break; |
| 591 | case TCPCHK_EXPECT_BINARY: |
Christopher Faulet | b61caf4 | 2020-04-21 10:57:42 +0200 | [diff] [blame] | 592 | chunk_appendf(chk, " (expect binary '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data)); |
Gaetan Rivet | b616add | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 593 | break; |
Christopher Faulet | 67a2345 | 2020-05-05 18:10:01 +0200 | [diff] [blame] | 594 | case TCPCHK_EXPECT_STRING_REGEX: |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 595 | chunk_appendf(chk, " (expect regex)"); |
Gaetan Rivet | b616add | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 596 | break; |
Christopher Faulet | 67a2345 | 2020-05-05 18:10:01 +0200 | [diff] [blame] | 597 | case TCPCHK_EXPECT_BINARY_REGEX: |
Gaetan Rivet | efab6c6 | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 598 | chunk_appendf(chk, " (expect binary regex)"); |
| 599 | break; |
Christopher Faulet | aaab083 | 2020-05-05 15:54:22 +0200 | [diff] [blame] | 600 | case TCPCHK_EXPECT_STRING_LF: |
| 601 | chunk_appendf(chk, " (expect log-format string)"); |
| 602 | break; |
| 603 | case TCPCHK_EXPECT_BINARY_LF: |
| 604 | chunk_appendf(chk, " (expect log-format binary)"); |
| 605 | break; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 606 | case TCPCHK_EXPECT_HTTP_STATUS: |
Christopher Faulet | 8021a5f | 2020-04-24 13:53:12 +0200 | [diff] [blame] | 607 | chunk_appendf(chk, " (expect HTTP status codes)"); |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 608 | break; |
Christopher Faulet | 67a2345 | 2020-05-05 18:10:01 +0200 | [diff] [blame] | 609 | case TCPCHK_EXPECT_HTTP_STATUS_REGEX: |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 610 | chunk_appendf(chk, " (expect HTTP status regex)"); |
| 611 | break; |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 612 | case TCPCHK_EXPECT_HTTP_HEADER: |
| 613 | chunk_appendf(chk, " (expect HTTP header pattern)"); |
| 614 | break; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 615 | case TCPCHK_EXPECT_HTTP_BODY: |
Christopher Faulet | b61caf4 | 2020-04-21 10:57:42 +0200 | [diff] [blame] | 616 | chunk_appendf(chk, " (expect HTTP body content '%.*s')", (unsigned int)istlen(expect->data), istptr(expect->data)); |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 617 | break; |
Christopher Faulet | 67a2345 | 2020-05-05 18:10:01 +0200 | [diff] [blame] | 618 | case TCPCHK_EXPECT_HTTP_BODY_REGEX: |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 619 | chunk_appendf(chk, " (expect HTTP body regex)"); |
| 620 | break; |
Christopher Faulet | aaab083 | 2020-05-05 15:54:22 +0200 | [diff] [blame] | 621 | case TCPCHK_EXPECT_HTTP_BODY_LF: |
| 622 | chunk_appendf(chk, " (expect log-format HTTP body)"); |
| 623 | break; |
Christopher Faulet | 9e6ed15 | 2020-04-03 15:24:06 +0200 | [diff] [blame] | 624 | case TCPCHK_EXPECT_CUSTOM: |
| 625 | chunk_appendf(chk, " (expect custom function)"); |
| 626 | break; |
Gaetan Rivet | b616add | 2020-02-07 15:37:17 +0100 | [diff] [blame] | 627 | case TCPCHK_EXPECT_UNDEF: |
| 628 | chunk_appendf(chk, " (undefined expect!)"); |
| 629 | break; |
| 630 | } |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 631 | } |
Christopher Faulet | b2c2e0f | 2020-03-30 11:05:10 +0200 | [diff] [blame] | 632 | else if (check->current_step && check->current_step->action == TCPCHK_ACT_SEND) { |
Willy Tarreau | 213c678 | 2014-10-02 14:51:02 +0200 | [diff] [blame] | 633 | chunk_appendf(chk, " (send)"); |
| 634 | } |
Baptiste Assmann | 22b09d2 | 2015-05-01 08:03:04 +0200 | [diff] [blame] | 635 | |
Christopher Faulet | 6f2a5e4 | 2020-04-01 13:11:41 +0200 | [diff] [blame] | 636 | if (check->current_step && check->current_step->comment) |
| 637 | chunk_appendf(chk, " comment: '%s'", check->current_step->comment); |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Willy Tarreau | 0014912 | 2017-10-04 18:05:01 +0200 | [diff] [blame] | 641 | if (conn && conn->err_code) { |
Willy Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 642 | if (unclean_errno(errno)) |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 643 | chunk_printf(&trash, "%s (%s)%s", conn_err_code_str(conn), strerror(errno), |
| 644 | chk->area); |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 645 | else |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 646 | chunk_printf(&trash, "%s%s", conn_err_code_str(conn), |
| 647 | chk->area); |
| 648 | err_msg = trash.area; |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 649 | } |
| 650 | else { |
Willy Tarreau | c8dc20a | 2019-12-27 12:03:27 +0100 | [diff] [blame] | 651 | if (unclean_errno(errno)) { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 652 | chunk_printf(&trash, "%s%s", strerror(errno), |
| 653 | chk->area); |
| 654 | err_msg = trash.area; |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 655 | } |
| 656 | else { |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 657 | err_msg = chk->area; |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Willy Tarreau | 0014912 | 2017-10-04 18:05:01 +0200 | [diff] [blame] | 661 | if (check->state & CHK_ST_PORT_MISS) { |
Baptiste Assmann | 95db2bc | 2016-06-13 14:15:41 +0200 | [diff] [blame] | 662 | /* NOTE: this is reported after <fall> tries */ |
| 663 | chunk_printf(chk, "No port available for the TCP connection"); |
| 664 | set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg); |
| 665 | } |
| 666 | |
Christopher Faulet | 5e29376 | 2020-10-26 11:10:49 +0100 | [diff] [blame] | 667 | if (!conn || !conn->ctrl) { |
| 668 | /* error before any connection attempt (connection allocation error or no control layer) */ |
Willy Tarreau | 0014912 | 2017-10-04 18:05:01 +0200 | [diff] [blame] | 669 | set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg); |
| 670 | } |
Willy Tarreau | c192b0a | 2020-01-23 09:11:58 +0100 | [diff] [blame] | 671 | else if (conn->flags & CO_FL_WAIT_L4_CONN) { |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 672 | /* L4 not established (yet) */ |
Willy Tarreau | 4ff3b89 | 2017-10-16 15:17:17 +0200 | [diff] [blame] | 673 | if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 674 | set_server_check_status(check, HCHK_STATUS_L4CON, err_msg); |
| 675 | else if (expired) |
| 676 | set_server_check_status(check, HCHK_STATUS_L4TOUT, err_msg); |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 677 | |
| 678 | /* |
| 679 | * might be due to a server IP change. |
| 680 | * Let's trigger a DNS resolution if none are currently running. |
| 681 | */ |
Olivier Houchard | 0923fa4 | 2019-01-11 18:43:04 +0100 | [diff] [blame] | 682 | if (check->server) |
Emeric Brun | d30e9a1 | 2020-12-23 18:49:16 +0100 | [diff] [blame] | 683 | resolv_trigger_resolution(check->server->resolv_requester); |
Baptiste Assmann | a68ca96 | 2015-04-14 01:15:08 +0200 | [diff] [blame] | 684 | |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 685 | } |
Willy Tarreau | c192b0a | 2020-01-23 09:11:58 +0100 | [diff] [blame] | 686 | else if (conn->flags & CO_FL_WAIT_L6_CONN) { |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 687 | /* L6 not established (yet) */ |
Willy Tarreau | 4ff3b89 | 2017-10-16 15:17:17 +0200 | [diff] [blame] | 688 | if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 689 | set_server_check_status(check, HCHK_STATUS_L6RSP, err_msg); |
| 690 | else if (expired) |
| 691 | set_server_check_status(check, HCHK_STATUS_L6TOUT, err_msg); |
| 692 | } |
Willy Tarreau | 4ff3b89 | 2017-10-16 15:17:17 +0200 | [diff] [blame] | 693 | else if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) { |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 694 | /* I/O error after connection was established and before we could diagnose */ |
| 695 | set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg); |
| 696 | } |
| 697 | else if (expired) { |
Christopher Faulet | cf80f2f | 2020-04-01 11:04:52 +0200 | [diff] [blame] | 698 | enum healthcheck_status tout = HCHK_STATUS_L7TOUT; |
| 699 | |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 700 | /* connection established but expired check */ |
Christopher Faulet | 1941bab | 2020-05-05 07:55:50 +0200 | [diff] [blame] | 701 | if (check->current_step && check->current_step->action == TCPCHK_ACT_EXPECT && |
| 702 | check->current_step->expect.tout_status != HCHK_STATUS_UNKNOWN) |
Christopher Faulet | 811f78c | 2020-04-01 11:10:27 +0200 | [diff] [blame] | 703 | tout = check->current_step->expect.tout_status; |
| 704 | set_server_check_status(check, tout, err_msg); |
Willy Tarreau | 25e2ab5 | 2013-12-04 11:17:05 +0100 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | return; |
| 708 | } |
| 709 | |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 710 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 711 | /* Builds the server state header used by HTTP health-checks */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 712 | int httpchk_build_status_header(struct server *s, struct buffer *buf) |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 713 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 714 | int sv_state; |
| 715 | int ratio; |
| 716 | char addr[46]; |
| 717 | char port[6]; |
| 718 | const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d", |
| 719 | "UP %d/%d", "UP", |
| 720 | "NOLB %d/%d", "NOLB", |
| 721 | "no check" }; |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 722 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 723 | if (!(s->check.state & CHK_ST_ENABLED)) |
| 724 | sv_state = 6; |
| 725 | else if (s->cur_state != SRV_ST_STOPPED) { |
| 726 | if (s->check.health == s->check.rise + s->check.fall - 1) |
| 727 | sv_state = 3; /* UP */ |
| 728 | else |
| 729 | sv_state = 2; /* going down */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 730 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 731 | if (s->cur_state == SRV_ST_STOPPING) |
| 732 | sv_state += 2; |
| 733 | } else { |
| 734 | if (s->check.health) |
| 735 | sv_state = 1; /* going up */ |
| 736 | else |
| 737 | sv_state = 0; /* DOWN */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 738 | } |
Willy Tarreau | b7b2478 | 2016-06-21 15:32:29 +0200 | [diff] [blame] | 739 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 740 | chunk_appendf(buf, srv_hlt_st[sv_state], |
| 741 | (s->cur_state != SRV_ST_STOPPED) ? (s->check.health - s->check.rise + 1) : (s->check.health), |
| 742 | (s->cur_state != SRV_ST_STOPPED) ? (s->check.fall) : (s->check.rise)); |
Willy Tarreau | b7b2478 | 2016-06-21 15:32:29 +0200 | [diff] [blame] | 743 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 744 | addr_to_str(&s->addr, addr, sizeof(addr)); |
| 745 | if (s->addr.ss_family == AF_INET || s->addr.ss_family == AF_INET6) |
| 746 | snprintf(port, sizeof(port), "%u", s->svc_port); |
| 747 | else |
| 748 | *port = 0; |
Willy Tarreau | b7b2478 | 2016-06-21 15:32:29 +0200 | [diff] [blame] | 749 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 750 | chunk_appendf(buf, "; address=%s; port=%s; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d", |
| 751 | addr, port, s->proxy->id, s->id, |
| 752 | global.node, |
| 753 | (s->cur_eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 754 | (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 755 | s->cur_sess, s->proxy->beconn - s->proxy->nbpend, |
| 756 | s->nbpend); |
Willy Tarreau | 9f6dc72 | 2019-03-01 11:15:10 +0100 | [diff] [blame] | 757 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 758 | if ((s->cur_state == SRV_ST_STARTING) && |
| 759 | now.tv_sec < s->last_change + s->slowstart && |
| 760 | now.tv_sec >= s->last_change) { |
| 761 | ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart); |
| 762 | chunk_appendf(buf, "; throttle=%d%%", ratio); |
| 763 | } |
Christopher Faulet | aaae9a0 | 2020-04-26 09:50:31 +0200 | [diff] [blame] | 764 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 765 | return b_data(buf); |
| 766 | } |
Christopher Faulet | aaae9a0 | 2020-04-26 09:50:31 +0200 | [diff] [blame] | 767 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 768 | /**************************************************************************/ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 769 | /***************** Health-checks based on connections *********************/ |
| 770 | /**************************************************************************/ |
| 771 | /* This function is used only for server health-checks. It handles connection |
| 772 | * status updates including errors. If necessary, it wakes the check task up. |
| 773 | * It returns 0 on normal cases, <0 if at least one close() has happened on the |
| 774 | * connection (eg: reconnect). It relies on tcpcheck_main(). |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 775 | */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 776 | static int wake_srv_chk(struct conn_stream *cs) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 777 | { |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 778 | struct connection *conn = cs->conn; |
| 779 | struct check *check = cs->data; |
| 780 | struct email_alertq *q = container_of(check, typeof(*q), check); |
| 781 | int ret = 0; |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 782 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 783 | if (check->server) |
| 784 | HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock); |
| 785 | else |
| 786 | HA_SPIN_LOCK(EMAIL_ALERTS_LOCK, &q->lock); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 787 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 788 | /* we may have to make progress on the TCP checks */ |
| 789 | ret = tcpcheck_main(check); |
Christopher Faulet | aaab083 | 2020-05-05 15:54:22 +0200 | [diff] [blame] | 790 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 791 | cs = check->cs; |
| 792 | conn = cs->conn; |
Christopher Faulet | aaab083 | 2020-05-05 15:54:22 +0200 | [diff] [blame] | 793 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 794 | if (unlikely(conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)) { |
| 795 | /* We may get error reports bypassing the I/O handlers, typically |
| 796 | * the case when sending a pure TCP check which fails, then the I/O |
| 797 | * handlers above are not called. This is completely handled by the |
| 798 | * main processing task so let's simply wake it up. If we get here, |
| 799 | * we expect errno to still be valid. |
| 800 | */ |
| 801 | chk_report_conn_err(check, errno, 0); |
| 802 | task_wakeup(check->task, TASK_WOKEN_IO); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 803 | } |
| 804 | |
Christopher Faulet | 8f10042 | 2021-01-18 15:47:03 +0100 | [diff] [blame] | 805 | if (check->result != CHK_RES_UNKNOWN || ret == -1) { |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 806 | /* Check complete or aborted. If connection not yet closed do it |
| 807 | * now and wake the check task up to be sure the result is |
| 808 | * handled ASAP. */ |
Willy Tarreau | 30bd4ef | 2020-12-11 11:09:29 +0100 | [diff] [blame] | 809 | cs_drain_and_close(cs); |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 810 | ret = -1; |
Christopher Faulet | 8f10042 | 2021-01-18 15:47:03 +0100 | [diff] [blame] | 811 | |
| 812 | if (check->wait_list.events) |
| 813 | cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list); |
| 814 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 815 | /* We may have been scheduled to run, and the |
| 816 | * I/O handler expects to have a cs, so remove |
| 817 | * the tasklet |
| 818 | */ |
| 819 | tasklet_remove_from_tasklet_list(check->wait_list.tasklet); |
| 820 | task_wakeup(check->task, TASK_WOKEN_IO); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 821 | } |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 822 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 823 | if (check->server) |
| 824 | HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock); |
| 825 | else |
| 826 | HA_SPIN_UNLOCK(EMAIL_ALERTS_LOCK, &q->lock); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 827 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 828 | return ret; |
| 829 | } |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 830 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 831 | /* This function checks if any I/O is wanted, and if so, attempts to do so */ |
Willy Tarreau | 025fc71 | 2021-01-29 12:35:24 +0100 | [diff] [blame] | 832 | struct task *event_srv_chk_io(struct task *t, void *ctx, unsigned short state) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 833 | { |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 834 | struct check *check = ctx; |
| 835 | struct conn_stream *cs = check->cs; |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 836 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 837 | wake_srv_chk(cs); |
| 838 | return NULL; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 839 | } |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 840 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 841 | /* manages a server health-check that uses a connection. Returns |
| 842 | * the time the task accepts to wait, or TIME_ETERNITY for infinity. |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 843 | * |
| 844 | * Please do NOT place any return statement in this function and only leave |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 845 | * via the out_unlock label. |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 846 | */ |
Willy Tarreau | 025fc71 | 2021-01-29 12:35:24 +0100 | [diff] [blame] | 847 | struct task *process_chk_conn(struct task *t, void *context, unsigned short state) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 848 | { |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 849 | struct check *check = context; |
| 850 | struct proxy *proxy = check->proxy; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 851 | struct conn_stream *cs = check->cs; |
| 852 | struct connection *conn = cs_conn(cs); |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 853 | int rv; |
| 854 | int expired = tick_is_expired(t->expire, now_ms); |
Willy Tarreau | deccd11 | 2018-06-14 18:38:55 +0200 | [diff] [blame] | 855 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 856 | if (check->server) |
| 857 | HA_SPIN_LOCK(SERVER_LOCK, &check->server->lock); |
| 858 | if (!(check->state & CHK_ST_INPROGRESS)) { |
| 859 | /* no check currently running */ |
| 860 | if (!expired) /* woke up too early */ |
| 861 | goto out_unlock; |
Willy Tarreau | abca5b6 | 2013-12-06 14:19:25 +0100 | [diff] [blame] | 862 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 863 | /* we don't send any health-checks when the proxy is |
| 864 | * stopped, the server should not be checked or the check |
| 865 | * is disabled. |
| 866 | */ |
| 867 | if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) || |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 868 | proxy->disabled) |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 869 | goto reschedule; |
Christopher Faulet | 404f919 | 2020-04-09 23:13:54 +0200 | [diff] [blame] | 870 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 871 | /* we'll initiate a new check */ |
| 872 | set_server_check_status(check, HCHK_STATUS_START, NULL); |
Christopher Faulet | 404f919 | 2020-04-09 23:13:54 +0200 | [diff] [blame] | 873 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 874 | check->state |= CHK_ST_INPROGRESS; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 875 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 876 | task_set_affinity(t, tid_bit); |
| 877 | |
| 878 | check->current_step = NULL; |
| 879 | tcpcheck_main(check); |
| 880 | goto out_unlock; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 881 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 882 | else { |
| 883 | /* there was a test running. |
| 884 | * First, let's check whether there was an uncaught error, |
| 885 | * which can happen on connect timeout or error. |
| 886 | */ |
| 887 | if (check->result == CHK_RES_UNKNOWN) { |
Christopher Faulet | b1bb069 | 2020-11-25 16:47:30 +0100 | [diff] [blame] | 888 | /* Here the connection must be defined. Otherwise the |
| 889 | * error would have already been detected |
| 890 | */ |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 891 | if ((conn->flags & CO_FL_ERROR) || cs->flags & CS_FL_ERROR || expired) { |
| 892 | chk_report_conn_err(check, 0, expired); |
| 893 | } |
Christopher Faulet | 8f10042 | 2021-01-18 15:47:03 +0100 | [diff] [blame] | 894 | else { |
| 895 | if (check->state & CHK_ST_CLOSE_CONN) { |
| 896 | cs_destroy(cs); |
| 897 | cs = NULL; |
| 898 | conn = NULL; |
| 899 | check->cs = NULL; |
| 900 | check->state &= ~CHK_ST_CLOSE_CONN; |
| 901 | tcpcheck_main(check); |
| 902 | } |
| 903 | if (check->result == CHK_RES_UNKNOWN) |
| 904 | goto out_unlock; /* timeout not reached, wait again */ |
| 905 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 906 | } |
Christopher Faulet | 404f919 | 2020-04-09 23:13:54 +0200 | [diff] [blame] | 907 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 908 | /* check complete or aborted */ |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 909 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 910 | check->current_step = NULL; |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 911 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 912 | if (conn && conn->xprt) { |
| 913 | /* The check was aborted and the connection was not yet closed. |
| 914 | * This can happen upon timeout, or when an external event such |
| 915 | * as a failed response coupled with "observe layer7" caused the |
| 916 | * server state to be suddenly changed. |
| 917 | */ |
Willy Tarreau | 30bd4ef | 2020-12-11 11:09:29 +0100 | [diff] [blame] | 918 | cs_drain_and_close(cs); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 919 | } |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 920 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 921 | if (cs) { |
| 922 | if (check->wait_list.events) |
| 923 | cs->conn->mux->unsubscribe(cs, check->wait_list.events, &check->wait_list); |
| 924 | /* We may have been scheduled to run, and the |
| 925 | * I/O handler expects to have a cs, so remove |
| 926 | * the tasklet |
| 927 | */ |
| 928 | tasklet_remove_from_tasklet_list(check->wait_list.tasklet); |
| 929 | cs_destroy(cs); |
| 930 | cs = check->cs = NULL; |
| 931 | conn = NULL; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 932 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 933 | |
| 934 | if (check->sess != NULL) { |
| 935 | vars_prune(&check->vars, check->sess, NULL); |
| 936 | session_free(check->sess); |
| 937 | check->sess = NULL; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 938 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 939 | |
| 940 | if (check->server) { |
| 941 | if (check->result == CHK_RES_FAILED) { |
| 942 | /* a failure or timeout detected */ |
| 943 | check_notify_failure(check); |
| 944 | } |
| 945 | else if (check->result == CHK_RES_CONDPASS) { |
| 946 | /* check is OK but asks for stopping mode */ |
| 947 | check_notify_stopping(check); |
| 948 | } |
| 949 | else if (check->result == CHK_RES_PASSED) { |
| 950 | /* a success was detected */ |
| 951 | check_notify_success(check); |
| 952 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 953 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 954 | task_set_affinity(t, MAX_THREADS_MASK); |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 955 | check_release_buf(check, &check->bi); |
| 956 | check_release_buf(check, &check->bo); |
| 957 | check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC); |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 958 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 959 | if (check->server) { |
| 960 | rv = 0; |
| 961 | if (global.spread_checks > 0) { |
| 962 | rv = srv_getinter(check) * global.spread_checks / 100; |
| 963 | rv -= (int) (2 * rv * (ha_random32() / 4294967295.0)); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 964 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 965 | t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(check) + rv)); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 966 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 967 | } |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 968 | |
| 969 | reschedule: |
| 970 | while (tick_is_expired(t->expire, now_ms)) |
| 971 | t->expire = tick_add(t->expire, MS_TO_TICKS(check->inter)); |
| 972 | out_unlock: |
| 973 | if (check->server) |
| 974 | HA_SPIN_UNLOCK(SERVER_LOCK, &check->server->lock); |
| 975 | return t; |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 976 | } |
| 977 | |
Willy Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame] | 978 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 979 | /**************************************************************************/ |
| 980 | /************************** Init/deinit checks ****************************/ |
| 981 | /**************************************************************************/ |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 982 | /* |
| 983 | * Tries to grab a buffer and to re-enables processing on check <target>. The |
| 984 | * check flags are used to figure what buffer was requested. It returns 1 if the |
| 985 | * allocation succeeds, in which case the I/O tasklet is woken up, or 0 if it's |
| 986 | * impossible to wake up and we prefer to be woken up later. |
| 987 | */ |
| 988 | int check_buf_available(void *target) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 989 | { |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 990 | struct check *check = target; |
| 991 | |
| 992 | if ((check->state & CHK_ST_IN_ALLOC) && b_alloc_margin(&check->bi, 0)) { |
| 993 | check->state &= ~CHK_ST_IN_ALLOC; |
| 994 | tasklet_wakeup(check->wait_list.tasklet); |
| 995 | return 1; |
| 996 | } |
| 997 | if ((check->state & CHK_ST_OUT_ALLOC) && b_alloc_margin(&check->bo, 0)) { |
| 998 | check->state &= ~CHK_ST_OUT_ALLOC; |
| 999 | tasklet_wakeup(check->wait_list.tasklet); |
| 1000 | return 1; |
| 1001 | } |
| 1002 | |
| 1003 | return 0; |
| 1004 | } |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 1005 | |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 1006 | /* |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 1007 | * Allocate a buffer. If it fails, it adds the check in buffer wait queue. |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 1008 | */ |
| 1009 | struct buffer *check_get_buf(struct check *check, struct buffer *bptr) |
| 1010 | { |
| 1011 | struct buffer *buf = NULL; |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 1012 | |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 1013 | if (likely(!MT_LIST_ADDED(&check->buf_wait.list)) && |
| 1014 | unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) { |
| 1015 | check->buf_wait.target = check; |
| 1016 | check->buf_wait.wakeup_cb = check_buf_available; |
| 1017 | MT_LIST_ADDQ(&buffer_wq, &check->buf_wait.list); |
| 1018 | } |
| 1019 | return buf; |
| 1020 | } |
| 1021 | |
| 1022 | /* |
| 1023 | * Release a buffer, if any, and try to wake up entities waiting in the buffer |
| 1024 | * wait queue. |
| 1025 | */ |
| 1026 | void check_release_buf(struct check *check, struct buffer *bptr) |
| 1027 | { |
| 1028 | if (bptr->size) { |
| 1029 | b_free(bptr); |
| 1030 | offer_buffers(check->buf_wait.target, tasks_run_queue); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | const char *init_check(struct check *check, int type) |
| 1035 | { |
| 1036 | check->type = type; |
Christopher Faulet | ba3c68f | 2020-04-01 16:27:05 +0200 | [diff] [blame] | 1037 | |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 1038 | check->bi = BUF_NULL; |
| 1039 | check->bo = BUF_NULL; |
| 1040 | MT_LIST_INIT(&check->buf_wait.list); |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1041 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1042 | check->wait_list.tasklet = tasklet_new(); |
| 1043 | if (!check->wait_list.tasklet) |
| 1044 | return "out of memory while allocating check tasklet"; |
| 1045 | check->wait_list.events = 0; |
| 1046 | check->wait_list.tasklet->process = event_srv_chk_io; |
| 1047 | check->wait_list.tasklet->context = check; |
| 1048 | return NULL; |
| 1049 | } |
| 1050 | |
| 1051 | void free_check(struct check *check) |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1052 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1053 | task_destroy(check->task); |
| 1054 | if (check->wait_list.tasklet) |
| 1055 | tasklet_free(check->wait_list.tasklet); |
| 1056 | |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 1057 | check_release_buf(check, &check->bi); |
| 1058 | check_release_buf(check, &check->bo); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1059 | if (check->cs) { |
| 1060 | free(check->cs->conn); |
| 1061 | check->cs->conn = NULL; |
| 1062 | cs_free(check->cs); |
| 1063 | check->cs = NULL; |
| 1064 | } |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1065 | } |
| 1066 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1067 | /* manages a server health-check. Returns the time the task accepts to wait, or |
| 1068 | * TIME_ETERNITY for infinity. |
| 1069 | */ |
Willy Tarreau | cee013e | 2020-06-05 11:40:38 +0200 | [diff] [blame] | 1070 | struct task *process_chk(struct task *t, void *context, unsigned short state) |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1071 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1072 | struct check *check = context; |
| 1073 | |
| 1074 | if (check->type == PR_O2_EXT_CHK) |
| 1075 | return process_chk_proc(t, context, state); |
| 1076 | return process_chk_conn(t, context, state); |
| 1077 | |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1080 | |
| 1081 | static int start_check_task(struct check *check, int mininter, |
| 1082 | int nbcheck, int srvpos) |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1083 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1084 | struct task *t; |
| 1085 | unsigned long thread_mask = MAX_THREADS_MASK; |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1086 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1087 | if (check->type == PR_O2_EXT_CHK) |
| 1088 | thread_mask = 1; |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1089 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1090 | /* task for the check */ |
| 1091 | if ((t = task_new(thread_mask)) == NULL) { |
| 1092 | ha_alert("Starting [%s:%s] check: out of memory.\n", |
| 1093 | check->server->proxy->id, check->server->id); |
| 1094 | return 0; |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1095 | } |
| 1096 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1097 | check->task = t; |
| 1098 | t->process = process_chk; |
| 1099 | t->context = check; |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1100 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1101 | if (mininter < srv_getinter(check)) |
| 1102 | mininter = srv_getinter(check); |
| 1103 | |
| 1104 | if (global.max_spread_checks && mininter > global.max_spread_checks) |
| 1105 | mininter = global.max_spread_checks; |
| 1106 | |
| 1107 | /* check this every ms */ |
| 1108 | t->expire = tick_add(now_ms, MS_TO_TICKS(mininter * srvpos / nbcheck)); |
| 1109 | check->start = now; |
| 1110 | task_queue(t); |
| 1111 | |
| 1112 | return 1; |
Gaetan Rivet | 707b52f | 2020-02-21 18:14:59 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1115 | /* updates the server's weight during a warmup stage. Once the final weight is |
| 1116 | * reached, the task automatically stops. Note that any server status change |
| 1117 | * must have updated s->last_change accordingly. |
| 1118 | */ |
Willy Tarreau | 025fc71 | 2021-01-29 12:35:24 +0100 | [diff] [blame] | 1119 | struct task *server_warmup(struct task *t, void *context, unsigned short state) |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1120 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1121 | struct server *s = context; |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1122 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1123 | /* by default, plan on stopping the task */ |
| 1124 | t->expire = TICK_ETERNITY; |
| 1125 | if ((s->next_admin & SRV_ADMF_MAINT) || |
| 1126 | (s->next_state != SRV_ST_STARTING)) |
| 1127 | return t; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1128 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1129 | HA_SPIN_LOCK(SERVER_LOCK, &s->lock); |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1130 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1131 | /* recalculate the weights and update the state */ |
| 1132 | server_recalc_eweight(s, 1); |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1133 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1134 | /* probably that we can refill this server with a bit more connections */ |
| 1135 | pendconn_grab_from_px(s); |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1136 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1137 | HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock); |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1138 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1139 | /* get back there in 1 second or 1/20th of the slowstart interval, |
| 1140 | * whichever is greater, resulting in small 5% steps. |
| 1141 | */ |
| 1142 | if (s->next_state == SRV_ST_STARTING) |
| 1143 | t->expire = tick_add(now_ms, MS_TO_TICKS(MAX(1000, s->slowstart / 20))); |
| 1144 | return t; |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | * Start health-check. |
| 1149 | * Returns 0 if OK, ERR_FATAL on error, and prints the error in this case. |
| 1150 | */ |
| 1151 | static int start_checks() |
| 1152 | { |
| 1153 | |
| 1154 | struct proxy *px; |
| 1155 | struct server *s; |
| 1156 | struct task *t; |
| 1157 | int nbcheck=0, mininter=0, srvpos=0; |
| 1158 | |
| 1159 | /* 0- init the dummy frontend used to create all checks sessions */ |
| 1160 | init_new_proxy(&checks_fe); |
| 1161 | checks_fe.cap = PR_CAP_FE | PR_CAP_BE; |
| 1162 | checks_fe.mode = PR_MODE_TCP; |
| 1163 | checks_fe.maxconn = 0; |
| 1164 | checks_fe.conn_retries = CONN_RETRIES; |
| 1165 | checks_fe.options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; |
| 1166 | checks_fe.timeout.client = TICK_ETERNITY; |
| 1167 | |
| 1168 | /* 1- count the checkers to run simultaneously. |
| 1169 | * We also determine the minimum interval among all of those which |
| 1170 | * have an interval larger than SRV_CHK_INTER_THRES. This interval |
| 1171 | * will be used to spread their start-up date. Those which have |
| 1172 | * a shorter interval will start independently and will not dictate |
| 1173 | * too short an interval for all others. |
| 1174 | */ |
| 1175 | for (px = proxies_list; px; px = px->next) { |
| 1176 | for (s = px->srv; s; s = s->next) { |
| 1177 | if (s->slowstart) { |
| 1178 | if ((t = task_new(MAX_THREADS_MASK)) == NULL) { |
| 1179 | ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); |
| 1180 | return ERR_ALERT | ERR_FATAL; |
| 1181 | } |
| 1182 | /* We need a warmup task that will be called when the server |
| 1183 | * state switches from down to up. |
| 1184 | */ |
| 1185 | s->warmup = t; |
| 1186 | t->process = server_warmup; |
| 1187 | t->context = s; |
| 1188 | /* server can be in this state only because of */ |
| 1189 | if (s->next_state == SRV_ST_STARTING) |
| 1190 | task_schedule(s->warmup, tick_add(now_ms, MS_TO_TICKS(MAX(1000, (now.tv_sec - s->last_change)) / 20))); |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1191 | } |
| 1192 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1193 | if (s->check.state & CHK_ST_CONFIGURED) { |
| 1194 | nbcheck++; |
| 1195 | if ((srv_getinter(&s->check) >= SRV_CHK_INTER_THRES) && |
| 1196 | (!mininter || mininter > srv_getinter(&s->check))) |
| 1197 | mininter = srv_getinter(&s->check); |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1200 | if (s->agent.state & CHK_ST_CONFIGURED) { |
| 1201 | nbcheck++; |
| 1202 | if ((srv_getinter(&s->agent) >= SRV_CHK_INTER_THRES) && |
| 1203 | (!mininter || mininter > srv_getinter(&s->agent))) |
| 1204 | mininter = srv_getinter(&s->agent); |
| 1205 | } |
Christopher Faulet | 5c28874 | 2020-03-31 08:15:58 +0200 | [diff] [blame] | 1206 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1207 | } |
Christopher Faulet | b7d3009 | 2020-03-30 15:19:03 +0200 | [diff] [blame] | 1208 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1209 | if (!nbcheck) |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1210 | return ERR_NONE; |
Christopher Faulet | b7d3009 | 2020-03-30 15:19:03 +0200 | [diff] [blame] | 1211 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1212 | srand((unsigned)time(NULL)); |
Christopher Faulet | b7d3009 | 2020-03-30 15:19:03 +0200 | [diff] [blame] | 1213 | |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 1214 | /* 2- start them as far as possible from each other. For this, we will |
| 1215 | * start them after their interval is set to the min interval divided |
| 1216 | * by the number of servers, weighted by the server's position in the |
| 1217 | * list. |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1218 | */ |
| 1219 | for (px = proxies_list; px; px = px->next) { |
| 1220 | if ((px->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
| 1221 | if (init_pid_list()) { |
| 1222 | ha_alert("Starting [%s] check: out of memory.\n", px->id); |
| 1223 | return ERR_ALERT | ERR_FATAL; |
| 1224 | } |
| 1225 | } |
Christopher Faulet | b7d3009 | 2020-03-30 15:19:03 +0200 | [diff] [blame] | 1226 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1227 | for (s = px->srv; s; s = s->next) { |
| 1228 | /* A task for the main check */ |
| 1229 | if (s->check.state & CHK_ST_CONFIGURED) { |
| 1230 | if (s->check.type == PR_O2_EXT_CHK) { |
| 1231 | if (!prepare_external_check(&s->check)) |
| 1232 | return ERR_ALERT | ERR_FATAL; |
Christopher Faulet | b7d3009 | 2020-03-30 15:19:03 +0200 | [diff] [blame] | 1233 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1234 | if (!start_check_task(&s->check, mininter, nbcheck, srvpos)) |
| 1235 | return ERR_ALERT | ERR_FATAL; |
| 1236 | srvpos++; |
Christopher Faulet | 9857232 | 2020-03-30 13:16:44 +0200 | [diff] [blame] | 1237 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1238 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1239 | /* A task for a auxiliary agent check */ |
| 1240 | if (s->agent.state & CHK_ST_CONFIGURED) { |
| 1241 | if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) { |
| 1242 | return ERR_ALERT | ERR_FATAL; |
| 1243 | } |
| 1244 | srvpos++; |
| 1245 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1246 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1247 | } |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1248 | return ERR_NONE; |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1249 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1250 | |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1251 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1252 | /* |
| 1253 | * Return value: |
| 1254 | * the port to be used for the health check |
| 1255 | * 0 in case no port could be found for the check |
| 1256 | */ |
| 1257 | static int srv_check_healthcheck_port(struct check *chk) |
| 1258 | { |
| 1259 | int i = 0; |
| 1260 | struct server *srv = NULL; |
| 1261 | |
| 1262 | srv = chk->server; |
| 1263 | |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 1264 | /* by default, we use the health check port configured */ |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1265 | if (chk->port > 0) |
| 1266 | return chk->port; |
| 1267 | |
| 1268 | /* try to get the port from check_core.addr if check.port not set */ |
| 1269 | i = get_host_port(&chk->addr); |
| 1270 | if (i > 0) |
| 1271 | return i; |
| 1272 | |
| 1273 | /* try to get the port from server address */ |
| 1274 | /* prevent MAPPORTS from working at this point, since checks could |
| 1275 | * not be performed in such case (MAPPORTS impose a relative ports |
| 1276 | * based on live traffic) |
| 1277 | */ |
| 1278 | if (srv->flags & SRV_F_MAPPORTS) |
| 1279 | return 0; |
| 1280 | |
| 1281 | i = srv->svc_port; /* by default */ |
| 1282 | if (i > 0) |
| 1283 | return i; |
| 1284 | |
| 1285 | return 0; |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1288 | /* Initializes an health-check attached to the server <srv>. Non-zero is returned |
| 1289 | * if an error occurred. |
| 1290 | */ |
| 1291 | static int init_srv_check(struct server *srv) |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1292 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1293 | const char *err; |
| 1294 | struct tcpcheck_rule *r; |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1295 | int ret = ERR_NONE; |
Amaury Denoyelle | 0519bd4 | 2020-11-13 12:34:56 +0100 | [diff] [blame] | 1296 | int check_type; |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1297 | |
Christopher Faulet | 6ecd593 | 2021-01-12 17:29:45 +0100 | [diff] [blame] | 1298 | if (!srv->do_check || !(srv->proxy->cap & PR_CAP_BE)) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1299 | goto out; |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1300 | |
Amaury Denoyelle | 0519bd4 | 2020-11-13 12:34:56 +0100 | [diff] [blame] | 1301 | check_type = srv->check.tcpcheck_rules->flags & TCPCHK_RULES_PROTO_CHK; |
Christopher Faulet | f50f4e9 | 2020-03-30 19:52:29 +0200 | [diff] [blame] | 1302 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1303 | /* If neither a port nor an addr was specified and no check transport |
| 1304 | * layer is forced, then the transport layer used by the checks is the |
| 1305 | * same as for the production traffic. Otherwise we use raw_sock by |
| 1306 | * default, unless one is specified. |
| 1307 | */ |
| 1308 | if (!srv->check.port && !is_addr(&srv->check.addr)) { |
| 1309 | if (!srv->check.use_ssl && srv->use_ssl != -1) { |
| 1310 | srv->check.use_ssl = srv->use_ssl; |
| 1311 | srv->check.xprt = srv->xprt; |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1312 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1313 | else if (srv->check.use_ssl == 1) |
| 1314 | srv->check.xprt = xprt_get(XPRT_SSL); |
| 1315 | srv->check.send_proxy |= (srv->pp_opts); |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1316 | } |
Christopher Faulet | 66163ec | 2020-05-20 22:36:24 +0200 | [diff] [blame] | 1317 | else if (srv->check.use_ssl == 1) |
| 1318 | srv->check.xprt = xprt_get(XPRT_SSL); |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1319 | |
Christopher Faulet | 12882cf | 2020-04-23 15:50:18 +0200 | [diff] [blame] | 1320 | /* Inherit the mux protocol from the server if not already defined for |
| 1321 | * the check |
| 1322 | */ |
Amaury Denoyelle | 0519bd4 | 2020-11-13 12:34:56 +0100 | [diff] [blame] | 1323 | if (srv->mux_proto && !srv->check.mux_proto && |
| 1324 | ((srv->mux_proto->mode == PROTO_MODE_HTTP && check_type == TCPCHK_RULES_HTTP_CHK) || |
| 1325 | (srv->mux_proto->mode == PROTO_MODE_TCP && check_type != TCPCHK_RULES_HTTP_CHK))) { |
Christopher Faulet | 12882cf | 2020-04-23 15:50:18 +0200 | [diff] [blame] | 1326 | srv->check.mux_proto = srv->mux_proto; |
Amaury Denoyelle | 0519bd4 | 2020-11-13 12:34:56 +0100 | [diff] [blame] | 1327 | } |
Amaury Denoyelle | 7c14890 | 2020-11-13 12:34:57 +0100 | [diff] [blame] | 1328 | /* test that check proto is valid if explicitly defined */ |
| 1329 | else if (srv->check.mux_proto && |
| 1330 | ((srv->check.mux_proto->mode == PROTO_MODE_HTTP && check_type != TCPCHK_RULES_HTTP_CHK) || |
| 1331 | (srv->check.mux_proto->mode == PROTO_MODE_TCP && check_type == TCPCHK_RULES_HTTP_CHK))) { |
| 1332 | ha_alert("config: %s '%s': server '%s' uses an incompatible MUX protocol for the selected check type\n", |
| 1333 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id); |
| 1334 | ret |= ERR_ALERT | ERR_FATAL; |
| 1335 | goto out; |
| 1336 | } |
Christopher Faulet | 12882cf | 2020-04-23 15:50:18 +0200 | [diff] [blame] | 1337 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1338 | /* validate <srv> server health-check settings */ |
Christopher Faulet | f50f4e9 | 2020-03-30 19:52:29 +0200 | [diff] [blame] | 1339 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1340 | /* We need at least a service port, a check port or the first tcp-check |
| 1341 | * rule must be a 'connect' one when checking an IPv4/IPv6 server. |
| 1342 | */ |
| 1343 | if ((srv_check_healthcheck_port(&srv->check) != 0) || |
| 1344 | (!is_inet_addr(&srv->check.addr) && (is_addr(&srv->check.addr) || !is_inet_addr(&srv->addr)))) |
| 1345 | goto init; |
Christopher Faulet | f50f4e9 | 2020-03-30 19:52:29 +0200 | [diff] [blame] | 1346 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1347 | if (!srv->proxy->tcpcheck_rules.list || LIST_ISEMPTY(srv->proxy->tcpcheck_rules.list)) { |
| 1348 | ha_alert("config: %s '%s': server '%s' has neither service port nor check port.\n", |
| 1349 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id); |
| 1350 | ret |= ERR_ALERT | ERR_ABORT; |
| 1351 | goto out; |
| 1352 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1353 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1354 | /* search the first action (connect / send / expect) in the list */ |
| 1355 | r = get_first_tcpcheck_rule(&srv->proxy->tcpcheck_rules); |
| 1356 | if (!r || (r->action != TCPCHK_ACT_CONNECT) || (!r->connect.port && !get_host_port(&r->connect.addr))) { |
| 1357 | ha_alert("config: %s '%s': server '%s' has neither service port nor check port " |
| 1358 | "nor tcp_check rule 'connect' with port information.\n", |
| 1359 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id); |
| 1360 | ret |= ERR_ALERT | ERR_ABORT; |
| 1361 | goto out; |
| 1362 | } |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1363 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1364 | /* scan the tcp-check ruleset to ensure a port has been configured */ |
| 1365 | list_for_each_entry(r, srv->proxy->tcpcheck_rules.list, list) { |
| 1366 | if ((r->action == TCPCHK_ACT_CONNECT) && (!r->connect.port || !get_host_port(&r->connect.addr))) { |
| 1367 | ha_alert("config: %s '%s': server '%s' has neither service port nor check port, " |
| 1368 | "and a tcp_check rule 'connect' with no port information.\n", |
| 1369 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id); |
| 1370 | ret |= ERR_ALERT | ERR_ABORT; |
| 1371 | goto out; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1372 | } |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1373 | } |
| 1374 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1375 | init: |
| 1376 | if (!(srv->proxy->options2 & PR_O2_CHK_ANY)) { |
| 1377 | struct tcpcheck_ruleset *rs = NULL; |
| 1378 | struct tcpcheck_rules *rules = &srv->proxy->tcpcheck_rules; |
| 1379 | //char *errmsg = NULL; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1380 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1381 | srv->proxy->options2 &= ~PR_O2_CHK_ANY; |
| 1382 | srv->proxy->options2 |= PR_O2_TCPCHK_CHK; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1383 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1384 | rs = find_tcpcheck_ruleset("*tcp-check"); |
| 1385 | if (!rs) { |
| 1386 | rs = create_tcpcheck_ruleset("*tcp-check"); |
| 1387 | if (rs == NULL) { |
| 1388 | ha_alert("config: %s '%s': out of memory.\n", |
| 1389 | proxy_type_str(srv->proxy), srv->proxy->id); |
| 1390 | ret |= ERR_ALERT | ERR_FATAL; |
| 1391 | goto out; |
| 1392 | } |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1395 | free_tcpcheck_vars(&rules->preset_vars); |
| 1396 | rules->list = &rs->rules; |
| 1397 | rules->flags = 0; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1400 | err = init_check(&srv->check, srv->proxy->options2 & PR_O2_CHK_ANY); |
| 1401 | if (err) { |
| 1402 | ha_alert("config: %s '%s': unable to init check for server '%s' (%s).\n", |
| 1403 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err); |
| 1404 | ret |= ERR_ALERT | ERR_ABORT; |
| 1405 | goto out; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1406 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1407 | srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED; |
| 1408 | global.maxsock++; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1409 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1410 | out: |
| 1411 | return ret; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1412 | } |
| 1413 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1414 | /* Initializes an agent-check attached to the server <srv>. Non-zero is returned |
| 1415 | * if an error occurred. |
| 1416 | */ |
| 1417 | static int init_srv_agent_check(struct server *srv) |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1418 | { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1419 | struct tcpcheck_rule *chk; |
| 1420 | const char *err; |
Christopher Faulet | fc633b6 | 2020-11-06 15:24:23 +0100 | [diff] [blame] | 1421 | int ret = ERR_NONE; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1422 | |
Christopher Faulet | 6ecd593 | 2021-01-12 17:29:45 +0100 | [diff] [blame] | 1423 | if (!srv->do_agent || !(srv->proxy->cap & PR_CAP_BE)) |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1424 | goto out; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1425 | |
Ilya Shipitsin | c02a23f | 2020-05-06 00:53:22 +0500 | [diff] [blame] | 1426 | /* If there is no connect rule preceding all send / expect rules, an |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1427 | * implicit one is inserted before all others. |
| 1428 | */ |
| 1429 | chk = get_first_tcpcheck_rule(srv->agent.tcpcheck_rules); |
| 1430 | if (!chk || chk->action != TCPCHK_ACT_CONNECT) { |
| 1431 | chk = calloc(1, sizeof(*chk)); |
| 1432 | if (!chk) { |
| 1433 | ha_alert("config : %s '%s': unable to add implicit tcp-check connect rule" |
| 1434 | " to agent-check for server '%s' (out of memory).\n", |
| 1435 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id); |
| 1436 | ret |= ERR_ALERT | ERR_FATAL; |
| 1437 | goto out; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1438 | } |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1439 | chk->action = TCPCHK_ACT_CONNECT; |
| 1440 | chk->connect.options = (TCPCHK_OPT_DEFAULT_CONNECT|TCPCHK_OPT_IMPLICIT); |
| 1441 | LIST_ADD(srv->agent.tcpcheck_rules->list, &chk->list); |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1444 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1445 | err = init_check(&srv->agent, PR_O2_TCPCHK_CHK); |
| 1446 | if (err) { |
| 1447 | ha_alert("config: %s '%s': unable to init agent-check for server '%s' (%s).\n", |
| 1448 | proxy_type_str(srv->proxy), srv->proxy->id, srv->id, err); |
| 1449 | ret |= ERR_ALERT | ERR_ABORT; |
| 1450 | goto out; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1451 | } |
| 1452 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1453 | if (!srv->agent.inter) |
| 1454 | srv->agent.inter = srv->check.inter; |
| 1455 | |
| 1456 | srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT; |
| 1457 | global.maxsock++; |
| 1458 | |
| 1459 | out: |
| 1460 | return ret; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1461 | } |
| 1462 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1463 | static void deinit_srv_check(struct server *srv) |
| 1464 | { |
| 1465 | if (srv->check.state & CHK_ST_CONFIGURED) |
| 1466 | free_check(&srv->check); |
| 1467 | srv->check.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED; |
| 1468 | srv->do_check = 0; |
| 1469 | } |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1470 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1471 | |
| 1472 | static void deinit_srv_agent_check(struct server *srv) |
| 1473 | { |
| 1474 | if (srv->agent.tcpcheck_rules) { |
| 1475 | free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars); |
| 1476 | free(srv->agent.tcpcheck_rules); |
| 1477 | srv->agent.tcpcheck_rules = NULL; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1478 | } |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1479 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1480 | if (srv->agent.state & CHK_ST_CONFIGURED) |
| 1481 | free_check(&srv->agent); |
| 1482 | |
| 1483 | srv->agent.state &= ~CHK_ST_CONFIGURED & ~CHK_ST_ENABLED & ~CHK_ST_AGENT; |
| 1484 | srv->do_agent = 0; |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
Willy Tarreau | cee013e | 2020-06-05 11:40:38 +0200 | [diff] [blame] | 1487 | REGISTER_POST_SERVER_CHECK(init_srv_check); |
| 1488 | REGISTER_POST_SERVER_CHECK(init_srv_agent_check); |
Willy Tarreau | cee013e | 2020-06-05 11:40:38 +0200 | [diff] [blame] | 1489 | REGISTER_POST_CHECK(start_checks); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1490 | |
Willy Tarreau | cee013e | 2020-06-05 11:40:38 +0200 | [diff] [blame] | 1491 | REGISTER_SERVER_DEINIT(deinit_srv_check); |
| 1492 | REGISTER_SERVER_DEINIT(deinit_srv_agent_check); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1493 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1494 | |
| 1495 | /**************************************************************************/ |
| 1496 | /************************** Check sample fetches **************************/ |
| 1497 | /**************************************************************************/ |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 1498 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1499 | static struct sample_fetch_kw_list smp_kws = {ILH, { |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1500 | { /* END */ }, |
| 1501 | }}; |
| 1502 | |
| 1503 | INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws); |
| 1504 | |
| 1505 | |
| 1506 | /**************************************************************************/ |
| 1507 | /************************ Check's parsing functions ***********************/ |
| 1508 | /**************************************************************************/ |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1509 | /* Parse the "addr" server keyword */ |
| 1510 | static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1511 | char **errmsg) |
| 1512 | { |
| 1513 | struct sockaddr_storage *sk; |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1514 | int port1, port2, err_code = 0; |
| 1515 | |
| 1516 | |
| 1517 | if (!*args[*cur_arg+1]) { |
| 1518 | memprintf(errmsg, "'%s' expects <ipv4|ipv6> as argument.", args[*cur_arg]); |
| 1519 | goto error; |
| 1520 | } |
| 1521 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 1522 | sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, errmsg, NULL, NULL, |
| 1523 | PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT); |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1524 | if (!sk) { |
| 1525 | memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg); |
| 1526 | goto error; |
| 1527 | } |
| 1528 | |
William Dauchy | 1c921cd | 2021-02-03 22:30:08 +0100 | [diff] [blame] | 1529 | srv->check.addr = *sk; |
| 1530 | /* if agentaddr was never set, we can use addr */ |
| 1531 | if (!(srv->flags & SRV_F_AGENTADDR)) |
| 1532 | srv->agent.addr = *sk; |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1533 | |
| 1534 | out: |
| 1535 | return err_code; |
| 1536 | |
| 1537 | error: |
| 1538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1539 | goto out; |
| 1540 | } |
| 1541 | |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1542 | /* Parse the "agent-addr" server keyword */ |
| 1543 | static int srv_parse_agent_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1544 | char **errmsg) |
| 1545 | { |
William Dauchy | 1c921cd | 2021-02-03 22:30:08 +0100 | [diff] [blame] | 1546 | struct sockaddr_storage sk; |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1547 | int err_code = 0; |
| 1548 | |
| 1549 | if (!*(args[*cur_arg+1])) { |
| 1550 | memprintf(errmsg, "'%s' expects an address as argument.", args[*cur_arg]); |
| 1551 | goto error; |
| 1552 | } |
William Dauchy | 1c921cd | 2021-02-03 22:30:08 +0100 | [diff] [blame] | 1553 | memset(&sk, 0, sizeof(sk)); |
| 1554 | if (str2ip(args[*cur_arg + 1], &sk) == NULL) { |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1555 | memprintf(errmsg, "parsing agent-addr failed. Check if '%s' is correct address.", args[*cur_arg+1]); |
| 1556 | goto error; |
| 1557 | } |
William Dauchy | 1c921cd | 2021-02-03 22:30:08 +0100 | [diff] [blame] | 1558 | set_srv_agent_addr(srv, &sk); |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1559 | |
| 1560 | out: |
| 1561 | return err_code; |
| 1562 | |
| 1563 | error: |
| 1564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1565 | goto out; |
| 1566 | } |
| 1567 | |
| 1568 | /* Parse the "agent-check" server keyword */ |
| 1569 | static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1570 | char **errmsg) |
| 1571 | { |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1572 | struct tcpcheck_ruleset *rs = NULL; |
| 1573 | struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules; |
| 1574 | struct tcpcheck_rule *chk; |
| 1575 | int err_code = 0; |
| 1576 | |
| 1577 | if (srv->do_agent) |
| 1578 | goto out; |
| 1579 | |
Christopher Faulet | 6ecd593 | 2021-01-12 17:29:45 +0100 | [diff] [blame] | 1580 | if (!(curpx->cap & PR_CAP_BE)) { |
| 1581 | memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability", |
| 1582 | args[*cur_arg], proxy_type_str(curpx), curpx->id); |
| 1583 | return ERR_WARN; |
| 1584 | } |
| 1585 | |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1586 | if (!rules) { |
| 1587 | rules = calloc(1, sizeof(*rules)); |
| 1588 | if (!rules) { |
| 1589 | memprintf(errmsg, "out of memory."); |
| 1590 | goto error; |
| 1591 | } |
| 1592 | LIST_INIT(&rules->preset_vars); |
| 1593 | srv->agent.tcpcheck_rules = rules; |
| 1594 | } |
| 1595 | rules->list = NULL; |
| 1596 | rules->flags = 0; |
| 1597 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1598 | rs = find_tcpcheck_ruleset("*agent-check"); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1599 | if (rs) |
| 1600 | goto ruleset_found; |
| 1601 | |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1602 | rs = create_tcpcheck_ruleset("*agent-check"); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1603 | if (rs == NULL) { |
| 1604 | memprintf(errmsg, "out of memory."); |
| 1605 | goto error; |
| 1606 | } |
| 1607 | |
Christopher Faulet | b50b3e6 | 2020-05-05 18:43:43 +0200 | [diff] [blame] | 1608 | chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", "%[var(check.agent_string)]", ""}, |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1609 | 1, curpx, &rs->rules, srv->conf.file, srv->conf.line, errmsg); |
| 1610 | if (!chk) { |
| 1611 | memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg); |
| 1612 | goto error; |
| 1613 | } |
| 1614 | chk->index = 0; |
| 1615 | LIST_ADDQ(&rs->rules, &chk->list); |
| 1616 | |
| 1617 | chk = parse_tcpcheck_expect((char *[]){"tcp-check", "expect", "custom", ""}, |
Christopher Faulet | e5870d8 | 2020-04-15 11:32:03 +0200 | [diff] [blame] | 1618 | 1, curpx, &rs->rules, TCPCHK_RULES_AGENT_CHK, |
| 1619 | srv->conf.file, srv->conf.line, errmsg); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1620 | if (!chk) { |
| 1621 | memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg); |
| 1622 | goto error; |
| 1623 | } |
| 1624 | chk->expect.custom = tcpcheck_agent_expect_reply; |
| 1625 | chk->index = 1; |
| 1626 | LIST_ADDQ(&rs->rules, &chk->list); |
| 1627 | |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1628 | ruleset_found: |
| 1629 | rules->list = &rs->rules; |
Christopher Faulet | 1faf18a | 2020-11-25 16:43:12 +0100 | [diff] [blame] | 1630 | rules->flags &= ~(TCPCHK_RULES_PROTO_CHK|TCPCHK_RULES_UNUSED_RS); |
Christopher Faulet | 404f919 | 2020-04-09 23:13:54 +0200 | [diff] [blame] | 1631 | rules->flags |= TCPCHK_RULES_AGENT_CHK; |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1632 | srv->do_agent = 1; |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1633 | |
| 1634 | out: |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1635 | return 0; |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1636 | |
| 1637 | error: |
| 1638 | deinit_srv_agent_check(srv); |
Christopher Faulet | 61cc852 | 2020-04-20 14:54:42 +0200 | [diff] [blame] | 1639 | free_tcpcheck_ruleset(rs); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1640 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1641 | goto out; |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | /* Parse the "agent-inter" server keyword */ |
| 1645 | static int srv_parse_agent_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1646 | char **errmsg) |
| 1647 | { |
| 1648 | const char *err = NULL; |
| 1649 | unsigned int delay; |
| 1650 | int err_code = 0; |
| 1651 | |
| 1652 | if (!*(args[*cur_arg+1])) { |
| 1653 | memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]); |
| 1654 | goto error; |
| 1655 | } |
| 1656 | |
| 1657 | err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS); |
| 1658 | if (err == PARSE_TIME_OVER) { |
| 1659 | memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).", |
| 1660 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1661 | goto error; |
| 1662 | } |
| 1663 | else if (err == PARSE_TIME_UNDER) { |
| 1664 | memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.", |
| 1665 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1666 | goto error; |
| 1667 | } |
| 1668 | else if (err) { |
| 1669 | memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.", |
| 1670 | *err, srv->id); |
| 1671 | goto error; |
| 1672 | } |
| 1673 | if (delay <= 0) { |
| 1674 | memprintf(errmsg, "invalid value %d for argument '%s' of server %s.", |
| 1675 | delay, args[*cur_arg], srv->id); |
| 1676 | goto error; |
| 1677 | } |
| 1678 | srv->agent.inter = delay; |
| 1679 | |
| 1680 | out: |
| 1681 | return err_code; |
| 1682 | |
| 1683 | error: |
| 1684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1685 | goto out; |
| 1686 | } |
| 1687 | |
| 1688 | /* Parse the "agent-port" server keyword */ |
| 1689 | static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1690 | char **errmsg) |
| 1691 | { |
| 1692 | int err_code = 0; |
| 1693 | |
| 1694 | if (!*(args[*cur_arg+1])) { |
| 1695 | memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]); |
| 1696 | goto error; |
| 1697 | } |
| 1698 | |
| 1699 | global.maxsock++; |
William Dauchy | 4858fb2 | 2021-02-03 22:30:09 +0100 | [diff] [blame] | 1700 | set_srv_agent_port(srv, atol(args[*cur_arg + 1])); |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1701 | |
| 1702 | out: |
| 1703 | return err_code; |
| 1704 | |
| 1705 | error: |
| 1706 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1707 | goto out; |
| 1708 | } |
| 1709 | |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1710 | int set_srv_agent_send(struct server *srv, const char *send) |
| 1711 | { |
| 1712 | struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules; |
| 1713 | struct tcpcheck_var *var = NULL; |
| 1714 | char *str; |
| 1715 | |
| 1716 | str = strdup(send); |
Christopher Faulet | b61caf4 | 2020-04-21 10:57:42 +0200 | [diff] [blame] | 1717 | var = create_tcpcheck_var(ist("check.agent_string")); |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1718 | if (str == NULL || var == NULL) |
| 1719 | goto error; |
| 1720 | |
| 1721 | free_tcpcheck_vars(&rules->preset_vars); |
| 1722 | |
| 1723 | var->data.type = SMP_T_STR; |
| 1724 | var->data.u.str.area = str; |
| 1725 | var->data.u.str.data = strlen(str); |
| 1726 | LIST_INIT(&var->list); |
| 1727 | LIST_ADDQ(&rules->preset_vars, &var->list); |
| 1728 | |
| 1729 | return 1; |
| 1730 | |
| 1731 | error: |
| 1732 | free(str); |
| 1733 | free(var); |
| 1734 | return 0; |
| 1735 | } |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1736 | |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 1737 | /* set agent addr and appropriate flag */ |
William Dauchy | 1c921cd | 2021-02-03 22:30:08 +0100 | [diff] [blame] | 1738 | inline void set_srv_agent_addr(struct server *srv, struct sockaddr_storage *sk) |
| 1739 | { |
| 1740 | srv->agent.addr = *sk; |
| 1741 | srv->flags |= SRV_F_AGENTADDR; |
| 1742 | } |
| 1743 | |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 1744 | /* set agent port and appropriate flag */ |
William Dauchy | 4858fb2 | 2021-02-03 22:30:09 +0100 | [diff] [blame] | 1745 | inline void set_srv_agent_port(struct server *srv, int port) |
| 1746 | { |
| 1747 | srv->agent.port = port; |
| 1748 | srv->flags |= SRV_F_AGENTPORT; |
| 1749 | } |
| 1750 | |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1751 | /* Parse the "agent-send" server keyword */ |
| 1752 | static int srv_parse_agent_send(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1753 | char **errmsg) |
| 1754 | { |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1755 | struct tcpcheck_rules *rules = srv->agent.tcpcheck_rules; |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1756 | int err_code = 0; |
| 1757 | |
| 1758 | if (!*(args[*cur_arg+1])) { |
| 1759 | memprintf(errmsg, "'%s' expects a string as argument.", args[*cur_arg]); |
| 1760 | goto error; |
| 1761 | } |
| 1762 | |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1763 | if (!rules) { |
| 1764 | rules = calloc(1, sizeof(*rules)); |
| 1765 | if (!rules) { |
| 1766 | memprintf(errmsg, "out of memory."); |
| 1767 | goto error; |
| 1768 | } |
| 1769 | LIST_INIT(&rules->preset_vars); |
| 1770 | srv->agent.tcpcheck_rules = rules; |
| 1771 | } |
| 1772 | |
| 1773 | if (!set_srv_agent_send(srv, args[*cur_arg+1])) { |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1774 | memprintf(errmsg, "out of memory."); |
| 1775 | goto error; |
| 1776 | } |
| 1777 | |
| 1778 | out: |
| 1779 | return err_code; |
| 1780 | |
| 1781 | error: |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1782 | deinit_srv_agent_check(srv); |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1783 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1784 | goto out; |
| 1785 | } |
| 1786 | |
| 1787 | /* Parse the "no-agent-send" server keyword */ |
| 1788 | static int srv_parse_no_agent_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1789 | char **errmsg) |
| 1790 | { |
Christopher Faulet | 0ae3d1d | 2020-04-06 17:54:24 +0200 | [diff] [blame] | 1791 | deinit_srv_agent_check(srv); |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1795 | /* Parse the "check" server keyword */ |
| 1796 | static int srv_parse_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1797 | char **errmsg) |
| 1798 | { |
Christopher Faulet | 6ecd593 | 2021-01-12 17:29:45 +0100 | [diff] [blame] | 1799 | if (!(curpx->cap & PR_CAP_BE)) { |
| 1800 | memprintf(errmsg, "'%s' ignored because %s '%s' has no backend capability", |
| 1801 | args[*cur_arg], proxy_type_str(curpx), curpx->id); |
| 1802 | return ERR_WARN; |
| 1803 | } |
| 1804 | |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1805 | srv->do_check = 1; |
| 1806 | return 0; |
| 1807 | } |
| 1808 | |
| 1809 | /* Parse the "check-send-proxy" server keyword */ |
| 1810 | static int srv_parse_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1811 | char **errmsg) |
| 1812 | { |
| 1813 | srv->check.send_proxy = 1; |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | /* Parse the "check-via-socks4" server keyword */ |
| 1818 | static int srv_parse_check_via_socks4(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1819 | char **errmsg) |
| 1820 | { |
| 1821 | srv->check.via_socks4 = 1; |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | /* Parse the "no-check" server keyword */ |
| 1826 | static int srv_parse_no_check(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1827 | char **errmsg) |
| 1828 | { |
| 1829 | deinit_srv_check(srv); |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
| 1833 | /* Parse the "no-check-send-proxy" server keyword */ |
| 1834 | static int srv_parse_no_check_send_proxy(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1835 | char **errmsg) |
| 1836 | { |
| 1837 | srv->check.send_proxy = 0; |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
Christopher Faulet | edc6ed9 | 2020-04-23 16:27:59 +0200 | [diff] [blame] | 1841 | /* parse the "check-proto" server keyword */ |
| 1842 | static int srv_parse_check_proto(char **args, int *cur_arg, |
| 1843 | struct proxy *px, struct server *newsrv, char **err) |
| 1844 | { |
| 1845 | int err_code = 0; |
| 1846 | |
| 1847 | if (!*args[*cur_arg + 1]) { |
| 1848 | memprintf(err, "'%s' : missing value", args[*cur_arg]); |
| 1849 | goto error; |
| 1850 | } |
| 1851 | newsrv->check.mux_proto = get_mux_proto(ist2(args[*cur_arg + 1], strlen(args[*cur_arg + 1]))); |
| 1852 | if (!newsrv->check.mux_proto) { |
| 1853 | memprintf(err, "'%s' : unknown MUX protocol '%s'", args[*cur_arg], args[*cur_arg+1]); |
| 1854 | goto error; |
| 1855 | } |
| 1856 | |
| 1857 | out: |
| 1858 | return err_code; |
| 1859 | |
| 1860 | error: |
| 1861 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1862 | goto out; |
| 1863 | } |
| 1864 | |
| 1865 | |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 1866 | /* Parse the "rise" server keyword */ |
| 1867 | static int srv_parse_check_rise(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1868 | char **errmsg) |
| 1869 | { |
| 1870 | int err_code = 0; |
| 1871 | |
| 1872 | if (!*args[*cur_arg + 1]) { |
| 1873 | memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]); |
| 1874 | goto error; |
| 1875 | } |
| 1876 | |
| 1877 | srv->check.rise = atol(args[*cur_arg+1]); |
| 1878 | if (srv->check.rise <= 0) { |
| 1879 | memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]); |
| 1880 | goto error; |
| 1881 | } |
| 1882 | |
| 1883 | if (srv->check.health) |
| 1884 | srv->check.health = srv->check.rise; |
| 1885 | |
| 1886 | out: |
| 1887 | return err_code; |
| 1888 | |
| 1889 | error: |
| 1890 | deinit_srv_agent_check(srv); |
| 1891 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1892 | goto out; |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
| 1896 | /* Parse the "fall" server keyword */ |
| 1897 | static int srv_parse_check_fall(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1898 | char **errmsg) |
| 1899 | { |
| 1900 | int err_code = 0; |
| 1901 | |
| 1902 | if (!*args[*cur_arg + 1]) { |
| 1903 | memprintf(errmsg, "'%s' expects an integer argument.", args[*cur_arg]); |
| 1904 | goto error; |
| 1905 | } |
| 1906 | |
| 1907 | srv->check.fall = atol(args[*cur_arg+1]); |
| 1908 | if (srv->check.fall <= 0) { |
| 1909 | memprintf(errmsg, "'%s' has to be > 0.", args[*cur_arg]); |
| 1910 | goto error; |
| 1911 | } |
| 1912 | |
| 1913 | out: |
| 1914 | return err_code; |
| 1915 | |
| 1916 | error: |
| 1917 | deinit_srv_agent_check(srv); |
| 1918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1919 | goto out; |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
| 1923 | /* Parse the "inter" server keyword */ |
| 1924 | static int srv_parse_check_inter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1925 | char **errmsg) |
| 1926 | { |
| 1927 | const char *err = NULL; |
| 1928 | unsigned int delay; |
| 1929 | int err_code = 0; |
| 1930 | |
| 1931 | if (!*(args[*cur_arg+1])) { |
| 1932 | memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]); |
| 1933 | goto error; |
| 1934 | } |
| 1935 | |
| 1936 | err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS); |
| 1937 | if (err == PARSE_TIME_OVER) { |
| 1938 | memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).", |
| 1939 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1940 | goto error; |
| 1941 | } |
| 1942 | else if (err == PARSE_TIME_UNDER) { |
| 1943 | memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.", |
| 1944 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1945 | goto error; |
| 1946 | } |
| 1947 | else if (err) { |
| 1948 | memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.", |
| 1949 | *err, srv->id); |
| 1950 | goto error; |
| 1951 | } |
| 1952 | if (delay <= 0) { |
| 1953 | memprintf(errmsg, "invalid value %d for argument '%s' of server %s.", |
| 1954 | delay, args[*cur_arg], srv->id); |
| 1955 | goto error; |
| 1956 | } |
| 1957 | srv->check.inter = delay; |
| 1958 | |
| 1959 | out: |
| 1960 | return err_code; |
| 1961 | |
| 1962 | error: |
| 1963 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1964 | goto out; |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | /* Parse the "fastinter" server keyword */ |
| 1969 | static int srv_parse_check_fastinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 1970 | char **errmsg) |
| 1971 | { |
| 1972 | const char *err = NULL; |
| 1973 | unsigned int delay; |
| 1974 | int err_code = 0; |
| 1975 | |
| 1976 | if (!*(args[*cur_arg+1])) { |
| 1977 | memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]); |
| 1978 | goto error; |
| 1979 | } |
| 1980 | |
| 1981 | err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS); |
| 1982 | if (err == PARSE_TIME_OVER) { |
| 1983 | memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).", |
| 1984 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1985 | goto error; |
| 1986 | } |
| 1987 | else if (err == PARSE_TIME_UNDER) { |
| 1988 | memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.", |
| 1989 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 1990 | goto error; |
| 1991 | } |
| 1992 | else if (err) { |
| 1993 | memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.", |
| 1994 | *err, srv->id); |
| 1995 | goto error; |
| 1996 | } |
| 1997 | if (delay <= 0) { |
| 1998 | memprintf(errmsg, "invalid value %d for argument '%s' of server %s.", |
| 1999 | delay, args[*cur_arg], srv->id); |
| 2000 | goto error; |
| 2001 | } |
| 2002 | srv->check.fastinter = delay; |
| 2003 | |
| 2004 | out: |
| 2005 | return err_code; |
| 2006 | |
| 2007 | error: |
| 2008 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2009 | goto out; |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | /* Parse the "downinter" server keyword */ |
| 2014 | static int srv_parse_check_downinter(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 2015 | char **errmsg) |
| 2016 | { |
| 2017 | const char *err = NULL; |
| 2018 | unsigned int delay; |
| 2019 | int err_code = 0; |
| 2020 | |
| 2021 | if (!*(args[*cur_arg+1])) { |
| 2022 | memprintf(errmsg, "'%s' expects a delay as argument.", args[*cur_arg]); |
| 2023 | goto error; |
| 2024 | } |
| 2025 | |
| 2026 | err = parse_time_err(args[*cur_arg+1], &delay, TIME_UNIT_MS); |
| 2027 | if (err == PARSE_TIME_OVER) { |
| 2028 | memprintf(errmsg, "timer overflow in argument <%s> to <%s> of server %s, maximum value is 2147483647 ms (~24.8 days).", |
| 2029 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 2030 | goto error; |
| 2031 | } |
| 2032 | else if (err == PARSE_TIME_UNDER) { |
| 2033 | memprintf(errmsg, "timer underflow in argument <%s> to <%s> of server %s, minimum non-null value is 1 ms.", |
| 2034 | args[*cur_arg+1], args[*cur_arg], srv->id); |
| 2035 | goto error; |
| 2036 | } |
| 2037 | else if (err) { |
| 2038 | memprintf(errmsg, "unexpected character '%c' in 'agent-inter' argument of server %s.", |
| 2039 | *err, srv->id); |
| 2040 | goto error; |
| 2041 | } |
| 2042 | if (delay <= 0) { |
| 2043 | memprintf(errmsg, "invalid value %d for argument '%s' of server %s.", |
| 2044 | delay, args[*cur_arg], srv->id); |
| 2045 | goto error; |
| 2046 | } |
| 2047 | srv->check.downinter = delay; |
| 2048 | |
| 2049 | out: |
| 2050 | return err_code; |
| 2051 | |
| 2052 | error: |
| 2053 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2054 | goto out; |
| 2055 | } |
| 2056 | |
| 2057 | /* Parse the "port" server keyword */ |
| 2058 | static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, |
| 2059 | char **errmsg) |
| 2060 | { |
| 2061 | int err_code = 0; |
| 2062 | |
| 2063 | if (!*(args[*cur_arg+1])) { |
| 2064 | memprintf(errmsg, "'%s' expects a port number as argument.", args[*cur_arg]); |
| 2065 | goto error; |
| 2066 | } |
| 2067 | |
| 2068 | global.maxsock++; |
| 2069 | srv->check.port = atol(args[*cur_arg+1]); |
William Dauchy | 4858fb2 | 2021-02-03 22:30:09 +0100 | [diff] [blame] | 2070 | /* if agentport was never set, we can use port */ |
| 2071 | if (!(srv->flags & SRV_F_AGENTPORT)) |
| 2072 | srv->agent.port = srv->check.port; |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2073 | |
| 2074 | out: |
| 2075 | return err_code; |
| 2076 | |
| 2077 | error: |
| 2078 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2079 | goto out; |
| 2080 | } |
| 2081 | |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 2082 | static struct srv_kw_list srv_kws = { "CHK", { }, { |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2083 | { "addr", srv_parse_addr, 1, 1 }, /* IP address to send health to or to probe from agent-check */ |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 2084 | { "agent-addr", srv_parse_agent_addr, 1, 1 }, /* Enable an auxiliary agent check */ |
| 2085 | { "agent-check", srv_parse_agent_check, 0, 1 }, /* Enable agent checks */ |
| 2086 | { "agent-inter", srv_parse_agent_inter, 1, 1 }, /* Set the interval between two agent checks */ |
| 2087 | { "agent-port", srv_parse_agent_port, 1, 1 }, /* Set the TCP port used for agent checks. */ |
| 2088 | { "agent-send", srv_parse_agent_send, 1, 1 }, /* Set string to send to agent. */ |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2089 | { "check", srv_parse_check, 0, 1 }, /* Enable health checks */ |
Christopher Faulet | edc6ed9 | 2020-04-23 16:27:59 +0200 | [diff] [blame] | 2090 | { "check-proto", srv_parse_check_proto, 1, 1 }, /* Set the mux protocol for health checks */ |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2091 | { "check-send-proxy", srv_parse_check_send_proxy, 0, 1 }, /* Enable PROXY protocol for health checks */ |
| 2092 | { "check-via-socks4", srv_parse_check_via_socks4, 0, 1 }, /* Enable socks4 proxy for health checks */ |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 2093 | { "no-agent-check", srv_parse_no_agent_check, 0, 1 }, /* Do not enable any auxiliary agent check */ |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2094 | { "no-check", srv_parse_no_check, 0, 1 }, /* Disable health checks */ |
William Dauchy | f430090 | 2021-02-06 20:47:50 +0100 | [diff] [blame] | 2095 | { "no-check-send-proxy", srv_parse_no_check_send_proxy, 0, 1 }, /* Disable PROXY protocol for health checks */ |
Christopher Faulet | ce8111e | 2020-04-06 15:04:11 +0200 | [diff] [blame] | 2096 | { "rise", srv_parse_check_rise, 1, 1 }, /* Set rise value for health checks */ |
| 2097 | { "fall", srv_parse_check_fall, 1, 1 }, /* Set fall value for health checks */ |
| 2098 | { "inter", srv_parse_check_inter, 1, 1 }, /* Set inter value for health checks */ |
| 2099 | { "fastinter", srv_parse_check_fastinter, 1, 1 }, /* Set fastinter value for health checks */ |
| 2100 | { "downinter", srv_parse_check_downinter, 1, 1 }, /* Set downinter value for health checks */ |
| 2101 | { "port", srv_parse_check_port, 1, 1 }, /* Set the TCP port used for health checks. */ |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 2102 | { NULL, NULL, 0 }, |
| 2103 | }}; |
| 2104 | |
Christopher Faulet | cbba66c | 2020-04-06 14:26:30 +0200 | [diff] [blame] | 2105 | INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws); |
Christopher Faulet | fd6c229 | 2020-03-25 18:20:15 +0100 | [diff] [blame] | 2106 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 2107 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2108 | * Local variables: |
| 2109 | * c-indent-level: 8 |
| 2110 | * c-basic-offset: 8 |
| 2111 | * End: |
| 2112 | */ |