]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
11 years agoMEDIUM: backend: Enhance hash-type directive with an algorithm options
Bhaskar [Wed, 30 Oct 2013 03:30:51 +0000 (23:30 -0400)] 
MEDIUM: backend: Enhance hash-type directive with an algorithm options

Summary:
In testing at tumblr, we found that using djb2 hashing instead of the
default sdbm hashing resulted is better workload distribution to our backends.

This commit implements a change, that allows the user to specify the hash
function they want to use. It does not limit itself to consistent hashing
scenarios.

The supported hash functions are sdbm (default), and djb2.

For a discussion of the feature and analysis, see mailing list thread
"Consistent hashing alternative to sdbm" :

      http://marc.info/?l=haproxy&m=138213693909219

Note: This change does NOT make changes to new features, for instance,
applying an avalance hashing always being performed before applying
consistent hashing.

11 years agoBUG/MINOR: acl: remove patterns from the tree before freeing them
Willy Tarreau [Thu, 14 Nov 2013 15:00:12 +0000 (16:00 +0100)] 
BUG/MINOR: acl: remove patterns from the tree before freeing them

A call to free_pattern_tree() upon exit() is made to free all ACL
patterns allocated in a tree (strings or IP addresses). Unfortunately
it happens that this function has been bogus from the beginning, it
walks over the whole tree, frees the nodes but forgets to remove them
from the tree prior to freeing them. So after visiting a leaf, the
next eb_next() call will require to revisit some of the upper nodes
that were just freed. This can remain unnoticed for a long time because
free() often just marks the area as free. But in cases of aggressive
memory freeing, the location will not be mapped anymore and the process
segfaults.

Note that the bug has no impact other than polluting kernel logs and
frightening sysadmins, since it happens just before exit().

Simply adding the debug code below makes it easier to reproduce the
same bug :

while (node) {
next = eb_next(node);
+ node->node_p = (void *)-1;
free(node);
node = next;
}

Many thanks to the StackExchange team for their very detailed bug report
that permitted to quickly understand this non-obvious bug!

This fix should be backported to 1.4 which introduced the bug.

11 years agoMINOR: buffer: align the last output line of buffer_dump()
Godbach [Thu, 14 Nov 2013 02:15:20 +0000 (10:15 +0800)] 
MINOR: buffer: align the last output line of buffer_dump()

If the dumped length of buffer is not multiple of 16, the last output line can
be seen as below:

Dumping contents from byte 0 to byte 125
         0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
  0000: 47 45 54 20 2f 69 6e 64 - 65 78 2e 68 74 6d 20 48   GET /index.htm H
  0010: 54 54 50 2f 31 2e 30 0d - 0a 55 73 65 72 2d 41 67   TTP/1.0..User-Ag
  ...
  0060: 30 0d 0a 43 6f 6e 6e 65 - 63 74 69 6f 6e 3a 20 4b   0..Connection: K
  0070: 65 65 70 2d 41 6c 69 76 - 65 0d 0a 0d 0a   eep-Alive....

Yes, the hex column will be overlapped by the text column. Both the hex and
text column should be aligned at their own area as below:

Dumping contents from byte 0 to byte 125
         0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
  0000: 47 45 54 20 2f 69 6e 64 - 65 78 2e 68 74 6d 20 48   GET /index.htm H
  0010: 54 54 50 2f 31 2e 30 0d - 0a 55 73 65 72 2d 41 67   TTP/1.0..User-Ag
  ...
  0060: 30 0d 0a 43 6f 6e 6e 65 - 63 74 69 6f 6e 3a 20 4b   0..Connection: K
  0070: 65 65 70 2d 41 6c 69 76 - 65 0d 0a 0d 0a            eep-Alive....

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoMINOR: tcp: don't use tick_add_ifset() when timeout is known to be set
Willy Tarreau [Mon, 4 Nov 2013 14:56:53 +0000 (15:56 +0100)] 
MINOR: tcp: don't use tick_add_ifset() when timeout is known to be set

These two useless tests propably result from a copy-paste. The test is
performed in the condition to enter the block.

11 years agoMINOR: acl: add a warning when an ACL keyword is used without any value
Willy Tarreau [Mon, 4 Nov 2013 17:09:12 +0000 (18:09 +0100)] 
MINOR: acl: add a warning when an ACL keyword is used without any value

It's quite common to write directives like the following :

  tcp-request reject if WAIT_END { sc0_inc_gpc0 }

This one will never reject, because sc0_inc_gpc0 is provided no value
to compare against. The proper form should have been something like this :

  tcp-request reject if WAIT_END { sc0_inc_gpc0 gt 0 }

or :

  tcp-request reject if WAIT_END { sc0_inc_gpc0 -m found }

Now we detect the absence of any argument on the command line and emit
a warning suggesting alternatives or the use of "--" to really avoid
matching anything (might be used when debugging).

11 years agoBUG/MEDIUM: acl: do not evaluate next terms after a miss
Willy Tarreau [Wed, 30 Oct 2013 18:30:32 +0000 (19:30 +0100)] 
BUG/MEDIUM: acl: do not evaluate next terms after a miss

When a condition does something like :

   action if A B C || D E F

