]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoMINOR: cfgparse: SSL/TLS binding in "peers" sections.
Frédéric Lécaille [Fri, 11 Jan 2019 13:06:12 +0000 (14:06 +0100)] 
MINOR: cfgparse: SSL/TLS binding in "peers" sections.

Make "bind" keywork be supported in "peers" sections.
All "bind" settings are supported on this line.
Add "default-bind" option to parse the binding options excepted the bind address.
Do not parse anymore the bind address for local peers on "server" lines.
Do not use anymore list_for_each_entry() to set the "peers" section
listener parameters because there is only one listener by "peers" section.

May be backported to 1.5 and newer.

6 years agoMINOR: peers: Make outgoing connection to SSL/TLS peers work.
Frédéric Lécaille [Thu, 26 Apr 2018 12:35:21 +0000 (14:35 +0200)] 
MINOR: peers: Make outgoing connection to SSL/TLS peers work.

This patch adds pointer to a struct server to peer structure which
is initialized after having parsed a remote "peer" line.

After having parsed all peers section we run ->prepare_srv to initialize
all SSL/TLS stuff of remote perr (or server).

Remaining thing to do to completely support peer protocol over SSL/TLS:
make "bind" keyword be supported in "peers" sections to make SSL/TLS
incoming connections to local peers work.

May be backported to 1.5 and newer.

6 years agoMINOR: cfgparse: Make "peer" lines be parsed as "server" lines.
Frédéric Lécaille [Thu, 26 Apr 2018 08:06:41 +0000 (10:06 +0200)] 
MINOR: cfgparse: Make "peer" lines be parsed as "server" lines.

With this patch "default-server" lines are supported in "peers" sections
to setup the default settings of peers which are from now setup
when parsing both "peer" and "server" lines.

May be backported to 1.5 and newer.

6 years agoMINOR: cfgparse: Simplication.
Frédéric Lécaille [Fri, 11 Jan 2019 10:47:12 +0000 (11:47 +0100)] 
MINOR: cfgparse: Simplication.

Make init_peers_frontend() be callable without having to check if
there is something to do or not.

May be backported to 1.5 and newer.

6 years agoMINOR: cfgparse: Rework peers frontend init.
Frédéric Lécaille [Fri, 11 Jan 2019 10:43:53 +0000 (11:43 +0100)] 
MINOR: cfgparse: Rework peers frontend init.

Even if not already the case, we suppose that the frontend "peers" section
may have been already initialized outside of "peer" line, we seperate
their initializations from their binding initializations.

May be backported to 1.5 and newer.

6 years agoMINOR: cfgparse: Useless frontend initialization in "peers" sections.
Frédéric Lécaille [Wed, 25 Apr 2018 13:32:18 +0000 (15:32 +0200)] 
MINOR: cfgparse: Useless frontend initialization in "peers" sections.

Use ->local "peers" struct member to flag a "peers" section frontend
has being initialized. This is to be able to initialize the frontend
of "peers" sections on lines different from "peer" lines.

May be backported to 1.5 and newer.

6 years agoCLEANUP: cfgparse: Code reindentation.
Frédéric Lécaille [Fri, 11 Jan 2019 10:27:16 +0000 (11:27 +0100)] 
CLEANUP: cfgparse: Code reindentation.

May help the series of patches to be reviewed.

May be backported to 1.5 and newer.

6 years agoCLEANUP: cfgparse: Return asap from cfg_parse_peers().
Frédéric Lécaille [Wed, 25 Apr 2018 13:13:38 +0000 (15:13 +0200)] 
CLEANUP: cfgparse: Return asap from cfg_parse_peers().

Avoid useless code indentation.

May be backported to 1.5 and newer.

6 years agoMINOR: cfgparse: Extract some code to be re-used.
Frédéric Lécaille [Fri, 11 Jan 2019 10:07:15 +0000 (11:07 +0100)] 
MINOR: cfgparse: Extract some code to be re-used.

Create init_peers_frontend() function to allocate and initialize
the frontend of "peers" sections (->peers_fe) so that to reuse it later.

May be backported to 1.5 and newer.

6 years agoDOC: add github issue templates
Lukas Tribus [Thu, 17 Jan 2019 17:02:18 +0000 (18:02 +0100)] 
DOC: add github issue templates

See issue #2

Co-authored-by: Tim Duesterhus <tim@bastelstu.be>
6 years agoBUG/MEDIUM: connections: Add the CO_FL_CONNECTED flag if a send succeeded.
Olivier Houchard [Thu, 17 Jan 2019 18:09:11 +0000 (19:09 +0100)] 
BUG/MEDIUM: connections: Add the CO_FL_CONNECTED flag if a send succeeded.

If a send succeeded, add the CO_FL_CONNECTED flag, the send may have been
called by the upper layers before we even realized we were connected, and we
may even read the response before we get the information, and si_cs_recv()
has to know if we were connected or not.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: servers: Make assign_tproxy_address work when ALPN is set.
Olivier Houchard [Thu, 17 Jan 2019 14:59:13 +0000 (15:59 +0100)] 
BUG/MEDIUM: servers: Make assign_tproxy_address work when ALPN is set.

If an ALPN is set on the server line, then when we reach assign_tproxy_address,
the stream_interface's endpoint will be a connection, not a conn_stream,
so make sure assign_tproxy_address() handles both cases.

This should be backported to 1.9.

6 years agoREGTEST: checks basic stats webpage functionality
PiBa-NL [Sat, 12 Jan 2019 20:57:48 +0000 (21:57 +0100)] 
REGTEST: checks basic stats webpage functionality

This regtest verifies that the stats webpage can be used to change a
server state to maintenance or drain, and that filtering the page scope
will result in a filtered page.

6 years agoDOC: add a missing space in the documentation for bc_http_major
Jérôme Magnin [Wed, 16 Jan 2019 13:38:37 +0000 (14:38 +0100)] 
DOC: add a missing space in the documentation for bc_http_major

add a missing space between sample fetch name and colon, and make
haproxy-dconv happier.

6 years agoBUG/MEDIUM: stats: Get the right scope pointer depending on HTX is used or not
Christopher Faulet [Mon, 14 Jan 2019 10:07:34 +0000 (11:07 +0100)] 
BUG/MEDIUM: stats: Get the right scope pointer depending on HTX is used or not

For HTX streams, the scope pointer is relative to the URI in the start-line. But
for streams using the legacy HTTP representation, the scope pointer is relative
to the beginning of output data in the channel's buffer. So we must be careful
to use the right one depending on the HTX is used or not.

Because the start-line is used to get de scope pointer, it is important to keep
it after the parsing of post paramters. So now, instead of removing blocks when
read in the function stats_process_http_post(), we just move on next, leaving it
in the HTX message.

Thanks to Pieter (PiBa-NL) to report this bug.

This patch must be backported to 1.9.

6 years agoBUG: 51d: Changes to the buffer API in 1.9 were not applied to the 51Degrees code.
Ben51Degrees [Wed, 16 Jan 2019 10:19:15 +0000 (10:19 +0000)] 
BUG: 51d: Changes to the buffer API in 1.9 were not applied to the 51Degrees code.

