Commit Graph

17143 Commits

Author SHA1 Message Date
Amaury Denoyelle
05d4ae6436 BUG/MINOR: quic: fix return value for error in start
Fix the return value used in quic-conn start callback for error. The
caller expects a negative value in this case.

Without this patch, the quic-conn and the connection stack are not
closed despite an initialization failure error, which is an undefined
behavior and may cause a crash in the end.
2022-04-14 15:08:16 +02:00
Amaury Denoyelle
622ec4166b BUG/MINOR: quic-sock: do not double free session on conn init failure
In the quic_session_accept, connection is in charge to call the
quic-conn start callback. If this callback fails for whatever reason,
there is a crash because of an explicit session_free.

This happens because the connection is now the owner of the session due
to previous conn_complete_session call. It will automatically calls
session_free. Fix this by skipping the session_free explicit invocation
on error.

In practice, currently this has never happened as there is only limited
cases of failures for conn_xprt_start for QUIC.
2022-04-14 14:50:12 +02:00
Amaury Denoyelle
2461bd534a BUG/MINOR: mux-quic: prevent a crash in session_free on mux.destroy
Implement qc_destroy. This callback is used to quickly release all MUX
resources.

session_free uses this callback. Currently, it can only be called if
there was an error during connection initialization. If not defined, the
process crashes.
2022-04-14 14:50:12 +02:00
Christopher Faulet
67df95a8a2 BUILD: http-client: Avoid dead code when compiled without SSL support
When an HTTP client is started on an HAProxy compiled without the SSL
support, an error is triggered when HTTPS is used. In this case, the freshly
created conn-stream is released. But this code is specific to the non-SSL
part. Thus it is moved the in right #if/#else section.

