]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
2 years agoMEDIUM: channel: Use CF_WRITE_EVENT instead of CF_WRITE_PARTIAL
Christopher Faulet [Tue, 20 Dec 2022 17:10:04 +0000 (18:10 +0100)] 
MEDIUM: channel: Use CF_WRITE_EVENT instead of CF_WRITE_PARTIAL

Just like CF_READ_PARTIAL, CF_WRITE_PARTIAL is now merged with
CF_WRITE_EVENT. There a subtlety in sc_notify(). The "connect" event
(formely CF_WRITE_NULL) is now detected with
(CF_WRITE_EVENT + sc->state < SC_ST_EST).

2 years agoMEDIUM: channel: Use CF_READ_EVENT instead of CF_READ_PARTIAL
Christopher Faulet [Mon, 12 Dec 2022 07:28:55 +0000 (08:28 +0100)] 
MEDIUM: channel: Use CF_READ_EVENT instead of CF_READ_PARTIAL

CF_READ_PARTIAL flag is now merged with CF_READ_EVENT. It means
CF_READ_EVENT is set when a read0 is received (formely CF_READ_NULL) or when
data are received (formely CF_READ_ACTIVITY).

There is nothing special here, except conditions to wake the stream up in
sc_notify(). Indeed, the test was a bit changed to reflect recent
change. read0 event is now formalized by (CF_READ_EVENT + CF_SHUTR).

2 years agoREORG: channel: Rename CF_WRITE_NULL to CF_WRITE_EVENT
Christopher Faulet [Mon, 12 Dec 2022 07:11:36 +0000 (08:11 +0100)] 
REORG: channel: Rename CF_WRITE_NULL to CF_WRITE_EVENT

As for CF_READ_NULL, it appears CF_WRITE_NULL and other write events on a
channel are mainly used to wake up the stream and may be replace by on write
event.

In this patch, we introduce CF_WRITE_EVENT flag as a replacement to
CF_WRITE_EVENT_NULL. There is no breaking change for now, it is just a
rename. Gradually, other write events will be merged with this one.

2 years agoREORG: channel: Rename CF_READ_NULL to CF_READ_EVENT
Christopher Faulet [Mon, 12 Dec 2022 07:08:15 +0000 (08:08 +0100)] 
REORG: channel: Rename CF_READ_NULL to CF_READ_EVENT

CF_READ_NULL flag is not really useful and used. It is a transient event
used to wakeup the stream. As we will see, all read events on a channel may
be resumed to only one and are all used to wake up the stream.

In this patch, we introduce CF_READ_EVENT flag as a replacement to
CF_READ_NULL. There is no breaking change for now, it is just a
rename. Gradually, other read events will be merged with this one.

2 years agoMINOR: channel: Don't test CF_READ_NULL while CF_SHUTR is enough
Christopher Faulet [Mon, 12 Dec 2022 06:53:18 +0000 (07:53 +0100)] 
MINOR: channel: Don't test CF_READ_NULL while CF_SHUTR is enough

If CF_READ_NULL flag is set on a channel, it implies a shutdown for reads
was performed and CF_SHUTR is also set on this channel. Thus, there is no
reason to test is any of these flags is present, testing CF_SHUTR is enough.

2 years agoMINOR: ssl: Remove mention of ckch_store in error message of cli command
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:49 +0000 (12:02 +0100)] 
MINOR: ssl: Remove mention of ckch_store in error message of cli command

When calling 'update ssl ocsp-response' with an unknown certificate file
name, the error message would mention a "ckch_store" which is an
internal structure unknown by users.

2 years agoMINOR: ssl: Limit ocsp_uri buffer size to minimum
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:48 +0000 (12:02 +0100)] 
MINOR: ssl: Limit ocsp_uri buffer size to minimum

The ocsp_uri field of the certificate_ocsp structure was a 16k buffer
when it could be hand allocated to just the required size to store the
OCSP uri. This field is now behaving the same way as the sctl and
ocsp_response buffers of the ckch_store structure.

2 years agoBUG/MINOR: ssl: Fix OCSP_CERTID leak when same certificate is used multiple times
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:47 +0000 (12:02 +0100)] 
BUG/MINOR: ssl: Fix OCSP_CERTID leak when same certificate is used multiple times

If a given certificate is used multiple times in a configuration, the
ocsp_cid field would have been overwritten during each
ssl_sock_load_ocsp call even if it was previously filled.

This patch does not need to be backported.

2 years agoMINOR: ssl: Detect more OCSP update inconsistencies
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:46 +0000 (12:02 +0100)] 
MINOR: ssl: Detect more OCSP update inconsistencies

If a configuration such as the following was included in a crt-list
file, it would not have raised a warning about 'ocsp-update'
inconsistencies for the concerned certificate:
    cert.pem [ocsp-update on]
    cert.pem
because the second line as a NULL entry->ssl_conf.

2 years agoMINOR: ssl: Release ssl_ocsp_task_ctx.cur_ocsp when destroying task
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:45 +0000 (12:02 +0100)] 
MINOR: ssl: Release ssl_ocsp_task_ctx.cur_ocsp when destroying task

In the unlikely event that the OCSP udpate task is killed in the middle
of an update process (request sent but no response received yet) the
cur_ocsp member of the update context would keep an unneeded reference
to a certificate_ocsp object. It must then be freed during the task's
cleanup.

2 years agoMINOR: ssl: Only set ocsp->issuer if issuer not in cert chain
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:44 +0000 (12:02 +0100)] 
MINOR: ssl: Only set ocsp->issuer if issuer not in cert chain

If the ocsp issuer certificate was actually taken from the certificate
chain in ssl_sock_load_ocsp, we don't need to keep an extra reference on
it since we already keep a reference to the full certificate chain.

2 years agoMINOR: ssl: Create temp X509_STORE filled with cert chain when checking ocsp response
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:43 +0000 (12:02 +0100)] 
MINOR: ssl: Create temp X509_STORE filled with cert chain when checking ocsp response

When calling OCSP_basic_verify to check the validity of the received
OCSP response, we need to provide an untrusted certificate chain as well
as an X509_STORE holding only trusted certificates. Since the
certificate chain and the issuer certificate are all provided by the
user, we assume that they are valid and we add them all to a temporary
store. This enables to focus only on the response's validity.

2 years agoBUG/MINOR: ssl: Crash during cleanup because of ocsp structure pointer UAF
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:42 +0000 (12:02 +0100)] 
BUG/MINOR: ssl: Crash during cleanup because of ocsp structure pointer UAF

When ocsp-update is enabled for a given certificate, its
certificate_ocsp objects is inserted in two separate trees (the actual
ocsp response one and the ocsp update one). But since the same instance
is used for the two trees, its ownership is kept by the regular ocsp
response one. The ocsp update task should then never have to free the
ocsp entries. The crash actually occurred because of this. The update
task was freeing entries whose reference counter was not increased while
a reference was still held by the SSL_CTXs.
The only time during which the ocsp update task will need to increase
the reference counter is during an actual update, because at this moment
the entry is taken out of the update tree and a 'flying' reference to
the certificate_ocsp is kept in the ocsp update context.

This bug could be reproduced by calling './haproxy -f conf.cfg -c' with
any of the used certificates having the 'ocsp-update on' option. For
some reason asan caught the bug easily but valgrind did not.

This patch does not need to be backported.

2 years agoBUG/MINOR: ssl: Fix crash in 'update ssl ocsp-response' CLI command
Remi Tricot-Le Breton [Mon, 9 Jan 2023 11:02:41 +0000 (12:02 +0100)] 
BUG/MINOR: ssl: Fix crash in 'update ssl ocsp-response' CLI command

This CLI command crashed when called for a certificate which did not
have an OCSP response during startup because it assumed that the
ocsp_issuer pointer of the ckch_data object would be valid. It was only
true for already known OCSP responses though.
The ocsp issuer certificate is now taken either from the ocsp_issuer
pointer or looked for in the certificate chain. This is the same logic
as the one in ssl_sock_load_ocsp.

This patch does not need to be backported.

2 years agoDOC: config: added optional rst-ttl argument to silent-drop in action lists
Mathias Weiersmueller [Mon, 9 Jan 2023 12:52:06 +0000 (13:52 +0100)] 
DOC: config: added optional rst-ttl argument to silent-drop in action lists

This patch adds the optional silent-drop rst-ttl argument to the action lists in
5 places in the configuration manual.

2 years agoCLEANUP: htx: fix a typo in an error message of http_str_to_htx
Manu Nicolas [Mon, 9 Jan 2023 01:31:06 +0000 (01:31 +0000)] 
CLEANUP: htx: fix a typo in an error message of http_str_to_htx

This fixes a typo in an error message about headers in the
http_str_to_htx function.

2 years ago[RELEASE] Released version 2.8-dev1 v2.8-dev1
Willy Tarreau [Sat, 7 Jan 2023 08:45:17 +0000 (09:45 +0100)] 
[RELEASE] Released version 2.8-dev1

