blob: 809ee2bd10530b6ba3d940376e4199834885f09f [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Server management functions.
3 *
Willy Tarreau7c669d72008-06-20 15:04:11 +02004 * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
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 <stdlib.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020014
15#include <common/config.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020016#include <common/debug.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020017#include <common/memory.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020018
Willy Tarreaubaaee002006-06-26 02:48:02 +020019#include <types/capture.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010020#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020022#include <proto/acl.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010023#include <proto/backend.h>
Willy Tarreau7341d942007-05-13 19:56:02 +020024#include <proto/buffers.h>
Willy Tarreau5ca791d2009-08-16 19:06:42 +020025#include <proto/dumpstats.h>
Willy Tarreau8d5d7f22007-01-21 19:16:41 +010026#include <proto/hdr_idx.h>
Willy Tarreau332f8bf2007-05-13 21:36:56 +020027#include <proto/log.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020028#include <proto/session.h>
Willy Tarreau3eba98a2009-01-25 13:56:13 +010029#include <proto/pipe.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010030#include <proto/proto_http.h>
31#include <proto/proto_tcp.h>
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020032#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020033#include <proto/queue.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010034#include <proto/server.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010035#include <proto/stream_interface.h>
36#include <proto/stream_sock.h>
37#include <proto/task.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020038
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020039struct pool_head *pool2_session;
Willy Tarreauf54f8bd2008-11-23 19:53:55 +010040struct list sessions;
Willy Tarreaubaaee002006-06-26 02:48:02 +020041
42/*
43 * frees the context associated to a session. It must have been removed first.
44 */
45void session_free(struct session *s)
46{
Willy Tarreau4dbc4a22007-03-03 16:23:22 +010047 struct http_txn *txn = &s->txn;
Willy Tarreau632f5a72007-07-11 10:42:35 +020048 struct proxy *fe = s->fe;
Willy Tarreau62e4f1d2008-12-07 20:16:23 +010049 struct bref *bref, *back;
Willy Tarreau0f7562b2007-01-07 15:46:13 +010050
Willy Tarreaubaaee002006-06-26 02:48:02 +020051 if (s->pend_pos)
52 pendconn_free(s->pend_pos);
Willy Tarreau922a8062008-12-04 09:33:58 +010053
Willy Tarreau1e62de62008-11-11 20:20:02 +010054 if (s->srv) { /* there may be requests left pending in queue */
55 if (s->flags & SN_CURR_SESS) {
56 s->flags &= ~SN_CURR_SESS;
57 s->srv->cur_sess--;
58 }
Willy Tarreau922a8062008-12-04 09:33:58 +010059 if (may_dequeue_tasks(s->srv, s->be))
60 process_srv_queue(s->srv);
Willy Tarreau1e62de62008-11-11 20:20:02 +010061 }
Willy Tarreau922a8062008-12-04 09:33:58 +010062
Willy Tarreau7c669d72008-06-20 15:04:11 +020063 if (unlikely(s->srv_conn)) {
64 /* the session still has a reserved slot on a server, but
65 * it should normally be only the same as the one above,
66 * so this should not happen in fact.
67 */
68 sess_change_server(s, NULL);
69 }
70
Willy Tarreau3eba98a2009-01-25 13:56:13 +010071 if (s->req->pipe)
72 put_pipe(s->req->pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +010073
Willy Tarreau3eba98a2009-01-25 13:56:13 +010074 if (s->rep->pipe)
75 put_pipe(s->rep->pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +010076
Willy Tarreau48d63db2008-08-03 17:41:33 +020077 pool_free2(pool2_buffer, s->req);
78 pool_free2(pool2_buffer, s->rep);
Willy Tarreaubaaee002006-06-26 02:48:02 +020079
Willy Tarreau92fb9832007-10-16 17:34:28 +020080 if (fe) {
Willy Tarreau48d63db2008-08-03 17:41:33 +020081 pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
Willy Tarreau41dff822007-01-01 23:32:30 +010082
Willy Tarreau92fb9832007-10-16 17:34:28 +020083 if (txn->rsp.cap != NULL) {
84 struct cap_hdr *h;
Willy Tarreau48d63db2008-08-03 17:41:33 +020085 for (h = fe->rsp_cap; h; h = h->next)
86 pool_free2(h->pool, txn->rsp.cap[h->index]);
Willy Tarreau92fb9832007-10-16 17:34:28 +020087 pool_free2(fe->rsp_cap_pool, txn->rsp.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +020088 }
Willy Tarreau92fb9832007-10-16 17:34:28 +020089 if (txn->req.cap != NULL) {
90 struct cap_hdr *h;
Willy Tarreau48d63db2008-08-03 17:41:33 +020091 for (h = fe->req_cap; h; h = h->next)
92 pool_free2(h->pool, txn->req.cap[h->index]);
Willy Tarreau92fb9832007-10-16 17:34:28 +020093 pool_free2(fe->req_cap_pool, txn->req.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +020094 }
Willy Tarreaubaaee002006-06-26 02:48:02 +020095 }
Willy Tarreau48d63db2008-08-03 17:41:33 +020096 pool_free2(pool2_requri, txn->uri);
97 pool_free2(pool2_capture, txn->cli_cookie);
98 pool_free2(pool2_capture, txn->srv_cookie);
Willy Tarreau62e4f1d2008-12-07 20:16:23 +010099
100 list_for_each_entry_safe(bref, back, &s->back_refs, users) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100101 /* we have to unlink all watchers. We must not relink them if
102 * this session was the last one in the list.
103 */
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100104 LIST_DEL(&bref->users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100105 LIST_INIT(&bref->users);
106 if (s->list.n != &sessions)
107 LIST_ADDQ(&LIST_ELEM(s->list.n, struct session *, list)->back_refs, &bref->users);
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100108 bref->ref = s->list.n;
109 }
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100110 LIST_DEL(&s->list);
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200111 pool_free2(pool2_session, s);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200112
113 /* We may want to free the maximum amount of pools if the proxy is stopping */
Willy Tarreau92fb9832007-10-16 17:34:28 +0200114 if (fe && unlikely(fe->state == PR_STSTOPPED)) {
Willy Tarreau48d63db2008-08-03 17:41:33 +0200115 pool_flush2(pool2_buffer);
116 pool_flush2(fe->hdr_idx_pool);
117 pool_flush2(pool2_requri);
118 pool_flush2(pool2_capture);
119 pool_flush2(pool2_session);
120 pool_flush2(fe->req_cap_pool);
121 pool_flush2(fe->rsp_cap_pool);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200122 }
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200123}
124
125
126/* perform minimal intializations, report 0 in case of error, 1 if OK. */
127int init_session()
128{
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100129 LIST_INIT(&sessions);
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200130 pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED);
131 return pool2_session != NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200132}
133
Willy Tarreau30e71012007-11-26 20:15:35 +0100134void session_process_counters(struct session *s)
135{
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100136 unsigned long long bytes;
137
Willy Tarreau30e71012007-11-26 20:15:35 +0100138 if (s->req) {
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100139 bytes = s->req->total - s->logs.bytes_in;
Willy Tarreau30e71012007-11-26 20:15:35 +0100140 s->logs.bytes_in = s->req->total;
141 if (bytes) {
142 s->fe->bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100143
Willy Tarreau30e71012007-11-26 20:15:35 +0100144 if (s->be != s->fe)
145 s->be->bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100146
Willy Tarreau30e71012007-11-26 20:15:35 +0100147 if (s->srv)
148 s->srv->bytes_in += bytes;
149 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100150 }
151
Willy Tarreau30e71012007-11-26 20:15:35 +0100152 if (s->rep) {
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100153 bytes = s->rep->total - s->logs.bytes_out;
Willy Tarreau30e71012007-11-26 20:15:35 +0100154 s->logs.bytes_out = s->rep->total;
155 if (bytes) {
156 s->fe->bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100157
Willy Tarreau30e71012007-11-26 20:15:35 +0100158 if (s->be != s->fe)
159 s->be->bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100160
Willy Tarreau30e71012007-11-26 20:15:35 +0100161 if (s->srv)
162 s->srv->bytes_out += bytes;
163 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100164 }
165}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200166
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100167/* This function is called with (si->state == SI_ST_CON) meaning that a
168 * connection was attempted and that the file descriptor is already allocated.
169 * We must check for establishment, error and abort. Possible output states
170 * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and
171 * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER,
172 * otherwise 1.
173 */
174int sess_update_st_con_tcp(struct session *s, struct stream_interface *si)
175{
176 struct buffer *req = si->ob;
177 struct buffer *rep = si->ib;
178
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100179 /* If we got an error, or if nothing happened and the connection timed
180 * out, we must give up. The CER state handler will take care of retry
181 * attempts and error reports.
182 */
183 if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) {
Willy Tarreau127334e2009-03-28 10:47:26 +0100184 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100185 si->state = SI_ST_CER;
Willy Tarreaudc340a92009-06-28 23:10:19 +0200186 si->flags &= ~SI_FL_CAP_SPLICE;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100187 fd_delete(si->fd);
188
189 if (si->err_type)
190 return 0;
191
192 si->err_loc = s->srv;
193 if (si->flags & SI_FL_ERR)
194 si->err_type = SI_ET_CONN_ERR;
195 else
196 si->err_type = SI_ET_CONN_TO;
197 return 0;
198 }
199
200 /* OK, maybe we want to abort */
201 if (unlikely((req->flags & BF_SHUTW_NOW) ||
202 (rep->flags & BF_SHUTW) ||
203 ((req->flags & BF_SHUTR) && /* FIXME: this should not prevent a connection from establishing */
Willy Tarreauefc612c2009-01-09 12:18:24 +0100204 (((req->flags & (BF_EMPTY|BF_WRITE_ACTIVITY)) == BF_EMPTY) ||
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100205 s->be->options & PR_O_ABRT_CLOSE)))) {
206 /* give up */
207 si->shutw(si);
208 si->err_type |= SI_ET_CONN_ABRT;
209 si->err_loc = s->srv;
Willy Tarreaudc340a92009-06-28 23:10:19 +0200210 si->flags &= ~SI_FL_CAP_SPLICE;
Willy Tarreau84455332009-03-15 22:34:05 +0100211 if (s->srv_error)
212 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100213 return 1;
214 }
215
216 /* we need to wait a bit more if there was no activity either */
217 if (!(req->flags & BF_WRITE_ACTIVITY))
218 return 1;
219
220 /* OK, this means that a connection succeeded. The caller will be
221 * responsible for handling the transition from CON to EST.
222 */
223 s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau127334e2009-03-28 10:47:26 +0100224 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100225 si->state = SI_ST_EST;
226 si->err_type = SI_ET_NONE;
227 si->err_loc = NULL;
228 return 1;
229}
230
231/* This function is called with (si->state == SI_ST_CER) meaning that a
232 * previous connection attempt has failed and that the file descriptor
233 * has already been released. Possible causes include asynchronous error
234 * notification and time out. Possible output states are SI_ST_CLO when
235 * retries are exhausted, SI_ST_TAR when a delay is wanted before a new
236 * connection attempt, SI_ST_ASS when it's wise to retry on the same server,
237 * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are
238 * marked as in error state. It returns 0.
239 */
240int sess_update_st_cer(struct session *s, struct stream_interface *si)
241{
242 /* we probably have to release last session from the server */
243 if (s->srv) {
244 if (s->flags & SN_CURR_SESS) {
245 s->flags &= ~SN_CURR_SESS;
246 s->srv->cur_sess--;
247 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100248 }
249
250 /* ensure that we have enough retries left */
251 s->conn_retries--;
252 if (s->conn_retries < 0) {
253 if (!si->err_type) {
254 si->err_type = SI_ET_CONN_ERR;
255 si->err_loc = s->srv;
256 }
257
258 if (s->srv)
259 s->srv->failed_conns++;
260 s->be->failed_conns++;
261 if (may_dequeue_tasks(s->srv, s->be))
262 process_srv_queue(s->srv);
263
264 /* shutw is enough so stop a connecting socket */
265 si->shutw(si);
266 si->ob->flags |= BF_WRITE_ERROR;
267 si->ib->flags |= BF_READ_ERROR;
268
269 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100270 if (s->srv_error)
271 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100272 return 0;
273 }
274
275 /* If the "redispatch" option is set on the backend, we are allowed to
276 * retry on another server for the last retry. In order to achieve this,
277 * we must mark the session unassigned, and eventually clear the DIRECT
278 * bit to ignore any persistence cookie. We won't count a retry nor a
279 * redispatch yet, because this will depend on what server is selected.
280 */
281 if (s->srv && s->conn_retries == 0 && s->be->options & PR_O_REDISP) {
282 if (may_dequeue_tasks(s->srv, s->be))
283 process_srv_queue(s->srv);
284
285 s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
286 s->prev_srv = s->srv;
287 si->state = SI_ST_REQ;
288 } else {
289 if (s->srv)
290 s->srv->retries++;
291 s->be->retries++;
292 si->state = SI_ST_ASS;
293 }
294
295 if (si->flags & SI_FL_ERR) {
296 /* The error was an asynchronous connection error, and we will
297 * likely have to retry connecting to the same server, most
298 * likely leading to the same result. To avoid this, we wait
299 * one second before retrying.
300 */
301
302 if (!si->err_type)
303 si->err_type = SI_ET_CONN_ERR;
304
305 si->state = SI_ST_TAR;
306 si->exp = tick_add(now_ms, MS_TO_TICKS(1000));
307 return 0;
308 }
309 return 0;
310}
311
312/*
313 * This function handles the transition between the SI_ST_CON state and the
314 * SI_ST_EST state. It must only be called after switching from SI_ST_CON to
315 * SI_ST_EST.
316 */
317void sess_establish(struct session *s, struct stream_interface *si)
318{
319 struct buffer *req = si->ob;
320 struct buffer *rep = si->ib;
321
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100322 if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100323 buffer_set_rlim(rep, BUFSIZE); /* no rewrite needed */
324
325 /* if the user wants to log as soon as possible, without counting
326 * bytes from the server, then this is the right moment. */
327 if (s->fe->to_log && !(s->logs.logwait & LW_BYTES)) {
328 s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
Willy Tarreaua5555ec2008-11-30 19:02:32 +0100329 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100330 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100331 }
332 else {
333 rep->analysers |= AN_RTR_HTTP_HDR;
334 buffer_set_rlim(rep, BUFSIZE - MAXREWRITE); /* rewrite needed */
335 s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE;
336 /* reset hdr_idx which was already initialized by the request.
337 * right now, the http parser does it.
338 * hdr_idx_init(&s->txn.hdr_idx);
339 */
340 }
341
342 rep->flags |= BF_READ_ATTACHED; /* producer is now attached */
343 req->wex = TICK_ETERNITY;
344}
345
346/* Update stream interface status for input states SI_ST_ASS, SI_ST_QUE, SI_ST_TAR.
347 * Other input states are simply ignored.
348 * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON.
349 * Flags must have previously been updated for timeouts and other conditions.
350 */
351void sess_update_stream_int(struct session *s, struct stream_interface *si)
352{
353 DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rql=%d rpl=%d cs=%d ss=%d\n",
354 now_ms, __FUNCTION__,
355 s,
356 s->req, s->rep,
357 s->req->rex, s->rep->wex,
358 s->req->flags, s->rep->flags,
359 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state);
360
361 if (si->state == SI_ST_ASS) {
362 /* Server assigned to connection request, we have to try to connect now */
363 int conn_err;
364
365 conn_err = connect_server(s);
366 if (conn_err == SN_ERR_NONE) {
367 /* state = SI_ST_CON now */
Willy Tarreau8f6457c2008-12-01 00:08:28 +0100368 if (s->srv)
Willy Tarreau7f062c42009-03-05 18:43:00 +0100369 srv_inc_sess_ctr(s->srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100370 return;
371 }
372
373 /* We have received a synchronous error. We might have to
374 * abort, retry immediately or redispatch.
375 */
376 if (conn_err == SN_ERR_INTERNAL) {
377 if (!si->err_type) {
378 si->err_type = SI_ET_CONN_OTHER;
379 si->err_loc = s->srv;
380 }
381
382 if (s->srv)
Willy Tarreau7f062c42009-03-05 18:43:00 +0100383 srv_inc_sess_ctr(s->srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100384 if (s->srv)
385 s->srv->failed_conns++;
386 s->be->failed_conns++;
387
388 /* release other sessions waiting for this server */
389 if (may_dequeue_tasks(s->srv, s->be))
390 process_srv_queue(s->srv);
391
392 /* Failed and not retryable. */
393 si->shutr(si);
394 si->shutw(si);
395 si->ob->flags |= BF_WRITE_ERROR;
396
397 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
398
399 /* no session was ever accounted for this server */
400 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100401 if (s->srv_error)
402 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100403 return;
404 }
405
406 /* We are facing a retryable error, but we don't want to run a
407 * turn-around now, as the problem is likely a source port
408 * allocation problem, so we want to retry now.
409 */
410 si->state = SI_ST_CER;
411 si->flags &= ~SI_FL_ERR;
412 sess_update_st_cer(s, si);
413 /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */
414 return;
415 }
416 else if (si->state == SI_ST_QUE) {
417 /* connection request was queued, check for any update */
418 if (!s->pend_pos) {
419 /* The connection is not in the queue anymore. Either
420 * we have a server connection slot available and we
421 * go directly to the assigned state, or we need to
422 * load-balance first and go to the INI state.
423 */
424 si->exp = TICK_ETERNITY;
425 if (unlikely(!(s->flags & SN_ASSIGNED)))
426 si->state = SI_ST_REQ;
427 else {
428 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
429 si->state = SI_ST_ASS;
430 }
431 return;
432 }
433
434 /* Connection request still in queue... */
435 if (si->flags & SI_FL_EXP) {
436 /* ... and timeout expired */
437 si->exp = TICK_ETERNITY;
438 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
439 if (s->srv)
440 s->srv->failed_conns++;
441 s->be->failed_conns++;
442 si->shutr(si);
443 si->shutw(si);
444 si->ob->flags |= BF_WRITE_TIMEOUT;
445 if (!si->err_type)
446 si->err_type = SI_ET_QUEUE_TO;
447 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100448 if (s->srv_error)
449 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100450 return;
451 }
452
453 /* Connection remains in queue, check if we have to abort it */
454 if ((si->ob->flags & (BF_READ_ERROR|BF_SHUTW_NOW)) || /* abort requested */
455 ((si->ob->flags & BF_SHUTR) && /* empty and client stopped */
456 (si->ob->flags & BF_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) {
457 /* give up */
458 si->exp = TICK_ETERNITY;
459 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
460 si->shutr(si);
461 si->shutw(si);
462 si->err_type |= SI_ET_QUEUE_ABRT;
463 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100464 if (s->srv_error)
465 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100466 return;
467 }
468
469 /* Nothing changed */
470 return;
471 }
472 else if (si->state == SI_ST_TAR) {
473 /* Connection request might be aborted */
474 if ((si->ob->flags & (BF_READ_ERROR|BF_SHUTW_NOW)) || /* abort requested */
475 ((si->ob->flags & BF_SHUTR) && /* empty and client stopped */
476 (si->ob->flags & BF_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) {
477 /* give up */
478 si->exp = TICK_ETERNITY;
479 si->shutr(si);
480 si->shutw(si);
481 si->err_type |= SI_ET_CONN_ABRT;
482 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100483 if (s->srv_error)
484 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100485 return;
486 }
487
488 if (!(si->flags & SI_FL_EXP))
489 return; /* still in turn-around */
490
491 si->exp = TICK_ETERNITY;
492
493 /* we keep trying on the same server as long as the session is
494 * marked "assigned".
495 * FIXME: Should we force a redispatch attempt when the server is down ?
496 */
497 if (s->flags & SN_ASSIGNED)
498 si->state = SI_ST_ASS;
499 else
500 si->state = SI_ST_REQ;
501 return;
502 }
503}
504
505/* This function initiates a server connection request on a stream interface
506 * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS,
507 * indicating that a server has been assigned. It may also return SI_ST_QUE,
508 * or SI_ST_CLO upon error.
509 */
510static void sess_prepare_conn_req(struct session *s, struct stream_interface *si) {
511 DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rql=%d rpl=%d cs=%d ss=%d\n",
512 now_ms, __FUNCTION__,
513 s,
514 s->req, s->rep,
515 s->req->rex, s->rep->wex,
516 s->req->flags, s->rep->flags,
517 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state);
518
519 if (si->state != SI_ST_REQ)
520 return;
521
522 /* Try to assign a server */
523 if (srv_redispatch_connect(s) != 0) {
524 /* We did not get a server. Either we queued the
525 * connection request, or we encountered an error.
526 */
527 if (si->state == SI_ST_QUE)
528 return;
529
530 /* we did not get any server, let's check the cause */
531 si->shutr(si);
532 si->shutw(si);
533 si->ob->flags |= BF_WRITE_ERROR;
534 if (!si->err_type)
535 si->err_type = SI_ET_CONN_OTHER;
536 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100537 if (s->srv_error)
538 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100539 return;
540 }
541
542 /* The server is assigned */
543 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
544 si->state = SI_ST_ASS;
545}
546
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200547/* This stream analyser checks the switching rules and changes the backend
548 * if appropriate. The default_backend rule is also considered.
549 * It returns 1 if the processing can continue on next analysers, or zero if it
550 * either needs more data or wants to immediately abort the request.
551 */
552int process_switching_rules(struct session *s, struct buffer *req, int an_bit)
553{
554 req->analysers &= ~an_bit;
555 req->analyse_exp = TICK_ETERNITY;
556
557 DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
558 now_ms, __FUNCTION__,
559 s,
560 req,
561 req->rex, req->wex,
562 req->flags,
563 req->l,
564 req->analysers);
565
566 /* now check whether we have some switching rules for this request */
567 if (!(s->flags & SN_BE_ASSIGNED)) {
568 struct switching_rule *rule;
569
570 list_for_each_entry(rule, &s->fe->switching_rules, list) {
571 int ret;
572
573 ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, ACL_DIR_REQ);
574 ret = acl_pass(ret);
575 if (rule->cond->pol == ACL_COND_UNLESS)
576 ret = !ret;
577
578 if (ret) {
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200579 if (!session_set_backend(s, rule->be.backend))
580 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200581 break;
582 }
583 }
584
585 /* To ensure correct connection accounting on the backend, we
586 * have to assign one if it was not set (eg: a listen). This
587 * measure also takes care of correctly setting the default
588 * backend if any.
589 */
590 if (!(s->flags & SN_BE_ASSIGNED))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200591 if (!session_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be))
592 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200593 }
594
595 /* we don't want to run the HTTP filters again if the backend has not changed */
596 if (s->fe == s->be)
597 s->req->analysers &= ~AN_REQ_HTTP_PROCESS_BE;
598
599 return 1;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200600
601 sw_failed:
602 /* immediately abort this request in case of allocation failure */
603 buffer_abort(s->req);
604 buffer_abort(s->rep);
605
606 if (!(s->flags & SN_ERR_MASK))
607 s->flags |= SN_ERR_RESOURCE;
608 if (!(s->flags & SN_FINST_MASK))
609 s->flags |= SN_FINST_R;
610
611 s->txn.status = 500;
612 s->req->analysers = 0;
613 s->req->analyse_exp = TICK_ETERNITY;
614 return 0;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200615}
616
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100617/* Processes the client, server, request and response jobs of a session task,
618 * then puts it back to the wait queue in a clean state, or cleans up its
619 * resources if it must be deleted. Returns in <next> the date the task wants
620 * to be woken up, or TICK_ETERNITY. In order not to call all functions for
621 * nothing too many times, the request and response buffers flags are monitored
622 * and each function is called only if at least another function has changed at
623 * least one flag it is interested in.
624 */
Willy Tarreau26c25062009-03-08 09:38:41 +0100625struct task *process_session(struct task *t)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100626{
627 struct session *s = t->context;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100628 unsigned int rqf_last, rpf_last;
629
630 //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
631 // s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s->rep->flags);
632
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200633 /* This flag must explicitly be set every time */
634 s->req->flags &= ~BF_READ_NOEXP;
635
636 /* Keep a copy of req/rep flags so that we can detect shutdowns */
637 rqf_last = s->req->flags;
638 rpf_last = s->rep->flags;
639
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100640 /* 1a: Check for low level timeouts if needed. We just set a flag on
641 * stream interfaces when their timeouts have expired.
642 */
643 if (unlikely(t->state & TASK_WOKEN_TIMER)) {
644 stream_int_check_timeouts(&s->si[0]);
645 stream_int_check_timeouts(&s->si[1]);
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200646
647 /* check buffer timeouts, and close the corresponding stream interfaces
648 * for future reads or writes. Note: this will also concern upper layers
649 * but we do not touch any other flag. We must be careful and correctly
650 * detect state changes when calling them.
651 */
652
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100653 buffer_check_timeouts(s->req);
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200654
655 if (unlikely((s->req->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
656 s->req->prod->shutr(s->req->prod);
657
658 if (unlikely((s->req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT))
659 s->req->cons->shutw(s->req->cons);
660
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100661 buffer_check_timeouts(s->rep);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100662
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200663 if (unlikely((s->rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
664 s->rep->prod->shutr(s->rep->prod);
Willy Tarreau86491c32008-12-14 09:04:47 +0100665
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200666 if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT))
667 s->rep->cons->shutw(s->rep->cons);
668 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100669
670 /* 1b: check for low-level errors reported at the stream interface.
671 * First we check if it's a retryable error (in which case we don't
672 * want to tell the buffer). Otherwise we report the error one level
673 * upper by setting flags into the buffers. Note that the side towards
674 * the client cannot have connect (hence retryable) errors. Also, the
675 * connection setup code must be able to deal with any type of abort.
676 */
677 if (unlikely(s->si[0].flags & SI_FL_ERR)) {
678 if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) {
679 s->si[0].shutr(&s->si[0]);
680 s->si[0].shutw(&s->si[0]);
681 stream_int_report_error(&s->si[0]);
Willy Tarreau05cb29b2008-12-14 11:44:04 +0100682 if (!(s->req->analysers) && !(s->rep->analysers)) {
683 if (!(s->flags & SN_ERR_MASK))
684 s->flags |= SN_ERR_CLICL;
685 if (!(s->flags & SN_FINST_MASK))
686 s->flags |= SN_FINST_D;
687 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100688 }
689 }
690
691 if (unlikely(s->si[1].flags & SI_FL_ERR)) {
692 if (s->si[1].state == SI_ST_EST || s->si[1].state == SI_ST_DIS) {
693 s->si[1].shutr(&s->si[1]);
694 s->si[1].shutw(&s->si[1]);
695 stream_int_report_error(&s->si[1]);
696 s->be->failed_resp++;
697 if (s->srv)
698 s->srv->failed_resp++;
Willy Tarreau05cb29b2008-12-14 11:44:04 +0100699 if (!(s->req->analysers) && !(s->rep->analysers)) {
700 if (!(s->flags & SN_ERR_MASK))
701 s->flags |= SN_ERR_SRVCL;
702 if (!(s->flags & SN_FINST_MASK))
703 s->flags |= SN_FINST_D;
704 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100705 }
706 /* note: maybe we should process connection errors here ? */
707 }
708
709 if (s->si[1].state == SI_ST_CON) {
710 /* we were trying to establish a connection on the server side,
711 * maybe it succeeded, maybe it failed, maybe we timed out, ...
712 */
713 if (unlikely(!sess_update_st_con_tcp(s, &s->si[1])))
714 sess_update_st_cer(s, &s->si[1]);
715 else if (s->si[1].state == SI_ST_EST)
716 sess_establish(s, &s->si[1]);
717
718 /* state is now one of SI_ST_CON (still in progress), SI_ST_EST
719 * (established), SI_ST_DIS (abort), SI_ST_CLO (last error),
720 * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors.
721 */
722 }
723
Willy Tarreaub67a9b82009-06-21 22:03:51 +0200724resync_stream_interface:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100725 /* Check for connection closure */
726
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100727 DPRINTF(stderr,
728 "[%u] %s:%d: task=%p s=%p, sfl=0x%08x, rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rql=%d rpl=%d cs=%d ss=%d, cet=0x%x set=0x%x retr=%d\n",
729 now_ms, __FUNCTION__, __LINE__,
730 t,
731 s, s->flags,
732 s->req, s->rep,
733 s->req->rex, s->rep->wex,
734 s->req->flags, s->rep->flags,
735 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state,
736 s->rep->cons->err_type, s->req->cons->err_type,
737 s->conn_retries);
738
739 /* nothing special to be done on client side */
740 if (unlikely(s->req->prod->state == SI_ST_DIS))
741 s->req->prod->state = SI_ST_CLO;
742
743 /* When a server-side connection is released, we have to count it and
744 * check for pending connections on this server.
745 */
746 if (unlikely(s->req->cons->state == SI_ST_DIS)) {
747 s->req->cons->state = SI_ST_CLO;
748 if (s->srv) {
749 if (s->flags & SN_CURR_SESS) {
750 s->flags &= ~SN_CURR_SESS;
751 s->srv->cur_sess--;
752 }
753 sess_change_server(s, NULL);
754 if (may_dequeue_tasks(s->srv, s->be))
755 process_srv_queue(s->srv);
756 }
757 }
758
759 /*
760 * Note: of the transient states (REQ, CER, DIS), only REQ may remain
761 * at this point.
762 */
763
Willy Tarreau0be0ef92009-03-08 19:20:25 +0100764 resync_request:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100765 /* Analyse request */
766 if ((s->req->flags & BF_MASK_ANALYSER) ||
767 (s->req->flags ^ rqf_last) & BF_MASK_STATIC) {
768 unsigned int flags = s->req->flags;
769
770 if (s->req->prod->state >= SI_ST_EST) {
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200771 unsigned int last_ana = 0;
772
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100773 /* it's up to the analysers to reset write_ena */
774 buffer_write_ena(s->req);
Willy Tarreauedcf6682008-11-30 23:15:34 +0100775
776 /* We will call all analysers for which a bit is set in
777 * s->req->analysers, following the bit order from LSB
778 * to MSB. The analysers must remove themselves from
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200779 * the list when not needed. Any analyser may return 0
780 * to break out of the loop, either because of missing
781 * data to take a decision, or because it decides to
782 * kill the session. We loop at least once through each
783 * analyser, and we may loop again if other analysers
784 * are added in the middle.
Willy Tarreauedcf6682008-11-30 23:15:34 +0100785 */
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200786 while (s->req->analysers & ~last_ana) {
787 last_ana = s->req->analysers;
788
789 if (s->req->analysers & AN_REQ_INSPECT) {
790 last_ana |= AN_REQ_INSPECT;
Willy Tarreau3a816292009-07-07 10:55:49 +0200791 if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT))
Willy Tarreauedcf6682008-11-30 23:15:34 +0100792 break;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200793 }
Willy Tarreauedcf6682008-11-30 23:15:34 +0100794
Willy Tarreaud787e662009-07-07 10:14:51 +0200795 if (s->req->analysers & AN_REQ_WAIT_HTTP) {
796 last_ana |= AN_REQ_WAIT_HTTP;
Willy Tarreau3a816292009-07-07 10:55:49 +0200797 if (!http_wait_for_request(s, s->req, AN_REQ_WAIT_HTTP))
Willy Tarreaud787e662009-07-07 10:14:51 +0200798 break;
799 }
800
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200801 if (s->req->analysers & AN_REQ_HTTP_PROCESS_FE) {
802 last_ana |= AN_REQ_HTTP_PROCESS_FE;
803 if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_FE, s->fe))
804 break;
805 }
806
807 if (s->req->analysers & AN_REQ_SWITCHING_RULES) {
808 last_ana |= AN_REQ_SWITCHING_RULES;
809 if (!process_switching_rules(s, s->req, AN_REQ_SWITCHING_RULES))
810 break;
Willy Tarreaud88bb6f2009-07-12 09:55:41 +0200811 /* FIXME: we mait switch from TCP to HTTP and want to
812 * immediately loop back to the top. This is a dirty way
813 * of doing it, and we should find a cleaner method relying
814 * on a circular list of function pointers.
815 */
816 if ((s->req->analysers & ~last_ana) & AN_REQ_WAIT_HTTP)
817 continue;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200818 }
819
820 if (s->req->analysers & AN_REQ_HTTP_PROCESS_BE) {
821 last_ana |= AN_REQ_HTTP_PROCESS_BE;
822 if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_BE, s->be))
823 break;
824 }
825
826 if (s->req->analysers & AN_REQ_HTTP_INNER) {
827 last_ana |= AN_REQ_HTTP_INNER;
828 if (!http_process_request(s, s->req, AN_REQ_HTTP_INNER))
Willy Tarreauedcf6682008-11-30 23:15:34 +0100829 break;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200830 }
Willy Tarreauedcf6682008-11-30 23:15:34 +0100831
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200832 if (s->req->analysers & AN_REQ_HTTP_TARPIT) {
833 last_ana |= AN_REQ_HTTP_TARPIT;
Willy Tarreau3a816292009-07-07 10:55:49 +0200834 if (!http_process_tarpit(s, s->req, AN_REQ_HTTP_TARPIT))
Willy Tarreau60b85b02008-11-30 23:28:40 +0100835 break;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200836 }
Willy Tarreau60b85b02008-11-30 23:28:40 +0100837
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200838 if (s->req->analysers & AN_REQ_HTTP_BODY) {
839 last_ana |= AN_REQ_HTTP_BODY;
Willy Tarreau3a816292009-07-07 10:55:49 +0200840 if (!http_process_request_body(s, s->req, AN_REQ_HTTP_BODY))
Willy Tarreaud34af782008-11-30 23:36:37 +0100841 break;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +0200842 }
Emeric Brun647caf12009-06-30 17:57:00 +0200843
Willy Tarreau5ca791d2009-08-16 19:06:42 +0200844 if (s->req->analysers & AN_REQ_STATS_SOCK) {
845 last_ana |= AN_REQ_STATS_SOCK;
846 if (!stats_sock_req_analyser(s, s->req, AN_REQ_STATS_SOCK))
Willy Tarreau104eb362009-08-16 18:51:29 +0200847 break;
848 }
849
Emeric Brun647caf12009-06-30 17:57:00 +0200850 if (s->req->analysers & AN_REQ_PRST_RDP_COOKIE) {
851 last_ana |= AN_REQ_PRST_RDP_COOKIE;
852 if (!tcp_persist_rdp_cookie(s, s->req, AN_REQ_PRST_RDP_COOKIE))
853 break;
854 }
Willy Tarreauedcf6682008-11-30 23:15:34 +0100855 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100856 }
Willy Tarreau84455332009-03-15 22:34:05 +0100857
Willy Tarreau3deb3d02009-06-21 22:43:05 +0200858 if ((s->req->flags ^ flags) & BF_MASK_STATIC) {
859 rqf_last = s->req->flags;
860 goto resync_request;
861 }
862 }
863
864 resync_response:
865 /* Analyse response */
866
867 if (unlikely(s->rep->flags & BF_HIJACK)) {
868 /* In inject mode, we wake up everytime something has
869 * happened on the write side of the buffer.
870 */
871 unsigned int flags = s->rep->flags;
872
873 if ((s->rep->flags & (BF_WRITE_PARTIAL|BF_WRITE_ERROR|BF_SHUTW)) &&
874 !(s->rep->flags & BF_FULL)) {
875 s->rep->hijacker(s, s->rep);
876 }
877
878 if ((s->rep->flags ^ flags) & BF_MASK_STATIC) {
879 rpf_last = s->rep->flags;
880 goto resync_response;
881 }
882 }
883 else if ((s->rep->flags & BF_MASK_ANALYSER) ||
884 (s->rep->flags ^ rpf_last) & BF_MASK_STATIC) {
885 unsigned int flags = s->rep->flags;
886
887 if (s->rep->prod->state >= SI_ST_EST) {
888 /* it's up to the analysers to reset write_ena */
889 buffer_write_ena(s->rep);
890 if (s->rep->analysers)
891 process_response(s);
892 }
893
894 if ((s->rep->flags ^ flags) & BF_MASK_STATIC) {
895 rpf_last = s->rep->flags;
896 goto resync_response;
897 }
898 }
899
900 /* FIXME: here we should call protocol handlers which rely on
901 * both buffers.
902 */
903
904
905 /*
906 * Now we propagate unhandled errors to the session
907 */
908 if (!(s->flags & SN_ERR_MASK)) {
909 if (s->req->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) {
910 /* Report it if the client got an error or a read timeout expired */
Willy Tarreau84455332009-03-15 22:34:05 +0100911 s->req->analysers = 0;
912 if (s->req->flags & BF_READ_ERROR)
913 s->flags |= SN_ERR_CLICL;
914 else if (s->req->flags & BF_READ_TIMEOUT)
915 s->flags |= SN_ERR_CLITO;
916 else if (s->req->flags & BF_WRITE_ERROR)
917 s->flags |= SN_ERR_SRVCL;
918 else
919 s->flags |= SN_ERR_SRVTO;
920 sess_set_term_flags(s);
921 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +0200922 else if (s->rep->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) {
923 /* Report it if the server got an error or a read timeout expired */
924 s->rep->analysers = 0;
925 if (s->rep->flags & BF_READ_ERROR)
926 s->flags |= SN_ERR_SRVCL;
927 else if (s->rep->flags & BF_READ_TIMEOUT)
928 s->flags |= SN_ERR_SRVTO;
929 else if (s->rep->flags & BF_WRITE_ERROR)
930 s->flags |= SN_ERR_CLICL;
931 else
Willy Tarreau84455332009-03-15 22:34:05 +0100932 s->flags |= SN_ERR_CLITO;
Willy Tarreau3deb3d02009-06-21 22:43:05 +0200933 sess_set_term_flags(s);
934 }
Willy Tarreau84455332009-03-15 22:34:05 +0100935 }
936
Willy Tarreau3deb3d02009-06-21 22:43:05 +0200937 /*
938 * Here we take care of forwarding unhandled data. This also includes
939 * connection establishments and shutdown requests.
940 */
941
942
Willy Tarreau7c84bab2009-03-08 21:38:23 +0100943 /* If noone is interested in analysing data, it's time to forward
944 * everything. We will wake up from time to time when either send_max
945 * or to_forward are reached.
Willy Tarreau6b66f3e2008-12-14 17:31:54 +0100946 */
Willy Tarreau7c84bab2009-03-08 21:38:23 +0100947 if (!s->req->analysers &&
948 !(s->req->flags & (BF_HIJACK|BF_SHUTW)) &&
949 (s->req->prod->state >= SI_ST_EST)) {
950 /* This buffer is freewheeling, there's no analyser nor hijacker
951 * attached to it. If any data are left in, we'll permit them to
952 * move.
953 */
954 buffer_flush(s->req);
Willy Tarreau5bd8c372009-01-19 00:32:22 +0100955
Willy Tarreau7c84bab2009-03-08 21:38:23 +0100956 /* If the producer is still connected, we'll schedule large blocks
957 * of data to be forwarded from the producer to the consumer (which
958 * might possibly not be connected yet).
959 */
960 if (!(s->req->flags & BF_SHUTR) &&
961 s->req->to_forward < FORWARD_DEFAULT_SIZE)
Willy Tarreau0abebcc2009-01-08 00:09:41 +0100962 buffer_forward(s->req, FORWARD_DEFAULT_SIZE);
Willy Tarreau6b66f3e2008-12-14 17:31:54 +0100963 }
Willy Tarreauf890dc92008-12-13 21:12:26 +0100964
Willy Tarreau7c84bab2009-03-08 21:38:23 +0100965 /* check if it is wise to enable kernel splicing to forward request data */
966 if (!(s->req->flags & (BF_KERN_SPLICING|BF_SHUTR)) &&
967 s->req->to_forward &&
968 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreaudc340a92009-06-28 23:10:19 +0200969 (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +0100970 (pipes_used < global.maxpipes) &&
971 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
972 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
973 (s->req->flags & BF_STREAMER_FAST)))) {
974 s->req->flags |= BF_KERN_SPLICING;
975 }
976
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100977 /* reflect what the L7 analysers have seen last */
978 rqf_last = s->req->flags;
979
980 /*
981 * Now forward all shutdown requests between both sides of the buffer
982 */
983
984 /* first, let's check if the request buffer needs to shutdown(write) */
985 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_SHUTR)) ==
986 (BF_EMPTY|BF_WRITE_ENA|BF_SHUTR)))
987 buffer_shutw_now(s->req);
988 else if ((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_EMPTY|BF_WRITE_ENA)) == (BF_EMPTY|BF_WRITE_ENA) &&
989 (s->req->cons->state == SI_ST_EST) &&
990 s->be->options & PR_O_FORCE_CLO &&
991 s->rep->flags & BF_READ_ACTIVITY) {
992 /* We want to force the connection to the server to close,
993 * and the server has begun to respond. That's the right
994 * time.
995 */
996 buffer_shutw_now(s->req);
997 }
998
999 /* shutdown(write) pending */
1000 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW)) == BF_SHUTW_NOW))
1001 s->req->cons->shutw(s->req->cons);
1002
1003 /* shutdown(write) done on server side, we must stop the client too */
Willy Tarreau3dbc6942008-12-07 13:05:04 +01001004 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW &&
1005 !s->req->analysers))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001006 buffer_shutr_now(s->req);
1007
1008 /* shutdown(read) pending */
1009 if (unlikely((s->req->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW))
1010 s->req->prod->shutr(s->req->prod);
1011
Willy Tarreau92795622009-03-06 12:51:23 +01001012 /* it's possible that an upper layer has requested a connection setup or abort */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001013 if (s->req->cons->state == SI_ST_INI &&
Willy Tarreau92795622009-03-06 12:51:23 +01001014 (s->req->flags & (BF_WRITE_ENA|BF_SHUTW|BF_SHUTW_NOW))) {
Willy Tarreau73201222009-08-16 18:27:24 +02001015 if ((s->req->flags & (BF_WRITE_ENA|BF_SHUTW|BF_SHUTW_NOW)) == BF_WRITE_ENA) {
1016 /* If we have a ->connect method, we need to perform a connection request,
1017 * otherwise we immediately switch to the connected state.
1018 */
1019 if (s->req->cons->connect)
1020 s->req->cons->state = SI_ST_REQ; /* new connection requested */
1021 else
1022 s->req->cons->state = SI_ST_EST; /* connection established */
1023 }
Willy Tarreau92795622009-03-06 12:51:23 +01001024 else
1025 s->req->cons->state = SI_ST_CLO; /* shutw+ini = abort */
1026 }
1027
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001028
1029 /* we may have a pending connection request, or a connection waiting
1030 * for completion.
1031 */
1032 if (s->si[1].state >= SI_ST_REQ && s->si[1].state < SI_ST_CON) {
1033 do {
1034 /* nb: step 1 might switch from QUE to ASS, but we first want
1035 * to give a chance to step 2 to perform a redirect if needed.
1036 */
1037 if (s->si[1].state != SI_ST_REQ)
1038 sess_update_stream_int(s, &s->si[1]);
1039 if (s->si[1].state == SI_ST_REQ)
1040 sess_prepare_conn_req(s, &s->si[1]);
1041
1042 if (s->si[1].state == SI_ST_ASS && s->srv &&
1043 s->srv->rdr_len && (s->flags & SN_REDIRECTABLE))
1044 perform_http_redirect(s, &s->si[1]);
1045 } while (s->si[1].state == SI_ST_ASS);
1046 }
1047
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001048 /* Benchmarks have shown that it's optimal to do a full resync now */
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001049 if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001050 goto resync_stream_interface;
1051
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001052 /* otherwise wewant to check if we need to resync the req buffer or not */
1053 if ((s->req->flags ^ rqf_last) & BF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001054 goto resync_request;
1055
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001056 /* perform output updates to the response buffer */
Willy Tarreau84455332009-03-15 22:34:05 +01001057
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001058 /* If noone is interested in analysing data, it's time to forward
1059 * everything. We will wake up from time to time when either send_max
1060 * or to_forward are reached.
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001061 */
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001062 if (!s->rep->analysers &&
1063 !(s->rep->flags & (BF_HIJACK|BF_SHUTW)) &&
1064 (s->rep->prod->state >= SI_ST_EST)) {
1065 /* This buffer is freewheeling, there's no analyser nor hijacker
1066 * attached to it. If any data are left in, we'll permit them to
1067 * move.
1068 */
1069 buffer_flush(s->rep);
Willy Tarreau5bd8c372009-01-19 00:32:22 +01001070
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001071 /* If the producer is still connected, we'll schedule large blocks
1072 * of data to be forwarded from the producer to the consumer (which
1073 * might possibly not be connected yet).
1074 */
1075 if (!(s->rep->flags & BF_SHUTR) &&
1076 s->rep->to_forward < FORWARD_DEFAULT_SIZE)
Willy Tarreau0abebcc2009-01-08 00:09:41 +01001077 buffer_forward(s->rep, FORWARD_DEFAULT_SIZE);
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001078 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01001079
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001080 /* check if it is wise to enable kernel splicing to forward response data */
1081 if (!(s->rep->flags & (BF_KERN_SPLICING|BF_SHUTR)) &&
1082 s->rep->to_forward &&
1083 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreaudc340a92009-06-28 23:10:19 +02001084 (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001085 (pipes_used < global.maxpipes) &&
1086 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
1087 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
1088 (s->rep->flags & BF_STREAMER_FAST)))) {
1089 s->rep->flags |= BF_KERN_SPLICING;
1090 }
1091
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001092 /* reflect what the L7 analysers have seen last */
1093 rpf_last = s->rep->flags;
1094
1095 /*
1096 * Now forward all shutdown requests between both sides of the buffer
1097 */
1098
1099 /*
1100 * FIXME: this is probably where we should produce error responses.
1101 */
1102
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001103 /* first, let's check if the response buffer needs to shutdown(write) */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001104 if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_SHUTR)) ==
1105 (BF_EMPTY|BF_WRITE_ENA|BF_SHUTR)))
1106 buffer_shutw_now(s->rep);
1107
1108 /* shutdown(write) pending */
1109 if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTW_NOW)) == BF_SHUTW_NOW))
1110 s->rep->cons->shutw(s->rep->cons);
1111
1112 /* shutdown(write) done on the client side, we must stop the server too */
Willy Tarreau3dbc6942008-12-07 13:05:04 +01001113 if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW) &&
1114 !s->rep->analysers)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001115 buffer_shutr_now(s->rep);
1116
1117 /* shutdown(read) pending */
1118 if (unlikely((s->rep->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW))
1119 s->rep->prod->shutr(s->rep->prod);
1120
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001121 if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001122 goto resync_stream_interface;
1123
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001124 if (s->req->flags != rqf_last)
1125 goto resync_request;
1126
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001127 if ((s->rep->flags ^ rpf_last) & BF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001128 goto resync_response;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001129
1130 /* This is needed only when debugging is enabled, to indicate
1131 * client-side or server-side close. Please note that in the unlikely
1132 * event where both sides would close at once, the sequence is reported
1133 * on the server side first.
1134 */
1135 if (unlikely((global.mode & MODE_DEBUG) &&
1136 (!(global.mode & MODE_QUIET) ||
1137 (global.mode & MODE_VERBOSE)))) {
1138 int len;
1139
1140 if (s->si[1].state == SI_ST_CLO &&
1141 s->si[1].prev_state == SI_ST_EST) {
1142 len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n",
1143 s->uniq_id, s->be->id,
1144 (unsigned short)s->si[0].fd,
1145 (unsigned short)s->si[1].fd);
1146 write(1, trash, len);
1147 }
1148
1149 if (s->si[0].state == SI_ST_CLO &&
1150 s->si[0].prev_state == SI_ST_EST) {
1151 len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n",
1152 s->uniq_id, s->be->id,
1153 (unsigned short)s->si[0].fd,
1154 (unsigned short)s->si[1].fd);
1155 write(1, trash, len);
1156 }
1157 }
1158
1159 if (likely((s->rep->cons->state != SI_ST_CLO) ||
1160 (s->req->cons->state > SI_ST_INI && s->req->cons->state < SI_ST_CLO))) {
1161
1162 if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED))
1163 session_process_counters(s);
1164
1165 if (s->rep->cons->state == SI_ST_EST)
Willy Tarreaub0253252008-11-30 21:37:12 +01001166 stream_sock_data_finish(s->rep->cons);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001167
1168 if (s->req->cons->state == SI_ST_EST)
Willy Tarreaub0253252008-11-30 21:37:12 +01001169 stream_sock_data_finish(s->req->cons);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001170
Willy Tarreauea388542009-06-21 21:45:58 +02001171 s->req->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL);
1172 s->rep->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001173 s->si[0].prev_state = s->si[0].state;
1174 s->si[1].prev_state = s->si[1].state;
Willy Tarreaub0ef7352008-12-14 13:26:20 +01001175 s->si[0].flags &= ~(SI_FL_ERR|SI_FL_EXP);
1176 s->si[1].flags &= ~(SI_FL_ERR|SI_FL_EXP);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001177
1178 /* Trick: if a request is being waiting for the server to respond,
1179 * and if we know the server can timeout, we don't want the timeout
1180 * to expire on the client side first, but we're still interested
1181 * in passing data from the client to the server (eg: POST). Thus,
1182 * we can cancel the client's request timeout if the server's
1183 * request timeout is set and the server has not yet sent a response.
1184 */
1185
1186 if ((s->rep->flags & (BF_WRITE_ENA|BF_SHUTR)) == 0 &&
Willy Tarreau86491c32008-12-14 09:04:47 +01001187 (tick_isset(s->req->wex) || tick_isset(s->rep->rex))) {
1188 s->req->flags |= BF_READ_NOEXP;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001189 s->req->rex = TICK_ETERNITY;
Willy Tarreau86491c32008-12-14 09:04:47 +01001190 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001191
1192 t->expire = tick_first(tick_first(s->req->rex, s->req->wex),
1193 tick_first(s->rep->rex, s->rep->wex));
1194 if (s->req->analysers)
1195 t->expire = tick_first(t->expire, s->req->analyse_exp);
1196
1197 if (s->si[0].exp)
1198 t->expire = tick_first(t->expire, s->si[0].exp);
1199
1200 if (s->si[1].exp)
1201 t->expire = tick_first(t->expire, s->si[1].exp);
1202
1203#ifdef DEBUG_FULL
Willy Tarreau127334e2009-03-28 10:47:26 +01001204 fprintf(stderr,
1205 "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u"
1206 " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n",
1207 now_ms, t->expire, s->req->rex, s->req->wex, s->req->analyse_exp,
1208 s->rep->rex, s->rep->wex, s->si[0].exp, s->si[1].exp, s->si[0].state, s->si[1].state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001209#endif
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001210
1211#ifdef DEBUG_DEV
1212 /* this may only happen when no timeout is set or in case of an FSM bug */
Willy Tarreaud0a201b2009-03-08 15:53:06 +01001213 if (!tick_isset(t->expire))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001214 ABORT_NOW();
1215#endif
Willy Tarreau26c25062009-03-08 09:38:41 +01001216 return t; /* nothing more to do */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001217 }
1218
1219 s->fe->feconn--;
1220 if (s->flags & SN_BE_ASSIGNED)
1221 s->be->beconn--;
1222 actconn--;
Willy Tarreau6e6fb2b2009-08-16 18:20:44 +02001223 s->listener->nbconn--;
1224 if (s->listener->state == LI_FULL &&
1225 s->listener->nbconn < s->listener->maxconn) {
1226 /* we should reactivate the listener */
1227 EV_FD_SET(s->listener->fd, DIR_RD);
1228 s->listener->state = LI_READY;
1229 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001230
1231 if (unlikely((global.mode & MODE_DEBUG) &&
1232 (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
1233 int len;
Willy Tarreauec22b2c2009-03-06 13:07:40 +01001234 len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001235 s->uniq_id, s->be->id,
Willy Tarreauec22b2c2009-03-06 13:07:40 +01001236 (unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001237 write(1, trash, len);
1238 }
1239
1240 s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
1241 session_process_counters(s);
1242
1243 /* let's do a final log if we need it */
1244 if (s->logs.logwait &&
1245 !(s->flags & SN_MONITOR) &&
1246 (!(s->fe->options & PR_O_NULLNOLOG) || s->req->total)) {
Willy Tarreaua5555ec2008-11-30 19:02:32 +01001247 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001248 }
1249
1250 /* the task MUST not be in the run queue anymore */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001251 session_free(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01001252 task_delete(t);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001253 task_free(t);
Willy Tarreau26c25062009-03-08 09:38:41 +01001254 return NULL;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001255}
1256
Willy Tarreau7c669d72008-06-20 15:04:11 +02001257/*
1258 * This function adjusts sess->srv_conn and maintains the previous and new
1259 * server's served session counts. Setting newsrv to NULL is enough to release
1260 * current connection slot. This function also notifies any LB algo which might
1261 * expect to be informed about any change in the number of active sessions on a
1262 * server.
1263 */
1264void sess_change_server(struct session *sess, struct server *newsrv)
1265{
1266 if (sess->srv_conn == newsrv)
1267 return;
1268
1269 if (sess->srv_conn) {
1270 sess->srv_conn->served--;
1271 if (sess->srv_conn->proxy->lbprm.server_drop_conn)
1272 sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
1273 sess->srv_conn = NULL;
1274 }
1275
1276 if (newsrv) {
1277 newsrv->served++;
1278 if (newsrv->proxy->lbprm.server_take_conn)
1279 newsrv->proxy->lbprm.server_take_conn(newsrv);
1280 sess->srv_conn = newsrv;
1281 }
1282}
1283
Willy Tarreau84455332009-03-15 22:34:05 +01001284/* Set correct session termination flags in case no analyser has done it. It
1285 * also counts a failed request if the server state has not reached the request
1286 * stage.
1287 */
1288void sess_set_term_flags(struct session *s)
1289{
1290 if (!(s->flags & SN_FINST_MASK)) {
1291 if (s->si[1].state < SI_ST_REQ) {
1292 s->fe->failed_req++;
1293 s->flags |= SN_FINST_R;
1294 }
1295 else if (s->si[1].state == SI_ST_QUE)
1296 s->flags |= SN_FINST_Q;
1297 else if (s->si[1].state < SI_ST_EST)
1298 s->flags |= SN_FINST_C;
1299 else if (s->si[1].state == SI_ST_EST)
1300 s->flags |= SN_FINST_D;
1301 else
1302 s->flags |= SN_FINST_L;
1303 }
1304}
1305
1306/* Handle server-side errors for default protocols. It is called whenever a a
1307 * connection setup is aborted or a request is aborted in queue. It sets the
1308 * session termination flags so that the caller does not have to worry about
1309 * them. It's installed as ->srv_error for the server-side stream_interface.
1310 */
1311void default_srv_error(struct session *s, struct stream_interface *si)
1312{
1313 int err_type = si->err_type;
1314 int err = 0, fin = 0;
1315
1316 if (err_type & SI_ET_QUEUE_ABRT) {
1317 err = SN_ERR_CLICL;
1318 fin = SN_FINST_Q;
1319 }
1320 else if (err_type & SI_ET_CONN_ABRT) {
1321 err = SN_ERR_CLICL;
1322 fin = SN_FINST_C;
1323 }
1324 else if (err_type & SI_ET_QUEUE_TO) {
1325 err = SN_ERR_SRVTO;
1326 fin = SN_FINST_Q;
1327 }
1328 else if (err_type & SI_ET_QUEUE_ERR) {
1329 err = SN_ERR_SRVCL;
1330 fin = SN_FINST_Q;
1331 }
1332 else if (err_type & SI_ET_CONN_TO) {
1333 err = SN_ERR_SRVTO;
1334 fin = SN_FINST_C;
1335 }
1336 else if (err_type & SI_ET_CONN_ERR) {
1337 err = SN_ERR_SRVCL;
1338 fin = SN_FINST_C;
1339 }
1340 else /* SI_ET_CONN_OTHER and others */ {
1341 err = SN_ERR_INTERNAL;
1342 fin = SN_FINST_C;
1343 }
1344
1345 if (!(s->flags & SN_ERR_MASK))
1346 s->flags |= err;
1347 if (!(s->flags & SN_FINST_MASK))
1348 s->flags |= fin;
1349}
Willy Tarreau7c669d72008-06-20 15:04:11 +02001350
Willy Tarreaubaaee002006-06-26 02:48:02 +02001351/*
1352 * Local variables:
1353 * c-indent-level: 8
1354 * c-basic-offset: 8
1355 * End:
1356 */