14879 Commits

Author SHA1 Message Date
Maximilian Mader
fc0cceb08a MINOR: haproxy: Add -cc argument
This patch adds the `-cc` (check condition) argument to evaluate conditions on
startup and return the result as the exit code.

As an example this can be used to easily check HAProxy's version in scripts:

    haproxy -cc 'version_atleast(2.4)'

This resolves GitHub issue #1246.

Co-authored-by: Tim Duesterhus <tim@bastelstu.be>
2021-06-08 11:17:19 +02:00
Maximilian Mader
29c6cd7d8a CLEANUP: tools: Make errptr const in parse_line()
This change is for consistency with `cfg_eval_condition()`.
2021-06-08 10:56:10 +02:00
Tim Duesterhus
b3168b34a9 CLEANUP: cfgparse: Remove duplication of MAX_LINE_ARGS + 1
We can calculate the number of possible arguments based off the size of the
`args` array. We should do so to prevent the two values from getting out of
sync.
2021-06-08 10:54:30 +02:00
Alex
5c866200d4 DOC: use the req.ssl_sni in examples
This patch should be backported to at least 2.0
2021-06-08 10:51:39 +02:00
Amaury Denoyelle
5e560e80c7 MINOR: server: use ha_alert in server parsing functions
Replace memprintf usage in _srv_parse* functions by ha_alert calls. This
has the advantage to simplify the function prototype by removing an
extra char** argument.

As a consequence, the CLI handler of 'add server' is updated to output
the user messages buffers if not empty.
2021-06-07 17:19:33 +02:00
Amaury Denoyelle
9d0138ab08 MINOR: server: use parsing ctx for server init addr
Initialize the parsing context in srv_init_addr. This function is called
after configuration check.

This will standardize the stderr output on startup with the parse_server
function.
2021-06-07 17:19:30 +02:00
Amaury Denoyelle
e74cbc3227 REORG: config: use parsing ctx for server config check
Initialize the parsing context when checking server config validity.
Adjust the log messages to remove redundant config file/line and server
name. Do a similar cleaning in prepare_srv from ssl_sock as this
function is called at the same stage.

This will standardize the stderr output on startup with the parse_server
function.
2021-06-07 17:19:27 +02:00
Amaury Denoyelle
0fc136ce5b REORG: server: use parsing ctx for server parsing
Use the parsing context in parse_server. Remove redundant manual
format-string specifying the current file/line/server parsed.
2021-06-07 17:19:24 +02:00
Amaury Denoyelle
d0b237c713 MINOR: log: define server user message format
Define the format for user messages related to a server instance. It
contains the names of the backend and the server itself.
2021-06-07 17:19:23 +02:00
Amaury Denoyelle
111243003e MINOR: errors: specify prefix "config" for parsing output
Set "config :" as a prefix for the user messages context before starting
the configuration parsing. All following stderr output will be prefixed
by it.

As a consequence, remove extraneous prefix "config" already specified in
various ha_alert/warning/notice calls.
2021-06-07 17:19:16 +02:00
Amaury Denoyelle
da3d68111c MINOR: log: display exec path on first warning
Display process executable path on first warning if not already done in
ha_warning, as in ha_alert. The output is thus cleaner when ALERT and
WARN messages are mixed, with the executable path always on first
position.
2021-06-07 17:19:15 +02:00
Amaury Denoyelle
816281ff16 MINOR: errors: use user messages context in print_message
Prepend the user messages context to stderr output in print_message. It
is inserted between the output prefix (log level / pid) and the message
itself. Its content depends on the loaded context infos.
2021-06-07 17:19:10 +02:00
Amaury Denoyelle
6af81f80fb MEDIUM: errors: implement parsing context type
Create a parsing_ctx structure. This type is used to store information
about the current file/line parsed. A global context is created and
can be manipulated when haproxy is in STARTING mode. When starting is
over, the context is resetted and should not be accessed anymore.
2021-06-07 16:58:16 +02:00
Amaury Denoyelle
0a1cdccebd MINOR: log: do not discard stderr when starting is over
Always print message in ha_alert/warning/notice when starting is over,
regardless of quiet/verbose options.

