]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
4 years agoMEDIUM: cfgparse: detect numa and set affinity if needed
Amaury Denoyelle [Fri, 26 Mar 2021 17:20:47 +0000 (18:20 +0100)] 
MEDIUM: cfgparse: detect numa and set affinity if needed

On process startup, the CPU topology of the machine is inspected. If a
multi-socket CPU machine is detected, automatically define the process
affinity on the first node with active cpus. This is done to prevent an
impact on the overall performance of the process in case the topology of
the machine is unknown to the user.

This step is not executed in the following condition :
- a non-null nbthread statement is present
- a restrictive 'cpu-map' statement is present
- the process affinity is already restricted, for example via a taskset
  call

For the record, benchmarks were executed on a machine with 2 CPUs
Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz. In both clear and ssl
scenario, the performance were sub-optimal without the automatic
rebinding on a single node.

4 years agoMINOR: cfgparse: support the comma separator on parse_cpu_set
Amaury Denoyelle [Tue, 6 Apr 2021 14:46:15 +0000 (16:46 +0200)] 
MINOR: cfgparse: support the comma separator on parse_cpu_set

Allow to specify multiple cpu ids/ranges in parse_cpu_set separated by a
comma. This is optional and must be activated by a parameter.

The comma support is disabled for the parsing of the 'cpu-map' config
statement. However, it will be useful to parse files in sysfs when
inspecting the cpus topology for NUMA automatic process binding.

4 years agoMINOR: thread: implement the detection of forced cpu affinity
Amaury Denoyelle [Wed, 31 Mar 2021 14:57:39 +0000 (16:57 +0200)] 
MINOR: thread: implement the detection of forced cpu affinity

Create a function thread_cpu_mask_forced. Its purpose is to report if a
restrictive cpu mask is active for the current proces, for example due
to a taskset invocation. It is only implemented for the linux platform
currently.

4 years agoMEDIUM: config: use platform independent type hap_cpuset for cpu-map
Amaury Denoyelle [Wed, 21 Apr 2021 16:39:58 +0000 (18:39 +0200)] 
MEDIUM: config: use platform independent type hap_cpuset for cpu-map

Use the platform independent type hap_cpuset for the cpu-map statement
parsing. This allow to address CPU index greater than LONGBITS.

Update the documentation to reflect the removal of this limit except for
platforms without cpu_set_t type or equivalent.

4 years agoMINOR: cfgparse: use hap_cpuset for parse_cpu_set
Amaury Denoyelle [Wed, 14 Apr 2021 14:16:03 +0000 (16:16 +0200)] 
MINOR: cfgparse: use hap_cpuset for parse_cpu_set

Replace the unsigned long parameter by a hap_cpuset. This allows to
address CPU with index greater than LONGBITS.

This function is used to parse the 'cpu-map' statement. However at the
moment, the result is casted back to a long to store it in the global
structure. The next step is to replace ulong in in cpu_map in the
global structure with hap_cpuset.

4 years agoMINOR: cpuset: define a platform-independent cpuset type
Amaury Denoyelle [Wed, 14 Apr 2021 13:03:51 +0000 (15:03 +0200)] 
MINOR: cpuset: define a platform-independent cpuset type

This module can be used to manipulate a cpu sets in a platform agnostic
way. Use the type cpu_set_t/cpuset_t if available on the platform, or
fallback to unsigned long, which limits de facto the maximum cpu index
to LONGBITS.

4 years agoBUG/MEDIUM: mux-h2: Properly handle shutdowns when received with data
Christopher Faulet [Fri, 23 Apr 2021 10:25:18 +0000 (12:25 +0200)] 
BUG/MEDIUM: mux-h2: Properly handle shutdowns when received with data

The H2_CF_RCVD_SHUT flag is used to report a read0 was encountered. It is
used by the H2 mux to properly handle shutdowns. However, this flag is only
set when no data are received. If it is detected at the socket level when
some data are received, it is not handled. And because the event was
reported on the connection, any other read attempts are blocked. In this
case, we are unable to close the connection and release the mux
immediately. We must wait the mux timeout expires.

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

4 years agoCLEANUP: compression: remove calls to SLZ init functions
Willy Tarreau [Thu, 22 Apr 2021 12:43:49 +0000 (14:43 +0200)] 
CLEANUP: compression: remove calls to SLZ init functions

As we now embed the library we don't need to support the older 1.0 API
any more, so we can remove the explicit calls to slz_make_crc_table()
and slz_prepare_dist_table().

4 years agoCI: github: do not build libslz any more
Willy Tarreau [Thu, 22 Apr 2021 14:10:32 +0000 (16:10 +0200)] 
CI: github: do not build libslz any more

As hinted by Tim, it's not needed any more since it's now integrated,
let's get rid of this step.

4 years agoBUILD: compression: switch SLZ from out-of-tree to in-tree
Willy Tarreau [Thu, 22 Apr 2021 12:14:22 +0000 (14:14 +0200)] 
BUILD: compression: switch SLZ from out-of-tree to in-tree

Now that SLZ is merged, let's update the makefile and compression
files to use it. As a result, SLZ_INC and SLZ_LIB are neither defined
nor used anymore.

USE_SLZ is enabled by default ("USE_SLZ=default") and can be disabled
by passing "USE_SLZ=" or by enabling USE_ZLIB=1.

The doc was updated to reflect the changes.

4 years agoIMPORT: slz: import slz into the tree
Willy Tarreau [Thu, 22 Apr 2021 12:09:44 +0000 (14:09 +0200)] 
IMPORT: slz: import slz into the tree

SLZ is rarely packaged by distros and there have been complaints about
the CPU and memory usage of ZLIB, leading to some suggestions to better
address the issue by simply integrating SLZ into the tree (just 3 files).
See discussions below:

   https://www.mail-archive.com/haproxy@formilux.org/msg38037.html
   https://www.mail-archive.com/haproxy@formilux.org/msg40079.html
   https://www.mail-archive.com/haproxy@formilux.org/msg40365.html

This patch does just this, after minor adjustments to these files:
  - tables.h was renamed to slz-tables.h
  - tables.h had the precomputed tables removed since not used here
  - slz.c uses includes <import/slz*> instead of "slz*.h"

