]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 years agoMINOR: mux: remove last occurences of qcc ring buffer
Amaury Denoyelle [Tue, 12 Oct 2021 16:14:12 +0000 (18:14 +0200)] 
MINOR: mux: remove last occurences of qcc ring buffer

The mux tx buffers have been rewritten with buffers attached to qcs
instances. qc_buf_available and qc_get_buf functions are updated to
manipulates qcs. All occurences of the unused qcc ring buffer are
removed to ease the code maintenance.

3 years agoMEDIUM: mux-quic: defer stream shut if remaining tx data
Amaury Denoyelle [Fri, 8 Oct 2021 15:57:41 +0000 (17:57 +0200)] 
MEDIUM: mux-quic: defer stream shut if remaining tx data

Defer the shutting of a qcs if there is still data in its tx buffers. In
this case, the conn_stream is closed but the qcs is kept with a new flag
QC_SF_DETACH.

On ACK reception, the xprt wake up the shut_tl tasklet if the stream is
flagged with QC_SF_DETACH. This tasklet is responsible to free the qcs
and possibly the qcc when all bidirectional streams are removed.

3 years agoMINOR: mux-quic: implement standard method to detect if qcc is dead
Amaury Denoyelle [Fri, 8 Oct 2021 15:57:03 +0000 (17:57 +0200)] 
MINOR: mux-quic: implement standard method to detect if qcc is dead

For the moment, a quic connection is considered dead if it has no
bidirectional streams left on it. This test is implemented via
qcc_is_dead function. It can be reused to properly close the connection
when needed.

3 years agoCLEANUP: h3: remove dead code
Amaury Denoyelle [Thu, 7 Oct 2021 14:27:36 +0000 (16:27 +0200)] 
CLEANUP: h3: remove dead code

Remove unused function. This will simplify code maintenance.

3 years agoMINOR: mux-quic: standardize h3 settings sending
Amaury Denoyelle [Thu, 7 Oct 2021 14:26:12 +0000 (16:26 +0200)] 
MINOR: mux-quic: standardize h3 settings sending

Use same buffer management to send h3 settings as for streams. This
simplify the code maintenance with unused function removed.

3 years agoMEDIUM: h3: properly manage tx buffers for large data
Amaury Denoyelle [Wed, 6 Oct 2021 12:53:13 +0000 (14:53 +0200)] 
MEDIUM: h3: properly manage tx buffers for large data

Properly handle tx buffers management in h3 data sending. If there is
not enough contiguous space, the buffer is first realigned. If this is
not enough, the stream is flagged with QC_SF_BLK_MROOM waiting for the
buffer to be emptied.

If a frame on a stream is successfully pushed for sending, the stream is
called if it was flagged with QC_SF_BLK_MROOM.

3 years agoMEDIUM: mux-quic: rationalize tx buffers between qcc/qcs
Amaury Denoyelle [Tue, 5 Oct 2021 09:45:58 +0000 (11:45 +0200)] 
MEDIUM: mux-quic: rationalize tx buffers between qcc/qcs

Remove the tx mux ring buffers in qcs, which should be in the qcc. For
the moment, use a simple architecture with 2 simple tx buffers in the
qcs.

The first buffer is used by the h3 layer to prepare the data. The mux
send operation transfer these into the 2nd buffer named xprt_buf. This
buffer is only freed when an ACK has been received.

This architecture is functional but not optimal for two reasons :
- it won't limit the buffer usage by connection
- each transfer on a new stream requires an allocation

3 years agoREGTESTS: ssl: Use mostly TLSv1.2 in ssl_errors test
Remi Tricot-Le Breton [Wed, 13 Oct 2021 09:21:02 +0000 (11:21 +0200)] 
REGTESTS: ssl: Use mostly TLSv1.2 in ssl_errors test

In order for the test to run with OpenSSL 1.0.2 the test will now mostly
use TLSv1.2 and use TLS 1.3 only on some specific tests (covered by
preconditions).

3 years agoREGTESTS: ssl: Reenable ssl_errors test for OpenSSL only
Remi Tricot-Le Breton [Mon, 11 Oct 2021 13:34:14 +0000 (15:34 +0200)] 
REGTESTS: ssl: Reenable ssl_errors test for OpenSSL only

The test is strongly dependent on the way the errors are output by the
SSL library so it is not possible to perform the same checks when using
OpenSSL or LibreSSL. It is then reenabled for OpenSSL (whatever the
version) but still disabled for LibreSSL.
This limitation is added thanks to the new ssllib_name_startswith
precondition check.

3 years agoREGTESTS: ssl: Fix ssl_errors test for OpenSSL v3
Remi Tricot-Le Breton [Mon, 11 Oct 2021 13:34:13 +0000 (15:34 +0200)] 
REGTESTS: ssl: Fix ssl_errors test for OpenSSL v3

The OpenSSL error codes for the same errors are not consistent between
OpenSSL versions. The ssl_errors test needs to be modified to only take
into account a fixed part of those error codes.
This patch focuses on the reason part of the error code by applying a
mask on the error code (whose size varies depending on the lib version).

3 years agoMINOR: ssl: Add ssllib_name_startswith precondition
Remi Tricot-Le Breton [Mon, 11 Oct 2021 13:34:12 +0000 (15:34 +0200)] 
MINOR: ssl: Add ssllib_name_startswith precondition

This new ssllib_name_startswith precondition check can be used to
distinguish application linked with OpenSSL from the ones linked with
other SSL libraries (LibreSSL or BoringSSL namely). This check takes a
string as input and returns 1 when the SSL library's name starts with
the given string. It is based on the OpenSSL_version function which
returns the same output as the "openssl version" command.

3 years agoREGTESTS: ssl: Fix references to removed option in test description
Remi Tricot-Le Breton [Mon, 11 Oct 2021 13:34:11 +0000 (15:34 +0200)] 
REGTESTS: ssl: Fix references to removed option in test description

The log-error-via-logformat option was removed in commit
3d6350e1084ca806d9f78c3802665e235e1fbf27 and was replaced by a dedicated
error-log-format option. The references to this option need to be
removed from the test's description.

3 years agoCI: github: switch to OpenSSL 3.0.0
William Lallemand [Tue, 12 Oct 2021 15:02:58 +0000 (17:02 +0200)] 
CI: github: switch to OpenSSL 3.0.0

Switch the OpenSSL 3.0.0alpha17 version to the final 3.0.0 release.

