]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
8 years agoREORG: cli: move map and acl code to map.c
William Lallemand [Fri, 18 Nov 2016 18:26:17 +0000 (19:26 +0100)] 
REORG: cli: move map and acl code to map.c

Move map and acl CLI functions to map.c and use the cli keyword API to
register actions on the CLI. Then remove the now unused individual
"add" and "del" keywords.

8 years agoREORG: cli: move ssl CLI functions to ssl_sock.c
William Lallemand [Sat, 29 Oct 2016 16:09:35 +0000 (18:09 +0200)] 
REORG: cli: move ssl CLI functions to ssl_sock.c

Move ssl CLI functions to ssl_sock.c and use the cli keyword API to
register ssl actions on the CLI.

8 years agoREORG: cli: split dumpstats.h in stats.h and cli.h
William Lallemand [Mon, 21 Nov 2016 16:49:11 +0000 (17:49 +0100)] 
REORG: cli: split dumpstats.h in stats.h and cli.h

proto/dumpstats.h has been split in 4 files:

  * proto/cli.h  contains protypes for the CLI
  * proto/stats.h contains prototypes for the stats
  * types/cli.h contains definition for the CLI
  * types/stats.h contains definition for the stats

8 years agoREORG: cli: split dumpstats.c in src/cli.c and src/stats.c
William Lallemand [Mon, 21 Nov 2016 16:18:36 +0000 (17:18 +0100)] 
REORG: cli: split dumpstats.c in src/cli.c and src/stats.c

dumpstats.c was containing either the stats code and the CLI code.
The cli code has been moved to cli.c and the stats code to stats.c

8 years agoMINOR: connection: add names for transport and data layers
Willy Tarreau [Thu, 24 Nov 2016 15:58:12 +0000 (16:58 +0100)] 
MINOR: connection: add names for transport and data layers

This makes debugging easier and avoids having to put ugly checks
against certain well-known internal struct pointers.

8 years agoMINOR: connection: add a few functions to report the data and xprt layers' names
Willy Tarreau [Wed, 23 Nov 2016 17:00:08 +0000 (18:00 +0100)] 
MINOR: connection: add a few functions to report the data and xprt layers' names

These functions will be needed by "show sess" on the CLI, let's make them
globally available. It's important to note that due to the fact that we
still do not set the data and transport layers' names in the structures,
we still have to rely on some exports just to match the pointers. This is
ugly but is preferable to adding many includes since the short-term goal
is to get rid of these tests by having proper names in place.

8 years agoBUG/MINOR: cli: wake up the CLI's task after a timeout update
Willy Tarreau [Thu, 24 Nov 2016 14:35:16 +0000 (15:35 +0100)] 
BUG/MINOR: cli: wake up the CLI's task after a timeout update

When the CLI's timeout is reduced, nothing was done to take the task
up to update it. In the past it used to run inside process_stream()
so it used to be refreshed. This is not the case anymore since we have
the appctx so the task needs to be woken up in order to recompute the
new expiration date.

This fix needs to be backported to 1.6.

8 years agoBUG/MINOR: cli: dequeue from the proxy when changing a maxconn
Willy Tarreau [Thu, 24 Nov 2016 14:25:39 +0000 (15:25 +0100)] 
BUG/MINOR: cli: dequeue from the proxy when changing a maxconn

The "set maxconn frontend" statement on the CLI tries to dequeue possibly
pending requests, but due to a copy-paste error, they're dequeued on the
CLI's frontend instead of the one being changed.

The impact is very minor as it only means that possibly pending connections
will still have to wait for a previous one to complete before being accepted
when a limit is raised.

This fix has to be backported to 1.6 and 1.5.

8 years agoBUG/MINOR: cli: fix pointer size when reporting data/transport layer name
Willy Tarreau [Thu, 24 Nov 2016 14:21:26 +0000 (15:21 +0100)] 
BUG/MINOR: cli: fix pointer size when reporting data/transport layer name

In dumpstats.c we have get_conn_xprt_name() and get_conn_data_name() to
report the name of the data and transport layers used on a connection.
But when the name is not known, its pointer is reported instead. But the
static char used to report the pointer is too small as it doesn't leave
room for '0x'. Fortunately all subsystems are known so we never trigger
this case.

This fix needs to be backported to 1.6 and 1.5.

8 years agoBUILD: fix build on Solaris 10/11
David Carlier [Sun, 20 Nov 2016 10:42:38 +0000 (10:42 +0000)] 
BUILD: fix build on Solaris 10/11

uint16_t instead of u_int16_t
None ISO fields of struct tm are not present, but
by zeroyfing it, on GNU and BSD systems tm_gmtoff
field will be set.

[wt: moved the memset into each of the date functions]

8 years agoBUILD: contrib: fix ip6range build on Centos 7
Willy Tarreau [Tue, 22 Nov 2016 10:50:51 +0000 (11:50 +0100)] 
BUILD: contrib: fix ip6range build on Centos 7

Jarno Huuskonen reported that ip6range doesn't build anymore on
Centos 7 (and possibly other distros) due to "in6_u" not being known.
Using s6_addr32 instead of in6_u.u6_addr32 apparently works fine, and
it's also what the Lua code uses so it should be OK.

This patch may be backported to 1.6.

8 years agoMINOR: stats: correct documentation of process ID for typed output
Simon Horman [Mon, 21 Nov 2016 16:00:24 +0000 (17:00 +0100)] 
MINOR: stats: correct documentation of process ID for typed output

The process ID appears at the end of the first column rather than
the line.

8 years agoMINOR: spoe: Add "option set-on-error" statement
Christopher Faulet [Wed, 16 Nov 2016 14:36:19 +0000 (15:36 +0100)] 
MINOR: spoe: Add "option set-on-error" statement

It defines the variable to set when an error occurred during an event
processing. It will only be set when an error occurred in the scope of the
transaction. As for all other variables define by the SPOE, it will be
prefixed. So, if your variable name is "error" and your prefix is "my_spoe_pfx",
the variable will be "txn.my_spoe_pfx.error".

When set, the variable is the boolean "true". Note that if "option
continue-on-error" is set, the variable is not automatically removed between
events processing.

8 years agoMINOR: spoe: Add "maxconnrate" and "maxerrrate" statements
Christopher Faulet [Wed, 16 Nov 2016 14:01:12 +0000 (15:01 +0100)] 
MINOR: spoe: Add "maxconnrate" and "maxerrrate" statements

"maxconnrate" is the maximum number of connections per second. The SPOE will
stop to open new connections if the maximum is reached and will wait to acquire
an existing one.

"maxerrrate" is the maximum number of errors per second. The SPOE will stop its
processing if the maximum is reached.

These options replace hardcoded macros MAX_NEW_SPOE_APPLETS and
MAX_NEW_SPOE_APPLET_ERRS. We use it to limit SPOE activity, especially when
servers are down..

8 years agoMINOR: spoe: Add 'option continue-on-error' statement in spoe-agent section
Christopher Faulet [Mon, 14 Nov 2016 09:54:21 +0000 (10:54 +0100)] 
MINOR: spoe: Add 'option continue-on-error' statement in spoe-agent section

By default, for a specific stream, when an abnormal/unexpected error occurs, the
SPOE is disabled for all the transaction. So if you have several events
configured, such error on an event will disabled all followings. For TCP
streams, this will disable the SPOE for the whole session. For HTTP streams,
this will disable it for the transaction (request and response).

To bypass this behaviour, you can set 'continue-on-error' option in 'spoe-agent'
section. With this option, only the current event will be ignored.