The slz commit imported here was b06c172 ("slz: avoid a build warning
with -Wimplicit-fallthrough"). No other change was performed either to
SLZ nor to haproxy at this point so that this operation may be replicated
if needed for a future version.

4 years agoBUILD: makefile: fix the "make clean" target on strict bourne shells
Willy Tarreau [Wed, 21 Apr 2021 15:17:16 +0000 (17:17 +0200)] 
BUILD: makefile: fix the "make clean" target on strict bourne shells

As reported by @axinojolais in issue #1217, some older bourne shells do
not expand on braces so some files were not cleaned since the recent
splitting of the contrib/ subdir. Let's fix that by explicitly listing
the patterns to be cleared (which are in much smaller quantity now that
contrib was removed), and for grouping them with their respective dirs.

At some point, some recursive makefiles would probably help there.

4 years agoBUG/MINOR: mworker: don't use oldpids[] anymore for reload
William Lallemand [Wed, 21 Apr 2021 14:55:34 +0000 (16:55 +0200)] 
BUG/MINOR: mworker: don't use oldpids[] anymore for reload

Since commit 3f12887 ("MINOR: mworker: don't use children variable
anymore"), the oldpids array is not used anymore to generate the new -sf
parameters. So we don't need to set nb_oldpids to 0 during the first
start of the master process.

This patch fixes a bug when 2 masters process tries to synchronize their
peers, there is a small chances that it won't work because nb_oldpids
equals 0.

Should be backported as far as 2.0.

4 years agoBUG/MINOR: mworker/init: don't reset nb_oldpids in non-mworker cases
William Lallemand [Wed, 21 Apr 2021 14:42:18 +0000 (16:42 +0200)] 
BUG/MINOR: mworker/init: don't reset nb_oldpids in non-mworker cases

This bug affects the peers synchronisation code which rely on the
nb_oldpids variable to synchronize the peer from the old PID.

In the case the process is not started in master-worker mode and tries
to synchronize using the peers, there is a small chance that won't work
because nb_oldpids equals 0.

Fix the bug by setting the variable to 0 only in the case of the
master-worker when not reloaded.

It could also be a problem when trying to synchronize the peers between
2 masters process which should be fixed in another patch.

Bug exists since commit 8a361b5 ("BUG/MEDIUM: mworker: don't reuse PIDs
passed to the master").

Sould be backported as far as 1.8.

4 years agoMINOR: config: add a diag for invalid cpu-map statement
Amaury Denoyelle [Thu, 15 Apr 2021 16:07:07 +0000 (18:07 +0200)] 
MINOR: config: add a diag for invalid cpu-map statement

If a cpu-statement is refering to multiple processes and threads, it is
silently ignored. Add a diag message to report it to the user.

4 years agoBUG/MEDIUM: config: fix cpu-map notation with both process and threads
Amaury Denoyelle [Thu, 15 Apr 2021 14:29:58 +0000 (16:29 +0200)] 
BUG/MEDIUM: config: fix cpu-map notation with both process and threads

The application of a cpu-map statement with both process and threads
is broken (P-Q/1 or 1/P-Q notation).

For example, before the fix, when using P-Q/1, proc_t1 would be updated.
Then it would be AND'ed with thread which is still 0 and thus does
nothing.

Another problem is when using 1/1[-Q], thread[0] is defined. But if
there is multiple processes, every processes will use this define
affinity even if it should be applied only to 1st process.

The solution to the fix is a little bit too complex for my taste and
there is maybe a simpler solution but I did not wish to break the
storage of global.cpu_map, as it is quite painful to test all the
use-cases. Besides, this code will probably be clean up when
multiprocess support removed on the future version.

Let's try to explain my logic.

* either haproxy runs in multiprocess or multithread mode. If on
  multiprocess, we should consider proc_t1 (P-Q/1 notation). If on
  multithread, we should consider thread (1/P-Q notation). However
  during parsing, the final number of processes or threads is unknown,
  thus we have to consider the two possibilities.

* there is a special case for the first thread / first process which is
  present in both execution modes. And as a matter of fact cpu-map 1 or
  1/1 notation represents the same thing. Thus, thread[0] and proc_t1[0]
  represents the same thing. To solve this problem, only thread[0] is
  used for this special case.

This fix must be backported up to 2.0.

4 years agoCLEANUP: contrib: remove the last references to the now dead contrib/ directory
Willy Tarreau [Wed, 21 Apr 2021 13:13:10 +0000 (15:13 +0200)] 
CLEANUP: contrib: remove the last references to the now dead contrib/ directory

Now with the last SPOA modules gone, contrib/ doesn't exist anymore
and does not need to be referenced in the Makefile nor .gitignore.

4 years agoCONTRIB: move mod_defender out of the tree
Willy Tarreau [Wed, 21 Apr 2021 13:05:52 +0000 (15:05 +0200)] 
CONTRIB: move mod_defender out of the tree

As previously mentioned SPOA code has nothing to do in the haproxy core
since they're not dependent on haproxy's version. This one was moved to
its own repository here with complete history:

  https://github.com/haproxytech/spoa-mod_defender

4 years agoMINOR: uri_normalizer: Add a `strip-dot` normalizer
Maximilian Mader [Tue, 20 Apr 2021 22:22:50 +0000 (00:22 +0200)] 
MINOR: uri_normalizer: Add a `strip-dot` normalizer

This normalizer removes "/./" segments from the path component.
Usually the dot refers to the current directory which renders those segments redundant.

See GitHub Issue #714.

4 years agoCLEANUP: uri_normalizer: Remove trailing whitespace
Maximilian Mader [Tue, 20 Apr 2021 22:22:49 +0000 (00:22 +0200)] 
CLEANUP: uri_normalizer: Remove trailing whitespace

This patch removes a single trailing space.

4 years agoBUG/MINOR: uri_normalizer: Use delim parameter when building the sorted query in...
Maximilian Mader [Tue, 20 Apr 2021 22:22:48 +0000 (00:22 +0200)] 
BUG/MINOR: uri_normalizer: Use delim parameter when building the sorted query in uri_normalizer_query_sort

Currently the delimiter is hardcoded as ampersand (&) but the function takes the delimiter as a paramter.
This patch replaces the hardcoded ampersand with the given delimiter.

4 years agoBUG/MEDIUM: mux-h2: Fix dfl calculation when merging CONTINUATION frames
Christopher Faulet [Wed, 21 Apr 2021 09:11:21 +0000 (11:11 +0200)] 
BUG/MEDIUM: mux-h2: Fix dfl calculation when merging CONTINUATION frames

When header are splitted over several frames, payload of HEADERS and
CONTINUATION frames are merged to form a unique HEADERS frame before
decoding the payload. To do so, info about the current frame are updated
(dff, dfl..) with info of the next one. Here there is a bug when the frame
length (dfl) is update. We must add the next frame length (hdr.dfl) and not
only the amount of data found in the buffer (clen). Because HEADERS frames
are decoded in one pass, dfl value is the whole frame length or 0. nothing
intermediary.

This patch must be backported as far as 2.0.

4 years agoBUG/MAJOR: mux-h2: Properly detect too large frames when decoding headers
Christopher Faulet [Wed, 21 Apr 2021 08:39:53 +0000 (10:39 +0200)] 
BUG/MAJOR: mux-h2: Properly detect too large frames when decoding headers

In the function decoding payload of HEADERS frames, an internal error is
returned if the frame length is too large. it cannot exceed the buffer
size. The same is true when headers are splitted on several frames. The
payload of HEADERS and CONTINUATION frames are merged and the overall size
must not exceed the buffer size.

However, there is a bug when the current frame is big enough to only have
the space for a part of the header of the next frame. Because, in this case,
we wait for more data, to have the whole frame header. We don't properly
detect that the headers are too large to be stored in one buffer. In fact
the test to trigger this error is not accurate. When the buffer is full, the
error is reported if the frame length exceeds the amount of data in the
buffer. But in reality, an error must be reported when we are unable to
decode the current frame while the buffer is full. Because, in this case, we
know there is no way to change this state.

When the bug happens, the H2 connection is woken up in loop, consumming all
the CPU. But the traffic is not blocked for all that.

This patch must be backported as far as 2.0.

4 years agoBUG/MINOR: server: fix potential null gcc error in delete server
Amaury Denoyelle [Wed, 21 Apr 2021 09:50:26 +0000 (11:50 +0200)] 
BUG/MINOR: server: fix potential null gcc error in delete server

gcc still reports a potential null pointer dereference in delete server
function event with a BUG_ON before it. Remove the misleading NULL check
in the for loop which should never happen.

This does not need to be backported.

4 years agoCONTRIB: move modsecurity out of the tree
Willy Tarreau [Wed, 21 Apr 2021 09:29:47 +0000 (11:29 +0200)] 
CONTRIB: move modsecurity out of the tree

As previously mentioned SPOA code has nothing to do in the haproxy core
since they're not dependent on haproxy's version. This one was moved to
its own repository here with complete history:

    https://github.com/haproxy/spoa-modsecurity

4 years agoCONTRIB: move spoa_server out of the tree
Willy Tarreau [Wed, 21 Apr 2021 09:28:48 +0000 (11:28 +0200)] 
CONTRIB: move spoa_server out of the tree

As previously mentioned SPOA code has nothing to do in the haproxy core
since they're not dependent on haproxy's version. This one was moved to
its own repository here with complete history:

    https://github.com/haproxy/spoa-server

4 years agoMINOR: server: implement delete server cli command
Amaury Denoyelle [Thu, 15 Apr 2021 12:41:20 +0000 (14:41 +0200)] 
MINOR: server: implement delete server cli command

Implement a new CLI command 'del server'. It can be used to removed a
dynamically added server. Only servers in maintenance mode can be
removed, and without pending/active/idle connection on it.

Add a new reg-test for this feature. The scenario of the reg-test need
to first add a dynamic server. It is then deleted and a client is used
to ensure that the server is non joinable.

The management doc is updated with the new command 'del server'.

4 years agoMINOR: server: add log on dynamic server creation
Amaury Denoyelle [Tue, 20 Apr 2021 16:35:19 +0000 (18:35 +0200)] 
MINOR: server: add log on dynamic server creation

Add a notice log to report the creation of a new server. The log is
printed at the end of the function.

4 years agoBUG/MEDIUM: server: ensure thread-safety of server runtime creation
Amaury Denoyelle [Tue, 20 Apr 2021 15:09:08 +0000 (17:09 +0200)] 
BUG/MEDIUM: server: ensure thread-safety of server runtime creation

cli_parse_add_server can be executed in parallel by several CLI
instances and so must be thread-safe. The critical points of the
function are :
- server duplicate detection
- insertion of the server in the proxy list

The mode of operation has been reversed. The server is first
instantiated and parsed. The duplicate check has been moved at the end
just before the insertion in the proxy list, under the thread isolation.
Thus, the thread safety is guaranteed and server allocation is kept
outside of locks/thread isolation.

4 years agoBUG/MINOR: logs: free logsrv.conf.file on exit
Amaury Denoyelle [Tue, 20 Apr 2021 15:05:47 +0000 (17:05 +0200)] 
BUG/MINOR: logs: free logsrv.conf.file on exit

Config information has been added into the logsrv struct. The filename
is duplicated and should be freed on exit.

Introduced in the current release.
This does not need to be backported.

4 years agoBUG/MINOR: server: free srv.lb_nodes in free_server
Amaury Denoyelle [Tue, 20 Apr 2021 14:48:22 +0000 (16:48 +0200)] 
BUG/MINOR: server: free srv.lb_nodes in free_server

lb_nodes is allocated for servers using lb_chash (balance random or
hash-type consistent).

It can be backported up to 1.8.

4 years agoCONTRIB: move spoa_example out of the tree
Willy Tarreau [Wed, 21 Apr 2021 07:39:06 +0000 (09:39 +0200)] 
CONTRIB: move spoa_example out of the tree

As previously mentioned SPOA code has nothing to do in the haproxy core
since they're not dependent on haproxy's version. This one was moved to
its own repository here with complete history:

     https://github.com/haproxy/spoa-example

4 years agoCLEANUP: lists/tree-wide: rename some list operations to avoid some confusion
Willy Tarreau [Wed, 21 Apr 2021 05:32:39 +0000 (07:32 +0200)] 
CLEANUP: lists/tree-wide: rename some list operations to avoid some confusion

The current "ADD" vs "ADDQ" is confusing because when thinking in terms
of appending at the end of a list, "ADD" naturally comes to mind, but
here it does the opposite, it inserts. Several times already it's been
incorrectly used where ADDQ was expected, the latest of which was a
fortunate accident explained in 6fa922562 ("CLEANUP: stream: explain
why we queue the stream at the head of the server list").

Let's use more explicit (but slightly longer) names now:

   LIST_ADD        ->       LIST_INSERT
   LIST_ADDQ       ->       LIST_APPEND
   LIST_ADDED      ->       LIST_INLIST
   LIST_DEL        ->       LIST_DELETE

The same is true for MT_LISTs, including their "TRY" variant.
LIST_DEL_INIT keeps its short name to encourage to use it instead of the
lazier LIST_DELETE which is often less safe.

The change is large (~674 non-comment entries) but is mechanical enough
to remain safe. No permutation was performed, so any out-of-tree code
can easily map older names to new ones.

The list doc was updated.

4 years agoCLEANUP: sample: Use explicit return for successful `json_query`s
Tim Duesterhus [Thu, 15 Apr 2021 16:40:06 +0000 (18:40 +0200)] 
CLEANUP: sample: Use explicit return for successful `json_query`s

Move the `return 1` into each of the cases, instead of relying on the single
`return 1` at the bottom of the function.

4 years agoCLEANUP: sample: Explicitly handle all possible enum values from mjson
Tim Duesterhus [Thu, 15 Apr 2021 16:14:32 +0000 (18:14 +0200)] 
CLEANUP: sample: Explicitly handle all possible enum values from mjson

This makes it easier to find bugs, because -Wswitch can help us.

4 years agoCLEANUP: sample: Improve local variables in sample_conv_json_query
Tim Duesterhus [Thu, 15 Apr 2021 16:08:48 +0000 (18:08 +0200)] 
CLEANUP: sample: Improve local variables in sample_conv_json_query

This improves the use of local variables in sample_conv_json_query:

- Use the enum type for the return value of `mjson_find`.
- Do not use single letter variables.
- Reduce the scope of variables that are only needed in a single branch.
- Add missing newlines after variable declaration.

4 years agoCONTRIB: modsecurity: make the code build with the embedded includes
Willy Tarreau [Tue, 20 Apr 2021 17:32:15 +0000 (19:32 +0200)] 
CONTRIB: modsecurity: make the code build with the embedded includes

From now on the code only needs its embedded dependencies and does not
depend any more on external haproxy dependencies. It can now be built
as a standalone project.

4 years agoCONTRIB: modsecurity: import the minimal number of includes
Willy Tarreau [Tue, 20 Apr 2021 17:30:56 +0000 (19:30 +0200)] 
CONTRIB: modsecurity: import the minimal number of includes

Just like mod_defender, modsecurity depends on a few haproxy includes
and it shouldn't since it's expected to be agnostic to the version.

This imports the strictly minimum number of includes required to build
it. These have been manually stripped from their exported functions
prototypes and their unneeded dependencies.

4 years agoCONTRIB: mod_defender: make the code build with the embedded includes
Willy Tarreau [Tue, 20 Apr 2021 17:19:53 +0000 (19:19 +0200)] 
CONTRIB: mod_defender: make the code build with the embedded includes

From now on the code only needs its embedded dependencies and does not
depend any more on external haproxy dependencies. It can now be built
as a standalone project.

4 years agoCONTRIB: mod_defender: import the minimal number of includes
Willy Tarreau [Tue, 20 Apr 2021 17:16:59 +0000 (19:16 +0200)] 
CONTRIB: mod_defender: import the minimal number of includes

mod_defender currently depends on haproxy includes while it should be
totally autonomous since it should build without and not even depend
on any specific haproxy version.

This imports the strictly minimum number of includes required to build
it. These have been manually stripped from their exported functions
prototypes and their unneeded dependencies.

In reality, the defender.c mostly needs sample.h because it stores its
data this way, spoe.h for the protocol definitions, and a few intops
and tools to decode varints. The rest mostly comes as intermediate
dependencies.

4 years agoBUG/MINOR: server: make srv_alloc_lb() allocate lb_nodes for consistent hash
Willy Tarreau [Tue, 20 Apr 2021 09:37:45 +0000 (11:37 +0200)] 
BUG/MINOR: server: make srv_alloc_lb() allocate lb_nodes for consistent hash

The test in srv_alloc_lb() to allocate the lb_nodes[] array used in the
consistent hash was incorrect, it wouldn't do it for consistent hash and
could do it for regular random.

No backport is needed as this was added for dynamic servers in 2.4-dev by
commit f99f77a50 ("MEDIUM: server: implement 'add server' cli command").

4 years agoBUILD: pools: fix build with DEBUG_FAIL_ALLOC
Willy Tarreau [Mon, 19 Apr 2021 16:36:48 +0000 (18:36 +0200)] 
BUILD: pools: fix build with DEBUG_FAIL_ALLOC

Amaury noticed that I managed to break the build of DEBUG_FAIL_ALLOC
for the second time with 207c09509 ("MINOR: pools: move the fault
injector to __pool_alloc()"). The joy of endlessly reworking patch
sets... No backport is needed, that was in the just merged cleanup
series.

4 years agoCLEANUP: pools: declare dummy pool functions to remove some ifdefs
Willy Tarreau [Mon, 19 Apr 2021 10:29:16 +0000 (12:29 +0200)] 
CLEANUP: pools: declare dummy pool functions to remove some ifdefs

By having a pair of dummy pool_get_from_cache() and pool_put_to_cache()
we can remove some ugly ifdefs, so let's do this. We've already done it
for the shared cache.

4 years agoCLEANUP: pools: uninline pool_put_to_cache()
Willy Tarreau [Mon, 19 Apr 2021 09:49:26 +0000 (11:49 +0200)] 
CLEANUP: pools: uninline pool_put_to_cache()

This function has become too big (251 bytes) and is now hurting
performance a lot, with up to 4% request rate being lost over the last
pool changes. Let's move it to pool.c as a regular function. Other
attempts were made to cut it in half but it's still inefficient. Doing
this results in saving ~90kB of object code, and even 112kB since the
pool changes, with code that is even slightly faster!

Conversely, pool_get_from_cache(), which remains half of this size, is
still faster inlined, likely in part due to the immediate use of the
returned pointer afterwards.

4 years agoCLEANUP: pools: merge pool_{get_from,put_to}_local_caches with generic ones
Willy Tarreau [Mon, 19 Apr 2021 07:02:15 +0000 (09:02 +0200)] 
CLEANUP: pools: merge pool_{get_from,put_to}_local_caches with generic ones

Since pool_get_from_cache() and pool_put_to_cache() were now only wrappers
to the local cache versions which do all the job, let's merge them together
so that there is no more local-cache specific function.

4 years agoCLEANUP: pools: make the local cache allocator fall back to the shared cache
Willy Tarreau [Mon, 19 Apr 2021 06:56:22 +0000 (08:56 +0200)] 
CLEANUP: pools: make the local cache allocator fall back to the shared cache

Now when pool_get_from_local_cache() fails, it automatically falls back
to pool_get_from_shared_cache(), which used to always be done in
pool_get_from_cache(). Thus now the API is simpler as we always allocate
and free from/to the local caches.

4 years agoMEDIUM: pools: make pool_put_to_cache() always call pool_put_to_local_cache()
Willy Tarreau [Mon, 19 Apr 2021 06:50:45 +0000 (08:50 +0200)] 
MEDIUM: pools: make pool_put_to_cache() always call pool_put_to_local_cache()

Till now it used to call it only if there were not too many objects into
the local cache otherwise would send the latest one directly into the
shared cache. Now it always sends to the local cache and it's up to the
local cache to free its oldest objects. From a cache freshness perspective
it's better this way since we always evict cold objects instead of hot
ones. From an API perspective it's better because it will help make the
shared cache invisible to the public API.

4 years agoMINOR: pools: evict excess objects using pool_evict_from_local_cache()
Willy Tarreau [Mon, 19 Apr 2021 06:14:03 +0000 (08:14 +0200)] 
MINOR: pools: evict excess objects using pool_evict_from_local_cache()

Till now we could only evict oldest objects from all local caches using
pool_evict_from_local_caches() until the cache size was satisfying again,
but there was no way to evict excess objects from a single cache, which
is the reason why pool_put_to_cache() used to refrain from putting into
the local cache and would directly write to the shared cache, resulting
in massive writes when caches were full.

Let's add this new function now. It will stop once the number of objects
in the local cache is no higher than 16+total/8 or the cache size is no
more than 75% full, just like before.

For now the function is not used.

4 years agoMINOR: pools: create unified pool_{get_from,put_to}_cache()
Willy Tarreau [Sun, 18 Apr 2021 09:11:14 +0000 (11:11 +0200)] 
MINOR: pools: create unified pool_{get_from,put_to}_cache()

These two functions are now responsible for allocating directly from
the cache and releasing to the cache.

Now the pool_alloc() function simply does this:

    if cache enabled
       return pool_alloc_from_cache() if no NULL
    return pool_alloc_nocache() otherwise

and the pool_free() function does this:

    if cache enabled
       pool_put_to_cache()
    else
       pool_free_nocache()

For now this only introduces these two functions without changing anything
else, but the goal is to soon allow to make them implementation-specific.

4 years agoMEDIUM: pools: make CONFIG_HAP_POOLS control both local and shared pools
Willy Tarreau [Sun, 18 Apr 2021 08:23:02 +0000 (10:23 +0200)] 
MEDIUM: pools: make CONFIG_HAP_POOLS control both local and shared pools

Continuing the unification of local and shared pools, now the usage of
pools is governed by CONFIG_HAP_POOLS without which allocations and
releases are performed directly from the OS using pool_alloc_nocache()
and pool_free_nocache().

4 years agoMINOR: pools: factor the release code into pool_put_to_os()
Willy Tarreau [Sat, 17 Apr 2021 15:48:40 +0000 (17:48 +0200)] 
MINOR: pools: factor the release code into pool_put_to_os()

There are two levels of freeing to the OS:
  - code that wants to keep the pool's usage counters updated uses
    pool_free_area() and handles the counters itself. That's what
    pool_put_to_shared_cache() does in the no-global-pools case.
  - code that does not want to update the counters because they were
    already updated only calls pool_free_area().

Let's extract these calls to establish the symmetry with pool_get_from_os()
and pool_alloc_nocache(), resulting in pool_put_to_os() (which only updates
the allocated counter) and pool_free_nocache() (which also updates the used
counter). This will later allow to simplify the generic code.

4 years agoMINOR: pools: move pool_free_area() out of the lock in the locked version
Willy Tarreau [Sat, 17 Apr 2021 16:19:51 +0000 (18:19 +0200)] 
MINOR: pools: move pool_free_area() out of the lock in the locked version

Calling pool_free_area() inside a lock in pool_put_to_shared_cache() is
a very bad idea. Fortunately this only happens on the lowest end platforms
which almost never use threads or in very small counts.

This change consists in zeroing the pointer once already released to the
cache in the first test so that the second stage knows if it needs to
pass it to the OS or not. This has slightly reduced the length of the

4 years agoMINOR: pools: always use atomic ops to maintain counters
Willy Tarreau [Sat, 17 Apr 2021 16:06:57 +0000 (18:06 +0200)] 
MINOR: pools: always use atomic ops to maintain counters

A part of the code cannot be factored out because it still uses non-atomic
inc/dec for pool->used and pool->allocated as these are located under the
pool's lock. While it can make sense in terms of bus cycles, it does not
make sense in terms of code normalization. Further, some operations were
still performed under a lock that could be totally removed via the use of
atomic ops.

There is still one occurrence in pool_put_to_shared_cache() in the locked
code where pool_free_area() is called under the lock, which must absolutely
be fixed.

4 years agoMINOR: pools: split the OS-based allocator in two
Willy Tarreau [Sat, 17 Apr 2021 14:57:25 +0000 (16:57 +0200)] 
MINOR: pools: split the OS-based allocator in two

Now there's one part dealing with the allocation itself and keeping
counters up to date, and another one on top of it to return such an
allocated pointer to the user and update the use count and stats.

This is in anticipation for being able to group cache-related parts.
The release code is still done at once.

4 years agoMINOR: pools: move the fault injector to __pool_alloc()
Willy Tarreau [Sat, 17 Apr 2021 14:00:08 +0000 (16:00 +0200)] 
MINOR: pools: move the fault injector to __pool_alloc()

Till now it was limited to objects allocated from the OS which means
it had little use as soon as pools were enabled. Let's move it upper
in the layers so that any code can benefit from fault injection. In
addition this allows to pass a new flag POOL_F_NO_FAIL to disable it
if some callers prefer a no-failure approach.

4 years agoMINOR: pools: use cheaper randoms for fault injections
Willy Tarreau [Sat, 17 Apr 2021 13:50:28 +0000 (15:50 +0200)] 
MINOR: pools: use cheaper randoms for fault injections

ha_random() is quite heavy and uses atomic ops or even a lock on some
architectures. Here we don't seek good randoms, just statistical ones,
so let's use the statistical prng instead.

4 years agoMINOR: tools: add statistical_prng_range() to get a random number over a range
Willy Tarreau [Sat, 17 Apr 2021 13:49:34 +0000 (15:49 +0200)] 
MINOR: tools: add statistical_prng_range() to get a random number over a range

This is simply a multiply and shift from statistical_prng() but it's made
easily accessible.

4 years agoCLEANUP: pools: rename __pool_free() to pool_put_to_shared_cache()
Willy Tarreau [Sat, 17 Apr 2021 12:11:39 +0000 (14:11 +0200)] 
CLEANUP: pools: rename __pool_free() to pool_put_to_shared_cache()

Now the multi-level cache becomes more visible:

    pool_get_from_local_cache()
    pool_put_to_local_cache()
    pool_get_from_shared_cache()
    pool_put_to_shared_cache()

4 years agoCLEANUP: pools: rename pool_*_{from,to}_cache() to *_local_cache()
Willy Tarreau [Thu, 15 Apr 2021 18:12:48 +0000 (20:12 +0200)] 
CLEANUP: pools: rename pool_*_{from,to}_cache() to *_local_cache()

The functions were rightfully called from/to_cache when the thread-local
cache was considered as the only cache, but this is getting terribly
confusing. Let's call them from/to local_cache to make it clear that
it is not related with the shared cache.

As a side note, since pool_evict_from_cache() used not to work for a
particular pool but for all of them at once, it was renamed to
pool_evict_from_local_caches()  (plural form).

4 years agoCLEANUP: pools: rename __pool_get_first() to pool_get_from_shared_cache()
Willy Tarreau [Thu, 15 Apr 2021 17:54:48 +0000 (19:54 +0200)] 
CLEANUP: pools: rename __pool_get_first() to pool_get_from_shared_cache()

This is exactly what it is, the entry is retrieved from the shared
cache when it is defined. The implementation that is enabled with
CONFIG_HAP_NO_GLOBAL_POOLS continues to return NULL.

4 years agoCLEANUP: pools: move the lock to the only __pool_get_first() that needs it
Willy Tarreau [Thu, 15 Apr 2021 17:48:44 +0000 (19:48 +0200)] 
CLEANUP: pools: move the lock to the only __pool_get_first() that needs it

Now that __pool_alloc() only surrounds __pool_get_first() with the lock,
let's move it to the only variant that requires it and remove the ugly
ifdefs from the function. This is safe because nobody else calls this
function.

4 years agoMINOR: pools: call pool_alloc_nocache() out of the pool's lock
Willy Tarreau [Thu, 15 Apr 2021 17:38:42 +0000 (19:38 +0200)] 
MINOR: pools: call pool_alloc_nocache() out of the pool's lock

In __pool_alloc(), historically we used to use factor out the
pool's lock between __pool_get_first() and __pool_refill_alloc(),
resulting in real malloc() or mmap() calls being performed under
the pool lock (for platforms using the locked shared pools).

As this is not needed anymore, let's move the call out of the
lock, it may improve allocation patterns on some platforms. This
also makes __pool_alloc() cleaner as we see a first attempt to
allocate from the local cache, then a second from the shared
cache then a reall allocation.

4 years agoCLEANUP: pools: re-merge pool_refill_alloc() and __pool_refill_alloc()
Willy Tarreau [Thu, 15 Apr 2021 16:20:12 +0000 (18:20 +0200)] 
CLEANUP: pools: re-merge pool_refill_alloc() and __pool_refill_alloc()

They were strictly equivalent, let's remerge them and rename them to
pool_alloc_nocache() as it's the call which performs a real allocation
which does not check nor update the cache. The only difference in the
past was the former taking the lock and not the second but now the lock
is not needed anymore at this stage since the pool's list is not touched.

In addition, given that the "avail" argument is no longer used by the
function nor by its callers, let's drop it.

4 years agoMEDIUM: pools: unify pool_refill_alloc() across all models
Willy Tarreau [Thu, 15 Apr 2021 16:13:13 +0000 (18:13 +0200)] 
MEDIUM: pools: unify pool_refill_alloc() across all models

Now we don't loop anymore trying to refill multiple items at once, and
an allocated object is directly returned to the requester instead of
being stored into the shared pool. This has multiple benefits. The
first one is that no locking is needed anymore on the allocation path
and the second one is that the loop will no longer cause latency spikes.

4 years agoMINOR: pools: make the basic pool_refill_alloc()/pool_free() update needed_avg
Willy Tarreau [Thu, 15 Apr 2021 15:23:15 +0000 (17:23 +0200)] 
MINOR: pools: make the basic pool_refill_alloc()/pool_free() update needed_avg

This is a first step towards unifying all the fallback code. Right now
these two functions are the only ones which do not update the needed_avg
rate counter since there's currently no shared pool kept when using them.
But their code is similar to what could be used everywhere except for
this one, so let's make them capable of maintaining usage statistics.

As a side effect the needed field in "show pools" will now be populated.

4 years agoMINOR: pools: enable the fault injector in all allocation modes
Willy Tarreau [Thu, 15 Apr 2021 14:43:18 +0000 (16:43 +0200)] 
MINOR: pools: enable the fault injector in all allocation modes

The mem_should_fail() call enabled by DEBUG_FAIL_ALLOC used to be placed
only in the no-cache version of the allocator. Now we can generalize it
to all modes and remove the exclusive test on CONFIG_HAP_NO_GLOBAL_POOLS.

4 years agoMINOR: pools: rename CONFIG_HAP_LOCAL_POOLS to CONFIG_HAP_POOLS
Willy Tarreau [Thu, 15 Apr 2021 14:24:00 +0000 (16:24 +0200)] 
MINOR: pools: rename CONFIG_HAP_LOCAL_POOLS to CONFIG_HAP_POOLS

We're going to make the local pool always present unless pools are
completely disabled. This means that pools are always enabled by
default, regardless of the use of threads. Let's drop this notion
of "local" pools and make it just "pool". The equivalent debug
option becomes DEBUG_NO_POOLS instead of DEBUG_NO_LOCAL_POOLS.

For now this changes nothing except the option and dropping the
dependency on USE_THREAD.

4 years agoMINOR: pool: remove the size field from pool_cache_head
Willy Tarreau [Sat, 17 Apr 2021 12:05:10 +0000 (14:05 +0200)] 
MINOR: pool: remove the size field from pool_cache_head

Everywhere we have access to the pool so we don't need to cache a copy
of the pool's size into the pool_cache_head. Let's remove it.

4 years agoMEDIUM: pools: move the cache into the pool header
Willy Tarreau [Fri, 16 Apr 2021 22:31:38 +0000 (00:31 +0200)] 
MEDIUM: pools: move the cache into the pool header

Initially per-thread pool caches were stored into a fixed-size array.
But this was a bit ugly because the last allocated pools were not able
to benefit from the cache at all. As a work around to preserve
performance, a size of 64 cacheable pools was set by default (there
are 51 pools at the moment, excluding any addon and debugging code),
so all in-tree pools were covered, at the expense of higher memory
usage.

In addition an index had to be calculated for each pool, and was used
to acces the pool cache head into that array. The pool index was not
even stored into the pools so it was required to determine it to access
the cache when the pool was already known.

This patch changes this by moving the pool cache head into the pool
head itself. This way it is certain that each pool will have its own
cache. This removes the need for index calculation.

The pool cache head is 32 bytes long so it was aligned to 64B to avoid
false sharing between threads. The extra cost is not huge (~2kB more
per pool than before), and we'll make better use of that space soon.
The pool cache head contains the size, which should probably be removed
since it's already in the pool's head.

4 years agoCLEANUP: pools: remove unused arguments to pool_evict_from_cache()
Willy Tarreau [Mon, 19 Apr 2021 05:49:50 +0000 (07:49 +0200)] 
CLEANUP: pools: remove unused arguments to pool_evict_from_cache()

In commit fb117e6a8 ("MEDIUM: memory: don't let pool_put_to_cache() free
the objects itself") pool_evict_from_cache() was introduced with no
argument, yet the only call place passes it the pool, the pointer and
the index number!

Let's remove these as they even let the reader think that the function
does something specific to the current pool while it's not the case.

4 years agoMINOR: pools: drop the unused static history of artificially failed allocs
Willy Tarreau [Thu, 15 Apr 2021 14:36:07 +0000 (16:36 +0200)] 
MINOR: pools: drop the unused static history of artificially failed allocs

When building with DEBUG_FAIL_ALLOC we call a random generator to decide
whether the pool alloc should succeed or fail, and there was a preliminary
debugging mechanism to keep sort of a history of the previous decisions. But
it was never used, enforces a lock during the allocation, and forces to use
static variables, all of which are limiting the ability to pursue the pools
cleanups with no real benefit. Let's get rid of them now.

4 years agoBUG/MINOR: pools/buffers: make sure to always reserve the required buffers
Willy Tarreau [Thu, 15 Apr 2021 17:24:12 +0000 (19:24 +0200)] 
BUG/MINOR: pools/buffers: make sure to always reserve the required buffers

Since recent commit ae07592 ("MEDIUM: pools: add CONFIG_HAP_NO_GLOBAL_POOLS
and CONFIG_HAP_GLOBAL_POOLS") the pre-allocation of all desired reserved
buffers was not done anymore on systems not using the shared cache. This
basically has no practical impact since these ones will quickly be refilled
by all the ones used at run time, but it may confuse someone checking if
they're allocated in "show pools".

That's only 2.4-dev, no backport is needed.

4 years agoBUG/MINOR: pools: maintain consistent ->allocated count on alloc failures
Willy Tarreau [Thu, 15 Apr 2021 15:31:19 +0000 (17:31 +0200)] 
BUG/MINOR: pools: maintain consistent ->allocated count on alloc failures

When running with CONFIG_HAP_NO_GLOBAL_POOLS, it's theoritically possible
to keep an incorrect count of allocated entries in a pool because the
allocated counter was used as a cumulated counter of alloc calls instead
of a number of currently allocated items (it's possible the meaning has
changed over time). The only impact in this mode essentially is that
"show pools" will report incorrect values. But this would only happen on
limited pools, which is not even certain still exist.

This was added by recent commit 0bae07592 ("MEDIUM: pools: add
CONFIG_HAP_NO_GLOBAL_POOLS and CONFIG_HAP_GLOBAL_POOLS") so no backport
is needed.

4 years agoDOC: Note that URI normalization is experimental
Tim Duesterhus [Fri, 16 Apr 2021 22:24:56 +0000 (00:24 +0200)] 
DOC: Note that URI normalization is experimental

Add a paragraph to the URI normalization documentation that URI normalization
is currently considered to be experimental.

4 years agoDOC: Add introduction to http-request normalize-uri
Tim Duesterhus [Fri, 16 Apr 2021 21:52:29 +0000 (23:52 +0200)] 
DOC: Add introduction to http-request normalize-uri

This patch adds an introduction to the http-request normalize-uri section,
explaining what to expect from the normalizers and possible issues that might
arise when not being careful.

4 years agoMEDIUM: http_act: Rename uri-normalizers
Tim Duesterhus [Sat, 17 Apr 2021 09:21:10 +0000 (11:21 +0200)] 
MEDIUM: http_act: Rename uri-normalizers

This patch renames all existing uri-normalizers into a more consistent naming
scheme:

1. The part of the URI that is being touched.
2. The modification being performed as an explicit verb.

4 years agoMINOR: uri_normalizer: Add a `percent-upper` normalizer
Tim Duesterhus [Thu, 15 Apr 2021 19:46:02 +0000 (21:46 +0200)] 
MINOR: uri_normalizer: Add a `percent-upper` normalizer

This normalizer uppercases the hexadecimal characters used in percent-encoding.

See GitHub Issue #714.

4 years agoMINOR: uri_normalizer: Add a `sort-query` normalizer
Tim Duesterhus [Thu, 15 Apr 2021 19:46:01 +0000 (21:46 +0200)] 
MINOR: uri_normalizer: Add a `sort-query` normalizer

This normalizer sorts the `&` delimited query parameters by parameter name.

See GitHub Issue #714.

4 years agoMINOR: uri_normalizer: Add support for supressing leading `../` for dotdot normalizer
Tim Duesterhus [Thu, 15 Apr 2021 19:46:00 +0000 (21:46 +0200)] 
MINOR: uri_normalizer: Add support for supressing leading `../` for dotdot normalizer

This adds an option to supress `../` at the start of the resulting path.

4 years agoMINOR: uri_normalizer: Add a `dotdot` normalizer to http-request normalize-uri
Tim Duesterhus [Thu, 15 Apr 2021 19:45:59 +0000 (21:45 +0200)] 
MINOR: uri_normalizer: Add a `dotdot` normalizer to http-request normalize-uri

This normalizer merges `../` path segments with the predecing segment, removing
both the preceding segment and the `../`.

Empty segments do not receive special treatment. The `merge-slashes` normalizer
should be executed first.

See GitHub Issue #714.

4 years agoMINOR: uri_normalizer: Add a `merge-slashes` normalizer to http-request normalize-uri
Tim Duesterhus [Thu, 15 Apr 2021 19:45:58 +0000 (21:45 +0200)] 
MINOR: uri_normalizer: Add a `merge-slashes` normalizer to http-request normalize-uri

This normalizer merges adjacent slashes into a single slash, thus removing
empty path segments.

See GitHub Issue #714.

4 years agoMINOR: uri_normalizer: Add `http-request normalize-uri`
Tim Duesterhus [Thu, 15 Apr 2021 19:45:57 +0000 (21:45 +0200)] 
MINOR: uri_normalizer: Add `http-request normalize-uri`

This patch adds the `http-request normalize-uri` action that was requested in
GitHub issue #714.

Normalizers will be added in the next patches.

4 years agoMINOR: uri_normalizer: Add `enum uri_normalizer_err`
Tim Duesterhus [Thu, 15 Apr 2021 19:45:56 +0000 (21:45 +0200)] 
MINOR: uri_normalizer: Add `enum uri_normalizer_err`

This enum will serve as the return type for each normalizer.

4 years agoMINOR: uri_normalizer: Add uri_normalizer module
Tim Duesterhus [Thu, 15 Apr 2021 19:45:55 +0000 (21:45 +0200)] 
MINOR: uri_normalizer: Add uri_normalizer module

This is in preparation for future patches.

4 years agoBUILD: makefile: Redirect stderr to /dev/null when probing options
Christopher Faulet [Wed, 14 Apr 2021 12:02:56 +0000 (14:02 +0200)] 
BUILD: makefile: Redirect stderr to /dev/null when probing options

It is a workaround to avoid a clang 11 bug that exits with SIGABRT when
stderr is redirected to stdin. This bug was already reported few weeks ago:

  https://bugs.llvm.org/show_bug.cgi?id=49463

But because it is pretty annoying, the standard error is now redirected to
/dev/null.

4 years agoBUG/MINOR: logs: Report the true number of retries if there was no connection
Christopher Faulet [Fri, 16 Apr 2021 09:24:20 +0000 (11:24 +0200)] 
BUG/MINOR: logs: Report the true number of retries if there was no connection

When the session is aborted before any connection attempt to any server, the
number of connection retries reported in the logs is wrong. It happens
because when the retries counter is not strictly positive, we consider the
max number of retries was reached and the backend retries value is used. It
is obviously wrong when no connectioh was performed.

In fact, at this stage, the retries counter is initialized to 0. But the
backend stream-interface is in the INI state. Once it is set to SI_ST_REQ,
the counter is set to the backend value. And it is the only possible state
transition from INI state. Thus it is safe to rely on it to fix the bug.

This patch must be backported to all stable versions.

4 years agoBUG/MINOR: http_htx: Remove BUG_ON() from http_get_stline() function
Christopher Faulet [Thu, 15 Apr 2021 08:25:35 +0000 (10:25 +0200)] 
BUG/MINOR: http_htx: Remove BUG_ON() from http_get_stline() function

The http_get_stline() was designed to be called from HTTP analyzers. Thus
before any data forwarding. To prevent any invalid usage, two BUG_ON()
statements were added. However, it is not a good idea because it is pretty
hard to be sure no HTTP sample fetch will never be called outside the
analyzers context. Especially because there is at least one possible area
where it may happens. An HTTP sample fetch may be used inside the unique-id
format string. On the normal case, it is generated in AN_REQ_HTTP_INNER
analyzer. But if an error is reported too early, the id is generated when
the log is emitted.

So, it is safer to remove the BUG_ON() statements and consider the normal
behavior is to return NULL if the first block is not a start-line. Of
course, this means all calling functions must test the return value or be
sure the start-line is really there.

This patch must be backported as far as 2.0.

4 years agoMINOR: tcp_samples: Be able to call bc_src/bc_dst from the health-checks
Christopher Faulet [Thu, 15 Apr 2021 07:39:38 +0000 (09:39 +0200)] 
MINOR: tcp_samples: Be able to call bc_src/bc_dst from the health-checks

The new L4 sample fetches used to get source and destination info of the
backend connection may now be called from an health-check.

4 years agoMINOR: tcp_samples: Add samples to get src/dst info of the backend connection
Christopher Faulet [Thu, 15 Apr 2021 07:38:37 +0000 (09:38 +0200)] 
MINOR: tcp_samples: Add samples to get src/dst info of the backend connection

This patch adds 4 new sample fetches to get the source and the destination
info (ip address and port) of the backend connection :

 * bc_dst      : Returns the destination address of the backend connection
 * bc_dst_port : Returns the destination port of the backend connection
 * bc_src      : Returns the source address of the backend connection
 * bc_src_port : Returns the source port of the backend connection

The configuration manual was updated accordingly.

4 years agoBUG/MINOR: http-fetch: Make method smp safe if headers were already forwarded
Christopher Faulet [Thu, 15 Apr 2021 07:28:02 +0000 (09:28 +0200)] 
BUG/MINOR: http-fetch: Make method smp safe if headers were already forwarded

When method sample fetch is called, if an exotic method is found
(HTTP_METH_OTHER), when smp_prefetch_htx() is called, we must be sure the
start-line is still there. Otherwise, HAproxy may crash because of a NULL
pointer dereference, for instance if the method sample fetch is used inside
a unique-id format string. Indeed, the unique id may be generated when the
log message is emitted. At this stage, the request channel is empty.

This patch must be backported as far as 2.0. But the bug exists in all
stable versions for the legacy HTTP mode too. Thus it must be adapted to the
legacy HTTP mode and backported to all other stable versions.

4 years agoBUG/MINOR: ssl-samples: Fix ssl_bc_* samples when called from a health-check
Christopher Faulet [Wed, 14 Apr 2021 13:49:41 +0000 (15:49 +0200)] 
BUG/MINOR: ssl-samples: Fix ssl_bc_* samples when called from a health-check

For all ssl_bc_* sample fetches, the test on the keyword when called from a
health-check is inverted. We must be sure the 5th charater is a 'b' to
retrieve a connection.

This patch must be backported as far as 2.2.

4 years agoMINOR: connection: Make bc_http_major compatible with tcp-checks
Christopher Faulet [Wed, 14 Apr 2021 13:46:49 +0000 (15:46 +0200)] 
MINOR: connection: Make bc_http_major compatible with tcp-checks

bc_http_major sample fetch now works when it is called from a
tcp-check. When it happens, the session origin is a check. The backend
connection is retrieved from the conn-stream attached to the check.

If required, this path may easily be backported as far as 2.2.

4 years agoBUG/MINOR: connection: Fix fc_http_major and bc_http_major for TCP connections
Christopher Faulet [Wed, 14 Apr 2021 13:40:30 +0000 (15:40 +0200)] 
BUG/MINOR: connection: Fix fc_http_major and bc_http_major for TCP connections

fc_http_major and bc_http_major sample fetches return the major digit of the
HTTP version used, respectively, by the frontend and the backend
connections, based on the mux. However, in reality, "2" is returned if the
H2 mux is detected, otherwise "1" is inconditionally returned, regardless
the mux used. Thus, if called for a raw TCP connection, "1" is returned.

To fix this bug, we now get the multiplexer flags, if there is one, to be
sure MX_FL_HTX is set.

I guess it was made this way on purpose when the H2 multiplexer was
introduced in the 1.8 and with the legacy HTTP mode there is no other
solution at the connection level. Thus this patch should be backported as
far as 2.2. For the 2.0, it must be evaluated first because of the legacy
HTTP mode.

4 years agoMINOR: logs: Add support of checks as session origin to format lf strings
Christopher Faulet [Wed, 14 Apr 2021 12:01:41 +0000 (14:01 +0200)] 
MINOR: logs: Add support of checks as session origin to format lf strings

When a log-format string is built from an health-check, the session origin
is the health-check itself and not a connection. In addition, there is no
stream. It means for now some formats are not supported: %s, %sc, %b, %bi,
%bp, %si and %sp.

Thanks to this patch, the session origin is converted to a check. So it is
possible to retrieve the backend and the backend connection. Note this
session have no listener, thus %ft format must be guarded.

This patch is light and standalone, thus it may be backported as far as 2.2
if required. However, because the error is human, it is probably better to
wait a bit to be sure everything is properly protected.

4 years agoBUG/MINOR: checks: Set missing id to the dummy checks frontend
Christopher Faulet [Fri, 16 Apr 2021 08:49:07 +0000 (10:49 +0200)] 
BUG/MINOR: checks: Set missing id to the dummy checks frontend

The dummy frontend used to create the session of the tcp-checks is
initialized without identifier. However, it is required because this id may
be used without any guard, for instance in log-format string via "%f" or
when fe_name sample fetch is called. Thus, an unset id may lead to crashes.

This patch must be backported as far as 2.2.

4 years agoMINOR: threads: Only consider running threads to end a thread harmeless period
Christopher Faulet [Fri, 16 Apr 2021 09:33:39 +0000 (11:33 +0200)] 
MINOR: threads: Only consider running threads to end a thread harmeless period

When a thread ends its harmeless period, we must only consider running
threads when testing threads_want_rdv_mask mask. To do so, we reintroduce
all_threads_mask mask in the bitwise operation (It was removed to fix a
deadlock).

Note that for now it is useless because there is no way to stop threads or
to have threads reserved for another task. But it is safer this way to avoid
bugs in the future.

4 years agoBUG/MEDIUM: threads: Ignore current thread to end its harmless period
Christopher Faulet [Wed, 14 Apr 2021 12:02:25 +0000 (14:02 +0200)] 
BUG/MEDIUM: threads: Ignore current thread to end its harmless period

A previous patch was pushed to fix a deadlock when an isolated thread ends
its harmless period (a9a9e9aac ["BUG/MEDIUM: thread: Fix a deadlock if an
isolated thread is marked as harmless"]). But, unfortunately, the fix is
incomplete. The same must be done in the outer loop, in
thread_harmless_end() function. The current thread must be ignored when
threads_want_rdv_mask mask is tested.

This patch must also be backported as far as 2.0.

4 years agoDOC: ssl: Certificate hot update works on server certificates
Remi Tricot-Le Breton [Wed, 14 Apr 2021 14:19:29 +0000 (16:19 +0200)] 
DOC: ssl: Certificate hot update works on server certificates

The CLI's "set ssl cert" command also works on backend certificates
(see GitHub issue #427).

It does not need to be backported.

4 years agoDOC: ssl: Certificate hot update only works on fronted certificates
Remi Tricot-Le Breton [Wed, 14 Apr 2021 14:19:28 +0000 (16:19 +0200)] 
DOC: ssl: Certificate hot update only works on fronted certificates

The CLI's "set ssl cert" command only works on frontend certificates but
the documentation did not specify this limitations yet.

This patch can be backported to all stable branches.

4 years agoCI: travis-ci: enable weekly graviton2 builds
Ilya Shipitsin [Thu, 15 Apr 2021 14:16:09 +0000 (19:16 +0500)] 
CI: travis-ci: enable weekly graviton2 builds

as documented in https://blog.travis-ci.com/2020-09-11-arm-on-aws
we can build on graviton2, let us expand travis-ci matrix to that
machine type as well