The code using the deprecated 'buf->p' has been updated to use
'ci_head(buf)' as described in section 5 of
'doc/internals/buffer-api.txt'.
A compile time switch on 'BUF_NULL' has also been added to enable the
same source code to be used with pre and post API change HAProxy.

This should be backported to 1.9, and is compatible with previous
versions.

6 years agoBUG/MINOR: stick_table: Prevent conn_cur from underflowing
Tim Duesterhus [Thu, 3 Jan 2019 23:11:59 +0000 (00:11 +0100)] 
BUG/MINOR: stick_table: Prevent conn_cur from underflowing

When using the peers feature a race condition could prevent
a connection from being properly counted. When this connection
exits it is being "uncounted" nonetheless, leading to a possible
underflow (-1) of the conn_curr stick table entry in the following
scenario :

  - Connect to peer A     (A=1, B=0)
  - Peer A sends 1 to B   (A=1, B=1)
  - Kill connection to A  (A=0, B=1)
  - Connect to peer B     (A=0, B=2)
  - Peer A sends 0 to B   (A=0, B=0)
  - Peer B sends 0/2 to A (A=?, B=0)
  - Kill connection to B  (A=?, B=-1)
  - Peer B sends -1 to A  (A=-1, B=-1)

This fix may be backported to all supported branches.

6 years agoBUILD/MEDIUM: da: Necessary code changes for new buffer API.
David Carlier [Tue, 15 Jan 2019 12:09:00 +0000 (12:09 +0000)] 
BUILD/MEDIUM: da: Necessary code changes for new buffer API.

The most significant change from 1.8 to >=1.9 is the buffer
data structure, using the new field and fixing along side
a little hidden compilation warning.

This must be backported to 1.9.

6 years agoMINOR: backend: make the random algorithm support a number of draws
Willy Tarreau [Mon, 14 Jan 2019 17:14:27 +0000 (18:14 +0100)] 
MINOR: backend: make the random algorithm support a number of draws

When an argument <draws> is present, it must be an integer value one
or greater, indicating the number of draws before selecting the least
loaded of these servers. It was indeed demonstrated that picking the
least loaded of two servers is enough to significantly improve the
fairness of the algorithm, by always avoiding to pick the most loaded
server within a farm and getting rid of any bias that could be induced
by the unfair distribution of the consistent list. Higher values N will
take away N-1 of the highest loaded servers at the expense of performance.
With very high values, the algorithm will converge towards the leastconn's
result but much slower. The default value is 2, which generally shows very
good distribution and performance. This algorithm is also known as the
Power of Two Random Choices and is described here :

http://www.eecs.harvard.edu/~michaelm/postscripts/handbook2001.pdf

6 years agoMEDIUM: backend: move all LB algo parameters into an union
Willy Tarreau [Mon, 14 Jan 2019 15:55:42 +0000 (16:55 +0100)] 
MEDIUM: backend: move all LB algo parameters into an union

Since all of them are exclusive, let's move them to an union instead
of eating memory with the sum of all of them. We're using a transparent
union to limit the code changes.

Doing so reduces the struct lbprm from 392 bytes to 372, and thanks
to these changes, the struct proxy is now down to 6480 bytes vs 6624
before the changes (144 bytes saved per proxy).

6 years agoMINOR: backend: move hash_balance_factor out of chash
Willy Tarreau [Mon, 14 Jan 2019 15:50:58 +0000 (16:50 +0100)] 
MINOR: backend: move hash_balance_factor out of chash

This one is a proxy option which can be inherited from defaults even
if the LB algo changes. Move it out of the lb_chash struct so that we
don't need to keep anything separate between these structs. This will
allow us to merge them into an union later. It even takes less room
now as it fills a hole and removes another one.

6 years agoMINOR: backend: remap the balance uri settings to lbprm.arg_opt{1,2,3}
Willy Tarreau [Mon, 14 Jan 2019 15:14:15 +0000 (16:14 +0100)] 
MINOR: backend: remap the balance uri settings to lbprm.arg_opt{1,2,3}

The algo-specific settings move from the proxy to the LB algo this way :
  - uri_whole => arg_opt1
  - uri_len_limit => arg_opt2
  - uri_dirs_depth1 => arg_opt3

6 years agoMINOR: backend: make the header hash use arg_opt1 for use_domain_only
Willy Tarreau [Mon, 14 Jan 2019 15:04:54 +0000 (16:04 +0100)] 
MINOR: backend: make the header hash use arg_opt1 for use_domain_only

This is only a boolean extra arg. Let's map it to arg_opt1 and remove
hh_match_domain from struct proxy.

6 years agoMINOR: backend: add new fields in lbprm to store more LB options
Willy Tarreau [Mon, 14 Jan 2019 15:04:01 +0000 (16:04 +0100)] 
MINOR: backend: add new fields in lbprm to store more LB options

Some algorithms require a few extra options (up to 3). Let's provide
some room in lbprm to store them, and make sure they're passed from
defaults to backends.

6 years agoMINOR: backend: make headers and RDP cookie also use arg_str/len
Willy Tarreau [Mon, 14 Jan 2019 14:28:53 +0000 (15:28 +0100)] 
MINOR: backend: make headers and RDP cookie also use arg_str/len

These ones used to rely on separate variables called hh_name/hh_len
but they are exclusive with the former. Let's use the same variable
which becomes a generic argument name and length for the LB algorithm.

6 years agoMINOR: backend: move url_param_name/len to lbprm.arg_str/len
Willy Tarreau [Mon, 14 Jan 2019 14:23:54 +0000 (15:23 +0100)] 
MINOR: backend: move url_param_name/len to lbprm.arg_str/len

This one is exclusively used by LB parameters, when using URL param
hashing. Let's move it to the lbprm struct under a more generic name.

6 years agoBUG/MINOR: backend: BE_LB_LKUP_CHTREE is a value, not a bit
Willy Tarreau [Mon, 14 Jan 2019 16:07:39 +0000 (17:07 +0100)] 
BUG/MINOR: backend: BE_LB_LKUP_CHTREE is a value, not a bit

There are a few instances where the lookup algo is tested against
BE_LB_LKUP_CHTREE using a binary "AND" operation while this macro
is a value among a set, and not a bit. The test happens to work
because the value is exactly 4 and no bit overlaps with the other
possible values but this is a latent bug waiting for a new LB algo
to appear to strike. At the moment the only other algo sharing a bit
with it is the "first" algo which is never supported in the same code
places.

This fix should be backported to maintained versions for safety if it
passes easily, otherwise it's not important as it will not fix any
visible issue.

6 years agoBUG/MINOR: backend: balance uri specific options were lost across defaults
Willy Tarreau [Mon, 14 Jan 2019 15:29:52 +0000 (16:29 +0100)] 
BUG/MINOR: backend: balance uri specific options were lost across defaults

The "balance uri" options "whole", "len" and "depth" were not properly
inherited from the defaults sections. In addition, "whole" and "len"
were not even reset when parsing "uri", meaning that 2 subsequent
"balance uri" statements would not have the expected effect as the
options from the first one would remain for the second one.

