]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
4 years agoMEDIUM: resolvers: add a ref on server to the used A/AAAA answer item
Emeric Brun [Fri, 11 Jun 2021 08:08:05 +0000 (10:08 +0200)] 
MEDIUM: resolvers: add a ref on server to the used A/AAAA answer item

This patch adds a head list into answer items on servers which use
this record to set their IPs. It makes lookup on duplicated ip faster and
allow to check immediatly if an item is still valid renewing the IP.

This results in better performances on A/AAAA resolutions.

This is an optimization but it could avoid to trigger the haproxy's
internal wathdog in some circumstances. And for this reason
it should be backported as far we can (2.0 ?)

4 years agoBUG/MINOR: resolvers: answser item list was randomly purged or errors
Emeric Brun [Thu, 10 Jun 2021 13:25:25 +0000 (15:25 +0200)] 
BUG/MINOR: resolvers: answser item list was randomly purged or errors

In case of SRV records, The answer item list was purged by the
error callback of the first requester which considers the error
could not be safely ignored. It makes this item list unavailable
for subsequent requesters even if they consider the error
could be ignored.

On A resolution or do_resolve action error, the answer items were
never trashed.

This patch re-work the error callbacks and the code to check the return code
If a callback return 1, we consider the error was ignored and
the answer item list must be kept. At the opposite, If all error callbacks
of all requesters of the same resolution returns 0 the list will be purged

This patch should be backported as far as 2.0.

4 years agoCLEANUP: l7-retries: do not test the buffer before calling b_alloc()
Christopher Faulet [Fri, 11 Jun 2021 13:55:56 +0000 (15:55 +0200)] 
CLEANUP: l7-retries: do not test the buffer before calling b_alloc()

The return value is enough now to know if the allocation succeeded or
failed.

This cleanup was already pushed by Willy (f499f50) but a revert crushed
it. It may be backported to the 2.4 because the original patch was done on
this version.

4 years agoBUG/MINOR: h1-htx: Fix a signess bug with char data type when parsing chunk size
Christopher Faulet [Fri, 11 Jun 2021 11:39:06 +0000 (13:39 +0200)] 
BUG/MINOR: h1-htx: Fix a signess bug with char data type when parsing chunk size

