]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoBUG/MEDIUM: compression: Use the right buffer pointers to compress input data
Christopher Faulet [Mon, 17 Dec 2018 11:02:57 +0000 (12:02 +0100)] 
BUG/MEDIUM: compression: Use the right buffer pointers to compress input data

A bug was introduced when the buffers API was refactored. It was when wrapping
input data were compressed. the pointer b_peek(in, 0) was used instead of
"b_orig(in)". b_peek(in, 0) is in fact the same as b_head(in).

6 years ago[RELEASE] Released version 1.9-dev11 v1.9-dev11
Willy Tarreau [Sun, 16 Dec 2018 21:35:06 +0000 (22:35 +0100)] 
[RELEASE] Released version 1.9-dev11

Released version 1.9-dev11 with the following main changes :
    - BUG/MEDIUM: connection: Don't use the provided conn_stream if it was tried.
    - REGTEST/MINOR: remove double body specification for server txresp
    - BUG/MEDIUM: connections: Remove error flags when retrying.
    - REGTEST/MINOR: skip seamless-reload test with abns socket on freebsd
    - REGTEST/MINOR: remove health-check that can make the test fail
    - DOC: clarify that check-sni needs an argument.
    - DOC: refer to check-sni in the documentation of sni
    - BUG/MEDIUM: mux-h2: fix encoding of non-GET/POST methods
    - BUG/MINOR: mux-h1: Fix conn_mode processing for headerless outgoing messages
    - BUG/MEDIUM: mux-h1: Add a BUSY mode to not loop on pipelinned requests
    - BUG/MEDIUM: mux-h1: Don't loop on the headers parsing if the read0 was received
    - BUG/MEDIUM: htx: Always do a defrag if a block value is replace by a bigger one
    - BUG/MEDIUM: mux-h2: Don't forget to set the CS_FL_EOS flag with htx.
    - BUG/MINOR: hpack: fix off-by-one in header name encoding length calculation
    - CLEANUP: hpack: no need to include chunk.h, only include buf.h
    - MINOR: hpack: simplify the len to bytes conversion
    - MINOR: hpack: use ist2bin() to copy header names in hpack_encode_header()
    - MINOR: hpack: optimize header encoding for short names
    - CONTRIB: hpack: add a compressed stream generator for the encoder
    - MEDIUM: hpack: make it possible to encode any static header name
    - MINOR: hpack: move the length computation and encoding functions to .h
    - MINOR: hpack: provide a function to encode a short indexed header
    - MINOR: hpack: provide a function to encode a long indexed header
    - MINOR: hpack: provide new functions to encode the ":status" header
    - MEDIUM: mux-h2: make use of standard HPACK encoding functions for the status
    - MINOR: hpack: provide a function to encode an HTTP method
    - MEDIUM: mux-h2: make use of hpack_encode_method() to encode the method
    - MINOR: hpack: provide a function to encode an HTTP scheme
    - MEDIUM: mux-h2: make use of hpack_encode_scheme() to encode the scheme
    - MINOR: hpack: provide a function to encode an HTTP path
    - MEDIUM: mux-h2: make use of hpack_encode_path() to encode the path
    - REGTEST: add the HTTP rules test involving HTX processing
    - REORG: connection: centralize the conn_set_{tos,mark,quickack} functions
    - MEDIUM: cli: rework the CLI proxy parser
    - MINOR: cli: parse prompt command in the CLI proxy
    - MINOR: cli: implements 'quit' in the CLI proxy
    - BUG/MINOR: cli: wait for payload data even without prompt
    - MEDIUM: cli: handle payload in CLI proxy
    - MINOR: cli: use pcli_flags for prompt activation
    - MINOR: compression: Rename the function check_legacy_http_comp_flt()
    - MINOR: cache/htx: Don't use the same cache on HTX and legacy HTTP proxies
    - MINOR: cache: Register the cache as a data filter only if response is cacheable
    - MEDIUM: cache/htx: Add the HTX support into the cache
    - MINOR: cache: Improve and simplify the cache configuration check
    - MINOR: filters: Export the name of known filters
    - MEDIUM: cache/compression: Add a way to safely combined compression and cache
    - MEDIUM: cache: Require an explicit filter declaration if other filters are used
    - REORG: htx: merge types+proto into common/htx.h
    - REORG: http: create http_msg.c to place there some legacy HTTP parts
    - REORG: h1: move legacy http functions to http_msg.c
    - REORG: h1: move the h1_state definition to proto_http
    - CLEANUP: h1: remove some occurrences of unneeded h1.h inclusions
    - REORG: h1: merge types+proto into common/h1.h
    - CLEANUP: stream: remove SF_TUNNEL, SF_INITIALIZED, SF_CONN_TAR
    - MEDIUM: mux-h1: implement true zero-copy of DATA blocks
    - MINOR: config: round up global.tune.bufsize to the next multiple of 2 void*
    - BUG/MINOR: mux-h2: refrain from muxing during the preface
    - BUG/MINOR: mux-h2: advertise a larger connection window size
    - DOC: master CLI documentation in management.txt
    - MINOR: mux-h2: avoid copying large blocks into full buffers
    - MEDIUM: mux-h2: implement true zero-copy send of large HTX DATA blocks
    - MINOR: mux-h2: force reads to be HTX-aligned in HTX mode
    - MINOR: cli: change 'show proc' output of old processes
    - BUG/MEDIUM: mux-h1: Fix the zero-copy on output for chunked messages
    - BUG: dns: Prevent stack-exhaustion via recursion loop in dns_read_name
    - BUG: dns: Prevent out-of-bounds read in dns_read_name()
    - BUG: dns: Prevent out-of-bounds read in dns_validate_dns_response()
    - BUG: dns: Fix out-of-bounds read via signedness error in dns_validate_dns_response()
    - BUG: dns: Fix off-by-one write in dns_validate_dns_response()
    - REGTEST: the cache regtest requires haproxy 1.9
    - MEDIUM: cli: store CLI level in the appctx
    - MEDIUM: cli: show and change CLI permissions
    - CLEANUP: cli: use dedicated define instead of appctx ones
    - MEDIUM: cli: handle CLI level from the master CLI
    - BUG/MEDIUM: cli: handle correctly prefix and payload
    - BUILD: Makefile: Implements the help target
    - REGTESTS: adjust the http-rules regtest to support window updates
    - BUG/MEDIUM: connections: Remove CS_FL_EOS | CS_FL_REOS on retry.
    - BUG/MEDIUM: stream_interface: Don't report read0 if we were not connected.
    - BUG/MEDIUM: connection: Just make sure we closed the fd on connection failure.
    - MEDIUM: mux: Add an optional "reset" method.
    - BUG/MEDIUM: mux-h1: Fix loop if server closes its connection with unparsed data
    - MINOR: mux-h1: Add helper functions to wake a stream from recv or send
    - BUG/MEDIUM: mux-h1: Wake the stream for send once the connection is established
    - BUG/MEDIUM: connections: Don't attempt to reuse an unusable connection.
    - MEDIUM: htx: Try to take a connection over if it has no owner.
    - REGTEST: Reg testing improvements.
    - REGTEST: Add a first test for health-checks.
    - REGTEST: Reg test for "check" health-check option.
    - REGTEST: level 1 health-check test 2.
    - REGTEST: Add miscellaneous reg tests for health-checks.
    - REGTEST: add a few HTTP messaging tests
    - MINOR: lb: make the leastconn algorithm more accurate
    - REGTEST: fix missing space in checks/s00001
    - REGTEST: http-messaging: add "option http-buffer-request" for H2 tests
    - BUG/MEDIUM: cache: fix random crash on filter parser's error path
    - MINOR: connection: realign empty buffers in muxes, not transport layers
    - MINOR: mux_h1/h2: simplify the zero-copy Rx alignment
    - MINOR: backend: count the number of connect and reuse per server and per backend
    - BUG/MINOR: stats: fix inversion of failed header rewrites and other statuses
    - MINOR: tools: increase the number of ITOA strings to 16
    - MINOR: cache: report the number of cache lookups and cache hits
    - MEDIUM: tasks: check the global task mask instead of the thread number
    - MINOR: mworker: set all_threads_mask and pid_bit to 1
    - BUG/MINOR: proto_htx: Fix htx_res_set_status to also set the reason
    - BUG/MINOR: stats: Parse post data for HTX streams
    - MINOR: payload/htx: Adapt smp_fetch_len to be HTX aware
    - MINOR: http_fecth: Implement body_len and body_size sample fetches for the HTX
    - MAJOR: lua: Forbid calls to Channel functions for LUA scripts in HTTP proxies
    - MEDIUM: lua/htx: Adapt functions of the HTTP to be compatible with HTX
    - MINOR: lua/htx: Adapt the functions get_in_length and is_full to be HTX aware
    - MAJOR: lua/htx: Adapt HTTP applets to support HTX messages
    - MINOR: lua: Remove useless check on the messages state in HTTP functions
    - BUG/MEDIUM: htx: When performing zero-copy, start from the right offset.
    - BUG/MINOR: mworker: don't use unitialized mworker_proc struct
    - MINOR: mworker/cli: indicate in the master prompt when a reload failed
    - MINOR: cli: implements 'reload' on master CLI
    - BUG/MEDIUM: log: Don't call sample_fetch_as_type if we don't have a stream.
    - BUG/MEDIUM: mux-h1: make sure we always have at least one HTX block to send
    - BUG/MAJOR: backend: only update server's counters when the server exists
    - MINOR: tools: preset the port of fd-based "sockets" to zero
    - BUG/MINOR: log: fix logging to both FD and IP
    - REGTEST: Add a reg test for HTTP cookies.
    - BUILD: ssl: Fix compilation without deprecated OpenSSL 1.1 APIs
    - BUILD: thread: properly report multi-thread support
    - BUG/MINOR: logs: leave startup-logs global and not per-thread
    - BUG/MEDIUM: threads: don't close the thread waker pipe if not init
    - BUG/MAJOR: compression/cache: Make it really works with these both filters
    - BUG/MEDIUM: h2: Don't forget to destroy the h2s after deferred shut.
    - MEDIUM: proxy: Set http-reuse safe as default.
    - MEDIUM: servers: Add a command to limit the number of idling connections.
    - MEDIUM: servers: Replace idle-timeout with pool-purge-delay.
    - MEDIUM: mux: Destroy the stream before trying to add the conn to the idle list.
    - MEDIUM: mux: provide the session to the init() and attach() method.
    - MEDIUM: sessions: Don't keep an infinite number of idling connections.
    - MEDIUM: servers: Be more agressive when adding H2 connection to idle lists.
    - MEDIUM: mux_h2: Always set CS_FL_NOT_FIRST for new conn_streams.
    - BUG/MEDIUM: htx/cache: use the correct class of error codes on abort
    - BUG/MINOR: cache: also consider CF_SHUTR to abort delivery
    - MINOR: pools: Cast to volatile int * instead of int *.
    - MINOR: debug: make the ABORT_NOW macro use a volatile int
    - BUG/MEDIUM: h2: Don't destroy the h2s if it still has a cs attached.
    - BUG/MEDIUM: mux-h1: don't try to process an empty input buffer
    - DOC: clarify the agent-check status line syntax
    - BUG/MAJOR: hpack: fix length check for short names encoding
    - DOC: split the README into README + INSTALL