This may be backported to all maintained versions.

6 years agoBUG/MINOR: backend: don't use url_param_name as a hint for BE_LB_ALGO_PH
Willy Tarreau [Mon, 14 Jan 2019 14:17:46 +0000 (15:17 +0100)] 
BUG/MINOR: backend: don't use url_param_name as a hint for BE_LB_ALGO_PH

At a few places in the code we used to rely on this variable to guess
what LB algo was in place. This is wrong because if the defaults section
presets "balance url_param foo" and a backend uses "balance roundrobin",
these locations will still see this url_param_name set and consider it.
The harm is limited, as this only causes the beginning of the request
body to be buffered. And in general this is a bad practice which prevents
us from cleaning the lbprm stuff. Let's explicitly check the LB algo
instead.

This may be backported to all currently maintained versions.

6 years agoMINOR: ssl: add support of aes256 bits ticket keys on file and cli.
Emeric Brun [Thu, 10 Jan 2019 16:51:55 +0000 (17:51 +0100)] 
MINOR: ssl: add support of aes256 bits ticket keys on file and cli.

Openssl switched from aes128 to aes256 since may 2016  to compute
tls ticket secrets used by default. But Haproxy still handled only
128 bits keys for both tls key file and CLI.

This patch permit the user to set aes256 keys throught CLI or
the key file (80 bytes encoded in base64) in the same way that
aes128 keys were handled (48 bytes encoded in base64):
- first 16 bytes for the key name
- next 16/32 bytes for aes 128/256 key bits key
- last 16/32 bytes for hmac 128/256 bits

Both sizes are now supported (but keys from same file must be
of the same size and can but updated via CLI only using a key of
the same size).

Note: This feature need the fix "dec func ignores padding for output
size checking."

6 years agoBUG/MEDIUM: ssl: missing allocation failure checks loading tls key file
Emeric Brun [Thu, 10 Jan 2019 09:51:13 +0000 (10:51 +0100)] 
BUG/MEDIUM: ssl: missing allocation failure checks loading tls key file

This patch fixes missing allocation checks loading tls key file
and avoid memory leak in some error cases.

This patch should be backport on branches 1.9 and 1.8

6 years agoBUG/MINOR: base64: dec func ignores padding for output size checking
Emeric Brun [Mon, 14 Jan 2019 13:38:39 +0000 (14:38 +0100)] 
BUG/MINOR: base64: dec func ignores padding for output size checking

Decode function returns an error even if the ouptut buffer is
large enought because the padding was not considered. This
case was never met with current code base.

6 years agoBUG/MEDIUM: h1: Make sure we destroy an inactive connectin that did shutw.
Olivier Houchard [Mon, 14 Jan 2019 16:27:23 +0000 (17:27 +0100)] 
BUG/MEDIUM: h1: Make sure we destroy an inactive connectin that did shutw.

In h1_process(), if we have no associated stream, and the connection got a
shutw, then destroy it, it is unusable and it may be our last chance to do
so.

This should be backported to 1.9.

6 years agoREGTEST: Adapt reg test doc files to vtest.
Frédéric Lécaille [Fri, 11 Jan 2019 09:10:22 +0000 (10:10 +0100)] 
REGTEST: Adapt reg test doc files to vtest.

This is a first patch to switch from varnishtest to new standalone
varnish cache reg testing program: vtest.

More information may be found here:

https://github.com/vtest/VTest
https://varnish-cache.org/docs/trunk/reference/varnishtest.html
https://varnish-cache.org/docs/trunk/reference/vtc.html

6 years agoREGTEST: Switch to vtest.
Frédéric Lécaille [Fri, 11 Jan 2019 09:10:21 +0000 (10:10 +0100)] 
REGTEST: Switch to vtest.

This patch replace the usage of the formerly varnish cache reg
testing program, name varnishtest by the new standalone one: vtest.

6 years agoBUG/MEDIUM: checks: Avoid having an associated server for email checks.
Olivier Houchard [Fri, 11 Jan 2019 17:43:04 +0000 (18:43 +0100)] 
BUG/MEDIUM: checks: Avoid having an associated server for email checks.

When using a check to send email, avoid having an associated server, so that
we don't modify the server state if we fail to send an email.
Also revert back to initialize the check status to HCHK_STATUS_INI, now that
set_server_check_status() stops early if there's no server, we shouldn't
get in a mail loop anymore.

This should be backported to 1.9.

6 years agoMINOR: checks: Store the proxy in checks.
Olivier Houchard [Fri, 11 Jan 2019 17:17:17 +0000 (18:17 +0100)] 
MINOR: checks: Store the proxy in checks.

Instead of assuming we have a server, store the proxy directly in struct
check, and use it instead of s->server.
This should be a no-op for now, but will be useful later when we change
mail checks to avoid having a server.

This should be backported to 1.9.

6 years agoMINOR: spoe: Make the SPOE filter compatible with HTX proxies
Christopher Faulet [Wed, 9 Jan 2019 14:05:10 +0000 (15:05 +0100)] 
MINOR: spoe: Make the SPOE filter compatible with HTX proxies

There is any specific HTTP processing in the SPOE. So there is no reason to not
use it on HTX proxies.

This patch may be backported to 1.9.

6 years agoDOC: REGTESTS README varnishtest -Dno-htx= define.
Jarno Huuskonen [Wed, 9 Jan 2019 13:42:25 +0000 (15:42 +0200)] 
DOC: REGTESTS README varnishtest -Dno-htx= define.

Add -Dno-htx= to varnishtest command line, because without no-htx most
vtc tests fail (${no-htx} macro). Also link to doc/regression-testing.txt

6 years agoREGTESTS: Basic tests for using maps to redirect requests / select backend
Jarno Huuskonen [Wed, 9 Jan 2019 13:40:27 +0000 (15:40 +0200)] 
REGTESTS: Basic tests for using maps to redirect requests / select backend

6 years agoREGTESTS: Basic tests for concat,strcmp,word,field,ipmask converters
Jarno Huuskonen [Wed, 9 Jan 2019 11:44:44 +0000 (13:44 +0200)] 
REGTESTS: Basic tests for concat,strcmp,word,field,ipmask converters

6 years agoREGTESTS: test case for map_regm commit 271022150d
Jarno Huuskonen [Wed, 9 Jan 2019 11:41:19 +0000 (13:41 +0200)] 
REGTESTS: test case for map_regm commit 271022150d