Released version 2.8-dev1 with the following main changes :
    - MEDIUM: 51d: add support for 51Degrees V4 with Hash algorithm
    - MINOR: debug: support pool filtering on "debug dev memstats"
    - MINOR: debug: add a balance of alloc - free at the end of the memstats dump
    - LICENSE: wurfl: clarify the dummy library license.
    - MINOR: event_hdl: add event handler base api
    - DOC/MINOR: api: add documentation for event_hdl feature
    - MEDIUM: ssl: rename the struct "cert_key_and_chain" to "ckch_data"
    - MINOR: quic: remove qc from quic_rx_packet
    - MINOR: quic: complete traces in qc_rx_pkt_handle()
    - MINOR: quic: extract datagram parsing code
    - MINOR: tools: add port for ipcmp as optional criteria
    - MINOR: quic: detect connection migration
    - MINOR: quic: ignore address migration during handshake
    - MINOR: quic: startup detect for quic-conn owned socket support
    - MINOR: quic: test IP_PKTINFO support for quic-conn owned socket
    - MINOR: quic: define config option for socket per conn
    - MINOR: quic: allocate a socket per quic-conn
    - MINOR: quic: use connection socket for emission
    - MEDIUM: quic: use quic-conn socket for reception
    - MEDIUM: quic: move receive out of FD handler to quic-conn io-cb
    - MINOR: mux-quic: rename duplicate function names
    - MEDIUM: quic: requeue datagrams received on wrong socket
    - MINOR: quic: reconnect quic-conn socket on address migration
    - MINOR: quic: activate socket per conn by default
    - BUG/MINOR: ssl: initialize SSL error before parsing
    - BUG/MINOR: ssl: initialize WolfSSL before parsing
    - BUG/MINOR: quic: fix fd leak on startup check quic-conn owned socket
    - BUG/MEDIIM: stconn: Flush output data before forwarding close to write side
    - MINOR: server: add srv->rid (revision id) value
    - MINOR: stats: add server revision id support
    - MINOR: server/event_hdl: add support for SERVER_ADD and SERVER_DEL events
    - MINOR: server/event_hdl: add support for SERVER_UP and SERVER_DOWN events
    - BUG/MEDIUM: checks: do not reschedule a possibly running task on state change
    - BUG/MINOR: checks: make sure fastinter is used even on forced transitions
    - CLEANUP: assorted typo fixes in the code and comments
    - MINOR: mworker: display an alert upon a wait-mode exit
    - BUG/MEDIUM: mworker: fix segv in early failure of mworker mode with peers
    - BUG/MEDIUM: mworker: create the mcli_reload socketpairs in case of upgrade
    - BUG/MINOR: checks: restore legacy on-error fastinter behavior
    - MINOR: check: use atomic for s->consecutive_errors
    - MINOR: stats: properly handle ST_F_CHECK_DURATION metric
    - MINOR: mworker: remove unused legacy code in mworker_cleanlisteners
    - MINOR: peers: unused code path in process_peer_sync
    - BUG/MINOR: init/threads: continue to limit default thread count to max per group
    - CLEANUP: init: remove useless assignment of nbthread
    - BUILD: atomic: atomic.h may need compiler.h on ARMv8.2-a
    - BUILD: makefile/da: also clean Os/ in Device Atlas dummy lib dir
    - BUG/MEDIUM: httpclient/lua: double LIST_DELETE on end of lua task
    - CLEANUP: pools: move the write before free to the uaf-only function
    - CLEANUP: pool: only include pool-os from pool.c not pool.h
    - REORG: pool: move all the OS specific code to pool-os.h
    - CLEANUP: pools: get rid of CONFIG_HAP_POOLS
    - DEBUG: pool: show a few examples in -dMhelp
    - MINOR: pools: make DEBUG_UAF a runtime setting
    - BUG/MINOR: promex: create haproxy_backend_agg_server_status
    - MINOR: promex: introduce haproxy_backend_agg_check_status
    - DOC: promex: Add missing backend metrics
    - BUG/MAJOR: fcgi: Fix uninitialized reserved bytes
    - REGTESTS: fix the race conditions in iff.vtc
    - CI: github: reintroduce openssl 1.1.1
    - BUG/MINOR: quic: properly handle alloc failure in qc_new_conn()
    - BUG/MINOR: quic: handle alloc failure on qc_new_conn() for owned socket
    - CLEANUP: mux-quic: remove unused attribute on qcs_is_close_remote()
    - BUG/MINOR: mux-quic: remove qcs from opening-list on free
    - BUG/MINOR: mux-quic: handle properly alloc error in qcs_new()
    - CI: github: split ssl lib selection based on git branch
    - REGTESTS: startup: check maxconn computation
    - BUG/MINOR: startup: don't use internal proxies to compute the maxconn
    - REGTESTS: startup: change the expected maxconn to 11000
    - CI: github: set ulimit -n to a greater value
    - REGTESTS: startup: activate automatic_maxconn.vtc
    - MINOR: sample: add param converter
    - CLEANUP: ssl: remove check on srv->proxy
    - BUG/MEDIUM: freq-ctr: Don't compute overshoot value for empty counters
    - BUG/MEDIUM: resolvers: Use tick_first() to update the resolvers task timeout
    - REGTESTS: startup: add alternatives values in automatic_maxconn.vtc
    - BUG/MEDIUM: h3: reject request with invalid header name
    - BUG/MEDIUM: h3: reject request with invalid pseudo header
    - MINOR: http: extract content-length parsing from H2
    - BUG/MEDIUM: h3: parse content-length and reject invalid messages
    - CI: github: remove redundant ASAN loop
    - CI: github: split matrix for development and stable branches
    - BUG/MEDIUM: mux-h1: Don't release H1 stream upgraded from TCP on error
    - BUG/MINOR: mux-h1: Fix test instead a BUG_ON() in h1_send_error()
    - MINOR: http-htx: add BUG_ON to prevent API error on http_cookie_register
    - BUG/MEDIUM: h3: fix cookie header parsing
    - BUG/MINOR: h3: fix memleak on HEADERS parsing failure
    - MINOR: h3: check return values of htx_add_* on headers parsing
    - MINOR: ssl: Remove unneeded buffer allocation in show ocsp-response
    - MINOR: ssl: Remove unnecessary alloc'ed trash chunk in show ocsp-response
    - BUG/MINOR: ssl: Fix memory leak of find_chain in ssl_sock_load_cert_chain
    - MINOR: stats: provide ctx for dumping functions
    - MINOR: stats: introduce stats field ctx
    - BUG/MINOR: stats: fix show stat json buffer limitation
    - MINOR: stats: make show info json future-proof
    - BUG/MINOR: quic: fix crash on PTO rearm if anti-amplification reset
    - BUILD: 51d: fix build issue with recent compilers
    - REGTESTS: startup: disable automatic_maxconn.vtc
    - BUILD: peers: peers-t.h depends on stick-table-t.h
    - BUG/MEDIUM: tests: use tmpdir to create UNIX socket
    - BUG/MINOR: mux-h1: Report EOS on parsing/internal error for not running stream
    - BUG/MINOR:: mux-h1: Never handle error at mux level for running connection
    - BUG/MEDIUM: stats: Rely on a local trash buffer to dump the stats
    - OPTIM: pool: split the read_mostly from read_write parts in pool_head
    - MINOR: pool: make the thread-local hot cache size configurable
    - MINOR: freq_ctr: add opportunistic versions of swrate_add()
    - MINOR: pool: only use opportunistic versions of the swrate_add() functions
    - REGTESTS: ssl: enable the ssl_reuse.vtc test for WolfSSL
    - BUG/MEDIUM: mux-quic: fix double delete from qcc.opening_list
    - BUG/MEDIUM: quic: properly take shards into account on bind lines
    - BUG/MINOR: quic: do not allocate more rxbufs than necessary
    - MINOR: ssl: Add a lock to the OCSP response tree
    - MINOR: httpclient: Make the CLI flags public for future use
    - MINOR: ssl: Add helper function that extracts an OCSP URI from a certificate
    - MINOR: ssl: Add OCSP request helper function
    - MINOR: ssl: Add helper function that checks the validity of an OCSP response
    - MINOR: ssl: Add "update ssl ocsp-response" cli command
    - MEDIUM: ssl: Add ocsp_certid in ckch structure and discard ocsp buffer early
    - MINOR: ssl: Add ocsp_update_tree and helper functions
    - MINOR: ssl: Add crt-list ocsp-update option
    - MINOR: ssl: Store 'ocsp-update' mode in the ckch_data and check for inconsistencies
    - MEDIUM: ssl: Insert ocsp responses in update tree when needed
    - MEDIUM: ssl: Add ocsp update task main function
    - MEDIUM: ssl: Start update task if at least one ocsp-update option is set to on
    - DOC: ssl: Add documentation for ocsp-update option
    - REGTESTS: ssl: Add tests for ocsp auto update mechanism
    - MINOR: ssl: Move OCSP code to a dedicated source file
    - BUG/MINOR: ssl/ocsp: check chunk_strcpy() in ssl_ocsp_get_uri_from_cert()
    - CLEANUP: ssl/ocsp: add spaces around operators
    - BUG/MEDIUM: mux-h2: Refuse interim responses with end-stream flag set
    - BUG/MINOR: pool/stats: Use ullong to report total pool usage in bytes in stats
    - BUG/MINOR: ssl/ocsp: httpclient blocked when doing a GET
    - MINOR: httpclient: don't add body when istlen is empty
    - MEDIUM: httpclient: change the default log format to skip duplicate proxy data
    - BUG/MINOR: httpclient/log: free of invalid ptr with httpclient_log_format
    - MEDIUM: mux-quic: implement shutw
    - MINOR: mux-quic: do not count stream flow-control if already closed
    - MINOR: mux-quic: handle RESET_STREAM reception
    - MEDIUM: mux-quic: implement STOP_SENDING emission
    - MINOR: h3: use stream error when needed instead of connection
    - CI: github: enable github api authentication for OpenSSL tags read
    - BUG/MINOR: mux-quic: ignore remote unidirectional stream close
    - CI: github: use the GITHUB_TOKEN instead of a manually generated token
    - BUILD: makefile: build the features list dynamically
    - BUILD: makefile: move common options-oriented macros to include/make/options.mk
    - BUILD: makefile: sort the features list
    - BUILD: makefile: initialize all build options' variables at once
    - BUILD: makefile: add a function to collect all options' CFLAGS/LDFLAGS
    - BUILD: makefile: start to automatically collect CFLAGS/LDFLAGS
    - BUILD: makefile: ensure that all USE_* handlers appear before CFLAGS are used
    - BUILD: makefile: clean the wolfssl include and lib generation rules
    - BUILD: makefile: make sure to also ignore SSL_INC when using wolfssl
    - BUILD: makefile: reference libdl only once
    - BUILD: makefile: make sure LUA_INC and LUA_LIB are always initialized
    - BUILD: makefile: do not restrict Lua's prepend path to empty LUA_LIB_NAME
    - BUILD: makefile: never force -latomic, set USE_LIBATOMIC instead
    - BUILD: makefile: add an implicit USE_MATH variable for -lm
    - BUILD: makefile: properly report USE_PCRE/USE_PCRE2 in features
    - CLEANUP: makefile: properly indent ifeq/ifneq conditional blocks
    - BUILD: makefile: rework 51D to split v3/v4
    - BUILD: makefile: support LIBCRYPT_LDFLAGS
    - BUILD: makefile: support RT_LDFLAGS
    - BUILD: makefile: support THREAD_LDFLAGS
    - BUILD: makefile: support BACKTRACE_LDFLAGS
    - BUILD: makefile: support SYSTEMD_LDFLAGS
    - BUILD: makefile: support ZLIB_CFLAGS and ZLIB_LDFLAGS
    - BUILD: makefile: support ENGINE_CFLAGS
    - BUILD: makefile: support OPENSSL_CFLAGS and OPENSSL_LDFLAGS
    - BUILD: makefile: support WOLFSSL_CFLAGS and WOLFSSL_LDFLAGS
    - BUILD: makefile: support LUA_CFLAGS and LUA_LDFLAGS
    - BUILD: makefile: support DEVICEATLAS_CFLAGS and DEVICEATLAS_LDFLAGS
    - BUILD: makefile: support PCRE[2]_CFLAGS and PCRE[2]_LDFLAGS
    - BUILD: makefile: refactor support for 51DEGREES v3/v4
    - BUILD: makefile: support WURFL_CFLAGS and WURFL_LDFLAGS
    - BUILD: makefile: make all OpenSSL variants use the same settings
    - BUILD: makefile: remove the special case of the SSL option
    - BUILD: makefile: only consider settings from enabled options
    - BUILD: makefile: also list per-option settings in 'make opts'
    - BUG/MINOR: debug: don't mask the TH_FL_STUCK flag before dumping threads
    - MINOR: cfgparse-ssl: avoid a possible crash on OOM in ssl_bind_parse_npn()
    - BUG/MINOR: ssl: Missing goto in error path in ocsp update code
    - BUG/MINOR: stick-table: report the correct action name in error message
    - CI: Improve headline in matrix.py
    - CI: Add in-memory cache for the latest OpenSSL/LibreSSL
    - CI: Use proper `if` blocks instead of conditional expressions in matrix.py
    - CI: Unify the `GITHUB_TOKEN` name across matrix.py and vtest.yml
    - CI: Explicitly check environment variable against `None` in matrix.py
    - CI: Reformat `matrix.py` using `black`
    - MINOR: config: add environment variables for default log format
    - REGTESTS: Remove REQUIRE_VERSION=1.9 from all tests
    - REGTESTS: Remove REQUIRE_VERSION=2.0 from all tests
    - REGTESTS: Remove tests with REQUIRE_VERSION_BELOW=1.9
    - BUG/MINOR: http-fetch: Only fill txn status during prefetch if not already set
    - BUG/MAJOR: buf: Fix copy of wrapping output data when a buffer is realigned
    - DOC: config: fix alphabetical ordering of http-after-response rules
    - MINOR: http-rules: Add missing actions in http-after-response ruleset
    - DOC: config: remove duplicated "http-response sc-set-gpt0" directive
    - BUG/MINOR: proxy: free orgto_hdr_name in free_proxy()
    - REGTEST: fix the race conditions in json_query.vtc
    - REGTEST: fix the race conditions in add_item.vtc
    - REGTEST: fix the race conditions in digest.vtc
    - REGTEST: fix the race conditions in hmac.vtc
    - BUG/MINOR: fd: avoid bad tgid assertion in fd_delete() from deinit()
    - BUG/MINOR: http: Memory leak of http redirect rules' format string
    - MEDIUM: stick-table: set the track-sc limit at boottime via tune.stick-counters
    - MINOR: stick-table: implement the sc-add-gpc() action

