]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
7 years agoMINOR: http: Switch requests/responses in TUNNEL mode only by checking txn flags
Christopher Faulet [Tue, 18 Jul 2017 08:48:24 +0000 (10:48 +0200)] 
MINOR: http: Switch requests/responses in TUNNEL mode only by checking txn flags

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

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

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

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

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

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

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

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

This patch must be backported in 1.7.

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

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

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

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

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

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

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

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

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

This patch must be backported in 1.6 and 1.7

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

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

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

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

This patch should be backported in 1.6 and 1.7

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

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

This patch should be backported in 1.6 and 1.7

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

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

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

This patch should be backported in 1.6 and 1.7

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

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

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

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

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

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

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

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

Must be backported to 1.6 and 1.7.

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

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

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

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

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

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

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

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

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

May be backported to 1.7 and 1.6.

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

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

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

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

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

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

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

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

This patch must be backported in 1.7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

i.e.

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

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

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

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

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

Time format is documented in section 2.4, not 2.2.

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

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

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

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

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

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

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

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

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

This patch must be backported in 1.7.

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

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

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

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

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

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

This patch wont directly apply on 1.6.

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

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

This patch should be backported on mainline branches 1.7 and 1.6

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

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

No backport needed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

8 years agoMINOR: backends: Change get_server_sh/get_server_uh into private function
Christopher Faulet [Fri, 9 Jun 2017 12:20:29 +0000 (14:20 +0200)] 
MINOR: backends: Change get_server_sh/get_server_uh into private function

8 years agoMINOR: queue: Change pendconn_get_next_strm into private function
Christopher Faulet [Tue, 6 Jun 2017 08:34:51 +0000 (10:34 +0200)] 
MINOR: queue: Change pendconn_get_next_strm into private function

8 years agoMINOR: task/stream: tasks related to a stream must be init by the caller.
Emeric Brun [Mon, 29 May 2017 13:26:51 +0000 (15:26 +0200)] 
MINOR: task/stream: tasks related to a stream must be init by the caller.

The task_wakeup was called on stream_new, but the task/stream
wasn't fully initialized yet. The task_wakeup must be called
explicitly by the caller once the task/stream is initialized.

8 years agoMAJOR: task: task scheduler rework.
Emeric Brun [Thu, 30 Mar 2017 13:37:25 +0000 (15:37 +0200)] 
MAJOR: task: task scheduler rework.

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

The lookups on runqueue and waitqueue are re-worked
to prepare multithread stuff.

If task_wakeup is called on a running task, the woken
message flags are savec in the 'pending_state' attribute of
the state. The real wakeup is postponed at the end of the handler
process and the woken messages are copied from pending_state
to the state attribute of the task.

It's important to note that this change will cause a very minor
(though measurable) performance loss but it is necessary to make
forward progress on a multi-threaded scheduler. Most users won't
ever notice.

8 years agoBUG/MINOR: stream: flag TASK_WOKEN_RES not set if task in runqueue
Emeric Brun [Fri, 31 Mar 2017 10:04:09 +0000 (12:04 +0200)] 
BUG/MINOR: stream: flag TASK_WOKEN_RES not set if task in runqueue

Under certain circumstances, if a stream's task is first woken up
(eg: I/O event) then notified of the availability of a buffer it
was waiting for via stream_res_wakeup(), this second event is lost
because the flags are only merged after seeing that the task is
running. At the moment it seems that the TASK_WOKEN_RES event is
not explicitly checked for, but better fix this before getting
reports of lost events.

This fix removes this "task running" test which is properly
performed in task_wakeup(), while the flags are properly merged.

It must be backported to 1.7 and 1.6.

8 years agoDOC: fix references to the section about the unix socket
Willy Tarreau [Fri, 23 Jun 2017 14:01:14 +0000 (16:01 +0200)] 
DOC: fix references to the section about the unix socket

The unix socket is documented in 9.3, not 9.2 of the management guide.

This should be backported to 1.7.

