Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Health-checks functions. |
| 3 | * |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 4 | * Copyright 2000-2007 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <errno.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 16 | #include <stdlib.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 17 | #include <string.h> |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 18 | #include <time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 19 | #include <unistd.h> |
| 20 | #include <sys/socket.h> |
| 21 | #include <netinet/in.h> |
| 22 | #include <arpa/inet.h> |
| 23 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 24 | #include <common/compat.h> |
| 25 | #include <common/config.h> |
| 26 | #include <common/mini-clist.h> |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 27 | #include <common/standard.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 28 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 29 | |
| 30 | #include <types/global.h> |
| 31 | #include <types/polling.h> |
| 32 | #include <types/proxy.h> |
| 33 | #include <types/session.h> |
| 34 | |
| 35 | #include <proto/backend.h> |
| 36 | #include <proto/fd.h> |
| 37 | #include <proto/log.h> |
| 38 | #include <proto/queue.h> |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 39 | #include <proto/proto_http.h> |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 40 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | #include <proto/server.h> |
| 42 | #include <proto/task.h> |
| 43 | |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 44 | #ifdef CONFIG_HAP_CTTPROXY |
| 45 | #include <import/ip_tproxy.h> |
| 46 | #endif |
| 47 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 48 | |
| 49 | /* Sets server <s> down, notifies by all available means, recounts the |
| 50 | * remaining servers on the proxy and transfers queued sessions whenever |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 51 | * possible to other servers. It automatically recomputes the number of |
| 52 | * servers, but not the map. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 53 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 54 | static void set_server_down(struct server *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | { |
| 56 | struct pendconn *pc, *pc_bck, *pc_end; |
| 57 | struct session *sess; |
| 58 | int xferred; |
| 59 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 60 | if (s->health == s->rise) { |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 61 | |
| 62 | s->last_change = now.tv_sec; |
| 63 | s->state &= ~SRV_RUNNING; |
| 64 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 65 | recount_servers(s->proxy); |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 66 | s->proxy->map_state |= PR_MAP_RECALC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | |
| 68 | /* we might have sessions queued on this server and waiting for |
| 69 | * a connection. Those which are redispatchable will be queued |
| 70 | * to another server or to the proxy itself. |
| 71 | */ |
| 72 | xferred = 0; |
| 73 | FOREACH_ITEM_SAFE(pc, pc_bck, &s->pendconns, pc_end, struct pendconn *, list) { |
| 74 | sess = pc->sess; |
Willy Tarreau | e2e27a5 | 2007-04-01 00:01:37 +0200 | [diff] [blame] | 75 | if ((sess->be->options & PR_O_REDISP)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 76 | /* The REDISP option was specified. We will ignore |
| 77 | * cookie and force to balance or use the dispatcher. |
| 78 | */ |
| 79 | sess->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
| 80 | sess->srv = NULL; /* it's left to the dispatcher to choose a server */ |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 81 | http_flush_cookie_flags(&sess->txn); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 82 | pendconn_free(pc); |
Willy Tarreau | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 83 | task_wakeup(sess->task); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | xferred++; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | sprintf(trash, "%sServer %s/%s is DOWN. %d active and %d backup servers left.%s" |
| 89 | " %d sessions active, %d requeued, %d remaining in queue.\n", |
| 90 | s->state & SRV_BACKUP ? "Backup " : "", |
| 91 | s->proxy->id, s->id, s->proxy->srv_act, s->proxy->srv_bck, |
| 92 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 93 | s->cur_sess, xferred, s->nbpend); |
| 94 | |
| 95 | Warning("%s", trash); |
| 96 | send_log(s->proxy, LOG_ALERT, "%s", trash); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 97 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 98 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 99 | s->proxy->last_change = now.tv_sec; |
| 100 | s->proxy->down_trans++; |
| 101 | |
| 102 | Alert("%s '%s' has no server available!\n", proxy_type_str(s->proxy), s->proxy->id); |
| 103 | send_log(s->proxy, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 104 | } |
| 105 | s->down_trans++; |
| 106 | } |
| 107 | s->health = 0; /* failure */ |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /* |
| 112 | * This function is used only for server health-checks. It handles |
| 113 | * the connection acknowledgement. If the proxy requires HTTP health-checks, |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 114 | * it sends the request. In other cases, it returns 1 in s->result if the |
| 115 | * socket is OK, or -1 if an error occured. |
| 116 | * The function itself returns 0 if it needs some polling before being called |
| 117 | * again, otherwise 1. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 118 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 119 | static int event_srv_chk_w(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 120 | { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 121 | __label__ out_wakeup, out_nowake, out_poll, out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 122 | struct task *t = fdtab[fd].owner; |
| 123 | struct server *s = t->context; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 124 | |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 125 | if (unlikely(fdtab[fd].state == FD_STERROR || (fdtab[fd].ev & FD_POLL_ERR))) |
| 126 | goto out_error; |
| 127 | |
| 128 | /* here, we know that the connection is established */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 129 | |
| 130 | if (s->result != -1) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 131 | /* 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] | 132 | if ((s->proxy->options & PR_O_HTTP_CHK) || |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 133 | (s->proxy->options & PR_O_SSL3_CHK) || |
| 134 | (s->proxy->options & PR_O_SMTP_CHK)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 135 | int ret; |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 136 | /* 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] | 137 | * so we'll send the request, and won't wake the checker up now. |
| 138 | */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 139 | |
| 140 | if (s->proxy->options & PR_O_SSL3_CHK) { |
| 141 | /* SSL requires that we put Unix time in the request */ |
| 142 | int gmt_time = htonl(now.tv_sec); |
| 143 | memcpy(s->proxy->check_req + 11, &gmt_time, 4); |
| 144 | } |
| 145 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 146 | #ifndef MSG_NOSIGNAL |
| 147 | ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT); |
| 148 | #else |
| 149 | ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT | MSG_NOSIGNAL); |
| 150 | #endif |
| 151 | if (ret == s->proxy->check_len) { |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 152 | EV_FD_SET(fd, DIR_RD); /* prepare for reading reply */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 153 | goto out_nowake; |
| 154 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 155 | else if (ret == 0 || errno == EAGAIN) |
| 156 | goto out_poll; |
| 157 | else |
| 158 | goto out_error; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 159 | } |
| 160 | else { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 161 | /* We have no data to send to check the connection, and |
| 162 | * getsockopt() will not inform us whether the connection |
| 163 | * is still pending. So we'll reuse connect() to check the |
| 164 | * state of the socket. This has the advantage of givig us |
| 165 | * the following info : |
| 166 | * - error |
| 167 | * - connecting (EALREADY, EINPROGRESS) |
| 168 | * - connected (EISCONN, 0) |
| 169 | */ |
| 170 | |
| 171 | struct sockaddr_in sa; |
| 172 | |
| 173 | sa = (s->check_addr.sin_addr.s_addr) ? s->check_addr : s->addr; |
| 174 | sa.sin_port = htons(s->check_port); |
| 175 | |
| 176 | if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == 0) |
| 177 | errno = 0; |
| 178 | |
| 179 | if (errno == EALREADY || errno == EINPROGRESS) |
| 180 | goto out_poll; |
| 181 | |
| 182 | if (errno && errno != EISCONN) |
| 183 | goto out_error; |
| 184 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 185 | /* good TCP connection is enough */ |
| 186 | s->result = 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 187 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 188 | } |
| 189 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 190 | out_wakeup: |
Willy Tarreau | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 191 | task_wakeup(t); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 192 | out_nowake: |
| 193 | EV_FD_CLR(fd, DIR_WR); /* nothing more to write */ |
| 194 | fdtab[fd].ev &= ~FD_POLL_WR; |
| 195 | return 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 196 | out_poll: |
| 197 | /* The connection is still pending. We'll have to poll it |
| 198 | * before attempting to go further. */ |
| 199 | fdtab[fd].ev &= ~FD_POLL_WR; |
| 200 | return 0; |
| 201 | out_error: |
| 202 | s->result = -1; |
| 203 | fdtab[fd].state = FD_STERROR; |
| 204 | goto out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | |
| 208 | /* |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 209 | * This function is used only for server health-checks. It handles the server's |
| 210 | * reply to an HTTP request or SSL HELLO. It returns 1 in s->result if the |
| 211 | * server replies HTTP 2xx or 3xx (valid responses), or if it returns at least |
| 212 | * 5 bytes in response to SSL HELLO. The principle is that this is enough to |
| 213 | * distinguish between an SSL server and a pure TCP relay. All other cases will |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 214 | * return -1. The function returns 0 if it needs to be called again after some |
| 215 | * polling, otherwise non-zero.. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 217 | static int event_srv_chk_r(int fd) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 218 | { |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 219 | __label__ out_wakeup; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 220 | int len, result; |
| 221 | struct task *t = fdtab[fd].owner; |
| 222 | struct server *s = t->context; |
| 223 | int skerr; |
| 224 | socklen_t lskerr = sizeof(skerr); |
| 225 | |
| 226 | result = len = -1; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 227 | |
| 228 | if (unlikely(fdtab[fd].state == FD_STERROR || |
| 229 | (fdtab[fd].ev & FD_POLL_ERR) || |
| 230 | (getsockopt(fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr) == -1) || |
| 231 | (skerr != 0))) { |
| 232 | /* in case of TCP only, this tells us if the connection failed */ |
| 233 | s->result = -1; |
| 234 | fdtab[fd].state = FD_STERROR; |
| 235 | goto out_wakeup; |
| 236 | } |
| 237 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 238 | #ifndef MSG_NOSIGNAL |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 239 | len = recv(fd, trash, sizeof(trash), 0); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 240 | #else |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 241 | /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available |
| 242 | * but the connection was closed on the remote end. Fortunately, recv still |
| 243 | * works correctly and we don't need to do the getsockopt() on linux. |
| 244 | */ |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 245 | len = recv(fd, trash, sizeof(trash), MSG_NOSIGNAL); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 246 | #endif |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 247 | if (unlikely(len < 0 && errno == EAGAIN)) { |
| 248 | /* we want some polling to happen first */ |
| 249 | fdtab[fd].ev &= ~FD_POLL_RD; |
| 250 | return 0; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 253 | if ((s->proxy->options & PR_O_HTTP_CHK) && (len >= sizeof("HTTP/1.0 000")) && |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 254 | (memcmp(trash, "HTTP/1.", 7) == 0) && (trash[9] == '2' || trash[9] == '3')) { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 255 | /* HTTP/1.X 2xx or 3xx */ |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 256 | result = 1; |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 257 | } |
| 258 | else if ((s->proxy->options & PR_O_SSL3_CHK) && (len >= 5) && |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 259 | (trash[0] == 0x15 || trash[0] == 0x16)) { |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 260 | /* SSLv3 alert or handshake */ |
| 261 | result = 1; |
| 262 | } |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 263 | else if ((s->proxy->options & PR_O_SMTP_CHK) && (len >= 3) && |
Krzysztof Oledzki | 6b3f8b4 | 2007-10-11 18:41:08 +0200 | [diff] [blame] | 264 | (trash[0] == '2')) /* 2xx (should be 250) */ { |
Willy Tarreau | 2367790 | 2007-05-08 23:50:35 +0200 | [diff] [blame] | 265 | result = 1; |
| 266 | } |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 267 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 268 | if (result == -1) |
| 269 | fdtab[fd].state = FD_STERROR; |
| 270 | |
| 271 | if (s->result != -1) |
| 272 | s->result = result; |
| 273 | |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 274 | out_wakeup: |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 275 | EV_FD_CLR(fd, DIR_RD); |
Willy Tarreau | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 276 | task_wakeup(t); |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 277 | fdtab[fd].ev &= ~FD_POLL_RD; |
| 278 | return 1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* |
| 282 | * manages a server health-check. Returns |
| 283 | * the time the task accepts to wait, or TIME_ETERNITY for infinity. |
| 284 | */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 285 | void process_chk(struct task *t, struct timeval *next) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 286 | { |
Willy Tarreau | 7317eb5 | 2007-05-09 00:54:10 +0200 | [diff] [blame] | 287 | __label__ new_chk, out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 288 | struct server *s = t->context; |
| 289 | struct sockaddr_in sa; |
| 290 | int fd; |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 291 | int rv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 292 | |
| 293 | //fprintf(stderr, "process_chk: task=%p\n", t); |
| 294 | |
| 295 | new_chk: |
| 296 | fd = s->curfd; |
| 297 | if (fd < 0) { /* no check currently running */ |
| 298 | //fprintf(stderr, "process_chk: 2\n"); |
Willy Tarreau | a8b55e3 | 2007-05-13 16:08:19 +0200 | [diff] [blame] | 299 | if (!tv_isle(&t->expire, &now)) { /* not good time yet */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 300 | task_queue(t); /* restore t to its place in the task list */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 301 | *next = t->expire; |
Willy Tarreau | 7317eb5 | 2007-05-09 00:54:10 +0200 | [diff] [blame] | 302 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* we don't send any health-checks when the proxy is stopped or when |
| 306 | * the server should not be checked. |
| 307 | */ |
| 308 | if (!(s->state & SRV_CHECKED) || s->proxy->state == PR_STSTOPPED) { |
Willy Tarreau | a8b55e3 | 2007-05-13 16:08:19 +0200 | [diff] [blame] | 309 | while (tv_isle(&t->expire, &now)) |
Willy Tarreau | 42aae5c | 2007-04-29 17:43:56 +0200 | [diff] [blame] | 310 | tv_ms_add(&t->expire, &t->expire, s->inter); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 311 | task_queue(t); /* restore t to its place in the task list */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 312 | *next = t->expire; |
Willy Tarreau | 7317eb5 | 2007-05-09 00:54:10 +0200 | [diff] [blame] | 313 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* we'll initiate a new check */ |
| 317 | s->result = 0; /* no result yet */ |
| 318 | if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1) { |
| 319 | if ((fd < global.maxsock) && |
| 320 | (fcntl(fd, F_SETFL, O_NONBLOCK) != -1) && |
| 321 | (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one)) != -1)) { |
| 322 | //fprintf(stderr, "process_chk: 3\n"); |
| 323 | |
Willy Tarreau | 9edd161 | 2007-10-18 18:07:48 +0200 | [diff] [blame] | 324 | if (s->proxy->options & PR_O_TCP_NOLING) { |
| 325 | /* We don't want to useless data */ |
| 326 | setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
| 327 | } |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 328 | |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 329 | if (s->check_addr.sin_addr.s_addr) |
| 330 | /* we'll connect to the check addr specified on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 331 | sa = s->check_addr; |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 332 | else |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 333 | /* we'll connect to the addr on the server */ |
Willy Tarreau | 2ea3abb | 2007-03-25 16:45:16 +0200 | [diff] [blame] | 334 | sa = s->addr; |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 335 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 336 | /* we'll connect to the check port on the server */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 337 | sa.sin_port = htons(s->check_port); |
| 338 | |
| 339 | /* allow specific binding : |
| 340 | * - server-specific at first |
| 341 | * - proxy-specific next |
| 342 | */ |
| 343 | if (s->state & SRV_BIND_SRC) { |
| 344 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one)); |
| 345 | if (bind(fd, (struct sockaddr *)&s->source_addr, sizeof(s->source_addr)) == -1) { |
| 346 | Alert("Cannot bind to source address before connect() for server %s/%s. Aborting.\n", |
| 347 | s->proxy->id, s->id); |
| 348 | s->result = -1; |
| 349 | } |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 350 | #ifdef CONFIG_HAP_CTTPROXY |
| 351 | if ((s->state & SRV_TPROXY_MASK) == SRV_TPROXY_ADDR) { |
| 352 | struct in_tproxy itp1, itp2; |
| 353 | memset(&itp1, 0, sizeof(itp1)); |
| 354 | |
| 355 | itp1.op = TPROXY_ASSIGN; |
| 356 | itp1.v.addr.faddr = s->tproxy_addr.sin_addr; |
| 357 | itp1.v.addr.fport = s->tproxy_addr.sin_port; |
| 358 | |
| 359 | /* set connect flag on socket */ |
| 360 | itp2.op = TPROXY_FLAGS; |
| 361 | itp2.v.flags = ITP_CONNECT | ITP_ONCE; |
| 362 | |
| 363 | if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1 || |
| 364 | setsockopt(fd, SOL_IP, IP_TPROXY, &itp2, sizeof(itp2)) == -1) { |
| 365 | Alert("Cannot bind to tproxy source address before connect() for server %s/%s. Aborting.\n", |
| 366 | s->proxy->id, s->id); |
| 367 | s->result = -1; |
| 368 | } |
| 369 | } |
| 370 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 371 | } |
| 372 | else if (s->proxy->options & PR_O_BIND_SRC) { |
| 373 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one)); |
| 374 | if (bind(fd, (struct sockaddr *)&s->proxy->source_addr, sizeof(s->proxy->source_addr)) == -1) { |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 375 | Alert("Cannot bind to source address before connect() for %s '%s'. Aborting.\n", |
| 376 | proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 377 | s->result = -1; |
| 378 | } |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 379 | #ifdef CONFIG_HAP_CTTPROXY |
| 380 | if ((s->proxy->options & PR_O_TPXY_MASK) == PR_O_TPXY_ADDR) { |
| 381 | struct in_tproxy itp1, itp2; |
| 382 | memset(&itp1, 0, sizeof(itp1)); |
| 383 | |
| 384 | itp1.op = TPROXY_ASSIGN; |
| 385 | itp1.v.addr.faddr = s->tproxy_addr.sin_addr; |
| 386 | itp1.v.addr.fport = s->tproxy_addr.sin_port; |
| 387 | |
| 388 | /* set connect flag on socket */ |
| 389 | itp2.op = TPROXY_FLAGS; |
| 390 | itp2.v.flags = ITP_CONNECT | ITP_ONCE; |
| 391 | |
| 392 | if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp1, sizeof(itp1)) == -1 || |
| 393 | setsockopt(fd, SOL_IP, IP_TPROXY, &itp2, sizeof(itp2)) == -1) { |
Willy Tarreau | 2b5652f | 2006-12-31 17:46:05 +0100 | [diff] [blame] | 394 | Alert("Cannot bind to tproxy source address before connect() for %s '%s'. Aborting.\n", |
| 395 | proxy_type_str(s->proxy), s->proxy->id); |
Willy Tarreau | 163c532 | 2006-11-14 16:18:41 +0100 | [diff] [blame] | 396 | s->result = -1; |
| 397 | } |
| 398 | } |
| 399 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | if (!s->result) { |
| 403 | if ((connect(fd, (struct sockaddr *)&sa, sizeof(sa)) != -1) || (errno == EINPROGRESS)) { |
| 404 | /* OK, connection in progress or established */ |
| 405 | |
| 406 | //fprintf(stderr, "process_chk: 4\n"); |
| 407 | |
| 408 | 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] | 409 | fd_insert(fd); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 410 | fdtab[fd].owner = t; |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 411 | fdtab[fd].cb[DIR_RD].f = &event_srv_chk_r; |
| 412 | fdtab[fd].cb[DIR_RD].b = NULL; |
| 413 | fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w; |
| 414 | fdtab[fd].cb[DIR_WR].b = NULL; |
Willy Tarreau | e94ebd0 | 2007-10-09 17:14:37 +0200 | [diff] [blame] | 415 | fdtab[fd].peeraddr = (struct sockaddr *)&sa; |
| 416 | fdtab[fd].peerlen = sizeof(sa); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 417 | fdtab[fd].state = FD_STCONN; /* connection in progress */ |
Willy Tarreau | 3d32d3a | 2007-04-15 11:31:05 +0200 | [diff] [blame] | 418 | fdtab[fd].ev = 0; |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 419 | EV_FD_SET(fd, DIR_WR); /* for connect status */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 420 | #ifdef DEBUG_FULL |
Willy Tarreau | f161a34 | 2007-04-08 16:59:42 +0200 | [diff] [blame] | 421 | assert (!EV_FD_ISSET(fd, DIR_RD)); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 422 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 423 | /* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */ |
Willy Tarreau | 42aae5c | 2007-04-29 17:43:56 +0200 | [diff] [blame] | 424 | tv_ms_add(&t->expire, &now, s->inter); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 425 | task_queue(t); /* restore t to its place in the task list */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 426 | *next = t->expire; |
Willy Tarreau | 8eee9c8 | 2007-05-14 03:40:11 +0200 | [diff] [blame] | 427 | return; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 428 | } |
| 429 | else if (errno != EALREADY && errno != EISCONN && errno != EAGAIN) { |
| 430 | s->result = -1; /* a real error */ |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | close(fd); /* socket creation error */ |
| 435 | } |
| 436 | |
| 437 | if (!s->result) { /* nothing done */ |
| 438 | //fprintf(stderr, "process_chk: 6\n"); |
Willy Tarreau | a8b55e3 | 2007-05-13 16:08:19 +0200 | [diff] [blame] | 439 | while (tv_isle(&t->expire, &now)) |
Willy Tarreau | 42aae5c | 2007-04-29 17:43:56 +0200 | [diff] [blame] | 440 | tv_ms_add(&t->expire, &t->expire, s->inter); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 441 | goto new_chk; /* may be we should initialize a new check */ |
| 442 | } |
| 443 | |
| 444 | /* here, we have seen a failure */ |
| 445 | if (s->health > s->rise) { |
| 446 | s->health--; /* still good */ |
| 447 | s->failed_checks++; |
| 448 | } |
| 449 | else |
| 450 | set_server_down(s); |
| 451 | |
| 452 | //fprintf(stderr, "process_chk: 7\n"); |
| 453 | /* FIXME: we allow up to <inter> for a connection to establish, but we should use another parameter */ |
Willy Tarreau | a8b55e3 | 2007-05-13 16:08:19 +0200 | [diff] [blame] | 454 | while (tv_isle(&t->expire, &now)) |
Willy Tarreau | 42aae5c | 2007-04-29 17:43:56 +0200 | [diff] [blame] | 455 | tv_ms_add(&t->expire, &t->expire, s->inter); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 456 | goto new_chk; |
| 457 | } |
| 458 | else { |
| 459 | //fprintf(stderr, "process_chk: 8\n"); |
| 460 | /* there was a test running */ |
| 461 | if (s->result > 0) { /* good server detected */ |
| 462 | //fprintf(stderr, "process_chk: 9\n"); |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 463 | |
| 464 | if (s->health < s->rise + s->fall - 1) { |
| 465 | s->health++; /* was bad, stays for a while */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 466 | |
| 467 | if (s->health == s->rise) { |
| 468 | int xferred; |
| 469 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 470 | if (s->last_change < now.tv_sec) // ignore negative times |
| 471 | s->down_time += now.tv_sec - s->last_change; |
| 472 | s->last_change = now.tv_sec; |
| 473 | s->state |= SRV_RUNNING; |
| 474 | |
| 475 | if (s->proxy->srv_bck == 0 && s->proxy->srv_act == 0) { |
| 476 | if (s->proxy->last_change < now.tv_sec) // ignore negative times |
| 477 | s->proxy->down_time += now.tv_sec - s->proxy->last_change; |
| 478 | s->proxy->last_change = now.tv_sec; |
| 479 | } |
| 480 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 481 | recount_servers(s->proxy); |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 482 | s->proxy->map_state |= PR_MAP_RECALC; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 483 | |
| 484 | /* check if we can handle some connections queued at the proxy. We |
| 485 | * will take as many as we can handle. |
| 486 | */ |
| 487 | for (xferred = 0; !s->maxconn || xferred < srv_dynamic_maxconn(s); xferred++) { |
| 488 | struct session *sess; |
| 489 | struct pendconn *p; |
| 490 | |
| 491 | p = pendconn_from_px(s->proxy); |
| 492 | if (!p) |
| 493 | break; |
| 494 | p->sess->srv = s; |
| 495 | sess = p->sess; |
| 496 | pendconn_free(p); |
Willy Tarreau | 96bcfd7 | 2007-04-29 10:41:56 +0200 | [diff] [blame] | 497 | task_wakeup(sess->task); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | sprintf(trash, |
| 501 | "%sServer %s/%s is UP. %d active and %d backup servers online.%s" |
| 502 | " %d sessions requeued, %d total in queue.\n", |
| 503 | s->state & SRV_BACKUP ? "Backup " : "", |
| 504 | s->proxy->id, s->id, s->proxy->srv_act, s->proxy->srv_bck, |
| 505 | (s->proxy->srv_bck && !s->proxy->srv_act) ? " Running on backup." : "", |
| 506 | xferred, s->nbpend); |
| 507 | |
| 508 | Warning("%s", trash); |
| 509 | send_log(s->proxy, LOG_NOTICE, "%s", trash); |
| 510 | } |
| 511 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 512 | if (s->health >= s->rise) |
| 513 | s->health = s->rise + s->fall - 1; /* OK now */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 514 | } |
| 515 | s->curfd = -1; /* no check running anymore */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 516 | fd_delete(fd); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 517 | |
| 518 | rv = 0; |
| 519 | if (global.spread_checks > 0) { |
| 520 | rv = s->inter * global.spread_checks / 100; |
| 521 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
| 522 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, s->inter, global.spread_checks, rv); |
| 523 | } |
| 524 | tv_ms_add(&t->expire, &now, s->inter + rv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 525 | goto new_chk; |
| 526 | } |
Willy Tarreau | a8b55e3 | 2007-05-13 16:08:19 +0200 | [diff] [blame] | 527 | else if (s->result < 0 || tv_isle(&t->expire, &now)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 528 | //fprintf(stderr, "process_chk: 10\n"); |
| 529 | /* failure or timeout detected */ |
| 530 | if (s->health > s->rise) { |
| 531 | s->health--; /* still good */ |
| 532 | s->failed_checks++; |
| 533 | } |
| 534 | else |
| 535 | set_server_down(s); |
| 536 | s->curfd = -1; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 537 | fd_delete(fd); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 538 | |
| 539 | rv = 0; |
| 540 | if (global.spread_checks > 0) { |
| 541 | rv = s->inter * global.spread_checks / 100; |
| 542 | rv -= (int) (2 * rv * (rand() / (RAND_MAX + 1.0))); |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 543 | //fprintf(stderr, "process_chk(%p): (%d+/-%d%%) random=%d\n", s, s->inter, global.spread_checks, rv); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 544 | } |
Willy Tarreau | 44ec0f0 | 2007-10-14 23:47:04 +0200 | [diff] [blame] | 545 | tv_ms_add(&t->expire, &now, s->inter + rv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 546 | goto new_chk; |
| 547 | } |
| 548 | /* if result is 0 and there's no timeout, we have to wait again */ |
| 549 | } |
| 550 | //fprintf(stderr, "process_chk: 11\n"); |
| 551 | s->result = 0; |
| 552 | task_queue(t); /* restore t to its place in the task list */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 553 | *next = t->expire; |
Willy Tarreau | 7317eb5 | 2007-05-09 00:54:10 +0200 | [diff] [blame] | 554 | out: |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 555 | return; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 556 | } |
| 557 | |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 558 | /* |
| 559 | * Start health-check. |
| 560 | * Returns 0 if OK, -1 if error, and prints the error in this case. |
| 561 | */ |
| 562 | int start_checks() { |
| 563 | |
| 564 | struct proxy *px; |
| 565 | struct server *s; |
| 566 | struct task *t; |
| 567 | int nbchk=0, mininter=0, srvpos=0; |
| 568 | |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 569 | /* 1- count the checkers to run simultaneously. |
| 570 | * We also determine the minimum interval among all of those which |
| 571 | * have an interval larger than SRV_CHK_INTER_THRES. This interval |
| 572 | * will be used to spread their start-up date. Those which have |
| 573 | * a shorter interval will start independantly and will not dictate |
| 574 | * too short an interval for all others. |
| 575 | */ |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 576 | for (px = proxy; px; px = px->next) { |
| 577 | for (s = px->srv; s; s = s->next) { |
| 578 | if (!(s->state & SRV_CHECKED)) |
| 579 | continue; |
| 580 | |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 581 | if ((s->inter >= SRV_CHK_INTER_THRES) && |
| 582 | (!mininter || mininter > s->inter)) |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 583 | mininter = s->inter; |
| 584 | |
| 585 | nbchk++; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | if (!nbchk) |
| 590 | return 0; |
| 591 | |
| 592 | srand((unsigned)time(NULL)); |
| 593 | |
| 594 | /* |
| 595 | * 2- start them as far as possible from each others. For this, we will |
| 596 | * start them after their interval set to the min interval divided by |
| 597 | * the number of servers, weighted by the server's position in the list. |
| 598 | */ |
| 599 | for (px = proxy; px; px = px->next) { |
| 600 | for (s = px->srv; s; s = s->next) { |
| 601 | if (!(s->state & SRV_CHECKED)) |
| 602 | continue; |
| 603 | |
| 604 | if ((t = pool_alloc2(pool2_task)) == NULL) { |
| 605 | Alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); |
| 606 | return -1; |
| 607 | } |
| 608 | |
| 609 | t->wq = NULL; |
| 610 | t->qlist.p = NULL; |
| 611 | t->state = TASK_IDLE; |
| 612 | t->process = process_chk; |
| 613 | t->context = s; |
| 614 | |
| 615 | /* check this every ms */ |
Willy Tarreau | 2c43a1e | 2007-10-14 23:05:39 +0200 | [diff] [blame] | 616 | tv_ms_add(&t->expire, &now, |
| 617 | ((mininter && mininter >= s->inter) ? mininter : s->inter) * srvpos / nbchk); |
Krzysztof Oledzki | b304dc7 | 2007-10-14 23:40:01 +0200 | [diff] [blame] | 618 | task_queue(t); |
| 619 | |
| 620 | srvpos++; |
| 621 | } |
| 622 | } |
| 623 | return 0; |
| 624 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * Local variables: |
| 628 | * c-indent-level: 8 |
| 629 | * c-basic-offset: 8 |
| 630 | * End: |
| 631 | */ |