]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
2 years agoBUG/MEDIUM: mux-h2: make sure control frames do not refresh the idle timeout
Willy Tarreau [Mon, 15 May 2023 09:28:48 +0000 (11:28 +0200)] 
BUG/MEDIUM: mux-h2: make sure control frames do not refresh the idle timeout

Christopher found as part of the analysis of Tim's issue #1891 that commit
15a4733d5 ("BUG/MEDIUM: mux-h2: make use of http-request and keep-alive
timeouts") introduced in 2.6 incompletely addressed a timeout issue in the
H2 mux. The problem was that the http-keepalive and http-request timeouts
were not applied before it. With that commit they are now considered, but
if a GOAWAY is sent (or even attempted to be sent), then they are not used
anymore again, because the way the code is arranged consists in applying
the client-fin timeout (if set) to the current date, and falling back to
the client timeout, without considering the idle_start period. This means
that a config having a "timeout http-keepalive" would still not close the
connection quickly when facing a client that periodically sends PING,
PRIORITY or whatever other frame types.

In addition, after the GOAWAY was attempted to be sent, there was no check
for pending data in the output buffer, meaning that it would be possible
to truncate some responses in configs involving a very short client-fin
timeout.

Finally the spreading of the closures during the soft-stop brought in 2.6
by commit b5d968d9b ("MEDIUM: global: Add a "close-spread-time" option to
spread soft-stop on time window") didn't consider the particular case of
an idle "pre-connect" connection, which would also live long if a browser
failed to deliver a valid request for a long time.

All of this indicates that the conditions must be reworked so as not to
have that level of exclusion between conditions, but rather stick to the
rules from the doc that are already enforced on other muxes:
  - timeout client always applies if there are data pending, and is
    relative to each new I/O ;
  - timeout http-request applies before the first complete request and
    is relative to the entry in idle state ;
  - timeout http-keepalive applies between idle and the next complete
    request and is relative to the entry in idle state ;
  - timeout client-fin applies when in idle after a shut was sent (here
    the shut is the GOAWAY). The shut may only be considered as sent if
    the buffer is empty and the flags indicate that it was successfully
    sent (or failed) but not if it's still waiting for some room in the
    output buffer for example. This implies that this timeout may then
    lower the http-keepalive/http-request ones.

This is what this patch implements. Of course the client timeout still
applies as a fallback when all the ones above are not set or when their
conditions are not met.

It would seem reasoanble to backport this to 2.7 first, then only after
one or two releases to 2.6.

2 years agoMINOR: ssl: add new sample ssl_c_r_dn
Abhijeet Rastogi [Sun, 14 May 2023 03:04:45 +0000 (20:04 -0700)] 
MINOR: ssl: add new sample ssl_c_r_dn

This patch addresses #1514, adds the ability to fetch DN of the root
ca that was in the chain when client certificate was verified during SSL
handshake.

2 years agoMEDIUM: proxy: stop emitting logs for internal proxies when stopping
William Lallemand [Sun, 14 May 2023 21:23:36 +0000 (23:23 +0200)] 
MEDIUM: proxy: stop emitting logs for internal proxies when stopping

The HTTPCLIENT and the OCSP-UPDATE proxies are internal proxies, we
don't need to display logs of them stopping during the stopping of the
process.

This patch checks if a proxy has the flag PR_CAP_INT so it doesn't
display annoying messages.

2 years agoMINOR: stconn: Remove useless test on sedesc on detach to release the xref
Christopher Faulet [Mon, 15 May 2023 07:53:29 +0000 (09:53 +0200)] 
MINOR: stconn: Remove useless test on sedesc on detach to release the xref

When the SC is detached from the endpoint, the xref between the endpoints is
removed. At this stage, the sedesc cannot be undefined. So we can remove the
test on it.

This issue should fix the issue #2156. No backport needed.

2 years agoMEDIUM: mworker/cli: does not disconnect the master CLI upon error
William Lallemand [Sun, 14 May 2023 16:36:00 +0000 (18:36 +0200)] 
MEDIUM: mworker/cli: does not disconnect the master CLI upon error

In the proxy CLI analyzer, when pcli_parse_request returns -1, the
client was shut to prevent any problem with the master CLI.

This behavior is a little bit excessive and not handy at all in prompt
mode. For example one could have activated multiples mode, then have an
error which disconnect the CLI, and they would have to reconnect and
enter all the modes again.

This patch introduces the pcli_error() function, which only output an
error and flush the input buffer, instead of closing everything.

When encountering a parsing error, this function is used, and the prompt
is written again, without any disconnection.

2 years agoCI: enable monthly Fedora Rawhide clang builds
Ilya Shipitsin [Fri, 12 May 2023 17:26:49 +0000 (19:26 +0200)] 
CI: enable monthly Fedora Rawhide clang builds

that was temporarily disabled due to
https://github.com/haproxy/haproxy/issues/1868

we are unblocked, let us enable clang in matrix

2 years agoMEDIUM: session/ssl: return the SSL error string during a SSL handshake error
William Lallemand [Fri, 12 May 2023 15:13:46 +0000 (17:13 +0200)] 
MEDIUM: session/ssl: return the SSL error string during a SSL handshake error

SSL hanshake error were unable to dump the OpenSSL error string by
default, to do so it was mandatory to configure a error-log-format with
the ssl_fc_err fetch.

This patch implements the session_build_err_string() function which creates
the error log to send during session_kill_embryonic(), a special case is
made with CO_ER_SSL_HANDSHAKE which is able to dump the error string
with ERR_error_string().

Before:
    <134>May 12 17:14:04 haproxy[183151]: 127.0.0.1:49346 [12/May/2023:17:14:04.571] frt2/1: SSL handshake failure

After:
    <134>May 12 17:14:04 haproxy[183151]: 127.0.0.1:49346 [12/May/2023:17:14:04.571] frt2/1: SSL handshake failure (error:0A000418:SSL routines::tlsv1 alert unknown ca)

2 years agoBUG/MINOR: mux-quic: free task on qc_init() app ops failure
Amaury Denoyelle [Fri, 12 May 2023 14:29:48 +0000 (16:29 +0200)] 
BUG/MINOR: mux-quic: free task on qc_init() app ops failure

qc_init() is used to initialize a QUIC MUX instance. On failure, each
resources are released via a series of goto statements. There is one
issue if the app_ops.init callback fails. In this case, MUX task is not
freed.

This can cause a crash as the task is already scheduled. When the
handler will run, it will crash when trying to access qcc instance.

To fix this, properly destroy qcc task on fail_install_app_ops label.

The impact of this bug is minor as app_ops.init callback succeeds most
of the time. However, it may fail on allocation failure due to memory
exhaustion.

This may fix github issue #2154.

This must be backported up to 2.7.

2 years agoBUG/MINOR: mux-quic: differentiate failure on qc_stream_desc alloc
Amaury Denoyelle [Fri, 12 May 2023 14:19:32 +0000 (16:19 +0200)] 
BUG/MINOR: mux-quic: differentiate failure on qc_stream_desc alloc

qc_stream_buf_alloc() can fail for two reasons :
* limit of Tx buffer per connection reached
* allocation failure

The first case is properly treated. A flag QC_CF_CONN_FULL is set on the
connection to interrupt emission. It is cleared when a buffer became
available after in order ACK reception and the MUX tasklet is woken up.

The allocation failure was handled with the same mechanism which in this
case is not appropriate and could lead to a connection transfer freeze.
Instead, prefer to close the connection with a QUIC internal error code.

To differentiate the two causes, qc_stream_buf_alloc() API was changed
to return the number of available buffers to the caller.

This must be backported up to 2.6.

2 years agoBUG/MINOR: quic: do not alloc buf count on alloc failure
Amaury Denoyelle [Thu, 11 May 2023 14:52:48 +0000 (16:52 +0200)] 
BUG/MINOR: quic: do not alloc buf count on alloc failure

The total number of buffer per connection for sending is limited by a
configuration value. To ensure this, <stream_buf_count> quic_conn field
is incremented on qc_stream_buf_alloc().

qc_stream_buf_alloc() may fail if the buffer cannot be allocated. In
this case, <stream_buf_count> should not be incremented. To fix this,
simply move increment operation after buffer allocation.

The impact of this bug is low. However, if a connection suffers from
several buffer allocation failure, it may cause the <stream_buf_count>
to be incremented over the limit without being able to go back down.

This must be backported up to 2.6.

2 years agoBUG/MINOR: mux-quic: handle properly recv ncbuf alloc failure
Amaury Denoyelle [Thu, 11 May 2023 15:00:54 +0000 (17:00 +0200)] 
BUG/MINOR: mux-quic: handle properly recv ncbuf alloc failure

The function qc_get_ncbuf() is used to allocate a ncbuf content.
Allocation failure was handled using a plain BUG_ON.

Fix this by a proper error management. This buffer is only used for
STREAM frame reception to support out-of-order offsets. When an
allocation failed, close the connection with a QUIC internal error code.

This should be backported up to 2.6.

2 years agoBUG/MINOR: mux-quic: properly handle buf alloc failure
Amaury Denoyelle [Thu, 11 May 2023 14:52:17 +0000 (16:52 +0200)] 
BUG/MINOR: mux-quic: properly handle buf alloc failure

A convenience function qc_get_buf() is implemented to centralize buffer
allocation on MUX and H3 layers. However, allocation failure was not
handled properly with a BUG_ON() statement.

Replace this by proper error management. On emission, streams is
temporarily skip over until the next qc_send() invocation. On reception,
H3 uses this function for HTX conversion; on alloc failure the
connection will be closed with QUIC internal error code.

This must be backported up to 2.6.

2 years agoMINOR: mux-quic: remove dedicated function to handle standalone FIN
Amaury Denoyelle [Thu, 11 May 2023 14:49:28 +0000 (16:49 +0200)] 
MINOR: mux-quic: remove dedicated function to handle standalone FIN

Remove QUIC MUX function qcs_http_handle_standalone_fin(). The purpose
of this function was only used when receiving an empty STREAM frame with
FIN bit. Besides, it was called by each application protocol which could
have different approach and render the function purpose unclear.

Invocation of qcs_http_handle_standalone_fin() have been replaced by
explicit code in both H3 and HTTP/0.9 module. In the process, use
htx_set_eom() to reliably put EOM on the HTX message.

This should be backported up to 2.7, along with the previous patch which
introduced htx_set_eom().

2 years agoMINOR: htx: add function to set EOM reliably
Amaury Denoyelle [Thu, 11 May 2023 14:50:04 +0000 (16:50 +0200)] 
MINOR: htx: add function to set EOM reliably

Implement a new HTX utility function htx_set_eom(). If the HTX message
is empty, it will first add a dummy EOT block. This is a small trick
needed to ensure readers will detect the HTX buffer as not empty and
retrieve the EOM flag.

Replace the H2 code related by a htx_set_eom() invocation. QUIC also has
the same code which will be replaced in the next commit.

This should be backported up to 2.7 before the related QUIC patch.

2 years agoBUG/MINOR: quic: Wrong redispatch for external data on connection socket
Frédéric Lécaille [Thu, 11 May 2023 18:43:28 +0000 (20:43 +0200)] 
BUG/MINOR: quic: Wrong redispatch for external data on connection socket

It is possible to receive datagram from other connection on a dedicated
quic-conn socket. This is due to a race condition between bind() and
connect() system calls.

To handle this, an explicit check is done on each datagram. If the DCID
is not associated to the connection which owns the socket, the datagram
is redispatch as if it arrived on the listener socket.

This redispatch step was not properly done because the source address
specified for the redispatch function was incorrect. Instead of using
the datagram source address, we used the address of the socket
quic-conn which received the datagram due to the above race condition.
Fix this simply by using the address from the recvmsg() system call.

The impact of this bug is minor as redispatch on connection socket
should be really rare. However, when it happens it can lead to several
kinds of problems, like for example a connection initialized with an
incorrect peer address. It can also break the Retry token check as this
relies on the peer address.

In fact, Retry token check failure was the reason this bug was found.
When using h2load with thousands of clients, the counter of Retry token
failure was unusually high. With this patch, no failure is reported
anymore for Retry.

Must be backported to 2.7.

2 years agoBUG/MINOR: log: fix memory error handling in parse_logsrv()
Aurelien DARRAGON [Thu, 11 May 2023 16:57:23 +0000 (18:57 +0200)] 
BUG/MINOR: log: fix memory error handling in parse_logsrv()

A check was missing in parse_logsrv() to make sure that malloc-dependent
variable is checked for non-NULL before using it.

If malloc fails, the function raises an error and stops, like it's already
done at a few other places within the function.

This partially fixes GH #2130.

It should be backported to every stable versions.

2 years agoBUG/MINOR: errors: handle malloc failure in usermsgs_put()
Aurelien DARRAGON [Thu, 11 May 2023 16:49:14 +0000 (18:49 +0200)] 
BUG/MINOR: errors: handle malloc failure in usermsgs_put()

usermsgs_buf.size is set without first checking if previous malloc
attempt succeeded.

This could fool the buffer API into assuming that the buffer is
initialized, resulting in unsafe read/writes.

Guarding usermsgs_buf.size assignment with the malloc attempt result
to make the buffer initialization safe against malloc failures.

This partially fixes GH #2130.

It should be backported up to 2.6.

2 years agoEXAMPLES: fix race condition in lua mailers script
Aurelien DARRAGON [Thu, 11 May 2023 15:46:42 +0000 (17:46 +0200)] 
EXAMPLES: fix race condition in lua mailers script

Christopher reported a rare race condition involving 'healthcheckmail.vtc'

The regtest would randomly FAIL with this kind of error:

    **   S1    === expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server b...
    **** S1    EXPECT MATCH ~ "[^:\[ ]\[581669\]: Health check for server be1/srv1 failed.+check duration: [[:digit:]]+ms.+status: 0/1 DOWN."
    **   S1    === recv info
    **** S1    syslog|<25>May 11 15:38:46 haproxy[581669]: Server be1/srv1 is DOWN. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
    **** S1    syslog|<24>May 11 15:38:46 haproxy[581669]: backend be1 has no server available!

It turns out that this it due to the recent commit 7963fb5 ("REGTESTS: use
lua mailer script for mailers tests") in which we tell the regtest to use
the new lua mailers instead of the legacy mailers API.

However, in the lua mailers script, due to the event subscriptions being
performed from a lua task, it is possible that the subscription may be
delayed during startup. Indeed lua tasks relie on the scheduler which runs
tasks with no ordering guarantees. Thus early tasks, including server
checks which are used in the regtest are competing during startup.

As such, we may end up with some events that are generated right before
the lua mailers script starts subscribing to events (because the lua task
is scheduled but started yet), resulting in events loss from lua point of
view.

To fix this and to make lua mailers more reliable during startup, we now
perform the events subscription from an init function instead of an
asynchronous task. (The init function is called synchronously during
haproxy post_init, and exclusively runs before the scheduler starts)

This should be enough to prevent healthcheckmail.vtc from randomly failing

2 years agoDOC: lua: fix core.{proxies,frontends,backends} visibility
Aurelien DARRAGON [Thu, 11 May 2023 15:31:46 +0000 (17:31 +0200)] 
DOC: lua: fix core.{proxies,frontends,backends} visibility

Despite the doc not mentionning it, core.{proxies,frontends,backends}
methods are also available from init context.
(through core.register_init() functions)

Updating the documentation to reflect this possibility.

2 years agoMINOR: ncbuf: missing malloc checks in standalone code
Aurelien DARRAGON [Thu, 11 May 2023 13:28:20 +0000 (15:28 +0200)] 
MINOR: ncbuf: missing malloc checks in standalone code

Some malloc resulsts were not checked in standalone ncbuf code.

As this is debug/test code, we don't need to explicitly handle memory
errors, we just add some BUG_ON() to ensure that memory is properly
allocated and prevent unexpected results.

This partially fixes issue GH #2130.

No backport needed.

2 years agoBUILD: debug: fix build issue on 32-bit platforms in "debug dev task"
Willy Tarreau [Fri, 12 May 2023 02:40:06 +0000 (04:40 +0200)] 
BUILD: debug: fix build issue on 32-bit platforms in "debug dev task"

Commit 986798718 ("DEBUG: cli: add "debug dev task" to show/wake/expire/kill
tasks and tasklets") caused a build failure on 32-bit platforms when parsing
the task's pointer. Let's use strtoul() and not strtoll(). No backport is
needed, unless the commit above gets backported.

2 years agoMINOR: httpclient: allow to disable the DNS resolvers of the httpclient
William Lallemand [Thu, 11 May 2023 19:08:38 +0000 (21:08 +0200)] 
MINOR: httpclient: allow to disable the DNS resolvers of the httpclient

httpclient.resolvers.disabled allow to disable completely the resolvers
of the httpclient, prevents the creation of the "default" resolvers
section, and does not insert the http do-resolve rule in the proxies.

2 years agoMINOR: cli: make "show fd" identify QUIC connections and listeners
Willy Tarreau [Thu, 11 May 2023 15:06:22 +0000 (17:06 +0200)] 
MINOR: cli: make "show fd" identify QUIC connections and listeners

Now we can detect the listener associated with a QUIC listener and report
a bit more info (e.g. listening port and frontend name), and provide a bit
more info about connections as well, and filter on both front connections
and listeners using the "l" and "f" flags.

2 years agoMINOR: master/cli: also implement the timed prompt on the master CLI
Willy Tarreau [Thu, 11 May 2023 14:14:02 +0000 (16:14 +0200)] 
MINOR: master/cli: also implement the timed prompt on the master CLI

This provides more consistency between the master and the worker. When
"prompt timed" is passed on the master, the timed mode is toggled. When
enabled, for a master it will show the master process' uptime, and for
a worker it will show this worker's uptime. Example:

  master> prompt timed
  [0:00:00:50] master> show proc
  #<PID>          <type>          <reloads>       <uptime>        <version>
  11940           master          1 [failed: 0]   0d00h02m10s     2.8-dev11-474c14-21
  # workers
  11955           worker          0               0d00h00m59s     2.8-dev11-474c14-21
  # old workers
  11942           worker          1               0d00h02m10s     2.8-dev11-474c14-21
  # programs

  [0:00:00:58] master> @!11955
  [0:00:01:03] 11955> @!11942
  [0:00:02:17] 11942> @
  [0:00:01:10] master>

2 years agoMINOR: cli: add an option to display the uptime in the CLI's prompt
Willy Tarreau [Thu, 4 May 2023 12:22:36 +0000 (14:22 +0200)] 
MINOR: cli: add an option to display the uptime in the CLI's prompt

Entering "prompt timed" toggles reporting of the process' uptime in
the prompt, which will report days, hours, minutes and seconds since
it was started. As discussed with Tim in issue #2145, this can be
convenient to roughly estimate the time between two outputs, as well
as detecting that a process failed to be reloaded for example.

2 years agoBUG/MINOR: cli: don't complain about empty command on empty lines
Willy Tarreau [Thu, 11 May 2023 14:32:56 +0000 (16:32 +0200)] 
BUG/MINOR: cli: don't complain about empty command on empty lines

There's something very irritating on the CLI, when just pressing ENTER,
it complains "Unknown command: ''..." and dumps all the help. This
action is often done to add a bit of clearance after a dump to visually
find delimitors later, but this stupid error makes it unusable. This
patch addresses this by just returning on empty command instead of trying
to look up a matching keyword. It will result in an empty line to mark
the end of the empty command and a prompt again.

It's probably not worth backporting this given that nobody seems to have
complained about it yet.

2 years agoCLEANUP: acl: discard prune_acl_cond() function
Aurelien DARRAGON [Thu, 11 May 2023 12:13:07 +0000 (14:13 +0200)] 
CLEANUP: acl: discard prune_acl_cond() function

Thanks to previous commit, we have no more use for prune_acl_cond(),
let's remove it to prevent code duplication.

2 years agoMINOR: tree-wide: use free_acl_cond() where relevant
Aurelien DARRAGON [Thu, 11 May 2023 10:29:51 +0000 (12:29 +0200)] 
MINOR: tree-wide: use free_acl_cond() where relevant

Now that we have free_acl_cond(cond) function that does cond prune then
frees cond, replace all occurences of this pattern:

   | prune_acl_cond(cond)
   | free(cond)

with:

   | free_acl_cond(cond)

2 years agoCLEANUP: http_act: use http_free_redirect_rule() to clean redirect act
Aurelien DARRAGON [Thu, 11 May 2023 10:42:24 +0000 (12:42 +0200)] 
CLEANUP: http_act: use http_free_redirect_rule() to clean redirect act

Since redirect rules now have a dedicated cleanup function, better use
it to prevent code duplication.

2 years agoBUG/MINOR: http_rules: fix errors paths in http_parse_redirect_rule()
Aurelien DARRAGON [Thu, 11 May 2023 08:34:49 +0000 (10:34 +0200)] 
BUG/MINOR: http_rules: fix errors paths in http_parse_redirect_rule()

http_parse_redirect_rule() doesn't perform enough checks around NULL
returning allocating functions.

Moreover, existing error paths don't perform cleanups. This could lead to
memory leaks.

Adding a few checks and a cleanup path to ensure memory errors are
properly handled and that no memory leaks occurs within the function
(already allocated structures are freed on error path).

It should partially fix GH #2130.

This patch depends on ("MINOR: proxy: add http_free_redirect_rule() function")

This could be backported up to 2.4. The patch is also relevant for
2.2 but "MINOR: proxy: add http_free_redirect_rule() function" would
need to be adapted first.

==

Backport notes:

-> For 2.2 only:

Replace:

    (strcmp(args[cur_arg], "drop-query") == 0)

with:

    (!strcmp(args[cur_arg],"drop-query"))

-> For 2.2 and 2.4:

Replace:

    "expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query', 'ignore-empty' or 'append-slash' (was '%s')",

with:

    "expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s')",

2 years agoMINOR: proxy: add http_free_redirect_rule() function
Aurelien DARRAGON [Thu, 11 May 2023 08:30:27 +0000 (10:30 +0200)] 
MINOR: proxy: add http_free_redirect_rule() function

Adding http_free_redirect_rule() function to free a single redirect rule
since it may be required to free rules outside of free_proxy() function.

This patch is required for an upcoming bugfix.

[for 2.2, free_proxy function did not exist (first seen in 2.4), thus
http_free_redirect_rule() needs to be deducted from haproxy.c deinit()
function if the patch is required]

2 years agoBUG/MINOR: proxy: missing free in free_proxy for redirect rules
Aurelien DARRAGON [Thu, 11 May 2023 10:36:32 +0000 (12:36 +0200)] 
BUG/MINOR: proxy: missing free in free_proxy for redirect rules

cookie_str from struct redirect, which may be allocated through
http_parse_redirect_rule() function is not properly freed on proxy
cleanup within free_proxy().

This could be backported to all stable versions.

[for 2.2, free_proxy() did not exist so the fix needs to be performed
directly in deinit() function from haproxy.c]

2 years agoMINOR: stconn: Add a cross-reference between SE descriptor
Christopher Faulet [Thu, 11 May 2023 12:40:27 +0000 (14:40 +0200)] 
MINOR: stconn: Add a cross-reference between SE descriptor

A xref is added between the endpoint descriptors. It is created when the
server endpoint is attached to the SC and it is destroyed when an endpoint
is detached.

This xref is not used for now. But it will be useful to retrieve info about
an endpoint for the opposite side. It is also the warranty there is still a
endpoint attached on the other side.

2 years agoBUG/MEDIUM: mux-fcgi: Don't request more room if mux is waiting for more data
Christopher Faulet [Thu, 11 May 2023 09:33:05 +0000 (11:33 +0200)] 
BUG/MEDIUM: mux-fcgi: Don't request more room if mux is waiting for more data

A mux must never report it is waiting for room in the channel buffer if this
buffer is empty. Because there is nothing the application layer can do to
unblock the situation. Indeed, when this happens, it means the mux is
waiting for data to progress. It typically happens when all headers are not
received.

In the FCGI mux, if some data remain in the RX buffer but the channel buffer
is empty, it does no longer report it is waiting for room.

This patch should fix the issue #2150. It must be backported as far as 2.6.

2 years agoBUG/MEDIUM: mux-fcgi: Never set SE_FL_EOS without SE_FL_EOI or SE_FL_ERROR
Christopher Faulet [Thu, 11 May 2023 09:16:59 +0000 (11:16 +0200)] 
BUG/MEDIUM: mux-fcgi: Never set SE_FL_EOS without SE_FL_EOI or SE_FL_ERROR

When end-of-stream is reported by a FCGI stream, we must take care to also
report an error if end-of-input was not reported. Indeed, it is now
mandatory to set SE_FL_EOI or SE_FL_ERROR flags when SE_FL_EOS is set.

It is a 2.8-specific issue. No backport needed.

2 years agoMINOR: stats: report the listener's protocol along with the address in stats
Willy Tarreau [Thu, 11 May 2023 12:49:43 +0000 (14:49 +0200)] 
MINOR: stats: report the listener's protocol along with the address in stats

When "optioon socket-stats" is used in a frontend, its listeners have
their own stats and will appear in the stats page. And when the stats
page has "stats show-legends", then a tooltip appears on each such
socket with ip:port and ID. The problem is that since QUIC arrived, it
was not possible to distinguish the TCP listeners from the QUIC ones
because no protocol indication was mentioned. Now we add a "proto"
legend there with the protocol name, so we can see "tcp4" or "quic6"
and figure how the socket is bound.

2 years agoMEDIUM: mux-quic: adjust transport layer error handling
Amaury Denoyelle [Thu, 4 May 2023 16:52:42 +0000 (18:52 +0200)] 
MEDIUM: mux-quic: adjust transport layer error handling

Following previous patch, error notification from quic_conn has been
adjusted to rely on standard connection flags. Most notably, CO_FL_ERROR
on the connection instance when a fatal error is detected.

Check for CO_FL_ERROR is implemented by qc_send(). If set the new flag
QC_CF_ERR_CONN will be set for the MUX instance. This flag is similar to
the local error flag and will abort most of the futur processing. To
ensure stream upper layer is also notified, qc_wake_some_streams()
called by qc_process() will put the stream on error if this new flag is
set.

This should be backported up to 2.7.

2 years agoMEDIUM: quic: streamline error notification
Amaury Denoyelle [Wed, 10 May 2023 09:57:40 +0000 (11:57 +0200)] 
MEDIUM: quic: streamline error notification

When an error is detected at quic-conn layer, the upper MUX must be
notified. Previously, this was done relying on quic_conn flag
QUIC_FL_CONN_NOTIFY_CLOSE set and the MUX wake callback called on
connection closure.

Adjust this mechanism to use an approach more similar to other transport
layers in haproxy. On error, connection flags are updated with
CO_FL_ERROR, CO_FL_SOCK_RD_SH and CO_FL_SOCK_WR_SH. The MUX is then
notified when the error happened instead of just before the closing. To
reflect this change, qc_notify_close() has been renamed qc_notify_err().
This function must now be explicitely called every time a new error
condition arises on the quic_conn layer.

To ensure MUX send is disabled on error, qc_send_mux() now checks
CO_FL_SOCK_WR_SH. If set, the function returns an error. This should
prevent the MUX from sending data on closing or draining state.

To complete this patch, MUX layer must now check for CO_FL_ERROR
explicitely. This will be the subject of the following commit.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: simplify return path of qc_send()
Amaury Denoyelle [Wed, 10 May 2023 09:59:10 +0000 (11:59 +0200)] 
MINOR: mux-quic: simplify return path of qc_send()

Remove the unnecessary err label for qc_send(). Anyway, this label
cannot be used once some frames are sent because there is no cleanup
part for it.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: factorize send subscribing
Amaury Denoyelle [Wed, 3 May 2023 07:50:25 +0000 (09:50 +0200)] 
MINOR: mux-quic: factorize send subscribing

Factorize code for send subscribing on the lower layer in a dedicated
function qcc_subscribe_send(). This allows to call the lower layer only
if not already subscribed and print a trace in this case. This should
help to understand when subscribing is really performed.

In the future, this function may be extended to avoid subscribing under
new conditions, such as connection already on error.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: do not send STREAM frames if already subscribe
Amaury Denoyelle [Wed, 3 May 2023 07:50:39 +0000 (09:50 +0200)] 
MINOR: mux-quic: do not send STREAM frames if already subscribe

Do not built STREAM frames if MUX is already subscribed for sending on
lower layer. Indeed, this means that either socket currently encountered
a transient error or congestion window is full.

This change is an optimization which prevents to allocate and release a
series of STREAM frames for nothing under congestion.

Note that nothing is done for other frames (flow-control, RESET_STREAM
and STOP_SENDING). Indeed, these frames are not restricted by flow
control. However, this means that they will be allocated for nothing if
send is blocked on a transient error.

This should be backported up to 2.7.

2 years agoMINOR: mux-quic: add traces for stream wake
Amaury Denoyelle [Thu, 11 May 2023 11:41:41 +0000 (13:41 +0200)] 
MINOR: mux-quic: add traces for stream wake

Add traces for when an upper layer stream is woken up by the MUX. This
should help to diagnose frozen stream issues.

This should be backported up to 2.7.

2 years agoBUG/MINOR: mux-quic: no need to subscribe for detach streams
Amaury Denoyelle [Wed, 3 May 2023 07:50:04 +0000 (09:50 +0200)] 
BUG/MINOR: mux-quic: no need to subscribe for detach streams

When detach is conducted by stream endpoint layer, a stream is either
freed or just flagged as detached if the transfer is not yet finished.
In the latter case, the stream will be finally freed via
qc_purge_streams() which is called periodically.

A subscribe was done on quic-conn layer if a stream cannot be freed via
qc_purge_streams() as this means FIN STREAM has not yet been sent.
However, this is unnecessary as either HTX EOM was not yet received and
we are waiting for the upper layer, or FIN stream is still in the buffer
but was not yet transmitted due to an incomplete transfer, in which case
a subscribe should have already been done.

This should be backported up to 2.7.

2 years agoBUG/MINOR: mux-quic: do not free frame already released by quic-conn
Amaury Denoyelle [Tue, 9 May 2023 12:10:55 +0000 (14:10 +0200)] 
BUG/MINOR: mux-quic: do not free frame already released by quic-conn

MUX uses qc_send_mux() function to send frames list over a QUIC
connection. On network congestion, the lower layer will reject some
frames and it is the MUX responsibility to free them. There is another
category of error which are when the sendto() fails. In this case, the
lower layer will free the packet and its attached frames and the MUX
should not touch them.

This model was violated by MUX layer for RESET_STREAM and STOP_SENDING
emission. In this case, frames were freed every time by the MUX on
error. This causes a double free error which lead to a crash.

Fix this by always ensuring if frames were rejected by the lower layer
before freeing them on the MUX. This is done simply by checking if frame
list is not empty, as RESET_STREAM and STOP_SENDING are sent
individually.

This bug was never reproduced in production. Thus, it is labelled as
MINOR.

This must be backported up to 2.7.

2 years agoBUG/MINOR: mux-quic: do not prevent shutw on error
Amaury Denoyelle [Wed, 10 May 2023 08:41:47 +0000 (10:41 +0200)] 
BUG/MINOR: mux-quic: do not prevent shutw on error

Since recent modification of MUX error processing, shutw operation was
skipped for a connection reported as on error. However, this can caused
the stream layer to not be notified about error. The impact of this bug
is unknown but it may lead to stream never closed.

To fix this, simply skip over send operations when connection is on
error while keep notifying the stream layer.

This should be backported up to 2.7.

2 years agoMINOR: stats: report the number of times the global maxconn was reached
Willy Tarreau [Thu, 11 May 2023 11:51:31 +0000 (13:51 +0200)] 
MINOR: stats: report the number of times the global maxconn was reached

As discussed a few times over the years, it's quite difficult to know
how often we stop accepting connections because the global maxconn was
reached. This is not easy to know because when we reach the limit we
stop accepting but we don't know if incoming connections are pending,
so it's not possible to know how many were delayed just because of this.
However, an interesting equivalent metric consist in counting the number
of times an accepted incoming connection resulted in the limit being
reached. I.e. "we've accepted the last one for now". That doesn't imply
any other one got delayed but it's a factual indicator that something
might have been delayed. And by counting the number of such events, it
becomes easier to know whether some limits need to be adjusted because
they're reached often, or if it's exceptionally rare.

The metric is reported as a counter in show info and on the stats page
in the info section right next to "maxconn".

2 years agoMINOR: stats: report the total number of warnings issued
Willy Tarreau [Thu, 11 May 2023 10:02:21 +0000 (12:02 +0200)] 
MINOR: stats: report the total number of warnings issued

Now in "show info" we have a TotalWarnings field that reports the total
number of warnings issued since the process started. It's also reported
in the the stats page next to the uptime.

2 years agoDEBUG: list: add DEBUG_LIST to purposely corrupt list heads after delete
Willy Tarreau [Thu, 11 May 2023 09:33:35 +0000 (11:33 +0200)] 
DEBUG: list: add DEBUG_LIST to purposely corrupt list heads after delete

LIST_DELETE doesn't affect the previous pointers of the stored element.
This can sometimes hide bugs when such a pointer is reused by accident
in a LIST_NEXT() or equivalent after having been detached for example, or
ia another LIST_DELETE is performed again, something that LIST_DEL_INIT()
is immune to. By compiling with -DDEBUG_LIST, we'll replace a freshly
detached list element with two invalid pointers that will cause a crash
in case of accidental misuse. It's not enabled by default.

2 years agoBUG/MINOR: quic: Buggy acknowlegments of acknowlegments function
Frédéric Lécaille [Tue, 2 May 2023 06:57:37 +0000 (08:57 +0200)] 
BUG/MINOR: quic: Buggy acknowlegments of acknowlegments function

qc_treat_ack_of_ack() must remove ranges of acknowlegments from an ebtree which
have been acknowledged. This is done keeping track of the largest acknowledged
packet number which has been acknowledged and sent with an ack-eliciting packet.
But due to the data structure of the acknowledgement ranges used to build an ACK frame,
one must leave at least one range in such an ebtree which must at least contain
a unique one-element range with the largest acknowledged packet number as element.

This issue was revealed by @Tristan971 in GH #2140.

Must be backported in 2.7 and 2.6.

2 years agoCLEANUP: hlua_fcn/queue: make queue:push() easier to read
Aurelien DARRAGON [Wed, 10 May 2023 17:59:35 +0000 (19:59 +0200)] 
CLEANUP: hlua_fcn/queue: make queue:push() easier to read

Adding some spaces and code comments in queue:push() function to make
it easier to read.

2 years agoBUG/MINOR: hlua_fcn/queue: fix reference leak
Aurelien DARRAGON [Wed, 10 May 2023 17:47:08 +0000 (19:47 +0200)] 
BUG/MINOR: hlua_fcn/queue: fix reference leak

When pushing a lua object through lua Queue class, a new reference is
created from the object so that it can be safely restored when needed.

Likewise, when popping an object from lua Queue class, the object is
restored at the top of the stack via its reference id.

However, once the object is restored the related queue entry is removed,
thus the object reference must be dropped to prevent reference leak.

2 years agoBUG/MINOR: hlua_fcn/queue: fix broken pop_wait()
Aurelien DARRAGON [Wed, 10 May 2023 17:30:26 +0000 (19:30 +0200)] 
BUG/MINOR: hlua_fcn/queue: fix broken pop_wait()

queue:pop_wait() was broken during late refactor prior to merge.
(Due to small modifications to ensure that pop() returns nil on empty
queue instead of nothing)

Because of this, pop_wait() currently behaves exactly as pop(), resulting
in 100% active CPU when used in a while loop.

Indeed, _hlua_queue_pop() should explicitly return 0 when the queue is
empty since pop_wait logic relies on this and the pushnil should be
handled directly in queue:pop() function instead.

Adding some comments as well to document this.

2 years agoBUG/MEDIUM: filters: Don't deinit filters for disabled proxies during startup
Christopher Faulet [Thu, 11 May 2023 07:11:57 +0000 (09:11 +0200)] 
BUG/MEDIUM: filters: Don't deinit filters for disabled proxies during startup

During the startup stage, if a proxy was disabled in config, all filters
were released and removed. But it may be an issue if some info are shared
between filters of the same type. Resources may be released too early.

It happens with ACLs defined in SPOE configurations. Pattern expressions can
be shared between filters. To fix the issue, filters for disabled proxies
are no longer released during the startup stage but only when HAProxy is
stopped.

This commit depends on the previous one ("MINOR: spoe: Don't stop disabled
proxies"). Both must be backported to all stable versions.

2 years agoMINOR: spoe: Don't stop disabled proxies
Christopher Faulet [Thu, 11 May 2023 07:08:28 +0000 (09:08 +0200)] 
MINOR: spoe: Don't stop disabled proxies

SPOE register a signal handler to be able to stop SPOE applets ASAP during
soft-stop. Disabled proxies must be ignored at this staged because they are
not fully configured.

For now, it is useless but this change is mandatory to fix a bug.

2 years agoBUILD: mjson: Fix warning about unused variables
Christopher Faulet [Wed, 10 May 2023 16:41:54 +0000 (18:41 +0200)] 
BUILD: mjson: Fix warning about unused variables

clang 15 reports unused variables in src/mjson.c:

  src/mjson.c:196:21: fatal error: expected ';' at end of declaration
    int __maybe_unused n = 0;

and

  src/mjson.c:727:17: fatal error: variable 'n' set but not used [-Wunused-but-set-variable]
    int sign = 1, n = 0;

An issue was created on the project, but it was not fixed for now:

   https://github.com/cesanta/mjson/issues/51

So for now, to fix the build issue, these variables are declared as unused.
Of course, if there is any update on this library, be careful to review this
patch first to be sure it is always required.

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

2 years ago[RELEASE] Released version 2.8-dev11 v2.8-dev11
Willy Tarreau [Thu, 11 May 2023 03:33:21 +0000 (05:33 +0200)] 
[RELEASE] Released version 2.8-dev11

Released version 2.8-dev11 with the following main changes :
    - BUILD: debug: do not check the isolated_thread variable in non-threaded builds
    - BUILD: quic: fix build warning when threads are disabled
    - CI: more granular failure on generating build matrix
    - CLEANUP: quic: No more used q_buf structure
    - CLEANUP: quic: Rename several <buf> variables in quic_frame.(c|h)
    - CLEANUP: quic: Typo fix for quic_connection_id pool
    - BUG/MINOR: quic: Wrong key update cipher context initialization for encryption
    - BUG/MEDIUM: cache: Don't request more room than the max allowed
    - MEDIUM: stconn: Be sure to always be able to unblock a SC that needs room
    - EXAMPLES: fix IPV6 support for lua mailers script
    - BUILD: ssl: buggy -Werror=dangling-pointer since gcc 13.0
    - DOC: stconn: Update comments about ABRT/SHUT for stconn structure
    - BUG/MEDIUM: stats: Require more room if buffer is almost full
    - DOC: configuration: add info about ssl-engine for 2.6
    - BUG/MINOR: mux-quic: fix transport VS app CONNECTION_CLOSE
    - BUG/MEDIUM: mux-quic: wakeup tasklet to close on error
    - DEV: flags: add a script to decode most flags in the "show sess all" output
    - BUG/MINOR: quic: Possible crash when dumping version information
    - BUG/MINOR: config: make compression work again in defaults section
    - BUG/MEDIUM: stream: Forward shutdowns when unhandled errors are caught
    - MEDIUM: stream: Resync analyzers at the end of process_stream() on change
    - DEV: flags: add missing stream flags to show-sess-to-flags
    - DEV: flags/show-sess-to-flags: only retrieve hex digits from hex fields
    - DEV: flags/show-sess-to-flags: add support for color output
    - CLEANUP: src/listener.c: remove redundant NULL check

2 years agoCLEANUP: src/listener.c: remove redundant NULL check
Ilya Shipitsin [Wed, 26 Apr 2023 19:05:12 +0000 (21:05 +0200)] 
CLEANUP: src/listener.c: remove redundant NULL check

fixes #2031

quoting Willy Tarreau:

"Originally the listeners were intended to work without a bind_conf
(e.g. for FTP processing) hence these tests, but over time the
bind_conf has become omnipresent"

2 years agoDEV: flags/show-sess-to-flags: add support for color output
Willy Tarreau [Wed, 10 May 2023 15:48:00 +0000 (17:48 +0200)] 
DEV: flags/show-sess-to-flags: add support for color output

Highlighting a few fields helps spot them, but only if there are not too
many. What is done here is the following:
  - the first line of each stream is highlighted in white (helps find
    beginning/end in long dumps
  - fields in the form name=value where value starts with upper case
    letters are considered as a state dump (e.g. stconn state) and are
    also highlighted. This results in ~20 pairs. In this case the name
    and value use two different colors (cyan vs yellow) to further help
    find what is being looked for

This is only done when the output is a terminal or when --color=always
is passed. It's also possible to disable it with --color=never or
--no-color.

2 years agoDEV: flags/show-sess-to-flags: only retrieve hex digits from hex fields
Willy Tarreau [Wed, 10 May 2023 15:46:10 +0000 (17:46 +0200)] 
DEV: flags/show-sess-to-flags: only retrieve hex digits from hex fields

Some fields are followed by a comma or a closing parenthesis and we
take them because we read everything that's not a space. Better be
stricter, we're causing warnings about incorrect hex format when
they're passed to printf.

2 years agoDEV: flags: add missing stream flags to show-sess-to-flags
Willy Tarreau [Wed, 10 May 2023 15:18:15 +0000 (17:18 +0200)] 
DEV: flags: add missing stream flags to show-sess-to-flags

I managed to miss strm.flg which appears at the top, in part because
there was no "stream" context. Let's create one and decode the flags.

2 years agoMEDIUM: stream: Resync analyzers at the end of process_stream() on change
Christopher Faulet [Wed, 10 May 2023 14:40:27 +0000 (16:40 +0200)] 
MEDIUM: stream: Resync analyzers at the end of process_stream() on change

At the end of process_stream(), if there was any change on request/response
analyzers, we now trigger a resync. It is performed if any analyzer is added
but also removed. It should help to catch internal changes on a stream and
eventually avoid it to be frozen.

There is no reason to backport this patch. But it may be good to keep an eye
on it, just in case.

2 years agoBUG/MEDIUM: stream: Forward shutdowns when unhandled errors are caught
Christopher Faulet [Wed, 10 May 2023 14:28:38 +0000 (16:28 +0200)] 
BUG/MEDIUM: stream: Forward shutdowns when unhandled errors are caught

In process_stream(), after request and response analyzers evaluation,
unhandled errors are processed, if any. In this case, depending on the case,
remaining request or response analyzers may be removed, unlesse the last one
about end of filters. However, auto-close is not reenabled in same
time. Thus it is possible to not forward the shutdown for a side to the
other one while no analyzer is there to do so or at least to make evolved
the situation.

In theory, it is thus possible to freeze a stream if no wakeup happens. And
it seems possible because it explain a freeze we've oberseved.

This patch could be backported to every stable versions but only after a
period of observation and if it may match an unexplained bug. It should not
lead to any loop but at worst and eventually to truncated messages.

2 years agoBUG/MINOR: config: make compression work again in defaults section
Willy Tarreau [Wed, 10 May 2023 14:39:00 +0000 (16:39 +0200)] 
BUG/MINOR: config: make compression work again in defaults section

When commit ead43fe4f ("MEDIUM: compression: Make it so we can compress
requests as well.") added the test for the direction flags to select the
compression, it implicitly broke compression defined in defaults sections
because the flags from the default proxy were not recopied, hence the
compression was enabled but in no direction.

No backport is needed, that's 2.8 only.

2 years agoBUG/MINOR: quic: Possible crash when dumping version information
Frédéric Lécaille [Wed, 10 May 2023 11:06:31 +0000 (13:06 +0200)] 
BUG/MINOR: quic: Possible crash when dumping version information

->others member of tp_version_information structure pointed to a buffer in the
TLS stack used to parse the transport parameters. There is no garantee that this
buffer is available until the connection is released.

Do not dump the available versions selected by the client anymore, but displayed the
chosen one (selected by the client for this connection) and the negotiated one.

Must be backported to 2.7 and 2.6.

2 years agoDEV: flags: add a script to decode most flags in the "show sess all" output
Willy Tarreau [Tue, 9 May 2023 18:17:18 +0000 (20:17 +0200)] 
DEV: flags: add a script to decode most flags in the "show sess all" output

This ugly script decodes most flags in the "show sess all" output and
summarizes them after each stream in an aligned format that makes it
relatively easy to spot the ones of interest. It relies on "flags", and
if not found in various places, will replace its output with a copy-
pastable command that will produce it. h3/quic are not covered yet.

In order to compact the output format, the front and back stream conns
and connections are noted "f.sc", "f.co", "f.h1s", "b.co" etc. That's
sufficiently understandable and entries are grouped by context anyway.

Example of output:

0x7f51a43f7e30: [09/May/2023:20:28:57.183945] id=53704 proto=tcpv4 source=xx.xx.xx.xx:xxxx
  flags=0x100c4a, conn_retries=0, conn_exp=<NEVER> conn_et=0x000 srv_conn=0x464e4e0, pend_pos=(nil) waiting=0 epoch=0xa2
  frontend=public (id=2 mode=http), listener=SSL (id=4) addr=xx.xx.xx.xx:443
  backend=static (id=7 mode=http) addr=xx.xx.xx.xx:50916
  server=srv1 (id=1) addr=xx.xx.xx.xx:80
  task=0x7f51a42190a0 (state=0x00 nice=0 calls=2 rate=0 exp=59s tid=1(1/1) age=0s)
  txn=0x7f51a4397300 flags=0x43000 meth=1 status=200 req.st=MSG_DONE rsp.st=MSG_DATA req.f=0x4c rsp.f=0x0d
  scf=0x57af8b0 flags=0x00000482 state=EST endp=CONN,0x7f51a4269fa0,0x04005001 sub=3 rex=59s wex=59s
      h2s=0x7f51a4269fa0 h2s.id=1 .st=HCR .flg=0x207001 .rxbuf=0@(nil)+0/0
      .sc=0x57af8b0(.flg=0x00000482 .app=0x7f51a43f7e30) .sd=0x5832eb0(.flg=0x04005001)
      .subs=0x57af8c8(ev=3 tl=0x7f51a40dd390 tl.calls=4 tl.ctx=0x57af8b0 tl.fct=sc_conn_io_cb)
      h2c=0x7f51a44144d0 h2c.st0=FRH .err=0 .maxid=1 .lastid=-1 .flg=0x0200 .nbst=1 .nbsc=1
      .fctl_cnt=0 .send_cnt=1 .tree_cnt=1 .orph_cnt=0 .sub=3 .dsi=0 .dbuf=0@(nil)+0/0
      .mbuf=[3..4|32],h=[32730@0x57ec920+16431/32768],t=[32730@0x7f51a4322660+16431/32768] .task=0x5722d40 .exp=<NEVER>
      co0=0x5727120 ctrl=tcpv4 xprt=SSL mux=H2 data=STRM target=LISTENER:0x1cc62d0
      flags=0x80000300 fd=30 fd.state=411 updt=0 fd.tmask=0x2
  scb=0x7f51a4064710 flags=0x00001211 state=EST endp=CONN,0x7f51a433eb50,0x011c0001 sub=0 rex=59s wex=<NEVER>
      h1s=0x7f51a433eb50 h1s.flg=0x4094 .sd.flg=0x11c0001 .req.state=MSG_DONE .res.state=MSG_DATA
      .meth=GET status=200 .sd.flg=0x011c0001 .sc.flg=0x00001211 .sc.app=0x7f51a43f7e30 .subs=(nil)
      h1c=0x7f51a4218b70 h1c.flg=0x80000020 .sub=0 .ibuf=32704@0x57d48c0+56/32768 .obuf=0@(nil)+0/0 .task=0x7f51a408ebb0 .exp=<NEVER>
      co1=0x57264e0 ctrl=tcpv4 xprt=RAW mux=H1 data=STRM target=SERVER:0x464e4e0
      flags=0x00000300 fd=26 fd.state=10122 updt=0 fd.tmask=0x2
  req=0x7f51a43f7e50 (f=0x21840000 an=0x48000 pipe=0 tofwd=0 total=142)
      an_exp=<NEVER> buf=0x7f51a43f7e58 data=(nil) o=0 p=0 i=0 size=0
      htx=0x818e40 flags=0x0 size=0 data=0 used=0 wrap=NO extra=0
  res=0x7f51a43f7ea0 (f=0xa0040101 an=0x24000000 pipe=0 tofwd=-1 total=163472)
      an_exp=<NEVER> buf=0x7f51a43f7ea8 data=0x7f51a43c2f50 o=16328 p=16328 i=16440 size=32768
      htx=0x7f51a43c2f50 flags=0x0 size=32720 data=16328 used=1 wrap=NO extra=3852188
  -----------------------------------
  task.state            0  0
  txn.meth              1  GET
  txn.flg         0x43000  TX_NOT_FIRST TX_CACHE_COOK TX_CACHEABLE
  txn.req.flg        0x4c  HTTP_MSGF_BODYLESS HTTP_MSGF_VER_11 HTTP_MSGF_XFER_LEN
  txn.rsp.flg         0xd  HTTP_MSGF_VER_11 HTTP_MSGF_XFER_LEN HTTP_MSGF_CNT_LEN
  f.sc.flg          0x482  SC_FL_RCV_ONCE SC_FL_WONT_READ SC_FL_EOI
  f.sc.sd.flg   0x4005001  SE_FL_HAVE_NO_DATA SE_FL_EOI SE_FL_NOT_FIRST SE_FL_T_MUX
  f.h2s.flg      0x207001  H2_SF_MORE_HTX_DATA H2_SF_HEADERS_RCVD H2_SF_OUTGOING_DATA H2_SF_HEADERS_SENT H2_SF_ES_RCVD
  f.h2s.sd.flg  0x4005001  SE_FL_HAVE_NO_DATA SE_FL_EOI SE_FL_NOT_FIRST SE_FL_T_MUX
  f.h2c.flg         0x200  H2_CF_DEM_SHORT_READ
  f.co.flg     0x80000300  CO_FL_XPRT_TRACKED CO_FL_XPRT_READY CO_FL_CTRL_READY
  f.co.fd.st        0x19b  FD_POLL_IN FD_EV_ERR_RW FD_EV_READY_R FD_EV_ACTIVE_W FD_EV_ACTIVE_R 0x8
  b.sc.flg         0x1211  SC_FL_SND_NEVERWAIT SC_FL_NEED_ROOM SC_FL_NOHALF SC_FL_ISBACK
  b.sc.sd.flg   0x11c0001  SE_FL_WAIT_DATA SE_FL_WANT_ROOM SE_FL_RCV_MORE SE_FL_MAY_SPLICE SE_FL_T_MUX
  b.h1s.sd.flg  0x11c0001  SE_FL_WAIT_DATA SE_FL_WANT_ROOM SE_FL_RCV_MORE SE_FL_MAY_SPLICE SE_FL_T_MUX
  b.h1s.flg        0x4094  H1S_F_HAVE_O_CONN H1S_F_NOT_FIRST H1S_F_WANT_KAL H1S_F_RX_CONGESTED
  b.h1c.flg    0x80000020  H1C_F_IS_BACK H1C_F_IN_FULL
  b.co.flg          0x300  CO_FL_XPRT_READY CO_FL_CTRL_READY
  b.co.fd.st       0x278a  FD_POLL_OUT FD_POLL_PRI FD_POLL_IN FD_EV_ERR_RW FD_EV_READY_R 0x2008
  req.flg      0x21840000  CF_FLT_ANALYZE CF_DONT_READ CF_AUTO_CONNECT CF_WROTE_DATA
  req.ana         0x48000  AN_REQ_FLT_END AN_REQ_HTTP_XFER_BODY
  req.htx.flg           0  0
  res.flg      0xa0040101  CF_ISRESP CF_FLT_ANALYZE CF_WROTE_DATA CF_WRITE_EVENT CF_READ_EVENT
  res.ana      0x24000000  AN_RES_FLT_END AN_RES_HTTP_XFER_BODY
  res.htx.flg           0  0
  -----------------------------------

2 years agoBUG/MEDIUM: mux-quic: wakeup tasklet to close on error
Amaury Denoyelle [Tue, 9 May 2023 16:20:45 +0000 (18:20 +0200)] 
BUG/MEDIUM: mux-quic: wakeup tasklet to close on error

A recent series of commit have been introduced to rework error
generation on QUIC MUX side. Now, all MUX/APP functions uses
qcc_set_error() to set the flag QC_CF_ERRL on error. Then, this flag is
converted to QC_CF_ERRL_DONE with a CONNECTION_CLOSE emission by
qc_send().

This has the advantage of centralizing the CONNECTION_CLOSE generation
in one place and reduces the link between MUX and quic-conn layer.
However, we must now ensure that every qcc_set_error() call is followed
by a QUIC MUX tasklet to invoke qc_send(). This was not the case, thus
when there is no active transfer, no CONNECTION_CLOSE frame is emitted
and the connection remains opened.

To fix this, add a tasklet_wakeup() directly in qcc_set_error(). This is
a brute force solution as this may be unneeded when already in the MUX
tasklet context. However, it is the simplest solution as it is too
tedious for the moment to list all qcc_set_error() invocation outside of
the tasklet.

This must be backported up to 2.7.

2 years agoBUG/MINOR: mux-quic: fix transport VS app CONNECTION_CLOSE
Amaury Denoyelle [Tue, 9 May 2023 16:01:09 +0000 (18:01 +0200)] 
BUG/MINOR: mux-quic: fix transport VS app CONNECTION_CLOSE

A recent series of patch were introduced to streamline error generation
by QUIC MUX. However, a regression was introduced : every error
generated by the MUX was built as CONNECTION_CLOSE_APP frame, whereas it
should be only for H3/QPACK errors.

Fix this by adding an argument <app> in qcc_set_error. When false, a
standard CONNECTION_CLOSE is used as error.

This bug was detected by QUIC tracker with the following tests
"stop_sending" and "server_flow_control" which requires a
CONNECTION_CLOSE frame.

This must be backported up to 2.7.

2 years agoDOC: configuration: add info about ssl-engine for 2.6
Aleksandar Lazic [Wed, 27 Jul 2022 13:24:54 +0000 (15:24 +0200)] 
DOC: configuration: add info about ssl-engine for 2.6

In the announcement of 2.6 is mentioned that the openssl engine
is not enabled by default.

This patch add the information to the configuration.txt.

This is related to GitHub Issue #1752.

Should be back ported to 2.6

2 years agoBUG/MEDIUM: stats: Require more room if buffer is almost full
Christopher Faulet [Tue, 9 May 2023 14:31:01 +0000 (16:31 +0200)] 
BUG/MEDIUM: stats: Require more room if buffer is almost full

This was lost with commit f4258bdf3 ("MINOR: stats: Use the applet API to
write data"). When the buffer is almost full, the stats applet gives up.
When this happens, the applet must require more room. Otherwise, data in the
channel buffer are sent to the client but the applet is not woken up in
return.

It is a 2.8-specific bug, no backport needed.

2 years agoDOC: stconn: Update comments about ABRT/SHUT for stconn structure
Christopher Faulet [Tue, 9 May 2023 11:57:25 +0000 (13:57 +0200)] 
DOC: stconn: Update comments about ABRT/SHUT for stconn structure

The comment for the stconn structure was still referencing the SHUTR/SHUTW
flags. These flags were replaced and we now use ABRT/SHUT flags in
comments. The comment itself was slightly updated to be accurate.

2 years agoBUILD: ssl: buggy -Werror=dangling-pointer since gcc 13.0
William Lallemand [Tue, 9 May 2023 12:15:57 +0000 (14:15 +0200)] 
BUILD: ssl: buggy -Werror=dangling-pointer since gcc 13.0

GCC complains about swapping 2 heads list, one local and one global.

    gcc -Iinclude  -O2 -g -Wall -Wextra -Wundef -Wdeclaration-after-statement -Wfatal-errors -Wtype-limits -Wshift-negative-value -Wshift-overflow=2 -Wduplicated-cond -Wnull-dereference -fwrapv -Wno-address-of-packed-member -Wno-unused-label -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered -Wno-missing-field-initializers -Wno-cast-function-type -Wno-string-plus-int -Wno-atomic-alignment -Werror     -DDEBUG_STRICT -DDEBUG_MEMORY_POOLS -DUSE_EPOLL  -DUSE_NETFILTER -DUSE_POLL -DUSE_THREAD  -DUSE_BACKTRACE -DUSE_TPROXY -DUSE_LINUX_TPROXY -DUSE_LINUX_SPLICE -DUSE_LIBCRYPT -DUSE_CRYPT_H  -DUSE_GETADDRINFO -DUSE_OPENSSL  -DUSE_SSL -DUSE_LUA -DUSE_ACCEPT4  -DUSE_ZLIB  -DUSE_CPU_AFFINITY -DUSE_TFO -DUSE_NS -DUSE_DL -DUSE_RT  -DUSE_MATH    -DUSE_SYSTEMD  -DUSE_PRCTL  -DUSE_THREAD_DUMP   -DUSE_QUIC   -DUSE_SHM_OPEN   -DUSE_PCRE -DUSE_PCRE_JIT   -I/github/home/opt/include -I/usr/include  -DCONFIG_HAPROXY_VERSION=\"2.8-dev8-7d23e8d1a6db\" -DCONFIG_HAPROXY_DATE=\"2023/04/24\" -c -o src/ssl_sample.o src/ssl_sample.c
    In file included from include/haproxy/pool.h:29,
                     from include/haproxy/chunk.h:31,
                     from include/haproxy/dynbuf.h:33,
                     from include/haproxy/channel.h:27,
                     from include/haproxy/applet.h:29,
                     from src/ssl_sock.c:47:
    src/ssl_sock.c: In function 'tlskeys_finalize_config':
    include/haproxy/list.h:48:88: error: storing the address of local variable 'tkr' in 'tlskeys_reference.p' [-Werror=dangling-pointer=]
       48 | #define LIST_INSERT(lh, el) ({ (el)->n = (lh)->n; (el)->n->p = (lh)->n = (el); (el)->p = (lh); (el); })
          |                                                                                ~~~~~~~~^~~~~~
    src/ssl_sock.c:1086:9: note: in expansion of macro 'LIST_INSERT'
     1086 |         LIST_INSERT(&tkr, &tlskeys_reference);
          |         ^~~~~~~~~~~
    compilation terminated due to -Wfatal-errors.

This appears with gcc 13.0.

The fix uses LIST_SPLICE() instead of inserting the head of the local
list in the global list.

Should fix issue #2136 .

2 years agoEXAMPLES: fix IPV6 support for lua mailers script
Aurelien DARRAGON [Tue, 9 May 2023 07:25:25 +0000 (09:25 +0200)] 
EXAMPLES: fix IPV6 support for lua mailers script

While this used to work fine with legacy mailers, IPV6 server support
for lua mailers script was overlooked so it is currently broken.

Indeed, within the lua script, server address was parsed as an IPV4
address to extract both ip and port and pass them to smtp_send_email()
function from Thierry FOURNIER.

From lua point of view: when fetching server address from
ProxyMailers.mailservers, server ip and port are not separated. Each
server address is represented using haproxy server address custom-format
(the one used to specify server addresses within haproxy config,
see 11. Address formats in haproxy configuration manual):

It is a string that contains both proto hint, ip and port.
(Such addresses are manipulated using str2sa_range() and sa2str()
in haproxy's code)

Parsing these custom-format addresses from lua to support multiple address
families is feasible since the format is properly documented in haproxy
configuration.

However, to keep things simple, and given that smtp_send_email() relies
on Socket.connect() function to set-up the tcp connection:

Socket.connect() already supports the full server address custom-format
when no explicit port argument is provided. Thus with minor code changes
we're able to pass the server string as it is.

With this, IPV6 smtp servers from mailers section are now automatically
supported when using lua mailers script.

2 years agoMEDIUM: stconn: Be sure to always be able to unblock a SC that needs room
Christopher Faulet [Tue, 9 May 2023 09:44:56 +0000 (11:44 +0200)] 
MEDIUM: stconn: Be sure to always be able to unblock a SC that needs room

When sc_need_room() is called, the caller cannot request more free space
than a minimum value to be sure it is always possible to unblock it. it is a
safety guard to not freeze any SC on NEED_ROOM condition. At worse it will
lead to some wakeups un excess at the edge.

To keep things simple, the following minimum is used:

  (global.tune.bufsize - global.tune.maxrewrite - sizeof(struct htx))

2 years agoBUG/MEDIUM: cache: Don't request more room than the max allowed
Christopher Faulet [Tue, 9 May 2023 09:31:24 +0000 (11:31 +0200)] 
BUG/MEDIUM: cache: Don't request more room than the max allowed

Since a recent change on the SC API, a producer must specify the amount of
free space it needs to progress when it is blocked. But, it must take care
to never exceed the maximum size allowed in the buffer. Otherwise, the
stream is freezed because it cannot reach the condition to unblock the
producer.

In this context, there is a bug in the cache applet when it fails to dump a
message. It may request more space than allowed. It happens when the cached
object is too big.

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

2 years agoBUG/MINOR: quic: Wrong key update cipher context initialization for encryption
Frédéric Lécaille [Tue, 2 May 2023 18:03:19 +0000 (20:03 +0200)] 
BUG/MINOR: quic: Wrong key update cipher context initialization for encryption

As noticed by Miroslav, there was a typo in quic_tls_key_update() which lead
a cipher context for decryption to be initialized and used in place of a cipher
context for encryption. Surprisingly, this did not prevent the key update
from working. Perhaps this is due to the fact that the underlying cryptographic
algorithms used by QUIC are all symetric algorithms.

Also modify incorrect traces.

Must be backported in 2.6 and 2.7.

2 years agoCLEANUP: quic: Typo fix for quic_connection_id pool
Frédéric Lécaille [Mon, 24 Apr 2023 16:20:44 +0000 (18:20 +0200)] 
CLEANUP: quic: Typo fix for quic_connection_id pool

Remove a "n" extra letter.

Should be backported to 2.7.

2 years agoCLEANUP: quic: Rename several <buf> variables in quic_frame.(c|h)
Frédéric Lécaille [Mon, 24 Apr 2023 15:45:01 +0000 (17:45 +0200)] 
CLEANUP: quic: Rename several <buf> variables in quic_frame.(c|h)

Most of the function in quic_frame.c and quic_frame.h manipulate <buf> buffer
position variables which have nothing to see with struct buffer variables.
Rename them to <pos>

Should be backported to 2.7.

2 years agoCLEANUP: quic: No more used q_buf structure
Frédéric Lécaille [Mon, 24 Apr 2023 14:25:29 +0000 (16:25 +0200)] 
CLEANUP: quic: No more used q_buf structure

This definition is no more used.

Should be backported to 2.7.

2 years agoCI: more granular failure on generating build matrix
Ilya Shipitsin [Wed, 26 Apr 2023 18:39:39 +0000 (20:39 +0200)] 
CI: more granular failure on generating build matrix

when some api endpoints used for determine latest OpenSSL, LibreSSL
are unavailable, fail only those builds, not entire matrix

2 years agoBUILD: quic: fix build warning when threads are disabled
Willy Tarreau [Sun, 7 May 2023 13:06:22 +0000 (15:06 +0200)] 
BUILD: quic: fix build warning when threads are disabled

Commit e83f937cc ("MEDIUM: quic: use a global CID trees list") uses a
local variable "tree" used only for locks, but when threads are disabled
it spews a warning about this unused variable.

2 years agoBUILD: debug: do not check the isolated_thread variable in non-threaded builds
Willy Tarreau [Sun, 7 May 2023 13:02:30 +0000 (15:02 +0200)] 
BUILD: debug: do not check the isolated_thread variable in non-threaded builds

The build without thread support was broken by commit b30ced3d8 ("BUG/MINOR:
debug: fix incorrect profiling status reporting in show threads") because
it accesses the isolated_thread variable that is not defined when threads
are disabled. In fact both the test on harmless and this one make no sense
without threads, so let's comment out the block and mark the related
variables as unused.

This may have to be backported to 2.7 if the commit above is.

2 years ago[RELEASE] Released version 2.8-dev10 v2.8-dev10
Willy Tarreau [Sun, 7 May 2023 05:31:54 +0000 (07:31 +0200)] 
[RELEASE] Released version 2.8-dev10

Released version 2.8-dev10 with the following main changes :
    - BUG/MINOR: stats: fix typo in `TotalSplicedBytesOut` field name
    - REGTESTS: add success test, "set server" via fqdn
    - MINOR: ssl: disable CRL checks with WolfSSL when no CRL file
    - BUG/MINOR: stream/cli: fix stream age calculation in "show sess"
    - MINOR: debug: clarify "debug dev stream" help message
    - DEBUG: cli: add "debug dev task" to show/wake/expire/kill tasks and tasklets
    - BUG/MINOR: ssl/sample: x509_v_err_str converter output when not found
    - REGTESTS: ssl: simplify X509_V code check in ssl_client_auth.vtc
    - BUILD: cli: fix build on Windows due to isalnum() implemented as a macro
    - MINOR: activity: use a single macro to iterate over all fields
    - MINOR: activity: show the line header inside the SHOW_VAL macro
    - MINOR: activity: iterate over all fields in a main loop for dumping
    - MINOR: activity: allow "show activity" to restart dumping on any line
    - MINOR: activity: allow "show activity" to restart in the middle of a line
    - DEV: haring: automatically disable DEBUG_STRICT
    - DEV: haring: update readme to suggest using the same build options for haring
    - BUG/MINOR: debug: fix incorrect profiling status reporting in show threads
    - MINOR: debug: permit the "debug dev loop" to run under isolation
    - BUG/MEDIUM: mux-h2: Properly handle end of request to expect data from server
    - BUG/MINOR: mux-quic: prevent quic_conn error code to be overwritten
    - MINOR: mux-quic: add trace event for local error
    - MINOR: mux-quic: wake up after recv only if avail data
    - MINOR: mux-quic: adjust local error API
    - MINOR: mux-quic: report local error on stream endpoint asap
    - MINOR: mux-quic: close connection asap on local error
    - BUG/MINOR: debug: do not emit empty lines in thread dumps
    - BUG/MINOR: mux-h2: Also expect data when waiting for a tunnel establishment
    - BUG/MINOR: time: fix NS_TO_TV macro
    - MEDIUM: debug: simplify the thread dump mechanism
    - MINOR: debug: write panic dump to stderr one thread at a time
    - MINOR: debug: make "show threads" properly iterate over all threads
    - CLEANUP: debug: remove the now unused ha_thread_dump_all_to_trash()
    - MINOR: ssl: allow to change the server signature algorithm
    - MINOR: ssl: allow to change the signature algorithm for client authentication
    - MINOR: cli: Use applet API to write output message
    - MINOR: stats: Use the applet API to write data
    - MINOR: peers: Use the applet API to send message
    - MINOR: stconn: Add a field to specify the room needed by the SC to progress
    - MEDIUM: tree-wide: Change sc API to specify required free space to progress
    - BUG/MEDIUM: stconn: Unblock SC from stream if there is enough room to progrees
    - MEDIUM: applet: Check room needed to unblock opposite SC when data was consumed
    - MEDIUM: stconn: Check room needed to unblock SC on fast-forward
    - MEDIUM: stconn: Check room needed to unblock opposite SC when data was sent
    - MINOR: hlua_fcn: fix Server.is_draining() return type
    - MINOR: hlua_fcn: add Server.is_backup()
    - MINOR: hlua_fcn: add Server.is_dynamic()
    - MINOR: hlua_fcn: add Server.tracking()
    - MINOR: hlua_fcn: add Server.get_trackers()
    - MINOR: hlua_fcn: add Server.get_proxy()
    - MINOR: hlua_fcn: add Server.get_pend_conn() and Server.get_cur_sess()
    - MINOR: hlua_fcn: add Proxy.get_srv_act() and Proxy.get_srv_bck()
    - DOC: lua/event: add ServerEvent class header
    - MINOR: server/event_hdl: publish macro helper
    - MINOR: server/event_hdl: add SERVER_STATE event
    - OPTIM: server: publish UP/DOWN events from STATE change
    - MINOR: hlua: expose SERVER_STATE event
    - MINOR: server/event_hdl: add SERVER_ADMIN event
    - MINOR: hlua: expose SERVER_ADMIN event
    - MINOR: checks/event_hdl: SERVER_CHECK event
    - MINOR: hlua/event_hdl: expose SERVER_CHECK event
    - MINOR: mailers/hlua: disable email sending from lua
    - MINOR: hlua: expose proxy mailers
    - EXAMPLES: add lua mailers script to replace tcpcheck mailers
    - BUG/MINOR: hlua: spinning loop in hlua_socket_handler()
    - MINOR: server: fix message report when IDRAIN is set and MAINT is cleared
    - CLEANUP: hlua: hlua_register_task() may longjmp
    - REGTESTS: use lua mailer script for mailers tests
    - MINOR: hlua: declare hlua_{ref,pushref,unref} functions
    - MINOR: hlua: declare hlua_gethlua() function
    - MINOR: hlua: declare hlua_yieldk() function
    - MINOR: hlua_fcn: add Queue class
    - EXAMPLES: mailqueue for lua mailers script
    - MINOR: quic: add format argument for "show quic"
    - MINOR: quic: implement oneline format for "show quic"
    - MINOR: config: allow cpu-map to take commas in lists of ranges
    - CLEANUP: fix a few reported typos in code comments
    - DOC: fix a few reported typos in the config and install doc

2 years agoDOC: fix a few reported typos in the config and install doc
Willy Tarreau [Sun, 7 May 2023 05:10:55 +0000 (07:10 +0200)] 
DOC: fix a few reported typos in the config and install doc

These are only the few relevant changes among those reported here:

  https://github.com/haproxy/haproxy/actions/runs/4856148287/jobs/8655397661

2 years agoCLEANUP: fix a few reported typos in code comments
Willy Tarreau [Sun, 7 May 2023 05:07:44 +0000 (07:07 +0200)] 
CLEANUP: fix a few reported typos in code comments

These are only the few relevant changes among those reported here:

  https://github.com/haproxy/haproxy/actions/runs/4856148287/jobs/8655397661

2 years agoMINOR: config: allow cpu-map to take commas in lists of ranges
Willy Tarreau [Fri, 5 May 2023 14:10:05 +0000 (16:10 +0200)] 
MINOR: config: allow cpu-map to take commas in lists of ranges

The function that cpu-map uses to parse CPU sets, parse_cpu_set(), was
etended in 2.4 with commit a80823543 ("MINOR: cfgparse: support the
comma separator on parse_cpu_set") to support commas between ranges.
But since it was quite late in the development cycle, by then it was
decided not to add a last-minute surprise and not to magically support
commas in cpu-map, hence the "comma_allowed" argument.

Since then we know that it was not the best choice, because the comma
is silently ignored in the cpu-map syntax, causing all sorts of
surprises in field with threads running on a single node for example.
In addition it's quite common to copy-paste a taskset line and put it
directly into the haproxy configuration.

This commit relaxes this rule an finally allows cpu-map to support
commas between ranges. It simply consists in removing the comma_allowed
argument in the parse_cpu_set() function. The doc was updated to
reflect this.

2 years agoMINOR: quic: implement oneline format for "show quic"
Amaury Denoyelle [Fri, 5 May 2023 14:08:34 +0000 (16:08 +0200)] 
MINOR: quic: implement oneline format for "show quic"

Add a new output format "oneline" for "show quic" command. This prints
one connection per line with minimal information. The objective is to
have an equivalent of the netstat/ss tools with just enough information
to quickly find connection which are misbehaving.

A legend is printed on the first line to describe the field columns
starting with a dash character.

This should be backported up to 2.7.

2 years agoMINOR: quic: add format argument for "show quic"
Amaury Denoyelle [Fri, 5 May 2023 14:07:58 +0000 (16:07 +0200)] 
MINOR: quic: add format argument for "show quic"

Add an extra optional argument for "show quic" to specify desired output
format. Its objective is to control the verbosity per connections. For
the moment, only "full" is supported, which is the already implemented
output with maximum information.

This should be backported up to 2.7.

2 years agoEXAMPLES: mailqueue for lua mailers script
Aurelien DARRAGON [Wed, 3 May 2023 17:12:53 +0000 (19:12 +0200)] 
EXAMPLES: mailqueue for lua mailers script

Lua mailers scripts now leverages Queue class to implement a mailqueue.

Thanks to the mailqueue, emails are still sent asynchronously, but with
respect to their generation order (better ordering consistency).

That is, previous script limitation (see below) is no longer true:
"
 Current known script limitation: if multiple events are generated
 simultaneously it is possible that emails could be received out of
 order since emails are sent asynchronously using smtp_send_email()
 and there is no sending queue. Relying on the email "date" should
 help to know which email was generated first..
"

For a given server, email-alerts will be sent in the same order as the
events were generated. However this does not apply to events between 2
distinct servers, since each server is tracked independently within
the lua script. (1 subscription per server, to make sure only relevant
servers x events are being tracked and prevent useless wakeups)

2 years agoMINOR: hlua_fcn: add Queue class
Aurelien DARRAGON [Wed, 3 May 2023 15:03:09 +0000 (17:03 +0200)] 
MINOR: hlua_fcn: add Queue class

Adding a new lua class: Queue.

This class provides a generic FIFO storage mechanism that may be shared
between multiple lua contexts to easily pass data between them, as stock
Lua doesn't provide easy methods for passing data between multiple
coroutines.

New Queue object may be obtained using core.queue()
(it works like core.concat() for a concat Class)

Lua documentation was updated (including some usage examples)

2 years agoMINOR: hlua: declare hlua_yieldk() function
Aurelien DARRAGON [Thu, 4 May 2023 12:01:17 +0000 (14:01 +0200)] 
MINOR: hlua: declare hlua_yieldk() function

Declaring hlua_yieldk() function to make it usable from hlua_fcn.c.

2 years agoMINOR: hlua: declare hlua_gethlua() function
Aurelien DARRAGON [Thu, 4 May 2023 11:59:48 +0000 (13:59 +0200)] 
MINOR: hlua: declare hlua_gethlua() function

Declaring hlua_gethlua() function to make it usable from hlua_fcn.c.

2 years agoMINOR: hlua: declare hlua_{ref,pushref,unref} functions
Aurelien DARRAGON [Wed, 3 May 2023 15:43:02 +0000 (17:43 +0200)] 
MINOR: hlua: declare hlua_{ref,pushref,unref} functions

Declaring hlua_{ref,pushref,unref} functions to make them usable from
hlua_fcn.c to simplify reference handling.

2 years agoREGTESTS: use lua mailer script for mailers tests
Aurelien DARRAGON [Wed, 3 May 2023 14:55:52 +0000 (16:55 +0200)] 
REGTESTS: use lua mailer script for mailers tests

Since mailers/healthcheckmail.vtc already requires lua to emulate the
SMTP server for the test, force it to use lua mailers example script
to send email-alerts so we don't rely anymore on legacy tcpcheck
mailers implementation.

This is done by simply loading examples/mailers.lua (as a symlink) from
haproxy config file.

2 years agoCLEANUP: hlua: hlua_register_task() may longjmp
Aurelien DARRAGON [Fri, 21 Apr 2023 15:38:37 +0000 (17:38 +0200)] 
CLEANUP: hlua: hlua_register_task() may longjmp

Adding __LJMP prefix to hlua_register_task() to indicate that the
function may longjmp when executed.

2 years agoMINOR: server: fix message report when IDRAIN is set and MAINT is cleared
Aurelien DARRAGON [Wed, 3 May 2023 08:36:54 +0000 (10:36 +0200)] 
MINOR: server: fix message report when IDRAIN is set and MAINT is cleared

Remaining in drain mode after removing one of server admins flags leads
to this message being generated:

"Server name/backend is leaving forced drain but remains in drain mode."

However this is not necessarily true: the server might just be leaving
MAINT with the IDRAIN flag set, so the report is incorrect in this case.
(FDRAIN was not set so it cannot be cleared)

To prevent confusion around this message and to comply with the code
comment above it: we remove the "leaving forced drain" precision to
make the report suitable for multiple transitions.

2 years agoBUG/MINOR: hlua: spinning loop in hlua_socket_handler()
Aurelien DARRAGON [Tue, 2 May 2023 17:10:24 +0000 (19:10 +0200)] 
BUG/MINOR: hlua: spinning loop in hlua_socket_handler()

Since 3157222 ("MEDIUM: hlua/applet: Use the sedesc to report and detect
end of processing"), hlua_socket_handler() might spin loop if the hlua
socket is destroyed and some data was left unconsumed in the applet.

Prior to the above commit, the stream was explicitly KILLED
(when ctx->die == 1) so the app couldn't spinloop on unconsumed data.
But since the refactor this is no longer the case.

To prevent unconsumed data from waking the applet indefinitely, we consume
pending data when either one of EOS|ERROR|SHR|SHW flags are set, as it is
done everywhere else this check is performed in the code. Hence it was
probably overlooked in the first place during the refacto.

This bug is 2.8 specific only, so no backport needed.

2 years agoEXAMPLES: add lua mailers script to replace tcpcheck mailers
Aurelien DARRAGON [Fri, 28 Apr 2023 18:19:23 +0000 (20:19 +0200)] 
EXAMPLES: add lua mailers script to replace tcpcheck mailers

Legacy mailers implemented using tcpchecks may now be replaced using a
pure lua implementation.

Simply loading the file "mailers.lua" using lua-load directive is enough
to disable the legacy mailer implementation and make the lua script
subscribe to server events in order to generate messages and send email
alerts to configured mailservers according to the mailers configuration
specified by the user in the config file.

lua-load-per-thread directive is supported, the script will automatically
force itself on a single thread to prevent multiple mails from being sent
for the same event.

The email sending from lua in itself is handled with smtp_send_email()
function from Thierry FOURNIER.
(see: https://www.arpalert.org/how-to-send-email.html)

The function was slightly adapted to send HELO instead of EHLO when
beginning the SMTP handshake to make it more compatible with basic SMTP
stacks and to comply with the legacy SMTP handshake performed in
mailers.c.

Authentication is not yet handled by smtp_send_email(), but it may be
further improved to do so.

Note that existing lua libraries may also support sending emails (even
with authentication support maybe?), I did not do much researchs about
this, so I'm not aware of existing solutions at the time of writing this
script.

The only restriction is that when using an external library, the library
function calls must not be blocking, since haproxy relies on lua
executions to be yieldable and rescheduled.

As long as the script complies with this limitation, it may be customized
or improved in many ways, including templating, making calls to APIs
services.. (ie: triggering automation flows, sending SMS alerts...
you name it)

The purpose of this script is to provide a basic working replacement for
legacy mailers implementation based on tcpchecks, which is planned for
removal in the future. tcpcheck based mailers is kind of a hack which is
not suitable as a long term solution.
(hard to maintain and not customizable)

Note: Email content for email alerts sent using this script might slightly
differ from the legacy implementation (some optional info might be missing
such as server's check dynamic description, or included statistics such as
currently active servers may appear out of sync) due the email generation
now being performed asynchronously. However the output format complies with
the original one and essential informations are consistently reported.

Current known script limitation: if multiple events are generated
simultaneously it is possible that emails could be received out of
order since emails are sent asynchronously using smtp_send_email()
and there is no sending queue. Relying on the email "date" should
help to know which email was generated first..

2 years agoMINOR: hlua: expose proxy mailers
Aurelien DARRAGON [Wed, 26 Apr 2023 17:02:43 +0000 (19:02 +0200)] 
MINOR: hlua: expose proxy mailers

Proxy mailers, which are configured using "email-alert" directives
in proxy sections from the configuration, are now being exposed
directly in lua thanks to the proxy:get_mailers() method which
returns a class containing the various mailers settings if email
alerts are configured for the given proxy (else nil is returned).

Both the class and the proxy method were marked as LEGACY since this
feature relies on mailers configuration, and the goal here is to provide
the last missing bits of information to lua scripts in order to make
them capable of sending email alerts instead of relying on the soon-to-
be deprecated mailers implementation based on checks (see src/mailers.c)

Lua documentation was updated accordingly.

2 years agoMINOR: mailers/hlua: disable email sending from lua
Aurelien DARRAGON [Fri, 21 Apr 2023 15:32:46 +0000 (17:32 +0200)] 
MINOR: mailers/hlua: disable email sending from lua

Exposing a new hlua function, available from body or init contexts, that
forcefully disables the sending of email alerts even if the mailers are
defined in haproxy configuration.

This will help for sending email directly from lua.
(prevent legacy email sending from intefering with lua)

2 years agoMINOR: hlua/event_hdl: expose SERVER_CHECK event
Aurelien DARRAGON [Thu, 30 Mar 2023 13:53:33 +0000 (15:53 +0200)] 
MINOR: hlua/event_hdl: expose SERVER_CHECK event

Exposing SERVER_CHECK event through the lua API.

New lua class named ServerEventCheck was added to provide additional
data for SERVER_CHECK event.

Lua documentation was updated accordingly.