]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
7 years agoMINOR: session: add a streams field to the session struct
Willy Tarreau [Tue, 27 Jun 2017 13:13:43 +0000 (15:13 +0200)] 
MINOR: session: add a streams field to the session struct

This will be used to hold the list of streams belonging to a given session.

7 years agoMINOR: chunks: add chunk_memcpy() and chunk_memcat()
Willy Tarreau [Thu, 27 Jul 2017 11:35:34 +0000 (13:35 +0200)] 
MINOR: chunks: add chunk_memcpy() and chunk_memcat()

These two functions respectively copy a memory area onto the chunk, and
append the contents of a memory area over a chunk. They are convenient
to prepare binary output data to be sent and will be used for HTTP/2.

7 years agoMINOR: dns: default "hold obsolete" timeout set to 0
Baptiste Assmann [Fri, 18 Aug 2017 08:15:42 +0000 (10:15 +0200)] 
MINOR: dns: default "hold obsolete" timeout set to 0

The "hold obsolete" timer is used to prevent HAProxy from moving a server to
an other IP or from considering the server as DOWN if the IP currently
affected to this server has not been seen for this period of time in DNS
responses.

That said, historically, HAProxy used to update servers as soon as the IP
has disappeared from the response. Current default timeout break this
historical behavior and may change HAProxy's behavior when people will
upgrade to 1.8.

This patch changes the default value to 0 to keep backward compatibility.

7 years agoMINOR: dns: enabled edns0 extension and make accpeted payload size tunable
Baptiste Assmann [Sun, 13 Aug 2017 22:13:01 +0000 (00:13 +0200)] 
MINOR: dns: enabled edns0 extension and make accpeted payload size tunable

Edns extensions may be used to negotiate some settings between a DNS
client and a server.
For now we only use it to announce the maximum response payload size accpeted
by HAProxy.
This size can be set through a configuration parameter in the resolvers
section. If not set, it defaults to 512 bytes.

7 years agoMINOR: dns: new dns record type (RTYPE) for OPT
Baptiste Assmann [Sun, 13 Aug 2017 22:04:58 +0000 (00:04 +0200)] 
MINOR: dns: new dns record type (RTYPE) for OPT

DNS record type OPT is required to send additional records.
OPT has been assigned ID 41.

7 years agoMINOR: dns: enable caching of responses for server set by a SRV record
Baptiste Assmann [Mon, 14 Aug 2017 14:35:45 +0000 (16:35 +0200)] 
MINOR: dns: enable caching of responses for server set by a SRV record

The function srv_set_fqdn() is used to update a server's fqdn and set
accordingly its DNS resolution.
Current implementation prevents a server whose update is triggered by a
SRV record from being linked to an existing resolution in the cache (if
applicable).
This patch aims at fixing this.

7 years agoMINOR: dns: ability to use a SRV resolution for multiple backends
Baptiste Assmann [Mon, 14 Aug 2017 14:38:29 +0000 (16:38 +0200)] 
MINOR: dns: ability to use a SRV resolution for multiple backends

Current code implementation prevents multiple backends from relying on
the same SRV resolution. Actually, only the first backend which triggers
the resolution gets updated.

This patch makes HAProxy to process the whole list of the 'curr'
requesters to apply the changes everywhere (hence, the cache also applies
to SRV records...)

7 years agoMINOR: dns: make debugging function dump_dns_config() compatible with SRV records
Baptiste Assmann [Sat, 12 Aug 2017 09:16:55 +0000 (11:16 +0200)] 
MINOR: dns: make debugging function dump_dns_config() compatible with SRV records

This function is particularly useful when debugging DNS resolution at
run time in HAProxy.
SRV records must be read differently, hence we have to update this
function.

7 years agoMINOR: dns: duplicate entries in resolution wait queue for SRV records
Baptiste Assmann [Sat, 12 Aug 2017 07:03:06 +0000 (09:03 +0200)] 
MINOR: dns: duplicate entries in resolution wait queue for SRV records

This loop is useless and duplicates entries into the resolution queue
for nothing.
Entries are already added a bit sooner in the same function.

7 years agoMINOR: dns: update dns response buffer reading pointer due to SRV record
Baptiste Assmann [Fri, 11 Aug 2017 08:37:20 +0000 (10:37 +0200)] 
MINOR: dns: update dns response buffer reading pointer due to SRV record

DNS SRV records uses "dns name compression" to store the target name.
"dns compression" principle is simple. Let's take the name below:
  3336633266663038.red.default.svc.cluster.local.
It can be stored "as is" in the response or it can be compressed like
this:
  3336633266663038<POINTER>
and <POINTER> would point to the string
'.red.default.svc.cluster.local.' availble in the question section for
example.
This mechanism allows storing much more data in a single DNS response.

This means the flag "record->data_len" which stores the size of the
record (hence the whole string, uncompressed) can't be used to move the
pointer forward when reading responses. We must use the "offset" integer
which means the real number of bytes occupied by the target name.

If we don't do that, we can properly read the first SRV record, then we
loose alignment and we start reading unrelated data (still in the
response) leading to a false negative error treated as an "invalid"
response...

7 years agoMINOR: dns: update record dname matching for SRV query types
Baptiste Assmann [Fri, 11 Aug 2017 08:31:22 +0000 (10:31 +0200)] 
MINOR: dns: update record dname matching for SRV query types

DNS response for SRV queries look like this:
- query dname looks like '_http._tcp.red.default.svc.cluster.local'
- answer record dname looks like
  '3336633266663038.red.default.svc.cluster.local.'

Of course, it never matches... and it triggers many false positive in
the current code (which is suitable for A/AAAA/CNAME).

This patch simply ignores this dname matching in the case of SRV query
type.

7 years agoMINOR: dns: Update analysis of TRUNCATED response for SRV records
Baptiste Assmann [Fri, 11 Aug 2017 07:58:27 +0000 (09:58 +0200)] 
MINOR: dns: Update analysis of TRUNCATED response for SRV records

First implementation of the DNS parser used to consider TRUNCATED
responses as errors and triggered a failover to an other query type
(usually A to AAAA or vice-versa).

When we query for SRV records, a TRUNCATED response still contains valid
records we can exploit, so we shouldn't trigger a failover in such case.

Note that we had to move the maching against the flag later in the
response parsing (actually, until we can read the query type....)

7 years agoMINOR: init: Fix CPU affinity setting on FreeBSD.
Olivier Houchard [Wed, 16 Aug 2017 15:29:11 +0000 (17:29 +0200)] 
MINOR: init: Fix CPU affinity setting on FreeBSD.

Use a cpuset_t instead of assuming the cpu mask is an unsigned long.
This should fix setting the CPU affinity on FreeBSD >= 11.

This patch should be backported to stable releases.

7 years agoCLEANUP: raw_sock: Use a better name for the constructor than __ssl_sock_deinit()
Olivier Houchard [Mon, 14 Aug 2017 13:59:44 +0000 (15:59 +0200)] 
CLEANUP: raw_sock: Use a better name for the constructor than __ssl_sock_deinit()

I just noticed the raw socket constructor was called __ssl_sock_deinit,
which is a bit confusing, and wrong twice, so the attached patch renames it
to __raw_sock_init, which seems more correct.

7 years agoBUG/MAJOR: stream: in stream_free(), close the front endpoint and not the origin
Willy Tarreau [Thu, 17 Aug 2017 13:54:46 +0000 (15:54 +0200)] 
BUG/MAJOR: stream: in stream_free(), close the front endpoint and not the origin

