blob: 0d8c5002ad7b20666f08e0db0c7a0fc00e0fc061 [file] [log] [blame]
Willy Tarreau87b09662015-04-03 00:22:06 +02001/*
2 * include/types/stream.h
3 * This file defines everything related to streams.
4 *
5 * Copyright (C) 2000-2015 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_STREAM_H
23#define _TYPES_STREAM_H
24
25
26#include <sys/time.h>
27#include <unistd.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30
31#include <common/config.h>
32#include <common/mini-clist.h>
33
34#include <types/channel.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020035#include <types/filters.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020036#include <types/hlua.h>
37#include <types/obj_type.h>
38#include <types/proto_http.h>
39#include <types/proxy.h>
40#include <types/queue.h>
41#include <types/server.h>
Willy Tarreaub1ec8c42015-04-03 13:53:24 +020042#include <types/session.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020043#include <types/stream_interface.h>
44#include <types/task.h>
45#include <types/stick_table.h>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020046#include <types/vars.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020047
Willy Tarreaue7dff022015-04-03 01:14:29 +020048/* Various Stream Flags, bits values 0x01 to 0x100 (shift 0) */
49#define SF_DIRECT 0x00000001 /* connection made on the server matching the client cookie */
50#define SF_ASSIGNED 0x00000002 /* no need to assign a server to this stream */
51#define SF_ADDR_SET 0x00000004 /* this stream's server address has been set */
52#define SF_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */
Willy Tarreau87b09662015-04-03 00:22:06 +020053
Willy Tarreaue7dff022015-04-03 01:14:29 +020054#define SF_FORCE_PRST 0x00000010 /* force persistence here, even if server is down */
55#define SF_MONITOR 0x00000020 /* this stream comes from a monitoring system */
56#define SF_CURR_SESS 0x00000040 /* a connection is currently being counted on the server */
57#define SF_INITIALIZED 0x00000080 /* the stream was fully initialized */
58#define SF_REDISP 0x00000100 /* set if this stream was redispatched from one server to another */
59#define SF_CONN_TAR 0x00000200 /* set if this stream is turning around before reconnecting */
60#define SF_REDIRECTABLE 0x00000400 /* set if this stream is redirectable (GET or HEAD) */
61#define SF_TUNNEL 0x00000800 /* tunnel-mode stream, nothing to catch after data */
Willy Tarreau87b09662015-04-03 00:22:06 +020062
63/* stream termination conditions, bits values 0x1000 to 0x7000 (0-9 shift 12) */
Willy Tarreaue7dff022015-04-03 01:14:29 +020064#define SF_ERR_NONE 0x00000000 /* normal end of request */
65#define SF_ERR_LOCAL 0x00001000 /* the proxy locally processed this request => not an error */
66#define SF_ERR_CLITO 0x00002000 /* client time-out */
67#define SF_ERR_CLICL 0x00003000 /* client closed (read/write error) */
68#define SF_ERR_SRVTO 0x00004000 /* server time-out, connect time-out */
69#define SF_ERR_SRVCL 0x00005000 /* server closed (connect/read/write error) */
70#define SF_ERR_PRXCOND 0x00006000 /* the proxy decided to close (deny...) */
71#define SF_ERR_RESOURCE 0x00007000 /* the proxy encountered a lack of a local resources (fd, mem, ...) */
72#define SF_ERR_INTERNAL 0x00008000 /* the proxy encountered an internal error */
73#define SF_ERR_DOWN 0x00009000 /* the proxy killed a stream because the backend became unavailable */
74#define SF_ERR_KILLED 0x0000a000 /* the proxy killed a stream because it was asked to do so */
75#define SF_ERR_UP 0x0000b000 /* the proxy killed a stream because a preferred backend became available */
Baptiste Assmann95db2bc2016-06-13 14:15:41 +020076#define SF_ERR_CHK_PORT 0x0000c000 /* no port could be found for a health check. TODO: check SF_ERR_SHIFT */
Willy Tarreaue7dff022015-04-03 01:14:29 +020077#define SF_ERR_MASK 0x0000f000 /* mask to get only stream error flags */
78#define SF_ERR_SHIFT 12 /* bit shift */
Willy Tarreau87b09662015-04-03 00:22:06 +020079
80/* stream state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */
Willy Tarreaue7dff022015-04-03 01:14:29 +020081#define SF_FINST_R 0x00010000 /* stream ended during client request */
82#define SF_FINST_C 0x00020000 /* stream ended during server connect */
83#define SF_FINST_H 0x00030000 /* stream ended during server headers */
84#define SF_FINST_D 0x00040000 /* stream ended during data phase */
85#define SF_FINST_L 0x00050000 /* stream ended while pushing last data to client */
86#define SF_FINST_Q 0x00060000 /* stream ended while waiting in queue for a server slot */
87#define SF_FINST_T 0x00070000 /* stream ended tarpitted */
88#define SF_FINST_MASK 0x00070000 /* mask to get only final stream state flags */
89#define SF_FINST_SHIFT 16 /* bit shift */
Willy Tarreau87b09662015-04-03 00:22:06 +020090
Willy Tarreaue7dff022015-04-03 01:14:29 +020091#define SF_IGNORE_PRST 0x00080000 /* ignore persistence */
Willy Tarreau87b09662015-04-03 00:22:06 +020092
Christopher Faulet92d36382015-11-05 13:35:03 +010093#define SF_SRV_REUSED 0x00100000 /* the server-side connection was reused */
Willy Tarreau87b09662015-04-03 00:22:06 +020094
95/* some external definitions */
96struct strm_logs {
97 int logwait; /* log fields waiting to be collected : LW_* */
98 int level; /* log level to force + 1 if > 0, -1 = no log */
99 struct timeval accept_date; /* date of the stream's accept() in user date */
100 struct timeval tv_accept; /* date of the stream's accept() in internal date (monotonic) */
Thierry FOURNIER / OZON.IO4cac3592016-07-28 17:19:45 +0200101 long t_handshake; /* hanshake duration, -1 if never occurs */
102 long t_idle; /* idle duration, -1 if never occurs */
Willy Tarreau87b09662015-04-03 00:22:06 +0200103 struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */
104 long t_queue; /* delay before the stream 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 ... */
107 unsigned long t_close; /* total stream duration */
108 unsigned long srv_queue_size; /* number of streams waiting for a connect slot on this server at accept() time (in direct assignment) */
109 unsigned long prx_queue_size; /* overall number of streams waiting for a connect slot on this instance at accept() time */
110 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 */
112};
113
114struct stream {
115 int flags; /* some flags describing the stream */
116 unsigned int uniq_id; /* unique ID used for the traces */
Willy Tarreau1f52bb22015-04-04 14:28:46 +0200117 enum obj_type *target; /* target to use for this stream */
Willy Tarreau87b09662015-04-03 00:22:06 +0200118
119 struct channel req; /* request channel */
120 struct channel res; /* response channel */
121
Willy Tarreau87b09662015-04-03 00:22:06 +0200122 struct proxy *be; /* the proxy this stream depends on for the server side */
123
Willy Tarreaub1ec8c42015-04-03 13:53:24 +0200124 struct session *sess; /* the session this stream is attached to */
125
Willy Tarreau87b09662015-04-03 00:22:06 +0200126 struct server *srv_conn; /* stream already has a slot on a server and is not in queue */
127 struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
128
Willy Tarreaueee5b512015-04-03 23:46:31 +0200129 struct http_txn *txn; /* current HTTP transaction being processed. Should become a list. */
Willy Tarreau87b09662015-04-03 00:22:06 +0200130
131 struct task *task; /* the task associated with this stream */
132 struct list list; /* position in global streams list */
133 struct list by_srv; /* position in server stream list */
134 struct list back_refs; /* list of users tracking this stream */
135 struct list buffer_wait; /* position in the list of streams waiting for a buffer */
136
137 struct {
138 struct stksess *ts;
139 struct stktable *table;
140 } store[8]; /* tracked stickiness values to store */
141 int store_count;
142 /* 4 unused bytes here */
143
Willy Tarreaub2bf8332015-04-04 15:58:58 +0200144 struct stkctr stkctr[MAX_SESS_STKCTR]; /* content-aware stick counters */
Willy Tarreau87b09662015-04-03 00:22:06 +0200145
Christopher Fauletfcf035c2015-12-03 11:48:03 +0100146 struct strm_flt strm_flt; /* current state of filters active on this stream */
147
Willy Tarreaucb7dd012015-04-03 22:16:32 +0200148 char **req_cap; /* array of captures from the request (may be NULL) */
149 char **res_cap; /* array of captures from the response (may be NULL) */
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200150 struct vars vars_txn; /* list of variables for the txn scope. */
151 struct vars vars_reqres; /* list of variables for the request and resp scope. */
Willy Tarreaucb7dd012015-04-03 22:16:32 +0200152
Willy Tarreau87b09662015-04-03 00:22:06 +0200153 struct stream_interface si[2]; /* client and server stream interfaces */
154 struct strm_logs logs; /* logs for this stream */
155
156 void (*do_log)(struct stream *s); /* the function to call in order to log (or NULL) */
157 void (*srv_error)(struct stream *s, /* the function to call upon unrecoverable server errors (or NULL) */
158 struct stream_interface *si);
Christopher Faulet92d36382015-11-05 13:35:03 +0100159
Willy Tarreau87b09662015-04-03 00:22:06 +0200160 char *unique_id; /* custom unique ID */
161
162 /* These two pointers are used to resume the execution of the rule lists. */
163 struct list *current_rule_list; /* this is used to store the current executed rule list. */
Willy Tarreau152b81e2015-04-20 13:26:17 +0200164 void *current_rule; /* this is used to store the current rule to be resumed. */
Willy Tarreau87b09662015-04-03 00:22:06 +0200165 struct hlua hlua; /* lua runtime context */
166};
167
168#endif /* _TYPES_STREAM_H */
169
170/*
171 * Local variables:
172 * c-indent-level: 8
173 * c-basic-offset: 8
174 * End:
175 */