Part of OpenSSL 3.0.0 portage. (ticket #1276)

3 years agoBUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()`
Tim Duesterhus [Mon, 11 Oct 2021 16:51:08 +0000 (18:51 +0200)] 
BUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()`

Set an `lua_atpanic()` handler before calling `hlua_prepend_path()` in
`hlua_config_prepend_path()`.

This prevents the process from abort()ing when `hlua_prepend_path()` fails
for some reason.

see GitHub Issue #1409

This is a very minor issue that can't happen in practice. No backport needed.

3 years agoCLEANUP: stream: Properly indent current_rule line in "show sess all"
Christopher Faulet [Tue, 12 Oct 2021 09:10:31 +0000 (11:10 +0200)] 
CLEANUP: stream: Properly indent current_rule line in "show sess all"

This line is not related to the response channel but to the stream. Thus it
must be indented at the same level as stream-interfaces, connections,
channels...

3 years agoMINOR: stream: report the current filter in "show sess all" when known
Christopher Faulet [Tue, 12 Oct 2021 09:02:48 +0000 (11:02 +0200)] 
MINOR: stream: report the current filter in "show sess all" when known

Filters can block the stream on pre/post analysis for any reason and it can
be useful to report it in "show sess all". So now, a "current_filter" extra
line is reported for each channel if a filter is blocking the analysis. Note
that this does not catch the TCP/HTTP payload analysis because all
registered filters are always evaluated when more data are received.

3 years agoMINOR: stream: report the current rule in "show sess all" when known
Willy Tarreau [Mon, 11 Oct 2021 07:49:03 +0000 (09:49 +0200)] 
MINOR: stream: report the current rule in "show sess all" when known

Sometimes an HTTP or TCP rule may take time to complete because it is
waiting for external data (e.g. "wait-for-body", "do-resolve"), and it
can be useful to report the action and the location of that rule in
"show sess all". Here for streams blocked on such a rule, there will
now be a "current_line" extra line reporting this. Note that this does
not catch rulesets which are re-evaluated from the start on each change
(e.g. tcp-request content waiting for changes) but only when a specific
rule is being paused.

3 years agoMINOR: rules: add a file name and line number to act_rules
Willy Tarreau [Mon, 11 Oct 2021 07:13:07 +0000 (09:13 +0200)] 
MINOR: rules: add a file name and line number to act_rules

These ones are passed on rule creation for the sole purpose of being
reported in "show sess", which is not done yet. For now the entries
are allocated upon rule creation and freed in free_act_rules().

3 years agoMINOR: rules: add a new function new_act_rule() to allocate act_rules
Willy Tarreau [Mon, 11 Oct 2021 06:49:26 +0000 (08:49 +0200)] 
MINOR: rules: add a new function new_act_rule() to allocate act_rules

Rules are currently allocated using calloc() by their caller, which does
not make it very convenient to pass more information such as the file
name and line number.

This patch introduces new_act_rule() which performs the malloc() and
already takes in argument the ruleset (ACT_F_*), the file name and the
line number. This saves the caller from having to assing ->from, and
will allow to improve the internal storage with more info.

3 years agoMINOR: initcall: Rename __GLOBL and __GLOBL1.
Olivier Houchard [Fri, 8 Oct 2021 23:53:03 +0000 (01:53 +0200)] 
MINOR: initcall: Rename __GLOBL and __GLOBL1.

Rename __GLOBL and __GLOBL1 to __HA_GLOBL and __HA_GLOBL1, as the former are
already defined on FreeBSD.

This should be backported to 2.4, 2.3 and 2.2.

3 years ago[RELEASE] Released version 2.5-dev9 v2.5-dev9
Willy Tarreau [Fri, 8 Oct 2021 16:22:24 +0000 (18:22 +0200)] 
[RELEASE] Released version 2.5-dev9

Released version 2.5-dev9 with the following main changes :
    - head-truc
    - REGTESTS: lua: test the httpclient:get() feature
    - Revert "head-truc"
    - BUG/MEDIUM: httpclient: replace ist0 by istptr
    - MINOR: config: use a standard parser for the "nbthread" keyword
    - CLEANUP: init: remove useless test against MAX_THREADS in affinity loop
    - MEDIUM: init: de-uglify the per-thread affinity setting
    - MINOR: init: extract the setup and end of threads to their own functions
    - MINOR: log: Try to get the status code when MUX_EXIT_STATUS is retrieved
    - MINOR: mux-h1: Set error code if possible when MUX_EXIT_STATUS is returned
    - MINOR: mux-h1: Be able to set custom status code on parsing error
    - MEDIUM: mux-h1: Reject HTTP/1.0 GET/HEAD/DELETE requests with a payload
    - MEDIUM: h1: Force close mode for invalid uses of T-E header
    - BUG/MINOR: mux-h1/mux-fcgi: Sanitize TE header to only send "trailers"
    - MINOR: http: Add 422-Unprocessable-Content error message
    - MINOR: h1: Change T-E header parsing to fail if chunked encoding is found twice
    - BUG/MEDIUM: mux-h1/mux-fcgi: Reject messages with unknown transfer encoding
    - REGTESTS: Add script to validate T-E header parsing
    - REORG: pools: move default settings to defaults.h
    - DOC: peers: fix doc "enable" statement on "peers" sections
    - MINOR: Makefile: add MEMORY_POOLS to the list of DEBUG_xxx options
    - MINOR: ssl: Set connection error code in case of SSL read or write fatal failure
    - MINOR: ssl: Rename ssl_bc_hsk_err to ssl_bc_err
    - MINOR: ssl: Store the last SSL error code in case of read or write failure
    - REGTESTS: ssl: enable show_ssl_ocspresponse.vtc again
    - REGTESTS: ssl: enable ssl_crt-list_filters.vtc again
    - BUG/MEDIUM: lua: fix wakeup condition from sleep()
    - BUG/MAJOR: lua: use task_wakeup() to properly run a task once
    - MINOR: arg: Be able to forbid unresolved args when building an argument list
    - BUG/MINOR: tcpcheck: Don't use arg list for default proxies during parsing
    - BUG/MINOR: tcp-rules: Stop content rules eval on read error and end-of-input
    - MINOR: tasks: catch TICK_ETERNITY with BUG_ON() in __task_queue()
    - REGTESTS: ssl: show_ssl_ocspresponse w/ freebsd won't use base64
    - REGTESTS: ssl: wrong feature cmd in show_ssl_ocspresponse.vtc
    - CLEANUP: tasks: remove the long-unused work_lists
    - MINOR: task: provide 3 task_new_* wrappers to simplify the API
    - MINOR: time: uninline report_idle() and move it to task.c
    - REORG: sched: move idle time calculation from time.h to task.h
    - REORG: sched: move the stolen CPU time detection to sched_entering_poll()
    - BUG/MEDIUM: filters: Fix a typo when a filter is attached blocking the release
    - BUG/MEDIUM: http-ana: Clear request analyzers when applying redirect rule
    - MINOR: httpclient: destroy() must free the headers and the ists
    - MINOR: httpclient: set HTTPCLIENT_F_ENDED only in release
    - MINOR: httpclient: stop_and_destroy() ask the applet to autokill
    - MINOR: httpclient: test if started during stop_and_destroy()
    - MINOR: httpclient/lua: implement garbage collection
    - BUG/MEDIUM: httpclient/lua: crash because of b_xfer and get_trash_chunk()
    - MINOR: httpclient: destroy checks if a client was started but not stopped
    - BUG/MINOR: httpclient/lua: does not process headers when failed
    - MINOR: httpclient/lua: supports headers via named arguments
    - CLEANUP: server: always include the storage for SSL settings
    - CLEANUP: sample: rename sample_conv_var2smp() to *_sint
    - CLEANUP: sample: uninline sample_conv_var2smp_str()
    - MINOR: sample: provide a generic var-to-sample conversion function
    - BUG/MEDIUM: sample: properly verify that variables cast to sample
    - BUILD: action: add the relevant structures for function arguments
    - BUILD: extcheck: needs to include stream-t.h
    - BUILD: hlua: needs to include stream-t.h
    - BUILD: stats: define several missing structures in stats.h
    - BUILD: resolvers: define missing types in resolvers.h
    - BUILD: httpclient: include missing ssl_sock-t
    - BUILD: sample: include openssl-compat
    - BUILD: http_ana: need to include proxy-t to get redirect_rule
    - BUILD: http_rules: requires http_ana-t.h for REDIRECT_*
    - BUILD: vars: need to include xxhash
    - BUILD: peers: need to include eb{32/mb/pt}tree.h
    - BUILD: ssl_ckch: include ebpttree.h in ssl_ckch.c
    - BUILD: compiler: add the container_of() and container_of_safe() macros
    - BUILD: idleconns: include missing ebmbtree.h at several places
    - BUILD: connection: connection.h needs list.h and server.h
    - BUILD: tree-wide: add missing http_ana.h from many places
    - BUILD: cfgparse-ssl: add missing errors.h
    - BUILD: tcp_sample: include missing errors.h and session-t.h
    - BUILD: mworker: mworker-prog needs time.h for the 'now' variable
    - BUILD: tree-wide: add several missing activity.h
    - BUILD: compat: fix -Wundef on SO_REUSEADDR
    - CLEANUP: pools: pools-t.h doesn't need to include thread-t.h
    - REORG: pools: uninline the UAF allocator and force-inline the rest
    - REORG: thread: uninline the lock-debugging code
    - MINOR: thread/debug: replace nsec_now() with now_mono_time()
    - CLEANUP: remove some unneeded includes from applet-t.h
    - REORG: listener: move bind_conf_alloc() and listener_state_str() to listener.c
    - CLEANUP: listeners: do not include openssl-compat
    - CLEANUP: servers: do not include openssl-compat
    - REORG: ssl: move ssl_sock_is_ssl() to connection.h and rename it
    - CLEANUP: mux_fcgi: remove dependency on ssl_sock
    - CLEANUP: ssl/server: move ssl_sock_set_srv() to srv_set_ssl() in server.c
    - REORG: ssl-sock: move the sslconns/totalsslconns counters to global
    - REORG: sample: move the crypto samples to ssl_sample.c
    - REORG: sched: moved samp_time and idle_time to task.c as well
    - REORG: time/ticks: move now_ms and global_now_ms definitions to ticks.h
    - CLEANUP: tree-wide: remove unneeded include time.h in ~20 files
    - REORG: activity: uninline activity_count_runtime()
    - REORG: acitvity: uninline sched_activity_entry()
    - CLEANUP: stream: remove many unneeded includes from stream-t.h
    - CLEANUP: stick-table: no need to include socket nor in.h
    - MINOR: connection: use uint64_t for the hashes
    - REORG: connection: move the hash-related stuff to connection.c
    - REORG: connection: uninline conn_notify_mux() and conn_delete_from_tree()
    - REORG: server: uninline the idle conns management functions
    - REORG: ebtree: split structures into their own file ebtree-t.h
    - CLEANUP: tree-wide: only include ebtree-t from type files
    - REORG: connection: move the largest inlines from connection.h to connection.c
    - CLEANUP: connection: do not include http_ana!
    - CLEANUP: connection: remove unneeded tcpcheck-t.h and use only session-t.h
    - REORG: connection: uninline the rest of the alloc/free stuff
    - REORG: task: uninline the loop time measurement code
    - CLEANUP: time: move a few configurable defines to defaults.h
    - CLEANUP: fd: do not include time.h
    - REORG: fd: uninline compute_poll_timeout()
    - CLENAUP: wdt: use ha_tkill() instead of accessing pthread directly
    - REORG: thread: move the thread init/affinity/stop to thread.c
    - REORG: thread: move ha_get_pthread_id() to thread.c
    - MINOR: thread: use a dedicated static pthread_t array in thread.c
    - CLEANUP: thread: uninline ha_tkill/ha_tkillall/ha_cpu_relax()
    - DOC: configuration: add clarification on escaping in keyword arguments
    - BUG/MINOR: task: fix missing include with DEBUG_TASK
    - MINOR: pools: report the amount used by thread caches in "show pools"
    - MINOR: quic: Distinguish packet and SSL read enc. level in traces
    - MINOR: quic: Add a function to dump SSL stack errors
    - MINOR: quic: BUG_ON() SSL errors.
    - MINOR: quic: Fix SSL error issues (do not use ssl_bio_and_sess_init())
    - BUG/MEDIUM: mux-quic: reinsert all streams in by_id tree
    - BUG/MAJOR: xprt-quic: do not queue qc timer if not set
    - MINOR: mux-quic: release connection if no more bidir streams
    - BUG/MAJOR: quic: remove qc from receiver cids tree on free
    - BUG/MEDIUM: mux_h2: Handle others remaining read0 cases on partial frames
    - MINOR: qpack: do not encode invalid http status code
    - MINOR: qpack: support non-indexed http status code encoding
    - MINOR: qpack: fix memory leak on huffman decoding
    - CLEANUP: mux-quic: remove unused code
    - BUG/MINOR: quic: fix includes for compilation
    - BUILD: connection: avoid a build warning on FreeBSD with SO_USER_COOKIE
    - BUILD: init: avoid a build warning on FreeBSD with USE_PROCCTL
    - REORG: time: move time-keeping code and variables to clock.c
    - REORG: clock: move the updates of cpu/mono time to clock.c
    - MINOR: activity: get the run_time from the clock updates
    - CLEANUP: clock: stop exporting before_poll and after_poll
    - REORG: clock: move the clock_id initialization to clock.c
    - REORG: clock/wdt: move wdt timer initialization to clock.c
    - MINOR: clock: move the clock_ids to clock.c
    - MINOR: wdt: move wd_timer to wdt.c
    - CLEANUP: wdt: do not remap SI_TKILL to SI_LWP, test the values directly
    - REORG: thread/sched: move the task_per_thread stuff to thread_ctx
    - REORG: thread/clock: move the clock parts of thread_info to thread_ctx
    - REORG: thread/sched: move the thread_info flags to the thread_ctx
    - REORG: thread/sched: move the last dynamic thread_info to thread_ctx
    - MINOR: thread: make "ti" a const pointer and clean up thread_info a bit
    - MINOR: threads: introduce a minimalistic notion of thread-group
    - MINOR: global: add a new "thread-groups" directive
    - MINOR: global: add a new "thread-group" directive
    - MINOR: threads: make tg point to the current thread's group
    - MEDIUM: threads: automatically assign threads to groups
    - MINOR: threads: set the group ID and its bit in the thread group
    - MINOR: threads: set the tid, ltid and their bit in thread_cfg
    - MEDIUM: threads: replace ha_set_tid() with ha_set_thread()
    - MINOR: threads: add the current group ID in thread-local "tgid" variable
    - MINOR: debug: report the group and thread ID in the thread dumps
    - MEDIUM: listeners: support the definition of thread groups on bind lines
    - MINOR: threads: add a new function to resolve config groups and masks
    - MEDIUM: config: resolve relative threads on bind lines to absolute ones
    - MEDIUM: stick-table: never learn the "conn_cur" value from peers

3 years agoMEDIUM: stick-table: never learn the "conn_cur" value from peers
Willy Tarreau [Fri, 8 Oct 2021 15:53:12 +0000 (17:53 +0200)] 
MEDIUM: stick-table: never learn the "conn_cur" value from peers

There have been a large number of issues reported with conn_cur
synchronization because the concept is wrong. In an active-passive
setup, pushing the local connections count from the active node to
the passive one will result in the passive node to have a higher
counter than the real number of connections. Due to this, after a
switchover, it will never be able to close enough connections to
go down to zero. The same commonly happens on reloads since the new
process preloads its values from the old process, and if no connection
happens for a key after the value is learned, it is impossible to reset
the previous ones. In active-active setups it's a bit different, as the
number of connections reflects the number on the peer that pushed last.

This patch solves this by marking the "conn_cur" local and preventing
it from being learned from peers. It is still pushed, however, so that
any monitoring system that collects values from the peers will still
see it.

The patch is tiny and trivially backportable. While a change of behavior
in stable branches is never welcome, it remains possible to fix issues
if reports become frequent.

3 years agoMEDIUM: config: resolve relative threads on bind lines to absolute ones
Willy Tarreau [Wed, 29 Sep 2021 17:02:25 +0000 (19:02 +0200)] 
MEDIUM: config: resolve relative threads on bind lines to absolute ones

Now threads ranges specified on bind lines will be turned to effective
ones that will lead to a usable thread mask and a group ID.

3 years agoMINOR: threads: add a new function to resolve config groups and masks
Willy Tarreau [Wed, 29 Sep 2021 16:59:47 +0000 (18:59 +0200)] 
MINOR: threads: add a new function to resolve config groups and masks

In the configuration sometimes we'll omit a thread group number to designate
a global thread number range, and sometimes we'll mention the group and
designate IDs within that group. The operation is more complex than it
seems due to the need to check for ranges spanning between multiple groups
and determining groups from threads from bit masks and remapping bit masks
between local/global.

This patch adds a function to perform this operation, it takes a group and
mask on input and updates them on output. It's designed to be used by "bind"
lines but will likely be usable at other places if needed.

For situations where specified threads do not exist in the group, we have
the choice in the code between silently fixing the thread set or failing
with a message. For now the better option seems to return an error, but if
it turns out to be an issue we can easily change that in the future. Note
that it should only happen with "x/even" when group x only has one thread.

3 years agoMEDIUM: listeners: support the definition of thread groups on bind lines
Willy Tarreau [Wed, 29 Sep 2021 16:50:31 +0000 (18:50 +0200)] 
MEDIUM: listeners: support the definition of thread groups on bind lines

This extends the "thread" statement of bind lines to support an optional
thread group number. When unspecified (0) it's an absolute thread range,
and when specified it's one relative to the thread group. Masks are still
used so no more than 64 threads may be specified at once, and a single
group is possible. The directive is not used for now.

3 years agoMINOR: debug: report the group and thread ID in the thread dumps
Willy Tarreau [Mon, 13 Sep 2021 17:24:47 +0000 (19:24 +0200)] 
MINOR: debug: report the group and thread ID in the thread dumps

Now thread dumps will report the thread group number and the ID within
this group. Note that this is still quite limited because some masks
are calculated based on the thread in argument while they have to be
performed against a group-level thread ID.

3 years agoMINOR: threads: add the current group ID in thread-local "tgid" variable
Willy Tarreau [Thu, 30 Sep 2021 06:00:11 +0000 (08:00 +0200)] 
MINOR: threads: add the current group ID in thread-local "tgid" variable

This is the equivalent of "tid" for ease of access. In the future if we
make th_cfg a pure thread-local array (not a pointer), it may make sense
to move it there.

3 years agoMEDIUM: threads: replace ha_set_tid() with ha_set_thread()
Willy Tarreau [Tue, 28 Sep 2021 07:43:11 +0000 (09:43 +0200)] 
MEDIUM: threads: replace ha_set_tid() with ha_set_thread()

ha_set_tid() was randomly used either to explicitly set thread 0 or to
set any possibly incomplete thread during boot. Let's replace it with
a pointer to a valid thread or NULL for any thread. This allows us to
check that the designated threads are always valid, and to ignore the
thread 0's mapping when setting it to NULL, and always use group 0 with
it during boot.

The initialization code is also cleaner, as we don't pass ugly casts
of a thread ID to a pointer anymore.

3 years agoMINOR: threads: set the tid, ltid and their bit in thread_cfg
Willy Tarreau [Tue, 28 Sep 2021 06:53:11 +0000 (08:53 +0200)] 
MINOR: threads: set the tid, ltid and their bit in thread_cfg

This will be a convenient way to communicate the thread ID and its
local ID in the group, as well as their respective bits when creating
the threads or when only a pointer is given.

3 years agoMINOR: threads: set the group ID and its bit in the thread group
Willy Tarreau [Tue, 28 Sep 2021 06:50:02 +0000 (08:50 +0200)] 
MINOR: threads: set the group ID and its bit in the thread group

This will ease the reporting of the current thread group ID when coming
from the thread itself, especially since it returns the visible ID,
starting at 1.

3 years agoMEDIUM: threads: automatically assign threads to groups
Willy Tarreau [Mon, 27 Sep 2021 08:10:26 +0000 (10:10 +0200)] 
MEDIUM: threads: automatically assign threads to groups

This takes care of unassigned threads groups and places unassigned
threads there, in a more or less balanced way. Too sparse allocations
may still fail though. For now with a maximum group number fixed to 1
nothing can really fail.

3 years agoMINOR: threads: make tg point to the current thread's group
Willy Tarreau [Tue, 28 Sep 2021 06:58:49 +0000 (08:58 +0200)] 
MINOR: threads: make tg point to the current thread's group

A the "tg" thread-local variable now always points to the current
thread group. It's pre-initializd to the first one during boot and is
set to point to the thread's one by ha_set_tid(). This last one takes
care of checking whether the thread group was assigned or not because
it may be called during boot before threads are initialized.

3 years agoMINOR: global: add a new "thread-group" directive
Willy Tarreau [Mon, 27 Sep 2021 11:55:10 +0000 (13:55 +0200)] 
MINOR: global: add a new "thread-group" directive

This registers a mapping of threads to groups by enumerating for each thread
what group it belongs to, and marking the group as assigned. It takes care of
checking for redefinitions, overlaps, and holes. It supports both individual
numbers and ranges. The thread group is referenced from the thread config.

3 years agoMINOR: global: add a new "thread-groups" directive
Willy Tarreau [Wed, 22 Sep 2021 10:07:23 +0000 (12:07 +0200)] 
MINOR: global: add a new "thread-groups" directive

This is used to configure the number of thread groups. For now it can
only be 1.

3 years agoMINOR: threads: introduce a minimalistic notion of thread-group
Willy Tarreau [Mon, 13 Sep 2021 16:11:26 +0000 (18:11 +0200)] 
MINOR: threads: introduce a minimalistic notion of thread-group

This creates a struct tgroup_info which knows the thread ID of the first
thread in a group, and the number of threads in it. For now there's only
one thread group supported in the configuration, but it may be forced to
other values for development purposes by defining MAX_TGROUPS, and it's
enabled even when threads are disabled and will need to remain accessible
during boot to keep a simple enough internal API.

For the purpose of easing the configurations which do not specify a thread
group, we're starting group numbering at 1 so that thread group 0 can be
"undefined" (i.e. for "bind" lines or when binding tasks).

The goal will be to later move there some global items that must be
made per-group.

3 years agoMINOR: thread: make "ti" a const pointer and clean up thread_info a bit
Willy Tarreau [Fri, 1 Oct 2021 14:29:27 +0000 (16:29 +0200)] 
MINOR: thread: make "ti" a const pointer and clean up thread_info a bit

We want to make sure that the current thread_info accessed via "ti" will
remain constant, so that we don't accidentally place new variable parts
there and so that the compiler knows that info retrieved from there is
not expected to have changed between two function calls.

Only a few init locations had to be adjusted to use the array and the
rest is unaffected.

3 years agoREORG: thread/sched: move the last dynamic thread_info to thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 17:02:18 +0000 (19:02 +0200)] 
REORG: thread/sched: move the last dynamic thread_info to thread_ctx

