]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
3 years agoBUG/MEDIUM: conn-stream: Don't reset CS flags on close
Christopher Faulet [Wed, 10 Nov 2021 14:12:47 +0000 (15:12 +0100)] 
BUG/MEDIUM: conn-stream: Don't reset CS flags on close

cs_close() and cs_drain_and_close() are called to close a conn-stream.
cs_shutr() and cs_shutw() are called with the appropriate modes. But the
conn-stream is not released at this stage. However the flags are
reset. Thus, after a cs_close(), we loose shutdown flags. If cs_close() is
performed several times, it is a problem. And indeed, it is possible. On one
hand, the stream-interface may close the conn-stream. On the other end, the
stream always closes it when it is released.

It is a problem for the H1 multiplexer. Because the conn-stream flags are
reset, the shutr and shutw are performed twice. For a delayed shutdown, the
dirty mode is used instead of the normal one because the last call to
h1_shutw() overwrite H1C flags set by the first call. This leads to dirty
shutdowns while normal ones are required. At the end, it is possible to
truncate the messages.

This bug was revealed by the commit a85c522d4 ("BUG/MINOR: mux-h1: Save
shutdown mode if the shutdown is delayed").

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

3 years agoMINOR: mux-h1: Slightly Improve H1 traces
Christopher Faulet [Wed, 10 Nov 2021 09:30:15 +0000 (10:30 +0100)] 
MINOR: mux-h1: Slightly Improve H1 traces

Connection and conn-stream pointers and flags are now dumped, if available,
in each trace messages. In addition, shutr and shutw mode is now reported.

3 years agoDOC: lua: Be explicit with the Reply object limits
Christopher Faulet [Tue, 9 Nov 2021 17:39:51 +0000 (18:39 +0100)] 
DOC: lua: Be explicit with the Reply object limits

In HTTP, when a lua action is evaluated, a reply object can be used to send
a response to the client and interrupt the transaction. This reply object is
converted into HTX and is limited to the response channel buffer. Its size,
once converted, cannot exceed the buffer size. There is no streaming at this
stage. However, this limitation was not documented.

Note that, for now, there is no easy way to know if the reply will fit or
not int the response channel buffer. Thus the reply must be reasonably
small. Otherwise a 500-Internal-Error message is returned.

This patch is related to the issue #1447. It may be backported as far as
2.2.

3 years agoDOC: config: Be more explicit in "allow" actions description
Christopher Faulet [Tue, 9 Nov 2021 16:58:12 +0000 (17:58 +0100)] 
DOC: config: Be more explicit in "allow" actions description

TCP/HTTP allow actions stop rules evaluation of the current section
only. Only the http-response description was accurate on this
point. Thus, the documentation is now explicit on this point for all
other concerned rulesets.

This patch may be backported, to all supported versions for tcp-request
and http-request documentation, and as far as 2.2 for http-after-response
documentation.

3 years agoRevert "BUG/MINOR: http-ana: Don't eval front after-response rules if stopped on...
Christopher Faulet [Tue, 9 Nov 2021 16:48:39 +0000 (17:48 +0100)] 
Revert "BUG/MINOR: http-ana: Don't eval front after-response rules if stopped on back"

This reverts commit 597909f4e67866c4f3ecf77f95f2cd4556c0c638

http-after-response rules evaluation was changed to do the same that was
done for http-response, in the code. However, the opposite must be performed
instead. Only the rules of the current section must be stopped. Thus the
above commit is reverted and the http-response rules evaluation will be
fixed instead.

Note that only "allow" action is concerned. It is most probably an uncommon
action for an http-after-request rule.

This patch must be backported as far as 2.2 if the above commit was
backported.

3 years agoBUG/MINOR: http-ana: Apply stop to the current section for http-response rules
Christopher Faulet [Tue, 9 Nov 2021 15:33:25 +0000 (16:33 +0100)] 
BUG/MINOR: http-ana: Apply stop to the current section for http-response rules

A TCP/HTTP action can stop the rules evaluation. However, it should be
applied on the current section only. For instance, for http-requests rules,
an "allow" on a frontend must stop evaluation of rules defined in this
frontend. But the backend rules, if any, must still be evaluated.

For http-response rulesets, according the configuration manual, the same
must be true. Only "allow" action is concerned. However, since the
beginning, this action stops evaluation of all remaining rules, not only
those of the current section.

This patch may be backported to all supported versions. But it is not so
critical because the bug exists since a while. I doubt it will break any
existing configuration because the current behavior is
counterintuitive.

3 years agoDOC: config: Fix typo in ssl_fc_unique_id description
Christopher Faulet [Tue, 9 Nov 2021 13:23:36 +0000 (14:23 +0100)] 
DOC: config: Fix typo in ssl_fc_unique_id description

In ssl_fc_unique_id decription, threre is a reference to the wrong sample
fetch. ssl_bc_unique_id is used instead of ssl_fc_unique_id.

This patch should fix the issue #1449. It may be backported to all
supportted versions.

3 years agoMINOR: promex: backend aggregated server check status
William Dauchy [Sun, 7 Nov 2021 09:18:47 +0000 (10:18 +0100)] 
MINOR: promex: backend aggregated server check status

- add new metric: `haproxy_backend_agg_server_check_status`
  it counts the number of servers matching a specific check status
  this permits to exclude per server check status as the usage is often
  to rely on the total. Indeed in large setup having thousands of
  servers per backend the memory impact is not neglible to store the per
  server metric.
- realign promex_str_metrics array

quite simple implementation - we could improve it later by adding an
internal state to the prometheus exporter, thus to avoid counting at
every dump.

this patch is an attempt to close github issue #1312. It may bebackported
to 2.4 if requested.

Signed-off-by: William Dauchy <wdauchy@gmail.com>
3 years agoBUG/MEDIUM: httpclient: channel_add_input() must use htx->data
William Lallemand [Mon, 8 Nov 2021 15:55:14 +0000 (16:55 +0100)] 
BUG/MEDIUM: httpclient: channel_add_input() must use htx->data

The httpclient uses channel_add_input() to notify the channel layer that
it must forward some data. This function was used with b_data(&req->buf)
which ask to send the size of a buffer (because of the HTX metadata
which fill the buffer completely).

This is wrong and will have the consequence of trying to send data that
doesn't exist, letting HAProxy looping at 100% CPU.

When using htx channel_add_input() must be used with the size of the htx
payload, and not the size of a buffer.

When sending the request payload it also need to sets the buffer size to
0, which is achieved with a htx_to_buf() when the htx payload is empty.

3 years agoBUG/MINOR: httpclient/lua: rcv freeze when no request payload
William Lallemand [Thu, 4 Nov 2021 08:45:58 +0000 (09:45 +0100)] 
BUG/MINOR: httpclient/lua: rcv freeze when no request payload

This patch fixes the receive part of the lua httpclient when no payload
was sent.

The lua task was not awoken once it jumped into
hlua_httpclient_rcv_yield(), which caused the lua client to freeze.

It works with a payload because the payload push is doing the wakeup.

A change in the state machine of the IO handler is also require to
achieve correctly the change from the REQ state to the RES state, it has
to detect if there is the right EOM flag in the request.

3 years agoDOC: internals: document the IST API
Willy Tarreau [Mon, 8 Nov 2021 15:48:54 +0000 (16:48 +0100)] 
DOC: internals: document the IST API

This one was missing. It should be easier to use now. It is obvious that
some functions are missing, and it looks like ist2str() and istpad() are
exactly the same.

3 years agoDOC: stats: fix location of the text representation
William Dauchy [Sat, 6 Nov 2021 11:30:43 +0000 (12:30 +0100)] 
DOC: stats: fix location of the text representation

`info_field_names` and `stat_field_names` no longer exist and have been
moved in stats.c
To avoid changing this comment, just mention the name of the new table
`info_fields` and `stat_fields`

Signed-off-by: William Dauchy <wdauchy@gmail.com>
3 years agoRevert "DEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_strncat()`"
Willy Tarreau [Mon, 8 Nov 2021 12:42:03 +0000 (13:42 +0100)] 
Revert "DEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_strncat()`"

This reverts commit b9656e48377a9e5359494bce6a413a9915c8f74b. It's
not needed anymore since 49b0482ed ("CLEANUP: chunk: remove misleading
chunk_strncat() function").

3 years agoBUG/MINOR: cache: properly ignore unparsable max-age in quotes
Willy Tarreau [Mon, 8 Nov 2021 11:09:27 +0000 (12:09 +0100)] 
BUG/MINOR: cache: properly ignore unparsable max-age in quotes

When "max-age" or "s-maxage" receive their values in quotes, the pointer
to the integer to be parsed is advanced by one, but the error pointer
check doesn't consider this advanced offset, so it will not match a
parse error such as max-age="a" and will take the value zero instead.

This probably needs to be backported, though it's unsure it has any
effect in the real world.

3 years agoCLEANUP: chunk: remove misleading chunk_strncat() function
Willy Tarreau [Mon, 8 Nov 2021 10:44:47 +0000 (11:44 +0100)] 
CLEANUP: chunk: remove misleading chunk_strncat() function

This function claims to perform an strncat()-like operation but it does
not, it always copies the indicated number of bytes, regardless of the
presence of a NUL character (what is currently done by chunk_memcat()).
Let's remove it and explicitly replace it with chunk_memcat().

3 years agoCLEANUP: chunk: Remove duplicated chunk_Xcat implementation
Tim Duesterhus [Mon, 8 Nov 2021 08:05:05 +0000 (09:05 +0100)] 
CLEANUP: chunk: Remove duplicated chunk_Xcat implementation

Delegate chunk_istcat, chunk_cat and chunk_strncat to the most generic
chunk_memcat.

3 years agoCLEANUP: Apply ist.cocci
Tim Duesterhus [Mon, 8 Nov 2021 08:05:04 +0000 (09:05 +0100)] 
CLEANUP: Apply ist.cocci

This is to make use of `chunk_istcat()`.

3 years agoDEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_strncat()`
Tim Duesterhus [Mon, 8 Nov 2021 08:05:03 +0000 (09:05 +0100)] 
DEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_strncat()`

This replaces `chunk_strncat()` with `chunk_istcat()` if the parameters are the
ist's `.ptr` and `.len`.

3 years agoDEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_memcat()`
Tim Duesterhus [Mon, 8 Nov 2021 08:05:02 +0000 (09:05 +0100)] 
DEV: coccinelle: Add rule to use `chunk_istcat()` instead of `chunk_memcat()`

This replaces `chunk_memcat()` with `chunk_istcat()` if the parameters are the
ist's `.ptr` and `.len`.

3 years agoCLEANUP: Apply ist.cocci
Tim Duesterhus [Mon, 8 Nov 2021 08:05:01 +0000 (09:05 +0100)] 
CLEANUP: Apply ist.cocci

Make use of the new rules to use `isttrim()`.

3 years agoDEV: coccinelle: Add rule to use `isttrim()` where possible
Tim Duesterhus [Mon, 8 Nov 2021 08:05:00 +0000 (09:05 +0100)] 
DEV: coccinelle: Add rule to use `isttrim()` where possible

This replaces `if (i.len > e) i.len = e;` by `isttrim(i, e)`.

3 years agoOPTIM: halog: skip fields 64 bits at a time when supported
Willy Tarreau [Mon, 8 Nov 2021 09:02:52 +0000 (10:02 +0100)] 
OPTIM: halog: skip fields 64 bits at a time when supported

Some architectures like x86_64 and aarch64 support efficient unaligned
64-bit reads. On such architectures, we already know that each string
passed to field_start() has some margin at the end because it's parsed
using fgets2() which looks for the trailing LF using the same method.
Thus let's skip spaces by packs of 8. This increases the parsing speed
by 35%.

3 years agoOPTIM: halog: improve field parser speed for modern compilers
Willy Tarreau [Mon, 8 Nov 2021 08:58:22 +0000 (09:58 +0100)] 
OPTIM: halog: improve field parser speed for modern compilers

Modern compilers were producing producing less efficient code in the
field_start() loop, by not emitting two conditional jumps for a single
test. However by reordering the test we can merge the optimal case and
the default one and get back to good performance so let's simplify the
test. This improves the parsing speed by 5%.

3 years agoCLEANUP: halog: remove unused strl2ui()
Willy Tarreau [Mon, 8 Nov 2021 08:50:29 +0000 (09:50 +0100)] 
CLEANUP: halog: remove unused strl2ui()

strl2ui() isn't used anymore in the code, likely because str2ic() is
often used instead. Let's drop it.

3 years agoMINOR: quic: Fix potential null pointer dereference
Frédéric Lécaille [Mon, 8 Nov 2021 10:23:17 +0000 (11:23 +0100)] 
MINOR: quic: Fix potential null pointer dereference

Fix compilation warnings about non initialized pointers.

This partially address #1445 github issue.

3 years agoMINOR: h3: fix potential NULL dereference
Amaury Denoyelle [Mon, 8 Nov 2021 08:13:42 +0000 (09:13 +0100)] 
MINOR: h3: fix potential NULL dereference

Fix potential allocation failure of HTX start-line during H3 request
decoding. In this case, h3_decode_qcs returns -1 as error code.

This addresses in part github issue #1445.

3 years agoMINOR: mux-quic: fix gcc11 warning
Amaury Denoyelle [Mon, 8 Nov 2021 07:58:26 +0000 (08:58 +0100)] 
MINOR: mux-quic: fix gcc11 warning

Fix minor warnings about an unused variable.

This addresses in part github issue #1445.

3 years agoMINOR: h3/qpack: fix gcc11 warnings
Amaury Denoyelle [Mon, 8 Nov 2021 07:57:18 +0000 (08:57 +0100)] 
MINOR: h3/qpack: fix gcc11 warnings

Fix minor warnings about unused variables and mixed declarations.

This addresses in part github issue #1445.

3 years agoCLEANUP: halog: make the default usage message fit in small screens
Willy Tarreau [Mon, 8 Nov 2021 07:37:40 +0000 (08:37 +0100)] 
CLEANUP: halog: make the default usage message fit in small screens

The usage message was starting to have long lines, it's preferable that
it still fits well into a default 80-col display so that options are
easy to find. Also cut that into the 3 parts (input filter, modifier,
output format) for improved legibility.

3 years agoCLEANUP: Re-apply xalloc_size.cocci
Tim Duesterhus [Sat, 6 Nov 2021 14:14:45 +0000 (15:14 +0100)] 
CLEANUP: Re-apply xalloc_size.cocci

Use a consistent size as the parameter for the *alloc family.

3 years agoCLEANUP: Apply ist.cocci
Tim Duesterhus [Sat, 6 Nov 2021 14:14:44 +0000 (15:14 +0100)] 
CLEANUP: Apply ist.cocci

Make use of the new rules to use `istend()`.

3 years agoDEV: coccinelle: Add rule to use `istend()` where possible
Tim Duesterhus [Sat, 6 Nov 2021 14:14:43 +0000 (15:14 +0100)] 
DEV: coccinelle: Add rule to use `istend()` where possible

This replaces `i.ptr + i.len` by `istend()`.

3 years agoDEV: coccinelle: Remove unused `expression e`
Tim Duesterhus [Sat, 6 Nov 2021 14:14:42 +0000 (15:14 +0100)] 
DEV: coccinelle: Remove unused `expression e`

Introduced in ef00c533e1ed37b414aab912f492be794ab589cc.

3 years ago[RELEASE] Released version 2.5-dev13 v2.5-dev13
Willy Tarreau [Sat, 6 Nov 2021 08:25:57 +0000 (09:25 +0100)] 
[RELEASE] Released version 2.5-dev13

Released version 2.5-dev13 with the following main changes :
    - SCRIPTS: git-show-backports: re-enable file-based filtering
    - MINOR: jwt: Make invalid static JWT algorithms an error in `jwt_verify` converter
    - MINOR: mux-h2: add trace on extended connect usage
    - BUG/MEDIUM: mux-h2: reject upgrade if no RFC8441 support
    - MINOR: stream/mux: implement websocket stream flag
    - MINOR: connection: implement function to update ALPN
    - MINOR: connection: add alternative mux_ops param for conn_install_mux_be
    - MEDIUM: server/backend: implement websocket protocol selection
    - MINOR: server: add ws keyword
    - BUG/MINOR: resolvers: fix sent messages were counted twice
    - BUG/MINOR: resolvers: throw log message if trash not large enough for query
    - MINOR: resolvers/dns: split dns and resolver counters in dns_counter struct
    - MEDIUM: resolvers: rename dns extra counters to resolvers extra counters
    - BUG/MINOR: jwt: Fix jwt_parse_alg incorrectly returning JWS_ALG_NONE
    - DOC: add QUIC instruction in INSTALL
    - CLEANUP: halog: Remove dead stores
    - DEV: coccinelle: Add ha_free.cocci
    - CLEANUP: Apply ha_free.cocci
    - DEV: coccinelle: Add rule to use `istnext()` where possible
    - CLEANUP: Apply ist.cocci
    - REGTESTS: Use `feature cmd` for 2.5+ tests (2)
    - DOC: internals: move some API definitions to an "api" subdirectory
    - MINOR: quic: Allocate listener RX buffers
    - CLEANUP: quic: Remove useless code
    - MINOR: quic: Enhance the listener RX buffering part
    - MINOR: quic: Remove a useless lock for CRYPTO frames
    - MINOR: quic: Use QUIC_LOCK QUIC specific lock label.
    - MINOR: backend: Get client dst address to set the server's one only if needful
    - MINOR: compression: Warn for 'compression offload' in defaults sections
    - MEDIUM: connection: rename fc_conn_err and bc_conn_err to fc_err and bc_err
    - DOC: configuration: move the default log formats to their own section
    - MINOR: ssl: make the ssl_fc_sni() sample-fetch function always available
    - MEDIUM: log: add the client's SNI to the default HTTPS log format
    - DOC: config: add an example of reasonably complete error-log-format
    - DOC: config: move error-log-format before custom log format

3 years agoDOC: config: move error-log-format before custom log format
Willy Tarreau [Sat, 6 Nov 2021 08:18:33 +0000 (09:18 +0100)] 
DOC: config: move error-log-format before custom log format

All default formats were described before the custom one, except this
one. Better place them all together before the custom log format. This
only swaps and renumbers the sections.

3 years agoDOC: config: add an example of reasonably complete error-log-format
Willy Tarreau [Sat, 6 Nov 2021 08:11:14 +0000 (09:11 +0100)] 
DOC: config: add an example of reasonably complete error-log-format

This commit adds a suggestion of a useful error-log-format that was
tested with success in production.

3 years agoMEDIUM: log: add the client's SNI to the default HTTPS log format
Willy Tarreau [Fri, 5 Nov 2021 18:14:55 +0000 (19:14 +0100)] 
MEDIUM: log: add the client's SNI to the default HTTPS log format

During a troublehooting it came obvious that the SNI always ought to
be logged on httpslog, as it explains errors caused by selection of
the default certificate (or failure to do so in case of strict-sni).

This expectation was also confirmed on the mailing list.

Since the field may be empty it appeared important not to leave an
empty string in the current format, so it was decided to place the
field before a '/' preceding the SSL version and ciphers, so that
in the worst case a missing field leads to a field looking like
"/TLSv1.2/AES...", though usually a missing element still results
in a "-" in logs.

This will change the log format for users who already deployed the
2.5-dev versions (hence the medium level) but no released version
was using this format yet so there's no harm for stable deployments.
The reg-test was updated to check for "-" there since we don't send
SNI in reg-tests.

Link: https://www.mail-archive.com/haproxy@formilux.org/msg41410.html
Cc: William Lallemand <wlallemand@haproxy.org>
3 years agoMINOR: ssl: make the ssl_fc_sni() sample-fetch function always available
Willy Tarreau [Fri, 5 Nov 2021 18:12:54 +0000 (19:12 +0100)] 
MINOR: ssl: make the ssl_fc_sni() sample-fetch function always available

Its definition is enclosed inside an ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
which is defined since OpenSSL 0.9.8. Having it conditioned like this
prevents us from using it by default in a log format, which could cause
an error on an old or exotic library.

Let's just always define it and make the sample fetch fail to return
anything on such libs instead.

3 years agoDOC: configuration: move the default log formats to their own section
Willy Tarreau [Fri, 5 Nov 2021 17:09:06 +0000 (18:09 +0100)] 
DOC: configuration: move the default log formats to their own section

I'm always having a very hard time finding the log-format definition of
httplog, because it's not in the httplog description, and looking for
"httplog" doesn't yield the custom log formats section.

It would make more sense to write these log-formats into their respective
sections where they will be easier to find. That's what this commit does.

3 years agoMEDIUM: connection: rename fc_conn_err and bc_conn_err to fc_err and bc_err
Willy Tarreau [Fri, 5 Nov 2021 16:07:03 +0000 (17:07 +0100)] 
MEDIUM: connection: rename fc_conn_err and bc_conn_err to fc_err and bc_err

Commit 3d2093af9 ("MINOR: connection: Add a connection error code sample
fetch") added these convenient sample-fetch functions but it appears that
due to a misunderstanding the redundant "conn" part was kept in their
name, causing confusion, since "fc" already stands for "front connection".

Let's simply call them "fc_err" and "bc_err" to match all other related
ones before they appear in a final release. The VTC they appeared in were
also updated, and the alpha sort in the keywords table updated.

Cc: William Lallemand <wlallemand@haproxy.org>
3 years agoMINOR: compression: Warn for 'compression offload' in defaults sections
Christopher Faulet [Fri, 5 Nov 2021 11:06:14 +0000 (12:06 +0100)] 
MINOR: compression: Warn for 'compression offload' in defaults sections

This directive is documented as being ignored if set in a defaults
section. But it is only mentionned in a small note in the configuration
manual. Thus, now, a warning is emitted. To do so, the errors handling in
parse_compression_options() function was slightly changed.

In addition, this directive is now documented apart from the other
compression directives. This way, it is clearly visible that it must not be
used in a defaults section.

3 years agoMINOR: backend: Get client dst address to set the server's one only if needful
Christopher Faulet [Fri, 5 Nov 2021 11:02:56 +0000 (12:02 +0100)] 
MINOR: backend: Get client dst address to set the server's one only if needful

In alloc_dst_address(), the client destination address must only be
retrieved when we are sure to use it. Most of time, this save a syscall to
getsockname(). It is not a bugfix in itself. But it revealed a bug in the
QUIC part. The CO_FL_ADDR_TO_SET flag is not set when the destination
address is create for anew quic client connection.

3 years agoMINOR: quic: Use QUIC_LOCK QUIC specific lock label.
Frédéric Lécaille [Wed, 3 Nov 2021 18:01:31 +0000 (19:01 +0100)] 
MINOR: quic: Use QUIC_LOCK QUIC specific lock label.

Very minor modifications without any impact.

3 years agoMINOR: quic: Remove a useless lock for CRYPTO frames
Frédéric Lécaille [Wed, 3 Nov 2021 17:39:59 +0000 (18:39 +0100)] 
MINOR: quic: Remove a useless lock for CRYPTO frames

->frms_rwlock is an old lock supposed to be used when several threads
could handle the same connection. This is no more the case since this
commit:
 "MINOR: quic: Attach the QUIC connection to a thread."

3 years agoMINOR: quic: Enhance the listener RX buffering part
Frédéric Lécaille [Tue, 2 Nov 2021 09:14:44 +0000 (10:14 +0100)] 
MINOR: quic: Enhance the listener RX buffering part

Add a buffer per QUIC connection. At this time the listener which receives
the UDP datagram is responsible of identifying the underlying QUIC connection
and must copy the QUIC packets to its buffer.
->pkt_list member has been added to quic_conn struct to enlist the packets
in the order they have been copied to the connection buffer so that to be
able to consume this buffer when the packets are freed. This list is locked
thanks to a R/W lock to protect it from concurent accesses.
quic_rx_packet struct does not use a static buffer anymore to store the QUIC
packets contents.

3 years agoCLEANUP: quic: Remove useless code
Frédéric Lécaille [Wed, 20 Oct 2021 15:24:42 +0000 (17:24 +0200)] 
CLEANUP: quic: Remove useless code

Remove old I/O handler implementation (listener and server).
At this time keep a defined but not used function for servers (qc_srv_pkt_rcv()).

3 years agoMINOR: quic: Allocate listener RX buffers
Frédéric Lécaille [Wed, 20 Oct 2021 09:09:58 +0000 (11:09 +0200)] 
MINOR: quic: Allocate listener RX buffers

At this time we allocate an RX buffer by thread.
Also take the opportunity offered by this patch to rename TX related variable
names to distinguish them from the RX part.

3 years agoDOC: internals: move some API definitions to an "api" subdirectory
Willy Tarreau [Fri, 5 Nov 2021 10:52:10 +0000 (11:52 +0100)] 
DOC: internals: move some API definitions to an "api" subdirectory

It's not always easy to figure that there are some docs on internal API
stuff, let's move them to their own directory. There's a diagram for
lists that could be placed there but instead would deserve a greppable
description for quick lookups, so it was not moved there.

3 years agoREGTESTS: Use `feature cmd` for 2.5+ tests (2)
Tim Duesterhus [Thu, 4 Nov 2021 20:12:14 +0000 (21:12 +0100)] 
REGTESTS: Use `feature cmd` for 2.5+ tests (2)

This patch effectively is identical to 7ba98480cc5b2ede0fd4cca162959f66beb82c82.

3 years agoCLEANUP: Apply ist.cocci
Tim Duesterhus [Thu, 4 Nov 2021 21:35:44 +0000 (22:35 +0100)] 
CLEANUP: Apply ist.cocci

Make use of the new rules to use `istnext()`.

3 years agoDEV: coccinelle: Add rule to use `istnext()` where possible
Tim Duesterhus [Thu, 4 Nov 2021 21:35:43 +0000 (22:35 +0100)] 
DEV: coccinelle: Add rule to use `istnext()` where possible

This matches both `istadv(..., 1)` as well as raw `.ptr++` uses.

3 years agoCLEANUP: Apply ha_free.cocci
Tim Duesterhus [Thu, 4 Nov 2021 20:03:52 +0000 (21:03 +0100)] 
CLEANUP: Apply ha_free.cocci

Use `ha_free()` where possible.

3 years agoDEV: coccinelle: Add ha_free.cocci
Tim Duesterhus [Thu, 4 Nov 2021 20:03:51 +0000 (21:03 +0100)] 
DEV: coccinelle: Add ha_free.cocci

Taken from 61cfdf4fd8a93dc6fd9922d5b309a71bdc7d2853.

3 years agoCLEANUP: halog: Remove dead stores
Tim Duesterhus [Thu, 4 Nov 2021 20:04:24 +0000 (21:04 +0100)] 
CLEANUP: halog: Remove dead stores

Found using clang's scan-build.

3 years agoDOC: add QUIC instruction in INSTALL
Amaury Denoyelle [Wed, 3 Nov 2021 17:14:44 +0000 (18:14 +0100)] 
DOC: add QUIC instruction in INSTALL

Add a new section about QUIC compilation, based on QUICTLS.

3 years agoBUG/MINOR: jwt: Fix jwt_parse_alg incorrectly returning JWS_ALG_NONE
Remi Tricot-Le Breton [Wed, 3 Nov 2021 11:23:54 +0000 (12:23 +0100)] 
BUG/MINOR: jwt: Fix jwt_parse_alg incorrectly returning JWS_ALG_NONE

jwt_parse_alg would mistakenly return JWT_ALG_NONE for algorithms "",
"n", "no" and "non" because of a strncmp misuse. It now sees them as
unknown algorithms.

No backport needed.

Cc: Tim Duesterhus <tim@bastelstu.be>
3 years agoMEDIUM: resolvers: rename dns extra counters to resolvers extra counters
Emeric Brun [Fri, 29 Oct 2021 15:59:18 +0000 (17:59 +0200)] 
MEDIUM: resolvers: rename dns extra counters to resolvers extra counters

This patch renames all dns extra counters and stats functions, types and
enums using the 'resolv' prefix/suffixes.

The dns extra counter domain id used on cli was replaced by "resolvers"
instead of "dns".

The typed extra counter prefix dumping resolvers domain "D." was
also renamed "N." because it points counters on a Nameserver.

This was done to finish the split between "resolver" and "dns" layers
and to avoid further misunderstanding when haproxy will handle dns
load balancing.

This should not be backported.

3 years agoMINOR: resolvers/dns: split dns and resolver counters in dns_counter struct
Emeric Brun [Fri, 29 Oct 2021 15:30:41 +0000 (17:30 +0200)] 
MINOR: resolvers/dns: split dns and resolver counters in dns_counter struct

This patch add a union and struct into dns_counter struct to split
application specific counters.

The only current existing application is the resolver.c layer but
in futur we could handle different application such as dns load
balancing with others specific counters.

This patch should not be backported.

3 years agoBUG/MINOR: resolvers: throw log message if trash not large enough for query
Emeric Brun [Fri, 29 Oct 2021 14:44:49 +0000 (16:44 +0200)] 
BUG/MINOR: resolvers: throw log message if trash not large enough for query

Before this patch the sent error counter was increased
for each targeted nameserver as soon as we were unable to build
the query message into the trash buffer. But this counter is here
to count sent errors at dns.c transport layer and this error is not
related to a nameserver.

This patch stops to increase those counters and sent a log message
to signal the trash buffer size is not large enough to build the query.

Note: This case should not happen except if trash size buffer was
customized to a very low value.

The function was also re-worked to return -1 in this error case
as it was specified in comment. This function is currently
called at multiple point in resolver.c but return code
is still not yet handled. So to advert the user of the malfunction
the log message was added.

This patch should be backported on all versions including the
layer split between dns.c and resolver.c (v >= 2.4)

3 years agoBUG/MINOR: resolvers: fix sent messages were counted twice
Emeric Brun [Fri, 29 Oct 2021 14:28:33 +0000 (16:28 +0200)] 
BUG/MINOR: resolvers: fix sent messages were counted twice

The sent messages counter was increased at both resolver.c and dns.c
layers.

This patch let the dns.c layer count the sent messages since this
layer handle a retry if transport layer is not ready (EAGAIN on udp
or tcp session ring buffer full).

This patch should be backported on all versions using a split of those
layers for resolving (v >=2.4)

3 years agoMINOR: server: add ws keyword
Amaury Denoyelle [Mon, 18 Oct 2021 12:40:29 +0000 (14:40 +0200)] 
MINOR: server: add ws keyword

Implement parsing for the server keyword 'ws'. This is used to configure
the mode of selection for websocket protocol. The configuration
documentation has been updated.

A new regtest has been created to test the proper behavior of the
keyword.

3 years agoMEDIUM: server/backend: implement websocket protocol selection
Amaury Denoyelle [Mon, 18 Oct 2021 12:39:57 +0000 (14:39 +0200)] 
MEDIUM: server/backend: implement websocket protocol selection

Handle properly websocket streams if the server uses an ALPN with both
h1 and h2. Add a new field h2_ws in the server structure. If set to off,
reuse is automatically disable on backend and ALPN is forced to http1.x
if possible. Nothing is done if on.

Implement a mechanism to be able to use a different http version for
websocket streams. A new server member <ws> represents the algorithm to
select the protocol. This can overrides the server <proto>
configuration. If the connection uses ALPN for proto selection, it is
updated for websocket streams to select the right protocol.

Three mode of selection are implemented :
- auto : use the same protocol between non-ws and ws streams. If ALPN is
  use, try to update it to "http/1.1"; this is only done if the server
  ALPN contains "http/1.1".
- h1 : use http/1.1
- h2 : use http/2.0; this requires the server to support RFC8441 or an
  error will be returned by haproxy.

3 years agoMINOR: connection: add alternative mux_ops param for conn_install_mux_be
Amaury Denoyelle [Thu, 28 Oct 2021 14:36:11 +0000 (16:36 +0200)] 
MINOR: connection: add alternative mux_ops param for conn_install_mux_be

Add a new parameter force_mux_ops. This will be useful to specify an
alternative to the srv->mux_proto field. If non-NULL, it will be use to
force the mux protocol wether srv->mux_proto is set or not.

This argument will become useful to install a mux for non-standard
streams, most notably websocket streams.

3 years agoMINOR: connection: implement function to update ALPN
Amaury Denoyelle [Mon, 18 Oct 2021 12:32:36 +0000 (14:32 +0200)] 
MINOR: connection: implement function to update ALPN

Implement a new function to update the ALPN on an existing connection.
on an existing connection. The ALPN from the ssl context can be checked
to update the ALPN only if it is a subset of the context value.

This method will be useful to change a connection ALPN for websocket,
must notably if the server does not support h2 websocket through the
rfc8441 Extended Connect.

3 years agoMINOR: stream/mux: implement websocket stream flag
Amaury Denoyelle [Mon, 18 Oct 2021 12:45:49 +0000 (14:45 +0200)] 
MINOR: stream/mux: implement websocket stream flag

Define a new stream flag SF_WEBSOCKET and a new cs flag CS_FL_WEBSOCKET.
The conn-stream flag is first set by h1/h2 muxes if the request is a
valid websocket upgrade. The flag is then converted to SF_WEBSOCKET on
the stream creation.

This will be useful to properly manage websocket streams in
connect_server().

3 years agoBUG/MEDIUM: mux-h2: reject upgrade if no RFC8441 support
Amaury Denoyelle [Mon, 18 Oct 2021 07:43:29 +0000 (09:43 +0200)] 
BUG/MEDIUM: mux-h2: reject upgrade if no RFC8441 support

The RFC8441 was not respected by haproxy in regards with server support
for Extended CONNECT. The Extended CONNECT method was used to convert an
Upgrade header stream even if no SETTINGS_ENABLE_CONNECT_PROTOCOL was
received, which is forbidden by the RFC8441. In this case, the behavior
of the http/2 server is unspecified.

Fix this by flagging the connection on receiption of the RFC8441
settings SETTINGS_ENABLE_CONNECT_PROTOCOL. Extended CONNECT is thus only
be used if the flag is present. In the other case, the stream is
immediatly closed as there is no way to handle it in http/2. It results
in a http/1.1 502 or http/2 RESET_STREAM to the client side.

The protocol-upgrade regtest has been extended to test that haproxy does
not emit Extended CONNECT on servers without RFC8441 support.

It must be backported up to 2.4.

3 years agoMINOR: mux-h2: add trace on extended connect usage
Amaury Denoyelle [Mon, 18 Oct 2021 08:05:16 +0000 (10:05 +0200)] 
MINOR: mux-h2: add trace on extended connect usage

Add a state trace to report that a protocol upgrade is converted using
the rfc8441 Extended connect method. This is useful in regards with the
recent changes to improve http/2 websockets.

3 years agoMINOR: jwt: Make invalid static JWT algorithms an error in `jwt_verify` converter
Tim Duesterhus [Fri, 29 Oct 2021 16:06:55 +0000 (18:06 +0200)] 
MINOR: jwt: Make invalid static JWT algorithms an error in `jwt_verify` converter

It is not useful to start a configuration where an invalid static string is
provided as the JWT algorithm. Better make the administrator aware of the
suspected typo by failing to start.

3 years agoSCRIPTS: git-show-backports: re-enable file-based filtering
Willy Tarreau [Wed, 3 Nov 2021 07:41:01 +0000 (08:41 +0100)] 
SCRIPTS: git-show-backports: re-enable file-based filtering

The early version of the script used to support passing non-branch
arguments but as it evolved we lost that option. Let's use "--" as a
delimiter after the branch(es) to pass optional file names to filter
on. This is convenient to list missing patches on a specific set of
files.

3 years ago[RELEASE] Released version 2.5-dev12 v2.5-dev12
Willy Tarreau [Tue, 2 Nov 2021 17:05:41 +0000 (18:05 +0100)] 
[RELEASE] Released version 2.5-dev12

Released version 2.5-dev12 with the following main changes :
    - MINOR: httpclient: support payload within a buffer
    - MINOR: httpclient/lua: support more HTTP methods
    - MINOR: httpclient/lua: return an error when it can't generate the request
    - CLEANUP: lua: Remove any ambiguities about lua txn execution context flags
    - BUG/MEDIUM: lua: fix invalid return types in hlua_http_msg_get_body
    - CLEANUP: connection: No longer export make_proxy_line_v1/v2 functions
    - CLEANUP: tools: Use const address for get_net_port() and get_host_port()
    - CLEANUP: lua: Use a const address to retrieve info about a connection
    - MINOR: connection: Add function to get src/dst without updating the connection
    - MINOR: session: Add src and dst addresses to the session
    - MINOR: stream-int: Add src and dst addresses to the stream-interface
    - MINOR: frontend: Rely on client src and dst addresses at stream level
    - MINOR: log: Rely on client addresses at the appropriate level to log messages
    - MINOR: session: Rely on client source address at session level to log error
    - MINOR: http-ana: Rely on addresses at stream level to set xff and xot headers
    - MINOR: http-fetch: Rely on addresses at stream level in HTTP sample fetches
    - MINOR: mux-fcgi: Rely on client addresses at stream level to set default params
    - MEDIUM: tcp-sample: Rely on addresses at the appropriate level in tcp samples
    - MEDIUM: connection: Rely on addresses at stream level to make proxy line
    - MEDIUM: backend: Rely on addresses at stream level to init server connection
    - MEDIUM: connection: Assign session addresses when PROXY line is received
    - MEDIUM: connection: Assign session addresses when NetScaler CIP proto is parsed
    - MEDIUM: tcp-act: Set addresses at the apprioriate level in set-(src/dst) actions
    - MINOR: tcp-act: Add set-src/set-src-port for "tcp-request content" rules
    - DOC: config: Fix alphabetical order of fc_* samples
    - MINOR: tcp-sample: Add samples to get original info about client connection
    - REGTESTS: Add script to test client src/dst manipulation at different levels
    - MINOR: stream: Use backend stream-interface dst address instead of target_addr
    - BUILD: log: Fix compilation without SSL support
    - DEBUG: protocol: yell loudly during registration of invalid sock_domain
    - MINOR: protocols: add a new protocol type selector
    - MINOR: protocols: make use of the protocol type to select the protocol
    - MINOR: protocols: replace protocol_by_family() with protocol_lookup()
    - MINOR: halog: Add -qry parameter allowing to preserve the query string in -uX
    - CLEANUP: jwt: Remove the use of a trash buffer in jwt_jwsverify_hmac()
    - CLEANUP: jwt: Remove the use of a trash buffer in jwt_jwsverify_rsa_ecdsa()
    - DEV: coccinelle: Add realloc_leak.cocci
    - CLEANUP: hlua: Remove obsolete branch in `hlua_alloc()`
    - BUILD: atomic: prefer __atomic_compare_exchange_n() for __ha_cas_dw()
    - BUILD: atomic: fix build on mac/arm64
    - MINOR: atomic: remove the memcpy() call and dependency on string.h
    - MINOR: httpclient: request streaming with a callback
    - MINOR: httpclient/lua: handle the streaming into the lua applet
    - REGTESTS: lua: test httpclient with body streaming
    - DOC: halog: Move the `-qry` parameter into the correct section in help text
    - MINOR: halog: Rename -qry to -query
    - CLEANUP: halog: Use consistent indentation in help()
    - BUG/MINOR: halog: Add missing newlines in die() messages
    - MINOR: halog: Add support for extracting captures using -hdr
    - DOC: Typo fixed "it" should be "is"
    - BUG/MINOR: mux-h1: Save shutdown mode if the shutdown is delayed
    - BUG/MEDIUM: mux-h1: Perform a connection shutdown when the h1c is released
    - BUG/MEDIUM: resolvers: Don't recursively perform requester unlink
    - BUG/MEDIUM: http-ana: Drain request data waiting the tarpit timeout expiration
    - BUG/MINOR: http: Authorization value can have multiple spaces after the scheme
    - BUG/MINOR: http: http_auth_bearer fetch does not work on custom header name
    - BUG/MINOR: httpclient/lua: misplaced luaL_buffinit()
    - BUILD/MINOR: cpuset freebsd build fix
    - BUG/MINOR: httpclient: use a placeholder value for Host header
    - BUG/MEDIUM: stream-int: Block reads if channel cannot receive more data
    - BUG/MEDIUM: resolvers: Track api calls with a counter to free resolutions
    - MINOR: stream: Improve dump of bogus streams
    - DOC/peers: some grammar fixes for peers 2.1 spec
    - MEDIUM: vars: make the var() sample fetch function really return type ANY
    - MINOR: vars: add "set-var" for "tcp-request connection" rules.

3 years agoMINOR: vars: add "set-var" for "tcp-request connection" rules.
Jaroslaw Rzeszótko [Tue, 2 Nov 2021 15:56:05 +0000 (16:56 +0100)] 
MINOR: vars: add "set-var" for "tcp-request connection" rules.

Session struct is already allocated when "tcp-request connection" rules
are evaluated so session-scoped variables turned out easy to support.

This resolves github issue #1408.

3 years agoMEDIUM: vars: make the var() sample fetch function really return type ANY
Willy Tarreau [Tue, 2 Nov 2021 16:08:15 +0000 (17:08 +0100)] 
MEDIUM: vars: make the var() sample fetch function really return type ANY

A long-standing issue was reported in issue #1215.

In short, var() was initially internally declared as returning a string
because it was not possible by then to return "any type". As such, users
regularly get trapped thinking that when they're storing an integer there,
then the integer matching method automatically applies. Except that this
is not possible since this is related to the config parser and is decided
at boot time where the variable's type is not known yet.

As such, what is done is that the output being declared as type string,
the string match will automatically apply, and any value will first be
converted to a string. This results in several issues like:

    http-request set-var(txn.foo) int(-1)
    http-request deny if { var(txn.foo) lt 0 }

not working. This is because the string match on the second line will in
fact compare the string representation of the variable against strings
"lt" and "0", none of which matches.

The doc says that the matching method is mandatory, though that's not
the case in the code due to that default string type being permissive.
There's not even a warning when no explicit match is placed, because
this happens very deep in the expression evaluator and making a special
case just for "var" can reveal very complicated.

The set-var() converter already mandates a matching method, as the
following will be rejected:

    ... if { int(12),set-var(txn.truc) 12 }

  while this one will work:

    ... if { int(12),set-var(txn.truc) -m int 12 }

As such, this patch this modifies var() to match the doc, returning the
type "any", and mandating the matching method, implying that this bogus
config which does not work:

    http-request set-var(txn.foo) int(-1)
    http-request deny if { var(txn.foo) lt 0 }

  will need to be written like this:

    http-request set-var(txn.foo) int(-1)
    http-request deny if { var(txn.foo) -m int lt 0 }

This *will* break some configs (and even 3 of our regtests relied on
this), but except those which already match string exclusively, all
other ones are already broken and silently fail (and one of the 3
regtests, the one on FIX, was bogus regarding this).

In order to fix existing configs, one can simply append "-m str"
after a "var()" in an ACL or "if" expression:

    http-request deny unless { var(txn.jwt_alg) "ES" }

  must become:

    http-request deny unless { var(txn.jwt_alg) -m str "ES" }

Most commonly, patterns such as "le", "lt", "ge", "gt", "eq", "ne" in
front of a number indicate that the intent was to match an integer,
and in this case "-m int" would be desired:

    tcp-response content reject if ! { var(res.size) gt 3800 }

  ought to become:

    tcp-response content reject if ! { var(res.size) -m int gt 3800 }

This must not be backported, but if a solution is found to at least
detect this exact condition in the generic expression parser and
emit a warning, this could probably help spot configuration bugs.

Link: https://www.mail-archive.com/haproxy@formilux.org/msg41341.html
Cc: Christopher Faulet <cfaulet@haproxy.com>
Cc: Tim Düsterhus <tim@bastelstu.be>
3 years agoDOC/peers: some grammar fixes for peers 2.1 spec
John Roesler [Fri, 29 Oct 2021 19:59:33 +0000 (14:59 -0500)] 
DOC/peers: some grammar fixes for peers 2.1 spec

These are a few minor grammar fixes for the peers protocol 2.1 documentation.

3 years agoMINOR: stream: Improve dump of bogus streams
Christopher Faulet [Tue, 2 Nov 2021 16:18:15 +0000 (17:18 +0100)] 
MINOR: stream: Improve dump of bogus streams

Stream flags and information about the HTTP txn, if defined, are now
emitted. This will help us to identify bugs when such message is reported.

3 years agoBUG/MEDIUM: resolvers: Track api calls with a counter to free resolutions
Christopher Faulet [Tue, 2 Nov 2021 15:25:05 +0000 (16:25 +0100)] 
BUG/MEDIUM: resolvers: Track api calls with a counter to free resolutions

The kill list introduced in commit f766ec6b5 ("MEDIUM: resolvers: use a kill
list to preserve the list consistency") contains a bug. The deatch_row must
be initialized before calling resolv_process_responses() function. However,
this function is called for the dns code. The death_row is not visible from
the outside. So, it is possible to add a resolution in an uninitialized
death_row, leading to a crash.

But, with the current implementation, it is not possible to handle the
death_row in resolv_process_responses() function because, internally, the
kill list may be freed via a call to resolv_unlink_resolution(). At the end,
we are unable to determine all call chains to guarantee a safe use of the
kill list. It is a shameful observation, but unfortunatly true.

So, to make the fix simple, we track all calls to the public resolvers
api. A counter is incremented when we enter in the resolver code and
decremented when we leave it. This way, we are able to track the recursions
to init and release the kill list only once, at the edge.

Following functions are incrementing/decrementing the recurse counter:

  * resolv_trigger_resolution()
  * resolv_srvrq_expire_task()
  * resolv_link_resolution()
  * resolv_unlink_resolution()
  * resolv_detach_from_resolution_answer_items()
  * resolv_process_responses()
  * process_resolvers()
  * resolvers_finalize_config()
  * resolv_action_do_resolve()

This patch should fix the issue #1404. It must be backported everywhere the
above commit was backported.

3 years agoBUG/MEDIUM: stream-int: Block reads if channel cannot receive more data
Christopher Faulet [Fri, 29 Oct 2021 12:55:59 +0000 (14:55 +0200)] 
BUG/MEDIUM: stream-int: Block reads if channel cannot receive more data

First of all, we must be careful here because this part was modified and
each time, this introduced a bug. But, in si_update_rx(), we must not
re-enables receives if the channel buffer cannot receive more
data. Otherwise the multiplexer will be wake up for nothing. Because the
stream is woken up when the multiplexer is waiting for more room to move on,
this may lead to a ping-pong loop between the stream and the mux.

Note that for now, it does not fix any known bug. All reported issues in
this area were fixed in another way.

This patch must be backported with a special care. Technically speaking, it
may be backported as far as 2.0.

3 years agoBUG/MINOR: httpclient: use a placeholder value for Host header
William Lallemand [Tue, 2 Nov 2021 14:22:10 +0000 (15:22 +0100)] 
BUG/MINOR: httpclient: use a placeholder value for Host header

A Host header must be present for http_update_host() to success.
htx_add_header(htx, ist("Host"), IST_NULL) was used but this is not a
good idea from a semantic point of view. It also tries to make a memcpy
with a len of 0, which is unrequired.

Use an ist("h") instead as a placeholder value.

This patch fixes bug #1439.

3 years agoBUILD/MINOR: cpuset freebsd build fix
David Carlier [Sat, 30 Oct 2021 11:22:21 +0000 (12:22 +0100)] 
BUILD/MINOR: cpuset freebsd build fix

Add missing strings.h header. Required for ffsl definition used by
CPU_FFS macro.

This must be backported up to 2.4.

3 years agoBUG/MINOR: httpclient/lua: misplaced luaL_buffinit()
William Lallemand [Tue, 2 Nov 2021 09:40:06 +0000 (10:40 +0100)] 
BUG/MINOR: httpclient/lua: misplaced luaL_buffinit()

Some luaL_buffinit() call was done before the push of the variable name,
where it seems to work correctly with lua < 5.4.3, it brokes
systematically on this version.

This patch inverts the pushstring and the buffinit.

3 years agoBUG/MINOR: http: http_auth_bearer fetch does not work on custom header name
Remi Tricot-Le Breton [Fri, 29 Oct 2021 13:25:19 +0000 (15:25 +0200)] 
BUG/MINOR: http: http_auth_bearer fetch does not work on custom header name

The http_auth_bearer sample fetch can take a header name as parameter,
in which case it will try to extract a Bearer value out of the given
header name instead of the default "Authorization" one. In this case,
the extraction would not have worked because of a misuse of strncasecmp.
This patch fixes this by replacing the standard string functions by ist
ones.
It also properly manages the multiple spaces that could be found between
the scheme and its value.

No backport needed, that's part of JWT which is only in 2.5.

Co-authored-by: Tim Duesterhus <tim@bastelstu.be>
3 years agoBUG/MINOR: http: Authorization value can have multiple spaces after the scheme
Remi Tricot-Le Breton [Fri, 29 Oct 2021 13:25:18 +0000 (15:25 +0200)] 
BUG/MINOR: http: Authorization value can have multiple spaces after the scheme

As per RFC7235, there can be multiple spaces in the value of an
Authorization header, between the scheme and the actual authentication
parameters.

This can be backported to all stable versions since basic auth has almost
always been there.

3 years agoBUG/MEDIUM: http-ana: Drain request data waiting the tarpit timeout expiration
Christopher Faulet [Fri, 29 Oct 2021 12:37:07 +0000 (14:37 +0200)] 
BUG/MEDIUM: http-ana: Drain request data waiting the tarpit timeout expiration

When a tarpit action is performed, we must be sure to drain data from the
request channel. Otherwise, the mux on the frontend side may be blocked
because the request channel buffer is full.

This may lead to Two bugs. The first one is a HOL blocking on the H2
multiplexer. A tarpitted stream may block all the others because data are
not drained for the whole tarpit timeout. The second bug is a ping-pong loop
between the multiplexer and the stream. The mux is waiting for more space in
the channel buffer, so it wakes up the stream. And the stream systematically
re-enables receives.

This last part is not pretty clean and it will be addressed with another
fix. But draning request data is a good way to fix both bugs in same time.

This patch must be backported as far as 2.0. The legacy HTTP mode is
probably affected, but I don't know if same bugs may be experienced in this
mode.

3 years agoBUG/MEDIUM: resolvers: Don't recursively perform requester unlink
Christopher Faulet [Fri, 29 Oct 2021 08:38:15 +0000 (10:38 +0200)] 
BUG/MEDIUM: resolvers: Don't recursively perform requester unlink

When a requester is unlink from a resolution, by reading the code, we can
have this call chain:

_resolv_unlink_resolution(srv->resolv_requester)
  resolv_detach_from_resolution_answer_items(resolution, requester)
    resolv_srvrq_cleanup_srv(srv)
      _resolv_unlink_resolution(srv->resolv_requester)

A loop on the resolution answer items is performed inside
resolv_detach_from_resolution_answer_items(). But by reading the code, it
seems possible to recursively unlink the same requester.

To avoid any loop at this stage, the requester clean up must be performed
before the call to resolv_detach_from_resolution_answer_items(). This way,
the second call to _resolv_unlink_resolution() does nothing and returns
immediately because the requester was already detached from the resolution.

This patch is related to the issue #1404. It must be backported as far as
2.2.

3 years agoBUG/MEDIUM: mux-h1: Perform a connection shutdown when the h1c is released
Christopher Faulet [Wed, 27 Oct 2021 13:42:13 +0000 (15:42 +0200)] 
BUG/MEDIUM: mux-h1: Perform a connection shutdown when the h1c is released

When the H1 connection is released, a connection shutdown is now performed.
If it was already performed when the stream was detached, this action has no
effect. But it is mandatory, when an idle H1C is released. Otherwise the
xprt and the socket shutdown is never perfmed. It is especially important
for SSL client connections, because it is the only way to perform a clean
SSL shutdown.

Without this patch, SSL_shutdown is never called, preventing, among other
things, the SSL session caching.

This patch depends on the commit "BUG/MINOR: mux-h1: Save shutdown mode if
the shutdown is delayed". It should be backported as far as 2.0.

3 years agoBUG/MINOR: mux-h1: Save shutdown mode if the shutdown is delayed
Christopher Faulet [Wed, 27 Oct 2021 13:36:38 +0000 (15:36 +0200)] 
BUG/MINOR: mux-h1: Save shutdown mode if the shutdown is delayed

The connection shutdown may be delayed if there are pending outgoing
data. The action is performed once data are fully sent. In this case the
mode (dirty/clean) was lost and a clean shutdown was always performed. Now,
the mode is saved to be sure to perform the connection shutdown using the
right mode. To do so, H1C_F_ST_SILENT_SHUT flag is introduced.

This patch should be backported as far as 2.0.

3 years agoDOC: Typo fixed "it" should be "is"
Anubhav [Thu, 14 Oct 2021 16:58:25 +0000 (22:28 +0530)] 
DOC: Typo fixed "it" should be "is"

This patch was proposed in GitHub PR #1415.

Reviewed-by: Tim Duesterhus <tim@bastelstu.be>
3 years agoMINOR: halog: Add support for extracting captures using -hdr
Tim Duesterhus [Thu, 28 Oct 2021 15:24:02 +0000 (17:24 +0200)] 
MINOR: halog: Add support for extracting captures using -hdr

This patch adds support for extracting captured header fields to halog. A field
can be extracted by passing the `-hdr <block>:<field>` output filter.

Both `<block>` and `<field>` are 1-indexed.

`<block>` refers to the index of the brace-delimited list of headers. If both
request and response headers are captured, then request headers are referenced
by `<block> = 1`, response headers are `2`. If only one direction is captured,
there will only be a single block `1`.

`<field>` refers to a single field within the selected block.

The output will contain one line, possibly empty, per log line processed.
Passing a non-existent `<block>` or `<field>` will result in an empty line.

Example:

    capture request  header a len 50
    capture request  header b len 50
    capture request  header c len 50
    capture response header d len 50
    capture response header e len 50
    capture response header f len 50

`-srv 1:1` will extract request  header `a`
`-srv 1:2` will extract request  header `b`
`-srv 1:3` will extract request  header `c`
`-srv 2:3` will extract response header `f`

This resolves GitHub issue #1146.

3 years agoBUG/MINOR: halog: Add missing newlines in die() messages
Tim Duesterhus [Thu, 28 Oct 2021 15:06:23 +0000 (17:06 +0200)] 
BUG/MINOR: halog: Add missing newlines in die() messages

This newline is required to correctly print the usage.

3 years agoCLEANUP: halog: Use consistent indentation in help()
Tim Duesterhus [Thu, 28 Oct 2021 13:55:49 +0000 (15:55 +0200)] 
CLEANUP: halog: Use consistent indentation in help()

Consistently use 1 Tab per line.

3 years agoMINOR: halog: Rename -qry to -query
Tim Duesterhus [Thu, 28 Oct 2021 14:36:03 +0000 (16:36 +0200)] 
MINOR: halog: Rename -qry to -query

With the query flag moved into the correct help section, there is enough space
for two additional characters.

3 years agoDOC: halog: Move the `-qry` parameter into the correct section in help text
Tim Duesterhus [Thu, 28 Oct 2021 13:53:37 +0000 (15:53 +0200)] 
DOC: halog: Move the `-qry` parameter into the correct section in help text

This is not an output filter, but instead a modifier. Specifically "only one
may be used at a time" is not true.

see 24b8d693b202b01b649f64ed878d8f9dd1b242e4

3 years agoREGTESTS: lua: test httpclient with body streaming
William Lallemand [Thu, 28 Oct 2021 13:57:33 +0000 (15:57 +0200)] 
REGTESTS: lua: test httpclient with body streaming

Improve the httpclient reg-tests to test the streaming,

The regtest now sends a big payload to vtest, then receive a payload
from vtest and send it again.

3 years agoMINOR: httpclient/lua: handle the streaming into the lua applet
William Lallemand [Thu, 28 Oct 2021 13:41:38 +0000 (15:41 +0200)] 
MINOR: httpclient/lua: handle the streaming into the lua applet

With this feature the lua implementation of the httpclient is now able
to stream a payload larger than an haproxy buffer.

The hlua_httpclient_send() function is now split into:

hlua_httpclient_send() which initiate the httpclient and parse the lua
parameters

hlua_httpclient_snd_yield() which will send the request and be called
again to stream the request if the body is larger than an haproxy buffer

hlua_httpclient_rcv_yield() which will receive the response and store it
in the lua buffer.

3 years agoMINOR: httpclient: request streaming with a callback
William Lallemand [Thu, 28 Oct 2021 13:34:26 +0000 (15:34 +0200)] 
MINOR: httpclient: request streaming with a callback

This patch add a way to handle HTTP requests streaming using a
callback.

The end of the data must be specified by using the "end" parameter in
httpclient_req_xfer().

3 years agoMINOR: atomic: remove the memcpy() call and dependency on string.h
Willy Tarreau [Thu, 28 Oct 2021 07:41:29 +0000 (09:41 +0200)] 
MINOR: atomic: remove the memcpy() call and dependency on string.h

The memcpy() call in the aarch64 version of __ha_cas_dw() is sometimes
inlined and sometimes not, depending on the gcc version. It's only used
to copy two void*, so let's use direct assignment instead of memcpy().
It would also be possible to change the asm code to directly write there,
but it's not worth it.

With this change the code is 8kB smaller with gcc-5.4.

3 years agoBUILD: atomic: fix build on mac/arm64
David CARLIER [Sat, 23 Oct 2021 13:43:42 +0000 (14:43 +0100)] 
BUILD: atomic: fix build on mac/arm64

The inline assembly is invalid for this platform thus falling back
to the builtin instead.

3 years agoBUILD: atomic: prefer __atomic_compare_exchange_n() for __ha_cas_dw()
Willy Tarreau [Thu, 28 Oct 2021 06:53:33 +0000 (08:53 +0200)] 
BUILD: atomic: prefer __atomic_compare_exchange_n() for __ha_cas_dw()

__atomic_compare_exchange() is incorrectly documented in the gcc builtins
doc, it says the desired value is "type *desired" while in reality it is
"const type *desired" as expected since that value must in no way be
modified by the operation. However it seems that clang has implemented
it as documented, and reports build warnings when fed a const.

This is quite problematic because it means we have to betry the callers,
pretending we won't touch their constants but not knowing what the
compiler would do with them, and possibly hiding future bugs.

Instead of forcing a cast, let's just switch to the better
__atomic_compare_exchange_n() that takes a value instead of a pointer.
At least with this one there is no doubt about how the input will be
used.

It was verified that the output object code is the same both in clang
and gcc with this change.

3 years agoCLEANUP: hlua: Remove obsolete branch in `hlua_alloc()`
Tim Duesterhus [Sat, 23 Oct 2021 17:56:40 +0000 (19:56 +0200)] 
CLEANUP: hlua: Remove obsolete branch in `hlua_alloc()`

This branch is no longer required, because the `!nsize` case is handled for any
value of `ptr` now.

see 22586524e32f14c44239063088a38ccea8abc9b7
see a5efdff93c36f75345a2a18f18bffee9b602bc7b

3 years agoDEV: coccinelle: Add realloc_leak.cocci
Tim Duesterhus [Sat, 23 Oct 2021 17:53:35 +0000 (19:53 +0200)] 
DEV: coccinelle: Add realloc_leak.cocci

This coccinelle patch finds locations where the return value of `realloc()` is
assigned to the pointer passed to `realloc()`. This calls will leak memory if
`realloc()` returns `NULL`.

3 years agoCLEANUP: jwt: Remove the use of a trash buffer in jwt_jwsverify_rsa_ecdsa()
Tim Duesterhus [Mon, 18 Oct 2021 16:40:29 +0000 (18:40 +0200)] 
CLEANUP: jwt: Remove the use of a trash buffer in jwt_jwsverify_rsa_ecdsa()

`trash` was completely unused within this function.