]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
8 years agoBUG/MINOR: ssl: Be sure that SSLv3 connection methods exist for openssl < 1.1.0
Christopher Faulet [Thu, 8 Jun 2017 20:18:52 +0000 (22:18 +0200)] 
BUG/MINOR: ssl: Be sure that SSLv3 connection methods exist for openssl < 1.1.0

For openssl 1.0.2, SSLv3_server_method and SSLv3_client_method are undefined if
OPENSSL_NO_SSL3_METHOD is set. So we must add a check on this macro before using
these functions.

8 years agoBUG/MINOR: acls: Set the right refflag when patterns are loaded from a map
Christopher Faulet [Wed, 14 Jun 2017 12:41:33 +0000 (14:41 +0200)] 
BUG/MINOR: acls: Set the right refflag when patterns are loaded from a map

For an ACL, we can load patterns from a map using the flag -M. For example:

    acl test hdr(host) -M -f hosts.map

The file is parsed as a map et the ACL will be executed as expected. But the
reference flag is wrong. It is set to PAT_REF_ACL. So the map will never be
listed by a "show map" on the stat socket. Setting the reference flag to
PAT_REF_ACL|PAT_REF_MAP fixes the bug.

8 years agoCONTRIB: plug qdiscs: Plug queuing disciplines mini HOWTO.
Frédéric Lécaille [Wed, 14 Jun 2017 13:16:15 +0000 (15:16 +0200)] 
CONTRIB: plug qdiscs: Plug queuing disciplines mini HOWTO.

Add plug_qdisc.c source file which may help in how to programatically
use plug queueing disciplines with its README file.
Such code may be useful to reproduce painful network application bugs.

8 years agoBUG/MINOR: buffers: Fix bi/bo_contig_space to handle full buffers
Christopher Faulet [Tue, 13 Jun 2017 20:00:22 +0000 (22:00 +0200)] 
BUG/MINOR: buffers: Fix bi/bo_contig_space to handle full buffers