Minimal test case for map_regm commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee.
Config and test is adapted from: Daniel Schneller's example
(https://www.mail-archive.com/haproxy@formilux.org/msg30523.html).

6 years agoBUG/MAJOR: cache: fix confusion between zero and uninitialized cache key
Willy Tarreau [Fri, 11 Jan 2019 18:38:25 +0000 (19:38 +0100)] 
BUG/MAJOR: cache: fix confusion between zero and uninitialized cache key

The cache uses the first 32 bits of the uri's hash as the key to reference
the object in the cache. It makes a special case of the value zero to mean
that the object is not in the cache anymore. The problem is that when an
object hashes as zero, it's still inserted but the eb32_delete() call is
skipped, resulting in the object still being chained in the memory area
while the block has been reclaimed and used for something else. Then when
objects which were chained below it (techically any object since zero is
at the root) are deleted, the walk through the upper object may encounter
corrupted values where valid pointers were expected.

But while this should only happen statically once on 4 billion, the problem
gets worse when the cache-use conditions don't match the cache-store ones,
because cache-store runs with an uninitialized key, which can create objects
that will never be found by the lookup code, or worse, entries with a zero
key preventing eviction of the tree node and resulting in a crash. It's easy
to accidently end up on such a config because the request rules generally
can't be used to decide on the response :

  http-request  cache-use cache   if { path_beg /images }
  http-response cache-store cache

In this test, mixing traffic with /images/$RANDOM and /foo/$RANDOM will
result in random keys being inserted, some of them possibly being zero,
and crashes will quickly happen.

The fix consists in 1) always initializing the transaction's cache_hash
to zero, and 2) never storing a response for which the hash has not been
calculated, as indicated by the value zero.

It is worth noting that objects hashing as value zero will never be cached,
but given that there's only one chance among 4 billion that this happens,
this is totally harmless.

This fix must be backported to 1.9 and 1.8.

6 years agoBUG/MEDIUM: connection: properly unregister the mux on failed initialization
Willy Tarreau [Thu, 10 Jan 2019 09:33:32 +0000 (10:33 +0100)] 
BUG/MEDIUM: connection: properly unregister the mux on failed initialization

When mux->init() fails, session_free() will call it again to unregister
it while it was already done, resulting in null derefs or use-after-free.
This typically happens on out-of-memory conditions during H1 or H2 connection
or stream allocation.

This fix must be backported to 1.9.

6 years agoBUILD: makefile: add an EXTRA_OBJS variable to help build optional code
Willy Tarreau [Thu, 10 Jan 2019 09:01:03 +0000 (10:01 +0100)] 
BUILD: makefile: add an EXTRA_OBJS variable to help build optional code

This variable will be useful to build experimental autonomous code like
new muxes without having to patch the makefile.

6 years agoMINOR: mux-h1: make the mux_h1_ops struct static
Willy Tarreau [Thu, 10 Jan 2019 09:00:08 +0000 (10:00 +0100)] 
MINOR: mux-h1: make the mux_h1_ops struct static

It was needlessly exported while it's only used inside the mux.

6 years agoDOC: Be a bit more explicit about allow-0rtt security implications.
Olivier Houchard [Tue, 8 Jan 2019 14:35:32 +0000 (15:35 +0100)] 
DOC: Be a bit more explicit about allow-0rtt security implications.

Document a bit better than allow-0rtt can trivially be used for replay attacks,
and so should only be used when it's safe to replay a request.

This should probably be backported to 1.8 and 1.9.

6 years agoBUG/MEDIUM: ssl: Disable anti-replay protection and set max data with 0RTT.
Olivier Houchard [Wed, 2 Jan 2019 17:46:41 +0000 (18:46 +0100)] 
BUG/MEDIUM: ssl: Disable anti-replay protection and set max data with 0RTT.

When using early data, disable the OpenSSL anti-replay protection, and set
the max amount of early data we're ready to accept, based on the size of
buffers, or early data won't work with the released OpenSSL 1.1.1.

This should be backported to 1.8.

6 years agoBUG/MEDIUM: init: Initialize idle_orphan_conns for first server in server-template
Daniel Corbett [Wed, 9 Jan 2019 13:13:29 +0000 (08:13 -0500)] 
BUG/MEDIUM: init: Initialize idle_orphan_conns for first server in server-template

When initializing server-template all of the servers after the first
have srv->idle_orphan_conns initialized within server_template_init()
The first server does not have this initialized and when http-reuse
is active this causes a segmentation fault when accessed from
srv_add_to_idle_list().  This patch removes the check for
srv->tmpl_info.prefix within server_finalize_init() and allows
the first server within a server-template to have srv->idle_orphan_conns
properly initialized.

This should be backported to 1.9.

6 years agoREGTEST: filters: add compression test
PiBa-NL [Sun, 23 Dec 2018 20:21:51 +0000 (21:21 +0100)] 
REGTEST: filters: add compression test

This test checks that data transferred with compression is correctly received at
different download speeds

6 years agoBUG/MINOR: lua/htx: Respect the reserve when data are send from an HTX applet
Christopher Faulet [Wed, 9 Jan 2019 11:16:58 +0000 (12:16 +0100)] 
BUG/MINOR: lua/htx: Respect the reserve when data are send from an HTX applet

In the function hlua_applet_htx_send_yield(), there already was a test to
respect the reserve but the wrong function was used to get the available space
for data in the HTX buffer. Instead of calling htx_free_space(), the function
htx_free_data_space() must be used. But in fact, there is no reason to bother
with that anymore because the function channel_htx_recv_max() has been added for
this purpose.

The result of this bug is that the call to htx_add_data() failed unexpectedly
while the amount of written data was incremented, leading the applet to think
all data was sent. To prevent any futher bugs, a test has been added to yield if
we are not able to write data into the channel buffer.

This patch must be backported to 1.9.

6 years agoREGTEST: "capture (request|response)" regtest.
Frédéric Lécaille [Tue, 8 Jan 2019 09:24:16 +0000 (10:24 +0100)] 
REGTEST: "capture (request|response)" regtest.

6 years agoDOC: http-request cache-use / http-response cache-store expects cache name
Jarno Huuskonen [Fri, 4 Jan 2019 12:05:02 +0000 (14:05 +0200)] 
DOC: http-request cache-use / http-response cache-store expects cache name

Adds missing cache name option to http-request cache-use and
http-response cache-store documentation.

Also adds optional if/unless condition to
10.2.2. Proxy section: http-request cache-use / http-response cache-store

6 years agoDOC: Fix typo in req.ssl_alpn example (commit 4afdd138424ab...)
Jarno Huuskonen [Thu, 3 Jan 2019 05:56:49 +0000 (07:56 +0200)] 
DOC: Fix typo in req.ssl_alpn example (commit 4afdd138424ab...)

Also link to ssl_fc_alpn.

6 years agoBUG/CRITICAL: mux-h2: re-check the frame length when PRIORITY is used
Willy Tarreau [Mon, 31 Dec 2018 06:41:24 +0000 (07:41 +0100)] 
BUG/CRITICAL: mux-h2: re-check the frame length when PRIORITY is used

Tim Düsterhus reported a possible crash in the H2 HEADERS frame decoder
when the PRIORITY flag is present. A check is missing to ensure the 5
extra bytes needed with this flag are actually part of the frame. As per
RFC7540#4.2, let's return a connection error with code FRAME_SIZE_ERROR.

Many thanks to Tim for responsibly reporting this issue with a working
config and reproducer. This issue was assigned CVE-2018-20615.

This fix must be backported to 1.9 and 1.8.

6 years agoBUG/MINOR: proto_htx: Use HTX versions to truncate or erase a buffer
Christopher Faulet [Mon, 7 Jan 2019 13:57:35 +0000 (14:57 +0100)] 
BUG/MINOR: proto_htx: Use HTX versions to truncate or erase a buffer

