]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
12 years agoMAJOR: acl: make all ACLs reference the fetch function via a sample.
Willy Tarreau [Fri, 11 Jan 2013 14:49:37 +0000 (15:49 +0100)] 
MAJOR: acl: make all ACLs reference the fetch function via a sample.

ACL fetch functions used to directly reference a fetch function. Now
that all ACL fetches have their sample fetches equivalent, we can make
ACLs reference a sample fetch keyword instead.

In order to simplify the code, a sample keyword name may be NULL if it
is the same as the ACL's, which is the most common case.

A minor change appeared, http_auth always expects one argument though
the ACL allowed it to be missing and reported as such afterwards, so
fix the ACL to match this. This is not really a bug.

12 years agoMINOR: session: rename sample fetch functions and declare the sample keywords
Willy Tarreau [Tue, 8 Jan 2013 00:23:27 +0000 (01:23 +0100)] 
MINOR: session: rename sample fetch functions and declare the sample keywords

The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

  sc1_bytes_in_rate, sc1_bytes_out_rate, sc1_clr_gpc0, sc1_conn_cnt,
  sc1_conn_cur, sc1_conn_rate, sc1_get_gpc0, sc1_http_err_cnt,
  sc1_http_err_rate, sc1_http_req_cnt, sc1_http_req_rate, sc1_inc_gpc0,
  sc1_kbytes_in, sc1_kbytes_out, sc1_sess_cnt, sc1_sess_rate, sc1_trackers,
  sc2_bytes_in_rate, sc2_bytes_out_rate, sc2_clr_gpc0, sc2_conn_cnt,
  sc2_conn_cur, sc2_conn_rate, sc2_get_gpc0, sc2_http_err_cnt,
  sc2_http_err_rate, sc2_http_req_cnt, sc2_http_req_rate, sc2_inc_gpc0,
  sc2_kbytes_in, sc2_kbytes_out, sc2_sess_cnt, sc2_sess_rate, sc2_trackers,
  src_bytes_in_rate, src_bytes_out_rate, src_clr_gpc0, src_conn_cnt,
  src_conn_cur, src_conn_rate, src_get_gpc0, src_http_err_cnt,
  src_http_err_rate, src_http_req_cnt, src_http_req_rate, src_inc_gpc0,
  src_kbytes_in, src_kbytes_out, src_sess_cnt, src_sess_rate,
  src_updt_conn_cnt, table_avl, table_cnt,

The fetch functions have been renamed "smp_fetch_*".

12 years agoMEDIUM: http: unify acl and sample fetch functions
Willy Tarreau [Mon, 7 Jan 2013 23:31:00 +0000 (00:31 +0100)] 
MEDIUM: http: unify acl and sample fetch functions

The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

    cook, cook_cnt, cook_val, hdr_cnt, hdr_ip, hdr_val, http_auth,
    http_auth_group, http_first_req, method, req_proto_http, req_ver,
    resp_ver, scook, scook_cnt, scook_val, shdr, shdr_cnt, shdr_ip,
    shdr_val, status, urlp, urlp_val,

Most of them won't bring much benefit at the moment, or are even aliases of
existing ones, however they'll be needed for ACL->SMP convergence.

A new val_usr() function was added to resolve userlist names into pointers.

The http_auth_group ACL forgot to make its first argument mandatory, so
there was a check in cfgparse to report a vague error. Now that args are
correctly parsed, let's report something more precise.

All urlp* ACLs now support an optional 3rd argument like their sample
counter-part which is the optional delimiter.

The fetch functions have been renamed "smp_fetch_*".

Some args controls on the sample keywords have been relaxed so that we
can soon use them for ACLs :

  - cookie now accepts to have an optional name ; it will return the
    first matching cookie if the name is not set ;
  - same for set-cookie and hdr

12 years agoMINOR: listener: rename sample fetch functions and declare the sample keywords
Willy Tarreau [Mon, 7 Jan 2013 21:54:17 +0000 (22:54 +0100)] 
MINOR: listener: rename sample fetch functions and declare the sample keywords

The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

          dst_conn, so_id,

The fetch functions have been renamed "smp_fetch_*".

12 years agoMINOR: frontend: rename sample fetch functions and declare the sample keywords
Willy Tarreau [Mon, 7 Jan 2013 21:48:29 +0000 (22:48 +0100)] 
MINOR: frontend: rename sample fetch functions and declare the sample keywords

The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

      fe_conn, fe_id, fe_sess_rate

The fetch functions have been renamed "smp_fetch_*".

12 years agoMINOR: backend: rename sample fetch functions and declare the sample keywords
Willy Tarreau [Mon, 7 Jan 2013 21:38:03 +0000 (22:38 +0100)] 
MINOR: backend: rename sample fetch functions and declare the sample keywords

The following sample fetch functions were only usable by ACLs but are now
usable by sample fetches too :

  avg_queue, be_conn, be_id, be_sess_rate, connslots, nbsrv,
  queue, srv_conn, srv_id, srv_is_up, srv_sess_rate

The fetch functions have been renamed "smp_fetch_*".

12 years agoMEDIUM: samples: move payload-based fetches and ACLs to their own file
Willy Tarreau [Mon, 7 Jan 2013 20:59:07 +0000 (21:59 +0100)] 
MEDIUM: samples: move payload-based fetches and ACLs to their own file

The file acl.c is a real mess, it both contains functions to parse and
process ACLs, and some sample extraction functions which act on buffers.
Some other payload analysers were arbitrarily dispatched to proto_tcp.c.

So now we're moving all payload-based fetches and ACLs to payload.c
which is capable of extracting data from buffers and rely on everything
that is protocol-independant. That way we can safely inflate this file
and only use the other ones when some fetches are really specific (eg:
HTTP, SSL, ...).

As a result of this cleanup, the following new sample fetches became
available even if they're not really useful :

  always_false, always_true, rep_ssl_hello_type, rdp_cookie_cnt,
  req_len, req_ssl_hello_type, req_ssl_sni, req_ssl_ver, wait_end

The function 'acl_fetch_nothing' was wrong and never used anywhere so it
was removed.

The "rdp_cookie" sample fetch used to have a mandatory argument while it
was optional in ACLs, which are supposed to iterate over RDP cookies. So
we're making it optional as a fetch too, and it will return the first one.

12 years agoMINOR: log: indicate it when some unreliable sample fetches are logged
Willy Tarreau [Tue, 8 Jan 2013 00:10:24 +0000 (01:10 +0100)] 
MINOR: log: indicate it when some unreliable sample fetches are logged

If a log-format involves some sample fetches that may not be present at
the logging instant, we can now report a warning.

Note that this is done both for log-format and for add-header and carefully
respects the original fetch keyword's capabilities.

12 years agoMEDIUM: samples: use new flags to describe compatibility between fetches and their...
Willy Tarreau [Mon, 7 Jan 2013 14:42:20 +0000 (15:42 +0100)] 
MEDIUM: samples: use new flags to describe compatibility between fetches and their usages

Samples fetches were relying on two flags SMP_CAP_REQ/SMP_CAP_RES to describe
whether they were compatible with requests rules or with response rules. This
was never reliable because we need a finer granularity (eg: an HTTP request
method needs to parse an HTTP request, and is available past this point).

