]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
14 months agoMEDIUM: shctx: Naming shared memory context
David Carlier [Sat, 20 Apr 2024 06:18:48 +0000 (07:18 +0100)] 
MEDIUM: shctx: Naming shared memory context

From Linux 5.17, anonymous regions can be name via prctl/PR_SET_VMA
so caches can be identified when looking at HAProxy process memory
mapping.
The most possible error is lack of kernel support, as a result
we ignore it, if the naming fails the mapping of memory context
ought to still occur.

14 months agoMINOR: Add support for UUIDv7 to the `uuid` sample fetch
Tim Duesterhus [Fri, 19 Apr 2024 19:01:27 +0000 (21:01 +0200)] 
MINOR: Add support for UUIDv7 to the `uuid` sample fetch

This adds support for UUIDv7 to the existing `uuid` sample fetch that was added
in 8a694b859cf98f8b0855b4aa5a50ebf64b501215.

14 months agoMINOR: Add `ha_generate_uuid_v7`
Tim Duesterhus [Fri, 19 Apr 2024 19:01:26 +0000 (21:01 +0200)] 
MINOR: Add `ha_generate_uuid_v7`

This function generates a version 7 UUID as per
draft-ietf-uuidrev-rfc4122bis-14.

14 months agoMINOR: tools: Rename `ha_generate_uuid` to `ha_generate_uuid_v4`
Tim Duesterhus [Fri, 19 Apr 2024 19:01:25 +0000 (21:01 +0200)] 
MINOR: tools: Rename `ha_generate_uuid` to `ha_generate_uuid_v4`

This is in preparation of adding support for other UUID versions.

14 months agoBUILD: stick-tables: silence build warnings when threads are disabled
Willy Tarreau [Wed, 24 Apr 2024 06:19:20 +0000 (08:19 +0200)] 
BUILD: stick-tables: silence build warnings when threads are disabled