channel_truncate() is not aware of the underlying format of the messages. So if
there are some outgoing data in the channel when called, it does some unexpected
operations on the channel's buffer. So the HTX version, channel_htx_truncate(),
must be used. The same is true for channel_erase(). It resets the buffer but not
the HTX message. So channel_htx_erase() must be used instead. This patch is
flagged as a bug, but as far as we know, it was never hitted.

This patch should be backported to 1.9. If so, following patch must be
backported too:

  * MINOR: channel/htx: Add the HTX version of channel_truncate/erase

6 years agoMINOR: channel/htx: Add the HTX version of channel_truncate/erase
Christopher Faulet [Mon, 7 Jan 2019 13:55:10 +0000 (14:55 +0100)] 
MINOR: channel/htx: Add the HTX version of channel_truncate/erase

The function channel_htx_truncate() can now be used on HTX buffer to truncate
all incoming data, keeping outgoing one intact. This function relies on the
function channel_htx_erase() and htx_truncate().

This patch may be backported to 1.9. If so, the patch "MINOR: channel/htx: Add
the HTX version of channel_truncate()" must also be backported.

6 years agoMINOR: htx: Add a function to truncate all blocks after a specific offset
Christopher Faulet [Mon, 7 Jan 2019 13:53:27 +0000 (14:53 +0100)] 
MINOR: htx: Add a function to truncate all blocks after a specific offset

This function will be used to truncate all incoming data in a channel, keeping
outgoing ones.

This may be backported to 1.9.

6 years agoREGTEST: Add some informatoin to test results.
Frédéric Lécaille [Tue, 8 Jan 2019 10:30:28 +0000 (11:30 +0100)] 
REGTEST: Add some informatoin to test results.

When the reg tests fail, it may be useful to display additional information
coming from varnishtest, especially when this latter aborts.
In such case, the test output may be made of lines prefixed by "*     diag"
string.

6 years agoBUG/MINOR: cache: Disable the cache if any compression filter precedes it
Christopher Faulet [Mon, 7 Jan 2019 15:12:07 +0000 (16:12 +0100)] 
BUG/MINOR: cache: Disable the cache if any compression filter precedes it

We need to check if any compression filter precedes the cache filter. This is
only possible when the compression is configured in the frontend while the cache
filter is configured on the backend (via a cache-store action or
explicitly). This case cannot be detected during HAProxy startup. So in such
cases, the cache is disabled.

The patch must be backported to 1.9.

6 years agoBUG/MINOR: filters: Detect cache+compression config on legacy HTTP streams
Christopher Faulet [Mon, 7 Jan 2019 14:03:22 +0000 (15:03 +0100)] 
BUG/MINOR: filters: Detect cache+compression config on legacy HTTP streams

On legacy HTTP streams, it is forbidden to use the compression with the
cache. When the compression filter is explicitly specified, the detection works
as expected and such configuration are rejected at startup. But it does not work
when the compression filter is implicitly defined. To fix the bug, the implicit
declaration of the compression filter is checked first, before calling .check()
callback of each filters.

This patch should be backported to 1.9.

6 years agoBUG/MINOR: compression: Disable it if another one is already in progress
Christopher Faulet [Mon, 7 Jan 2019 13:41:59 +0000 (14:41 +0100)] 
BUG/MINOR: compression: Disable it if another one is already in progress