Some fetches are also dependant on the context (eg: "hdr" uses request or
response depending where it's involved, causing some abiguity).

In order to solve this, we need to precisely indicate in fetches what they
use, and their users will have to compare with what they have.

So now we have a bunch of bits indicating where the sample is fetched in the
processing chain, with a few variants indicating for some of them if it is
permanent or volatile (eg: an HTTP status is stored into the transaction so
it is permanent, despite being caught in the response contents).

The fetches also have a second mask indicating their validity domain. This one
is computed from a conversion table at registration time, so there is no need
for doing it by hand. This validity domain consists in a bitmask with one bit
set for each usage point in the processing chain. Some provisions were made
for upcoming controls such as connection-based TCP rules which apply on top of
the connection layer but before instantiating the session.

Then everywhere a fetch is used, the bit for the control point is checked in
the fetch's validity domain, and it becomes possible to finely ensure that a
fetch will work or not.

Note that we need these two separate bitfields because some fetches are usable
both in request and response (eg: "hdr", "payload"). So the keyword will have
a "use" field made of a combination of several SMP_USE_* values, which will be
converted into a wider list of SMP_VAL_* flags.

The knowledge of permanent vs dynamic information has disappeared for now, as
it was never used. Later we'll probably reintroduce it differently when
dealing with variables. Its only use at the moment could have been to avoid
caching a dynamic rate measurement, but nothing is cached as of now.

12 years agoMEDIUM: acl: remove flag ACL_MAY_LOOKUP which is improperly used
Willy Tarreau [Fri, 4 Jan 2013 15:31:47 +0000 (16:31 +0100)] 
MEDIUM: acl: remove flag ACL_MAY_LOOKUP which is improperly used

This flag is used on ACL matches that support being looking up patterns
in trees. At the moment, only strings and IPs support tree-based lookups,
but the flag is randomly set also on integers and binary data, and is not
even always set on strings nor IPs.

Better get rid of this mess by only relying on the matching function to
decide whether or not it supports tree-based lookups, this is safer and
easier to maintain.

12 years agoBUG/CRITICAL: using HTTP information in tcp-request content may crash the process
Willy Tarreau [Fri, 29 Mar 2013 11:31:49 +0000 (12:31 +0100)] 
BUG/CRITICAL: using HTTP information in tcp-request content may crash the process

During normal HTTP request processing, request buffers are realigned if
there are less than global.maxrewrite bytes available after them, in
order to leave enough room for rewriting headers after the request. This
is done in http_wait_for_request().

However, if some HTTP inspection happens during a "tcp-request content"
rule, this realignment is not performed. In theory this is not a problem
because empty buffers are always aligned and TCP inspection happens at
the beginning of a connection. But with HTTP keep-alive, it also happens
at the beginning of each subsequent request. So if a second request was
pipelined by the client before the first one had a chance to be forwarded,
the second request will not be realigned. Then, http_wait_for_request()
will not perform such a realignment either because the request was
already parsed and marked as such. The consequence of this, is that the
rewrite of a sufficient number of such pipelined, unaligned requests may
leave less room past the request been processed than the configured
reserve, which can lead to a buffer overflow if request processing appends
some data past the end of the buffer.

A number of conditions are required for the bug to be triggered :
  - HTTP keep-alive must be enabled ;
  - HTTP inspection in TCP rules must be used ;
  - some request appending rules are needed (reqadd, x-forwarded-for)
  - since empty buffers are always realigned, the client must pipeline
    enough requests so that the buffer always contains something till
    the point where there is no more room for rewriting.

While such a configuration is quite unlikely to be met (which is
confirmed by the bug's lifetime), a few people do use these features
together for very specific usages. And more importantly, writing such
a configuration and the request to attack it is trivial.

A quick workaround consists in forcing keep-alive off by adding
"option httpclose" or "option forceclose" in the frontend. Alternatively,
disabling HTTP-based TCP inspection rules enough if the application
supports it.

At first glance, this bug does not look like it could lead to remote code
execution, as the overflowing part is controlled by the configuration and
not by the user. But some deeper analysis should be performed to confirm
this. And anyway, corrupting the process' memory and crashing it is quite
trivial.

Special thanks go to Yves Lafon from the W3C who reported this bug and
deployed significant efforts to collect the relevant data needed to
understand it in less than one week.

CVE-2013-1912 was assigned to this issue.

Note that 1.4 is also affected so the fix must be backported.

12 years agoBUG/MAJOR: http: fix regression introduced by commit d655ffe
Willy Tarreau [Tue, 2 Apr 2013 22:22:25 +0000 (00:22 +0200)] 
BUG/MAJOR: http: fix regression introduced by commit d655ffe

Sander Klein reported that since last snapshot, some downloads would
hang from nginx but succeed from apache. The culprit was not too hard
to find given the low number of recent changes affecting the data path.

Commit d655ffe slightly reorganized the HTTP state machine and
introduced this regression. The reason is that we must never jump
into the MSG_DONE case without first flushing remaining data because
this is not done anymore afterwards. This part is scheduled for
being reorganized since it's totally ugly especially since we added
compression, and this regression is an illustration of its readability.

The issue is entirely dependant on the server close sequence, which
explains why it was reproducible only with nginx here.

12 years agoBUG/MAJOR: http: fix regression introduced by commit a890d072
Willy Tarreau [Tue, 2 Apr 2013 21:16:53 +0000 (23:16 +0200)] 
BUG/MAJOR: http: fix regression introduced by commit a890d072

This commit fixed a bug and introduced a new one at the same time.
It's a stupid typo, the index to store the context is [0], not [2].

The effect is that parsing the header can loop forever if multiple
headers are found. This issue was reported by Lukas Tribus.

12 years agoBUILD: add explicit support for TFO with USE_TFO
Lukas Tribus [Tue, 2 Apr 2013 14:43:24 +0000 (16:43 +0200)] 
BUILD: add explicit support for TFO with USE_TFO

TCP Fast Open is supported in server mode since Linux 3.7, but current
libc's don't define TCP_FASTOPEN=23. Introduce the new USE flag USE_TFO
to define it manually in compat.h. Also note this in the TFO related
documentation.

12 years agoBUG/MEDIUM: ssl: improve error processing and reporting in ssl_sock_load_cert_list_file()
Willy Tarreau [Tue, 2 Apr 2013 15:35:58 +0000 (17:35 +0200)] 
BUG/MEDIUM: ssl: improve error processing and reporting in ssl_sock_load_cert_list_file()

fe61656b added the ability to load a list of certificates from a file,
but error control was incomplete and misleading, as some errors such
as missing files were not reported, and errors reported with Alert()
instead of memprintf() were inappropriate and mixed with upper errors.
Also, the code really supports a single SNI filter right now, so let's
correct it and the doc for that, leaving room for later change if needed.

12 years agoMEDIUM: ssl: add mapping from SNI to cert file using "crt-list"
Emmanuel Hocdet [Tue, 22 Jan 2013 14:31:15 +0000 (15:31 +0100)] 
MEDIUM: ssl: add mapping from SNI to cert file using "crt-list"

It designates a list of PEM file with an optional list of SNI filter
per certificate, with the following format for each line :

    <crtfile>[ <snifilter>]*

Wildcards are supported in the SNI filter. The certificates will be
presented to clients who provide a valid TLS Server Name Indication
field matching one of SNI filter. If no SNI filter is specified the
CN and alt subjects are used.

12 years agoBUG/MEDIUM: systemd-wrapper: don't leak zombie processes
Marc-Antoine Perennou [Tue, 2 Apr 2013 11:53:21 +0000 (13:53 +0200)] 
BUG/MEDIUM: systemd-wrapper: don't leak zombie processes

Formerly, if A was replaced by B, and then B by C before
A finished exiting, we didn't wait for B to finish so it
ended up as a zombie process.
Fix this by waiting randomly every child we spawn.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
12 years agoBUG/MAJOR: http: use a static storage for sample fetch context
Willy Tarreau [Tue, 2 Apr 2013 10:01:06 +0000 (12:01 +0200)] 
BUG/MAJOR: http: use a static storage for sample fetch context

Baptiste Assmann reported that the cook*() ACLs do not work anymore.

The reason is the way we store the hdr_ctx between subsequent calls
to smp_fetch_cookie() since commit 3740635b (1.5-dev10).

The smp->ctx.a[] storage holds up to 8 pointers. It is not meant for
generic storage. We used to store hdr_ctx in the ctx, but while it used
to just fit for smp_fetch_hdr(), it does not for smp_fetch_cookie()
since we stored it at offset 2.

The correct solution is to use this storage to store a pointer to the
current hdr_ctx struct which is statically allocated.

12 years agoBUILD: add explicit support for Mac OS/X
Willy Tarreau [Tue, 2 Apr 2013 06:17:43 +0000 (08:17 +0200)] 
BUILD: add explicit support for Mac OS/X

The "osx" target may now be passed in the TARGET variable. It supports
the same features as FreeBSD and allows its users to use the GNU makefile
instead of the platform-specific makefile which lacks some features.

12 years agoBUILD: enable poll() by default in the makefile
Willy Tarreau [Tue, 2 Apr 2013 06:14:29 +0000 (08:14 +0200)] 
BUILD: enable poll() by default in the makefile

This allows to build haproxy for unknown targets and still have poll().
If for any reason a target does not support it, just passing USE_POLL=""
disables it.

12 years agoOPTIM: http: optimize the response forward state machine
Willy Tarreau [Mon, 1 Apr 2013 23:48:58 +0000 (01:48 +0200)] 
OPTIM: http: optimize the response forward state machine

By replacing the if/else series with a switch/case, we could save
another 20% on the worst case (chunks of 1 byte).

12 years agoOPTIM: http: improve branching in chunk size parser
Willy Tarreau [Mon, 1 Apr 2013 23:26:55 +0000 (01:26 +0200)] 
OPTIM: http: improve branching in chunk size parser

By tweaking a bit some conditions in http_parse_chunk_size(), we could
improve the overall performance in the worst case by 15%.

12 years agoOPTIM: buffer: remove one jump in buffer_count()
Willy Tarreau [Mon, 1 Apr 2013 23:25:57 +0000 (01:25 +0200)] 
OPTIM: buffer: remove one jump in buffer_count()

We can help gcc build an expression not involving a jump. This function
is used a lot when parsing chunks.

12 years agoMEDIUM: regex: Use PCRE JIT in acl
Hiroaki Nakamura [Sun, 13 Jan 2013 06:00:42 +0000 (15:00 +0900)] 
MEDIUM: regex: Use PCRE JIT in acl

This is a patch for using PCRE JIT in acl.

I notice regex are used in other places, but they are more complicated
to modify to use PCRE APIs. So I focused to acl in the first try.

BTW, I made a simple benchmark program for PCRE JIT beforehand.
https://github.com/hnakamur/pcre-jit-benchmark

I read the manual for PCRE JIT
http://www.manpagez.com/man/3/pcrejit/

and wrote my benchmark program.
https://github.com/hnakamur/pcre-jit-benchmark/blob/master/test-pcre.c

12 years agoDOCS: Add explanation of intermediate certs to crt paramater
Alex Davies [Sat, 2 Mar 2013 16:04:50 +0000 (16:04 +0000)] 
DOCS: Add explanation of intermediate certs to crt paramater

This change makes the "crt" block of the documentation easier to use
for those not clear on what needs to go in what file, specifically for
those using CAs that require intermediate certificates.

12 years agoBUG/MEDIUM: tools: vsnprintf() is not always reliable on Solaris
Willy Tarreau [Mon, 1 Apr 2013 20:48:54 +0000 (22:48 +0200)] 
BUG/MEDIUM: tools: vsnprintf() is not always reliable on Solaris

Seen on Solaris 8, calling vsnprintf() with a null-size results
in the output size not being computed. This causes some random
behaviour including crashes when trying to display error messages
when loading an invalid configuration.

12 years agoBUILD: fix usual isdigit() warning on solaris
Willy Tarreau [Mon, 1 Apr 2013 18:37:42 +0000 (20:37 +0200)] 
BUILD: fix usual isdigit() warning on solaris

src/standard.c: In function `str2sa_range':
src/standard.c:734: warning: subscript has type `char'

This one was recently introduced by commit c120c8d3.

12 years agoBUG/MINOR: acl: ssl_c_used, ssl_fc{,_has_crt,_has_sni} take no pattern
Willy Tarreau [Sun, 31 Mar 2013 17:44:57 +0000 (19:44 +0200)] 
BUG/MINOR: acl: ssl_c_used, ssl_fc{,_has_crt,_has_sni} take no pattern

The ones are booleans, not integers. This bug has no impact however.

12 years agoBUG/MINOR: acl: ssl_fc_{alg,use}_keysize must parse integers, not strings
Willy Tarreau [Sun, 31 Mar 2013 17:38:19 +0000 (19:38 +0200)] 
BUG/MINOR: acl: ssl_fc_{alg,use}_keysize must parse integers, not strings

This is a copy-paste typo making the ACLs unusable.

12 years agoBUG/MAJOR: ev_select: disable the select() poller if maxsock > FD_SETSIZE
Willy Tarreau [Sun, 31 Mar 2013 12:41:15 +0000 (14:41 +0200)] 
BUG/MAJOR: ev_select: disable the select() poller if maxsock > FD_SETSIZE

Some recent glibc updates have added controls on FD_SET/FD_CLR/FD_ISSET
that crash the program if it tries to use a file descriptor larger than
FD_SETSIZE.

For this reason, we now control the compatibility between global.maxsock
and FD_SETSIZE, and refuse to use select() if there too many FDs are
expected to be used. Note that on Solaris, FD_SETSIZE is already forced
to 65536, and that FreeBSD and OpenBSD allow it to be redefined, though
this is not needed thanks to kqueue which is much more efficient.

In practice, since poll() is enabled on all targets, it should not cause
any problem, unless it is explicitly disabled.

This change must be backported to 1.4 because the crashes caused by glibc
have already been reported on this version.

12 years agoMEDIUM: poll: do not use FD_* macros anymore
Willy Tarreau [Sun, 31 Mar 2013 12:06:57 +0000 (14:06 +0200)] 
MEDIUM: poll: do not use FD_* macros anymore

Some recent glibc updates have added controls on FD_SET/FD_CLR/FD_ISSET
that crash the program if it tries to use a file descriptor larger than
FD_SETSIZE.

Do not rely on FD_* macros anymore and replace them with bit fields.

12 years agoDOC: mention the new HTTP 307 and 308 redirect statues
Willy Tarreau [Fri, 29 Mar 2013 18:28:11 +0000 (19:28 +0100)] 
DOC: mention the new HTTP 307 and 308 redirect statues

12 years agoMINOR: http: status 301 should not be marked non-cacheable
Yves Lafon [Mon, 11 Mar 2013 15:06:05 +0000 (11:06 -0400)] 
MINOR: http: status 301 should not be marked non-cacheable

Also, browsers behaviour is inconsistent regarding the Cache-Control
header field on a 301.

12 years agoMEDIUM: http: implement redirect 307 and 308
Yves Lafon [Mon, 11 Mar 2013 15:06:05 +0000 (11:06 -0400)] 
MEDIUM: http: implement redirect 307 and 308

I needed to emit a 307 and noticed it was not available so I did it,
as well as 308.

12 years agoMINOR: http: status code 303 is HTTP/1.1 only
Yves Lafon [Mon, 11 Mar 2013 15:06:05 +0000 (11:06 -0400)] 
MINOR: http: status code 303 is HTTP/1.1 only

Don't return a 303 redirect with "HTTP/1.0" as it's HTTP/1.1 only.

12 years agoBUG/MEDIUM: http: fix another issue caused by http-send-name-header
Willy Tarreau [Tue, 26 Mar 2013 00:08:21 +0000 (01:08 +0100)] 
BUG/MEDIUM: http: fix another issue caused by http-send-name-header

An issue reported by David Coulson is that when using http-send-name-header,
the response processing would randomly be performed. The issue was first
diagnosed by Cyril Bonté as being related to a time race when processing
the closing of the response.

In practice, the issue is a bit trickier. It happens that
http_send_name_header() did not update msg->sol after a rewrite. This
counter is supposed to point to the beginning of the message's body
once headers are scheduled for being forwarded. And not updating it
means that the first forwarding of the request headers in
http_request_forward_body() does not send the correct count, leaving
some bytes in chn->to_forward.

Then if the server sends its response in a single packet with the
close, the stream interface switches to state SI_ST_DIS which in
turn moves to SI_ST_CLO in process_session(), and to close the
outgoing connection. This is detected by http_request_forward_body(),
which then switches the request message to the error state, and syncs
all FSMs and removes any response analyser.

The response analyser being removed, no processing is performed on
the response buffer, which is tunnelled as-is to the client.

Of course, the correct fix consists in having http_send_name_header()
update msg->sol. Normally this ought not to have been needed, but it
is an abuse to modify data already scheduled for being forwarded, so
it is expected that such specific handling has to be done there. Better
not have generic functions deal with such cases, so that it does not
become the standard.

Note: 1.4 does not have this issue even if it does not update the
pointer either, because it forwards from msg->som which is not
updated at the moment the connect() succeeds. So no backport is
required.

12 years agoBUG/MEDIUM: config: ACL compatibility check on "redirect" was wrong
Willy Tarreau [Mon, 25 Mar 2013 18:16:31 +0000 (19:16 +0100)] 
BUG/MEDIUM: config: ACL compatibility check on "redirect" was wrong

The check was made on "cond" instead of "rule->cond", so it never
emitted any warning since either the rule was NULL or it was set to
the last condition met.

This is 1.5-specific and the bug was introduced by commit 4baae248
in 1.5-dev17, so no backport is needed.

12 years agoBUG/MEDIUM: http: add-header should not emit "-" for empty fields
Willy Tarreau [Sun, 24 Mar 2013 06:33:22 +0000 (07:33 +0100)] 
BUG/MEDIUM: http: add-header should not emit "-" for empty fields

Patch 6cbbdbf3 fixed the missing "-" delimitors in logs but it caused
them to be emitted with "http-request add-header", eventhough it was
correctly fixed for the unique-id format. Fix this by simply removing
LOG_OPT_MANDATORY in this case.

12 years agoMAJOR: tools: support environment variables in addresses
Willy Tarreau [Mon, 11 Mar 2013 00:20:04 +0000 (01:20 +0100)] 
MAJOR: tools: support environment variables in addresses

Now that all addresses are parsed using str2sa_range(), it becomes easy
to add support for environment variables and use them everywhere an address
is needed. Environment variables are used as $VAR or ${VAR} as in shell.
Any number of variables may compose an address, allowing various fantasies
such as "fd@${FD_HTTP}" or "${LAN_DC1}.1:80".

These ones are usable in logs, bind, servers, peers, stats socket, source,
dispatch, and check address.

12 years agoMAJOR: listener: support inheriting a listening fd from the parent
Willy Tarreau [Sun, 10 Mar 2013 22:51:38 +0000 (23:51 +0100)] 
MAJOR: listener: support inheriting a listening fd from the parent

Using the address syntax "fd@<num>", a listener may inherit a file
descriptor that the caller process has already bound and passed as
this number. The fd's socket family is detected using getsockname(),
and the usual initialization is performed through the existing code
for that family, but the socket creation is skipped.

Whether the parent has performed the listen() call or not is not
important as this is detected.

For UNIX sockets, we immediately clear the path after preparing a
socket so that we never remove it in case an abort would happen due
to a late error during startup.

12 years agoMEDIUM: tools: support specifying explicit address families in str2sa_range()
Willy Tarreau [Sun, 10 Mar 2013 20:32:12 +0000 (21:32 +0100)] 
MEDIUM: tools: support specifying explicit address families in str2sa_range()

This change allows one to force the address family in any address parsed
by str2sa_range() by specifying it as a prefix followed by '@' then the
address. Currently supported address prefixes are 'ipv4@', 'ipv6@', 'unix@'.
This also helps forcing resolving for host names (when getaddrinfo is used),
and force the family of the empty address (eg: 'ipv4@' = 0.0.0.0 while
'ipv6@' = ::).

The main benefits is that unix sockets can now get a local name without
being forced to begin with a slash. This is useful during development as
it is no longer necessary to have stats socket sent to /tmp.

12 years agoCLEANUP: config: do not use multiple errmsg at once
Willy Tarreau [Sun, 10 Mar 2013 18:44:48 +0000 (19:44 +0100)] 
CLEANUP: config: do not use multiple errmsg at once

Several of the parsing functions made use of multiple errmsg/err_msg
variables which had to be freed, while there is already one in each
function that is freed upon exit. Adapt the code to use the existing
variable exclusively.

12 years agoCLEANUP: minor cleanup in str2sa_range() and str2ip()
Willy Tarreau [Sun, 10 Mar 2013 18:27:44 +0000 (19:27 +0100)] 
CLEANUP: minor cleanup in str2sa_range() and str2ip()

Don't use a statically allocated address both for str2ip and str2sa_range,
use the same. The inet and unix code paths have been splitted a little
better to improve readability.

12 years agoMEDIUM: config: add complete support for str2sa_range() in 'source' and 'usesrc'
Willy Tarreau [Sun, 10 Mar 2013 17:51:54 +0000 (18:51 +0100)] 
MEDIUM: config: add complete support for str2sa_range() in 'source' and 'usesrc'

The 'source' and 'usesrc' statements now completely rely on str2sa_range() to
parse an address. A test is made to ensure that the address family supports
connect().

12 years agoMEDIUM: config: add complete support for str2sa_range() in 'peer'
Willy Tarreau [Sun, 10 Mar 2013 17:37:42 +0000 (18:37 +0100)] 
MEDIUM: config: add complete support for str2sa_range() in 'peer'

The peer addresses are now completely parsed using str2sa_range()
and the resulting protocol is checked for support for connect().

12 years agoMEDIUM: config: add complete support for str2sa_range() in 'server'
Willy Tarreau [Wed, 6 Mar 2013 19:04:27 +0000 (20:04 +0100)] 
MEDIUM: config: add complete support for str2sa_range() in 'server'

The server addresses are now completely parsed using str2sa_range()
and the resulting protocol is checked for support for connect().

12 years agoMEDIUM: config: add complete support for str2sa_range() in server addr
Willy Tarreau [Wed, 6 Mar 2013 17:05:34 +0000 (18:05 +0100)] 
MEDIUM: config: add complete support for str2sa_range() in server addr

The server addr statement now completely relies on str2sa_range() to
parse an address.

12 years agoMEDIUM: config: add complete support for str2sa_range() in dispatch
Willy Tarreau [Wed, 6 Mar 2013 15:52:04 +0000 (16:52 +0100)] 
MEDIUM: config: add complete support for str2sa_range() in dispatch

The dispatch statement now completely relies on str2sa_range() to parse
an address.

12 years agoCLEANUP: tools: remove str2sun() which is not used anymore.
Willy Tarreau [Wed, 6 Mar 2013 14:08:16 +0000 (15:08 +0100)] 
CLEANUP: tools: remove str2sun() which is not used anymore.

12 years agoMEDIUM: config: use str2sa_range() to parse log addresses
Willy Tarreau [Wed, 6 Mar 2013 14:02:49 +0000 (15:02 +0100)] 
MEDIUM: config: use str2sa_range() to parse log addresses

str2sa_range() is now used to parse log addresses, both INET and
UNIX. str2sun() is not used anymore.

12 years agoMEDIUM: config: use a single str2sa_range() call to parse bind addresses
Willy Tarreau [Wed, 6 Mar 2013 14:45:03 +0000 (15:45 +0100)] 
MEDIUM: config: use a single str2sa_range() call to parse bind addresses

str2listener() now doesn't check the address syntax, it only relies on
str2sa_range() to retrieve the address and family.

12 years agoMEDIUM: config: make str2listener() use str2sa_range() to parse unix addresses
Willy Tarreau [Mon, 4 Mar 2013 18:56:20 +0000 (19:56 +0100)] 
MEDIUM: config: make str2listener() use str2sa_range() to parse unix addresses

Now that str2sa_range() knows how to parse UNIX addresses, make str2listener()
use it. It simplifies the function. Next step consists in unifying the error
handling to further simplify the call.

Tests have been done and show that unix sockets are correctly handled, with
and without prefixes, both for global stats and normal "bind" statements.

12 years agoMEDIUM: tools: make str2sa_range() parse unix addresses too
Willy Tarreau [Mon, 4 Mar 2013 18:48:14 +0000 (19:48 +0100)] 
MEDIUM: tools: make str2sa_range() parse unix addresses too

str2sa_range() now considers that any address beginning with '/' is a UNIX
address. It is compatible with all callers at the moment since all of them
perform this test and use a different parser for such addresses. However,
some parsers (eg: servers) still don't check for unix addresses.

12 years agoMINOR: tools: prepare str2sa_range() to accept a prefix
Willy Tarreau [Mon, 4 Mar 2013 17:22:00 +0000 (18:22 +0100)] 
MINOR: tools: prepare str2sa_range() to accept a prefix

We'll need str2sa_range() to support a prefix for unix sockets. Since
we don't always want to use it (eg: stats socket), let's not take it
unconditionally from global but let the caller pass it.

12 years agoBUG/MEDIUM: checks: don't call connect() on unsupported address families
Willy Tarreau [Mon, 4 Mar 2013 19:07:44 +0000 (20:07 +0100)] 
BUG/MEDIUM: checks: don't call connect() on unsupported address families

At the moment, all address families supported on a "server" statement support
a connect() method, but this will soon change with the generalization of
str2sa_range(). Checks currently call ->connect() unconditionally so let's
add a check for this.

12 years agoMINOR: tools: prepare str2sa_range() to return an error message
Willy Tarreau [Fri, 1 Mar 2013 19:22:54 +0000 (20:22 +0100)] 
MINOR: tools: prepare str2sa_range() to return an error message

We'll need str2sa_range() to return address parsing errors if we want to
extend its functionalities. Let's do that now eventhough it's not used
yet.

12 years agoBUG/MEDIUM: stats: never apply "unix-bind prefix" to the global stats socket
Willy Tarreau [Mon, 4 Mar 2013 18:53:29 +0000 (19:53 +0100)] 
BUG/MEDIUM: stats: never apply "unix-bind prefix" to the global stats socket

The "unix-bind prefix" feature was made for explicit "bind" statements. Since
the stats socket was changed to use str2listener(), it implicitly inherited
from this feature. But both are defined in the global section, and we don't
want them to be position-dependant.

So let's make str2listener() explicitly not apply the unix-bind prefix to the
global stats frontend.

This only affects 1.5-dev so it does not need any backport.

12 years agoBUG/MEDIUM: ssl: ECDHE ciphers not usable without named curve configured.
Emeric Brun [Wed, 6 Mar 2013 13:08:53 +0000 (14:08 +0100)] 
BUG/MEDIUM: ssl: ECDHE ciphers not usable without named curve configured.

Fix consists to use prime256v1 as default named curve to init ECDHE ciphers if none configured.

12 years agoBUG/MEDIUM: tools: fix bad character handling in str2sa_range()
Willy Tarreau [Wed, 6 Mar 2013 14:28:17 +0000 (15:28 +0100)] 
BUG/MEDIUM: tools: fix bad character handling in str2sa_range()

Commit d4448bc8 brought support for parsing port ranges, but invalid
characters are not properly handled and can result in a crash while
parsing the configuration if an invalid character is present in the
port, because the return value is set to NULL then dereferenced.

12 years agoMINOR: config: report missing peers section name
Willy Tarreau [Tue, 5 Mar 2013 10:31:55 +0000 (11:31 +0100)] 
MINOR: config: report missing peers section name

Right now we report "invalid character ''" which is a bit confusing,
better make a special case of the missing name.

12 years agoBUILD/MINOR: syscall: add definition of NR_accept4 for ARM
Willy Tarreau [Mon, 4 Mar 2013 06:38:08 +0000 (07:38 +0100)] 
BUILD/MINOR: syscall: add definition of NR_accept4 for ARM

This platform was not covered and older libc do not provide accept4().

12 years agoBUG/MINOR: syscall: fix NR_accept4 system call on sparc/linux
Willy Tarreau [Mon, 4 Mar 2013 06:31:08 +0000 (07:31 +0100)] 
BUG/MINOR: syscall: fix NR_accept4 system call on sparc/linux

An invalid copy-paste called it NR_splice instead of NR_accept4.
This does not lead to real issues because if this define is used,
then the code cannot compile since NR_accept4 is still missing.

12 years agoMINOR: ssl: add a global tunable for the max SSL/TLS record size
Willy Tarreau [Thu, 21 Feb 2013 06:46:09 +0000 (07:46 +0100)] 
MINOR: ssl: add a global tunable for the max SSL/TLS record size

Add new tunable "tune.ssl.maxrecord".

Over SSL/TLS, the client can decipher the data only once it has received
a full record. With large records, it means that clients might have to
download up to 16kB of data before starting to process them. Limiting the
record size can improve page load times on browsers located over high
latency or low bandwidth networks. It is suggested to find optimal values
which fit into 1 or 2 TCP segments (generally 1448 bytes over Ethernet
with TCP timestamps enabled, or 1460 when timestamps are disabled), keeping
in mind that SSL/TLS add some overhead. Typical values of 1419 and 2859
gave good results during tests. Use "strace -e trace=write" to find the
best value.

This trick was first suggested by Mike Belshe :

   http://www.belshe.com/2010/12/17/performance-and-the-tls-record-size/

Then requested again by Ilya Grigorik who provides some hints here :

   http://ofps.oreilly.com/titles/9781449344764/_transport_layer_security_tls.html#ch04_00000101

12 years agoMINOR: tests: add a config file to ease address parsing tests.
Willy Tarreau [Wed, 20 Feb 2013 16:30:09 +0000 (17:30 +0100)] 
MINOR: tests: add a config file to ease address parsing tests.

This one tests str2sa_range().

12 years agoMEDIUM: config: use str2sa_range() to parse peers addresses
Willy Tarreau [Wed, 20 Feb 2013 18:20:59 +0000 (19:20 +0100)] 
MEDIUM: config: use str2sa_range() to parse peers addresses

Similarly to previous changes, use str2sa_range() so that we can
detect invalid addresses or port configurations in peers.

12 years agoMEDIUM: config: use str2sa_range() to parse server addresses
Willy Tarreau [Wed, 20 Feb 2013 18:06:35 +0000 (19:06 +0100)] 
MEDIUM: config: use str2sa_range() to parse server addresses

Similarly to previous changes, we're now able to detect other invalid
addresses thanks to the use of this function (eg: port ranges).

12 years agoMEDIUM: config: make use of str2sa_range() instead of str2sa()
Willy Tarreau [Wed, 20 Feb 2013 16:26:02 +0000 (17:26 +0100)] 
MEDIUM: config: make use of str2sa_range() instead of str2sa()

When parsing the config, we now use str2sa_range() to detect when
ranges or port offsets were improperly used. Among the new checks
are "log", "source", "addr", "usesrc" which previously didn't check
for extra parameters.

12 years agoMEDIUM: tools: make str2sa_range support all address syntaxes
Willy Tarreau [Wed, 20 Feb 2013 14:55:15 +0000 (15:55 +0100)] 
MEDIUM: tools: make str2sa_range support all address syntaxes

Right now we have multiple methods for parsing IP addresses in the
configuration. This is quite painful. This patch aims at adapting
str2sa_range() to make it support all formats, so that the callers
perform the appropriate tests on the return values. str2sa() was
changed to simply return str2sa_range().

The output values are now the following ones (taken from the comment
on top of the function).

  Converts <str> to a locally allocated struct sockaddr_storage *, and a port
  range or offset consisting in two integers that the caller will have to
  check to find the relevant input format. The following format are supported :

    String format           | address |  port  |  low   |  high
     addr                   | <addr>  |   0    |   0    |   0
     addr:                  | <addr>  |   0    |   0    |   0
     addr:port              | <addr>  | <port> | <port> | <port>
     addr:pl-ph             | <addr>  |  <pl>  |  <pl>  |  <ph>
     addr:+port             | <addr>  | <port> |   0    | <port>
     addr:-port             | <addr>  |-<port> | <port> |   0

  The detection of a port range or increment by the caller is made by
  comparing <low> and <high>. If both are equal, then port 0 means no port
  was specified. The caller may pass NULL for <low> and <high> if it is not
  interested in retrieving port ranges.

  Note that <addr> above may also be :
    - empty ("")  => family will be AF_INET and address will be INADDR_ANY
    - "*"         => family will be AF_INET and address will be INADDR_ANY
    - "::"        => family will be AF_INET6 and address will be IN6ADDR_ANY
    - a host name => family and address will depend on host name resolving.

12 years agoMEDIUM: halog: add support for counting per source address (-ic)
Willy Tarreau [Sat, 16 Feb 2013 22:49:04 +0000 (23:49 +0100)] 
MEDIUM: halog: add support for counting per source address (-ic)

This is the same as -uc except that instead of counting URLs, it
counts source addresses. The reported times are request times and
not response times.

The code becomes heavily ugly, the url struct is being abused to
store an address, and there are no more bit fields available. The
code needs a major revamp.

12 years agoBUG/MEDIUM: config: fix parser crash with bad bind or server address
Sean Carey [Fri, 15 Feb 2013 22:39:18 +0000 (23:39 +0100)] 
BUG/MEDIUM: config: fix parser crash with bad bind or server address

If an address is improperly formated on a bind or server address
and haproxy is built for using getaddrinfo, then a crash may occur
upon the call to freeaddrinfo().

Thanks to Jon Meredith for helping me patch this for SmartOS,
I am not a C/GDB wizard.

12 years agoDOC: tfo: bump required kernel to linux-3.7
Lukas Tribus [Wed, 13 Feb 2013 22:35:39 +0000 (23:35 +0100)] 
DOC: tfo: bump required kernel to linux-3.7

Support for server side TFO was actually introduced in linux-3.7,
linux-3.6 just has client support.

This patch fixes documentation and a code comment about the
kernel requirement. It also fixes a wrong tfo related code
comment in src/proto_tcp.c.

12 years agoBUILD: improve the makefile's support for libpcre
Willy Tarreau [Wed, 13 Feb 2013 11:39:06 +0000 (12:39 +0100)] 
BUILD: improve the makefile's support for libpcre

Currently when cross-compiling, it's generally necessary to force
PCREDIR which the Makefile automatically appends /include and /lib to.
Unfortunately on most 64-bit linux distros, the lib path is instead
/lib64, which is really annoying to fix in the makefile.

So now we're computing PCRE_INC and PCRE_LIB from PCREDIR and using
these ones instead. If one wants to force paths individually, it is
possible to set them instead of setting PCREDIR. The old behaviour
of not passing anything to the compiler when PCREDIR is forced to blank
is conserved.

12 years agoDOC: minor typo fix in documentation
Baptiste Assmann [Sat, 2 Feb 2013 22:47:49 +0000 (23:47 +0100)] 
DOC: minor typo fix in documentation

12 years agoBUILD: fix a warning emitted by isblank() on non-c99 compilers
Willy Tarreau [Wed, 13 Feb 2013 11:47:12 +0000 (12:47 +0100)] 
BUILD: fix a warning emitted by isblank() on non-c99 compilers

Commit a2b9dad introduced use of isblank() which is not present everywhere
and requires -std=c99 or various other defines. Here on gcc-3.4 with glibc
2.3 it emits a warning though it works :

  src/checks.c: In function 'event_srv_chk_r':
  src/checks.c:1007: warning: implicit declaration of function 'isblank'

This macro matches only 2 values, better replace it with the explicit match.

12 years agoMEDIUM: checks: Add agent health check
Simon Horman [Tue, 12 Feb 2013 01:45:54 +0000 (10:45 +0900)] 
MEDIUM: checks: Add agent health check

Support a agent health check performed by opening a TCP socket to a
pre-defined port and reading an ASCII string. The string should have one of
the following forms:

* An ASCII representation of an positive integer percentage.
  e.g. "75%"

  Values in this format will set the weight proportional to the initial
  weight of a server as configured when haproxy starts.

* The string "drain".

  This will cause the weight of a server to be set to 0, and thus it will
  not accept any new connections other than those that are accepted via
  persistence.

* The string "down", optionally followed by a description string.

  Mark the server as down and log the description string as the reason.

* The string "stopped", optionally followed by a description string.

  This currently has the same behaviour as down (iii).

* The string "fail", optionally followed by a description string.

  This currently has the same behaviour as down (iii).

A agent health check may be configured using "option lb-agent-chk".
The use of an alternate check-port, used to obtain agent heath check
information described above as opposed to the port of the service,
may be useful in conjunction with this option.

e.g.

    option  lb-agent-chk
    server  http1_1 10.0.0.10:80 check port 10000 weight 100

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoMEDIUM: server: Tighten up parsing of weight string
Simon Horman [Tue, 12 Feb 2013 01:45:53 +0000 (10:45 +0900)] 
MEDIUM: server: Tighten up parsing of weight string

Detect:
* Empty weight string, including no digits before '%' in relative
  weight string
* Trailing garbage, including between the last integer and '%'
  in relative weights

The motivation for this is to allow the weight string to be safely
logged if successfully parsed by this function

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoMEDIUM: server: Allow relative weights greater than 100%
Simon Horman [Tue, 12 Feb 2013 01:45:52 +0000 (10:45 +0900)] 
MEDIUM: server: Allow relative weights greater than 100%

Allow relative weights greater than 100%,
capping the absolute value to 256 which is
the largest supported absolute weight.

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoMEDIUM: server: Break out set weight processing code
Simon Horman [Tue, 12 Feb 2013 01:45:51 +0000 (10:45 +0900)] 
MEDIUM: server: Break out set weight processing code

Break out set weight processing code.
This is in preparation for reusing the code.

Also, remove duplicate check in nested if clauses.
{px->lbprm.algo & BE_LB_PROP_DYN) is checked by
the immediate outer if clause, so there is no need
to check it a second time.

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoCLEANUP: dumpstats: Make cli_release_handler() static
Simon Horman [Tue, 12 Feb 2013 01:45:50 +0000 (10:45 +0900)] 
CLEANUP: dumpstats: Make cli_release_handler() static

Make cli_release_handler() static, it is only used
inside dumpstats.c

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoCLEANUP: checks: Make desc argument to set_server_check_status const
Simon Horman [Tue, 12 Feb 2013 01:45:49 +0000 (10:45 +0900)] 
CLEANUP: checks: Make desc argument to set_server_check_status const

This parameter is not modified by set_server_check_status() and
thus may be const.

Signed-off-by: Simon Horman <horms@verge.net.au>
12 years agoBUG/MINOR: Correct logic in cut_crlf()
Simon Horman [Wed, 13 Feb 2013 08:48:00 +0000 (17:48 +0900)] 
BUG/MINOR: Correct logic in cut_crlf()

This corrects what appears to be logic errors in cut_crlf().
I assume that the intention of this function is to truncate a
string at the first cr or lf. However, currently lf are ignored.

Also use '\0' instead of 0 as the null character, a cosmetic change.

Cc: Krzysztof Piotr Oledzki <ole@ans.pl>
Signed-off-by: Simon Horman <horms@verge.net.au>
[WT: this fix may be backported to 1.4 too]

12 years agoMEDIUM: add systemd service
Marc-Antoine Perennou [Wed, 13 Feb 2013 08:28:50 +0000 (09:28 +0100)] 
MEDIUM: add systemd service

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
12 years agoMEDIUM: add haproxy-systemd-wrapper
Marc-Antoine Perennou [Tue, 12 Feb 2013 09:53:53 +0000 (10:53 +0100)] 
MEDIUM: add haproxy-systemd-wrapper

Currently, to reload haproxy configuration, you have to use "-sf".

There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.

This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
12 years agoMEDIUM: New cli option -Ds for systemd compatibility
Marc-Antoine Perennou [Tue, 12 Feb 2013 09:53:52 +0000 (10:53 +0100)] 
MEDIUM: New cli option -Ds for systemd compatibility

This patch adds a new option "-Ds" which is exactly like "-D", but instead of
forking n times to get n jobs running and then exiting, prefers to wait for all the
children it just created. With this done, haproxy becomes more systemd-compliant,
without changing anything for other systems.

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
12 years agoDOC: simplify bind option "interface" explanation
Lukas Tribus [Tue, 12 Feb 2013 21:13:19 +0000 (22:13 +0100)] 
DOC: simplify bind option "interface" explanation

The current documentation of the bind option "interface" can be misleading
(as seen on the ML recently).

This patch tries to address misunderstandings by :

  - avoiding the words listen or bind in the behavior description, using
    "restrict to interface" instead

  - using a different sentence construction (partially stolen from
    "man 7 socket": SO_BINDTODEVICE)

  - "defragmentation": moving behavior related explanations to the beginning
    and restrictions, use-cases and requirements to the end.

12 years agoBUG/MEDIUM: checks: fix a race condition between checks and observe layer7
Willy Tarreau [Tue, 12 Feb 2013 14:23:12 +0000 (15:23 +0100)] 
BUG/MEDIUM: checks: fix a race condition between checks and observe layer7

When observe layer7 is enabled on a server, a response may cause a server
to be marked down while a check is in progress. When the check finally
completes, the connection is not properly released in process_chk() because
the server states makes it think that no check was in progress due to the
lastly reported failure.

When a new check gets scheduled, it reuses the same connection structure
which is reinitialized. When the server finally closes the previous
connection, epoll_wait() notifies conn_fd_handler() which sees that the
old connection is still referenced by fdtab[fd], but it can not do anything
with this fd which does not match conn->t.sock.fd. So epoll_wait() keeps
reporting this fd forever.

The solution is to always make process_chk() always take care of closing
the connection and not make it rely on the connection layer to so.

Special thanks go to James Cole and Finn Arne Gangstad who encountered
the issue almost at the same time and took care of reporting a very
detailed analysis with rich information to help understand the issue.

12 years agoBUG/MEDIUM: log: emit '-' for empty fields again
Willy Tarreau [Tue, 5 Feb 2013 17:52:25 +0000 (18:52 +0100)] 
BUG/MEDIUM: log: emit '-' for empty fields again

Commit 2b0108ad accidently got rid of the ability to emit a "-" for
empty log fields. This can happen for captured request and response
cookies, as well as for fetches. Since we don't want to have this done
for headers however, we set the default log method when parsing the
format. It is still possible to force the desired mode using +M/-M.

12 years agoBUG/MEDIUM: ssl: openssl 0.9.8 doesn't open /dev/random before chroot
Thierry Fournier [Thu, 24 Jan 2013 13:15:43 +0000 (14:15 +0100)] 
BUG/MEDIUM: ssl: openssl 0.9.8 doesn't open /dev/random before chroot

Openssl needs to access /dev/urandom to initialize its internal random
number generator. It does so when it needs a random for the first time,
which fails if it is a handshake performed after the chroot(), causing
all SSL incoming connections to fail.

This fix consists in calling RAND_bytes() to produce a random before
the chroot, which will in turn open /dev/urandom before it's too late,
and avoid the issue.

If the random generator fails to work while processing the config,
haproxy now fails with an error instead of causing SSL connections to
fail at runtime.

12 years agoMEDIUM: ssl: add bind-option "strict-sni"
Emmanuel Hocdet [Thu, 24 Jan 2013 16:17:15 +0000 (17:17 +0100)] 
MEDIUM: ssl: add bind-option "strict-sni"

This new option ensures that there is no possible fallback to a default
certificate if the client does not provide an SNI which is explicitly
handled by a certificate.

12 years agoCLEANUP: config: maxcompcpuusage is never negative
Willy Tarreau [Thu, 24 Jan 2013 15:25:38 +0000 (16:25 +0100)] 
CLEANUP: config: maxcompcpuusage is never negative

No need to check for a negative value in the "maxcompcpuusage" argument,
it's an unsigned int.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoCLEANUP: config: slowstart is never negative
Willy Tarreau [Thu, 24 Jan 2013 15:24:15 +0000 (16:24 +0100)] 
CLEANUP: config: slowstart is never negative

No need to check for a negative value in the "slowstart" argument, it's
an unsigned.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoCLEANUP: http: don't try to deinitialize http compression if it fails before init
Willy Tarreau [Thu, 24 Jan 2013 14:58:42 +0000 (15:58 +0100)] 
CLEANUP: http: don't try to deinitialize http compression if it fails before init

In select_compression_response_header(), some tests are rather confusing
as the "fail" label is used to deinitialize the compression context for
the session while it's branched only before initialization succeeds. The
test is always false here and the dereferencing of the comp_algo pointer
which might be null is also confusing. Remove that code which is not needed
anymore since commit ec3e3890 got rid of the latest issues.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MINOR: unix: remove the 'level' field from the ux struct
Willy Tarreau [Thu, 24 Jan 2013 14:17:20 +0000 (15:17 +0100)] 
BUG/MINOR: unix: remove the 'level' field from the ux struct

Commit 290e63aa moved the unix parameters out of the global stats socket
to the bind_conf struct. As such the stats admin level was also moved
overthere, but it remained in the stats global section where it was not
used, except by a nasty memcpy() used to initialize the ux struct in the
bind_conf with too large data. Fortunately, the extra data copied were
the previous level over the new level so it did not have any impact, but
it could have been worse.

This bug is 1.5 specific, no backport is needed.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MEDIUM: uri_auth: missing NULL check and memory leak on memory shortage
Willy Tarreau [Thu, 24 Jan 2013 01:26:43 +0000 (02:26 +0100)] 
BUG/MEDIUM: uri_auth: missing NULL check and memory leak on memory shortage

A test is obviously wrong in uri_auth(). If strdup(pass) returns an error
while strdup(user) passes, the NULL pointer is still stored into the
structure. If the user returns the NULL instead, the allocated memory is
not released before returning the error.

The issue was present in 1.4 so the fix should be backported.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MEDIUM: tools: off-by-one in quote_arg()
Willy Tarreau [Thu, 24 Jan 2013 01:14:42 +0000 (02:14 +0100)] 
BUG/MEDIUM: tools: off-by-one in quote_arg()

This function may write the \0 one char too far in the static array.
There is no effect right now as the function has never been used except
maybe in code that was never released. Out-of-tree code might possibly
be affected though (hence the MEDIUM flag).

No backport is needed.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MEDIUM: signal: signal handler does not properly check for signal bounds
Willy Tarreau [Thu, 24 Jan 2013 01:06:05 +0000 (02:06 +0100)] 
BUG/MEDIUM: signal: signal handler does not properly check for signal bounds

sig is checked for < 0 or > MAX_SIGNAL, but the signal array is
MAX_SIGNAL in size. At the moment, MAX_SIGNAL is 256. If a system supports
more than MAX_SIGNAL signals, then sending signal MAX_SIGNAL to the process
will corrupt one integer in its memory and might also crash the process.

This bug is also present in 1.4 and 1.3, and the fix must be backported.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoCLEANUP: tcp/unix: remove useless NULL check in {tcp,unix}_bind_listener()
Willy Tarreau [Thu, 24 Jan 2013 00:41:38 +0000 (01:41 +0100)] 
CLEANUP: tcp/unix: remove useless NULL check in {tcp,unix}_bind_listener()

errmsg may only be NULL if errlen is zero. Clarify this in the comment too.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoCLEANUP: http: remove a useless null check
Willy Tarreau [Thu, 24 Jan 2013 00:25:25 +0000 (01:25 +0100)] 
CLEANUP: http: remove a useless null check

srv cannot be null in http_perform_server_redirect(), as it's taken
from the stream interface's target which is always valid for a
server-based redirect, and it was already dereferenced above, so in
practice, gcc already removes the test anyway.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MINOR: log: improper NULL return check on utoa_pad()
Willy Tarreau [Thu, 24 Jan 2013 00:18:16 +0000 (01:18 +0100)] 
BUG/MINOR: log: improper NULL return check on utoa_pad()

utoa_pad() is directly fed into tmplog, which is checked for NULL.
First, when NULLs are possible, they should be put into a temp variable
in order to preserve tmplog, and second, this return value can never be
NULL because the value passed is tv_usec/1000 (between "0" and "999")
with a 4-char output. However better fix the check in case this code gets
improperly copy-pasted for another usage later.

Reported-by: Dinko Korunic <dkorunic@reflected.net>
12 years agoBUG/MINOR: cli: show sess should always validate s->listener
Willy Tarreau [Wed, 23 Jan 2013 23:48:39 +0000 (00:48 +0100)] 
BUG/MINOR: cli: show sess should always validate s->listener

Currently s->listener is set for all sessions, but this may not remain
the case forever so we already check s->listener for validity. On check
was missed.

Reported-by: Dinko Korunic <dkorunic@reflected.net>