The last 3 fields were 3 list heads that are per-thread, and which are:
  - the pool's LRU head
  - the buffer_wq
  - the streams list head

Moving them into thread_ctx completes the removal of dynamic elements
from the struct thread_info. Now all these dynamic elements are packed
together at a single place for a thread.

3 years agoREORG: thread/sched: move the thread_info flags to the thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 16:48:37 +0000 (18:48 +0200)] 
REORG: thread/sched: move the thread_info flags to the thread_ctx

The TI_FL_STUCK flag is manipulated by the watchdog and scheduler
and describes the apparent life/death of a thread so it changes
all the time and it makes sense to move it to the thread's context
for an active thread.

3 years agoREORG: thread/clock: move the clock parts of thread_info to thread_ctx
Willy Tarreau [Thu, 30 Sep 2021 16:28:49 +0000 (18:28 +0200)] 
REORG: thread/clock: move the clock parts of thread_info to thread_ctx

The "thread_info" name was initially chosen to store all info about
threads but since we now have a separate per-thread context, there is
no point keeping some of its elements in the thread_info struct.

As such, this patch moves prev_cpu_time, prev_mono_time and idle_pct to
thread_ctx, into the thread context, with the scheduler parts. Instead
of accessing them via "ti->" we now access them via "th_ctx->", which
makes more sense as they're totally dynamic, and will be required for
future evolutions. There's no room problem for now, the structure still
has 84 bytes available at the end.

