Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Server management functions. |
| 3 | * |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 4 | * Copyright 2000-2008 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 <stdlib.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 14 | |
| 15 | #include <common/config.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 16 | #include <common/debug.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 17 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 18 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 19 | #include <types/capture.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 20 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 22 | #include <proto/acl.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 23 | #include <proto/backend.h> |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame] | 24 | #include <proto/buffers.h> |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 25 | #include <proto/dumpstats.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 26 | #include <proto/hdr_idx.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 27 | #include <proto/log.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 28 | #include <proto/session.h> |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 29 | #include <proto/pipe.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 30 | #include <proto/proto_http.h> |
| 31 | #include <proto/proto_tcp.h> |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 32 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | #include <proto/queue.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 34 | #include <proto/server.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 35 | #include <proto/stream_interface.h> |
| 36 | #include <proto/stream_sock.h> |
| 37 | #include <proto/task.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 38 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 39 | struct pool_head *pool2_session; |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 40 | struct list sessions; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * frees the context associated to a session. It must have been removed first. |
| 44 | */ |
| 45 | void session_free(struct session *s) |
| 46 | { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 47 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 48 | struct proxy *fe = s->fe; |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 49 | struct bref *bref, *back; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 50 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | if (s->pend_pos) |
| 52 | pendconn_free(s->pend_pos); |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 53 | |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 54 | 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 Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 59 | if (may_dequeue_tasks(s->srv, s->be)) |
| 60 | process_srv_queue(s->srv); |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 61 | } |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 62 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 63 | 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 Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 71 | if (s->req->pipe) |
| 72 | put_pipe(s->req->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 73 | |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 74 | if (s->rep->pipe) |
| 75 | put_pipe(s->rep->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 76 | |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 77 | pool_free2(pool2_buffer, s->req); |
| 78 | pool_free2(pool2_buffer, s->rep); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 79 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 80 | if (fe) { |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 81 | pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v); |
Willy Tarreau | 41dff82 | 2007-01-01 23:32:30 +0100 | [diff] [blame] | 82 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 83 | if (txn->rsp.cap != NULL) { |
| 84 | struct cap_hdr *h; |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 85 | for (h = fe->rsp_cap; h; h = h->next) |
| 86 | pool_free2(h->pool, txn->rsp.cap[h->index]); |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 87 | pool_free2(fe->rsp_cap_pool, txn->rsp.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 88 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 89 | if (txn->req.cap != NULL) { |
| 90 | struct cap_hdr *h; |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 91 | for (h = fe->req_cap; h; h = h->next) |
| 92 | pool_free2(h->pool, txn->req.cap[h->index]); |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 93 | pool_free2(fe->req_cap_pool, txn->req.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 94 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 95 | } |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 96 | pool_free2(pool2_requri, txn->uri); |
| 97 | pool_free2(pool2_capture, txn->cli_cookie); |
| 98 | pool_free2(pool2_capture, txn->srv_cookie); |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 99 | |
| 100 | list_for_each_entry_safe(bref, back, &s->back_refs, users) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 101 | /* we have to unlink all watchers. We must not relink them if |
| 102 | * this session was the last one in the list. |
| 103 | */ |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 104 | LIST_DEL(&bref->users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 105 | 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 Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 108 | bref->ref = s->list.n; |
| 109 | } |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 110 | LIST_DEL(&s->list); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 111 | pool_free2(pool2_session, s); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 112 | |
| 113 | /* We may want to free the maximum amount of pools if the proxy is stopping */ |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 114 | if (fe && unlikely(fe->state == PR_STSTOPPED)) { |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 115 | 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 Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 122 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
| 126 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 127 | int init_session() |
| 128 | { |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 129 | LIST_INIT(&sessions); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 130 | pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); |
| 131 | return pool2_session != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 134 | void session_process_counters(struct session *s) |
| 135 | { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 136 | unsigned long long bytes; |
| 137 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 138 | if (s->req) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 139 | bytes = s->req->total - s->logs.bytes_in; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 140 | s->logs.bytes_in = s->req->total; |
| 141 | if (bytes) { |
| 142 | s->fe->bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 143 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 144 | if (s->be != s->fe) |
| 145 | s->be->bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 146 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 147 | if (s->srv) |
| 148 | s->srv->bytes_in += bytes; |
| 149 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 152 | if (s->rep) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 153 | bytes = s->rep->total - s->logs.bytes_out; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 154 | s->logs.bytes_out = s->rep->total; |
| 155 | if (bytes) { |
| 156 | s->fe->bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 157 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 158 | if (s->be != s->fe) |
| 159 | s->be->bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 160 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 161 | if (s->srv) |
| 162 | s->srv->bytes_out += bytes; |
| 163 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 166 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 167 | /* 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 | */ |
| 174 | int 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 179 | /* 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 Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 184 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 185 | si->state = SI_ST_CER; |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 186 | si->flags &= ~SI_FL_CAP_SPLICE; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 187 | 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 Tarreau | efc612c | 2009-01-09 12:18:24 +0100 | [diff] [blame] | 204 | (((req->flags & (BF_EMPTY|BF_WRITE_ACTIVITY)) == BF_EMPTY) || |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 205 | 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 Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 210 | si->flags &= ~SI_FL_CAP_SPLICE; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 211 | if (s->srv_error) |
| 212 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 213 | 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 Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 224 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 225 | 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 | */ |
| 240 | int 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 248 | } |
| 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 270 | if (s->srv_error) |
| 271 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 272 | 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 | */ |
| 317 | void sess_establish(struct session *s, struct stream_interface *si) |
| 318 | { |
| 319 | struct buffer *req = si->ob; |
| 320 | struct buffer *rep = si->ib; |
| 321 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 322 | if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ |
Willy Tarreau | a07a34e | 2009-08-16 23:27:46 +0200 | [diff] [blame] | 323 | buffer_set_rlim(rep, rep->size); /* no rewrite needed */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 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 Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 329 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 330 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 331 | } |
| 332 | else { |
Willy Tarreau | 27a674e | 2009-08-17 07:23:33 +0200 | [diff] [blame] | 333 | buffer_set_rlim(rep, req->size - global.tune.maxrewrite); /* rewrite needed */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 334 | s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE; |
| 335 | /* reset hdr_idx which was already initialized by the request. |
| 336 | * right now, the http parser does it. |
| 337 | * hdr_idx_init(&s->txn.hdr_idx); |
| 338 | */ |
| 339 | } |
| 340 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 341 | rep->analysers |= s->fe->fe_rsp_ana | s->be->be_rsp_ana; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 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 | */ |
| 351 | void 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 Tarreau | 8f6457c | 2008-12-01 00:08:28 +0100 | [diff] [blame] | 368 | if (s->srv) |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 369 | srv_inc_sess_ctr(s->srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 370 | 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 Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 383 | srv_inc_sess_ctr(s->srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 384 | 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 401 | if (s->srv_error) |
| 402 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 403 | 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 448 | if (s->srv_error) |
| 449 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 450 | 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 464 | if (s->srv_error) |
| 465 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 466 | 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 483 | if (s->srv_error) |
| 484 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 485 | 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 | */ |
| 510 | static 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 Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 537 | if (s->srv_error) |
| 538 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 539 | 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 Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 547 | /* 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 | */ |
| 552 | int 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 Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 579 | if (!session_set_backend(s, rule->be.backend)) |
| 580 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 581 | 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 Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 591 | if (!session_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be)) |
| 592 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 593 | } |
| 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 Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 600 | |
| 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 Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 617 | /* 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 Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 625 | struct task *process_session(struct task *t) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 626 | { |
| 627 | struct session *s = t->context; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 628 | 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 Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 633 | /* 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 640 | /* 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 Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 646 | |
| 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 653 | buffer_check_timeouts(s->req); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 654 | |
| 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 661 | buffer_check_timeouts(s->rep); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 662 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 663 | if (unlikely((s->rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT)) |
| 664 | s->rep->prod->shutr(s->rep->prod); |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 665 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 666 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) |
| 667 | s->rep->cons->shutw(s->rep->cons); |
| 668 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 669 | |
| 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 Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 682 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 688 | } |
| 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 Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 699 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 705 | } |
| 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 Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 724 | resync_stream_interface: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 725 | /* Check for connection closure */ |
| 726 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 727 | 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 Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 764 | resync_request: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 765 | /* 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 Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 771 | unsigned int last_ana = 0; |
| 772 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 773 | /* it's up to the analysers to reset write_ena */ |
| 774 | buffer_write_ena(s->req); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 775 | |
| 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 Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 779 | * 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 Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 785 | */ |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 786 | 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 Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 791 | if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT)) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 792 | break; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 793 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 794 | |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 795 | if (s->req->analysers & AN_REQ_WAIT_HTTP) { |
| 796 | last_ana |= AN_REQ_WAIT_HTTP; |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 797 | if (!http_wait_for_request(s, s->req, AN_REQ_WAIT_HTTP)) |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 798 | break; |
| 799 | } |
| 800 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 801 | 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 Tarreau | d88bb6f | 2009-07-12 09:55:41 +0200 | [diff] [blame] | 811 | /* 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 Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 818 | } |
| 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 Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 829 | break; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 830 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 831 | |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 832 | if (s->req->analysers & AN_REQ_HTTP_TARPIT) { |
| 833 | last_ana |= AN_REQ_HTTP_TARPIT; |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 834 | if (!http_process_tarpit(s, s->req, AN_REQ_HTTP_TARPIT)) |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 835 | break; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 836 | } |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 837 | |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 838 | if (s->req->analysers & AN_REQ_HTTP_BODY) { |
| 839 | last_ana |= AN_REQ_HTTP_BODY; |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 840 | if (!http_process_request_body(s, s->req, AN_REQ_HTTP_BODY)) |
Willy Tarreau | d34af78 | 2008-11-30 23:36:37 +0100 | [diff] [blame] | 841 | break; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 842 | } |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 843 | |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 844 | 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 Tarreau | 104eb36 | 2009-08-16 18:51:29 +0200 | [diff] [blame] | 847 | break; |
| 848 | } |
| 849 | |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 850 | 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 Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 855 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 856 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 857 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 858 | 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 Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 911 | 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 Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 922 | 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 Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 932 | s->flags |= SN_ERR_CLITO; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 933 | sess_set_term_flags(s); |
| 934 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 935 | } |
| 936 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 937 | /* |
| 938 | * Here we take care of forwarding unhandled data. This also includes |
| 939 | * connection establishments and shutdown requests. |
| 940 | */ |
| 941 | |
| 942 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 943 | /* 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 Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 946 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 947 | 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 Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 955 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 956 | /* 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 Tarreau | 0abebcc | 2009-01-08 00:09:41 +0100 | [diff] [blame] | 962 | buffer_forward(s->req, FORWARD_DEFAULT_SIZE); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 963 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 964 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 965 | /* 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 Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 969 | (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 970 | (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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 977 | /* 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 Tarreau | 3dbc694 | 2008-12-07 13:05:04 +0100 | [diff] [blame] | 1004 | if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW && |
| 1005 | !s->req->analysers)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1006 | 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 Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 1012 | /* it's possible that an upper layer has requested a connection setup or abort */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1013 | if (s->req->cons->state == SI_ST_INI && |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 1014 | (s->req->flags & (BF_WRITE_ENA|BF_SHUTW|BF_SHUTW_NOW))) { |
Willy Tarreau | 7320122 | 2009-08-16 18:27:24 +0200 | [diff] [blame] | 1015 | 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 Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 1024 | else |
| 1025 | s->req->cons->state = SI_ST_CLO; /* shutw+ini = abort */ |
| 1026 | } |
| 1027 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1028 | |
| 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 Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1048 | /* Benchmarks have shown that it's optimal to do a full resync now */ |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1049 | if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1050 | goto resync_stream_interface; |
| 1051 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1052 | /* 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 Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1054 | goto resync_request; |
| 1055 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1056 | /* perform output updates to the response buffer */ |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1057 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1058 | /* 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 Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1061 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1062 | 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 Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 1070 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1071 | /* 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 Tarreau | 0abebcc | 2009-01-08 00:09:41 +0100 | [diff] [blame] | 1077 | buffer_forward(s->rep, FORWARD_DEFAULT_SIZE); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1078 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 1079 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1080 | /* 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 Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 1084 | (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1085 | (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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1092 | /* 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 Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1103 | /* first, let's check if the response buffer needs to shutdown(write) */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1104 | 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 Tarreau | 3dbc694 | 2008-12-07 13:05:04 +0100 | [diff] [blame] | 1113 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW) && |
| 1114 | !s->rep->analysers) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1115 | 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 Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1121 | if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1122 | goto resync_stream_interface; |
| 1123 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1124 | if (s->req->flags != rqf_last) |
| 1125 | goto resync_request; |
| 1126 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1127 | if ((s->rep->flags ^ rpf_last) & BF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1128 | goto resync_response; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1129 | |
| 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 Tarreau | dc85b39 | 2009-08-18 07:38:19 +0200 | [diff] [blame] | 1166 | s->rep->cons->update(s->rep->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1167 | |
| 1168 | if (s->req->cons->state == SI_ST_EST) |
Willy Tarreau | dc85b39 | 2009-08-18 07:38:19 +0200 | [diff] [blame] | 1169 | s->req->cons->update(s->req->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1170 | |
Willy Tarreau | ea38854 | 2009-06-21 21:45:58 +0200 | [diff] [blame] | 1171 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1173 | s->si[0].prev_state = s->si[0].state; |
| 1174 | s->si[1].prev_state = s->si[1].state; |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 1175 | s->si[0].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
| 1176 | s->si[1].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1177 | |
| 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 Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 1187 | (tick_isset(s->req->wex) || tick_isset(s->rep->rex))) { |
| 1188 | s->req->flags |= BF_READ_NOEXP; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1189 | s->req->rex = TICK_ETERNITY; |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 1190 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1191 | |
| 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 Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 1204 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1209 | #endif |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1210 | |
| 1211 | #ifdef DEBUG_DEV |
| 1212 | /* this may only happen when no timeout is set or in case of an FSM bug */ |
Willy Tarreau | d0a201b | 2009-03-08 15:53:06 +0100 | [diff] [blame] | 1213 | if (!tick_isset(t->expire)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1214 | ABORT_NOW(); |
| 1215 | #endif |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1216 | return t; /* nothing more to do */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | s->fe->feconn--; |
| 1220 | if (s->flags & SN_BE_ASSIGNED) |
| 1221 | s->be->beconn--; |
| 1222 | actconn--; |
Willy Tarreau | 6e6fb2b | 2009-08-16 18:20:44 +0200 | [diff] [blame] | 1223 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1230 | |
| 1231 | if (unlikely((global.mode & MODE_DEBUG) && |
| 1232 | (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
| 1233 | int len; |
Willy Tarreau | ec22b2c | 2009-03-06 13:07:40 +0100 | [diff] [blame] | 1234 | len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1235 | s->uniq_id, s->be->id, |
Willy Tarreau | ec22b2c | 2009-03-06 13:07:40 +0100 | [diff] [blame] | 1236 | (unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1237 | 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 Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 1247 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | /* the task MUST not be in the run queue anymore */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1251 | session_free(s); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1252 | task_delete(t); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1253 | task_free(t); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1254 | return NULL; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1257 | /* |
| 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 | */ |
| 1264 | void 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 Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1284 | /* 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 | */ |
| 1288 | void 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 | */ |
| 1311 | void 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 Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1350 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1351 | /* |
| 1352 | * Local variables: |
| 1353 | * c-indent-level: 8 |
| 1354 | * c-basic-offset: 8 |
| 1355 | * End: |
| 1356 | */ |