6 years agoDOC: split the README into README + INSTALL
Willy Tarreau [Sun, 16 Dec 2018 21:27:15 +0000 (22:27 +0100)] 
DOC: split the README into README + INSTALL

The README was barely usable after all the additions having accumulated
over the years. This patch introduces a new INSTALL file explaining how
to build and install haproxy with various levels of details. The README
is now mostly an index to the list of useful documentations.

6 years agoBUG/MAJOR: hpack: fix length check for short names encoding
Willy Tarreau [Sun, 16 Dec 2018 08:38:30 +0000 (09:38 +0100)] 
BUG/MAJOR: hpack: fix length check for short names encoding

Commit 19ed92b ("MINOR: hpack: optimize header encoding for short names")
introduced an error in the space computation for short names, as it removed
the length encoding from the count without replacing with 1 (the minimum
byte). This results in the last byte of the area being occasionally
overwritten, which is immediately detected with -DDEBUG_MEMORY_POOLS as
the canary at the end gets overwritten.

No backport is needed.

6 years agoDOC: clarify the agent-check status line syntax
Willy Tarreau [Sun, 16 Dec 2018 07:42:56 +0000 (08:42 +0100)] 
DOC: clarify the agent-check status line syntax

Nick Ramirez reported that the wording is confusing and lets one think
that the CR or LF are both optional, which is not the case (either is
optional). Let's reformulate this.

6 years agoBUG/MEDIUM: mux-h1: don't try to process an empty input buffer
Willy Tarreau [Sun, 16 Dec 2018 07:29:56 +0000 (08:29 +0100)] 
BUG/MEDIUM: mux-h1: don't try to process an empty input buffer

h1_process_input() may occasionally be called with an empty input
buffer, and the code behind cannot deal with that, let's check the
condition at the beginning.

No backport is needed.

6 years agoBUG/MEDIUM: h2: Don't destroy the h2s if it still has a cs attached.
Olivier Houchard [Sun, 16 Dec 2018 00:29:11 +0000 (01:29 +0100)] 
BUG/MEDIUM: h2: Don't destroy the h2s if it still has a cs attached.

In h2_deferred_shut, if we're done sending the shutr/shutw, don't destroy
the h2s if it still has a conn_stream attached, or the conn_stream may try
to access it again.

6 years agoMINOR: debug: make the ABORT_NOW macro use a volatile int
Willy Tarreau [Sun, 16 Dec 2018 07:17:23 +0000 (08:17 +0100)] 
MINOR: debug: make the ABORT_NOW macro use a volatile int

Similar to previous commit, let's make the macro use a volatile when
dereferencing NULL so that clang doesn't optimize it away.

6 years agoMINOR: pools: Cast to volatile int * instead of int *.
Olivier Houchard [Sat, 15 Dec 2018 23:58:28 +0000 (00:58 +0100)] 
MINOR: pools: Cast to volatile int * instead of int *.

When using DEBUG_MEMORY_POOLS, when we want to crash, instead of using
*(int *)0 = 0, use *(volatile int *)0 = 0, or clang will just translate it
to a nop, instead of dereferencing 0.

6 years agoBUG/MINOR: cache: also consider CF_SHUTR to abort delivery
Willy Tarreau [Sat, 15 Dec 2018 23:37:45 +0000 (00:37 +0100)] 
BUG/MINOR: cache: also consider CF_SHUTR to abort delivery

The cache runs in an applet, so it delivers data into the input side
of the channel's buffer. Thus it must also abort feeding the buffer
as soon as CF_SHUTR is present, not just CF_SHUTW*, since these last
ones may only appear later. There doesn't seem to be an observable
side effect of this bug, the fix probably doesn't even need to be
backported.

6 years agoBUG/MEDIUM: htx/cache: use the correct class of error codes on abort
Willy Tarreau [Sat, 15 Dec 2018 23:35:15 +0000 (00:35 +0100)] 
BUG/MEDIUM: htx/cache: use the correct class of error codes on abort