This change is useful to retrieve the output via the newly implemented
user messages buffer at runtime, for the CLI handlers.
2021-06-07 16:58:16 +02:00
Amaury Denoyelle
1833e43c3e MEDIUM: errors: implement user messages buffer
The user messages buffer is used to store the stderr output after the
starting is over. Each thread has it own user messages buffer. Add some
functions to add a new message, retrieve and clear the content.

The user messages buffer primary goal is to be consulted by CLI
handlers. Each handlers using it must clear the buffer before starting
its operation.
2021-06-07 16:58:16 +02:00
Amaury Denoyelle
c008a63582 CLEANUP: server: fix cosmetic of error message on sni parsing
Fix memprintf used in server_parse_sni_expr. Error messages should not
be ending with a newline as it will be inserted in the parent function
on the ha_alert invocation.
2021-06-07 16:58:16 +02:00
Amaury Denoyelle
ce986e1ce8 REORG: errors: split errors reporting function from log.c
Move functions related to errors output on stderr from log.c to a newly
created errors.c file. It targets print_message and
ha_alert/warning/notice/diag functions and related startup_logs feature.
2021-06-07 16:58:15 +02:00
Amaury Denoyelle
01b3c3d4fb MINOR: errors: allow empty va_args for diag variadic macro
Use the '##' operator to allow the usage of HA_DIAG_WARNING_COND macro
without extra arguments.

