Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 2 | * Session management functions. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 4 | * Copyright 2000-2010 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 | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 14 | #include <unistd.h> |
| 15 | #include <fcntl.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 16 | |
| 17 | #include <common/config.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 18 | #include <common/debug.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 19 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 20 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | #include <types/capture.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 22 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 24 | #include <proto/acl.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 25 | #include <proto/backend.h> |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame] | 26 | #include <proto/buffers.h> |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 27 | #include <proto/checks.h> |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 28 | #include <proto/dumpstats.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 29 | #include <proto/hdr_idx.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 30 | #include <proto/log.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | #include <proto/session.h> |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 32 | #include <proto/pipe.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 33 | #include <proto/proto_http.h> |
| 34 | #include <proto/proto_tcp.h> |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 35 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | #include <proto/queue.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 37 | #include <proto/server.h> |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 38 | #include <proto/stick_table.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 39 | #include <proto/stream_interface.h> |
| 40 | #include <proto/stream_sock.h> |
| 41 | #include <proto/task.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 43 | struct pool_head *pool2_session; |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 44 | struct list sessions; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 46 | /* This function is called from the protocol layer accept() in order to instanciate |
| 47 | * a new session on behalf of a given listener and frontend. It returns a positive |
| 48 | * value upon success, 0 if the connection needs to be closed and ignored, or a |
| 49 | * negative value upon critical failure. |
| 50 | */ |
| 51 | int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) |
| 52 | { |
| 53 | struct proxy *p = l->frontend; |
| 54 | struct session *s; |
| 55 | struct http_txn *txn; |
| 56 | struct task *t; |
| 57 | |
| 58 | if (unlikely((s = pool_alloc2(pool2_session)) == NULL)) { |
| 59 | Alert("out of memory in event_accept().\n"); |
| 60 | goto out_close; |
| 61 | } |
| 62 | |
| 63 | /* minimum session initialization required for monitor mode below */ |
| 64 | s->flags = 0; |
| 65 | s->logs.logwait = p->to_log; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 66 | s->tracked_counters = NULL; |
| 67 | s->tracked_table = NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 68 | |
| 69 | /* if this session comes from a known monitoring system, we want to ignore |
| 70 | * it as soon as possible, which means closing it immediately for TCP, but |
| 71 | * cleanly. |
| 72 | */ |
| 73 | if (unlikely((l->options & LI_O_CHK_MONNET) && |
| 74 | addr->ss_family == AF_INET && |
| 75 | (((struct sockaddr_in *)addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr)) { |
| 76 | if (p->mode == PR_MODE_TCP) { |
| 77 | pool_free2(pool2_session, s); |
| 78 | return 0; |
| 79 | } |
| 80 | s->flags |= SN_MONITOR; |
| 81 | s->logs.logwait = 0; |
| 82 | } |
| 83 | |
| 84 | /* OK, we're keeping the session, so let's properly initialize the session */ |
| 85 | LIST_ADDQ(&sessions, &s->list); |
| 86 | LIST_INIT(&s->back_refs); |
| 87 | |
| 88 | if (unlikely((t = task_new()) == NULL)) { /* disable this proxy for a while */ |
| 89 | Alert("out of memory in event_accept().\n"); |
| 90 | goto out_free_session; |
| 91 | } |
| 92 | |
| 93 | s->term_trace = 0; |
| 94 | s->cli_addr = *addr; |
| 95 | s->logs.accept_date = date; /* user-visible date for logging */ |
| 96 | s->logs.tv_accept = now; /* corrected date for internal use */ |
| 97 | s->uniq_id = totalconn; |
Willy Tarreau | 24dcaf3 | 2010-06-05 10:49:41 +0200 | [diff] [blame] | 98 | p->feconn++; /* beconn will be increased once assigned */ |
| 99 | |
Willy Tarreau | b36b424 | 2010-06-04 20:59:39 +0200 | [diff] [blame] | 100 | proxy_inc_fe_conn_ctr(l, p); /* note: cum_beconn will be increased once assigned */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 101 | |
| 102 | t->process = l->handler; |
| 103 | t->context = s; |
| 104 | t->nice = l->nice; |
| 105 | t->expire = TICK_ETERNITY; |
| 106 | |
| 107 | s->task = t; |
| 108 | s->listener = l; |
| 109 | |
| 110 | /* Note: initially, the session's backend points to the frontend. |
| 111 | * This changes later when switching rules are executed or |
| 112 | * when the default backend is assigned. |
| 113 | */ |
| 114 | s->be = s->fe = p; |
| 115 | s->req = s->rep = NULL; /* will be allocated later */ |
| 116 | |
| 117 | /* now evaluate the tcp-request layer4 rules. Since we expect to be able |
| 118 | * to abort right here as soon as possible, we check the rules before |
| 119 | * even initializing the stream interfaces. |
| 120 | */ |
| 121 | if ((l->options & LI_O_TCP_RULES) && !tcp_exec_req_rules(s)) { |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 122 | if (s->tracked_counters) |
| 123 | session_store_counters(s); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 124 | task_free(t); |
| 125 | LIST_DEL(&s->list); |
| 126 | pool_free2(pool2_session, s); |
| 127 | /* let's do a no-linger now to close with a single RST. */ |
| 128 | setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
Willy Tarreau | 24dcaf3 | 2010-06-05 10:49:41 +0200 | [diff] [blame] | 129 | p->feconn--; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Willy Tarreau | b36b424 | 2010-06-04 20:59:39 +0200 | [diff] [blame] | 133 | /* This session was accepted, count it now */ |
Willy Tarreau | 24dcaf3 | 2010-06-05 10:49:41 +0200 | [diff] [blame] | 134 | if (p->feconn > p->counters.feconn_max) |
| 135 | p->counters.feconn_max = p->feconn; |
Willy Tarreau | b36b424 | 2010-06-04 20:59:39 +0200 | [diff] [blame] | 136 | proxy_inc_fe_sess_ctr(l, p); |
| 137 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 138 | /* this part should be common with other protocols */ |
| 139 | s->si[0].fd = cfd; |
| 140 | s->si[0].owner = t; |
| 141 | s->si[0].state = s->si[0].prev_state = SI_ST_EST; |
| 142 | s->si[0].err_type = SI_ET_NONE; |
| 143 | s->si[0].err_loc = NULL; |
| 144 | s->si[0].connect = NULL; |
| 145 | s->si[0].iohandler = NULL; |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 146 | s->si[0].release = NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 147 | s->si[0].exp = TICK_ETERNITY; |
| 148 | s->si[0].flags = SI_FL_NONE; |
| 149 | |
| 150 | if (likely(s->fe->options2 & PR_O2_INDEPSTR)) |
| 151 | s->si[0].flags |= SI_FL_INDEP_STR; |
| 152 | |
| 153 | if (addr->ss_family == AF_INET || addr->ss_family == AF_INET6) |
| 154 | s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */ |
| 155 | |
| 156 | /* add the various callbacks */ |
| 157 | stream_sock_prepare_interface(&s->si[0]); |
| 158 | |
| 159 | /* pre-initialize the other side's stream interface to an INIT state. The |
| 160 | * callbacks will be initialized before attempting to connect. |
| 161 | */ |
| 162 | s->si[1].fd = -1; /* just to help with debugging */ |
| 163 | s->si[1].owner = t; |
| 164 | s->si[1].state = s->si[1].prev_state = SI_ST_INI; |
| 165 | s->si[1].err_type = SI_ET_NONE; |
| 166 | s->si[1].err_loc = NULL; |
| 167 | s->si[1].connect = NULL; |
| 168 | s->si[1].iohandler = NULL; |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 169 | s->si[1].release = NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 170 | s->si[1].shutr = stream_int_shutr; |
| 171 | s->si[1].shutw = stream_int_shutw; |
| 172 | s->si[1].exp = TICK_ETERNITY; |
| 173 | s->si[1].flags = SI_FL_NONE; |
| 174 | |
| 175 | if (likely(s->fe->options2 & PR_O2_INDEPSTR)) |
| 176 | s->si[1].flags |= SI_FL_INDEP_STR; |
| 177 | |
| 178 | s->srv = s->prev_srv = s->srv_conn = NULL; |
| 179 | s->pend_pos = NULL; |
| 180 | |
| 181 | /* init store persistence */ |
| 182 | s->store_count = 0; |
| 183 | |
| 184 | /* Adjust some socket options */ |
| 185 | if (unlikely(fcntl(cfd, F_SETFL, O_NONBLOCK) == -1)) { |
| 186 | Alert("accept(): cannot set the socket in non blocking mode. Giving up\n"); |
| 187 | goto out_free_task; |
| 188 | } |
| 189 | |
| 190 | txn = &s->txn; |
| 191 | /* Those variables will be checked and freed if non-NULL in |
| 192 | * session.c:session_free(). It is important that they are |
| 193 | * properly initialized. |
| 194 | */ |
| 195 | txn->sessid = NULL; |
| 196 | txn->srv_cookie = NULL; |
| 197 | txn->cli_cookie = NULL; |
| 198 | txn->uri = NULL; |
| 199 | txn->req.cap = NULL; |
| 200 | txn->rsp.cap = NULL; |
| 201 | txn->hdr_idx.v = NULL; |
| 202 | txn->hdr_idx.size = txn->hdr_idx.used = 0; |
| 203 | |
| 204 | if (unlikely((s->req = pool_alloc2(pool2_buffer)) == NULL)) |
| 205 | goto out_free_task; /* no memory */ |
| 206 | |
| 207 | if (unlikely((s->rep = pool_alloc2(pool2_buffer)) == NULL)) |
| 208 | goto out_free_req; /* no memory */ |
| 209 | |
| 210 | /* initialize the request buffer */ |
| 211 | s->req->size = global.tune.bufsize; |
| 212 | buffer_init(s->req); |
| 213 | s->req->prod = &s->si[0]; |
| 214 | s->req->cons = &s->si[1]; |
| 215 | s->si[0].ib = s->si[1].ob = s->req; |
| 216 | s->req->flags |= BF_READ_ATTACHED; /* the producer is already connected */ |
| 217 | |
| 218 | /* activate default analysers enabled for this listener */ |
| 219 | s->req->analysers = l->analysers; |
| 220 | |
| 221 | s->req->wto = TICK_ETERNITY; |
| 222 | s->req->rto = TICK_ETERNITY; |
| 223 | s->req->rex = TICK_ETERNITY; |
| 224 | s->req->wex = TICK_ETERNITY; |
| 225 | s->req->analyse_exp = TICK_ETERNITY; |
| 226 | |
| 227 | /* initialize response buffer */ |
| 228 | s->rep->size = global.tune.bufsize; |
| 229 | buffer_init(s->rep); |
| 230 | s->rep->prod = &s->si[1]; |
| 231 | s->rep->cons = &s->si[0]; |
| 232 | s->si[0].ob = s->si[1].ib = s->rep; |
| 233 | s->rep->analysers = 0; |
| 234 | |
| 235 | s->rep->rto = TICK_ETERNITY; |
| 236 | s->rep->wto = TICK_ETERNITY; |
| 237 | s->rep->rex = TICK_ETERNITY; |
| 238 | s->rep->wex = TICK_ETERNITY; |
| 239 | s->rep->analyse_exp = TICK_ETERNITY; |
| 240 | |
| 241 | /* finish initialization of the accepted file descriptor */ |
| 242 | fd_insert(cfd); |
| 243 | fdtab[cfd].owner = &s->si[0]; |
| 244 | fdtab[cfd].state = FD_STREADY; |
| 245 | fdtab[cfd].flags = 0; |
| 246 | fdtab[cfd].cb[DIR_RD].f = l->proto->read; |
| 247 | fdtab[cfd].cb[DIR_RD].b = s->req; |
| 248 | fdtab[cfd].cb[DIR_WR].f = l->proto->write; |
| 249 | fdtab[cfd].cb[DIR_WR].b = s->rep; |
| 250 | fdinfo[cfd].peeraddr = (struct sockaddr *)&s->cli_addr; |
| 251 | fdinfo[cfd].peerlen = sizeof(s->cli_addr); |
| 252 | EV_FD_SET(cfd, DIR_RD); |
| 253 | |
| 254 | if (p->accept) { |
| 255 | int ret = p->accept(s); |
| 256 | if (unlikely(ret < 0)) |
| 257 | goto out_free_rep; |
| 258 | |
| 259 | if (unlikely(ret == 0)) { |
| 260 | /* work is finished, we can release everything (eg: monitoring) */ |
| 261 | pool_free2(pool2_buffer, s->rep); |
| 262 | pool_free2(pool2_buffer, s->req); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 263 | if (s->tracked_counters) |
| 264 | session_store_counters(s); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 265 | task_free(t); |
| 266 | LIST_DEL(&s->list); |
| 267 | pool_free2(pool2_session, s); |
Willy Tarreau | 24dcaf3 | 2010-06-05 10:49:41 +0200 | [diff] [blame] | 268 | p->feconn--; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /* it is important not to call the wakeup function directly but to |
| 274 | * pass through task_wakeup(), because this one knows how to apply |
| 275 | * priorities to tasks. |
| 276 | */ |
| 277 | task_wakeup(t, TASK_WOKEN_INIT); |
| 278 | return 1; |
| 279 | |
| 280 | /* Error unrolling */ |
| 281 | out_free_rep: |
| 282 | pool_free2(pool2_buffer, s->rep); |
| 283 | out_free_req: |
| 284 | pool_free2(pool2_buffer, s->req); |
| 285 | out_free_task: |
Willy Tarreau | 24dcaf3 | 2010-06-05 10:49:41 +0200 | [diff] [blame] | 286 | p->feconn--; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 287 | if (s->tracked_counters) |
| 288 | session_store_counters(s); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 289 | task_free(t); |
| 290 | out_free_session: |
| 291 | LIST_DEL(&s->list); |
| 292 | pool_free2(pool2_session, s); |
| 293 | out_close: |
| 294 | return -1; |
| 295 | } |
| 296 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 297 | /* |
| 298 | * frees the context associated to a session. It must have been removed first. |
| 299 | */ |
| 300 | void session_free(struct session *s) |
| 301 | { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 302 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 303 | struct proxy *fe = s->fe; |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 304 | struct bref *bref, *back; |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 305 | int i; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 306 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 307 | if (s->pend_pos) |
| 308 | pendconn_free(s->pend_pos); |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 309 | |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 310 | if (s->srv) { /* there may be requests left pending in queue */ |
| 311 | if (s->flags & SN_CURR_SESS) { |
| 312 | s->flags &= ~SN_CURR_SESS; |
| 313 | s->srv->cur_sess--; |
| 314 | } |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 315 | if (may_dequeue_tasks(s->srv, s->be)) |
| 316 | process_srv_queue(s->srv); |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 317 | } |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 318 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 319 | if (unlikely(s->srv_conn)) { |
| 320 | /* the session still has a reserved slot on a server, but |
| 321 | * it should normally be only the same as the one above, |
| 322 | * so this should not happen in fact. |
| 323 | */ |
| 324 | sess_change_server(s, NULL); |
| 325 | } |
| 326 | |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 327 | if (s->req->pipe) |
| 328 | put_pipe(s->req->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 329 | |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 330 | if (s->rep->pipe) |
| 331 | put_pipe(s->rep->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 332 | |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 333 | pool_free2(pool2_buffer, s->req); |
| 334 | pool_free2(pool2_buffer, s->rep); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 335 | |
Willy Tarreau | 4602363 | 2010-01-07 22:51:47 +0100 | [diff] [blame] | 336 | http_end_txn(s); |
| 337 | |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 338 | for (i = 0; i < s->store_count; i++) { |
| 339 | if (!s->store[i].ts) |
| 340 | continue; |
| 341 | stksess_free(s->store[i].table, s->store[i].ts); |
| 342 | s->store[i].ts = NULL; |
| 343 | } |
| 344 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 345 | if (fe) { |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 346 | pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v); |
Willy Tarreau | 4602363 | 2010-01-07 22:51:47 +0100 | [diff] [blame] | 347 | pool_free2(fe->rsp_cap_pool, txn->rsp.cap); |
| 348 | pool_free2(fe->req_cap_pool, txn->req.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 349 | } |
Willy Tarreau | 0937bc4 | 2009-12-22 15:03:09 +0100 | [diff] [blame] | 350 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 351 | if (s->tracked_counters) |
| 352 | session_store_counters(s); |
| 353 | |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 354 | list_for_each_entry_safe(bref, back, &s->back_refs, users) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 355 | /* we have to unlink all watchers. We must not relink them if |
| 356 | * this session was the last one in the list. |
| 357 | */ |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 358 | LIST_DEL(&bref->users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 359 | LIST_INIT(&bref->users); |
| 360 | if (s->list.n != &sessions) |
| 361 | 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] | 362 | bref->ref = s->list.n; |
| 363 | } |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 364 | LIST_DEL(&s->list); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 365 | pool_free2(pool2_session, s); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 366 | |
| 367 | /* 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] | 368 | if (fe && unlikely(fe->state == PR_STSTOPPED)) { |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 369 | pool_flush2(pool2_buffer); |
| 370 | pool_flush2(fe->hdr_idx_pool); |
| 371 | pool_flush2(pool2_requri); |
| 372 | pool_flush2(pool2_capture); |
| 373 | pool_flush2(pool2_session); |
| 374 | pool_flush2(fe->req_cap_pool); |
| 375 | pool_flush2(fe->rsp_cap_pool); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 376 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
| 380 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 381 | int init_session() |
| 382 | { |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 383 | LIST_INIT(&sessions); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 384 | pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); |
| 385 | return pool2_session != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 388 | void session_process_counters(struct session *s) |
| 389 | { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 390 | unsigned long long bytes; |
| 391 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 392 | if (s->req) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 393 | bytes = s->req->total - s->logs.bytes_in; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 394 | s->logs.bytes_in = s->req->total; |
| 395 | if (bytes) { |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 396 | s->fe->counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 397 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 398 | if (s->be != s->fe) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 399 | s->be->counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 400 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 401 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 402 | s->srv->counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 403 | |
| 404 | if (s->listener->counters) |
| 405 | s->listener->counters->bytes_in += bytes; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 406 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 409 | if (s->rep) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 410 | bytes = s->rep->total - s->logs.bytes_out; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 411 | s->logs.bytes_out = s->rep->total; |
| 412 | if (bytes) { |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 413 | s->fe->counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 414 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 415 | if (s->be != s->fe) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 416 | s->be->counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 417 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 418 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 419 | s->srv->counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 420 | |
| 421 | if (s->listener->counters) |
| 422 | s->listener->counters->bytes_out += bytes; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 423 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 424 | } |
| 425 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 426 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 427 | /* This function is called with (si->state == SI_ST_CON) meaning that a |
| 428 | * connection was attempted and that the file descriptor is already allocated. |
| 429 | * We must check for establishment, error and abort. Possible output states |
| 430 | * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and |
| 431 | * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER, |
| 432 | * otherwise 1. |
| 433 | */ |
| 434 | int sess_update_st_con_tcp(struct session *s, struct stream_interface *si) |
| 435 | { |
| 436 | struct buffer *req = si->ob; |
| 437 | struct buffer *rep = si->ib; |
| 438 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 439 | /* If we got an error, or if nothing happened and the connection timed |
| 440 | * out, we must give up. The CER state handler will take care of retry |
| 441 | * attempts and error reports. |
| 442 | */ |
| 443 | if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) { |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 444 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 445 | si->state = SI_ST_CER; |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 446 | si->flags &= ~SI_FL_CAP_SPLICE; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 447 | fd_delete(si->fd); |
| 448 | |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 449 | if (si->release) |
| 450 | si->release(si); |
| 451 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 452 | if (si->err_type) |
| 453 | return 0; |
| 454 | |
| 455 | si->err_loc = s->srv; |
| 456 | if (si->flags & SI_FL_ERR) |
| 457 | si->err_type = SI_ET_CONN_ERR; |
| 458 | else |
| 459 | si->err_type = SI_ET_CONN_TO; |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | /* OK, maybe we want to abort */ |
Willy Tarreau | 418fd47 | 2009-09-06 21:37:23 +0200 | [diff] [blame] | 464 | if (unlikely((rep->flags & BF_SHUTW) || |
| 465 | ((req->flags & BF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */ |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 466 | (((req->flags & (BF_OUT_EMPTY|BF_WRITE_ACTIVITY)) == BF_OUT_EMPTY) || |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 467 | s->be->options & PR_O_ABRT_CLOSE)))) { |
| 468 | /* give up */ |
| 469 | si->shutw(si); |
| 470 | si->err_type |= SI_ET_CONN_ABRT; |
| 471 | si->err_loc = s->srv; |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 472 | si->flags &= ~SI_FL_CAP_SPLICE; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 473 | if (s->srv_error) |
| 474 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 475 | return 1; |
| 476 | } |
| 477 | |
| 478 | /* we need to wait a bit more if there was no activity either */ |
| 479 | if (!(req->flags & BF_WRITE_ACTIVITY)) |
| 480 | return 1; |
| 481 | |
| 482 | /* OK, this means that a connection succeeded. The caller will be |
| 483 | * responsible for handling the transition from CON to EST. |
| 484 | */ |
| 485 | s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 486 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 487 | si->state = SI_ST_EST; |
| 488 | si->err_type = SI_ET_NONE; |
| 489 | si->err_loc = NULL; |
| 490 | return 1; |
| 491 | } |
| 492 | |
| 493 | /* This function is called with (si->state == SI_ST_CER) meaning that a |
| 494 | * previous connection attempt has failed and that the file descriptor |
| 495 | * has already been released. Possible causes include asynchronous error |
| 496 | * notification and time out. Possible output states are SI_ST_CLO when |
| 497 | * retries are exhausted, SI_ST_TAR when a delay is wanted before a new |
| 498 | * connection attempt, SI_ST_ASS when it's wise to retry on the same server, |
| 499 | * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are |
| 500 | * marked as in error state. It returns 0. |
| 501 | */ |
| 502 | int sess_update_st_cer(struct session *s, struct stream_interface *si) |
| 503 | { |
| 504 | /* we probably have to release last session from the server */ |
| 505 | if (s->srv) { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 506 | health_adjust(s->srv, HANA_STATUS_L4_ERR); |
| 507 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 508 | if (s->flags & SN_CURR_SESS) { |
| 509 | s->flags &= ~SN_CURR_SESS; |
| 510 | s->srv->cur_sess--; |
| 511 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* ensure that we have enough retries left */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 515 | si->conn_retries--; |
| 516 | if (si->conn_retries < 0) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 517 | if (!si->err_type) { |
| 518 | si->err_type = SI_ET_CONN_ERR; |
| 519 | si->err_loc = s->srv; |
| 520 | } |
| 521 | |
| 522 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 523 | s->srv->counters.failed_conns++; |
| 524 | s->be->counters.failed_conns++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 525 | if (may_dequeue_tasks(s->srv, s->be)) |
| 526 | process_srv_queue(s->srv); |
| 527 | |
| 528 | /* shutw is enough so stop a connecting socket */ |
| 529 | si->shutw(si); |
| 530 | si->ob->flags |= BF_WRITE_ERROR; |
| 531 | si->ib->flags |= BF_READ_ERROR; |
| 532 | |
| 533 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 534 | if (s->srv_error) |
| 535 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | /* If the "redispatch" option is set on the backend, we are allowed to |
| 540 | * retry on another server for the last retry. In order to achieve this, |
| 541 | * we must mark the session unassigned, and eventually clear the DIRECT |
| 542 | * bit to ignore any persistence cookie. We won't count a retry nor a |
| 543 | * redispatch yet, because this will depend on what server is selected. |
| 544 | */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 545 | if (s->srv && si->conn_retries == 0 && |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 546 | s->be->options & PR_O_REDISP && !(s->flags & SN_FORCE_PRST)) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 547 | if (may_dequeue_tasks(s->srv, s->be)) |
| 548 | process_srv_queue(s->srv); |
| 549 | |
| 550 | s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
| 551 | s->prev_srv = s->srv; |
| 552 | si->state = SI_ST_REQ; |
| 553 | } else { |
| 554 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 555 | s->srv->counters.retries++; |
| 556 | s->be->counters.retries++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 557 | si->state = SI_ST_ASS; |
| 558 | } |
| 559 | |
| 560 | if (si->flags & SI_FL_ERR) { |
| 561 | /* The error was an asynchronous connection error, and we will |
| 562 | * likely have to retry connecting to the same server, most |
| 563 | * likely leading to the same result. To avoid this, we wait |
| 564 | * one second before retrying. |
| 565 | */ |
| 566 | |
| 567 | if (!si->err_type) |
| 568 | si->err_type = SI_ET_CONN_ERR; |
| 569 | |
| 570 | si->state = SI_ST_TAR; |
| 571 | si->exp = tick_add(now_ms, MS_TO_TICKS(1000)); |
| 572 | return 0; |
| 573 | } |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* |
| 578 | * This function handles the transition between the SI_ST_CON state and the |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 579 | * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or |
| 580 | * SI_ST_INI) to SI_ST_EST, but only when a ->connect function is defined. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 581 | */ |
| 582 | void sess_establish(struct session *s, struct stream_interface *si) |
| 583 | { |
| 584 | struct buffer *req = si->ob; |
| 585 | struct buffer *rep = si->ib; |
| 586 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 587 | if (s->srv) |
| 588 | health_adjust(s->srv, HANA_STATUS_L4_OK); |
| 589 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 590 | if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 591 | /* if the user wants to log as soon as possible, without counting |
| 592 | * bytes from the server, then this is the right moment. */ |
| 593 | if (s->fe->to_log && !(s->logs.logwait & LW_BYTES)) { |
| 594 | 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] | 595 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 596 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 597 | } |
| 598 | else { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 599 | s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE; |
| 600 | /* reset hdr_idx which was already initialized by the request. |
| 601 | * right now, the http parser does it. |
| 602 | * hdr_idx_init(&s->txn.hdr_idx); |
| 603 | */ |
| 604 | } |
| 605 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 606 | rep->analysers |= s->fe->fe_rsp_ana | s->be->be_rsp_ana; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 607 | rep->flags |= BF_READ_ATTACHED; /* producer is now attached */ |
Willy Tarreau | d04e858 | 2010-05-31 12:31:35 +0200 | [diff] [blame] | 608 | if (si->connect) { |
| 609 | /* real connections have timeouts */ |
| 610 | req->wto = s->be->timeout.server; |
| 611 | rep->rto = s->be->timeout.server; |
| 612 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 613 | req->wex = TICK_ETERNITY; |
| 614 | } |
| 615 | |
| 616 | /* Update stream interface status for input states SI_ST_ASS, SI_ST_QUE, SI_ST_TAR. |
| 617 | * Other input states are simply ignored. |
| 618 | * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON. |
| 619 | * Flags must have previously been updated for timeouts and other conditions. |
| 620 | */ |
| 621 | void sess_update_stream_int(struct session *s, struct stream_interface *si) |
| 622 | { |
| 623 | 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", |
| 624 | now_ms, __FUNCTION__, |
| 625 | s, |
| 626 | s->req, s->rep, |
| 627 | s->req->rex, s->rep->wex, |
| 628 | s->req->flags, s->rep->flags, |
| 629 | s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state); |
| 630 | |
| 631 | if (si->state == SI_ST_ASS) { |
| 632 | /* Server assigned to connection request, we have to try to connect now */ |
| 633 | int conn_err; |
| 634 | |
| 635 | conn_err = connect_server(s); |
| 636 | if (conn_err == SN_ERR_NONE) { |
| 637 | /* state = SI_ST_CON now */ |
Willy Tarreau | 8f6457c | 2008-12-01 00:08:28 +0100 | [diff] [blame] | 638 | if (s->srv) |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 639 | srv_inc_sess_ctr(s->srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* We have received a synchronous error. We might have to |
| 644 | * abort, retry immediately or redispatch. |
| 645 | */ |
| 646 | if (conn_err == SN_ERR_INTERNAL) { |
| 647 | if (!si->err_type) { |
| 648 | si->err_type = SI_ET_CONN_OTHER; |
| 649 | si->err_loc = s->srv; |
| 650 | } |
| 651 | |
| 652 | if (s->srv) |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 653 | srv_inc_sess_ctr(s->srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 654 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 655 | s->srv->counters.failed_conns++; |
| 656 | s->be->counters.failed_conns++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 657 | |
| 658 | /* release other sessions waiting for this server */ |
| 659 | if (may_dequeue_tasks(s->srv, s->be)) |
| 660 | process_srv_queue(s->srv); |
| 661 | |
| 662 | /* Failed and not retryable. */ |
| 663 | si->shutr(si); |
| 664 | si->shutw(si); |
| 665 | si->ob->flags |= BF_WRITE_ERROR; |
| 666 | |
| 667 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 668 | |
| 669 | /* no session was ever accounted for this server */ |
| 670 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 671 | if (s->srv_error) |
| 672 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
| 676 | /* We are facing a retryable error, but we don't want to run a |
| 677 | * turn-around now, as the problem is likely a source port |
| 678 | * allocation problem, so we want to retry now. |
| 679 | */ |
| 680 | si->state = SI_ST_CER; |
| 681 | si->flags &= ~SI_FL_ERR; |
| 682 | sess_update_st_cer(s, si); |
| 683 | /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */ |
| 684 | return; |
| 685 | } |
| 686 | else if (si->state == SI_ST_QUE) { |
| 687 | /* connection request was queued, check for any update */ |
| 688 | if (!s->pend_pos) { |
| 689 | /* The connection is not in the queue anymore. Either |
| 690 | * we have a server connection slot available and we |
| 691 | * go directly to the assigned state, or we need to |
| 692 | * load-balance first and go to the INI state. |
| 693 | */ |
| 694 | si->exp = TICK_ETERNITY; |
| 695 | if (unlikely(!(s->flags & SN_ASSIGNED))) |
| 696 | si->state = SI_ST_REQ; |
| 697 | else { |
| 698 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 699 | si->state = SI_ST_ASS; |
| 700 | } |
| 701 | return; |
| 702 | } |
| 703 | |
| 704 | /* Connection request still in queue... */ |
| 705 | if (si->flags & SI_FL_EXP) { |
| 706 | /* ... and timeout expired */ |
| 707 | si->exp = TICK_ETERNITY; |
| 708 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 709 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 710 | s->srv->counters.failed_conns++; |
| 711 | s->be->counters.failed_conns++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 712 | si->shutr(si); |
| 713 | si->shutw(si); |
| 714 | si->ob->flags |= BF_WRITE_TIMEOUT; |
| 715 | if (!si->err_type) |
| 716 | si->err_type = SI_ET_QUEUE_TO; |
| 717 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 718 | if (s->srv_error) |
| 719 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 720 | return; |
| 721 | } |
| 722 | |
| 723 | /* Connection remains in queue, check if we have to abort it */ |
Willy Tarreau | 418fd47 | 2009-09-06 21:37:23 +0200 | [diff] [blame] | 724 | if ((si->ob->flags & (BF_READ_ERROR)) || |
| 725 | ((si->ob->flags & BF_SHUTW_NOW) && /* empty and client aborted */ |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 726 | (si->ob->flags & BF_OUT_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 727 | /* give up */ |
| 728 | si->exp = TICK_ETERNITY; |
| 729 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 730 | si->shutr(si); |
| 731 | si->shutw(si); |
| 732 | si->err_type |= SI_ET_QUEUE_ABRT; |
| 733 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 734 | if (s->srv_error) |
| 735 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 736 | return; |
| 737 | } |
| 738 | |
| 739 | /* Nothing changed */ |
| 740 | return; |
| 741 | } |
| 742 | else if (si->state == SI_ST_TAR) { |
| 743 | /* Connection request might be aborted */ |
Willy Tarreau | 418fd47 | 2009-09-06 21:37:23 +0200 | [diff] [blame] | 744 | if ((si->ob->flags & (BF_READ_ERROR)) || |
| 745 | ((si->ob->flags & BF_SHUTW_NOW) && /* empty and client aborted */ |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 746 | (si->ob->flags & BF_OUT_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 747 | /* give up */ |
| 748 | si->exp = TICK_ETERNITY; |
| 749 | si->shutr(si); |
| 750 | si->shutw(si); |
| 751 | si->err_type |= SI_ET_CONN_ABRT; |
| 752 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 753 | if (s->srv_error) |
| 754 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (!(si->flags & SI_FL_EXP)) |
| 759 | return; /* still in turn-around */ |
| 760 | |
| 761 | si->exp = TICK_ETERNITY; |
| 762 | |
| 763 | /* we keep trying on the same server as long as the session is |
| 764 | * marked "assigned". |
| 765 | * FIXME: Should we force a redispatch attempt when the server is down ? |
| 766 | */ |
| 767 | if (s->flags & SN_ASSIGNED) |
| 768 | si->state = SI_ST_ASS; |
| 769 | else |
| 770 | si->state = SI_ST_REQ; |
| 771 | return; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | /* This function initiates a server connection request on a stream interface |
| 776 | * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS, |
| 777 | * indicating that a server has been assigned. It may also return SI_ST_QUE, |
| 778 | * or SI_ST_CLO upon error. |
| 779 | */ |
| 780 | static void sess_prepare_conn_req(struct session *s, struct stream_interface *si) { |
| 781 | 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", |
| 782 | now_ms, __FUNCTION__, |
| 783 | s, |
| 784 | s->req, s->rep, |
| 785 | s->req->rex, s->rep->wex, |
| 786 | s->req->flags, s->rep->flags, |
| 787 | s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state); |
| 788 | |
| 789 | if (si->state != SI_ST_REQ) |
| 790 | return; |
| 791 | |
| 792 | /* Try to assign a server */ |
| 793 | if (srv_redispatch_connect(s) != 0) { |
| 794 | /* We did not get a server. Either we queued the |
| 795 | * connection request, or we encountered an error. |
| 796 | */ |
| 797 | if (si->state == SI_ST_QUE) |
| 798 | return; |
| 799 | |
| 800 | /* we did not get any server, let's check the cause */ |
| 801 | si->shutr(si); |
| 802 | si->shutw(si); |
| 803 | si->ob->flags |= BF_WRITE_ERROR; |
| 804 | if (!si->err_type) |
| 805 | si->err_type = SI_ET_CONN_OTHER; |
| 806 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 807 | if (s->srv_error) |
| 808 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 809 | return; |
| 810 | } |
| 811 | |
| 812 | /* The server is assigned */ |
| 813 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 814 | si->state = SI_ST_ASS; |
| 815 | } |
| 816 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 817 | /* This stream analyser checks the switching rules and changes the backend |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 818 | * if appropriate. The default_backend rule is also considered, then the |
| 819 | * target backend's forced persistence rules are also evaluated last if any. |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 820 | * It returns 1 if the processing can continue on next analysers, or zero if it |
| 821 | * either needs more data or wants to immediately abort the request. |
| 822 | */ |
| 823 | int process_switching_rules(struct session *s, struct buffer *req, int an_bit) |
| 824 | { |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 825 | struct persist_rule *prst_rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 826 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 827 | req->analysers &= ~an_bit; |
| 828 | req->analyse_exp = TICK_ETERNITY; |
| 829 | |
| 830 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 831 | now_ms, __FUNCTION__, |
| 832 | s, |
| 833 | req, |
| 834 | req->rex, req->wex, |
| 835 | req->flags, |
| 836 | req->l, |
| 837 | req->analysers); |
| 838 | |
| 839 | /* now check whether we have some switching rules for this request */ |
| 840 | if (!(s->flags & SN_BE_ASSIGNED)) { |
| 841 | struct switching_rule *rule; |
| 842 | |
| 843 | list_for_each_entry(rule, &s->fe->switching_rules, list) { |
| 844 | int ret; |
| 845 | |
| 846 | ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, ACL_DIR_REQ); |
| 847 | ret = acl_pass(ret); |
| 848 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 849 | ret = !ret; |
| 850 | |
| 851 | if (ret) { |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 852 | if (!session_set_backend(s, rule->be.backend)) |
| 853 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 854 | break; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | /* To ensure correct connection accounting on the backend, we |
| 859 | * have to assign one if it was not set (eg: a listen). This |
| 860 | * measure also takes care of correctly setting the default |
| 861 | * backend if any. |
| 862 | */ |
| 863 | if (!(s->flags & SN_BE_ASSIGNED)) |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 864 | if (!session_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be)) |
| 865 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 866 | } |
| 867 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 868 | /* we don't want to run the TCP or HTTP filters again if the backend has not changed */ |
| 869 | if (s->fe == s->be) { |
| 870 | s->req->analysers &= ~AN_REQ_INSPECT_BE; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 871 | s->req->analysers &= ~AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 872 | } |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 873 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 874 | /* as soon as we know the backend, we must check if we have a matching forced or ignored |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 875 | * persistence rule, and report that in the session. |
| 876 | */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 877 | list_for_each_entry(prst_rule, &s->be->persist_rules, list) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 878 | int ret = 1; |
| 879 | |
| 880 | if (prst_rule->cond) { |
| 881 | ret = acl_exec_cond(prst_rule->cond, s->be, s, &s->txn, ACL_DIR_REQ); |
| 882 | ret = acl_pass(ret); |
| 883 | if (prst_rule->cond->pol == ACL_COND_UNLESS) |
| 884 | ret = !ret; |
| 885 | } |
| 886 | |
| 887 | if (ret) { |
| 888 | /* no rule, or the rule matches */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 889 | if (prst_rule->type == PERSIST_TYPE_FORCE) { |
| 890 | s->flags |= SN_FORCE_PRST; |
| 891 | } else { |
| 892 | s->flags |= SN_IGNORE_PRST; |
| 893 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 894 | break; |
| 895 | } |
| 896 | } |
| 897 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 898 | return 1; |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 899 | |
| 900 | sw_failed: |
| 901 | /* immediately abort this request in case of allocation failure */ |
| 902 | buffer_abort(s->req); |
| 903 | buffer_abort(s->rep); |
| 904 | |
| 905 | if (!(s->flags & SN_ERR_MASK)) |
| 906 | s->flags |= SN_ERR_RESOURCE; |
| 907 | if (!(s->flags & SN_FINST_MASK)) |
| 908 | s->flags |= SN_FINST_R; |
| 909 | |
| 910 | s->txn.status = 500; |
| 911 | s->req->analysers = 0; |
| 912 | s->req->analyse_exp = TICK_ETERNITY; |
| 913 | return 0; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 914 | } |
| 915 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 916 | /* This stream analyser works on a request. It applies all sticking rules on |
| 917 | * it then returns 1. The data must already be present in the buffer otherwise |
| 918 | * they won't match. It always returns 1. |
| 919 | */ |
| 920 | int process_sticking_rules(struct session *s, struct buffer *req, int an_bit) |
| 921 | { |
| 922 | struct proxy *px = s->be; |
| 923 | struct sticking_rule *rule; |
| 924 | |
| 925 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 926 | now_ms, __FUNCTION__, |
| 927 | s, |
| 928 | req, |
| 929 | req->rex, req->wex, |
| 930 | req->flags, |
| 931 | req->l, |
| 932 | req->analysers); |
| 933 | |
| 934 | list_for_each_entry(rule, &px->sticking_rules, list) { |
| 935 | int ret = 1 ; |
| 936 | int i; |
| 937 | |
| 938 | for (i = 0; i < s->store_count; i++) { |
| 939 | if (rule->table.t == s->store[i].table) |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | if (i != s->store_count) |
| 944 | continue; |
| 945 | |
| 946 | if (rule->cond) { |
| 947 | ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_REQ); |
| 948 | ret = acl_pass(ret); |
| 949 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 950 | ret = !ret; |
| 951 | } |
| 952 | |
| 953 | if (ret) { |
| 954 | struct stktable_key *key; |
| 955 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 956 | key = stktable_fetch_key(px, s, &s->txn, PATTERN_FETCH_REQ, rule->expr, rule->table.t->type); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 957 | if (!key) |
| 958 | continue; |
| 959 | |
| 960 | if (rule->flags & STK_IS_MATCH) { |
| 961 | struct stksess *ts; |
| 962 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 963 | if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 964 | if (!(s->flags & SN_ASSIGNED)) { |
| 965 | struct eb32_node *node; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 966 | void *ptr; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 967 | |
| 968 | /* srv found in table */ |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 969 | ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID); |
| 970 | node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id)); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 971 | if (node) { |
| 972 | struct server *srv; |
| 973 | |
| 974 | srv = container_of(node, struct server, conf.id); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 975 | if ((srv->state & SRV_RUNNING) || |
| 976 | (px->options & PR_O_PERSIST) || |
| 977 | (s->flags & SN_FORCE_PRST)) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 978 | s->flags |= SN_DIRECT | SN_ASSIGNED; |
| 979 | s->srv = srv; |
| 980 | } |
| 981 | } |
| 982 | } |
Willy Tarreau | e8f6338 | 2010-07-13 15:20:24 +0200 | [diff] [blame] | 983 | stktable_touch(rule->table.t, ts); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | if (rule->flags & STK_IS_STORE) { |
| 987 | if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
| 988 | struct stksess *ts; |
| 989 | |
| 990 | ts = stksess_new(rule->table.t, key); |
| 991 | if (ts) { |
| 992 | s->store[s->store_count].table = rule->table.t; |
| 993 | s->store[s->store_count++].ts = ts; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | req->analysers &= ~an_bit; |
| 1001 | req->analyse_exp = TICK_ETERNITY; |
| 1002 | return 1; |
| 1003 | } |
| 1004 | |
| 1005 | /* This stream analyser works on a response. It applies all store rules on it |
| 1006 | * then returns 1. The data must already be present in the buffer otherwise |
| 1007 | * they won't match. It always returns 1. |
| 1008 | */ |
| 1009 | int process_store_rules(struct session *s, struct buffer *rep, int an_bit) |
| 1010 | { |
| 1011 | struct proxy *px = s->be; |
| 1012 | struct sticking_rule *rule; |
| 1013 | int i; |
| 1014 | |
| 1015 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 1016 | now_ms, __FUNCTION__, |
| 1017 | s, |
Willy Tarreau | 2e2b3eb | 2010-02-09 20:55:44 +0100 | [diff] [blame] | 1018 | rep, |
| 1019 | rep->rex, rep->wex, |
| 1020 | rep->flags, |
| 1021 | rep->l, |
| 1022 | rep->analysers); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1023 | |
| 1024 | list_for_each_entry(rule, &px->storersp_rules, list) { |
| 1025 | int ret = 1 ; |
| 1026 | int storereqidx = -1; |
| 1027 | |
| 1028 | for (i = 0; i < s->store_count; i++) { |
| 1029 | if (rule->table.t == s->store[i].table) { |
| 1030 | if (!(s->store[i].flags)) |
| 1031 | storereqidx = i; |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | if ((i != s->store_count) && (storereqidx == -1)) |
| 1037 | continue; |
| 1038 | |
| 1039 | if (rule->cond) { |
| 1040 | ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_RTR); |
| 1041 | ret = acl_pass(ret); |
| 1042 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1043 | ret = !ret; |
| 1044 | } |
| 1045 | |
| 1046 | if (ret) { |
| 1047 | struct stktable_key *key; |
| 1048 | |
Willy Tarreau | f0b38bf | 2010-06-06 13:22:23 +0200 | [diff] [blame] | 1049 | key = stktable_fetch_key(px, s, &s->txn, PATTERN_FETCH_RTR, rule->expr, rule->table.t->type); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1050 | if (!key) |
| 1051 | continue; |
| 1052 | |
| 1053 | if (storereqidx != -1) { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 1054 | stksess_setkey(s->store[storereqidx].table, s->store[storereqidx].ts, key); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1055 | s->store[storereqidx].flags = 1; |
| 1056 | } |
| 1057 | else if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
| 1058 | struct stksess *ts; |
| 1059 | |
| 1060 | ts = stksess_new(rule->table.t, key); |
| 1061 | if (ts) { |
| 1062 | s->store[s->store_count].table = rule->table.t; |
| 1063 | s->store[s->store_count].flags = 1; |
| 1064 | s->store[s->store_count++].ts = ts; |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /* process store request and store response */ |
| 1071 | for (i = 0; i < s->store_count; i++) { |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1072 | struct stksess *ts; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1073 | void *ptr; |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1074 | |
| 1075 | ts = stktable_lookup(s->store[i].table, s->store[i].ts); |
| 1076 | if (ts) { |
| 1077 | /* the entry already existed, we can free ours */ |
Willy Tarreau | e8f6338 | 2010-07-13 15:20:24 +0200 | [diff] [blame] | 1078 | stktable_touch(s->store[i].table, ts); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1079 | stksess_free(s->store[i].table, s->store[i].ts); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1080 | } |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1081 | else |
| 1082 | ts = stktable_store(s->store[i].table, s->store[i].ts); |
| 1083 | |
| 1084 | s->store[i].ts = NULL; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1085 | ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID); |
| 1086 | stktable_data_cast(ptr, server_id) = s->srv->puid; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1087 | } |
Willy Tarreau | 2a164ee | 2010-06-18 09:57:45 +0200 | [diff] [blame] | 1088 | s->store_count = 0; /* everything is stored */ |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1089 | |
| 1090 | rep->analysers &= ~an_bit; |
| 1091 | rep->analyse_exp = TICK_ETERNITY; |
| 1092 | return 1; |
| 1093 | } |
| 1094 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1095 | /* This macro is very specific to the function below. See the comments in |
| 1096 | * process_session() below to understand the logic and the tests. |
| 1097 | */ |
| 1098 | #define UPDATE_ANALYSERS(real, list, back, flag) { \ |
| 1099 | list = (((list) & ~(flag)) | ~(back)) & (real); \ |
| 1100 | back = real; \ |
| 1101 | if (!(list)) \ |
| 1102 | break; \ |
| 1103 | if (((list) ^ ((list) & ((list) - 1))) < (flag)) \ |
| 1104 | continue; \ |
| 1105 | } |
| 1106 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1107 | /* Processes the client, server, request and response jobs of a session task, |
| 1108 | * then puts it back to the wait queue in a clean state, or cleans up its |
| 1109 | * resources if it must be deleted. Returns in <next> the date the task wants |
| 1110 | * to be woken up, or TICK_ETERNITY. In order not to call all functions for |
| 1111 | * nothing too many times, the request and response buffers flags are monitored |
| 1112 | * and each function is called only if at least another function has changed at |
| 1113 | * least one flag it is interested in. |
| 1114 | */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1115 | struct task *process_session(struct task *t) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1116 | { |
| 1117 | struct session *s = t->context; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1118 | unsigned int rqf_last, rpf_last; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1119 | unsigned int rq_prod_last, rq_cons_last; |
| 1120 | unsigned int rp_cons_last, rp_prod_last; |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1121 | unsigned int req_ana_back; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1122 | |
| 1123 | //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__, |
| 1124 | // s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s->rep->flags); |
| 1125 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1126 | /* this data may be no longer valid, clear it */ |
| 1127 | memset(&s->txn.auth, 0, sizeof(s->txn.auth)); |
| 1128 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1129 | /* This flag must explicitly be set every time */ |
| 1130 | s->req->flags &= ~BF_READ_NOEXP; |
| 1131 | |
| 1132 | /* Keep a copy of req/rep flags so that we can detect shutdowns */ |
| 1133 | rqf_last = s->req->flags; |
| 1134 | rpf_last = s->rep->flags; |
| 1135 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1136 | /* we don't want the stream interface functions to recursively wake us up */ |
| 1137 | if (s->req->prod->owner == t) |
| 1138 | s->req->prod->flags |= SI_FL_DONT_WAKE; |
| 1139 | if (s->req->cons->owner == t) |
| 1140 | s->req->cons->flags |= SI_FL_DONT_WAKE; |
| 1141 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1142 | /* 1a: Check for low level timeouts if needed. We just set a flag on |
| 1143 | * stream interfaces when their timeouts have expired. |
| 1144 | */ |
| 1145 | if (unlikely(t->state & TASK_WOKEN_TIMER)) { |
| 1146 | stream_int_check_timeouts(&s->si[0]); |
| 1147 | stream_int_check_timeouts(&s->si[1]); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1148 | |
| 1149 | /* check buffer timeouts, and close the corresponding stream interfaces |
| 1150 | * for future reads or writes. Note: this will also concern upper layers |
| 1151 | * but we do not touch any other flag. We must be careful and correctly |
| 1152 | * detect state changes when calling them. |
| 1153 | */ |
| 1154 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1155 | buffer_check_timeouts(s->req); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1156 | |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1157 | if (unlikely((s->req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) { |
| 1158 | s->req->cons->flags |= SI_FL_NOLINGER; |
| 1159 | s->req->cons->shutw(s->req->cons); |
| 1160 | } |
| 1161 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1162 | if (unlikely((s->req->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT)) |
| 1163 | s->req->prod->shutr(s->req->prod); |
| 1164 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1165 | buffer_check_timeouts(s->rep); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1166 | |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1167 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) { |
| 1168 | s->rep->cons->flags |= SI_FL_NOLINGER; |
| 1169 | s->rep->cons->shutw(s->rep->cons); |
| 1170 | } |
| 1171 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1172 | if (unlikely((s->rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT)) |
| 1173 | s->rep->prod->shutr(s->rep->prod); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1174 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1175 | |
| 1176 | /* 1b: check for low-level errors reported at the stream interface. |
| 1177 | * First we check if it's a retryable error (in which case we don't |
| 1178 | * want to tell the buffer). Otherwise we report the error one level |
| 1179 | * upper by setting flags into the buffers. Note that the side towards |
| 1180 | * the client cannot have connect (hence retryable) errors. Also, the |
| 1181 | * connection setup code must be able to deal with any type of abort. |
| 1182 | */ |
| 1183 | if (unlikely(s->si[0].flags & SI_FL_ERR)) { |
| 1184 | if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) { |
| 1185 | s->si[0].shutr(&s->si[0]); |
| 1186 | s->si[0].shutw(&s->si[0]); |
| 1187 | stream_int_report_error(&s->si[0]); |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1188 | if (!(s->req->analysers) && !(s->rep->analysers)) { |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1189 | s->be->counters.cli_aborts++; |
| 1190 | if (s->srv) |
| 1191 | s->srv->counters.cli_aborts++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1192 | if (!(s->flags & SN_ERR_MASK)) |
| 1193 | s->flags |= SN_ERR_CLICL; |
| 1194 | if (!(s->flags & SN_FINST_MASK)) |
| 1195 | s->flags |= SN_FINST_D; |
| 1196 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | if (unlikely(s->si[1].flags & SI_FL_ERR)) { |
| 1201 | if (s->si[1].state == SI_ST_EST || s->si[1].state == SI_ST_DIS) { |
| 1202 | s->si[1].shutr(&s->si[1]); |
| 1203 | s->si[1].shutw(&s->si[1]); |
| 1204 | stream_int_report_error(&s->si[1]); |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1205 | s->be->counters.failed_resp++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1206 | if (s->srv) |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1207 | s->srv->counters.failed_resp++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1208 | if (!(s->req->analysers) && !(s->rep->analysers)) { |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1209 | s->be->counters.srv_aborts++; |
| 1210 | if (s->srv) |
| 1211 | s->srv->counters.srv_aborts++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1212 | if (!(s->flags & SN_ERR_MASK)) |
| 1213 | s->flags |= SN_ERR_SRVCL; |
| 1214 | if (!(s->flags & SN_FINST_MASK)) |
| 1215 | s->flags |= SN_FINST_D; |
| 1216 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1217 | } |
| 1218 | /* note: maybe we should process connection errors here ? */ |
| 1219 | } |
| 1220 | |
| 1221 | if (s->si[1].state == SI_ST_CON) { |
| 1222 | /* we were trying to establish a connection on the server side, |
| 1223 | * maybe it succeeded, maybe it failed, maybe we timed out, ... |
| 1224 | */ |
| 1225 | if (unlikely(!sess_update_st_con_tcp(s, &s->si[1]))) |
| 1226 | sess_update_st_cer(s, &s->si[1]); |
| 1227 | else if (s->si[1].state == SI_ST_EST) |
| 1228 | sess_establish(s, &s->si[1]); |
| 1229 | |
| 1230 | /* state is now one of SI_ST_CON (still in progress), SI_ST_EST |
| 1231 | * (established), SI_ST_DIS (abort), SI_ST_CLO (last error), |
| 1232 | * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors. |
| 1233 | */ |
| 1234 | } |
| 1235 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1236 | rq_prod_last = s->si[0].state; |
| 1237 | rq_cons_last = s->si[1].state; |
| 1238 | rp_cons_last = s->si[0].state; |
| 1239 | rp_prod_last = s->si[1].state; |
| 1240 | |
| 1241 | resync_stream_interface: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1242 | /* Check for connection closure */ |
| 1243 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1244 | DPRINTF(stderr, |
| 1245 | "[%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", |
| 1246 | now_ms, __FUNCTION__, __LINE__, |
| 1247 | t, |
| 1248 | s, s->flags, |
| 1249 | s->req, s->rep, |
| 1250 | s->req->rex, s->rep->wex, |
| 1251 | s->req->flags, s->rep->flags, |
| 1252 | s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state, |
| 1253 | s->rep->cons->err_type, s->req->cons->err_type, |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 1254 | s->req->cons->conn_retries); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1255 | |
| 1256 | /* nothing special to be done on client side */ |
| 1257 | if (unlikely(s->req->prod->state == SI_ST_DIS)) |
| 1258 | s->req->prod->state = SI_ST_CLO; |
| 1259 | |
| 1260 | /* When a server-side connection is released, we have to count it and |
| 1261 | * check for pending connections on this server. |
| 1262 | */ |
| 1263 | if (unlikely(s->req->cons->state == SI_ST_DIS)) { |
| 1264 | s->req->cons->state = SI_ST_CLO; |
| 1265 | if (s->srv) { |
| 1266 | if (s->flags & SN_CURR_SESS) { |
| 1267 | s->flags &= ~SN_CURR_SESS; |
| 1268 | s->srv->cur_sess--; |
| 1269 | } |
| 1270 | sess_change_server(s, NULL); |
| 1271 | if (may_dequeue_tasks(s->srv, s->be)) |
| 1272 | process_srv_queue(s->srv); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * Note: of the transient states (REQ, CER, DIS), only REQ may remain |
| 1278 | * at this point. |
| 1279 | */ |
| 1280 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1281 | resync_request: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1282 | /* Analyse request */ |
| 1283 | if ((s->req->flags & BF_MASK_ANALYSER) || |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1284 | ((s->req->flags ^ rqf_last) & BF_MASK_STATIC) || |
| 1285 | s->si[0].state != rq_prod_last || |
| 1286 | s->si[1].state != rq_cons_last) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1287 | unsigned int flags = s->req->flags; |
| 1288 | |
| 1289 | if (s->req->prod->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1290 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1291 | unsigned int ana_list; |
| 1292 | unsigned int ana_back; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1293 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1294 | /* it's up to the analysers to stop new connections, |
| 1295 | * disable reading or closing. Note: if an analyser |
| 1296 | * disables any of these bits, it is responsible for |
| 1297 | * enabling them again when it disables itself, so |
| 1298 | * that other analysers are called in similar conditions. |
| 1299 | */ |
| 1300 | buffer_auto_read(s->req); |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1301 | buffer_auto_connect(s->req); |
| 1302 | buffer_auto_close(s->req); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1303 | |
| 1304 | /* We will call all analysers for which a bit is set in |
| 1305 | * s->req->analysers, following the bit order from LSB |
| 1306 | * to MSB. The analysers must remove themselves from |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1307 | * the list when not needed. Any analyser may return 0 |
| 1308 | * to break out of the loop, either because of missing |
| 1309 | * data to take a decision, or because it decides to |
| 1310 | * kill the session. We loop at least once through each |
| 1311 | * analyser, and we may loop again if other analysers |
| 1312 | * are added in the middle. |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1313 | * |
| 1314 | * We build a list of analysers to run. We evaluate all |
| 1315 | * of these analysers in the order of the lower bit to |
| 1316 | * the higher bit. This ordering is very important. |
| 1317 | * An analyser will often add/remove other analysers, |
| 1318 | * including itself. Any changes to itself have no effect |
| 1319 | * on the loop. If it removes any other analysers, we |
| 1320 | * want those analysers not to be called anymore during |
| 1321 | * this loop. If it adds an analyser that is located |
| 1322 | * after itself, we want it to be scheduled for being |
| 1323 | * processed during the loop. If it adds an analyser |
| 1324 | * which is located before it, we want it to switch to |
| 1325 | * it immediately, even if it has already been called |
| 1326 | * once but removed since. |
| 1327 | * |
| 1328 | * In order to achieve this, we compare the analyser |
| 1329 | * list after the call with a copy of it before the |
| 1330 | * call. The work list is fed with analyser bits that |
| 1331 | * appeared during the call. Then we compare previous |
| 1332 | * work list with the new one, and check the bits that |
| 1333 | * appeared. If the lowest of these bits is lower than |
| 1334 | * the current bit, it means we have enabled a previous |
| 1335 | * analyser and must immediately loop again. |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1336 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1337 | |
| 1338 | ana_list = ana_back = s->req->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1339 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1340 | /* Warning! ensure that analysers are always placed in ascending order! */ |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1341 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1342 | if (ana_list & AN_REQ_INSPECT_FE) { |
| 1343 | if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_FE)) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1344 | break; |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1345 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_FE); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1346 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1347 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1348 | if (ana_list & AN_REQ_WAIT_HTTP) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1349 | if (!http_wait_for_request(s, s->req, AN_REQ_WAIT_HTTP)) |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1350 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1351 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_WAIT_HTTP); |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1354 | if (ana_list & AN_REQ_HTTP_PROCESS_FE) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1355 | if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_FE, s->fe)) |
| 1356 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1357 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1360 | if (ana_list & AN_REQ_SWITCHING_RULES) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1361 | if (!process_switching_rules(s, s->req, AN_REQ_SWITCHING_RULES)) |
| 1362 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1363 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_SWITCHING_RULES); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1366 | if (ana_list & AN_REQ_INSPECT_BE) { |
| 1367 | if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_BE)) |
| 1368 | break; |
| 1369 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_BE); |
| 1370 | } |
| 1371 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1372 | if (ana_list & AN_REQ_HTTP_PROCESS_BE) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1373 | if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_BE, s->be)) |
| 1374 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1375 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1378 | if (ana_list & AN_REQ_HTTP_TARPIT) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1379 | if (!http_process_tarpit(s, s->req, AN_REQ_HTTP_TARPIT)) |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1380 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1381 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_TARPIT); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1382 | } |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1383 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1384 | if (ana_list & AN_REQ_HTTP_INNER) { |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1385 | if (!http_process_request(s, s->req, AN_REQ_HTTP_INNER)) |
| 1386 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1387 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_INNER); |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1390 | if (ana_list & AN_REQ_HTTP_BODY) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1391 | if (!http_process_request_body(s, s->req, AN_REQ_HTTP_BODY)) |
Willy Tarreau | d34af78 | 2008-11-30 23:36:37 +0100 | [diff] [blame] | 1392 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1393 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_BODY); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1394 | } |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1395 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1396 | if (ana_list & AN_REQ_PRST_RDP_COOKIE) { |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1397 | if (!tcp_persist_rdp_cookie(s, s->req, AN_REQ_PRST_RDP_COOKIE)) |
| 1398 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1399 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1400 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1401 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1402 | if (ana_list & AN_REQ_STICKING_RULES) { |
| 1403 | if (!process_sticking_rules(s, s->req, AN_REQ_STICKING_RULES)) |
| 1404 | break; |
| 1405 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_STICKING_RULES); |
| 1406 | } |
| 1407 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1408 | if (ana_list & AN_REQ_HTTP_XFER_BODY) { |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1409 | if (!http_request_forward_body(s, s->req, AN_REQ_HTTP_XFER_BODY)) |
| 1410 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1411 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1412 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1413 | break; |
| 1414 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1415 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1416 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1417 | rq_prod_last = s->si[0].state; |
| 1418 | rq_cons_last = s->si[1].state; |
| 1419 | rqf_last = s->req->flags; |
| 1420 | |
| 1421 | if ((s->req->flags ^ flags) & BF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1422 | goto resync_request; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1425 | /* we'll monitor the request analysers while parsing the response, |
| 1426 | * because some response analysers may indirectly enable new request |
| 1427 | * analysers (eg: HTTP keep-alive). |
| 1428 | */ |
| 1429 | req_ana_back = s->req->analysers; |
| 1430 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1431 | resync_response: |
| 1432 | /* Analyse response */ |
| 1433 | |
| 1434 | if (unlikely(s->rep->flags & BF_HIJACK)) { |
| 1435 | /* In inject mode, we wake up everytime something has |
| 1436 | * happened on the write side of the buffer. |
| 1437 | */ |
| 1438 | unsigned int flags = s->rep->flags; |
| 1439 | |
| 1440 | if ((s->rep->flags & (BF_WRITE_PARTIAL|BF_WRITE_ERROR|BF_SHUTW)) && |
| 1441 | !(s->rep->flags & BF_FULL)) { |
| 1442 | s->rep->hijacker(s, s->rep); |
| 1443 | } |
| 1444 | |
| 1445 | if ((s->rep->flags ^ flags) & BF_MASK_STATIC) { |
| 1446 | rpf_last = s->rep->flags; |
| 1447 | goto resync_response; |
| 1448 | } |
| 1449 | } |
| 1450 | else if ((s->rep->flags & BF_MASK_ANALYSER) || |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1451 | (s->rep->flags ^ rpf_last) & BF_MASK_STATIC || |
| 1452 | s->si[0].state != rp_cons_last || |
| 1453 | s->si[1].state != rp_prod_last) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1454 | unsigned int flags = s->rep->flags; |
| 1455 | |
| 1456 | if (s->rep->prod->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1457 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1458 | unsigned int ana_list; |
| 1459 | unsigned int ana_back; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1460 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1461 | /* it's up to the analysers to stop disable reading or |
| 1462 | * closing. Note: if an analyser disables any of these |
| 1463 | * bits, it is responsible for enabling them again when |
| 1464 | * it disables itself, so that other analysers are called |
| 1465 | * in similar conditions. |
| 1466 | */ |
| 1467 | buffer_auto_read(s->rep); |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1468 | buffer_auto_close(s->rep); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1469 | |
| 1470 | /* We will call all analysers for which a bit is set in |
| 1471 | * s->rep->analysers, following the bit order from LSB |
| 1472 | * to MSB. The analysers must remove themselves from |
| 1473 | * the list when not needed. Any analyser may return 0 |
| 1474 | * to break out of the loop, either because of missing |
| 1475 | * data to take a decision, or because it decides to |
| 1476 | * kill the session. We loop at least once through each |
| 1477 | * analyser, and we may loop again if other analysers |
| 1478 | * are added in the middle. |
| 1479 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1480 | |
| 1481 | ana_list = ana_back = s->rep->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1482 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1483 | /* Warning! ensure that analysers are always placed in ascending order! */ |
| 1484 | |
| 1485 | if (ana_list & AN_RES_WAIT_HTTP) { |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1486 | if (!http_wait_for_response(s, s->rep, AN_RES_WAIT_HTTP)) |
| 1487 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1488 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_WAIT_HTTP); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1489 | } |
| 1490 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1491 | if (ana_list & AN_RES_STORE_RULES) { |
| 1492 | if (!process_store_rules(s, s->rep, AN_RES_STORE_RULES)) |
| 1493 | break; |
| 1494 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_STORE_RULES); |
| 1495 | } |
| 1496 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1497 | if (ana_list & AN_RES_HTTP_PROCESS_BE) { |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1498 | if (!http_process_res_common(s, s->rep, AN_RES_HTTP_PROCESS_BE, s->be)) |
| 1499 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1500 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1501 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1502 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1503 | if (ana_list & AN_RES_HTTP_XFER_BODY) { |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1504 | if (!http_response_forward_body(s, s->rep, AN_RES_HTTP_XFER_BODY)) |
| 1505 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1506 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1507 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1508 | break; |
| 1509 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1510 | } |
| 1511 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1512 | rp_cons_last = s->si[0].state; |
| 1513 | rp_prod_last = s->si[1].state; |
| 1514 | rpf_last = s->rep->flags; |
| 1515 | |
| 1516 | if ((s->rep->flags ^ flags) & BF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1517 | goto resync_response; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1520 | /* maybe someone has added some request analysers, so we must check and loop */ |
| 1521 | if (s->req->analysers & ~req_ana_back) |
| 1522 | goto resync_request; |
| 1523 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1524 | /* FIXME: here we should call protocol handlers which rely on |
| 1525 | * both buffers. |
| 1526 | */ |
| 1527 | |
| 1528 | |
| 1529 | /* |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1530 | * Now we propagate unhandled errors to the session. Normally |
| 1531 | * we're just in a data phase here since it means we have not |
| 1532 | * seen any analyser who could set an error status. |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1533 | */ |
| 1534 | if (!(s->flags & SN_ERR_MASK)) { |
| 1535 | if (s->req->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) { |
| 1536 | /* 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] | 1537 | s->req->analysers = 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1538 | if (s->req->flags & BF_READ_ERROR) { |
| 1539 | s->be->counters.cli_aborts++; |
| 1540 | if (s->srv) |
| 1541 | s->srv->counters.cli_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1542 | s->flags |= SN_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1543 | } |
| 1544 | else if (s->req->flags & BF_READ_TIMEOUT) { |
| 1545 | s->be->counters.cli_aborts++; |
| 1546 | if (s->srv) |
| 1547 | s->srv->counters.cli_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1548 | s->flags |= SN_ERR_CLITO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1549 | } |
| 1550 | else if (s->req->flags & BF_WRITE_ERROR) { |
| 1551 | s->be->counters.srv_aborts++; |
| 1552 | if (s->srv) |
| 1553 | s->srv->counters.srv_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1554 | s->flags |= SN_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1555 | } |
| 1556 | else { |
| 1557 | s->be->counters.srv_aborts++; |
| 1558 | if (s->srv) |
| 1559 | s->srv->counters.srv_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1560 | s->flags |= SN_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1561 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1562 | sess_set_term_flags(s); |
| 1563 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1564 | else if (s->rep->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) { |
| 1565 | /* Report it if the server got an error or a read timeout expired */ |
| 1566 | s->rep->analysers = 0; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1567 | if (s->rep->flags & BF_READ_ERROR) { |
| 1568 | s->be->counters.srv_aborts++; |
| 1569 | if (s->srv) |
| 1570 | s->srv->counters.srv_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1571 | s->flags |= SN_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1572 | } |
| 1573 | else if (s->rep->flags & BF_READ_TIMEOUT) { |
| 1574 | s->be->counters.srv_aborts++; |
| 1575 | if (s->srv) |
| 1576 | s->srv->counters.srv_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1577 | s->flags |= SN_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1578 | } |
| 1579 | else if (s->rep->flags & BF_WRITE_ERROR) { |
| 1580 | s->be->counters.cli_aborts++; |
| 1581 | if (s->srv) |
| 1582 | s->srv->counters.cli_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1583 | s->flags |= SN_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1584 | } |
| 1585 | else { |
| 1586 | s->be->counters.cli_aborts++; |
| 1587 | if (s->srv) |
| 1588 | s->srv->counters.cli_aborts++; |
| 1589 | s->flags |= SN_ERR_CLITO; |
| 1590 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1591 | sess_set_term_flags(s); |
| 1592 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1595 | /* |
| 1596 | * Here we take care of forwarding unhandled data. This also includes |
| 1597 | * connection establishments and shutdown requests. |
| 1598 | */ |
| 1599 | |
| 1600 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1601 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1602 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1603 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1604 | if (!s->req->analysers && |
Willy Tarreau | 82eeaf2 | 2009-12-29 12:09:05 +0100 | [diff] [blame] | 1605 | !(s->req->flags & (BF_HIJACK|BF_SHUTW|BF_SHUTW_NOW)) && |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1606 | (s->req->prod->state >= SI_ST_EST) && |
| 1607 | (s->req->to_forward != BUF_INFINITE_FORWARD)) { |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1608 | /* This buffer is freewheeling, there's no analyser nor hijacker |
| 1609 | * attached to it. If any data are left in, we'll permit them to |
| 1610 | * move. |
| 1611 | */ |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1612 | buffer_auto_read(s->req); |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1613 | buffer_auto_connect(s->req); |
| 1614 | buffer_auto_close(s->req); |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1615 | buffer_flush(s->req); |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 1616 | |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1617 | /* If the producer is still connected, we'll enable data to flow |
| 1618 | * from the producer to the consumer (which might possibly not be |
| 1619 | * connected yet). |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1620 | */ |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1621 | if (!(s->req->flags & (BF_SHUTR|BF_SHUTW|BF_SHUTW_NOW))) |
| 1622 | buffer_forward(s->req, BUF_INFINITE_FORWARD); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1623 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 1624 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1625 | /* check if it is wise to enable kernel splicing to forward request data */ |
| 1626 | if (!(s->req->flags & (BF_KERN_SPLICING|BF_SHUTR)) && |
| 1627 | s->req->to_forward && |
| 1628 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 1629 | (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1630 | (pipes_used < global.maxpipes) && |
| 1631 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) || |
| 1632 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
| 1633 | (s->req->flags & BF_STREAMER_FAST)))) { |
| 1634 | s->req->flags |= BF_KERN_SPLICING; |
| 1635 | } |
| 1636 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1637 | /* reflect what the L7 analysers have seen last */ |
| 1638 | rqf_last = s->req->flags; |
| 1639 | |
| 1640 | /* |
| 1641 | * Now forward all shutdown requests between both sides of the buffer |
| 1642 | */ |
| 1643 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1644 | /* first, let's check if the request buffer needs to shutdown(write), which may |
| 1645 | * happen either because the input is closed or because we want to force a close |
Willy Tarreau | e459976 | 2010-03-21 23:25:09 +0100 | [diff] [blame] | 1646 | * once the server has begun to respond. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1647 | */ |
Willy Tarreau | 82eeaf2 | 2009-12-29 12:09:05 +0100 | [diff] [blame] | 1648 | if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK|BF_AUTO_CLOSE|BF_SHUTR)) == |
Willy Tarreau | e459976 | 2010-03-21 23:25:09 +0100 | [diff] [blame] | 1649 | (BF_AUTO_CLOSE|BF_SHUTR))) |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 1650 | buffer_shutw_now(s->req); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1651 | |
| 1652 | /* shutdown(write) pending */ |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 1653 | if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_OUT_EMPTY)) == (BF_SHUTW_NOW|BF_OUT_EMPTY))) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1654 | s->req->cons->shutw(s->req->cons); |
| 1655 | |
| 1656 | /* shutdown(write) done on server side, we must stop the client too */ |
Willy Tarreau | 3dbc694 | 2008-12-07 13:05:04 +0100 | [diff] [blame] | 1657 | if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW && |
| 1658 | !s->req->analysers)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1659 | buffer_shutr_now(s->req); |
| 1660 | |
| 1661 | /* shutdown(read) pending */ |
| 1662 | if (unlikely((s->req->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW)) |
| 1663 | s->req->prod->shutr(s->req->prod); |
| 1664 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1665 | /* it's possible that an upper layer has requested a connection setup or abort. |
| 1666 | * There are 2 situations where we decide to establish a new connection : |
| 1667 | * - there are data scheduled for emission in the buffer |
| 1668 | * - the BF_AUTO_CONNECT flag is set (active connection) |
| 1669 | */ |
| 1670 | if (s->req->cons->state == SI_ST_INI) { |
Willy Tarreau | e459976 | 2010-03-21 23:25:09 +0100 | [diff] [blame] | 1671 | if (!(s->req->flags & BF_SHUTW)) { |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 1672 | if ((s->req->flags & (BF_AUTO_CONNECT|BF_OUT_EMPTY)) != BF_OUT_EMPTY) { |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 1673 | /* If we have an iohandler without a connect method, we immediately |
| 1674 | * switch to the connected state, otherwise we perform a connection |
| 1675 | * request. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1676 | */ |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 1677 | s->req->cons->state = SI_ST_REQ; /* new connection requested */ |
Willy Tarreau | 070ceb6 | 2010-06-01 10:36:43 +0200 | [diff] [blame] | 1678 | s->req->cons->conn_retries = s->be->conn_retries; |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 1679 | if (unlikely(s->req->cons->iohandler && !s->req->cons->connect)) { |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1680 | s->req->cons->state = SI_ST_EST; /* connection established */ |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 1681 | s->rep->flags |= BF_READ_ATTACHED; /* producer is now attached */ |
| 1682 | s->req->wex = TICK_ETERNITY; |
| 1683 | } |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1684 | } |
Willy Tarreau | 7320122 | 2009-08-16 18:27:24 +0200 | [diff] [blame] | 1685 | } |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 1686 | else { |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 1687 | s->req->cons->state = SI_ST_CLO; /* shutw+ini = abort */ |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 1688 | buffer_shutw_now(s->req); /* fix buffer flags upon abort */ |
| 1689 | buffer_shutr_now(s->rep); |
| 1690 | } |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1693 | |
| 1694 | /* we may have a pending connection request, or a connection waiting |
| 1695 | * for completion. |
| 1696 | */ |
| 1697 | if (s->si[1].state >= SI_ST_REQ && s->si[1].state < SI_ST_CON) { |
| 1698 | do { |
| 1699 | /* nb: step 1 might switch from QUE to ASS, but we first want |
| 1700 | * to give a chance to step 2 to perform a redirect if needed. |
| 1701 | */ |
| 1702 | if (s->si[1].state != SI_ST_REQ) |
| 1703 | sess_update_stream_int(s, &s->si[1]); |
| 1704 | if (s->si[1].state == SI_ST_REQ) |
| 1705 | sess_prepare_conn_req(s, &s->si[1]); |
| 1706 | |
| 1707 | if (s->si[1].state == SI_ST_ASS && s->srv && |
| 1708 | s->srv->rdr_len && (s->flags & SN_REDIRECTABLE)) |
| 1709 | perform_http_redirect(s, &s->si[1]); |
| 1710 | } while (s->si[1].state == SI_ST_ASS); |
| 1711 | } |
| 1712 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1713 | /* 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] | 1714 | 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] | 1715 | goto resync_stream_interface; |
| 1716 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1717 | /* otherwise we want to check if we need to resync the req buffer or not */ |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1718 | if ((s->req->flags ^ rqf_last) & BF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1719 | goto resync_request; |
| 1720 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1721 | /* perform output updates to the response buffer */ |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1722 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1723 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1724 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1725 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1726 | if (!s->rep->analysers && |
Willy Tarreau | 82eeaf2 | 2009-12-29 12:09:05 +0100 | [diff] [blame] | 1727 | !(s->rep->flags & (BF_HIJACK|BF_SHUTW|BF_SHUTW_NOW)) && |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1728 | (s->rep->prod->state >= SI_ST_EST) && |
| 1729 | (s->rep->to_forward != BUF_INFINITE_FORWARD)) { |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1730 | /* This buffer is freewheeling, there's no analyser nor hijacker |
| 1731 | * attached to it. If any data are left in, we'll permit them to |
| 1732 | * move. |
| 1733 | */ |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1734 | buffer_auto_read(s->rep); |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1735 | buffer_auto_close(s->rep); |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1736 | buffer_flush(s->rep); |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1737 | if (!(s->rep->flags & (BF_SHUTR|BF_SHUTW|BF_SHUTW_NOW))) |
| 1738 | buffer_forward(s->rep, BUF_INFINITE_FORWARD); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1739 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 1740 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1741 | /* check if it is wise to enable kernel splicing to forward response data */ |
| 1742 | if (!(s->rep->flags & (BF_KERN_SPLICING|BF_SHUTR)) && |
| 1743 | s->rep->to_forward && |
| 1744 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 1745 | (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1746 | (pipes_used < global.maxpipes) && |
| 1747 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) || |
| 1748 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
| 1749 | (s->rep->flags & BF_STREAMER_FAST)))) { |
| 1750 | s->rep->flags |= BF_KERN_SPLICING; |
| 1751 | } |
| 1752 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1753 | /* reflect what the L7 analysers have seen last */ |
| 1754 | rpf_last = s->rep->flags; |
| 1755 | |
| 1756 | /* |
| 1757 | * Now forward all shutdown requests between both sides of the buffer |
| 1758 | */ |
| 1759 | |
| 1760 | /* |
| 1761 | * FIXME: this is probably where we should produce error responses. |
| 1762 | */ |
| 1763 | |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1764 | /* first, let's check if the response buffer needs to shutdown(write) */ |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1765 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK|BF_AUTO_CLOSE|BF_SHUTR)) == |
| 1766 | (BF_AUTO_CLOSE|BF_SHUTR))) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1767 | buffer_shutw_now(s->rep); |
| 1768 | |
| 1769 | /* shutdown(write) pending */ |
Willy Tarreau | ba0b63d | 2009-09-20 08:09:44 +0200 | [diff] [blame] | 1770 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_OUT_EMPTY|BF_SHUTW_NOW)) == (BF_OUT_EMPTY|BF_SHUTW_NOW))) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1771 | s->rep->cons->shutw(s->rep->cons); |
| 1772 | |
| 1773 | /* 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] | 1774 | if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW) && |
| 1775 | !s->rep->analysers) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1776 | buffer_shutr_now(s->rep); |
| 1777 | |
| 1778 | /* shutdown(read) pending */ |
| 1779 | if (unlikely((s->rep->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW)) |
| 1780 | s->rep->prod->shutr(s->rep->prod); |
| 1781 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1782 | 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] | 1783 | goto resync_stream_interface; |
| 1784 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1785 | if (s->req->flags != rqf_last) |
| 1786 | goto resync_request; |
| 1787 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1788 | if ((s->rep->flags ^ rpf_last) & BF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1789 | goto resync_response; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1790 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1791 | /* we're interested in getting wakeups again */ |
| 1792 | s->req->prod->flags &= ~SI_FL_DONT_WAKE; |
| 1793 | s->req->cons->flags &= ~SI_FL_DONT_WAKE; |
| 1794 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1795 | /* This is needed only when debugging is enabled, to indicate |
| 1796 | * client-side or server-side close. Please note that in the unlikely |
| 1797 | * event where both sides would close at once, the sequence is reported |
| 1798 | * on the server side first. |
| 1799 | */ |
| 1800 | if (unlikely((global.mode & MODE_DEBUG) && |
| 1801 | (!(global.mode & MODE_QUIET) || |
| 1802 | (global.mode & MODE_VERBOSE)))) { |
| 1803 | int len; |
| 1804 | |
| 1805 | if (s->si[1].state == SI_ST_CLO && |
| 1806 | s->si[1].prev_state == SI_ST_EST) { |
| 1807 | len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n", |
| 1808 | s->uniq_id, s->be->id, |
| 1809 | (unsigned short)s->si[0].fd, |
| 1810 | (unsigned short)s->si[1].fd); |
| 1811 | write(1, trash, len); |
| 1812 | } |
| 1813 | |
| 1814 | if (s->si[0].state == SI_ST_CLO && |
| 1815 | s->si[0].prev_state == SI_ST_EST) { |
| 1816 | len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n", |
| 1817 | s->uniq_id, s->be->id, |
| 1818 | (unsigned short)s->si[0].fd, |
| 1819 | (unsigned short)s->si[1].fd); |
| 1820 | write(1, trash, len); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | if (likely((s->rep->cons->state != SI_ST_CLO) || |
| 1825 | (s->req->cons->state > SI_ST_INI && s->req->cons->state < SI_ST_CLO))) { |
| 1826 | |
| 1827 | if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED)) |
| 1828 | session_process_counters(s); |
| 1829 | |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1830 | if (s->rep->cons->state == SI_ST_EST && !s->rep->cons->iohandler) |
Willy Tarreau | dc85b39 | 2009-08-18 07:38:19 +0200 | [diff] [blame] | 1831 | s->rep->cons->update(s->rep->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1832 | |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1833 | if (s->req->cons->state == SI_ST_EST && !s->req->cons->iohandler) |
Willy Tarreau | dc85b39 | 2009-08-18 07:38:19 +0200 | [diff] [blame] | 1834 | s->req->cons->update(s->req->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1835 | |
Willy Tarreau | a6eebb3 | 2010-06-04 11:40:20 +0200 | [diff] [blame] | 1836 | s->req->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_READ_ATTACHED); |
| 1837 | s->rep->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_READ_ATTACHED); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1838 | s->si[0].prev_state = s->si[0].state; |
| 1839 | s->si[1].prev_state = s->si[1].state; |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 1840 | s->si[0].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
| 1841 | s->si[1].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1842 | |
| 1843 | /* Trick: if a request is being waiting for the server to respond, |
| 1844 | * and if we know the server can timeout, we don't want the timeout |
| 1845 | * to expire on the client side first, but we're still interested |
| 1846 | * in passing data from the client to the server (eg: POST). Thus, |
| 1847 | * we can cancel the client's request timeout if the server's |
| 1848 | * request timeout is set and the server has not yet sent a response. |
| 1849 | */ |
| 1850 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 1851 | if ((s->rep->flags & (BF_AUTO_CLOSE|BF_SHUTR)) == 0 && |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 1852 | (tick_isset(s->req->wex) || tick_isset(s->rep->rex))) { |
| 1853 | s->req->flags |= BF_READ_NOEXP; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1854 | s->req->rex = TICK_ETERNITY; |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 1855 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1856 | |
Willy Tarreau | 7a20aa6 | 2010-07-13 16:30:45 +0200 | [diff] [blame] | 1857 | /* Call the stream interfaces' I/O handlers when embedded. |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1858 | * Note that this one may wake the task up again. |
| 1859 | */ |
Willy Tarreau | 7a20aa6 | 2010-07-13 16:30:45 +0200 | [diff] [blame] | 1860 | if (s->req->cons->iohandler || s->rep->cons->iohandler) { |
| 1861 | if (s->req->cons->iohandler) |
| 1862 | s->req->cons->iohandler(s->req->cons); |
| 1863 | if (s->rep->cons->iohandler) |
| 1864 | s->rep->cons->iohandler(s->rep->cons); |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1865 | if (task_in_rq(t)) { |
| 1866 | /* If we woke up, we don't want to requeue the |
| 1867 | * task to the wait queue, but rather requeue |
| 1868 | * it into the runqueue ASAP. |
| 1869 | */ |
| 1870 | t->expire = TICK_ETERNITY; |
| 1871 | return t; |
| 1872 | } |
| 1873 | } |
| 1874 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1875 | t->expire = tick_first(tick_first(s->req->rex, s->req->wex), |
| 1876 | tick_first(s->rep->rex, s->rep->wex)); |
| 1877 | if (s->req->analysers) |
| 1878 | t->expire = tick_first(t->expire, s->req->analyse_exp); |
| 1879 | |
| 1880 | if (s->si[0].exp) |
| 1881 | t->expire = tick_first(t->expire, s->si[0].exp); |
| 1882 | |
| 1883 | if (s->si[1].exp) |
| 1884 | t->expire = tick_first(t->expire, s->si[1].exp); |
| 1885 | |
| 1886 | #ifdef DEBUG_FULL |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 1887 | fprintf(stderr, |
| 1888 | "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u" |
| 1889 | " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n", |
| 1890 | now_ms, t->expire, s->req->rex, s->req->wex, s->req->analyse_exp, |
| 1891 | 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] | 1892 | #endif |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1893 | |
| 1894 | #ifdef DEBUG_DEV |
| 1895 | /* 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] | 1896 | if (!tick_isset(t->expire)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1897 | ABORT_NOW(); |
| 1898 | #endif |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1899 | return t; /* nothing more to do */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | s->fe->feconn--; |
| 1903 | if (s->flags & SN_BE_ASSIGNED) |
| 1904 | s->be->beconn--; |
| 1905 | actconn--; |
Willy Tarreau | 6e6fb2b | 2009-08-16 18:20:44 +0200 | [diff] [blame] | 1906 | s->listener->nbconn--; |
| 1907 | if (s->listener->state == LI_FULL && |
| 1908 | s->listener->nbconn < s->listener->maxconn) { |
| 1909 | /* we should reactivate the listener */ |
| 1910 | EV_FD_SET(s->listener->fd, DIR_RD); |
| 1911 | s->listener->state = LI_READY; |
| 1912 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1913 | |
| 1914 | if (unlikely((global.mode & MODE_DEBUG) && |
| 1915 | (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
| 1916 | int len; |
Willy Tarreau | ec22b2c | 2009-03-06 13:07:40 +0100 | [diff] [blame] | 1917 | len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1918 | s->uniq_id, s->be->id, |
Willy Tarreau | ec22b2c | 2009-03-06 13:07:40 +0100 | [diff] [blame] | 1919 | (unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1920 | write(1, trash, len); |
| 1921 | } |
| 1922 | |
| 1923 | s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 1924 | session_process_counters(s); |
| 1925 | |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1926 | if (s->txn.status) { |
| 1927 | int n; |
| 1928 | |
| 1929 | n = s->txn.status / 100; |
| 1930 | if (n < 1 || n > 5) |
| 1931 | n = 0; |
| 1932 | |
| 1933 | if (s->fe->mode == PR_MODE_HTTP) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1934 | s->fe->counters.fe.http.rsp[n]++; |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1935 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1936 | if ((s->flags & SN_BE_ASSIGNED) && |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1937 | (s->be->mode == PR_MODE_HTTP)) |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 1938 | s->be->counters.be.http.rsp[n]++; |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1941 | /* let's do a final log if we need it */ |
| 1942 | if (s->logs.logwait && |
| 1943 | !(s->flags & SN_MONITOR) && |
| 1944 | (!(s->fe->options & PR_O_NULLNOLOG) || s->req->total)) { |
Willy Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 1945 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /* the task MUST not be in the run queue anymore */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1949 | session_free(s); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1950 | task_delete(t); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1951 | task_free(t); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1952 | return NULL; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1955 | /* |
| 1956 | * This function adjusts sess->srv_conn and maintains the previous and new |
| 1957 | * server's served session counts. Setting newsrv to NULL is enough to release |
| 1958 | * current connection slot. This function also notifies any LB algo which might |
| 1959 | * expect to be informed about any change in the number of active sessions on a |
| 1960 | * server. |
| 1961 | */ |
| 1962 | void sess_change_server(struct session *sess, struct server *newsrv) |
| 1963 | { |
| 1964 | if (sess->srv_conn == newsrv) |
| 1965 | return; |
| 1966 | |
| 1967 | if (sess->srv_conn) { |
| 1968 | sess->srv_conn->served--; |
| 1969 | if (sess->srv_conn->proxy->lbprm.server_drop_conn) |
| 1970 | sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn); |
| 1971 | sess->srv_conn = NULL; |
| 1972 | } |
| 1973 | |
| 1974 | if (newsrv) { |
| 1975 | newsrv->served++; |
| 1976 | if (newsrv->proxy->lbprm.server_take_conn) |
| 1977 | newsrv->proxy->lbprm.server_take_conn(newsrv); |
| 1978 | sess->srv_conn = newsrv; |
| 1979 | } |
| 1980 | } |
| 1981 | |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1982 | /* Set correct session termination flags in case no analyser has done it. It |
| 1983 | * also counts a failed request if the server state has not reached the request |
| 1984 | * stage. |
| 1985 | */ |
| 1986 | void sess_set_term_flags(struct session *s) |
| 1987 | { |
| 1988 | if (!(s->flags & SN_FINST_MASK)) { |
| 1989 | if (s->si[1].state < SI_ST_REQ) { |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1990 | |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 1991 | s->fe->counters.failed_req++; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1992 | if (s->listener->counters) |
| 1993 | s->listener->counters->failed_req++; |
| 1994 | |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1995 | s->flags |= SN_FINST_R; |
| 1996 | } |
| 1997 | else if (s->si[1].state == SI_ST_QUE) |
| 1998 | s->flags |= SN_FINST_Q; |
| 1999 | else if (s->si[1].state < SI_ST_EST) |
| 2000 | s->flags |= SN_FINST_C; |
Willy Tarreau | 033b2db | 2010-03-04 17:54:21 +0100 | [diff] [blame] | 2001 | else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST) |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2002 | s->flags |= SN_FINST_D; |
| 2003 | else |
| 2004 | s->flags |= SN_FINST_L; |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | /* Handle server-side errors for default protocols. It is called whenever a a |
| 2009 | * connection setup is aborted or a request is aborted in queue. It sets the |
| 2010 | * session termination flags so that the caller does not have to worry about |
| 2011 | * them. It's installed as ->srv_error for the server-side stream_interface. |
| 2012 | */ |
| 2013 | void default_srv_error(struct session *s, struct stream_interface *si) |
| 2014 | { |
| 2015 | int err_type = si->err_type; |
| 2016 | int err = 0, fin = 0; |
| 2017 | |
| 2018 | if (err_type & SI_ET_QUEUE_ABRT) { |
| 2019 | err = SN_ERR_CLICL; |
| 2020 | fin = SN_FINST_Q; |
| 2021 | } |
| 2022 | else if (err_type & SI_ET_CONN_ABRT) { |
| 2023 | err = SN_ERR_CLICL; |
| 2024 | fin = SN_FINST_C; |
| 2025 | } |
| 2026 | else if (err_type & SI_ET_QUEUE_TO) { |
| 2027 | err = SN_ERR_SRVTO; |
| 2028 | fin = SN_FINST_Q; |
| 2029 | } |
| 2030 | else if (err_type & SI_ET_QUEUE_ERR) { |
| 2031 | err = SN_ERR_SRVCL; |
| 2032 | fin = SN_FINST_Q; |
| 2033 | } |
| 2034 | else if (err_type & SI_ET_CONN_TO) { |
| 2035 | err = SN_ERR_SRVTO; |
| 2036 | fin = SN_FINST_C; |
| 2037 | } |
| 2038 | else if (err_type & SI_ET_CONN_ERR) { |
| 2039 | err = SN_ERR_SRVCL; |
| 2040 | fin = SN_FINST_C; |
| 2041 | } |
| 2042 | else /* SI_ET_CONN_OTHER and others */ { |
| 2043 | err = SN_ERR_INTERNAL; |
| 2044 | fin = SN_FINST_C; |
| 2045 | } |
| 2046 | |
| 2047 | if (!(s->flags & SN_ERR_MASK)) |
| 2048 | s->flags |= err; |
| 2049 | if (!(s->flags & SN_FINST_MASK)) |
| 2050 | s->flags |= fin; |
| 2051 | } |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2052 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 2053 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2054 | /************************************************************************/ |
| 2055 | /* All supported ACL keywords must be declared here. */ |
| 2056 | /************************************************************************/ |
| 2057 | |
| 2058 | /* set test->i to the number of connections from the session's source address |
| 2059 | * in the table pointed to by expr. |
| 2060 | */ |
| 2061 | static int |
| 2062 | acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir, |
| 2063 | struct acl_expr *expr, struct acl_test *test) |
| 2064 | { |
| 2065 | struct stksess *ts; |
| 2066 | struct stktable_key *key; |
| 2067 | |
| 2068 | key = tcpv4_src_to_stktable_key(l4); |
| 2069 | if (!key) |
| 2070 | return 0; /* only TCPv4 is supported right now */ |
| 2071 | |
| 2072 | if (expr->arg_len) |
| 2073 | px = find_stktable(expr->arg.str); |
| 2074 | |
| 2075 | if (!px) |
| 2076 | return 0; /* table not found */ |
| 2077 | |
| 2078 | test->flags = ACL_TEST_F_VOL_TEST; |
| 2079 | test->i = 0; |
| 2080 | if ((ts = stktable_lookup_key(&px->table, key)) != NULL) { |
| 2081 | void *ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT); |
| 2082 | if (!ptr) |
| 2083 | return 0; /* parameter not stored */ |
| 2084 | test->i = stktable_data_cast(ptr, conn_cnt); |
| 2085 | } |
| 2086 | |
| 2087 | return 1; |
| 2088 | } |
| 2089 | |
| 2090 | /* set test->i to the number of connections from the session's source address |
| 2091 | * in the table pointed to by expr, after updating it. |
| 2092 | */ |
| 2093 | static int |
| 2094 | acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir, |
| 2095 | struct acl_expr *expr, struct acl_test *test) |
| 2096 | { |
| 2097 | struct stksess *ts; |
| 2098 | struct stktable_key *key; |
| 2099 | void *ptr; |
| 2100 | |
| 2101 | key = tcpv4_src_to_stktable_key(l4); |
| 2102 | if (!key) |
| 2103 | return 0; /* only TCPv4 is supported right now */ |
| 2104 | |
| 2105 | if (expr->arg_len) |
| 2106 | px = find_stktable(expr->arg.str); |
| 2107 | |
| 2108 | if (!px) |
| 2109 | return 0; /* table not found */ |
| 2110 | |
| 2111 | if ((ts = stktable_lookup_key(&px->table, key)) == NULL) { |
| 2112 | /* entry does not exist, initialize a new one */ |
| 2113 | ts = stksess_new(&px->table, key); |
| 2114 | if (!ts) |
| 2115 | return 0; |
| 2116 | stktable_store(&px->table, ts); |
| 2117 | } |
| 2118 | else |
| 2119 | stktable_touch(&px->table, ts); |
| 2120 | |
| 2121 | ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT); |
| 2122 | if (!ptr) |
| 2123 | return 0; /* parameter not stored in this table */ |
| 2124 | |
| 2125 | test->i = ++stktable_data_cast(ptr, conn_cnt); |
| 2126 | test->flags = ACL_TEST_F_VOL_TEST; |
| 2127 | return 1; |
| 2128 | } |
| 2129 | |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame^] | 2130 | /* set test->i to the number of concurrent connections from the session's source |
| 2131 | * address in the table pointed to by expr. |
| 2132 | */ |
| 2133 | static int |
| 2134 | acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir, |
| 2135 | struct acl_expr *expr, struct acl_test *test) |
| 2136 | { |
| 2137 | struct stksess *ts; |
| 2138 | struct stktable_key *key; |
| 2139 | |
| 2140 | key = tcpv4_src_to_stktable_key(l4); |
| 2141 | if (!key) |
| 2142 | return 0; /* only TCPv4 is supported right now */ |
| 2143 | |
| 2144 | if (expr->arg_len) |
| 2145 | px = find_stktable(expr->arg.str); |
| 2146 | |
| 2147 | if (!px) |
| 2148 | return 0; /* table not found */ |
| 2149 | |
| 2150 | test->flags = ACL_TEST_F_VOL_TEST; |
| 2151 | test->i = 0; |
| 2152 | |
| 2153 | if ((ts = stktable_lookup_key(&px->table, key)) != NULL) { |
| 2154 | void *ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CUR); |
| 2155 | if (!ptr) |
| 2156 | return 0; /* parameter not stored */ |
| 2157 | test->i = stktable_data_cast(ptr, conn_cur); |
| 2158 | } |
| 2159 | |
| 2160 | return 1; |
| 2161 | } |
| 2162 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2163 | |
| 2164 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 2165 | static struct acl_kw_list acl_kws = {{ },{ |
| 2166 | { "src_conn_cnt", acl_parse_int, acl_fetch_src_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE }, |
| 2167 | { "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE }, |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame^] | 2168 | { "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE }, |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2169 | { NULL, NULL, NULL, NULL }, |
| 2170 | }}; |
| 2171 | |
| 2172 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 2173 | /* Parse a "track-counters" line starting with "track-counters" in args[arg-1]. |
| 2174 | * Returns the number of warnings emitted, or -1 in case of fatal errors. The |
| 2175 | * <prm> struct is fed with the table name if any. If unspecified, the caller |
| 2176 | * will assume that the current proxy's table is used. |
| 2177 | */ |
| 2178 | int parse_track_counters(char **args, int *arg, |
| 2179 | int section_type, struct proxy *curpx, |
| 2180 | struct track_ctr_prm *prm, |
| 2181 | struct proxy *defpx, char *err, int errlen) |
| 2182 | { |
| 2183 | int pattern_type = 0; |
| 2184 | |
| 2185 | /* parse the arguments of "track-counters" before the condition in the |
| 2186 | * following form : |
| 2187 | * track-counters src [ table xxx ] [ if|unless ... ] |
| 2188 | */ |
| 2189 | while (args[*arg]) { |
| 2190 | if (strcmp(args[*arg], "src") == 0) { |
| 2191 | prm->type = STKTABLE_TYPE_IP; |
| 2192 | pattern_type = 1; |
| 2193 | } |
| 2194 | else if (strcmp(args[*arg], "table") == 0) { |
| 2195 | if (!args[*arg + 1]) { |
| 2196 | snprintf(err, errlen, |
| 2197 | "missing table for track-counter in %s '%s'.", |
| 2198 | proxy_type_str(curpx), curpx->id); |
| 2199 | return -1; |
| 2200 | } |
| 2201 | /* we copy the table name for now, it will be resolved later */ |
| 2202 | prm->table.n = strdup(args[*arg + 1]); |
| 2203 | (*arg)++; |
| 2204 | } |
| 2205 | else { |
| 2206 | /* unhandled keywords are handled by the caller */ |
| 2207 | break; |
| 2208 | } |
| 2209 | (*arg)++; |
| 2210 | } |
| 2211 | |
| 2212 | if (!pattern_type) { |
| 2213 | snprintf(err, errlen, |
| 2214 | "track-counter key not specified in %s '%s' (found %s, only 'src' is supported).", |
| 2215 | proxy_type_str(curpx), curpx->id, quote_arg(args[*arg])); |
| 2216 | return -1; |
| 2217 | } |
| 2218 | |
| 2219 | return 0; |
| 2220 | } |
| 2221 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2222 | __attribute__((constructor)) |
| 2223 | static void __session_init(void) |
| 2224 | { |
| 2225 | acl_register_keywords(&acl_kws); |
| 2226 | } |
| 2227 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 2228 | /* |
| 2229 | * Local variables: |
| 2230 | * c-indent-level: 8 |
| 2231 | * c-basic-offset: 8 |
| 2232 | * End: |
| 2233 | */ |