]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
10 years agoMINOR: sample: add "json" converter
Thierry FOURNIER [Tue, 12 Aug 2014 08:20:47 +0000 (10:20 +0200)] 
MINOR: sample: add "json" converter

This converter escapes string to use it as json/ascii escaped string.
It can read UTF-8 with differents behavior on errors and encode it in
json/ascii.

json([<input-code>])
  Escapes the input string and produces an ASCII ouput string ready to use as a
  JSON string. The converter tries to decode the input string according to the
  <input-code> parameter. It can be "ascii", "utf8", "utf8s", "utf8"" or
  "utf8ps". The "ascii" decoder never fails. The "utf8" decoder detects 3 types
  of errors:
   - bad UTF-8 sequence (lone continuation byte, bad number of continuation
     bytes, ...)
   - invalid range (the decoded value is within a UTF-8 prohibited range),
   - code overlong (the value is encoded with more bytes than necessary).

  The UTF-8 JSON encoding can produce a "too long value" error when the UTF-8
  character is greater than 0xffff because the JSON string escape specification
  only authorizes 4 hex digits for the value encoding. The UTF-8 decoder exists
  in 4 variants designated by a combination of two suffix letters : "p" for
  "permissive" and "s" for "silently ignore". The behaviors of the decoders
  are :
   - "ascii"  : never fails ;
   - "utf8"   : fails on any detected errors ;
   - "utf8s"  : never fails, but removes characters corresponding to errors ;
   - "utf8p"  : accepts and fixes the overlong errors, but fails on any other
                error ;
   - "utf8ps" : never fails, accepts and fixes the overlong errors, but removes
                characters corresponding to the other errors.

  This converter is particularly useful for building properly escaped JSON for
  logging to servers which consume JSON-formated traffic logs.

  Example:
     capture request header user-agent len 150
     capture request header Host len 15
     log-format {"ip":"%[src]","user-agent":"%[capture.req.hdr(1),json]"}

  Input request from client 127.0.0.1:
     GET / HTTP/1.0
     User-Agent: Very "Ugly" UA 1/2

  Output log:
     {"ip":"127.0.0.1","user-agent":"Very \"Ugly\" UA 1\/2"}

10 years agoBUG/MEDIUM: tcp: fix outgoing polling based on proxy protocol
Willy Tarreau [Fri, 24 Oct 2014 10:02:24 +0000 (12:02 +0200)] 
BUG/MEDIUM: tcp: fix outgoing polling based on proxy protocol

During a tcp connection setup in tcp_connect_server(), we check if
there are pending data to start polling for writes immediately. We
also use the same test to know if we can disable the quick ack and
merge the first data packet with the connection's ACK. This last
case is also valid for the proxy protocol.

The problem lies in the way it's done, as the "data" variable is
improperly completed with the presence of the proxy protocol, resulting
in the connection being polled for data writes if the proxy protocol is
enabled. It's not a big issue per se, except that the proxy protocol
uses the fact that we're polling for data to know if it can use MSG_MORE.

This causes no problem on HTTP/HTTPS, but with banner protocols, it
introduces a 200ms delay if the server waits for the PROXY header.