2 years agoMINOR: stick-table: implement the sc-add-gpc() action
Willy Tarreau [Mon, 2 Jan 2023 17:15:20 +0000 (18:15 +0100)] 
MINOR: stick-table: implement the sc-add-gpc() action

This action increments the General Purpose Counter at the index <idx> of
the array associated to the sticky counter designated by <sc-id> by the
value of either integer <int> or the integer evaluation of expression
<expr>. Integers and expressions are limited to unsigned 32-bit values.
If an error occurs, this action silently fails and the actions evaluation
continues. <idx> is an integer between 0 and 99 and <sc-id> is an integer
between 0 and 2. It also silently fails if the there is no GPC stored at
this index. The entry in the table is refreshed even if the value is zero.
The 'gpc_rate' is automatically adjusted to reflect the average growth
rate of the gpc value.

The main use of this action is to count scores or total volumes (e.g.
estimated danger per source IP reported by the server or a WAF, total
uploaded bytes, etc).

2 years agoMEDIUM: stick-table: set the track-sc limit at boottime via tune.stick-counters
Willy Tarreau [Fri, 6 Jan 2023 15:09:58 +0000 (16:09 +0100)] 
MEDIUM: stick-table: set the track-sc limit at boottime via tune.stick-counters

The number of stick-counter entries usable by track-sc rules is currently
set at build time. There is no good value for this since the vast majority
of users don't need any, most need only a few and rare users need more.
Adding more counters for everyone increases memory and CPU usages for no
reason.

This patch moves the per-session and per-stream arrays to a pool of a size
defined at boot time. This way it becomes possible to set the number of
entries at boot time via a new global setting "tune.stick-counters" that
sets the limit for the whole process. When not set, the MAX_SESS_STR_CTR
value still applies, or 3 if not set, as before.

It is also possible to lower the value to 0 to save a bit of memory if
not used at all.

Note that a few low-level sample-fetch functions had to be protected due
to the ability to use sample-fetches in the global section to set some
variables.

2 years agoBUG/MINOR: http: Memory leak of http redirect rules' format string
Remi Tricot-Le Breton [Fri, 6 Jan 2023 15:31:06 +0000 (16:31 +0100)] 
BUG/MINOR: http: Memory leak of http redirect rules' format string

When the configuration contains such a line:
    http-request redirect location /
a "struct logformat_node" object is created and it contains an "arg"
member which gets alloc'ed as well in which we copy the new location
(see add_to_logformat_list). This internal arg pointer was not freed in
the dedicated release_http_redir release function.
Likewise, the expression pointer was not released as well.

This patch can be backported to all stable branches. It should apply
as-is all the way to 2.2 but it won't on 2.0 because release_http_redir
did not exist yet.

2 years agoBUG/MINOR: fd: avoid bad tgid assertion in fd_delete() from deinit()
Willy Tarreau [Thu, 5 Jan 2023 17:06:58 +0000 (18:06 +0100)] 
BUG/MINOR: fd: avoid bad tgid assertion in fd_delete() from deinit()

