]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 years agoBUG/MEDIUM: wdt: don't trigger the watchdog when p is unitialized
William Lallemand [Fri, 13 May 2022 09:03:39 +0000 (11:03 +0200)] 
BUG/MEDIUM: wdt: don't trigger the watchdog when p is unitialized

In wdt_handler(), does not try to trigger the watchdog if the
prev_cpu_time wasn't initialized.

This prevents an unexpected trigger of the watchdog when it wasn't
initialized yet. This case could happen in the master just after loading
the configuration. This would show a trace where the <diff> value is equal
to the <now> value in the trace, and the <poll> value would be 0.

For example:

    Thread 1 is about to kill the process.
    *>Thread 1 : id=0x0 act=1 glob=1 wq=0 rq=0 tl=0 tlsz=0 rqsz=0
                  stuck=1 prof=0 harmless=0 wantrdv=0
                  cpu_ns: poll=0 now=6005541706 diff=6005541706
                  curr_task=0

Thanks to Christian Ruppert for repporting the problem.

Could be backported in every stable versions.

3 years agoDOC/MINOR: fix typos in the lua-api document
Boyang Li [Tue, 10 May 2022 18:11:00 +0000 (18:11 +0000)] 
DOC/MINOR: fix typos in the lua-api document

Fixes a few typos in the Lua API document.

3 years agoBUG/MEDIUM: lua: fix argument handling in data removal functions
Boyang Li [Tue, 10 May 2022 17:47:23 +0000 (17:47 +0000)] 
BUG/MEDIUM: lua: fix argument handling in data removal functions

Lua API Channel.remove() and HTTPMessage.remove() expects 1 to 3
arguments (counting the manipulated object), with offset and length
being the 2nd and 3rd argument, respectively.

hlua_{channel,http_msg}_del_data() incorrectly gets the 3rd argument as
offset, and 4th (nonexistent) as length. hlua_http_msg_del_data() also
improperly checks arguments. This patch fixes argument handling in both.

Must be backported to 2.5.

3 years agoMINOR: ncbuf: write unit tests
Amaury Denoyelle [Wed, 4 May 2022 14:51:19 +0000 (16:51 +0200)] 
MINOR: ncbuf: write unit tests

Implement a series of unit test to validate ncbuf. This is written with
a main function which can be compiled independently using the following
command-line :
 $ gcc -DSTANDALONE -lasan -I./include -o ncbuf src/ncbuf.c

The first part tests is used to test ncb_add()/ncb_advance(). After each
call a loop is done on the buffer blocks which should ensure that the
gap infos are correct.

The second part generates random offsets and insert them until the
buffer is full. The buffer is then resetted and all random offsets are
re-inserted in the reverse order : the buffer should be full once again.

The generated binary takes arguments to change the tests execution.
 "usage: ncbuf [-r] [-s bufsize] [-h bufhead] [-p <delay_msec>]"

3 years agoMINOR: ncbuf: implement advance
Amaury Denoyelle [Wed, 4 May 2022 14:47:09 +0000 (16:47 +0200)] 
MINOR: ncbuf: implement advance

A new function ncb_advance() is implemented. This is used to advance the
buffer head pointer. This will consume the front data while forming a
new gap at the end for future data.

On success NCB_RET_OK is returned. The operation can be rejected if a
too small new gap is formed in front of the buffer.

3 years agoMINOR: ncbuf: define various insertion modes
Amaury Denoyelle [Mon, 9 May 2022 09:59:15 +0000 (11:59 +0200)] 
MINOR: ncbuf: define various insertion modes

Define three different ways to proceed insertion. This configures how
overlapping data is treated.
- NCB_ADD_PRESERVE : in this mode, old data are kept during insertion.
- NCB_ADD_OVERWRT : new data will overwrite old ones.
- NCB_ADD_COMPARE : this mode adds a new test in check stage. The
  overlapping old and new data must be identical or else the insertion
  is not conducted. An error NCB_RET_DATA_REJ is used in this case.

The mode is specified with a new argument to ncb_add() function.

3 years agoMINOR: ncbuf: implement insertion
Amaury Denoyelle [Mon, 9 May 2022 07:43:11 +0000 (09:43 +0200)] 
MINOR: ncbuf: implement insertion

Implement a new function ncb_add() to insert data in ncbuf. This
operation is conducted in two stages. First, a simulation will be run to
ensure that insertion can be proceeded. If a gap is formed, either
before or after the new data, it must be big enough to store its header,
or else the insertion is aborted.

After this check stage, the insertion is conducted block by block with
the function pair ncb_fill_data_blk()/ncb_fill_gap_blk().

A new type ncb_ret is used as a return value. For the moment, only
success or gap-size error is used. It is planned to add new error types
in the future when insertion will be extended.

3 years agoMINOR: ncbuf: optimize storage for the last gap
Amaury Denoyelle [Wed, 4 May 2022 14:16:39 +0000 (16:16 +0200)] 
MINOR: ncbuf: optimize storage for the last gap

Relax the constraint for gap storage when this is the last block.
ncb_blk API functions will consider that if a gap is stored near the end
of the buffer, without the space to store its header, the gap will cover
entirely the buffer end.

For these special cases, the gap size/data size are not write/read
inside the gap to prevent an overflow. Such a gap is designed in
functions as "reduced gap" and will be flagged with the value
NCB_BK_F_FIN.

This should reduce the rejection on future add operation when receiving
data in-order. Without reduced gap handling, an insertion would be
rejected if it covers only partially the last buffer bytes, which can be
a very common case.

3 years agoMINOR: ncbuf: complete API and define block interal abstraction
Amaury Denoyelle [Mon, 9 May 2022 07:38:45 +0000 (09:38 +0200)] 
MINOR: ncbuf: complete API and define block interal abstraction

Implement two new functions to report the total data stored accross the
whole buffer and the data stored at a specific offset until the next gap
or the buffer end.

To facilitate implementation of these new functions and also future
add/delete operations, a new abstraction is introduced : ncb_blk. This
structure represents a block of either data or gap in the buffer. It
simplifies operation when moving forward in the buffer. The first buffer
block can be retrieved via ncb_blk_first(buf). The block at a specific
offset is accessed via ncb_blk_find(buf, off).

This abstraction is purely used in functions but not stored in the ncbuf
structure per-se. This is necessary to keep the minimal memory
footprint.

3 years agoMINOR: ncbuf: define non-contiguous buffer
Amaury Denoyelle [Mon, 9 May 2022 07:37:27 +0000 (09:37 +0200)] 
MINOR: ncbuf: define non-contiguous buffer

Define the new type ncbuf. It can be used as a buffer with
non-contiguous data and wrapping support.

To reduce as much as possible the memory footprint, size of data and
gaps are stored in the gaps themselves. This put some limitation on the
buffer usage. A reserved space is present just before the head to store
the size of the first data block. Also, add and delete operations will
be constrained to ensure minimal gap sizes are preserved.

The sizes stored in the gaps are represented by a custom type named
ncb_sz_t. This type is a typedef to easily change it : this has a
direct impact on the maximum buffer size (MAX(ncb_sz_t) - sizeof(ncb_sz_t))
and the minimal gap sizes (sizeof(ncb_sz_t) * 2)).
Currently, it is set to uint32_t.

3 years agoCLEANUP: quic_tls: QUIC_TLS_IV_LEN defined two times
Frédéric Lécaille [Wed, 11 May 2022 08:56:07 +0000 (10:56 +0200)] 
CLEANUP: quic_tls: QUIC_TLS_IV_LEN defined two times

Hopefully with the same value!

3 years agoCLEANUP: quic: Useless use of pointer for quic_hkdf_extract()
Frédéric Lécaille [Tue, 10 May 2022 16:40:19 +0000 (18:40 +0200)] 
CLEANUP: quic: Useless use of pointer for quic_hkdf_extract()

There is no need to use a pointer to the output buffer length.

3 years agoCLEANUP: quic: wrong use of eb*entry() macro
Frédéric Lécaille [Tue, 10 May 2022 13:15:24 +0000 (15:15 +0200)] 
CLEANUP: quic: wrong use of eb*entry() macro

This wrong use has no consequence because the ->node member fields of
eb*node structs are the first.

