]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 years agoBUG/MAJOR: dns: attempt to lock globaly for msg waiter list instead of use barrier
Emeric Brun [Wed, 20 Oct 2021 08:49:53 +0000 (10:49 +0200)] 
BUG/MAJOR: dns: attempt to lock globaly for msg waiter list instead of use barrier

The barrier is insufficient here to protect the waiters list as we can
definitely catch situations where ds->waiter shows an inconsistency
whereby the element is not attached when entering the "if" block and
is already attached when attaching it later.

This patch uses a larger lock to maintain consistency. Without it the
code would crash in 30-180 minutes under heavy stress, always showing
the same problem (ds->waiter->n->p != &ds->waiter). Now it seems to
always resist, suggesting that this was indeed the problem.

This will have to be backported to 2.4.

3 years agoBUG/MAJOR: dns: tcp session can remain attached to a list after a free
Emeric Brun [Tue, 19 Oct 2021 13:40:10 +0000 (15:40 +0200)] 
BUG/MAJOR: dns: tcp session can remain attached to a list after a free

Using tcp, after a session release and free, the session can remain
attached to the list of sessions with a response message waiting for
a commit (ds->waiter). This results to a use after free of this
session.

Also, on some error path and after free, a session could remain attached
to the lists of available idle/free sessions (ds->list).

This patch ensure to remove the session from those external lists
before a free.

This patch should be backported to all version including
the dns over tcp (2.4)

3 years agoBUG/MEDIUM: tcpcheck: Properly catch early HTTP parsing errors
Christopher Faulet [Wed, 20 Oct 2021 11:53:38 +0000 (13:53 +0200)] 
BUG/MEDIUM: tcpcheck: Properly catch early HTTP parsing errors

When an HTTP response is parsed, early parsing errors are not properly
handled. When this error is reported by the multiplexer, nothing is copied
into the input buffer. The HTX message remains empty but the
HTX_FL_PARSING_ERROR flag is set. In addition CS_FL_EOI is set on the
conn-stream. This last flag must be handled to prevent subscription for
receive events. Otherwise, in the best case, a L7 timeout error is
reported. But a transient loop is also possible if a shutdown is received
because the multiplexer notifies the check of the event while the check
never handles it and waits for more data.

Now, if CS_FL_EOI flag is set on the conn-stream, expect rules are
evaluated. Any error must be handled there.

Thanks to @kazeburo for his valuable report.

This patch should fix the issue #1420. It must be backported at least to
2.4. On 2.3 and 2.2, there is no loop but the wrong error is reported (empty
response instead of invalid one). Thus it may also be backported as far as
2.2.

3 years agoDOC: management: doc about the CLI httpclient
William Lallemand [Tue, 19 Oct 2021 12:53:55 +0000 (14:53 +0200)] 
DOC: management: doc about the CLI httpclient

Add the doc about the CLI httpclient.

3 years agoMINOR: httpclient/cli: access should be only done from expert mode
William Lallemand [Tue, 19 Oct 2021 08:58:30 +0000 (10:58 +0200)] 
MINOR: httpclient/cli: access should be only done from expert mode

Only enable the usage of the CLI HTTP client in expert mode.

3 years agoBUG/MEDIUM: stream: Keep FLT_END analyzers if a stream detects a channel error
Christopher Faulet [Mon, 18 Oct 2021 13:06:20 +0000 (15:06 +0200)] 
BUG/MEDIUM: stream: Keep FLT_END analyzers if a stream detects a channel error

If a channel error (READ_ERRO|READ_TIMEOUT|WRITE_ERROR|WRITE_TIMEOUT) is
detected by the stream, in process_stream(), FLT_END analyers must be
preserved. It is important to be sure to ends filter analysis and be able to
release the stream.

First, filters may release some ressources when FLT_END analyzers are
called. Then, the CF_FL_ANALYZE flag is used to sync end of analysis for the
request and the response. If FLT_END analyzer is ignored on a channel, this
may block the other side and freeze the stream.

This patch must be backported to all stable versions

3 years agoMINOR: jwt: Do not rely on enum order anymore
Remi Tricot-Le Breton [Mon, 18 Oct 2021 13:14:48 +0000 (15:14 +0200)] 
MINOR: jwt: Do not rely on enum order anymore

Replace the test based on the enum value of the algorithm by an explicit
switch statement in case someone reorders it for some reason (while
still managing not to break the regtest).

3 years agoMINOR: jwt: jwt_verify returns negative values in case of error
Remi Tricot-Le Breton [Mon, 18 Oct 2021 13:14:49 +0000 (15:14 +0200)] 
MINOR: jwt: jwt_verify returns negative values in case of error

In order for all the error return values to be distributed on the same
side (instead of surrounding the success error code), the return values
for errors other than a simple verification failure are switched to
negative values. This way the result of the jwt_verify converter can be
compared strictly to 1 as well relative to 0 (any <= 0 return value is
an error).
The documentation was also modified to discourage conversion of the
return value into a boolean (which would definitely not work).

3 years agoMINOR: jwt: Empty the certificate tree during deinit
Remi Tricot-Le Breton [Mon, 18 Oct 2021 13:14:47 +0000 (15:14 +0200)] 
MINOR: jwt: Empty the certificate tree during deinit

The tree in which the JWT certificates are stored was not emptied. It is
now done during deinit.

3 years agoMEDIUM: resolvers: replace bogus resolv_hostname_cmp() with memcmp()
Willy Tarreau [Fri, 15 Oct 2021 06:53:44 +0000 (08:53 +0200)] 
MEDIUM: resolvers: replace bogus resolv_hostname_cmp() with memcmp()

resolv_hostname_cmp() is bogus, it is applied on labels and not plain
names, but doesn't make any distinction between length prefixes and
characters, so it compares the labels lengths via tolower() as well.
The only reason for which it doesn't break is because labels cannot
be larger than 63 bytes, and that none of the common encoding systems
have upper case letters in the lower 63 bytes, that could be turned
into a different value via tolower().

