]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
8 years agoMAJOR: spoe: refactor the filter to clean up the code
Christopher Faulet [Mon, 20 Feb 2017 21:56:03 +0000 (22:56 +0100)] 
MAJOR: spoe: refactor the filter to clean up the code

The SPOE code is now pretty big and it was the good time to clean it up. It is
not perfect, some parts remains a bit ugly. But it is far better now.

8 years agoMINOR: spoe: Add support for fragmentation capability in the SPOA example
Christopher Faulet [Thu, 2 Feb 2017 09:14:36 +0000 (10:14 +0100)] 
MINOR: spoe: Add support for fragmentation capability in the SPOA example

This is just an example. So be careful to not send really huge payload because
it would eat all your memory.

8 years agoMAJOR: spoe: Add support of payload fragmentation in NOTIFY frames
Christopher Faulet [Thu, 19 Jan 2017 09:01:12 +0000 (10:01 +0100)] 
MAJOR: spoe: Add support of payload fragmentation in NOTIFY frames

Now, agents can announce the support for the "fragmentation" capability during
the HELLO handshake. HAProxy will never announce it because fragmented frame
decoding is not implemented yet. But it can send such kind of frames. So, if an
agent supports this capability, payloads exceeding the frame size will be
split. A fragemented payload consists of several frames with the FIN bit clear
and terminated by a single frame with the FIN bit set. All these frames must
share the same STREAM-ID and FRAME-ID.

Note that an unfragemnted payload consists of a single frame with the FIN bit
set. And HELLO and DISCONNECT frames cannot be fragmented. This means that only
NOTIFY frames can transport fragmented payload for now.

8 years agoMINOR: spoe: Use the min of all known max_frame_size to encode messages
Christopher Faulet [Fri, 13 Jan 2017 10:30:50 +0000 (11:30 +0100)] 
MINOR: spoe: Use the min of all known max_frame_size to encode messages

The max_frame_size value is negociated between HAProxy and SPOE agents during
the HELLO handshake. It is a per-connection value. Different SPOE agents can
choose to use different max_frame_size values. So, now, we keep the minimum of
all known max_frame_size. This minimum is updated when a new connection to a
SPOE agent is opened and when a connection is closed. We use this value as a
limit to encode messages in NOTIFY frames.

8 years agoMEDIUM: spoe: Be sure to wakeup the good entity waiting for a buffer
Christopher Faulet [Wed, 11 Jan 2017 13:05:19 +0000 (14:05 +0100)] 
MEDIUM: spoe: Be sure to wakeup the good entity waiting for a buffer

This happens when buffer allocation failed. In the SPOE context, buffers are
allocated by streams and SPOE applets at different time. First, by streams, when
messages need to be encoded before sending them in a NOTIFY frame. Then, by SPOE
applets, when a ACK frame is received.

The first case works as expected, we wake up the stream. But for the second one,
we must wake up the waiting SPOE applet.

8 years agoMINOR: spoe: Check the scope of sample fetches used in SPOE messages
Christopher Faulet [Mon, 9 Jan 2017 15:56:23 +0000 (16:56 +0100)] 
MINOR: spoe: Check the scope of sample fetches used in SPOE messages

If an error is triggered, the corresponding message is ignored and a warning is
emitted.

8 years agoMINOR: spoe: Send a log message when an error occurred during event processing
Christopher Faulet [Wed, 4 Jan 2017 15:39:41 +0000 (16:39 +0100)] 
MINOR: spoe: Send a log message when an error occurred during event processing

8 years agoMINOR: spoe: Add status code in error variable instead of hardcoded value
Christopher Faulet [Wed, 4 Jan 2017 15:39:11 +0000 (16:39 +0100)] 
MINOR: spoe: Add status code in error variable instead of hardcoded value

Now, when option "set-on-error" is enabled, we set a status code representing
the error occurred instead of "true". For values under 256, it represents an
error coming from the engine. Below 256, it reports a SPOP error. In this case,
to retrieve the right SPOP status code, you must remove 256 to this value. Here
are possible values:

  * 1:     a timeout occurred during the event processing.
  * 2:     an error was triggered during the ressources allocation.
  * 255:   an unknown error occurred during the event processing.
  * 256+N: a SPOP error occurred during the event processing.

8 years agoMINOR: spoe: Remove SPOE details from the appctx structure
Christopher Faulet [Wed, 4 Jan 2017 13:14:19 +0000 (14:14 +0100)] 
MINOR: spoe: Remove SPOE details from the appctx structure

Now, as for peers, we use an opaque pointer to store information related to the
SPOE filter in appctx structure. These information are now stored in a dedicated
structure (spoe_appctx) and allocated, using a pool, when the applet is created.

This removes the dependency between applets and the SPOE filter and avoids to
eventually inflate the appctx structure.

8 years agoMINOR: spoe: Add support for pipelining/async capabilities in the SPOA example
Christopher Faulet [Wed, 21 Dec 2016 07:58:16 +0000 (08:58 +0100)] 
MINOR: spoe: Add support for pipelining/async capabilities in the SPOA example

Now, we can use the option '-c' to enable the support of a capability. By
default, all capabilities are disabled. For example:

  $> ./spoa -c async -c pipelining

In addition, it is also possible to set the maximum frame size supported by your
agent (-m) and to add a delay in frames processing (-t).

8 years agoMAJOR: spoe: Add support of pipelined and asynchronous exchanges with agents
Christopher Faulet [Wed, 21 Dec 2016 07:58:06 +0000 (08:58 +0100)] 
MAJOR: spoe: Add support of pipelined and asynchronous exchanges with agents

Now, HAProxy and agents can announce the support for "pipelining" and/or "async"
capabilities during the HELLO handshake. For now, HAProxy always announces the
support of both. In addition, in its HELLO frames. HAproxy adds the "engine-id"
key. It is a uniq string that identify a SPOE engine.

The "pipelining" capability is the ability for a peer to decouple NOTIFY and ACK
frames. This is a symmectical capability. To be used, it must be supported by
HAproxy and agents. Unlike HTTP pipelining, the ACK frames can be send in any
order, but always on the same TCP connection used for the corresponding NOTIFY
frame.

The "async" capability is similar to the pipelining, but here any TCP connection
established between HAProxy and the agent can be used to send ACK frames. if an
agent accepts connections from multiple HAProxy, it can use the "engine-id"
value to group TCP connections.

8 years agoBUG/MINOR: spoe: Fix parsing of arguments in spoe-message section
Christopher Faulet [Thu, 23 Feb 2017 21:41:09 +0000 (22:41 +0100)] 
BUG/MINOR: spoe: Fix parsing of arguments in spoe-message section

The array of pointers passed to sample_parse_expr was not really an array but a
pointer to pointer. So it can easily lead to a segfault during the configuration
parsing.

8 years agoBUG/MINOR: spoe: Fix soft stop handler using a specific id for spoe filters
Christopher Faulet [Thu, 23 Feb 2017 09:17:15 +0000 (10:17 +0100)] 
BUG/MINOR: spoe: Fix soft stop handler using a specific id for spoe filters

During a soft stop, we need to wakeup all SPOE applets to stop them. So we loop
on all proxies, and for each proxy, on all filters. But we must be sure to only
handle SPOE filters here. To do so, we use a specific id.

8 years agoMINOR: ssl: improved cipherlist captures
Emmanuel Hocdet [Wed, 8 Mar 2017 10:07:10 +0000 (11:07 +0100)] 
MINOR: ssl: improved cipherlist captures

Alloc capture buffer later (when filling), parse client-hello after
heartbeat check and remove capture->conn (unused).

8 years agoBUG/MINOR: ssl: fix cipherlist captures with sustainable SSL calls
Emmanuel Hocdet [Tue, 7 Mar 2017 17:34:58 +0000 (18:34 +0100)] 
BUG/MINOR: ssl: fix cipherlist captures with sustainable SSL calls