3 years agoREORG: thread/sched: move the task_per_thread stuff to thread_ctx
Willy Tarreau [Fri, 1 Oct 2021 09:30:33 +0000 (11:30 +0200)] 
REORG: thread/sched: move the task_per_thread stuff to thread_ctx

The scheduler contains a lot of stuff that is thread-local and not
exclusively tied to the scheduler. Other parts (namely thread_info)
contain similar thread-local context that ought to be merged with
it but that is even less related to the scheduler. However moving
more data into this structure isn't possible since task.h is high
level and cannot be included everywhere (e.g. activity) without
causing include loops.

In the end, it appears that the task_per_thread represents most of
the per-thread context defined with generic types and should simply
move to tinfo.h so that everyone can use them.

The struct was renamed to thread_ctx and the variable "sched" was
renamed to "th_ctx". "sched" used to be initialized manually from
run_thread_poll_loop(), now it's initialized by ha_set_tid() just
like ti, tid, tid_bit.

The memset() in init_task() was removed in favor of a bss initialization
of the array, so that other subsystems can put their stuff in this array.

Since the tasklet array has TL_CLASSES elements, the TL_* definitions
was moved there as well, but it's not a problem.

The vast majority of the change in this patch is caused by the
renaming of the structures.

3 years agoCLEANUP: wdt: do not remap SI_TKILL to SI_LWP, test the values directly
Willy Tarreau [Fri, 8 Oct 2021 13:31:04 +0000 (15:31 +0200)] 
CLEANUP: wdt: do not remap SI_TKILL to SI_LWP, test the values directly

