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