Commit Graph

5549 Commits

Author SHA1 Message Date
Willy Tarreau
8a32106fff BUG/MEDIUM: channel: fix miscalculation of available buffer space (2nd try)
Commit 999f643 ("BUG/MEDIUM: channel: fix miscalculation of available buffer
space.") introduced a bug which made output data to be ignored when computing
the remaining room in a buffer. The problem is that channel_may_recv()
properly considers them and may declare that the FD may be polled for read
events, but once the even strikes, channel_recv_limit() called before recv()
says the opposite. In 1.6 and later this case is automatically caught by
polling loop detection at the connection level and is harmless. But the
backport in 1.5 ends up with a busy polling loop as soon as it becomes
possible to have a buffer with this conflict. In order to reproduce it, it
is necessary to have less than [maxrewrite] bytes available in a buffer, no
forwarding enabled (end of transfer) and [buf->o >= maxrewrite - free space].

Since this heavily depends on socket buffers, it will randomly strike users.
On 1.5 with 8kB buffers it was possible to reproduce it with httpterm using
the following command line :

   $ (printf "GET /?s=675000 HTTP/1.0\r\n\r\n"; sleep 60) | \
       nc6 --rcvbuf-size 1 --send-only 127.0.0.1 8002

This bug is only medium in 1.6 and later but is major in the 1.5 backport,
so it must be backported there.

Thanks to Nenad Merdanovic and Janusz Dziemidowicz for reporting this issue
with enough elements to help understand it.
2016-04-11 17:13:35 +02:00
William Lallemand
0567fa3af5 BUG/MEDIUM: trace.c: rdtsc() is defined in two files
The rdtsc() function provided in standard.h forbid trace.c to compile
because it's already defined there.
2016-04-09 22:27:01 +02:00
Thierry Fournier
0e00dca58b DOC: http: rename the unique-id sample and add the documentation
This patch renames the ssample fetch from "uniqueid" to "unique-id".
It also adds the documentation associated with this sample fetch.
2016-04-07 19:14:58 +02:00
Frederik Deweerdt
6cd8d13c05 OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.

This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.

sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.

This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 19:12:02 +02:00
Willy Tarreau
bb137a8af7 BUG/MEDIUM: ssl: rewind the BIO when reading certificates
Emeric found that some certificate files that were valid with the old method
(the one with the explicit name involving SSL_CTX_use_PrivateKey_file()) do
not work anymore with the new one (the one trying to load multiple cert types
using PEM_read_bio_PrivateKey()). With the last one, the private key couldn't
be loaded.

The difference was related to the ordering in the PEM file was different. The
old method would always work. The new method only works if the private key is
at the top, or if it appears as an "EC" private key. The cause in fact is that
we never rewind the BIO between the various calls. So this patch moves the
loading of the private key as the first step, then it rewinds the BIO, and
then it loads the cert and the chain. With this everything works.

No backport is needed, this issue came with the recent addition of the
multi-cert support.
2016-04-06 19:02:38 +02:00
Bertrand Paquet
83a2c3d4d7 BUG/MINOR : allow to log cookie for tarpit and denied request
The following patch allow to log cookie for tarpit and denied request.
This minor bug affect at least 1.5, 1.6 and 1.7 branch.

The solution is not perfect : may be the cookie processing
(manage_client_side_cookies) can be moved into http_process_req_common.
2016-04-06 14:58:41 +02:00
Baptiste Assmann
6f79aca339 BUG/MINOR: DNS: resolution structure change
060e57301d introduced a bug, related to a
dns option structure change and an improper rebase.

Thanks Lukas Tribus for reporting it.

backport: 1.7 and above
2016-04-05 21:35:42 +02:00
David Carlier
7365f7d41b CLEANUP: proto_http: few corrections for gcc warnings.
first, we modify the signatures of http_msg_forward_body and
http_msg_forward_chunked_body as they are declared as inline
below. Secondly, just verify the returns of the chunk initialization
which holds the Authorization Method (althought it is unlikely to fail  ...).
Both from gcc warnings.
2016-04-05 18:05:24 +02:00
Baptiste Assmann
060e57301d BUG/MINOR: dns: trigger a DNS query type change on resolution timeout
After Cedric Jeanneret reported an issue with HAProxy and DNS resolution
when multiple servers are in use, I saw that the implementation of DNS
query type update on resolution timeout was not implemented, even if it
is documented.

backport: 1.6 and above
2016-04-05 05:56:11 +02:00
Baptiste Assmann
382824c475 BUG/MINOR: dns: inapropriate way out after a resolution timeout
A bug leading HAProxy to stop DNS resolution when multiple servers are
configured and one is in timeout, the request is not resent.
Current code fix this issue.

backport status: 1.6 and above
2016-04-05 05:56:11 +02:00
Conrad Hoffmann
692c9386db BUG/MINOR: dumpstats: fix write to global chunk
This just happens to work as it is the correct chunk, but should be whatever
gets passed in as argument.

Signed-off-by: Conrad Hoffmann <conrad@soundcloud.com>
2016-04-05 05:56:10 +02:00
Thiago Farina
9f72a39f68 DOC: fix "needed" typo
While at it use "You" instead of "They" as in the context
it seems to make more sense to refer to "you", as it is
you that are going to be running the command, there is no
"they".

Signed-off-by: Thiago Farina <tfarina@chromium.org>
2016-04-03 14:21:22 +02:00
Vincent Bernat
02779b6263 CLEANUP: uniformize last argument of malloc/calloc
Instead of repeating the type of the LHS argument (sizeof(struct ...))
in calls to malloc/calloc, we directly use the pointer
name (sizeof(*...)). The following Coccinelle patch was used:

@@
type T;
T *x;
@@

  x = malloc(
- sizeof(T)
+ sizeof(*x)
  )

@@
type T;
T *x;
@@

  x = calloc(1,
- sizeof(T)
+ sizeof(*x)
  )

When the LHS is not just a variable name, no change is made. Moreover,
the following patch was used to ensure that "1" is consistently used as
a first argument of calloc, not the last one:

@@
@@

  calloc(
+ 1,
  ...
- ,1
  )
2016-04-03 14:17:42 +02:00
Vincent Bernat
3c2f2f207f CLEANUP: remove unneeded casts
In C89, "void *" is automatically promoted to any pointer type. Casting
the result of malloc/calloc to the type of the LHS variable is therefore
unneeded.

Most of this patch was built using this Coccinelle patch:

@@
type T;
@@

- (T *)
  (\(lua_touserdata\|malloc\|calloc\|SSL_get_app_data\|hlua_checkudata\|lua_newuserdata\)(...))

@@
type T;
T *x;
void *data;
@@

  x =
- (T *)
  data

@@
type T;
T *x;
T *data;
@@

  x =
- (T *)
  data

Unfortunately, either Coccinelle or I is too limited to detect situation
where a complex RHS expression is of type "void *" and therefore casting
is not needed. Those cases were manually examined and corrected.
2016-04-03 14:17:42 +02:00
Willy Tarreau
f3764b7993 MEDIUM: proxy: use dynamic allocation for error dumps
There are two issues with error captures. The first one is that the
capture size is still hard-coded to BUFSIZE regardless of any possible
tune.bufsize setting and of the fact that frontends only capture request
errors and that backends only capture response errors. The second is that
captures are allocated in both directions for all proxies, which start to
count a lot in configs using thousands of proxies.

This patch changes this so that error captures are allocated only when
needed, and of the proper size. It also refrains from dumping a buffer
that was not allocated, which still allows to emit all relevant info
such as flags and HTTP states. This way it is possible to save up to
32 kB of RAM per proxy in the default configuration.
2016-03-31 13:49:23 +02:00
Thierry Fournier
40e1d51068 BUG/MEDIUM: stick-tables: some sample-fetch doesn't work in the connection state.
The sc_* sample fetch can work without the struct strm, because the
tracked counters are also stored in the session. So, this patchs
removes the check for the strm existance.

This bug is recent and was introduced in 1.7-dev2 by commit 6204cd9
("BUG/MAJOR: vars: always retrieve the stream and session from the sample")

This bugfix must be backported in 1.6.
2016-03-30 19:51:33 +02:00
Thierry Fournier
ff480424ab MINOR: lua: add class listener
This class provides the access to the listener struct, it allows
some manipulations and retrieve informations.
2016-03-30 18:43:47 +02:00
Thierry Fournier
f2fdc9dc39 MINOR: lua: add class server
This class provides the access to the server struct, it allows
some manipulations and retrieve informations.
2016-03-30 18:43:47 +02:00
Thierry Fournier
f61aa6356e MINOR: lua: add class proxy
This class provides the access to the proxy struct, it allows
some manipulations and retrieve informations.
2016-03-30 18:43:42 +02:00
Thierry Fournier
eea77c0e17 MINOR: lua: dump general info
This patch adds function able to dump general haproxy information.
2016-03-30 17:27:40 +02:00
Thierry Fournier
d0a56c2953 MINOR: dumpstats: split stats_dump_be_stats() in two parts
This patch splits the function stats_dump_be_stats() in two parts. The
part is called stats_fill_be_stats(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
2016-03-30 17:26:19 +02:00
Thierry Fournier
61fe6c0adb MINOR: dumpstats: split stats_dump_sv_stats() in two parts
This patch splits the function stats_dump_sv_stats() in two parts. The
extracted part is called stats_fill_sv_stats(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
2016-03-30 17:26:09 +02:00
Thierry Fournier
c4456856b0 MINOR: dumpstats: split stats_dump_li_stats() in two parts
This patch splits the function stats_dump_li_stats() in two parts. The
extracted part is called stats_fill_li_stats(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
2016-03-30 17:26:02 +02:00
Thierry Fournier
23d2d64185 MINOR: dumpstats: split stats_dump_fe_stats() in two parts
This patch splits the function stats_dump_fe_stats() in two parts. The
extracted part is called stats_fill_fe_stats(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
2016-03-30 17:21:59 +02:00
Thierry Fournier
cb2c767681 MINOR: dumpstats: split stats_dump_info_to_buffer() in two parts
This patch splits the function stats_dump_info_to_buffer() in two parts. The
extracted part is called stats_fill_info(), and just fill the stats buffer.
This split allows the usage of preformated stats in other parts of HAProxy
like the Lua.
2016-03-30 17:21:37 +02:00
Thierry Fournier
31e64ca301 MINOR: dumpstats: extract stats fields enum and names
These field names can be used outside of the dumpstats file.
This will be useful for exporting stats in Lua.
2016-03-30 17:21:09 +02:00
Thierry Fournier
f4011ddcf5 MINOR: http: sample fetch which returns unique-id
This patch adds a sample fetch which returns the unique-id if it is
configured. If the unique-id is not yet generated, it build it. If
the unique-id is not configured, it returns none.
2016-03-30 17:19:45 +02:00
Thierry Fournier
b912567020 DOC: name set-gpt0 mismatch with the expected keyword
replace set-gpt0 by sc-set-gpt0

must be backported in 1.6
2016-03-30 17:16:46 +02:00
Baptiste Assmann
c8f0e78b25 DOC: typo: req.uri is now replaced by capture.req.uri
A configuration example was not updated after the switch from req.uri to
capture.req.uri.

backport: 1.5 and above
2016-03-30 17:13:44 +02:00
Baptiste Assmann
66025d856c DOC: regsub: parser limitation about the inability to use closing square brackets
We can't match range in regsub, since the closing bracket is evaluated
by the configuration parser.

backport: 1.6 and above
2016-03-30 17:13:24 +02:00
Baptiste Assmann
79fb45d10b DOC: typo: maxconn paragraph is wrong due to a wrong buffer size
HAProxy allocates 2 tune.bufsize, which is by default 16kB.

backport: 1.4 and above
2016-03-30 17:12:40 +02:00
Baptiste Assmann
33db600442 DOC: typo: ACL subdir match
ACL subdir match is "-m dir"

backport: 1.5 and above
2016-03-30 17:12:04 +02:00
Baptiste Assmann
123ff0463e DOC: stick-table: amend paragraph blaming the loss of table upon reload
This statement is not true anymore since we have the peers in HAProxy.

backport: 1.6 and above
2016-03-30 17:11:45 +02:00
Baptiste Assmann
2f2d2ec164 DOC: typo on stick-store response
It is used to store responses, and not requests.

backport: 1.5 and above
2016-03-30 16:53:39 +02:00
Baptiste Assmann
2e1941ec6e DOC: timeout client: pointers to timeout http-request
It worth mentionning "timeout http-request" in the "timeout client"
documentation paragraph, to ensure nobody misses this important setting.

backport: 1.5 and above
2016-03-30 16:53:34 +02:00
Baptiste Assmann
13f835380f DOC: "addr" parameter applies to both health and agent checks
It was not obvious in the documentation that the server's "addr"
parameter applies to both the agent and the health check.

backport: 1.5 and above
2016-03-30 15:49:52 +02:00
Thierry Fournier
8b0d6e1d04 MINOR: lua: convert field to lua type
This function converts a field used by stats in lua type.
2016-03-30 15:46:18 +02:00
Thierry Fournier
94ed1c127e MINOR: lua: Add internal function which strip spaces
Some internal HAproxy error message are provided with a final '\n'.
Its typically for the integration in the CLI. Sometimes, these messages
are returned as Lua string. These string must be without "\n" or final
spaces.

This patch adds a function whoch removes unrequired parameters.
2016-03-30 15:45:45 +02:00
Thierry Fournier
3d4a675f24 MINOR: lua: post initialization
This patch adds a Lua post initialisation wrapper. It already exists for
pure Lua function, now it executes also C. It is useful for doing things
when the configuration is ready to use. For example we can can browse and
register all the proxies.
2016-03-30 15:44:58 +02:00
Thierry Fournier
fd107a2b1c MINOR: lua: precise message when a critical error is catched
This patch try to find error message when the safe execution wrapper
function catch a critical error.
2016-03-30 15:44:44 +02:00
Thierry Fournier
45e78d7aa9 MINOR: lua: refactor the Lua object registration
All the HAProxy Lua object are declared with the same pattern:
 - Add the function __tosting which dumps the object name
 - Register the name in the Lua REGISTRY
 - Register the reference ID

These action are refactored in on function. This remove some
lines of code.
2016-03-30 15:43:52 +02:00
Thierry Fournier
4f99b27c34 CLEANUP: lua: Remove two same functions
The function hlua_array_add_fcn() is exactly the same than the function
hlua_class_function(), so this patch removes the first one.
2016-03-30 15:43:25 +02:00
Thierry Fournier
991188d297 MINOR: lua: remove some useless checks
The modified function are declared in the safe environment, so
they must called from safe environement. As the environement is
safe, its useles to check the stack size.
2016-03-30 15:42:50 +02:00
Thierry Fournier
ddd8988fe5 MINOR: lua: move class registration facilities
The functions
 - hlua_class_const_int()
 - hlua_class_const_str()
 - hlua_class_function()
are use for common class registration actions.

The function 'hlua_dump_object()' is generic dump name function.

These functions can be used by all the HAProxy objects, so I move
it into the safe functions file.
2016-03-30 15:42:20 +02:00
Thierry Fournier
9ba1d024db CLEANUP: map: it seems that the map were planed to be chained
It seems that the map were planed to be chained, but obviously
it is not the case. This patch remove the struct which should
be used gor the chain
2016-03-30 15:41:15 +02:00
Thierry Fournier
ac9d467c5e BUG/MINOR: prevent the dump of uninitialized vars
Some vars are not initialized when the dumps of variables
are called. This patch prevent the dereferencement of
uninitialized pointers.
2016-03-30 15:38:10 +02:00
Thierry Fournier
85dc1d3995 BUG/MINOR: lua: can't load external libraries
Libraries requires the export of embedded Lua symbols. If a library
is loaded by HAProxy or by an Lua program, an error like the following
error raises:

   [ALERT] 085/135722 (7224) : parsing [test.cfg:8] : lua runtime error: error loading module 'test' from file './test.so':
        ./test.so: undefined symbol: lua_createtable

This patch modify the Makefile, and allow exports of the Lua symbols.

This patch must be backported in version 1.6
2016-03-30 15:20:19 +02:00
Nenad Merdanovic
69ad4b9977 BUG/MAJOR: Fix crash in http_get_fhdr with exactly MAX_HDR_HISTORY headers
Similar issue was fixed in 67dad27, but the fix is incomplete. Crash still
happened when utilizing req.fhdr() and sending exactly MAX_HDR_HISTORY
headers.

This fix needs to be backported to 1.5 and 1.6.

Signed-off-by: Nenad Merdanovic <nmerdan@anine.io>
2016-03-29 16:03:41 +02:00
Nenad Merdanovic
1789115a52 BUG/MEDIUM: Fix RFC5077 resumption when more than TLS_TICKETS_NO are present
Olivier Doucet reported the issue on the ML and tested that when using
more than TLS_TICKETS_NO keys in the file, the CPU usage is much higeher
than expected.

Lukas Tribus then provided a test case which showed that resumption doesn't
work at all in that case.

This fix needs to be backported to 1.6.

Signed-off-by: Nenad Merdanovic <nmerdan@anine.io>
2016-03-29 16:03:37 +02:00
Willy Tarreau
3bb46177ac BUG/MEDIUM: peers: fix incorrect age in frequency counters
The frequency counters's window start is sent as "now - freq.date",
which is a positive age compared to the current date. But on receipt,
this age was added to the current date instead of subtracted. So
since the date was always in the future, they were always expired if
the activity changed side in less than the counter's measuring period
(eg: 10s).

This bug was reported by Christian Ruppert who also provided an easy
reproducer.

It needs to be backported to 1.6.
2016-03-25 18:17:47 +01:00