]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
9 years agoMEDIUM: filters/http: Move body parsing of HTTP messages in dedicated functions
Christopher Faulet [Wed, 2 Dec 2015 09:01:17 +0000 (10:01 +0100)] 
MEDIUM: filters/http: Move body parsing of HTTP messages in dedicated functions

Now body parsing is done in http_msg_forward_body and
http_msg_forward_chunked_body functions, regardless of whether we parse a
request or a response.
Parsing result is still handled in http_request_forward_body and
http_response_forward_body functions.

This patch will ease futur optimizations, mainly on filters.

9 years agoMEDIUM: filters: Replace filter_http_headers callback by an analyzer
Christopher Faulet [Wed, 2 Dec 2015 08:57:32 +0000 (09:57 +0100)] 
MEDIUM: filters: Replace filter_http_headers callback by an analyzer

This new analyzer will be called for each HTTP request/response, before the
parsing of the body. It is identified by AN_FLT_HTTP_HDRS.

Special care was taken about the following condition :

  * the frontend is a TCP proxy
  * filters are defined in the frontend section
  * the selected backend is a HTTP proxy

So, this patch explicitly add AN_FLT_HTTP_HDRS analyzer on the request and the
response channels when the backend is a HTTP proxy and when there are filters
attatched on the stream.
This patch simplifies http_request_forward_body and http_response_forward_body
functions.

9 years agoMEDIUM: filters: remove http_start_chunk, http_last_chunk and http_chunk_end
Christopher Faulet [Tue, 1 Dec 2015 09:40:57 +0000 (10:40 +0100)] 
MEDIUM: filters: remove http_start_chunk, http_last_chunk and http_chunk_end

For Chunked HTTP request/response, the body filtering can be really
expensive. In the worse case (many chunks of 1 bytes), the filters overhead is
of 3 calls per chunk. If http_data callback is useful, others are just
informative.

So these callbacks has been removed. Of course, existing filters (trace and
compression) has beeen updated accordingly. For the HTTP compression filter, the
update is quite huge. Its implementation is closer to the old one.

9 years agoMEDIUM: filters: Use macros to call filters callbacks to speed-up processing
Christopher Faulet [Tue, 24 Nov 2015 15:24:13 +0000 (16:24 +0100)] 
MEDIUM: filters: Use macros to call filters callbacks to speed-up processing

When no filter is attached to the stream, the CPU footprint due to the calls to
filters_* functions is huge, especially for chunk-encoded messages. Using macros
to check if we have some filters or not is a great improvement.

Furthermore, instead of checking the filter list emptiness, we introduce a flag
to know if filters are attached or not to a stream.

9 years agoMAJOR: filters/http: Rewrite the HTTP compression as a filter
Christopher Faulet [Thu, 5 Nov 2015 12:35:03 +0000 (13:35 +0100)] 
MAJOR: filters/http: Rewrite the HTTP compression as a filter

HTTP compression has been rewritten to use the filter API. This is more a PoC
than other thing for now. It allocates memory to work. So, if only for that, it
should be rewritten.

In the mean time, the implementation has been refactored to allow its use with
other filters. However, there are limitations that should be respected:

  - No filter placed after the compression one is allowed to change input data
    (in 'http_data' callback).
  - No filter placed before the compression one is allowed to change forwarded
    data (in 'http_forward_data' callback).

For now, these limitations are informal, so you should be careful when you use
several filters.

About the configuration, 'compression' keywords are still supported and must be
used to configure the HTTP compression behavior. In absence of a 'filter' line
for the compression filter, it is added in the filter chain when the first
compression' line is parsed. This is an easy way to do when you do not use other
filters. But another filter exists, an error is reported so that the user must
explicitly declare the filter.

For example:

  listen tst
      ...
      compression algo gzip
      compression offload
      ...
      filter flt_1
      filter compression
      filter flt_2
      ...

9 years agoREORG: filters: Prepare creation of the HTTP compression filter
Christopher Faulet [Wed, 9 Dec 2015 13:59:38 +0000 (14:59 +0100)] 
REORG: filters: Prepare creation of the HTTP compression filter

HTTP compression will be moved in a true filter. To prepare the ground, some
functions have been moved in a dedicated file. Idea is to keep everything about
compression algos in compression.c and everything related to the filtering in
flt_http_comp.c.

For now, a header has been added to help during the transition. It will be
removed later.

Unused empty ACL keyword list was removed. The "compression" keyword
parser was moved from cfgparse.c to flt_http_comp.c.

9 years agoMINOR: filters: Do not reset stream analyzers if the client is gone
Christopher Faulet [Tue, 22 Dec 2015 11:01:29 +0000 (12:01 +0100)] 
MINOR: filters: Do not reset stream analyzers if the client is gone

When all callbacks have been called for all filters registered on a stream, if
we are waiting for the next HTTP request, we must reset stream analyzers. But it
is useless to do so if the client has already closed the connection.

9 years agoMAJOR: filters: Add filters support
Christopher Faulet [Thu, 30 Apr 2015 09:48:27 +0000 (11:48 +0200)] 
MAJOR: filters: Add filters support

This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.

To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:

struct flt_ops {
       /*
        * Callbacks to manage the filter lifecycle
        */
       int  (*init)  (struct proxy *p);
       void (*deinit)(struct proxy *p);
       int  (*check) (struct proxy *p);

        /*
         * Stream callbacks
         */
        void (*stream_start)     (struct stream *s);
        void (*stream_accept)    (struct stream *s);
        void (*session_establish)(struct stream *s);
        void (*stream_stop)      (struct stream *s);

       /*
        * HTTP callbacks
        */
       int  (*http_start)         (struct stream *s, struct http_msg *msg);
       int  (*http_start_body)    (struct stream *s, struct http_msg *msg);
       int  (*http_start_chunk)   (struct stream *s, struct http_msg *msg);
       int  (*http_data)          (struct stream *s, struct http_msg *msg);
       int  (*http_last_chunk)    (struct stream *s, struct http_msg *msg);
       int  (*http_end_chunk)     (struct stream *s, struct http_msg *msg);
       int  (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
       int  (*http_end_body)      (struct stream *s, struct http_msg *msg);
       void (*http_end)           (struct stream *s, struct http_msg *msg);
       void (*http_reset)         (struct stream *s, struct http_msg *msg);
       int  (*http_pre_process)   (struct stream *s, struct http_msg *msg);
       int  (*http_post_process)  (struct stream *s, struct http_msg *msg);
       void (*http_reply)         (struct stream *s, short status,
                                   const struct chunk *msg);
};

To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:

  frontend test
    ...
    filter <FILTER-NAME> [OPTIONS...]

The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.

For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.

It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.

The filter API has been highly refactored. Main changes are:

* Now, HA supports an infinite number of filters per proxy. To do so, filters
  are stored in list.

* Because filters are stored in list, filters state has been moved from the
  channel structure to the filter structure. This is cleaner because there is no
  more info about filters in channel structure.

* It is possible to defined filters on backends only. For such filters,
  stream_start/stream_stop callbacks are not called. Of course, it is possible
  to mix frontend and backend filters.

* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
  are called for all kind of streams. In addition, 2 new callbacks were added to
  filter data exchanged through a TCP stream:

    - tcp_data: it is called when new data are available or when old unprocessed
      data are still waiting.

    - tcp_forward_data: it is called when some data can be consumed.

* New callbacks attached to channel were added:

    - channel_start_analyze: it is called when a filter is ready to process data
      exchanged through a channel. 2 new analyzers (a frontend and a backend)
      are attached to channels to call this callback. For a frontend filter, it
      is called before any other analyzer. For a backend filter, it is called
      when a backend is attached to a stream. So some processing cannot be
      filtered in that case.

    - channel_analyze: it is called before each analyzer attached to a channel,
      expects analyzers responsible for data sending.

    - channel_end_analyze: it is called when all other analyzers have finished
      their processing. A new analyzers is attached to channels to call this
      callback. For a TCP stream, this is always the last one called. For a HTTP
      one, the callback is called when a request/response ends, so it is called
      one time for each request/response.

* 'session_established' callback has been removed. Everything that is done in
  this callback can be handled by 'channel_start_analyze' on the response
  channel.

* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
  'channel_analyze'.

* 'http_start' callback has been replaced by 'http_headers'. This new one is
  called just before headers sending and parsing of the body.

* 'http_end' callback has been replaced by 'channel_end_analyze'.

* It is possible to set a forwarder for TCP channels. It was already possible to
  do it for HTTP ones.

* Forwarders can partially consumed forwardable data. For this reason a new
  HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.

Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.

In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.

Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.

The HTTP compression code had to be moved.

So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:

 * flt_set_http_data_forwarder: This function sets the filter (using its id)
   that will forward data for the specified HTTP message. It is possible if it
   was not already set by another filter _AND_ if no data was yet forwarded
   (msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.

 * flt_http_data_forwarder: This function returns the filter id that will
   forward data for the specified HTTP message. If there is no forwarder set, it
   returns -1.

When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.

9 years agoBUG/MINOR: stats: fix missing comma in stats on agent drain
Raghu Udiyar [Fri, 5 Feb 2016 17:00:11 +0000 (22:30 +0530)] 
BUG/MINOR: stats: fix missing comma in stats on agent drain

The csv stats format breaks when agent changes server state to drain.
Tools like hatop, metric or check agents will fail due to this. This
should be backported to 1.6.

9 years agoBUG/MINOR: ssl: Be sure to use unique serial for regenerated certificates
Christopher Faulet [Thu, 12 Nov 2015 10:35:51 +0000 (11:35 +0100)] 
BUG/MINOR: ssl: Be sure to use unique serial for regenerated certificates

The serial number for a generated certificate was computed using the requested
servername, without any variable/random part. It is not a problem from the
moment it is not regenerated.

But if the cache is disabled or when the certificate is evicted from the cache,
we may need to regenerate it. It is important to not reuse the same serial
number for the new certificate. Else clients (especially browsers) trigger a
warning because 2 certificates issued by the same CA have the same serial
number.

So now, the serial is a static variable initialized with now_ms (internal date
in milliseconds) and incremented at each new certificate generation.

(Ref MPS-2031)

9 years agoBUG/MEDIUM: http-reuse: do not share private connections across backends
Willy Tarreau [Tue, 2 Feb 2016 17:50:47 +0000 (18:50 +0100)] 
BUG/MEDIUM: http-reuse: do not share private connections across backends

When working on the previous bug, it appeared that it the case that was
triggering the bug would also work between two backends, one of which
doesn't support http-reuse. The reason is that while the idle connection
is moved to the private pool, upon reuse we only check if it holds the
CO_FL_PRIVATE flag. And we don't set this flag when there's no reuse.

So let's always set it in this case, it will guarantee that no undesired
connection sharing may happen.

This fix must be backported to 1.6.

9 years agoBUG/MAJOR: http-reuse: fix risk of orphaned connections
Willy Tarreau [Tue, 2 Feb 2016 17:29:05 +0000 (18:29 +0100)] 
BUG/MAJOR: http-reuse: fix risk of orphaned connections

There is a bug in connect_server() : we use si_attach_conn() to offer
the current session's connection to the session we're stealing the
connection from. Unfortunately, si_attach_conn() uses the standard data
connection operations while here we need to use the idle connection
operations.

This results in a situation where when the server's idle timeout strikes,
the read0 is silently ignored, causes the response channel to be shut down
for reads, and the connection remains attached. Next attempt to send a
request when using this connection simply results in nothing being done
because we try to send over an already closed connection. Worse, if the
client aborts, then no timeout remains at all and the session waits
forever and remains assigned to the server.

A more-or-less easy way to reproduce this bug is to have two concurrent
streams each connecting to a different server with "http-reuse aggressive",
typically a cache farm using a URL hash :

   stream1: GET /1 HTTP/1.1
   stream2: GET /2 HTTP/1.1
   stream1: GET /2 HTTP/1.1
   wait for the server 1's connection to timeout
   stream2: GET /1 HTTP/1.1

The connection hangs here, and "show sess all" shows a closed connection
with a SHUTR on the response channel.

The fix is very simple though not optimal. It consists in calling
si_idle_conn() again after attaching the connection. But in practise
it should not be done like this. The real issue is that there's no way
to cleanly attach a connection to a stream interface without changing
the connection's operations. So the API clearly needs to be revisited
to make such operations easier.

Many thanks to Yves Lafon from W3C for providing lots of useful dumps
and testing patches to help figure the root cause!

This fix must be backported to 1.6.

9 years agoDOC: remove old tunnel mode assumptions
Lukas Tribus [Wed, 3 Feb 2016 17:09:37 +0000 (18:09 +0100)] 
DOC: remove old tunnel mode assumptions

MichaÅ\82 Pasierb reported doc inconsistencies regarding the old default
HTTP tunnel mode.

This patch fixes a few of those inconsistencies and should be backported
to both 1.6 and 1.5.

9 years agoBUG: stream_interface: Reuse connection even if the output channel is empty
Christopher Faulet [Wed, 23 Dec 2015 08:33:35 +0000 (09:33 +0100)] 
BUG: stream_interface: Reuse connection even if the output channel is empty

in function 'si_connect', an existing connection is reused (and considered as
established) only when there are some pending data in the output channel.

This can be problem when filters are used, because a filter can choose to not
forward data immediatly. So when we try to initiate a connection to a server,
the output channel can be empty. In this situation, if the connection already
exists, it is not considered as established and nothing happens. If the stream
interface is in the state SI_ST_ASS, this leads to an infinite loop in
process_stream because it remains in this state.

This patch fixes this problem. Now, in 'si_connect', we always reuse an existing
connection, whether or not there are pending data in the output channel.

9 years agoMINOR: stats: send content-length with the redirect to allow keep-alive
Willy Tarreau [Tue, 26 Jan 2016 12:57:29 +0000 (13:57 +0100)] 
MINOR: stats: send content-length with the redirect to allow keep-alive

After a POST on the stats admin page, a 303 is emitted. Unfortunately
this 303 doesn't contain a content-length, which forces the connection
to be closed and reopened. Let's simply add a content-length: 0 to solve
this.

9 years agoBUG/CLEANUP: CLI: report the proper field states in "show sess"
Willy Tarreau [Mon, 25 Jan 2016 14:27:17 +0000 (15:27 +0100)] 
BUG/CLEANUP: CLI: report the proper field states in "show sess"

Commit 16f649c ("REORG: polling: rename "fd_spec" to "fd_cache"")
missed the server-facing connection during the rename, so the old
names are still in used and add a bit of confusion during the
debugging.

This should be backported to 1.6 and 1.5.

9 years agoMINOR: unix: don't mention free ports on EAGAIN
Lukas Tribus [Tue, 26 Jan 2016 19:33:14 +0000 (20:33 +0100)] 
MINOR: unix: don't mention free ports on EAGAIN

When a connect() to a unix socket returns EAGAIN we talk about
"no free ports" in the error/debug message, which only makes
sense when using TCP.

Explain connect() failure and suggest troubleshooting server
backlog size.

9 years agoBUG/MINOR: counters: make the sc-inc-gpc0 and sc-set-gpt0 touch the table
Willy Tarreau [Mon, 25 Jan 2016 13:54:45 +0000 (14:54 +0100)] 
BUG/MINOR: counters: make the sc-inc-gpc0 and sc-set-gpt0 touch the table

These two actions don't touch the table so the entry will expire and
the values will not be pushed to other peers. Also in the case of gpc0,
the gpc0_rate counter must be updated. The issue was reported by
Ruoshan Huang.

This fix needs to be backported to 1.6.

9 years agoBUG/MINOR: stream: don't force retries if the server is DOWN
Willy Tarreau [Wed, 13 Jan 2016 06:58:44 +0000 (07:58 +0100)] 
BUG/MINOR: stream: don't force retries if the server is DOWN

Arkadiy Kulev noticed that if a server is marked down while a connection
is being trying to establish, we still insist on performing retries on
the same server, which is absurd. Better perform the redispatch if we
already know the server is down. Because of this, it's likely that the
observe-l4 and sudden-death mechanisms are not optimal an cannot help
much the connection which was used to detect the problem.

The fix should be backported to 1.6 and 1.5 at least.

9 years agoBUG/MEDIUM: buffers: do not round up buffer size during allocation
Willy Tarreau [Mon, 25 Jan 2016 01:23:25 +0000 (02:23 +0100)] 
BUG/MEDIUM: buffers: do not round up buffer size during allocation

When users request 16384 bytes for a buffer, they get 16392 after
rounding up. This is problematic for SSL as it systematically
causes a small 8-bytes message to be appended after the first 16kB
message and costs about 15% of performance.

Let's add MEM_F_EXACT to use exactly the size we need. This requires
previous patch (MEDIUM: pools: add a new flag to avoid rounding pool
size up).

This issue was introduced in 1.6 and causes trouble there, so this
fix must be backported.

This is issue was reported by Gary Barrueto and diagnosed by Cyril Bonté.

9 years agoMEDIUM: pools: add a new flag to avoid rounding pool size up
Willy Tarreau [Mon, 25 Jan 2016 01:19:13 +0000 (02:19 +0100)] 
MEDIUM: pools: add a new flag to avoid rounding pool size up

Usually it's desirable to merge similarly sized pools, which is the
reason why their size is rounded up to the next multiple of 16. But
for the buffers this is problematic because we add the size of
struct buffer to the user-requested size, and the rounding results
in 8 extra bytes that are usable in the end. So the user gets more
bytes than asked for, and in case of SSL it results in short writes
for the extra bytes that are sent above multiples of 16 kB.

So we add a new flag MEM_F_EXACT to request that the size is not
rounded up when creating the entry. Thus it doesn't disable merging.

9 years agoBUG/MEDIUM: channel: fix miscalculation of available buffer space.
Willy Tarreau [Mon, 25 Jan 2016 00:09:11 +0000 (01:09 +0100)] 
BUG/MEDIUM: channel: fix miscalculation of available buffer space.

The function channel_recv_limit() relies on channel_reserved() which
itself relies on channel_in_transit(). Individually they're OK but
combined they're doing the wrong thing.

The problem is that we refrain from filling buffers while to_forward
is even much larger than the buffer because of a semantic issue along
the call chain. This is particularly visible when offloading SSL on
moderately large files (1 MB), though it is also visible on clear text.
Twice the number of recv() calls are made compared to what is needed,
and the typical performance drops by 15-20% in SSL in 1.6 and later,
and no directly measurable drop in 1.5 except when using strace.

There's no need for all these intermediate functions, so let's get
rid of them and reimplement channel_recv_limit() from scratch in a
safer way.

This fix needs to be backported to 1.6 and 1.5 (at least). Note that in
1.5 the function is called buffer_recv_limit() and it may differ a bit.

9 years agoBUG/MEDIUM: sample: http_date() doesn't provide the right day of the week
Cyril Bonté [Fri, 22 Jan 2016 18:40:28 +0000 (19:40 +0100)] 
BUG/MEDIUM: sample: http_date() doesn't provide the right day of the week

Gregor KovaÄ\8d reported that http_date() did not return the right day of the
week. For example "Sat, 22 Jan 2016 17:43:38 GMT" instead of "Fri, 22 Jan
2016 17:43:38 GMT". Indeed, gmtime() returns a 'struct tm' result, where
tm_wday begins on Sunday, whereas the code assumed it began on Monday.

This patch must be backported to haproxy 1.5 and 1.6.

9 years agoBUG/MEDIUM: config: Adding validation to stick-table expire value.
Ben Cabot [Wed, 20 Jan 2016 09:44:39 +0000 (09:44 +0000)] 
BUG/MEDIUM: config: Adding validation to stick-table expire value.

If the expire value exceedes the maximum value clients are not added
to the stick table.

9 years agoBUG/MEDIUM: servers state: server port is used uninitialized
Willy Tarreau [Thu, 21 Jan 2016 12:51:56 +0000 (13:51 +0100)] 
BUG/MEDIUM: servers state: server port is used uninitialized

Nenad spotted that the last fix was unfortunately wrong. Needs to be
backported to 1.6 as well.

9 years agoBUG/MAJOR: servers state: server port is erased when dns resolution is enabled on...
Baptiste Assmann [Wed, 20 Jan 2016 23:17:09 +0000 (00:17 +0100)] 
BUG/MAJOR: servers state: server port is erased when dns resolution is enabled on a server

Servers state function save and apply server IP when DNS resolution is
enabled on a server.
Purpose is to prevent switching traffic from one server to an other one
when multiple IPs are returned by the DNS server for the A or AAAA
record.

That said, a bug in current code lead to erase the service port while
copying the IP found in the file into the server structure in HAProxy's
memory.
This patch fix this bug.

The bug was reported on the ML by Robert Samuel Newson and fix proposed
by Nenad Merdanovic.
Thank you both!!!

backport: can be backported to 1.6

9 years agoBUG/MEDIUM: dns: no DNS resolution happens if no ports provided to the nameserver
Baptiste Assmann [Wed, 20 Jan 2016 23:59:46 +0000 (00:59 +0100)] 
BUG/MEDIUM: dns: no DNS resolution happens if no ports provided to the nameserver

Erez reported a bug on discourse.haproxy.org about DNS resolution not
occuring when no port is specified on the nameserver directive.

This patch prevent this behavior by returning an error explaining this
issue when parsing the configuration file.
That said, later, we may want to force port 53 when client did not
provide any.

backport: 1.6

9 years agoMINOR: server state: missing LF (\n) on error message printed when parsing server...
Baptiste Assmann [Wed, 20 Jan 2016 23:20:50 +0000 (00:20 +0100)] 
MINOR: server state: missing LF (\n) on error message printed when parsing server state file

There is no LF characters printed at the end of the error message
returned by the function when applying server state found in a file.

9 years agoMINOR: fix the return type for dns_response_get_query_id() function
Thiago Farina [Wed, 20 Jan 2016 22:46:34 +0000 (23:46 +0100)] 
MINOR: fix the return type for dns_response_get_query_id() function

This function should return a 16-bit type as that is the type for
dns header id.
Also because it is doing an uint16 unpack big-endian operation.

Backport: can be backported to 1.6

Signed-off-by: Thiago Farina <tfarina@chromium.org>
Signed-off-by: Baptiste Assmann <bedis9@gmail.com>
9 years agoBUG/MINOR: examples: Fixing haproxy.spec to remove references to .cfg files
Chris Short [Mon, 18 Jan 2016 14:11:04 +0000 (09:11 -0500)] 
BUG/MINOR: examples: Fixing haproxy.spec to remove references to .cfg files

Building RPMs from the provided haproxy.spec fails due to references to
config files that do not exist.

I should point out, this patch will inevitably create an empty /etc/haproxy
dir and I'm not sure that's desirable/intended.

9 years agoDOC: fix "workaround" spelling
Willy Tarreau [Fri, 15 Jan 2016 09:26:26 +0000 (10:26 +0100)] 
DOC: fix "workaround" spelling

"a workaround", "to work around", and not "to walk around".
Thanks to Lukas for reporting.

9 years agoDOC: fix a few spelling mistakes
fengpeiyuan [Fri, 15 Jan 2016 08:40:53 +0000 (16:40 +0800)] 
DOC: fix a few spelling mistakes

9 years agoMINOR: rename master process name in -Ds (systemd mode)
William Lallemand [Thu, 14 Jan 2016 17:10:30 +0000 (18:10 +0100)] 
MINOR: rename master process name in -Ds (systemd mode)

To avoid confusion between the master process and child processes,
the master process is renamed after the forks.

9 years agoCLEANUP: 51d: Aligned if statements with HAProxy best practices and removed casts...
ben@51degrees.com [Fri, 8 Jan 2016 13:52:32 +0000 (13:52 +0000)] 
CLEANUP: 51d: Aligned if statements with HAProxy best practices and removed casts from malloc.

Changes to if statements do not affect code operation, just layout of
the code. Type casts from malloc returns have been removed as this cast
happens automatically from the void* type.

This may be backported to 1.6.

9 years agoBUG/MINOR: 51d: Aligned const pointers to changes in 51Degrees.
ben@51degrees.com [Fri, 8 Jan 2016 13:49:32 +0000 (13:49 +0000)] 
BUG/MINOR: 51d: Aligned const pointers to changes in 51Degrees.

Parameters provided to 51Degrees methods that have changed to require
const pointers are now cast to avoid compiler warnings.

This should be backported to 1.6.

9 years agoBUG/MINOR: 51d: Releases workset back to pool.
ben@51degrees.com [Fri, 8 Jan 2016 13:48:37 +0000 (13:48 +0000)] 
BUG/MINOR: 51d: Releases workset back to pool.

The workset is now released correctly when a cache hit occurs.

This should be backported to 1.6.

9 years agoBUG/MINOR: 51d: Aligns Pattern cache implementation with HAProxy best practices.
ben@51degrees.com [Fri, 8 Jan 2016 13:47:46 +0000 (13:47 +0000)] 
BUG/MINOR: 51d: Aligns Pattern cache implementation with HAProxy best practices.

Malloc continues to be used for the creation of cache entries. The
implementation has been enhanced ready for production deployment. A new
method to free cache entries created in 51d.c has been added to ensure
memory is released correctly.

This should be backported to 1.6.

9 years agoBUG/MINOR: 51d: Ensures a unique domain for each configuration
ben@51degrees.com [Fri, 8 Jan 2016 13:42:41 +0000 (13:42 +0000)] 
BUG/MINOR: 51d: Ensures a unique domain for each configuration

Args pointer is now used as the LRU cache domain to ensure the cache
distinguishes between multiple fetch and conv configurations.

This should be backported to 1.6.

9 years agoDOC: add Ben Shillito as the maintainer of 51d
Ben Shillito [Mon, 11 Jan 2016 17:33:24 +0000 (17:33 +0000)] 
DOC: add Ben Shillito as the maintainer of 51d

you can put me down as the maintainer with this email.

This should be backported to 1.6.

9 years agoMINOR: lru: new function to delete <nb> least recently used keys
Baptiste Assmann [Thu, 7 Jan 2016 01:28:50 +0000 (02:28 +0100)] 
MINOR: lru: new function to delete <nb> least recently used keys

Introduction of a new function in the LRU cache source file.
Purpose of this function is to be used to delete a number of entries in
the cache. 'number' is defined by the caller and the key removed are
taken at the tail of the tree

9 years agoMINOR: tools: make csv_enc_append() always start at the first byte of the chunk
Willy Tarreau [Fri, 8 Jan 2016 09:04:08 +0000 (10:04 +0100)] 
MINOR: tools: make csv_enc_append() always start at the first byte of the chunk

csv_enc_append() returns a pointer to the beginning of the encoded
string, which makes it convenient to use in printf(). However it's not
convenient for use in chunks as it may leave an unused byte at the
beginning depending on the automatic quoting. Let's modify it to work
in two passes. First it looks for a character that requires escaping
using strpbrk(), and second it encodes the string. This way it
guarantees to always start at the first available byte of the chunk.
Additionally it made the code quite simpler.

9 years agoMEDIUM: tools: add csv_enc_append() to preserve the original chunk
Willy Tarreau [Wed, 6 Jan 2016 17:07:04 +0000 (18:07 +0100)] 
MEDIUM: tools: add csv_enc_append() to preserve the original chunk

We have csv_enc() but there's no way to append some CSV-encoded data
to an existing chunk, so here we modify the existing function for this
and create an inlined version of csv_enc() which first resets the output
chunk. It will be handy to append data to an existing chunk without
having to use an extra temporary chunk, or to encode multiple strings
into a single chunk with chunk_newstr().

The patch is quite small, in fact most changes are typo fixes in the
comments.

9 years agoMINOR: chunk: make chunk_initstr() take a const string
Willy Tarreau [Wed, 6 Jan 2016 19:45:03 +0000 (20:45 +0100)] 
MINOR: chunk: make chunk_initstr() take a const string

chunk_initstr() prepares a read-only chunk from a string of
fixed length. Thus it must be prepared to accept a read-only
string on the input, otherwise the caller has to force-cast
some const char* and that's not a good idea.

9 years agoMINOR: chunks: add chunk_strcat() and chunk_newstr()
Willy Tarreau [Mon, 4 Jan 2016 19:13:55 +0000 (20:13 +0100)] 
MINOR: chunks: add chunk_strcat() and chunk_newstr()

These two new functions will make it easier to manipulate small strings
from within functions, because at many places, multiple short strings
are needed which do not deserve a malloc() nor a free(), and alloca()
is often discouraged. Since we already have trash chunks, it's convenient
to be able to allocate substrings from a chunk and use them later since
our functions already perform all the length checks. chunk_newstr() adds
a trailing zero at the end of a chunk and returns the pointer to the next
character, which can be used as an independant string. chunk_strcat()
does what it says.

9 years agoMINOR: chunks: ensure that chunk_strcpy() adds a trailing zero
Willy Tarreau [Mon, 4 Jan 2016 19:21:33 +0000 (20:21 +0100)] 
MINOR: chunks: ensure that chunk_strcpy() adds a trailing zero

Since thus function bears the name of a well-known string function, it
must at least promise compatible semantics. Here it means always adding
the trailing zero so that anyone willing to use chunk->str as a regular
string can do it. Of course the zero is not counted in the chunk's length.

9 years agoDOC: ssl: fixed some formatting errors in crt tag
yanbzhu [Tue, 5 Jan 2016 17:52:02 +0000 (12:52 -0500)] 
DOC: ssl: fixed some formatting errors in crt tag

Fixed grammar error in crt tag as well as fixed table in example.

9 years agoBUG/MINOR: chunk: make chunk_dup() always check and set dst->size
Willy Tarreau [Mon, 4 Jan 2016 19:36:59 +0000 (20:36 +0100)] 
BUG/MINOR: chunk: make chunk_dup() always check and set dst->size

chunk_dup() was affected by two bugs at once related to dst->size :
  - first, it didn't check dst->size to know if it could free(dst->str),
    so using it on a statically allocated chunk would cause a free(constant)
    and crash the process ;

  - second, it didn't properly set dst->size, possibly causing smaller
    strings not to be properly reported in a chunk that was previously
    used for something else.

Fortunately, neither of these situations ever happened since the function
is rarely used.

In the process of doing this, we even allocate one more byte for a
trailing zero if the input chunk was not full, so that the copied
string can safely be reused by standard string functions.

The bug was introduced in 1.3.4 nine years ago with this commit :

  0f77253 ("[MINOR] store HTTP error messages into a chunk array")

It's better to backport this fix in case a future fix relies on it.

9 years agoMINOR: filters/http: Use a wrapper function instead of stream_int_retnclose
Christopher Faulet [Wed, 9 Dec 2015 14:55:06 +0000 (15:55 +0100)] 
MINOR: filters/http: Use a wrapper function instead of stream_int_retnclose

The function http_reply_and_close has been added in proto_http.c to wrap calls
to stream_int_retnclose. This functions will be modified when the filters will
be added.

9 years agoBUG/MINOR: http: Be sure to process all the data received from a server
Christopher Faulet [Fri, 19 Jun 2015 07:00:58 +0000 (09:00 +0200)] 
BUG/MINOR: http: Be sure to process all the data received from a server

When the response body is forwarded, if the server closes the input before the
end, an error is thrown. But if the data processing is too slow, all data could
already be received and pending in the input buffer. So this is a bug to stop
processing in this context. The server doesn't really closed the input before
the end.

As an example, this could happen when HAProxy is configured to do compression
offloading. If the server closes the connection explicitly after the response
(keep-alive disabled by the server) and if HAProxy receives the data faster than
they are compressed, then the response could be truncated.

This patch fixes the bug by checking if some pending data remain in the input
buffer before returning an error. If yes, the processing continues.

9 years agoBUG/MINOR: http: fix several off-by-one errors in the url_param parser
Willy Tarreau [Sun, 27 Dec 2015 13:51:01 +0000 (14:51 +0100)] 
BUG/MINOR: http: fix several off-by-one errors in the url_param parser

Several cases of "<=" instead of "<" were found in the url_param parser,
mostly affecting the case where the parameter is wrapping. They shouldn't
affect header operations, just body parsing in a wrapped pipelined request.

The code is a bit complicated with certain operations done multiple times
in multiple functions, so it's not sure others are not left. This code
must be re-audited.

It should only be backported to 1.6 once carefully tested, because it is
possible that other bugs relied on these ones.

9 years agoMINOR: lua: add set/get priv for applets
Thierry FOURNIER [Fri, 25 Dec 2015 00:33:18 +0000 (01:33 +0100)] 
MINOR: lua: add set/get priv for applets

The applet can't have access to the session private data. This patch
fix this problem. Now an applet can use private data stored by actions
and fecthes.

9 years agoDOC: lua: fix somme errors and add implicit types
Thierry FOURNIER [Fri, 25 Dec 2015 00:31:35 +0000 (01:31 +0100)] 
DOC: lua: fix somme errors and add implicit types

This patch fix some errors and adds implicit types for AppletHTTP
and AppletTCP.

Should be backported in 1.6

9 years agoBUG/MINOR: stream: bad return code
Thierry FOURNIER [Thu, 26 Nov 2015 18:48:04 +0000 (19:48 +0100)] 
BUG/MINOR: stream: bad return code

In error case, we expect the enum ACT_RET_PRS_ERR, but the
function "stream_parse_use_service()" returns "-1"

This patch must be backported in 1.6

9 years agoBUILD/MINOR: regex: missing header
Thierry FOURNIER [Thu, 26 Nov 2015 18:33:54 +0000 (19:33 +0100)] 
BUILD/MINOR: regex: missing header

When HAProxy is compiled with pcre, strlen() is used, but <string.h>
is not included.

This patch must be backported in 1.6

9 years agoDOC: compression: missing mention of libslz for compression algorithm
Baptiste Assmann [Mon, 21 Dec 2015 16:57:32 +0000 (17:57 +0100)] 
DOC: compression: missing mention of libslz for compression algorithm

Compression algorithm documentation only mention zlib, while HAProxy
also support libslz, which is much lighter and faster.

9 years agoDOC: mailers: typo in 'hostname' description
Baptiste Assmann [Mon, 21 Dec 2015 14:27:53 +0000 (15:27 +0100)] 
DOC: mailers: typo in 'hostname' description

fixed a typo caused by a copy/paste where <hostname> parameter
description was replaced by <emailaddr>...

9 years agoDOC: lua: fix lua API
Thierry FOURNIER [Mon, 21 Dec 2015 10:13:52 +0000 (11:13 +0100)] 
DOC: lua: fix lua API

This patch fix the Lua API documentation, and adds some internal link
between values returned and associated class.

This patch can be backported in 1.6.

9 years ago[RELEASE] Released version 1.7-dev1 v1.7-dev1
Willy Tarreau [Sun, 20 Dec 2015 22:33:18 +0000 (23:33 +0100)] 
[RELEASE] Released version 1.7-dev1

Released version 1.7-dev1 with the following main changes :
    - DOC: specify that stats socket doc (section 9.2) is in management
    - BUILD: install only relevant and existing documentation
    - CLEANUP: don't ignore debian/ directory if present
    - BUG/MINOR: dns: parsing error of some DNS response
    - BUG/MEDIUM: namespaces: don't fail if no namespace is used
    - BUG/MAJOR: ssl: free the generated SSL_CTX if the LRU cache is disabled
    - MEDIUM: dns: Don't use the ANY query type
    - BUILD: ssl: fix build error introduced in commit 7969a3 with OpenSSL < 1.0.0
    - DOC: fix a typo for a "deviceatlas" keyword
    - FIX: small typo in an example using the "Referer" header
    - MINOR: cli: ability to set per-server maxconn
    - DEBUG/MINOR: memory: add a build option to disable memory pools sharing
    - DEBUG/MEDIUM: memory: optionally protect free data in pools
    - DEBUG/MEDIUM: memory: add optional control pool memory operations
    - MEDIUM: memory: add accounting for failed allocations
    - BUG/MEDIUM: config: count memory limits on 64 bits, not 32
    - BUG/MAJOR: dns: first DNS response packet not matching queried hostname may lead to a loop
    - BUG/MINOR: dns: unable to parse CNAMEs response
    - BUG/MINOR: examples/haproxy.init: missing brace in quiet_check()
    - DOC: deviceatlas: more example use cases.
    - MINOR: config: allow IPv6 bracketed literals
    - BUG/BUILD: replace haproxy-systemd-wrapper with $(EXTRA) in install-bin.
    - BUILD: add Haiku as supported target.
    - BUG/MAJOR: http: don't requeue an idle connection that is already queued
    - DOC: typo on capture.res.hdr and capture.req.hdr
    - BUG/MINOR: dns: check for duplicate nameserver id in a resolvers section was missing
    - CLEANUP: use direction names in place of numeric values
    - BUG/MEDIUM: lua: sample fetches based on response doesn't work
    - MINOR: check: add agent-send server parameter
    - BUG/MINOR: http rule: http capture 'id' rule points to a non existing id
    - BUG/MINOR: server: check return value of fgets() in apply_server_state()
    - BUG/MINOR: acl: don't use record layer in req_ssl_ver
    - BUILD: freebsd: double declaration
    - BUG/MEDIUM: lua: clean output buffer
    - BUILD: check for libressl to be able to build against it
    - DOC: lua-api/index.rst small example fixes, spelling correction.
    - DOC: lua: architecture and first steps
    - DOC: relation between timeout http-request and option http-buffer-request
    - BUILD: Make deviceatlas require PCRE
    - BUG: http: do not abort keep-alive connections on server timeout
    - BUG/MEDIUM: http: switch the request channel to no-delay once done.
    - BUG/MINOR: lua: don't force-sslv3 LUA's SSL socket
    - BUILD/MINOR: http: proto_http.h needs sample.h
    - BUG/MEDIUM: http: don't enable auto-close on the response side
    - BUG/MEDIUM: stream: fix half-closed timeout handling
    - CLEANUP: compression: don't allocate DEFAULT_MAXZLIBMEM without USE_ZLIB
    - BUG/MEDIUM: cli: changing compression rate-limiting must require admin level
    - BUG/MEDIUM: sample: urlp can't match an empty value
    - BUILD: dumpstats: silencing warning for printf format specifier / time_t
    - CLEANUP: proxy: calloc call inverted arguments
    - MINOR: da: silent logging by default and displaying DeviceAtlas support if built.
    - BUG/MEDIUM: da: stop DeviceAtlas processing in the convertor if there is no input.
    - DOC: Edited 51Degrees section of README/
    - BUG/MEDIUM: checks: email-alert not working when declared in defaults
    - BUG/MINOR: checks: email-alert causes a segfault when an unknown mailers section is configured
    - BUG/MINOR: checks: typo in an email-alert error message
    - BUG/MINOR: tcpcheck: conf parsing error when no port configured on server and last rule is a CONNECT with no port
    - BUG/MINOR: tcpcheck: conf parsing error when no port configured on server and first rule(s) is (are) COMMENT
    - BUG/MEDIUM: http: fix http-reuse when frontend and backend differ
    - DOC: prefer using http-request/response over reqXXX/rspXXX directives
    - CLEANUP: haproxy: using _GNU_SOURCE instead of __USE_GNU macro.
    - MINOR: ssl: Added cert_key_and_chain struct
    - MEDIUM: ssl: Added support for creating SSL_CTX with multiple certs
    - MINOR: ssl: Added multi cert support for crt-list config keyword
    - MEDIUM: ssl: Added multi cert support for loading crt directories
    - MEDIUM: ssl: Added support for Multi-Cert OCSP Stapling
    - BUILD: ssl: set SSL_SOCK_NUM_KEYTYPES with openssl < 1.0.2
    - MINOR: config: make tune.recv_enough configurable
    - BUG/MEDIUM: config: properly adjust maxconn with nbproc when memmax is forced
    - DOC: ssl: Adding docs for Multi-Cert bundling
    - BUG/MEDIUM: peers: table entries learned from a remote are pushed to others after a random delay.
    - BUG/MEDIUM: peers: old stick table updates could be repushed.
    - MINOR: lua: service/applet can have access to the HTTP headers when a POST is received
    - REORG/MINOR: lua: convert boolean "int" to bitfield
    - BUG/MEDIUM: lua: Lua applets must not fetch samples using http_txn
    - BUG/MINOR: lua: Lua applets must not use http_txn
    - BUG/MEDIUM: lua: Forbid HTTP applets from being called from tcp rulesets
    - BUG/MAJOR: lua: Do not force the HTTP analysers in use-services
    - CLEANUP: lua: bad error messages
    - CONTRIB: initiate a debugging suite to make debugging easier

9 years agoCONTRIB: initiate a debugging suite to make debugging easier
Willy Tarreau [Sun, 20 Dec 2015 22:21:57 +0000 (23:21 +0100)] 
CONTRIB: initiate a debugging suite to make debugging easier

The goal is to have a collection of quick-n-dirty utilities that make
debugging easier and that can easily be modified when needed. The first
utility in this series is called "flags". For a given numeric argument,
it reports the various known combinations of flags for channels, streams
and so on. This way it's easy to copy-paste values from the CLI or from
gdb and immediately know what state a stream-interface or connection is
in.

9 years agoCLEANUP: lua: bad error messages
Thierry FOURNIER [Sun, 20 Dec 2015 18:51:06 +0000 (19:51 +0100)] 
CLEANUP: lua: bad error messages

An error message reference "register_service" in place of
"register_action".

This one should be backported to 1.6.

9 years agoBUG/MAJOR: lua: Do not force the HTTP analysers in use-services
Thierry FOURNIER [Sun, 20 Dec 2015 18:14:35 +0000 (19:14 +0100)] 
BUG/MAJOR: lua: Do not force the HTTP analysers in use-services

INNER and XFERBODY analyzer were set in order to support HTTP applets
from TCP rulesets, but this does not work (cf previous patch).

Other cases already provides theses analyzers, so their addition is
not needed. Furthermore if INNER was set it could cause some headers
to be rewritten (ex: connection) after headers were already forwarded,
resulting in a crash in buffer_insert_line2().

Special thanks to Bernd Helm for providing very detailed information,
captures and stack traces making it possible to spot the root cause
here.

This fix must be backported to 1.6.

9 years agoBUG/MEDIUM: lua: Forbid HTTP applets from being called from tcp rulesets
Thierry FOURNIER [Sun, 20 Dec 2015 19:13:14 +0000 (20:13 +0100)] 
BUG/MEDIUM: lua: Forbid HTTP applets from being called from tcp rulesets

HTTP applets request requires everything initilized by
"http_process_request" (analyzer flag AN_REQ_HTTP_INNER).
The applet will be immediately initilized, but its before
the call of this analyzer.

Due to this problem HTTP applets could be called with uncompletely
initialized http_txn.

This fix must be backported to 1.6.

9 years agoBUG/MINOR: lua: Lua applets must not use http_txn
Thierry FOURNIER [Sun, 20 Dec 2015 18:14:52 +0000 (19:14 +0100)] 
BUG/MINOR: lua: Lua applets must not use http_txn

In certain circumstances (eg: Lua HTTP applet called from a
TCP ruleset before http_process_request()), the HTTP TXN is not
yet fully initialized so some information it contains cannot be
relied on. Such information include the HTTP version, the state
of the expect: 100-continue header, the connection header and
the transfer-encoding header.

Here the bug only turns something which already doesn't work
into something wrong, but better avoid any references to the
http_txn from the Lua code to avoid future mistakes.

This patch should be backported into 1.6 for code consistency.

9 years agoBUG/MEDIUM: lua: Lua applets must not fetch samples using http_txn
Thierry FOURNIER [Sun, 20 Dec 2015 17:43:03 +0000 (18:43 +0100)] 
BUG/MEDIUM: lua: Lua applets must not fetch samples using http_txn

If a sample fetch needing http_txn is called from an HTTP Lua applet,
the result will be invalid and may even cause a crash because some HTTP
data can be forwarded and the HTTP txn is no longer valid.

Here the solution is to ensure that a fetch called from Lua never
needs http_txn. This is done thanks to a new flag HLUA_F_MAY_USE_HTTP
which indicates whether or not it is safe to call a fetch which needs
HTTP.

This fix needs to be backported to 1.6.

9 years agoREORG/MINOR: lua: convert boolean "int" to bitfield
Thierry FOURNIER [Sun, 20 Dec 2015 17:42:25 +0000 (18:42 +0100)] 
REORG/MINOR: lua: convert boolean "int" to bitfield

This patch converts a boolean "int" to a bitfiled. The main
reason is to save space in the struct if another flag may will
be require.

Note that this patch is required for next fix and will need to be
backported to 1.6.

9 years agoMINOR: lua: service/applet can have access to the HTTP headers when a POST is received
Thierry FOURNIER [Fri, 11 Dec 2015 16:10:09 +0000 (17:10 +0100)] 
MINOR: lua: service/applet can have access to the HTTP headers when a POST is received

When a POST is processed by a Lua service, the HTTP header are
potentially gone. So, we cannot retrieve their content using
the standard "hdr" sample fetchs (which will soon become invalid
anyway) from an applet.

This patch add an entry "headers" to the object applet_http. This
entry is an array containing all the headers. It permits to use the
HTTP headers during the processing of the service.

Many thanks to Jan Bruder for reporting this issue with enough
details to reproduce it.

This patch will have to be backported to 1.6 since it will be the
only way to access headers from Lua applets.

9 years agoBUG/MEDIUM: peers: old stick table updates could be repushed.
Emeric Brun [Wed, 16 Dec 2015 14:28:12 +0000 (15:28 +0100)] 
BUG/MEDIUM: peers: old stick table updates could be repushed.

Because the stick table updates tree was not properly initialized to EB_ROOT_UNIQUE.

9 years agoBUG/MEDIUM: peers: table entries learned from a remote are pushed to others after...
Emeric Brun [Wed, 16 Dec 2015 14:16:46 +0000 (15:16 +0100)] 
BUG/MEDIUM: peers: table entries learned from a remote are pushed to others after a random delay.

New sticktable entries learned from a remote peer can be pushed to others after
a random delay because they are not inserted at the right position in the updates
tree.

9 years agoDOC: ssl: Adding docs for Multi-Cert bundling
yanbzhu [Mon, 14 Dec 2015 20:10:25 +0000 (15:10 -0500)] 
DOC: ssl: Adding docs for Multi-Cert bundling

Added entries in crt and crt-list to document multi-cert bundling.

9 years agoBUG/MEDIUM: config: properly adjust maxconn with nbproc when memmax is forced
Willy Tarreau [Mon, 14 Dec 2015 11:46:07 +0000 (12:46 +0100)] 
BUG/MEDIUM: config: properly adjust maxconn with nbproc when memmax is forced

When memmax is forced using "-m", the per-process memory limit is enforced
using setrlimit(), but this value is not used to compute the automatic
maxconn limit. In addition, the per-process memory limit didn't consider
the fact that the shared SSL cache only needs to be accounted once.

The doc was also fixed to clearly state that "-m" is global and not per
process. It makes sense because people who use -m want to protect the
system's resources regardless of whatever appears in the configuration.

9 years agoMINOR: config: make tune.recv_enough configurable
Willy Tarreau [Mon, 14 Dec 2015 11:04:35 +0000 (12:04 +0100)] 
MINOR: config: make tune.recv_enough configurable

This setting used to be assigned to a variable tunable from a constant
and for an unknown reason never made its way into the config parser.

tune.recv_enough <number>
  Haproxy uses some hints to detect that a short read indicates the end of the
  socket buffers. One of them is that a read returns more than <recv_enough>
  bytes, which defaults to 10136 (7 segments of 1448 each). This default value
  may be changed by this setting to better deal with workloads involving lots
  of short messages such as telnet or SSH sessions.

9 years agoBUILD: ssl: set SSL_SOCK_NUM_KEYTYPES with openssl < 1.0.2
Willy Tarreau [Mon, 14 Dec 2015 10:28:33 +0000 (11:28 +0100)] 
BUILD: ssl: set SSL_SOCK_NUM_KEYTYPES with openssl < 1.0.2

Last patch unfortunately broke build with openssl older than 1.0.2.
Let's just define a single key type in this case.

9 years agoMEDIUM: ssl: Added support for Multi-Cert OCSP Stapling
yanbzhu [Thu, 10 Dec 2015 20:07:30 +0000 (15:07 -0500)] 
MEDIUM: ssl: Added support for Multi-Cert OCSP Stapling

Enabled loading of OCSP staple responses (.ocsp files) when processing a
bundled certificate with multiple keytypes.

9 years agoMEDIUM: ssl: Added multi cert support for loading crt directories
yanbzhu [Wed, 9 Dec 2015 18:35:14 +0000 (13:35 -0500)] 
MEDIUM: ssl: Added multi cert support for loading crt directories

Loading of multiple certs into shared contexts is now supported if a user
specifies a directory instead of a cert file.

9 years agoMINOR: ssl: Added multi cert support for crt-list config keyword
yanbzhu [Wed, 2 Dec 2015 18:54:14 +0000 (13:54 -0500)] 
MINOR: ssl: Added multi cert support for crt-list config keyword

Added support for loading mutiple certs into shared contexts when they
are specified in a crt-list

Note that it's not practical to support SNI filters with multicerts, so
any SNI filters that's provided to the crt-list is ignored if a
multi-cert opertion is used.

9 years agoMEDIUM: ssl: Added support for creating SSL_CTX with multiple certs
yanbzhu [Wed, 2 Dec 2015 18:01:29 +0000 (13:01 -0500)] 
MEDIUM: ssl: Added support for creating SSL_CTX with multiple certs

Added ability for users to specify multiple certificates that all relate
a single server. Users do this by specifying certificate "cert_name.pem"
but having "cert_name.pem.rsa", "cert_name.pem.dsa" and/or
"cert_name.pem.ecdsa" in the directory.

HAProxy will now intelligently search for those 3 files and try combine
them into as few SSL_CTX's as possible based on CN/SAN. This will allow
HAProxy to support multiple ciphersuite key algorithms off a single
SSL_CTX.

This change integrates into the existing architecture of SNI lookup and
multiple SNI's can point to the same SSL_CTX, which can support multiple
key_types.

9 years agoMINOR: ssl: Added cert_key_and_chain struct
yanbzhu [Tue, 1 Dec 2015 20:16:07 +0000 (15:16 -0500)] 
MINOR: ssl: Added cert_key_and_chain struct

Added cert_key_and_chain struct to ssl. This struct will store the
contents of a crt path (from the config file) into memory. This will
allow us to use the data stored in memory instead of reading the file
multiple times.

This will be used to support a later commit to load multiple pkeys/certs
into a single SSL_CTX

9 years agoCLEANUP: haproxy: using _GNU_SOURCE instead of __USE_GNU macro.
David Carlier [Tue, 8 Dec 2015 21:43:09 +0000 (21:43 +0000)] 
CLEANUP: haproxy: using _GNU_SOURCE instead of __USE_GNU macro.

In order to properly enable sched_setaffinity, in some versions of Linux,
it is rather _GNU_SOURCE than __USE_GNU (spotted on Alpine Linux for instance),
also for the sake of consistency as __USE_GNU seems not used across the code and
for last, it seems on Linux it is the best way to enable non portable code.
On Linux glibc's based versions, it seems _GNU_SOURCE defines __USE_GNU
it should be safe enough.

9 years agoDOC: prefer using http-request/response over reqXXX/rspXXX directives
Ruoshan Huang [Tue, 8 Dec 2015 13:00:23 +0000 (21:00 +0800)] 
DOC: prefer using http-request/response over reqXXX/rspXXX directives

add referrence for "http-request" or "http-response" in reqXXX/rspXXX
directives.

add a paragraph in "http-request" and "http-response" stating that
reqXXX/rspXXX directives are discouraged

9 years agoBUG/MEDIUM: http: fix http-reuse when frontend and backend differ
Willy Tarreau [Mon, 7 Dec 2015 16:04:59 +0000 (17:04 +0100)] 
BUG/MEDIUM: http: fix http-reuse when frontend and backend differ

Krishna Kumar reported that the following configuration doesn't permit
HTTP reuse between two clients :

    frontend private-frontend
        mode http
        bind :8001
        default_backend private-backend

    backend private-backend
        mode http
        http-reuse always
        server bck 127.0.0.1:8888

The reason for this is that in http_end_txn_clean_session() we check the
stream's backend backend's http-reuse option before deciding whether the
backend connection should be moved back to the server's pool or not. But
since we're doing this after the call to http_reset_txn(), the backend is
reset to match the frontend, which doesn't have the option. However it
will work fine in a setup involving a "listen" section.

We just need to keep a pointer to the current backend before calling
http_reset_txn(). The code does that and replaces the few remaining
references to s->be inside the same function so that if any part of
code were to be moved later, this trap doesn't happen again.

This fix must be backported to 1.6.

9 years agoBUG/MINOR: tcpcheck: conf parsing error when no port configured on server and first...
Baptiste Assmann [Fri, 4 Dec 2015 05:49:31 +0000 (06:49 +0100)] 
BUG/MINOR: tcpcheck: conf parsing error when no port configured on server and first rule(s) is (are) COMMENT

A small configuration parsing error exists when no port is setup on the
server IP:port statement and the server's parameter 'port' is not set
and if the first tcp-check rule is a comment, like in the example below:

  backend b
   option tcp-check
   tcp-check comment blah
   tcp-check connect 8444
   server s 127.0.0.1 check

In such case, an ALERT is improperly returned, despite this
configuration is valid and works.

The new code move the pointer to the first tcp-check rule which isn't a
comment before checking the presence of the port.

backport status: 1.6 and above

9 years agoBUG/MINOR: tcpcheck: conf parsing error when no port configured on server and last...
Baptiste Assmann [Fri, 4 Dec 2015 05:57:25 +0000 (06:57 +0100)] 
BUG/MINOR: tcpcheck: conf parsing error when no port configured on server and last rule is a CONNECT with no port

Current configuration parsing is permissive in such situation:
A server in a backend with no port conigured on the IP address
statement, no 'port' parameter configured and last rule of a tcp-check
is a CONNECT with no port.

The current code currently parses all the rules to validate a port is
well available, but it misses the last one, which means such
configuration is valid:

  backend b
   option tcp-check
   tcp-check connect port 8444
   tcp-check connect
   server s 127.0.0.1 check

the second connect tentative is sent to port '0'...

Current patch fixes this by parsing the list the right way, including
the last rule.

backport status: 1.6 and above

9 years agoBUG/MINOR: checks: typo in an email-alert error message
Cyril Bonté [Fri, 4 Dec 2015 02:07:08 +0000 (03:07 +0100)] 
BUG/MINOR: checks: typo in an email-alert error message

When the email alert message couldn't be formatted, the logged error message
said the contrary.

This fix must be backported to 1.6.

9 years agoBUG/MINOR: checks: email-alert causes a segfault when an unknown mailers section...
Cyril Bonté [Fri, 4 Dec 2015 02:07:07 +0000 (03:07 +0100)] 
BUG/MINOR: checks: email-alert causes a segfault when an unknown mailers section is configured

A segfault can occur during at the initialization phase, when an unknown
"mailers" name is configured. This happens when "email-alert myhostname" is not
set, where a direct pointer to an array is used instead of copying the string,
causing the segfault when haproxy tries to free the memory.

This is a minor issue because the configuration is invalid and a fatal error
will remain, but it should be fixed to prevent reload issues.

Example of minimal configuration to reproduce the bug :
    backend example
        email-alert mailers NOT_FOUND
        email-alert from foo@localhost
        email-alert to bar@localhost

This fix must be backported to 1.6.

9 years agoBUG/MEDIUM: checks: email-alert not working when declared in defaults
Cyril Bonté [Fri, 4 Dec 2015 02:07:06 +0000 (03:07 +0100)] 
BUG/MEDIUM: checks: email-alert not working when declared in defaults

Tommy Atkinson and Sylvain Faivre reported that email alerts didn't work when
they were declared in the defaults section. This is due to the use of an
internal attribute which is set once an email-alert is at least partially
configured. But this attribute was not propagated to the current proxy during
the configuration parsing.

Not that the issue doesn't occur if "email-alert myhostname" is configured in
the defaults section.

This fix must be backported to 1.6.

9 years agoDOC: Edited 51Degrees section of README/
Ben Shillito [Thu, 3 Dec 2015 10:36:20 +0000 (10:36 +0000)] 
DOC: Edited 51Degrees section of README/

9 years agoBUG/MEDIUM: da: stop DeviceAtlas processing in the convertor if there is no input.
David Carlier [Wed, 2 Dec 2015 12:05:42 +0000 (12:05 +0000)] 
BUG/MEDIUM: da: stop DeviceAtlas processing in the convertor if there is no input.

In case a HTTP header modifier, like req*del, is used, the User-Agent would be removed
and cause a segfault, hence the work is stopped in due time.

9 years agoMINOR: da: silent logging by default and displaying DeviceAtlas support if built.
David Carlier [Wed, 2 Dec 2015 11:22:53 +0000 (11:22 +0000)] 
MINOR: da: silent logging by default and displaying DeviceAtlas support if built.

9 years agoCLEANUP: proxy: calloc call inverted arguments
David CARLIER [Wed, 25 Nov 2015 15:27:36 +0000 (15:27 +0000)] 
CLEANUP: proxy: calloc call inverted arguments

Nothing major but a human typo mistake.

9 years agoBUILD: dumpstats: silencing warning for printf format specifier / time_t
David Carlier [Wed, 18 Nov 2015 06:10:22 +0000 (06:10 +0000)] 
BUILD: dumpstats: silencing warning for printf format specifier / time_t

time_t is not necesseraly a long int (spotted in OpenBSD), so just an explicit cast to
avoid the compiler warning. should be safe enough.

9 years agoBUG/MEDIUM: sample: urlp can't match an empty value
Cyril Bonté [Thu, 26 Nov 2015 20:39:56 +0000 (21:39 +0100)] 
BUG/MEDIUM: sample: urlp can't match an empty value

Currently urlp fetching samples were able to find parameters with an empty
value, but the return code depended on the value length. The final result was
that acls using urlp couldn't match empty values.

Example of acl which always returned "false":
  acl MATCH_EMPTY urlp(foo) -m len 0

The fix consists in unconditionally return 1 when the parameter is found.

This fix must be backported to 1.6 and 1.5.

9 years agoBUG/MEDIUM: cli: changing compression rate-limiting must require admin level
Willy Tarreau [Thu, 26 Nov 2015 17:32:39 +0000 (18:32 +0100)] 
BUG/MEDIUM: cli: changing compression rate-limiting must require admin level

Right now it's possible to change the global compression rate limiting
without the CLI being at the admin level.

This fix must be backported to 1.6 and 1.5.

9 years agoCLEANUP: compression: don't allocate DEFAULT_MAXZLIBMEM without USE_ZLIB
Willy Tarreau [Thu, 26 Nov 2015 15:34:56 +0000 (16:34 +0100)] 
CLEANUP: compression: don't allocate DEFAULT_MAXZLIBMEM without USE_ZLIB

It's pointless to reserve this amount of memory when zlib is not used.
Adding the condition will make build scripts easier to manage. This may
be backported to 1.6.

9 years agoBUG/MEDIUM: stream: fix half-closed timeout handling
Willy Tarreau [Wed, 25 Nov 2015 19:17:27 +0000 (20:17 +0100)] 
BUG/MEDIUM: stream: fix half-closed timeout handling

client-fin and server-fin are bogus. They are applied on the write
side after a SHUTR was seen. The immediate effect is that sometimes
if a SHUTR was seen after a SHUTW on the same side, the timeout is
enabled again regardless of the fact that the output is already
closed. This results in the timeout event not to be processed and
a busy poll loop to happen until another timeout on the stream gets
rid of it. Note that haproxy continues its job during this, it's just
that it eats all the CPU trying to handle an event that it ignores.

An reproducible case consists in having a client stop reading data from
a server to ensure data remain in the response buffer, then the client
sends a shutdown(write). If abortonclose is enabled on haproxy, the
shutdown is passed to the server side and the server responds with a
SHUTR that cannot immediately be forwarded to the client since the
buffer is full. During this time the event is ignored and the task is
woken again in loops.

It is worth noting that the timeout handling since 1.5 is a bit fragile
and that it might be possible that other similar conditions still exist,
so the timeout handling should be audited regarding this issue.

Many thanks to BaiYang for providing detailed information showing the
problem in action.

This bug also affects 1.5 thus the fix must be backported.

9 years agoBUG/MEDIUM: http: don't enable auto-close on the response side
Willy Tarreau [Wed, 25 Nov 2015 19:11:11 +0000 (20:11 +0100)] 
BUG/MEDIUM: http: don't enable auto-close on the response side

There is a bug where "option http-keep-alive" doesn't force a response
to stay in keep-alive if the server sends the FIN along with the response
on the second or subsequent response. The reason is that the auto-close
was forced enabled when recycling the HTTP transaction and it's never
disabled along the response processing chain before the SHUTR gets a
chance to be forwarded to the client side. The MSG_DONE state of the
HTTP response properly disables it but too late.

There's no more reason for enabling auto-close here, because either it
doesn't matter in non-keep-alive modes because the connection is closed,
or it is automatically enabled by process_stream() when it sees there's
no analyser on the stream.

This bug also affects 1.5 so a backport is desired.

9 years agoBUILD/MINOR: http: proto_http.h needs sample.h
Willy Tarreau [Wed, 25 Nov 2015 10:29:47 +0000 (11:29 +0100)] 
BUILD/MINOR: http: proto_http.h needs sample.h

Since commit fd7edd3 ("MINOR: Move http method enum from proto_http to sample")
proto_http.h needs to include sample.h. This can be backported to 1.6 though
it doesn't affect existing code.

9 years agoBUG/MINOR: lua: don't force-sslv3 LUA's SSL socket
Lukas Tribus [Thu, 26 Nov 2015 00:48:08 +0000 (01:48 +0100)] 
BUG/MINOR: lua: don't force-sslv3 LUA's SSL socket

Sander Klein reported an error messages about SSLv3 not
being supported on Debian 8, although he didn't force-sslv3.

Vincent Bernat tracked this down to the LUA initialization, which
actually does force-sslv3.

This patch removes force-sslv3 from the LUA initialization, so
the LUA SSL socket can actually use TLS and doesn't trigger
warnings when SSLv3 is not supported by libssl (such as in
Debian 8).

This should be backported to 1.6.

9 years agoBUG/MEDIUM: http: switch the request channel to no-delay once done.
Willy Tarreau [Wed, 18 Nov 2015 10:59:55 +0000 (11:59 +0100)] 
BUG/MEDIUM: http: switch the request channel to no-delay once done.

There's an issue when sending POST data that came in a second packet,
the CF_NEVER_WAIT flag is not always set on the request channel, while
the server is waiting for the request. We must always set this flag in
this case since we're not going to shut down after sending, contrary
to the response side.

Note that option http-no-delay works around this issue.

Reproducer :

listen  px
        mode http
        timeout client 10s
        timeout server 5s
        timeout connect 3s
        option http-server-close
        #option http-no-delay
        bind :8001
        server s1 127.0.0.1:8003

$ (printf "POST / HTTP/1.1\r\nTransfer-encoding: chunked\r\n\r\n"; sleep 0.01; printf "10\r\nAZERTYUIOPQSDFGH\r\n0\r\n\r\n") | nc6 0 8001

Before this fix :

12:03:31.946763 epoll_wait(3, {{EPOLLIN, {u32=5, u64=5}}}, 200, 1000) = 1
12:03:32.634175 accept4(5, {sa_family=AF_INET, sin_port=htons(53849), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_NONBLOCK) = 6
12:03:32.634318 setsockopt(6, SOL_TCP, TCP_NODELAY, [1], 4) = 0
12:03:32.634434 accept4(5, 0x7ffccfbb2cf0, [128], SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
12:03:32.634574 recvfrom(6, "POST / HTTP/1.1\r\nTransfer-encodi"..., 8192, 0, NULL, NULL) = 47
12:03:32.634809 setsockopt(6, SOL_TCP, TCP_QUICKACK, [1], 4) = 0
12:03:32.634952 socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 7
12:03:32.635031 fcntl(7, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
12:03:32.635089 setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0
12:03:32.635153 connect(7, {sa_family=AF_INET, sin_port=htons(8003), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
12:03:32.635315 epoll_wait(3, {}, 200, 0) = 0
12:03:32.635394 sendto(7, "POST / HTTP/1.1\r\nTransfer-encodi"..., 66, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 66
12:03:32.635527 recvfrom(6, 0x7f0224e66024, 8192, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
12:03:32.635651 epoll_ctl(3, EPOLL_CTL_ADD, 6, {EPOLLIN|0x2000, {u32=6, u64=6}}) = 0
12:03:32.635782 epoll_wait(3, {}, 200, 0) = 0
12:03:32.635842 recvfrom(7, 0x7f0224e66024, 8192, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
12:03:32.635924 epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN|0x2000, {u32=7, u64=7}}) = 0
12:03:32.636027 epoll_wait(3, {{EPOLLIN, {u32=6, u64=6}}}, 200, 1000) = 1
12:03:32.644892 recvfrom(6, "10\r\nAZERTYUIOPQSDFGH\r\n0\r\n\r\n", 8192, 0, NULL, NULL) = 27
12:03:32.645016 epoll_wait(3, {}, 200, 0) = 0
12:03:32.645105 sendto(7, "10\r\nAZERTYUIOPQSDFGH\r\n0\r\n\r\n", 27, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE, NULL, 0) = 27

After the fix :

11:59:12.538617 connect(7, {sa_family=AF_INET, sin_port=htons(8003), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
11:59:12.538787 epoll_wait(3, {}, 200, 0) = 0
11:59:12.538867 sendto(7, "POST / HTTP/1.1\r\nTransfer-encodi"..., 66, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 66
11:59:12.539031 recvfrom(6, 0x7f832ce45024, 8192, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
11:59:12.539161 epoll_ctl(3, EPOLL_CTL_ADD, 6, {EPOLLIN|0x2000, {u32=6, u64=6}}) = 0
11:59:12.539259 epoll_wait(3, {}, 200, 0) = 0
11:59:12.539337 recvfrom(7, 0x7f832ce45024, 8192, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
11:59:12.539421 epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLIN|0x2000, {u32=7, u64=7}}) = 0
11:59:12.539499 epoll_wait(3, {{EPOLLIN, {u32=6, u64=6}}}, 200, 1000) = 1
11:59:12.548519 recvfrom(6, "10\r\nAZERTYUIOPQSDFGH\r\n0\r\n\r\n", 8192, 0, NULL, NULL) = 27
11:59:12.548844 epoll_wait(3, {}, 200, 0) = 0
11:59:12.549012 sendto(7, "10\r\nAZERTYUIOPQSDFGH\r\n0\r\n\r\n", 27, MSG_DONTWAIT|MSG_NOSIGNAL, NULL, 0) = 27
11:59:12.549454 epoll_wait(3, {}, 200, 1000) = 0

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

9 years agoBUG: http: do not abort keep-alive connections on server timeout
lsenta [Fri, 13 Nov 2015 09:44:22 +0000 (10:44 +0100)] 
BUG: http: do not abort keep-alive connections on server timeout

When a server timeout is detected on the second or nth request of a keep-alive
connection, HAProxy closes the connection without writing a response.
Some clients would fail with a remote disconnected exception and some
others would retry potentially unsafe requests.

This patch removes the special case and makes sure a 504 timeout is
written back whenever a server timeout is handled.

Signed-off-by: lsenta <laurent.senta@gmail.com>
9 years agoBUILD: Make deviceatlas require PCRE
David CARLIER [Fri, 6 Nov 2015 15:13:06 +0000 (15:13 +0000)] 
BUILD: Make deviceatlas require PCRE

Makefile deviceatlas throwing an error if the necessary pcre flag
is not passed avoiding surprising bunch of 'undefined reference'
for the user. Plus a tiny typo in OPENSSL area.

[wt: backport to 1.6]