Use SSL_set_ex_data/SSL_get_ex_data standard API call to store capture.
We need to avoid internal structures/undocumented calls usage to try to
control the beast and limit painful compatibilities.

8 years agoBUG/MEDIUM: ssl: in bind line, ssl-options after 'crt' are ignored.
Emmanuel Hocdet [Mon, 6 Mar 2017 14:34:44 +0000 (15:34 +0100)] 
BUG/MEDIUM: ssl: in bind line, ssl-options after 'crt' are ignored.

Bug introduced with "removes SSL_CTX_set_ssl_version call and cleanup CTX
creation": ssl_sock_new_ctx is called before all the bind line is parsed.
The fix consists of separating the use of default_ctx as the initialization
context of the SSL connection via bind_conf->initial_ctx. Initial_ctx contains
all the necessary parameters before performing the selection of the CTX:
default_ctx is processed as others ctx without unnecessary parameters.

8 years agoMEDIUM: ssl: remove ssl-options from crt-list
Emmanuel Hocdet [Fri, 20 Jan 2017 12:06:27 +0000 (13:06 +0100)] 
MEDIUM: ssl: remove ssl-options from crt-list

ssl-options are link to the initial negotiation environnement worn
by default_ctx.
Remove it from crt-list to avoid any confusion.

8 years agoMEDIUM: ssl: add new sample-fetch which captures the cipherlist
Thierry FOURNIER [Sat, 25 Feb 2017 11:45:22 +0000 (12:45 +0100)] 
MEDIUM: ssl: add new sample-fetch which captures the cipherlist

This new sample-fetches captures the cipher list offer by the client
SSL connection during the client-hello phase. This is useful for
fingerprint the SSL connection.

8 years agoBUILD: ssl: fix build with -DOPENSSL_NO_DH
Emmanuel Hocdet [Fri, 3 Mar 2017 16:04:14 +0000 (17:04 +0100)] 
BUILD: ssl: fix build with -DOPENSSL_NO_DH

8 years agoMINOR: ssl: removes SSL_CTX_set_ssl_version call and cleanup CTX creation.
Emmanuel Hocdet [Fri, 3 Mar 2017 11:21:32 +0000 (12:21 +0100)] 
MINOR: ssl: removes SSL_CTX_set_ssl_version call and cleanup CTX creation.

BoringSSL doesn't support SSL_CTX_set_ssl_version. To remove this call, the
CTX creation is cleanup to clarify what is happening. SSL_CTX_new is used to
match the original behavior, in order: force-<method> according the method
version then the default method with no-<method> options.
OPENSSL_NO_SSL3 error message is now in force-sslv3 parsing (as force-tls*).
For CTX creation in bind environement, all CTX set related to the initial ctx
are aggregate to ssl_sock_new_ctx function for clarity.

Tests with crt-list have shown that server_method, options and mode are
linked to the initial CTX (default_ctx): all ssl-options are link to each
bind line and must be removed from crt-list.

8 years agoBUG/MEDIUM: ssl: switchctx should not return SSL_TLSEXT_ERR_ALERT_WARNING
Emmanuel Hocdet [Fri, 3 Mar 2017 14:21:26 +0000 (15:21 +0100)] 
BUG/MEDIUM: ssl: switchctx should not return SSL_TLSEXT_ERR_ALERT_WARNING

Extract from RFC 6066:
"If the server understood the ClientHello extension but does not recognize
the server name, the server SHOULD take one of two actions: either abort the
handshake by sending a fatal-level unrecognized_name(112) alert or continue the
handshake. It is NOT RECOMMENDED to send a warning-level unrecognized_name(112)
alert, because the client's behavior in response to warning-level alerts is
unpredictable. If there is a mismatch between the server name used by the
client application and the server name of the credential chosen by the server,
this mismatch will become apparent when the client application performs the
server endpoint identification, at which point the client application will have
to decide whether to proceed with the communication."

Thanks Roberto Guimaraes for the bug repport, spotted with openssl-1.1.0.
This fix must be backported.

8 years agoBUG/MEDIUM: ssl: fix verify/ca-file per certificate
Emmanuel Hocdet [Wed, 1 Mar 2017 17:54:56 +0000 (18:54 +0100)] 
BUG/MEDIUM: ssl: fix verify/ca-file per certificate

SSL verify and client_CA inherits from the initial ctx (default_ctx).
When a certificate is found, the SSL connection environment must be replaced by
the certificate configuration (via SSL_set_verify and SSL_set_client_CA_list).

8 years agoMEDIUM: boringssl: support native multi-cert selection without bundling
Emmanuel Hocdet [Mon, 20 Feb 2017 15:11:50 +0000 (16:11 +0100)] 
MEDIUM: boringssl: support native multi-cert selection without bundling

This patch used boringssl's callback to analyse CLientHello before any
handshake to extract key signature capabilities.
Certificat with better signature (ECDSA before RSA) is choosed
transparenty, if client can support it. RSA and ECDSA certificates can
be declare in a row (without order). This makes it possible to set
different ssl and filter parameter with crt-list.

8 years agoMINOR: http: don't close when redirect location doesn't start with "/"
Willy Tarreau [Tue, 28 Feb 2017 08:48:11 +0000 (09:48 +0100)] 
MINOR: http: don't close when redirect location doesn't start with "/"

In 1.4-dev5 when we started to implement keep-alive, commit a9679ac
("[MINOR] http: make the conditional redirect support keep-alive")
added a specific check was added to support keep-alive on redirect
rules but only when the location would start with a "/" indicating
the client would come back to the same server.

But nowadays most applications put http:// or https:// in front of
each and every location, and continuing to perform a close there is
counter-efficient, especially when multiple objects are fetched at
once from a same origin which redirects them to the correct origin
(eg: after an http to https forced upgrade).

It's about time to get rid of this old trick as it causes more harm
than good at an era where persistent connections are omnipresent.

Special thanks to Ciprian Dorin Craciun for providing convincing
arguments with a pretty valid use case and proposing this draft
patch which addresses the issue he was facing.

This change although not exactly a bug fix should be backported
to 1.7 to adapt better to existing infrastructure.

8 years agoBUG/MEDIUM: config: reject anything but "if" or "unless" after a use-backend rule
Willy Tarreau [Tue, 28 Feb 2017 08:34:39 +0000 (09:34 +0100)] 
BUG/MEDIUM: config: reject anything but "if" or "unless" after a use-backend rule