Since 3.0-dev7 with commit 1a088da7c2 ("MAJOR: stktable: split the keys
across multiple shards to reduce contention"), building without threads
yields a warning about the shard not being used. This is because the
locks API does nothing of its arguments, which is the only place where
the shard is being used. We cannot modify the lock API to pretend to
consume its argument because quite often it's not even instantiated.
Let's just pretend we consume shard using an explict ALREADY_CHECKED()
statement instead. While we're at it, let's make sure that XXH32() is
not called when there is a single bucket!

No backport is needed.

14 months agoBUG/MEDIUM: applet: Let's applets decide if they have more data to deliver
Christopher Faulet [Mon, 22 Apr 2024 16:49:55 +0000 (18:49 +0200)] 
BUG/MEDIUM: applet: Let's applets decide if they have more data to deliver

Unlike the muxes, the applets have the responsibility to notify the SC if
they have more data to deliver to the stream. The same is done to notify the
SC that applets must be woken up ASAP to continue some processing. When an
applet is woken up, we pretend it has no more data to deliver by setting
SE_FL_HAVE_NO_DATA flag. If the applet removes this flag, we must take care
to not set it again just after. Otherwise, the applet may remain blocked if
there is no other condition to wake it up.

It is an issue for the applets using their own buffers because
SE_FL_HAVE_NO_DATA is erroneously set in sc_applet_recv() function, after
the applet execution. For instance, it happens for the cli applet when a
huge map is cleared. No data are delivered to the stream but we pretend it
is the case to clear the map per batches.

This patch should fix the issue #2543. No Backported needed.

14 months agoMINOR: stats: use STAT_F_* prefix for flags
Amaury Denoyelle [Mon, 22 Apr 2024 12:42:09 +0000 (14:42 +0200)] 
MINOR: stats: use STAT_F_* prefix for flags

Some flags are defined during statistics generation and output. They use
the prefix STAT_* which is also used for other purposes. Rename them
with the new prefix STAT_F_* to differentiate them from the other
usages.

14 months agoMINOR: stats: use stricter naming stats/field/line
Amaury Denoyelle [Mon, 22 Apr 2024 08:26:23 +0000 (10:26 +0200)] 
MINOR: stats: use stricter naming stats/field/line

Several unique names were used for different purposes under statistics
implementation. This caused the code to be difficult to understand.

* stat/stats name is removed when a more specific name could be used
* restrict field usage to purely refer to <struct field> which
  represents a raw stat value.
* use "line" naming to represent an array of <struct field>

14 months agoMINOR: stats: rename info stats
Amaury Denoyelle [Mon, 22 Apr 2024 07:41:15 +0000 (09:41 +0200)] 
MINOR: stats: rename info stats

Info are used to expose haproxy global metrics. It is similar to proxy
statistics and any other module. As such, rename info indexes using
SI_I_INF_* prefix. Also info variable is renamed stat_line_info.

Thanks to this, naming is now consistent between info and other
statistics. It will help to integrate it as a "global" statistics
module.

14 months agoMINOR: stats: rename ambiguous stat_l and stat_count
Amaury Denoyelle [Mon, 22 Apr 2024 09:19:17 +0000 (11:19 +0200)] 
MINOR: stats: rename ambiguous stat_l and stat_count

Statistics were extended with the introduction of stats module. This
mechanism allows to expose various metrics for several haproxy
components. As a consequence of this, some static variables were
transformed to dynamic ones to be able to regroup all statistics
definition.

Rename these variables with more explicit naming :
* stat_lines can be used to generate one line of statistics for any
  module using struct field as value
* metrics and metrics_len are used to stored description of metrics
  indexed by module

Note that info is not integrated in the statistics module mechanism.
However, it could be done in the future to better reflect its purpose.

14 months agoMINOR: stats: rename proxy stats
Amaury Denoyelle [Fri, 19 Apr 2024 16:03:45 +0000 (18:03 +0200)] 
MINOR: stats: rename proxy stats

This commit is the first one of a serie which adjust naming convention
for stats module. The objective is to remove ambiguity and better
reflect how stats are implemented, especially since the introduction of
stats module.

This patch renames elements related to proxies statistics. One of the
main change is to rename ST_F_* statistics indexes prefix with the new
name ST_I_PX_*. This remove the reference to field which represents
another concept in the stats module. In the same vein, global
stat_fields variable is renamed metrics_px.

14 months agoREGTESTS: use -dI for insecure fork by default in the regtest scripts
William Lallemand [Mon, 22 Apr 2024 14:15:57 +0000 (16:15 +0200)] 
REGTESTS: use -dI for insecure fork by default in the regtest scripts

Let's remove the CI HAPROXY_ARGS setting and set -dI for anything run
with the run-regtests.sh.

14 months agoBUG/MINOR: stats: fix stot metric for listeners
Amaury Denoyelle [Thu, 4 Apr 2024 16:15:42 +0000 (18:15 +0200)] 
BUG/MINOR: stats: fix stot metric for listeners

This commit is part of a series to align counters usage between
frontends/listeners on one side and backends/servers on the other.

On frontend side, "stot" is the total count of sessions for both proxies
and listeners. For proxies, fe_counters <cum_sess> is correctely used.
The bug is on listeners where <cum_conn> value is returned, which
instead indicates a number of connection. This commit fixes this by
returning <cum_sess> counter value for "stot" metric.

Along this fixes, use the opportunity to report "conn_tot" for listeners
using <cum_conn> value, as for frontend proxies.

This commit fixes a bug but must not be backported as stats output is
changed.

14 months agoBUG/MINOR: backend: use cum_sess counters instead of cum_conn
Amaury Denoyelle [Thu, 4 Apr 2024 16:08:46 +0000 (18:08 +0200)] 
BUG/MINOR: backend: use cum_sess counters instead of cum_conn

This commit is part of a serie to align counters usage between
frontends/listeners on one side and backends/servers on the other.

"stot" metric refers to the total number of sessions. On backend side,
it is interpreted as a number of streams. Previously, this was accounted
using <cum_sess> be_counters field for servers, but <cum_conn> instead
for backend proxies.

Adjust this by using <cum_sess> for both proxies and servers. As such,
<cum_conn> field can be removed from be_counters.

Note that several diagnostic messages which reports total frontend and
backend connections were adjusted to use <cum_sess>. However, this is an
outdated and misleading information as it does reports streams count on
backend side. These messages should be fixed in a separate commit.

This should be backported to all stable releases.

14 months agoMINOR: backend: use be_counters for health down accounting
Amaury Denoyelle [Thu, 28 Mar 2024 16:37:07 +0000 (17:37 +0100)] 
MINOR: backend: use be_counters for health down accounting

This commit is the first one of a series which aims to align counters
usage between frontends/listeners on one side and backends/servers on
the other.

Remove <down_trans> field from proxy structure. Use instead the same
name field from be_counters structure, which is already used for
servers.

14 months agoBUILD: ssl: use %zd for sizeof() in ssl_ckch.c
William Lallemand [Sat, 20 Apr 2024 12:25:42 +0000 (14:25 +0200)] 
BUILD: ssl: use %zd for sizeof() in ssl_ckch.c

32bits build was broken because of wrong printf length modifier.

src/ssl_ckch.c:4144:66: error: format specifies type 'long' but the argument has type 'unsigned int' [-Werror,-Wformat]
 4143 |                                                 memprintf(err, "parsing [%s:%d] : cannot parse '%s' value '%s', too long, max len is %ld.\n",
      |                                                                                                                                      ~~~
      |                                                                                                                                      %u
 4144 |                                                           file, linenum, args[cur_arg], args[cur_arg + 1], sizeof(alias_name));
      |                                                                                                            ^~~~~~~~~~~~~~~~~~
src/ssl_ckch.c:4217:64: error: format specifies type 'long' but the argument has type 'unsigned int' [-Werror,-Wformat]
 4216 |                                 memprintf(err, "parsing [%s:%d] : cannot parse '%s' value '%s', too long, max len is %ld.\n",
      |                                                                                                                      ~~~
      |                                                                                                                      %u
 4217 |                                           file, linenum, args[cur_arg], args[cur_arg + 1], sizeof(alias_name));
      |                                                                                            ^~~~~~~~~~~~~~~~~~
2 errors generated.
make: *** [Makefile:1034: src/ssl_ckch.o] Error 1
make: *** Waiting for unfinished jobs....

Replace %ld by %zd.

Should fix issue #2542.

14 months ago[RELEASE] Released version 3.0-dev8 v3.0-dev8
Willy Tarreau [Fri, 19 Apr 2024 16:02:28 +0000 (18:02 +0200)] 
[RELEASE] Released version 3.0-dev8

Released version 3.0-dev8 with the following main changes :
    - BUG/MINOR: cli: Don't warn about a too big command for incomplete commands
    - BUG/MINOR: listener: always assign distinct IDs to shards
    - BUG/MINOR: log: fix lf_text_len() truncate inconsistency
    - BUG/MINOR: tools/log: invalid encode_{chunk,string} usage
    - BUG/MINOR: log: invalid snprintf() usage in sess_build_logline()
    - CLEANUP: log: lf_text_len() returns a pointer not an integer
    - MINOR: quic: simplify qc_send_hdshk_pkts() return
    - MINOR: quic: uniformize sending methods for handshake
    - MINOR: quic: improve sending API on retransmit
    - MINOR: quic: use qc_send_hdshk_pkts() in handshake IO cb
    - MEDIUM: quic: remove duplicate hdshk/app send functions
    - OPTIM: quic: do not call qc_send() if nothing to emit
    - OPTIM: quic: do not call qc_prep_pkts() if everything sent
    - BUG/MEDIUM: http-ana: Deliver 502 on keep-alive for fressh server connection
    - BUG/MINOR: http-ana: Fix TX_L7_RETRY and TX_D_L7_RETRY values
    - BUILD: makefile: warn about unknown USE_* variables
    - BUILD: makefile: support USE_xxx=0 as well
    - BUG/MINOR: guid: fix crash on invalid guid name
    - BUILD: atomic: fix peers build regression on gcc < 4.7 after recent changes
    - BUG/MINOR: debug: make sure DEBUG_STRICT=0 does work as documented
    - BUILD: cache: fix non-inline vs inline declaration mismatch to silence a warning
    - BUILD: debug: make DEBUG_STRICT=1 the default
    - BUILD: pools: make DEBUG_MEMORY_POOLS=1 the default option
    - CI: update the build options to get rid of unneeded DEBUG options
    - BUILD: makefile: get rid of the config CFLAGS variable
    - BUILD: makefile: allow to use CFLAGS to append build options
    - BUILD: makefile: drop the SMALL_OPTS settings
    - BUILD: makefile: move -O2 from CPU_CFLAGS to OPT_CFLAGS
    - BUILD: makefile: get rid of the CPU variable
    - BUILD: makefile: drop the ARCH variable and better document ARCH_FLAGS
    - BUILD: makefile: extract ARCH_FLAGS out of LDFLAGS
    - BUILD: makefile: move the fwrapv option to STD_CFLAGS
    - BUILD: makefile: make the ERR variable also support 0
    - BUILD: makefile: add FAILFAST to select the -Wfatal-errors behavior
    - BUILD: makefile: extract -Werror/-Wfatal-errors from automatic CFLAGS
    - BUILD: makefile: split WARN_CFLAGS from SPEC_CFLAGS
    - BUILD: makefile: rename SPEC_CFLAGS to NOWARN_CFLAGS
    - BUILD: makefile: do not pass warnings to VERBOSE_CFLAGS
    - BUILD: makefile: also drop DEBUG_CFLAGS
    - CLEANUP: makefile: make the output of the "opts" target more readable
    - DOC: install: clarify the build process by splitting it into subsections
    - BUG/MINOR: server: fix slowstart behavior
    - BUG/MEDIUM: cache/stats: Handle inbuf allocation failure in the I/O handler
    - MINOR: ssl: add the section parser for 'crt-store'
    - DOC: configuration: Add 3.12 Certificate Storage
    - REGTESTS: ssl: test simple case of crt-store
    - MINOR: ssl: rename ckchs_load_cert_file to new_ckch_store_load_files_path
    - MINOR: ssl/crtlist: alloc ssl_conf only when a valid keyword is found
    - BUG/MEDIUM: stick-tables: fix the task's next expiration date
    - CLEANUP: stick-tables: always respect the to_batch limit when trashing
    - BUG/MEDIUM: peers/trace: fix crash when listing event types
    - BUG/MAJOR: stick-tables: fix race with peers in entry expiration
    - DEBUG: pool: improve decoding of corrupted pools
    - REORG: pool: move the area dump with symbol resolution to tools.c
    - DEBUG: pools: report the data around the offending area in case of mismatch
    - MINOR: listener/protocol: add proto name in alerts
    - MINOR: proto_quic: add proto name in alert
    - BUG/MINOR: lru: fix the standalone test case for invalid revision
    - DOC: management: fix typos
    - CI: revert kernel addr randomization introduced in 3a0fc864
    - MINOR: ring: clarify the usage of ring_size() and add ring_allocated_size()
    - BUG/MAJOR: ring: use the correct size to reallocate startup_logs
    - MINOR: ring: always check that the old ring fits in the new one in ring_dup()
    - CLEANUP: ssl: remove dead code in cfg_parse_crtstore()
    - MINOR: ssl: supports crt-base in crt-store
    - MINOR: ssl: 'key-base' allows to load a 'key' from a specific path
    - MINOR: net_helper: Add support for floats/doubles.
    - BUG/MEDIUM: grpc: Fix several unaligned 32/64 bits accesses
    - MINOR: peers: Split resync process function to separate running/stopping states
    - MINOR: peers: Add 2 peer flags about the peer learn status
    - MINOR: peers: Add flags to report the peer state to the resync task
    - MINOR: peers: sligthly adapt part processing the stopping signal
    - MINOR: peers: Add functions to commit peer changes from the resync task
    - BUG/MINOR: peers: Report a resync was explicitly requested from a thread-safe manner
    - BUG/MAJOR: peers: Update peers section state from a thread-safe manner
    - MEDIUM: peers: Only lock one peer at a time in the sync process function
    - MINOR: peer: Restore previous peer flags value to ease debugging
    - BUG/MEDIUM: stconn: Don't forward channel data if input data must be filtered
    - BUILD: cache: fix a build warning with gcc < 7
    - BUILD: xxhash: silence a build warning on Solaris + gcc-5.5
    - CI: reduce ASAN log redirection umbrella size
    - CLEANUP: assorted typo fixes in the code and comments
    - BUG/MEDIUM: evports: do not clear returned events list on signal
    - MEDIUM: evports: permit to report multiple events at once
    - MEDIUM: ssl: support aliases in crt-store
    - BUG/MINOR: ssl: check on forbidden character on wrong value
    - BUG/MINOR: ssl: fix crt-store load parsing
    - BUG/MEDIUM: applet: Fix applet API to put input data in a buffer
    - BUG/MEDIUM: spoe: Always retry when an applet fails to send a frame
    - BUG/MEDIUM: peers: Fix exit condition when max-updates-at-once is reached
    - BUILD: linuxcap: Properly declare prepare_caps_from_permitted_set()
    - BUG/MEDIUM: peers: fix localpeer regression with 'bind+server' config style
    - MINOR: peers: stop relying on srv->addr to find peer port
    - MEDIUM: ssl: support a named crt-store section
    - MINOR: stats: remove implicit static trash_chunk usage
    - REORG: stats: extract HTML related functions
    - REORG: stats: extract JSON related functions
    - MEDIUM: ssl: crt-base and key-base local keywords for crt-store
    - MINOR: stats: Get the right prototype for stats_dump_html_end().
    - MAJOR: ssl: use the msg callback mecanism for backend connections
    - MINOR: ssl: implement keylog fetches for backend connections
    - BUG/MINOR: stconn: Fix sc_mux_strm() return value
    - MINOR: mux-pt: Test conn flags instead of sedesc ones to perform a full close
    - MINOR: stconn/connection: Move shut modes at the SE descriptor level
    - MINOR: stconn: Rewrite shutdown functions to simplify the switch statements
    - MEDIUM: stconn: Use only one SC function to shut connection endpoints
    - MEDIUM: stconn: Explicitly pass shut modes to shut applet endpoints
    - MEDIUM: stconn: Use one function to shut connection and applet endpoints
    - MEDIUM: muxes: Use one callback function to shut a mux stream
    - BUG/MINOR: sock: handle a weird condition with connect()
    - BUG/MINOR: fd: my_closefrom() on Linux could skip contiguous series of sockets
    - BUG/MEDIUM: peers: Don't set PEERS_F_RESYNC_PROCESS flag on a peer
    - BUG/MEDIUM: peers: Fix state transitions of a peer
    - MINOR: init: use RLIMIT_DATA instead of RLIMIT_AS
    - CI: modernize macos matrix

14 months agoCI: modernize macos matrix
Ilya Shipitsin [Fri, 19 Apr 2024 05:16:45 +0000 (07:16 +0200)] 
CI: modernize macos matrix

let's stick to macos-13 for stable branches and macos-14 for development branches.
since macos-14 is available for Apple Silicon, some modifications are required
for VTest (should be ported to VTest later)

news: https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available/

14 months agoMINOR: init: use RLIMIT_DATA instead of RLIMIT_AS
Valentine Krasnobaeva [Thu, 18 Apr 2024 13:38:58 +0000 (15:38 +0200)] 
MINOR: init: use RLIMIT_DATA instead of RLIMIT_AS

Limiting total allocatable process memory (VSZ) via setting RLIMIT_AS limit is
no longer effective, in order to restrict memory consumption at run time.
We can see from process memory map below, that there are many holes within
the process VA space, which bumps its VSZ to 1.5G. These holes are here by
many reasons and could be explaned at first by the full randomization of
system VA space. Now it is usually enabled in Linux kernels by default. There
are always gaps around the process stack area to trap overflows. Holes before
and after shared libraries could be explained by the fact, that on many
architectures libraries have a 'preferred' address to be loaded at; putting
them elsewhere requires relocation work, and probably some unshared pages.
Repetitive holes of 65380K are most probably correspond to the header that
malloc has to allocate before asked a claimed memory block. This header is
used by malloc to link allocated chunks together and for its internal book
keeping.

$ sudo pmap -x -p `pidof haproxy`
127136:   ./haproxy -f /home/haproxy/haproxy/haproxy_h2.cfg
Address           Kbytes     RSS   Dirty Mode  Mapping
0000555555554000     388      64       0 r---- /home/haproxy/haproxy/haproxy
00005555555b5000    2608    1216       0 r-x-- /home/haproxy/haproxy/haproxy
0000555555841000     916      64       0 r---- /home/haproxy/haproxy/haproxy
0000555555926000      60      60      60 r---- /home/haproxy/haproxy/haproxy
0000555555935000     116     116     116 rw--- /home/haproxy/haproxy/haproxy
0000555555952000    7872    5236    5236 rw---   [ anon ]
00007fff98000000     156      36      36 rw---   [ anon ]
00007fff98027000   65380       0       0 -----   [ anon ]
00007fffa0000000     156      36      36 rw---   [ anon ]
00007fffa0027000   65380       0       0 -----   [ anon ]
00007fffa4000000     156      36      36 rw---   [ anon ]
00007fffa4027000   65380       0       0 -----   [ anon ]
00007fffa8000000     156      36      36 rw---   [ anon ]
00007fffa8027000   65380       0       0 -----   [ anon ]
00007fffac000000     156      36      36 rw---   [ anon ]
00007fffac027000   65380       0       0 -----   [ anon ]
00007fffb0000000     156      36      36 rw---   [ anon ]
00007fffb0027000   65380       0       0 -----   [ anon ]
...
00007ffff7fce000       4       4       0 r-x--   [ anon ]
00007ffff7fcf000       4       4       0 r---- /usr/lib/x86_64-linux-gnu/ld-2.31.so
00007ffff7fd0000     140     140       0 r-x-- /usr/lib/x86_64-linux-gnu/ld-2.31.so
...
00007ffff7ffe000       4       4       4 rw---   [ anon ]
00007ffffffde000     132      20      20 rw---   [ stack ]
ffffffffff600000       4       0       0 --x--   [ anon ]
---------------- ------- ------- -------
total kB         1499288   75504   72760

This exceeded VSZ makes impossible to start an haproxy process with 200M
memory limit, set at its initialization stage as RLIMIT_AS. We usually
have in this case such cryptic output at stderr:

$ haproxy -m 200 -f haproxy_quic.cfg
        (null)(null)(null)(null)(null)(null)

At the same time the process RSS (a memory really used) is only 75,5M.
So to make process memory accounting more realistic let's base the memory
limit, set by -m option, on RSS measurement and let's use RLIMIT_DATA instead
of RLIMIT_AS.

RLIMIT_AS was used before, because earlier versions of haproxy always allocate
memory buffers for new connections, but data were not written there
immediately. So these buffers were not instantly counted in RSS, but were
always counted in VSZ. Now we allocate new buffers only in the case, when we
will write there some data immediately, so using RLIMIT_DATA becomes more
appropriate.

14 months agoBUG/MEDIUM: peers: Fix state transitions of a peer
Christopher Faulet [Fri, 19 Apr 2024 14:50:08 +0000 (16:50 +0200)] 
BUG/MEDIUM: peers: Fix state transitions of a peer

The commit 9425aeaffb ("BUG/MAJOR: peers: Update peers section state from a
thread-safe manner") introduced regressions about state transitions of a
peer.

A peer may be in a connected, accepted or released state. Before, changes for
these states were performed synchronously. Since the commit above, changes
are mainly performed in the sync process task.

The first regression was about the released then accepted state transition,
called the renewed state. In reality the state was always crushed by the
accepted state. After some review, the state was just removed to always
perform the cleanup in the sync process task before acknowledging the
connected or accepted states.

Then, a wakeup of the peer applet was missing from the sync process task
after the ack of connected or accepted states, blocking the applet.

Finally, when a peer is in released, connected or accepted state, we must
take care to wait the sync process task wakeup before trying to receive or
send messages.

This patch must only be backported if the above commit is backported.

14 months agoBUG/MEDIUM: peers: Don't set PEERS_F_RESYNC_PROCESS flag on a peer
Christopher Faulet [Fri, 19 Apr 2024 13:39:52 +0000 (15:39 +0200)] 
BUG/MEDIUM: peers: Don't set PEERS_F_RESYNC_PROCESS flag on a peer

The bug was introduced by commit 9425aeaffb ("BUG/MAJOR: peers: Update peers
section state from a thread-safe manner"). A peers flags was set on a peer
by error. Just remove it.

This patch must only be backported if the above commit is backported.

14 months agoBUG/MINOR: fd: my_closefrom() on Linux could skip contiguous series of sockets
Willy Tarreau [Fri, 19 Apr 2024 14:52:32 +0000 (16:52 +0200)] 
BUG/MINOR: fd: my_closefrom() on Linux could skip contiguous series of sockets

We got a detailed report analysis showing that our optimization consisting
in using poll() to detect already closed FDs within a 1024 range has an
issue with the case where 1024 consecutive FDs are open (hence do not show
POLLNVAL) and none of them has any activity report. In this case poll()
returns zero update and we would just skip the loop that inspects all the
FDs to close the valid ones. One visible effect is that the called programs
might occasionally see some FDs being exposed in the low range of their fd
space, possibly making the process run out of FDs when trying to open a
file for example.

Note that this is actually a fix for commit b8e602cb1b ("BUG/MINOR: fd:
make sure my_closefrom() doesn't miss some FDs") that already faced a
more common form of this problem (incomplete but non-empty FDs reported).

This can be backported up to 2.0.

14 months agoBUG/MINOR: sock: handle a weird condition with connect()
Willy Tarreau [Tue, 9 Apr 2024 06:03:10 +0000 (08:03 +0200)] 
BUG/MINOR: sock: handle a weird condition with connect()

As reported on github issue #2491, there's a very strange situation where
epoll_wait() appears to be reported EPOLLERR only (and not IN/OUT/HUP etc
as normally happens with EPOLLERR), and when connect() is called again to
check the state of the ongoing connection, it returns EALREADY, basically
saying "no news, please wait". This obviously triggers a wakeup loop. For
now it has remained impossible to reproduce this issue outside of the
reporter's environment, but that's definitely something that is impossible
to get out from.

The workaround here is to address the lowest level cause we can act on,
which is to avoid returning to wait if EPOLLERR was returned. Indeed, in
this case we know it will loop, so we must definitely take this one into
account. We only do that after connect() asks us to wait, so that a
properly established connection with a queued error at the end of an
exchange will not be diverted and will be handled as usual.

This should be backported to approximately all versions, at least as far
as 2.4 according to the reporter who observed it there.

Thanks to @donnyxray for their useful captures isolating the problem.

14 months agoMEDIUM: muxes: Use one callback function to shut a mux stream
Christopher Faulet [Thu, 18 Apr 2024 07:56:11 +0000 (09:56 +0200)] 
MEDIUM: muxes: Use one callback function to shut a mux stream

mux-ops .shutr and .shutw callback functions are merged into a unique
functions, called .shut. The shutdown mode is still passed as argument,
muxes are responsible to test it. Concretly, .shut() function of each mux is
now the content of the old .shutw() followed by the content of the old
.shutr().

14 months agoMEDIUM: stconn: Use one function to shut connection and applet endpoints
Christopher Faulet [Tue, 16 Apr 2024 16:36:40 +0000 (18:36 +0200)] 
MEDIUM: stconn: Use one function to shut connection and applet endpoints

se_shutdown() function is now used to perform a shutdown on a connection
endpoint and an applet endpoint. The same function is used for
both. sc_conn_shut() function was removed and appctx_shut() function was
updated to only deal with the applet stuff.

14 months agoMEDIUM: stconn: Explicitly pass shut modes to shut applet endpoints
Christopher Faulet [Tue, 16 Apr 2024 16:07:43 +0000 (18:07 +0200)] 
MEDIUM: stconn: Explicitly pass shut modes to shut applet endpoints

It is the same than the previous patch but for applets. Here there is
already only one function. But with this patch, appctx_shut() function was
modified to explicitly get shutdown mode as parameter. In addition
appctx_shutw() was removed.

14 months agoMEDIUM: stconn: Use only one SC function to shut connection endpoints
Christopher Faulet [Tue, 16 Apr 2024 15:42:38 +0000 (17:42 +0200)] 
MEDIUM: stconn: Use only one SC function to shut connection endpoints

The SC API to perform shutdowns on connection endpoints was unified to have
only one function, sc_conn_shut(), with read/write shut modes passed
explicitly. It means sc_conn_shutr() and sc_conn_shutw() were removed. The
next step is to do the same at the mux level.

14 months agoMINOR: stconn: Rewrite shutdown functions to simplify the switch statements
Christopher Faulet [Tue, 16 Apr 2024 14:26:49 +0000 (16:26 +0200)] 
MINOR: stconn: Rewrite shutdown functions to simplify the switch statements

To ease shutdown API refactoring, shutdown callback functions were
simplified. The fallthrough were removed from the switch statements.

14 months agoMINOR: stconn/connection: Move shut modes at the SE descriptor level
Christopher Faulet [Tue, 16 Apr 2024 06:51:56 +0000 (08:51 +0200)] 
MINOR: stconn/connection: Move shut modes at the SE descriptor level

CO_SHR_* and CO_SHW_* modes are in fact used by the stream-connectors to
instruct the muxes how streams must be shut done. It is then the mux
responsibility to decide if it must be propagated to the connection layer or
not. And in this case, the modes above are only tested to pass a boolean
(clean or not).

So, it is not consistant to still use connection related modes for
information set at an upper layer and never used by the connection layer
itself.

These modes are thus moved at the sedesc level and merged into a single
enum. Idea is to add more modes, not necessarily mutually exclusive, to pass
more info to the muxes. For now, it is a one-for-one renaming.

14 months agoMINOR: mux-pt: Test conn flags instead of sedesc ones to perform a full close
Christopher Faulet [Tue, 16 Apr 2024 06:22:36 +0000 (08:22 +0200)] 
MINOR: mux-pt: Test conn flags instead of sedesc ones to perform a full close

In .shutr and .shutw callback functions, we must rely on the connection
flags (CO_FL_SOCK_RD_SH/WR_SH) to decide to fully close the connection
instead of using sedesc flags. At the end, for the PT multiplexer, it is
equivalent. But it is more logicial and consistent this way.

14 months agoBUG/MINOR: stconn: Fix sc_mux_strm() return value
Christopher Faulet [Fri, 19 Apr 2024 13:29:57 +0000 (15:29 +0200)] 
BUG/MINOR: stconn: Fix sc_mux_strm() return value

Since the begining, this function returns a pointer on an appctx while it
should be a void pointer. It is the caller responsibility to cast it to the
right type, the corresponding mux stream in this case.

However, it is not a big deal because this function is unused for now. Only
the unsafe one is used.

This patch must be backported as far as 2.6.

14 months agoMINOR: ssl: implement keylog fetches for backend connections
William Lallemand [Fri, 19 Apr 2024 12:29:05 +0000 (14:29 +0200)] 
MINOR: ssl: implement keylog fetches for backend connections

This patch implements the backend side of the keylog fetches.
The code was ready but needed the SSL message callbacks.

This could be used like this:

 log-format "CLIENT_EARLY_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_client_early_traffic_secret]\n
             CLIENT_HANDSHAKE_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_client_handshake_traffic_secret]\n
             SERVER_HANDSHAKE_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_server_handshake_traffic_secret]\n
             CLIENT_TRAFFIC_SECRET_0 %[ssl_bc_client_random,hex] %[ssl_bc_client_traffic_secret_0]\n
             SERVER_TRAFFIC_SECRET_0 %[ssl_bc_client_random,hex] %[ssl_bc_server_traffic_secret_0]\n
             EXPORTER_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_exporter_secret]\n
             EARLY_EXPORTER_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_early_exporter_secret]"