Since the commit 9666720c8 ("BUG/MEDIUM: compression: Use the right buffer
pointers to compress input data"), the compression can be done twice. The first
time on the frontend and the second time on the backend. This may happen by
configuring the compression in a default section.

To fix the bug, when the response is checked to know if it should be compressed
or not, if the flag HTTP_MSGF_COMPRESSING is set, the compression is not
performed. It means it is already handled by a previous compression filter.

Thanks to Pieter (PiBa-NL) to report this bug.

This patch must be backported to 1.9.

6 years agoMEDIUM: mux-h1: Clarify how shutr/shutw are handled
Christopher Faulet [Tue, 8 Jan 2019 10:12:04 +0000 (11:12 +0100)] 
MEDIUM: mux-h1: Clarify how shutr/shutw are handled

Now, h1_shutr() only do a shutdown read and try to set the flag
H1C_F_CS_SHUTDOWN if shutdown write was already performed. On its side,
h1_shutw(), if all conditions are met, do the same for the shutdown write. The
real connection close is done when the mux h1 is released, in h1_release().

The flag H1C_F_CS_SHUTW was renamed to H1C_F_CS_SHUTDOWN to be less ambiguous.

This patch may be backported to 1.9.

6 years agoBUG/MINOR: mux-h1: Close connection on shutr only when shutw was really done
Christopher Faulet [Tue, 8 Jan 2019 09:43:36 +0000 (10:43 +0100)] 
BUG/MINOR: mux-h1: Close connection on shutr only when shutw was really done

In h1_shutr(), to fully close the connection, we must be sure the shutdown write
was already performed on the connection. So we know rely on connection flags
instead of conn_stream flags. If CO_FL_SOCK_WR_SH is already set when h1_shutr()
is called, we can do a full connection close. Otherwise, we just do the shutdown
read.

Without this patch, it is possible to close the connection too early with some
outgoing data in the output buf.

This patch must be backported to 1.9.

6 years agoREGTEST: Add a reg test for health-checks over SSL/TLS.
Frédéric Lécaille [Tue, 18 Dec 2018 09:31:04 +0000 (10:31 +0100)] 
REGTEST: Add a reg test for health-checks over SSL/TLS.

This script runs two tests. One with "httpchk" over SSL/TLS and another
one with "check-ssl" option. As varnishtest does not support SSL/TLS
we use two haproxy processes to run these tests. h2 haproxy process
be2 and be4 backends declare one server each wich are the frontend
of h1 haproxy process. We check the layer6/7 checks thanks to syslog
messages.

Signed-off-by: Frédéric Lécaille <flecaille@haproxy.com>
6 years agoREGTEST: mailers: add new test for 'mailers' section
PiBa-NL [Sun, 23 Dec 2018 20:06:31 +0000 (21:06 +0100)] 
REGTEST: mailers: add new test for 'mailers' section

This test verifies the mailers section works properly by checking that
it sends the proper amount of mails when health-checks are changing and
or marking a server up/down

The test currently fails on all versions of haproxy i tried with varying
results:

- 1.9.0 produces thousands of mails.
- 1.8.14 only sends 1 mail, needs a 200ms 'timeout mail' to succeed
- 1.7.11 only sends 1 mail, needs a 200ms 'timeout mail' to succeed
- 1.6 only sends 1 mail, (does not have the 'timeout mail' setting implemented)

6 years agoDOC: regtest: make it clearer what the purpose of the "broken" series is
Willy Tarreau [Tue, 8 Jan 2019 08:56:20 +0000 (09:56 +0100)] 
DOC: regtest: make it clearer what the purpose of the "broken" series is

The purpose of the "broken" series of reg tests is to integrate scripts
which are known for triggering bugs that are not fixed at the time the
script is merged. These ones are not useful to validate non-regression
after merging a change, but have an important value to help fix the bug
they trigger. This patch updates the description in the Makefile to make
this clearer.

6 years agoBUG/MINOR: stats/htx: Respect the reserve when the stats page is dumped
Christopher Faulet [Mon, 7 Jan 2019 13:27:53 +0000 (14:27 +0100)] 
BUG/MINOR: stats/htx: Respect the reserve when the stats page is dumped

As for the cache applet, this one must respect the reserve on HTX streams. This
patch is tagged as MINOR because it is unlikely to fully fill the channel's
buffer. Some tests are already done to not process almost full buffer.

This patch must be backported to 1.9.

6 years agoBUG/MEDIUM: cache/htx: Respect the reserve when cached objects are served
Christopher Faulet [Mon, 7 Jan 2019 13:07:29 +0000 (14:07 +0100)] 
BUG/MEDIUM: cache/htx: Respect the reserve when cached objects are served

It is only true for HTX streams. The legacy code relies on ci_putblk() which is
already aware of the reserve. It is mandatory to not fill the reserve to let
other filters analysing data. It is especially true for the compression
filter. It needs at least 20 bytes of free space, plus at most 5 bytes per 32kB
block. So if the cache fully fills the channel's buffer, the compression will
not have enough space to do its job and it will block the data forwarding,
waiting for more free space. But if the buffer fully filled with input data (ie
no outgoing data), the stream will be frozen infinitely.

This patch must be backported to 1.9. It depends on the following patches:

  * BUG/MEDIUM: cache/htx: Respect the reserve when cached objects are served
    from the cache
  * MINOR: channel/htx: Add HTX version for some helper functions

6 years agoMINOR: channel/htx: Add HTX version for some helper functions
Christopher Faulet [Mon, 7 Jan 2019 12:57:01 +0000 (13:57 +0100)] 
MINOR: channel/htx: Add HTX version for some helper functions

HTX versions for functions to test the free space in input against the reserve
have been added. Now, on HTX streams, following functions can be used:

  * channel_htx_may_recv
  * channel_htx_recv_limit
  * channel_htx_recv_max
  * channel_htx_full

This patch must be backported in 1.9 because it will be used by a futher patch
to fix a bug.

6 years agoMINOR: htx: Add an helper function to get the max space usable for a block
Christopher Faulet [Mon, 7 Jan 2019 12:48:55 +0000 (13:48 +0100)] 
MINOR: htx: Add an helper function to get the max space usable for a block

This patch must be backported in 1.9 because it will be used by a futher patch
to fix a bug.

6 years agoBUG/MEDIUM: lua: dead lock when Lua tasks are trigerred
Thierry FOURNIER [Sun, 6 Jan 2019 18:04:24 +0000 (19:04 +0100)] 
BUG/MEDIUM: lua: dead lock when Lua tasks are trigerred

When a task is created from Lua context out of initialisation,
the hlua_ctx_init() function can be called from safe environement,
so we must not initialise it. While the support of threads appear,
the safe environment set a lock to ensure only one Lua execution
at a time. If we initialize safe environment in another safe
environmenet, we have a dead lock.

this patch adds the support of the idicator "already_safe" whoch
indicates if the context is initialized form safe Lua fonction.

thank to Flakebi for the report

This patch must be backported to haproxy-1.9 and haproxy-1.8

6 years agoBUG/MINOR: lua: bad args are returned for Lua actions
Thierry FOURNIER [Sun, 6 Jan 2019 18:38:49 +0000 (19:38 +0100)] 
BUG/MINOR: lua: bad args are returned for Lua actions

In tcp actions case, the argument n - 1 is returned. For example:

  http-request lua.script stuff

display "stuff" as first arg

  tcp-request content lua.script stuff

display "lua.script" as first arg

The action parser doesn't use the *cur_arg value.

Thanks to Andy Franks for the bug report.

This patch mist be backported in haproxy-1.8 and haproxy-1.9

6 years agoMINOR: stream/cli: report more info about the HTTP messages on "show sess all"
Willy Tarreau [Mon, 7 Jan 2019 09:38:10 +0000 (10:38 +0100)] 
MINOR: stream/cli: report more info about the HTTP messages on "show sess all"

The "show sess all" command didn't allow to detect whether compression
is in use for a given stream, which is sometimes annoying. Let's add a
few more info about the HTTP messages, namely the flags, body len, chunk
len and the "next" pointer.

6 years agoMINOR: stream/cli: fix the location of the waiting flag in "show sess all"
Willy Tarreau [Mon, 7 Jan 2019 09:10:07 +0000 (10:10 +0100)] 
MINOR: stream/cli: fix the location of the waiting flag in "show sess all"

The "waiting" flag indicates if the stream is waiting for some memory,
and was placed on the same output line as the txn for ease of reading.
But since 1.6 the txn is not part of the stream anymore so this output
was placed under a condition, resulting in "waiting" to appear only
when a txn is present. Let's move it upper, closer to the stream's
flags to fix this.

This may safely be backported though it has little value for older
versions.

6 years agoMINOR: stream/htx: add the HTX flags output in "show sess all"
Willy Tarreau [Mon, 7 Jan 2019 09:01:34 +0000 (10:01 +0100)] 
MINOR: stream/htx: add the HTX flags output in "show sess all"

Commit b9af88151 ("MINOR: stream/htx: Add info about the HTX structs in
"show sess all" command") accidently forgot the flags on the request
path, it was only on the response path.

It makes sense to backport this to 1.9 so that both outputs are the same.

6 years agoBUILD: add a new file "version.c" to carry version updates
Willy Tarreau [Fri, 4 Jan 2019 17:20:32 +0000 (18:20 +0100)] 
BUILD: add a new file "version.c" to carry version updates

While testing fixes, it's sometimes confusing to rebuild only one C file
(e.g. a mux) and not to have the correct commit ID reported in "haproxy -v"
nor on the stats page.

This patch adds a new "version.c" file which is always rebuilt. It's
very small and contains only 3 variables derived from the various
version strings. These variables are used instead of the macros at the
few places showing the version. This way the output version of the
running code is always correct for the parts that were rebuilt.

6 years agoBUG/MEDIUM: cli: make "show sess" really thread-safe
Willy Tarreau [Fri, 4 Jan 2019 16:42:57 +0000 (17:42 +0100)] 
BUG/MEDIUM: cli: make "show sess" really thread-safe

This one used to rely on a few spin locks around lists manipulations
only but 1) there were still a few races (e.g. when aborting, or
between STAT_ST_INIT and STAT_ST_LIST), and 2) after last commit
which dumps htx info it became obvious that dereferencing the buffer
contents is not safe at all.

This patch uses the thread isolation from the rendez-vous point
instead, to guarantee that nothing moves during the dump. It may
make the dump a bit slower but it will be 100% safe.

This fix must be backported to 1.9, and possibly to 1.8 which likely
suffers from the short races above, eventhough they're extremely
hard to trigger.

6 years agoMINOR: connections: Remove a stall comment.
Olivier Houchard [Fri, 4 Jan 2019 16:22:51 +0000 (17:22 +0100)] 
MINOR: connections: Remove a stall comment.

