]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
4 years agoMINOR: ssl: add ssl_{c,s}_chain_der fetch methods
William Dauchy [Thu, 6 Aug 2020 16:11:38 +0000 (18:11 +0200)] 
MINOR: ssl: add ssl_{c,s}_chain_der fetch methods

Following work from Arjen and Mathilde, it adds ssl_{c,s}_chain_der
methods; it returns DER encoded certs from SSL_get_peer_cert_chain

Also update existing vtc tests to add random intermediate certificates

When getting the result through this header:
  http-response add-header x-ssl-chain-der %[ssl_c_chain_der,hex]
One can parse it with any lib accepting ASN.1 DER data, such as in go:
  bin, err := encoding/hex.DecodeString(cert)
  certs_parsed, err := x509.ParseCertificates(bin)

Cc: Arjen Nienhuis <arjen@zorgdoc.nl>
Signed-off-by: Mathilde Gilles <m.gilles@criteo.com>
Signed-off-by: William Dauchy <w.dauchy@criteo.com>
4 years agoCLEANUP: ssl: ssl_sock_crt2der semicolon and spaces
William Dauchy [Thu, 6 Aug 2020 16:11:37 +0000 (18:11 +0200)] 
CLEANUP: ssl: ssl_sock_crt2der semicolon and spaces

trivial commit, does not change the code behaviour

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
4 years agoBUG/MINOR: snapshots: leak of snapshots on deinit()
William Lallemand [Fri, 7 Aug 2020 12:48:37 +0000 (14:48 +0200)] 
BUG/MINOR: snapshots: leak of snapshots on deinit()

Free the snapshots on deinit() when they were initialized in a proxy
upon an error.