The HTX-specific cache code uses HTX_CACHE_* states which overlap with
the legacy HTTP states. A typo in the error handling made the state
become HTTP_CACHE_END, which equals 3 and is the value for HTX_CACHE_EOD,
which explains why we were seeing a transition to trailers and memory
corruption.

no backport needed.

6 years agoMEDIUM: mux_h2: Always set CS_FL_NOT_FIRST for new conn_streams.
Olivier Houchard [Sat, 15 Dec 2018 18:42:00 +0000 (19:42 +0100)] 
MEDIUM: mux_h2: Always set CS_FL_NOT_FIRST for new conn_streams.

When creating new conn_streams, always set the CS_FL_NOT_FIRST flag. We
don't really care about being the first request for HTTP/2, this only
really makes sense for HTTP/1, and that way we can reuse connections.

6 years agoMEDIUM: servers: Be more agressive when adding H2 connection to idle lists.
Olivier Houchard [Fri, 14 Dec 2018 18:31:51 +0000 (19:31 +0100)] 
MEDIUM: servers: Be more agressive when adding H2 connection to idle lists.

Add the newly created to the idle list as long as http-reuse != never, and
when completing a H2 request, add the connection to the safe list instead of
the idle list, if we have to add it at that point, that means we created
many streams so we know it's safe.

6 years agoMEDIUM: sessions: Don't keep an infinite number of idling connections.
Olivier Houchard [Fri, 14 Dec 2018 18:27:06 +0000 (19:27 +0100)] 
MEDIUM: sessions: Don't keep an infinite number of idling connections.

In session, don't keep an infinite number of connection that can idle.
Add a new frontend parameter, "max-session-srv-conns" to set a max number,
with a default value of 5.

6 years agoMEDIUM: mux: provide the session to the init() and attach() method.
Olivier Houchard [Fri, 14 Dec 2018 18:42:40 +0000 (19:42 +0100)] 
MEDIUM: mux: provide the session to the init() and attach() method.

Instead of trying to get the session from the connection, which is not
always there, and of course there could be multiple sessions per connection,
provide it with the init() and attach() methods, so that we know the
session for each outgoing stream.

6 years agoMEDIUM: mux: Destroy the stream before trying to add the conn to the idle list.
Olivier Houchard [Sat, 15 Dec 2018 15:05:40 +0000 (16:05 +0100)] 
MEDIUM: mux: Destroy the stream before trying to add the conn to the idle list.

In the mux_h1 and mux_h2, move the test to see if we should add the
connection in the idle list until after we destroyed the h1s/h2s, that way
later we'll be able to check if the connection has no stream at all, and if
it should be added to the server idling list.

6 years agoMEDIUM: servers: Replace idle-timeout with pool-purge-delay.
Olivier Houchard [Fri, 14 Dec 2018 17:15:36 +0000 (18:15 +0100)] 
MEDIUM: servers: Replace idle-timeout with pool-purge-delay.

Instead of the old "idle-timeout" mechanism, add a new option,
"pool-purge-delay", that sets the delay before purging idle connections.
Each time the delay happens, we destroy half of the idle connections.

6 years agoMEDIUM: servers: Add a command to limit the number of idling connections.
Olivier Houchard [Mon, 10 Dec 2018 17:30:32 +0000 (18:30 +0100)] 
MEDIUM: servers: Add a command to limit the number of idling connections.

Add a new command, "pool-max-conn" that sets the maximum number of connections
waiting in the orphan idling connections list (as activated with idle-timeout).
Using "-1" means unlimited. Using pools is now dependant on this.

6 years agoMEDIUM: proxy: Set http-reuse safe as default.
Olivier Houchard [Fri, 14 Dec 2018 18:37:49 +0000 (19:37 +0100)] 
MEDIUM: proxy: Set http-reuse safe as default.

Change the default for http-reuse from "never" to "safe", as it has been
the recommended setting for a few versions now and backend H2 makes little
sense without it.

Some warnings were removed from the config parser since it can dynamically
be disabled depending on the server's configuration, so there's no need to
disable it on a whole backend just for one server.

6 years agoBUG/MEDIUM: h2: Don't forget to destroy the h2s after deferred shut.
Olivier Houchard [Sat, 15 Dec 2018 21:42:20 +0000 (22:42 +0100)] 
BUG/MEDIUM: h2: Don't forget to destroy the h2s after deferred shut.

If we had to defer shutr/shutw, and we're now done, destroy the h2s, or
nobody will do so.

6 years agoBUG/MAJOR: compression/cache: Make it really works with these both filters
Christopher Faulet [Sat, 15 Dec 2018 21:32:02 +0000 (22:32 +0100)] 
BUG/MAJOR: compression/cache: Make it really works with these both filters

Caching the response with the compression enabled was totally broken. To fix the
problem, the compression must be done after caching the response. Otherwise it
needs to change the cache to store compressed and uncompressed objects for the
same ressource. So, because it is not possible for now, it is forbidden to
declare the compression filter before the cache one. To ease the configuration,
both can be implicitly declared (without "filter" keyword). The compression will
automatically be inserted after the cache.

Then, to make it works this way, the compression filter has been slighly
modified. Now, the response headers are updated after http-response rules
evaluations, instead of before. So, if the response contains a "Content-length"
header, it will be kept with the response stored in the cache. So this cached
response will be able to be served to clients not supporting the compression at
all.

6 years agoBUG/MEDIUM: threads: don't close the thread waker pipe if not init
William Lallemand [Sat, 15 Dec 2018 21:34:31 +0000 (22:34 +0100)] 
BUG/MEDIUM: threads: don't close the thread waker pipe if not init

This bugfix concerns the thread deinit but affects the master process.

When the master process falls in wait mode (it fails to reload the
configuration), it launches the deinit_pollers_per_thread and close the
thread waker pipe. It closes rd (-1) and wr (0).

Closing a FD in the master can have several sides effects and the
process will probably quit at some point.

In this case it assigns 0 to the socketpair of a worker during the next
correct reload, and then closes the socketpair once it falls in wait
mode again. The worker assumes that the master died and leaves.

6 years agoBUG/MINOR: logs: leave startup-logs global and not per-thread
Willy Tarreau [Sat, 15 Dec 2018 15:55:36 +0000 (16:55 +0100)] 
BUG/MINOR: logs: leave startup-logs global and not per-thread

Commit f8188c6 ("MEDIUM: threads/logs: Make logs thread-safe") made logs
thread-local but it also made the copy of the startup-logs thread-local,
meaning that when threads are configured, upon startup the list of startup
logs appears to be empty. Let's just remove the THEAD_LOCAL directive
there, as the check for the startup period is already present.

This fix should be backported to 1.8.

6 years agoBUILD: thread: properly report multi-thread support
Willy Tarreau [Sat, 15 Dec 2018 15:48:14 +0000 (16:48 +0100)] 
BUILD: thread: properly report multi-thread support

When refactoring the build option strings in 1.9, the thread support
was placed outside of the ifdef block resulting in threads always being
mentioned even if that was not true. Let's fix this and also mention
when threads are disabled to help troubleshooting.

6 years agoBUILD: ssl: Fix compilation without deprecated OpenSSL 1.1 APIs
Rosen Penev [Fri, 14 Dec 2018 16:47:02 +0000 (08:47 -0800)] 
BUILD: ssl: Fix compilation without deprecated OpenSSL 1.1 APIs

Removing deprecated APIs is an optional part of OpenWrt's build system to
save some space on embedded devices.

