Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/session.h |
| 3 | This file defines everything related to sessions. |
| 4 | |
| 5 | Copyright (C) 2000-2006 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 | */ |
| 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 Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 31 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 32 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
| 34 | #include <types/buffers.h> |
| 35 | #include <types/proxy.h> |
| 36 | #include <types/queue.h> |
| 37 | #include <types/server.h> |
| 38 | #include <types/task.h> |
Willy Tarreau | e5f20dc | 2006-12-03 15:21:35 +0100 | [diff] [blame] | 39 | #include <types/hdr_idx.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 */ |
| 44 | #define SN_CLDENY 0x00000002 /* a client header matches a deny regex */ |
| 45 | #define SN_CLALLOW 0x00000004 /* a client header matches an allow regex */ |
| 46 | #define SN_SVDENY 0x00000008 /* a server header matches a deny regex */ |
| 47 | #define SN_SVALLOW 0x00000010 /* a server header matches an allow regex */ |
Willy Tarreau | f1221aa | 2006-12-17 22:14:12 +0100 | [diff] [blame] | 48 | #define SN_BE_ASSIGNED 0x00000020 /* a backend was assigned. Conns are accounted. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | |
| 50 | /* session flags dedicated to cookies : bits values 0x40, 0x80 (0-3 shift 6) */ |
| 51 | #define SN_CK_NONE 0x00000000 /* this session had no cookie */ |
| 52 | #define SN_CK_INVALID 0x00000040 /* this session had a cookie which matches no server */ |
| 53 | #define SN_CK_DOWN 0x00000080 /* this session had cookie matching a down server */ |
| 54 | #define SN_CK_VALID 0x000000C0 /* this session had cookie matching a valid server */ |
| 55 | #define SN_CK_MASK 0x000000C0 /* mask to get this session's cookie flags */ |
| 56 | #define SN_CK_SHIFT 6 /* bit shift */ |
| 57 | |
| 58 | /* session termination conditions, bits values 0x100 to 0x700 (0-7 shift 8) */ |
| 59 | #define SN_ERR_NONE 0x00000000 |
| 60 | #define SN_ERR_CLITO 0x00000100 /* client time-out */ |
| 61 | #define SN_ERR_CLICL 0x00000200 /* client closed (read/write error) */ |
| 62 | #define SN_ERR_SRVTO 0x00000300 /* server time-out, connect time-out */ |
| 63 | #define SN_ERR_SRVCL 0x00000400 /* server closed (connect/read/write error) */ |
| 64 | #define SN_ERR_PRXCOND 0x00000500 /* the proxy decided to close (deny...) */ |
| 65 | #define SN_ERR_RESOURCE 0x00000600 /* the proxy encountered a lack of a local resources (fd, mem, ...) */ |
| 66 | #define SN_ERR_INTERNAL 0x00000700 /* the proxy encountered an internal error */ |
| 67 | #define SN_ERR_MASK 0x00000700 /* mask to get only session error flags */ |
| 68 | #define SN_ERR_SHIFT 8 /* bit shift */ |
| 69 | |
| 70 | /* session state at termination, bits values 0x1000 to 0x7000 (0-7 shift 12) */ |
| 71 | #define SN_FINST_R 0x00001000 /* session ended during client request */ |
| 72 | #define SN_FINST_C 0x00002000 /* session ended during server connect */ |
| 73 | #define SN_FINST_H 0x00003000 /* session ended during server headers */ |
| 74 | #define SN_FINST_D 0x00004000 /* session ended during data phase */ |
| 75 | #define SN_FINST_L 0x00005000 /* session ended while pushing last data to client */ |
| 76 | #define SN_FINST_Q 0x00006000 /* session ended while waiting in queue for a server slot */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 77 | #define SN_FINST_T 0x00007000 /* session ended tarpitted */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | #define SN_FINST_MASK 0x00007000 /* mask to get only final session state flags */ |
| 79 | #define SN_FINST_SHIFT 12 /* bit shift */ |
| 80 | |
| 81 | /* cookie information, bits values 0x10000 to 0x80000 (0-8 shift 16) */ |
| 82 | #define SN_SCK_NONE 0x00000000 /* no set-cookie seen for the server cookie */ |
| 83 | #define SN_SCK_DELETED 0x00010000 /* existing set-cookie deleted or changed */ |
| 84 | #define SN_SCK_INSERTED 0x00020000 /* new set-cookie inserted or changed existing one */ |
| 85 | #define SN_SCK_SEEN 0x00040000 /* set-cookie seen for the server cookie */ |
| 86 | #define SN_SCK_MASK 0x00070000 /* mask to get the set-cookie field */ |
| 87 | #define SN_SCK_ANY 0x00080000 /* at least one set-cookie seen (not to be counted) */ |
| 88 | #define SN_SCK_SHIFT 16 /* bit shift */ |
| 89 | |
| 90 | /* cacheability management, bits values 0x100000 to 0x300000 (0-3 shift 20) */ |
| 91 | #define SN_CACHEABLE 0x00100000 /* at least part of the response is cacheable */ |
| 92 | #define SN_CACHE_COOK 0x00200000 /* a cookie in the response is cacheable */ |
| 93 | #define SN_CACHE_SHIFT 20 /* bit shift */ |
| 94 | |
| 95 | /* various other session flags, bits values 0x400000 and above */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 96 | #define SN_CONN_CLOSED 0x00000800 /* "Connection: close" was present or added */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 97 | #define SN_MONITOR 0x00400000 /* this session comes from a monitoring system */ |
| 98 | #define SN_ASSIGNED 0x00800000 /* no need to assign a server to this session */ |
| 99 | #define SN_ADDR_SET 0x01000000 /* this session's server address has been set */ |
| 100 | #define SN_SELF_GEN 0x02000000 /* the proxy generates data for the client (eg: stats) */ |
Willy Tarreau | b8750a8 | 2006-09-03 09:56:00 +0200 | [diff] [blame] | 101 | #define SN_CLTARPIT 0x04000000 /* the session is tarpitted (anti-dos) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 102 | |
Willy Tarreau | 53b6c74 | 2006-12-17 13:37:46 +0100 | [diff] [blame] | 103 | typedef enum { |
| 104 | HTTP_METH_NONE = 0, |
| 105 | HTTP_METH_OPTIONS, |
| 106 | HTTP_METH_GET, |
| 107 | HTTP_METH_HEAD, |
| 108 | HTTP_METH_POST, |
| 109 | HTTP_METH_PUT, |
| 110 | HTTP_METH_DELETE, |
| 111 | HTTP_METH_TRACE, |
| 112 | HTTP_METH_CONNECT, |
| 113 | HTTP_METH_OTHER, |
| 114 | } http_meth_t; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 115 | |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 116 | /* FIXME-20070107: this should move out to another file when HTTP will not be |
| 117 | * in the session anymore. |
| 118 | */ |
| 119 | |
| 120 | /* This is an HTTP message, as described in RFC2616. It can be either a request |
| 121 | * message or a response message. |
Willy Tarreau | 0637fa0 | 2007-01-13 23:07:22 +0100 | [diff] [blame] | 122 | * |
| 123 | * The values there are a little bit obscure, because their meaning can change |
| 124 | * during the parsing : |
| 125 | * |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 126 | * - som (Start of Message) : relative offset in the buffer of first byte of |
Willy Tarreau | 0637fa0 | 2007-01-13 23:07:22 +0100 | [diff] [blame] | 127 | * the request being processed or parsed. Reset to |
| 128 | * zero during accept(). |
| 129 | * - eoh (End of Headers) : relative offset in the buffer of first byte that |
| 130 | * is not part of a completely processed header. |
| 131 | * During parsing, it points to last header seen |
| 132 | * for states after START. |
| 133 | * - eol (End of Line) : relative offset in the buffer of the first byte |
| 134 | * which marks the end of the line (LF or CRLF). |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 135 | */ |
| 136 | struct http_msg { |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 137 | int msg_state; /* where we are in the current message parsing */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 138 | char *sol, *eol; /* start of line, end of line */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 139 | int som; /* Start Of Message, relative to buffer */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 140 | int col, sov; /* current header: colon, start of value */ |
| 141 | int eoh; /* End Of Headers, relative to buffer */ |
Willy Tarreau | 362b34d | 2007-01-21 20:49:31 +0100 | [diff] [blame] | 142 | char **cap; /* array of captured headers (may be NULL) */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 143 | union { /* useful start line pointers, relative to buffer */ |
| 144 | struct { |
| 145 | int l; /* request line length (not including CR) */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 146 | int m_l; /* METHOD length (method starts at ->som) */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 147 | int u, u_l; /* URI, length */ |
| 148 | int v, v_l; /* VERSION, length */ |
| 149 | } rq; /* request line : field, length */ |
| 150 | struct { |
| 151 | int l; /* status line length (not including CR) */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 152 | int v_l; /* VERSION length (version starts at ->som) */ |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 153 | int c, c_l; /* CODE, length */ |
| 154 | int r, r_l; /* REASON, length */ |
| 155 | } st; /* status line : field, length */ |
| 156 | } sl; /* start line */ |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 159 | /* This is an HTTP transaction. It contains both a request message and a |
| 160 | * response message (which can be empty). |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 161 | */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 162 | struct http_txn { |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 163 | http_meth_t meth; /* HTTP method */ |
| 164 | struct hdr_idx hdr_idx; /* array of header indexes (max: MAX_HTTP_HDR) */ |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 165 | struct chunk auth_hdr; /* points to 'Authorization:' header */ |
| 166 | struct http_msg req, rsp; /* HTTP request and response messages */ |
| 167 | }; |
| 168 | |
| 169 | /* WARNING: if new fields are added, they must be initialized in event_accept() |
| 170 | * and freed in session_free() ! |
| 171 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 172 | struct session { |
| 173 | struct task *task; /* the task associated with this session */ |
| 174 | /* application specific below */ |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 175 | struct proxy *fe; /* the proxy this session depends on for the client side */ |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 176 | struct proxy *be; /* the proxy this session depends on for the server side */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | int cli_fd; /* the client side fd */ |
| 178 | int srv_fd; /* the server side fd */ |
| 179 | int cli_state; /* state of the client side */ |
| 180 | int srv_state; /* state of the server side */ |
| 181 | int conn_retries; /* number of connect retries left */ |
| 182 | int flags; /* some flags describing the session */ |
| 183 | struct buffer *req; /* request buffer */ |
| 184 | struct buffer *rep; /* response buffer */ |
| 185 | struct sockaddr_storage cli_addr; /* the client address */ |
| 186 | struct sockaddr_in srv_addr; /* the address to connect to */ |
| 187 | struct server *srv; /* the server being used */ |
| 188 | struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 189 | struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 190 | struct { |
| 191 | int logwait; /* log fields waiting to be collected : LW_* */ |
| 192 | struct timeval tv_accept; /* date of the accept() (beginning of the session) */ |
| 193 | long t_request; /* delay before the end of the request arrives, -1 if never occurs */ |
| 194 | long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */ |
| 195 | long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */ |
| 196 | long t_data; /* delay before the first data byte from the server ... */ |
| 197 | unsigned long t_close; /* total session duration */ |
| 198 | unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */ |
| 199 | unsigned long prx_queue_size; /* overall number of sessions waiting for a connect slot on this instance at accept() time */ |
| 200 | char *uri; /* first line if log needed, NULL otherwise */ |
| 201 | char *cli_cookie; /* cookie presented by the client, in capture mode */ |
| 202 | char *srv_cookie; /* cookie presented by the server, in capture mode */ |
| 203 | int status; /* HTTP status from the server, negative if from proxy */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 204 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 205 | long long bytes_out; /* number of bytes transferred from the server to the client */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 206 | } logs; |
| 207 | short int data_source; /* where to get the data we generate ourselves */ |
| 208 | short int data_state; /* where to get the data we generate ourselves */ |
| 209 | union { |
| 210 | struct { |
| 211 | struct proxy *px; |
| 212 | struct server *sv; |
| 213 | short px_st, sv_st; /* DATA_ST_INIT or DATA_ST_DATA */ |
| 214 | } stats; |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 215 | } data_ctx; /* used by produce_content to dump the stats right now */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 216 | unsigned int uniq_id; /* unique ID used for the traces */ |
| 217 | }; |
| 218 | |
| 219 | |
| 220 | #define sizeof_session sizeof(struct session) |
| 221 | extern void **pool_session; |
| 222 | |
| 223 | |
| 224 | #endif /* _TYPES_SESSION_H */ |
| 225 | |
| 226 | /* |
| 227 | * Local variables: |
| 228 | * c-indent-level: 8 |
| 229 | * c-basic-offset: 8 |
| 230 | * End: |
| 231 | */ |