This has been caused by the connection management changes introduced in
1.5-dev12, specifically commit a1a7474 ("MEDIUM: proxy-proto: don't use
buffer flags in conn_si_send_proxy()"), so this fix must be backported
to 1.5.

10 years agoBUG/MINOR: log: fix request flags when keep-alive is enabled
Cyril Bonté [Wed, 22 Oct 2014 20:30:13 +0000 (22:30 +0200)] 
BUG/MINOR: log: fix request flags when keep-alive is enabled

Colin Ingarfield reported some unexplainable flags in the logs.
For example, a "LR" termination state was set on a request which was forwarded
to a server, where "LR" means that the request should have been handled
internally by haproxy.

This case happens when at least client side keep-alive is enabled. Next
requests in the connection will inherit the flags from the previous request.

2 fields are impacted : "termination_state" and "Tt" in the timing events,
where a "+" can be added, when a previous request was redispatched.

This is not critical for the service itself but can confuse troubleshooting.

The fix must be backported to 1.5 and 1.4.

10 years agoBUG/MAJOR: cli: explicitly call cli_release_handler() upon error
Willy Tarreau [Wed, 22 Oct 2014 17:06:31 +0000 (19:06 +0200)] 
BUG/MAJOR: cli: explicitly call cli_release_handler() upon error

Dmitry Sivachenko reported an embarrassing problem where haproxy
would sometimes segfault upon reload. After careful analysis and
code inspection, what happens is related to the "show sess" command
on the CLI, and it is not limited to reload operations only.

When a "show sess" is running, once the output buffer is full, the
stats applet grabs a reference to the session being dumped in order
for the current pointer to be able to advance by itself should this
session disappear while the buffer is full. The applet also uses a
release handler that is called when the applet terminates to release
such references.

The problem is that upon error, the command line parser sets the
applet state to STAT_CLI_O_END indicating it wants to terminate the
processing. Unfortunately, the release handler which is called later
to clean everything up relies on the applet's state to know what
operations were in progress, and as such it does not release the
reference. A later "show sess" or the completion of the task being
watched lead to a LIST_DEL() on the task's list which point to a
location that does not match the applet's reference list anymore
and the process dies.

One solution to this would be to add a flag to the current applet's
state mentionning it must leave, without affecting the state indicating
the current operation. It's a bit invasive but could be the long term
solution. The short term solution simply consists in calling the
release handler just before changing the state to STAT_CLI_O_END.
That way everything that must be released is released in time.

Note that the probability to encounter this issue is very low.
It requires a lot of "show sess" or "show sess all" calls, and
that one of them dies before being completed. That can happen
if "show sess" is run in scripts which truncate the output (eg:
"echo show sess|socat|head"). This could be the worst case as it
almost ensures that haproxy fills a buffer, grabs a reference and
detects the error on the socket.

There's no config-based workaround to this issue, except refraining
from issuing "show sess" on large connection counts or "show sess all".
If that's not possible to block everyone, restricting permissions on
the stats socket ensures only authorized tools can connect.

This fix must be backported to 1.5 and to 1.4 (with some changes in
1.4 since the release function does not exist so the LIST_DEL sequence
must be open-coded).

Special thanks to Dmitry for the fairly complete report.

10 years agoBUG/MEDIUM: http: don't dump debug headers on MSG_ERROR
Willy Tarreau [Tue, 21 Oct 2014 17:36:09 +0000 (19:36 +0200)] 
BUG/MEDIUM: http: don't dump debug headers on MSG_ERROR

When the HTTP parser is in state HTTP_MSG_ERROR, we don't know if it was
already initialized or not. If the error happens before HTTP_MSG_RQBEFORE,
random offsets might be present and we don't want to display such random
strings in debug mode.

While it's theorically possible to randomly crash the process when running
in debug mode here, this bug was not tagged MAJOR because it would not
make sense to run in debug mode in production.

This fix must be backported to 1.5 and 1.4.

10 years agoMINOR: ssl: use SSL_get_ciphers() instead of directly accessing the cipher list.
Remi Gacogne [Fri, 10 Oct 2014 15:04:26 +0000 (17:04 +0200)] 
MINOR: ssl: use SSL_get_ciphers() instead of directly accessing the cipher list.

10 years agoBUG/MEDIUM: backend: fix URI hash when a query string is present
Willy Tarreau [Fri, 17 Oct 2014 10:11:50 +0000 (12:11 +0200)] 
BUG/MEDIUM: backend: fix URI hash when a query string is present

Commit 98634f0 ("MEDIUM: backend: Enhance hash-type directive with an
algorithm options") cleaned up the hashing code by using a centralized
function. A bug appeared in get_server_uh() which is the URI hashing
function. Prior to the patch, the function would stop hashing on the
question mark, or on the trailing slash of a maximum directory count.
Consecutive to the patch, this last character is included into the
hash computation. This means that :

    GET /0
    GET /0?

Are not hashed similarly. The following configuration reproduces it :

    mode http
    balance uri
    server s1 0.0.0.0:1234 redir /s1
    server s2 0.0.0.0:1234 redir /s2

Many thanks to Vedran Furac for reporting this issue. The fix must
be backported to 1.5.

10 years agoBUG/MINOR: config: do not accept more track-sc than configured
Willy Tarreau [Fri, 17 Oct 2014 09:53:05 +0000 (11:53 +0200)] 
BUG/MINOR: config: do not accept more track-sc than configured

MAX_SESS_STKCTR allows one to define the number of stick counters that can
be used in parallel in track-sc* rules. The naming of this macro creates
some confusion because the value there is sometimes used as a max instead
of a count, and the config parser accepts values from 0 to MAX_SESS_STKCTR
and the processing ignores anything tracked on the last one. This means
that by default, track-sc3 is allowed and ignored.

This fix must be backported to 1.5 where the problem there only affects
TCP rules.

10 years agoMINOR: systemd: Check configuration before start
Kristoffer Grönlund [Thu, 9 Oct 2014 14:51:29 +0000 (16:51 +0200)] 
MINOR: systemd: Check configuration before start

Adds a configuration check before starting the haproxy service.

10 years agoBUG/MEDIUM: config: avoid skipping disabled proxies
Willy Tarreau [Fri, 10 Oct 2014 12:54:25 +0000 (14:54 +0200)] 
BUG/MEDIUM: config: avoid skipping disabled proxies

Paul Taylor and Bryan Talbot found that after commit 419ead8 ("MEDIUM:
config: compute the exact bind-process before listener's maxaccept"),
a backend marked "disabled" would cause the next backend to be skipped
and if it was the last one it would cause a segfault.

The reason is that the commit above changed the "while" loop for a "for"
loop but a "continue" statement still incrementing the current proxy was
left in the code for disabled proxies, causing the next one to be skipped
as well and the last one to try to dereference NULL when seeking ->next.

The quick workaround consists in not disabling backends, or adding an
empty dummy one after a disabled section.

This fix must be backported to 1.5.

10 years agoBUG/MEDIUM: systemd: set KillMode to 'mixed'
Apollon Oikonomopoulos [Wed, 8 Oct 2014 12:14:41 +0000 (15:14 +0300)] 
BUG/MEDIUM: systemd: set KillMode to 'mixed'

By default systemd will send SIGTERM to all processes in the service's
control group. In our case, this includes the wrapper, the master
process and all worker processes.

Since commit c54bdd2a the wrapper actually catches SIGTERM and survives
to see the master process getting killed by systemd and regard this as
an error, placing the unit in a failed state during "systemctl stop".

Since the wrapper now handles SIGTERM by itself, we switch the kill mode
to 'mixed', which means that systemd will deliver the initial SIGTERM to
the wrapper only, and if the actual haproxy processes don't exit after a
given amount of time (default: 90s), a SIGKILL is sent to all remaining
processes in the control group. See systemd.kill(5) for more
information.

This should also be backported to 1.5.

10 years agoDOC: indicate that weight zero is reported as DRAIN
Willy Tarreau [Tue, 7 Oct 2014 13:27:33 +0000 (15:27 +0200)] 
DOC: indicate that weight zero is reported as DRAIN

It's not the same state but reported as such.

10 years agoDOC: Address issue where documentation is excluded due to a gitignore rule.
Andrew Latham [Tue, 7 Oct 2014 12:45:54 +0000 (07:45 -0500)] 
DOC: Address issue where documentation is excluded due to a gitignore rule.

10 years agoBUG/MINOR: config: don't propagate process binding for dynamic use_backend
Cyril Bonté [Thu, 2 Oct 2014 17:56:25 +0000 (19:56 +0200)] 
BUG/MINOR: config: don't propagate process binding for dynamic use_backend

A segfault was reported with the introduction of the propagate_processes()
function. It was caused when a use_backend rule was declared with a dynamic
name, using a log-format string. The backend is not resolved during the
configuration, which lead to the segfault.

The patch prevents the process binding propagation for such dynamic rules, it
should also be backported to 1.5.

10 years agoBUG/MINOR: tcp-check: report the correct failed step in the status
Willy Tarreau [Thu, 2 Oct 2014 12:51:02 +0000 (14:51 +0200)] 
BUG/MINOR: tcp-check: report the correct failed step in the status

The step number was reported by checking only last_started_step, which
was not set in case of error during the initial connection phase, and
caused "step 1" to be returned with an invalid check type (typically
SEND). So now we first verify that a test was started before returning
this.

In addition to this, the indication of the test type was taken from
current_step instead of last_started_step, so the error description
was matching the next action instead of the one reported in the step
ID. Thus we could get the confusing "step 1 (send)" report below :

      tcp-check connect
      tcp-check send foo

In order to ease debugging, when the port number is known for a connect,
it is indicated in the error report.

Note that this only affects asynchronous error messages, synchronous ones
are correct.

This fix must be backported to 1.5.

10 years agoBUG/MEDIUM: check: rule-less tcp-check must detect connect failures
Willy Tarreau [Thu, 2 Oct 2014 12:30:14 +0000 (14:30 +0200)] 
BUG/MEDIUM: check: rule-less tcp-check must detect connect failures

When "option tcp-check" is specified without any tcp-check rules, the
documentation says that it's the same as the default check method. But
the code path is a bit different, and we used to consider that since
the end of rules was reached, the check is always successful regardless
of the connection status.

This patch reorganizes the error detection, and considers the special
case where there's no tcp-check rule as a real L4 check. It also avoids
dereferencing the rule list head as a rule by itself.

While fixing this bug, another one related to the output messages'
accuracy was noticed, it will be fixed in a separate commit and is
much less important.

This bug is also present in 1.5, so this fix must be backported.

10 years agoBUG/MINOR: config: don't propagate process binding on fatal errors.
Willy Tarreau [Wed, 1 Oct 2014 18:50:17 +0000 (20:50 +0200)] 
BUG/MINOR: config: don't propagate process binding on fatal errors.

propagate_processes() must not be called with unresolved proxies, but
nothing prevents it from being called in check_config_validity(). The
resulting effect is that an unresolved proxy can cause a recursion
loop if called in such a situation, ending with a segfault after the
fatal error report. There's no side effect beyond this.

This patch refrains from calling the function when any error was met.

This bug also affects 1.5, it should be backported.

10 years agoBUG/MEDIUM: http: adjust close mode when switching to backend
Willy Tarreau [Tue, 30 Sep 2014 16:44:22 +0000 (18:44 +0200)] 
BUG/MEDIUM: http: adjust close mode when switching to backend

Commit 179085c ("MEDIUM: http: move Connection header processing earlier")
introduced a regression : the backend's HTTP mode is not considered anymore
when setting the session's HTTP mode, because wait_for_request() is only
called once, when the frontend receives the request (or when the frontend
is in TCP mode, when the backend receives the request).

The net effect is that in some situations when the frontend and the backend
do not work in the same mode (eg: keep-alive vs close), the backend's mode
is ignored.

This patch moves all that processing to a dedicated function, which is
called from the original place, as well as from session_set_backend()
when switching from an HTTP frontend to an HTTP backend in different
modes.

This fix must be backported to 1.5.

10 years agoBUG/MEDIUM: remove debugging code from systemd-wrapper
Willy Tarreau [Wed, 24 Sep 2014 10:59:25 +0000 (12:59 +0200)] 
BUG/MEDIUM: remove debugging code from systemd-wrapper

Kristoffer Grönlund reported that after my recent update to the
systemd-wrapper, I accidentely left the debugging code which
consists in disabling the fork :-(

The fix needs to be backported to 1.5 as well since I pushed it
there as well.

10 years agoMEDIUM: systemd-wrapper: support multiple executable versions and names
Willy Tarreau [Fri, 19 Sep 2014 13:42:30 +0000 (15:42 +0200)] 
MEDIUM: systemd-wrapper: support multiple executable versions and names

Having to use a hard-coded "haproxy" executable name next to the systemd
wrapper is not always convenient, as it's sometimes desirable to run with
multiple versions in parallel.

Thus this patch performs a minor change to the wrapper : if the name ends
with "-systemd-wrapper", then it trims that part off and what remains
becomes the target haproxy executable. That makes it easy to have for
example :

     haproxy-1.5.4-systemd-wrapper      haproxy-1.5.4
     haproxy-1.5.3-systemd-wrapper      haproxy-1.5.3

and so on, in a same directory.

This patch also fixes a rare bug caused by readlink() not adding the
trailing zero and leaving possible existing contents, including possibly
a randomly placed "/" which would make it unable to locate the correct
binary. This case is not totally unlikely as I got a \177 a few times
at the end of the executable names, so I could have got a '/' as well.

Back-porting to 1.5 is desirable.

10 years agoMINOR: config: detect the case where a tcp-request content rule has no inspect-delay
Willy Tarreau [Tue, 16 Sep 2014 14:21:19 +0000 (16:21 +0200)] 
MINOR: config: detect the case where a tcp-request content rule has no inspect-delay

If a frontend has any tcp-request content rule relying on request contents
without any inspect delay, we now emit a warning as this will randomly match.

This can be backported to 1.5 as it reduces the support effort.

10 years agoDOC: indicate in the doc that track-sc* can wait if data are missing
Willy Tarreau [Tue, 16 Sep 2014 13:48:15 +0000 (15:48 +0200)] 
DOC: indicate in the doc that track-sc* can wait if data are missing

Since commit 1b71eb5 ("BUG/MEDIUM: counters: fix track-sc* to wait on
unstable contents"), we don't need the "if HTTP" anymore. But the doc
was not updated to reflect this.

Since this change was backported to 1.5, this doc update should be
backported as well.

10 years agoMEDIUM: config: report it when tcp-request rules are misplaced
Willy Tarreau [Tue, 16 Sep 2014 13:39:51 +0000 (15:39 +0200)] 
MEDIUM: config: report it when tcp-request rules are misplaced

A config where a tcp-request rule appears after an http-request rule
might seem valid but it is not. So let's report a warning about this
since this case is hard to detect by the naked eye.

10 years agoMEDIUM: config: only warn if stats are attached to multi-process bind directives
Willy Tarreau [Tue, 16 Sep 2014 13:11:04 +0000 (15:11 +0200)] 
MEDIUM: config: only warn if stats are attached to multi-process bind directives

Some users want to have a stats frontend with one line per process, but while
100% valid and safe, the config parser emits a warning. Relax this check to
ensure that the warning is only emitted if at least one of the listeners is
bound to multiple processes, or if the directive is placed in a backend called
from multiple processes (since in this case we don't know if it's safe).

10 years agoMEDIUM: config: compute the exact bind-process before listener's maxaccept
Willy Tarreau [Tue, 16 Sep 2014 11:41:21 +0000 (13:41 +0200)] 
MEDIUM: config: compute the exact bind-process before listener's maxaccept

This is a continuation of previous patch, the listener's maxaccept is divided
by the number of processes, so it's best if we can swap the two blocks so that
the number of processes is already known when computing the maxaccept value.

10 years agoMEDIUM: config: make the frontends automatically bind to the listeners' processes
Willy Tarreau [Tue, 16 Sep 2014 11:21:03 +0000 (13:21 +0200)] 
MEDIUM: config: make the frontends automatically bind to the listeners' processes

When a frontend does not have any bind-process directive, make it
automatically bind to the union of all of its listeners' processes
instead of binding to all processes. That will make it possible to
have the expected behaviour without having to explicitly specify a
bind-process directive.

Note that if the listeners are not bound to a specific process, the
default is still to bind to all processes.

This change could be backported to 1.5 as it simplifies process
management, and was planned to be done during the 1.5 development phase.

10 years agoMEDIUM: config: properly propagate process binding between proxies
Willy Tarreau [Tue, 16 Sep 2014 10:17:36 +0000 (12:17 +0200)] 
MEDIUM: config: properly propagate process binding between proxies

We now recursively propagate the bind-process values between frontends
and backends instead of doing it during name resolving. This ensures
that we're able to properly propagate all the bind-process directives
even across "listen" instances, which are not perfectly covered at the
moment, depending on the declaration order.

10 years agoBUG/MEDIUM: config: propagate frontend to backend process binding again.
Willy Tarreau [Tue, 16 Sep 2014 09:31:31 +0000 (11:31 +0200)] 
BUG/MEDIUM: config: propagate frontend to backend process binding again.

This basically reverts 3507d5d ("MEDIUM: proxy: only adjust the backend's
bind-process when already set"). It was needed during the transition to
the new process binding method but is causing trouble now because frontend
to backend binding is not properly propagated.

This fix should be backported to 1.5.

10 years agoMEDIUM: http: enable header manipulation for 101 responses
Willy Tarreau [Tue, 16 Sep 2014 08:40:38 +0000 (10:40 +0200)] 
MEDIUM: http: enable header manipulation for 101 responses

Ryan Brock reported that server stickiness did not work for WebSocket
because the cookies and headers are not modified on 1xx responses. He
found that his browser correctly presents the cookies learned on 101
responses, which was not specifically defined in the WebSocket spec,
nor in the cookie spec. 101 is a very special case. Being part of 1xx,
it's an interim response. But within 1xx, it's special because it's
the last HTTP/1 response that transits on the wire, which is different
from 100 or 102 which may appear multiple times. So in that sense, we
can consider it as a final response regarding HTTP/1, and it makes
sense to allow header processing there. Note that we still ensure not
to mangle the Connection header, which is critical for HTTP upgrade to
continue to work smoothly with agents that are a bit picky about what
tokens are found there.

The rspadd rules are now processed for 101 responses as well, but the
cache-control checks are not performed (since no body is delivered).

Ryan confirmed that this patch works for him.

It would make sense to backport it to 1.5 given that it improves end
user experience on WebSocket servers.

10 years agoMINOR: Also accept SIGHUP/SIGTERM in systemd-wrapper
Matt Robenolt [Thu, 11 Sep 2014 05:19:30 +0000 (05:19 +0000)] 
MINOR: Also accept SIGHUP/SIGTERM in systemd-wrapper

My proposal is to let haproxy-systemd-wrapper also accept normal
SIGHUP/SIGTERM signals to play nicely with other process managers
besides just systemd. In my use case, this will be for using with
runit which has to ability to change the signal used for a
"reload" or "stop" command. It also might be worth renaming this
bin to just haproxy-wrapper or something of that sort to separate
itself away from systemd. But that's a different discussion. :)

10 years agoMINOR: stats: fix minor typo fix in stats_dump_errors_to_buffer()
Olivier Doucet [Mon, 8 Sep 2014 09:23:00 +0000 (11:23 +0200)] 
MINOR: stats: fix minor typo fix in stats_dump_errors_to_buffer()

Remove the space before the colon to match the format used in the frontend.

10 years agoDOC: missing track-sc* in http-request rules
Baptiste Assmann [Wed, 3 Sep 2014 16:29:47 +0000 (18:29 +0200)] 
DOC: missing track-sc* in http-request rules

track-sc is well defined in http-request rules, but not listed in
option list.
This patch fix this miss.

10 years agoDOC: clearly state that the "show sess" output format is not fixed
Olivier [Fri, 5 Sep 2014 16:49:10 +0000 (18:49 +0200)] 
DOC: clearly state that the "show sess" output format is not fixed

It requires to look at the code (src/dumpstats.c) since the format may
change at any moment.

10 years agoMINOR: deinit: fix memory leak
Sárközi, László [Fri, 5 Sep 2014 08:08:23 +0000 (10:08 +0200)] 
MINOR: deinit: fix memory leak

deinit() did not free the conf.file member of server objects.

10 years agoBUG/CRITICAL: http: don't update msg->sov once data start to leave the buffer
Willy Tarreau [Mon, 1 Sep 2014 18:35:55 +0000 (20:35 +0200)] 
BUG/CRITICAL: http: don't update msg->sov once data start to leave the buffer

Commit bb2e669 ("BUG/MAJOR: http: correctly rewind the request body
after start of forwarding") was incorrect/incomplete. It used to rely on
CF_READ_ATTACHED to stop updating msg->sov once data start to leave the
buffer, but this is unreliable because since commit a6eebb3 ("[BUG]
session: clear BF_READ_ATTACHED before next I/O") merged in 1.5-dev1,
this flag is only ephemeral and is cleared once all analysers have
seen it. So we can start updating msg->sov again each time we pass
through this place with new data. With a sufficiently large amount of
data, it is possible to make msg->sov wrap and validate the if()
condition at the top, causing the buffer to advance by about 2GB and
crash the process.

Note that the offset cannot be controlled by the attacker because it is
a sum of millions of small random sizes depending on how many bytes were
read by the server and how many were left in the buffer, only because
of the speed difference between reading and writing. Also, nothing is
written, the invalid pointer resulting from this operation is only read.

Many thanks to James Dempsey for reporting this bug and to Chris Forbes for
narrowing down the faulty area enough to make its root cause analysable.

This fix must be backported to haproxy 1.5.

10 years agoBUG/MEDIUM: config: userlists should ensure that encrypted passwords are supported
Cyril Bonté [Fri, 29 Aug 2014 18:20:02 +0000 (20:20 +0200)] 
BUG/MEDIUM: config: userlists should ensure that encrypted passwords are supported

When an unknown encryption algorithm is used in userlists or the password is
not pasted correctly in the configuration, http authentication silently fails.

An initial check is now performed during the configuration parsing, in order to
verify that the encrypted password is supported. An unsupported password will
fail with a fatal error.

This patch should be backported to 1.4 and 1.5.

10 years agoBUG/MEDIUM: auth: fix segfault with http-auth and a configuration with an unknown...
Cyril Bonté [Fri, 29 Aug 2014 18:20:01 +0000 (20:20 +0200)] 
BUG/MEDIUM: auth: fix segfault with http-auth and a configuration with an unknown encryption algorithm

Grégoire Morpain reported a segfault when a secured password is used for http
authentication. It was caused by the use of an unsupported encryption algorithm
with libcrypto. In this case, crypt() returns a NULL pointer.

The fix should be backported to 1.4 and 1.5.

10 years agoCLEANUP: acl: cleanup some of the redundancy and spaghetti after last fix
Willy Tarreau [Fri, 29 Aug 2014 17:09:48 +0000 (19:09 +0200)] 
CLEANUP: acl: cleanup some of the redundancy and spaghetti after last fix

This code aims at clearing up the ACL parsing code a bit to make it
more obvious what happens in the case of an ACL keyword and what happens
in the case of a sample expression. Variables prev_type and cur_type were
merged, and ACL keyword processing functions are checked only once.

This patch could be backported into 1.5 after the previous patch, in order
to keep the code more maintainable.

10 years agoBUG/MEDIUM: acl: correctly compute the output type when a converter is used
Willy Tarreau [Fri, 29 Aug 2014 15:36:40 +0000 (17:36 +0200)] 
BUG/MEDIUM: acl: correctly compute the output type when a converter is used

Sample expressions involving converters in expression simply do not work
if the converter changes the sample type from the original keyword. Either
the keyword is a sample fetch keyword and its own type is used, or it's an
ACL keyword, and the keyword's parse/index/match functions are used despite
the converters. Thus it causes such a stupid error :

     redirect location / if { date,ltime(%a) -i Fri }

[ALERT] 240/171746 (29127) : parsing [bug-conv.cfg:35] : error detected in proxy 'svc' while parsing redirect rule : error in condition: 'Fri' is not a number.

In fact now in ACLs, the case where the ACL keyword is alone is an exception
(eventhough the most common one). It's an exception to the sample expression
parsing rules since ACLs allow to redefine alternate parsing functions.

This fix does two things :
  - it voids any references to the ACL keyword when a converter is involved
    since we certainly not want to enforce a parser for a wrong data type ;
  - it ensures that for all other cases (sample expressions), the type of
    the expression is used instead of the type of the fetch keyword.

A significant cleanup of the code should be done, but this patch only aims
fixing the bug.

The fix should be backported into 1.5 since this appeared along the redesign
of the acl/pattern processing.

10 years agoBUG/MINOR: pattern: remove useless allocation of unused trash in pat_parse_reg()
Willy Tarreau [Fri, 29 Aug 2014 13:19:33 +0000 (15:19 +0200)] 
BUG/MINOR: pattern: remove useless allocation of unused trash in pat_parse_reg()

Just like previous patch, this is a remains of an early implementation. Also
fix the outdated comments above. The fix may be backported to 1.5 though the
bug cannot be triggerred, thus it's just a matter of keeping the code clean.

10 years agoBUG/MEDIUM: http: fix improper parsing of HTTP methods for use with ACLs
Willy Tarreau [Fri, 29 Aug 2014 13:15:50 +0000 (15:15 +0200)] 
BUG/MEDIUM: http: fix improper parsing of HTTP methods for use with ACLs

pat_parse_meth() had some remains of an early implementation attempt for
the patterns, it initialises a trash and never sets the pattern value there.
The result is that a non-standard method cannot be matched anymore. The bug
appeared during the pattern rework in 1.5, so this fix must be backported
there. Thanks to Joe Williams of GitHub for reporting the bug.

10 years agoBUG/MEDIUM: http: fix inverted condition in pat_match_meth()
Willy Tarreau [Thu, 28 Aug 2014 18:42:57 +0000 (20:42 +0200)] 
BUG/MEDIUM: http: fix inverted condition in pat_match_meth()

This results in a string-based HTTP method match returning true when
it doesn't match and conversely. This bug was reported by Joe Williams.

The fix must be backported to 1.5, though it still doesn't work because
of at least 3-4 other bugs in the long path which leads to building this
pattern list.

10 years agoMINOR: log: add a new field "%lc" to implement a per-frontend log counter
Willy Tarreau [Thu, 28 Aug 2014 13:03:15 +0000 (15:03 +0200)] 
MINOR: log: add a new field "%lc" to implement a per-frontend log counter

Sometimes it would be convenient to have a log counter so that from a log
server we know whether some logs were lost or not. The frontend's log counter
serves exactly this purpose. It's incremented each time a traffic log is
produced. If a log is disabled using "http-request set-log-level silent",
the counter will not be incremented. However, admin logs are not accounted
for. Also, if logs are filtered out before being sent to the server because
of a minimum level set on the log line, the counter will be increased anyway.

The counter is 32-bit, so it will wrap, but that's not an issue considering
that 4 billion logs are rarely in the same file, let alone close to each
other.

10 years agoOPTIM/MINOR: proxy: reduce struct proxy by 48 bytes on 64-bit archs
Willy Tarreau [Thu, 28 Aug 2014 12:36:36 +0000 (14:36 +0200)] 
OPTIM/MINOR: proxy: reduce struct proxy by 48 bytes on 64-bit archs

Just by moving a few struct members around, we can avoid 32-bit holes
between 64-bit pointers and shrink the struct size by 48 bytes. That's
not huge but that's for free, so let's do it.

10 years agoMEDIUM: connection: add new bit in Proxy Protocol V2
Dave McCowan [Wed, 30 Jul 2014 14:39:13 +0000 (10:39 -0400)] 
MEDIUM: connection: add new bit in Proxy Protocol V2

There are two sample commands to get information about the presence of a
client certificate.
ssl_fc_has_crt is true if there is a certificate present in the current
connection
ssl_c_used is true if there is a certificate present in the session.
If a session has stopped and resumed, then ssl_c_used could be true, while
ssl_fc_has_crt is false.

In the client byte of the TLS TLV of Proxy Protocol V2, there is only one
bit to indicate whether a certificate is present on the connection.  The
attached patch adds a second bit to indicate the presence for the session.

This maintains backward compatibility.

[wt: this should be backported to 1.5 to help maintain compatibility
 between versions]

10 years agoBUG/MEDIUM: http: tarpit timeout is reset
Thierry FOURNIER [Fri, 22 Aug 2014 04:55:26 +0000 (06:55 +0200)] 
BUG/MEDIUM: http: tarpit timeout is reset

Before the commit bbba2a8ecc35daf99317aaff7015c1931779c33b
(1.5-dev24-8), the tarpit section set timeout and return, after this
commit, the tarpit section set the timeout, and go to the "done" label
which reset the timeout.

Thanks Bryan Talbot for the bug report and analysis.

This should be backported in 1.5.

10 years agoMINOR: ssl: don't use boringssl's cipher_list
Lukas Tribus [Sun, 17 Aug 2014 22:56:33 +0000 (00:56 +0200)] 
MINOR: ssl: don't use boringssl's cipher_list

Google's boringssl has a different cipher_list, we cannot use it as
in OpenSSL. This is due to the "Equal preference cipher groups" feature:

https://boringssl.googlesource.com/boringssl/+/858a88daf27975f67d9f63e18f95645be2886bfb^!/

also see:
https://www.imperialviolet.org/2014/02/27/tlssymmetriccrypto.html

cipher_list is used in haproxy since commit f46cd6e4ec3a ("MEDIUM: ssl:
Add the option to use standardized DH parameters >= 1024 bits") to
check if DHE ciphers are used.

So, if boringssl is used, the patch just assumes that there is some
DHE cipher enabled. This will lead to false positives, but thats better
than compiler warnings and crashes.

This may be replaced one day by properly implementing the the new style
cipher_list, in the meantime this workaround allows to build and use
boringssl.

Signed-off-by: Lukas Tribus <luky-37@hotmail.com>
10 years agoBUILD: ssl: don't call get_rfc2409_prime when using boringssl
Lukas Tribus [Sun, 17 Aug 2014 22:56:32 +0000 (00:56 +0200)] 
BUILD: ssl: don't call get_rfc2409_prime when using boringssl

get_rfc2409_prime_1024() and friends are not available in Google's
boringssl, so use the fallback in that case.

Signed-off-by: Lukas Tribus <luky-37@hotmail.com>
10 years agoBUILD: ssl: disable OCSP when using boringssl
Lukas Tribus [Sun, 17 Aug 2014 22:56:31 +0000 (00:56 +0200)] 
BUILD: ssl: disable OCSP when using boringssl

Google's boringssl doesn't currently support OCSP, so
disable it if detected.

OCSP support may be reintroduced as per:
https://code.google.com/p/chromium/issues/detail?id=398677

In that case we can simply revert this commit.

Signed-off-by: Lukas Tribus <luky-37@hotmail.com>
10 years agoBUILD: ssl: handle boringssl in openssl version detection
Lukas Tribus [Sun, 17 Aug 2014 22:56:30 +0000 (00:56 +0200)] 
BUILD: ssl: handle boringssl in openssl version detection

Google's boringssl doesn't have OPENSSL_VERSION_TEXT, SSLeay_version()
or SSLEAY_VERSION, in fact, it doesn't have any real versioning, its
just git-based.

So in case we build against boringssl, we can't access those values.

Instead, we just inform the user that HAProxy was build against
boringssl.

Signed-off-by: Lukas Tribus <luky-37@hotmail.com>
10 years agoBUG: config: error in http-response replace-header number of arguments
Baptiste Assmann [Fri, 8 Aug 2014 15:29:06 +0000 (17:29 +0200)] 
BUG: config: error in http-response replace-header number of arguments

A couple of typo fixed in 'http-response replace-header':
- an error when counting the number of arguments
- a typo in the alert message

This should be backported to 1.5.

10 years agoBUG/MINOR: checks: external checks shouldn't wait for timeout to return the result
Cyril Bonté [Wed, 6 Aug 2014 23:55:39 +0000 (01:55 +0200)] 
BUG/MINOR: checks: external checks shouldn't wait for timeout to return the result

When the child process terminates, it should wake up the associated task to
process the result immediately, otherwise it will be available only when the
task expires.

This fix is specific to the 1.6 branch.

10 years agoBUG/MEDIUM: checks: segfault with external checks in a backend section
Cyril Bonté [Wed, 6 Aug 2014 23:55:38 +0000 (01:55 +0200)] 
BUG/MEDIUM: checks: segfault with external checks in a backend section

The documentation indicates that external checks can be used in a backend
section, but the code requires a listener to provide information in the script
arguments.
External checks were initialized lately, during the first check, leaving some
variables uninitialized in such a scenario, which trigger the segfault when
accessed to collect errors information.

To prevent the segfault, currently we should initialize the external checks
earlier, during the process initialiation itself and quit if the error occurs.

This fix is specific to the 1.6 branch.

10 years agoBUG/MEDIUM: checks: external checks can't change server status to UP
Cyril Bonté [Wed, 6 Aug 2014 23:55:37 +0000 (01:55 +0200)] 
BUG/MEDIUM: checks: external checks can't change server status to UP

Mark Brooks reported an issue with external healthchecks, where servers are
never marked as UP. This is due to a typo, which flags a successful check as
CHK_RES_FAILED instead of CHK_RES_PASSED.

This bug is specific to the 1.6 branch.

10 years agoBUG/MAJOR: tcp: fix a possible busy spinning loop in content track-sc*
Willy Tarreau [Wed, 30 Jul 2014 06:56:35 +0000 (08:56 +0200)] 
BUG/MAJOR: tcp: fix a possible busy spinning loop in content track-sc*

As a consequence of various recent changes on the sample conversion,
a corner case has emerged where it is possible to wait forever for a
sample in track-sc*.

The issue is caused by the fact that functions relying on sample_process()
don't all exactly work the same regarding the SMP_F_MAY_CHANGE flag and
the output result. Here it was possible to wait forever for an output
sample from stktable_fetch_key() without checking the SMP_OPT_FINAL flag.
As a result, if the client connects and closes without sending the data
and haproxy expects a sample which is capable of coming, it will ignore
this impossible case and will continue to wait.

This change adds control for SMP_OPT_FINAL before waiting for extra data.
The various relevant functions have been better documented regarding their
output values.

This fix must be backported to 1.5 since it appeared there.

10 years agoMEDIUM: Improve signal handling in systemd wrapper.
Conrad Hoffmann [Mon, 28 Jul 2014 21:52:20 +0000 (23:52 +0200)] 
MEDIUM: Improve signal handling in systemd wrapper.

Move all code out of the signal handlers, since this is potentially
dangerous. To make sure the signal handlers behave as expected, use
sigaction() instead of signal(). That also obsoletes messing with
the signal mask after restart.

Signed-off-by: Conrad Hoffmann <conrad@soundcloud.com>
10 years agoBUG/MINOR: Fix search for -p argument in systemd wrapper.
Conrad Hoffmann [Mon, 28 Jul 2014 21:22:43 +0000 (23:22 +0200)] 
BUG/MINOR: Fix search for -p argument in systemd wrapper.

Searching for the pid file in the list of arguments did not
take flags without parameters into account, like e.g. -de. Because
of this, the wrapper would use a different pid file than haproxy
if such an argument was specified before -p.

The new version can still yield a false positive for some crazy
situations, like your config file name starting with "-p", but
I think this is as good as it gets without using getopt or some
library.

Signed-off-by: Conrad Hoffmann <conrad@soundcloud.com>
10 years agoBUG/MINOR: server: move the directive #endif to the end of file
Godbach [Mon, 28 Jul 2014 09:31:57 +0000 (17:31 +0800)] 
BUG/MINOR: server: move the directive #endif to the end of file

If a source file includes proto/server.h twice or more, redefinition errors will
be triggered for such inline functions as server_throttle_rate(),
server_is_draining(), srv_adm_set_maint() and so on. Just move #endif directive
to the end of file to solve this issue.

Signed-off-by: Godbach <nylzhaowei@gmail.com>
10 years agoBUG/MEDIUM: connection: fix proxy v2 header again!
Willy Tarreau [Sat, 19 Jul 2014 04:37:33 +0000 (06:37 +0200)] 
BUG/MEDIUM: connection: fix proxy v2 header again!

Last commit 77d1f01 ("BUG/MEDIUM: connection: fix memory corruption
when building a proxy v2 header") was wrong, using &cn_trash instead
of cn_trash resulting in a warning and the client's SSL cert CN not
being stored at the proper location.

Thanks to Lukas Tribus for spotting this quickly.

This should be backported to 1.5 after the patch above is backported.

10 years agoBUG/MEDIUM: connection: fix memory corruption when building a proxy v2 header
Dave McCowan [Thu, 17 Jul 2014 18:34:01 +0000 (14:34 -0400)] 
BUG/MEDIUM: connection: fix memory corruption when building a proxy v2 header

Use temporary trash chunk, instead of global trash chunk in
make_proxy_line_v2() to avoid memory overwrite.

This fix must also be backported to 1.5.

11 years agoMEDIUM: http: add the track-sc* actions to http-request rules
Willy Tarreau [Wed, 25 Jun 2014 16:12:15 +0000 (18:12 +0200)] 
MEDIUM: http: add the track-sc* actions to http-request rules

Add support for http-request track-sc, similar to what is done in
tcp-request for backends. A new act_prm field was added to HTTP
request rules to store the track params (table, counter). Just
like for TCP rules, the table is resolved while checking for
config validity. The code was mostly copied from the TCP code
with the exception that here we also count the HTTP request count
and rate by hand. Probably that something could be factored out in
the future.

It seems like tracking flags should be improved to mark each hook
which tracks a key so that we can have some check points where to
increase counters of the past if not done yet, a bit like is done
for TRACK_BACKEND.

11 years agoCLEANUP: session: move the stick counters declarations to stick_table.h
Willy Tarreau [Wed, 25 Jun 2014 16:30:01 +0000 (18:30 +0200)] 
CLEANUP: session: move the stick counters declarations to stick_table.h

They're really not appropriate in session.h as they always require a
stick table, and I'm having a hard time finding them each time I need
to.

11 years agoBUILD: report commit ID in git versions as well
Willy Tarreau [Wed, 16 Jul 2014 09:38:52 +0000 (11:38 +0200)] 
BUILD: report commit ID in git versions as well

Currently, the commit ID appears in the sub-version in snapshots, but
when people use the git repository, we only have the commits count,
and not the last commit ID, which requires to count commits when
troubleshooting. This change ensures that unreleased versions also
report the commit ID before the commit number, such as :

      1.6-dev0-bbfd1a-50

Tagged versions will not have this, since the post-release commit count
is zero.

11 years agoMINOR: sample: allow integers to cast to binary
Willy Tarreau [Tue, 15 Jul 2014 19:19:08 +0000 (21:19 +0200)] 
MINOR: sample: allow integers to cast to binary

Doing so finally allows to apply the hex converter to integers as well.
Note that all integers are represented in 32-bit, big endian so that their
conversion remains human readable and portable. A later improvement to the
hex converter could be to make it trim leading zeroes, and/or to only report
a number of least significant bytes.

11 years agoMINOR: sample: add new converters to hash input
Willy Tarreau [Tue, 15 Jul 2014 18:15:37 +0000 (20:15 +0200)] 
MINOR: sample: add new converters to hash input

From time to time it's useful to hash input data (scramble input, or
reduce the space needed in a stick table). This patch provides 3 simple
converters allowing use of the available hash functions to hash input
data. The output is an unsigned integer which can be passed into a header,
a log or used as an index for a stick table. One nice usage is to scramble
source IP addresses before logging when there are requirements to hide them.

11 years agoMINOR: sample: allow IP address to cast to binary
Willy Tarreau [Tue, 15 Jul 2014 19:03:26 +0000 (21:03 +0200)] 
MINOR: sample: allow IP address to cast to binary

IP addresses are a perfect example of fixed size data which we could
cast to binary, still it was not allowed by lack of cast function,
eventhough the opposite was allowed in ACLs. Make that possible both
in sample expressions and in stick tables.

11 years agoBUG/MINOR: http: base32+src should use the big endian version of base32
Willy Tarreau [Tue, 15 Jul 2014 19:34:06 +0000 (21:34 +0200)] 
BUG/MINOR: http: base32+src should use the big endian version of base32

We're using the internal memory representation of base32 here, which is
wrong since these data might be exported to headers for logs or be used
to stick to a server and replicated to other peers. Let's convert base32
to big endian (network representation) when building the binary block.

This mistake is also present in 1.5, it would be better to backport it.

11 years agoMEDIUM: stick-table: make it easier to register extra data types
Willy Tarreau [Tue, 15 Jul 2014 14:44:27 +0000 (16:44 +0200)] 
MEDIUM: stick-table: make it easier to register extra data types

Some users want to add their own data types to stick tables. We don't
want to use a linked list here for performance reasons, so we need to
continue to use an indexed array. This patch allows one to reserve a
compile-time-defined number of extra data types by setting the new
macro STKTABLE_EXTRA_DATA_TYPES to anything greater than zero, keeping
in mind that anything larger will slightly inflate the memory consumed
by stick tables (not per entry though).

Then calling stktable_register_data_store() with the new keyword will
either register a new keyword or fail if the desired entry was already
taken or the keyword already registered.

Note that this patch does not dictate how the data will be used, it only
offers the possibility to create new keywords and have an index to
reference them in the config and in the tables. The caller will not be
able to use stktable_data_cast() and will have to explicitly cast the
stable pointers to the expected types. It can be used for experimentation
as well.

11 years agoMINOR: session: export the function 'smp_fetch_sc_stkctr'
Willy Tarreau [Tue, 15 Jul 2014 17:06:18 +0000 (19:06 +0200)] 
MINOR: session: export the function 'smp_fetch_sc_stkctr'

This one is sometimes useful outside of this file.

11 years agoMINOR: http: export the function 'smp_fetch_base32'
Thierry FOURNIER [Tue, 15 Jul 2014 14:11:07 +0000 (16:11 +0200)] 
MINOR: http: export the function 'smp_fetch_base32'

It's sometimes useful outside of proto_http.c.

11 years agoBUILD: fix dependencies between config and compat.h
Willy Tarreau [Tue, 15 Jul 2014 16:05:58 +0000 (18:05 +0200)] 
BUILD: fix dependencies between config and compat.h

compat.h only depends on the system, and config needs compat, not the
opposite. global.h was fixed to explicitly include standard.h for LONGBITS.

11 years agoBUG/MEDIUM: ssl: Fix a memory leak in DHE key exchange
Remi Gacogne [Tue, 15 Jul 2014 09:36:40 +0000 (11:36 +0200)] 
BUG/MEDIUM: ssl: Fix a memory leak in DHE key exchange

OpenSSL does not free the DH * value returned by the callback specified with SSL_CTX_set_tmp_dh_callback(),
leading to a memory leak for SSL/TLS connections using Diffie Hellman Ephemeral key exchange.
This patch fixes the leak by allocating the DH * structs holding the DH parameters once, at configuration time.

Note: this fix must be backported to 1.5.

11 years agoDOC: fix typo in Unix Socket commands
Cyril Bonté [Sat, 12 Jul 2014 16:22:42 +0000 (18:22 +0200)] 
DOC: fix typo in Unix Socket commands

Konstantin Romanenko reported a typo in the HTML documentation. The typo is
already present in the raw text version : the "shutdown sessions" command
should be "shutdown sessions server".

11 years agoDOC: mention that Squid correctly responds 400 to PPv2 header
Willy Tarreau [Sat, 12 Jul 2014 15:31:07 +0000 (17:31 +0200)] 
DOC: mention that Squid correctly responds 400 to PPv2 header

Amos reported that Squid builds 3.5.0.0_20140624 and 3.5.0.0_20140630
were confirmed to respond correctly here and that any version will do
the same.

11 years agoDOC: mention that "compression offload" is ignored in defaults section
Willy Tarreau [Sat, 12 Jul 2014 14:37:02 +0000 (16:37 +0200)] 
DOC: mention that "compression offload" is ignored in defaults section

This one is not inherited from defaults into frontends nor backends
because it would create a confusion situation where it would be hard
to disable it (since both frontend and backend would enable it).

11 years agoDOC: remove references to CPU=native in the README
Willy Tarreau [Thu, 10 Jul 2014 18:24:25 +0000 (20:24 +0200)] 
DOC: remove references to CPU=native in the README

Certain compilers running in virtualized environments may produce code
that the same processor cannot execute with -march=native, either because
of hypervisor bugs reporting wrong CPU features, or because of compiler
bugs forgetting to check CPU features. So better stop recommending this
combination so that users don't get trapped anymore.

11 years agoBUG/MAJOR: http: correctly rewind the request body after start of forwarding
Willy Tarreau [Thu, 10 Jul 2014 17:06:10 +0000 (19:06 +0200)] 
BUG/MAJOR: http: correctly rewind the request body after start of forwarding

Daniel Dubovik reported an interesting bug showing that the request body
processing was still not 100% fixed. If a POST request contained short
enough data to be forwarded at once before trying to establish the
connection to the server, we had no way to correctly rewind the body.

The first visible case is that balancing on a header does not always work
on such POST requests since the header cannot be found. But there are even
nastier implications which are that http-send-name-header would apply to
the wrong location and possibly even affect part of the request's body
due to an incorrect rewinding.

There are two options to fix the problem :
  - first one is to force the HTTP_MSG_F_WAIT_CONN flag on all hash-based
    balancing algorithms and http-send-name-header, but there's always a
    risk that any new algorithm forgets to set it ;

  - the second option is to account for the amount of skipped data before
    the connection establishes so that we always know the position of the
    request's body relative to the buffer's origin.

The second option is much more reliable and fits very well in the spirit
of the past changes to fix forwarding. Indeed, at the moment we have
msg->sov which points to the start of the body before headers are forwarded
and which equals zero afterwards (so it still points to the start of the
body before forwarding data). A minor change consists in always making it
point to the start of the body even after data have been forwarded. It means
that it can get a negative value (so we need to change its type to signed)..

In order to avoid wrapping, we only do this as long as the other side of
the buffer is not connected yet.

Doing this definitely fixes the issues above for the requests. Since the
response cannot be rewound we don't need to perform any change there.

This bug was introduced/remained unfixed in 1.5-dev23 so the fix must be
backported to 1.5.

11 years agoMINOR: samples: add two converters for the date format
Willy Tarreau [Thu, 10 Jul 2014 14:37:47 +0000 (16:37 +0200)] 
MINOR: samples: add two converters for the date format

This patch adds two converters :

   ltime(<format>[,<offset>])
   utime(<format>[,<offset>])

Both use strftime() to emit the output string from an input date. ltime()
provides local time, while utime() provides the UTC time.

11 years agoMEDIUM: stick-table: add new converters to fetch table data
Willy Tarreau [Thu, 10 Jul 2014 12:03:38 +0000 (14:03 +0200)] 
MEDIUM: stick-table: add new converters to fetch table data

These new converters make it possible to look up any sample expression
in a table, and check whether an equivalent key exists or not, and if it
exists, to retrieve the associated data (eg: gpc0, request rate, etc...).

Till now it was only possible using tracking, but sometimes tracking is
not suited to only retrieving such counters, either because it's done too
early or because too many items need to be checked without necessarily
being tracked.

These converters all take a string on input, and then convert it again to
the table's type. This means that if an input sample is of type IPv4 and
the table is of type IP, it will first be converted to a string, then back
to an IP address. This is a limitation of the current design which does not
allow converters to declare that "any" type is supported on input. Since
strings are the only types which can be cast to any other one, this method
always works.

The following converters were added :

  in_table, table_bytes_in_rate, table_bytes_out_rate, table_conn_cnt,
  table_conn_cur, table_conn_rate, table_gpc0, table_gpc0_rate,
  table_http_err_cnt, table_http_err_rate, table_http_req_cnt,
  table_http_req_rate, table_kbytes_in, table_kbytes_out,
  table_server_id, table_sess_cnt, table_sess_rate, table_trackers.

11 years agoMEDIUM: stick-table: implement lookup from a sample fetch
Willy Tarreau [Thu, 3 Jul 2014 15:02:46 +0000 (17:02 +0200)] 
MEDIUM: stick-table: implement lookup from a sample fetch

Currently we have stktable_fetch_key() which fetches a sample according
to an expression and returns a stick table key, but we also need a function
which does only the second half of it from a known sample. So let's cut the
function in two and introduce smp_to_stkey() to perform this lookup. The
first function was adapted to make use of it in order to avoid code
duplication.

11 years agoDOC: fix alphabetical sort of converters
Willy Tarreau [Thu, 10 Jul 2014 14:29:08 +0000 (16:29 +0200)] 
DOC: fix alphabetical sort of converters

For an unknown reason, these ones were not sorted.

11 years agoDOC: minor fix on {sc,src}_kbytes_{in,out}
Willy Tarreau [Thu, 10 Jul 2014 13:29:24 +0000 (15:29 +0200)] 
DOC: minor fix on {sc,src}_kbytes_{in,out}

These ones report total amount of bytes, not byte rates.
This fix should be backported into 1.5 which has the same error.

11 years agoBUG/MEDIUM: backend: Update hash to use unsigned int throughout
Dan Dubovik [Tue, 8 Jul 2014 15:51:03 +0000 (08:51 -0700)] 
BUG/MEDIUM: backend: Update hash to use unsigned int throughout

When we were generating a hash, it was done using an unsigned long.  When the hash was used
to select a backend, it was sent as an unsigned int.  This made it difficult to predict which
backend would be selected.

This patch updates get_hash, and the hash methods to use an unsigned int, to remain consistent
throughout the codebase.

This fix should be backported to 1.5 and probably in part to 1.4.

11 years agoDOC: expand the docs for the provided stats.
James Westby [Tue, 8 Jul 2014 14:14:57 +0000 (10:14 -0400)] 
DOC: expand the docs for the provided stats.

Indicate for each statistic which types may have a value for
that statistic.

Explain some of the provided statistics a little more deeply.

11 years agoDOC: explicitly mention the limits of abstract namespace sockets
Willy Tarreau [Mon, 7 Jul 2014 22:37:50 +0000 (00:37 +0200)] 
DOC: explicitly mention the limits of abstract namespace sockets

Listening to an abstract namespace socket is quite convenient but
comes with some drawbacks that must be clearly understood when the
socket is being listened to by multiple processes. The trouble is
that the socket cannot be rebound if a new process attempts a soft
restart and fails, so only one of the initially bound processes
will still be bound to it, the other ones will fail to rebind. For
most situations it's not an issue but it needs to be indicated.

11 years agoBUG/MEDIUM: unix: completely unbind abstract sockets during a pause()
Willy Tarreau [Mon, 7 Jul 2014 19:07:51 +0000 (21:07 +0200)] 
BUG/MEDIUM: unix: completely unbind abstract sockets during a pause()

Abstract namespace sockets ignore the shutdown() call and do not make
it possible to temporarily stop listening. The issue it causes is that
during a soft reload, the new process cannot bind, complaining that the
address is already in use.

This change registers a new pause() function for unix sockets and
completely unbinds the abstract ones since it's possible to rebind
them later. It requires the two previous patches as well as preceeding
fixes.

This fix should be backported into 1.5 since the issue apperas there.

11 years agoMEDIUM: listener: support rebinding during resume()
Willy Tarreau [Mon, 7 Jul 2014 19:06:24 +0000 (21:06 +0200)] 
MEDIUM: listener: support rebinding during resume()

When a listener resumes operations, supporting a full rebind makes it
possible to perform a full stop as a pause(). This will be used for
pausing abstract namespace unix sockets.

11 years agoMEDIUM: listener: implement a per-protocol pause() function
Willy Tarreau [Mon, 7 Jul 2014 18:22:12 +0000 (20:22 +0200)] 
MEDIUM: listener: implement a per-protocol pause() function

In order to fix the abstact socket pause mechanism during soft restarts,
we'll need to proceed differently depending on the socket protocol. The
pause_listener() function already supports some protocol-specific handling
for the TCP case.

This commit makes this cleaner by adding a new ->pause() function to the
protocol struct, which, if defined, may be used to pause a listener of a
given protocol.

For now, only TCP has been adapted, with the specific code moved from
pause_listener() to tcp_pause_listener().

11 years agoBUG/MEDIUM: unix: failed abstract socket binding is retryable
Willy Tarreau [Mon, 7 Jul 2014 16:36:45 +0000 (18:36 +0200)] 
BUG/MEDIUM: unix: failed abstract socket binding is retryable

Jan Seda noticed that abstract sockets are incompatible with soft reload,
because the new process cannot bind and immediately fails. This patch marks
the binding as retryable and not fatal so that the new process can try to
bind again after sending a signal to the old process.

Note that this fix is not enough to completely solve the problem, but it
is necessary. This patch should be backported to 1.5.

11 years agoBUG/MINOR: listener: set the listener's fd to -1 after deletion
Willy Tarreau [Mon, 7 Jul 2014 16:24:48 +0000 (18:24 +0200)] 
BUG/MINOR: listener: set the listener's fd to -1 after deletion

This is currently harmless, but when stopping a listener, its fd is
closed but not set to -1, so it is not possible to re-open it again.
Currently this has no impact but can have after the abstract sockets
are modified to perform a complete close on soft-reload.

The fix can be backported to 1.5 and may even apply to 1.4 (protocols.c).

11 years agoBUILD: http: fix isdigit & isspace warnings on Solaris
Willy Tarreau [Mon, 7 Jul 2014 22:59:48 +0000 (00:59 +0200)] 
BUILD: http: fix isdigit & isspace warnings on Solaris

As usual, when touching any is* function, Solaris complains about the
type of the element being checked. Better backport this to 1.5 since
nobody knows what the emitted code looks like since macros are used
instead of functions.

11 years agoBUILD: checks: kill a minor warning on Solaris in external checks
Willy Tarreau [Mon, 7 Jul 2014 22:56:27 +0000 (00:56 +0200)] 
BUILD: checks: kill a minor warning on Solaris in external checks

Gcc on Solaris complains that elem->pid is pid_t and that we display
it as int. A simple cast fixes this. No backport needed, this is 1.6
only.

11 years agoBUILD: checks: external checker needs signal.h
Willy Tarreau [Mon, 7 Jul 2014 22:54:10 +0000 (00:54 +0200)] 
BUILD: checks: external checker needs signal.h

check.c doesn't build on solaris since 98637e5 ("MEDIUM: Add external check")
because sigset_t is unknown. Simply include signal.h to fix the issue.

No need to backport, this is 1.6-only.

11 years agoDOC: provide an example of how to use ssl_c_sha1
Willy Tarreau [Wed, 2 Jul 2014 17:01:22 +0000 (19:01 +0200)] 
DOC: provide an example of how to use ssl_c_sha1

As suggested by Aydan Yumerefendi, a little bit of examples never hurts.

11 years agoBUG/MEDIUM: unix: do not unlink() abstract namespace sockets upon failure.
Jan Seda [Thu, 26 Jun 2014 18:44:05 +0000 (20:44 +0200)] 
BUG/MEDIUM: unix: do not unlink() abstract namespace sockets upon failure.

When bind() fails (function uxst_bind_listener()), the fail path doesn't
consider the abstract namespace and tries to unlink paths held in
uninitiliazed memory (tempname and backname). See the strace excerpt;
the strings still hold the path from test1.

===============================================================================================
23722 bind(5, {sa_family=AF_FILE, path=@"test2"}, 110) = -1 EADDRINUSE (Address already in use)
23722 unlink("/tmp/test1.sock.23722.tmp") = -1 ENOENT (No such file or directory)
23722 close(5)                          = 0
23722 unlink("/tmp/test1.sock.23722.bak") = -1 ENOENT (No such file or directory)
===============================================================================================

This patch should be backported to 1.5.

11 years agoMINOR: stats: fix minor typo in HTML page
Marco Corte [Wed, 2 Jul 2014 15:49:34 +0000 (17:49 +0200)] 
MINOR: stats: fix minor typo in HTML page

There is a very small typo in the statistics interface: a "set" in
lowercase where allothers are uppercase "Set".

11 years agoMEDIUM: log: support a user-configurable max log line length
Willy Tarreau [Fri, 27 Jun 2014 16:10:07 +0000 (18:10 +0200)] 
MEDIUM: log: support a user-configurable max log line length

With all the goodies supported by logformat, people find that the limit
of 1024 chars for log lines is too short. Some servers do not support
larger lines and can simply drop them, so changing the default value is
not always the best choice.

This patch takes a different approach. Log line length is specified per
log server on the "log" line, with a value between 80 and 65535. That
way it's possibly to satisfy all needs, even with some fat local servers
and small remote ones.

11 years agoMINOR: log: make MAX_SYSLOG_LEN overridable at build time
Willy Tarreau [Fri, 27 Jun 2014 16:08:49 +0000 (18:08 +0200)] 
MINOR: log: make MAX_SYSLOG_LEN overridable at build time

This value was set in log.h without any #ifndef around, so when one
wanted to change it, a patch was needed. Let's move it to defaults.h
with the usual #ifndef so that it's easier to change it.

11 years agoBUILD: remove TODO from the spec file and add README
Willy Tarreau [Thu, 26 Jun 2014 06:20:38 +0000 (08:20 +0200)] 
BUILD: remove TODO from the spec file and add README

This used to cause a build failure since 1.5.0, as reported by
Timothy Shelton. The proxy protocol doc was also added.

11 years agoBUG/MEDIUM: counters: fix track-sc* to wait on unstable contents
Willy Tarreau [Wed, 25 Jun 2014 15:01:56 +0000 (17:01 +0200)] 
BUG/MEDIUM: counters: fix track-sc* to wait on unstable contents

I've been facing multiple configurations which involved track-sc* rules
in tcp-request content without the "if ..." to force it to wait for the
contents, resulting in random behaviour with contents sometimes retrieved
and sometimes not.

Reading the doc doesn't make it clear either that the tracking will be
performed only if data are already there and that waiting on an ACL is
the only way to avoid this.

Since this behaviour is not natural and we now have the ability to fix
it, this patch ensures that if input data are still moving, instead of
silently dropping them, we naturally wait for them to stabilize up to
the inspect-delay. This way it's not needed anymore to implement an
ACL-based condition to force to wait for data, eventhough the behaviour
is not changed for when an ACL is present.

The most obvious usage will be when track-sc is followed by any HTTP
sample expression, there's no need anymore for adding "if HTTP".

It's probably worth backporting this to 1.5 to avoid further configuration
issues. Note that it requires previous patch.