These functions was added in commit 637f8f2c ("BUG/MEDIUM: buffers: Fix how
input/output data are injected into buffers").

This patch fixes hidden bugs. When a buffer is full (buf->i + buf->o ==
buf->size), instead of returning 0, these functions can return buf->size. Today,
this never happens because callers already check if the buffer is full before
calling bi/bo_contig_space. But to avoid possible bugs if calling conditions
changed, we slightly refactored these functions.

8 years agoBUG/MAJOR: http: call manage_client_side_cookies() before erasing the buffer
Willy Tarreau [Sun, 11 Jun 2017 15:56:27 +0000 (17:56 +0200)] 
BUG/MAJOR: http: call manage_client_side_cookies() before erasing the buffer

Jean Lubatti reported a crash on haproxy using a config involving cookies
and tarpit rules. It just happens that since 1.7-dev3 with commit 83a2c3d
("BUG/MINOR : allow to log cookie for tarpit and denied request"), function
manage_client_side_cookies() was called after erasing the request buffer in
case of a tarpit action. The problem is that this function must absolutely
not be called with an empty buffer since it moves parts of it. A typical
reproducer consists in sending :

    "GET / HTTP/1.1\r\nCookie: S=1\r\n\r\n"

On such a config :

    listen crash
        bind :8001
        mode http
        reqitarpit .
        cookie S insert indirect
        server s1 127.0.0.1:8000 cookie 1

The fix simply consists in moving the call to the function before the call
to buffer_erase().

Many thanks to Jean for testing instrumented code and providing a usable
core.

This fix must be backported to all stable versions since the fix introducing
this bug was backported as well.

8 years agoBUILD: scripts: add a "quiet" mode to publish-release
Willy Tarreau [Fri, 9 Jun 2017 13:57:31 +0000 (15:57 +0200)] 
BUILD: scripts: add a "quiet" mode to publish-release

Option "-q" will make it silent in automatic mode when there is nothing to do.

8 years agoBUILD: scripts: add an automatic mode for publish-release
Willy Tarreau [Fri, 9 Jun 2017 13:54:39 +0000 (15:54 +0200)] 
BUILD: scripts: add an automatic mode for publish-release

Passing "-a" will make it easier to automatically create archives from
tagged repositories. It doesn't ask any question and doesn't return an
error when the current branch is not tagged nor if the release already
exists.

8 years agoBUILD: scripts: make publish-release support bare repositories
Willy Tarreau [Fri, 9 Jun 2017 13:36:02 +0000 (15:36 +0200)] 
BUILD: scripts: make publish-release support bare repositories

First we must not report an error when "git diff HEAD" fails. Second, we
don't want to "cd" to the home dir when "git rev-parse --show-toplevel"
returns an empty string. Third, we definitely want to check that a master
branch really exists in the current directory to avoid mistakes.

8 years agoBUG/MINOR: Makefile: fix compile error with USE_LUA=1 in ubuntu16.04
Nan Liu [Fri, 9 Jun 2017 07:57:45 +0000 (15:57 +0800)] 
BUG/MINOR: Makefile: fix compile error with USE_LUA=1 in ubuntu16.04

include/types/hlua.h:6:17: fatal error: lua.h: No such file or directory

8 years agoBUG/MEDIUM: misplaced exit and wrong exit code
William Lallemand [Wed, 7 Jun 2017 13:04:47 +0000 (15:04 +0200)] 
BUG/MEDIUM: misplaced exit and wrong exit code

Commit cb11fd2 ("MEDIUM: mworker: wait mode on reload failure")
introduced a regression, when HAProxy is used in daemon mode, it exits 1
after forking its children.

HAProxy should exit(0), the exit(EXIT_FAILURE) was expected to be use
when the master fail in master-worker mode.

Thanks to Emmanuel Hocdet for reporting this bug. No backport needed.

8 years agoBUG/MINOR: warning: â\80\98need_resendâ\80\99 may be used uninitialized
William Lallemand [Thu, 8 Jun 2017 17:30:39 +0000 (19:30 +0200)] 
BUG/MINOR: warning: â\80\98need_resendâ\80\99 may be used uninitialized

The commit 201c07f68 ("MAJOR/REORG: dns: DNS resolution task and
requester queues") introduces a warning during compilation:

src/dns.c: In function â\80\98dns_resolve_recvâ\80\99:
src/dns.c:487:6: warning: â\80\98need_resendâ\80\99 may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (need_resend) {
      ^

This patch initialize the variable and remove the comment about it.

8 years agoBUG/MEDIUM: build without openssl broken
William Lallemand [Thu, 8 Jun 2017 17:05:48 +0000 (19:05 +0200)] 
BUG/MEDIUM: build without openssl broken

The commit 872f9c213 ("MEDIUM: ssl: add basic support for OpenSSL crypto
engine") broke the build without openssl support.

The ssl_free_dh() function is not defined when USE_OPENSSL is not
defined and leads to a compilation failure.

8 years agoBUG/MINOR: haproxy/cli : fix for solaris/illumos distros for CMSG* macros
David Carlier [Wed, 7 Jun 2017 19:02:43 +0000 (20:02 +0100)] 
BUG/MINOR: haproxy/cli : fix for solaris/illumos distros for CMSG* macros

control message sockets macros implies (SUS)XPG4V2 enabled under solaris based oses.

8 years agoBUG/MINOR: ssl: do not call directly the conn_fd_handler from async_fd_handler
Emeric Brun [Fri, 2 Jun 2017 15:54:06 +0000 (15:54 +0000)] 
BUG/MINOR: ssl: do not call directly the conn_fd_handler from async_fd_handler

This patch modifies the way to re-enable the connection from the async fd
handler calling conn_update_sock_polling instead of the conn_fd_handler.

It also ensures that the polling is really stopped on the async fd.

8 years agoBUG/MAJOR: ssl: buffer overflow using offloaded ciphering on async engine
Emeric Brun [Tue, 6 Jun 2017 12:35:14 +0000 (12:35 +0000)] 
BUG/MAJOR: ssl: buffer overflow using offloaded ciphering on async engine

The Openssl's ASYNC API does'nt support moving buffers on SSL_read/write
This patch disables the ASYNC mode dynamically when the handshake
is left and re-enables it on reneg.

8 years agoBUG/MAJOR: ssl: fix segfault on connection close using async engines.
Emeric Brun [Wed, 31 May 2017 10:02:53 +0000 (10:02 +0000)] 
BUG/MAJOR: ssl: fix segfault on connection close using async engines.

This patch ensure that the ASYNC fd handlers won't be wake up
too early, disabling the event cache for this fd on connection close
and when a WANT_ASYNC is rised by Openssl.

The calls to SSL_read/SSL_write/SSL_do_handshake before rising a real read
event from the ASYNC fd, generated an EAGAIN followed by a context switch
for some engines, or a blocked read for the others.

On connection close it resulted in a too early call to SSL_free followed
by a segmentation fault.

8 years agoMEDIUM: ssl: disable SSLv3 per default for bind
Emmanuel Hocdet [Mon, 15 May 2017 13:53:41 +0000 (15:53 +0200)] 
MEDIUM: ssl: disable SSLv3 per default for bind

For security, disable SSLv3 on bind line must be the default configuration.
SSLv3 can be enabled with "ssl-min-ver SSLv3".

8 years agoMINOR: ssl: support ssl-min-ver and ssl-max-ver with crt-list
Emmanuel Hocdet [Thu, 18 May 2017 10:46:50 +0000 (12:46 +0200)] 
MINOR: ssl: support ssl-min-ver and ssl-max-ver with crt-list

SSL/TLS version can be changed per certificat if and only if openssl lib support
earlier callback on handshake and, of course, is implemented in haproxy. It's ok
for BoringSSL. For Openssl, version 1.1.1 have such callback and could support it.

8 years agoMEDIUM: ssl: ctx_set_version/ssl_set_version func for methodVersions table
Emmanuel Hocdet [Thu, 18 May 2017 10:33:19 +0000 (12:33 +0200)] 
MEDIUM: ssl: ctx_set_version/ssl_set_version func for methodVersions table

This patch cleanup the usage of set_version func with a more suitable name:
ctx_set_version. It introduce ssl_set_version func (unused for the moment).

8 years agoREORG: ssl: move defines and methodVersions table upper
Emmanuel Hocdet [Thu, 18 May 2017 09:56:58 +0000 (11:56 +0200)] 
REORG: ssl: move defines and methodVersions table upper

It will used in ssl_sock_switchctx_cbk.

8 years ago[RELEASE] Released version 1.8-dev2 v1.8-dev2
Willy Tarreau [Fri, 2 Jun 2017 13:59:51 +0000 (15:59 +0200)] 
[RELEASE] Released version 1.8-dev2

Released version 1.8-dev2 with the following main changes :
    - CLEANUP: server: moving netinet/tcp.h inclusion
    - DOC: changed "block"(deprecated) examples to http-request deny
    - DOC: add few comments to examples.
    - DOC: update sample code for PROXY protocol
    - DOC: mention lighttpd 1.4.46 implements PROXY
    - MINOR server: Restrict dynamic cookie check to the same proxy.
    - DOC: stick-table is available in frontend sections
    - BUG/MINOR: server : no transparent proxy for DragonflyBSD
    - BUILD/MINOR: stats: remove unexpected argument to stats_dump_json_header()
    - BUILD/MINOR: tools: fix build warning in debug_hexdump()
    - BUG/MINOR: dns: Wrong address family used when creating IPv6 sockets.
    - BUG/MINOR: config: missing goto out after parsing an incorrect ACL character
    - BUG/MINOR: arg: don't try to add an argument on failed memory allocation
    - MEDIUM: server: Inherit CLI weight changes and agent-check weight responses
    - BUG/MEDIUM: arg: ensure that we properly unlink unresolved arguments on error
    - BUG/MEDIUM: acl: don't free unresolved args in prune_acl_expr()
    - BUG/MEDIUM: servers: unbreak server weight propagation
    - MINOR: lua: ensure the memory allocator is used all the time
    - MINOR: cli: Add a command to send listening sockets.
    - MINOR: global: Add an option to get the old listening sockets.
    - MINOR: tcp: When binding socket, attempt to reuse one from the old proc.
    - MINOR: doc: document the -x flag
    - MINOR: proxy: Don't close FDs if not our proxy.
    - MINOR: socket transfer: Set a timeout on the socket.
    - MINOR: systemd wrapper: add support for passing the -x option.
    - BUG/MINOR: server: Fix a wrong error message during 'usesrc' keyword parsing.
    - BUG/MAJOR: Broken parsing for valid keywords provided after 'source' setting.
    - CLEANUP: logs: typo: simgle => single
    - BUG/MEDIUM: acl: proprely release unused args in prune_acl_expr()
    - MEDIUM: config: don't check config validity when there are fatal errors
    - BUG/MAJOR: Use -fwrapv.
    - BUG/MINOR: server: don't use "proxy" when px is really meant.
    - BUG/MEDIUM: http: Drop the connection establishment when a redirect is performed
    - BUG/MINOR: server: missing default server 'resolvers' setting duplication.
    - MINOR: server: Extract the code responsible of copying default-server settings.
    - MINOR: server: Extract the code which finalizes server initializations after 'server' lines parsing.
    - MINOR: server: Add 'server-template' new keyword supported in backend sections.
    - MINOR: server: Add server_template_init() function to initialize servers from a templates.
    - DOC: Add documentation for new "server-template" keyword.
    - DOC: add layer 4 links/cross reference to "block" keyword.
    - DOC: errloc/errorloc302/errorloc303 missing status codes.
    - BUG/MEDIUM: lua: memory leak
    - CLEANUP: lua: remove test
    - BUG/MINOR: hash-balance-factor isn't effective in certain circumstances
    - BUG/MINOR: change header-declared function to static inline
    - REORG: spoe: move spoe_encode_varint / spoe_decode_varint from spoe to common
    - MINOR: Add binary encoding request header sample fetch
    - MINOR: proto-http: Add sample fetch wich returns all HTTP headers
    - MINOR: Add ModSecurity wrapper as contrib
    - BUG/MINOR: ssl: fix warnings about methods for opensslv1.1.
    - DOC: update RFC references
    - CONTRIB: tcploop: add action "X" to execute a command
    - MINOR: server: cli: Add server FQDNs to server-state file and stats socket.
    - BUG/MINOR: contrib/mod_security: fix build on FreeBSD
    - BUG/MINOR: checks: don't send proxy protocol with agent checks
    - MINOR: ssl: add prefer-client-ciphers
    - MEDIUM: ssl: revert ssl/tls version settings relative to default-server.
    - MEDIUM: ssl: ssl_methods implementation is reworked and factored for min/max tlsxx
    - MEDIUM: ssl: calculate the real min/max TLS version and find holes
    - MINOR: ssl: support TLSv1.3 for bind and server
    - MINOR: ssl: show methods supported by openssl
    - MEDIUM: ssl: add ssl-min-ver and ssl-max-ver parameters for bind and server
    - MEDIUM: ssl: ssl-min-ver and ssl-max-ver compatibility.
    - CLEANUP: retire obsoleted USE_GETSOCKNAME build option
    - BUG/MAJOR: dns: Broken kqueue events handling (BSD systems).
    - MINOR: sample: Add b64dec sample converter
    - BUG/MEDIUM: lua: segfault if a converter or a sample doesn't return anything
    - MINOR: cli: add ACCESS_LVL_MASK to store the access level
    - MINOR: cli: add 'expose-fd listeners' to pass listeners FDs
    - MEDIUM: proxy: zombify proxies only when the expose-fd socket is bound
    - MEDIUM: ssl: add basic support for OpenSSL crypto engine
    - MAJOR: ssl: add openssl async mode support
    - MEDIUM: ssl: handle multiple async engines
    - MINOR: boringssl: basic support for OCSP Stapling
    - MEDIUM: mworker: replace systemd mode by master worker mode
    - MEDIUM: mworker: handle reload and signals
    - MEDIUM: mworker: wait mode on reload failure
    - MEDIUM: mworker: try to guess the next stats socket to use with -x
    - MEDIUM: mworker: exit-on-failure option
    - MEDIUM: mworker: workers exit when the master leaves
    - DOC: add documentation for the master-worker mode
    - MEDIUM: systemd: Type=forking in unit file
    - MAJOR: systemd-wrapper: get rid of the wrapper
    - MINOR: log: Add logurilen tunable.
    - CLEANUP: server.c: missing prototype of srv_free_dns_resolution
    - MINOR: dns: smallest DNS fqdn size
    - MINOR: dns: functions to manage memory for a DNS resolution structure
    - MINOR: dns: parse_server() now uses srv_alloc_dns_resolution()
    - REORG: dns: dns_option structure, storage of hostname_dn
    - MINOR: dns: new snr_check_ip_callback function
    - MAJOR: dns: save a copy of the DNS response in struct resolution
    - MINOR: dns: implement a LRU cache for DNS resolutions
    - MINOR: dns: make 'ancount' field to match the number of saved records
    - MINOR: dns: introduce roundrobin into the internal cache (WIP)
    - MAJOR/REORG: dns: DNS resolution task and requester queues
    - BUILD: ssl: fix build with OPENSSL_NO_ENGINE
    - MINOR: Add Mod Defender integration as contrib
    - CLEANUP: str2mask return code comment: non-zero -> zero.
    - MINOR: tools: make debug_hexdump() use a const char for the string
    - MINOR: tools: make debug_hexdump() take a string prefix
    - CLEANUP: connection: remove unused CO_FL_WAIT_DATA

8 years agoCLEANUP: connection: remove unused CO_FL_WAIT_DATA
Willy Tarreau [Wed, 26 Apr 2017 14:25:12 +0000 (16:25 +0200)] 
CLEANUP: connection: remove unused CO_FL_WAIT_DATA

Very early in the connection rework process leading to v1.5-dev12, commit
56a77e5 ("MEDIUM: connection: complete the polling cleanups") marked the
end of use for this flag which since was never set anymore, but it continues
to be tested. Let's kill it now.

8 years agoMINOR: tools: make debug_hexdump() take a string prefix
Willy Tarreau [Thu, 27 Apr 2017 16:03:20 +0000 (18:03 +0200)] 
MINOR: tools: make debug_hexdump() take a string prefix

When dumping data at various places in the code, it's hard to figure
what is present where. To make this easier, this patch slightly modifies
debug_hexdump() to take a prefix string which is prepended in front of
each output line.

8 years agoMINOR: tools: make debug_hexdump() use a const char for the string
Willy Tarreau [Thu, 27 Apr 2017 15:54:58 +0000 (17:54 +0200)] 
MINOR: tools: make debug_hexdump() use a const char for the string

There's no reason the string to be dumped should be a char *, it's
a const.

8 years agoCLEANUP: str2mask return code comment: non-zero -> zero.
Jarno Huuskonen [Sun, 21 May 2017 14:32:21 +0000 (17:32 +0300)] 
CLEANUP: str2mask return code comment: non-zero -> zero.

8 years agoMINOR: Add Mod Defender integration as contrib
Dragan Dosen [Fri, 2 Jun 2017 10:03:16 +0000 (12:03 +0200)] 
MINOR: Add Mod Defender integration as contrib

This is a service that talks SPOE protocol and uses the Mod Defender (a
NAXSI clone) functionality to detect HTTP attacks. It returns a HTTP
status code to indicate whether the request is suspicious or not, based on
NAXSI rules. The value of the returned code can be used in HAProxy rules
to determine if the HTTP request should be blocked/rejected.

8 years agoBUILD: ssl: fix build with OPENSSL_NO_ENGINE
Emmanuel Hocdet [Mon, 29 May 2017 12:36:20 +0000 (14:36 +0200)] 
BUILD: ssl: fix build with OPENSSL_NO_ENGINE

Build is broken with openssl library without support of engin (like boringssl).
Add OPENSSL_NO_ENGINE flag to fix that.

8 years agoMAJOR/REORG: dns: DNS resolution task and requester queues
Baptiste Assmann [Mon, 22 May 2017 13:17:15 +0000 (15:17 +0200)] 
MAJOR/REORG: dns: DNS resolution task and requester queues

This patch is a major upgrade of the internal run-time DNS resolver in
HAProxy and it brings the following 2 main changes:

1. DNS resolution task

Up to now, DNS resolution was triggered by the health check task.
From now, DNS resolution task is autonomous. It is started by HAProxy
right after the scheduler is available and it is woken either when a
network IO occurs for one of its nameserver or when a timeout is
matched.

From now, this means we can enable DNS resolution for a server without
enabling health checking.

2. Introduction of a dns_requester structure

Up to now, DNS resolution was purposely made for resolving server
hostnames.
The idea, is to ensure that any HAProxy internal object should be able
to trigger a DNS resolution. For this purpose, 2 things has to be done:
  - clean up the DNS code from the server structure (this was already
    quite clean actually) and clean up the server's callbacks from
    manipulating too much DNS resolution
  - create an agnostic structure which allows linking a DNS resolution
    and a requester of any type (using obj_type enum)

3. Manage requesters through queues

Up to now, there was an uniq relationship between a resolution and it's
owner (aka the requester now). It's a shame, because in some cases,
multiple objects may share the same hostname and may benefit from a
resolution being performed by a third party.
This patch introduces the notion of queues, which are basically lists of
either currently running resolution or waiting ones.

The resolutions are now available as a pool, which belongs to the resolvers.
The pool has has a default size of 64 resolutions per resolvers and is
allocated at configuration parsing.

8 years agoMINOR: dns: introduce roundrobin into the internal cache (WIP)
Baptiste Assmann [Thu, 4 May 2017 06:24:11 +0000 (08:24 +0200)] 
MINOR: dns: introduce roundrobin into the internal cache (WIP)

This patch introduces a bit of roundrobin in the records stored in our
local cache.
Purpose is to allow some kind of distribution of the IPs found in a
response.
Note that distribution properly applies only when the IP used by many
requesters disappear and is replaced by an other one.

8 years agoMINOR: dns: make 'ancount' field to match the number of saved records
Baptiste Assmann [Thu, 4 May 2017 06:37:45 +0000 (08:37 +0200)] 
MINOR: dns: make 'ancount' field to match the number of saved records

ancount is the number of answers available in a DNS response.
Before this patch, HAProxy used to store the ancount found in the buffer
(sent by the DNS server).
Unfortunately, this is now inaccurate and does not correspond to the
number of records effectively stored in our local version of the
response. In Example, the CNAMEs are not stored.

This patch updates ancount field in to make it match what is effectively
stored in our version.

8 years agoMINOR: dns: implement a LRU cache for DNS resolutions
Baptiste Assmann [Thu, 4 May 2017 07:05:00 +0000 (09:05 +0200)] 
MINOR: dns: implement a LRU cache for DNS resolutions

Introduction of a DNS response LRU cache in HAProxy.

When a positive response is received from a DNS server, HAProxy stores
it in the struct resolution and then also populates a LRU cache with the
response.
For now, the key in the cache is a XXHASH64 of the hostname in the
domain name format concatened to the query type in string format.

8 years agoMAJOR: dns: save a copy of the DNS response in struct resolution
Baptiste Assmann [Mon, 22 May 2017 13:13:10 +0000 (15:13 +0200)] 
MAJOR: dns: save a copy of the DNS response in struct resolution

Prior this patch, the DNS responses were stored in a pre-allocated
memory area (allocated at HAProxy's startup).
The problem is that this memory is erased for each new DNS responses
received and processed.

This patch removes the global memory allocation (which was not thread
safe by the way) and introduces a storage of the dns response  in the
struct
resolution.
The memory in the struct resolution is also reserved at start up and is
thread safe, since each resolution structure will have its own memory
area.

For now, we simply store the response and use it atomically per
response per server.

8 years agoMINOR: dns: new snr_check_ip_callback function
Baptiste Assmann [Wed, 3 May 2017 13:43:12 +0000 (15:43 +0200)] 
MINOR: dns: new snr_check_ip_callback function

In the process of breaking links between dns_* functions and other
structures (mainly server and a bit of resolution), the function
dns_get_ip_from_response needs to be reworked: it now can call
"callback" functions based on resolution's owner type to allow modifying
the way the response is processed.

For now, main purpose of the callback function is to check that an IP
address is not already affected to an element of the same type.

For now, only server type has a callback.

8 years agoREORG: dns: dns_option structure, storage of hostname_dn
Baptiste Assmann [Wed, 3 May 2017 10:12:02 +0000 (12:12 +0200)] 
REORG: dns: dns_option structure, storage of hostname_dn

This patch introduces a some re-organisation around the DNS code in
HAProxy.

1. make the dns_* functions less dependent on 'struct server' and 'struct resolution'.

With this in mind, the following changes were performed:
- 'struct dns_options' has been removed from 'struct resolution' (well,
  we might need it back at some point later, we'll see)
  ==> we'll use the 'struct dns_options' from the owner of the resolution
- dns_get_ip_from_response(): takes a 'struct dns_options' instead of
  'struct resolution'
  ==> so the caller can pass its own dns options to get the most
      appropriate IP from the response
- dns_process_resolve(): struct dns_option is deduced from new
  resolution->requester_type parameter

2. add hostname_dn and hostname_dn_len into struct server

In order to avoid recomputing a server's hostname into its domain name
format (and use a trash buffer to store the result), it is safer to
compute it once at configuration parsing and to store it into the struct
server.
In the mean time, the struct resolution linked to the server doesn't
need anymore to store the hostname in domain name format. A simple
pointer to the server one will make the trick.

The function srv_alloc_dns_resolution() properly manages everything for
us: memory allocation, pointer updates, etc...

3. move resolvers pointer into struct server

This patch makes the pointer to struct dns_resolvers from struct
dns_resolution obsolete.
Purpose is to make the resolution as "neutral" as possible and since the
requester is already linked to the resolvers, then we don't need this
information anymore in the resolution itself.

8 years agoMINOR: dns: parse_server() now uses srv_alloc_dns_resolution()
Baptiste Assmann [Wed, 3 May 2017 10:09:54 +0000 (12:09 +0200)] 
MINOR: dns: parse_server() now uses srv_alloc_dns_resolution()

In order to make DNS code more consistent, the function parse_server()
now uses srv_alloc_dns_resolution() to set up a server and its
resolution.

8 years agoMINOR: dns: functions to manage memory for a DNS resolution structure
Baptiste Assmann [Wed, 3 May 2017 08:11:44 +0000 (10:11 +0200)] 
MINOR: dns: functions to manage memory for a DNS resolution structure

A couple of new functions to allocate and free memory for a DNS
resolution structure. Main purpose is to to make the code related to DNS
more consistent.
They allocate or free memory for the structure itself. Later, if needed,
they should also allocate / free the buffers, etc, used by this structure.
They don't set/unset any parameters, this is the role of the caller.

This patch also implement calls to these function eveywhere it is
required.

8 years agoMINOR: dns: smallest DNS fqdn size
Baptiste Assmann [Mon, 3 Apr 2017 12:40:20 +0000 (14:40 +0200)] 
MINOR: dns: smallest DNS fqdn size

global variable used to define the size of the smallest fqdn possible.

8 years agoCLEANUP: server.c: missing prototype of srv_free_dns_resolution
Baptiste Assmann [Thu, 4 May 2017 10:13:31 +0000 (12:13 +0200)] 
CLEANUP: server.c: missing prototype of srv_free_dns_resolution

Prototype for the function srv_free_dns_resolution() missing at the top
of the file.

8 years agoMINOR: log: Add logurilen tunable.
Stéphane Cottin [Thu, 18 May 2017 06:58:41 +0000 (08:58 +0200)] 
MINOR: log: Add logurilen tunable.

The default len of request uri in log messages is 1024. In some use
cases, you need to keep the long trail of GET parameters. The only
way to increase this len is to recompile with DEFINE=-DREQURI_LEN=2048.

This commit introduces a tune.http.logurilen configuration directive,
allowing to tune this at runtime.

8 years agoMAJOR: systemd-wrapper: get rid of the wrapper
William Lallemand [Thu, 1 Jun 2017 15:38:58 +0000 (17:38 +0200)] 
MAJOR: systemd-wrapper: get rid of the wrapper

The master worker mode obsoletes the systemd-wrapper, to ensure that
nobody uses it anymore, the code has been removed.

8 years agoMEDIUM: systemd: Type=forking in unit file
William Lallemand [Thu, 1 Jun 2017 15:38:57 +0000 (17:38 +0200)] 
MEDIUM: systemd: Type=forking in unit file

Adding Type=forking in the unit file ensure better monitoring from
systemd. During a systemctl start the tool is able to return an error if
it didn't work with this option.

8 years agoDOC: add documentation for the master-worker mode
William Lallemand [Thu, 1 Jun 2017 15:38:56 +0000 (17:38 +0200)] 
DOC: add documentation for the master-worker mode

8 years agoMEDIUM: mworker: workers exit when the master leaves
William Lallemand [Thu, 1 Jun 2017 15:38:55 +0000 (17:38 +0200)] 
MEDIUM: mworker: workers exit when the master leaves

This patch ensure that the children will exit when the master quits,
even if the master didn't send any signal.

The master and the workers are connected through a pipe, when the pipe
closes the children leave.

8 years agoMEDIUM: mworker: exit-on-failure option
William Lallemand [Thu, 1 Jun 2017 15:38:54 +0000 (17:38 +0200)] 
MEDIUM: mworker: exit-on-failure option

This option exits every workers when one of the current workers die.

It allows you to monitor the master process in order to relaunch
everything on a failure.

For example it can be used with systemd and Restart=on-failure in a spec
file.

8 years agoMEDIUM: mworker: try to guess the next stats socket to use with -x
William Lallemand [Thu, 1 Jun 2017 15:38:53 +0000 (17:38 +0200)] 
MEDIUM: mworker: try to guess the next stats socket to use with -x

In master worker mode, you can't specify the stats socket where you get
your listeners FDs on a reload, because the command line of the re-exec
is launched by the master.

To solve the problem, when -x is found on the command line, its
parameter is rewritten on a reexec with the first stats socket with the
capability to send sockets. It tries to reuse the original parameter if
it has this capability.

8 years agoMEDIUM: mworker: wait mode on reload failure
William Lallemand [Thu, 1 Jun 2017 15:38:52 +0000 (17:38 +0200)] 
MEDIUM: mworker: wait mode on reload failure

In Master Worker mode, when the reloading of the configuration fail,
the process is exiting leaving the children without their father.

To handle this, we register an exit function with atexit(3), which is
reexecuting the binary in a special mode. This particular mode of
HAProxy don't reload the configuration, it only loops on wait().

8 years agoMEDIUM: mworker: handle reload and signals
William Lallemand [Thu, 1 Jun 2017 15:38:51 +0000 (17:38 +0200)] 
MEDIUM: mworker: handle reload and signals

The master-worker will reload itself on SIGUSR2/SIGHUP

It's inherited from the systemd wrapper, when the SIGUSR2 signal is
received, the master process will reexecute itself with the -sf flag
followed by the PIDs of the children.

In the systemd wrapper, the children were using a pipe to notify when
the config has been parsed and when the new process is ready. The goal
was to ensure that the process couldn't reload during the parsing of the
configuration, before signals were send to old process.

With the new mworker model, the master parses the configuration and is
aware of all the children. We don't need a pipe, but we need to block
those signals before the end of a reload, to ensure that the process
won't be killed during a reload.

The SIGUSR1 signal is forwarded to the children to soft-stop HAProxy.

The SIGTERM and SIGINT signals are forwarded to the children in order to
terminate them.

8 years agoMEDIUM: mworker: replace systemd mode by master worker mode
William Lallemand [Thu, 1 Jun 2017 15:38:50 +0000 (17:38 +0200)] 
MEDIUM: mworker: replace systemd mode by master worker mode

This commit remove the -Ds systemd mode in HAProxy in order to replace
it by a more generic master worker system. It aims to replace entirely
the systemd wrapper in the near future.

The master worker mode implements a new way of managing HAProxy
processes. The master is in charge of parsing the configuration
file and is responsible for spawning child processes.

The master worker mode can be invoked by using the -W flag.  It can be
used either in background mode (-D) or foreground mode. When used in
background mode, the master will fork to daemonize.

In master worker background mode, chroot, setuid and setgid are done in
each child rather than in the master process, because the master process
will still need access to filesystem to reload the configuration.

8 years agoMINOR: boringssl: basic support for OCSP Stapling
Emmanuel Hocdet [Mon, 22 May 2017 12:58:00 +0000 (14:58 +0200)] 
MINOR: boringssl: basic support for OCSP Stapling

Use boringssl SSL_CTX_set_ocsp_response to set OCSP response from file with
'.ocsp' extension. CLI update is not supported.

8 years agoMEDIUM: ssl: handle multiple async engines
Emeric Brun [Wed, 17 May 2017 18:42:48 +0000 (20:42 +0200)] 
MEDIUM: ssl: handle multiple async engines

This patch adds the support of a maximum of 32 engines
in async mode.

Some tests have been done using 2 engines simultaneously.

This patch also removes specific 'async' attribute from the connection
structure. All the code relies only on Openssl functions.

8 years agoMAJOR: ssl: add openssl async mode support
Grant Zhang [Sat, 14 Jan 2017 01:42:15 +0000 (01:42 +0000)] 
MAJOR: ssl: add openssl async mode support

ssl-mode-async is a global configuration parameter which enables
asynchronous processing in OPENSSL for all SSL connections haproxy
handles. With SSL_MODE_ASYNC set, TLS I/O operations may indicate a
retry with SSL_ERROR_WANT_ASYNC with this mode set if an asynchronous
capable engine is used to perform cryptographic operations. Currently
async mode only supports one async-capable engine.

This is the latest version of the patchset which includes Emeric's
updates :
  - improved async fd cleaning when openssl reports an fd to delete
  - prevent conn_fd_handler from calling SSL_{read,write,handshake} until
    the async fd is ready, as these operations are very slow and waste CPU
  - postpone of SSL_free to ensure the async operation can complete and
    does not cause a dereference a released SSL.
  - proper removal of async fd from the fdtab and removal of the unused async
    flag.

8 years agoMEDIUM: ssl: add basic support for OpenSSL crypto engine
Grant Zhang [Sat, 21 Jan 2017 01:10:18 +0000 (01:10 +0000)] 
MEDIUM: ssl: add basic support for OpenSSL crypto engine

This patch adds the global 'ssl-engine' keyword. First arg is an engine
identifier followed by a list of default_algorithms the engine will
operate.

If the openssl version is too old, an error is reported when the option
is used.

8 years agoMEDIUM: proxy: zombify proxies only when the expose-fd socket is bound
William Lallemand [Fri, 26 May 2017 16:19:55 +0000 (18:19 +0200)] 
MEDIUM: proxy: zombify proxies only when the expose-fd socket is bound

When HAProxy is running with multiple processes and some listeners
arebound to processes, the unused sockets were not closed in the other
processes. The aim was to be able to send those listening sockets using
the -x option.

However to ensure the previous behavior which was to close those
sockets, we provided the "no-unused-socket" global option.

This patch changes this behavior, it will close unused sockets which are
not in the same process as an expose-fd socket, making the
"no-unused-socket" option useless.

The "no-unused-socket" option was removed in this patch.

8 years agoMINOR: cli: add 'expose-fd listeners' to pass listeners FDs
William Lallemand [Fri, 26 May 2017 15:42:10 +0000 (17:42 +0200)] 
MINOR: cli: add 'expose-fd listeners' to pass listeners FDs

This patch changes the stats socket rights for allowing the sending of
listening sockets.

The previous behavior was to allow any unix stats socket with admin
level to send sockets. It's not possible anymore, you have to set this
option to activate the socket sending.

Example:
   stats socket /var/run/haproxy4.sock mode 666 expose-fd listeners level user process 4

8 years agoMINOR: cli: add ACCESS_LVL_MASK to store the access level
William Lallemand [Tue, 23 May 2017 22:57:40 +0000 (00:57 +0200)] 
MINOR: cli: add ACCESS_LVL_MASK to store the access level

The current level variable use only 2 bits for storing the 3 access
level (user, oper and admin).

This patch add a bitmask which allows to use the remaining bits for
other usage.

8 years agoBUG/MEDIUM: lua: segfault if a converter or a sample doesn't return anything
Thierry FOURNIER [Fri, 12 May 2017 14:32:20 +0000 (16:32 +0200)] 
BUG/MEDIUM: lua: segfault if a converter or a sample doesn't return anything

In the case of a Lua sample-fetch or converter doesn't return any
value, an acces outside the Lua stack can be performed. This patch
check the stack size before converting the top value to a HAProxy
internal sample.

A workaround consist to check that a value value is always returned
with sample fetches and converters.

This patch should be backported in the version 1.6 and 1.7

8 years agoMINOR: sample: Add b64dec sample converter
Holger Just [Fri, 5 May 2017 22:56:53 +0000 (00:56 +0200)] 
MINOR: sample: Add b64dec sample converter

Add "b64dec" as a new converter which can be used to decode a base64
encoded string into its binary representation. It performs the inverse
operation of the "base64" converter.

8 years agoBUG/MAJOR: dns: Broken kqueue events handling (BSD systems).
Frédéric Lécaille [Fri, 12 May 2017 07:57:15 +0000 (09:57 +0200)] 
BUG/MAJOR: dns: Broken kqueue events handling (BSD systems).

Some DNS related network sockets were closed without unregistering their file
descriptors from their underlying kqueue event sets. This patch replaces calls to
close() by fd_delete() calls to that to delete such events attached to DNS
network sockets from the kqueue before closing the sockets.

The bug was introduced by commit 26c6eb8 ("BUG/MAJOR: dns: restart sockets
after fork()") which was backported in 1.7 so this fix has to be backported
there as well.

Thanks to Jim Pingle who reported it and indicated the faulty commit, and
to Lukas Tribus for the trace showing the bad file descriptor.

8 years agoCLEANUP: retire obsoleted USE_GETSOCKNAME build option
Dmitry Sivachenko [Fri, 12 May 2017 13:38:29 +0000 (15:38 +0200)] 
CLEANUP: retire obsoleted USE_GETSOCKNAME build option

The last user of this option disappeared in 1.5-dev10.

8 years agoMEDIUM: ssl: ssl-min-ver and ssl-max-ver compatibility.
Emmanuel Hocdet [Fri, 5 May 2017 16:06:12 +0000 (18:06 +0200)] 
MEDIUM: ssl: ssl-min-ver and ssl-max-ver compatibility.

In haproxy < 1.8, no-sslv3/no-tlsv1x are ignored when force-sslv3/force-tlsv1x
is used (without warning). With this patch, no-sslv3/no-tlsv1x are ignored when
ssl-min-ver or ssl-max-ver is used (with warning).
When all SSL/TLS versions are disable: generate an error, not a warning.
example: ssl-min-ver TLSV1.3 (or force-tlsv13) with a openssl <= 1.1.0.

8 years agoMEDIUM: ssl: add ssl-min-ver and ssl-max-ver parameters for bind and server
Emmanuel Hocdet [Fri, 31 Mar 2017 13:02:54 +0000 (15:02 +0200)] 
MEDIUM: ssl: add ssl-min-ver and ssl-max-ver parameters for bind and server

'ssl-min-ver' and 'ssl-max-ver' with argument SSLv3, TLSv1.0, TLSv1.1, TLSv1.2
or TLSv1.3 limit the SSL negotiation version to a continuous range. ssl-min-ver
and ssl-max-ver should be used in replacement of no-tls* and no-sslv3. Warning
and documentation are set accordingly.

8 years agoMINOR: ssl: show methods supported by openssl
Emmanuel Hocdet [Fri, 24 Mar 2017 14:20:03 +0000 (15:20 +0100)] 
MINOR: ssl: show methods supported by openssl

TLS v1.3 incoming, SSLv3 will disappears: it could be useful to list
all methods supported by haproxy/openssl (with -vvv).

8 years agoMINOR: ssl: support TLSv1.3 for bind and server
Emmanuel Hocdet [Thu, 30 Mar 2017 17:29:39 +0000 (19:29 +0200)] 
MINOR: ssl: support TLSv1.3 for bind and server

This patch add 'no-tlsv13' and 'force-tlsv13' configuration. This is
only useful with openssl-dev and boringssl.

8 years agoMEDIUM: ssl: calculate the real min/max TLS version and find holes
Emmanuel Hocdet [Thu, 30 Mar 2017 17:25:07 +0000 (19:25 +0200)] 
MEDIUM: ssl: calculate the real min/max TLS version and find holes

Plan is to add min-tlsxx max-tlsxx configuration, more consistent than no-tlsxx.
Find the real min/max versions (openssl capabilities and haproxy configuration)
and generate warning with bad versions range.
'no-tlsxx' can generate 'holes':
"The list of protocols available can be further limited using the SSL_OP_NO_X
options of the SSL_CTX_set_options or SSL_set_options functions. Clients should
avoid creating 'holes' in the set of protocols they support, when disabling a
protocol, make sure that you also disable either all previous or all subsequent
protocol versions. In clients, when a protocol version is disabled without
disabling all previous protocol versions, the effect is to also disable all
subsequent protocol versions."
To not break compatibility, "holes" is authorized with warning, because openssl
1.1.0 and boringssl deal with it (keep the upper or lower range depending the
case and version).

8 years agoMEDIUM: ssl: ssl_methods implementation is reworked and factored for min/max tlsxx
Emmanuel Hocdet [Thu, 30 Mar 2017 17:19:37 +0000 (19:19 +0200)] 
MEDIUM: ssl: ssl_methods implementation is reworked and factored for min/max tlsxx

Plan is to add min-tlsxx max-tlsxx configuration, more consistent than no-tlsxx.
This patch introduce internal min/max and replace force-tlsxx implementation.
SSL method configuration is store in 'struct tls_version_filter'.
SSL method configuration to openssl setting is abstract in 'methodVersions' table.
With openssl < 1.1.0, SSL_CTX_set_ssl_version is used for force (min == max).
With openssl >= 1.1.0, SSL_CTX_set_min/max_proto_version is used.

8 years agoMEDIUM: ssl: revert ssl/tls version settings relative to default-server.
Emmanuel Hocdet [Thu, 30 Mar 2017 12:43:31 +0000 (14:43 +0200)] 
MEDIUM: ssl: revert ssl/tls version settings relative to default-server.

Plan is to add min-tlsxx max-tlsxx configuration, more consistent than no-tlsxx.
min-tlsxx and max-tlsxx can be overwrite on local definition. This directives
should be the only ones needed in default-server.
To simplify next patches (rework of tls versions settings with min/max) all
ssl/tls version settings relative to default-server are reverted first:
remove: 'sslv3', 'tls*', 'no-force-sslv3', 'no-force-tls*'.
remove from default-server: 'no-sslv3', 'no-tls*'.
Note:
. force-tlsxx == min-tlsxx + max-tlsxx : would be ok in default-server.
. no-tlsxx is keep for compatibility: should not be propagated to default-server.

8 years agoMINOR: ssl: add prefer-client-ciphers
Lukas Tribus [Thu, 4 May 2017 15:45:40 +0000 (15:45 +0000)] 
MINOR: ssl: add prefer-client-ciphers

Currently we unconditionally set SSL_OP_CIPHER_SERVER_PREFERENCE [1],
which may not always be a good thing.

The benefit of server side cipher prioritization may not apply to all
cases out there, and it appears that the various SSL libs are going away
from this recommendation ([2], [3]), as insecure ciphers suites are
properly blacklisted/removed and honoring the client's preference is
more likely to improve user experience  (for example using SW-friendly
ciphers on devices without HW AES support).

This is especially true for TLSv1.3, which will restrict the cipher
suites to just AES-GCM and Chacha20/Poly1305.

Apache [4], nginx [5] and others give admins full flexibility, we should
as well.

The initial proposal to change the current default and add a
"prefer-server-ciphers" option (as implemented in e566ecb) has been
declined due to the possible security impact.

This patch implements prefer-client-ciphers without changing the defaults.

[1] https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html
[2] https://github.com/openssl/openssl/issues/541
[3] https://github.com/libressl-portable/portable/issues/66
[4] https://httpd.apache.org/docs/2.0/en/mod/mod_ssl.html#sslhonorcipherorder
[5] https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_prefer_server_ciphers

8 years agoBUG/MINOR: checks: don't send proxy protocol with agent checks
Willy Tarreau [Sat, 6 May 2017 06:45:28 +0000 (08:45 +0200)] 
BUG/MINOR: checks: don't send proxy protocol with agent checks

James Brown reported that agent-check mistakenly sends the proxy
protocol header when it's configured. This is obviously wrong as
the agent is an independant servie and not a traffic port, let's
disable this.

This fix must be backported to 1.7 and possibly 1.6.

8 years agoBUG/MINOR: contrib/mod_security: fix build on FreeBSD
David CARLIER [Wed, 3 May 2017 09:23:08 +0000 (10:23 +0100)] 
BUG/MINOR: contrib/mod_security: fix build on FreeBSD

Fix linker flags settings since 3rd parties libraries are not in
/usr/lib
Plus libfuzzy needs to be added.
undef LIST_HEAD from event2 which conflicts with haproxy's

8 years agoMINOR: server: cli: Add server FQDNs to server-state file and stats socket.
Frédéric Lécaille [Wed, 26 Apr 2017 09:24:02 +0000 (11:24 +0200)] 
MINOR: server: cli: Add server FQDNs to server-state file and stats socket.

This patch adds a new stats socket command to modify server
FQDNs at run time.
Its syntax:
  set server <backend>/<server> fqdn <FQDN>
This patch also adds FQDNs to server state file at the end
of each line for backward compatibility ("-" if not present).

8 years agoCONTRIB: tcploop: add action "X" to execute a command
Willy Tarreau [Tue, 2 May 2017 20:14:59 +0000 (22:14 +0200)] 
CONTRIB: tcploop: add action "X" to execute a command

Sometimes it's convenient to be able to execute a command directly on
the stream, whether we're connecting or accepting an incoming connection.
New command 'X' makes this possible. It simply calls execvp() on the
next arguments and branches stdin/stdout/stderr on the socket. Optionally
it's possible to limit the passed FDs to any combination of them by
appending 'i', 'o', 'e' after the X. In any case the program ends just
after executing this command.

Examples :
- chargen server
      tcploop 8001 L A Xo cat /dev/zero

- telnet server
      tcploop 8001 L W N A X /usr/sbin/in.telnetd

8 years agoDOC: update RFC references
Lukas Tribus [Fri, 28 Apr 2017 13:24:30 +0000 (13:24 +0000)] 
DOC: update RFC references

A few doc and code comment updates bumping RFC references to the new
ones.

8 years agoBUG/MINOR: ssl: fix warnings about methods for opensslv1.1.
Emeric Brun [Fri, 28 Apr 2017 14:19:51 +0000 (16:19 +0200)] 
BUG/MINOR: ssl: fix warnings about methods for opensslv1.1.

This patch replaces the calls to TLSvX_X_client/server/_method
by the new TLS_client/server_method and it uses the new functions
SSL_set_min_proto_version and SSL_set_max_proto_version, setting them
at the wanted protocol version using 'force-' statements.

8 years agoMINOR: Add ModSecurity wrapper as contrib
Thierry FOURNIER [Mon, 10 Apr 2017 21:47:23 +0000 (23:47 +0200)] 
MINOR: Add ModSecurity wrapper as contrib

This patch contains a base for a modsecurity wrapper in HAProxy using SPOE.

8 years agoMINOR: proto-http: Add sample fetch wich returns all HTTP headers
Thierry FOURNIER [Wed, 19 Apr 2017 13:15:14 +0000 (15:15 +0200)] 
MINOR: proto-http: Add sample fetch wich returns all HTTP headers

The sample fetch returns all headers including the last jump line.
The last jump line is used to determine if the block of headers is
truncated or not.

8 years agoMINOR: Add binary encoding request header sample fetch
Thierry FOURNIER [Sun, 9 Apr 2017 03:38:19 +0000 (05:38 +0200)] 
MINOR: Add binary encoding request header sample fetch

This sample fetch encodes the http request headers in binary
format. This sample-fetch is useful with SPOE.

8 years agoREORG: spoe: move spoe_encode_varint / spoe_decode_varint from spoe to common
Thierry FOURNIER [Wed, 19 Apr 2017 09:49:44 +0000 (11:49 +0200)] 
REORG: spoe: move spoe_encode_varint / spoe_decode_varint from spoe to common

These encoding functions does general stuff and can be used in
other context than spoe. This patch moves the function spoe_encode_varint
and spoe_decode_varint from spoe to common. It also remove the prefix spoe.

These functions will be used for encoding values in new binary sample fetch.

8 years agoBUG/MINOR: change header-declared function to static inline
Thierry FOURNIER [Sun, 9 Apr 2017 03:41:27 +0000 (05:41 +0200)] 
BUG/MINOR: change header-declared function to static inline

When we include the header proto/spoe.h in other files in the same
project, the compilator claim that the symbol have multiple definitions:

   src/flt_spoe.o: In function `spoe_encode_varint':
   ~/git/haproxy/include/proto/spoe.h:45: multiple definition of `spoe_encode_varint'
   src/proto_http.o:~/git/haproxy/include/proto/spoe.h:45: first defined here

8 years agoBUG/MINOR: hash-balance-factor isn't effective in certain circumstances
Andrew Rodland [Wed, 26 Apr 2017 06:57:03 +0000 (02:57 -0400)] 
BUG/MINOR: hash-balance-factor isn't effective in certain circumstances

in chash_get_server_hash, we find the nearest server entries both
before and after the request hash. If the next and prev entries both
point to the same server, the function would exit early and return that
server, to save work.

Before hash-balance-factor this was a valid optimization -- one of nsrv
and psrv would definitely be chosen, so if they are the same there's no
need to choose between them. But with hash-balance-factor it's possible
that adding another request to that server would overload it
(chash_server_is_eligible returns false) and we go further around the
ring. So it's not valid to return before checking for that.

This commit simply removes the early return, as it provides a minimal
savings even when it's correct.

8 years agoCLEANUP: lua: remove test
Thierry FOURNIER [Wed, 26 Apr 2017 11:27:05 +0000 (13:27 +0200)] 
CLEANUP: lua: remove test

The man of "luaL_unref" says "If ref is LUA_NOREF or LUA_REFNIL,
luaL_unref does nothing.", so I remove the check.

8 years agoBUG/MEDIUM: lua: memory leak
Thierry FOURNIER [Wed, 26 Apr 2017 12:25:58 +0000 (14:25 +0200)] 
BUG/MEDIUM: lua: memory leak

The priv context is not cleaned when we set a new priv context.
This is caused by a stupid swap between two parameter of the
luaL_unref() function.

workaround: use set_priv only once when we process a stream.

This patch should be backported in version 1.7 and 1.6

8 years agoDOC: errloc/errorloc302/errorloc303 missing status codes.
Jarno Huuskonen [Sat, 22 Apr 2017 08:26:50 +0000 (11:26 +0300)] 
DOC: errloc/errorloc302/errorloc303 missing status codes.

errorloc/errorloc302/errorloc303 was missing some status codes that
haproxy can generate.

8 years agoDOC: add layer 4 links/cross reference to "block" keyword.
Jarno Huuskonen [Thu, 6 Apr 2017 10:59:14 +0000 (13:59 +0300)] 
DOC: add layer 4 links/cross reference to "block" keyword.

Idea from Aleksandar Lazic: add explanation/links about layer4
tcp-request connection or content reject to "block" keyword.

Add http-request cross ref. to "tcp-request content".

8 years agoDOC: Add documentation for new "server-template" keyword.
Frédéric Lécaille [Thu, 20 Apr 2017 11:36:25 +0000 (13:36 +0200)] 
DOC: Add documentation for new "server-template" keyword.

8 years agoMINOR: server: Add server_template_init() function to initialize servers from a templ...
Frédéric Lécaille [Fri, 14 Apr 2017 11:28:00 +0000 (13:28 +0200)] 
MINOR: server: Add server_template_init() function to initialize servers from a templates.

This patch adds server_template_init() function used to initialize servers
from server templates. It is called just after having parsed a 'server-template'
line.

8 years agoMINOR: server: Add 'server-template' new keyword supported in backend sections.
Frédéric Lécaille [Thu, 13 Apr 2017 16:24:23 +0000 (18:24 +0200)] 
MINOR: server: Add 'server-template' new keyword supported in backend sections.

This patch makes backend sections support 'server-template' new keyword.
Such 'server-template' objects are parsed similarly to a 'server' object
by parse_server() function, but its first arguments are as follows:
    server-template <ID prefix> <nb | range> <ip | fqdn>:<port> ...

The remaining arguments are the same as for 'server' lines.

With such server template declarations, servers may be allocated with IDs
built from <ID prefix> and <nb | range> arguments.

For instance declaring:
    server-template foo 1-5 google.com:80 ...
or
    server-template foo 5 google.com:80 ...

would be equivalent to declare:
    server foo1 google.com:80 ...
    server foo2 google.com:80 ...
    server foo3 google.com:80 ...
    server foo4 google.com:80 ...
    server foo5 google.com:80 ...

8 years agoMINOR: server: Extract the code which finalizes server initializations after 'server...
Frédéric Lécaille [Thu, 30 Mar 2017 15:32:36 +0000 (17:32 +0200)] 
MINOR: server: Extract the code which finalizes server initializations after 'server' lines parsing.

This patch moves the code which is responsible of finalizing server initializations
after having fully parsed a 'server' line (health-check, agent check and SNI expression
initializations) from parse_server() to new functions.

8 years agoMINOR: server: Extract the code responsible of copying default-server settings.
Frédéric Lécaille [Thu, 30 Mar 2017 12:18:30 +0000 (14:18 +0200)] 
MINOR: server: Extract the code responsible of copying default-server settings.

This patch moves the code responsible of copying default server settings
to a new server instance from parse_server() function to new defsrv_*_cpy()
functions which may be used both during server lines parsing and during server
templates initializations to come.

These defsrv_*_cpy() do not make any reference to anything else than default
server settings.

8 years agoBUG/MINOR: server: missing default server 'resolvers' setting duplication.
Frédéric Lécaille [Thu, 20 Apr 2017 10:17:50 +0000 (12:17 +0200)] 
BUG/MINOR: server: missing default server 'resolvers' setting duplication.

'resolvers' setting was not duplicated from default server setting to
new server instances when parsing 'server' lines.
This fix is simple: strdup() default resolvers <id> string argument after
having allocated a new server when parsing 'server' lines.

This patch must be backported to 1.7 and 1.6.

8 years agoBUG/MEDIUM: http: Drop the connection establishment when a redirect is performed
Christopher Faulet [Thu, 20 Apr 2017 12:16:13 +0000 (14:16 +0200)] 
BUG/MEDIUM: http: Drop the connection establishment when a redirect is performed

This bug occurs when a redirect rule is applied during the request analysis on a
persistent connection, on a proxy without any server. This means, in a frontend
section or in a listen/backend section with no "server" line.

Because the transaction processing is shortened, no server can be selected to
perform the connection. So if we try to establish it, this fails and a 503 error
is returned, while a 3XX was already sent. So, in this case, HAProxy generates 2
replies and only the first one is expected.

Here is the configuration snippet to easily reproduce the problem:

    listen www
        bind :8080
        mode http
        timeout connect 5s
        timeout client 3s
        timeout server 6s
        redirect location /

A simple HTTP/1.1 request without body will trigger the bug:

    $ telnet 0 8080
    Trying 0.0.0.0...
    Connected to 0.
    Escape character is '^]'.
    GET / HTTP/1.1

    HTTP/1.1 302 Found
    Cache-Control: no-cache
    Content-length: 0
    Location: /

    HTTP/1.0 503 Service Unavailable
    Cache-Control: no-cache
    Connection: close
    Content-Type: text/html

    <html><body><h1>503 Service Unavailable</h1>
    No server is available to handle this request.
    </body></html>
    Connection closed by foreign host.

[wt: only 1.8-dev is impacted though the bug is present in older ones]

8 years agoBUG/MINOR: server: don't use "proxy" when px is really meant.
Olivier Houchard [Thu, 20 Apr 2017 16:21:17 +0000 (18:21 +0200)] 
BUG/MINOR: server: don't use "proxy" when px is really meant.

In server_parse_sni_expr(), we use the "proxy" global variable, when we
should probably be using "px" given as an argument.
It happens to work by accident right now, but may not in the future.

[wt: better backport it]

8 years agoBUG/MAJOR: Use -fwrapv.
Olivier Houchard [Wed, 19 Apr 2017 09:34:10 +0000 (11:34 +0200)] 
BUG/MAJOR: Use -fwrapv.

Haproxy relies on signed integer wraparound on overflow, however this is
really an undefined behavior, so the C compiler is allowed to do whatever
it wants, and clang does exactly that, and that causes problems when the
timer goes from <= INT_MAX to > INT_MAX, and explains the various hangs
reported on FreeBSD every 49.7 days. To make sure we get the intended
behavior, use -fwrapv for now. A proper fix is to switch everything to
unsigned, and it will happen later, but this is simpler, and more likely to
be backported to the stable branches.
Many thanks to David King, Mark S, Dave Cottlehuber, Slawa Olhovchenkov,
Piotr Pawel Stefaniak, and any other I may have forgotten for reporting that
and investigating.

8 years agoMEDIUM: config: don't check config validity when there are fatal errors
Willy Tarreau [Wed, 19 Apr 2017 09:24:07 +0000 (11:24 +0200)] 
MEDIUM: config: don't check config validity when there are fatal errors

Overall we do have an issue with the severity of a number of errors. Most
fatal errors are reported with ERR_FATAL (which prevents startup) and not
ERR_ABORT (which stops parsing ASAP), but check_config_validity() is still
called on ERR_FATAL, and will most of the time report bogus errors. This
is what caused smp_resolve_args() to be called on a number of unparsable
ACLs, and it also is what reports incorrect ordering or unresolvable
section names when certain entries could not be properly parsed.

This patch stops this domino effect by simply aborting before trying to
further check and resolve the configuration when it's already know that
there are fatal errors.

A concrete example comes from this config :

  userlist users :
      user foo insecure-password bar

  listen foo
      bind :1234
      mode htttp
      timeout client 10S
      timeout server 10s
      timeout connect 10s
      stats uri /stats
      stats http-request auth unless { http_auth(users) }
      http-request redirect location /index.html if { path / }

It contains a colon after the userlist name, a typo in the client timeout value,
another one in "mode http" which cause some other configuration elements not to
be properly handled.

Previously it would confusingly report :

  [ALERT] 108/114851 (20224) : parsing [err-report.cfg:1] : 'userlist' cannot handle unexpected argument ':'.
  [ALERT] 108/114851 (20224) : parsing [err-report.cfg:6] : unknown proxy mode 'htttp'.
  [ALERT] 108/114851 (20224) : parsing [err-report.cfg:7] : unexpected character 'S' in 'timeout client'
  [ALERT] 108/114851 (20224) : Error(s) found in configuration file : err-report.cfg
  [ALERT] 108/114851 (20224) : parsing [err-report.cfg:11] : unable to find userlist 'users' referenced in arg 1 of ACL keyword 'http_auth' in proxy 'foo'.
  [WARNING] 108/114851 (20224) : config : missing timeouts for proxy 'foo'.
     | While not properly invalid, you will certainly encounter various problems
     | with such a configuration. To fix this, please ensure that all following
     | timeouts are set to a non-zero value: 'client', 'connect', 'server'.
  [WARNING] 108/114851 (20224) : config : 'stats' statement ignored for proxy 'foo' as it requires HTTP mode.
  [WARNING] 108/114851 (20224) : config : 'http-request' rules ignored for proxy 'foo' as they require HTTP mode.
  [ALERT] 108/114851 (20224) : Fatal errors found in configuration.

The "requires HTTP mode" errors are just pollution resulting from the
improper spelling of this mode earlier. The unresolved reference to the
userlist is caused by the extra colon on the declaration, and the warning
regarding the missing timeouts is caused by the wrong character.

Now it more accurately reports :

  [ALERT] 108/114900 (20225) : parsing [err-report.cfg:1] : 'userlist' cannot handle unexpected argument ':'.
  [ALERT] 108/114900 (20225) : parsing [err-report.cfg:6] : unknown proxy mode 'htttp'.
  [ALERT] 108/114900 (20225) : parsing [err-report.cfg:7] : unexpected character 'S' in 'timeout client'
  [ALERT] 108/114900 (20225) : Error(s) found in configuration file : err-report.cfg
  [ALERT] 108/114900 (20225) : Fatal errors found in configuration.

Despite not really a fix, this patch should be backported at least to 1.7,
possibly even 1.6, and 1.5 since it hardens the config parser against
certain bad situations like the recently reported use-after-free and the
last null dereference.

8 years agoBUG/MEDIUM: acl: proprely release unused args in prune_acl_expr()
Willy Tarreau [Wed, 19 Apr 2017 09:13:48 +0000 (11:13 +0200)] 
BUG/MEDIUM: acl: proprely release unused args in prune_acl_expr()

Stephan Zeisberg reported another dirty abort case which can be triggered
with this simple config (where file "d" doesn't exist) :

    backend b1
        stats  auth a:b
        acl auth_ok http_auth(c) -f d

This issue was brought in 1.5-dev9 by commit 34db108 ("MAJOR: acl: make use
of the new argument parsing framework") when prune_acl_expr() started to
release arguments. The arg pointer is set to NULL but not its length.
Because of this, later in smp_resolve_args(), the argument is still seen
as valid (since only a test on the length is made as in all other places),
and the NULL pointer is dereferenced.

This patch properly clears the lengths to avoid such tests.

This fix needs to be backported to 1.7, 1.6, and 1.5.

8 years agoCLEANUP: logs: typo: simgle => single
Jim Freeman [Sat, 15 Apr 2017 14:01:59 +0000 (08:01 -0600)] 
CLEANUP: logs: typo: simgle => single

Typo in error message. Backport to 1.7.

8 years agoBUG/MAJOR: Broken parsing for valid keywords provided after 'source' setting.
Frédéric Lécaille [Sun, 16 Apr 2017 15:14:14 +0000 (17:14 +0200)] 
BUG/MAJOR: Broken parsing for valid keywords provided after 'source' setting.

Any valid keyword could not be parsed anymore if provided after 'source' keyword.
This was due to the fact that 'source' number of arguments is variable.
So, as its parser srv_parse_source() is the only one who may know how many arguments
was provided after 'source' keyword, it updates 'cur_arg' variable (the index
in the line of the current arg to be parsed), this is a good thing.
This variable is also incremented by one (to skip the 'source' keyword).
This patch disable this behavior.

Should have come with dba9707 commit.

8 years agoBUG/MINOR: server: Fix a wrong error message during 'usesrc' keyword parsing.
Frédéric Lécaille [Fri, 14 Apr 2017 13:19:56 +0000 (15:19 +0200)] 
BUG/MINOR: server: Fix a wrong error message during 'usesrc' keyword parsing.

'usesrc' setting is not permitted on 'server' lines if not provided after
'source' setting. This is now also the case on 'default-server' lines.
Without this patch parse_server() parser displayed that 'usersrc' is
an unknown keyword.

Should have come with dba9707 commit.

8 years agoMINOR: systemd wrapper: add support for passing the -x option.
Olivier Houchard [Sun, 9 Apr 2017 14:28:10 +0000 (16:28 +0200)] 
MINOR: systemd wrapper: add support for passing the -x option.

Make the systemd wrapper chech if HAPROXY_STATS_SOCKET if set.
If set, it will use it as an argument to the "-x" option, which makes
haproxy asks for any listening socket, on the stats socket, in order
to achieve reloads with no new connection lost.

8 years agoMINOR: socket transfer: Set a timeout on the socket.
Olivier Houchard [Thu, 6 Apr 2017 12:45:14 +0000 (14:45 +0200)] 
MINOR: socket transfer: Set a timeout on the socket.

Make sure we're not stuck forever by setting a timeout on the socket.

8 years agoMINOR: proxy: Don't close FDs if not our proxy.
Olivier Houchard [Wed, 5 Apr 2017 23:05:05 +0000 (01:05 +0200)] 
MINOR: proxy: Don't close FDs if not our proxy.

When running with multiple process, if some proxies are just assigned
to some processes, the other processes will just close the file descriptors
for the listening sockets. However, we may still have to provide those
sockets when reloading, so instead we just try hard to pretend those proxies
are dead, while keeping the sockets opened.
A new global option, no-reused-socket", has been added, to restore the old
behavior of closing the sockets not bound to this process.