Remove the comment that pretends 0x40000000 is unused, it's not true anymore.

6 years agoBUG/MEDIUM: server: Defer the mux init until after xprt has been initialized.
Olivier Houchard [Fri, 4 Jan 2019 14:52:26 +0000 (15:52 +0100)] 
BUG/MEDIUM: server: Defer the mux init until after xprt has been initialized.

In connect_server(), if we're using a new connection, and we have to
initialize the mux right away, only do it so after si_connect() has been
called. si_connect() is responsible for initializing the xprt, and the
mux initialization may depend on the xprt being usable, as it may try to
receive data. Otherwise, the connection will be flagged as having an error,
and we will have to try to connect a second time.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: h1: In h1_init(), wake the tasklet instead of calling h1_recv().
Olivier Houchard [Fri, 4 Jan 2019 15:51:40 +0000 (16:51 +0100)] 
BUG/MEDIUM: h1: In h1_init(), wake the tasklet instead of calling h1_recv().

In h1_init(), instead of calling h1_recv() directly, just wake the tasklet,
so that the receive will be done later.
h1_init() might be called from connect_server(), which is itself called
indirectly from process_stream(), and if the receive fails, we may call
si_cs_process(), which may destroy the channel buffers while process_stream()
still expects them to exist.

This should be backported to 1.9.

6 years agoBUG/MINOR: cache/htx: Be sure to count partial trailers
Christopher Faulet [Fri, 4 Jan 2019 15:15:34 +0000 (16:15 +0100)] 
BUG/MINOR: cache/htx: Be sure to count partial trailers

When a chunked object is served from the cache, If the trailers are not pushed
in the channel's buffer in one time, we still have to count them in the total
written bytes in the buffer.

This patch must be backported to 1.9.

6 years agoBUG/MEDIUM: h1: Get the h1m state when restarting the headers parsing
Christopher Faulet [Fri, 4 Jan 2019 15:06:48 +0000 (16:06 +0100)] 
BUG/MEDIUM: h1: Get the h1m state when restarting the headers parsing