Also added compatibility for LibreSSL.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
6 years agoREGTEST: Add a reg test for HTTP cookies.
Frédéric Lécaille [Fri, 14 Dec 2018 19:07:57 +0000 (20:07 +0100)] 
REGTEST: Add a reg test for HTTP cookies.

This script tests the "cookie <name> insert indirect" directive with
header checks on server and client side. syslog messages are also
checked, especially --II (invalid, insert) flags logging.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoBUG/MINOR: log: fix logging to both FD and IP
Willy Tarreau [Sat, 15 Dec 2018 14:48:48 +0000 (15:48 +0100)] 
BUG/MINOR: log: fix logging to both FD and IP

PiBa-NL reported an issue affecting logs when stdout is enabled at the
same time as an IP address. It does not affect FD and UNIX, but does
still affect multiple FDs. What happens is that the condition to detect
that the initialization was not made relies on the FD being -1, and in
this case the FD points to the *unique* FD used for AF_INET sockets, so
the configured socket used for outgoing logs over UDP gets overwritten
by the last configured FD. This is not appropriate, so instead we rely
on the sin_port part of the IPv4-mapped address to store the
initialization state for each FD.

This part deserves being significantly revamped, as IPv6 is still not
possible due to the way the FDs are managed, and inherited FDs are a
bit hackish.

Note that this patch relies on "MINOR: tools: preset the port of
fd-based "sockets" to zero" in order to operate properly.

No backport is needed.

6 years agoMINOR: tools: preset the port of fd-based "sockets" to zero
Willy Tarreau [Sat, 15 Dec 2018 14:40:12 +0000 (15:40 +0100)] 
MINOR: tools: preset the port of fd-based "sockets" to zero

Addresses made of a file descriptor store the file descriptor into the
address part of a sin_addr. Contrary to other address classes, there's
no way to figure later based on the FD if an initialization was done
(which is how logs initialize their FDs). The port part is currently
left with random data, so let's instead specifically set the port part
to zero when creating an FD, and let the code using it set whatever
info it needs there, typically an initialization state.

6 years agoBUG/MAJOR: backend: only update server's counters when the server exists
Willy Tarreau [Sat, 15 Dec 2018 14:11:36 +0000 (15:11 +0100)] 
BUG/MAJOR: backend: only update server's counters when the server exists

