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 | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5 | * Copyright 2007-2008 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> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 18 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 19 | #include <string.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 20 | #include <time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | #include <sys/socket.h> |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 23 | #include <sys/types.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | #include <netinet/in.h> |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 25 | #include <netinet/tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 26 | #include <arpa/inet.h> |
| 27 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/mini-clist.h> |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 31 | #include <common/standard.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 32 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
| 34 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | |
| 36 | #include <proto/backend.h> |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 37 | #include <proto/buffers.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | #include <proto/fd.h> |
| 39 | #include <proto/log.h> |
| 40 | #include <proto/queue.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 41 | #include <proto/port_range.h> |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 42 | #include <proto/proto_http.h> |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 43 | #include <proto/proto_tcp.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 44 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | #include <proto/server.h> |
| 46 | #include <proto/task.h> |
| 47 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 48 | /* sends a log message when a backend goes down, and also sets last |
| 49 | * change date. |
| 50 | */ |
| 51 | static void set_backend_down(struct proxy *be) |
| 52 | { |
| 53 | be->last_change = now.tv_sec; |
| 54 | be->down_trans++; |
| 55 | |
| 56 | Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id); |
| 57 | send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id); |
| 58 | } |
| 59 | |
| 60 | /* Redistribute pending connections when a server goes down. The number of |
| 61 | * connections redistributed is returned. |
| 62 | */ |
| 63 | static int redistribute_pending(struct server *s) |
| 64 | { |
| 65 | struct pendconn *pc, *pc_bck, *pc_end; |
| 66 | int xferred = 0; |
| 67 | |
| 68 | FOREACH_ITEM_SAFE(pc, pc_bck, &s->pendconns, pc_end, struct pendconn *, list) { |
| 69 | struct session *sess = pc->sess; |
| 70 | if (sess->be->options & PR_O_REDISP) { |
| 71 | /* The REDISP option was specified. We will ignore |
| 72 | * cookie and force to balance or use the dispatcher. |
| 73 | */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 74 | |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 75 | /* it's left to the dispatcher to choose a server */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 76 | sess->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 77 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 78 | pendconn_free(pc); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 79 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 80 | xferred++; |
| 81 | } |
| 82 | } |
| 83 | return xferred; |
| 84 | } |
| 85 | |
| 86 | /* Check for pending connections at the backend, and assign some of them to |
| 87 | * the server coming up. The server's weight is checked before being assigned |
| 88 | * connections it may not be able to handle. The total number of transferred |
| 89 | * connections is returned. |
| 90 | */ |
| 91 | static int check_for_pending(struct server *s) |
| 92 | { |
| 93 | int xferred; |
| 94 | |
| 95 | if (!s->eweight) |
| 96 | return 0; |
| 97 | |
| 98 | for (xferred = 0; !s->maxconn || xferred < srv_dynamic_maxconn(s); xferred++) { |
| 99 | struct session *sess; |
| 100 | struct pendconn *p; |
| 101 | |
| 102 | p = pendconn_from_px(s->proxy); |
| 103 | if (!p) |
| 104 | break; |
| 105 | p->sess->srv = s; |
| 106 | sess = p->sess; |
| 107 | pendconn_free(p); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 108 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 109 | } |
| 110 | return xferred; |
| 111 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 112 | |
| 113 | /* Sets server <s> down, notifies by all available means, recounts the |
| 114 | * remaining servers on the proxy and transfers queued sessions whenever |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 115 | * possible to other servers. It automatically recomputes the number of |
| 116 | * servers, but not the map. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 117 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 118 | static void set_server_down(struct server *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 119 | { |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 120 | struct server *srv; |
| 121 | struct chunk msg; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 122 | int xferred; |
| 123 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 124 | if (s->health == s->rise || s->tracked) { |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 125 | int srv_was_paused = s->state & SRV_GOINGDOWN; |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 126 | |
| 127 | s->last_change = now.tv_sec; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 128 | s->state &= ~(SRV_RUNNING | SRV_GOINGDOWN); |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 129 | s->proxy->lbprm.set_server_status_down(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 130 | |
| 131 | /* we might have sessions queued on this server and waiting for |
| 132 | * a connection. Those which are redispatchable will be queued |
| 133 | * to another server or to the proxy itself. |
| 134 | */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 135 | xferred = redistribute_pending(s); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 136 | |
| 137 | msg.len = 0; |
| 138 | msg.str = trash; |
| 139 | |
| 140 | chunk_printf(&msg, sizeof(trash), |
| 141 | "%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "", |
| 142 | s->proxy->id, s->id); |
| 143 | |
| 144 | if (s->tracked) |
| 145 | chunk_printf(&msg, sizeof(trash), " via %s/%s", |
| 146 | s->tracked->proxy->id, s->tracked->id); |
| 147 | |
| 148 | chunk_printf(&msg, sizeof(trash), ". %d active and %d backup servers left.%s" |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 149 | " %d sessions active, %d requeued, %d remaining in queue.\n", |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 150 | s->proxy->srv_act, s->proxy->srv_bck, |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 151 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 152 | s->cur_sess, xferred, s->nbpend); |
| 153 | |
| 154 | Warning("%s", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 155 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 156 | /* we don't send an alert if the server was previously paused */ |
| 157 | if (srv_was_paused) |
| 158 | send_log(s->proxy, LOG_NOTICE, "%s", trash); |
| 159 | else |
| 160 | send_log(s->proxy, LOG_ALERT, "%s", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 161 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 162 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) |
| 163 | set_backend_down(s->proxy); |
| 164 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 165 | s->down_trans++; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 166 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 167 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 168 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 169 | set_server_down(srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 170 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 171 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 172 | s->health = 0; /* failure */ |
| 173 | } |
| 174 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 175 | static void set_server_up(struct server *s) { |
| 176 | |
| 177 | struct server *srv; |
| 178 | struct chunk msg; |
| 179 | int xferred; |
| 180 | |
| 181 | if (s->health == s->rise || s->tracked) { |
| 182 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 183 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 184 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 185 | s->proxy->last_change = now.tv_sec; |
| 186 | } |
| 187 | |
| 188 | if (s->last_change < now.tv_sec) // ignore negative times |
| 189 | s->down_time += now.tv_sec - s->last_change; |
| 190 | |
| 191 | s->last_change = now.tv_sec; |
| 192 | s->state |= SRV_RUNNING; |
| 193 | |
| 194 | if (s->slowstart > 0) { |
| 195 | s->state |= SRV_WARMINGUP; |
| 196 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 197 | /* For dynamic algorithms, start at the first step of the weight, |
| 198 | * without multiplying by BE_WEIGHT_SCALE. |
| 199 | */ |
| 200 | s->eweight = s->uweight; |
| 201 | if (s->proxy->lbprm.update_server_eweight) |
| 202 | s->proxy->lbprm.update_server_eweight(s); |
| 203 | } |
| 204 | } |
| 205 | s->proxy->lbprm.set_server_status_up(s); |
| 206 | |
| 207 | /* check if we can handle some connections queued at the proxy. We |
| 208 | * will take as many as we can handle. |
| 209 | */ |
| 210 | xferred = check_for_pending(s); |
| 211 | |
| 212 | msg.len = 0; |
| 213 | msg.str = trash; |
| 214 | |
| 215 | chunk_printf(&msg, sizeof(trash), |
| 216 | "%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "", |
| 217 | s->proxy->id, s->id); |
| 218 | |
| 219 | if (s->tracked) |
| 220 | chunk_printf(&msg, sizeof(trash), " via %s/%s", |
| 221 | s->tracked->proxy->id, s->tracked->id); |
| 222 | |
| 223 | chunk_printf(&msg, sizeof(trash), ". %d active and %d backup servers online.%s" |
| 224 | " %d sessions requeued, %d total in queue.\n", |
| 225 | s->proxy->srv_act, s->proxy->srv_bck, |
| 226 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 227 | xferred, s->nbpend); |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 228 | |
| 229 | Warning("%s", trash); |
| 230 | send_log(s->proxy, LOG_NOTICE, "%s", trash); |
| 231 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 232 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 233 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 234 | set_server_up(srv); |
| 235 | } |
| 236 | |
| 237 | if (s->health >= s->rise) |
| 238 | s->health = s->rise + s->fall - 1; /* OK now */ |
| 239 | |
| 240 | } |
| 241 | |
| 242 | static void set_server_disabled(struct server *s) { |
| 243 | |
| 244 | struct server *srv; |
| 245 | struct chunk msg; |
| 246 | int xferred; |
| 247 | |
| 248 | s->state |= SRV_GOINGDOWN; |
| 249 | s->proxy->lbprm.set_server_status_down(s); |
| 250 | |
| 251 | /* we might have sessions queued on this server and waiting for |
| 252 | * a connection. Those which are redispatchable will be queued |
| 253 | * to another server or to the proxy itself. |
| 254 | */ |
| 255 | xferred = redistribute_pending(s); |
| 256 | |
| 257 | msg.len = 0; |
| 258 | msg.str = trash; |
| 259 | |
| 260 | chunk_printf(&msg, sizeof(trash), |
| 261 | "Load-balancing on %sServer %s/%s is disabled", |
| 262 | s->state & SRV_BACKUP ? "Backup " : "", |
| 263 | s->proxy->id, s->id); |
| 264 | |
| 265 | if (s->tracked) |
| 266 | chunk_printf(&msg, sizeof(trash), " via %s/%s", |
| 267 | s->tracked->proxy->id, s->tracked->id); |
| 268 | |
| 269 | |
| 270 | chunk_printf(&msg, sizeof(trash),". %d active and %d backup servers online.%s" |
| 271 | " %d sessions requeued, %d total in queue.\n", |
| 272 | s->proxy->srv_act, s->proxy->srv_bck, |
| 273 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 274 | xferred, s->nbpend); |
| 275 | |
| 276 | Warning("%s", trash); |
| 277 | |
| 278 | send_log(s->proxy, LOG_NOTICE, "%s", trash); |
| 279 | |
| 280 | if (!s->proxy->srv_bck && !s->proxy->srv_act) |
| 281 | set_backend_down(s->proxy); |
| 282 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 283 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 284 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 285 | set_server_disabled(srv); |
| 286 | } |
| 287 | |
| 288 | static void set_server_enabled(struct server *s) { |
| 289 | |
| 290 | struct server *srv; |
| 291 | struct chunk msg; |
| 292 | int xferred; |
| 293 | |
| 294 | s->state &= ~SRV_GOINGDOWN; |
| 295 | s->proxy->lbprm.set_server_status_up(s); |
| 296 | |
| 297 | /* check if we can handle some connections queued at the proxy. We |
| 298 | * will take as many as we can handle. |
| 299 | */ |
| 300 | xferred = check_for_pending(s); |
| 301 | |
| 302 | msg.len = 0; |
| 303 | msg.str = trash; |
| 304 | |
| 305 | chunk_printf(&msg, sizeof(trash), |
| 306 | "Load-balancing on %sServer %s/%s is enabled again", |
| 307 | s->state & SRV_BACKUP ? "Backup " : "", |
| 308 | s->proxy->id, s->id); |
| 309 | |
| 310 | if (s->tracked) |
| 311 | chunk_printf(&msg, sizeof(trash), " via %s/%s", |
| 312 | s->tracked->proxy->id, s->tracked->id); |
| 313 | |
| 314 | chunk_printf(&msg, sizeof(trash), ". %d active and %d backup servers online.%s" |
| 315 | " %d sessions requeued, %d total in queue.\n", |
| 316 | s->proxy->srv_act, s->proxy->srv_bck, |
| 317 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 318 | xferred, s->nbpend); |
| 319 | |
| 320 | Warning("%s", trash); |
| 321 | send_log(s->proxy, LOG_NOTICE, "%s", trash); |
| 322 | |
Krzysztof Piotr Oledzki | f39c71c | 2009-01-30 00:52:49 +0100 | [diff] [blame] | 323 | if (s->state & SRV_CHECKED) |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 324 | for(srv = s->tracknext; srv; srv = srv->tracknext) |
| 325 | set_server_enabled(srv); |
| 326 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * This function is used only for server health-checks. It handles |
| 330 | * the connection acknowledgement. If the proxy requires HTTP health-checks, |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 331 | * it sends the request. In other cases, it fills s->result with SRV_CHK_*. |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 332 | * The function itself returns 0 if it needs some polling before being called |
| 333 | * again, otherwise 1. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 334 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 335 | static int event_srv_chk_w(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 336 | { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 337 | __label__ out_wakeup, out_nowake, out_poll, out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 338 | struct task *t = fdtab[fd].owner; |
| 339 | struct server *s = t->context; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 340 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 341 | //fprintf(stderr, "event_srv_chk_w, state=%ld\n", unlikely(fdtab[fd].state)); |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 342 | if (unlikely(fdtab[fd].state == FD_STERROR || (fdtab[fd].ev & FD_POLL_ERR))) |
| 343 | goto out_error; |
| 344 | |
| 345 | /* here, we know that the connection is established */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 346 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 347 | if (!(s->result & SRV_CHK_ERROR)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 348 | /* 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] | 349 | if ((s->proxy->options & PR_O_HTTP_CHK) || |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 350 | (s->proxy->options & PR_O_SSL3_CHK) || |
| 351 | (s->proxy->options & PR_O_SMTP_CHK)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 352 | int ret; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 353 | /* 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] | 354 | * so we'll send the request, and won't wake the checker up now. |
| 355 | */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 356 | |
| 357 | if (s->proxy->options & PR_O_SSL3_CHK) { |
| 358 | /* SSL requires that we put Unix time in the request */ |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 359 | int gmt_time = htonl(date.tv_sec); |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 360 | memcpy(s->proxy->check_req + 11, &gmt_time, 4); |
| 361 | } |
| 362 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 363 | ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT | MSG_NOSIGNAL); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 364 | if (ret == s->proxy->check_len) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 365 | /* we allow up to <timeout.check> if nonzero for a responce */ |
Willy Tarreau | 7cd9d94 | 2008-12-21 13:00:41 +0100 | [diff] [blame] | 366 | if (s->proxy->timeout.check) |
| 367 | t->expire = tick_add_ifset(now_ms, s->proxy->timeout.check); |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 368 | EV_FD_SET(fd, DIR_RD); /* prepare for reading reply */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 369 | goto out_nowake; |
| 370 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 371 | else if (ret == 0 || errno == EAGAIN) |
| 372 | goto out_poll; |
| 373 | else |
| 374 | goto out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 375 | } |
| 376 | else { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 377 | /* We have no data to send to check the connection, and |
| 378 | * getsockopt() will not inform us whether the connection |
| 379 | * is still pending. So we'll reuse connect() to check the |
| 380 | * state of the socket. This has the advantage of givig us |
| 381 | * the following info : |
| 382 | * - error |
| 383 | * - connecting (EALREADY, EINPROGRESS) |
| 384 | * - connected (EISCONN, 0) |
| 385 | */ |
| 386 | |
| 387 | struct sockaddr_in sa; |
| 388 | |
| 389 | sa = (s->check_addr.sin_addr.s_addr) ? s->check_addr : s->addr; |
| 390 | sa.sin_port = htons(s->check_port); |
| 391 | |
| 392 | if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == 0) |
| 393 | errno = 0; |
| 394 | |
| 395 | if (errno == EALREADY || errno == EINPROGRESS) |
| 396 | goto out_poll; |
| 397 | |
| 398 | if (errno && errno != EISCONN) |
| 399 | goto out_error; |
| 400 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 401 | /* good TCP connection is enough */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 402 | s->result |= SRV_CHK_RUNNING; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 403 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 404 | } |
| 405 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 406 | out_wakeup: |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 407 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 408 | out_nowake: |
| 409 | EV_FD_CLR(fd, DIR_WR); /* nothing more to write */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 410 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 411 | return 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 412 | out_poll: |
| 413 | /* The connection is still pending. We'll have to poll it |
| 414 | * before attempting to go further. */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 415 | fdtab[fd].ev &= ~FD_POLL_OUT; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 416 | return 0; |
| 417 | out_error: |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 418 | s->result |= SRV_CHK_ERROR; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 419 | fdtab[fd].state = FD_STERROR; |
| 420 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
| 424 | /* |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 425 | * This function is used only for server health-checks. It handles the server's |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 426 | * reply to an HTTP request or SSL HELLO. It sets s->result to SRV_CHK_RUNNING |
| 427 | * if an HTTP server replies HTTP 2xx or 3xx (valid responses), if an SMTP |
| 428 | * server returns 2xx, or if an SSL server returns at least 5 bytes in response |
| 429 | * to an SSL HELLO (the principle is that this is enough to distinguish between |
| 430 | * an SSL server and a pure TCP relay). All other cases will set s->result to |
| 431 | * SRV_CHK_ERROR. The function returns 0 if it needs to be called again after |
| 432 | * some polling, otherwise non-zero.. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 433 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 434 | static int event_srv_chk_r(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 435 | { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 436 | __label__ out_wakeup; |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 437 | int len; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 438 | struct task *t = fdtab[fd].owner; |
| 439 | struct server *s = t->context; |
| 440 | int skerr; |
| 441 | socklen_t lskerr = sizeof(skerr); |
| 442 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 443 | len = -1; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 444 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 445 | if (unlikely((s->result & SRV_CHK_ERROR) || |
| 446 | (fdtab[fd].state == FD_STERROR) || |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 447 | (fdtab[fd].ev & FD_POLL_ERR) || |
| 448 | (getsockopt(fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == -1) || |
| 449 | (skerr != 0))) { |
| 450 | /* in case of TCP only, this tells us if the connection failed */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 451 | s->result |= SRV_CHK_ERROR; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 452 | goto out_wakeup; |
| 453 | } |
| 454 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 455 | /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available |
| 456 | * but the connection was closed on the remote end. Fortunately, recv still |
| 457 | * works correctly and we don't need to do the getsockopt() on linux. |
| 458 | */ |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 459 | len = recv(fd, trash, sizeof(trash), MSG_NOSIGNAL); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 460 | if (unlikely(len < 0 && errno == EAGAIN)) { |
| 461 | /* we want some polling to happen first */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 462 | fdtab[fd].ev &= ~FD_POLL_IN; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 463 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 466 | /* Note: the response will only be accepted if read at once */ |
| 467 | if (s->proxy->options & PR_O_HTTP_CHK) { |
| 468 | /* Check if the server speaks HTTP 1.X */ |
| 469 | if ((len < strlen("HTTP/1.0 000\r")) || |
| 470 | (memcmp(trash, "HTTP/1.", 7) != 0)) { |
| 471 | s->result |= SRV_CHK_ERROR; |
| 472 | goto out_wakeup; |
| 473 | } |
| 474 | |
| 475 | /* check the reply : HTTP/1.X 2xx and 3xx are OK */ |
| 476 | if (trash[9] == '2' || trash[9] == '3') |
| 477 | s->result |= SRV_CHK_RUNNING; |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 478 | else if ((s->proxy->options & PR_O_DISABLE404) && |
| 479 | (s->state & SRV_RUNNING) && |
| 480 | (memcmp(&trash[9], "404", 3) == 0)) { |
| 481 | /* 404 may be accepted as "stopping" only if the server was up */ |
| 482 | s->result |= SRV_CHK_RUNNING | SRV_CHK_DISABLE; |
| 483 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 484 | else |
| 485 | s->result |= SRV_CHK_ERROR; |
| 486 | } |
| 487 | else if (s->proxy->options & PR_O_SSL3_CHK) { |
| 488 | /* Check for SSLv3 alert or handshake */ |
| 489 | if ((len >= 5) && (trash[0] == 0x15 || trash[0] == 0x16)) |
| 490 | s->result |= SRV_CHK_RUNNING; |
| 491 | else |
| 492 | s->result |= SRV_CHK_ERROR; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 493 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 494 | else if (s->proxy->options & PR_O_SMTP_CHK) { |
| 495 | /* Check for SMTP code 2xx (should be 250) */ |
| 496 | if ((len >= 3) && (trash[0] == '2')) |
| 497 | s->result |= SRV_CHK_RUNNING; |
| 498 | else |
| 499 | s->result |= SRV_CHK_ERROR; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 500 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 501 | else { |
| 502 | /* other checks are valid if the connection succeeded anyway */ |
| 503 | s->result |= SRV_CHK_RUNNING; |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 504 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 505 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 506 | out_wakeup: |
| 507 | if (s->result & SRV_CHK_ERROR) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 508 | fdtab[fd].state = FD_STERROR; |
| 509 | |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 510 | EV_FD_CLR(fd, DIR_RD); |
Willy Tarreau | fdccded | 2008-08-29 18:19:04 +0200 | [diff] [blame] | 511 | task_wakeup(t, TASK_WOKEN_IO); |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 512 | fdtab[fd].ev &= ~FD_POLL_IN; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 513 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /* |
| 517 | * manages a server health-check. Returns |
| 518 | * the time the task accepts to wait, or TIME_ETERNITY for infinity. |
| 519 | */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 520 | struct task *process_chk(struct task *t) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 521 | { |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 522 | int attempts = 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 523 | struct server *s = t->context; |
| 524 | struct sockaddr_in sa; |
| 525 | int fd; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 526 | int rv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 527 | |
| 528 | //fprintf(stderr, "process_chk: task=%p\n", t); |
| 529 | |
| 530 | new_chk: |
Willy Tarreau | e383880 | 2009-03-21 18:58:32 +0100 | [diff] [blame] | 531 | if (attempts++ > 0) { |
| 532 | /* we always fail to create a server, let's stop insisting... */ |
| 533 | while (tick_is_expired(t->expire, now_ms)) |
| 534 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
| 535 | return t; |
| 536 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 537 | fd = s->curfd; |
| 538 | if (fd < 0) { /* no check currently running */ |
| 539 | //fprintf(stderr, "process_chk: 2\n"); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 540 | if (!tick_is_expired(t->expire, now_ms)) /* woke up too early */ |
| 541 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 542 | |
| 543 | /* we don't send any health-checks when the proxy is stopped or when |
| 544 | * the server should not be checked. |
| 545 | */ |
| 546 | if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED) { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 547 | while (tick_is_expired(t->expire, now_ms)) |
| 548 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 549 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | /* we'll initiate a new check */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 553 | s->result = SRV_CHK_UNKNOWN; /* no result yet */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 554 | if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) { |
| 555 | if ((fd < global.maxsock) && |
| 556 | (fcntl(fd, F_SETFL, O_NONBLOCK) != -1) && |
| 557 | (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)) != -1)) { |
| 558 | //fprintf(stderr, "process_chk: 3\n"); |
| 559 | |
Willy Tarreau | 9edd161 | 2007-10-18 18:07:48 +0200 | [diff] [blame] | 560 | if (s->proxy->options & PR_O_TCP_NOLING) { |
| 561 | /* We don't want to useless data */ |
| 562 | setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
| 563 | } |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 564 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 565 | if (s->check_addr.sin_addr.s_addr) |
| 566 | /* we'll connect to the check addr specified on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 567 | sa = s->check_addr; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 568 | else |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 569 | /* we'll connect to the addr on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 570 | sa = s->addr; |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 571 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 572 | /* we'll connect to the check port on the server */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 573 | sa.sin_port = htons(s->check_port); |
| 574 | |
| 575 | /* allow specific binding : |
| 576 | * - server-specific at first |
| 577 | * - proxy-specific next |
| 578 | */ |
| 579 | if (s->state & SRV_BIND_SRC) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 580 | struct sockaddr_in *remote = NULL; |
| 581 | int ret, flags = 0; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 582 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 583 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 584 | if ((s->state & SRV_TPROXY_MASK) == SRV_TPROXY_ADDR) { |
| 585 | remote = (struct sockaddr_in *)&s->tproxy_addr; |
| 586 | flags = 3; |
| 587 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 588 | #endif |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 589 | #ifdef SO_BINDTODEVICE |
| 590 | /* Note: this might fail if not CAP_NET_RAW */ |
| 591 | if (s->iface_name) |
| 592 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 593 | s->iface_name, s->iface_len + 1); |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 594 | #endif |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 595 | if (s->sport_range) { |
| 596 | int bind_attempts = 10; /* should be more than enough to find a spare port */ |
| 597 | struct sockaddr_in src; |
| 598 | |
| 599 | ret = 1; |
| 600 | src = s->source_addr; |
| 601 | |
| 602 | do { |
| 603 | /* note: in case of retry, we may have to release a previously |
| 604 | * allocated port, hence this loop's construct. |
| 605 | */ |
| 606 | port_range_release_port(fdtab[fd].port_range, fdtab[fd].local_port); |
| 607 | fdtab[fd].port_range = NULL; |
| 608 | |
| 609 | if (!bind_attempts) |
| 610 | break; |
| 611 | bind_attempts--; |
| 612 | |
| 613 | fdtab[fd].local_port = port_range_alloc_port(s->sport_range); |
| 614 | if (!fdtab[fd].local_port) |
| 615 | break; |
| 616 | |
| 617 | fdtab[fd].port_range = s->sport_range; |
| 618 | src.sin_port = htons(fdtab[fd].local_port); |
| 619 | |
| 620 | ret = tcpv4_bind_socket(fd, flags, &src, remote); |
| 621 | } while (ret != 0); /* binding NOK */ |
| 622 | } |
| 623 | else { |
| 624 | ret = tcpv4_bind_socket(fd, flags, &s->source_addr, remote); |
| 625 | } |
| 626 | |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 627 | if (ret) { |
| 628 | s->result |= SRV_CHK_ERROR; |
| 629 | switch (ret) { |
| 630 | case 1: |
| 631 | Alert("Cannot bind to source address before connect() for server %s/%s. Aborting.\n", |
| 632 | s->proxy->id, s->id); |
| 633 | break; |
| 634 | case 2: |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 635 | Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n", |
| 636 | s->proxy->id, s->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 637 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 638 | } |
| 639 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 640 | } |
| 641 | else if (s->proxy->options & PR_O_BIND_SRC) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 642 | struct sockaddr_in *remote = NULL; |
| 643 | int ret, flags = 0; |
| 644 | |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 645 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 646 | if ((s->proxy->options & PR_O_TPXY_MASK) == PR_O_TPXY_ADDR) { |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 647 | remote = (struct sockaddr_in *)&s->proxy->tproxy_addr; |
| 648 | flags = 3; |
| 649 | } |
Willy Tarreau | cf1d572 | 2008-02-14 20:28:18 +0100 | [diff] [blame] | 650 | #endif |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 651 | #ifdef SO_BINDTODEVICE |
| 652 | /* Note: this might fail if not CAP_NET_RAW */ |
| 653 | if (s->proxy->iface_name) |
| 654 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, |
Willy Tarreau | 604e830 | 2009-03-06 00:48:23 +0100 | [diff] [blame] | 655 | s->proxy->iface_name, s->proxy->iface_len + 1); |
Willy Tarreau | d53f96b | 2009-02-04 18:46:54 +0100 | [diff] [blame] | 656 | #endif |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 657 | ret = tcpv4_bind_socket(fd, flags, &s->proxy->source_addr, remote); |
| 658 | if (ret) { |
| 659 | s->result |= SRV_CHK_ERROR; |
| 660 | switch (ret) { |
| 661 | case 1: |
| 662 | Alert("Cannot bind to source address before connect() for %s '%s'. Aborting.\n", |
| 663 | proxy_type_str(s->proxy), s->proxy->id); |
| 664 | break; |
| 665 | case 2: |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 666 | Alert("Cannot bind to tproxy source address before connect() for %s '%s'. Aborting.\n", |
| 667 | proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | e8c66af | 2008-01-13 18:40:14 +0100 | [diff] [blame] | 668 | break; |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 669 | } |
| 670 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 671 | } |
| 672 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 673 | if (s->result == SRV_CHK_UNKNOWN) { |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 674 | #if defined(TCP_QUICKACK) |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 675 | /* disabling tcp quick ack now allows |
| 676 | * the request to leave the machine with |
| 677 | * the first ACK. |
| 678 | */ |
| 679 | if (s->proxy->options2 & PR_O2_SMARTCON) |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 680 | setsockopt(fd, IPPROTO_TCP, TCP_QUICKACK, (char *) &zero, sizeof(zero)); |
Willy Tarreau | 1274bc4 | 2009-07-15 07:16:31 +0200 | [diff] [blame] | 681 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 682 | if ((connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != -1) || (errno == EINPROGRESS)) { |
| 683 | /* OK, connection in progress or established */ |
| 684 | |
| 685 | //fprintf(stderr, "process_chk: 4\n"); |
| 686 | |
| 687 | 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] | 688 | fd_insert(fd); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 689 | fdtab[fd].owner = t; |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 690 | fdtab[fd].cb[DIR_RD].f = &event_srv_chk_r; |
| 691 | fdtab[fd].cb[DIR_RD].b = NULL; |
| 692 | fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w; |
| 693 | fdtab[fd].cb[DIR_WR].b = NULL; |
Willy Tarreau | e94ebd0 | 2007-10-09 17:14:37 +0200 | [diff] [blame] | 694 | fdtab[fd].peeraddr = (struct sockaddr *)&sa; |
| 695 | fdtab[fd].peerlen = sizeof(sa); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 696 | fdtab[fd].state = FD_STCONN; /* connection in progress */ |
Willy Tarreau | fb14edc | 2009-06-14 15:24:37 +0200 | [diff] [blame] | 697 | fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 698 | EV_FD_SET(fd, DIR_WR); /* for connect status */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 699 | #ifdef DEBUG_FULL |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 700 | assert (!EV_FD_ISSET(fd, DIR_RD)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 701 | #endif |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 702 | //fprintf(stderr, "process_chk: 4+, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 703 | /* we allow up to min(inter, timeout.connect) for a connection |
| 704 | * to establish but only when timeout.check is set |
| 705 | * as it may be to short for a full check otherwise |
| 706 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 707 | t->expire = tick_add(now_ms, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 708 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 709 | if (s->proxy->timeout.check && s->proxy->timeout.connect) { |
| 710 | int t_con = tick_add(now_ms, s->proxy->timeout.connect); |
| 711 | t->expire = tick_first(t->expire, t_con); |
Willy Tarreau | 6054819 | 2008-02-17 11:34:10 +0100 | [diff] [blame] | 712 | } |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 713 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 714 | } |
| 715 | else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) { |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 716 | s->result |= SRV_CHK_ERROR; /* a real error */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | } |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 720 | port_range_release_port(fdtab[fd].port_range, fdtab[fd].local_port); |
| 721 | fdtab[fd].port_range = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 722 | close(fd); /* socket creation error */ |
| 723 | } |
| 724 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 725 | if (s->result == SRV_CHK_UNKNOWN) { /* nothing done */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 726 | //fprintf(stderr, "process_chk: 6\n"); |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 727 | while (tick_is_expired(t->expire, now_ms)) |
| 728 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 729 | goto new_chk; /* may be we should initialize a new check */ |
| 730 | } |
| 731 | |
| 732 | /* here, we have seen a failure */ |
| 733 | if (s->health > s->rise) { |
| 734 | s->health--; /* still good */ |
| 735 | s->failed_checks++; |
| 736 | } |
| 737 | else |
| 738 | set_server_down(s); |
| 739 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 740 | //fprintf(stderr, "process_chk: 7, %lu\n", __tv_to_ms(&s->proxy->timeout.connect)); |
| 741 | /* we allow up to min(inter, timeout.connect) for a connection |
| 742 | * to establish but only when timeout.check is set |
| 743 | * as it may be to short for a full check otherwise |
| 744 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 745 | while (tick_is_expired(t->expire, now_ms)) { |
| 746 | int t_con; |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 747 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 748 | t_con = tick_add(t->expire, s->proxy->timeout.connect); |
| 749 | t->expire = tick_add(t->expire, MS_TO_TICKS(s->inter)); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 750 | |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 751 | if (s->proxy->timeout.check) |
| 752 | t->expire = tick_first(t->expire, t_con); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 753 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 754 | goto new_chk; |
| 755 | } |
| 756 | else { |
| 757 | //fprintf(stderr, "process_chk: 8\n"); |
| 758 | /* there was a test running */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 759 | 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] | 760 | //fprintf(stderr, "process_chk: 9\n"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 761 | |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 762 | if (s->state & SRV_WARMINGUP) { |
| 763 | if (now.tv_sec < s->last_change || now.tv_sec >= s->last_change + s->slowstart) { |
| 764 | s->state &= ~SRV_WARMINGUP; |
| 765 | if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) |
| 766 | s->eweight = s->uweight * BE_WEIGHT_SCALE; |
| 767 | if (s->proxy->lbprm.update_server_eweight) |
| 768 | s->proxy->lbprm.update_server_eweight(s); |
| 769 | } |
| 770 | else if (s->proxy->lbprm.algo & BE_LB_PROP_DYN) { |
| 771 | /* for dynamic algorithms, let's update the weight */ |
Willy Tarreau | 5542af6 | 2007-12-03 02:04:00 +0100 | [diff] [blame] | 772 | s->eweight = (BE_WEIGHT_SCALE * (now.tv_sec - s->last_change) + |
| 773 | s->slowstart - 1) / s->slowstart; |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 774 | s->eweight *= s->uweight; |
| 775 | if (s->proxy->lbprm.update_server_eweight) |
| 776 | s->proxy->lbprm.update_server_eweight(s); |
| 777 | } |
| 778 | /* probably that we can refill this server with a bit more connections */ |
| 779 | check_for_pending(s); |
| 780 | } |
| 781 | |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 782 | /* we may have to add/remove this server from the LB group */ |
| 783 | if ((s->state & SRV_RUNNING) && (s->proxy->options & PR_O_DISABLE404)) { |
| 784 | if ((s->state & SRV_GOINGDOWN) && |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 785 | ((s->result & (SRV_CHK_RUNNING|SRV_CHK_DISABLE)) == SRV_CHK_RUNNING)) |
| 786 | set_server_enabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 787 | else if (!(s->state & SRV_GOINGDOWN) && |
| 788 | ((s->result & (SRV_CHK_RUNNING | SRV_CHK_DISABLE)) == |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 789 | (SRV_CHK_RUNNING | SRV_CHK_DISABLE))) |
| 790 | set_server_disabled(s); |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 793 | if (s->health < s->rise + s->fall - 1) { |
| 794 | s->health++; /* was bad, stays for a while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 795 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 796 | set_server_up(s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 797 | } |
| 798 | s->curfd = -1; /* no check running anymore */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 799 | fd_delete(fd); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 800 | |
| 801 | rv = 0; |
| 802 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 803 | rv = srv_getinter(s) * global.spread_checks / 100; |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 804 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 805 | //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] | 806 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 807 | 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] | 808 | goto new_chk; |
| 809 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 810 | else if ((s->result & SRV_CHK_ERROR) || tick_is_expired(t->expire, now_ms)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 811 | //fprintf(stderr, "process_chk: 10\n"); |
| 812 | /* failure or timeout detected */ |
| 813 | if (s->health > s->rise) { |
| 814 | s->health--; /* still good */ |
| 815 | s->failed_checks++; |
| 816 | } |
| 817 | else |
| 818 | set_server_down(s); |
| 819 | s->curfd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 820 | fd_delete(fd); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 821 | |
| 822 | rv = 0; |
| 823 | if (global.spread_checks > 0) { |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 824 | rv = srv_getinter(s) * global.spread_checks / 100; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 825 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 826 | //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] | 827 | } |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 828 | 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] | 829 | goto new_chk; |
| 830 | } |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 831 | /* 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] | 832 | } |
| 833 | //fprintf(stderr, "process_chk: 11\n"); |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 834 | s->result = SRV_CHK_UNKNOWN; |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 835 | return t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 836 | } |
| 837 | |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 838 | /* |
| 839 | * Start health-check. |
| 840 | * Returns 0 if OK, -1 if error, and prints the error in this case. |
| 841 | */ |
| 842 | int start_checks() { |
| 843 | |
| 844 | struct proxy *px; |
| 845 | struct server *s; |
| 846 | struct task *t; |
| 847 | int nbchk=0, mininter=0, srvpos=0; |
| 848 | |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 849 | /* 1- count the checkers to run simultaneously. |
| 850 | * We also determine the minimum interval among all of those which |
| 851 | * have an interval larger than SRV_CHK_INTER_THRES. This interval |
| 852 | * will be used to spread their start-up date. Those which have |
| 853 | * a shorter interval will start independantly and will not dictate |
| 854 | * too short an interval for all others. |
| 855 | */ |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 856 | for (px = proxy; px; px = px->next) { |
| 857 | for (s = px->srv; s; s = s->next) { |
| 858 | if (!(s->state & SRV_CHECKED)) |
| 859 | continue; |
| 860 | |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 861 | if ((srv_getinter(s) >= SRV_CHK_INTER_THRES) && |
| 862 | (!mininter || mininter > srv_getinter(s))) |
| 863 | mininter = srv_getinter(s); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 864 | |
| 865 | nbchk++; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | if (!nbchk) |
| 870 | return 0; |
| 871 | |
| 872 | srand((unsigned)time(NULL)); |
| 873 | |
| 874 | /* |
| 875 | * 2- start them as far as possible from each others. For this, we will |
| 876 | * start them after their interval set to the min interval divided by |
| 877 | * the number of servers, weighted by the server's position in the list. |
| 878 | */ |
| 879 | for (px = proxy; px; px = px->next) { |
| 880 | for (s = px->srv; s; s = s->next) { |
| 881 | if (!(s->state & SRV_CHECKED)) |
| 882 | continue; |
| 883 | |
Willy Tarreau | a461318 | 2009-03-21 18:13:21 +0100 | [diff] [blame] | 884 | if ((t = task_new()) == NULL) { |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 885 | Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); |
| 886 | return -1; |
| 887 | } |
| 888 | |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 889 | s->check = t; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 890 | t->process = process_chk; |
| 891 | t->context = s; |
| 892 | |
| 893 | /* check this every ms */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 894 | t->expire = tick_add(now_ms, |
| 895 | MS_TO_TICKS(((mininter && mininter >= srv_getinter(s)) ? |
| 896 | mininter : srv_getinter(s)) * srvpos / nbchk)); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 897 | task_queue(t); |
| 898 | |
| 899 | srvpos++; |
| 900 | } |
| 901 | } |
| 902 | return 0; |
| 903 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 904 | |
| 905 | /* |
| 906 | * Local variables: |
| 907 | * c-indent-level: 8 |
| 908 | * c-basic-offset: 8 |
| 909 | * End: |
| 910 | */ |