If B returns a miss (can't tell true or false), C must not
be evaluated. This is important when C has a side effect
(eg: sc*_inc_gpc0). However the second part after the ||
can still be evaluated.

11 years agoBUG/MEDIUM: tcp: do not skip tracking rules on second pass
Willy Tarreau [Wed, 30 Oct 2013 18:24:00 +0000 (19:24 +0100)] 
BUG/MEDIUM: tcp: do not skip tracking rules on second pass

The track-sc* tcp rules are bogus. The test to verify if the
tracked counter was already assigned is performed in the same
condition as the test for the action. The effect is that a
rule which tracks a counter that is already being tracked
is implicitly converted to an accept because the default
rule is an accept.

This bug only affects 1.5-dev releases.

11 years agoBUG/MINOR: peers: set the accept date in outgoing connections
Willy Tarreau [Tue, 1 Oct 2013 15:06:10 +0000 (17:06 +0200)] 
BUG/MINOR: peers: set the accept date in outgoing connections

Without this, "show sess" on the CLI reports a wrong age.

11 years agoBUG/MEDIUM: session: risk of crash on out of memory conditions
Willy Tarreau [Sun, 20 Oct 2013 21:10:28 +0000 (23:10 +0200)] 
BUG/MEDIUM: session: risk of crash on out of memory conditions

In session_accept(), if we face a memory allocation error, we try to
emit an HTTP 500 error message in HTTP mode. The problem is that we
must not use http_error_message() for this since it dereferences the
session which can be NULL in this case.

We don't need the session to build the error message anyway since
this function only uses it to retrieve the backend and frontend to
get the most suited error message. Let's pick it ourselves, we're
at the beginning of the session, only the frontend is relevant.

This bug is 1.5-specific.

11 years agoBUILD/MINOR: missing header file
Thierry FOURNIER [Wed, 16 Oct 2013 14:19:38 +0000 (16:19 +0200)] 
BUILD/MINOR: missing header file

In the header file "types/proto_http.h", the list are used
but the header file "mini-clist.h" is not included.

11 years agoMINOR: http: change url_decode to return the size of the decoded string.
Thierry FOURNIER [Fri, 4 Oct 2013 14:27:27 +0000 (16:27 +0200)] 
MINOR: http: change url_decode to return the size of the decoded string.

Currently url_decode returns 1 or 0 depending on whether it could decode
the string or not. For some future use cases, it will be needed to get the
decoded string length after a successful decoding, so let's make it return
that value, and fall back to a negative one in case of error.

11 years agoMINOR: http: some exported functions were not in the header file
Thierry FOURNIER [Tue, 15 Oct 2013 09:43:19 +0000 (11:43 +0200)] 
MINOR: http: some exported functions were not in the header file

Export the following functions:
 - find_hdr_value_end
 - http_header_match2
 - http_remove_header2
 - http_header_add_tail2

11 years agoCLEANUP: The function "regex_exec" needs the string length but in many case they...
Thierry FOURNIER [Tue, 15 Oct 2013 11:41:44 +0000 (13:41 +0200)] 
CLEANUP: The function "regex_exec" needs the string length but in many case they expect null terminated char.

If haproxy is compiled with the USE_PCRE_JIT option, the length of the
string is used. If it is compiled without this option the function doesn't
use the length and expects a null terminated string.

The prototype of the function is ambiguous, and depends on the
compilation option. The developer can think that the length is always
used, and many bugs can be created.

This patch makes sure that the length is used. The regex_exec function
adds the final '\0' if it is needed.

11 years agoMINOR: Makefile: provide cscope rule
William Lallemand [Fri, 18 Oct 2013 14:26:39 +0000 (16:26 +0200)] 
MINOR: Makefile: provide cscope rule

"make cscope" builds tags for cscope.

11 years agoBUG/MINOR: acl: implicit arguments of ACL keywords were not properly resolved
Willy Tarreau [Tue, 22 Oct 2013 17:10:06 +0000 (19:10 +0200)] 
BUG/MINOR: acl: implicit arguments of ACL keywords were not properly resolved

William Lallemand reported a bug which happens when an ACL keyword using an
implicit argument (eg: a proxy name) is used : the keyword is not properly
set in the arglist field, resulting in an error about the previous keyword
being returned, or "(null)" if the faulty ACL appears first.

The bug only affects error reporting and is 1.5-specific, so no backport is
nedeed.

11 years agoBUG/MEDIUM: http: accept full buffers on smp_prefetch_http
Willy Tarreau [Mon, 14 Oct 2013 20:41:30 +0000 (22:41 +0200)] 
BUG/MEDIUM: http: accept full buffers on smp_prefetch_http

Bertrand Jacquin reported a but when using tcp_request content rules
on large POST HTTP requests. The issue is that smp_prefetch_http()
first tries to validate an input buffer, but only if the buffer is
not full. This test is wrong since it must only be performed after
the parsing has failed, otherwise we don't accept POST requests which
fill the buffer as valid HTTP requests.

This bug is 1.5-specific, no backport needed.

11 years agoCLEANUP: regex: Create regex_comp function that compiles regex using compilation...
Thierry FOURNIER [Mon, 14 Oct 2013 12:07:36 +0000 (14:07 +0200)] 
CLEANUP: regex: Create regex_comp function that compiles regex using compilation options

The current file "regex.h" define an abstraction for the regex. It
provides the same struct name and the same "regexec" function for the
3 regex types supported: standard libc, basic pcre and jit pcre.

The regex compilation function is not provided by this file. If the
developper wants to use regex, he must write regex compilation code
containing "#define *JIT*".

This patch provides a unique regex compilation function according to
the compilation options.

In addition, the "regex.h" file checks the presence of the "#define
PCRE_CONFIG_JIT" when "USE_PCRE_JIT" is enabled. If this flag is not
present, the pcre lib doesn't support JIT and "#error" is emitted.

11 years agoCLEANUP: stream_interface: cleanup loop information in si_conn_send_loop()
Godbach [Fri, 11 Oct 2013 07:48:29 +0000 (15:48 +0800)] 
CLEANUP: stream_interface: cleanup loop information in si_conn_send_loop()

Though si_conn_send_loop() does not loop over ->snd_buf() after commit ed7f836,
there is still some codes left which use `while` but only execute once. This
commit does the cleanup job and rename si_conn_send_loop() to si_conn_send().

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoDOC: missing http-send-name-header keyword in keyword table
Baptiste Assmann [Wed, 9 Oct 2013 19:57:02 +0000 (21:57 +0200)] 
DOC: missing http-send-name-header keyword in keyword table

This one was in the doc but not in the keyword matrix.

11 years agoDOC: missing information for the "description" keyword
Baptiste Assmann [Wed, 9 Oct 2013 04:51:49 +0000 (06:51 +0200)] 
DOC: missing information for the "description" keyword

This keyword was not documented.

11 years agoBUILD/MINOR: missing header file
Thierry FOURNIER [Wed, 9 Oct 2013 13:23:01 +0000 (15:23 +0200)] 
BUILD/MINOR: missing header file

In the header file "common/regex.h", the C keyword NULL is used. This
keyword is referenced into the header file "stdlib.h", but this is not
included.

11 years agoBUG/MINOR: ssl: verifyhost does not match empty strings on wildcard.
Emeric Brun [Tue, 8 Oct 2013 09:39:35 +0000 (11:39 +0200)] 
BUG/MINOR: ssl: verifyhost does not match empty strings on wildcard.

RFC6125 does not specify if wildcard matches empty strings but
classical browsers implementations does.
After the fix foo*bar.exemple.om matches foobar.exemple.com.

11 years agoMINOR: ssl: optimization of verifyhost on wildcard certificates.
Emeric Brun [Tue, 8 Oct 2013 09:27:28 +0000 (11:27 +0200)] 
MINOR: ssl: optimization of verifyhost on wildcard certificates.

Optimizes verifyhost on wildcard certificates avoiding travel several times
the same string.

11 years agoBUG/MINOR: ssl: potential memory leaks using ssl_c_key_alg or ssl_c_sig_alg.
Emeric Brun [Mon, 7 Oct 2013 12:31:44 +0000 (14:31 +0200)] 
BUG/MINOR: ssl: potential memory leaks using ssl_c_key_alg or ssl_c_sig_alg.

The leak occurs in an error case which practically never happens.

11 years agoBUG/MINOR: deinit: free server map which is allocated in init_server_map()
Godbach [Wed, 2 Oct 2013 09:10:11 +0000 (17:10 +0800)] 
BUG/MINOR: deinit: free server map which is allocated in init_server_map()

Both static-rr and hash with type map-based call init_server_map() to allocate
server map, so the server map should be freed while doing cleanup if one of
the above load balance algorithms is used.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
[wt: removed the unneeded "if" before the free]

11 years agoDOC: fix typo in comments
Godbach [Mon, 30 Sep 2013 03:23:10 +0000 (11:23 +0800)] 
DOC: fix typo in comments

Hi Willy,

There is a patch to fix typo in comments, please check the attachment
for you information.

The commit log is as below:

commit 9824d1b3740ac2746894f1aa611c795366c84210
Author: Godbach <nylzhaowei@gmail.com>
Date:   Mon Sep 30 11:05:42 2013 +0800

    DOC: fix typo in comments

      0x20000000 -> 0x40000000
      vuf -> buf
      ethod -> Method

Signed-off-by: Godbach <nylzhaowei@gmail.com>
--
Best Regards,
Godbach

From 9824d1b3740ac2746894f1aa611c795366c84210 Mon Sep 17 00:00:00 2001
From: Godbach <nylzhaowei@gmail.com>
Date: Mon, 30 Sep 2013 11:05:42 +0800
Subject: [PATCH] DOC: fix typo in comments

  0x20000000 -> 0x40000000
  vuf -> buf
  ethod -> Method

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoDOC: ssl: update build instructions to use new SSL_* variables
Lukas Tribus [Mon, 30 Sep 2013 22:28:03 +0000 (00:28 +0200)] 
DOC: ssl: update build instructions to use new SSL_* variables

Since commit 9a05945bd ("BUILD: add SSL_INC/SSL_LIB variables to force the
path to openssl") we have SSL_INC and SSL_LIB to point to the libssl
installation.

This commits updates the build instructions in README accordingly.

11 years agoDOC: remove -s and -l options from the manpage
Apollon Oikonomopoulos [Sun, 29 Sep 2013 20:04:27 +0000 (23:04 +0300)] 
DOC: remove -s and -l options from the manpage

These options are no longer supported since 1.3, so remove them from the
manpage.

Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com>
11 years agoDOC: update manpage reference to haproxy-en.txt
Apollon Oikonomopoulos [Sun, 29 Sep 2013 20:04:13 +0000 (23:04 +0300)] 
DOC: update manpage reference to haproxy-en.txt

The manpage refers to haproxy-en.txt, which is obsolete. Update the reference
to point to configuration.txt, together with the location on Debian systems.

Also capitalize "Debian".

Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com>
11 years agoDOC: add manpage references to all system calls
Apollon Oikonomopoulos [Sun, 29 Sep 2013 20:03:51 +0000 (23:03 +0300)] 
DOC: add manpage references to all system calls

Add a man section to every system call reference, giving users pointers to the
respective manpages.

Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com>
11 years agoDOC: add missing options to the manpage
Apollon Oikonomopoulos [Sun, 29 Sep 2013 20:03:37 +0000 (23:03 +0300)] 
DOC: add missing options to the manpage

Document -L, -v(v), -C, -dS and -dM, as they were missing from the manpage.

Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com>
11 years agoBUG/MINOR: acl: fix improper string size assignment in proxy argument
Willy Tarreau [Sun, 29 Sep 2013 09:36:53 +0000 (11:36 +0200)] 
BUG/MINOR: acl: fix improper string size assignment in proxy argument

This minor bug was found using the coccinelle script "da.cocci". The
len was initialized twice instead of setting the size. It's harmless
since no operations are performed on this empty string but needs to
be fixed anyway.

11 years agoMINOR: http: compute response time before processing headers
Willy Tarreau [Mon, 23 Sep 2013 14:44:27 +0000 (16:44 +0200)] 
MINOR: http: compute response time before processing headers

At the moment, HTTP response time is computed after response headers are
processed. This can misleadingly assign to the server some heavy local
processing (eg: regex), and also prevents response headers from passing
information related to the response time (which can sometimes be useful
for stats).

Let's retrieve the reponse time before processing the headers instead.

Note that in order to remain compatible with what was previously done,
we disable the response time when we get a 502 or any bad response. This
should probably be changed in 1.6 since it does not make sense anymore
to lose this information.

11 years agoBUG/MINOR: fix forcing fastinter in "on-error"
Sergiy Prykhodko [Sat, 21 Sep 2013 09:05:00 +0000 (12:05 +0300)] 
BUG/MINOR: fix forcing fastinter in "on-error"

health_adjust() should requeue the task after changing its expire timer.

I noticed it on devel servers without load. We have long inter (10 seconds)
and short fasinter (100ms). But according to webserver logs, after a failed
request next check request was called with same 10s interval.

This patch should probably be backported to 1.4 which has the same feature.

11 years agoBUILD: ssl: compilation issue with openssl v0.9.6.
Emeric Brun [Tue, 17 Sep 2013 13:47:48 +0000 (15:47 +0200)] 
BUILD: ssl: compilation issue with openssl v0.9.6.

Failed to compile with openssl 0.9.6 since the 'verifyhost' feature.

11 years agoBUG/MEDIUM: ssl: potential memory leak using verifyhost
Emeric Brun [Tue, 17 Sep 2013 13:19:54 +0000 (15:19 +0200)] 
BUG/MEDIUM: ssl: potential memory leak using verifyhost

If server certificate presents dns aliases, a memory leak appears
on health checks when 'verifyhost' statement is used.

11 years agoBUILD: add SSL_INC/SSL_LIB variables to force the path to openssl
Willy Tarreau [Tue, 17 Sep 2013 13:26:39 +0000 (15:26 +0200)] 
BUILD: add SSL_INC/SSL_LIB variables to force the path to openssl

When trying to build with various versions of openssl, forcing the
path is still cumbersome. Let's add SSL_INC and SSL_LIB similar to
PCRE_INC and PCRE_LIB to allow forcing the path to the SSL includes
and libs.

11 years agoMINOR: payload: provide the "res.len" fetch method
Willy Tarreau [Wed, 11 Sep 2013 21:28:46 +0000 (23:28 +0200)] 
MINOR: payload: provide the "res.len" fetch method

This fetch method returns the response buffer len, similarly
to req.len for the request. Previously it was only possible
to rely on "res.payload(0,size) -m found" to find if at least
that amount of data was available, which was a bit tricky.

11 years agoMINOR: tcp: add new "close" action for tcp-response
Willy Tarreau [Wed, 11 Sep 2013 21:20:29 +0000 (23:20 +0200)] 
MINOR: tcp: add new "close" action for tcp-response

This new action immediately closes the connection with the server
when the condition is met. The first such rule executed ends the
rules evaluation. The main purpose of this action is to force a
connection to be finished between a client and a server after an
exchange when the application protocol expects some long time outs
to elapse first. The goal is to eliminate idle connections which
take signifiant resources on servers with certain protocols.

11 years agoMEDIUM: stick-tables: flush old entries upon soft-stop
Willy Tarreau [Wed, 4 Sep 2013 15:54:01 +0000 (17:54 +0200)] 
MEDIUM: stick-tables: flush old entries upon soft-stop

When a process with large stick tables is replaced by a new one and remains
present until the last connection finishes, it keeps these data in memory
for nothing since they will never be used anymore by incoming connections,
except during syncing with the new process. This is especially problematic
when dealing with long session protocols such as WebSocket as it becomes
possible to stack many processes and eat a lot of memory.

So the idea here is to know if a table still needs to be synced or not,
and to purge all unused entries once the sync is complete. This means that
after a few hundred milliseconds when everything has been synchronized with
the new process, only a few entries will remain allocated (only the ones
held by sessions during the restart) and all the remaining memory will be
freed.

Note that we carefully do that only after the grace period is expired so as
not to impact a possible proxy that needs to accept a few more connections
before leaving.

Doing this required to add a sync counter to the stick tables, to know how
many peer sync sessions are still in progress in order not to flush the entries
until all synchronizations are completed.

11 years agoBUG/MEDIUM: fix broken send_proxy on FreeBSD
Willy Tarreau [Tue, 3 Sep 2013 07:02:11 +0000 (09:02 +0200)] 
BUG/MEDIUM: fix broken send_proxy on FreeBSD

David Berard reported that send-proxy was broken on FreeBSD and tracked the
issue to be an error returned by send(). We already had the same issue in
the past in another area which was addressed by the following commit :

   0ea0cf6 BUG: raw_sock: also consider ENOTCONN in addition to EAGAIN

In fact, on Linux send() returns EAGAIN when the connection is not yet
established while other OSes return ENOTCONN. Let's consider ENOTCONN for
send-proxy there as the same as EAGAIN.

David confirmed that this change properly fixed the issue.

Another place was affected as well (health checks with send-proxy), and
was fixed.

This fix does not need any backport since it only affects 1.5.

11 years agoMINOR: ssl: Add statement 'verifyhost' to "server" statements
Evan Broder [Thu, 27 Jun 2013 07:05:25 +0000 (00:05 -0700)] 
MINOR: ssl: Add statement 'verifyhost' to "server" statements

verifyhost allows you to specify a hostname that the remote server's
SSL certificate must match. Connections that don't match will be
closed with an SSL error.

11 years agoDOC: add a mention about the limited chunk size
Willy Tarreau [Sat, 31 Aug 2013 06:16:26 +0000 (08:16 +0200)] 
DOC: add a mention about the limited chunk size

We now indicate that PD flags can be returned for chunk sizes >= 2GB.

11 years agoBUG/MINOR: log: junk at the end of syslog packet
William Lallemand [Fri, 30 Aug 2013 12:17:46 +0000 (14:17 +0200)] 
BUG/MINOR: log: junk at the end of syslog packet

With a facily of 2 or 1 digit, the send size was wrong and bytes with
unknown value were sent.
The size was calculated using the start of the buffer and not the start
of the data which varies with the number of digits of the facility.

This bug was reported by Samuel Stoller and reported by Lukas Tribus.

11 years agoBUG/MEDIUM: unique_id: junk in log on empty unique_id
William Lallemand [Wed, 28 Aug 2013 13:44:19 +0000 (15:44 +0200)] 
BUG/MEDIUM: unique_id: junk in log on empty unique_id

When a request fail, the unique_id was allocated but not generated.
The string was not initialized and junk was printed in the log with %ID.

This patch changes the behavior of the unique_id. The unique_id is now
generated when a request failed.

This bug was reported by Patrick Hemmer.

11 years agoBUG/MEDIUM: unique_id: HTTP request counter must be unique!
Willy Tarreau [Tue, 13 Aug 2013 15:51:07 +0000 (17:51 +0200)] 
BUG/MEDIUM: unique_id: HTTP request counter must be unique!

The HTTP request counter is incremented non atomically, which means that
many requests can log the same ID. Let's increment it when it is consumed
so that we avoid this case.

This bug was reported by Patrick Hemmer. It's 1.5-specific and does not
need to be backported.

11 years agoMINOR: config: warn when a server with no specific port uses rdp-cookie
Willy Tarreau [Tue, 13 Aug 2013 15:19:08 +0000 (17:19 +0200)] 
MINOR: config: warn when a server with no specific port uses rdp-cookie

Mathew Levett reported an issue which is a bit nasty and hard to track
down. RDP cookies contain both the IP and the port, and haproxy matches
them exactly. So if a server has no port specified (or a remapped port),
it will never match a port specified in a cookie. Better warn the user
when this is detected.

11 years agoMINOR: ssl: use MAXPATHLEN instead of PATH_MAX
Willy Tarreau [Tue, 13 Aug 2013 14:59:39 +0000 (16:59 +0200)] 
MINOR: ssl: use MAXPATHLEN instead of PATH_MAX

Apollon Oikonomopoulos reported a build failure on Hurd where PATH_MAX
is not defined. The only place where it is referenced is ssl_sock.c,
all other places use MAXPATHLEN instead, with a fallback to 128 when
the OS does not define it. So let's switch to MAXPATHLEN as well.

11 years agoBUG/MINOR: cli: "clear table" must not kill entries that don't match condition
Willy Tarreau [Tue, 13 Aug 2013 14:44:40 +0000 (16:44 +0200)] 
BUG/MINOR: cli: "clear table" must not kill entries that don't match condition

Mark Brooks reported the following issue :

"My table looks like this -

  0x24a8294: key=192.168.136.10 use=0 exp=1761492 server_id=3
  0x24a8344: key=192.168.136.11 use=0 exp=1761506 server_id=2
  0x24a83f4: key=192.168.136.12 use=0 exp=1761520 server_id=3
  0x24a84a4: key=192.168.136.13 use=0 exp=1761534 server_id=2
  0x24a8554: key=192.168.136.14 use=0 exp=1761548 server_id=3
  0x24a8604: key=192.168.136.15 use=0 exp=1761563 server_id=2
  0x24a86b4: key=192.168.136.16 use=0 exp=1761580 server_id=3
  0x24a8764: key=192.168.136.17 use=0 exp=1761592 server_id=2
  0x24a8814: key=192.168.136.18 use=0 exp=1761607 server_id=3
  0x24a88c4: key=192.168.136.19 use=0 exp=1761622 server_id=2
  0x24a8974: key=192.168.136.20 use=0 exp=1761636 server_id=3
  0x24a8a24: key=192.168.136.21 use=0 exp=1761649 server_id=2

im running the command -

  socat unix-connect:/var/run/haproxy.stat stdio <<< 'clear table VIP_Name-2 data.server_id eq 2'

Id assume that the entries with server_id = 2 would be removed but its
removing everything each time."

The cause of the issue is a missing test for skip_entry when deciding
whether to clear the key or not. The test was present when only the
last node is to be removed, so removing only the first node from a
list of two always did the right thing, explaining why it remained
unnoticed in basic unit tests.

The bug was introduced by commit 8fa52f4e which attempted to fix a
previous issue with this feature where only the last node was removed.

This bug is 1.5-specific and does not require any backport.

11 years agoBUG/MINOR: use the same check condition for server as other algorithms
Godbach [Wed, 7 Aug 2013 01:48:23 +0000 (09:48 +0800)] 
BUG/MINOR: use the same check condition for server as other algorithms

Such load balance algorithms as roundrobin, leastconn and first will check the
server after being selected with the following condition:
if (!s->maxconn || (!s->nbpend && s->served < srv_dynamic_maxconn(s)))

But static-rr uses the different one in map_get_server_rr()  as below:
if (!srv->maxconn || srv->cur_sess < srv_dynamic_maxconn(srv))
After viewing this difference, it is a better choice for static-rr to use the
same check condition as other algorithms.

This change will only affect static-rr. Though all hash algorithms with type
map-based will use the same server map as static-rr, they call another function
map_get_server_hash() to get server.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
11 years agoMINOR: payload: allow the payload sample fetches to retrieve arbitrary lengths
Willy Tarreau [Fri, 2 Aug 2013 09:07:32 +0000 (11:07 +0200)] 
MINOR: payload: allow the payload sample fetches to retrieve arbitrary lengths

When using req.payload and res.payload to look up for specific content at an
arbitrary location, we're often facing the problem of not knowing the input
buffer length. If the length argument is larger than the buffer length, the
function did not match, and if they're smaller, there is a risk of not getting
the expected content. This is especially true when looking for data in SOAP
requests.

So let's make some provisions for scanning the whole buffer by specifying a
length of 0 bytes. This greatly simplifies the processing of random-sized
input data.

11 years agoMINOR: cli: make it possible to enter multiple values at once with "set table"
Willy Tarreau [Thu, 1 Aug 2013 19:11:42 +0000 (21:11 +0200)] 
MINOR: cli: make it possible to enter multiple values at once with "set table"

The "set table" statement allows to create new entries with their respective
values. Till now it was limited to a single data type per line, requiring as
many "set table" statements as the desired data types to be set. Since this
is only a parser limitation, this patch gets rid of it. It also allows the
creation of a key with no data types (all reset to their default values).

11 years agoMEDIUM: cli: adjust the method for feeding frequency counters in tables
Willy Tarreau [Tue, 23 Jul 2013 21:44:30 +0000 (23:44 +0200)] 
MEDIUM: cli: adjust the method for feeding frequency counters in tables

Since commit 654694e1, it has been possible to feed some data into
stick tables from the CLI. That commit considered that frequency
counters would only have their previous value set, so that they
progressively fade out. But this does not match any real world
use case in fact. The only reason for feeding a freq counter is
to pass some data learned outside. We certainly don't want to see
such data start to vanish immediately, otherwise it will force the
external scripts to loop very frequently to limit the losses.

So let's set the current value instead in order to guarantee that
the data remains stable over the full period, then starts to fade
out between 1* and 2* the period.

11 years agoMEDIUM: counters: support looking up a key in an alternate table
Willy Tarreau [Tue, 23 Jul 2013 17:56:43 +0000 (19:56 +0200)] 
MEDIUM: counters: support looking up a key in an alternate table

sc_* sample fetches now take an optional parameter which allows to look
the key in an alternate table. This is convenient to pass multiple
information for the same key at once (eg: have multiple gpc0 for the
same key, or support being fed complementary information from the CLI).
Example :

    listen front
        bind :8000
        tcp-request content track-sc0 src table local-ip
        http-response set-header src-id %[sc0_get_gpc0]+%[sc0_get_gpc0(global-ip)]
        server dummy 127.0.0.1:8001

    backend local-ip
        stick-table size 1k type ip store gpc0

    backend global-ip
        stick-table size 1k type ip store gpc0

11 years agoMEDIUM: counters: support passing the counter number as a fetch argument
Willy Tarreau [Tue, 23 Jul 2013 17:33:46 +0000 (19:33 +0200)] 
MEDIUM: counters: support passing the counter number as a fetch argument

One very annoying issue when trying to extend the sticky counters beyond
the current 3 counters is that it requires a massive copy-paste of fetch
functions (we don't have to copy-paste code anymore), just so that the
fetch names exist.

So let's have an alternate form like "sc_*(num)" to allow passing the
counter number as an argument without having to redefine new fetch names.
The MAX_SESS_STKCTR macro defines the number of usable sticky counters,
which defaults to 3.

11 years agoMINOR: session: make the number of stick counter entries more configurable
Willy Tarreau [Tue, 23 Jul 2013 17:15:30 +0000 (19:15 +0200)] 
MINOR: session: make the number of stick counter entries more configurable

In preparation of more flexibility in the stick counters, make their
number configurable. It still defaults to 3 which is the minimum
accepted value. Changing the value alone is not sufficient to get
more counters, some bitfields still need to be updated and the TCP
actions need to be updated as well, but this update tries to be
easier, which is nice for experimentation purposes.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_trackers
Willy Tarreau [Tue, 23 Jul 2013 16:32:02 +0000 (18:32 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_trackers

smp_fetch_sc0_trackers, smp_fetch_sc1_trackers and smp_fetch_sc2_trackers
were merged into a single function which relies on the fetch name to decide
what to return.

This is also a bug fix for this feature which has never worked till its bogus
introduction by commit "2406db4 MEDIUM: counters: add sc1_trackers/sc2_trackers"
(1.5-dev10).

Instead of returning the value in the sample, it was returned as the fetch
result!

There is no need to backport this fix anyway since it's 1.5-specific and
nobody uses the feature.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_bytes_out_rate
Willy Tarreau [Tue, 23 Jul 2013 16:26:32 +0000 (18:26 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_bytes_out_rate

smp_fetch_sc0_bytes_out_rate, smp_fetch_sc1_bytes_out_rate, smp_fetch_sc2_bytes_out_rate,
smp_fetch_src_bytes_out_rate and smp_fetch_bytes_out_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_kbytes_out
Willy Tarreau [Tue, 23 Jul 2013 15:39:02 +0000 (17:39 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_kbytes_out

smp_fetch_sc0_kbytes_out, smp_fetch_sc1_kbytes_out, smp_fetch_sc2_kbytes_out,
smp_fetch_src_kbytes_out and smp_fetch_kbytes_out were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_bytes_in_rate
Willy Tarreau [Tue, 23 Jul 2013 15:39:19 +0000 (17:39 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_bytes_in_rate

smp_fetch_sc0_bytes_in_rate, smp_fetch_sc1_bytes_in_rate, smp_fetch_sc2_bytes_in_rate,
smp_fetch_src_bytes_in_rate and smp_fetch_bytes_in_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_kbytes_in
Willy Tarreau [Tue, 23 Jul 2013 15:17:10 +0000 (17:17 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_kbytes_in

smp_fetch_sc0_kbytes_in, smp_fetch_sc1_kbytes_in, smp_fetch_sc2_kbytes_in,
smp_fetch_src_kbytes_in and smp_fetch_kbytes_in were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_http_err_rate
Willy Tarreau [Tue, 23 Jul 2013 14:48:54 +0000 (16:48 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_http_err_rate

smp_fetch_sc0_http_err_rate, smp_fetch_sc1_http_err_rate, smp_fetch_sc2_http_err_rate,
smp_fetch_src_http_err_rate and smp_fetch_http_err_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_http_err_cnt
Willy Tarreau [Tue, 23 Jul 2013 14:45:38 +0000 (16:45 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_http_err_cnt

smp_fetch_sc0_http_err_cnt, smp_fetch_sc1_http_err_cnt, smp_fetch_sc2_http_err_cnt,
smp_fetch_src_http_err_cnt and smp_fetch_http_err_cnt were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_http_req_rate
Willy Tarreau [Tue, 23 Jul 2013 14:04:37 +0000 (16:04 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_http_req_rate

smp_fetch_sc0_http_req_rate, smp_fetch_sc1_http_req_rate, smp_fetch_sc2_http_req_rate,
smp_fetch_src_http_req_rate and smp_fetch_http_req_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_http_req_cnt
Willy Tarreau [Tue, 23 Jul 2013 13:55:19 +0000 (15:55 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_http_req_cnt

smp_fetch_sc0_http_req_cnt, smp_fetch_sc1_http_req_cnt, smp_fetch_sc2_http_req_cnt,
smp_fetch_src_http_req_cnt and smp_fetch_http_req_cnt were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_sess_rate
Willy Tarreau [Tue, 23 Jul 2013 13:48:01 +0000 (15:48 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_sess_rate

smp_fetch_sc0_sess_rate, smp_fetch_sc1_sess_rate, smp_fetch_sc2_sess_rate,
smp_fetch_src_sess_rate and smp_fetch_sess_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_sess_cnt
Willy Tarreau [Tue, 23 Jul 2013 13:35:33 +0000 (15:35 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_sess_cnt

smp_fetch_sc0_sess_cnt, smp_fetch_sc1_sess_cnt, smp_fetch_sc2_sess_cnt,
smp_fetch_src_sess_cnt and smp_fetch_sess_cnt were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_conn_cur
Willy Tarreau [Tue, 23 Jul 2013 13:17:53 +0000 (15:17 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_conn_cur

smp_fetch_sc0_conn_cur, smp_fetch_sc1_conn_cur, smp_fetch_sc2_conn_cur,
smp_fetch_src_conn_cur and smp_fetch_conn_cur were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_conn_rate
Willy Tarreau [Tue, 23 Jul 2013 13:09:35 +0000 (15:09 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_conn_rate

smp_fetch_sc0_conn_rate, smp_fetch_sc1_conn_rate, smp_fetch_sc2_conn_rate,
smp_fetch_src_conn_rate and smp_fetch_conn_rate were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_conn_cnt
Willy Tarreau [Mon, 22 Jul 2013 22:22:50 +0000 (00:22 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_conn_cnt

smp_fetch_sc0_conn_cnt, smp_fetch_sc1_conn_cnt, smp_fetch_sc2_conn_cnt,
smp_fetch_src_conn_cnt and smp_fetch_conn_cnt were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_clr_gpc0
Willy Tarreau [Mon, 22 Jul 2013 22:10:35 +0000 (00:10 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_clr_gpc0

smp_fetch_sc0_clr_gpc0, smp_fetch_sc1_clr_gpc0, smp_fetch_sc2_clr_gpc0,
smp_fetch_src_clr_gpc0 and smp_fetch_clr_gpc0 were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_inc_gpc0
Willy Tarreau [Mon, 22 Jul 2013 22:07:04 +0000 (00:07 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_inc_gpc0

smp_fetch_sc0_inc_gpc0, smp_fetch_sc1_inc_gpc0, smp_fetch_sc2_inc_gpc0,
smp_fetch_src_inc_gpc0 and smp_fetch_inc_gpc0 were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_gpc0_rate
Willy Tarreau [Mon, 22 Jul 2013 21:47:07 +0000 (23:47 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_gpc0_rate

smp_fetch_sc0_gpc0, smp_fetch_sc1_gpc0, smp_fetch_sc2_gpc0,
smp_fetch_src_gpc0 and smp_fetch_gpc0 were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMEDIUM: counters: factor out smp_fetch_sc*_get_gpc0
Willy Tarreau [Mon, 22 Jul 2013 17:46:52 +0000 (19:46 +0200)] 
MEDIUM: counters: factor out smp_fetch_sc*_get_gpc0

smp_fetch_sc0_get_gpc0, smp_fetch_sc1_get_gpc0, smp_fetch_sc2_get_gpc0,
smp_fetch_src_get_gpc0 and smp_fetch_get_gpc0 were merged into a single
function which relies on the fetch name to decide what to return.

11 years agoMINOR: counters: provide a generic function to retrieve a stkctr for sc* and src.
Willy Tarreau [Mon, 22 Jul 2013 20:40:11 +0000 (22:40 +0200)] 
MINOR: counters: provide a generic function to retrieve a stkctr for sc* and src.

This function aims at simplifying the prefetching of the table and entry
when using any of the session counters fetches. The principle is that the
src_* variant produces a stkctr that is used instead of the one from the
session. That way we can call the same function from all session counter
fetch functions and always have a single function to support sc[0-9]_/src_.

11 years agoMINOR: counters: factor out smp_fetch_sc*_tracked
Willy Tarreau [Mon, 22 Jul 2013 16:29:29 +0000 (18:29 +0200)] 
MINOR: counters: factor out smp_fetch_sc*_tracked

The new function makes use of the sc# in the keyword to
get the counter ID.

11 years agoMINOR: payload: split smp_fetch_rdp_cookie()
Willy Tarreau [Mon, 22 Jul 2013 16:09:52 +0000 (18:09 +0200)] 
MINOR: payload: split smp_fetch_rdp_cookie()

This function is also called directly from backend.c, so let's stop
building fake args to call it as a sample fetch, and have a lower
layer more generic function instead.

11 years agoMEDIUM: sample: systematically pass the keyword pointer to the keyword
Willy Tarreau [Mon, 22 Jul 2013 14:29:32 +0000 (16:29 +0200)] 
MEDIUM: sample: systematically pass the keyword pointer to the keyword

We're having a lot of duplicate code just because of minor variants between
fetch functions that could be dealt with if the functions had the pointer to
the original keyword, so let's pass it as the last argument. An earlier
version used to pass a pointer to the sample_fetch element, but this is not
the best solution for two reasons :
  - fetch functions will solely rely on the keyword string
  - some other smp_fetch_* users do not have the pointer to the original
    keyword and were forced to pass NULL.

So finally we're passing a pointer to the keyword as a const char *, which
perfectly fits the original purpose.

11 years agoDOC: minor improvements to the part on the stats socket.
Willy Tarreau [Thu, 1 Aug 2013 14:50:16 +0000 (16:50 +0200)] 
DOC: minor improvements to the part on the stats socket.

Some people regularly ask for some details, which proves the doc is far
from being sufficient.

11 years agoMINOR: samples: add the http_date([<offset>]) sample converter.
Willy Tarreau [Thu, 25 Jul 2013 12:36:01 +0000 (14:36 +0200)] 
MINOR: samples: add the http_date([<offset>]) sample converter.

Converts an integer supposed to contain a date since epoch to
a string representing this date in a format suitable for use
in HTTP header fields. If an offset value is specified, then
it is a number of seconds that is added to the date before the
conversion is operated. This is particularly useful to emit
Date header fields, Expires values in responses when combined
with a positive offset, or Last-Modified values when the
offset is negative.

11 years agoMINOR: sample: add a new "date" fetch to return the current date
Willy Tarreau [Thu, 25 Jul 2013 12:28:25 +0000 (14:28 +0200)] 
MINOR: sample: add a new "date" fetch to return the current date

Returns the current date as the epoch (number of seconds since 01/01/1970).
If an offset value is specified, then it is a number of seconds that is added
to the current date before returning the value. This is particularly useful
to compute relative dates, as both positive and negative offsets are allowed.

11 years agoCLEANUP: acl: move the 3 remaining sample fetches to samples.c
Willy Tarreau [Thu, 25 Jul 2013 10:17:57 +0000 (12:17 +0200)] 
CLEANUP: acl: move the 3 remaining sample fetches to samples.c

There is no more reason for having "always_true", "always_false" and "env"
in acl.c while they're the most basic sample fetch keywords, so let's move
them to sample.c where it's easier to find them.

11 years agoMINOR: sample: fix sample_process handling of unstable data
Willy Tarreau [Thu, 25 Jul 2013 10:02:38 +0000 (12:02 +0200)] 
MINOR: sample: fix sample_process handling of unstable data

sample_process() used to return NULL on changing data, regardless of the
SMP_OPT_FINAL flag. Let's change this so that it is now possible to
include such data in logs or HTTP headers. Also, one unconvenient
thing was that it used to always set the sample flags to zero, making
it incompatible with ACLs which may need to call it multiple times. Only
do this for locally-allocated samples.

11 years agoMEDIUM: sample: handle comma-delimited converter list
Willy Tarreau [Wed, 24 Jul 2013 13:34:19 +0000 (15:34 +0200)] 
MEDIUM: sample: handle comma-delimited converter list

We now support having a comma-delimited converter list, which can start
right after the fetch keyword. The immediate benefit is that it allows
to use converters in log-format expressions, for example :

   set-header source-net %[src,ipmask(24)]

The parser is also slightly improved and should be more resilient against
configuration errors. Also, optional arguments in converters were mistakenly
not allowed till now, so this was fixed.

11 years agoOPTIM: splicing: use splice() for the last block when relevant
Willy Tarreau [Thu, 18 Jul 2013 20:21:54 +0000 (22:21 +0200)] 
OPTIM: splicing: use splice() for the last block when relevant

Splicing is avoided for small transfers because it's generally cheaper
to perform a couple of recv+send calls than pipe+splice+splice. This
has the consequence that the last chunk of a large transfer may be
transferred using recv+send if it's less than 4 kB. But when the pipe
is already set up, it's better to use splice() to read the pending data,
since they will get merged with the pending ones. This is what now
happens everytime the reader is slower than the writer.

Note that this change alone could have fixed most of the CPU hog bug,
except at the end when only the close was pending.

11 years agoBUG/MINOR: stream_interface: don't call chk_snd() on polled events
Willy Tarreau [Thu, 18 Jul 2013 20:09:48 +0000 (22:09 +0200)] 
BUG/MINOR: stream_interface: don't call chk_snd() on polled events

As explained in previous patch, we incorrectly call chk_snd() when
performing a read even if the write event is already subscribed to
poll(). This is counter-productive because we're almost sure to get
an EAGAIN.

A quick test shows that this fix halves the number of failed splice()
calls without adding any extra work on other syscalls.

This could have been tagged as an improvement, but since this behaviour
made the analysis of previous bug more complex, it still qualifies as
a fix.

11 years agoBUG/MEDIUM: splicing: fix abnormal CPU usage with splicing
Willy Tarreau [Thu, 18 Jul 2013 19:49:32 +0000 (21:49 +0200)] 
BUG/MEDIUM: splicing: fix abnormal CPU usage with splicing

Mark Janssen reported an issue in 1.5-dev19 which was introduced
in 1.5-dev12 by commit 96199b10. From time to time, randomly, the
CPU usage spikes to 100% for seconds to minutes.

A deep analysis of the traces provided shows that it happens when
waiting for the response to a second pipelined HTTP request, or
when trying to handle the received shutdown advertised by epoll()
after the last block of data. Each time, splice() was involved with
data pending in the pipe.

The cause of this was that such events could not be taken into account
by splice nor by recv and were left pending :

  - the transfer of the last block of data, optionally with a shutdown
    was not handled by splice() because of the validation that to_forward
    is higher than MIN_SPLICE_FORWARD ;

  - the next recv() call was inhibited because of the test on presence
    of data in the pipe. This is also what prevented the recv() call
    from handling a response to a pipelined request until the client
    had ACKed the previous response.

No less than 4 different methods were experimented to fix this, and the
current one was finally chosen. The principle is that if an event is not
caught by splice(), then it MUST be caught by recv(). So we remove the
condition on the pipe's emptiness to perform an recv(), and in order to
prevent recv() from being used in the middle of a transfer, we mark
supposedly full pipes with CO_FL_WAIT_ROOM, which makes sense because
the reason for stopping a splice()-based receive is that the pipe is
supposed to be full.

The net effect is that we don't wake up and sleep in loops during these
transient states. This happened much more often than expected, sometimes
for a few cycles at end of transfers, but rarely long enough to be
noticed, unless a client timed out with data pending in the pipe. The
effect on CPU usage is visible even when transfering 1MB objects in
pipeline, where the CPU usage drops from 10 to 6% on a small machine at
medium bandwidth.

Some further improvements are needed :
  - the last chunk of a splice() transfer is never done using splice due
    to the test on to_forward. This is wrong and should be performed with
    splice if the pipe has not yet been emptied ;

  - si_chk_snd() should not be called when the write event is already being
    polled, otherwise we're almost certain to get EAGAIN.

Many thanks to Mark for all the traces he cared to provide, they were
essential for understanding this issue which was not reproducible
without.

Only 1.5-dev is affected, no backport is needed.

11 years agoBUG/MEDIUM: server: set the macro for server's max weight SRV_UWGHT_MAX to SRV_UWGHT_...
Godbach [Sun, 21 Jul 2013 23:44:53 +0000 (07:44 +0800)] 
BUG/MEDIUM: server: set the macro for server's max weight SRV_UWGHT_MAX to SRV_UWGHT_RANGE

The max weight of server is 256 now, but SRV_UWGHT_MAX is still 255. As a result,
FWRR will not work well when server's weight is 256. The description is as below:

There are some macros related to server's weight in include/types/server.h:
    #define SRV_UWGHT_RANGE 256
    #define SRV_UWGHT_MAX   (SRV_UWGHT_RANGE - 1)
    #define SRV_EWGHT_MAX   (SRV_UWGHT_MAX   * BE_WEIGHT_SCALE)

Since weight of server can be reach to 256 and BE_WEIGHT_SCALE equals to 16,
the max eweight of server should be 256*16 = 4096, it will exceed SRV_EWGHT_MAX
which equals to SRV_UWGHT_MAX*BE_WEIGHT_SCALE = 255*16 = 4080. When a server
with weight 256 is insterted into FWRR tree during initialization, the key value
of this server should be SRV_EWGHT_MAX - s->eweight = 4080 - 4096 = -16 which
is closed to UINT_MAX in unsigned type, so the server with highest weight will
be not elected as the first server to process request.

In addition, it is a better choice to compare with SRV_UWGHT_MAX than a magic
number 256 while doing check for the weight. The max number of servers for
round-robin algorithm is also updated.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
12 years agoBUG/MAJOR: http: sample prefetch code was not properly migrated
Willy Tarreau [Sat, 6 Jul 2013 11:29:24 +0000 (13:29 +0200)] 
BUG/MAJOR: http: sample prefetch code was not properly migrated

When ACLs and samples were converged in 1.5-dev18, function
"acl_prefetch_http" was not properly converted after commit 8ed669b1.
It used to return -1 when contents did not match HTTP traffic, which
was considered as a "true" boolean result by the ACL execution code,
possibly causing crashes due to missing data when checking for HTTP
traffic in TCP rules.

Another issue is that when the function returned zero, it did not
set tje SMP_F_MAY_CHANGE flag, so it could randomly exit on partial
requests before waiting for a complete one.

Last issue is that when it returned 1, it did not set smp->data.uint,
so this last one would retain a random value from a past execution.
This could randomly cause some matches to fail as well.

Thanks to Remo Eichenberger for reporting this issue with a detailed
explanation and configuration.

This bug is 1.5-specific, no backport is needed.

12 years agoBUG/MEDIUM: http: "option checkcache" fails with the no-cache header
Willy Tarreau [Thu, 4 Jul 2013 10:46:56 +0000 (12:46 +0200)] 
BUG/MEDIUM: http: "option checkcache" fails with the no-cache header

The checkcache option checks for cacheable responses with a set-cookie
header. Since the response processing code was refactored in 1.3.8
(commit a15645d4), the check was broken because the no-cache value
is only checked as no-cache="set-cookie", and not alone.

Thanks to HervĂ© Commowick for reporting this stupid bug!

The fix should be backported to 1.4 and 1.3.

12 years agoBUG/MAJOR: http: don't emit the send-name-header when no server is available
Willy Tarreau [Thu, 4 Jul 2013 09:44:27 +0000 (11:44 +0200)] 
BUG/MAJOR: http: don't emit the send-name-header when no server is available

Lukas Benes reported that http-send-name-header causes a segfault if no
server is available because we're dereferencing the session's target which
is NULL. The tiniest reproducer looks like this :

     listen foo
         bind :1234
         mode http
         http-send-name-header srv

This obvious fix must be backported to 1.4 which is affected as well.

12 years agoDOC: minor typo fix in documentation
Godbach [Mon, 1 Jul 2013 17:19:15 +0000 (01:19 +0800)] 
DOC: minor typo fix in documentation

"http-reqsponse" => "http-response"

Signed-off-by: Godbach <nylzhaowei@gmail.com>
12 years agoBUG: counters: third counter was not stored if others unset
Willy Tarreau [Mon, 1 Jul 2013 16:07:03 +0000 (18:07 +0200)] 
BUG: counters: third counter was not stored if others unset

Commit e25c917a introduced a third tracking counter bug forgot
to check it when storing values at the end of the session. The
impact is that  if neither the first nor the second one are
changed, none of them are saved.

12 years agoBUG/MINOR: deinit: free fdinfo while doing cleanup
Godbach [Wed, 26 Jun 2013 08:49:51 +0000 (16:49 +0800)] 
BUG/MINOR: deinit: free fdinfo while doing cleanup

Both fdinfo and fdtab are allocated memory in init() while haproxy is starting,
but only fdtab is freed in deinit(), fdinfo should also be freed.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
12 years agoDOC: remove the comment saying that SSL certs are not checked on the server side
Willy Tarreau [Tue, 25 Jun 2013 05:56:20 +0000 (07:56 +0200)] 
DOC: remove the comment saying that SSL certs are not checked on the server side

Server certificate check was added in 1.5-dev13 but the comment on the "ssl"
keyword was not removed, leading to confusion about when to use it.

12 years agoMEDIUM: http: add IPv6 support for "set-tos"
Lukas Tribus [Sun, 23 Jun 2013 15:37:13 +0000 (17:37 +0200)] 
MEDIUM: http: add IPv6 support for "set-tos"

As per RFC3260 #4 and BCP37 #4.2 and #5.2, the IPv6 counterpart of TOS
is "traffic class".

Add support for IPv6 traffic class in "set-tos" by moving the "set-tos"
related code to the new inline function inet_set_tos(), handling IPv4
(IP_TOS), IPv6 (IPV6_TCLASS) and IPv4-mapped sockets (IP_TOS, like
::ffff:127.0.0.1).

Also define - if missing - the IN6_IS_ADDR_V4MAPPED() macro in
include/common/compat.h for compatibility.

12 years agoBUG/MINOR: http: fix "set-tos" not working in certain configurations
Lukas Tribus [Wed, 19 Jun 2013 21:34:41 +0000 (23:34 +0200)] 
BUG/MINOR: http: fix "set-tos" not working in certain configurations

s->req->prod->conn->addr.to.ss_family contains only useful data if
conn_get_to_addr() is called early. If thats not the case (nothing in the
configuration needs the destination address like logs, transparent, ...)
then "set-tos" doesn't work.

Fix this by checking s->req->prod->conn->addr.from.ss_family instead.
Also fix a minor doc issue about set-tos in http-response.

12 years agoBUG/MEDIUM: prevent gcc from moving empty keywords lists into BSS
Willy Tarreau [Fri, 21 Jun 2013 21:16:39 +0000 (23:16 +0200)] 
BUG/MEDIUM: prevent gcc from moving empty keywords lists into BSS

Benoit Dolez reported a failure to start haproxy 1.5-dev19. The
process would immediately report an internal error with missing
fetches from some crap instead of ACL names.

The cause is that some versions of gcc seem to trim static structs
containing a variable array when moving them to BSS, and only keep
the fixed size, which is just a list head for all ACL and sample
fetch keywords. This was confirmed at least with gcc 3.4.6. And we
can't move these structs to const because they contain a list element
which is needed to link all of them together during the parsing.

The bug indeed appeared with 1.5-dev19 because it's the first one
to have some empty ACL keyword lists.

One solution is to impose -fno-zero-initialized-in-bss to everyone
but this is not really nice. Another solution consists in ensuring
the struct is never empty so that it does not move there. The easy
solution consists in having a non-null list head since it's not yet
initialized.

A new "ILH" list head type was thus created for this purpose : create
an Initialized List Head so that gcc cannot move the struct to BSS.
This fixes the issue for this version of gcc and does not create any
burden for the declarations.

12 years agoMEDIUM: session: disable lingering on the server when the client aborts
Willy Tarreau [Fri, 21 Jun 2013 06:20:19 +0000 (08:20 +0200)] 
MEDIUM: session: disable lingering on the server when the client aborts

When abortonclose is used and an error is detected on the client side,
better force an RST to the server. That way we propagate to the server
the same vision we got from the client, and we ensure that we won't keep
TIME_WAITs.

12 years agoCLEANUP: session: remove event_accept() which was not used anymore
Godbach [Thu, 20 Jun 2013 05:28:38 +0000 (13:28 +0800)] 
CLEANUP: session: remove event_accept() which was not used anymore

Remove event_accept() in include/proto/proto_http.h and use correct function
name in other two files instead of event_accept().

Signed-off-by: Godbach <nylzhaowei@gmail.com>