]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
6 years agoBUG/MINOR: mux-h1: Don't process input or ouput if an error occurred
Christopher Faulet [Thu, 4 Jul 2019 19:22:34 +0000 (21:22 +0200)] 
BUG/MINOR: mux-h1: Don't process input or ouput if an error occurred

It is useless to proceed if an error already occurred. Instead, it is better to
wait it will be catched by the stream or the connection, depending on which is
the first one to detect it.

This patch must be backported to 2.0.

6 years agoBUG/MEDIUM: mux-h1: Handle TUNNEL state when outgoing messages are formatted
Christopher Faulet [Thu, 4 Jul 2019 15:12:12 +0000 (17:12 +0200)] 
BUG/MEDIUM: mux-h1: Handle TUNNEL state when outgoing messages are formatted

Since the commit 94b2c7 ("MEDIUM: mux-h1: refactor output processing"), the
formatting of outgoing messages is performed on the message state and no more on
the HTX blocks read. But the TUNNEL state was left out. So, the HTTP tunneling
using the CONNECT method or switching the protocol (for instance,
the WebSocket) does not work.

This issue was reported on Github. See #131. This patch must be backported to
2.0.

6 years agoBUG/MEDIUM: lb_fas: Don't test the server's lb_tree from outside the lock
Christopher Faulet [Thu, 4 Jul 2019 09:59:42 +0000 (11:59 +0200)] 
BUG/MEDIUM: lb_fas: Don't test the server's lb_tree from outside the lock

In the function fas_srv_reposition(), the server's lb_tree is tested from
outside the lock. So it is possible to remove it after the test and then call
eb32_insert() in fas_queue_srv() with a NULL root pointer, which is
invalid. Moving the test in the scope of the lock fixes the bug.

This issue was reported on Github, issue #126.

This patch must be backported to 2.0, 1.9 and 1.8.

6 years agoBUG/MEDIUM: http/applet: Finish request processing when a service is registered
Christopher Faulet [Thu, 4 Jul 2019 09:27:15 +0000 (11:27 +0200)] 
BUG/MEDIUM: http/applet: Finish request processing when a service is registered

In the analyzers AN_REQ_HTTP_PROCESS_FE/BE, when a service is registered, it is
important to not interrupt remaining processing but just the http-request rules
processing. Otherwise, the part that handles the applets installation is
skipped.

Among the several effects, if the service is registered on a frontend (not a
listen), the forwarding of the request is skipped because all analyzers are not
set on the request channel. If the service does not depends on it, the response
is still produced and forwarded to the client. But the stream is infinitly
blocked because the request is not fully consumed. This issue was reported on
Github, see #151.

So this bug is fixed thanks to the new action return ACT_RET_DONE. Once a
service is registered, the action process_use_service() still returns
ACT_RET_STOP. But now, only rules processing is stopped. As a side effet, the
action http_action_reject() must now return ACT_RET_DONE to really stop all
processing.

This patch must be backported to 2.0. It depends on the commit introducing the
return code ACT_RET_DONE.

6 years agoMINOR: action: Add the return code ACT_RET_DONE for actions
Christopher Faulet [Thu, 4 Jul 2019 09:08:38 +0000 (11:08 +0200)] 
MINOR: action: Add the return code ACT_RET_DONE for actions

This code should be now used by action to stop at the same time the rules
processing and the possible following processings. And from its side, the return
code ACT_RET_STOP should be used to only stop rules processing.

So concretely, for TCP rules, there is no changes. ACT_RET_STOP and ACT_RET_DONE
are handled the same way. However, for HTTP rules, ACT_RET_STOP should now be
mapped on HTTP_RULE_RES_STOP and ACT_RET_DONE on HTTP_RULE_RES_DONE. So this
way, a action will have the possibilty to stop all processing or only rules
processing.

Note that changes about the TCP is done in this commit but changes about the
HTTP will be done in another one because it will fix a bug in the same time.

This patch must be backported to 2.0 because a bugfix depends on it.

6 years agoBUG/MINOR: contrib/prometheus-exporter: Don't try to add empty data blocks
Christopher Faulet [Thu, 4 Jul 2019 08:03:28 +0000 (10:03 +0200)] 
BUG/MINOR: contrib/prometheus-exporter: Don't try to add empty data blocks

When the response buffer is full and nothing more can be inserted, it is
important to not try to insert an empty data block. Otherwise, when the function
channel_add_input() is called, the flag CF_READ_PARTIAL is set on the response
channel while nothing was read and the stream is uselessly woken up. Finally, we
have loop while the response buffer is full.

This patch must be backported to 2.0.

6 years agoMINOR: server: Add "no-tfo" option.
Frédéric Lécaille [Thu, 4 Jul 2019 12:19:06 +0000 (14:19 +0200)] 
MINOR: server: Add "no-tfo" option.

Simple patch to add "no-tfo" option to "default-server" and "server" lines
to disable any usage of TCP fast open.

Must be backported to 2.0.

6 years agoBUG/MEDIUM: sessions: Don't keep an extra idle connection in sessions.
Olivier Houchard [Thu, 4 Jul 2019 12:26:41 +0000 (14:26 +0200)] 
BUG/MEDIUM: sessions: Don't keep an extra idle connection in sessions.

When deciding if we keep an idle connection in the session, check if
the number of connections currently in the session is >= the max allowed,
not >, or we'll keep an extra connection.

This should be backported to 1.9 and 2.0.

6 years agoBUG/MEDIUM: servers: Authorize tfo in default-server.
Olivier Houchard [Thu, 4 Jul 2019 11:34:10 +0000 (13:34 +0200)] 
BUG/MEDIUM: servers: Authorize tfo in default-server.

There's no reason to forbid using tfo with default-server, so allow it.

This should be backported to 2.0.

6 years agoBUG/MEDIUM: connections: Make sure we're unsubscribe before upgrading the mux.
Olivier Houchard [Wed, 3 Jul 2019 11:08:18 +0000 (13:08 +0200)] 
BUG/MEDIUM: connections: Make sure we're unsubscribe before upgrading the mux.

Just calling conn_force_unsubscribe() from conn_upgrade_mux_fe() is not
enough, as there may be multiple XPRT involved. Instead, require that
any user of conn_upgrade_mux_fe() unsubscribe itself before calling it.
This should fix upgrading a TCP connection to HTX when using SSL.

This should be backported to 2.0.

6 years agoBUG/MINOR: contrib/prometheus-exporter: Respect the reserve when data are sent
Christopher Faulet [Wed, 3 Jul 2019 09:43:17 +0000 (11:43 +0200)] 
BUG/MINOR: contrib/prometheus-exporter: Respect the reserve when data are sent

