blob: 02772a86d75132ca9e06b334d8e7ecc342bee021 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau5b154472009-12-21 20:11:07 +01002 * include/types/session.h
3 * This file defines everything related to sessions.
4 *
Willy Tarreau4de91492010-01-22 19:10:05 +01005 * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
Willy Tarreau5b154472009-12-21 20:11:07 +01006 *
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 Tarreaubaaee002006-06-26 02:48:02 +020021
22#ifndef _TYPES_SESSION_H
23#define _TYPES_SESSION_H
24
25
26#include <sys/time.h>
27#include <unistd.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020031#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020032#include <common/mini-clist.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020033
Willy Tarreauc7e42382012-08-24 19:22:53 +020034#include <types/channel.h>
William Lallemand82fe75c2012-10-23 10:25:10 +020035#include <types/compression.h>
William Lallemand08289f12012-10-31 11:19:18 +010036
Willy Tarreau3fdb3662012-11-12 00:42:33 +010037#include <types/obj_type.h>
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010038#include <types/proto_http.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020039#include <types/proxy.h>
40#include <types/queue.h>
41#include <types/server.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020042#include <types/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020043#include <types/task.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010044#include <types/stick_table.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020045
46
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010047/* various session flags, bits values 0x01 to 0x100 (shift 0) */
Willy Tarreaubaaee002006-06-26 02:48:02 +020048#define SN_DIRECT 0x00000001 /* connection made on the server matching the client cookie */
Willy Tarreau3d300592007-03-18 18:34:41 +010049#define SN_ASSIGNED 0x00000002 /* no need to assign a server to this session */
50#define SN_ADDR_SET 0x00000004 /* this session's server address has been set */
51#define SN_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */
Willy Tarreau5b154472009-12-21 20:11:07 +010052
Willy Tarreau4de91492010-01-22 19:10:05 +010053#define SN_FORCE_PRST 0x00000010 /* force persistence here, even if server is down */
Willy Tarreau3d300592007-03-18 18:34:41 +010054#define SN_MONITOR 0x00000020 /* this session comes from a monitoring system */
Willy Tarreau1e62de62008-11-11 20:20:02 +010055#define SN_CURR_SESS 0x00000040 /* a connection is currently being counted on the server */
Willy Tarreau2542b532012-08-31 16:01:23 +020056#define SN_INITIALIZED 0x00000080 /* the session was fully initialized */
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010057#define SN_REDISP 0x00000100 /* set if this session was redispatched from one server to another */
Willy Tarreau541b5c22008-01-06 23:34:21 +010058#define SN_CONN_TAR 0x00000200 /* set if this session is turning around before reconnecting */
Willy Tarreau21d2af32008-02-14 20:25:24 +010059#define SN_REDIRECTABLE 0x00000400 /* set if this session is redirectable (GET or HEAD) */
Willy Tarreaud0f06fc2009-11-30 12:19:56 +010060#define SN_TUNNEL 0x00000800 /* tunnel-mode session, nothing to catch after data */
Willy Tarreaubaaee002006-06-26 02:48:02 +020061
Willy Tarreaua2a64e92011-09-07 23:01:56 +020062/* session termination conditions, bits values 0x1000 to 0x7000 (0-9 shift 12) */
Willy Tarreau570f2212013-06-10 16:42:09 +020063#define SN_ERR_NONE 0x00000000 /* normal end of request */
64#define SN_ERR_LOCAL 0x00001000 /* the proxy locally processed this request => not an error */
65#define SN_ERR_CLITO 0x00002000 /* client time-out */
66#define SN_ERR_CLICL 0x00003000 /* client closed (read/write error) */
67#define SN_ERR_SRVTO 0x00004000 /* server time-out, connect time-out */
68#define SN_ERR_SRVCL 0x00005000 /* server closed (connect/read/write error) */
69#define SN_ERR_PRXCOND 0x00006000 /* the proxy decided to close (deny...) */
70#define SN_ERR_RESOURCE 0x00007000 /* the proxy encountered a lack of a local resources (fd, mem, ...) */
71#define SN_ERR_INTERNAL 0x00008000 /* the proxy encountered an internal error */
72#define SN_ERR_DOWN 0x00009000 /* the proxy killed a session because the backend became unavailable */
73#define SN_ERR_KILLED 0x0000a000 /* the proxy killed a session because it was asked to do so */
74#define SN_ERR_UP 0x0000b000 /* the proxy killed a session because a preferred backend became available */
75#define SN_ERR_MASK 0x0000f000 /* mask to get only session error flags */
76#define SN_ERR_SHIFT 12 /* bit shift */
Willy Tarreaubaaee002006-06-26 02:48:02 +020077
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010078/* session state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */
79#define SN_FINST_R 0x00010000 /* session ended during client request */
80#define SN_FINST_C 0x00020000 /* session ended during server connect */
81#define SN_FINST_H 0x00030000 /* session ended during server headers */
82#define SN_FINST_D 0x00040000 /* session ended during data phase */
83#define SN_FINST_L 0x00050000 /* session ended while pushing last data to client */
84#define SN_FINST_Q 0x00060000 /* session ended while waiting in queue for a server slot */
85#define SN_FINST_T 0x00070000 /* session ended tarpitted */
86#define SN_FINST_MASK 0x00070000 /* mask to get only final session state flags */
87#define SN_FINST_SHIFT 16 /* bit shift */
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010088
Simon Horman752dc4a2011-06-21 14:34:59 +090089#define SN_IGNORE_PRST 0x00080000 /* ignore persistence */
Willy Tarreaud5ca9ab2013-05-28 17:40:25 +020090
91#define SN_COMP_READY 0x00100000 /* the compression is initialized */
Willy Tarreau36346242014-02-24 18:26:30 +010092#define SN_SRV_REUSED 0x00200000 /* the server-side connection was reused */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +020093
Godbach430f2912013-06-20 13:28:38 +080094/* WARNING: if new fields are added, they must be initialized in session_accept()
Willy Tarreau0a4838c2010-08-06 20:11:05 +020095 * and freed in session_free() !
96 */
97
Willy Tarreaucc08d2c2014-01-28 23:18:23 +010098#define STKCTR_TRACK_BACKEND 1
99#define STKCTR_TRACK_CONTENT 2
100/* stick counter. The <entry> member is a composite address (caddr) made of a
101 * pointer to an stksess struct, and two flags among STKCTR_TRACK_* above.
102 */
Willy Tarreau20d46a52012-12-09 15:55:40 +0100103struct stkctr {
Willy Tarreaucc08d2c2014-01-28 23:18:23 +0100104 unsigned long entry; /* entry containing counters currently being tracked by this session */
Willy Tarreau20d46a52012-12-09 15:55:40 +0100105 struct stktable *table; /* table the counters above belong to (undefined if counters are null) */
106};
107
Willy Tarreau7c669d72008-06-20 15:04:11 +0200108/*
109 * Note: some session flags have dependencies :
110 * - SN_DIRECT cannot exist without SN_ASSIGNED, because a server is
111 * immediately assigned when SN_DIRECT is determined. Both must be cleared
112 * when clearing SN_DIRECT (eg: redispatch).
113 * - ->srv has no meaning without SN_ASSIGNED and must not be checked without
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100114 * it. ->target may be used to check previous ->srv after a failed connection attempt.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200115 * - a session being processed has srv_conn set.
116 * - srv_conn might remain after SN_DIRECT has been reset, but the assigned
117 * server should eventually be released.
118 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200119struct session {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200120 int flags; /* some flags describing the session */
Willy Tarreau2518db42013-12-06 22:01:11 +0100121 unsigned int uniq_id; /* unique ID used for the traces */
Willy Tarreauf8a49ea2013-10-14 21:32:07 +0200122 enum obj_type *target; /* target to use for this session ; for mini-sess: incoming connection */
Willy Tarreau109e95a2012-10-13 11:22:24 +0200123
Willy Tarreau7421efb2012-07-02 15:11:27 +0200124 struct channel *req; /* request buffer */
125 struct channel *rep; /* response buffer */
Willy Tarreau109e95a2012-10-13 11:22:24 +0200126
127 struct proxy *fe; /* the proxy this session depends on for the client side */
128 struct proxy *be; /* the proxy this session depends on for the server side */
129
130 struct listener *listener; /* the listener by which the request arrived */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200131 struct server *srv_conn; /* session already has a slot on a server and is not in queue */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200132 struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
Willy Tarreau109e95a2012-10-13 11:22:24 +0200133
Willy Tarreaub326fcc2007-03-03 13:54:32 +0100134 struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100135
Willy Tarreau109e95a2012-10-13 11:22:24 +0200136 struct task *task; /* the task associated with this session */
137 struct list list; /* position in global sessions list */
138 struct list by_srv; /* position in server session list */
139 struct list back_refs; /* list of users tracking this session */
140
Emeric Brunb982a3d2010-01-04 15:45:53 +0100141 struct {
142 struct stksess *ts;
143 struct stktable *table;
Emeric Brunb982a3d2010-01-04 15:45:53 +0100144 } store[8]; /* tracked stickiness values to store */
145 int store_count;
Willy Tarreau2518db42013-12-06 22:01:11 +0100146 /* 4 unused bytes here */
Willy Tarreau56123282010-08-06 19:06:56 +0200147
Willy Tarreaub4c84932013-07-23 19:15:30 +0200148 struct stkctr stkctr[MAX_SESS_STKCTR]; /* stick counters */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100149
Willy Tarreau109e95a2012-10-13 11:22:24 +0200150 struct stream_interface si[2]; /* client and server stream interfaces */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200151 struct {
152 int logwait; /* log fields waiting to be collected : LW_* */
Willy Tarreauabcd5142013-06-11 17:18:02 +0200153 int level; /* log level to force + 1 if > 0, -1 = no log */
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200154 struct timeval accept_date; /* date of the accept() in user date */
155 struct timeval tv_accept; /* date of the accept() in internal date (monotonic) */
Willy Tarreau70089872008-06-13 21:12:51 +0200156 struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200157 long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */
158 long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */
159 long t_data; /* delay before the first data byte from the server ... */
Willy Tarreau3bac9ff2007-03-18 17:31:28 +0100160 unsigned long t_close; /* total session duration */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200161 unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */
162 unsigned long prx_queue_size; /* overall number of sessions waiting for a connect slot on this instance at accept() time */
Willy Tarreau35d66b02007-01-02 00:28:21 +0100163 long long bytes_in; /* number of bytes transferred from the client to the server */
164 long long bytes_out; /* number of bytes transferred from the server to the client */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200165 } logs;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100166 void (*do_log)(struct session *s); /* the function to call in order to log (or NULL) */
167 void (*srv_error)(struct session *s, /* the function to call upon unrecoverable server errors (or NULL) */
168 struct stream_interface *si);
William Lallemand8b52bb32012-11-16 18:06:41 +0100169 struct comp_ctx *comp_ctx; /* HTTP compression context */
William Lallemand82fe75c2012-10-23 10:25:10 +0200170 struct comp_algo *comp_algo; /* HTTP compression algorithm if not NULL */
William Lallemanda73203e2012-03-12 12:48:57 +0100171 char *unique_id; /* custom unique ID */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200172};
173
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200174/* parameters to configure tracked counters */
175struct track_ctr_prm {
Willy Tarreau5d5b5d82012-12-09 12:00:04 +0100176 struct sample_expr *expr; /* expression used as the key */
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200177 union {
178 struct stktable *t; /* a pointer to the table */
179 char *n; /* or its name during parsing. */
180 } table;
181};
182
Willy Tarreaubaaee002006-06-26 02:48:02 +0200183
Willy Tarreaubaaee002006-06-26 02:48:02 +0200184#endif /* _TYPES_SESSION_H */
185
186/*
187 * Local variables:
188 * c-indent-level: 8
189 * c-basic-offset: 8
190 * End:
191 */