blob: 3eb5265db45bb07668c59837cf90391cfa45cd45 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau87b09662015-04-03 00:22:06 +02002 * Stream management functions.
Willy Tarreaubaaee002006-06-26 02:48:02 +02003 *
Willy Tarreaud28c3532012-04-19 19:28:33 +02004 * Copyright 2000-2012 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
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020017#include <common/cfgparse.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020018#include <common/config.h>
Willy Tarreau9b28e032012-10-12 23:49:43 +020019#include <common/buffer.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020020#include <common/debug.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020021#include <common/memory.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020022
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020023#include <types/applet.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020024#include <types/capture.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020025#include <types/filters.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010026#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020028#include <proto/acl.h>
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020029#include <proto/action.h>
Willy Tarreau61612d42012-04-19 18:42:05 +020030#include <proto/arg.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010031#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020032#include <proto/channel.h>
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010033#include <proto/checks.h>
Willy Tarreaud2274c62012-07-06 14:29:45 +020034#include <proto/connection.h>
Willy Tarreau5ca791d2009-08-16 19:06:42 +020035#include <proto/dumpstats.h>
Willy Tarreaudd2f85e2012-09-02 22:34:23 +020036#include <proto/fd.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020037#include <proto/filters.h>
Willy Tarreau91c43d72010-06-20 11:19:22 +020038#include <proto/freq_ctr.h>
Willy Tarreau3041b9f2010-10-15 23:25:20 +020039#include <proto/frontend.h>
Willy Tarreau8d5d7f22007-01-21 19:16:41 +010040#include <proto/hdr_idx.h>
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010041#include <proto/hlua.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020042#include <proto/listener.h>
Willy Tarreau332f8bf2007-05-13 21:36:56 +020043#include <proto/log.h>
Willy Tarreaucbaaec42012-09-06 11:32:07 +020044#include <proto/raw_sock.h>
Willy Tarreaufeb76402015-04-03 14:10:06 +020045#include <proto/session.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020046#include <proto/stream.h>
Willy Tarreau3eba98a2009-01-25 13:56:13 +010047#include <proto/pipe.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010048#include <proto/proto_http.h>
49#include <proto/proto_tcp.h>
Willy Tarreau1d0dfb12009-07-07 15:10:31 +020050#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020051#include <proto/queue.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010052#include <proto/server.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020053#include <proto/sample.h>
Emeric Brun1d33b292010-01-04 15:47:17 +010054#include <proto/stick_table.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010055#include <proto/stream_interface.h>
Willy Tarreau55a8d0e2008-11-30 18:47:21 +010056#include <proto/task.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020057#include <proto/vars.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020058
Willy Tarreau87b09662015-04-03 00:22:06 +020059struct pool_head *pool2_stream;
60struct list streams;
Willy Tarreaubaaee002006-06-26 02:48:02 +020061
Willy Tarreau87b09662015-04-03 00:22:06 +020062/* list of streams waiting for at least one buffer */
Willy Tarreaubf883e02014-11-25 21:10:35 +010063struct list buffer_wq = LIST_HEAD_INIT(buffer_wq);
64
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020065/* List of all use-service keywords. */
66static struct list service_keywords = LIST_HEAD_INIT(service_keywords);
67
Willy Tarreau9903f0e2015-04-04 18:50:31 +020068/* This function is called from the session handler which detects the end of
Willy Tarreau73b65ac2015-04-08 18:26:29 +020069 * handshake, in order to complete initialization of a valid stream. It must be
70 * called with a session (which may be embryonic). It returns the pointer to
71 * the newly created stream, or NULL in case of fatal error. The client-facing
72 * end point is assigned to <origin>, which must be valid. The task's context
73 * is set to the new stream, and its function is set to process_stream().
74 * Target and analysers are null.
Willy Tarreau2542b532012-08-31 16:01:23 +020075 */
Willy Tarreau73b65ac2015-04-08 18:26:29 +020076struct stream *stream_new(struct session *sess, struct task *t, enum obj_type *origin)
Willy Tarreau2542b532012-08-31 16:01:23 +020077{
Willy Tarreau02a0c0e2015-04-04 18:08:21 +020078 struct stream *s;
Willy Tarreau73b65ac2015-04-08 18:26:29 +020079 struct connection *conn = objt_conn(origin);
80 struct appctx *appctx = objt_appctx(origin);
Willy Tarreau2542b532012-08-31 16:01:23 +020081
Willy Tarreau02a0c0e2015-04-04 18:08:21 +020082 if (unlikely((s = pool_alloc2(pool2_stream)) == NULL))
Willy Tarreau02d86382015-04-05 12:00:52 +020083 return s;
Willy Tarreau02a0c0e2015-04-04 18:08:21 +020084
85 /* minimum stream initialization required for an embryonic stream is
86 * fairly low. We need very little to execute L4 ACLs, then we need a
87 * task to make the client-side connection live on its own.
88 * - flags
89 * - stick-entry tracking
90 */
91 s->flags = 0;
Willy Tarreaufb9f5842015-04-05 18:19:23 +020092 s->logs.logwait = sess->fe->to_log;
Willy Tarreau02a0c0e2015-04-04 18:08:21 +020093 s->logs.level = 0;
Willy Tarreau99eb0f12015-04-05 12:03:54 +020094 s->logs.accept_date = sess->accept_date; /* user-visible date for logging */
95 s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */
96 tv_zero(&s->logs.tv_request);
97 s->logs.t_queue = -1;
98 s->logs.t_connect = -1;
99 s->logs.t_data = -1;
100 s->logs.t_close = 0;
101 s->logs.bytes_in = s->logs.bytes_out = 0;
102 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
103 s->logs.srv_queue_size = 0; /* we will get this number soon */
104
105 /* default logging function */
106 s->do_log = strm_log;
107
108 /* default error reporting function, may be changed by analysers */
109 s->srv_error = default_srv_error;
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200110
111 /* Initialise the current rule list pointer to NULL. We are sure that
112 * any rulelist match the NULL pointer.
113 */
114 s->current_rule_list = NULL;
Remi Gacogne7fb9de22015-07-22 17:10:58 +0200115 s->current_rule = NULL;
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200116
Willy Tarreaua68f7622015-09-21 17:48:24 +0200117 /* Copy SC counters for the stream. We don't touch refcounts because
118 * any reference we have is inherited from the session. Since the stream
119 * doesn't exist without the session, the session's existence guarantees
120 * we don't lose the entry. During the store operation, the stream won't
121 * touch these ones.
Thierry FOURNIER827752e2015-08-18 11:34:18 +0200122 */
Thierry FOURNIERc8fdb982015-08-16 12:03:39 +0200123 memcpy(s->stkctr, sess->stkctr, sizeof(s->stkctr));
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200124
125 s->sess = sess;
126 s->si[0].flags = SI_FL_NONE;
127 s->si[1].flags = SI_FL_ISBACK;
128
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200129 s->uniq_id = global.req_count++;
130
Willy Tarreau87b09662015-04-03 00:22:06 +0200131 /* OK, we're keeping the stream, so let's properly initialize the stream */
132 LIST_ADDQ(&streams, &s->list);
Willy Tarreau2542b532012-08-31 16:01:23 +0200133 LIST_INIT(&s->back_refs);
Willy Tarreaubf883e02014-11-25 21:10:35 +0100134 LIST_INIT(&s->buffer_wait);
Willy Tarreauf8a49ea2013-10-14 21:32:07 +0200135
Willy Tarreaue7dff022015-04-03 01:14:29 +0200136 s->flags |= SF_INITIALIZED;
Willy Tarreau2542b532012-08-31 16:01:23 +0200137 s->unique_id = NULL;
Willy Tarreau2542b532012-08-31 16:01:23 +0200138
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200139 s->task = t;
Willy Tarreaud1769b82015-04-06 00:25:48 +0200140 t->process = process_stream;
Willy Tarreau2542b532012-08-31 16:01:23 +0200141 t->context = s;
142 t->expire = TICK_ETERNITY;
143
Willy Tarreau87b09662015-04-03 00:22:06 +0200144 /* Note: initially, the stream's backend points to the frontend.
Willy Tarreau2542b532012-08-31 16:01:23 +0200145 * This changes later when switching rules are executed or
146 * when the default backend is assigned.
147 */
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200148 s->be = sess->fe;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100149 s->req.buf = s->res.buf = NULL;
Willy Tarreaucb7dd012015-04-03 22:16:32 +0200150 s->req_cap = NULL;
151 s->res_cap = NULL;
Willy Tarreau2542b532012-08-31 16:01:23 +0200152
Willy Tarreauebcd4842015-06-19 11:59:02 +0200153 /* Initialise all the variables contexts even if not used.
154 * This permits to prune these contexts without errors.
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200155 */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200156 vars_init(&s->vars_txn, SCOPE_TXN);
157 vars_init(&s->vars_reqres, SCOPE_REQ);
158
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200159 /* this part should be common with other protocols */
Willy Tarreau819d3322014-11-28 12:12:34 +0100160 si_reset(&s->si[0]);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200161 si_set_state(&s->si[0], SI_ST_EST);
162
Willy Tarreau1f52bb22015-04-04 14:28:46 +0200163 /* attach the incoming connection to the stream interface now. */
Willy Tarreauf2b98742015-04-05 01:30:42 +0200164 if (conn)
165 si_attach_conn(&s->si[0], conn);
Willy Tarreau470280e2015-04-05 01:33:13 +0200166 else if (appctx)
167 si_attach_appctx(&s->si[0], appctx);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200168
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200169 if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200170 s->si[0].flags |= SI_FL_INDEP_STR;
171
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200172 /* pre-initialize the other side's stream interface to an INIT state. The
173 * callbacks will be initialized before attempting to connect.
174 */
Willy Tarreau819d3322014-11-28 12:12:34 +0100175 si_reset(&s->si[1]);
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200176
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200177 if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200178 s->si[1].flags |= SI_FL_INDEP_STR;
179
Willy Tarreau87b09662015-04-03 00:22:06 +0200180 stream_init_srv_conn(s);
Willy Tarreaud1769b82015-04-06 00:25:48 +0200181 s->target = NULL;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200182 s->pend_pos = NULL;
183
184 /* init store persistence */
185 s->store_count = 0;
186
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100187 channel_init(&s->req);
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100188 s->req.flags |= CF_READ_ATTACHED; /* the producer is already connected */
Willy Tarreaud1769b82015-04-06 00:25:48 +0200189 s->req.analysers = 0;
190 channel_auto_connect(&s->req); /* don't wait to establish connection */
191 channel_auto_close(&s->req); /* let the producer forward close requests */
Willy Tarreauc8815ef2015-04-05 18:15:59 +0200192
193 s->req.rto = sess->fe->timeout.client;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100194 s->req.wto = TICK_ETERNITY;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100195 s->req.rex = TICK_ETERNITY;
196 s->req.wex = TICK_ETERNITY;
197 s->req.analyse_exp = TICK_ETERNITY;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200198
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100199 channel_init(&s->res);
Willy Tarreauef573c02014-11-28 14:17:09 +0100200 s->res.flags |= CF_ISRESP;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100201 s->res.analysers = 0;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200202
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200203 if (sess->fe->options2 & PR_O2_NODELAY) {
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100204 s->req.flags |= CF_NEVER_WAIT;
205 s->res.flags |= CF_NEVER_WAIT;
Willy Tarreau96e31212011-05-30 18:10:30 +0200206 }
207
Willy Tarreauc8815ef2015-04-05 18:15:59 +0200208 s->res.wto = sess->fe->timeout.client;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100209 s->res.rto = TICK_ETERNITY;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100210 s->res.rex = TICK_ETERNITY;
211 s->res.wex = TICK_ETERNITY;
212 s->res.analyse_exp = TICK_ETERNITY;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200213
Willy Tarreaueee5b512015-04-03 23:46:31 +0200214 s->txn = NULL;
Willy Tarreau62f791e2012-03-09 11:32:30 +0100215
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100216 HLUA_INIT(&s->hlua);
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100217
Christopher Faulet92d36382015-11-05 13:35:03 +0100218 if (flt_stream_init(s) < 0 || flt_stream_start(s) < 0)
Christopher Fauletd7c91962015-04-30 11:48:27 +0200219 goto out_fail_accept;
220
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200221 /* finish initialization of the accepted file descriptor */
Willy Tarreauf2b98742015-04-05 01:30:42 +0200222 if (conn)
223 conn_data_want_recv(conn);
Willy Tarreau470280e2015-04-05 01:33:13 +0200224 else if (appctx)
Willy Tarreaufe127932015-04-21 19:23:39 +0200225 si_applet_want_get(&s->si[0]);
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200226
Willy Tarreaufb9f5842015-04-05 18:19:23 +0200227 if (sess->fe->accept && sess->fe->accept(s) < 0)
Willy Tarreauc5a7ff42015-04-05 11:52:08 +0200228 goto out_fail_accept;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200229
230 /* it is important not to call the wakeup function directly but to
231 * pass through task_wakeup(), because this one knows how to apply
232 * priorities to tasks.
233 */
234 task_wakeup(t, TASK_WOKEN_INIT);
Willy Tarreau02d86382015-04-05 12:00:52 +0200235 return s;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200236
237 /* Error unrolling */
Willy Tarreauc5a7ff42015-04-05 11:52:08 +0200238 out_fail_accept:
Christopher Faulet92d36382015-11-05 13:35:03 +0100239 flt_stream_release(s, 0);
Willy Tarreau3b246412014-11-25 17:10:33 +0100240 LIST_DEL(&s->list);
Willy Tarreau02a0c0e2015-04-04 18:08:21 +0200241 pool_free2(pool2_stream, s);
Willy Tarreau02d86382015-04-05 12:00:52 +0200242 return NULL;
Willy Tarreau81f9aa32010-06-01 17:45:26 +0200243}
244
Willy Tarreaubaaee002006-06-26 02:48:02 +0200245/*
Willy Tarreau87b09662015-04-03 00:22:06 +0200246 * frees the context associated to a stream. It must have been removed first.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200247 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200248static void stream_free(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200249{
Willy Tarreau9ad7bd42015-04-03 19:19:59 +0200250 struct session *sess = strm_sess(s);
251 struct proxy *fe = sess->fe;
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100252 struct bref *bref, *back;
Willy Tarreau9ad7bd42015-04-03 19:19:59 +0200253 struct connection *cli_conn = objt_conn(sess->origin);
Willy Tarreaua4cda672010-06-06 18:28:49 +0200254 int i;
Willy Tarreau0f7562b2007-01-07 15:46:13 +0100255
Willy Tarreaubaaee002006-06-26 02:48:02 +0200256 if (s->pend_pos)
257 pendconn_free(s->pend_pos);
Willy Tarreau922a8062008-12-04 09:33:58 +0100258
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100259 if (objt_server(s->target)) { /* there may be requests left pending in queue */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200260 if (s->flags & SF_CURR_SESS) {
261 s->flags &= ~SF_CURR_SESS;
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100262 objt_server(s->target)->cur_sess--;
Willy Tarreau1e62de62008-11-11 20:20:02 +0100263 }
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100264 if (may_dequeue_tasks(objt_server(s->target), s->be))
265 process_srv_queue(objt_server(s->target));
Willy Tarreau1e62de62008-11-11 20:20:02 +0100266 }
Willy Tarreau922a8062008-12-04 09:33:58 +0100267
Willy Tarreau7c669d72008-06-20 15:04:11 +0200268 if (unlikely(s->srv_conn)) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200269 /* the stream still has a reserved slot on a server, but
Willy Tarreau7c669d72008-06-20 15:04:11 +0200270 * it should normally be only the same as the one above,
271 * so this should not happen in fact.
272 */
273 sess_change_server(s, NULL);
274 }
275
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100276 if (s->req.pipe)
277 put_pipe(s->req.pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +0100278
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100279 if (s->res.pipe)
280 put_pipe(s->res.pipe);
Willy Tarreau259de1b2009-01-18 21:56:21 +0100281
Willy Tarreaubf883e02014-11-25 21:10:35 +0100282 /* We may still be present in the buffer wait queue */
283 if (!LIST_ISEMPTY(&s->buffer_wait)) {
284 LIST_DEL(&s->buffer_wait);
285 LIST_INIT(&s->buffer_wait);
286 }
287
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100288 b_drop(&s->req.buf);
289 b_drop(&s->res.buf);
Willy Tarreaubf883e02014-11-25 21:10:35 +0100290 if (!LIST_ISEMPTY(&buffer_wq))
Willy Tarreau87b09662015-04-03 00:22:06 +0200291 stream_offer_buffers();
Willy Tarreau9b28e032012-10-12 23:49:43 +0200292
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100293 hlua_ctx_destroy(&s->hlua);
Willy Tarreaueee5b512015-04-03 23:46:31 +0200294 if (s->txn)
295 http_end_txn(s);
Willy Tarreau46023632010-01-07 22:51:47 +0100296
Willy Tarreau1e954912012-10-12 17:50:05 +0200297 /* ensure the client-side transport layer is destroyed */
Willy Tarreauf79c8172013-10-21 16:30:56 +0200298 if (cli_conn)
299 conn_force_close(cli_conn);
Willy Tarreau1e954912012-10-12 17:50:05 +0200300
Willy Tarreaua4cda672010-06-06 18:28:49 +0200301 for (i = 0; i < s->store_count; i++) {
302 if (!s->store[i].ts)
303 continue;
304 stksess_free(s->store[i].table, s->store[i].ts);
305 s->store[i].ts = NULL;
306 }
307
Willy Tarreaueee5b512015-04-03 23:46:31 +0200308 if (s->txn) {
309 pool_free2(pool2_hdr_idx, s->txn->hdr_idx.v);
310 pool_free2(pool2_http_txn, s->txn);
311 s->txn = NULL;
312 }
313
Christopher Fauletd7c91962015-04-30 11:48:27 +0200314 flt_stream_stop(s);
Christopher Faulet92d36382015-11-05 13:35:03 +0100315 flt_stream_release(s, 0);
Christopher Fauletd7c91962015-04-30 11:48:27 +0200316
Willy Tarreau92fb9832007-10-16 17:34:28 +0200317 if (fe) {
Willy Tarreaucb7dd012015-04-03 22:16:32 +0200318 pool_free2(fe->rsp_cap_pool, s->res_cap);
319 pool_free2(fe->req_cap_pool, s->req_cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200320 }
Willy Tarreau0937bc42009-12-22 15:03:09 +0100321
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200322 /* Cleanup all variable contexts. */
Willy Tarreau6204cd92016-03-10 16:33:04 +0100323 vars_prune(&s->vars_txn, s->sess, s);
324 vars_prune(&s->vars_reqres, s->sess, s);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200325
Willy Tarreau87b09662015-04-03 00:22:06 +0200326 stream_store_counters(s);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200327
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100328 list_for_each_entry_safe(bref, back, &s->back_refs, users) {
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100329 /* we have to unlink all watchers. We must not relink them if
Willy Tarreau87b09662015-04-03 00:22:06 +0200330 * this stream was the last one in the list.
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100331 */
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100332 LIST_DEL(&bref->users);
Willy Tarreaufd3828e2009-02-22 15:17:24 +0100333 LIST_INIT(&bref->users);
Willy Tarreau87b09662015-04-03 00:22:06 +0200334 if (s->list.n != &streams)
335 LIST_ADDQ(&LIST_ELEM(s->list.n, struct stream *, list)->back_refs, &bref->users);
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100336 bref->ref = s->list.n;
337 }
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100338 LIST_DEL(&s->list);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200339 si_release_endpoint(&s->si[1]);
340 si_release_endpoint(&s->si[0]);
Willy Tarreaufeb76402015-04-03 14:10:06 +0200341
342 /* FIXME: for now we have a 1:1 relation between stream and session so
343 * the stream must free the session.
344 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200345 pool_free2(pool2_stream, s);
Willy Tarreau11c36242015-04-04 15:54:03 +0200346 session_free(sess);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200347
348 /* We may want to free the maximum amount of pools if the proxy is stopping */
Willy Tarreau92fb9832007-10-16 17:34:28 +0200349 if (fe && unlikely(fe->state == PR_STSTOPPED)) {
Willy Tarreau9b28e032012-10-12 23:49:43 +0200350 pool_flush2(pool2_buffer);
Willy Tarreau63986c72015-04-03 22:55:33 +0200351 pool_flush2(pool2_http_txn);
Willy Tarreau34eb6712011-10-24 18:15:04 +0200352 pool_flush2(pool2_hdr_idx);
Willy Tarreau48d63db2008-08-03 17:41:33 +0200353 pool_flush2(pool2_requri);
354 pool_flush2(pool2_capture);
Willy Tarreau87b09662015-04-03 00:22:06 +0200355 pool_flush2(pool2_stream);
Willy Tarreaufeb76402015-04-03 14:10:06 +0200356 pool_flush2(pool2_session);
Willy Tarreau3a5e0602014-11-13 16:46:28 +0100357 pool_flush2(pool2_connection);
358 pool_flush2(pool2_pendconn);
Willy Tarreau48d63db2008-08-03 17:41:33 +0200359 pool_flush2(fe->req_cap_pool);
360 pool_flush2(fe->rsp_cap_pool);
Willy Tarreau632f5a72007-07-11 10:42:35 +0200361 }
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200362}
363
Willy Tarreau78955f42014-12-28 13:09:02 +0100364/* Allocates a receive buffer for channel <chn>, but only if it's guaranteed
365 * that it's not the last available buffer or it's the response buffer. Unless
366 * the buffer is the response buffer, an extra control is made so that we always
367 * keep <tune.buffers.reserved> buffers available after this allocation. To be
368 * called at the beginning of recv() callbacks to ensure that the required
369 * buffers are properly allocated. Returns 0 in case of failure, non-zero
370 * otherwise.
Willy Tarreau656859d2014-11-25 19:46:36 +0100371 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200372int stream_alloc_recv_buffer(struct channel *chn)
Willy Tarreau656859d2014-11-25 19:46:36 +0100373{
Willy Tarreau87b09662015-04-03 00:22:06 +0200374 struct stream *s;
Willy Tarreau656859d2014-11-25 19:46:36 +0100375 struct buffer *b;
Willy Tarreaua24adf02014-11-27 01:11:56 +0100376 int margin = 0;
Willy Tarreau656859d2014-11-25 19:46:36 +0100377
Willy Tarreau78955f42014-12-28 13:09:02 +0100378 if (!(chn->flags & CF_ISRESP))
Willy Tarreaua24adf02014-11-27 01:11:56 +0100379 margin = global.tune.reserved_bufs;
380
Thierry FOURNIER27929fb2015-09-25 08:36:11 +0200381 s = chn_strm(chn);
Willy Tarreau78955f42014-12-28 13:09:02 +0100382
383 b = b_alloc_margin(&chn->buf, margin);
Willy Tarreau656859d2014-11-25 19:46:36 +0100384 if (b)
385 return 1;
386
Willy Tarreaubf883e02014-11-25 21:10:35 +0100387 if (LIST_ISEMPTY(&s->buffer_wait))
388 LIST_ADDQ(&buffer_wq, &s->buffer_wait);
Willy Tarreau656859d2014-11-25 19:46:36 +0100389 return 0;
390}
391
Willy Tarreau87b09662015-04-03 00:22:06 +0200392/* Allocates a work buffer for stream <s>. It is meant to be called inside
393 * process_stream(). It will only allocate the side needed for the function
Willy Tarreaubc39a5d2015-04-20 15:52:18 +0200394 * to work fine, which is the response buffer so that an error message may be
395 * built and returned. Response buffers may be allocated from the reserve, this
396 * is critical to ensure that a response may always flow and will never block a
397 * server from releasing a connection. Returns 0 in case of failure, non-zero
398 * otherwise.
Willy Tarreau656859d2014-11-25 19:46:36 +0100399 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200400int stream_alloc_work_buffer(struct stream *s)
Willy Tarreau656859d2014-11-25 19:46:36 +0100401{
Willy Tarreaubf883e02014-11-25 21:10:35 +0100402 if (!LIST_ISEMPTY(&s->buffer_wait)) {
403 LIST_DEL(&s->buffer_wait);
404 LIST_INIT(&s->buffer_wait);
405 }
Willy Tarreau656859d2014-11-25 19:46:36 +0100406
Willy Tarreaubc39a5d2015-04-20 15:52:18 +0200407 if (b_alloc_margin(&s->res.buf, 0))
Willy Tarreau656859d2014-11-25 19:46:36 +0100408 return 1;
409
Willy Tarreaubf883e02014-11-25 21:10:35 +0100410 LIST_ADDQ(&buffer_wq, &s->buffer_wait);
Willy Tarreau656859d2014-11-25 19:46:36 +0100411 return 0;
412}
413
414/* releases unused buffers after processing. Typically used at the end of the
Willy Tarreaubf883e02014-11-25 21:10:35 +0100415 * update() functions. It will try to wake up as many tasks as the number of
Willy Tarreau87b09662015-04-03 00:22:06 +0200416 * buffers that it releases. In practice, most often streams are blocked on
Willy Tarreaubf883e02014-11-25 21:10:35 +0100417 * a single buffer, so it makes sense to try to wake two up when two buffers
418 * are released at once.
Willy Tarreau656859d2014-11-25 19:46:36 +0100419 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200420void stream_release_buffers(struct stream *s)
Willy Tarreau656859d2014-11-25 19:46:36 +0100421{
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100422 if (s->req.buf->size && buffer_empty(s->req.buf))
423 b_free(&s->req.buf);
Willy Tarreau656859d2014-11-25 19:46:36 +0100424
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100425 if (s->res.buf->size && buffer_empty(s->res.buf))
426 b_free(&s->res.buf);
Willy Tarreau656859d2014-11-25 19:46:36 +0100427
Willy Tarreaubf883e02014-11-25 21:10:35 +0100428 /* if we're certain to have at least 1 buffer available, and there is
429 * someone waiting, we can wake up a waiter and offer them.
430 */
Willy Tarreaua24adf02014-11-27 01:11:56 +0100431 if (!LIST_ISEMPTY(&buffer_wq))
Willy Tarreau87b09662015-04-03 00:22:06 +0200432 stream_offer_buffers();
Willy Tarreaubf883e02014-11-25 21:10:35 +0100433}
434
Willy Tarreau87b09662015-04-03 00:22:06 +0200435/* Runs across the list of pending streams waiting for a buffer and wakes one
Willy Tarreaua24adf02014-11-27 01:11:56 +0100436 * up if buffers are available. Will stop when the run queue reaches <rqlimit>.
Willy Tarreau87b09662015-04-03 00:22:06 +0200437 * Should not be called directly, use stream_offer_buffers() instead.
Willy Tarreaubf883e02014-11-25 21:10:35 +0100438 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200439void __stream_offer_buffers(int rqlimit)
Willy Tarreaubf883e02014-11-25 21:10:35 +0100440{
Willy Tarreau87b09662015-04-03 00:22:06 +0200441 struct stream *sess, *bak;
Willy Tarreaubf883e02014-11-25 21:10:35 +0100442
443 list_for_each_entry_safe(sess, bak, &buffer_wq, buffer_wait) {
Willy Tarreaua24adf02014-11-27 01:11:56 +0100444 if (rqlimit <= run_queue)
445 break;
446
Willy Tarreaubf883e02014-11-25 21:10:35 +0100447 if (sess->task->state & TASK_RUNNING)
448 continue;
449
450 LIST_DEL(&sess->buffer_wait);
451 LIST_INIT(&sess->buffer_wait);
Willy Tarreaubf883e02014-11-25 21:10:35 +0100452 task_wakeup(sess->task, TASK_WOKEN_RES);
Willy Tarreaubf883e02014-11-25 21:10:35 +0100453 }
Willy Tarreau656859d2014-11-25 19:46:36 +0100454}
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200455
456/* perform minimal intializations, report 0 in case of error, 1 if OK. */
Willy Tarreau87b09662015-04-03 00:22:06 +0200457int init_stream()
Willy Tarreauc6ca1a02007-05-13 19:43:47 +0200458{
Willy Tarreau87b09662015-04-03 00:22:06 +0200459 LIST_INIT(&streams);
460 pool2_stream = create_pool("stream", sizeof(struct stream), MEM_F_SHARED);
461 return pool2_stream != NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200462}
463
Willy Tarreau87b09662015-04-03 00:22:06 +0200464void stream_process_counters(struct stream *s)
Willy Tarreau30e71012007-11-26 20:15:35 +0100465{
Willy Tarreaufb0afa72015-04-03 14:46:27 +0200466 struct session *sess = s->sess;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100467 unsigned long long bytes;
Emeric Brun57056f02015-06-15 18:29:57 +0200468 void *ptr1,*ptr2;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100469 int i;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100470
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100471 bytes = s->req.total - s->logs.bytes_in;
472 s->logs.bytes_in = s->req.total;
473 if (bytes) {
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200474 sess->fe->fe_counters.bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100475
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100476 s->be->be_counters.bytes_in += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100477
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100478 if (objt_server(s->target))
479 objt_server(s->target)->counters.bytes_in += bytes;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200480
Willy Tarreaufb0afa72015-04-03 14:46:27 +0200481 if (sess->listener && sess->listener->counters)
482 sess->listener->counters->bytes_in += bytes;
Willy Tarreau855e4bb2010-06-18 18:33:32 +0200483
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100484 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200485 struct stkctr *stkctr = &s->stkctr[i];
486
487 if (!stkctr_entry(stkctr)) {
488 stkctr = &sess->stkctr[i];
489 if (!stkctr_entry(stkctr))
490 continue;
491 }
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200492
Emeric Brun57056f02015-06-15 18:29:57 +0200493 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT);
494 if (ptr1)
495 stktable_data_cast(ptr1, bytes_in_cnt) += bytes;
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200496
Emeric Brun57056f02015-06-15 18:29:57 +0200497 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE);
498 if (ptr2)
499 update_freq_ctr_period(&stktable_data_cast(ptr2, bytes_in_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200500 stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes);
Emeric Brun57056f02015-06-15 18:29:57 +0200501
502 /* If data was modified, we need to touch to re-schedule sync */
503 if (ptr1 || ptr2)
504 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreau30e71012007-11-26 20:15:35 +0100505 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100506 }
507
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100508 bytes = s->res.total - s->logs.bytes_out;
509 s->logs.bytes_out = s->res.total;
510 if (bytes) {
Willy Tarreaue36cbcb2015-04-03 15:40:56 +0200511 sess->fe->fe_counters.bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100512
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100513 s->be->be_counters.bytes_out += bytes;
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100514
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100515 if (objt_server(s->target))
516 objt_server(s->target)->counters.bytes_out += bytes;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200517
Willy Tarreaufb0afa72015-04-03 14:46:27 +0200518 if (sess->listener && sess->listener->counters)
519 sess->listener->counters->bytes_out += bytes;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200520
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100521 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200522 struct stkctr *stkctr = &s->stkctr[i];
523
524 if (!stkctr_entry(stkctr)) {
525 stkctr = &sess->stkctr[i];
526 if (!stkctr_entry(stkctr))
527 continue;
528 }
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200529
Emeric Brun57056f02015-06-15 18:29:57 +0200530 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT);
531 if (ptr1)
532 stktable_data_cast(ptr1, bytes_out_cnt) += bytes;
Willy Tarreau6c59e0a2010-06-20 11:56:30 +0200533
Emeric Brun57056f02015-06-15 18:29:57 +0200534 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE);
535 if (ptr2)
536 update_freq_ctr_period(&stktable_data_cast(ptr2, bytes_out_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200537 stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes);
Emeric Brun57056f02015-06-15 18:29:57 +0200538
539 /* If data was modified, we need to touch to re-schedule sync */
540 if (ptr1 || ptr2)
541 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreau30e71012007-11-26 20:15:35 +0100542 }
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100543 }
544}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200545
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100546/* This function is called with (si->state == SI_ST_CON) meaning that a
547 * connection was attempted and that the file descriptor is already allocated.
548 * We must check for establishment, error and abort. Possible output states
549 * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and
550 * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER,
Willy Tarreau87b09662015-04-03 00:22:06 +0200551 * otherwise 1. This only works with connection-based streams.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100552 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200553static int sess_update_st_con_tcp(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100554{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100555 struct stream_interface *si = &s->si[1];
556 struct channel *req = &s->req;
557 struct channel *rep = &s->res;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100558
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100559 /* If we got an error, or if nothing happened and the connection timed
560 * out, we must give up. The CER state handler will take care of retry
561 * attempts and error reports.
562 */
563 if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) {
Willy Tarreau103197d2014-11-28 15:26:12 +0100564 if (unlikely(req->flags & CF_WRITE_PARTIAL)) {
Willy Tarreaue3224e82012-10-29 22:41:31 +0100565 /* Some data were sent past the connection establishment,
566 * so we need to pretend we're established to log correctly
567 * and let later states handle the failure.
568 */
Willy Tarreaue3224e82012-10-29 22:41:31 +0100569 si->state = SI_ST_EST;
570 si->err_type = SI_ET_DATA_ERR;
Willy Tarreau103197d2014-11-28 15:26:12 +0100571 rep->flags |= CF_READ_ERROR | CF_WRITE_ERROR;
Willy Tarreaue3224e82012-10-29 22:41:31 +0100572 return 1;
573 }
Willy Tarreau127334e2009-03-28 10:47:26 +0100574 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100575 si->state = SI_ST_CER;
Willy Tarreau0ede5a32012-12-08 08:44:02 +0100576
Willy Tarreau568743a2016-08-07 08:12:35 +0200577 si_release_endpoint(si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100578
579 if (si->err_type)
580 return 0;
581
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100582 if (si->flags & SI_FL_ERR)
583 si->err_type = SI_ET_CONN_ERR;
584 else
585 si->err_type = SI_ET_CONN_TO;
586 return 0;
587 }
588
589 /* OK, maybe we want to abort */
Willy Tarreaua7a7ebc2012-12-30 00:50:35 +0100590 if (!(req->flags & CF_WRITE_PARTIAL) &&
591 unlikely((rep->flags & CF_SHUTW) ||
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200592 ((req->flags & CF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */
593 ((!(req->flags & CF_WRITE_ACTIVITY) && channel_is_empty(req)) ||
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100594 s->be->options & PR_O_ABRT_CLOSE)))) {
595 /* give up */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200596 si_shutw(si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100597 si->err_type |= SI_ET_CONN_ABRT;
Willy Tarreau84455332009-03-15 22:34:05 +0100598 if (s->srv_error)
599 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100600 return 1;
601 }
602
603 /* we need to wait a bit more if there was no activity either */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200604 if (!(req->flags & CF_WRITE_ACTIVITY))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100605 return 1;
606
607 /* OK, this means that a connection succeeded. The caller will be
608 * responsible for handling the transition from CON to EST.
609 */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100610 si->state = SI_ST_EST;
611 si->err_type = SI_ET_NONE;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100612 return 1;
613}
614
615/* This function is called with (si->state == SI_ST_CER) meaning that a
616 * previous connection attempt has failed and that the file descriptor
617 * has already been released. Possible causes include asynchronous error
618 * notification and time out. Possible output states are SI_ST_CLO when
619 * retries are exhausted, SI_ST_TAR when a delay is wanted before a new
620 * connection attempt, SI_ST_ASS when it's wise to retry on the same server,
621 * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are
622 * marked as in error state. It returns 0.
623 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200624static int sess_update_st_cer(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100625{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100626 struct stream_interface *si = &s->si[1];
627
Willy Tarreau87b09662015-04-03 00:22:06 +0200628 /* we probably have to release last stream from the server */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100629 if (objt_server(s->target)) {
630 health_adjust(objt_server(s->target), HANA_STATUS_L4_ERR);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100631
Willy Tarreaue7dff022015-04-03 01:14:29 +0200632 if (s->flags & SF_CURR_SESS) {
633 s->flags &= ~SF_CURR_SESS;
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100634 objt_server(s->target)->cur_sess--;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100635 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100636 }
637
638 /* ensure that we have enough retries left */
Willy Tarreauee28de02010-06-01 09:51:00 +0200639 si->conn_retries--;
640 if (si->conn_retries < 0) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100641 if (!si->err_type) {
642 si->err_type = SI_ET_CONN_ERR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100643 }
644
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100645 if (objt_server(s->target))
646 objt_server(s->target)->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100647 s->be->be_counters.failed_conns++;
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100648 sess_change_server(s, NULL);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100649 if (may_dequeue_tasks(objt_server(s->target), s->be))
650 process_srv_queue(objt_server(s->target));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100651
652 /* shutw is enough so stop a connecting socket */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200653 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100654 s->req.flags |= CF_WRITE_ERROR;
655 s->res.flags |= CF_READ_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100656
657 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100658 if (s->srv_error)
659 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100660 return 0;
661 }
662
663 /* If the "redispatch" option is set on the backend, we are allowed to
Joseph Lynch726ab712015-05-11 23:25:34 -0700664 * retry on another server. By default this redispatch occurs on the
665 * last retry, but if configured we allow redispatches to occur on
666 * configurable intervals, e.g. on every retry. In order to achieve this,
Willy Tarreau87b09662015-04-03 00:22:06 +0200667 * we must mark the stream unassigned, and eventually clear the DIRECT
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100668 * bit to ignore any persistence cookie. We won't count a retry nor a
669 * redispatch yet, because this will depend on what server is selected.
Willy Tarreau33a14e52014-06-13 17:49:40 +0200670 * If the connection is not persistent, the balancing algorithm is not
671 * determinist (round robin) and there is more than one active server,
672 * we accept to perform an immediate redispatch without waiting since
673 * we don't care about this particular server.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100674 */
Willy Tarreau33a14e52014-06-13 17:49:40 +0200675 if (objt_server(s->target) &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700676 (s->be->options & PR_O_REDISP) && !(s->flags & SF_FORCE_PRST) &&
Willy Tarreau49008c12016-01-13 07:58:44 +0100677 ((__objt_server(s->target)->state < SRV_ST_RUNNING) ||
678 (((s->be->redispatch_after > 0) &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700679 ((s->be->conn_retries - si->conn_retries) %
680 s->be->redispatch_after == 0)) ||
681 ((s->be->redispatch_after < 0) &&
682 ((s->be->conn_retries - si->conn_retries) %
683 (s->be->conn_retries + 1 + s->be->redispatch_after) == 0))) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +0200684 (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700685 ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR)))) {
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100686 sess_change_server(s, NULL);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100687 if (may_dequeue_tasks(objt_server(s->target), s->be))
688 process_srv_queue(objt_server(s->target));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100689
Willy Tarreaue7dff022015-04-03 01:14:29 +0200690 s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100691 si->state = SI_ST_REQ;
692 } else {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100693 if (objt_server(s->target))
694 objt_server(s->target)->counters.retries++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100695 s->be->be_counters.retries++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100696 si->state = SI_ST_ASS;
697 }
698
699 if (si->flags & SI_FL_ERR) {
700 /* The error was an asynchronous connection error, and we will
701 * likely have to retry connecting to the same server, most
702 * likely leading to the same result. To avoid this, we wait
Willy Tarreaub0290662014-06-13 17:04:44 +0200703 * MIN(one second, connect timeout) before retrying.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100704 */
705
Willy Tarreaub0290662014-06-13 17:04:44 +0200706 int delay = 1000;
707
708 if (s->be->timeout.connect && s->be->timeout.connect < delay)
709 delay = s->be->timeout.connect;
710
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100711 if (!si->err_type)
712 si->err_type = SI_ET_CONN_ERR;
713
Willy Tarreaudb6d0122014-06-13 17:40:15 +0200714 /* only wait when we're retrying on the same server */
715 if (si->state == SI_ST_ASS ||
716 (s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_RR ||
717 (s->be->srv_act <= 1)) {
718 si->state = SI_ST_TAR;
719 si->exp = tick_add(now_ms, MS_TO_TICKS(delay));
720 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100721 return 0;
722 }
723 return 0;
724}
725
726/*
727 * This function handles the transition between the SI_ST_CON state and the
Willy Tarreau85e7d002010-05-31 11:57:51 +0200728 * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or
Willy Tarreau26d8c592012-05-07 18:12:14 +0200729 * SI_ST_INI) to SI_ST_EST, but only when a ->proto is defined.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100730 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200731static void sess_establish(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100732{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100733 struct stream_interface *si = &s->si[1];
734 struct channel *req = &s->req;
735 struct channel *rep = &s->res;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100736
Willy Tarreau0e37f1c2013-12-31 23:06:46 +0100737 /* First, centralize the timers information */
738 s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
739 si->exp = TICK_ETERNITY;
740
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100741 if (objt_server(s->target))
742 health_adjust(objt_server(s->target), HANA_STATUS_L4_OK);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100743
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100744 if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100745 /* if the user wants to log as soon as possible, without counting
746 * bytes from the server, then this is the right moment. */
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200747 if (!LIST_ISEMPTY(&strm_fe(s)->logformat) && !(s->logs.logwait & LW_BYTES)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100748 s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
Willy Tarreaua5555ec2008-11-30 19:02:32 +0100749 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100750 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100751 }
752 else {
Willy Tarreaud81ca042013-12-31 22:33:13 +0100753 rep->flags |= CF_READ_DONTWAIT; /* a single read is enough to get response headers */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100754 }
755
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200756 rep->analysers |= strm_fe(s)->fe_rsp_ana | s->be->be_rsp_ana;
Christopher Faulet309c6412015-12-02 09:57:32 +0100757
758 /* Be sure to filter response headers if the backend is an HTTP proxy
759 * and if there are filters attached to the stream. */
760 if (s->be->mode == PR_MODE_HTTP && HAS_FILTERS(s))
761 rep->analysers |= AN_FLT_HTTP_HDRS;
762
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200763 rep->flags |= CF_READ_ATTACHED; /* producer is now attached */
Willy Tarreau644c1012014-04-30 18:11:11 +0200764 if (req->flags & CF_WAKE_CONNECT) {
765 req->flags |= CF_WAKE_ONCE;
766 req->flags &= ~CF_WAKE_CONNECT;
767 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200768 if (objt_conn(si->end)) {
Willy Tarreaud04e8582010-05-31 12:31:35 +0200769 /* real connections have timeouts */
770 req->wto = s->be->timeout.server;
771 rep->rto = s->be->timeout.server;
772 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100773 req->wex = TICK_ETERNITY;
774}
775
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700776/* Check if the connection request is in such a state that it can be aborted. */
777static int check_req_may_abort(struct channel *req, struct stream *s)
778{
779 return ((req->flags & (CF_READ_ERROR)) ||
780 ((req->flags & CF_SHUTW_NOW) && /* empty and client aborted */
781 (channel_is_empty(req) || s->be->options & PR_O_ABRT_CLOSE)));
782}
783
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100784/* Update back stream interface status for input states SI_ST_ASS, SI_ST_QUE,
785 * SI_ST_TAR. Other input states are simply ignored.
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +0100786 * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON
787 * and SI_ST_EST. Flags must have previously been updated for timeouts and other
788 * conditions.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100789 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200790static void sess_update_stream_int(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100791{
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100792 struct server *srv = objt_server(s->target);
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100793 struct stream_interface *si = &s->si[1];
Willy Tarreau103197d2014-11-28 15:26:12 +0100794 struct channel *req = &s->req;
Willy Tarreau827aee92011-03-10 16:55:02 +0100795
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100796 DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100797 now_ms, __FUNCTION__,
798 s,
CJ Ess6eac32e2015-05-02 16:35:24 -0400799 req, &s->res,
Willy Tarreau103197d2014-11-28 15:26:12 +0100800 req->rex, s->res.wex,
801 req->flags, s->res.flags,
CJ Ess6eac32e2015-05-02 16:35:24 -0400802 req->buf->i, req->buf->o, s->res.buf->i, s->res.buf->o, s->si[0].state, s->si[1].state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100803
804 if (si->state == SI_ST_ASS) {
805 /* Server assigned to connection request, we have to try to connect now */
806 int conn_err;
807
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700808 /* Before we try to initiate the connection, see if the
809 * request may be aborted instead.
810 */
811 if (check_req_may_abort(req, s)) {
812 si->err_type |= SI_ET_CONN_ABRT;
813 goto abort_connection;
814 }
815
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100816 conn_err = connect_server(s);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100817 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +0100818
Willy Tarreaue7dff022015-04-03 01:14:29 +0200819 if (conn_err == SF_ERR_NONE) {
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +0100820 /* state = SI_ST_CON or SI_ST_EST now */
Willy Tarreau827aee92011-03-10 16:55:02 +0100821 if (srv)
822 srv_inc_sess_ctr(srv);
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -0500823 if (srv)
824 srv_set_sess_last(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100825 return;
826 }
827
828 /* We have received a synchronous error. We might have to
829 * abort, retry immediately or redispatch.
830 */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200831 if (conn_err == SF_ERR_INTERNAL) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100832 if (!si->err_type) {
833 si->err_type = SI_ET_CONN_OTHER;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100834 }
835
Willy Tarreau827aee92011-03-10 16:55:02 +0100836 if (srv)
837 srv_inc_sess_ctr(srv);
838 if (srv)
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -0500839 srv_set_sess_last(srv);
840 if (srv)
Willy Tarreau827aee92011-03-10 16:55:02 +0100841 srv->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100842 s->be->be_counters.failed_conns++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100843
Willy Tarreau87b09662015-04-03 00:22:06 +0200844 /* release other streams waiting for this server */
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100845 sess_change_server(s, NULL);
Willy Tarreau827aee92011-03-10 16:55:02 +0100846 if (may_dequeue_tasks(srv, s->be))
847 process_srv_queue(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100848
849 /* Failed and not retryable. */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200850 si_shutr(si);
851 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100852 req->flags |= CF_WRITE_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100853
854 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
855
Willy Tarreau87b09662015-04-03 00:22:06 +0200856 /* no stream was ever accounted for this server */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100857 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100858 if (s->srv_error)
859 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100860 return;
861 }
862
863 /* We are facing a retryable error, but we don't want to run a
864 * turn-around now, as the problem is likely a source port
865 * allocation problem, so we want to retry now.
866 */
867 si->state = SI_ST_CER;
868 si->flags &= ~SI_FL_ERR;
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100869 sess_update_st_cer(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100870 /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */
871 return;
872 }
873 else if (si->state == SI_ST_QUE) {
874 /* connection request was queued, check for any update */
875 if (!s->pend_pos) {
876 /* The connection is not in the queue anymore. Either
877 * we have a server connection slot available and we
878 * go directly to the assigned state, or we need to
879 * load-balance first and go to the INI state.
880 */
881 si->exp = TICK_ETERNITY;
Willy Tarreaue7dff022015-04-03 01:14:29 +0200882 if (unlikely(!(s->flags & SF_ASSIGNED)))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100883 si->state = SI_ST_REQ;
884 else {
885 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
886 si->state = SI_ST_ASS;
887 }
888 return;
889 }
890
891 /* Connection request still in queue... */
892 if (si->flags & SI_FL_EXP) {
893 /* ... and timeout expired */
894 si->exp = TICK_ETERNITY;
895 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau827aee92011-03-10 16:55:02 +0100896 if (srv)
897 srv->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100898 s->be->be_counters.failed_conns++;
Willy Tarreau73b013b2012-05-21 16:31:45 +0200899 si_shutr(si);
900 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100901 req->flags |= CF_WRITE_TIMEOUT;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100902 if (!si->err_type)
903 si->err_type = SI_ET_QUEUE_TO;
904 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100905 if (s->srv_error)
906 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100907 return;
908 }
909
910 /* Connection remains in queue, check if we have to abort it */
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700911 if (check_req_may_abort(req, s)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100912 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100913 si->err_type |= SI_ET_QUEUE_ABRT;
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700914 goto abort_connection;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100915 }
916
917 /* Nothing changed */
918 return;
919 }
920 else if (si->state == SI_ST_TAR) {
921 /* Connection request might be aborted */
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700922 if (check_req_may_abort(req, s)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100923 si->err_type |= SI_ET_CONN_ABRT;
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700924 goto abort_connection;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100925 }
926
927 if (!(si->flags & SI_FL_EXP))
928 return; /* still in turn-around */
929
930 si->exp = TICK_ETERNITY;
931
Willy Tarreau87b09662015-04-03 00:22:06 +0200932 /* we keep trying on the same server as long as the stream is
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100933 * marked "assigned".
934 * FIXME: Should we force a redispatch attempt when the server is down ?
935 */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200936 if (s->flags & SF_ASSIGNED)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100937 si->state = SI_ST_ASS;
938 else
939 si->state = SI_ST_REQ;
940 return;
941 }
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700942 return;
943
944abort_connection:
945 /* give up */
946 si->exp = TICK_ETERNITY;
947 si_shutr(si);
948 si_shutw(si);
949 si->state = SI_ST_CLO;
950 if (s->srv_error)
951 s->srv_error(s, si);
952 return;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100953}
954
Willy Tarreau87b09662015-04-03 00:22:06 +0200955/* Set correct stream termination flags in case no analyser has done it. It
Simon Hormandec5be42011-06-08 09:19:07 +0900956 * also counts a failed request if the server state has not reached the request
957 * stage.
958 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200959static void sess_set_term_flags(struct stream *s)
Simon Hormandec5be42011-06-08 09:19:07 +0900960{
Willy Tarreaue7dff022015-04-03 01:14:29 +0200961 if (!(s->flags & SF_FINST_MASK)) {
Simon Hormandec5be42011-06-08 09:19:07 +0900962 if (s->si[1].state < SI_ST_REQ) {
963
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200964 strm_fe(s)->fe_counters.failed_req++;
Willy Tarreau2c1068c2015-09-23 12:21:21 +0200965 if (strm_li(s) && strm_li(s)->counters)
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200966 strm_li(s)->counters->failed_req++;
Simon Hormandec5be42011-06-08 09:19:07 +0900967
Willy Tarreaue7dff022015-04-03 01:14:29 +0200968 s->flags |= SF_FINST_R;
Simon Hormandec5be42011-06-08 09:19:07 +0900969 }
970 else if (s->si[1].state == SI_ST_QUE)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200971 s->flags |= SF_FINST_Q;
Simon Hormandec5be42011-06-08 09:19:07 +0900972 else if (s->si[1].state < SI_ST_EST)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200973 s->flags |= SF_FINST_C;
Simon Hormandec5be42011-06-08 09:19:07 +0900974 else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200975 s->flags |= SF_FINST_D;
Simon Hormandec5be42011-06-08 09:19:07 +0900976 else
Willy Tarreaue7dff022015-04-03 01:14:29 +0200977 s->flags |= SF_FINST_L;
Simon Hormandec5be42011-06-08 09:19:07 +0900978 }
979}
980
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100981/* This function initiates a server connection request on a stream interface
Willy Tarreaud84fb5e2013-11-30 09:06:53 +0100982 * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS for
983 * a real connection to a server, indicating that a server has been assigned,
984 * or SI_ST_EST for a successful connection to an applet. It may also return
985 * SI_ST_QUE, or SI_ST_CLO upon error.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100986 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200987static void sess_prepare_conn_req(struct stream *s)
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100988{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100989 struct stream_interface *si = &s->si[1];
990
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100991 DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100992 now_ms, __FUNCTION__,
993 s,
CJ Ess6eac32e2015-05-02 16:35:24 -0400994 &s->req, &s->res,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100995 s->req.rex, s->res.wex,
996 s->req.flags, s->res.flags,
CJ Ess6eac32e2015-05-02 16:35:24 -0400997 s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, s->si[0].state, s->si[1].state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100998
999 if (si->state != SI_ST_REQ)
1000 return;
1001
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001002 if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) {
1003 /* the applet directly goes to the EST state */
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001004 struct appctx *appctx = objt_appctx(si->end);
1005
1006 if (!appctx || appctx->applet != __objt_applet(s->target))
1007 appctx = stream_int_register_handler(si, objt_applet(s->target));
1008
1009 if (!appctx) {
1010 /* No more memory, let's immediately abort. Force the
1011 * error code to ignore the ERR_LOCAL which is not a
1012 * real error.
1013 */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001014 s->flags &= ~(SF_ERR_MASK | SF_FINST_MASK);
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001015
1016 si_shutr(si);
1017 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +01001018 s->req.flags |= CF_WRITE_ERROR;
Willy Tarreau6bbb2f62013-12-09 17:14:23 +01001019 si->err_type = SI_ET_CONN_RES;
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001020 si->state = SI_ST_CLO;
1021 if (s->srv_error)
1022 s->srv_error(s, si);
1023 return;
1024 }
1025
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001026 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001027 si->state = SI_ST_EST;
1028 si->err_type = SI_ET_NONE;
Willy Tarreaub9a551e2014-04-23 00:35:17 +02001029 be_set_sess_last(s->be);
Willy Tarreaufac4bd12013-11-30 09:21:49 +01001030 /* let sess_establish() finish the job */
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001031 return;
1032 }
1033
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001034 /* Try to assign a server */
1035 if (srv_redispatch_connect(s) != 0) {
1036 /* We did not get a server. Either we queued the
1037 * connection request, or we encountered an error.
1038 */
1039 if (si->state == SI_ST_QUE)
1040 return;
1041
1042 /* we did not get any server, let's check the cause */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001043 si_shutr(si);
1044 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +01001045 s->req.flags |= CF_WRITE_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001046 if (!si->err_type)
1047 si->err_type = SI_ET_CONN_OTHER;
1048 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +01001049 if (s->srv_error)
1050 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001051 return;
1052 }
1053
1054 /* The server is assigned */
1055 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
1056 si->state = SI_ST_ASS;
Willy Tarreaub9a551e2014-04-23 00:35:17 +02001057 be_set_sess_last(s->be);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001058}
1059
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02001060/* This function parses the use-service action ruleset. It executes
1061 * the associated ACL and set an applet as a stream or txn final node.
1062 * it returns ACT_RET_ERR if an error occurs, the proxy left in
1063 * consistent state. It returns ACT_RET_STOP in succes case because
1064 * use-service must be a terminal action. Returns ACT_RET_YIELD
1065 * if the initialisation function require more data.
1066 */
1067enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
1068 struct session *sess, struct stream *s, int flags)
1069
1070{
1071 struct appctx *appctx;
1072
1073 /* Initialises the applet if it is required. */
1074 if (flags & ACT_FLAG_FIRST) {
1075 /* Register applet. this function schedules the applet. */
1076 s->target = &rule->applet.obj_type;
1077 if (unlikely(!stream_int_register_handler(&s->si[1], objt_applet(s->target))))
1078 return ACT_RET_ERR;
1079
1080 /* Initialise the context. */
1081 appctx = si_appctx(&s->si[1]);
1082 memset(&appctx->ctx, 0, sizeof(appctx->ctx));
1083 appctx->rule = rule;
1084 }
1085 else
1086 appctx = si_appctx(&s->si[1]);
1087
1088 /* Stops the applet sheduling, in case of the init function miss
1089 * some data.
1090 */
1091 appctx_pause(appctx);
1092 si_applet_stop_get(&s->si[1]);
1093
1094 /* Call initialisation. */
1095 if (rule->applet.init)
1096 switch (rule->applet.init(appctx, px, s)) {
1097 case 0: return ACT_RET_ERR;
1098 case 1: break;
1099 default: return ACT_RET_YIELD;
1100 }
1101
1102 /* Now we can schedule the applet. */
1103 si_applet_cant_get(&s->si[1]);
1104 appctx_wakeup(appctx);
1105
1106 if (sess->fe == s->be) /* report it if the request was intercepted by the frontend */
1107 sess->fe->fe_counters.intercepted_req++;
1108
1109 /* The flag SF_ASSIGNED prevent from server assignment. */
1110 s->flags |= SF_ASSIGNED;
1111
1112 return ACT_RET_STOP;
1113}
1114
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001115/* This stream analyser checks the switching rules and changes the backend
Willy Tarreau4de91492010-01-22 19:10:05 +01001116 * if appropriate. The default_backend rule is also considered, then the
1117 * target backend's forced persistence rules are also evaluated last if any.
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001118 * It returns 1 if the processing can continue on next analysers, or zero if it
1119 * either needs more data or wants to immediately abort the request.
1120 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001121static int process_switching_rules(struct stream *s, struct channel *req, int an_bit)
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001122{
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001123 struct persist_rule *prst_rule;
Willy Tarreau192252e2015-04-04 01:47:55 +02001124 struct session *sess = s->sess;
1125 struct proxy *fe = sess->fe;
Willy Tarreau4de91492010-01-22 19:10:05 +01001126
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001127 req->analysers &= ~an_bit;
1128 req->analyse_exp = TICK_ETERNITY;
1129
Willy Tarreau87b09662015-04-03 00:22:06 +02001130 DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001131 now_ms, __FUNCTION__,
1132 s,
1133 req,
1134 req->rex, req->wex,
1135 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001136 req->buf->i,
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001137 req->analysers);
1138
1139 /* now check whether we have some switching rules for this request */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001140 if (!(s->flags & SF_BE_ASSIGNED)) {
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001141 struct switching_rule *rule;
1142
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001143 list_for_each_entry(rule, &fe->switching_rules, list) {
Willy Tarreauf51658d2014-04-23 01:21:56 +02001144 int ret = 1;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001145
Willy Tarreauf51658d2014-04-23 01:21:56 +02001146 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001147 ret = acl_exec_cond(rule->cond, fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Willy Tarreauf51658d2014-04-23 01:21:56 +02001148 ret = acl_pass(ret);
1149 if (rule->cond->pol == ACL_COND_UNLESS)
1150 ret = !ret;
1151 }
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001152
1153 if (ret) {
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01001154 /* If the backend name is dynamic, try to resolve the name.
1155 * If we can't resolve the name, or if any error occurs, break
1156 * the loop and fallback to the default backend.
1157 */
1158 struct proxy *backend;
1159
1160 if (rule->dynamic) {
1161 struct chunk *tmp = get_trash_chunk();
1162 if (!build_logline(s, tmp->str, tmp->size, &rule->be.expr))
1163 break;
Willy Tarreau9e0bb102015-05-26 11:24:42 +02001164 backend = proxy_be_by_name(tmp->str);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01001165 if (!backend)
1166 break;
1167 }
1168 else
1169 backend = rule->be.backend;
1170
Willy Tarreau87b09662015-04-03 00:22:06 +02001171 if (!stream_set_backend(s, backend))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001172 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001173 break;
1174 }
1175 }
1176
1177 /* To ensure correct connection accounting on the backend, we
1178 * have to assign one if it was not set (eg: a listen). This
1179 * measure also takes care of correctly setting the default
1180 * backend if any.
1181 */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001182 if (!(s->flags & SF_BE_ASSIGNED))
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001183 if (!stream_set_backend(s, fe->defbe.be ? fe->defbe.be : s->be))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001184 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001185 }
1186
Willy Tarreaufb356202010-08-03 14:02:05 +02001187 /* we don't want to run the TCP or HTTP filters again if the backend has not changed */
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001188 if (fe == s->be) {
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001189 s->req.analysers &= ~AN_REQ_INSPECT_BE;
1190 s->req.analysers &= ~AN_REQ_HTTP_PROCESS_BE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02001191 s->req.analysers &= ~AN_FLT_START_BE;
Willy Tarreaufb356202010-08-03 14:02:05 +02001192 }
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001193
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001194 /* as soon as we know the backend, we must check if we have a matching forced or ignored
Willy Tarreau87b09662015-04-03 00:22:06 +02001195 * persistence rule, and report that in the stream.
Willy Tarreau4de91492010-01-22 19:10:05 +01001196 */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001197 list_for_each_entry(prst_rule, &s->be->persist_rules, list) {
Willy Tarreau4de91492010-01-22 19:10:05 +01001198 int ret = 1;
1199
1200 if (prst_rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001201 ret = acl_exec_cond(prst_rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Willy Tarreau4de91492010-01-22 19:10:05 +01001202 ret = acl_pass(ret);
1203 if (prst_rule->cond->pol == ACL_COND_UNLESS)
1204 ret = !ret;
1205 }
1206
1207 if (ret) {
1208 /* no rule, or the rule matches */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001209 if (prst_rule->type == PERSIST_TYPE_FORCE) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001210 s->flags |= SF_FORCE_PRST;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001211 } else {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001212 s->flags |= SF_IGNORE_PRST;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001213 }
Willy Tarreau4de91492010-01-22 19:10:05 +01001214 break;
1215 }
1216 }
1217
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001218 return 1;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001219
1220 sw_failed:
1221 /* immediately abort this request in case of allocation failure */
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001222 channel_abort(&s->req);
1223 channel_abort(&s->res);
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001224
Willy Tarreaue7dff022015-04-03 01:14:29 +02001225 if (!(s->flags & SF_ERR_MASK))
1226 s->flags |= SF_ERR_RESOURCE;
1227 if (!(s->flags & SF_FINST_MASK))
1228 s->flags |= SF_FINST_R;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001229
Willy Tarreaueee5b512015-04-03 23:46:31 +02001230 if (s->txn)
1231 s->txn->status = 500;
Christopher Fauletd7c91962015-04-30 11:48:27 +02001232 s->req.analysers &= AN_FLT_END;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001233 s->req.analyse_exp = TICK_ETERNITY;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001234 return 0;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001235}
1236
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001237/* This stream analyser works on a request. It applies all use-server rules on
1238 * it then returns 1. The data must already be present in the buffer otherwise
1239 * they won't match. It always returns 1.
1240 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001241static int process_server_rules(struct stream *s, struct channel *req, int an_bit)
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001242{
1243 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001244 struct session *sess = s->sess;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001245 struct server_rule *rule;
1246
Willy Tarreau87b09662015-04-03 00:22:06 +02001247 DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n",
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001248 now_ms, __FUNCTION__,
1249 s,
1250 req,
1251 req->rex, req->wex,
1252 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001253 req->buf->i + req->buf->o,
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001254 req->analysers);
1255
Willy Tarreaue7dff022015-04-03 01:14:29 +02001256 if (!(s->flags & SF_ASSIGNED)) {
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001257 list_for_each_entry(rule, &px->server_rules, list) {
1258 int ret;
1259
Willy Tarreau192252e2015-04-04 01:47:55 +02001260 ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001261 ret = acl_pass(ret);
1262 if (rule->cond->pol == ACL_COND_UNLESS)
1263 ret = !ret;
1264
1265 if (ret) {
1266 struct server *srv = rule->srv.ptr;
1267
Willy Tarreau892337c2014-05-13 23:41:20 +02001268 if ((srv->state != SRV_ST_STOPPED) ||
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001269 (px->options & PR_O_PERSIST) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +02001270 (s->flags & SF_FORCE_PRST)) {
1271 s->flags |= SF_DIRECT | SF_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001272 s->target = &srv->obj_type;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001273 break;
1274 }
1275 /* if the server is not UP, let's go on with next rules
1276 * just in case another one is suited.
1277 */
1278 }
1279 }
1280 }
1281
1282 req->analysers &= ~an_bit;
1283 req->analyse_exp = TICK_ETERNITY;
1284 return 1;
1285}
1286
Emeric Brun1d33b292010-01-04 15:47:17 +01001287/* This stream analyser works on a request. It applies all sticking rules on
1288 * it then returns 1. The data must already be present in the buffer otherwise
1289 * they won't match. It always returns 1.
1290 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001291static int process_sticking_rules(struct stream *s, struct channel *req, int an_bit)
Emeric Brun1d33b292010-01-04 15:47:17 +01001292{
1293 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001294 struct session *sess = s->sess;
Emeric Brun1d33b292010-01-04 15:47:17 +01001295 struct sticking_rule *rule;
1296
Willy Tarreau87b09662015-04-03 00:22:06 +02001297 DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
Emeric Brun1d33b292010-01-04 15:47:17 +01001298 now_ms, __FUNCTION__,
1299 s,
1300 req,
1301 req->rex, req->wex,
1302 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001303 req->buf->i,
Emeric Brun1d33b292010-01-04 15:47:17 +01001304 req->analysers);
1305
1306 list_for_each_entry(rule, &px->sticking_rules, list) {
1307 int ret = 1 ;
1308 int i;
1309
Willy Tarreau9667a802013-12-09 12:52:13 +01001310 /* Only the first stick store-request of each table is applied
1311 * and other ones are ignored. The purpose is to allow complex
1312 * configurations which look for multiple entries by decreasing
1313 * order of precision and to stop at the first which matches.
1314 * An example could be a store of the IP address from an HTTP
1315 * header first, then from the source if not found.
1316 */
Emeric Brun1d33b292010-01-04 15:47:17 +01001317 for (i = 0; i < s->store_count; i++) {
1318 if (rule->table.t == s->store[i].table)
1319 break;
1320 }
1321
1322 if (i != s->store_count)
1323 continue;
1324
1325 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001326 ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001327 ret = acl_pass(ret);
1328 if (rule->cond->pol == ACL_COND_UNLESS)
1329 ret = !ret;
1330 }
1331
1332 if (ret) {
1333 struct stktable_key *key;
1334
Willy Tarreau192252e2015-04-04 01:47:55 +02001335 key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr, NULL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001336 if (!key)
1337 continue;
1338
1339 if (rule->flags & STK_IS_MATCH) {
1340 struct stksess *ts;
1341
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001342 if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001343 if (!(s->flags & SF_ASSIGNED)) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001344 struct eb32_node *node;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001345 void *ptr;
Emeric Brun1d33b292010-01-04 15:47:17 +01001346
1347 /* srv found in table */
Willy Tarreau13c29de2010-06-06 16:40:39 +02001348 ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID);
1349 node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id));
Emeric Brun1d33b292010-01-04 15:47:17 +01001350 if (node) {
1351 struct server *srv;
1352
1353 srv = container_of(node, struct server, conf.id);
Willy Tarreau892337c2014-05-13 23:41:20 +02001354 if ((srv->state != SRV_ST_STOPPED) ||
Willy Tarreau4de91492010-01-22 19:10:05 +01001355 (px->options & PR_O_PERSIST) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +02001356 (s->flags & SF_FORCE_PRST)) {
1357 s->flags |= SF_DIRECT | SF_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001358 s->target = &srv->obj_type;
Emeric Brun1d33b292010-01-04 15:47:17 +01001359 }
1360 }
1361 }
Emeric Brun85e77c72010-09-23 18:16:52 +02001362 stktable_touch(rule->table.t, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001363 }
1364 }
1365 if (rule->flags & STK_IS_STORE) {
1366 if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
1367 struct stksess *ts;
1368
1369 ts = stksess_new(rule->table.t, key);
1370 if (ts) {
1371 s->store[s->store_count].table = rule->table.t;
1372 s->store[s->store_count++].ts = ts;
1373 }
1374 }
1375 }
1376 }
1377 }
1378
1379 req->analysers &= ~an_bit;
1380 req->analyse_exp = TICK_ETERNITY;
1381 return 1;
1382}
1383
1384/* This stream analyser works on a response. It applies all store rules on it
1385 * then returns 1. The data must already be present in the buffer otherwise
1386 * they won't match. It always returns 1.
1387 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001388static int process_store_rules(struct stream *s, struct channel *rep, int an_bit)
Emeric Brun1d33b292010-01-04 15:47:17 +01001389{
1390 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001391 struct session *sess = s->sess;
Emeric Brun1d33b292010-01-04 15:47:17 +01001392 struct sticking_rule *rule;
1393 int i;
Willy Tarreau9667a802013-12-09 12:52:13 +01001394 int nbreq = s->store_count;
Emeric Brun1d33b292010-01-04 15:47:17 +01001395
Willy Tarreau87b09662015-04-03 00:22:06 +02001396 DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
Emeric Brun1d33b292010-01-04 15:47:17 +01001397 now_ms, __FUNCTION__,
1398 s,
Willy Tarreau2e2b3eb2010-02-09 20:55:44 +01001399 rep,
1400 rep->rex, rep->wex,
1401 rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001402 rep->buf->i,
Willy Tarreau2e2b3eb2010-02-09 20:55:44 +01001403 rep->analysers);
Emeric Brun1d33b292010-01-04 15:47:17 +01001404
1405 list_for_each_entry(rule, &px->storersp_rules, list) {
1406 int ret = 1 ;
Emeric Brun1d33b292010-01-04 15:47:17 +01001407
Willy Tarreau9667a802013-12-09 12:52:13 +01001408 /* Only the first stick store-response of each table is applied
1409 * and other ones are ignored. The purpose is to allow complex
1410 * configurations which look for multiple entries by decreasing
1411 * order of precision and to stop at the first which matches.
1412 * An example could be a store of a set-cookie value, with a
1413 * fallback to a parameter found in a 302 redirect.
1414 *
1415 * The store-response rules are not allowed to override the
1416 * store-request rules for the same table, but they may coexist.
1417 * Thus we can have up to one store-request entry and one store-
1418 * response entry for the same table at any time.
1419 */
1420 for (i = nbreq; i < s->store_count; i++) {
1421 if (rule->table.t == s->store[i].table)
1422 break;
1423 }
1424
1425 /* skip existing entries for this table */
1426 if (i < s->store_count)
1427 continue;
1428
Emeric Brun1d33b292010-01-04 15:47:17 +01001429 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001430 ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001431 ret = acl_pass(ret);
1432 if (rule->cond->pol == ACL_COND_UNLESS)
1433 ret = !ret;
1434 }
1435
1436 if (ret) {
1437 struct stktable_key *key;
1438
Willy Tarreau192252e2015-04-04 01:47:55 +02001439 key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr, NULL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001440 if (!key)
1441 continue;
1442
Willy Tarreau37e340c2013-12-06 23:05:21 +01001443 if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001444 struct stksess *ts;
1445
1446 ts = stksess_new(rule->table.t, key);
1447 if (ts) {
1448 s->store[s->store_count].table = rule->table.t;
Emeric Brun1d33b292010-01-04 15:47:17 +01001449 s->store[s->store_count++].ts = ts;
1450 }
1451 }
1452 }
1453 }
1454
1455 /* process store request and store response */
1456 for (i = 0; i < s->store_count; i++) {
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001457 struct stksess *ts;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001458 void *ptr;
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001459
Willy Tarreauc93cd162014-05-13 15:54:22 +02001460 if (objt_server(s->target) && objt_server(s->target)->flags & SRV_F_NON_STICK) {
Simon Hormanfa461682011-06-25 09:39:49 +09001461 stksess_free(s->store[i].table, s->store[i].ts);
1462 s->store[i].ts = NULL;
1463 continue;
1464 }
1465
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001466 ts = stktable_lookup(s->store[i].table, s->store[i].ts);
1467 if (ts) {
1468 /* the entry already existed, we can free ours */
Emeric Brun85e77c72010-09-23 18:16:52 +02001469 stktable_touch(s->store[i].table, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001470 stksess_free(s->store[i].table, s->store[i].ts);
Emeric Brun1d33b292010-01-04 15:47:17 +01001471 }
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001472 else
Emeric Brun85e77c72010-09-23 18:16:52 +02001473 ts = stktable_store(s->store[i].table, s->store[i].ts, 1);
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001474
1475 s->store[i].ts = NULL;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001476 ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID);
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001477 stktable_data_cast(ptr, server_id) = objt_server(s->target)->puid;
Emeric Brun1d33b292010-01-04 15:47:17 +01001478 }
Willy Tarreau2a164ee2010-06-18 09:57:45 +02001479 s->store_count = 0; /* everything is stored */
Emeric Brun1d33b292010-01-04 15:47:17 +01001480
1481 rep->analysers &= ~an_bit;
1482 rep->analyse_exp = TICK_ETERNITY;
1483 return 1;
1484}
1485
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001486/* This macro is very specific to the function below. See the comments in
Willy Tarreau87b09662015-04-03 00:22:06 +02001487 * process_stream() below to understand the logic and the tests.
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001488 */
1489#define UPDATE_ANALYSERS(real, list, back, flag) { \
1490 list = (((list) & ~(flag)) | ~(back)) & (real); \
1491 back = real; \
1492 if (!(list)) \
1493 break; \
1494 if (((list) ^ ((list) & ((list) - 1))) < (flag)) \
1495 continue; \
1496}
1497
Christopher Fauleta9215b72016-05-11 17:06:28 +02001498/* These 2 following macros call an analayzer for the specified channel if the
1499 * right flag is set. The first one is used for "filterable" analyzers. If a
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001500 * stream has some registered filters, pre and post analyaze callbacks are
1501 * called. The second are used for other analyzers (AN_FLT_* and
Christopher Fauleta9215b72016-05-11 17:06:28 +02001502 * AN_REQ/RES_HTTP_XFER_BODY) */
1503#define FLT_ANALYZE(strm, chn, fun, list, back, flag, ...) \
1504 { \
1505 if ((list) & (flag)) { \
1506 if (HAS_FILTERS(strm)) { \
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001507 if (!flt_pre_analyze((strm), (chn), (flag))) \
Christopher Fauleta9215b72016-05-11 17:06:28 +02001508 break; \
1509 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1510 break; \
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001511 if (!flt_post_analyze((strm), (chn), (flag))) \
1512 break; \
Christopher Fauleta9215b72016-05-11 17:06:28 +02001513 } \
1514 else { \
1515 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1516 break; \
1517 } \
1518 UPDATE_ANALYSERS((chn)->analysers, (list), \
1519 (back), (flag)); \
1520 } \
1521 }
1522
1523#define ANALYZE(strm, chn, fun, list, back, flag, ...) \
1524 { \
1525 if ((list) & (flag)) { \
1526 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1527 break; \
1528 UPDATE_ANALYSERS((chn)->analysers, (list), \
1529 (back), (flag)); \
1530 } \
1531 }
1532
Willy Tarreau87b09662015-04-03 00:22:06 +02001533/* Processes the client, server, request and response jobs of a stream task,
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001534 * then puts it back to the wait queue in a clean state, or cleans up its
1535 * resources if it must be deleted. Returns in <next> the date the task wants
1536 * to be woken up, or TICK_ETERNITY. In order not to call all functions for
1537 * nothing too many times, the request and response buffers flags are monitored
1538 * and each function is called only if at least another function has changed at
1539 * least one flag it is interested in.
1540 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001541struct task *process_stream(struct task *t)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001542{
Willy Tarreau827aee92011-03-10 16:55:02 +01001543 struct server *srv;
Willy Tarreau87b09662015-04-03 00:22:06 +02001544 struct stream *s = t->context;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02001545 struct session *sess = s->sess;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001546 unsigned int rqf_last, rpf_last;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001547 unsigned int rq_prod_last, rq_cons_last;
1548 unsigned int rp_cons_last, rp_prod_last;
Willy Tarreau576507f2010-01-07 00:09:04 +01001549 unsigned int req_ana_back;
Willy Tarreau8f128b42014-11-28 15:07:47 +01001550 struct channel *req, *res;
1551 struct stream_interface *si_f, *si_b;
1552
1553 req = &s->req;
1554 res = &s->res;
1555
1556 si_f = &s->si[0];
1557 si_b = &s->si[1];
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001558
1559 //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
Willy Tarreau8f128b42014-11-28 15:07:47 +01001560 // si_f->state, si_b->state, si_b->err_type, req->flags, res->flags);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001561
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001562 /* this data may be no longer valid, clear it */
Willy Tarreaueee5b512015-04-03 23:46:31 +02001563 if (s->txn)
1564 memset(&s->txn->auth, 0, sizeof(s->txn->auth));
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001565
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02001566 /* This flag must explicitly be set every time */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001567 req->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE);
1568 res->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001569
1570 /* Keep a copy of req/rep flags so that we can detect shutdowns */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001571 rqf_last = req->flags & ~CF_MASK_ANALYSER;
1572 rpf_last = res->flags & ~CF_MASK_ANALYSER;
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001573
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001574 /* we don't want the stream interface functions to recursively wake us up */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001575 si_f->flags |= SI_FL_DONT_WAKE;
1576 si_b->flags |= SI_FL_DONT_WAKE;
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001577
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001578 /* 1a: Check for low level timeouts if needed. We just set a flag on
1579 * stream interfaces when their timeouts have expired.
1580 */
1581 if (unlikely(t->state & TASK_WOKEN_TIMER)) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001582 stream_int_check_timeouts(si_f);
1583 stream_int_check_timeouts(si_b);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001584
Willy Tarreau8263d2b2012-08-28 00:06:31 +02001585 /* check channel timeouts, and close the corresponding stream interfaces
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001586 * for future reads or writes. Note: this will also concern upper layers
1587 * but we do not touch any other flag. We must be careful and correctly
1588 * detect state changes when calling them.
1589 */
1590
Willy Tarreau8f128b42014-11-28 15:07:47 +01001591 channel_check_timeouts(req);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001592
Willy Tarreau8f128b42014-11-28 15:07:47 +01001593 if (unlikely((req->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
1594 si_b->flags |= SI_FL_NOLINGER;
1595 si_shutw(si_b);
Willy Tarreau14641402009-12-29 14:49:56 +01001596 }
1597
Willy Tarreau8f128b42014-11-28 15:07:47 +01001598 if (unlikely((req->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
1599 if (si_f->flags & SI_FL_NOHALF)
1600 si_f->flags |= SI_FL_NOLINGER;
1601 si_shutr(si_f);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02001602 }
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001603
Willy Tarreau8f128b42014-11-28 15:07:47 +01001604 channel_check_timeouts(res);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001605
Willy Tarreau8f128b42014-11-28 15:07:47 +01001606 if (unlikely((res->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
1607 si_f->flags |= SI_FL_NOLINGER;
1608 si_shutw(si_f);
Willy Tarreau14641402009-12-29 14:49:56 +01001609 }
1610
Willy Tarreau8f128b42014-11-28 15:07:47 +01001611 if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
1612 if (si_b->flags & SI_FL_NOHALF)
1613 si_b->flags |= SI_FL_NOLINGER;
1614 si_shutr(si_b);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02001615 }
Willy Tarreau798f4322012-11-08 14:49:17 +01001616
1617 /* Once in a while we're woken up because the task expires. But
1618 * this does not necessarily mean that a timeout has been reached.
Willy Tarreau87b09662015-04-03 00:22:06 +02001619 * So let's not run a whole stream processing if only an expiration
Willy Tarreau798f4322012-11-08 14:49:17 +01001620 * timeout needs to be refreshed.
1621 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001622 if (!((req->flags | res->flags) &
Willy Tarreau798f4322012-11-08 14:49:17 +01001623 (CF_SHUTR|CF_READ_ACTIVITY|CF_READ_TIMEOUT|CF_SHUTW|
1624 CF_WRITE_ACTIVITY|CF_WRITE_TIMEOUT|CF_ANA_TIMEOUT)) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01001625 !((si_f->flags | si_b->flags) & (SI_FL_EXP|SI_FL_ERR)) &&
Willy Tarreau5fb04712016-05-04 10:18:37 +02001626 ((t->state & TASK_WOKEN_ANY) == TASK_WOKEN_TIMER)) {
1627 si_f->flags &= ~SI_FL_DONT_WAKE;
1628 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau798f4322012-11-08 14:49:17 +01001629 goto update_exp_and_leave;
Willy Tarreau5fb04712016-05-04 10:18:37 +02001630 }
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001631 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001632
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001633 /* below we may emit error messages so we have to ensure that we have
1634 * our buffers properly allocated.
1635 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001636 if (!stream_alloc_work_buffer(s)) {
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001637 /* No buffer available, we've been subscribed to the list of
1638 * buffer waiters, let's wait for our turn.
1639 */
Willy Tarreau5fb04712016-05-04 10:18:37 +02001640 si_f->flags &= ~SI_FL_DONT_WAKE;
1641 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001642 goto update_exp_and_leave;
1643 }
1644
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001645 /* 1b: check for low-level errors reported at the stream interface.
1646 * First we check if it's a retryable error (in which case we don't
1647 * want to tell the buffer). Otherwise we report the error one level
1648 * upper by setting flags into the buffers. Note that the side towards
1649 * the client cannot have connect (hence retryable) errors. Also, the
1650 * connection setup code must be able to deal with any type of abort.
1651 */
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001652 srv = objt_server(s->target);
Willy Tarreau8f128b42014-11-28 15:07:47 +01001653 if (unlikely(si_f->flags & SI_FL_ERR)) {
1654 if (si_f->state == SI_ST_EST || si_f->state == SI_ST_DIS) {
1655 si_shutr(si_f);
1656 si_shutw(si_f);
1657 stream_int_report_error(si_f);
1658 if (!(req->analysers) && !(res->analysers)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001659 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001660 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001661 if (srv)
1662 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001663 if (!(s->flags & SF_ERR_MASK))
1664 s->flags |= SF_ERR_CLICL;
1665 if (!(s->flags & SF_FINST_MASK))
1666 s->flags |= SF_FINST_D;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001667 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001668 }
1669 }
1670
Willy Tarreau8f128b42014-11-28 15:07:47 +01001671 if (unlikely(si_b->flags & SI_FL_ERR)) {
1672 if (si_b->state == SI_ST_EST || si_b->state == SI_ST_DIS) {
1673 si_shutr(si_b);
1674 si_shutw(si_b);
1675 stream_int_report_error(si_b);
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001676 s->be->be_counters.failed_resp++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001677 if (srv)
1678 srv->counters.failed_resp++;
Willy Tarreau8f128b42014-11-28 15:07:47 +01001679 if (!(req->analysers) && !(res->analysers)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001680 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001681 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001682 if (srv)
1683 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001684 if (!(s->flags & SF_ERR_MASK))
1685 s->flags |= SF_ERR_SRVCL;
1686 if (!(s->flags & SF_FINST_MASK))
1687 s->flags |= SF_FINST_D;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001688 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001689 }
1690 /* note: maybe we should process connection errors here ? */
1691 }
1692
Willy Tarreau8f128b42014-11-28 15:07:47 +01001693 if (si_b->state == SI_ST_CON) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001694 /* we were trying to establish a connection on the server side,
1695 * maybe it succeeded, maybe it failed, maybe we timed out, ...
1696 */
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01001697 if (unlikely(!sess_update_st_con_tcp(s)))
1698 sess_update_st_cer(s);
Willy Tarreau8f128b42014-11-28 15:07:47 +01001699 else if (si_b->state == SI_ST_EST)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01001700 sess_establish(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001701
1702 /* state is now one of SI_ST_CON (still in progress), SI_ST_EST
1703 * (established), SI_ST_DIS (abort), SI_ST_CLO (last error),
1704 * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors.
1705 */
1706 }
1707
Willy Tarreau8f128b42014-11-28 15:07:47 +01001708 rq_prod_last = si_f->state;
1709 rq_cons_last = si_b->state;
1710 rp_cons_last = si_f->state;
1711 rp_prod_last = si_b->state;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001712
1713 resync_stream_interface:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001714 /* Check for connection closure */
1715
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001716 DPRINTF(stderr,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001717 "[%u] %s:%d: task=%p s=%p, sfl=0x%08x, rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d, cet=0x%x set=0x%x retr=%d\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001718 now_ms, __FUNCTION__, __LINE__,
1719 t,
1720 s, s->flags,
Willy Tarreau8f128b42014-11-28 15:07:47 +01001721 req, res,
1722 req->rex, res->wex,
1723 req->flags, res->flags,
1724 req->buf->i, req->buf->o, res->buf->i, res->buf->o, si_f->state, si_b->state,
1725 si_f->err_type, si_b->err_type,
1726 si_b->conn_retries);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001727
1728 /* nothing special to be done on client side */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001729 if (unlikely(si_f->state == SI_ST_DIS))
1730 si_f->state = SI_ST_CLO;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001731
1732 /* When a server-side connection is released, we have to count it and
1733 * check for pending connections on this server.
1734 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001735 if (unlikely(si_b->state == SI_ST_DIS)) {
1736 si_b->state = SI_ST_CLO;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001737 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001738 if (srv) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001739 if (s->flags & SF_CURR_SESS) {
1740 s->flags &= ~SF_CURR_SESS;
Willy Tarreau827aee92011-03-10 16:55:02 +01001741 srv->cur_sess--;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001742 }
1743 sess_change_server(s, NULL);
Willy Tarreau827aee92011-03-10 16:55:02 +01001744 if (may_dequeue_tasks(srv, s->be))
1745 process_srv_queue(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001746 }
1747 }
1748
1749 /*
1750 * Note: of the transient states (REQ, CER, DIS), only REQ may remain
1751 * at this point.
1752 */
1753
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001754 resync_request:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001755 /* Analyse request */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001756 if (((req->flags & ~rqf_last) & CF_MASK_ANALYSER) ||
1757 ((req->flags ^ rqf_last) & CF_MASK_STATIC) ||
1758 si_f->state != rq_prod_last ||
1759 si_b->state != rq_cons_last ||
Thierry FOURNIER2e05a8c2014-11-24 14:49:56 +01001760 s->task->state & TASK_WOKEN_MSG) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001761 unsigned int flags = req->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001762
Willy Tarreau8f128b42014-11-28 15:07:47 +01001763 if (si_f->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001764 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001765 unsigned int ana_list;
1766 unsigned int ana_back;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001767
Willy Tarreau90deb182010-01-07 00:20:41 +01001768 /* it's up to the analysers to stop new connections,
1769 * disable reading or closing. Note: if an analyser
1770 * disables any of these bits, it is responsible for
1771 * enabling them again when it disables itself, so
1772 * that other analysers are called in similar conditions.
1773 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001774 channel_auto_read(req);
1775 channel_auto_connect(req);
1776 channel_auto_close(req);
Willy Tarreauedcf6682008-11-30 23:15:34 +01001777
1778 /* We will call all analysers for which a bit is set in
Willy Tarreau8f128b42014-11-28 15:07:47 +01001779 * req->analysers, following the bit order from LSB
Willy Tarreauedcf6682008-11-30 23:15:34 +01001780 * to MSB. The analysers must remove themselves from
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001781 * the list when not needed. Any analyser may return 0
1782 * to break out of the loop, either because of missing
1783 * data to take a decision, or because it decides to
Willy Tarreau87b09662015-04-03 00:22:06 +02001784 * kill the stream. We loop at least once through each
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001785 * analyser, and we may loop again if other analysers
1786 * are added in the middle.
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001787 *
1788 * We build a list of analysers to run. We evaluate all
1789 * of these analysers in the order of the lower bit to
1790 * the higher bit. This ordering is very important.
1791 * An analyser will often add/remove other analysers,
1792 * including itself. Any changes to itself have no effect
1793 * on the loop. If it removes any other analysers, we
1794 * want those analysers not to be called anymore during
1795 * this loop. If it adds an analyser that is located
1796 * after itself, we want it to be scheduled for being
1797 * processed during the loop. If it adds an analyser
1798 * which is located before it, we want it to switch to
1799 * it immediately, even if it has already been called
1800 * once but removed since.
1801 *
1802 * In order to achieve this, we compare the analyser
1803 * list after the call with a copy of it before the
1804 * call. The work list is fed with analyser bits that
1805 * appeared during the call. Then we compare previous
1806 * work list with the new one, and check the bits that
1807 * appeared. If the lowest of these bits is lower than
1808 * the current bit, it means we have enabled a previous
1809 * analyser and must immediately loop again.
Willy Tarreauedcf6682008-11-30 23:15:34 +01001810 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001811
Willy Tarreau8f128b42014-11-28 15:07:47 +01001812 ana_list = ana_back = req->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001813 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001814 /* Warning! ensure that analysers are always placed in ascending order! */
Christopher Fauleta9215b72016-05-11 17:06:28 +02001815 ANALYZE (s, req, flt_start_analyze, ana_list, ana_back, AN_FLT_START_FE);
1816 FLT_ANALYZE(s, req, tcp_inspect_request, ana_list, ana_back, AN_REQ_INSPECT_FE);
1817 FLT_ANALYZE(s, req, http_wait_for_request, ana_list, ana_back, AN_REQ_WAIT_HTTP);
1818 FLT_ANALYZE(s, req, http_wait_for_request_body, ana_list, ana_back, AN_REQ_HTTP_BODY);
1819 FLT_ANALYZE(s, req, http_process_req_common, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE, sess->fe);
1820 FLT_ANALYZE(s, req, process_switching_rules, ana_list, ana_back, AN_REQ_SWITCHING_RULES);
1821 ANALYZE (s, req, flt_start_analyze, ana_list, ana_back, AN_FLT_START_BE);
1822 FLT_ANALYZE(s, req, tcp_inspect_request, ana_list, ana_back, AN_REQ_INSPECT_BE);
1823 FLT_ANALYZE(s, req, http_process_req_common, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE, s->be);
1824 FLT_ANALYZE(s, req, http_process_tarpit, ana_list, ana_back, AN_REQ_HTTP_TARPIT);
1825 FLT_ANALYZE(s, req, process_server_rules, ana_list, ana_back, AN_REQ_SRV_RULES);
1826 FLT_ANALYZE(s, req, http_process_request, ana_list, ana_back, AN_REQ_HTTP_INNER);
1827 FLT_ANALYZE(s, req, tcp_persist_rdp_cookie, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE);
1828 FLT_ANALYZE(s, req, process_sticking_rules, ana_list, ana_back, AN_REQ_STICKING_RULES);
1829 ANALYZE (s, req, flt_analyze_http_headers, ana_list, ana_back, AN_FLT_HTTP_HDRS);
1830 ANALYZE (s, req, flt_xfer_data, ana_list, ana_back, AN_FLT_XFER_DATA);
1831 ANALYZE (s, req, http_request_forward_body, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY);
1832 ANALYZE (s, req, flt_end_analyze, ana_list, ana_back, AN_FLT_END);
Willy Tarreaue34070e2010-01-08 00:32:27 +01001833 break;
1834 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001835 }
Willy Tarreau84455332009-03-15 22:34:05 +01001836
Willy Tarreau8f128b42014-11-28 15:07:47 +01001837 rq_prod_last = si_f->state;
1838 rq_cons_last = si_b->state;
1839 req->flags &= ~CF_WAKE_ONCE;
1840 rqf_last = req->flags;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001841
Willy Tarreau8f128b42014-11-28 15:07:47 +01001842 if ((req->flags ^ flags) & CF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001843 goto resync_request;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001844 }
1845
Willy Tarreau576507f2010-01-07 00:09:04 +01001846 /* we'll monitor the request analysers while parsing the response,
1847 * because some response analysers may indirectly enable new request
1848 * analysers (eg: HTTP keep-alive).
1849 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001850 req_ana_back = req->analysers;
Willy Tarreau576507f2010-01-07 00:09:04 +01001851
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001852 resync_response:
1853 /* Analyse response */
1854
Willy Tarreau8f128b42014-11-28 15:07:47 +01001855 if (((res->flags & ~rpf_last) & CF_MASK_ANALYSER) ||
1856 (res->flags ^ rpf_last) & CF_MASK_STATIC ||
1857 si_f->state != rp_cons_last ||
1858 si_b->state != rp_prod_last ||
Thierry FOURNIER2e05a8c2014-11-24 14:49:56 +01001859 s->task->state & TASK_WOKEN_MSG) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001860 unsigned int flags = res->flags;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001861
Willy Tarreau8f128b42014-11-28 15:07:47 +01001862 if ((res->flags & CF_MASK_ANALYSER) &&
1863 (res->analysers & AN_REQ_ALL)) {
Willy Tarreau0499e352010-12-17 07:13:42 +01001864 /* Due to HTTP pipelining, the HTTP request analyser might be waiting
1865 * for some free space in the response buffer, so we might need to call
1866 * it when something changes in the response buffer, but still we pass
1867 * it the request buffer. Note that the SI state might very well still
1868 * be zero due to us returning a flow of redirects!
1869 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001870 res->analysers &= ~AN_REQ_ALL;
1871 req->flags |= CF_WAKE_ONCE;
Willy Tarreau0499e352010-12-17 07:13:42 +01001872 }
1873
Willy Tarreau8f128b42014-11-28 15:07:47 +01001874 if (si_b->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001875 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001876 unsigned int ana_list;
1877 unsigned int ana_back;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001878
Willy Tarreau90deb182010-01-07 00:20:41 +01001879 /* it's up to the analysers to stop disable reading or
1880 * closing. Note: if an analyser disables any of these
1881 * bits, it is responsible for enabling them again when
1882 * it disables itself, so that other analysers are called
1883 * in similar conditions.
1884 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001885 channel_auto_read(res);
1886 channel_auto_close(res);
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001887
1888 /* We will call all analysers for which a bit is set in
Willy Tarreau8f128b42014-11-28 15:07:47 +01001889 * res->analysers, following the bit order from LSB
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001890 * to MSB. The analysers must remove themselves from
1891 * the list when not needed. Any analyser may return 0
1892 * to break out of the loop, either because of missing
1893 * data to take a decision, or because it decides to
Willy Tarreau87b09662015-04-03 00:22:06 +02001894 * kill the stream. We loop at least once through each
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001895 * analyser, and we may loop again if other analysers
1896 * are added in the middle.
1897 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001898
Willy Tarreau8f128b42014-11-28 15:07:47 +01001899 ana_list = ana_back = res->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001900 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001901 /* Warning! ensure that analysers are always placed in ascending order! */
Christopher Fauleta9215b72016-05-11 17:06:28 +02001902 ANALYZE (s, res, flt_start_analyze, ana_list, ana_back, AN_FLT_START_FE);
1903 ANALYZE (s, res, flt_start_analyze, ana_list, ana_back, AN_FLT_START_BE);
1904 FLT_ANALYZE(s, res, tcp_inspect_response, ana_list, ana_back, AN_RES_INSPECT);
1905 FLT_ANALYZE(s, res, http_wait_for_response, ana_list, ana_back, AN_RES_WAIT_HTTP);
1906 FLT_ANALYZE(s, res, process_store_rules, ana_list, ana_back, AN_RES_STORE_RULES);
1907 FLT_ANALYZE(s, res, http_process_res_common, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE, s->be);
1908 ANALYZE (s, res, flt_analyze_http_headers, ana_list, ana_back, AN_FLT_HTTP_HDRS);
1909 ANALYZE (s, res, flt_xfer_data, ana_list, ana_back, AN_FLT_XFER_DATA);
1910 ANALYZE (s, res, http_response_forward_body, ana_list, ana_back, AN_RES_HTTP_XFER_BODY);
1911 ANALYZE (s, res, flt_end_analyze, ana_list, ana_back, AN_FLT_END);
Willy Tarreaue34070e2010-01-08 00:32:27 +01001912 break;
1913 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001914 }
1915
Willy Tarreau8f128b42014-11-28 15:07:47 +01001916 rp_cons_last = si_f->state;
1917 rp_prod_last = si_b->state;
1918 rpf_last = res->flags;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001919
Willy Tarreau8f128b42014-11-28 15:07:47 +01001920 if ((res->flags ^ flags) & CF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001921 goto resync_response;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001922 }
1923
Willy Tarreau576507f2010-01-07 00:09:04 +01001924 /* maybe someone has added some request analysers, so we must check and loop */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001925 if (req->analysers & ~req_ana_back)
Willy Tarreau576507f2010-01-07 00:09:04 +01001926 goto resync_request;
1927
Willy Tarreau8f128b42014-11-28 15:07:47 +01001928 if ((req->flags & ~rqf_last) & CF_MASK_ANALYSER)
Willy Tarreau0499e352010-12-17 07:13:42 +01001929 goto resync_request;
1930
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001931 /* FIXME: here we should call protocol handlers which rely on
1932 * both buffers.
1933 */
1934
1935
1936 /*
Willy Tarreau87b09662015-04-03 00:22:06 +02001937 * Now we propagate unhandled errors to the stream. Normally
Willy Tarreauae526782010-03-04 20:34:23 +01001938 * we're just in a data phase here since it means we have not
1939 * seen any analyser who could set an error status.
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001940 */
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001941 srv = objt_server(s->target);
Willy Tarreaue7dff022015-04-03 01:14:29 +02001942 if (unlikely(!(s->flags & SF_ERR_MASK))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001943 if (req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001944 /* Report it if the client got an error or a read timeout expired */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001945 req->analysers = 0;
1946 if (req->flags & CF_READ_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001947 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001948 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001949 if (srv)
1950 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001951 s->flags |= SF_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01001952 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001953 else if (req->flags & CF_READ_TIMEOUT) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001954 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001955 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001956 if (srv)
1957 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001958 s->flags |= SF_ERR_CLITO;
Willy Tarreauae526782010-03-04 20:34:23 +01001959 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001960 else if (req->flags & CF_WRITE_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001961 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001962 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001963 if (srv)
1964 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001965 s->flags |= SF_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001966 }
1967 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001968 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001969 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001970 if (srv)
1971 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001972 s->flags |= SF_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001973 }
Willy Tarreau84455332009-03-15 22:34:05 +01001974 sess_set_term_flags(s);
1975 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001976 else if (res->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001977 /* Report it if the server got an error or a read timeout expired */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001978 res->analysers = 0;
1979 if (res->flags & CF_READ_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001980 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001981 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001982 if (srv)
1983 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001984 s->flags |= SF_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001985 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001986 else if (res->flags & CF_READ_TIMEOUT) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001987 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001988 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001989 if (srv)
1990 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001991 s->flags |= SF_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001992 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001993 else if (res->flags & CF_WRITE_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001994 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001995 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001996 if (srv)
1997 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001998 s->flags |= SF_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01001999 }
2000 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002001 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002002 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01002003 if (srv)
2004 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002005 s->flags |= SF_ERR_CLITO;
Willy Tarreauae526782010-03-04 20:34:23 +01002006 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002007 sess_set_term_flags(s);
2008 }
Willy Tarreau84455332009-03-15 22:34:05 +01002009 }
2010
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002011 /*
2012 * Here we take care of forwarding unhandled data. This also includes
2013 * connection establishments and shutdown requests.
2014 */
2015
2016
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002017 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02002018 * everything. We configure the buffer to forward indefinitely.
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002019 * Note that we're checking CF_SHUTR_NOW as an indication of a possible
Willy Tarreau8263d2b2012-08-28 00:06:31 +02002020 * recent call to channel_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002021 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002022 if (unlikely(!req->analysers &&
2023 !(req->flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
2024 (si_f->state >= SI_ST_EST) &&
2025 (req->to_forward != CHN_INFINITE_FORWARD))) {
Willy Tarreaub31c9712012-11-11 23:05:39 +01002026 /* This buffer is freewheeling, there's no analyser
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002027 * attached to it. If any data are left in, we'll permit them to
2028 * move.
2029 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002030 channel_auto_read(req);
2031 channel_auto_connect(req);
2032 channel_auto_close(req);
2033 buffer_flush(req->buf);
Willy Tarreau5bd8c372009-01-19 00:32:22 +01002034
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01002035 /* We'll let data flow between the producer (if still connected)
2036 * to the consumer (which might possibly not be connected yet).
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002037 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002038 if (!(req->flags & (CF_SHUTR|CF_SHUTW_NOW)))
Willy Tarreau8bf242b2016-05-04 14:05:58 +02002039 channel_forward_forever(req);
Willy Tarreau42529c32015-07-09 18:38:57 +02002040
2041 /* Just in order to support fetching HTTP contents after start
2042 * of forwarding when the HTTP forwarding analyser is not used,
2043 * we simply reset msg->sov so that HTTP rewinding points to the
2044 * headers.
2045 */
2046 if (s->txn)
2047 s->txn->req.sov = s->txn->req.eoh + s->txn->req.eol - req->buf->o;
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002048 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01002049
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002050 /* check if it is wise to enable kernel splicing to forward request data */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002051 if (!(req->flags & (CF_KERN_SPLICING|CF_SHUTR)) &&
2052 req->to_forward &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002053 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002054 (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->rcv_pipe) &&
2055 (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->snd_pipe) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002056 (pipes_used < global.maxpipes) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002057 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
2058 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002059 (req->flags & CF_STREAMER_FAST)))) {
2060 req->flags |= CF_KERN_SPLICING;
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002061 }
2062
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002063 /* reflect what the L7 analysers have seen last */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002064 rqf_last = req->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002065
2066 /*
2067 * Now forward all shutdown requests between both sides of the buffer
2068 */
2069
Willy Tarreau520d95e2009-09-19 21:04:57 +02002070 /* first, let's check if the request buffer needs to shutdown(write), which may
2071 * happen either because the input is closed or because we want to force a close
Willy Tarreau05cdd962014-05-10 14:30:07 +02002072 * once the server has begun to respond. If a half-closed timeout is set, we adjust
2073 * the other side's timeout as well.
Willy Tarreau520d95e2009-09-19 21:04:57 +02002074 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002075 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) ==
Willy Tarreau05cdd962014-05-10 14:30:07 +02002076 (CF_AUTO_CLOSE|CF_SHUTR))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002077 channel_shutw_now(req);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002078 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002079
2080 /* shutdown(write) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002081 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
2082 channel_is_empty(req))) {
2083 if (req->flags & CF_READ_ERROR)
2084 si_b->flags |= SI_FL_NOLINGER;
2085 si_shutw(si_b);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002086 if (tick_isset(s->be->timeout.serverfin)) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002087 res->rto = s->be->timeout.serverfin;
2088 res->rex = tick_add(now_ms, res->rto);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002089 }
Willy Tarreau8615c2a2013-06-21 08:20:19 +02002090 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002091
2092 /* shutdown(write) done on server side, we must stop the client too */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002093 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW &&
2094 !req->analysers))
2095 channel_shutr_now(req);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002096
2097 /* shutdown(read) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002098 if (unlikely((req->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
2099 if (si_f->flags & SI_FL_NOHALF)
2100 si_f->flags |= SI_FL_NOLINGER;
2101 si_shutr(si_f);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02002102 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002103
Willy Tarreau520d95e2009-09-19 21:04:57 +02002104 /* it's possible that an upper layer has requested a connection setup or abort.
2105 * There are 2 situations where we decide to establish a new connection :
2106 * - there are data scheduled for emission in the buffer
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002107 * - the CF_AUTO_CONNECT flag is set (active connection)
Willy Tarreau520d95e2009-09-19 21:04:57 +02002108 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002109 if (si_b->state == SI_ST_INI) {
2110 if (!(req->flags & CF_SHUTW)) {
2111 if ((req->flags & CF_AUTO_CONNECT) || !channel_is_empty(req)) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02002112 /* If we have an appctx, there is no connect method, so we
2113 * immediately switch to the connected state, otherwise we
2114 * perform a connection request.
Willy Tarreau520d95e2009-09-19 21:04:57 +02002115 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002116 si_b->state = SI_ST_REQ; /* new connection requested */
2117 si_b->conn_retries = s->be->conn_retries;
Willy Tarreau520d95e2009-09-19 21:04:57 +02002118 }
Willy Tarreau73201222009-08-16 18:27:24 +02002119 }
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02002120 else {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002121 si_b->state = SI_ST_CLO; /* shutw+ini = abort */
2122 channel_shutw_now(req); /* fix buffer flags upon abort */
2123 channel_shutr_now(res);
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02002124 }
Willy Tarreau92795622009-03-06 12:51:23 +01002125 }
2126
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002127
2128 /* we may have a pending connection request, or a connection waiting
2129 * for completion.
2130 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002131 if (si_b->state >= SI_ST_REQ && si_b->state < SI_ST_CON) {
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02002132
2133 /* prune the request variables and swap to the response variables. */
2134 if (s->vars_reqres.scope != SCOPE_RES) {
Willy Tarreau6204cd92016-03-10 16:33:04 +01002135 vars_prune(&s->vars_reqres, s->sess, s);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02002136 vars_init(&s->vars_reqres, SCOPE_RES);
2137 }
2138
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002139 do {
2140 /* nb: step 1 might switch from QUE to ASS, but we first want
2141 * to give a chance to step 2 to perform a redirect if needed.
2142 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002143 if (si_b->state != SI_ST_REQ)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002144 sess_update_stream_int(s);
Willy Tarreau8f128b42014-11-28 15:07:47 +01002145 if (si_b->state == SI_ST_REQ)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002146 sess_prepare_conn_req(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002147
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +01002148 /* applets directly go to the ESTABLISHED state. Similarly,
2149 * servers experience the same fate when their connection
2150 * is reused.
2151 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002152 if (unlikely(si_b->state == SI_ST_EST))
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002153 sess_establish(s);
Willy Tarreaufac4bd12013-11-30 09:21:49 +01002154
Willy Tarreaub44c8732013-12-31 23:16:50 +01002155 /* Now we can add the server name to a header (if requested) */
2156 /* check for HTTP mode and proxy server_name_hdr_name != NULL */
Willy Tarreau9c03b332015-09-07 19:32:33 +02002157 if ((si_b->state >= SI_ST_CON) && (si_b->state < SI_ST_CLO) &&
Willy Tarreaub44c8732013-12-31 23:16:50 +01002158 (s->be->server_id_hdr_name != NULL) &&
2159 (s->be->mode == PR_MODE_HTTP) &&
2160 objt_server(s->target)) {
Willy Tarreaueee5b512015-04-03 23:46:31 +02002161 http_send_name_header(s->txn, s->be, objt_server(s->target)->id);
Willy Tarreau1e5dfda2013-04-07 18:19:16 +02002162 }
2163
Willy Tarreau3fdb3662012-11-12 00:42:33 +01002164 srv = objt_server(s->target);
Willy Tarreaue7dff022015-04-03 01:14:29 +02002165 if (si_b->state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE))
Willy Tarreau8f128b42014-11-28 15:07:47 +01002166 http_perform_server_redirect(s, si_b);
2167 } while (si_b->state == SI_ST_ASS);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002168 }
2169
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002170 /* Benchmarks have shown that it's optimal to do a full resync now */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002171 if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002172 goto resync_stream_interface;
2173
Willy Tarreau815a9b22010-07-27 17:15:12 +02002174 /* otherwise we want to check if we need to resync the req buffer or not */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002175 if ((req->flags ^ rqf_last) & CF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002176 goto resync_request;
2177
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002178 /* perform output updates to the response buffer */
Willy Tarreau84455332009-03-15 22:34:05 +01002179
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002180 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02002181 * everything. We configure the buffer to forward indefinitely.
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002182 * Note that we're checking CF_SHUTR_NOW as an indication of a possible
Willy Tarreau8263d2b2012-08-28 00:06:31 +02002183 * recent call to channel_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002184 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002185 if (unlikely(!res->analysers &&
2186 !(res->flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
2187 (si_b->state >= SI_ST_EST) &&
2188 (res->to_forward != CHN_INFINITE_FORWARD))) {
Willy Tarreaub31c9712012-11-11 23:05:39 +01002189 /* This buffer is freewheeling, there's no analyser
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002190 * attached to it. If any data are left in, we'll permit them to
2191 * move.
2192 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002193 channel_auto_read(res);
2194 channel_auto_close(res);
2195 buffer_flush(res->buf);
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01002196
2197 /* We'll let data flow between the producer (if still connected)
2198 * to the consumer.
2199 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002200 if (!(res->flags & (CF_SHUTR|CF_SHUTW_NOW)))
Willy Tarreau8bf242b2016-05-04 14:05:58 +02002201 channel_forward_forever(res);
Willy Tarreauce887fd2012-05-12 12:50:00 +02002202
Willy Tarreau42529c32015-07-09 18:38:57 +02002203 /* Just in order to support fetching HTTP contents after start
2204 * of forwarding when the HTTP forwarding analyser is not used,
2205 * we simply reset msg->sov so that HTTP rewinding points to the
2206 * headers.
2207 */
2208 if (s->txn)
2209 s->txn->rsp.sov = s->txn->rsp.eoh + s->txn->rsp.eol - res->buf->o;
2210
Willy Tarreauce887fd2012-05-12 12:50:00 +02002211 /* if we have no analyser anymore in any direction and have a
Willy Tarreau05cdd962014-05-10 14:30:07 +02002212 * tunnel timeout set, use it now. Note that we must respect
2213 * the half-closed timeouts as well.
Willy Tarreauce887fd2012-05-12 12:50:00 +02002214 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002215 if (!req->analysers && s->be->timeout.tunnel) {
2216 req->rto = req->wto = res->rto = res->wto =
Willy Tarreauce887fd2012-05-12 12:50:00 +02002217 s->be->timeout.tunnel;
Willy Tarreau05cdd962014-05-10 14:30:07 +02002218
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002219 if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin))
2220 res->wto = sess->fe->timeout.clientfin;
Willy Tarreau8f128b42014-11-28 15:07:47 +01002221 if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin))
2222 res->rto = s->be->timeout.serverfin;
2223 if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin))
2224 req->wto = s->be->timeout.serverfin;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002225 if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin))
2226 req->rto = sess->fe->timeout.clientfin;
Willy Tarreau05cdd962014-05-10 14:30:07 +02002227
Willy Tarreau8f128b42014-11-28 15:07:47 +01002228 req->rex = tick_add(now_ms, req->rto);
2229 req->wex = tick_add(now_ms, req->wto);
2230 res->rex = tick_add(now_ms, res->rto);
2231 res->wex = tick_add(now_ms, res->wto);
Willy Tarreauce887fd2012-05-12 12:50:00 +02002232 }
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002233 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01002234
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002235 /* check if it is wise to enable kernel splicing to forward response data */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002236 if (!(res->flags & (CF_KERN_SPLICING|CF_SHUTR)) &&
2237 res->to_forward &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002238 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002239 (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->snd_pipe) &&
2240 (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->rcv_pipe) &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002241 (pipes_used < global.maxpipes) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002242 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
2243 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002244 (res->flags & CF_STREAMER_FAST)))) {
2245 res->flags |= CF_KERN_SPLICING;
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002246 }
2247
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002248 /* reflect what the L7 analysers have seen last */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002249 rpf_last = res->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002250
2251 /*
2252 * Now forward all shutdown requests between both sides of the buffer
2253 */
2254
2255 /*
2256 * FIXME: this is probably where we should produce error responses.
2257 */
2258
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002259 /* first, let's check if the response buffer needs to shutdown(write) */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002260 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) ==
Willy Tarreau05cdd962014-05-10 14:30:07 +02002261 (CF_AUTO_CLOSE|CF_SHUTR))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002262 channel_shutw_now(res);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002263 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002264
2265 /* shutdown(write) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002266 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
2267 channel_is_empty(res))) {
2268 si_shutw(si_f);
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002269 if (tick_isset(sess->fe->timeout.clientfin)) {
2270 req->rto = sess->fe->timeout.clientfin;
Willy Tarreau8f128b42014-11-28 15:07:47 +01002271 req->rex = tick_add(now_ms, req->rto);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002272 }
2273 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002274
2275 /* shutdown(write) done on the client side, we must stop the server too */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002276 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW) &&
2277 !res->analysers)
2278 channel_shutr_now(res);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002279
2280 /* shutdown(read) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002281 if (unlikely((res->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
2282 if (si_b->flags & SI_FL_NOHALF)
2283 si_b->flags |= SI_FL_NOLINGER;
2284 si_shutr(si_b);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02002285 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002286
Willy Tarreau8f128b42014-11-28 15:07:47 +01002287 if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002288 goto resync_stream_interface;
2289
Willy Tarreau8f128b42014-11-28 15:07:47 +01002290 if (req->flags != rqf_last)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002291 goto resync_request;
2292
Willy Tarreau8f128b42014-11-28 15:07:47 +01002293 if ((res->flags ^ rpf_last) & CF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002294 goto resync_response;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002295
Willy Tarreau89f7ef22009-09-05 20:57:35 +02002296 /* we're interested in getting wakeups again */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002297 si_f->flags &= ~SI_FL_DONT_WAKE;
2298 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau89f7ef22009-09-05 20:57:35 +02002299
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002300 /* This is needed only when debugging is enabled, to indicate
2301 * client-side or server-side close. Please note that in the unlikely
2302 * event where both sides would close at once, the sequence is reported
2303 * on the server side first.
2304 */
2305 if (unlikely((global.mode & MODE_DEBUG) &&
2306 (!(global.mode & MODE_QUIET) ||
2307 (global.mode & MODE_VERBOSE)))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002308 if (si_b->state == SI_ST_CLO &&
2309 si_b->prev_state == SI_ST_EST) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002310 chunk_printf(&trash, "%08x:%s.srvcls[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002311 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002312 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2313 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002314 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002315 }
2316
Willy Tarreau8f128b42014-11-28 15:07:47 +01002317 if (si_f->state == SI_ST_CLO &&
2318 si_f->prev_state == SI_ST_EST) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002319 chunk_printf(&trash, "%08x:%s.clicls[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002320 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002321 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2322 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002323 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002324 }
2325 }
2326
Willy Tarreau8f128b42014-11-28 15:07:47 +01002327 if (likely((si_f->state != SI_ST_CLO) ||
2328 (si_b->state > SI_ST_INI && si_b->state < SI_ST_CLO))) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002329
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002330 if ((sess->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED))
Willy Tarreau87b09662015-04-03 00:22:06 +02002331 stream_process_counters(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002332
Willy Tarreau563cc372015-04-19 18:13:56 +02002333 if (si_f->state == SI_ST_EST)
Willy Tarreau8f128b42014-11-28 15:07:47 +01002334 si_update(si_f);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002335
Willy Tarreau563cc372015-04-19 18:13:56 +02002336 if (si_b->state == SI_ST_EST)
Willy Tarreau8f128b42014-11-28 15:07:47 +01002337 si_update(si_b);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002338
Willy Tarreau8f128b42014-11-28 15:07:47 +01002339 req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
2340 res->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
2341 si_f->prev_state = si_f->state;
2342 si_b->prev_state = si_b->state;
2343 si_f->flags &= ~(SI_FL_ERR|SI_FL_EXP);
2344 si_b->flags &= ~(SI_FL_ERR|SI_FL_EXP);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002345
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02002346 /* Trick: if a request is being waiting for the server to respond,
2347 * and if we know the server can timeout, we don't want the timeout
2348 * to expire on the client side first, but we're still interested
2349 * in passing data from the client to the server (eg: POST). Thus,
2350 * we can cancel the client's request timeout if the server's
2351 * request timeout is set and the server has not yet sent a response.
2352 */
2353
Willy Tarreau8f128b42014-11-28 15:07:47 +01002354 if ((res->flags & (CF_AUTO_CLOSE|CF_SHUTR)) == 0 &&
2355 (tick_isset(req->wex) || tick_isset(res->rex))) {
2356 req->flags |= CF_READ_NOEXP;
2357 req->rex = TICK_ETERNITY;
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02002358 }
2359
Willy Tarreau798f4322012-11-08 14:49:17 +01002360 update_exp_and_leave:
Willy Tarreau5fb04712016-05-04 10:18:37 +02002361 /* Note: please ensure that if you branch here you disable SI_FL_DONT_WAKE */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002362 t->expire = tick_first(tick_first(req->rex, req->wex),
2363 tick_first(res->rex, res->wex));
2364 if (req->analysers)
2365 t->expire = tick_first(t->expire, req->analyse_exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002366
Willy Tarreau8f128b42014-11-28 15:07:47 +01002367 if (si_f->exp)
2368 t->expire = tick_first(t->expire, si_f->exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002369
Willy Tarreau8f128b42014-11-28 15:07:47 +01002370 if (si_b->exp)
2371 t->expire = tick_first(t->expire, si_b->exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002372
2373#ifdef DEBUG_FULL
Willy Tarreau127334e2009-03-28 10:47:26 +01002374 fprintf(stderr,
2375 "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u"
2376 " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n",
Willy Tarreau8f128b42014-11-28 15:07:47 +01002377 now_ms, t->expire, req->rex, req->wex, req->analyse_exp,
2378 res->rex, res->wex, si_f->exp, si_b->exp, si_f->state, si_b->state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002379#endif
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002380
2381#ifdef DEBUG_DEV
2382 /* this may only happen when no timeout is set or in case of an FSM bug */
Willy Tarreaud0a201b2009-03-08 15:53:06 +01002383 if (!tick_isset(t->expire))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002384 ABORT_NOW();
2385#endif
Willy Tarreau87b09662015-04-03 00:22:06 +02002386 stream_release_buffers(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01002387 return t; /* nothing more to do */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002388 }
2389
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002390 sess->fe->feconn--;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002391 if (s->flags & SF_BE_ASSIGNED)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002392 s->be->beconn--;
Willy Tarreauaf7ad002010-08-31 15:39:26 +02002393 jobs--;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02002394 if (sess->listener) {
2395 if (!(sess->listener->options & LI_O_UNLIMITED))
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002396 actconn--;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02002397 sess->listener->nbconn--;
2398 if (sess->listener->state == LI_FULL)
2399 resume_listener(sess->listener);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002400
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002401 /* Dequeues all of the listeners waiting for a resource */
2402 if (!LIST_ISEMPTY(&global_listener_queue))
2403 dequeue_all_listeners(&global_listener_queue);
Willy Tarreau08ceb102011-07-24 22:58:00 +02002404
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002405 if (!LIST_ISEMPTY(&sess->fe->listener_queue) &&
2406 (!sess->fe->fe_sps_lim || freq_ctr_remain(&sess->fe->fe_sess_per_sec, sess->fe->fe_sps_lim, 0) > 0))
2407 dequeue_all_listeners(&sess->fe->listener_queue);
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002408 }
Willy Tarreau07687c12011-07-24 23:55:06 +02002409
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002410 if (unlikely((global.mode & MODE_DEBUG) &&
2411 (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002412 chunk_printf(&trash, "%08x:%s.closed[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002413 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002414 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2415 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002416 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002417 }
2418
2419 s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau87b09662015-04-03 00:22:06 +02002420 stream_process_counters(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002421
Willy Tarreaueee5b512015-04-03 23:46:31 +02002422 if (s->txn && s->txn->status) {
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002423 int n;
2424
Willy Tarreaueee5b512015-04-03 23:46:31 +02002425 n = s->txn->status / 100;
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002426 if (n < 1 || n > 5)
2427 n = 0;
2428
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002429 if (sess->fe->mode == PR_MODE_HTTP) {
2430 sess->fe->fe_counters.p.http.rsp[n]++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002431 }
Willy Tarreaue7dff022015-04-03 01:14:29 +02002432 if ((s->flags & SF_BE_ASSIGNED) &&
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002433 (s->be->mode == PR_MODE_HTTP)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002434 s->be->be_counters.p.http.rsp[n]++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002435 s->be->be_counters.p.http.cum_req++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002436 }
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002437 }
2438
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002439 /* let's do a final log if we need it */
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002440 if (!LIST_ISEMPTY(&sess->fe->logformat) && s->logs.logwait &&
Willy Tarreaue7dff022015-04-03 01:14:29 +02002441 !(s->flags & SF_MONITOR) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002442 (!(sess->fe->options & PR_O_NULLNOLOG) || req->total)) {
Willy Tarreaua5555ec2008-11-30 19:02:32 +01002443 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002444 }
2445
Willy Tarreau87b09662015-04-03 00:22:06 +02002446 /* update time stats for this stream */
2447 stream_update_time_stats(s);
Willy Tarreau4bfc5802014-06-17 12:19:18 +02002448
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002449 /* the task MUST not be in the run queue anymore */
Willy Tarreau87b09662015-04-03 00:22:06 +02002450 stream_free(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01002451 task_delete(t);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002452 task_free(t);
Willy Tarreau26c25062009-03-08 09:38:41 +01002453 return NULL;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002454}
2455
Willy Tarreau87b09662015-04-03 00:22:06 +02002456/* Update the stream's backend and server time stats */
2457void stream_update_time_stats(struct stream *s)
Willy Tarreau4bfc5802014-06-17 12:19:18 +02002458{
2459 int t_request;
2460 int t_queue;
2461 int t_connect;
2462 int t_data;
2463 int t_close;
2464 struct server *srv;
2465
2466 t_request = 0;
2467 t_queue = s->logs.t_queue;
2468 t_connect = s->logs.t_connect;
2469 t_close = s->logs.t_close;
2470 t_data = s->logs.t_data;
2471
2472 if (s->be->mode != PR_MODE_HTTP)
2473 t_data = t_connect;
2474
2475 if (t_connect < 0 || t_data < 0)
2476 return;
2477
2478 if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))
2479 t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request);
2480
2481 t_data -= t_connect;
2482 t_connect -= t_queue;
2483 t_queue -= t_request;
2484
2485 srv = objt_server(s->target);
2486 if (srv) {
2487 swrate_add(&srv->counters.q_time, TIME_STATS_SAMPLES, t_queue);
2488 swrate_add(&srv->counters.c_time, TIME_STATS_SAMPLES, t_connect);
2489 swrate_add(&srv->counters.d_time, TIME_STATS_SAMPLES, t_data);
2490 swrate_add(&srv->counters.t_time, TIME_STATS_SAMPLES, t_close);
2491 }
2492 swrate_add(&s->be->be_counters.q_time, TIME_STATS_SAMPLES, t_queue);
2493 swrate_add(&s->be->be_counters.c_time, TIME_STATS_SAMPLES, t_connect);
2494 swrate_add(&s->be->be_counters.d_time, TIME_STATS_SAMPLES, t_data);
2495 swrate_add(&s->be->be_counters.t_time, TIME_STATS_SAMPLES, t_close);
2496}
2497
Willy Tarreau7c669d72008-06-20 15:04:11 +02002498/*
2499 * This function adjusts sess->srv_conn and maintains the previous and new
Willy Tarreau87b09662015-04-03 00:22:06 +02002500 * server's served stream counts. Setting newsrv to NULL is enough to release
Willy Tarreau7c669d72008-06-20 15:04:11 +02002501 * current connection slot. This function also notifies any LB algo which might
Willy Tarreau87b09662015-04-03 00:22:06 +02002502 * expect to be informed about any change in the number of active streams on a
Willy Tarreau7c669d72008-06-20 15:04:11 +02002503 * server.
2504 */
Willy Tarreau87b09662015-04-03 00:22:06 +02002505void sess_change_server(struct stream *sess, struct server *newsrv)
Willy Tarreau7c669d72008-06-20 15:04:11 +02002506{
2507 if (sess->srv_conn == newsrv)
2508 return;
2509
2510 if (sess->srv_conn) {
2511 sess->srv_conn->served--;
2512 if (sess->srv_conn->proxy->lbprm.server_drop_conn)
2513 sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
Willy Tarreau87b09662015-04-03 00:22:06 +02002514 stream_del_srv_conn(sess);
Willy Tarreau7c669d72008-06-20 15:04:11 +02002515 }
2516
2517 if (newsrv) {
2518 newsrv->served++;
2519 if (newsrv->proxy->lbprm.server_take_conn)
2520 newsrv->proxy->lbprm.server_take_conn(newsrv);
Willy Tarreau87b09662015-04-03 00:22:06 +02002521 stream_add_srv_conn(sess, newsrv);
Willy Tarreau7c669d72008-06-20 15:04:11 +02002522 }
2523}
2524
Willy Tarreau84455332009-03-15 22:34:05 +01002525/* Handle server-side errors for default protocols. It is called whenever a a
2526 * connection setup is aborted or a request is aborted in queue. It sets the
Willy Tarreau87b09662015-04-03 00:22:06 +02002527 * stream termination flags so that the caller does not have to worry about
Willy Tarreau84455332009-03-15 22:34:05 +01002528 * them. It's installed as ->srv_error for the server-side stream_interface.
2529 */
Willy Tarreau87b09662015-04-03 00:22:06 +02002530void default_srv_error(struct stream *s, struct stream_interface *si)
Willy Tarreau84455332009-03-15 22:34:05 +01002531{
2532 int err_type = si->err_type;
2533 int err = 0, fin = 0;
2534
2535 if (err_type & SI_ET_QUEUE_ABRT) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002536 err = SF_ERR_CLICL;
2537 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002538 }
2539 else if (err_type & SI_ET_CONN_ABRT) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002540 err = SF_ERR_CLICL;
2541 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002542 }
2543 else if (err_type & SI_ET_QUEUE_TO) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002544 err = SF_ERR_SRVTO;
2545 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002546 }
2547 else if (err_type & SI_ET_QUEUE_ERR) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002548 err = SF_ERR_SRVCL;
2549 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002550 }
2551 else if (err_type & SI_ET_CONN_TO) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002552 err = SF_ERR_SRVTO;
2553 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002554 }
2555 else if (err_type & SI_ET_CONN_ERR) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002556 err = SF_ERR_SRVCL;
2557 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002558 }
Willy Tarreau2d400bb2012-05-14 12:11:47 +02002559 else if (err_type & SI_ET_CONN_RES) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002560 err = SF_ERR_RESOURCE;
2561 fin = SF_FINST_C;
Willy Tarreau2d400bb2012-05-14 12:11:47 +02002562 }
Willy Tarreau84455332009-03-15 22:34:05 +01002563 else /* SI_ET_CONN_OTHER and others */ {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002564 err = SF_ERR_INTERNAL;
2565 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002566 }
2567
Willy Tarreaue7dff022015-04-03 01:14:29 +02002568 if (!(s->flags & SF_ERR_MASK))
Willy Tarreau84455332009-03-15 22:34:05 +01002569 s->flags |= err;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002570 if (!(s->flags & SF_FINST_MASK))
Willy Tarreau84455332009-03-15 22:34:05 +01002571 s->flags |= fin;
2572}
Willy Tarreau7c669d72008-06-20 15:04:11 +02002573
Willy Tarreaue7dff022015-04-03 01:14:29 +02002574/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +02002575void stream_shutdown(struct stream *stream, int why)
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002576{
Willy Tarreau87b09662015-04-03 00:22:06 +02002577 if (stream->req.flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002578 return;
2579
Willy Tarreau87b09662015-04-03 00:22:06 +02002580 channel_shutw_now(&stream->req);
2581 channel_shutr_now(&stream->res);
2582 stream->task->nice = 1024;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002583 if (!(stream->flags & SF_ERR_MASK))
Willy Tarreau87b09662015-04-03 00:22:06 +02002584 stream->flags |= why;
2585 task_wakeup(stream->task, TASK_WOKEN_OTHER);
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002586}
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02002587
Willy Tarreau8b22a712010-06-18 17:46:06 +02002588/************************************************************************/
2589/* All supported ACL keywords must be declared here. */
2590/************************************************************************/
2591
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002592/* Returns a pointer to a stkctr depending on the fetch keyword name.
2593 * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively.
Willy Tarreaua65536c2013-07-22 22:40:11 +02002594 * sc[0-9]_* will return a pointer to the respective field in the
Willy Tarreau87b09662015-04-03 00:22:06 +02002595 * stream <l4>. sc_* requires an UINT argument specifying the stick
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002596 * counter number. src_* will fill a locally allocated structure with
Willy Tarreaua65536c2013-07-22 22:40:11 +02002597 * the table and entry corresponding to what is specified with src_*.
Willy Tarreau0f791d42013-07-23 19:56:43 +02002598 * NULL may be returned if the designated stkctr is not tracked. For
2599 * the sc_* and sc[0-9]_* forms, an optional table argument may be
2600 * passed. When present, the currently tracked key is then looked up
2601 * in the specified table instead of the current table. The purpose is
2602 * to be able to convery multiple values per key (eg: have gpc0 from
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002603 * multiple tables). <strm> is allowed to be NULL, in which case only
2604 * the session will be consulted.
Willy Tarreaua65536c2013-07-22 22:40:11 +02002605 */
Willy Tarreaue12704b2014-07-15 19:06:18 +02002606struct stkctr *
Willy Tarreau192252e2015-04-04 01:47:55 +02002607smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw)
Willy Tarreaua65536c2013-07-22 22:40:11 +02002608{
2609 static struct stkctr stkctr;
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002610 struct stkctr *stkptr;
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002611 struct stksess *stksess;
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002612 unsigned int num = kw[2] - '0';
Willy Tarreau0f791d42013-07-23 19:56:43 +02002613 int arg = 0;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002614
Willy Tarreau0f791d42013-07-23 19:56:43 +02002615 if (num == '_' - '0') {
2616 /* sc_* variant, args[0] = ctr# (mandatory) */
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02002617 num = args[arg++].data.sint;
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002618 if (num >= MAX_SESS_STKCTR)
2619 return NULL;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002620 }
Willy Tarreau0f791d42013-07-23 19:56:43 +02002621 else if (num > 9) { /* src_* variant, args[0] = table */
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002622 struct stktable_key *key;
Willy Tarreau9ad7bd42015-04-03 19:19:59 +02002623 struct connection *conn = objt_conn(sess->origin);
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002624 struct sample smp;
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002625
2626 if (!conn)
2627 return NULL;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002628
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002629 /* Fetch source adress in a sample. */
2630 smp.px = NULL;
2631 smp.sess = sess;
2632 smp.strm = strm;
2633 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2634 return NULL;
2635
2636 /* Converts into key. */
2637 key = smp_to_stkey(&smp, &args->data.prx->table);
Willy Tarreaua65536c2013-07-22 22:40:11 +02002638 if (!key)
2639 return NULL;
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002640
Willy Tarreaua65536c2013-07-22 22:40:11 +02002641 stkctr.table = &args->data.prx->table;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002642 stkctr_set_entry(&stkctr, stktable_lookup_key(stkctr.table, key));
Willy Tarreaua65536c2013-07-22 22:40:11 +02002643 return &stkctr;
2644 }
Willy Tarreau0f791d42013-07-23 19:56:43 +02002645
2646 /* Here, <num> contains the counter number from 0 to 9 for
2647 * the sc[0-9]_ form, or even higher using sc_(num) if needed.
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002648 * args[arg] is the first optional argument. We first lookup the
2649 * ctr form the stream, then from the session if it was not there.
Willy Tarreau0f791d42013-07-23 19:56:43 +02002650 */
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002651
Thierry Fournier40e1d512016-03-29 21:27:36 +02002652 if (strm)
2653 stkptr = &strm->stkctr[num];
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002654 if (!strm || !stkctr_entry(stkptr)) {
2655 stkptr = &sess->stkctr[num];
2656 if (!stkctr_entry(stkptr))
2657 return NULL;
2658 }
2659
2660 stksess = stkctr_entry(stkptr);
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002661 if (!stksess)
2662 return NULL;
2663
Willy Tarreau0f791d42013-07-23 19:56:43 +02002664 if (unlikely(args[arg].type == ARGT_TAB)) {
2665 /* an alternate table was specified, let's look up the same key there */
2666 stkctr.table = &args[arg].data.prx->table;
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002667 stkctr_set_entry(&stkctr, stktable_lookup(stkctr.table, stksess));
Willy Tarreau0f791d42013-07-23 19:56:43 +02002668 return &stkctr;
2669 }
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002670 return stkptr;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002671}
2672
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002673/* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create
2674 * the entry if it doesn't exist yet. This is needed for a few fetch
2675 * functions which need to create an entry, such as src_inc_gpc* and
2676 * src_clr_gpc*.
2677 */
2678struct stkctr *
2679smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw)
2680{
2681 static struct stkctr stkctr;
2682 struct stktable_key *key;
2683 struct connection *conn = objt_conn(sess->origin);
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002684 struct sample smp;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002685
2686 if (strncmp(kw, "src_", 4) != 0)
2687 return NULL;
2688
2689 if (!conn)
2690 return NULL;
2691
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002692 /* Fetch source adress in a sample. */
2693 smp.px = NULL;
2694 smp.sess = sess;
2695 smp.strm = strm;
2696 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2697 return NULL;
2698
2699 /* Converts into key. */
2700 key = smp_to_stkey(&smp, &args->data.prx->table);
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002701 if (!key)
2702 return NULL;
2703
2704 stkctr.table = &args->data.prx->table;
2705 stkctr_set_entry(&stkctr, stktable_update_key(stkctr.table, key));
2706 return &stkctr;
2707}
2708
Willy Tarreau87b09662015-04-03 00:22:06 +02002709/* set return a boolean indicating if the requested stream counter is
Willy Tarreau88821242013-07-22 18:29:29 +02002710 * currently being tracked or not.
2711 * Supports being called as "sc[0-9]_tracked" only.
2712 */
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002713static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002714smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002715{
2716 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002717 smp->data.type = SMP_T_BOOL;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002718 smp->data.u.sint = !!smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002719 return 1;
2720}
2721
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002722/* set <smp> to the General Purpose Flag 0 value from the stream's tracked
2723 * frontend counters or from the src.
2724 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value
2725 * zero is returned if the key is new.
2726 */
2727static int
2728smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2729{
Willy Tarreaube508f12016-03-10 11:47:01 +01002730 struct stkctr *stkctr;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002731
Willy Tarreaube508f12016-03-10 11:47:01 +01002732 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002733 if (!stkctr)
2734 return 0;
2735
2736 smp->flags = SMP_F_VOL_TEST;
2737 smp->data.type = SMP_T_SINT;
2738 smp->data.u.sint = 0;
2739
2740 if (stkctr_entry(stkctr) != NULL) {
2741 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0);
2742 if (!ptr)
2743 return 0; /* parameter not stored */
2744 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
2745 }
2746 return 1;
2747}
2748
Willy Tarreau87b09662015-04-03 00:22:06 +02002749/* set <smp> to the General Purpose Counter 0 value from the stream's tracked
Willy Tarreau30b20462013-07-22 19:46:52 +02002750 * frontend counters or from the src.
2751 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value
2752 * zero is returned if the key is new.
2753 */
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002754static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002755smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002756{
Willy Tarreaube508f12016-03-10 11:47:01 +01002757 struct stkctr *stkctr;
2758
Willy Tarreaube508f12016-03-10 11:47:01 +01002759 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau30b20462013-07-22 19:46:52 +02002760 if (!stkctr)
2761 return 0;
2762
Willy Tarreau37406352012-04-23 16:16:37 +02002763 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002764 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002765 smp->data.u.sint = 0;
Willy Tarreau30b20462013-07-22 19:46:52 +02002766
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002767 if (stkctr_entry(stkctr) != NULL) {
2768 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002769 if (!ptr)
2770 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002771 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002772 }
2773 return 1;
2774}
2775
Willy Tarreau87b09662015-04-03 00:22:06 +02002776/* set <smp> to the General Purpose Counter 0's event rate from the stream's
Willy Tarreaub5e0af02013-07-22 23:47:07 +02002777 * tracked frontend counters or from the src.
2778 * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only.
2779 * Value zero is returned if the key is new.
2780 */
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002781static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002782smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002783{
Willy Tarreaube508f12016-03-10 11:47:01 +01002784 struct stkctr *stkctr;
2785
Willy Tarreaube508f12016-03-10 11:47:01 +01002786 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaub5e0af02013-07-22 23:47:07 +02002787 if (!stkctr)
2788 return 0;
2789
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002790 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002791 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002792 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002793 if (stkctr_entry(stkctr) != NULL) {
2794 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002795 if (!ptr)
2796 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002797 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002798 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002799 }
2800 return 1;
2801}
2802
Willy Tarreau87b09662015-04-03 00:22:06 +02002803/* Increment the General Purpose Counter 0 value from the stream's tracked
Willy Tarreau710d38c2013-07-23 00:07:04 +02002804 * frontend counters and return it into temp integer.
2805 * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only.
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002806 */
2807static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002808smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002809{
Willy Tarreaube508f12016-03-10 11:47:01 +01002810 struct stkctr *stkctr;
2811
Willy Tarreaube508f12016-03-10 11:47:01 +01002812 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau710d38c2013-07-23 00:07:04 +02002813 if (!stkctr)
2814 return 0;
2815
Willy Tarreau37406352012-04-23 16:16:37 +02002816 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002817 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002818 smp->data.u.sint = 0;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002819
2820 if (stkctr_entry(stkctr) == NULL)
2821 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw);
2822
Thierry Fournier6fc340f2016-06-06 18:28:05 +02002823 if (stkctr && stkctr_entry(stkctr)) {
Emeric Brun57056f02015-06-15 18:29:57 +02002824 void *ptr1,*ptr2;
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002825
2826 /* First, update gpc0_rate if it's tracked. Second, update its
2827 * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr.
2828 */
Emeric Brun57056f02015-06-15 18:29:57 +02002829 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
2830 if (ptr1) {
2831 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
Willy Tarreau710d38c2013-07-23 00:07:04 +02002832 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002833 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr;
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002834 }
2835
Emeric Brun57056f02015-06-15 18:29:57 +02002836 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2837 if (ptr2)
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002838 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002839
Emeric Brun57056f02015-06-15 18:29:57 +02002840 /* If data was modified, we need to touch to re-schedule sync */
2841 if (ptr1 || ptr2)
2842 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002843 }
2844 return 1;
2845}
2846
Willy Tarreau87b09662015-04-03 00:22:06 +02002847/* Clear the General Purpose Counter 0 value from the stream's tracked
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002848 * frontend counters and return its previous value into temp integer.
2849 * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only.
Willy Tarreauf73cd112011-08-13 01:45:16 +02002850 */
2851static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002852smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauf73cd112011-08-13 01:45:16 +02002853{
Willy Tarreaube508f12016-03-10 11:47:01 +01002854 struct stkctr *stkctr;
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002855
Willy Tarreaube508f12016-03-10 11:47:01 +01002856 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002857 if (!stkctr)
2858 return 0;
2859
Willy Tarreau37406352012-04-23 16:16:37 +02002860 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002861 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002862 smp->data.u.sint = 0;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002863
2864 if (stkctr_entry(stkctr) == NULL)
2865 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw);
2866
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002867 if (stkctr_entry(stkctr) != NULL) {
2868 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002869 if (!ptr)
2870 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002871 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002872 stktable_data_cast(ptr, gpc0) = 0;
Emeric Brun57056f02015-06-15 18:29:57 +02002873 /* If data was modified, we need to touch to re-schedule sync */
2874 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002875 }
2876 return 1;
2877}
2878
Willy Tarreau87b09662015-04-03 00:22:06 +02002879/* set <smp> to the cumulated number of connections from the stream's tracked
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002880 * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or
2881 * "src_conn_cnt" only.
2882 */
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002883static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002884smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002885{
Willy Tarreaube508f12016-03-10 11:47:01 +01002886 struct stkctr *stkctr;
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002887
Willy Tarreaube508f12016-03-10 11:47:01 +01002888 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002889 if (!stkctr)
2890 return 0;
2891
Willy Tarreau37406352012-04-23 16:16:37 +02002892 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002893 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002894 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002895 if (stkctr_entry(stkctr) != NULL) {
2896 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT);
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002897 if (!ptr)
2898 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002899 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002900 }
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002901 return 1;
2902}
2903
Willy Tarreau87b09662015-04-03 00:22:06 +02002904/* set <smp> to the connection rate from the stream's tracked frontend
Willy Tarreauc8c65702013-07-23 15:09:35 +02002905 * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate"
2906 * only.
2907 */
Willy Tarreau91c43d72010-06-20 11:19:22 +02002908static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002909smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002910{
Willy Tarreaube508f12016-03-10 11:47:01 +01002911 struct stkctr *stkctr;
2912
Willy Tarreaube508f12016-03-10 11:47:01 +01002913 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreauc8c65702013-07-23 15:09:35 +02002914 if (!stkctr)
2915 return 0;
2916
Willy Tarreau37406352012-04-23 16:16:37 +02002917 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002918 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002919 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002920 if (stkctr_entry(stkctr) != NULL) {
2921 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002922 if (!ptr)
2923 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002924 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
Willy Tarreauc8c65702013-07-23 15:09:35 +02002925 stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002926 }
2927 return 1;
2928}
2929
Willy Tarreau87b09662015-04-03 00:22:06 +02002930/* set temp integer to the number of connections from the stream's source address
Willy Tarreau8b22a712010-06-18 17:46:06 +02002931 * in the table pointed to by expr, after updating it.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02002932 * Accepts exactly 1 argument of type table.
Willy Tarreau8b22a712010-06-18 17:46:06 +02002933 */
2934static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002935smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau8b22a712010-06-18 17:46:06 +02002936{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002937 struct connection *conn = objt_conn(smp->sess->origin);
Willy Tarreau8b22a712010-06-18 17:46:06 +02002938 struct stksess *ts;
2939 struct stktable_key *key;
2940 void *ptr;
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002941 struct proxy *px;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002942
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002943 if (!conn)
2944 return 0;
2945
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002946 /* Fetch source adress in a sample. */
2947 if (!smp_fetch_src(NULL, smp, NULL, NULL))
2948 return 0;
2949
2950 /* Converts into key. */
2951 key = smp_to_stkey(smp, &args->data.prx->table);
Willy Tarreau8b22a712010-06-18 17:46:06 +02002952 if (!key)
David du Colombier4f92d322011-03-24 11:09:31 +01002953 return 0;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002954
Willy Tarreau24e32d82012-04-23 23:55:44 +02002955 px = args->data.prx;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002956
Willy Tarreau1f7e9252010-06-20 12:27:21 +02002957 if ((ts = stktable_update_key(&px->table, key)) == NULL)
2958 /* entry does not exist and could not be created */
2959 return 0;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002960
2961 ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
2962 if (!ptr)
2963 return 0; /* parameter not stored in this table */
2964
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002965 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002966 smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt);
Emeric Brun57056f02015-06-15 18:29:57 +02002967 /* Touch was previously performed by stktable_update_key */
Willy Tarreau37406352012-04-23 16:16:37 +02002968 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002969 return 1;
2970}
2971
Willy Tarreau87b09662015-04-03 00:22:06 +02002972/* set <smp> to the number of concurrent connections from the stream's tracked
Willy Tarreauf44a5532013-07-23 15:17:53 +02002973 * frontend counters. Supports being called as "sc[0-9]_conn_cur" or
2974 * "src_conn_cur" only.
2975 */
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002976static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002977smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002978{
Willy Tarreaube508f12016-03-10 11:47:01 +01002979 struct stkctr *stkctr;
2980
Willy Tarreaube508f12016-03-10 11:47:01 +01002981 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreauf44a5532013-07-23 15:17:53 +02002982 if (!stkctr)
2983 return 0;
2984
Willy Tarreau37406352012-04-23 16:16:37 +02002985 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002986 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002987 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002988 if (stkctr_entry(stkctr) != NULL) {
2989 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR);
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002990 if (!ptr)
2991 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002992 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002993 }
2994 return 1;
2995}
2996
Willy Tarreau87b09662015-04-03 00:22:06 +02002997/* set <smp> to the cumulated number of streams from the stream's tracked
Willy Tarreau20843082013-07-23 15:35:33 +02002998 * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or
2999 * "src_sess_cnt" only.
3000 */
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003001static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003002smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003003{
Willy Tarreaube508f12016-03-10 11:47:01 +01003004 struct stkctr *stkctr;
3005
Willy Tarreaube508f12016-03-10 11:47:01 +01003006 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau20843082013-07-23 15:35:33 +02003007 if (!stkctr)
3008 return 0;
3009
Willy Tarreau37406352012-04-23 16:16:37 +02003010 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003011 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003012 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003013 if (stkctr_entry(stkctr) != NULL) {
3014 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003015 if (!ptr)
3016 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003017 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003018 }
3019 return 1;
3020}
3021
Willy Tarreau87b09662015-04-03 00:22:06 +02003022/* set <smp> to the stream rate from the stream's tracked frontend counters.
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003023 * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only.
3024 */
Willy Tarreau91c43d72010-06-20 11:19:22 +02003025static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003026smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau91c43d72010-06-20 11:19:22 +02003027{
Willy Tarreaube508f12016-03-10 11:47:01 +01003028 struct stkctr *stkctr;
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003029
Willy Tarreaube508f12016-03-10 11:47:01 +01003030 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003031 if (!stkctr)
3032 return 0;
3033
Willy Tarreau37406352012-04-23 16:16:37 +02003034 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003035 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003036 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003037 if (stkctr_entry(stkctr) != NULL) {
3038 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
Willy Tarreau91c43d72010-06-20 11:19:22 +02003039 if (!ptr)
3040 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003041 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003042 stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u);
Willy Tarreau91c43d72010-06-20 11:19:22 +02003043 }
3044 return 1;
3045}
3046
Willy Tarreau87b09662015-04-03 00:22:06 +02003047/* set <smp> to the cumulated number of HTTP requests from the stream's tracked
Willy Tarreau91200da2013-07-23 15:55:19 +02003048 * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or
3049 * "src_http_req_cnt" only.
3050 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003051static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003052smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003053{
Willy Tarreaube508f12016-03-10 11:47:01 +01003054 struct stkctr *stkctr;
Willy Tarreau91200da2013-07-23 15:55:19 +02003055
Willy Tarreaube508f12016-03-10 11:47:01 +01003056 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau91200da2013-07-23 15:55:19 +02003057 if (!stkctr)
3058 return 0;
3059
Willy Tarreau37406352012-04-23 16:16:37 +02003060 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003061 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003062 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003063 if (stkctr_entry(stkctr) != NULL) {
3064 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003065 if (!ptr)
3066 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003067 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003068 }
3069 return 1;
3070}
3071
Willy Tarreau87b09662015-04-03 00:22:06 +02003072/* set <smp> to the HTTP request rate from the stream's tracked frontend
Willy Tarreaucf477632013-07-23 16:04:37 +02003073 * counters. Supports being called as "sc[0-9]_http_req_rate" or
3074 * "src_http_req_rate" only.
3075 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003076static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003077smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003078{
Willy Tarreaube508f12016-03-10 11:47:01 +01003079 struct stkctr *stkctr;
3080
Willy Tarreaube508f12016-03-10 11:47:01 +01003081 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaucf477632013-07-23 16:04:37 +02003082 if (!stkctr)
3083 return 0;
3084
Willy Tarreau37406352012-04-23 16:16:37 +02003085 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003086 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003087 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003088 if (stkctr_entry(stkctr) != NULL) {
3089 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003090 if (!ptr)
3091 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003092 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreaucf477632013-07-23 16:04:37 +02003093 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003094 }
3095 return 1;
3096}
3097
Willy Tarreau87b09662015-04-03 00:22:06 +02003098/* set <smp> to the cumulated number of HTTP requests errors from the stream's
Willy Tarreau30d07c32013-07-23 16:45:38 +02003099 * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or
3100 * "src_http_err_cnt" only.
3101 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003102static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003103smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003104{
Willy Tarreaube508f12016-03-10 11:47:01 +01003105 struct stkctr *stkctr;
3106
Willy Tarreaube508f12016-03-10 11:47:01 +01003107 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau30d07c32013-07-23 16:45:38 +02003108 if (!stkctr)
3109 return 0;
3110
Willy Tarreau37406352012-04-23 16:16:37 +02003111 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003112 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003113 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003114 if (stkctr_entry(stkctr) != NULL) {
3115 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003116 if (!ptr)
3117 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003118 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003119 }
3120 return 1;
3121}
3122
Willy Tarreau87b09662015-04-03 00:22:06 +02003123/* set <smp> to the HTTP request error rate from the stream's tracked frontend
Willy Tarreau9daf2622013-07-23 16:48:54 +02003124 * counters. Supports being called as "sc[0-9]_http_err_rate" or
3125 * "src_http_err_rate" only.
3126 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003127static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003128smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003129{
Willy Tarreaube508f12016-03-10 11:47:01 +01003130 struct stkctr *stkctr;
3131
Willy Tarreaube508f12016-03-10 11:47:01 +01003132 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau9daf2622013-07-23 16:48:54 +02003133 if (!stkctr)
3134 return 0;
3135
Willy Tarreau37406352012-04-23 16:16:37 +02003136 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003137 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003138 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003139 if (stkctr_entry(stkctr) != NULL) {
3140 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003141 if (!ptr)
3142 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003143 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
Willy Tarreau9daf2622013-07-23 16:48:54 +02003144 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003145 }
3146 return 1;
3147}
3148
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003149/* set <smp> to the number of kbytes received from clients, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003150 * stream's tracked frontend counters. Supports being called as
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003151 * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
3152 */
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003153static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003154smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003155{
Willy Tarreaube508f12016-03-10 11:47:01 +01003156 struct stkctr *stkctr;
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003157
Willy Tarreaube508f12016-03-10 11:47:01 +01003158 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003159 if (!stkctr)
3160 return 0;
3161
Willy Tarreau37406352012-04-23 16:16:37 +02003162 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003163 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003164 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003165 if (stkctr_entry(stkctr) != NULL) {
3166 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT);
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003167 if (!ptr)
3168 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003169 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003170 }
3171 return 1;
3172}
3173
Willy Tarreau613fe992013-07-23 17:39:19 +02003174/* set <smp> to the data rate received from clients in bytes/s, as found
Willy Tarreau87b09662015-04-03 00:22:06 +02003175 * in the stream's tracked frontend counters. Supports being called as
Willy Tarreau613fe992013-07-23 17:39:19 +02003176 * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only.
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003177 */
3178static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003179smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003180{
Willy Tarreaube508f12016-03-10 11:47:01 +01003181 struct stkctr *stkctr;
Willy Tarreau613fe992013-07-23 17:39:19 +02003182
Willy Tarreaube508f12016-03-10 11:47:01 +01003183 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau613fe992013-07-23 17:39:19 +02003184 if (!stkctr)
3185 return 0;
3186
Willy Tarreau37406352012-04-23 16:16:37 +02003187 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003188 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003189 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003190 if (stkctr_entry(stkctr) != NULL) {
3191 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003192 if (!ptr)
3193 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003194 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
Willy Tarreau613fe992013-07-23 17:39:19 +02003195 stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003196 }
3197 return 1;
3198}
3199
Willy Tarreau53aea102013-07-23 17:39:02 +02003200/* set <smp> to the number of kbytes sent to clients, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003201 * stream's tracked frontend counters. Supports being called as
Willy Tarreau53aea102013-07-23 17:39:02 +02003202 * "sc[0-9]_kbytes_out" or "src_kbytes_out" only.
3203 */
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003204static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003205smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003206{
Willy Tarreaube508f12016-03-10 11:47:01 +01003207 struct stkctr *stkctr;
3208
Willy Tarreaube508f12016-03-10 11:47:01 +01003209 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau53aea102013-07-23 17:39:02 +02003210 if (!stkctr)
3211 return 0;
3212
Willy Tarreau37406352012-04-23 16:16:37 +02003213 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003214 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003215 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003216 if (stkctr_entry(stkctr) != NULL) {
3217 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT);
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003218 if (!ptr)
3219 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003220 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003221 }
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003222 return 1;
3223}
3224
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003225/* set <smp> to the data rate sent to clients in bytes/s, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003226 * stream's tracked frontend counters. Supports being called as
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003227 * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003228 */
3229static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003230smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003231{
Willy Tarreaube508f12016-03-10 11:47:01 +01003232 struct stkctr *stkctr;
3233
Willy Tarreaube508f12016-03-10 11:47:01 +01003234 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003235 if (!stkctr)
3236 return 0;
3237
Willy Tarreau37406352012-04-23 16:16:37 +02003238 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003239 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003240 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003241 if (stkctr_entry(stkctr) != NULL) {
3242 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003243 if (!ptr)
3244 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003245 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003246 stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003247 }
3248 return 1;
3249}
3250
Willy Tarreau87b09662015-04-03 00:22:06 +02003251/* set <smp> to the number of active trackers on the SC entry in the stream's
Willy Tarreau563eef42013-07-23 18:32:02 +02003252 * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only.
3253 */
Willy Tarreau2406db42012-12-09 12:16:43 +01003254static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003255smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau2406db42012-12-09 12:16:43 +01003256{
Willy Tarreaube508f12016-03-10 11:47:01 +01003257 struct stkctr *stkctr;
3258
Willy Tarreaube508f12016-03-10 11:47:01 +01003259 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau563eef42013-07-23 18:32:02 +02003260 if (!stkctr)
Willy Tarreau2406db42012-12-09 12:16:43 +01003261 return 0;
3262
Willy Tarreau563eef42013-07-23 18:32:02 +02003263 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003264 smp->data.type = SMP_T_SINT;
Willy Tarreau4d03ef72016-08-14 12:02:55 +02003265 smp->data.u.sint = stkctr_entry(stkctr) ? stkctr_entry(stkctr)->ref_cnt : 0;
Willy Tarreau563eef42013-07-23 18:32:02 +02003266 return 1;
Willy Tarreaue25c9172013-05-28 18:32:20 +02003267}
3268
Willy Tarreau34db1082012-04-19 17:16:54 +02003269/* set temp integer to the number of used entries in the table pointed to by expr.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02003270 * Accepts exactly 1 argument of type table.
Willy Tarreau34db1082012-04-19 17:16:54 +02003271 */
Willy Tarreauc735a072011-03-29 00:57:02 +02003272static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003273smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc735a072011-03-29 00:57:02 +02003274{
Willy Tarreau37406352012-04-23 16:16:37 +02003275 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003276 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003277 smp->data.u.sint = args->data.prx->table.current;
Willy Tarreauc735a072011-03-29 00:57:02 +02003278 return 1;
3279}
3280
Willy Tarreau34db1082012-04-19 17:16:54 +02003281/* set temp integer to the number of free entries in the table pointed to by expr.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02003282 * Accepts exactly 1 argument of type table.
Willy Tarreau34db1082012-04-19 17:16:54 +02003283 */
Willy Tarreauc735a072011-03-29 00:57:02 +02003284static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003285smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc735a072011-03-29 00:57:02 +02003286{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02003287 struct proxy *px;
3288
Willy Tarreau24e32d82012-04-23 23:55:44 +02003289 px = args->data.prx;
Willy Tarreau37406352012-04-23 16:16:37 +02003290 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003291 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003292 smp->data.u.sint = px->table.size - px->table.current;
Willy Tarreauc735a072011-03-29 00:57:02 +02003293 return 1;
3294}
Willy Tarreau8b22a712010-06-18 17:46:06 +02003295
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003296/* 0=OK, <0=Alert, >0=Warning */
3297static enum act_parse_ret stream_parse_use_service(const char **args, int *cur_arg,
3298 struct proxy *px, struct act_rule *rule,
3299 char **err)
3300{
3301 struct action_kw *kw;
3302
3303 /* Check if the service name exists. */
3304 if (*(args[*cur_arg]) == 0) {
3305 memprintf(err, "'%s' expects a service name.", args[0]);
Thierry FOURNIER337eae12015-11-26 19:48:04 +01003306 return ACT_RET_PRS_ERR;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003307 }
3308
3309 /* lookup for keyword corresponding to a service. */
3310 kw = action_lookup(&service_keywords, args[*cur_arg]);
3311 if (!kw) {
3312 memprintf(err, "'%s' unknown service name.", args[1]);
3313 return ACT_RET_PRS_ERR;
3314 }
3315 (*cur_arg)++;
3316
3317 /* executes specific rule parser. */
3318 rule->kw = kw;
3319 if (kw->parse((const char **)args, cur_arg, px, rule, err) == ACT_RET_PRS_ERR)
3320 return ACT_RET_PRS_ERR;
3321
3322 /* Register processing function. */
3323 rule->action_ptr = process_use_service;
3324 rule->action = ACT_CUSTOM;
3325
3326 return ACT_RET_PRS_OK;
3327}
3328
3329void service_keywords_register(struct action_kw_list *kw_list)
3330{
3331 LIST_ADDQ(&service_keywords, &kw_list->list);
3332}
3333
3334/* main configuration keyword registration. */
3335static struct action_kw_list stream_tcp_keywords = { ILH, {
3336 { "use-service", stream_parse_use_service },
3337 { /* END */ }
3338}};
3339
3340static struct action_kw_list stream_http_keywords = { ILH, {
3341 { "use-service", stream_parse_use_service },
3342 { /* END */ }
3343}};
3344
Willy Tarreau61612d42012-04-19 18:42:05 +02003345/* Note: must not be declared <const> as its list will be overwritten.
3346 * Please take care of keeping this list alphabetically sorted.
3347 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02003348static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau281c7992013-01-08 01:23:27 +01003349 { /* END */ },
Willy Tarreau8b22a712010-06-18 17:46:06 +02003350}};
3351
Willy Tarreau281c7992013-01-08 01:23:27 +01003352/* Note: must not be declared <const> as its list will be overwritten.
3353 * Please take care of keeping this list alphabetically sorted.
3354 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02003355static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02003356 { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3357 { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3358 { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3359 { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3360 { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3361 { "sc_conn_rate", smp_fetch_sc_conn_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003362 { "sc_get_gpt0", smp_fetch_sc_get_gpt0, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02003363 { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3364 { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3365 { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3366 { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3367 { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3368 { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3369 { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3370 { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3371 { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3372 { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3373 { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3374 { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
3375 { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003376 { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3377 { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3378 { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3379 { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3380 { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3381 { "sc0_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003382 { "sc0_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003383 { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3384 { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3385 { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3386 { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3387 { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3388 { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3389 { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3390 { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3391 { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3392 { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3393 { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau0f791d42013-07-23 19:56:43 +02003394 { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003395 { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3396 { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3397 { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3398 { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3399 { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3400 { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3401 { "sc1_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003402 { "sc1_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003403 { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3404 { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3405 { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3406 { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3407 { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3408 { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3409 { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3410 { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3411 { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3412 { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3413 { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau0f791d42013-07-23 19:56:43 +02003414 { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003415 { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3416 { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3417 { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3418 { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3419 { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3420 { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3421 { "sc2_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003422 { "sc2_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003423 { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3424 { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3425 { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3426 { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3427 { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3428 { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3429 { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3430 { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3431 { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3432 { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3433 { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau0f791d42013-07-23 19:56:43 +02003434 { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003435 { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3436 { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3437 { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3438 { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3439 { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3440 { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3441 { "src_conn_rate", smp_fetch_sc_conn_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003442 { "src_get_gpt0", smp_fetch_sc_get_gpt0, ARG1(1,TAB), NULL, SMP_T_BOOL, SMP_USE_L4CLI, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003443 { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3444 { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3445 { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3446 { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3447 { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3448 { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3449 { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3450 { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3451 { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3452 { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3453 { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3454 { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3455 { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3456 { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau281c7992013-01-08 01:23:27 +01003457 { /* END */ },
3458}};
3459
Willy Tarreau8b22a712010-06-18 17:46:06 +02003460__attribute__((constructor))
Willy Tarreau87b09662015-04-03 00:22:06 +02003461static void __stream_init(void)
Willy Tarreau8b22a712010-06-18 17:46:06 +02003462{
Willy Tarreau281c7992013-01-08 01:23:27 +01003463 sample_register_fetches(&smp_fetch_keywords);
Willy Tarreau8b22a712010-06-18 17:46:06 +02003464 acl_register_keywords(&acl_kws);
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003465 tcp_req_cont_keywords_register(&stream_tcp_keywords);
3466 http_req_keywords_register(&stream_http_keywords);
Willy Tarreau8b22a712010-06-18 17:46:06 +02003467}
3468
Willy Tarreaubaaee002006-06-26 02:48:02 +02003469/*
3470 * Local variables:
3471 * c-indent-level: 8
3472 * c-basic-offset: 8
3473 * End:
3474 */