In 2.7, commit 0dc1cc93b ("MAJOR: fd: grab the tgid before manipulating
running") added a check to make sure we never try to delete an FD from
the wrong thread group. It already handles the specific case of an
isolated thread (e.g. stop a listener from the CLI) but forgot to take
into account the deinit() code iterating over all idle server connections
to close them. This results in the crash below during deinit() if thread
groups are enabled and idle connections exist on a thread group higher
than 1.

  [WARNING]  (15711) : Proxy decrypt stopped (cumulated conns: FE: 64, BE: 374511).
  [WARNING]  (15711) : Proxy stats stopped (cumulated conns: FE: 0, BE: 0).
  [WARNING]  (15711) : Proxy GLOBAL stopped (cumulated conns: FE: 0, BE: 0).

  FATAL: bug condition "fd_tgid(fd) != ti->tgid && !thread_isolated()" matched at src/fd.c:369
    call trace(11):
    |       0x4a6060 [c6 04 25 01 00 00 00 00]: main-0x1d60
    |       0x67fcc6 [c7 43 68 fd ad de fd 5b]: sock_conn_ctrl_close+0x16/0x1f
    |       0x59e6f5 [48 89 ef e8 83 65 11 00]: main+0xf6935
    |       0x60ad16 [48 8b 1b 48 81 fb a0 91]: free_proxy+0x716/0xb35
    |       0x62750e [48 85 db 74 35 48 89 dd]: deinit+0xbe/0x87a
    |       0x627ce2 [89 ef e8 97 76 e7 ff 0f]: deinit_and_exit+0x12/0x19
    |       0x4a9694 [bf e6 ff 9d 00 44 89 6c]: main+0x18d4/0x2c1a

There's no harm though since all traffic already ended. This must be
backported to 2.7.

2 years agoREGTEST: fix the race conditions in hmac.vtc
Aurelien DARRAGON [Mon, 2 Jan 2023 14:03:20 +0000 (15:03 +0100)] 
REGTEST: fix the race conditions in hmac.vtc

A "Connection: close" header is added to responses to avoid any connection
reuse. This should avoid any "HTTP header incomplete" errors.

2 years agoREGTEST: fix the race conditions in digest.vtc
Aurelien DARRAGON [Mon, 2 Jan 2023 14:02:10 +0000 (15:02 +0100)] 
REGTEST: fix the race conditions in digest.vtc

A "Connection: close" header is added to responses to avoid any connection
reuse. This should avoid any "HTTP header incomplete" errors.

2 years agoREGTEST: fix the race conditions in add_item.vtc
Aurelien DARRAGON [Mon, 2 Jan 2023 13:59:50 +0000 (14:59 +0100)] 
REGTEST: fix the race conditions in add_item.vtc

A "Connection: close" header is added to responses to avoid any connection
reuse. This should avoid any "HTTP header incomplete" errors.

2 years agoREGTEST: fix the race conditions in json_query.vtc
Aurelien DARRAGON [Mon, 2 Jan 2023 13:54:31 +0000 (14:54 +0100)] 
REGTEST: fix the race conditions in json_query.vtc

A "Connection: close" header is added to responses to avoid any connection
reuse. This should avoid any "HTTP header incomplete" errors.

2 years agoBUG/MINOR: proxy: free orgto_hdr_name in free_proxy()
Aurelien DARRAGON [Wed, 28 Dec 2022 11:18:15 +0000 (12:18 +0100)] 
BUG/MINOR: proxy: free orgto_hdr_name in free_proxy()

Unlike fwdfor_hdr_name, orgto_hdr_name was not properly freed in
free_proxy().

This did not cause observable memory leaks because originalto proxy option is
only used for user configurable proxies, which are solely freed right before
process termination.
No backport needed unless some architectural changes causing regular proxies
to be freed and reused multiple times within single process lifetime are made.

2 years agoDOC: config: remove duplicated "http-response sc-set-gpt0" directive
Christopher Faulet [Thu, 5 Jan 2023 10:24:55 +0000 (11:24 +0100)] 
DOC: config: remove duplicated "http-response sc-set-gpt0" directive

This directive was erroneously duplicated.

This patch could be backported as far as 2.5.

2 years agoMINOR: http-rules: Add missing actions in http-after-response ruleset
Christopher Faulet [Thu, 5 Jan 2023 10:17:38 +0000 (11:17 +0100)] 
MINOR: http-rules: Add missing actions in http-after-response ruleset

This patch adds the support of following actions in the http-after-response
ruleset:

  * set-map, del-map and del-acl
  * set-log-level
  * sc-inc-gpc, sc-inc-gpc0 and set-inc-gpc1
  * sc-inc-gpt and sc-set-gpt0

This patch should solve the issue #1980.

2 years agoDOC: config: fix alphabetical ordering of http-after-response rules
Christopher Faulet [Thu, 5 Jan 2023 09:25:30 +0000 (10:25 +0100)] 
DOC: config: fix alphabetical ordering of http-after-response rules

The 'capture' action must be placed after the 'allow' action.

This patch could be backported as far as 2.5.

2 years agoBUG/MAJOR: buf: Fix copy of wrapping output data when a buffer is realigned
Christopher Faulet [Thu, 5 Jan 2023 08:34:47 +0000 (09:34 +0100)] 
BUG/MAJOR: buf: Fix copy of wrapping output data when a buffer is realigned

There is a bug in b_slow_realign() function when wrapping output data are
copied in the swap buffer. block1 and block2 sizes are inverted. Thus blocks
with a wrong size are copied. It leads to data mixin if the first block is
in reality larger than the second one or to a copy of data outside the
buffer is the first block is smaller than the second one.

The bug was introduced when the buffer API was refactored in 1.9. It was
found by a code review and seems never to have been triggered in almost 5
years. However, we cannot exclude it is responsible of some unresolved bugs.

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

2 years agoBUG/MINOR: http-fetch: Only fill txn status during prefetch if not already set
Christopher Faulet [Wed, 4 Jan 2023 09:11:32 +0000 (10:11 +0100)] 
BUG/MINOR: http-fetch: Only fill txn status during prefetch if not already set

When an HTTP sample fetch is evaluated, a prefetch is performed to check the
channel contains a valid HTTP message. If the HTTP analysis was not already
started, some info are filled.

It may be an issue when an error is returned before the response analysis
and when http-after-response rules are used because the original HTTP txn
status may be crushed. For instance, with the following configuration:

  listen l1
    log global
    mode http
    bind :8000

    log-format ST=%ST
    http-after-response set-status 400
    #http-after-response set-var(res.foo) status

A "ST=503" is reported in the log messages, independantly on the first
http-after-response rule. The same must happen if the second rule is
uncommented. However, for now, a "ST=400" is logged.

To fix the bug, during the prefetch, the HTTP txn status is only set if it
is undefined (-1). This way, we are sure the original one is never lost.

This patch should be backported as far as 2.2.

2 years agoREGTESTS: Remove tests with REQUIRE_VERSION_BELOW=1.9
Tim Duesterhus [Wed, 4 Jan 2023 17:49:38 +0000 (18:49 +0100)] 
REGTESTS: Remove tests with REQUIRE_VERSION_BELOW=1.9

HAProxy 2.0 is the lowest supported version, thus this never matches.

2 years agoREGTESTS: Remove REQUIRE_VERSION=2.0 from all tests
Tim Duesterhus [Wed, 4 Jan 2023 17:49:37 +0000 (18:49 +0100)] 
REGTESTS: Remove REQUIRE_VERSION=2.0 from all tests

HAProxy 2.0 is the lowest supported version, thus this always matches.

see 1b095cac9468d0c3eeb157e9b1a2947487bd3c83

2 years agoREGTESTS: Remove REQUIRE_VERSION=1.9 from all tests
Tim Duesterhus [Wed, 4 Jan 2023 17:49:36 +0000 (18:49 +0100)] 
REGTESTS: Remove REQUIRE_VERSION=1.9 from all tests

HAProxy 2.0 is the lowest supported version, thus this always matches.

see 1b095cac9468d0c3eeb157e9b1a2947487bd3c83

2 years agoMINOR: config: add environment variables for default log format
Sébastien Gross [Wed, 30 Nov 2022 21:36:50 +0000 (22:36 +0100)] 
MINOR: config: add environment variables for default log format

This patch provides a convenient way to override the default TCP, HTTP
and HTTP log formats. Instead of having a look into the documentation
to figure out what is the appropriate default log format three new
environment variables can be used: HAPROXY_TCP_LOG_FMT,
HAPROXY_HTTP_LOG_FMT and HAPROXY_HTTPS_LOG_FMT. Their content are
substituted verbatim.

These variables are set before parsing the configuration and are unset
just after all configuration files are successful parsed.

Example:

    # Instead of writing this long log-format line...
    log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC \
                %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r \
                lr=last_rule_file:last_rule_line"

    # ..the HAPROXY_HTTP_LOG_FMT can be used to provide the default
    # http log-format string
    log-format "${HAPROXY_HTTP_LOG_FMT} lr=last_rule_file:last_rule_line"

Please note that nothing prevents users to unset the variables or
override their content in a global section.

Signed-off-by: Sébastien Gross <sgross@haproxy.com>
2 years agoCI: Reformat `matrix.py` using `black`
Tim Duesterhus [Thu, 29 Dec 2022 16:40:29 +0000 (17:40 +0100)] 
CI: Reformat `matrix.py` using `black`

The initial version of matrix.py was formatted using `black` [1], but with all
the later changes, the formatting diverged quite a bit. This patch reformats
the script using black, fixing the indentation of some statements and
shortening overlong lines.

[1] https://github.com/psf/black

2 years agoCI: Explicitly check environment variable against `None` in matrix.py
Tim Duesterhus [Thu, 29 Dec 2022 16:40:28 +0000 (17:40 +0100)] 
CI: Explicitly check environment variable against `None` in matrix.py

For consistency with `GITHUB_OUTPUT` at the bottom.

2 years agoCI: Unify the `GITHUB_TOKEN` name across matrix.py and vtest.yml
Tim Duesterhus [Thu, 29 Dec 2022 16:40:27 +0000 (17:40 +0100)] 
CI: Unify the `GITHUB_TOKEN` name across matrix.py and vtest.yml

This makes naming a little clearer in matrix.py, because the name matches the
name of the actual secret.

2 years agoCI: Use proper `if` blocks instead of conditional expressions in matrix.py
Tim Duesterhus [Thu, 29 Dec 2022 16:40:26 +0000 (17:40 +0100)] 
CI: Use proper `if` blocks instead of conditional expressions in matrix.py

For complex expressions, such as the ones modified, the condition expression is
much less readable, especially with the actual condition in the middle of the
"then" and "else" part.

2 years agoCI: Add in-memory cache for the latest OpenSSL/LibreSSL
Tim Duesterhus [Thu, 29 Dec 2022 16:40:25 +0000 (17:40 +0100)] 
CI: Add in-memory cache for the latest OpenSSL/LibreSSL

These functions were previously called once per compiler. Add the `lru_cache`
decorator to only perform one HTTP request each.

2 years agoCI: Improve headline in matrix.py
Tim Duesterhus [Thu, 29 Dec 2022 16:40:24 +0000 (17:40 +0100)] 
CI: Improve headline in matrix.py

Since 4a04cd35ae89bf6a3bb7620f7a49804de3240ac4 (CI: github: split ssl lib
selection based on git branch) the branch, instead of the workflow type is
passed. The headline should reflect that.

2 years agoBUG/MINOR: stick-table: report the correct action name in error message
Willy Tarreau [Mon, 2 Jan 2023 16:35:50 +0000 (17:35 +0100)] 
BUG/MINOR: stick-table: report the correct action name in error message

sc-inc-gpc() learned to use arrays in 2.5 with commit 4d7ada8f9 ("MEDIUM:
stick-table: add the new arrays of gpc and gpc_rate"), but the error
message says "sc-set-gpc" instead of "sc-inc-gpc". Let's fix this to
avoid confusion.

This can be backported to 2.5.

2 years agoBUG/MINOR: ssl: Missing goto in error path in ocsp update code
Remi Tricot-Le Breton [Mon, 2 Jan 2023 14:01:16 +0000 (15:01 +0100)] 
BUG/MINOR: ssl: Missing goto in error path in ocsp update code

When converting an OCSP request's information into base64, the return
value of a2base64 is checked but processing is not interrupted when it
returns a negative value, which was caught by coverity.

This patch fixes GitHub issue #1974.
It does not need to be backported.

2 years agoMINOR: cfgparse-ssl: avoid a possible crash on OOM in ssl_bind_parse_npn()
Willy Tarreau [Thu, 29 Dec 2022 10:11:02 +0000 (11:11 +0100)] 
MINOR: cfgparse-ssl: avoid a possible crash on OOM in ssl_bind_parse_npn()

Upon out of memory condition at boot, we could possibly crash when
parsing the "npn" bind line keyword since it's used unchecked. There's
no real need to backport this though it will not hurt.

2 years agoBUG/MINOR: debug: don't mask the TH_FL_STUCK flag before dumping threads
Willy Tarreau [Mon, 2 Jan 2023 07:33:18 +0000 (08:33 +0100)] 
BUG/MINOR: debug: don't mask the TH_FL_STUCK flag before dumping threads

Commit f0c86ddfe ("BUG/MEDIUM: debug: fix parallel thread dumps again")
added a clearing of the TH_FL_STUCK flag before dumping threads in case
of parallel dumps, but that was in part a sort of workaround for some
remains of the commit that introduced the flag in 2.0 before the watchdog
existed, and which would set it after dumping a thread: e6a02fa65 ("MINOR:
threads: add a "stuck" flag to the thread_info struct"), and in part an
attempt to avoid that a thread waiting for too long during the dump would
get the flag set. But that is not possible, a thread waiting for being
dumped has the harmless bit set and doesn't get the stuck bit. What happens
in fact is that issuing "show threads" in fast loops ends up causing some
threads to keep their STUCK bit that was set at the end of "show threads",
and confuses the output.

The problem with doing this is that the flag is cleared before the thread
is dumped, and since this flag is used to decide whether to show a backtrace
or not, we don't get backtraces anymore of stuck threads since the commit
above in 2.7.

This patch just removes the two points where the flag was cleared by the
commit above. It should be backported to 2.7.

2 years agoBUILD: makefile: also list per-option settings in 'make opts'
Willy Tarreau [Fri, 23 Dec 2022 16:29:11 +0000 (17:29 +0100)] 
BUILD: makefile: also list per-option settings in 'make opts'

Thanks to the generic naming of the build options, it's now relatively
easy to enumerate all _CFLAGS and _LDFLAGS for defined USE_* options.
That was added to the first line of 'make opts', but is only listed for
enabled options, non-empty variables or cmd-line defined variables.

2 years agoBUILD: makefile: only consider settings from enabled options
Willy Tarreau [Fri, 23 Dec 2022 14:08:38 +0000 (15:08 +0100)] 
BUILD: makefile: only consider settings from enabled options

Due to the previous SSL exception we coudln't restrict the collected
CFLAGS/LDFLAGS to those of enabled options, so all of them were
considered if set. The problem is that it would prevent simply
disabling a build option without unsetting its xxx_CFLAGS or _LDFLAGS
values if those had incompatible values (e.g. -lfoo).

Now that only existing options are listed in collect_opts_flags, we
can safely check that the option is set and only consider its settings
in this case. Thus OT_LDFLAGS will not be used if USE_OT is not set
for example.

2 years agoBUILD: makefile: remove the special case of the SSL option
Willy Tarreau [Fri, 23 Dec 2022 14:01:54 +0000 (15:01 +0100)] 
BUILD: makefile: remove the special case of the SSL option

By creating USE_SSL and enabling it when USE_OPENSSL is set, we can
get rid of the special case that was made with it regarding cflags
collect and when resetting options. The option doesn't need to be
manually set, though in the future it might prove useful if other
non-openssl API are supported.

2 years agoBUILD: makefile: make all OpenSSL variants use the same settings
Willy Tarreau [Thu, 22 Dec 2022 13:39:54 +0000 (14:39 +0100)] 
BUILD: makefile: make all OpenSSL variants use the same settings

It's getting complicated to configure includes and lib dirs for
OpenSSL API variants such as WolfSSL, because some settings are
common and others are specific but carry a prefix that doesn't
match the USE_* rule scheme.

This patch simplifies everything by considering that all SSL libs
will use SSL_INC, SSL_LIB, SSL_CFLAGS and SSL_LDFLAGS. That's much
more convenient. This works thanks to the settings collector which
explicitly checks the SSL_* settings. When USE_OPENSSL_WOLFSSL is
set, then USE_OPENSSL is implied, so that there's no need to
duplicate maintenance effort.

2 years agoBUILD: makefile: support WURFL_CFLAGS and WURFL_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 17:58:46 +0000 (18:58 +0100)] 
BUILD: makefile: support WURFL_CFLAGS and WURFL_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_WURFL can now be overridden
using WURFL_CFLAGS and WURFL_LDFLAGS.

2 years agoBUILD: makefile: refactor support for 51DEGREES v3/v4
Willy Tarreau [Wed, 21 Dec 2022 17:54:36 +0000 (18:54 +0100)] 
BUILD: makefile: refactor support for 51DEGREES v3/v4

In order to simplify maintenance and long-term evolutions, now the
feature remains enabled by setting USE_51DEGREES=1 and the version
is set in 51DEGREES_VER (3 or 4 are supported only). The default
version remains 3. All 51DEGREES flags are shared between both
versions and only use the "51DEGREES_" prefix.

The related CFLAGS and LDFLAGS can now be overridden using
51DEGREES_CFLAGS and 51DEGREES_LDFLAGS, both of which are automatically
collected into the respective OPTIONS_*. The USE_51DEGREES_V4 option is
now removed, and the doc was updated.

2 years agoBUILD: makefile: support PCRE[2]_CFLAGS and PCRE[2]_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 16:24:38 +0000 (17:24 +0100)] 
BUILD: makefile: support PCRE[2]_CFLAGS and PCRE[2]_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_PCRE/USE_PCRE2 can now be
overridden using PCRE_CFLAGS/PCRE2_CFLAGS and PCRE_LDFLAGS/PCRE2_LDFLAGS.

Its worth noting that PCRE2_LDFLAGS did already exist and was preset from
the pkgconfig output then complemented with -lpcre2-posix, and only then
the -L and optional -Wl,-Bstatic were appended when adding them to the
resulting global LDFLAGS. A search on the net did not reveal any use of
PCRE2_LDFLAGS in any public build scripts, and for consistency sake it's
important to make sure that we can now finally override the -L settings
like we're able to do with every other build option. Thus the meaning of
this variable changed to include all the related ldflags (-L and -Wl).

These flags are now automatically collected into OPTIONS_*.

2 years agoBUILD: makefile: support DEVICEATLAS_CFLAGS and DEVICEATLAS_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:20:57 +0000 (16:20 +0100)] 
BUILD: makefile: support DEVICEATLAS_CFLAGS and DEVICEATLAS_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_DEVICEATLAS can now be overridden
using DEVICEATLAS_CFLAGS and DEVICEATLAS_LDFLAGS.