This must be backported up to 2.4.
2021-06-07 16:58:15 +02:00
William Lallemand
64d6c09e54 CI: github actions: -Wno-deprecated-declarations with OpenSSL 3.0.0
Disable the deprecated functions warning when building with openssl
3.0.0 alpha. This will need to be reverted once haproxy is ported to the
new API.
2021-06-07 15:34:07 +02:00
Ilya Shipitsin
c3f28a38d2 CI: github actions: add OpenSSL-3.0.0 builds
OpenSSL-3.0.0 is getting close to its release, let us add it to build matrix
2021-06-07 15:27:35 +02:00
Tim Duesterhus
a9334df5a9 CLEANUP: reg-tests: Remove obsolete no-htx parameter for reg-tests
The legacy HTTP subsystem has been removed. HTX is always enabled.
2021-06-04 15:41:21 +02:00
Willy Tarreau
63b3ae7ca3 CLEANUP: backend: fix incorrect comments on locking conditions for lb functions
The leastconn and roundrobin functions mention that the server's lock
must be held while this is not true at all and it is not used either.
The "first" algo doesn't mention anything about the need for locking,
so let's mention that it uses the lbprm lock.
2021-06-04 15:40:50 +02:00
Christopher Faulet
3b9cb60059 REGTESTS: Fix http_abortonclose.vtc to support -1 status for some client aborts
Since the commit 5e702fcad ("MINOR: http-ana: Use -1 status for client
aborts during queuing and connect"), -1 status is reported in the log
message when the client aborts during queuing and
connect. http_abortonclose.vtc script must be update accordingly.
2021-06-02 17:23:48 +02:00
Christopher Faulet
5e702fcadc MINOR: http-ana: Use -1 status for client aborts during queuing and connect
When a client aborts while the session is in the queue or during the connect
stage, instead of reporting a 503-Service-Unavailable error in logs, -1
status is used. It means -1 status is now reported with 'CC' and 'CQ'
termination state.

Indeed, when a client aborts before the server connection is established,
there is no reason to report a 503 because nothing is sent to the
server. And in this case, because it is a client abort, it is useless to
send any response to the client. Thus -1 status is approriate. This status
is used in log messages when the connection is closed and no response is
sent.

This patch should fix the issue #1266.
2021-06-02 17:17:34 +02:00
William Lallemand
f22b032956 BUILD: fix compilation for OpenSSL-3.0.0-alpha17
Some changes in the OpenSSL syntax API broke this syntax:
  #if SSL_OP_NO_TLSv1_3

OpenSSL made this change which broke our usage in commit f04bb0bce490de847ed0482b8ec9eabedd173852:

-# define SSL_OP_NO_TLSv1_3                               (uint64_t)0x20000000
+#define SSL_OP_BIT(n)  ((uint64_t)1 << (uint64_t)n)
+# define SSL_OP_NO_TLSv1_3                               SSL_OP_BIT(29)

Which can't be evaluated by the preprocessor anymore.
This patch replace the test by an openssl version test.

This fix part of #1276 issue.
2021-06-02 16:41:50 +02:00
Christopher Faulet
bf7743094e CLEANUP: mux-fcgi: Don't needlessly store result of data/trailers parsing
Return values of fcgi_strm_parse_data() and fcgi_strm_parse_trailers() are
no longer checked. Thus it is useless to store it.

This patch should fix the issues #1269 and #1268.
2021-06-02 12:04:42 +02:00
Alexandar Lazic
528adc3b18 DOC/MINOR: move uuid in the configuration to the right alphabetical order
This patch can be backported up to 2.1 where the uuid fetch was
introduced
2021-06-02 11:57:18 +02:00
Christopher Faulet
c4439f71b0 BUG/MINOR: vars: Be sure to have a session to get checks variables
It is now possible to get any variables from the cli. Concretely, only
variables in the PROC scope can be retrieved because there is neither stream
nor session defined. But, nothing forbids anyone to try to get a variable in
any scope. No value will be found, but it is allowed. Thus, we must be sure
to not rely on an undefined session or stream in that case. Especially, the
session must be tested before retrieving variables in CHECK scope.

This patch should fix the issue #1249. It must be backported to 2.4.
2021-06-02 11:55:14 +02:00
Christopher Faulet
e9106d69cb MINOR: backend: Don't release SI endpoint anymore in connect_server()
Thanks to the previous patch (822decfd "BUG/MAJOR: stream-int: Release SI
endpoint on server side ASAP on retry"), it is now useless to release any
existing connection in connect_server() because it was already done in
back_handle_st_cer() if necessary.

This patch is not a CLEANUP because it may introduce some bugs in edge
cases. There is no reason to backport it for now except if it is required to
fix a bug.
2021-06-01 15:54:50 +02:00
Christopher Faulet
f822decfda BUG/MAJOR: stream-int: Release SI endpoint on server side ASAP on retry
When a connection attempt failed, if a retry is possible, the SI endpoint on
the server side is immediately released, instead of waiting to establish a
new connection to a server. Thus, when the backend SI is switched from
SI_ST_CER state to SI_ST_REQ, SI_ST_ASS or SI_ST_TAR, its endpoint is
released. It is expected because the SI is moved to a state prior to the
connection stage ( < SI_ST_CONN). So it seems logical to not have any server
connection.

It is especially important if the retry is delayed (SI_ST_TAR or
SI_ST_QUE). Because, if the server connection is preserved, any error at the
connection level is unexpectedly relayed to the stream, via the
stream-interface, leading to an infinite loop in process_stream(). if
SI_FL_ERR flag is set on the backend SI in another state than SI_ST_CLO, an
internal goto is performed to resync the stream-interfaces. In addtition,
some ressources are not released ASAP.

This bug is quite old and was reported 1 or 2 times per years since the 2.2
(at least) with not enough information to catch it. It must be backported as
far as 2.2 with a special care because this part has moved several times and
after some observation period and feedback from users to be sure. For info,
in 2.0 and prior, the connection is released when an error is encountered in
SI_ST_CON or SI_ST_RDY states.
2021-06-01 15:53:54 +02:00
Christopher Faulet
1a4449b0d0 CLEANUP: http-ana: Remove useless if statement about L7 retries
Thanks to the commit 1f08bffe0 ("MINOR: http-ana: Perform L7 retries because
of status codes in response analyser"), the L7 retries about the response
status code is now fully handled in the HTTP response analyser.
CF_READ_ERROR flag is no longer set on the response channel in this
case. Thus it is useless to try to catch L7 retries when CF_READ_ERROR is
set because it cannot happen.

The above commit was backported to 2.4, thus this one should also be
backported.
2021-05-31 11:45:26 +02:00
Remi Tricot-Le Breton
476462010e BUG/MINOR: proxy: Missing calloc return value check in chash_init_server_tree
A memory allocation failure happening in chash_init_server_tree while
trying to allocate a server's lb_nodes item used in consistent hashing
would have resulted in a crash. This function is only called during
configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:55:51 +02:00
Remi Tricot-Le Breton
17acbab0ac BUG/MINOR: http: Missing calloc return value check in make_arg_list
A memory allocation failure happening in make_arg_list when trying to
allocate the argument list would have resulted in a crash. This function
is only called during configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:09 +02:00
Remi Tricot-Le Breton
b6864a5b6f BUG/MINOR: http: Missing calloc return value check while parsing redirect rule
A memory allocation failure happening in http_parse_redirect_rule when
trying to allocate a redirect_rule structure would have resulted in a
crash. This function is only called during configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:08 +02:00
Remi Tricot-Le Breton
1f4fa906c7 BUG/MINOR: worker: Missing calloc return value check in mworker_env_to_proc_list
A memory allocation failure happening in mworker_env_to_proc_list when
trying to allocate a mworker_proc would have resulted in a crash. This
function is only called during init.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:06 +02:00
Remi Tricot-Le Breton
6443bcc2e1 BUG/MINOR: compression: Missing calloc return value check in comp_append_type/algo
A memory allocation failure happening in comp_append_type or
comp_append_algo called while parsing compression options would have
resulted in a crash. These functions are only called during
configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:04 +02:00
Remi Tricot-Le Breton
8cb033643f BUG/MINOR: http: Missing calloc return value check while parsing tcp-request rule
A memory allocation failure happening in tcp_parse_request_rule while
processing the "capture" keyword and trying to allocate a cap_hdr
structure would have resulted in a crash. This function is only called
during configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:02 +02:00
Remi Tricot-Le Breton
2ca42b4656 BUG/MINOR: http: Missing calloc return value check while parsing tcp-request/tcp-response
A memory allocation failure happening in tcp_parse_tcp_req or
tcp_parse_tcp_rep when trying to allocate an act_rule structure would
have resulted in a crash. These functions are only called during
configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:51:00 +02:00
Remi Tricot-Le Breton
18a82ba690 BUG/MINOR: proxy: Missing calloc return value check in proxy_defproxy_cpy
A memory allocation failure happening in proxy_defproxy_cpy while
copying the default compression options would have resulted in a crash.
This function is called for every new proxy found while parsing the
configuration.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:50:59 +02:00
Remi Tricot-Le Breton
55ba0d6865 BUG/MINOR: proxy: Missing calloc return value check in proxy_parse_declare
A memory allocation failure happening during proxy_parse_declare while
processing the "capture" keyword and allocating a cap_hdr structure
would have resulted in a crash. This function is only called during
configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:50:57 +02:00
Remi Tricot-Le Breton
a4bf8a059d BUG/MINOR: http: Missing calloc return value check in parse_http_req_capture
A memory allocation failure happening in parse_http_req_capture while
processing a "len" keyword and allocating a cap_hdr structure would
have resulted in a crash. This function is only called during
configuration parsing.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:50:55 +02:00
Remi Tricot-Le Breton
612b2c37be BUG/MINOR: ssl: Missing calloc return value check in ssl_init_single_engine
A memory allocation failure happening during ssl_init_single_engine
would have resulted in a crash. This function is only called during
init.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:50:49 +02:00
Remi Tricot-Le Breton
208ff01b23 BUG/MINOR: peers: Missing calloc return value check in peers_register_table
A memory allocation failure happening during peers_register_table would
have resulted in a crash. This function is only called during init.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.
2021-05-31 10:50:46 +02:00
Remi Tricot-Le Breton
f1800e64ef BUG/MINOR: server: Missing calloc return value check in srv_parse_source
Two calloc calls were not checked in the srv_parse_source function.
Considering that this function could be called at runtime through a
dynamic server creation via the CLI, this could lead to an unfortunate
crash.

It was raised in GitHub issue #1233.
It could be backported to all stable branches even though the runtime
crash could only happen on branches where dynamic server creation is
possible.
2021-05-31 10:50:32 +02:00
Mark Mullan
e1ecfdda81 DOC: intro: Fix typo in starter guide
s/sned/send.
2021-05-27 08:26:43 +02:00
Tim Duesterhus
5546c8bdce MINOR: cfgparse: Fail when encountering extra arguments in macro
This resolves GitHub issue #1124.

This change should be backported as a *warning* to 2.4.
2021-05-27 07:54:21 +02:00
Christopher Faulet
1f08bffe0c MINOR: http-ana: Perform L7 retries because of status codes in response analyser
L7 retries because of status codes are now performed in the response
analyser. This way, it is no longer required to handle L7 retries in
si_cs_recv(). It is also useless to set CF_READ_ERROR on the response
channel to be able to trigger such retries.

In addition, if no L7 retries are performed when the response is received,
the L7 buffer is immediately released. Before in this case, it was only
released with the stream.
2021-05-26 13:56:06 +02:00
Christopher Faulet
d976923ab2 BUG/MINOR: http-ana: Handle L7 retries on refused early data before K/A aborts
When a network error occurred on the server side, if it is not the first
request (in case of keep-alive), nothing is returned to the client and its
connexion is closed to be sure it may retry. However L7 retries on refused
early data (0rtt-rejected) must be performed first.

In addition, such L7 retries must also be performed before incrementing the
failed responses counter.

This patch must be backported as far as 2.0.
2021-05-26 13:56:06 +02:00
Christopher Faulet
552601d5fd BUG/MINOR: http-ana: Send the right error if max retries is reached on L7 retry
This bug was introduced by the previous commit (9f5382e45 Revert "MEDIUM:
http-ana: Deal with L7 retries in HTTP analysers") because I failed the
revert.

On L7 retry, if the maximum connection retries is reached, an error must be
return to the client. Depending the situation, it may be a 502-Bad-Gateway
(empty-response or junk-response), a 504-Gateway-Timeout (response-timeout)
or a 425-Too-Early (0rtt-rejected). But contrary to what the comment says,
the do_l7_retry() function always returns a success.

Note it is not a problem for L7 retries on the response status code because
the stream-interface already takes care to have not reached the maximum
connection retries counter to trigger a L7 retry.

This patch must be backported to 2.4 because the commit must also be
backported to 2.4.
2021-05-26 10:31:11 +02:00
Christopher Faulet
9f5382e452 Revert "MEDIUM: http-ana: Deal with L7 retries in HTTP analysers"
This reverts commit 5b82cc5b5c350c7cfa194cc6bc16ad9308784541. The purpose of
this commit was to fully handle L7 retries in HTTP analysers and stop to
deal with the L7 buffer in si_cs_send()/si_cs_recv(). It is of course
cleaner this way. But there is a huge drawback. The L7 buffer is reserved
from the time the request analysis is finished until the moment the response
is received. For a small request, the analysis is finished before the
connection to the server. Thus for the L7 buffer will be kept for queued
sessions while it is not mandatory.

So, for now, the commit is reverted to go back to the less expensive
solution. This patch must be backported to 2.4.
2021-05-25 10:51:20 +02:00