On some platform, a char may be unsigned. Of course, we should not rely on
the signess of a char to be portable. Unfortunatly, since the commit
a835f3cb ("MINOR: h1-htx: Use a correlation table to speed-up small chunks
parsing") we rely on it to test the value retrieved from the hexadecimal
correlation table when the size of a chunk is parsed.

To fix the bug, we now test the result is in the range [0,15] with a bitwise
AND.

This patch should fix the issue #1272. It is 2.5-specific, no backport is
needed except if the commit above is backported.

4 years agoBUG/MINOR: mux-fcgi: Expose SERVER_SOFTWARE parameter by default
Christopher Faulet [Fri, 11 Jun 2021 11:34:42 +0000 (13:34 +0200)] 
BUG/MINOR: mux-fcgi: Expose SERVER_SOFTWARE parameter by default

As specified in the RFC3875 (section 4.1.17), this parameter must be set to
the name and version of the information server software making the CGI
request. Thus, it is now added to the default parameters defined by
HAProxy. It is set to the string "HAProxy $version".

This patch should fix the issue #1285 and must be backported as far as 2.2.

4 years agoBUG/MAJOR: htx: Fix htx_defrag() when an HTX block is expanded
Christopher Faulet [Wed, 9 Jun 2021 15:30:40 +0000 (17:30 +0200)] 
BUG/MAJOR: htx: Fix htx_defrag() when an HTX block is expanded

When an HTX block is expanded, a defragmentation may be performed first to
have enough space to copy the new data. When it happens, the meta data of
the HTX message must take account of the new data length but copied data are
still unchanged at this stage (because we need more space to update the
message content). And here there is a bug because the meta data are updated
by the caller. It means that when the blocks content is copied, the new
length is already set. Thus a block larger than the reality is copied and
data outside the buffer may be accessed, leading to a crash.

To fix this bug, htx_defrag() is updated to use an extra argument with the
new meta data to use for the referenced block. Thus the caller does not need
to update the HTX message by itself. However, it still have to update the
data.

Most of time, the bug will be encountered in the HTTP compression
filter. But, even if it is highly unlikely, in theory it is also possible to
hit it when a HTTP header (or only its value) is replaced or when the
start-line is changed.

This patch must be backported as far as 2.0.

4 years agoREGTESTS: ssl: show_ssl_ocspresponce.vtc is broken with BoringSSL
William Lallemand [Fri, 11 Jun 2021 08:03:08 +0000 (10:03 +0200)] 
REGTESTS: ssl: show_ssl_ocspresponce.vtc is broken with BoringSSL

The `show ssl ocsp-response` feature is not available with BoringSSL,
but we don't have a way to disable this feature only with boringSSL on
the CI. Disable the reg-test until we do.

4 years agoBUG/MEDIUM: errors: include missing obj_type file
Willy Tarreau [Fri, 11 Jun 2021 05:31:57 +0000 (07:31 +0200)] 
BUG/MEDIUM: errors: include missing obj_type file

A tiny change in commit 6af81f80f ("MEDIUM: errors: implement parsing
context type") triggered an awful bug in gcc 5 and below (4.7.4 to 5.5
confirmed affected, at least on aarch64/mips/x86_64) causing the startup
to loop forever in acl_find_target().

This was tracked down to the acl.c file seeing a different definition
of the struct proxy than other files. The reason for this is that it
sees an unpacked "enum obj_type" (4 bytes) while others see it packed
(1 byte), thus all fields in the struct are having a different
alignment, and the "acl" list is shifted one pointer to the next struct
and seems to loop onto itself.

The commit above did nothing more than adding "enum obj_type *obj" in a
new struct without including obj_type.h, and that was apparently enough
for the compiler to internally declare obj_type as a regular enum and
silently ignore the packed attribute that it discovers later, so depending
on the order of includes, some files would see it as 1 byte and others as
4.

This patch simply adds the missing include but due to the nature of the
bug, probably that creating a special "packed_enum" definition to disable
the packed attribute on such compilers could be a safer option.

No backport is needed as this is only in -dev.

4 years agoBUILD: ssl: Fix compilation with BoringSSL
Remi Tricot-Le Breton [Thu, 10 Jun 2021 16:10:32 +0000 (18:10 +0200)] 
BUILD: ssl: Fix compilation with BoringSSL

The ifdefs surrounding the "show ssl ocsp-response" functionality that
were supposed to disable the code with BoringSSL were built the wrong
way.

It does not need to be backported.

4 years agoMEDIUM: pools: remove the locked pools implementation
Willy Tarreau [Thu, 10 Jun 2021 15:31:48 +0000 (17:31 +0200)] 
MEDIUM: pools: remove the locked pools implementation

Now that the modified lockless variant does not need a DWCAS anymore,
there's no reason to keep the much slower locked version, so let's
just get rid of it.

4 years agoCLEANUP: pools: remove now unused seq and pool_free_list
Willy Tarreau [Thu, 10 Jun 2021 06:46:28 +0000 (08:46 +0200)] 
CLEANUP: pools: remove now unused seq and pool_free_list

These ones were only used by the lockless implementation and are not
needed anymore.

4 years agoBUG/MAJOR: pools: fix possible race with free() in the lockless variant
Willy Tarreau [Wed, 9 Jun 2021 16:59:58 +0000 (18:59 +0200)] 
BUG/MAJOR: pools: fix possible race with free() in the lockless variant

In GH issue #1275, Fabiano Nunes Parente provided a nicely detailed
report showing reproducible crashes under musl. Musl is one of the libs
coming with a simple allocator for which we prefer to keep the shared
cache. On x86 we have a DWCAS so the lockless implementation is enabled
for such libraries.

And this implementation has had a small race since day one: the allocator
will need to read the first object's <next> pointer to place it into the
free list's head. If another thread picks the same element and immediately
releases it, while both the local and the shared pools are too crowded, it
will be freed to the OS. If the libc's allocator immediately releases it,
the memory area is unmapped and we can have a crash while trying to read
that pointer. However there is no problem as long as the item remains
mapped in memory because whatever value found there will not be placed
into the head since the counter will have changed.

The probability for this to happen is extremely low, but as analyzed by
Fabiano, it increases with the buffer size. On 16 threads it's relatively
easy to reproduce with 2MB buffers above 200k req/s, where it should
happen within the first 20 seconds of traffic usually.

This is a structural issue for which there are two non-trivial solutions:
  - place a read lock in the alloc call and a barrier made of lock/unlock
    in the free() call to force to serialize operations; this will have
    a big performance impact since free() is already one of the contention
    points;

  - change the allocator to use a self-locked head, similar to what is
    done in the MT_LISTS. This requires two memory writes to the head
    instead of a single one, thus the overhead is exactly one memory
    write during alloc and one during free;

This patch implements the second option. A new POOL_DUMMY pointer was
defined for the locked pointer value, allowing to both read and lock it
with a single xchg call. The code was carefully optimized so that the
locked period remains the shortest possible and that bus writes are
avoided as much as possible whenever the lock is held.

Tests show that while a bit slower than the original lockless
implementation on large buffers (2MB), it's 2.6 times faster than both
the no-cache and the locked implementation on such large buffers, and
remains as fast or faster than the all implementations when buffers are
48k or higher. Tests were also run on arm64 with similar results.

Note that this code is not used on modern libcs featuring a fast allocator.

A nice benefit of this change is that since it removes a dependency on
the DWCAS, it will be possible to remove the locked implementation and
replace it with this one, that is then usable on all systems, thus
significantly increasing their performance with large buffers.

Given that lockless pools were introduced in 1.9 (not supported anymore),
this patch will have to be backported as far as 2.0. The code changed
several times in this area and is subject to many ifdefs which will
complicate the backport. What is important is to remove all the DWCAS
code from the shared cache alloc/free lockless code and replace it with
this one. The pool_flush() code is basically the same code as the
allocator, retrieving the whole list at once. If in doubt regarding what
barriers to use in older versions, it's safe to use the generic ones.

This patch depends on the following previous commits:

 - MINOR: pools: do not maintain the lock during pool_flush()
 - MINOR: pools: call malloc_trim() under thread isolation
 - MEDIUM: pools: use a single pool_gc() function for locked and lockless

The last one also removes one occurrence of an unneeded DWCAS in the
code that was incompatible with this fix. The removal of the now unused
seq field will happen in a future patch.

Many thanks to Fabiano for his detailed report, and to Olivier for
his help on this issue.

4 years agoMEDIUM: pools: use a single pool_gc() function for locked and lockless
Willy Tarreau [Thu, 10 Jun 2021 08:21:35 +0000 (10:21 +0200)] 
MEDIUM: pools: use a single pool_gc() function for locked and lockless

Locked and lockless shared pools don't need to use a different pool_gc()
function because this function isolates itself during the operation, so
we do not need to rely on DWCAS nor any atomic operation in fact. Let's
just get rid of the lockless one in favor of the simple one. This should
even result in a faster execution.

The ifdefs were slightly moved so that we can have pool_gc() defined
as soon as there are global pools, this avoids duplicating the function.

4 years agoMINOR: pools: call malloc_trim() under thread isolation
Willy Tarreau [Thu, 10 Jun 2021 06:40:16 +0000 (08:40 +0200)] 
MINOR: pools: call malloc_trim() under thread isolation

pool_gc() was adjusted to run under thread isolation by commit c0e2ff202
("MEDIUM: memory: make pool_gc() run under thread isolation") so that the
underlying malloc() and free() don't compete between threads during these
potentially aggressive moments (especially when mmap/munmap are involved).

Commit 88366c292 ("MEDIUM: pools: call malloc_trim() from pool_gc()")
later added a call to malloc_trim() but made it outside of the thread
isolation, which is contrary to the principle explained above. Also it
missed it in the locked version, meaning that those without a lockless
implementation cannot benefit from trimming.

This patch fixes that by calling it before thread_release() in both
places.

4 years agoMINOR: pools: do not maintain the lock during pool_flush()
Willy Tarreau [Thu, 10 Jun 2021 05:13:04 +0000 (07:13 +0200)] 
MINOR: pools: do not maintain the lock during pool_flush()

The locked version of pool_flush() is absurd, it locks the pool for each
and every element to be released till the end. Not only this is extremely
inefficient, but it may even never finish if other threads spend their
time refilling the pool. The only case where this can happen is during
soft-stop so the risk remains limited, but it should be addressed.

4 years agoBUG/MINOR: pools: make DEBUG_UAF always write to the to-be-freed location
Willy Tarreau [Thu, 10 Jun 2021 15:20:19 +0000 (17:20 +0200)] 
BUG/MINOR: pools: make DEBUG_UAF always write to the to-be-freed location

Since the code was reorganized, DEBUG_UAF was still tested in the locked
pool code despite pools being disabled when DEBUG_UAF is used. Let's move
the test to pool_put_to_os() which is the one that is always called in
this condition.

The impact is only a possible misleading analysis during a troubleshooting
session due to a missing double-frees or free of const area test that is
normally already dealt with by the underlying code anyway. In practice it's
unlikely anyone will ever notice.

This should only be backported to 2.4.

4 years agoBUG/MINOR: pools: fix a possible memory leak in the lockless pool_flush()
Willy Tarreau [Thu, 10 Jun 2021 04:54:22 +0000 (06:54 +0200)] 
BUG/MINOR: pools: fix a possible memory leak in the lockless pool_flush()

The lockless version of pool_flush() had a leftover of the original
version causing the pool's first entry to be set to NULL at the end.
The problem is that it does this outside of any lock and in a non-
atomic way, so that any concurrent alloc+free would result in a lost
object.

The risk is low and the consequence even lower, given that pool_flush()
is only used in pool_destroy() (hence single-threaded) or by stream_free()
during a soft-stop (not the place where most allocations happen), so in
the worst case it could result in valgrind complaining on soft-stop.

The bug was introduced with the first version of the code, in 1.9, so
the fix can be backported to all stable versions.

4 years agoBUG/MINOR: server: explicitly set "none" init-addr for dynamic servers
Amaury Denoyelle [Thu, 10 Jun 2021 15:34:10 +0000 (17:34 +0200)] 
BUG/MINOR: server: explicitly set "none" init-addr for dynamic servers

Define srv.init_addr_methods to SRV_IADDR_NONE on 'add server' CLI
handler. This explicitly states that no resolution will be made on the
server creation.

This is not a real bug as the default value (SRV_IADDR_END) has the same
effect in practice. However the intent is clearer and prevent to use the
default "libc,last" by mistake which cannot execute on runtime (blocking
call + file access via gethostbyname/getaddrinfo).

The doc is also updated to reflect this limitation.

This should be backported up to 2.4.

4 years agoREGTESTS: ssl: Add "show ssl ocsp-response" test
Remi Tricot-Le Breton [Thu, 10 Jun 2021 11:51:16 +0000 (13:51 +0200)] 
REGTESTS: ssl: Add "show ssl ocsp-response" test

This file adds tests for the new "show ssl ocsp-response" command and
the new "show ssl cert foo.pem.ocsp" and "show ssl cert *foo.pem.ocsp"
special cases. They are all used to display information about an OCSP
response, committed or not.

4 years agoMINOR: ssl: Add the "show ssl cert foo.pem.ocsp" CLI command
Remi Tricot-Le Breton [Thu, 10 Jun 2021 11:51:15 +0000 (13:51 +0200)] 
MINOR: ssl: Add the "show ssl cert foo.pem.ocsp" CLI command

Add the ability to dump an OCSP response details through a call to "show
ssl cert cert.pem.ocsp". It can also be used on an ongoing transaction
by prefixing the certificate name with a '*'.
Even if the ckch structure holds an ocsp_response buffer, we still need
to look for the actual ocsp response entry in the ocsp response tree
rather than just dumping the ckch's buffer details because when updating
an ocsp response through a "set ssl ocsp-response" call, the
corresponding buffer in the ckch is not updated accordingly. So this
buffer, even if it is not empty, might hold an outdated ocsp response.

4 years agoMINOR: ssl: Add the OCSP entry key when displaying the details of a certificate
Remi Tricot-Le Breton [Thu, 10 Jun 2021 11:51:14 +0000 (13:51 +0200)] 
MINOR: ssl: Add the OCSP entry key when displaying the details of a certificate

This patch adds an "OCSP Response Key" information in the output of a
"show ssl cert <certfile>" call. The key can then be used in a "show ssl
ocsp-response <key>" CLI command.

4 years agoMINOR: ssl: Add new "show ssl ocsp-response" CLI command
Remi Tricot-Le Breton [Thu, 10 Jun 2021 11:51:13 +0000 (13:51 +0200)] 
MINOR: ssl: Add new "show ssl ocsp-response" CLI command

This patch adds the "show ssl ocsp-response [<id>]" CLI command. This
command can be used to display the IDs of the OCSP tree entries along
with details about the entries' certificate ID (issuer's name and key
hash + serial number), or to display the details of a single
ocsp-response if an ID is given. The details displayed in this latter
case are the ones shown by a "openssl ocsp -respin <ocsp-response>
-text" call.