14 months agoMAJOR: ssl: use the msg callback mecanism for backend connections
William Lallemand [Fri, 19 Apr 2024 12:18:32 +0000 (14:18 +0200)] 
MAJOR: ssl: use the msg callback mecanism for backend connections

Backend SSL connections never used the ssl_sock_msg_callbacks() which
prevent the use of keylog on the server side.

The impact should be minimum, though it add a major callback system for
protocol analysis, which is the same used on frontend connections.

https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_msg_callback.html

The patch add a call to SSL_CTX_set_msg_callback() in
ssl_sock_prepare_srv_ssl_ctx() the same way it's done for bind lines in
ssl_sock_prepare_ctx().

14 months agoMINOR: stats: Get the right prototype for stats_dump_html_end().
Olivier Houchard [Thu, 18 Apr 2024 23:49:12 +0000 (01:49 +0200)] 
MINOR: stats: Get the right prototype for stats_dump_html_end().

When the stat code was reorganized, and the prototype to
stats_dump_html_end() was moved to its own header, it missed the function
arguments. Fix that.

This should fix issue 2540.

14 months agoMEDIUM: ssl: crt-base and key-base local keywords for crt-store
William Lallemand [Thu, 18 Apr 2024 15:24:58 +0000 (17:24 +0200)] 
MEDIUM: ssl: crt-base and key-base local keywords for crt-store

