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> |
| 18 | #include <stdio.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 20 | #include <string.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 21 | #include <time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | #include <sys/socket.h> |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 24 | #include <sys/types.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 25 | #include <netinet/in.h> |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 26 | #include <netinet/tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | #include <arpa/inet.h> |
| 28 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 29 | #include <common/compat.h> |
| 30 | #include <common/config.h> |
| 31 | #include <common/mini-clist.h> |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 32 | #include <common/standard.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 33 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
| 35 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | |
| 37 | #include <proto/backend.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 38 | #include <proto/checks.h> |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 39 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <proto/fd.h> |
| 41 | #include <proto/log.h> |
| 42 | #include <proto/queue.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 43 | #include <proto/port_range.h> |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 44 | #include <proto/proto_http.h> |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 45 | #include <proto/proto_tcp.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 46 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | #include <proto/server.h> |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 48 | #include <proto/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <proto/task.h> |
| 50 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 51 | static int httpchk_expect(struct server *s, int done); |
| 52 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 53 | const struct check_status check_statuses[HCHK_STATUS_SIZE] = { |
| 54 | [HCHK_STATUS_UNKNOWN] = { SRV_CHK_UNKNOWN, "UNK", "Unknown" }, |
| 55 | [HCHK_STATUS_INI] = { SRV_CHK_UNKNOWN, "INI", "Initializing" }, |
| 56 | [HCHK_STATUS_START] = { /* SPECIAL STATUS*/ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 57 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 58 | [HCHK_STATUS_HANA] = { SRV_CHK_ERROR, "HANA", "Health analyze" }, |
| 59 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 60 | [HCHK_STATUS_SOCKERR] = { SRV_CHK_ERROR, "SOCKERR", "Socket error" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 61 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 62 | [HCHK_STATUS_L4OK] = { SRV_CHK_RUNNING, "L4OK", "Layer4 check passed" }, |
| 63 | [HCHK_STATUS_L4TOUT] = { SRV_CHK_ERROR, "L4TOUT", "Layer4 timeout" }, |
| 64 | [HCHK_STATUS_L4CON] = { SRV_CHK_ERROR, "L4CON", "Layer4 connection problem" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 65 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 66 | [HCHK_STATUS_L6OK] = { SRV_CHK_RUNNING, "L6OK", "Layer6 check passed" }, |
| 67 | [HCHK_STATUS_L6TOUT] = { SRV_CHK_ERROR, "L6TOUT", "Layer6 timeout" }, |
| 68 | [HCHK_STATUS_L6RSP] = { SRV_CHK_ERROR, "L6RSP", "Layer6 invalid response" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 69 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 70 | [HCHK_STATUS_L7TOUT] = { SRV_CHK_ERROR, "L7TOUT", "Layer7 timeout" }, |
| 71 | [HCHK_STATUS_L7RSP] = { SRV_CHK_ERROR, "L7RSP", "Layer7 invalid response" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 72 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 73 | [HCHK_STATUS_L57DATA] = { /* DUMMY STATUS */ }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 74 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 75 | [HCHK_STATUS_L7OKD] = { SRV_CHK_RUNNING, "L7OK", "Layer7 check passed" }, |
| 76 | [HCHK_STATUS_L7OKCD] = { SRV_CHK_RUNNING | SRV_CHK_DISABLE, "L7OKC", "Layer7 check conditionally passed" }, |
| 77 | [HCHK_STATUS_L7STS] = { SRV_CHK_ERROR, "L7STS", "Layer7 wrong status" }, |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 80 | const struct analyze_status analyze_statuses[HANA_STATUS_SIZE] = { /* 0: ignore, 1: error, 2: OK */ |
| 81 | [HANA_STATUS_UNKNOWN] = { "Unknown", { 0, 0 }}, |
| 82 | |
| 83 | [HANA_STATUS_L4_OK] = { "L4 successful connection", { 2, 0 }}, |
| 84 | [HANA_STATUS_L4_ERR] = { "L4 unsuccessful connection", { 1, 1 }}, |
| 85 | |
| 86 | [HANA_STATUS_HTTP_OK] = { "Correct http response", { 0, 2 }}, |
| 87 | [HANA_STATUS_HTTP_STS] = { "Wrong http response", { 0, 1 }}, |
| 88 | [HANA_STATUS_HTTP_HDRRSP] = { "Invalid http response (headers)", { 0, 1 }}, |
| 89 | [HANA_STATUS_HTTP_RSP] = { "Invalid http response", { 0, 1 }}, |
| 90 | |
| 91 | [HANA_STATUS_HTTP_READ_ERROR] = { "Read error (http)", { 0, 1 }}, |
| 92 | [HANA_STATUS_HTTP_READ_TIMEOUT] = { "Read timeout (http)", { 0, 1 }}, |
| 93 | [HANA_STATUS_HTTP_BROKEN_PIPE] = { "Close from server (http)", { 0, 1 }}, |
| 94 | }; |
| 95 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 96 | /* |
| 97 | * Convert check_status code to description |
| 98 | */ |
| 99 | const char *get_check_status_description(short check_status) { |
| 100 | |
| 101 | const char *desc; |
| 102 | |
| 103 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 104 | desc = check_statuses[check_status].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 105 | else |
| 106 | desc = NULL; |
| 107 | |
| 108 | if (desc && *desc) |
| 109 | return desc; |
| 110 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 111 | return check_statuses[HCHK_STATUS_UNKNOWN].desc; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Convert check_status code to short info |
| 116 | */ |
| 117 | const char *get_check_status_info(short check_status) { |
| 118 | |
| 119 | const char *info; |
| 120 | |
| 121 | if (check_status < HCHK_STATUS_SIZE) |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 122 | info = check_statuses[check_status].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 123 | else |
| 124 | info = NULL; |
| 125 | |
| 126 | if (info && *info) |
| 127 | return info; |
| 128 | else |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 129 | return check_statuses[HCHK_STATUS_UNKNOWN].info; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 132 | const char *get_analyze_status(short analyze_status) { |
| 133 | |
| 134 | const char *desc; |
| 135 | |
| 136 | if (analyze_status < HANA_STATUS_SIZE) |
| 137 | desc = analyze_statuses[analyze_status].desc; |
| 138 | else |
| 139 | desc = NULL; |
| 140 | |
| 141 | if (desc && *desc) |
| 142 | return desc; |
| 143 | else |
| 144 | return analyze_statuses[HANA_STATUS_UNKNOWN].desc; |
| 145 | } |
| 146 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 147 | #define SSP_O_HCHK 0x0002 |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 148 | |
| 149 | static void server_status_printf(struct chunk *msg, struct server *s, unsigned options, int xferred) { |
| 150 | |
Krzysztof Piotr Oledzki | 5f5b7d2 | 2010-01-11 11:13:39 +0100 | [diff] [blame] | 151 | if (s->tracked) |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 152 | chunk_printf(msg, " via %s/%s", |
| 153 | s->tracked->proxy->id, s->tracked->id); |
| 154 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 155 | if (options & SSP_O_HCHK) { |
| 156 | chunk_printf(msg, ", reason: %s", get_check_status_description(s->check_status)); |
| 157 | |
| 158 | if (s->check_status >= HCHK_STATUS_L57DATA) |
| 159 | chunk_printf(msg, ", code: %d", s->check_code); |
| 160 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 161 | if (*s->check_desc) { |
| 162 | struct chunk src; |
| 163 | |
| 164 | chunk_printf(msg, ", info: \""); |
| 165 | |
| 166 | chunk_initlen(&src, s->check_desc, 0, strlen(s->check_desc)); |
| 167 | chunk_asciiencode(msg, &src, '"'); |
| 168 | |
| 169 | chunk_printf(msg, "\""); |
| 170 | } |
| 171 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 172 | if (s->check_duration >= 0) |
| 173 | chunk_printf(msg, ", check duration: %ldms", s->check_duration); |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Krzysztof Piotr Oledzki | 3bb0571 | 2010-09-27 13:10:50 +0200 | [diff] [blame] | 176 | if (xferred >= 0) { |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 177 | if (!(s->state & SRV_RUNNING)) |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 178 | chunk_printf(msg, ". %d active and %d backup servers left.%s" |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 179 | " %d sessions active, %d requeued, %d remaining in queue", |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 180 | s->proxy->srv_act, s->proxy->srv_bck, |
| 181 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 182 | s->cur_sess, xferred, s->nbpend); |
| 183 | else |
| 184 | chunk_printf(msg, ". %d active and %d backup servers online.%s" |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 185 | " %d sessions requeued, %d total in queue", |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 186 | s->proxy->srv_act, s->proxy->srv_bck, |
| 187 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 188 | xferred, s->nbpend); |
| 189 | } |
| 190 | } |
| 191 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 192 | /* |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 193 | * Set s->check_status, update s->check_duration and fill s->result with |
| 194 | * an adequate SRV_CHK_* value. |
| 195 | * |
| 196 | * Show information in logs about failed health check if server is UP |
| 197 | * or succeeded health checks if server is DOWN. |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 198 | */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 199 | static void set_server_check_status(struct server *s, short status, char *desc) { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 200 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 201 | struct chunk msg; |
| 202 | |
| 203 | if (status == HCHK_STATUS_START) { |
| 204 | s->result = SRV_CHK_UNKNOWN; /* no result yet */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 205 | s->check_desc[0] = '\0'; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 206 | s->check_start = now; |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | if (!s->check_status) |
| 211 | return; |
| 212 | |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 213 | if (desc && *desc) { |
| 214 | strncpy(s->check_desc, desc, HCHK_DESC_LEN-1); |
| 215 | s->check_desc[HCHK_DESC_LEN-1] = '\0'; |
| 216 | } else |
| 217 | s->check_desc[0] = '\0'; |
| 218 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 219 | s->check_status = status; |
| 220 | if (check_statuses[status].result) |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 221 | s->result = check_statuses[status].result; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 222 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 223 | if (status == HCHK_STATUS_HANA) |
| 224 | s->check_duration = -1; |
| 225 | else if (!tv_iszero(&s->check_start)) { |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 226 | /* set_server_check_status() may be called more than once */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 227 | s->check_duration = tv_ms_elapsed(&s->check_start, &now); |
| 228 | tv_zero(&s->check_start); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | if (s->proxy->options2 & PR_O2_LOGHCHKS && |
| 232 | (((s->health != 0) && (s->result & SRV_CHK_ERROR)) || |
| 233 | ((s->health != s->rise + s->fall - 1) && (s->result & SRV_CHK_RUNNING)) || |
| 234 | ((s->state & SRV_GOINGDOWN) && !(s->result & SRV_CHK_DISABLE)) || |
| 235 | (!(s->state & SRV_GOINGDOWN) && (s->result & SRV_CHK_DISABLE)))) { |
| 236 | |
| 237 | int health, rise, fall, state; |
| 238 | |
| 239 | chunk_init(&msg, trash, sizeof(trash)); |
| 240 | |
| 241 | /* FIXME begin: calculate local version of the health/rise/fall/state */ |
| 242 | health = s->health; |
| 243 | rise = s->rise; |
| 244 | fall = s->fall; |
| 245 | state = s->state; |
| 246 | |
| 247 | if (s->result & SRV_CHK_ERROR) { |
| 248 | if (health > rise) { |
| 249 | health--; /* still good */ |
| 250 | } else { |
| 251 | if (health == rise) |
| 252 | state &= ~(SRV_RUNNING | SRV_GOINGDOWN); |
| 253 | |
| 254 | health = 0; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | if (s->result & SRV_CHK_RUNNING) { |
| 259 | if (health < rise + fall - 1) { |
| 260 | health++; /* was bad, stays for a while */ |
| 261 | |
| 262 | if (health == rise) |
| 263 | state |= SRV_RUNNING; |
| 264 | |
| 265 | if (health >= rise) |
| 266 | health = rise + fall - 1; /* OK now */ |
| 267 | } |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 268 | |
| 269 | /* clear consecutive_errors if observing is enabled */ |
| 270 | if (s->onerror) |
| 271 | s->consecutive_errors = 0; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 272 | } |
| 273 | /* FIXME end: calculate local version of the health/rise/fall/state */ |
| 274 | |
| 275 | chunk_printf(&msg, |
| 276 | "Health check for %sserver %s/%s %s%s", |
| 277 | s->state & SRV_BACKUP ? "backup " : "", |
| 278 | s->proxy->id, s->id, |
| 279 | (s->result & SRV_CHK_DISABLE)?"conditionally ":"", |
| 280 | (s->result & SRV_CHK_RUNNING)?"succeeded":"failed"); |
| 281 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 282 | server_status_printf(&msg, s, SSP_O_HCHK, -1); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 283 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 284 | chunk_printf(&msg, ", status: %d/%d %s", |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 285 | (state & SRV_RUNNING) ? (health - rise + 1) : (health), |
| 286 | (state & SRV_RUNNING) ? (fall) : (rise), |
| 287 | (state & SRV_RUNNING)?"UP":"DOWN"); |
| 288 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 289 | Warning("%s.\n", trash); |
| 290 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 291 | } |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 294 | /* sends a log message when a backend goes down, and also sets last |
| 295 | * change date. |
| 296 | */ |
| 297 | static void set_backend_down(struct proxy *be) |
| 298 | { |
| 299 | be->last_change = now.tv_sec; |
| 300 | be->down_trans++; |
| 301 | |
| 302 | Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id); |
| 303 | send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id); |
| 304 | } |
| 305 | |
| 306 | /* Redistribute pending connections when a server goes down. The number of |
| 307 | * connections redistributed is returned. |
| 308 | */ |
| 309 | static int redistribute_pending(struct server *s) |
| 310 | { |
| 311 | struct pendconn *pc, *pc_bck, *pc_end; |
| 312 | int xferred = 0; |
| 313 | |
| 314 | FOREACH_ITEM_SAFE(pc, pc_bck, &s->pendconns, pc_end, struct pendconn *, list) { |
| 315 | struct session *sess = pc->sess; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 316 | if ((sess->be->options & (PR_O_REDISP|PR_O_PERSIST)) == PR_O_REDISP && |
| 317 | !(sess->flags & SN_FORCE_PRST)) { |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 318 | /* The REDISP option was specified. We will ignore |
| 319 | * cookie and force to balance or use the dispatcher. |
| 320 | */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 321 | |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 322 | /* it's left to the dispatcher to choose a server */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 323 | sess->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 324 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 325 | pendconn_free(pc); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 326 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 327 | xferred++; |
| 328 | } |
| 329 | } |
| 330 | return xferred; |
| 331 | } |
| 332 | |
| 333 | /* Check for pending connections at the backend, and assign some of them to |
| 334 | * the server coming up. The server's weight is checked before being assigned |
| 335 | * connections it may not be able to handle. The total number of transferred |
| 336 | * connections is returned. |
| 337 | */ |
| 338 | static int check_for_pending(struct server *s) |
| 339 | { |
| 340 | int xferred; |
| 341 | |
| 342 | if (!s->eweight) |
| 343 | return 0; |
| 344 | |
| 345 | for (xferred = 0; !s->maxconn || xferred < srv_dynamic_maxconn(s); xferred++) { |
| 346 | struct session *sess; |
| 347 | struct pendconn *p; |
| 348 | |
| 349 | p = pendconn_from_px(s->proxy); |
| 350 | if (!p) |
| 351 | break; |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 352 | set_target_server(&p->sess->target, s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 353 | sess = p->sess; |
| 354 | pendconn_free(p); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 355 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 356 | } |
| 357 | return xferred; |
| 358 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 359 | |
| 360 | /* Sets server <s> down, notifies by all available means, recounts the |
| 361 | * remaining servers on the proxy and transfers queued sessions whenever |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 362 | * possible to other servers. It automatically recomputes the number of |
| 363 | * servers, but not the map. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 364 | */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 365 | void set_server_down(struct server *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 366 | { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 367 | struct server *srv; |
| 368 | struct chunk msg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 369 | int xferred; |
| 370 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 371 | if (s->state & SRV_MAINTAIN) { |
| 372 | s->health = s->rise; |
| 373 | } |
| 374 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 375 | if (s->health == s->rise || s->tracked) { |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 376 | int srv_was_paused = s->state & SRV_GOINGDOWN; |
Willy Tarreau | d64d225 | 2010-10-17 17:16:42 +0200 | [diff] [blame] | 377 | int prev_srv_count = s->proxy->srv_bck + s->proxy->srv_act; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 378 | |
| 379 | s->last_change = now.tv_sec; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 380 | s->state &= ~(SRV_RUNNING | SRV_GOINGDOWN); |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 381 | s->proxy->lbprm.set_server_status_down(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 382 | |
| 383 | /* we might have sessions queued on this server and waiting for |
| 384 | * a connection. Those which are redispatchable will be queued |
| 385 | * to another server or to the proxy itself. |
| 386 | */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 387 | xferred = redistribute_pending(s); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 388 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 389 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 390 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 391 | if (s->state & SRV_MAINTAIN) { |
| 392 | chunk_printf(&msg, |
| 393 | "%sServer %s/%s is DOWN for maintenance", s->state & SRV_BACKUP ? "Backup " : "", |
| 394 | s->proxy->id, s->id); |
| 395 | } else { |
| 396 | chunk_printf(&msg, |
| 397 | "%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "", |
| 398 | s->proxy->id, s->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 399 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 400 | server_status_printf(&msg, s, |
| 401 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
| 402 | xferred); |
| 403 | } |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 404 | Warning("%s.\n", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 405 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 406 | /* we don't send an alert if the server was previously paused */ |
| 407 | if (srv_was_paused) |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 408 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 409 | else |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 410 | send_log(s->proxy, LOG_ALERT, "%s.\n", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 411 | |
Willy Tarreau | d64d225 | 2010-10-17 17:16:42 +0200 | [diff] [blame] | 412 | if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 413 | set_backend_down(s->proxy); |
| 414 | |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 415 | s->counters.down_trans++; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 416 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 417 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 418 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 419 | if (! (srv->state & SRV_MAINTAIN)) |
| 420 | /* Only notify tracking servers that are not already in maintenance. */ |
| 421 | set_server_down(srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 422 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 423 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 424 | s->health = 0; /* failure */ |
| 425 | } |
| 426 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 427 | void set_server_up(struct server *s) { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 428 | |
| 429 | struct server *srv; |
| 430 | struct chunk msg; |
| 431 | int xferred; |
| 432 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 433 | if (s->state & SRV_MAINTAIN) { |
| 434 | s->health = s->rise; |
| 435 | } |
| 436 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 437 | if (s->health == s->rise || s->tracked) { |
| 438 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 439 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 440 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 441 | s->proxy->last_change = now.tv_sec; |
| 442 | } |
| 443 | |
| 444 | if (s->last_change < now.tv_sec) // ignore negative times |
| 445 | s->down_time += now.tv_sec - s->last_change; |
| 446 | |
| 447 | s->last_change = now.tv_sec; |
| 448 | s->state |= SRV_RUNNING; |
| 449 | |
| 450 | if (s->slowstart > 0) { |
| 451 | s->state |= SRV_WARMINGUP; |
| 452 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 453 | /* For dynamic algorithms, start at the first step of the weight, |
| 454 | * without multiplying by BE_WEIGHT_SCALE. |
| 455 | */ |
| 456 | s->eweight = s->uweight; |
| 457 | if (s->proxy->lbprm.update_server_eweight) |
| 458 | s->proxy->lbprm.update_server_eweight(s); |
| 459 | } |
| 460 | } |
| 461 | s->proxy->lbprm.set_server_status_up(s); |
| 462 | |
| 463 | /* check if we can handle some connections queued at the proxy. We |
| 464 | * will take as many as we can handle. |
| 465 | */ |
| 466 | xferred = check_for_pending(s); |
| 467 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 468 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 469 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 470 | if (s->state & SRV_MAINTAIN) { |
| 471 | chunk_printf(&msg, |
| 472 | "%sServer %s/%s is UP (leaving maintenance)", s->state & SRV_BACKUP ? "Backup " : "", |
| 473 | s->proxy->id, s->id); |
| 474 | } else { |
| 475 | chunk_printf(&msg, |
| 476 | "%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "", |
| 477 | s->proxy->id, s->id); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 478 | |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 479 | server_status_printf(&msg, s, |
| 480 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
| 481 | xferred); |
| 482 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 483 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 484 | Warning("%s.\n", trash); |
| 485 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 486 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 487 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 488 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 489 | if (! (srv->state & SRV_MAINTAIN)) |
| 490 | /* Only notify tracking servers if they're not in maintenance. */ |
| 491 | set_server_up(srv); |
| 492 | |
| 493 | s->state &= ~SRV_MAINTAIN; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | if (s->health >= s->rise) |
| 497 | s->health = s->rise + s->fall - 1; /* OK now */ |
| 498 | |
| 499 | } |
| 500 | |
| 501 | static void set_server_disabled(struct server *s) { |
| 502 | |
| 503 | struct server *srv; |
| 504 | struct chunk msg; |
| 505 | int xferred; |
| 506 | |
| 507 | s->state |= SRV_GOINGDOWN; |
| 508 | s->proxy->lbprm.set_server_status_down(s); |
| 509 | |
| 510 | /* we might have sessions queued on this server and waiting for |
| 511 | * a connection. Those which are redispatchable will be queued |
| 512 | * to another server or to the proxy itself. |
| 513 | */ |
| 514 | xferred = redistribute_pending(s); |
| 515 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 516 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 517 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 518 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 519 | "Load-balancing on %sServer %s/%s is disabled", |
| 520 | s->state & SRV_BACKUP ? "Backup " : "", |
| 521 | s->proxy->id, s->id); |
| 522 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 523 | server_status_printf(&msg, s, |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 524 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 525 | xferred); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 526 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 527 | Warning("%s.\n", trash); |
| 528 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 529 | |
| 530 | if (!s->proxy->srv_bck && !s->proxy->srv_act) |
| 531 | set_backend_down(s->proxy); |
| 532 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 533 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 534 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 535 | set_server_disabled(srv); |
| 536 | } |
| 537 | |
| 538 | static void set_server_enabled(struct server *s) { |
| 539 | |
| 540 | struct server *srv; |
| 541 | struct chunk msg; |
| 542 | int xferred; |
| 543 | |
| 544 | s->state &= ~SRV_GOINGDOWN; |
| 545 | s->proxy->lbprm.set_server_status_up(s); |
| 546 | |
| 547 | /* check if we can handle some connections queued at the proxy. We |
| 548 | * will take as many as we can handle. |
| 549 | */ |
| 550 | xferred = check_for_pending(s); |
| 551 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 552 | chunk_init(&msg, trash, sizeof(trash)); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 553 | |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 554 | chunk_printf(&msg, |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 555 | "Load-balancing on %sServer %s/%s is enabled again", |
| 556 | s->state & SRV_BACKUP ? "Backup " : "", |
| 557 | s->proxy->id, s->id); |
| 558 | |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 559 | server_status_printf(&msg, s, |
Krzysztof Piotr Oledzki | 99ab5f8 | 2009-09-27 17:28:21 +0200 | [diff] [blame] | 560 | ((!s->tracked && !(s->proxy->options2 & PR_O2_LOGHCHKS))?SSP_O_HCHK:0), |
Krzysztof Piotr Oledzki | b16a607 | 2010-01-10 21:12:58 +0100 | [diff] [blame] | 561 | xferred); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 562 | |
Krzysztof Piotr Oledzki | 9f2b9d5 | 2010-01-11 13:16:27 +0100 | [diff] [blame] | 563 | Warning("%s.\n", trash); |
| 564 | send_log(s->proxy, LOG_NOTICE, "%s.\n", trash); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 565 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 566 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 567 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 568 | set_server_enabled(srv); |
| 569 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 570 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 571 | void health_adjust(struct server *s, short status) { |
| 572 | |
| 573 | int failed; |
| 574 | int expire; |
| 575 | |
| 576 | /* return now if observing nor health check is not enabled */ |
| 577 | if (!s->observe || !s->check) |
| 578 | return; |
| 579 | |
| 580 | if (s->observe >= HANA_OBS_SIZE) |
| 581 | return; |
| 582 | |
| 583 | if (status >= HCHK_STATUS_SIZE || !analyze_statuses[status].desc) |
| 584 | return; |
| 585 | |
| 586 | switch (analyze_statuses[status].lr[s->observe - 1]) { |
| 587 | case 1: |
| 588 | failed = 1; |
| 589 | break; |
| 590 | |
| 591 | case 2: |
| 592 | failed = 0; |
| 593 | break; |
| 594 | |
| 595 | default: |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | if (!failed) { |
| 600 | /* good: clear consecutive_errors */ |
| 601 | s->consecutive_errors = 0; |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | s->consecutive_errors++; |
| 606 | |
| 607 | if (s->consecutive_errors < s->consecutive_errors_limit) |
| 608 | return; |
| 609 | |
| 610 | sprintf(trash, "Detected %d consecutive errors, last one was: %s", |
| 611 | s->consecutive_errors, get_analyze_status(status)); |
| 612 | |
| 613 | switch (s->onerror) { |
| 614 | case HANA_ONERR_FASTINTER: |
| 615 | /* force fastinter - nothing to do here as all modes force it */ |
| 616 | break; |
| 617 | |
| 618 | case HANA_ONERR_SUDDTH: |
| 619 | /* simulate a pre-fatal failed health check */ |
| 620 | if (s->health > s->rise) |
| 621 | s->health = s->rise + 1; |
| 622 | |
| 623 | /* no break - fall through */ |
| 624 | |
| 625 | case HANA_ONERR_FAILCHK: |
| 626 | /* simulate a failed health check */ |
| 627 | set_server_check_status(s, HCHK_STATUS_HANA, trash); |
| 628 | |
| 629 | if (s->health > s->rise) { |
| 630 | s->health--; /* still good */ |
| 631 | s->counters.failed_checks++; |
| 632 | } |
| 633 | else |
| 634 | set_server_down(s); |
| 635 | |
| 636 | break; |
| 637 | |
| 638 | case HANA_ONERR_MARKDWN: |
| 639 | /* mark server down */ |
| 640 | s->health = s->rise; |
| 641 | set_server_check_status(s, HCHK_STATUS_HANA, trash); |
| 642 | set_server_down(s); |
| 643 | |
| 644 | break; |
| 645 | |
| 646 | default: |
| 647 | /* write a warning? */ |
| 648 | break; |
| 649 | } |
| 650 | |
| 651 | s->consecutive_errors = 0; |
| 652 | s->counters.failed_hana++; |
| 653 | |
| 654 | if (s->fastinter) { |
| 655 | expire = tick_add(now_ms, MS_TO_TICKS(s->fastinter)); |
| 656 | if (s->check->expire > expire) |
| 657 | s->check->expire = expire; |
| 658 | } |
| 659 | } |
| 660 | |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 661 | static int httpchk_build_status_header(struct server *s, char *buffer) |
| 662 | { |
| 663 | int sv_state; |
| 664 | int ratio; |
| 665 | int hlen = 0; |
| 666 | const char *srv_hlt_st[7] = { "DOWN", "DOWN %d/%d", |
| 667 | "UP %d/%d", "UP", |
| 668 | "NOLB %d/%d", "NOLB", |
| 669 | "no check" }; |
| 670 | |
| 671 | memcpy(buffer + hlen, "X-Haproxy-Server-State: ", 24); |
| 672 | hlen += 24; |
| 673 | |
| 674 | if (!(s->state & SRV_CHECKED)) |
| 675 | sv_state = 6; /* should obviously never happen */ |
| 676 | else if (s->state & SRV_RUNNING) { |
| 677 | if (s->health == s->rise + s->fall - 1) |
| 678 | sv_state = 3; /* UP */ |
| 679 | else |
| 680 | sv_state = 2; /* going down */ |
| 681 | |
| 682 | if (s->state & SRV_GOINGDOWN) |
| 683 | sv_state += 2; |
| 684 | } else { |
| 685 | if (s->health) |
| 686 | sv_state = 1; /* going up */ |
| 687 | else |
| 688 | sv_state = 0; /* DOWN */ |
| 689 | } |
| 690 | |
| 691 | hlen += sprintf(buffer + hlen, |
| 692 | srv_hlt_st[sv_state], |
| 693 | (s->state & SRV_RUNNING) ? (s->health - s->rise + 1) : (s->health), |
| 694 | (s->state & SRV_RUNNING) ? (s->fall) : (s->rise)); |
| 695 | |
| 696 | hlen += sprintf(buffer + hlen, "; name=%s/%s; node=%s; weight=%d/%d; scur=%d/%d; qcur=%d", |
| 697 | s->proxy->id, s->id, |
| 698 | global.node, |
| 699 | (s->eweight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 700 | (s->proxy->lbprm.tot_weight * s->proxy->lbprm.wmult + s->proxy->lbprm.wdiv - 1) / s->proxy->lbprm.wdiv, |
| 701 | s->cur_sess, s->proxy->beconn - s->proxy->nbpend, |
| 702 | s->nbpend); |
| 703 | |
| 704 | if ((s->state & SRV_WARMINGUP) && |
| 705 | now.tv_sec < s->last_change + s->slowstart && |
| 706 | now.tv_sec >= s->last_change) { |
| 707 | ratio = MAX(1, 100 * (now.tv_sec - s->last_change) / s->slowstart); |
| 708 | hlen += sprintf(buffer + hlen, "; throttle=%d%%", ratio); |
| 709 | } |
| 710 | |
| 711 | buffer[hlen++] = '\r'; |
| 712 | buffer[hlen++] = '\n'; |
| 713 | |
| 714 | return hlen; |
| 715 | } |
| 716 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 717 | /* |
| 718 | * This function is used only for server health-checks. It handles |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 719 | * the connection acknowledgement. If the proxy requires L7 health-checks, |
| 720 | * it sends the request. In other cases, it calls set_server_check_status() |
| 721 | * to set s->check_status, s->check_duration and s->result. |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 722 | * The function itself returns 0 if it needs some polling before being called |
| 723 | * again, otherwise 1. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 724 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 725 | static int event_srv_chk_w(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 726 | { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 727 | __label__ out_wakeup, out_nowake, out_poll, out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 728 | struct task *t = fdtab[fd].owner; |
| 729 | struct server *s = t->context; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 730 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 731 | //fprintf(stderr, "event_srv_chk_w, state=%ld\n", unlikely(fdtab[fd].state)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 732 | if (unlikely(fdtab[fd].state == FD_STERROR || (fdtab[fd].ev & FD_POLL_ERR))) { |
Krzysztof Piotr Oledzki | 6492db5 | 2010-01-02 22:03:01 +0100 | [diff] [blame] | 733 | int skerr, err = errno; |
| 734 | socklen_t lskerr = sizeof(skerr); |
| 735 | |
| 736 | if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) && skerr) |
| 737 | err = skerr; |
| 738 | |
| 739 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(err)); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 740 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 741 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 742 | |
| 743 | /* here, we know that the connection is established */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 744 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 745 | if (!(s->result & SRV_CHK_ERROR)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 746 | /* we don't want to mark 'UP' a server on which we detected an error earlier */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 747 | if ((s->proxy->options & PR_O_HTTP_CHK) || |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 748 | (s->proxy->options & PR_O_SMTP_CHK) || |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 749 | (s->proxy->options2 & PR_O2_SSL3_CHK) || |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 750 | (s->proxy->options2 & PR_O2_MYSQL_CHK) || |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 751 | (s->proxy->options2 & PR_O2_PGSQL_CHK) || |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 752 | (s->proxy->options2 & PR_O2_LDAP_CHK)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 753 | int ret; |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 754 | const char *check_req = s->proxy->check_req; |
| 755 | int check_len = s->proxy->check_len; |
| 756 | |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 757 | /* we want to check if this host replies to HTTP or SSLv3 requests |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 758 | * so we'll send the request, and won't wake the checker up now. |
| 759 | */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 760 | |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 761 | if (s->proxy->options2 & PR_O2_SSL3_CHK) { |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 762 | /* SSL requires that we put Unix time in the request */ |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 763 | int gmt_time = htonl(date.tv_sec); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 764 | memcpy(s->proxy->check_req + 11, &gmt_time, 4); |
| 765 | } |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 766 | else if (s->proxy->options & PR_O_HTTP_CHK) { |
| 767 | memcpy(trash, check_req, check_len); |
Willy Tarreau | ef78104 | 2010-01-27 11:53:01 +0100 | [diff] [blame] | 768 | |
| 769 | if (s->proxy->options2 & PR_O2_CHK_SNDST) |
| 770 | check_len += httpchk_build_status_header(s, trash + check_len); |
| 771 | |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 772 | trash[check_len++] = '\r'; |
| 773 | trash[check_len++] = '\n'; |
| 774 | trash[check_len] = '\0'; |
| 775 | check_req = trash; |
| 776 | } |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 777 | |
Willy Tarreau | e9d8788 | 2010-01-27 11:28:42 +0100 | [diff] [blame] | 778 | ret = send(fd, check_req, check_len, MSG_DONTWAIT | MSG_NOSIGNAL); |
| 779 | if (ret == check_len) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 780 | /* we allow up to <timeout.check> if nonzero for a responce */ |
Willy Tarreau | 7cd9d94 | 2008-12-21 13:00:41 +0100 | [diff] [blame] | 781 | if (s->proxy->timeout.check) |
| 782 | t->expire = tick_add_ifset(now_ms, s->proxy->timeout.check); |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 783 | EV_FD_SET(fd, DIR_RD); /* prepare for reading reply */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 784 | goto out_nowake; |
| 785 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 786 | else if (ret == 0 || errno == EAGAIN) |
| 787 | goto out_poll; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 788 | else { |
| 789 | switch (errno) { |
| 790 | case ECONNREFUSED: |
| 791 | case ENETUNREACH: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 792 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | default: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 796 | set_server_check_status(s, HCHK_STATUS_SOCKERR, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 799 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 800 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 801 | } |
| 802 | else { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 803 | /* We have no data to send to check the connection, and |
| 804 | * getsockopt() will not inform us whether the connection |
| 805 | * is still pending. So we'll reuse connect() to check the |
| 806 | * state of the socket. This has the advantage of givig us |
| 807 | * the following info : |
| 808 | * - error |
| 809 | * - connecting (EALREADY, EINPROGRESS) |
| 810 | * - connected (EISCONN, 0) |
| 811 | */ |
| 812 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 813 | struct sockaddr_storage sa; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 814 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 815 | if (is_addr(&s->check_addr)) |
| 816 | sa = s->check_addr; |
| 817 | else |
| 818 | sa = s->addr; |
| 819 | |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 820 | set_host_port(&sa, s->check_port); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 821 | |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 822 | if (connect(fd, (struct sockaddr *)&sa, get_addr_len(&sa)) == 0) |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 823 | errno = 0; |
| 824 | |
| 825 | if (errno == EALREADY || errno == EINPROGRESS) |
| 826 | goto out_poll; |
| 827 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 828 | if (errno && errno != EISCONN) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 829 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 830 | goto out_error; |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 831 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 832 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 833 | /* good TCP connection is enough */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 834 | set_server_check_status(s, HCHK_STATUS_L4OK, NULL); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 835 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 836 | } |
| 837 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 838 | out_wakeup: |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 839 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 840 | out_nowake: |
| 841 | EV_FD_CLR(fd, DIR_WR); /* nothing more to write */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 842 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 843 | return 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 844 | out_poll: |
| 845 | /* The connection is still pending. We'll have to poll it |
| 846 | * before attempting to go further. */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 847 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 848 | return 0; |
| 849 | out_error: |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 850 | fdtab[fd].state = FD_STERROR; |
| 851 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | |
| 855 | /* |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 856 | * This function is used only for server health-checks. It handles the server's |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 857 | * reply to an HTTP request, SSL HELLO or MySQL client Auth. It calls |
| 858 | * set_server_check_status() to update s->check_status, s->check_duration |
| 859 | * and s->result. |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 860 | |
| 861 | * The set_server_check_status function is called with HCHK_STATUS_L7OKD if |
| 862 | * an HTTP server replies HTTP 2xx or 3xx (valid responses), if an SMTP server |
| 863 | * returns 2xx, HCHK_STATUS_L6OK if an SSL server returns at least 5 bytes in |
| 864 | * response to an SSL HELLO (the principle is that this is enough to |
| 865 | * distinguish between an SSL server and a pure TCP relay). All other cases will |
| 866 | * call it with a proper error status like HCHK_STATUS_L7STS, HCHK_STATUS_L6RSP, |
| 867 | * etc. |
| 868 | * |
| 869 | * The function returns 0 if it needs to be called again after some polling, |
| 870 | * otherwise non-zero.. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 871 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 872 | static int event_srv_chk_r(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 873 | { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 874 | __label__ out_wakeup; |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 875 | int len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 876 | struct task *t = fdtab[fd].owner; |
| 877 | struct server *s = t->context; |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 878 | char *desc; |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 879 | int done; |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 880 | unsigned short msglen; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 881 | |
Willy Tarreau | 659d7bc | 2010-03-16 21:14:41 +0100 | [diff] [blame] | 882 | if (unlikely((s->result & SRV_CHK_ERROR) || (fdtab[fd].state == FD_STERROR))) { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 883 | /* in case of TCP only, this tells us if the connection failed */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 884 | if (!(s->result & SRV_CHK_ERROR)) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 885 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 886 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 887 | goto out_wakeup; |
| 888 | } |
| 889 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 890 | /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available |
| 891 | * but the connection was closed on the remote end. Fortunately, recv still |
| 892 | * works correctly and we don't need to do the getsockopt() on linux. |
| 893 | */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 894 | |
| 895 | /* Set buffer to point to the end of the data already read, and check |
| 896 | * that there is free space remaining. If the buffer is full, proceed |
| 897 | * with running the checks without attempting another socket read. |
| 898 | */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 899 | |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 900 | done = 0; |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 901 | for (len = 0; s->check_data_len < global.tune.chksize; s->check_data_len += len) { |
| 902 | len = recv(fd, s->check_data + s->check_data_len, global.tune.chksize - s->check_data_len, 0); |
Willy Tarreau | 2c7ace0 | 2010-03-16 20:32:04 +0100 | [diff] [blame] | 903 | if (len <= 0) |
| 904 | break; |
| 905 | } |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 906 | |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 907 | if (len == 0) |
| 908 | done = 1; /* connection hangup received */ |
| 909 | else if (len < 0 && errno != EAGAIN) { |
Willy Tarreau | c1a0796 | 2010-03-16 20:55:43 +0100 | [diff] [blame] | 910 | /* Report network errors only if we got no other data. Otherwise |
| 911 | * we'll let the upper layers decide whether the response is OK |
| 912 | * or not. It is very common that an RST sent by the server is |
| 913 | * reported as an error just after the last data chunk. |
| 914 | */ |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 915 | done = 1; |
Willy Tarreau | c1a0796 | 2010-03-16 20:55:43 +0100 | [diff] [blame] | 916 | if (!s->check_data_len) { |
| 917 | if (!(s->result & SRV_CHK_ERROR)) |
| 918 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
| 919 | goto out_wakeup; |
| 920 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 923 | /* Intermediate or complete response received. |
| 924 | * Terminate string in check_data buffer. |
| 925 | */ |
Willy Tarreau | 43961d5 | 2010-10-04 20:39:20 +0200 | [diff] [blame] | 926 | if (s->check_data_len < global.tune.chksize) |
Willy Tarreau | 2c7ace0 | 2010-03-16 20:32:04 +0100 | [diff] [blame] | 927 | s->check_data[s->check_data_len] = '\0'; |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 928 | else { |
Willy Tarreau | 2c7ace0 | 2010-03-16 20:32:04 +0100 | [diff] [blame] | 929 | s->check_data[s->check_data_len - 1] = '\0'; |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 930 | done = 1; /* buffer full, don't wait for more data */ |
| 931 | } |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 932 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 933 | /* Run the checks... */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 934 | if (s->proxy->options & PR_O_HTTP_CHK) { |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 935 | if (!done && s->check_data_len < strlen("HTTP/1.0 000\r")) |
| 936 | goto wait_more_data; |
| 937 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 938 | /* Check if the server speaks HTTP 1.X */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 939 | if ((s->check_data_len < strlen("HTTP/1.0 000\r")) || |
| 940 | (memcmp(s->check_data, "HTTP/1.", 7) != 0 || |
| 941 | (*(s->check_data + 12) != ' ' && *(s->check_data + 12) != '\r')) || |
| 942 | !isdigit((unsigned char) *(s->check_data + 9)) || !isdigit((unsigned char) *(s->check_data + 10)) || |
| 943 | !isdigit((unsigned char) *(s->check_data + 11))) { |
| 944 | cut_crlf(s->check_data); |
| 945 | set_server_check_status(s, HCHK_STATUS_L7RSP, s->check_data); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 946 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 947 | goto out_wakeup; |
| 948 | } |
| 949 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 950 | s->check_code = str2uic(s->check_data + 9); |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 951 | desc = ltrim(s->check_data + 12, ' '); |
| 952 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 953 | if ((s->proxy->options & PR_O_DISABLE404) && |
| 954 | (s->state & SRV_RUNNING) && (s->check_code == 404)) { |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 955 | /* 404 may be accepted as "stopping" only if the server was up */ |
| 956 | cut_crlf(desc); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 957 | set_server_check_status(s, HCHK_STATUS_L7OKCD, desc); |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 958 | } |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 959 | else if (s->proxy->options2 & PR_O2_EXP_TYPE) { |
| 960 | /* Run content verification check... We know we have at least 13 chars */ |
| 961 | if (!httpchk_expect(s, done)) |
| 962 | goto wait_more_data; |
| 963 | } |
| 964 | /* check the reply : HTTP/1.X 2xx and 3xx are OK */ |
| 965 | else if (*(s->check_data + 9) == '2' || *(s->check_data + 9) == '3') { |
| 966 | cut_crlf(desc); |
| 967 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
| 968 | } |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 969 | else { |
| 970 | cut_crlf(desc); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 971 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 972 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 973 | } |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 974 | else if (s->proxy->options2 & PR_O2_SSL3_CHK) { |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 975 | if (!done && s->check_data_len < 5) |
| 976 | goto wait_more_data; |
| 977 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 978 | /* Check for SSLv3 alert or handshake */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 979 | if ((s->check_data_len >= 5) && (*s->check_data == 0x15 || *s->check_data == 0x16)) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 980 | set_server_check_status(s, HCHK_STATUS_L6OK, NULL); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 981 | else |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 982 | set_server_check_status(s, HCHK_STATUS_L6RSP, NULL); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 983 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 984 | else if (s->proxy->options & PR_O_SMTP_CHK) { |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 985 | if (!done && s->check_data_len < strlen("000\r")) |
| 986 | goto wait_more_data; |
| 987 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 988 | /* Check if the server speaks SMTP */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 989 | if ((s->check_data_len < strlen("000\r")) || |
| 990 | (*(s->check_data + 3) != ' ' && *(s->check_data + 3) != '\r') || |
| 991 | !isdigit((unsigned char) *s->check_data) || !isdigit((unsigned char) *(s->check_data + 1)) || |
| 992 | !isdigit((unsigned char) *(s->check_data + 2))) { |
| 993 | cut_crlf(s->check_data); |
| 994 | set_server_check_status(s, HCHK_STATUS_L7RSP, s->check_data); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 995 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 996 | goto out_wakeup; |
| 997 | } |
| 998 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 999 | s->check_code = str2uic(s->check_data); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1000 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 1001 | desc = ltrim(s->check_data + 3, ' '); |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1002 | cut_crlf(desc); |
| 1003 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1004 | /* Check for SMTP code 2xx (should be 250) */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 1005 | if (*s->check_data == '2') |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1006 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 1007 | else |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1008 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 1009 | } |
Rauf Kuliyev | 38b4156 | 2011-01-04 15:14:13 +0100 | [diff] [blame] | 1010 | else if (s->proxy->options2 & PR_O2_PGSQL_CHK) { |
| 1011 | if (!done && s->check_data_len < 9) |
| 1012 | goto wait_more_data; |
| 1013 | |
| 1014 | if (s->check_data[0] == 'R') { |
| 1015 | set_server_check_status(s, HCHK_STATUS_L7OKD, "PostgreSQL server is ok"); |
| 1016 | } |
| 1017 | else { |
| 1018 | if ((s->check_data[0] == 'E') && (s->check_data[5]!=0) && (s->check_data[6]!=0)) |
| 1019 | desc = &s->check_data[6]; |
| 1020 | else |
| 1021 | desc = "PostgreSQL unknown error"; |
| 1022 | |
| 1023 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
| 1024 | } |
| 1025 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 1026 | else if (s->proxy->options2 & PR_O2_MYSQL_CHK) { |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 1027 | if (!done && s->check_data_len < 5) |
| 1028 | goto wait_more_data; |
| 1029 | |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 1030 | if (s->proxy->check_len == 0) { // old mode |
| 1031 | if (*(s->check_data + 4) != '\xff') { |
| 1032 | /* We set the MySQL Version in description for information purpose |
| 1033 | * FIXME : it can be cool to use MySQL Version for other purpose, |
| 1034 | * like mark as down old MySQL server. |
| 1035 | */ |
| 1036 | if (s->check_data_len > 51) { |
| 1037 | desc = ltrim(s->check_data + 5, ' '); |
| 1038 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
| 1039 | } |
| 1040 | else { |
| 1041 | if (!done) |
| 1042 | goto wait_more_data; |
| 1043 | /* it seems we have a OK packet but without a valid length, |
| 1044 | * it must be a protocol error |
| 1045 | */ |
| 1046 | set_server_check_status(s, HCHK_STATUS_L7RSP, s->check_data); |
| 1047 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 1048 | } |
| 1049 | else { |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 1050 | /* An error message is attached in the Error packet */ |
| 1051 | desc = ltrim(s->check_data + 7, ' '); |
| 1052 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
| 1053 | } |
| 1054 | } else { |
| 1055 | unsigned int first_packet_len = ((unsigned int) *s->check_data) + |
| 1056 | (((unsigned int) *(s->check_data + 1)) << 8) + |
| 1057 | (((unsigned int) *(s->check_data + 2)) << 16); |
| 1058 | |
| 1059 | if (s->check_data_len == first_packet_len + 4) { |
| 1060 | /* MySQL Error packet always begin with field_count = 0xff */ |
| 1061 | if (*(s->check_data + 4) != '\xff') { |
| 1062 | /* We have only one MySQL packet and it is a Handshake Initialization packet |
| 1063 | * but we need to have a second packet to know if it is alright |
| 1064 | */ |
| 1065 | if (!done && s->check_data_len < first_packet_len + 5) |
| 1066 | goto wait_more_data; |
| 1067 | } |
| 1068 | else { |
| 1069 | /* We have only one packet and it is an Error packet, |
| 1070 | * an error message is attached, so we can display it |
| 1071 | */ |
| 1072 | desc = &s->check_data[7]; |
| 1073 | //Warning("onlyoneERR: %s\n", desc); |
| 1074 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
| 1075 | } |
| 1076 | } else if (s->check_data_len > first_packet_len + 4) { |
| 1077 | unsigned int second_packet_len = ((unsigned int) *(s->check_data + first_packet_len + 4)) + |
| 1078 | (((unsigned int) *(s->check_data + first_packet_len + 5)) << 8) + |
| 1079 | (((unsigned int) *(s->check_data + first_packet_len + 6)) << 16); |
| 1080 | |
| 1081 | if (s->check_data_len == first_packet_len + 4 + second_packet_len + 4 ) { |
| 1082 | /* We have 2 packets and that's good */ |
| 1083 | /* Check if the second packet is a MySQL Error packet or not */ |
| 1084 | if (*(s->check_data + first_packet_len + 8) != '\xff') { |
| 1085 | /* No error packet */ |
| 1086 | /* We set the MySQL Version in description for information purpose */ |
| 1087 | desc = &s->check_data[5]; |
| 1088 | //Warning("2packetOK: %s\n", desc); |
| 1089 | set_server_check_status(s, HCHK_STATUS_L7OKD, desc); |
| 1090 | } |
| 1091 | else { |
| 1092 | /* An error message is attached in the Error packet |
| 1093 | * so we can display it ! :) |
| 1094 | */ |
| 1095 | desc = &s->check_data[first_packet_len+11]; |
| 1096 | //Warning("2packetERR: %s\n", desc); |
| 1097 | set_server_check_status(s, HCHK_STATUS_L7STS, desc); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | else { |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 1102 | if (!done) |
| 1103 | goto wait_more_data; |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 1104 | /* it seems we have a Handshake Initialization packet but without a valid length, |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 1105 | * it must be a protocol error |
| 1106 | */ |
Hervé COMMOWICK | 8776f1b | 2010-10-18 15:58:36 +0200 | [diff] [blame] | 1107 | desc = &s->check_data[5]; |
| 1108 | //Warning("protoerr: %s\n", desc); |
| 1109 | set_server_check_status(s, HCHK_STATUS_L7RSP, desc); |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 1110 | } |
| 1111 | } |
Hervé COMMOWICK | 698ae00 | 2010-01-12 09:25:13 +0100 | [diff] [blame] | 1112 | } |
Gabor Lekeny | b4c81e4 | 2010-09-29 18:17:05 +0200 | [diff] [blame] | 1113 | else if (s->proxy->options2 & PR_O2_LDAP_CHK) { |
| 1114 | if (!done && s->check_data_len < 14) |
| 1115 | goto wait_more_data; |
| 1116 | |
| 1117 | /* Check if the server speaks LDAP (ASN.1/BER) |
| 1118 | * http://en.wikipedia.org/wiki/Basic_Encoding_Rules |
| 1119 | * http://tools.ietf.org/html/rfc4511 |
| 1120 | */ |
| 1121 | |
| 1122 | /* http://tools.ietf.org/html/rfc4511#section-4.1.1 |
| 1123 | * LDAPMessage: 0x30: SEQUENCE |
| 1124 | */ |
| 1125 | if ((s->check_data_len < 14) || (*(s->check_data) != '\x30')) { |
| 1126 | set_server_check_status(s, HCHK_STATUS_L7RSP, "Not LDAPv3 protocol"); |
| 1127 | } |
| 1128 | else { |
| 1129 | /* size of LDAPMessage */ |
| 1130 | msglen = (*(s->check_data + 1) & 0x80) ? (*(s->check_data + 1) & 0x7f) : 0; |
| 1131 | |
| 1132 | /* http://tools.ietf.org/html/rfc4511#section-4.2.2 |
| 1133 | * messageID: 0x02 0x01 0x01: INTEGER 1 |
| 1134 | * protocolOp: 0x61: bindResponse |
| 1135 | */ |
| 1136 | if ((msglen > 2) || |
| 1137 | (memcmp(s->check_data + 2 + msglen, "\x02\x01\x01\x61", 4) != 0)) { |
| 1138 | set_server_check_status(s, HCHK_STATUS_L7RSP, "Not LDAPv3 protocol"); |
| 1139 | |
| 1140 | goto out_wakeup; |
| 1141 | } |
| 1142 | |
| 1143 | /* size of bindResponse */ |
| 1144 | msglen += (*(s->check_data + msglen + 6) & 0x80) ? (*(s->check_data + msglen + 6) & 0x7f) : 0; |
| 1145 | |
| 1146 | /* http://tools.ietf.org/html/rfc4511#section-4.1.9 |
| 1147 | * ldapResult: 0x0a 0x01: ENUMERATION |
| 1148 | */ |
| 1149 | if ((msglen > 4) || |
| 1150 | (memcmp(s->check_data + 7 + msglen, "\x0a\x01", 2) != 0)) { |
| 1151 | set_server_check_status(s, HCHK_STATUS_L7RSP, "Not LDAPv3 protocol"); |
| 1152 | |
| 1153 | goto out_wakeup; |
| 1154 | } |
| 1155 | |
| 1156 | /* http://tools.ietf.org/html/rfc4511#section-4.1.9 |
| 1157 | * resultCode |
| 1158 | */ |
| 1159 | s->check_code = *(s->check_data + msglen + 9); |
| 1160 | if (s->check_code) { |
| 1161 | set_server_check_status(s, HCHK_STATUS_L7STS, "See RFC: http://tools.ietf.org/html/rfc4511#section-4.1.9"); |
| 1162 | } else { |
| 1163 | set_server_check_status(s, HCHK_STATUS_L7OKD, "Success"); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1167 | else { |
| 1168 | /* other checks are valid if the connection succeeded anyway */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1169 | set_server_check_status(s, HCHK_STATUS_L4OK, NULL); |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 1170 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 1171 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1172 | out_wakeup: |
| 1173 | if (s->result & SRV_CHK_ERROR) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1174 | fdtab[fd].state = FD_STERROR; |
| 1175 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 1176 | /* Reset the check buffer... */ |
| 1177 | *s->check_data = '\0'; |
| 1178 | s->check_data_len = 0; |
| 1179 | |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 1180 | /* Close the connection... */ |
| 1181 | shutdown(fd, SHUT_RDWR); |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1182 | EV_FD_CLR(fd, DIR_RD); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 1183 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 1184 | fdtab[fd].ev &= ~FD_POLL_IN; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 1185 | return 1; |
Willy Tarreau | 0393818 | 2010-03-17 21:52:07 +0100 | [diff] [blame] | 1186 | |
| 1187 | wait_more_data: |
| 1188 | fdtab[fd].ev &= ~FD_POLL_IN; |
| 1189 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /* |
| 1193 | * manages a server health-check. Returns |
| 1194 | * the time the task accepts to wait, or TIME_ETERNITY for infinity. |
| 1195 | */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1196 | struct task *process_chk(struct task *t) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1197 | { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 1198 | int attempts = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1199 | struct server *s = t->context; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1200 | struct sockaddr_storage sa; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1201 | int fd; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1202 | int rv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1203 | |
| 1204 | //fprintf(stderr, "process_chk: task=%p\n", t); |
| 1205 | |
| 1206 | new_chk: |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 1207 | if (attempts++ > 0) { |
| 1208 | /* we always fail to create a server, let's stop insisting... */ |
| 1209 | while (tick_is_expired(t->expire, now_ms)) |
| 1210 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
| 1211 | return t; |
| 1212 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1213 | fd = s->curfd; |
| 1214 | if (fd < 0) { /* no check currently running */ |
| 1215 | //fprintf(stderr, "process_chk: 2\n"); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1216 | if (!tick_is_expired(t->expire, now_ms)) /* woke up too early */ |
| 1217 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1218 | |
| 1219 | /* we don't send any health-checks when the proxy is stopped or when |
| 1220 | * the server should not be checked. |
| 1221 | */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 1222 | if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED || (s->state & SRV_MAINTAIN)) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1223 | while (tick_is_expired(t->expire, now_ms)) |
| 1224 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1225 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | /* we'll initiate a new check */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1229 | set_server_check_status(s, HCHK_STATUS_START, NULL); |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1230 | if ((fd = socket(s->addr.ss_family, SOCK_STREAM, IPPROTO_TCP)) != -1) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1231 | if ((fd < global.maxsock) && |
| 1232 | (fcntl(fd, F_SETFL, O_NONBLOCK) != -1) && |
| 1233 | (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)) != -1)) { |
| 1234 | //fprintf(stderr, "process_chk: 3\n"); |
| 1235 | |
Willy Tarreau | 9edd161 | 2007-10-18 18:07:48 +0200 | [diff] [blame] | 1236 | if (s->proxy->options & PR_O_TCP_NOLING) { |
| 1237 | /* We don't want to useless data */ |
| 1238 | setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
| 1239 | } |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1240 | |
| 1241 | if (is_addr(&s->check_addr)) |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1242 | /* we'll connect to the check addr specified on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1243 | sa = s->check_addr; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1244 | else |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1245 | /* we'll connect to the addr on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 1246 | sa = s->addr; |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 1247 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1248 | switch (s->check_addr.ss_family) { |
| 1249 | case AF_INET: |
| 1250 | /* we'll connect to the check port on the server */ |
| 1251 | ((struct sockaddr_in *)&sa)->sin_port = htons(s->check_port); |
| 1252 | break; |
| 1253 | case AF_INET6: |
| 1254 | /* we'll connect to the check port on the server */ |
| 1255 | ((struct sockaddr_in6 *)&sa)->sin6_port = htons(s->check_port); |
| 1256 | break; |
| 1257 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1258 | /* allow specific binding : |
| 1259 | * - server-specific at first |
| 1260 | * - proxy-specific next |
| 1261 | */ |
| 1262 | if (s->state & SRV_BIND_SRC) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1263 | struct sockaddr_storage *remote = NULL; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1264 | int ret, flags = 0; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1265 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1266 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1267 | if ((s->state & SRV_TPROXY_MASK) == SRV_TPROXY_ADDR) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1268 | remote = &s->tproxy_addr; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1269 | flags = 3; |
| 1270 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1271 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 1272 | #ifdef SO_BINDTODEVICE |
| 1273 | /* Note: this might fail if not CAP_NET_RAW */ |
| 1274 | if (s->iface_name) |
| 1275 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 1276 | s->iface_name, s->iface_len + 1); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 1277 | #endif |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1278 | if (s->sport_range) { |
| 1279 | int bind_attempts = 10; /* should be more than enough to find a spare port */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1280 | struct sockaddr_storage src; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1281 | |
| 1282 | ret = 1; |
| 1283 | src = s->source_addr; |
| 1284 | |
| 1285 | do { |
| 1286 | /* note: in case of retry, we may have to release a previously |
| 1287 | * allocated port, hence this loop's construct. |
| 1288 | */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1289 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 1290 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1291 | |
| 1292 | if (!bind_attempts) |
| 1293 | break; |
| 1294 | bind_attempts--; |
| 1295 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1296 | fdinfo[fd].local_port = port_range_alloc_port(s->sport_range); |
| 1297 | if (!fdinfo[fd].local_port) |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1298 | break; |
| 1299 | |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1300 | fdinfo[fd].port_range = s->sport_range; |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1301 | |
| 1302 | switch (src.ss_family) { |
| 1303 | case AF_INET: |
| 1304 | ((struct sockaddr_in *)&src)->sin_port = htons(fdinfo[fd].local_port); |
| 1305 | break; |
| 1306 | case AF_INET6: |
| 1307 | ((struct sockaddr_in6 *)&src)->sin6_port = htons(fdinfo[fd].local_port); |
| 1308 | break; |
| 1309 | } |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1310 | |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1311 | ret = tcp_bind_socket(fd, flags, &src, remote); |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1312 | } while (ret != 0); /* binding NOK */ |
| 1313 | } |
| 1314 | else { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1315 | ret = tcp_bind_socket(fd, flags, &s->source_addr, remote); |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 1316 | } |
| 1317 | |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1318 | if (ret) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1319 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1320 | switch (ret) { |
| 1321 | case 1: |
| 1322 | Alert("Cannot bind to source address before connect() for server %s/%s. Aborting.\n", |
| 1323 | s->proxy->id, s->id); |
| 1324 | break; |
| 1325 | case 2: |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1326 | Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n", |
| 1327 | s->proxy->id, s->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1328 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1329 | } |
| 1330 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1331 | } |
| 1332 | else if (s->proxy->options & PR_O_BIND_SRC) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1333 | struct sockaddr_storage *remote = NULL; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1334 | int ret, flags = 0; |
| 1335 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1336 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1337 | if ((s->proxy->options & PR_O_TPXY_MASK) == PR_O_TPXY_ADDR) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1338 | remote = &s->proxy->tproxy_addr; |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1339 | flags = 3; |
| 1340 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 1341 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1342 | #ifdef SO_BINDTODEVICE |
| 1343 | /* Note: this might fail if not CAP_NET_RAW */ |
| 1344 | if (s->proxy->iface_name) |
| 1345 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 1346 | s->proxy->iface_name, s->proxy->iface_len + 1); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 1347 | #endif |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 1348 | ret = tcp_bind_socket(fd, flags, &s->proxy->source_addr, remote); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1349 | if (ret) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1350 | set_server_check_status(s, HCHK_STATUS_SOCKERR, NULL); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1351 | switch (ret) { |
| 1352 | case 1: |
| 1353 | Alert("Cannot bind to source address before connect() for %s '%s'. Aborting.\n", |
| 1354 | proxy_type_str(s->proxy), s->proxy->id); |
| 1355 | break; |
| 1356 | case 2: |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 1357 | Alert("Cannot bind to tproxy source address before connect() for %s '%s'. Aborting.\n", |
| 1358 | proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 1359 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 1360 | } |
| 1361 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1362 | } |
| 1363 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1364 | if (s->result == SRV_CHK_UNKNOWN) { |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 1365 | #if defined(TCP_QUICKACK) |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 1366 | /* disabling tcp quick ack now allows |
| 1367 | * the request to leave the machine with |
| 1368 | * the first ACK. |
| 1369 | */ |
| 1370 | if (s->proxy->options2 & PR_O2_SMARTCON) |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 1371 | setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (char *) &zero, sizeof(zero)); |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 1372 | #endif |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 1373 | if ((connect(fd, (struct sockaddr *)&sa, get_addr_len(&sa)) != -1) || (errno == EINPROGRESS)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1374 | /* OK, connection in progress or established */ |
| 1375 | |
| 1376 | //fprintf(stderr, "process_chk: 4\n"); |
| 1377 | |
| 1378 | s->curfd = fd; /* that's how we know a test is in progress ;-) */ |
Willy Tarreau | 7a96648 | 2007-04-15 10:58:02 +0200 | [diff] [blame] | 1379 | fd_insert(fd); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1380 | fdtab[fd].owner = t; |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 1381 | fdtab[fd].cb[DIR_RD].f = &event_srv_chk_r; |
| 1382 | fdtab[fd].cb[DIR_RD].b = NULL; |
| 1383 | fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w; |
| 1384 | fdtab[fd].cb[DIR_WR].b = NULL; |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1385 | fdinfo[fd].peeraddr = (struct sockaddr *)&sa; |
Willy Tarreau | 1b4b7ce | 2011-04-05 16:56:50 +0200 | [diff] [blame] | 1386 | fdinfo[fd].peerlen = get_addr_len(&sa); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1387 | fdtab[fd].state = FD_STCONN; /* connection in progress */ |
Willy Tarreau | fb14edc | 2009-06-14 15:24:37 +0200 | [diff] [blame] | 1388 | fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1389 | EV_FD_SET(fd, DIR_WR); /* for connect status */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1390 | #ifdef DEBUG_FULL |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 1391 | assert (!EV_FD_ISSET(fd, DIR_RD)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1392 | #endif |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1393 | //fprintf(stderr, "process_chk: 4+, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 1394 | /* we allow up to min(inter, timeout.connect) for a connection |
| 1395 | * to establish but only when timeout.check is set |
| 1396 | * as it may be to short for a full check otherwise |
| 1397 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1398 | t->expire = tick_add(now_ms, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1399 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1400 | if (s->proxy->timeout.check && s->proxy->timeout.connect) { |
| 1401 | int t_con = tick_add(now_ms, s->proxy->timeout.connect); |
| 1402 | t->expire = tick_first(t->expire, t_con); |
Willy Tarreau | 6054819 | 2008-02-17 11:34:10 +0100 | [diff] [blame] | 1403 | } |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1404 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1405 | } |
| 1406 | else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) { |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 1407 | /* a real error */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1408 | |
| 1409 | switch (errno) { |
| 1410 | /* FIXME: is it possible to get ECONNREFUSED/ENETUNREACH with O_NONBLOCK? */ |
| 1411 | case ECONNREFUSED: |
| 1412 | case ENETUNREACH: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1413 | set_server_check_status(s, HCHK_STATUS_L4CON, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1414 | break; |
| 1415 | |
| 1416 | default: |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1417 | set_server_check_status(s, HCHK_STATUS_SOCKERR, strerror(errno)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1418 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | } |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 1422 | port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port); |
| 1423 | fdinfo[fd].port_range = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1424 | close(fd); /* socket creation error */ |
| 1425 | } |
Willy Tarreau | d11ad78 | 2011-03-09 20:38:33 +0100 | [diff] [blame] | 1426 | else |
| 1427 | set_server_check_status(s, HCHK_STATUS_SOCKERR, strerror(errno)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1428 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1429 | if (s->result == SRV_CHK_UNKNOWN) { /* nothing done */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1430 | //fprintf(stderr, "process_chk: 6\n"); |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1431 | while (tick_is_expired(t->expire, now_ms)) |
| 1432 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1433 | goto new_chk; /* may be we should initialize a new check */ |
| 1434 | } |
| 1435 | |
| 1436 | /* here, we have seen a failure */ |
| 1437 | if (s->health > s->rise) { |
| 1438 | s->health--; /* still good */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1439 | s->counters.failed_checks++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1440 | } |
| 1441 | else |
| 1442 | set_server_down(s); |
| 1443 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1444 | //fprintf(stderr, "process_chk: 7, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 1445 | /* we allow up to min(inter, timeout.connect) for a connection |
| 1446 | * to establish but only when timeout.check is set |
| 1447 | * as it may be to short for a full check otherwise |
| 1448 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1449 | while (tick_is_expired(t->expire, now_ms)) { |
| 1450 | int t_con; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1451 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1452 | t_con = tick_add(t->expire, s->proxy->timeout.connect); |
| 1453 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1454 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1455 | if (s->proxy->timeout.check) |
| 1456 | t->expire = tick_first(t->expire, t_con); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1457 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1458 | goto new_chk; |
| 1459 | } |
| 1460 | else { |
| 1461 | //fprintf(stderr, "process_chk: 8\n"); |
| 1462 | /* there was a test running */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1463 | if ((s->result & (SRV_CHK_ERROR|SRV_CHK_RUNNING)) == SRV_CHK_RUNNING) { /* good server detected */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1464 | //fprintf(stderr, "process_chk: 9\n"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1465 | |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 1466 | if (s->state & SRV_WARMINGUP) { |
| 1467 | if (now.tv_sec < s->last_change || now.tv_sec >= s->last_change + s->slowstart) { |
| 1468 | s->state &= ~SRV_WARMINGUP; |
| 1469 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) |
| 1470 | s->eweight = s->uweight * BE_WEIGHT_SCALE; |
| 1471 | if (s->proxy->lbprm.update_server_eweight) |
| 1472 | s->proxy->lbprm.update_server_eweight(s); |
| 1473 | } |
| 1474 | else if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 1475 | /* for dynamic algorithms, let's update the weight */ |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 1476 | s->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - s->last_change) + |
| 1477 | s->slowstart - 1) / s->slowstart; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 1478 | s->eweight *= s->uweight; |
| 1479 | if (s->proxy->lbprm.update_server_eweight) |
| 1480 | s->proxy->lbprm.update_server_eweight(s); |
| 1481 | } |
| 1482 | /* probably that we can refill this server with a bit more connections */ |
| 1483 | check_for_pending(s); |
| 1484 | } |
| 1485 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1486 | /* we may have to add/remove this server from the LB group */ |
| 1487 | if ((s->state & SRV_RUNNING) && (s->proxy->options & PR_O_DISABLE404)) { |
| 1488 | if ((s->state & SRV_GOINGDOWN) && |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1489 | ((s->result & (SRV_CHK_RUNNING|SRV_CHK_DISABLE)) == SRV_CHK_RUNNING)) |
| 1490 | set_server_enabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1491 | else if (!(s->state & SRV_GOINGDOWN) && |
| 1492 | ((s->result & (SRV_CHK_RUNNING | SRV_CHK_DISABLE)) == |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1493 | (SRV_CHK_RUNNING | SRV_CHK_DISABLE))) |
| 1494 | set_server_disabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1497 | if (s->health < s->rise + s->fall - 1) { |
| 1498 | s->health++; /* was bad, stays for a while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1499 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 1500 | set_server_up(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1501 | } |
| 1502 | s->curfd = -1; /* no check running anymore */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1503 | fd_delete(fd); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1504 | |
| 1505 | rv = 0; |
| 1506 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1507 | rv = srv_getinter(s) * global.spread_checks / 100; |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1508 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1509 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, srv_getinter(s), global.spread_checks, rv); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 1510 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1511 | t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(s) + rv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1512 | goto new_chk; |
| 1513 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1514 | else if ((s->result & SRV_CHK_ERROR) || tick_is_expired(t->expire, now_ms)) { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1515 | if (!(s->result & SRV_CHK_ERROR)) { |
| 1516 | if (!EV_FD_ISSET(fd, DIR_RD)) { |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1517 | set_server_check_status(s, HCHK_STATUS_L4TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1518 | } else { |
Willy Tarreau | 07a5490 | 2010-03-29 18:33:29 +0200 | [diff] [blame] | 1519 | if (s->proxy->options2 & PR_O2_SSL3_CHK) |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1520 | set_server_check_status(s, HCHK_STATUS_L6TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1521 | else /* HTTP, SMTP */ |
Krzysztof Piotr Oledzki | f7089f5 | 2009-10-10 21:06:49 +0200 | [diff] [blame] | 1522 | set_server_check_status(s, HCHK_STATUS_L7TOUT, NULL); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1526 | //fprintf(stderr, "process_chk: 10\n"); |
| 1527 | /* failure or timeout detected */ |
| 1528 | if (s->health > s->rise) { |
| 1529 | s->health--; /* still good */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1530 | s->counters.failed_checks++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1531 | } |
| 1532 | else |
| 1533 | set_server_down(s); |
| 1534 | s->curfd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1535 | fd_delete(fd); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1536 | |
| 1537 | rv = 0; |
| 1538 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1539 | rv = srv_getinter(s) * global.spread_checks / 100; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1540 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1541 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, srv_getinter(s), global.spread_checks, rv); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1542 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1543 | t->expire = tick_add(now_ms, MS_TO_TICKS(srv_getinter(s) + rv)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1544 | goto new_chk; |
| 1545 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1546 | /* if result is unknown and there's no timeout, we have to wait again */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1547 | } |
| 1548 | //fprintf(stderr, "process_chk: 11\n"); |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 1549 | s->result = SRV_CHK_UNKNOWN; |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1550 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1551 | } |
| 1552 | |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1553 | /* |
| 1554 | * Start health-check. |
| 1555 | * Returns 0 if OK, -1 if error, and prints the error in this case. |
| 1556 | */ |
| 1557 | int start_checks() { |
| 1558 | |
| 1559 | struct proxy *px; |
| 1560 | struct server *s; |
| 1561 | struct task *t; |
| 1562 | int nbchk=0, mininter=0, srvpos=0; |
| 1563 | |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 1564 | /* 1- count the checkers to run simultaneously. |
| 1565 | * We also determine the minimum interval among all of those which |
| 1566 | * have an interval larger than SRV_CHK_INTER_THRES. This interval |
| 1567 | * will be used to spread their start-up date. Those which have |
| 1568 | * a shorter interval will start independantly and will not dictate |
| 1569 | * too short an interval for all others. |
| 1570 | */ |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1571 | for (px = proxy; px; px = px->next) { |
| 1572 | for (s = px->srv; s; s = s->next) { |
| 1573 | if (!(s->state & SRV_CHECKED)) |
| 1574 | continue; |
| 1575 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 1576 | if ((srv_getinter(s) >= SRV_CHK_INTER_THRES) && |
| 1577 | (!mininter || mininter > srv_getinter(s))) |
| 1578 | mininter = srv_getinter(s); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1579 | |
| 1580 | nbchk++; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | if (!nbchk) |
| 1585 | return 0; |
| 1586 | |
| 1587 | srand((unsigned)time(NULL)); |
| 1588 | |
| 1589 | /* |
| 1590 | * 2- start them as far as possible from each others. For this, we will |
| 1591 | * start them after their interval set to the min interval divided by |
| 1592 | * the number of servers, weighted by the server's position in the list. |
| 1593 | */ |
| 1594 | for (px = proxy; px; px = px->next) { |
| 1595 | for (s = px->srv; s; s = s->next) { |
| 1596 | if (!(s->state & SRV_CHECKED)) |
| 1597 | continue; |
| 1598 | |
Willy Tarreau | a461318 | 2009-03-21 18:13:21 +0100 | [diff] [blame] | 1599 | if ((t = task_new()) == NULL) { |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1600 | Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); |
| 1601 | return -1; |
| 1602 | } |
| 1603 | |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 1604 | s->check = t; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1605 | t->process = process_chk; |
| 1606 | t->context = s; |
| 1607 | |
| 1608 | /* check this every ms */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 1609 | t->expire = tick_add(now_ms, |
| 1610 | MS_TO_TICKS(((mininter && mininter >= srv_getinter(s)) ? |
| 1611 | mininter : srv_getinter(s)) * srvpos / nbchk)); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1612 | s->check_start = now; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 1613 | task_queue(t); |
| 1614 | |
| 1615 | srvpos++; |
| 1616 | } |
| 1617 | } |
| 1618 | return 0; |
| 1619 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1620 | |
| 1621 | /* |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 1622 | * Perform content verification check on data in s->check_data buffer. |
| 1623 | * The buffer MUST be terminated by a null byte before calling this function. |
| 1624 | * Sets server status appropriately. The caller is responsible for ensuring |
| 1625 | * that the buffer contains at least 13 characters. If <done> is zero, we may |
| 1626 | * return 0 to indicate that data is required to decide of a match. |
| 1627 | */ |
| 1628 | static int httpchk_expect(struct server *s, int done) |
| 1629 | { |
| 1630 | static char status_msg[] = "HTTP status check returned code <000>"; |
| 1631 | char status_code[] = "000"; |
| 1632 | char *contentptr; |
| 1633 | int crlf; |
| 1634 | int ret; |
| 1635 | |
| 1636 | switch (s->proxy->options2 & PR_O2_EXP_TYPE) { |
| 1637 | case PR_O2_EXP_STS: |
| 1638 | case PR_O2_EXP_RSTS: |
| 1639 | memcpy(status_code, s->check_data + 9, 3); |
| 1640 | memcpy(status_msg + strlen(status_msg) - 4, s->check_data + 9, 3); |
| 1641 | |
| 1642 | if ((s->proxy->options2 & PR_O2_EXP_TYPE) == PR_O2_EXP_STS) |
| 1643 | ret = strncmp(s->proxy->expect_str, status_code, 3) == 0; |
| 1644 | else |
| 1645 | ret = regexec(s->proxy->expect_regex, status_code, MAX_MATCH, pmatch, 0) == 0; |
| 1646 | |
| 1647 | /* we necessarily have the response, so there are no partial failures */ |
| 1648 | if (s->proxy->options2 & PR_O2_EXP_INV) |
| 1649 | ret = !ret; |
| 1650 | |
| 1651 | set_server_check_status(s, ret ? HCHK_STATUS_L7OKD : HCHK_STATUS_L7STS, status_msg); |
| 1652 | break; |
| 1653 | |
| 1654 | case PR_O2_EXP_STR: |
| 1655 | case PR_O2_EXP_RSTR: |
| 1656 | /* very simple response parser: ignore CR and only count consecutive LFs, |
| 1657 | * stop with contentptr pointing to first char after the double CRLF or |
| 1658 | * to '\0' if crlf < 2. |
| 1659 | */ |
| 1660 | crlf = 0; |
| 1661 | for (contentptr = s->check_data; *contentptr; contentptr++) { |
| 1662 | if (crlf >= 2) |
| 1663 | break; |
| 1664 | if (*contentptr == '\r') |
| 1665 | continue; |
| 1666 | else if (*contentptr == '\n') |
| 1667 | crlf++; |
| 1668 | else |
| 1669 | crlf = 0; |
| 1670 | } |
| 1671 | |
| 1672 | /* Check that response contains a body... */ |
| 1673 | if (crlf < 2) { |
| 1674 | if (!done) |
| 1675 | return 0; |
| 1676 | |
| 1677 | set_server_check_status(s, HCHK_STATUS_L7RSP, |
| 1678 | "HTTP content check could not find a response body"); |
| 1679 | return 1; |
| 1680 | } |
| 1681 | |
| 1682 | /* Check that response body is not empty... */ |
| 1683 | if (*contentptr == '\0') { |
Willy Tarreau | a164fb5 | 2011-04-13 09:32:41 +0200 | [diff] [blame] | 1684 | if (!done) |
| 1685 | return 0; |
| 1686 | |
Willy Tarreau | bd74154 | 2010-03-16 18:46:54 +0100 | [diff] [blame] | 1687 | set_server_check_status(s, HCHK_STATUS_L7RSP, |
| 1688 | "HTTP content check found empty response body"); |
| 1689 | return 1; |
| 1690 | } |
| 1691 | |
| 1692 | /* Check the response content against the supplied string |
| 1693 | * or regex... */ |
| 1694 | if ((s->proxy->options2 & PR_O2_EXP_TYPE) == PR_O2_EXP_STR) |
| 1695 | ret = strstr(contentptr, s->proxy->expect_str) != NULL; |
| 1696 | else |
| 1697 | ret = regexec(s->proxy->expect_regex, contentptr, MAX_MATCH, pmatch, 0) == 0; |
| 1698 | |
| 1699 | /* if we don't match, we may need to wait more */ |
| 1700 | if (!ret && !done) |
| 1701 | return 0; |
| 1702 | |
| 1703 | if (ret) { |
| 1704 | /* content matched */ |
| 1705 | if (s->proxy->options2 & PR_O2_EXP_INV) |
| 1706 | set_server_check_status(s, HCHK_STATUS_L7RSP, |
| 1707 | "HTTP check matched unwanted content"); |
| 1708 | else |
| 1709 | set_server_check_status(s, HCHK_STATUS_L7OKD, |
| 1710 | "HTTP content check matched"); |
| 1711 | } |
| 1712 | else { |
| 1713 | if (s->proxy->options2 & PR_O2_EXP_INV) |
| 1714 | set_server_check_status(s, HCHK_STATUS_L7OKD, |
| 1715 | "HTTP check did not match unwanted content"); |
| 1716 | else |
| 1717 | set_server_check_status(s, HCHK_STATUS_L7RSP, |
| 1718 | "HTTP content check did not match"); |
| 1719 | } |
| 1720 | break; |
| 1721 | } |
| 1722 | return 1; |
| 1723 | } |
| 1724 | |
| 1725 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1726 | * Local variables: |
| 1727 | * c-indent-level: 8 |
| 1728 | * c-basic-offset: 8 |
| 1729 | * End: |
| 1730 | */ |