Commit Graph

5205 Commits

Author SHA1 Message Date
Thierry FOURNIER
27929fbfd7 MINOR: channel: rename function chn_sess to chn_strm
The name of the function chn_sess is no longer appropriate.
This patch renames it to chn_strm.
2015-09-25 23:27:33 +02:00
Thierry FOURNIER
ed08d6a9be MEDIUM: proto_http: smp_prefetch_http initialize txn
When we call the function smp_prefetch_http(), if the txn is not initialized,
it doesn't work. This patch fix this. Now, smp_prefecth_http() permits to use
http with any proxy mode.
2015-09-25 23:27:23 +02:00
Willy Tarreau
958f0742a2 BUG/MEDIUM: stream-int: avoid double-call to applet->release
While the SI_ST_DIS state is set *after* doing the close on a connection,
it was set *before* calling release on an applet. Applets have no internal
flags contrary to connections, so they have no way to detect they were
already released. Because of this it happened that applets were closed
twice, once via si_applet_release() and once via si_release_endpoint() at
the end of a transaction. The CLI applet could perform a double free in
this case, though the situation to cause it is quite hard because it
requires that the applet is stuck on output in states that produce very
few data.

In order to solve this, we now assign the SI_ST_DIS state *after* calling
->release, and we refrain from doing so if the state is already assigned.
This makes applets work much more like connections and definitely avoids
this double release.

In the future it might be worth making applets have their own flags like
connections to carry their own state regardless of the stream interface's
state, especially when dealing with connection reuse.

No backport is needed since this issue was caused by the rearchitecture
in 1.6.
2015-09-25 21:16:03 +02:00
Willy Tarreau
5cfa3bcc22 MINOR: cli: do not call the release handler on internal error.
It's dangerous to call this on internal state error, because it risks
to perform a double-free. This can only happen when a state is not
handled. Note that the switch/case currently doesn't offer any option
for missed states since they're all declared. Better fix this anyway.
The fix was tested by commenting out some entries in the switch/case.
2015-09-25 21:16:03 +02:00
Willy Tarreau
c9e930accc BUG/MEDIUM: cli: properly handle closed output
Due to the code inherited from the early CLI mode with the non-interactive
code, the SHUTR status was only considered while waiting for a request,
which prevents the connection from properly being closed during a dump,
and the connection used to remain established. This issue didn't happen
in 1.5 because while this part was missed, the resynchronization performed
in process_session() would detect the situation and handle the cleanup.

No backport is needed.
2015-09-25 21:16:03 +02:00
Willy Tarreau
68c00c7185 BUG/MINOR: stats: do not call cli_release_handler 3 times
If an error happens during a dump on the CLI, an explicit call to
cli_release_handler() is performed. This is not needed anymore since
we introduced ->release() in the applet which is called upon error.
Let's remove this confusing call which can even be risky in some
situations.
2015-09-25 21:16:02 +02:00
Willy Tarreau
eca572fe7f BUG/MEDIUM: applet: fix reporting of broken write situation
If an applet tries to write to a closed connection, it hangs forever.
This results in some "get map" commands on the CLI to leave orphaned
connections alive.

Now the applet wakeup function detects that the applet still wants to
write while the channel is closed for reads, which is the equivalent
to the common "broken pipe" situation. In this case, an error is
reported on the stream interface, just as it happens with connections
trying to perform a send() in a similar situation.

With this fix the stats socket is properly released.
2015-09-25 21:16:02 +02:00
Willy Tarreau
aa977ba205 MINOR: stream-int: rename si_applet_done() to si_applet_wake_cb()
This function is a callback made only for calls from the applet handler.
Rename it to remove confusion. It's currently called from the Lua code
but that's not correct, we should call the notify and update functions
instead otherwise it will not enable the applet again.
2015-09-25 21:16:02 +02:00
Willy Tarreau
335520305c MEDIUM: stream-int: completely remove stream_int_update_embedded()
This one is not needed anymore as what it used to do is either
completely covered by the new stream_int_notify() function, or undesired
and inherited from the past as a side effect of introducing the
connections.

