]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
2 years agoMINOR: quic: replace custom buf on Tx by default struct buffer
Amaury Denoyelle [Thu, 4 Aug 2022 14:19:57 +0000 (16:19 +0200)] 
MINOR: quic: replace custom buf on Tx by default struct buffer

On first prototype version of QUIC, emission was multithreaded. To
support this, a custom thread-safe ring-buffer has been implemented with
qring/cbuf.

Now the thread model has been adjusted : a quic-conn is always used on
the same thread and emission is not multi-threaded. Thus, qring/cbuf
usage can be replace by a standard struct buffer.

The code has been simplified even more as for now buffer is always
drained after a prepare/send invocation. This is the case since a
datagram is always considered as sent even on sendto() error. BUG_ON
statements guard are here to ensure that this model is always valid.
Thus, code to handle data wrapping and consume too small contiguous
space with a 0-length datagram is removed.

2 years agoCLEANUP: mux-quic: remove loop on sending frames
Amaury Denoyelle [Thu, 4 Aug 2022 08:11:12 +0000 (10:11 +0200)] 
CLEANUP: mux-quic: remove loop on sending frames

qc_send_app_pkts() has now a while loop implemented which allows to send
all possible frames even if the send buffer is full between packet
prepare and send. This is present since commit :
  dc07751ed7ebad10f49081d28a9a5ae785f53d76
  MINOR: quic: Send packets as much as possible from qc_send_app_pkts()

This means we can remove code from the MUX which implement this at the
upper layer. This is useful to simplify qc_send_frames() function.

As mentionned commit is subject to backport, this commit should be
backported as well to 2.6.

2 years agoMINOR: debug/memstats: permit to pass the size to free()
Willy Tarreau [Tue, 9 Aug 2022 07:08:18 +0000 (09:08 +0200)] 
MINOR: debug/memstats: permit to pass the size to free()

Right now the free() call is not intercepted since all this is done
using macros and that would break a lot of stuff. Instead a __free()
macro was provided but never used. In addition it used to only report
a zero size, which is not very convenient.

With this patch comes a better solution. Instead it provides a new
will_free() macro that can be prepended before a call to free(). It
only keeps the counters up to date, and also supports being passed a
size. The pool_free_area() command now uses it, which finally allows
the stats to look correct:

  pool-os.h:38   MALLOC  size:   5802127832  calls:   3868044  size/call:   1500
  pool-os.h:47     FREE  size:   5800041576  calls:   3867444  size/call:   1499

The few other places directly calling free() could now be instrumented to
use this and to pass the correct sizeof() when known.

2 years agoMINOR: debug/memstats: automatically determine first column size
Willy Tarreau [Tue, 9 Aug 2022 06:51:08 +0000 (08:51 +0200)] 
MINOR: debug/memstats: automatically determine first column size

The first column's width may vary a lot depending on outputs, and it's
annoying to have large empty columns on small names and mangled large
columns that are not yet large enough. In order to overcome this, this
patch adds a width field to the memstats applet's context, and this
width is calculated the first time the function is entered, by estimating
the width of all lines that will be dumped. This is simple enough and
does the job well. If in the future some filtering criteria are added,
it will still be possible to perform a single pass on everything
depending on the desired output format.

2 years agoMINOR: debug: also store the function name in struct mem_stats
Willy Tarreau [Tue, 9 Aug 2022 06:40:08 +0000 (08:40 +0200)] 
MINOR: debug: also store the function name in struct mem_stats

