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