This update is theorically never called since it's assigned only when
nothing is connected to the stream interface. However a test has been
added to si_update() to stay safe if some foreign code decides to call
si_update() in unsafe situations.
2015-09-25 21:16:02 +02:00
Willy Tarreau
651e18292d MEDIUM: stream-int: use the same stream notification function for applets and conns
The code to report completion after a connection update or an applet update
was almost the same since applets stole it from the connection. But the
differences made them hard to maintain and prevented the creation of new
functions doing only one part of the work.

This patch replaces the common code from the si_conn_wake_cb() and
si_applet_wake_cb() with a single call to stream_int_notify() which only
notifies the stream (si+channels+task) from the outside.

No functional change was made beyond this.
2015-09-25 21:16:02 +02:00
Willy Tarreau
615f28bec1 MINOR: stream-int: implement the stream_int_notify() function
stream_int_notify() was taken from the common part between si_conn_wake_cb()
and si_applet_done(). It is designed to report activity to a stream from
outside its handler. It'll generally be used by lower layers to report I/O
completion but may also be used by remote streams if the buffer processing
is shared.
2015-09-25 21:16:02 +02:00
Willy Tarreau
ea3cc48d64 MEDIUM: stream-int: clean up the conditions to enable reading in si_conn_wake_cb
The condition to release the SI_FL_WAIT_ROOM flag was abnormally
complicated because it was inherited from 6 years ago before we used
to check for the buffer's emptiness. The CF_READ_PARTIAL flag had to be
removed, and the complex test was replaced with a simpler one checking
if *some* data were moved out or not.

The reason behind this change is to have a condition compatible with
both connections and applets, as applets currently don't work very
well in this area. Specifically, some optimizations on the applet
side cause them not to release the flag above until the buffer is
empty, which may prevent applets from taking together (eg: peers
over large haproxy buffers and small kernel buffers).
2015-09-25 18:07:16 +02:00
Willy Tarreau
388a2385a5 MINOR: stream-int: move the applet_pause call out of the stream updates
It's just to split the part dealing with the stream update and the part
dealing with the applet update in si_applet_done().
2015-09-25 18:07:16 +02:00
Willy Tarreau
cbc32601a6 MINOR: stream-int: export stream_int_update_*
Not only these functions were not static, but we'll also want to export
them.
2015-09-25 18:07:16 +02:00
Willy Tarreau
5d5b2fecac MEDIUM: stream-int: call stream_int_update() from si_update()
Now the call to stream_int_update() is moved to si_update(), which
is exclusively called from the stream, so that the socket layer may
be updated without updating the stream layer. This will later permit
to call it individually from other places (other tasks or applets for
example).
2015-09-25 18:07:16 +02:00
Willy Tarreau
452c7d5d93 MEDIUM: stream-int: factor out the stream update functions
Now that we have a generic stream_int_update() function, we can
replace the equivalent part in stream_int_update_conn() and
stream_int_update_applet() to avoid code duplication.

There is no functional change, as the code is the same but split
in two functions for each call.
2015-09-25 18:07:16 +02:00
Willy Tarreau
25f1310f33 MINOR: stream-int: implement a new stream_int_update() function
This function is designed to be called from within the stream handler to
update the channels' expiration timers and the stream interface's flags
based on the channels' flags. It needs to be called only once after the
channels' flags have settled down, and before they are cleared, though it
doesn't harm to call it as often as desired (it just slightly hurts
performance). It must not be called from outside of the stream handler,
as what it does will be used to compute the stream task's expiration.

The code was taken directly from stream_int_update_applet() and
stream_int_update_conn() which had exactly the same one except for
applet-specific or connection-specific status update.
2015-09-25 18:07:16 +02:00
Willy Tarreau
2f4e702031 MEDIUM: stream-int: split stream_int_update_conn() into si- and conn-specific parts
The purpose is to separate the connection-specific parts so that the
stream-int specific one can be factored out. There's no functional
change here, only code displacement.
2015-09-25 18:07:16 +02:00
Willy Tarreau
9994238adc BUG/MAJOR: applet: use a separate run queue to maintain list integrity
If an applet wakes up and causes the next one to sleep, the active list
is corrupted and cannot be scanned anymore, as the process then loops
over the next element.

In order to avoid this problem, we move the active applet list to a run
queue and reinit the active list. Only the first element of this queue
is checked, and if the element is not removed, it is removed and requeued
into the active list.