8 years agoBUG/MINOR: log: pin the front connection when front ip/ports are logged
Willy Tarreau [Fri, 23 Jun 2017 09:23:43 +0000 (11:23 +0200)] 
BUG/MINOR: log: pin the front connection when front ip/ports are logged

Mathias Weiersmueller reported an interesting issue with logs which Lukas
diagnosed as dating back from commit 9b061e332 (1.5-dev9). When front
connection information (ip, port) are logged in TCP mode and the log is
emitted at the end of the connection (eg: because %B or any log tag
requiring LW_BYTES is set), the log is emitted after the connection is
closed, so the address and ports cannot be retrieved anymore.

It could be argued that we'd make a special case of these to immediatly
retrieve the source and destination addresses from the connection, but it
seems cleaner to simply pin the front connection, marking it "tracked" by
adding the LW_XPRT flag to mention that we'll need some of these elements
at the last moment. Only LW_FRTIP and LW_CLIP are affected. Note that after
this change, LW_FRTIP could simply be removed as it's not used anywhere.

Note that the problem doesn't happen when using %[src] or %[dst] since
all sample expressions set LW_XPRT.

This must be backported to 1.7, 1.6 and 1.5.

8 years agoBUG/MINOR: cfgparse: Check if tune.http.maxhdr is in the range 1..32767
Christopher Faulet [Wed, 21 Jun 2017 14:31:35 +0000 (16:31 +0200)] 
BUG/MINOR: cfgparse: Check if tune.http.maxhdr is in the range 1..32767

We cannot store more than 32K headers in the structure hdr_idx, because
internaly we use signed short integers. To avoid any bugs (due to an integers
overflow), a check has been added on tune.http.maxhdr to be sure to not set a
value greater than 32767 and lower than 1 (because this is a nonsense to set
this parameter to a value <= 0).

The documentation has been updated accordingly.

This patch can be backported in 1.7, 1.6 and 1.5.

8 years agoBUG/MINOR: Wrong peer task expiration handling during synchronization processing.
Frédéric Lécaille [Mon, 29 May 2017 11:47:16 +0000 (13:47 +0200)] 
BUG/MINOR: Wrong peer task expiration handling during synchronization processing.

When a peer task has sent a synchronization request to remote peers
its next expiration date was updated based on a resynchronization timeout
value which itself may have already expired leading the underlying
poller to wait for 0ms during a fraction of second (consuming high CPU
resources).

With this patch we update such peer task expiration dates only if
the resynchronization timeout is not already expired.

Thanks to Patrick Hemmer who reported an issue with nice traces
which helped in finding this one.

This patch may be backported to 1.7 and 1.6.

8 years agoBUG/MEDIUM: mworker: don't reuse PIDs passed to the master
William Lallemand [Tue, 20 Jun 2017 09:20:33 +0000 (11:20 +0200)] 
BUG/MEDIUM: mworker: don't reuse PIDs passed to the master

When starting the master worker with -sf or -st, the PIDs will be reused
on the next reload, which is a problem if new processes on the system
took those PIDs.

This patch ensures that we don't register old PIDs in the reload system
when launching the master worker.

8 years agoMINOR: mworker: don't copy -x argument anymore in copy_argv()
William Lallemand [Tue, 20 Jun 2017 09:20:23 +0000 (11:20 +0200)] 
MINOR: mworker: don't copy -x argument anymore in copy_argv()

Don't copy the -x argument anymore in copy_argv() since it's already
allocated in mworker_reload().

Make the copy_argv() more consistent when used with multiple arguments
to strip.

It prevents multiple -x on reload, which is not supported.

8 years agoMINOR: warning on multiple -x
William Lallemand [Mon, 19 Jun 2017 14:37:19 +0000 (16:37 +0200)] 
MINOR: warning on multiple -x

Multiple use of the -x option is useless, emit a warning.

8 years agoBUG/MEDIUM: fix segfault when no argument to -x option
William Lallemand [Mon, 19 Jun 2017 13:57:55 +0000 (15:57 +0200)] 
BUG/MEDIUM: fix segfault when no argument to -x option