The previous commit e6cdfe574 ("BUG/MINOR: contrib/prometheus-exporter: Don't
use channel_htx_recv_max()") is buggy. The buffer's reserve must be respected.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: hlua/htx: Respect the reserve when HTX data are sent
Christopher Faulet [Wed, 3 Jul 2019 09:39:30 +0000 (11:39 +0200)] 
BUG/MINOR: hlua/htx: Respect the reserve when HTX data are sent

The previous commit 7e145b3e2 ("BUG/MINOR: hlua: Don't use
channel_htx_recv_max()") is buggy. The buffer's reserve must be respected.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: channel/htx: Use the total HTX size in channel_htx_recv_limit()
Christopher Faulet [Tue, 2 Jul 2019 13:48:03 +0000 (15:48 +0200)] 
BUG/MEDIUM: channel/htx: Use the total HTX size in channel_htx_recv_limit()

The receive limit of an HTX channel must be calculated against the total size of
the HTX message. Otherwise, the buffer may never be seen as full whereas the
receive limit is 0. Indeed, the function channel_htx_full() already takes care
to add a block size to the buffer's reserve (8 bytes). So if the function
channel_htx_recv_limit() also keep a block size free in addition to the buffer's
reserve, it means that at least 2 block size will be kept free but only one will
be taken into account, freezing the stream if the option http-buffer-request is
enabled.

This patch fixes the Github issue #136. It should be backported to 2.0 and
1.9. Thanks jaroslawr (Jarosław Rzeszótko) for his help.

6 years agoBUG/MINOR: hlua: Don't use channel_htx_recv_max()
Christopher Faulet [Tue, 2 Jul 2019 19:29:43 +0000 (21:29 +0200)] 
BUG/MINOR: hlua: Don't use channel_htx_recv_max()

The function htx_free_data_space() must be used intead. Otherwise, if there are
some output data not already forwarded, the maximum amount of data that may be
inserted into the buffer may be greater than what we can really insert.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: contrib/prometheus-exporter: Don't use channel_htx_recv_max()
Christopher Faulet [Tue, 2 Jul 2019 14:36:15 +0000 (16:36 +0200)] 
BUG/MINOR: contrib/prometheus-exporter: Don't use channel_htx_recv_max()

The function htx_free_data_space() must be used intead. Otherwise, if there are
some output data not already forwarded, the maximum amount of data that may be
inserted into the buffer may be greater than what we can really insert.

This patch must be backported to 2.0.

6 years agoBUG/MEDIUM: checks: Make sure the tasklet won't run if the connection is closed.
Olivier Houchard [Tue, 2 Jul 2019 15:42:22 +0000 (17:42 +0200)] 
BUG/MEDIUM: checks: Make sure the tasklet won't run if the connection is closed.

wake_srv_chk() can be called from conn_fd_handler(), and may decide to
destroy the conn_stream and the connection, by calling cs_close(). If that
happens, we have to make sure the tasklet isn't scheduled to run, or it will
probably crash trying to access the connection or the conn_stream.
This fixes a crash that can be seen when using tcp checks.

This should be backported to 1.9 and 2.0.
For 1.9, the call should be instead :
task_remove_from_tasklet_list((struct task *)check->wait_list.task);
That function was renamed in 2.0.

6 years agoBUG/MEDIUM: connections: Always call shutdown, with no linger.
Olivier Houchard [Tue, 2 Jul 2019 14:35:18 +0000 (16:35 +0200)] 
BUG/MEDIUM: connections: Always call shutdown, with no linger.

Revert commit fe4abe62c7c5206dff1802f42d17014e198b9141.
The goal was to make sure for health-checks, we would not get sockets in
TIME_WAIT. To do so, we would not call shutdown() if linger_risk is set.
However that is wrong, and that means shutw would never be forwarded to
the server, and thus we could get connection that are never properly closed.
Instead, to fix the original problem as described here :
https://www.mail-archive.com/haproxy@formilux.org/msg34080.html
Just make sure the checks code call cs_shutr() before calling cs_shutw().
If shutr has been called, conn_sock_shutw() will make no attempt to call
shutdown(), as it knows close() will be called.
We should really review and revamp the shutr/shutw code, as described in
github issue #142.

This should be backported to 1.9 and 2.0.

6 years agoBUG/MINOR: mux-h1: Don't return the empty chunk on HEAD responses
Christopher Faulet [Mon, 1 Jul 2019 14:17:30 +0000 (16:17 +0200)] 
BUG/MINOR: mux-h1: Don't return the empty chunk on HEAD responses

HEAD responses must not have any body payload. But, because of a bug, for chunk
reponses, the empty chunk was always added.

This patch fixes the Github issue #146. It must be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: mux-h1: Skip trailers for non-chunked outgoing messages
Christopher Faulet [Thu, 27 Jun 2019 15:40:14 +0000 (17:40 +0200)] 
BUG/MINOR: mux-h1: Skip trailers for non-chunked outgoing messages

Unlike H1, H2 messages may contains trailers while the header "Content-Length"
is set. Indeed, because of the framed structure of HTTP/2, it is no longer
necessary to use the chunked transfer encoding. So Trailing HEADERS frames,
after all DATA frames, may be added on messages with an explicit content length.

But in H1, it is impossible to have trailers on non-chunked messages. So when
outgoing messages are formatted by the H1 multiplexer, if the message is not
chunked, all trailers must be dropped.

This patch must be backported to 2.0 and 1.9. However, the patch will have to be
adapted for the 1.9.

6 years agoBUG/MEDIUM: checks: unblock signals in external checks
Willy Tarreau [Mon, 1 Jul 2019 05:51:29 +0000 (07:51 +0200)] 
BUG/MEDIUM: checks: unblock signals in external checks

As discussed in issue #140, processes are forked with signals blocked
resulting in haproxy's kill being ignored. This happens when the command
takes more time to complete than the configured check timeout or interval.
Just calling "sleep 30" every second makes the problem obvious.

The fix simply consists in unblocking the signals in the child after the
fork. It needs to be backported to all stable branches containing external
checks and where signals are blocked on startup. It's unclear when it
started, but the following config exhibits the issue :

  global
    external-check

  listen www
    bind :8001
    timeout client 5s
    timeout server 5s
    timeout connect 5s
    option external-check
    external-check command "$PWD/sleep10.sh"
    server local 127.0.0.1:80 check inter 200

  $ cat sleep10.sh
  #!/bin/sh
  exec /bin/sleep 10

The "sleep" processes keep accumulating for 10 seconds and stabilize
around 25 when the bug is present. Just issuing "killall sleep" has no
effect on them, and stopping haproxy leaves these processes behind.

6 years agoBUG/MINOR: mworker/cli: don't output a \n before the response
William Lallemand [Mon, 1 Jul 2019 08:56:15 +0000 (10:56 +0200)] 
BUG/MINOR: mworker/cli: don't output a \n before the response

When using a level lower than admin on the master CLI, a \n is output
before the response, this is caused by the response of the "operator" or
"user" that are sent before the actual command.

To fix this problem we introduce the flag APPCTX_CLI_ST1_NOLF which ask
a command response to not be followed by the final \n.
This patch made a special case with the command operator and user
followed by a - so they are not followed by \n.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: mux-h1: Always release H1C if a shutdown for writes was reported
Christopher Faulet [Fri, 28 Jun 2019 15:41:42 +0000 (17:41 +0200)] 
BUG/MEDIUM: mux-h1: Always release H1C if a shutdown for writes was reported

We must take care of this when the stream is detached from the
connection. Otherwise, on the server side, the connexion is inserted in the list
of idle connections of the session. But when reused, because the shutdown for
writes was already catched, nothing is sent to the server and the session is
blocked with a freezed connection.

This patch must be backported to 2.0 and 1.9. It is related to the issue #136
reported on Github.

6 years agoBUG/MEDIUM: ssl: Don't attempt to set alpn if we're not using SSL.
Olivier Houchard [Fri, 28 Jun 2019 12:10:33 +0000 (14:10 +0200)] 
BUG/MEDIUM: ssl: Don't attempt to set alpn if we're not using SSL.

Checks use ssl_sock_set_alpn() to set the ALPN if check-alpn is used, however
check-alpn failed to check if the connection was indeed using SSL, and thus,
would crash if check-alpn was used on a non-SSL connection. Fix this by
making sure the connection uses SSL before attempting to set the ALPN.

This should be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: mux-h1: Make format errors during output formatting fatal
Christopher Faulet [Wed, 26 Jun 2019 13:16:28 +0000 (15:16 +0200)] 
BUG/MINOR: mux-h1: Make format errors during output formatting fatal

These errors are unexpected at this staged and there is not much more to do than
to close the connection and leave. So now, when it happens, the flag
H1C_F_CS_ERROR is set on the H1 connection and the flag HTX_FL_PARSING_ERROR is
set on the channel's HTX message.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: mux-h1: Use buf_room_for_htx_data() to detect too large messages
Christopher Faulet [Wed, 26 Jun 2019 12:56:27 +0000 (14:56 +0200)] 
BUG/MEDIUM: mux-h1: Use buf_room_for_htx_data() to detect too large messages

During headers parsing, an error is returned if the message is too large and
does not fit in the input buffer. The mux h1 used the function b_full() to do
so. But to allow zero copy transfers, in h1_recv(), the input buffer is
pre-aligned and thus few bytes remains always free.

To fix the bug, as during the trailers parsing, the function
buf_room_for_htx_data() should be used instead.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: proto_htx: Don't add EOM on 1xx informational messages
Christopher Faulet [Wed, 26 Jun 2019 12:23:54 +0000 (14:23 +0200)] 
BUG/MEDIUM: proto_htx: Don't add EOM on 1xx informational messages

Since the commit b75b5eaf ("MEDIUM: htx: 1xx messages are now part of the final
reponses"), these messages are part of the response and should not contain
EOM. This block is skipped during responses parsing, but analyzers still add it
for "100-Continue" and "103-Eraly-Hints". It can also be added for error files
with 1xx status code.

Now, when HAProxy generate such transitional responses, it does not emit EOM
blocks. And informational messages are now forbidden in error files.

This patch must be backported to 2.0.

6 years agoBUG/MINOR: log: Detect missing sampling ranges in config
Tim Duesterhus [Sun, 23 Jun 2019 20:10:10 +0000 (22:10 +0200)] 
BUG/MINOR: log: Detect missing sampling ranges in config

Consider a config like:

    global
     log 127.0.0.1:10001 sample :10 local0

No sampling ranges are given here, leading to NULL being passed
as the first argument to qsort.

This configuration does not make sense anyway, a log without ranges
would never log. Thus output an error if no ranges are given.

This bug was introduced in d95ea2897eb951c72fd169f36b6a79905f2ed999.
This fix must be backported to HAProxy 2.0.

6 years agoBUG/MINOR: memory: Set objects size for pools in the per-thread cache
Christopher Faulet [Tue, 25 Jun 2019 19:45:59 +0000 (21:45 +0200)] 
BUG/MINOR: memory: Set objects size for pools in the per-thread cache

When a memory pool is created, it may be allocated from a static array. This
happens for "most common" pools, allocated first. Objects of these pools may
also be cached in a pool cache. Of course, to not cache too much entries, we
track the number of cached objects and the total size of the cache.

But the objects size of each pool in the cache (ie, pool_cache[tid][idx].size,
where tid is the thread-id and idx is the index of the pool) was never set. So
the total size of the cache was never limited. Now when a pool is created, if
these objects may be cached, we set the corresponding objects size in the pool
cache.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MAJOR: mux-h1: Don't crush trash chunk area when outgoing message is formatted
Christopher Faulet [Tue, 25 Jun 2019 19:41:02 +0000 (21:41 +0200)] 
BUG/MAJOR: mux-h1: Don't crush trash chunk area when outgoing message is formatted

When an outgoing HTX message is formatted before sending it, a trash chunk is
used to do the formatting. Its content is then copied into the output buffer of
the H1 connection. There are some tricks to avoid this last copy. First, if
possible we perform a zero-copy by swapping the area of the HTX buffer with the
one of the output buffer. If zero-copy is not possible, but if the output buffer
is empty, we don't use a trash chunk. To do so, we change the area of the trash
chunk to point on the one of the output buffer. But it is terribly wrong. Trash
chunks are global variables, allocated statically. If the area is changed, the
old one is lost. Worst, the area of the output buffer is dynamically allocated,
so it is released when emptied, leaving the trash chunk with a freed area (in
fact, it is a bit more complicated because buffers are allocated from a memory
pool).

So, honestly, I don't know why we never experienced any problem because this bug
till now. To fix it, we still use a temporary buffer, but we assign it to a
trash chunk only when other solutions were excluded. This way, we never
overwrite the area of a trash chunk.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: htx: Save hdrs_bytes when the HTX start-line is replaced
Christopher Faulet [Tue, 25 Jun 2019 19:31:26 +0000 (21:31 +0200)] 
BUG/MINOR: htx: Save hdrs_bytes when the HTX start-line is replaced

The HTX start-line contains the number of bytes held by all headers as seen by
the mux during the parsing. So it must not be updated during analysis. It was
done when the start-line is replaced, so this update was removed at this
place. But we still save it from the old start-line to not loose it. It should
not be used outside the mux, but there is no reason to skip it. It is a bug,
however it should have no impact.

This patch must be backported to 2.0.

6 years agoBUG/MEDIUM: mworker/cli: command pipelining doesn't work anymore
William Lallemand [Tue, 25 Jun 2019 16:00:19 +0000 (18:00 +0200)] 
BUG/MEDIUM: mworker/cli: command pipelining doesn't work anymore

Since commit 829bd471 ("MEDIUM: stream: rearrange the events to remove
the loop"), the pipelining in the master CLI does not work anymore.

Indeed when doing:

  echo "@1 show info; @2 show info; @3 show info" | socat /tmp/haproxy.master -

the CLI will only show the response of the first command.

When debugging we can observe that the command is sent, but the client
closes the connection before receiving the response.

The problem is that the flag CF_READ_NULL is not cleared when we
reiniate the flags of the response and we rely on this flag to close.

Must be backported in 2.0

6 years agoBUG/MEDIUM: ssl: Don't do anything in ssl_subscribe if we have no ctx.
Olivier Houchard [Mon, 24 Jun 2019 16:57:39 +0000 (18:57 +0200)] 
BUG/MEDIUM: ssl: Don't do anything in ssl_subscribe if we have no ctx.

In ssl_subscribe(), make sure we have a ssl_sock_ctx before doing anything.
When ssl_sock_close() is called, it wakes any subscriber up, and that
subscriber may decide to subscribe again, for some reason. If we no longer
have a context, there's not much we can do.

This should be backported to 2.0.

6 years agoBUG/MEDIUM: connections: Always add the xprt handshake if needed.
Olivier Houchard [Mon, 24 Jun 2019 16:19:40 +0000 (18:19 +0200)] 
BUG/MEDIUM: connections: Always add the xprt handshake if needed.

In connect_server(), we used to only call xprt_add_hs() if CO_FL_SEND_PROXY
was set during the function call, we would not do it if the flag was set
before connect_server() was called. The rational at the time was if the flag
was already set, then the XPRT was already present. But now the xprt_handshake
always removes itself, so we have to re-add it each time, or it wouldn't be
done if the first connection attempt failed.
While I'm there, check any non-ssl handshake flag, instead of just
CO_FL_SEND_PROXY, or we'd miss the SOCKS4 flags.

This should be backported to 2.0.

6 years agoBUG/MEDIUM: stream_interface: Don't add SI_FL_ERR the state is < SI_ST_CON.
Olivier Houchard [Mon, 24 Jun 2019 14:08:08 +0000 (16:08 +0200)] 
BUG/MEDIUM: stream_interface: Don't add SI_FL_ERR the state is < SI_ST_CON.

Only add SI_FL_ERR if the stream_interface is connected, or is attempting
a connection. We may get there because the stream_interface's tasklet
was woken up, but before it actually runs, process_stream() may be called,
detect that there were an error, and change the state of the stream_interface
to SI_ST_TAR. When the stream_interface's tasklet then run, the connection
may still have CO_FL_ERROR, but that error was already accounted for, so
just ignore it.

This should be backported to 2.0.

6 years agoBUG/MEDIUM: mworker: don't call the thread and fdtab deinit
William Lallemand [Mon, 24 Jun 2019 15:40:48 +0000 (17:40 +0200)] 
BUG/MEDIUM: mworker: don't call the thread and fdtab deinit

Before switching to wait mode, the per thread deinit should not be
called, because we didn't initiate threads and fdtab.

The problem is that the master could crash if we try to reload HAProxy

The commit 944e619 ("MEDIUM: mworker: wait mode use standard init code
path") removed the deinit code by accident, but its fix 7c756a8
("BUG/MEDIUM: mworker: fix FD leak upon reload") was incomplete and did
not took care of the WAIT_MODE.

This fix must be backported in 1.9 and 2.0

6 years agoBUG/MINOR: spoe: Fix memory leak if failing to allocate memory
Tim Duesterhus [Sun, 23 Jun 2019 20:10:13 +0000 (22:10 +0200)] 
BUG/MINOR: spoe: Fix memory leak if failing to allocate memory

Technically harmless, but it annoys clang analyzer.

This bug was introduced in 336d3ef0e77192582c98b3c578927a529ceadd9b.
This fix should be backported to HAProxy 1.9+.

6 years agoBUG/MINOR: mworker-prog: Fix segmentation fault during cfgparse
Tim Duesterhus [Sun, 23 Jun 2019 20:10:12 +0000 (22:10 +0200)] 
BUG/MINOR: mworker-prog: Fix segmentation fault during cfgparse

Consider this configuration:

    frontend fe_http
     mode http
     bind *:8080

     default_backend be_http

    backend be_http
     mode http
     server example example.com:80

    program foo bar

Running with valgrind results in:

    ==16252== Invalid read of size 8
    ==16252==    at 0x52AE3F: cfg_parse_program (mworker-prog.c:233)
    ==16252==    by 0x4823B3: readcfgfile (cfgparse.c:2180)
    ==16252==    by 0x47BCED: init (haproxy.c:1649)
    ==16252==    by 0x404E22: main (haproxy.c:2714)
    ==16252==  Address 0x48 is not stack'd, malloc'd or (recently) free'd

Check whether `ext_child` is valid before attempting to free it and its
contents.

This bug was introduced in 9a1ee7ac31c56fd7d881adf2ef4659f336e50c9f.
This fix must be backported to HAProxy 2.0.

6 years agoBUILD: makefile: do not rely on shell substitutions to determine git version
Willy Tarreau [Sat, 22 Jun 2019 06:24:16 +0000 (08:24 +0200)] 
BUILD: makefile: do not rely on shell substitutions to determine git version

Solaris's default shell doesn't support substitutions at the beginning or
end of variables, which are still used to determine the version based on
git. Since we added --abbrev=0 we don't need the last one. And using cut
it's trivial to replace the first one, actually simplifying the whole
expression.

This may be backported to all stable branches.

6 years agoBUILD: makefile: adjust the sed expression of "make help" for solaris
Willy Tarreau [Sat, 22 Jun 2019 06:13:24 +0000 (08:13 +0200)] 
BUILD: makefile: adjust the sed expression of "make help" for solaris

Solaris's sed doesn't take the 'p' argument on the 's' command so
nothing is printed. Just passing ';p' fixes this without affecting
other implementations. Additionally, optional characters cannot be
matched using a question mark, which is always searched verbatim, so
the leading '#' wasn't stripped. Using \{0,1\} works fine everywhere
so let's use this instead.

6 years agoBUILD: makefile: use :space: instead of digits to count commits
Willy Tarreau [Sat, 22 Jun 2019 05:51:02 +0000 (07:51 +0200)] 
BUILD: makefile: use :space: instead of digits to count commits

The 'tr' command on Solaris doesn't conform to POSIX and requires
brackets around ranges. So the sequence '0-9' is understood as the
3 characters '0', '-', and '9'. This causes tagged versions (those
with no commit after the last commit) to be numberred as an empty
string, resulting in an error being reported while computing the
version number.

All implementations support '[:space:]' to delete heading spaces,
so let's use this instead.

This may be backported to all stable versions.

6 years agoBUILD: mworker: silence two printf format warnings around getpid()
Willy Tarreau [Sat, 22 Jun 2019 05:41:38 +0000 (07:41 +0200)] 
BUILD: mworker: silence two printf format warnings around getpid()

getpid() is documented as returning a pit pid_t result, not
necessarily an int. This causes a build warning on Solaris 10
because of '%d' or '%u' are used in the format passed to snprintf().
Let's just cast the result as an int (respectively unsigned int).

This can be backported to 2.0 and possibly older versions though
it really has no impact.

6 years agoBUG/MAJOR: sample: Wrong stick-table name parsing in "if/unless" ACL condition.
Frédéric Lécaille [Thu, 20 Jun 2019 07:31:04 +0000 (09:31 +0200)] 
BUG/MAJOR: sample: Wrong stick-table name parsing in "if/unless" ACL condition.

This bug was introduced by 1b8e68e commit which supposed the stick-table was always
stored in struct arg at parsing time. This is never the case with the usage of
"if/unless" conditions in stick-table declared as backends. In this case, this is
the name of the proxy which must be considered as the stick-table name.

This must be backported to 2.0.

6 years agoBUG/MEDIUM: lb_fwlc: Don't test the server's lb_tree from outside the lock
Christopher Faulet [Wed, 19 Jun 2019 08:50:38 +0000 (10:50 +0200)] 
BUG/MEDIUM: lb_fwlc: Don't test the server's lb_tree from outside the lock

In the function fwlc_srv_reposition(), the server's lb_tree is tested from
outside the lock. So it is possible to remove it after the test and then call
eb32_insert() in fwlc_queue_srv() with a NULL root pointer, which is
invalid. Moving the test in the scope of the lock fixes the bug.

This issue was reported on Github, issue #126.

This patch must be backported to 2.0, 1.9 and 1.8.

6 years agoBUG/MEDIUM: mux-h2: Remove the padding length when a DATA frame size is checked
Christopher Faulet [Wed, 19 Jun 2019 07:25:58 +0000 (09:25 +0200)] 
BUG/MEDIUM: mux-h2: Remove the padding length when a DATA frame size is checked

When a DATA frame is processed for a message with a content-length, we first
take care to not have a frame size that exceeds the remaining to
read. Otherwise, an error is triggered. But we must remove the padding length
from the frame size because the padding is not included in the announced
content-length.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: mux-h2: Reset padlen when several frames are demux
Christopher Faulet [Tue, 18 Jun 2019 10:22:38 +0000 (12:22 +0200)] 
BUG/MEDIUM: mux-h2: Reset padlen when several frames are demux

In the function h2_process_demux(), if several frames are parsed, the padding
length must be reset between each frame. Otherwise we may wrongly think a frame
has a padding block because the previous one was padded.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MEDIUM: htx: Fully update HTX message when the block value is changed
Christopher Faulet [Tue, 18 Jun 2019 07:49:16 +0000 (09:49 +0200)] 
BUG/MEDIUM: htx: Fully update HTX message when the block value is changed

Everywhere the value length of a block is changed, calling the function
htx_set_blk_value_len(), the HTX message must be updated. But at many places,
because of the recent changes in the HTX structure, this update was only
partially done. tail_addr and head_addr values were not systematically updated.

In fact, the function htx_set_blk_value_len() was designed as an internal
function to the HTX API. And we used it from outside by convenience. But it is
really painfull and error prone to let the caller update the HTX message. So
now, we use the function htx_change_blk_value_len() wherever is possible. It
changes the value length of a block and updates the HTX message accordingly.

This patch must be backported to 2.0.

6 years agoMINOR: htx: Add the function htx_change_blk_value_len()
Christopher Faulet [Tue, 18 Jun 2019 07:37:00 +0000 (09:37 +0200)] 
MINOR: htx: Add the function htx_change_blk_value_len()

As its name suggest, this function change the value length of a block. But it
also update the HTX message accordingly. It simplifies the HTX API. The function
htx_set_blk_value_len() is still available and must be used with caution because
this one does not update the HTX message. It just updates the HTX block. It
should be considered as an internal function. When possible,
htx_change_blk_value_len() should be used instead.

This function is used to fix a bug affecting the 2.0. So, this patch must be
backported to 2.0.

6 years agoBUG/MEDIUM: compression: Set Vary: Accept-Encoding for compressed responses
Tim Duesterhus [Mon, 17 Jun 2019 14:10:07 +0000 (16:10 +0200)] 
BUG/MEDIUM: compression: Set Vary: Accept-Encoding for compressed responses

Make HAProxy set the `Vary: Accept-Encoding` response header if it compressed
the server response.

Technically the `Vary` header SHOULD also be set for responses that would
normally be compressed based off the current configuration, but are not due
to a missing or invalid `Accept-Encoding` request header or due to the
maximum compression rate being exceeded.

Not setting the header in these cases does no real harm, though: An
uncompressed response might be returned by a Cache, even if a compressed
one could be retrieved from HAProxy. This increases the traffic to the end
user if the cache is unable to compress itself, but it saves another
roundtrip to HAProxy.

see the discussion on the mailing list: https://www.mail-archive.com/haproxy@formilux.org/msg34221.html
Message-ID: 20190617121708.GA2964@1wt.eu

A small issue remains: The User-Agent is not added to the `Vary` header,
despite being relevant to the response. Adding the User-Agent header would
make responses effectively uncacheable and it's unlikely to see a Mozilla/4
in the wild in 2019.

Add a reg-test to ensure the behaviour as described in this commit message.

see issue #121
Should be backported to all branches with compression (i.e. 1.6+).

6 years agoBUG/MINOR: mux-h1: Add the header connection in lower case in outgoing messages
Christopher Faulet [Mon, 17 Jun 2019 12:07:46 +0000 (14:07 +0200)] 
BUG/MINOR: mux-h1: Add the header connection in lower case in outgoing messages

When necessary, this header is directly added in outgoing messages by the H1
multiplexer. Because there is no HTX conversion first, the header name is not
converserted to its lower case version. So, it must be added in lower case by
the multiplexer.

This patch must be backported to 2.0 and 1.9.

6 years agoBUG/MINOR: lua/htx: Make txn.req_req_* and txn.res_rep_* HTX aware
Christopher Faulet [Mon, 17 Jun 2019 11:36:06 +0000 (13:36 +0200)] 
BUG/MINOR: lua/htx: Make txn.req_req_* and txn.res_rep_* HTX aware

These bindings were not updated to support HTX streams.

This patch must be backported to 2.0 and 1.9. It fixes the issue #124.

6 years agoMEDIUM: server: server-state global file stored in a tree
Baptiste Assmann [Thu, 13 Jun 2019 11:24:29 +0000 (13:24 +0200)] 
MEDIUM: server: server-state global file stored in a tree

Server states can be recovered from either a "global" file (all backends)
or a "local" file (per backend).

The way the algorithm to parse the state file was first implemented was good
enough for a low number of backends and servers per backend.
Basically, for each backend the state file (global or local) is opened,
parsed entirely and for each line we check if it contains data related to
a server from the backend we're currently processing.
We must read the file entirely, just in case some lines for the current
backend are stored at the end of the file.
This does not scale at all!

This patch changes the behavior above for the "global" file only. Now,
the global file is read and parsed once and all lines it contains are
stored in a tree, for faster discovery.
This result in way much less fopen, fgets, and strcmp calls, which make
loading of very big state files very quick now.

6 years agoMINOR: sample: Add sha2([<bits>]) converter
Tim Duesterhus [Mon, 17 Jun 2019 10:41:44 +0000 (12:41 +0200)] 
MINOR: sample: Add sha2([<bits>]) converter

This adds a converter for the SHA-2 family, supporting SHA-224, SHA-256
SHA-384 and SHA-512.

The converter relies on the OpenSSL implementation, thus only being available
when HAProxy is compiled with USE_OPENSSL.

See GitHub issue #123. The hypothetical `ssl_?_sha256` fetch can then be
simulated using `ssl_?_der,sha2(256)`:

  http-response set-header Server-Cert-FP %[ssl_f_der,sha2(256),hex]

6 years agoMEDIUM: Remove 'option independant-streams'
Tim Duesterhus [Tue, 14 May 2019 18:58:01 +0000 (20:58 +0200)] 
MEDIUM: Remove 'option independant-streams'

It is deprecated with HAProxy 1.5. Time to remove it.

6 years agoMEDIUM: Make '(cli|con|srv)timeout' directive fatal
Tim Duesterhus [Tue, 14 May 2019 18:57:59 +0000 (20:57 +0200)] 
MEDIUM: Make '(cli|con|srv)timeout' directive fatal

They were deprecated with HAProxy 1.5. Time to remove them.

6 years agoMEDIUM: Make 'redispatch' directive fatal
Tim Duesterhus [Tue, 14 May 2019 18:57:58 +0000 (20:57 +0200)] 
MEDIUM: Make 'redispatch' directive fatal

It was deprecated with HAProxy 1.5. Time to remove it.

6 years agoMEDIUM: Make 'block' directive fatal
Tim Duesterhus [Tue, 14 May 2019 18:57:57 +0000 (20:57 +0200)] 
MEDIUM: Make 'block' directive fatal

It was deprecated with HAProxy 1.5. Time to remove it.

6 years agoDOC: this is a development branch again.
Willy Tarreau [Mon, 17 Jun 2019 11:35:23 +0000 (13:35 +0200)] 
DOC: this is a development branch again.

This effectively reverts 4bc567c5.

6 years agoBUG/MEDIUM: h2/htx: Update data length of the HTX when the cookie list is built
Christopher Faulet [Mon, 17 Jun 2019 09:44:47 +0000 (11:44 +0200)] 
BUG/MEDIUM: h2/htx: Update data length of the HTX when the cookie list is built

When an H2 request is converted into an HTX message, All cookie headers are
grouped into one, each value separated by a semicolon (;). To do so, we add the
header "cookie" with the first value and then we update the value by appending
other cookies. But during this operation, only the size of the HTX block is
updated. And not the data length of the whole HTX message.

It is an old bug and it seems to work by chance till now. But it may lead to
undefined behaviour by time to time.

This patch must be backported to 2.0 and 1.9

6 years ago[RELEASE] Released version 2.1-dev0 v2.1-dev0
Willy Tarreau [Sun, 16 Jun 2019 19:49:47 +0000 (21:49 +0200)] 
[RELEASE] Released version 2.1-dev0

Released version 2.1-dev0 with the following main changes :
    - exact copy of 2.0.0

6 years ago[RELEASE] Released version 2.0.0 v2.0.0
Willy Tarreau [Sun, 16 Jun 2019 18:00:26 +0000 (20:00 +0200)] 
[RELEASE] Released version 2.0.0

Released version 2.0.0 with the following main changes :
    - MINOR: fd: Don't use atomic operations when it's not needed.
    - DOC: mworker-prog: documentation for the program section
    - MINOR: http: add a new "http-request replace-uri" action
    - BUG/MINOR: 51d/htx: The _51d_fetch method, and the methods it calls are now HTX aware.
    - MINOR: 51d: Added dummy libraries for the 51Degrees module for testing.
    - MINOR: mworker: change formatting in uptime field of "show proc"
    - MINOR: mworker: add the HAProxy version in "show proc"
    - MINOR: doc: Remove -Ds option in man page
    - MINOR: doc: add master-worker in the man page
    - MINOR: doc: mention HAPROXY_LOCALPEER in the man
    - BUILD: Silence gcc warning about unused return value
    - CLEANUP: 51d: move the 51d dummy lib to contrib/51d/src to match the real lib
    - BUILD: travis-ci: add 51Degree device detection, update openssl to 1.1.1c
    - MINOR: doc: update the manpage and usage message about -S
    - BUILD/MINOR: 51d: Updated build registration output to indicate thatif the library is a dummy one or not.
    - BUG/MEDIUM: h1: Don't wait for handshake if we had an error.
    - BUG/MEDIUM: h1: Wait for the connection if the handshake didn't complete.
    - BUG/MINOR: task: prevent schedulable tasks from starving under high I/O activity
    - BUG/MINOR: fl_trace/htx: Be sure to always forward trailers and EOM
    - BUG/MINOR: channel/htx: Call channel_htx_full() from channel_full()
    - BUG/MINOR: http: Use the global value to limit the number of parsed headers
    - BUG/MINOR: htx: Detect when tail_addr meet end_addr to maximize free rooms
    - BUG/MEDIUM: htx: Don't change position of the first block during HTX analysis
    - CLEANUP: channel: Remove channel_htx_fwd_payload() and channel_htx_fwd_all()
    - BUG/MEDIUM: proto_htx: Introduce the state ENDING during forwarding
    - MINOR: htx: Add 3 flags on the start-line to deal with the request schemes
    - MINOR: h2: Set flags about the request's scheme on the start-line
    - MINOR: mux-h1: Set flags about the request's scheme on the start-line
    - MINOR: mux-h2: Forward clients scheme to servers checking start-line flags
    - MEDIUM: server: server-state only rely on server name
    - CLEANUP: connection: rename the wait_event.task field to .tasklet
    - CLEANUP: tasks: rename task_remove_from_tasklet_list() to tasklet_remove_*
    - BUG/MEDIUM: connections: Don't call shutdown() if we want to disable linger.
    - DOC: add some environment variables in section 2.3
    - BUILD: makefile: clarify the "help" output and list options
    - BUG/MINOR: mux-h1: Wake busy mux for I/O when message is fully sent
    - BUG: tasks: fix bug introduced by latest scheduler cleanup
    - BUG/MEDIUM: mux-h2: fix early close with option abortonclose
    - BUG/MEDIUM: connections: Don't use ALPN to pick mux when in mode TCP.
    - BUG/MEDIUM: connections: Don't try to send early data if we have no mux.
    - BUG/MEDIUM: mux-h2: properly account for the appended data in HTX
    - BUILD: makefile: further clarify the "help" output and list targets
    - BUILD: makefile: rename "linux2628" to "linux-glibc" and remove older targets
    - BUILD: travis-ci: switch to linux-glibc instead of linux2628
    - DOC: update few references to the linux* targets and change them to linux-glibc
    - BUILD: makefile: detect and reject recently removed linux targets
    - BUILD: makefile: enable linux namespaces by default on linux
    - BUILD: makefile: enable TFO on linux platforms
    - BUILD: makefile: enable getaddrinfo on the linux-glibc target
    - DOC: small updates to the CONTRIBUTING file
    - BUG/MEDIUM: ssl: Make sure we initiate the handshake after using early data.
    - CLEANUP: removed obsolete examples an move a few to better places
    - DOC: Fix typos in CONTRIBUTING
    - DOC: update the outdated ROADMAP file
    - DOC: create a BRANCHES file to explain the life cycle
    - DOC: mention in INSTALL haproxy 2.0 is a long-term supported stable version
    - BUILD: travis-ci: TFO and GETADDRINFO are now enabled by default
    - BUILD: makefile: make the obsolete target detection compatible with make-3.80
    - BUILD: tools: work around an internal compiler bug in gcc-3.4
    - BUILD: pattern: work around an internal compiler bug in gcc-3.4
    - BUILD: makefile: enable USE_RT on Solaris
    - BUILD: makefile: do not use echo -n
    - DOC: mention a few common build errors in the INSTALL file

6 years agoDOC: mention a few common build errors in the INSTALL file
Willy Tarreau [Sun, 16 Jun 2019 17:39:44 +0000 (19:39 +0200)] 
DOC: mention a few common build errors in the INSTALL file

These are some errors met when trying to build with gcc 3.4 on an
old (13 years-old) Solaris 10 and on an even older Linux 2.4 with
glibc 2.2.5. A few options were enough to fix the build there.

6 years agoBUILD: makefile: do not use echo -n
Willy Tarreau [Sun, 16 Jun 2019 17:26:18 +0000 (19:26 +0200)] 
BUILD: makefile: do not use echo -n

On certain UNIXes (Solaris at least), echo -n displays "-n". Let's
simply re-arrange the "if" block in the help message not to use it.

6 years agoBUILD: makefile: enable USE_RT on Solaris
Willy Tarreau [Sun, 16 Jun 2019 17:13:28 +0000 (19:13 +0200)] 
BUILD: makefile: enable USE_RT on Solaris

It doesn't build on Ultra5 under Solaris 10 without this due to
clock_gettime() not being found.

6 years agoBUILD: pattern: work around an internal compiler bug in gcc-3.4
Willy Tarreau [Sun, 16 Jun 2019 16:40:33 +0000 (18:40 +0200)] 
BUILD: pattern: work around an internal compiler bug in gcc-3.4

gcc-3.4 fails to compile pattern.c :

src/pattern.c: In function `pat_match_ip':
src/pattern.c:1092: error: unrecognizable insn:
(insn 186 185 187 9 src/pattern.c:970 (set (reg/f:SI 179)
        (high:SI (const:SI (plus:SI (symbol_ref:SI ("static_pattern") [flags 0x22] <var_decl fe5bae80 static_pattern>)
                    (const_int 8 [0x8]))))) -1 (nil)
    (nil))
src/pattern.c:1092: internal compiler error: in extract_insn, at recog.c:2083

This happens when performing the memcpy() on the union, and in this
case the workaround is trivial (and even cleaner) using a cast instead.

6 years agoBUILD: tools: work around an internal compiler bug in gcc-3.4
Willy Tarreau [Sun, 16 Jun 2019 16:16:33 +0000 (18:16 +0200)] 
BUILD: tools: work around an internal compiler bug in gcc-3.4

gcc-3.4 fails to compile standard.c :

src/standard.c: In function `str2sa_range':
src/standard.c:1034: error: unrecognizable insn:
(insn 582 581 583 37 src/standard.c:949 (set (reg/f:SI 262)
        (high:SI (const:SI (plus:SI (symbol_ref:SI ("*ss.4") [flags 0x22] <var_decl fe782e80 ss>)
                    (const_int 2 [0x2]))))) -1 (nil)
    (nil))
src/standard.c:1034: internal compiler error: in extract_insn, at recog.c:2083

The workaround is explained here :

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21613

It only requires creating a local variable containing the result of the
cast, which is totally harmless, so let's do it.

6 years agoBUILD: makefile: make the obsolete target detection compatible with make-3.80
Willy Tarreau [Sun, 16 Jun 2019 15:53:39 +0000 (17:53 +0200)] 
BUILD: makefile: make the obsolete target detection compatible with make-3.80

Older versions of GNU make do not support "else ifneq", let's split
this in two lines.

6 years agoBUILD: travis-ci: TFO and GETADDRINFO are now enabled by default
Ilya Shipitsin [Sat, 15 Jun 2019 20:19:27 +0000 (01:19 +0500)] 
BUILD: travis-ci: TFO and GETADDRINFO are now enabled by default

This default changed in the linux-glibc target with commits 364d6f5
and a26181e.

6 years agoDOC: mention in INSTALL haproxy 2.0 is a long-term supported stable version
Willy Tarreau [Sat, 15 Jun 2019 17:07:54 +0000 (19:07 +0200)] 
DOC: mention in INSTALL haproxy 2.0 is a long-term supported stable version

Let's switch back to the stable wording now.

6 years agoDOC: create a BRANCHES file to explain the life cycle
Willy Tarreau [Sat, 15 Jun 2019 19:53:40 +0000 (21:53 +0200)] 
DOC: create a BRANCHES file to explain the life cycle

This file tries to describe development versus maintenance and gives hints
about what version to pick depending on the user's skills and goals.

6 years agoDOC: update the outdated ROADMAP file
Willy Tarreau [Sat, 15 Jun 2019 19:58:44 +0000 (21:58 +0200)] 
DOC: update the outdated ROADMAP file

At least the load load balancing was done. Other points are being carried
since 1.5 or so, they should go into the issue tracker with no version
indication.

6 years agoDOC: Fix typos in CONTRIBUTING
Tim Duesterhus [Sat, 15 Jun 2019 17:47:29 +0000 (19:47 +0200)] 
DOC: Fix typos in CONTRIBUTING

Fixes typos introduced in 09e0d7422e64645ad6b03b66e94e5df80a6177fa
as well as anything found by `spell`.

6 years agoCLEANUP: removed obsolete examples an move a few to better places
Willy Tarreau [Sat, 15 Jun 2019 16:56:48 +0000 (18:56 +0200)] 
CLEANUP: removed obsolete examples an move a few to better places

The following example files awere removed as irrelevant by this
time :
  auth.cfg check.conf ssl.cfg haproxy.spec

The following scripts were removed as having been unused for more
than a decade :
  debug2ansi debug2html debugfind check init.haproxy stats_haproxy.sh

seemless_reload.txt was moved to doc/ where it's more suitable.

haproxy.vim was moved to contrib/syntax-highlight/

scripts/create-release was updated not to try to update haproxy.spec
anymore.

6 years agoBUG/MEDIUM: ssl: Make sure we initiate the handshake after using early data.
Olivier Houchard [Sat, 15 Jun 2019 18:59:30 +0000 (20:59 +0200)] 
BUG/MEDIUM: ssl: Make sure we initiate the handshake after using early data.

When we're done sending/receiving early data, and we add the handshake
flags on the connection, make sure we wake the associated tasklet up, so that
the handshake will be initiated.

6 years agoDOC: small updates to the CONTRIBUTING file
Willy Tarreau [Sat, 15 Jun 2019 15:15:12 +0000 (17:15 +0200)] 
DOC: small updates to the CONTRIBUTING file

There's an abstract explaining what is discussed in the file, a small
explanation of how the project works, which justifies the measures
taken here, and instructions about what to do when a patch is ignored,
or how to annoy everyone.

6 years agoBUILD: makefile: enable getaddrinfo on the linux-glibc target
Willy Tarreau [Fri, 14 Jun 2019 16:33:56 +0000 (18:33 +0200)] 
BUILD: makefile: enable getaddrinfo on the linux-glibc target

getaddrinfo() has been available since glibc 2.3.3 or so and is generally
enabled by distro packagers. The main reason for not enabling it on Linux
in the past is that it was known broken on some libc alternatives. It's
the right moment to enable it by default with glibc.

6 years agoBUILD: makefile: enable TFO on linux platforms
Willy Tarreau [Fri, 14 Jun 2019 14:57:42 +0000 (16:57 +0200)] 
BUILD: makefile: enable TFO on linux platforms

TCP Fast Open is supported on all supported Linux kernels and on all
kernels shipped in supported distros, except the older 2.6.32 that
comes with RHEL6. However the option is harmless, will not prevent
from building and smoothly falls back even if forcefully enabled, so
it makes sense to enable it by default. It's still possible to pass
"USE_TFO=" to force it disabled if really desired.

6 years agoBUILD: makefile: enable linux namespaces by default on linux
Willy Tarreau [Fri, 14 Jun 2019 14:54:51 +0000 (16:54 +0200)] 
BUILD: makefile: enable linux namespaces by default on linux

Oldest kernel found on a supported Linux distro (2.6.32 + backports on
RHEL6) supports network namespaces, so we have no reason not to enable
them by default on the linux-glibc target.

6 years agoBUILD: makefile: detect and reject recently removed linux targets
Willy Tarreau [Fri, 14 Jun 2019 14:44:49 +0000 (16:44 +0200)] 
BUILD: makefile: detect and reject recently removed linux targets

We've just removed old linux targets "linux22", "linux24", "linux24e",
"linux26" and "linux2628" and it's likely that many build scripts and
packages will still reference these. So let's have the makefile detect
these and reject with instructions instead of silently building with
incorrect options.

6 years agoDOC: update few references to the linux* targets and change them to linux-glibc
Willy Tarreau [Fri, 14 Jun 2019 16:40:48 +0000 (18:40 +0200)] 
DOC: update few references to the linux* targets and change them to linux-glibc

The INSTALL guide, the Lua doc and the Prometheus exporter's README all
used to reference "linux2628", "linux26" or even "linux". These were all
updated to consistently reflect "linux-glibc" instead. The default options
were updated there as well so that it should build cleanly on most distros.

6 years agoBUILD: travis-ci: switch to linux-glibc instead of linux2628
Willy Tarreau [Fri, 14 Jun 2019 16:32:34 +0000 (18:32 +0200)] 
BUILD: travis-ci: switch to linux-glibc instead of linux2628

The Linux target has changed and only linux-glibc is known now.

6 years agoBUILD: makefile: rename "linux2628" to "linux-glibc" and remove older targets
Willy Tarreau [Fri, 14 Jun 2019 14:32:09 +0000 (16:32 +0200)] 
BUILD: makefile: rename "linux2628" to "linux-glibc" and remove older targets

The linux targets have become more than confusing over time. We used to
have "linux2628" to match the features available in kernels 2.6.28 and
above, without consideration for the libc, and due to many new features
appearing later in kernels, some other options were added that are not
enabled by default in linux2628, so this target doesn't make any sense
anymore. The older ones (linux 2.2, linux 2.4, ...) do not make sense
either since these versions are not supported anymore. Let's clean things
up by creating a new "linux-glibc" target that matches what is available
by default on Linux kernels and glibc present on supported distros at the
time of release. Other libc implementation may use a custom or generic
target or be added later if needed.

All the older linux targets were removed.

6 years agoBUILD: makefile: further clarify the "help" output and list targets
Willy Tarreau [Fri, 14 Jun 2019 13:52:01 +0000 (15:52 +0200)] 
BUILD: makefile: further clarify the "help" output and list targets

When a target is not set we now also list the known ones. A minor
alignment issue in the output was also addressed.

6 years agoBUG/MEDIUM: mux-h2: properly account for the appended data in HTX
Willy Tarreau [Sat, 15 Jun 2019 09:34:41 +0000 (11:34 +0200)] 
BUG/MEDIUM: mux-h2: properly account for the appended data in HTX

When commit 0350b90e3 ("MEDIUM: htx: make htx_add_data() never defragment
the buffer") was introduced, it made htx_add_data() actually be able to
add less data than it was asked for, and the callers must use the returned
value to know how much was added. The H2 code used to rely on the frame
length instead of the return value. A version of the code doing this was
written but is obviously not the one that got merged, resulting in breaking
large uploads or downloads when HTX would have instead defragmented the
buffer because the HTX side sees less contents than what the H2 side sees.

This patch fixes this again. No backport is needed.

6 years agoBUG/MEDIUM: connections: Don't try to send early data if we have no mux.
Olivier Houchard [Fri, 14 Jun 2019 22:14:05 +0000 (00:14 +0200)] 
BUG/MEDIUM: connections: Don't try to send early data if we have no mux.

In connect_server(), if we don't yet have a mux, because we're choosing
one depending on the ALPN, don't attempt to send early data. We can't do
it because those data would depend on the mux, that will only be determined
by the handshake.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: connections: Don't use ALPN to pick mux when in mode TCP.
Olivier Houchard [Fri, 14 Jun 2019 22:13:15 +0000 (00:13 +0200)] 
BUG/MEDIUM: connections: Don't use ALPN to pick mux when in mode TCP.

In connect_server(), don't wait until we negociate the ALPN to choose the
mux, the only mux we want to use is the mux_pt anyway.

This should be backported to 1.9.

6 years agoBUG/MEDIUM: mux-h2: fix early close with option abortonclose
Willy Tarreau [Sat, 15 Jun 2019 07:55:50 +0000 (09:55 +0200)] 
BUG/MEDIUM: mux-h2: fix early close with option abortonclose

Olivier found that commit 99ad1b3e8 ("MINOR: mux-h2: stop relying on
CS_FL_REOS") managed to break abortonclose again with H2. What happens
is that while the CS_FL_REOS flag was set on some transitions to the
HREM state, it's not set on all and is in fact only set when the low
level connection is closed. So making the replacement condition match
the HREM and ERROR states is not correct and causes completely correct
requests to send advertise an early close of the connection layer while
only the stream's input is closed.

In order to avoid this, we now properly split the checks for the CLOSED
state and for the closed connection. This way there is no risk to set
the EOS flag too early on the connection.

No backport is needed.

6 years agoBUG: tasks: fix bug introduced by latest scheduler cleanup
Willy Tarreau [Fri, 14 Jun 2019 16:05:54 +0000 (18:05 +0200)] 
BUG: tasks: fix bug introduced by latest scheduler cleanup

In commit 86eded6c6 ("CLEANUP: tasks: rename task_remove_from_tasklet_list()
to tasklet_remove_*") which consisted in removing the casts between tasks
and tasklet, I was a bit too fast to believe that we only saw tasklets in
this function since process_runnable_tasks() also uses it with tasks under
a cast. So removing the bookkeeping on task_list_size was not appropriate.
Bah, the joy of casts which hide the real thing...

This patch does two things at once to address this mess once for all:
  - it restores the decrement of task_list_size when it's a real task,
    but moves it to process_runnable_task() since it's the only place
    where it's allowed to call it with a task

  - it moves the increment there as well and renames
    task_insert_into_tasklet_list() to tasklet_insert_into_tasklet_list()
    of obvious consistency reasons.

This way the increment/decrement of task_list_size is made at the only
places where the cast is enforced, so it has less risks to be missed.
The comments on top of these functions were updated to reflect that they
are only supposed to be used with tasklets and that the caller is responsible
for keeping task_list_size up to date if it decides to enforce a task there.

Now we don't have to worry anymore about how these functions work outside
of the scheduler, which is better longterm-wise. Thanks to Christopher for
spotting this mistake.

No backport is needed.

6 years agoBUG/MINOR: mux-h1: Wake busy mux for I/O when message is fully sent
Christopher Faulet [Fri, 14 Jun 2019 14:54:15 +0000 (16:54 +0200)] 
BUG/MINOR: mux-h1: Wake busy mux for I/O when message is fully sent

If a mux is in busy mode when the outgoing EOM is consummed, it is important to
wake it up for I/O. Because in busy mode, the mux is not subscribed for
receive. Otherwise, it depends on the applicative layer to shutdown the H1
stream. Wake it up allows the mux to catch the read0 as soon as possible.

This patch must be backported to 1.9.

6 years agoBUILD: makefile: clarify the "help" output and list options
Willy Tarreau [Fri, 14 Jun 2019 13:52:01 +0000 (15:52 +0200)] 
BUILD: makefile: clarify the "help" output and list options

The list of enable and disabled build options now appears separately
at the end of "make help". This is convenient to know what is enabled
by default on a given target. For example :

  $ make help TARGET=linux2628
  Enabled features for TARGET 'linux2628' (disable with 'USE_xxx=') :
    EPOLL NETFILTER POLL THREAD TPROXY LINUX_TPROXY LINUX_SPLICE LIBCRYPT
    CRYPT_H FUTEX ACCEPT4 CPU_AFFINITY DL RT PRCTL THREAD_DUMP

  Disabled features for TARGET 'linux2628' (enable with 'USE_xxx=1') :
    KQUEUE MY_EPOLL MY_SPLICE PCRE PCRE_JIT PCRE2 PCRE2_JIT PRIVATE_CACHE
    PTHREAD_PSHARED REGPARM STATIC_PCRE STATIC_PCRE2 VSYSCALL GETADDRINFO
    OPENSSL LUA MY_ACCEPT4 ZLIB SLZ TFO NS DEVICEATLAS 51DEGREES WURFL
    SYSTEMD OBSOLETE_LINKER EVPORTS

6 years agoDOC: add some environment variables in section 2.3
William Lallemand [Fri, 14 Jun 2019 13:35:37 +0000 (15:35 +0200)] 
DOC: add some environment variables in section 2.3

Add the missing environment variable in the 2.3 section.

6 years agoBUG/MEDIUM: connections: Don't call shutdown() if we want to disable linger.
Olivier Houchard [Fri, 14 Jun 2019 13:26:06 +0000 (15:26 +0200)] 
BUG/MEDIUM: connections: Don't call shutdown() if we want to disable linger.

In conn_sock_shutw(), avoid calling shutdown() if linger_risk is set. Not
doing so will result in getting sockets in TIME_WAIT for some time.
This is particularly observable with health checks.

This should be backported to 1.9.

6 years agoCLEANUP: tasks: rename task_remove_from_tasklet_list() to tasklet_remove_*
Willy Tarreau [Fri, 14 Jun 2019 12:47:49 +0000 (14:47 +0200)] 
CLEANUP: tasks: rename task_remove_from_tasklet_list() to tasklet_remove_*

The function really only operates on tasklets, its arguments are always
tasklets cast as tasks to match the function's type, to be cast back to
a struct tasklet. Let's rename it to tasklet_remove_from_tasklet_list(),
take a struct tasklet, and get rid of the undesired task casts.

6 years agoCLEANUP: connection: rename the wait_event.task field to .tasklet
Willy Tarreau [Fri, 14 Jun 2019 12:42:29 +0000 (14:42 +0200)] 
CLEANUP: connection: rename the wait_event.task field to .tasklet

It's really confusing to call it a task because it's a tasklet and used
in places where tasks and tasklets are used together. Let's rename it
to tasklet to remove this confusion.

6 years agoMEDIUM: server: server-state only rely on server name
Baptiste Assmann [Tue, 11 Jun 2019 12:51:49 +0000 (14:51 +0200)] 
MEDIUM: server: server-state only rely on server name

Since h7da71293e431b5ebb3d6289a55b0102331788ee6as has been added, the
server name (srv->id in the code) is now unique per backend, which
means it can reliabely be used to identify a server recovered from the
server-state file.

This patch cleans up the parsing of server-state file and ensure we use
only the server name as a reliable key.

6 years agoMINOR: mux-h2: Forward clients scheme to servers checking start-line flags
Christopher Faulet [Fri, 14 Jun 2019 08:46:51 +0000 (10:46 +0200)] 
MINOR: mux-h2: Forward clients scheme to servers checking start-line flags

By default, the scheme "https" is always used. But when an explicit scheme was
defined and when this scheme is "http", we use it in the request sent to the
server. This is done by checking flags of the start-line. If the flag
HTX_SL_F_HAS_SCHM is set, it means an explicit scheme was defined on the client
side. And if the flag HTX_SL_F_SCHM_HTTP is set, it means the scheme "http" was
used.

6 years agoMINOR: mux-h1: Set flags about the request's scheme on the start-line
Christopher Faulet [Fri, 14 Jun 2019 08:31:25 +0000 (10:31 +0200)] 
MINOR: mux-h1: Set flags about the request's scheme on the start-line

We first try to figure out if the URI of the start-line is absolute or not. So,
if it does not start by a slash ("/"), it means the URI is an absolute one and
the flag HTX_SL_F_HAS_SCHM is set. Then checks are performed to know if the
scheme is "http" or "https" and the corresponding flag is set,
HTX_SL_F_SCHM_HTTP or HTX_SL_F_SCHM_HTTPS. Other schemes, for instance ftp, are
ignored.

6 years agoMINOR: h2: Set flags about the request's scheme on the start-line
Christopher Faulet [Fri, 14 Jun 2019 08:25:47 +0000 (10:25 +0200)] 
MINOR: h2: Set flags about the request's scheme on the start-line

The flag HTX_SL_F_HAS_SCHM is always set because H2 requests have always an
explicit scheme. Then, the pseudo-header ":scheme" is tested. If it is set to
"http", the flag HTX_SL_F_SCHM_HTTP is set. Otherwise, for all other cases, the
flag HTX_SL_F_SCHM_HTTPS is set. For now, it seems reasonable to have a fallback
on the scheme "https".

6 years agoMINOR: htx: Add 3 flags on the start-line to deal with the request schemes
Christopher Faulet [Fri, 14 Jun 2019 08:08:13 +0000 (10:08 +0200)] 
MINOR: htx: Add 3 flags on the start-line to deal with the request schemes

The first one, HTX_SL_F_HAS_SCHM, will be used to know the request has an
explicit scheme. So, in H2, it is always true because the pseudo-header
":scheme" is mandatory. In H1, it is only true when an absolute URI is found on
the start-line. The other flags, HTX_SL_F_SCHM_HTTP and HTX_SL_F_SCHM_HTTPS,
will be used to know which scheme the request have. For now, other protocols are
not handled.

The aim of these flags is to pass this information to the backend side in
general, and to the H2 mux in particular. So the multiplexer will have a chance
to use this information to send the right scheme to the server.

6 years agoBUG/MEDIUM: proto_htx: Introduce the state ENDING during forwarding
Christopher Faulet [Thu, 13 Jun 2019 14:43:22 +0000 (16:43 +0200)] 
BUG/MEDIUM: proto_htx: Introduce the state ENDING during forwarding

This state is used in the legacy HTTP when everything was received from an
endpoint but a filter doesn't forward all the data. It is used to not report a
client or a server abort, depending on channels flags.

The same must be done on HTX streams. Otherwise, the message may be
truncated. For instance, it may happen with the filter trace with the random
forwarding enabled on the response channel.

This patch must be backported to 1.9.

6 years agoCLEANUP: channel: Remove channel_htx_fwd_payload() and channel_htx_fwd_all()
Christopher Faulet [Thu, 13 Jun 2019 09:31:24 +0000 (11:31 +0200)] 
CLEANUP: channel: Remove channel_htx_fwd_payload() and channel_htx_fwd_all()

These functions are unused now. No backport needed.