Add support for crt-base and key-base local keywords for the crt-store.

current_crtbase and current_keybase are filed with a copy of the global
keyword argument when a crt-store is declared, and updated with a new
path when the keywords are in the crt-store section.

The ckch_conf_kws[] array was updated with &current_crtbase and
&current_keybase instead of the global_ssl ones so the parser can use
them.

The keyword must be used before any "load" line in a crt-store section.

Example:

    crt-store web
        crt-base /etc/ssl/certs/
        key-base /etc/ssl/private/
        load crt "site3.crt" alias "site3"
        load crt "site4.crt" key "site4.key"

    frontend in2
        bind *:443 ssl crt "@web/site3" crt "@web/site4.crt"

14 months agoREORG: stats: extract JSON related functions
Amaury Denoyelle [Tue, 16 Apr 2024 12:57:54 +0000 (14:57 +0200)] 
REORG: stats: extract JSON related functions

This commit is similar to the previous one. This time it deals with
functions related to stats JSON output.

14 months agoREORG: stats: extract HTML related functions
Amaury Denoyelle [Tue, 16 Apr 2024 09:21:06 +0000 (11:21 +0200)] 
REORG: stats: extract HTML related functions

Extract functions related to HTML stats webpage from stats.c into a new
module named stats-html. This allows to reduce stats.c to roughly half
of its original size.

14 months agoMINOR: stats: remove implicit static trash_chunk usage
Amaury Denoyelle [Thu, 18 Apr 2024 14:13:48 +0000 (16:13 +0200)] 
MINOR: stats: remove implicit static trash_chunk usage

A static variable trash_chunk was used as implicit buffer in most of
stats output function. It was a oneline buffer uses as temporary storage
before emitting to the final applet or CLI buffer.

Replaces it by a buffer defined in show_stat_ctx structure. This allows
to retrieve it in most of stats output function. An additional parameter
was added for the function where context was not already used. This
renders the code cleaner and will allow to split stats.c in several
source files.

As a result of a new member into show_stat_ctx, per-command context max
size has increased. This forces to increase APPLET_MAX_SVCCTX to ensure
pool size is big enough. Increase it to 128 bytes which includes some
extra room for the future.

14 months agoMEDIUM: ssl: support a named crt-store section
William Lallemand [Thu, 18 Apr 2024 13:54:16 +0000 (15:54 +0200)] 
MEDIUM: ssl: support a named crt-store section

This patch introduces named crt-store section. A named crt-store allows
to add a scope to the crt name.

For example, a crt named "foo.crt" in a crt-store named "web" will
result in a certificate called "@web/foo.crt".

14 months agoMINOR: peers: stop relying on srv->addr to find peer port
Aurelien DARRAGON [Thu, 18 Apr 2024 09:03:45 +0000 (11:03 +0200)] 
MINOR: peers: stop relying on srv->addr to find peer port

Now that peers entirely rely on peer->srv for connection settings, and
that it was confirmed that it works properly thanks to previous commit,
let's finish what we started in f6ae258 ("MINOR: peers: rely on srv->addr
and remove peer->addr") and stop using srv->addr to find out peers port
and instead rely on srv->svc_port as it's already done for other proxy
types.

14 months agoBUG/MEDIUM: peers: fix localpeer regression with 'bind+server' config style
Aurelien DARRAGON [Wed, 17 Apr 2024 16:43:25 +0000 (18:43 +0200)] 
BUG/MEDIUM: peers: fix localpeer regression with 'bind+server' config style

A dumb mistake was made in f6ae25858 ("MINOR: peers: rely on srv->addr
and remove peer->addr"). I completely overlooked the part where the bind
address settings are used as implicit server's address settings when the
peers are declared using the new bind+server config style (which is the
new recommended method to declare peers as it follows the same logic as
the one used in other proxy sections).

As such, the peers synchro fails to work between previous and new process
(localpeer mechanism) upon reload when declaring peers with way:

global
localpeer local

peers mypeers
bind 127.0.0.1:10001
server local

And one has to use the 'old' config style to make it work:

global
localpeer local

peers mypeers
peer local 127.0.0.1:10001

--

To fix the issue, let's explicitly set the server's addr:port
according to the bind's address settings (only the first listener is
considered) when local peer was declared using the 'bind+server' method.

No backport needed.

14 months agoBUILD: linuxcap: Properly declare prepare_caps_from_permitted_set()
Christopher Faulet [Thu, 18 Apr 2024 08:08:46 +0000 (10:08 +0200)] 
BUILD: linuxcap: Properly declare prepare_caps_from_permitted_set()

Expected arguments were not specified in the
prepare_caps_from_permitted_set() function declaration. It is an issue for
some compilers, for instance clang. But at the end, it is unexpected and
deprecated.