We used to remap SI_TKILL to SI_LWP when SI_TKILL was not available
(e.g. FreeBSD) but that's ugly and since we need this only in a single
switch/case block in wdt.c it's even simpler and cleaner to perform the
two tests there, so let's do this.

3 years agoMINOR: wdt: move wd_timer to wdt.c
Willy Tarreau [Fri, 8 Oct 2021 13:23:26 +0000 (15:23 +0200)] 
MINOR: wdt: move wd_timer to wdt.c

The watchdog timer had no more reason for being shared with the struct
thread_info since the watchdog is the only user now. Let's remove it
from the struct and move it to a static array in wdt.c. This removes
some ifdefs and the need for the ugly mapping to empty_t that might be
subject to a cast to a long when compared to TIMER_INVALID. Now timer_t
is not known outside of wdt.c and clock.c anymore.

3 years agoMINOR: clock: move the clock_ids to clock.c
Willy Tarreau [Fri, 8 Oct 2021 13:09:17 +0000 (15:09 +0200)] 
MINOR: clock: move the clock_ids to clock.c

This removes the knowledge of clockid_t from anywhere but clock.c, thus
eliminating a source of includes burden. The unused clock_id field was
removed from thread_info, and the definition setting of clockid_t was
removed from compat.h. The most visible change is that the function
now_cpu_time_thread() now takes the thread number instead of a tinfo
pointer.

3 years agoREORG: clock/wdt: move wdt timer initialization to clock.c
Willy Tarreau [Fri, 8 Oct 2021 12:48:30 +0000 (14:48 +0200)] 
REORG: clock/wdt: move wdt timer initialization to clock.c

The code that deals with timer creation for the WDT was moved to clock.c
and is called with the few relevant arguments. This removes the need for
awareness of clock_id from wdt.c and as such saves us from having to
share it outside. The timer_t is also known only from both ends but not
from the public API so that we don't have to create a fake timer_t
anymore on systems which do not support it (e.g. macos).

3 years agoREORG: clock: move the clock_id initialization to clock.c
Willy Tarreau [Fri, 8 Oct 2021 10:27:54 +0000 (12:27 +0200)] 
REORG: clock: move the clock_id initialization to clock.c

This was previously open-coded in run_thread_poll_loop(). Now that
we have clock.c dedicated to such stuff, let's move the code there
so that we don't need to keep such ifdefs nor to depend on the
clock_id.

3 years agoCLEANUP: clock: stop exporting before_poll and after_poll
Willy Tarreau [Fri, 8 Oct 2021 09:38:30 +0000 (11:38 +0200)] 
CLEANUP: clock: stop exporting before_poll and after_poll

We don't need to export them anymore so let's make them static.

3 years agoMINOR: activity: get the run_time from the clock updates
Willy Tarreau [Fri, 8 Oct 2021 09:34:46 +0000 (11:34 +0200)] 
MINOR: activity: get the run_time from the clock updates

Instead of fiddling with before_poll and after_poll in
activity_count_runtime(), the function is now called by
clock_entering_poll() which passes it the number of microseconds
spent working. This allows to remove all calls to
activity_count_runtime() from the pollers.

3 years agoREORG: clock: move the updates of cpu/mono time to clock.c
Willy Tarreau [Fri, 8 Oct 2021 08:43:59 +0000 (10:43 +0200)] 
REORG: clock: move the updates of cpu/mono time to clock.c

The entering_poll/leaving_poll/measure_idle functions that were hard
to classify and used to move to various locations have now been placed
into clock.c since it's precisely about time-keeping. The functions
were renamed to clock_*. The samp_time and idle_time values are now
static since there is no reason for them to be read from outside.

3 years agoREORG: time: move time-keeping code and variables to clock.c
Willy Tarreau [Fri, 8 Oct 2021 07:33:24 +0000 (09:33 +0200)] 
REORG: time: move time-keeping code and variables to clock.c

There is currently a problem related to time keeping. We're mixing
the functions to perform calculations with the os-dependent code
needed to retrieve and adjust the local time.

This patch extracts from time.{c,h} the parts that are solely dedicated
to time keeping. These are the "now" or "before_poll" variables for
example, as well as the various now_*() functions that make use of
gettimeofday() and clock_gettime() to retrieve the current time.

The "tv_*" functions moved there were also more appropriately renamed
to "clock_*".

Other parts used to compute stolen time are in other files, they will
have to be picked next.

3 years agoBUILD: init: avoid a build warning on FreeBSD with USE_PROCCTL
Willy Tarreau [Fri, 8 Oct 2021 13:55:13 +0000 (15:55 +0200)] 
BUILD: init: avoid a build warning on FreeBSD with USE_PROCCTL