stream_free() used to close the front connection by using s->sess->origin,
instead of using s->si[0].end. This is very visible in HTTP/2 where the
front connection is abusively closed and causes all sort of issues including
crashes caused by double closes due to the same origin being referenced many
times.

It's also suspected that it may have caused some of the early issues met
during the Lua development.

It's uncertain whether stable branches are affected. It might be worth
backporting it once it has been confirmed not to create new impacts.

7 years agoBUILD/MINOR: build without openssl still broken
Willy Tarreau [Wed, 16 Aug 2017 13:35:19 +0000 (15:35 +0200)] 
BUILD/MINOR: build without openssl still broken

As mentionned in commit cf4e496c9 ("BUG/MEDIUM: build without openssl broken"),
commit 872f9c213 ("MEDIUM: ssl: add basic support for OpenSSL crypto engine")
broke the build without openssl support. But the former did only fix it when
openssl is not enabled, but not when it's not installed on the system :

In file included from src/haproxy.c:112:
include/proto/ssl_sock.h:24:25: openssl/ssl.h: No such file or directory
In file included from src/haproxy.c:112:
include/proto/ssl_sock.h:45: error: syntax error before "SSL_CTX"
include/proto/ssl_sock.h:75: error: syntax error before '*' token
include/proto/ssl_sock.h:75: warning: type defaults to `int' in declaration of `ssl_sock_create_cert'
include/proto/ssl_sock.h:75: warning: data definition has no type or storage class
include/proto/ssl_sock.h:76: error: syntax error before '*' token
include/proto/ssl_sock.h:76: warning: type defaults to `int' in declaration of `ssl_sock_get_generated_cert'
include/proto/ssl_sock.h:76: warning: data definition has no type or storage class
include/proto/ssl_sock.h:77: error: syntax error before '*' token

Now we also surround the include with #ifdef USE_OPENSSL to fix this. No
backport is needed since openssl async engines were not backported.

7 years agoBUILD: ssl: replace SSL_CTX_get0_privatekey for openssl < 1.0.2
Emmanuel Hocdet [Fri, 11 Aug 2017 08:56:00 +0000 (10:56 +0200)] 
BUILD: ssl: replace SSL_CTX_get0_privatekey for openssl < 1.0.2

Commit 48a8332a introduce SSL_CTX_get0_privatekey in openssl-compat.h but
SSL_CTX_get0_privatekey access internal structure and can't be a candidate
to openssl-compat.h. The workaround with openssl < 1.0.2 is to use SSL_new
then SSL_get_privatekey.

7 years agoBUILD/MINOR: cli: shut a minor gcc warning in "show fd"
Willy Tarreau [Wed, 9 Aug 2017 14:35:44 +0000 (16:35 +0200)] 
BUILD/MINOR: cli: shut a minor gcc warning in "show fd"

Recent commit 7a4a0ac ("MINOR: cli: add a new "show fd" command") introduced
a warning when building at -O2 and above. The compiler doesn't know if a
variable's value might have changed between two if blocks so warns that some
values might be used uninitialized, which is not the case. Let's simply
initialize them to shut the warning.

7 years agoMINOR: doc: Document SRV label usage.
Olivier Houchard [Mon, 7 Aug 2017 15:30:03 +0000 (17:30 +0200)] 
MINOR: doc: Document SRV label usage.

7 years agoMINOR: check: Fix checks when using SRV records.
Olivier Houchard [Fri, 4 Aug 2017 16:39:01 +0000 (18:39 +0200)] 
MINOR: check: Fix checks when using SRV records.

When started, a server may not yet have an associated protocol, so don't
bother trying to run the checks until it is there.

7 years agoMINOR: dns: Handle SRV records.
Olivier Houchard [Fri, 4 Aug 2017 16:35:36 +0000 (18:35 +0200)] 
MINOR: dns: Handle SRV records.

Make it so for each server, instead of specifying a hostname, one can use
a SRV label.
When doing so, haproxy will first resolve the SRV label, then use the
resulting hostnames, as well as port and weight (priority is ignored right
now), to each server using the SRV label.
It is resolved periodically, and any server disappearing from the SRV records
will be removed, and any server appearing will be added, assuming there're
free servers in haproxy.

7 years agoAdd a few functions to do unaligned access.
Olivier Houchard [Mon, 7 Aug 2017 17:20:04 +0000 (19:20 +0200)] 
Add a few functions to do unaligned access.

Add a few functions to read 16bits and 32bits integers that may be
unaligned, both in host and network order.

7 years agoMINOR: obj: Add a new type of object, OBJ_TYPE_SRVRQ.
Olivier Houchard [Fri, 4 Aug 2017 16:31:56 +0000 (18:31 +0200)] 
MINOR: obj: Add a new type of object, OBJ_TYPE_SRVRQ.

dns_srvrq will be objects used for dealing with SRV records.

7 years agoMINOR: dns: Cache previous DNS answers.
Olivier Houchard [Thu, 6 Jul 2017 16:46:47 +0000 (18:46 +0200)] 
MINOR: dns: Cache previous DNS answers.

As DNS servers may not return all IPs in one answer, we want to cache the
previous entries. Those entries are removed when considered obsolete, which
happens when the IP hasn't been returned by the DNS server for a time
defined in the "hold obsolete" parameter of the resolver section. The default
is 30s.

7 years agoMINOR: ssl: allow to start without certificate if strict-sni is set
Emmanuel Hocdet [Wed, 9 Aug 2017 09:24:25 +0000 (11:24 +0200)] 
MINOR: ssl: allow to start without certificate if strict-sni is set

With strict-sni, ssl connection will fail if no certificate match. Have no
certificate in bind line, fail on all ssl connections. It's ok with the
behavior of strict-sni. When 'generate-certificates' is set 'strict-sni' is
never used. When 'strict-sni' is set, default_ctx is never used. Allow to start
without certificate only in this case.

Use case is to start haproxy with ssl before customer start to use certificates.
Typically with 'crt' on a empty directory and 'strict-sni' parameters.

7 years agoMINOR: Add server port field to server state file.
Frédéric Lécaille [Tue, 1 Aug 2017 06:47:19 +0000 (08:47 +0200)] 
MINOR: Add server port field to server state file.

This patch adds server ports to server state file at the end of each line
for backward compatibility.

7 years agoBUG/MEDIUM: ssl: Fix regression about certificates generation
Christopher Faulet [Fri, 28 Jul 2017 14:56:09 +0000 (16:56 +0200)] 
BUG/MEDIUM: ssl: Fix regression about certificates generation

