]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
2 years agoMINOR: server: add srv->rid (revision id) value
Aurelien DARRAGON [Thu, 17 Nov 2022 15:10:35 +0000 (16:10 +0100)] 
MINOR: server: add srv->rid (revision id) value

With current design, we could not distinguish between
previously existing deleted server and a new server reusing
the deleted server name/id.

This can cause some confusion when auditing stats/events/logs,
because the new server will look similar to the old
one.

To address this, we're adding a new value in server structure: rid

rid (revision id) value is an unsigned 32bits value that is set upon
server creation. Value is derived from a global counter that starts
at 0 and is incremented each time one or multiple server deletions are
followed by a server addition (meaning that old name/id reuse could occur).

Thanks to this revision id, it is now easy to tell whether the server
we're looking at is the same as before or if it has been deleted and
re-added in the meantime.
(combining server name/id + server revision id yields a process-wide unique
identifier)

2 years agoBUG/MEDIIM: stconn: Flush output data before forwarding close to write side
Christopher Faulet [Mon, 5 Dec 2022 06:42:00 +0000 (07:42 +0100)] 
BUG/MEDIIM: stconn: Flush output data before forwarding close to write side

In process_stream(), we wait to have an empty output channel to forward a
close to the write side (a shutw). However, at the stream-connector level,
when a close is detected on one side and we don't want to keep half-close
connections, the shutw is unconditionally forwarded to the write side. This
typically happens on server side.

At first glance, this bug may truncate messages. But depending on the muxes
and the stream states, the bug may be more visible. On recent versions
(2.8-dev and 2.7) and on 2.2 and 2.0, the stream may be freezed, waiting for
the client timeout, if the client mux is unable to forward data because the
client is too slow _AND_ the response channel is not empty _AND_ the server
closes its connection _AND_ the server mux has forwarded all data to the
upper layer _AND_ the client decides to send some data and to close its
connection. On 2.6 and 2.4, it is worst. Instead of a freeze, the client mux
is woken up in loop.

Of course, conditions are pretty hard to meet. Especially because it is highly
time dependent. For what it's worth, I reproduce it with tcploop on client and
server sides and a basic HTTP configuration for HAProxy:

  * client: tcploop -v 8889 C S:"GET / HTTP/1.1\r\nConnection: upgrade\r\n\r\n" P5000 S:"1234567890" K
  * server: tcploop -v 8000 L A R S:"HTTP/1.1 101 ok\r\nConnection: upgrade\r\n\r\n" P2000 S2660000 F R

On 2.8-dev, without this patch, the stream is freezed and when the client
connection timed out, client data are truncated and '--cL' is reported in
logs. With the patch, the client data are forwarded to the server and the
connection is closed. A '--CD' is reported in logs.

It is an old bug. It was probably introduced with the multiplexers. To fix
it, in stconn (Formerly the stream-interface), we must wait all output data
be flushed before forwarding close to write side.

This patch must be backported as far as 2.2 and must be evaluated for 2.0.

2 years agoBUG/MINOR: quic: fix fd leak on startup check quic-conn owned socket
Amaury Denoyelle [Mon, 5 Dec 2022 09:24:54 +0000 (10:24 +0100)] 
BUG/MINOR: quic: fix fd leak on startup check quic-conn owned socket

A startup check is done for first QUIC listener to detect if quic-conn
owned socket is supported by the system. This is done by creating a
dummy socket reusing the listener address. This socket must be closed as
soon as the check is done.

The socket condition is invalid as it excludes zero which is a valid
file-descriptor value. Fix this bug by adjusting this condition.

In theory, this bug could prevent the usage of quic-conn owned socket as
startup check would report a false error. Also, the file-descriptor
would leak as it is not closed. In practice, this cannot happen when
startup check is done after a 'quic4/quic6' listener is instantiated as
file-descriptor are allocated in ascending order by the system.

This should fix github issue #1954.

quic-conn owned socket implementation is scheduled for backport on 2.7.
This commit must be backported with it, more specifically to fix the
following patch :
  75839a44e7e904bd1e332b58bd579e03b6d106f0
  MINOR: quic: startup detect for quic-conn owned socket support

2 years agoBUG/MINOR: ssl: initialize WolfSSL before parsing
William Lallemand [Fri, 2 Dec 2022 16:17:43 +0000 (17:17 +0100)] 
BUG/MINOR: ssl: initialize WolfSSL before parsing

The wolfSSL library need to be initialized before parsing the
configuration which uses some SSL functions.

To be backported in 2.6.

2 years agoBUG/MINOR: ssl: initialize SSL error before parsing
William Lallemand [Fri, 2 Dec 2022 16:06:59 +0000 (17:06 +0100)] 
BUG/MINOR: ssl: initialize SSL error before parsing

The SSL error initialization need to be done before the configuration
parsing, because it uses the SSL.

Need to be backported to 2.6.

2 years agoMINOR: quic: activate socket per conn by default
Amaury Denoyelle [Mon, 21 Nov 2022 10:54:13 +0000 (11:54 +0100)] 
MINOR: quic: activate socket per conn by default

Activate QUIC connection socket to achieve the best performance. The
previous behavior can be reverted by tune.quic.socket-owner
configuration option.

This change is part of quic-conn owned socket implementation.

Contrary to its siblings patches, I suggest to not backport it to 2.7.
This should ensure that stable releases behavior is perserved. If a user
faces issues with QUIC performance on 2.7, he can nonetheless change the
default configuration.

2 years agoMINOR: quic: reconnect quic-conn socket on address migration
Amaury Denoyelle [Thu, 1 Dec 2022 15:20:06 +0000 (16:20 +0100)] 
MINOR: quic: reconnect quic-conn socket on address migration

UDP addresses may change over time for a QUIC connection. When using
quic-conn owned socket, we have to detect address change to break the
bind/connect association on the socket.

For the moment, on change detected, QUIC connection socket is closed and
a new one is opened. In the future, we may improve this by trying to
keep the original socket and reexecute only bind/connect syscalls.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMEDIUM: quic: requeue datagrams received on wrong socket
Amaury Denoyelle [Wed, 5 Oct 2022 15:56:08 +0000 (17:56 +0200)] 
MEDIUM: quic: requeue datagrams received on wrong socket

There is a small race condition when QUIC connection socket is
instantiated between the bind() and connect() system calls. This means
that the first datagram read on the sockets may belong to another
connection.

To detect this rare case, we compare the DCID for each QUIC datagram
read on the QUIC socket. If it does not match the connection CID, the
datagram is requeue using quic_receiver_buf to be able to handle it on
the correct thread.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: mux-quic: rename duplicate function names
Amaury Denoyelle [Thu, 24 Nov 2022 09:51:19 +0000 (10:51 +0100)] 
MINOR: mux-quic: rename duplicate function names

qc_rcv_buf and qc_snd_buf are names used for static functions in both
quic-sock and quic-mux. To remove this ambiguity, slightly modify names
used in MUX code.

In the future, we should properly define a unique prefix for all QUIC
MUX functions to avoid such problem in the future.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMEDIUM: quic: move receive out of FD handler to quic-conn io-cb
Amaury Denoyelle [Wed, 16 Nov 2022 10:01:02 +0000 (11:01 +0100)] 
MEDIUM: quic: move receive out of FD handler to quic-conn io-cb

This change is the second part for reception on QUIC connection socket.
All operations inside the FD handler has been delayed to quic-conn
tasklet via the new function qc_rcv_buf().

With this change, buffer management on reception has been simplified. It
is now possible to use a local buffer inside qc_rcv_buf() instead of
quic_receiver_buf().

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMEDIUM: quic: use quic-conn socket for reception
Amaury Denoyelle [Mon, 24 Oct 2022 15:40:37 +0000 (17:40 +0200)] 
MEDIUM: quic: use quic-conn socket for reception

Try to use the quic-conn socket for reception if it is allocated. For
this, the socket is inserted in the fdtab. This will call the new
handler quic_conn_io_cb() which is responsible to process the recv()
system call. It will reuse datagram dispatch for simplicity. However,
this is guaranteed to be called on the quic-conn thread, so it will be
more efficient to use a dedicated buffer. This will be implemented in
another commit.

This patch should improve performance by reducing contention on the
receiver socket. However, more gain can be obtained when the datagram
dispatch operation will be skipped.

Older quic_sock_fd_iocb() is renamed to quic_lstnr_sock_fd_iocb() to
emphasize its usage for the receiver socket.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: use connection socket for emission
Amaury Denoyelle [Mon, 21 Nov 2022 13:48:57 +0000 (14:48 +0100)] 
MINOR: quic: use connection socket for emission

If quic-conn has a dedicated socket, use it for sending over the
listener socket. This should improve performance by reducing contention
over the shared listener socket.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: allocate a socket per quic-conn
Amaury Denoyelle [Mon, 24 Oct 2022 15:08:43 +0000 (17:08 +0200)] 
MINOR: quic: allocate a socket per quic-conn