It was brought by a variable declared after some statements in commit
21185970c ("MINOR: proc: setting the process to produce a core dump on
FreeBSD."). It's worth noting that some versions of clang seem to ignore
-Wdeclaration-after-statement by default. No backport is needed.

3 years agoBUILD: connection: avoid a build warning on FreeBSD with SO_USER_COOKIE
Willy Tarreau [Fri, 8 Oct 2021 13:52:27 +0000 (15:52 +0200)] 
BUILD: connection: avoid a build warning on FreeBSD with SO_USER_COOKIE

It was brough by an unneeded addition of a local variable after a test
in commit f7f53afcf ("BUILD/MEDIUM: tcp: set-mark setting support for
FreeBSD."). No backport needed.

3 years agoBUG/MINOR: quic: fix includes for compilation
Amaury Denoyelle [Thu, 7 Oct 2021 14:44:05 +0000 (16:44 +0200)] 
BUG/MINOR: quic: fix includes for compilation

Fix missing includes in quic code following the general recent include
reorganization. This fixes the compilation error with QUIC enabled.

3 years agoCLEANUP: mux-quic: remove unused code
Amaury Denoyelle [Tue, 5 Oct 2021 09:43:50 +0000 (11:43 +0200)] 
CLEANUP: mux-quic: remove unused code

Remove unused code in mux-quic. This is mostly code related to the
backend side. This code is untested for the moment, its removal will
simplify the code maintenance.

3 years agoMINOR: qpack: fix memory leak on huffman decoding
Amaury Denoyelle [Thu, 30 Sep 2021 15:14:55 +0000 (17:14 +0200)] 
MINOR: qpack: fix memory leak on huffman decoding

Remove an unneeded strdup invocation during QPACK huffman decoding. A
temporary storage buffer is passed by the function and exists after
decoding so no need to duplicate memory here.

3 years agoMINOR: qpack: support non-indexed http status code encoding
Amaury Denoyelle [Thu, 30 Sep 2021 12:47:55 +0000 (14:47 +0200)] 
MINOR: qpack: support non-indexed http status code encoding

If a HTTP status code is not present in the QPACK static table, encode
it with a literal field line with name reference.

3 years agoMINOR: qpack: do not encode invalid http status code
Amaury Denoyelle [Thu, 30 Sep 2021 12:47:32 +0000 (14:47 +0200)] 
MINOR: qpack: do not encode invalid http status code

Ensure that the HTTP status code is valid before encoding with QPACK. An
error is return if this is not the case.

3 years agoBUG/MEDIUM: mux_h2: Handle others remaining read0 cases on partial frames
Christopher Faulet [Fri, 8 Oct 2021 06:56:00 +0000 (08:56 +0200)] 
BUG/MEDIUM: mux_h2: Handle others remaining read0 cases on partial frames

We've found others places where the read0 is ignored because of an
incomplete frame parsing. This time, it happens during parsing of
CONTINUATION frames.

When frames are parsed, incomplete frames are properly handled and
H2_CF_DEM_SHORT_READ flag is set. It is also true for HEADERS
frames. However, for CONTINUATION frames, there is an exception. Besides
parsing the current frame, we try to peek header of the next one to merge
payload of both frames, the current one and the next one. Idea is to create
a sole HEADERS frame before parsing the payload. However, in this case, it
is possible to have an incomplete frame too, not the current one but the
next one. From the demux point of view, the current frame is complete. We
must go to the internal function h2c_decode_headers() to detect an
incomplete frame. And this case was not identified and fixed when
H2_CF_DEM_SHORT_READ flag was introduced in the commit b5f7b5296
("BUG/MEDIUM: mux-h2: Handle remaining read0 cases on partial frames")

This bug was reported in a comment of the issue #1362. The patch must be
backported as far as 2.0.

3 years agoBUG/MAJOR: quic: remove qc from receiver cids tree on free
Amaury Denoyelle [Thu, 30 Sep 2021 09:03:28 +0000 (11:03 +0200)] 
BUG/MAJOR: quic: remove qc from receiver cids tree on free

Remove the quic_conn from the receiver connection_ids tree on
quic_conn_free. This fixes a crash due to dangling references in the
tree after a quic connection release.

This operation must be conducted under the listener lock. For this
reason, the quic_conn now contains a reference to its attached listener.

3 years agoMINOR: mux-quic: release connection if no more bidir streams
Amaury Denoyelle [Fri, 24 Sep 2021 08:05:30 +0000 (10:05 +0200)] 
MINOR: mux-quic: release connection if no more bidir streams

Use the count of bidirectional streams to call qc_release in qc_detach.
We cannot inspect the by_id tree because uni-streams are never removed
from it. This allows the connection to be properly freed.

3 years agoBUG/MAJOR: xprt-quic: do not queue qc timer if not set
Amaury Denoyelle [Tue, 5 Oct 2021 12:42:25 +0000 (14:42 +0200)] 
BUG/MAJOR: xprt-quic: do not queue qc timer if not set

Do not queue the pto/loss-detection timer if set to TICK_ETERNITY. This
usage is invalid with the scheduler and cause a BUG_ON trigger.

3 years agoBUG/MEDIUM: mux-quic: reinsert all streams in by_id tree
Amaury Denoyelle [Fri, 24 Sep 2021 08:03:16 +0000 (10:03 +0200)] 
BUG/MEDIUM: mux-quic: reinsert all streams in by_id tree

It is required that all qcs streams are in the by_id tree for the xprt
to function correctly. Without this, some ACKs are not properly emitted
by xprt.

Note that this change breaks the free of the connection because the
condition eb_is_empty in qc_detach is always true. This will be fixed in
a following patch.

3 years agoMINOR: quic: Fix SSL error issues (do not use ssl_bio_and_sess_init())
Frédéric Lécaille [Tue, 28 Sep 2021 07:51:23 +0000 (09:51 +0200)] 
MINOR: quic: Fix SSL error issues (do not use ssl_bio_and_sess_init())

It seems it was a bad idea to use the same function as for TCP ssl sockets
to initialize the SSL session objects for QUIC with ssl_bio_and_sess_init().
Indeed, this had as very bad side effects to generate SSL errors due
to the fact that such BIOs initialized for QUIC could not finally be controlled
via the BIO_ctrl*() API, especially BIO_ctrl() function used by very much other
internal OpenSSL functions (BIO_push(), BIO_pop() etc).
Others OpenSSL base QUIC implementation do not use at all BIOs to configure
QUIC connections. So, we decided to proceed the same way as ngtcp2 for instance:
only initialize an SSL object and call SSL_set_quic_method() to set its
underlying method. Note that calling this function silently disable this option:
SSL_OP_ENABLE_MIDDLEBOX_COMPAT.
We implement qc_ssl_sess_init() to initialize SSL sessions for QUIC connections
to do so with a retry in case of allocation failure as this is done by
ssl_bio_and_sess_init(). We also modify the code part for haproxy servers.

3 years agoMINOR: quic: BUG_ON() SSL errors.
Frédéric Lécaille [Tue, 28 Sep 2021 07:05:59 +0000 (09:05 +0200)] 
MINOR: quic: BUG_ON() SSL errors.

As this QUIC implementation is still experimental, let's BUG_ON()
very important SSL handshake errors.
Also dump the SSL errors before BUG_ON().

3 years agoMINOR: quic: Add a function to dump SSL stack errors
Frédéric Lécaille [Tue, 28 Sep 2021 07:04:12 +0000 (09:04 +0200)] 
MINOR: quic: Add a function to dump SSL stack errors

This has been very helpful to fix SSL related issues.

3 years agoMINOR: quic: Distinguish packet and SSL read enc. level in traces
Frédéric Lécaille [Thu, 23 Sep 2021 16:10:56 +0000 (18:10 +0200)] 
MINOR: quic: Distinguish packet and SSL read enc. level in traces

This is only to distinguish the encryption level of packet traces from
the TLS stack current read encryption level.

3 years agoMINOR: pools: report the amount used by thread caches in "show pools"
Willy Tarreau [Thu, 7 Oct 2021 14:29:31 +0000 (16:29 +0200)] 
MINOR: pools: report the amount used by thread caches in "show pools"

The "show pools" command provides some "allocated" and "used" estimates
on the pools objects, but this applies to the shared pool and the "used"
includes what is currently assigned to thread-local caches. It's possible
to know how much each thread uses, so let's dump the total size allocated
by thread caches as an estimate. It's only done when pools are enabled,
which explains why the patch adds quite a lot of ifdefs.

3 years agoBUG/MINOR: task: fix missing include with DEBUG_TASK
Amaury Denoyelle [Thu, 7 Oct 2021 14:37:42 +0000 (16:37 +0200)] 
BUG/MINOR: task: fix missing include with DEBUG_TASK

Following include reorganzation, there is some missing include files for
task.h when compiling with DEBUG_TASK :
- activity.h for task_profiling_mask
- time.h for now_mono_time()

This is present since the following commit
  d8b325c74826bdb02759f62c41a00455dbae3431
  REORG: task: uninline the loop time measurement code

No need to backport this.

3 years agoDOC: configuration: add clarification on escaping in keyword arguments
Thayne McCombs [Mon, 4 Oct 2021 07:02:58 +0000 (01:02 -0600)] 
DOC: configuration: add clarification on escaping in keyword arguments

Add a more precise description on how backslash escaping is different
than the top-level parser, and give examples of how to handle single
quotes inside arguments.

3 years agoCLEANUP: thread: uninline ha_tkill/ha_tkillall/ha_cpu_relax()
Willy Tarreau [Wed, 6 Oct 2021 21:33:20 +0000 (23:33 +0200)] 
CLEANUP: thread: uninline ha_tkill/ha_tkillall/ha_cpu_relax()

These ones are rarely used or only to waste CPU cycles waiting, and are
the last ones requiring system includes in thread.h. Let's uninline them
and move them to thread.c.

3 years agoMINOR: thread: use a dedicated static pthread_t array in thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:53:51 +0000 (22:53 +0200)] 
MINOR: thread: use a dedicated static pthread_t array in thread.c

This removes the thread identifiers from struct thread_info and moves
them only in static array in thread.c since it's now the only file that
needs to touch it. It's also the only file that needs to include
pthread.h, beyond haproxy.c which needs it to start the poll loop. As
a result, much less system includes are needed and the LoC reduced by
around 3%.

3 years agoREORG: thread: move ha_get_pthread_id() to thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:44:28 +0000 (22:44 +0200)] 
REORG: thread: move ha_get_pthread_id() to thread.c

