blob: c34ed9f65a8333375d30820e93c5e13833d0f080 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau81f9aa32010-06-01 17:45:26 +02002 * Session management functions.
Willy Tarreaubaaee002006-06-26 02:48:02 +02003 *
Willy Tarreau81f9aa32010-06-01 17:45:26 +02004 * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdlib.h>
Willy Tarreau81f9aa32010-06-01 17:45:26 +020014#include <unistd.h>
15#include <fcntl.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020016
17#include <common/config.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020018#include <common/debug.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020019#include <common/memory.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020020
Willy Tarreaubaaee002006-06-26 02:48:02 +020021#include <types/capture.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010022#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020023
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020024#include <proto/acl.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010025#include <proto/backend.h>
Willy Tarreau7341d942007-05-13 19:56:02 +020026#include <proto/buffers.h>
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010027#include <proto/checks.h>
Willy Tarreau5ca791d2009-08-16 19:06:42 +020028#include <proto/dumpstats.h>
Willy Tarreau91c43d72010-06-20 11:19:22 +020029#include <proto/freq_ctr.h>
Willy Tarreau3041b9f2010-10-15 23:25:20 +020030#include <proto/frontend.h>
Willy Tarreau8d5d7f22007-01-21 19:16:41 +010031#include <proto/hdr_idx.h>
Willy Tarreau332f8bf2007-05-13 21:36:56 +020032#include <proto/log.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020033#include <proto/session.h>
Willy Tarreau3eba98a2009-01-25 13:56:13 +010034#include <proto/pipe.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010035#include <proto/proto_http.h>
36#include <proto/proto_tcp.h>
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020037#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020038#include <proto/queue.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010039#include <proto/server.h>
Emeric Brun1d33b292010-01-04 15:47:17 +010040#include <proto/stick_table.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010041#include <proto/stream_interface.h>
42#include <proto/stream_sock.h>
43#include <proto/task.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020044
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020045struct pool_head *pool2_session;
Willy Tarreauf54f8bd2008-11-23 19:53:55 +010046struct list sessions;
Willy Tarreaubaaee002006-06-26 02:48:02 +020047
Willy Tarreau81f9aa32010-06-01 17:45:26 +020048/* This function is called from the protocol layer accept() in order to instanciate
49 * a new session on behalf of a given listener and frontend. It returns a positive
Willy Tarreauabe8ea52010-11-11 10:56:04 +010050 * value upon success, 0 if the connection can be ignored, or a negative value upon
51 * critical failure. The accepted file descriptor is closed if we return <= 0.
Willy Tarreau81f9aa32010-06-01 17:45:26 +020052 */
53int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
54{
55 struct proxy *p = l->frontend;
56 struct session *s;
57 struct http_txn *txn;
58 struct task *t;
Willy Tarreauabe8ea52010-11-11 10:56:04 +010059 int ret;
60
61
62 ret = -1; /* assume unrecoverable error by default */
Willy Tarreau81f9aa32010-06-01 17:45:26 +020063
Willy Tarreaufffe1322010-11-11 09:48:16 +010064 if (unlikely((s = pool_alloc2(pool2_session)) == NULL))
Willy Tarreau81f9aa32010-06-01 17:45:26 +020065 goto out_close;
Willy Tarreau81f9aa32010-06-01 17:45:26 +020066
67 /* minimum session initialization required for monitor mode below */
68 s->flags = 0;
69 s->logs.logwait = p->to_log;
Willy Tarreau56123282010-08-06 19:06:56 +020070 s->stkctr1_entry = NULL;
71 s->stkctr2_entry = NULL;
72 s->stkctr1_table = NULL;
73 s->stkctr2_table = NULL;
Willy Tarreau81f9aa32010-06-01 17:45:26 +020074
75 /* if this session comes from a known monitoring system, we want to ignore
76 * it as soon as possible, which means closing it immediately for TCP, but
77 * cleanly.
78 */
79 if (unlikely((l->options & LI_O_CHK_MONNET) &&
80 addr->ss_family == AF_INET &&
81 (((struct sockaddr_in *)addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr)) {
82 if (p->mode == PR_MODE_TCP) {
Willy Tarreauabe8ea52010-11-11 10:56:04 +010083 ret = 0; /* successful termination */
84 goto out_free_session;
Willy Tarreau81f9aa32010-06-01 17:45:26 +020085 }
86 s->flags |= SN_MONITOR;
87 s->logs.logwait = 0;
88 }
89
Willy Tarreauabe8ea52010-11-11 10:56:04 +010090 if (unlikely((t = task_new()) == NULL))
91 goto out_free_session;
92
Willy Tarreau81f9aa32010-06-01 17:45:26 +020093 /* OK, we're keeping the session, so let's properly initialize the session */
94 LIST_ADDQ(&sessions, &s->list);
95 LIST_INIT(&s->back_refs);
96
Willy Tarreau81f9aa32010-06-01 17:45:26 +020097 s->term_trace = 0;
98 s->cli_addr = *addr;
99 s->logs.accept_date = date; /* user-visible date for logging */
100 s->logs.tv_accept = now; /* corrected date for internal use */
101 s->uniq_id = totalconn;
Willy Tarreau24dcaf32010-06-05 10:49:41 +0200102 p->feconn++; /* beconn will be increased once assigned */
103
Willy Tarreaub36b4242010-06-04 20:59:39 +0200104 proxy_inc_fe_conn_ctr(l, p); /* note: cum_beconn will be increased once assigned */
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200105
106 t->process = l->handler;
107 t->context = s;
108 t->nice = l->nice;
109 t->expire = TICK_ETERNITY;
110
111 s->task = t;
112 s->listener = l;
113
114 /* Note: initially, the session's backend points to the frontend.
115 * This changes later when switching rules are executed or
116 * when the default backend is assigned.
117 */
118 s->be = s->fe = p;
119 s->req = s->rep = NULL; /* will be allocated later */
120
121 /* now evaluate the tcp-request layer4 rules. Since we expect to be able
122 * to abort right here as soon as possible, we check the rules before
123 * even initializing the stream interfaces.
124 */
125 if ((l->options & LI_O_TCP_RULES) && !tcp_exec_req_rules(s)) {
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200126 /* let's do a no-linger now to close with a single RST. */
127 setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
Willy Tarreauabe8ea52010-11-11 10:56:04 +0100128 ret = 0; /* successful termination */
129 goto out_free_task;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200130 }
131
Willy Tarreaub36b4242010-06-04 20:59:39 +0200132 /* This session was accepted, count it now */
Willy Tarreau24dcaf32010-06-05 10:49:41 +0200133 if (p->feconn > p->counters.feconn_max)
134 p->counters.feconn_max = p->feconn;
Willy Tarreauabe8ea52010-11-11 10:56:04 +0100135
Willy Tarreaub36b4242010-06-04 20:59:39 +0200136 proxy_inc_fe_sess_ctr(l, p);
Willy Tarreau56123282010-08-06 19:06:56 +0200137 if (s->stkctr1_entry) {
Willy Tarreau91c43d72010-06-20 11:19:22 +0200138 void *ptr;
139
Willy Tarreau56123282010-08-06 19:06:56 +0200140 ptr = stktable_data_ptr(s->stkctr1_table, s->stkctr1_entry, STKTABLE_DT_SESS_CNT);
Willy Tarreauf4d17d92010-06-18 22:10:12 +0200141 if (ptr)
142 stktable_data_cast(ptr, sess_cnt)++;
Willy Tarreau91c43d72010-06-20 11:19:22 +0200143
Willy Tarreau56123282010-08-06 19:06:56 +0200144 ptr = stktable_data_ptr(s->stkctr1_table, s->stkctr1_entry, STKTABLE_DT_SESS_RATE);
Willy Tarreau91c43d72010-06-20 11:19:22 +0200145 if (ptr)
146 update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200147 s->stkctr1_table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
Willy Tarreauf4d17d92010-06-18 22:10:12 +0200148 }
Willy Tarreaub36b4242010-06-04 20:59:39 +0200149
Willy Tarreau56123282010-08-06 19:06:56 +0200150 if (s->stkctr2_entry) {
Willy Tarreau9e9879a2010-08-06 15:25:22 +0200151 void *ptr;
152
Willy Tarreau56123282010-08-06 19:06:56 +0200153 ptr = stktable_data_ptr(s->stkctr2_table, s->stkctr2_entry, STKTABLE_DT_SESS_CNT);
Willy Tarreau9e9879a2010-08-06 15:25:22 +0200154 if (ptr)
155 stktable_data_cast(ptr, sess_cnt)++;
156
Willy Tarreau56123282010-08-06 19:06:56 +0200157 ptr = stktable_data_ptr(s->stkctr2_table, s->stkctr2_entry, STKTABLE_DT_SESS_RATE);
Willy Tarreau9e9879a2010-08-06 15:25:22 +0200158 if (ptr)
159 update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200160 s->stkctr2_table->data_arg[STKTABLE_DT_SESS_RATE].u, 1);
Willy Tarreau9e9879a2010-08-06 15:25:22 +0200161 }
162
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200163 /* this part should be common with other protocols */
164 s->si[0].fd = cfd;
165 s->si[0].owner = t;
166 s->si[0].state = s->si[0].prev_state = SI_ST_EST;
167 s->si[0].err_type = SI_ET_NONE;
168 s->si[0].err_loc = NULL;
169 s->si[0].connect = NULL;
170 s->si[0].iohandler = NULL;
Willy Tarreau0bd05ea2010-07-02 11:18:03 +0200171 s->si[0].release = NULL;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200172 s->si[0].exp = TICK_ETERNITY;
173 s->si[0].flags = SI_FL_NONE;
174
175 if (likely(s->fe->options2 & PR_O2_INDEPSTR))
176 s->si[0].flags |= SI_FL_INDEP_STR;
177
178 if (addr->ss_family == AF_INET || addr->ss_family == AF_INET6)
179 s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */
180
181 /* add the various callbacks */
182 stream_sock_prepare_interface(&s->si[0]);
183
184 /* pre-initialize the other side's stream interface to an INIT state. The
185 * callbacks will be initialized before attempting to connect.
186 */
187 s->si[1].fd = -1; /* just to help with debugging */
188 s->si[1].owner = t;
189 s->si[1].state = s->si[1].prev_state = SI_ST_INI;
190 s->si[1].err_type = SI_ET_NONE;
191 s->si[1].err_loc = NULL;
192 s->si[1].connect = NULL;
193 s->si[1].iohandler = NULL;
Willy Tarreau0bd05ea2010-07-02 11:18:03 +0200194 s->si[1].release = NULL;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200195 s->si[1].shutr = stream_int_shutr;
196 s->si[1].shutw = stream_int_shutw;
197 s->si[1].exp = TICK_ETERNITY;
198 s->si[1].flags = SI_FL_NONE;
199
200 if (likely(s->fe->options2 & PR_O2_INDEPSTR))
201 s->si[1].flags |= SI_FL_INDEP_STR;
202
203 s->srv = s->prev_srv = s->srv_conn = NULL;
204 s->pend_pos = NULL;
205
206 /* init store persistence */
207 s->store_count = 0;
208
209 /* Adjust some socket options */
Willy Tarreaufffe1322010-11-11 09:48:16 +0100210 if (unlikely(fcntl(cfd, F_SETFL, O_NONBLOCK) == -1))
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200211 goto out_free_task;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200212
213 txn = &s->txn;
214 /* Those variables will be checked and freed if non-NULL in
215 * session.c:session_free(). It is important that they are
216 * properly initialized.
217 */
218 txn->sessid = NULL;
219 txn->srv_cookie = NULL;
220 txn->cli_cookie = NULL;
221 txn->uri = NULL;
222 txn->req.cap = NULL;
223 txn->rsp.cap = NULL;
224 txn->hdr_idx.v = NULL;
225 txn->hdr_idx.size = txn->hdr_idx.used = 0;
226
227 if (unlikely((s->req = pool_alloc2(pool2_buffer)) == NULL))
228 goto out_free_task; /* no memory */
229
230 if (unlikely((s->rep = pool_alloc2(pool2_buffer)) == NULL))
231 goto out_free_req; /* no memory */
232
233 /* initialize the request buffer */
234 s->req->size = global.tune.bufsize;
235 buffer_init(s->req);
236 s->req->prod = &s->si[0];
237 s->req->cons = &s->si[1];
238 s->si[0].ib = s->si[1].ob = s->req;
239 s->req->flags |= BF_READ_ATTACHED; /* the producer is already connected */
240
241 /* activate default analysers enabled for this listener */
242 s->req->analysers = l->analysers;
243
244 s->req->wto = TICK_ETERNITY;
245 s->req->rto = TICK_ETERNITY;
246 s->req->rex = TICK_ETERNITY;
247 s->req->wex = TICK_ETERNITY;
248 s->req->analyse_exp = TICK_ETERNITY;
249
250 /* initialize response buffer */
251 s->rep->size = global.tune.bufsize;
252 buffer_init(s->rep);
253 s->rep->prod = &s->si[1];
254 s->rep->cons = &s->si[0];
255 s->si[0].ob = s->si[1].ib = s->rep;
256 s->rep->analysers = 0;
257
258 s->rep->rto = TICK_ETERNITY;
259 s->rep->wto = TICK_ETERNITY;
260 s->rep->rex = TICK_ETERNITY;
261 s->rep->wex = TICK_ETERNITY;
262 s->rep->analyse_exp = TICK_ETERNITY;
263
264 /* finish initialization of the accepted file descriptor */
265 fd_insert(cfd);
266 fdtab[cfd].owner = &s->si[0];
267 fdtab[cfd].state = FD_STREADY;
268 fdtab[cfd].flags = 0;
269 fdtab[cfd].cb[DIR_RD].f = l->proto->read;
270 fdtab[cfd].cb[DIR_RD].b = s->req;
271 fdtab[cfd].cb[DIR_WR].f = l->proto->write;
272 fdtab[cfd].cb[DIR_WR].b = s->rep;
273 fdinfo[cfd].peeraddr = (struct sockaddr *)&s->cli_addr;
274 fdinfo[cfd].peerlen = sizeof(s->cli_addr);
275 EV_FD_SET(cfd, DIR_RD);
276
Willy Tarreauabe8ea52010-11-11 10:56:04 +0100277 if (p->accept && (ret = p->accept(s)) <= 0) {
278 /* Either we had an unrecoverable error (<0) or work is
279 * finished (=0, eg: monitoring), in both situations,
280 * we can release everything and close.
281 */
282 goto out_free_rep;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200283 }
284
285 /* it is important not to call the wakeup function directly but to
286 * pass through task_wakeup(), because this one knows how to apply
287 * priorities to tasks.
288 */
289 task_wakeup(t, TASK_WOKEN_INIT);
290 return 1;
291
292 /* Error unrolling */
293 out_free_rep:
294 pool_free2(pool2_buffer, s->rep);
295 out_free_req:
296 pool_free2(pool2_buffer, s->req);
297 out_free_task:
Willy Tarreau24dcaf32010-06-05 10:49:41 +0200298 p->feconn--;
Willy Tarreau56123282010-08-06 19:06:56 +0200299 if (s->stkctr1_entry || s->stkctr2_entry)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200300 session_store_counters(s);
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200301 task_free(t);
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200302 LIST_DEL(&s->list);
Willy Tarreauabe8ea52010-11-11 10:56:04 +0100303 out_free_session:
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200304 pool_free2(pool2_session, s);
305 out_close:
Willy Tarreauabe8ea52010-11-11 10:56:04 +0100306 if (fdtab[cfd].state != FD_STCLOSE)
307 fd_delete(cfd);
308 else
309 close(cfd);
310 return ret;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200311}
312
Willy Tarreaubaaee002006-06-26 02:48:02 +0200313/*
314 * frees the context associated to a session. It must have been removed first.
315 */
316void session_free(struct session *s)
317{
Willy Tarreau4dbc4a22007-03-03 16:23:22 +0100318 struct http_txn *txn = &s->txn;
Willy Tarreau632f5a72007-07-11 10:42:35 +0200319 struct proxy *fe = s->fe;
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100320 struct bref *bref, *back;
Willy Tarreaua4cda672010-06-06 18:28:49 +0200321 int i;
Willy Tarreau0f7562b2007-01-07 15:46:13 +0100322
Willy Tarreaubaaee002006-06-26 02:48:02 +0200323 if (s->pend_pos)
324 pendconn_free(s->pend_pos);
Willy Tarreau922a8062008-12-04 09:33:58 +0100325
Willy Tarreau1e62de62008-11-11 20:20:02 +0100326 if (s->srv) { /* there may be requests left pending in queue */
327 if (s->flags & SN_CURR_SESS) {
328 s->flags &= ~SN_CURR_SESS;
329 s->srv->cur_sess--;
330 }
Willy Tarreau922a8062008-12-04 09:33:58 +0100331 if (may_dequeue_tasks(s->srv, s->be))
332 process_srv_queue(s->srv);
Willy Tarreau1e62de62008-11-11 20:20:02 +0100333 }
Willy Tarreau922a8062008-12-04 09:33:58 +0100334
Willy Tarreau7c669d72008-06-20 15:04:11 +0200335 if (unlikely(s->srv_conn)) {
336 /* the session still has a reserved slot on a server, but
337 * it should normally be only the same as the one above,
338 * so this should not happen in fact.
339 */
340 sess_change_server(s, NULL);
341 }
342
Willy Tarreau3eba98a2009-01-25 13:56:13 +0100343 if (s->req->pipe)
344 put_pipe(s->req->pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +0100345
Willy Tarreau3eba98a2009-01-25 13:56:13 +0100346 if (s->rep->pipe)
347 put_pipe(s->rep->pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +0100348
Willy Tarreau48d63db2008-08-03 17:41:33 +0200349 pool_free2(pool2_buffer, s->req);
350 pool_free2(pool2_buffer, s->rep);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200351
Willy Tarreau46023632010-01-07 22:51:47 +0100352 http_end_txn(s);
353
Willy Tarreaua4cda672010-06-06 18:28:49 +0200354 for (i = 0; i < s->store_count; i++) {
355 if (!s->store[i].ts)
356 continue;
357 stksess_free(s->store[i].table, s->store[i].ts);
358 s->store[i].ts = NULL;
359 }
360
Willy Tarreau92fb9832007-10-16 17:34:28 +0200361 if (fe) {
Willy Tarreau48d63db2008-08-03 17:41:33 +0200362 pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v);
Willy Tarreau46023632010-01-07 22:51:47 +0100363 pool_free2(fe->rsp_cap_pool, txn->rsp.cap);
364 pool_free2(fe->req_cap_pool, txn->req.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200365 }
Willy Tarreau0937bc42009-12-22 15:03:09 +0100366
Willy Tarreau56123282010-08-06 19:06:56 +0200367 if (s->stkctr1_entry || s->stkctr2_entry)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200368 session_store_counters(s);
369
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100370 list_for_each_entry_safe(bref, back, &s->back_refs, users) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100371 /* we have to unlink all watchers. We must not relink them if
372 * this session was the last one in the list.
373 */
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100374 LIST_DEL(&bref->users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100375 LIST_INIT(&bref->users);
376 if (s->list.n != &sessions)
377 LIST_ADDQ(&LIST_ELEM(s->list.n, struct session *, list)->back_refs, &bref->users);
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100378 bref->ref = s->list.n;
379 }
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100380 LIST_DEL(&s->list);
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200381 pool_free2(pool2_session, s);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200382
383 /* We may want to free the maximum amount of pools if the proxy is stopping */
Willy Tarreau92fb9832007-10-16 17:34:28 +0200384 if (fe && unlikely(fe->state == PR_STSTOPPED)) {
Willy Tarreau48d63db2008-08-03 17:41:33 +0200385 pool_flush2(pool2_buffer);
386 pool_flush2(fe->hdr_idx_pool);
387 pool_flush2(pool2_requri);
388 pool_flush2(pool2_capture);
389 pool_flush2(pool2_session);
390 pool_flush2(fe->req_cap_pool);
391 pool_flush2(fe->rsp_cap_pool);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200392 }
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200393}
394
395
396/* perform minimal intializations, report 0 in case of error, 1 if OK. */
397int init_session()
398{
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100399 LIST_INIT(&sessions);
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200400 pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED);
401 return pool2_session != NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200402}
403
Willy Tarreau30e71012007-11-26 20:15:35 +0100404void session_process_counters(struct session *s)
405{
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100406 unsigned long long bytes;
407
Willy Tarreau30e71012007-11-26 20:15:35 +0100408 if (s->req) {
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100409 bytes = s->req->total - s->logs.bytes_in;
Willy Tarreau30e71012007-11-26 20:15:35 +0100410 s->logs.bytes_in = s->req->total;
411 if (bytes) {
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200412 s->fe->counters.bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100413
Willy Tarreau30e71012007-11-26 20:15:35 +0100414 if (s->be != s->fe)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200415 s->be->counters.bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100416
Willy Tarreau30e71012007-11-26 20:15:35 +0100417 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200418 s->srv->counters.bytes_in += bytes;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200419
420 if (s->listener->counters)
421 s->listener->counters->bytes_in += bytes;
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200422
Willy Tarreau56123282010-08-06 19:06:56 +0200423 if (s->stkctr2_entry) {
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200424 void *ptr;
425
Willy Tarreau56123282010-08-06 19:06:56 +0200426 ptr = stktable_data_ptr(s->stkctr2_table,
427 s->stkctr2_entry,
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200428 STKTABLE_DT_BYTES_IN_CNT);
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200429 if (ptr)
430 stktable_data_cast(ptr, bytes_in_cnt) += bytes;
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200431
Willy Tarreau56123282010-08-06 19:06:56 +0200432 ptr = stktable_data_ptr(s->stkctr2_table,
433 s->stkctr2_entry,
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200434 STKTABLE_DT_BYTES_IN_RATE);
435 if (ptr)
436 update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200437 s->stkctr2_table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200438 }
439
Willy Tarreau56123282010-08-06 19:06:56 +0200440 if (s->stkctr1_entry) {
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200441 void *ptr;
442
Willy Tarreau56123282010-08-06 19:06:56 +0200443 ptr = stktable_data_ptr(s->stkctr1_table,
444 s->stkctr1_entry,
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200445 STKTABLE_DT_BYTES_IN_CNT);
446 if (ptr)
447 stktable_data_cast(ptr, bytes_in_cnt) += bytes;
448
Willy Tarreau56123282010-08-06 19:06:56 +0200449 ptr = stktable_data_ptr(s->stkctr1_table,
450 s->stkctr1_entry,
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200451 STKTABLE_DT_BYTES_IN_RATE);
452 if (ptr)
453 update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200454 s->stkctr1_table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes);
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200455 }
Willy Tarreau30e71012007-11-26 20:15:35 +0100456 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100457 }
458
Willy Tarreau30e71012007-11-26 20:15:35 +0100459 if (s->rep) {
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100460 bytes = s->rep->total - s->logs.bytes_out;
Willy Tarreau30e71012007-11-26 20:15:35 +0100461 s->logs.bytes_out = s->rep->total;
462 if (bytes) {
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200463 s->fe->counters.bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100464
Willy Tarreau30e71012007-11-26 20:15:35 +0100465 if (s->be != s->fe)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200466 s->be->counters.bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100467
Willy Tarreau30e71012007-11-26 20:15:35 +0100468 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200469 s->srv->counters.bytes_out += bytes;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200470
471 if (s->listener->counters)
472 s->listener->counters->bytes_out += bytes;
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200473
Willy Tarreau56123282010-08-06 19:06:56 +0200474 if (s->stkctr2_entry) {
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200475 void *ptr;
476
Willy Tarreau56123282010-08-06 19:06:56 +0200477 ptr = stktable_data_ptr(s->stkctr2_table,
478 s->stkctr2_entry,
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200479 STKTABLE_DT_BYTES_OUT_CNT);
480 if (ptr)
481 stktable_data_cast(ptr, bytes_out_cnt) += bytes;
482
Willy Tarreau56123282010-08-06 19:06:56 +0200483 ptr = stktable_data_ptr(s->stkctr2_table,
484 s->stkctr2_entry,
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200485 STKTABLE_DT_BYTES_OUT_RATE);
486 if (ptr)
487 update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200488 s->stkctr2_table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200489 }
490
Willy Tarreau56123282010-08-06 19:06:56 +0200491 if (s->stkctr1_entry) {
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200492 void *ptr;
493
Willy Tarreau56123282010-08-06 19:06:56 +0200494 ptr = stktable_data_ptr(s->stkctr1_table,
495 s->stkctr1_entry,
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200496 STKTABLE_DT_BYTES_OUT_CNT);
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200497 if (ptr)
498 stktable_data_cast(ptr, bytes_out_cnt) += bytes;
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200499
Willy Tarreau56123282010-08-06 19:06:56 +0200500 ptr = stktable_data_ptr(s->stkctr1_table,
501 s->stkctr1_entry,
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200502 STKTABLE_DT_BYTES_OUT_RATE);
503 if (ptr)
504 update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
Willy Tarreau56123282010-08-06 19:06:56 +0200505 s->stkctr1_table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes);
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200506 }
Willy Tarreau30e71012007-11-26 20:15:35 +0100507 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100508 }
509}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200510
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100511/* This function is called with (si->state == SI_ST_CON) meaning that a
512 * connection was attempted and that the file descriptor is already allocated.
513 * We must check for establishment, error and abort. Possible output states
514 * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and
515 * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER,
516 * otherwise 1.
517 */
518int sess_update_st_con_tcp(struct session *s, struct stream_interface *si)
519{
520 struct buffer *req = si->ob;
521 struct buffer *rep = si->ib;
522
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100523 /* If we got an error, or if nothing happened and the connection timed
524 * out, we must give up. The CER state handler will take care of retry
525 * attempts and error reports.
526 */
527 if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) {
Willy Tarreau127334e2009-03-28 10:47:26 +0100528 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100529 si->state = SI_ST_CER;
Willy Tarreaudc340a92009-06-28 23:10:19 +0200530 si->flags &= ~SI_FL_CAP_SPLICE;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100531 fd_delete(si->fd);
532
Willy Tarreau0bd05ea2010-07-02 11:18:03 +0200533 if (si->release)
534 si->release(si);
535
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100536 if (si->err_type)
537 return 0;
538
539 si->err_loc = s->srv;
540 if (si->flags & SI_FL_ERR)
541 si->err_type = SI_ET_CONN_ERR;
542 else
543 si->err_type = SI_ET_CONN_TO;
544 return 0;
545 }
546
547 /* OK, maybe we want to abort */
Willy Tarreau418fd472009-09-06 21:37:23 +0200548 if (unlikely((rep->flags & BF_SHUTW) ||
549 ((req->flags & BF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200550 (((req->flags & (BF_OUT_EMPTY|BF_WRITE_ACTIVITY)) == BF_OUT_EMPTY) ||
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100551 s->be->options & PR_O_ABRT_CLOSE)))) {
552 /* give up */
553 si->shutw(si);
554 si->err_type |= SI_ET_CONN_ABRT;
555 si->err_loc = s->srv;
Willy Tarreaudc340a92009-06-28 23:10:19 +0200556 si->flags &= ~SI_FL_CAP_SPLICE;
Willy Tarreau84455332009-03-15 22:34:05 +0100557 if (s->srv_error)
558 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100559 return 1;
560 }
561
562 /* we need to wait a bit more if there was no activity either */
563 if (!(req->flags & BF_WRITE_ACTIVITY))
564 return 1;
565
566 /* OK, this means that a connection succeeded. The caller will be
567 * responsible for handling the transition from CON to EST.
568 */
569 s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau127334e2009-03-28 10:47:26 +0100570 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100571 si->state = SI_ST_EST;
572 si->err_type = SI_ET_NONE;
573 si->err_loc = NULL;
574 return 1;
575}
576
577/* This function is called with (si->state == SI_ST_CER) meaning that a
578 * previous connection attempt has failed and that the file descriptor
579 * has already been released. Possible causes include asynchronous error
580 * notification and time out. Possible output states are SI_ST_CLO when
581 * retries are exhausted, SI_ST_TAR when a delay is wanted before a new
582 * connection attempt, SI_ST_ASS when it's wise to retry on the same server,
583 * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are
584 * marked as in error state. It returns 0.
585 */
586int sess_update_st_cer(struct session *s, struct stream_interface *si)
587{
588 /* we probably have to release last session from the server */
589 if (s->srv) {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100590 health_adjust(s->srv, HANA_STATUS_L4_ERR);
591
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100592 if (s->flags & SN_CURR_SESS) {
593 s->flags &= ~SN_CURR_SESS;
594 s->srv->cur_sess--;
595 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100596 }
597
598 /* ensure that we have enough retries left */
Willy Tarreauee28de02010-06-01 09:51:00 +0200599 si->conn_retries--;
600 if (si->conn_retries < 0) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100601 if (!si->err_type) {
602 si->err_type = SI_ET_CONN_ERR;
603 si->err_loc = s->srv;
604 }
605
606 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200607 s->srv->counters.failed_conns++;
608 s->be->counters.failed_conns++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100609 if (may_dequeue_tasks(s->srv, s->be))
610 process_srv_queue(s->srv);
611
612 /* shutw is enough so stop a connecting socket */
613 si->shutw(si);
614 si->ob->flags |= BF_WRITE_ERROR;
615 si->ib->flags |= BF_READ_ERROR;
616
617 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100618 if (s->srv_error)
619 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100620 return 0;
621 }
622
623 /* If the "redispatch" option is set on the backend, we are allowed to
624 * retry on another server for the last retry. In order to achieve this,
625 * we must mark the session unassigned, and eventually clear the DIRECT
626 * bit to ignore any persistence cookie. We won't count a retry nor a
627 * redispatch yet, because this will depend on what server is selected.
628 */
Willy Tarreauee28de02010-06-01 09:51:00 +0200629 if (s->srv && si->conn_retries == 0 &&
Willy Tarreau4de91492010-01-22 19:10:05 +0100630 s->be->options & PR_O_REDISP && !(s->flags & SN_FORCE_PRST)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100631 if (may_dequeue_tasks(s->srv, s->be))
632 process_srv_queue(s->srv);
633
634 s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
635 s->prev_srv = s->srv;
636 si->state = SI_ST_REQ;
637 } else {
638 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200639 s->srv->counters.retries++;
640 s->be->counters.retries++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100641 si->state = SI_ST_ASS;
642 }
643
644 if (si->flags & SI_FL_ERR) {
645 /* The error was an asynchronous connection error, and we will
646 * likely have to retry connecting to the same server, most
647 * likely leading to the same result. To avoid this, we wait
648 * one second before retrying.
649 */
650
651 if (!si->err_type)
652 si->err_type = SI_ET_CONN_ERR;
653
654 si->state = SI_ST_TAR;
655 si->exp = tick_add(now_ms, MS_TO_TICKS(1000));
656 return 0;
657 }
658 return 0;
659}
660
661/*
662 * This function handles the transition between the SI_ST_CON state and the
Willy Tarreau85e7d002010-05-31 11:57:51 +0200663 * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or
664 * SI_ST_INI) to SI_ST_EST, but only when a ->connect function is defined.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100665 */
666void sess_establish(struct session *s, struct stream_interface *si)
667{
668 struct buffer *req = si->ob;
669 struct buffer *rep = si->ib;
670
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100671 if (s->srv)
672 health_adjust(s->srv, HANA_STATUS_L4_OK);
673
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100674 if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100675 /* if the user wants to log as soon as possible, without counting
676 * bytes from the server, then this is the right moment. */
677 if (s->fe->to_log && !(s->logs.logwait & LW_BYTES)) {
678 s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
Willy Tarreaua5555ec2008-11-30 19:02:32 +0100679 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100680 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100681 }
682 else {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100683 s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE;
684 /* reset hdr_idx which was already initialized by the request.
685 * right now, the http parser does it.
686 * hdr_idx_init(&s->txn.hdr_idx);
687 */
688 }
689
Willy Tarreau4e5b8282009-08-16 22:57:50 +0200690 rep->analysers |= s->fe->fe_rsp_ana | s->be->be_rsp_ana;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100691 rep->flags |= BF_READ_ATTACHED; /* producer is now attached */
Willy Tarreaud04e8582010-05-31 12:31:35 +0200692 if (si->connect) {
693 /* real connections have timeouts */
694 req->wto = s->be->timeout.server;
695 rep->rto = s->be->timeout.server;
696 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100697 req->wex = TICK_ETERNITY;
698}
699
700/* Update stream interface status for input states SI_ST_ASS, SI_ST_QUE, SI_ST_TAR.
701 * Other input states are simply ignored.
702 * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON.
703 * Flags must have previously been updated for timeouts and other conditions.
704 */
705void sess_update_stream_int(struct session *s, struct stream_interface *si)
706{
707 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",
708 now_ms, __FUNCTION__,
709 s,
710 s->req, s->rep,
711 s->req->rex, s->rep->wex,
712 s->req->flags, s->rep->flags,
713 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state);
714
715 if (si->state == SI_ST_ASS) {
716 /* Server assigned to connection request, we have to try to connect now */
717 int conn_err;
718
719 conn_err = connect_server(s);
720 if (conn_err == SN_ERR_NONE) {
721 /* state = SI_ST_CON now */
Willy Tarreau8f6457c2008-12-01 00:08:28 +0100722 if (s->srv)
Willy Tarreau7f062c42009-03-05 18:43:00 +0100723 srv_inc_sess_ctr(s->srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100724 return;
725 }
726
727 /* We have received a synchronous error. We might have to
728 * abort, retry immediately or redispatch.
729 */
730 if (conn_err == SN_ERR_INTERNAL) {
731 if (!si->err_type) {
732 si->err_type = SI_ET_CONN_OTHER;
733 si->err_loc = s->srv;
734 }
735
736 if (s->srv)
Willy Tarreau7f062c42009-03-05 18:43:00 +0100737 srv_inc_sess_ctr(s->srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100738 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200739 s->srv->counters.failed_conns++;
740 s->be->counters.failed_conns++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100741
742 /* release other sessions waiting for this server */
743 if (may_dequeue_tasks(s->srv, s->be))
744 process_srv_queue(s->srv);
745
746 /* Failed and not retryable. */
747 si->shutr(si);
748 si->shutw(si);
749 si->ob->flags |= BF_WRITE_ERROR;
750
751 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
752
753 /* no session was ever accounted for this server */
754 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100755 if (s->srv_error)
756 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100757 return;
758 }
759
760 /* We are facing a retryable error, but we don't want to run a
761 * turn-around now, as the problem is likely a source port
762 * allocation problem, so we want to retry now.
763 */
764 si->state = SI_ST_CER;
765 si->flags &= ~SI_FL_ERR;
766 sess_update_st_cer(s, si);
767 /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */
768 return;
769 }
770 else if (si->state == SI_ST_QUE) {
771 /* connection request was queued, check for any update */
772 if (!s->pend_pos) {
773 /* The connection is not in the queue anymore. Either
774 * we have a server connection slot available and we
775 * go directly to the assigned state, or we need to
776 * load-balance first and go to the INI state.
777 */
778 si->exp = TICK_ETERNITY;
779 if (unlikely(!(s->flags & SN_ASSIGNED)))
780 si->state = SI_ST_REQ;
781 else {
782 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
783 si->state = SI_ST_ASS;
784 }
785 return;
786 }
787
788 /* Connection request still in queue... */
789 if (si->flags & SI_FL_EXP) {
790 /* ... and timeout expired */
791 si->exp = TICK_ETERNITY;
792 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
793 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200794 s->srv->counters.failed_conns++;
795 s->be->counters.failed_conns++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100796 si->shutr(si);
797 si->shutw(si);
798 si->ob->flags |= BF_WRITE_TIMEOUT;
799 if (!si->err_type)
800 si->err_type = SI_ET_QUEUE_TO;
801 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100802 if (s->srv_error)
803 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100804 return;
805 }
806
807 /* Connection remains in queue, check if we have to abort it */
Willy Tarreau418fd472009-09-06 21:37:23 +0200808 if ((si->ob->flags & (BF_READ_ERROR)) ||
809 ((si->ob->flags & BF_SHUTW_NOW) && /* empty and client aborted */
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200810 (si->ob->flags & BF_OUT_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100811 /* give up */
812 si->exp = TICK_ETERNITY;
813 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
814 si->shutr(si);
815 si->shutw(si);
816 si->err_type |= SI_ET_QUEUE_ABRT;
817 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100818 if (s->srv_error)
819 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100820 return;
821 }
822
823 /* Nothing changed */
824 return;
825 }
826 else if (si->state == SI_ST_TAR) {
827 /* Connection request might be aborted */
Willy Tarreau418fd472009-09-06 21:37:23 +0200828 if ((si->ob->flags & (BF_READ_ERROR)) ||
829 ((si->ob->flags & BF_SHUTW_NOW) && /* empty and client aborted */
Willy Tarreauba0b63d2009-09-20 08:09:44 +0200830 (si->ob->flags & BF_OUT_EMPTY || s->be->options & PR_O_ABRT_CLOSE))) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100831 /* give up */
832 si->exp = TICK_ETERNITY;
833 si->shutr(si);
834 si->shutw(si);
835 si->err_type |= SI_ET_CONN_ABRT;
836 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100837 if (s->srv_error)
838 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100839 return;
840 }
841
842 if (!(si->flags & SI_FL_EXP))
843 return; /* still in turn-around */
844
845 si->exp = TICK_ETERNITY;
846
847 /* we keep trying on the same server as long as the session is
848 * marked "assigned".
849 * FIXME: Should we force a redispatch attempt when the server is down ?
850 */
851 if (s->flags & SN_ASSIGNED)
852 si->state = SI_ST_ASS;
853 else
854 si->state = SI_ST_REQ;
855 return;
856 }
857}
858
859/* This function initiates a server connection request on a stream interface
860 * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS,
861 * indicating that a server has been assigned. It may also return SI_ST_QUE,
862 * or SI_ST_CLO upon error.
863 */
864static void sess_prepare_conn_req(struct session *s, struct stream_interface *si) {
865 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",
866 now_ms, __FUNCTION__,
867 s,
868 s->req, s->rep,
869 s->req->rex, s->rep->wex,
870 s->req->flags, s->rep->flags,
871 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state);
872
873 if (si->state != SI_ST_REQ)
874 return;
875
876 /* Try to assign a server */
877 if (srv_redispatch_connect(s) != 0) {
878 /* We did not get a server. Either we queued the
879 * connection request, or we encountered an error.
880 */
881 if (si->state == SI_ST_QUE)
882 return;
883
884 /* we did not get any server, let's check the cause */
885 si->shutr(si);
886 si->shutw(si);
887 si->ob->flags |= BF_WRITE_ERROR;
888 if (!si->err_type)
889 si->err_type = SI_ET_CONN_OTHER;
890 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100891 if (s->srv_error)
892 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100893 return;
894 }
895
896 /* The server is assigned */
897 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
898 si->state = SI_ST_ASS;
899}
900
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200901/* This stream analyser checks the switching rules and changes the backend
Willy Tarreau4de91492010-01-22 19:10:05 +0100902 * if appropriate. The default_backend rule is also considered, then the
903 * target backend's forced persistence rules are also evaluated last if any.
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200904 * It returns 1 if the processing can continue on next analysers, or zero if it
905 * either needs more data or wants to immediately abort the request.
906 */
907int process_switching_rules(struct session *s, struct buffer *req, int an_bit)
908{
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200909 struct persist_rule *prst_rule;
Willy Tarreau4de91492010-01-22 19:10:05 +0100910
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200911 req->analysers &= ~an_bit;
912 req->analyse_exp = TICK_ETERNITY;
913
914 DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
915 now_ms, __FUNCTION__,
916 s,
917 req,
918 req->rex, req->wex,
919 req->flags,
920 req->l,
921 req->analysers);
922
923 /* now check whether we have some switching rules for this request */
924 if (!(s->flags & SN_BE_ASSIGNED)) {
925 struct switching_rule *rule;
926
927 list_for_each_entry(rule, &s->fe->switching_rules, list) {
928 int ret;
929
930 ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, ACL_DIR_REQ);
931 ret = acl_pass(ret);
932 if (rule->cond->pol == ACL_COND_UNLESS)
933 ret = !ret;
934
935 if (ret) {
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200936 if (!session_set_backend(s, rule->be.backend))
937 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200938 break;
939 }
940 }
941
942 /* To ensure correct connection accounting on the backend, we
943 * have to assign one if it was not set (eg: a listen). This
944 * measure also takes care of correctly setting the default
945 * backend if any.
946 */
947 if (!(s->flags & SN_BE_ASSIGNED))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200948 if (!session_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be))
949 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200950 }
951
Willy Tarreaufb356202010-08-03 14:02:05 +0200952 /* we don't want to run the TCP or HTTP filters again if the backend has not changed */
953 if (s->fe == s->be) {
954 s->req->analysers &= ~AN_REQ_INSPECT_BE;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200955 s->req->analysers &= ~AN_REQ_HTTP_PROCESS_BE;
Willy Tarreaufb356202010-08-03 14:02:05 +0200956 }
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200957
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200958 /* as soon as we know the backend, we must check if we have a matching forced or ignored
Willy Tarreau4de91492010-01-22 19:10:05 +0100959 * persistence rule, and report that in the session.
960 */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200961 list_for_each_entry(prst_rule, &s->be->persist_rules, list) {
Willy Tarreau4de91492010-01-22 19:10:05 +0100962 int ret = 1;
963
964 if (prst_rule->cond) {
965 ret = acl_exec_cond(prst_rule->cond, s->be, s, &s->txn, ACL_DIR_REQ);
966 ret = acl_pass(ret);
967 if (prst_rule->cond->pol == ACL_COND_UNLESS)
968 ret = !ret;
969 }
970
971 if (ret) {
972 /* no rule, or the rule matches */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200973 if (prst_rule->type == PERSIST_TYPE_FORCE) {
974 s->flags |= SN_FORCE_PRST;
975 } else {
976 s->flags |= SN_IGNORE_PRST;
977 }
Willy Tarreau4de91492010-01-22 19:10:05 +0100978 break;
979 }
980 }
981
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200982 return 1;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +0200983
984 sw_failed:
985 /* immediately abort this request in case of allocation failure */
986 buffer_abort(s->req);
987 buffer_abort(s->rep);
988
989 if (!(s->flags & SN_ERR_MASK))
990 s->flags |= SN_ERR_RESOURCE;
991 if (!(s->flags & SN_FINST_MASK))
992 s->flags |= SN_FINST_R;
993
994 s->txn.status = 500;
995 s->req->analysers = 0;
996 s->req->analyse_exp = TICK_ETERNITY;
997 return 0;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +0200998}
999
Emeric Brun1d33b292010-01-04 15:47:17 +01001000/* This stream analyser works on a request. It applies all sticking rules on
1001 * it then returns 1. The data must already be present in the buffer otherwise
1002 * they won't match. It always returns 1.
1003 */
1004int process_sticking_rules(struct session *s, struct buffer *req, int an_bit)
1005{
1006 struct proxy *px = s->be;
1007 struct sticking_rule *rule;
1008
1009 DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
1010 now_ms, __FUNCTION__,
1011 s,
1012 req,
1013 req->rex, req->wex,
1014 req->flags,
1015 req->l,
1016 req->analysers);
1017
1018 list_for_each_entry(rule, &px->sticking_rules, list) {
1019 int ret = 1 ;
1020 int i;
1021
1022 for (i = 0; i < s->store_count; i++) {
1023 if (rule->table.t == s->store[i].table)
1024 break;
1025 }
1026
1027 if (i != s->store_count)
1028 continue;
1029
1030 if (rule->cond) {
1031 ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_REQ);
1032 ret = acl_pass(ret);
1033 if (rule->cond->pol == ACL_COND_UNLESS)
1034 ret = !ret;
1035 }
1036
1037 if (ret) {
1038 struct stktable_key *key;
1039
Emeric Brun485479d2010-09-23 18:02:19 +02001040 key = stktable_fetch_key(rule->table.t, px, s, &s->txn, PATTERN_FETCH_REQ, rule->expr);
Emeric Brun1d33b292010-01-04 15:47:17 +01001041 if (!key)
1042 continue;
1043
1044 if (rule->flags & STK_IS_MATCH) {
1045 struct stksess *ts;
1046
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001047 if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001048 if (!(s->flags & SN_ASSIGNED)) {
1049 struct eb32_node *node;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001050 void *ptr;
Emeric Brun1d33b292010-01-04 15:47:17 +01001051
1052 /* srv found in table */
Willy Tarreau13c29de2010-06-06 16:40:39 +02001053 ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID);
1054 node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id));
Emeric Brun1d33b292010-01-04 15:47:17 +01001055 if (node) {
1056 struct server *srv;
1057
1058 srv = container_of(node, struct server, conf.id);
Willy Tarreau4de91492010-01-22 19:10:05 +01001059 if ((srv->state & SRV_RUNNING) ||
1060 (px->options & PR_O_PERSIST) ||
1061 (s->flags & SN_FORCE_PRST)) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001062 s->flags |= SN_DIRECT | SN_ASSIGNED;
1063 s->srv = srv;
1064 }
1065 }
1066 }
Emeric Brun85e77c72010-09-23 18:16:52 +02001067 stktable_touch(rule->table.t, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001068 }
1069 }
1070 if (rule->flags & STK_IS_STORE) {
1071 if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
1072 struct stksess *ts;
1073
1074 ts = stksess_new(rule->table.t, key);
1075 if (ts) {
1076 s->store[s->store_count].table = rule->table.t;
1077 s->store[s->store_count++].ts = ts;
1078 }
1079 }
1080 }
1081 }
1082 }
1083
1084 req->analysers &= ~an_bit;
1085 req->analyse_exp = TICK_ETERNITY;
1086 return 1;
1087}
1088
1089/* This stream analyser works on a response. It applies all store rules on it
1090 * then returns 1. The data must already be present in the buffer otherwise
1091 * they won't match. It always returns 1.
1092 */
1093int process_store_rules(struct session *s, struct buffer *rep, int an_bit)
1094{
1095 struct proxy *px = s->be;
1096 struct sticking_rule *rule;
1097 int i;
1098
1099 DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
1100 now_ms, __FUNCTION__,
1101 s,
Willy Tarreau2e2b3eb2010-02-09 20:55:44 +01001102 rep,
1103 rep->rex, rep->wex,
1104 rep->flags,
1105 rep->l,
1106 rep->analysers);
Emeric Brun1d33b292010-01-04 15:47:17 +01001107
1108 list_for_each_entry(rule, &px->storersp_rules, list) {
1109 int ret = 1 ;
1110 int storereqidx = -1;
1111
1112 for (i = 0; i < s->store_count; i++) {
1113 if (rule->table.t == s->store[i].table) {
1114 if (!(s->store[i].flags))
1115 storereqidx = i;
1116 break;
1117 }
1118 }
1119
1120 if ((i != s->store_count) && (storereqidx == -1))
1121 continue;
1122
1123 if (rule->cond) {
1124 ret = acl_exec_cond(rule->cond, px, s, &s->txn, ACL_DIR_RTR);
1125 ret = acl_pass(ret);
1126 if (rule->cond->pol == ACL_COND_UNLESS)
1127 ret = !ret;
1128 }
1129
1130 if (ret) {
1131 struct stktable_key *key;
1132
Emeric Brun485479d2010-09-23 18:02:19 +02001133 key = stktable_fetch_key(rule->table.t, px, s, &s->txn, PATTERN_FETCH_RTR, rule->expr);
Emeric Brun1d33b292010-01-04 15:47:17 +01001134 if (!key)
1135 continue;
1136
1137 if (storereqidx != -1) {
Willy Tarreau393379c2010-06-06 12:11:37 +02001138 stksess_setkey(s->store[storereqidx].table, s->store[storereqidx].ts, key);
Emeric Brun1d33b292010-01-04 15:47:17 +01001139 s->store[storereqidx].flags = 1;
1140 }
1141 else if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
1142 struct stksess *ts;
1143
1144 ts = stksess_new(rule->table.t, key);
1145 if (ts) {
1146 s->store[s->store_count].table = rule->table.t;
1147 s->store[s->store_count].flags = 1;
1148 s->store[s->store_count++].ts = ts;
1149 }
1150 }
1151 }
1152 }
1153
1154 /* process store request and store response */
1155 for (i = 0; i < s->store_count; i++) {
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001156 struct stksess *ts;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001157 void *ptr;
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001158
1159 ts = stktable_lookup(s->store[i].table, s->store[i].ts);
1160 if (ts) {
1161 /* the entry already existed, we can free ours */
Emeric Brun85e77c72010-09-23 18:16:52 +02001162 stktable_touch(s->store[i].table, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001163 stksess_free(s->store[i].table, s->store[i].ts);
Emeric Brun1d33b292010-01-04 15:47:17 +01001164 }
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001165 else
Emeric Brun85e77c72010-09-23 18:16:52 +02001166 ts = stktable_store(s->store[i].table, s->store[i].ts, 1);
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001167
1168 s->store[i].ts = NULL;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001169 ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID);
1170 stktable_data_cast(ptr, server_id) = s->srv->puid;
Emeric Brun1d33b292010-01-04 15:47:17 +01001171 }
Willy Tarreau2a164ee2010-06-18 09:57:45 +02001172 s->store_count = 0; /* everything is stored */
Emeric Brun1d33b292010-01-04 15:47:17 +01001173
1174 rep->analysers &= ~an_bit;
1175 rep->analyse_exp = TICK_ETERNITY;
1176 return 1;
1177}
1178
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001179/* This macro is very specific to the function below. See the comments in
1180 * process_session() below to understand the logic and the tests.
1181 */
1182#define UPDATE_ANALYSERS(real, list, back, flag) { \
1183 list = (((list) & ~(flag)) | ~(back)) & (real); \
1184 back = real; \
1185 if (!(list)) \
1186 break; \
1187 if (((list) ^ ((list) & ((list) - 1))) < (flag)) \
1188 continue; \
1189}
1190
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001191/* Processes the client, server, request and response jobs of a session task,
1192 * then puts it back to the wait queue in a clean state, or cleans up its
1193 * resources if it must be deleted. Returns in <next> the date the task wants
1194 * to be woken up, or TICK_ETERNITY. In order not to call all functions for
1195 * nothing too many times, the request and response buffers flags are monitored
1196 * and each function is called only if at least another function has changed at
1197 * least one flag it is interested in.
1198 */
Willy Tarreau26c25062009-03-08 09:38:41 +01001199struct task *process_session(struct task *t)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001200{
1201 struct session *s = t->context;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001202 unsigned int rqf_last, rpf_last;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001203 unsigned int rq_prod_last, rq_cons_last;
1204 unsigned int rp_cons_last, rp_prod_last;
Willy Tarreau576507f2010-01-07 00:09:04 +01001205 unsigned int req_ana_back;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001206
1207 //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
1208 // s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s->rep->flags);
1209
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001210 /* this data may be no longer valid, clear it */
1211 memset(&s->txn.auth, 0, sizeof(s->txn.auth));
1212
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001213 /* This flag must explicitly be set every time */
1214 s->req->flags &= ~BF_READ_NOEXP;
1215
1216 /* Keep a copy of req/rep flags so that we can detect shutdowns */
Willy Tarreau2f976e12010-11-11 14:28:47 +01001217 rqf_last = s->req->flags & ~BF_MASK_ANALYSER;
1218 rpf_last = s->rep->flags & ~BF_MASK_ANALYSER;
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001219
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001220 /* we don't want the stream interface functions to recursively wake us up */
1221 if (s->req->prod->owner == t)
1222 s->req->prod->flags |= SI_FL_DONT_WAKE;
1223 if (s->req->cons->owner == t)
1224 s->req->cons->flags |= SI_FL_DONT_WAKE;
1225
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001226 /* 1a: Check for low level timeouts if needed. We just set a flag on
1227 * stream interfaces when their timeouts have expired.
1228 */
1229 if (unlikely(t->state & TASK_WOKEN_TIMER)) {
1230 stream_int_check_timeouts(&s->si[0]);
1231 stream_int_check_timeouts(&s->si[1]);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001232
1233 /* check buffer timeouts, and close the corresponding stream interfaces
1234 * for future reads or writes. Note: this will also concern upper layers
1235 * but we do not touch any other flag. We must be careful and correctly
1236 * detect state changes when calling them.
1237 */
1238
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001239 buffer_check_timeouts(s->req);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001240
Willy Tarreau14641402009-12-29 14:49:56 +01001241 if (unlikely((s->req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) {
1242 s->req->cons->flags |= SI_FL_NOLINGER;
1243 s->req->cons->shutw(s->req->cons);
1244 }
1245
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001246 if (unlikely((s->req->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
1247 s->req->prod->shutr(s->req->prod);
1248
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001249 buffer_check_timeouts(s->rep);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001250
Willy Tarreau14641402009-12-29 14:49:56 +01001251 if (unlikely((s->rep->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == BF_WRITE_TIMEOUT)) {
1252 s->rep->cons->flags |= SI_FL_NOLINGER;
1253 s->rep->cons->shutw(s->rep->cons);
1254 }
1255
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001256 if (unlikely((s->rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == BF_READ_TIMEOUT))
1257 s->rep->prod->shutr(s->rep->prod);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001258 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001259
1260 /* 1b: check for low-level errors reported at the stream interface.
1261 * First we check if it's a retryable error (in which case we don't
1262 * want to tell the buffer). Otherwise we report the error one level
1263 * upper by setting flags into the buffers. Note that the side towards
1264 * the client cannot have connect (hence retryable) errors. Also, the
1265 * connection setup code must be able to deal with any type of abort.
1266 */
1267 if (unlikely(s->si[0].flags & SI_FL_ERR)) {
1268 if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) {
1269 s->si[0].shutr(&s->si[0]);
1270 s->si[0].shutw(&s->si[0]);
1271 stream_int_report_error(&s->si[0]);
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001272 if (!(s->req->analysers) && !(s->rep->analysers)) {
Willy Tarreauae526782010-03-04 20:34:23 +01001273 s->be->counters.cli_aborts++;
1274 if (s->srv)
1275 s->srv->counters.cli_aborts++;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001276 if (!(s->flags & SN_ERR_MASK))
1277 s->flags |= SN_ERR_CLICL;
1278 if (!(s->flags & SN_FINST_MASK))
1279 s->flags |= SN_FINST_D;
1280 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001281 }
1282 }
1283
1284 if (unlikely(s->si[1].flags & SI_FL_ERR)) {
1285 if (s->si[1].state == SI_ST_EST || s->si[1].state == SI_ST_DIS) {
1286 s->si[1].shutr(&s->si[1]);
1287 s->si[1].shutw(&s->si[1]);
1288 stream_int_report_error(&s->si[1]);
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001289 s->be->counters.failed_resp++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001290 if (s->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001291 s->srv->counters.failed_resp++;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001292 if (!(s->req->analysers) && !(s->rep->analysers)) {
Willy Tarreauae526782010-03-04 20:34:23 +01001293 s->be->counters.srv_aborts++;
1294 if (s->srv)
1295 s->srv->counters.srv_aborts++;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001296 if (!(s->flags & SN_ERR_MASK))
1297 s->flags |= SN_ERR_SRVCL;
1298 if (!(s->flags & SN_FINST_MASK))
1299 s->flags |= SN_FINST_D;
1300 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001301 }
1302 /* note: maybe we should process connection errors here ? */
1303 }
1304
1305 if (s->si[1].state == SI_ST_CON) {
1306 /* we were trying to establish a connection on the server side,
1307 * maybe it succeeded, maybe it failed, maybe we timed out, ...
1308 */
1309 if (unlikely(!sess_update_st_con_tcp(s, &s->si[1])))
1310 sess_update_st_cer(s, &s->si[1]);
1311 else if (s->si[1].state == SI_ST_EST)
1312 sess_establish(s, &s->si[1]);
1313
1314 /* state is now one of SI_ST_CON (still in progress), SI_ST_EST
1315 * (established), SI_ST_DIS (abort), SI_ST_CLO (last error),
1316 * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors.
1317 */
1318 }
1319
Willy Tarreau815a9b22010-07-27 17:15:12 +02001320 rq_prod_last = s->si[0].state;
1321 rq_cons_last = s->si[1].state;
1322 rp_cons_last = s->si[0].state;
1323 rp_prod_last = s->si[1].state;
1324
1325 resync_stream_interface:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001326 /* Check for connection closure */
1327
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001328 DPRINTF(stderr,
1329 "[%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",
1330 now_ms, __FUNCTION__, __LINE__,
1331 t,
1332 s, s->flags,
1333 s->req, s->rep,
1334 s->req->rex, s->rep->wex,
1335 s->req->flags, s->rep->flags,
1336 s->req->l, s->rep->l, s->rep->cons->state, s->req->cons->state,
1337 s->rep->cons->err_type, s->req->cons->err_type,
Willy Tarreauee28de02010-06-01 09:51:00 +02001338 s->req->cons->conn_retries);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001339
1340 /* nothing special to be done on client side */
1341 if (unlikely(s->req->prod->state == SI_ST_DIS))
1342 s->req->prod->state = SI_ST_CLO;
1343
1344 /* When a server-side connection is released, we have to count it and
1345 * check for pending connections on this server.
1346 */
1347 if (unlikely(s->req->cons->state == SI_ST_DIS)) {
1348 s->req->cons->state = SI_ST_CLO;
1349 if (s->srv) {
1350 if (s->flags & SN_CURR_SESS) {
1351 s->flags &= ~SN_CURR_SESS;
1352 s->srv->cur_sess--;
1353 }
1354 sess_change_server(s, NULL);
1355 if (may_dequeue_tasks(s->srv, s->be))
1356 process_srv_queue(s->srv);
1357 }
1358 }
1359
1360 /*
1361 * Note: of the transient states (REQ, CER, DIS), only REQ may remain
1362 * at this point.
1363 */
1364
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001365 resync_request:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001366 /* Analyse request */
Willy Tarreau2f976e12010-11-11 14:28:47 +01001367 if (((s->req->flags & ~rqf_last) & BF_MASK_ANALYSER) ||
Willy Tarreau815a9b22010-07-27 17:15:12 +02001368 ((s->req->flags ^ rqf_last) & BF_MASK_STATIC) ||
1369 s->si[0].state != rq_prod_last ||
1370 s->si[1].state != rq_cons_last) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001371 unsigned int flags = s->req->flags;
1372
1373 if (s->req->prod->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001374 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001375 unsigned int ana_list;
1376 unsigned int ana_back;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001377
Willy Tarreau90deb182010-01-07 00:20:41 +01001378 /* it's up to the analysers to stop new connections,
1379 * disable reading or closing. Note: if an analyser
1380 * disables any of these bits, it is responsible for
1381 * enabling them again when it disables itself, so
1382 * that other analysers are called in similar conditions.
1383 */
1384 buffer_auto_read(s->req);
Willy Tarreau520d95e2009-09-19 21:04:57 +02001385 buffer_auto_connect(s->req);
1386 buffer_auto_close(s->req);
Willy Tarreauedcf6682008-11-30 23:15:34 +01001387
1388 /* We will call all analysers for which a bit is set in
1389 * s->req->analysers, following the bit order from LSB
1390 * to MSB. The analysers must remove themselves from
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001391 * the list when not needed. Any analyser may return 0
1392 * to break out of the loop, either because of missing
1393 * data to take a decision, or because it decides to
1394 * kill the session. We loop at least once through each
1395 * analyser, and we may loop again if other analysers
1396 * are added in the middle.
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001397 *
1398 * We build a list of analysers to run. We evaluate all
1399 * of these analysers in the order of the lower bit to
1400 * the higher bit. This ordering is very important.
1401 * An analyser will often add/remove other analysers,
1402 * including itself. Any changes to itself have no effect
1403 * on the loop. If it removes any other analysers, we
1404 * want those analysers not to be called anymore during
1405 * this loop. If it adds an analyser that is located
1406 * after itself, we want it to be scheduled for being
1407 * processed during the loop. If it adds an analyser
1408 * which is located before it, we want it to switch to
1409 * it immediately, even if it has already been called
1410 * once but removed since.
1411 *
1412 * In order to achieve this, we compare the analyser
1413 * list after the call with a copy of it before the
1414 * call. The work list is fed with analyser bits that
1415 * appeared during the call. Then we compare previous
1416 * work list with the new one, and check the bits that
1417 * appeared. If the lowest of these bits is lower than
1418 * the current bit, it means we have enabled a previous
1419 * analyser and must immediately loop again.
Willy Tarreauedcf6682008-11-30 23:15:34 +01001420 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001421
1422 ana_list = ana_back = s->req->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001423 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001424 /* Warning! ensure that analysers are always placed in ascending order! */
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001425
Willy Tarreau3041b9f2010-10-15 23:25:20 +02001426 if (ana_list & AN_REQ_DECODE_PROXY) {
1427 if (!frontend_decode_proxy_request(s, s->req, AN_REQ_DECODE_PROXY))
1428 break;
1429 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_DECODE_PROXY);
1430 }
1431
Willy Tarreaufb356202010-08-03 14:02:05 +02001432 if (ana_list & AN_REQ_INSPECT_FE) {
1433 if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_FE))
Willy Tarreauedcf6682008-11-30 23:15:34 +01001434 break;
Willy Tarreaufb356202010-08-03 14:02:05 +02001435 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_FE);
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001436 }
Willy Tarreauedcf6682008-11-30 23:15:34 +01001437
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001438 if (ana_list & AN_REQ_WAIT_HTTP) {
Willy Tarreau3a816292009-07-07 10:55:49 +02001439 if (!http_wait_for_request(s, s->req, AN_REQ_WAIT_HTTP))
Willy Tarreaud787e662009-07-07 10:14:51 +02001440 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001441 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_WAIT_HTTP);
Willy Tarreaud787e662009-07-07 10:14:51 +02001442 }
1443
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001444 if (ana_list & AN_REQ_HTTP_PROCESS_FE) {
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001445 if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_FE, s->fe))
1446 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001447 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE);
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001448 }
1449
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001450 if (ana_list & AN_REQ_SWITCHING_RULES) {
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001451 if (!process_switching_rules(s, s->req, AN_REQ_SWITCHING_RULES))
1452 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001453 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_SWITCHING_RULES);
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001454 }
1455
Willy Tarreaufb356202010-08-03 14:02:05 +02001456 if (ana_list & AN_REQ_INSPECT_BE) {
1457 if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_BE))
1458 break;
1459 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_BE);
1460 }
1461
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001462 if (ana_list & AN_REQ_HTTP_PROCESS_BE) {
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001463 if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_BE, s->be))
1464 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001465 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE);
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001466 }
1467
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001468 if (ana_list & AN_REQ_HTTP_TARPIT) {
Willy Tarreau3a816292009-07-07 10:55:49 +02001469 if (!http_process_tarpit(s, s->req, AN_REQ_HTTP_TARPIT))
Willy Tarreau60b85b02008-11-30 23:28:40 +01001470 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001471 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_TARPIT);
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001472 }
Willy Tarreau60b85b02008-11-30 23:28:40 +01001473
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001474 if (ana_list & AN_REQ_HTTP_INNER) {
Willy Tarreauc465fd72009-08-31 00:17:18 +02001475 if (!http_process_request(s, s->req, AN_REQ_HTTP_INNER))
1476 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001477 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_INNER);
Willy Tarreauc465fd72009-08-31 00:17:18 +02001478 }
1479
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001480 if (ana_list & AN_REQ_HTTP_BODY) {
Willy Tarreau3a816292009-07-07 10:55:49 +02001481 if (!http_process_request_body(s, s->req, AN_REQ_HTTP_BODY))
Willy Tarreaud34af782008-11-30 23:36:37 +01001482 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001483 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_BODY);
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001484 }
Emeric Brun647caf12009-06-30 17:57:00 +02001485
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001486 if (ana_list & AN_REQ_PRST_RDP_COOKIE) {
Emeric Brun647caf12009-06-30 17:57:00 +02001487 if (!tcp_persist_rdp_cookie(s, s->req, AN_REQ_PRST_RDP_COOKIE))
1488 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001489 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE);
Emeric Brun647caf12009-06-30 17:57:00 +02001490 }
Willy Tarreaud98cf932009-12-27 22:54:55 +01001491
Emeric Brun1d33b292010-01-04 15:47:17 +01001492 if (ana_list & AN_REQ_STICKING_RULES) {
1493 if (!process_sticking_rules(s, s->req, AN_REQ_STICKING_RULES))
1494 break;
1495 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_STICKING_RULES);
1496 }
1497
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001498 if (ana_list & AN_REQ_HTTP_XFER_BODY) {
Willy Tarreaud98cf932009-12-27 22:54:55 +01001499 if (!http_request_forward_body(s, s->req, AN_REQ_HTTP_XFER_BODY))
1500 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001501 UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY);
Willy Tarreaud98cf932009-12-27 22:54:55 +01001502 }
Willy Tarreaue34070e2010-01-08 00:32:27 +01001503 break;
1504 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001505 }
Willy Tarreau84455332009-03-15 22:34:05 +01001506
Willy Tarreau815a9b22010-07-27 17:15:12 +02001507 rq_prod_last = s->si[0].state;
1508 rq_cons_last = s->si[1].state;
1509 rqf_last = s->req->flags;
1510
1511 if ((s->req->flags ^ flags) & BF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001512 goto resync_request;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001513 }
1514
Willy Tarreau576507f2010-01-07 00:09:04 +01001515 /* we'll monitor the request analysers while parsing the response,
1516 * because some response analysers may indirectly enable new request
1517 * analysers (eg: HTTP keep-alive).
1518 */
1519 req_ana_back = s->req->analysers;
1520
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001521 resync_response:
1522 /* Analyse response */
1523
1524 if (unlikely(s->rep->flags & BF_HIJACK)) {
1525 /* In inject mode, we wake up everytime something has
1526 * happened on the write side of the buffer.
1527 */
1528 unsigned int flags = s->rep->flags;
1529
1530 if ((s->rep->flags & (BF_WRITE_PARTIAL|BF_WRITE_ERROR|BF_SHUTW)) &&
1531 !(s->rep->flags & BF_FULL)) {
1532 s->rep->hijacker(s, s->rep);
1533 }
1534
1535 if ((s->rep->flags ^ flags) & BF_MASK_STATIC) {
1536 rpf_last = s->rep->flags;
1537 goto resync_response;
1538 }
1539 }
Willy Tarreau2f976e12010-11-11 14:28:47 +01001540 else if (((s->rep->flags & ~rpf_last) & BF_MASK_ANALYSER) ||
Willy Tarreau815a9b22010-07-27 17:15:12 +02001541 (s->rep->flags ^ rpf_last) & BF_MASK_STATIC ||
1542 s->si[0].state != rp_cons_last ||
1543 s->si[1].state != rp_prod_last) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001544 unsigned int flags = s->rep->flags;
1545
1546 if (s->rep->prod->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001547 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001548 unsigned int ana_list;
1549 unsigned int ana_back;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001550
Willy Tarreau90deb182010-01-07 00:20:41 +01001551 /* it's up to the analysers to stop disable reading or
1552 * closing. Note: if an analyser disables any of these
1553 * bits, it is responsible for enabling them again when
1554 * it disables itself, so that other analysers are called
1555 * in similar conditions.
1556 */
1557 buffer_auto_read(s->rep);
Willy Tarreau520d95e2009-09-19 21:04:57 +02001558 buffer_auto_close(s->rep);
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001559
1560 /* We will call all analysers for which a bit is set in
1561 * s->rep->analysers, following the bit order from LSB
1562 * to MSB. The analysers must remove themselves from
1563 * the list when not needed. Any analyser may return 0
1564 * to break out of the loop, either because of missing
1565 * data to take a decision, or because it decides to
1566 * kill the session. We loop at least once through each
1567 * analyser, and we may loop again if other analysers
1568 * are added in the middle.
1569 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001570
1571 ana_list = ana_back = s->rep->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001572 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001573 /* Warning! ensure that analysers are always placed in ascending order! */
1574
Emeric Brun97679e72010-09-23 17:56:44 +02001575 if (ana_list & AN_RES_INSPECT) {
1576 if (!tcp_inspect_response(s, s->rep, AN_RES_INSPECT))
1577 break;
1578 UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_INSPECT);
1579 }
1580
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001581 if (ana_list & AN_RES_WAIT_HTTP) {
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001582 if (!http_wait_for_response(s, s->rep, AN_RES_WAIT_HTTP))
1583 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001584 UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_WAIT_HTTP);
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001585 }
1586
Emeric Brun1d33b292010-01-04 15:47:17 +01001587 if (ana_list & AN_RES_STORE_RULES) {
1588 if (!process_store_rules(s, s->rep, AN_RES_STORE_RULES))
1589 break;
1590 UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_STORE_RULES);
1591 }
1592
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001593 if (ana_list & AN_RES_HTTP_PROCESS_BE) {
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001594 if (!http_process_res_common(s, s->rep, AN_RES_HTTP_PROCESS_BE, s->be))
1595 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001596 UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE);
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001597 }
Willy Tarreaud98cf932009-12-27 22:54:55 +01001598
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001599 if (ana_list & AN_RES_HTTP_XFER_BODY) {
Willy Tarreaud98cf932009-12-27 22:54:55 +01001600 if (!http_response_forward_body(s, s->rep, AN_RES_HTTP_XFER_BODY))
1601 break;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001602 UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_XFER_BODY);
Willy Tarreaud98cf932009-12-27 22:54:55 +01001603 }
Willy Tarreaue34070e2010-01-08 00:32:27 +01001604 break;
1605 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001606 }
1607
Willy Tarreau815a9b22010-07-27 17:15:12 +02001608 rp_cons_last = s->si[0].state;
1609 rp_prod_last = s->si[1].state;
1610 rpf_last = s->rep->flags;
1611
1612 if ((s->rep->flags ^ flags) & BF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001613 goto resync_response;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001614 }
1615
Willy Tarreau576507f2010-01-07 00:09:04 +01001616 /* maybe someone has added some request analysers, so we must check and loop */
1617 if (s->req->analysers & ~req_ana_back)
1618 goto resync_request;
1619
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001620 /* FIXME: here we should call protocol handlers which rely on
1621 * both buffers.
1622 */
1623
1624
1625 /*
Willy Tarreauae526782010-03-04 20:34:23 +01001626 * Now we propagate unhandled errors to the session. Normally
1627 * we're just in a data phase here since it means we have not
1628 * seen any analyser who could set an error status.
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001629 */
Willy Tarreau2f976e12010-11-11 14:28:47 +01001630 if (unlikely(!(s->flags & SN_ERR_MASK))) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001631 if (s->req->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) {
1632 /* Report it if the client got an error or a read timeout expired */
Willy Tarreau84455332009-03-15 22:34:05 +01001633 s->req->analysers = 0;
Willy Tarreauae526782010-03-04 20:34:23 +01001634 if (s->req->flags & BF_READ_ERROR) {
1635 s->be->counters.cli_aborts++;
1636 if (s->srv)
1637 s->srv->counters.cli_aborts++;
Willy Tarreau84455332009-03-15 22:34:05 +01001638 s->flags |= SN_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01001639 }
1640 else if (s->req->flags & BF_READ_TIMEOUT) {
1641 s->be->counters.cli_aborts++;
1642 if (s->srv)
1643 s->srv->counters.cli_aborts++;
Willy Tarreau84455332009-03-15 22:34:05 +01001644 s->flags |= SN_ERR_CLITO;
Willy Tarreauae526782010-03-04 20:34:23 +01001645 }
1646 else if (s->req->flags & BF_WRITE_ERROR) {
1647 s->be->counters.srv_aborts++;
1648 if (s->srv)
1649 s->srv->counters.srv_aborts++;
Willy Tarreau84455332009-03-15 22:34:05 +01001650 s->flags |= SN_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001651 }
1652 else {
1653 s->be->counters.srv_aborts++;
1654 if (s->srv)
1655 s->srv->counters.srv_aborts++;
Willy Tarreau84455332009-03-15 22:34:05 +01001656 s->flags |= SN_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001657 }
Willy Tarreau84455332009-03-15 22:34:05 +01001658 sess_set_term_flags(s);
1659 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001660 else if (s->rep->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) {
1661 /* Report it if the server got an error or a read timeout expired */
1662 s->rep->analysers = 0;
Willy Tarreauae526782010-03-04 20:34:23 +01001663 if (s->rep->flags & BF_READ_ERROR) {
1664 s->be->counters.srv_aborts++;
1665 if (s->srv)
1666 s->srv->counters.srv_aborts++;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001667 s->flags |= SN_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001668 }
1669 else if (s->rep->flags & BF_READ_TIMEOUT) {
1670 s->be->counters.srv_aborts++;
1671 if (s->srv)
1672 s->srv->counters.srv_aborts++;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001673 s->flags |= SN_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001674 }
1675 else if (s->rep->flags & BF_WRITE_ERROR) {
1676 s->be->counters.cli_aborts++;
1677 if (s->srv)
1678 s->srv->counters.cli_aborts++;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001679 s->flags |= SN_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01001680 }
1681 else {
1682 s->be->counters.cli_aborts++;
1683 if (s->srv)
1684 s->srv->counters.cli_aborts++;
1685 s->flags |= SN_ERR_CLITO;
1686 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001687 sess_set_term_flags(s);
1688 }
Willy Tarreau84455332009-03-15 22:34:05 +01001689 }
1690
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001691 /*
1692 * Here we take care of forwarding unhandled data. This also includes
1693 * connection establishments and shutdown requests.
1694 */
1695
1696
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001697 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02001698 * everything. We configure the buffer to forward indefinitely.
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001699 * Note that we're checking BF_SHUTR_NOW as an indication of a possible
1700 * recent call to buffer_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001701 */
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001702 if (!s->req->analysers &&
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001703 !(s->req->flags & (BF_HIJACK|BF_SHUTW|BF_SHUTR_NOW)) &&
Willy Tarreau31971e52009-09-20 12:07:52 +02001704 (s->req->prod->state >= SI_ST_EST) &&
1705 (s->req->to_forward != BUF_INFINITE_FORWARD)) {
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001706 /* This buffer is freewheeling, there's no analyser nor hijacker
1707 * attached to it. If any data are left in, we'll permit them to
1708 * move.
1709 */
Willy Tarreau90deb182010-01-07 00:20:41 +01001710 buffer_auto_read(s->req);
Willy Tarreau520d95e2009-09-19 21:04:57 +02001711 buffer_auto_connect(s->req);
1712 buffer_auto_close(s->req);
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001713 buffer_flush(s->req);
Willy Tarreau5bd8c372009-01-19 00:32:22 +01001714
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001715 /* We'll let data flow between the producer (if still connected)
1716 * to the consumer (which might possibly not be connected yet).
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001717 */
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001718 if (!(s->req->flags & (BF_SHUTR|BF_SHUTW_NOW)))
Willy Tarreau31971e52009-09-20 12:07:52 +02001719 buffer_forward(s->req, BUF_INFINITE_FORWARD);
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001720 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01001721
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001722 /* check if it is wise to enable kernel splicing to forward request data */
1723 if (!(s->req->flags & (BF_KERN_SPLICING|BF_SHUTR)) &&
1724 s->req->to_forward &&
1725 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreaudc340a92009-06-28 23:10:19 +02001726 (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001727 (pipes_used < global.maxpipes) &&
1728 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
1729 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
1730 (s->req->flags & BF_STREAMER_FAST)))) {
1731 s->req->flags |= BF_KERN_SPLICING;
1732 }
1733
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001734 /* reflect what the L7 analysers have seen last */
1735 rqf_last = s->req->flags;
1736
1737 /*
1738 * Now forward all shutdown requests between both sides of the buffer
1739 */
1740
Willy Tarreau520d95e2009-09-19 21:04:57 +02001741 /* first, let's check if the request buffer needs to shutdown(write), which may
1742 * happen either because the input is closed or because we want to force a close
Willy Tarreaue4599762010-03-21 23:25:09 +01001743 * once the server has begun to respond.
Willy Tarreau520d95e2009-09-19 21:04:57 +02001744 */
Willy Tarreau82eeaf22009-12-29 12:09:05 +01001745 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK|BF_AUTO_CLOSE|BF_SHUTR)) ==
Willy Tarreaue4599762010-03-21 23:25:09 +01001746 (BF_AUTO_CLOSE|BF_SHUTR)))
Willy Tarreauba0b63d2009-09-20 08:09:44 +02001747 buffer_shutw_now(s->req);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001748
1749 /* shutdown(write) pending */
Willy Tarreauba0b63d2009-09-20 08:09:44 +02001750 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_OUT_EMPTY)) == (BF_SHUTW_NOW|BF_OUT_EMPTY)))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001751 s->req->cons->shutw(s->req->cons);
1752
1753 /* shutdown(write) done on server side, we must stop the client too */
Willy Tarreau3dbc6942008-12-07 13:05:04 +01001754 if (unlikely((s->req->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW &&
1755 !s->req->analysers))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001756 buffer_shutr_now(s->req);
1757
1758 /* shutdown(read) pending */
1759 if (unlikely((s->req->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW))
1760 s->req->prod->shutr(s->req->prod);
1761
Willy Tarreau520d95e2009-09-19 21:04:57 +02001762 /* it's possible that an upper layer has requested a connection setup or abort.
1763 * There are 2 situations where we decide to establish a new connection :
1764 * - there are data scheduled for emission in the buffer
1765 * - the BF_AUTO_CONNECT flag is set (active connection)
1766 */
1767 if (s->req->cons->state == SI_ST_INI) {
Willy Tarreaue4599762010-03-21 23:25:09 +01001768 if (!(s->req->flags & BF_SHUTW)) {
Willy Tarreauba0b63d2009-09-20 08:09:44 +02001769 if ((s->req->flags & (BF_AUTO_CONNECT|BF_OUT_EMPTY)) != BF_OUT_EMPTY) {
Willy Tarreau85e7d002010-05-31 11:57:51 +02001770 /* If we have an iohandler without a connect method, we immediately
1771 * switch to the connected state, otherwise we perform a connection
1772 * request.
Willy Tarreau520d95e2009-09-19 21:04:57 +02001773 */
Willy Tarreau85e7d002010-05-31 11:57:51 +02001774 s->req->cons->state = SI_ST_REQ; /* new connection requested */
Willy Tarreau070ceb62010-06-01 10:36:43 +02001775 s->req->cons->conn_retries = s->be->conn_retries;
Willy Tarreau85e7d002010-05-31 11:57:51 +02001776 if (unlikely(s->req->cons->iohandler && !s->req->cons->connect)) {
Willy Tarreau520d95e2009-09-19 21:04:57 +02001777 s->req->cons->state = SI_ST_EST; /* connection established */
Willy Tarreau85e7d002010-05-31 11:57:51 +02001778 s->rep->flags |= BF_READ_ATTACHED; /* producer is now attached */
1779 s->req->wex = TICK_ETERNITY;
1780 }
Willy Tarreau520d95e2009-09-19 21:04:57 +02001781 }
Willy Tarreau73201222009-08-16 18:27:24 +02001782 }
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02001783 else {
Willy Tarreau92795622009-03-06 12:51:23 +01001784 s->req->cons->state = SI_ST_CLO; /* shutw+ini = abort */
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02001785 buffer_shutw_now(s->req); /* fix buffer flags upon abort */
1786 buffer_shutr_now(s->rep);
1787 }
Willy Tarreau92795622009-03-06 12:51:23 +01001788 }
1789
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001790
1791 /* we may have a pending connection request, or a connection waiting
1792 * for completion.
1793 */
1794 if (s->si[1].state >= SI_ST_REQ && s->si[1].state < SI_ST_CON) {
1795 do {
1796 /* nb: step 1 might switch from QUE to ASS, but we first want
1797 * to give a chance to step 2 to perform a redirect if needed.
1798 */
1799 if (s->si[1].state != SI_ST_REQ)
1800 sess_update_stream_int(s, &s->si[1]);
1801 if (s->si[1].state == SI_ST_REQ)
1802 sess_prepare_conn_req(s, &s->si[1]);
1803
1804 if (s->si[1].state == SI_ST_ASS && s->srv &&
1805 s->srv->rdr_len && (s->flags & SN_REDIRECTABLE))
1806 perform_http_redirect(s, &s->si[1]);
1807 } while (s->si[1].state == SI_ST_ASS);
1808 }
1809
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001810 /* Benchmarks have shown that it's optimal to do a full resync now */
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001811 if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001812 goto resync_stream_interface;
1813
Willy Tarreau815a9b22010-07-27 17:15:12 +02001814 /* otherwise we want to check if we need to resync the req buffer or not */
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001815 if ((s->req->flags ^ rqf_last) & BF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001816 goto resync_request;
1817
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001818 /* perform output updates to the response buffer */
Willy Tarreau84455332009-03-15 22:34:05 +01001819
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001820 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02001821 * everything. We configure the buffer to forward indefinitely.
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001822 * Note that we're checking BF_SHUTR_NOW as an indication of a possible
1823 * recent call to buffer_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001824 */
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001825 if (!s->rep->analysers &&
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001826 !(s->rep->flags & (BF_HIJACK|BF_SHUTW|BF_SHUTR_NOW)) &&
Willy Tarreau31971e52009-09-20 12:07:52 +02001827 (s->rep->prod->state >= SI_ST_EST) &&
1828 (s->rep->to_forward != BUF_INFINITE_FORWARD)) {
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001829 /* This buffer is freewheeling, there's no analyser nor hijacker
1830 * attached to it. If any data are left in, we'll permit them to
1831 * move.
1832 */
Willy Tarreau90deb182010-01-07 00:20:41 +01001833 buffer_auto_read(s->rep);
Willy Tarreau520d95e2009-09-19 21:04:57 +02001834 buffer_auto_close(s->rep);
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001835 buffer_flush(s->rep);
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01001836
1837 /* We'll let data flow between the producer (if still connected)
1838 * to the consumer.
1839 */
1840 if (!(s->rep->flags & (BF_SHUTR|BF_SHUTW_NOW)))
Willy Tarreau31971e52009-09-20 12:07:52 +02001841 buffer_forward(s->rep, BUF_INFINITE_FORWARD);
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001842 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01001843
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001844 /* check if it is wise to enable kernel splicing to forward response data */
1845 if (!(s->rep->flags & (BF_KERN_SPLICING|BF_SHUTR)) &&
1846 s->rep->to_forward &&
1847 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreaudc340a92009-06-28 23:10:19 +02001848 (s->si[0].flags & s->si[1].flags & SI_FL_CAP_SPLICE) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01001849 (pipes_used < global.maxpipes) &&
1850 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
1851 (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
1852 (s->rep->flags & BF_STREAMER_FAST)))) {
1853 s->rep->flags |= BF_KERN_SPLICING;
1854 }
1855
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001856 /* reflect what the L7 analysers have seen last */
1857 rpf_last = s->rep->flags;
1858
1859 /*
1860 * Now forward all shutdown requests between both sides of the buffer
1861 */
1862
1863 /*
1864 * FIXME: this is probably where we should produce error responses.
1865 */
1866
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01001867 /* first, let's check if the response buffer needs to shutdown(write) */
Willy Tarreau520d95e2009-09-19 21:04:57 +02001868 if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTW_NOW|BF_HIJACK|BF_AUTO_CLOSE|BF_SHUTR)) ==
1869 (BF_AUTO_CLOSE|BF_SHUTR)))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001870 buffer_shutw_now(s->rep);
1871
1872 /* shutdown(write) pending */
Willy Tarreauba0b63d2009-09-20 08:09:44 +02001873 if (unlikely((s->rep->flags & (BF_SHUTW|BF_OUT_EMPTY|BF_SHUTW_NOW)) == (BF_OUT_EMPTY|BF_SHUTW_NOW)))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001874 s->rep->cons->shutw(s->rep->cons);
1875
1876 /* shutdown(write) done on the client side, we must stop the server too */
Willy Tarreau3dbc6942008-12-07 13:05:04 +01001877 if (unlikely((s->rep->flags & (BF_SHUTW|BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTW) &&
1878 !s->rep->analysers)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001879 buffer_shutr_now(s->rep);
1880
1881 /* shutdown(read) pending */
1882 if (unlikely((s->rep->flags & (BF_SHUTR|BF_SHUTR_NOW)) == BF_SHUTR_NOW))
1883 s->rep->prod->shutr(s->rep->prod);
1884
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001885 if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001886 goto resync_stream_interface;
1887
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001888 if (s->req->flags != rqf_last)
1889 goto resync_request;
1890
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001891 if ((s->rep->flags ^ rpf_last) & BF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001892 goto resync_response;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001893
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001894 /* we're interested in getting wakeups again */
1895 s->req->prod->flags &= ~SI_FL_DONT_WAKE;
1896 s->req->cons->flags &= ~SI_FL_DONT_WAKE;
1897
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001898 /* This is needed only when debugging is enabled, to indicate
1899 * client-side or server-side close. Please note that in the unlikely
1900 * event where both sides would close at once, the sequence is reported
1901 * on the server side first.
1902 */
1903 if (unlikely((global.mode & MODE_DEBUG) &&
1904 (!(global.mode & MODE_QUIET) ||
1905 (global.mode & MODE_VERBOSE)))) {
1906 int len;
1907
1908 if (s->si[1].state == SI_ST_CLO &&
1909 s->si[1].prev_state == SI_ST_EST) {
1910 len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n",
1911 s->uniq_id, s->be->id,
1912 (unsigned short)s->si[0].fd,
1913 (unsigned short)s->si[1].fd);
1914 write(1, trash, len);
1915 }
1916
1917 if (s->si[0].state == SI_ST_CLO &&
1918 s->si[0].prev_state == SI_ST_EST) {
1919 len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n",
1920 s->uniq_id, s->be->id,
1921 (unsigned short)s->si[0].fd,
1922 (unsigned short)s->si[1].fd);
1923 write(1, trash, len);
1924 }
1925 }
1926
1927 if (likely((s->rep->cons->state != SI_ST_CLO) ||
1928 (s->req->cons->state > SI_ST_INI && s->req->cons->state < SI_ST_CLO))) {
1929
1930 if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED))
1931 session_process_counters(s);
1932
Willy Tarreau1accfc02009-09-05 20:57:35 +02001933 if (s->rep->cons->state == SI_ST_EST && !s->rep->cons->iohandler)
Willy Tarreaudc85b392009-08-18 07:38:19 +02001934 s->rep->cons->update(s->rep->cons);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001935
Willy Tarreau1accfc02009-09-05 20:57:35 +02001936 if (s->req->cons->state == SI_ST_EST && !s->req->cons->iohandler)
Willy Tarreaudc85b392009-08-18 07:38:19 +02001937 s->req->cons->update(s->req->cons);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001938
Willy Tarreaua6eebb32010-06-04 11:40:20 +02001939 s->req->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_READ_ATTACHED);
1940 s->rep->flags &= ~(BF_READ_NULL|BF_READ_PARTIAL|BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_READ_ATTACHED);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001941 s->si[0].prev_state = s->si[0].state;
1942 s->si[1].prev_state = s->si[1].state;
Willy Tarreaub0ef7352008-12-14 13:26:20 +01001943 s->si[0].flags &= ~(SI_FL_ERR|SI_FL_EXP);
1944 s->si[1].flags &= ~(SI_FL_ERR|SI_FL_EXP);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001945
1946 /* Trick: if a request is being waiting for the server to respond,
1947 * and if we know the server can timeout, we don't want the timeout
1948 * to expire on the client side first, but we're still interested
1949 * in passing data from the client to the server (eg: POST). Thus,
1950 * we can cancel the client's request timeout if the server's
1951 * request timeout is set and the server has not yet sent a response.
1952 */
1953
Willy Tarreau520d95e2009-09-19 21:04:57 +02001954 if ((s->rep->flags & (BF_AUTO_CLOSE|BF_SHUTR)) == 0 &&
Willy Tarreau86491c32008-12-14 09:04:47 +01001955 (tick_isset(s->req->wex) || tick_isset(s->rep->rex))) {
1956 s->req->flags |= BF_READ_NOEXP;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001957 s->req->rex = TICK_ETERNITY;
Willy Tarreau86491c32008-12-14 09:04:47 +01001958 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001959
Willy Tarreau7a20aa62010-07-13 16:30:45 +02001960 /* Call the stream interfaces' I/O handlers when embedded.
Willy Tarreau1accfc02009-09-05 20:57:35 +02001961 * Note that this one may wake the task up again.
1962 */
Willy Tarreau7a20aa62010-07-13 16:30:45 +02001963 if (s->req->cons->iohandler || s->rep->cons->iohandler) {
1964 if (s->req->cons->iohandler)
1965 s->req->cons->iohandler(s->req->cons);
1966 if (s->rep->cons->iohandler)
1967 s->rep->cons->iohandler(s->rep->cons);
Willy Tarreau1accfc02009-09-05 20:57:35 +02001968 if (task_in_rq(t)) {
1969 /* If we woke up, we don't want to requeue the
1970 * task to the wait queue, but rather requeue
1971 * it into the runqueue ASAP.
1972 */
1973 t->expire = TICK_ETERNITY;
1974 return t;
1975 }
1976 }
1977
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001978 t->expire = tick_first(tick_first(s->req->rex, s->req->wex),
1979 tick_first(s->rep->rex, s->rep->wex));
1980 if (s->req->analysers)
1981 t->expire = tick_first(t->expire, s->req->analyse_exp);
1982
1983 if (s->si[0].exp)
1984 t->expire = tick_first(t->expire, s->si[0].exp);
1985
1986 if (s->si[1].exp)
1987 t->expire = tick_first(t->expire, s->si[1].exp);
1988
1989#ifdef DEBUG_FULL
Willy Tarreau127334e2009-03-28 10:47:26 +01001990 fprintf(stderr,
1991 "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u"
1992 " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n",
1993 now_ms, t->expire, s->req->rex, s->req->wex, s->req->analyse_exp,
1994 s->rep->rex, s->rep->wex, s->si[0].exp, s->si[1].exp, s->si[0].state, s->si[1].state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001995#endif
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001996
1997#ifdef DEBUG_DEV
1998 /* this may only happen when no timeout is set or in case of an FSM bug */
Willy Tarreaud0a201b2009-03-08 15:53:06 +01001999 if (!tick_isset(t->expire))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002000 ABORT_NOW();
2001#endif
Willy Tarreau26c25062009-03-08 09:38:41 +01002002 return t; /* nothing more to do */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002003 }
2004
2005 s->fe->feconn--;
2006 if (s->flags & SN_BE_ASSIGNED)
2007 s->be->beconn--;
2008 actconn--;
Willy Tarreauaf7ad002010-08-31 15:39:26 +02002009 jobs--;
Willy Tarreau6e6fb2b2009-08-16 18:20:44 +02002010 s->listener->nbconn--;
2011 if (s->listener->state == LI_FULL &&
2012 s->listener->nbconn < s->listener->maxconn) {
2013 /* we should reactivate the listener */
2014 EV_FD_SET(s->listener->fd, DIR_RD);
2015 s->listener->state = LI_READY;
2016 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002017
2018 if (unlikely((global.mode & MODE_DEBUG) &&
2019 (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
2020 int len;
Willy Tarreauec22b2c2009-03-06 13:07:40 +01002021 len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002022 s->uniq_id, s->be->id,
Willy Tarreauec22b2c2009-03-06 13:07:40 +01002023 (unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002024 write(1, trash, len);
2025 }
2026
2027 s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
2028 session_process_counters(s);
2029
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002030 if (s->txn.status) {
2031 int n;
2032
2033 n = s->txn.status / 100;
2034 if (n < 1 || n > 5)
2035 n = 0;
2036
2037 if (s->fe->mode == PR_MODE_HTTP)
Willy Tarreau24657792010-02-26 10:30:28 +01002038 s->fe->counters.fe.http.rsp[n]++;
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002039
Willy Tarreau24657792010-02-26 10:30:28 +01002040 if ((s->flags & SN_BE_ASSIGNED) &&
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002041 (s->be->mode == PR_MODE_HTTP))
Willy Tarreau24657792010-02-26 10:30:28 +01002042 s->be->counters.be.http.rsp[n]++;
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002043 }
2044
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002045 /* let's do a final log if we need it */
2046 if (s->logs.logwait &&
2047 !(s->flags & SN_MONITOR) &&
2048 (!(s->fe->options & PR_O_NULLNOLOG) || s->req->total)) {
Willy Tarreaua5555ec2008-11-30 19:02:32 +01002049 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002050 }
2051
2052 /* the task MUST not be in the run queue anymore */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002053 session_free(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01002054 task_delete(t);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002055 task_free(t);
Willy Tarreau26c25062009-03-08 09:38:41 +01002056 return NULL;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002057}
2058
Willy Tarreau7c669d72008-06-20 15:04:11 +02002059/*
2060 * This function adjusts sess->srv_conn and maintains the previous and new
2061 * server's served session counts. Setting newsrv to NULL is enough to release
2062 * current connection slot. This function also notifies any LB algo which might
2063 * expect to be informed about any change in the number of active sessions on a
2064 * server.
2065 */
2066void sess_change_server(struct session *sess, struct server *newsrv)
2067{
2068 if (sess->srv_conn == newsrv)
2069 return;
2070
2071 if (sess->srv_conn) {
2072 sess->srv_conn->served--;
2073 if (sess->srv_conn->proxy->lbprm.server_drop_conn)
2074 sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
2075 sess->srv_conn = NULL;
2076 }
2077
2078 if (newsrv) {
2079 newsrv->served++;
2080 if (newsrv->proxy->lbprm.server_take_conn)
2081 newsrv->proxy->lbprm.server_take_conn(newsrv);
2082 sess->srv_conn = newsrv;
2083 }
2084}
2085
Willy Tarreau84455332009-03-15 22:34:05 +01002086/* Set correct session termination flags in case no analyser has done it. It
2087 * also counts a failed request if the server state has not reached the request
2088 * stage.
2089 */
2090void sess_set_term_flags(struct session *s)
2091{
2092 if (!(s->flags & SN_FINST_MASK)) {
2093 if (s->si[1].state < SI_ST_REQ) {
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002094
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02002095 s->fe->counters.failed_req++;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02002096 if (s->listener->counters)
2097 s->listener->counters->failed_req++;
2098
Willy Tarreau84455332009-03-15 22:34:05 +01002099 s->flags |= SN_FINST_R;
2100 }
2101 else if (s->si[1].state == SI_ST_QUE)
2102 s->flags |= SN_FINST_Q;
2103 else if (s->si[1].state < SI_ST_EST)
2104 s->flags |= SN_FINST_C;
Willy Tarreau033b2db2010-03-04 17:54:21 +01002105 else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST)
Willy Tarreau84455332009-03-15 22:34:05 +01002106 s->flags |= SN_FINST_D;
2107 else
2108 s->flags |= SN_FINST_L;
2109 }
2110}
2111
2112/* Handle server-side errors for default protocols. It is called whenever a a
2113 * connection setup is aborted or a request is aborted in queue. It sets the
2114 * session termination flags so that the caller does not have to worry about
2115 * them. It's installed as ->srv_error for the server-side stream_interface.
2116 */
2117void default_srv_error(struct session *s, struct stream_interface *si)
2118{
2119 int err_type = si->err_type;
2120 int err = 0, fin = 0;
2121
2122 if (err_type & SI_ET_QUEUE_ABRT) {
2123 err = SN_ERR_CLICL;
2124 fin = SN_FINST_Q;
2125 }
2126 else if (err_type & SI_ET_CONN_ABRT) {
2127 err = SN_ERR_CLICL;
2128 fin = SN_FINST_C;
2129 }
2130 else if (err_type & SI_ET_QUEUE_TO) {
2131 err = SN_ERR_SRVTO;
2132 fin = SN_FINST_Q;
2133 }
2134 else if (err_type & SI_ET_QUEUE_ERR) {
2135 err = SN_ERR_SRVCL;
2136 fin = SN_FINST_Q;
2137 }
2138 else if (err_type & SI_ET_CONN_TO) {
2139 err = SN_ERR_SRVTO;
2140 fin = SN_FINST_C;
2141 }
2142 else if (err_type & SI_ET_CONN_ERR) {
2143 err = SN_ERR_SRVCL;
2144 fin = SN_FINST_C;
2145 }
2146 else /* SI_ET_CONN_OTHER and others */ {
2147 err = SN_ERR_INTERNAL;
2148 fin = SN_FINST_C;
2149 }
2150
2151 if (!(s->flags & SN_ERR_MASK))
2152 s->flags |= err;
2153 if (!(s->flags & SN_FINST_MASK))
2154 s->flags |= fin;
2155}
Willy Tarreau7c669d72008-06-20 15:04:11 +02002156
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02002157
Willy Tarreau8b22a712010-06-18 17:46:06 +02002158/************************************************************************/
2159/* All supported ACL keywords must be declared here. */
2160/************************************************************************/
2161
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002162/* set test->i to the General Purpose Counter 0 value in the stksess entry <ts> */
2163static int
2164acl_fetch_get_gpc0(struct stktable *table, struct acl_test *test, struct stksess *ts)
2165{
2166 test->flags = ACL_TEST_F_VOL_TEST;
2167 test->i = 0;
2168 if (ts != NULL) {
2169 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0);
2170 if (!ptr)
2171 return 0; /* parameter not stored */
2172 test->i = stktable_data_cast(ptr, gpc0);
2173 }
2174 return 1;
2175}
2176
2177/* set test->i to the General Purpose Counter 0 value from the session's tracked
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002178 * frontend counters.
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002179 */
2180static int
Willy Tarreau56123282010-08-06 19:06:56 +02002181acl_fetch_sc1_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2182 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002183{
Willy Tarreau56123282010-08-06 19:06:56 +02002184 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002185 return 0;
Willy Tarreau56123282010-08-06 19:06:56 +02002186 return acl_fetch_get_gpc0(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002187}
2188
2189/* set test->i to the General Purpose Counter 0 value from the session's tracked
2190 * backend counters.
2191 */
2192static int
Willy Tarreau56123282010-08-06 19:06:56 +02002193acl_fetch_sc2_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2194 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002195{
Willy Tarreau56123282010-08-06 19:06:56 +02002196 if (!l4->stkctr2_entry)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002197 return 0;
Willy Tarreau56123282010-08-06 19:06:56 +02002198 return acl_fetch_get_gpc0(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002199}
2200
2201/* set test->i to the General Purpose Counter 0 value from the session's source
2202 * address in the table pointed to by expr.
2203 */
2204static int
2205acl_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2206 struct acl_expr *expr, struct acl_test *test)
2207{
2208 struct stktable_key *key;
2209
2210 key = tcpv4_src_to_stktable_key(l4);
2211 if (!key)
2212 return 0; /* only TCPv4 is supported right now */
2213
2214 if (expr->arg_len)
2215 px = find_stktable(expr->arg.str);
2216
2217 if (!px)
2218 return 0; /* table not found */
2219
2220 return acl_fetch_get_gpc0(&px->table, test, stktable_lookup_key(&px->table, key));
2221}
2222
2223/* Increment the General Purpose Counter 0 value in the stksess entry <ts> and
2224 * return it into test->i.
2225 */
2226static int
2227acl_fetch_inc_gpc0(struct stktable *table, struct acl_test *test, struct stksess *ts)
2228{
2229 test->flags = ACL_TEST_F_VOL_TEST;
2230 test->i = 0;
2231 if (ts != NULL) {
2232 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0);
2233 if (!ptr)
2234 return 0; /* parameter not stored */
2235 test->i = ++stktable_data_cast(ptr, gpc0);
2236 }
2237 return 1;
2238}
2239
2240/* Increment the General Purpose Counter 0 value from the session's tracked
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002241 * frontend counters and return it into test->i.
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002242 */
2243static int
Willy Tarreau56123282010-08-06 19:06:56 +02002244acl_fetch_sc1_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2245 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002246{
Willy Tarreau56123282010-08-06 19:06:56 +02002247 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002248 return 0;
Willy Tarreau56123282010-08-06 19:06:56 +02002249 return acl_fetch_inc_gpc0(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002250}
2251
2252/* Increment the General Purpose Counter 0 value from the session's tracked
2253 * backend counters and return it into test->i.
2254 */
2255static int
Willy Tarreau56123282010-08-06 19:06:56 +02002256acl_fetch_sc2_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2257 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002258{
Willy Tarreau56123282010-08-06 19:06:56 +02002259 if (!l4->stkctr2_entry)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002260 return 0;
Willy Tarreau56123282010-08-06 19:06:56 +02002261 return acl_fetch_inc_gpc0(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002262}
2263
2264/* Increment the General Purpose Counter 0 value from the session's source
2265 * address in the table pointed to by expr, and return it into test->i.
2266 */
2267static int
2268acl_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, int dir,
2269 struct acl_expr *expr, struct acl_test *test)
2270{
2271 struct stktable_key *key;
2272
2273 key = tcpv4_src_to_stktable_key(l4);
2274 if (!key)
2275 return 0; /* only TCPv4 is supported right now */
2276
2277 if (expr->arg_len)
2278 px = find_stktable(expr->arg.str);
2279
2280 if (!px)
2281 return 0; /* table not found */
2282
2283 return acl_fetch_inc_gpc0(&px->table, test, stktable_update_key(&px->table, key));
2284}
2285
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002286/* set test->i to the cumulated number of connections in the stksess entry <ts> */
2287static int
2288acl_fetch_conn_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
2289{
2290 test->flags = ACL_TEST_F_VOL_TEST;
2291 test->i = 0;
2292 if (ts != NULL) {
2293 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CNT);
2294 if (!ptr)
2295 return 0; /* parameter not stored */
2296 test->i = stktable_data_cast(ptr, conn_cnt);
2297 }
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002298 return 1;
2299}
2300
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002301/* set test->i to the cumulated number of connections from the session's tracked FE counters */
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002302static int
Willy Tarreau56123282010-08-06 19:06:56 +02002303acl_fetch_sc1_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2304 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002305{
Willy Tarreau56123282010-08-06 19:06:56 +02002306 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002307 return 0;
2308
Willy Tarreau56123282010-08-06 19:06:56 +02002309 return acl_fetch_conn_cnt(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002310}
2311
2312/* set test->i to the cumulated number of connections from the session's tracked BE counters */
2313static int
Willy Tarreau56123282010-08-06 19:06:56 +02002314acl_fetch_sc2_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2315 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002316{
Willy Tarreau56123282010-08-06 19:06:56 +02002317 if (!l4->stkctr2_entry)
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002318 return 0;
2319
Willy Tarreau56123282010-08-06 19:06:56 +02002320 return acl_fetch_conn_cnt(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002321}
2322
2323/* set test->i to the cumulated number of connections from the session's source
2324 * address in the table pointed to by expr.
Willy Tarreau8b22a712010-06-18 17:46:06 +02002325 */
2326static int
2327acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2328 struct acl_expr *expr, struct acl_test *test)
2329{
Willy Tarreau8b22a712010-06-18 17:46:06 +02002330 struct stktable_key *key;
2331
2332 key = tcpv4_src_to_stktable_key(l4);
2333 if (!key)
2334 return 0; /* only TCPv4 is supported right now */
2335
2336 if (expr->arg_len)
2337 px = find_stktable(expr->arg.str);
2338
2339 if (!px)
2340 return 0; /* table not found */
2341
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002342 return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
Willy Tarreau8b22a712010-06-18 17:46:06 +02002343}
2344
Willy Tarreau91c43d72010-06-20 11:19:22 +02002345/* set test->i to the connection rate in the stksess entry <ts> over the configured period */
2346static int
2347acl_fetch_conn_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
2348{
2349 test->flags = ACL_TEST_F_VOL_TEST;
2350 test->i = 0;
2351 if (ts != NULL) {
2352 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_RATE);
2353 if (!ptr)
2354 return 0; /* parameter not stored */
2355 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
2356 table->data_arg[STKTABLE_DT_CONN_RATE].u);
2357 }
2358 return 1;
2359}
2360
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002361/* set test->i to the connection rate from the session's tracked FE counters over
Willy Tarreau91c43d72010-06-20 11:19:22 +02002362 * the configured period.
2363 */
2364static int
Willy Tarreau56123282010-08-06 19:06:56 +02002365acl_fetch_sc1_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2366 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002367{
Willy Tarreau56123282010-08-06 19:06:56 +02002368 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002369 return 0;
2370
Willy Tarreau56123282010-08-06 19:06:56 +02002371 return acl_fetch_conn_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002372}
2373
2374/* set test->i to the connection rate from the session's tracked BE counters over
2375 * the configured period.
2376 */
2377static int
Willy Tarreau56123282010-08-06 19:06:56 +02002378acl_fetch_sc2_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2379 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002380{
Willy Tarreau56123282010-08-06 19:06:56 +02002381 if (!l4->stkctr2_entry)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002382 return 0;
2383
Willy Tarreau56123282010-08-06 19:06:56 +02002384 return acl_fetch_conn_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002385}
2386
2387/* set test->i to the connection rate from the session's source address in the
2388 * table pointed to by expr, over the configured period.
2389 */
2390static int
2391acl_fetch_src_conn_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2392 struct acl_expr *expr, struct acl_test *test)
2393{
2394 struct stktable_key *key;
2395
2396 key = tcpv4_src_to_stktable_key(l4);
2397 if (!key)
2398 return 0; /* only TCPv4 is supported right now */
2399
2400 if (expr->arg_len)
2401 px = find_stktable(expr->arg.str);
2402
2403 if (!px)
2404 return 0; /* table not found */
2405
2406 return acl_fetch_conn_rate(&px->table, test, stktable_lookup_key(&px->table, key));
2407}
2408
Willy Tarreau8b22a712010-06-18 17:46:06 +02002409/* set test->i to the number of connections from the session's source address
2410 * in the table pointed to by expr, after updating it.
2411 */
2412static int
2413acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2414 struct acl_expr *expr, struct acl_test *test)
2415{
2416 struct stksess *ts;
2417 struct stktable_key *key;
2418 void *ptr;
2419
2420 key = tcpv4_src_to_stktable_key(l4);
2421 if (!key)
2422 return 0; /* only TCPv4 is supported right now */
2423
2424 if (expr->arg_len)
2425 px = find_stktable(expr->arg.str);
2426
2427 if (!px)
2428 return 0; /* table not found */
2429
Willy Tarreau1f7e9252010-06-20 12:27:21 +02002430 if ((ts = stktable_update_key(&px->table, key)) == NULL)
2431 /* entry does not exist and could not be created */
2432 return 0;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002433
2434 ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
2435 if (!ptr)
2436 return 0; /* parameter not stored in this table */
2437
2438 test->i = ++stktable_data_cast(ptr, conn_cnt);
2439 test->flags = ACL_TEST_F_VOL_TEST;
2440 return 1;
2441}
2442
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002443/* set test->i to the number of concurrent connections in the stksess entry <ts> */
2444static int
2445acl_fetch_conn_cur(struct stktable *table, struct acl_test *test, struct stksess *ts)
2446{
2447 test->flags = ACL_TEST_F_VOL_TEST;
2448 test->i = 0;
2449
2450 if (ts != NULL) {
2451 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CUR);
2452 if (!ptr)
2453 return 0; /* parameter not stored */
2454 test->i = stktable_data_cast(ptr, conn_cur);
2455 }
2456 return 1;
2457}
2458
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002459/* set test->i to the number of concurrent connections from the session's tracked FE counters */
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002460static int
Willy Tarreau56123282010-08-06 19:06:56 +02002461acl_fetch_sc1_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
2462 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002463{
Willy Tarreau56123282010-08-06 19:06:56 +02002464 if (!l4->stkctr1_entry)
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002465 return 0;
2466
Willy Tarreau56123282010-08-06 19:06:56 +02002467 return acl_fetch_conn_cur(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002468}
2469
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002470/* set test->i to the number of concurrent connections from the session's tracked BE counters */
2471static int
Willy Tarreau56123282010-08-06 19:06:56 +02002472acl_fetch_sc2_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
2473 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002474{
Willy Tarreau56123282010-08-06 19:06:56 +02002475 if (!l4->stkctr2_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002476 return 0;
2477
Willy Tarreau56123282010-08-06 19:06:56 +02002478 return acl_fetch_conn_cur(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002479}
2480
Willy Tarreau38285c12010-06-18 16:35:43 +02002481/* set test->i to the number of concurrent connections from the session's source
2482 * address in the table pointed to by expr.
2483 */
2484static int
2485acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir,
2486 struct acl_expr *expr, struct acl_test *test)
2487{
Willy Tarreau38285c12010-06-18 16:35:43 +02002488 struct stktable_key *key;
2489
2490 key = tcpv4_src_to_stktable_key(l4);
2491 if (!key)
2492 return 0; /* only TCPv4 is supported right now */
2493
2494 if (expr->arg_len)
2495 px = find_stktable(expr->arg.str);
2496
2497 if (!px)
2498 return 0; /* table not found */
2499
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002500 return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
Willy Tarreau38285c12010-06-18 16:35:43 +02002501}
2502
Willy Tarreauf4d17d92010-06-18 22:10:12 +02002503/* set test->i to the cumulated number of sessions in the stksess entry <ts> */
2504static int
2505acl_fetch_sess_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
2506{
2507 test->flags = ACL_TEST_F_VOL_TEST;
2508 test->i = 0;
2509 if (ts != NULL) {
2510 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_CNT);
2511 if (!ptr)
2512 return 0; /* parameter not stored */
2513 test->i = stktable_data_cast(ptr, sess_cnt);
2514 }
2515 return 1;
2516}
2517
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002518/* set test->i to the cumulated number of sessions from the session's tracked FE counters */
Willy Tarreauf4d17d92010-06-18 22:10:12 +02002519static int
Willy Tarreau56123282010-08-06 19:06:56 +02002520acl_fetch_sc1_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2521 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002522{
Willy Tarreau56123282010-08-06 19:06:56 +02002523 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002524 return 0;
2525
Willy Tarreau56123282010-08-06 19:06:56 +02002526 return acl_fetch_sess_cnt(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002527}
2528
2529/* set test->i to the cumulated number of sessions from the session's tracked BE counters */
2530static int
Willy Tarreau56123282010-08-06 19:06:56 +02002531acl_fetch_sc2_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2532 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf4d17d92010-06-18 22:10:12 +02002533{
Willy Tarreau56123282010-08-06 19:06:56 +02002534 if (!l4->stkctr2_entry)
Willy Tarreauf4d17d92010-06-18 22:10:12 +02002535 return 0;
2536
Willy Tarreau56123282010-08-06 19:06:56 +02002537 return acl_fetch_sess_cnt(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauf4d17d92010-06-18 22:10:12 +02002538}
2539
2540/* set test->i to the cumulated number of session from the session's source
2541 * address in the table pointed to by expr.
2542 */
2543static int
2544acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2545 struct acl_expr *expr, struct acl_test *test)
2546{
2547 struct stktable_key *key;
2548
2549 key = tcpv4_src_to_stktable_key(l4);
2550 if (!key)
2551 return 0; /* only TCPv4 is supported right now */
2552
2553 if (expr->arg_len)
2554 px = find_stktable(expr->arg.str);
2555
2556 if (!px)
2557 return 0; /* table not found */
2558
2559 return acl_fetch_sess_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
2560}
2561
Willy Tarreau91c43d72010-06-20 11:19:22 +02002562/* set test->i to the session rate in the stksess entry <ts> over the configured period */
2563static int
2564acl_fetch_sess_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
2565{
2566 test->flags = ACL_TEST_F_VOL_TEST;
2567 test->i = 0;
2568 if (ts != NULL) {
2569 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_RATE);
2570 if (!ptr)
2571 return 0; /* parameter not stored */
2572 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
2573 table->data_arg[STKTABLE_DT_SESS_RATE].u);
2574 }
2575 return 1;
2576}
2577
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002578/* set test->i to the session rate from the session's tracked FE counters over
2579 * the configured period.
2580 */
2581static int
Willy Tarreau56123282010-08-06 19:06:56 +02002582acl_fetch_sc1_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2583 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002584{
Willy Tarreau56123282010-08-06 19:06:56 +02002585 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002586 return 0;
2587
Willy Tarreau56123282010-08-06 19:06:56 +02002588 return acl_fetch_sess_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002589}
2590
2591/* set test->i to the session rate from the session's tracked BE counters over
Willy Tarreau91c43d72010-06-20 11:19:22 +02002592 * the configured period.
2593 */
2594static int
Willy Tarreau56123282010-08-06 19:06:56 +02002595acl_fetch_sc2_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2596 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002597{
Willy Tarreau56123282010-08-06 19:06:56 +02002598 if (!l4->stkctr2_entry)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002599 return 0;
2600
Willy Tarreau56123282010-08-06 19:06:56 +02002601 return acl_fetch_sess_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002602}
2603
2604/* set test->i to the session rate from the session's source address in the
2605 * table pointed to by expr, over the configured period.
2606 */
2607static int
2608acl_fetch_src_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2609 struct acl_expr *expr, struct acl_test *test)
2610{
2611 struct stktable_key *key;
2612
2613 key = tcpv4_src_to_stktable_key(l4);
2614 if (!key)
2615 return 0; /* only TCPv4 is supported right now */
2616
2617 if (expr->arg_len)
2618 px = find_stktable(expr->arg.str);
2619
2620 if (!px)
2621 return 0; /* table not found */
2622
2623 return acl_fetch_sess_rate(&px->table, test, stktable_lookup_key(&px->table, key));
2624}
2625
Willy Tarreauda7ff642010-06-23 11:44:09 +02002626/* set test->i to the cumulated number of sessions in the stksess entry <ts> */
2627static int
2628acl_fetch_http_req_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
2629{
2630 test->flags = ACL_TEST_F_VOL_TEST;
2631 test->i = 0;
2632 if (ts != NULL) {
2633 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_CNT);
2634 if (!ptr)
2635 return 0; /* parameter not stored */
2636 test->i = stktable_data_cast(ptr, http_req_cnt);
2637 }
2638 return 1;
2639}
2640
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002641/* set test->i to the cumulated number of sessions from the session's tracked FE counters */
Willy Tarreauda7ff642010-06-23 11:44:09 +02002642static int
Willy Tarreau56123282010-08-06 19:06:56 +02002643acl_fetch_sc1_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2644 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002645{
Willy Tarreau56123282010-08-06 19:06:56 +02002646 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002647 return 0;
2648
Willy Tarreau56123282010-08-06 19:06:56 +02002649 return acl_fetch_http_req_cnt(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002650}
2651
2652/* set test->i to the cumulated number of sessions from the session's tracked BE counters */
2653static int
Willy Tarreau56123282010-08-06 19:06:56 +02002654acl_fetch_sc2_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2655 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002656{
Willy Tarreau56123282010-08-06 19:06:56 +02002657 if (!l4->stkctr2_entry)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002658 return 0;
2659
Willy Tarreau56123282010-08-06 19:06:56 +02002660 return acl_fetch_http_req_cnt(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauda7ff642010-06-23 11:44:09 +02002661}
2662
2663/* set test->i to the cumulated number of session from the session's source
2664 * address in the table pointed to by expr.
2665 */
2666static int
2667acl_fetch_src_http_req_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
Willy Tarreau56123282010-08-06 19:06:56 +02002668 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002669{
2670 struct stktable_key *key;
2671
2672 key = tcpv4_src_to_stktable_key(l4);
2673 if (!key)
2674 return 0; /* only TCPv4 is supported right now */
2675
2676 if (expr->arg_len)
2677 px = find_stktable(expr->arg.str);
2678
2679 if (!px)
2680 return 0; /* table not found */
2681
2682 return acl_fetch_http_req_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
2683}
2684
2685/* set test->i to the session rate in the stksess entry <ts> over the configured period */
2686static int
2687acl_fetch_http_req_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
2688{
2689 test->flags = ACL_TEST_F_VOL_TEST;
2690 test->i = 0;
2691 if (ts != NULL) {
2692 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_RATE);
2693 if (!ptr)
2694 return 0; /* parameter not stored */
2695 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
2696 table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
2697 }
2698 return 1;
2699}
2700
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002701/* set test->i to the session rate from the session's tracked FE counters over
Willy Tarreauda7ff642010-06-23 11:44:09 +02002702 * the configured period.
2703 */
2704static int
Willy Tarreau56123282010-08-06 19:06:56 +02002705acl_fetch_sc1_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2706 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002707{
Willy Tarreau56123282010-08-06 19:06:56 +02002708 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002709 return 0;
2710
Willy Tarreau56123282010-08-06 19:06:56 +02002711 return acl_fetch_http_req_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002712}
2713
2714/* set test->i to the session rate from the session's tracked BE counters over
2715 * the configured period.
2716 */
2717static int
Willy Tarreau56123282010-08-06 19:06:56 +02002718acl_fetch_sc2_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2719 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002720{
Willy Tarreau56123282010-08-06 19:06:56 +02002721 if (!l4->stkctr2_entry)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002722 return 0;
2723
Willy Tarreau56123282010-08-06 19:06:56 +02002724 return acl_fetch_http_req_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauda7ff642010-06-23 11:44:09 +02002725}
2726
2727/* set test->i to the session rate from the session's source address in the
2728 * table pointed to by expr, over the configured period.
2729 */
2730static int
2731acl_fetch_src_http_req_rate(struct proxy *px, struct session *l4, void *l7, int dir,
Willy Tarreau56123282010-08-06 19:06:56 +02002732 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002733{
2734 struct stktable_key *key;
2735
2736 key = tcpv4_src_to_stktable_key(l4);
2737 if (!key)
2738 return 0; /* only TCPv4 is supported right now */
2739
2740 if (expr->arg_len)
2741 px = find_stktable(expr->arg.str);
2742
2743 if (!px)
2744 return 0; /* table not found */
2745
2746 return acl_fetch_http_req_rate(&px->table, test, stktable_lookup_key(&px->table, key));
2747}
2748
2749/* set test->i to the cumulated number of sessions in the stksess entry <ts> */
2750static int
2751acl_fetch_http_err_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
2752{
2753 test->flags = ACL_TEST_F_VOL_TEST;
2754 test->i = 0;
2755 if (ts != NULL) {
2756 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_CNT);
2757 if (!ptr)
2758 return 0; /* parameter not stored */
2759 test->i = stktable_data_cast(ptr, http_err_cnt);
2760 }
2761 return 1;
2762}
2763
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002764/* set test->i to the cumulated number of sessions from the session's tracked FE counters */
Willy Tarreauda7ff642010-06-23 11:44:09 +02002765static int
Willy Tarreau56123282010-08-06 19:06:56 +02002766acl_fetch_sc1_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2767 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002768{
Willy Tarreau56123282010-08-06 19:06:56 +02002769 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002770 return 0;
2771
Willy Tarreau56123282010-08-06 19:06:56 +02002772 return acl_fetch_http_err_cnt(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002773}
2774
2775/* set test->i to the cumulated number of sessions from the session's tracked BE counters */
2776static int
Willy Tarreau56123282010-08-06 19:06:56 +02002777acl_fetch_sc2_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
2778 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002779{
Willy Tarreau56123282010-08-06 19:06:56 +02002780 if (!l4->stkctr2_entry)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002781 return 0;
2782
Willy Tarreau56123282010-08-06 19:06:56 +02002783 return acl_fetch_http_err_cnt(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauda7ff642010-06-23 11:44:09 +02002784}
2785
2786/* set test->i to the cumulated number of session from the session's source
2787 * address in the table pointed to by expr.
2788 */
2789static int
2790acl_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
Willy Tarreau56123282010-08-06 19:06:56 +02002791 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002792{
2793 struct stktable_key *key;
2794
2795 key = tcpv4_src_to_stktable_key(l4);
2796 if (!key)
2797 return 0; /* only TCPv4 is supported right now */
2798
2799 if (expr->arg_len)
2800 px = find_stktable(expr->arg.str);
2801
2802 if (!px)
2803 return 0; /* table not found */
2804
2805 return acl_fetch_http_err_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
2806}
2807
2808/* set test->i to the session rate in the stksess entry <ts> over the configured period */
2809static int
2810acl_fetch_http_err_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
2811{
2812 test->flags = ACL_TEST_F_VOL_TEST;
2813 test->i = 0;
2814 if (ts != NULL) {
2815 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_RATE);
2816 if (!ptr)
2817 return 0; /* parameter not stored */
2818 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
2819 table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
2820 }
2821 return 1;
2822}
2823
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002824/* set test->i to the session rate from the session's tracked FE counters over
Willy Tarreauda7ff642010-06-23 11:44:09 +02002825 * the configured period.
2826 */
2827static int
Willy Tarreau56123282010-08-06 19:06:56 +02002828acl_fetch_sc1_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2829 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002830{
Willy Tarreau56123282010-08-06 19:06:56 +02002831 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002832 return 0;
2833
Willy Tarreau56123282010-08-06 19:06:56 +02002834 return acl_fetch_http_err_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002835}
2836
2837/* set test->i to the session rate from the session's tracked BE counters over
2838 * the configured period.
2839 */
2840static int
Willy Tarreau56123282010-08-06 19:06:56 +02002841acl_fetch_sc2_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2842 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002843{
Willy Tarreau56123282010-08-06 19:06:56 +02002844 if (!l4->stkctr2_entry)
Willy Tarreauda7ff642010-06-23 11:44:09 +02002845 return 0;
2846
Willy Tarreau56123282010-08-06 19:06:56 +02002847 return acl_fetch_http_err_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreauda7ff642010-06-23 11:44:09 +02002848}
2849
2850/* set test->i to the session rate from the session's source address in the
2851 * table pointed to by expr, over the configured period.
2852 */
2853static int
2854acl_fetch_src_http_err_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2855 struct acl_expr *expr, struct acl_test *test)
2856{
2857 struct stktable_key *key;
2858
2859 key = tcpv4_src_to_stktable_key(l4);
2860 if (!key)
2861 return 0; /* only TCPv4 is supported right now */
2862
2863 if (expr->arg_len)
2864 px = find_stktable(expr->arg.str);
2865
2866 if (!px)
2867 return 0; /* table not found */
2868
2869 return acl_fetch_http_err_rate(&px->table, test, stktable_lookup_key(&px->table, key));
2870}
2871
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002872/* set test->i to the number of kbytes received from clients matching the stksess entry <ts> */
2873static int
2874acl_fetch_kbytes_in(struct stktable *table, struct acl_test *test, struct stksess *ts)
2875{
2876 test->flags = ACL_TEST_F_VOL_TEST;
2877 test->i = 0;
2878
2879 if (ts != NULL) {
2880 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_CNT);
2881 if (!ptr)
2882 return 0; /* parameter not stored */
2883 test->i = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
2884 }
2885 return 1;
2886}
2887
2888/* set test->i to the number of kbytes received from clients according to the
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002889 * session's tracked FE counters.
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002890 */
2891static int
Willy Tarreau56123282010-08-06 19:06:56 +02002892acl_fetch_sc1_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
2893 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002894{
Willy Tarreau56123282010-08-06 19:06:56 +02002895 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002896 return 0;
2897
Willy Tarreau56123282010-08-06 19:06:56 +02002898 return acl_fetch_kbytes_in(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002899}
2900
2901/* set test->i to the number of kbytes received from clients according to the
2902 * session's tracked BE counters.
2903 */
2904static int
Willy Tarreau56123282010-08-06 19:06:56 +02002905acl_fetch_sc2_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
2906 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002907{
Willy Tarreau56123282010-08-06 19:06:56 +02002908 if (!l4->stkctr2_entry)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002909 return 0;
2910
Willy Tarreau56123282010-08-06 19:06:56 +02002911 return acl_fetch_kbytes_in(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002912}
2913
Willy Tarreau855e4bb2010-06-18 18:33:32 +02002914/* set test->i to the number of kbytes received from the session's source
2915 * address in the table pointed to by expr.
2916 */
2917static int
2918acl_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, int dir,
2919 struct acl_expr *expr, struct acl_test *test)
2920{
Willy Tarreau855e4bb2010-06-18 18:33:32 +02002921 struct stktable_key *key;
2922
2923 key = tcpv4_src_to_stktable_key(l4);
2924 if (!key)
2925 return 0; /* only TCPv4 is supported right now */
2926
2927 if (expr->arg_len)
2928 px = find_stktable(expr->arg.str);
2929
2930 if (!px)
2931 return 0; /* table not found */
2932
Willy Tarreau1aa006f2010-06-18 21:52:52 +02002933 return acl_fetch_kbytes_in(&px->table, test, stktable_lookup_key(&px->table, key));
2934}
2935
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002936/* set test->i to the bytes rate from clients in the stksess entry <ts> over the
2937 * configured period.
2938 */
2939static int
2940acl_fetch_bytes_in_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
2941{
2942 test->flags = ACL_TEST_F_VOL_TEST;
2943 test->i = 0;
2944 if (ts != NULL) {
2945 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_RATE);
2946 if (!ptr)
2947 return 0; /* parameter not stored */
2948 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
2949 table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
2950 }
2951 return 1;
2952}
2953
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002954/* set test->i to the bytes rate from clients from the session's tracked FE
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002955 * counters over the configured period.
2956 */
2957static int
Willy Tarreau56123282010-08-06 19:06:56 +02002958acl_fetch_sc1_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2959 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002960{
Willy Tarreau56123282010-08-06 19:06:56 +02002961 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002962 return 0;
2963
Willy Tarreau56123282010-08-06 19:06:56 +02002964 return acl_fetch_bytes_in_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02002965}
2966
2967/* set test->i to the bytes rate from clients from the session's tracked BE
2968 * counters over the configured period.
2969 */
2970static int
Willy Tarreau56123282010-08-06 19:06:56 +02002971acl_fetch_sc2_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
2972 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002973{
Willy Tarreau56123282010-08-06 19:06:56 +02002974 if (!l4->stkctr2_entry)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002975 return 0;
2976
Willy Tarreau56123282010-08-06 19:06:56 +02002977 return acl_fetch_bytes_in_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002978}
2979
2980/* set test->i to the bytes rate from clients from the session's source address
2981 * in the table pointed to by expr, over the configured period.
2982 */
2983static int
2984acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
Willy Tarreau56123282010-08-06 19:06:56 +02002985 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02002986{
2987 struct stktable_key *key;
2988
2989 key = tcpv4_src_to_stktable_key(l4);
2990 if (!key)
2991 return 0; /* only TCPv4 is supported right now */
2992
2993 if (expr->arg_len)
2994 px = find_stktable(expr->arg.str);
2995
2996 if (!px)
2997 return 0; /* table not found */
2998
2999 return acl_fetch_bytes_in_rate(&px->table, test, stktable_lookup_key(&px->table, key));
3000}
3001
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003002/* set test->i to the number of kbytes sent to clients matching the stksess entry <ts> */
3003static int
3004acl_fetch_kbytes_out(struct stktable *table, struct acl_test *test, struct stksess *ts)
3005{
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003006 test->flags = ACL_TEST_F_VOL_TEST;
3007 test->i = 0;
3008
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003009 if (ts != NULL) {
3010 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_CNT);
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003011 if (!ptr)
3012 return 0; /* parameter not stored */
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003013 test->i = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003014 }
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003015 return 1;
3016}
3017
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003018/* set test->i to the number of kbytes sent to clients according to the session's
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003019 * tracked FE counters.
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003020 */
3021static int
Willy Tarreau56123282010-08-06 19:06:56 +02003022acl_fetch_sc1_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
3023 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003024{
Willy Tarreau56123282010-08-06 19:06:56 +02003025 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003026 return 0;
3027
Willy Tarreau56123282010-08-06 19:06:56 +02003028 return acl_fetch_kbytes_out(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003029}
3030
3031/* set test->i to the number of kbytes sent to clients according to the session's
3032 * tracked BE counters.
3033 */
3034static int
Willy Tarreau56123282010-08-06 19:06:56 +02003035acl_fetch_sc2_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
3036 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003037{
Willy Tarreau56123282010-08-06 19:06:56 +02003038 if (!l4->stkctr2_entry)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003039 return 0;
3040
Willy Tarreau56123282010-08-06 19:06:56 +02003041 return acl_fetch_kbytes_out(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003042}
3043
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003044/* set test->i to the number of kbytes sent to the session's source address in
3045 * the table pointed to by expr.
3046 */
3047static int
3048acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir,
3049 struct acl_expr *expr, struct acl_test *test)
3050{
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003051 struct stktable_key *key;
3052
3053 key = tcpv4_src_to_stktable_key(l4);
3054 if (!key)
3055 return 0; /* only TCPv4 is supported right now */
3056
3057 if (expr->arg_len)
3058 px = find_stktable(expr->arg.str);
3059
3060 if (!px)
3061 return 0; /* table not found */
3062
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003063 return acl_fetch_kbytes_out(&px->table, test, stktable_lookup_key(&px->table, key));
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003064}
3065
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003066/* set test->i to the bytes rate to clients in the stksess entry <ts> over the
3067 * configured period.
3068 */
3069static int
3070acl_fetch_bytes_out_rate(struct stktable *table, struct acl_test *test, struct stksess *ts)
3071{
3072 test->flags = ACL_TEST_F_VOL_TEST;
3073 test->i = 0;
3074 if (ts != NULL) {
3075 void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_RATE);
3076 if (!ptr)
3077 return 0; /* parameter not stored */
3078 test->i = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
3079 table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
3080 }
3081 return 1;
3082}
3083
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003084/* set test->i to the bytes rate to clients from the session's tracked FE counters
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003085 * over the configured period.
3086 */
3087static int
Willy Tarreau56123282010-08-06 19:06:56 +02003088acl_fetch_sc1_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
3089 struct acl_expr *expr, struct acl_test *test)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003090{
Willy Tarreau56123282010-08-06 19:06:56 +02003091 if (!l4->stkctr1_entry)
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003092 return 0;
3093
Willy Tarreau56123282010-08-06 19:06:56 +02003094 return acl_fetch_bytes_out_rate(l4->stkctr1_table, test, l4->stkctr1_entry);
Willy Tarreauf059a0f2010-08-03 16:29:52 +02003095}
3096
3097/* set test->i to the bytes rate to clients from the session's tracked BE counters
3098 * over the configured period.
3099 */
3100static int
Willy Tarreau56123282010-08-06 19:06:56 +02003101acl_fetch_sc2_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
3102 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003103{
Willy Tarreau56123282010-08-06 19:06:56 +02003104 if (!l4->stkctr2_entry)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003105 return 0;
3106
Willy Tarreau56123282010-08-06 19:06:56 +02003107 return acl_fetch_bytes_out_rate(l4->stkctr2_table, test, l4->stkctr2_entry);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003108}
3109
3110/* set test->i to the bytes rate to client from the session's source address in
3111 * the table pointed to by expr, over the configured period.
3112 */
3113static int
3114acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
Willy Tarreau56123282010-08-06 19:06:56 +02003115 struct acl_expr *expr, struct acl_test *test)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003116{
3117 struct stktable_key *key;
3118
3119 key = tcpv4_src_to_stktable_key(l4);
3120 if (!key)
3121 return 0; /* only TCPv4 is supported right now */
3122
3123 if (expr->arg_len)
3124 px = find_stktable(expr->arg.str);
3125
3126 if (!px)
3127 return 0; /* table not found */
3128
3129 return acl_fetch_bytes_out_rate(&px->table, test, stktable_lookup_key(&px->table, key));
3130}
3131
Willy Tarreau8b22a712010-06-18 17:46:06 +02003132
3133/* Note: must not be declared <const> as its list will be overwritten */
3134static struct acl_kw_list acl_kws = {{ },{
Willy Tarreau56123282010-08-06 19:06:56 +02003135 { "sc1_get_gpc0", acl_parse_int, acl_fetch_sc1_get_gpc0, acl_match_int, ACL_USE_NOTHING },
3136 { "sc2_get_gpc0", acl_parse_int, acl_fetch_sc2_get_gpc0, acl_match_int, ACL_USE_NOTHING },
3137 { "src_get_gpc0", acl_parse_int, acl_fetch_src_get_gpc0, acl_match_int, ACL_USE_TCP4_VOLATILE },
3138 { "sc1_inc_gpc0", acl_parse_int, acl_fetch_sc1_inc_gpc0, acl_match_int, ACL_USE_NOTHING },
3139 { "sc2_inc_gpc0", acl_parse_int, acl_fetch_sc2_inc_gpc0, acl_match_int, ACL_USE_NOTHING },
3140 { "src_inc_gpc0", acl_parse_int, acl_fetch_src_inc_gpc0, acl_match_int, ACL_USE_TCP4_VOLATILE },
3141 { "sc1_conn_cnt", acl_parse_int, acl_fetch_sc1_conn_cnt, acl_match_int, ACL_USE_NOTHING },
3142 { "sc2_conn_cnt", acl_parse_int, acl_fetch_sc2_conn_cnt, acl_match_int, ACL_USE_NOTHING },
3143 { "src_conn_cnt", acl_parse_int, acl_fetch_src_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
3144 { "sc1_conn_rate", acl_parse_int, acl_fetch_sc1_conn_rate, acl_match_int, ACL_USE_NOTHING },
3145 { "sc2_conn_rate", acl_parse_int, acl_fetch_sc2_conn_rate, acl_match_int, ACL_USE_NOTHING },
3146 { "src_conn_rate", acl_parse_int, acl_fetch_src_conn_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
3147 { "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
3148 { "sc1_conn_cur", acl_parse_int, acl_fetch_sc1_conn_cur, acl_match_int, ACL_USE_NOTHING },
3149 { "sc2_conn_cur", acl_parse_int, acl_fetch_sc2_conn_cur, acl_match_int, ACL_USE_NOTHING },
3150 { "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE },
3151 { "sc1_sess_cnt", acl_parse_int, acl_fetch_sc1_sess_cnt, acl_match_int, ACL_USE_NOTHING },
3152 { "sc2_sess_cnt", acl_parse_int, acl_fetch_sc2_sess_cnt, acl_match_int, ACL_USE_NOTHING },
3153 { "src_sess_cnt", acl_parse_int, acl_fetch_src_sess_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
3154 { "sc1_sess_rate", acl_parse_int, acl_fetch_sc1_sess_rate, acl_match_int, ACL_USE_NOTHING },
3155 { "sc2_sess_rate", acl_parse_int, acl_fetch_sc2_sess_rate, acl_match_int, ACL_USE_NOTHING },
3156 { "src_sess_rate", acl_parse_int, acl_fetch_src_sess_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
3157 { "sc1_http_req_cnt", acl_parse_int, acl_fetch_sc1_http_req_cnt, acl_match_int, ACL_USE_NOTHING },
3158 { "sc2_http_req_cnt", acl_parse_int, acl_fetch_sc2_http_req_cnt, acl_match_int, ACL_USE_NOTHING },
3159 { "src_http_req_cnt", acl_parse_int, acl_fetch_src_http_req_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
3160 { "sc1_http_req_rate", acl_parse_int, acl_fetch_sc1_http_req_rate, acl_match_int, ACL_USE_NOTHING },
3161 { "sc2_http_req_rate", acl_parse_int, acl_fetch_sc2_http_req_rate, acl_match_int, ACL_USE_NOTHING },
3162 { "src_http_req_rate", acl_parse_int, acl_fetch_src_http_req_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
3163 { "sc1_http_err_cnt", acl_parse_int, acl_fetch_sc1_http_err_cnt, acl_match_int, ACL_USE_NOTHING },
3164 { "sc2_http_err_cnt", acl_parse_int, acl_fetch_sc2_http_err_cnt, acl_match_int, ACL_USE_NOTHING },
3165 { "src_http_err_cnt", acl_parse_int, acl_fetch_src_http_err_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
3166 { "sc1_http_err_rate", acl_parse_int, acl_fetch_sc1_http_err_rate, acl_match_int, ACL_USE_NOTHING },
3167 { "sc2_http_err_rate", acl_parse_int, acl_fetch_sc2_http_err_rate, acl_match_int, ACL_USE_NOTHING },
3168 { "src_http_err_rate", acl_parse_int, acl_fetch_src_http_err_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
3169 { "sc1_kbytes_in", acl_parse_int, acl_fetch_sc1_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
3170 { "sc2_kbytes_in", acl_parse_int, acl_fetch_sc2_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
3171 { "src_kbytes_in", acl_parse_int, acl_fetch_src_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE },
3172 { "sc1_bytes_in_rate", acl_parse_int, acl_fetch_sc1_bytes_in_rate, acl_match_int, ACL_USE_NOTHING },
3173 { "sc2_bytes_in_rate", acl_parse_int, acl_fetch_sc2_bytes_in_rate, acl_match_int, ACL_USE_NOTHING },
3174 { "src_bytes_in_rate", acl_parse_int, acl_fetch_src_bytes_in_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
3175 { "sc1_kbytes_out", acl_parse_int, acl_fetch_sc1_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },
3176 { "sc2_kbytes_out", acl_parse_int, acl_fetch_sc2_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },
3177 { "src_kbytes_out", acl_parse_int, acl_fetch_src_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },
3178 { "sc1_bytes_out_rate", acl_parse_int, acl_fetch_sc1_bytes_out_rate, acl_match_int, ACL_USE_NOTHING },
3179 { "sc2_bytes_out_rate", acl_parse_int, acl_fetch_sc2_bytes_out_rate, acl_match_int, ACL_USE_NOTHING },
3180 { "src_bytes_out_rate", acl_parse_int, acl_fetch_src_bytes_out_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
Willy Tarreau8b22a712010-06-18 17:46:06 +02003181 { NULL, NULL, NULL, NULL },
3182}};
3183
3184
Willy Tarreau56123282010-08-06 19:06:56 +02003185/* Parse a "track-sc[12]" line starting with "track-sc[12]" in args[arg-1].
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003186 * Returns the number of warnings emitted, or -1 in case of fatal errors. The
3187 * <prm> struct is fed with the table name if any. If unspecified, the caller
3188 * will assume that the current proxy's table is used.
3189 */
3190int parse_track_counters(char **args, int *arg,
3191 int section_type, struct proxy *curpx,
3192 struct track_ctr_prm *prm,
3193 struct proxy *defpx, char *err, int errlen)
3194{
3195 int pattern_type = 0;
Willy Tarreau56123282010-08-06 19:06:56 +02003196 char *kw = args[*arg - 1];
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003197
Willy Tarreau56123282010-08-06 19:06:56 +02003198 /* parse the arguments of "track-sc[12]" before the condition in the
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003199 * following form :
Willy Tarreau56123282010-08-06 19:06:56 +02003200 * track-sc[12] src [ table xxx ] [ if|unless ... ]
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003201 */
3202 while (args[*arg]) {
3203 if (strcmp(args[*arg], "src") == 0) {
3204 prm->type = STKTABLE_TYPE_IP;
3205 pattern_type = 1;
3206 }
3207 else if (strcmp(args[*arg], "table") == 0) {
3208 if (!args[*arg + 1]) {
3209 snprintf(err, errlen,
Willy Tarreau56123282010-08-06 19:06:56 +02003210 "missing table for %s in %s '%s'.",
3211 kw, proxy_type_str(curpx), curpx->id);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003212 return -1;
3213 }
3214 /* we copy the table name for now, it will be resolved later */
3215 prm->table.n = strdup(args[*arg + 1]);
3216 (*arg)++;
3217 }
3218 else {
3219 /* unhandled keywords are handled by the caller */
3220 break;
3221 }
3222 (*arg)++;
3223 }
3224
3225 if (!pattern_type) {
3226 snprintf(err, errlen,
Willy Tarreau56123282010-08-06 19:06:56 +02003227 "%s key not specified in %s '%s' (found %s, only 'src' is supported).",
3228 kw, proxy_type_str(curpx), curpx->id, quote_arg(args[*arg]));
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02003229 return -1;
3230 }
3231
3232 return 0;
3233}
3234
Willy Tarreau8b22a712010-06-18 17:46:06 +02003235__attribute__((constructor))
3236static void __session_init(void)
3237{
3238 acl_register_keywords(&acl_kws);
3239}
3240
Willy Tarreaubaaee002006-06-26 02:48:02 +02003241/*
3242 * Local variables:
3243 * c-indent-level: 8
3244 * c-basic-offset: 8
3245 * End:
3246 */