Adrian Fitzpatrick reported that since commit f51658d ("MEDIUM: config:
relax use_backend check to make the condition optional"), typos like "of"
instead of "if" on use_backend rules are not properly detected. The reason
is that the parser only checks for "if" or "unless" otherwise it considers
there's no keyword, making the rule inconditional.

This patch fixes it. It may reveal some rare config bugs for some people,
but will not affect valid configurations.

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

8 years agoBUG/MAJOR: lua segmentation fault when the request is like 'GET ?arg=val HTTP/1.1'
Thierry FOURNIER [Wed, 22 Feb 2017 01:06:16 +0000 (02:06 +0100)] 
BUG/MAJOR: lua segmentation fault when the request is like 'GET ?arg=val HTTP/1.1'

Error in the HTTP parser. The function http_get_path() can
return NULL and this case is not catched in the code. So, we
try to dereference NULL pointer, and a segfault occurs.

These two lines are useful to prevent the bug.

   acl prevent_bug path_beg /
http-request deny if !prevent_bug

This bug fix should be backported in 1.6 and 1.7

8 years agoBUG/MAJOR: ssl: fix a regression in ssl_sock_shutw()
Willy Tarreau [Mon, 13 Feb 2017 10:12:29 +0000 (11:12 +0100)] 
BUG/MAJOR: ssl: fix a regression in ssl_sock_shutw()

Commit 405ff31 ("BUG/MINOR: ssl: assert on SSL_set_shutdown with BoringSSL")
introduced a regression causing some random crashes apparently due to
memory corruption. The issue is the use of SSL_CTX_set_quiet_shutdown()
instead of SSL_set_quiet_shutdown(), making it use a different structure
and causing the flag to be put who-knows-where.

Many thanks to Jarno Huuskonen who reported this bug early and who
bisected the issue to spot this patch. No backport is needed, this
is 1.8-specific.

8 years agoBUG/MINOR: sendmail: The return of vsnprintf is not cleanly tested
Thierry FOURNIER [Thu, 9 Feb 2017 11:19:27 +0000 (12:19 +0100)] 
BUG/MINOR: sendmail: The return of vsnprintf is not cleanly tested

The string formatted by vsnprintf may be bigger than the size of
the buffer "buf". This case is not tested.

This sould be backported to 1.6 and 1.7

8 years agoBUG/MINOR: http: Return an error when a replace-header rule failed on the response
Christopher Faulet [Wed, 8 Feb 2017 11:41:31 +0000 (12:41 +0100)] 
BUG/MINOR: http: Return an error when a replace-header rule failed on the response

Historically, http-response rules couldn't produce errors generating HTTP
responses during their evaluation. This possibility was "implicitly" added with
http-response redirect rules (51d861a4). But, at the time, replace-header rules
were kept untouched. When such a rule failed, the rules processing was just
stopped (like for an accept rule).

Conversely, when a replace-header rule fails on the request, it generates a HTTP
response (400 Bad Request).

With this patch, errors on replace-header rule are now handled in the same way
for HTTP requests and HTTP responses.

This patch should be backported in 1.7 and 1.6.

8 years agoBUG/MEDIUM: http: Prevent replace-header from overwriting a buffer
Christopher Faulet [Wed, 8 Feb 2017 11:17:07 +0000 (12:17 +0100)] 
BUG/MEDIUM: http: Prevent replace-header from overwriting a buffer

This is the same fix as which concerning the redirect rules (0d94576c).

The buffer used to expand the <replace-fmt> argument must be protected to
prevent it being overwritten during build_logline() execution (the function used
to expand the format string).

This patch should be backported in 1.7, 1.6 and 1.5. It relies on commit b686afd
("MINOR: chunks: implement a simple dynamic allocator for trash buffers") for
the trash allocator, which has to be backported as well.

8 years agoBUG/MEDIUM: filters: Do not truncate HTTP response when body length is undefined
Christopher Faulet [Wed, 8 Feb 2017 08:45:13 +0000 (09:45 +0100)] 
BUG/MEDIUM: filters: Do not truncate HTTP response when body length is undefined

Some users have experienced some troubles using the compression filter when the
HTTP response body length is undefined. They complained about receiving
truncated responses.

In fact, the bug can be triggered if there is at least one filter attached to
the stream but none registered to analyze the HTTP response body. In this case,
when the body length is undefined, data should be forwarded without any
parsing. But, because of a wrong check, we were starting to parse them. Because
it was not expected, the end of response was not correctly detected and the
response could be truncted. So now, we rely on HAS_DATA_FILTER macro instead of
HAS_FILTER one to choose to parse HTTP response body or not.

Furthermore, in http_response_forward_body, the test to not forward the server
closure to the client has been updated to reflect conditions listed in the
associated comment.

And finally, in http_msg_forward_body, when the body length is undefined, we
continue the parsing it until the server closes the connection without any on
filters. So filters can safely stop to filter data during their parsing.

This fix should be backported in 1.7

8 years agoBUG/MEDIUM: http: prevent redirect from overwriting a buffer
Thierry FOURNIER [Sat, 28 Jan 2017 06:39:53 +0000 (07:39 +0100)] 
BUG/MEDIUM: http: prevent redirect from overwriting a buffer

See 4b788f7d349ddde3f70f063b7394529eac6ab678

If we use the action "http-request redirect" with a Lua sample-fetch or
converter, and the Lua function calls one of the Lua log function, the
header name is corrupted, it contains an extract of the last loggued data.

This is due to an overwrite of the trash buffer, because his scope is not
respected in the "add-header" function. The scope of the trash buffer must
be limited to the function using it. The build_logline() function can
execute a lot of other function which can use the trash buffer.

This patch fix the usage of the trash buffer. It limits the scope of this
global buffer to the local function, we build first the header value using
build_logline, and after we store the header name.

Thanks Jesse Schulman for the bug repport.

This patch must be backported in 1.7, 1.6 and 1.5 version, and it relies
on commit b686afd ("MINOR: chunks: implement a simple dynamic allocator for
trash buffers") for the trash allocator, which has to be backported as well.

8 years agoMINOR: chunks: implement a simple dynamic allocator for trash buffers
Willy Tarreau [Wed, 8 Feb 2017 10:06:11 +0000 (11:06 +0100)] 
MINOR: chunks: implement a simple dynamic allocator for trash buffers

The trash buffers are becoming increasingly complex to deal with due to
the code's modularity allowing some functions to be chained and causing
the same chunk buffers to be used multiple times along the chain, possibly
corrupting each other. In fact the trash were designed from scratch for
explicitly not surviving a function call but string manipulation makes
this impossible most of the time while not fullfilling the need for
reliable temporary chunks.

Here we introduce the ability to allocate a temporary trash chunk which
is reserved, so that it will not conflict with the trash chunks other
functions use, and will even support reentrant calls (eg: build_logline).

For this, we create a new pool which is exactly the size of a usual chunk
buffer plus the size of the chunk struct so that these chunks when allocated
are exactly the same size as the ones returned by get_trash_buffer(). These
chunks may fail so the caller must check them, and the caller is also
responsible for freeing them.

The code focuses on minimal changes and ease of reliable backporting
because it will be needed in stable versions in order to support next
patch.

8 years agoBUG/MAJOR: dns: restart sockets after fork()
Baptiste Assmann [Thu, 2 Feb 2017 22:14:51 +0000 (23:14 +0100)] 
BUG/MAJOR: dns: restart sockets after fork()

UDP sockets used to send DNS queries are created before fork happens and
this is a big problem because all the processes (in case of a
configuration starting multiple processes) share the same socket. Some
processes may consume responses dedicated to an other one, some servers
may be disabled, some IPs changed, etc...

As a workaround, this patch close the existing socket and create a new
one after the fork() has happened.

[wt: backport this to 1.7]

8 years agoMINOR: dns: give ability to dns_init_resolvers() to close a socket when requested
Baptiste Assmann [Thu, 2 Feb 2017 21:44:15 +0000 (22:44 +0100)] 
MINOR: dns: give ability to dns_init_resolvers() to close a socket when requested

The function dns_init_resolvers() is used to initialize socket used to
send DNS queries.
This patch gives the function the ability to close a socket before
re-opening it.

[wt: this needs to be backported to 1.7 for next fix]

8 years agoBUG/MINOR: lua: Map.end are not reliable because "end" is a reserved keyword
Thierry FOURNIER [Sat, 28 Jan 2017 07:33:08 +0000 (08:33 +0100)] 
BUG/MINOR: lua: Map.end are not reliable because "end" is a reserved keyword

This patch change the names prefixing it by a "_". So "end" becomes "_end".
The backward compatibility with names without the prefix "_" is assured.
In other way, another the keyword "end" can be used like this: Map['end'].

Thanks Robin H. Johnson for the bug repport

This should be backported in version 1.6 and 1.7

8 years agoMINOR: server: extend the flags to 32 bits
Willy Tarreau [Mon, 23 Jan 2017 20:38:57 +0000 (21:38 +0100)] 
MINOR: server: extend the flags to 32 bits

Right now not only we're limited to 8 bits, but it's mentionned nowhere
and the limit was already reached. In addition, pp_opts (proxy protocol
options) were set to 32 bits while only 3 are needed. So let's swap
these two and group them together to avoid leaving two holes in the
structure, saving 64 bits on 64-bit machines.

8 years agoBUG/MINOR: unix: fix connect's polling in case no data are scheduled
Willy Tarreau [Wed, 25 Jan 2017 13:27:38 +0000 (14:27 +0100)] 
BUG/MINOR: unix: fix connect's polling in case no data are scheduled

There's a test after a successful synchronous connect() consisting
in waking the data layer up asap if there's no more handshake.
Unfortunately this test is run before setting the CO_FL_SEND_PROXY
flag and before the transport layer adds its own flags, so it can
indicate a willingness to send data while it's not the case and it
will have to be handled later.

This has no visible effect except a useless call to a function in
case of health checks making use of the proxy protocol for example.

Additionally a corner case where EALREADY was returned and considered
equivalent to EISCONN was fixed so that it's considered equivalent to
EINPROGRESS given that the connection is not complete yet. But this
code should never return on the first call anyway so it's mostly a
cleanup.

This fix should be backported to 1.7 and 1.6 at least to avoid
headaches during some debugging.

8 years agoBUG/MEDIUM: tcp: don't poll for write when connect() succeeds
Willy Tarreau [Wed, 25 Jan 2017 13:12:22 +0000 (14:12 +0100)] 
BUG/MEDIUM: tcp: don't poll for write when connect() succeeds

While testing a tcp_fastopen related change, it appeared that in the rare
case where connect() can immediately succeed, we still subscribe to write
notifications on the socket, causing the conn_fd_handler() to immediately
be called and a second call to connect() to be attempted to double-check
the connection.

In fact this issue had already been met with unix sockets (which often
respond immediately) and partially addressed but incorrect so another
patch will follow. But for TCP nothing was done.

The fix consists in removing the WAIT_L4_CONN flag if connect() succeeds
and to subscribe for writes only if some handshakes or L4_CONN are still
needed. In addition in order not to fail raw TCP health checks, we have
to continue to enable polling for data when nothing is scheduled for
leaving and the connection is already established, otherwise the caller
will never be notified.

This fix should be backported to 1.7 and 1.6.

8 years agoBUILD: ssl: kill a build warning introduced by BoringSSL compatibility
Willy Tarreau [Thu, 19 Jan 2017 16:25:20 +0000 (17:25 +0100)] 
BUILD: ssl: kill a build warning introduced by BoringSSL compatibility

A recent patch to support BoringSSL caused this warning to appear on
OpenSSL 1.1.0 :
   src/ssl_sock.c:3062:4: warning: statement with no effect [-Wunused-value]

It's caused by SSL_CTX_set_ecdh_auto() which is now only a macro testing
that the last argument is zero, and the result is not used here. Let's
just kill it for both versions.

Tested with 0.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0. This fix may be backported
to 1.7 if the boringssl fix is as well.

8 years agoBUILD: ssl: eliminate warning with OpenSSL 1.1.0 regarding RAND_pseudo_bytes()
Willy Tarreau [Thu, 19 Jan 2017 16:10:54 +0000 (17:10 +0100)] 
BUILD: ssl: eliminate warning with OpenSSL 1.1.0 regarding RAND_pseudo_bytes()

This function was deprecated in 1.1.0 causing this warning :

  src/ssl_sock.c:551:3: warning: 'RAND_pseudo_bytes' is deprecated (declared at /opt/openssl-1.1.0/include/openssl/rand.h:47) [-Wdeprecated-declarations]

The man suggests to use RAND_bytes() instead. While the return codes
differ, it turns out that the function was already misused and was
relying on RAND_bytes() return code instead.

The patch was tested on 0.9.8, 1.0.0, 1.0.1, 1.0.2 and 1.1.0.

This fix must be backported to 1.7 and the return code check should
be backported to earlier versions if relevant.

8 years agoBUILD: ssl: silence a warning reported for ERR_remove_state()
Willy Tarreau [Thu, 19 Jan 2017 15:50:25 +0000 (16:50 +0100)] 
BUILD: ssl: silence a warning reported for ERR_remove_state()

In 1.0.0, this function was replaced with ERR_remove_thread_state().
As of openssl 1.1.0, both are now deprecated and do nothing at all.
Thus we simply make this call do nothing in 1.1.0 to silence the
warning.

The change was tested with 0.9.8, 1.0.0, 1.0.1, 1.0.2 and 1.1.0.

This kills the following warning on 1.1.0 :
   src/ssl_sock.c:7266:9: warning: 'ERR_remove_state' is deprecated (declared at /dev/shm/openssl-1.1.0b/include/openssl/err.h:247) [-Wdeprecated-declarations]

This fix should be backported to 1.7.

8 years agoBUILD: ssl: fix build on OpenSSL 1.0.0
Willy Tarreau [Thu, 19 Jan 2017 16:04:02 +0000 (17:04 +0100)] 
BUILD: ssl: fix build on OpenSSL 1.0.0

After the code was ported to support 1.1.0, this one broke on 1.0.0 :

  src/shctx.c:406: undefined reference to `SSL_SESSION_set1_id_context'

The function was indeed introduced only in 1.0.1. The build was validated
with 0.9.8, 1.0.0, 1.0.1, 1.0.2 and 1.1.0.

This fix must be backported to 1.7.

8 years agoBUILD: ssl: fix to build (again) with boringssl
Emmanuel Hocdet [Fri, 13 Jan 2017 16:48:18 +0000 (17:48 +0100)] 
BUILD: ssl: fix to build (again) with boringssl

Limitations:
. disable force-ssl/tls (need more work)
should be set earlier with SSL_CTX_new (SSL_CTX_set_ssl_version is removed)
. disable generate-certificates (need more work)
introduce SSL_NO_GENERATE_CERTIFICATES to disable generate-certificates.

Cleanup some #ifdef and type related to boringssl env.

8 years agoMINOR: doc: Add docs for agent-addr and agent-send CLI commands
Misiek [Mon, 9 Jan 2017 08:53:06 +0000 (09:53 +0100)] 
MINOR: doc: Add docs for agent-addr and agent-send CLI commands

8 years agoMINOR: doc: Add docs for agent-addr configuration variable
Misiek [Mon, 9 Jan 2017 08:52:43 +0000 (09:52 +0100)] 
MINOR: doc: Add docs for agent-addr configuration variable

8 years agoMINOR: cli: Add possiblity to change agent config via CLI/socket
Misiek [Mon, 9 Jan 2017 08:40:42 +0000 (09:40 +0100)] 
MINOR: cli: Add possiblity to change agent config via CLI/socket

This change adds possibility to change agent-addr and agent-send directives
by CLI/socket. Now you can replace server's and their configuration without
reloading/restarting whole haproxy, so it's a step in no-reload/no-restart
direction.

Depends on #e9602af - agent-addr is implemented there.

Can be backported to 1.7.

8 years agoMINOR: checks: Add agent-addr config directive
Misiek [Mon, 9 Jan 2017 08:39:51 +0000 (09:39 +0100)] 
MINOR: checks: Add agent-addr config directive

This directive add possibility to set different address for agent-checks.
With this you can manage server status and weight from central place.

Can be backported to 1.7.

8 years agoMINOR: ssl: add curve suite for ECDHE negotiation
Emmanuel Hocdet [Mon, 9 Jan 2017 15:15:54 +0000 (16:15 +0100)] 
MINOR: ssl: add curve suite for ECDHE negotiation

Add 'curves' parameter on 'bind' and for 'crt-list' to set curve suite.
(ex: curves X25519:P-256)

8 years agoMAJOR: ssl: bind configuration per certificat
Emmanuel Hocdet [Thu, 29 Dec 2016 17:26:15 +0000 (18:26 +0100)] 
MAJOR: ssl: bind configuration per certificat

crt-list is extend to support ssl configuration. You can now have
such line in crt-list <file>:
mycert.pem [npn h2,http/1.1]

Support include "npn", "alpn", "verify", "ca_file", "crl_file",
"ecdhe", "ciphers" configuration and ssl options.

"crt-base" is also supported to fetch certificates.

8 years agoBUG/MINOR: stream: Fix how backend-specific analyzers are set on a stream
Christopher Faulet [Mon, 9 Jan 2017 15:33:19 +0000 (16:33 +0100)] 
BUG/MINOR: stream: Fix how backend-specific analyzers are set on a stream

When the stream's backend was defined, the request's analyzers flag was always
set to 0 if the stream had no listener. This bug was introduced with the filter
API but never triggered (I think so).

Because of the commit 5820a366, it is now possible to encountered it. For
example, this happens when the trace filter is enabled on a SPOE backend. The
fix is pretty trivial.

This fix must be backported to 1.7.

8 years agoOPTIM/MINOR: config: Optimize fullconn automatic computation loading configuration
Emeric Brun [Thu, 12 Jan 2017 10:21:28 +0000 (11:21 +0100)] 
OPTIM/MINOR: config: Optimize fullconn automatic computation loading configuration

The previous version used an O(number of proxies)^2 algo to get the sum of
the number of maxconns of frontends which reference a backend at least once.

This new version adds the frontend's maxconn number to the backend's
struct proxy member 'tot_fe_maxconn' when the backend name is resolved
for switching rules or default_backend statment.  At the end, the final
backend's fullconn is computed looping only one time for all on proxies O(n).

The load of a configuration using a large amount of backends (10 thousands)
without configured fullconn was reduced from several minutes to few seconds.

8 years agoMINOR: ssl: don't show prefer-server-ciphers output
Lukas Tribus [Wed, 11 Jan 2017 22:47:18 +0000 (22:47 +0000)] 
MINOR: ssl: don't show prefer-server-ciphers output

The output of whether prefer-server-ciphers is supported by OpenSSL
actually always show yes in 1.8, because SSL_OP_CIPHER_SERVER_PREFERENCE
is redefined before the actual check in src/ssl_sock.c, since it was
moved from here from src/haproxy.c.

Since this is not really relevant anymore as we don't support OpenSSL
< 0.9.7 anyway, this change just removes this output.

8 years agoBUG/MINOR: Reset errno variable before calling strtol(3)
Ryabin Sergey [Wed, 11 Jan 2017 15:39:55 +0000 (19:39 +0400)] 
BUG/MINOR: Reset errno variable before calling strtol(3)

Sometimes errno != 0 before calling strtol(3)

[wt: this needs to be backported to 1.7]

8 years agoMINOR: compression: fix -vv output without zlib/slz
Lukas Tribus [Wed, 11 Jan 2017 14:24:35 +0000 (14:24 +0000)] 
MINOR: compression: fix -vv output without zlib/slz

When haproxy is compiled without zlib or slz, the output of
haproxy -vv shows (null).

Make haproxy -vv output great again by providing the proper
information (which is what we did before).

This is for 1.8 only.

8 years agoDOC: add deprecation notice to "block"
Jarno Huuskonen [Wed, 28 Dec 2016 16:50:29 +0000 (18:50 +0200)] 
DOC: add deprecation notice to "block"

[wt: this one is in fact emulated using http-request deny. This
 patch can thus be backported to 1.7, 1.6 and 1.5 so that users
 of older versions do not add this keyword in their configs]

8 years agoMINOR: proto_http.c 502 error txt typo.
Jarno Huuskonen [Wed, 28 Dec 2016 08:49:01 +0000 (10:49 +0200)] 
MINOR: proto_http.c 502 error txt typo.

[wt: should be backported to 1.7 and 1.6 as it was introduced in 1.6-dev4]

8 years agoMINOR: Use "500 Internal Server Error" for 500 error/status code message.
Jarno Huuskonen [Mon, 9 Jan 2017 12:17:10 +0000 (14:17 +0200)] 
MINOR: Use "500 Internal Server Error" for 500 error/status code message.

Internal Server Error is what is in RFC 2616/7231.

8 years agoBUG/MINOR: ssl: assert on SSL_set_shutdown with BoringSSL
Emmanuel Hocdet [Sun, 8 Jan 2017 13:07:39 +0000 (14:07 +0100)] 
BUG/MINOR: ssl: assert on SSL_set_shutdown with BoringSSL

With BoringSSL:
SSL_set_shutdown: Assertion `(SSL_get_shutdown(ssl) & mode) == SSL_get_shutdown(ssl)' failed.

"SSL_set_shutdown causes ssl to behave as if the shutdown bitmask (see SSL_get_shutdown)
were mode. This may be used to skip sending or receiving close_notify in SSL_shutdown by
causing the implementation to believe the events already happened.
It is an error to use SSL_set_shutdown to unset a bit that has already been set.
Doing so will trigger an assert in debug builds and otherwise be ignored.
Use SSL_CTX_set_quiet_shutdown instead."

Change logic to not notify on SSL_shutdown when connection is not clean.

8 years agoBUG/MINOR: ssl: EVP_PKEY must be freed after X509_get_pubkey usage
Emmanuel Hocdet [Fri, 6 Jan 2017 11:57:46 +0000 (12:57 +0100)] 
BUG/MINOR: ssl: EVP_PKEY must be freed after X509_get_pubkey usage

"X509_get_pubkey() attempts to decode the public key for certificate x.
If successful it returns the public key as an EVP_PKEY pointer with its
reference count incremented: this means the returned key must be freed
up after use."

8 years agoBUG/MEDIUM: tools: do not force an unresolved address to AF_INET:0.0.0.0
Willy Tarreau [Fri, 6 Jan 2017 18:23:20 +0000 (19:23 +0100)] 
BUG/MEDIUM: tools: do not force an unresolved address to AF_INET:0.0.0.0

This prevents DNS from resolving IPv6-only servers in 1.7. Note, this
patch depends on the previous series :

  1. BUG/MINOR: tools: fix off-by-one in port size check
  2. BUG/MEDIUM: server: consider AF_UNSPEC as a valid address family
  3. MEDIUM: server: split the address and the port into two different fields
  4. MINOR: tools: make str2sa_range() return the port in a separate argument
  5. MINOR: server: take the destination port from the port field, not the addr
  6. MEDIUM: server: disable protocol validations when the server doesn't resolve

This fix (hence the whole series) must be backported to 1.7.

8 years agoMEDIUM: server: disable protocol validations when the server doesn't resolve
Willy Tarreau [Fri, 6 Jan 2017 17:42:57 +0000 (18:42 +0100)] 
MEDIUM: server: disable protocol validations when the server doesn't resolve

When a server doesn't resolve we don't know the address family so we
can't perform the basic protocol validations. However we know that we'll
ultimately resolve to AF_INET4 or AF_INET6 so the controls are OK. It is
important to proceed like this otherwise it will not be possible to start
with unresolved addresses.

8 years agoMINOR: server: take the destination port from the port field, not the addr
Willy Tarreau [Fri, 6 Jan 2017 17:36:06 +0000 (18:36 +0100)] 
MINOR: server: take the destination port from the port field, not the addr

Next patch will cause the port to disappear from the address field when servers
do not resolve so we need to take it from the separate field provided by
str2sa_range().

8 years agoMINOR: tools: make str2sa_range() return the port in a separate argument
Willy Tarreau [Fri, 6 Jan 2017 17:32:38 +0000 (18:32 +0100)] 
MINOR: tools: make str2sa_range() return the port in a separate argument

This will be needed so that we're don't have to extract it from the
returned address where it will not always be anymore (eg: for unresolved
servers).

8 years agoMEDIUM: server: split the address and the port into two different fields
Willy Tarreau [Fri, 6 Jan 2017 16:41:29 +0000 (17:41 +0100)] 
MEDIUM: server: split the address and the port into two different fields

Keeping the address and the port in the same field causes a lot of problems,
specifically on the DNS part where we're forced to cheat on the family to be
able to keep the port. This causes some issues such as some families not being
resolvable anymore.

This patch first moves the service port to a new field "svc_port" so that the
port field is never used anymore in the "addr" field (struct sockaddr_storage).
All call places were adapted (there aren't that many).

8 years agoBUG/MEDIUM: server: consider AF_UNSPEC as a valid address family
Willy Tarreau [Fri, 6 Jan 2017 18:18:32 +0000 (19:18 +0100)] 
BUG/MEDIUM: server: consider AF_UNSPEC as a valid address family

The DNS code is written so as to support AF_UNSPEC to decide on the
server family based on responses, but unfortunately snr_resolution_cb()
considers it as invalid causing a DNS storm to happen when a server
arrives with this family.

This situation is not supposed to happen as long as unresolved addresses
are forced to AF_INET, but this will change with the upcoming fixes and
it's possible that it's not granted already when changing an address on
the CLI.

This fix must be backported to 1.7 and 1.6.

8 years agoBUG/MINOR: tools: fix off-by-one in port size check
Willy Tarreau [Fri, 6 Jan 2017 15:46:22 +0000 (16:46 +0100)] 
BUG/MINOR: tools: fix off-by-one in port size check

port_to_str() checks that the port size is at least 5 characters instead
of at least 6. While in theory it could permit a buffer overflow, it's
harmless because all callers have at least 6 characters here.

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

8 years agoBUG/MINOR: config: emit a warning if http-reuse is enabled with incompatible options
Willy Tarreau [Fri, 6 Jan 2017 11:21:38 +0000 (12:21 +0100)] 
BUG/MINOR: config: emit a warning if http-reuse is enabled with incompatible options

http-reuse should normally not be used in conjunction with the proxy
protocol or with "usesrc clientip". While there's nothing fundamentally
wrong with this, whenever these options are used, the server expects the
IP address to be the source address for all requests, which doesn't make
sense with http-reuse.

8 years agoMINOR: connection: add sample fetch "fc_rcvd_proxy"
Emeric Brun [Thu, 5 Jan 2017 14:11:44 +0000 (15:11 +0100)] 
MINOR: connection: add sample fetch "fc_rcvd_proxy"

fc_rcvd_proxy : boolean
  Returns true if the client initiated the connection with a PROXY protocol
  header.

A flag is added on the struct connection if a PROXY header is successfully
parsed.

8 years agoMINOR: http: custom status reason.
Robin H. Johnson [Sun, 1 Jan 2017 21:10:52 +0000 (13:10 -0800)] 
MINOR: http: custom status reason.

The older 'rsprep' directive allows modification of the status reason.

Extend 'http-response set-status' to take an optional string of the new
status reason.

  http-response set-status 418 reason "I'm a coffeepot"

Matching updates in Lua code:
- AppletHTTP.set_status
- HTTP.res_set_status

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
8 years agoBUG/MAJOR: http: fix risk of getting invalid reports of bad requests
Willy Tarreau [Wed, 4 Jan 2017 13:44:46 +0000 (14:44 +0100)] 
BUG/MAJOR: http: fix risk of getting invalid reports of bad requests

Commits 5f10ea3 ("OPTIM: http: improve parsing performance of long
URIs") and 0431f9d ("OPTIM: http: improve parsing performance of long
header lines") introduced a bug in the HTTP parser : when a partial
request is read, the first part ends up on a 8-bytes boundary (or 4-byte
on 32-bit machines), the end lies in the header field value part, and
the buffer used to contain a CR character exactly after the last block,
then the parser could be confused and read this CR character as being
part of the current request, then switch to a new state waiting for an
LF character. Then when the next part of the request appeared, it would
read the character following what was erroneously mistaken for a CR,
see that it is not an LF and fail on a bad request. In some cases, it
can even be worse and the header following the hole can be improperly
indexed causing all sort of unexpected behaviours like a content-length
being ignored or a header appended at the wrong position. The reason is
that there's no control of and of parsing just after breaking out of the
loop.

One way to reproduce it is with this config :

  global
      stats socket /tmp/sock1 mode 666 level admin
      stats timeout 1d

  frontend  px
      bind :8001
      mode http
      timeout client 10s
      redirect location /

And sending requests this way :

  $ tcploop 8001 C P S:"$(dd if=/dev/zero bs=16384 count=1 2>/dev/null | tr '\000' '\r')"
  $ tcploop 8001 C P S:"$(dd if=/dev/zero bs=16384 count=1 2>/dev/null | tr '\000' '\r')"
  $ tcploop 8001 C P \
    S:"GET / HTTP/1.0\r\nX-padding: 0123456789.123456789.123456789.123456789.123456789.123456789.1234567" P \
    S:"89.123456789\r\n\r\n" P

Then a "show errors" on the socket will report :

  $ echo "show errors" | socat - /tmp/sock1
  Total events captured on [04/Jan/2017:15:09:15.755] : 32

  [04/Jan/2017:15:09:13.050] frontend px (#2): invalid request
    backend <NONE> (#-1), server <NONE> (#-1), event #31
    src 127.0.0.1:59716, session #91, session flags 0x00000080
    HTTP msg state 17, msg flags 0x00000000, tx flags 0x00000000
    HTTP chunk len 0 bytes, HTTP body len 0 bytes
    buffer flags 0x00808002, out 0 bytes, total 111 bytes
    pending 111 bytes, wrapping at 16384, error at position 107:

    00000  GET / HTTP/1.0\r\n
    00016  X-padding: 0123456789.123456789.123456789.123456789.123456789.12345678
    00086+ 9.123456789.123456789\r\n
    00109  \r\n

This fix must be backported to 1.7.

Many thanks to Aleksey Gordeev and Axel Reinhold for providing detailed
network captures and configurations exhibiting the issue.

8 years agoMINOR: tools: add a generic hexdump function for debugging
Willy Tarreau [Sun, 4 Dec 2016 23:10:57 +0000 (00:10 +0100)] 
MINOR: tools: add a generic hexdump function for debugging

debug_hexdump() prints to the requested output stream (typically stdout
or stderr) an hex dump of the blob passed in argument. This is useful
to help debug binary protocols.

8 years agoBUILD: scripts: automatically update the branch in version.h when releasing
Willy Tarreau [Thu, 5 Jan 2017 18:58:24 +0000 (19:58 +0100)] 
BUILD: scripts: automatically update the branch in version.h when releasing

The stats page proudly displays "Updates (v1.5)". This version is inherited
from version.h which has not been updated since 1.5, so let's teach the
create-release script about it.

This must be backported to 1.7. 1.6 now uses the same script (externally)
for the release and will automatically benefit from it.

8 years agoBUG/MINOR: http: report real parser state in error captures
Willy Tarreau [Wed, 4 Jan 2017 13:51:22 +0000 (14:51 +0100)] 
BUG/MINOR: http: report real parser state in error captures

Error captures almost always report a state 26 (MSG_ERROR) making it
very hard to know what the parser was expecting. The reason is that
we have to switch to MSG_ERROR to trigger the dump, and then during
the dump we capture the current state which is already MSG_ERROR. With
this change we now copy the current state into an err_state field that
will be reported as the faulty state.

This patch looks a bit large because the parser doesn't update the
current state until it runs out of data so the current state is never
known when jumping to ther error label! Thus the code had to be updated
to take copies of the current state before switching to MSG_ERROR based
on the switch/case values.

As a bonus, it now shows the current state in human-readable form and
not only in numeric form ; in the past it was not an issue since it was
always 26 (MSG_ERROR).

At least now we can get exploitable invalid request/response reports :

  [05/Jan/2017:19:28:57.095] frontend f (#2): invalid request
    backend <NONE> (#-1), server <NONE> (#-1), event #1
    src 127.0.0.1:39894, session #4, session flags 0x00000080
    HTTP msg state MSG_RQURI(4), msg flags 0x00000000, tx flags 0x00000000
    HTTP chunk len 0 bytes, HTTP body len 0 bytes
    buffer flags 0x00908002, out 0 bytes, total 20 bytes
    pending 20 bytes, wrapping at 16384, error at position 5:

    00000  GET /\e HTTP/1.0\r\n
    00017  \r\n
    00019  \n

  [05/Jan/2017:19:28:33.827] backend b (#3): invalid response
    frontend f (#2), server s1 (#1), event #0
    src 127.0.0.1:39718, session #0, session flags 0x000004ce
    HTTP msg state MSG_HDR_NAME(17), msg flags 0x00000000, tx flags 0x08300000
    HTTP chunk len 0 bytes, HTTP body len 0 bytes
    buffer flags 0x80008002, out 0 bytes, total 59 bytes
    pending 59 bytes, wrapping at 16384, error at position 31:

    00000  HTTP/1.1 200 OK\r\n
    00017  Content-length : 10\r\n
    00038  \r\n
    00040  0a\r\n
    00044  0123456789\r\n
    00056  0\r\n

This should be backported to 1.7 and 1.6 at least to help with bug
reports.

8 years agoBUG/MAJOR: channel: Fix the definition order of channel analyzers
Christopher Faulet [Thu, 5 Jan 2017 13:06:34 +0000 (14:06 +0100)] 
BUG/MAJOR: channel: Fix the definition order of channel analyzers

It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.

With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.

So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.

Some other analyzers have been reordered to respect the evaluation order:

  * AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
  * AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
  * AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP

Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.

[wt: all of this must be backported to 1.7, and part of it must be backported
 to 1.6 and 1.5]

8 years agoBUG/MINOR: sample-fetches/stick-tables: bad type for the sample fetches sc*_get_gpt0
Thierry FOURNIER [Thu, 5 Jan 2017 10:44:09 +0000 (11:44 +0100)] 
BUG/MINOR: sample-fetches/stick-tables: bad type for the sample fetches sc*_get_gpt0

The registered output type for the sample fetches sc*_get_gpt0
is a boolean, but the value returned is an integer.

This patch fixs the default type to SINT in place of BOOL.

This patch should be backported in 1.6 and 1.7

8 years agoMINOR: stats: Support "select all" for backend actions
David Harrigan [Fri, 30 Dec 2016 12:12:49 +0000 (12:12 +0000)] 
MINOR: stats: Support "select all" for backend actions

Allow the user to quickly select all servers within a group before invoking an
action.

8 years agoBUG/MINOR: option prefer-last-server must be ignored in some case
Olivier Doucet [Mon, 2 Jan 2017 10:48:57 +0000 (11:48 +0100)] 
BUG/MINOR: option prefer-last-server must be ignored in some case

when using "option prefer-last-server", we may not always stay on
the same backend if option balance told us otherwise.
For example, backend may change in the following cases:
balance hdr()
balance rdp-cookie
balance source
balance uri
balance url_param

[wt: backport this to 1.7 and 1.6]

8 years agoMEDIUM: regex: pcre2 support
David Carlier [Mon, 21 Nov 2016 21:25:58 +0000 (21:25 +0000)] 
MEDIUM: regex: pcre2 support

this adds a support of the newest pcre2 library,
more secure than its older sibling in a cost of a
more complex API.
It works pretty similarly to pcre's part to keep
the overall change smooth,  except :

- we define the string class supported at compile time.
- after matching the ovec data is properly sized, althought
we do not take advantage of it here.
- the lack of jit support is treated less 'dramatically'
as pcre2_jit_compile in this case is 'no-op'.

8 years agoMINOR: samples: add xx-hash functions
Thierry FOURNIER [Mon, 26 Dec 2016 10:46:11 +0000 (11:46 +0100)] 
MINOR: samples: add xx-hash functions

This patch adds the support of xx-hash 32 and 64-bits functions.

8 years agoBUILD: lua: build failed on FreeBSD.
Thierry FOURNIER [Fri, 23 Dec 2016 16:03:25 +0000 (17:03 +0100)] 
BUILD: lua: build failed on FreeBSD.

s6_addr* fields are not available in the userland on
BSD systems in general.

bug reported by David Carlier

needs backport to 1.7.x

8 years agoDOC: Add timings events schemas
Guillaume de Lafond [Fri, 23 Dec 2016 16:32:43 +0000 (17:32 +0100)] 
DOC: Add timings events schemas

[wt: this could be backported to 1.7]

8 years agoBUG/MINOR: systemd: potential zombie processes
William Lallemand [Fri, 23 Dec 2016 14:44:15 +0000 (15:44 +0100)] 
BUG/MINOR: systemd: potential zombie processes

In systemd mode (-Ds), the master haproxy process is waiting for each
child to exit in a specific order. If a process die when it's not his
turn, it will become a zombie process until every processes exit.

The master is now waiting for any process to exit in any order.

This patch should be backported to 1.7, 1.6 and 1.5.

8 years agoBUG/MEDIUM: ssl: for a handshake when server-side SNI changes
Willy Tarreau [Thu, 22 Dec 2016 20:58:38 +0000 (21:58 +0100)] 
BUG/MEDIUM: ssl: for a handshake when server-side SNI changes

Calling SSL_set_tlsext_host_name() on the current SSL ctx has no effect
if the session is being resumed because the hostname is already stored
in the session and is not advertised again in subsequent connections.
It's visible when enabling SNI and health checks at the same time because
checks do not send an SNI and regular traffic reuses the same connection,
resulting in no SNI being sent.

The only short-term solution is to reset the reused session when the
SNI changes compared to the previous one. It can make the server-side
performance suffer when SNIs are interleaved but it will work. A better
long-term solution would be to keep a small cache of a few contexts for
a few SNIs.

Now with SSL_set_session(ctx, NULL) it works. This needs to be double-
checked though. The man says that SSL_set_session() frees any previously
existing context. Some people report a bit of breakage when calling
SSL_set_session(NULL) on openssl 1.1.0a (freed session not reusable at
all though it's not an issue for now).

This needs to be backported to 1.7 and 1.6.

8 years agoBUG/MINOR: backend: nbsrv() should return 0 if backend is disabled
Marcin Deranek [Thu, 22 Dec 2016 15:21:08 +0000 (16:21 +0100)] 
BUG/MINOR: backend: nbsrv() should return 0 if backend is disabled

According to nbsrv() documentation this fetcher should return "an
integer value corresponding to the number of usable servers".
In case backend is disabled none of servers is usable, so I believe
fetcher should return 0.

This patch should be backported to 1.7, 1.6, 1.5.

8 years agoCLEANUP: ssl: move most ssl-specific global settings to ssl_sock.c
Willy Tarreau [Thu, 22 Dec 2016 22:12:01 +0000 (23:12 +0100)] 
CLEANUP: ssl: move most ssl-specific global settings to ssl_sock.c

Historically a lot of SSL global settings were stored into the global
struct, but we've reached a point where there are 3 ifdefs in it just
for this, and others in haproxy.c to initialize it.

This patch moves all the private fields to a new struct "global_ssl"
stored in ssl_sock.c. This includes :

       char *crt_base;
       char *ca_base;
       char *listen_default_ciphers;
       char *connect_default_ciphers;
       int listen_default_ssloptions;
       int connect_default_ssloptions;
       int tune.sslprivatecache; /* Force to use a private session cache even if nbproc > 1 */
       unsigned int tune.ssllifetime;   /* SSL session lifetime in seconds */
       unsigned int tune.ssl_max_record; /* SSL max record size */
       unsigned int tune.ssl_default_dh_param; /* SSL maximum DH parameter size */
       int tune.ssl_ctx_cache; /* max number of entries in the ssl_ctx cache. */

The "tune" part was removed (useless here) and the occasional "ssl"
prefixes were removed as well. Thus for example instead of

       global.tune.ssl_default_dh_param

we now have :

       global_ssl.default_dh_param

A few initializers were present in the constructor, they could be brought
back to the structure declaration.

A few other entries had to stay in global for now. They concern memory
calculationn (used in haproxy.c) and stats (used in stats.c).

The code is already much cleaner now, especially for global.h and haproxy.c
which become readable.

8 years agoCLEANUP: ssl: move tlskeys_finalize_config() to a post_check callback
Willy Tarreau [Thu, 22 Dec 2016 21:46:15 +0000 (22:46 +0100)] 
CLEANUP: ssl: move tlskeys_finalize_config() to a post_check callback

tlskeys_finalize_config() was the only reason for haproxy.c to still
require ifdef and includes for ssl_sock. This one fits perfectly well
in the late initializers so it was changed to be registered with
hap_register_post_check().

8 years agoMINOR: ssl_sock: implement and use prepare_srv()/destroy_srv()
Willy Tarreau [Thu, 22 Dec 2016 20:16:08 +0000 (21:16 +0100)] 
MINOR: ssl_sock: implement and use prepare_srv()/destroy_srv()

Now we can simply check the transport layer at run time and decide
whether or not to initialize or destroy these entries. This removes
other ifdefs and includes from cfgparse.c, haproxy.c and hlua.c.

8 years agoMINOR: connection: add new prepare_srv()/destroy_srv() entries to xprt_ops
Willy Tarreau [Thu, 22 Dec 2016 20:13:18 +0000 (21:13 +0100)] 
MINOR: connection: add new prepare_srv()/destroy_srv() entries to xprt_ops

These one will be used by the SSL layer to prepare and destroy a server-side
SSL context.

8 years agoCLEANUP: connection: unexport raw_sock and ssl_sock
Willy Tarreau [Thu, 22 Dec 2016 20:08:52 +0000 (21:08 +0100)] 
CLEANUP: connection: unexport raw_sock and ssl_sock

This way we're sure not to reuse them by accident.

8 years agoCLEANUP: connection: remove all direct references to raw_sock and ssl_sock
Willy Tarreau [Thu, 22 Dec 2016 19:44:00 +0000 (20:44 +0100)] 
CLEANUP: connection: remove all direct references to raw_sock and ssl_sock

Now we exclusively use xprt_get(XPRT_RAW) instead of &raw_sock or
xprt_get(XPRT_SSL) for &ssl_sock. This removes a bunch of #ifdef and
include spread over a number of location including backend, cfgparse,
checks, cli, hlua, log, server and session.

8 years agoMINOR: connection: add a minimal transport layer registration system
Willy Tarreau [Thu, 22 Dec 2016 19:25:26 +0000 (20:25 +0100)] 
MINOR: connection: add a minimal transport layer registration system

There are still a lot of #ifdef USE_OPENSSL in the code (still 43
occurences) because we never know if we can directly access ssl_sock
or not. This patch attacks the problem differently by providing a
way for transport layers to register themselves and for users to
retrieve the pointer. Unregistered transport layers will point to NULL
so it will be easy to check if SSL is registered or not. The mechanism
is very inexpensive as it relies on a two-entries array of pointers,
so the performance will not be affected.

8 years agoMINOR: server: move the use_ssl field out of the ifdef USE_OPENSSL
Willy Tarreau [Thu, 22 Dec 2016 17:38:00 +0000 (18:38 +0100)] 
MINOR: server: move the use_ssl field out of the ifdef USE_OPENSSL

Having it in the ifdef complicates certain operations which require
additional ifdefs just to access a member which could remain zero in
non-ssl cases. Let's move it out, it will not even increase the
struct size on 64-bit machines due to alignment.

8 years agoMINOR: ssl_sock: implement ssl_sock_destroy_bind_conf()
Willy Tarreau [Thu, 22 Dec 2016 16:30:54 +0000 (17:30 +0100)] 
MINOR: ssl_sock: implement ssl_sock_destroy_bind_conf()

Instead of hard-coding all SSL destruction in cfgparse.c and haproxy.c,
we now register this new function as the transport layer's destroy_bind_conf()
and call it only when defined. This removes some non-obvious SSL-specific
code and #ifdefs from cfgparse.c and haproxy.c

8 years agoMINOR: connection: add a new destroy_bind_conf() entry to xprt_ops
Willy Tarreau [Thu, 22 Dec 2016 16:30:20 +0000 (17:30 +0100)] 
MINOR: connection: add a new destroy_bind_conf() entry to xprt_ops

This one will be set by the transport layers which want to destroy
a bind_conf. It will typically be used by SSL to release certificates,
CAs and so on.

8 years agoMEDIUM: ssl_sock: implement ssl_sock_prepare_bind_conf()
Willy Tarreau [Wed, 21 Dec 2016 22:38:39 +0000 (23:38 +0100)] 
MEDIUM: ssl_sock: implement ssl_sock_prepare_bind_conf()

Instead of hard-coding all SSL preparation in cfgparse.c, we now register
this new function as the transport layer's prepare_bind_conf() and call it
only when definied. This removes some non-obvious SSL-specific code from
cfgparse.c as well as a #ifdef.

8 years agoMINOR: connection: add a new prepare_bind_conf() entry to xprt_ops
Willy Tarreau [Thu, 22 Dec 2016 16:19:24 +0000 (17:19 +0100)] 
MINOR: connection: add a new prepare_bind_conf() entry to xprt_ops

This one will be set by the transport layers which want to initialize
a bind_conf. It will typically be used by SSL to load certificates, CAs
and so on.

8 years agoMEDIUM: ssl: remote the proxy argument from most functions
Willy Tarreau [Thu, 22 Dec 2016 16:08:28 +0000 (17:08 +0100)] 
MEDIUM: ssl: remote the proxy argument from most functions

Most of the SSL functions used to have a proxy argument which was mostly
used to be able to emit clean errors using Alert(). First, many of them
were converted to memprintf() and don't require this pointer anymore.
Second, the rare which still need it also have either a bind_conf argument
or a server argument, both of which carry a pointer to the relevant proxy.

So let's now get rid of it, it needlessly complicates the API and certain
functions already have many arguments.

8 years agoMEDIUM: move listener->frontend to bind_conf->frontend
Willy Tarreau [Wed, 21 Dec 2016 23:13:31 +0000 (00:13 +0100)] 
MEDIUM: move listener->frontend to bind_conf->frontend

Historically, all listeners have a pointer to the frontend. But since
the introduction of SSL, we now have an intermediary layer called
bind_conf corresponding to a "bind" line. It makes no sense to have
the frontend on each listener given that it's the same for all
listeners belonging to a same bind_conf. Also certain parts like
SSL can only operate on bind_conf and need the frontend.

This patch fixes this by moving the frontend pointer from the listener
to the bind_conf. The extra indirection is quite cheap given and the
places were this is used are very scarce.

8 years agoMINOR: listener: move the transport layer pointer to the bind_conf
Willy Tarreau [Wed, 21 Dec 2016 21:04:54 +0000 (22:04 +0100)] 
MINOR: listener: move the transport layer pointer to the bind_conf

A mistake was made when the socket layer was cut into proto and
transport, the transport was attached to the listener while all
listeners in a single "bind" line always have exactly the same
transport. It doesn't seem obvious but this is the reason why there
are so many #ifdefs USE_OPENSSL in cfgparse : a lot of operations
have to be open-coded because cfgparse only manipulates bind_conf
and we don't have the information of the transport layer here.

Very little code makes use of the transport layer, mainly session
setup and log. These places can afford an extra pointer indirection
(the listener points to the bind_conf). This change is thus very small,
it saves a little bit of memory (8B per listener) and makes the code
more flexible.