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