blob: 819acfd74aa5ed039e63b9f5f5459ea397b543ec [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/session.h
3 This file defines everything related to sessions.
4
Willy Tarreauc6ca1a02007-05-13 19:43:47 +02005 Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +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*/
21
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
34#include <types/buffers.h>
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010035#include <types/proto_http.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020036#include <types/proxy.h>
37#include <types/queue.h>
38#include <types/server.h>
39#include <types/task.h>
40
41
42/* various session flags, bits values 0x01 to 0x20 (shift 0) */
43#define SN_DIRECT 0x00000001 /* connection made on the server matching the client cookie */
Willy Tarreau3d300592007-03-18 18:34:41 +010044#define SN_ASSIGNED 0x00000002 /* no need to assign a server to this session */
45#define SN_ADDR_SET 0x00000004 /* this session's server address has been set */
46#define SN_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */
47#define SN_CONN_CLOSED 0x00000010 /* "Connection: close" was present or added */
48#define SN_MONITOR 0x00000020 /* this session comes from a monitoring system */
49#define SN_SELF_GEN 0x00000040 /* the proxy generates data for the client (eg: stats) */
Willy Tarreau14c8aac2007-05-08 19:46:30 +020050#define SN_FRT_ADDR_SET 0x00000080 /* set if the frontend address has been filled */
Willy Tarreaubaaee002006-06-26 02:48:02 +020051
52/* session termination conditions, bits values 0x100 to 0x700 (0-7 shift 8) */
53#define SN_ERR_NONE 0x00000000
54#define SN_ERR_CLITO 0x00000100 /* client time-out */
55#define SN_ERR_CLICL 0x00000200 /* client closed (read/write error) */
56#define SN_ERR_SRVTO 0x00000300 /* server time-out, connect time-out */
57#define SN_ERR_SRVCL 0x00000400 /* server closed (connect/read/write error) */
58#define SN_ERR_PRXCOND 0x00000500 /* the proxy decided to close (deny...) */
59#define SN_ERR_RESOURCE 0x00000600 /* the proxy encountered a lack of a local resources (fd, mem, ...) */
60#define SN_ERR_INTERNAL 0x00000700 /* the proxy encountered an internal error */
61#define SN_ERR_MASK 0x00000700 /* mask to get only session error flags */
62#define SN_ERR_SHIFT 8 /* bit shift */
Willy Tarreau3d300592007-03-18 18:34:41 +010063/* unused: 0x00000800 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020064
65/* session state at termination, bits values 0x1000 to 0x7000 (0-7 shift 12) */
66#define SN_FINST_R 0x00001000 /* session ended during client request */
67#define SN_FINST_C 0x00002000 /* session ended during server connect */
68#define SN_FINST_H 0x00003000 /* session ended during server headers */
69#define SN_FINST_D 0x00004000 /* session ended during data phase */
70#define SN_FINST_L 0x00005000 /* session ended while pushing last data to client */
71#define SN_FINST_Q 0x00006000 /* session ended while waiting in queue for a server slot */
Willy Tarreaub8750a82006-09-03 09:56:00 +020072#define SN_FINST_T 0x00007000 /* session ended tarpitted */
Willy Tarreaubaaee002006-06-26 02:48:02 +020073#define SN_FINST_MASK 0x00007000 /* mask to get only final session state flags */
74#define SN_FINST_SHIFT 12 /* bit shift */
Willy Tarreau3d300592007-03-18 18:34:41 +010075/* unused: 0x00008000 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020076
Willy Tarreau0f7562b2007-01-07 15:46:13 +010077
78/* WARNING: if new fields are added, they must be initialized in event_accept()
79 * and freed in session_free() !
80 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020081struct session {
82 struct task *task; /* the task associated with this session */
83 /* application specific below */
Willy Tarreau73de9892006-11-30 11:40:23 +010084 struct proxy *fe; /* the proxy this session depends on for the client side */
Willy Tarreau73de9892006-11-30 11:40:23 +010085 struct proxy *be; /* the proxy this session depends on for the server side */
Willy Tarreaubaaee002006-06-26 02:48:02 +020086 int cli_fd; /* the client side fd */
87 int srv_fd; /* the server side fd */
88 int cli_state; /* state of the client side */
89 int srv_state; /* state of the server side */
90 int conn_retries; /* number of connect retries left */
91 int flags; /* some flags describing the session */
92 struct buffer *req; /* request buffer */
93 struct buffer *rep; /* response buffer */
94 struct sockaddr_storage cli_addr; /* the client address */
Willy Tarreau14c8aac2007-05-08 19:46:30 +020095 struct sockaddr_storage frt_addr; /* the frontend address reached by the client if SN_FRT_ADDR_SET is set */
Willy Tarreaubaaee002006-06-26 02:48:02 +020096 struct sockaddr_in srv_addr; /* the address to connect to */
97 struct server *srv; /* the server being used */
98 struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
Willy Tarreaub326fcc2007-03-03 13:54:32 +010099 struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200100 struct {
101 int logwait; /* log fields waiting to be collected : LW_* */
102 struct timeval tv_accept; /* date of the accept() (beginning of the session) */
103 long t_request; /* delay before the end of the request arrives, -1 if never occurs */
104 long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */
105 long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */
106 long t_data; /* delay before the first data byte from the server ... */
Willy Tarreau3bac9ff2007-03-18 17:31:28 +0100107 unsigned long t_close; /* total session duration */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200108 unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */
109 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 +0100110 long long bytes_in; /* number of bytes transferred from the client to the server */
111 long long bytes_out; /* number of bytes transferred from the server to the client */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200112 } logs;
113 short int data_source; /* where to get the data we generate ourselves */
114 short int data_state; /* where to get the data we generate ourselves */
115 union {
116 struct {
117 struct proxy *px;
118 struct server *sv;
119 short px_st, sv_st; /* DATA_ST_INIT or DATA_ST_DATA */
120 } stats;
Willy Tarreau73de9892006-11-30 11:40:23 +0100121 } data_ctx; /* used by produce_content to dump the stats right now */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200122 unsigned int uniq_id; /* unique ID used for the traces */
123};
124
125
Willy Tarreaubaaee002006-06-26 02:48:02 +0200126#endif /* _TYPES_SESSION_H */
127
128/*
129 * Local variables:
130 * c-indent-level: 8
131 * c-basic-offset: 8
132 * End:
133 */