blob: edd7cbfbe919e67b4473ab25746a756a873255fa [file] [log] [blame]
Willy TARREAU3dc06442006-06-15 21:48:13 +02001/*
Willy Tarreaudfd3de82020-06-04 23:46:14 +02002 * include/haproxy/stream.h
Willy Tarreau87b09662015-04-03 00:22:06 +02003 * This file defines everything related to streams.
Willy Tarreau81f9aa32010-06-01 17:45:26 +02004 *
Willy Tarreaudfd3de82020-06-04 23:46:14 +02005 * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
Willy Tarreau81f9aa32010-06-01 17:45:26 +02006 *
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 Tarreaudfd3de82020-06-04 23:46:14 +020022#ifndef _HAPROXY_STREAM_H
23#define _HAPROXY_STREAM_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreau122eba92020-06-04 10:15:32 +020025#include <haproxy/action-t.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020026#include <haproxy/api.h>
Willy Tarreau0f6ffd62020-06-03 19:33:00 +020027#include <haproxy/fd.h>
Willy Tarreau66347942020-06-01 12:18:08 +020028#include <haproxy/freq_ctr.h>
Willy Tarreau8efbdfb2020-06-04 11:29:21 +020029#include <haproxy/obj_type.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020030#include <haproxy/pool-t.h>
Willy Tarreaua55c4542020-06-04 22:59:39 +020031#include <haproxy/queue.h>
Willy Tarreau872f2ea2020-06-04 18:46:44 +020032#include <haproxy/stick_table.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020033#include <haproxy/stream-t.h>
34#include <haproxy/task-t.h>
35#include <haproxy/trace-t.h>
Christopher Fauleteea8fc72019-11-05 16:18:10 +010036
37extern struct trace_source trace_strm;
38
39/* Details about these events are defined in <src/stream.c> */
40#define STRM_EV_STRM_NEW (1ULL << 0)
41#define STRM_EV_STRM_FREE (1ULL << 1)
42#define STRM_EV_STRM_ERR (1ULL << 2)
43#define STRM_EV_STRM_ANA (1ULL << 3)
44#define STRM_EV_STRM_PROC (1ULL << 4)
45#define STRM_EV_SI_ST (1ULL << 5)
46#define STRM_EV_HTTP_ANA (1ULL << 6)
47#define STRM_EV_HTTP_ERR (1ULL << 7)
48#define STRM_EV_TCP_ANA (1ULL << 8)
49#define STRM_EV_TCP_ERR (1ULL << 9)
50#define STRM_EV_FLT_ANA (1ULL << 10)
51#define STRM_EV_FLT_ERR (1ULL << 11)
Willy TARREAU3dc06442006-06-15 21:48:13 +020052
Christopher Fauletc8b246f2019-05-14 22:05:28 +020053#define IS_HTX_STRM(strm) ((strm)->flags & SF_HTX)
54
Willy Tarreaubafbe012017-11-24 17:34:44 +010055extern struct pool_head *pool_head_stream;
Tim Duesterhus127a74d2020-02-28 15:13:33 +010056extern struct pool_head *pool_head_uniqueid;
Willy Tarreau87b09662015-04-03 00:22:06 +020057extern struct list streams;
Willy Tarreauc6ca1a02007-05-13 19:43:47 +020058
Willy Tarreaubc174aa2012-11-19 16:10:32 +010059extern struct data_cb sess_conn_cb;
60
Christopher Faulet26256f82020-09-14 11:40:13 +020061struct stream *stream_new(struct session *sess, enum obj_type *origin, struct buffer *input);
62int stream_create_from_cs(struct conn_stream *cs, struct buffer *input);
Christopher Faulet4ef84c92021-01-21 17:36:12 +010063int stream_upgrade_from_cs(struct conn_stream *cs, struct buffer *input);
Willy Tarreaubaaee002006-06-26 02:48:02 +020064
Willy Tarreaue7dff022015-04-03 01:14:29 +020065/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +020066void stream_shutdown(struct stream *stream, int why);
Willy Tarreau5484d582019-05-22 09:33:03 +020067void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, char eol);
Willy Tarreau71c07ac2019-04-25 19:08:48 +020068void stream_dump_and_crash(enum obj_type *obj, int rate);
Simon Hormandec5be42011-06-08 09:19:07 +090069
Tim Duesterhusa17e6622020-03-05 20:19:02 +010070struct ist stream_generate_unique_id(struct stream *strm, struct list *format);
Tim Duesterhus127a74d2020-02-28 15:13:33 +010071
Willy Tarreau87b09662015-04-03 00:22:06 +020072void stream_process_counters(struct stream *s);
73void sess_change_server(struct stream *sess, struct server *newsrv);
Olivier Houchard9f6af332018-05-25 14:04:04 +020074struct task *process_stream(struct task *t, void *context, unsigned short state);
Willy Tarreau87b09662015-04-03 00:22:06 +020075void default_srv_error(struct stream *s, struct stream_interface *si);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020076int parse_track_counters(char **args, int *arg,
77 int section_type, struct proxy *curpx,
78 struct track_ctr_prm *prm,
Willy Tarreau0a3dd742012-05-08 19:47:01 +020079 struct proxy *defpx, char **err);
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +020080
Willy Tarreau87b09662015-04-03 00:22:06 +020081/* Update the stream's backend and server time stats */
82void stream_update_time_stats(struct stream *s);
Willy Tarreau87b09662015-04-03 00:22:06 +020083void stream_release_buffers(struct stream *s);
Willy Tarreaub882dd82018-11-06 15:50:21 +010084int stream_buf_available(void *arg);
Willy Tarreau4bfc5802014-06-17 12:19:18 +020085
Willy Tarreaub1ec8c42015-04-03 13:53:24 +020086/* returns the session this stream belongs to */
87static inline struct session *strm_sess(const struct stream *strm)
88{
89 return strm->sess;
90}
91
Willy Tarreaud0d8da92015-04-04 02:10:38 +020092/* returns the frontend this stream was initiated from */
93static inline struct proxy *strm_fe(const struct stream *strm)
94{
95 return strm->sess->fe;
96}
97
98/* returns the listener this stream was initiated from */
99static inline struct listener *strm_li(const struct stream *strm)
100{
101 return strm->sess->listener;
102}
103
104/* returns a pointer to the origin of the session which created this stream */
105static inline enum obj_type *strm_orig(const struct stream *strm)
106{
107 return strm->sess->origin;
108}
109
Willy Tarreau87b09662015-04-03 00:22:06 +0200110/* Remove the refcount from the stream to the tracked counters, and clear the
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200111 * pointer to ensure this is only performed once. The caller is responsible for
Willy Tarreaua68f7622015-09-21 17:48:24 +0200112 * ensuring that the pointer is valid first. We must be extremely careful not
113 * to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200114 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200115static inline void stream_store_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200116{
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200117 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100118 int i;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200119 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200120
Willy Tarreaub4c84932013-07-23 19:15:30 +0200121 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200122 ts = stkctr_entry(&s->stkctr[i]);
123 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100124 continue;
Willy Tarreaua68f7622015-09-21 17:48:24 +0200125
126 if (stkctr_entry(&s->sess->stkctr[i]))
127 continue;
128
Emeric Brun819fc6f2017-06-13 19:37:32 +0200129 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
130 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100131 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200132
Tim Duesterhus8b87c012019-01-04 00:11:59 +0100133 if (stktable_data_cast(ptr, conn_cur) > 0)
134 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200135
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100136 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100137
138 /* If data was modified, we need to touch to re-schedule sync */
139 stktable_touch_local(s->stkctr[i].table, ts, 0);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200140 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100141 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200142 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau38285c12010-06-18 16:35:43 +0200143 }
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200144}
145
Willy Tarreau87b09662015-04-03 00:22:06 +0200146/* Remove the refcount from the stream counters tracked at the content level if
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200147 * any, and clear the pointer to ensure this is only performed once. The caller
Willy Tarreaua68f7622015-09-21 17:48:24 +0200148 * is responsible for ensuring that the pointer is valid first. We must be
149 * extremely careful not to touch the entries we inherited from the session.
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200150 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200151static inline void stream_stop_content_counters(struct stream *s)
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200152{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200153 struct stksess *ts;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200154 void *ptr;
Willy Tarreau20d46a52012-12-09 15:55:40 +0100155 int i;
Willy Tarreaue3487932010-06-18 21:03:20 +0200156
Willy Tarreaub4c84932013-07-23 19:15:30 +0200157 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Emeric Brun819fc6f2017-06-13 19:37:32 +0200158 ts = stkctr_entry(&s->stkctr[i]);
159 if (!ts)
Willy Tarreau20d46a52012-12-09 15:55:40 +0100160 continue;
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200161
Willy Tarreaua68f7622015-09-21 17:48:24 +0200162 if (stkctr_entry(&s->sess->stkctr[i]))
163 continue;
164
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100165 if (!(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_CONTENT))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100166 continue;
167
Emeric Brun819fc6f2017-06-13 19:37:32 +0200168 ptr = stktable_data_ptr(s->stkctr[i].table, ts, STKTABLE_DT_CONN_CUR);
169 if (ptr) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100170 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200171
Tim Duesterhus8b87c012019-01-04 00:11:59 +0100172 if (stktable_data_cast(ptr, conn_cur) > 0)
173 stktable_data_cast(ptr, conn_cur)--;
Emeric Brun819fc6f2017-06-13 19:37:32 +0200174
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100175 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100176
177 /* If data was modified, we need to touch to re-schedule sync */
178 stktable_touch_local(s->stkctr[i].table, ts, 0);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200179 }
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100180 stkctr_set_entry(&s->stkctr[i], NULL);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200181 stksess_kill_if_expired(s->stkctr[i].table, ts, 1);
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200182 }
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200183}
Willy Tarreaue3487932010-06-18 21:03:20 +0200184
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200185/* Increase total and concurrent connection count for stick entry <ts> of table
186 * <t>. The caller is responsible for ensuring that <t> and <ts> are valid
187 * pointers, and for calling this only once per connection.
188 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200189static inline void stream_start_counters(struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200190{
191 void *ptr;
Willy Tarreau91c43d72010-06-20 11:19:22 +0200192
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100193 HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun819fc6f2017-06-13 19:37:32 +0200194
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200195 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
196 if (ptr)
197 stktable_data_cast(ptr, conn_cur)++;
198
199 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
200 if (ptr)
201 stktable_data_cast(ptr, conn_cnt)++;
202
203 ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
204 if (ptr)
205 update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
206 t->data_arg[STKTABLE_DT_CONN_RATE].u, 1);
207 if (tick_isset(t->expire))
208 ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
Emeric Brun819fc6f2017-06-13 19:37:32 +0200209
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100210 HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
Emeric Brun0fed0b02017-11-29 16:15:07 +0100211
212 /* If data was modified, we need to touch to re-schedule sync */
213 stktable_touch_local(t, ts, 0);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200214}
215
Willy Tarreau87b09662015-04-03 00:22:06 +0200216/* Enable tracking of stream counters as <stkctr> on stksess <ts>. The caller is
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200217 * responsible for ensuring that <t> and <ts> are valid pointers. Some controls
218 * are performed to ensure the state can still change.
219 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200220static inline void stream_track_stkctr(struct stkctr *ctr, struct stktable *t, struct stksess *ts)
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200221{
Emeric Brun819fc6f2017-06-13 19:37:32 +0200222 /* Why this test ???? */
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100223 if (stkctr_entry(ctr))
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200224 return;
225
Willy Tarreau20d46a52012-12-09 15:55:40 +0100226 ctr->table = t;
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100227 stkctr_set_entry(ctr, ts);
Willy Tarreau87b09662015-04-03 00:22:06 +0200228 stream_start_counters(t, ts);
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200229}
230
Willy Tarreauda7ff642010-06-23 11:44:09 +0200231/* Increase the number of cumulated HTTP requests in the tracked counters */
Willy Tarreau0e492e22019-04-15 21:25:03 +0200232static inline void stream_inc_http_req_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200233{
Willy Tarreau20d46a52012-12-09 15:55:40 +0100234 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200235
Willy Tarreaub4c84932013-07-23 19:15:30 +0200236 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Christopher Faulet84600632020-10-06 13:52:40 +0200237 if (!stkctr_inc_http_req_ctr(&s->stkctr[i]))
238 stkctr_inc_http_req_ctr(&s->sess->stkctr[i]);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200239 }
240}
241
Willy Tarreau8b7f8682015-04-04 16:29:12 +0200242/* Increase the number of cumulated HTTP requests in the backend's tracked
243 * counters. We don't look up the session since it cannot happen in the bakcend.
244 */
Willy Tarreau0e492e22019-04-15 21:25:03 +0200245static inline void stream_inc_be_http_req_ctr(struct stream *s)
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100246{
Willy Tarreau20d46a52012-12-09 15:55:40 +0100247 int i;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100248
Willy Tarreaub4c84932013-07-23 19:15:30 +0200249 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Christopher Faulet84600632020-10-06 13:52:40 +0200250 if (!stkctr_entry(&s->stkctr[i]) || !(stkctr_flags(&s->stkctr[i]) & STKCTR_TRACK_BACKEND))
Willy Tarreau20d46a52012-12-09 15:55:40 +0100251 continue;
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100252
Christopher Faulet84600632020-10-06 13:52:40 +0200253 stkctr_inc_http_req_ctr(&s->stkctr[i]);
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100254 }
255}
256
Willy Tarreauda7ff642010-06-23 11:44:09 +0200257/* Increase the number of cumulated failed HTTP requests in the tracked
258 * counters. Only 4xx requests should be counted here so that we can
259 * distinguish between errors caused by client behaviour and other ones.
260 * Note that even 404 are interesting because they're generally caused by
261 * vulnerability scans.
262 */
Willy Tarreau0e492e22019-04-15 21:25:03 +0200263static inline void stream_inc_http_err_ctr(struct stream *s)
Willy Tarreauda7ff642010-06-23 11:44:09 +0200264{
Willy Tarreau20d46a52012-12-09 15:55:40 +0100265 int i;
Willy Tarreauf059a0f2010-08-03 16:29:52 +0200266
Willy Tarreaub4c84932013-07-23 19:15:30 +0200267 for (i = 0; i < MAX_SESS_STKCTR; i++) {
Christopher Faulet84600632020-10-06 13:52:40 +0200268 if (!stkctr_inc_http_err_ctr(&s->stkctr[i]))
269 stkctr_inc_http_err_ctr(&s->sess->stkctr[i]);
Willy Tarreauda7ff642010-06-23 11:44:09 +0200270 }
271}
272
Willy Tarreau0e492e22019-04-15 21:25:03 +0200273static inline void __stream_add_srv_conn(struct stream *sess, struct server *srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900274{
275 sess->srv_conn = srv;
276 LIST_ADD(&srv->actconns, &sess->by_srv);
Willy Tarreau103e5662017-11-26 18:48:14 +0100277}
278
Willy Tarreau0e492e22019-04-15 21:25:03 +0200279static inline void stream_add_srv_conn(struct stream *sess, struct server *srv)
Willy Tarreau103e5662017-11-26 18:48:14 +0100280{
281 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
282 __stream_add_srv_conn(sess, srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100283 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900284}
285
Willy Tarreau0e492e22019-04-15 21:25:03 +0200286static inline void stream_del_srv_conn(struct stream *sess)
Simon Hormanaf514952011-06-21 14:34:57 +0900287{
Christopher Faulet29f77e82017-06-08 14:04:45 +0200288 struct server *srv = sess->srv_conn;
289
290 if (!srv)
Simon Hormanaf514952011-06-21 14:34:57 +0900291 return;
292
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100293 HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900294 sess->srv_conn = NULL;
295 LIST_DEL(&sess->by_srv);
Christopher Faulet2a944ee2017-11-07 10:42:54 +0100296 HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
Simon Hormanaf514952011-06-21 14:34:57 +0900297}
298
Willy Tarreau0e492e22019-04-15 21:25:03 +0200299static inline void stream_init_srv_conn(struct stream *sess)
Willy Tarreau9bd0d742011-07-20 00:17:39 +0200300{
301 sess->srv_conn = NULL;
302 LIST_INIT(&sess->by_srv);
303}
304
Olivier Houchard4bd58672019-07-12 16:16:59 +0200305static inline void stream_choose_redispatch(struct stream *s)
306{
307 struct stream_interface *si = &s->si[1];
308
309 /* If the "redispatch" option is set on the backend, we are allowed to
310 * retry on another server. By default this redispatch occurs on the
311 * last retry, but if configured we allow redispatches to occur on
312 * configurable intervals, e.g. on every retry. In order to achieve this,
313 * we must mark the stream unassigned, and eventually clear the DIRECT
314 * bit to ignore any persistence cookie. We won't count a retry nor a
315 * redispatch yet, because this will depend on what server is selected.
316 * If the connection is not persistent, the balancing algorithm is not
317 * determinist (round robin) and there is more than one active server,
318 * we accept to perform an immediate redispatch without waiting since
319 * we don't care about this particular server.
320 */
321 if (objt_server(s->target) &&
322 (s->be->options & PR_O_REDISP) && !(s->flags & SF_FORCE_PRST) &&
323 ((__objt_server(s->target)->cur_state < SRV_ST_RUNNING) ||
324 (((s->be->redispatch_after > 0) &&
325 ((s->be->conn_retries - si->conn_retries) %
326 s->be->redispatch_after == 0)) ||
327 ((s->be->redispatch_after < 0) &&
328 ((s->be->conn_retries - si->conn_retries) %
329 (s->be->conn_retries + 1 + s->be->redispatch_after) == 0))) ||
330 (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 &&
331 ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR)))) {
332 sess_change_server(s, NULL);
333 if (may_dequeue_tasks(objt_server(s->target), s->be))
334 process_srv_queue(objt_server(s->target));
335
336 s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
337 si->state = SI_ST_REQ;
338 } else {
339 if (objt_server(s->target))
340 _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.retries, 1);
341 _HA_ATOMIC_ADD(&s->be->be_counters.retries, 1);
342 si->state = SI_ST_ASS;
343 }
344
345}
346
Amaury Denoyelleb7150782020-12-10 13:43:51 +0100347int stream_set_timeout(struct stream *s, enum act_timeout_name name, int timeout);
348
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200349void service_keywords_register(struct action_kw_list *kw_list);
Thierry Fournier87e53992020-11-28 19:32:14 +0100350struct action_kw *service_find(const char *kw);
Willy Tarreau679bba12019-03-19 08:08:10 +0100351void list_services(FILE *out);
Thierry FOURNIER5a363e72015-09-27 19:29:33 +0200352
Willy Tarreaudfd3de82020-06-04 23:46:14 +0200353#endif /* _HAPROXY_STREAM_H */
Willy TARREAU3dc06442006-06-15 21:48:13 +0200354
Willy Tarreaubaaee002006-06-26 02:48:02 +0200355/*
356 * Local variables:
357 * c-indent-level: 8
358 * c-basic-offset: 8
359 * End:
360 */