3 years agoMINOR: quic: Short packets always embed a trailing AEAD TAG
Frédéric Lécaille [Mon, 9 May 2022 16:08:13 +0000 (18:08 +0200)] 
MINOR: quic: Short packets always embed a trailing AEAD TAG

We must drop as soon as possible too small 1-RTT packets to be valid QUIC
packets to avoid replying with stateless reset packets.

3 years agoMINOR: quic: Send stateless reset tokens
Frédéric Lécaille [Mon, 9 May 2022 14:30:55 +0000 (16:30 +0200)] 
MINOR: quic: Send stateless reset tokens

Add send_stateless_reset() to send a stateless reset packet. It prepares
a packet to build a 1-RTT packet with quic_stateless_reset_token_cpy()
to copy a stateless reset token derived from the cluster secret with
the destination connection ID received as salt.
Also add QUIC_EV_STATELESS_RST new trace event to at least to have a trace
of the connection which are reset.

3 years agoMINOR: quic: Stateless reset token copy to transport parameters
Frédéric Lécaille [Mon, 9 May 2022 14:22:29 +0000 (16:22 +0200)] 
MINOR: quic: Stateless reset token copy to transport parameters

A server may send the stateless reset token associated to the current
connection from its transport parameters. So, let's copy it from
qc_lstnt_params_init().

3 years agoMINOR: qc_new_conn() rework for stateless reset
Frédéric Lécaille [Mon, 9 May 2022 13:42:26 +0000 (15:42 +0200)] 
MINOR: qc_new_conn() rework for stateless reset

The stateless reset token of a connection is generated from qc_new_conn() when
allocating the first connection ID. A QUIC server can copy it into its transport
parameters to allow the peer to reset the associated connection.
This latter is not easily reachable after having returned from qc_new_conn().
We want to be able to initialize the transport parameters from this function which
has an access to all the information to do so.

Extract the code used to initialize the transport parameters from qc_lstnr_pkt_rcv()
and make it callable from qc_new_conn(). qc_lstnr_params_init() is implemented
to accomplish this task for a haproxy listener.
Modify qc_new_conn() to reduce its the number of parameters.
The source address coming from Initial packets is also copied from qc_new_conn().

3 years agoMINOR: quic: Initialize stateless reset tokens with HKDF secrets
Frédéric Lécaille [Fri, 6 May 2022 13:07:20 +0000 (15:07 +0200)] 
MINOR: quic: Initialize stateless reset tokens with HKDF secrets

Add quic_stateless_reset_token_init() wrapper function around
quic_hkdf_extract_and_expand() function to derive the stateless reset tokens
attached to the connection IDs from "cluster-secret" configuration setting
and call it each time we instantiate a QUIC connection ID.

3 years agoMINOR: quic: new_quic_cid() code moving
Frédéric Lécaille [Fri, 6 May 2022 12:18:53 +0000 (14:18 +0200)] 
MINOR: quic: new_quic_cid() code moving

This function will have to call another one from quic_tls.[ch] soon.
As we do not want to include quic_tls.h from xprt_quic.h because
quic_tls.h already includes xprt_quic.h, let's moving it into
xprt_quic.c.

3 years agoMINOR: quic-tls: Add quic_hkdf_extract_and_expand() for HKDF
Frédéric Lécaille [Fri, 6 May 2022 07:54:48 +0000 (09:54 +0200)] 
MINOR: quic-tls: Add quic_hkdf_extract_and_expand() for HKDF

This is a wrapper function around OpenSSL HKDF API functions to
use the "extract-then-expand" HKDF mode as defined by rfc5869.
This function will be used to derived stateless reset tokens
from secrets ("cluster-secret" conf. keyword) and CIDs (as salts).

3 years agoMINOR: config: Add "cluster-secret" new global keyword
Frédéric Lécaille [Fri, 6 May 2022 06:53:16 +0000 (08:53 +0200)] 
MINOR: config: Add "cluster-secret" new global keyword

It could be usefull to set a ASCII secret which could be used for different
usages. For instance, it will be used to derive QUIC stateless reset tokens.

3 years agoMINOR: quic: Add correct ack delay values to ACK frames
Frédéric Lécaille [Thu, 5 May 2022 10:04:28 +0000 (12:04 +0200)] 
MINOR: quic: Add correct ack delay values to ACK frames

A ->time_received new member is added to quic_rx_packet to store the time the
packet are received. ->largest_time_received is added the the packet number
space structure to store this timestamp for the packet with a new largest
packet number to be acknowledged. QUIC_FL_PKTNS_NEW_LARGEST_PN new flag is
added to mark a packet number space as having to acknowledged a packet wih a
new largest packet number. In this case, the packet number space ack delay
must be recalculated.
Add quic_compute_ack_delay_us() function to compute the ack delay from the value
of the time a packet was received. Used only when a packet with a new largest
packet number.

3 years agoMINOR: quic: Congestion controller event trace fix (loss)
Frédéric Lécaille [Wed, 4 May 2022 13:24:50 +0000 (15:24 +0200)] 
MINOR: quic: Congestion controller event trace fix (loss)

Missing event type (loss).

3 years agoBUG/MINOR: quic: Wrong unit for ack delay for incoming ACK frames
Frédéric Lécaille [Tue, 3 May 2022 14:09:08 +0000 (16:09 +0200)] 
BUG/MINOR: quic: Wrong unit for ack delay for incoming ACK frames

This ACK frame field value is in microseconds. Everything is interpreted
and stored in milliseconds in our QUIC implementation.

3 years agoBUG/MINOR: quic: Dropped peer transport parameters
Frédéric Lécaille [Tue, 3 May 2022 13:55:17 +0000 (15:55 +0200)] 
BUG/MINOR: quic: Dropped peer transport parameters

The call to quic_dflt_transport_params_cpy() is already first done by
quic_transport_params_init() which is a good thing. But this function was also
called each time we parsed a transport parameters with quic_transport_param_decode(),
re-initializing to default values some of them. The transport parameters concerned
by this bug are the following:
   - max_udp_payload_size
   - ack_delay_exponent
   - max_ack_delay
   - active_connection_id_limit
So, let's remove this call to quic_dflt_transport_params_cpy() which has nothing
to do here!

3 years agoMINOR: quic: Add a debug counter for sendto() errors
Frédéric Lécaille [Tue, 3 May 2022 08:32:21 +0000 (10:32 +0200)] 
MINOR: quic: Add a debug counter for sendto() errors

As we do not have any task to be wake up by the poller after sendto() error,
we add an sendto() error counter to the quic_conn struct.
Dump its values from qc_send_ppkts().

3 years agoDOC: configuration: add the httpclient keywords to the global keywords index
William Lallemand [Thu, 12 May 2022 08:51:15 +0000 (10:51 +0200)] 
DOC: configuration: add the httpclient keywords to the global keywords index

    - httpclient.ssl.verify
    - httpclient.ssl.ca-file
    - httpclient.resolvers.id
    - httpclient.resolvers.prefer

3 years agoMINOR: mux-h2: report a trace event when failing to create a new stream
Willy Tarreau [Thu, 12 May 2022 07:24:41 +0000 (09:24 +0200)] 
MINOR: mux-h2: report a trace event when failing to create a new stream

There are two reasons we can reject the creation of an h2 stream on the
frontend:
  - its creation would violate the MAX_CONCURRENT_STREAMS setting
  - there's no more memory available

And on the backend it's almost the same except that the setting might
have be negotiated after trying to set up the stream.

Let's add traces for such a sitaution so that it's possible to know why
the stream was rejected (currently we only know it was rejected).

It could be nice to backport this to the most recent versions.

3 years agoBUG/MINOR: mux-h2: mark the stream as open before processing it not after
Willy Tarreau [Thu, 12 May 2022 07:08:51 +0000 (09:08 +0200)] 
BUG/MINOR: mux-h2: mark the stream as open before processing it not after

When a client doesn't respect the h2 MAX_CONCURRENT_STREAMS setting, we
rightfully send RST_STREAM to it so that the client closes. But the
max_id is only updated on the successful path of h2c_handle_stream_new(),
which may be reentered for partial frames or CONTINUATION frames, and as
a result we don't increment it if an extraneous stream ID is rejected.