Since we're using a distinct list, if an applet wants to requeue another
applet into the active list, it properly gets added to the active list
and not to the run queue.

This stops the infinite loop issue that could be caused with Lua applets,
and in any future configuration where two applets could be attached
together.
2015-09-25 18:07:16 +02:00
Willy Tarreau
64bca9d36a MINOR: applet: rename applet_runq to applet_active_queue
This is not a real run queue and we're facing ugly bugs because
if this : if a an applet removes another applet from the queue,
typically the next one after itself, the list iterator loops
forever because the list's backup pointer is not valid anymore.
Before creating a run queue, let's rename this list.
2015-09-25 18:02:44 +02:00
Willy Tarreau
9bb49f6906 BUG/MEDIUM: acl: always accept match "found"
The pattern match "found" fails to parse on binary type samples. The
reason is that it presents itself as an integer type which bin cannot
be cast into. We must always accept this match since it validates
anything on input regardless of the type. Let's just relax the parser
to accept it.

This problem might also exist in 1.5.
(cherry picked from commit 91cc2368a73198bddc3e140d267cce4ee08cf20e)
2015-09-24 16:38:48 +02:00
Willy Tarreau
d7bdcb874b BUG/MEDIUM: payload: make req.payload and payload_lv aware of dynamic buffers
Due to a check between offset+len and buf->size, an empty buffer returns
"will never match". Check against tune.bufsize instead.
(cherry picked from commit 43e4039fd5d208fd9d32157d20de93d3ddf9bc0d)
2015-09-24 16:38:48 +02:00
Willy Tarreau
c4b56e4470 MINOR: stream-int: use si_release_endpoint() to close idle conns
We don't want to open-code the connection close code in
si_idle_conn_wake_cb() because we need to centralize some controls.
2015-09-24 11:57:34 +02:00
Thierry FOURNIER
8255a75e08 MINOR: lua: change actions registration
The current Lua action are not registered. The executed function is
selected according with a function name writed in the HAProxy configuration.

This patch add an action registration function. The configuration mode
described above disappear.