Allocate quic-conn owned socket if possible. This requires that this is
activated in haproxy configuration. Also, this is done only if local
address is known so it depends on the support of IP_PKTINFO.

For the moment this socket is not used. This causes QUIC support to be
broken as received datagram are not read. This commit will be completed
by a following patch to support recv operation on the newly allocated
socket.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: define config option for socket per conn
Amaury Denoyelle [Fri, 18 Nov 2022 16:42:16 +0000 (17:42 +0100)] 
MINOR: quic: define config option for socket per conn

Define global configuration option "tune.quic.socket-owner". This option
can be used to activate or not socket per QUIC connection mode. The
default value is "listener" which disable this feature. It can be
activated with the option "connection".

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: test IP_PKTINFO support for quic-conn owned socket
Amaury Denoyelle [Thu, 1 Dec 2022 13:51:16 +0000 (14:51 +0100)] 
MINOR: quic: test IP_PKTINFO support for quic-conn owned socket

Extend the startup platform detection support test for quic-conn owned
socket. It is required to be able to retrieve destination address on a
recvfrom() system call so check if IP_PKTINFO or IP_RECVDSTADDR flags
are supported.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: startup detect for quic-conn owned socket support
Amaury Denoyelle [Mon, 21 Nov 2022 09:04:14 +0000 (10:04 +0100)] 
MINOR: quic: startup detect for quic-conn owned socket support

To be able to use individual sockets for QUIC connections, we rely on
the OS network stack which must support UDP sockets binding on the same
local address.

Add a detection code for this feature executed on startup. When the
first QUIC listener socket is binded, a test socket is created and
binded on the same address. If the bind call fails, we consider that
it's impossible to use individual socket for QUIC connections.

A new global option GTUNE_QUIC_SOCK_PER_CONN is defined. If startup
detect fails, this value is resetted from global options. For the
moment, there is no code to activate the option : this will be in a
follow-up patch with the introduction of a new configuration option.

This change is part of quic-conn owned socket implementation.
It may be backported to 2.7 after a period of observation.

2 years agoMINOR: quic: ignore address migration during handshake
Amaury Denoyelle [Mon, 21 Nov 2022 10:14:45 +0000 (11:14 +0100)] 
MINOR: quic: ignore address migration during handshake

QUIC protocol support address migration which allows to maintain the
connection even if client has changed its network address. This is done
through address migration.

RFC 9000 stipulates that address migration is forbidden before handshake
has been completed. Add a check for this : drop silently every datagram
if client network address has changed until handshake completion.

This commit is one of the first steps towards QUIC connection migration
support.

This should be backported up to 2.7.

2 years agoMINOR: quic: detect connection migration
Amaury Denoyelle [Fri, 2 Dec 2022 08:57:32 +0000 (09:57 +0100)] 
MINOR: quic: detect connection migration

Detect connection migration attempted by the client. This is done by
comparing addresses stored in quic-conn with src/dest addresses of the
UDP datagram.

A new function qc_handle_conn_migration() has been added. For the
moment, no operation is conducted and the function will be completed
during connection migration implementation. The only notable things is
the increment of a new counter "quic_conn_migration_done".

This should be backported up to 2.7.

2 years agoMINOR: tools: add port for ipcmp as optional criteria
Amaury Denoyelle [Thu, 1 Dec 2022 16:46:45 +0000 (17:46 +0100)] 
MINOR: tools: add port for ipcmp as optional criteria

Complete ipcmp() function with a new argument <check_port>. If this
argument is true, the function will compare port values besides IP
addresses and return true only if both are identical.

This commit will simplify QUIC connection migration detection. As such,
it should be backported to 2.7.

2 years agoMINOR: quic: extract datagram parsing code
Amaury Denoyelle [Tue, 27 Sep 2022 12:22:09 +0000 (14:22 +0200)] 
MINOR: quic: extract datagram parsing code

Extract individual datagram parsing code outside of datagrams list loop
in quic_lstnr_dghdlr(). This is moved in a new function named
quic_dgram_parse().

To complete this change, quic_lstnr_dghdlr() has been moved into
quic_sock source file : it belongs to QUIC socket lower layer and is
directly called by quic_sock_fd_iocb().

This commit will ease implementation of quic-conn owned socket.
New function quic_dgram_parse() will be easily usable after a receive
operation done on quic-conn IO-cb.

This should be backported up to 2.7.

2 years agoMINOR: quic: complete traces in qc_rx_pkt_handle()
Amaury Denoyelle [Thu, 24 Nov 2022 16:15:08 +0000 (17:15 +0100)] 
MINOR: quic: complete traces in qc_rx_pkt_handle()

Add missing ENTER trace for qc_rx_pkt_handle() function. LEAVE traces
are already present.

This should be backported up to 2.7.

2 years agoMINOR: quic: remove qc from quic_rx_packet
Amaury Denoyelle [Thu, 24 Nov 2022 16:12:25 +0000 (17:12 +0100)] 
MINOR: quic: remove qc from quic_rx_packet

quic_rx_packet struct had a reference to the quic_conn instance. This is
useless as qc instance is always passed through function argument. In
fact, pkt.qc is used only in qc_pkt_decrypt() on key update, even though
qc is also passed as argument.

Simplify this by removing qc field from quic_rx_packet structure
definition. Also clean up qc_pkt_decrypt() documentation and interface
to align it with other quic-conn related functions.

This should be backported up to 2.7.

2 years agoMEDIUM: ssl: rename the struct "cert_key_and_chain" to "ckch_data"
William Lallemand [Tue, 22 Nov 2022 10:51:53 +0000 (11:51 +0100)] 
MEDIUM: ssl: rename the struct "cert_key_and_chain" to "ckch_data"

Rename the structure "cert_key_and_chain" to "ckch_data" in order to
avoid confusion with the store whcih often called "ckchs".

The "cert_key_and_chain *ckch" were renamed "ckch_data *data", so we now
have store->data instead of ckchs->ckch.

Marked medium because it changes the API.

2 years agoDOC/MINOR: api: add documentation for event_hdl feature
Aurelien DARRAGON [Wed, 16 Nov 2022 17:06:34 +0000 (18:06 +0100)] 
DOC/MINOR: api: add documentation for event_hdl feature

This is an initial work for the dedicated
event handler API internal documentation.

The file is located at doc/internals/api/event_hdl.txt

event_hdl feature has been introduced with:
MINOR: event_hdl: add event handler base api

2 years agoMINOR: event_hdl: add event handler base api
Aurelien DARRAGON [Wed, 16 Nov 2022 17:06:28 +0000 (18:06 +0100)] 
MINOR: event_hdl: add event handler base api

Adding base code to provide subscribe/publish API for internal
events processing.

event_hdl provides two complementary APIs, both are implemented
in src/event_hdl.c and include/haproxy/event_hdl{-t.h,.h}:

One API targeting developers that want to register event handlers
that will be notified on specific events.
(SUBSCRIBE)

One API targeting developers that want to notify registered handlers
about an event.
(PUBLISH)

This feature is being considered to address the following scenarios:
- mailers code refactoring (getting rid of deprecated
tcp-check ruleset implementation)
- server events from lua code (registering user defined
lua function that is executed with relevant data when a
server is dynamically added/removed or on server state change)
- providing a stable and easy to use API for upcoming
developments that rely on specific events to perform actions.
(e.g: ressource cleanup when a server is deleted from haproxy)

At this time though, we don't have much use cases in mind in addition to
server events handling, but the API is aimed at being multipurpose
so that new event families, with their own particularities, can be
easily implemented afterwards (and hopefully) without requiring breaking
changes to the API.

Moreover, you should know that the API was not designed to cope well
with high rate event publishing.
Mostly because publishing means iterating over unsorted subscriber list.
So it won't scale well as subscriber list increases, but it is intended in
order to keep the code simple and versatile.

Instead, it is assumed that events implemented using this API
should be periodic events, and that events related to critical
io/networking processing should be handled using
dedicated facilities anyway.
(After all, this is meant to be a general purpose event API)

Apart from being easily extensible, one of the main goals of this API is
to make subscriber code as simple and safe as possible.

This is done by offering multiple event handling modes:
- SYNC mode:
publishing code directly
leverages handler code (callback function)
and handler code has a direct access to "live" event data
(pointers mostly, alongside with lock hints/context
so that accessing data pointers can be done properly)
- normal ASYNC mode:
handler is executed in a backward compatible way with sync mode,
so that it is easy to switch from and to SYNC/ASYNC mode.
Only here the handler has access to "offline" event data, and
not "live" data (ptrs) so that data consistency is guaranteed.
By offline, you should understand "snapshot" of relevant data
at the time of the event, so that the handler can consume it
later (even if associated ressource is not valid anymore)
- advanced ASYNC mode
same as normal ASYNC mode, but here handler is not a function
that is executed with event data passed as argument: handler is a
user defined tasklet that is notified when event occurs.
The tasklet may consume pending events and associated data
through its own message queue.