2 years agoBUILD: makefile: support LUA_CFLAGS and LUA_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:20:41 +0000 (16:20 +0100)] 
BUILD: makefile: support LUA_CFLAGS and LUA_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_LUA can now be overridden using
LUA_CFLAGS and LUA_LDFLAGS. Note that if these flags are forced, they
have to contain the optional -DHLUA_PREPEND_PATH= since this is added
to CFLAGS.

2 years agoBUILD: makefile: support WOLFSSL_CFLAGS and WOLFSSL_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:20:20 +0000 (16:20 +0100)] 
BUILD: makefile: support WOLFSSL_CFLAGS and WOLFSSL_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_WOLFSSL can now be overridden
using WOLFSSL_CFLAGS and WOLFSSL_LDFLAGS.

2 years agoBUILD: makefile: support OPENSSL_CFLAGS and OPENSSL_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:20:01 +0000 (16:20 +0100)] 
BUILD: makefile: support OPENSSL_CFLAGS and OPENSSL_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_OPENSSL can now be overridden
using OPENSSL_CFLAGS and OPENSSL_LDFLAGS.

2 years agoBUILD: makefile: support ENGINE_CFLAGS
Willy Tarreau [Thu, 22 Dec 2022 10:45:33 +0000 (11:45 +0100)] 
BUILD: makefile: support ENGINE_CFLAGS

