]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
5 years agoMEDIUM: arg: make make_arg_list() support quotes in arguments
Willy Tarreau [Fri, 14 Feb 2020 12:37:20 +0000 (13:37 +0100)] 
MEDIUM: arg: make make_arg_list() support quotes in arguments

Now it becomes possible to reuse the quotes within arguments, allowing
the parser to distinguish a ',' or ')' that is part of the value from
one which delimits the argument. In addition, ',' and ')' may be escaped
using a backslash. However, it is also important to keep in mind that
just like in shell, quotes are first resolved by the word tokenizer, so
in order to pass quotes that are visible to the argument parser, a second
level is needed, either using backslash escaping, or by using an alternate
type.

For example, it's possible to write this to append a comma:

     http-request add-header paren-comma-paren "%[str('(--,--)')]"

or this:

     http-request add-header paren-comma-paren '%[str("(--,--)")]'

or this:

     http-request add-header paren-comma-paren %[str(\'(--,--)\')]

or this:

     http-request add-header paren-comma-paren %[str(\"(--,--)\")]

or this:

     http-request add-header paren-comma-paren %[str(\"(\"--\',\'--\")\")]

Note that due to the wide use of '\' in front of parenthesis in regex,
the backslash character will purposely *not* escape parenthesis, so that
'\)' placed in quotes is passed verbatim to a regex engine.

5 years agoMEDIUM: arg: copy parsed arguments into the trash instead of allocating them
Willy Tarreau [Fri, 14 Feb 2020 10:34:35 +0000 (11:34 +0100)] 
MEDIUM: arg: copy parsed arguments into the trash instead of allocating them

For each and every argument parsed by make_arg_list(), there was an
strndup() call, just so that we have a trailing zero for most functions,
and this temporary buffer is released afterwards except for strings where
it is kept.

Proceeding like this is not convenient because 1) it performs a huge
malloc/free dance, and 2) it forces to decide upfront where the argument
ends, which is what prevents commas and right parenthesis from being used.

This patch makes the function copy the temporary argument into the trash
instead, so that we avoid the malloc/free dance for most all non-string
args (e.g. integers, addresses, time, size etc), and that we can later
produce the contents on the fly while parsing the input. It adds a length
check to make sure that the argument is not longer than the buffer size,
which should obviously never be the case but who knows what people put in
their configuration.

5 years agoMEDIUM: arg: make make_arg_list() stop after its own arguments
Willy Tarreau [Fri, 14 Feb 2020 07:40:37 +0000 (08:40 +0100)] 
MEDIUM: arg: make make_arg_list() stop after its own arguments

The main problem we're having with argument parsing is that at the
moment the caller looks for the first character looking like an end
of arguments (')') and calls make_arg_list() on the sub-string inside
the parenthesis.

Let's first change the way it works so that make_arg_list() also
consumes the parenthesis and returns the pointer to the first char not
consumed. This will later permit to refine each argument parsing.

For now there is no functional change.

5 years agoMINOR: sample/acl: use is_idchar() to locate the fetch/conv name
Willy Tarreau [Fri, 14 Feb 2020 17:27:10 +0000 (18:27 +0100)] 
MINOR: sample/acl: use is_idchar() to locate the fetch/conv name

Instead of scanning a string looking for an end of line, ')' or ',',
let's only accept characters which are actually valid identifier
characters. This will let the parser know that in %[src], only "src"
is the sample fetch name, not "src]". This was done both for samples
and ACLs since they are the same here.

5 years agoMINOR: chunk: implement chunk_strncpy() to copy partial strings
Willy Tarreau [Fri, 14 Feb 2020 10:31:41 +0000 (11:31 +0100)] 
MINOR: chunk: implement chunk_strncpy() to copy partial strings

This does like chunk_strcpy() except that the maximum string length may
be limited by the caller. A trailing zero is always appended. This is
particularly handy to extract portions of strings to put into the trash
for use with libc functions requiring a nul-terminated string.

5 years agoMINOR: tools: add is_idchar() to tell if a char may belong to an identifier
Willy Tarreau [Fri, 14 Feb 2020 17:25:17 +0000 (18:25 +0100)] 
MINOR: tools: add is_idchar() to tell if a char may belong to an identifier

This function will simply be used to find the end of config identifiers
(proxies, servers, ACLs, sample fetches, converters, etc).

5 years agoMINOR: mux-fcgi: Make the capture of the path-info optional in pathinfo regex
Christopher Faulet [Fri, 14 Feb 2020 15:55:52 +0000 (16:55 +0100)] 
MINOR: mux-fcgi: Make the capture of the path-info optional in pathinfo regex

Now, only one capture is mandatory in the path-info regex, the one matching the
script-name. The path-info capture is optional. Of couse, it must be defined to
fill the PATH_INFO parameter. But it is not mandatory. This way, it is possible
to get the script-name part from the path, excluding the path-info.

This patch is small enough to be backported to 2.1.

5 years agoCLEANUP: ssl: remove unused functions in openssl-compat.h
Ilya Shipitsin [Thu, 13 Feb 2020 09:07:36 +0000 (14:07 +0500)] 
CLEANUP: ssl: remove unused functions in openssl-compat.h

functions SSL_SESSION_get0_id_context, SSL_CTX_get_default_passwd_cb,
SSL_CTX_get_default_passwd_cb_userdata are not used anymore

5 years agoBUG/MINOR: mux-fcgi: Forbid special characters when matching PATH_INFO param
Christopher Faulet [Fri, 14 Feb 2020 13:47:37 +0000 (14:47 +0100)] 
BUG/MINOR: mux-fcgi: Forbid special characters when matching PATH_INFO param

If a regex to match the PATH_INFO parameter is configured, it systematically
fails if a newline or a null character is present in the URL-decoded path. So,
from the moment there is at least a "%0a" or a "%00" in the request path, we
always fail to get the PATH_INFO parameter and all the decoded path is used for
the SCRIPT_NAME parameter.

It is probably not the expected behavior. Because, most of time, these
characters are not expected at all in a path, an error is now triggered when one
of these characters is found in the URL-decoded path before trying to execute
the path_info regex. However, this test is not performed if there is no regex
configured.

Note that in reality, the newline character is only a problem when HAProxy is
complied with pcre or pcre2 library and conversely, the null character is only a
problem for the libc's regex library. But both are always excluded to avoid any
inconsistency depending on compile options.

An alternative, not implemented yet, is to replace these characters by another
one. If someone complains about this behavior, it will be re-evaluated.

This patch must be backported to all versions supporting the FastCGI
applications, so to 2.1 for now.

5 years agoBUG/MEDIUM: muxes: Use the right argument when calling the destroy method.
Olivier Houchard [Fri, 14 Feb 2020 12:23:45 +0000 (13:23 +0100)] 
BUG/MEDIUM: muxes: Use the right argument when calling the destroy method.

When calling the mux "destroy" method, the argument should be the mux
context, not the connection. In a few instances in the mux code, the
connection was used (mainly when the session wouldn't handle the idle
connection, and the server pool was fool), and that could lead to random
segfaults.

This should be backported to 2.1, 2.0, and 1.9

5 years agoBUG/MINOR: namespace: avoid closing fd when socket failed in my_socketat
William Dauchy [Wed, 12 Feb 2020 20:23:20 +0000 (21:23 +0100)] 
BUG/MINOR: namespace: avoid closing fd when socket failed in my_socketat

we cannot return right after socket opening as we need to move back to
the default namespace first

this should fix github issue #500

this might be backported to all version >= 1.6

Fixes: b3e54fe387c7c1 ("MAJOR: namespace: add Linux network namespace
support")
Signed-off-by: William Dauchy <w.dauchy@criteo.com>
5 years agoSCRIPTS: make announce-release executable again
Willy Tarreau [Wed, 12 Feb 2020 17:21:11 +0000 (18:21 +0100)] 
SCRIPTS: make announce-release executable again

I managed to mess up with the file's permission while using a temporary
one during last release, and to backport the non-exec version everywhere.
This can be backported as far as 1.7 now.

5 years agoBUG/MINOR: tcp: don't try to set defaultmss when value is negative
William Dauchy [Wed, 12 Feb 2020 14:53:04 +0000 (15:53 +0100)] 
BUG/MINOR: tcp: don't try to set defaultmss when value is negative

when `getsockopt` previously failed, we were trying to set defaultmss
with -2 value.

this is a followup of github issue #499

this should be backported to all versions >= v1.8

Fixes: 153659f1ae69a1 ("MINOR: tcp: When binding socket, attempt to
reuse one from the old proc.")
Signed-off-by: William Dauchy <w.dauchy@criteo.com>
5 years agoBUILD: scripts/build-ssl.sh: use "uname" instead of ${TRAVIS_OS_NAME}
Ilya Shipitsin [Tue, 11 Feb 2020 09:36:23 +0000 (14:36 +0500)] 
BUILD: scripts/build-ssl.sh: use "uname" instead of ${TRAVIS_OS_NAME}

it is also useful for local builds, when ${TRAVIS_OS_NAME} is not set

5 years agoBUILD: travis-ci: harden builds, add ERR=1 (warning ought to be errors)
Ilya Shipitsin [Tue, 11 Feb 2020 09:31:13 +0000 (14:31 +0500)] 
BUILD: travis-ci: harden builds, add ERR=1 (warning ought to be errors)

5 years agoBUILD: travis-ci: no more allowed failures for openssl-1.0.2
Ilya Shipitsin [Tue, 11 Feb 2020 09:29:41 +0000 (14:29 +0500)] 
BUILD: travis-ci: no more allowed failures for openssl-1.0.2

since 23fb037 (which fixes #429) no need to allow failures
on openssl-1.0.2

5 years agoMINOR: build: add aix72-gcc build TARGET and power{8,9} CPUs
Christian Lachner [Mon, 10 Feb 2020 09:29:13 +0000 (10:29 +0100)] 
MINOR: build: add aix72-gcc build TARGET and power{8,9} CPUs

As haproxy wont build on AIX 7.2 using the old "aix52" TARGET a new
TARGET was introduced which adds two special CFLAGS to prevent the
loading of AIXs xmem.h and var.h. This is done by defining the
corresponding include-guards _H_XMEM and _H_VAR. Without excluding
those headers-files the build fails because of redefinition errors:

1)
  CC      src/mux_fcgi.o
In file included from /usr/include/sys/uio.h:90,
                 from /opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8.3.0/include-fixed/sys/socket.h:104,
                 from include/common/compat.h:32,
                 from include/common/cfgparse.h:25,
                 from src/mux_fcgi.c:13:
src/mux_fcgi.c:204:13: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token
  struct ist rem_addr;
             ^~~~~~~~

2)
  CC      src/cfgparse-listen.o
In file included from include/types/arg.h:31,
                 from include/types/acl.h:29,
                 from include/types/proxy.h:41,
                 from include/proto/log.h:34,
                 from include/common/cfgparse.h:30,
                 from src/mux_h2.c:13:
include/types/vars.h:30:8: error: redefinition of 'struct var'
 struct var {
        ^~~

Futhermore, to enable multithreading via USE_THREAD, the atomic
library was added to the LDFLAGS. Finally, two new CPUs were added
to simplify the usage of power8 and power9 optimizations.

This TARGET was only tested on GCC 8.3 and may or may not work on
IBM's native C-compiler (XLC).

Should be backported to 2.1.

5 years agoBUG/MINOR: tcp: avoid closing fd when socket failed in tcp_bind_listener
William Dauchy [Wed, 12 Feb 2020 09:09:14 +0000 (10:09 +0100)] 
BUG/MINOR: tcp: avoid closing fd when socket failed in tcp_bind_listener

we were trying to close file descriptor even when `socket` call was
failing.
this should fix github issue #499

this should be backported to all versions >= v1.8

Fixes: 153659f1ae69a1 ("MINOR: tcp: When binding socket, attempt to
reuse one from the old proc.")
Signed-off-by: William Dauchy <w.dauchy@criteo.com>
5 years agoBUG/MINOR: listener: enforce all_threads_mask on bind_thread on init
Willy Tarreau [Wed, 12 Feb 2020 09:15:34 +0000 (10:15 +0100)] 
BUG/MINOR: listener: enforce all_threads_mask on bind_thread on init

When intializing a listener, let's make sure the bind_thread mask is
always limited to all_threads_mask when inserting the FD. This will
avoid seeing listening FDs with bits corresponding to threads that are
not active (e.g. when using "bind ... process 1/even"). The side effect
is very limited, all that was identified is that atomic operations are
used in fd_update_events() when not necessary. It's more a matter of
long-term correctness in practice.

This fix might be backported as far as 1.8 (then proto_sockpair must
be dropped).

5 years agoBUG/MEDIUM: listener: only consider running threads when resuming listeners
Willy Tarreau [Wed, 12 Feb 2020 09:01:29 +0000 (10:01 +0100)] 
BUG/MEDIUM: listener: only consider running threads when resuming listeners

In bug #495 we found that it is possible to resume a listener on an
inexistent thread. This happens when a bind's thread_mask contains bits
out of the active threads mask, such as when using "1/odd" or "1/even".
The thread_mask was used as-is to pick a thread number to re-enable the
listener, and given that the highest number is used, 1/odd or 1/even can
produce quite high thread numbers and crash the process by queuing some
entries into non-existent lists.

This bug is an incomplete fix of commit 413e926ba ("BUG/MAJOR: listener:
fix thread safety in resume_listener()") though it will only trigger if
some bind lines are explicitly bound to thread numbers higher than the
thread count. The fix must be backported to all branches having the fix
above (as far as 1.8, though the code is different there, see the commit
message in 1.8 for changes).

There are a few other places where bind_thread is used without
enforcing all_thread_mask, namely when doing fd_insert() while creating
listeners. It seems harmless but would probably deserve another fix.

5 years agoBUILD: http_act: cast file sizes when reporting file size error
Willy Tarreau [Tue, 11 Feb 2020 09:58:56 +0000 (10:58 +0100)] 
BUILD: http_act: cast file sizes when reporting file size error

As seen in issue #496, st_size may be of varying types on different
systems. Let's simply cast it to long long and use long long for
all size outputs.

5 years agoCLEANUP: mini-clist: simplify nested do { while(1) {} } while (0)
Willy Tarreau [Tue, 11 Feb 2020 09:17:52 +0000 (10:17 +0100)] 
CLEANUP: mini-clist: simplify nested do { while(1) {} } while (0)

While looking for other occurrences of do { continue; } while (0) I
found these few leftovers in mini-clist where an outer loop was made
around "do { } while (0)" then another loop was placed inside just to
handle the continue. Let's clean this up by just removing the outer
one. Most of the patch is only the inner part of the loop that is
reindented. It was verified that the resulting code is the same.

5 years agoBUG/MINOR: connection: correctly retry I/O on signals
Willy Tarreau [Tue, 11 Feb 2020 09:08:05 +0000 (10:08 +0100)] 
BUG/MINOR: connection: correctly retry I/O on signals

Issue #490 reports that there are a few bogus constructs of the famous
"do { if (cond) continue; } while (0)" in the connection code, that are
used to retry on I/O failures caused by receipt of a signal. Let's turn
them into the more correct "while (1) { if (cond) continue; break }"
instead. This may or may not be backported, it shouldn't have any
visible effect.

5 years agoBUILD: cirrus-ci: add ERR=1 to freebsd builds
Ilya Shipitsin [Tue, 11 Feb 2020 08:20:32 +0000 (13:20 +0500)] 
BUILD: cirrus-ci: add ERR=1 to freebsd builds

5 years agoBUILD: cirrus-ci: workaround "pkg install" bug
Ilya Shipitsin [Tue, 11 Feb 2020 08:19:22 +0000 (13:19 +0500)] 
BUILD: cirrus-ci: workaround "pkg install" bug

there's a bug https://github.com/freebsd/pkg/issues/902
adding "pkg update -f && pkg upgrade -y" is workaround.

5 years agoBUILD: cirrus-ci: switch to "snap" images to unify openssl naming
Ilya Shipitsin [Tue, 11 Feb 2020 08:16:02 +0000 (13:16 +0500)] 
BUILD: cirrus-ci: switch to "snap" images to unify openssl naming

"snap" images are updated frequently, while regular images are updated quarterly.
so, mixing "snap" and regular images lead to package naming mismatch, which will occur every
quarter. we cannot use 11.3 release image, it is broken, so we have to use 11.3 "snap" image.
Thus let us use all "snap" images. 13-snap is first introduced with this commit.

5 years agoBUG/MINOR: unix: better catch situations where the unix socket path length is close...
Willy Tarreau [Tue, 11 Feb 2020 05:43:37 +0000 (06:43 +0100)] 
BUG/MINOR: unix: better catch situations where the unix socket path length is close to the limit

We do have some checks for the UNIX socket path length to validate the
full pathname of a unix socket but the pathname extension is only taken
into account when using a bind_prefix. The second check only matches
against MAXPATHLEN. So this means that path names between 98 and 108
might successfully parse but fail to bind. Let's adjust the check in
the address parser and refine the error checking at the bind() step.

This addresses bug #493.

5 years agoBUG/MAJOR: mux-h2: don't wake streams after connection was destroyed
Willy Tarreau [Tue, 11 Feb 2020 03:38:56 +0000 (04:38 +0100)] 
BUG/MAJOR: mux-h2: don't wake streams after connection was destroyed

In commit 477902b ("MEDIUM: connections: Get ride of the xprt_done
callback.") we added an inconditional call to h2_wake_some_streams()
in h2_wake(), though we must not do it if the connection is destroyed
or we end up with a use-after-free. In this case it's already done in
h2_process() before destroying the connection anyway.

Let's just add this test for now. A cleaner approach might consist in
doing it in the h2_process() function itself when a connection status
change is detected.

No backport is needed, this is purely 2.2.

5 years agoDOC: schematic of the SSL certificates architecture
William Lallemand [Mon, 10 Feb 2020 10:43:43 +0000 (11:43 +0100)] 
DOC: schematic of the SSL certificates architecture

This patch provides a schematic of the new architecture based on the
struct cert_key_and_chain which appeared with haproxy 2.1.

Could be backported in 2.1

5 years agoBUG/MEDIUM: tcp-rules: Fix track-sc* actions for L4/L5 TCP rules
Christopher Faulet [Mon, 10 Feb 2020 08:54:49 +0000 (09:54 +0100)] 
BUG/MEDIUM: tcp-rules: Fix track-sc* actions for L4/L5 TCP rules

A bug was introduced during TCP rules refactoring by the commit ac98d81f4
("MINOR: http-rule/tcp-rules: Make track-sc* custom actions"). There is no
stream when L4/L5 TCP rules are evaluated. For these rulesets, In track-sc*
actions, we must take care to rely on the session instead of the stream.

Because of this bug, any evaluation of L4/L5 TCP rules using a track-sc* action
leads to a crash of HAProxy.

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

5 years agoBUG/MEDIUM: ssl/cli: 'commit ssl cert' wrong SSL_CTX init
William Lallemand [Fri, 7 Feb 2020 19:45:24 +0000 (20:45 +0100)] 
BUG/MEDIUM: ssl/cli: 'commit ssl cert' wrong SSL_CTX init

The code which is supposed to apply the bind_conf configuration on the
SSL_CTX was not called correctly. Indeed it was called with the previous
SSL_CTX so the new ones were left with default settings. For example the
ciphers were not changed.

This patch fixes #429.

Must be backported in 2.1.

5 years agoBUG/MINOR: http-act: Fix bugs on error path during parsing of return actions
Christopher Faulet [Fri, 7 Feb 2020 09:26:23 +0000 (10:26 +0100)] 
BUG/MINOR: http-act: Fix bugs on error path during parsing of return actions

This patch fixes memory leaks and a null pointer dereference found by coverity
on the error path when an HTTP return action is parsed. See issue #491.

No need to backport this patch except the HTT return action is backported too.

5 years agoBUG/MINOR: http-act: Set stream error flag before returning an error
Christopher Faulet [Fri, 7 Feb 2020 09:22:31 +0000 (10:22 +0100)] 
BUG/MINOR: http-act: Set stream error flag before returning an error

In action_http_set_status(), when a rewrite error occurred, the stream error
flag must be set before returning the error.

No need to backport this patch except if commit 333bf8c33 ("MINOR: http-rules:
Set SF_ERR_PRXCOND termination flag when a header rewrite fails") is
backported. This bug was reported in issue #491.

5 years agoSCRIPTS: backport: fix the master branch detection
Willy Tarreau [Fri, 7 Feb 2020 07:26:49 +0000 (08:26 +0100)] 
SCRIPTS: backport: fix the master branch detection

The condition was inverted. When the branch was the master, it was
harmless because it caused an extra "checkout master", but when it
was not the master, the commit could be applied to the wrong branch
and it could even possibly not match the name to stop on.

5 years agoSCRIPTS: announce-release: allow the user to force to overwrite old files
Willy Tarreau [Fri, 7 Feb 2020 07:11:45 +0000 (08:11 +0100)] 
SCRIPTS: announce-release: allow the user to force to overwrite old files

When starting the script multiple times, one had to remove the previous
files by hand. Now with -f it's not needed anymore, they get removed.

5 years agoSCRIPTS: announce-release: place the send command in the mail's header
Willy Tarreau [Fri, 7 Feb 2020 07:10:06 +0000 (08:10 +0100)] 
SCRIPTS: announce-release: place the send command in the mail's header

I'm fed up with having to scroll my terminals trying to look for the
mail send command printed 30 minutes before the release, let's have
it copied into the e-mail template itself, and replace the old headers
that used to be duplicated there and that are not needed anymore.

5 years ago[RELEASE] Released version 2.2-dev2 v2.2-dev2
Willy Tarreau [Fri, 7 Feb 2020 03:12:19 +0000 (04:12 +0100)] 
[RELEASE] Released version 2.2-dev2

Released version 2.2-dev2 with the following main changes :
    - BUILD: CI: temporarily mark openssl-1.0.2 as allowed failure
    - MEDIUM: cli: Allow multiple filter entries for "show table"
    - BUG/MEDIUM: netscaler: Don't forget to allocate storage for conn->src/dst.
    - BUG/MINOR: ssl: ssl_sock_load_pem_into_ckch is not consistent
    - BUILD: stick-table: fix build errors introduced by last stick-table change
    - BUG/MINOR: cli: Missing arg offset for filter data values.
    - MEDIUM: streams: Always create a conn_stream in connect_server().
    - MEDIUM: connections: Get ride of the xprt_done callback.
    - CLEANUP: changelog: remove the duplicate entry for 2.2-dev1
    - BUILD: CI: move cygwin builds to Github Actions
    - MINOR: cli: Report location of errors or any extra data for "show table"
    - BUG/MINOR: ssl/cli: free the previous ckch content once a PEM is loaded
    - CLEANUP: backend: remove useless test for inexistent connection
    - CLEANUP: backend: shut another false null-deref in back_handle_st_con()
    - CLEANUP: stats: shut up a wrong null-deref warning from gcc 9.2
    - BUG/MINOR: ssl: increment issuer refcount if in chain
    - BUG/MINOR: ssl: memory leak w/ the ocsp_issuer
    - BUG/MINOR: ssl: typo in previous patch
    - BUG/MEDIUM: connections: Set CO_FL_CONNECTED in conn_complete_session().
    - BUG/MINOR: ssl/cli: ocsp_issuer must be set w/ "set ssl cert"
    - MEDIUM: connection: remove CO_FL_CONNECTED and only rely on CO_FL_WAIT_*
    - BUG/MEDIUM: 0rtt: Only consider the SSL handshake.
    - MINOR: stream-int: always report received shutdowns
    - MINOR: connection: remove CO_FL_SSL_WAIT_HS from CO_FL_HANDSHAKE
    - MEDIUM: connection: use CO_FL_WAIT_XPRT more consistently than L4/L6/HANDSHAKE
    - MINOR: connection: remove checks for CO_FL_HANDSHAKE before I/O
    - MINOR: connection: do not check for CO_FL_SOCK_RD_SH too early
    - MINOR: connection: don't check for CO_FL_SOCK_WR_SH too early in handshakes
    - MINOR: raw-sock: always check for CO_FL_SOCK_WR_SH before sending
    - MINOR: connection: remove some unneeded checks for CO_FL_SOCK_WR_SH
    - BUG/MINOR: stktable: report the current proxy name in error messages
    - BUG/MEDIUM: mux-h2: make sure we don't emit TE headers with anything but "trailers"
    - MINOR: lua: Add hlua_prepend_path function
    - MINOR: lua: Add lua-prepend-path configuration option
    - MINOR: lua: Add HLUA_PREPEND_C?PATH build option
    - BUILD: cfgparse: silence a bogus gcc warning on 32-bit machines
    - BUG/MINOR: http-ana: Increment the backend counters on the backend
    - BUG/MINOR: stream: Be sure to have a listener to increment its counters
    - BUG/MEDIUM: streams: Move the conn_stream allocation outside #IF USE_OPENSSL.
    - REGTESTS: make the set_ssl_cert test require version 2.2
    - BUG/MINOR: ssl: Possible memleak when allowing the 0RTT data buffer.
    - MINOR: ssl: Remove dead code.
    - BUG/MEDIUM: ssl: Don't forget to free ctx->ssl on failure.
    - BUG/MEDIUM: stream: Don't install the mux in back_handle_st_con().
    - MEDIUM: streams: Don't close the connection in back_handle_st_con().
    - MEDIUM: streams: Don't close the connection in back_handle_st_rdy().
    - BUILD: CI: disable slow regtests on Travis
    - BUG/MINOR: tcpchecks: fix the connect() flags regarding delayed ack
    - BUG/MINOR: http-rules: Always init log-format expr for common HTTP actions
    - BUG/MINOR: connection: fix ip6 dst_port copy in make_proxy_line_v2
    - BUG/MINOR: dns: allow 63 char in hostname
    - MINOR: proxy: clarify number of connections log when stopping
    - DOC: word converter ignores delimiters at the start or end of input string
    - MEDIUM: raw-sock: remove obsolete calls to fd_{cant,cond,done}_{send,recv}
    - BUG/MINOR: ssl/cli: fix unused variable with openssl < 1.0.2
    - MEDIUM: pipe/thread: reduce the locking overhead
    - MEDIUM: pipe/thread: maintain a per-thread local cache of recently used pipes
    - BUG/MEDIUM: pipe/thread: fix atomicity of pipe counters
    - MINOR: tasks: move the list walking code to its own function
    - MEDIUM: tasks: implement 3 different tasklet classes with their own queues
    - MEDIUM: tasks: automatically requeue into the bulk queue an already running tasklet
    - OPTIM: task: refine task classes default CPU bandwidth ratios
    - BUG/MEDIUM: connections: Don't forget to unlock when killing a connection.
    - MINOR: task: permanently flag tasklets waking themselves up
    - MINOR: task: make sched->current also reflect tasklets
    - MINOR: task: detect self-wakeups on tl==sched->current instead of TASK_RUNNING
    - OPTIM: task: readjust CPU bandwidth distribution since last update
    - MINOR: task: don't set TASK_RUNNING on tasklets
    - BUG/MEDIUM: memory_pool: Update the seq number in pool_flush().
    - MINOR: memory: Only init the pool spinlock once.
    - BUG/MEDIUM: memory: Add a rwlock before freeing memory.
    - BUG/MAJOR: memory: Don't forget to unlock the rwlock if the pool is empty.
    - MINOR: ssl: ssl-load-extra-files configure loading of files
    - SCRIPTS: add a new "backport" script to simplify long series of backports
    - BUG/MINOR: ssl: we may only ignore the first 64 errors
    - SCRIPTS: use /usr/bin/env bash instead of /bin/bash for scripts
    - BUG/MINOR: ssl: clear the SSL errors on DH loading failure
    - CLEANUP: hpack: remove a redundant test in the decoder
    - CLEANUP: peers: Remove unused static function `free_dcache`
    - CLEANUP: peers: Remove unused static function `free_dcache_tx`
    - CONTRIB: debug: add missing flags SF_HTX and SF_MUX
    - CONTRIB: debug: add the possibility to decode the value as certain types only
    - CONTRIB: debug: support reporting multiple values at once
    - BUG/MINOR: http-act: Use the good message to test strict rewritting mode
    - MINOR: global: Set default tune.maxrewrite value during global structure init
    - MINOR: http-rules: Set SF_ERR_PRXCOND termination flag when a header rewrite fails
    - MINOR: http-htx: Emit a warning if an error file runs over the buffer's reserve
    - MINOR: htx: Add a function to append an HTX message to another one
    - MINOR: htx/channel: Add a function to copy an HTX message in a channel's buffer
    - BUG/MINOR: http-ana: Don't overwrite outgoing data when an error is reported
    - MINOR: dns: Dynamically allocate dns options to reduce the act_rule size
    - MINOR: dns: Add function to release memory allocated for a do-resolve rule
    - BUG/MINOR: http-ana: Reset HTX first index when HAPRoxy sends a response
    - BUG/MINOR: http-ana: Set HTX_FL_PROXY_RESP flag if a server perform a redirect
    - MINOR: http-rules: Add a flag on redirect rules to know the rule direction
    - MINOR: http-rules: Handle the rule direction when a redirect is evaluated
    - MINOR: http-ana: Rely on http_reply_and_close() to handle server error
    - MINOR: http-ana: Add a function for forward internal responses
    - MINOR: http-ana/http-rules: Use dedicated function to forward internal responses
    - MEDIUM: http: Add a ruleset evaluated on all responses just before forwarding
    - MEDIUM: http-rules: Add the return action to HTTP rules
    - MEDIUM: http-rules: Support extra headers for HTTP return actions
    - CLEANUP: lua: Remove consistency check for sample fetches and actions
    - BUG/MINOR: http-ana: Increment failed_resp counters on invalid response
    - MINOR: lua: Get the action return code on the stack when an action finishes
    - MINOR: lua: Create the global 'act' object to register all action return codes
    - MINOR: lua: Add act:wake_time() function to set a timeout when an action yields
    - MEDIUM: lua: Add ability for actions to intercept HTTP messages
    - REGTESTS: Add reg tests for the HTTP return action
    - REGTESTS: Add a reg test for http-after-response rulesets
    - BUILD: lua: silence a warning on systems where longjmp is not marked as noreturn
    - MINOR: acl: Warn when an ACL is named 'or'
    - CONTRIB: debug: also support reading values from stdin
    - SCRIPTS: backport: use short revs and resolve the initial commit
    - BUG/MINOR: acl: Fix type of log message when an acl is named 'or'

5 years agoBUG/MINOR: acl: Fix type of log message when an acl is named 'or'
Tim Duesterhus [Thu, 6 Feb 2020 21:04:03 +0000 (22:04 +0100)] 
BUG/MINOR: acl: Fix type of log message when an acl is named 'or'

The patch adding this check initially only issued a warning, instead of
being fatal. It was changed before committing. However when making this
change the type of the log message was not changed from `ha_warning` to
`ha-alert`. This patch makes this forgotten adjustment.

see 0cf811a5f941261176b67046dbc542d0479ff4a7
No backport needed. The initial patch was backported as a warning, thus
the log message type is correct.

5 years agoSCRIPTS: backport: use short revs and resolve the initial commit
Willy Tarreau [Thu, 6 Feb 2020 17:38:19 +0000 (18:38 +0100)] 
SCRIPTS: backport: use short revs and resolve the initial commit

I find myself often getting trapped into calling "backport 2.0 HEAD" which
doesn't work because "HEAD" is passed as the argument to cherry-pick in
other repos. Let's resolve it first. And also let's shorten the commit IDs
to make the error messages more readable and to ease copy-paste.

5 years agoCONTRIB: debug: also support reading values from stdin
Willy Tarreau [Thu, 6 Feb 2020 17:17:50 +0000 (18:17 +0100)] 
CONTRIB: debug: also support reading values from stdin

This is convenient when processing large dumps, it allows to copy-paste
values to inspect from one window to another, or to directly transfer
a "show fd"/"show stream" output through sed. In order to do this, simply
pass "-" alone instead of the value and they will all be read one line at
a time from stdin. For example, in order to quickly print the different
set of connection flags from "show fd", this is sufficient:

     sed -ne 's/^.* cflg=\([^ ]*\).*/\1/p' | contrib/debug/flags conn -

5 years agoMINOR: acl: Warn when an ACL is named 'or'
Tim Duesterhus [Wed, 5 Feb 2020 20:00:50 +0000 (21:00 +0100)] 
MINOR: acl: Warn when an ACL is named 'or'

Consider a configuration like this:

> acl t always_true
> acl or always_false
>
> http-response set-header Foo Bar if t or t

The 'or' within the condition will be treated as a logical disjunction
and the header will be set, despite the ACL 'or' being falsy.

This patch makes it an error to declare such an ACL that will never
work. This patch may be backported to stable releases, turning the
error into a warning only (the code was written in a way to make this
trivial). It should not break anything and might improve the users'
lifes.

5 years agoBUILD: lua: silence a warning on systems where longjmp is not marked as noreturn
Willy Tarreau [Thu, 6 Feb 2020 14:55:41 +0000 (15:55 +0100)] 
BUILD: lua: silence a warning on systems where longjmp is not marked as noreturn

If the longjmp() call is not flagged as "noreturn", for example, because the
operating system doesn't target a gcc-compatible compiler, we may get this
warning when building Lua :

  src/hlua.c: In function 'hlua_panic_ljmp':
  src/hlua.c:128:1: warning: no return statement in function returning non-void [-Wreturn-type]
   static int hlua_panic_ljmp(lua_State *L) { longjmp(safe_ljmp_env, 1); }
   ^~~~~~

The function's prototype cannot be changed because it must be compatible
with Lua's callbacks. Let's simply enclose the call inside WILL_LJMP()
which we created exactly to signal a call to longjmp(). It lets the compiler
know we won't get back into the function and that the return statement is
not needed.

5 years agoREGTESTS: Add a reg test for http-after-response rulesets
Christopher Faulet [Thu, 6 Feb 2020 13:27:09 +0000 (14:27 +0100)] 
REGTESTS: Add a reg test for http-after-response rulesets

A reg test has been added to ensure the evaluation of http-after-responses rules
is functionnal for all kind of responses (server, applet and internal
responses).

5 years agoREGTESTS: Add reg tests for the HTTP return action
Christopher Faulet [Wed, 5 Feb 2020 15:46:38 +0000 (16:46 +0100)] 
REGTESTS: Add reg tests for the HTTP return action

2 reg tests have been added to ensure the HTTP return action is functionnal. A
reg test is about returning error files. The other one is about returning
default responses and responses based on string or file payloads.

5 years agoMEDIUM: lua: Add ability for actions to intercept HTTP messages
Christopher Faulet [Fri, 31 Jan 2020 11:21:52 +0000 (12:21 +0100)] 
MEDIUM: lua: Add ability for actions to intercept HTTP messages

It is now possible to intercept HTTP messages from a lua action and reply to
clients. To do so, a reply object must be provided to the function
txn:done(). It may contain a status code with a reason, a header list and a
body. By default, if an empty reply object is used, an empty 200 response is
returned. If no reply is passed when txn:done() is called, the previous
behaviour is respected, the transaction is terminated and nothing is returned to
the client. The same is done for TCP streams. When txn:done() is called, the
action is terminated with the code ACT_RET_DONE on success and ACT_RET_ERR on
error, interrupting the message analysis.

The reply object may be created for the lua, by hand. Or txn:reply() may be
called. If so, this object provides some methods to fill it:

  * Reply:set_status(<status> [  <reason>]) : Set the status and optionally the
   reason. If no reason is provided, the default one corresponding to the status
   code is used.

  * Reply:add_header(<name>, <value>) : Add a header. For a given name, the
    values are stored in an ordered list.

  * Reply:del_header(<name>) : Removes all occurrences of a header name.

  * Reply:set_body(<body>) : Set the reply body.

Here are some examples, all doing the same:

    -- ex. 1
    txn:done{
        status  = 400,
        reason  = "Bad request",
        headers = {
            ["content-type"]  = { "text/html" },
            ["cache-control"] = { "no-cache", "no-store" },
        },
        body = "<html><body><h1>invalid request<h1></body></html>"
    }

    -- ex. 2
    local reply = txn:reply{
        status  = 400,
        reason  = "Bad request",
        headers = {
            ["content-type"]  = { "text/html" },
            ["cache-control"] = { "no-cache", "no-store" }
        },
        body = "<html><body><h1>invalid request<h1></body></html>"
    }
    txn:done(reply)

    -- ex. 3
    local reply = txn:reply()
    reply:set_status(400, "Bad request")
    reply:add_header("content-length", "text/html")
    reply:add_header("cache-control", "no-cache")
    reply:add_header("cache-control", "no-store")
    reply:set_body("<html><body><h1>invalid request<h1></body></html>")
    txn:done(reply)

5 years agoMINOR: lua: Add act:wake_time() function to set a timeout when an action yields
Christopher Faulet [Fri, 31 Jan 2020 18:07:52 +0000 (19:07 +0100)] 
MINOR: lua: Add act:wake_time() function to set a timeout when an action yields

This function may be used to defined a timeout when a lua action returns
act:YIELD. It is a way to force to reexecute the script after a short time
(defined in milliseconds).

Unlike core:sleep() or core:yield(), the script is fully reexecuted if it
returns act:YIELD. With core functions to yield, the script is interrupted and
restarts from the yield point. When a script returns act:YIELD, it is finished
but the message analysis is blocked on the action waiting its end.

5 years agoMINOR: lua: Create the global 'act' object to register all action return codes
Christopher Faulet [Fri, 31 Jan 2020 17:57:12 +0000 (18:57 +0100)] 
MINOR: lua: Create the global 'act' object to register all action return codes

ACT_RET_* code are now available from lua scripts. The gloabl object "act" is
used to register these codes as constant. Now, lua actions can return any of
following codes :

  * act.CONTINUE for ACT_RET_CONT
  * act.STOP for ACT_RET_STOP
  * act.YIELD for ACT_RET_YIELD
  * act.ERROR for ACT_RET_ERR
  * act.DONE for ACT_RET_DONE
  * act.DENY for ACT_RET_DENY
  * act.ABORT for ACT_RET_ABRT
  * act.INVALID for ACT_RET_INV

For instance, following script denied all requests :

  core.register_action("deny", { "http-req" }, function (txn)
      return act.DENY
  end)

Thus "http-request lua.deny" do exactly the same than "http-request deny".

5 years agoMINOR: lua: Get the action return code on the stack when an action finishes
Christopher Faulet [Wed, 29 Jan 2020 10:53:30 +0000 (11:53 +0100)] 
MINOR: lua: Get the action return code on the stack when an action finishes

When an action successfully finishes, the action return code (ACT_RET_*) is now
retrieve on the stack, ff the first element is an integer. In addition, in
hlua_txn_done(), the value ACT_RET_DONE is pushed on the stack before
exiting. Thus, when a script uses this function, the corresponding action still
finishes with the good code. Thanks to this change, the flag HLUA_STOP is now
useless. So it has been removed.

It is a mandatory step to allow a lua action to return any action return code.

5 years agoBUG/MINOR: http-ana: Increment failed_resp counters on invalid response
Christopher Faulet [Wed, 5 Feb 2020 09:16:41 +0000 (10:16 +0100)] 
BUG/MINOR: http-ana: Increment failed_resp counters on invalid response

In http_process_res_common() analyzer, when a invalid response is reported, the
failed_resp counters must be incremented.

No need to backport this patch, except if the commit b8a5371a ("MEDIUM:
http-ana: Properly handle internal processing errors") is backported too.

5 years agoCLEANUP: lua: Remove consistency check for sample fetches and actions
Christopher Faulet [Wed, 29 Jan 2020 10:51:39 +0000 (11:51 +0100)] 
CLEANUP: lua: Remove consistency check for sample fetches and actions

It is not possible anymore to alter the HTTP parser state from lua sample
fetches or lua actions. So there is no reason to still check for the parser
state consistency.

5 years agoMEDIUM: http-rules: Support extra headers for HTTP return actions
Christopher Faulet [Fri, 31 Jan 2020 16:36:01 +0000 (17:36 +0100)] 
MEDIUM: http-rules: Support extra headers for HTTP return actions

It is now possible to append extra headers to the generated responses by HTTP
return actions, while it is not based on an errorfile. For return actions based
on errorfiles, these extra headers are ignored. To define an extra header, a
"hdr" argument must be used with a name and a value. The value is a log-format
string. For instance:

  http-request status 200 hdr "x-src" "%[src]" hdr "x-dst" "%[dst]"

5 years agoMEDIUM: http-rules: Add the return action to HTTP rules
Christopher Faulet [Fri, 24 Jan 2020 16:44:23 +0000 (17:44 +0100)] 
MEDIUM: http-rules: Add the return action to HTTP rules

Thanks to this new action, it is now possible to return any responses from
HAProxy, with any status code, based on an errorfile, a file or a string. Unlike
the other internal messages generated by HAProxy, these ones are not interpreted
as errors. And it is not necessary to use a file containing a full HTTP
response, although it is still possible. In addition, using a log-format string
or a log-format file, it is possible to have responses with a dynamic
content. This action can be used on the request path or the response path. The
only constraint is to have a responses smaller than a buffer. And to avoid any
warning the buffer space reserved to the headers rewritting should also be free.

When a response is returned with a file or a string as payload, it only contains
the content-length header and the content-type header, if applicable. Here are
examples:

  http-request return content-type image/x-icon file /var/www/favicon.ico  \
      if { path /favicon.ico }

  http-request return status 403 content-type text/plain    \
      lf-string "Access denied. IP %[src] is blacklisted."  \
      if { src -f /etc/haproxy/blacklist.lst }

5 years agoMEDIUM: http: Add a ruleset evaluated on all responses just before forwarding
Christopher Faulet [Wed, 22 Jan 2020 08:26:35 +0000 (09:26 +0100)] 
MEDIUM: http: Add a ruleset evaluated on all responses just before forwarding

This patch introduces the 'http-after-response' rules. These rules are evaluated
at the end of the response analysis, just before the data forwarding, on ALL
HTTP responses, the server ones but also all responses generated by
HAProxy. Thanks to this ruleset, it is now possible for instance to add some
headers to the responses generated by the stats applet. Following actions are
supported :

   * allow
   * add-header
   * del-header
   * replace-header
   * replace-value
   * set-header
   * set-status
   * set-var
   * strict-mode
   * unset-var

5 years agoMINOR: http-ana/http-rules: Use dedicated function to forward internal responses
Christopher Faulet [Tue, 28 Jan 2020 08:28:11 +0000 (09:28 +0100)] 
MINOR: http-ana/http-rules: Use dedicated function to forward internal responses

Call http_forward_proxy_resp() function when an internal response is
returned. It concerns redirect, auth and error reponses. But also 100-Continue
and 103-Early-Hints responses. For errors, there is a subtlety. if the forward
fails, an HTTP 500 error is generated if it is not already an internal
error. For now http_forward_proxy_resp() cannot fail. But it will be possible
when the new ruleset applied on all responses will be added.

5 years agoMINOR: http-ana: Add a function for forward internal responses
Christopher Faulet [Tue, 28 Jan 2020 08:26:19 +0000 (09:26 +0100)] 
MINOR: http-ana: Add a function for forward internal responses

Operations performed when internal responses (redirect/deny/auth/errors) are
returned are always the same. The http_forward_proxy_resp() function is added to
group all of them under a unique function.

5 years agoMINOR: http-ana: Rely on http_reply_and_close() to handle server error
Christopher Faulet [Mon, 27 Jan 2020 14:32:25 +0000 (15:32 +0100)] 
MINOR: http-ana: Rely on http_reply_and_close() to handle server error

The http_server_error() function now relies on http_reply_and_close(). Both do
almost the same actions. In addtion, http_server_error() sets the error flag and
the final state flag on the stream.

5 years agoMINOR: http-rules: Handle the rule direction when a redirect is evaluated
Christopher Faulet [Tue, 28 Jan 2020 08:18:10 +0000 (09:18 +0100)] 
MINOR: http-rules: Handle the rule direction when a redirect is evaluated

The rule direction must be tested to do specific processing on the request
path. intercepted_req counter shoud be updated if the rule is evaluated on the
frontend and remaining request's analyzers must be removed. But only on the
request path. The rule direction must also be tested to set the right final
stream state flag.

This patch depends on the commit "MINOR: http-rules: Add a flag on redirect
rules to know the rule direction". Both must be backported to all stable
versions.

5 years agoMINOR: http-rules: Add a flag on redirect rules to know the rule direction
Christopher Faulet [Tue, 28 Jan 2020 08:13:41 +0000 (09:13 +0100)] 
MINOR: http-rules: Add a flag on redirect rules to know the rule direction

HTTP redirect rules can be evaluated on the request or the response path. So
when a redirect rule is evaluated, it is important to have this information
because some specific processing may be performed depending on the direction. So
the REDIRECT_FLAG_FROM_REQ flag has been added. It is set when applicable on the
redirect rule during the parsing.

This patch is mandatory to fix a bug on redirect rule. It must be backported to
all stable versions.

5 years agoBUG/MINOR: http-ana: Set HTX_FL_PROXY_RESP flag if a server perform a redirect
Christopher Faulet [Fri, 24 Jan 2020 18:16:26 +0000 (19:16 +0100)] 
BUG/MINOR: http-ana: Set HTX_FL_PROXY_RESP flag if a server perform a redirect

It is important to not forget to specify the HTX resposne was internally
generated when a server perform a redirect. This information is used by the H1
multiplexer to choose the right connexion mode when the response is sent to the
client.

This patch must be backported to 2.1.

5 years agoBUG/MINOR: http-ana: Reset HTX first index when HAPRoxy sends a response
Christopher Faulet [Fri, 24 Jan 2020 18:12:35 +0000 (19:12 +0100)] 
BUG/MINOR: http-ana: Reset HTX first index when HAPRoxy sends a response

The first index in an HTX message is the HTX block index from which the HTTP
analysis must be performed. When HAProxy sends an HTTP response, on error or
redirect, this index must be reset because all pending incoming data are
considered as forwarded. For now, it is only a bug for 103-Early-Hints
response. For other responses, it is not a problem. But it will be when the new
ruleset applied on all responses will be added. For 103 responses, if the first
index is not reset, if there are rewritting rules on server responses, the
generated 103 responses, if any, are evaluated too.

This patch must be backported and probably adapted, at least for 103 responses,
as far as 1.9.

5 years agoMINOR: dns: Add function to release memory allocated for a do-resolve rule
Christopher Faulet [Fri, 24 Jan 2020 17:12:58 +0000 (18:12 +0100)] 
MINOR: dns: Add function to release memory allocated for a do-resolve rule

Memory allocated when a do-resolve rule is parsed is now released when HAProxy
exits.

5 years agoMINOR: dns: Dynamically allocate dns options to reduce the act_rule size
Christopher Faulet [Fri, 24 Jan 2020 17:08:42 +0000 (18:08 +0100)] 
MINOR: dns: Dynamically allocate dns options to reduce the act_rule size

<.arg.dns.dns_opts> field in the act_rule structure is now dynamically allocated
when a do-resolve rule is parsed. This drastically reduces the structure size.

5 years agoBUG/MINOR: http-ana: Don't overwrite outgoing data when an error is reported
Christopher Faulet [Thu, 23 Jan 2020 10:57:31 +0000 (11:57 +0100)] 
BUG/MINOR: http-ana: Don't overwrite outgoing data when an error is reported

When an error is returned to a client, the right message is injected into the
response buffer. It is performed by http_server_error() or
http_replay_and_close(). Both ignore any data already present into the channel's
buffer. While it is legitimate to remove all input data, it is important to not
remove any outgoing data.

So now, we try to append the error message to the response buffer, only removing
input data. We rely on the channel_htx_copy_msg() function to do so. So this
patch depends on the following two commits:

  * MINOR: htx: Add a function to append an HTX message to another one
  * MINOR: htx/channel: Add a function to copy an HTX message in a channel's buffer

This patch must be backported as far as 1.9. However, above patches must be
backported first.

5 years agoMINOR: htx/channel: Add a function to copy an HTX message in a channel's buffer
Christopher Faulet [Thu, 23 Jan 2020 10:53:18 +0000 (11:53 +0100)] 
MINOR: htx/channel: Add a function to copy an HTX message in a channel's buffer

The channel_htx_copy_msg() function can now be used to copy an HTX message in a
channel's buffer. This function takes care to not overwrite existing data.

This patch depends on the commit "MINOR: htx: Add a function to append an HTX
message to another one". Both are mandatory to fix a bug in
http_reply_and_close() function. Be careful to backport both first.

5 years agoMINOR: htx: Add a function to append an HTX message to another one
Christopher Faulet [Thu, 23 Jan 2020 10:47:53 +0000 (11:47 +0100)] 
MINOR: htx: Add a function to append an HTX message to another one

the htx_append_msg() function can now be used to append an HTX message to
another one. All the message is copied or nothing. If an error occurs during the
copy, all changes are rolled back.

This patch is mandatory to fix a bug in http_reply_and_close() function. Be
careful to backport it first.

5 years agoMINOR: http-htx: Emit a warning if an error file runs over the buffer's reserve
Christopher Faulet [Wed, 22 Jan 2020 13:47:04 +0000 (14:47 +0100)] 
MINOR: http-htx: Emit a warning if an error file runs over the buffer's reserve

If an error file is too big and, once converted in HTX, runs over the buffer
space reserved to headers rewritting, a warning is emitted. Because a new set of
rules will be added to allow headers rewritting on all responses, including
HAProxy ones, it is important to always keep this space free for error files.

5 years agoMINOR: http-rules: Set SF_ERR_PRXCOND termination flag when a header rewrite fails
Christopher Faulet [Wed, 22 Jan 2020 13:38:05 +0000 (14:38 +0100)] 
MINOR: http-rules: Set SF_ERR_PRXCOND termination flag when a header rewrite fails

When a header rewrite fails, an internal errors is triggered. But
SF_ERR_INTERNAL is documented to be the concequence of a bug and must be
reported to the dev teamm. So, when this happens, the SF_ERR_PRXCOND termination
flag is set now.

5 years agoMINOR: global: Set default tune.maxrewrite value during global structure init
Christopher Faulet [Wed, 22 Jan 2020 13:31:21 +0000 (14:31 +0100)] 
MINOR: global: Set default tune.maxrewrite value during global structure init

When the global structure is initialized, instead of setting tune.maxrewrite to
-1, its default value can be immediately set. This way, it is always defined
during the configuration validity check. Otherwise, the only way to have it at
this stage, it is to explicity set it in the global section.

5 years agoBUG/MINOR: http-act: Use the good message to test strict rewritting mode
Christopher Faulet [Fri, 24 Jan 2020 14:37:13 +0000 (15:37 +0100)] 
BUG/MINOR: http-act: Use the good message to test strict rewritting mode

Since the strict rewritting mode was introduced, actions manipulating headers
(set/add/replace) always rely on the request message to test if the
HTTP_MSGF_SOFT_RW flag is set or not. But, of course, we must only rely on the
request for http-request rules. For http-response rules, we must use the
response message.

This patch must be backported if the strict rewritting is backported too.

5 years agoCONTRIB: debug: support reporting multiple values at once
Willy Tarreau [Thu, 6 Feb 2020 07:48:16 +0000 (08:48 +0100)] 
CONTRIB: debug: support reporting multiple values at once

It's often convenient, for example to dump two channels or two stream-int
at once. Now all input values are decoded and the value is recalled before
the dump when there is more than one to display.

5 years agoCONTRIB: debug: add the possibility to decode the value as certain types only
Willy Tarreau [Thu, 6 Feb 2020 07:33:08 +0000 (08:33 +0100)] 
CONTRIB: debug: add the possibility to decode the value as certain types only

It's often confusing to have a whole dump on the screen while only
checking for a set of task or stream flags, and appending "|grep ^chn"
isn't very convenient to repeat the opeation. Instead let's add the
ability to filter the output as certain types only by prepending their
name(s) before the value.

5 years agoCONTRIB: debug: add missing flags SF_HTX and SF_MUX
Willy Tarreau [Thu, 6 Feb 2020 06:57:36 +0000 (07:57 +0100)] 
CONTRIB: debug: add missing flags SF_HTX and SF_MUX

These two were forgotten when HTX was added. They can be backported
as they're missing for debugging traces in 2.0.

5 years agoCLEANUP: peers: Remove unused static function `free_dcache_tx`
Tim Duesterhus [Wed, 5 Feb 2020 22:37:15 +0000 (23:37 +0100)] 
CLEANUP: peers: Remove unused static function `free_dcache_tx`

The function was added in commit 6c39198b575444466ddfc5368e481d2a7cf8111d,
but was also used within a single function `free_dcache` which was unused
itself.

see issue #301
see commit 10ce0c2f31ba06e52edfb52176dc47986314321b which removed
`free_dcache`

5 years agoCLEANUP: peers: Remove unused static function `free_dcache`
Tim Duesterhus [Wed, 5 Feb 2020 16:22:02 +0000 (17:22 +0100)] 
CLEANUP: peers: Remove unused static function `free_dcache`

The function was changed to be static in commit
6c39198b575444466ddfc5368e481d2a7cf8111d, but even that commit
no longer uses it. The purpose of the change vs. outright removal
is unclear.

see issue #301

5 years agoCLEANUP: hpack: remove a redundant test in the decoder
Willy Tarreau [Wed, 5 Feb 2020 14:28:55 +0000 (15:28 +0100)] 
CLEANUP: hpack: remove a redundant test in the decoder

As reported in issue #485 the test for !len at the end of the
loop in get_var_int() is useless since it was already done inside
the loop. Actually the code is more readable if we remove the first
one so let's do this instead. The resulting code is exactly the same
since the compiler already optimized the test away.

5 years agoBUG/MINOR: ssl: clear the SSL errors on DH loading failure
William Lallemand [Wed, 5 Feb 2020 10:46:33 +0000 (11:46 +0100)] 
BUG/MINOR: ssl: clear the SSL errors on DH loading failure

In ssl_sock_load_dh_params(), if haproxy failed to apply the dhparam
with SSL_CTX_set_tmp_dh(), it will apply the DH with
SSL_CTX_set_dh_auto().

The problem is that we don't clean the OpenSSL errors when leaving this
function so it could fail to load the certificate, even if it's only a
warning.

Fixes bug #483.

Must be backported in 2.1.

5 years agoSCRIPTS: use /usr/bin/env bash instead of /bin/bash for scripts
Willy Tarreau [Wed, 5 Feb 2020 03:45:18 +0000 (04:45 +0100)] 
SCRIPTS: use /usr/bin/env bash instead of /bin/bash for scripts

Given that some OSes have bash in /usr/local/bin and in order not to
give too easy an excuse to Olivier for not backporting fixes, let's
make a few scripts rely on /usr/bin/env bash instead of /bin/bash :-)

5 years agoBUG/MINOR: ssl: we may only ignore the first 64 errors
Willy Tarreau [Tue, 4 Feb 2020 13:02:02 +0000 (14:02 +0100)] 
BUG/MINOR: ssl: we may only ignore the first 64 errors

We have the ability per bind option to ignore certain errors (CA, crt, ...),
and for this we use a 64-bit field. In issue #479 coverity reports a risk of
too large a left shift. For now as of OpenSSL 1.1.1 the highest error value
that may be reported by X509_STORE_CTX_get_error() seems to be around 50 so
there should be no risk yet, but it's enough of a warning to add a check so
that we don't accidently hide random errors in the future.

This may be backported to relevant stable branches.

5 years agoSCRIPTS: add a new "backport" script to simplify long series of backports
Willy Tarreau [Tue, 4 Feb 2020 12:50:36 +0000 (13:50 +0100)] 
SCRIPTS: add a new "backport" script to simplify long series of backports

The script is simply called from the repository holding the patch to
backport, with the last branch number and the commit(s) ID(s) to send
there and it then follows the chain of "down" repos to go down one step
until it meets the indicated last one. It basically automates what we do
by hand. Example:

   ./scripts/backport 1.9 1c7c0d6b97513e79c304aaf834f83843f32a674d

Note that it does *not* push, which still has to be done by hand after
building and testing.

5 years agoMINOR: ssl: ssl-load-extra-files configure loading of files
William Lallemand [Mon, 3 Feb 2020 16:15:52 +0000 (17:15 +0100)] 
MINOR: ssl: ssl-load-extra-files configure loading of files

This new setting in the global section alters the way HAProxy will look
for unspecified files (.ocsp, .sctl, .issuer, bundles) during the
loading of the SSL certificates.

By default, HAProxy discovers automatically a lot of files not specified
in the configuration, and you may want to disable this behavior if you
want to optimize the startup time.

This patch sets flags in global_ssl.extra_files and then check them
before trying to load an extra file.

5 years agoBUG/MAJOR: memory: Don't forget to unlock the rwlock if the pool is empty.
Olivier Houchard [Mon, 3 Feb 2020 12:03:30 +0000 (13:03 +0100)] 
BUG/MAJOR: memory: Don't forget to unlock the rwlock if the pool is empty.

In __pool_get_first(), don't forget to unlock the pool lock if the pool is
empty, otherwise no writer will be able to take the lock, and as it is done
when reloading, it leads to an infinite loop on reload.

This should be backported with commit 04f5fe87d3d3a222b89420f8c1231461f55ebdeb

5 years agoBUG/MEDIUM: memory: Add a rwlock before freeing memory.
Olivier Houchard [Sat, 1 Feb 2020 16:49:31 +0000 (17:49 +0100)] 
BUG/MEDIUM: memory: Add a rwlock before freeing memory.

When using lockless pools, add a new rwlock, flush_pool. read-lock it when
getting memory from the pool, so that concurrenct access are still
authorized, but write-lock it when we're about to free memory, in
pool_flush() and pool_gc().
The problem is, when removing an item from the pool, we unreference it
to get the next one, however, that pointer may have been free'd in the
meanwhile, and that could provoke a crash if the pointer has been unmapped.
It should be OK to use a rwlock, as normal operations will still be able
to access the pool concurrently, and calls to pool_flush() and pool_gc()
should be pretty rare.

This should be backported to 2.1, 2.0 and 1.9.

5 years agoMINOR: memory: Only init the pool spinlock once.
Olivier Houchard [Sat, 1 Feb 2020 16:45:32 +0000 (17:45 +0100)] 
MINOR: memory: Only init the pool spinlock once.

In pool_create(), only initialize the pool spinlock if we just created the
pool, in the event we're reusing it, there's no need to initialize it again.

5 years agoBUG/MEDIUM: memory_pool: Update the seq number in pool_flush().
Olivier Houchard [Sat, 1 Feb 2020 16:37:22 +0000 (17:37 +0100)] 
BUG/MEDIUM: memory_pool: Update the seq number in pool_flush().

In pool_flush(), we can't just set the free_list to NULL, or we may suffer
the ABA problem. Instead, use a double-width CAS and update the sequence
number.

This should be backported to 2.1, 2.0 and 1.9.
This may, or may not, be related to github issue #476.

5 years agoMINOR: task: don't set TASK_RUNNING on tasklets
Willy Tarreau [Fri, 31 Jan 2020 15:39:30 +0000 (16:39 +0100)] 
MINOR: task: don't set TASK_RUNNING on tasklets

We can't clear flags on tasklets because we don't know if they're still
present upon return (they all return NULL, maybe that could change in
the future). As a side effect, once TASK_RUNNING is set, it's never
cleared anymore, which is misleading and resulted in some incorrect
flagging of bulk tasks in the recent scheduler changes. And the only
reason for setting TASK_RUNNING on tasklets was to detect self-wakers,
which is not done using a dedicated flag. So instead of setting this
flags for no opportunity to clear it, let's simply not set it.

5 years agoOPTIM: task: readjust CPU bandwidth distribution since last update
Willy Tarreau [Fri, 31 Jan 2020 16:55:09 +0000 (17:55 +0100)] 
OPTIM: task: readjust CPU bandwidth distribution since last update

Now that we can more accurately watch which connection is really
being woken up from itself, it was desirable to re-adjust the CPU BW
thresholds based on measurements. New tests with 60000 concurrent
connections were run at 100 Gbps with unbounded queues and showed
the following distribution:

     scenario           TC0 TC1 TC2   observation
    -------------------+---+---+----+---------------------------
     TCP conn rate     : 32, 51, 17
     HTTP conn rate    : 34, 41, 25
     TCP byte rate     :  2,  3, 95   (2 MB objets)
     splicing byte rate: 11,  6, 83   (2 MB objets)
     H2 10k object     : 44, 23, 33   client-limited
     mixed traffic     : 18, 10, 72   2*1m+1*0: 11kcps, 36 Gbps

The H2 experienced a huge change since it uses a persistent connection
that was accidently flagged in the previous test. The splicing test
exhibits a higher need for short tasklets, so does the mixed traffic
test. Given that latency mainly matters for conn rate and H2 here,
the ratios were readjusted as 33% for TC0, 50% for TC1 and 17% for
TC2, keeping in mind that whatever is not consumed by one class is
automatically shared in equal propertions by the next one(s). This
setting immediately provided a nice improvement as with the default
settings (maxpollevents=200, runqueue-depth=200), the same ratios as
above are still reported, while the time to request "show activity"
on the CLI dropped to 30-50ms. The average loop time is around 5.7ms
on the mixed traffic.

In addition, one extra stress test at 90.5 Gbps with 5100 conn/s shows
70-100ms CLI request time, with an average loop time of 17 ms.

5 years agoMINOR: task: detect self-wakeups on tl==sched->current instead of TASK_RUNNING
Willy Tarreau [Fri, 31 Jan 2020 15:37:34 +0000 (16:37 +0100)] 
MINOR: task: detect self-wakeups on tl==sched->current instead of TASK_RUNNING

This is exactly what we want to detect (a task/tasklet waking itself),
so let's use the proper condition for this.

5 years agoMINOR: task: make sched->current also reflect tasklets
Willy Tarreau [Fri, 31 Jan 2020 09:39:03 +0000 (10:39 +0100)] 
MINOR: task: make sched->current also reflect tasklets

sched->current is used to know the current task/tasklet, and is currently
only used by the panic dump code. However it turns out it was not set for
tasklets, which prevents us from using it for more usages, despite the
panic handling code already handling this case very well. Let's make sure
it's now set.

5 years agoMINOR: task: permanently flag tasklets waking themselves up
Willy Tarreau [Fri, 31 Jan 2020 09:48:10 +0000 (10:48 +0100)] 
MINOR: task: permanently flag tasklets waking themselves up

Commit a17664d829 ("MEDIUM: tasks: automatically requeue into the bulk
queue an already running tasklet") tried to inflict a penalty to
self-requeuing tasks/tasklets which correspond to those involved in
large, high-latency data transfers, for the benefit of all other
processing which requires a low latency. However, it turns out that
while it ought to do this on a case-by-case basis, basing itself on
the RUNNING flag isn't accurate because this flag doesn't leave for
tasklets, so we'd rather need a distinct flag to tag such tasklets.

This commit introduces TASK_SELF_WAKING to mark tasklets acting like
this. For now it's still set when TASK_RUNNING is present but this
will have to change. The flag is kept across wakeups.

5 years agoBUG/MEDIUM: connections: Don't forget to unlock when killing a connection.
Olivier Houchard [Fri, 31 Jan 2020 16:22:08 +0000 (17:22 +0100)] 
BUG/MEDIUM: connections: Don't forget to unlock when killing a connection.

Commit 140237471e408736bb7162e68c572c710a66a526 made sure we hold the
toremove_lock for the corresponding thread before removing a connection
from its idle_orphan_conns list, however it failed to unlock it if we
found a connection, leading to a deadlock, so add the missing deadlock.

This should be backported to 2.1 and 2.0.

5 years agoOPTIM: task: refine task classes default CPU bandwidth ratios
Willy Tarreau [Fri, 31 Jan 2020 05:26:39 +0000 (06:26 +0100)] 
OPTIM: task: refine task classes default CPU bandwidth ratios

Measures with unbounded execution ratios under 40000 concurrent
connections at 100 Gbps showed the following CPU bandwidth
distribution between task classes depending on traffic scenarios:

    scenario           TC0 TC1 TC2   observation
   -------------------+---+---+----+---------------------------
    TCP conn rate     : 29, 48, 23   221 kcps
    HTTP conn rate    : 29, 47, 24   200 kcps
    TCP byte rate     :  3,  5, 92   53 Gbps
    splicing byte rate:  5, 10, 85   70 Gbps
    H2 10k object     : 10, 21, 74   client-limited
    mixed traffic     :  4,  7, 89   2*1m+1*0: 11kcps, 36 Gbps

Thus it seems that we always need a bit of bulk tasks even for short
connections, which seems to imply a suboptimal processing somewhere,
and that there are roughly twice as many tasks (TC1=normal) as regular
tasklets (TC0=urgent). This ratio stands even when data forwarding
increases. So at first glance it looks reasonable to enforce the
following ratio by default:

  - 16% for TL_URGENT
  - 33% for TL_NORMAL
  - 50% for TL_BULK

With this, the TCP conn rate climbs to ~225 kcps, and the mixed traffic
pattern shows a more balanced 17kcps + 35 Gbps with 35ms CLI request
time time instead of 11kcps + 36 Gbps and 400 ms response time. The
byte rate tests (1M objects) are not affected at all. This setting
looks "good enough" to allow immediate merging, and could be refined
later.

It's worth noting that it resists very well to massive increase of
run queue depth and maxpollevents: with the run queue depth changed
from 200 to 10000 and maxpollevents to 10000 as well, the CLI's
request time is back to the previous ~400ms, but the mixed traffic
test reaches 52 Gbps + 7500 CPS, which was never met with the previous
scheduling model, while the CLI used to show ~1 minute response time.
The reason is that in the bulk class it becomes possible to perform
multiple rounds of recv+send and eliminate objects at once, increasing
the L3 cache hit ratio, and keeping the connection count low, without
degrading too much the latency.

Another test with mixed traffic involving 2/3 splicing on huge objects
and 1/3 on empty objects without touching any setting reports 51 Gbps +
5300 cps and 35ms CLI request time.

5 years agoMEDIUM: tasks: automatically requeue into the bulk queue an already running tasklet
Willy Tarreau [Thu, 30 Jan 2020 17:59:43 +0000 (18:59 +0100)] 
MEDIUM: tasks: automatically requeue into the bulk queue an already running tasklet

When a tasklet re-runs itself such as in this chain:

   si_cs_io_cb -> si_cs_process -> si_notify -> si_chk_rcv

then we know it can easily clobber the run queue and harm latency. Now
what the scheduler does when it detects this is that such a tasklet is
automatically placed into the bulk list so that it's processed with the
remaining CPU bandwidth only. Thanks to this the CLI becomes instantly
responsive again even under heavy stress at 50 Gbps over 40kcon and
100% CPU on 16 threads.

5 years agoMEDIUM: tasks: implement 3 different tasklet classes with their own queues
Willy Tarreau [Thu, 30 Jan 2020 17:37:28 +0000 (18:37 +0100)] 
MEDIUM: tasks: implement 3 different tasklet classes with their own queues

We used to mix high latency tasks and low latency tasklets in the same
list, and to even refill bulk tasklets there, causing some unfairness
in certain situations (e.g. poll-less transfers between many connections
saturating the machine with similarly-sized in and out network interfaces).

This patch changes the mechanism to split the load into 3 lists depending
on the task/tasklet's desired classes :
  - URGENT: this is mainly for tasklets used as deferred callbacks
  - NORMAL: this is for regular tasks
  - BULK: this is for bulk tasks/tasklets

Arbitrary ratios of max_processed are picked from each of these lists in
turn, with the ability to complete in one list from what was not picked
in the previous one. After some quick tests, the following setup gave
apparently good results both for raw TCP with splicing and for H2-to-H1
request rate:

  - 0 to 75% for urgent
  - 12 to 50% for normal
  - 12 to what remains for bulk

Bulk is not used yet.

5 years agoMINOR: tasks: move the list walking code to its own function
Willy Tarreau [Thu, 30 Jan 2020 17:13:13 +0000 (18:13 +0100)] 
MINOR: tasks: move the list walking code to its own function

New function run_tasks_from_list() will run over a tasklet list and will
run all the tasks and tasklets it finds there within a limit of <max>
that is passed in arggument. This is a preliminary work for scheduler QoS
improvements.

5 years agoBUG/MEDIUM: pipe/thread: fix atomicity of pipe counters
Willy Tarreau [Thu, 30 Jan 2020 08:15:37 +0000 (09:15 +0100)] 
BUG/MEDIUM: pipe/thread: fix atomicity of pipe counters

Previous patch 160287b676 ("MEDIUM: pipe/thread: maintain a per-thread
local cache of recently used pipes") didn't replace all pipe counter
updates with atomic ops since some were already under a lock, which is
obviously not a valid reason since these ones can be updated in parallel
to other atomic ops. The result was that the pipes_used could seldom be
seen as negative in the stats (harmless) but also this could result in
slightly more pipes being allocated than permitted, thus stealing a few
file descriptors that were not usable for connections anymore. Let's use
pure atomic ops everywhere these counters are updated.

No backport is needed.

5 years agoMEDIUM: pipe/thread: maintain a per-thread local cache of recently used pipes
Willy Tarreau [Wed, 29 Jan 2020 10:05:50 +0000 (11:05 +0100)] 
MEDIUM: pipe/thread: maintain a per-thread local cache of recently used pipes

In order to completely remove the pipe locking cost and try to reuse
hot pipes, each thread now maintains a local cache of recently used pipes
that is no larger than its share (maxpipes/nbthreads). All extra pipes
are instead refilled into the global pool. Allocations are made from the
local pool first, and fall back to the global one before allocating one.
This completely removes the observed pipe locking cost at high bit rates,
which was still around 5-6%.

5 years agoMEDIUM: pipe/thread: reduce the locking overhead
Willy Tarreau [Wed, 29 Jan 2020 09:41:34 +0000 (10:41 +0100)] 
MEDIUM: pipe/thread: reduce the locking overhead

In a quick test involving splicing, we can see that get_pipe() and
put_pipe() together consume up to 12% of the CPU. That's not surprizing
considering how much work is performed under the lock, including the
pipe struct allocation, the pipe creation and its initialization. Same
for releasing, we don't need a lock there to call close() nor to free
to the pool.

Changing this alone was enough to cut the overhead in half. A better
approach should consist in having a per-thread pipe cache, which will
also help keep pages hot in the CPU caches.

5 years agoBUG/MINOR: ssl/cli: fix unused variable with openssl < 1.0.2
William Lallemand [Tue, 28 Jan 2020 23:04:24 +0000 (00:04 +0100)] 
BUG/MINOR: ssl/cli: fix unused variable with openssl < 1.0.2

src/ssl_sock.c: In function ‘cli_io_handler_show_cert’:
src/ssl_sock.c:10214:6: warning: unused variable ‘n’ [-Wunused-variable]
  int n;
      ^
Fix this problem in the io handler of the "show ssl cert" function.

5 years agoMEDIUM: raw-sock: remove obsolete calls to fd_{cant,cond,done}_{send,recv}
Willy Tarreau [Tue, 28 Jan 2020 17:51:57 +0000 (18:51 +0100)] 
MEDIUM: raw-sock: remove obsolete calls to fd_{cant,cond,done}_{send,recv}

Given that raw_sock's functions solely act on connections and that all its
callers properly use subscribe() when they want to receive/send more, there
is no more reason for calling fd_{cant,cond,done}_{send,recv} anymore as
this call is immediately overridden by the subscribe call. It's also worth
noting that the purpose of fd_cond_recv() whose purpose was to speculatively
enable reading in the FD cache if the FD was active but not yet polled was
made to save on expensive epoll_ctl() calls and was implicitly covered more
cleanly by recent commit 5d7dcc2a8e ("OPTIM: epoll: always poll for recv if
neither active nor ready").

No change on the number of calls to epoll_ctl() was noticed consecutive to
this change.

5 years agoDOC: word converter ignores delimiters at the start or end of input string
Jerome Magnin [Tue, 28 Jan 2020 12:33:44 +0000 (13:33 +0100)] 
DOC: word converter ignores delimiters at the start or end of input string

The comments for match_word() in pattern.c mention that delimiters
at the start or end of the input string will be ignored, but this
is not mentionned in the documentation.

Backport to all supported versions.