]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
7 years agoMINOR: cli: make "show fd" report the mux and mux_ctx pointers when available
Willy Tarreau [Wed, 28 Mar 2018 16:41:30 +0000 (18:41 +0200)] 
MINOR: cli: make "show fd" report the mux and mux_ctx pointers when available

This is handy to quickly distinguish H2 connections as well as to easily
access the h2c context. It could be backported to 1.8 to help during
troubleshooting sessions.

7 years agoMINOR: cli/threads: make "show fd" report thread_sync_io_handler instead of "unknown"
Willy Tarreau [Wed, 28 Mar 2018 16:06:47 +0000 (18:06 +0200)] 
MINOR: cli/threads: make "show fd" report thread_sync_io_handler instead of "unknown"

The output was confusing when the sync point's dummy handler was shown.

This patch should be backported to 1.8 to help with troubleshooting.

7 years agoBUG/MINOR: hpack: fix harmless use of uninitialized value in hpack_dht_insert
Willy Tarreau [Tue, 27 Mar 2018 13:06:02 +0000 (15:06 +0200)] 
BUG/MINOR: hpack: fix harmless use of uninitialized value in hpack_dht_insert

A warning is reported here by valgrind on first pass in hpack_dht_insert().
The cause is that the not-yet-initialized dht->head is checked in
hpack_dht_get_tail(), though the result is not used, making it have
no impact. At the very least it confuses valgrind, and maybe it makes
it harder for gcc to optimize the code path. Let's move the variable
initialization around to shut it up. Thanks to Olivier for reporting
this one.

This fix may be backported to 1.8 at least to make valgrind usage less
painful.

7 years agoMINOR: lua: allow socket api settimeout to accept integers, float, and doubles
Mark Lakes [Tue, 27 Mar 2018 07:48:06 +0000 (09:48 +0200)] 
MINOR: lua: allow socket api settimeout to accept integers, float, and doubles

Instead of hlua_socket_settimeout() accepting only integers, allow user
to specify float and double as well. Convert to milliseconds much like
cli_parse_set_timeout but also sanity check the value.

http://w3.impa.br/~diego/software/luasocket/tcp.html#settimeout

T. Fournier edit:

The main goal is to keep compatibility with the LuaSocket API. This
API only accept seconds, so using a float to specify milliseconds is
an acceptable way.

Update doc.

7 years agoBUILD/MINOR: fix build when USE_THREAD is not defined
Ilya Shipitsin [Sat, 24 Mar 2018 12:17:32 +0000 (17:17 +0500)] 
BUILD/MINOR: fix build when USE_THREAD is not defined

src/queue.o: In function `pendconn_redistribute':
/home/ilia/haproxy/src/queue.c:272: undefined reference to `thread_want_sync'
src/queue.o: In function `pendconn_grab_from_px':
/home/ilia/haproxy/src/queue.c:311: undefined reference to `thread_want_sync'
src/queue.o: In function `process_srv_queue':
/home/ilia/haproxy/src/queue.c:184: undefined reference to `thread_want_sync'
collect2: error: ld returned 1 exit status
make: *** [Makefile:900: haproxy] Error 1

To be backported to 1.8.

7 years agoCLEANUP: lua: typo fix in comments
Mark Lakes [Mon, 29 Jan 2018 22:38:40 +0000 (14:38 -0800)] 
CLEANUP: lua: typo fix in comments

Some typo fixes in comments.

7 years agoBUG/MINOR: lua funtion hlua_socket_settimeout don't check negative values
Thierry Fournier [Thu, 8 Mar 2018 08:59:02 +0000 (09:59 +0100)] 
BUG/MINOR: lua funtion hlua_socket_settimeout don't check negative values

Negatives timeouts doesn't have sense. A negative timeout doesn't cause
a crash, but the connection expires before the system try to extablish it.

This patch should be backported in all versions from 1.6

7 years agoBUG/MINOR: lua: the function returns anything
Thierry Fournier [Thu, 8 Mar 2018 08:54:32 +0000 (09:54 +0100)] 
BUG/MINOR: lua: the function returns anything

The output of these function indicates that one element is pushed in
the stack, but no element is set in the stack. Actually, if anyone
read the value returned by this function, is gets "something"
present in the stack.

This patch is a complement of these one: 119a5f10e47f3507e58116

The LuaSocket documentation tell anything about the returned value,
but the effective code set an integer of value one.

   https://github.com/diegonehab/luasocket/blob/316a9455b9cb4637fe6e62b20fbe05f5141fec54/src/timeout.c#L172

Thanks to Tim for the bug report.

This patch should be backported in all version from 1.6

7 years agoCLEANUP: map, stream: remove duplicate code in src/map.c, src/stream.c
Ilya Shipitsin [Fri, 23 Mar 2018 12:41:48 +0000 (17:41 +0500)] 
CLEANUP: map, stream: remove duplicate code in src/map.c, src/stream.c

issue was identified by cppcheck

[src/map.c:372] -> [src/map.c:376]: (warning) Variable 'appctx->st2' is reassigned a value before the old one has been used. 'break;' missing?
[src/map.c:433] -> [src/map.c:437]: (warning) Variable 'appctx->st2' is reassigned a value before the old one has been used. 'break;' missing?
[src/map.c:555] -> [src/map.c:559]: (warning) Variable 'appctx->st2' is reassigned a value before the old one has been used. 'break;' missing?
[src/stream.c:3264] -> [src/stream.c:3268]: (warning) Variable 'appctx->st2' is reassigned a value before the old one has been used. 'break;' missing?

Signed-off-by: Ilya Shipitsin <chipitsine@gmail.com>
7 years agoBUG/MINOR: listener: Don't decrease actconn twice when a new session is rejected
Christopher Faulet [Fri, 23 Mar 2018 14:11:55 +0000 (15:11 +0100)] 
BUG/MINOR: listener: Don't decrease actconn twice when a new session is rejected

When a freshly created session is rejected, for any reason, during the accept in
the function "session_accept_fd", the variable "actconn" is decreased twice. The
first time when the rejected session is released, then in the function
"listener_accpect", because of the failure. So it is possible to have an
negative value for actconn. Note that, in this case, we will also have a negatve
value for the current number of connections on the listener rejecting the
session (actconn and l->nbconn are in/decreased in same time).

It is easy to reproduce the bug with this small configuration:

  global
      stats socket /tmp/haproxy

  listen test
      bind *:12345
      tcp-request connection reject if TRUE

A "show info" on the stat socket, after a connection attempt, will show a very
high value (the unsigned representation of -1).

To fix the bug, if the function "session_accept_fd" returns an error, it
decrements the right counters and "listener_accpect" leaves them untouched.

This patch must be backported in 1.8.

7 years agoBUG/MINOR: h2: ensure we can never send an RST_STREAM in response to an RST_STREAM
Willy Tarreau [Thu, 22 Mar 2018 16:37:05 +0000 (17:37 +0100)] 
BUG/MINOR: h2: ensure we can never send an RST_STREAM in response to an RST_STREAM

