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