Since the commit f6b37c67 ["BUG/MEDIUM: ssl: in bind line, ssl-options after
'crt' are ignored."], the certificates generation is broken.

To generate a certificate, we retrieved the private key of the default
certificate using the SSL object. But since the commit f6b37c67, the SSL object
is created with a dummy certificate (initial_ctx).

So to fix the bug, we use directly the default certificate in the bind_conf
structure. We use SSL_CTX_get0_privatekey function to do so. Because this
function does not exist for OpenSSL < 1.0.2 and for LibreSSL, it has been added
in openssl-compat.h with the right #ifdef.

7 years agoMINOR: cli: add a new "show fd" command
Willy Tarreau [Tue, 25 Jul 2017 17:32:50 +0000 (19:32 +0200)] 
MINOR: cli: add a new "show fd" command

This one dumps the fdtab for all active FDs with some quickly interpretable
characters to read the flags (like upper case=set, lower case=unset). It
can probably be improved to report fdupdt[] and/or fdinfo[] but at least it
provides a good start and allows to see how FDs are seen. When the fd owner
is a connection, its flags are also reported as it can help compare with the
polling status, and the target (fe/px/sv) as well. When it's a listener, the
listener's state is reported as well as the frontend it belongs to.

7 years agoMINOR: listener: add a function to return a listener's state as a string
Willy Tarreau [Tue, 25 Jul 2017 17:46:06 +0000 (19:46 +0200)] 
MINOR: listener: add a function to return a listener's state as a string

This will be used in debugging output, so it's a short 3-character string.

7 years agoDOC: fix alphabetical order of "show commands" in management.txt
Willy Tarreau [Fri, 28 Jul 2017 14:52:23 +0000 (16:52 +0200)] 
DOC: fix alphabetical order of "show commands" in management.txt

"show acl" and "show backend" were misplaced.

7 years agoBUG/MINOR: lua: Fix bitwise logic for hlua_server_check_* functions.
Adis Nezirovic [Wed, 26 Jul 2017 07:19:06 +0000 (09:19 +0200)] 
BUG/MINOR: lua: Fix bitwise logic for hlua_server_check_* functions.

The logical operations were inverted so enable/disable operations did
the opposite.

The bug is present since 1.7 so the fix should be backported there.

7 years agoMINOR: ssl: add "no-ca-names" parameter for bind
Emmanuel Hocdet [Fri, 28 Jul 2017 13:01:05 +0000 (15:01 +0200)] 
MINOR: ssl: add "no-ca-names" parameter for bind

This option prevent to send CA names in server hello message when
ca-file is used. This parameter is also available in "crt-list".

7 years agoBUG/MEDIUM: stream: don't retry SSL connections which fail the SNI name check
Willy Tarreau [Wed, 26 Jul 2017 18:13:37 +0000 (20:13 +0200)] 
BUG/MEDIUM: stream: don't retry SSL connections which fail the SNI name check

Commits 2ab8867 ("MINOR: ssl: compare server certificate names to the
SNI on outgoing connections") and 96c7b8d ("BUG/MINOR: ssl: Fix check
against SNI during server certificate verification") made it possible
to check that the server's certificate matches the name presented in
the SNI field. While it solves a class of problems, it opens another
one which is that by failing such a connection, we'll retry it and put
more load on the server. It can be a real problem if a user can trigger
this issue, which is what will very often happen when the SNI is forwarded
from the client to the server.

This patch solves this by detecting that this very specific hostname
verification failed and that the hostname was provided using SNI, and
then it simply disables retries and the failure is immediate.

At the time of writing this patch, the previous patches were not backported
(yet), so no backport is needed for this one unless the aforementionned
patches are backported as well. This patch requires previous patches
"BUG/MINOR: ssl: make use of the name in SNI before verifyhost" and
"MINOR: ssl: add a new error code for wrong server certificates".

7 years agoMINOR: ssl: add a new error codes for wrong server certificates
Willy Tarreau [Wed, 26 Jul 2017 18:09:56 +0000 (20:09 +0200)] 
MINOR: ssl: add a new error codes for wrong server certificates

If a server presents an unexpected certificate to haproxy, that is, a
certificate that doesn't match the expected name as configured in
verifyhost or as requested using SNI, we want to store that precious
information. Fortunately we have access to the connection in the
verification callback so it's possible to store an error code there.

For this purpose we use CO_ER_SSL_MISMATCH_SNI (for when the cert name
didn't match the one requested using SNI) and CO_ER_SSL_MISMATCH for
when it doesn't match verifyhost.

7 years agoBUG/MINOR: ssl: make use of the name in SNI before verifyhost
Willy Tarreau [Fri, 28 Jul 2017 09:38:41 +0000 (11:38 +0200)] 
BUG/MINOR: ssl: make use of the name in SNI before verifyhost

Commit 2ab8867 ("MINOR: ssl: compare server certificate names to the SNI
on outgoing connections") introduced the ability to check server cert
names against the name provided with in the SNI, but verifyhost was kept
as a way to force the name to check against. This was a mistake, because :
  - if an SNI is used, any static hostname in verifyhost will be wrong ;
    worse, if it matches and doesn't match the SNI, the server presented
    the wrong certificate ;

  - there's no way to have a default name to check against for health
    checks anymore because the point above mandates the removal of the
    verifyhost directive

This patch reverses the ordering of the check : whenever SNI is used, the
name provided always has precedence (ie the server must always present a
certificate that matches the requested name). And if no SNI is provided,
then verifyhost is used, and will be configured to match the server's
default certificate name. This will work both when SNI is not used and
for health checks.

If the commit 2ab8867 is backported in 1.7 and/or 1.6, this one must be
backported too.

7 years agoBUG/MINOR: ssl: Fix check against SNI during server certificate verification
Christopher Faulet [Wed, 26 Jul 2017 09:50:01 +0000 (11:50 +0200)] 
BUG/MINOR: ssl: Fix check against SNI during server certificate verification

This patch fixes the commit 2ab8867 ("MINOR: ssl: compare server certificate
names to the SNI on outgoing connections")

When we check the certificate sent by a server, in the verify callback, we get
the SNI from the session (SSL_SESSION object). In OpenSSL, tlsext_hostname value
for this session is copied from the ssl connection (SSL object). But the copy is
done only if the "server_name" extension is found in the server hello
message. This means the server has found a certificate matching the client's
SNI.

When the server returns a default certificate not matching the client's SNI, it
doesn't set any "server_name" extension in the server hello message. So no SNI
is set on the SSL session and SSL_SESSION_get0_hostname always returns NULL.

To fix the problemn, we get the SNI directly from the SSL connection. It is
always defined with the value set by the client.

If the commit 2ab8867 is backported in 1.7 and/or 1.6, this one must be
backported too.

Note: it's worth mentionning that by making the SNI check work, we
      introduce another problem by which failed SNI checks can cause
      long connection retries on the server, and in certain cases the
      SNI value used comes from the client. So this patch series must
      not be backported until this issue is resolved.

7 years agoMINOR: lua: Add lists of frontends and backends
Thierry FOURNIER [Mon, 24 Jul 2017 11:30:43 +0000 (13:30 +0200)] 
MINOR: lua: Add lists of frontends and backends

Adis Nezirovic reports:

   While playing with Lua API I've noticed that core.proxies attribute
   doesn't return all the proxies, more precisely the ones with same names
   (e.g. for frontend and backend with the same name it would only return
   the latter one).

So, this patch fixes this problem without breaking the actual behaviour.
We have two case of proxies with frontend/backend capabilities:

The first case is the listen. This case is not a problem because the
proxy object process these two entities as only one and it is the
expected behavior. With these case the "proxies" list works fine.

The second case is the frontend and backend with the same name. i think
that this case is possible for compatibility with 'listen' declaration.
These two proxes with same name and different capabilities must not
processed with the same object (different statitics, differents orders).
In fact, one the the two object crush the other one whoch is no longer
accessible.

To fix this problem, this patch adds two lists which are "frontends" and
"backends", each of these list contains specialized proxy, but warning
the "listen" proxy are declare in each list.

7 years agoDOC: lua: Proxy class doc update
Thierry FOURNIER [Mon, 24 Jul 2017 12:35:04 +0000 (14:35 +0200)] 
DOC: lua: Proxy class doc update

Following the patch adding the name of the proxy, this patch contains
the associated doc update.

7 years agoMINOR: lua: Add proxy as member of proxy object.
Thierry FOURNIER [Mon, 24 Jul 2017 11:59:22 +0000 (13:59 +0200)] 
MINOR: lua: Add proxy as member of proxy object.

By Adis Nezirovic:

   This is just for convenience and uniformity, Proxy.servers/listeners
   returns a table/hash of objects with names as keys, but for example when
   I want to pass such object to some other Lua function I have to manually
   copy the name (or wrap the object), since the object itself doesn't
   expose name info.

This patch simply adds the proxy name as member of the proxy object.

7 years agoBUG/MAJOR: lua: properly dequeue hlua_applet_wakeup() for new scheduler
Willy Tarreau [Fri, 21 Jul 2017 14:41:56 +0000 (16:41 +0200)] 
BUG/MAJOR: lua: properly dequeue hlua_applet_wakeup() for new scheduler

The recent scheduler change broke the Lua co-sockets due to
hlua_applet_wakeup() returning NULL after waking the applet up. With the
previous scheduler, returning NULL was a way to do nothing on return.

With the new one it keeps TASK_RUNNING set, causing all new notifications
to end up into t->pending_state instead of t->state, and prevents the
task from being added into the run queue again, so and it's never woken
up anymore.

The applet keeps waking up, causing hlua_socket_handler() to do nothing
new, then si_applet_wake_cb() calling stream_int_notify() to try to wake
the task up, which it can't do due to the TASK_RUNNING flag, then decide
that since the associated task is not in the run queue, it needs to call
stream_int_update_applet() to propagate the update. This last one finds
that the applet needs to be woken up to deal with the last reported events
and calling appctx_wakeup() again. Previously, this situation didn't exist
because the task was always added in the run queue despite the TASK_RUNNING
flag.

By returning the task instead in hlua_applet_wakeup(), we can ensure its
flag is properly cleared and the task is requeued if needed or just sits
waiting for new events to happen.

This fix requires the previous ones ("BUG/MINOR: lua: always detach the
tcp/http tasks before freeing them") and MINOR: task: always preinitialize
the task's timeout in task_init().

Thanks to Thierry, Christopher and Emeric for the long head-scratching
session!

No backport is needed as the bug doesn't appear in older versions and
it's unsure whether we'll not break something by backporting it.

7 years agoCLEANUP: task: remove all initializations to TICK_ETERNITY after task_new()
Willy Tarreau [Mon, 24 Jul 2017 15:55:20 +0000 (17:55 +0200)] 
CLEANUP: task: remove all initializations to TICK_ETERNITY after task_new()

This is now guaranteed by design, simply remove these unneeded parts to
avoid confusion.

7 years agoMINOR: task: always preinitialize the task's timeout in task_init()
Willy Tarreau [Mon, 24 Jul 2017 15:52:58 +0000 (17:52 +0200)] 
MINOR: task: always preinitialize the task's timeout in task_init()

task_init() is called exclusively by task_new() which is the only way
to create a task. Most callers set t->expire to TICK_ETERNITY, some set
it to another value and a few like Lua don't set it at all as they don't
need a timeout, causing random values to be used in case the task gets
queued.

Let's always set t->expire to TICK_ETERNITY in task_init() so that all
tasks are now initialized in a clean state.

This patch can be backported as it will definitely make the code more
robust (at least the Lua code, possibly other places).

7 years agoBUG/MINOR: lua: always detach the tcp/http tasks before freeing them
Willy Tarreau [Mon, 24 Jul 2017 15:35:27 +0000 (17:35 +0200)] 
BUG/MINOR: lua: always detach the tcp/http tasks before freeing them

In hlua_{http,tcp}_applet_release(), a call to task_free() is performed
to release the task, but no task_delete() is made on these tasks. Till
now it wasn't much of a problem because this was normally not done with
the task in the run queue, and the task was never put into the wait queue
since it doesn't have any timer. But with threading it will become an
issue. And not having this already prevents another bug from being fixed.

Thanks to Christopher for spotting this one. A backport to 1.7 and 1.6 is
preferred for safety.

7 years agoMINOR: samples: Don't allocate memory for SMP_T_METH sample when method is known
Christopher Faulet [Mon, 24 Jul 2017 14:24:39 +0000 (16:24 +0200)] 
MINOR: samples: Don't allocate memory for SMP_T_METH sample when method is known

For known methods (GET,POST...), in samples, an enum is used instead of a chunk
to reference the method. So there is no needs to allocate memory when a variable
is stored with this kind of sample.

7 years agoMINOR: samples: Handle the type SMP_T_METH in smp_is_safe and smp_is_rw
Christopher Faulet [Mon, 24 Jul 2017 14:07:12 +0000 (16:07 +0200)] 
MINOR: samples: Handle the type SMP_T_METH in smp_is_safe and smp_is_rw

For all known methods, samples are considered as safe and rewritable. For
unknowns, we handle them like strings (SMP_T_STR).

7 years agoMINOR: samples: Handle the type SMP_T_METH when we duplicate a sample in smp_dup
Christopher Faulet [Mon, 24 Jul 2017 13:38:41 +0000 (15:38 +0200)] 
MINOR: samples: Handle the type SMP_T_METH when we duplicate a sample in smp_dup

First, the type SMP_T_METH was not handled by smp_dup function. It was never
called with this kind of samples, so it's not really a problem. But, this could
be useful in future.

For all known HTTP methods (GET, POST...), there is no extra space allocated for
a sample of type SMP_T_METH. But for unkown methods, it uses a chunk. So, like
for strings, we duplicate data, using a trash chunk.

7 years agoBUG/MINOR: lua: Correctly use INET6_ADDRSTRLEN in Server.get_addr()
Nenad Merdanovic [Mon, 24 Jul 2017 02:04:59 +0000 (22:04 -0400)] 
BUG/MINOR: lua: Correctly use INET6_ADDRSTRLEN in Server.get_addr()

The get_addr() method of the Lua Server class incorrectly used
INET_ADDRSTRLEN for IPv6 addresses resulting in failing to convert
longer IPv6 addresses to strings.

This fix should be backported to 1.7.

7 years agoBUG/MINOR: lua: Fix Server.get_addr() port values
Nenad Merdanovic [Mon, 24 Jul 2017 02:04:58 +0000 (22:04 -0400)] 
BUG/MINOR: lua: Fix Server.get_addr() port values

The get_addr() method of the Lua Server class was using the
'sockaddr_storage addr' member to get the port value. HAProxy does not
store ports in this member as it uses a separate member, called
'svc_port'.

This fix should be backported to 1.7.

7 years agoMINOR: memory: remove macros
David Carlier [Fri, 21 Jul 2017 07:44:40 +0000 (08:44 +0100)] 
MINOR: memory: remove macros

We finally get rid of the macros and use usual memory management
functions directly.

7 years agoBUG/MAJOR: http: Fix possible infinity loop in http_sync_(req|res)_state
Christopher Faulet [Thu, 20 Jul 2017 09:05:10 +0000 (11:05 +0200)] 
BUG/MAJOR: http: Fix possible infinity loop in http_sync_(req|res)_state

In commit "MINOR: http: Switch requests/responses in TUNNEL mode only by
checking txn flags", it is possible to have an infinite loop on HTTP_MSG_CLOSING
state.

7 years agoDOC: Updated 51Degrees git URL to point to a stable version.
ben51degrees [Wed, 19 Jul 2017 15:22:04 +0000 (16:22 +0100)] 
DOC: Updated 51Degrees git URL to point to a stable version.

The previously documented location doesn't work anymore and must not be
used. Warning for backports, different branches are in use depending on
the version (v3.2.10 for 1.7, v3.2.5 for 1.6).

7 years agoBUILD: lua: replace timegm() with my_timegm() to fix build on Solaris 10
Willy Tarreau [Wed, 19 Jul 2017 17:08:48 +0000 (19:08 +0200)] 
BUILD: lua: replace timegm() with my_timegm() to fix build on Solaris 10

Akhnin Nikita reported that Lua doesn't build on Solaris 10 because
the code uses timegm() to parse a date, which is not provided there.
The recommended way to implement timegm() is broken in the man page,
as it is based on a change of the TZ environment variable at run time
before calling the function (which is obviously not thread safe, and
terribly inefficient).

Here instead we rely on the new my_timegm() function, it should be
sufficient for all known use cases.

7 years agoMINOR: tools: add a portable timegm() alternative
Willy Tarreau [Wed, 19 Jul 2017 17:05:29 +0000 (19:05 +0200)] 
MINOR: tools: add a portable timegm() alternative

timegm() is not provided everywhere and the documentation on how to
replace it is bogus as it proposes an inefficient and non-thread safe
alternative.

Here we reimplement everything needed to compute the number of seconds
since Epoch based on the broken down fields in struct tm. It is only
guaranteed to return correct values for correct inputs. It was successfully
tested with all possible 32-bit values of time_t converted to struct tm
using gmtime() and back to time_t using the legacy timegm() and this
function, and both functions always produced the same result.

Thanks to Benoît Garnier for an instructive discussion and detailed
explanations of the various time functions, leading to this solution.

7 years agoBUILD: ssl: fix compatibility with openssl without TLSEXT_signature_*
Emmanuel Hocdet [Wed, 19 Jul 2017 14:04:05 +0000 (16:04 +0200)] 
BUILD: ssl: fix compatibility with openssl without TLSEXT_signature_*

In openssl < 1.0.1, TLSEXT_signature_* is undefined. Add TLSEXT signatures
(RFC 5246) when TLSEXT_signature_anonymous is undefined.

7 years agoMINOR: ssl: remove an unecessary SSL_OP_NO_* dependancy
Emmanuel Hocdet [Wed, 12 Jul 2017 12:25:38 +0000 (14:25 +0200)] 
MINOR: ssl: remove an unecessary SSL_OP_NO_* dependancy

Use methodVersions table to display "OpenSSL library supports".

7 years agoBUG/MINOR: ssl: remove haproxy SSLv3 support when ssl lib have no SSLv3
Emmanuel Hocdet [Wed, 12 Jul 2017 10:53:02 +0000 (12:53 +0200)] 
BUG/MINOR: ssl: remove haproxy SSLv3 support when ssl lib have no SSLv3

The commit 5db33cbd "MEDIUM: ssl: ssl_methods implementation is reworked and
factored for min/max tlsxx" drop the case when ssl lib have removed SSLv3.
The commit 1e59fcc5 "BUG/MINOR: ssl: Be sure that SSLv3 connection methods
exist for openssl < 1.1.0" fix build but it's false because haproxy think
that ssl lib support SSLv3.

SSL_OP_NO_* are flags to set in ssl_options and is the way haproxy do the
link between ssl capabilities and haproxy configuration. (The mapping table
is done via methodVersions). SSL_OP_NO_* is set to 0 when ssl lib doesn't
support a new TLS version. Older version (like SSLv3) can be removed at
build or unsupported (like libressl). In all case OPENSSL_NO_SSL3 is define.

To keep the same logic, this patch alter SSL_OP_NO_SSLv3 to 0 when SSLv3 is
not supported by ssl lib (when OPENSSL_NO_SSL3 is define).

7 years agoBUG/MINOR: contrib/mod_defender: build fix
David Carlier [Wed, 7 Jun 2017 11:39:16 +0000 (12:39 +0100)] 
BUG/MINOR: contrib/mod_defender: build fix

In similar manner than modsecurity, making the build possible under *BSD flavors, the -lm for ceilf function.

7 years agoBUG/MINOR: contrib/modsecurity: BSD build fix
David Carlier [Tue, 6 Jun 2017 09:20:51 +0000 (10:20 +0100)] 
BUG/MINOR: contrib/modsecurity: BSD build fix

previous version introduced in the last commit was not the correct one.

7 years agoBUG/MINOR: http: Fix bug introduced in previous patch in http_resync_states
Christopher Faulet [Tue, 18 Jul 2017 20:01:05 +0000 (22:01 +0200)] 
BUG/MINOR: http: Fix bug introduced in previous patch in http_resync_states

The previous patch ("MINOR: http: Rely on analyzers mask to end processing in
forward_body functions") contains a bug for keep-alive transactions.

For these transactions, AN_REQ_FLT_END and AN_RES_FLT_END analyzers must be
removed only when all outgoing data was forwarded.

8 years agoMINOR: http: Rely on analyzers mask to end processing in forward_body functions
Christopher Faulet [Tue, 18 Jul 2017 09:29:07 +0000 (11:29 +0200)] 
MINOR: http: Rely on analyzers mask to end processing in forward_body functions

Instead of relying on request or response state, we use "chn->analysers" mask as
all other analyzers. So now, http_resync_states does not return anything
anymore.

The debug message in http_resync_states has been improved.

8 years agoBUG/MEDIUM: http: Switch HTTP responses in TUNNEL mode when body length is undefined
Christopher Faulet [Tue, 18 Jul 2017 09:42:08 +0000 (11:42 +0200)] 
BUG/MEDIUM: http: Switch HTTP responses in TUNNEL mode when body length is undefined

When the body length of a HTTP response is undefined, the HTTP parser is blocked
in the body parsing. Before HAProxy 1.7, in this case, because
AN_RES_HTTP_XFER_BODY is never set, there is no visible effect. When the server
closes its connection to terminate the response, HAProxy catches it as a normal
closure. Since 1.7, we always set this analyzer to enter at least once in
http_response_forward_body. But, in the present case, when the server connection
is closed, http_response_forward_body is called one time too many. The response
is correctly sent to the client, but an error is catched and logged with "SD--"
flags.

To reproduce the bug, you can use the configuration "tests/test-fsm.cfg". The
tests 3 and 21 hit the bug.

Idea to fix the bug is to switch the response in TUNNEL mode without switching
the request. This is possible because of previous patches.

First, we need to detect responses with undefined body length during states
synchronization. Excluding tunnelled transactions, when the response length is
undefined, TX_CON_WANT_CLO is always set on the transaction. So, when states are
synchronized, if TX_CON_WANT_CLO is set, the response is switched in TUNNEL mode
and the request remains unchanged.

Then, in http_msg_forward_body, we add a specific check to switch the response
in DONE mode if the body length is undefined and if there is no data filter.

This patch depends on following previous commits:

  * MINOR: http: Switch requests/responses in TUNNEL mode only by checking txn flags
  * MINOR: http: Reorder/rewrite checks in http_resync_states

This patch must be backported in 1.7 with 2 previous ones.

8 years agoMINOR: http: Switch requests/responses in TUNNEL mode only by checking txn flags
Christopher Faulet [Tue, 18 Jul 2017 08:48:24 +0000 (10:48 +0200)] 
MINOR: http: Switch requests/responses in TUNNEL mode only by checking txn flags

Today, the only way to have a request or a response in HTTP_MSG_TUNNEL state is
to have the flag TX_CON_WANT_TUN set on the transaction. So this is a symmetric
state. Both the request and the response are switch in same time in this
state. This can be done only by checking transaction flags instead of relying on
the other side state. This is the purpose of this patch.

This way, if for any reason we need to switch only one side in TUNNEL mode, it
will be possible. And to prepare asymmetric cases, we check channel flags in
DONE _AND_ TUNNEL states.

WARNING: This patch will be used to fix a bug. The fix will be commited in a
very next commit. So if the fix is backported, this one must be backported too.

8 years agoMINOR: http: Reorder/rewrite checks in http_resync_states
Christopher Faulet [Tue, 18 Jul 2017 09:18:46 +0000 (11:18 +0200)] 
MINOR: http: Reorder/rewrite checks in http_resync_states

The previous patch removed the forced symmetry of the TUNNEL mode during the
state synchronization. Here, we take care to remove body analyzer only on the
channel in TUNNEL mode. In fact, today, this change has no effect because both
sides are switched in same time. But this way, with some changes, it will be
possible to keep body analyzer on a side (to finish the states synchronization)
with the other one in TUNNEL mode.

WARNING: This patch will be used to fix a bug. The fix will be commited in a
very next commit. So if the fix is backported, this one must be backported too.

8 years agoBUG/MINOR: http: Set the response error state in http_sync_res_state
Christopher Faulet [Tue, 18 Jul 2017 08:35:55 +0000 (10:35 +0200)] 
BUG/MINOR: http: Set the response error state in http_sync_res_state

This is just typo. It may only report a wrong response message state in
"show errors" on the CLI.

This patch must be backported in 1.7.

8 years agoDOC: update the list of OpenSSL versions in the README
Willy Tarreau [Tue, 18 Jul 2017 04:58:16 +0000 (06:58 +0200)] 
DOC: update the list of OpenSSL versions in the README

1.1.0 is also supported nowadays. Also mention the best effort support
for derivatives.

8 years agoDOC: update CONTRIBUTING regarding optional parts and message format
Willy Tarreau [Tue, 18 Jul 2017 04:56:40 +0000 (06:56 +0200)] 
DOC: update CONTRIBUTING regarding optional parts and message format

Make it clear that optional components must not break when disabled,
that openssl is the only officially supported library and its support
must not be broken, and that bug fixes must always be detailed.

8 years agoBUG/MINOR: Lua: variable already initialized
Thierry FOURNIER [Sun, 16 Jul 2017 14:35:53 +0000 (16:35 +0200)] 
BUG/MINOR: Lua: variable already initialized

The variable strm->hlua is already initilized by the function stream_new().

8 years agoBUG/MEDIUM: lua: bad memory access
Thierry FOURNIER [Sun, 16 Jul 2017 22:44:40 +0000 (00:44 +0200)] 
BUG/MEDIUM: lua: bad memory access

We cannot perform garbage collection on unreferenced thread.
This memory is now free and another Lua process can use it for
other things.

HAProxy is monothread, so this bug doesn't cause crash.

This patch must be backported in 1.6 and 1.7

8 years agoBUG/MAJOR: lua/socket: resources not detroyed when the socket is aborted
Thierry FOURNIER [Sun, 16 Jul 2017 18:48:54 +0000 (20:48 +0200)] 
BUG/MAJOR: lua/socket: resources not detroyed when the socket is aborted

In some cases, the socket is misused. The user can open socket and never
close it, or open the socket and close it without sending data. This
causes resources leak on all resources associated to the stream (buffer,
spoe, ...)

This is caused by the stream_shutdown function which is called outside
of the stream execution process. Sometimes, the shtudown is required
while the stream is not started, so the cleanup is ignored.

This patch change the shutdown mode of the session. Now if the session is
no longer used and the Lua want to destroy it, it just set a destroy flag
and the session kill itself.

This patch should be backported in 1.6 and 1.7

8 years agoBUG/MINOR: lua: executes the function destroying the Lua session in safe mode
Thierry FOURNIER [Wed, 12 Jul 2017 11:41:33 +0000 (13:41 +0200)] 
BUG/MINOR: lua: executes the function destroying the Lua session in safe mode

When we destroy the Lua session, we manipulates Lua stack,
so errors can raises. It will be better to catch these errors.

This patch should be backported in 1.6 and 1.7

8 years agoBUG/MINOR: lua: In error case, the safe mode is not removed
Thierry FOURNIER [Wed, 12 Jul 2017 09:18:00 +0000 (11:18 +0200)] 
BUG/MINOR: lua: In error case, the safe mode is not removed

Just forgot of reset the safe mode. This have not consequences
the safe mode just set a pointer on fucntion which is called only
and initialises a longjmp.

Out of lua execution, this longjmp is never executed and the
function is never called.

This patch should be backported in 1.6 and 1.7

8 years agoBUG/MINOR: Prevent a use-after-free on error scenario on option "-x".
Olivier Houchard [Mon, 17 Jul 2017 15:25:33 +0000 (17:25 +0200)] 
BUG/MINOR: Prevent a use-after-free on error scenario on option "-x".

This was introduced with recent commit f73629d ("MINOR: global: Add an
option to get the old listening sockets."). No backport is needed.

8 years agoCLEANUP: hdr_idx: make some function arguments const where possible
Willy Tarreau [Mon, 17 Jul 2017 18:46:05 +0000 (20:46 +0200)] 
CLEANUP: hdr_idx: make some function arguments const where possible

Functions hdr_idx_first_idx() and hdr_idx_first_pos() were missing a
"const" qualifier on their arguments which are not modified, causing
a warning in some experimental H2 code.

8 years agoBUG/MINOR: peers: peer synchronization issue (with several peers sections).
Frédéric Lécaille [Thu, 13 Jul 2017 07:07:09 +0000 (09:07 +0200)] 
BUG/MINOR: peers: peer synchronization issue (with several peers sections).

When several stick-tables were configured with several peers sections,
only a part of them could be synchronized: the ones attached to the last
parsed 'peers' section. This was due to the fact that, at least, the peer I/O handler
refered to the wrong peer section list, in fact always the same: the last one parsed.

The fact that the global peer section list was named "struct peers *peers"
lead to this issue. This variable name is dangerous ;).

So this patch renames global 'peers' variable to 'cfg_peers' to ensure that
no such wrong references are still in use, then all the functions wich used
old 'peers' variable have been modified to refer to the correct peer list.

Must be backported to 1.6 and 1.7.

8 years agoOPTIM: ssl: don't consider a small ssl_read() as an indication of end of buffer
Willy Tarreau [Tue, 11 Jul 2017 12:38:39 +0000 (14:38 +0200)] 
OPTIM: ssl: don't consider a small ssl_read() as an indication of end of buffer

In ssl_sock_to_buf(), when we face a small read, we used to consider it
as an indication for the end of incoming data, as is the case with plain
text. The problem is that here it's quite different, SSL records are
returned at once so doing so make us wake all the upper layers for each
and every record. Given that SSL records are 16kB by default, this is
rarely observed unless the protocol employs small records or the buffers
are increased. But with 64kB buffers while trying to deal with HTTP/2
frames, the exchanges are obviously suboptimal as there are two messages
per frame (one for the frame header and another one for the frame payload),
causing the H2 parser to be woken up half of the times without being able
to proceed :

   try=65536 ret=45
   try=65536 ret=16384
   try=49152 ret=9
   try=49143 ret=16384
   try=32759 ret=9
   try=32750 ret=16384
   try=16366 ret=9
   try=32795 ret=27
   try=49161 ret=9
   try=49152 ret=16384
   try=49116 ret=9
   try=49107 ret=16384
   try=32723 ret=9
   try=32714 ret=16384
   try=16330 ret=9
   try=32831 ret=63
   try=49161 ret=9
   try=49152 ret=16384
   try=49080 ret=9
   try=49071 ret=2181

With this change, the buffer can safely be filled with all pending frames
at once when they are available.

8 years agoBUG/MINOR: http: properly handle all 1xx informational responses
Willy Tarreau [Fri, 7 Jul 2017 09:36:32 +0000 (11:36 +0200)] 
BUG/MINOR: http: properly handle all 1xx informational responses

Only 100 was considered informational instead of all 1xx. This can be
a problem when facing a 102 ("progress") or with the upcoming 103 for
early hints. Let's properly handle all 1xx now, leaving a special case
for 101 which is used for the upgrade.

This fix should be backported to 1.7, 1.6 and 1.5. In 1.4 the code is
different but the backport should be made there as well.

8 years agoMINOR: peers: Add additional information to stick-table definition messages.
Frédéric Lécaille [Thu, 6 Jul 2017 13:02:16 +0000 (15:02 +0200)] 
MINOR: peers: Add additional information to stick-table definition messages.

With this patch additional information are added to stick-table definition
messages so that to make external application capable of learning peer
stick-table configurations. First stick-table entries duration is added
followed by the frequency counters type IDs and values.

May be backported to 1.7 and 1.6.

8 years agoBUG/MEDIUM: filters: Be sure to call flt_end_analyze for both channels
Christopher Faulet [Thu, 6 Jul 2017 13:53:02 +0000 (15:53 +0200)] 
BUG/MEDIUM: filters: Be sure to call flt_end_analyze for both channels

In the commit 2b553de5 ("BUG/MINOR: filters: Don't force the stream's wakeup
when we wait in flt_end_analyze"), we removed a task_wakeup in flt_end_analyze
to no consume too much CPU by looping in certain circumstances.

But this fix was too drastic. For Keep-Alive transactions, flt_end_analyze is
often called only for the response. Then the stream is paused until a timeout is
hitted or the next request is received. We need first let a chance to both
channels to call flt_end_analyze function. Then if a filter need to wait here,
it is its responsibility to wake up the stream when needed. To fix the bug, and
thanks to previous commits, we set the flag CF_WAKE_ONCE on channels to pretend
there is an activity. On the current channel, the flag will be removed without
any effect, but for the other side the analyzer will be called immediatly.

Thanks for Lukas Tribus for his detailed analysis of the bug.

This patch must be backported in 1.7 with the 2 previous ones:

  * a94fda3 ("BUG/MINOR: http: Don't reset the transaction if there are still data to send")
  * cdaea89 ("BUG/MINOR: stream: Don't forget to remove CF_WAKE_ONCE flag on response channel")

8 years agoBUG/MINOR: http: Don't reset the transaction if there are still data to send
Christopher Faulet [Thu, 6 Jul 2017 13:51:35 +0000 (15:51 +0200)] 
BUG/MINOR: http: Don't reset the transaction if there are still data to send

To reset an HTTP transaction, we need to be sure all data were sent, for the
request and the response. There are tests on request and response buffers for
that in http_resync_states function. But the return code was wrong. We must
return 0 to wait.

This patch must be backported in 1.7

8 years agoBUG/MINOR: stream: Don't forget to remove CF_WAKE_ONCE flag on response channel
Christopher Faulet [Thu, 6 Jul 2017 13:49:30 +0000 (15:49 +0200)] 
BUG/MINOR: stream: Don't forget to remove CF_WAKE_ONCE flag on response channel

This flag can be set on a channel to pretend there is activity on it. This is a
way to wake-up the corresponding stream and evaluate stream analyzers on the
channel. It is correctly handled on both channels but removed only on the
request channel.

This patch is flagged as a bug but for now, CF_WAKE_ONCE is never set on the
response channel.

8 years agoMINOR: ssl: compare server certificate names to the SNI on outgoing connections
Willy Tarreau [Wed, 5 Jul 2017 16:23:03 +0000 (18:23 +0200)] 
MINOR: ssl: compare server certificate names to the SNI on outgoing connections

When support for passing SNI to the server was added in 1.6-dev3, there
was no way to validate that the certificate presented by the server would
really match the name requested in the SNI, which is quite a problem as
it allows other (valid) certificates to be presented instead (when hitting
the wrong server or due to a man in the middle).

This patch adds the missing check against the value passed in the SNI.
The "verifyhost" value keeps precedence if set. If no SNI is used and
no verifyhost directive is specified, then the certificate name is not
checked (this is unchanged).

In order to extract the SNI value, it was necessary to make use of
SSL_SESSION_get0_hostname(), which appeared in openssl 1.1.0. This is
a trivial function which returns the value of s->tlsext_hostname, so
it was provided in the compat layer for older versions. After some
refinements from Emmanuel, it now builds with openssl 1.0.2, openssl
1.1.0 and boringssl. A test file was provided to ease testing all cases.

After some careful observation period it may make sense to backport
this to 1.7 and 1.6 as some users rightfully consider this limitation
as a bug.

Cc: Emmanuel Hocdet <manu@gandi.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
8 years agoBUG/MAJOR: http: fix buffer overflow on loguri buffer.
Emeric Brun [Wed, 5 Jul 2017 11:33:16 +0000 (13:33 +0200)] 
BUG/MAJOR: http: fix buffer overflow on loguri buffer.

The pool used to log the uri was created with a size of 0 because the
configuration and 'tune.http.logurilen' were parsed too earlier.

The fix consist to postpone the pool_create as it is done for
cookie captures.

Regression introduced with 'MINOR: log: Add logurilen tunable'

8 years agoBUG/MEDIUM: map/acl: fix unwanted flags inheritance.
Emeric Brun [Mon, 3 Jul 2017 15:54:23 +0000 (17:54 +0200)] 
BUG/MEDIUM: map/acl: fix unwanted flags inheritance.

The bug: Maps/ACLs using the same file/id can mistakenly inherit
their flags from the last declared one.

i.e.

    $ cat haproxy.conf
    listen mylistener
mode http
bind 0.0.0.0:8080

acl myacl1 url -i -f mine.acl
acl myacl2 url -f mine.acl
acl myacl3 url -i -f mine.acl
redirect location / if myacl2
    $ cat mine.acl
    foobar

Shows an unexpected redirect for request 'GET /FOObAR HTTP/1.0\n\n'.

This fix should be backported on mainline branches v1.6 and v1.7.

8 years agoDOC: fix references to the section about time format.
Jarno Huuskonen [Tue, 4 Jul 2017 07:35:12 +0000 (10:35 +0300)] 
DOC: fix references to the section about time format.

Time format is documented in section 2.4, not 2.2.

8 years agoBUG/MAJOR: applet: fix a freeze if data is immedately forwarded.
Emeric Brun [Fri, 30 Jun 2017 12:11:56 +0000 (14:11 +0200)] 
BUG/MAJOR: applet: fix a freeze if data is immedately forwarded.

Introduced regression with 'MAJOR: applet scheduler rework' (1.8-dev only).

The fix consist to re-enable the appctx immediatly from the
applet wake cb if the process_stream is not pending in runqueue
and the applet want perform a put or a get and the WAIT_ROOM
flag was removed by stream_int_notify.

8 years agoMINOR: compression: Use a memory pool to allocate compression states
Christopher Faulet [Mon, 26 Jun 2017 14:53:33 +0000 (16:53 +0200)] 
MINOR: compression: Use a memory pool to allocate compression states

Instead of doing a malloc/free to each HTTP transaction to allocate the
compression state (when the HTTP compression is enabled), we use a memory pool.

8 years agoBUG/MAJOR: compression: Be sure to release the compression state in all cases
Christopher Faulet [Mon, 26 Jun 2017 09:47:13 +0000 (11:47 +0200)] 
BUG/MAJOR: compression: Be sure to release the compression state in all cases

This patch fixes an obvious memory leak in the compression filter. The
compression state (comp_state) is allocated when a HTTP transaction starts, in
channel_start_analyze callback, Whether we are able to compression the response
or not. So it must be released when the transaction ends, in channel_end_analyze
callback.

But there is a bug here. The state is released on the response side only. So, if
a transaction ends before the response is started, it is never released. This
happens when a connection is closed before the response is started.

To fix the bug, statistics about the HTTP compression are now updated in
http_end callback, when the response parsing ends.  It happens only if no error
is encountered and when the response is compressed. So, it is safe to release
the compression state in channel_end_analyze callback, regardless the
channel's type.

This patch must be backported in 1.7.

8 years agoBUG/MAJOR: map: fix segfault during 'show map/acl' on cli.
Emeric Brun [Thu, 29 Jun 2017 13:40:33 +0000 (15:40 +0200)] 
BUG/MAJOR: map: fix segfault during 'show map/acl' on cli.

The reference of the current map/acl element to dump could
be destroyed if map is updated from an 'http-request del-map'
configuration rule or throught a 'del map/acl' on CLI.

We use a 'back_refs' chaining element to fix this. As it
is done to dump sessions.

This patch needs also fix:
'BUG/MAJOR: cli: fix custom io_release was crushed by NULL.'

To clean the back_ref and avoid a crash on a further
del/clear map operation.

Those fixes should be backported on mainline branches 1.7 and 1.6.

This patch wont directly apply on 1.6.

8 years agoBUG/MAJOR: cli: fix custom io_release was crushed by NULL.
Emeric Brun [Thu, 29 Jun 2017 17:54:13 +0000 (19:54 +0200)] 
BUG/MAJOR: cli: fix custom io_release was crushed by NULL.

The io_release could be set into the parsing request handler
and must not be crushed.

This patch should be backported on mainline branches 1.7 and 1.6

8 years agoBUG/MAJOR: frontend: don't dereference a null conn on outgoing connections
Willy Tarreau [Tue, 27 Jun 2017 13:47:56 +0000 (15:47 +0200)] 
BUG/MAJOR: frontend: don't dereference a null conn on outgoing connections

Recently merged commit 0cfe388 ("MINOR: frontend: retrieve the ALPN name when
available") assumed that the connection is always known in frontend_accept()
which is not true for outgoing peers connections for example.

No backport needed.

8 years agoMAJOR: applet: applet scheduler rework.
Emeric Brun [Mon, 26 Jun 2017 14:36:53 +0000 (16:36 +0200)] 
MAJOR: applet: applet scheduler rework.

In order to authorize call of appctx_wakeup on running task:
- from within the task handler itself.
- in futur, from another thread.

The appctx is considered paused as default after running the handler.

The handler should explicitly call appctx_wakeup to be re-called.

When the appctx_free is called on a running handler. The real
free is postponed at the end of the handler process.

8 years agoMINOR: connection: send data before receiving
Willy Tarreau [Tue, 11 Apr 2017 17:59:33 +0000 (19:59 +0200)] 
MINOR: connection: send data before receiving

It's more efficient this way, as it allows to flush a send buffer before
receiving data in the other one. This can lead to a slightly faster buffer
recycling, thus slightly less memory and a small performance increase by
using a hotter cache.

8 years agoMINOR: stream: don't set backend's nor response analysers on SF_TUNNEL
Willy Tarreau [Tue, 13 Dec 2016 14:26:56 +0000 (15:26 +0100)] 
MINOR: stream: don't set backend's nor response analysers on SF_TUNNEL

In order to implement hot-pluggable applets like we'll need for HTTP/2
which will speak a different protocol than the expected one, it will be
mandatory to be able to clear all analysers from the request and response
channel and/or to keep only the ones the applet initializer installed.

Unfortunately for now in sess_establish() we systematically place a number
of analysers inherited from the frontend, backend and some hard-coded ones.

This patch reuses the now unused SF_TUNNEL flag on the stream to indicate
we're dealing with a tunnel and don't want to add more analysers anymore.
It will be usable to install such a specific applet.

Ideally over the long term it might be nice to be able to set the mode on
the stream instead of the proxy so that we can decide to change a stream's
mode (eg: TCP, HTTP, HTTP/2) at run time. But it would require many more
changes for a gain which is not yet obvious.

8 years agoMINOR: frontend: report the connection's ALPN in the debug output
Willy Tarreau [Sun, 4 Dec 2016 18:05:24 +0000 (19:05 +0100)] 
MINOR: frontend: report the connection's ALPN in the debug output

Now the incoming connection will also report the ALPN field, truncated
to 15 characters.

8 years agoMINOR: frontend: retrieve the ALPN name when available
Willy Tarreau [Sun, 4 Dec 2016 17:59:29 +0000 (18:59 +0100)] 
MINOR: frontend: retrieve the ALPN name when available

Here we try to retrieve the negociated ALPN on the front connection.
This will be used to decide whether or not we want to switch to H2.

8 years agoMINOR: ssl: add a get_alpn() method to ssl_sock
Willy Tarreau [Sun, 4 Dec 2016 17:44:29 +0000 (18:44 +0100)] 
MINOR: ssl: add a get_alpn() method to ssl_sock

This is used to retrieve the TLS ALPN information from a connection. We
also support a fallback to NPN if ALPN doesn't find anything or is not
available on the existing implementation. It happens that depending on
the library version, either one or the other is available. NPN was
present in openssl 1.0.1 (very common) while ALPN is in 1.0.2 and onwards
(still uncommon at the time of writing). Clients are used to send either
one or the other to ensure a smooth transition.

8 years agoMINOR: connection: add a .get_alpn() method to xprt_ops
Willy Tarreau [Sun, 4 Dec 2016 17:42:09 +0000 (18:42 +0100)] 
MINOR: connection: add a .get_alpn() method to xprt_ops

This will be used to retrieve the ALPN negociated over SSL (or possibly
via the proxy protocol later). It's likely that this information should
be stored in the connection itself, but it requires adding an extra
pointer and an extra integer. Thus better rely on the transport layer
to pass this info for now.

8 years agoMINOR: frontend: initialize HTTP layer after the debugging code
Willy Tarreau [Sun, 4 Dec 2016 17:39:22 +0000 (18:39 +0100)] 
MINOR: frontend: initialize HTTP layer after the debugging code

For HTTP/2 we'll have to choose the upper layer based on the
advertised protocol name here and we want to keep debugging,
so let's move debugging earlier.

8 years agoMEDIUM: stream: make stream_new() always set the target and analysers
Willy Tarreau [Sun, 4 Dec 2016 23:26:31 +0000 (00:26 +0100)] 
MEDIUM: stream: make stream_new() always set the target and analysers

It doesn't make sense that stream_new() doesn't sets the target nor
analysers and that the caller has to do it even if it doesn't know
about streams (eg: in session_accept_fd()). This causes trouble for
H2 where the applet handling the protocol cannot properly change
these information during its init phase.

Let's ensure it's always set and that the callers don't set it anymore.

Note: peers and lua don't use analysers and that's properly handled.

8 years agoMINOR: queue: Change pendconn_from_srv/pendconn_from_px into private functions
Christopher Faulet [Fri, 9 Jun 2017 12:26:38 +0000 (14:26 +0200)] 
MINOR: queue: Change pendconn_from_srv/pendconn_from_px into private functions