Since the commit 0f8fb6b7f ("MINOR: h1: make the H1 headers block parser able to
parse headers only"), when headers are not received in one time, a parsing error
is returned because the local state in the function h1_headers_to_hdr_list() was
not initialized with the previous one (in fact, it was not initialized at all).

So now, we start the parsing of headers with the state H1_MSG_HDR_FIRST when the
flag H1_MF_HDRS_ONLY is set. Otherwise, we always get it from the h1m.

This patch must be backported to 1.9.

6 years agoMINOR: mux-h1: Add the subscription events in "show fd" command
Christopher Faulet [Fri, 4 Jan 2019 14:16:06 +0000 (15:16 +0100)] 
MINOR: mux-h1: Add the subscription events in "show fd" command

It could be helpful to debug frozen connections.

The patch may be backported to 1.9.

6 years agoMINOR: stream: Add the subscription events of SIs in "show sess all" command
Christopher Faulet [Fri, 4 Jan 2019 14:06:13 +0000 (15:06 +0100)] 
MINOR: stream: Add the subscription events of SIs in "show sess all" command

It could be helpful to debug frozen sessions.

The patch may be backported to 1.9.

6 years agoMINOR: stream/htx: Add info about the HTX structs in "show sess all" command
Christopher Faulet [Fri, 4 Jan 2019 13:30:44 +0000 (14:30 +0100)] 
MINOR: stream/htx: Add info about the HTX structs in "show sess all" command

For HTX streams, info about the HTX structure is now dumped for the request and
the response channels in "show sess all" command.

The patch may be backported to 1.9.

6 years agoMEDIUM: mux-h2: emit HEADERS frames when facing HTX trailers blocks
Willy Tarreau [Fri, 4 Jan 2019 09:56:26 +0000 (10:56 +0100)] 
MEDIUM: mux-h2: emit HEADERS frames when facing HTX trailers blocks

Now the H2 mux will parse and encode the HTX trailers blocks and send
the corresponding HEADERS frame. Since these blocks contain pure H1
trailers which may be fragmented on line boundaries, if first needs
to collect all of them, parse them using the H1 parser, build a list
and finally encode all of them at once once the EOM is met. Note that
this HEADERS frame always carries the end-of-headers and end-of-stream
flags.

This was tested using the helloworld examples from the grpc project,
as well as with the h2c tools. It doesn't seem possible at the moment
to test tailers using varnishtest though.

6 years agoMINOR: h1: make the H1 headers block parser able to parse headers only
Willy Tarreau [Fri, 4 Jan 2019 09:48:03 +0000 (10:48 +0100)] 
MINOR: h1: make the H1 headers block parser able to parse headers only

Currently the H1 headers parser works for either a request or a response
because it starts from the start line. It is also able to resume its
processing when it was interrupted, but in this case it doesn't update
the list.

Make it support a new flag, H1_MF_HDRS_ONLY so that the caller can
indicate it's only interested in the headers list and not the start
line. This will be convenient to parse H1 trailers.

6 years agoMINOR: mux-h2: make HTX_BLK_EOM processing idempotent
Willy Tarreau [Fri, 4 Jan 2019 08:28:17 +0000 (09:28 +0100)] 
MINOR: mux-h2: make HTX_BLK_EOM processing idempotent

We want to make sure we won't emit another empty DATA frame if we meet
HTX_BLK_EOM after and end of stream was already sent. For now it cannot
happen as far as HTX is respected, but with trailers it may become
ambiguous.

6 years agoBUG/MEDIUM: mux-h1: don't enforce chunked encoding on requests
Willy Tarreau [Thu, 3 Jan 2019 20:27:19 +0000 (21:27 +0100)] 
BUG/MEDIUM: mux-h1: don't enforce chunked encoding on requests

Recent commit 4710d20 ("BUG/MEDIUM: mux-h1: make HTX chunking
consistent with H2") tried to address chunking inconsistencies between
H1/HTX/H2 and has enforced it on every outgoing message carrying
H1_MF_XFER_LEN without H1_MF_CLEN nor H1_MF_CHNK. But it also does it
on requests, which is not appropriate since a request by default
doesn't have a message body unless explicitly mentioned. Also make
sure we only do this on HTTP/1.1 messages.

The problem is to guarantee the highest level of compatibility between
H1/H1, H1/H2, H2/H1 in each direction regarding the lack of content-
length. We have this truth table (a star '*' indicates which one can
pass trailers) :

  H1 client -> H1 server :
     request:
        CL=0 TE=0 XL=1 -> CL=0 TE=0
        CL=0 TE=1 XL=1 -> CL=0 TE=1 *
        CL=1 TE=0 XL=1 -> CL=1 TE=0
        CL=1 TE=1 XL=1 -> CL=1 TE=1 *

     response:
        CL=0 TE=0 XL=0 -> CL=0 TE=0
        CL=0 TE=1 XL=1 -> CL=0 TE=1 *
        CL=1 TE=0 XL=1 -> CL=1 TE=0
        CL=1 TE=1 XL=1 -> CL=1 TE=1 *

  H2 client -> H1 server : (H2 messages always carry XFER_LEN)
     request:
        CL=0 XL=1 -> CL=0 TE=0
        CL=1 XL=1 -> CL=1 TE=0

     response:
        CL=0 TE=0 XL=0 -> CL=0
        CL=0 TE=1 XL=1 -> CL=0 *
        CL=1 TE=0 XL=1 -> CL=1
        CL=1 TE=1 XL=1 -> CL=1 *

  H1 client -> H2 server : (H2 messages always carry XFER_LEN)
     request:
        CL=0 TE=0 XL=1 -> CL=0
        CL=0 TE=1 XL=1 -> CL=0 *
        CL=1 TE=0 XL=1 -> CL=1
        CL=1 TE=1 XL=1 -> CL=1 *

     response:
        CL=0 XL=1 -> CL=0 TE=1 *
        CL=1 XL=1 -> CL=1 TE=0

For H1 client to H2 server, it will be possible to rely on the presence
of "TE: trailers"  in the H1 request to automatically switch to chunks
in the response, and be able to pass trailers at the end. For now this
check is not implemented so an H2 response missing a content-length to
an H1 request will always have a transfer-encoding header added and
trailers will be forwarded if any.

This patch depends on previous commit "MINOR: mux-h1: parse the
content-length header on output and set H1_MF_CLEN" to work properly.

Since the aforementioned commit is scheduled for backport to 1.9 this
commit must also be backported to 1.9.

6 years agoMINOR: mux-h1: parse the content-length header on output and set H1_MF_CLEN
Willy Tarreau [Thu, 3 Jan 2019 20:52:42 +0000 (21:52 +0100)] 
MINOR: mux-h1: parse the content-length header on output and set H1_MF_CLEN

The H1_MF_CLEN flag is needed to figure whether a content-length header is
present or not when producing a request, so let's check it on output just
like we already check the transfer-encoding header.

6 years agoMEDIUM: mux-h2: pass trailers to HTX
Willy Tarreau [Thu, 3 Jan 2019 17:41:05 +0000 (18:41 +0100)] 
MEDIUM: mux-h2: pass trailers to HTX

When receiving an H2 message in HTX mode, trailers present in chunked
messages are now properly appended to the HTX block.

6 years agoMINOR: h2: add h2_make_htx_trailers to turn H2 headers to HTX trailers
Willy Tarreau [Thu, 3 Jan 2019 17:39:54 +0000 (18:39 +0100)] 
MINOR: h2: add h2_make_htx_trailers to turn H2 headers to HTX trailers

This function is usable to transform a list of H2 header fields to a
HTX trailers block. It takes care of rejecting forbidden headers and
pseudo-headers when performing the conversion. It also emits the
trailing CRLF that is currently needed in the HTX trailers block.

6 years agoMINOR: htx: add a new function to add a block without filling it
Willy Tarreau [Thu, 3 Jan 2019 17:26:17 +0000 (18:26 +0100)] 
MINOR: htx: add a new function to add a block without filling it

htx_add_blk_type_size() creates a block of a specified type and size
and returns it. The caller can then fill it.

6 years agoMEDIUM: mux-h2: pass trailers to H1 (legacy mode)
Willy Tarreau [Thu, 3 Jan 2019 15:18:34 +0000 (16:18 +0100)] 
MEDIUM: mux-h2: pass trailers to H1 (legacy mode)

When forwarding an H2 request to an H1 server, if the request doesn't
have a content-length header field, it is chunked. In this case it is
possible to send trailers to the server, which is what this patch does.
If the transfer is performed without chunking, then the trailers are
silently discarded.

6 years agoMINOR: h2: add h2_make_h1_trailers to turn H2 headers to H1 trailers
Willy Tarreau [Thu, 3 Jan 2019 15:18:14 +0000 (16:18 +0100)] 
MINOR: h2: add h2_make_h1_trailers to turn H2 headers to H1 trailers

This function is usable to transform a list of H2 header fields to a
H1 trailers block. It takes care of rejecting forbidden headers and
pseudo-headers when performing the conversion.

6 years agoBUG/MEDIUM: mux-h2: decode trailers in HEADERS frames
Willy Tarreau [Wed, 2 Jan 2019 18:38:14 +0000 (19:38 +0100)] 
BUG/MEDIUM: mux-h2: decode trailers in HEADERS frames

This is not exactly a bug but a long-time design limitation. We used not
to decode trailers in H2, resulting in broken connections each time a
trailer was sent, since it was impossible to keep the HPACK decompressor
synchronized. Now that the sequencing of operations permits it, we must
make sure to at least properly decode them.

What we try to do is to identify if a HEADERS frame was already seen and
use this indication to know if it's a headers or a trailers. For this,
h2c_decode_headers() checks if the stream indicates that a HEADERS frame
was already received. If so, it decodes it and emits the trailing
0 CRLF CRLF in case of H1, or the HTX_EOD + HTX_EOM blocks in case of HTX,
to terminate the data stream.

The trailers contents are still deleted for now but the request works, and
the connection remains synchronized and usable for subsequent streams.

The correctness may be tested using a simple config and h2spec :

    h2spec -o 1000 -v -t -S -k -h 127.0.0.1 -p 4443 generic/4/4

This should definitely be backported to 1.9 given the low impact for the
benefit. However it cannot be backported to 1.8 since the operations cannot
be resumed. The following patches are also needed with this one :

   MINOR: mux-h2: make h2c_decode_headers() return a status, not a count
   MINOR: mux-h2: add a new dummy stream : h2_error_stream
   MEDIUM: mux-h2: make h2c_decode_headers() support recoverable errors
   BUG/MINOR: mux-h2: detect when the HTX EOM block cannot be added after headers
   MINOR: mux-h2: check for too many streams only for idle streams
   MINOR: mux-h2: set H2_SF_HEADERS_RCVD when a HEADERS frame was decoded

6 years agoMINOR: mux-h2: set H2_SF_HEADERS_RCVD when a HEADERS frame was decoded
Willy Tarreau [Wed, 2 Jan 2019 14:49:20 +0000 (15:49 +0100)] 
MINOR: mux-h2: set H2_SF_HEADERS_RCVD when a HEADERS frame was decoded

Doing this will be needed to be able to tell the difference between a
headers block and a trailers block.

6 years agoMINOR: mux-h2: check for too many streams only for idle streams
Willy Tarreau [Wed, 2 Jan 2019 12:59:43 +0000 (13:59 +0100)] 
MINOR: mux-h2: check for too many streams only for idle streams

The HEADERS frame parser checks if we still have too many streams, but
this should only be done for idle streams, otherwise it would prevent
us from processing trailer frames.

6 years agoCLEANUP: mux-h2: clean the stream error path on HEADERS frame processing
Willy Tarreau [Thu, 3 Jan 2019 10:48:45 +0000 (11:48 +0100)] 
CLEANUP: mux-h2: clean the stream error path on HEADERS frame processing

In h2c_frt_handle_headers() and h2c_bck_handle_headers() we have an unused
error path made of the strm_err label, while send_rst is used to emit an
RST upon stream error after forcing the stream to h2_refused_stream. Let's
remove this unused strm_err block now.