The CFLAGS appended by USE_ENGINE can now be overridden using
ENGINE_CFLAGS. These would have been better located inside the
OPENSSL stuff but it's a bit too late now.

2 years agoBUILD: makefile: support ZLIB_CFLAGS and ZLIB_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:15:40 +0000 (16:15 +0100)] 
BUILD: makefile: support ZLIB_CFLAGS and ZLIB_LDFLAGS

The CFLAGS and LDFLAGS appended by USE_ZLIB can now be overridden using
ZLIB_CFLAGS and ZLIB_LDFLAGS.

2 years agoBUILD: makefile: support SYSTEMD_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:19:22 +0000 (16:19 +0100)] 
BUILD: makefile: support SYSTEMD_LDFLAGS

The LDFLAGS appended by USE_SYSTEMD can now be overridden using
SYSTEMD_LDFLAGS.

2 years agoBUILD: makefile: support BACKTRACE_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:18:40 +0000 (16:18 +0100)] 
BUILD: makefile: support BACKTRACE_LDFLAGS

The LDFLAGS appended by USE_BACKTRACE can now be overridden using
BACKTRACE_LDFLAGS.

2 years agoBUILD: makefile: support THREAD_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:17:40 +0000 (16:17 +0100)] 
BUILD: makefile: support THREAD_LDFLAGS

The LDFLAGS appended by USE_THREAD can now be overridden using
THREAD_LDFLAGS.

2 years agoBUILD: makefile: support RT_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:16:36 +0000 (16:16 +0100)] 
BUILD: makefile: support RT_LDFLAGS

The LDFLAGS appended by USE_RT can now be overridden using
RT_LDFLAGS.

2 years agoBUILD: makefile: support LIBCRYPT_LDFLAGS
Willy Tarreau [Wed, 21 Dec 2022 15:14:11 +0000 (16:14 +0100)] 
BUILD: makefile: support LIBCRYPT_LDFLAGS

The LDFLAGS appended by USE_LIBCRYPT can now be overridden using
LIBCRYPT_LDFLAGS.

2 years agoBUILD: makefile: rework 51D to split v3/v4
Willy Tarreau [Wed, 21 Dec 2022 14:23:04 +0000 (15:23 +0100)] 
BUILD: makefile: rework 51D to split v3/v4

There are multiple options for 51DEGREES, v3/v4, threading or not,
pattern/trie for v3, vhash for v4, use of libatomic, etc. While the
current rules deal with all of that correctly, it's too difficult to
focus on one version because the two are interleaved for every single
option. Let's just split them into two independent blocks. This removes
some if/endif, and makes the lecture much more straightforward.

2 years agoCLEANUP: makefile: properly indent ifeq/ifneq conditional blocks
Willy Tarreau [Wed, 21 Dec 2022 14:49:56 +0000 (15:49 +0100)] 
CLEANUP: makefile: properly indent ifeq/ifneq conditional blocks

Some conditional blocks have become out of control over time and are
totally unreadble. It took 15 minutes to figure what "endif" matched
what "if" in the PCRE one for example, and DA and 51D use multiple
levels as well that are not easy to sort out.

Let's reindent the whole thing. Most places that were already indented
used 2 spaces per level, so here we're keeping that principle. It was
just not done on the two last ones that are used to define some rules
because we don't want spaces before rule names. A few had the opening
condition indicated on the endif line.

It would be desirable that over time this more maintainable layout is
preserved.

2 years agoBUILD: makefile: properly report USE_PCRE/USE_PCRE2 in features
Willy Tarreau [Wed, 21 Dec 2022 16:27:46 +0000 (17:27 +0100)] 
BUILD: makefile: properly report USE_PCRE/USE_PCRE2 in features

The PCRE/PCRE2 CFLAGS forcefully add -DUSE_PCRE or -DUSE_PCRE2 because
we want that USE_STATIC_PCRE or USE_PCRE_JIT implicitly enables them.
However, doing it this way is incorrect because the option is not visible
in BUILD_FEATURES, and for example, some regtests depending on such
features (such as map_redirect.vtc) would be skipped if only the static
or jit versions are enabled.

The correct way to do this is to always set USE_PCRE feature for such
variants instead of adding the define.

This could almost be backported but would require to backport other
makefile patches and likely only has effects on the reg-tests at the
moment, so it's probably not worth the hassle.

2 years agoBUILD: makefile: add an implicit USE_MATH variable for -lm
Willy Tarreau [Wed, 21 Dec 2022 10:59:33 +0000 (11:59 +0100)] 
BUILD: makefile: add an implicit USE_MATH variable for -lm

Lua and 51d make use of -lm, which would be better served by having its
own option than being passed in the LDFLAGS. It also simplifies linking
against a static version of libm. The option uses its own LDFLAGS which
are automatically collected into OPTIONS_LDFLAGS.

2 years agoBUILD: makefile: never force -latomic, set USE_LIBATOMIC instead
Willy Tarreau [Wed, 21 Dec 2022 09:46:07 +0000 (10:46 +0100)] 
BUILD: makefile: never force -latomic, set USE_LIBATOMIC instead

Two places, 51Dv4 and AIX7.2, used to forcefully add -latomic to the
ldflags (and via different variables). This must not be done because
it depends on compiler, arch, etc. USE_LIBATOMIC=implicit is much
better: it allows the user to forcefully disable it if undesired.
The LIBATOMIC_LDFLAGS are set to -latomic and automatically added
to OPTIONS_LDFLAGS.

It will make this dependency appear in haproxy -vv but that's not
and issue and it may even sometimes help when troubleshooting.

2 years agoBUILD: makefile: do not restrict Lua's prepend path to empty LUA_LIB_NAME
Willy Tarreau [Thu, 15 Dec 2022 10:55:51 +0000 (11:55 +0100)] 
BUILD: makefile: do not restrict Lua's prepend path to empty LUA_LIB_NAME

The HLUA_PREPEND_PATH and HLUA_PREPEND_CPATH settings were only applied
when LUA_LIB_NAME was empty, otherwise they were silently ignored. Let's
take them out of that conditional block as this makes no sense to enforce
such a restriction (the main reason in fact is that this whole block is
unreadable).

Also take this opportunity to unfold the last two imbricated tests of
LUA_LIB_NAME and put comments around certain blocks to know what "endif"
matches what "if".

2 years agoBUILD: makefile: make sure LUA_INC and LUA_LIB are always initialized
Willy Tarreau [Thu, 15 Dec 2022 09:47:14 +0000 (10:47 +0100)] 
BUILD: makefile: make sure LUA_INC and LUA_LIB are always initialized

While LUA_INC is sometimes set in the makefile (only when LUA_LIB_NAME
is not set), LUA_LIB is never pre-initialized and faces the risk of
being accidently inherited from the environment. Let's make sure both
are properly reset first when not explicitly set. For this we always
set LUA_INC based on the autodetection if it's not set, and always
pre-initialize LUA_LIB to empty. This also helps make that block
slightly less difficult to understand.

2 years agoBUILD: makefile: reference libdl only once
Willy Tarreau [Wed, 14 Dec 2022 17:46:48 +0000 (18:46 +0100)] 
BUILD: makefile: reference libdl only once