This patch should fix the issue #1655.
2022-04-14 12:02:35 +02:00
Christopher Faulet
ae660be547 BUG/MEDIUM: mux-h1: Don't request more room on partial trailers
The commit 744451c7c ("BUG/MEDIUM: mux-h1: Properly detect full buffer cases
during message parsing") introduced a regression if trailers are not
received in one time. Indeed, in this case, nothing is appended in the
channel buffer, while there are some data in the input buffer. In this case,
we must not request more room to the upper layer, especially because the
channel buffer can be empty.

To fix the issue, on trailers parsing, we consider the H1 stream as
congested when the max size allowed is reached. Of course, the H1 stream is
also considered as congested if the trailers are too big and the channel
buffer is not empty.

This patch should fix the issue #1657. It must be backported as far as 2.0.
2022-04-14 11:57:06 +02:00
Christopher Faulet
cea05437c0 MINOR: conn-stream: Use unsafe functions to get conn/appctx in cs_detach_endp
There is no reason to rely on safe functions here. This patch should fix the
issue #1656.
2022-04-14 11:57:06 +02:00
Christopher Faulet
4de1bff866 MINOR: muxes: Don't expect to call release function with no mux defined
For all muxes, the function responsible to release a mux is always called
with a defined mux. Thus there is no reason to test if it is defined or not.

Note the patch may seem huge but it is just because of indentation changes.
2022-04-14 11:57:06 +02:00
Christopher Faulet
4e61096e30 MINOR: muxes: Don't handle proto upgrade for muxes not supporting it
Several muxes (h2, fcgi, quic) don't support the protocol upgrade. For these
muxes, there is no reason to have code to support it. Thus in the destroy
callback, there is now a BUG_ON() and the release function is simplified
because the connection is always owned by the mux..
2022-04-14 11:57:06 +02:00
Christopher Faulet
7c452ccbff MINOR: muxes: Don't expect to have a mux without connection in destroy callback
Once a mux initialized, the underlying connection alwaus exists from its
point of view and it is never removed until the mux is released. It may be
owned by another mux during an upgrade. But the pointer remains set. Thus
there is no reason to test it in the destroy callback function.

This patch should fix the issue #1652.
2022-04-14 11:57:05 +02:00
Willy Tarreau
86b08a3e3e BUG/MINOR: mux-h2: use timeout http-request as a fallback for http-keep-alive
The doc states that timeout http-keep-alive is not set, timeout http-request
is used instead. As implemented in commit  15a4733d5 ("BUG/MEDIUM: mux-h2:
make use of http-request and keep-alive timeouts"), we use http-keep-alive
unconditionally between requests, with a fallback on client/server. Let's
make sure http-request is always used as a fallback for http-keep-alive
first.

This needs to be backported wherever the commit above is backported.

Thanks to Christian Ruppert for spotting this.
2022-04-14 11:45:36 +02:00
Willy Tarreau
6ff91e2023 BUG/MINOR: mux-h2: do not use timeout http-keep-alive on backend side
Commit 15a4733d5 ("BUG/MEDIUM: mux-h2: make use of http-request and
keep-alive timeouts") omitted to check the side of the connection, and
as a side effect, automatically enabled timeouts on idle backend
connections, which is totally contrary to the principle that they
must be autonomous.

This needs to be backported wherever the patch above is backported.
2022-04-14 11:43:35 +02:00
Willy Tarreau
2a06e248f5 BUILD: initcall: mark the __start_i_* symbols as weak, not global
Just like for previous fix, these symbols are marked ".globl" during
their declaration, but their later mention uses __attribute__((weak)),
so it's better to only use ".weak" during the declaration so that the
symbol's class does not change.

No need to backport this unless someone reports build issues.
2022-04-13 19:13:49 +02:00
Willy Tarreau
b12966af10 BUILD: debug: mark the __start_mem_stats/__stop_mem_stats symbols as weak
Building with clang and DEBUG_MEM_STATS shows the following warnings:

  warning: __start_mem_stats changed binding to STB_WEAK [-Wsource-mgr]
  warning: __stop_mem_stats changed binding to STB_WEAK [-Wsource-mgr]

The reason is that the symbols are declared using ".globl" while they
are also referenced as __attribute__((weak)) elsewhere. It turns out
that a weak symbol is implicitly a global one and that the two classes
are exclusive, thus it may confuse the linker. Better fix this.

This may be backported where the patch applies.
2022-04-13 19:13:49 +02:00
Frédéric Lécaille
bc964bd1ae BUG/MINOR: quic: Avoid starting the mux if no ALPN sent by the client
If the client does not sent an ALPN, the SSL ALPN negotiation callback
is not called. However, the handshake is reported as successful. Check
just after SSL_do_handshake if an ALPN was negotiated. If not, emit a
CONNECTION_CLOSE with a TLS alert to close the connection.

This prevent a crash in qcc_install_app_ops() called with null as second
parameter value.
2022-04-13 16:48:43 +02:00
Christopher Faulet
186354beac MINOR: mux-h1: Rely on the endpoint instead of the conn-stream when possible
Instead of testing if a conn-stream exists or not, we rely on CS_EP_ORPHAN
endpoint flag. In addition, if possible, we access the endpoint from the
h1s. Finally, the endpoint flags are now reported in trace messages.
2022-04-13 15:10:16 +02:00
Christopher Faulet
22050e0a2c MINOR: muxes: Improve show_fd callbacks to dump endpoint flags
H1, H2 and FCGI multiplexers define a show_fd callback to dump some internal
info. The stream endpoint and its flags are now dumped if it exists.
2022-04-13 15:10:16 +02:00
Christopher Faulet
1336ccffab CLEANUP: conn-stream: rename cs_register_applet() to cs_applet_create()
cs_register_applet() was not a good name because it suggests it happens
during startup, just like any other registration mechanisms..
2022-04-13 15:10:16 +02:00
Christopher Faulet
aa69d8fa1c MINOR: conn-stream: Use a dedicated function to conditionally remove a CS
cs_free_cond() must now be used to remove a CS. cs_free() may be used on
error path to release a freshly allocated but unused CS. But in all other
cases cs_free_cond() must be used. This function takes care to release the
CS if it is possible (no app and detached from any endpoint).

In fact, this function is only used internally. From the outside,
cs_detach_* functions are used.
2022-04-13 15:10:16 +02:00
Christopher Faulet
a97ccedf6f CLEANUP: muxes: Remove MX_FL_CLEAN_ABRT flag
This flag is unused. Thus, it may be removed. No reason to still set it. It
also cleans up "haproxy -vv" output.
2022-04-13 15:10:16 +02:00
Christopher Faulet
177a0e60ee MEDIUM: check: Use a new conn-stream for each health-check run
It is a partial revert of 54e85cbfc ("MAJOR: check: Use a persistent
conn-stream for health-checks"). But with the CS refactoring, the result is
cleaner now. A CS is allocated when a new health-check run is started. The
same CS is then used throughout the run. If there are several connections,
the endpoint is just reset. At the end of the run, the CS is released. It
means, in the tcp-check part, the CS is always defined.
2022-04-13 15:10:16 +02:00
Christopher Faulet
9ed7742673 DOC: conn-stream: Add comments on functions of the new CS api
With the conn-stream refactoring, new functions were added. This patch adds
missing comments to help devs to use them.
2022-04-13 15:10:16 +02:00
Christopher Faulet
265e165d82 CLEANUP: conn-stream: Don't export internal functions
cs_new() and cs_attach_app() are only used internally. Thus, there is no
reason to export them.
2022-04-13 15:10:16 +02:00
Christopher Faulet
6b0a0fb2f9 CLEANUP: tree-wide: Remove any ref to stream-interfaces
Stream-interfaces are gone. Corresponding files can be safely be removed. In
addition, comments are updated accordingly.
2022-04-13 15:10:16 +02:00
Christopher Faulet
09b3c5559e DEV: flags: No longer dump SI flags
stream-interface API is no longer used. And there is no more SI flags. Thus,
the stream-interface's flags are no longer dumped by "flags" tool.
2022-04-13 15:10:16 +02:00
Christopher Faulet
582a226a2c MINOR: conn-stream: Remove the stream-interface from the conn-stream
The stream-interface API is no longer used. Thus, it is removed from the
conn-stream. From now, stream-interfaces are now longer used !
2022-04-13 15:10:16 +02:00
Christopher Faulet
c77ceb6ad1 MEDIUM: stream: Don't use the stream-int anymore in process_stream()
process_stream() and all associated functions now manipulate conn-streams.
stream-interfaces are no longer used. In addition, function to dump info
about a stream no longer print info about stream-interfaces.
2022-04-13 15:10:16 +02:00
Christopher Faulet
7739799ab4 MINOR: http-ana: Use CS to perform L7 retries
do_l7_retry function now manipulated a conn-stream instead of a
stream-interface.
2022-04-13 15:10:16 +02:00
Christopher Faulet
0eb32c0dd1 MINOR: stream: Use conn-stream to report server error
the stream's srv_error callback function now manipulates a conn-stream
instead of a stream-interface.
2022-04-13 15:10:16 +02:00
Christopher Faulet
1d03e6e3a1 REORG: stream-int/conn-stream: Move remaining functions to conn-stream
functions to get or set blocking flags on a conn-stream are moved to
conn_stream.h.
2022-04-13 15:10:15 +02:00
Christopher Faulet
5e29b76ea6 MEDIUM: stream-int/conn-stream: Move I/O functions to conn-stream
cs_conn_io_cb(), cs_conn_sync_recv() and cs_conn_sync_send() are moved in
conn_stream.c. Associated functions are moved too (cs_notify, cs_conn_read0,
cs_conn_recv, cs_conn_send and cs_conn_process).
2022-04-13 15:10:15 +02:00
Christopher Faulet
a0bdec350f MEDIUM: stream-int/conn-stream: Move blocking flags from SI to CS
Remaining flags and associated functions are move in the conn-stream
scope. These flags are added on the endpoint and not the conn-stream
itself. This way it will be possible to get them from the mux or the
applet. The functions to get or set these flags are renamed accordingly with
the "cs_" prefix and updated to manipualte a conn-stream instead of a
stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
ba92787d13 CLEANUP: stream-int: Remove unused SI functions
Some stream-interface's functions are now unused and can safely be removed.
2022-04-13 15:10:15 +02:00
Christopher Faulet
8f45eec016 MINOR: stream-int/conn-stream: Move si_alloc_ibuf() in the conn-stream scope
si_alloc_ibuf() is renamed as c_alloc_ibuf() and update to manipulate a
conn-stream instead of a stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
158f33615d MINOR: stream-int/conn-stream Move si_is_conn_error() in the conn-stream scope
si_is_conn_error() is renamed as cs_is_conn_erro() and updated to manipulate
a conn-stream instead of a stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
000ba3e613 MINOR: conn-stream: Move si_conn_cb in the conn-stream scope
si_conn_cb variable is renamed cs_data_conn_cb. In addtion, its associated
functions are also renamed. si_cs_recv(), si_cs_send() and si_cs_process() are
renamed cs_conn_recv(), cs_conn_send and cs_conn_process(). These functions are
updated to manipulate conn-streams instead of stream-interfaces.
2022-04-13 15:10:15 +02:00
Christopher Faulet
431ce2e3c1 MINOR: stream-int/conn-stream: Move si_sync_recv/send() in conn-stream scope
si_sync_recv() and si_sync_send() are renamesd cs_conn_recv() and
cs_conn_send() and updated to manipulate conn-streams instead of
stream-interfaces.
2022-04-13 15:10:15 +02:00
Christopher Faulet
4a7764ae9d MINOR: stream-int/conn-stream: Move si_cs_io_cb() in the conn-stream scope
si_cs_io_cb() is renamed cs_conn_io_cb(). In addition, the context of the
tasklet used to wake-up the conn-stream is now a conn-stream.
2022-04-13 15:10:15 +02:00
Christopher Faulet
9029a72899 MINOR: stream-int/conn-stream: Move stream_int_notify() in the conn-stream scope
stream_int_notify() is renamed cs_notify() and is updated to manipulate a
conn-stream instead of a stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
d715d36200 MINOR: stream-int/conn-stream: Move stream_int_read0() in the conn-stream scope
stream_int_read0() is renamed cs_conn_read0() and is updated to manipulate a
conn-stream instead of a stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
6059ba4acc MEDIUM: conn-stream/applet: Add a data callback for applets
data callbacks were only used for streams attached to a connection and
for health-checks. However there is a callback used by task_run_applet. So,
si_applet_wake_cb() is first renamed to cs_applet_process() and it is
defined as the data callback for streams attached to an applet. This way,
this part now manipulates a conn-stream instead of a stream-interface. In
addition, applets are no longer handled as an exception for this part.
2022-04-13 15:10:15 +02:00
Christopher Faulet
ef285c18f2 MINOR: stream-int/stream: Move si_update_both in stream scope
si_update_both() is renamed stream_update_both_cs() and moved in stream.c.
The function is slightly changed to manipulate the stream instead the front
and back conn-streams.
2022-04-13 15:10:15 +02:00
Christopher Faulet
13045f0eae MINOR: stream-int-conn-stream: Move si_update_* in conn-stream scope
si_update_rx(), si_update_tx() and si_update() are renamed cs_update_rx(),
cs_upate_tx() and cs_update() and updated to manipulate a conn-stream
instead of a stream-interface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
9ffddd5ca5 REORG: conn-stream: Move cs_app_ops in conn_stream.c
Callback functions to perform shutdown for reads and writes and to trigger
I/O calls are now moved in conn_stream.c.
2022-04-13 15:10:15 +02:00
Christopher Faulet
19bd728642 REORG: conn-stream: Move cs_shut* and cs_chk* in cs_utils
cs_shutr(), cs_shutw(), cs_chk_rcv() and cs_chk_snd() are moved in
cs_utils.h
2022-04-13 15:10:15 +02:00
Christopher Faulet
dde33046bd REORG: stream-int: Move si_is_conn_error() in the header file
To ease next changes, this function is moved in the header file. It is a
transient commit.
2022-04-13 15:10:15 +02:00
Christopher Faulet
9b7a9b400d REORG: stream-int: Export si_cs_recv(), si_cs_send() and si_cs_process()
It is a transient commit. It should ease next changes about the conn-stream
refactoring. At the end these functions will be moved in the conn-stream
scope.
2022-04-13 15:10:15 +02:00
Christopher Faulet
aa91d6292b MINOR: stream-int/connection: Move conn_si_send_proxy() in the connection scope
conn_si_send_proxy() function is renamed conn_send_proxy() and moved in
connection.c
2022-04-13 15:10:15 +02:00
Christopher Faulet
64b8d33577 MINOR: connection: unconst mux's get_fist_cs() callback function
This change is mandatory for next commits.
2022-04-13 15:10:15 +02:00
Christopher Faulet
3704663e5f MINOR: applet: Use the CS to register and release applets instead of SI
si_register_applet() and si_applet_release() are renamed
cs_register_applet() and cs_applet_release() and now manipulate a
conn-stream instead of a stream-inteface.
2022-04-13 15:10:15 +02:00
Christopher Faulet
0c6a64cd5f MEDIUM: stream-int/conn-stream: Move si_ops in the conn-stream scope
The si_ops structure is renamed to cs_app_ops and the callback functions are
changed to manipulate a conn-stream instead of a stream-interface..
2022-04-13 15:10:15 +02:00