blob: 2ca3b360069909d8259f2c672776ca7231595acc [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 Tarreaub363a1f2013-10-01 10:45:07 +0200558 struct connection *srv_conn = __objt_conn(si->end);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100559
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100560 /* If we got an error, or if nothing happened and the connection timed
561 * out, we must give up. The CER state handler will take care of retry
562 * attempts and error reports.
563 */
564 if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) {
Willy Tarreau103197d2014-11-28 15:26:12 +0100565 if (unlikely(req->flags & CF_WRITE_PARTIAL)) {
Willy Tarreaue3224e82012-10-29 22:41:31 +0100566 /* Some data were sent past the connection establishment,
567 * so we need to pretend we're established to log correctly
568 * and let later states handle the failure.
569 */
Willy Tarreaue3224e82012-10-29 22:41:31 +0100570 si->state = SI_ST_EST;
571 si->err_type = SI_ET_DATA_ERR;
Willy Tarreau103197d2014-11-28 15:26:12 +0100572 rep->flags |= CF_READ_ERROR | CF_WRITE_ERROR;
Willy Tarreaue3224e82012-10-29 22:41:31 +0100573 return 1;
574 }
Willy Tarreau127334e2009-03-28 10:47:26 +0100575 si->exp = TICK_ETERNITY;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100576 si->state = SI_ST_CER;
Willy Tarreau0ede5a32012-12-08 08:44:02 +0100577
Willy Tarreauf79c8172013-10-21 16:30:56 +0200578 conn_force_close(srv_conn);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100579
580 if (si->err_type)
581 return 0;
582
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100583 if (si->flags & SI_FL_ERR)
584 si->err_type = SI_ET_CONN_ERR;
585 else
586 si->err_type = SI_ET_CONN_TO;
587 return 0;
588 }
589
590 /* OK, maybe we want to abort */
Willy Tarreaua7a7ebc2012-12-30 00:50:35 +0100591 if (!(req->flags & CF_WRITE_PARTIAL) &&
592 unlikely((rep->flags & CF_SHUTW) ||
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200593 ((req->flags & CF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */
594 ((!(req->flags & CF_WRITE_ACTIVITY) && channel_is_empty(req)) ||
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100595 s->be->options & PR_O_ABRT_CLOSE)))) {
596 /* give up */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200597 si_shutw(si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100598 si->err_type |= SI_ET_CONN_ABRT;
Willy Tarreau84455332009-03-15 22:34:05 +0100599 if (s->srv_error)
600 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100601 return 1;
602 }
603
604 /* we need to wait a bit more if there was no activity either */
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200605 if (!(req->flags & CF_WRITE_ACTIVITY))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100606 return 1;
607
608 /* OK, this means that a connection succeeded. The caller will be
609 * responsible for handling the transition from CON to EST.
610 */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100611 si->state = SI_ST_EST;
612 si->err_type = SI_ET_NONE;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100613 return 1;
614}
615
616/* This function is called with (si->state == SI_ST_CER) meaning that a
617 * previous connection attempt has failed and that the file descriptor
618 * has already been released. Possible causes include asynchronous error
619 * notification and time out. Possible output states are SI_ST_CLO when
620 * retries are exhausted, SI_ST_TAR when a delay is wanted before a new
621 * connection attempt, SI_ST_ASS when it's wise to retry on the same server,
622 * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are
623 * marked as in error state. It returns 0.
624 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200625static int sess_update_st_cer(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100626{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100627 struct stream_interface *si = &s->si[1];
628
Willy Tarreau87b09662015-04-03 00:22:06 +0200629 /* we probably have to release last stream from the server */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100630 if (objt_server(s->target)) {
631 health_adjust(objt_server(s->target), HANA_STATUS_L4_ERR);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100632
Willy Tarreaue7dff022015-04-03 01:14:29 +0200633 if (s->flags & SF_CURR_SESS) {
634 s->flags &= ~SF_CURR_SESS;
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100635 objt_server(s->target)->cur_sess--;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100636 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100637 }
638
639 /* ensure that we have enough retries left */
Willy Tarreauee28de02010-06-01 09:51:00 +0200640 si->conn_retries--;
641 if (si->conn_retries < 0) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100642 if (!si->err_type) {
643 si->err_type = SI_ET_CONN_ERR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100644 }
645
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100646 if (objt_server(s->target))
647 objt_server(s->target)->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100648 s->be->be_counters.failed_conns++;
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100649 sess_change_server(s, NULL);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100650 if (may_dequeue_tasks(objt_server(s->target), s->be))
651 process_srv_queue(objt_server(s->target));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100652
653 /* shutw is enough so stop a connecting socket */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200654 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100655 s->req.flags |= CF_WRITE_ERROR;
656 s->res.flags |= CF_READ_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100657
658 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100659 if (s->srv_error)
660 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100661 return 0;
662 }
663
664 /* If the "redispatch" option is set on the backend, we are allowed to
Joseph Lynch726ab712015-05-11 23:25:34 -0700665 * retry on another server. By default this redispatch occurs on the
666 * last retry, but if configured we allow redispatches to occur on
667 * configurable intervals, e.g. on every retry. In order to achieve this,
Willy Tarreau87b09662015-04-03 00:22:06 +0200668 * we must mark the stream unassigned, and eventually clear the DIRECT
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100669 * bit to ignore any persistence cookie. We won't count a retry nor a
670 * redispatch yet, because this will depend on what server is selected.
Willy Tarreau33a14e52014-06-13 17:49:40 +0200671 * If the connection is not persistent, the balancing algorithm is not
672 * determinist (round robin) and there is more than one active server,
673 * we accept to perform an immediate redispatch without waiting since
674 * we don't care about this particular server.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100675 */
Willy Tarreau33a14e52014-06-13 17:49:40 +0200676 if (objt_server(s->target) &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700677 (s->be->options & PR_O_REDISP) && !(s->flags & SF_FORCE_PRST) &&
Willy Tarreau49008c12016-01-13 07:58:44 +0100678 ((__objt_server(s->target)->state < SRV_ST_RUNNING) ||
679 (((s->be->redispatch_after > 0) &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700680 ((s->be->conn_retries - si->conn_retries) %
681 s->be->redispatch_after == 0)) ||
682 ((s->be->redispatch_after < 0) &&
683 ((s->be->conn_retries - si->conn_retries) %
684 (s->be->conn_retries + 1 + s->be->redispatch_after) == 0))) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +0200685 (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 &&
Joseph Lynch726ab712015-05-11 23:25:34 -0700686 ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR)))) {
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100687 sess_change_server(s, NULL);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100688 if (may_dequeue_tasks(objt_server(s->target), s->be))
689 process_srv_queue(objt_server(s->target));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100690
Willy Tarreaue7dff022015-04-03 01:14:29 +0200691 s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100692 si->state = SI_ST_REQ;
693 } else {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100694 if (objt_server(s->target))
695 objt_server(s->target)->counters.retries++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100696 s->be->be_counters.retries++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100697 si->state = SI_ST_ASS;
698 }
699
700 if (si->flags & SI_FL_ERR) {
701 /* The error was an asynchronous connection error, and we will
702 * likely have to retry connecting to the same server, most
703 * likely leading to the same result. To avoid this, we wait
Willy Tarreaub0290662014-06-13 17:04:44 +0200704 * MIN(one second, connect timeout) before retrying.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100705 */
706
Willy Tarreaub0290662014-06-13 17:04:44 +0200707 int delay = 1000;
708
709 if (s->be->timeout.connect && s->be->timeout.connect < delay)
710 delay = s->be->timeout.connect;
711
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100712 if (!si->err_type)
713 si->err_type = SI_ET_CONN_ERR;
714
Willy Tarreaudb6d0122014-06-13 17:40:15 +0200715 /* only wait when we're retrying on the same server */
716 if (si->state == SI_ST_ASS ||
717 (s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_RR ||
718 (s->be->srv_act <= 1)) {
719 si->state = SI_ST_TAR;
720 si->exp = tick_add(now_ms, MS_TO_TICKS(delay));
721 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100722 return 0;
723 }
724 return 0;
725}
726
727/*
728 * This function handles the transition between the SI_ST_CON state and the
Willy Tarreau85e7d002010-05-31 11:57:51 +0200729 * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or
Willy Tarreau26d8c592012-05-07 18:12:14 +0200730 * SI_ST_INI) to SI_ST_EST, but only when a ->proto is defined.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100731 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200732static void sess_establish(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100733{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100734 struct stream_interface *si = &s->si[1];
735 struct channel *req = &s->req;
736 struct channel *rep = &s->res;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100737
Willy Tarreau0e37f1c2013-12-31 23:06:46 +0100738 /* First, centralize the timers information */
739 s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
740 si->exp = TICK_ETERNITY;
741
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100742 if (objt_server(s->target))
743 health_adjust(objt_server(s->target), HANA_STATUS_L4_OK);
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100744
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100745 if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100746 /* if the user wants to log as soon as possible, without counting
747 * bytes from the server, then this is the right moment. */
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200748 if (!LIST_ISEMPTY(&strm_fe(s)->logformat) && !(s->logs.logwait & LW_BYTES)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100749 s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
Willy Tarreaua5555ec2008-11-30 19:02:32 +0100750 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100751 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100752 }
753 else {
Willy Tarreaud81ca042013-12-31 22:33:13 +0100754 rep->flags |= CF_READ_DONTWAIT; /* a single read is enough to get response headers */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100755 }
756
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200757 rep->analysers |= strm_fe(s)->fe_rsp_ana | s->be->be_rsp_ana;
Christopher Faulet309c6412015-12-02 09:57:32 +0100758
759 /* Be sure to filter response headers if the backend is an HTTP proxy
760 * and if there are filters attached to the stream. */
761 if (s->be->mode == PR_MODE_HTTP && HAS_FILTERS(s))
762 rep->analysers |= AN_FLT_HTTP_HDRS;
763
Willy Tarreau03cdb7c2012-08-27 23:14:58 +0200764 rep->flags |= CF_READ_ATTACHED; /* producer is now attached */
Willy Tarreau644c1012014-04-30 18:11:11 +0200765 if (req->flags & CF_WAKE_CONNECT) {
766 req->flags |= CF_WAKE_ONCE;
767 req->flags &= ~CF_WAKE_CONNECT;
768 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200769 if (objt_conn(si->end)) {
Willy Tarreaud04e8582010-05-31 12:31:35 +0200770 /* real connections have timeouts */
771 req->wto = s->be->timeout.server;
772 rep->rto = s->be->timeout.server;
773 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100774 req->wex = TICK_ETERNITY;
775}
776
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700777/* Check if the connection request is in such a state that it can be aborted. */
778static int check_req_may_abort(struct channel *req, struct stream *s)
779{
780 return ((req->flags & (CF_READ_ERROR)) ||
781 ((req->flags & CF_SHUTW_NOW) && /* empty and client aborted */
782 (channel_is_empty(req) || s->be->options & PR_O_ABRT_CLOSE)));
783}
784
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100785/* Update back stream interface status for input states SI_ST_ASS, SI_ST_QUE,
786 * SI_ST_TAR. Other input states are simply ignored.
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +0100787 * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON
788 * and SI_ST_EST. Flags must have previously been updated for timeouts and other
789 * conditions.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100790 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200791static void sess_update_stream_int(struct stream *s)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100792{
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100793 struct server *srv = objt_server(s->target);
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100794 struct stream_interface *si = &s->si[1];
Willy Tarreau103197d2014-11-28 15:26:12 +0100795 struct channel *req = &s->req;
Willy Tarreau827aee92011-03-10 16:55:02 +0100796
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100797 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 +0100798 now_ms, __FUNCTION__,
799 s,
CJ Ess6eac32e2015-05-02 16:35:24 -0400800 req, &s->res,
Willy Tarreau103197d2014-11-28 15:26:12 +0100801 req->rex, s->res.wex,
802 req->flags, s->res.flags,
CJ Ess6eac32e2015-05-02 16:35:24 -0400803 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 +0100804
805 if (si->state == SI_ST_ASS) {
806 /* Server assigned to connection request, we have to try to connect now */
807 int conn_err;
808
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700809 /* Before we try to initiate the connection, see if the
810 * request may be aborted instead.
811 */
812 if (check_req_may_abort(req, s)) {
813 si->err_type |= SI_ET_CONN_ABRT;
814 goto abort_connection;
815 }
816
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100817 conn_err = connect_server(s);
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100818 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +0100819
Willy Tarreaue7dff022015-04-03 01:14:29 +0200820 if (conn_err == SF_ERR_NONE) {
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +0100821 /* state = SI_ST_CON or SI_ST_EST now */
Willy Tarreau827aee92011-03-10 16:55:02 +0100822 if (srv)
823 srv_inc_sess_ctr(srv);
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -0500824 if (srv)
825 srv_set_sess_last(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100826 return;
827 }
828
829 /* We have received a synchronous error. We might have to
830 * abort, retry immediately or redispatch.
831 */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200832 if (conn_err == SF_ERR_INTERNAL) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100833 if (!si->err_type) {
834 si->err_type = SI_ET_CONN_OTHER;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100835 }
836
Willy Tarreau827aee92011-03-10 16:55:02 +0100837 if (srv)
838 srv_inc_sess_ctr(srv);
839 if (srv)
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -0500840 srv_set_sess_last(srv);
841 if (srv)
Willy Tarreau827aee92011-03-10 16:55:02 +0100842 srv->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100843 s->be->be_counters.failed_conns++;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100844
Willy Tarreau87b09662015-04-03 00:22:06 +0200845 /* release other streams waiting for this server */
Willy Tarreaub89cfca2010-12-29 14:32:28 +0100846 sess_change_server(s, NULL);
Willy Tarreau827aee92011-03-10 16:55:02 +0100847 if (may_dequeue_tasks(srv, s->be))
848 process_srv_queue(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100849
850 /* Failed and not retryable. */
Willy Tarreau73b013b2012-05-21 16:31:45 +0200851 si_shutr(si);
852 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100853 req->flags |= CF_WRITE_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100854
855 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
856
Willy Tarreau87b09662015-04-03 00:22:06 +0200857 /* no stream was ever accounted for this server */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100858 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100859 if (s->srv_error)
860 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100861 return;
862 }
863
864 /* We are facing a retryable error, but we don't want to run a
865 * turn-around now, as the problem is likely a source port
866 * allocation problem, so we want to retry now.
867 */
868 si->state = SI_ST_CER;
869 si->flags &= ~SI_FL_ERR;
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100870 sess_update_st_cer(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100871 /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */
872 return;
873 }
874 else if (si->state == SI_ST_QUE) {
875 /* connection request was queued, check for any update */
876 if (!s->pend_pos) {
877 /* The connection is not in the queue anymore. Either
878 * we have a server connection slot available and we
879 * go directly to the assigned state, or we need to
880 * load-balance first and go to the INI state.
881 */
882 si->exp = TICK_ETERNITY;
Willy Tarreaue7dff022015-04-03 01:14:29 +0200883 if (unlikely(!(s->flags & SF_ASSIGNED)))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100884 si->state = SI_ST_REQ;
885 else {
886 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
887 si->state = SI_ST_ASS;
888 }
889 return;
890 }
891
892 /* Connection request still in queue... */
893 if (si->flags & SI_FL_EXP) {
894 /* ... and timeout expired */
895 si->exp = TICK_ETERNITY;
896 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau827aee92011-03-10 16:55:02 +0100897 if (srv)
898 srv->counters.failed_conns++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100899 s->be->be_counters.failed_conns++;
Willy Tarreau73b013b2012-05-21 16:31:45 +0200900 si_shutr(si);
901 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +0100902 req->flags |= CF_WRITE_TIMEOUT;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100903 if (!si->err_type)
904 si->err_type = SI_ET_QUEUE_TO;
905 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100906 if (s->srv_error)
907 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100908 return;
909 }
910
911 /* Connection remains in queue, check if we have to abort it */
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700912 if (check_req_may_abort(req, s)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100913 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100914 si->err_type |= SI_ET_QUEUE_ABRT;
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700915 goto abort_connection;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100916 }
917
918 /* Nothing changed */
919 return;
920 }
921 else if (si->state == SI_ST_TAR) {
922 /* Connection request might be aborted */
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700923 if (check_req_may_abort(req, s)) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100924 si->err_type |= SI_ET_CONN_ABRT;
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700925 goto abort_connection;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100926 }
927
928 if (!(si->flags & SI_FL_EXP))
929 return; /* still in turn-around */
930
931 si->exp = TICK_ETERNITY;
932
Willy Tarreau87b09662015-04-03 00:22:06 +0200933 /* we keep trying on the same server as long as the stream is
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100934 * marked "assigned".
935 * FIXME: Should we force a redispatch attempt when the server is down ?
936 */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200937 if (s->flags & SF_ASSIGNED)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100938 si->state = SI_ST_ASS;
939 else
940 si->state = SI_ST_REQ;
941 return;
942 }
Frederik Deweerdt6cd8d132016-04-07 09:01:04 -0700943 return;
944
945abort_connection:
946 /* give up */
947 si->exp = TICK_ETERNITY;
948 si_shutr(si);
949 si_shutw(si);
950 si->state = SI_ST_CLO;
951 if (s->srv_error)
952 s->srv_error(s, si);
953 return;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100954}
955
Willy Tarreau87b09662015-04-03 00:22:06 +0200956/* Set correct stream termination flags in case no analyser has done it. It
Simon Hormandec5be42011-06-08 09:19:07 +0900957 * also counts a failed request if the server state has not reached the request
958 * stage.
959 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200960static void sess_set_term_flags(struct stream *s)
Simon Hormandec5be42011-06-08 09:19:07 +0900961{
Willy Tarreaue7dff022015-04-03 01:14:29 +0200962 if (!(s->flags & SF_FINST_MASK)) {
Simon Hormandec5be42011-06-08 09:19:07 +0900963 if (s->si[1].state < SI_ST_REQ) {
964
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200965 strm_fe(s)->fe_counters.failed_req++;
Willy Tarreau2c1068c2015-09-23 12:21:21 +0200966 if (strm_li(s) && strm_li(s)->counters)
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200967 strm_li(s)->counters->failed_req++;
Simon Hormandec5be42011-06-08 09:19:07 +0900968
Willy Tarreaue7dff022015-04-03 01:14:29 +0200969 s->flags |= SF_FINST_R;
Simon Hormandec5be42011-06-08 09:19:07 +0900970 }
971 else if (s->si[1].state == SI_ST_QUE)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200972 s->flags |= SF_FINST_Q;
Simon Hormandec5be42011-06-08 09:19:07 +0900973 else if (s->si[1].state < SI_ST_EST)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200974 s->flags |= SF_FINST_C;
Simon Hormandec5be42011-06-08 09:19:07 +0900975 else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST)
Willy Tarreaue7dff022015-04-03 01:14:29 +0200976 s->flags |= SF_FINST_D;
Simon Hormandec5be42011-06-08 09:19:07 +0900977 else
Willy Tarreaue7dff022015-04-03 01:14:29 +0200978 s->flags |= SF_FINST_L;
Simon Hormandec5be42011-06-08 09:19:07 +0900979 }
980}
981
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100982/* This function initiates a server connection request on a stream interface
Willy Tarreaud84fb5e2013-11-30 09:06:53 +0100983 * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS for
984 * a real connection to a server, indicating that a server has been assigned,
985 * or SI_ST_EST for a successful connection to an applet. It may also return
986 * SI_ST_QUE, or SI_ST_CLO upon error.
Willy Tarreau55a8d0e2008-11-30 18:47:21 +0100987 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200988static void sess_prepare_conn_req(struct stream *s)
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100989{
Willy Tarreau7b8c4f92014-11-28 15:15:44 +0100990 struct stream_interface *si = &s->si[1];
991
Willy Tarreau02d6cfc2012-03-01 18:19:58 +0100992 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 +0100993 now_ms, __FUNCTION__,
994 s,
CJ Ess6eac32e2015-05-02 16:35:24 -0400995 &s->req, &s->res,
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100996 s->req.rex, s->res.wex,
997 s->req.flags, s->res.flags,
CJ Ess6eac32e2015-05-02 16:35:24 -0400998 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 +0100999
1000 if (si->state != SI_ST_REQ)
1001 return;
1002
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001003 if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) {
1004 /* the applet directly goes to the EST state */
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001005 struct appctx *appctx = objt_appctx(si->end);
1006
1007 if (!appctx || appctx->applet != __objt_applet(s->target))
1008 appctx = stream_int_register_handler(si, objt_applet(s->target));
1009
1010 if (!appctx) {
1011 /* No more memory, let's immediately abort. Force the
1012 * error code to ignore the ERR_LOCAL which is not a
1013 * real error.
1014 */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001015 s->flags &= ~(SF_ERR_MASK | SF_FINST_MASK);
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001016
1017 si_shutr(si);
1018 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +01001019 s->req.flags |= CF_WRITE_ERROR;
Willy Tarreau6bbb2f62013-12-09 17:14:23 +01001020 si->err_type = SI_ET_CONN_RES;
Willy Tarreau4384ddf2013-12-01 12:25:52 +01001021 si->state = SI_ST_CLO;
1022 if (s->srv_error)
1023 s->srv_error(s, si);
1024 return;
1025 }
1026
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001027 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001028 si->state = SI_ST_EST;
1029 si->err_type = SI_ET_NONE;
Willy Tarreaub9a551e2014-04-23 00:35:17 +02001030 be_set_sess_last(s->be);
Willy Tarreaufac4bd12013-11-30 09:21:49 +01001031 /* let sess_establish() finish the job */
Willy Tarreaud84fb5e2013-11-30 09:06:53 +01001032 return;
1033 }
1034
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001035 /* Try to assign a server */
1036 if (srv_redispatch_connect(s) != 0) {
1037 /* We did not get a server. Either we queued the
1038 * connection request, or we encountered an error.
1039 */
1040 if (si->state == SI_ST_QUE)
1041 return;
1042
1043 /* we did not get any server, let's check the cause */
Willy Tarreau73b013b2012-05-21 16:31:45 +02001044 si_shutr(si);
1045 si_shutw(si);
Willy Tarreau103197d2014-11-28 15:26:12 +01001046 s->req.flags |= CF_WRITE_ERROR;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001047 if (!si->err_type)
1048 si->err_type = SI_ET_CONN_OTHER;
1049 si->state = SI_ST_CLO;
Willy Tarreau0cac36f2008-11-30 20:44:17 +01001050 if (s->srv_error)
1051 s->srv_error(s, si);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001052 return;
1053 }
1054
1055 /* The server is assigned */
1056 s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
1057 si->state = SI_ST_ASS;
Willy Tarreaub9a551e2014-04-23 00:35:17 +02001058 be_set_sess_last(s->be);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001059}
1060
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02001061/* This function parses the use-service action ruleset. It executes
1062 * the associated ACL and set an applet as a stream or txn final node.
1063 * it returns ACT_RET_ERR if an error occurs, the proxy left in
1064 * consistent state. It returns ACT_RET_STOP in succes case because
1065 * use-service must be a terminal action. Returns ACT_RET_YIELD
1066 * if the initialisation function require more data.
1067 */
1068enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
1069 struct session *sess, struct stream *s, int flags)
1070
1071{
1072 struct appctx *appctx;
1073
1074 /* Initialises the applet if it is required. */
1075 if (flags & ACT_FLAG_FIRST) {
1076 /* Register applet. this function schedules the applet. */
1077 s->target = &rule->applet.obj_type;
1078 if (unlikely(!stream_int_register_handler(&s->si[1], objt_applet(s->target))))
1079 return ACT_RET_ERR;
1080
1081 /* Initialise the context. */
1082 appctx = si_appctx(&s->si[1]);
1083 memset(&appctx->ctx, 0, sizeof(appctx->ctx));
1084 appctx->rule = rule;
1085 }
1086 else
1087 appctx = si_appctx(&s->si[1]);
1088
1089 /* Stops the applet sheduling, in case of the init function miss
1090 * some data.
1091 */
1092 appctx_pause(appctx);
1093 si_applet_stop_get(&s->si[1]);
1094
1095 /* Call initialisation. */
1096 if (rule->applet.init)
1097 switch (rule->applet.init(appctx, px, s)) {
1098 case 0: return ACT_RET_ERR;
1099 case 1: break;
1100 default: return ACT_RET_YIELD;
1101 }
1102
1103 /* Now we can schedule the applet. */
1104 si_applet_cant_get(&s->si[1]);
1105 appctx_wakeup(appctx);
1106
1107 if (sess->fe == s->be) /* report it if the request was intercepted by the frontend */
1108 sess->fe->fe_counters.intercepted_req++;
1109
1110 /* The flag SF_ASSIGNED prevent from server assignment. */
1111 s->flags |= SF_ASSIGNED;
1112
1113 return ACT_RET_STOP;
1114}
1115
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001116/* This stream analyser checks the switching rules and changes the backend
Willy Tarreau4de91492010-01-22 19:10:05 +01001117 * if appropriate. The default_backend rule is also considered, then the
1118 * target backend's forced persistence rules are also evaluated last if any.
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001119 * It returns 1 if the processing can continue on next analysers, or zero if it
1120 * either needs more data or wants to immediately abort the request.
1121 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001122static int process_switching_rules(struct stream *s, struct channel *req, int an_bit)
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001123{
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001124 struct persist_rule *prst_rule;
Willy Tarreau192252e2015-04-04 01:47:55 +02001125 struct session *sess = s->sess;
1126 struct proxy *fe = sess->fe;
Willy Tarreau4de91492010-01-22 19:10:05 +01001127
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001128 req->analysers &= ~an_bit;
1129 req->analyse_exp = TICK_ETERNITY;
1130
Willy Tarreau87b09662015-04-03 00:22:06 +02001131 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 +02001132 now_ms, __FUNCTION__,
1133 s,
1134 req,
1135 req->rex, req->wex,
1136 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001137 req->buf->i,
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001138 req->analysers);
1139
1140 /* now check whether we have some switching rules for this request */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001141 if (!(s->flags & SF_BE_ASSIGNED)) {
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001142 struct switching_rule *rule;
1143
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001144 list_for_each_entry(rule, &fe->switching_rules, list) {
Willy Tarreauf51658d2014-04-23 01:21:56 +02001145 int ret = 1;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001146
Willy Tarreauf51658d2014-04-23 01:21:56 +02001147 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001148 ret = acl_exec_cond(rule->cond, fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Willy Tarreauf51658d2014-04-23 01:21:56 +02001149 ret = acl_pass(ret);
1150 if (rule->cond->pol == ACL_COND_UNLESS)
1151 ret = !ret;
1152 }
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001153
1154 if (ret) {
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01001155 /* If the backend name is dynamic, try to resolve the name.
1156 * If we can't resolve the name, or if any error occurs, break
1157 * the loop and fallback to the default backend.
1158 */
1159 struct proxy *backend;
1160
1161 if (rule->dynamic) {
1162 struct chunk *tmp = get_trash_chunk();
1163 if (!build_logline(s, tmp->str, tmp->size, &rule->be.expr))
1164 break;
Willy Tarreau9e0bb102015-05-26 11:24:42 +02001165 backend = proxy_be_by_name(tmp->str);
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01001166 if (!backend)
1167 break;
1168 }
1169 else
1170 backend = rule->be.backend;
1171
Willy Tarreau87b09662015-04-03 00:22:06 +02001172 if (!stream_set_backend(s, backend))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001173 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001174 break;
1175 }
1176 }
1177
1178 /* To ensure correct connection accounting on the backend, we
1179 * have to assign one if it was not set (eg: a listen). This
1180 * measure also takes care of correctly setting the default
1181 * backend if any.
1182 */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001183 if (!(s->flags & SF_BE_ASSIGNED))
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001184 if (!stream_set_backend(s, fe->defbe.be ? fe->defbe.be : s->be))
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001185 goto sw_failed;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001186 }
1187
Willy Tarreaufb356202010-08-03 14:02:05 +02001188 /* 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 +02001189 if (fe == s->be) {
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001190 s->req.analysers &= ~AN_REQ_INSPECT_BE;
1191 s->req.analysers &= ~AN_REQ_HTTP_PROCESS_BE;
Christopher Fauletd7c91962015-04-30 11:48:27 +02001192 s->req.analysers &= ~AN_FLT_START_BE;
Willy Tarreaufb356202010-08-03 14:02:05 +02001193 }
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001194
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001195 /* 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 +02001196 * persistence rule, and report that in the stream.
Willy Tarreau4de91492010-01-22 19:10:05 +01001197 */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001198 list_for_each_entry(prst_rule, &s->be->persist_rules, list) {
Willy Tarreau4de91492010-01-22 19:10:05 +01001199 int ret = 1;
1200
1201 if (prst_rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001202 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 +01001203 ret = acl_pass(ret);
1204 if (prst_rule->cond->pol == ACL_COND_UNLESS)
1205 ret = !ret;
1206 }
1207
1208 if (ret) {
1209 /* no rule, or the rule matches */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001210 if (prst_rule->type == PERSIST_TYPE_FORCE) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001211 s->flags |= SF_FORCE_PRST;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001212 } else {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001213 s->flags |= SF_IGNORE_PRST;
Cyril Bonté47fdd8e2010-04-25 00:00:51 +02001214 }
Willy Tarreau4de91492010-01-22 19:10:05 +01001215 break;
1216 }
1217 }
1218
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001219 return 1;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001220
1221 sw_failed:
1222 /* immediately abort this request in case of allocation failure */
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001223 channel_abort(&s->req);
1224 channel_abort(&s->res);
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001225
Willy Tarreaue7dff022015-04-03 01:14:29 +02001226 if (!(s->flags & SF_ERR_MASK))
1227 s->flags |= SF_ERR_RESOURCE;
1228 if (!(s->flags & SF_FINST_MASK))
1229 s->flags |= SF_FINST_R;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001230
Willy Tarreaueee5b512015-04-03 23:46:31 +02001231 if (s->txn)
1232 s->txn->status = 500;
Christopher Fauletd7c91962015-04-30 11:48:27 +02001233 s->req.analysers &= AN_FLT_END;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +01001234 s->req.analyse_exp = TICK_ETERNITY;
Willy Tarreaubedb9ba2009-07-12 08:27:39 +02001235 return 0;
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02001236}
1237
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001238/* This stream analyser works on a request. It applies all use-server rules on
1239 * it then returns 1. The data must already be present in the buffer otherwise
1240 * they won't match. It always returns 1.
1241 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001242static int process_server_rules(struct stream *s, struct channel *req, int an_bit)
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001243{
1244 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001245 struct session *sess = s->sess;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001246 struct server_rule *rule;
1247
Willy Tarreau87b09662015-04-03 00:22:06 +02001248 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 +02001249 now_ms, __FUNCTION__,
1250 s,
1251 req,
1252 req->rex, req->wex,
1253 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001254 req->buf->i + req->buf->o,
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001255 req->analysers);
1256
Willy Tarreaue7dff022015-04-03 01:14:29 +02001257 if (!(s->flags & SF_ASSIGNED)) {
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001258 list_for_each_entry(rule, &px->server_rules, list) {
1259 int ret;
1260
Willy Tarreau192252e2015-04-04 01:47:55 +02001261 ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001262 ret = acl_pass(ret);
1263 if (rule->cond->pol == ACL_COND_UNLESS)
1264 ret = !ret;
1265
1266 if (ret) {
1267 struct server *srv = rule->srv.ptr;
1268
Willy Tarreau892337c2014-05-13 23:41:20 +02001269 if ((srv->state != SRV_ST_STOPPED) ||
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001270 (px->options & PR_O_PERSIST) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +02001271 (s->flags & SF_FORCE_PRST)) {
1272 s->flags |= SF_DIRECT | SF_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001273 s->target = &srv->obj_type;
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001274 break;
1275 }
1276 /* if the server is not UP, let's go on with next rules
1277 * just in case another one is suited.
1278 */
1279 }
1280 }
1281 }
1282
1283 req->analysers &= ~an_bit;
1284 req->analyse_exp = TICK_ETERNITY;
1285 return 1;
1286}
1287
Emeric Brun1d33b292010-01-04 15:47:17 +01001288/* This stream analyser works on a request. It applies all sticking rules on
1289 * it then returns 1. The data must already be present in the buffer otherwise
1290 * they won't match. It always returns 1.
1291 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001292static int process_sticking_rules(struct stream *s, struct channel *req, int an_bit)
Emeric Brun1d33b292010-01-04 15:47:17 +01001293{
1294 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001295 struct session *sess = s->sess;
Emeric Brun1d33b292010-01-04 15:47:17 +01001296 struct sticking_rule *rule;
1297
Willy Tarreau87b09662015-04-03 00:22:06 +02001298 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 +01001299 now_ms, __FUNCTION__,
1300 s,
1301 req,
1302 req->rex, req->wex,
1303 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001304 req->buf->i,
Emeric Brun1d33b292010-01-04 15:47:17 +01001305 req->analysers);
1306
1307 list_for_each_entry(rule, &px->sticking_rules, list) {
1308 int ret = 1 ;
1309 int i;
1310
Willy Tarreau9667a802013-12-09 12:52:13 +01001311 /* Only the first stick store-request of each table is applied
1312 * and other ones are ignored. The purpose is to allow complex
1313 * configurations which look for multiple entries by decreasing
1314 * order of precision and to stop at the first which matches.
1315 * An example could be a store of the IP address from an HTTP
1316 * header first, then from the source if not found.
1317 */
Emeric Brun1d33b292010-01-04 15:47:17 +01001318 for (i = 0; i < s->store_count; i++) {
1319 if (rule->table.t == s->store[i].table)
1320 break;
1321 }
1322
1323 if (i != s->store_count)
1324 continue;
1325
1326 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001327 ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001328 ret = acl_pass(ret);
1329 if (rule->cond->pol == ACL_COND_UNLESS)
1330 ret = !ret;
1331 }
1332
1333 if (ret) {
1334 struct stktable_key *key;
1335
Willy Tarreau192252e2015-04-04 01:47:55 +02001336 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 +01001337 if (!key)
1338 continue;
1339
1340 if (rule->flags & STK_IS_MATCH) {
1341 struct stksess *ts;
1342
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001343 if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001344 if (!(s->flags & SF_ASSIGNED)) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001345 struct eb32_node *node;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001346 void *ptr;
Emeric Brun1d33b292010-01-04 15:47:17 +01001347
1348 /* srv found in table */
Willy Tarreau13c29de2010-06-06 16:40:39 +02001349 ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID);
1350 node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id));
Emeric Brun1d33b292010-01-04 15:47:17 +01001351 if (node) {
1352 struct server *srv;
1353
1354 srv = container_of(node, struct server, conf.id);
Willy Tarreau892337c2014-05-13 23:41:20 +02001355 if ((srv->state != SRV_ST_STOPPED) ||
Willy Tarreau4de91492010-01-22 19:10:05 +01001356 (px->options & PR_O_PERSIST) ||
Willy Tarreaue7dff022015-04-03 01:14:29 +02001357 (s->flags & SF_FORCE_PRST)) {
1358 s->flags |= SF_DIRECT | SF_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001359 s->target = &srv->obj_type;
Emeric Brun1d33b292010-01-04 15:47:17 +01001360 }
1361 }
1362 }
Emeric Brun85e77c72010-09-23 18:16:52 +02001363 stktable_touch(rule->table.t, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001364 }
1365 }
1366 if (rule->flags & STK_IS_STORE) {
1367 if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
1368 struct stksess *ts;
1369
1370 ts = stksess_new(rule->table.t, key);
1371 if (ts) {
1372 s->store[s->store_count].table = rule->table.t;
1373 s->store[s->store_count++].ts = ts;
1374 }
1375 }
1376 }
1377 }
1378 }
1379
1380 req->analysers &= ~an_bit;
1381 req->analyse_exp = TICK_ETERNITY;
1382 return 1;
1383}
1384
1385/* This stream analyser works on a response. It applies all store rules on it
1386 * then returns 1. The data must already be present in the buffer otherwise
1387 * they won't match. It always returns 1.
1388 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001389static int process_store_rules(struct stream *s, struct channel *rep, int an_bit)
Emeric Brun1d33b292010-01-04 15:47:17 +01001390{
1391 struct proxy *px = s->be;
Willy Tarreau192252e2015-04-04 01:47:55 +02001392 struct session *sess = s->sess;
Emeric Brun1d33b292010-01-04 15:47:17 +01001393 struct sticking_rule *rule;
1394 int i;
Willy Tarreau9667a802013-12-09 12:52:13 +01001395 int nbreq = s->store_count;
Emeric Brun1d33b292010-01-04 15:47:17 +01001396
Willy Tarreau87b09662015-04-03 00:22:06 +02001397 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 +01001398 now_ms, __FUNCTION__,
1399 s,
Willy Tarreau2e2b3eb2010-02-09 20:55:44 +01001400 rep,
1401 rep->rex, rep->wex,
1402 rep->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001403 rep->buf->i,
Willy Tarreau2e2b3eb2010-02-09 20:55:44 +01001404 rep->analysers);
Emeric Brun1d33b292010-01-04 15:47:17 +01001405
1406 list_for_each_entry(rule, &px->storersp_rules, list) {
1407 int ret = 1 ;
Emeric Brun1d33b292010-01-04 15:47:17 +01001408
Willy Tarreau9667a802013-12-09 12:52:13 +01001409 /* Only the first stick store-response of each table is applied
1410 * and other ones are ignored. The purpose is to allow complex
1411 * configurations which look for multiple entries by decreasing
1412 * order of precision and to stop at the first which matches.
1413 * An example could be a store of a set-cookie value, with a
1414 * fallback to a parameter found in a 302 redirect.
1415 *
1416 * The store-response rules are not allowed to override the
1417 * store-request rules for the same table, but they may coexist.
1418 * Thus we can have up to one store-request entry and one store-
1419 * response entry for the same table at any time.
1420 */
1421 for (i = nbreq; i < s->store_count; i++) {
1422 if (rule->table.t == s->store[i].table)
1423 break;
1424 }
1425
1426 /* skip existing entries for this table */
1427 if (i < s->store_count)
1428 continue;
1429
Emeric Brun1d33b292010-01-04 15:47:17 +01001430 if (rule->cond) {
Willy Tarreau192252e2015-04-04 01:47:55 +02001431 ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
Emeric Brun1d33b292010-01-04 15:47:17 +01001432 ret = acl_pass(ret);
1433 if (rule->cond->pol == ACL_COND_UNLESS)
1434 ret = !ret;
1435 }
1436
1437 if (ret) {
1438 struct stktable_key *key;
1439
Willy Tarreau192252e2015-04-04 01:47:55 +02001440 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 +01001441 if (!key)
1442 continue;
1443
Willy Tarreau37e340c2013-12-06 23:05:21 +01001444 if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) {
Emeric Brun1d33b292010-01-04 15:47:17 +01001445 struct stksess *ts;
1446
1447 ts = stksess_new(rule->table.t, key);
1448 if (ts) {
1449 s->store[s->store_count].table = rule->table.t;
Emeric Brun1d33b292010-01-04 15:47:17 +01001450 s->store[s->store_count++].ts = ts;
1451 }
1452 }
1453 }
1454 }
1455
1456 /* process store request and store response */
1457 for (i = 0; i < s->store_count; i++) {
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001458 struct stksess *ts;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001459 void *ptr;
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001460
Willy Tarreauc93cd162014-05-13 15:54:22 +02001461 if (objt_server(s->target) && objt_server(s->target)->flags & SRV_F_NON_STICK) {
Simon Hormanfa461682011-06-25 09:39:49 +09001462 stksess_free(s->store[i].table, s->store[i].ts);
1463 s->store[i].ts = NULL;
1464 continue;
1465 }
1466
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001467 ts = stktable_lookup(s->store[i].table, s->store[i].ts);
1468 if (ts) {
1469 /* the entry already existed, we can free ours */
Emeric Brun85e77c72010-09-23 18:16:52 +02001470 stktable_touch(s->store[i].table, ts, 1);
Emeric Brun1d33b292010-01-04 15:47:17 +01001471 stksess_free(s->store[i].table, s->store[i].ts);
Emeric Brun1d33b292010-01-04 15:47:17 +01001472 }
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001473 else
Emeric Brun85e77c72010-09-23 18:16:52 +02001474 ts = stktable_store(s->store[i].table, s->store[i].ts, 1);
Willy Tarreauf16d2b82010-06-06 15:38:59 +02001475
1476 s->store[i].ts = NULL;
Willy Tarreau13c29de2010-06-06 16:40:39 +02001477 ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID);
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001478 stktable_data_cast(ptr, server_id) = objt_server(s->target)->puid;
Emeric Brun1d33b292010-01-04 15:47:17 +01001479 }
Willy Tarreau2a164ee2010-06-18 09:57:45 +02001480 s->store_count = 0; /* everything is stored */
Emeric Brun1d33b292010-01-04 15:47:17 +01001481
1482 rep->analysers &= ~an_bit;
1483 rep->analyse_exp = TICK_ETERNITY;
1484 return 1;
1485}
1486
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001487/* This macro is very specific to the function below. See the comments in
Willy Tarreau87b09662015-04-03 00:22:06 +02001488 * process_stream() below to understand the logic and the tests.
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001489 */
1490#define UPDATE_ANALYSERS(real, list, back, flag) { \
1491 list = (((list) & ~(flag)) | ~(back)) & (real); \
1492 back = real; \
1493 if (!(list)) \
1494 break; \
1495 if (((list) ^ ((list) & ((list) - 1))) < (flag)) \
1496 continue; \
1497}
1498
Christopher Fauleta9215b72016-05-11 17:06:28 +02001499/* These 2 following macros call an analayzer for the specified channel if the
1500 * right flag is set. The first one is used for "filterable" analyzers. If a
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001501 * stream has some registered filters, pre and post analyaze callbacks are
1502 * called. The second are used for other analyzers (AN_FLT_* and
Christopher Fauleta9215b72016-05-11 17:06:28 +02001503 * AN_REQ/RES_HTTP_XFER_BODY) */
1504#define FLT_ANALYZE(strm, chn, fun, list, back, flag, ...) \
1505 { \
1506 if ((list) & (flag)) { \
1507 if (HAS_FILTERS(strm)) { \
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001508 if (!flt_pre_analyze((strm), (chn), (flag))) \
Christopher Fauleta9215b72016-05-11 17:06:28 +02001509 break; \
1510 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1511 break; \
Christopher Faulet3a394fa2016-05-11 17:13:39 +02001512 if (!flt_post_analyze((strm), (chn), (flag))) \
1513 break; \
Christopher Fauleta9215b72016-05-11 17:06:28 +02001514 } \
1515 else { \
1516 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1517 break; \
1518 } \
1519 UPDATE_ANALYSERS((chn)->analysers, (list), \
1520 (back), (flag)); \
1521 } \
1522 }
1523
1524#define ANALYZE(strm, chn, fun, list, back, flag, ...) \
1525 { \
1526 if ((list) & (flag)) { \
1527 if (!fun((strm), (chn), (flag), ##__VA_ARGS__)) \
1528 break; \
1529 UPDATE_ANALYSERS((chn)->analysers, (list), \
1530 (back), (flag)); \
1531 } \
1532 }
1533
Willy Tarreau87b09662015-04-03 00:22:06 +02001534/* Processes the client, server, request and response jobs of a stream task,
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001535 * then puts it back to the wait queue in a clean state, or cleans up its
1536 * resources if it must be deleted. Returns in <next> the date the task wants
1537 * to be woken up, or TICK_ETERNITY. In order not to call all functions for
1538 * nothing too many times, the request and response buffers flags are monitored
1539 * and each function is called only if at least another function has changed at
1540 * least one flag it is interested in.
1541 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001542struct task *process_stream(struct task *t)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001543{
Willy Tarreau827aee92011-03-10 16:55:02 +01001544 struct server *srv;
Willy Tarreau87b09662015-04-03 00:22:06 +02001545 struct stream *s = t->context;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02001546 struct session *sess = s->sess;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001547 unsigned int rqf_last, rpf_last;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001548 unsigned int rq_prod_last, rq_cons_last;
1549 unsigned int rp_cons_last, rp_prod_last;
Willy Tarreau576507f2010-01-07 00:09:04 +01001550 unsigned int req_ana_back;
Willy Tarreau8f128b42014-11-28 15:07:47 +01001551 struct channel *req, *res;
1552 struct stream_interface *si_f, *si_b;
1553
1554 req = &s->req;
1555 res = &s->res;
1556
1557 si_f = &s->si[0];
1558 si_b = &s->si[1];
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001559
1560 //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 +01001561 // si_f->state, si_b->state, si_b->err_type, req->flags, res->flags);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001562
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001563 /* this data may be no longer valid, clear it */
Willy Tarreaueee5b512015-04-03 23:46:31 +02001564 if (s->txn)
1565 memset(&s->txn->auth, 0, sizeof(s->txn->auth));
Krzysztof Piotr Oledzkif9423ae2010-01-29 19:26:18 +01001566
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02001567 /* This flag must explicitly be set every time */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001568 req->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE);
1569 res->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001570
1571 /* Keep a copy of req/rep flags so that we can detect shutdowns */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001572 rqf_last = req->flags & ~CF_MASK_ANALYSER;
1573 rpf_last = res->flags & ~CF_MASK_ANALYSER;
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001574
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001575 /* we don't want the stream interface functions to recursively wake us up */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001576 si_f->flags |= SI_FL_DONT_WAKE;
1577 si_b->flags |= SI_FL_DONT_WAKE;
Willy Tarreau89f7ef22009-09-05 20:57:35 +02001578
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001579 /* 1a: Check for low level timeouts if needed. We just set a flag on
1580 * stream interfaces when their timeouts have expired.
1581 */
1582 if (unlikely(t->state & TASK_WOKEN_TIMER)) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001583 stream_int_check_timeouts(si_f);
1584 stream_int_check_timeouts(si_b);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001585
Willy Tarreau8263d2b2012-08-28 00:06:31 +02001586 /* check channel timeouts, and close the corresponding stream interfaces
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001587 * for future reads or writes. Note: this will also concern upper layers
1588 * but we do not touch any other flag. We must be careful and correctly
1589 * detect state changes when calling them.
1590 */
1591
Willy Tarreau8f128b42014-11-28 15:07:47 +01001592 channel_check_timeouts(req);
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001593
Willy Tarreau8f128b42014-11-28 15:07:47 +01001594 if (unlikely((req->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
1595 si_b->flags |= SI_FL_NOLINGER;
1596 si_shutw(si_b);
Willy Tarreau14641402009-12-29 14:49:56 +01001597 }
1598
Willy Tarreau8f128b42014-11-28 15:07:47 +01001599 if (unlikely((req->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
1600 if (si_f->flags & SI_FL_NOHALF)
1601 si_f->flags |= SI_FL_NOLINGER;
1602 si_shutr(si_f);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02001603 }
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001604
Willy Tarreau8f128b42014-11-28 15:07:47 +01001605 channel_check_timeouts(res);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001606
Willy Tarreau8f128b42014-11-28 15:07:47 +01001607 if (unlikely((res->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) {
1608 si_f->flags |= SI_FL_NOLINGER;
1609 si_shutw(si_f);
Willy Tarreau14641402009-12-29 14:49:56 +01001610 }
1611
Willy Tarreau8f128b42014-11-28 15:07:47 +01001612 if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
1613 if (si_b->flags & SI_FL_NOHALF)
1614 si_b->flags |= SI_FL_NOLINGER;
1615 si_shutr(si_b);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02001616 }
Willy Tarreau798f4322012-11-08 14:49:17 +01001617
1618 /* Once in a while we're woken up because the task expires. But
1619 * this does not necessarily mean that a timeout has been reached.
Willy Tarreau87b09662015-04-03 00:22:06 +02001620 * So let's not run a whole stream processing if only an expiration
Willy Tarreau798f4322012-11-08 14:49:17 +01001621 * timeout needs to be refreshed.
1622 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001623 if (!((req->flags | res->flags) &
Willy Tarreau798f4322012-11-08 14:49:17 +01001624 (CF_SHUTR|CF_READ_ACTIVITY|CF_READ_TIMEOUT|CF_SHUTW|
1625 CF_WRITE_ACTIVITY|CF_WRITE_TIMEOUT|CF_ANA_TIMEOUT)) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01001626 !((si_f->flags | si_b->flags) & (SI_FL_EXP|SI_FL_ERR)) &&
Willy Tarreau5fb04712016-05-04 10:18:37 +02001627 ((t->state & TASK_WOKEN_ANY) == TASK_WOKEN_TIMER)) {
1628 si_f->flags &= ~SI_FL_DONT_WAKE;
1629 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau798f4322012-11-08 14:49:17 +01001630 goto update_exp_and_leave;
Willy Tarreau5fb04712016-05-04 10:18:37 +02001631 }
Willy Tarreaub67a9b82009-06-21 22:03:51 +02001632 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001633
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001634 /* below we may emit error messages so we have to ensure that we have
1635 * our buffers properly allocated.
1636 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001637 if (!stream_alloc_work_buffer(s)) {
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001638 /* No buffer available, we've been subscribed to the list of
1639 * buffer waiters, let's wait for our turn.
1640 */
Willy Tarreau5fb04712016-05-04 10:18:37 +02001641 si_f->flags &= ~SI_FL_DONT_WAKE;
1642 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau10fc09e2014-11-25 19:46:36 +01001643 goto update_exp_and_leave;
1644 }
1645
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001646 /* 1b: check for low-level errors reported at the stream interface.
1647 * First we check if it's a retryable error (in which case we don't
1648 * want to tell the buffer). Otherwise we report the error one level
1649 * upper by setting flags into the buffers. Note that the side towards
1650 * the client cannot have connect (hence retryable) errors. Also, the
1651 * connection setup code must be able to deal with any type of abort.
1652 */
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001653 srv = objt_server(s->target);
Willy Tarreau8f128b42014-11-28 15:07:47 +01001654 if (unlikely(si_f->flags & SI_FL_ERR)) {
1655 if (si_f->state == SI_ST_EST || si_f->state == SI_ST_DIS) {
1656 si_shutr(si_f);
1657 si_shutw(si_f);
1658 stream_int_report_error(si_f);
1659 if (!(req->analysers) && !(res->analysers)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001660 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001661 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001662 if (srv)
1663 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001664 if (!(s->flags & SF_ERR_MASK))
1665 s->flags |= SF_ERR_CLICL;
1666 if (!(s->flags & SF_FINST_MASK))
1667 s->flags |= SF_FINST_D;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001668 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001669 }
1670 }
1671
Willy Tarreau8f128b42014-11-28 15:07:47 +01001672 if (unlikely(si_b->flags & SI_FL_ERR)) {
1673 if (si_b->state == SI_ST_EST || si_b->state == SI_ST_DIS) {
1674 si_shutr(si_b);
1675 si_shutw(si_b);
1676 stream_int_report_error(si_b);
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001677 s->be->be_counters.failed_resp++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001678 if (srv)
1679 srv->counters.failed_resp++;
Willy Tarreau8f128b42014-11-28 15:07:47 +01001680 if (!(req->analysers) && !(res->analysers)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001681 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001682 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001683 if (srv)
1684 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001685 if (!(s->flags & SF_ERR_MASK))
1686 s->flags |= SF_ERR_SRVCL;
1687 if (!(s->flags & SF_FINST_MASK))
1688 s->flags |= SF_FINST_D;
Willy Tarreau05cb29b2008-12-14 11:44:04 +01001689 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001690 }
1691 /* note: maybe we should process connection errors here ? */
1692 }
1693
Willy Tarreau8f128b42014-11-28 15:07:47 +01001694 if (si_b->state == SI_ST_CON) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001695 /* we were trying to establish a connection on the server side,
1696 * maybe it succeeded, maybe it failed, maybe we timed out, ...
1697 */
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01001698 if (unlikely(!sess_update_st_con_tcp(s)))
1699 sess_update_st_cer(s);
Willy Tarreau8f128b42014-11-28 15:07:47 +01001700 else if (si_b->state == SI_ST_EST)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01001701 sess_establish(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001702
1703 /* state is now one of SI_ST_CON (still in progress), SI_ST_EST
1704 * (established), SI_ST_DIS (abort), SI_ST_CLO (last error),
1705 * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors.
1706 */
1707 }
1708
Willy Tarreau8f128b42014-11-28 15:07:47 +01001709 rq_prod_last = si_f->state;
1710 rq_cons_last = si_b->state;
1711 rp_cons_last = si_f->state;
1712 rp_prod_last = si_b->state;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001713
1714 resync_stream_interface:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001715 /* Check for connection closure */
1716
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001717 DPRINTF(stderr,
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001718 "[%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 +01001719 now_ms, __FUNCTION__, __LINE__,
1720 t,
1721 s, s->flags,
Willy Tarreau8f128b42014-11-28 15:07:47 +01001722 req, res,
1723 req->rex, res->wex,
1724 req->flags, res->flags,
1725 req->buf->i, req->buf->o, res->buf->i, res->buf->o, si_f->state, si_b->state,
1726 si_f->err_type, si_b->err_type,
1727 si_b->conn_retries);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001728
1729 /* nothing special to be done on client side */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001730 if (unlikely(si_f->state == SI_ST_DIS))
1731 si_f->state = SI_ST_CLO;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001732
1733 /* When a server-side connection is released, we have to count it and
1734 * check for pending connections on this server.
1735 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001736 if (unlikely(si_b->state == SI_ST_DIS)) {
1737 si_b->state = SI_ST_CLO;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001738 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001739 if (srv) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001740 if (s->flags & SF_CURR_SESS) {
1741 s->flags &= ~SF_CURR_SESS;
Willy Tarreau827aee92011-03-10 16:55:02 +01001742 srv->cur_sess--;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001743 }
1744 sess_change_server(s, NULL);
Willy Tarreau827aee92011-03-10 16:55:02 +01001745 if (may_dequeue_tasks(srv, s->be))
1746 process_srv_queue(srv);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001747 }
1748 }
1749
1750 /*
1751 * Note: of the transient states (REQ, CER, DIS), only REQ may remain
1752 * at this point.
1753 */
1754
Willy Tarreau0be0ef92009-03-08 19:20:25 +01001755 resync_request:
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001756 /* Analyse request */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001757 if (((req->flags & ~rqf_last) & CF_MASK_ANALYSER) ||
1758 ((req->flags ^ rqf_last) & CF_MASK_STATIC) ||
1759 si_f->state != rq_prod_last ||
1760 si_b->state != rq_cons_last ||
Thierry FOURNIER2e05a8c2014-11-24 14:49:56 +01001761 s->task->state & TASK_WOKEN_MSG) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001762 unsigned int flags = req->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001763
Willy Tarreau8f128b42014-11-28 15:07:47 +01001764 if (si_f->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001765 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001766 unsigned int ana_list;
1767 unsigned int ana_back;
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001768
Willy Tarreau90deb182010-01-07 00:20:41 +01001769 /* it's up to the analysers to stop new connections,
1770 * disable reading or closing. Note: if an analyser
1771 * disables any of these bits, it is responsible for
1772 * enabling them again when it disables itself, so
1773 * that other analysers are called in similar conditions.
1774 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001775 channel_auto_read(req);
1776 channel_auto_connect(req);
1777 channel_auto_close(req);
Willy Tarreauedcf6682008-11-30 23:15:34 +01001778
1779 /* We will call all analysers for which a bit is set in
Willy Tarreau8f128b42014-11-28 15:07:47 +01001780 * req->analysers, following the bit order from LSB
Willy Tarreauedcf6682008-11-30 23:15:34 +01001781 * to MSB. The analysers must remove themselves from
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001782 * the list when not needed. Any analyser may return 0
1783 * to break out of the loop, either because of missing
1784 * data to take a decision, or because it decides to
Willy Tarreau87b09662015-04-03 00:22:06 +02001785 * kill the stream. We loop at least once through each
Willy Tarreau1a52dbd2009-06-28 19:37:53 +02001786 * analyser, and we may loop again if other analysers
1787 * are added in the middle.
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001788 *
1789 * We build a list of analysers to run. We evaluate all
1790 * of these analysers in the order of the lower bit to
1791 * the higher bit. This ordering is very important.
1792 * An analyser will often add/remove other analysers,
1793 * including itself. Any changes to itself have no effect
1794 * on the loop. If it removes any other analysers, we
1795 * want those analysers not to be called anymore during
1796 * this loop. If it adds an analyser that is located
1797 * after itself, we want it to be scheduled for being
1798 * processed during the loop. If it adds an analyser
1799 * which is located before it, we want it to switch to
1800 * it immediately, even if it has already been called
1801 * once but removed since.
1802 *
1803 * In order to achieve this, we compare the analyser
1804 * list after the call with a copy of it before the
1805 * call. The work list is fed with analyser bits that
1806 * appeared during the call. Then we compare previous
1807 * work list with the new one, and check the bits that
1808 * appeared. If the lowest of these bits is lower than
1809 * the current bit, it means we have enabled a previous
1810 * analyser and must immediately loop again.
Willy Tarreauedcf6682008-11-30 23:15:34 +01001811 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001812
Willy Tarreau8f128b42014-11-28 15:07:47 +01001813 ana_list = ana_back = req->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001814 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001815 /* Warning! ensure that analysers are always placed in ascending order! */
Christopher Fauleta9215b72016-05-11 17:06:28 +02001816 ANALYZE (s, req, flt_start_analyze, ana_list, ana_back, AN_FLT_START_FE);
1817 FLT_ANALYZE(s, req, tcp_inspect_request, ana_list, ana_back, AN_REQ_INSPECT_FE);
1818 FLT_ANALYZE(s, req, http_wait_for_request, ana_list, ana_back, AN_REQ_WAIT_HTTP);
1819 FLT_ANALYZE(s, req, http_wait_for_request_body, ana_list, ana_back, AN_REQ_HTTP_BODY);
1820 FLT_ANALYZE(s, req, http_process_req_common, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE, sess->fe);
1821 FLT_ANALYZE(s, req, process_switching_rules, ana_list, ana_back, AN_REQ_SWITCHING_RULES);
1822 ANALYZE (s, req, flt_start_analyze, ana_list, ana_back, AN_FLT_START_BE);
1823 FLT_ANALYZE(s, req, tcp_inspect_request, ana_list, ana_back, AN_REQ_INSPECT_BE);
1824 FLT_ANALYZE(s, req, http_process_req_common, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE, s->be);
1825 FLT_ANALYZE(s, req, http_process_tarpit, ana_list, ana_back, AN_REQ_HTTP_TARPIT);
1826 FLT_ANALYZE(s, req, process_server_rules, ana_list, ana_back, AN_REQ_SRV_RULES);
1827 FLT_ANALYZE(s, req, http_process_request, ana_list, ana_back, AN_REQ_HTTP_INNER);
1828 FLT_ANALYZE(s, req, tcp_persist_rdp_cookie, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE);
1829 FLT_ANALYZE(s, req, process_sticking_rules, ana_list, ana_back, AN_REQ_STICKING_RULES);
1830 ANALYZE (s, req, flt_analyze_http_headers, ana_list, ana_back, AN_FLT_HTTP_HDRS);
1831 ANALYZE (s, req, flt_xfer_data, ana_list, ana_back, AN_FLT_XFER_DATA);
1832 ANALYZE (s, req, http_request_forward_body, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY);
1833 ANALYZE (s, req, flt_end_analyze, ana_list, ana_back, AN_FLT_END);
Willy Tarreaue34070e2010-01-08 00:32:27 +01001834 break;
1835 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01001836 }
Willy Tarreau84455332009-03-15 22:34:05 +01001837
Willy Tarreau8f128b42014-11-28 15:07:47 +01001838 rq_prod_last = si_f->state;
1839 rq_cons_last = si_b->state;
1840 req->flags &= ~CF_WAKE_ONCE;
1841 rqf_last = req->flags;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001842
Willy Tarreau8f128b42014-11-28 15:07:47 +01001843 if ((req->flags ^ flags) & CF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001844 goto resync_request;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001845 }
1846
Willy Tarreau576507f2010-01-07 00:09:04 +01001847 /* we'll monitor the request analysers while parsing the response,
1848 * because some response analysers may indirectly enable new request
1849 * analysers (eg: HTTP keep-alive).
1850 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001851 req_ana_back = req->analysers;
Willy Tarreau576507f2010-01-07 00:09:04 +01001852
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001853 resync_response:
1854 /* Analyse response */
1855
Willy Tarreau8f128b42014-11-28 15:07:47 +01001856 if (((res->flags & ~rpf_last) & CF_MASK_ANALYSER) ||
1857 (res->flags ^ rpf_last) & CF_MASK_STATIC ||
1858 si_f->state != rp_cons_last ||
1859 si_b->state != rp_prod_last ||
Thierry FOURNIER2e05a8c2014-11-24 14:49:56 +01001860 s->task->state & TASK_WOKEN_MSG) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001861 unsigned int flags = res->flags;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001862
Willy Tarreau8f128b42014-11-28 15:07:47 +01001863 if ((res->flags & CF_MASK_ANALYSER) &&
1864 (res->analysers & AN_REQ_ALL)) {
Willy Tarreau0499e352010-12-17 07:13:42 +01001865 /* Due to HTTP pipelining, the HTTP request analyser might be waiting
1866 * for some free space in the response buffer, so we might need to call
1867 * it when something changes in the response buffer, but still we pass
1868 * it the request buffer. Note that the SI state might very well still
1869 * be zero due to us returning a flow of redirects!
1870 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001871 res->analysers &= ~AN_REQ_ALL;
1872 req->flags |= CF_WAKE_ONCE;
Willy Tarreau0499e352010-12-17 07:13:42 +01001873 }
1874
Willy Tarreau8f128b42014-11-28 15:07:47 +01001875 if (si_b->state >= SI_ST_EST) {
Willy Tarreaue34070e2010-01-08 00:32:27 +01001876 int max_loops = global.tune.maxpollevents;
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001877 unsigned int ana_list;
1878 unsigned int ana_back;
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001879
Willy Tarreau90deb182010-01-07 00:20:41 +01001880 /* it's up to the analysers to stop disable reading or
1881 * closing. Note: if an analyser disables any of these
1882 * bits, it is responsible for enabling them again when
1883 * it disables itself, so that other analysers are called
1884 * in similar conditions.
1885 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001886 channel_auto_read(res);
1887 channel_auto_close(res);
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001888
1889 /* We will call all analysers for which a bit is set in
Willy Tarreau8f128b42014-11-28 15:07:47 +01001890 * res->analysers, following the bit order from LSB
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001891 * to MSB. The analysers must remove themselves from
1892 * the list when not needed. Any analyser may return 0
1893 * to break out of the loop, either because of missing
1894 * data to take a decision, or because it decides to
Willy Tarreau87b09662015-04-03 00:22:06 +02001895 * kill the stream. We loop at least once through each
Willy Tarreaub37c27e2009-10-18 22:53:08 +02001896 * analyser, and we may loop again if other analysers
1897 * are added in the middle.
1898 */
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001899
Willy Tarreau8f128b42014-11-28 15:07:47 +01001900 ana_list = ana_back = res->analysers;
Willy Tarreaue34070e2010-01-08 00:32:27 +01001901 while (ana_list && max_loops--) {
Willy Tarreau1e0bbaf2010-01-06 23:53:24 +01001902 /* Warning! ensure that analysers are always placed in ascending order! */
Christopher Fauleta9215b72016-05-11 17:06:28 +02001903 ANALYZE (s, res, flt_start_analyze, ana_list, ana_back, AN_FLT_START_FE);
1904 ANALYZE (s, res, flt_start_analyze, ana_list, ana_back, AN_FLT_START_BE);
1905 FLT_ANALYZE(s, res, tcp_inspect_response, ana_list, ana_back, AN_RES_INSPECT);
1906 FLT_ANALYZE(s, res, http_wait_for_response, ana_list, ana_back, AN_RES_WAIT_HTTP);
1907 FLT_ANALYZE(s, res, process_store_rules, ana_list, ana_back, AN_RES_STORE_RULES);
1908 FLT_ANALYZE(s, res, http_process_res_common, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE, s->be);
1909 ANALYZE (s, res, flt_analyze_http_headers, ana_list, ana_back, AN_FLT_HTTP_HDRS);
1910 ANALYZE (s, res, flt_xfer_data, ana_list, ana_back, AN_FLT_XFER_DATA);
1911 ANALYZE (s, res, http_response_forward_body, ana_list, ana_back, AN_RES_HTTP_XFER_BODY);
1912 ANALYZE (s, res, flt_end_analyze, ana_list, ana_back, AN_FLT_END);
Willy Tarreaue34070e2010-01-08 00:32:27 +01001913 break;
1914 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001915 }
1916
Willy Tarreau8f128b42014-11-28 15:07:47 +01001917 rp_cons_last = si_f->state;
1918 rp_prod_last = si_b->state;
1919 rpf_last = res->flags;
Willy Tarreau815a9b22010-07-27 17:15:12 +02001920
Willy Tarreau8f128b42014-11-28 15:07:47 +01001921 if ((res->flags ^ flags) & CF_MASK_STATIC)
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001922 goto resync_response;
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001923 }
1924
Willy Tarreau576507f2010-01-07 00:09:04 +01001925 /* maybe someone has added some request analysers, so we must check and loop */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001926 if (req->analysers & ~req_ana_back)
Willy Tarreau576507f2010-01-07 00:09:04 +01001927 goto resync_request;
1928
Willy Tarreau8f128b42014-11-28 15:07:47 +01001929 if ((req->flags & ~rqf_last) & CF_MASK_ANALYSER)
Willy Tarreau0499e352010-12-17 07:13:42 +01001930 goto resync_request;
1931
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001932 /* FIXME: here we should call protocol handlers which rely on
1933 * both buffers.
1934 */
1935
1936
1937 /*
Willy Tarreau87b09662015-04-03 00:22:06 +02001938 * Now we propagate unhandled errors to the stream. Normally
Willy Tarreauae526782010-03-04 20:34:23 +01001939 * we're just in a data phase here since it means we have not
1940 * seen any analyser who could set an error status.
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001941 */
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001942 srv = objt_server(s->target);
Willy Tarreaue7dff022015-04-03 01:14:29 +02001943 if (unlikely(!(s->flags & SF_ERR_MASK))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01001944 if (req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001945 /* Report it if the client got an error or a read timeout expired */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001946 req->analysers = 0;
1947 if (req->flags & CF_READ_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001948 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001949 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001950 if (srv)
1951 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001952 s->flags |= SF_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01001953 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001954 else if (req->flags & CF_READ_TIMEOUT) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001955 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001956 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001957 if (srv)
1958 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001959 s->flags |= SF_ERR_CLITO;
Willy Tarreauae526782010-03-04 20:34:23 +01001960 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001961 else if (req->flags & CF_WRITE_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001962 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001963 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001964 if (srv)
1965 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001966 s->flags |= SF_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001967 }
1968 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001969 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001970 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001971 if (srv)
1972 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001973 s->flags |= SF_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001974 }
Willy Tarreau84455332009-03-15 22:34:05 +01001975 sess_set_term_flags(s);
1976 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001977 else if (res->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) {
Willy Tarreau3deb3d02009-06-21 22:43:05 +02001978 /* Report it if the server got an error or a read timeout expired */
Willy Tarreau8f128b42014-11-28 15:07:47 +01001979 res->analysers = 0;
1980 if (res->flags & CF_READ_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001981 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001982 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001983 if (srv)
1984 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001985 s->flags |= SF_ERR_SRVCL;
Willy Tarreauae526782010-03-04 20:34:23 +01001986 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001987 else if (res->flags & CF_READ_TIMEOUT) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001988 s->be->be_counters.srv_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001989 sess->fe->fe_counters.srv_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001990 if (srv)
1991 srv->counters.srv_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001992 s->flags |= SF_ERR_SRVTO;
Willy Tarreauae526782010-03-04 20:34:23 +01001993 }
Willy Tarreau8f128b42014-11-28 15:07:47 +01001994 else if (res->flags & CF_WRITE_ERROR) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01001995 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02001996 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01001997 if (srv)
1998 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02001999 s->flags |= SF_ERR_CLICL;
Willy Tarreauae526782010-03-04 20:34:23 +01002000 }
2001 else {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002002 s->be->be_counters.cli_aborts++;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002003 sess->fe->fe_counters.cli_aborts++;
Willy Tarreau827aee92011-03-10 16:55:02 +01002004 if (srv)
2005 srv->counters.cli_aborts++;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002006 s->flags |= SF_ERR_CLITO;
Willy Tarreauae526782010-03-04 20:34:23 +01002007 }
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002008 sess_set_term_flags(s);
2009 }
Willy Tarreau84455332009-03-15 22:34:05 +01002010 }
2011
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002012 /*
2013 * Here we take care of forwarding unhandled data. This also includes
2014 * connection establishments and shutdown requests.
2015 */
2016
2017
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002018 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02002019 * everything. We configure the buffer to forward indefinitely.
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002020 * Note that we're checking CF_SHUTR_NOW as an indication of a possible
Willy Tarreau8263d2b2012-08-28 00:06:31 +02002021 * recent call to channel_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002022 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002023 if (unlikely(!req->analysers &&
2024 !(req->flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
2025 (si_f->state >= SI_ST_EST) &&
2026 (req->to_forward != CHN_INFINITE_FORWARD))) {
Willy Tarreaub31c9712012-11-11 23:05:39 +01002027 /* This buffer is freewheeling, there's no analyser
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002028 * attached to it. If any data are left in, we'll permit them to
2029 * move.
2030 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002031 channel_auto_read(req);
2032 channel_auto_connect(req);
2033 channel_auto_close(req);
2034 buffer_flush(req->buf);
Willy Tarreau5bd8c372009-01-19 00:32:22 +01002035
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01002036 /* We'll let data flow between the producer (if still connected)
2037 * to the consumer (which might possibly not be connected yet).
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002038 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002039 if (!(req->flags & (CF_SHUTR|CF_SHUTW_NOW)))
Willy Tarreau8bf242b2016-05-04 14:05:58 +02002040 channel_forward_forever(req);
Willy Tarreau42529c32015-07-09 18:38:57 +02002041
2042 /* Just in order to support fetching HTTP contents after start
2043 * of forwarding when the HTTP forwarding analyser is not used,
2044 * we simply reset msg->sov so that HTTP rewinding points to the
2045 * headers.
2046 */
2047 if (s->txn)
2048 s->txn->req.sov = s->txn->req.eoh + s->txn->req.eol - req->buf->o;
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002049 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01002050
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002051 /* check if it is wise to enable kernel splicing to forward request data */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002052 if (!(req->flags & (CF_KERN_SPLICING|CF_SHUTR)) &&
2053 req->to_forward &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002054 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002055 (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->rcv_pipe) &&
2056 (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 +01002057 (pipes_used < global.maxpipes) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002058 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
2059 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002060 (req->flags & CF_STREAMER_FAST)))) {
2061 req->flags |= CF_KERN_SPLICING;
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002062 }
2063
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002064 /* reflect what the L7 analysers have seen last */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002065 rqf_last = req->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002066
2067 /*
2068 * Now forward all shutdown requests between both sides of the buffer
2069 */
2070
Willy Tarreau520d95e2009-09-19 21:04:57 +02002071 /* first, let's check if the request buffer needs to shutdown(write), which may
2072 * happen either because the input is closed or because we want to force a close
Willy Tarreau05cdd962014-05-10 14:30:07 +02002073 * once the server has begun to respond. If a half-closed timeout is set, we adjust
2074 * the other side's timeout as well.
Willy Tarreau520d95e2009-09-19 21:04:57 +02002075 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002076 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) ==
Willy Tarreau05cdd962014-05-10 14:30:07 +02002077 (CF_AUTO_CLOSE|CF_SHUTR))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002078 channel_shutw_now(req);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002079 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002080
2081 /* shutdown(write) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002082 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
2083 channel_is_empty(req))) {
2084 if (req->flags & CF_READ_ERROR)
2085 si_b->flags |= SI_FL_NOLINGER;
2086 si_shutw(si_b);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002087 if (tick_isset(s->be->timeout.serverfin)) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002088 res->rto = s->be->timeout.serverfin;
2089 res->rex = tick_add(now_ms, res->rto);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002090 }
Willy Tarreau8615c2a2013-06-21 08:20:19 +02002091 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002092
2093 /* shutdown(write) done on server side, we must stop the client too */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002094 if (unlikely((req->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW &&
2095 !req->analysers))
2096 channel_shutr_now(req);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002097
2098 /* shutdown(read) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002099 if (unlikely((req->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
2100 if (si_f->flags & SI_FL_NOHALF)
2101 si_f->flags |= SI_FL_NOLINGER;
2102 si_shutr(si_f);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02002103 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002104
Willy Tarreau520d95e2009-09-19 21:04:57 +02002105 /* it's possible that an upper layer has requested a connection setup or abort.
2106 * There are 2 situations where we decide to establish a new connection :
2107 * - there are data scheduled for emission in the buffer
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002108 * - the CF_AUTO_CONNECT flag is set (active connection)
Willy Tarreau520d95e2009-09-19 21:04:57 +02002109 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002110 if (si_b->state == SI_ST_INI) {
2111 if (!(req->flags & CF_SHUTW)) {
2112 if ((req->flags & CF_AUTO_CONNECT) || !channel_is_empty(req)) {
Willy Tarreaucf644ed2013-09-29 17:19:56 +02002113 /* If we have an appctx, there is no connect method, so we
2114 * immediately switch to the connected state, otherwise we
2115 * perform a connection request.
Willy Tarreau520d95e2009-09-19 21:04:57 +02002116 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002117 si_b->state = SI_ST_REQ; /* new connection requested */
2118 si_b->conn_retries = s->be->conn_retries;
Willy Tarreau520d95e2009-09-19 21:04:57 +02002119 }
Willy Tarreau73201222009-08-16 18:27:24 +02002120 }
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02002121 else {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002122 si_b->state = SI_ST_CLO; /* shutw+ini = abort */
2123 channel_shutw_now(req); /* fix buffer flags upon abort */
2124 channel_shutr_now(res);
Willy Tarreauf41ffdc2009-09-20 08:19:25 +02002125 }
Willy Tarreau92795622009-03-06 12:51:23 +01002126 }
2127
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002128
2129 /* we may have a pending connection request, or a connection waiting
2130 * for completion.
2131 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002132 if (si_b->state >= SI_ST_REQ && si_b->state < SI_ST_CON) {
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02002133
2134 /* prune the request variables and swap to the response variables. */
2135 if (s->vars_reqres.scope != SCOPE_RES) {
Willy Tarreau6204cd92016-03-10 16:33:04 +01002136 vars_prune(&s->vars_reqres, s->sess, s);
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02002137 vars_init(&s->vars_reqres, SCOPE_RES);
2138 }
2139
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002140 do {
2141 /* nb: step 1 might switch from QUE to ASS, but we first want
2142 * to give a chance to step 2 to perform a redirect if needed.
2143 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002144 if (si_b->state != SI_ST_REQ)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002145 sess_update_stream_int(s);
Willy Tarreau8f128b42014-11-28 15:07:47 +01002146 if (si_b->state == SI_ST_REQ)
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002147 sess_prepare_conn_req(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002148
Willy Tarreau9e5a3aa2013-12-31 23:32:12 +01002149 /* applets directly go to the ESTABLISHED state. Similarly,
2150 * servers experience the same fate when their connection
2151 * is reused.
2152 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002153 if (unlikely(si_b->state == SI_ST_EST))
Willy Tarreau7b8c4f92014-11-28 15:15:44 +01002154 sess_establish(s);
Willy Tarreaufac4bd12013-11-30 09:21:49 +01002155
Willy Tarreaub44c8732013-12-31 23:16:50 +01002156 /* Now we can add the server name to a header (if requested) */
2157 /* check for HTTP mode and proxy server_name_hdr_name != NULL */
Willy Tarreau9c03b332015-09-07 19:32:33 +02002158 if ((si_b->state >= SI_ST_CON) && (si_b->state < SI_ST_CLO) &&
Willy Tarreaub44c8732013-12-31 23:16:50 +01002159 (s->be->server_id_hdr_name != NULL) &&
2160 (s->be->mode == PR_MODE_HTTP) &&
2161 objt_server(s->target)) {
Willy Tarreaueee5b512015-04-03 23:46:31 +02002162 http_send_name_header(s->txn, s->be, objt_server(s->target)->id);
Willy Tarreau1e5dfda2013-04-07 18:19:16 +02002163 }
2164
Willy Tarreau3fdb3662012-11-12 00:42:33 +01002165 srv = objt_server(s->target);
Willy Tarreaue7dff022015-04-03 01:14:29 +02002166 if (si_b->state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE))
Willy Tarreau8f128b42014-11-28 15:07:47 +01002167 http_perform_server_redirect(s, si_b);
2168 } while (si_b->state == SI_ST_ASS);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002169 }
2170
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002171 /* Benchmarks have shown that it's optimal to do a full resync now */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002172 if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002173 goto resync_stream_interface;
2174
Willy Tarreau815a9b22010-07-27 17:15:12 +02002175 /* otherwise we want to check if we need to resync the req buffer or not */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002176 if ((req->flags ^ rqf_last) & CF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002177 goto resync_request;
2178
Willy Tarreau3deb3d02009-06-21 22:43:05 +02002179 /* perform output updates to the response buffer */
Willy Tarreau84455332009-03-15 22:34:05 +01002180
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002181 /* If noone is interested in analysing data, it's time to forward
Willy Tarreau31971e52009-09-20 12:07:52 +02002182 * everything. We configure the buffer to forward indefinitely.
Willy Tarreau03cdb7c2012-08-27 23:14:58 +02002183 * Note that we're checking CF_SHUTR_NOW as an indication of a possible
Willy Tarreau8263d2b2012-08-28 00:06:31 +02002184 * recent call to channel_abort().
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002185 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002186 if (unlikely(!res->analysers &&
2187 !(res->flags & (CF_SHUTW|CF_SHUTR_NOW)) &&
2188 (si_b->state >= SI_ST_EST) &&
2189 (res->to_forward != CHN_INFINITE_FORWARD))) {
Willy Tarreaub31c9712012-11-11 23:05:39 +01002190 /* This buffer is freewheeling, there's no analyser
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002191 * attached to it. If any data are left in, we'll permit them to
2192 * move.
2193 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002194 channel_auto_read(res);
2195 channel_auto_close(res);
2196 buffer_flush(res->buf);
Willy Tarreauda4d9fe2010-11-07 20:26:56 +01002197
2198 /* We'll let data flow between the producer (if still connected)
2199 * to the consumer.
2200 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002201 if (!(res->flags & (CF_SHUTR|CF_SHUTW_NOW)))
Willy Tarreau8bf242b2016-05-04 14:05:58 +02002202 channel_forward_forever(res);
Willy Tarreauce887fd2012-05-12 12:50:00 +02002203
Willy Tarreau42529c32015-07-09 18:38:57 +02002204 /* Just in order to support fetching HTTP contents after start
2205 * of forwarding when the HTTP forwarding analyser is not used,
2206 * we simply reset msg->sov so that HTTP rewinding points to the
2207 * headers.
2208 */
2209 if (s->txn)
2210 s->txn->rsp.sov = s->txn->rsp.eoh + s->txn->rsp.eol - res->buf->o;
2211
Willy Tarreauce887fd2012-05-12 12:50:00 +02002212 /* if we have no analyser anymore in any direction and have a
Willy Tarreau05cdd962014-05-10 14:30:07 +02002213 * tunnel timeout set, use it now. Note that we must respect
2214 * the half-closed timeouts as well.
Willy Tarreauce887fd2012-05-12 12:50:00 +02002215 */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002216 if (!req->analysers && s->be->timeout.tunnel) {
2217 req->rto = req->wto = res->rto = res->wto =
Willy Tarreauce887fd2012-05-12 12:50:00 +02002218 s->be->timeout.tunnel;
Willy Tarreau05cdd962014-05-10 14:30:07 +02002219
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002220 if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin))
2221 res->wto = sess->fe->timeout.clientfin;
Willy Tarreau8f128b42014-11-28 15:07:47 +01002222 if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin))
2223 res->rto = s->be->timeout.serverfin;
2224 if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin))
2225 req->wto = s->be->timeout.serverfin;
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002226 if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin))
2227 req->rto = sess->fe->timeout.clientfin;
Willy Tarreau05cdd962014-05-10 14:30:07 +02002228
Willy Tarreau8f128b42014-11-28 15:07:47 +01002229 req->rex = tick_add(now_ms, req->rto);
2230 req->wex = tick_add(now_ms, req->wto);
2231 res->rex = tick_add(now_ms, res->rto);
2232 res->wex = tick_add(now_ms, res->wto);
Willy Tarreauce887fd2012-05-12 12:50:00 +02002233 }
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002234 }
Willy Tarreauf890dc92008-12-13 21:12:26 +01002235
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002236 /* check if it is wise to enable kernel splicing to forward response data */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002237 if (!(res->flags & (CF_KERN_SPLICING|CF_SHUTR)) &&
2238 res->to_forward &&
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002239 (global.tune.options & GTUNE_USE_SPLICE) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002240 (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->snd_pipe) &&
2241 (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 +01002242 (pipes_used < global.maxpipes) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002243 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
2244 (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
Willy Tarreau8f128b42014-11-28 15:07:47 +01002245 (res->flags & CF_STREAMER_FAST)))) {
2246 res->flags |= CF_KERN_SPLICING;
Willy Tarreau7c84bab2009-03-08 21:38:23 +01002247 }
2248
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002249 /* reflect what the L7 analysers have seen last */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002250 rpf_last = res->flags;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002251
2252 /*
2253 * Now forward all shutdown requests between both sides of the buffer
2254 */
2255
2256 /*
2257 * FIXME: this is probably where we should produce error responses.
2258 */
2259
Willy Tarreau6b66f3e2008-12-14 17:31:54 +01002260 /* first, let's check if the response buffer needs to shutdown(write) */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002261 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) ==
Willy Tarreau05cdd962014-05-10 14:30:07 +02002262 (CF_AUTO_CLOSE|CF_SHUTR))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002263 channel_shutw_now(res);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002264 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002265
2266 /* shutdown(write) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002267 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
2268 channel_is_empty(res))) {
2269 si_shutw(si_f);
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002270 if (tick_isset(sess->fe->timeout.clientfin)) {
2271 req->rto = sess->fe->timeout.clientfin;
Willy Tarreau8f128b42014-11-28 15:07:47 +01002272 req->rex = tick_add(now_ms, req->rto);
Willy Tarreau05cdd962014-05-10 14:30:07 +02002273 }
2274 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002275
2276 /* shutdown(write) done on the client side, we must stop the server too */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002277 if (unlikely((res->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW) &&
2278 !res->analysers)
2279 channel_shutr_now(res);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002280
2281 /* shutdown(read) pending */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002282 if (unlikely((res->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) {
2283 if (si_b->flags & SI_FL_NOHALF)
2284 si_b->flags |= SI_FL_NOLINGER;
2285 si_shutr(si_b);
Willy Tarreau7bb68ab2012-05-13 14:48:59 +02002286 }
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002287
Willy Tarreau8f128b42014-11-28 15:07:47 +01002288 if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002289 goto resync_stream_interface;
2290
Willy Tarreau8f128b42014-11-28 15:07:47 +01002291 if (req->flags != rqf_last)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002292 goto resync_request;
2293
Willy Tarreau8f128b42014-11-28 15:07:47 +01002294 if ((res->flags ^ rpf_last) & CF_MASK_STATIC)
Willy Tarreau0be0ef92009-03-08 19:20:25 +01002295 goto resync_response;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002296
Willy Tarreau89f7ef22009-09-05 20:57:35 +02002297 /* we're interested in getting wakeups again */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002298 si_f->flags &= ~SI_FL_DONT_WAKE;
2299 si_b->flags &= ~SI_FL_DONT_WAKE;
Willy Tarreau89f7ef22009-09-05 20:57:35 +02002300
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002301 /* This is needed only when debugging is enabled, to indicate
2302 * client-side or server-side close. Please note that in the unlikely
2303 * event where both sides would close at once, the sequence is reported
2304 * on the server side first.
2305 */
2306 if (unlikely((global.mode & MODE_DEBUG) &&
2307 (!(global.mode & MODE_QUIET) ||
2308 (global.mode & MODE_VERBOSE)))) {
Willy Tarreau8f128b42014-11-28 15:07:47 +01002309 if (si_b->state == SI_ST_CLO &&
2310 si_b->prev_state == SI_ST_EST) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002311 chunk_printf(&trash, "%08x:%s.srvcls[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002312 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002313 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2314 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002315 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002316 }
2317
Willy Tarreau8f128b42014-11-28 15:07:47 +01002318 if (si_f->state == SI_ST_CLO &&
2319 si_f->prev_state == SI_ST_EST) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002320 chunk_printf(&trash, "%08x:%s.clicls[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002321 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002322 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2323 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002324 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002325 }
2326 }
2327
Willy Tarreau8f128b42014-11-28 15:07:47 +01002328 if (likely((si_f->state != SI_ST_CLO) ||
2329 (si_b->state > SI_ST_INI && si_b->state < SI_ST_CLO))) {
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002330
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002331 if ((sess->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED))
Willy Tarreau87b09662015-04-03 00:22:06 +02002332 stream_process_counters(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002333
Willy Tarreau563cc372015-04-19 18:13:56 +02002334 if (si_f->state == SI_ST_EST)
Willy Tarreau8f128b42014-11-28 15:07:47 +01002335 si_update(si_f);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002336
Willy Tarreau563cc372015-04-19 18:13:56 +02002337 if (si_b->state == SI_ST_EST)
Willy Tarreau8f128b42014-11-28 15:07:47 +01002338 si_update(si_b);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002339
Willy Tarreau8f128b42014-11-28 15:07:47 +01002340 req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
2341 res->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED);
2342 si_f->prev_state = si_f->state;
2343 si_b->prev_state = si_b->state;
2344 si_f->flags &= ~(SI_FL_ERR|SI_FL_EXP);
2345 si_b->flags &= ~(SI_FL_ERR|SI_FL_EXP);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002346
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02002347 /* Trick: if a request is being waiting for the server to respond,
2348 * and if we know the server can timeout, we don't want the timeout
2349 * to expire on the client side first, but we're still interested
2350 * in passing data from the client to the server (eg: POST). Thus,
2351 * we can cancel the client's request timeout if the server's
2352 * request timeout is set and the server has not yet sent a response.
2353 */
2354
Willy Tarreau8f128b42014-11-28 15:07:47 +01002355 if ((res->flags & (CF_AUTO_CLOSE|CF_SHUTR)) == 0 &&
2356 (tick_isset(req->wex) || tick_isset(res->rex))) {
2357 req->flags |= CF_READ_NOEXP;
2358 req->rex = TICK_ETERNITY;
Willy Tarreau6f0a7ba2014-06-23 15:22:31 +02002359 }
2360
Willy Tarreau798f4322012-11-08 14:49:17 +01002361 update_exp_and_leave:
Willy Tarreau5fb04712016-05-04 10:18:37 +02002362 /* Note: please ensure that if you branch here you disable SI_FL_DONT_WAKE */
Willy Tarreau8f128b42014-11-28 15:07:47 +01002363 t->expire = tick_first(tick_first(req->rex, req->wex),
2364 tick_first(res->rex, res->wex));
2365 if (req->analysers)
2366 t->expire = tick_first(t->expire, req->analyse_exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002367
Willy Tarreau8f128b42014-11-28 15:07:47 +01002368 if (si_f->exp)
2369 t->expire = tick_first(t->expire, si_f->exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002370
Willy Tarreau8f128b42014-11-28 15:07:47 +01002371 if (si_b->exp)
2372 t->expire = tick_first(t->expire, si_b->exp);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002373
2374#ifdef DEBUG_FULL
Willy Tarreau127334e2009-03-28 10:47:26 +01002375 fprintf(stderr,
2376 "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u"
2377 " 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 +01002378 now_ms, t->expire, req->rex, req->wex, req->analyse_exp,
2379 res->rex, res->wex, si_f->exp, si_b->exp, si_f->state, si_b->state);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002380#endif
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002381
2382#ifdef DEBUG_DEV
2383 /* this may only happen when no timeout is set or in case of an FSM bug */
Willy Tarreaud0a201b2009-03-08 15:53:06 +01002384 if (!tick_isset(t->expire))
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002385 ABORT_NOW();
2386#endif
Willy Tarreau87b09662015-04-03 00:22:06 +02002387 stream_release_buffers(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01002388 return t; /* nothing more to do */
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002389 }
2390
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002391 sess->fe->feconn--;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002392 if (s->flags & SF_BE_ASSIGNED)
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002393 s->be->beconn--;
Willy Tarreauaf7ad002010-08-31 15:39:26 +02002394 jobs--;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02002395 if (sess->listener) {
2396 if (!(sess->listener->options & LI_O_UNLIMITED))
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002397 actconn--;
Willy Tarreaufb0afa72015-04-03 14:46:27 +02002398 sess->listener->nbconn--;
2399 if (sess->listener->state == LI_FULL)
2400 resume_listener(sess->listener);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002401
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002402 /* Dequeues all of the listeners waiting for a resource */
2403 if (!LIST_ISEMPTY(&global_listener_queue))
2404 dequeue_all_listeners(&global_listener_queue);
Willy Tarreau08ceb102011-07-24 22:58:00 +02002405
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002406 if (!LIST_ISEMPTY(&sess->fe->listener_queue) &&
2407 (!sess->fe->fe_sps_lim || freq_ctr_remain(&sess->fe->fe_sess_per_sec, sess->fe->fe_sps_lim, 0) > 0))
2408 dequeue_all_listeners(&sess->fe->listener_queue);
Thierry FOURNIERa47a94f2014-03-20 15:42:53 +01002409 }
Willy Tarreau07687c12011-07-24 23:55:06 +02002410
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002411 if (unlikely((global.mode & MODE_DEBUG) &&
2412 (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
Willy Tarreau19d14ef2012-10-29 16:51:55 +01002413 chunk_printf(&trash, "%08x:%s.closed[%04x:%04x]\n",
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002414 s->uniq_id, s->be->id,
Willy Tarreau8f128b42014-11-28 15:07:47 +01002415 objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1,
2416 objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1);
Willy Tarreau89efaed2013-12-13 15:14:55 +01002417 shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002418 }
2419
2420 s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
Willy Tarreau87b09662015-04-03 00:22:06 +02002421 stream_process_counters(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002422
Willy Tarreaueee5b512015-04-03 23:46:31 +02002423 if (s->txn && s->txn->status) {
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002424 int n;
2425
Willy Tarreaueee5b512015-04-03 23:46:31 +02002426 n = s->txn->status / 100;
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002427 if (n < 1 || n > 5)
2428 n = 0;
2429
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002430 if (sess->fe->mode == PR_MODE_HTTP) {
2431 sess->fe->fe_counters.p.http.rsp[n]++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002432 }
Willy Tarreaue7dff022015-04-03 01:14:29 +02002433 if ((s->flags & SF_BE_ASSIGNED) &&
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002434 (s->be->mode == PR_MODE_HTTP)) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +01002435 s->be->be_counters.p.http.rsp[n]++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002436 s->be->be_counters.p.http.cum_req++;
Willy Tarreau5e16cbc2012-11-24 14:54:13 +01002437 }
Krzysztof Piotr Oledzkide71d162009-10-24 15:36:15 +02002438 }
2439
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002440 /* let's do a final log if we need it */
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002441 if (!LIST_ISEMPTY(&sess->fe->logformat) && s->logs.logwait &&
Willy Tarreaue7dff022015-04-03 01:14:29 +02002442 !(s->flags & SF_MONITOR) &&
Willy Tarreaue36cbcb2015-04-03 15:40:56 +02002443 (!(sess->fe->options & PR_O_NULLNOLOG) || req->total)) {
Willy Tarreaua5555ec2008-11-30 19:02:32 +01002444 s->do_log(s);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002445 }
2446
Willy Tarreau87b09662015-04-03 00:22:06 +02002447 /* update time stats for this stream */
2448 stream_update_time_stats(s);
Willy Tarreau4bfc5802014-06-17 12:19:18 +02002449
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002450 /* the task MUST not be in the run queue anymore */
Willy Tarreau87b09662015-04-03 00:22:06 +02002451 stream_free(s);
Willy Tarreau26c25062009-03-08 09:38:41 +01002452 task_delete(t);
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002453 task_free(t);
Willy Tarreau26c25062009-03-08 09:38:41 +01002454 return NULL;
Willy Tarreau55a8d0e2008-11-30 18:47:21 +01002455}
2456
Willy Tarreau87b09662015-04-03 00:22:06 +02002457/* Update the stream's backend and server time stats */
2458void stream_update_time_stats(struct stream *s)
Willy Tarreau4bfc5802014-06-17 12:19:18 +02002459{
2460 int t_request;
2461 int t_queue;
2462 int t_connect;
2463 int t_data;
2464 int t_close;
2465 struct server *srv;
2466
2467 t_request = 0;
2468 t_queue = s->logs.t_queue;
2469 t_connect = s->logs.t_connect;
2470 t_close = s->logs.t_close;
2471 t_data = s->logs.t_data;
2472
2473 if (s->be->mode != PR_MODE_HTTP)
2474 t_data = t_connect;
2475
2476 if (t_connect < 0 || t_data < 0)
2477 return;
2478
2479 if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept))
2480 t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request);
2481
2482 t_data -= t_connect;
2483 t_connect -= t_queue;
2484 t_queue -= t_request;
2485
2486 srv = objt_server(s->target);
2487 if (srv) {
2488 swrate_add(&srv->counters.q_time, TIME_STATS_SAMPLES, t_queue);
2489 swrate_add(&srv->counters.c_time, TIME_STATS_SAMPLES, t_connect);
2490 swrate_add(&srv->counters.d_time, TIME_STATS_SAMPLES, t_data);
2491 swrate_add(&srv->counters.t_time, TIME_STATS_SAMPLES, t_close);
2492 }
2493 swrate_add(&s->be->be_counters.q_time, TIME_STATS_SAMPLES, t_queue);
2494 swrate_add(&s->be->be_counters.c_time, TIME_STATS_SAMPLES, t_connect);
2495 swrate_add(&s->be->be_counters.d_time, TIME_STATS_SAMPLES, t_data);
2496 swrate_add(&s->be->be_counters.t_time, TIME_STATS_SAMPLES, t_close);
2497}
2498
Willy Tarreau7c669d72008-06-20 15:04:11 +02002499/*
2500 * This function adjusts sess->srv_conn and maintains the previous and new
Willy Tarreau87b09662015-04-03 00:22:06 +02002501 * server's served stream counts. Setting newsrv to NULL is enough to release
Willy Tarreau7c669d72008-06-20 15:04:11 +02002502 * current connection slot. This function also notifies any LB algo which might
Willy Tarreau87b09662015-04-03 00:22:06 +02002503 * expect to be informed about any change in the number of active streams on a
Willy Tarreau7c669d72008-06-20 15:04:11 +02002504 * server.
2505 */
Willy Tarreau87b09662015-04-03 00:22:06 +02002506void sess_change_server(struct stream *sess, struct server *newsrv)
Willy Tarreau7c669d72008-06-20 15:04:11 +02002507{
2508 if (sess->srv_conn == newsrv)
2509 return;
2510
2511 if (sess->srv_conn) {
2512 sess->srv_conn->served--;
2513 if (sess->srv_conn->proxy->lbprm.server_drop_conn)
2514 sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
Willy Tarreau87b09662015-04-03 00:22:06 +02002515 stream_del_srv_conn(sess);
Willy Tarreau7c669d72008-06-20 15:04:11 +02002516 }
2517
2518 if (newsrv) {
2519 newsrv->served++;
2520 if (newsrv->proxy->lbprm.server_take_conn)
2521 newsrv->proxy->lbprm.server_take_conn(newsrv);
Willy Tarreau87b09662015-04-03 00:22:06 +02002522 stream_add_srv_conn(sess, newsrv);
Willy Tarreau7c669d72008-06-20 15:04:11 +02002523 }
2524}
2525
Willy Tarreau84455332009-03-15 22:34:05 +01002526/* Handle server-side errors for default protocols. It is called whenever a a
2527 * connection setup is aborted or a request is aborted in queue. It sets the
Willy Tarreau87b09662015-04-03 00:22:06 +02002528 * stream termination flags so that the caller does not have to worry about
Willy Tarreau84455332009-03-15 22:34:05 +01002529 * them. It's installed as ->srv_error for the server-side stream_interface.
2530 */
Willy Tarreau87b09662015-04-03 00:22:06 +02002531void default_srv_error(struct stream *s, struct stream_interface *si)
Willy Tarreau84455332009-03-15 22:34:05 +01002532{
2533 int err_type = si->err_type;
2534 int err = 0, fin = 0;
2535
2536 if (err_type & SI_ET_QUEUE_ABRT) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002537 err = SF_ERR_CLICL;
2538 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002539 }
2540 else if (err_type & SI_ET_CONN_ABRT) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002541 err = SF_ERR_CLICL;
2542 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002543 }
2544 else if (err_type & SI_ET_QUEUE_TO) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002545 err = SF_ERR_SRVTO;
2546 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002547 }
2548 else if (err_type & SI_ET_QUEUE_ERR) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002549 err = SF_ERR_SRVCL;
2550 fin = SF_FINST_Q;
Willy Tarreau84455332009-03-15 22:34:05 +01002551 }
2552 else if (err_type & SI_ET_CONN_TO) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002553 err = SF_ERR_SRVTO;
2554 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002555 }
2556 else if (err_type & SI_ET_CONN_ERR) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002557 err = SF_ERR_SRVCL;
2558 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002559 }
Willy Tarreau2d400bb2012-05-14 12:11:47 +02002560 else if (err_type & SI_ET_CONN_RES) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002561 err = SF_ERR_RESOURCE;
2562 fin = SF_FINST_C;
Willy Tarreau2d400bb2012-05-14 12:11:47 +02002563 }
Willy Tarreau84455332009-03-15 22:34:05 +01002564 else /* SI_ET_CONN_OTHER and others */ {
Willy Tarreaue7dff022015-04-03 01:14:29 +02002565 err = SF_ERR_INTERNAL;
2566 fin = SF_FINST_C;
Willy Tarreau84455332009-03-15 22:34:05 +01002567 }
2568
Willy Tarreaue7dff022015-04-03 01:14:29 +02002569 if (!(s->flags & SF_ERR_MASK))
Willy Tarreau84455332009-03-15 22:34:05 +01002570 s->flags |= err;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002571 if (!(s->flags & SF_FINST_MASK))
Willy Tarreau84455332009-03-15 22:34:05 +01002572 s->flags |= fin;
2573}
Willy Tarreau7c669d72008-06-20 15:04:11 +02002574
Willy Tarreaue7dff022015-04-03 01:14:29 +02002575/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +02002576void stream_shutdown(struct stream *stream, int why)
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002577{
Willy Tarreau87b09662015-04-03 00:22:06 +02002578 if (stream->req.flags & (CF_SHUTW|CF_SHUTW_NOW))
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002579 return;
2580
Willy Tarreau87b09662015-04-03 00:22:06 +02002581 channel_shutw_now(&stream->req);
2582 channel_shutr_now(&stream->res);
2583 stream->task->nice = 1024;
Willy Tarreaue7dff022015-04-03 01:14:29 +02002584 if (!(stream->flags & SF_ERR_MASK))
Willy Tarreau87b09662015-04-03 00:22:06 +02002585 stream->flags |= why;
2586 task_wakeup(stream->task, TASK_WOKEN_OTHER);
Willy Tarreaua2a64e92011-09-07 23:01:56 +02002587}
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +02002588
Willy Tarreau8b22a712010-06-18 17:46:06 +02002589/************************************************************************/
2590/* All supported ACL keywords must be declared here. */
2591/************************************************************************/
2592
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002593/* Returns a pointer to a stkctr depending on the fetch keyword name.
2594 * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively.
Willy Tarreaua65536c2013-07-22 22:40:11 +02002595 * sc[0-9]_* will return a pointer to the respective field in the
Willy Tarreau87b09662015-04-03 00:22:06 +02002596 * stream <l4>. sc_* requires an UINT argument specifying the stick
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002597 * counter number. src_* will fill a locally allocated structure with
Willy Tarreaua65536c2013-07-22 22:40:11 +02002598 * the table and entry corresponding to what is specified with src_*.
Willy Tarreau0f791d42013-07-23 19:56:43 +02002599 * NULL may be returned if the designated stkctr is not tracked. For
2600 * the sc_* and sc[0-9]_* forms, an optional table argument may be
2601 * passed. When present, the currently tracked key is then looked up
2602 * in the specified table instead of the current table. The purpose is
2603 * to be able to convery multiple values per key (eg: have gpc0 from
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002604 * multiple tables). <strm> is allowed to be NULL, in which case only
2605 * the session will be consulted.
Willy Tarreaua65536c2013-07-22 22:40:11 +02002606 */
Willy Tarreaue12704b2014-07-15 19:06:18 +02002607struct stkctr *
Willy Tarreau192252e2015-04-04 01:47:55 +02002608smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw)
Willy Tarreaua65536c2013-07-22 22:40:11 +02002609{
2610 static struct stkctr stkctr;
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002611 struct stkctr *stkptr;
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002612 struct stksess *stksess;
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002613 unsigned int num = kw[2] - '0';
Willy Tarreau0f791d42013-07-23 19:56:43 +02002614 int arg = 0;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002615
Willy Tarreau0f791d42013-07-23 19:56:43 +02002616 if (num == '_' - '0') {
2617 /* sc_* variant, args[0] = ctr# (mandatory) */
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02002618 num = args[arg++].data.sint;
Willy Tarreau4d4149c2013-07-23 19:33:46 +02002619 if (num >= MAX_SESS_STKCTR)
2620 return NULL;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002621 }
Willy Tarreau0f791d42013-07-23 19:56:43 +02002622 else if (num > 9) { /* src_* variant, args[0] = table */
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002623 struct stktable_key *key;
Willy Tarreau9ad7bd42015-04-03 19:19:59 +02002624 struct connection *conn = objt_conn(sess->origin);
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002625 struct sample smp;
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002626
2627 if (!conn)
2628 return NULL;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002629
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002630 /* Fetch source adress in a sample. */
2631 smp.px = NULL;
2632 smp.sess = sess;
2633 smp.strm = strm;
2634 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2635 return NULL;
2636
2637 /* Converts into key. */
2638 key = smp_to_stkey(&smp, &args->data.prx->table);
Willy Tarreaua65536c2013-07-22 22:40:11 +02002639 if (!key)
2640 return NULL;
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002641
Willy Tarreaua65536c2013-07-22 22:40:11 +02002642 stkctr.table = &args->data.prx->table;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002643 stkctr_set_entry(&stkctr, stktable_lookup_key(stkctr.table, key));
Willy Tarreaua65536c2013-07-22 22:40:11 +02002644 return &stkctr;
2645 }
Willy Tarreau0f791d42013-07-23 19:56:43 +02002646
2647 /* Here, <num> contains the counter number from 0 to 9 for
2648 * the sc[0-9]_ form, or even higher using sc_(num) if needed.
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002649 * args[arg] is the first optional argument. We first lookup the
2650 * ctr form the stream, then from the session if it was not there.
Willy Tarreau0f791d42013-07-23 19:56:43 +02002651 */
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002652
Thierry Fournier40e1d512016-03-29 21:27:36 +02002653 if (strm)
2654 stkptr = &strm->stkctr[num];
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002655 if (!strm || !stkctr_entry(stkptr)) {
2656 stkptr = &sess->stkctr[num];
2657 if (!stkctr_entry(stkptr))
2658 return NULL;
2659 }
2660
2661 stksess = stkctr_entry(stkptr);
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002662 if (!stksess)
2663 return NULL;
2664
Willy Tarreau0f791d42013-07-23 19:56:43 +02002665 if (unlikely(args[arg].type == ARGT_TAB)) {
2666 /* an alternate table was specified, let's look up the same key there */
2667 stkctr.table = &args[arg].data.prx->table;
Willy Tarreau6a0b6bd2014-04-09 13:25:42 +02002668 stkctr_set_entry(&stkctr, stktable_lookup(stkctr.table, stksess));
Willy Tarreau0f791d42013-07-23 19:56:43 +02002669 return &stkctr;
2670 }
Willy Tarreau8b7f8682015-04-04 16:29:12 +02002671 return stkptr;
Willy Tarreaua65536c2013-07-22 22:40:11 +02002672}
2673
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002674/* same as smp_fetch_sc_stkctr() but dedicated to src_* and can create
2675 * the entry if it doesn't exist yet. This is needed for a few fetch
2676 * functions which need to create an entry, such as src_inc_gpc* and
2677 * src_clr_gpc*.
2678 */
2679struct stkctr *
2680smp_create_src_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw)
2681{
2682 static struct stkctr stkctr;
2683 struct stktable_key *key;
2684 struct connection *conn = objt_conn(sess->origin);
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002685 struct sample smp;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002686
2687 if (strncmp(kw, "src_", 4) != 0)
2688 return NULL;
2689
2690 if (!conn)
2691 return NULL;
2692
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002693 /* Fetch source adress in a sample. */
2694 smp.px = NULL;
2695 smp.sess = sess;
2696 smp.strm = strm;
2697 if (!smp_fetch_src(NULL, &smp, NULL, NULL))
2698 return NULL;
2699
2700 /* Converts into key. */
2701 key = smp_to_stkey(&smp, &args->data.prx->table);
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002702 if (!key)
2703 return NULL;
2704
2705 stkctr.table = &args->data.prx->table;
2706 stkctr_set_entry(&stkctr, stktable_update_key(stkctr.table, key));
2707 return &stkctr;
2708}
2709
Willy Tarreau87b09662015-04-03 00:22:06 +02002710/* set return a boolean indicating if the requested stream counter is
Willy Tarreau88821242013-07-22 18:29:29 +02002711 * currently being tracked or not.
2712 * Supports being called as "sc[0-9]_tracked" only.
2713 */
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002714static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002715smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002716{
2717 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002718 smp->data.type = SMP_T_BOOL;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002719 smp->data.u.sint = !!smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau6f1615f2013-06-03 15:15:22 +02002720 return 1;
2721}
2722
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002723/* set <smp> to the General Purpose Flag 0 value from the stream's tracked
2724 * frontend counters or from the src.
2725 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpt0" only. Value
2726 * zero is returned if the key is new.
2727 */
2728static int
2729smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw, void *private)
2730{
Willy Tarreaube508f12016-03-10 11:47:01 +01002731 struct stkctr *stkctr;
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002732
Willy Tarreaube508f12016-03-10 11:47:01 +01002733 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Thierry FOURNIER236657b2015-08-19 08:25:14 +02002734 if (!stkctr)
2735 return 0;
2736
2737 smp->flags = SMP_F_VOL_TEST;
2738 smp->data.type = SMP_T_SINT;
2739 smp->data.u.sint = 0;
2740
2741 if (stkctr_entry(stkctr) != NULL) {
2742 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0);
2743 if (!ptr)
2744 return 0; /* parameter not stored */
2745 smp->data.u.sint = stktable_data_cast(ptr, gpt0);
2746 }
2747 return 1;
2748}
2749
Willy Tarreau87b09662015-04-03 00:22:06 +02002750/* set <smp> to the General Purpose Counter 0 value from the stream's tracked
Willy Tarreau30b20462013-07-22 19:46:52 +02002751 * frontend counters or from the src.
2752 * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value
2753 * zero is returned if the key is new.
2754 */
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002755static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002756smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002757{
Willy Tarreaube508f12016-03-10 11:47:01 +01002758 struct stkctr *stkctr;
2759
Willy Tarreaube508f12016-03-10 11:47:01 +01002760 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau30b20462013-07-22 19:46:52 +02002761 if (!stkctr)
2762 return 0;
2763
Willy Tarreau37406352012-04-23 16:16:37 +02002764 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002765 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002766 smp->data.u.sint = 0;
Willy Tarreau30b20462013-07-22 19:46:52 +02002767
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002768 if (stkctr_entry(stkctr) != NULL) {
2769 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002770 if (!ptr)
2771 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002772 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002773 }
2774 return 1;
2775}
2776
Willy Tarreau87b09662015-04-03 00:22:06 +02002777/* set <smp> to the General Purpose Counter 0's event rate from the stream's
Willy Tarreaub5e0af02013-07-22 23:47:07 +02002778 * tracked frontend counters or from the src.
2779 * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only.
2780 * Value zero is returned if the key is new.
2781 */
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002782static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002783smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002784{
Willy Tarreaube508f12016-03-10 11:47:01 +01002785 struct stkctr *stkctr;
2786
Willy Tarreaube508f12016-03-10 11:47:01 +01002787 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaub5e0af02013-07-22 23:47:07 +02002788 if (!stkctr)
2789 return 0;
2790
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002791 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002792 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002793 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002794 if (stkctr_entry(stkctr) != NULL) {
2795 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002796 if (!ptr)
2797 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002798 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002799 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002800 }
2801 return 1;
2802}
2803
Willy Tarreau87b09662015-04-03 00:22:06 +02002804/* Increment the General Purpose Counter 0 value from the stream's tracked
Willy Tarreau710d38c2013-07-23 00:07:04 +02002805 * frontend counters and return it into temp integer.
2806 * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only.
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002807 */
2808static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002809smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002810{
Willy Tarreaube508f12016-03-10 11:47:01 +01002811 struct stkctr *stkctr;
2812
Willy Tarreaube508f12016-03-10 11:47:01 +01002813 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau710d38c2013-07-23 00:07:04 +02002814 if (!stkctr)
2815 return 0;
2816
Willy Tarreau37406352012-04-23 16:16:37 +02002817 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002818 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002819 smp->data.u.sint = 0;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002820
2821 if (stkctr_entry(stkctr) == NULL)
2822 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw);
2823
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002824 if (stkctr_entry(stkctr) != NULL) {
Emeric Brun57056f02015-06-15 18:29:57 +02002825 void *ptr1,*ptr2;
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002826
2827 /* First, update gpc0_rate if it's tracked. Second, update its
2828 * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr.
2829 */
Emeric Brun57056f02015-06-15 18:29:57 +02002830 ptr1 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE);
2831 if (ptr1) {
2832 update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate),
Willy Tarreau710d38c2013-07-23 00:07:04 +02002833 stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1);
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002834 smp->data.u.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr;
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002835 }
2836
Emeric Brun57056f02015-06-15 18:29:57 +02002837 ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
2838 if (ptr2)
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002839 smp->data.u.sint = ++stktable_data_cast(ptr2, gpc0);
Willy Tarreauba2ffd12013-05-29 15:54:14 +02002840
Emeric Brun57056f02015-06-15 18:29:57 +02002841 /* If data was modified, we need to touch to re-schedule sync */
2842 if (ptr1 || ptr2)
2843 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreauc3bd9722010-06-20 12:47:25 +02002844 }
2845 return 1;
2846}
2847
Willy Tarreau87b09662015-04-03 00:22:06 +02002848/* Clear the General Purpose Counter 0 value from the stream's tracked
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002849 * frontend counters and return its previous value into temp integer.
2850 * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only.
Willy Tarreauf73cd112011-08-13 01:45:16 +02002851 */
2852static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002853smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauf73cd112011-08-13 01:45:16 +02002854{
Willy Tarreaube508f12016-03-10 11:47:01 +01002855 struct stkctr *stkctr;
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002856
Willy Tarreaube508f12016-03-10 11:47:01 +01002857 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaub9f441d2013-07-23 00:10:35 +02002858 if (!stkctr)
2859 return 0;
2860
Willy Tarreau37406352012-04-23 16:16:37 +02002861 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002862 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002863 smp->data.u.sint = 0;
Willy Tarreau0f4eadd2015-08-18 17:15:20 +02002864
2865 if (stkctr_entry(stkctr) == NULL)
2866 stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw);
2867
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002868 if (stkctr_entry(stkctr) != NULL) {
2869 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002870 if (!ptr)
2871 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002872 smp->data.u.sint = stktable_data_cast(ptr, gpc0);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002873 stktable_data_cast(ptr, gpc0) = 0;
Emeric Brun57056f02015-06-15 18:29:57 +02002874 /* If data was modified, we need to touch to re-schedule sync */
2875 stktable_touch(stkctr->table, stkctr_entry(stkctr), 1);
Willy Tarreauf73cd112011-08-13 01:45:16 +02002876 }
2877 return 1;
2878}
2879
Willy Tarreau87b09662015-04-03 00:22:06 +02002880/* set <smp> to the cumulated number of connections from the stream's tracked
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002881 * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or
2882 * "src_conn_cnt" only.
2883 */
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002884static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002885smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002886{
Willy Tarreaube508f12016-03-10 11:47:01 +01002887 struct stkctr *stkctr;
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002888
Willy Tarreaube508f12016-03-10 11:47:01 +01002889 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau3b46c5c2013-07-23 00:22:50 +02002890 if (!stkctr)
2891 return 0;
2892
Willy Tarreau37406352012-04-23 16:16:37 +02002893 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002894 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002895 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002896 if (stkctr_entry(stkctr) != NULL) {
2897 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT);
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002898 if (!ptr)
2899 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002900 smp->data.u.sint = stktable_data_cast(ptr, conn_cnt);
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002901 }
Willy Tarreau9a3f8492010-06-18 19:53:25 +02002902 return 1;
2903}
2904
Willy Tarreau87b09662015-04-03 00:22:06 +02002905/* set <smp> to the connection rate from the stream's tracked frontend
Willy Tarreauc8c65702013-07-23 15:09:35 +02002906 * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate"
2907 * only.
2908 */
Willy Tarreau91c43d72010-06-20 11:19:22 +02002909static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002910smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau91c43d72010-06-20 11:19:22 +02002911{
Willy Tarreaube508f12016-03-10 11:47:01 +01002912 struct stkctr *stkctr;
2913
Willy Tarreaube508f12016-03-10 11:47:01 +01002914 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreauc8c65702013-07-23 15:09:35 +02002915 if (!stkctr)
2916 return 0;
2917
Willy Tarreau37406352012-04-23 16:16:37 +02002918 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002919 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002920 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002921 if (stkctr_entry(stkctr) != NULL) {
2922 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002923 if (!ptr)
2924 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002925 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
Willy Tarreauc8c65702013-07-23 15:09:35 +02002926 stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u);
Willy Tarreau91c43d72010-06-20 11:19:22 +02002927 }
2928 return 1;
2929}
2930
Willy Tarreau87b09662015-04-03 00:22:06 +02002931/* set temp integer to the number of connections from the stream's source address
Willy Tarreau8b22a712010-06-18 17:46:06 +02002932 * in the table pointed to by expr, after updating it.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02002933 * Accepts exactly 1 argument of type table.
Willy Tarreau8b22a712010-06-18 17:46:06 +02002934 */
2935static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002936smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau8b22a712010-06-18 17:46:06 +02002937{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002938 struct connection *conn = objt_conn(smp->sess->origin);
Willy Tarreau8b22a712010-06-18 17:46:06 +02002939 struct stksess *ts;
2940 struct stktable_key *key;
2941 void *ptr;
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02002942 struct proxy *px;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002943
Willy Tarreaub363a1f2013-10-01 10:45:07 +02002944 if (!conn)
2945 return 0;
2946
Thierry FOURNIER7e25df32015-07-24 19:31:59 +02002947 /* Fetch source adress in a sample. */
2948 if (!smp_fetch_src(NULL, smp, NULL, NULL))
2949 return 0;
2950
2951 /* Converts into key. */
2952 key = smp_to_stkey(smp, &args->data.prx->table);
Willy Tarreau8b22a712010-06-18 17:46:06 +02002953 if (!key)
David du Colombier4f92d322011-03-24 11:09:31 +01002954 return 0;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002955
Willy Tarreau24e32d82012-04-23 23:55:44 +02002956 px = args->data.prx;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002957
Willy Tarreau1f7e9252010-06-20 12:27:21 +02002958 if ((ts = stktable_update_key(&px->table, key)) == NULL)
2959 /* entry does not exist and could not be created */
2960 return 0;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002961
2962 ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
2963 if (!ptr)
2964 return 0; /* parameter not stored in this table */
2965
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002966 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002967 smp->data.u.sint = ++stktable_data_cast(ptr, conn_cnt);
Emeric Brun57056f02015-06-15 18:29:57 +02002968 /* Touch was previously performed by stktable_update_key */
Willy Tarreau37406352012-04-23 16:16:37 +02002969 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau8b22a712010-06-18 17:46:06 +02002970 return 1;
2971}
2972
Willy Tarreau87b09662015-04-03 00:22:06 +02002973/* set <smp> to the number of concurrent connections from the stream's tracked
Willy Tarreauf44a5532013-07-23 15:17:53 +02002974 * frontend counters. Supports being called as "sc[0-9]_conn_cur" or
2975 * "src_conn_cur" only.
2976 */
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002977static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02002978smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002979{
Willy Tarreaube508f12016-03-10 11:47:01 +01002980 struct stkctr *stkctr;
2981
Willy Tarreaube508f12016-03-10 11:47:01 +01002982 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreauf44a5532013-07-23 15:17:53 +02002983 if (!stkctr)
2984 return 0;
2985
Willy Tarreau37406352012-04-23 16:16:37 +02002986 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02002987 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002988 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01002989 if (stkctr_entry(stkctr) != NULL) {
2990 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR);
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002991 if (!ptr)
2992 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02002993 smp->data.u.sint = stktable_data_cast(ptr, conn_cur);
Willy Tarreau9b0ddcf2010-06-18 21:14:36 +02002994 }
2995 return 1;
2996}
2997
Willy Tarreau87b09662015-04-03 00:22:06 +02002998/* set <smp> to the cumulated number of streams from the stream's tracked
Willy Tarreau20843082013-07-23 15:35:33 +02002999 * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or
3000 * "src_sess_cnt" only.
3001 */
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003002static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003003smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003004{
Willy Tarreaube508f12016-03-10 11:47:01 +01003005 struct stkctr *stkctr;
3006
Willy Tarreaube508f12016-03-10 11:47:01 +01003007 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau20843082013-07-23 15:35:33 +02003008 if (!stkctr)
3009 return 0;
3010
Willy Tarreau37406352012-04-23 16:16:37 +02003011 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003012 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003013 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003014 if (stkctr_entry(stkctr) != NULL) {
3015 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT);
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003016 if (!ptr)
3017 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003018 smp->data.u.sint = stktable_data_cast(ptr, sess_cnt);
Willy Tarreauf4d17d92010-06-18 22:10:12 +02003019 }
3020 return 1;
3021}
3022
Willy Tarreau87b09662015-04-03 00:22:06 +02003023/* set <smp> to the stream rate from the stream's tracked frontend counters.
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003024 * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only.
3025 */
Willy Tarreau91c43d72010-06-20 11:19:22 +02003026static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003027smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau91c43d72010-06-20 11:19:22 +02003028{
Willy Tarreaube508f12016-03-10 11:47:01 +01003029 struct stkctr *stkctr;
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003030
Willy Tarreaube508f12016-03-10 11:47:01 +01003031 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003032 if (!stkctr)
3033 return 0;
3034
Willy Tarreau37406352012-04-23 16:16:37 +02003035 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003036 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003037 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003038 if (stkctr_entry(stkctr) != NULL) {
3039 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE);
Willy Tarreau91c43d72010-06-20 11:19:22 +02003040 if (!ptr)
3041 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003042 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
Willy Tarreau3a96f3f2013-07-23 15:48:01 +02003043 stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u);
Willy Tarreau91c43d72010-06-20 11:19:22 +02003044 }
3045 return 1;
3046}
3047
Willy Tarreau87b09662015-04-03 00:22:06 +02003048/* set <smp> to the cumulated number of HTTP requests from the stream's tracked
Willy Tarreau91200da2013-07-23 15:55:19 +02003049 * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or
3050 * "src_http_req_cnt" only.
3051 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003052static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003053smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003054{
Willy Tarreaube508f12016-03-10 11:47:01 +01003055 struct stkctr *stkctr;
Willy Tarreau91200da2013-07-23 15:55:19 +02003056
Willy Tarreaube508f12016-03-10 11:47:01 +01003057 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau91200da2013-07-23 15:55:19 +02003058 if (!stkctr)
3059 return 0;
3060
Willy Tarreau37406352012-04-23 16:16:37 +02003061 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003062 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003063 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003064 if (stkctr_entry(stkctr) != NULL) {
3065 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003066 if (!ptr)
3067 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003068 smp->data.u.sint = stktable_data_cast(ptr, http_req_cnt);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003069 }
3070 return 1;
3071}
3072
Willy Tarreau87b09662015-04-03 00:22:06 +02003073/* set <smp> to the HTTP request rate from the stream's tracked frontend
Willy Tarreaucf477632013-07-23 16:04:37 +02003074 * counters. Supports being called as "sc[0-9]_http_req_rate" or
3075 * "src_http_req_rate" only.
3076 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003077static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003078smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003079{
Willy Tarreaube508f12016-03-10 11:47:01 +01003080 struct stkctr *stkctr;
3081
Willy Tarreaube508f12016-03-10 11:47:01 +01003082 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaucf477632013-07-23 16:04:37 +02003083 if (!stkctr)
3084 return 0;
3085
Willy Tarreau37406352012-04-23 16:16:37 +02003086 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003087 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003088 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003089 if (stkctr_entry(stkctr) != NULL) {
3090 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003091 if (!ptr)
3092 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003093 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreaucf477632013-07-23 16:04:37 +02003094 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003095 }
3096 return 1;
3097}
3098
Willy Tarreau87b09662015-04-03 00:22:06 +02003099/* set <smp> to the cumulated number of HTTP requests errors from the stream's
Willy Tarreau30d07c32013-07-23 16:45:38 +02003100 * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or
3101 * "src_http_err_cnt" only.
3102 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003103static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003104smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003105{
Willy Tarreaube508f12016-03-10 11:47:01 +01003106 struct stkctr *stkctr;
3107
Willy Tarreaube508f12016-03-10 11:47:01 +01003108 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau30d07c32013-07-23 16:45:38 +02003109 if (!stkctr)
3110 return 0;
3111
Willy Tarreau37406352012-04-23 16:16:37 +02003112 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003113 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003114 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003115 if (stkctr_entry(stkctr) != NULL) {
3116 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003117 if (!ptr)
3118 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003119 smp->data.u.sint = stktable_data_cast(ptr, http_err_cnt);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003120 }
3121 return 1;
3122}
3123
Willy Tarreau87b09662015-04-03 00:22:06 +02003124/* set <smp> to the HTTP request error rate from the stream's tracked frontend
Willy Tarreau9daf2622013-07-23 16:48:54 +02003125 * counters. Supports being called as "sc[0-9]_http_err_rate" or
3126 * "src_http_err_rate" only.
3127 */
Willy Tarreauda7ff642010-06-23 11:44:09 +02003128static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003129smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauda7ff642010-06-23 11:44:09 +02003130{
Willy Tarreaube508f12016-03-10 11:47:01 +01003131 struct stkctr *stkctr;
3132
Willy Tarreaube508f12016-03-10 11:47:01 +01003133 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau9daf2622013-07-23 16:48:54 +02003134 if (!stkctr)
3135 return 0;
3136
Willy Tarreau37406352012-04-23 16:16:37 +02003137 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003138 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003139 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003140 if (stkctr_entry(stkctr) != NULL) {
3141 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003142 if (!ptr)
3143 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003144 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
Willy Tarreau9daf2622013-07-23 16:48:54 +02003145 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
Willy Tarreauda7ff642010-06-23 11:44:09 +02003146 }
3147 return 1;
3148}
3149
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003150/* set <smp> to the number of kbytes received from clients, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003151 * stream's tracked frontend counters. Supports being called as
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003152 * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
3153 */
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003154static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003155smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003156{
Willy Tarreaube508f12016-03-10 11:47:01 +01003157 struct stkctr *stkctr;
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003158
Willy Tarreaube508f12016-03-10 11:47:01 +01003159 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau5077d4b2013-07-23 17:17:10 +02003160 if (!stkctr)
3161 return 0;
3162
Willy Tarreau37406352012-04-23 16:16:37 +02003163 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003164 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003165 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003166 if (stkctr_entry(stkctr) != NULL) {
3167 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT);
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003168 if (!ptr)
3169 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003170 smp->data.u.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003171 }
3172 return 1;
3173}
3174
Willy Tarreau613fe992013-07-23 17:39:19 +02003175/* set <smp> to the data rate received from clients in bytes/s, as found
Willy Tarreau87b09662015-04-03 00:22:06 +02003176 * in the stream's tracked frontend counters. Supports being called as
Willy Tarreau613fe992013-07-23 17:39:19 +02003177 * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only.
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003178 */
3179static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003180smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003181{
Willy Tarreaube508f12016-03-10 11:47:01 +01003182 struct stkctr *stkctr;
Willy Tarreau613fe992013-07-23 17:39:19 +02003183
Willy Tarreaube508f12016-03-10 11:47:01 +01003184 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau613fe992013-07-23 17:39:19 +02003185 if (!stkctr)
3186 return 0;
3187
Willy Tarreau37406352012-04-23 16:16:37 +02003188 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003189 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003190 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003191 if (stkctr_entry(stkctr) != NULL) {
3192 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003193 if (!ptr)
3194 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003195 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
Willy Tarreau613fe992013-07-23 17:39:19 +02003196 stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003197 }
3198 return 1;
3199}
3200
Willy Tarreau53aea102013-07-23 17:39:02 +02003201/* set <smp> to the number of kbytes sent to clients, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003202 * stream's tracked frontend counters. Supports being called as
Willy Tarreau53aea102013-07-23 17:39:02 +02003203 * "sc[0-9]_kbytes_out" or "src_kbytes_out" only.
3204 */
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003205static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003206smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau1aa006f2010-06-18 21:52:52 +02003207{
Willy Tarreaube508f12016-03-10 11:47:01 +01003208 struct stkctr *stkctr;
3209
Willy Tarreaube508f12016-03-10 11:47:01 +01003210 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau53aea102013-07-23 17:39:02 +02003211 if (!stkctr)
3212 return 0;
3213
Willy Tarreau37406352012-04-23 16:16:37 +02003214 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003215 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003216 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003217 if (stkctr_entry(stkctr) != NULL) {
3218 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT);
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003219 if (!ptr)
3220 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003221 smp->data.u.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003222 }
Willy Tarreau855e4bb2010-06-18 18:33:32 +02003223 return 1;
3224}
3225
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003226/* set <smp> to the data rate sent to clients in bytes/s, as found in the
Willy Tarreau87b09662015-04-03 00:22:06 +02003227 * stream's tracked frontend counters. Supports being called as
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003228 * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only.
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003229 */
3230static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003231smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003232{
Willy Tarreaube508f12016-03-10 11:47:01 +01003233 struct stkctr *stkctr;
3234
Willy Tarreaube508f12016-03-10 11:47:01 +01003235 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003236 if (!stkctr)
3237 return 0;
3238
Willy Tarreau37406352012-04-23 16:16:37 +02003239 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003240 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003241 smp->data.u.sint = 0;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +01003242 if (stkctr_entry(stkctr) != NULL) {
3243 void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003244 if (!ptr)
3245 return 0; /* parameter not stored */
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003246 smp->data.u.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
Willy Tarreaua0b68ed2013-07-23 18:26:32 +02003247 stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
Willy Tarreau6c59e0a2010-06-20 11:56:30 +02003248 }
3249 return 1;
3250}
3251
Willy Tarreau87b09662015-04-03 00:22:06 +02003252/* set <smp> to the number of active trackers on the SC entry in the stream's
Willy Tarreau563eef42013-07-23 18:32:02 +02003253 * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only.
3254 */
Willy Tarreau2406db42012-12-09 12:16:43 +01003255static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003256smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau2406db42012-12-09 12:16:43 +01003257{
Willy Tarreaube508f12016-03-10 11:47:01 +01003258 struct stkctr *stkctr;
3259
Willy Tarreaube508f12016-03-10 11:47:01 +01003260 stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw);
Willy Tarreau563eef42013-07-23 18:32:02 +02003261 if (!stkctr)
Willy Tarreau2406db42012-12-09 12:16:43 +01003262 return 0;
3263
Willy Tarreau563eef42013-07-23 18:32:02 +02003264 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003265 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003266 smp->data.u.sint = stkctr_entry(stkctr)->ref_cnt;
Willy Tarreau563eef42013-07-23 18:32:02 +02003267 return 1;
Willy Tarreaue25c9172013-05-28 18:32:20 +02003268}
3269
Willy Tarreau34db1082012-04-19 17:16:54 +02003270/* set temp integer to the number of used entries in the table pointed to by expr.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02003271 * Accepts exactly 1 argument of type table.
Willy Tarreau34db1082012-04-19 17:16:54 +02003272 */
Willy Tarreauc735a072011-03-29 00:57:02 +02003273static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003274smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc735a072011-03-29 00:57:02 +02003275{
Willy Tarreau37406352012-04-23 16:16:37 +02003276 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003277 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003278 smp->data.u.sint = args->data.prx->table.current;
Willy Tarreauc735a072011-03-29 00:57:02 +02003279 return 1;
3280}
3281
Willy Tarreau34db1082012-04-19 17:16:54 +02003282/* set temp integer to the number of free entries in the table pointed to by expr.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02003283 * Accepts exactly 1 argument of type table.
Willy Tarreau34db1082012-04-19 17:16:54 +02003284 */
Willy Tarreauc735a072011-03-29 00:57:02 +02003285static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02003286smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreauc735a072011-03-29 00:57:02 +02003287{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02003288 struct proxy *px;
3289
Willy Tarreau24e32d82012-04-23 23:55:44 +02003290 px = args->data.prx;
Willy Tarreau37406352012-04-23 16:16:37 +02003291 smp->flags = SMP_F_VOL_TEST;
Thierry FOURNIER8c542ca2015-08-19 09:00:18 +02003292 smp->data.type = SMP_T_SINT;
Thierry FOURNIER136f9d32015-08-19 09:07:19 +02003293 smp->data.u.sint = px->table.size - px->table.current;
Willy Tarreauc735a072011-03-29 00:57:02 +02003294 return 1;
3295}
Willy Tarreau8b22a712010-06-18 17:46:06 +02003296
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003297/* 0=OK, <0=Alert, >0=Warning */
3298static enum act_parse_ret stream_parse_use_service(const char **args, int *cur_arg,
3299 struct proxy *px, struct act_rule *rule,
3300 char **err)
3301{
3302 struct action_kw *kw;
3303
3304 /* Check if the service name exists. */
3305 if (*(args[*cur_arg]) == 0) {
3306 memprintf(err, "'%s' expects a service name.", args[0]);
Thierry FOURNIER337eae12015-11-26 19:48:04 +01003307 return ACT_RET_PRS_ERR;
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003308 }
3309
3310 /* lookup for keyword corresponding to a service. */
3311 kw = action_lookup(&service_keywords, args[*cur_arg]);
3312 if (!kw) {
3313 memprintf(err, "'%s' unknown service name.", args[1]);
3314 return ACT_RET_PRS_ERR;
3315 }
3316 (*cur_arg)++;
3317
3318 /* executes specific rule parser. */
3319 rule->kw = kw;
3320 if (kw->parse((const char **)args, cur_arg, px, rule, err) == ACT_RET_PRS_ERR)
3321 return ACT_RET_PRS_ERR;
3322
3323 /* Register processing function. */
3324 rule->action_ptr = process_use_service;
3325 rule->action = ACT_CUSTOM;
3326
3327 return ACT_RET_PRS_OK;
3328}
3329
3330void service_keywords_register(struct action_kw_list *kw_list)
3331{
3332 LIST_ADDQ(&service_keywords, &kw_list->list);
3333}
3334
3335/* main configuration keyword registration. */
3336static struct action_kw_list stream_tcp_keywords = { ILH, {
3337 { "use-service", stream_parse_use_service },
3338 { /* END */ }
3339}};
3340
3341static struct action_kw_list stream_http_keywords = { ILH, {
3342 { "use-service", stream_parse_use_service },
3343 { /* END */ }
3344}};
3345
Willy Tarreau61612d42012-04-19 18:42:05 +02003346/* Note: must not be declared <const> as its list will be overwritten.
3347 * Please take care of keeping this list alphabetically sorted.
3348 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02003349static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau281c7992013-01-08 01:23:27 +01003350 { /* END */ },
Willy Tarreau8b22a712010-06-18 17:46:06 +02003351}};
3352
Willy Tarreau281c7992013-01-08 01:23:27 +01003353/* Note: must not be declared <const> as its list will be overwritten.
3354 * Please take care of keeping this list alphabetically sorted.
3355 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02003356static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
Thierry FOURNIERbf65cd42015-07-20 17:45:02 +02003357 { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3358 { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3359 { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3360 { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3361 { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3362 { "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 +02003363 { "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 +02003364 { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3365 { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3366 { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3367 { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3368 { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3369 { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3370 { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3371 { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3372 { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3373 { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3374 { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3375 { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
3376 { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003377 { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3378 { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3379 { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3380 { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3381 { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3382 { "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 +02003383 { "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 +02003384 { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3385 { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3386 { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3387 { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3388 { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3389 { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3390 { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3391 { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3392 { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3393 { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3394 { "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 +02003395 { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003396 { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3397 { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3398 { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3399 { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3400 { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3401 { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3402 { "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 +02003403 { "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 +02003404 { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3405 { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3406 { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3407 { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3408 { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3409 { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3410 { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3411 { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3412 { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3413 { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3414 { "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 +02003415 { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003416 { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3417 { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3418 { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3419 { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3420 { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3421 { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3422 { "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 +02003423 { "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 +02003424 { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3425 { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3426 { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3427 { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3428 { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3429 { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3430 { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3431 { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3432 { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3433 { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3434 { "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 +02003435 { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +02003436 { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3437 { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3438 { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3439 { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3440 { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3441 { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3442 { "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 +02003443 { "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 +02003444 { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3445 { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3446 { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3447 { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3448 { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3449 { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3450 { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3451 { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3452 { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3453 { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3454 { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3455 { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, },
3456 { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
3457 { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, },
Willy Tarreau281c7992013-01-08 01:23:27 +01003458 { /* END */ },
3459}};
3460
Willy Tarreau8b22a712010-06-18 17:46:06 +02003461__attribute__((constructor))
Willy Tarreau87b09662015-04-03 00:22:06 +02003462static void __stream_init(void)
Willy Tarreau8b22a712010-06-18 17:46:06 +02003463{
Willy Tarreau281c7992013-01-08 01:23:27 +01003464 sample_register_fetches(&smp_fetch_keywords);
Willy Tarreau8b22a712010-06-18 17:46:06 +02003465 acl_register_keywords(&acl_kws);
Thierry FOURNIER5a363e72015-09-27 19:29:33 +02003466 tcp_req_cont_keywords_register(&stream_tcp_keywords);
3467 http_req_keywords_register(&stream_http_keywords);
Willy Tarreau8b22a712010-06-18 17:46:06 +02003468}
3469
Willy Tarreaubaaee002006-06-26 02:48:02 +02003470/*
3471 * Local variables:
3472 * c-indent-level: 8
3473 * c-basic-offset: 8
3474 * End:
3475 */