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