Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 31 | #include <haproxy/api-t.h> |
Willy Tarreau | 2741c8c | 2020-06-02 11:28:02 +0200 | [diff] [blame] | 32 | #include <haproxy/dynbuf-t.h> |
Willy Tarreau | 8641605 | 2020-06-04 09:20:54 +0200 | [diff] [blame] | 33 | #include <haproxy/hlua-t.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 34 | #include <haproxy/list-t.h> |
Willy Tarreau | 8efbdfb | 2020-06-04 11:29:21 +0200 | [diff] [blame] | 35 | #include <haproxy/obj_type-t.h> |
Willy Tarreau | a171892 | 2020-06-04 16:25:31 +0200 | [diff] [blame] | 36 | #include <haproxy/vars-t.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 37 | |
| 38 | #include <types/channel.h> |
Christopher Faulet | d7c9196 | 2015-04-30 11:48:27 +0200 | [diff] [blame] | 39 | #include <types/filters.h> |
Christopher Faulet | fc9cfe4 | 2019-07-16 14:54:53 +0200 | [diff] [blame] | 40 | #include <types/http_ana.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 41 | #include <types/proxy.h> |
| 42 | #include <types/queue.h> |
| 43 | #include <types/server.h> |
Willy Tarreau | b1ec8c4 | 2015-04-03 13:53:24 +0200 | [diff] [blame] | 44 | #include <types/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 45 | #include <types/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 46 | #include <haproxy/task-t.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 47 | #include <types/stick_table.h> |
| 48 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 49 | /* Various Stream Flags, bits values 0x01 to 0x100 (shift 0) */ |
| 50 | #define SF_DIRECT 0x00000001 /* connection made on the server matching the client cookie */ |
| 51 | #define SF_ASSIGNED 0x00000002 /* no need to assign a server to this stream */ |
| 52 | #define SF_ADDR_SET 0x00000004 /* this stream's server address has been set */ |
| 53 | #define SF_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 54 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 55 | #define SF_FORCE_PRST 0x00000010 /* force persistence here, even if server is down */ |
| 56 | #define SF_MONITOR 0x00000020 /* this stream comes from a monitoring system */ |
| 57 | #define SF_CURR_SESS 0x00000040 /* a connection is currently being counted on the server */ |
Willy Tarreau | 0007d0a | 2018-12-11 18:01:38 +0100 | [diff] [blame] | 58 | /* unused: 0x00000080 */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 59 | #define SF_REDISP 0x00000100 /* set if this stream was redispatched from one server to another */ |
Olivier Houchard | 4c18f94 | 2019-07-31 18:05:26 +0200 | [diff] [blame] | 60 | #define SF_IGNORE 0x00000200 /* The stream lead to a mux upgrade, and should be ignored */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 61 | #define SF_REDIRECTABLE 0x00000400 /* set if this stream is redirectable (GET or HEAD) */ |
Christopher Faulet | 0e160ff | 2019-04-03 10:01:07 +0200 | [diff] [blame] | 62 | #define SF_HTX 0x00000800 /* set if this stream is an htx stream */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 63 | |
| 64 | /* stream termination conditions, bits values 0x1000 to 0x7000 (0-9 shift 12) */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 65 | #define SF_ERR_NONE 0x00000000 /* normal end of request */ |
| 66 | #define SF_ERR_LOCAL 0x00001000 /* the proxy locally processed this request => not an error */ |
| 67 | #define SF_ERR_CLITO 0x00002000 /* client time-out */ |
| 68 | #define SF_ERR_CLICL 0x00003000 /* client closed (read/write error) */ |
| 69 | #define SF_ERR_SRVTO 0x00004000 /* server time-out, connect time-out */ |
| 70 | #define SF_ERR_SRVCL 0x00005000 /* server closed (connect/read/write error) */ |
| 71 | #define SF_ERR_PRXCOND 0x00006000 /* the proxy decided to close (deny...) */ |
| 72 | #define SF_ERR_RESOURCE 0x00007000 /* the proxy encountered a lack of a local resources (fd, mem, ...) */ |
| 73 | #define SF_ERR_INTERNAL 0x00008000 /* the proxy encountered an internal error */ |
| 74 | #define SF_ERR_DOWN 0x00009000 /* the proxy killed a stream because the backend became unavailable */ |
| 75 | #define SF_ERR_KILLED 0x0000a000 /* the proxy killed a stream because it was asked to do so */ |
| 76 | #define SF_ERR_UP 0x0000b000 /* the proxy killed a stream because a preferred backend became available */ |
Baptiste Assmann | 95db2bc | 2016-06-13 14:15:41 +0200 | [diff] [blame] | 77 | #define SF_ERR_CHK_PORT 0x0000c000 /* no port could be found for a health check. TODO: check SF_ERR_SHIFT */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 78 | #define SF_ERR_MASK 0x0000f000 /* mask to get only stream error flags */ |
| 79 | #define SF_ERR_SHIFT 12 /* bit shift */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 80 | |
| 81 | /* stream state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */ |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 82 | #define SF_FINST_R 0x00010000 /* stream ended during client request */ |
| 83 | #define SF_FINST_C 0x00020000 /* stream ended during server connect */ |
| 84 | #define SF_FINST_H 0x00030000 /* stream ended during server headers */ |
| 85 | #define SF_FINST_D 0x00040000 /* stream ended during data phase */ |
| 86 | #define SF_FINST_L 0x00050000 /* stream ended while pushing last data to client */ |
| 87 | #define SF_FINST_Q 0x00060000 /* stream ended while waiting in queue for a server slot */ |
| 88 | #define SF_FINST_T 0x00070000 /* stream ended tarpitted */ |
| 89 | #define SF_FINST_MASK 0x00070000 /* mask to get only final stream state flags */ |
| 90 | #define SF_FINST_SHIFT 16 /* bit shift */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 91 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 92 | #define SF_IGNORE_PRST 0x00080000 /* ignore persistence */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 93 | |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 94 | #define SF_SRV_REUSED 0x00100000 /* the server-side connection was reused */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 95 | |
William Lallemand | dc12c2e | 2018-12-13 09:05:46 +0100 | [diff] [blame] | 96 | |
| 97 | /* flags for the proxy of the master CLI */ |
William Lallemand | b7ea141 | 2018-12-13 09:05:47 +0100 | [diff] [blame] | 98 | /* 0x1.. to 0x3 are reserved for ACCESS_LVL_MASK */ |
William Lallemand | dc12c2e | 2018-12-13 09:05:46 +0100 | [diff] [blame] | 99 | |
| 100 | #define PCLI_F_PROMPT 0x4 |
| 101 | #define PCLI_F_PAYLOAD 0x8 |
| 102 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 103 | /* some external definitions */ |
| 104 | struct strm_logs { |
| 105 | int logwait; /* log fields waiting to be collected : LW_* */ |
| 106 | int level; /* log level to force + 1 if > 0, -1 = no log */ |
| 107 | struct timeval accept_date; /* date of the stream's accept() in user date */ |
| 108 | struct timeval tv_accept; /* date of the stream's accept() in internal date (monotonic) */ |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 109 | long t_handshake; /* handshake duration, -1 if never occurs */ |
Thierry FOURNIER / OZON.IO | 4cac359 | 2016-07-28 17:19:45 +0200 | [diff] [blame] | 110 | long t_idle; /* idle duration, -1 if never occurs */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 111 | struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */ |
| 112 | long t_queue; /* delay before the stream gets out of the connect queue, -1 if never occurs */ |
| 113 | long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */ |
| 114 | long t_data; /* delay before the first data byte from the server ... */ |
| 115 | unsigned long t_close; /* total stream duration */ |
Patrick Hemmer | ffe5e8c | 2018-05-11 12:52:31 -0400 | [diff] [blame] | 116 | unsigned long srv_queue_pos; /* number of streams de-queued while waiting for a connection slot on this server */ |
| 117 | unsigned long prx_queue_pos; /* number of streams de-qeuued while waiting for a connection slot on this instance */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 118 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 119 | long long bytes_out; /* number of bytes transferred from the server to the client */ |
| 120 | }; |
| 121 | |
| 122 | struct stream { |
| 123 | int flags; /* some flags describing the stream */ |
| 124 | unsigned int uniq_id; /* unique ID used for the traces */ |
Willy Tarreau | 1f52bb2 | 2015-04-04 14:28:46 +0200 | [diff] [blame] | 125 | enum obj_type *target; /* target to use for this stream */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 126 | |
| 127 | struct channel req; /* request channel */ |
| 128 | struct channel res; /* response channel */ |
| 129 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 130 | struct proxy *be; /* the proxy this stream depends on for the server side */ |
| 131 | |
Willy Tarreau | b1ec8c4 | 2015-04-03 13:53:24 +0200 | [diff] [blame] | 132 | struct session *sess; /* the session this stream is attached to */ |
| 133 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 134 | struct server *srv_conn; /* stream already has a slot on a server and is not in queue */ |
Christopher Faulet | 5cd4bbd | 2018-03-14 16:18:06 +0100 | [diff] [blame] | 135 | struct pendconn *pend_pos; /* if not NULL, points to the pending position in the pending queue */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 136 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 137 | struct http_txn *txn; /* current HTTP transaction being processed. Should become a list. */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 138 | |
| 139 | struct task *task; /* the task associated with this stream */ |
Christopher Faulet | 9d810ca | 2016-12-08 22:33:52 +0100 | [diff] [blame] | 140 | unsigned short pending_events; /* the pending events not yet processed by the stream. |
| 141 | * This is a bit field of TASK_WOKEN_* */ |
Patrick Hemmer | 268a707 | 2018-05-11 12:52:31 -0400 | [diff] [blame] | 142 | int16_t priority_class; /* priority class of the stream for the pending queue */ |
| 143 | int32_t priority_offset; /* priority offset of the stream for the pending queue */ |
Christopher Faulet | 9d810ca | 2016-12-08 22:33:52 +0100 | [diff] [blame] | 144 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 145 | struct list list; /* position in global streams list */ |
| 146 | struct list by_srv; /* position in server stream list */ |
| 147 | struct list back_refs; /* list of users tracking this stream */ |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 148 | struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 149 | |
Willy Tarreau | 2e9c1d2 | 2019-04-24 08:28:31 +0200 | [diff] [blame] | 150 | struct freq_ctr call_rate; /* stream task call rate */ |
| 151 | |
Willy Tarreau | 9042060 | 2019-07-18 15:09:57 +0200 | [diff] [blame] | 152 | short store_count; |
| 153 | enum obj_type obj_type; /* object type == OBJ_TYPE_STREAM */ |
| 154 | /* 1 unused bytes here */ |
| 155 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 156 | struct { |
| 157 | struct stksess *ts; |
| 158 | struct stktable *table; |
| 159 | } store[8]; /* tracked stickiness values to store */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 160 | |
Willy Tarreau | 9042060 | 2019-07-18 15:09:57 +0200 | [diff] [blame] | 161 | struct sockaddr_storage *target_addr; /* the address to join if not null */ |
Willy Tarreau | b2bf833 | 2015-04-04 15:58:58 +0200 | [diff] [blame] | 162 | struct stkctr stkctr[MAX_SESS_STKCTR]; /* content-aware stick counters */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 163 | |
Christopher Faulet | fcf035c | 2015-12-03 11:48:03 +0100 | [diff] [blame] | 164 | struct strm_flt strm_flt; /* current state of filters active on this stream */ |
| 165 | |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 166 | char **req_cap; /* array of captures from the request (may be NULL) */ |
| 167 | char **res_cap; /* array of captures from the response (may be NULL) */ |
Thierry FOURNIER | 4834bc7 | 2015-06-06 19:29:07 +0200 | [diff] [blame] | 168 | struct vars vars_txn; /* list of variables for the txn scope. */ |
| 169 | struct vars vars_reqres; /* list of variables for the request and resp scope. */ |
Willy Tarreau | cb7dd01 | 2015-04-03 22:16:32 +0200 | [diff] [blame] | 170 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 171 | struct stream_interface si[2]; /* client and server stream interfaces */ |
| 172 | struct strm_logs logs; /* logs for this stream */ |
| 173 | |
| 174 | void (*do_log)(struct stream *s); /* the function to call in order to log (or NULL) */ |
| 175 | void (*srv_error)(struct stream *s, /* the function to call upon unrecoverable server errors (or NULL) */ |
| 176 | struct stream_interface *si); |
Christopher Faulet | 92d3638 | 2015-11-05 13:35:03 +0100 | [diff] [blame] | 177 | |
William Lallemand | cf62f7e | 2018-10-26 14:47:40 +0200 | [diff] [blame] | 178 | int pcli_next_pid; /* next target PID to use for the CLI proxy */ |
William Lallemand | ebf6180 | 2018-12-11 16:10:57 +0100 | [diff] [blame] | 179 | int pcli_flags; /* flags for CLI proxy */ |
William Lallemand | 5b80fa2 | 2018-12-11 16:10:54 +0100 | [diff] [blame] | 180 | |
Tim Duesterhus | a17e662 | 2020-03-05 20:19:02 +0100 | [diff] [blame] | 181 | struct ist unique_id; /* custom unique ID */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 182 | |
| 183 | /* These two pointers are used to resume the execution of the rule lists. */ |
| 184 | struct list *current_rule_list; /* this is used to store the current executed rule list. */ |
Willy Tarreau | 152b81e | 2015-04-20 13:26:17 +0200 | [diff] [blame] | 185 | void *current_rule; /* this is used to store the current rule to be resumed. */ |
Thierry FOURNIER | 2c8b54e | 2016-12-17 12:45:32 +0100 | [diff] [blame] | 186 | struct hlua *hlua; /* lua runtime context */ |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 187 | |
| 188 | /* Context */ |
| 189 | struct { |
| 190 | struct dns_requester *dns_requester; /* owner of the resolution */ |
| 191 | char *hostname_dn; /* hostname being resolve, in domain name format */ |
| 192 | int hostname_dn_len; /* size of hostname_dn */ |
| 193 | /* 4 unused bytes here */ |
| 194 | struct act_rule *parent; /* rule which requested this resolution */ |
| 195 | } dns_ctx; /* context information for DNS resolution */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | #endif /* _TYPES_STREAM_H */ |
| 199 | |
| 200 | /* |
| 201 | * Local variables: |
| 202 | * c-indent-level: 8 |
| 203 | * c-basic-offset: 8 |
| 204 | * End: |
| 205 | */ |