blob: f44820977055642f897a0e7feaa5f4771bdd68b6 [file] [log] [blame]
Willy TARREAU3dc06442006-06-15 21:48:13 +02001/*
Willy Tarreau87b09662015-04-03 00:22:06 +02002 * include/proto/stream.h
3 * This file defines everything related to streams.
Willy Tarreau81f9aa32010-06-01 17:45:26 +02004 *
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 TARREAU3dc06442006-06-15 21:48:13 +020021
Willy Tarreau87b09662015-04-03 00:22:06 +020022#ifndef _PROTO_STREAM_H
23#define _PROTO_STREAM_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020026#include <common/memory.h>
Willy Tarreau61c112a2018-10-02 16:43:32 +020027#include <types/action.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020028#include <types/stream.h>
Willy Tarreaua24adf02014-11-27 01:11:56 +010029#include <proto/fd.h>
Willy Tarreau91c43d72010-06-20 11:19:22 +020030#include <proto/freq_ctr.h>
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020031#include <proto/stick_table.h>
Willy Tarreaua24adf02014-11-27 01:11:56 +010032#include <proto/task.h>
Willy TARREAU3dc06442006-06-15 21:48:13 +020033
Willy Tarreaubafbe012017-11-24 17:34:44 +010034extern struct pool_head *pool_head_stream;
Willy Tarreau87b09662015-04-03 00:22:06 +020035extern struct list streams;
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020036
Willy Tarreaubc174aa2012-11-19 16:10:32 +010037extern struct data_cb sess_conn_cb;
38
Willy Tarreau87787ac2017-08-28 16:22:54 +020039struct stream *stream_new(struct session *sess, enum obj_type *origin);
Olivier Houchard9aaf7782017-09-13 18:30:23 +020040int stream_create_from_cs(struct conn_stream *cs);
Willy Tarreaubaaee002006-06-26 02:48:02 +020041
Willy Tarreaue7dff022015-04-03 01:14:29 +020042/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +020043void stream_shutdown(struct stream *stream, int why);
Simon Hormandec5be42011-06-08 09:19:07 +090044
Willy Tarreau87b09662015-04-03 00:22:06 +020045void stream_process_counters(struct stream *s);
46void sess_change_server(struct stream *sess, struct server *newsrv);
Olivier Houchard9f6af332018-05-25 14:04:04 +020047struct task *process_stream(struct task *t, void *context, unsigned short state);
Willy Tarreau87b09662015-04-03 00:22:06 +020048void default_srv_error(struct stream *s, struct stream_interface *si);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020049int parse_track_counters(char **args, int *arg,
50 int section_type, struct proxy *curpx,
51 struct track_ctr_prm *prm,
Willy Tarreau0a3dd742012-05-08 19:47:01 +020052 struct proxy *defpx, char **err);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020053
Willy Tarreau87b09662015-04-03 00:22:06 +020054/* Update the stream's backend and server time stats */
55void stream_update_time_stats(struct stream *s);
Willy Tarreau87b09662015-04-03 00:22:06 +020056void stream_release_buffers(struct stream *s);
Willy Tarreaub882dd82018-11-06 15:50:21 +010057int stream_buf_available(void *arg);
Willy Tarreau4bfc5802014-06-17 12:19:18 +020058
Willy Tarreaub1ec8c42015-04-03 13:53:24 +020059/* returns the session this stream belongs to */
60static inline struct session *strm_sess(const struct stream *strm)
61{
62 return strm->sess;
63}
64
Willy Tarreaud0d8da92015-04-04 02:10:38 +020065/* returns the frontend this stream was initiated from */
66static inline struct proxy *strm_fe(const struct stream *strm)
67{
68 return strm->sess->fe;
69}
70
71/* returns the listener this stream was initiated from */
72static inline struct listener *strm_li(const struct stream *strm)
73{
74 return strm->sess->listener;
75}
76
77/* returns a pointer to the origin of the session which created this stream */
78static inline enum obj_type *strm_orig(const struct stream *strm)
79{
80 return strm->sess->origin;
81}
82
Willy Tarreau87b09662015-04-03 00:22:06 +020083/* Remove the refcount from the stream to the tracked counters, and clear the
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020084 * pointer to ensure this is only performed once. The caller is responsible for
Willy Tarreaua68f7622015-09-21 17:48:24 +020085 * ensuring that the pointer is valid first. We must be extremely careful not
86 * to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020087 */
Willy Tarreau87b09662015-04-03 00:22:06 +020088static inline void stream_store_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020089{
Willy Tarreauf059a0f2010-08-03 16:29:52 +020090 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +010091 int i;
Emeric Brun819fc6f2017-06-13 19:37:32 +020092 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +020093
Willy Tarreaub4c84932013-07-23 19:15:30 +020094 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +020095 ts = stkctr_entry(&s->stkctr[i]);
96 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +010097 continue;
Willy Tarreaua68f7622015-09-21 17:48:24 +020098
99 if (stkctr_entry(&s->sess->stkctr[i]))
100 continue;
101
Emeric Brun819fc6f2017-06-13 19:37:32 +0200102 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
103 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100104 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200105
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200106 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200107
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100108 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100109
110 /* If data was modified, we need to touch to re-schedule sync */
111 stktable_touch_local(s->stkctr[i].table, ts, 0);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200112 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100113 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200114 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau38285c12010-06-18 16:35:43 +0200115 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200116}
117
Willy Tarreau87b09662015-04-03 00:22:06 +0200118/* Remove the refcount from the stream counters tracked at the content level if
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200119 * any, and clear the pointer to ensure this is only performed once. The caller
Willy Tarreaua68f7622015-09-21 17:48:24 +0200120 * is responsible for ensuring that the pointer is valid first. We must be
121 * extremely careful not to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200122 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200123static inline void stream_stop_content_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200124{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200125 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200126 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100127 int i;
Willy Tarreaue3487932010-06-18 21:03:20 +0200128
Willy Tarreaub4c84932013-07-23 19:15:30 +0200129 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200130 ts = stkctr_entry(&s->stkctr[i]);
131 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100132 continue;
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200133
Willy Tarreaua68f7622015-09-21 17:48:24 +0200134 if (stkctr_entry(&s->sess->stkctr[i]))
135 continue;
136
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100137 if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_CONTENT))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100138 continue;
139
Emeric Brun819fc6f2017-06-13 19:37:32 +0200140 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
141 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100142 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200143
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200144 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200145
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100146 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100147
148 /* If data was modified, we need to touch to re-schedule sync */
149 stktable_touch_local(s->stkctr[i].table, ts, 0);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200150 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100151 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200152 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200153 }
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200154}
Willy Tarreaue3487932010-06-18 21:03:20 +0200155
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200156/* Increase total and concurrent connection count for stick entry <ts> of table
157 * <t>. The caller is responsible for ensuring that <t> and <ts> are valid
158 * pointers, and for calling this only once per connection.
159 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200160static inline void stream_start_counters(struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200161{
162 void *ptr;
Willy Tarreau91c43d72010-06-20 11:19:22 +0200163
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100164 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200165
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200166 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
167 if (ptr)
168 stktable_data_cast(ptr, conn_cur)++;
169
170 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
171 if (ptr)
172 stktable_data_cast(ptr, conn_cnt)++;
173
174 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
175 if (ptr)
176 update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
177 t->data_arg[STKTABLE_DT_CONN_RATE].u, 1);
178 if (tick_isset(t->expire))
179 ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
Emeric Brun819fc6f2017-06-13 19:37:32 +0200180
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100181 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100182
183 /* If data was modified, we need to touch to re-schedule sync */
184 stktable_touch_local(t, ts, 0);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200185}
186
Willy Tarreau87b09662015-04-03 00:22:06 +0200187/* Enable tracking of stream counters as <stkctr> on stksess <ts>. The caller is
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200188 * responsible for ensuring that <t> and <ts> are valid pointers. Some controls
189 * are performed to ensure the state can still change.
190 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200191static inline void stream_track_stkctr(struct stkctr *ctr, struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200192{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200193 /* Why this test ???? */
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100194 if (stkctr_entry(ctr))
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200195 return;
196
Willy Tarreau20d46a52012-12-09 15:55:40 +0100197 ctr->table = t;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100198 stkctr_set_entry(ctr, ts);
Willy Tarreau87b09662015-04-03 00:22:06 +0200199 stream_start_counters(t, ts);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200200}
201
Willy Tarreauda7ff642010-06-23 11:44:09 +0200202/* Increase the number of cumulated HTTP requests in the tracked counters */
Willy Tarreau87b09662015-04-03 00:22:06 +0200203static void inline stream_inc_http_req_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200204{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200205 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200206 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100207 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200208
Willy Tarreaub4c84932013-07-23 19:15:30 +0200209 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200210 struct stkctr *stkctr = &s->stkctr[i];
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200211
Emeric Brun819fc6f2017-06-13 19:37:32 +0200212 ts = stkctr_entry(stkctr);
213 if (!ts) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200214 stkctr = &s->sess->stkctr[i];
Emeric Brun819fc6f2017-06-13 19:37:32 +0200215 ts = stkctr_entry(stkctr);
216 if (!ts)
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200217 continue;
218 }
219
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100220 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200221
222 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200223 if (ptr)
224 stktable_data_cast(ptr, http_req_cnt)++;
225
Emeric Brun819fc6f2017-06-13 19:37:32 +0200226 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200227 if (ptr)
228 update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200229 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200230
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100231 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100232
233 /* If data was modified, we need to touch to re-schedule sync */
234 stktable_touch_local(stkctr->table, ts, 0);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200235 }
236}
237
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200238/* Increase the number of cumulated HTTP requests in the backend's tracked
239 * counters. We don't look up the session since it cannot happen in the bakcend.
240 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200241static void inline stream_inc_be_http_req_ctr(struct stream *s)
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100242{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200243 struct stksess *ts;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100244 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100245 int i;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100246
Willy Tarreaub4c84932013-07-23 19:15:30 +0200247 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200248 struct stkctr *stkctr = &s->stkctr[i];
249
Emeric Brun819fc6f2017-06-13 19:37:32 +0200250 ts = stkctr_entry(stkctr);
251 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100252 continue;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100253
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100254 if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_BACKEND))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100255 continue;
256
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100257 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200258
259 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_CNT);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100260 if (ptr)
261 stktable_data_cast(ptr, http_req_cnt)++;
262
Emeric Brun819fc6f2017-06-13 19:37:32 +0200263 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_REQ_RATE);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100264 if (ptr)
265 update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200266 stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200267
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100268 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100269
270 /* If data was modified, we need to touch to re-schedule sync */
271 stktable_touch_local(stkctr->table, ts, 0);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100272 }
273}
274
Willy Tarreauda7ff642010-06-23 11:44:09 +0200275/* Increase the number of cumulated failed HTTP requests in the tracked
276 * counters. Only 4xx requests should be counted here so that we can
277 * distinguish between errors caused by client behaviour and other ones.
278 * Note that even 404 are interesting because they're generally caused by
279 * vulnerability scans.
280 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200281static void inline stream_inc_http_err_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200282{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200283 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200284 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100285 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200286
Willy Tarreaub4c84932013-07-23 19:15:30 +0200287 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200288 struct stkctr *stkctr = &s->stkctr[i];
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200289
Emeric Brun819fc6f2017-06-13 19:37:32 +0200290 ts = stkctr_entry(stkctr);
291 if (!ts) {
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200292 stkctr = &s->sess->stkctr[i];
Emeric Brun819fc6f2017-06-13 19:37:32 +0200293 ts = stkctr_entry(stkctr);
294 if (!ts)
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200295 continue;
296 }
297
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100298 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200299
300 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_ERR_CNT);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200301 if (ptr)
302 stktable_data_cast(ptr, http_err_cnt)++;
303
Emeric Brun819fc6f2017-06-13 19:37:32 +0200304 ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_HTTP_ERR_RATE);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200305 if (ptr)
306 update_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200307 stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200308
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100309 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100310
311 /* If data was modified, we need to touch to re-schedule sync */
312 stktable_touch_local(stkctr->table, ts, 0);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200313 }
314}
315
Willy Tarreau103e5662017-11-26 18:48:14 +0100316static void inline __stream_add_srv_conn(struct stream *sess, struct server *srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900317{
318 sess->srv_conn = srv;
319 LIST_ADD(&srv->actconns, &sess->by_srv);
Willy Tarreau103e5662017-11-26 18:48:14 +0100320}
321
322static void inline stream_add_srv_conn(struct stream *sess, struct server *srv)
323{
324 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
325 __stream_add_srv_conn(sess, srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100326 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900327}
328
Willy Tarreau87b09662015-04-03 00:22:06 +0200329static void inline stream_del_srv_conn(struct stream *sess)
Simon Hormanaf514952011-06-21 14:34:57 +0900330{
Christopher Faulet29f77e82017-06-08 14:04:45 +0200331 struct server *srv = sess->srv_conn;
332
333 if (!srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900334 return;
335
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100336 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900337 sess->srv_conn = NULL;
338 LIST_DEL(&sess->by_srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100339 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900340}
341
Willy Tarreau87b09662015-04-03 00:22:06 +0200342static void inline stream_init_srv_conn(struct stream *sess)
Willy Tarreau9bd0d742011-07-20 00:17:39 +0200343{
344 sess->srv_conn = NULL;
345 LIST_INIT(&sess->by_srv);
346}
347
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200348void service_keywords_register(struct action_kw_list *kw_list);
349
Willy Tarreau87b09662015-04-03 00:22:06 +0200350#endif /* _PROTO_STREAM_H */
Willy TARREAU3dc06442006-06-15 21:48:13 +0200351
Willy Tarreaubaaee002006-06-26 02:48:02 +0200352/*
353 * Local variables:
354 * c-indent-level: 8
355 * c-basic-offset: 8
356 * End:
357 */