8 years agoMINOR: spoe: Remove useless 'timeout ack' option
Christopher Faulet [Sat, 19 Nov 2016 15:47:56 +0000 (16:47 +0100)] 
MINOR: spoe: Remove useless 'timeout ack' option

To limit the time to process an event, you should set 'timeout processing'
option. So 'timeout ack' option is redundant and useless.

8 years agoMINOR: spoe: Add 'timeout processing' option to limit time to process an event
Christopher Faulet [Thu, 10 Nov 2016 14:04:51 +0000 (15:04 +0100)] 
MINOR: spoe: Add 'timeout processing' option to limit time to process an event

It is a way to set the maximum time to wait for a stream to process an event,
i.e to acquire a stream to talk with an agent, to encode all messages, to send
the NOTIFY frame, to receive the corrsponding acknowledgement and to process all
actions. It is applied on the stream that handle the client and the server
sessions.

8 years agoMINOR: filters: Add check_timeouts callback to handle timers expiration on streams
Christopher Faulet [Thu, 10 Nov 2016 13:58:05 +0000 (14:58 +0100)] 
MINOR: filters: Add check_timeouts callback to handle timers expiration on streams

A filter can now be notified when a stream is woken up because of an expired
timer.

The documentation and the TRACE filter have been updated.

8 years agoBUG/MEDIUM: lua: In some case, the return of sample-fetche is ignored
Thierry FOURNIER / OZON.IO [Fri, 18 Nov 2016 18:06:21 +0000 (19:06 +0100)] 
BUG/MEDIUM: lua: In some case, the return of sample-fetche is ignored

When:

 - A Lua action return data and close the channel. The request status
   is set to HTTP_MSG_CLOSED for the request and HTTP_MSG_DONE for the
   response.

 - HAProxy sets the state HTTP_MSG_ERROR. I don't known why, because
   there are many line which sets this state.

 - A Lua sample-fetch is executed, typically for building the log
   line.

 - When the Lua sample fetch exits, a control of the data is
   executed. If HAProxy is currently parsing the request, the request
   is aborted in order to prevent a segfault or sending corrupted
   data.

This ast control is executed comparing the state HTTP_MSG_BODY. When
this state is reached, the request is parsed and no error are
possible. When the state is < than HTTP_MSG_BODY, the parser is
running.

Unfortunately, the code HTTP_MSG_ERROR is just < HTTP_MSG_BODY. When
we are in error, we want to terminate the execution of Lua without
error.

This patch changes the comparaison level.

This patch must be backported in 1.6

8 years agoBUG/MINOR: cli: properly decrement ref count on tables during failed dumps
Willy Tarreau [Fri, 18 Nov 2016 18:17:40 +0000 (19:17 +0100)] 
BUG/MINOR: cli: properly decrement ref count on tables during failed dumps

Gernot Pörner reported some constant leak of ref counts for stick tables
entries. It happens that this leak was not at all in the regular traffic
path but on the "show table" path. An extra ref count was taken during
the dump if the output had to be paused, and it was released upon clean
termination or an error detected in the I/O handler. But the release
handler didn't do it, while it used to properly do it for the sessions
dump.

This fix needs to be backported to 1.6.

8 years agoBUG/MEDIUM: stick-table: fix regression caused by recent fix for out-of-memory
Willy Tarreau [Fri, 18 Nov 2016 17:21:39 +0000 (18:21 +0100)] 
BUG/MEDIUM: stick-table: fix regression caused by recent fix for out-of-memory