It's the last function which directly accesses the pthread_t, let's move
it to thread.c and leave a static inline for non-thread.

3 years agoREORG: thread: move the thread init/affinity/stop to thread.c
Willy Tarreau [Wed, 6 Oct 2021 20:22:40 +0000 (22:22 +0200)] 
REORG: thread: move the thread init/affinity/stop to thread.c

haproxy.c still has to deal with pthread-specific low-level stuff that
is OS-dependent. We should not have to deal with this there, and we do
not need to access pthread anywhere else.

Let's move these 3 functions to thread.c and keep empty inline ones for
when threads are disabled.

3 years agoCLENAUP: wdt: use ha_tkill() instead of accessing pthread directly
Willy Tarreau [Wed, 6 Oct 2021 19:43:38 +0000 (21:43 +0200)] 
CLENAUP: wdt: use ha_tkill() instead of accessing pthread directly

Instead of calling pthread_kill() directly on the pthread_t let's
call ha_tkill() which does the same by itself. This will help isolate
pthread_t.

3 years agoREORG: fd: uninline compute_poll_timeout()
Willy Tarreau [Wed, 6 Oct 2021 17:55:29 +0000 (19:55 +0200)] 
REORG: fd: uninline compute_poll_timeout()

It's not needed to inline it at all (one call per loop) and it introduces
dependencies, let's move it to fd.c.

Removing the few remaining includes that came with it further reduced
by ~0.2% the LoC and the build time is now below 6s.

3 years agoCLEANUP: fd: do not include time.h
Willy Tarreau [Wed, 6 Oct 2021 17:44:15 +0000 (19:44 +0200)] 
CLEANUP: fd: do not include time.h

It's not needed at all here.

3 years agoCLEANUP: time: move a few configurable defines to defaults.h
Willy Tarreau [Wed, 6 Oct 2021 17:36:47 +0000 (19:36 +0200)] 
CLEANUP: time: move a few configurable defines to defaults.h

TV_ETERNITY, TV_ETERNITY_MS and MAX_DELAY_MS may be configured and
ought to be in defaults.h so that they can be inherited from everywhere
without including time.h and could also be redefined if neede
(particularly for MAX_DELAY_MS).

3 years agoREORG: task: uninline the loop time measurement code
Willy Tarreau [Wed, 6 Oct 2021 17:25:38 +0000 (19:25 +0200)] 
REORG: task: uninline the loop time measurement code

It's pointless to inline this, it's called exactly once per poll loop,
and it depends on time.h which is quite deep. Let's move that to task.c
along with sched_report_idle().

3 years agoREORG: connection: uninline the rest of the alloc/free stuff
Willy Tarreau [Wed, 6 Oct 2021 17:11:10 +0000 (19:11 +0200)] 
REORG: connection: uninline the rest of the alloc/free stuff

The remaining large functions are those allocating/initializing and
occasionally freeing connections, conn_streams and sockaddr. Let's
move them to connection.c. In fact, cs_free() is the only one-liner
but let's move it along with the other ones since a call will be
small compared to the rest of the work done there.

3 years agoCLEANUP: connection: remove unneeded tcpcheck-t.h and use only session-t.h
Willy Tarreau [Wed, 6 Oct 2021 17:03:12 +0000 (19:03 +0200)] 
CLEANUP: connection: remove unneeded tcpcheck-t.h and use only session-t.h

No need to include the full session stuff, we only need the type. Also,
remove the unneeded tcpcheck types.

3 years agoCLEANUP: connection: do not include http_ana!
Willy Tarreau [Wed, 6 Oct 2021 16:57:44 +0000 (18:57 +0200)] 
CLEANUP: connection: do not include http_ana!

It makes no sense to have http_ana here, that's used at higher levels.

3 years agoREORG: connection: move the largest inlines from connection.h to connection.c
Willy Tarreau [Wed, 6 Oct 2021 16:48:28 +0000 (18:48 +0200)] 
REORG: connection: move the largest inlines from connection.h to connection.c

The following inlined functions are particularly large (and probably not
inlined at all by the compiler), and together represent roughly half of
the file, while they're used at most once per connection. They were moved
to connection.c.

  conn_upgrade_mux_fe, conn_install_mux_fe, conn_install_mux_be,
  conn_install_mux_chk, conn_delete_from_tree, conn_init, conn_new,
  conn_free

3 years agoCLEANUP: tree-wide: only include ebtree-t from type files
Willy Tarreau [Wed, 6 Oct 2021 16:31:48 +0000 (18:31 +0200)] 
CLEANUP: tree-wide: only include ebtree-t from type files

No need to include the full tree management code, type files only
need the definitions. Doing so reduces the whole code size by around
3.6% and the build time is down to just 6s.

3 years agoREORG: ebtree: split structures into their own file ebtree-t.h
Willy Tarreau [Wed, 6 Oct 2021 15:55:45 +0000 (17:55 +0200)] 
REORG: ebtree: split structures into their own file ebtree-t.h

ebtree is one piece using a lot of inlines and each tree root or node
definition needed by many of our structures requires to parse and
compile all these includes, which is large and painfully slow. Let's
move the very basic definitions to their own file and include it from
ebtree.h.

3 years agoREORG: server: uninline the idle conns management functions
Willy Tarreau [Wed, 6 Oct 2021 16:30:04 +0000 (18:30 +0200)] 
REORG: server: uninline the idle conns management functions

The following functions are quite heavy and have no reason to be kept
inlined:

   srv_release_conn, srv_lookup_conn, srv_lookup_conn_next,
   srv_add_to_idle_list

They were moved to server.c. It's worth noting that they're a bit
at the edge between server and connection and that maybe we could
create an idle-conn file for these in the near future.

