/src/haproxy/include/haproxy/stconn-t.h
Line | Count | Source |
1 | | /* |
2 | | * include/haproxy/stconn-t.h |
3 | | * This file describes the stream connector struct and associated constants. |
4 | | * |
5 | | * Copyright 2021 Christopher Faulet <cfaulet@haproxy.com> |
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 _HAPROXY_STCONN_T_H |
23 | | #define _HAPROXY_STCONN_T_H |
24 | | |
25 | | #include <haproxy/obj_type-t.h> |
26 | | #include <haproxy/connection-t.h> |
27 | | #include <haproxy/pipe-t.h> |
28 | | #include <haproxy/show_flags-t.h> |
29 | | #include <haproxy/task-t.h> |
30 | | #include <haproxy/xref-t.h> |
31 | | |
32 | | enum iobuf_flags { |
33 | | IOBUF_FL_NONE = 0x00000000, /* For initialization purposes */ |
34 | | IOBUF_FL_NO_FF = 0x00000001, /* Fast-forwarding is not supported */ |
35 | | IOBUF_FL_NO_SPLICING = 0x00000002, /* Splicing is not supported or unusable for this stream */ |
36 | | IOBUF_FL_FF_BLOCKED = 0x00000004, /* Fast-forwarding is blocked (buffer allocation/full) */ |
37 | | |
38 | | IOBUF_FL_INTERIM_FF = 0x00000008, /* Producer side warn it will immediately retry a fast-forward. |
39 | | * .done_fastfwd() on consumer side must take care of this flag |
40 | | */ |
41 | | IOBUF_FL_EOI = 0x00000010, /* A EOI was encountered on producer side */ |
42 | | IOBUF_FL_FF_WANT_ROOM = 0x00000020, /* Producer need more room in the IOBUF to forward data */ |
43 | | }; |
44 | | |
45 | | /* Flags used */ |
46 | | enum nego_ff_flags { |
47 | | NEGO_FF_FL_NONE = 0x00000000, /* For initialization purposes */ |
48 | | NEGO_FF_FL_MAY_SPLICE = 0x00000001, /* Consumer may choose to use kernel splicing if it supports it */ |
49 | | NEGO_FF_FL_EXACT_SIZE = 0x00000002, /* Size passed for the nego is the expected exact size to forwarded */ |
50 | | }; |
51 | | |
52 | | struct iobuf { |
53 | | struct pipe *pipe; /* non-NULL only when data present */ |
54 | | struct buffer *buf; |
55 | | size_t offset; |
56 | | size_t data; |
57 | | unsigned int flags; |
58 | | }; |
59 | | |
60 | | /* Stream Endpoint Flags. |
61 | | * Please also update the se_show_flags() function below in case of changes. |
62 | | */ |
63 | | enum se_flags { |
64 | | SE_FL_NONE = 0x00000000, /* For initialization purposes */ |
65 | | |
66 | | /* Endpoint types */ |
67 | | SE_FL_T_MUX = 0x00000001, /* The endpoint is a mux (the target may be NULL before the mux init) */ |
68 | | SE_FL_T_APPLET = 0x00000002, /* The endpoint is an applet */ |
69 | | |
70 | | /* unused: 0x00000004 .. 0x00000008 */ |
71 | | |
72 | | /* Endpoint states: none == attached to a mux with a stream connector */ |
73 | | SE_FL_DETACHED = 0x00000010, /* The endpoint is detached (no mux/no applet) */ |
74 | | SE_FL_ORPHAN = 0x00000020, /* The endpoint is orphan (no stream connector) */ |
75 | | |
76 | | SE_FL_APP_STARTED= 0x00000040, /* the application layer has really started */ |
77 | | |
78 | | /* unused: 0x00000080 */ |
79 | | |
80 | | SE_FL_SHRD = 0x00000100, /* read shut, draining extra data */ |
81 | | SE_FL_SHRR = 0x00000200, /* read shut, resetting extra data */ |
82 | | SE_FL_SHR = SE_FL_SHRD | SE_FL_SHRR, /* read shut status */ |
83 | | |
84 | | SE_FL_SHWN = 0x00000400, /* write shut, verbose mode */ |
85 | | SE_FL_SHWS = 0x00000800, /* write shut, silent mode */ |
86 | | SE_FL_SHW = SE_FL_SHWN | SE_FL_SHWS, /* write shut status */ |
87 | | |
88 | | /* following flags are supposed to be set by the endpoint and read by |
89 | | * the app layer : |
90 | | */ |
91 | | |
92 | | /* Permanent flags */ |
93 | | SE_FL_NOT_FIRST = 0x00001000, /* This stream connector is not the first one for the endpoint */ |
94 | | SE_FL_WEBSOCKET = 0x00002000, /* The endpoint uses the websocket proto */ |
95 | | SE_FL_EOI = 0x00004000, /* end-of-input reached */ |
96 | | SE_FL_EOS = 0x00008000, /* End of stream delivered to data layer */ |
97 | | SE_FL_ERROR = 0x00010000, /* a fatal error was reported */ |
98 | | /* Transient flags */ |
99 | | SE_FL_ERR_PENDING= 0x00020000, /* An error is pending, but there's still data to be read */ |
100 | | SE_FL_RCV_MORE = 0x00040000, /* Endpoint may have more bytes to transfer */ |
101 | | SE_FL_WANT_ROOM = 0x00080000, /* More bytes to transfer, but not enough room */ |
102 | | SE_FL_EXP_NO_DATA= 0x00100000, /* No data expected by the endpoint */ |
103 | | SE_FL_MAY_FASTFWD_PROD = 0x00200000, /* The endpoint may produce data via zero-copy forwarding */ |
104 | | SE_FL_MAY_FASTFWD_CONS = 0x00400000, /* The endpoint may consume data via zero-copy forwarding */ |
105 | | SE_FL_ENDP_MASK = 0x004ff000, /* Mask for flags set by the endpoint */ |
106 | | |
107 | | /* following flags are supposed to be set by the app layer and read by |
108 | | * the endpoint : |
109 | | */ |
110 | | /* unused 0x00800000,*/ |
111 | | /* unused 0x01000000,*/ |
112 | | /* unused 0x02000000,*/ |
113 | | SE_FL_WAIT_FOR_HS = 0x04000000, /* This stream is waiting for handhskae */ |
114 | | SE_FL_KILL_CONN = 0x08000000, /* must kill the connection when the SC closes */ |
115 | | SE_FL_WAIT_DATA = 0x10000000, /* stream endpoint cannot work without more data from the stream's output */ |
116 | | SE_FL_WONT_CONSUME = 0x20000000, /* stream endpoint will not consume more data */ |
117 | | SE_FL_HAVE_NO_DATA = 0x40000000, /* the endpoint has no more data to deliver to the stream */ |
118 | | SE_FL_APPLET_NEED_CONN = 0x80000000, /* applet is waiting for the other side to (fail to) connect */ |
119 | | }; |
120 | | |
121 | | /* Shutdown modes */ |
122 | | enum se_shut_mode { |
123 | | SE_SHR_DRAIN = 0x00000001, /* read shutdown, drain any extra stuff */ |
124 | | SE_SHR_RESET = 0x00000002, /* read shutdown, reset any extra stuff */ |
125 | | SE_SHW_NORMAL = 0x00000004, /* regular write shutdown */ |
126 | | SE_SHW_SILENT = 0x00000008, /* imminent close, don't notify peer */ |
127 | | }; |
128 | | |
129 | | /* This function is used to report flags in debugging tools. Please reflect |
130 | | * below any single-bit flag addition above in the same order via the |
131 | | * __APPEND_FLAG macro. The new end of the buffer is returned. |
132 | | */ |
133 | | static forceinline char *se_show_flags(char *buf, size_t len, const char *delim, uint flg) |
134 | 0 | { |
135 | 0 | #define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__) |
136 | 0 | /* prologue */ |
137 | 0 | _(0); |
138 | 0 | /* flags */ |
139 | 0 | _(SE_FL_T_MUX, _(SE_FL_T_APPLET, _(SE_FL_DETACHED, _(SE_FL_ORPHAN, |
140 | 0 | _(SE_FL_APP_STARTED, _(SE_FL_SHRD, _(SE_FL_SHRR, _(SE_FL_SHWN, _(SE_FL_SHWS, |
141 | 0 | _(SE_FL_NOT_FIRST, _(SE_FL_WEBSOCKET, _(SE_FL_EOI, _(SE_FL_EOS, |
142 | 0 | _(SE_FL_ERROR, _(SE_FL_ERR_PENDING, _(SE_FL_RCV_MORE, |
143 | 0 | _(SE_FL_WANT_ROOM, _(SE_FL_EXP_NO_DATA, _(SE_FL_MAY_FASTFWD_PROD, _(SE_FL_MAY_FASTFWD_CONS, |
144 | 0 | _(SE_FL_WAIT_FOR_HS, _(SE_FL_KILL_CONN, _(SE_FL_WAIT_DATA, |
145 | 0 | _(SE_FL_WONT_CONSUME, _(SE_FL_HAVE_NO_DATA, _(SE_FL_APPLET_NEED_CONN)))))))))))))))))))))))))); |
146 | 0 | /* epilogue */ |
147 | 0 | _(~0U); |
148 | 0 | return buf; |
149 | 0 | #undef _ |
150 | 0 | } Unexecuted instantiation: debug.c:se_show_flags Unexecuted instantiation: fd.c:se_show_flags Unexecuted instantiation: haproxy.c:se_show_flags Unexecuted instantiation: http_htx.c:se_show_flags Unexecuted instantiation: limits.c:se_show_flags Unexecuted instantiation: listener.c:se_show_flags Unexecuted instantiation: log.c:se_show_flags Unexecuted instantiation: mworker.c:se_show_flags Unexecuted instantiation: peers.c:se_show_flags Unexecuted instantiation: pool.c:se_show_flags Unexecuted instantiation: proto_sockpair.c:se_show_flags Unexecuted instantiation: proxy.c:se_show_flags Unexecuted instantiation: resolvers.c:se_show_flags Unexecuted instantiation: ring.c:se_show_flags Unexecuted instantiation: sample.c:se_show_flags Unexecuted instantiation: server.c:se_show_flags Unexecuted instantiation: session.c:se_show_flags Unexecuted instantiation: sink.c:se_show_flags Unexecuted instantiation: sock.c:se_show_flags Unexecuted instantiation: stats.c:se_show_flags Unexecuted instantiation: stconn.c:se_show_flags Unexecuted instantiation: stick_table.c:se_show_flags Unexecuted instantiation: stream.c:se_show_flags Unexecuted instantiation: tcp_rules.c:se_show_flags Unexecuted instantiation: tcpcheck.c:se_show_flags Unexecuted instantiation: thread.c:se_show_flags Unexecuted instantiation: tools.c:se_show_flags Unexecuted instantiation: trace.c:se_show_flags Unexecuted instantiation: vars.c:se_show_flags Unexecuted instantiation: action.c:se_show_flags Unexecuted instantiation: activity.c:se_show_flags Unexecuted instantiation: applet.c:se_show_flags Unexecuted instantiation: backend.c:se_show_flags Unexecuted instantiation: cfgparse-listen.c:se_show_flags Unexecuted instantiation: cfgparse.c:se_show_flags Unexecuted instantiation: channel.c:se_show_flags Unexecuted instantiation: check.c:se_show_flags Unexecuted instantiation: cli.c:se_show_flags Unexecuted instantiation: connection.c:se_show_flags Unexecuted instantiation: dns.c:se_show_flags Unexecuted instantiation: dns_ring.c:se_show_flags Unexecuted instantiation: errors.c:se_show_flags Unexecuted instantiation: extcheck.c:se_show_flags Unexecuted instantiation: filters.c:se_show_flags Unexecuted instantiation: flt_http_comp.c:se_show_flags Unexecuted instantiation: frontend.c:se_show_flags Unexecuted instantiation: guid.c:se_show_flags Unexecuted instantiation: haterm.c:se_show_flags Unexecuted instantiation: http_ana.c:se_show_flags Unexecuted instantiation: http_ext.c:se_show_flags Unexecuted instantiation: http_fetch.c:se_show_flags Unexecuted instantiation: http_rules.c:se_show_flags Unexecuted instantiation: lb_chash.c:se_show_flags Unexecuted instantiation: lb_fas.c:se_show_flags Unexecuted instantiation: lb_fwlc.c:se_show_flags Unexecuted instantiation: lb_fwrr.c:se_show_flags Unexecuted instantiation: lb_map.c:se_show_flags Unexecuted instantiation: lb_ss.c:se_show_flags Unexecuted instantiation: mux_spop.c:se_show_flags Unexecuted instantiation: pattern.c:se_show_flags Unexecuted instantiation: payload.c:se_show_flags Unexecuted instantiation: proto_rhttp.c:se_show_flags Unexecuted instantiation: queue.c:se_show_flags Unexecuted instantiation: stats-file.c:se_show_flags Unexecuted instantiation: stats-html.c:se_show_flags Unexecuted instantiation: stats-json.c:se_show_flags Unexecuted instantiation: stats-proxy.c:se_show_flags Unexecuted instantiation: cache.c:se_show_flags Unexecuted instantiation: cfgparse-global.c:se_show_flags Unexecuted instantiation: compression.c:se_show_flags Unexecuted instantiation: fcgi-app.c:se_show_flags Unexecuted instantiation: flt_spoe.c:se_show_flags Unexecuted instantiation: proto_tcp.c:se_show_flags |
151 | | |
152 | | /* stconn flags. |
153 | | * Please also update the sc_show_flags() function below in case of changes. |
154 | | * |
155 | | * When SC_FL_ABRT_WANTED/SC_FL_EOS is set, it is strictly forbidden for the |
156 | | * producer to alter the buffer contents. In this case, the consumer is free to |
157 | | * perform a shutdown when it has consumed the last contents, otherwise the |
158 | | * session processor will do it anyway. SC_FL_ABRT* are set at the upper layer |
159 | | * level (the stream) while SC_FL_EOS is set at the SE layer. |
160 | | * |
161 | | * The SC_FL_SHUT_WANTED flaga should be set by the session processor when |
162 | | * SC_FLABRT_DONE/SC_FL_EOS and CF_AUTO_CLOSE are both set. And it may also be |
163 | | * set by the producer when it detects SC_FL_EOS while directly forwarding data to the |
164 | | * consumer. |
165 | | * |
166 | | * The SHUT/ABRT flags work like this : |
167 | | * |
168 | | * ABRT_WANTED ABRT_DONE meaning |
169 | | * 0 0 normal case, connection still open and data is being read |
170 | | * 1 0 closing : the producer cannot feed data anymore but can close |
171 | | * 0/1 1 closed: the producer has closed its input channel. |
172 | | * |
173 | | * SHUT_WANTED SHUT_DONE meaning |
174 | | * 0 0 normal case, connection still open and data is being written |
175 | | * 1 0 closing: the consumer can send last data and may then close |
176 | | * 0/1 1 closed: the consumer has closed its output channel. |
177 | | * |
178 | | * |
179 | | * The ABRT_WANTED flag is mostly used to force the producer to abort when an error is |
180 | | * detected on the consumer side. |
181 | | * |
182 | | */ |
183 | | enum sc_flags { |
184 | | SC_FL_NONE = 0x00000000, /* Just for initialization purposes */ |
185 | | SC_FL_ISBACK = 0x00000001, /* Set for SC on back-side */ |
186 | | |
187 | | SC_FL_EOI = 0x00000002, /* End of input was reached. no more data will be received from the endpoint */ |
188 | | SC_FL_ERROR = 0x00000004, /* A fatal error was reported */ |
189 | | |
190 | | SC_FL_NOLINGER = 0x00000008, /* may close without lingering. One-shot. */ |
191 | | SC_FL_NOHALF = 0x00000010, /* no half close, close both sides at once */ |
192 | | SC_FL_DONT_WAKE = 0x00000020, /* resync in progress, don't wake up */ |
193 | | SC_FL_INDEP_STR = 0x00000040, /* independent streams = don't update rex on write */ |
194 | | |
195 | | SC_FL_WONT_READ = 0x00000080, /* SC doesn't want to read data */ |
196 | | SC_FL_NEED_BUFF = 0x00000100, /* SC waits for an rx buffer allocation to complete */ |
197 | | SC_FL_NEED_ROOM = 0x00000200, /* SC needs more room in the rx buffer to store incoming data */ |
198 | | |
199 | | SC_FL_RCV_ONCE = 0x00000400, /* Don't loop to receive data. cleared after a successful receive */ |
200 | | SC_FL_SND_ASAP = 0x00000800, /* Don't wait for sending. cleared when all data were sent */ |
201 | | SC_FL_SND_NEVERWAIT = 0x00001000, /* Never wait for sending (permanent) */ |
202 | | SC_FL_SND_EXP_MORE = 0x00002000, /* More data expected to be sent very soon. cleared when all data were sent */ |
203 | | |
204 | | SC_FL_ABRT_WANTED = 0x00004000, /* An abort was requested and must be performed ASAP (up side to down side) */ |
205 | | SC_FL_SHUT_WANTED = 0x00008000, /* A shutdown was requested and mux be performed ASAP (up side to down side) */ |
206 | | SC_FL_ABRT_DONE = 0x00010000, /* An abort was performed for the SC */ |
207 | | SC_FL_SHUT_DONE = 0x00020000, /* A shutdown was performed for the SC */ |
208 | | |
209 | | SC_FL_EOS = 0x00040000, /* End of stream was reached (from down side to up side) */ |
210 | | SC_FL_HAVE_BUFF = 0x00080000, /* A buffer is ready, flag will be cleared once allocated */ |
211 | | SC_FL_NO_FASTFWD = 0x00100000, /* disable data fast-forwarding */ |
212 | | }; |
213 | | |
214 | | /* This function is used to report flags in debugging tools. Please reflect |
215 | | * below any single-bit flag addition above in the same order via the |
216 | | * __APPEND_FLAG macro. The new end of the buffer is returned. |
217 | | */ |
218 | | static forceinline char *sc_show_flags(char *buf, size_t len, const char *delim, uint flg) |
219 | 0 | { |
220 | 0 | #define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__) |
221 | 0 | /* prologue */ |
222 | 0 | _(0); |
223 | 0 | /* flags */ |
224 | 0 | _(SC_FL_ISBACK, _(SC_FL_EOI, _(SC_FL_ERROR, _(SC_FL_NOLINGER, _(SC_FL_NOHALF, |
225 | 0 | _(SC_FL_DONT_WAKE, _(SC_FL_INDEP_STR, _(SC_FL_WONT_READ, |
226 | 0 | _(SC_FL_NEED_BUFF, _(SC_FL_NEED_ROOM, |
227 | 0 | _(SC_FL_RCV_ONCE, _(SC_FL_SND_ASAP, _(SC_FL_SND_NEVERWAIT, _(SC_FL_SND_EXP_MORE, |
228 | 0 | _(SC_FL_ABRT_WANTED, _(SC_FL_SHUT_WANTED, _(SC_FL_ABRT_DONE, _(SC_FL_SHUT_DONE, |
229 | 0 | _(SC_FL_EOS, _(SC_FL_HAVE_BUFF, _(SC_FL_NO_FASTFWD))))))))))))))))))))); |
230 | 0 | /* epilogue */ |
231 | 0 | _(~0U); |
232 | 0 | return buf; |
233 | 0 | #undef _ |
234 | 0 | } Unexecuted instantiation: debug.c:sc_show_flags Unexecuted instantiation: fd.c:sc_show_flags Unexecuted instantiation: haproxy.c:sc_show_flags Unexecuted instantiation: http_htx.c:sc_show_flags Unexecuted instantiation: limits.c:sc_show_flags Unexecuted instantiation: listener.c:sc_show_flags Unexecuted instantiation: log.c:sc_show_flags Unexecuted instantiation: mworker.c:sc_show_flags Unexecuted instantiation: peers.c:sc_show_flags Unexecuted instantiation: pool.c:sc_show_flags Unexecuted instantiation: proto_sockpair.c:sc_show_flags Unexecuted instantiation: proxy.c:sc_show_flags Unexecuted instantiation: resolvers.c:sc_show_flags Unexecuted instantiation: ring.c:sc_show_flags Unexecuted instantiation: sample.c:sc_show_flags Unexecuted instantiation: server.c:sc_show_flags Unexecuted instantiation: session.c:sc_show_flags Unexecuted instantiation: sink.c:sc_show_flags Unexecuted instantiation: sock.c:sc_show_flags Unexecuted instantiation: stats.c:sc_show_flags Unexecuted instantiation: stconn.c:sc_show_flags Unexecuted instantiation: stick_table.c:sc_show_flags Unexecuted instantiation: stream.c:sc_show_flags Unexecuted instantiation: tcp_rules.c:sc_show_flags Unexecuted instantiation: tcpcheck.c:sc_show_flags Unexecuted instantiation: thread.c:sc_show_flags Unexecuted instantiation: tools.c:sc_show_flags Unexecuted instantiation: trace.c:sc_show_flags Unexecuted instantiation: vars.c:sc_show_flags Unexecuted instantiation: action.c:sc_show_flags Unexecuted instantiation: activity.c:sc_show_flags Unexecuted instantiation: applet.c:sc_show_flags Unexecuted instantiation: backend.c:sc_show_flags Unexecuted instantiation: cfgparse-listen.c:sc_show_flags Unexecuted instantiation: cfgparse.c:sc_show_flags Unexecuted instantiation: channel.c:sc_show_flags Unexecuted instantiation: check.c:sc_show_flags Unexecuted instantiation: cli.c:sc_show_flags Unexecuted instantiation: connection.c:sc_show_flags Unexecuted instantiation: dns.c:sc_show_flags Unexecuted instantiation: dns_ring.c:sc_show_flags Unexecuted instantiation: errors.c:sc_show_flags Unexecuted instantiation: extcheck.c:sc_show_flags Unexecuted instantiation: filters.c:sc_show_flags Unexecuted instantiation: flt_http_comp.c:sc_show_flags Unexecuted instantiation: frontend.c:sc_show_flags Unexecuted instantiation: guid.c:sc_show_flags Unexecuted instantiation: haterm.c:sc_show_flags Unexecuted instantiation: http_ana.c:sc_show_flags Unexecuted instantiation: http_ext.c:sc_show_flags Unexecuted instantiation: http_fetch.c:sc_show_flags Unexecuted instantiation: http_rules.c:sc_show_flags Unexecuted instantiation: lb_chash.c:sc_show_flags Unexecuted instantiation: lb_fas.c:sc_show_flags Unexecuted instantiation: lb_fwlc.c:sc_show_flags Unexecuted instantiation: lb_fwrr.c:sc_show_flags Unexecuted instantiation: lb_map.c:sc_show_flags Unexecuted instantiation: lb_ss.c:sc_show_flags Unexecuted instantiation: mux_spop.c:sc_show_flags Unexecuted instantiation: pattern.c:sc_show_flags Unexecuted instantiation: payload.c:sc_show_flags Unexecuted instantiation: proto_rhttp.c:sc_show_flags Unexecuted instantiation: queue.c:sc_show_flags Unexecuted instantiation: stats-file.c:sc_show_flags Unexecuted instantiation: stats-html.c:sc_show_flags Unexecuted instantiation: stats-json.c:sc_show_flags Unexecuted instantiation: stats-proxy.c:sc_show_flags Unexecuted instantiation: cache.c:sc_show_flags Unexecuted instantiation: cfgparse-global.c:sc_show_flags Unexecuted instantiation: compression.c:sc_show_flags Unexecuted instantiation: fcgi-app.c:sc_show_flags Unexecuted instantiation: flt_spoe.c:sc_show_flags Unexecuted instantiation: proto_tcp.c:sc_show_flags |
235 | | |
236 | | /* A conn stream must have its own errors independently of the buffer's, so that |
237 | | * applications can rely on what the buffer reports while the conn stream is |
238 | | * performing some retries (eg: connection error). Some states are transient and |
239 | | * do not last beyond process_session(). |
240 | | */ |
241 | | enum sc_state { |
242 | | SC_ST_INI = 0, /* SC not sollicitated yet */ |
243 | | SC_ST_REQ, /* [transient] connection initiation desired and not started yet */ |
244 | | SC_ST_QUE, /* SC waiting in queue */ |
245 | | SC_ST_TAR, /* SC in turn-around state after failed connect attempt */ |
246 | | SC_ST_ASS, /* server just assigned to this SC */ |
247 | | SC_ST_CON, /* initiated connection request (resource exists) */ |
248 | | SC_ST_CER, /* [transient] previous connection attempt failed (resource released) */ |
249 | | SC_ST_RDY, /* [transient] ready proven after I/O success during SC_ST_CON */ |
250 | | SC_ST_EST, /* connection established (resource exists) */ |
251 | | SC_ST_DIS, /* [transient] disconnected from other side, but cleanup not done yet */ |
252 | | SC_ST_CLO, /* SC closed, might not existing anymore. Buffers shut. */ |
253 | | } __attribute__((packed)); |
254 | | |
255 | | /* state bits for use with lists of states */ |
256 | | enum sc_state_bit { |
257 | | SC_SB_NONE = 0, |
258 | | SC_SB_INI = 1U << SC_ST_INI, |
259 | | SC_SB_REQ = 1U << SC_ST_REQ, |
260 | | SC_SB_QUE = 1U << SC_ST_QUE, |
261 | | SC_SB_TAR = 1U << SC_ST_TAR, |
262 | | SC_SB_ASS = 1U << SC_ST_ASS, |
263 | | SC_SB_CON = 1U << SC_ST_CON, |
264 | | SC_SB_CER = 1U << SC_ST_CER, |
265 | | SC_SB_RDY = 1U << SC_ST_RDY, |
266 | | SC_SB_EST = 1U << SC_ST_EST, |
267 | | SC_SB_DIS = 1U << SC_ST_DIS, |
268 | | SC_SB_CLO = 1U << SC_ST_CLO, |
269 | | SC_SB_ALL = SC_SB_INI|SC_SB_REQ|SC_SB_QUE|SC_SB_TAR|SC_SB_ASS|SC_SB_CON|SC_SB_CER|SC_SB_RDY|SC_SB_EST|SC_SB_DIS|SC_SB_CLO, |
270 | | }; |
271 | | |
272 | | struct stconn; |
273 | | |
274 | | /* represent the abort code, enriched with contextual info: |
275 | | * - First 5 bits are used for the source (31 possible sources) |
276 | | * - other bits are reserved for now |
277 | | */ |
278 | 0 | #define SE_ABRT_SRC_SHIFT 0 |
279 | 0 | #define SE_ABRT_SRC_MASK 0x0000001f |
280 | | |
281 | | #define SE_ABRT_SRC_MUX_PT 0x01 /* Code set by the PT mux */ |
282 | | #define SE_ABRT_SRC_MUX_H1 0x02 /* Code set by the H1 mux */ |
283 | 0 | #define SE_ABRT_SRC_MUX_H2 0x03 /* Code set by the H2 mux */ |
284 | 0 | #define SE_ABRT_SRC_MUX_QUIC 0x04 /* Code set by the QUIC/H3 mux */ |
285 | | #define SE_ABRT_SRC_MUX_FCGI 0x05 /* Code set by the FCGI mux */ |
286 | 0 | #define SE_ABRT_SRC_MUX_SPOP 0x06 /* Code set by the SPOP mux */ |
287 | | |
288 | | struct se_abort_info { |
289 | | uint32_t info; |
290 | | uint64_t code; |
291 | | }; |
292 | | |
293 | | /* A Stream Endpoint Descriptor (sedesc) is the link between the stream |
294 | | * connector (ex. stconn) and the Stream Endpoint (mux or appctx). |
295 | | * It always exists for either of them, and binds them together. It also |
296 | | * contains some shared information relative to the endpoint. It is created by |
297 | | * the first one which needs it and is shared by the other one, i.e. on the |
298 | | * client side, it's created the mux or applet and shared with the connector. |
299 | | * An sedesc without stconn is called an ORPHANED descriptor. An sedesc with |
300 | | * no mux/applet is called a DETACHED descriptor. Upon detach, the connector |
301 | | * transfers the whole responsibility of the endpoint descriptor to the |
302 | | * endpoint itself (mux/applet) and eventually creates a new sedesc (for |
303 | | * instance on connection retries). |
304 | | * |
305 | | * <lra> should be updated when a read activity at the endpoint level is |
306 | | * detected. It can be a successful receive or when a EOS/EOI is reported. |
307 | | * A read activity is also reported when receives are unblocked. |
308 | | |
309 | | * <fsb> should be updated when the first send of a series is blocked and reset |
310 | | * when a successful send is reported. |
311 | | * |
312 | | * |
313 | | * NOTE: <lra> and <fsb> must only be used via the SC api to compute read/write |
314 | | * expiration date. |
315 | | * |
316 | | * <kip> is the known input payload length. It is set by the stream endpoint |
317 | | * that produce data and decremented once consumed by the app |
318 | | * layer. Depending on the endpoint, this value may be unset. It may be set |
319 | | * only once if the payload length is fully known from the beginning (a |
320 | | * HTTP message with a content-length for instance), or incremented |
321 | | * periodically when more data are expected (a chunk-encoded HTTP message |
322 | | * for instance). On the app side, this value is decremented when data are |
323 | | * scheduled to be forwarded to the other side and <kop> is incremented |
324 | | * accordingly. |
325 | | * |
326 | | * <kop> is the known output payload length still expected from the app |
327 | | * layer. It is set by the app layer, when data are forwarded to the |
328 | | * stream endpoint and decremented when the endpoint the value was |
329 | | * processed (for instance when a size of the next chunk is emitted). |
330 | | * |
331 | | * NOTE: <kip> and <kop> act like communicating vessels and are just used as an |
332 | | * information from the producer side to allow optimisations on the |
333 | | * consumer side. These value may be unset by the producer or just never |
334 | | * used by the consumer. When set, these values reflect the data already |
335 | | * present in the channel buffer, and those which will come soon. |
336 | | * |
337 | | */ |
338 | | struct sedesc { |
339 | | void *se; /* the stream endpoint, i.e. the mux stream or the appctx */ |
340 | | struct connection *conn; /* the connection for connection-based streams */ |
341 | | struct stconn *sc; /* the stream connector we're attached to, or NULL */ |
342 | | struct iobuf iobuf; /* contains data forwarded by the other side and that must be sent by the stream endpoint */ |
343 | | unsigned int flags; /* SE_FL_* */ |
344 | | uint32_t term_evts_log; /* Termination events log: first 4 events reported */ |
345 | | struct se_abort_info abort_info; /* Info about abort, as reported by the endpoint and eventually enriched by the app level */ |
346 | | unsigned int lra; /* the last read activity */ |
347 | | unsigned int fsb; /* the first send blocked */ |
348 | | struct xref xref; /* cross reference with the opposite SC */ |
349 | | |
350 | | unsigned long long kip; /* Known input payload length (see above) */ |
351 | | unsigned long long kop; /* Known outgoing payload length (see above) */ |
352 | | }; |
353 | | |
354 | | /* |
355 | | * This structure describes the elements of a connection relevant to a stream |
356 | | */ |
357 | | struct stconn { |
358 | | enum obj_type obj_type; /* differentiates connection from applet context */ |
359 | | enum sc_state state; /* SC_ST* */ |
360 | | /* 2 bytes hole here */ |
361 | | |
362 | | unsigned int flags; /* SC_FL_* */ |
363 | | unsigned int ioto; /* I/O activity timeout */ |
364 | | uint32_t term_evts_log; /* termination events log aggregating SE + connection events */ |
365 | | ssize_t room_needed; /* free space in the input buffer required to receive more data. |
366 | | * -1 : the SC is waiting for room but not on a specific amount of data |
367 | | * >= 0 : min free space required to progress. 0 means SC must be unblocked ASAP |
368 | | */ |
369 | | unsigned long long bytes_in; /* total number of bytes received from the SE */ |
370 | | unsigned long long bytes_out; /* total number of bytes sent to the SE */ |
371 | | |
372 | | struct wait_event wait_event; /* We're in a wait list */ |
373 | | struct sedesc *sedesc; /* points to the stream endpoint descriptor */ |
374 | | enum obj_type *app; /* points to the applicative point (stream or check) */ |
375 | | struct sockaddr_storage *src; /* source address (pool), when known, otherwise NULL */ |
376 | | struct sockaddr_storage *dst; /* destination address (pool), when known, otherwise NULL */ |
377 | | }; |
378 | | |
379 | | |
380 | | #endif /* _HAPROXY_STCONN_T_H */ |