This patch fixes a segfault in the command line parser.

When haproxy is launched with -x with no argument and -x is the latest
option in argv it segfaults.

Use usage() insteads of exit() on error.

8 years agoSCRIPTS: create-release: enforce GIT_COMMITTER_{NAME|EMAIL} validity
Willy Tarreau [Fri, 16 Jun 2017 10:43:53 +0000 (12:43 +0200)] 
SCRIPTS: create-release: enforce GIT_COMMITTER_{NAME|EMAIL} validity

If it's not set, fall back to git config --get.

8 years agoscripts: create-release pass -n to tail
Willy Tarreau [Fri, 16 Jun 2017 10:35:54 +0000 (12:35 +0200)] 
scripts: create-release pass -n to tail

Some versions of tail don't accept "tail +4".

8 years agoBUG/MEDIUM: unix: never unlink a unix socket from the file system
Willy Tarreau [Fri, 16 Jun 2017 08:34:20 +0000 (10:34 +0200)] 
BUG/MEDIUM: unix: never unlink a unix socket from the file system

James Brown reported some cases where a race condition happens between
the old and the new processes resulting in the leaving process removing
a newly bound unix socket. Jeff gave all the details he observed here :

   https://www.mail-archive.com/haproxy@formilux.org/msg25001.html

The unix socket removal was an attempt at an optimal cleanup, which
almost never works anyway since the process is supposed to be chrooted.
And in the rare cases where it works it occasionally creates trouble.
There was already a workaround in place to avoid removing this socket
when it's been inherited from a parent's file descriptor.

So let's finally kill this useless stuff now to definitely get rid of
this persistent problem.

This fix should be backported to all stable releases.

8 years agoBUG/MAJOR: server: Segfault after parsing server state file.
Frédéric Lécaille [Thu, 15 Jun 2017 12:09:10 +0000 (14:09 +0200)] 
BUG/MAJOR: server: Segfault after parsing server state file.

This patch makes the server state file parser ignore servers wich are
not present in the configuration file.

8 years agoBUG/MEDIUM: peers: Peers CLOSE_WAIT issue.
Frédéric Lécaille [Tue, 13 Jun 2017 14:39:57 +0000 (16:39 +0200)] 
BUG/MEDIUM: peers: Peers CLOSE_WAIT issue.

A peer session which has just been created upon reconnect timeout expirations,
could be right after shutdown (at peer session level) because the remote
side peer could also righ after have connected. In such a case the underlying
TCP session was still running (connect()/accept()) and finally left in CLOSE_WAIT
state after the remote side stopped writting (shutdown(SHUT_WR)).

Now on, with this patch we never shutdown such peer sessions wich have just
been created. We leave them connect to the remote peer which is already
connected and must shutdown its own peer session.

Thanks to Patric Hemmer and Yves Lafon at w3.org for reporting this issue,
and for having tested this patch on the field.
Thanks also to Willy and Yelp blogs which helped me a lot in fixing it
(see https://www.haproxy.com/blog/truly-seamless-reloads-with-haproxy-no-more-hacks/ and
https://engineeringblog.yelp.com/2015/04/true-zero-downtime-haproxy-reloads.htmll).

8 years agoBUG/MINOR: http/filters: Be sure to wait if a filter loops in HTTP_MSG_ENDING
Christopher Faulet [Fri, 31 Mar 2017 13:37:29 +0000 (15:37 +0200)] 
BUG/MINOR: http/filters: Be sure to wait if a filter loops in HTTP_MSG_ENDING

A filter can choose to loop when a HTTP message is in the state
HTTP_MSG_ENDING. But the transaction is terminated with an error if the input is
closed (CF_SHUTR set on the channel). At this step, we have received all data,
so we can wait.

So now, we also check the parser state before leaving. This fix only affects
configs that use a filter that can wait in http_forward_data or http_end
callbacks, when all data were parsed.

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