This was introduced by c55015e ("MEDIUM: snapshots: dynamically allocate
the snapshots").

Should be backported as far as 1.9.

4 years agoMINOR: arg: Use chunk_destroy() to release string arguments
Christopher Faulet [Fri, 7 Aug 2020 09:45:18 +0000 (11:45 +0200)] 
MINOR: arg: Use chunk_destroy() to release string arguments

This way, all fields of the buffer structure are reset when a string argument
(ARGT_STR) is released.  It is also a good way to explicitly specify this kind
of argument is a chunk. So .data and .size fields must be set.

This patch may be backported to ease backports.

4 years agoMINOR: lua: Add support for regex as fetches and converters arguments
Christopher Faulet [Thu, 6 Aug 2020 09:10:57 +0000 (11:10 +0200)] 
MINOR: lua: Add support for regex as fetches and converters arguments

It means now regsub() converter is now exported to the lua. Map converters based
on regex are not available because the map arguments are not supported.

4 years agoMINOR: lua: Add support for userlist as fetches and converters arguments
Christopher Faulet [Thu, 6 Aug 2020 09:04:46 +0000 (11:04 +0200)] 
MINOR: lua: Add support for userlist as fetches and converters arguments

It means now http_auth() and http_auth_group() sample fetches are now exported
to the lua.

4 years agoMEDIUM: lua: Don't filter exported fetches and converters
Christopher Faulet [Thu, 6 Aug 2020 08:32:28 +0000 (10:32 +0200)] 
MEDIUM: lua: Don't filter exported fetches and converters

Thanks to previous commits, it is now safe to use from lua the sample fetches
and sample converters that convert arguments, especially the strings
(ARGT_STR). So now, there are all exported to the lua. They was filtered on the
validation functions. Only fetches without validation functions or with val_hdr
or val_payload_lv functions were exported, and converters without validation
functions.

This patch depends on following commits :

  * aec27ef44 "BUG/MINOR: lua: Duplicate lua strings in sample fetches/converters arg array"
  * fdea1b631 "MINOR: hlua: Don't needlessly copy lua strings in trash during args validation"

It must be backported as far as 2.1 because the date() and http_date()
converters are no longer exported because of the filter on the validation
function, since the commit ae6f125c7 ("MINOR: sample: add us/ms support to
date/http_date)".

4 years agoBUG/MINOR: lua: Duplicate lua strings in sample fetches/converters arg array
Christopher Faulet [Thu, 6 Aug 2020 06:54:25 +0000 (08:54 +0200)] 
BUG/MINOR: lua: Duplicate lua strings in sample fetches/converters arg array

Strings in the argument array used by sample fetches and converters must be
duplicated. This is mandatory because, during the arguments validations, these
strings may be converted and released. It works this way during the
configuration parsing and there is no reason to adapt this behavior during the
runtime when a sample fetch or a sample converter is called from the lua. In
fact, there is a reason to not change the behavior. It must reamain simple for
everyone to add new fetches or converters.

Thus, lua strings are duplicated. It is only performed at the end of the
hlua_lua2arg_check() function, if the argument is still a ARGT_STR. Of course,
it requires a cleanup loop after the call or when an error is triggered.

This patch depends on following commits:

  * 959171376 "BUG/MINOR: arg: Fix leaks during arguments validation for fetches/converters"
  * fdea1b631 "MINOR: hlua: Don't needlessly copy lua strings in trash during args validation"

It may be backported to all supported versions, most probably as far as 2.1
only.

4 years agoMINOR: hlua: Don't needlessly copy lua strings in trash during args validation
Christopher Faulet [Thu, 6 Aug 2020 06:29:18 +0000 (08:29 +0200)] 
MINOR: hlua: Don't needlessly copy lua strings in trash during args validation

Lua strings are NULL terminated. So in the hlua_lua2arg_check() function, used
to check arguments against the sample fetches specification, there is no reason
to copy these strings in a trash to add a terminating null byte.

In addition, when the array of arguments is built from lua values, we must take
care to count this terminating null bytes in the size of the buffer where a
string is stored. The same must be done when a sample is built from a lua value.

This patch may be backported to easy backports.

4 years agoBUG/MINOR: lua: Check argument type to convert it to IP mask in arg validation
Christopher Faulet [Fri, 7 Aug 2020 07:11:22 +0000 (09:11 +0200)] 
BUG/MINOR: lua: Check argument type to convert it to IP mask in arg validation

In hlua_lua2arg_check() function, before converting an argument to an IPv4 or
IPv6 mask, we must be sure to have an integer or a string argument (ARGT_SINT or
ARGT_STR).

This patch must be backported to all supported versions.

4 years agoBUG/MINOR: lua: Check argument type to convert it to IPv4/IPv6 arg validation
Christopher Faulet [Fri, 7 Aug 2020 07:07:26 +0000 (09:07 +0200)] 
BUG/MINOR: lua: Check argument type to convert it to IPv4/IPv6 arg validation

In hlua_lua2arg_check() function, before converting a string to an IP address,
we must be to sure to have a string argument (ARGT_STR).

This patch must be backported to all supported versions.

4 years agoBUG/MINOR: arg: Fix leaks during arguments validation for fetches/converters
Christopher Faulet [Wed, 5 Aug 2020 21:07:07 +0000 (23:07 +0200)] 
BUG/MINOR: arg: Fix leaks during arguments validation for fetches/converters

Some sample fetches or sample converters uses a validation functions for their
arguments. In these function, string arguments (ARGT_STR) may be converted to
another type (for instance a regex, a variable or a integer). Because these
strings are allocated when the argument list is built, they must be freed after
a conversion. Most of time, it is done. But not always. This patch fixes these
minor memory leaks (only on few strings, during the configuration parsing).

This patch may be backported to all supported versions, most probably as far as
2.1 only. If this commit is backported, the previous one 73292e9e6 ("BUG/MINOR:
lua: Duplicate map name to load it when a new Map object is created") must also
be backported. Note that some validation functions does not exists on old
version. It should be easy to resolve conflicts.

4 years agoBUG/MINOR: lua: Duplicate map name to load it when a new Map object is created
Christopher Faulet [Thu, 6 Aug 2020 06:40:09 +0000 (08:40 +0200)] 
BUG/MINOR: lua: Duplicate map name to load it when a new Map object is created

When a new map is created, the sample_load_map() function is called. To do so,
an argument array is created with the name as first argument. Because it is a
lua string, owned by the lua, it must be duplicated. The sample_load_map()
function will convert this argument to a map. In theory, after the conversion,
it must release the original string. It is not performed for now and it is a bug
that will be fixed in the next commit.

This patch may be backported to all supported versions, most probably as far as
2.1 only. But it must be backported with the next commit "BUG/MINOR: arg: Fix
leaks during arguments validation for fetches/converters".

4 years agoBUG/MINOR: converters: Store the sink in an arg pointer for debug() converter
Christopher Faulet [Fri, 7 Aug 2020 12:00:23 +0000 (14:00 +0200)] 
BUG/MINOR: converters: Store the sink in an arg pointer for debug() converter

The debug() converter uses a string to reference the sink where to send debug
events. During the configuration parsing, this string is converted to a sink
object but it is still store as a string argument. It is a problem on deinit
because string arguments are released. So the sink pointer will be released
twice.

To fix the bug, we keep a reference on the sink using an ARGT_PTR argument. This
way, it will not be freed on the deinit.

This patch depends on the commit e02fc4d0d ("MINOR: arg: Add an argument type to
keep a reference on opaque data"). Both must be backported as far as 2.1.

4 years agoMINOR: arg: Add an argument type to keep a reference on opaque data
Christopher Faulet [Fri, 7 Aug 2020 11:56:00 +0000 (13:56 +0200)] 
MINOR: arg: Add an argument type to keep a reference on opaque data

The ARGT_PTR argument type may now be used to keep a reference to opaque data in
the argument array used by sample fetches and converters. It is a generic way to
point on data. I guess it could be used for some other arguments, like proxy,
server, map or stick-table.

4 years agoBUG/MEDIUM: map/lua: Return an error if a map is loaded during runtime
Christopher Faulet [Wed, 5 Aug 2020 21:23:37 +0000 (23:23 +0200)] 
BUG/MEDIUM: map/lua: Return an error if a map is loaded during runtime

In sample_load_map() function, the global mode is now tested to be sure to be in
the starting mode. If not, an error is returned.

At first glance, this patch may seem useless because maps are loaded during the
configuration parsing. But in fact, it is possible to load a map from the lua,
using Map:new() method. And, there is nothing to forbid to call this method at
runtime, during a script execution. It must never be done because it may perform
an filesystem access for unknown maps or allocation for known ones. So at
runtime, it means a blocking call or a memroy leak. Note it is still possible to
load a map from the lua, but in the global part of a script only. This part is
executed during the configuration parsing.

This patch must be backported in all stable versions.

4 years agoBUG/MEDIUM: ssl: memory leak of ocsp data at SSL_CTX_free()
William Lallemand [Tue, 4 Aug 2020 15:41:39 +0000 (17:41 +0200)] 
BUG/MEDIUM: ssl: memory leak of ocsp data at SSL_CTX_free()

This bug affects all version of HAProxy since the OCSP data is not free
in the deinit(), but leaking on exit() is not really an issue. However,
when doing dynamic update of certificates over the CLI, those data are
not free'd upon the free of the SSL_CTX.

3 leaks are happening, the first leak is the one of the ocsp_arg
structure which serves the purpose of containing the pointers in the
case of a multi-certificate bundle. The second leak is the one ocsp
struct. And the third leak is the one of the struct buffer in the
ocsp_struct.

The problem lies with SSL_CTX_set_tlsext_status_arg() which does not
provide a way to free the argument upon an SSL_CTX_free().

This fix uses ex index functions instead of registering a
tlsext_status_arg(). This is really convenient because it allows to
register a free callback which will free the ex index content upon a
SSL_CTX_free().

A refcount was also added to the ocsp_response structure since it is
stored in a tree and can be reused in another SSL_CTX.

Should fix part of the issue #746.

This must be backported in 2.2 and 2.1.

4 years agoBUG/MINOR: ssl: fix memory leak at OCSP loading
William Lallemand [Thu, 6 Aug 2020 22:44:32 +0000 (00:44 +0200)] 
BUG/MINOR: ssl: fix memory leak at OCSP loading

Fix a memory leak when loading an OCSP file when the file was already
loaded elsewhere in the configuration.

Indeed, if the OCSP file already exists, a useless chunk_dup() will be
done during the load.

To fix it we reverts "ocsp" to "iocsp" like it was done previously.

This was introduced by commit 246c024 ("MINOR: ssl: load the ocsp
in/from the ckch").

Should fix part of the issue #746.

It must be backported in 2.1 and 2.2.

4 years agoDOC: spoa-server: fix false friends `actually`
William Dauchy [Sat, 1 Aug 2020 14:28:52 +0000 (16:28 +0200)] 
DOC: spoa-server: fix false friends `actually`

it seems like `actually` was wrongly used instead of `currently`

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
4 years agoBUG/MINOR: spoa-server: fix size_t format printing
William Dauchy [Sat, 1 Aug 2020 14:28:51 +0000 (16:28 +0200)] 
BUG/MINOR: spoa-server: fix size_t format printing

From https://www.python.org/dev/peps/pep-0353/
"A new type Py_ssize_t is introduced, which has the same size as the
compiler's size_t type, but is signed. It will be a typedef for ssize_t
where available."

For integer types, causes printf to expect a size_t-sized integer
argument.

This should fix github issue #702

This should be backported to >= v2.2

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
4 years agoBUG/MAJOR: dns: disabled servers through SRV records never recover
Baptiste Assmann [Tue, 4 Aug 2020 08:57:21 +0000 (10:57 +0200)] 
BUG/MAJOR: dns: disabled servers through SRV records never recover

A regression was introduced by 13a9232ebc63fdf357ffcf4fa7a1a5e77a1eac2b
when I added support for Additional section of the SRV responses..

Basically, when a server is managed through SRV records additional
section and it's disabled (because its associated Additional record has
disappeared), it never leaves its MAINT state and so never comes back to
production.
This patch updates the "snr_update_srv_status()" function to clear the
MAINT status when the server now has an IP address and also ensure this
function is called when parsing Additional records (and associating them
to new servers).

This can cause severe outage for people using HAProxy + consul (or any
other service registry) through DNS service discovery).

This should fix issue #793.
This should be backported to 2.2.

4 years agoCLEANUP: dns: typo in reported error message
Baptiste Assmann [Tue, 4 Aug 2020 08:54:14 +0000 (10:54 +0200)] 
CLEANUP: dns: typo in reported error message

"record" instead of "recrd".

This should be backported to 2.2.

4 years agoBUG/MEDIUM: mux-h1: Refresh H1 connection timeout after a synchronous send
Christopher Faulet [Wed, 5 Aug 2020 09:31:16 +0000 (11:31 +0200)] 
BUG/MEDIUM: mux-h1: Refresh H1 connection timeout after a synchronous send

The H1 multiplexer is able to perform synchronous send. When a large body is
transfer, if nothing is received and if no error or shutdown occurs, it is
possible to not go down at the H1 connection level to do I/O for a long
time. When this happens, we must still take care to refresh the H1 connection
timeout. Otherwise it is possible to hit the connection timeout during the
transfer while it should not expire.

This bug exists because only h1_process() refresh the H1 connection timeout. To
fix the bug, h1_snd_buf() must also refresh this timeout. To make things more
readable, a dedicated function has been introduced and called to refresh the
timeout.

This bug exists on all HTX versions. But it is harder to hit it on 2.1 and below
because when a H1 mux is initialized, we actively try to read data instead of
subscribing for receiving. So there is at least one call to h1_process().

This patch should fix the issue #790. It must be backported as far as 2.0.

4 years agoCI: travis-ci: specify SLZ_LIB, SLZ_INC for travis builds
Ilya Shipitsin [Tue, 4 Aug 2020 10:39:41 +0000 (15:39 +0500)] 
CI: travis-ci: specify SLZ_LIB, SLZ_INC for travis builds

These variables must be explicitly set as they are not inherited from
the environment. Till now they were ignored.

4 years agoBUILD: Makefile: require SSL_LIB, SSL_INC to be explicitly set
Ilya Shipitsin [Tue, 4 Aug 2020 10:36:24 +0000 (15:36 +0500)] 
BUILD: Makefile: require SSL_LIB, SSL_INC to be explicitly set

The SSL_INC and SSL_LIB variables were not initialized in the Makefile,
so they could be accidently inherited from the environment. We require
that any makefile variable is explicitly set on the command line so they
must be initialized.

Note that the Travis scripts used to rely only on these variables to be
exported, so it was adjusted as well.

4 years agoSCRIPTS: git-show-backports: emit the shell command to backport a commit
Willy Tarreau [Fri, 31 Jul 2020 14:47:44 +0000 (16:47 +0200)] 
SCRIPTS: git-show-backports: emit the shell command to backport a commit

It's cumbersome to copy-paste a commit ID into another window after having
typed "git cherry-pick -sx", so let's have the suggested output format of
git-show prepare this line just before the subject line, it remains at a
stable position on the terminal when searching for "/^commit". One just
has to copy-paste the line into another terminal will result in the commit
being properly picked.

4 years agoSCRIPTS: git-show-backports: make -m most only show the left branch
Willy Tarreau [Fri, 31 Jul 2020 14:38:57 +0000 (16:38 +0200)] 
SCRIPTS: git-show-backports: make -m most only show the left branch

We've never used the output of the rightmost branch with this tool,
and it systematically causes two identical outputs making the job
harder during backport sessions. Let's simply remove the right part
when it's identical to the left one. This also adds a few line feeds
to make the output more readable.

4 years ago[RELEASE] Released version 2.3-dev2 v2.3-dev2
Willy Tarreau [Fri, 31 Jul 2020 12:48:32 +0000 (14:48 +0200)] 
[RELEASE] Released version 2.3-dev2

Released version 2.3-dev2 with the following main changes :
    - DOC: ssl: req_ssl_sni needs implicit TLS
    - BUG/MEDIUM: arg: empty args list must be dropped
    - BUG/MEDIUM: resolve: fix init resolving for ring and peers section.
    - BUG/MAJOR: tasks: don't requeue global tasks into the local queue
    - MINOR: tasks/debug: make the thread affinity BUG_ON check a bit stricter
    - MINOR: tasks/debug: add a few BUG_ON() to detect use of wrong timer queue
    - MINOR: tasks/debug: add a BUG_ON() check to detect requeued task on free
    - BUG/MAJOR: dns: Make the do-resolve action thread-safe
    - BUG/MEDIUM: dns: Release answer items when a DNS resolution is freed
    - MEDIUM: htx: Add a flag on a HTX message when no more data are expected
    - BUG/MEDIUM: stream-int: Don't set MSG_MORE flag if no more data are expected
    - BUG/MEDIUM: http-ana: Only set CF_EXPECT_MORE flag on data filtering
    - CLEANUP: dns: remove 45 "return" statements from dns_validate_dns_response()
    - BUG/MINOR: htx: add two missing HTX_FL_EOI and remove an unexpected one
    - BUG/MINOR: mux-fcgi: Don't url-decode the QUERY_STRING parameter anymore
    - BUILD: tools: fix build with static only toolchains
    - DOC: Use gender neutral language
    - BUG/MINOR: debug: Don't dump the lua stack if it is not initialized
    - BUG/MAJOR: dns: fix null pointer dereference in snr_update_srv_status
    - BUG/MAJOR: dns: don't treat Authority records as an error
    - CI : travis-ci : prepare for using stock OpenSSL
    - CI: travis-ci : switch to stock openssl when openssl-1.1.1 is used
    - MEDIUM: lua: Add support for the Lua 5.4
    - BUG/MEDIUM: dns: Don't yield in do-resolve action on a final evaluation
    - BUG/MINOR: lua: Abort execution of actions that yield on a final evaluation
    - MINOR: tcp-rules: Return an internal error if an action yields on a final eval
    - BUG/MINOR: tcp-rules: Preserve the right filter analyser on content eval abort
    - BUG/MINOR: tcp-rules: Set the inspect-delay when a tcp-response action yields
    - MEDIUM: tcp-rules: Use a dedicated expiration date for tcp ruleset
    - MEDIUM: lua: Set the analyse expiration date with smaller wake_time only
    - BUG/MEDIUM: connection: Be sure to always install a mux for sync connect
    - MINOR: connection: Preinstall the mux for non-ssl connect
    - MINOR: stream-int: Be sure to have a mux to do sends and receives
    - BUG/MINOR: lua: Fix a possible null pointer deref on lua ctx
    - SCRIPTS: announce-release: add the link to the wiki in the announce messages
    - CI: travis-ci: use better name for Coverity scan job
    - CI: travis-ci: use proper linking flags for SLZ build
    - BUG/MEDIUM: backend: always attach the transport before installing the mux
    - BUG/MEDIUM: tcp-checks: always attach the transport before installing the mux
    - MINOR: connection: avoid a useless recvfrom() on outgoing connections
    - MINOR: mux-h1: do not even try to receive if the connection is not fully set up
    - MINOR: mux-h1: do not try to receive on backend before sending a request
    - CLEANUP: assorted typo fixes in the code and comments
    - BUG/MEDIUM: ssl: check OCSP calloc in ssl_sock_load_ocsp()

4 years agoBUG/MEDIUM: ssl: check OCSP calloc in ssl_sock_load_ocsp()
William Lallemand [Fri, 31 Jul 2020 09:43:20 +0000 (11:43 +0200)] 
BUG/MEDIUM: ssl: check OCSP calloc in ssl_sock_load_ocsp()

Check the return of the calloc in ssl_sock_load_ocsp() which could lead
to a NULL dereference.

This was introduced by commit be2774d ("MEDIUM: ssl: Added support for
Multi-Cert OCSP Stapling").

Could be backported as far as 1.7.

4 years agoCLEANUP: assorted typo fixes in the code and comments
Ilya Shipitsin [Wed, 22 Jul 2020 19:32:55 +0000 (00:32 +0500)] 
CLEANUP: assorted typo fixes in the code and comments

This is 12th iteration of typo fixes

4 years agoMINOR: mux-h1: do not try to receive on backend before sending a request
Willy Tarreau [Fri, 31 Jul 2020 07:16:23 +0000 (09:16 +0200)] 
MINOR: mux-h1: do not try to receive on backend before sending a request

There's no point trying to perform an recv() on a back connection if we
have a stream before having sent a request, as it's expected to fail.
It's likely that this may avoid some spurious subscribe() calls in some
keep-alive cases (the close case was already addressed at the connection
level by "MINOR: connection: avoid a useless recvfrom() on outgoing
connections").

4 years agoMINOR: mux-h1: do not even try to receive if the connection is not fully set up
Willy Tarreau [Fri, 31 Jul 2020 07:15:43 +0000 (09:15 +0200)] 
MINOR: mux-h1: do not even try to receive if the connection is not fully set up

If the connection is still waiting for L4/L6, there's no point even trying
to receive as it will fail, so better return zero in h1_recv_allowed().

4 years agoMINOR: connection: avoid a useless recvfrom() on outgoing connections
Willy Tarreau [Fri, 31 Jul 2020 06:59:09 +0000 (08:59 +0200)] 
MINOR: connection: avoid a useless recvfrom() on outgoing connections

When a connect() doesn't immediately succeed (i.e. most of the times),
fd_cant_send() is called to enable polling. But given that we don't
mark that we cannot receive either, we end up performing a failed
recvfrom() immediately when the connect() is finally confirmed, as
indicated in issue #253.

This patch simply adds fd_cant_recv() as well so that we're only
notified once the recv path is ready. The reason it was not there
is purely historic, as in the past when there was the fd cache,
doing it would have caused a pending recv request to be placed into
the fd cache, hence a useless recvfrom() upon success (i.e. what
happens now).

Without this patch, forwarding 100k connections does this:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 17.51    0.704229           7    100000    100000 connect
 16.75    0.673875           3    200000           sendto
 16.24    0.653222           3    200036           close
 10.82    0.435082           1    300000    100000 recvfrom
 10.37    0.417266           1    300012           setsockopt
  7.12    0.286511           1    199954           epoll_ctl
  6.80    0.273447           2    100000           shutdown
  5.34    0.214942           2    100005           socket
  4.65    0.187137           1    105002      5002 accept4
  3.35    0.134757           1    100004           fcntl
  0.61    0.024585           4      5858           epoll_wait

With the patch:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 18.04    0.697365           6    100000    100000 connect
 17.40    0.672471           3    200000           sendto
 17.03    0.658134           3    200036           close
 10.57    0.408459           1    300012           setsockopt
  7.69    0.297270           1    200000           recvfrom
  7.32    0.282934           1    199922           epoll_ctl
  7.09    0.274027           2    100000           shutdown
  5.59    0.216041           2    100005           socket
  4.87    0.188352           1    104697      4697 accept4
  3.35    0.129641           1    100004           fcntl
  0.65    0.024959           4      5337         1 epoll_wait

Note the total disappearance of 1/3 of failed recvfrom() *without*
adding any extra syscall anywhere else.

The trace of an HTTP health check is now totally clean, with no useless
syscall at all anymore:

  09:14:21.959255 connect(9, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
  09:14:21.959292 epoll_ctl(4, EPOLL_CTL_ADD, 9, {EPOLLIN|EPOLLOUT|EPOLLRDHUP, {u32=9, u64=9}}) = 0
  09:14:21.959315 epoll_wait(4, [{EPOLLOUT, {u32=9, u64=9}}], 200, 1000) = 1
  09:14:21.959376 sendto(9, "OPTIONS / HTTP/1.0\r\ncontent-leng"..., 41, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 41
  09:14:21.959436 epoll_wait(4, [{EPOLLOUT, {u32=9, u64=9}}], 200, 1000) = 1
  09:14:21.959456 epoll_ctl(4, EPOLL_CTL_MOD, 9, {EPOLLIN|EPOLLRDHUP, {u32=9, u64=9}}) = 0
  09:14:21.959512 epoll_wait(4, [{EPOLLIN|EPOLLRDHUP, {u32=9, u64=9}}], 200, 1000) = 1
  09:14:21.959548 recvfrom(9, "HTTP/1.0 200\r\nContent-length: 0\r"..., 16320, 0, NULL, NULL) = 126
  09:14:21.959570 close(9)                = 0

With the edge-triggered poller, it gets even better:

  09:29:15.776201 connect(9, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
  09:29:15.776256 epoll_ctl(4, EPOLL_CTL_ADD, 9, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=9, u64=9}}) = 0
  09:29:15.776287 epoll_wait(4, [{EPOLLOUT, {u32=9, u64=9}}], 200, 1000) = 1
  09:29:15.776320 sendto(9, "OPTIONS / HTTP/1.0\r\ncontent-leng"..., 41, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 41
  09:29:15.776374 epoll_wait(4, [{EPOLLIN|EPOLLOUT|EPOLLRDHUP, {u32=9, u64=9}}], 200, 1000) = 1
  09:29:15.776406 recvfrom(9, "HTTP/1.0 200\r\nContent-length: 0\r"..., 16320, 0, NULL, NULL) = 126
  09:29:15.776434 close(9)                = 0

It could make sense to backport this patch to 2.2 and maybe 2.1 after
it has been sufficiently checked for absence of side effects in 2.3-dev,
as some people had reported an extra overhead like in issue #168.

4 years agoBUG/MEDIUM: tcp-checks: always attach the transport before installing the mux
Willy Tarreau [Fri, 31 Jul 2020 06:49:31 +0000 (08:49 +0200)] 
BUG/MEDIUM: tcp-checks: always attach the transport before installing the mux

Similarly to the issue described in commit "BUG/MEDIUM: backend: always
attach the transport before installing the mux", in tcpcheck_eval_connect()
we can install a handshake transport layer underneath the mux and replace
its subscriptions, causing a crash if the mux had already subscribed for
whatever reason.

A simple reproducer consists in adding fd_cant_recv() after fd_cant_send()
in tcp_connect_server() and running it on this config, as discussed in issue

  listen foo
    bind :8181
    mode http
    option httpchk
    server srv1 127.0.0.1:8888 send-proxy-v2 check inter 1000

The mux may only be installed *after* xprt_handshake is set up, so that
it registers against it and not against raw_sock or ssl_sock. This needs
to be backported to 2.2 which is the first version using muxes for checks.

4 years agoBUG/MEDIUM: backend: always attach the transport before installing the mux
Willy Tarreau [Fri, 31 Jul 2020 06:39:31 +0000 (08:39 +0200)] 
BUG/MEDIUM: backend: always attach the transport before installing the mux

In connect_server(), we can enter in a stupid situation:

  - conn_install_mux_be() is called to install the mux. This one
    subscribes for receiving and quits ;

  - then we discover that a handshake is required on the connection
    (e.g. send-proxy), so xprt_add_hs() is called and subscribes as
    well.

  - we crash in conn_subscribe() which gets a different subscriber.
    And if BUG_ON is disabled, we'd likely lose one event.

Note that it doesn't seem to happen by default, but definitely does
if connect() rightfully performs fd_cant_recv(), so it's a matter of
who does what and in what order.

A simple reproducer consists in adding fd_cant_recv() after fd_cant_send()
in tcp_connect_server() and running it on this config, as discussed in issue

  listen foo
    bind :8181
    mode http
    server srv1 127.0.0.1:8888 send-proxy-v2

The root cause is that xprt_add_hs() installs an xprt layer underneath
the mux without taking over its subscriptions. Ideally if we want to
support this, we'd need to steal the connection's wait_events and
replace them by new ones. But there doesn't seem to be any case where
we're interested in doing this so better simply always install the
transport layer before installing the mux, that's safer and simpler.

This needs to be backported to 2.1 which is constructed the same way
and thus suffers from the same issue, though the code is slightly
different there.

4 years agoCI: travis-ci: use proper linking flags for SLZ build
Ilya Shipitsin [Thu, 30 Jul 2020 21:08:13 +0000 (02:08 +0500)] 
CI: travis-ci: use proper linking flags for SLZ build

previously SSL_INC and SSL_INC were set for all builds, and SLZ lib
was linked because of those flags. After we switched SLZ build to
stock openssl lib, SSL_INC, SSL_LIB are not set anymore.

Good time to set SLZ_INC, SLZ_LIB for such builds

4 years agoCI: travis-ci: use better name for Coverity scan job
Ilya Shipitsin [Thu, 30 Jul 2020 21:05:55 +0000 (02:05 +0500)] 
CI: travis-ci: use better name for Coverity scan job

Let's add Coverity in the job name.

4 years agoSCRIPTS: announce-release: add the link to the wiki in the announce messages
Willy Tarreau [Thu, 30 Jul 2020 15:41:42 +0000 (17:41 +0200)] 
SCRIPTS: announce-release: add the link to the wiki in the announce messages

Let's add the link to the wiki to the announce messages, plenty of
users don't even know it exists.

4 years agoBUG/MINOR: lua: Fix a possible null pointer deref on lua ctx
Christopher Faulet [Thu, 30 Jul 2020 08:40:58 +0000 (10:40 +0200)] 
BUG/MINOR: lua: Fix a possible null pointer deref on lua ctx

This bug was introduced by the commit 8f587ea3 ("MEDIUM: lua: Set the analyse
expiration date with smaller wake_time only"). At the end of hlua_action(), the
lua context may be null if the alloc failed.

No backport needed, this is 2.3-dev.

4 years agoMINOR: stream-int: Be sure to have a mux to do sends and receives
Christopher Faulet [Thu, 30 Jul 2020 07:26:46 +0000 (09:26 +0200)] 
MINOR: stream-int: Be sure to have a mux to do sends and receives

In si_cs_send() and si_cs_recv(), we explicitly test the connection's mux is
defined to proceed. For si_cs_recv(), it is probably a bit overkill. But
opportunistic sends are possible from the moment the server connection is
created. So it is safer to do this test.

This patch may be backported as far as 1.9 if necessary.

4 years agoMINOR: connection: Preinstall the mux for non-ssl connect
Christopher Faulet [Thu, 30 Jul 2020 07:10:36 +0000 (09:10 +0200)] 
MINOR: connection: Preinstall the mux for non-ssl connect

In the connect_server() function, there is an optim to install the mux as soon
as possible. It is possible if we can determine the mux to use from the
configuration only. For instance if the mux is explicitly specified or if no ALPN
is set. This patch adds a new condition to preinstall the mux for non-ssl
connection. In this case, by default, we always use the mux_pt for raw
connections and the mux-h1 for HTTP ones.

This patch is related to the issue #762. It may be backported to 2.2 (and
possibly as far as 1.9 if necessary).

4 years agoBUG/MEDIUM: connection: Be sure to always install a mux for sync connect
Christopher Faulet [Wed, 29 Jul 2020 20:42:27 +0000 (22:42 +0200)] 
BUG/MEDIUM: connection: Be sure to always install a mux for sync connect

Sometime, a server connection may be performed synchronously. Most of time on
TCP socket, it does not happen. It is easier to have sync connect with unix
socket. When it happens, if we are not waiting for any hanshake completion, we
must be sure to have a mux installed before leaving the connect_server()
function because an attempt to send may be done before the I/O connection
handler have a chance to be executed to install the mux, if not already done.

For now, It is not expected to perform a send with no mux installed, leading to
a crash if it happens.

This patch should fix the issue #762 and probably #779 too. It must be
backported as far as 1.9.

4 years agoMEDIUM: lua: Set the analyse expiration date with smaller wake_time only
Christopher Faulet [Tue, 28 Jul 2020 10:01:55 +0000 (12:01 +0200)] 
MEDIUM: lua: Set the analyse expiration date with smaller wake_time only

If a lua action yields for any reason and if the wake timeout is set, it only
override the analyse expiration date if it is smaller. This way, a lower
inspect-delay will be respected, if any.

4 years agoMEDIUM: tcp-rules: Use a dedicated expiration date for tcp ruleset
Christopher Faulet [Tue, 28 Jul 2020 09:56:13 +0000 (11:56 +0200)] 
MEDIUM: tcp-rules: Use a dedicated expiration date for tcp ruleset

A dedicated expiration date is now used to apply the inspect-delay of the
tcp-request or tcp-response rulesets. Before, the analyse expiratation date was
used but it may also be updated by the lua (at least). So a lua script may
extend or reduce the inspect-delay by side effect. This is not expected. If it
becomes necessary, a specific function will be added to do this. Because, for
now, it is a bit confusing.

4 years agoBUG/MINOR: tcp-rules: Set the inspect-delay when a tcp-response action yields
Christopher Faulet [Wed, 29 Jul 2020 10:00:23 +0000 (12:00 +0200)] 
BUG/MINOR: tcp-rules: Set the inspect-delay when a tcp-response action yields

On a tcp-response content ruleset evaluation, the inspect-delay is engaged when
rule's conditions are not validated but not when the rule's action yields.

This patch must be backported to all supported versions.

4 years agoBUG/MINOR: tcp-rules: Preserve the right filter analyser on content eval abort
Christopher Faulet [Tue, 28 Jul 2020 09:40:07 +0000 (11:40 +0200)] 
BUG/MINOR: tcp-rules: Preserve the right filter analyser on content eval abort

When a tcp-request or a tcp-response content ruleset evaluation is aborted, the
corresponding FLT_END analyser must be preserved, if any. But because of a typo
error, on the tcp-response content ruleset evaluation, we try to preserve the
request analyser instead of the response one.

This patch must be backported to 2.2.

4 years agoMINOR: tcp-rules: Return an internal error if an action yields on a final eval
Christopher Faulet [Tue, 28 Jul 2020 09:30:19 +0000 (11:30 +0200)] 
MINOR: tcp-rules: Return an internal error if an action yields on a final eval

On a final evaluation of a tcp-request or tcp-response content ruleset, it is
forbidden for an action to yield. To quickly identify bugs an internal error is
now returned if it happens and a warning log message is emitted.

4 years agoBUG/MINOR: lua: Abort execution of actions that yield on a final evaluation
Christopher Faulet [Tue, 28 Jul 2020 09:59:58 +0000 (11:59 +0200)] 
BUG/MINOR: lua: Abort execution of actions that yield on a final evaluation

A Lua action may yield. It may happen because the action returns explicitly
act.YIELD or because the script itself yield. In the first case, we must abort
the script execution if it is the final rule evaluation, i.e if the
ACT_OPT_FINAL flag is set. The second case is already covered.

This patch must be backported to 2.2.

4 years agoBUG/MEDIUM: dns: Don't yield in do-resolve action on a final evaluation
Christopher Faulet [Tue, 28 Jul 2020 08:21:54 +0000 (10:21 +0200)] 
BUG/MEDIUM: dns: Don't yield in do-resolve action on a final evaluation

When an action is evaluated, flags are passed to know if it is the first call
(ACT_OPT_FIRST) and if it must be the last one (ACT_OPT_FINAL). For the
do-resolve DNS action, the ACT_OPT_FINAL flag must be handled because the
action may yield. It must never yield when this flag is set. Otherwise, it may
lead to a wakeup loop of the stream because the inspected-delay of a tcp-request
content ruleset was reached without stopping the rules evaluation.

This patch is related to the issue #222. It must be backported as far as 2.0.

4 years agoMEDIUM: lua: Add support for the Lua 5.4
Christopher Faulet [Tue, 28 Jul 2020 08:33:25 +0000 (10:33 +0200)] 
MEDIUM: lua: Add support for the Lua 5.4

On Lua 5.4, some API changes make HAProxy compilation to fail. Among other
things, the lua_resume() function has changed and now takes an extra argument in
Lua 5.4 and the error LUA_ERRGCMM was removed. Thus the LUA_VERSION_NUM macro is
now tested to know the lua version is used and adapt the code accordingly.

Here are listed the incompatibilities with the previous Lua versions :

   http://www.lua.org/manual/5.4/manual.html#8

This patch comes from the HAproxy's fedora RPM, committed by Tom Callaway :

  https://src.fedoraproject.org/rpms/haproxy/blob/db970613/f/haproxy-2.2.0-lua-5.4.patch

This patch should fix the issue #730. It must be backported to 2.2 and probably
as far as 2.0.

4 years agoCI: travis-ci : switch to stock openssl when openssl-1.1.1 is used
Ilya Shipitsin [Wed, 29 Jul 2020 20:47:55 +0000 (01:47 +0500)] 
CI: travis-ci : switch to stock openssl when openssl-1.1.1 is used

instead of building openssl-1.1.1 let us use stock package and save
some electricity

4 years agoCI : travis-ci : prepare for using stock OpenSSL
Ilya Shipitsin [Wed, 29 Jul 2020 20:39:24 +0000 (01:39 +0500)] 
CI : travis-ci : prepare for using stock OpenSSL

initially SSL_LIB and SSL_INC were set globally and we assumed
that any OpenSSL variant is supposed to be built using "script/build-ssl.sh".

starting with ARM64 build we use stock openssl, also it makes sense
to use stock openssl for 1.1.1 builds for velocity sake.

Let us make stock openssl lib first class citizen.

SSL_LIB and SSL_INC are only set when custom openssl variant
is built.

4 years agoBUG/MAJOR: dns: don't treat Authority records as an error
Jerome Magnin [Sun, 26 Jul 2020 10:13:12 +0000 (12:13 +0200)] 
BUG/MAJOR: dns: don't treat Authority records as an error

Support for DNS Service Discovery by means of SRV records was enhanced with
commit 13a9232eb ("MEDIUM: dns: use Additional records from SRV responses")
to use the content of the answers Additional records when present.

If there are Authority records before the Additional records we mistakenly
treat that as an invalid response. To fix this, just ignore the Authority
section if it exist and skip to the Additional records.

As 13a9232eb was introduced during 2.2-dev, it must be backported to 2.2.
This is a fix for issue #778

4 years agoBUG/MAJOR: dns: fix null pointer dereference in snr_update_srv_status
Jerome Magnin [Tue, 28 Jul 2020 11:38:22 +0000 (13:38 +0200)] 
BUG/MAJOR: dns: fix null pointer dereference in snr_update_srv_status

Since commit 13a9232eb ("MEDIUM: dns: use Additional records from SRV
responses"), a struct server can have a NULL dns_requester->resolution,
when SRV records are used and DNS answers contain an Additional section.

This is a problem when we call snr_update_srv_status() because it does
not check that resolution is NULL, and dereferences it. This patch
simply adds a test for resolution being NULL. When that happens, it means
we are using SRV records with Additional records, and an entry was removed.

This should fix issue #775.
This should be backported to 2.2.

4 years agoBUG/MINOR: debug: Don't dump the lua stack if it is not initialized
Christopher Faulet [Fri, 24 Jul 2020 17:08:05 +0000 (19:08 +0200)] 
BUG/MINOR: debug: Don't dump the lua stack if it is not initialized

When the watchdog is fired because of the lua, the stack of the corresponding
lua context is dumped. But we must be sure the lua context is fully initialized
to do so. If we are blocked on the global lua lock, during the lua context
initialization, the lua stask may be NULL.

This patch should fix the issue #776. It must be backported as far as 2.0.

4 years agoDOC: Use gender neutral language
Jackie Tapia [Wed, 22 Jul 2020 23:59:40 +0000 (18:59 -0500)] 
DOC: Use gender neutral language

This patch updates the documentation files and code comments to avoid
the use of gender specific phrasing in favor of "they" or "it".

4 years agoBUILD: tools: fix build with static only toolchains
Baruch Siach [Fri, 24 Jul 2020 04:52:20 +0000 (07:52 +0300)] 
BUILD: tools: fix build with static only toolchains

uClibc toolchains built with no dynamic library support don't provide
the dlfcn.h header. That leads to build failure:

  CC      src/tools.o
src/tools.c:15:10: fatal error: dlfcn.h: No such file or directory
 #include <dlfcn.h>
          ^~~~~~~~~
Enable dladdr on Linux platforms only when USE_DL is defined.

This should be backported wherever 109201fc5 ("BUILD: tools: rely on
__ELF__ not USE_DL to enable use of dladdr()") is backported (currently
only 2.2 and 2.1).

4 years agoBUG/MINOR: mux-fcgi: Don't url-decode the QUERY_STRING parameter anymore
Christopher Faulet [Thu, 23 Jul 2020 13:44:37 +0000 (15:44 +0200)] 
BUG/MINOR: mux-fcgi: Don't url-decode the QUERY_STRING parameter anymore

In the CGI/1.1 specification, it is specified the QUERY_STRING must not be
url-decoded. However, this parameter is sent decoded because it is extracted
after the URI's path decoding. Now, the query-string is first extracted, then
the script part of the path is url-decoded. This way, the QUERY_STRING parameter
is no longer decoded.

This patch should fix the issue #769. It must be backported as far as 2.1.

4 years agoBUG/MINOR: htx: add two missing HTX_FL_EOI and remove an unexpected one
Willy Tarreau [Thu, 23 Jul 2020 04:53:27 +0000 (06:53 +0200)] 
BUG/MINOR: htx: add two missing HTX_FL_EOI and remove an unexpected one

A workaround for some difficulties encountered to anticipate end of
messages was addressed by commit 810df0614 ("MEDIUM: htx: Add a flag on
a HTX message when no more data are expected"), but there were 3 issues
in it (with minor impact):
  - the flag was mistakenly set before an EOH in Lua, which would only
    cause incomplete packets to be emitted for now but could cause
    truncated responses in the future. It's not needed to add it on
    the next EOM block as http_forward_proxy_resp() already does it.

  - one was still missing in hlua_applet_http_fct(), possibly causing
    delays on Lua services

  - one was missing in the Prometheus exporter.

All this simply shows that this mechanism is still quite fragile and
not trivial to use, especially in order to deal with the impossibility
to append the EOM, so we'll need to improve the solution in the future
and future backports should not be completely ruled out.

This fix must be backported where the patch above is backported,
typically 2.1 and later as it was required for a set of fixes.

4 years agoCLEANUP: dns: remove 45 "return" statements from dns_validate_dns_response()
Willy Tarreau [Wed, 22 Jul 2020 15:00:45 +0000 (17:00 +0200)] 
CLEANUP: dns: remove 45 "return" statements from dns_validate_dns_response()

The previous leak on do-resolve was particularly tricky to check due
to the important code repetition in dns_validate_dns_response() which
required careful examination of all return statements to check whether
they needed a pool_free() or not. Let's clean all this up using a common
leave point which releases the element itself. This also encourages
to properly set the current response to null right after freeing or
adding it so that it doesn't get added. 45 return and 22 pool_free()
were replaced by one of each.

4 years agoBUG/MEDIUM: http-ana: Only set CF_EXPECT_MORE flag on data filtering
Christopher Faulet [Wed, 22 Jul 2020 14:34:59 +0000 (16:34 +0200)] 
BUG/MEDIUM: http-ana: Only set CF_EXPECT_MORE flag on data filtering

This flag is set by HTTP analyzers to notify that more data are epxected. It is
used to know if the CO_SFL_MSG_MORE flag must be set on the connection when data
are sent. Historically, it was set on chuncked messages and on compressed
responses. But in HTX, the chunked messages are parsed by the H1 multipexer. So
for this case, the infinite forwarding is enabled and the flag must no longer be
set. For the compression, the test must be extended and be applied on all data
filters. Thus it is also true for the request channel.

So, now, CF_EXPECT_MORE flag is set on a request or a response channel if there
is at least one data filter attached to the stream. In addition, the flag is
removed when the HTTP message analysis is finished.

This patch should partially fix the issue #756. It must be backported to 2.1.

4 years agoBUG/MEDIUM: stream-int: Don't set MSG_MORE flag if no more data are expected
Christopher Faulet [Wed, 22 Jul 2020 14:28:44 +0000 (16:28 +0200)] 
BUG/MEDIUM: stream-int: Don't set MSG_MORE flag if no more data are expected

In HTX, if the HTX_FL_EOI message is set on the message, we don't set the
CO_SFL_MSG_MORE flag on the connection. This way, the send is not delayed if
only the EOM is missing in the HTX message.

This patch depends on the commit "MEDIUM: htx: Add a flag on a HTX message when
no more data are expected".

This patch should partially fix the issue #756. It must be backported to
2.1. For earlier versions, CO_SFL_MSG_MORE is ignored by HTX muxes.

4 years agoMEDIUM: htx: Add a flag on a HTX message when no more data are expected
Christopher Faulet [Wed, 22 Jul 2020 14:20:34 +0000 (16:20 +0200)] 
MEDIUM: htx: Add a flag on a HTX message when no more data are expected

The HTX_FL_EOI flag must now be set on a HTX message when no more data are
expected. Most of time, it must be set before adding the EOM block. Thus, if
there is no space for the EOM, there is still an information to know all data
were received and pushed in the HTX message. There is only an exception for the
HTTP replies (deny, return...). For these messages, the flag is set after all
blocks are pushed in the message, including the EOM block, because, on error,
we remove all inserted data.

4 years agoBUG/MEDIUM: dns: Release answer items when a DNS resolution is freed
Christopher Faulet [Wed, 22 Jul 2020 13:55:49 +0000 (15:55 +0200)] 
BUG/MEDIUM: dns: Release answer items when a DNS resolution is freed

When a DNS resolution is freed, the remaining items in .ar_list and .answer_list
are also released. It must be done to avoid a memory leak. And it is the last
chance to release these objects. I've honestly no idea if there is a better
place to release them earlier. But at least, there is no more leak.

This patch should solve the issue #222. It must be backported, at least, as far
as 2.0, and probably, with caution, as far as 1.8 or 1.7.

4 years agoBUG/MAJOR: dns: Make the do-resolve action thread-safe
Christopher Faulet [Wed, 22 Jul 2020 09:46:32 +0000 (11:46 +0200)] 
BUG/MAJOR: dns: Make the do-resolve action thread-safe

The do-resolve HTTP action, performing a DNS resolution of a sample expression
output, is not thread-safe at all. The resolver object used to do the resolution
must be locked when the action is executed or when the stream is released
because its curr or wait resolution lists and the requester list inside a
resolution are updated. It is also important to not wake up a released stream
(with a destroyed task).

Of course, because of this bug, various kind of crashes may be observed.

This patch should fix the issue #236. It must be backported as far as 2.0.

4 years agoMINOR: tasks/debug: add a BUG_ON() check to detect requeued task on free
Willy Tarreau [Wed, 22 Jul 2020 12:33:53 +0000 (14:33 +0200)] 
MINOR: tasks/debug: add a BUG_ON() check to detect requeued task on free

__task_free() cannot be called with a task still in the queue. This
test adds a check which confirms there is no concurrency issue on such
a case where a thread could requeue nor wakeup a task being freed.

4 years agoMINOR: tasks/debug: add a few BUG_ON() to detect use of wrong timer queue
Willy Tarreau [Wed, 22 Jul 2020 12:29:42 +0000 (14:29 +0200)] 
MINOR: tasks/debug: add a few BUG_ON() to detect use of wrong timer queue

This aims at catching calls to task_unlink_wq() performed by the wrong
thread based on the shared status for the task, as well as calls to
__task_queue() with the wrong timer queue being used based on the task's
capabilities. This will at least help eliminate some hypothesis during
debugging sessions when suspecting that a wrong thread has attempted to
queue a task at the wrong place.

4 years agoMINOR: tasks/debug: make the thread affinity BUG_ON check a bit stricter
Willy Tarreau [Wed, 22 Jul 2020 12:20:14 +0000 (14:20 +0200)] 
MINOR: tasks/debug: make the thread affinity BUG_ON check a bit stricter

The BUG_ON() test in task_queue() only tests for the case where
we're queuing a task that doesn't run on the current thread. Let's
refine it a bit further to catch all cases where the task does not
run *exactly* on the current thread alone.

4 years agoBUG/MAJOR: tasks: don't requeue global tasks into the local queue
Willy Tarreau [Wed, 22 Jul 2020 12:12:45 +0000 (14:12 +0200)] 
BUG/MAJOR: tasks: don't requeue global tasks into the local queue

A bug was introduced by commit 77015abe0 ("MEDIUM: tasks: clean up the
front side of the wait queue in wake_expired_tasks()"): front tasks
that are not yet expired were incorrectly requeued into the local
wait queue instead of the global one. Because of this, the same task
could be found by the same thread on next invocation and be unlinked
without locking, allowing another thread to requeue it in parallel,
and conversely another thread could unlink it while the task was being
walked over, causing all sorts of crashes and endless loops in
wake_expired_tasks() and affiliates.

This bug can easily be triggered by stressing the do_resolve action
in multi-thread (after applying the fixes required to get do_resolve
to work with threads). It certainly is the cause of issue #758.

This must be backported to 2.2 only.

4 years agoBUG/MEDIUM: resolve: fix init resolving for ring and peers section.
Emeric Brun [Tue, 21 Jul 2020 14:54:36 +0000 (16:54 +0200)] 
BUG/MEDIUM: resolve: fix init resolving for ring and peers section.

Reported github issue #759 shows there is no name resolving
on server lines for ring and peers sections.

This patch introduce the resolving for those lines.

This patch adds  boolean a parameter to parse_server function to specify
if we want the function to perform an initial name resolving using libc.

This boolean is forced to true in case of peers or ring section.

The boolean is kept to false in case of classic servers (from
backend/listen)

This patch should be backported in branches where peers sections
support 'server' lines.

4 years agoBUG/MEDIUM: arg: empty args list must be dropped
Willy Tarreau [Tue, 21 Jul 2020 13:44:38 +0000 (15:44 +0200)] 
BUG/MEDIUM: arg: empty args list must be dropped

Before commit 80b53ffb1 ("MEDIUM: arg: make make_arg_list() stop after
its own arguments"), consumers of arguments would measure the length of
the string between the first opening and closing parenthesis before
calling make_arg_list(), and this latter one would detect an empty string
early by len==0 and would not allocate an argument list.

Since that commit, this has a changed a bit because the argument parser
is now the one in charge for delimiting the argument string, so the early
test cannot be used anymore. But the argument list is still allocated,
and despite the number of arguments being returned, consumers do not
necessarily rely on it but instead they rely on the non-null arg_p
pointer that used to be allocated only if at least one argument was
present. But as it's now always allocated, the first argument always
carries the first argument's type with an empty value, which confuses
all functions that take a unique optional argument (such as uuid()).

The proper long term solution would be to always use the returned argument
count, but at least we can make sure the function always returns an empty
argument list when fed with an empty set of parenthesis, as it always used
to do. This is what this patch does.

This fix must be backported to 2.2 and fixes github issue #763. Thanks to
Luke Seelenbinder for reporting the problem.

4 years agoDOC: ssl: req_ssl_sni needs implicit TLS
Lukas Tribus [Sat, 18 Jul 2020 22:25:06 +0000 (00:25 +0200)] 
DOC: ssl: req_ssl_sni needs implicit TLS

req_ssl_sni is not compatible with protocols negotiating TLS
explicitly, like SMTP on port 25 or 587 and IMAP on port 143.

Fix an example referring to 587 (SMTPS port with implicit TLS
is 465) and amend the req_ssl_sni documentation.

This doc fix should be backported to supported versions.

4 years ago[RELEASE] Released version 2.3-dev1 v2.3-dev1
Willy Tarreau [Fri, 17 Jul 2020 13:13:19 +0000 (15:13 +0200)] 
[RELEASE] Released version 2.3-dev1

Released version 2.3-dev1 with the following main changes :
    - MINOR: config: make strict limits enabled by default
    - BUG/MINOR: acl: Fix freeing of expr->smp in prune_acl_expr
    - BUG/MINOR: sample: Fix freeing of conv_exprs in release_sample_expr
    - BUG/MINOR: haproxy: Free proxy->format_unique_id during deinit
    - BUG/MINOR: haproxy: Add missing free of server->(hostname|resolvers_id)
    - BUG/MINOR: haproxy: Free proxy->unique_id_header during deinit
    - BUG/MINOR: haproxy: Free srule->file during deinit
    - BUG/MINOR: haproxy: Free srule->expr during deinit
    - BUG/MINOR: sample: Free str.area in smp_check_const_bool
    - BUG/MINOR: sample: Free str.area in smp_check_const_meth
    - CLEANUP: haproxy: Free proxy_deinit_list in deinit()
    - CLEANUP: haproxy: Free post_deinit_list in deinit()
    - CLEANUP: haproxy: Free server_deinit_list in deinit()
    - CLEANUP: haproxy: Free post_server_check_list in deinit()
    - CLEANUP: Add static void vars_deinit()
    - CLEANUP: Add static void hlua_deinit()
    - CLEANUP: contrib/prometheus-exporter: typo fixes for ssl reuse metric
    - BUG/MEDIUM: lists: add missing store barrier on MT_LIST_BEHEAD()
    - BUG/MEDIUM: lists: add missing store barrier in MT_LIST_ADD/MT_LIST_ADDQ
    - MINOR: tcp: Support TCP keepalive parameters customization
    - BUILD: tcp: condition TCP keepalive settings to platforms providing them
    - MINOR: lists: rename some MT_LIST operations to clarify them
    - MINOR: buffer: use MT_LIST_ADDQ() for buffer_wait lists additions
    - MINOR: connection: use MT_LIST_ADDQ() to add connections to idle lists
    - MINOR: tasks: use MT_LIST_ADDQ() when killing tasks.
    - CONTRIB: da: fix memory leak in dummy function da_atlas_open()
    - CI: travis-ci: speed up osx build by running brew scripted, switch to latest osx image
    - BUG/MEDIUM: mux-h2: Don't add private connections in available connection list
    - BUG/MEDIUM: mux-fcgi: Don't add private connections in available connection list
    - MINOR: connection: Set the SNI on server connections before installing the mux
    - MINOR: connection: Set new connection as private on reuse never
    - MINOR: connection: Add a wrapper to mark a connection as private
    - MEDIUM: connection: Add private connections synchronously in session server list
    - MINOR: connection: Use a dedicated function to look for a session's connection
    - MINOR: connection: Set the conncetion target during its initialisation
    - MINOR: session: Take care to decrement idle_conns counter in session_unown_conn
    - MINOR: server: Factorize code to deal with reuse of server idle connections
    - MINOR: server: Factorize code to deal with connections removed from an idle list
    - CLEANUP: connection: remove unused field idle_time from the connection struct
    - BUG/MEDIUM: mux-h1: Continue to process request when switching in tunnel mode
    - MINOR: raw_sock: Report the number of bytes emitted using the splicing
    - MINOR: contrib/prometheus-exporter: Add missing global and per-server metrics
    - MINOR: backend: Add sample fetches to get the server's weight
    - BUG/MINOR: mux-fcgi: Handle empty STDERR record
    - BUG/MINOR: mux-fcgi: Set conn state to RECORD_P when skipping the record padding
    - BUG/MINOR: mux-fcgi: Set flags on the right stream field for empty FCGI_STDOUT
    - BUG/MINOR: backend: fix potential null deref on srv_conn
    - BUG/MEDIUM: log: issue mixing sampled to not sampled log servers.
    - MEDIUM: udp: adds minimal proto udp support for message listeners.
    - MEDIUM: log/sink: re-work and merge of build message API.
    - MINOR: log: adds syslog udp message handler and parsing.
    - MEDIUM: log: adds log forwarding section.
    - MINOR: log: adds counters on received syslog messages.
    - BUG/MEDIUM: fcgi-app: fix memory leak in fcgi_flt_http_headers
    - BUG/MEDIUM: server: resolve state file handle leak on reload
    - BUG/MEDIUM: server: fix possibly uninitialized state file on close
    - BUG/MEDIUM: channel: Be aware of SHUTW_NOW flag when output data are peeked
    - BUILD: config: address build warning on raspbian+rpi4
    - BUG/MAJOR: tasks: make sure to always lock the shared wait queue if needed
    - BUILD: config: fix again bugs gcc warnings on calloc

4 years agoBUILD: config: fix again bugs gcc warnings on calloc
Willy Tarreau [Fri, 17 Jul 2020 13:04:53 +0000 (15:04 +0200)] 
BUILD: config: fix again bugs gcc warnings on calloc

Since commit ad37c7ab ("BUILD: config: address build warning on
raspbian+rpi4") gcc 7.3.0 complains again on x86_64 (while 8.2.0
does not) :

  src/cfgparse.c: In function 'check_config_validity':
  src/cfgparse.c:3593:26: warning: argument 1 range [1844674407156206796818446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
       newsrv->idle_conns = calloc(global.nbthread, sizeof(*newsrv->idle_conns));
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This thing is completely bogus (actually the RPi one was the most wrong).
Let's try to shut them both by using an unsigned short for the cast which
is expected to satisfy everyone. It's worth noting that the exact same call
a few lines above and below do not trigger this stupid warning.

This should be backported to 2.2 since the fix above was put there already.

4 years agoBUG/MAJOR: tasks: make sure to always lock the shared wait queue if needed
Willy Tarreau [Fri, 17 Jul 2020 12:37:51 +0000 (14:37 +0200)] 
BUG/MAJOR: tasks: make sure to always lock the shared wait queue if needed

In run_tasks_from_task_list() we may free some tasks that have been
killed. Before doing so we unlink them from the wait queue. But if such
a task is in the global wait queue, the queue isn't locked so this can
result in corrupting the global task list and causing loops or crashes.

It's very likely one cause of issue #758.

This must be backported to 2.2. For 2.1 there doesn't seem to be any
case where a task could be freed this way while in the global queue,
but it doesn't cost much to apply the same change (the code is in
process_runnable_task there).

4 years agoBUILD: config: address build warning on raspbian+rpi4
Willy Tarreau [Fri, 17 Jul 2020 12:18:36 +0000 (14:18 +0200)] 
BUILD: config: address build warning on raspbian+rpi4

Issue #747 reports that building on raspbian for rpi4 triggers this
warning:

  src/cfgparse.c: In function 'check_config_validity':
  src/cfgparse.c:3584:26: warning: argument 1 range [21474836484294967295] exceeds maximum object size 2147483647 [-Walloc-size-larger-than=]
     newsrv->idle_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->idle_conns));
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's surprising because the declared type is size_t and the argument is
unsigned (i.e. the same type on 32-bit) precisely to avoid cast issues,
but gcc seems to be too smart at this one and to issue a warning over
the valid range, implying that passing the originally required type would
also warn. Given that these are the only casts in calloc and other ones
don't complain, let's drop them.

All 3 were added by commit dc2f2753e ("MEDIUM: servers: Split the
connections into idle, safe, and available.")  that went into 2.2, so
this should be backported.

4 years agoBUG/MEDIUM: channel: Be aware of SHUTW_NOW flag when output data are peeked
Christopher Faulet [Thu, 16 Jul 2020 09:43:46 +0000 (11:43 +0200)] 
BUG/MEDIUM: channel: Be aware of SHUTW_NOW flag when output data are peeked

The CF_SHUTW_NOW flag must be handled the same way than the CF_SHUTW flag in
co_getblk_nc() and co_getline_nc() functions. It is especally important when we
try to peek a line from outgoing data. In this case, an unfinished line is
blocked an nothing is peeked if the CF_SHUTW_NOW flag is set. But the blocked
data pevent the transition to CF_SHUTW.

The above functions are only used by LUA cosockets. Because of this bug, we may
experienced wakeups in loop of the cosocket's io handler if we try to read a
line on a closed socket with a pending unfinished line (no LF found at the end).

This patch should fix issue #744. It must be backported to all supported
versions.

4 years agoBUG/MEDIUM: server: fix possibly uninitialized state file on close
Willy Tarreau [Thu, 16 Jul 2020 04:40:27 +0000 (06:40 +0200)] 
BUG/MEDIUM: server: fix possibly uninitialized state file on close

Previous fix dc6e8a9a7 ("BUG/MEDIUM: server: resolve state file handle
leak on reload") traded a bug for another one, now we get this warning
when building server.c, which is valid since f is not necessarily
initialized (e.g. if no global state file is passed):

  src/server.c: In function 'apply_server_state':
  src/server.c:3272:3: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
     fclose(f);
   ^~~~~~~~~

Let's initialize it first. This whole code block should really be
splitted, cleaned up and reorganized as it's possible that other
similar bugs are hidden in it.

This must be backported to the same branches the commit above is
backported to (likely 2.2 and 2.1).

4 years agoBUG/MEDIUM: server: resolve state file handle leak on reload
Ilya Shipitsin [Wed, 15 Jul 2020 21:02:40 +0000 (02:02 +0500)] 
BUG/MEDIUM: server: resolve state file handle leak on reload

During reload, server state file is read and file handle is not released
this was indepently reported in #738 and #660.

partially resolves #660. This should be backported to 2.2 and 2.1.

4 years agoBUG/MEDIUM: fcgi-app: fix memory leak in fcgi_flt_http_headers
Harris Kaufmann [Wed, 15 Jul 2020 14:26:13 +0000 (16:26 +0200)] 
BUG/MEDIUM: fcgi-app: fix memory leak in fcgi_flt_http_headers

When the loop is continued early, the memory for param_rule is not freed. This
can leak memory per request, which will eventually consume all available memory
on the server.

This patch should fix the issue #750. It must be backported as far as 2.1.

4 years agoMINOR: log: adds counters on received syslog messages.
Emeric Brun [Thu, 9 Jul 2020 21:23:34 +0000 (23:23 +0200)] 
MINOR: log: adds counters on received syslog messages.

This patch adds a global counter of received syslog messages
and this one is exported on CLI "show info" as "CumRecvLogs".

This patch also updates internal conn counter and freq
of the listener and the proxy for each received log message to
prepare a further export on the "show stats".

4 years agoMEDIUM: log: adds log forwarding section.
Emeric Brun [Tue, 7 Jul 2020 12:19:42 +0000 (14:19 +0200)] 
MEDIUM: log: adds log forwarding section.

Log forwarding:

It is possible to declare one or multiple log forwarding section,
haproxy will forward all received log messages to a log servers list.

log-forward <name>
  Creates a new log forwarder proxy identified as <name>.

bind <addr> [param*]
  Used to configure a log udp listener to receive messages to forward.
  Only udp listeners are allowed, address must be prefixed using
  'udp@', 'udp4@' or 'udp6@'. This supports for all "bind" parameters
  found in 5.1 paragraph but most of them are irrelevant for udp/syslog case.

log global
log <address> [len <length>] [format <format>] [sample <ranges>:<smp_size>]
    <facility> [<level> [<minlevel>]]
  Used to configure target log servers. See more details on proxies
  documentation.
  If no format specified, haproxy tries to keep the incoming log format.
  Configured facility is ignored, except if incoming message does not
  present a facility but one is mandatory on the outgoing format.
  If there is no timestamp available in the input format, but the field
  exists in output format, haproxy will use the local date.

  Example:
    global
       log stderr format iso local7

    ring myring
        description "My local buffer"
        format rfc5424
        maxlen 1200
        size 32764
        timeout connect 5s
        timeout server 10s
        # syslog tcp server
        server mysyslogsrv 127.0.0.1:514 log-proto octet-count

    log-forward sylog-loadb
        bind udp4@127.0.0.1:1514
        # all messages on stderr
        log global
        # all messages on local tcp syslog server
        log ring@myring local0
        # load balance messages on 4 udp syslog servers
        log 127.0.0.1:10001 sample 1:4 local0
        log 127.0.0.1:10002 sample 2:4 local0
        log 127.0.0.1:10003 sample 3:4 local0
        log 127.0.0.1:10004 sample 4:4 local0

4 years agoMINOR: log: adds syslog udp message handler and parsing.
Emeric Brun [Tue, 7 Jul 2020 07:43:24 +0000 (09:43 +0200)] 
MINOR: log: adds syslog udp message handler and parsing.

This patch introduce a new fd handler used to parse syslog
message on udp.

The parsing function returns level, facility and metadata that
can be immediatly reused to forward message to a log server.

This handler is enabled on udp listeners if proxy is internally set
to mode PR_MODE_SYSLOG

4 years agoMEDIUM: log/sink: re-work and merge of build message API.
Emeric Brun [Mon, 6 Jul 2020 13:54:06 +0000 (15:54 +0200)] 
MEDIUM: log/sink: re-work and merge of build message API.

This patch merges build message code between sink and log
and introduce a new API based on struct ist array to
prepare message header with zero copy, targeting the
log forwarding feature.

Log format 'iso' and 'timed' are now avalaible on logs line.
A new log format 'priority' is also added.

4 years agoMEDIUM: udp: adds minimal proto udp support for message listeners.
Emeric Brun [Tue, 7 Jul 2020 07:46:09 +0000 (09:46 +0200)] 
MEDIUM: udp: adds minimal proto udp support for message listeners.

This patch introduce proto_udp.c targeting a further support of
log forwarding feature.

This code was originally produced by Frederic Lecaille working on
QUIC support and only minimal requirements for syslog support
have been merged.

4 years agoBUG/MEDIUM: log: issue mixing sampled to not sampled log servers.
Emeric Brun [Fri, 10 Jul 2020 13:47:11 +0000 (15:47 +0200)] 
BUG/MEDIUM: log: issue mixing sampled to not sampled log servers.

A boolean was mistakenly declared 'static THREAD_LOCAL' causing
the probe of a log to a 'not sampled' log server conditionned by
the last evaluated 'sampled log' server test on the same thread.

This results to unpredictable drops of logs on 'not sampled'
log servers as soon a 'sampled' log server is declared.

This patch removes the static THREAD_LOCAL attribute from this
boolean, fixing the issue and allowing to mix 'sampled' and
'not sampled' servers.

This fix should be backported in any branches which includes
the log sampling feature.

4 years agoBUG/MINOR: backend: fix potential null deref on srv_conn
Willy Tarreau [Wed, 15 Jul 2020 15:46:32 +0000 (17:46 +0200)] 
BUG/MINOR: backend: fix potential null deref on srv_conn

Commit 08016ab82 ("MEDIUM: connection: Add private connections
synchronously in session server list") introduced a build warning about
a potential null dereference which is actually true: in case a reuse
fails an we fail to allocate a new connection, we could crash. The
issue was already present earlier but the compiler couldn't detect
it since it was guarded by an independent condition.

This should be carefully backported to older versions (at least 2.2
and maybe 2.1), the change consists in only adding a test on srv_conn.

The whole sequence of "if" blocks is ugly there and would deserve being
cleaned up so that the !srv_conn condition is matched ASAP and the
assignment is done later. This would remove complicated conditions.

4 years agoBUG/MINOR: mux-fcgi: Set flags on the right stream field for empty FCGI_STDOUT
Christopher Faulet [Wed, 15 Jul 2020 14:04:49 +0000 (16:04 +0200)] 
BUG/MINOR: mux-fcgi: Set flags on the right stream field for empty FCGI_STDOUT

In fcgi_strm_handle_empty_stdout(), the FCGI_SF_ES_RCVD flag is set on "->state"
stream field instead of "->flags". It is obviously wrong. This bug is not
noticeable because the right state is set in the fcgi_process_demux() function a
bit later.

This patch must be backported as far as 2.1.

4 years agoBUG/MINOR: mux-fcgi: Set conn state to RECORD_P when skipping the record padding
Christopher Faulet [Wed, 15 Jul 2020 13:55:52 +0000 (15:55 +0200)] 
BUG/MINOR: mux-fcgi: Set conn state to RECORD_P when skipping the record padding

When the padding of a "stream" record (STDOUT or STDERR) is skipped, we must set
the connection state to RECORD_P. It is especially important if the padding is
not fully received.

This patch must be backported as far as 2.1.

4 years agoBUG/MINOR: mux-fcgi: Handle empty STDERR record
Christopher Faulet [Wed, 15 Jul 2020 13:46:30 +0000 (15:46 +0200)] 
BUG/MINOR: mux-fcgi: Handle empty STDERR record

As mentionned in the FastCGI specification, FCGI "streams" are series of
non-empty stream records (length != 0), followed by an empty one. It is properly
handled for FCGI_STDOUT records, but not for FCGI_STDERR ones. If an empty
FCGI_STDERR record is received, the connection is blocked waiting for data which
will never come.

To fix the bug, when an empty FCGI_STDERR record is received, we drop it, eating
the padding if any.

This patch should fix the issue #743. It must be backported as far as 2.1.

4 years agoMINOR: backend: Add sample fetches to get the server's weight
Christopher Faulet [Fri, 10 Jul 2020 14:03:45 +0000 (16:03 +0200)] 
MINOR: backend: Add sample fetches to get the server's weight

The following sample fetches have been added :

 * srv_iweight : returns the initial server's weight
 * srv_uweight : returns the user-visible server's weight
 * srv_weight  : returns the current (or effetctive) server's weight

The requested server must be passed as argument, evnetually preceded by the
backend name. For instance :

  srv_weight(back-http/www1)

4 years agoMINOR: contrib/prometheus-exporter: Add missing global and per-server metrics
Christopher Faulet [Fri, 10 Jul 2020 13:39:39 +0000 (15:39 +0200)] 
MINOR: contrib/prometheus-exporter: Add missing global and per-server metrics

Following metrics are now exported by the prometheus exporter to reflect recent
changes on HAProxy :

  * haproxy_process_failed_resolutions
  * haproxy_process_bytes_out_total
  * haproxy_process_spliced_bytes_out_total
  * haproxy_process_bytes_out_rate

and

 * haproxy_server_unsafe_idle_connections_current
 * haproxy_server_safe_idle_connections_current
 * haproxy_server_used_connections_current
 * haproxy_server_need_connections_current

4 years agoMINOR: raw_sock: Report the number of bytes emitted using the splicing
Christopher Faulet [Fri, 10 Jul 2020 11:56:30 +0000 (13:56 +0200)] 
MINOR: raw_sock: Report the number of bytes emitted using the splicing

In the continuity of the commit 7cf0e4517 ("MINOR: raw_sock: report global
traffic statistics"), we are now able to report the global number of bytes
emitted using the splicing. It can be retrieved in "show info" output on the
CLI.

Note this counter is always declared, regardless the splicing support. This
eases the integration with monitoring tools plugged on the CLI.

4 years agoBUG/MEDIUM: mux-h1: Continue to process request when switching in tunnel mode
Christopher Faulet [Fri, 10 Jul 2020 08:01:26 +0000 (10:01 +0200)] 
BUG/MEDIUM: mux-h1: Continue to process request when switching in tunnel mode

When input data are processed, if the request is switched in tunnel mode on a
protocol upgrade, we must continue the processing. Otherwise, pending input data
will only be processed on the next wakeup. So when new input data are received,
on a timeout expiration or shutdown. Worst, if the input buffer is full when it
happens, only a timeout or a shutdown will unblock the situation.

This patch should fix the issue #737. It must be backported as far as 1.9. The
bug does not seem to affect the 2.0 and 1.9 because, on a protocol upgrade, the
request is switched in tunnel mode when the response is sent to the client. But
the bug is present, so the backport remains necessary.

4 years agoCLEANUP: connection: remove unused field idle_time from the connection struct
Christopher Faulet [Thu, 2 Jul 2020 14:09:30 +0000 (16:09 +0200)] 
CLEANUP: connection: remove unused field idle_time from the connection struct

Thanks to previous changes, this field is now unused.

4 years agoMINOR: server: Factorize code to deal with connections removed from an idle list
Christopher Faulet [Thu, 2 Jul 2020 14:03:30 +0000 (16:03 +0200)] 
MINOR: server: Factorize code to deal with connections removed from an idle list

The srv_del_conn_from_list() function is now responsible to update the server
counters and the connection flags when a connection is removed from an idle list
(safe, idle or available). It is called when a connection is released or when a
connection is set as private. This function also removes the connection from the
idle list if necessary.

4 years agoMINOR: server: Factorize code to deal with reuse of server idle connections
Christopher Faulet [Thu, 2 Jul 2020 13:45:56 +0000 (15:45 +0200)] 
MINOR: server: Factorize code to deal with reuse of server idle connections

The srv_use_idle_conn() function is now responsible to update the server
counters and the connection flags when an idle connection is reused. The same
function is called when a new connection is created. This simplifies a bit the
connect_server() function.

4 years agoMINOR: session: Take care to decrement idle_conns counter in session_unown_conn
Christopher Faulet [Thu, 2 Jul 2020 13:56:23 +0000 (15:56 +0200)] 
MINOR: session: Take care to decrement idle_conns counter in session_unown_conn

So conn_free() only calls session_unown_conn() if necessary. The details are now
fully handled by session_unown_conn().

4 years agoMINOR: connection: Set the conncetion target during its initialisation
Christopher Faulet [Thu, 2 Jul 2020 07:19:54 +0000 (09:19 +0200)] 
MINOR: connection: Set the conncetion target during its initialisation

When a new connection is created, its target is always set just after. So the
connection target may set when it is created instead, during its initialisation
to be precise. It is the purpose of this patch. Now, conn_new() function is
called with the connection target as parameter. The target is then passed to
conn_init(). It means the target must be passed when cs_new() is called. In this
case, the target is only used when the conn-stream is created with no
connection. This only happens for tcpchecks for now.

4 years agoMINOR: connection: Use a dedicated function to look for a session's connection
Christopher Faulet [Wed, 1 Jul 2020 14:36:51 +0000 (16:36 +0200)] 
MINOR: connection: Use a dedicated function to look for a session's connection

The session_get_conn() must now be used to look for an available connection
matching a specific target for a given session. This simplifies a bit the
connect_server() function.