Now that all labels are stored in lower case, we don't need to burn
CPU cycles in tolower() at run time and can use memcmp() instead of
resolv_hostname_cmp(). This results in a ~22% lower CPU usage on large
farms using SRV records:

before:
  18.33%  haproxy                   [.] resolv_validate_dns_response
  10.58%  haproxy                   [.] process_resolvers
  10.28%  haproxy                   [.] resolv_hostname_cmp
   7.50%  libc-2.30.so              [.] tolower
  46.69%  total

after:
  24.73%  haproxy                     [.] resolv_validate_dns_response
   7.78%  libc-2.30.so                [.] __memcmp_avx2_movbe
   3.65%  haproxy                     [.] process_resolvers
  36.16%  total

3 years agoMEDIUM: resolvers: lower-case labels when converting from/to DNS names
Willy Tarreau [Fri, 15 Oct 2021 05:45:38 +0000 (07:45 +0200)] 
MEDIUM: resolvers: lower-case labels when converting from/to DNS names

The whole code relies on performing case-insensitive comparison on
lookups, which is extremely inefficient.

Let's make sure that all labels to be looked up or sent are first
converted to lower case. Doing so is also the opportunity to eliminate
an inefficient memcpy() in resolv_dn_label_to_str() that essentially
runs over a few unaligned bytes at once. As a side note, that call
was dangerous because it relied on a sign-extended size taken from a
string that had to be sanitized first.

This is tagged medium because while this is 100% safe, it may cause
visible changes on the wire at the packet level and trigger bugs in
test programs.

3 years agoCLEANUP: Consistently `unsigned int` for bitfields
Tim Duesterhus [Sat, 16 Oct 2021 16:24:18 +0000 (18:24 +0200)] 
CLEANUP: Consistently `unsigned int` for bitfields

see 6a0dd733906611dea958cf74b9f51bb16028ae20

Found using GitHub's CodeQL scan.

3 years agoCLEANUP: assorted typo fixes in the code and comments
Ilya Shipitsin [Fri, 15 Oct 2021 11:18:21 +0000 (16:18 +0500)] 
CLEANUP: assorted typo fixes in the code and comments

This is 27th iteration of typo fixes

3 years agoMINOR: add ::1 to predefined LOCALHOST acl
Björn Jacke [Fri, 15 Oct 2021 14:32:15 +0000 (16:32 +0200)] 
MINOR: add ::1 to predefined LOCALHOST acl

The "LOCALHOST" ACL currently matches only 127.0.0.1/8. This adds the
IPv6 "::1" address to the supported patterns.

3 years agoCI: Clean up formatting in GitHub Action definitions
Tim Duesterhus [Sat, 16 Oct 2021 16:10:27 +0000 (18:10 +0200)] 
CI: Clean up formatting in GitHub Action definitions

This patch cleans up the formatting within the .yml definition files for GitHub
Actions to ensure a consistent look across all actions.

3 years agoCI: Add `permissions` to GitHub Actions
Tim Duesterhus [Sat, 16 Oct 2021 16:10:26 +0000 (18:10 +0200)] 
CI: Add `permissions` to GitHub Actions

This change locks down the permissions of the access token in GitHub Actions to
only allow reading the repository contents and nothing else.

see https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

3 years agoCLEANUP: Apply strcmp.cocci
Tim Duesterhus [Sat, 16 Oct 2021 15:48:15 +0000 (17:48 +0200)] 
CLEANUP: Apply strcmp.cocci

This fixes the use of the various *cmp functions to use != 0 or == 0.

3 years agoDEV: coccinelle: Add strcmp.cocci
Tim Duesterhus [Sat, 16 Oct 2021 15:48:14 +0000 (17:48 +0200)] 
DEV: coccinelle: Add strcmp.cocci

see e5ff14100aceba70714a2d8549ee7621ffc2701e

3 years ago[RELEASE] Released version 2.5-dev10 v2.5-dev10
Willy Tarreau [Sat, 16 Oct 2021 13:24:22 +0000 (15:24 +0200)] 
[RELEASE] Released version 2.5-dev10