Normally it doesn't have any consequence. But on a POST it can have some
if the DATA frame immediately follows the faulty HEADERS frame: with
max_id not incremented, the stream remains in IDLE state, and the DATA
frame now lands in an invalid state from a protocol's perspective, which
must lead to a connection error instead of a stream error.

This can be tested by modifying the code to send an arbitrarily large
MAX_CONCURRENT_STREAM setting and using h2load to send more concurrent
streams than configured: with a GET, only a tiny fraction of them will
report an error (e.g. 101 streams for 100 accepted will result in ~1%
failure), but when sending data, most of the streams will be reported
as failed because the connection will be closed. By updating the max_id
earlier, the stream is now considered as closed when the DATA frame
arrives and it's silently discarded.

This must be backported to all versions but only if the code is exactly
the same. Under no circumstance this ID may be updated for a partial frame
(i.e. only update it before or just after calling h2c_frt_steam_new()).

3 years agoBUG/MAJOR: dns: multi-thread concurrency issue on UDP socket
Emeric Brun [Tue, 10 May 2022 09:35:48 +0000 (11:35 +0200)] 
BUG/MAJOR: dns: multi-thread concurrency issue on UDP socket

This patch adds a lock on the struct dgram_conn to ensure
that an other thread cannot trash a fd or alter its status
while the current thread processing it on for send/receive/connect
operations.

Starting with the 2.4 version this could cause a crash when a DNS
request is failing, setting the FD of the dgram structure to -1. If the
dgram structure is reused after that, a read access to fdtab[-1] is
attempted. The crash was only triggered when compiled with ASAN.

In previous versions the concurrency issue also exists but is less
likely to crash.

This patch must be backported until v2.4 and should be
adapt for v < 2.4.

3 years agoBUG/MINOR: server: Make SRV_STATE_LINE_MAXLEN value from 512 to 2kB (2000 bytes).
vigneshsp [Mon, 9 May 2022 17:06:39 +0000 (22:36 +0530)] 
BUG/MINOR: server: Make SRV_STATE_LINE_MAXLEN value from 512 to 2kB (2000 bytes).

The statefile before this patch can only parse lines within 512
characters, now as we made the value to 2000, it can support a
line of length of 2kB.

This patch fixes GitHub issue #1530.
It should be backported to all stable releases.

3 years agoBUILD: makefile: add -Wfatal-errors to the default flags
Willy Tarreau [Wed, 11 May 2022 09:32:41 +0000 (11:32 +0200)] 
BUILD: makefile: add -Wfatal-errors to the default flags

Some error reports are misleading on some recent versions of gcc because
it goes on to build for a very long time after it meets an error. Not
only this makes it hard to scroll back to the beginning of the error,
but it also hides the cause of the error when it's prominently printed
in a "#error" statement. This typically happens when building with QUIC
and without OPENSSL where there can be 4 pages of unknown types and such
errors after the "Must define USE_OPENSSL" suggestion.

The flag -Wfatal-errors serves exactly this purpose, to stop after the
first error, and it's supported on all the compilers we support, so let's
enable this now.

3 years agoDOC: install: update gcc version requirements
Willy Tarreau [Wed, 11 May 2022 09:29:54 +0000 (11:29 +0200)] 
DOC: install: update gcc version requirements

It turns out that gcc-3.4 doesn't build anymore (and it has probably been
the case since 2.4 or so). gcc-4.2 does build fine though, let's mark it
as the oldest supported one. Now that gcc-12 works, also update the most
recently known-to-work version.