There used to be special cases where USE_DL was only for the SSL library,
then for Lua, then was used globally, but each of them kept their own copy
of -ldl. When building on a system supporting libdl, with SSL and Lua
enabled, no less than 3 -ldl are found on the linker's command line.

What matters is only that it's close to the end, so let's remove the old
specific ones and move the global one to the end. The option now uses its
own DL_LDFLAGS that is automatically collected into OPTIONS_LDFLAGS.

2 years agoBUILD: makefile: make sure to also ignore SSL_INC when using wolfssl
Willy Tarreau [Wed, 14 Dec 2022 17:38:58 +0000 (18:38 +0100)] 
BUILD: makefile: make sure to also ignore SSL_INC when using wolfssl

I got a build error when adding USE_OPENSSL_WOLFSSL to my make command
line because SSL_INC was still set and caused some conflicting headers
to be included first. There's already an exclusion test for the wolfssl
variant used for SSL_LIB, make it also cover SSL_INC to avoid this.

This may be backported to 2.7 to ease testing of wolfssl.

2 years agoBUILD: makefile: clean the wolfssl include and lib generation rules
Willy Tarreau [Wed, 14 Dec 2022 17:18:41 +0000 (18:18 +0100)] 
BUILD: makefile: clean the wolfssl include and lib generation rules

The default include paths for wolfssl didn't match the explicit pattern
one. This was causing some confusion about what to look for, complexifying
the rules and making /usr/local/include to be automatically included if a
path was not set.

Let's just proceed as we usually do, i.e. pass -I only when a path is
specified, so that it works similarly to openssl. Let's also simplify
the LDFLAG rule at the same time.

This may be backported to 2.7 to ease testing of wolfssl.

2 years agoBUILD: makefile: ensure that all USE_* handlers appear before CFLAGS are used
Willy Tarreau [Thu, 22 Dec 2022 16:58:24 +0000 (17:58 +0100)] 
BUILD: makefile: ensure that all USE_* handlers appear before CFLAGS are used

It happens that a few "if USE_foo" were placed too low in the makefile,
and would mostly work by luck thanks to not using variables that were
already referenced before. The opentracing include is even trickier
because it extends OPTIONS_CFLAGS that was last read a few lines before
being included, but it only works because COPTS is defined as a macro and
not a variable, so it will be evaluated later. At least now it doesn't
touch OPTIONS_* anymore and since it's cleanly arranged, it will work by
default via the flags collector.

Let's just move these late USE_* handlers upper and place a visible
delimiter after them reminding not to add any after.

2 years agoBUILD: makefile: start to automatically collect CFLAGS/LDFLAGS
Willy Tarreau [Thu, 22 Dec 2022 17:24:46 +0000 (18:24 +0100)] 
BUILD: makefile: start to automatically collect CFLAGS/LDFLAGS

Now OPTIONS_CFLAGS and OPTIONS_LDFLAGS don't need to be set anymore
for options USE_xxx that set xxx_CFLAGS or xxx_LDFLAGS. These ones
will be automatically connected.

The only entry for now that was ready for this was PCRE2, so it was
adjusted so as not to append to OPTIONS_LDFLAGS anymore. More will
come later.

2 years agoBUILD: makefile: add a function to collect all options' CFLAGS/LDFLAGS
Willy Tarreau [Thu, 22 Dec 2022 18:44:35 +0000 (19:44 +0100)] 
BUILD: makefile: add a function to collect all options' CFLAGS/LDFLAGS

The new function collect_opts_flags now scans all USE_* options defined
in use_opts and appends the corresponding *_CFLAGS and *_LDFLAGS to
OPTIONS_{C,LD}FLAGS respectively. This will be useful to get rid of all
the individual concatenations to these variables.

2 years agoBUILD: makefile: initialize all build options' variables at once
Willy Tarreau [Thu, 22 Dec 2022 14:47:47 +0000 (15:47 +0100)] 
BUILD: makefile: initialize all build options' variables at once

A lot of _SRC, _INC, _LIB etc variables are set and expected to be
initialized to an empty string by default. However, an in-depth
review of all of them showed that WOLFSSL_{INC,LIB}, SSL_{INC,LIB},
LUA_{INC,LIB}, and maybe others were not always initialized and could
sometimes leak from the environment and as such cause strange build
issues when running from cascaded scripts that had exported them.

The approach taken here consists in iterating over all USE_* options
and unsetting any _SRC, _INC, _LIB, _CFLAGS and _LDFLAGS that follows
the same name. For the few variable names options that don't exactly
match the build option (SSL & WOLFSSL), these ones are specifically
added to the list. The few that were explicitly cleared in their own
sections were just removed since not needed anymore. Note that an
"undefine" command appeared in GNU make 3.82 but since we support
older ones we can only initialize the variables to an empty string
here. It's not a problem in practice.

We're now certain that these variables are empty wherever they are
used, and that it is possible to just append to them, or use them
as-is.

2 years agoBUILD: makefile: sort the features list
Willy Tarreau [Thu, 22 Dec 2022 18:51:30 +0000 (19:51 +0100)] 
BUILD: makefile: sort the features list

The features list that appears in -vv appears in a random order, which
always makes it a pain to look for certain features. Let's sort it.

2 years agoBUILD: makefile: move common options-oriented macros to include/make/options.mk
Willy Tarreau [Thu, 22 Dec 2022 18:32:24 +0000 (19:32 +0100)] 
BUILD: makefile: move common options-oriented macros to include/make/options.mk

Some macros and functions are barely understandable and are only used
to iterate over known options from the use_opts list. Better assign
them a name and move them into a dedicated file to clean the makefile
a little bit. Now at least "use_opts" only appears once, where it is
defined. This also allowed to completely remove the BUILD_FEATURES
macro that caused some confusion until previous commit.

2 years agoBUILD: makefile: build the features list dynamically
Willy Tarreau [Wed, 21 Dec 2022 10:57:43 +0000 (11:57 +0100)] 
BUILD: makefile: build the features list dynamically

The BUILD_FEATURES string was created too early to inherit implicit
additions. This could make the features list report that some features
were disabled while they had later been enabled. Better make it a macro
that is interpreted where needed based on the current state of each
option.

2 years agoCI: github: use the GITHUB_TOKEN instead of a manually generated token
William Lallemand [Fri, 23 Dec 2022 13:40:04 +0000 (14:40 +0100)] 
CI: github: use the GITHUB_TOKEN instead of a manually generated token

Github allows to use a auto generated GITHUB_TOKEN so we don't need to
handle the token in the secret configuration.

https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret

2 years agoBUG/MINOR: mux-quic: ignore remote unidirectional stream close
Amaury Denoyelle [Thu, 22 Dec 2022 17:56:09 +0000 (18:56 +0100)] 
BUG/MINOR: mux-quic: ignore remote unidirectional stream close

Remove ABORT_NOW() on remote unidirectional stream closure. This is
required to ensure our implementation is evolutive enough to not fail on
unknown stream type.

Note that for the moment MAX_STREAMS_UNI flow-control frame is never
emitted. This should be unnecessary for HTTP/3 which have a limited
usage of unidirectional streams but may be required if other application
protocols are supported in the future.

ABORT_NOW() was triggered by s2n-quic which opens an unknown
unidirectional stream with greasing. This was detected by QUIC interop
runner for http3 testcase.

This must be backported up to 2.6.

2 years agoCI: github: enable github api authentication for OpenSSL tags read
Ilya Shipitsin [Thu, 22 Dec 2022 16:27:37 +0000 (22:27 +0600)] 
CI: github: enable github api authentication for OpenSSL tags read

github api throttles requests with no auth, thus we can enable
GITHUB_API_TOKEN env variable. if not set, current behaviour is kept

2 years agoMINOR: h3: use stream error when needed instead of connection
Amaury Denoyelle [Fri, 9 Dec 2022 14:01:31 +0000 (15:01 +0100)] 
MINOR: h3: use stream error when needed instead of connection

Use a stream error when possible instead of always closing the whole
connection. This requires a new field <err> in h3s structure.

Change slightly the decoding loop to facilitate error propagation. It
will be interrupted as soon as <h3s.err> or <h3c.err> is non null. In
the later case, a CONNECTION_CLOSE is requested through
qcc_emit_cc_app().

For stream error, H3 layer uses qcc_abort_stream_read() coupled with
qcc_reset_stream(). This is in conformance with RFC 9114 which
recommends to use STOP_SENDING + RESET_STREAM emission on stream error.

This commit is part of implementing H3 errors at the stream level.

This should be backported up to 2.7.

2 years agoMEDIUM: mux-quic: implement STOP_SENDING emission
Amaury Denoyelle [Fri, 9 Dec 2022 13:58:28 +0000 (14:58 +0100)] 
MEDIUM: mux-quic: implement STOP_SENDING emission

Implement STOP_SENDING. This is divided in two main functions :
* qcc_abort_stream_read() which can be used by application protocol to
  request for a STOP_SENDING. This set the flag QC_SF_READ_ABORTED.
* qcs_send_reset() is a static function called after the preceding one.
  It will send a STOP_SENDING via qcc_send().