Released version 2.5-dev10 with the following main changes :
    - MINOR: initcall: Rename __GLOBL and __GLOBL1.
    - MINOR: rules: add a new function new_act_rule() to allocate act_rules
    - MINOR: rules: add a file name and line number to act_rules
    - MINOR: stream: report the current rule in "show sess all" when known
    - MINOR: stream: report the current filter in "show sess all" when known
    - CLEANUP: stream: Properly indent current_rule line in "show sess all"
    - BUG/MINOR: lua: Fix lua error handling in `hlua_config_prepend_path()`
    - CI: github: switch to OpenSSL 3.0.0
    - REGTESTS: ssl: Fix references to removed option in test description
    - MINOR: ssl: Add ssllib_name_startswith precondition
    - REGTESTS: ssl: Fix ssl_errors test for OpenSSL v3
    - REGTESTS: ssl: Reenable ssl_errors test for OpenSSL only
    - REGTESTS: ssl: Use mostly TLSv1.2 in ssl_errors test
    - MEDIUM: mux-quic: rationalize tx buffers between qcc/qcs
    - MEDIUM: h3: properly manage tx buffers for large data
    - MINOR: mux-quic: standardize h3 settings sending
    - CLEANUP: h3: remove dead code
    - MINOR: mux-quic: implement standard method to detect if qcc is dead
    - MEDIUM: mux-quic: defer stream shut if remaining tx data
    - MINOR: mux: remove last occurences of qcc ring buffer
    - MINOR: quic: handle CONNECTION_CLOSE frame
    - REGTESTS: ssl: re-enable set_ssl_cert_bundle.vtc
    - MINOR: ssl: add ssl_fc_is_resumed to "option httpslog"
    - MINOR: http: Add http_auth_bearer sample fetch
    - MINOR: jwt: Parse JWT alg field
    - MINOR: jwt: JWT tokenizing helper function
    - MINOR: jwt: Insert public certificates into dedicated JWT tree
    - MINOR: jwt: jwt_header_query and jwt_payload_query converters
    - MEDIUM: jwt: Add jwt_verify converter to verify JWT integrity
    - REGTESTS: jwt: Add tests for the jwt_verify converter
    - BUILD: jwt: fix declaration of EVP_KEY in jwt-h.h
    - MINOR: proto_tcp: use chunk_appendf() to ouput socket setup errors
    - MINOR: proto_tcp: also report the attempted MSS values in error message
    - MINOR: inet: report the faulty interface name in "bind" errors
    - MINOR: protocol: report the file and line number for binding/listening errors
    - MINOR: protocol: uniformize protocol errors
    - MINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero
    - BUG/MEDIUM: resolver: make sure to always use the correct hostname length
    - BUG/MINOR: resolvers: do not reject host names of length 255 in SRV records
    - MINOR: resolvers: fix the resolv_dn_label_to_str() API about trailing zero
    - MEDIUM: listeners: split the thread mask between receiver and bind_conf
    - MINOR: listeners: add clone_listener() to duplicate listeners at boot time
    - MEDIUM: listener: add the "shards" bind keyword
    - BUG/MEDIUM: resolvers: use correct storage for the target address
    - MINOR: resolvers: merge address and target into a union "data"
    - BUG/MEDIUM: resolvers: fix truncated TLD consecutive to the API fix
    - BUG/MEDIUM: jwt: fix base64 decoding error detection
    - BUG/MINOR: jwt: use CRYPTO_memcmp() to compare HMACs
    - DOC: jwt: fix a typo in the jwt_verify() keyword description
    - BUG/MEDIUM: sample/jwt: fix another instance of base64 error detection
    - BUG/MINOR: http-ana: Don't eval front after-response rules if stopped on back
    - BUG/MINOR: sample: Fix 'fix_tag_value' sample when waiting for more data
    - DOC: config: Move 'tcp-response content' at the right place
    - BUG/MINOR: proxy: Use .disabled field as a bitfield as documented
    - MINOR: proxy: Introduce proxy flags to replace disabled bitfield
    - MINOR: sample/arg: Be able to resolve args found in defaults sections
    - MEDIUM: proxy: Warn about ambiguous use of named defaults sections
    - MINOR: proxy: Be able to reference the defaults section used by a proxy
    - MINOR: proxy: Add PR_FL_READY flag on fully configured and usable proxies
    - MINOR: config: Finish configuration for referenced default proxies
    - MINOR: config: No longer remove previous anonymous defaults section
    - MINOR: tcpcheck: Support 2-steps args resolution in defaults sections
    - MEDIUM: rules/acl: Parse TCP/HTTP rules and acls defined in defaults sections
    - MEDIUM: tcp-rules: Eval TCP rules defined in defaults sections
    - MEDIUM: http-ana: Eval HTTP rules defined in defaults sections
    - BUG/MEDIUM: sample: Cumulate frontend and backend sample validity flags
    - REGTESTS: Add scripts to test support of TCP/HTTP rules in defaults sections
    - DOC: config: Add documentation about TCP/HTTP rules in defaults section
    - DOC: config: Rework and uniformize how TCP/HTTP rules are documented
    - BUG/MINOR: proxy: Release ACLs and TCP/HTTP rules of default proxies
    - BUG/MEDIUM: cpuset: fix cpuset size for FreeBSD
    - BUG/MINOR: sample: fix backend direction flags consecutive to last fix
    - BUG/MINOR: listener: fix incorrect return on out-of-memory
    - BUG/MINOR: listener: add an error check for unallocatable trash
    - CLEANUP: listeners: remove unreachable code in clone_listener()

3 years agoCLEANUP: listeners: remove unreachable code in clone_listener()
Willy Tarreau [Sat, 16 Oct 2021 12:58:30 +0000 (14:58 +0200)] 
CLEANUP: listeners: remove unreachable code in clone_listener()