4 years agoMINOR: ssl: Keep the actual key length in the certificate_ocsp structure
Remi Tricot-Le Breton [Thu, 10 Jun 2021 11:51:12 +0000 (13:51 +0200)] 
MINOR: ssl: Keep the actual key length in the certificate_ocsp structure

The OCSP tree entry key is a serialized version of the OCSP_CERTID of
the entry which is stored in a buffer that can be at most 128 bytes.
Depending on the length of the serial number, the actual non-zero part
of the key can be smaller than 128 bytes and this new structure member
allows to know how many of the bytes are filled. It will be useful when
dumping the key (in a "show ssl cert <cert>" output for instance).

4 years agoBUG/MEDIUM: compression: Add a flag to know the filter is still processing data
Christopher Faulet [Wed, 9 Jun 2021 15:12:44 +0000 (17:12 +0200)] 
BUG/MEDIUM: compression: Add a flag to know the filter is still processing data

Since the commit acfd71b97 ("BUG/MINOR: http-comp: Preserve
HTTP_MSGF_COMPRESSIONG flag on the response"), there is no more flag to know
when the compression ends. This means it is possible to finish the
compression several time if there are trailers.

So, we reintroduce almost the same mechanism but with a dedicated flag. So
now, there is a bits field in the compression filter context.

The commit above is marked to be backported as far as 2.0. Thus this patch
must also be backported as far as 2.0.

4 years agoBUG/MEDIUM: compression: Properly get the next block to iterate on payload
Christopher Faulet [Wed, 9 Jun 2021 15:04:37 +0000 (17:04 +0200)] 
BUG/MEDIUM: compression: Properly get the next block to iterate on payload

When a DATA block is compressed, or when the compression context is finished
on a TLR/EOT block, the next block used to loop on the HTX message must be
refreshed because a defragmentation may have occurred.

This bug was introduced when the EOM block was removed in 2.4. Thus, this
patch must be backported to 2.4.

4 years agoBUG/MEDIUM: compression: Fix loop skipping unused blocks to get the next block
Christopher Faulet [Wed, 9 Jun 2021 14:59:02 +0000 (16:59 +0200)] 
BUG/MEDIUM: compression: Fix loop skipping unused blocks to get the next block

In comp_http_payload(), the loop skipping unused blocks is buggy and may
lead to a infinite loop if the first next block is unused. Indeed instead of
iterating on blocks, we always retrieve the same one because <blk> is used
instead of <next> to get the next block.

This bug was introduced when the EOM block was removed in 2.4. Thus, this
patch must be backported to 2.4.

4 years agoSCRIPTS: opentracing: enable parallel builds in build-ot.sh
Willy Tarreau [Thu, 10 Jun 2021 05:35:15 +0000 (07:35 +0200)] 
SCRIPTS: opentracing: enable parallel builds in build-ot.sh

The script didn't make use of parallel builds, which roughly cut the
build time in half with 4 cores. This can help a bit with the CI.

4 years agoBUG/MEDIUM: opentracing: initialization before establishing daemon and/or chroot...
Miroslav Zagorac [Wed, 9 Jun 2021 23:23:15 +0000 (01:23 +0200)] 
BUG/MEDIUM: opentracing: initialization before establishing daemon and/or chroot mode

This patch solves the problem reported in github issue #1204, where the
OpenTracing filter cannot communicate with the selected tracer if HAProxy
is run in daemon mode.

This commit also solves github issue #1274, where the problem manifests
itself when using the 'chroot' keyword in the HAProxy configuration.

This is solved so that the initialization of the OpenTracing plugin is
split into two operations, first the plugin (dynamic library) is loaded
before switching the HAProxy to daemon mode (or chroot) and then the
tracer thread is started.

This means that nothing is retrieved from the file system in runtime.

After applying this commit, opentracing C wrapper version 1.1.0 should be
used because the earlier version does not have separated initialization
functions.

This resolves GitHub issues #1204 and #1274.

4 years agoRevert "BUG/MINOR: opentracing: initialization after establishing daemon mode"
Miroslav Zagorac [Wed, 9 Jun 2021 23:19:13 +0000 (01:19 +0200)] 
Revert "BUG/MINOR: opentracing: initialization after establishing daemon mode"

This reverts commit f2263435d71964d1aa3eb80df6464500696c0515.

This commit is unnecessary because although it solves the problem of using
the OpenTracing filter in daemon mode, it does not solve the same problem
if chroot is used.

The following commit related to the OpenTracing filter solves both problems
efficiently.

4 years agoBUG/MINOR: ssl: OCSP stapling does not work if expire too far in the future
Remi Tricot-Le Breton [Wed, 9 Jun 2021 15:16:18 +0000 (17:16 +0200)] 
BUG/MINOR: ssl: OCSP stapling does not work if expire too far in the future

The wey the "Next Update" field of the OCSP response is converted into a
timestamp relies on the use of signed integers for the year and month so
if the calculated timestamp happens to overflow INT_MAX, it ends up
being seen as negative and the OCSP response being dwignored in
ssl_sock_ocsp_stapling_cbk (because of the "ocsp->expire < now.tv_sec"
test).

It could be backported to all stable branches.

4 years agoBUILD: make tune.ssl.keylog available again
William Lallemand [Wed, 9 Jun 2021 14:46:12 +0000 (16:46 +0200)] 
BUILD: make tune.ssl.keylog available again

Since commit 04a5a44 ("BUILD: ssl: use HAVE_OPENSSL_KEYLOG instead of
OpenSSL versions") the "tune.ssl.keylog" feature is broken because
HAVE_OPENSSL_KEYLOG does not exist.

Replace this by a HAVE_SSL_KEYLOG which is defined in openssl-compat.h.
Also add an error when not built with the right openssl version.

Must be backported as far as 2.3.

4 years agoCI: Make matrix.py executable and add shebang
Tim Duesterhus [Tue, 8 Jun 2021 13:14:35 +0000 (15:14 +0200)] 
CI: Make matrix.py executable and add shebang

It's a script, allow executing this as a script without needing to invoke
`python3` manually.

4 years agoBUG: errors: remove printf positional args for user messages context
Amaury Denoyelle [Mon, 7 Jun 2021 17:24:10 +0000 (19:24 +0200)] 
BUG: errors: remove printf positional args for user messages context

Change the algorithm for the generation of the user messages context
prefix. Remove the dubious API relying on optional printf positional
arguments. This may be non portable, and in fact the CI glibc crashes
with the following error when some arguments are not present in the
format string :

"invalid %N$ use detected".

Now, a fixed buffer attached to the context instance is allocated once
for the program lifetime. Then call repeatedly snprintf with the
optional arguments of context if present to build the context string.
The buffer is deallocated via a per-thread free handler.

This does not need to be backported.

4 years agoMINOR: haproxy: Add `-cc` argument
Maximilian Mader [Sat, 5 Jun 2021 22:50:22 +0000 (00:50 +0200)] 
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>
4 years agoCLEANUP: tools: Make errptr const in `parse_line()`
Maximilian Mader [Sat, 5 Jun 2021 22:50:21 +0000 (00:50 +0200)] 
CLEANUP: tools: Make errptr const in `parse_line()`

This change is for consistency with `cfg_eval_condition()`.

4 years agoCLEANUP: cfgparse: Remove duplication of `MAX_LINE_ARGS + 1`
Tim Duesterhus [Sat, 5 Jun 2021 22:50:20 +0000 (00:50 +0200)] 
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.

4 years agoDOC: use the req.ssl_sni in examples
Alex [Sat, 5 Jun 2021 11:23:08 +0000 (13:23 +0200)] 
DOC: use the req.ssl_sni in examples

This patch should be backported to at least 2.0

4 years agoMINOR: server: use ha_alert in server parsing functions
Amaury Denoyelle [Fri, 28 May 2021 14:35:05 +0000 (16:35 +0200)] 
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.

4 years agoMINOR: server: use parsing ctx for server init addr
Amaury Denoyelle [Fri, 28 May 2021 09:01:52 +0000 (11:01 +0200)] 
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.

4 years agoREORG: config: use parsing ctx for server config check
Amaury Denoyelle [Fri, 28 May 2021 08:34:01 +0000 (10:34 +0200)] 
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.

4 years agoREORG: server: use parsing ctx for server parsing
Amaury Denoyelle [Fri, 28 May 2021 09:00:18 +0000 (11:00 +0200)] 
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.

4 years agoMINOR: log: define server user message format
Amaury Denoyelle [Fri, 28 May 2021 08:36:56 +0000 (10:36 +0200)] 
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.

4 years agoMINOR: errors: specify prefix "config" for parsing output
Amaury Denoyelle [Fri, 4 Jun 2021 16:22:08 +0000 (18:22 +0200)] 
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.

4 years agoMINOR: log: display exec path on first warning
Amaury Denoyelle [Fri, 28 May 2021 07:57:10 +0000 (09:57 +0200)] 
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.

4 years agoMINOR: errors: use user messages context in print_message
Amaury Denoyelle [Thu, 27 May 2021 13:46:19 +0000 (15:46 +0200)] 
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.

4 years agoMEDIUM: errors: implement parsing context type
Amaury Denoyelle [Thu, 27 May 2021 13:45:28 +0000 (15:45 +0200)] 
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.

4 years agoMINOR: log: do not discard stderr when starting is over
Amaury Denoyelle [Wed, 26 May 2021 09:05:45 +0000 (11:05 +0200)] 
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.

4 years agoMEDIUM: errors: implement user messages buffer
Amaury Denoyelle [Wed, 26 May 2021 09:05:22 +0000 (11:05 +0200)] 
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.

4 years agoCLEANUP: server: fix cosmetic of error message on sni parsing
Amaury Denoyelle [Fri, 28 May 2021 09:01:22 +0000 (11:01 +0200)] 
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.

4 years agoREORG: errors: split errors reporting function from log.c
Amaury Denoyelle [Fri, 4 Jun 2021 09:20:32 +0000 (11:20 +0200)] 
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.

4 years agoMINOR: errors: allow empty va_args for diag variadic macro
Amaury Denoyelle [Mon, 31 May 2021 12:26:20 +0000 (14:26 +0200)] 
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.

4 years agoCI: github actions: -Wno-deprecated-declarations with OpenSSL 3.0.0
William Lallemand [Mon, 7 Jun 2021 13:27:57 +0000 (15:27 +0200)] 
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.

4 years agoCI: github actions: add OpenSSL-3.0.0 builds
Ilya Shipitsin [Sat, 5 Jun 2021 03:06:59 +0000 (03:06 +0000)] 
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

4 years agoCLEANUP: reg-tests: Remove obsolete no-htx parameter for reg-tests
Tim Duesterhus [Mon, 31 May 2021 21:07:29 +0000 (23:07 +0200)] 
CLEANUP: reg-tests: Remove obsolete no-htx parameter for reg-tests

The legacy HTTP subsystem has been removed. HTX is always enabled.

4 years agoCLEANUP: backend: fix incorrect comments on locking conditions for lb functions
Willy Tarreau [Tue, 1 Jun 2021 14:58:31 +0000 (16:58 +0200)] 
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.

4 years agoREGTESTS: Fix http_abortonclose.vtc to support -1 status for some client aborts
Christopher Faulet [Wed, 2 Jun 2021 15:23:47 +0000 (17:23 +0200)] 
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.

4 years agoMINOR: http-ana: Use -1 status for client aborts during queuing and connect
Christopher Faulet [Wed, 2 Jun 2021 12:07:24 +0000 (14:07 +0200)] 
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.

4 years agoBUILD: fix compilation for OpenSSL-3.0.0-alpha17
William Lallemand [Wed, 2 Jun 2021 14:09:11 +0000 (16:09 +0200)] 
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.

4 years agoCLEANUP: mux-fcgi: Don't needlessly store result of data/trailers parsing
Christopher Faulet [Wed, 2 Jun 2021 10:04:40 +0000 (12:04 +0200)] 
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.

4 years agoDOC/MINOR: move uuid in the configuration to the right alphabetical order
Alexandar Lazic [Mon, 31 May 2021 22:27:01 +0000 (00:27 +0200)] 
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

4 years agoBUG/MINOR: vars: Be sure to have a session to get checks variables
Christopher Faulet [Wed, 2 Jun 2021 09:48:42 +0000 (11:48 +0200)] 
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.

4 years agoMINOR: backend: Don't release SI endpoint anymore in connect_server()
Christopher Faulet [Tue, 1 Jun 2021 13:54:49 +0000 (15:54 +0200)] 
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.

4 years agoBUG/MAJOR: stream-int: Release SI endpoint on server side ASAP on retry
Christopher Faulet [Tue, 1 Jun 2021 12:06:05 +0000 (14:06 +0200)] 
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.

4 years agoCLEANUP: http-ana: Remove useless if statement about L7 retries
Christopher Faulet [Mon, 31 May 2021 09:45:24 +0000 (11:45 +0200)] 
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.

4 years agoBUG/MINOR: proxy: Missing calloc return value check in chash_init_server_tree
Remi Tricot-Le Breton [Wed, 19 May 2021 14:40:28 +0000 (16:40 +0200)] 
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.

4 years agoBUG/MINOR: http: Missing calloc return value check in make_arg_list
Remi Tricot-Le Breton [Wed, 19 May 2021 10:00:54 +0000 (12:00 +0200)] 
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.

4 years agoBUG/MINOR: http: Missing calloc return value check while parsing redirect rule
Remi Tricot-Le Breton [Wed, 19 May 2021 09:32:04 +0000 (11:32 +0200)] 
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.

4 years agoBUG/MINOR: worker: Missing calloc return value check in mworker_env_to_proc_list
Remi Tricot-Le Breton [Wed, 19 May 2021 08:45:12 +0000 (10:45 +0200)] 
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.

4 years agoBUG/MINOR: compression: Missing calloc return value check in comp_append_type/algo
Remi Tricot-Le Breton [Mon, 17 May 2021 08:35:08 +0000 (10:35 +0200)] 
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.

4 years agoBUG/MINOR: http: Missing calloc return value check while parsing tcp-request rule
Remi Tricot-Le Breton [Mon, 17 May 2021 08:08:16 +0000 (10:08 +0200)] 
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.

4 years agoBUG/MINOR: http: Missing calloc return value check while parsing tcp-request/tcp...
Remi Tricot-Le Breton [Wed, 12 May 2021 16:24:18 +0000 (18:24 +0200)] 
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.

4 years agoBUG/MINOR: proxy: Missing calloc return value check in proxy_defproxy_cpy
Remi Tricot-Le Breton [Wed, 12 May 2021 16:07:27 +0000 (18:07 +0200)] 
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.

4 years agoBUG/MINOR: proxy: Missing calloc return value check in proxy_parse_declare
Remi Tricot-Le Breton [Wed, 12 May 2021 16:04:46 +0000 (18:04 +0200)] 
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.

4 years agoBUG/MINOR: http: Missing calloc return value check in parse_http_req_capture
Remi Tricot-Le Breton [Wed, 12 May 2021 15:54:17 +0000 (17:54 +0200)] 
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.

4 years agoBUG/MINOR: ssl: Missing calloc return value check in ssl_init_single_engine
Remi Tricot-Le Breton [Wed, 12 May 2021 15:45:21 +0000 (17:45 +0200)] 
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.

4 years agoBUG/MINOR: peers: Missing calloc return value check in peers_register_table
Remi Tricot-Le Breton [Wed, 12 May 2021 15:39:04 +0000 (17:39 +0200)] 
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.

4 years agoBUG/MINOR: server: Missing calloc return value check in srv_parse_source
Remi Tricot-Le Breton [Wed, 12 May 2021 07:44:06 +0000 (09:44 +0200)] 
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.

4 years agoDOC: intro: Fix typo in starter guide
Mark Mullan [Sat, 22 May 2021 18:15:02 +0000 (11:15 -0700)] 
DOC: intro: Fix typo in starter guide

s/sned/send.

4 years agoMINOR: cfgparse: Fail when encountering extra arguments in macro
Tim Duesterhus [Wed, 26 May 2021 15:45:33 +0000 (17:45 +0200)] 
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.

4 years agoMINOR: http-ana: Perform L7 retries because of status codes in response analyser
Christopher Faulet [Wed, 26 May 2021 11:14:39 +0000 (13:14 +0200)] 
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.

4 years agoBUG/MINOR: http-ana: Handle L7 retries on refused early data before K/A aborts
Christopher Faulet [Wed, 26 May 2021 10:15:37 +0000 (12:15 +0200)] 
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.

4 years agoBUG/MINOR: http-ana: Send the right error if max retries is reached on L7 retry
Christopher Faulet [Wed, 26 May 2021 08:31:06 +0000 (10:31 +0200)] 
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.

4 years agoRevert "MEDIUM: http-ana: Deal with L7 retries in HTTP analysers"
Christopher Faulet [Fri, 21 May 2021 11:46:14 +0000 (13:46 +0200)] 
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.

4 years agoCLEANUP: mux-h1: Rename functions parsing input buf and filling output buf
Christopher Faulet [Tue, 16 Feb 2021 17:32:08 +0000 (18:32 +0100)] 
CLEANUP: mux-h1: Rename functions parsing input buf and filling output buf

Main functions are renamed h1_process_demux() and h1_process_mux() to be
consistent with the H2 mux. For the same reason,
h1_process_header/data/tralers) functions, responsible to parse incoming
data are renamed with "h1_handle_" prefix.

4 years agoMINOR: muxes/h1-htx: Realign input buffer using b_slow_realign_ofs()
Christopher Faulet [Thu, 4 Feb 2021 10:01:51 +0000 (11:01 +0100)] 
MINOR: muxes/h1-htx: Realign input buffer using b_slow_realign_ofs()

Input buffers have never output data. So, use b_slow_realign_ofs() function
instead of b_slow_realign(). It is a slighly simpler function. And in the H1
mux, it allows a realign by setting the input buffer head to permit
zero-copies.

4 years agoMINOR: buf: Add function to realign a buffer with a specific head position
Christopher Faulet [Thu, 4 Feb 2021 09:54:37 +0000 (10:54 +0100)] 
MINOR: buf: Add function to realign a buffer with a specific head position

b_slow_realign() function may be used to realign a buffer with a given
amount of output data, eventually 0. In such case, the head is set to
0. This function is not designed to be used with input only buffers, like
those used in the muxes. It is the purpose of b_slow_realign_ofs()
function. It does almost the same, realign a buffer. But it do so by setting
the buffer head to a specific offset.

4 years agoMINOR: h1-htx: Use a correlation table to speed-up small chunks parsing
Christopher Faulet [Fri, 21 May 2021 09:31:35 +0000 (11:31 +0200)] 
MINOR: h1-htx: Use a correlation table to speed-up small chunks parsing

Instead of using hex2i() to convert an hexa digit to an integer in the
function parsing small chunks, we now use a table because it is faster.

4 years agoMEDIUM: h1-htx: Add a function to parse contiguous small chunks
Christopher Faulet [Fri, 21 May 2021 09:05:12 +0000 (11:05 +0200)] 
MEDIUM: h1-htx: Add a function to parse contiguous small chunks

Add h1_parse_full_contig_chunks() function to parse full contiguous chunks.
This function neither handles incomplete chunks nor wrapping buffers. It is
designed to efficiently parse a buffer with several small chunks. Of course,
there is no zero copy here because it is not possible. This function is a
bit tricky and all changes may a have a impact. This one may probably be
optimized, but it is good enough for now and not too complex.

The main function (h1_parse_msg_chunks) always tries to use this function
when the HTTP parser is waiting for a chunk size. In this case, there is no
zero-copy, so there is no reason to call the generic version to parse the
chunk. However, if some unparsed data remain after this step, the generic
function is called. This way, wrapping data and incomplete chunks may be
parsed.

Quick tests show it is now slightly faster in all cases than the legacy
mode.

4 years agoMEDIUM: h1-htx: Split function to parse a chunk and the loop on the buffer
Christopher Faulet [Fri, 21 May 2021 08:56:24 +0000 (10:56 +0200)] 
MEDIUM: h1-htx: Split function to parse a chunk and the loop on the buffer

A generic function is now used to only parse the current chunk (h1_parse_chunk)
and the main one (h1_parse_msg_chunks) is used to loop on the buffer and relies
on the first one. This change is mandatory to be able to use an optimized
function to parse contiguous small chunks.

4 years agoMINOR: h1-htx: Move HTTP chunks parsing into a dedicated function
Christopher Faulet [Wed, 3 Feb 2021 10:51:24 +0000 (11:51 +0100)] 
MINOR: h1-htx: Move HTTP chunks parsing into a dedicated function

Chunked data are now parsed in a dedicated function. This way, it will be
possible to have two functions to parse chunked messages. The current one
for messages with large chunks and an other one to parse messages with small
chunks.

The parsing of small chunks is really sensitive because it may be used as a
DoS attack. So we must be carefull to have an optimized function to parse
such messages.

4 years agoMINOR: mux-h1/mux-fcgi: Don't needlessly loop on data parsing
Christopher Faulet [Tue, 2 Feb 2021 20:16:03 +0000 (21:16 +0100)] 
MINOR: mux-h1/mux-fcgi: Don't needlessly loop on data parsing

Because the function parsing H1 data is now able to handle wrapping input
buffers, there is no reason to loop anymore in the muxes to be sure to parse
wrapping data.

4 years agoMEDIUM: h1-htx: Adapt H1 data parsing to copy wrapping data in one call
Christopher Faulet [Tue, 2 Feb 2021 18:40:07 +0000 (19:40 +0100)] 
MEDIUM: h1-htx: Adapt H1 data parsing to copy wrapping data in one call

Since the beginning, wrapping input data are parsed and copied in 2 steps to
not deal with the wrapping in H1 parsing functions. But there is no reason
to do so. This needs 2 calls to parsing functions. This also means, most of
time, when the input buffer does not wrap, there is an extra call for
nothing.

Thus, now, the data parsing functions try to copy as much data as possible,
handling wrapping buffer if necessary.

4 years agoMINOR: h1-htx: Update h1 parsing functions to return result as a size_t
Christopher Faulet [Mon, 1 Feb 2021 15:37:28 +0000 (16:37 +0100)] 
MINOR: h1-htx: Update h1 parsing functions to return result as a size_t

h1 parsing functions (h1_parse_msg_*) returns the number of bytes parsed or
0 if nothing is parsed because an error occurred or some data are
missing. But they never return negative values. Thus, instead of a signed
integer, these function now return a size_t value.

The H1 and FCGI muxes are updated accordingly. Note that h1_parse_msg_data()
has been slightly adapted because the parsing of chunked messages still need
to handle negative values when a parsing error is reported by
h1_parse_chunk_size() or h1_skip_chunk_crlf().

4 years agoCLEANUP: pattern: remove export of non-existent function pattern_delete()
Dragan Dosen [Fri, 21 May 2021 15:01:08 +0000 (17:01 +0200)] 
CLEANUP: pattern: remove export of non-existent function pattern_delete()

4 years agoMINOR: map/acl: print the count of all the map/acl entries in "show map/acl"
Dragan Dosen [Fri, 21 May 2021 14:59:15 +0000 (16:59 +0200)] 
MINOR: map/acl: print the count of all the map/acl entries in "show map/acl"

The output of "show map/acl" now contains the 'entry_cnt' value that
represents the count of all the entries for each map/acl, not just the
active ones, which means that it also includes entries currently being
added.

4 years agoBUG/MINOR: http-comp: Preserve HTTP_MSGF_COMPRESSIONG flag on the response
Christopher Faulet [Fri, 21 May 2021 07:49:20 +0000 (09:49 +0200)] 
BUG/MINOR: http-comp: Preserve HTTP_MSGF_COMPRESSIONG flag on the response

This flag is set on the response when its payload is compressed by HAProxy.
It must be preserved because it may be used when the log message is emitted.

When the compression filter was refactored to support the HTX, an
optimization was added to not perform extra proessing on the trailers.
HTTP_MSGF_COMPRESSIONG flag is removed when the last data block is
compressed. It is not required, it is just an optimization and unfortunately
a bug. This optimization must be removed to preserve the flag.

This patch must be backported as far as 2.0. On the HTX is affected.

4 years agoBUG/MEDIUM: filters: Exec pre/post analysers only one time per filter
Christopher Faulet [Thu, 20 May 2021 16:00:55 +0000 (18:00 +0200)] 
BUG/MEDIUM: filters: Exec pre/post analysers only one time per filter

For each filter, pre and post callback functions must only be called one
time. To do so, when one of them is finished, the corresponding analyser bit
must be removed from pre_analyzers or post_analyzers bit field. It is only
an issue with pre-analyser callback functions if the corresponding analyser
yields. It may happens with lua action for instance. In this case, the
filters pre analyser callback function is unexpectedly called several times.

This patch should fix the issue #1263. It must be backported is all stable
versions.

4 years agoBUILD/MINOR: opentracing: fixed build when using clang
Miroslav Zagorac [Tue, 18 May 2021 18:05:10 +0000 (20:05 +0200)] 
BUILD/MINOR: opentracing: fixed build when using clang

The arguments of the snprintf() function are now consistent with the
format used.

This should fix the github issue #1242.

4 years agoBUG/MAJOR: server: prevent deadlock when using 'set maxconn server'
Amaury Denoyelle [Mon, 17 May 2021 08:47:18 +0000 (10:47 +0200)] 
BUG/MAJOR: server: prevent deadlock when using 'set maxconn server'

A deadlock is possible with 'set maxconn server' command, if there is
pending connection ready to be dequeued. This is caused by the locking
of server spinlock in both cli_parse_set_maxconn_server and
process_srv_queue.

Fix this by reducing the scope of the server lock into
server_parse_maxconn_change_request. If connection are dequeued, the
lock is taken a second time. This can be seen as suboptimal but as it
happens only during 'set maxconn server' it can be considered as
tolerable.

This issue was reported on the mailing list, for the 1.8.x branch.
It must be backported up to the 1.8.

4 years agoBUG/MEDIUM: ebtree: Invalid read when looking for dup entry
Remi Tricot-Le Breton [Tue, 18 May 2021 16:56:42 +0000 (18:56 +0200)] 
BUG/MEDIUM: ebtree: Invalid read when looking for dup entry

The first item inserted into an ebtree will be inserted directly below
the root, which is a simple struct eb_root which only holds two branch
pointers (left and right).
If we try to find a duplicated entry to this first leaf through a
ebmb_next_dup, our leaf_p pointer will point to the eb_root instead of a
complete eb_node so we cannot look for the bit part of our leaf_p since
it would try to cast our eb_root into an eb_node and perform an out of
bounds access when reading "eb_root_to_node(eb_untag(t,EB_LEFT)))->bit".
This bug was found by address sanitizer running on a CRL hot update VTC
test.

Note that the bug has been there since the import of the eb_next_dup()
and eb_prev_dup() function in 1.5-dev19 by commit 2b5702030 ("MINOR:
ebtree: add new eb_next_dup/eb_prev_dup() functions to visit duplicates").

It can be backported to all stable branches.