3 years agoBUG/MEDIUM: ssl: fix the gcc-12 broken fix :-(
Willy Tarreau [Mon, 9 May 2022 19:14:04 +0000 (21:14 +0200)] 
BUG/MEDIUM: ssl: fix the gcc-12 broken fix :-(

... or how a bogus warning forces you to do tricky changes in your code
and fail on a length test condition! Fortunately it changed in the right
direction that immediately broke, due to a missing "> sizeof(path)" that
had to be added to the already ugly condition.

This fixes recent commit 393e42ae5 ("BUILD: ssl: work around bogus warning
in gcc 12's -Wformat-truncation"). It may have to be backported if that
one is backported.

3 years agoBUILD: listener: shut report of possible null-deref in listener_accept()
Willy Tarreau [Mon, 9 May 2022 18:41:54 +0000 (20:41 +0200)] 
BUILD: listener: shut report of possible null-deref in listener_accept()

When building without threads, gcc 12 says that there's a null-deref in
_HA_ATOMIC_INC() called from listener_accept(). It's just that the code
was originally written in an attempt not to always have a proxy for a
listener and that there are two places where the pointer is tested before
being used, so the compiler concludes that the pointer might be null
hence that other places are null-derefs.

In practice the pointer cannot be null there (and never has been), but
since that code was initially built that way and it's only a matter of
adding a pair of braces to shut it up, let's respect that initial
attempt in case one day we need it.

This one was also reported by Ilya in issue #1513, though with threads
enabled in his case.

This may have to be backported if users complain about new breakage with
gcc-12.

3 years agoBUILD: debug: work around gcc-12 excessive -Warray-bounds warnings
Willy Tarreau [Mon, 9 May 2022 18:07:21 +0000 (20:07 +0200)] 
BUILD: debug: work around gcc-12 excessive -Warray-bounds warnings

As was first reported by Ilya in issue #1513, compiling with gcc-12
adds warnings about size 0 around each BUG_ON() call due to the
ABORT_NOW() macro that tries to dereference pointer value 1.

The problem is known, seems to be complex inside gcc and could only
be worked around for now by adjusting a pointer limit so that the
warning still catches NULL derefs in the first page but not other
values commonly used in kernels and boot loaders:
   https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=91f7d7e1b

It's described in more details here:
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104657
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103768

And some projects had to work around it using various approaches,
some of which are described in the bugs reports above, plus another
one here:
   https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/HLK3BHP2T3FN6FZ46BIPIK3VD5FOU74Z/

In haproxy we can hide it by hiding the pointer in a DISGUISE() macro,
but this forces the pointer to be loaded into a register, so that
register is lost precisely where we want to get the maximum of them.

In our case we purposely use a low-value non-null pointer because:
  - it's mandatory that this value fits within an unmapped page and
    only the lowest one has this property
  - we really want to avoid register loads for the address, as these
    will be lost and will complicate the bug analysis, and they tend
    to be used for large addresses (i.e. instruction length limit).
  - the compiler may decide to optimize away the null deref when it
    sees it (seen in the past already)

As such, the current workaround merged in gcc-12 is not effective for
us.

Another approach consists in using pragmas to silently disable
-Warray-bounds and -Wnull-dereference only for this part. The problem
is that pragmas cannot be placed into macros.

The resulting solution consists in defining a forced-inlined function
only to trigger the crash, and surround the dereference with pragmas,
themselves conditionned to gcc >= 5 since older versions don't
understand them (but they don't complain on the dereference at least).

This way the code remains the same even at -O0, without the stack
pointer being modified nor any address register being modified on
common archs (x86 at least). A variation could have been to rely on
__builtin_trap() but it's not everywhere and it behaves differently
on different platforms (undefined opcode or a nasty abort()) while
the segv remains uniform and effective.

This may need to be backported to older releases once users start to
complain about gcc-12 breakage.

3 years agoBUILD: ssl: work around bogus warning in gcc 12's -Wformat-truncation
Willy Tarreau [Mon, 9 May 2022 08:31:28 +0000 (10:31 +0200)] 
BUILD: ssl: work around bogus warning in gcc 12's -Wformat-truncation

As was first reported by Ilya in issue #1513, Gcc 12 incorrectly reports
a possible overflow from the concatenation of two strings whose size was
previously checked to fit:

  src/ssl_crtlist.c: In function 'crtlist_parse_file':
  src/ssl_crtlist.c:545:58: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 1 and 4096 [-Werror=format-truncation=]
    545 |                         snprintf(path, sizeof(path), "%s/%s",  global_ssl.crt_base, crt_path);
        |                                                          ^~
  src/ssl_crtlist.c:545:25: note: 'snprintf' output between 2 and 8192 bytes into a destination of size 4097
    545 |                         snprintf(path, sizeof(path), "%s/%s",  global_ssl.crt_base, crt_path);
        |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It would be a bit concerning to disable -Wformat-truncation because it
might detect real programming mistakes at other places. The solution
adopted in this patch is absolutely ugly and error-prone, but it works,
it consists in integrating the snprintf() call in the error condition
and to test the result again. Let's hope a smarter compiler will not
warn that this test is absurd since guaranteed by the first condition...

This may have to be backported for those suffering from a compiler upgrade.

3 years agoBUILD: stats: conditionally mark obsolete stats states as deprecated
Willy Tarreau [Mon, 9 May 2022 17:46:35 +0000 (19:46 +0200)] 
BUILD: stats: conditionally mark obsolete stats states as deprecated

The obsolete stats states STAT_ST_* were marked as deprecated with recent
commit 6ef1648dc ("CLEANUP: stats: rename the stats state values an mark
the old ones deprecated"), except that this feature requires gcc 6 and
above. Let's use the macro that depends on this condition instead.

The issue appeared on 2.6-dev9 so no backport is needed.

3 years agoMINOR: compiler: add a new macro to set an attribute on an enum when possible
Willy Tarreau [Mon, 9 May 2022 17:45:06 +0000 (19:45 +0200)] 
MINOR: compiler: add a new macro to set an attribute on an enum when possible

Gcc 6 and above support placing an attribute on an enum's value. This
is convenient for marking some values as deprecated. We just need the
macro because older versions fail to parse __attribute__() there.

3 years agoBUG/MINOR: ssl: Fix typos in crl-file related CLI commands
Remi Tricot-Le Breton [Thu, 5 May 2022 15:18:40 +0000 (17:18 +0200)] 
BUG/MINOR: ssl: Fix typos in crl-file related CLI commands

The CRL file CLI update code was strongly based off the CA one and some
copy-paste issues were then introduced.

This patch fixes GitHub issue #1685.
It should be backported to 2.5.

3 years agoMEDIUM: ssl: ignore dotfiles when loading a dir w/ crt
William Lallemand [Mon, 9 May 2022 08:30:51 +0000 (10:30 +0200)] 
MEDIUM: ssl: ignore dotfiles when loading a dir w/ crt

Ignore the files starting with a dot when trying to load a directory
with the "crt" directive.

Should fix issue #1689.

3 years agoMINOR: ssl: ignore dotfiles when loading a dir w/ ca-file
William Lallemand [Mon, 9 May 2022 07:29:00 +0000 (09:29 +0200)] 
MINOR: ssl: ignore dotfiles when loading a dir w/ ca-file

Ignore the files starting with a dot when trying to load a directory
with the "ca-file directive".

3 years ago[RELEASE] Released version 2.6-dev9 v2.6-dev9
Willy Tarreau [Sun, 8 May 2022 09:44:15 +0000 (11:44 +0200)] 
[RELEASE] Released version 2.6-dev9

Released version 2.6-dev9 with the following main changes :
    - MINOR: mux-quic: support full request channel buffer
    - BUG/MINOR: h3: fix parsing of unknown frame type with null length
    - CLEANUP: backend: make alloc_{bind,dst}_address() idempotent
    - MEDIUM: stream: remove the confusing SF_ADDR_SET flag
    - MINOR: conn_stream: remove the now unused CS_FL_ADDR_*_SET flags
    - CLEANUP: protocol: make sure the connect_* functions always receive a dst
    - MINOR: connection: get rid of the CO_FL_ADDR_*_SET flags
    - MINOR: session: get rid of the now unused SESS_FL_ADDR_*_SET flags
    - CLEANUP: mux: Useless xprt_quic-t.h inclusion
    - MINOR: quic: Make the quic_conn be aware of the number of streams
    - BUG/MINOR: quic: Dropped retransmitted STREAM frames
    - BUG/MINOR: mux_quic: Dropped packet upon retransmission for closed streams
    - MEDIUM: httpclient: remove url2sa to use a more flexible parser
    - MEDIUM: httpclient: http-request rules for resolving
    - MEDIUM: httpclient: allow address and port change for resolving
    - CLEANUP: httpclient: remove the comment about resolving
    - MINOR: httpclient: handle unix and other socket types in dst
    - MINOR: httpclient: rename dash by dot in global option
    - MINOR: init: exit() after pre-check upon error
    - MINOR: httpclient: cleanup the error handling in init
    - MEDIUM: httpclient: hard-error when SSL is configured
    - MINOR: httpclient: allow to configure the ca-file
    - MINOR: httpclient: configure the resolvers section to use
    - MINOR: httpclient: allow ipv4 or ipv6 preference for resolving
    - DOC: configuration: httpclient global option
    - MINOR: conn-stream: Add mask from flags set by endpoint or app layer
    - BUG/MEDIUM: conn-stream: Only keep app layer flags of the endpoint on reset
    - BUG/MEDIUM: mux-fcgi: Be sure to never set EOM flag on an empty HTX message
    - BUG/MEDIUM: mux-h1: Be able to handle trailers when C-L header was specified
    - DOC: config: Update doc for PR/PH session states to warn about rewrite failures
    - MINOR: resolvers: cleanup alert/warning in parse-resolve-conf
    - MINOR: resolvers: move the resolv.conf parser in parse_resolv_conf()
    - MINOR: resolvers: resolvers_new() create a resolvers with default values
    - BUILD: debug: unify the definition of ha_backtrace_to_stderr()
    - BUG/MINOR: tcp/http: release the expr of set-{src,dst}[-port]
    - MEDIUM: resolvers: create a "default" resolvers section at startup
    - DOC: resolvers: default resolvers section
    - BUG/MINOR: startup: usage() when no -cc arguments
    - BUG/MEDIUM: resolvers: make "show resolvers" properly yield
    - BUG/MEDIUM: cli: make "show cli sockets" really yield
    - BUG/MINOR: proxy/cli: don't enumerate internal proxies on "show backend"
    - BUG/MINOR: map/cli: protect the backref list during "show map" errors
    - BUG/MINOR: map/cli: make sure patterns don't vanish under "show map"'s init
    - BUG/MINOR: ssl/cli: fix "show ssl ca-file/crl-file" not to mix cli+ssl contexts
    - BUG/MINOR: ssl/cli: fix "show ssl ca-file <name>" not to mix cli+ssl contexts
    - BUG/MINOR: ssl/cli: fix "show ssl crl-file" not to mix cli+ssl contexts
    - BUG/MINOR: ssl/cli: fix "show ssl cert" not to mix cli+ssl contexts
    - CLEANUP: ssl/cli: do not loop on unknown states in "add ssl crt-list" handler
    - MINOR: applet: reserve some generic storage in the applet's context
    - CLEANUP: applet: make appctx_new() initialize the whole appctx
    - CLEANUP: stream/cli: take the "show sess" context definition out of the appctx
    - CLEANUP: stream/cli: stop using appctx->st2 for the dump state
    - CLEANUP: stream/cli: remove the unneeded init state from "show sess"
    - CLEANUP: stream/cli: remove the unneeded STATE_FIN state from "show sess"
    - CLEANUP: stream/cli: remove the now unneeded dump state from "show sess"
    - CLEANUP: proxy/cli: take the "show errors" context definition out of the appctx
    - CLEANUP: stick-table/cli: take the "show table" context definition out of the appctx
    - CLEANUP: stick-table/cli: stop using appctx->st2 for the dump state
    - CLEANUP: stick-table/cli: remove the unneeded STATE_INIT for "show table"
    - CLEANUP: map/cli: take the "show map" context definition out of the appctx
    - CLEANUP: map/cli: stop using cli.i0/i1 to store the generation numbers
    - CLEANUP: map/cli: stop using appctx->st2 for the dump state
    - CLEANUP: map/cli: always detach the backref from the list after "show map"
    - CLEANUP: peers/cli: take the "show peers" context definition out of the appctx
    - CLEANUP: peers/cli: stop using appctx->st2 for the dump state
    - CLEANUP: peers/cli: remove unneeded state STATE_INIT
    - CLEANUP: cli: initialize the whole appctx->ctx, not just the stats part
    - CLEANUP: promex: make the applet use its own context
    - CLEANUP: promex: stop using appctx->st2
    - CLEANUP: stats/cli: take the "show stat" context definition out of the appctx
    - CLEANUP: stats/cli: stop using appctx->st2
    - CLEANUP: hlua/cli: take the hlua_cli context definition out of the appctx
    - CLEANUP: ssl/cli: use a local context for "show cafile"
    - CLEANUP: ssl/cli: use a local context for "show crlfile"
    - CLEANUP: ssl/cli: use a local context for "show ssl cert"
    - CLEANUP: ssl/cli: use a local context for "commit ssl cert"
    - CLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl cert"
    - CLEANUP: ssl/cli: use a local context for "set ssl cert"
    - CLEANUP: ssl/cli: use a local context for "set ssl cafile"
    - CLEANUP: ssl/cli: use a local context for "set ssl crlfile"
    - CLEANUP: ssl/cli: use a local context for "commit ssl {ca|crl}file"
    - CLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl ca/crl"
    - CLEANUP: ssl/cli: stop using ctx.cli.i0/i1/p0 for "show tls-keys"
    - CLEANUP: ssl/cli: add a new "dump_entries" field to "show_keys_ref"
    - CLEANUP: ssl/cli: make "show tlskeys" not use appctx->st2 anymore
    - CLEANUP: ssl/cli: make "show ssl ocsp-response" not use cli.p0 anymore
    - CLEANUP: ssl/cli: make "{show|dump} ssl crtlist" use its own context
    - CLEANUP: ssl/cli: make "add ssl crtlist" use its own context
    - CLEANUP: ssl/cli: make "add ssl crtlist" not use st2 anymore
    - CLEANUP: dns: stop abusing the sink forwarder's context
    - CLEANUP: sink: use the generic context to store the forwarder's context
    - CLEANUP: activity/cli: make "show profiling" not use ctx.cli anymore
    - CLEANUP: debug/cli: make "debug dev fd" not use ctx.cli anymore
    - CLEANUP: debug/cli: make "debug dev memstats" not use ctx.cli anymore
    - CLEANUP: ring: pass the ring watch flags to ring_attach_cli(), not in ctx.cli
    - CLEANUP: ring/cli: use a locally-defined context instead of using ctx.cli
    - CLEANUP: resolvers/cli: make "show resolvers" use a locally-defined context
    - CLEANUP: resolvers/cli: remove the unneeded appctx->st2 from "show resolvers"
    - CLEANUP: cache/cli: make use of a locally defined context for "show cache"
    - CLEANUP: proxy/cli: make use of a locally defined context for "show servers"
    - CLEANUP: proxy/cli: get rid of appctx->st2 in "show servers"
    - CLEANUP: proxy/cli: make "show backend" only use the generic context
    - CLEANUP: cli: make "show fd" use its own context
    - CLEANUP: cli: make "show env" use its own context
    - CLEANUP: cli: simplify the "show cli sockets" I/O handler
    - CLEANUP: cli: make "show cli sockets" use its own context
    - CLEANUP: httpclient/cli: use a locally-defined context instead of ctx.cli
    - CLEANUP: httpclient: do not use the appctx.ctx anymore
    - CLEANUP: peers: do not use appctx.ctx anymore
    - CLEANUP: spoe: do not use appctx.ctx anymore
    - BUILD: applet: mark the CLI's generic variables as deprecated
    - BUILD: applet: mark the appctx's st2 variable as deprecated
    - CLEANUP: cache: take the context out of appctx.ctx
    - MEDIUM: lua: move the cosocket storage outside of appctx.ctx
    - MINOR: lua: move the tcp service storage outside of appctx.ctx
    - MINOR: lua: move the http service context out of appctx.ctx
    - CLEANUP: cli: move the status print context into its own context
    - CLEANUP: stats: rename the stats state values an mark the old ones deprecated
    - DOC: internal: document the new cleaner approach to the appctx
    - MINOR: tcp: socket translate TCP_KEEPIDLE for macOs equivalent
    - DOC: fix typo "ant" for "and" in INSTALL
    - CI: dynamically determine actual version of h2spec

3 years agoCI: dynamically determine actual version of h2spec
Ilya Shipitsin [Thu, 5 May 2022 10:15:12 +0000 (15:15 +0500)] 
CI: dynamically determine actual version of h2spec

previously we used hardcoded h2spec version. let us switch to
the latest available

3 years agoDOC: fix typo "ant" for "and" in INSTALL
Willy Tarreau [Sun, 8 May 2022 08:59:00 +0000 (10:59 +0200)] 
DOC: fix typo "ant" for "and" in INSTALL

Tomas Zubiri reported this typo in the doc that apparently exists in
2.5 as well.

3 years agoMINOR: tcp: socket translate TCP_KEEPIDLE for macOs equivalent
David CARLIER [Sun, 1 May 2022 14:29:58 +0000 (15:29 +0100)] 
MINOR: tcp: socket translate TCP_KEEPIDLE for macOs equivalent

On Linux the interval before starting to send TCP keep-alive packets
is defined by TCP_KEEPIDLE. MacOS has an equivalent with TCP_KEEPIDLE,
which also uses seconds as a unit, so it's possible to simply remap the
definition of TCP_KEEPIDLE to TCP_KEEPALIVE there and get it to seamlessly
work. The other settings (interval and count) are not present, though.

3 years agoDOC: internal: document the new cleaner approach to the appctx
Willy Tarreau [Fri, 6 May 2022 16:00:24 +0000 (18:00 +0200)] 
DOC: internal: document the new cleaner approach to the appctx

It explains the problems with the previous union, the temporary state
for the transition between 2.6 and 2.7, and how to perform the changes.

3 years agoCLEANUP: stats: rename the stats state values an mark the old ones deprecated
Willy Tarreau [Fri, 6 May 2022 16:07:53 +0000 (18:07 +0200)] 
CLEANUP: stats: rename the stats state values an mark the old ones deprecated

The STAT_ST_* values have been abused by virtually every applet and CLI
keyword handler, and this must not continue as it's a source of bugs and
of overly complicated code.

This patch renames the states to STAT_STATE_*, and keeps the previous
enum while marking each entry as deprecated. This should be sufficient to
catch out-of-tree code that might rely on them and to let them know what
to do with that.

3 years agoCLEANUP: cli: move the status print context into its own context
Willy Tarreau [Fri, 6 May 2022 15:16:35 +0000 (17:16 +0200)] 
CLEANUP: cli: move the status print context into its own context

Now that the CLI's print context is alone in the appctx, it's possible
to refine the appctx's ctx layout so that the cli part matches exactly
a regular svcctx, and as such move the CLI context into an svcctx like
other applets. External code will still build and work because the
struct cli perfectly maps onto the struct cli_print_ctx that's located
into svc.storage. This is of course only to make a smooth transition
during 2.6 and will disappear immediately after.

A tiny change had to be applied to the opentracing addon which performs
direct accesses to the CLI's err pointer in its own print function. The
rest uses the standard cli_print_* which were the only ones that needed
a small change.

The whole "ctx.cli" struct could be tagged as deprecated so that any
possibly existing external code that relies on it will get build
warnings, and the comments in the struct are pretty clear about the
way to fix it, and the lack of future of this old API.

3 years agoMINOR: lua: move the http service context out of appctx.ctx
Willy Tarreau [Fri, 6 May 2022 12:26:10 +0000 (14:26 +0200)] 
MINOR: lua: move the http service context out of appctx.ctx

Just like for the TCP service, let's move the context away from
appctx.ctx. A new struct hlua_http_ctx was defined, reserved in
hlua_applet_http_init() and used everywhere else. Similarly, the
task dump code will no more report decoded stack traces in case
these services would be involved. That may be solved later.

3 years agoMINOR: lua: move the tcp service storage outside of appctx.ctx
Willy Tarreau [Fri, 6 May 2022 12:07:13 +0000 (14:07 +0200)] 
MINOR: lua: move the tcp service storage outside of appctx.ctx

The use-service mechanism for Lua in TCP mode relies on the
hlua_tcp storage in appctx->ctx. We can move its definition to
hlua.c and simply use appctx_reserve_svcctx() to reserve and access
the stoage. One tiny side effect is that the task dump used in panics
will not show anymore the Lua call stack in its trace. For this a
better API is needed from the Lua code to expose a function that does
the job from an appctx.

3 years agoMEDIUM: lua: move the cosocket storage outside of appctx.ctx
Willy Tarreau [Fri, 6 May 2022 09:57:34 +0000 (11:57 +0200)] 
MEDIUM: lua: move the cosocket storage outside of appctx.ctx

The Lua cosockets were using appctx.ctx.hlua_cosocket. Let's move this
to a local definition of "hlua_csk_ctx" in hlua.c, which is allocated
from the appctx by hlua_socket_new(). There's a notable change which is
that, while previously the xref link with the peer was established with
the appctx, it's now in the hlua_csk_ctx. This one must then hold a
pointer to the appctx. The code was adjusted accordingly, and now that
part of the code doesn't use the appctx.ctx anymore.

3 years agoCLEANUP: cache: take the context out of appctx.ctx
Willy Tarreau [Fri, 6 May 2022 09:03:39 +0000 (11:03 +0200)] 
CLEANUP: cache: take the context out of appctx.ctx

The context was moved to a local definition in the cache code, and
there's nothing specific to the cache anymore in the appctx. The
struct is stored into the appctx's storage area via the svcctx.

3 years agoBUILD: applet: mark the appctx's st2 variable as deprecated
Willy Tarreau [Thu, 5 May 2022 18:01:54 +0000 (20:01 +0200)] 
BUILD: applet: mark the appctx's st2 variable as deprecated

This one has been misused for a while as well, it's time to deprecate it
since we don't use it anymore. It will be removed in 2.7 and for now is
only marked as deprecated. Since we need to guarantee that it's zeroed
before starting any applet or CLI command, it was moved into an anonymous
union where its sibling is not marked as deprecated so that we can
continue to initialize it without triggering a warning.

If you found this commit after a bisect session you initiated to figure
why you got some build warnings and don't know what to do, have a look
at the code that deals with the "show fd", "show sess" or "show servers"
commands, as it's supposed to be self-explanatory about the tiny changes
to apply to your code to port it. If you find APPLET_MAX_SVCCTX to be
too small for your use case, either kindly ask for a tiny extension
(and try to get your code merged), or just use a pool.

3 years agoBUILD: applet: mark the CLI's generic variables as deprecated
Willy Tarreau [Thu, 5 May 2022 17:43:49 +0000 (19:43 +0200)] 
BUILD: applet: mark the CLI's generic variables as deprecated

The generic context variables p0/p1/p2, i0/i1, o0/o1 have been abused
and causing trouble for too long, it's time to remove them now that
they are not used anymore.

However the risk that external code still uses them is not nul and we
had not warned before about their removal. Let's mark them deprecated
in 2.6 and removed in 2.7. This will let external code continue to work
(as well as it could if it misuses them), with a strong encouragement
on updating it.

If you found this commit after a bisect session you initiated to figure
why you got some build warnings and don't know what to do, have a look
at the code that deals with the "show fd", "show env" or "show servers"
commands, as it's supposed to be self-explanatory about the tiny changes
to apply to your code to port it. If you find APPLET_MAX_SVCCTX to be
too small for your use case, either kindly ask for a tiny extension
(and try to get your code merged), or just use a pool.

3 years agoCLEANUP: spoe: do not use appctx.ctx anymore
Willy Tarreau [Thu, 5 May 2022 18:18:44 +0000 (20:18 +0200)] 
CLEANUP: spoe: do not use appctx.ctx anymore

The spoe code already uses its own generic pointer, let's move it to
svcctx instead of keeping a struct spoe in the appctx union.

3 years agoCLEANUP: peers: do not use appctx.ctx anymore
Willy Tarreau [Thu, 5 May 2022 18:16:16 +0000 (20:16 +0200)] 
CLEANUP: peers: do not use appctx.ctx anymore

The peers code already uses its own generic pointer, let's move it to
svcctx instead of keeping a struct peers in the appctx union.

3 years agoCLEANUP: httpclient: do not use the appctx.ctx anymore
Willy Tarreau [Thu, 5 May 2022 18:12:01 +0000 (20:12 +0200)] 
CLEANUP: httpclient: do not use the appctx.ctx anymore

The httpclient already uses its own pointer and only used to store this
single pointer into the appctx.ctx field. Let's just move it to the
svcctx and remove this entry from the appctx union.

3 years agoCLEANUP: httpclient/cli: use a locally-defined context instead of ctx.cli
Willy Tarreau [Thu, 5 May 2022 17:38:21 +0000 (19:38 +0200)] 
CLEANUP: httpclient/cli: use a locally-defined context instead of ctx.cli

The httpclient's CLI uses ctx.cli.i0 for its flags and .p0 for the client
instance. Let's have a locally defined structure for this so that we don't
need the generic cli variables anymore.

3 years agoCLEANUP: cli: make "show cli sockets" use its own context
Willy Tarreau [Thu, 5 May 2022 17:11:05 +0000 (19:11 +0200)] 
CLEANUP: cli: make "show cli sockets" use its own context

Let's create a show_sock_ctx to store the bind_conf and the listener.
The entry is reserved when entering the I/O handler since there's no
parser here. That's fine because the function doesn't touch the area.

3 years agoCLEANUP: cli: simplify the "show cli sockets" I/O handler
Willy Tarreau [Thu, 5 May 2022 16:52:36 +0000 (18:52 +0200)] 
CLEANUP: cli: simplify the "show cli sockets" I/O handler

The code is was a bit convoluted by the use of a state machine around
st2 that is not used since only the STAT_ST_LIST state was used, and
the test of global.cli_fe inside the loop while it ought better be
tested before entering there. Let's get rid of this unneded state and
simplify the code. There's no more need for ->st2 now. The code looks
more changed than it really is due to the reindent caused by the
removal of the switch statement, but "git show -b" shows what really
changed.

3 years agoCLEANUP: cli: make "show env" use its own context
Willy Tarreau [Thu, 5 May 2022 15:45:52 +0000 (17:45 +0200)] 
CLEANUP: cli: make "show env" use its own context

There is the variable to start from (or environ) and an option to stop
after dumping the first one, just like "show fd". Let's have a small
locally-defined context with these two fields.

3 years agoCLEANUP: cli: make "show fd" use its own context
Willy Tarreau [Thu, 5 May 2022 15:56:58 +0000 (17:56 +0200)] 
CLEANUP: cli: make "show fd" use its own context

The "show fd" command used to rely on cli.i0 for the fd, and st2 just
to decide whether to stop after the first value or not. It could have
been possible to decide to use just a negative integer to dump a single
value, but it's as easy and more durable to declare a two-field struct
show_fd_ctx for this.

3 years agoCLEANUP: proxy/cli: make "show backend" only use the generic context
Willy Tarreau [Thu, 5 May 2022 15:05:38 +0000 (17:05 +0200)] 
CLEANUP: proxy/cli: make "show backend" only use the generic context

Let's use appctx->svcctx instead of abusing cli.p0 to store the
current proxy being dumped.

3 years agoCLEANUP: proxy/cli: get rid of appctx->st2 in "show servers"
Willy Tarreau [Thu, 5 May 2022 17:26:18 +0000 (19:26 +0200)] 
CLEANUP: proxy/cli: get rid of appctx->st2 in "show servers"

Now that we have the show_srv_ctx, let's store a state in it. We only
need two states here, header and list.

3 years agoCLEANUP: proxy/cli: make use of a locally defined context for "show servers"
Willy Tarreau [Thu, 5 May 2022 15:00:20 +0000 (17:00 +0200)] 
CLEANUP: proxy/cli: make use of a locally defined context for "show servers"

The command uses a pointer to the current proxy being dumped, one to the
current server being dumped, an optional ID of the only proxy to dump
(which is in fact used as a boolean), and a flag indicating if we're
doing a "show servers conn" or a "show servers state". Let's move all
this to a struct show_srv_ctx.

3 years agoCLEANUP: cache/cli: make use of a locally defined context for "show cache"
Willy Tarreau [Thu, 5 May 2022 14:46:13 +0000 (16:46 +0200)] 
CLEANUP: cache/cli: make use of a locally defined context for "show cache"

The command uses a pointer to a cache instance and the next key to dump,
they were in cli.p0/i0 respectively, let's move them to a struct
show_cache_ctx.

3 years agoCLEANUP: resolvers/cli: remove the unneeded appctx->st2 from "show resolvers"
Willy Tarreau [Thu, 5 May 2022 14:38:13 +0000 (16:38 +0200)] 
CLEANUP: resolvers/cli: remove the unneeded appctx->st2 from "show resolvers"

The command uses this state but _INIT immediately turns to _LIST, which
turns to _FIN at the end without doing anything in that state, thus the
only existing state is _LIST so we don't need to store a state. Let's
just get rid of it.

3 years agoCLEANUP: resolvers/cli: make "show resolvers" use a locally-defined context
Willy Tarreau [Thu, 5 May 2022 13:39:02 +0000 (15:39 +0200)] 
CLEANUP: resolvers/cli: make "show resolvers" use a locally-defined context

The command was using cli.p0/p1/p2 to select which section to dump, the
current section and the current ns. Let's instead have a locally defined
"show_resolvers_ctx" section for this.

3 years agoCLEANUP: ring/cli: use a locally-defined context instead of using ctx.cli
Willy Tarreau [Thu, 5 May 2022 13:29:43 +0000 (15:29 +0200)] 
CLEANUP: ring/cli: use a locally-defined context instead of using ctx.cli

The ring code was using ctx.cli.i0/p0/o0 to store its context during CLI
dumps via "show events" or "show errors". Let's use a locally defined
context and drop that.

3 years agoCLEANUP: ring: pass the ring watch flags to ring_attach_cli(), not in ctx.cli
Willy Tarreau [Thu, 5 May 2022 13:18:57 +0000 (15:18 +0200)] 
CLEANUP: ring: pass the ring watch flags to ring_attach_cli(), not in ctx.cli

The ring watch flags (wait, seek end) were dangerously passed via ctx.cli.i0
from "show buf" in sink.c:cli_parse_show_events(), or implicitly reset in
"show errors". That's very unconvenient, difficult to follow, and prone to
short-term breakage.

Let's pass an extra argument to ring_attach_cli() to take these flags, now
defined in ring-t.h as RING_WF_*, and let the function set them itself
where appropriate (still ctx.cli.i0 for now).

3 years agoCLEANUP: debug/cli: make "debug dev memstats" not use ctx.cli anymore
Willy Tarreau [Thu, 5 May 2022 12:39:51 +0000 (14:39 +0200)] 
CLEANUP: debug/cli: make "debug dev memstats" not use ctx.cli anymore

There was only the need for a start and a stop pointer, and a show_all
flag. All of that moved to a locally-defined struct dev_mem_ctx.

3 years agoCLEANUP: debug/cli: make "debug dev fd" not use ctx.cli anymore
Willy Tarreau [Thu, 5 May 2022 12:26:28 +0000 (14:26 +0200)] 
CLEANUP: debug/cli: make "debug dev fd" not use ctx.cli anymore

The command only requires to store an int, but it will be useful later
to have a struct to pass extra info such as an "all" flag to dump all
FDs. The new context is now a struct dev_fd_ctx stored in svcctx.

3 years agoCLEANUP: activity/cli: make "show profiling" not use ctx.cli anymore
Willy Tarreau [Thu, 5 May 2022 12:19:00 +0000 (14:19 +0200)] 
CLEANUP: activity/cli: make "show profiling" not use ctx.cli anymore

The I/O handler was using ctx.cli.i0/i1/o0/o1. Let's put all that into
a locally-defined context and use it instead.

3 years agoCLEANUP: sink: use the generic context to store the forwarder's context
Willy Tarreau [Wed, 4 May 2022 18:42:23 +0000 (20:42 +0200)] 
CLEANUP: sink: use the generic context to store the forwarder's context

Instead of having a struct that contains a single pointer in the appctx
context, let's directly use the generic context pointer and get rid of
the now unused sft.ptr entry.

3 years agoCLEANUP: dns: stop abusing the sink forwarder's context
Willy Tarreau [Wed, 4 May 2022 18:41:19 +0000 (20:41 +0200)] 
CLEANUP: dns: stop abusing the sink forwarder's context

The DNS code was abusing the sink forwarder's context as its own. Let's
make it directly use the generic context pointer instead.

3 years agoCLEANUP: ssl/cli: make "add ssl crtlist" not use st2 anymore
Willy Tarreau [Thu, 5 May 2022 11:48:40 +0000 (13:48 +0200)] 
CLEANUP: ssl/cli: make "add ssl crtlist" not use st2 anymore

Several steps are used during the addition of a crtlist to yield during
long operations, and states are used for this. Let's just not use the
st2 anymore and place the state inside the add_crtlist_ctx struct instead.

3 years agoCLEANUP: ssl/cli: make "add ssl crtlist" use its own context
Willy Tarreau [Thu, 5 May 2022 11:43:49 +0000 (13:43 +0200)] 
CLEANUP: ssl/cli: make "add ssl crtlist" use its own context

This command was using cli.p0/p1/p2 in the io_handler. Let's move them
to a command-specific "struct add_crtlist_ctx".

3 years agoCLEANUP: ssl/cli: make "{show|dump} ssl crtlist" use its own context
Willy Tarreau [Thu, 5 May 2022 09:53:23 +0000 (11:53 +0200)] 
CLEANUP: ssl/cli: make "{show|dump} ssl crtlist" use its own context

These commands were using cli.i0/p0/p1 and in a not very clean way since
they use the same parser but with different types depending on the I/O
handler. Given there was no explanation about what the variables were
supposed to be, they were named based on best guess and placed into a
new "show_crtlist_ctx" structure.

3 years agoCLEANUP: ssl/cli: make "show ssl ocsp-response" not use cli.p0 anymore
Willy Tarreau [Thu, 5 May 2022 07:09:15 +0000 (09:09 +0200)] 
CLEANUP: ssl/cli: make "show ssl ocsp-response" not use cli.p0 anymore

Instead the single-pointer context is placed into appctx->svcctx.
There's no need to declare a structure there for this.

3 years agoCLEANUP: ssl/cli: make "show tlskeys" not use appctx->st2 anymore
Willy Tarreau [Thu, 5 May 2022 07:03:44 +0000 (09:03 +0200)] 
CLEANUP: ssl/cli: make "show tlskeys" not use appctx->st2 anymore

A new "state" enum was added to "show_keys_ctx" for this, and only 3
states are needed.

3 years agoCLEANUP: ssl/cli: add a new "dump_entries" field to "show_keys_ref"
Willy Tarreau [Thu, 5 May 2022 06:59:17 +0000 (08:59 +0200)] 
CLEANUP: ssl/cli: add a new "dump_entries" field to "show_keys_ref"

This gets rid of a ugly hack consisting in checking the IO handler's
address while one is defined as an inline function calling the second.

3 years agoCLEANUP: ssl/cli: stop using ctx.cli.i0/i1/p0 for "show tls-keys"
Willy Tarreau [Thu, 5 May 2022 06:50:17 +0000 (08:50 +0200)] 
CLEANUP: ssl/cli: stop using ctx.cli.i0/i1/p0 for "show tls-keys"

This creates a local context of type show_keys_ctx which contains
the equivalent fields with more natural names.

3 years agoCLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl ca/crl"
Willy Tarreau [Thu, 5 May 2022 06:17:29 +0000 (08:17 +0200)] 
CLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl ca/crl"

A new entry "state" was added into the commit_cacrl_ctx struct instead.

3 years agoCLEANUP: ssl/cli: use a local context for "commit ssl {ca|crl}file"
Willy Tarreau [Wed, 4 May 2022 18:25:05 +0000 (20:25 +0200)] 
CLEANUP: ssl/cli: use a local context for "commit ssl {ca|crl}file"

These two commands use distinct parse/release functions but a common
iohandler, thus they need to keep the same context. It was created
under the name "commit_cacrlfile_ctx" and holds a large part of the
pointers (6) and the ca_type field that helps distinguish between
the two commands for the I/O handler. It looks like some of these
fields could have been merged since apparently the CA part only
uses *cafile* and the CRL part *crlfile*, while both old and new
are of type cafile_entry and set only for each type. This could
probably even simplify some parts of the code that tries to use
the correct field.

These fields were the last ones to be migrated thus the appctx's
ssl context could finally be removed.

3 years agoCLEANUP: ssl/cli: use a local context for "set ssl crlfile"
Willy Tarreau [Wed, 4 May 2022 18:33:03 +0000 (20:33 +0200)] 
CLEANUP: ssl/cli: use a local context for "set ssl crlfile"

Just like for "set ssl cafile", the command doesn't really need this
context which doesn't outlive the parsing function but it was there
for a purpose so it's maintained. Only 3 fields were used from the
appctx's ssl context: old_crlfile_entry, new_crlfile_entry, and path.
These ones were reinstantiated into a new "set_crlfile_ctx" struct.
It could have been merged with the one used in "set cafile" if the
fields had been renamed since cafile and crlfile are of the same
type (probably one of them ought to be renamed?).

None of these fields could be dropped as they are still shared with
other commands.

3 years agoCLEANUP: ssl/cli: use a local context for "set ssl cafile"
Willy Tarreau [Wed, 4 May 2022 18:12:55 +0000 (20:12 +0200)] 
CLEANUP: ssl/cli: use a local context for "set ssl cafile"

Just like for "set ssl cert", the command doesn't really need this
context which doesn't outlive the parsing function but it was there
for a purpose so it's maintained. Only 3 fields were used from the
appctx's ssl context: old_cafile_entry, new_cafile_entry, and path.
These ones were reinstantiated into a new "set_cafile_ctx" struct.
None of them could be dropped as they are still shared with other
commands.

3 years agoCLEANUP: ssl/cli: use a local context for "set ssl cert"
Willy Tarreau [Wed, 4 May 2022 18:05:55 +0000 (20:05 +0200)] 
CLEANUP: ssl/cli: use a local context for "set ssl cert"

The command doesn't really need any storage since there's only a parser,
but since it used this context, there might have been plans for extension,
so better continue with a persistent one. Only old_ckchs, new_ckchs, and
path were being used from the appctx's ssl context. There ones moved to
the local definition, and the two former ones were removed from the appctx
since not used anymore.

3 years agoCLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl cert"
Willy Tarreau [Thu, 5 May 2022 06:15:27 +0000 (08:15 +0200)] 
CLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl cert"

A new entry "state" was added into the commit_cert_ctx struct instead.

3 years agoCLEANUP: ssl/cli: use a local context for "commit ssl cert"
Willy Tarreau [Wed, 4 May 2022 17:58:00 +0000 (19:58 +0200)] 
CLEANUP: ssl/cli: use a local context for "commit ssl cert"

This command only really uses old_ckchs, new_ckchs and next_ckchi
from the appctx's ssl context. The new structure "commit_cert_ctx"
only has these 3 fields, though none could be removed from the shared
ssl context since they're still used by other commands.

3 years agoCLEANUP: ssl/cli: use a local context for "show ssl cert"
Willy Tarreau [Wed, 4 May 2022 17:51:37 +0000 (19:51 +0200)] 
CLEANUP: ssl/cli: use a local context for "show ssl cert"

This command only really uses old_ckchs, cur_ckchs and the index
in which the transaction was stored. The new structure "show_cert_ctx"
only has these 3 fields, and the now unused "cur_ckchs" and "index"
could be removed from the shared ssl context.

3 years agoCLEANUP: ssl/cli: use a local context for "show crlfile"
Willy Tarreau [Wed, 4 May 2022 17:38:57 +0000 (19:38 +0200)] 
CLEANUP: ssl/cli: use a local context for "show crlfile"

Now this command doesn't share any context anymore with "show cafile"
nor with the other commands. The previous "cur_cafile_entry" field from
the applet's ssl context was removed as not used anymore. Everything was
moved to show_crlfile_ctx which only has 3 fields.

3 years agoCLEANUP: ssl/cli: use a local context for "show cafile"
Willy Tarreau [Wed, 4 May 2022 17:26:59 +0000 (19:26 +0200)] 
CLEANUP: ssl/cli: use a local context for "show cafile"

Saying that the layout and usage of the various variables in the ssl
applet context is a mess would be an understatement. It's very hard
to know what command uses what fields, even after having moved away
from the mix of cli and ssl.

Let's extract the parts used by "show cafile" into their own structure.
Only the "show_all" field would be removed from the ssl ctx, the other
fields are still shared with other commands.

3 years agoCLEANUP: hlua/cli: take the hlua_cli context definition out of the appctx
Willy Tarreau [Tue, 3 May 2022 16:13:39 +0000 (18:13 +0200)] 
CLEANUP: hlua/cli: take the hlua_cli context definition out of the appctx

This context is used by CLI keywords registered by Lua. We can take
it out of the appctx and use the generic command context allocation so
that the appctx doesn't have to declare a specific one anymore. The
context is created during parsing.

3 years agoCLEANUP: stats/cli: stop using appctx->st2
Willy Tarreau [Tue, 3 May 2022 16:39:27 +0000 (18:39 +0200)] 
CLEANUP: stats/cli: stop using appctx->st2

Instead, let's have the state as an enum inside the context. It's much
cleaner and safer as we know nobody else touches it.

3 years agoCLEANUP: stats/cli: take the "show stat" context definition out of the appctx
Willy Tarreau [Tue, 3 May 2022 15:08:29 +0000 (17:08 +0200)] 
CLEANUP: stats/cli: take the "show stat" context definition out of the appctx

This makes use of the generic command context allocation so that the
appctx doesn't have to declare a specific one anymore. The context is
created during parsing (both in the CLI and HTTP).

The change looks large but it's particularly mechanical. The context
initialization appears in stats.c and http_ana.c. The context is used
in stats.c and resolvers.c since "show stat resolvers" points there.
That's the reason why the definition moved to stats.h. "show info"
and "show stat" continue to share the same state definition for now.

Nothing else was modified.

3 years agoCLEANUP: promex: stop using appctx->st2
Willy Tarreau [Tue, 3 May 2022 16:05:23 +0000 (18:05 +0200)] 
CLEANUP: promex: stop using appctx->st2

Now that we have out own context, there's no need to use the cryptic st2
struct member. It's solely used to carry a field number here, so let's
add this into the context.

3 years agoCLEANUP: promex: make the applet use its own context
Willy Tarreau [Tue, 3 May 2022 15:33:00 +0000 (17:33 +0200)] 
CLEANUP: promex: make the applet use its own context

The prometheus applet used to map to the stats context since it was not
convenient to have one's own context, and to reuse the fields with its
own values and enums. The obj1 pointer was used both for proxies and
stick-tables; obj2 was used both for servers and listeners.

This change makes use of the generic command context allocation so that
the there's now a properly typed context for prometheus, defined in the
code itself and independent on the stats or appctx ones. For clarity,
the types are correctly set and there's one proxy, one table, one server
and one listener. Some could be compacted using unions but that's not
necessary since the context is reasonably compact. The stats' st_code
field was used as the object state so the new field name is obj_state.

An attempt was made to change the types to const for what us only visited
but some calls pass through the stats code to retrieve info and that code
uses non-const variables due to internal API limitations (read_freq_ctr()
being used and requiring variable). That could change in the future,
though.

3 years agoCLEANUP: cli: initialize the whole appctx->ctx, not just the stats part
Willy Tarreau [Tue, 3 May 2022 15:02:03 +0000 (17:02 +0200)] 
CLEANUP: cli: initialize the whole appctx->ctx, not just the stats part

Historically the CLI was a second access to the stats and we've continued
to initialize only the stats part when initializing the CLI. Let's make
sure we do that on the whole ctx instead. It's probably not more needed
at all nowadays but better stay on the safe side.

3 years agoCLEANUP: peers/cli: remove unneeded state STATE_INIT
Willy Tarreau [Tue, 3 May 2022 13:04:25 +0000 (15:04 +0200)] 
CLEANUP: peers/cli: remove unneeded state STATE_INIT

All the settings in this initial state are konwn at parsing time,
there's no need for an initial state to bootstrap other ones.