QC_SF_READ_ABORTED flag is now properly used : if activated on a stream
during qcc_recv(), <qcc.app_ops.decode_qcs> callback is skipped. Also,
abort reading on unknown unidirection remote stream is now fully
supported with the emission of a STOP_SENDING as specified by RFC 9000.

This commit is part of implementing H3 errors at the stream level. This
will allows the H3 layer to request the peer to close its endpoint for
an error on a stream.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: handle RESET_STREAM reception
Amaury Denoyelle [Fri, 9 Dec 2022 15:25:48 +0000 (16:25 +0100)] 
MINOR: mux-quic: handle RESET_STREAM reception

Implement RESET_STREAM reception by mux-quic. On reception, qcs instance
will be mark as remotely closed and its Rx buffer released. The stream
layer will be flagged on error if still attached.

This commit is part of implementing H3 errors at the stream level.
Indeed, on H3 stream errors, STOP_SENDING + RESET_STREAM should be
emitted. The STOP_SENDING will in turn generate a RESET_STREAM by the
remote peer which will be handled thanks to this patch.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: do not count stream flow-control if already closed
Amaury Denoyelle [Fri, 9 Dec 2022 14:00:17 +0000 (15:00 +0100)] 
MINOR: mux-quic: do not count stream flow-control if already closed

It is unnecessary to increase stream credit once its size is known.
Indeed, a peer cannot sent a greater offset than the value advertized.
Else, connection will be closed on STREAM reception with
FINAL_SIZE_ERROR.

This commit is a small optimization and may prevent the emission of
unneeded MAX_STREAM_DATA frames on some occasions.

It should be backported up to 2.7.

2 years agoMEDIUM: mux-quic: implement shutw
Amaury Denoyelle [Wed, 21 Dec 2022 09:21:58 +0000 (10:21 +0100)] 
MEDIUM: mux-quic: implement shutw

Implement mux_ops shutw operation for QUIC mux. A RESET_STREAM is
emitted unless the stream is already closed due to all data or
RESET_STREAM already transmitted.

This operation is notably useful when upper stream layer wants to close
the connection early due to an error.

This was tested by using a HTTP server which listens with PROXY protocol
support. The corresponding server line on haproxy configuration
deliberately not specify send-proxy. This causes the server to close
abruptly the connection. Without this patch, nothing was done on the QUIC
stream which was kept open until the whole connection is closed. Now, a
proper RESET_STREAM is emitted to report the error.

This should be backported up to 2.7.

2 years agoBUG/MINOR: httpclient/log: free of invalid ptr with httpclient_log_format
William Lallemand [Thu, 22 Dec 2022 14:37:01 +0000 (15:37 +0100)] 
BUG/MINOR: httpclient/log: free of invalid ptr with httpclient_log_format

free_proxy() must check if the ptr is not httpclient_log_format before
trying to free p->conf.logformat_string.

No backport needed.

2 years agoMEDIUM: httpclient: change the default log format to skip duplicate proxy data
William Lallemand [Thu, 22 Dec 2022 14:13:59 +0000 (15:13 +0100)] 
MEDIUM: httpclient: change the default log format to skip duplicate proxy data

The httpclient emits logs in the httplog format, however it still
display the frontend, the backend and the server.

In the case of the httpclient we only need to know that we are using the
httpclient, so the backend and server information are irelevant.
In the case of extra code the name of the proxy can be long and will be
displayed twice which is not useful.

This is the same log-format as the httplog but the %b/%s is now -/- so
the format is still compatible with an httplog parser.

Before:
  <134>Dec 22 15:19:27 haproxy[1013520]: -:- [22/Dec/2022:15:19:27.482] <HTTPCLIENT> <HTTPCLIENT>/<HTTPCLIENT> 2/0/4/6/10 200 848 - - ---- 0/0/0/0/0 0/0 {92.123.236.161} "GET http://r3.o.lencr.org/1234 HTTP/1.1"

After:
  <134>Dec 22 15:19:27 haproxy[1013520]: -:- [22/Dec/2022:15:19:27.482] <HTTPCLIENT> -/- 2/0/4/6/10 200 848 - - ---- 0/0/0/0/0 0/0 {92.123.236.161} "GET http://r3.o.lencr.org/1234 HTTP/1.1"

2 years agoMINOR: httpclient: don't add body when istlen is empty
William Lallemand [Thu, 22 Dec 2022 13:49:43 +0000 (14:49 +0100)] 
MINOR: httpclient: don't add body when istlen is empty

Don't try to create a request with a body in httpclient_req_gen() if the
payload ist has a ptr but no len.

Sometimes people have their httpclient stuck because they use an ist
with a data ptr but no len. Check the len so this mistake doesn't block
the client.

2 years agoBUG/MINOR: ssl/ocsp: httpclient blocked when doing a GET
William Lallemand [Thu, 22 Dec 2022 13:34:01 +0000 (14:34 +0100)] 
BUG/MINOR: ssl/ocsp: httpclient blocked when doing a GET

When the OCSP updater uses the GET method with the payload in the URI,
the body must be set to IST_NULL, or the request won't be sent.

2 years agoBUG/MINOR: pool/stats: Use ullong to report total pool usage in bytes in stats
Christopher Faulet [Thu, 22 Dec 2022 10:05:48 +0000 (11:05 +0100)] 
BUG/MINOR: pool/stats: Use ullong to report total pool usage in bytes in stats

The same change was already performed for the cli. The stats applet and the
prometheus exporter are also concerned. Both use the stats API and rely on
pool functions to get total pool usage in bytes. pool_total_allocated() and
pool_total_used() must return 64 bits unsigned integer to avoid any wrapping
around 4G.

This may be backported to all versions.

2 years agoBUG/MEDIUM: mux-h2: Refuse interim responses with end-stream flag set
Christopher Faulet [Thu, 22 Dec 2022 08:47:01 +0000 (09:47 +0100)] 
BUG/MEDIUM: mux-h2: Refuse interim responses with end-stream flag set

As state in RFC9113#8.1, HEADERS frame with the ES flag set that carries an
informational status code is malformed. However, there is no test on this
condition.

On 2.4 and higher, it is hard to predict consequences of this bug because
end of the message is only reported with a flag. But on 2.2 and lower, it
leads to a crash because there is an unexpected extra EOM block at the end
of an interim response.

Now, when a ES flag is detected on a HEADERS frame for an interim message, a
stream error is sent (RST_STREAM/PROTOCOL_ERROR).

This patch should solve the issue #1972. It should be backported as far as
2.0.

2 years agoCLEANUP: ssl/ocsp: add spaces around operators
William Lallemand [Thu, 22 Dec 2022 09:19:07 +0000 (10:19 +0100)] 
CLEANUP: ssl/ocsp: add spaces around operators

Add spaces around operators in ssl_ocsp_create_request_details().

2 years agoBUG/MINOR: ssl/ocsp: check chunk_strcpy() in ssl_ocsp_get_uri_from_cert()
William Lallemand [Thu, 22 Dec 2022 09:09:11 +0000 (10:09 +0100)] 
BUG/MINOR: ssl/ocsp: check chunk_strcpy() in ssl_ocsp_get_uri_from_cert()

Check the return value of chunk_strcpy() in
ssl_ocsp_get_uri_from_cert().

Should fix issue #1975.

2 years agoMINOR: ssl: Move OCSP code to a dedicated source file
Remi Tricot-Le Breton [Tue, 20 Dec 2022 10:11:17 +0000 (11:11 +0100)] 
MINOR: ssl: Move OCSP code to a dedicated source file

This is a simple cleanup that moves OCSP related code to a dedicated
file instead of interlacing it in some pure ssl connection code.

2 years agoREGTESTS: ssl: Add tests for ocsp auto update mechanism
Remi Tricot-Le Breton [Tue, 20 Dec 2022 10:11:16 +0000 (11:11 +0100)] 
REGTESTS: ssl: Add tests for ocsp auto update mechanism

Tests a subpart of the ocsp auto update feature. It will mainly focus on
the 'auto' mode since the 'on' one relies strongly on timers way too
long to be used in a regtest context.

2 years agoDOC: ssl: Add documentation for ocsp-update option
Remi Tricot-Le Breton [Tue, 20 Dec 2022 10:11:15 +0000 (11:11 +0100)] 
DOC: ssl: Add documentation for ocsp-update option

This adds the documentation for the ocsp-update option.

2 years agoMEDIUM: ssl: Start update task if at least one ocsp-update option is set to on
Remi Tricot-Le Breton [Tue, 20 Dec 2022 10:11:14 +0000 (11:11 +0100)] 
MEDIUM: ssl: Start update task if at least one ocsp-update option is set to on

This patch effectively enables the ocsp auto update mechanism. If a
least one ocsp-update option is enabled in a crt-list, then the ocsp
auto update task is created. It will look into the dedicated ocsp update
tree for the next update to be updated, use the http_client to send the
ocsp request to the proper responder, validate the received ocsp
response and update the ocsp response tree before finally reinserting
the entry in the ocsp update tree (with a next update time set to
now+1H).
The main task will then sleep until another entry needs to be updated.

The task gets scheduled after config check in order to avoid trying to
update ocsp responses while configuration is still being parsed (and
certificates and actual ocsp responses are loaded).