Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2 | * Stream management functions. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d28c353 | 2012-04-19 19:28:33 +0200 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdlib.h> |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 14 | #include <unistd.h> |
| 15 | #include <fcntl.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 16 | |
| 17 | #include <common/config.h> |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 18 | #include <common/buffer.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 19 | #include <common/debug.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 20 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 22 | #include <types/capture.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 23 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 25 | #include <proto/acl.h> |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 26 | #include <proto/arg.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 27 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 28 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 29 | #include <proto/checks.h> |
Willy Tarreau | d2274c6 | 2012-07-06 14:29:45 +0200 | [diff] [blame] | 30 | #include <proto/connection.h> |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 31 | #include <proto/dumpstats.h> |
Willy Tarreau | dd2f85e | 2012-09-02 22:34:23 +0200 | [diff] [blame] | 32 | #include <proto/fd.h> |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 33 | #include <proto/freq_ctr.h> |
Willy Tarreau | 3041b9f | 2010-10-15 23:25:20 +0200 | [diff] [blame] | 34 | #include <proto/frontend.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 35 | #include <proto/hdr_idx.h> |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 36 | #include <proto/hlua.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 37 | #include <proto/listener.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 38 | #include <proto/log.h> |
Willy Tarreau | cbaaec4 | 2012-09-06 11:32:07 +0200 | [diff] [blame] | 39 | #include <proto/raw_sock.h> |
Willy Tarreau | feb7640 | 2015-04-03 14:10:06 +0200 | [diff] [blame] | 40 | #include <proto/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 41 | #include <proto/stream.h> |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 42 | #include <proto/pipe.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 43 | #include <proto/proto_http.h> |
| 44 | #include <proto/proto_tcp.h> |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 45 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 46 | #include <proto/queue.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 47 | #include <proto/server.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 48 | #include <proto/sample.h> |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 49 | #include <proto/stick_table.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 50 | #include <proto/stream_interface.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 51 | #include <proto/task.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 52 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 53 | struct pool_head *pool2_stream; |
| 54 | struct list streams; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 56 | /* list of streams waiting for at least one buffer */ |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 57 | struct list buffer_wq = LIST_HEAD_INIT(buffer_wq); |
| 58 | |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 59 | /* This function is called from the session handler which detects the end of |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 60 | * handshake, in order to complete initialization of a valid stream. It must |
Willy Tarreau | 02d8638 | 2015-04-05 12:00:52 +0200 | [diff] [blame] | 61 | * be called with an embryonic session. It returns the pointer to the newly |
| 62 | * created stream, or NULL in case of fatal error. For now the client-side |
| 63 | * end point is taken from the session's origin, which must be valid. |
Willy Tarreau | d1769b8 | 2015-04-06 00:25:48 +0200 | [diff] [blame] | 64 | * The task's context is set to the new stream, and its function is set to |
| 65 | * process_stream(). Target and analysers are null. |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 66 | */ |
Willy Tarreau | 02d8638 | 2015-04-05 12:00:52 +0200 | [diff] [blame] | 67 | struct stream *stream_new(struct session *sess, struct task *t) |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 68 | { |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 69 | struct stream *s; |
Willy Tarreau | f2b9874 | 2015-04-05 01:30:42 +0200 | [diff] [blame] | 70 | struct connection *conn = objt_conn(sess->origin); |
Willy Tarreau | 470280e | 2015-04-05 01:33:13 +0200 | [diff] [blame] | 71 | struct appctx *appctx = objt_appctx(sess->origin); |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 72 | |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 73 | if (unlikely((s = pool_alloc2(pool2_stream)) == NULL)) |
Willy Tarreau | 02d8638 | 2015-04-05 12:00:52 +0200 | [diff] [blame] | 74 | return s; |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 75 | |
| 76 | /* minimum stream initialization required for an embryonic stream is |
| 77 | * fairly low. We need very little to execute L4 ACLs, then we need a |
| 78 | * task to make the client-side connection live on its own. |
| 79 | * - flags |
| 80 | * - stick-entry tracking |
| 81 | */ |
| 82 | s->flags = 0; |
Willy Tarreau | fb9f584 | 2015-04-05 18:19:23 +0200 | [diff] [blame] | 83 | s->logs.logwait = sess->fe->to_log; |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 84 | s->logs.level = 0; |
Willy Tarreau | 99eb0f1 | 2015-04-05 12:03:54 +0200 | [diff] [blame] | 85 | s->logs.accept_date = sess->accept_date; /* user-visible date for logging */ |
| 86 | s->logs.tv_accept = sess->tv_accept; /* corrected date for internal use */ |
| 87 | tv_zero(&s->logs.tv_request); |
| 88 | s->logs.t_queue = -1; |
| 89 | s->logs.t_connect = -1; |
| 90 | s->logs.t_data = -1; |
| 91 | s->logs.t_close = 0; |
| 92 | s->logs.bytes_in = s->logs.bytes_out = 0; |
| 93 | s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */ |
| 94 | s->logs.srv_queue_size = 0; /* we will get this number soon */ |
| 95 | |
| 96 | /* default logging function */ |
| 97 | s->do_log = strm_log; |
| 98 | |
| 99 | /* default error reporting function, may be changed by analysers */ |
| 100 | s->srv_error = default_srv_error; |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 101 | |
| 102 | /* Initialise the current rule list pointer to NULL. We are sure that |
| 103 | * any rulelist match the NULL pointer. |
| 104 | */ |
| 105 | s->current_rule_list = NULL; |
| 106 | |
| 107 | memset(s->stkctr, 0, sizeof(s->stkctr)); |
| 108 | |
| 109 | s->sess = sess; |
| 110 | s->si[0].flags = SI_FL_NONE; |
| 111 | s->si[1].flags = SI_FL_ISBACK; |
| 112 | |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 113 | s->uniq_id = global.req_count++; |
| 114 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 115 | /* OK, we're keeping the stream, so let's properly initialize the stream */ |
| 116 | LIST_ADDQ(&streams, &s->list); |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 117 | LIST_INIT(&s->back_refs); |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 118 | LIST_INIT(&s->buffer_wait); |
Willy Tarreau | f8a49ea | 2013-10-14 21:32:07 +0200 | [diff] [blame] | 119 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 120 | s->flags |= SF_INITIALIZED; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 121 | s->unique_id = NULL; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 122 | |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 123 | s->task = t; |
Willy Tarreau | d1769b8 | 2015-04-06 00:25:48 +0200 | [diff] [blame] | 124 | t->process = process_stream; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 125 | t->context = s; |
| 126 | t->expire = TICK_ETERNITY; |
| 127 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 128 | /* Note: initially, the stream's backend points to the frontend. |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 129 | * This changes later when switching rules are executed or |
| 130 | * when the default backend is assigned. |
| 131 | */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 132 | s->be = sess->fe; |
William Lallemand | 82fe75c | 2012-10-23 10:25:10 +0200 | [diff] [blame] | 133 | s->comp_algo = NULL; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 134 | s->req.buf = s->res.buf = NULL; |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 135 | s->req_cap = NULL; |
| 136 | s->res_cap = NULL; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 137 | |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 138 | /* this part should be common with other protocols */ |
Willy Tarreau | 819d332 | 2014-11-28 12:12:34 +0100 | [diff] [blame] | 139 | si_reset(&s->si[0]); |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 140 | si_set_state(&s->si[0], SI_ST_EST); |
| 141 | |
Willy Tarreau | 1f52bb2 | 2015-04-04 14:28:46 +0200 | [diff] [blame] | 142 | /* attach the incoming connection to the stream interface now. */ |
Willy Tarreau | f2b9874 | 2015-04-05 01:30:42 +0200 | [diff] [blame] | 143 | if (conn) |
| 144 | si_attach_conn(&s->si[0], conn); |
Willy Tarreau | 470280e | 2015-04-05 01:33:13 +0200 | [diff] [blame] | 145 | else if (appctx) |
| 146 | si_attach_appctx(&s->si[0], appctx); |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 147 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 148 | if (likely(sess->fe->options2 & PR_O2_INDEPSTR)) |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 149 | s->si[0].flags |= SI_FL_INDEP_STR; |
| 150 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 151 | /* pre-initialize the other side's stream interface to an INIT state. The |
| 152 | * callbacks will be initialized before attempting to connect. |
| 153 | */ |
Willy Tarreau | 819d332 | 2014-11-28 12:12:34 +0100 | [diff] [blame] | 154 | si_reset(&s->si[1]); |
Willy Tarreau | 2a6e880 | 2013-10-24 15:50:53 +0200 | [diff] [blame] | 155 | si_detach(&s->si[1]); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 156 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 157 | if (likely(sess->fe->options2 & PR_O2_INDEPSTR)) |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 158 | s->si[1].flags |= SI_FL_INDEP_STR; |
| 159 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 160 | stream_init_srv_conn(s); |
Willy Tarreau | d1769b8 | 2015-04-06 00:25:48 +0200 | [diff] [blame] | 161 | s->target = NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 162 | s->pend_pos = NULL; |
| 163 | |
| 164 | /* init store persistence */ |
| 165 | s->store_count = 0; |
| 166 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 167 | channel_init(&s->req); |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 168 | s->req.flags |= CF_READ_ATTACHED; /* the producer is already connected */ |
Willy Tarreau | d1769b8 | 2015-04-06 00:25:48 +0200 | [diff] [blame] | 169 | s->req.analysers = 0; |
| 170 | channel_auto_connect(&s->req); /* don't wait to establish connection */ |
| 171 | channel_auto_close(&s->req); /* let the producer forward close requests */ |
Willy Tarreau | c8815ef | 2015-04-05 18:15:59 +0200 | [diff] [blame] | 172 | |
| 173 | s->req.rto = sess->fe->timeout.client; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 174 | s->req.wto = TICK_ETERNITY; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 175 | s->req.rex = TICK_ETERNITY; |
| 176 | s->req.wex = TICK_ETERNITY; |
| 177 | s->req.analyse_exp = TICK_ETERNITY; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 178 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 179 | channel_init(&s->res); |
Willy Tarreau | ef573c0 | 2014-11-28 14:17:09 +0100 | [diff] [blame] | 180 | s->res.flags |= CF_ISRESP; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 181 | s->res.analysers = 0; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 182 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 183 | if (sess->fe->options2 & PR_O2_NODELAY) { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 184 | s->req.flags |= CF_NEVER_WAIT; |
| 185 | s->res.flags |= CF_NEVER_WAIT; |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Willy Tarreau | c8815ef | 2015-04-05 18:15:59 +0200 | [diff] [blame] | 188 | s->res.wto = sess->fe->timeout.client; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 189 | s->res.rto = TICK_ETERNITY; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 190 | s->res.rex = TICK_ETERNITY; |
| 191 | s->res.wex = TICK_ETERNITY; |
| 192 | s->res.analyse_exp = TICK_ETERNITY; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 193 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 194 | s->txn = NULL; |
Willy Tarreau | 62f791e | 2012-03-09 11:32:30 +0100 | [diff] [blame] | 195 | |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 196 | HLUA_INIT(&s->hlua); |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 197 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 198 | /* finish initialization of the accepted file descriptor */ |
Willy Tarreau | f2b9874 | 2015-04-05 01:30:42 +0200 | [diff] [blame] | 199 | if (conn) |
| 200 | conn_data_want_recv(conn); |
Willy Tarreau | 470280e | 2015-04-05 01:33:13 +0200 | [diff] [blame] | 201 | else if (appctx) |
| 202 | s->si[0].flags |= SI_FL_WAIT_DATA; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | fb9f584 | 2015-04-05 18:19:23 +0200 | [diff] [blame] | 204 | if (sess->fe->accept && sess->fe->accept(s) < 0) |
Willy Tarreau | c5a7ff4 | 2015-04-05 11:52:08 +0200 | [diff] [blame] | 205 | goto out_fail_accept; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 206 | |
Willy Tarreau | f2b9874 | 2015-04-05 01:30:42 +0200 | [diff] [blame] | 207 | if (conn) { |
| 208 | /* if logs require transport layer information, note it on the connection */ |
| 209 | if (s->logs.logwait & LW_XPRT) |
| 210 | conn->flags |= CO_FL_XPRT_TRACKED; |
Willy Tarreau | 93dbc2b | 2012-10-12 18:01:49 +0200 | [diff] [blame] | 211 | |
Willy Tarreau | f2b9874 | 2015-04-05 01:30:42 +0200 | [diff] [blame] | 212 | /* we want the connection handler to notify the stream interface about updates. */ |
| 213 | conn->flags |= CO_FL_WAKE_DATA; |
| 214 | } |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 215 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 216 | /* it is important not to call the wakeup function directly but to |
| 217 | * pass through task_wakeup(), because this one knows how to apply |
| 218 | * priorities to tasks. |
| 219 | */ |
| 220 | task_wakeup(t, TASK_WOKEN_INIT); |
Willy Tarreau | 02d8638 | 2015-04-05 12:00:52 +0200 | [diff] [blame] | 221 | return s; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 222 | |
| 223 | /* Error unrolling */ |
Willy Tarreau | c5a7ff4 | 2015-04-05 11:52:08 +0200 | [diff] [blame] | 224 | out_fail_accept: |
Willy Tarreau | 3b24641 | 2014-11-25 17:10:33 +0100 | [diff] [blame] | 225 | LIST_DEL(&s->list); |
Willy Tarreau | 02a0c0e | 2015-04-04 18:08:21 +0200 | [diff] [blame] | 226 | pool_free2(pool2_stream, s); |
Willy Tarreau | 02d8638 | 2015-04-05 12:00:52 +0200 | [diff] [blame] | 227 | return NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 230 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 231 | * frees the context associated to a stream. It must have been removed first. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 232 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 233 | static void stream_free(struct stream *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 234 | { |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 235 | struct session *sess = strm_sess(s); |
| 236 | struct proxy *fe = sess->fe; |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 237 | struct bref *bref, *back; |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 238 | struct connection *cli_conn = objt_conn(sess->origin); |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 239 | int i; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 240 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 241 | if (s->pend_pos) |
| 242 | pendconn_free(s->pend_pos); |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 243 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 244 | if (objt_server(s->target)) { /* there may be requests left pending in queue */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 245 | if (s->flags & SF_CURR_SESS) { |
| 246 | s->flags &= ~SF_CURR_SESS; |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 247 | objt_server(s->target)->cur_sess--; |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 248 | } |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 249 | if (may_dequeue_tasks(objt_server(s->target), s->be)) |
| 250 | process_srv_queue(objt_server(s->target)); |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 251 | } |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 252 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 253 | if (unlikely(s->srv_conn)) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 254 | /* the stream still has a reserved slot on a server, but |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 255 | * it should normally be only the same as the one above, |
| 256 | * so this should not happen in fact. |
| 257 | */ |
| 258 | sess_change_server(s, NULL); |
| 259 | } |
| 260 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 261 | if (s->req.pipe) |
| 262 | put_pipe(s->req.pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 263 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 264 | if (s->res.pipe) |
| 265 | put_pipe(s->res.pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 266 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 267 | /* We may still be present in the buffer wait queue */ |
| 268 | if (!LIST_ISEMPTY(&s->buffer_wait)) { |
| 269 | LIST_DEL(&s->buffer_wait); |
| 270 | LIST_INIT(&s->buffer_wait); |
| 271 | } |
| 272 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 273 | b_drop(&s->req.buf); |
| 274 | b_drop(&s->res.buf); |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 275 | if (!LIST_ISEMPTY(&buffer_wq)) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 276 | stream_offer_buffers(); |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 277 | |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 278 | hlua_ctx_destroy(&s->hlua); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 279 | if (s->txn) |
| 280 | http_end_txn(s); |
Willy Tarreau | 4602363 | 2010-01-07 22:51:47 +0100 | [diff] [blame] | 281 | |
Willy Tarreau | 1e95491 | 2012-10-12 17:50:05 +0200 | [diff] [blame] | 282 | /* ensure the client-side transport layer is destroyed */ |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 283 | if (cli_conn) |
| 284 | conn_force_close(cli_conn); |
Willy Tarreau | 1e95491 | 2012-10-12 17:50:05 +0200 | [diff] [blame] | 285 | |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 286 | for (i = 0; i < s->store_count; i++) { |
| 287 | if (!s->store[i].ts) |
| 288 | continue; |
| 289 | stksess_free(s->store[i].table, s->store[i].ts); |
| 290 | s->store[i].ts = NULL; |
| 291 | } |
| 292 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 293 | if (s->txn) { |
| 294 | pool_free2(pool2_hdr_idx, s->txn->hdr_idx.v); |
| 295 | pool_free2(pool2_http_txn, s->txn); |
| 296 | s->txn = NULL; |
| 297 | } |
| 298 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 299 | if (fe) { |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 300 | pool_free2(fe->rsp_cap_pool, s->res_cap); |
| 301 | pool_free2(fe->req_cap_pool, s->req_cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 302 | } |
Willy Tarreau | 0937bc4 | 2009-12-22 15:03:09 +0100 | [diff] [blame] | 303 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 304 | stream_store_counters(s); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 305 | |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 306 | list_for_each_entry_safe(bref, back, &s->back_refs, users) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 307 | /* we have to unlink all watchers. We must not relink them if |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 308 | * this stream was the last one in the list. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 309 | */ |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 310 | LIST_DEL(&bref->users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 311 | LIST_INIT(&bref->users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 312 | if (s->list.n != &streams) |
| 313 | LIST_ADDQ(&LIST_ELEM(s->list.n, struct stream *, list)->back_refs, &bref->users); |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 314 | bref->ref = s->list.n; |
| 315 | } |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 316 | LIST_DEL(&s->list); |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 317 | si_release_endpoint(&s->si[1]); |
| 318 | si_release_endpoint(&s->si[0]); |
Willy Tarreau | feb7640 | 2015-04-03 14:10:06 +0200 | [diff] [blame] | 319 | |
| 320 | /* FIXME: for now we have a 1:1 relation between stream and session so |
| 321 | * the stream must free the session. |
| 322 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 323 | pool_free2(pool2_stream, s); |
Willy Tarreau | 11c3624 | 2015-04-04 15:54:03 +0200 | [diff] [blame] | 324 | session_free(sess); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 325 | |
| 326 | /* We may want to free the maximum amount of pools if the proxy is stopping */ |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 327 | if (fe && unlikely(fe->state == PR_STSTOPPED)) { |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 328 | pool_flush2(pool2_buffer); |
Willy Tarreau | 63986c7 | 2015-04-03 22:55:33 +0200 | [diff] [blame] | 329 | pool_flush2(pool2_http_txn); |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 330 | pool_flush2(pool2_hdr_idx); |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 331 | pool_flush2(pool2_requri); |
| 332 | pool_flush2(pool2_capture); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 333 | pool_flush2(pool2_stream); |
Willy Tarreau | feb7640 | 2015-04-03 14:10:06 +0200 | [diff] [blame] | 334 | pool_flush2(pool2_session); |
Willy Tarreau | 3a5e060 | 2014-11-13 16:46:28 +0100 | [diff] [blame] | 335 | pool_flush2(pool2_connection); |
| 336 | pool_flush2(pool2_pendconn); |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 337 | pool_flush2(fe->req_cap_pool); |
| 338 | pool_flush2(fe->rsp_cap_pool); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 339 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Willy Tarreau | 78955f4 | 2014-12-28 13:09:02 +0100 | [diff] [blame] | 342 | /* Allocates a receive buffer for channel <chn>, but only if it's guaranteed |
| 343 | * that it's not the last available buffer or it's the response buffer. Unless |
| 344 | * the buffer is the response buffer, an extra control is made so that we always |
| 345 | * keep <tune.buffers.reserved> buffers available after this allocation. To be |
| 346 | * called at the beginning of recv() callbacks to ensure that the required |
| 347 | * buffers are properly allocated. Returns 0 in case of failure, non-zero |
| 348 | * otherwise. |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 349 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 350 | int stream_alloc_recv_buffer(struct channel *chn) |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 351 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 352 | struct stream *s; |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 353 | struct buffer *b; |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 354 | int margin = 0; |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 355 | |
Willy Tarreau | 78955f4 | 2014-12-28 13:09:02 +0100 | [diff] [blame] | 356 | if (!(chn->flags & CF_ISRESP)) |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 357 | margin = global.tune.reserved_bufs; |
| 358 | |
Willy Tarreau | 78955f4 | 2014-12-28 13:09:02 +0100 | [diff] [blame] | 359 | s = chn_sess(chn); |
| 360 | |
| 361 | b = b_alloc_margin(&chn->buf, margin); |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 362 | if (b) |
| 363 | return 1; |
| 364 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 365 | if (LIST_ISEMPTY(&s->buffer_wait)) |
| 366 | LIST_ADDQ(&buffer_wq, &s->buffer_wait); |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 370 | /* Allocates a work buffer for stream <s>. It is meant to be called inside |
| 371 | * process_stream(). It will only allocate the side needed for the function |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 372 | * to work fine. For a regular connection, only the response is needed so that |
| 373 | * an error message may be built and returned. In case where the initiator is |
| 374 | * an applet (eg: peers), then we need to allocate the request buffer for the |
| 375 | * applet to be able to send its data (in this case a response is not needed). |
| 376 | * Request buffers are never picked from the reserved pool, but response |
| 377 | * buffers may be allocated from the reserve. This is critical to ensure that |
| 378 | * a response may always flow and will never block a server from releasing a |
| 379 | * connection. Returns 0 in case of failure, non-zero otherwise. |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 380 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 381 | int stream_alloc_work_buffer(struct stream *s) |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 382 | { |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 383 | int margin; |
| 384 | struct buffer **buf; |
| 385 | |
| 386 | if (objt_appctx(s->si[0].end)) { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 387 | buf = &s->req.buf; |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 388 | margin = global.tune.reserved_bufs; |
| 389 | } |
| 390 | else { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 391 | buf = &s->res.buf; |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 392 | margin = 0; |
| 393 | } |
| 394 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 395 | if (!LIST_ISEMPTY(&s->buffer_wait)) { |
| 396 | LIST_DEL(&s->buffer_wait); |
| 397 | LIST_INIT(&s->buffer_wait); |
| 398 | } |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 399 | |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 400 | if (b_alloc_margin(buf, margin)) |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 401 | return 1; |
| 402 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 403 | LIST_ADDQ(&buffer_wq, &s->buffer_wait); |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | /* releases unused buffers after processing. Typically used at the end of the |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 408 | * update() functions. It will try to wake up as many tasks as the number of |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 409 | * buffers that it releases. In practice, most often streams are blocked on |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 410 | * a single buffer, so it makes sense to try to wake two up when two buffers |
| 411 | * are released at once. |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 412 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 413 | void stream_release_buffers(struct stream *s) |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 414 | { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 415 | if (s->req.buf->size && buffer_empty(s->req.buf)) |
| 416 | b_free(&s->req.buf); |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 417 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 418 | if (s->res.buf->size && buffer_empty(s->res.buf)) |
| 419 | b_free(&s->res.buf); |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 420 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 421 | /* if we're certain to have at least 1 buffer available, and there is |
| 422 | * someone waiting, we can wake up a waiter and offer them. |
| 423 | */ |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 424 | if (!LIST_ISEMPTY(&buffer_wq)) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 425 | stream_offer_buffers(); |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 428 | /* Runs across the list of pending streams waiting for a buffer and wakes one |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 429 | * up if buffers are available. Will stop when the run queue reaches <rqlimit>. |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 430 | * Should not be called directly, use stream_offer_buffers() instead. |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 431 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 432 | void __stream_offer_buffers(int rqlimit) |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 433 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 434 | struct stream *sess, *bak; |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 435 | |
| 436 | list_for_each_entry_safe(sess, bak, &buffer_wq, buffer_wait) { |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 437 | if (rqlimit <= run_queue) |
| 438 | break; |
| 439 | |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 440 | if (sess->task->state & TASK_RUNNING) |
| 441 | continue; |
| 442 | |
| 443 | LIST_DEL(&sess->buffer_wait); |
| 444 | LIST_INIT(&sess->buffer_wait); |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 445 | task_wakeup(sess->task, TASK_WOKEN_RES); |
Willy Tarreau | bf883e0 | 2014-11-25 21:10:35 +0100 | [diff] [blame] | 446 | } |
Willy Tarreau | 656859d | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 447 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 448 | |
| 449 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 450 | int init_stream() |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 451 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 452 | LIST_INIT(&streams); |
| 453 | pool2_stream = create_pool("stream", sizeof(struct stream), MEM_F_SHARED); |
| 454 | return pool2_stream != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 457 | void stream_process_counters(struct stream *s) |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 458 | { |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 459 | struct session *sess = s->sess; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 460 | unsigned long long bytes; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 461 | void *ptr; |
| 462 | int i; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 463 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 464 | bytes = s->req.total - s->logs.bytes_in; |
| 465 | s->logs.bytes_in = s->req.total; |
| 466 | if (bytes) { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 467 | sess->fe->fe_counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 468 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 469 | s->be->be_counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 470 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 471 | if (objt_server(s->target)) |
| 472 | objt_server(s->target)->counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 473 | |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 474 | if (sess->listener && sess->listener->counters) |
| 475 | sess->listener->counters->bytes_in += bytes; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 476 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 477 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 478 | struct stkctr *stkctr = &s->stkctr[i]; |
| 479 | |
| 480 | if (!stkctr_entry(stkctr)) { |
| 481 | stkctr = &sess->stkctr[i]; |
| 482 | if (!stkctr_entry(stkctr)) |
| 483 | continue; |
| 484 | } |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 485 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 486 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 487 | if (ptr) |
| 488 | stktable_data_cast(ptr, bytes_in_cnt) += bytes; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 489 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 490 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 491 | if (ptr) |
| 492 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 493 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes); |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 494 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 495 | } |
| 496 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 497 | bytes = s->res.total - s->logs.bytes_out; |
| 498 | s->logs.bytes_out = s->res.total; |
| 499 | if (bytes) { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 500 | sess->fe->fe_counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 501 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 502 | s->be->be_counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 503 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 504 | if (objt_server(s->target)) |
| 505 | objt_server(s->target)->counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 506 | |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 507 | if (sess->listener && sess->listener->counters) |
| 508 | sess->listener->counters->bytes_out += bytes; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 509 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 510 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 511 | struct stkctr *stkctr = &s->stkctr[i]; |
| 512 | |
| 513 | if (!stkctr_entry(stkctr)) { |
| 514 | stkctr = &sess->stkctr[i]; |
| 515 | if (!stkctr_entry(stkctr)) |
| 516 | continue; |
| 517 | } |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 518 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 519 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 520 | if (ptr) |
| 521 | stktable_data_cast(ptr, bytes_out_cnt) += bytes; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 522 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 523 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 524 | if (ptr) |
| 525 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 526 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes); |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 527 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 528 | } |
| 529 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 530 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 531 | /* This function is called with (si->state == SI_ST_CON) meaning that a |
| 532 | * connection was attempted and that the file descriptor is already allocated. |
| 533 | * We must check for establishment, error and abort. Possible output states |
| 534 | * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and |
| 535 | * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER, |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 536 | * otherwise 1. This only works with connection-based streams. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 537 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 538 | static int sess_update_st_con_tcp(struct stream *s) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 539 | { |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 540 | struct stream_interface *si = &s->si[1]; |
| 541 | struct channel *req = &s->req; |
| 542 | struct channel *rep = &s->res; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 543 | struct connection *srv_conn = __objt_conn(si->end); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 544 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 545 | /* If we got an error, or if nothing happened and the connection timed |
| 546 | * out, we must give up. The CER state handler will take care of retry |
| 547 | * attempts and error reports. |
| 548 | */ |
| 549 | if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) { |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 550 | if (unlikely(req->flags & CF_WRITE_PARTIAL)) { |
Willy Tarreau | e3224e8 | 2012-10-29 22:41:31 +0100 | [diff] [blame] | 551 | /* Some data were sent past the connection establishment, |
| 552 | * so we need to pretend we're established to log correctly |
| 553 | * and let later states handle the failure. |
| 554 | */ |
Willy Tarreau | e3224e8 | 2012-10-29 22:41:31 +0100 | [diff] [blame] | 555 | si->state = SI_ST_EST; |
| 556 | si->err_type = SI_ET_DATA_ERR; |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 557 | rep->flags |= CF_READ_ERROR | CF_WRITE_ERROR; |
Willy Tarreau | e3224e8 | 2012-10-29 22:41:31 +0100 | [diff] [blame] | 558 | return 1; |
| 559 | } |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 560 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 561 | si->state = SI_ST_CER; |
Willy Tarreau | 0ede5a3 | 2012-12-08 08:44:02 +0100 | [diff] [blame] | 562 | |
Willy Tarreau | f79c817 | 2013-10-21 16:30:56 +0200 | [diff] [blame] | 563 | conn_force_close(srv_conn); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 564 | |
| 565 | if (si->err_type) |
| 566 | return 0; |
| 567 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 568 | if (si->flags & SI_FL_ERR) |
| 569 | si->err_type = SI_ET_CONN_ERR; |
| 570 | else |
| 571 | si->err_type = SI_ET_CONN_TO; |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /* OK, maybe we want to abort */ |
Willy Tarreau | a7a7ebc | 2012-12-30 00:50:35 +0100 | [diff] [blame] | 576 | if (!(req->flags & CF_WRITE_PARTIAL) && |
| 577 | unlikely((rep->flags & CF_SHUTW) || |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 578 | ((req->flags & CF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */ |
| 579 | ((!(req->flags & CF_WRITE_ACTIVITY) && channel_is_empty(req)) || |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 580 | s->be->options & PR_O_ABRT_CLOSE)))) { |
| 581 | /* give up */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 582 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 583 | si->err_type |= SI_ET_CONN_ABRT; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 584 | if (s->srv_error) |
| 585 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 586 | return 1; |
| 587 | } |
| 588 | |
| 589 | /* we need to wait a bit more if there was no activity either */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 590 | if (!(req->flags & CF_WRITE_ACTIVITY)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 591 | return 1; |
| 592 | |
| 593 | /* OK, this means that a connection succeeded. The caller will be |
| 594 | * responsible for handling the transition from CON to EST. |
| 595 | */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 596 | si->state = SI_ST_EST; |
| 597 | si->err_type = SI_ET_NONE; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 598 | return 1; |
| 599 | } |
| 600 | |
| 601 | /* This function is called with (si->state == SI_ST_CER) meaning that a |
| 602 | * previous connection attempt has failed and that the file descriptor |
| 603 | * has already been released. Possible causes include asynchronous error |
| 604 | * notification and time out. Possible output states are SI_ST_CLO when |
| 605 | * retries are exhausted, SI_ST_TAR when a delay is wanted before a new |
| 606 | * connection attempt, SI_ST_ASS when it's wise to retry on the same server, |
| 607 | * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are |
| 608 | * marked as in error state. It returns 0. |
| 609 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 610 | static int sess_update_st_cer(struct stream *s) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 611 | { |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 612 | struct stream_interface *si = &s->si[1]; |
| 613 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 614 | /* we probably have to release last stream from the server */ |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 615 | if (objt_server(s->target)) { |
| 616 | health_adjust(objt_server(s->target), HANA_STATUS_L4_ERR); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 617 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 618 | if (s->flags & SF_CURR_SESS) { |
| 619 | s->flags &= ~SF_CURR_SESS; |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 620 | objt_server(s->target)->cur_sess--; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 621 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* ensure that we have enough retries left */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 625 | si->conn_retries--; |
| 626 | if (si->conn_retries < 0) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 627 | if (!si->err_type) { |
| 628 | si->err_type = SI_ET_CONN_ERR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 631 | if (objt_server(s->target)) |
| 632 | objt_server(s->target)->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 633 | s->be->be_counters.failed_conns++; |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 634 | sess_change_server(s, NULL); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 635 | if (may_dequeue_tasks(objt_server(s->target), s->be)) |
| 636 | process_srv_queue(objt_server(s->target)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 637 | |
| 638 | /* shutw is enough so stop a connecting socket */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 639 | si_shutw(si); |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 640 | s->req.flags |= CF_WRITE_ERROR; |
| 641 | s->res.flags |= CF_READ_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 642 | |
| 643 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 644 | if (s->srv_error) |
| 645 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | /* If the "redispatch" option is set on the backend, we are allowed to |
| 650 | * retry on another server for the last retry. In order to achieve this, |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 651 | * we must mark the stream unassigned, and eventually clear the DIRECT |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 652 | * bit to ignore any persistence cookie. We won't count a retry nor a |
| 653 | * redispatch yet, because this will depend on what server is selected. |
Willy Tarreau | 33a14e5 | 2014-06-13 17:49:40 +0200 | [diff] [blame] | 654 | * If the connection is not persistent, the balancing algorithm is not |
| 655 | * determinist (round robin) and there is more than one active server, |
| 656 | * we accept to perform an immediate redispatch without waiting since |
| 657 | * we don't care about this particular server. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 658 | */ |
Willy Tarreau | 33a14e5 | 2014-06-13 17:49:40 +0200 | [diff] [blame] | 659 | if (objt_server(s->target) && |
| 660 | (si->conn_retries == 0 || |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 661 | (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 && |
Willy Tarreau | 33a14e5 | 2014-06-13 17:49:40 +0200 | [diff] [blame] | 662 | ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR))) && |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 663 | s->be->options & PR_O_REDISP && !(s->flags & SF_FORCE_PRST)) { |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 664 | sess_change_server(s, NULL); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 665 | if (may_dequeue_tasks(objt_server(s->target), s->be)) |
| 666 | process_srv_queue(objt_server(s->target)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 667 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 668 | s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 669 | si->state = SI_ST_REQ; |
| 670 | } else { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 671 | if (objt_server(s->target)) |
| 672 | objt_server(s->target)->counters.retries++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 673 | s->be->be_counters.retries++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 674 | si->state = SI_ST_ASS; |
| 675 | } |
| 676 | |
| 677 | if (si->flags & SI_FL_ERR) { |
| 678 | /* The error was an asynchronous connection error, and we will |
| 679 | * likely have to retry connecting to the same server, most |
| 680 | * likely leading to the same result. To avoid this, we wait |
Willy Tarreau | b029066 | 2014-06-13 17:04:44 +0200 | [diff] [blame] | 681 | * MIN(one second, connect timeout) before retrying. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 682 | */ |
| 683 | |
Willy Tarreau | b029066 | 2014-06-13 17:04:44 +0200 | [diff] [blame] | 684 | int delay = 1000; |
| 685 | |
| 686 | if (s->be->timeout.connect && s->be->timeout.connect < delay) |
| 687 | delay = s->be->timeout.connect; |
| 688 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 689 | if (!si->err_type) |
| 690 | si->err_type = SI_ET_CONN_ERR; |
| 691 | |
Willy Tarreau | db6d012 | 2014-06-13 17:40:15 +0200 | [diff] [blame] | 692 | /* only wait when we're retrying on the same server */ |
| 693 | if (si->state == SI_ST_ASS || |
| 694 | (s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_RR || |
| 695 | (s->be->srv_act <= 1)) { |
| 696 | si->state = SI_ST_TAR; |
| 697 | si->exp = tick_add(now_ms, MS_TO_TICKS(delay)); |
| 698 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 699 | return 0; |
| 700 | } |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * This function handles the transition between the SI_ST_CON state and the |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 706 | * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 707 | * SI_ST_INI) to SI_ST_EST, but only when a ->proto is defined. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 708 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 709 | static void sess_establish(struct stream *s) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 710 | { |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 711 | struct stream_interface *si = &s->si[1]; |
| 712 | struct channel *req = &s->req; |
| 713 | struct channel *rep = &s->res; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 714 | |
Willy Tarreau | 0e37f1c | 2013-12-31 23:06:46 +0100 | [diff] [blame] | 715 | /* First, centralize the timers information */ |
| 716 | s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 717 | si->exp = TICK_ETERNITY; |
| 718 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 719 | if (objt_server(s->target)) |
| 720 | health_adjust(objt_server(s->target), HANA_STATUS_L4_OK); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 721 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 722 | if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 723 | /* if the user wants to log as soon as possible, without counting |
| 724 | * bytes from the server, then this is the right moment. */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 725 | if (!LIST_ISEMPTY(&strm_fe(s)->logformat) && !(s->logs.logwait & LW_BYTES)) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 726 | s->logs.t_close = s->logs.t_connect; /* to get a valid end date */ |
Willy Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 727 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 728 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 729 | } |
| 730 | else { |
Willy Tarreau | d81ca04 | 2013-12-31 22:33:13 +0100 | [diff] [blame] | 731 | rep->flags |= CF_READ_DONTWAIT; /* a single read is enough to get response headers */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 734 | rep->analysers |= strm_fe(s)->fe_rsp_ana | s->be->be_rsp_ana; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 735 | rep->flags |= CF_READ_ATTACHED; /* producer is now attached */ |
Willy Tarreau | 644c101 | 2014-04-30 18:11:11 +0200 | [diff] [blame] | 736 | if (req->flags & CF_WAKE_CONNECT) { |
| 737 | req->flags |= CF_WAKE_ONCE; |
| 738 | req->flags &= ~CF_WAKE_CONNECT; |
| 739 | } |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 740 | if (objt_conn(si->end)) { |
Willy Tarreau | d04e858 | 2010-05-31 12:31:35 +0200 | [diff] [blame] | 741 | /* real connections have timeouts */ |
| 742 | req->wto = s->be->timeout.server; |
| 743 | rep->rto = s->be->timeout.server; |
| 744 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 745 | req->wex = TICK_ETERNITY; |
| 746 | } |
| 747 | |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 748 | /* Update back stream interface status for input states SI_ST_ASS, SI_ST_QUE, |
| 749 | * SI_ST_TAR. Other input states are simply ignored. |
Willy Tarreau | 9e5a3aa | 2013-12-31 23:32:12 +0100 | [diff] [blame] | 750 | * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON |
| 751 | * and SI_ST_EST. Flags must have previously been updated for timeouts and other |
| 752 | * conditions. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 753 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 754 | static void sess_update_stream_int(struct stream *s) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 755 | { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 756 | struct server *srv = objt_server(s->target); |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 757 | struct stream_interface *si = &s->si[1]; |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 758 | struct channel *req = &s->req; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 759 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 760 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 761 | now_ms, __FUNCTION__, |
| 762 | s, |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 763 | req, s->rep, |
| 764 | req->rex, s->res.wex, |
| 765 | req->flags, s->res.flags, |
| 766 | req->buf->i, req->buf->o, s->res.buf->i, s->res.buf->o, s->si[0].state, req->cons->state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 767 | |
| 768 | if (si->state == SI_ST_ASS) { |
| 769 | /* Server assigned to connection request, we have to try to connect now */ |
| 770 | int conn_err; |
| 771 | |
| 772 | conn_err = connect_server(s); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 773 | srv = objt_server(s->target); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 774 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 775 | if (conn_err == SF_ERR_NONE) { |
Willy Tarreau | 9e5a3aa | 2013-12-31 23:32:12 +0100 | [diff] [blame] | 776 | /* state = SI_ST_CON or SI_ST_EST now */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 777 | if (srv) |
| 778 | srv_inc_sess_ctr(srv); |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 779 | if (srv) |
| 780 | srv_set_sess_last(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | |
| 784 | /* We have received a synchronous error. We might have to |
| 785 | * abort, retry immediately or redispatch. |
| 786 | */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 787 | if (conn_err == SF_ERR_INTERNAL) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 788 | if (!si->err_type) { |
| 789 | si->err_type = SI_ET_CONN_OTHER; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 792 | if (srv) |
| 793 | srv_inc_sess_ctr(srv); |
| 794 | if (srv) |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 795 | srv_set_sess_last(srv); |
| 796 | if (srv) |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 797 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 798 | s->be->be_counters.failed_conns++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 799 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 800 | /* release other streams waiting for this server */ |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 801 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 802 | if (may_dequeue_tasks(srv, s->be)) |
| 803 | process_srv_queue(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 804 | |
| 805 | /* Failed and not retryable. */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 806 | si_shutr(si); |
| 807 | si_shutw(si); |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 808 | req->flags |= CF_WRITE_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 809 | |
| 810 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 811 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 812 | /* no stream was ever accounted for this server */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 813 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 814 | if (s->srv_error) |
| 815 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
| 819 | /* We are facing a retryable error, but we don't want to run a |
| 820 | * turn-around now, as the problem is likely a source port |
| 821 | * allocation problem, so we want to retry now. |
| 822 | */ |
| 823 | si->state = SI_ST_CER; |
| 824 | si->flags &= ~SI_FL_ERR; |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 825 | sess_update_st_cer(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 826 | /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */ |
| 827 | return; |
| 828 | } |
| 829 | else if (si->state == SI_ST_QUE) { |
| 830 | /* connection request was queued, check for any update */ |
| 831 | if (!s->pend_pos) { |
| 832 | /* The connection is not in the queue anymore. Either |
| 833 | * we have a server connection slot available and we |
| 834 | * go directly to the assigned state, or we need to |
| 835 | * load-balance first and go to the INI state. |
| 836 | */ |
| 837 | si->exp = TICK_ETERNITY; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 838 | if (unlikely(!(s->flags & SF_ASSIGNED))) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 839 | si->state = SI_ST_REQ; |
| 840 | else { |
| 841 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 842 | si->state = SI_ST_ASS; |
| 843 | } |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | /* Connection request still in queue... */ |
| 848 | if (si->flags & SI_FL_EXP) { |
| 849 | /* ... and timeout expired */ |
| 850 | si->exp = TICK_ETERNITY; |
| 851 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 852 | if (srv) |
| 853 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 854 | s->be->be_counters.failed_conns++; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 855 | si_shutr(si); |
| 856 | si_shutw(si); |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 857 | req->flags |= CF_WRITE_TIMEOUT; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 858 | if (!si->err_type) |
| 859 | si->err_type = SI_ET_QUEUE_TO; |
| 860 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 861 | if (s->srv_error) |
| 862 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 863 | return; |
| 864 | } |
| 865 | |
| 866 | /* Connection remains in queue, check if we have to abort it */ |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 867 | if ((req->flags & (CF_READ_ERROR)) || |
| 868 | ((req->flags & CF_SHUTW_NOW) && /* empty and client aborted */ |
| 869 | (channel_is_empty(req) || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 870 | /* give up */ |
| 871 | si->exp = TICK_ETERNITY; |
| 872 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 873 | si_shutr(si); |
| 874 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 875 | si->err_type |= SI_ET_QUEUE_ABRT; |
| 876 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 877 | if (s->srv_error) |
| 878 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 879 | return; |
| 880 | } |
| 881 | |
| 882 | /* Nothing changed */ |
| 883 | return; |
| 884 | } |
| 885 | else if (si->state == SI_ST_TAR) { |
| 886 | /* Connection request might be aborted */ |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 887 | if ((req->flags & (CF_READ_ERROR)) || |
| 888 | ((req->flags & CF_SHUTW_NOW) && /* empty and client aborted */ |
| 889 | (channel_is_empty(req) || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 890 | /* give up */ |
| 891 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 892 | si_shutr(si); |
| 893 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 894 | si->err_type |= SI_ET_CONN_ABRT; |
| 895 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 896 | if (s->srv_error) |
| 897 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 898 | return; |
| 899 | } |
| 900 | |
| 901 | if (!(si->flags & SI_FL_EXP)) |
| 902 | return; /* still in turn-around */ |
| 903 | |
| 904 | si->exp = TICK_ETERNITY; |
| 905 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 906 | /* we keep trying on the same server as long as the stream is |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 907 | * marked "assigned". |
| 908 | * FIXME: Should we force a redispatch attempt when the server is down ? |
| 909 | */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 910 | if (s->flags & SF_ASSIGNED) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 911 | si->state = SI_ST_ASS; |
| 912 | else |
| 913 | si->state = SI_ST_REQ; |
| 914 | return; |
| 915 | } |
| 916 | } |
| 917 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 918 | /* Set correct stream termination flags in case no analyser has done it. It |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 919 | * also counts a failed request if the server state has not reached the request |
| 920 | * stage. |
| 921 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 922 | static void sess_set_term_flags(struct stream *s) |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 923 | { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 924 | if (!(s->flags & SF_FINST_MASK)) { |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 925 | if (s->si[1].state < SI_ST_REQ) { |
| 926 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 927 | strm_fe(s)->fe_counters.failed_req++; |
| 928 | if (strm_li(s)->counters) |
| 929 | strm_li(s)->counters->failed_req++; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 930 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 931 | s->flags |= SF_FINST_R; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 932 | } |
| 933 | else if (s->si[1].state == SI_ST_QUE) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 934 | s->flags |= SF_FINST_Q; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 935 | else if (s->si[1].state < SI_ST_EST) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 936 | s->flags |= SF_FINST_C; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 937 | else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 938 | s->flags |= SF_FINST_D; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 939 | else |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 940 | s->flags |= SF_FINST_L; |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 944 | /* This function initiates a server connection request on a stream interface |
Willy Tarreau | d84fb5e | 2013-11-30 09:06:53 +0100 | [diff] [blame] | 945 | * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS for |
| 946 | * a real connection to a server, indicating that a server has been assigned, |
| 947 | * or SI_ST_EST for a successful connection to an applet. It may also return |
| 948 | * SI_ST_QUE, or SI_ST_CLO upon error. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 949 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 950 | static void sess_prepare_conn_req(struct stream *s) |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 951 | { |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 952 | struct stream_interface *si = &s->si[1]; |
| 953 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 954 | 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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 955 | now_ms, __FUNCTION__, |
| 956 | s, |
| 957 | s->req, s->rep, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 958 | s->req.rex, s->res.wex, |
| 959 | s->req.flags, s->res.flags, |
Willy Tarreau | 350f487 | 2014-11-28 14:42:25 +0100 | [diff] [blame] | 960 | s->req.buf->i, s->req.buf->o, s->res.buf->i, s->res.buf->o, s->si[0].state, s->req.cons->state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 961 | |
| 962 | if (si->state != SI_ST_REQ) |
| 963 | return; |
| 964 | |
Willy Tarreau | d84fb5e | 2013-11-30 09:06:53 +0100 | [diff] [blame] | 965 | if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) { |
| 966 | /* the applet directly goes to the EST state */ |
Willy Tarreau | 4384ddf | 2013-12-01 12:25:52 +0100 | [diff] [blame] | 967 | struct appctx *appctx = objt_appctx(si->end); |
| 968 | |
| 969 | if (!appctx || appctx->applet != __objt_applet(s->target)) |
| 970 | appctx = stream_int_register_handler(si, objt_applet(s->target)); |
| 971 | |
| 972 | if (!appctx) { |
| 973 | /* No more memory, let's immediately abort. Force the |
| 974 | * error code to ignore the ERR_LOCAL which is not a |
| 975 | * real error. |
| 976 | */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 977 | s->flags &= ~(SF_ERR_MASK | SF_FINST_MASK); |
Willy Tarreau | 4384ddf | 2013-12-01 12:25:52 +0100 | [diff] [blame] | 978 | |
| 979 | si_shutr(si); |
| 980 | si_shutw(si); |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 981 | s->req.flags |= CF_WRITE_ERROR; |
Willy Tarreau | 6bbb2f6 | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 982 | si->err_type = SI_ET_CONN_RES; |
Willy Tarreau | 4384ddf | 2013-12-01 12:25:52 +0100 | [diff] [blame] | 983 | si->state = SI_ST_CLO; |
| 984 | if (s->srv_error) |
| 985 | s->srv_error(s, si); |
| 986 | return; |
| 987 | } |
| 988 | |
Willy Tarreau | d84fb5e | 2013-11-30 09:06:53 +0100 | [diff] [blame] | 989 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | d84fb5e | 2013-11-30 09:06:53 +0100 | [diff] [blame] | 990 | si->state = SI_ST_EST; |
| 991 | si->err_type = SI_ET_NONE; |
Willy Tarreau | b9a551e | 2014-04-23 00:35:17 +0200 | [diff] [blame] | 992 | be_set_sess_last(s->be); |
Willy Tarreau | fac4bd1 | 2013-11-30 09:21:49 +0100 | [diff] [blame] | 993 | /* let sess_establish() finish the job */ |
Willy Tarreau | d84fb5e | 2013-11-30 09:06:53 +0100 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 997 | /* Try to assign a server */ |
| 998 | if (srv_redispatch_connect(s) != 0) { |
| 999 | /* We did not get a server. Either we queued the |
| 1000 | * connection request, or we encountered an error. |
| 1001 | */ |
| 1002 | if (si->state == SI_ST_QUE) |
| 1003 | return; |
| 1004 | |
| 1005 | /* we did not get any server, let's check the cause */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1006 | si_shutr(si); |
| 1007 | si_shutw(si); |
Willy Tarreau | 103197d | 2014-11-28 15:26:12 +0100 | [diff] [blame] | 1008 | s->req.flags |= CF_WRITE_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1009 | if (!si->err_type) |
| 1010 | si->err_type = SI_ET_CONN_OTHER; |
| 1011 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 1012 | if (s->srv_error) |
| 1013 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | /* The server is assigned */ |
| 1018 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 1019 | si->state = SI_ST_ASS; |
Willy Tarreau | b9a551e | 2014-04-23 00:35:17 +0200 | [diff] [blame] | 1020 | be_set_sess_last(s->be); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1023 | /* This stream analyser checks the switching rules and changes the backend |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1024 | * if appropriate. The default_backend rule is also considered, then the |
| 1025 | * target backend's forced persistence rules are also evaluated last if any. |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1026 | * It returns 1 if the processing can continue on next analysers, or zero if it |
| 1027 | * either needs more data or wants to immediately abort the request. |
| 1028 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1029 | static int process_switching_rules(struct stream *s, struct channel *req, int an_bit) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1030 | { |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1031 | struct persist_rule *prst_rule; |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1032 | struct session *sess = s->sess; |
| 1033 | struct proxy *fe = sess->fe; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1034 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1035 | req->analysers &= ~an_bit; |
| 1036 | req->analyse_exp = TICK_ETERNITY; |
| 1037 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1038 | DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1039 | now_ms, __FUNCTION__, |
| 1040 | s, |
| 1041 | req, |
| 1042 | req->rex, req->wex, |
| 1043 | req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1044 | req->buf->i, |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1045 | req->analysers); |
| 1046 | |
| 1047 | /* now check whether we have some switching rules for this request */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1048 | if (!(s->flags & SF_BE_ASSIGNED)) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1049 | struct switching_rule *rule; |
| 1050 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1051 | list_for_each_entry(rule, &fe->switching_rules, list) { |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 1052 | int ret = 1; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1053 | |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 1054 | if (rule->cond) { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1055 | ret = acl_exec_cond(rule->cond, fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | f51658d | 2014-04-23 01:21:56 +0200 | [diff] [blame] | 1056 | ret = acl_pass(ret); |
| 1057 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1058 | ret = !ret; |
| 1059 | } |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1060 | |
| 1061 | if (ret) { |
Bertrand Jacquin | 702d44f | 2013-11-19 11:43:06 +0100 | [diff] [blame] | 1062 | /* If the backend name is dynamic, try to resolve the name. |
| 1063 | * If we can't resolve the name, or if any error occurs, break |
| 1064 | * the loop and fallback to the default backend. |
| 1065 | */ |
| 1066 | struct proxy *backend; |
| 1067 | |
| 1068 | if (rule->dynamic) { |
| 1069 | struct chunk *tmp = get_trash_chunk(); |
| 1070 | if (!build_logline(s, tmp->str, tmp->size, &rule->be.expr)) |
| 1071 | break; |
| 1072 | backend = findproxy(tmp->str, PR_CAP_BE); |
| 1073 | if (!backend) |
| 1074 | break; |
| 1075 | } |
| 1076 | else |
| 1077 | backend = rule->be.backend; |
| 1078 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1079 | if (!stream_set_backend(s, backend)) |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1080 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1081 | break; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /* To ensure correct connection accounting on the backend, we |
| 1086 | * have to assign one if it was not set (eg: a listen). This |
| 1087 | * measure also takes care of correctly setting the default |
| 1088 | * backend if any. |
| 1089 | */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1090 | if (!(s->flags & SF_BE_ASSIGNED)) |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1091 | if (!stream_set_backend(s, fe->defbe.be ? fe->defbe.be : s->be)) |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1092 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1095 | /* we don't want to run the TCP or HTTP filters again if the backend has not changed */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1096 | if (fe == s->be) { |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1097 | s->req.analysers &= ~AN_REQ_INSPECT_BE; |
| 1098 | s->req.analysers &= ~AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1099 | } |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1100 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1101 | /* as soon as we know the backend, we must check if we have a matching forced or ignored |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1102 | * persistence rule, and report that in the stream. |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1103 | */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1104 | list_for_each_entry(prst_rule, &s->be->persist_rules, list) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1105 | int ret = 1; |
| 1106 | |
| 1107 | if (prst_rule->cond) { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1108 | ret = acl_exec_cond(prst_rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1109 | ret = acl_pass(ret); |
| 1110 | if (prst_rule->cond->pol == ACL_COND_UNLESS) |
| 1111 | ret = !ret; |
| 1112 | } |
| 1113 | |
| 1114 | if (ret) { |
| 1115 | /* no rule, or the rule matches */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1116 | if (prst_rule->type == PERSIST_TYPE_FORCE) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1117 | s->flags |= SF_FORCE_PRST; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1118 | } else { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1119 | s->flags |= SF_IGNORE_PRST; |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1120 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1121 | break; |
| 1122 | } |
| 1123 | } |
| 1124 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1125 | return 1; |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1126 | |
| 1127 | sw_failed: |
| 1128 | /* immediately abort this request in case of allocation failure */ |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1129 | channel_abort(&s->req); |
| 1130 | channel_abort(&s->res); |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1131 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1132 | if (!(s->flags & SF_ERR_MASK)) |
| 1133 | s->flags |= SF_ERR_RESOURCE; |
| 1134 | if (!(s->flags & SF_FINST_MASK)) |
| 1135 | s->flags |= SF_FINST_R; |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1136 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1137 | if (s->txn) |
| 1138 | s->txn->status = 500; |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1139 | s->req.analysers = 0; |
| 1140 | s->req.analyse_exp = TICK_ETERNITY; |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1141 | return 0; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1142 | } |
| 1143 | |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1144 | /* This stream analyser works on a request. It applies all use-server rules on |
| 1145 | * it then returns 1. The data must already be present in the buffer otherwise |
| 1146 | * they won't match. It always returns 1. |
| 1147 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1148 | static int process_server_rules(struct stream *s, struct channel *req, int an_bit) |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1149 | { |
| 1150 | struct proxy *px = s->be; |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1151 | struct session *sess = s->sess; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1152 | struct server_rule *rule; |
| 1153 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1154 | DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1155 | now_ms, __FUNCTION__, |
| 1156 | s, |
| 1157 | req, |
| 1158 | req->rex, req->wex, |
| 1159 | req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1160 | req->buf->i + req->buf->o, |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1161 | req->analysers); |
| 1162 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1163 | if (!(s->flags & SF_ASSIGNED)) { |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1164 | list_for_each_entry(rule, &px->server_rules, list) { |
| 1165 | int ret; |
| 1166 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1167 | ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1168 | ret = acl_pass(ret); |
| 1169 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1170 | ret = !ret; |
| 1171 | |
| 1172 | if (ret) { |
| 1173 | struct server *srv = rule->srv.ptr; |
| 1174 | |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 1175 | if ((srv->state != SRV_ST_STOPPED) || |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1176 | (px->options & PR_O_PERSIST) || |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1177 | (s->flags & SF_FORCE_PRST)) { |
| 1178 | s->flags |= SF_DIRECT | SF_ASSIGNED; |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1179 | s->target = &srv->obj_type; |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1180 | break; |
| 1181 | } |
| 1182 | /* if the server is not UP, let's go on with next rules |
| 1183 | * just in case another one is suited. |
| 1184 | */ |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | req->analysers &= ~an_bit; |
| 1190 | req->analyse_exp = TICK_ETERNITY; |
| 1191 | return 1; |
| 1192 | } |
| 1193 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1194 | /* This stream analyser works on a request. It applies all sticking rules on |
| 1195 | * it then returns 1. The data must already be present in the buffer otherwise |
| 1196 | * they won't match. It always returns 1. |
| 1197 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1198 | static int process_sticking_rules(struct stream *s, struct channel *req, int an_bit) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1199 | { |
| 1200 | struct proxy *px = s->be; |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1201 | struct session *sess = s->sess; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1202 | struct sticking_rule *rule; |
| 1203 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1204 | DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1205 | now_ms, __FUNCTION__, |
| 1206 | s, |
| 1207 | req, |
| 1208 | req->rex, req->wex, |
| 1209 | req->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1210 | req->buf->i, |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1211 | req->analysers); |
| 1212 | |
| 1213 | list_for_each_entry(rule, &px->sticking_rules, list) { |
| 1214 | int ret = 1 ; |
| 1215 | int i; |
| 1216 | |
Willy Tarreau | 9667a80 | 2013-12-09 12:52:13 +0100 | [diff] [blame] | 1217 | /* Only the first stick store-request of each table is applied |
| 1218 | * and other ones are ignored. The purpose is to allow complex |
| 1219 | * configurations which look for multiple entries by decreasing |
| 1220 | * order of precision and to stop at the first which matches. |
| 1221 | * An example could be a store of the IP address from an HTTP |
| 1222 | * header first, then from the source if not found. |
| 1223 | */ |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1224 | for (i = 0; i < s->store_count; i++) { |
| 1225 | if (rule->table.t == s->store[i].table) |
| 1226 | break; |
| 1227 | } |
| 1228 | |
| 1229 | if (i != s->store_count) |
| 1230 | continue; |
| 1231 | |
| 1232 | if (rule->cond) { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1233 | ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1234 | ret = acl_pass(ret); |
| 1235 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1236 | ret = !ret; |
| 1237 | } |
| 1238 | |
| 1239 | if (ret) { |
| 1240 | struct stktable_key *key; |
| 1241 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1242 | key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr, NULL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1243 | if (!key) |
| 1244 | continue; |
| 1245 | |
| 1246 | if (rule->flags & STK_IS_MATCH) { |
| 1247 | struct stksess *ts; |
| 1248 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1249 | if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1250 | if (!(s->flags & SF_ASSIGNED)) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1251 | struct eb32_node *node; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1252 | void *ptr; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1253 | |
| 1254 | /* srv found in table */ |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1255 | ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID); |
| 1256 | node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id)); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1257 | if (node) { |
| 1258 | struct server *srv; |
| 1259 | |
| 1260 | srv = container_of(node, struct server, conf.id); |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 1261 | if ((srv->state != SRV_ST_STOPPED) || |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1262 | (px->options & PR_O_PERSIST) || |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1263 | (s->flags & SF_FORCE_PRST)) { |
| 1264 | s->flags |= SF_DIRECT | SF_ASSIGNED; |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1265 | s->target = &srv->obj_type; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1269 | stktable_touch(rule->table.t, ts, 1); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | if (rule->flags & STK_IS_STORE) { |
| 1273 | if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
| 1274 | struct stksess *ts; |
| 1275 | |
| 1276 | ts = stksess_new(rule->table.t, key); |
| 1277 | if (ts) { |
| 1278 | s->store[s->store_count].table = rule->table.t; |
| 1279 | s->store[s->store_count++].ts = ts; |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | req->analysers &= ~an_bit; |
| 1287 | req->analyse_exp = TICK_ETERNITY; |
| 1288 | return 1; |
| 1289 | } |
| 1290 | |
| 1291 | /* This stream analyser works on a response. It applies all store rules on it |
| 1292 | * then returns 1. The data must already be present in the buffer otherwise |
| 1293 | * they won't match. It always returns 1. |
| 1294 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1295 | static int process_store_rules(struct stream *s, struct channel *rep, int an_bit) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1296 | { |
| 1297 | struct proxy *px = s->be; |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1298 | struct session *sess = s->sess; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1299 | struct sticking_rule *rule; |
| 1300 | int i; |
Willy Tarreau | 9667a80 | 2013-12-09 12:52:13 +0100 | [diff] [blame] | 1301 | int nbreq = s->store_count; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1302 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1303 | DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1304 | now_ms, __FUNCTION__, |
| 1305 | s, |
Willy Tarreau | 2e2b3eb | 2010-02-09 20:55:44 +0100 | [diff] [blame] | 1306 | rep, |
| 1307 | rep->rex, rep->wex, |
| 1308 | rep->flags, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 1309 | rep->buf->i, |
Willy Tarreau | 2e2b3eb | 2010-02-09 20:55:44 +0100 | [diff] [blame] | 1310 | rep->analysers); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1311 | |
| 1312 | list_for_each_entry(rule, &px->storersp_rules, list) { |
| 1313 | int ret = 1 ; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1314 | |
Willy Tarreau | 9667a80 | 2013-12-09 12:52:13 +0100 | [diff] [blame] | 1315 | /* Only the first stick store-response of each table is applied |
| 1316 | * and other ones are ignored. The purpose is to allow complex |
| 1317 | * configurations which look for multiple entries by decreasing |
| 1318 | * order of precision and to stop at the first which matches. |
| 1319 | * An example could be a store of a set-cookie value, with a |
| 1320 | * fallback to a parameter found in a 302 redirect. |
| 1321 | * |
| 1322 | * The store-response rules are not allowed to override the |
| 1323 | * store-request rules for the same table, but they may coexist. |
| 1324 | * Thus we can have up to one store-request entry and one store- |
| 1325 | * response entry for the same table at any time. |
| 1326 | */ |
| 1327 | for (i = nbreq; i < s->store_count; i++) { |
| 1328 | if (rule->table.t == s->store[i].table) |
| 1329 | break; |
| 1330 | } |
| 1331 | |
| 1332 | /* skip existing entries for this table */ |
| 1333 | if (i < s->store_count) |
| 1334 | continue; |
| 1335 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1336 | if (rule->cond) { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1337 | ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1338 | ret = acl_pass(ret); |
| 1339 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1340 | ret = !ret; |
| 1341 | } |
| 1342 | |
| 1343 | if (ret) { |
| 1344 | struct stktable_key *key; |
| 1345 | |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 1346 | key = stktable_fetch_key(rule->table.t, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr, NULL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1347 | if (!key) |
| 1348 | continue; |
| 1349 | |
Willy Tarreau | 37e340c | 2013-12-06 23:05:21 +0100 | [diff] [blame] | 1350 | if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1351 | struct stksess *ts; |
| 1352 | |
| 1353 | ts = stksess_new(rule->table.t, key); |
| 1354 | if (ts) { |
| 1355 | s->store[s->store_count].table = rule->table.t; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1356 | s->store[s->store_count++].ts = ts; |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /* process store request and store response */ |
| 1363 | for (i = 0; i < s->store_count; i++) { |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1364 | struct stksess *ts; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1365 | void *ptr; |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1366 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 1367 | if (objt_server(s->target) && objt_server(s->target)->flags & SRV_F_NON_STICK) { |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 1368 | stksess_free(s->store[i].table, s->store[i].ts); |
| 1369 | s->store[i].ts = NULL; |
| 1370 | continue; |
| 1371 | } |
| 1372 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1373 | ts = stktable_lookup(s->store[i].table, s->store[i].ts); |
| 1374 | if (ts) { |
| 1375 | /* the entry already existed, we can free ours */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1376 | stktable_touch(s->store[i].table, ts, 1); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1377 | stksess_free(s->store[i].table, s->store[i].ts); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1378 | } |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1379 | else |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1380 | ts = stktable_store(s->store[i].table, s->store[i].ts, 1); |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1381 | |
| 1382 | s->store[i].ts = NULL; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1383 | ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID); |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1384 | stktable_data_cast(ptr, server_id) = objt_server(s->target)->puid; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1385 | } |
Willy Tarreau | 2a164ee | 2010-06-18 09:57:45 +0200 | [diff] [blame] | 1386 | s->store_count = 0; /* everything is stored */ |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1387 | |
| 1388 | rep->analysers &= ~an_bit; |
| 1389 | rep->analyse_exp = TICK_ETERNITY; |
| 1390 | return 1; |
| 1391 | } |
| 1392 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1393 | /* This macro is very specific to the function below. See the comments in |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1394 | * process_stream() below to understand the logic and the tests. |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1395 | */ |
| 1396 | #define UPDATE_ANALYSERS(real, list, back, flag) { \ |
| 1397 | list = (((list) & ~(flag)) | ~(back)) & (real); \ |
| 1398 | back = real; \ |
| 1399 | if (!(list)) \ |
| 1400 | break; \ |
| 1401 | if (((list) ^ ((list) & ((list) - 1))) < (flag)) \ |
| 1402 | continue; \ |
| 1403 | } |
| 1404 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1405 | /* Processes the client, server, request and response jobs of a stream task, |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1406 | * then puts it back to the wait queue in a clean state, or cleans up its |
| 1407 | * resources if it must be deleted. Returns in <next> the date the task wants |
| 1408 | * to be woken up, or TICK_ETERNITY. In order not to call all functions for |
| 1409 | * nothing too many times, the request and response buffers flags are monitored |
| 1410 | * and each function is called only if at least another function has changed at |
| 1411 | * least one flag it is interested in. |
| 1412 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1413 | struct task *process_stream(struct task *t) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1414 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1415 | struct server *srv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1416 | struct stream *s = t->context; |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 1417 | struct session *sess = s->sess; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1418 | unsigned int rqf_last, rpf_last; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1419 | unsigned int rq_prod_last, rq_cons_last; |
| 1420 | unsigned int rp_cons_last, rp_prod_last; |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1421 | unsigned int req_ana_back; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1422 | struct channel *req, *res; |
| 1423 | struct stream_interface *si_f, *si_b; |
| 1424 | |
| 1425 | req = &s->req; |
| 1426 | res = &s->res; |
| 1427 | |
| 1428 | si_f = &s->si[0]; |
| 1429 | si_b = &s->si[1]; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1430 | |
| 1431 | //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__, |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1432 | // si_f->state, si_b->state, si_b->err_type, req->flags, res->flags); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1433 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1434 | /* this data may be no longer valid, clear it */ |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 1435 | if (s->txn) |
| 1436 | memset(&s->txn->auth, 0, sizeof(s->txn->auth)); |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1437 | |
Willy Tarreau | 6f0a7ba | 2014-06-23 15:22:31 +0200 | [diff] [blame] | 1438 | /* This flag must explicitly be set every time */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1439 | req->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE); |
| 1440 | res->flags &= ~(CF_READ_NOEXP|CF_WAKE_WRITE); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1441 | |
| 1442 | /* Keep a copy of req/rep flags so that we can detect shutdowns */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1443 | rqf_last = req->flags & ~CF_MASK_ANALYSER; |
| 1444 | rpf_last = res->flags & ~CF_MASK_ANALYSER; |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1445 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1446 | /* we don't want the stream interface functions to recursively wake us up */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1447 | si_f->flags |= SI_FL_DONT_WAKE; |
| 1448 | si_b->flags |= SI_FL_DONT_WAKE; |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1449 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1450 | /* 1a: Check for low level timeouts if needed. We just set a flag on |
| 1451 | * stream interfaces when their timeouts have expired. |
| 1452 | */ |
| 1453 | if (unlikely(t->state & TASK_WOKEN_TIMER)) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1454 | stream_int_check_timeouts(si_f); |
| 1455 | stream_int_check_timeouts(si_b); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1456 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1457 | /* check channel timeouts, and close the corresponding stream interfaces |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1458 | * for future reads or writes. Note: this will also concern upper layers |
| 1459 | * but we do not touch any other flag. We must be careful and correctly |
| 1460 | * detect state changes when calling them. |
| 1461 | */ |
| 1462 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1463 | channel_check_timeouts(req); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1464 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1465 | if (unlikely((req->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { |
| 1466 | si_b->flags |= SI_FL_NOLINGER; |
| 1467 | si_shutw(si_b); |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1470 | if (unlikely((req->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { |
| 1471 | if (si_f->flags & SI_FL_NOHALF) |
| 1472 | si_f->flags |= SI_FL_NOLINGER; |
| 1473 | si_shutr(si_f); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1474 | } |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1475 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1476 | channel_check_timeouts(res); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1477 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1478 | if (unlikely((res->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { |
| 1479 | si_f->flags |= SI_FL_NOLINGER; |
| 1480 | si_shutw(si_f); |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1483 | if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { |
| 1484 | if (si_b->flags & SI_FL_NOHALF) |
| 1485 | si_b->flags |= SI_FL_NOLINGER; |
| 1486 | si_shutr(si_b); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1487 | } |
Willy Tarreau | 798f432 | 2012-11-08 14:49:17 +0100 | [diff] [blame] | 1488 | |
| 1489 | /* Once in a while we're woken up because the task expires. But |
| 1490 | * this does not necessarily mean that a timeout has been reached. |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1491 | * So let's not run a whole stream processing if only an expiration |
Willy Tarreau | 798f432 | 2012-11-08 14:49:17 +0100 | [diff] [blame] | 1492 | * timeout needs to be refreshed. |
| 1493 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1494 | if (!((req->flags | res->flags) & |
Willy Tarreau | 798f432 | 2012-11-08 14:49:17 +0100 | [diff] [blame] | 1495 | (CF_SHUTR|CF_READ_ACTIVITY|CF_READ_TIMEOUT|CF_SHUTW| |
| 1496 | CF_WRITE_ACTIVITY|CF_WRITE_TIMEOUT|CF_ANA_TIMEOUT)) && |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1497 | !((si_f->flags | si_b->flags) & (SI_FL_EXP|SI_FL_ERR)) && |
Willy Tarreau | 798f432 | 2012-11-08 14:49:17 +0100 | [diff] [blame] | 1498 | ((t->state & TASK_WOKEN_ANY) == TASK_WOKEN_TIMER)) |
| 1499 | goto update_exp_and_leave; |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1500 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1501 | |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 1502 | /* below we may emit error messages so we have to ensure that we have |
| 1503 | * our buffers properly allocated. |
| 1504 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1505 | if (!stream_alloc_work_buffer(s)) { |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 1506 | /* No buffer available, we've been subscribed to the list of |
| 1507 | * buffer waiters, let's wait for our turn. |
| 1508 | */ |
| 1509 | goto update_exp_and_leave; |
| 1510 | } |
| 1511 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1512 | /* 1b: check for low-level errors reported at the stream interface. |
| 1513 | * First we check if it's a retryable error (in which case we don't |
| 1514 | * want to tell the buffer). Otherwise we report the error one level |
| 1515 | * upper by setting flags into the buffers. Note that the side towards |
| 1516 | * the client cannot have connect (hence retryable) errors. Also, the |
| 1517 | * connection setup code must be able to deal with any type of abort. |
| 1518 | */ |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1519 | srv = objt_server(s->target); |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1520 | if (unlikely(si_f->flags & SI_FL_ERR)) { |
| 1521 | if (si_f->state == SI_ST_EST || si_f->state == SI_ST_DIS) { |
| 1522 | si_shutr(si_f); |
| 1523 | si_shutw(si_f); |
| 1524 | stream_int_report_error(si_f); |
| 1525 | if (!(req->analysers) && !(res->analysers)) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1526 | s->be->be_counters.cli_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1527 | sess->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1528 | if (srv) |
| 1529 | srv->counters.cli_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1530 | if (!(s->flags & SF_ERR_MASK)) |
| 1531 | s->flags |= SF_ERR_CLICL; |
| 1532 | if (!(s->flags & SF_FINST_MASK)) |
| 1533 | s->flags |= SF_FINST_D; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1534 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1538 | if (unlikely(si_b->flags & SI_FL_ERR)) { |
| 1539 | if (si_b->state == SI_ST_EST || si_b->state == SI_ST_DIS) { |
| 1540 | si_shutr(si_b); |
| 1541 | si_shutw(si_b); |
| 1542 | stream_int_report_error(si_b); |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1543 | s->be->be_counters.failed_resp++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1544 | if (srv) |
| 1545 | srv->counters.failed_resp++; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1546 | if (!(req->analysers) && !(res->analysers)) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1547 | s->be->be_counters.srv_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1548 | sess->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1549 | if (srv) |
| 1550 | srv->counters.srv_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1551 | if (!(s->flags & SF_ERR_MASK)) |
| 1552 | s->flags |= SF_ERR_SRVCL; |
| 1553 | if (!(s->flags & SF_FINST_MASK)) |
| 1554 | s->flags |= SF_FINST_D; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1555 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1556 | } |
| 1557 | /* note: maybe we should process connection errors here ? */ |
| 1558 | } |
| 1559 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1560 | if (si_b->state == SI_ST_CON) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1561 | /* we were trying to establish a connection on the server side, |
| 1562 | * maybe it succeeded, maybe it failed, maybe we timed out, ... |
| 1563 | */ |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 1564 | if (unlikely(!sess_update_st_con_tcp(s))) |
| 1565 | sess_update_st_cer(s); |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1566 | else if (si_b->state == SI_ST_EST) |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 1567 | sess_establish(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1568 | |
| 1569 | /* state is now one of SI_ST_CON (still in progress), SI_ST_EST |
| 1570 | * (established), SI_ST_DIS (abort), SI_ST_CLO (last error), |
| 1571 | * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors. |
| 1572 | */ |
| 1573 | } |
| 1574 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1575 | rq_prod_last = si_f->state; |
| 1576 | rq_cons_last = si_b->state; |
| 1577 | rp_cons_last = si_f->state; |
| 1578 | rp_prod_last = si_b->state; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1579 | |
| 1580 | resync_stream_interface: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1581 | /* Check for connection closure */ |
| 1582 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1583 | DPRINTF(stderr, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1584 | "[%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 Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1585 | now_ms, __FUNCTION__, __LINE__, |
| 1586 | t, |
| 1587 | s, s->flags, |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1588 | req, res, |
| 1589 | req->rex, res->wex, |
| 1590 | req->flags, res->flags, |
| 1591 | req->buf->i, req->buf->o, res->buf->i, res->buf->o, si_f->state, si_b->state, |
| 1592 | si_f->err_type, si_b->err_type, |
| 1593 | si_b->conn_retries); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1594 | |
| 1595 | /* nothing special to be done on client side */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1596 | if (unlikely(si_f->state == SI_ST_DIS)) |
| 1597 | si_f->state = SI_ST_CLO; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1598 | |
| 1599 | /* When a server-side connection is released, we have to count it and |
| 1600 | * check for pending connections on this server. |
| 1601 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1602 | if (unlikely(si_b->state == SI_ST_DIS)) { |
| 1603 | si_b->state = SI_ST_CLO; |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1604 | srv = objt_server(s->target); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1605 | if (srv) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1606 | if (s->flags & SF_CURR_SESS) { |
| 1607 | s->flags &= ~SF_CURR_SESS; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1608 | srv->cur_sess--; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1609 | } |
| 1610 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1611 | if (may_dequeue_tasks(srv, s->be)) |
| 1612 | process_srv_queue(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Note: of the transient states (REQ, CER, DIS), only REQ may remain |
| 1618 | * at this point. |
| 1619 | */ |
| 1620 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1621 | resync_request: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1622 | /* Analyse request */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1623 | if (((req->flags & ~rqf_last) & CF_MASK_ANALYSER) || |
| 1624 | ((req->flags ^ rqf_last) & CF_MASK_STATIC) || |
| 1625 | si_f->state != rq_prod_last || |
| 1626 | si_b->state != rq_cons_last || |
Thierry FOURNIER | 2e05a8c | 2014-11-24 14:49:56 +0100 | [diff] [blame] | 1627 | s->task->state & TASK_WOKEN_MSG) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1628 | unsigned int flags = req->flags; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1629 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1630 | if (si_f->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1631 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1632 | unsigned int ana_list; |
| 1633 | unsigned int ana_back; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1634 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1635 | /* it's up to the analysers to stop new connections, |
| 1636 | * disable reading or closing. Note: if an analyser |
| 1637 | * disables any of these bits, it is responsible for |
| 1638 | * enabling them again when it disables itself, so |
| 1639 | * that other analysers are called in similar conditions. |
| 1640 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1641 | channel_auto_read(req); |
| 1642 | channel_auto_connect(req); |
| 1643 | channel_auto_close(req); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1644 | |
| 1645 | /* We will call all analysers for which a bit is set in |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1646 | * req->analysers, following the bit order from LSB |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1647 | * to MSB. The analysers must remove themselves from |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1648 | * the list when not needed. Any analyser may return 0 |
| 1649 | * to break out of the loop, either because of missing |
| 1650 | * data to take a decision, or because it decides to |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1651 | * kill the stream. We loop at least once through each |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1652 | * analyser, and we may loop again if other analysers |
| 1653 | * are added in the middle. |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1654 | * |
| 1655 | * We build a list of analysers to run. We evaluate all |
| 1656 | * of these analysers in the order of the lower bit to |
| 1657 | * the higher bit. This ordering is very important. |
| 1658 | * An analyser will often add/remove other analysers, |
| 1659 | * including itself. Any changes to itself have no effect |
| 1660 | * on the loop. If it removes any other analysers, we |
| 1661 | * want those analysers not to be called anymore during |
| 1662 | * this loop. If it adds an analyser that is located |
| 1663 | * after itself, we want it to be scheduled for being |
| 1664 | * processed during the loop. If it adds an analyser |
| 1665 | * which is located before it, we want it to switch to |
| 1666 | * it immediately, even if it has already been called |
| 1667 | * once but removed since. |
| 1668 | * |
| 1669 | * In order to achieve this, we compare the analyser |
| 1670 | * list after the call with a copy of it before the |
| 1671 | * call. The work list is fed with analyser bits that |
| 1672 | * appeared during the call. Then we compare previous |
| 1673 | * work list with the new one, and check the bits that |
| 1674 | * appeared. If the lowest of these bits is lower than |
| 1675 | * the current bit, it means we have enabled a previous |
| 1676 | * analyser and must immediately loop again. |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1677 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1678 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1679 | ana_list = ana_back = req->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1680 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1681 | /* Warning! ensure that analysers are always placed in ascending order! */ |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1682 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1683 | if (ana_list & AN_REQ_INSPECT_FE) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1684 | if (!tcp_inspect_request(s, req, AN_REQ_INSPECT_FE)) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1685 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1686 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_INSPECT_FE); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1687 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1688 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1689 | if (ana_list & AN_REQ_WAIT_HTTP) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1690 | if (!http_wait_for_request(s, req, AN_REQ_WAIT_HTTP)) |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1691 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1692 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_WAIT_HTTP); |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1695 | if (ana_list & AN_REQ_HTTP_PROCESS_FE) { |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1696 | if (!http_process_req_common(s, req, AN_REQ_HTTP_PROCESS_FE, sess->fe)) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1697 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1698 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1699 | } |
| 1700 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1701 | if (ana_list & AN_REQ_SWITCHING_RULES) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1702 | if (!process_switching_rules(s, req, AN_REQ_SWITCHING_RULES)) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1703 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1704 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_SWITCHING_RULES); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1705 | } |
| 1706 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1707 | if (ana_list & AN_REQ_INSPECT_BE) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1708 | if (!tcp_inspect_request(s, req, AN_REQ_INSPECT_BE)) |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1709 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1710 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_INSPECT_BE); |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1713 | if (ana_list & AN_REQ_HTTP_PROCESS_BE) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1714 | if (!http_process_req_common(s, req, AN_REQ_HTTP_PROCESS_BE, s->be)) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1715 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1716 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1717 | } |
| 1718 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1719 | if (ana_list & AN_REQ_HTTP_TARPIT) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1720 | if (!http_process_tarpit(s, req, AN_REQ_HTTP_TARPIT)) |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1721 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1722 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_TARPIT); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1723 | } |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1724 | |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1725 | if (ana_list & AN_REQ_SRV_RULES) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1726 | if (!process_server_rules(s, req, AN_REQ_SRV_RULES)) |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1727 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1728 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_SRV_RULES); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1729 | } |
| 1730 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1731 | if (ana_list & AN_REQ_HTTP_INNER) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1732 | if (!http_process_request(s, req, AN_REQ_HTTP_INNER)) |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1733 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1734 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_INNER); |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1735 | } |
| 1736 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1737 | if (ana_list & AN_REQ_HTTP_BODY) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1738 | if (!http_wait_for_request_body(s, req, AN_REQ_HTTP_BODY)) |
Willy Tarreau | d34af78 | 2008-11-30 23:36:37 +0100 | [diff] [blame] | 1739 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1740 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_BODY); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1741 | } |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1742 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1743 | if (ana_list & AN_REQ_PRST_RDP_COOKIE) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1744 | if (!tcp_persist_rdp_cookie(s, req, AN_REQ_PRST_RDP_COOKIE)) |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1745 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1746 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1747 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1748 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1749 | if (ana_list & AN_REQ_STICKING_RULES) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1750 | if (!process_sticking_rules(s, req, AN_REQ_STICKING_RULES)) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1751 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1752 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_STICKING_RULES); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1755 | if (ana_list & AN_REQ_HTTP_XFER_BODY) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1756 | if (!http_request_forward_body(s, req, AN_REQ_HTTP_XFER_BODY)) |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1757 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1758 | UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1759 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1760 | break; |
| 1761 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1762 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1763 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1764 | rq_prod_last = si_f->state; |
| 1765 | rq_cons_last = si_b->state; |
| 1766 | req->flags &= ~CF_WAKE_ONCE; |
| 1767 | rqf_last = req->flags; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1768 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1769 | if ((req->flags ^ flags) & CF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1770 | goto resync_request; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1771 | } |
| 1772 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1773 | /* we'll monitor the request analysers while parsing the response, |
| 1774 | * because some response analysers may indirectly enable new request |
| 1775 | * analysers (eg: HTTP keep-alive). |
| 1776 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1777 | req_ana_back = req->analysers; |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1778 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1779 | resync_response: |
| 1780 | /* Analyse response */ |
| 1781 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1782 | if (((res->flags & ~rpf_last) & CF_MASK_ANALYSER) || |
| 1783 | (res->flags ^ rpf_last) & CF_MASK_STATIC || |
| 1784 | si_f->state != rp_cons_last || |
| 1785 | si_b->state != rp_prod_last || |
Thierry FOURNIER | 2e05a8c | 2014-11-24 14:49:56 +0100 | [diff] [blame] | 1786 | s->task->state & TASK_WOKEN_MSG) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1787 | unsigned int flags = res->flags; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1788 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1789 | if ((res->flags & CF_MASK_ANALYSER) && |
| 1790 | (res->analysers & AN_REQ_ALL)) { |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1791 | /* Due to HTTP pipelining, the HTTP request analyser might be waiting |
| 1792 | * for some free space in the response buffer, so we might need to call |
| 1793 | * it when something changes in the response buffer, but still we pass |
| 1794 | * it the request buffer. Note that the SI state might very well still |
| 1795 | * be zero due to us returning a flow of redirects! |
| 1796 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1797 | res->analysers &= ~AN_REQ_ALL; |
| 1798 | req->flags |= CF_WAKE_ONCE; |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1801 | if (si_b->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1802 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1803 | unsigned int ana_list; |
| 1804 | unsigned int ana_back; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1805 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1806 | /* it's up to the analysers to stop disable reading or |
| 1807 | * closing. Note: if an analyser disables any of these |
| 1808 | * bits, it is responsible for enabling them again when |
| 1809 | * it disables itself, so that other analysers are called |
| 1810 | * in similar conditions. |
| 1811 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1812 | channel_auto_read(res); |
| 1813 | channel_auto_close(res); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1814 | |
| 1815 | /* We will call all analysers for which a bit is set in |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1816 | * res->analysers, following the bit order from LSB |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1817 | * to MSB. The analysers must remove themselves from |
| 1818 | * the list when not needed. Any analyser may return 0 |
| 1819 | * to break out of the loop, either because of missing |
| 1820 | * data to take a decision, or because it decides to |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1821 | * kill the stream. We loop at least once through each |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1822 | * analyser, and we may loop again if other analysers |
| 1823 | * are added in the middle. |
| 1824 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1825 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1826 | ana_list = ana_back = res->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1827 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1828 | /* Warning! ensure that analysers are always placed in ascending order! */ |
| 1829 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1830 | if (ana_list & AN_RES_INSPECT) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1831 | if (!tcp_inspect_response(s, res, AN_RES_INSPECT)) |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1832 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1833 | UPDATE_ANALYSERS(res->analysers, ana_list, ana_back, AN_RES_INSPECT); |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1836 | if (ana_list & AN_RES_WAIT_HTTP) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1837 | if (!http_wait_for_response(s, res, AN_RES_WAIT_HTTP)) |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1838 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1839 | UPDATE_ANALYSERS(res->analysers, ana_list, ana_back, AN_RES_WAIT_HTTP); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1842 | if (ana_list & AN_RES_STORE_RULES) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1843 | if (!process_store_rules(s, res, AN_RES_STORE_RULES)) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1844 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1845 | UPDATE_ANALYSERS(res->analysers, ana_list, ana_back, AN_RES_STORE_RULES); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1848 | if (ana_list & AN_RES_HTTP_PROCESS_BE) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1849 | if (!http_process_res_common(s, res, AN_RES_HTTP_PROCESS_BE, s->be)) |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1850 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1851 | UPDATE_ANALYSERS(res->analysers, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1852 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1853 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1854 | if (ana_list & AN_RES_HTTP_XFER_BODY) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1855 | if (!http_response_forward_body(s, res, AN_RES_HTTP_XFER_BODY)) |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1856 | break; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1857 | UPDATE_ANALYSERS(res->analysers, ana_list, ana_back, AN_RES_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1858 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1859 | break; |
| 1860 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1861 | } |
| 1862 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1863 | rp_cons_last = si_f->state; |
| 1864 | rp_prod_last = si_b->state; |
| 1865 | rpf_last = res->flags; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1866 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1867 | if ((res->flags ^ flags) & CF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1868 | goto resync_response; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1871 | /* maybe someone has added some request analysers, so we must check and loop */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1872 | if (req->analysers & ~req_ana_back) |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1873 | goto resync_request; |
| 1874 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1875 | if ((req->flags & ~rqf_last) & CF_MASK_ANALYSER) |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1876 | goto resync_request; |
| 1877 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1878 | /* FIXME: here we should call protocol handlers which rely on |
| 1879 | * both buffers. |
| 1880 | */ |
| 1881 | |
| 1882 | |
| 1883 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1884 | * Now we propagate unhandled errors to the stream. Normally |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1885 | * we're just in a data phase here since it means we have not |
| 1886 | * seen any analyser who could set an error status. |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1887 | */ |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 1888 | srv = objt_server(s->target); |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1889 | if (unlikely(!(s->flags & SF_ERR_MASK))) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1890 | if (req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1891 | /* Report it if the client got an error or a read timeout expired */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1892 | req->analysers = 0; |
| 1893 | if (req->flags & CF_READ_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1894 | s->be->be_counters.cli_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1895 | sess->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1896 | if (srv) |
| 1897 | srv->counters.cli_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1898 | s->flags |= SF_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1899 | } |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1900 | else if (req->flags & CF_READ_TIMEOUT) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1901 | s->be->be_counters.cli_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1902 | sess->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1903 | if (srv) |
| 1904 | srv->counters.cli_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1905 | s->flags |= SF_ERR_CLITO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1906 | } |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1907 | else if (req->flags & CF_WRITE_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1908 | s->be->be_counters.srv_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1909 | sess->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1910 | if (srv) |
| 1911 | srv->counters.srv_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1912 | s->flags |= SF_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1913 | } |
| 1914 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1915 | s->be->be_counters.srv_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1916 | sess->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1917 | if (srv) |
| 1918 | srv->counters.srv_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1919 | s->flags |= SF_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1920 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1921 | sess_set_term_flags(s); |
| 1922 | } |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1923 | else if (res->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1924 | /* Report it if the server got an error or a read timeout expired */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1925 | res->analysers = 0; |
| 1926 | if (res->flags & CF_READ_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1927 | s->be->be_counters.srv_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1928 | sess->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1929 | if (srv) |
| 1930 | srv->counters.srv_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1931 | s->flags |= SF_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1932 | } |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1933 | else if (res->flags & CF_READ_TIMEOUT) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1934 | s->be->be_counters.srv_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1935 | sess->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1936 | if (srv) |
| 1937 | srv->counters.srv_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1938 | s->flags |= SF_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1939 | } |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1940 | else if (res->flags & CF_WRITE_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1941 | s->be->be_counters.cli_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1942 | sess->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1943 | if (srv) |
| 1944 | srv->counters.cli_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1945 | s->flags |= SF_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1946 | } |
| 1947 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1948 | s->be->be_counters.cli_aborts++; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1949 | sess->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1950 | if (srv) |
| 1951 | srv->counters.cli_aborts++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 1952 | s->flags |= SF_ERR_CLITO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1953 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1954 | sess_set_term_flags(s); |
| 1955 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1956 | } |
| 1957 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1958 | /* |
| 1959 | * Here we take care of forwarding unhandled data. This also includes |
| 1960 | * connection establishments and shutdown requests. |
| 1961 | */ |
| 1962 | |
| 1963 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1964 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1965 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1966 | * Note that we're checking CF_SHUTR_NOW as an indication of a possible |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1967 | * recent call to channel_abort(). |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1968 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1969 | if (unlikely(!req->analysers && |
| 1970 | !(req->flags & (CF_SHUTW|CF_SHUTR_NOW)) && |
| 1971 | (si_f->state >= SI_ST_EST) && |
| 1972 | (req->to_forward != CHN_INFINITE_FORWARD))) { |
Willy Tarreau | b31c971 | 2012-11-11 23:05:39 +0100 | [diff] [blame] | 1973 | /* This buffer is freewheeling, there's no analyser |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1974 | * attached to it. If any data are left in, we'll permit them to |
| 1975 | * move. |
| 1976 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1977 | channel_auto_read(req); |
| 1978 | channel_auto_connect(req); |
| 1979 | channel_auto_close(req); |
| 1980 | buffer_flush(req->buf); |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 1981 | |
Willy Tarreau | da4d9fe | 2010-11-07 20:26:56 +0100 | [diff] [blame] | 1982 | /* We'll let data flow between the producer (if still connected) |
| 1983 | * to the consumer (which might possibly not be connected yet). |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1984 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1985 | if (!(req->flags & (CF_SHUTR|CF_SHUTW_NOW))) |
| 1986 | channel_forward(req, CHN_INFINITE_FORWARD); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1987 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 1988 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1989 | /* check if it is wise to enable kernel splicing to forward request data */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1990 | if (!(req->flags & (CF_KERN_SPLICING|CF_SHUTR)) && |
| 1991 | req->to_forward && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1992 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1993 | (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->rcv_pipe) && |
| 1994 | (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->snd_pipe) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1995 | (pipes_used < global.maxpipes) && |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 1996 | (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) || |
| 1997 | (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 1998 | (req->flags & CF_STREAMER_FAST)))) { |
| 1999 | req->flags |= CF_KERN_SPLICING; |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2002 | /* reflect what the L7 analysers have seen last */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2003 | rqf_last = req->flags; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2004 | |
| 2005 | /* |
| 2006 | * Now forward all shutdown requests between both sides of the buffer |
| 2007 | */ |
| 2008 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2009 | /* first, let's check if the request buffer needs to shutdown(write), which may |
| 2010 | * happen either because the input is closed or because we want to force a close |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2011 | * once the server has begun to respond. If a half-closed timeout is set, we adjust |
| 2012 | * the other side's timeout as well. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2013 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2014 | if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) == |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2015 | (CF_AUTO_CLOSE|CF_SHUTR))) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2016 | channel_shutw_now(req); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2017 | if (tick_isset(sess->fe->timeout.clientfin)) { |
| 2018 | res->wto = sess->fe->timeout.clientfin; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2019 | res->wex = tick_add(now_ms, res->wto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2020 | } |
| 2021 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2022 | |
| 2023 | /* shutdown(write) pending */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2024 | if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW && |
| 2025 | channel_is_empty(req))) { |
| 2026 | if (req->flags & CF_READ_ERROR) |
| 2027 | si_b->flags |= SI_FL_NOLINGER; |
| 2028 | si_shutw(si_b); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2029 | if (tick_isset(s->be->timeout.serverfin)) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2030 | res->rto = s->be->timeout.serverfin; |
| 2031 | res->rex = tick_add(now_ms, res->rto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2032 | } |
Willy Tarreau | 8615c2a | 2013-06-21 08:20:19 +0200 | [diff] [blame] | 2033 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2034 | |
| 2035 | /* shutdown(write) done on server side, we must stop the client too */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2036 | if (unlikely((req->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW && |
| 2037 | !req->analysers)) |
| 2038 | channel_shutr_now(req); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2039 | |
| 2040 | /* shutdown(read) pending */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2041 | if (unlikely((req->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) { |
| 2042 | if (si_f->flags & SI_FL_NOHALF) |
| 2043 | si_f->flags |= SI_FL_NOLINGER; |
| 2044 | si_shutr(si_f); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2045 | if (tick_isset(sess->fe->timeout.clientfin)) { |
| 2046 | res->wto = sess->fe->timeout.clientfin; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2047 | res->wex = tick_add(now_ms, res->wto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2048 | } |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2049 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2050 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2051 | /* it's possible that an upper layer has requested a connection setup or abort. |
| 2052 | * There are 2 situations where we decide to establish a new connection : |
| 2053 | * - there are data scheduled for emission in the buffer |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2054 | * - the CF_AUTO_CONNECT flag is set (active connection) |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2055 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2056 | if (si_b->state == SI_ST_INI) { |
| 2057 | if (!(req->flags & CF_SHUTW)) { |
| 2058 | if ((req->flags & CF_AUTO_CONNECT) || !channel_is_empty(req)) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 2059 | /* If we have an appctx, there is no connect method, so we |
| 2060 | * immediately switch to the connected state, otherwise we |
| 2061 | * perform a connection request. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2062 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2063 | si_b->state = SI_ST_REQ; /* new connection requested */ |
| 2064 | si_b->conn_retries = s->be->conn_retries; |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2065 | } |
Willy Tarreau | 7320122 | 2009-08-16 18:27:24 +0200 | [diff] [blame] | 2066 | } |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 2067 | else { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2068 | si_b->state = SI_ST_CLO; /* shutw+ini = abort */ |
| 2069 | channel_shutw_now(req); /* fix buffer flags upon abort */ |
| 2070 | channel_shutr_now(res); |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 2071 | } |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 2072 | } |
| 2073 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2074 | |
| 2075 | /* we may have a pending connection request, or a connection waiting |
| 2076 | * for completion. |
| 2077 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2078 | if (si_b->state >= SI_ST_REQ && si_b->state < SI_ST_CON) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2079 | do { |
| 2080 | /* nb: step 1 might switch from QUE to ASS, but we first want |
| 2081 | * to give a chance to step 2 to perform a redirect if needed. |
| 2082 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2083 | if (si_b->state != SI_ST_REQ) |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 2084 | sess_update_stream_int(s); |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2085 | if (si_b->state == SI_ST_REQ) |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 2086 | sess_prepare_conn_req(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2087 | |
Willy Tarreau | 9e5a3aa | 2013-12-31 23:32:12 +0100 | [diff] [blame] | 2088 | /* applets directly go to the ESTABLISHED state. Similarly, |
| 2089 | * servers experience the same fate when their connection |
| 2090 | * is reused. |
| 2091 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2092 | if (unlikely(si_b->state == SI_ST_EST)) |
Willy Tarreau | 7b8c4f9 | 2014-11-28 15:15:44 +0100 | [diff] [blame] | 2093 | sess_establish(s); |
Willy Tarreau | fac4bd1 | 2013-11-30 09:21:49 +0100 | [diff] [blame] | 2094 | |
Willy Tarreau | b44c873 | 2013-12-31 23:16:50 +0100 | [diff] [blame] | 2095 | /* Now we can add the server name to a header (if requested) */ |
| 2096 | /* check for HTTP mode and proxy server_name_hdr_name != NULL */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2097 | if ((si_b->state >= SI_ST_CON) && |
Willy Tarreau | b44c873 | 2013-12-31 23:16:50 +0100 | [diff] [blame] | 2098 | (s->be->server_id_hdr_name != NULL) && |
| 2099 | (s->be->mode == PR_MODE_HTTP) && |
| 2100 | objt_server(s->target)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 2101 | http_send_name_header(s->txn, s->be, objt_server(s->target)->id); |
Willy Tarreau | 1e5dfda | 2013-04-07 18:19:16 +0200 | [diff] [blame] | 2102 | } |
| 2103 | |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 2104 | srv = objt_server(s->target); |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2105 | if (si_b->state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE)) |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2106 | http_perform_server_redirect(s, si_b); |
| 2107 | } while (si_b->state == SI_ST_ASS); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2108 | } |
| 2109 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 2110 | /* Benchmarks have shown that it's optimal to do a full resync now */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2111 | if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2112 | goto resync_stream_interface; |
| 2113 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 2114 | /* otherwise we want to check if we need to resync the req buffer or not */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2115 | if ((req->flags ^ rqf_last) & CF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2116 | goto resync_request; |
| 2117 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 2118 | /* perform output updates to the response buffer */ |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2119 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2120 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 2121 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2122 | * Note that we're checking CF_SHUTR_NOW as an indication of a possible |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2123 | * recent call to channel_abort(). |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2124 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2125 | if (unlikely(!res->analysers && |
| 2126 | !(res->flags & (CF_SHUTW|CF_SHUTR_NOW)) && |
| 2127 | (si_b->state >= SI_ST_EST) && |
| 2128 | (res->to_forward != CHN_INFINITE_FORWARD))) { |
Willy Tarreau | b31c971 | 2012-11-11 23:05:39 +0100 | [diff] [blame] | 2129 | /* This buffer is freewheeling, there's no analyser |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2130 | * attached to it. If any data are left in, we'll permit them to |
| 2131 | * move. |
| 2132 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2133 | channel_auto_read(res); |
| 2134 | channel_auto_close(res); |
| 2135 | buffer_flush(res->buf); |
Willy Tarreau | da4d9fe | 2010-11-07 20:26:56 +0100 | [diff] [blame] | 2136 | |
| 2137 | /* We'll let data flow between the producer (if still connected) |
| 2138 | * to the consumer. |
| 2139 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2140 | if (!(res->flags & (CF_SHUTR|CF_SHUTW_NOW))) |
| 2141 | channel_forward(res, CHN_INFINITE_FORWARD); |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2142 | |
| 2143 | /* if we have no analyser anymore in any direction and have a |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2144 | * tunnel timeout set, use it now. Note that we must respect |
| 2145 | * the half-closed timeouts as well. |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2146 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2147 | if (!req->analysers && s->be->timeout.tunnel) { |
| 2148 | req->rto = req->wto = res->rto = res->wto = |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2149 | s->be->timeout.tunnel; |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2150 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2151 | if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin)) |
| 2152 | res->wto = sess->fe->timeout.clientfin; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2153 | if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin)) |
| 2154 | res->rto = s->be->timeout.serverfin; |
| 2155 | if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin)) |
| 2156 | req->wto = s->be->timeout.serverfin; |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2157 | if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin)) |
| 2158 | req->rto = sess->fe->timeout.clientfin; |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2159 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2160 | req->rex = tick_add(now_ms, req->rto); |
| 2161 | req->wex = tick_add(now_ms, req->wto); |
| 2162 | res->rex = tick_add(now_ms, res->rto); |
| 2163 | res->wex = tick_add(now_ms, res->wto); |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2164 | } |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2165 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 2166 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2167 | /* check if it is wise to enable kernel splicing to forward response data */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2168 | if (!(res->flags & (CF_KERN_SPLICING|CF_SHUTR)) && |
| 2169 | res->to_forward && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2170 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2171 | (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->snd_pipe) && |
| 2172 | (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->rcv_pipe) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2173 | (pipes_used < global.maxpipes) && |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2174 | (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) || |
| 2175 | (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2176 | (res->flags & CF_STREAMER_FAST)))) { |
| 2177 | res->flags |= CF_KERN_SPLICING; |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2178 | } |
| 2179 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2180 | /* reflect what the L7 analysers have seen last */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2181 | rpf_last = res->flags; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2182 | |
| 2183 | /* |
| 2184 | * Now forward all shutdown requests between both sides of the buffer |
| 2185 | */ |
| 2186 | |
| 2187 | /* |
| 2188 | * FIXME: this is probably where we should produce error responses. |
| 2189 | */ |
| 2190 | |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2191 | /* first, let's check if the response buffer needs to shutdown(write) */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2192 | if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) == |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2193 | (CF_AUTO_CLOSE|CF_SHUTR))) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2194 | channel_shutw_now(res); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2195 | if (tick_isset(s->be->timeout.serverfin)) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2196 | req->wto = s->be->timeout.serverfin; |
| 2197 | req->wex = tick_add(now_ms, req->wto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2198 | } |
| 2199 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2200 | |
| 2201 | /* shutdown(write) pending */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2202 | if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW && |
| 2203 | channel_is_empty(res))) { |
| 2204 | si_shutw(si_f); |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2205 | if (tick_isset(sess->fe->timeout.clientfin)) { |
| 2206 | req->rto = sess->fe->timeout.clientfin; |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2207 | req->rex = tick_add(now_ms, req->rto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2208 | } |
| 2209 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2210 | |
| 2211 | /* shutdown(write) done on the client side, we must stop the server too */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2212 | if (unlikely((res->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW) && |
| 2213 | !res->analysers) |
| 2214 | channel_shutr_now(res); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2215 | |
| 2216 | /* shutdown(read) pending */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2217 | if (unlikely((res->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) { |
| 2218 | if (si_b->flags & SI_FL_NOHALF) |
| 2219 | si_b->flags |= SI_FL_NOLINGER; |
| 2220 | si_shutr(si_b); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2221 | if (tick_isset(s->be->timeout.serverfin)) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2222 | req->wto = s->be->timeout.serverfin; |
| 2223 | req->wex = tick_add(now_ms, req->wto); |
Willy Tarreau | 05cdd96 | 2014-05-10 14:30:07 +0200 | [diff] [blame] | 2224 | } |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2225 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2226 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2227 | if (si_f->state == SI_ST_DIS || si_b->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2228 | goto resync_stream_interface; |
| 2229 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2230 | if (req->flags != rqf_last) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2231 | goto resync_request; |
| 2232 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2233 | if ((res->flags ^ rpf_last) & CF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2234 | goto resync_response; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2235 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2236 | /* we're interested in getting wakeups again */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2237 | si_f->flags &= ~SI_FL_DONT_WAKE; |
| 2238 | si_b->flags &= ~SI_FL_DONT_WAKE; |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2239 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2240 | /* This is needed only when debugging is enabled, to indicate |
| 2241 | * client-side or server-side close. Please note that in the unlikely |
| 2242 | * event where both sides would close at once, the sequence is reported |
| 2243 | * on the server side first. |
| 2244 | */ |
| 2245 | if (unlikely((global.mode & MODE_DEBUG) && |
| 2246 | (!(global.mode & MODE_QUIET) || |
| 2247 | (global.mode & MODE_VERBOSE)))) { |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2248 | if (si_b->state == SI_ST_CLO && |
| 2249 | si_b->prev_state == SI_ST_EST) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2250 | chunk_printf(&trash, "%08x:%s.srvcls[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2251 | s->uniq_id, s->be->id, |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2252 | objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1, |
| 2253 | objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1); |
Willy Tarreau | 89efaed | 2013-12-13 15:14:55 +0100 | [diff] [blame] | 2254 | shut_your_big_mouth_gcc(write(1, trash.str, trash.len)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2255 | } |
| 2256 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2257 | if (si_f->state == SI_ST_CLO && |
| 2258 | si_f->prev_state == SI_ST_EST) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2259 | chunk_printf(&trash, "%08x:%s.clicls[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2260 | s->uniq_id, s->be->id, |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2261 | objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1, |
| 2262 | objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1); |
Willy Tarreau | 89efaed | 2013-12-13 15:14:55 +0100 | [diff] [blame] | 2263 | shut_your_big_mouth_gcc(write(1, trash.str, trash.len)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2264 | } |
| 2265 | } |
| 2266 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2267 | if (likely((si_f->state != SI_ST_CLO) || |
| 2268 | (si_b->state > SI_ST_INI && si_b->state < SI_ST_CLO))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2269 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2270 | if ((sess->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED)) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2271 | stream_process_counters(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2272 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2273 | if (si_f->state == SI_ST_EST && obj_type(si_f->end) != OBJ_TYPE_APPCTX) |
| 2274 | si_update(si_f); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2275 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2276 | if (si_b->state == SI_ST_EST && obj_type(si_b->end) != OBJ_TYPE_APPCTX) |
| 2277 | si_update(si_b); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2278 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2279 | req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED); |
| 2280 | res->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED); |
| 2281 | si_f->prev_state = si_f->state; |
| 2282 | si_b->prev_state = si_b->state; |
| 2283 | si_f->flags &= ~(SI_FL_ERR|SI_FL_EXP); |
| 2284 | si_b->flags &= ~(SI_FL_ERR|SI_FL_EXP); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2285 | |
Willy Tarreau | 6f0a7ba | 2014-06-23 15:22:31 +0200 | [diff] [blame] | 2286 | /* Trick: if a request is being waiting for the server to respond, |
| 2287 | * and if we know the server can timeout, we don't want the timeout |
| 2288 | * to expire on the client side first, but we're still interested |
| 2289 | * in passing data from the client to the server (eg: POST). Thus, |
| 2290 | * we can cancel the client's request timeout if the server's |
| 2291 | * request timeout is set and the server has not yet sent a response. |
| 2292 | */ |
| 2293 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2294 | if ((res->flags & (CF_AUTO_CLOSE|CF_SHUTR)) == 0 && |
| 2295 | (tick_isset(req->wex) || tick_isset(res->rex))) { |
| 2296 | req->flags |= CF_READ_NOEXP; |
| 2297 | req->rex = TICK_ETERNITY; |
Willy Tarreau | 6f0a7ba | 2014-06-23 15:22:31 +0200 | [diff] [blame] | 2298 | } |
| 2299 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 2300 | /* When any of the stream interfaces is attached to an applet, |
| 2301 | * we have to call it here. Note that this one may wake the |
| 2302 | * task up again. If at least one applet was called, the current |
| 2303 | * task might have been woken up, in which case we don't want it |
| 2304 | * to be requeued to the wait queue but rather to the run queue |
| 2305 | * to run ASAP. The bitwise "or" in the condition ensures that |
| 2306 | * both functions are always called and that we wake up if at |
| 2307 | * least one did something. |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2308 | */ |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2309 | if ((si_applet_call(si_b) | si_applet_call(si_f)) != 0) { |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2310 | if (task_in_rq(t)) { |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2311 | t->expire = TICK_ETERNITY; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2312 | stream_release_buffers(s); |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2313 | return t; |
| 2314 | } |
| 2315 | } |
| 2316 | |
Willy Tarreau | 798f432 | 2012-11-08 14:49:17 +0100 | [diff] [blame] | 2317 | update_exp_and_leave: |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2318 | t->expire = tick_first(tick_first(req->rex, req->wex), |
| 2319 | tick_first(res->rex, res->wex)); |
| 2320 | if (req->analysers) |
| 2321 | t->expire = tick_first(t->expire, req->analyse_exp); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2322 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2323 | if (si_f->exp) |
| 2324 | t->expire = tick_first(t->expire, si_f->exp); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2325 | |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2326 | if (si_b->exp) |
| 2327 | t->expire = tick_first(t->expire, si_b->exp); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2328 | |
| 2329 | #ifdef DEBUG_FULL |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 2330 | fprintf(stderr, |
| 2331 | "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u" |
| 2332 | " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n", |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2333 | now_ms, t->expire, req->rex, req->wex, req->analyse_exp, |
| 2334 | res->rex, res->wex, si_f->exp, si_b->exp, si_f->state, si_b->state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2335 | #endif |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2336 | |
| 2337 | #ifdef DEBUG_DEV |
| 2338 | /* this may only happen when no timeout is set or in case of an FSM bug */ |
Willy Tarreau | d0a201b | 2009-03-08 15:53:06 +0100 | [diff] [blame] | 2339 | if (!tick_isset(t->expire)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2340 | ABORT_NOW(); |
| 2341 | #endif |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2342 | stream_release_buffers(s); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2343 | return t; /* nothing more to do */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2344 | } |
| 2345 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2346 | sess->fe->feconn--; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2347 | if (s->flags & SF_BE_ASSIGNED) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2348 | s->be->beconn--; |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 2349 | jobs--; |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 2350 | if (sess->listener) { |
| 2351 | if (!(sess->listener->options & LI_O_UNLIMITED)) |
Thierry FOURNIER | a47a94f | 2014-03-20 15:42:53 +0100 | [diff] [blame] | 2352 | actconn--; |
Willy Tarreau | fb0afa7 | 2015-04-03 14:46:27 +0200 | [diff] [blame] | 2353 | sess->listener->nbconn--; |
| 2354 | if (sess->listener->state == LI_FULL) |
| 2355 | resume_listener(sess->listener); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2356 | |
Thierry FOURNIER | a47a94f | 2014-03-20 15:42:53 +0100 | [diff] [blame] | 2357 | /* Dequeues all of the listeners waiting for a resource */ |
| 2358 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2359 | dequeue_all_listeners(&global_listener_queue); |
Willy Tarreau | 08ceb10 | 2011-07-24 22:58:00 +0200 | [diff] [blame] | 2360 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2361 | if (!LIST_ISEMPTY(&sess->fe->listener_queue) && |
| 2362 | (!sess->fe->fe_sps_lim || freq_ctr_remain(&sess->fe->fe_sess_per_sec, sess->fe->fe_sps_lim, 0) > 0)) |
| 2363 | dequeue_all_listeners(&sess->fe->listener_queue); |
Thierry FOURNIER | a47a94f | 2014-03-20 15:42:53 +0100 | [diff] [blame] | 2364 | } |
Willy Tarreau | 07687c1 | 2011-07-24 23:55:06 +0200 | [diff] [blame] | 2365 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2366 | if (unlikely((global.mode & MODE_DEBUG) && |
| 2367 | (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2368 | chunk_printf(&trash, "%08x:%s.closed[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2369 | s->uniq_id, s->be->id, |
Willy Tarreau | 8f128b4 | 2014-11-28 15:07:47 +0100 | [diff] [blame] | 2370 | objt_conn(si_f->end) ? (unsigned short)objt_conn(si_f->end)->t.sock.fd : -1, |
| 2371 | objt_conn(si_b->end) ? (unsigned short)objt_conn(si_b->end)->t.sock.fd : -1); |
Willy Tarreau | 89efaed | 2013-12-13 15:14:55 +0100 | [diff] [blame] | 2372 | shut_your_big_mouth_gcc(write(1, trash.str, trash.len)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2376 | stream_process_counters(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2377 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 2378 | if (s->txn && s->txn->status) { |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2379 | int n; |
| 2380 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 2381 | n = s->txn->status / 100; |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2382 | if (n < 1 || n > 5) |
| 2383 | n = 0; |
| 2384 | |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2385 | if (sess->fe->mode == PR_MODE_HTTP) { |
| 2386 | sess->fe->fe_counters.p.http.rsp[n]++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2387 | if (s->comp_algo && (s->flags & SF_COMP_READY)) |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2388 | sess->fe->fe_counters.p.http.comp_rsp++; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2389 | } |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2390 | if ((s->flags & SF_BE_ASSIGNED) && |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2391 | (s->be->mode == PR_MODE_HTTP)) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2392 | s->be->be_counters.p.http.rsp[n]++; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2393 | s->be->be_counters.p.http.cum_req++; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2394 | if (s->comp_algo && (s->flags & SF_COMP_READY)) |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 2395 | s->be->be_counters.p.http.comp_rsp++; |
| 2396 | } |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2397 | } |
| 2398 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2399 | /* let's do a final log if we need it */ |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2400 | if (!LIST_ISEMPTY(&sess->fe->logformat) && s->logs.logwait && |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2401 | !(s->flags & SF_MONITOR) && |
Willy Tarreau | e36cbcb | 2015-04-03 15:40:56 +0200 | [diff] [blame] | 2402 | (!(sess->fe->options & PR_O_NULLNOLOG) || req->total)) { |
Willy Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 2403 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2406 | /* update time stats for this stream */ |
| 2407 | stream_update_time_stats(s); |
Willy Tarreau | 4bfc580 | 2014-06-17 12:19:18 +0200 | [diff] [blame] | 2408 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2409 | /* the task MUST not be in the run queue anymore */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2410 | stream_free(s); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2411 | task_delete(t); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2412 | task_free(t); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2413 | return NULL; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2416 | /* Update the stream's backend and server time stats */ |
| 2417 | void stream_update_time_stats(struct stream *s) |
Willy Tarreau | 4bfc580 | 2014-06-17 12:19:18 +0200 | [diff] [blame] | 2418 | { |
| 2419 | int t_request; |
| 2420 | int t_queue; |
| 2421 | int t_connect; |
| 2422 | int t_data; |
| 2423 | int t_close; |
| 2424 | struct server *srv; |
| 2425 | |
| 2426 | t_request = 0; |
| 2427 | t_queue = s->logs.t_queue; |
| 2428 | t_connect = s->logs.t_connect; |
| 2429 | t_close = s->logs.t_close; |
| 2430 | t_data = s->logs.t_data; |
| 2431 | |
| 2432 | if (s->be->mode != PR_MODE_HTTP) |
| 2433 | t_data = t_connect; |
| 2434 | |
| 2435 | if (t_connect < 0 || t_data < 0) |
| 2436 | return; |
| 2437 | |
| 2438 | if (tv_isge(&s->logs.tv_request, &s->logs.tv_accept)) |
| 2439 | t_request = tv_ms_elapsed(&s->logs.tv_accept, &s->logs.tv_request); |
| 2440 | |
| 2441 | t_data -= t_connect; |
| 2442 | t_connect -= t_queue; |
| 2443 | t_queue -= t_request; |
| 2444 | |
| 2445 | srv = objt_server(s->target); |
| 2446 | if (srv) { |
| 2447 | swrate_add(&srv->counters.q_time, TIME_STATS_SAMPLES, t_queue); |
| 2448 | swrate_add(&srv->counters.c_time, TIME_STATS_SAMPLES, t_connect); |
| 2449 | swrate_add(&srv->counters.d_time, TIME_STATS_SAMPLES, t_data); |
| 2450 | swrate_add(&srv->counters.t_time, TIME_STATS_SAMPLES, t_close); |
| 2451 | } |
| 2452 | swrate_add(&s->be->be_counters.q_time, TIME_STATS_SAMPLES, t_queue); |
| 2453 | swrate_add(&s->be->be_counters.c_time, TIME_STATS_SAMPLES, t_connect); |
| 2454 | swrate_add(&s->be->be_counters.d_time, TIME_STATS_SAMPLES, t_data); |
| 2455 | swrate_add(&s->be->be_counters.t_time, TIME_STATS_SAMPLES, t_close); |
| 2456 | } |
| 2457 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2458 | /* |
| 2459 | * This function adjusts sess->srv_conn and maintains the previous and new |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2460 | * server's served stream counts. Setting newsrv to NULL is enough to release |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2461 | * current connection slot. This function also notifies any LB algo which might |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2462 | * expect to be informed about any change in the number of active streams on a |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2463 | * server. |
| 2464 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2465 | void sess_change_server(struct stream *sess, struct server *newsrv) |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2466 | { |
| 2467 | if (sess->srv_conn == newsrv) |
| 2468 | return; |
| 2469 | |
| 2470 | if (sess->srv_conn) { |
| 2471 | sess->srv_conn->served--; |
| 2472 | if (sess->srv_conn->proxy->lbprm.server_drop_conn) |
| 2473 | sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2474 | stream_del_srv_conn(sess); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | if (newsrv) { |
| 2478 | newsrv->served++; |
| 2479 | if (newsrv->proxy->lbprm.server_take_conn) |
| 2480 | newsrv->proxy->lbprm.server_take_conn(newsrv); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2481 | stream_add_srv_conn(sess, newsrv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2485 | /* Handle server-side errors for default protocols. It is called whenever a a |
| 2486 | * connection setup is aborted or a request is aborted in queue. It sets the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2487 | * stream termination flags so that the caller does not have to worry about |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2488 | * them. It's installed as ->srv_error for the server-side stream_interface. |
| 2489 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2490 | void default_srv_error(struct stream *s, struct stream_interface *si) |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2491 | { |
| 2492 | int err_type = si->err_type; |
| 2493 | int err = 0, fin = 0; |
| 2494 | |
| 2495 | if (err_type & SI_ET_QUEUE_ABRT) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2496 | err = SF_ERR_CLICL; |
| 2497 | fin = SF_FINST_Q; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2498 | } |
| 2499 | else if (err_type & SI_ET_CONN_ABRT) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2500 | err = SF_ERR_CLICL; |
| 2501 | fin = SF_FINST_C; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2502 | } |
| 2503 | else if (err_type & SI_ET_QUEUE_TO) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2504 | err = SF_ERR_SRVTO; |
| 2505 | fin = SF_FINST_Q; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2506 | } |
| 2507 | else if (err_type & SI_ET_QUEUE_ERR) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2508 | err = SF_ERR_SRVCL; |
| 2509 | fin = SF_FINST_Q; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2510 | } |
| 2511 | else if (err_type & SI_ET_CONN_TO) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2512 | err = SF_ERR_SRVTO; |
| 2513 | fin = SF_FINST_C; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2514 | } |
| 2515 | else if (err_type & SI_ET_CONN_ERR) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2516 | err = SF_ERR_SRVCL; |
| 2517 | fin = SF_FINST_C; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2518 | } |
Willy Tarreau | 2d400bb | 2012-05-14 12:11:47 +0200 | [diff] [blame] | 2519 | else if (err_type & SI_ET_CONN_RES) { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2520 | err = SF_ERR_RESOURCE; |
| 2521 | fin = SF_FINST_C; |
Willy Tarreau | 2d400bb | 2012-05-14 12:11:47 +0200 | [diff] [blame] | 2522 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2523 | else /* SI_ET_CONN_OTHER and others */ { |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2524 | err = SF_ERR_INTERNAL; |
| 2525 | fin = SF_FINST_C; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2526 | } |
| 2527 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2528 | if (!(s->flags & SF_ERR_MASK)) |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2529 | s->flags |= err; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2530 | if (!(s->flags & SF_FINST_MASK)) |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2531 | s->flags |= fin; |
| 2532 | } |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2533 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2534 | /* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2535 | void stream_shutdown(struct stream *stream, int why) |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2536 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2537 | if (stream->req.flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2538 | return; |
| 2539 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2540 | channel_shutw_now(&stream->req); |
| 2541 | channel_shutr_now(&stream->res); |
| 2542 | stream->task->nice = 1024; |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2543 | if (!(stream->flags & SF_ERR_MASK)) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2544 | stream->flags |= why; |
| 2545 | task_wakeup(stream->task, TASK_WOKEN_OTHER); |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2546 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 2547 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2548 | /************************************************************************/ |
| 2549 | /* All supported ACL keywords must be declared here. */ |
| 2550 | /************************************************************************/ |
| 2551 | |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 2552 | /* Returns a pointer to a stkctr depending on the fetch keyword name. |
| 2553 | * It is designed to be called as sc[0-9]_* sc_* or src_* exclusively. |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2554 | * sc[0-9]_* will return a pointer to the respective field in the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2555 | * stream <l4>. sc_* requires an UINT argument specifying the stick |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 2556 | * counter number. src_* will fill a locally allocated structure with |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2557 | * the table and entry corresponding to what is specified with src_*. |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2558 | * NULL may be returned if the designated stkctr is not tracked. For |
| 2559 | * the sc_* and sc[0-9]_* forms, an optional table argument may be |
| 2560 | * passed. When present, the currently tracked key is then looked up |
| 2561 | * in the specified table instead of the current table. The purpose is |
| 2562 | * to be able to convery multiple values per key (eg: have gpc0 from |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 2563 | * multiple tables). <strm> is allowed to be NULL, in which case only |
| 2564 | * the session will be consulted. |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2565 | */ |
Willy Tarreau | e12704b | 2014-07-15 19:06:18 +0200 | [diff] [blame] | 2566 | struct stkctr * |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2567 | smp_fetch_sc_stkctr(struct session *sess, struct stream *strm, const struct arg *args, const char *kw) |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2568 | { |
| 2569 | static struct stkctr stkctr; |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 2570 | struct stkctr *stkptr; |
Willy Tarreau | 6a0b6bd | 2014-04-09 13:25:42 +0200 | [diff] [blame] | 2571 | struct stksess *stksess; |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 2572 | unsigned int num = kw[2] - '0'; |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2573 | int arg = 0; |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2574 | |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2575 | if (num == '_' - '0') { |
| 2576 | /* sc_* variant, args[0] = ctr# (mandatory) */ |
| 2577 | num = args[arg++].data.uint; |
Willy Tarreau | 4d4149c | 2013-07-23 19:33:46 +0200 | [diff] [blame] | 2578 | if (num >= MAX_SESS_STKCTR) |
| 2579 | return NULL; |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2580 | } |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2581 | else if (num > 9) { /* src_* variant, args[0] = table */ |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 2582 | struct stktable_key *key; |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 2583 | struct connection *conn = objt_conn(sess->origin); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 2584 | |
| 2585 | if (!conn) |
| 2586 | return NULL; |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2587 | |
Thierry FOURNIER | 74c219d | 2014-04-14 14:35:40 +0200 | [diff] [blame] | 2588 | key = addr_to_stktable_key(&conn->addr.from, args->data.prx->table.type); |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2589 | if (!key) |
| 2590 | return NULL; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 2591 | |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2592 | stkctr.table = &args->data.prx->table; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2593 | stkctr_set_entry(&stkctr, stktable_lookup_key(stkctr.table, key)); |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2594 | return &stkctr; |
| 2595 | } |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2596 | |
| 2597 | /* Here, <num> contains the counter number from 0 to 9 for |
| 2598 | * the sc[0-9]_ form, or even higher using sc_(num) if needed. |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 2599 | * args[arg] is the first optional argument. We first lookup the |
| 2600 | * ctr form the stream, then from the session if it was not there. |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2601 | */ |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 2602 | |
| 2603 | stkptr = &strm->stkctr[num]; |
| 2604 | if (!strm || !stkctr_entry(stkptr)) { |
| 2605 | stkptr = &sess->stkctr[num]; |
| 2606 | if (!stkctr_entry(stkptr)) |
| 2607 | return NULL; |
| 2608 | } |
| 2609 | |
| 2610 | stksess = stkctr_entry(stkptr); |
Willy Tarreau | 6a0b6bd | 2014-04-09 13:25:42 +0200 | [diff] [blame] | 2611 | if (!stksess) |
| 2612 | return NULL; |
| 2613 | |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2614 | if (unlikely(args[arg].type == ARGT_TAB)) { |
| 2615 | /* an alternate table was specified, let's look up the same key there */ |
| 2616 | stkctr.table = &args[arg].data.prx->table; |
Willy Tarreau | 6a0b6bd | 2014-04-09 13:25:42 +0200 | [diff] [blame] | 2617 | stkctr_set_entry(&stkctr, stktable_lookup(stkctr.table, stksess)); |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 2618 | return &stkctr; |
| 2619 | } |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 2620 | return stkptr; |
Willy Tarreau | a65536c | 2013-07-22 22:40:11 +0200 | [diff] [blame] | 2621 | } |
| 2622 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2623 | /* set return a boolean indicating if the requested stream counter is |
Willy Tarreau | 8882124 | 2013-07-22 18:29:29 +0200 | [diff] [blame] | 2624 | * currently being tracked or not. |
| 2625 | * Supports being called as "sc[0-9]_tracked" only. |
| 2626 | */ |
Willy Tarreau | 6f1615f | 2013-06-03 15:15:22 +0200 | [diff] [blame] | 2627 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2628 | smp_fetch_sc_tracked(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Willy Tarreau | 15e91e1 | 2015-04-04 00:52:09 +0200 | [diff] [blame] | 2629 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 6f1615f | 2013-06-03 15:15:22 +0200 | [diff] [blame] | 2630 | { |
| 2631 | smp->flags = SMP_F_VOL_TEST; |
| 2632 | smp->type = SMP_T_BOOL; |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2633 | smp->data.uint = !!smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 6f1615f | 2013-06-03 15:15:22 +0200 | [diff] [blame] | 2634 | return 1; |
| 2635 | } |
| 2636 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2637 | /* set <smp> to the General Purpose Counter 0 value from the stream's tracked |
Willy Tarreau | 30b2046 | 2013-07-22 19:46:52 +0200 | [diff] [blame] | 2638 | * frontend counters or from the src. |
| 2639 | * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value |
| 2640 | * zero is returned if the key is new. |
| 2641 | */ |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2642 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2643 | smp_fetch_sc_get_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2644 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2645 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2646 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 30b2046 | 2013-07-22 19:46:52 +0200 | [diff] [blame] | 2647 | |
| 2648 | if (!stkctr) |
| 2649 | return 0; |
| 2650 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2651 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2652 | smp->type = SMP_T_UINT; |
| 2653 | smp->data.uint = 0; |
Willy Tarreau | 30b2046 | 2013-07-22 19:46:52 +0200 | [diff] [blame] | 2654 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2655 | if (stkctr_entry(stkctr) != NULL) { |
| 2656 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2657 | if (!ptr) |
| 2658 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2659 | smp->data.uint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2660 | } |
| 2661 | return 1; |
| 2662 | } |
| 2663 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2664 | /* set <smp> to the General Purpose Counter 0's event rate from the stream's |
Willy Tarreau | b5e0af0 | 2013-07-22 23:47:07 +0200 | [diff] [blame] | 2665 | * tracked frontend counters or from the src. |
| 2666 | * Supports being called as "sc[0-9]_gpc0_rate" or "src_gpc0_rate" only. |
| 2667 | * Value zero is returned if the key is new. |
| 2668 | */ |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2669 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2670 | smp_fetch_sc_gpc0_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2671 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2672 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2673 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | b5e0af0 | 2013-07-22 23:47:07 +0200 | [diff] [blame] | 2674 | |
| 2675 | if (!stkctr) |
| 2676 | return 0; |
| 2677 | |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2678 | smp->flags = SMP_F_VOL_TEST; |
| 2679 | smp->type = SMP_T_UINT; |
| 2680 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2681 | if (stkctr_entry(stkctr) != NULL) { |
| 2682 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2683 | if (!ptr) |
| 2684 | return 0; /* parameter not stored */ |
| 2685 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), |
Willy Tarreau | b5e0af0 | 2013-07-22 23:47:07 +0200 | [diff] [blame] | 2686 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u); |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2687 | } |
| 2688 | return 1; |
| 2689 | } |
| 2690 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2691 | /* Increment the General Purpose Counter 0 value from the stream's tracked |
Willy Tarreau | 710d38c | 2013-07-23 00:07:04 +0200 | [diff] [blame] | 2692 | * frontend counters and return it into temp integer. |
| 2693 | * Supports being called as "sc[0-9]_inc_gpc0" or "src_inc_gpc0" only. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2694 | */ |
| 2695 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2696 | smp_fetch_sc_inc_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2697 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2698 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2699 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 710d38c | 2013-07-23 00:07:04 +0200 | [diff] [blame] | 2700 | |
| 2701 | if (!stkctr) |
| 2702 | return 0; |
| 2703 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2704 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2705 | smp->type = SMP_T_UINT; |
| 2706 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2707 | if (stkctr_entry(stkctr) != NULL) { |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2708 | void *ptr; |
| 2709 | |
| 2710 | /* First, update gpc0_rate if it's tracked. Second, update its |
| 2711 | * gpc0 if tracked. Returns gpc0's value otherwise the curr_ctr. |
| 2712 | */ |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2713 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2714 | if (ptr) { |
| 2715 | update_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), |
Willy Tarreau | 710d38c | 2013-07-23 00:07:04 +0200 | [diff] [blame] | 2716 | stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2717 | smp->data.uint = (&stktable_data_cast(ptr, gpc0_rate))->curr_ctr; |
| 2718 | } |
| 2719 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2720 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Willy Tarreau | ba2ffd1 | 2013-05-29 15:54:14 +0200 | [diff] [blame] | 2721 | if (ptr) |
| 2722 | smp->data.uint = ++stktable_data_cast(ptr, gpc0); |
| 2723 | |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2724 | } |
| 2725 | return 1; |
| 2726 | } |
| 2727 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2728 | /* Clear the General Purpose Counter 0 value from the stream's tracked |
Willy Tarreau | b9f441d | 2013-07-23 00:10:35 +0200 | [diff] [blame] | 2729 | * frontend counters and return its previous value into temp integer. |
| 2730 | * Supports being called as "sc[0-9]_clr_gpc0" or "src_clr_gpc0" only. |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2731 | */ |
| 2732 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2733 | smp_fetch_sc_clr_gpc0(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2734 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2735 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2736 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | b9f441d | 2013-07-23 00:10:35 +0200 | [diff] [blame] | 2737 | |
| 2738 | if (!stkctr) |
| 2739 | return 0; |
| 2740 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2741 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2742 | smp->type = SMP_T_UINT; |
| 2743 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2744 | if (stkctr_entry(stkctr) != NULL) { |
| 2745 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2746 | if (!ptr) |
| 2747 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2748 | smp->data.uint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2749 | stktable_data_cast(ptr, gpc0) = 0; |
| 2750 | } |
| 2751 | return 1; |
| 2752 | } |
| 2753 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2754 | /* set <smp> to the cumulated number of connections from the stream's tracked |
Willy Tarreau | 3b46c5c | 2013-07-23 00:22:50 +0200 | [diff] [blame] | 2755 | * frontend counters. Supports being called as "sc[0-9]_conn_cnt" or |
| 2756 | * "src_conn_cnt" only. |
| 2757 | */ |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2758 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2759 | smp_fetch_sc_conn_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2760 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2761 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2762 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 3b46c5c | 2013-07-23 00:22:50 +0200 | [diff] [blame] | 2763 | |
| 2764 | if (!stkctr) |
| 2765 | return 0; |
| 2766 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2767 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2768 | smp->type = SMP_T_UINT; |
| 2769 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2770 | if (stkctr_entry(stkctr) != NULL) { |
| 2771 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2772 | if (!ptr) |
| 2773 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2774 | smp->data.uint = stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2775 | } |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2776 | return 1; |
| 2777 | } |
| 2778 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2779 | /* set <smp> to the connection rate from the stream's tracked frontend |
Willy Tarreau | c8c6570 | 2013-07-23 15:09:35 +0200 | [diff] [blame] | 2780 | * counters. Supports being called as "sc[0-9]_conn_rate" or "src_conn_rate" |
| 2781 | * only. |
| 2782 | */ |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2783 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2784 | smp_fetch_sc_conn_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2785 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2786 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2787 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | c8c6570 | 2013-07-23 15:09:35 +0200 | [diff] [blame] | 2788 | |
| 2789 | if (!stkctr) |
| 2790 | return 0; |
| 2791 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2792 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2793 | smp->type = SMP_T_UINT; |
| 2794 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2795 | if (stkctr_entry(stkctr) != NULL) { |
| 2796 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2797 | if (!ptr) |
| 2798 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2799 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
Willy Tarreau | c8c6570 | 2013-07-23 15:09:35 +0200 | [diff] [blame] | 2800 | stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2801 | } |
| 2802 | return 1; |
| 2803 | } |
| 2804 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2805 | /* set temp integer to the number of connections from the stream's source address |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2806 | * in the table pointed to by expr, after updating it. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2807 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2808 | */ |
| 2809 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2810 | smp_fetch_src_updt_conn_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2811 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2812 | { |
Willy Tarreau | 9ad7bd4 | 2015-04-03 19:19:59 +0200 | [diff] [blame] | 2813 | struct connection *conn = objt_conn(sess->origin); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2814 | struct stksess *ts; |
| 2815 | struct stktable_key *key; |
| 2816 | void *ptr; |
| 2817 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 2818 | if (!conn) |
| 2819 | return 0; |
| 2820 | |
Thierry FOURNIER | 74c219d | 2014-04-14 14:35:40 +0200 | [diff] [blame] | 2821 | key = addr_to_stktable_key(&conn->addr.from, px->table.type); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2822 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2823 | return 0; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2824 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2825 | px = args->data.prx; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2826 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 2827 | if ((ts = stktable_update_key(&px->table, key)) == NULL) |
| 2828 | /* entry does not exist and could not be created */ |
| 2829 | return 0; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2830 | |
| 2831 | ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT); |
| 2832 | if (!ptr) |
| 2833 | return 0; /* parameter not stored in this table */ |
| 2834 | |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2835 | smp->type = SMP_T_UINT; |
| 2836 | smp->data.uint = ++stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2837 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2838 | return 1; |
| 2839 | } |
| 2840 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2841 | /* set <smp> to the number of concurrent connections from the stream's tracked |
Willy Tarreau | f44a553 | 2013-07-23 15:17:53 +0200 | [diff] [blame] | 2842 | * frontend counters. Supports being called as "sc[0-9]_conn_cur" or |
| 2843 | * "src_conn_cur" only. |
| 2844 | */ |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2845 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2846 | smp_fetch_sc_conn_cur(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2847 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2848 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2849 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | f44a553 | 2013-07-23 15:17:53 +0200 | [diff] [blame] | 2850 | |
| 2851 | if (!stkctr) |
| 2852 | return 0; |
| 2853 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2854 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2855 | smp->type = SMP_T_UINT; |
| 2856 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2857 | if (stkctr_entry(stkctr) != NULL) { |
| 2858 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2859 | if (!ptr) |
| 2860 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2861 | smp->data.uint = stktable_data_cast(ptr, conn_cur); |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2862 | } |
| 2863 | return 1; |
| 2864 | } |
| 2865 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2866 | /* set <smp> to the cumulated number of streams from the stream's tracked |
Willy Tarreau | 2084308 | 2013-07-23 15:35:33 +0200 | [diff] [blame] | 2867 | * frontend counters. Supports being called as "sc[0-9]_sess_cnt" or |
| 2868 | * "src_sess_cnt" only. |
| 2869 | */ |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2870 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2871 | smp_fetch_sc_sess_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2872 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2873 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2874 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 2084308 | 2013-07-23 15:35:33 +0200 | [diff] [blame] | 2875 | |
| 2876 | if (!stkctr) |
| 2877 | return 0; |
| 2878 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2879 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2880 | smp->type = SMP_T_UINT; |
| 2881 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2882 | if (stkctr_entry(stkctr) != NULL) { |
| 2883 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2884 | if (!ptr) |
| 2885 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2886 | smp->data.uint = stktable_data_cast(ptr, sess_cnt); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2887 | } |
| 2888 | return 1; |
| 2889 | } |
| 2890 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2891 | /* set <smp> to the stream rate from the stream's tracked frontend counters. |
Willy Tarreau | 3a96f3f | 2013-07-23 15:48:01 +0200 | [diff] [blame] | 2892 | * Supports being called as "sc[0-9]_sess_rate" or "src_sess_rate" only. |
| 2893 | */ |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2894 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2895 | smp_fetch_sc_sess_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2896 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2897 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2898 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 3a96f3f | 2013-07-23 15:48:01 +0200 | [diff] [blame] | 2899 | |
| 2900 | if (!stkctr) |
| 2901 | return 0; |
| 2902 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2903 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2904 | smp->type = SMP_T_UINT; |
| 2905 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2906 | if (stkctr_entry(stkctr) != NULL) { |
| 2907 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2908 | if (!ptr) |
| 2909 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2910 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
Willy Tarreau | 3a96f3f | 2013-07-23 15:48:01 +0200 | [diff] [blame] | 2911 | stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2912 | } |
| 2913 | return 1; |
| 2914 | } |
| 2915 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2916 | /* set <smp> to the cumulated number of HTTP requests from the stream's tracked |
Willy Tarreau | 91200da | 2013-07-23 15:55:19 +0200 | [diff] [blame] | 2917 | * frontend counters. Supports being called as "sc[0-9]_http_req_cnt" or |
| 2918 | * "src_http_req_cnt" only. |
| 2919 | */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2920 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2921 | smp_fetch_sc_http_req_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2922 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2923 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2924 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 91200da | 2013-07-23 15:55:19 +0200 | [diff] [blame] | 2925 | |
| 2926 | if (!stkctr) |
| 2927 | return 0; |
| 2928 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2929 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2930 | smp->type = SMP_T_UINT; |
| 2931 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2932 | if (stkctr_entry(stkctr) != NULL) { |
| 2933 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2934 | if (!ptr) |
| 2935 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2936 | smp->data.uint = stktable_data_cast(ptr, http_req_cnt); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2937 | } |
| 2938 | return 1; |
| 2939 | } |
| 2940 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2941 | /* set <smp> to the HTTP request rate from the stream's tracked frontend |
Willy Tarreau | cf47763 | 2013-07-23 16:04:37 +0200 | [diff] [blame] | 2942 | * counters. Supports being called as "sc[0-9]_http_req_rate" or |
| 2943 | * "src_http_req_rate" only. |
| 2944 | */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2945 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2946 | smp_fetch_sc_http_req_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2947 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2948 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2949 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | cf47763 | 2013-07-23 16:04:37 +0200 | [diff] [blame] | 2950 | |
| 2951 | if (!stkctr) |
| 2952 | return 0; |
| 2953 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2954 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2955 | smp->type = SMP_T_UINT; |
| 2956 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2957 | if (stkctr_entry(stkctr) != NULL) { |
| 2958 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2959 | if (!ptr) |
| 2960 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2961 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | cf47763 | 2013-07-23 16:04:37 +0200 | [diff] [blame] | 2962 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2963 | } |
| 2964 | return 1; |
| 2965 | } |
| 2966 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2967 | /* set <smp> to the cumulated number of HTTP requests errors from the stream's |
Willy Tarreau | 30d07c3 | 2013-07-23 16:45:38 +0200 | [diff] [blame] | 2968 | * tracked frontend counters. Supports being called as "sc[0-9]_http_err_cnt" or |
| 2969 | * "src_http_err_cnt" only. |
| 2970 | */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2971 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2972 | smp_fetch_sc_http_err_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2973 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2974 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2975 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 30d07c3 | 2013-07-23 16:45:38 +0200 | [diff] [blame] | 2976 | |
| 2977 | if (!stkctr) |
| 2978 | return 0; |
| 2979 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2980 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2981 | smp->type = SMP_T_UINT; |
| 2982 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 2983 | if (stkctr_entry(stkctr) != NULL) { |
| 2984 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2985 | if (!ptr) |
| 2986 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2987 | smp->data.uint = stktable_data_cast(ptr, http_err_cnt); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2988 | } |
| 2989 | return 1; |
| 2990 | } |
| 2991 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2992 | /* set <smp> to the HTTP request error rate from the stream's tracked frontend |
Willy Tarreau | 9daf262 | 2013-07-23 16:48:54 +0200 | [diff] [blame] | 2993 | * counters. Supports being called as "sc[0-9]_http_err_rate" or |
| 2994 | * "src_http_err_rate" only. |
| 2995 | */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2996 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 2997 | smp_fetch_sc_http_err_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 2998 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2999 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3000 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 9daf262 | 2013-07-23 16:48:54 +0200 | [diff] [blame] | 3001 | |
| 3002 | if (!stkctr) |
| 3003 | return 0; |
| 3004 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3005 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3006 | smp->type = SMP_T_UINT; |
| 3007 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3008 | if (stkctr_entry(stkctr) != NULL) { |
| 3009 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3010 | if (!ptr) |
| 3011 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3012 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
Willy Tarreau | 9daf262 | 2013-07-23 16:48:54 +0200 | [diff] [blame] | 3013 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3014 | } |
| 3015 | return 1; |
| 3016 | } |
| 3017 | |
Willy Tarreau | 5077d4b | 2013-07-23 17:17:10 +0200 | [diff] [blame] | 3018 | /* set <smp> to the number of kbytes received from clients, as found in the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3019 | * stream's tracked frontend counters. Supports being called as |
Willy Tarreau | 5077d4b | 2013-07-23 17:17:10 +0200 | [diff] [blame] | 3020 | * "sc[0-9]_kbytes_in" or "src_kbytes_in" only. |
| 3021 | */ |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3022 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3023 | smp_fetch_sc_kbytes_in(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3024 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3025 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3026 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 5077d4b | 2013-07-23 17:17:10 +0200 | [diff] [blame] | 3027 | |
| 3028 | if (!stkctr) |
| 3029 | return 0; |
| 3030 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3031 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3032 | smp->type = SMP_T_UINT; |
| 3033 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3034 | if (stkctr_entry(stkctr) != NULL) { |
| 3035 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3036 | if (!ptr) |
| 3037 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3038 | smp->data.uint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3039 | } |
| 3040 | return 1; |
| 3041 | } |
| 3042 | |
Willy Tarreau | 613fe99 | 2013-07-23 17:39:19 +0200 | [diff] [blame] | 3043 | /* set <smp> to the data rate received from clients in bytes/s, as found |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3044 | * in the stream's tracked frontend counters. Supports being called as |
Willy Tarreau | 613fe99 | 2013-07-23 17:39:19 +0200 | [diff] [blame] | 3045 | * "sc[0-9]_bytes_in_rate" or "src_bytes_in_rate" only. |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3046 | */ |
| 3047 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3048 | smp_fetch_sc_bytes_in_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3049 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3050 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3051 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 613fe99 | 2013-07-23 17:39:19 +0200 | [diff] [blame] | 3052 | |
| 3053 | if (!stkctr) |
| 3054 | return 0; |
| 3055 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3056 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3057 | smp->type = SMP_T_UINT; |
| 3058 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3059 | if (stkctr_entry(stkctr) != NULL) { |
| 3060 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3061 | if (!ptr) |
| 3062 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3063 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
Willy Tarreau | 613fe99 | 2013-07-23 17:39:19 +0200 | [diff] [blame] | 3064 | stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3065 | } |
| 3066 | return 1; |
| 3067 | } |
| 3068 | |
Willy Tarreau | 53aea10 | 2013-07-23 17:39:02 +0200 | [diff] [blame] | 3069 | /* set <smp> to the number of kbytes sent to clients, as found in the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3070 | * stream's tracked frontend counters. Supports being called as |
Willy Tarreau | 53aea10 | 2013-07-23 17:39:02 +0200 | [diff] [blame] | 3071 | * "sc[0-9]_kbytes_out" or "src_kbytes_out" only. |
| 3072 | */ |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3073 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3074 | smp_fetch_sc_kbytes_out(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Willy Tarreau | 15e91e1 | 2015-04-04 00:52:09 +0200 | [diff] [blame] | 3075 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3076 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3077 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 53aea10 | 2013-07-23 17:39:02 +0200 | [diff] [blame] | 3078 | |
| 3079 | if (!stkctr) |
| 3080 | return 0; |
| 3081 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3082 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3083 | smp->type = SMP_T_UINT; |
| 3084 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3085 | if (stkctr_entry(stkctr) != NULL) { |
| 3086 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3087 | if (!ptr) |
| 3088 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3089 | smp->data.uint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3090 | } |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3091 | return 1; |
| 3092 | } |
| 3093 | |
Willy Tarreau | a0b68ed | 2013-07-23 18:26:32 +0200 | [diff] [blame] | 3094 | /* set <smp> to the data rate sent to clients in bytes/s, as found in the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3095 | * stream's tracked frontend counters. Supports being called as |
Willy Tarreau | a0b68ed | 2013-07-23 18:26:32 +0200 | [diff] [blame] | 3096 | * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3097 | */ |
| 3098 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3099 | smp_fetch_sc_bytes_out_rate(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3100 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3101 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3102 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | a0b68ed | 2013-07-23 18:26:32 +0200 | [diff] [blame] | 3103 | |
| 3104 | if (!stkctr) |
| 3105 | return 0; |
| 3106 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3107 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3108 | smp->type = SMP_T_UINT; |
| 3109 | smp->data.uint = 0; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3110 | if (stkctr_entry(stkctr) != NULL) { |
| 3111 | void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3112 | if (!ptr) |
| 3113 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3114 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
Willy Tarreau | a0b68ed | 2013-07-23 18:26:32 +0200 | [diff] [blame] | 3115 | stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3116 | } |
| 3117 | return 1; |
| 3118 | } |
| 3119 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3120 | /* set <smp> to the number of active trackers on the SC entry in the stream's |
Willy Tarreau | 563eef4 | 2013-07-23 18:32:02 +0200 | [diff] [blame] | 3121 | * tracked frontend counters. Supports being called as "sc[0-9]_trackers" only. |
| 3122 | */ |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 3123 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3124 | smp_fetch_sc_trackers(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3125 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 3126 | { |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3127 | struct stkctr *stkctr = smp_fetch_sc_stkctr(sess, strm, args, kw); |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 3128 | |
Willy Tarreau | 563eef4 | 2013-07-23 18:32:02 +0200 | [diff] [blame] | 3129 | if (!stkctr) |
Willy Tarreau | 2406db4 | 2012-12-09 12:16:43 +0100 | [diff] [blame] | 3130 | return 0; |
| 3131 | |
Willy Tarreau | 563eef4 | 2013-07-23 18:32:02 +0200 | [diff] [blame] | 3132 | smp->flags = SMP_F_VOL_TEST; |
| 3133 | smp->type = SMP_T_UINT; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 3134 | smp->data.uint = stkctr_entry(stkctr)->ref_cnt; |
Willy Tarreau | 563eef4 | 2013-07-23 18:32:02 +0200 | [diff] [blame] | 3135 | return 1; |
Willy Tarreau | e25c917 | 2013-05-28 18:32:20 +0200 | [diff] [blame] | 3136 | } |
| 3137 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3138 | /* set temp integer to the number of used entries in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3139 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3140 | */ |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3141 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3142 | smp_fetch_table_cnt(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3143 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3144 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3145 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3146 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3147 | smp->data.uint = args->data.prx->table.current; |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3148 | return 1; |
| 3149 | } |
| 3150 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3151 | /* set temp integer to the number of free entries in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3152 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3153 | */ |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3154 | static int |
Willy Tarreau | 192252e | 2015-04-04 01:47:55 +0200 | [diff] [blame] | 3155 | smp_fetch_table_avl(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, |
Thierry FOURNIER | f41a809 | 2014-12-07 18:37:57 +0100 | [diff] [blame] | 3156 | const struct arg *args, struct sample *smp, const char *kw, void *private) |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3157 | { |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3158 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3159 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3160 | smp->type = SMP_T_UINT; |
| 3161 | smp->data.uint = px->table.size - px->table.current; |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3162 | return 1; |
| 3163 | } |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3164 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 3165 | /* Note: must not be declared <const> as its list will be overwritten. |
| 3166 | * Please take care of keeping this list alphabetically sorted. |
| 3167 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 3168 | static struct acl_kw_list acl_kws = {ILH, { |
Willy Tarreau | 281c799 | 2013-01-08 01:23:27 +0100 | [diff] [blame] | 3169 | { /* END */ }, |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3170 | }}; |
| 3171 | |
Willy Tarreau | 281c799 | 2013-01-08 01:23:27 +0100 | [diff] [blame] | 3172 | /* Note: must not be declared <const> as its list will be overwritten. |
| 3173 | * Please take care of keeping this list alphabetically sorted. |
| 3174 | */ |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 3175 | static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { |
Willy Tarreau | 0f791d4 | 2013-07-23 19:56:43 +0200 | [diff] [blame] | 3176 | { "sc_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3177 | { "sc_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3178 | { "sc_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3179 | { "sc_conn_cnt", smp_fetch_sc_conn_cnt, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3180 | { "sc_conn_cur", smp_fetch_sc_conn_cur, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3181 | { "sc_conn_rate", smp_fetch_sc_conn_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3182 | { "sc_get_gpc0", smp_fetch_sc_get_gpc0, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3183 | { "sc_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3184 | { "sc_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3185 | { "sc_http_err_rate", smp_fetch_sc_http_err_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3186 | { "sc_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3187 | { "sc_http_req_rate", smp_fetch_sc_http_req_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3188 | { "sc_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3189 | { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3190 | { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3191 | { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3192 | { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3193 | { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,UINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3194 | { "sc_trackers", smp_fetch_sc_trackers, ARG2(1,UINT,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3195 | { "sc0_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3196 | { "sc0_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3197 | { "sc0_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3198 | { "sc0_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3199 | { "sc0_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3200 | { "sc0_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3201 | { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3202 | { "sc0_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3203 | { "sc0_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3204 | { "sc0_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3205 | { "sc0_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3206 | { "sc0_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3207 | { "sc0_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3208 | { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3209 | { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3210 | { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3211 | { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3212 | { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3213 | { "sc0_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3214 | { "sc1_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3215 | { "sc1_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3216 | { "sc1_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3217 | { "sc1_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3218 | { "sc1_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3219 | { "sc1_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3220 | { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3221 | { "sc1_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3222 | { "sc1_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3223 | { "sc1_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3224 | { "sc1_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3225 | { "sc1_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3226 | { "sc1_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3227 | { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3228 | { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3229 | { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3230 | { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3231 | { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3232 | { "sc1_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3233 | { "sc2_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3234 | { "sc2_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3235 | { "sc2_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3236 | { "sc2_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3237 | { "sc2_conn_cur", smp_fetch_sc_conn_cur, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3238 | { "sc2_conn_rate", smp_fetch_sc_conn_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3239 | { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3240 | { "sc2_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3241 | { "sc2_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3242 | { "sc2_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3243 | { "sc2_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3244 | { "sc2_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3245 | { "sc2_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3246 | { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3247 | { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3248 | { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3249 | { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3250 | { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, |
| 3251 | { "sc2_trackers", smp_fetch_sc_trackers, ARG1(0,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3252 | { "src_bytes_in_rate", smp_fetch_sc_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3253 | { "src_bytes_out_rate", smp_fetch_sc_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3254 | { "src_clr_gpc0", smp_fetch_sc_clr_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3255 | { "src_conn_cnt", smp_fetch_sc_conn_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3256 | { "src_conn_cur", smp_fetch_sc_conn_cur, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3257 | { "src_conn_rate", smp_fetch_sc_conn_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3258 | { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3259 | { "src_gpc0_rate", smp_fetch_sc_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3260 | { "src_http_err_cnt", smp_fetch_sc_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3261 | { "src_http_err_rate", smp_fetch_sc_http_err_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3262 | { "src_http_req_cnt", smp_fetch_sc_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3263 | { "src_http_req_rate", smp_fetch_sc_http_req_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3264 | { "src_inc_gpc0", smp_fetch_sc_inc_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3265 | { "src_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3266 | { "src_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3267 | { "src_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3268 | { "src_sess_rate", smp_fetch_sc_sess_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3269 | { "src_updt_conn_cnt", smp_fetch_src_updt_conn_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, }, |
| 3270 | { "table_avl", smp_fetch_table_avl, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
| 3271 | { "table_cnt", smp_fetch_table_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_INTRN, }, |
Willy Tarreau | 281c799 | 2013-01-08 01:23:27 +0100 | [diff] [blame] | 3272 | { /* END */ }, |
| 3273 | }}; |
| 3274 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3275 | __attribute__((constructor)) |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 3276 | static void __stream_init(void) |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3277 | { |
Willy Tarreau | 281c799 | 2013-01-08 01:23:27 +0100 | [diff] [blame] | 3278 | sample_register_fetches(&smp_fetch_keywords); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3279 | acl_register_keywords(&acl_kws); |
| 3280 | } |
| 3281 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3282 | /* |
| 3283 | * Local variables: |
| 3284 | * c-indent-level: 8 |
| 3285 | * c-basic-offset: 8 |
| 3286 | * End: |
| 3287 | */ |