PiBa-NL reported that since this commit f157384 ("MINOR: backend: count
the number of connect and reuse per server and per backend"), reg-test
connection/h00001 fails. Indeed it does, the server is not checked for
existing prior to updating its counter. It should also fail with
transparent mode.

6 years agoBUG/MEDIUM: mux-h1: make sure we always have at least one HTX block to send
Willy Tarreau [Sat, 15 Dec 2018 13:48:31 +0000 (14:48 +0100)] 
BUG/MEDIUM: mux-h1: make sure we always have at least one HTX block to send

Commit 84cca66 ("BUG/MEDIUM: htx: When performing zero-copy, start from
the right offset.") uncovered another issue which is that the send function
may occasionally be called without any block. It's important to check for
this case when computing the zero-copy offsets.

No backport is needed.

6 years agoBUG/MEDIUM: log: Don't call sample_fetch_as_type if we don't have a stream.
Olivier Houchard [Sat, 15 Dec 2018 13:00:06 +0000 (14:00 +0100)] 
BUG/MEDIUM: log: Don't call sample_fetch_as_type if we don't have a stream.

In sess_build_logline(), don't attempt to call sample_fetch_as_type()
if we don't have a stream.

It used never to happen in the past before commit 09bb27c ("MEDIUM: log:
make sess_build_logline() support being called with no stream"). But now
it can happen when sess_log() is called from the lower layers (i.e. the
H2 mux got garbage when it was expecting a preface frame), and it reveals
that some sample fetch functions and some converter fnuctions which rely
on the stream don't test for its existence. For the sample fetch functions,
a durable solution is easy and would consist in adapting sample_process()
to verify the SMP_USE_* bits when the stream is not set. But for the
converters we don't have this option as they don't declare whether or not
they use a stream (which possibly is the real issue).

Thus for now let's disable sample_fetch_as_type() if a stream does not
exist, until it can be more accurately refined later.

6 years agoMINOR: cli: implements 'reload' on master CLI
William Lallemand [Fri, 14 Dec 2018 20:11:31 +0000 (21:11 +0100)] 
MINOR: cli: implements 'reload' on master CLI

The reload command reload the haproxy master like it is done with a kill
-USR2 on the master process.

6 years agoMINOR: mworker/cli: indicate in the master prompt when a reload failed
Willy Tarreau [Sat, 15 Dec 2018 12:30:03 +0000 (13:30 +0100)] 
MINOR: mworker/cli: indicate in the master prompt when a reload failed

If a reload was issued to the master process and failed, it is critical
that the admin sees it because it means that the saved configuration
does not work anymore and might not be usable after a full restart. For
this reason in this case we modify the "master" prompt to explicitly
indicate that a reload failed.

6 years agoBUG/MINOR: mworker: don't use unitialized mworker_proc struct
William Lallemand [Fri, 14 Dec 2018 18:31:21 +0000 (19:31 +0100)] 
BUG/MINOR: mworker: don't use unitialized mworker_proc struct

If the reload fail after the parsing of the configuration, the
mworker_proc structures are created for the processes it tried to
create.

The mworker_proc_list_to_env() function was exporting these unitialized
structures in the "HAPROXY_PROCESSES" environment variable which was
leading to this kind of output in "show proc":

4294967295      worker          [was: 1]        1               17879d 16h26m28s

6 years agoBUG/MEDIUM: htx: When performing zero-copy, start from the right offset.
Olivier Houchard [Fri, 14 Dec 2018 15:28:08 +0000 (16:28 +0100)] 
BUG/MEDIUM: htx: When performing zero-copy, start from the right offset.

When using zerocopy, start from the beginning of the data, not from the
beginning of the buffer, it may have contained headers, and so the data
won't start at the beginning of the buffer.

6 years agoMINOR: lua: Remove useless check on the messages state in HTTP functions
Christopher Faulet [Fri, 14 Dec 2018 12:37:54 +0000 (13:37 +0100)] 
MINOR: lua: Remove useless check on the messages state in HTTP functions

The headers parsing is always finished when LUA scripts are evaluated.

6 years agoMAJOR: lua/htx: Adapt HTTP applets to support HTX messages
Christopher Faulet [Fri, 14 Dec 2018 12:34:05 +0000 (13:34 +0100)] 
MAJOR: lua/htx: Adapt HTTP applets to support HTX messages

This patch is a bit huge but nothing special here. Some functions have been
duplicated to support the HTX, some others have a switch inside to do so. So,
now, it is possible to create HTTP applets from HTX proxies. However, TCP
applets remains unsupported.

6 years agoMINOR: lua/htx: Adapt the functions get_in_length and is_full to be HTX aware
Christopher Faulet [Fri, 14 Dec 2018 12:39:09 +0000 (13:39 +0100)] 
MINOR: lua/htx: Adapt the functions get_in_length and is_full to be HTX aware

6 years agoMEDIUM: lua/htx: Adapt functions of the HTTP to be compatible with HTX
Christopher Faulet [Thu, 13 Dec 2018 21:12:15 +0000 (22:12 +0100)] 
MEDIUM: lua/htx: Adapt functions of the HTTP to be compatible with HTX

So, LUA actions, converter and sample fetches are now available from HTX
proxies.

6 years agoMAJOR: lua: Forbid calls to Channel functions for LUA scripts in HTTP proxies
Christopher Faulet [Thu, 13 Dec 2018 20:56:45 +0000 (21:56 +0100)] 
MAJOR: lua: Forbid calls to Channel functions for LUA scripts in HTTP proxies

Functions from then Channel class are now forbidden for LUA scripts called from
HTTP proxies. These functions totally hijacked the HTTP parser, leaving it in an
undefined state. This patch is tagged as MAJOR because it could be see as a
compatibility breakage. But a LUA script using one of these functions has a very
low probablity to work correctly except by chance.

So, concretely, following functions are concerned: Channel.get, Channel.dup,
Channel.getline, Channel.set, Channel.append, Channel.send,
Channel.forward. Others remain available.

6 years agoMINOR: http_fecth: Implement body_len and body_size sample fetches for the HTX
Christopher Faulet [Wed, 12 Dec 2018 13:11:22 +0000 (14:11 +0100)] 
MINOR: http_fecth: Implement body_len and body_size sample fetches for the HTX

HTX implementation for these 2 sample fetches was missing. This patch fills this
gap.

6 years agoMINOR: payload/htx: Adapt smp_fetch_len to be HTX aware
Christopher Faulet [Fri, 14 Dec 2018 12:44:53 +0000 (13:44 +0100)] 
MINOR: payload/htx: Adapt smp_fetch_len to be HTX aware

6 years agoBUG/MINOR: stats: Parse post data for HTX streams
Christopher Faulet [Thu, 13 Dec 2018 20:59:56 +0000 (21:59 +0100)] 
BUG/MINOR: stats: Parse post data for HTX streams

This part was just left out for no reason when the stats applet was adapted to
support the HTX messages.

6 years agoBUG/MINOR: proto_htx: Fix htx_res_set_status to also set the reason
Christopher Faulet [Thu, 13 Dec 2018 20:58:18 +0000 (21:58 +0100)] 
BUG/MINOR: proto_htx: Fix htx_res_set_status to also set the reason

Becaue the check on the return value of the function http_replace_res_status was
done upside down, no reason was never set.

6 years agoMINOR: mworker: set all_threads_mask and pid_bit to 1
William Lallemand [Fri, 14 Dec 2018 14:52:39 +0000 (15:52 +0100)] 
MINOR: mworker: set all_threads_mask and pid_bit to 1

Reinit the all_threads_mask and pid_bit to 1 before the master polling
loop, this process is monothread.

6 years agoMEDIUM: tasks: check the global task mask instead of the thread number
Willy Tarreau [Fri, 14 Dec 2018 14:49:45 +0000 (15:49 +0100)] 
MEDIUM: tasks: check the global task mask instead of the thread number

When deciding whether to scan the global run queue or not, we currently
check the configured threads number, and if it's 1 we skip the queue
since it's not supposed to be used. However when running with a master
process and multiple threads in the workers, the master will turn this
number back to 1 while some task wakeups might possibly have set bits
in the global tasks mask, thus causing active_tasks_mask to have one
bit permanently set, preventing the process from sleeping.

Instead of checking global.nbthread, let's check for the current
thread's bit in global_tasks_mask. First it will make this part of the
code more consistent, working like a test and set operation, it will
solve the issue with master+nbthread and as a bonus it will save a
lock/unlock for each scheduler call when the thread doesn't have a
task in the global run queue.

6 years agoMINOR: cache: report the number of cache lookups and cache hits
Willy Tarreau [Fri, 14 Dec 2018 13:00:25 +0000 (14:00 +0100)] 
MINOR: cache: report the number of cache lookups and cache hits

The cache lookups and hits is now accounted per frontend and per backend,
and reported on the stats page.

6 years agoMINOR: tools: increase the number of ITOA strings to 16
Willy Tarreau [Fri, 14 Dec 2018 12:59:42 +0000 (13:59 +0100)] 
MINOR: tools: increase the number of ITOA strings to 16

It's currently 10 and is too little to extend some tooltips on the stats page.

6 years agoBUG/MINOR: stats: fix inversion of failed header rewrites and other statuses
Willy Tarreau [Fri, 14 Dec 2018 12:48:44 +0000 (13:48 +0100)] 
BUG/MINOR: stats: fix inversion of failed header rewrites and other statuses

The tooltip in the HTML stats page was damaged by commit 1b0f85e47 ("MINOR:
stats: also report the failed header rewrites warnings on the stats page"),
due to the header rewrites counter being inserted at the wrong place and
taking the place of the other statuses.

This is only for 1.9, no backport is needed.

6 years agoMINOR: backend: count the number of connect and reuse per server and per backend
Willy Tarreau [Fri, 14 Dec 2018 10:35:36 +0000 (11:35 +0100)] 
MINOR: backend: count the number of connect and reuse per server and per backend

Sadly we didn't have the cumulated number of connections established to
servers till now, so let's now update it per backend and per-server and
report it in the stats. On the stats page it appears in the tooltip
when hovering over the total sessions count field.

6 years agoMINOR: mux_h1/h2: simplify the zero-copy Rx alignment
Willy Tarreau [Fri, 14 Dec 2018 09:59:15 +0000 (10:59 +0100)] 
MINOR: mux_h1/h2: simplify the zero-copy Rx alignment

The transpory layer now respects buffer alignment, so we don't need to
cheat anymore pretending we have some data at the head, adjusting the
buffer's head is enough.

6 years agoMINOR: connection: realign empty buffers in muxes, not transport layers
Willy Tarreau [Fri, 14 Dec 2018 09:51:23 +0000 (10:51 +0100)] 
MINOR: connection: realign empty buffers in muxes, not transport layers

For a long time we've been realigning empty buffers in the transport
layers, where the I/Os were performed based on callbacks. Doing so is
optimal for higher data throughput but makes it trickier to optimize
unaligned data, where mux_h1/h2 have to claim some data are present
in the buffer to force unaligned accesses to skip the frame's header
or the chunk header.

We don't need to do this anymore since the I/O calls are now always
performed from top to bottom, so it's only the mux's responsibility
to realign an empty buffer if it wants to.

In practice it doesn't change anything, it's just a convention, and
it will allow the code to be simplified in a next patch.

6 years agoBUG/MEDIUM: cache: fix random crash on filter parser's error path
Willy Tarreau [Fri, 14 Dec 2018 09:19:28 +0000 (10:19 +0100)] 
BUG/MEDIUM: cache: fix random crash on filter parser's error path

The cconf variable was not initialized before the two first possible
error exits before being freed, resulting in random crashes instead
of displaying an error message if the cache ID was missing from the
filter declaration.

No backport is needed, this is exclusively 1.9.

6 years agoREGTEST: http-messaging: add "option http-buffer-request" for H2 tests
Willy Tarreau [Fri, 14 Dec 2018 08:51:48 +0000 (09:51 +0100)] 
REGTEST: http-messaging: add "option http-buffer-request" for H2 tests

These tests upload contents and randomly make the server start to
respond before the client finishes to upload data, making the test
occasionally fail. Waiting for a body in the server doesn't always
work, depending on the method or how the data are advertised. Thus,
let's ask haproxy to wait for the request using the aforementioned
option, it guarantees that the DATA frame is sent before the response
HEADERS frame is delivered.

6 years agoREGTEST: fix missing space in checks/s00001
Willy Tarreau [Fri, 14 Dec 2018 08:49:19 +0000 (09:49 +0100)] 
REGTEST: fix missing space in checks/s00001

I accidently dropped one space when fixing this 3k-long line in the
VTC script, causing the test to fail.

6 years agoMINOR: lb: make the leastconn algorithm more accurate
Willy Tarreau [Fri, 14 Dec 2018 07:33:28 +0000 (08:33 +0100)] 
MINOR: lb: make the leastconn algorithm more accurate

The leastconn algorithm queues available servers based on their weighted
current load. But this results in an inaccurate load balancing when weights
differ and the load is very low, because what matters is not the load before
picking the server but the load resulting from picking the server. At the
very least, it must be granted that servers with the highest weight are
always picked first when no server has any connection.

This patch addresses this by simply adding one to the current connections
count when queuing the server, since this is the load the server will have
once picked. This finally allows to bridge the gap that existed between
the "leastconn" and the "first" algorithms.

6 years agoREGTEST: add a few HTTP messaging tests
Willy Tarreau [Thu, 13 Dec 2018 18:35:29 +0000 (19:35 +0100)] 
REGTEST: add a few HTTP messaging tests

These tests send GET/HEAD/POST requests in H1 and H2, with and without
HTX, with and without a body, and verify that the behaviour is the expected
one. For now HEAD requests have been commented out because in H1 they are
not really testable as varnishtest expects to read a body, and in H2 the
behaviour depends on HTX/legacy, indicating a bug in haproxy (it looks
like we can deliver some data in response to HEAD in legacy mode).

6 years agoREGTEST: Add miscellaneous reg tests for health-checks.
Frederic Lecaille [Thu, 13 Dec 2018 21:15:09 +0000 (22:15 +0100)] 
REGTEST: Add miscellaneous reg tests for health-checks.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoREGTEST: level 1 health-check test 2.
Frederic Lecaille [Thu, 13 Dec 2018 21:15:08 +0000 (22:15 +0100)] 
REGTEST: level 1 health-check test 2.

With this test we check that the health-checks do not consume any connection on
the backend side.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoREGTEST: Reg test for "check" health-check option.
Frederic Lecaille [Thu, 13 Dec 2018 21:15:07 +0000 (22:15 +0100)] 
REGTEST: Reg test for "check" health-check option.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoREGTEST: Add a first test for health-checks.
Frederic Lecaille [Thu, 13 Dec 2018 21:15:06 +0000 (22:15 +0100)] 
REGTEST: Add a first test for health-checks.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoREGTEST: Reg testing improvements.
Frederic Lecaille [Thu, 13 Dec 2018 21:15:05 +0000 (22:15 +0100)] 
REGTEST: Reg testing improvements.

Add a new target to the Makefile named "reg-tests-help" to have an idea
about how to run the reg tests from haproxy Makefile.
Handle list of levels and lists of level range passed to make with LEVEL variable.
New supported syntax:
    LEVEL=1,4     make reg-tests
    LEVEL=1-2,5-6 make reg-tests
Add two new levels 5 and 6. 5 is for broken script, 6 for experimental scripts.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoMEDIUM: htx: Try to take a connection over if it has no owner.
Olivier Houchard [Thu, 13 Dec 2018 17:46:22 +0000 (18:46 +0100)] 
MEDIUM: htx: Try to take a connection over if it has no owner.

In the mux detach function, when using HTX, take the connection over if
it no longer has an owner (ie because the session that was the owner left).
It is done for legacy code in proto_http.c, but not for HTX.
Also when using HTX, in H2, try to add the connection back to idle_conns if
it was not already (ie we used to use all the available streams, and we're
freeing one). That too was done in proto_http.c.

6 years agoBUG/MEDIUM: connections: Don't attempt to reuse an unusable connection.
Olivier Houchard [Thu, 13 Dec 2018 17:01:00 +0000 (18:01 +0100)] 
BUG/MEDIUM: connections: Don't attempt to reuse an unusable connection.

Before trying to add a connection to the idle list, make sure it doesn't
have the error, the shutr or the shutw flag. If any of them is present,
don't bother trying to recycle the connection, it's going to be destroyed
anyway.

6 years agoBUG/MEDIUM: mux-h1: Wake the stream for send once the connection is established
Christopher Faulet [Tue, 11 Dec 2018 15:26:50 +0000 (16:26 +0100)] 
BUG/MEDIUM: mux-h1: Wake the stream for send once the connection is established

We must do that to let the connection retry working. Otherwise, the stream never
retry to send its data once the connection is established.

6 years agoMINOR: mux-h1: Add helper functions to wake a stream from recv or send
Christopher Faulet [Tue, 11 Dec 2018 15:25:36 +0000 (16:25 +0100)] 
MINOR: mux-h1: Add helper functions to wake a stream from recv or send

This will avoid code duplication.

6 years agoBUG/MEDIUM: mux-h1: Fix loop if server closes its connection with unparsed data
Christopher Faulet [Tue, 11 Dec 2018 15:12:31 +0000 (16:12 +0100)] 
BUG/MEDIUM: mux-h1: Fix loop if server closes its connection with unparsed data

A first patch was pushed to fix this bug if it happens during the headers
parsing. But it is also possible to hit the bug during the parsing of
chunks. For instance, if the server sends only part of the trailers, some data
remains unparsed. So it the server closes its connection without sending the end
of the response, we fall back again into an infinite loop.

The fix contains in 2 parts. First, we block the receive if a read0 or an error
is detected on the connection, independently if the input buffer is empty or
not. Then, the flags CS_FL_RCV_MORE and CL_FL_WANT_ROOM are always reset when
input data are processed. We set them again only when necessary.

6 years agoMEDIUM: mux: Add an optional "reset" method.
Olivier Houchard [Tue, 11 Dec 2018 15:47:14 +0000 (16:47 +0100)] 
MEDIUM: mux: Add an optional "reset" method.

Add a new method to mux, "reset", that is used to let the mux know the
connection attempt failed, and we're about to retry, so it just have to
reinit itself. Currently only the H1 mux needs it.

6 years agoBUG/MEDIUM: connection: Just make sure we closed the fd on connection failure.
Olivier Houchard [Thu, 13 Dec 2018 14:40:16 +0000 (15:40 +0100)] 
BUG/MEDIUM: connection: Just make sure we closed the fd on connection failure.

When the connection failed, we don't really want to close the conn_stream,
as we're probably about to retry, so just make sure the file descriptor is
closed.

6 years agoBUG/MEDIUM: stream_interface: Don't report read0 if we were not connected.
Olivier Houchard [Thu, 13 Dec 2018 14:38:16 +0000 (15:38 +0100)] 
BUG/MEDIUM: stream_interface: Don't report read0 if we were not connected.

In si_cs_recv(), report that arrive at the end of stream only if we were
indeed connected, we don't want that if the connection failed and we're about
to retry.

6 years agoBUG/MEDIUM: connections: Remove CS_FL_EOS | CS_FL_REOS on retry.
Olivier Houchard [Thu, 13 Dec 2018 14:37:25 +0000 (15:37 +0100)] 
BUG/MEDIUM: connections: Remove CS_FL_EOS | CS_FL_REOS on retry.

CS_FL_EOS | CS_FL_REOS can be set by the mux if the connection failed, so make
sure we remove them before retrying to connect, or it may lead to a premature
close of the connection.

6 years agoREGTESTS: adjust the http-rules regtest to support window updates
Willy Tarreau [Thu, 13 Dec 2018 16:29:20 +0000 (17:29 +0100)] 
REGTESTS: adjust the http-rules regtest to support window updates

Varnishtest is not happy to see the window update come before the
settings ACK, as by default it expects exactly tx/rx/txack/rxack.
One workaround could consist in making haproxy send the WU after
the settings ACK but this would be a real hack as the preface is
already finished when sending this ack. Instead, let's make the
initial sequence explicit in the tests.

6 years agoBUILD: Makefile: Implements the help target
William Lallemand [Thu, 13 Dec 2018 13:02:25 +0000 (14:02 +0100)] 
BUILD: Makefile: Implements the help target

Use the header of the Makefile to output the help target.

6 years agoBUG/MEDIUM: cli: handle correctly prefix and payload
William Lallemand [Thu, 13 Dec 2018 08:05:48 +0000 (09:05 +0100)] 
BUG/MEDIUM: cli: handle correctly prefix and payload

In the master CLI, the commands and the prefix were still parsed and
trimmed after the pattern payload. Don't parse anything but the end of a
line till we are in payload mode.

Put the search of the pattern after the trim so we can use correctly a
payload with a command which is prefixed by @.

6 years agoMEDIUM: cli: handle CLI level from the master CLI
William Lallemand [Thu, 13 Dec 2018 08:05:47 +0000 (09:05 +0100)] 
MEDIUM: cli: handle CLI level from the master CLI

Handle the CLI level in the master CLI. In order to do this, the master
CLI stores the level in the stream. Each command are prefixed by a
"user" or "operator" command before they are forwarded to the target
CLI.

The level can be configured in the haproxy program arguments with the
level keyword: -S /tmp/sock,level,admin -S /tmp/sock2,level,user.

6 years agoCLEANUP: cli: use dedicated define instead of appctx ones
William Lallemand [Thu, 13 Dec 2018 08:05:46 +0000 (09:05 +0100)] 
CLEANUP: cli: use dedicated define instead of appctx ones

Replace APPCTX_CLI_ST1_PAYLOAD and APPCTX_CLI_ST1_PROMPT by
PCLI_F_PAYLOAD and PCLI_F_PROMPT in the master CLI code.

6 years agoMEDIUM: cli: show and change CLI permissions
William Lallemand [Thu, 13 Dec 2018 08:05:45 +0000 (09:05 +0100)] 
MEDIUM: cli: show and change CLI permissions

Implement "show cli level" which show the level of the current CLI
session.

Implement "operator" and "user" which lower the permissions of the
current CLI session.

6 years agoMEDIUM: cli: store CLI level in the appctx
William Lallemand [Thu, 13 Dec 2018 08:05:44 +0000 (09:05 +0100)] 
MEDIUM: cli: store CLI level in the appctx

Store and check the level in the appctx in order to allow dynamic
permission changes over the CLI.

6 years agoREGTEST: the cache regtest requires haproxy 1.9
Willy Tarreau [Wed, 12 Dec 2018 14:21:56 +0000 (15:21 +0100)] 
REGTEST: the cache regtest requires haproxy 1.9

The chunks and the max-object-size features require version 1.9.

6 years agoBUG: dns: Fix off-by-one write in dns_validate_dns_response()
Remi Gacogne [Wed, 5 Dec 2018 16:59:56 +0000 (17:59 +0100)] 
BUG: dns: Fix off-by-one write in dns_validate_dns_response()

The maximum number of bytes in a DNS name is indeed 255, but we
need to allocate one more byte for the NULL-terminating byte.
Otherwise dns_read_name() might return 255 for a very long name,
causing dns_validate_dns_response() to write a NULL value one
byte after the end of the buffer:

dns_answer_record->name[len] = 0;

The next fields in the struct being filled from the content of the
query, it might have been possible to fill them with non-0 values,
causing for example a strlen() of the name to read past the end of
the struct and access unintended parts of the memory, possibly
leading to a crash.

To be backported to 1.8, probably also 1.7.

6 years agoBUG: dns: Fix out-of-bounds read via signedness error in dns_validate_dns_response()
Remi Gacogne [Wed, 5 Dec 2018 16:57:49 +0000 (17:57 +0100)] 
BUG: dns: Fix out-of-bounds read via signedness error in dns_validate_dns_response()

Since the data_len field of the dns_answer_item struct was an int16_t,
record length values larger than 2^15-1 were causing an integer
overflow and thus may have been interpreted as negative, making us
read well before the beginning of the buffer.
This might have led to information disclosure or a crash.

To be backported to 1.8, probably also 1.7.

6 years agoBUG: dns: Prevent out-of-bounds read in dns_validate_dns_response()
Remi Gacogne [Wed, 5 Dec 2018 16:56:29 +0000 (17:56 +0100)] 
BUG: dns: Prevent out-of-bounds read in dns_validate_dns_response()

We need to make sure that the record length is not making us read
past the end of the data we received.
Before this patch we could for example read the 16 bytes
corresponding to an AAAA record from the non-initialized part of
the buffer, possibly accessing anything that was left on the stack,
or even past the end of the 8193-byte buffer, depending on the
value of accepted_payload_size.

To be backported to 1.8, probably also 1.7.

6 years agoBUG: dns: Prevent out-of-bounds read in dns_read_name()
Remi Gacogne [Wed, 5 Dec 2018 16:55:10 +0000 (17:55 +0100)] 
BUG: dns: Prevent out-of-bounds read in dns_read_name()

Some callers of dns_read_name() do not make sure that we can read
the first byte, holding the length of the next label, without going
past our buffer, so we need to make sure of that.
In addition, if the label is a compressed one we need to make sure
that we can read the following byte to compute the target offset.

To be backported to 1.8, probably also 1.7.

6 years agoBUG: dns: Prevent stack-exhaustion via recursion loop in dns_read_name
Remi Gacogne [Wed, 5 Dec 2018 16:52:54 +0000 (17:52 +0100)] 
BUG: dns: Prevent stack-exhaustion via recursion loop in dns_read_name

When a compressed pointer is encountered, dns_read_name() will call
itself with the pointed-to offset in the packet.
With a specially crafted packet, it was possible to trigger an
infinite-loop recursion by making the pointer points to itself.
While it would be possible to handle that particular case differently
by making sure that the target is different from the current offset,
it would still be possible to craft a packet with a very long chain
of valid pointers, always pointing backwards. To prevent a stack
exhaustion in that case, this patch restricts the number of recursive
calls to 100, which should be more than enough.

To be backported to 1.8, probably also 1.7.

6 years agoBUG/MEDIUM: mux-h1: Fix the zero-copy on output for chunked messages
Christopher Faulet [Wed, 12 Dec 2018 09:32:09 +0000 (10:32 +0100)] 
BUG/MEDIUM: mux-h1: Fix the zero-copy on output for chunked messages

The commit 3815b227f ("MEDIUM: mux-h1: implement true zero-copy of DATA blocks")
broke the output of chunked messages. When the zero-copy was performed on such
messages, no chunk size was emitted nor ending CRLF.

Now, the chunked envelope is added when necessary. We have at least the size of
the struct htx to emit it. So 40 bytes for now. It should be enough.

6 years agoMINOR: cli: change 'show proc' output of old processes
William Lallemand [Wed, 12 Dec 2018 12:45:57 +0000 (13:45 +0100)] 
MINOR: cli: change 'show proc' output of old processes

Change the output of the relative pid for the old processes, displays
"[was: X]" instead of just "X" which was confusing if you want to
connect to the CLI of an old PID.

6 years agoMINOR: mux-h2: force reads to be HTX-aligned in HTX mode
Willy Tarreau [Wed, 12 Dec 2018 07:23:47 +0000 (08:23 +0100)] 
MINOR: mux-h2: force reads to be HTX-aligned in HTX mode

H2 has a 9-byte frame header, and HTX has a 40-byte frame header.
By artificially advancing the Rx header and limiting the amount of
bytes read to protect the end of the buffer, we can make the data
payload perfectly aligned with HTX blocks and optimize the copy.

6 years agoMEDIUM: mux-h2: implement true zero-copy send of large HTX DATA blocks
Willy Tarreau [Wed, 12 Dec 2018 06:03:00 +0000 (07:03 +0100)] 
MEDIUM: mux-h2: implement true zero-copy send of large HTX DATA blocks

This is similar to what was done for the H1 mux : when the mux's buffer
is empty and the htx area contains exactly one data block of the same
size as the requested count, and all window and frame size conditions are
satisfied, then it's possible to simply swap the caller's buffer with the
mux's output buffer and adjust offsets and length to match the entire
DATA HTX block in the middle. An H2 frame header has to be prepended
before the block but this always fits in an HTX frame header.

In this case we perform a true zero-copy operation from end-to-end. This
is the situation that happens all the time with large files. When using
HTX over H2 over TLS, this brings a 3% extra performance gain. TLS remains
a limiting factor here but the copy definitely has a cost. Also since
haproxy can now use H2 in clear, the savings can be higher.

6 years agoMINOR: mux-h2: avoid copying large blocks into full buffers
Willy Tarreau [Wed, 12 Dec 2018 08:17:21 +0000 (09:17 +0100)] 
MINOR: mux-h2: avoid copying large blocks into full buffers

Due to blocking factor being different on H1 and H2, we regularly end
up with tails of data blocks that leave room in the mux buffer, making
it tempting to copy the pending frame into the remaining room left, and
possibly realigning the output buffer.

Here we check if the output buffer contains data, and prefer to wait
if either the current frame doesn't fit or if it's larger than 1/4 of
the buffer. This way upon next call, either a zero copy, or a larger
and aligned copy will be performed, taking the whole chunk at once.

Doing so increases the H2 bandwidth by slightly more than 1% on large
objects.

6 years agoDOC: master CLI documentation in management.txt
William Lallemand [Tue, 11 Dec 2018 17:56:45 +0000 (18:56 +0100)] 
DOC: master CLI documentation in management.txt

Documentation which explains the basic usage of the master CLI.

6 years agoBUG/MINOR: mux-h2: advertise a larger connection window size
Willy Tarreau [Wed, 12 Dec 2018 07:08:05 +0000 (08:08 +0100)] 
BUG/MINOR: mux-h2: advertise a larger connection window size

By default H2 uses a 65535 bytes window for the connection, and changing
it requires sending a WINDOW_UPDATE message. We only used to update the
window when receiving data, thus never increasing it further.

As reported by user klzgrad on the mailing list, this seriously limits
the upload bitrate, and will have an even higher impact on the backend
H2 connections to origin servers.

There is no technical reason for keeping this window so low, so let's
increase it to the maximum possible value (2G-1). We do this by
pretending we've already received that many data minus the maximum
data the client might already send (65535), so that an early
WINDOW_UPDATE message is sent right after the SETTINGS frame.

This should be backported to 1.8. This patch depends on previous
patch "BUG/MINOR: mux-h2: refrain from muxing during the preface".

6 years agoBUG/MINOR: mux-h2: refrain from muxing during the preface
Willy Tarreau [Wed, 12 Dec 2018 07:03:58 +0000 (08:03 +0100)] 
BUG/MINOR: mux-h2: refrain from muxing during the preface

The condition to refrain from processing the mux was insufficient as it
would only handle the outgoing connections. In essence it is not that much
of a problem since we don't have streams yet on an incoming connetion. But
it prevents waiting for the end of the preface before sending an early
WINDOW_UPDATE message, thus causing the connections to fail in this case.

This must be backported to 1.8 with a few minor adaptations.

6 years agoMINOR: config: round up global.tune.bufsize to the next multiple of 2 void*
Willy Tarreau [Wed, 12 Dec 2018 05:19:42 +0000 (06:19 +0100)] 
MINOR: config: round up global.tune.bufsize to the next multiple of 2 void*

Since HTX casts the buffer to a struct and stores relative pointers at the
end, it is mandatory that its end is properly aligned. This patch enforces
a buffer size rounding up to the next multiple of two void*, thus 8 on
32-bit and 16 on 64-bit, to match what malloc() already does on the beginning
of the buffer. In pratice it will never be really noticeable since default
sizes already are such multiples.

6 years agoMEDIUM: mux-h1: implement true zero-copy of DATA blocks
Willy Tarreau [Tue, 11 Dec 2018 18:50:43 +0000 (19:50 +0100)] 
MEDIUM: mux-h1: implement true zero-copy of DATA blocks

When the mux's buffer is empty and the htx area contains exactly one
data block of the same size as the requested count, then it's possible
to simply swap the caller's buffer with the mux's output buffer and
adjust offsets and length to match the entire DATA HTX block in the
middle. In this case we perform a true zero-copy operation from
end-to-end. This is the situation that happens all the time with large
files. With this change, the HTX bit rate performance catches up again
with the legacy mode (measured at 97%).

6 years agoCLEANUP: stream: remove SF_TUNNEL, SF_INITIALIZED, SF_CONN_TAR
Willy Tarreau [Tue, 11 Dec 2018 17:01:38 +0000 (18:01 +0100)] 
CLEANUP: stream: remove SF_TUNNEL, SF_INITIALIZED, SF_CONN_TAR

These flags haven't been used for a while. SF_TUNNEL was reintroduced
by commit d62b98c6e ("MINOR: stream: don't set backend's nor response
analysers on SF_TUNNEL") to handle the two-level streams needed to
deal with the first model for H2, and was not removed after this model
was abandonned. SF_INITIALIZED was only set. SF_CONN_TAR was never
referenced at all.

6 years agoREORG: h1: merge types+proto into common/h1.h
Willy Tarreau [Tue, 11 Dec 2018 12:44:24 +0000 (13:44 +0100)] 
REORG: h1: merge types+proto into common/h1.h

These two files are self-contained and do not depend on other
layers, so let's remerge them together for easier manipulation.

6 years agoCLEANUP: h1: remove some occurrences of unneeded h1.h inclusions
Willy Tarreau [Tue, 11 Dec 2018 10:11:37 +0000 (11:11 +0100)] 
CLEANUP: h1: remove some occurrences of unneeded h1.h inclusions

Several places where h1.h was included didn't need it at all since
they in fact relied on the legacy HTTP definitions.

6 years agoREORG: h1: move the h1_state definition to proto_http
Willy Tarreau [Tue, 11 Dec 2018 10:04:56 +0000 (11:04 +0100)] 
REORG: h1: move the h1_state definition to proto_http

This is the legacy HTTP/1 state, it's never used from within h1 users,
let's move it to proto_http with the rest of the legacy code.

6 years agoREORG: h1: move legacy http functions to http_msg.c
Willy Tarreau [Tue, 11 Dec 2018 09:59:20 +0000 (10:59 +0100)] 
REORG: h1: move legacy http functions to http_msg.c

Now that h1 and legacy HTTP are two distinct things, there's no need
to keep the legacy HTTP parsers in h1.c since they're only used by
the legacy code in proto_http.c, and h1.h doesn't need to include
hdr_idx anymore. This concerns the following functions :

- http_parse_reqline();
- http_parse_stsline();
- http_msg_analyzer();
- http_forward_trailers();

All of these were moved to http_msg.c.

6 years agoREORG: http: create http_msg.c to place there some legacy HTTP parts
Willy Tarreau [Tue, 11 Dec 2018 10:42:27 +0000 (11:42 +0100)] 
REORG: http: create http_msg.c to place there some legacy HTTP parts

Lots of HTTP code still uses struct http_msg. Not only this code is
still huge, but it's part of the legacy interface. Let's move most
of these functions to a separate file http_msg.c to make it more
visible which file relies on what. It's mostly symmetrical with
what is present in http_htx.c.

The function http_transform_header_str() which used to rely on two
function pointers to look up a header was simplified to rely on
two variants http_legacy_replace_{,full_}header(), making both
sides of the function much simpler.

No code was changed beyond these moves.