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