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