3 years agoREORG: connection: uninline conn_notify_mux() and conn_delete_from_tree()
Willy Tarreau [Wed, 6 Oct 2021 16:27:28 +0000 (18:27 +0200)] 
REORG: connection: uninline conn_notify_mux() and conn_delete_from_tree()

The former is far too huge to be inlined and the second is the only
one requiring an ebmb tree through all includes, let's move them to
connection.c.

3 years agoREORG: connection: move the hash-related stuff to connection.c
Willy Tarreau [Wed, 6 Oct 2021 15:14:49 +0000 (17:14 +0200)] 
REORG: connection: move the hash-related stuff to connection.c

We do not really need to have them inlined, and having xxhash.h included
by connection.h results in this 4700-lines file being processed 101 times
over the whole project, which accounts for 13.5% of the total size!
Additionally, half of the functions are only needed from connection.c.
Let's move the functions there and get rid of the painful include.

The build time is now down to 6.2s just due to this.

3 years agoMINOR: connection: use uint64_t for the hashes
Willy Tarreau [Wed, 6 Oct 2021 15:09:41 +0000 (17:09 +0200)] 
MINOR: connection: use uint64_t for the hashes

The hash type stored everywhere is XXH64_hash_t, which annoyingly forces
everyone to include the huge xxhash file. We know it's an uint64_t because
that's its purpose and the type is only made to abstract it on machines
where uint64_t is not availble. Let's switch the type to uint64_t
everywhere and avoid including xxhash from the type file.

3 years agoCLEANUP: stick-table: no need to include socket nor in.h
Willy Tarreau [Wed, 6 Oct 2021 14:43:14 +0000 (16:43 +0200)] 
CLEANUP: stick-table: no need to include socket nor in.h

The types provided by these are never present in stick_table-t.h,
let's drop them.

3 years agoCLEANUP: stream: remove many unneeded includes from stream-t.h
Willy Tarreau [Wed, 6 Oct 2021 14:39:28 +0000 (16:39 +0200)] 
CLEANUP: stream: remove many unneeded includes from stream-t.h

Plenty of includes were present there only for struct pointers resulting
in them being used from many other places. The LoC reduced again by more
than 1% by cleaning this.

3 years agoREORG: acitvity: uninline sched_activity_entry()
Willy Tarreau [Wed, 6 Oct 2021 14:26:33 +0000 (16:26 +0200)] 
REORG: acitvity: uninline sched_activity_entry()

This one is expensive in code size because it comes with xxhash.h at a
low level of dependency that's inherited at plenty of places, and for
a function does doesn't benefit from inlining and could possibly even
benefit from not being inline given that it's large and called from the
scheduler.

Moving it to activity.c reduces the LoC by 1.2% and the binary size by
~1kB.

3 years agoREORG: activity: uninline activity_count_runtime()
Willy Tarreau [Wed, 6 Oct 2021 14:22:09 +0000 (16:22 +0200)] 
REORG: activity: uninline activity_count_runtime()

This function has no reason for being inlined, it's called from non
critical places (once in pollers), is quite large and comes with
dependencies (time and freq_ctr). Let's move it to acitvity.c. That's
another 0.4% less LoC to build.

3 years agoCLEANUP: tree-wide: remove unneeded include time.h in ~20 files
Willy Tarreau [Wed, 6 Oct 2021 14:18:40 +0000 (16:18 +0200)] 
CLEANUP: tree-wide: remove unneeded include time.h in ~20 files

20 files used to have haproxy/time.h included only for now_ms, and two
were missing it for other things but used to inherit from it via other
files.

3 years agoREORG: time/ticks: move now_ms and global_now_ms definitions to ticks.h
Willy Tarreau [Wed, 6 Oct 2021 14:03:19 +0000 (16:03 +0200)] 
REORG: time/ticks: move now_ms and global_now_ms definitions to ticks.h

These are ticks, not timeval, and they're a cause for plenty of files
including time.h just to access now_ms that's only used with ticks
functions. Let's move them over there.

3 years agoREORG: sched: moved samp_time and idle_time to task.c as well
Willy Tarreau [Wed, 6 Oct 2021 13:58:46 +0000 (15:58 +0200)] 
REORG: sched: moved samp_time and idle_time to task.c as well

The idle time calculation stuff was moved to task.h by commit 6dfab112e
("REORG: sched: move idle time calculation from time.h to task.h") but
these two variables that are only maintained by task.{c,h} were still
left in time.{c,h}. They have to move as well.

3 years agoREORG: sample: move the crypto samples to ssl_sample.c
Willy Tarreau [Wed, 6 Oct 2021 13:37:17 +0000 (15:37 +0200)] 
REORG: sample: move the crypto samples to ssl_sample.c

These ones require openssl and are only built when it's enabled. There's
no point keeping them in sample.c when ssl_sample.c already deals with this
and the required includes. This also allows to remove openssl-compat.h
from sample.c and to further reduce the number of inclusions of openssl
includes, and the build time is now down to under 8 seconds.

3 years agoREORG: ssl-sock: move the sslconns/totalsslconns counters to global
Willy Tarreau [Wed, 6 Oct 2021 10:15:18 +0000 (12:15 +0200)] 
REORG: ssl-sock: move the sslconns/totalsslconns counters to global

These two counters were the only ones not in the global struct, while
the SSL freq counters or the req counts are already in it, this forces
stats.c to include ssl_sock just to know about them. Let's move them
over there with their friends. This reduces from 408 to 384 the number
of includes of opensslconf.h.

3 years agoCLEANUP: ssl/server: move ssl_sock_set_srv() to srv_set_ssl() in server.c
Willy Tarreau [Wed, 6 Oct 2021 09:48:34 +0000 (11:48 +0200)] 
CLEANUP: ssl/server: move ssl_sock_set_srv() to srv_set_ssl() in server.c

This one has nothing to do with ssl_sock as it manipulates the struct
server only. Let's move it to server.c and remove unneeded dependencies
on ssl_sock.h. This further reduces by 10% the number of includes of
opensslconf.h and by 0.5% the number of compiled lines.

3 years agoCLEANUP: mux_fcgi: remove dependency on ssl_sock
Willy Tarreau [Wed, 6 Oct 2021 09:40:11 +0000 (11:40 +0200)] 
CLEANUP: mux_fcgi: remove dependency on ssl_sock

It's not needed anymore (used to be needed for ssl_sock_is_ssl()).

3 years agoREORG: ssl: move ssl_sock_is_ssl() to connection.h and rename it
Willy Tarreau [Wed, 6 Oct 2021 09:38:44 +0000 (11:38 +0200)] 
REORG: ssl: move ssl_sock_is_ssl() to connection.h and rename it

This one doesn't use anything from an SSL context, it only checks the
type of the transport layer of a connection, thus it belongs to
connection.h. This is particularly visible due to all the ifdefs
around it in various call places.

3 years agoCLEANUP: servers: do not include openssl-compat
Willy Tarreau [Wed, 6 Oct 2021 09:23:32 +0000 (11:23 +0200)] 
CLEANUP: servers: do not include openssl-compat

This is exactly the same as for listeners, servers only include
openssl-compat to provide the SSL_CTX type to use as two pointers to
contexts, and to detect if NPN, ALPN, and cipher suites are supported,
and save up to 5 pointers in the ssl_ctx struct if not supported. This
is pointless, as these ones have all been supported for about a decade,
and including this file comes with a long dependency chain that impacts
lots of other files. The ctx was made a void*.

Now the build time was significantly reduced, from 9.2 to 8.1 seconds,
thanks to opensslconf.h being included "only" 456 times instead of 2424
previously!

The total number of lines of code compiled was reduced by 15%.