2006-06-15 19:48:13 +00:00
|
|
|
/*
|
2010-06-01 15:45:26 +00:00
|
|
|
* include/proto/session.h
|
|
|
|
* This file defines everything related to sessions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
* exclusively.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-06-15 19:48:13 +00:00
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
#ifndef _PROTO_SESSION_H
|
|
|
|
#define _PROTO_SESSION_H
|
|
|
|
|
2006-06-29 16:54:54 +00:00
|
|
|
#include <common/config.h>
|
2007-05-13 17:43:47 +00:00
|
|
|
#include <common/memory.h>
|
2006-06-26 00:48:02 +00:00
|
|
|
#include <types/session.h>
|
2010-06-20 09:19:22 +00:00
|
|
|
#include <proto/freq_ctr.h>
|
2010-06-14 19:04:55 +00:00
|
|
|
#include <proto/stick_table.h>
|
2006-06-15 19:48:13 +00:00
|
|
|
|
2007-05-13 17:43:47 +00:00
|
|
|
extern struct pool_head *pool2_session;
|
2008-11-23 18:53:55 +00:00
|
|
|
extern struct list sessions;
|
2007-05-13 17:43:47 +00:00
|
|
|
|
2010-06-01 15:45:26 +00:00
|
|
|
int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr);
|
2006-06-26 00:48:02 +00:00
|
|
|
void session_free(struct session *s);
|
2006-06-15 19:48:13 +00:00
|
|
|
|
2007-05-13 17:43:47 +00:00
|
|
|
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
|
|
|
|
int init_session();
|
2006-06-26 00:48:02 +00:00
|
|
|
|
2007-11-24 21:12:47 +00:00
|
|
|
void session_process_counters(struct session *s);
|
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 13:04:11 +00:00
|
|
|
void sess_change_server(struct session *sess, struct server *newsrv);
|
2009-03-08 08:38:41 +00:00
|
|
|
struct task *process_session(struct task *t);
|
2009-03-15 21:34:05 +00:00
|
|
|
void sess_set_term_flags(struct session *s);
|
|
|
|
void default_srv_error(struct session *s, struct stream_interface *si);
|
2010-06-14 19:04:55 +00:00
|
|
|
int parse_track_counters(char **args, int *arg,
|
|
|
|
int section_type, struct proxy *curpx,
|
|
|
|
struct track_ctr_prm *prm,
|
|
|
|
struct proxy *defpx, char *err, int errlen);
|
|
|
|
|
|
|
|
/* Remove the refcount from the session to the tracked counters, and clear the
|
|
|
|
* pointer to ensure this is only performed once. The caller is responsible for
|
|
|
|
* ensuring that the pointer is valid first.
|
|
|
|
*/
|
|
|
|
static inline void session_store_counters(struct session *s)
|
|
|
|
{
|
2010-06-18 14:35:43 +00:00
|
|
|
if (s->tracked_counters) {
|
|
|
|
void *ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_CONN_CUR);
|
|
|
|
if (ptr)
|
|
|
|
stktable_data_cast(ptr, conn_cur)--;
|
|
|
|
}
|
2010-06-14 19:04:55 +00:00
|
|
|
s->tracked_counters->ref_cnt--;
|
|
|
|
s->tracked_counters = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable tracking of session counters on stksess <ts>. The caller is
|
|
|
|
* responsible for ensuring that <t> and <ts> are valid pointers and that no
|
|
|
|
* previous tracked_counters was assigned to the session.
|
|
|
|
*/
|
|
|
|
static inline void session_track_counters(struct session *s, struct stktable *t, struct stksess *ts)
|
|
|
|
{
|
|
|
|
ts->ref_cnt++;
|
|
|
|
s->tracked_table = t;
|
|
|
|
s->tracked_counters = ts;
|
2010-06-18 14:35:43 +00:00
|
|
|
if (ts) {
|
2010-06-18 19:03:20 +00:00
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
|
2010-06-18 14:35:43 +00:00
|
|
|
if (ptr)
|
|
|
|
stktable_data_cast(ptr, conn_cur)++;
|
2010-06-18 19:03:20 +00:00
|
|
|
|
|
|
|
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
|
|
|
|
if (ptr)
|
|
|
|
stktable_data_cast(ptr, conn_cnt)++;
|
|
|
|
|
2010-06-20 09:19:22 +00:00
|
|
|
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
|
|
|
|
if (ptr)
|
|
|
|
update_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
|
|
|
|
t->data_arg[STKTABLE_DT_CONN_RATE].u, 1);
|
|
|
|
|
2010-06-18 14:35:43 +00:00
|
|
|
if (tick_isset(t->expire))
|
|
|
|
ts->expire = tick_add(now_ms, MS_TO_TICKS(t->expire));
|
|
|
|
}
|
2010-06-14 19:04:55 +00:00
|
|
|
}
|
2007-11-24 21:12:47 +00:00
|
|
|
|
2008-08-16 12:55:08 +00:00
|
|
|
static void inline trace_term(struct session *s, unsigned int code)
|
|
|
|
{
|
|
|
|
s->term_trace <<= TT_BIT_SHIFT;
|
|
|
|
s->term_trace |= code;
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:44:09 +00:00
|
|
|
/* Increase the number of cumulated HTTP requests in the tracked counters */
|
|
|
|
static void inline session_inc_http_req_ctr(struct session *s)
|
|
|
|
{
|
|
|
|
if (s->tracked_counters) {
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_HTTP_REQ_CNT);
|
|
|
|
if (ptr)
|
|
|
|
stktable_data_cast(ptr, http_req_cnt)++;
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_HTTP_REQ_RATE);
|
|
|
|
if (ptr)
|
|
|
|
update_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
|
|
|
|
s->tracked_table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increase the number of cumulated failed HTTP requests in the tracked
|
|
|
|
* counters. Only 4xx requests should be counted here so that we can
|
|
|
|
* distinguish between errors caused by client behaviour and other ones.
|
|
|
|
* Note that even 404 are interesting because they're generally caused by
|
|
|
|
* vulnerability scans.
|
|
|
|
*/
|
|
|
|
static void inline session_inc_http_err_ctr(struct session *s)
|
|
|
|
{
|
|
|
|
if (s->tracked_counters) {
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_HTTP_ERR_CNT);
|
|
|
|
if (ptr)
|
|
|
|
stktable_data_cast(ptr, http_err_cnt)++;
|
|
|
|
|
|
|
|
ptr = stktable_data_ptr(s->tracked_table, s->tracked_counters, STKTABLE_DT_HTTP_ERR_RATE);
|
|
|
|
if (ptr)
|
|
|
|
update_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
|
|
|
|
s->tracked_table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-26 00:48:02 +00:00
|
|
|
#endif /* _PROTO_SESSION_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-indent-level: 8
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|