The calling function name is now stored in the structure, and it's
reported when the "all" argument is passed. The first column is
significantly enlarged because some names are really wide :-(

2 years agoMINOR: debug: store and report the pool's name in struct mem_stats
Willy Tarreau [Tue, 9 Aug 2022 06:15:27 +0000 (08:15 +0200)] 
MINOR: debug: store and report the pool's name in struct mem_stats

Let's add a generic "extra" pointer to the struct mem_stats to store
context-specific information. When tracing pool_alloc/pool_free, we
can now store a pointer to the pool, which allows to report the pool
name on an extra column. This significantly improves tracing
capabilities.

Example:

  proxy.c:1598      CALLOC   size:  28832  calls:  4     size/call:  7208
  dynbuf.c:55       P_FREE   size:  32768  calls:  2     size/call:  16384  buffer
  quic_tls.h:385    P_FREE   size:  34008  calls:  1417  size/call:  24     quic_tls_iv
  quic_tls.h:389    P_FREE   size:  34008  calls:  1417  size/call:  24     quic_tls_iv
  quic_tls.h:554    P_FREE   size:  34008  calls:  1417  size/call:  24     quic_tls_iv
  quic_tls.h:558    P_FREE   size:  34008  calls:  1417  size/call:  24     quic_tls_iv
  quic_tls.h:562    P_FREE   size:  34008  calls:  1417  size/call:  24     quic_tls_iv
  quic_tls.h:401    P_ALLOC  size:  34080  calls:  1420  size/call:  24     quic_tls_iv
  quic_tls.h:403    P_ALLOC  size:  34080  calls:  1420  size/call:  24     quic_tls_iv
  xprt_quic.c:4060  MALLOC   size:  45376  calls:  5672  size/call:  8
  quic_sock.c:328   P_ALLOC  size:  46440  calls:  215   size/call:  216    quic_dgram

2 years agoMINOR: debug: make the mem_stats section aligned to void*
Willy Tarreau [Tue, 9 Aug 2022 06:09:24 +0000 (08:09 +0200)] 
MINOR: debug: make the mem_stats section aligned to void*

Not specifying the alignment will let the linker choose it, and it turns
out that it will not necessarily be the same size as the one chosen for
struct mem_stats, as can be seen if any new fields are added there. Let's
enforce an alignment to void* both for the section and for the structure.

2 years agoMINOR: quic: Replace pool_zalloc() by pool_malloc() for fake datagrams
Frédéric Lécaille [Mon, 8 Aug 2022 19:10:58 +0000 (21:10 +0200)] 
MINOR: quic: Replace pool_zalloc() by pool_malloc() for fake datagrams

These fake datagrams are only used by the low level I/O handler. They
are not provided to the "by connection" datagram handlers. This
is why they are not MT_LIST_APPEND()ed to the listner RX buffer list
(see &quic_dghdlrs[cid_tid].dgrams in quic_lstnr_dgram_dispatch().
Replace the call to pool_zalloc() to by the lighter call to pool_malloc()
and initialize only the ->buf and ->length members. This is safe because
only these fields are inspected by the low level I/O handler.

2 years agoBUG/MEDIUM: quic: Missing AEAD TAG check after removing header protection
Frédéric Lécaille [Mon, 8 Aug 2022 16:41:16 +0000 (18:41 +0200)] 
BUG/MEDIUM: quic: Missing AEAD TAG check after removing header protection

After removing the packet header protection, we can check the packet is long
enough to contain a 16 bytes length AEAD TAG (at this end of the packet).
This test was missing.

Must be backported to 2.6.

2 years agoMINOR: quic: Too much useless traces in qc_build_frms()
Frédéric Lécaille [Mon, 8 Aug 2022 14:09:46 +0000 (16:09 +0200)] 
MINOR: quic: Too much useless traces in qc_build_frms()

These traces about the available room into the packet currently built and
its payload length could be displayed for each STREAM frame, even for
those which have no chance to be embedded into a packet leading to
very traces to be displayed from a connection with a lot of stream.
This was revealed by traces provide by Tristan in GH #1808

May be backported to 2.6.

2 years agoBUG/MEDIUM: quic: Wrong packet length check in qc_do_rm_hp()
Frédéric Lécaille [Mon, 8 Aug 2022 08:28:07 +0000 (10:28 +0200)] 
BUG/MEDIUM: quic: Wrong packet length check in qc_do_rm_hp()

When entering this function, we first check the packet length is not too short.
But this was done against the datagram lenght in place of the packet length.
This could lead to the header protection to be removed using data past
the end of the packet (without buffer overflow).

Use the packet length in place of the datagram length which is at <end>
address passed as parameter to this function. As the packet length
is already stored in ->len packet struct member, this <end> parameter is no
more useful.

Must be backported to 2.6.

2 years ago[RELEASE] Released version 2.7-dev3 v2.7-dev3
Willy Tarreau [Sun, 7 Aug 2022 15:28:59 +0000 (17:28 +0200)] 
[RELEASE] Released version 2.7-dev3

Released version 2.7-dev3 with the following main changes :
    - BUILD: makefile: Fix install(1) handling for OpenBSD/NetBSD/Solaris/AIX
    - BUG/MEDIUM: tools: avoid calling dlsym() in static builds (try 2)
    - MINOR: resolvers: resolvers_destroy() deinit and free a resolver
    - BUG/MINOR: resolvers: shut off the warning for the default resolvers
    - BUG/MINOR: ssl: allow duplicate certificates in ca-file directories
    - BUG/MINOR: tools: fix statistical_prng_range()'s output range
    - BUG/MINOR: quic: do not send CONNECTION_CLOSE_APP in initial/handshake
    - BUILD: debug: Add braces to if statement calling only CHECK_IF()
    - BUG/MINOR: fd: Properly init the fd state in fd_insert()
    - BUG/MEDIUM: fd/threads: fix incorrect thread selection in wakeup broadcast
    - MINOR: init: load OpenSSL error strings
    - MINOR: ssl: enhance ca-file error emitting
    - BUG/MINOR: mworker/cli: relative pid prefix not validated anymore
    - BUG/MAJOR: mux_quic: fix invalid PROTOCOL_VIOLATION on POST data overlap
    - BUG/MEDIUM: mworker: proc_self incorrectly set crashes upon reload
    - BUILD: add detection for unsupported compiler models
    - BUG/MEDIUM: stconn: Only reset connect expiration when processing backend side
    - BUG/MINOR: backend: Fallback on RR algo if balance on source is impossible
    - BUG/MEDIUM: master: force the thread count earlier
    - BUG/MAJOR: poller: drop FD's tgid when masks don't match
    - DEBUG: fd: detect possibly invalid tgid in fd_insert()
    - BUG/MINOR: sockpair: wrong return value for fd_send_uxst()
    - MINOR: sockpair: move send_fd_uxst() error message in caller
    - Revert "BUG/MINOR: peers: set the proxy's name to the peers section name"
    - DEBUG: fd: split the fd check
    - MEDIUM: resolvers: continue startup if network is unavailable
    - BUG/MINOR: fd: always remove late updates when freeing fd_updt[]
    - MINOR: cli: emit a warning when _getsocks was used more than once
    - BUG/MINOR: mworker: PROC_O_LEAVING used but not updated
    - Revert "MINOR: cli: emit a warning when _getsocks was used more than once"
    - MINOR: cli: warning on _getsocks when socket were closed
    - BUG/MEDIUM: mux-quic: fix missing EOI flag to prevent streams leaks
    - MINOR: quic: Congestion control architecture refactoring
    - MEDIUM: quic: Cubic congestion control algorithm implementation
    - MINOR: quic: New "quic-cc-algo" bind keyword
    - BUG/MINOR: quic: loss time limit variable computed but not used
    - MINOR: quic: Stop looking for packet loss asap
    - BUG/MAJOR: quic: Useless resource intensive loop qc_ackrng_pkts()
    - MINOR: quic: Send packets as much as possible from qc_send_app_pkts()
    - BUG/MEDIUM: queue/threads: limit the number of entries dequeued at once
    - MAJOR: threads/plock: update the embedded library
    - MINOR: thread: provide an alternative to pthread's rwlock
    - DEBUG: tools: provide a tree dump function for ebmbtrees as well
    - MINOR: ebtree: add ebmb_lookup_shorter() to pursue lookups
    - BUG/MEDIUM: pattern: only visit equivalent nodes when skipping versions
    - BUG/MINOR: mux-quic: prevent crash if conn released during IO callback
    - CLEANUP: mux-quic: remove useless app_ops is_active callback
    - BUG/MINOR: mux-quic: do not free conn if attached streams
    - MINOR: mux-quic: save proxy instance into qcc
    - MINOR: mux-quic: use timeout server for backend conns
    - MEDIUM: mux-quic: adjust timeout refresh
    - MINOR: mux-quic: count in-progress requests
    - MEDIUM: mux-quic: implement http-keep-alive timeout
    - MINOR: peers: Add a warning about incompatible SSL config for the local peer
    - MINOR: peers: Use a dedicated reconnect timeout when stopping the local peer
    - BUG/MEDIUM: peers: limit reconnect attempts of the old process on reload
    - BUG/MINOR: peers: Use right channel flag to consider the peer as connected
    - BUG/MEDIUM: dns: Properly initialize new DNS session
    - BUG/MINOR: backend: Don't increment conn_retries counter too early
    - MINOR: server: Constify source server to copy its settings
    - REORG: server: Export srv_settings_cpy() function
    - BUG/MEDIUM: proxy: Perform a custom copy for default server settings
    - BUG/MINOR: quic: Missing in flight ack eliciting packet counter decrement
    - BUG/MEDIUM: quic: Floating point exception in cubic_root()
    - MINOR: h3: support HTTP request framing state
    - MINOR: mux-quic: refresh timeout on frame decoding
    - MINOR: mux-quic: refactor refresh timeout function
    - MEDIUM: mux-quic: implement http-request timeout
    - BUG/MINOR: quic: Avoid sending truncated datagrams
    - BUG/MINOR: ring/cli: fix a race condition between the writer and the reader
    - BUG/MEDIUM: sink: Set the sink ref for forwarders created during ring parsing
    - BUG/MINOR: sink: fix a race condition between the writer and the reader
    - BUG/MINOR: quic: do not reject datagrams matching minimum permitted size
    - MINOR: quic: Add two new stats counters for sendto() errors
    - BUG/MINOR: quic: Missing Initial packet dropping case
    - MINOR: quic: explicitely ignore sendto error
    - BUG/MINOR: quic: adjust errno handling on sendto
    - BUG/MEDIUM: quic: break out of the loop in quic_lstnr_dghdlr
    - MINOR: threads: report the number of thread groups in build options
    - MINOR: config: automatically preset MAX_THREADS based on MAX_TGROUPS
    - BUILD: SSL: allow to pass additional configure args to QUICTLS
    - CI: enable weekly "m32" builds on x86_64
    - CLEANUP: assorted typo fixes in the code and comments
    - BUG/MEDIUM: fix DH length when EC key is used
    - REGTESTS: ssl: adopt tests to OpenSSL-3.0.N
    - REGTESTS: ssl: adopt tests to OpenSSL-3.0.N
    - REGTESTS: ssl: fix grep invocation to use extended regex in ssl_generate_certificate.vtc
    - BUILD: cfgparse: always defined _GNU_SOURCE for sched.h and crypt.h

2 years agoBUILD: cfgparse: always defined _GNU_SOURCE for sched.h and crypt.h
Willy Tarreau [Sun, 7 Aug 2022 14:55:07 +0000 (16:55 +0200)] 
BUILD: cfgparse: always defined _GNU_SOURCE for sched.h and crypt.h

_GNU_SOURCE used to be defined only when USE_LIBCRYPT was set. It's also
needed for sched_setaffinity() to be exported. As a side effect, when
USE_LIBCRYPT is not set, a warning is emitted, as Ilya found and reported
in issue #1815. Let's just define _GNU_SOURCE regardless of USE_LIBCRYPT,
and also explicitly add sched.h, as right now it appears to be inherited
from one of the other includes.

This should be backported to 2.4.

2 years agoREGTESTS: ssl: fix grep invocation to use extended regex in ssl_generate_certificate.vtc
Ilya Shipitsin [Sat, 6 Aug 2022 17:40:41 +0000 (22:40 +0500)] 
REGTESTS: ssl: fix grep invocation to use extended regex in ssl_generate_certificate.vtc

in 2f2a2884b7464ccb56469cb94d8a1ae4015a8cb6 grep should have use regex flag -E, but flag
was lost by mistake

2 years agoREGTESTS: ssl: adopt tests to OpenSSL-3.0.N
Ilya Shipitsin [Sat, 23 Jul 2022 19:05:45 +0000 (00:05 +0500)] 
REGTESTS: ssl: adopt tests to OpenSSL-3.0.N

on Ubuntu-22.04 openssl-3.0.5 is shipped which has changed ec curve
description to "Server Temp Key: ECDH, secp384r1, 384 bits"

2 years agoREGTESTS: ssl: adopt tests to OpenSSL-3.0.N
Ilya Shipitsin [Sat, 23 Jul 2022 19:01:32 +0000 (00:01 +0500)] 
REGTESTS: ssl: adopt tests to OpenSSL-3.0.N

on Ubuntu-22.04 openssl-3.0.5 is shipped which has changed ec curve
description to "Server Temp Key: ECDH, prime256v1, 256 bits"

2 years agoBUG/MEDIUM: fix DH length when EC key is used
Ilya Shipitsin [Sat, 23 Jul 2022 18:55:19 +0000 (23:55 +0500)] 
BUG/MEDIUM: fix DH length when EC key is used

dh of length 1024 were chosen for EVP_PKEY_EC key type.
let us pick "default_dh_param" instead.

issue was found on Ubuntu 22.04 which is shipped with OpenSSL configured
with SECLEVEL=2 by default. such SECLEVEL value prohibits DH shorter than
2048:

OpenSSL error[0xa00018a] SSL_CTX_set0_tmp_dh_pkey: dh key too small

better strategy for chosing DH still may be considered though.

2 years agoCLEANUP: assorted typo fixes in the code and comments
Ilya Shipitsin [Fri, 29 Jul 2022 17:26:53 +0000 (22:26 +0500)] 
CLEANUP: assorted typo fixes in the code and comments

This is 31st iteration of typo fixes

2 years agoCI: enable weekly "m32" builds on x86_64
Ilya Shipitsin [Fri, 29 Jul 2022 18:21:37 +0000 (23:21 +0500)] 
CI: enable weekly "m32" builds on x86_64

this is build only workflow, catches potential "size_t" mismatches
--
v2 job name added, various markup changes

2 years agoBUILD: SSL: allow to pass additional configure args to QUICTLS
Ilya Shipitsin [Fri, 29 Jul 2022 18:13:21 +0000 (23:13 +0500)] 
BUILD: SSL: allow to pass additional configure args to QUICTLS

 this allows to pass QUICTLS_EXTRA_ARGS to QUICTLS builds. if no
 additional arg is passed, behaviour is kept unchanged

--
v2 indentation fixed

2 years agoMINOR: config: automatically preset MAX_THREADS based on MAX_TGROUPS
Willy Tarreau [Sat, 6 Aug 2022 14:37:27 +0000 (16:37 +0200)] 
MINOR: config: automatically preset MAX_THREADS based on MAX_TGROUPS

MAX_THREADS was not changed when setting MAX_TGROUPS, which still limits
some possibilities. Let's preset it to 4 * LONGBITS when MAX_TGROUPS is
larger than 1, or LONGBITS when it's set to 1. This means that the new
default value is 256 threads.

The rationale behind this is that the main use of thread groups is
mostly to address NUMA issues and that we don't necessarily need large
thread counts when using many groups, and 256 threads is already plenty
even on quite large systems.

For now it's important not to go too far because some internal structs
are arrays of MAX_THREADS entries, for example accept_queue_ring, which
is around 8kB per thread. Such structures will need to become dynamic
before defaulting to large thread counts (at 4096 threads max the
accept queues would require 32 MB RAM alone).

2 years agoMINOR: threads: report the number of thread groups in build options
Willy Tarreau [Sat, 6 Aug 2022 14:44:55 +0000 (16:44 +0200)] 
MINOR: threads: report the number of thread groups in build options

haproxy -vv shows the number of threads but didn't report the number
of groups, let's add it.

2 years agoBUG/MEDIUM: quic: break out of the loop in quic_lstnr_dghdlr
Willy Tarreau [Fri, 5 Aug 2022 06:45:56 +0000 (08:45 +0200)] 
BUG/MEDIUM: quic: break out of the loop in quic_lstnr_dghdlr

The function processes packets sent by other threads in the current
thread's queue. But if, for any reason, other threads write faster
than the current one processes, this can lead to a situation where
the function never returns.

It seems that it might be what's happening in issue #1808, though
unfortunately, this function is one of the rare without traces. But
the amount of calls to functions like qc_lstnr_pkt_rcv() on a single
thread seems to indicate this possibility.

Thanks to Tristan for his efforts in collecting extremely precious
traces!

This likely needs to be backported to 2.6.

2 years agoBUG/MINOR: quic: adjust errno handling on sendto
Amaury Denoyelle [Fri, 5 Aug 2022 09:56:36 +0000 (11:56 +0200)] 
BUG/MINOR: quic: adjust errno handling on sendto

qc_snd_buf returned a size_t which means that it was never negative
despite its documentation. Thus the caller who checked for this was
never informed of a sendto error.

Clean this by changing the return value of qc_snd_buf() to an integer.
A 0 is returned on success. Every other values are considered as an
error.

This commit should be backported up to 2.6. Note that to not cause
malfunctions, it must be backported after the previous patch :
  906b0589546b700b532472ede019e5c5a8ac1f38
  MINOR: quic: explicitely ignore sendto error
This is to ensure that a sendto error does not cause send to be
interrupted which may cause a stalled transfer without a proper retry
mechanism.

The impact of this bug seems null as caller explicitely ignores sendto
error. However this part of code seems to be subject to strange issues
and it may fix them in part. It may be of interest for github issue #1808.

2 years agoMINOR: quic: explicitely ignore sendto error
Amaury Denoyelle [Fri, 5 Aug 2022 13:22:28 +0000 (15:22 +0200)] 
MINOR: quic: explicitely ignore sendto error

qc_snd_buf() returns an error if sendto has failed. On standard
conditions, we should check for EAGAIN/EWOULDBLOCK errno and if so,
register the file-descriptor in the poller to retry the operation later.

However, quic_conn uses directly the listener fd which is shared for all
QUIC connections of this listener on several threads. Thus, it's
complicated to implement fd supversion via the poller : there is no
mechanism to easily wakeup quic_conn or MUX after a sendto failure.

A quick and simple solution for the moment is to considered a datagram
as properly emitted even on sendto error. In the end, this will trigger
the quic_conn retransmission timer as data will be considered lost on
the network and the send operation will be retried. This solution will
be replaced when fd management for quic_conn is reworked.

In fact, this quick hack was already in use in the current code, albeit
not voluntarily. This is due to a bug caused by an API mismatch on the
return type of qc_snd_buf() which never emits a negative error code
despite its documentation. Thus, all its invocation were considered as a
success. If this bug was fixed, the sending would would have been
interrupted by a break which could cause the transfer to freeze.

qc_snd_buf() invocation is clean up : the break statement is removed.
Send operation is now always explicitely conducted entirely even on
error and buffer data is purged.

A simple optimization has been added to skip over sendto when looping
over several datagrams at the first sendto error. However, to properly
function, it requires a fix on the return type of qc_snd_buf() which is
provided in another patch.

As the behavior before and after this patch seems identical, it is not
labelled as a BUG. However, it should be backported for cleaning
purpose. It may also have an impact on github issue #1808.

2 years agoBUG/MINOR: quic: Missing Initial packet dropping case
Frédéric Lécaille [Fri, 5 Aug 2022 07:34:44 +0000 (09:34 +0200)] 
BUG/MINOR: quic: Missing Initial packet dropping case

An Initial packet shorter than 1200 bytes must be dropped. The test was there
without the "goto drop"!

Must be backported to 2.6

2 years agoMINOR: quic: Add two new stats counters for sendto() errors
Frédéric Lécaille [Thu, 4 Aug 2022 10:00:00 +0000 (12:00 +0200)] 
MINOR: quic: Add two new stats counters for sendto() errors

Add "quic_socket_full" new stats counter for sendto() errors with EAGAIN as errno.
and "quic_sendto_err" counter for any other error.

2 years agoBUG/MINOR: quic: do not reject datagrams matching minimum permitted size
Willy Tarreau [Fri, 5 Aug 2022 08:09:32 +0000 (10:09 +0200)] 
BUG/MINOR: quic: do not reject datagrams matching minimum permitted size

The dgram length check in quic_get_dgram_dcid() rejects datagrams
matching exactly the minimum allowed length, which doesn't seem
correct. I doubt any useful packet would be that small but better
fix this to avoid confusing debugging sessions in the future.

This might be backported to 2.6.

2 years agoBUG/MINOR: sink: fix a race condition between the writer and the reader
Willy Tarreau [Thu, 4 Aug 2022 15:18:54 +0000 (17:18 +0200)] 
BUG/MINOR: sink: fix a race condition between the writer and the reader

This is the same issue as just fixed in b8e0fb97f ("BUG/MINOR: ring/cli:
fix a race condition between the writer and the reader") but this time
for sinks. They're also sucking the ring and present the same race at
high write loads.

This must be backported to 2.2 as well. See comments in the aforementioned
commit for backport hints if needed.

2 years agoBUG/MEDIUM: sink: Set the sink ref for forwarders created during ring parsing
Christopher Faulet [Thu, 4 Aug 2022 14:00:13 +0000 (16:00 +0200)] 
BUG/MEDIUM: sink: Set the sink ref for forwarders created during ring parsing

A reference to the sink was added in every forwarder by the commit 2ae25ea24
("MINOR: sink: Add a ref to sink in the sink_forward_target structure"). But
this commit is incomplete. It is not performed for the forwarders created
during a ring parsing.

This patch must be backported to 2.6.

2 years agoBUG/MINOR: ring/cli: fix a race condition between the writer and the reader
Willy Tarreau [Thu, 4 Aug 2022 15:00:21 +0000 (17:00 +0200)] 
BUG/MINOR: ring/cli: fix a race condition between the writer and the reader

The ring's CLI reader unlocks the read side of a ring and relocks it for
writing only if it needs to re-subscribe. But during this time, the writer
might have pushed data, see nobody subscribed hence woken nobody, while
the reader would have left marking that the applet had no more data. This
results in a dump that will not make any forward progress: the ring is
clogged by this reader which believes there's no data and the writer
will never wake it up.

The right approach consists in verifying after re-attaching if the writer
had made any progress in between, and to report that another call is
needed. Note that a jump back to the beginning would also work but here
we provide better fairness between readers this way.

This needs to be backported to 2.2. The applet API needed to signal the
availability of new data changed a few times since then.

2 years agoBUG/MINOR: quic: Avoid sending truncated datagrams
Frédéric Lécaille [Wed, 3 Aug 2022 18:52:20 +0000 (20:52 +0200)] 
BUG/MINOR: quic: Avoid sending truncated datagrams

There is a remaining loop in this ugly qc_snd_buf() function which could
lead haproxy to send truncated UDP datagrams. For now on, we send
a complete UDP datagram or nothing!

Must be backported to 2.6.

2 years agoMEDIUM: mux-quic: implement http-request timeout
Amaury Denoyelle [Wed, 3 Aug 2022 09:17:57 +0000 (11:17 +0200)] 
MEDIUM: mux-quic: implement http-request timeout

Implement http-request timeout for QUIC MUX. It is used when the
connection is opened and is triggered if no HTTP request is received in
time. By HTTP request we mean at least a QUIC stream with a full header
section. Then qcs instance is attached to a sedesc and upper layer is
then responsible to wait for the rest of the request.

This timeout is also used when new QUIC streams are opened during the
connection lifetime to wait for full HTTP request on them. As it's
possible to demux multiple streams in parallel with QUIC, each waiting
stream is registered in a list <opening_list> stored in qcc with <start>
as timestamp in qcs for the stream opening. Once a qcs is attached to a
sedesc, it is removed from <opening_list>. When refreshing MUX timeout,
if <opening_list> is not empty, the first waiting stream is used to set
MUX timeout.

This is efficient as streams are stored in the list in their creation
order so CPU usage is minimal. Also, the size of the list is
automatically restricted by flow control limitation so it should not
grow too much.

Streams are insert in <opening_list> by application protocol layer. This
is because only application protocol can differentiate streams for HTTP
messaging from internal usage. A function qcs_wait_http_req() has been
added to register a request stream by app layer. QUIC MUX can then
remove it from the list in qc_attach_sc().

As a side-note, it was necessary to implement attach qcc_app_ops
callback on hq-interop module to be able to insert a stream in waiting
list. Without this, a BUG_ON statement would be triggered when trying to
remove the stream on sedesc attach. This is to ensure that every
requests streams are registered for http-request timeout.

MUX timeout is explicitely refreshed on MAX_STREAM_DATA and STOP_SENDING
frame parsing to schedule http-request timeout if a new stream has been
instantiated. It was already done on STREAM parsing due to a previous
patch.

2 years agoMINOR: mux-quic: refactor refresh timeout function
Amaury Denoyelle [Mon, 1 Aug 2022 15:59:38 +0000 (17:59 +0200)] 
MINOR: mux-quic: refactor refresh timeout function

Try to reorganize qcc_refresh_timeout() to improve its readability. The
main objective is to reduce the indentation level and if sequences by
using goto statement to the end of the function. Also, backend and
frontend code path should be more explicit with this new version.

2 years agoMINOR: mux-quic: refresh timeout on frame decoding
Amaury Denoyelle [Tue, 2 Aug 2022 13:57:16 +0000 (15:57 +0200)] 
MINOR: mux-quic: refresh timeout on frame decoding

Refresh the MUX connection timeout in frame parsing functions. This is
necessary as these Rx operation are completed directly from the
quic-conn layer outside of MUX I/O callback. Thus, the timeout should be
refreshed on this occasion.

Note that however on STREAM parsing refresh is only conducted when
receiving the current consecutive data offset.

Timeouts related function have been moved up in the source file to be
able to use them in qcc_decode_qcs().

This commit will be useful for http-request timeout. Indeed, a new
stream may be opened during qcc_decode_qcs() which should trigger this
timeout until a full header section is received and qcs instance is
attached to sedesc.

2 years agoMINOR: h3: support HTTP request framing state
Amaury Denoyelle [Tue, 2 Aug 2022 09:32:45 +0000 (11:32 +0200)] 
MINOR: h3: support HTTP request framing state

Store the current step of HTTP message in h3s stream. This reports if we
are in the parsing of headers, content or trailers section. A new enum
h3s_st_req is defined for this.

This field is stored in h3s struct but only used for request stream. It
is left undefined for other streams (control or QPACK streams).

h3_is_frame_valid() has been extended to take into account this state
information. A connection error H3_FRAME_UNEXPECTED is reported if an
invalid frame according to the current state is received; for example a
DATA frame at the beginning of a stream.

2 years agoBUG/MEDIUM: quic: Floating point exception in cubic_root()
Frédéric Lécaille [Wed, 3 Aug 2022 10:49:30 +0000 (12:49 +0200)] 
BUG/MEDIUM: quic: Floating point exception in cubic_root()

It is illegal to call my_flsl() with 0 as parameter value. It is a UB.
This leaded cubic_root() to divide values by 0 at this line:

  x = 2 * x + (uint32_t)(val / ((uint64_t)x * (uint64_t)(x - 1)));

Thank you to Tristan971 for having reported this issue in GH #1808
and Willy for having spotted the root cause of this bug.

Must follow any cubic for QUIC backport (2.6).

2 years agoBUG/MINOR: quic: Missing in flight ack eliciting packet counter decrement
Frédéric Lécaille [Mon, 1 Aug 2022 12:07:50 +0000 (14:07 +0200)] 
BUG/MINOR: quic: Missing in flight ack eliciting packet counter decrement

The decrement was missing in quic_pktns_tx_pkts_release() called each time a
packet number space is discarded. This is not sure this bug could have an impact
during handshakes. This counter is used to cancel the timer used both for packet
detection and PTO, setting its value to null. So there could be retransmissions
or probing which could be triggered for nothing.

Must be backported to 2.6.

2 years agoBUG/MEDIUM: proxy: Perform a custom copy for default server settings
Christopher Faulet [Wed, 3 Aug 2022 09:31:55 +0000 (11:31 +0200)] 
BUG/MEDIUM: proxy: Perform a custom copy for default server settings

When a proxy is initialized with the settings of the default proxy, instead
of doing a raw copy of the default server settings, a custom copy is now
performed by calling srv_settings_copy(). This way, all settings will be
really duplicated. Without this deep copy, some pointers are shared between
several servers, leading to UAF, double-free or such bugs.

This patch relies on following commits:

  * b32cb9b51 REORG: server: Export srv_settings_cpy() function
  * 0b365e3cb MINOR: server: Constify source server to copy its settings

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

2 years agoREORG: server: Export srv_settings_cpy() function
Christopher Faulet [Wed, 3 Aug 2022 09:28:08 +0000 (11:28 +0200)] 
REORG: server: Export srv_settings_cpy() function

This function will be used to init a proxy with settings of the default
proxy. It is mandatory to fix a bug. To do so, it must be exposed.

2 years agoMINOR: server: Constify source server to copy its settings
Christopher Faulet [Wed, 3 Aug 2022 09:21:14 +0000 (11:21 +0200)] 
MINOR: server: Constify source server to copy its settings

The source server used to initialize a new server, in srv_settings_cpy() and
sub-functions, is now a constant.

This patch is mandatory to fix a bug.

2 years agoBUG/MINOR: backend: Don't increment conn_retries counter too early
Christopher Faulet [Wed, 3 Aug 2022 08:47:48 +0000 (10:47 +0200)] 
BUG/MINOR: backend: Don't increment conn_retries counter too early

The connection retry counter is incremented too early when a connection
fails. In SC_ST_CER state, errors handling must be performed before
incrementing the counter. Otherwise, we may consider the max connection
attempt is reached while a last one is in fact possible.

This patch must be backported to 2.6.

2 years agoBUG/MEDIUM: dns: Properly initialize new DNS session
Christopher Faulet [Wed, 3 Aug 2022 08:30:06 +0000 (10:30 +0200)] 
BUG/MEDIUM: dns: Properly initialize new DNS session

When a new DNS session is created, all its fields are not properly
initialized. For instance, "tx_msg_offset" can have any value after the
allocation. So, to fix the bug, pool_zalloc() is now used to allocate new
DNS session.

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

2 years agoBUG/MINOR: peers: Use right channel flag to consider the peer as connected
Christopher Faulet [Wed, 27 Jul 2022 08:49:31 +0000 (10:49 +0200)] 
BUG/MINOR: peers: Use right channel flag to consider the peer as connected

When a peer open a new connection to another peer, it is considered as
connected when the hello message is sent. To do so, the peer applet was
relying on CF_WRITE_PARTIAL channel flag. However it is not the right flag
to use. This one is a transient flag. Depending on the scheduling, this flag
may be removed by the stream before the peer has a chance to see
it. Instead, CF_WROTE_DATA flag must be checked.

This patch is related to the issue #1799. It must be backported as far as
2.0.

2 years agoBUG/MEDIUM: peers: limit reconnect attempts of the old process on reload
Christopher Faulet [Tue, 26 Jul 2022 17:19:18 +0000 (19:19 +0200)] 
BUG/MEDIUM: peers: limit reconnect attempts of the old process on reload

When peers are configured and HAProxy is reloaded or restarted, a
synchronization is performed between the old process and the new one. To do
so, the old process connects on the new one. If the synchronization fails,
it retries. However, there is no delay and reconnect attempts are not
bounded. Thus, it may loop for a while, consuming all the CPU. Of course, it
is unexpected, but it is possible. For instance, if the local peer is
misconfigured, an infinite loop can be observed if the connection succeeds
but not the synchronization. This prevents the old process to exit, except
if "hard-stop-after" option is set.

To fix the bug, the reconnect is delayed. The local peer already has a
expiration date to delay the reconnects. But it was not used on stopping
mode. So we use it not. Thanks to the previous fix, the reconnect timeout is
shorter in this case (500ms against 5s on running mode). In addition, we
also use the peers resync expiration date to not infinitely retries. It is
accurate because the new process, on its side, use this timeout to switch
from a local resync to a remote resync.

This patch depends on "MINOR: peers: Use a dedicated reconnect timeout when
stopping the local peer". It fixes the issue #1799. It should be backported
as far as 2.0.

2 years agoMINOR: peers: Use a dedicated reconnect timeout when stopping the local peer
Christopher Faulet [Tue, 26 Jul 2022 17:14:36 +0000 (19:14 +0200)] 
MINOR: peers: Use a dedicated reconnect timeout when stopping the local peer

When a process is stopped or reload, a dedicated reconnect timeout is now
used. For now, this timeout is not used because the current code retries
immediately to reconnect to perform the local synchronization with the new
local peer, if any.

This patch is required to fix the issue #1799. It should be backported as
far as 2.0 with next fixes.

2 years agoMINOR: peers: Add a warning about incompatible SSL config for the local peer
Christopher Faulet [Tue, 26 Jul 2022 17:03:51 +0000 (19:03 +0200)] 
MINOR: peers: Add a warning about incompatible SSL config for the local peer

In peers section, it is possible to enable SSL for the local peer. In this
case, the bind line and the server line should both be configured. A
"default-server" directive may also be used to configure the SSL on the
server side. However there is no test to be sure the SSL is enabled on both
sides. It is an problem because the local resync performed during a reload
will be impossible and it is probably not the expected behavior.

So, it is now checked during the configuration validation. A warning message
is displayed if the SSL is not properly configured for the local peer.

This patch is related to issue #1799. It should probably be backported to 2.6.

2 years agoMEDIUM: mux-quic: implement http-keep-alive timeout
Amaury Denoyelle [Mon, 25 Jul 2022 09:53:18 +0000 (11:53 +0200)] 
MEDIUM: mux-quic: implement http-keep-alive timeout

Complete QUIC MUX timeout refresh function by using http-keep-alive
timeout. It is used when the connection is idle after having handle at
least one request.

To implement this a new member <idle_start> has been defined in qcc
structure. This is used as timestamp for when the connection became idle
and is used as base time for http keep-alive timeout

2 years agoMINOR: mux-quic: count in-progress requests
Amaury Denoyelle [Mon, 25 Jul 2022 09:21:46 +0000 (11:21 +0200)] 
MINOR: mux-quic: count in-progress requests

Add a new qcc member named <nb_hreq>. Its purpose is close to <nb_sc>
which represents the number of attached stream connectors. Both are
incremented inside qc_attach_sc().

The difference is on the decrement operation. While <nb_cs> is
decremented on sedesc detach callback, <nb_hreq> is decremented when the
qcs is locally closed.

In most cases, <nb_hreq> will be decremented before <nb_cs>. However, it
will be the reverse if a stream must be kept alive after detach callback.

The main purpose of this field is to implement http-keep-alive timeout.
Both <nb_sc> and <nb_hreq> must be null to activate the http-keep-alive
timeout.

2 years agoMEDIUM: mux-quic: adjust timeout refresh
Amaury Denoyelle [Mon, 25 Jul 2022 12:58:48 +0000 (14:58 +0200)] 
MEDIUM: mux-quic: adjust timeout refresh

Implement a new internal function qcc_refresh_timeout(). Its role will be
to reset QUIC MUX timeout depending if there is requests in progress or
not.

qcc_update_timeout() does not set a timeout if there is still attached
streams as in this case the upper layer is responsible to manage it.
Else it will activate the timeout depending on the connection current
status.

Timeout is refreshed on several locations : on stream detach and in I/O
handler and wake callback.

For the moment, only the default timeout is used (client or server). The
function may be expanded in the future to support more specific ones :
* http-keep-alive if connection is idle
* http-request when waiting for incomplete HTTP requests
* client/server-fin for graceful shutdown

2 years agoMINOR: mux-quic: use timeout server for backend conns
Amaury Denoyelle [Mon, 25 Jul 2022 12:51:56 +0000 (14:51 +0200)] 
MINOR: mux-quic: use timeout server for backend conns

Use timeout server in qcc_init() as default timeout for backend
connections. No impact for the moment as QUIC backend support is not
implemented.

2 years agoMINOR: mux-quic: save proxy instance into qcc
Amaury Denoyelle [Fri, 22 Jul 2022 14:16:03 +0000 (16:16 +0200)] 
MINOR: mux-quic: save proxy instance into qcc

Store a reference to proxy in the qcc structure. This will be useful to
access to proxy members outside of qcc_init().

Most notably, this change is required to implement timeout refreshing by
using the various timeouts configured at the proxy level.

2 years agoBUG/MINOR: mux-quic: do not free conn if attached streams
Amaury Denoyelle [Wed, 27 Jul 2022 09:39:01 +0000 (11:39 +0200)] 
BUG/MINOR: mux-quic: do not free conn if attached streams

Ensure via qcc_is_dead() that a connection is not released instance
until all of qcs streams are detached by the upper layer, even if an
error has been reported or the timeout has fired.

On the other side, as qc_detach() always check the connection status,
this should ensure that we do not keep a connection if not necessary.

Without this patch, a qcc instance may be freed with some of its qcs
streams not detached. This is an incorrect behavior and will lead to a
BUG_ON fault. Note however that no occurence of this bug has been
produced currently. This patch is mainly a safety against future
occurences.

This should be backported up to 2.6.

2 years agoCLEANUP: mux-quic: remove useless app_ops is_active callback
Amaury Denoyelle [Mon, 1 Aug 2022 09:42:48 +0000 (11:42 +0200)] 
CLEANUP: mux-quic: remove useless app_ops is_active callback

Timeout in QUIC MUX has evolved from the simple first implementation. At
the beginning, a connection was considered dead unless bidirectional
streams were opened. This was abstracted through an app callback
is_active().

Now this paradigm has been reversed and a connection is considered alive
by default, unless an error has been reported or a timeout has already
been fired. The callback is_active() is thus not used anymore and can be
safely removed to simplify qcc_is_dead().

This commit should be backported to 2.6.

2 years agoBUG/MINOR: mux-quic: prevent crash if conn released during IO callback
Amaury Denoyelle [Mon, 25 Jul 2022 12:56:54 +0000 (14:56 +0200)] 
BUG/MINOR: mux-quic: prevent crash if conn released during IO callback

A qcc instance may be freed in the middle of qc_io_cb() if all streams
were purged. This will lead to a crash as qcc instance is reused after
this step. Jump directly to the end of the function to avoid this.

Note that this bug has not been triggered for the moment. This is a
safety fix to prevent it.

This must be backported up to 2.6.

2 years agoBUG/MEDIUM: pattern: only visit equivalent nodes when skipping versions
Willy Tarreau [Mon, 1 Aug 2022 09:46:27 +0000 (11:46 +0200)] 
BUG/MEDIUM: pattern: only visit equivalent nodes when skipping versions

Miroslav reported in issue #1802 a problem that affects atomic map/acl
updates. During an update, incorrect versions are properly skipped, but
in order to do so, we rely on ebmb_next() instead of ebmb_next_dup().
This means that if a new matching entry is in the process of being
added and is the first one to succeed in the lookup, we'll skip it due
to its version and use the next entry regardless of its value provided
that it has the correct version. For IP addresses and string prefixes
it's particularly visible because a lookup may match a new longer prefix
that's not yet committed (e.g. 11.0.0.1 would match 11/8 when 10/7 was
the only committed one), and skipping it could end up on 12/8 for
example. As soon as a commit for the last version happens, the issue
disappears.

This problem only affects tree-based matches: the "str", "ip", and "beg"
matches.

Here we replace the ebmb_next() values with ebmb_next_dup() for exact
string matches, and with ebmb_lookup_shorter() for longest matches,
which will first visit duplicates, then look for shorter prefixes. This
relies on previous commit:

    MINOR: ebtree: add ebmb_lookup_shorter() to pursue lookups

Both need to be backported to 2.4, where the generation ID was added.

Note that nowadays a simpler and more efficient approach might be employed,
by having a single version in the current tree, and a list of trees per
version. Manipulations would look up the tree version and work (and lock)
only in the relevant trees, while normal operations would be performed on
the current tree only. Committing would just be a matter of swapping tree
roots and deleting old trees contents.

2 years agoMINOR: ebtree: add ebmb_lookup_shorter() to pursue lookups
Willy Tarreau [Mon, 1 Aug 2022 08:37:29 +0000 (10:37 +0200)] 
MINOR: ebtree: add ebmb_lookup_shorter() to pursue lookups

This function is designed to enlarge the scope of a lookup performed
by a caller via ebmb_lookup_longest() that was not satisfied with the
result. It will first visit next duplicates, and if none are found,
it will go up in the tree to visit similar keys with shorter prefixes
and will return them if they match. We only use the starting point's
value to perform the comparison since it was expected to be valid for
the looked up key, hence it has all bits in common with its own length.

The algorithm is a bit complex because when going up we may visit nodes
that are located beneath the level we just come from. However it is
guaranteed that keys having a shorter prefix will be present above the
current location, though they may be attached to the left branch of a
cover node, so we just visit all nodes as long as their prefix is too
large, possibly go down along the left branch on cover nodes, and stop
when either there's a match, or there's a non-matching prefix anymore.

The following tricky case now works fine and properly finds 10.0.0.0/7
when looking up 11.0.0.1 from tree version 1 though both belong to
different sub-trees:

  prepare map #1
    add map @1 #1 10.0.0.0/7 10.0.0.0/7
    add map @1 #1 10.0.0.0/7 10.0.0.0/7
  commit map @1 #1
  prepare map #1
    add map @2 #1 11.0.0.0/8 11.0.0.0/8
    add map @2 #1 11.0.0.0/8 11.0.0.0/8

  prepare map #1
    add map @1 #1 10.0.0.0/7 10.0.0.0/7
  commit map @1 #1
  prepare map #1
    add map @2 #1 10.0.0.0/7 10.0.0.0/7
    add map @2 #1 11.0.0.0/8 11.0.0.0/8
    add map @2 #1 11.0.0.0/8 11.0.0.0/8

2 years agoDEBUG: tools: provide a tree dump function for ebmbtrees as well
Willy Tarreau [Mon, 1 Aug 2022 09:55:57 +0000 (11:55 +0200)] 
DEBUG: tools: provide a tree dump function for ebmbtrees as well

It's convenient for debugging IP trees. However we're not dumping the
full keys, for the sake of simplicity, only the 4 first bytes are dumped
as a u32 hex value. In practice this is sufficient for debugging. As a
reminder since it seems difficult to recover the command each time it's
needed, the output is converted to an image using dot from Graphviz:

    dot -o a.png -Tpng dump.txt

2 years agoMINOR: thread: provide an alternative to pthread's rwlock
Willy Tarreau [Sun, 10 Jul 2022 08:58:57 +0000 (10:58 +0200)] 
MINOR: thread: provide an alternative to pthread's rwlock

Since version 1.1.0, OpenSSL's libcrypto ignores the provided locking
mechanism and uses pthread's rwlocks instead. The problem is that for
some code paths (e.g. async engines) this results in a huge amount of
syscalls on systems facing a bit of contention, to the point where more
than 80% of the CPU can be spent in the system dealing with spinlocks
just for futex_wake().

This patch provides an alternative by redefining the relevant pthread
rwlocks from the low-overhead version of the progressive rw locks. This
way there will be no more syscalls in case of contention, and CPU will
be burnt in userland. Doing this saves massive amounts of CPU, where
the locks only take 12-15% vs 80% before, which allows SSL to work much
faster on large thread counts (e.g. 24 or more).

The tryrdlock and trywrlock variants have been implemented using a CAS
since their goal is only to succeed on no contention and never to wait.
The pthread_rwlock API is complete except that the timed versions of
the rdlock and wrlock do not wait and simply fall back to trylock
versions.

Since the gains have only been observed with async engines for now,
this option remains disabled by default. It can be enabled at build
time using USE_PTHREAD_EMULATION=1.

2 years agoMAJOR: threads/plock: update the embedded library
Willy Tarreau [Fri, 29 Jul 2022 15:53:31 +0000 (17:53 +0200)] 
MAJOR: threads/plock: update the embedded library

The plock code hasn't been been updated since 2017 and didn't benefit
from the exponential back-off improvements that were added in 2018.
Simply updating the file shows a massive performance gain on large
thread count (>=48) with dequeuing going from 113k RPS to 300k RPS and
round robin from 229k RPS to 1020k RPS. It was about time to update.
In addition, some recent improvements to the code will be useful with
thread groups.

An interesting improvement concerns EPYC CPUs. This one alone increased
fairness and was sufficient to avoid crashes in process_srv_queue() there,
when hammering two servers with maxconn 200 under 1k connections.

2 years agoBUG/MEDIUM: queue/threads: limit the number of entries dequeued at once
Willy Tarreau [Sat, 30 Jul 2022 07:53:22 +0000 (09:53 +0200)] 
BUG/MEDIUM: queue/threads: limit the number of entries dequeued at once

When testing strong queue contention on a 48-thread machine, some crashes
would frequently happen due to process_srv_queue() never leaving and
processing pending requests forever. A dump showed more than 500000
loops at once. The problem is that other threads find it working so
they don't do anything and are free to process their pending requests.
Because of this, the dequeuing thread can be kept busy forever and does
not process its own requests anymore (fortunately the watchdog stops it).

This patch adds a limit to the number of rounds, it limits it to
maxpollevents, which is reasonable because it's also an indicator of
latency and batches size. However there's a catch. If all requests
are finished when the thread ends the loop, there might not be enough
anymore to restart processing the queue. Thus we tolerate to re-enter
the loop to process one request at a time when it doesn't have any
anymore. This way we're leaving more room for another thread to take
on this task, and we're sure to eventually end this loop.

Doing this has also improved the overall dequeuing performance by ~20%
in highly contended situations with 48 threads.

It should be backported at least to 2.4, maybe even 2.2 since issues
were faced in the past on machines having many cores.

2 years agoMINOR: quic: Send packets as much as possible from qc_send_app_pkts()
Frédéric Lécaille [Tue, 26 Jul 2022 07:17:19 +0000 (09:17 +0200)] 
MINOR: quic: Send packets as much as possible from qc_send_app_pkts()

Add a loop into this function to send more packets from this function
which is called by the mux. It is broken when we could not prepare
packet with qc_prep_app_pkts() due to missing available room in the
buffer used to send packets. This improves the throughput.

Must be backported to 2.6.

2 years agoBUG/MAJOR: quic: Useless resource intensive loop qc_ackrng_pkts()
Frédéric Lécaille [Fri, 22 Jul 2022 14:27:44 +0000 (16:27 +0200)] 
BUG/MAJOR: quic: Useless resource intensive loop qc_ackrng_pkts()

This usless loop should have been removed a long time ago. As it is CPU resource
intensive, it could trigger the watchdog.

Must be backported to 2.6.

2 years agoMINOR: quic: Stop looking for packet loss asap
Frédéric Lécaille [Thu, 21 Jul 2022 12:24:41 +0000 (14:24 +0200)] 
MINOR: quic: Stop looking for packet loss asap

As the TX packets are ordered by their packet number and always sent
in the same order. their TX timestamps are inspected from the older to
the newer values when we look for the packet loss. So we can stop
this search as soon as we found the first packet which has not been lost.

Must be backported to 2.6

2 years agoBUG/MINOR: quic: loss time limit variable computed but not used
Frédéric Lécaille [Thu, 21 Jul 2022 07:55:15 +0000 (09:55 +0200)] 
BUG/MINOR: quic: loss time limit variable computed but not used

<loss_time_limit> is the loss time limit computed from <time_sent> packet
transmission timestamps in qc_packet_loss_lookup() to identify the packets which
have been lost. This latter timestamp variable was used in place of
<loss_time_limit> to distinguish such packets from others (still in fly packets).

Must be backported to 2.6

2 years agoMINOR: quic: New "quic-cc-algo" bind keyword
Frédéric Lécaille [Mon, 11 Jul 2022 08:24:21 +0000 (10:24 +0200)] 
MINOR: quic: New "quic-cc-algo" bind keyword

As it could be interesting to be able to choose the QUIC control congestion
algorithm to be used by listener, add "quic-cc-algo" new keyword to do so.
Update the documentation consequently.

Must be backported to 2.6.

2 years agoMEDIUM: quic: Cubic congestion control algorithm implementation
Frédéric Lécaille [Wed, 1 Jun 2022 13:06:58 +0000 (15:06 +0200)] 
MEDIUM: quic: Cubic congestion control algorithm implementation

Cubic is the congestion control algorithm used by default by the Linux kernel
since 2.6.15 version. This algorithm is supposed to achieve good scalability and
fairness between flows using the same network path, it should also be used by QUIC
by default. This patch implements this algorithm and select it as default algorithm
for the congestion control.

Must be backported to 2.6.

2 years agoMINOR: quic: Congestion control architecture refactoring
Frédéric Lécaille [Tue, 31 May 2022 07:40:44 +0000 (09:40 +0200)] 
MINOR: quic: Congestion control architecture refactoring

Ease the integration of new congestion control algorithm to come.
Move the congestion controller state to a private array of uint32_t
to stop using a union. We do not want to continue using such long
paths cc->algo_state.<algo>.<var> to modify the internal state variable
for each algorithm.

Must be backported to 2.6

2 years agoBUG/MEDIUM: mux-quic: fix missing EOI flag to prevent streams leaks
Amaury Denoyelle [Fri, 29 Jul 2022 13:34:12 +0000 (15:34 +0200)] 
BUG/MEDIUM: mux-quic: fix missing EOI flag to prevent streams leaks

On H3 DATA frame transfer from the client, some streams are not properly
closed by the upper layer, despite all transfer operation completed.
Data integrity is not impacted but this will prevent the stream timeout
to fire and thus keep the owner session opened.

In most cases, sessions are closed on QUIC idle timeout, but it may stay
forever if a client emits PING frames at a regular interval to maintain
it.

This bug is caused by a missing EOI stream desc flag on certain
condition in qc_rcv_buf(). To be triggered, we have to use the
optimization when conn-stream buffer is empty and can be swapped with
qcs buffer. The problem is that it will skip the function body for
default copy but also a condition to check if EOI must be set. Thus this
bug does not happens for every H3 post requets : it requires that
conn-stream buffer is empty on last qc_rcv_buf() invocation.

This was reproduced more frequently when using ngtcp2 client with one or
multiple streams :
$ ngtcp2-client -m POST -d ~/infra/html/10K 127.0.0.1 20443 \
  http://127.0.0.1:20443/post

This may fix at least partially github issue #1801.

This must be backported up to 2.6.

2 years agoMINOR: cli: warning on _getsocks when socket were closed
William Lallemand [Thu, 28 Jul 2022 13:33:41 +0000 (15:33 +0200)] 
MINOR: cli: warning on _getsocks when socket were closed

The previous attempt was reverted because it would emit a warning when
the sockets are still in the process when a reload failed, so this was
an expected 2nd try.

This warning however, will be displayed if a new process successfully
get the previous sockets AND the sendable number of sockets is 0.

This way the user will be warned if he tried to get the sockets fromt
the wrong process.

2 years agoRevert "MINOR: cli: emit a warning when _getsocks was used more than once"
William Lallemand [Wed, 27 Jul 2022 11:55:54 +0000 (13:55 +0200)] 
Revert "MINOR: cli: emit a warning when _getsocks was used more than once"

This reverts commit 519cd2021bda11231d461f5974b4e321d0b4eb29.

This was reverted because it's still useful to have access to _getsosks
when the previous reload failed.

2 years agoBUG/MINOR: mworker: PROC_O_LEAVING used but not updated
William Lallemand [Wed, 27 Jul 2022 09:57:12 +0000 (11:57 +0200)] 
BUG/MINOR: mworker: PROC_O_LEAVING used but not updated

Since commit 2be557f ("MEDIUM: mworker: seamless reload use the internal
sockpair"), we are using the PROC_O_LEAVING flag to determine which
sockpair worker will be used with -x during the next reload.

However in mworker_reexec(), the PROC_O_LEAVING flag is not updated, it
is only updated at startup in mworker_env_to_proc_list().

This could be a problem when a remaining process is still in the list,
it could be selected as the current worker, and its socket will be used
even if _getsocks doesn't work anymore on it. (bug #1803)

This patch fixes the issue by updating the PROC_O_LEAVING flag in
mworker_proc_list_to_env() just before using it in mworker_reexec()

Must be backported to 2.6.

2 years agoMINOR: cli: emit a warning when _getsocks was used more than once
William Lallemand [Wed, 27 Jul 2022 09:48:54 +0000 (11:48 +0200)] 
MINOR: cli: emit a warning when _getsocks was used more than once

The _getsocks CLI command can be used only once, after that the sockets
are not available anymore.

Emit a warning when the command was already used once.

2 years agoBUG/MINOR: fd: always remove late updates when freeing fd_updt[]
Willy Tarreau [Tue, 26 Jul 2022 17:06:17 +0000 (19:06 +0200)] 
BUG/MINOR: fd: always remove late updates when freeing fd_updt[]

Christopher found that since commit 8e2c0fa8e ("MINOR: fd: delete unused
updates on close()") we may crash in a late stop due to an fd_delete()
in the main thread performed after all threads have deleted the fd_updt[]
array. Prior to that commit that didn't happen because we didn't touch
the updates on this path, but now it may happen. We don't care about these
ones anyway since the poller is stopped, so let's just wipe them by
resetting their counter before freeing the array.

No backport is needed as this is only 2.7.

2 years agoMEDIUM: resolvers: continue startup if network is unavailable
William Lallemand [Tue, 26 Jul 2022 08:50:09 +0000 (10:50 +0200)] 
MEDIUM: resolvers: continue startup if network is unavailable

When haproxy starts with a resolver section, and there is a default one
since 2.6 which use /etc/resolv.conf, it tries to do a connect() with the UDP
socket in order to check if the routes of the system allows to reach the
server.

This check is too much restrictive as it won't prevent any runtime
failure.

Relax the check by making it a warning instead of a fatal alert.

This must be backported in 2.6.

2 years agoDEBUG: fd: split the fd check
William Lallemand [Tue, 26 Jul 2022 08:35:24 +0000 (10:35 +0200)] 
DEBUG: fd: split the fd check

Split the BUG_ON(fd < 0 || fd >= global.maxsock) so it's easier to know
if it quits because of a -1.

2 years agoRevert "BUG/MINOR: peers: set the proxy's name to the peers section name"
Christopher Faulet [Mon, 25 Jul 2022 13:10:44 +0000 (15:10 +0200)] 
Revert "BUG/MINOR: peers: set the proxy's name to the peers section name"

This reverts commit 356866accefd16458f0e3c335d1b784e24e86d2d.

It seems that an undocumented expectation of peers is based on the peers
proxy name to determine if the local peer is fully configured or not. Thus
because of the commit above, we are no longer able to detect incomplete
peers sections.

On side effect of this bug is a segfault when HAProxy is stopped/reloaded if
we try to perform a local resync on a mis-configured local peer. So waiting
for a better solution, the patch is reverted.

This patch must be backported as far as 2.5.

2 years agoMINOR: sockpair: move send_fd_uxst() error message in caller
William Lallemand [Mon, 25 Jul 2022 14:04:38 +0000 (16:04 +0200)] 
MINOR: sockpair: move send_fd_uxst() error message in caller

Move the ha_alert() in send_fd_uxst() in the callers and add the FD
numbers in the message.

2 years agoBUG/MINOR: sockpair: wrong return value for fd_send_uxst()
William Lallemand [Mon, 25 Jul 2022 13:51:30 +0000 (15:51 +0200)] 
BUG/MINOR: sockpair: wrong return value for fd_send_uxst()

The fd_send_uxst() function which is used to send a socket over the
socketpair returns 1 upon error instead of -1, which means the error
case of the sendmsg() is never catched correctly.

Must be backported as far as 1.9.

2 years agoDEBUG: fd: detect possibly invalid tgid in fd_insert()
Willy Tarreau [Mon, 25 Jul 2022 13:42:41 +0000 (15:42 +0200)] 
DEBUG: fd: detect possibly invalid tgid in fd_insert()

Since the API is still a bit young, let's make sure nobody tries to
assign and FD to a group not strictly 1..MAX_TGROUPS as that would
indicate a bug.

Note: some of these might be relaxed to BUG_ON_HOT() in the future

2 years agoBUG/MAJOR: poller: drop FD's tgid when masks don't match
Willy Tarreau [Mon, 25 Jul 2022 13:39:21 +0000 (15:39 +0200)] 
BUG/MAJOR: poller: drop FD's tgid when masks don't match

A bug was introduced in 2.7-dev2 by commit 1f947cb39 ("MAJOR: poller:
only touch/inspect the update_mask under tgid protection"): once the
FD's tgid is held, we would forget to drop it in case the update mask
doesn't match, resulting in random watchdog panics of older processes
on successive reloads.

This should fix issue #1798. Thanks to Christian for the report and
to Christopher for the reproducer.

No backport is needed.

2 years agoBUG/MEDIUM: master: force the thread count earlier
Willy Tarreau [Fri, 22 Jul 2022 15:35:49 +0000 (17:35 +0200)] 
BUG/MEDIUM: master: force the thread count earlier

Christopher bisected that recent commit d0b73bca71 ("MEDIUM: listener:
switch bind_thread from global to group-local") broke the master socket
in that only the first out of the Nth initial connections would work,
where N is the number of threads, after which they all work.

The cause is that the master socket was bound to multiple threads,
despite global.nbthread being 1 there, so the incoming connection load
balancing would try to send incoming connections to non-existing threads,
however the bind_thread mask would nonetheless include multiple threads.

What happened is that in 1.9 we forced "nbthread" to 1 in the master's poll
loop with commit b3f2be338b ("MEDIUM: mworker: use the haproxy poll loop").

In 2.0, nbthread detection was enabled by default in commit 149ab779cc
("MAJOR: threads: enable one thread per CPU by default"). From this point
on, the operation above is unsafe because everything during startup is
performed with nbthread corresponding to the default value, then it
changes to one when starting the polling loop. But by then we weren't
using the wait mode except for reload errors, so even if it would have
happened nobody would have noticed.

In 2.5 with commit fab0fdce9 ("MEDIUM: mworker: reexec in waitpid mode
after successful loading") we started to rexecute all the time, not just
for errors, so as to release precious resources and to possibly spot bugs
that were rarely exposed in this mode. By then the incoming connection LB
was enforcing all_threads_mask on the listener's thread mask so that the
incorrect value was being corrected while using it.

Finally in 2.7 commit d0b73bca71 ("MEDIUM: listener: switch bind_thread
from global to group-local") replaces the all_threads_mask there with
the listener's bind_thread, but that one was never adjusted by the
starting master, whose thread group was filled to N threads by the
automatic detection during early setup.

The best approach here is to set nbthread to 1 very early in init()
when we're in the master in wait mode, so that we don't try to guess
the best value and don't end up with incorrect bindings anymore. This
patch does this and also sets nbtgroups to 1 in preparation for a
possible future where this will also be automatically calculated.

There is no need to backport this patch since no other versions were
affected, but if it were to be discovered that the incorrect bind mask
on some of the master's FDs could be responsible for any trouble in
older versions, then the backport should be safe (provided that
nbtgroups is dropped of course).

2 years agoBUG/MINOR: backend: Fallback on RR algo if balance on source is impossible
Christopher Faulet [Fri, 22 Jul 2022 15:07:32 +0000 (17:07 +0200)] 
BUG/MINOR: backend: Fallback on RR algo if balance on source is impossible

If the loadbalancing is performed on the source IP address, an internal
error was returned on error. So for an applet on the client side (for
instance an SPOE applet) or for a client connected to a unix socket, an
internal error is returned.

However, when other LB algos fail, a fallback on round-robin is
performed. There is no reson to not do the same here.

This patch should fix the issue #1797. It must be backported to all
supported versions.

2 years agoBUG/MEDIUM: stconn: Only reset connect expiration when processing backend side
Christopher Faulet [Wed, 20 Jul 2022 11:24:04 +0000 (13:24 +0200)] 
BUG/MEDIUM: stconn: Only reset connect expiration when processing backend side

Since commit ae024ced0 ("MEDIUM: stream-int/stream: Use connect expiration
instead of SI expiration"), the connect expiration date is per-stream. So
there is only one expiration date instead of one per side, front and
back. So when a stream-connector is processed, we must test if it is a
frontend or a backend stconn before updating the connect expiration
date. Indeed, the frontend stconn must not reset the connect expiration
date.

This bug may have several side effect. One known bug is about peer sessions
blocked because the frontend peer applet is in ST_CLO state and its backend
connection is in ST_TAR state but without connect expiration date.

This patch should fix the issue #1791 and #1792. It must be backported to
2.6.

2 years agoBUILD: add detection for unsupported compiler models
Willy Tarreau [Thu, 21 Jul 2022 07:55:22 +0000 (09:55 +0200)] 
BUILD: add detection for unsupported compiler models

As reported in github issue #1765, some people get trapped into building
haproxy and companion libraries on Windows using a compiler following the
LLP64 model. This has no chance to work, and definitely causes nasty bugs
everywhere when pointers are passed as longs. Let's save them time and
detect this at boot time.

The message and detection was factored with the existing one for -fwrapv
since we need the same info and actions.

This should be backported to all recent supported versions (the ones
that are likely to be tried on such platforms when people don't know).

2 years agoBUG/MEDIUM: mworker: proc_self incorrectly set crashes upon reload
William Lallemand [Wed, 20 Jul 2022 22:52:43 +0000 (00:52 +0200)] 
BUG/MEDIUM: mworker: proc_self incorrectly set crashes upon reload

When updating from 2.4 to 2.6, the child->reloads++ instruction changed
place, resulting in a former worker from the 2.4 process, still
identified as a current worker once in 2.6, because its reload counter
is still 0.

Unfortunately this counter is used to chose the mworker_proc structure
that will be used for the new worker.

What happens next, is that the mworker_proc structure of the previous
process is selected, and this one has ipc_fd[1] set to -1, because this
structure was supposed to be in the master.

The process then forks, and mworker_sockpair_register_per_thread() tries
to register ipc_fd[1] which is set to -1, instead of the fd of the new
socketpair.

This patch fixes the issue by checking if child->pid is equal to -1 when
selecting proc_self. This way we could be sure it wasn't a previous
process.

Should fix issue #1785.

This must be backported as far as 2.4 to fix the issue related to the
reload computation difference. However backporting it in every stable
branch will enforce the reload process.

2 years agoBUG/MAJOR: mux_quic: fix invalid PROTOCOL_VIOLATION on POST data overlap
Frédéric Lécaille [Mon, 4 Jul 2022 07:54:58 +0000 (09:54 +0200)] 
BUG/MAJOR: mux_quic: fix invalid PROTOCOL_VIOLATION on POST data overlap

Stream data reception is incorrect when dealing with a partially new
offset with some data already consumed out of the RX buffer. In this
case, data length is adjusted but not the data buffer. In most cases,
ncb_add() operation will be rejected as already stored data does not
correspond with the new inserted offset. This will result in an invalid
CONNECTION_CLOSE with PROTOCOL_VIOLATION.

To fix this, buffer pointer is advanced while the length is reduced.

This can be reproduced with a POST request and patching haproxy to call
qcc_recv() multiple times by copying a quic_stream frame with different
offsets.

Must be backported to 2.6.

2 years agoBUG/MINOR: mworker/cli: relative pid prefix not validated anymore
William Lallemand [Wed, 20 Jul 2022 12:30:56 +0000 (14:30 +0200)] 
BUG/MINOR: mworker/cli: relative pid prefix not validated anymore

Since e8422bf ("MEDIUM: global: remove the relative_pid from global and
mworker"), the relative pid prefix is not tested anymore on the master
CLI. Which means any value will fall into the "1" process.

Since we removed the nbproc, only the "1" and the "0" (master) value are
correct, any other value should return an error.

Fix issue #1793.

This must be backported as far as 2.5.

2 years agoMINOR: ssl: enhance ca-file error emitting
William Lallemand [Tue, 19 Jul 2022 16:03:16 +0000 (18:03 +0200)] 
MINOR: ssl: enhance ca-file error emitting

Enhance the errors and warnings when trying to load a ca-file with
ssl_store_load_locations_file().

Add errors from ERR_get_error() and strerror to give more information to
the user.

2 years agoMINOR: init: load OpenSSL error strings
William Lallemand [Tue, 19 Jul 2022 16:13:29 +0000 (18:13 +0200)] 
MINOR: init: load OpenSSL error strings

Load OpenSSL Error strings in order to be able to output reason strings.

This is mandatory to be able to use ERR_reason_error_string().

2 years agoBUG/MEDIUM: fd/threads: fix incorrect thread selection in wakeup broadcast
Willy Tarreau [Tue, 19 Jul 2022 13:58:00 +0000 (15:58 +0200)] 
BUG/MEDIUM: fd/threads: fix incorrect thread selection in wakeup broadcast

In commit cfdd20a0b ("MEDIUM: fd: support broadcasting updates for foreign
groups in updt_fd_polling") we decided to pick a random thread number among
a set of candidates for a wakeup in case we need an instant change. But the
thread count range was wrong (MAX_THREADS) instead of tg->count, resulting
in random crashes when thread groups are > 1 and MAX_THREADS > 64.

No backport is needed, this was introduced in 2.7-dev2.

2 years agoBUG/MINOR: fd: Properly init the fd state in fd_insert()
Christopher Faulet [Tue, 19 Jul 2022 10:04:18 +0000 (12:04 +0200)] 
BUG/MINOR: fd: Properly init the fd state in fd_insert()

When a new fd is inserted in the fdtab array, its state is initialized. The
"newstate" variable is used to compute the right state (0 by default, but
FD_ET_POSSIBLE flag is set if edge-triggered is supported for the fd).
However, this variable is never used and the fd state is always set to 0.

Now, the fd state is initialized with "newstate" variable.

This bug was introduced by commit ddedc1662 ("MEDIUM: fd: make
fd_insert/fd_delete atomically update fd.tgid"). No backport needed.

2 years agoBUILD: debug: Add braces to if statement calling only CHECK_IF()
Christopher Faulet [Tue, 19 Jul 2022 09:53:46 +0000 (11:53 +0200)] 
BUILD: debug: Add braces to if statement calling only CHECK_IF()

In src/ev_epoll.c, a CHECK_IF() is guarded by an if statement. So, when the
macro is empty, GCC (at least 11.3.1) is not happy because there is an if
statement with an empty body without braces... It is handled by
"-Wempty-body" option.

So, braces are added and GCC is now happy.

No backport needed.

2 years agoBUG/MINOR: quic: do not send CONNECTION_CLOSE_APP in initial/handshake
Amaury Denoyelle [Mon, 18 Jul 2022 12:11:50 +0000 (14:11 +0200)] 
BUG/MINOR: quic: do not send CONNECTION_CLOSE_APP in initial/handshake

As specified by RFC 9000, it is forbidden to send a CONNECTION_CLOSE of
type 0x1d (CONNECTION_CLOSE_APP) in an Initial or Handshake packet. It
must be converted to type 0x1c (CONNECTION_CLOSE) with APPLICATION_ERROR
code.

CONNECTION_CLOSE_APP are generated by QUIC MUX interaction. Thus,
special care must be taken when dealing with a 0-RTT packet, as this is
the only case where the MUX can be instantiated and quic-conn still on
the Initial or Handshake encryption level.

To enforce RFC 9000, xprt build packet function is now responsible to
translate a CONNECTION_CLOSE_APP if still on Initial/Handshake
encryption. This process is done in a dedicated function named
qc_build_cc_frm().

Without this patch, BUG_ON() statement in qc_build_frm() will be
triggered when building a CONNECTION_CLOSE_APP frame on Initial or
Handshake level. This is because QUIC_FT_CONNECTION_CLOSE_APP frame
builder mask does not allow these encryption levels, as opposed to
QUIC_FT_CONNECTION_CLOSE builder. This crash was reproduced by modifying
the H3 layer to force emission of a CONNECTION_CLOSE_APP on first frame
of a 0-RTT session.

Note however that CONNECTION_CLOSE emission during Handshake is a
complicated process for the server. For the moment, this is still
incomplete on haproxy side. RFC 9000 requires to emit it multiple times
in several packets under different encryption levels, depending on what
we know about the client encryption context.

This patch should be backported up to 2.6.

2 years agoBUG/MINOR: tools: fix statistical_prng_range()'s output range
Willy Tarreau [Mon, 18 Jul 2022 17:09:55 +0000 (19:09 +0200)] 
BUG/MINOR: tools: fix statistical_prng_range()'s output range

This function was added by commit 84ebfabf7 ("MINOR: tools: add
statistical_prng_range() to get a random number over a range") but it
contains a bug on the range, since mul32hi() covers the whole input
range, we must pass it range-1. For now it didn't have any impact, but
if used to find an array's index it will cause trouble.

This should be backported to 2.4.

2 years agoBUG/MINOR: ssl: allow duplicate certificates in ca-file directories
William Lallemand [Mon, 18 Jul 2022 16:42:52 +0000 (18:42 +0200)] 
BUG/MINOR: ssl: allow duplicate certificates in ca-file directories

It looks like OpenSSL 1.0.2 returns an error when trying to insert a
certificate whis is already present in a X509_STORE.

This patch simply ignores the X509_R_CERT_ALREADY_IN_HASH_TABLE error if
emitted.

Should fix part of issue #1780.

Must be backported in 2.6.

2 years agoBUG/MINOR: resolvers: shut off the warning for the default resolvers
William Lallemand [Mon, 18 Jul 2022 12:12:17 +0000 (14:12 +0200)] 
BUG/MINOR: resolvers: shut off the warning for the default resolvers

When the resolv.conf file is empty or there is no resolv.conf file, an
empty resolvers will be created, which emits a warning during the
postparsing step.

This patch fixes the problem by freeing the resolvers section if the
parsing failed or if the nameserver list is empty.

Must be backported in 2.6, the previous patch which introduces
resolvers_destroy() is also required.

2 years agoMINOR: resolvers: resolvers_destroy() deinit and free a resolver
William Lallemand [Mon, 18 Jul 2022 12:09:58 +0000 (14:09 +0200)] 
MINOR: resolvers: resolvers_destroy() deinit and free a resolver

Split the resolvers_deinit() function into resolvers_destroy() and
resolvers_deinit() in order to be able to free a unique resolvers
section.

2 years agoBUG/MEDIUM: tools: avoid calling dlsym() in static builds (try 2)
Willy Tarreau [Mon, 18 Jul 2022 11:58:17 +0000 (13:58 +0200)] 
BUG/MEDIUM: tools: avoid calling dlsym() in static builds (try 2)

The first approach in commit 288dc1d8e ("BUG/MEDIUM: tools: avoid calling
dlsym() in static builds") relied on dlopen() but on certain configs (at
least gcc-4.8+ld-2.27+glibc-2.17) it used to catch situations where it
ought not fail.

Let's have a second try on this using dladdr() instead. The variable was
renamed "build_is_static" as it's exactly what's being detected there.
We could even take it for reporting in -vv though that doesn't seem very
useful. At least the variable was made global to ease inspection via the
debugger, or in case it's useful later.

Now it properly detects a static build even with gcc-4.4+glibc-2.11.1 and
doesn't crash anymore.

2 years agoBUILD: makefile: Fix install(1) handling for OpenBSD/NetBSD/Solaris/AIX
Brad Smith [Sat, 16 Jul 2022 09:18:50 +0000 (05:18 -0400)] 
BUILD: makefile: Fix install(1) handling for OpenBSD/NetBSD/Solaris/AIX

Add a new INSTALL variable to allow overridiing the flags passed to
install(1). install(1) on OpenBSD/NetBSD/Solaris/AIX does not support
the -v flag. With the new INSTALL variable and handling only use the
-v flag with the Linux targets.