There are some corner cases where this could happen by accident. Since
the spec explicitly forbids this (RFC7540#5.4.2), let's add a test in
the two only functions which make the RST to avoid this. Thanks to user
klzgrad for reporting this problem. Usually it is expected to be harmless
but may result in browsers issuing a warning.

This fix must be backported to 1.8.

7 years agoBUG/MEDIUM: h2: properly account for DATA padding in flow control
Willy Tarreau [Thu, 22 Mar 2018 15:53:12 +0000 (16:53 +0100)] 
BUG/MEDIUM: h2: properly account for DATA padding in flow control

Recent fixes made to process partial frames broke the flow control on
DATA frames, as the padding is not considered anymore, only the actual
data is. Let's simply take account of the padding once the transfer
ends. The probability to meet this bug is low because, when used, padding
is small and it can require a large number of padded transfers before the
window is completely depleted.

Thanks to user klzgrad for reporting this bug and confirming the fix.

This fix must be backported to 1.8.

7 years agoMINOR: samples: add crc32c converter
Emmanuel Hocdet [Wed, 21 Mar 2018 10:19:01 +0000 (11:19 +0100)] 
MINOR: samples: add crc32c converter

This patch adds the support of CRC32c (rfc4960).

7 years agoREORG: compact "struct server"
Emmanuel Hocdet [Mon, 19 Mar 2018 17:14:02 +0000 (18:14 +0100)] 
REORG: compact "struct server"

Move use_ssl (bool value) in "struct server" hole.

7 years agoMINOR: accept-proxy: support proxy protocol v2 CRC32c checksum
Emmanuel Hocdet [Mon, 5 Feb 2018 15:23:23 +0000 (16:23 +0100)] 
MINOR: accept-proxy: support proxy protocol v2 CRC32c checksum

When proxy protocol v2 CRC32c tlv is received, check it before accept
connection (as describe in "doc/proxy-protocol.txt").

7 years agoMINOR: proxy-v2-options: add crc32c
Emmanuel Hocdet [Mon, 5 Feb 2018 14:26:43 +0000 (15:26 +0100)] 
MINOR: proxy-v2-options: add crc32c

This patch add option crc32c (PP2_TYPE_CRC32C) to proxy protocol v2.
It compute the checksum of proxy protocol v2 header as describe in
"doc/proxy-protocol.txt".

7 years agoMINOR: hash: add new function hash_crc32c
Emmanuel Hocdet [Mon, 5 Feb 2018 14:23:39 +0000 (15:23 +0100)] 
MINOR: hash: add new function hash_crc32c

This function will be used to perform CRC32c computations. This is
required to compute proxy protocol v2 CRC32C tlv (PP2_TYPE_CRC32C).

7 years agoDOC: log: more than 2 log servers are allowed
Cyril Bonté [Tue, 20 Mar 2018 22:30:27 +0000 (23:30 +0100)] 
DOC: log: more than 2 log servers are allowed

Since commit 0f99e3497, loggers are not limited to 2 instances anymore.

7 years agoBUG/MEDIUM: fd/threads: ensure the fdcache_mask always reflects the cache contents
Willy Tarreau [Tue, 20 Mar 2018 18:06:52 +0000 (19:06 +0100)] 
BUG/MEDIUM: fd/threads: ensure the fdcache_mask always reflects the cache contents

Commit 4815c8c ("MAJOR: fd/threads: Make the fdcache mostly lockless.")
made the fd cache lockless, but after a few iterations, a subtle part was
lost, consisting in setting the bit on the fd_cache_mask immediately when
adding an event. Now it was done only when the cache started to process
events, but the problem it causes is that fd_cache_mask isn't reliable
anymore as an indicator of presence of events to be processed with no
delay outside of fd_process_cached_events(). This results in some spurious
delays when processing inter-thread wakeups between tasks. Just restoring
the flag when the event is added is enough to fix the problem.

Kudos to Christopher for spotting this one!

No backport is needed as this is only in the development version.

7 years agoBUILD/BUG: enable -fno-strict-overflow by default
Willy Tarreau [Tue, 20 Mar 2018 15:46:46 +0000 (16:46 +0100)] 
BUILD/BUG: enable -fno-strict-overflow by default

Some time ago, integer overflows detection stopped working in the timer
code on recent compliers and were addressed by commit 73bdb32 ("BUG/MAJOR:
Use -fwrapv."). By then it was thought that -fno-strict-overflow was not
needed as implied, but it resulted from a misinterpretation of the doc,
as this one is still needed to disable pointer overflow optimization that
is automatically enabled at -O2/-O3/-Os.

Unfortunately the compiler happily removes overflow checks without the
slightest warning so it's not trivial to guess the extent of this issue
without comparing the emitted asm code. By checking the emitted assembly
code with and without the option, it was found that the only affected
location was the reported one, in ssl_sock_parse_clienthello(), where
the test can never fail on any system where the highest userland pointer
is at least 64kB away from wrapping (ie all 32/64 bit OS in field), so
there it is harmless.

This patch must be backported to all maintained versions.

Special thanks to Ilya Shipitsin for reporting this issue.

7 years agoMINOR: log: stop emitting alerts when it's not possible to write on the socket
Willy Tarreau [Tue, 20 Mar 2018 10:17:29 +0000 (11:17 +0100)] 
MINOR: log: stop emitting alerts when it's not possible to write on the socket

This is a recurring pain when using certain unix domain sockets or when
sending to temporarily unroutable addresses, if the process remains in
the foreground, the console is full of error which it's impossible to
do anything about. It's even worse when the process is remote, or when
run from a serial console which will slow the whole process down. Let's
send them only once now to warn about a possible config issue, and not
pollute the system nor slow everything down.

7 years agoBUG/MEDIUM: threads/queue: wake up other threads upon dequeue
Christopher Faulet [Mon, 19 Mar 2018 14:22:09 +0000 (15:22 +0100)] 
BUG/MEDIUM: threads/queue: wake up other threads upon dequeue

The previous patch about queues (5cd4bbd7a "BUG/MAJOR: threads/queue: Fix
thread-safety issues on the queues management") revealed a performance drop when
multithreading is enabled (nbthread > 1). This happens when pending connections
handled by other theads are dequeued. If these other threads are blocked in the
poller, we have to wait the poller's timeout (or any I/O event) to process the
dequeued connections.

To fix the problem, at least temporarly, we "wake up" the threads by requesting
a synchronization. This may seem a bit overkill to use the sync point to do a
wakeup on threads, but it fixes this performance issue. So we can now think
calmly on the good way to address this kind of issues.

This patch should be backported in 1.8 with the commit 5cd4bbd7a ("BUG/MAJOR:
threads/queue: Fix thread-safety issues on the queues management").

7 years agoBUG/MINOR: tcp-check: use the server's service port as a fallback
Baptiste Assmann [Mon, 19 Mar 2018 11:22:41 +0000 (12:22 +0100)] 
BUG/MINOR: tcp-check: use the server's service port as a fallback

When running tcp-check scripts, one must ensure we can establish a tcp
connection first.
When doing this action, HAProxy needs a TCP port configured either on
the server or on the check itself or on the connect rule itself.
For some reasons, the connect code did not evaluate the service port on
the server structure...

this patch fixes this error.

Backport status: 1.8

7 years agoBUG/MEDIUM: tcp-check: single connect rule can't detect DOWN servers
Baptiste Assmann [Thu, 1 Mar 2018 20:49:01 +0000 (21:49 +0100)] 
BUG/MEDIUM: tcp-check: single connect rule can't detect DOWN servers

When tcpcheck is used to do TCP port monitoring only and the script is
composed by a single "tcp-check connect" rule (whatever port and ssl
options enabled), then the server can't be seen as DOWN.
Simple configuration to reproduce:

  backend b
    [...]
    option tcp-check
    tcp-check connect
    server s1 127.0.0.1:22 check

The main reason for this issue is that the piece of code which validates
that we're not at the end of the chained list (of rules) prevents
executing the validation of the establishment of the TCP connection.
Since validation is not executed, the rule is terminated and the report
says no errors were encountered, hence the server is UP all the time.

The workaround is simple: move the connection validation outsied the
CONNECT rule processing loop, into the main function.
That way, if the connection status is not CONNECTED, then HAProxy will
now add more time to wait for it. If the time is expired, an error is
now well reported.

Backport status: 1.8

7 years agoCLEANUP: lua/syntax: lua is a name and not an acronym
Thierry FOURNIER [Sun, 25 Feb 2018 13:32:36 +0000 (14:32 +0100)] 
CLEANUP: lua/syntax: lua is a name and not an acronym

This patch fix some first letter upercase for Lua messages.

7 years agoBUG/MINOR: lua: return bad error messages
Thierry FOURNIER [Fri, 23 Feb 2018 17:41:18 +0000 (18:41 +0100)] 
BUG/MINOR: lua: return bad error messages

The returned type is the type of the top of stack value and
not the type of the checked argument.

[wt: this can be backported to 1.8, 1.7 and 1.6]

7 years agoBUG/MINOR: spoa-example: unexpected behavior for more than 127 args
Thierry FOURNIER [Sun, 25 Feb 2018 20:33:38 +0000 (21:33 +0100)] 
BUG/MINOR: spoa-example: unexpected behavior for more than 127 args

Buf is unsigned, so nbargs will be negative for more then 127 args.

Note that I cant test this bug because I cant put sufficient args
on the configuration line. It is just detected reading code.

[wt: this can be backported to 1.8 & 1.7]

7 years agoBUILD: ssl: Fix build with OpenSSL without NPN capability
Bernard Spil [Thu, 15 Feb 2018 12:34:58 +0000 (13:34 +0100)] 
BUILD: ssl: Fix build with OpenSSL without NPN capability

OpenSSL can be built without NEXTPROTONEG support by passing
-no-npn to the configure script. This sets the
OPENSSL_NO_NEXTPROTONEG flag in opensslconf.h

Since NEXTPROTONEG is now considered deprecated, it is superseeded
by ALPN (Application Layer Protocol Next), HAProxy should allow
building withough NPN support.

7 years agoBUG/MINOR: cli: Fix a crash when sending a command with too many arguments
Aurélien Nephtali [Fri, 16 Mar 2018 09:11:06 +0000 (10:11 +0100)] 
BUG/MINOR: cli: Fix a crash when sending a command with too many arguments

This bug was introduced in 48bcfdab2 ("MEDIUM: dumpstat: make the CLI
parser understand the backslash as an escape char").

This should be backported to 1.8.

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoBUG/MINOR: cli: Ensure all command outputs end with a LF
Aurélien Nephtali [Thu, 15 Mar 2018 20:48:50 +0000 (21:48 +0100)] 
BUG/MINOR: cli: Ensure all command outputs end with a LF

Since 200b0fac ("MEDIUM: Add support for updating TLS ticket keys via
socket"), 4147b2ef ("MEDIUM: ssl: basic OCSP stapling support."),
4df59e9 ("MINOR: cli: add socket commands and config to prepend
informational messages with severity") and 654694e1 ("MEDIUM: stats/cli:
add support for "set table key" to enter values"), commands
'set ssl tls-key', 'set ssl ocsp-response', 'set severity-output' and
'set table' do not always send an extra LF at the end of their outputs.

This is required as mentioned in doc/management.txt:

"Since multiple commands may be issued at once, haproxy uses the empty
line as a delimiter to mark an end of output for each command"

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoBUG/MINOR: seemless reload: Fix crash when an interface is specified.
Olivier Houchard [Thu, 15 Mar 2018 16:48:49 +0000 (17:48 +0100)] 
BUG/MINOR: seemless reload: Fix crash when an interface is specified.

When doing a seemless reload, while receiving the sockets from the old process
the new process will die if the socket has been bound to a specific
interface.
This happens because the code that tries to parse the informations bogusly
try to set xfer_sock->namespace, while it should be setting wfer_sock->iface.

This should be backported to 1.8.

7 years agoCLEANUP: dns: remove duplicate code in src/dns.c
Ilya Shipitsin [Thu, 15 Mar 2018 11:38:38 +0000 (16:38 +0500)] 
CLEANUP: dns: remove duplicate code in src/dns.c

issue was identified by cppcheck

[src/dns.c:2037] -> [src/dns.c:2041]: (warning) Variable 'appctx->st2' is reassigned a value before the old one has been used. 'break;' missing?

7 years agoTESTS: Add a testcase for multi-port + multi-server listener issue
Philipp Kolmann [Tue, 24 Oct 2017 09:32:22 +0000 (11:32 +0200)] 
TESTS: Add a testcase for multi-port + multi-server listener issue

7 years agoBUG/MINOR: dns: don't downgrade DNS accepted payload size automatically
Baptiste Assmann [Thu, 1 Mar 2018 21:26:57 +0000 (22:26 +0100)] 
BUG/MINOR: dns: don't downgrade DNS accepted payload size automatically

Automatic downgrade of DNS accepted payload size may have undesired side
effect, which could make a backend with all servers DOWN.

After talking with Lukas on the ML, I realized this "feature" introduces
more issues that it fixes problem.
The "best" way to handle properly big responses will be to implement DNS
over TCP.

To be backported to 1.8.

7 years agoBUG/MAJOR: threads/queue: Fix thread-safety issues on the queues management
Christopher Faulet [Wed, 14 Mar 2018 15:18:06 +0000 (16:18 +0100)] 
BUG/MAJOR: threads/queue: Fix thread-safety issues on the queues management

The management of the servers and the proxies queues was not thread-safe at
all. First, the accesses to <strm>->pend_pos were not protected. So it was
possible to release it on a thread (for instance because the stream is released)
and to use it in same time on another one (because we redispatch pending
connections for a server). Then, the accesses to stream's information (flags and
target) from anywhere is forbidden. To be safe, The stream's state must always
be updated in the context of process_stream.

So to fix these issues, the queue module has been refactored. A lock has been
added in the pendconn structure. And now, when we try to dequeue a pending
connection, we start by unlinking it from the server/proxy queue and we wake up
the stream. Then, it is the stream reponsibility to really dequeue it (or
release it). This way, we are sure that only the stream can create and release
its <pend_pos> field.

However, be careful. This new implementation should be thread-safe
(hopefully...). But it is not optimal and in some situations, it could be really
slower in multi-threaded mode than in single-threaded one. The problem is that,
when we try to dequeue pending connections, we process it from the older one to
the newer one independently to the thread's affinity. So we need to wait the
other threads' wakeup to really process them. If threads are blocked in the
poller, this will add a significant latency. This problem happens when maxconn
values are very low.

This patch must be backported in 1.8.

7 years agoBUG/MEDIUM: threads/unix: Fix a deadlock when a listener is temporarily disabled
Christopher Faulet [Fri, 16 Mar 2018 09:04:47 +0000 (10:04 +0100)] 
BUG/MEDIUM: threads/unix: Fix a deadlock when a listener is temporarily disabled

When a listener is temporarily disabled, we start by locking it and then we call
.pause callback of the underlying protocol (tcp/unix). For TCP listeners, this
is not a problem. But listeners bound on an unix socket are in fact closed
instead. So .pause callback relies on unbind_listener function to do its job.

Unfortunatly, unbind_listener hold the listener's lock and then call an internal
function to unbind it. So, there is a deadlock here. This happens during a
reload. To fix the problemn, the function do_unbind_listener, which is lockless,
is now exported and is called when a listener bound on an unix socket is
temporarily disabled.

This patch must be backported in 1.8.

7 years agoBUG/MINOR: force-persist and ignore-persist only apply to backends
Cyril Bonté [Mon, 12 Mar 2018 21:02:59 +0000 (22:02 +0100)] 
BUG/MINOR: force-persist and ignore-persist only apply to backends

>From the very first day of force-persist and ignore-persist features,
they only applied to backends, except that the documentation stated it
could also be applied to frontends.

In order to make it clear, the documentation is updated and the parser
will raise a warning if the keywords are used in a frontend section.

This patch should be backported up to the 1.5 branch.

7 years agoBUG/MEDIUM: fix a 100% cpu usage with cpu-map and nbthread/nbproc
Cyril Bonté [Mon, 12 Mar 2018 20:47:39 +0000 (21:47 +0100)] 
BUG/MEDIUM: fix a 100% cpu usage with cpu-map and nbthread/nbproc

Krishna Kumar reported a 100% cpu usage with a configuration using
cpu-map and a high number of threads,

Indeed, this minimal configuration to reproduce the issue :
  global
    nbthread 40
    cpu-map auto:1/1-40 0-39

  frontend test
    bind :8000

This is due to a wrong type in a shift operator (int vs unsigned long int),
causing an endless loop while applying the cpu affinity on threads. The same
issue may also occur with nbproc under FreeBSD. This commit addresses both
cases.

This patch must be backported to 1.8.

7 years agoBUG/MINOR: cli: Fix a typo in the 'set rate-limit' usage
Aurélien Nephtali [Sun, 11 Mar 2018 15:55:02 +0000 (16:55 +0100)] 
BUG/MINOR: cli: Fix a typo in the 'set rate-limit' usage

The correct keyword is 'ssl-sessions' (vs. 'ssl-session').
The typo was introduced in 45c742be05 ('REORG: cli: move the "set
rate-limit" functions to their own parser').

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoCLEANUP: cli: Remove a leftover debug message
Aurélien Nephtali [Sat, 10 Mar 2018 19:59:56 +0000 (20:59 +0100)] 
CLEANUP: cli: Remove a leftover debug message

This printf() was added in f886e3478d ("MINOR: cli: Add a command to
send listening sockets.").

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoCLEANUP: ssl: Remove a duplicated #include
Aurélien Nephtali [Tue, 20 Feb 2018 18:23:07 +0000 (19:23 +0100)] 
CLEANUP: ssl: Remove a duplicated #include

openssl/x509.h is included twice since commit fc0421fde ("MEDIUM: ssl:
add support for SNI and wildcard certificates").

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoBUG/MINOR: cli: Fix a crash when passing a negative or too large value to "show fd"
Aurélien Nephtali [Fri, 9 Mar 2018 17:51:16 +0000 (18:51 +0100)] 
BUG/MINOR: cli: Fix a crash when passing a negative or too large value to "show fd"

This bug is present since 7a4a0ac71d ("MINOR: cli: add a new "show fd"
command").

This should be backported to 1.8.

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@corp.ovh.com>
7 years agoBUG/MEDIUM: h2: also arm the h2 timeout when sending
Willy Tarreau [Mon, 5 Mar 2018 15:10:54 +0000 (16:10 +0100)] 
BUG/MEDIUM: h2: also arm the h2 timeout when sending

Right now the h2 idle timeout is only set when there is no stream. If we
fail to send because the socket buffers are full (generally indicating
the client has left), we also need to arm it so that we can properly
expire such connections, otherwise some failed transfers might leave
H2 connections pending forever.

Thanks to Thierry Fournier for the diag and the traces.

This patch needs to be backported to 1.8.

7 years agoDOC: buffers: clarify the purpose of the <from> pointer in offer_buffers()
Willy Tarreau [Fri, 2 Mar 2018 09:27:12 +0000 (10:27 +0100)] 
DOC: buffers: clarify the purpose of the <from> pointer in offer_buffers()

This one is only used to compare pointers and NULL is permitted though
this is far from being clear.

7 years agoBUG/MINOR: unix: Don't mess up when removing the socket from the xfer_sock_list.
Olivier Houchard [Thu, 8 Mar 2018 17:25:49 +0000 (18:25 +0100)] 
BUG/MINOR: unix: Don't mess up when removing the socket from the xfer_sock_list.

When removing the socket from the xfer_sock_list, we want to set
next->prev to prev, not to next->prev, which is useless.

This should be backported to 1.8.

7 years agoCLEANUP: .gitignore: Ignore binaries from the contrib directory
Christopher Faulet [Wed, 28 Feb 2018 10:22:15 +0000 (11:22 +0100)] 
CLEANUP: .gitignore: Ignore binaries from the contrib directory

Some binaries were not ignored and polluted the "git status" output.

7 years agoBUG/MINOR: session: Fix tcp-request session failure if handshake.
Emeric Brun [Mon, 5 Mar 2018 16:46:16 +0000 (17:46 +0100)] 
BUG/MINOR: session: Fix tcp-request session failure if handshake.

Some sample fetches check if session is established using
the flag CO_FL_CONNECTED. But in some cases, when a handshake
is performed this flag is set too late, after the process
of the tcp-request session rules.

This fix move the raising of the flag at the beginning of the
conn_complete_session function which processes the tcp-request
session rules.

This fix must be backported to 1.8 (and perhaps 1.7)

7 years agoBUILD/MINOR: fix Lua build on Mac OS X (again)
Willy Tarreau [Mon, 5 Mar 2018 14:37:04 +0000 (15:37 +0100)] 
BUILD/MINOR: fix Lua build on Mac OS X (again)

Previous commit (13113d6 "MINOR/BUILD: fix Lua build on Mac OS X")
contains a typo, it uses "-export-dynamic" instead of "-export_dynamic"
(dash instead of underscore), despite what the commit message suggests,
and it obviously doesn't work. Thanks to Kirill A. Korinsky for reporting
it.

This patch should be backported on each version from 1.6 like the
aforementionned one above.

7 years agoMINOR/BUILD: fix Lua build on Mac OS X
Thierry Fournier [Mon, 26 Feb 2018 08:25:56 +0000 (09:25 +0100)] 
MINOR/BUILD: fix Lua build on Mac OS X

Change gcc option syntax for Mac. -Wl,--export-dynamic is not
supported, use -Wl,-export_dynamic.

Thanks to Kirill A. Korinsky for the report.

This patch should be backported on each version from 1.6

7 years agoMEDIUM: h2: use a single buffer allocator
Willy Tarreau [Thu, 1 Mar 2018 16:49:30 +0000 (17:49 +0100)] 
MEDIUM: h2: use a single buffer allocator

We used to have one buffer allocator per direction while we can never
block on two buffers at once. Let's have a single one and rely on the
connection's flags to know which one we're waitinf for.

7 years agoMINOR: h2: provide and use h2s_detach() and h2s_free()
Willy Tarreau [Thu, 1 Mar 2018 15:27:53 +0000 (16:27 +0100)] 
MINOR: h2: provide and use h2s_detach() and h2s_free()

These ones save us from open-coding the cleanup functions on each and
every error path. The code was updated to use them with no functional
change.

7 years agoCLEANUP: h2: rename misleading h2c_stream_close() to h2s_close()
Willy Tarreau [Thu, 1 Mar 2018 15:31:34 +0000 (16:31 +0100)] 
CLEANUP: h2: rename misleading h2c_stream_close() to h2s_close()

This function takes an h2c and an h2s but it never uses the h2c, which
is a bit confusing at some places in the code. Let's make it clear that
it only operates on the h2s instead by renaming it and removing the
unused h2c argument.

7 years agoMINOR: systemd: Add SystemD's SystemCallFilter option to the unit file
Tim Duesterhus [Tue, 27 Feb 2018 19:19:05 +0000 (20:19 +0100)] 
MINOR: systemd: Add SystemD's SystemCallFilter option to the unit file

This option takes away system calls that are unneeded for haproxy's
operation and thus is a good defense in depth measure.

7 years agoMINOR: systemd: Add SystemD's Protect*= options to the unit file
Tim Duesterhus [Tue, 27 Feb 2018 19:19:04 +0000 (20:19 +0100)] 
MINOR: systemd: Add SystemD's Protect*= options to the unit file

While the haproxy workers usually are running chrooted the master
process is not. This patch is a pretty safe defense in depth measure
to ensure haproxy cannot touch sensitive parts of the file system.

ProtectSystem takes non-boolean arguments in newer SystemD versions,
but setting those would leave older systems such as Ubuntu Xenial
unprotected. Distro maintainers and system administrators could
adapt the ProtectSystem value to the SystemD version they ship.

7 years agoMINOR: systemd: Add section for SystemD sandboxing to unit file
Tim Duesterhus [Tue, 27 Feb 2018 19:19:03 +0000 (20:19 +0100)] 
MINOR: systemd: Add section for SystemD sandboxing to unit file

This commit adds a warning for settings that possibly provide better
sandboxing and explains their tradeoffs.

7 years agoMINOR: connection: add proxy-v2-options authority
Emmanuel Hocdet [Thu, 1 Feb 2018 17:29:59 +0000 (18:29 +0100)] 
MINOR: connection: add proxy-v2-options authority

This patch add option PP2_TYPE_AUTHORITY to proxy protocol v2 when a TLS
connection was negotiated. In this case, authority corresponds to the sni.

7 years agoMINOR: connection: add proxy-v2-options ssl-cipher,cert-sig,cert-key
Emmanuel Hocdet [Thu, 1 Feb 2018 14:53:52 +0000 (15:53 +0100)] 
MINOR: connection: add proxy-v2-options ssl-cipher,cert-sig,cert-key

This patch implement proxy protocol v2 options related to crypto information:
ssl-cipher (PP2_SUBTYPE_SSL_CIPHER), cert-sig (PP2_SUBTYPE_SSL_SIG_ALG) and
cert-key (PP2_SUBTYPE_SSL_KEY_ALG).

7 years agoMINOR: ssl: add ssl_sock_get_cert_sig function
Emmanuel Hocdet [Thu, 2 Nov 2017 13:05:23 +0000 (14:05 +0100)] 
MINOR: ssl: add ssl_sock_get_cert_sig function

ssl_sock_get_cert_sig can be used to report cert signature short name
to log and ppv2 (RSA-SHA256).

7 years agoMINOR: ssl: add ssl_sock_get_pkey_algo function
Emmanuel Hocdet [Tue, 31 Oct 2017 14:46:07 +0000 (15:46 +0100)] 
MINOR: ssl: add ssl_sock_get_pkey_algo function

ssl_sock_get_pkey_algo can be used to report pkey algorithm to log
and ppv2 (RSA2048, EC256,...).
Extract pkey information is not free in ssl api (lock/alloc/free):
haproxy can use the pkey information computed in load_certificate.
Store and use this information in a SSL ex_data when available,
compute it if not (SSL multicert bundled and generated cert).

7 years agoMINOR: ssl: extract full pkey info in load_certificate
Emmanuel Hocdet [Fri, 27 Oct 2017 16:43:29 +0000 (18:43 +0200)] 
MINOR: ssl: extract full pkey info in load_certificate

Private key information is used in switchctx to implement native multicert
selection (ecdsa/rsa/anonymous). This patch extract and store full pkey
information: dsa type and pkey size in bits. This can be used for switchctx
or to report pkey informations in ppv2 and log.

7 years agoRevert "BUG/MINOR: send-proxy-v2: string size must include ('\0')"
Emmanuel Hocdet [Wed, 28 Feb 2018 11:02:14 +0000 (12:02 +0100)] 
Revert "BUG/MINOR: send-proxy-v2: string size must include ('\0')"

This reverts commit 82913e4f79a1f1fb25aec84a2ce2f5f0e5ce1959.
TLV string value should not be null-terminated.

This should be backported to 1.8.

7 years agoBUG/MEDIUM: spoe: Remove idle applets from idle list when HAProxy is stopping
Christopher Faulet [Wed, 28 Feb 2018 12:33:26 +0000 (13:33 +0100)] 
BUG/MEDIUM: spoe: Remove idle applets from idle list when HAProxy is stopping

In the SPOE applet's handler, when an applet is switched from the state IDLE to
PROCESSING, it is removed for the list of idle applets. But when HAProxy is
stopping, this applet can be switched to DISCONNECT. In this case, we also need
to remove it from the list of idle applets. Else the applet is removed but still
present in the list. It could lead to a segmentation fault or an infinite loop,
depending the code path.

7 years agoBUG/MEDIUM: buffer: Fix the wrapping case in bi_putblk
Christopher Faulet [Mon, 26 Feb 2018 09:51:28 +0000 (10:51 +0100)] 
BUG/MEDIUM: buffer: Fix the wrapping case in bi_putblk

When the block of data need to be split to support the wrapping, the start of
the second block of data was wrong. We must be sure to skup data copied during
the first memcpy.

This patch must be backported to 1.8.

7 years agoBUG/MEDIUM: buffer: Fix the wrapping case in bo_putblk
Christopher Faulet [Mon, 26 Feb 2018 09:47:03 +0000 (10:47 +0100)] 
BUG/MEDIUM: buffer: Fix the wrapping case in bo_putblk

When the block of data need to be split to support the wrapping, the start of
the second block of data was wrong. We must be sure to skip data copied during
the first memcpy.

This patch must be backported to 1.8, 1.7, 1.6 and 1.5.

7 years agoBUG/MEDIUM: h2: always consume any trailing data after end of output buffers
Willy Tarreau [Tue, 27 Feb 2018 14:37:25 +0000 (15:37 +0100)] 
BUG/MEDIUM: h2: always consume any trailing data after end of output buffers

In case a stream tries to emit more data than advertised by the chunks
or content-length headers, the extra data remains in the channel's output
buffer until the channel's timeout expires. It can easily happen when
sending malformed error files making use of a wrong content-length or
having extra CRLFs after the empty chunk. It may also be possible to
forge such a bad response using Lua.

The H1 to H2 encoder must protect itself against this by marking the data
presented to it as consumed if it decides to discard them, so that the
sending stream doesn't wait for the timeout to trigger.

The visible effect of this problem is a huge memory usage and a high
concurrent connection count during benchmarks when using such bad data
(a typical place where this easily happens).

This fix must be backported to 1.8.

7 years agoBUG/MINOR: h2: Set the target of dbuf_wait to h2c
Christopher Faulet [Mon, 26 Feb 2018 12:43:38 +0000 (13:43 +0100)] 
BUG/MINOR: h2: Set the target of dbuf_wait to h2c

In h2_get_dbuf, when the buffer allocation was failing, dbuf_wait.target was
errornously set to the connection (h2c->conn) instead of the h2 connection
descriptor (h2c).

This patch must be backported to 1.8.

7 years agoMINOR: stats: display the number of threads in the statistics.
Yves Lafon [Mon, 26 Feb 2018 10:10:37 +0000 (11:10 +0100)] 
MINOR: stats: display the number of threads in the statistics.

Add the nbthread global variable to the output, matching nbproc.

This may be backported to 1.8

7 years agoMINOR: debug/pools: make DEBUG_UAF also detect underflows
Willy Tarreau [Thu, 22 Feb 2018 13:14:23 +0000 (14:14 +0100)] 
MINOR: debug/pools: make DEBUG_UAF also detect underflows

Since we use padding before the allocated page, it's trivial to place
the allocated address there and see if it gets mangled once we release
it.

This may be backported to stable releases already using DEBUG_UAF.

7 years agoBUG/MINOR: debug/pools: properly handle out-of-memory when building with DEBUG_UAF
Willy Tarreau [Thu, 22 Feb 2018 10:39:23 +0000 (11:39 +0100)] 
BUG/MINOR: debug/pools: properly handle out-of-memory when building with DEBUG_UAF

Commit 158fa75 ("MINOR: pools: implement DEBUG_UAF to detect use after free")
implemented pool use-after-free detection, but the mmap() return value isn't
properly checked, preventing the call to pool_alloc_area() from returning
NULL. So on out-of-memory a mangled pointer is returned, causing a crash on
the pool_alloc() site instead of forcing a GC. It doesn't affect regular
operations however, just complicates complex bug investigations.

This fix should be backported to 1.8 and to 1.7.

7 years agoBUG/MINOR: pools/threads: don't ignore DEBUG_UAF on double-word CAS capable archs
Willy Tarreau [Thu, 22 Feb 2018 13:05:55 +0000 (14:05 +0100)] 
BUG/MINOR: pools/threads: don't ignore DEBUG_UAF on double-word CAS capable archs

Since commit cf975d4 ("MINOR: pools/threads: Implement lockless memory
pools."), we support lockless pools. However the parts dedicated to
detecting use-after-free are not present in this part, making DEBUG_UAF
useless in this situation.

The present patch sets a new define CONFIG_HAP_LOCKLESS_POOLS when such
a compatible architecture is detected, and when pool debugging is not
requested, then makes use of this everywhere in pools and buffers
functions. This way enabling DEBUG_UAF will automatically disable the
lockless version.

No backport is needed as this is purely 1.9-dev.

7 years agoCLEANUP: standard: Fix typo in IPv6 mask example
Tim Duesterhus [Tue, 20 Feb 2018 16:02:18 +0000 (17:02 +0100)] 
CLEANUP: standard: Fix typo in IPv6 mask example

IPv6 addresses with two double colons are invalid.

This typo was introduced in commit 471851713af20d84b67b8966471ea758dc8c12b9.

7 years agoCLEANUP: pools: Remove unused end label in memory.h
Tim Duesterhus [Mon, 19 Feb 2018 23:49:46 +0000 (00:49 +0100)] 
CLEANUP: pools: Remove unused end label in memory.h

This removes the end label from memory.h.

The labels are unused as of cf975d46bca2515056a4f55e55fedbbc7b4eda59
which is unreleased (and incidentally the first commit containing
those labels, thus they never have been used).

7 years agoCLEANUP: h2: Remove unused labels from mux_h2.c
Tim Duesterhus [Mon, 19 Feb 2018 23:49:45 +0000 (00:49 +0100)] 
CLEANUP: h2: Remove unused labels from mux_h2.c

This removes the unused next_header_block and try_again labels
from mux_h2.c.

try_again is unused as of a76e4c21839cafd036fbe755416569206502c1d9,
which first appeared in haproxy 1.8.0.
next_header_block is unused as of 872855998bd03d5224e0e5cd6aef9b91e2a6de1d,
which was backported to haproxy 1.8.0 as
59fcb216085a7aa9744cffe39567c80de4ebd6bf.

7 years agoCLEANUP: spoe: Remove unused label retry
Tim Duesterhus [Mon, 19 Feb 2018 23:49:44 +0000 (00:49 +0100)] 
CLEANUP: spoe: Remove unused label retry

This removes the retry labels from spoe_send_frame and spoe_recv_frame
which are unused since d5216d474d69856a282e4443f180af2093a80d6c, which
is unreleased, but was backported to haproxy 1.8 as
f13f3a4babdb1ce23a7e982c765704bca728111a.

7 years agoCLEANUP: cfgparse: Remove unused label end
Tim Duesterhus [Mon, 19 Feb 2018 23:49:43 +0000 (00:49 +0100)] 
CLEANUP: cfgparse: Remove unused label end

This removes the end label from parse_process_number() which
is unused since 5ab51775e736511b7e54f42e080dcef76a284da9, which
first was released in haproxy 1.8.0.

7 years agoMINOR: ssl/sample: adds ssl_bc_is_resumed fetch keyword.
Emeric Brun [Mon, 19 Feb 2018 15:14:12 +0000 (16:14 +0100)] 
MINOR: ssl/sample: adds ssl_bc_is_resumed fetch keyword.

Returns true when the back connection was made over an SSL/TLS transport
layer and the newly created SSL session was resumed using a cached
session or a TLS ticket.

7 years agoBUG/MEDIUM: ssl/sample: ssl_bc_* fetch keywords are broken.
Emeric Brun [Mon, 19 Feb 2018 14:59:48 +0000 (15:59 +0100)] 
BUG/MEDIUM: ssl/sample: ssl_bc_* fetch keywords are broken.

Since the split between connections and conn-stream objects, this
keywords are broken.

This patch must be backported in 1.8

7 years agoBUG/MEDIUM: http: Switch the HTTP response in tunnel mode as earlier as possible
Christopher Faulet [Fri, 2 Feb 2018 14:54:15 +0000 (15:54 +0100)] 
BUG/MEDIUM: http: Switch the HTTP response in tunnel mode as earlier as possible

When the body length is undefined (no Content-Length or Transfer-Encoding
headers), The reponse remains in ending mode, waiting the request is done. So,
most of time this is not a problem because the resquest is done before the
response. But when a client sends data to a server that replies without waiting
all the data, it is really not desirable to wait the end of the request to
finish the response.

This bug was introduced when the tunneling of the request and the reponse was
refactored, in commit 4be980391 ("MINOR: http: Switch requests/responses in
TUNNEL mode only by checking txn flag").

This patch should be backported in 1.8 and 1.7.

7 years agoBUG/MEDIUM: ssl: Shutdown the connection for reading on SSL_ERROR_SYSCALL
Christopher Faulet [Mon, 19 Feb 2018 13:25:15 +0000 (14:25 +0100)] 
BUG/MEDIUM: ssl: Shutdown the connection for reading on SSL_ERROR_SYSCALL

When SSL_read returns SSL_ERROR_SYSCALL and errno is unset or set to EAGAIN, the
connection must be shut down for reading. Else, the connection loops infinitly,
consuming all the CPU.

The bug was introduced in the commit 7e2e50500 ("BUG/MEDIUM: ssl: Don't always
treat SSL_ERROR_SYSCALL as unrecovarable."). This patch must be backported in
1.8 too.

7 years agoMINOR: sample: add a new "concat" converter
Willy Tarreau [Mon, 19 Feb 2018 14:34:12 +0000 (15:34 +0100)] 
MINOR: sample: add a new "concat" converter

It's always a pain not to be able to combine variables. This commit
introduces the "concat" converter, which appends a delimiter, a variable's
contents and another delimiter to an existing string. The result is a string.
This makes it easier to build composite variables made of other variables.

7 years agoBUG/MINOR: ssl/threads: Make management of the TLS ticket keys files thread-safe
Christopher Faulet [Fri, 16 Feb 2018 10:23:49 +0000 (11:23 +0100)] 
BUG/MINOR: ssl/threads: Make management of the TLS ticket keys files thread-safe

A TLS ticket keys file can be updated on the CLI and used in same time. So we
need to protect it to be sure all accesses are thread-safe. Because updates are
infrequent, a R/W lock has been used.

This patch must be backported in 1.8

7 years agoDOC: cfgparse: Warn on option (tcp|http)log in backend
Tim Duesterhus [Mon, 5 Feb 2018 19:52:27 +0000 (20:52 +0100)] 
DOC: cfgparse: Warn on option (tcp|http)log in backend

The option does not seem to have any effect since at least haproxy
1.3. Also the `log-format` directive already warns when being used
in a backend.

7 years agoDOC: lua: new prototype for function "register_action()"
Thierry FOURNIER [Mon, 12 Feb 2018 13:46:54 +0000 (14:46 +0100)] 
DOC: lua: new prototype for function "register_action()"

This patch should be backported to version 1.8.

7 years agoBUG/MINOR: init: Add missing brackets in the code parsing -sf/-st
Aurélien Nephtali [Sat, 17 Feb 2018 19:53:11 +0000 (20:53 +0100)] 
BUG/MINOR: init: Add missing brackets in the code parsing -sf/-st

The codes tries to strip trailing spaces of arguments but due to missing
brackets, it will always exit.

It can be reproduced with this (silly) example:

$ haproxy -f /etc/haproxy/haproxy.cfg -sf 1234 "1235 " 1236
$ echo $?
1

This was introduced in commit 236062f7c ("MINOR: init: emit warning when
-sf/-sd cannot parse argument")

Signed-off-by: Aurélien Nephtali <aurelien.nephtali@gmail.com>
7 years agoBUILD/MINOR: memory: stdint is needed for uintptr_t
David Carlier [Sun, 18 Feb 2018 19:36:42 +0000 (19:36 +0000)] 
BUILD/MINOR: memory: stdint is needed for uintptr_t

stdint.h is needed on OpenBSD for uintptr_t type.

7 years agoBUG/MEDIUM: ssl: Don't always treat SSL_ERROR_SYSCALL as unrecovarable.
Olivier Houchard [Tue, 13 Feb 2018 14:17:23 +0000 (15:17 +0100)] 
BUG/MEDIUM: ssl: Don't always treat SSL_ERROR_SYSCALL as unrecovarable.

Bart Geesink reported some random errors appearing under the form of
termination flags SD in the logs for connections involving SSL traffic
to reach the servers.

Tomek Gacek and Mateusz Malek finally narrowed down the problem to commit
c2aae74 ("MEDIUM: ssl: Handle early data with OpenSSL 1.1.1"). It happens
that the special case of SSL_ERROR_SYSCALL isn't handled anymore since
this commit.

SSL_read() might return <= 0, and SSL_get_erro() return SSL_ERROR_SYSCALL,
without meaning the connection is gone. Before flagging the connection
as in error, check the errno value.

This should be backported to 1.8.

7 years agoBUG/MEDIUM: threads: fix the double CAS implementation for ARMv7
Willy Tarreau [Wed, 14 Feb 2018 13:16:28 +0000 (14:16 +0100)] 
BUG/MEDIUM: threads: fix the double CAS implementation for ARMv7

Commit f61f0cb ("MINOR: threads: Introduce double-width CAS on x86_64
and arm.") introduced the double CAS. But the ARMv7 version is bogus,
it uses the value of the pointers instead of dereferencing them. When
lucky, it simply doesn't build due to impossible registers combinations.
Otherwise it will immediately crash at run time when facing traffic.

No backport is needed, this bug was introduced in 1.9-dev.

7 years agoBUG/MINOR: fd/threads: properly lock the FD before adding it to the fd cache.
Olivier Houchard [Thu, 8 Feb 2018 16:03:33 +0000 (16:03 +0000)] 
BUG/MINOR: fd/threads: properly lock the FD before adding it to the fd cache.

It was believed that it was useless to lock the "prev" field when adding a
FD. However, if there's only one element in the FD cache, and that element
removes itself from the fd cache, and another FD is added before the first
add completed, there's a risk of losing elements. To prevent that, lock the
"prev" field, so that such a removal will wait until the add completed.

7 years agoBUG/MINOR: config: don't emit a warning when global stats is incompletely configured
Willy Tarreau [Thu, 8 Feb 2018 08:55:09 +0000 (09:55 +0100)] 
BUG/MINOR: config: don't emit a warning when global stats is incompletely configured

Martin Brauer reported an unexpected warning when some parts of the
global stats are defined but not the listening address, like below :

  global
    #stats socket run/admin.sock mode 660 level admin
    stats timeout 30s

Then haproxy complains :
  [WARNING] 334/150131 (23086) : config : frontend 'GLOBAL' has no
'bind' directive. Please declare it as a backend if this was intended.

This is because of the check for a bind-less frontend (the global section
creates a frontend for the stats). There's no clean fix for this one, so
here we're simply checking that the frontend is not the global stats one
before emitting the warning.

This patch should be backported to all stable versions.

7 years agoDOC: Mention -Ws in the list of available options
Pavlos Parissis [Wed, 7 Feb 2018 20:42:16 +0000 (21:42 +0100)] 
DOC: Mention -Ws in the list of available options

7 years agoDOC: Describe routing impact of using interface keyword on bind lines
Jérôme Magnin [Wed, 7 Feb 2018 10:39:58 +0000 (11:39 +0100)] 
DOC: Describe routing impact of using interface keyword on bind lines

7 years agoBUILD: fd/threads: fix breakage build breakage without threads
Willy Tarreau [Tue, 6 Feb 2018 11:00:27 +0000 (12:00 +0100)] 
BUILD: fd/threads: fix breakage build breakage without threads

The last fix for the volatile dereference made use of pl_deref_int()
which is unknown when building without threads. Let's simply open-code
it instead. No backport needed.

7 years agoMINOR: init: emit warning when -sf/-sd cannot parse argument
Chris Lane [Mon, 5 Feb 2018 23:15:44 +0000 (23:15 +0000)] 
MINOR: init: emit warning when -sf/-sd cannot parse argument

Previously, -sf and -sd command line parsing used atol which cannot
detect errors.  I had a problem where I was doing -sf "$pid1 $pid2 $pid"
and it was sending the gracefully terminate signal only to the first pid.
The change uses strtol and checks endptr and errno to see if the parsing
worked.  It will exit when the pid list is not parsed.

[wt: this should be backported to 1.8]

7 years agoBUG/MEDIUM: standard: Fix memory leak in str2ip2()
Tim Duesterhus [Sun, 21 Jan 2018 21:11:17 +0000 (22:11 +0100)] 
BUG/MEDIUM: standard: Fix memory leak in str2ip2()

An haproxy compiled with:

> make -j4 all TARGET=linux2628 USE_GETADDRINFO=1

And running with a configuration like this:

  defaults
   log global
   mode http
   option httplog
   option dontlognull
   timeout connect 5000
   timeout client  50000
   timeout server  50000

  frontend fe
   bind :::8080 v4v6

   default_backend be

  backend be
   server s example.com:80 check

Will leak memory inside `str2ip2()`, because the list `result` is not
properly freed in success cases:

==18875== 140 (76 direct, 64 indirect) bytes in 1 blocks are definitely lost in loss record 87 of 111
==18875==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18875==    by 0x537A565: gaih_inet (getaddrinfo.c:1223)
==18875==    by 0x537DD5D: getaddrinfo (getaddrinfo.c:2425)
==18875==    by 0x4868E5: str2ip2 (standard.c:733)
==18875==    by 0x43F28B: srv_set_addr_via_libc (server.c:3767)
==18875==    by 0x43F50A: srv_iterate_initaddr (server.c:3879)
==18875==    by 0x43F50A: srv_init_addr (server.c:3944)
==18875==    by 0x475B30: init (haproxy.c:1595)
==18875==    by 0x40406D: main (haproxy.c:2479)

The exists as long as the usage of getaddrinfo in that function exists,
it was introduced in commit:
d5f4328efd5f4eaa7c89cad9773124959195430a

v1.5-dev8 is the first tag containing this comment, the fix
should be backported to haproxy 1.5 and newer.

7 years agoBUG/MINOR: time/threads: ensure the adjusted time is always correct
Willy Tarreau [Mon, 5 Feb 2018 19:11:38 +0000 (20:11 +0100)] 
BUG/MINOR: time/threads: ensure the adjusted time is always correct

In the time offset calculation loop, we ensure we only commit the new
date once it's futher in the future than the current one. However there
is a small issue here on 32-bit platforms : if global_now is written in
two cycles by another thread, starting with the tv_sec part, and the
current thread reads it in the middle of a change, it may compute a
wrong "adjusted" value on the first round, with the new (larger) tv_sec
and the old (large) tv_usec. This will be detected as the CAS will fail,
and another attempt will be made, but this time possibly with too large
an adusted value, pushing the date further than needed (at worst almost
one second).

This patch addresses this by using a temporary adjusted time in the loop
that always restarts from the last known one, and by assigning the result
to the final value only once the CAS succeeds.

The impact is very limited, it may cause the time to advance in small
jumps on 32 bit platforms and in the worst case some timeouts might
expire 1 second too early.

This fix should be backported to 1.8.

7 years agoMINOR: fd: reorder fd_add_to_fd_list()
Willy Tarreau [Mon, 5 Feb 2018 16:52:24 +0000 (17:52 +0100)] 
MINOR: fd: reorder fd_add_to_fd_list()

The function was cleaned up a bit from duplicated parts inherited from
the initial attempt at getting it to work. It's a bit smaller and cleaner
this way.

7 years agoMINOR: fd: remove the unneeded last CAS when adding an fd to the list
Willy Tarreau [Mon, 5 Feb 2018 16:40:21 +0000 (17:40 +0100)] 
MINOR: fd: remove the unneeded last CAS when adding an fd to the list

This was a leftover from the initial code where two threads could fight
for the list's tail.

7 years agoBUG/MINOR: fd/threads: properly dereference fdcache as volatile
Willy Tarreau [Mon, 5 Feb 2018 18:43:30 +0000 (19:43 +0100)] 
BUG/MINOR: fd/threads: properly dereference fdcache as volatile

In fd_rm_from_fd_list(), we have loops waiting for another change to
complete, in case we don't have support for a double CAS. But these
ones fail to place a compiler barrier or to dereference the fdcache
as a volatile, resulting in an endless loop on the first collision,
which is visible when run on MIPS32.

No backport needed.

7 years agoMINOR: fd: move the fd_{add_to,rm_from}_fdlist functions to fd.c
Willy Tarreau [Mon, 5 Feb 2018 16:14:55 +0000 (17:14 +0100)] 
MINOR: fd: move the fd_{add_to,rm_from}_fdlist functions to fd.c

There's not point inlining these huge functions, better move them to real
functions in fd.c.

7 years agoMEDIUM: poller: use atomic ops to update the fdtab mask
Willy Tarreau [Thu, 25 Jan 2018 17:06:46 +0000 (18:06 +0100)] 
MEDIUM: poller: use atomic ops to update the fdtab mask

We don't need to lock the fdtab[].lock anymore since we only have one
modification left (update update_mask). Let's use an atomic AND instead.