ASYNC mode should be considered first if you don't rely on live event
data and you wan't to make sure that your code has the lowest impact
possible on publisher code. (ie: you don't want to break stuff)

Internal API documentation will follow:
You will find more details about the notions we roughly approached here.

2 years agoLICENSE: wurfl: clarify the dummy library license.
scientiamobile [Thu, 1 Dec 2022 16:21:10 +0000 (17:21 +0100)] 
LICENSE: wurfl: clarify the dummy library license.

This clarifies that LGPL is also permitted for the wurfl.h dummy file.
Should be backported where relevant.

Signed-off-by: Luca Passani <luca.passani@scientiamobile.com>
2 years agoMINOR: debug: add a balance of alloc - free at the end of the memstats dump
Willy Tarreau [Wed, 30 Nov 2022 16:16:51 +0000 (17:16 +0100)] 
MINOR: debug: add a balance of alloc - free at the end of the memstats dump

When digging into suspected memory leaks, it's cumbersome to count the
number of allocations and free calls. Here we're adding a summary at the
end of the sum of allocs minus the sum of frees, excluding realloc since
we can't know how much it releases upon each call. This means that when
doing many realloc+free the count may be negative but in practice there
are very few reallocs so that's not a problem. Also the size/call is signed
and corresponds to the average size allocated (e.g. leaked) per call.

It seems to work reasonably well for now:

  > debug dev memstats match buf
  quic_conn.c:2978       P_FREE  size:   1239547904  calls:     75656  size/call:  16384 buffer
  quic_conn.c:2960      P_ALLOC  size:   1239547904  calls:     75656  size/call:  16384 buffer
  mux_quic.c:393        P_ALLOC  size:   9112780800  calls:    556200  size/call:  16384 buffer
  mux_quic.c:383        P_ALLOC  size:  17783193600  calls:   1085400  size/call:  16384 buffer
  mux_quic.c:159         P_FREE  size:   8935833600  calls:    545400  size/call:  16384 buffer
  mux_quic.c:142         P_FREE  size:   9112780800  calls:    556200  size/call:  16384 buffer
  h3.c:776              P_ALLOC  size:   8935833600  calls:    545400  size/call:  16384 buffer
  quic_stream.c:166      P_FREE  size:    975241216  calls:     59524  size/call:  16384 buffer
  quic_stream.c:127      P_FREE  size:   7960592384  calls:    485876  size/call:  16384 buffer
  stream.c:772           P_FREE  size:      8798208  calls:       537  size/call:  16384 buffer
  stream.c:768           P_FREE  size:      2424832  calls:       148  size/call:  16384 buffer
  stream.c:751          P_ALLOC  size:   8852062208  calls:    540287  size/call:  16384 buffer
  stream.c:641           P_FREE  size:   8849162240  calls:    540110  size/call:  16384 buffer
  stream.c:640           P_FREE  size:   8847360000  calls:    540000  size/call:  16384 buffer
  channel.h:850         P_ALLOC  size:      2441216  calls:       149  size/call:  16384 buffer
  channel.h:850         P_ALLOC  size:      5914624  calls:       361  size/call:  16384 buffer
  dynbuf.c:55            P_FREE  size:        32768  calls:         2  size/call:  16384 buffer
  Total                 BALANCE  size:            0  calls:   5606906  size/call:      0 (excl. realloc)

Let's see how useful this becomes over time.

2 years agoMINOR: debug: support pool filtering on "debug dev memstats"
Willy Tarreau [Wed, 30 Nov 2022 15:42:54 +0000 (16:42 +0100)] 
MINOR: debug: support pool filtering on "debug dev memstats"

Sometimes when debugging it's convenient to be able to focus only on
certain pools. Just like we did for "show pools", let's add a filter
based on a prefix on "debug dev memstats match <prefix>".

2 years agoMEDIUM: 51d: add support for 51Degrees V4 with Hash algorithm
Dragan Dosen [Mon, 14 Feb 2022 12:05:45 +0000 (13:05 +0100)] 
MEDIUM: 51d: add support for 51Degrees V4 with Hash algorithm

This patch also adds a set of new global options:

- 51degrees-use-performance-graph { on | off }
- 51degrees-use-predictive-graph { on | off }
- 51degrees-drift <number>
- 51degrees-difference <number>
- 51degrees-allow-unmatched { on | off }

To build using the latest 51Degrees V4 engine with Hash algorithm, set
USE_51DEGREES_V4=1.

Other supported build options are 51DEGREES_INC, 51DEGREES_LIB and
51DEGREES_SRC which needs to be set to the directory that contains
headers and C files. For example:

make TARGET=<target> USE_51DEGREES_V4=1 51DEGREES_SRC='51D_REPO_PATH'/src

2 years ago[RELEASE] Released version 2.8-dev0 v2.8-dev0
Willy Tarreau [Thu, 1 Dec 2022 14:25:34 +0000 (15:25 +0100)] 
[RELEASE] Released version 2.8-dev0

Released version 2.8-dev0 with the following main changes :
    - MINOR: version: mention that it's development again

2 years agoMINOR: version: mention that it's development again
Willy Tarreau [Thu, 1 Dec 2022 14:23:12 +0000 (15:23 +0100)] 
MINOR: version: mention that it's development again

This essentially reverts d705b85a4a43e9be5c99796e2b83197b42d6918e.

2 years ago[RELEASE] Released version 2.7.0 v2.7.0
Willy Tarreau [Thu, 1 Dec 2022 14:16:46 +0000 (15:16 +0100)] 
[RELEASE] Released version 2.7.0

Released version 2.7.0 with the following main changes :
    - MINOR: ssl: forgotten newline in error messages on ca-file
    - BUG/MINOR: ssl: shut the ca-file errors emitted during httpclient init
    - DOC: config: provide some configuration hints for "http-reuse"
    - DOC: config: refer to section about quoting in the "add_item" converter
    - DOC: halog: explain how to use -ac and -ad in the help message
    - DOC: config: clarify the fact that SNI should not be used in HTTP scenarios
    - DOC: config: mention that a single monitor-uri rule is supported
    - DOC: config: explain how default matching method for ACL works
    - DOC: config: clarify the fact that "retries" is not just for connections
    - BUILD: halog: fix missing double-quote at end of help line
    - DOC: config: clarify the -m dir and -m dom pattern matching methods
    - MINOR: activity: report uptime in "show activity"
    - REORG: activity/cli: move the "show activity" handler to activity.c
    - DEV: poll: add support for epoll
    - DEV: tcploop: centralize the polling code into wait_for_fd()
    - DEV: tcploop: add support for POLLRDHUP when supported
    - DEV: tcploop: do not report an error on POLLERR
    - DEV: tcploop: add optional support for epoll
    - SCRIPTS: announce-release: add a link to the data plane API
    - CLEANUP: stick-table: fill alignment holes in the stktable struct
    - MINOR: stick-table: store a per-table hash seed and use it
    - MINOR: stick-table: show the shard number in each entry's "show table" output
    - CLEANUP: ncbuf: remove ncb_blk args by value
    - CLEANUP: ncbuf: inline small functions
    - CLEANUP: ncbuf: use standard BUG_ON with DEBUG_STRICT
    - BUG/MINOR: quic: Endless loop during retransmissions
    - MINOR: mux-h2: add the expire task and its expiration date in "show fd"
    - BUG/MINOR: peers: always initialize the stksess shard value
    - REGTESTS: fix peers-related regtests regarding "show table"
    - BUG/MEDIUM: mux-h1: Close client H1C on EOS when there is no output data
    - MINOR: stick-table: change the API of the function used to calculate the shard
    - CLEANUP: peers: factor out the key len calculation in received updates
    - BUG/MINOR: peers: always update the stksess shard number on incoming updates
    - CLEANUP: assorted typo fixes in the code and comments
    - MINOR: mux-h1: add the expire task and its expiration date in "show fd"
    - MINOR: debug: improve error handling on the memstats command parser
    - BUILD: quic: allow build with USE_QUIC and USE_OPENSSL_WOLFSSL
    - CLEANUP: anon: clarify the help message on "debug dev hash"
    - MINOR: debug: relax access restrictions on "debug dev hash" and "memstats"
    - SCRIPTS: run-regtests: add a version check
    - MINOR: version: mention that it's stable now

2 years agoMINOR: version: mention that it's stable now
Willy Tarreau [Thu, 1 Dec 2022 14:15:24 +0000 (15:15 +0100)] 
MINOR: version: mention that it's stable now

This version will be maintained up to around Q1 2024. The INSTALL file
also mentions it.

2 years agoSCRIPTS: run-regtests: add a version check
Willy Tarreau [Wed, 30 Nov 2022 17:44:33 +0000 (18:44 +0100)] 
SCRIPTS: run-regtests: add a version check

It happens from time to time while switching between branches and/or
updating after someone else's changes that regtests are run by accident
on the wrong binary, typically the one the tests were run on during
development and not with the latest adaptations. And obviously it's
when this happens that we break the CI. There are various causes to
this but they all come down to humans context-switching a lot, and
there's no real fix for this that doesn't add even more burden hence
increases the overhead. However we can help the human detect such
mistakes very easily.

This change here will compare the version of the haproxy binary to
the version of the tree, and will emit a warning in the regtest output
if they do not match, regardless of the outcome of the test. This is
sufficient in case of failures because these are quickly glanced over,
and is sufficient as well in case of accidental success because the
warning is the last message. E.g:

  ########################## Starting vtest ##########################
  Testing with haproxy version: 2.7-dev10-cfcdbc-38
  Warning: version does not match the current tree (2.7-dev10-111c78-39)
  0 tests failed, 0 tests skipped, 182 tests passed

This should not affect builds made out of a git tree because the version
is retrieved using "make version", or exactly the same way as it's passd
to the haproxy binary. We just need to know what "make" command to run,
so $MAKE is used primarily, falling back to "make" then to "gmake". In
case all of these fail, we just ignore the version check. This should be
sufficient to catch human mistakes without affecting the CI.

2 years agoMINOR: debug: relax access restrictions on "debug dev hash" and "memstats"
Willy Tarreau [Wed, 30 Nov 2022 16:51:47 +0000 (17:51 +0100)] 
MINOR: debug: relax access restrictions on "debug dev hash" and "memstats"

These two have absolutely zero impact on the process and do not need to
be restricted to the expert mode. The first one calculates a string hash
that can be used by anyone when checking a dump; the second one may be
used by anyone tracking a memory leak, and is cumbersome to use due to
the "expert-mode on" that needs to be prepended. In addition this gives
bad habits to users and needlessly taints the process. So let's drop
this restriction for these two commands.

2 years agoCLEANUP: anon: clarify the help message on "debug dev hash"
Willy Tarreau [Wed, 30 Nov 2022 16:47:08 +0000 (17:47 +0100)] 
CLEANUP: anon: clarify the help message on "debug dev hash"

This command is used to hash a section name using the current anon key,
it was brought in 2.7 by commit 54966dffd ("MINOR: anon: store the
anonymizing key in the CLI's appctx"). However the help message only
says "return msg hashed" which is misleading because if anon mode is
not enabled, it returns the string as-is. Let's just mention this
condition in the help message, and also fix the alphabetical ordering
and alignment on the line.

2 years agoBUILD: quic: allow build with USE_QUIC and USE_OPENSSL_WOLFSSL
Stefan Eissing [Wed, 30 Nov 2022 14:16:38 +0000 (15:16 +0100)] 
BUILD: quic: allow build with USE_QUIC and USE_OPENSSL_WOLFSSL

WolfSSL does not implement the TLS1_3_CK_AES_128_CCM_SHA256 cipher as
well as the SSL_ERROR_WANT_ASYNC, SSL_ERROR_WANT_ASYNC_JOB and
SSL_ERROR_WANT_CLIENT_HELLO_CB error codes.

This patch disables them for WolfSSL.

Signed-off-by: William Lallemand <wlallemand@haproxy.org>
2 years agoMINOR: debug: improve error handling on the memstats command parser
Willy Tarreau [Wed, 30 Nov 2022 15:50:48 +0000 (16:50 +0100)] 
MINOR: debug: improve error handling on the memstats command parser

"debug dev memstats" supports various options but silently ignores the
unknown ones. Let's make sure it returns indications about what it
expects, as the help message is quite limited otherwise.

2 years agoMINOR: mux-h1: add the expire task and its expiration date in "show fd"
Christopher Faulet [Wed, 30 Nov 2022 13:49:56 +0000 (14:49 +0100)] 
MINOR: mux-h1: add the expire task and its expiration date in "show fd"

Just like for the H2 multiplexer, info about the H1 connection task is now
displayed in "show fd" output. The task pointer is displayed and, if not
null, its expiration date.

It may be useful to backport it.

2 years agoCLEANUP: assorted typo fixes in the code and comments
Ilya Shipitsin [Wed, 30 Nov 2022 11:22:42 +0000 (16:22 +0500)] 
CLEANUP: assorted typo fixes in the code and comments

This is 33rd iteration of typo fixes

2 years agoBUG/MINOR: peers: always update the stksess shard number on incoming updates
Willy Tarreau [Tue, 29 Nov 2022 17:01:28 +0000 (18:01 +0100)] 
BUG/MINOR: peers: always update the stksess shard number on incoming updates

If shards are in use, we must fill the shard number on incoming updates,
otherwise some entries are assigned shard number zero, and may be broadcast
everywhere once updated, instead of being sent only to the peers having the
same shard number.

This fixes commit 36d156564 ("MINOR: peers: Support for peer shards"). No
backport is needed.

2 years agoCLEANUP: peers: factor out the key len calculation in received updates
Willy Tarreau [Tue, 29 Nov 2022 16:43:10 +0000 (17:43 +0100)] 
CLEANUP: peers: factor out the key len calculation in received updates

In peer_treat_updatemsg(), the lower layers of the stick-table code are
reimplemented, and the key length is never really known for an entry
being processed, it depends on the type being parsed and the moment
where it's done. This makes it quite difficult to stuff some shard
number calculation there.

This patch adds a keylen local variable that is always set to the length
of the current key depending on its type. It takes this opportunity for
reducing redudant expressions involving this length and always using the
new variable instead, limiting the risk of errors. Arguably that code
would have been way simpler by creating a dummy stktable_key and passing
it to stksess_new() as done anywhere else, but let's not change all that
a few days before the release.

2 years agoMINOR: stick-table: change the API of the function used to calculate the shard
Willy Tarreau [Tue, 29 Nov 2022 16:36:44 +0000 (17:36 +0100)] 
MINOR: stick-table: change the API of the function used to calculate the shard

The function used to calculate the shard number currently requires a
stktable_key on input for this. Unfortunately, it happens that peers
currently miss this calculation and they do not provide stktable_key
at all, instead they're open-coding all the low-level stick-table work
(hence why it's missing). Thus we'll need to be able to calculate the
shard number in keys coming from peers as well but the current API does
not make it possible.

This commit addresses this by inverting the order where the length and
the shard number are used. Now the low-level function is independent on
stksess and stktable_key, it takes a table, pointer and length and does
all the job. The upper function takes care of the type and key to get
the its length, and is for use only from stick-table code.

This doesn't change anything except that the low-level one will be usable
from outside (hence why it's exported now).

2 years agoBUG/MEDIUM: mux-h1: Close client H1C on EOS when there is no output data
Christopher Faulet [Tue, 29 Nov 2022 16:16:30 +0000 (17:16 +0100)] 
BUG/MEDIUM: mux-h1: Close client H1C on EOS when there is no output data

If the client closes the connection while there is no pending outgoing data,
the H1 connection must be released. However, it was switched to CLOSING
state instead. Thus the client connection was closed on client timeout.

It is side effect of the commif d1b573059a ("MINOR: mux-h1: Avoid useless
call to h1_send() if no error is sent"). Before, the extra call to h1_send()
was able to fix the H1C state.

To fix the bug and make switch to close state (CLOSING or CLOSED) less
errorprone, h1_close() helper function is systematically used.

It is a 2.7-specific bug. No backport needed.

2 years agoREGTESTS: fix peers-related regtests regarding "show table"
Willy Tarreau [Tue, 29 Nov 2022 15:29:12 +0000 (16:29 +0100)] 
REGTESTS: fix peers-related regtests regarding "show table"

When I added commit 16b282f4b ("MINOR: stick-table: show the shard
number in each entry's "show table" output"), I don't know how but
I managed to mess up my reg tests since everything worked fine,
most likely by running it on a binary built in the wrong branch.
Several reg tests include some table outputs that were upset by the
new "shard=" field. This test added them and revealed at the same
time that entries learned over peers are not properly initialized,
which will be fixed in a future series of fixes.

This commit requires previous fix "BUG/MINOR: peers: always
initialize the stksess shard value" so as not to trip on entries
learned from peers.

2 years agoBUG/MINOR: peers: always initialize the stksess shard value
Willy Tarreau [Tue, 29 Nov 2022 15:08:35 +0000 (16:08 +0100)] 
BUG/MINOR: peers: always initialize the stksess shard value

We need to initialize the shard value in __stksess_init() because there is
not necessarily a key to make it happen later, resulting in an uninitialized
shard value appearing in the entry, typically when entries are learned from
peers. This fixes commit 36d156564 ("MINOR: peers: Support for peer shards"),
no backport is needed.

Note however that it is not sufficient to completely fix the peers code, the
shard value remains zero because the setting of the key was open-coded in
the peers code and these parts were not identified when adding support for
shards.

2 years agoMINOR: mux-h2: add the expire task and its expiration date in "show fd"
Willy Tarreau [Tue, 29 Nov 2022 14:26:43 +0000 (15:26 +0100)] 
MINOR: mux-h2: add the expire task and its expiration date in "show fd"

Some issues such as #1929 seem to involve a task without timeout but we
can't find the condition to reproduce this in the code. However, not having
this info in the output doesn't help, so this patch adds the task pointer
and its timeout (when the task is non-null). It may be useful to backport
it.

2 years agoBUG/MINOR: quic: Endless loop during retransmissions
Frédéric Lécaille [Mon, 28 Nov 2022 16:21:45 +0000 (17:21 +0100)] 
BUG/MINOR: quic: Endless loop during retransmissions

qc_dgrams_retransmit() could reuse the same local list and could splice it two
times to the packet number space list of frame to be send/resend. This creates a
loop in this list and makes qc_build_frms() possibly endlessly loop when trying
to build frames from the packet number space list of frames. Then haproxy aborts.

This issue could be easily reproduced patching qc_build_frms() function to set <dlen>
variable value to 0 after having built at least 10 CRYPTO frames and using ngtcp2
as client with 30% packet loss in both direction.

Thank you to @gabrieltz for having reported this issue in GH #1903.

Must be backported to 2.6.

2 years agoCLEANUP: ncbuf: use standard BUG_ON with DEBUG_STRICT
Amaury Denoyelle [Mon, 28 Nov 2022 14:10:30 +0000 (15:10 +0100)] 
CLEANUP: ncbuf: use standard BUG_ON with DEBUG_STRICT

ncbuf can be compiled for haproxy or standalone to run unit test suite.
For the latest mode, BUG_ON() macro has been re-implemented in a simple
version.

The inclusion of the default or the redefined macro relied on DEBUG_DEV.
Change this to now rely on DEBUG_STRICT as this is activated for the
default build.

This change is safe as only BUG_ON_HOT() macro is used in ncbuf code,
which is activated only with the default value DEBUG_STRICT=2.

This should be backported up to 2.6.

2 years agoCLEANUP: ncbuf: inline small functions
Amaury Denoyelle [Mon, 28 Nov 2022 14:08:14 +0000 (15:08 +0100)] 
CLEANUP: ncbuf: inline small functions

ncbuf API relies on lot of small functions. Mark these functions as
inline to reduce call invocations and facilitate compiler optimizations
to reduce code size.

This should be backported up to 2.6.

2 years agoCLEANUP: ncbuf: remove ncb_blk args by value
Amaury Denoyelle [Mon, 28 Nov 2022 10:06:42 +0000 (11:06 +0100)] 
CLEANUP: ncbuf: remove ncb_blk args by value

ncb_blk structure is used to represent a block of data or a gap in a
non-contiguous buffer. This is used in several functions for ncbuf
implementation. Before this patch, ncb_blk was passed by value, which is
sub-optimal. Replace this by const pointer arguments.

This has the side-effect of suppressing a compiler warning reported in
older GCC version :
  CC      src/http_conv.o
  src/ncbuf.c: In function 'ncb_blk_next':
  src/ncbuf.c:170: warning: 'blk.end' may be used uninitialized in this function

This should be backported up to 2.6.

2 years agoMINOR: stick-table: show the shard number in each entry's "show table" output
Willy Tarreau [Tue, 29 Nov 2022 10:55:18 +0000 (11:55 +0100)] 
MINOR: stick-table: show the shard number in each entry's "show table" output

Stick-tables support sharding to multiple peers but there was no way to
know to what shard an entry was going to be sent. Let's display this in
the "show table" output to ease debugging.

2 years agoMINOR: stick-table: store a per-table hash seed and use it
Willy Tarreau [Mon, 28 Nov 2022 17:53:06 +0000 (18:53 +0100)] 
MINOR: stick-table: store a per-table hash seed and use it

Instead of using memcpy() to concatenate the table's name to the key when
allocating an stksess, let's compute once for all a per-table seed at boot
time and use it to calculate the key's hash. This saves two memcpy() and
the usage of a chunk, it's always nice in a fast path.

When tested under extreme conditions with a 80-byte long table name, it
showed a 1% performance increase.

2 years agoCLEANUP: stick-table: fill alignment holes in the stktable struct
Willy Tarreau [Mon, 28 Nov 2022 17:48:11 +0000 (18:48 +0100)] 
CLEANUP: stick-table: fill alignment holes in the stktable struct

There were two 32-bit holes in the stktable struct surrounding 32-bit
words, so let's just reorder them a little bit to address the issue.

2 years agoSCRIPTS: announce-release: add a link to the data plane API
Willy Tarreau [Mon, 28 Nov 2022 06:22:46 +0000 (07:22 +0100)] 
SCRIPTS: announce-release: add a link to the data plane API

Since Marko announced at HAProxyConf 2022 that the data plane API is
mostly complete and will now follow the same release cycle as haproxy
starting with 2.7, it's probably the right moment to encourage users
to start trying it so that we can hope to migrate all the painful
discovery stuff there in a not too distant future.

Let's just point to the latest release for now. We'll see in the future
if we need to adapt the link depending on the branch.

2 years agoDEV: tcploop: add optional support for epoll
Willy Tarreau [Fri, 25 Nov 2022 16:05:05 +0000 (17:05 +0100)] 
DEV: tcploop: add optional support for epoll

When -e is passed, epoll is used instead of poll. The FD is added
then removed around the call to epoll_wait() so that we don't need
to track it. The only purpose is to compare events reported by each
syscall.

2 years agoDEV: tcploop: do not report an error on POLLERR
Willy Tarreau [Fri, 25 Nov 2022 16:04:05 +0000 (17:04 +0100)] 
DEV: tcploop: do not report an error on POLLERR

Actually this breaks certain client tests where the server closes with
RST, it prevents from reading the final data so better not abort on
that.

2 years agoDEV: tcploop: add support for POLLRDHUP when supported
Willy Tarreau [Fri, 25 Nov 2022 15:15:20 +0000 (16:15 +0100)] 
DEV: tcploop: add support for POLLRDHUP when supported

This is just in order to closer match what haproxy does.

2 years agoDEV: tcploop: centralize the polling code into wait_for_fd()
Willy Tarreau [Fri, 25 Nov 2022 15:05:46 +0000 (16:05 +0100)] 
DEV: tcploop: centralize the polling code into wait_for_fd()

There are multiple call places for poll(), let's first centralize them
to make it easier to enhance it. All callers now use the wait_for_fd()
function which was extended to take a timeout and which can return the
indication that an error was seen.

2 years agoDEV: poll: add support for epoll
Willy Tarreau [Fri, 25 Nov 2022 15:34:11 +0000 (16:34 +0100)] 
DEV: poll: add support for epoll

When called with -e, epoll is used instead of poll. The poller does
very little in this code (just checks for any event without waiting) but
that's sufficient to see return values.

2 years agoREORG: activity/cli: move the "show activity" handler to activity.c
Willy Tarreau [Fri, 25 Nov 2022 14:32:38 +0000 (15:32 +0100)] 
REORG: activity/cli: move the "show activity" handler to activity.c

Initially the code was placed into cli.c to keep activity.c small and
independent of the cli stuff, but that's no longer the case anyway and
keeping that code over there makes it harder to find. Let's move it to
its more natural place now.

2 years agoMINOR: activity: report uptime in "show activity"
Willy Tarreau [Fri, 25 Nov 2022 14:36:48 +0000 (15:36 +0100)] 
MINOR: activity: report uptime in "show activity"

It happened a few times that it was difficult to figure if a counter was
normal or not in "show activity" based on the uptime. Let's just emit the
uptime value along with the date.

2 years agoDOC: config: clarify the -m dir and -m dom pattern matching methods
Willy Tarreau [Fri, 25 Nov 2022 11:02:25 +0000 (12:02 +0100)] 
DOC: config: clarify the -m dir and -m dom pattern matching methods

There's regularly some confusion about them (do they match at the
beginning, end ? do they support multiple components etc). Tim
suggested to improve the doc in issue #61, it's never too late, so
let's do it now wih a few examples.

2 years agoBUILD: halog: fix missing double-quote at end of help line
Willy Tarreau [Fri, 25 Nov 2022 10:10:19 +0000 (11:10 +0100)] 
BUILD: halog: fix missing double-quote at end of help line

This will tell me to change the line format after testing :-(
This was introduced with commit 286199c24 ("DOC: halog: explain how to
use -ac and -ad in the help message"), no backport is needed unless it's
backported as well.

2 years agoDOC: config: clarify the fact that "retries" is not just for connections
Willy Tarreau [Fri, 25 Nov 2022 10:06:20 +0000 (11:06 +0100)] 
DOC: config: clarify the fact that "retries" is not just for connections

In issue #412 it was rightfully reported that the wording in "retries"
still exclusively speaks about connection attempts, while since L7
retries with "retry-on" it's no longer a limitation. Let's update the
text.

2 years agoDOC: config: explain how default matching method for ACL works
Willy Tarreau [Fri, 25 Nov 2022 09:49:41 +0000 (10:49 +0100)] 
DOC: config: explain how default matching method for ACL works

In issue #698, it's made apparent that the default matching method for
ACL keywords can be confusing when a converter is applied, because
depending on the converters used, users may think that the default
matching method from the sample fetch name might apply to the whole
expression. It's easier to understand that this doesn't make sense
when thinking about converters turning to completely different types
(e.g. hdr_beg(host),do_resolve() returns an IP, thus it's obvious
that _beg makes no sense at all).  This patch states this in the
doc to avoid future confusion.

2 years agoDOC: config: mention that a single monitor-uri rule is supported
Willy Tarreau [Fri, 25 Nov 2022 09:24:44 +0000 (10:24 +0100)] 
DOC: config: mention that a single monitor-uri rule is supported

It was reported in issue #1059 that when multiple monitor-uri rules are
specified, only the last one is used. While this was done on purpose
since a single URI is used, it was not clearly mentioned in the doc,
possibly leading to confusion or wasted time trying to establish a
working setup. Let's clarify this point.

2 years agoDOC: config: clarify the fact that SNI should not be used in HTTP scenarios
Willy Tarreau [Fri, 25 Nov 2022 09:12:12 +0000 (10:12 +0100)] 
DOC: config: clarify the fact that SNI should not be used in HTTP scenarios

As reported by Tim in issue #1373 some warnings are deserved to explain
why using the frontend SNI for routing or connecting to a server is
usually not correct, especially since it can be tempting and used to
make sense in pure TCP scenarios.

2 years agoDOC: halog: explain how to use -ac and -ad in the help message
Willy Tarreau [Fri, 25 Nov 2022 08:40:06 +0000 (09:40 +0100)] 
DOC: halog: explain how to use -ac and -ad in the help message

Tim reported in issue #1435 that halog options -ac/-ad were poorly
documented. They're indeed used to spot infrastructure outages between
the clients and haproxy by detecting abnormal periods of silence followed
by bursts, either affecting the network itself, or also a single machine
(e.g. swapping on an edge client or proxy can cause such patterns).

2 years agoDOC: config: refer to section about quoting in the "add_item" converter
Willy Tarreau [Fri, 25 Nov 2022 08:27:15 +0000 (09:27 +0100)] 
DOC: config: refer to section about quoting in the "add_item" converter

As requested by Nick in issue #1719, let's add a reference to the section
about quoting there, since add_item() will often be used with commas and
it's easy to mess up.

2 years agoDOC: config: provide some configuration hints for "http-reuse"
Willy Tarreau [Fri, 25 Nov 2022 08:17:18 +0000 (09:17 +0100)] 
DOC: config: provide some configuration hints for "http-reuse"

This adds some configuration hints regarding various workloads that do
not manage to achieve high reuse rates due to too low a global maxconn
or thread groups.

This fixes github issue #1472.

2 years agoBUG/MINOR: ssl: shut the ca-file errors emitted during httpclient init
William Lallemand [Thu, 24 Nov 2022 18:14:19 +0000 (19:14 +0100)] 
BUG/MINOR: ssl: shut the ca-file errors emitted during httpclient init

With an OpenSSL library which use the wrong OPENSSLDIR, HAProxy tries to
load the OPENSSLDIR/certs/ into @system-ca, but emits a warning when it
can't.

This patch fixes the issue by allowing to shut the error when the SSL
configuration for the httpclient is not explicit.

Must be backported in 2.6.

2 years agoMINOR: ssl: forgotten newline in error messages on ca-file
William Lallemand [Thu, 24 Nov 2022 17:45:28 +0000 (18:45 +0100)] 
MINOR: ssl: forgotten newline in error messages on ca-file

Add forgotten newlines in ssl_store_load_ca_from_buf() error messages.

2 years ago[RELEASE] Released version 2.7-dev10 v2.7-dev10
Willy Tarreau [Thu, 24 Nov 2022 16:13:05 +0000 (17:13 +0100)] 
[RELEASE] Released version 2.7-dev10

Released version 2.7-dev10 with the following main changes :
    - MEDIUM: tcp-act: add parameter rst-ttl to silent-drop
    - BUG/MAJOR: quic: Crash upon retransmission of dgrams with several packets
    - MINOR: cli: print parsed command when not found
    - BUG/MAJOR: quic: Crash after discarding packet number spaces
    - CLEANUP: quic: replace "choosen" with "chosen" all over the code
    - MINOR: cli/pools: store "show pools" results into a temporary array
    - MINOR: cli/pools: add sorting capabilities to "show pools"
    - MINOR: cli/pools: add pool name filtering capability to "show pools"
    - DOC: configuration: fix quic prefix typo
    - MINOR: quic: report error if force-retry without cluster-secret
    - MINOR: global: generate random cluster.secret if not defined
    - BUG/MINOR: resolvers: do not run the timeout task when there's no resolution
    - BUG/MINOR: server/idle: at least use atomic stores when updating max_used_conns
    - MINOR: server/idle: make the next_takeover index per-tgroup
    - BUILD: listener: fix build warning on global_listener_rwlock without threads
    - BUG/MAJOR: sched: protect task during removal from wait queue
    - BUILD: sched: fix build with DEBUG_THREAD with the previous commit
    - DOC: quic: add note on performance issue with listener contention
    - BUG/MINOR: cfgparse-listen: fix ebpt_next_dup pointer dereference on proxy "from" inheritance
    - BUG/MINOR: log: fix parse_log_message rfc5424 size check
    - CLEANUP: arg: remove extra check in make_arg_list arg escaping
    - CLEANUP: tools: extra check in utoa_pad
    - MINOR: h1: Consider empty port as invalid in authority for CONNECT
    - MINOR: http: Considere empty ports as valid default ports
    - BUG/MINOR: http-htx: Normalized absolute URIs with an empty port
    - BUG/MINOR: h1: Replace authority validation to conform RFC3986
    - REG-TESTS: http: Add more tests about authority/host matching
    - BUG/MINOR: http-htx: Don't consider an URI as normalized after a set-uri action
    - BUG/MEDIUM: mux-h1: Don't release H1C on timeout if there is a SC attached
    - BUG/MEDIUM: mux-h1: Subscribe for reads on error on sending path
    - BUILD: http-htx: Silent build error about a possible NULL start-line
    - DOC: configuration.txt: add default_value for table_idle signature
    - BUILD: ssl-sock: Silent error about NULL deref in ssl_sock_bind_verifycbk()
    - BUG/MEDIUM: mux-h1: Remove H1C_F_WAIT_NEXT_REQ flag on a next request
    - BUG/MINOR: mux-h1: Fix handling of 408-Request-Time-Out
    - MINOR: mux-h1: Remove H1C_F_WAIT_NEXT_REQ in functions handling errors
    - MINOR: mux-h1: Avoid useless call to h1_send() if no error is sent
    - DOC: configuration.txt: fix typo in table_idle signature
    - BUILD: stick-tables: fix build breakage in xxhash on older compilers
    - BUILD: compiler: include compiler's definitions before ours
    - BUILD: quic: global.h is needed in cfgparse-quic
    - CLEANUP: tools: do not needlessly include xxhash nor cli from tools.h
    - BUILD: flags: really restrict the cases where flags are exposed
    - BUILD: makefile: minor reordering of objects by build time
    - BUILD: quic: silence two invalid build warnings at -O1 with gcc-6.5
    - BUILD: quic: use openssl-compat.h instead of openssl/ssl.h
    - MEDIUM: ssl: add minimal WolfSSL support with OpenSSL compatibility mode
    - MINOR: sample: make the rand() sample fetch function use the statistical_prng
    - MINOR: auth: silence null dereference warning in check_user()
    - CLEANUP: peers: fix format string for status messages (int signedness)
    - CLEANUP: qpack: fix format string in debugging code (int signedness)
    - CLEANUP: qpack: properly use the QPACK macros not HPACK ones in debug code
    - BUG/MEDIUM: quic: fix datagram dropping on queueing failed

2 years agoBUG/MEDIUM: quic: fix datagram dropping on queueing failed
Amaury Denoyelle [Thu, 24 Nov 2022 14:24:38 +0000 (15:24 +0100)] 
BUG/MEDIUM: quic: fix datagram dropping on queueing failed

After reading a datagram, it is enqueud for the thread attached to the
DCID. This is done via quic_lstnr_dgram_dispatch() function. If this
step fails, we remove the datagram from the buffer of quic_receiver_buf.

This step is faulty because we use b_del() instead of b_sub(). If
quic_receiver_buf was not empty, we will remove content from another
datagram while leaving the content of the last read datagram. This
probably produces valid datagram dropping and may even result in crash.

As stated, this bug can only happen if qc_lstnr_dgram_dispatch() fails
which happen on two occaions :
* on quic_dgram allocation failure, which should be pretty rare
* on datagram labelled as invalid for QUIC protocol. This may happen
  more frequently depending on the network conditions. Thus, this bug
  has been labelled as a medium one.

This should be backported up to 2.6.

2 years agoCLEANUP: qpack: properly use the QPACK macros not HPACK ones in debug code
Willy Tarreau [Thu, 24 Nov 2022 14:38:26 +0000 (15:38 +0100)] 
CLEANUP: qpack: properly use the QPACK macros not HPACK ones in debug code

There were a few leftovers of DEBUG_HPACK and HPACK_SHT_SIZE instead of
their QPACK equivalent in the QPACK debug code. There's no harm anyway,
but it could lead to confusing results if the tables are not sized
equally.

2 years agoCLEANUP: qpack: fix format string in debugging code (int signedness)
Willy Tarreau [Thu, 24 Nov 2022 14:35:17 +0000 (15:35 +0100)] 
CLEANUP: qpack: fix format string in debugging code (int signedness)

In issue #1939, Ilya mentions that cppchecks warned about use of "%d" to
report the QPACK table's index that's locally stored as an unsigned int.
While technically valid, this will never cause any trouble since indexes
are always small positive values, but better use %u anyway to silence
this warning.

2 years agoCLEANUP: peers: fix format string for status messages (int signedness)
Willy Tarreau [Thu, 24 Nov 2022 14:32:20 +0000 (15:32 +0100)] 
CLEANUP: peers: fix format string for status messages (int signedness)

In issue #1939, Ilya mentions that cppchecks warned about use of "%d" to
report the status state that's locally stored as an unsigned int. While
technically valid, this will never cause any trouble since in the end
what we store there are the applet's states (just a few enum values).
Better use %u anyway to silence this warning.

2 years agoMINOR: auth: silence null dereference warning in check_user()
Aurelien DARRAGON [Thu, 24 Nov 2022 07:37:13 +0000 (08:37 +0100)] 
MINOR: auth: silence null dereference warning in check_user()

In GH issue #1940 cppcheck warns about a possible null-dereference in
check_user() when DEBUG_AUTH is enabled. Indeed, <ep> may potentially
be NULL because upon error crypt_r() and crypt() may return a null
pointer. However it's not directly derefenced, it is only passed to
printf() with '%s' fmt. While it is in practice fine with the printf
implementations we care about (that check strings against null before
printing them), it is undefined behavior according to the spec, hence
the warning.

Let's check <ep> before passing it to printf. This should partly
solve GH #1940.

2 years agoMINOR: sample: make the rand() sample fetch function use the statistical_prng
Willy Tarreau [Thu, 24 Nov 2022 13:54:29 +0000 (14:54 +0100)] 
MINOR: sample: make the rand() sample fetch function use the statistical_prng

Emeric noticed that producing many randoms to fill a stick table was
saturating on the rand_lock. Since 2.4 we have the statistical PRNG
for low-quality randoms like this one, there is no point in using the
one that was originally implemented for the purpose of creating safe
UUIDs, since the doc itself clearly states that these randoms are not
secure and they have not been in the past either. With this change,
locking contention is completely gone.

2 years agoMEDIUM: ssl: add minimal WolfSSL support with OpenSSL compatibility mode
Uriah Pollock [Wed, 23 Nov 2022 15:41:25 +0000 (16:41 +0100)] 
MEDIUM: ssl: add minimal WolfSSL support with OpenSSL compatibility mode

This adds a USE_OPENSSL_WOLFSSL option, wolfSSL must be used with the
OpenSSL compatibility layer. This must be used with USE_OPENSSL=1.

WolfSSL build options:

   ./configure --prefix=/opt/wolfssl --enable-haproxy

HAProxy build options:

  USE_OPENSSL=1 USE_OPENSSL_WOLFSSL=1 WOLFSSL_INC=/opt/wolfssl/include/ WOLFSSL_LIB=/opt/wolfssl/lib/ ADDLIB='-Wl,-rpath=/opt/wolfssl/lib'

Using at least the commit 54466b6 ("Merge pull request #5810 from
Uriah-wolfSSL/haproxy-integration") from WolfSSL. (2022-11-23).

This is still to be improved, reg-tests are not supported yet, and more
tests are to be done.

Signed-off-by: William Lallemand <wlallemand@haproxy.org>
2 years agoBUILD: quic: use openssl-compat.h instead of openssl/ssl.h
Uriah Pollock [Wed, 23 Nov 2022 16:10:07 +0000 (17:10 +0100)] 
BUILD: quic: use openssl-compat.h instead of openssl/ssl.h

Replace the include of openssl/ssl.h by openssl-compat.h.

Signed-off-by: William Lallemand <wlallemand@haproxy.org>
2 years agoBUILD: quic: silence two invalid build warnings at -O1 with gcc-6.5
Willy Tarreau [Thu, 24 Nov 2022 08:16:41 +0000 (09:16 +0100)] 
BUILD: quic: silence two invalid build warnings at -O1 with gcc-6.5

Gcc 6.5 is now well known for triggering plenty of false "may be used
uninitialized", particularly at -O1, and two of them happen in quic,
quic_tp and quic_conn. Both of them were reviewed and easily confirmed
as wrong (gcc seems to ignore the control flow after the function
returns and believes error conditions are not met). Let's just preset
the variables that bothers it. In quic_tp the initialization was moved
out of the loop since there's no point inflating the code just to
silence a stupid warning.

2 years agoBUILD: makefile: minor reordering of objects by build time
Willy Tarreau [Thu, 24 Nov 2022 07:57:13 +0000 (08:57 +0100)] 
BUILD: makefile: minor reordering of objects by build time

This time the current ordering of common objects remained mostly
unchanged, except for flt_bwlim that was added. However, the SSL
and QUIC build order still had not been handled and were extremely
imbalanced, so they were adjusted. It's even possible to start
building QUIC before openssl to save a little bit more but more
likely that a few large quic files will get split again over time.

2 years agoBUILD: flags: really restrict the cases where flags are exposed
Willy Tarreau [Thu, 24 Nov 2022 07:22:40 +0000 (08:22 +0100)] 
BUILD: flags: really restrict the cases where flags are exposed

A number of internal flags started to be exposed to external programs
at the location of their definition since commit 77acaf5af ("MINOR:
flags: add a new file to host flag dumping macros"). This allowed the
"flags" utility to decode many more of them and always correctly. The
condition to expose them was to rely on the preliminary definition of
EOF that indicates that stdio is already included. But this was a
wrong approach. It only guarantees that snprintf() can safely be used
but still causes large functions to be built. But stdio is often
included before some of these includes, so these heavy inline functions
actually have to be compiled in many cases. The result is that the
build time significantly increased, especially with fast compilers
like gcc -O0 which took +50% or TCC which took +100%!

This patch addresses the problem by instead relying on an explicit
macro HA_EXPOSE_FLAGS that the calling program must explicitly define
before including these files. flags.c does this and that's all. The
previous build time is now restored with a speed up of 20 to 50%
depending on the build options.

2 years agoCLEANUP: tools: do not needlessly include xxhash nor cli from tools.h
Willy Tarreau [Thu, 24 Nov 2022 07:09:12 +0000 (08:09 +0100)] 
CLEANUP: tools: do not needlessly include xxhash nor cli from tools.h

These includes brought by commit 9c76637ff ("MINOR: anon: add new macros
and functions to anonymize contents") resulted in an increase of exactly
20% of the number of lines to build. These include are not needed there,
only tools.c needs xxhash.h.

2 years agoBUILD: quic: global.h is needed in cfgparse-quic
Willy Tarreau [Thu, 24 Nov 2022 07:28:43 +0000 (08:28 +0100)] 
BUILD: quic: global.h is needed in cfgparse-quic

cfgparse-quic accesses some members of the "global" struct but only
includes global-t.h. It actually used to work via tools.h due to a
long dependency chain that brought it, but it will be fixed and will
break cfgparse-quic, so let's fix it first.

2 years agoBUILD: compiler: include compiler's definitions before ours
Willy Tarreau [Thu, 24 Nov 2022 06:51:57 +0000 (07:51 +0100)] 
BUILD: compiler: include compiler's definitions before ours

Building with TCC caused a warning on __attribute__() being redefined,
because we do define it on compilers that don't have it, but we didn't
include the compiler's definitions first to leave it a chance to expose
its definitions. The correct way to do this would be to include
sys/cdefs.h but we currently don't include it explicitly and a few
reports on the net mention some platforms where it could be missing
by default. Let's use inttypes.h instead, it always causes it (or its
equivalent) to be included and we know it's present on supported
platforms since we already depend on it.

No backport is needed.

2 years agoBUILD: stick-tables: fix build breakage in xxhash on older compilers
Willy Tarreau [Thu, 24 Nov 2022 06:35:17 +0000 (07:35 +0100)] 
BUILD: stick-tables: fix build breakage in xxhash on older compilers

Commit 36d156564 ("MINOR: peers: Support for peer shards") reintroduced
a direct dependency on import/xxhash.h which was previously dropped by
commit d5fc8fcb8 ("CLEANUP: Add haproxy/xxhash.h to avoid modifying
import/xxhash.h"). This results in xxhash.h being included twice, which
breaks the build on older compilers which do not like seeing XXH32_hash_t
being defined twice.

Let's just use include/haproxy/xxhash.h instead.

No backport is needed.

2 years agoDOC: configuration.txt: fix typo in table_idle signature
Aurelien DARRAGON [Wed, 23 Nov 2022 13:35:06 +0000 (14:35 +0100)] 
DOC: configuration.txt: fix typo in table_idle signature

An extra ',' was mistakenly added in table_idle converter signature
with commit ed36968 ("DOC: configuration.txt: add default_value for
table_idle signature").

2 years agoMINOR: mux-h1: Avoid useless call to h1_send() if no error is sent
Christopher Faulet [Wed, 23 Nov 2022 16:13:12 +0000 (17:13 +0100)] 
MINOR: mux-h1: Avoid useless call to h1_send() if no error is sent

If we choose to not send an error to the client, there is no reason to call
h1_send() for nothing. This happens because functions handling errors return
1 instead of 0 when nothing is performed.

2 years agoMINOR: mux-h1: Remove H1C_F_WAIT_NEXT_REQ in functions handling errors
Christopher Faulet [Wed, 23 Nov 2022 16:07:48 +0000 (17:07 +0100)] 
MINOR: mux-h1: Remove H1C_F_WAIT_NEXT_REQ in functions handling errors

If is cleaner to remove this flag in the internal functions handling errors,
responsible to update the H1 connection state, instead to do so in calling
functions. This will hopefully avoid bugs in future.

2 years agoBUG/MINOR: mux-h1: Fix handling of 408-Request-Time-Out
Christopher Faulet [Wed, 23 Nov 2022 15:58:22 +0000 (16:58 +0100)] 
BUG/MINOR: mux-h1: Fix handling of 408-Request-Time-Out

When a timeout is detected waiting for the request, a 408-Request-Time-Out
response is sent. However, an error was introduced by commit 6858d76cd3
("BUG/MINOR: mux-h1: Obey dontlognull option for empty requests"). Instead
of inhibiting the log message, the option was stopping the error sending.

Of course, we must do the opposite.

This patch must be backported as far as 2.4.

2 years agoBUG/MEDIUM: mux-h1: Remove H1C_F_WAIT_NEXT_REQ flag on a next request
Christopher Faulet [Wed, 23 Nov 2022 14:58:59 +0000 (15:58 +0100)] 
BUG/MEDIUM: mux-h1: Remove H1C_F_WAIT_NEXT_REQ flag on a next request

When an idle H1 connection starts to process an new request, we must take
care to remove H1C_F_WAIT_NEXT_REQ flag. This flag is used to know an idle
H1 connection has already processed at least one request and is waiting for
a next one, but nothing was received yet.

Keeping this flag leads to a crash because some running H1 connections may
be erroneously released on a soft-stop. Indeed, only idle or closed
connections must be released.

This bug was reported into #1903. It is 2.7-specific. No backport needed.

2 years agoBUILD: ssl-sock: Silent error about NULL deref in ssl_sock_bind_verifycbk()
Christopher Faulet [Wed, 23 Nov 2022 08:27:13 +0000 (09:27 +0100)] 
BUILD: ssl-sock: Silent error about NULL deref in ssl_sock_bind_verifycbk()

In ssl_sock_bind_verifycbk(), when compiled without QUIC support, the
compiler may report an error during compilation about a possible NULL
dereference:

src/ssl_sock.c: In function ‘ssl_sock_bind_verifycbk’:
src/ssl_sock.c:1738:12: error: potential null pointer dereference [-Werror=null-dereference]
 1738 |         ctx->xprt_st |= SSL_SOCK_ST_FL_VERIFY_DONE;
      |         ~~~^~~~~~~~~

A BUG_ON() was addeded because it must never happen. But when compiled
without DEBUG_STRICT, there is nothing to help the compiler. Thus
ALREADY_CHECKED() macro is used. The ssl-sock context and the bind config
are concerned.

This patch must be backported to 2.6.

2 years agoDOC: configuration.txt: add default_value for table_idle signature
Aurelien DARRAGON [Tue, 22 Nov 2022 17:55:35 +0000 (18:55 +0100)] 
DOC: configuration.txt: add default_value for table_idle signature

table_idle converter takes optional default_value argument.
The documentation correctly describes this usage but <default_value> was
missing in the converter signature.

It should be backported with bbeec37b3 ("MINOR: stick-table:
Add table_expire() and table_idle() new converters")

2 years agoBUILD: http-htx: Silent build error about a possible NULL start-line
Christopher Faulet [Tue, 22 Nov 2022 17:02:00 +0000 (18:02 +0100)] 
BUILD: http-htx: Silent build error about a possible NULL start-line

In http_replace_req_uri(), if the URI was successfully replaced, it means
the start-line exists. However, the compiler reports an error about a
possible NULL pointer dereference:

src/http_htx.c: In function ‘http_replace_req_uri’:
src/http_htx.c:392:19: error: potential null pointer dereference [-Werror=null-dereference]
  392 |         sl->flags &= ~HTX_SL_F_NORMALIZED_URI;

So, ALREADY_CHECKED() macro is used to silent the build error. This patch
must be backported with 84cdbe478a ("BUG/MINOR: http-htx: Don't consider an
URI as normalized after a set-uri action").

2 years agoBUG/MEDIUM: mux-h1: Subscribe for reads on error on sending path
Christopher Faulet [Tue, 22 Nov 2022 16:16:22 +0000 (17:16 +0100)] 
BUG/MEDIUM: mux-h1: Subscribe for reads on error on sending path

The recent refactoring about errors handling in the H1 multiplexer
introduced a bug on abort when the client wait for the server response. The
bug only exists if abortonclose option is not enabled. Indeed, in this case,
when the end of the message is reached, the mux stops to receive data
because these data are part of the next request. However, error on the
sending path are no longer fatal. An error on the reading path must be
caught to do so. So, in case of a client abort, the error is not reported to
the upper layer and the H1 connection cannot be closed if some pending data
are blocked (remember, an error on sending path was detected, blocking
outgoing data).

To be sure to have a chance to detect the abort in the case, when an error
is detected on the sending path, we force the subscription for reads.

This patch, with the previous one, should fix the issue #1943. It is
2.7-specific, no backport is needed.

2 years agoBUG/MEDIUM: mux-h1: Don't release H1C on timeout if there is a SC attached
Christopher Faulet [Tue, 22 Nov 2022 16:06:13 +0000 (17:06 +0100)] 
BUG/MEDIUM: mux-h1: Don't release H1C on timeout if there is a SC attached

When the H1 task timed out, we must be careful to not release the H1
conneciton if there is still a H1 stream with a stream-connector
attached. In this case, we must wait. There are some tests to prevent it
happens. But the last one only tests the UPGRADING state while there is also
the CLOSING state with a SC attached. But, in the end, it is safer to test
if there is a H1 stream with a SC attached.

This patch should partially fix the issue #1943. However, it only prevent
the segfault. There is another bug under the hood. BTW, this one is
2.7-specific. Not backport is needed.

2 years agoBUG/MINOR: http-htx: Don't consider an URI as normalized after a set-uri action
Christopher Faulet [Tue, 22 Nov 2022 14:41:48 +0000 (15:41 +0100)] 
BUG/MINOR: http-htx: Don't consider an URI as normalized after a set-uri action

An abosulte URI is marked as normalized if it comes from an H2 client. This
way, we know we can send a relative URI to an H1 server. But, after a
set-uri action, the URI must no longer be considered as normalized.
Otherwise there is no way to send an absolute URI on the server side.

If it is important to update a normalized absolute URI without altering this
property, the host, path and/or query-string must be set separatly.

This patch should fix the issue #1938. It should be backported as far as
2.4.