This change make some incompatibilities with existing configuration files for
HAProxy 1.6-dev.
2015-09-23 21:44:23 +02:00
Thierry FOURNIER
85c6c97830 MINOR: action: add reference to the original keywork matched for the called parser.
This is usefull because the keyword can contains some condifiguration
data set while the keyword registration.
2015-09-23 21:44:23 +02:00
Thierry FOURNIER
7ea160cb5f MINOR: action: add private configuration
This private configuration pointer is used for storing some configuration
data associated the keyword, So many keywords can use the same parse
function, and this one can use a discriminator.
2015-09-23 21:44:23 +02:00
Willy Tarreau
2c1068cb67 BUG/MEDIUM: stream: do not dereference strm_li(stream)
Some streams do not have a listener (eg: Lua's cosockets) so
let's check for this. For now this problem cannot happen but
it's definitely unsafe.
2015-09-23 13:42:08 +02:00
Willy Tarreau
b746329dc3 BUG/MEDIUM: proxy: do not dereference strm_li(stream)
Some streams do not have a listener (eg: Lua's cosockets) so
let's check for this. For now this problem cannot happen but
it's definitely unsafe.
2015-09-23 13:42:08 +02:00
Willy Tarreau
c29d0cda4b BUG/MEDIUM: http: do not dereference strm_li(stream)
Some streams do not have a listener (eg: Lua's cosockets) so
let's check for this. For now this problem cannot happen but
it's definitely unsafe.
2015-09-23 13:42:08 +02:00
Willy Tarreau
f1e0212d54 BUG/MAJOR: cli: do not dereference strm_li()->proto->name
Or it will crash when dumping streams instanciated by an applet,
like Lua's cosockets.
2015-09-23 13:42:08 +02:00
Willy Tarreau
0fd99094c3 CLEANUP: stream-int: remove obsolete function si_applet_call()
This one is not used anymore and is bogus due to the way applets
now work. Remove it instead of fixing it before someone finds it
fun to use it.
2015-09-23 13:42:08 +02:00
Willy Tarreau
ed17655666 DOC: add more entries to MAINTAINERS
Simon is willing to maintain mailers and external checks.
2015-09-23 07:41:56 +02:00
Emeric Brun
b058f1c548 BUG/MINOR: fct peer_prepare_ackmsg should not use trash.
function 'peer_prepare_ackmsg' is designed to use the argument 'msg'
instead of 'trash.str'.

There is currently no bug because the caller passes 'trash.str' in
the 'msg' argument.
2015-09-22 16:07:34 +02:00
Emeric Brun
a6a0998529 BUG/MEDIUM: peers: same table updates re-pushed after a re-connect
Some updates are pushed using an incremental update message after a
re-connection whereas the origin is forgotten by the peer.
These updates are never correctly acknowledged. So they are regularly
re-pushed after an idle timeout and a re-connect.

The fix consists to use an absolute update message in some cases.
2015-09-22 16:07:32 +02:00
Emeric Brun
c703a9d296 BUG/MEDIUM: peers: some table updates are randomly not pushed.
If an entry is still not present in the update tree, we could miss to schedule
for a push depending of an un-initialized value (upd.key remains un-initialized
for new sessions or isn't re-initalized for reused ones).

In the same way, if an entry is present in the tree, but its update's tick
is far in the past (> 2^31). We could consider it's still scheduled even if
it is not the case.

The fix consist to force the re-scheduling of an update if it was not present in
the updates tree or if the update is not in the scheduling window of every peers.
2015-09-22 16:07:27 +02:00
Baptiste Assmann
8c62c47cb2 BUG: dns: can't connect UDP socket on FreeBSD
PiBANL reported that HAProxy's DNS resolver can't "connect" its socker
on FreeBSD.
Remi Gacogne reported that we should use the function 'get_addr_len' to
get the addr structure size instead of sizeof.
2015-09-22 16:06:41 +02:00
Willy Tarreau
a9937f9519 DOC: add more entries to MAINTAINERS
Cyril is the most impacted by doc format changes, Thierry is the one who
knows maps and patterns infrastructure in great details.
2015-09-22 01:08:15 +02:00
Willy Tarreau
f7ead61388 BUG/MINOR: args: add name for ARGT_VAR
Commit 4834bc7 ("MEDIUM: vars: adds support of variables") introduced
ARGT_VAR but forgot to put it in the names array. No backport needed.
2015-09-21 20:57:12 +02:00
Willy Tarreau
a68f7629dd BUG/MEDIUM: stick-tables: fix double-decrement of tracked entries
Mailing list participant "mlist" reported negative conn_cur values in
stick tables as the result of "tcp-request connection track-sc". The
reason is that after the stick entry it copied from the session to the
stream, both the session and the stream grab a reference to the entry
and when the stream ends, it decrements one reference and one connection,
then the same is done for the session.

In fact this problem was already encountered slightly differently in the
past and addressed by Thierry using the patch below as it was believed by
then to be only a refcount issue since it was the observable symptom :

   827752e "BUG/MEDIUM: stick-tables: refcount error after copying SC..."

In reality the problem is that the stream must touch neither the refcount
nor the connection count for entries it inherits from the session. While
we have no way to tell whether a track entry was inherited from the session
(since they're simply memcpy'd), it is possible to prevent the stream from
touching an entry that already exists in the session because that's a
guarantee that it was inherited from it.

Note that it may be a temporary fix. Maybe in the future when a session
gives birth to multiple streams we'll face a situation where a session may
be updated to add more tracked entries after instanciating some streams.
The correct long-term fix is to mark some tracked entries as shared or
private (or RO/RW). That will allow the session to track more entries
even after the same trackers are being used by early streams.

No backport is needed, this is only caused by the session/stream split in 1.6.
2015-09-21 17:48:24 +02:00
Willy Tarreau
8f1b35b383 DOC: update coding-style to reference checkpatch.pl
Running the Linux kernel's checkpatch.pl is actually quite efficient
at spotting style issues and even sometimes bugs. The doc now suggests
how to use it to avoid the warnings that are specific to Linux's stricter
rules.

It properly reports errors like the following ones that were found on
real submissions so it should improve the situation for everyone :

ERROR: "foo * bar" should be "foo *bar"
+static char * tcpcheck_get_step_comment(struct check *, int);

ERROR: do not use assignment in if condition
+                       if ((comment = tcpcheck_get_step_comment(check, step)))

WARNING: trailing semicolon indicates no statements, indent implies otherwise
+                       if (elem->data && elem->free);
+                               elem->free(elem->data);

ERROR: do not initialise statics to 0 or NULL
+static struct lru64_head *ssl_ctx_lru_tree = NULL;

ERROR: space required after that ',' (ctx:VxV)
+           !X509_gmtime_adj(X509_get_notAfter(newcrt),(long)60*60*24*365))
                                                      ^
WARNING: space prohibited between function name and open parenthesis '('
+       else if (EVP_PKEY_type (capkey->type) == EVP_PKEY_RSA)

ERROR: trailing statements should be on next line
+       if (cacert) X509_free(cacert);

ERROR: space prohibited after that open parenthesis '('
+                                       !(         (srv_op_state == SRV_ST_STOPPED)
2015-09-21 16:45:45 +02:00
Willy Tarreau
37bb7be09c BUG/MAJOR: peers: fix a crash when stopping peers on unbound processes
Pradeep Jindal reported and troubleshooted a bug causing haproxy to die
during startup on all processes not making use of a peers section. It
only happens with nbproc > 1 when peers are declared. Technically it's
when the peers task is stopped on processes that don't use it that the
crash occurred (a task_free() called on a NULL task pointer).

This only affects peers v2 in the dev branch, no backport is needed.
2015-09-21 15:24:58 +02:00
Willy Tarreau
14a923cd2e DOC: add a MAINTAINERS file
This one indicates who to CC when sending changes affecting certain
parts of the product.
2015-09-21 15:24:34 +02:00
James Rosewell
63426cb6a6 MINOR: 51d: Improved string handling for LRU cache
Removed use of strlen with the data added to and retrived from the cache
by using chunk structures instead of string pointers.
2015-09-21 12:55:24 +02:00
James Rosewell
a28bbd53c4 MAJOR: 51d: Upgraded to support 51Degrees V3.2 and new features
Trie device detection doesn't benefit from caching compared to Pattern.
As such the LRU cache has been removed from the Trie method.

A new fetch  method has been added named 51d.all which uses all the
available HTTP headers for device device detection. The previous 51d
conv method has been changed to 51d.single where one HTTP header,
typically User-Agent, is used for detection. This method is marginally
faster but less accurate.

Three new properties are available with the Pattern method called
Method, Difference and Rank which provide insight into the validity of
the results returned.

A pool of worksets is used to avoid needing to create a new workset for
every request. The workset pool is thread safe ready to support a future
multi threaded version of HAProxy.
2015-09-21 12:44:59 +02:00
James Rosewell
3670eb1d74 BUILD: Changed 51Degrees option to support V3.2
Added support for city hash method, turned off multi threading support
and included maths library. Removed reference to compression library
which was never needed.
2015-09-21 12:14:11 +02:00
James Rosewell
a0c4c69b67 DOC: Added more explanation for 51Degrees V3.2
Changed examples to demonstrate the the new fetch and conv methods
available with the enhancements made in version 3.2 of 51Degrees.

Added reference to the accuracy indicators available with Pattern
detection method.
2015-09-21 12:13:50 +02:00
James Rosewell
10790964b0 MINOR: global: Added new fields for 51Degrees device detection
Added support for version 3.2 of 51Degrees C library.

Added fields to store HTTP header names important to device detection
other than User-Agent.

Included a pool of worksets for use with Pattern device detection.
2015-09-21 12:10:41 +02:00
James Rosewell
91a41cb32d MINOR: http: made CHECK_HTTP_MESSAGE_FIRST accessible to other functions
Added the definition of CHECK_HTTP_MESSAGE_FIRST and the declaration of
smp_prefetch_http to the header.

Changed smp_prefetch_http implementation to remove the static qualifier.
2015-09-21 12:05:26 +02:00
Willy Tarreau
11e334d972 DOC: add a CONTRIBUTING file
This file tries to explain in the most detailed way how to contribute
patches. A few parts of it were moved from the README. .gitignore was
updated.
2015-09-20 22:43:56 +02:00
Willy Tarreau
2f5cd60ed0 DOC: add the documentation about internal circular lists
This file was recovered from the first project where it was born 12 years
ago, but it's still convenient to understand how our circular lists work,
so let's add it.
2015-09-20 22:43:56 +02:00