No backport needed, except if f0b6436f57 ("MEDIUM: capabilities: check
process capabilities sets") is backported.

14 months agoBUG/MEDIUM: peers: Fix exit condition when max-updates-at-once is reached
Christopher Faulet [Thu, 18 Apr 2024 07:05:11 +0000 (09:05 +0200)] 
BUG/MEDIUM: peers: Fix exit condition when max-updates-at-once is reached

When a peer applet is pushing updates, we limit the number of update sent at
once via a global parameter to not spend too much time in the applet. On
interrupt, we claimed for more room to be woken up quickly. However, this
statement is only true if something was pushed in the buffer. Otherwise,
with an empty buffer, if the stream itself is not woken up, the applet
remains also blocked because there is no send activity on the other side to
unblock it.

In this case, instead of requesting more room, it is sufficient to state the
applet have more data to send.

This patch must be backported as far as 2.6.

14 months agoBUG/MEDIUM: spoe: Always retry when an applet fails to send a frame
Christopher Faulet [Thu, 18 Apr 2024 06:58:55 +0000 (08:58 +0200)] 
BUG/MEDIUM: spoe: Always retry when an applet fails to send a frame

This bug is related to the previous one ("BUG/MEDIUM: spoe: Always retry
when an applet fails to send a frame"). applet_putblk() function retruns -1
on error and it should always be interpreted as a missing of room in the
buffer. However, on the spoe, this was processed as an I/O error.

This patch must be backported as far as 2.8.

14 months agoBUG/MEDIUM: applet: Fix applet API to put input data in a buffer
Christopher Faulet [Thu, 18 Apr 2024 06:42:27 +0000 (08:42 +0200)] 
BUG/MEDIUM: applet: Fix applet API to put input data in a buffer

applet_putblk and co were added to simplify applets. In 2.8, a fix was
pushed to deal with all errors as a room error because the vast majority of
applets didn't expect other kind of errors. The API was changed with the
commit 389b7d1f7b ("BUG/MEDIUM: applet: Fix API for function to push new
data in channels buffer").

Unfortunately and for unknown reason, the fix was totally failed. Checks on
channel functions were just wrong and not consistent. applet_putblk()
function is especially affected because the error is returned but no flag
are set on the SC to request more room. Because of this bug, applets relying
on it may be blocked, waiting for more room, and never woken up.

It is an issue for the peer and spoe applets.

This patch must be backported as far as 2.8.

14 months agoBUG/MINOR: ssl: fix crt-store load parsing
William Lallemand [Wed, 17 Apr 2024 18:52:46 +0000 (20:52 +0200)] 
BUG/MINOR: ssl: fix crt-store load parsing

The crt-store load line parser relies on offsets of member of the
ckch_conf struct. However the new "alias" keyword as an offset to
-1, because it does not need to be used. Plan was to handle it that way
in the parser, but it wasn't supported yet. So -1 was still used in an
offset computation which was not used, but ASAN could see the problem.

This patch fixes the issue by using a signed type for the offset value,
so any negative value would be skipped. It also introduced a
PARSE_TYPE_NONE for the parser.

No backport needed.

14 months agoBUG/MINOR: ssl: check on forbidden character on wrong value
William Lallemand [Wed, 17 Apr 2024 18:28:36 +0000 (20:28 +0200)] 
BUG/MINOR: ssl: check on forbidden character on wrong value

The check on the forbidden '/' for the crt-store load keyword was done
on the keyword instead of the value itself.

No backport needed.

14 months agoMEDIUM: ssl: support aliases in crt-store
William Lallemand [Wed, 17 Apr 2024 15:03:58 +0000 (17:03 +0200)] 
MEDIUM: ssl: support aliases in crt-store

The crt-store load line now allows to put an alias. This alias is used
as the key in the ckch_tree instead of the certificate. This way an
alias can be referenced in the configuration with the '@/' prefix.

This can only be define with a crt-store.

14 months agoMEDIUM: evports: permit to report multiple events at once
Willy Tarreau [Wed, 17 Apr 2024 14:37:04 +0000 (16:37 +0200)] 
MEDIUM: evports: permit to report multiple events at once

Since the beginning in 2.0 the nevlist parameter was set to 1 before
calling port_getn(), which means that a single FD event will be reported
per polling loop. This is extremely inefficient, and all the code was
designed to use global.tune.maxpollevents. It looks like it's a leftover
of a temporary debugging change. No apparent issues were found by setting
it to a higher value, so better do that.

That code is not much used nowadays with Solaris disappearing from the
landscape, so even if this definitely was a bug, it's preferable not to
backport that fix as it could uncover other subtle bugs that were never
raised yet.

14 months agoBUG/MEDIUM: evports: do not clear returned events list on signal
Willy Tarreau [Wed, 17 Apr 2024 14:25:20 +0000 (16:25 +0200)] 
BUG/MEDIUM: evports: do not clear returned events list on signal

Since 2.0 with commit 0ba4f483d2 ("MAJOR: polling: add event ports
support (Solaris)"), the polling system on Solaris suffers from a
signal handling problem. It turns out that this API is very bizarre,
as reported events are automatically unregistered and their counter
is updated in the same variable that was used to pass the count on
input, making it difficult to handle certain error codes (how should
one handle ENOSYS for example?). And to complete everything, the API
is able to return both EINTR and an event if a signal is reported.

The code tries to deal with certain such cases (e.g. ETIME for timeout
can also report an event), otherwise it defaults to clearing the
event counter upon error. This has the effect that EINTR clears the
list of events, which are also automatically cleared from the set by
the system.

This is visible when using external checks where the SIGCHLD of the
leaving child causes a wakeup that ruins the event counter and causes
endless loops, apparently due to the queued inter-thread byte in the
pipe used to wake threads up that never gets removed in this case.
Note that extcheck would also deserve deeper investigation because it
can immediately re-trigger a check in such a case, which is not normal.

Removing the wiping of the nevlist variable fixes the problem.

This can be backported to all versions since it affects 2.0.

14 months agoCLEANUP: assorted typo fixes in the code and comments
Ilya Shipitsin [Sun, 14 Apr 2024 07:23:52 +0000 (09:23 +0200)] 
CLEANUP: assorted typo fixes in the code and comments

This is 41st iteration of typo fixes

14 months agoCI: reduce ASAN log redirection umbrella size
Ilya Shipitsin [Sun, 14 Apr 2024 07:23:51 +0000 (09:23 +0200)] 
CI: reduce ASAN log redirection umbrella size

previously ASAN_OPTIONS=log_path=asan.log was intended for VTest
execution only, it should not affect "haproxy -vv" and hsproxy
config smoke testing

14 months agoBUILD: xxhash: silence a build warning on Solaris + gcc-5.5
Willy Tarreau [Wed, 17 Apr 2024 07:41:30 +0000 (09:41 +0200)] 
BUILD: xxhash: silence a build warning on Solaris + gcc-5.5

Testing an undefined macro emits warnings due to -Wundef, and we have
exactly one such case in xxhash:

  include/import/xxhash.h:3390:42: warning: "__cplusplus" is not defined [-Wundef]
   #if ((defined(sun) || defined(__sun)) && __cplusplus) /* Solaris includes __STDC_VERSION__ with C++. Tested with GCC 5.5 */

Let's just prepend "defined(__cplusplus) &&" before __cplusplus to
resolve the problem. Upstream is still affected apparently.

14 months agoBUILD: cache: fix a build warning with gcc < 7
Willy Tarreau [Wed, 17 Apr 2024 07:36:33 +0000 (09:36 +0200)] 
BUILD: cache: fix a build warning with gcc < 7

Gcc before 7 does really not like direct operations on cast pointers
such as "((struct a*)b)->c += d;". It turns our that we have exactly
that construct in 3.0 since commit 5baa9ea168 ("MEDIUM: cache: Save
body size of cached objects and track it on delivery").

It's generally sufficient to use an intermediary variable such as :
"({ (struct a*) _ = b; _; })->c +=d;" but that's ugly. Fortunately
DISGUISE() implicitly does something very similar and works fine, so
let's use that.

No backport is needed.

14 months agoBUG/MEDIUM: stconn: Don't forward channel data if input data must be filtered
Christopher Faulet [Mon, 15 Apr 2024 17:09:01 +0000 (19:09 +0200)] 
BUG/MEDIUM: stconn: Don't forward channel data if input data must be filtered

Once data are received and placed in a channel buffer, if it is possible,
outgoing data are immediately forwarded. But we must take care to not do so
if there is also pending input data and a filter registered on the
channel. It is especially important for HTX streams because the HTX may be
altered, especially the extra field. And it is indeed an issue with the HTTP
compression filter and the H1 multiplexer. The wrong chunk size may be
announced leading to an internal error.

This patch should fix the issue #2530. It must be backported to all stable
versions.

14 months agoMINOR: peer: Restore previous peer flags value to ease debugging
Christopher Faulet [Tue, 16 Apr 2024 09:05:53 +0000 (11:05 +0200)] 
MINOR: peer: Restore previous peer flags value to ease debugging

The last fixes on the peers to improve the locking mechanism introduced new
peer flags and the value of some old flags was changed. This was done in the
commit 9b78e33837 ("MINOR: peers: Add 2 peer flags about the peer learn
status"). But, to ease the debugging of the peers team, old values are
restored.

This patch must be backported with the commit above.

14 months agoMEDIUM: peers: Only lock one peer at a time in the sync process function
Christopher Faulet [Fri, 22 Mar 2024 16:39:46 +0000 (17:39 +0100)] 
MEDIUM: peers: Only lock one peer at a time in the sync process function

Thanks to all previous changes, it is now possible to stop locking all peers
at once in the resync process function. Peer are locked one after the
other. Wen a peer is locked, another one may be locked when all peer sharing
the same shard must be updated. Otherwise, at anytime, at most one peer is
locked. This should significantly improve the situation.

This patch depends on the following patchs:

 * BUG/MAJOR: peers: Update peers section state from a thread-safe manner
 * BUG/MINOR: peers: Report a resync was explicitly requested from a thread-safe manner
 * MINOR: peers: Add functions to commit peer changes from the resync task
 * MINOR: peers: sligthly adapt part processing the stopping signal
 * MINOR: peers: Add flags to report the peer state to the resync task
 * MINOR: peers: Add 2 peer flags about the peer learn status
 * MINOR: peers: Split resync process function to separate running/stopping states

It may be good to backport it to 2.9. All the seris should fix the issue #2470.

14 months agoBUG/MAJOR: peers: Update peers section state from a thread-safe manner
Christopher Faulet [Fri, 22 Mar 2024 16:39:04 +0000 (17:39 +0100)] 
BUG/MAJOR: peers: Update peers section state from a thread-safe manner

It is the main part of this series. In the peer applet, only the peer flags
are updated. It is now the responsibility of the resync process function to
check changes on each peer to update the peers section state accordingly.

Concretly, changes on the connection state (accepted, connected, released or
renewed) are first reported at the peer level and then handled in
__process_peer_state() function.

In the same manner, when the learn status of a peer changes, the peers
section state is no longer updated immediately. The resync task is woken up
to deal with this changes.

Thanks to these changes, the peers should be now really thread-safe.

This patch relies on the following ones:

  * BUG/MINOR: peers: Report a resync was explicitly requested from a thread-safe manner
  * MINOR: peers: Add functions to commit peer changes from the resync task
  * MINOR: peers: sligthly adapt part processing the stopping signal
  * MINOR: peers: Add flags to report the peer state to the resync task
  * MINOR: peers: Add 2 peer flags about the peer learn status
  * MINOR: peers: Split resync process function to separate running/stopping states

No bug was reported about the thread-safety of peers. Only a performance
issue was encountered with a huge number of peers (> 50). So there is no
reason to backport all these patches further than 2.9.

14 months agoBUG/MINOR: peers: Report a resync was explicitly requested from a thread-safe manner
Christopher Faulet [Fri, 22 Mar 2024 15:27:13 +0000 (16:27 +0100)] 
BUG/MINOR: peers: Report a resync was explicitly requested from a thread-safe manner

Flags on the peers section state must be updated from a thread-safe manner.
It is not true today. With this patch we take care PEERS_F_RESYNC_REQUESTED
flag is only set by the resync task. To do so, a peer flag is used. This
flag is only set once and never removed. It is juste used for debugging
purpose. So it is enough to set it on a peer and be sure to report it on the
peers section when the sync task is executed.

This patch relies on previous ones:

 * MINOR: peers: Add functions to commit peer changes from the resync task
 * MINOR: peers: sligthly adapt part processing the stopping signal
 * MINOR: peers: Add flags to report the peer state to the resync task
 * MINOR: peers: Add 2 peer flags about the peer learn status
 * MINOR: peers: Split resync process function to separate running/stopping states

14 months agoMINOR: peers: Add functions to commit peer changes from the resync task
Christopher Faulet [Fri, 22 Mar 2024 15:23:40 +0000 (16:23 +0100)] 
MINOR: peers: Add functions to commit peer changes from the resync task

For now, nothing is done in these functions. It is only a patch to prepare
the huge part of the refactoring about the locking mechanism of the peers.
These functions will be responsible to check peers state and their learn
status to update the peers section flags accordingly.

14 months agoMINOR: peers: sligthly adapt part processing the stopping signal
Christopher Faulet [Fri, 22 Mar 2024 13:51:24 +0000 (14:51 +0100)] 
MINOR: peers: sligthly adapt part processing the stopping signal

The signal and the PEERS_F_DONOTSTOP flag are now handled in the loop on peers
to force sessions shutdown. We will need to loop on all peers to update their
state. It is easier this way.

14 months agoMINOR: peers: Add flags to report the peer state to the resync task
Christopher Faulet [Fri, 22 Mar 2024 13:34:21 +0000 (14:34 +0100)] 
MINOR: peers: Add flags to report the peer state to the resync task

As the previous patch, this patch is also part of the refactoring of peer
locking mechanisme. Here we add flags to represent a transitional state for
a peer. It will be the resync task responsibility to update the peers state
accordingly.

A peer may be in 4 transitional states:

  * accepted : a connection was accepted from a peer
  * connected: a connection to a peer was established
  * release  : a peer session was released
  * renewed  : a peer session was released because it was replaced by a new
               one. Concretly, this will be equivalent to released+accepted

If none of these flags is set, it means the transition, if any, was
processed by the resync task, or no transition happened.

14 months agoMINOR: peers: Add 2 peer flags about the peer learn status
Christopher Faulet [Fri, 22 Mar 2024 13:26:49 +0000 (14:26 +0100)] 
MINOR: peers: Add 2 peer flags about the peer learn status

PEER_F_LEARN_PROCESS and PEER_F_LEARN_FINISHED flags are added to help to
fix locking issue about peers. Indeed, a peer is able to update the peers
"section" state under its own lock. Because the resync task locks all peers
at once, there is no conflict at this level. But there is nothing to prevent
2 peers to update the peers state in same time. So it seems there is no real
issue here, but there is a theorical thread-safety issue here. And it means
the locking mechanism of the peers must be reviewed.

In this context, the 2 flags above will help to move all update of the peers
state in the scope of resync task. Each peer will be able to update its own
state and the resync task will be responsible to update the peers state
accordingly.

14 months agoMINOR: peers: Split resync process function to separate running/stopping states
Christopher Faulet [Fri, 22 Mar 2024 13:20:32 +0000 (14:20 +0100)] 
MINOR: peers: Split resync process function to separate running/stopping states

The function responsible to deal with resynchro between all peers is now split
in two subfunctions. The first one is used when HAProxy is running while the
other one is used in soft-stop case.

This patch is required to be able to refactor locking mechanism of the peers.

14 months agoBUG/MEDIUM: grpc: Fix several unaligned 32/64 bits accesses
Frederic Lecaille [Mon, 15 Apr 2024 07:57:37 +0000 (09:57 +0200)] 
BUG/MEDIUM: grpc: Fix several unaligned 32/64 bits accesses

There were several places in grpc and its dependency protobuf where unaligned
accesses were done. Read accesses to 32 (resp. 64) bits values should be performed
by read_u32() (resp. read_u64()).
Replace these unligned read accesses by correct calls to these functions.
Same fixes for doubles and floats.

Such unaligned read accesses could lead to crashes with bus errors on CPU
archictectures which do not fix them at run time.

This patch depends on this previous commit:
    861199fa71 MINOR: net_helper: Add support for floats/doubles.

Must be backported as far as 2.6.

14 months agoMINOR: net_helper: Add support for floats/doubles.
Frederic Lecaille [Mon, 15 Apr 2024 07:52:25 +0000 (09:52 +0200)] 
MINOR: net_helper: Add support for floats/doubles.

Implement (read|write)_flt() (resp. (read|write)_dbl()) to read/write floats
(resp. read/write doubles) from/to an unaligned buffer.

14 months agoMINOR: ssl: 'key-base' allows to load a 'key' from a specific path
William Lallemand [Mon, 15 Apr 2024 12:33:24 +0000 (14:33 +0200)] 
MINOR: ssl: 'key-base' allows to load a 'key' from a specific path

The global 'key-base' keyword allows to read the 'key' parameter of a
crt-store load line using a path prefix.

This is the equivalent of the 'crt-base' keyword but for 'key'.

It only applies on crt-store.

14 months agoMINOR: ssl: supports crt-base in crt-store
William Lallemand [Mon, 15 Apr 2024 12:01:11 +0000 (14:01 +0200)] 
MINOR: ssl: supports crt-base in crt-store

Add crt-base support for "crt-store". It will be used by 'crt', 'ocsp',
'issuer', 'sctl' load line parameter.

In order to keep compatibility with previous configurations and scripts
for the CLI, a crt-store load line will save its ckch_store using the
absolute crt path with the crt-base as the ckch tree key. This way, a
`show ssl cert` on the CLI will always have the completed path.

14 months agoCLEANUP: ssl: remove dead code in cfg_parse_crtstore()
William Lallemand [Mon, 15 Apr 2024 07:04:37 +0000 (09:04 +0200)] 
CLEANUP: ssl: remove dead code in cfg_parse_crtstore()

Remove dead code reported in #2531.

14 months agoMINOR: ring: always check that the old ring fits in the new one in ring_dup()
Willy Tarreau [Mon, 15 Apr 2024 06:31:01 +0000 (08:31 +0200)] 
MINOR: ring: always check that the old ring fits in the new one in ring_dup()

Let's add a BUG_ON() to make sure we don't accidentally shrink a buffer.

14 months agoBUG/MAJOR: ring: use the correct size to reallocate startup_logs
Willy Tarreau [Mon, 15 Apr 2024 06:26:41 +0000 (08:26 +0200)] 
BUG/MAJOR: ring: use the correct size to reallocate startup_logs

In 3.0-dev, with commit 7c9ce715c9 ("MINOR: ring: make callers use
ring_data() and ring_size(), not ring->buf"), we made startup_logs_dup()
use ring_size() to get the old ring size and pass it to ring_new() to
create a new ring. But due to the ambiguity of the allocate vs usable
size, this resulted in slightly shrinking the buffer compared to the
previous one, occasionally causing crashes if the first one was already
full of warnings, as seen in GH issue #2529. We need to use the allocated
size instead, thanks to the function brought by previous commit.

No backport is needed, this only affects 3.0-dev. Thanks to @felipewd
for the detailed report that allowed to spot the problem.

14 months agoMINOR: ring: clarify the usage of ring_size() and add ring_allocated_size()
Willy Tarreau [Mon, 15 Apr 2024 06:25:03 +0000 (08:25 +0200)] 
MINOR: ring: clarify the usage of ring_size() and add ring_allocated_size()

There's currently an abiguity around ring_size(), it's said to return
the allocated size but returns the usable size. We can't change it as
it's used everywhere in the code like this. Let's fix the comment and
add ring_allocated_size() instead for anything related to allocation.

14 months agoCI: revert kernel addr randomization introduced in 3a0fc864
Ilya Shipitsin [Sat, 6 Apr 2024 13:37:34 +0000 (15:37 +0200)] 
CI: revert kernel addr randomization introduced in 3a0fc864

It has been resolved on image generation side:
https://github.com/actions/runner-images/issues/9491

It is no harm to keep it on our side as well, but we can drop it.

14 months agoDOC: management: fix typos
Andrey Lebedev [Fri, 12 Apr 2024 09:47:07 +0000 (11:47 +0200)] 
DOC: management: fix typos

[WT: some of them seem to be relevant to older versions, so it might
 be worth backporting the relevant parts.]

14 months agoBUG/MINOR: lru: fix the standalone test case for invalid revision
Willy Tarreau [Sun, 7 Apr 2024 16:27:06 +0000 (18:27 +0200)] 
BUG/MINOR: lru: fix the standalone test case for invalid revision

In 2.6, a build issue for LRU in standalone test mode was addressed by
commit bf9c07fd9 ("BUILD/DEBUG: lru: update the standalone code to
support the revision"), but using revision 1 while looking up rev 0
results in 100% misses. Let's fix this and commit with revision 0 as
well.

No backport is needed, this only happens when hacking on the code.

15 months agoMINOR: proto_quic: add proto name in alert
Valentine Krasnobaeva [Wed, 10 Apr 2024 13:18:25 +0000 (15:18 +0200)] 
MINOR: proto_quic: add proto name in alert

In quic_alloc_dghdlrs() add proto name in the last alert. This helps to
identify potential problem immediately and makes log messages more uniform.

15 months agoMINOR: listener/protocol: add proto name in alerts
Valentine Krasnobaeva [Wed, 10 Apr 2024 12:18:47 +0000 (14:18 +0200)] 
MINOR: listener/protocol: add proto name in alerts

Frontend and listen sections allow unlimited number of bind statements, it is
often, when there is a bind statement per supported protocol, like below:

listen test
  mode http
  bind quic4@0.0.0.0:443 name quic ssl crt ...
  bind 0.0.0.0:443 name https ssl alpn http/1.1,h2 crt ...
  bind 0.0.0.0:8080 ...
  ...

It seems useful to show corresponded protocol name in alerts and warnings,
when problem occures with port binding, connection resuming or sharding. This
helps to figure out immediately, which bind statement has a wrong setting or
which protocol module is the root cause of the issue.

15 months agoDEBUG: pools: report the data around the offending area in case of mismatch
Willy Tarreau [Fri, 12 Apr 2024 15:54:51 +0000 (17:54 +0200)] 
DEBUG: pools: report the data around the offending area in case of mismatch

When the integrity check fails, it's useful to get a dump of the area
around the first faulty byte. That's what this patch does. For example
it now shows this before reporting info about the tag itself:

  Contents around first corrupted address relative to pool item:.
  Contents around address 0xe4febc0792c0+40=0xe4febc0792e8:
    0xe4febc0792c8 [80 75 56 d8 fe e4 00 00] [.uV.....]
    0xe4febc0792d0 [a0 f7 23 a4 fe e4 00 00] [..#.....]
    0xe4febc0792d8 [90 75 56 d8 fe e4 00 00] [.uV.....]
    0xe4febc0792e0 [d9 93 fb ff fd ff ff ff] [........]
    0xe4febc0792e8 [d9 93 fb ff ff ff ff ff] [........]
    0xe4febc0792f0 [d9 93 fb ff ff ff ff ff] [........]
    0xe4febc0792f8 [d9 93 fb ff ff ff ff ff] [........]
    0xe4febc079300 [d9 93 fb ff ff ff ff ff] [........]

This may be backported to 2.9 and maybe even 2.8 as it does help spot
the cause of the memory corruption.

15 months agoREORG: pool: move the area dump with symbol resolution to tools.c
Willy Tarreau [Fri, 12 Apr 2024 14:18:34 +0000 (16:18 +0200)] 
REORG: pool: move the area dump with symbol resolution to tools.c

This function is particularly useful to dump unknown areas watching
for opportunistic symbols, so let's move it to tools.c so that we can
reuse it a little bit more.

15 months agoDEBUG: pool: improve decoding of corrupted pools
Willy Tarreau [Fri, 12 Apr 2024 13:56:18 +0000 (15:56 +0200)] 
DEBUG: pool: improve decoding of corrupted pools

When a corruption was detected in an object, it's often said that the
tag doesn't match the pool, but it should also check if it matches the
location of an earlier pool_free() call, which happens when -dMcaller
is used. That's what we're doing now.

15 months agoBUG/MAJOR: stick-tables: fix race with peers in entry expiration
Willy Tarreau [Fri, 12 Apr 2024 15:31:00 +0000 (17:31 +0200)] 
BUG/MAJOR: stick-tables: fix race with peers in entry expiration

In 2.9 with commit 7968fe3889 ("MEDIUM: stick-table: change the ref_cnt
atomically") we significantly relaxed the stick-tables locking when
dealing with peers by adjusting the ref_cnt atomically and moving it
out of the lock.

However it opened a tiny window that became problematic in 3.0-dev7
when the table's contention was lowered by commit 1a088da7c2 ("MAJOR:
stktable: split the keys across multiple shards to reduce contention").

What happens is that some peers may access the entry for reading at
the moment it's about to expire, and while the read accesses to push
the data remain unnoticed (possibly that from time to time we push
crap), but the releasing of the refcount causes a new write that may
damage anything else. The scenario is the following:

  process_table_expire()               peer_send_teachmsgs()

                                       RDLOCK(&updt_lock);
     tick_is_expired() != 0

     ebmb_delete(ts->key);

     if (ts->upd.node.leaf_p) {
                                       HA_ATOMIC_INC(&ts->ref_cnt);
                                       RDUNLOCK(&updt_lock);
          WRLOCK(&updt_lock);
          eb32_delete(&ts->upd);
     }
     __stksess_free(t, ts);
                                       peer_send_updatemsg(ts);
                                       RDLOCK(&updt_lock);
                                       HA_ATOMIC_DEC(&ts->ref_cnt);

Here it's clear that the bottom part of peer_send_teachmsgs() believes
to be protected but may act on freed data.

This is more visible when enabling -dMtag,no-merge,integrity because
the ATOMIC_DEC(&ref_cnt) decrements one byte in the area, that makes
the eviction check fail while the tag has the address of the left
__stksess_free(), proving a completed pool_free() before the decrement,
and the anomaly there is pretty visible in the crash dump. Changing
INC()/DEC() with ADD(2)/DEC(2) shows that the byte is now off by two,
confirming that the operation happened there.

The solution is not very hard, it consists in checking for the ref_cnt
on the left after grabbing the lock, and doing both before deleting the
element, so that we have the guarantee that either the peer will not
take it or that it has already started taking it.

This was proven to be sufficient, as instead of crashing after 3s of
injection with 4 peers, 16 threads and 130k RPS, it survived for 15mn.

In order to stress the setup, a config involving 4+ peers, tracking
HTTP request with randoms and applying a bwlim-out filter with a
random key, with a client made of 160 h2 conns downloading 10 streams
of 4MB objects in parallel managed to trigger it within a few seconds:

  frontend ft
    http-request track-sc0 rand(100000) table tbl
    filter bwlim-out lim-out limit 2047m key rand(100000000),ipmask(32) min-size 1 table tbl
    http-request set-bandwidth-limit lim-out
    use_backend bk

  backend bk
    server s1 198.18.0.30:8000
    server s2 198.18.0.34:8000

  backend tbl
        stick-table type ip size 1000k expire 1s store http_req_cnt,bytes_in_rate(1s),bytes_out_rate(1s) peers peers

This seems to be very dependent on the timing and setup though.

This will need to be backported to 2.9. This part of the code was
reindented with shards but the block should remain mostly unchanged.
The logic to apply is the same.

15 months agoBUG/MEDIUM: peers/trace: fix crash when listing event types
Willy Tarreau [Fri, 12 Apr 2024 10:01:31 +0000 (12:01 +0200)] 
BUG/MEDIUM: peers/trace: fix crash when listing event types

Sending "trace peers event" on the CLI crashes because the event list
in the peers is not finished. This was introduced in 2.4 by commit
d865935f32 ("MINOR: peers: Add traces to peer_treat_updatemsg().")
so this must be backported to 2.4.

15 months agoCLEANUP: stick-tables: always respect the to_batch limit when trashing
Willy Tarreau [Fri, 12 Apr 2024 08:02:26 +0000 (10:02 +0200)] 
CLEANUP: stick-tables: always respect the to_batch limit when trashing

When adding the shards support to tables with commit 1a088da7c ("MAJOR:
stktable: split the keys across multiple shards to reduce contention"),
the condition to stop eliminating entries based on the batch size being
reached is based on a pre-decrement of the max_search counter, but now
it goes back into the outer loop which doesn't check it, so next time
it does it when entering the next shard, it will become even more
negative and will properly stop, but at first glance it looks like an
int overflow (which it is not). Let's make sure the outer loop stops
on this condition so that we don't continue searching when the limit
is reached.

15 months agoBUG/MEDIUM: stick-tables: fix the task's next expiration date
Willy Tarreau [Fri, 12 Apr 2024 07:57:32 +0000 (09:57 +0200)] 
BUG/MEDIUM: stick-tables: fix the task's next expiration date

While changing the stick-table indexing that led to commit 1a088da7c
("MAJOR: stktable: split the keys across multiple shards to reduce
contention"), I met a problem with the task's expiration date being
incorrectly updated, I fixed it and apparently I committed the wrong
version :-/

The effect is that the task's date is only correctly reset if the
table is empty, otherwise the task wakes up again and is queued at
the previous date, eating 100% CPU. The tick_isfirst() must not be
used when storing the last result.

No backport is needed as this was only merged in 3.0-dev7.

15 months agoMINOR: ssl/crtlist: alloc ssl_conf only when a valid keyword is found
William Lallemand [Wed, 10 Apr 2024 17:05:15 +0000 (19:05 +0200)] 
MINOR: ssl/crtlist: alloc ssl_conf only when a valid keyword is found

crt-list will be enhanced with ckch_conf keywords, however these keywords
does not fill the 'ssl_conf' structure. So we don't need to allocate the
ssl_conf for every options between [ ] but only when we found a relevant
one.

15 months agoMINOR: ssl: rename ckchs_load_cert_file to new_ckch_store_load_files_path
William Lallemand [Thu, 11 Apr 2024 13:55:16 +0000 (15:55 +0200)] 
MINOR: ssl: rename ckchs_load_cert_file to new_ckch_store_load_files_path

Remove the ambiguous "ckchs" name and reflect the fact that its loaded
from a path.

15 months agoREGTESTS: ssl: test simple case of crt-store
William Lallemand [Mon, 8 Apr 2024 15:52:08 +0000 (17:52 +0200)] 
REGTESTS: ssl: test simple case of crt-store

Test the crt-store loading with some basic cases.

15 months agoDOC: configuration: Add 3.12 Certificate Storage
William Lallemand [Tue, 13 Feb 2024 15:57:34 +0000 (16:57 +0100)] 
DOC: configuration: Add 3.12 Certificate Storage

The 3.12. Certificate Storage section, explain how to configure a
"crt-store" section.

15 months agoMINOR: ssl: add the section parser for 'crt-store'
William Lallemand [Fri, 9 Feb 2024 14:12:15 +0000 (15:12 +0100)] 
MINOR: ssl: add the section parser for 'crt-store'

'crt-store' is a new section useful to define the struct ckch_store.

The "load" keyword in the "crt-store" section allows to define which
files you want to load for a specific certificate definition.

Ex:
    crt-store
        load crt "site1.crt" key "site1.key"
        load crt "site2.crt" key "site2.key"

    frontend in
        bind *:443 ssl crt "site1.crt" crt "site2.crt"

This is part of the certificate loading which was discussed in #785.

15 months agoBUG/MEDIUM: cache/stats: Handle inbuf allocation failure in the I/O handler
Christopher Faulet [Fri, 12 Apr 2024 12:36:47 +0000 (14:36 +0200)] 
BUG/MEDIUM: cache/stats: Handle inbuf allocation failure in the I/O handler

When cache and stats applets were changed to use their own buffers, a change
was also performed to no longer access the stream from the I/O
handller. Among other things, the HTTP start-line of the request is now
retrieved to get the method. But, when these changes were brought, the inbuf
buffer allocation failures were not handled.

It is of course not so common. But if this happens, a crash may be
experienced. To fix the issue, we now check for inbuf allocation failures
before accessing it.

No backported needed.

15 months agoBUG/MINOR: server: fix slowstart behavior
Damien Claisse [Tue, 9 Apr 2024 15:37:07 +0000 (15:37 +0000)] 
BUG/MINOR: server: fix slowstart behavior

We observed that a dynamic server which health check is down for longer
than slowstart delay at startup doesn't trigger the warmup phase, it
receives full traffic immediately. This has been confirmed by checking
haproxy UI, weight is immediately the full one (e.g. 75/75), without any
throttle applied. Further tests showed that it was similar if it was in
maintenance, and even when entering a down or maintenance state after
being up.
Another issue is that if the server is down for less time than
slowstart, when it comes back up, it briefly has a much higher weight
than expected for a slowstart.

An easy way to reproduce is to do the following:
- Add a server with e.g. a 20s slowstart and a weight of 10 in config
  file
- Put it in maintenance using CLI (set server be1/srv1 state maint)
- Wait more than 20s, enable it again (set server be1/srv1 state ready)
- Observe UI, weight will show 10/10 immediately.
If server was down for less than 20s, you'd briefly see a weight and
throttle value that is inconsistent, e.g. 50% throttle value and a
weight of 5 if server comes back up after 10s before going back to
6% after a second or two.

Code analysis shows that the logic in server_recalc_eweight stops the
warmup task by setting server's next state to SRV_ST_RUNNING if it
didn't change state for longer than the slowstart duration, regardless
of its current state. As a consequence, a server being down or disabled
for longer than the slowstart duration will never enter the warmup phase
when it will be up again.

Regarding the weight when server comes back up, issue is that even if
the server is down, we still compute its next weight as if it was up,
hence when it comes back up, it can briefly have a much higher weight
than expected during slowstart, until the warmup task is called again
after last_change is updated.

This patch aims to fix both issues.

15 months agoDOC: install: clarify the build process by splitting it into subsections
Willy Tarreau [Thu, 11 Apr 2024 15:59:19 +0000 (17:59 +0200)] 
DOC: install: clarify the build process by splitting it into subsections

The doc about the build process has grown to a point where it was painful
to read when searching a specific element. This commit cuts it into a few
sub-categories for ease of searching, and it also adds a summary of the
most commonly used makefile variables, their usage and default settings.

15 months agoCLEANUP: makefile: make the output of the "opts" target more readable
Willy Tarreau [Thu, 11 Apr 2024 15:20:42 +0000 (17:20 +0200)] 
CLEANUP: makefile: make the output of the "opts" target more readable

"make opts" is nice because it shows all options being used, but it
does so in a copy-pastable way that aggregates everything on a single
line, rendering very poorly and making it hard to spot the relevant
variables.

Let's break lines and append a trailing backslash to them instead. This
gives something much more readable which remains copy-pastable. Options
can be inspected and more easily replicated. It was also verified that
copy-pasting the whole block after "make" does continue to work like
before and produces the same output.

15 months agoBUILD: makefile: also drop DEBUG_CFLAGS
Willy Tarreau [Wed, 10 Apr 2024 16:21:18 +0000 (18:21 +0200)] 
BUILD: makefile: also drop DEBUG_CFLAGS

This one is often used as a gateway to inject regular CFLAGS, even though
not designed for this. It's now ignored, but any attempt at setting it
reports a warning suggesting to use CFLAGS or ARCH_FLAGS instead.

15 months agoBUILD: makefile: do not pass warnings to VERBOSE_CFLAGS
Willy Tarreau [Thu, 11 Apr 2024 13:51:38 +0000 (15:51 +0200)] 
BUILD: makefile: do not pass warnings to VERBOSE_CFLAGS

The VERBOSE_CFLAGS variable is used to report the CFLAGS used in the
output of "haproxy -vv". It currently contains all -Wxxx and -Wno-xxx
because there was no other possibility till now, but these warnings
are highly specific to the compiler version in use, are automatically
detected and do not bring value being presented here. Worse, by
encouraging users to copy-paste them, they can end up with warnings
that are not relevant to their build environment.

In addition, their presence there doesn't give indication of whether
or not they triggered, so they cannot vouch for the output code quality.

Better just not report them there. However, as part of VERBOSE_CFLAGS
they were also used to detect whether or not to rebuild, via build_opts,
so they still have to be explicitly mentioned there if we want to make
sure that changing warning options triggers a rebuild to see their
effect.

Now we can have more useful outputs like this one which indicate precisely
what to use to safely rebuild the executable:

  Build options :
    TARGET  = linux-glibc
    CC      = gcc
    CFLAGS  = -O2 -g -fwrapv
    OPTIONS = USE_OPENSSL=1 USE_LUA=1 USE_ZLIB= USE_SLZ=1 USE_DEVICEATLAS=1 USE_51DEGREES=1 USE_WURFL=1 USE_QUIC=1 USE_PROMEX=1 USE_PCRE=1
    DEBUG   = -DDEBUG_DONT_SHARE_POOLS -DDEBUG_MEMORY_POOLS -DDEBUG_EXPR -DDEBUG_STRICT=2 -DDEBUG_DEV -DDEBUG_MEM_STATS -DDEBUG_POOL_TRACING

15 months agoBUILD: makefile: rename SPEC_CFLAGS to NOWARN_CFLAGS
Willy Tarreau [Thu, 11 Apr 2024 13:46:54 +0000 (15:46 +0200)] 
BUILD: makefile: rename SPEC_CFLAGS to NOWARN_CFLAGS

Now that the variable only serves to disable warnings, let's give it a
more suitable name and document its (rare) usage for package maintainers.

15 months agoBUILD: makefile: split WARN_CFLAGS from SPEC_CFLAGS
Willy Tarreau [Thu, 11 Apr 2024 13:29:42 +0000 (15:29 +0200)] 
BUILD: makefile: split WARN_CFLAGS from SPEC_CFLAGS

It's currently not possible to only set some -Wno... without breaking
the -W... and conversely. Let's split both sets apart so that it's now
possible to set -W... alone in WARN_CFLAGS to enable only some warnings,
and pass the -Wno... in SPEC_CFLAGS without losing the enabled ones.

15 months agoBUILD: makefile: extract -Werror/-Wfatal-errors from automatic CFLAGS
Willy Tarreau [Thu, 11 Apr 2024 13:20:46 +0000 (15:20 +0200)] 
BUILD: makefile: extract -Werror/-Wfatal-errors from automatic CFLAGS

The compiler-specific CFLAGS that are automatically detected (SPEC_CFLAGS)
are currently the ones affected by ERR and FAILFAST. Not only this makes
these options useless as soon as SPEC_CFLAGS is forced, but it also means
that any change to them causes a rebuild, so disabling FAILFAST or
enabling ERR to get more info on a faulty object causes a full rebuild
of all others. Let's just move them to ERROR_CFLAGS that only contains
these two.  It's not documented outside of the makefile because it's not
supposed to be touched.

15 months agoBUILD: makefile: add FAILFAST to select the -Wfatal-errors behavior
Willy Tarreau [Thu, 11 Apr 2024 13:08:14 +0000 (15:08 +0200)] 
BUILD: makefile: add FAILFAST to select the -Wfatal-errors behavior

-Wfatal-errors is set by default and is not supported on older compilers.
Since it's part of all the automatically detected flags, it's painful to
remove when needed. Also it's a matter of taste, some developers might
prefer to get a long list of all errors at once, others prefer that the
build stops immediately after the root cause.

The default is now back to no -Wfatal-errors, and when FAILFAST is set to
any non-empty non-zero value, -Wfatal-errors is added:

 $ make TARGET=linux-glibc USE_OPENSSL=0 USE_QUIC=1 FAILFAST=0 2>&1 | wc
    132     536    6111

 $ make TARGET=linux-glibc USE_OPENSSL=0 USE_QUIC=1 FAILFAST=1 2>&1 | wc
      8      39     362

15 months agoBUILD: makefile: make the ERR variable also support 0
Willy Tarreau [Thu, 11 Apr 2024 13:03:12 +0000 (15:03 +0200)] 
BUILD: makefile: make the ERR variable also support 0

It's among the options that change a lot on the developer's side and it's
tempting to change from ERR=1 to ERR=0 on the make command line by reusing
the history, except it doesn't work. Let's explictily permit ERR=0 to
disable -Werror like ERR= does.