Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2 | * include/proto/stream.h |
| 3 | * This file defines everything related to streams. |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 22 | #ifndef _PROTO_STREAM_H |
| 23 | #define _PROTO_STREAM_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 26 | #include <common/memory.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 27 | #include <types/stream.h> |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 28 | #include <proto/fd.h> |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 29 | #include <proto/freq_ctr.h> |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 30 | #include <proto/stick_table.h> |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 31 | #include <proto/task.h> |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 33 | extern struct pool_head *pool2_stream; |
| 34 | extern struct list streams; |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 35 | |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 36 | extern struct data_cb sess_conn_cb; |
| 37 | |
Willy Tarreau | 87787ac | 2017-08-28 16:22:54 +0200 | [diff] [blame] | 38 | struct stream *stream_new(struct session *sess, enum obj_type *origin); |
Willy Tarreau | 5790eb0 | 2017-08-28 17:18:36 +0200 | [diff] [blame] | 39 | int stream_create_from_conn(struct connection *conn); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 41 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 42 | int init_stream(); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 44 | /* 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] | 45 | void stream_shutdown(struct stream *stream, int why); |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 46 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 47 | void stream_process_counters(struct stream *s); |
| 48 | void sess_change_server(struct stream *sess, struct server *newsrv); |
| 49 | struct task *process_stream(struct task *t); |
| 50 | void default_srv_error(struct stream *s, struct stream_interface *si); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 51 | int parse_track_counters(char **args, int *arg, |
| 52 | int section_type, struct proxy *curpx, |
| 53 | struct track_ctr_prm *prm, |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 54 | struct proxy *defpx, char **err); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 55 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 56 | /* Update the stream's backend and server time stats */ |
| 57 | void stream_update_time_stats(struct stream *s); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 58 | void stream_release_buffers(struct stream *s); |
Willy Tarreau | 4bfc580 | 2014-06-17 12:19:18 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | b1ec8c4 | 2015-04-03 13:53:24 +0200 | [diff] [blame] | 60 | /* returns the session this stream belongs to */ |
| 61 | static inline struct session *strm_sess(const struct stream *strm) |
| 62 | { |
| 63 | return strm->sess; |
| 64 | } |
| 65 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 66 | /* returns the frontend this stream was initiated from */ |
| 67 | static inline struct proxy *strm_fe(const struct stream *strm) |
| 68 | { |
| 69 | return strm->sess->fe; |
| 70 | } |
| 71 | |
| 72 | /* returns the listener this stream was initiated from */ |
| 73 | static inline struct listener *strm_li(const struct stream *strm) |
| 74 | { |
| 75 | return strm->sess->listener; |
| 76 | } |
| 77 | |
| 78 | /* returns a pointer to the origin of the session which created this stream */ |
| 79 | static inline enum obj_type *strm_orig(const struct stream *strm) |
| 80 | { |
| 81 | return strm->sess->origin; |
| 82 | } |
| 83 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 84 | /* Remove the refcount from the stream to the tracked counters, and clear the |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 85 | * pointer to ensure this is only performed once. The caller is responsible for |
Willy Tarreau | a68f762 | 2015-09-21 17:48:24 +0200 | [diff] [blame] | 86 | * ensuring that the pointer is valid first. We must be extremely careful not |
| 87 | * to touch the entries we inherited from the session. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 88 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 89 | static inline void stream_store_counters(struct stream *s) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 90 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 91 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 92 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 93 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 94 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 95 | if (!stkctr_entry(&s->stkctr[i])) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 96 | continue; |
Willy Tarreau | a68f762 | 2015-09-21 17:48:24 +0200 | [diff] [blame] | 97 | |
| 98 | if (stkctr_entry(&s->sess->stkctr[i])) |
| 99 | continue; |
| 100 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 101 | ptr = stktable_data_ptr(s->stkctr[i].table, stkctr_entry(&s->stkctr[i]), STKTABLE_DT_CONN_CUR); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 102 | if (ptr) |
| 103 | stktable_data_cast(ptr, conn_cur)--; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 104 | stkctr_entry(&s->stkctr[i])->ref_cnt--; |
| 105 | stksess_kill_if_expired(s->stkctr[i].table, stkctr_entry(&s->stkctr[i])); |
| 106 | stkctr_set_entry(&s->stkctr[i], NULL); |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 107 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 110 | /* Remove the refcount from the stream counters tracked at the content level if |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 111 | * any, and clear the pointer to ensure this is only performed once. The caller |
Willy Tarreau | a68f762 | 2015-09-21 17:48:24 +0200 | [diff] [blame] | 112 | * is responsible for ensuring that the pointer is valid first. We must be |
| 113 | * extremely careful not to touch the entries we inherited from the session. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 114 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 115 | static inline void stream_stop_content_counters(struct stream *s) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 116 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 117 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 118 | int i; |
Willy Tarreau | e348793 | 2010-06-18 21:03:20 +0200 | [diff] [blame] | 119 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 120 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 121 | if (!stkctr_entry(&s->stkctr[i])) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 122 | continue; |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 123 | |
Willy Tarreau | a68f762 | 2015-09-21 17:48:24 +0200 | [diff] [blame] | 124 | if (stkctr_entry(&s->sess->stkctr[i])) |
| 125 | continue; |
| 126 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 127 | if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_CONTENT)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 128 | continue; |
| 129 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 130 | ptr = stktable_data_ptr(s->stkctr[i].table, stkctr_entry(&s->stkctr[i]), STKTABLE_DT_CONN_CUR); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 131 | if (ptr) |
| 132 | stktable_data_cast(ptr, conn_cur)--; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 133 | stkctr_entry(&s->stkctr[i])->ref_cnt--; |
| 134 | stksess_kill_if_expired(s->stkctr[i].table, stkctr_entry(&s->stkctr[i])); |
| 135 | stkctr_set_entry(&s->stkctr[i], NULL); |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 136 | } |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 137 | } |
Willy Tarreau | e348793 | 2010-06-18 21:03:20 +0200 | [diff] [blame] | 138 | |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 139 | /* Increase total and concurrent connection count for stick entry <ts> of table |
| 140 | * <t>. The caller is responsible for ensuring that <t> and <ts> are valid |
| 141 | * pointers, and for calling this only once per connection. |
| 142 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 143 | static inline void stream_start_counters(struct stktable *t, struct stksess *ts) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 144 | { |
| 145 | void *ptr; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 146 | |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 147 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR); |
| 148 | if (ptr) |
| 149 | stktable_data_cast(ptr, conn_cur)++; |
| 150 | |
| 151 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT); |
| 152 | if (ptr) |
| 153 | stktable_data_cast(ptr, conn_cnt)++; |
| 154 | |
| 155 | ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE); |
| 156 | if (ptr) |
| 157 | update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
| 158 | t->data_arg[STKTABLE_DT_CONN_RATE].u, 1); |
| 159 | if (tick_isset(t->expire)) |
| 160 | ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire)); |
| 161 | } |
| 162 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 163 | /* Enable tracking of stream counters as <stkctr> on stksess <ts>. The caller is |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 164 | * responsible for ensuring that <t> and <ts> are valid pointers. Some controls |
| 165 | * are performed to ensure the state can still change. |
| 166 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 167 | static inline void stream_track_stkctr(struct stkctr *ctr, struct stktable *t, struct stksess *ts) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 168 | { |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 169 | if (stkctr_entry(ctr)) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 170 | return; |
| 171 | |
| 172 | ts->ref_cnt++; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 173 | ctr->table = t; |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 174 | stkctr_set_entry(ctr, ts); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 175 | stream_start_counters(t, ts); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 178 | /* Increase the number of cumulated HTTP requests in the tracked counters */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 179 | static void inline stream_inc_http_req_ctr(struct stream *s) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 180 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 181 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 182 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 183 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 184 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 185 | struct stkctr *stkctr = &s->stkctr[i]; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 186 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 187 | if (!stkctr_entry(stkctr)) { |
| 188 | stkctr = &s->sess->stkctr[i]; |
| 189 | if (!stkctr_entry(stkctr)) |
| 190 | continue; |
| 191 | } |
| 192 | |
| 193 | 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] | 194 | if (ptr) |
| 195 | stktable_data_cast(ptr, http_req_cnt)++; |
| 196 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 197 | 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] | 198 | if (ptr) |
| 199 | update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 200 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 204 | /* Increase the number of cumulated HTTP requests in the backend's tracked |
| 205 | * counters. We don't look up the session since it cannot happen in the bakcend. |
| 206 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 207 | static void inline stream_inc_be_http_req_ctr(struct stream *s) |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 208 | { |
| 209 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 210 | int i; |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 211 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 212 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 213 | struct stkctr *stkctr = &s->stkctr[i]; |
| 214 | |
| 215 | if (!stkctr_entry(stkctr)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 216 | continue; |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 217 | |
Willy Tarreau | cc08d2c | 2014-01-28 23:18:23 +0100 | [diff] [blame] | 218 | if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_BACKEND)) |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 219 | continue; |
| 220 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 221 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 222 | if (ptr) |
| 223 | stktable_data_cast(ptr, http_req_cnt)++; |
| 224 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 225 | ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 226 | if (ptr) |
| 227 | update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 228 | stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1); |
Willy Tarreau | 5d5b5d8 | 2012-12-09 12:00:04 +0100 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 232 | /* Increase the number of cumulated failed HTTP requests in the tracked |
| 233 | * counters. Only 4xx requests should be counted here so that we can |
| 234 | * distinguish between errors caused by client behaviour and other ones. |
| 235 | * Note that even 404 are interesting because they're generally caused by |
| 236 | * vulnerability scans. |
| 237 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 238 | static void inline stream_inc_http_err_ctr(struct stream *s) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 239 | { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 240 | void *ptr; |
Willy Tarreau | 20d46a5 | 2012-12-09 15:55:40 +0100 | [diff] [blame] | 241 | int i; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 242 | |
Willy Tarreau | b4c8493 | 2013-07-23 19:15:30 +0200 | [diff] [blame] | 243 | for (i = 0; i < MAX_SESS_STKCTR; i++) { |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 244 | struct stkctr *stkctr = &s->stkctr[i]; |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 245 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 246 | if (!stkctr_entry(stkctr)) { |
| 247 | stkctr = &s->sess->stkctr[i]; |
| 248 | if (!stkctr_entry(stkctr)) |
| 249 | continue; |
| 250 | } |
| 251 | |
| 252 | 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] | 253 | if (ptr) |
| 254 | stktable_data_cast(ptr, http_err_cnt)++; |
| 255 | |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 256 | 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] | 257 | if (ptr) |
| 258 | update_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
Willy Tarreau | 8b7f868 | 2015-04-04 16:29:12 +0200 | [diff] [blame] | 259 | stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 263 | static void inline stream_add_srv_conn(struct stream *sess, struct server *srv) |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 264 | { |
| 265 | sess->srv_conn = srv; |
| 266 | LIST_ADD(&srv->actconns, &sess->by_srv); |
| 267 | } |
| 268 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 269 | static void inline stream_del_srv_conn(struct stream *sess) |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 270 | { |
| 271 | if (!sess->srv_conn) |
| 272 | return; |
| 273 | |
| 274 | sess->srv_conn = NULL; |
| 275 | LIST_DEL(&sess->by_srv); |
| 276 | } |
| 277 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 278 | static void inline stream_init_srv_conn(struct stream *sess) |
Willy Tarreau | 9bd0d74 | 2011-07-20 00:17:39 +0200 | [diff] [blame] | 279 | { |
| 280 | sess->srv_conn = NULL; |
| 281 | LIST_INIT(&sess->by_srv); |
| 282 | } |
| 283 | |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 284 | /* Callback used to wake up a stream when a buffer is available. The stream <s> |
| 285 | * is woken up is if it is not already running and if it is not already in the |
| 286 | * task run queue. This functions returns 1 is the stream is woken up, otherwise |
| 287 | * it returns 0. */ |
| 288 | static int inline stream_res_wakeup(struct stream *s) |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 289 | { |
Emeric Brun | ff44917 | 2017-03-31 12:04:09 +0200 | [diff] [blame] | 290 | if (s->task->state & TASK_RUNNING) |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 291 | return 0; |
| 292 | task_wakeup(s->task, TASK_WOKEN_RES); |
| 293 | return 1; |
Willy Tarreau | a24adf0 | 2014-11-27 01:11:56 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Thierry FOURNIER | 5a363e7 | 2015-09-27 19:29:33 +0200 | [diff] [blame] | 296 | void service_keywords_register(struct action_kw_list *kw_list); |
| 297 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 298 | #endif /* _PROTO_STREAM_H */ |
Willy TARREAU | 3dc0644 | 2006-06-15 21:48:13 +0200 | [diff] [blame] | 299 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 300 | /* |
| 301 | * Local variables: |
| 302 | * c-indent-level: 8 |
| 303 | * c-basic-offset: 8 |
| 304 | * End: |
| 305 | */ |