Commit ef8f4fe ("BUG/MINOR: stick-table: handle out-of-memory condition
gracefully") unfortunately got trapped by a pointer operation. Replacing

    ts = poll_alloc() + size;

with :

    ts = poll_alloc();
    ts += size;

Doesn't give the same result because pool_alloc() is void while ts is a
struct stksess*. So now we don't access the same places, which is visible
in certain stick-table scenarios causing a crash.

This must be backported to 1.6 and 1.5.

8 years agoDEBUG: connection: mark the closed FDs with a value that is easier to detect
Willy Tarreau [Thu, 17 Nov 2016 13:22:52 +0000 (14:22 +0100)] 
DEBUG: connection: mark the closed FDs with a value that is easier to detect

Setting an FD to -1 when closed isn't the most easily noticeable thing
to do when we're chasing accidental reuse of a stale file descriptor.
Instead set it to that large a negative value that it will overflow the
fdtab and provide an analysable core at the moment the issue happens.
Care was taken to ensure it doesn't overflow nor change sign on 32-bit
machines when multiplied by fdtab, and that it also remains negative for
the various checks that exist. The value equals 0xFDDEADFD which happens
to be easily spotted in a debugger.

8 years agoBUG/MEDIUM: connection: check the control layer before stopping polling
Willy Tarreau [Thu, 17 Nov 2016 11:05:13 +0000 (12:05 +0100)] 
BUG/MEDIUM: connection: check the control layer before stopping polling

The bug described in commit 568743a ("BUG/MEDIUM: stream-int: completely
detach connection on connect error") was not a stream-interface layer bug
but a connection layer bug. There was exactly one place in the code where
we could change a file descriptor's status without first checking whether
it is valid or not, it was in conn_stop_polling(). This one is called when
the polling status is changed after an update, and calls fd_stop_both even
if we had already closed the file descriptor :

1479388298.484240 ->->->->->   conn_fd_handler > conn_cond_update_polling
1479388298.484240 ->->->->->->   conn_cond_update_polling > conn_stop_polling
1479388298.484241 ->->->->->->->   conn_stop_polling > conn_ctrl_ready
1479388298.484241                  conn_stop_polling < conn_ctrl_ready
1479388298.484241 ->->->->->->->   conn_stop_polling > fd_stop_both
1479388298.484242 ->->->->->->->->   fd_stop_both > fd_update_cache
1479388298.484242 ->->->->->->->->->   fd_update_cache > fd_release_cache_entry
1479388298.484242                      fd_update_cache < fd_release_cache_entry
1479388298.484243                    fd_stop_both < fd_update_cache
1479388298.484243                  conn_stop_polling < fd_stop_both
1479388298.484243                conn_cond_update_polling < conn_stop_polling
1479388298.484243              conn_fd_handler < conn_cond_update_polling

The problem with the previous fix above is that it break the http_proxy mode
and possibly even some Lua parts and peers to a certain extent ; all outgoing
connections where the target address is initially copied into the outgoing
connection which experience a retry would use a random outgoing address after
the retry because closing and detaching the connection causes the target
address to be lost. This was attempted to be addressed by commit 0857d7a
("BUG/MAJOR: stream: properly mark the server address as unset on connect
retry") but it used to only solve the most visible effect and not the root
cause.

Prior to this fix, it was possible to cause this config to keep CLOSE_WAIT
for as long as it takes to expire a client or server timeout (note the
missing client timeout) :

   listen test
        mode http
        bind :8002
        server s1 127.0.0.1:8001

   $ tcploop 8001 L0 W N20 A R P100 S:"HTTP/1.1 200 OK\r\nContent-length: 0\r\n\r\n" &
   $ tcploop 8002 N200 C T W S:"GET / HTTP/1.0\r\n\r\n" O P10000 K

With this patch, these CLOSE_WAIT properly vanish when both processes leave.

This commit reverts the two fixes above and replaces them with the proper
fix in connection.h. It must be backported to 1.6 and 1.5. Thanks to
Robson Roberto Souza Peixoto for providing very detailed traces showing
some obvious inconsistencies leading to finding this bug.

8 years agoMEDIUM: lua: Add cli handler for Lua
Thierry FOURNIER / OZON.IO [Sun, 13 Nov 2016 12:19:20 +0000 (13:19 +0100)] 
MEDIUM: lua: Add cli handler for Lua

Now, HAProxy allows to register some keys in the "cli". This patch allows
to handle these keys with Lua code.

8 years agoMINOR: cli: add private pointer and release function
Thierry FOURNIER / OZON.IO [Sat, 12 Nov 2016 09:51:33 +0000 (10:51 +0100)] 
MINOR: cli: add private pointer and release function

This pointer will be used for storing private context. With this,
the same executed function can handle more than one keyword. This
will be very useful for creation Lua cli bindings.

The release function is called when the command is terminated (give
back the hand to the prompt) or when the session is broken (timeout
or client closed).

8 years agoBUG/MINOR: stick-table: handle out-of-memory condition gracefully
Vincent Bernat [Thu, 17 Nov 2016 14:42:40 +0000 (15:42 +0100)] 
BUG/MINOR: stick-table: handle out-of-memory condition gracefully

In case `pool_alloc2()` returns NULL, propagate the condition to the
caller. This could happen when limiting the amount of memory available
for HAProxy with `-m`.

[wt: backport to 1.6 and 1.5 needed]

8 years agoCLEANUP: lua: avoid directly calling getsockname/getpeername()
Willy Tarreau [Wed, 16 Nov 2016 16:00:14 +0000 (17:00 +0100)] 
CLEANUP: lua: avoid directly calling getsockname/getpeername()

We already have per-protocol functions for this, and they already
take care of properly setting the CO_FL_ADDR_*_SET flags.

8 years agoDOC: ssl: Use correct wording for ca-sign-pass
Bertrand Jacquin [Sun, 13 Nov 2016 16:37:12 +0000 (16:37 +0000)] 
DOC: ssl: Use correct wording for ca-sign-pass

Doc references ca-sign-passphrase but the source code is referring
ca-sign-pass. Align doc to reality.

8 years agoCLEANUP: ssl: Fix bind keywords name in comments
Bertrand Jacquin [Sun, 13 Nov 2016 16:37:11 +0000 (16:37 +0000)] 
CLEANUP: ssl: Fix bind keywords name in comments

Along with a whitespace cleanup and a grammar typo

8 years agoCLEANUP: ssl: Remove goto after return dead code
Bertrand Jacquin [Sun, 13 Nov 2016 16:37:10 +0000 (16:37 +0000)] 
CLEANUP: ssl: Remove goto after return dead code

This code can never be reached.

8 years agoBUG/MINOR: ssl: Print correct filename when error occurs reading OCSP
Bertrand Jacquin [Sun, 13 Nov 2016 16:37:14 +0000 (16:37 +0000)] 
BUG/MINOR: ssl: Print correct filename when error occurs reading OCSP

When Multi-Cert bundle are used, error is throwned regarding certificate
filename without including certifcate type extension.

8 years agoBUG/MEDIUM: ssl: Store certificate filename in a variable
Bertrand Jacquin [Sun, 13 Nov 2016 16:37:13 +0000 (16:37 +0000)] 
BUG/MEDIUM: ssl: Store certificate filename in a variable

Before this change, trash is being used to create certificate filename
to read in care Mutli-Cert are in used. But then ssl_sock_load_ocsp()
modify trash leading to potential wrong information given in later error
message.

This also blocks any further use of certificate filename for other
usage, like ongoing patch to support Certificate Transparency handling
in Multi-Cert bundle.

8 years agoCLEANUP: lua: control executed twice
Thierry FOURNIER / OZON.IO [Sat, 12 Nov 2016 12:11:47 +0000 (13:11 +0100)] 
CLEANUP: lua: control executed twice

The availaible size in the stack is check two times. This patch removes
this double check.

Must be backported in 1.6

8 years agoCLEANUP: lua: move comment
Thierry FOURNIER / OZON.IO [Sat, 12 Nov 2016 10:07:05 +0000 (11:07 +0100)] 
CLEANUP: lua: move comment

Old comment is misplaced. Certainly due to a bad copy/paste

Must be backported in 1.6

8 years agoBUG/MEDIUM: channel: bad unlikely macro
Thierry FOURNIER / OZON.IO [Sat, 12 Nov 2016 16:39:58 +0000 (17:39 +0100)] 
BUG/MEDIUM: channel: bad unlikely macro

The unlikely macro doesn't take in acount the condition, but only one
variable.

Must be backported in 1.6

[wt: with gcc 3.x, unlikely(x) is defined as __builtin_expect((x) != 0, 0)
 so the condition is wrong for negative numbers, which correspond to the
 case where bi_getblk_nc() has reached the end of the buffer and the
 channel is already closed. With gcc 4.x, the output is cast to unsigned long
 so the <=0 will not match negative values either. This is only used in Lua
 for now so that may explain why it hasn't hit yet]

8 years agoCONTRIB: tcploop: add basic loops via a jump instruction
Willy Tarreau [Sat, 12 Nov 2016 17:54:20 +0000 (18:54 +0100)] 
CONTRIB: tcploop: add basic loops via a jump instruction

This one jumps back to the oldest post-fork and post-accept action,
so it allows to recv(), pause() and send() in loops after a fork()
and an accept() for example. This is handy for bugs that reproduce
once in a while or to keep idle connections working.

8 years agoCONTRIB: tcploop: don't report failed send() or recv()
Willy Tarreau [Sat, 12 Nov 2016 17:45:42 +0000 (18:45 +0100)] 
CONTRIB: tcploop: don't report failed send() or recv()

Many clients close with an RST on the last response or when they get
their response, so let's not report an error.

8 years agoCONTRIB: tcploop: support sending plain strings
Willy Tarreau [Sat, 12 Nov 2016 17:25:45 +0000 (18:25 +0100)] 
CONTRIB: tcploop: support sending plain strings

By passing "S:<string>" instead of S<size> it's possible to send
a pre-defined string, which is convenient to write HTTP requests or
responses.

Example : produce two responses, one in keep-alive, one not for ab :

  ./tcploop 8001 L W N2 A R S:"HTTP/1.0 200 OK\r\nConnection: keep-alive\r\nContent-length: 50\r\n\r\n0123456789.123456789.123456789.123456789.123456789" R S:"HTTP/1.0 200 OK\r\nContent-length: 50\r\n\r\n0123456789.123456789.123456789.123456789.123456789"

With 20 such keep-alive responses and 10 parallel processes, ab achieves
350kreq/s, so it should be possible to get precise timings.

8 years agoCONTRIB: tcploop: update the usage output
Willy Tarreau [Sat, 12 Nov 2016 16:53:16 +0000 (17:53 +0100)] 
CONTRIB: tcploop: update the usage output

Otherwise we have no other help.

8 years agoCONTRIB: tcploop: implement logging when called with -v
Willy Tarreau [Sat, 12 Nov 2016 16:50:57 +0000 (17:50 +0100)] 
CONTRIB: tcploop: implement logging when called with -v

This is helpful to show what state we're dealing with. The pid is
written, optionally followed by the time in 3 different formats
(relative/absolute) depending on the command line option (-t, -tt, -ttt).

8 years agoCONTRIB: tcploop: implement fork()
Willy Tarreau [Sat, 12 Nov 2016 12:25:53 +0000 (13:25 +0100)] 
CONTRIB: tcploop: implement fork()

Fork is a very convenient way to deal with independant yet properly
timed connections. It's particularly useful here for accept(), and
ensures that any accepted FD will automatically be released. The
principle is that when we hit a fork command, the parent restarts
evaluating the actions from the beginning and the child continues
to evaluate the next actions. Listen and connect are skipped if the
connection is already established. Fork() is amazingly cheap on
Linux, 21k forked connections per second are handled on a single
core, and 38k on two cores.

For now it's not possible to have two different code paths so in order
to have both a listener and a connector, two distinct commands are
still needed.

8 years agoCONTRIB: tcploop: scriptable TCP I/O for debugging purposes
Willy Tarreau [Sat, 12 Nov 2016 10:29:46 +0000 (11:29 +0100)] 
CONTRIB: tcploop: scriptable TCP I/O for debugging purposes

netcat, nc6 and socat are only partially convenient as reproducers for
state machine bugs, but when it comes to adding delays, forcing resets,
waiting for data to be acked, they become useless.

The purpose of this utility is to be able to easily script some TCP
operations such as connect, accept, send, receive, shutdown and of
course pauses.

8 years agoMINOR: lua: add ip addresses and network manipulation function
Thierry FOURNIER / OZON.IO [Thu, 10 Nov 2016 19:38:11 +0000 (20:38 +0100)] 
MINOR: lua: add ip addresses and network manipulation function

Add two functions core.parse_addr() and core.match_addr() where are used
for matching networks.

8 years agoMINOR: lua: add function which return true if the channel is full.
Thierry FOURNIER / OZON.IO [Mon, 7 Nov 2016 14:28:40 +0000 (15:28 +0100)] 
MINOR: lua: add function which return true if the channel is full.

Add function which return true if the channel is full. It is
useful for triggering some process when the buffer is full.

8 years agoCONTRIB: debug/flags: add check for SF_ERR_CHK_PORT
Willy Tarreau [Fri, 11 Nov 2016 07:05:34 +0000 (08:05 +0100)] 
CONTRIB: debug/flags: add check for SF_ERR_CHK_PORT

This flag was added by commit 95db2bc ("MAJOR: check: find out which
port to use for health check at run time"), let's check for it.

8 years agoBUILD: debug/flags: remove test for SF_COMP_READY
Willy Tarreau [Fri, 11 Nov 2016 07:04:44 +0000 (08:04 +0100)] 
BUILD: debug/flags: remove test for SF_COMP_READY

It doesn't exist anymore.

8 years agoBUILD: http: include types/sample.h in proto_http.h
Willy Tarreau [Fri, 11 Nov 2016 06:56:48 +0000 (07:56 +0100)] 
BUILD: http: include types/sample.h in proto_http.h

Commit d7c9196 ("MAJOR: filters: Add filters support") removed sample.h
from proto_http.h, but it has become necessary as of commit fd7edd3
("MINOR: Move http method enum from proto_http to sample") in order
to have HTTP_METH_*. Due to this, the "debug/flags" utility doesn't
build anymore.

8 years agoSCRIPTS: make publish-release also copy the new SPOE doc
Willy Tarreau [Wed, 9 Nov 2016 22:21:47 +0000 (23:21 +0100)] 
SCRIPTS: make publish-release also copy the new SPOE doc

It may be useful for developers who want to experiment with the protocol.

8 years ago[RELEASE] Released version 1.7-dev6 v1.7-dev6
Willy Tarreau [Wed, 9 Nov 2016 22:18:17 +0000 (23:18 +0100)] 
[RELEASE] Released version 1.7-dev6

Released version 1.7-dev6 with the following main changes :
    - DOC: fix the entry for hash-balance-factor config option
    - DOC: Fix typo in description of `-st` parameter in man page
    - CLEANUP: cfgparse: Very minor spelling correction
    - MINOR: examples: Update haproxy.spec URLs to haproxy.org
    - BUG/MEDIUM: peers: on shutdown, wake up the appctx, not the stream
    - BUG/MEDIUM: peers: fix use after free in peer_session_create()
    - MINOR: peers: make peer_session_forceshutdown() use the appctx and not the stream
    - MINOR: peers: remove the pointer to the stream
    - BUG/MEDIUM: systemd-wrapper: return correct exit codes
    - DOC: stats: provide state details for show servers state
    - MEDIUM: tools: make str2ip2() preserve existing ports
    - CLEANUP: tools: make ipcpy() preserve the original port
    - OPTIM: http: move all http character classs tables into a single one
    - OPTIM: http: improve parsing performance of long header lines
    - OPTIM: http: improve parsing performance of long URIs
    - OPTIM: http: optimize lookup of comma and quote in header values
    - BUG/MEDIUM: srv-state: properly restore the DRAIN state
    - BUG/MINOR: srv-state: allow to have both CMAINT and FDRAIN flags
    - MINOR: server: do not emit warnings/logs/alerts on server state changes at boot
    - BUG/MEDIUM: servers: properly propagate the maintenance states during startup
    - MEDIUM: wurfl: add Scientiamobile WURFL device detection module
    - DOC: move the device detection modules documentation to their own files
    - CLEANUP: wurfl: reduce exposure in the rest of the code
    - MEDIUM: ssl: Add support for OpenSSL 1.1.0
    - MINOR: stream: make option contstats usable again
    - MEDIUM: tools: make str2sa_range() return the FQDN even when not resolving
    - MINOR: init: move apply_server_state in haproxy.c before MODE_CHECK
    - MAJOR: server: postpone address resolution
    - MINOR: new srv_admin flag: SRV_ADMF_RMAINT
    - MINOR: server: indicate in the logs when RMAINT is cleared
    - MINOR: stats: indicate it when a server is down due to resolution
    - MINOR: server: make srv_set_admin_state() capable of telling why this happens
    - MINOR: dns: implement extra 'hold' timers.
    - MAJOR: dns: runtime resolution can change server admin state
    - MEDIUM: cli: leave the RMAINT state when setting an IP address on the CLI
    - MEDIUM: server: add a new init-addr server line setting
    - MEDIUM: server: make use of init-addr
    - MINOR: server: implement init-addr none
    - MEDIUM: server: make libc resolution failure non-fatal
    - MINOR: server: add support for explicit numeric address in init-addr
    - DOC: add some documentation for the "init-addr" server keyword
    - MINOR: init: add -dr to ignore server address resolution failures
    - MEDIUM: server: do not restrict anymore usage of IP address from the state file
    - BUG: vars: Fix 'set-var' converter because of a typo
    - CLEANUP: remove last references to 'ruleset' section
    - MEDIUM: filters: Add attch/detach and stream_set_backend callbacks
    - MINOR: filters: Update filters documentation accordingly to recent changes
    - MINOR: filters: Call stream_set_backend callbacks before updating backend stats
    - MINOR: filters: Remove backend filters attached to a stream only for HTTP streams
    - MINOR: flt_trace: Add hexdump option to dump forwarded data
    - MINOR: cfgparse: Add functions to backup and restore registered sections
    - MINOR: cfgparse: Parse scope lines and save the last one parsed
    - REORG: sample: move code to release a sample expression in sample.c
    - MINOR: vars: Allow '.' in variable names
    - MINOR: vars: Add vars_set_by_name_ifexist function
    - MEDIUM: vars: Add a per-process scope for variables
    - MINOR: vars: Add 'unset-var' action/converter
    - MAJOR: spoe: Add an experimental Stream Processing Offload Engine
    - MINOR: spoe: add random ip-reputation service as SPOA example
    - MINOR: spoe/checks: Add support for SPOP health checks
    - DOC: update ROADMAP file

8 years agoDOC: update ROADMAP file
Willy Tarreau [Wed, 9 Nov 2016 22:17:05 +0000 (23:17 +0100)] 
DOC: update ROADMAP file

tcp-request session is OK now.

8 years agoMINOR: spoe/checks: Add support for SPOP health checks
Christopher Faulet [Mon, 7 Nov 2016 20:07:38 +0000 (21:07 +0100)] 
MINOR: spoe/checks: Add support for SPOP health checks

A new "option spop-check" statement has been added to enable server health
checks based on SPOP HELLO handshake. SPOP is the protocol used by SPOE filters
to talk to servers.

8 years agoMINOR: spoe: add random ip-reputation service as SPOA example
Christopher Faulet [Thu, 3 Nov 2016 21:49:37 +0000 (22:49 +0100)] 
MINOR: spoe: add random ip-reputation service as SPOA example

This is a very simple service that implement a "random" ip reputation
service. It will return random scores for all checked IP addresses. It only
shows you how to implement a ip reputation service or such kind of services
using the SPOE.

8 years agoMAJOR: spoe: Add an experimental Stream Processing Offload Engine
Christopher Faulet [Thu, 27 Oct 2016 20:29:49 +0000 (22:29 +0200)] 
MAJOR: spoe: Add an experimental Stream Processing Offload Engine

SPOE makes possible the communication with external components to retrieve some
info using an in-house binary protocol, the Stream Processing Offload Protocol
(SPOP). In the long term, its aim is to allow any kind of offloading on the
streams. This first version, besides being experimental, won't do lot of
things. The most important today is to validate the protocol design and lay the
foundations of what will, one day, be a full offload engine for the stream
processing.

So, for now, the SPOE can offload the stream processing before "tcp-request
content", "tcp-response content", "http-request" and "http-response" rules. And
it only supports variables creation/suppression. But, in spite of these limited
features, we can easily imagine to implement a SSO solution, an ip reputation
service or an ip geolocation service.

Internally, the SPOE is implemented as a filter. So, to use it, you must use
following line in a proxy proxy section:

  frontend my-front
      ...
      filter spoe [engine <name>] config <file>
      ...

It uses its own configuration file to keep the HAProxy configuration clean. It
is also a easy way to disable it by commenting out the filter line.

See "doc/SPOE.txt" for all details about the SPOE configuration.

8 years agoMINOR: vars: Add 'unset-var' action/converter
Christopher Faulet [Wed, 9 Nov 2016 15:54:56 +0000 (16:54 +0100)] 
MINOR: vars: Add 'unset-var' action/converter

It does the opposite of 'set-var' action/converter. It is really useful for
per-process variables. But, it can be used for any scope.

The lua function 'unset_var' has also been added.

8 years agoMEDIUM: vars: Add a per-process scope for variables
Christopher Faulet [Wed, 9 Nov 2016 10:36:17 +0000 (11:36 +0100)] 
MEDIUM: vars: Add a per-process scope for variables

Now it is possible to use variables attached to a process. The scope name is
'proc'. These variables are released only when HAProxy is stopped.

'tune.vars.proc-max-size' directive has been added to confiure the maximum
amount of memory used by "proc" variables. And because memory accounting is
hierachical for variables, memory for "proc" vars includes memory for "sess"
vars.

8 years agoMINOR: vars: Add vars_set_by_name_ifexist function
Christopher Faulet [Mon, 31 Oct 2016 10:05:37 +0000 (11:05 +0100)] 
MINOR: vars: Add vars_set_by_name_ifexist function

This function, unsurprisingly, sets a variable value only if it already
exists. In other words, this function will succeed only if the variable was
found somewhere in the configuration during HAProxy startup.

It will be used by SPOE filter. So an agent will be able to set a value only for
existing variables. This prevents an agent to create a very large number of
unused variables to flood HAProxy and exhaust the memory reserved to variables..

8 years agoMINOR: vars: Allow '.' in variable names
Christopher Faulet [Mon, 31 Oct 2016 09:49:03 +0000 (10:49 +0100)] 
MINOR: vars: Allow '.' in variable names

This is required to have implicit prefix or scope. SPOE filter will use it to
keep variables set by an agent in its own namespace.

8 years agoREORG: sample: move code to release a sample expression in sample.c
Christopher Faulet [Wed, 26 Oct 2016 09:34:47 +0000 (11:34 +0200)] 
REORG: sample: move code to release a sample expression in sample.c

This code has been moved from haproxy.c to sample.c and the function
release_sample_expr can now be called from anywhere to release a sample
expression. This function will be used by the stream processing offload engine
(SPOE).

8 years agoMINOR: cfgparse: Parse scope lines and save the last one parsed
Christopher Faulet [Fri, 4 Nov 2016 21:36:15 +0000 (22:36 +0100)] 
MINOR: cfgparse: Parse scope lines and save the last one parsed

A scope is a section name between square bracket, alone on its line, ie:

  [scope-name]
  ...

The spaces at the beginning and at the end of the line are skipped. Comments at
the end of the line are also skipped.

When a scope is parsed, its name is saved in the global variable
cfg_scope. Initially, cfg_scope is NULL and it remains NULL until a valid scope
line is parsed.

This feature remains unused in the HAProxy configuration file and
undocumented. However, it will be used during SPOE configuration parsing.

8 years agoMINOR: cfgparse: Add functions to backup and restore registered sections
Christopher Faulet [Wed, 26 Oct 2016 09:09:44 +0000 (11:09 +0200)] 
MINOR: cfgparse: Add functions to backup and restore registered sections

This feature will be used by the stream processing offload engine (SPOE) to
parse dedicated configuration files without mixing HAProxy sections with SPOE
sections.

So, here we can back up all sections known by HAProxy, unregister all of them
and add new ones, dedicted to the SPOE. Once the SPOE configuration file parsed,
we can roll back all changes by restoring HAProxy sections.

8 years agoMINOR: flt_trace: Add hexdump option to dump forwarded data
Christopher Faulet [Mon, 31 Oct 2016 10:27:21 +0000 (11:27 +0100)] 
MINOR: flt_trace: Add hexdump option to dump forwarded data

This is pretty verbose, but it can be handy to have it in HAProxy.

8 years agoMINOR: filters: Remove backend filters attached to a stream only for HTTP streams
Christopher Faulet [Mon, 31 Oct 2016 10:22:37 +0000 (11:22 +0100)] 
MINOR: filters: Remove backend filters attached to a stream only for HTTP streams

Now, for TCP streams, backend filters are released when the stream is
destroyed. But, for HTTP streams, these filters are released when the
transaction analyze ends, in flt_end_analyze callback.

8 years agoMINOR: filters: Call stream_set_backend callbacks before updating backend stats
Christopher Faulet [Tue, 21 Jun 2016 09:54:52 +0000 (11:54 +0200)] 
MINOR: filters: Call stream_set_backend callbacks before updating backend stats

So if an internal error is returned, the number of cumulated connections on the
backend is not incremented.

8 years agoMINOR: filters: Update filters documentation accordingly to recent changes
Christopher Faulet [Tue, 21 Jun 2016 09:50:49 +0000 (11:50 +0200)] 
MINOR: filters: Update filters documentation accordingly to recent changes

8 years agoMEDIUM: filters: Add attch/detach and stream_set_backend callbacks
Christopher Faulet [Tue, 21 Jun 2016 09:42:37 +0000 (11:42 +0200)] 
MEDIUM: filters: Add attch/detach and stream_set_backend callbacks

New callbacks have been added to handle creation and destruction of filter
instances:

* 'attach' callback is called after a filter instance creation, when it is
  attached to a stream. This happens when the stream is started for filters
  defined on the stream's frontend and when the backend is set for filters
  declared on the stream's backend. It is possible to ignore the filter, if
  needed, by returning 0. This could be useful to have conditional filtering.

* 'detach' callback is called when a filter instance is detached from a stream,
  before its destruction. This happens when the stream is stopped for filters
  defined on the stream's frontend and when the analyze ends for filters defined
  on the stream's backend.

In addition, the callback 'stream_set_backend' has been added to know when a
backend is set for a stream. It is only called when the frontend and the backend
are not the same. And it is called for all filters attached to a stream
(frontend and backend).

Finally, the TRACE filter has been updated.

8 years agoCLEANUP: remove last references to 'ruleset' section
Christopher Faulet [Wed, 26 Oct 2016 09:06:28 +0000 (11:06 +0200)] 
CLEANUP: remove last references to 'ruleset' section

8 years agoBUG: vars: Fix 'set-var' converter because of a typo
Christopher Faulet [Wed, 9 Nov 2016 15:15:32 +0000 (16:15 +0100)] 
BUG: vars: Fix 'set-var' converter because of a typo

The 'set-var' converter uses function smp_conv_store (vars.c). In this function,
we should use the first argument (index 0) to retrieve the variable name and its
scope. But because of a typo, we get the scope of the second argument (index
1). In this case, there is no second argument. So the scope used was always 0
(SCOPE_SESS), always setting the variable in the session scope.

So, due to this bug, this rules

  tcp-request content accept if { src,set-var(txn.foo) -m found }

always set the variable 'sess.foo' instead of 'txn.foo'.

8 years agoMEDIUM: server: do not restrict anymore usage of IP address from the state file
Willy Tarreau [Wed, 9 Nov 2016 13:54:53 +0000 (14:54 +0100)] 
MEDIUM: server: do not restrict anymore usage of IP address from the state file

Now that it is possible to decide whether we prefer to use libc or the
state file to resolve the server's IP address and it is possible to change
a server's IP address at run time on the CLI, let's not restrict the reuse
of the address from the state file anymore to the DNS only.

The impact is that by default the state file will be considered first
(which matches its purpose) and only then the libc. This way any address
change performed at run time over the CLI will be preserved regardless
of DNS usage or not.

8 years agoMINOR: init: add -dr to ignore server address resolution failures
Willy Tarreau [Mon, 7 Nov 2016 20:03:16 +0000 (21:03 +0100)] 
MINOR: init: add -dr to ignore server address resolution failures

It is very common when validating a configuration out of production not to
have access to the same resolvers and to fail on server address resolution,
making it difficult to test a configuration. This option simply appends the
"none" method to the list of address resolution methods for all servers,
ensuring that even if the libc fails to resolve an address, the startup
sequence is not interrupted.

8 years agoDOC: add some documentation for the "init-addr" server keyword
Willy Tarreau [Mon, 7 Nov 2016 18:42:35 +0000 (19:42 +0100)] 
DOC: add some documentation for the "init-addr" server keyword

All 4 new values were documented at once.

8 years agoMINOR: server: add support for explicit numeric address in init-addr
Willy Tarreau [Wed, 2 Nov 2016 14:05:56 +0000 (15:05 +0100)] 
MINOR: server: add support for explicit numeric address in init-addr

This will allow a server to automatically fall back to an explicit numeric
IP address when all other methods fail. The address is simply specified in
the address list.

8 years agoMEDIUM: server: make libc resolution failure non-fatal
Willy Tarreau [Mon, 7 Nov 2016 18:19:22 +0000 (19:19 +0100)] 
MEDIUM: server: make libc resolution failure non-fatal

Now that we have "init-addr none", it becomes possible to recover on
libc resolver's failures. Thus it's preferable not to alert nor fail
at the moment the libc is called, and instead process the failure at
the end of the list. This allows "none" to be set after libc to
provide a smooth fallback in case of resolver issues.

8 years agoMINOR: server: implement init-addr none
Willy Tarreau [Fri, 4 Nov 2016 14:17:58 +0000 (15:17 +0100)] 
MINOR: server: implement init-addr none

The server is put into the "no address" maintenance state in this case.

8 years agoMEDIUM: server: make use of init-addr
Willy Tarreau [Fri, 4 Nov 2016 14:10:17 +0000 (15:10 +0100)] 
MEDIUM: server: make use of init-addr

It is now supported. If not set, we default to the legacy methods list
which is "last,libc".

8 years agoMEDIUM: server: add a new init-addr server line setting
Baptiste Assmann [Wed, 21 Sep 2016 18:26:16 +0000 (20:26 +0200)] 
MEDIUM: server: add a new init-addr server line setting

This new setting supports a comma-delimited list of methods used to
resolve the server's FQDN to an IP address. Currently supported methods
are "libc" (use the regular libc's resolver) and "last" (use the last
known valid address found in the state file).

The list is implemented in a 32-bit integer, because each init-addr
method only requires 3 bits. The last one must always be SRV_IADDR_END
(0), allowing to store up to 10 methods in a single 32 bit integer.

Note: the doc is provided at the end of this series.

8 years agoMEDIUM: cli: leave the RMAINT state when setting an IP address on the CLI
Willy Tarreau [Fri, 4 Nov 2016 17:21:32 +0000 (18:21 +0100)] 
MEDIUM: cli: leave the RMAINT state when setting an IP address on the CLI

The RMAINT state happens when a server doesn't get a valid DNS response
past the hold time. If the address is forced on the CLI, we must use it
and leave the RMAINT state.

8 years agoMAJOR: dns: runtime resolution can change server admin state
Baptiste Assmann [Wed, 2 Nov 2016 21:58:18 +0000 (22:58 +0100)] 
MAJOR: dns: runtime resolution can change server admin state

WARNING: this is a MAJOR (and disruptive) change with previous HAProxy's
behavior: before, HAProxy never ever used to change a server administrative
status when the DNS resolution failed at run time.

This patch gives HAProxy the ability to change the administrative status
of a server to MAINT (RMAINT actually) when an error is encountered for
a period longer than its own allowed by the corresponding 'hold'
parameter.

IE if the configuration sets "hold nx 10s" and a server's hostname
points to a NX for more than 10s, then the server will be set to RMAINT,
hence in MAINTENANCE mode.

8 years agoMINOR: dns: implement extra 'hold' timers.
Baptiste Assmann [Wed, 2 Nov 2016 21:23:31 +0000 (22:23 +0100)] 
MINOR: dns: implement extra 'hold' timers.

This adds new "hold" timers : nx, refused, timeout, other. This timers
will be used to tell HAProxy to keep an erroneous response as valid for
the corresponding period. For now they're only configured, not enforced.

8 years agoMINOR: server: make srv_set_admin_state() capable of telling why this happens
Willy Tarreau [Mon, 7 Nov 2016 14:53:43 +0000 (15:53 +0100)] 
MINOR: server: make srv_set_admin_state() capable of telling why this happens

It will be important to help debugging some DNS resolution issues to
know why a server was marked down, so let's make  the function support
a 3rd argument with an indication of the reason. Passing NULL will keep
the message as-is.

8 years agoMINOR: stats: indicate it when a server is down due to resolution
Willy Tarreau [Wed, 9 Nov 2016 13:45:51 +0000 (14:45 +0100)] 
MINOR: stats: indicate it when a server is down due to resolution

The server's state is now "MAINT (resolution)" just like we also have
"MAINT (via x/y)" when servers are tracked. The HTML stats page reports
"resolution" in the checks field similarly to what is done for the "via"
entry.

8 years agoMINOR: server: indicate in the logs when RMAINT is cleared
Willy Tarreau [Mon, 7 Nov 2016 14:42:33 +0000 (15:42 +0100)] 
MINOR: server: indicate in the logs when RMAINT is cleared

It's important to report in the server state change logs that RMAINT was
cleared, as it's not the regular maintenance mode, it's specific to name
resolution, and it's important to report the new state (which can be DRAIN
or READY).

8 years agoMINOR: new srv_admin flag: SRV_ADMF_RMAINT
Baptiste Assmann [Wed, 2 Nov 2016 20:31:27 +0000 (21:31 +0100)] 
MINOR: new srv_admin flag: SRV_ADMF_RMAINT

This flag has to be set when an IP address resolution fails (either
using libc at start up or using HAProxy's runtime resolver). This will
automatically trigger the administrative status "MAINT", through the
global mask SRV_ADMF_MAINT.

8 years agoMAJOR: server: postpone address resolution
Baptiste Assmann [Wed, 2 Nov 2016 14:34:05 +0000 (15:34 +0100)] 
MAJOR: server: postpone address resolution

Server addresses are not resolved anymore upon the first pass so that we
don't fail if an address cannot be resolved by the libc. Instead they are
processed all at once after the configuration is fully loaded, by the new
function srv_init_addr(). This function only acts on the server's address
if this address uses an FQDN, which appears in server->hostname.

For now the function does two things, to followup with HAProxy's historical
default behavior:

  1. apply server IP address found in server-state file if runtime DNS
     resolution is enabled for this server

  2. use the DNS resolver provided by the libc

If none of the 2 options above can find an IP address, then an error is
returned.

All of this will be needed to support the new server parameter "init-addr".
For now, the biggest user-visible change is that all server resolution errors
are dumped at once instead of causing a startup failure one by one.

8 years agoMINOR: init: move apply_server_state in haproxy.c before MODE_CHECK
Baptiste Assmann [Wed, 2 Nov 2016 14:33:15 +0000 (15:33 +0100)] 
MINOR: init: move apply_server_state in haproxy.c before MODE_CHECK

Currently, the function which applies server states provided by the
"old" process is applied after configuration sanity check. This results
in the impossibility to check the validity of the state file during a
regular config check, implying a full start is required, which can be
a problem sometimes.

This patch moves the loading of server_state file before MODE_CHECK.

8 years agoMEDIUM: tools: make str2sa_range() return the FQDN even when not resolving
Willy Tarreau [Wed, 2 Nov 2016 21:27:10 +0000 (22:27 +0100)] 
MEDIUM: tools: make str2sa_range() return the FQDN even when not resolving

This will be needed to later postpone server address resolution. We need the
FQDN even when it doesn't resolve. The caller then needs to check if fqdn was
set when resolve is null to detect that the address couldn't be parsed and
needs later resolution.

8 years agoMINOR: stream: make option contstats usable again
Willy Tarreau [Tue, 8 Nov 2016 21:03:00 +0000 (22:03 +0100)] 
MINOR: stream: make option contstats usable again

Quite a lot of people have been complaining about option contstats not
working correctly anymore since about 1.4. The reason was that one reason
for the significant performance boost between 1.3 and 1.4 was the ability
to forward data between a server and a client without waking up the stream
manager. And we couldn't afford to force sessions to constantly wake it
up given that most of the people interested in contstats are also those
interested in high performance transmission.

An idea was experimented with in the past, consisting in limiting the
amount of transmissible data before waking it up, but it was not usable
on slow connections (eg: FTP over modem lines, RDP, SSH) as stats would
be updated too rarely if at all, so that idea was dropped.

During a discussion today another idea came up : ensure that stats are
updated once in a while, since it's the only thing that matters. It
happens that we have the request channel's analyse_exp timeout that is
used to wake the stream up after a configured delay, and that by
definition this timeout is not used when there's no more analyser
(otherwise the stream would wake up and the stats would be updated).

Thus here the idea is to reuse this timeout when there's no analyser
and set it to now+5 seconds so that a stream wakes up at least once
every 5 seconds to update its stats. It should be short enough to
provide smooth traffic graphs and to allow to debug outputs of "show
sess" more easily without inflicting too much load even for very large
number of concurrent connections.

This patch is simple enough and safe enough to be backportable to 1.6
if there is some demand.

8 years agoMEDIUM: ssl: Add support for OpenSSL 1.1.0
Dirkjan Bussink [Mon, 29 Aug 2016 11:26:37 +0000 (13:26 +0200)] 
MEDIUM: ssl: Add support for OpenSSL 1.1.0

In the last release a lot of the structures have become opaque for an
end user. This means the code using these needs to be changed to use the
proper functions to interact with these structures instead of trying to
manipulate them directly.

This does not fix any deprecations yet that are part of 1.1.0, it only
ensures that it can be compiled against that version and is still
compatible with older ones.

[wt: openssl-0.9.8 doesn't build with it, there are conflicts on certain
     function prototypes which we declare as inline here and which are
     defined differently there. But openssl-0.9.8 is not supported anymore
     so probably it's OK to go without it for now and we'll see later if
     some users still need it. Emeric has reviewed this change and didn't
     spot anything obvious which requires special care. Let's try it for
     real now]

8 years agoCLEANUP: wurfl: reduce exposure in the rest of the code
Willy Tarreau [Tue, 8 Nov 2016 17:47:25 +0000 (18:47 +0100)] 
CLEANUP: wurfl: reduce exposure in the rest of the code

The only reason wurfl/wurfl.h was needed outside of wurfl.c was to expose
wurfl_handle which is a pointer to a structure, referenced by global.h.
By just storing a void* there instead, we can confine all wurfl code to
wurfl.c, which is really nice.

8 years agoDOC: move the device detection modules documentation to their own files
Willy Tarreau [Tue, 8 Nov 2016 13:57:29 +0000 (14:57 +0100)] 
DOC: move the device detection modules documentation to their own files

Both DeviceAtlas and 51Degrees used to put their building instructions
in the README, representing more than 1/3 of it. It's better to let the
README focus on generic stuff and building procedure and move the DD
docs to their own files.

8 years agoMEDIUM: wurfl: add Scientiamobile WURFL device detection module
scientiamobile [Fri, 4 Nov 2016 09:55:08 +0000 (10:55 +0100)] 
MEDIUM: wurfl: add Scientiamobile WURFL device detection module

WURFL is a high-performance and low-memory footprint mobile device
detection software component that can quickly and accurately detect
over 500 capabilities of visiting devices. It can differentiate between
portable mobile devices, desktop devices, SmartTVs and any other types
of devices on which a web browser can be installed.

In order to add WURFL device detection support, you would need to
download Scientiamobile InFuze C API and install it on your system.
Refer to www.scientiamobile.com to obtain a valid InFuze license.

Any useful information on how to configure HAProxy working with WURFL
may be found in:

  doc/WURFL-device-detection.txt
  doc/configuration.txt
  examples/wurfl-example.cfg

Please find more information about WURFL device detection API detection
at https://docs.scientiamobile.com/documentation/infuze/infuze-c-api-user-guide

8 years agoBUG/MEDIUM: servers: properly propagate the maintenance states during startup
Willy Tarreau [Thu, 3 Nov 2016 18:22:19 +0000 (19:22 +0100)] 
BUG/MEDIUM: servers: properly propagate the maintenance states during startup

Right now there is an issue with the way the maintenance flags are
propagated upon startup. They are not propagate, just copied from the
tracked server. This implies that depending on the server's order, some
tracking servers may not be marked down. For example this configuration
does not work as expected :

        server s1 1.1.1.1:8000 track s2
        server s2 1.1.1.1:8000 track s3
        server s3 1.1.1.1:8000 track s4
        server s4 wtap:8000 check inter 1s disabled

It results in s1/s2 being up, and s3/s4 being down, while all of them
should be down.

The only clean way to process this is to run through all "root" servers
(those not tracking any other server), and to propagate their state down
to all their trackers. This is the same algorithm used to propagate the
state changes. It has to be done both to compute the IDRAIN flag and the
IMAINT flag. However, doing so requires that tracking servers are not
marked as inherited maintenance anymore while parsing the configuration
(and given that it is wrong, better drop it).

This fix also addresses another side effect of the bug above which is
that the IDRAIN/IMAINT flags are stored in the state files, and if
restored while the tracked server doesn't have the equivalent flag,
the servers may end up in a situation where it's impossible to remove
these flags. For example in the configuration above, after removing
"disabled" on server s4, the other servers would have remained down,
and not anymore with this fix. Similarly, the combination of IMAINT
or IDRAIN with their respective forced modes was not accepted on
reload, which is wrong as well.

This bug has been present at least since 1.5, maybe even 1.4 (it came
with tracking support). The fix needs to be backported there, though
the srv-state parts are irrelevant.

This commit relies on previous patch to silence warnings on startup.

8 years agoMINOR: server: do not emit warnings/logs/alerts on server state changes at boot
Willy Tarreau [Thu, 3 Nov 2016 18:42:36 +0000 (19:42 +0100)] 
MINOR: server: do not emit warnings/logs/alerts on server state changes at boot

We'll have to use srv_set_admin_flag() to propagate some server flags
during the startup, and we don't want the resulting actions to cause
warnings, logs nor e-mail alerts to be generated since we're just applying
the config or a state file. So let's condition these notifications to the
fact that we're starting.

8 years agoBUG/MINOR: srv-state: allow to have both CMAINT and FDRAIN flags
Willy Tarreau [Thu, 3 Nov 2016 17:33:25 +0000 (18:33 +0100)] 
BUG/MINOR: srv-state: allow to have both CMAINT and FDRAIN flags

CMAINT indicates that the server was *initially* disabled in the
configuration via the "disabled" keyword. FDRAIN indicates that the
server was switched to the DRAIN state from the CLI or the agent.
This it's perfectly valid to have both of them in the state file,
so the parser must not reject this combination.

This fix must be backported to 1.6.

8 years agoBUG/MEDIUM: srv-state: properly restore the DRAIN state
Willy Tarreau [Thu, 3 Nov 2016 17:19:49 +0000 (18:19 +0100)] 
BUG/MEDIUM: srv-state: properly restore the DRAIN state

There were seveal reports about the DRAIN state not being properly
restored upon reload.

It happens that the condition in the code does exactly the opposite
of what the comment says, and the comment is right so the code is
wrong.

It's worth noting that the conditions are complex here due to the 2
available methods to set the drain state (CLI/agent, and config's
weight). To paraphrase the updated comment in the code, there are
two possible reasons for FDRAIN to have been present :
  - previous config weight was zero
  - "set server b/s drain" was sent to the CLI

In the first case, we simply want to drop this drain state if the new
weight is not zero anymore, meaning the administrator has intentionally
turned the weight back to a positive value to enable the server again
after an operation. In the second case, the drain state was forced on
the CLI regardless of the config's weight so we don't want a change to
the config weight to lose this status. What this means is :
  - if previous weight was 0 and new one is >0, drop the DRAIN state.
  - if the previous weight was >0, keep it.

This fix must be backported to 1.6.

8 years agoOPTIM: http: optimize lookup of comma and quote in header values
Willy Tarreau [Sat, 5 Nov 2016 17:23:38 +0000 (18:23 +0100)] 
OPTIM: http: optimize lookup of comma and quote in header values

http_find_header2() relies on find_hdr_value_end() to find the comma
delimiting a header field value, which also properly handles double
quotes and backslashes within quotes. In fact double quotes are very
rare, and commas happen once every multiple characters, especially
with cookies where a full block can be found at once. So it makes
sense to optimize this function to speed up the lookup of the first
block before the quote.

This change increases the performance from 212k to 217k req/s when
requests contain a 1kB cookie (+2.5%). We don't care about going
back into the fast parser after the first quote, as it may
needlessly make the parser more complex for very marginal gains.

8 years agoOPTIM: http: improve parsing performance of long URIs
Willy Tarreau [Sat, 5 Nov 2016 16:52:06 +0000 (17:52 +0100)] 
OPTIM: http: improve parsing performance of long URIs

Searching the trailing space in long URIs takes some time. This can
happen especially on static files and some blogs. By skipping valid
character ranges by 32-bit blocks, it's possible to increase the
HTTP performance from 212k to 216k req/s on requests features a
100-character URI, which is an increase of 2%. This is done for
architectures supporting unaligned accesses (x86_64, x86, armv7a).
There's only a 32-bit version because URIs are rarely long and very
often short, so it's more efficient to limit the systematic overhead
than to try to optimize for the rarest requests.

8 years agoOPTIM: http: improve parsing performance of long header lines
Willy Tarreau [Sat, 5 Nov 2016 16:35:40 +0000 (17:35 +0100)] 
OPTIM: http: improve parsing performance of long header lines

A performance test with 1kB cookies was capping at 194k req/s. After
implementing multi-byte skipping, the performance increased to 212k req/s,
or 9.2% faster. This patch implements this for architectures supporting
unaligned accesses (x86_64, x86, armv7a). Maybe other architectures can
benefit from this but they were not tested yet.

8 years agoOPTIM: http: move all http character classs tables into a single one
Willy Tarreau [Sat, 5 Nov 2016 14:50:20 +0000 (15:50 +0100)] 
OPTIM: http: move all http character classs tables into a single one

We used to have 7 different character classes, each was 256 bytes long,
resulting in almost 2kB being used in the L1 cache. It's as cheap to
test a bit than to check the byte is not null, so let's store a 7-bit
composite value and check for the respective bits there instead.

The executable is now 4 kB smaller and the performance on small
objects increased by about 1% to 222k requests/second with a config
involving 4 http-request rules including 1 header lookup, one header
replacement, and 2 variable assignments.

8 years agoCLEANUP: tools: make ipcpy() preserve the original port
Willy Tarreau [Fri, 4 Nov 2016 17:47:01 +0000 (18:47 +0100)] 
CLEANUP: tools: make ipcpy() preserve the original port

ipcpy() is used to replace an IP address with another one, but it
doesn't preserve the original port so all callers have to do it
manually while it's trivial to do there. Better do it inside the
function.

8 years agoMEDIUM: tools: make str2ip2() preserve existing ports
Willy Tarreau [Wed, 2 Nov 2016 21:37:03 +0000 (22:37 +0100)] 
MEDIUM: tools: make str2ip2() preserve existing ports

Often we need to call str2ip2() on an address which already contains a
port without replacing it, so let's ensure we preserve it even if the
family changes.