Coverity reported in issue #1416 that label oom3 is not reachable in
function close_listener() added by commit 59a877dfd ("MINOR: listeners:
add clone_listener() to duplicate listeners at boot time"). The code
leading to it was removed during the development of the function, but
not the label itself.

3 years agoBUG/MINOR: listener: add an error check for unallocatable trash
Willy Tarreau [Sat, 16 Oct 2021 12:54:19 +0000 (14:54 +0200)] 
BUG/MINOR: listener: add an error check for unallocatable trash

Coverity noticed in issue #1416 that a missing allocation error was
introduced in tcp_bind_listener() with the rework of error messages by
commit ed1748553 ("MINOR: proto_tcp: use chunk_appendf() to ouput socket
setup errors"). In practice nobody will ever face it but better address
it anyway.

No backport is needed.

3 years agoBUG/MINOR: listener: fix incorrect return on out-of-memory
Willy Tarreau [Sat, 16 Oct 2021 12:45:29 +0000 (14:45 +0200)] 
BUG/MINOR: listener: fix incorrect return on out-of-memory

When the clone_listener() function was added in commit 59a877dfd
("MINOR: listeners: add clone_listener() to duplicate listeners at
boot time"), a stupid bug was introduced when splitting the error
path because while the first case where calloc fails will leave NULL
in the output value, the other cases will return the pointer to a
freed area. This was reported by Coverity in issue #1416.

In practice nobody will face it (out-of-memory while checking config),
but let's fix it.

No backport is needed.

3 years agoBUG/MINOR: sample: fix backend direction flags consecutive to last fix
Willy Tarreau [Sat, 16 Oct 2021 12:41:09 +0000 (14:41 +0200)] 
BUG/MINOR: sample: fix backend direction flags consecutive to last fix

Commit 7a06ffb85 ("BUG/MEDIUM: sample: Cumulate frontend and backend
sample validity flags") introduced a typo confusing the request and
the response direction when checking for validity of a rule applied
to a backend. This was reported by Coverity in issue #1417.

This needs to be backported where the patch above is backported.

3 years agoBUG/MEDIUM: cpuset: fix cpuset size for FreeBSD
Amaury Denoyelle [Fri, 15 Oct 2021 13:22:31 +0000 (15:22 +0200)] 
BUG/MEDIUM: cpuset: fix cpuset size for FreeBSD

Fix the macro used to retrieve the max number of cpus on FreeBSD. The
MAXCPU is not properly defined in userspace and always set to 1 despite
the machine architecture. Replace it with CPU_SETSIZE.

See https://freebsd-hackers.freebsd.narkive.com/gw4BeLum/smp-in-machine-params-h#post6

Without this, the following config file is rejected on FreeBSD even if
the machine is SMP :
  global
    cpu-map 1-2 0-1

This must be backported up to 2.4.

3 years agoBUG/MINOR: proxy: Release ACLs and TCP/HTTP rules of default proxies
Christopher Faulet [Fri, 15 Oct 2021 12:33:34 +0000 (14:33 +0200)] 
BUG/MINOR: proxy: Release ACLs and TCP/HTTP rules of default proxies

It is now possible to have TCP/HTTP rules and ACLs defined in defaults
sections. So we must try to release corresponding lists when a default proxy
is destroyed.

No backport needed.

3 years agoDOC: config: Rework and uniformize how TCP/HTTP rules are documented
Christopher Faulet [Thu, 14 Oct 2021 06:18:50 +0000 (08:18 +0200)] 
DOC: config: Rework and uniformize how TCP/HTTP rules are documented

Now all these rules are documented using the same structure. First there is
a general description with the list of all supported actions. Then all
actions are described in details. Thus, it is easy to have a quick list of
all supported actions and this avoids to have a huge description with all
info about these actions. In addition, when it is possible, we make a
reference to already documented parts.

3 years agoDOC: config: Add documentation about TCP/HTTP rules in defaults section
Christopher Faulet [Wed, 13 Oct 2021 17:27:38 +0000 (19:27 +0200)] 
DOC: config: Add documentation about TCP/HTTP rules in defaults section

Documentation of each directive that can now be used in defaults section was
updated to explain how it works. A special mark was added to specify when a
keyword is supported by defaults sections with a name but not anonymous
ones. In this case an exclamation mark is added.

3 years agoREGTESTS: Add scripts to test support of TCP/HTTP rules in defaults sections
Christopher Faulet [Wed, 13 Oct 2021 16:06:55 +0000 (18:06 +0200)] 
REGTESTS: Add scripts to test support of TCP/HTTP rules in defaults sections

3 scripts are added:

  * startup/default_rules.vtc to check configuration parsing
  * http-rules/default_rules.vtc to check evaluation of HTTP rules
  * tcp-rules/default_rules.vtc to check evaluation of TCP rules

3 years agoBUG/MEDIUM: sample: Cumulate frontend and backend sample validity flags
Christopher Faulet [Wed, 13 Oct 2021 15:22:17 +0000 (17:22 +0200)] 
BUG/MEDIUM: sample: Cumulate frontend and backend sample validity flags

When the sample validity flags are computed to check if a sample is used in
a valid scope, the flags depending on the proxy capabilities must be
cumulated. Historically, for a sample on the request, only the frontend
capability was used to set the sample validity flags while for a sample on
the response only the backend was used. But it is a problem for listen or
defaults proxies. For those proxies, all frontend and backend samples should
be valid. However, at many place, only frontend ones are possible.

For instance, it is impossible to set the backend name (be_name) into a
variable from a listen proxy.

This bug exists on all stable versions. Thus this patch should probably be
backported. But with some caution because the code has probably changed
serveral times. Note that nobody has ever noticed this issue. So the need to
backport this patch must be evaluated for each branch.

3 years agoMEDIUM: http-ana: Eval HTTP rules defined in defaults sections
Christopher Faulet [Wed, 13 Oct 2021 13:35:55 +0000 (15:35 +0200)] 
MEDIUM: http-ana: Eval HTTP rules defined in defaults sections

As for TCP rules, HTTP rules from defaults section are now evaluated. These
rules are evaluated before those of the proxy. The same default ruleset
cannot be attached to the frontend and the backend. However, at this stage,
we take care to not execute twice the same ruleset. So, in theory, a
frontend and a backend could use the same defaults section. In this case,
the default ruleset is executed before all others and only once.

3 years agoMEDIUM: tcp-rules: Eval TCP rules defined in defaults sections
Christopher Faulet [Wed, 13 Oct 2021 13:34:49 +0000 (15:34 +0200)] 
MEDIUM: tcp-rules: Eval TCP rules defined in defaults sections

TCP rules from defaults section are now evaluated. These rules are evaluated
before those of the proxy. For L7 TCP rules, the same default ruleset cannot
be attached to the frontend and the backend. However, at this stage, we take
care to not execute twice the same ruleset. So, in theory, a frontend and a
backend could use the same defaults section. In this case, the default
ruleset is executed before all others and only once.

3 years agoMEDIUM: rules/acl: Parse TCP/HTTP rules and acls defined in defaults sections
Christopher Faulet [Wed, 13 Oct 2021 13:40:15 +0000 (15:40 +0200)] 
MEDIUM: rules/acl: Parse TCP/HTTP rules and acls defined in defaults sections

TCP and HTTP rules can now be defined in defaults sections, but only those
with a name. Because these rules may use conditions based on ACLs, ACLs can
also be defined in defaults sections.

However there are some limitations:

  * A defaults section defining TCP/HTTP rules cannot be used by a defaults
    section
  * A defaults section defining TCP/HTTP rules cannot be used bu a listen
    section
  * A defaults sections defining TCP/HTTP rules cannot be used by frontends
    and backends at the same time
  * A defaults sections defining 'tcp-request connection' or 'tcp-request
    session' rules cannot be used by backends
  * A defaults sections defining 'tcp-response content' rules cannot be used
    by frontends

The TCP request/response inspect-delay of a proxy is now inherited from the
defaults section it uses. For now, these rules are only parsed. No evaluation is
performed.

3 years agoMINOR: tcpcheck: Support 2-steps args resolution in defaults sections
Christopher Faulet [Wed, 13 Oct 2021 13:18:36 +0000 (15:18 +0200)] 
MINOR: tcpcheck: Support 2-steps args resolution in defaults sections

With the commit eaba25dd9 ("BUG/MINOR: tcpcheck: Don't use arg list for
default proxies during parsing"), we restricted the use of sample fetch in
tcpcheck rules defined in a defaults section to those depending on explicit
arguments only. This means a tcpcheck rules defined in a defaults section
cannot rely on argument unresolved during the configuration parsing.

Thanks to recent changes, it is now possible again.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMINOR: config: No longer remove previous anonymous defaults section
Christopher Faulet [Wed, 13 Oct 2021 09:12:50 +0000 (11:12 +0200)] 
MINOR: config: No longer remove previous anonymous defaults section

When the parsing of a defaults section is started, the previous anonymous
defaults section is removed. It may be a problem with referenced defaults
sections. And because all unused defautl proxies are removed after the
configuration parsing, it is not required to remove it so early.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMINOR: config: Finish configuration for referenced default proxies
Christopher Faulet [Wed, 13 Oct 2021 09:04:10 +0000 (11:04 +0200)] 
MINOR: config: Finish configuration for referenced default proxies

If a not-ready default proxy is referenced by a proxy during the
configuration validity check, its configuration is also finished and
PR_FL_READY flag is set on it.

For now, the arguments resolution is the only step performed.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMINOR: proxy: Add PR_FL_READY flag on fully configured and usable proxies
Christopher Faulet [Wed, 13 Oct 2021 08:10:09 +0000 (10:10 +0200)] 
MINOR: proxy: Add PR_FL_READY flag on fully configured and usable proxies

The PR_FL_READY flags must now be set on a proxy at the end of the
configuration validity check to notify it is fully configured and may be
safely used.

For now there is no real usage of this flag. But it will be usefull for
referenced default proxies to finish their configuration only once.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMINOR: proxy: Be able to reference the defaults section used by a proxy
Christopher Faulet [Wed, 13 Oct 2021 07:50:53 +0000 (09:50 +0200)] 
MINOR: proxy: Be able to reference the defaults section used by a proxy

A proxy may now references the defaults section it is used. To do so, a
pointer on the default proxy was added in the proxy structure. And a
refcount must be used to track proxies using a default proxy. A default
proxy is destroyed iff its refcount is equal to zero and when it drops to
zero.

All this stuff must be performed during init/deinit staged for now. All
unreferenced default proxies are removed after the configuration parsing.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMEDIUM: proxy: Warn about ambiguous use of named defaults sections
Christopher Faulet [Tue, 12 Oct 2021 16:57:43 +0000 (18:57 +0200)] 
MEDIUM: proxy: Warn about ambiguous use of named defaults sections

It is now possible to designate the defaults section to use by adding a name
of the corresponding defaults section and referencing it in the desired
proxy section. However, this introduces an ambiguity. This named defaults
section may still be implicitly used by other proxies if it is the last one
defined. In this case for instance:

  default common
    ...

  default frt from common
    ...

  default bck from common
    ...

  frontend fe from frt
    ...

  backend be from bck
    ...

  listen stats
    ...

Here, it is not really obvious the last section will use the 'bck' defaults
section. And it is probably not the expected behaviour. To help users to
properly configure their haproxy, a warning is now emitted if a defaults
section is explicitly AND implicitly used. The configuration manual was
updated accordingly.

Because this patch adds a warning, it should probably not be backported to
2.4. However, if is is backported, it depends on commit "MINOR: proxy:
Introduce proxy flags to replace disabled bitfield".

3 years agoMINOR: sample/arg: Be able to resolve args found in defaults sections
Christopher Faulet [Tue, 12 Oct 2021 16:48:05 +0000 (18:48 +0200)] 
MINOR: sample/arg: Be able to resolve args found in defaults sections

It is not yet used but thanks to this patch, it will be possible to resolve
arguments found in defaults sections. However, there is some restrictions:

  * For FE (frontend) or BE (backend) arguments, if the proxy is explicity
    defined, there is no change. But for implicit proxy (not specified), the
    argument points on the default proxy. when a sample fetch using this
    kind of argument is evaluated, the default proxy replaced by the current
    one.

  * For SRV (server) and TAB (stick-table)arguments, the proxy must always
    be specified. Otherwise an error is reported.

This patch is mandatory to support TCP/HTTP rules in defaults sections.

3 years agoMINOR: proxy: Introduce proxy flags to replace disabled bitfield
Christopher Faulet [Wed, 6 Oct 2021 12:24:19 +0000 (14:24 +0200)] 
MINOR: proxy: Introduce proxy flags to replace disabled bitfield

This change is required to support TCP/HTTP rules in defaults sections. The
'disabled' bitfield in the proxy structure, used to know if a proxy is
disabled or stopped, is replaced a generic bitfield named 'flags'.

PR_DISABLED and PR_STOPPED flags are renamed to PR_FL_DISABLED and
PR_FL_STOPPED respectively. In addition, everywhere there is a test to know
if a proxy is disabled or stopped, there is now a bitwise AND operation on
PR_FL_DISABLED and/or PR_FL_STOPPED flags.

3 years agoBUG/MINOR: proxy: Use .disabled field as a bitfield as documented
Christopher Faulet [Thu, 30 Sep 2021 16:11:54 +0000 (18:11 +0200)] 
BUG/MINOR: proxy: Use .disabled field as a bitfield as documented

.disabled field in the proxy structure is documented to be a bitfield. So
use it as a bitfield. This change was introduced to the 2.5, by commit
8e765b86f ("MINOR: proxy: disabled takes a stopping and a disabled state").

No backport is needed except if the above commit is backported.

3 years agoDOC: config: Move 'tcp-response content' at the right place
Christopher Faulet [Wed, 13 Oct 2021 20:00:39 +0000 (22:00 +0200)] 
DOC: config: Move 'tcp-response content' at the right place

Documentation of 'tcp-response content' was placed before documentation
'tcp-request session'.

3 years agoBUG/MINOR: sample: Fix 'fix_tag_value' sample when waiting for more data
Christopher Faulet [Wed, 13 Oct 2021 15:58:53 +0000 (17:58 +0200)] 
BUG/MINOR: sample: Fix 'fix_tag_value' sample when waiting for more data

The test on the return value of fix_tag_value() function was inverted. To
wait for more data, the return value must be a valid empty string and not
IST_NULL.

This patch must be backported to 2.4.

3 years agoBUG/MINOR: http-ana: Don't eval front after-response rules if stopped on back
Christopher Faulet [Fri, 15 Oct 2021 11:51:34 +0000 (13:51 +0200)] 
BUG/MINOR: http-ana: Don't eval front after-response rules if stopped on back

http-after-response rules evaluation must be stopped after a "allow". It
means the frontend ruleset must not be evaluated if a "allow" was performed
in the backend ruleset. Internally, the evaluation must be stopped if on
HTTP_RULE_RES_STOP return value. Only the "allow" action is concerned by
this change.

Thanks to this patch, http-response and http-after-response behave in the
same way.

This patch should be backported as far as 2.2.

3 years agoBUG/MEDIUM: sample/jwt: fix another instance of base64 error detection
Willy Tarreau [Fri, 15 Oct 2021 10:10:24 +0000 (12:10 +0200)] 
BUG/MEDIUM: sample/jwt: fix another instance of base64 error detection

This is the same as for commit 468c000db ("BUG/MEDIUM: jwt: fix base64
decoding error detection"), but for function sample_conv_jwt_member_query()
that is used by sample converters jwt_header_query() and jwt_payload_query().
Thanks to Tim for the report. No backport is needed.

3 years agoDOC: jwt: fix a typo in the jwt_verify() keyword description
Willy Tarreau [Fri, 15 Oct 2021 09:48:42 +0000 (11:48 +0200)] 
DOC: jwt: fix a typo in the jwt_verify() keyword description

Just a missing "s" in "case". Also, the wide table was slightly reduced
to fit into 80 columns.

3 years agoBUG/MINOR: jwt: use CRYPTO_memcmp() to compare HMACs
Willy Tarreau [Fri, 15 Oct 2021 09:52:41 +0000 (11:52 +0200)] 
BUG/MINOR: jwt: use CRYPTO_memcmp() to compare HMACs

As Tim reported in github issue #1414, we ought to use a constant-time
memcmp() when comparing hashes to avoid time-based attacks. Let's use
CRYPTO_memcmp() since this code already depends on openssl.

No backport is needed, this was just merged into 2.5.

3 years agoBUG/MEDIUM: jwt: fix base64 decoding error detection
Willy Tarreau [Fri, 15 Oct 2021 09:41:16 +0000 (11:41 +0200)] 
BUG/MEDIUM: jwt: fix base64 decoding error detection

Tim reported that a decoding error from the base64 function wouldn't
be matched in case of bad input, and could possibly cause trouble
with -1 being passed in decoded_sig->data. In the case of HMAC+SHA
it is harmless as the comparison is made using memcmp() after checking
for length equality, but in the case of RSA/ECDSA this result is passed
as a size_t to EVP_DigetVerifyFinal() and may depend on the lib's mood.

The fix simply consists in checking the intermediary result before
storing it.

That's precisely what happens with one of the regtests which returned
0 instead of 4 on the intentionally defective token, so the regtest
was fixed as well.

No backport is needed as this is new in this release.

3 years agoBUG/MEDIUM: resolvers: fix truncated TLD consecutive to the API fix
Willy Tarreau [Fri, 15 Oct 2021 06:09:25 +0000 (08:09 +0200)] 
BUG/MEDIUM: resolvers: fix truncated TLD consecutive to the API fix

A bug was introduced by commit previous bf9498a31 ("MINOR: resolvers:
fix the resolv_str_to_dn_label() API about trailing zero") as the code
is particularly contrived and hard to test. The output writes the last
char at [i+1] so the trailing zero and return value must be at i+1.

This will have to be backported where the patch above is backported
since it was needed for a fix.

3 years agoMINOR: resolvers: merge address and target into a union "data"
Willy Tarreau [Thu, 14 Oct 2021 20:52:04 +0000 (22:52 +0200)] 
MINOR: resolvers: merge address and target into a union "data"

These two fields are exclusive as they depend on the data type.
Let's move them into a union to save some precious bytes. This
reduces the struct resolv_answer_item size from 600 to 576 bytes.

3 years agoBUG/MEDIUM: resolvers: use correct storage for the target address
Willy Tarreau [Thu, 14 Oct 2021 20:30:38 +0000 (22:30 +0200)] 
BUG/MEDIUM: resolvers: use correct storage for the target address

The struct resolv_answer_item contains an address field of type
"sockaddr" which is only 16 bytes long, but which is used to store
either IPv4 or IPv6. Fortunately, the contents only overlap with
the "target" field that follows it and that is large enough to
absorb the extra bytes needed to store AAAA records. But this is
dangerous as just moving fields around could result in memory
corruption.

The fix uses a union and removes the casts that were used to hide
the problem.

Older versions need to be checked and possibly fixed. This needs
to be backported anyway.

3 years agoMEDIUM: listener: add the "shards" bind keyword
Willy Tarreau [Tue, 12 Oct 2021 13:23:03 +0000 (15:23 +0200)] 
MEDIUM: listener: add the "shards" bind keyword

In multi-threaded mode, on operating systems supporting multiple listeners on
the same IP:port, this will automatically create this number of multiple
identical listeners for the same line, all bound to a fair share of the number
of the threads attached to this listener. This can sometimes be useful when
using very large thread counts where the in-kernel locking on a single socket
starts to cause a significant overhead. In this case the incoming traffic is
distributed over multiple sockets and the contention is reduced. Note that
doing this can easily increase the CPU usage by making more threads work a
little bit.

If the number of shards is higher than the number of available threads, it
will automatically be trimmed to the number of threads. A special value
"by-thread" will automatically assign one shard per thread.

3 years agoMINOR: listeners: add clone_listener() to duplicate listeners at boot time
Willy Tarreau [Tue, 12 Oct 2021 07:36:10 +0000 (09:36 +0200)] 
MINOR: listeners: add clone_listener() to duplicate listeners at boot time

This function's purpose will be to duplicate a listener in INIT state.
This will be used to ease declaration of listeners spanning multiple
groups, which will thus require multiple FDs hence multiple receivers.

3 years agoMEDIUM: listeners: split the thread mask between receiver and bind_conf
Willy Tarreau [Tue, 12 Oct 2021 06:47:54 +0000 (08:47 +0200)] 
MEDIUM: listeners: split the thread mask between receiver and bind_conf

With groups at some point we'll have to have distinct masks/groups in the
receiver and the bind_conf, because a single bind_conf might require to
instantiate multiple receivers (one per group).

Let's split the thread mask and group to have one for the bind_conf and
another one for the receiver while it remains easy to do. This will later
allow to use different storage for the bind_conf if needed (e.g. support
multiple groups).

3 years agoMINOR: resolvers: fix the resolv_dn_label_to_str() API about trailing zero
Willy Tarreau [Thu, 14 Oct 2021 06:05:25 +0000 (08:05 +0200)] 
MINOR: resolvers: fix the resolv_dn_label_to_str() API about trailing zero

This function suffers from the same API issue as its sibling that does the
opposite direction, it demands that the input string is zero-terminated
*and* that its length *including* the trailing zero is passed on input,
forcing callers to pass length + 1, and itself to use that length - 1
everywhere internally.

This patch addressess this. There is a single caller, which is the
location of the previous bug, so it should probably be backported at
least to keep the code consistent across versions. Note that the
function is called dns_dn_label_to_str() in 2.3 and earlier.

3 years agoBUG/MINOR: resolvers: do not reject host names of length 255 in SRV records
Willy Tarreau [Thu, 14 Oct 2021 06:00:38 +0000 (08:00 +0200)] 
BUG/MINOR: resolvers: do not reject host names of length 255 in SRV records

An off-by-one issue in buffer size calculation used to limit the output
of resolv_dn_label_to_str() to 254 instead of 255.

This must be backported to 2.0.

3 years agoBUG/MEDIUM: resolver: make sure to always use the correct hostname length
Willy Tarreau [Thu, 14 Oct 2021 06:11:48 +0000 (08:11 +0200)] 
BUG/MEDIUM: resolver: make sure to always use the correct hostname length

In issue #1411, @jjiang-stripe reports that do-resolve() sometimes seems
to be trying to resolve crap from random memory contents.

The issue is that action_prepare_for_resolution() tries to measure the
input string by itself using strlen(), while resolv_action_do_resolve()
directly passes it a pointer to the sample, omitting the known length.
Thus of course any other header present after the host in memory are
appended to the host value. It could theoretically crash if really
unlucky, with a buffer that does not contain any zero including in the
index at the end, and if the HTX buffer ends on an allocation boundary.
In practice it should be too low a probability to have ever been observed.

This patch modifies the action_prepare_for_resolution() function to take
the string length on with the host name on input and pass that down the
chain. This should be backported to 2.0 along with commit "MINOR:
resolvers: fix the resolv_str_to_dn_label() API about trailing zero".

3 years agoMINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero
Willy Tarreau [Thu, 14 Oct 2021 05:49:49 +0000 (07:49 +0200)] 
MINOR: resolvers: fix the resolv_str_to_dn_label() API about trailing zero

This function is bogus at the API level: it demands that the input string
is zero-terminated *and* that its length *including* the trailing zero is
passed on input. While that already looks smelly, the trailing zero is
copied as-is, and is then explicitly replaced with a zero... Not only
all callers have to pass hostname_len+1 everywhere to work around this
absurdity, but this requirement causes a bug in the do-resolve() action
that passes random string lengths on input, and that will be fixed on a
subsequent patch.

Let's fix this API issue for now.

This patch will have to be backported, and in versions 2.3 and older,
the function is in dns.c and is called dns_str_to_dn_label().

3 years agoMINOR: protocol: uniformize protocol errors
Willy Tarreau [Thu, 14 Oct 2021 09:59:15 +0000 (11:59 +0200)] 
MINOR: protocol: uniformize protocol errors

Some protocols fail with "error blah [ip:port]" and other fail with
"[ip:port] error blah". All this already appears in a "starting" or
"binding" context after a proxy name. Let's choose a more universal
approach like below where the ip:port remains at the end of the line
prefixed with "for".

  [WARNING]  (18632) : Binding [binderr.cfg:10] for proxy http: cannot bind receiver to device 'eth2' (No such device) for [0.0.0.0:1080]
  [WARNING]  (18632) : Starting [binderr.cfg:10] for proxy http: cannot set MSS to 12 for [0.0.0.0:1080]

3 years agoMINOR: protocol: report the file and line number for binding/listening errors
Willy Tarreau [Thu, 14 Oct 2021 09:55:48 +0000 (11:55 +0200)] 
MINOR: protocol: report the file and line number for binding/listening errors

Binding errors and late socket errors provide no information about
the file and line where the problem occurs. These are all done by
protocol_bind_all() and they only report "Starting proxy blah". Let's
change this a little bit so that:
  - the file name and line number of the faulty bind line is alwas mentioned
  - early binding errors are indicated with "Binding" instead of "Starting".

Now we can for example have this:
  [WARNING]  (18580) : Binding [binderr.cfg:10] for proxy http: cannot bind receiver to device 'eth2' (No such device) [0.0.0.0:1080]

3 years agoMINOR: inet: report the faulty interface name in "bind" errors
Willy Tarreau [Thu, 14 Oct 2021 09:41:19 +0000 (11:41 +0200)] 
MINOR: inet: report the faulty interface name in "bind" errors

When a "bind ... interface foo" statement fails, let's report the
interface name in the error message to help locating it in the file.

3 years agoMINOR: proto_tcp: also report the attempted MSS values in error message
Willy Tarreau [Thu, 14 Oct 2021 09:39:18 +0000 (11:39 +0200)] 
MINOR: proto_tcp: also report the attempted MSS values in error message

The MSS errors are the only ones not indicating what was attempted, let's
report the value that was tried, as it can help users spot them in the
config (particularly if a default value was used).

3 years agoMINOR: proto_tcp: use chunk_appendf() to ouput socket setup errors
Bjoern Jacke [Tue, 12 Jan 2021 18:24:43 +0000 (19:24 +0100)] 
MINOR: proto_tcp: use chunk_appendf() to ouput socket setup errors

Right now only the last warning or error is reported from
tcp_bind_listener(), but it is useful to report all warnings and no only
the last one, so we now emit them delimited by commas. Previously we used
a fixed buffer of 100 bytes, which was too small to store more than one
message, so let's extend it.

Signed-off-by: Bjoern Jacke <bjacke@samba.org>
3 years agoBUILD: jwt: fix declaration of EVP_KEY in jwt-h.h
William Lallemand [Thu, 14 Oct 2021 14:51:08 +0000 (16:51 +0200)] 
BUILD: jwt: fix declaration of EVP_KEY in jwt-h.h

In file included from include/haproxy/jwt.h:25:
include/haproxy/jwt-t.h:66:2: error: unknown type name 'EVP_PKEY'
        EVP_PKEY *pkey;
        ^
1 error generated.

Fix this compilation issue by inserting openssl-compat.h in jwt-t.h

3 years agoREGTESTS: jwt: Add tests for the jwt_verify converter
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:59 +0000 (15:36 +0200)] 
REGTESTS: jwt: Add tests for the jwt_verify converter

This regtest uses the new jwt_header_query, jwt_payload_query and
jwt_verify converters that can be used to validate a JSON Web Token.

3 years agoMEDIUM: jwt: Add jwt_verify converter to verify JWT integrity
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:58 +0000 (15:36 +0200)] 
MEDIUM: jwt: Add jwt_verify converter to verify JWT integrity

This new converter takes a JSON Web Token, an algorithm (among the ones
specified for JWS tokens in RFC 7518) and a public key or a secret, and
it returns a verdict about the signature contained in the token. It does
not simply return a boolean because some specific error cases cas be
specified by returning an integer instead, such as unmanaged algorithms
or invalid tokens. This enables to distinguich malformed tokens from
tampered ones, that would be valid format-wise but would have a bad
signature.
This converter does not perform a full JWT validation as decribed in
section 7.2 of RFC 7519. For instance it does not ensure that the header
and payload parts of the token are completely valid JSON objects because
it would need a complete JSON parser. It only focuses on the signature
and checks that it matches the token's contents.

3 years agoMINOR: jwt: jwt_header_query and jwt_payload_query converters
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:57 +0000 (15:36 +0200)] 
MINOR: jwt: jwt_header_query and jwt_payload_query converters

Those converters allow to extract a JSON value out of a JSON Web Token's
header part or payload part (the two first dot-separated base64url
encoded parts of a JWS in the Compact Serialization format).
They act as a json_query call on the corresponding decoded subpart when
given parameters, and they return the decoded JSON subpart when no
parameter is given.

3 years agoMINOR: jwt: Insert public certificates into dedicated JWT tree
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:56 +0000 (15:36 +0200)] 
MINOR: jwt: Insert public certificates into dedicated JWT tree

A JWT signed with the RSXXX or ESXXX algorithm (RSA or ECDSA) requires a
public certificate to be verified and to ensure it is valid. Those
certificates must not be read on disk at runtime so we need a caching
mechanism into which those certificates will be loaded during init.
This is done through a dedicated ebtree that is filled during
configuration parsing. The path to the public certificates will need to
be explicitely mentioned in the configuration so that certificates can
be loaded as early as possible.
This tree is different from the ckch one because ckch entries are much
bigger than the public certificates used in JWT validation process.

3 years agoMINOR: jwt: JWT tokenizing helper function
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:55 +0000 (15:36 +0200)] 
MINOR: jwt: JWT tokenizing helper function

This helper function splits a JWT under Compact Serialization format
(dot-separated base64-url encoded strings) into its different sub
strings. Since we do not want to manage more than JWS for now, which can
only have at most three subparts, any JWT that has strictly more than
two dots is considered invalid.

3 years agoMINOR: jwt: Parse JWT alg field
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:54 +0000 (15:36 +0200)] 
MINOR: jwt: Parse JWT alg field

The full list of possible algorithms used to create a JWS signature is
defined in section 3.1 of RFC7518. This patch adds a helper function
that converts the "alg" strings into an enum member.

3 years agoMINOR: http: Add http_auth_bearer sample fetch
Remi Tricot-Le Breton [Fri, 1 Oct 2021 13:36:53 +0000 (15:36 +0200)] 
MINOR: http: Add http_auth_bearer sample fetch

This fetch can be used to retrieve the data contained in an HTTP
Authorization header when the Bearer scheme is used. This is used when
transmitting JSON Web Tokens for instance.

3 years agoMINOR: ssl: add ssl_fc_is_resumed to "option httpslog"
William Lallemand [Thu, 14 Oct 2021 12:27:48 +0000 (14:27 +0200)] 
MINOR: ssl: add ssl_fc_is_resumed to "option httpslog"

In order to trace which session were TLS resumed, add the
ssl_fc_is_resumed in the httpslog option.

3 years agoREGTESTS: ssl: re-enable set_ssl_cert_bundle.vtc
William Lallemand [Thu, 14 Oct 2021 09:06:16 +0000 (11:06 +0200)] 
REGTESTS: ssl: re-enable set_ssl_cert_bundle.vtc

The new "ssllib_name_startswith(OpenSSL)" command allows us to
reactivate set_ssl_cert_bundle.vtc with >= OpenSSL 1.1.1 only.

3 years agoMINOR: quic: handle CONNECTION_CLOSE frame
Amaury Denoyelle [Wed, 13 Oct 2021 14:34:49 +0000 (16:34 +0200)] 
MINOR: quic: handle CONNECTION_CLOSE frame

On receiving CONNECTION_CLOSE frame, the mux is flagged for immediate
connection close. A stream is closed even if there is data not ACKed
left if CONNECTION_CLOSE has been received.

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.