]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
16 years ago[MINOR] redirect: add support for "set-cookie" and "clear-cookie"
Willy Tarreau [Wed, 19 Nov 2008 20:07:09 +0000 (21:07 +0100)] 
[MINOR] redirect: add support for "set-cookie" and "clear-cookie"

It is now possible to set or clear a cookie during a redirection. This
is useful for logout pages, or for protecting against some DoSes. Check
the documentation for the options supported by the "redirect" keyword.

(cherry-picked from commit 4af993822e880d8c932f4ad6920db4c9242b0981)

16 years ago[MINOR] redirect: add support for the "drop-query" option
Willy Tarreau [Wed, 19 Nov 2008 19:03:04 +0000 (20:03 +0100)] 
[MINOR] redirect: add support for the "drop-query" option

If "drop-query" is present on a "redirect" line using the "prefix" mode,
then the returned Location header will be the request URI without the
query-string. This may be used on some login/logout pages, or when it
must be decided to redirect the user to a non-secure server.

(cherry-picked from commit f2d361ccd73aa16538ce767c766362dd8f0a88fd)

16 years ago[BUG] critical errors should be reported even in daemon mode
Willy Tarreau [Sun, 16 Nov 2008 06:40:34 +0000 (07:40 +0100)] 
[BUG] critical errors should be reported even in daemon mode

Josh Goebel reported that haproxy silently dies when it fails to
chroot. In fact, it does so when in daemon mode, because daemon
mode has been disabling output for ages.

Since the code has been reworked, this could have been changed
because there is no reason for this anymore, hence this patch.
(cherry picked from commit 304d6fb00fe32fca1bd932a301d4afb7d54c92bc)
(cherry picked from commit 50b7f7f12c67322c793f50a6be009f0fd0eec1bb)

16 years ago[BUILD] fix MANDIR default location to match documentation
Jeremy Hinegardner [Sun, 16 Nov 2008 00:29:03 +0000 (17:29 -0700)] 
[BUILD] fix MANDIR default location to match documentation

I found this while building for Fedora.
(cherry picked from commit a2b53f8831b84b7c8647d7e960b84defd3bcbfa8)
(cherry picked from commit 2cac232b966a252951073d7b1a4bba4c4a730978)

16 years ago[MINOR] cfgparse: fix off-by 2 in error message size
Jeffrey 'jf' Lim [Sat, 4 Oct 2008 16:07:00 +0000 (18:07 +0200)] 
[MINOR] cfgparse: fix off-by 2 in error message size

was just looking through the source, and noticed this... :)
(cherry picked from commit 63b76be713784f487e8d0c859a85513642fe7bdc)
(cherry picked from commit a801db6c5ea750f93a3795dbb2e70c03e05bbef4)

16 years ago[BUG] cookie capture is declared in the frontend but checked on the backend
Willy Tarreau [Fri, 17 Oct 2008 10:01:58 +0000 (12:01 +0200)] 
[BUG] cookie capture is declared in the frontend but checked on the backend

Cookie capture would only work by pure luck on the request but did
never work on responses since only the backend was checked. The fix
consists in always checking frontend for cookie captures.
(cherry picked from commit a83c5ba9315a7c47cda2698280b7e49a9d3eb374)

16 years ago[BUG] acl-related keywords are not allowed in defaults sections
Willy Tarreau [Sun, 12 Oct 2008 15:26:37 +0000 (17:26 +0200)] 
[BUG] acl-related keywords are not allowed in defaults sections

Using an ACL-related keyword in the defaults section causes a
segfault during parsing because the list headers are not initialized.
We must initialize list headers for default instance and reject
keywords relying on ACLs.
(cherry picked from commit 1c90a6ec20946a713e9c93995a8e91ed3eeb9da4)
(cherry picked from commit eb8131b4e418b838b2d62d991d91d94482ba49de)

16 years ago[BUG] ensure that listeners from disabled proxies are correctly unbound.
Willy Tarreau [Sun, 12 Oct 2008 10:07:48 +0000 (12:07 +0200)] 
[BUG] ensure that listeners from disabled proxies are correctly unbound.

There is a problem when an instance is marked "disabled". Its ports are
still bound but will not be unbound upon termination. This causes processes
to accumulate during soft restarts, and might even cause failures to restart
new ones due to the inability to bind to the same port.

The ideal solution would be to bind all ports at the end of the configuration
parsing. An acceptable workaround is to unbind all listeners of disabled
proxies. This is what the current patch does.
(cherry picked from commit a944218e9c1d5ff1aca34609146389dc680335b7)
(cherry picked from commit 8cfebbb82b87345bade831920177077e7d25840a)

16 years ago[BUG] do not try to pause backends during reload
Willy Tarreau [Fri, 10 Oct 2008 15:51:34 +0000 (17:51 +0200)] 
[BUG] do not try to pause backends during reload

During a configuration reload, haproxy tried to pause all proxies.
Unfortunately, it also tried to pause backends, which would fail
and cause trouble to the new process since the port was still bound.

(backported from commit eab5c70f93c0a44223f706f6c120ad8d59f28796)
(cherry picked from commit ac1ca38e9b07422e21b5b4778918d243768e5498)

16 years ago[BUG] dynamic connection throttling could return a max of zero conns
Willy Tarreau [Sun, 14 Sep 2008 15:43:27 +0000 (17:43 +0200)] 
[BUG] dynamic connection throttling could return a max of zero conns

srv_dynamic_maxconn() is clearly documented as returning at least 1
possible connection under throttling. But the computation was wrong,
the minimum 1 was divided and got lost in case of very low maxconns.

Apply the MAX(1, max) before returning the result in order to ensure
that a newly appeared server will get some traffic.
(cherry picked from commit 819970098f134453c0934047b3bd3440b0996b55)

16 years ago[BUG] do not release the connection slot during a retry
Willy Tarreau [Sun, 14 Sep 2008 15:40:09 +0000 (17:40 +0200)] 
[BUG] do not release the connection slot during a retry

(forward-port of commit 8262d8bd7fdb262c980bd70cb2931e51df07513f)

A bug was introduced during last queue management fix. If a server
connection fails, the allocated connection slot is released, but it
will be needed again after the turn-around. This also causes more
connections than expected to go to the server because it appears to
have less connections than real.

Many thanks to Rupert Fiasco, Mark Imbriaco, Cody Fauser, Brian
Gupta and Alexander Staubo for promptly providing configuration
and diagnosis elements to help reproduce this problem easily.

16 years ago[MINOR] acl: add new keyword "connslots"
Jeffrey 'jf' Lim [Wed, 3 Sep 2008 17:03:03 +0000 (01:03 +0800)] 
[MINOR] acl: add new keyword "connslots"

I'm in the process of setting up one haproxy instance now, and I find
the following acl option useful. I'm not too sure why this option has
not been available before, but I find this useful for my own usage, so
I'm submitting this patch in the hope that it will be useful as well.

The basic idea is to be able to measure the available connection slots
still available (connection, + queue) - anything beyond that can be
redirected to a different backend. 'connslots' = number of available
server connection slots, + number of available server queue slots. In
the case where we encounter srv maxconn = 0, or srv maxqueue = 0 (in
which case we dont need to care about connslots) the value you get is
-1. Note also that this code does not take care of dynamic connections
at this point in time.

The reason why I'm using this new acl (as opposed to 'nbsrv') is that
'nbsrv' only measures servers that are actually *down*. Whereas this
other acl is more fine-grained, and looks into the number of conn
slots available as well.

16 years ago[MEDIUM] add support for "show sess" in unix stats socket
Willy Tarreau [Sun, 7 Dec 2008 21:29:48 +0000 (22:29 +0100)] 
[MEDIUM] add support for "show sess" in unix stats socket

It is now possible to list all known sessions by issuing "show sess"
on the unix stats socket. The format is not much evolved but it is
very useful for debugging.

The doc has been updated to reflect the new keyword.

16 years ago[MINOR] add back-references to sessions for later use by a dumper.
Willy Tarreau [Sun, 7 Dec 2008 19:16:23 +0000 (20:16 +0100)] 
[MINOR] add back-references to sessions for later use by a dumper.

This is the first step in implementing a session dump tool.
A session dump will need restart points. It will be necessary for
it to get references to sessions which can be moved when the session
dies.

The principle is not that complex : when a session ends, it looks for
any potential back-references. If it finds any, then it moves them to
the next session in the list. The dump function will of course have
to restart from that new point.

16 years ago[MINOR] add a new back-reference type : struct bref
Willy Tarreau [Sun, 7 Dec 2008 19:00:15 +0000 (20:00 +0100)] 
[MINOR] add a new back-reference type : struct bref

This type will be used to maintain back-references to items which
are subject to move between accesses. Typical usage includes session
removal during a listing.

16 years ago[MINOR] slightly rebalance stats_dump_{raw,http}
Willy Tarreau [Sun, 7 Dec 2008 17:30:00 +0000 (18:30 +0100)] 
[MINOR] slightly rebalance stats_dump_{raw,http}

Both should process the response buffer equally. They now both
clear the hijack bit once done, and both receive a pointer to
the response buffer in their arguments.

16 years ago[MEDIUM] reference the current hijack function in the buffer itself
Willy Tarreau [Sun, 7 Dec 2008 17:03:29 +0000 (18:03 +0100)] 
[MEDIUM] reference the current hijack function in the buffer itself

Instead of calling a hard-coded function to produce data, let's
reference this function into the buffer and call it from there
when BF_HIJACK is set. This goes in the direction of more generic
session management code.

16 years ago[MINOR] move the listener reference from fd to session
Willy Tarreau [Sun, 7 Dec 2008 15:45:10 +0000 (16:45 +0100)] 
[MINOR] move the listener reference from fd to session

The listener referenced in the fd was only used to check the
listener state upon session termination. There was no guarantee
that the FD had not been reassigned by the moment it was processed,
so this was a bit racy. Having it in the session is more robust.

16 years ago[MEDIUM] remove cli_fd, srv_fd, cli_state and srv_state from the session
Willy Tarreau [Sun, 7 Dec 2008 15:27:56 +0000 (16:27 +0100)] 
[MEDIUM] remove cli_fd, srv_fd, cli_state and srv_state from the session

Those were previously used by the unix sockets only, and could be
removed.

16 years ago[MAJOR] make unix sockets work again with stats
Willy Tarreau [Sun, 7 Dec 2008 15:06:43 +0000 (16:06 +0100)] 
[MAJOR] make unix sockets work again with stats

The unix protocol handler had not been updated during the last
stream_sock changes. This has been done now. There is still a
lot of duplicated code between session.c and proto_uxst.c due
to the way the session is handled. Session.c relies on the existence
of a frontend while it does not exist here.

It is easier to see the difference between the stats part (placed
in dumpstats.c) and the unix-stream part (in proto_uxst.c).

The hijacking function still needs to be dynamically set into the
response buffer, and some cleanup is still required, then all those
changes should be forward-ported to the HTTP part. Adding support
for new keywords should not cause trouble now.

16 years ago[MINOR] add an analyser state in struct session
Willy Tarreau [Sun, 7 Dec 2008 13:37:09 +0000 (14:37 +0100)] 
[MINOR] add an analyser state in struct session

It will be very convenient to have an analyser state in the session.
It will always be initialized to zero. The analysers can make use of
it, but must reset it to zero when they leave.

16 years ago[MEDIUM] ensure that sock->shutw() also closes read for init states
Willy Tarreau [Sun, 7 Dec 2008 13:04:04 +0000 (14:04 +0100)] 
[MEDIUM] ensure that sock->shutw() also closes read for init states

Non-connected states will never have a chance to receive a shutr event,
so we need to propagate the shutw across the stream interface.

16 years ago[BUG] do not forward close from cons to prod with analysers
Willy Tarreau [Sun, 7 Dec 2008 12:05:04 +0000 (13:05 +0100)] 
[BUG] do not forward close from cons to prod with analysers

We must not forward a close from consumer to producer as long as
an analyser is present.

16 years ago[MINOR] pre-set analyser flags on the listener at registration time
Willy Tarreau [Sun, 7 Dec 2008 10:50:35 +0000 (11:50 +0100)] 
[MINOR] pre-set analyser flags on the listener at registration time

In order to achieve more generic accept() code, we can set the request
analysers at the listener registration time. It's better than doing it
during accept(), and allows more code reuse.

16 years ago[MINOR] add an analyser code for UNIX stats request
Willy Tarreau [Sun, 7 Dec 2008 10:28:08 +0000 (11:28 +0100)] 
[MINOR] add an analyser code for UNIX stats request

The UNIX stats socket will be analysed like any other protocol. Add
an analyser for it.

16 years ago[MEDIUM] first pass of lifting to proto_uxst.c:uxst_event_accept()
Willy Tarreau [Mon, 1 Dec 2008 00:44:25 +0000 (01:44 +0100)] 
[MEDIUM] first pass of lifting to proto_uxst.c:uxst_event_accept()

The accept function must be adapted to the new framework. It is
still broken, and calling it will still result in a segfault. But
this cleanup is needed anyway.

16 years ago[MINOR] declare process_session in session.h, not proto_http.h
Willy Tarreau [Mon, 1 Dec 2008 00:35:40 +0000 (01:35 +0100)] 
[MINOR] declare process_session in session.h, not proto_http.h

16 years ago[BUG] fix forgotten server session counter
Willy Tarreau [Sun, 30 Nov 2008 23:08:28 +0000 (00:08 +0100)] 
[BUG] fix forgotten server session counter

The server session counter was forgotten when the session establishes.

16 years ago[MEDIUM] rename process_request to http_process_request
Willy Tarreau [Sun, 30 Nov 2008 22:51:27 +0000 (23:51 +0100)] 
[MEDIUM] rename process_request to http_process_request

Now the function only does HTTP request and nothing else. Also pass
the request buffer to it.

16 years ago[MEDIUM] move the HTTP request body analyser out of process_request().
Willy Tarreau [Sun, 30 Nov 2008 22:36:37 +0000 (23:36 +0100)] 
[MEDIUM] move the HTTP request body analyser out of process_request().

A new function http_process_request_body() has been created to process
the request body. Next step is now to clean up process_request().

16 years ago[MEDIUM] extract the HTTP tarpit code from process_request().
Willy Tarreau [Sun, 30 Nov 2008 22:28:40 +0000 (23:28 +0100)] 
[MEDIUM] extract the HTTP tarpit code from process_request().

The tarpit is now an autonomous independant analyser.

16 years ago[MEDIUM] extract TCP request processing from HTTP
Willy Tarreau [Sun, 30 Nov 2008 22:15:34 +0000 (23:15 +0100)] 
[MEDIUM] extract TCP request processing from HTTP

The TCP analyser has moved to proto_tcp.c. Breaking the function
has required finer use of the return value and adding some tests
to process_session().

16 years ago[MINOR] stream_sock_data_finish() should not expose fd
Willy Tarreau [Sun, 30 Nov 2008 20:37:12 +0000 (21:37 +0100)] 
[MINOR] stream_sock_data_finish() should not expose fd

stream_sock_data_finish was still using a file descriptor as only
argument, while a stream interface is preferred. This is now fixed.

16 years ago[CLEANUP] session.c: removed some migration left-overs in sess_establish()
Willy Tarreau [Sun, 30 Nov 2008 20:13:54 +0000 (21:13 +0100)] 
[CLEANUP] session.c: removed some migration left-overs in sess_establish()

A few obsolete fd manipulations were left in sess_establish. Obviously
they must go away.

16 years ago[MEDIUM] make the http server error function a pointer in the session
Willy Tarreau [Sun, 30 Nov 2008 19:44:17 +0000 (20:44 +0100)] 
[MEDIUM] make the http server error function a pointer in the session

It was a bit awkward to have session.c call return_srv_error() for
HTTP error messages related to servers. The function has been adapted
to be passed a pointer to the faulty stream interface, and is now a
pointer in the session. It is possible that in the future, it will
become a callback in the stream interface itself.

16 years ago[MINOR] replace srv_close_with_err() with http_server_error()
Willy Tarreau [Sun, 30 Nov 2008 19:20:08 +0000 (20:20 +0100)] 
[MINOR] replace srv_close_with_err() with http_server_error()

The new function looks like the previous one except that it operates
at the stream interface level and assumes an already closed SI.

Also remove some old unused occurrences of srv_close_with_err().

16 years ago[MINOR] replace client_retnclose() with stream_int_retnclose()
Willy Tarreau [Sun, 30 Nov 2008 18:48:07 +0000 (19:48 +0100)] 
[MINOR] replace client_retnclose() with stream_int_retnclose()

This makes more sense to return a message to a stream interface
than to a session.

senddata.{c,h} have been removed.

16 years ago[MINOR] replace the ambiguous client_return function by stream_int_return
Willy Tarreau [Sun, 30 Nov 2008 18:22:53 +0000 (19:22 +0100)] 
[MINOR] replace the ambiguous client_return function by stream_int_return

This one applies to a stream interface, which makes more sense.

16 years ago[MINOR] call session->do_log() for logging
Willy Tarreau [Sun, 30 Nov 2008 18:02:32 +0000 (19:02 +0100)] 
[MINOR] call session->do_log() for logging

In order to avoid having to call per-protocol logging function directly
from session.c, it's better to assign the logging function when the session
is created. This also eliminates a test when the function is needed, and
opens the way to more complete logging functions.

16 years ago[CLEANUP] move the session-related functions to session.c
Willy Tarreau [Sun, 30 Nov 2008 17:47:21 +0000 (18:47 +0100)] 
[CLEANUP] move the session-related functions to session.c

proto_http.c was not suitable for session-related processing, it was
just convenient for the tranformation.

Some more splitting must occur: process_request/response in proto_http.c
must be split again per protocol, and the caller must run a list.

Some functions should be directly attached to the session or the buffer
(eg: perform_http_redirect, return_srv_error, http_sess_log).

16 years ago[MAJOR] complete layer4/7 separation
Willy Tarreau [Sun, 30 Nov 2008 17:14:12 +0000 (18:14 +0100)] 
[MAJOR] complete layer4/7 separation

All the processing has now completely been split in layers. As of
now, everything is still in process_session() which is not the right
place, but the code sequence works. Timeouts, retries, errors, all
work.

The shutdown sequence has been strictly applied: BF_SHUTR/BF_SHUTW
are only assigned by lower layers. Upper layers can only indicate
their wish to close using BF_SHUTR_NOW and BF_SHUTW_NOW.

When a shutdown is performed on a stream interface, the buffer flags
are updated accordingly and re-checked by upper layers. A lot of care
has been taken to ensure that aborts during intermediate connection
setups are correctly handled and shutdowns correctly propagated to
both buffers.

A future evolution would consist in ensuring that BF_SHUT?_NOW may
be set at any time, and applies only when the buffer is empty. This
might help with error messages, but might complicate the processing
of data remaining in buffers.

Some useless buffer flag combinations have been removed.

Stat counters are still broken (eg: per-server total number of sessions).

Error messages should be delayed to the close instant and be produced by
protocol.

Many functions must now move to proper locations.

16 years ago[MEDIUM] make the stream interface control the SHUT{R,W} bits
Willy Tarreau [Thu, 27 Nov 2008 09:30:51 +0000 (10:30 +0100)] 
[MEDIUM] make the stream interface control the SHUT{R,W} bits

It's better that the stream interface controls the BF_SHUT* bits so
that they always reflect the real state of the interface.

16 years ago[MEDIUM] process shutw during connection attempt
Willy Tarreau [Thu, 27 Nov 2008 08:25:45 +0000 (09:25 +0100)] 
[MEDIUM] process shutw during connection attempt

It sometimes happens that a connection is aborted at the exact same moment
it establishes. We have to close the socket and not only to shut it down
for writes.

Some corner cases remain. We have to handle the shutr/shutw at the stream
interface and only report the status to the buffer, not the opposite.

16 years ago[BUG] shutw must imply close during a connect
Willy Tarreau [Sun, 23 Nov 2008 20:33:29 +0000 (21:33 +0100)] 
[BUG] shutw must imply close during a connect

The sessions which were remaining stuck were being connecting to the
server while they received a shutw which caused them to partially
stop. A shutw() during a connect() must imply a close().

16 years ago[MINOR] maintain a global session list in order to ease debugging
Willy Tarreau [Sun, 23 Nov 2008 18:53:55 +0000 (19:53 +0100)] 
[MINOR] maintain a global session list in order to ease debugging

Now the global variable 'sessions' will be a dual-linked list of all
known sessions. The list element is set at the beginning of the session
so that it's easier to follow them all with gdb.

16 years ago[MEDIUM] remove stream_sock_update_data()
Willy Tarreau [Sun, 23 Nov 2008 18:31:35 +0000 (19:31 +0100)] 
[MEDIUM] remove stream_sock_update_data()

Two new functions are used instead : buffer_check_{shutr,shutw}.
It is indeed more adequate to check for new closures only when the
buffer reports them.

Several remaining unclosed connections were detected after a test,
even before this patch, so a bug remains. To reproduce, try the
following during 30 seconds :

  inject30l4 -n 20000 -l -t 1000 -P 10 -o 4 -u 100 -s 100 -G 127.0.0.1:8000/

16 years ago[MEDIUM] stream_interface: added a DISconnected state between CON/EST and CLO
Willy Tarreau [Sun, 23 Nov 2008 16:23:07 +0000 (17:23 +0100)] 
[MEDIUM] stream_interface: added a DISconnected state between CON/EST and CLO

There were rare situations where it was not easy to detect that a failed
session attempt had occurred and needed some server cleanup. In particular,
client aborts sometimes lead to session leaks on the server side.

A new state "SI_ST_DIS" (disconnected) has been introduced for this. When
a session has been closed at a stream interface but the server cleanup has
not occurred, this state is entered instead of CLO. The cleanup is then
performed there and the state goes to CLO.

A new diagram has been added to show possible stream_interface state
transitions that can occur in a stream-sock. It makes debugging easier.

16 years ago[MEDIUM] continue layering cleanups.
Willy Tarreau [Wed, 12 Nov 2008 00:51:41 +0000 (01:51 +0100)] 
[MEDIUM] continue layering cleanups.

The server sessions are now only decremented when entering SI_ST_CER
and SI_ST_CLO states. A state is clearly missing between EST and CLO,
or after CLO (eg: END), because many cleanups are performed upon CLO
and must rely on tricks to ensure being done only once.

The goal of next changes will be to improve what has been started.
Ideally, the FD should only notify the SI about the change, which
should itself only notify the session when it has some news or when
it needs help (eg: redispatch). The buffer's error processing should
not change the FD's status immediately, otherwise we risk race conds
between a pending connect and a shutw (for instance). Also, the new
connect attempt should only be made after layer 7 and all the crap
above buffers.

16 years ago[MEDIUM] add the SN_CURR_SESS flag to the session to track open sessions
Willy Tarreau [Tue, 11 Nov 2008 19:20:02 +0000 (20:20 +0100)] 
[MEDIUM] add the SN_CURR_SESS flag to the session to track open sessions

It is quite hard to track when the current session has already been counted
or discounted from the server's total number of established sessions. For
this reason, we introduce a new session flag, SN_CURR_SESS, which indicates
if the current session is one of those reported by the server or not. It
simplifies session accounting and makes it far more robust. It also makes
it possible to perform a last-minute cleanup during session_free().

Right now, with this fix and a few more buffer transitions fixes, no session
were found to remain after a test.

16 years ago[MAJOR] add a connection error state to the stream_interface
Willy Tarreau [Mon, 3 Nov 2008 05:26:53 +0000 (06:26 +0100)] 
[MAJOR] add a connection error state to the stream_interface

Tracking connection status changes was hard, and some code was
redundant. A new SI_ST_CER state was added to the stream interface
to indicate a past connection error, and an SI_FL_ERR flag was
added to report past I/O error. The stream_sock code does not set
the connection to SI_ST_CLO anymore in case of I/O error, it's
the upper layer which does it. This makes it possible to know
exactly when the file descriptors are allocated.

The new SI_ST_CER state permitted to split tcp_connection_status()
in two parts, one processing SI_ST_CON and the other one SI_ST_CER.
Synchronous connection errors now make use of this last state, hence
eliminating duplicate code.

Some ib<->ob copy paste errors were found and fixed, and all entities
setting SI_ST_CLO also shut the buffers down.

Some of these stream_interface specific functions and structures
have migrated to a new stream_interface.c file.

Some types of errors are still not detected by the buffers. For
instance, let's assume the following scenario in one single pass
of process_session: a connection sits in SI_ST_TAR state during
a retry. At TAR expiration, a new connection attempt is made, the
connection is obtained and srv->cur_sess is increased. Then the
buffer timeout is fires and everything is cleared, the new state
becomes SI_ST_CLO. The cleaning code checks that previous state
was either SI_ST_CON or SI_ST_EST to release the connection. But
that's wrong because last state is still SI_ST_TAR. So the
server's connection count does not get decreased.

This means that prev_state must not be used, and must be replaced
by some transition detection instead of level detection.

The following debugging line was useful to track state changes :

  fprintf(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
          s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s-> rep->flags);

16 years ago[MAJOR] migrate the connection logic to stream interface
Willy Tarreau [Sun, 26 Oct 2008 19:49:47 +0000 (20:49 +0100)] 
[MAJOR] migrate the connection logic to stream interface

The connection setup code has been refactored in order to
make it run only on low level (stream interface). Several
complicated functions have been removed from backend.c,
and we now have sess_update_stream_int() to manage
an assigned connection, sess_prepare_conn_req() to assign a
server to a connection request, perform_http_redirect() to
redirect instead of connecting to server, and return_srv_error()
to return connection error status messages.

The stream_interface status changes are checked before adjusting
buffer flags, so that the buffers can be informed about this lower
level update.

A new connection is initiated by changing si->state from SI_ST_INI
to SI_ST_REQ.

The code seems to work but is awfully dirty. Some functions need
to be moved, and the layering is not yet quite clear.

A lot of dead old code has simply been removed.

16 years ago[MINOR] add an expiration flag to the stream_sock_interface
Willy Tarreau [Thu, 4 Sep 2008 09:51:16 +0000 (11:51 +0200)] 
[MINOR] add an expiration flag to the stream_sock_interface

This expiration flag is used to indicate that the timer has
expired without having to check it everywhere.

16 years ago[MEDIUM] use buffer_check_timeouts instead of stream_sock_check_timeouts()
Willy Tarreau [Thu, 4 Sep 2008 09:19:41 +0000 (11:19 +0200)] 
[MEDIUM] use buffer_check_timeouts instead of stream_sock_check_timeouts()

It's more appropriate to use buffer_check_timeouts() to check for buffer
timeouts and si->shutw/shutr to shutdown the stream interfaces.

16 years ago[MINOR] add buffer_check_timeouts() to check what timeouts have fired.
Willy Tarreau [Thu, 4 Sep 2008 07:14:08 +0000 (09:14 +0200)] 
[MINOR] add buffer_check_timeouts() to check what timeouts have fired.

This new function sets the BF_*_TIMEOUT flags when a buffer timeout
has expired.

16 years ago[OPTIM] add compiler hints in tick_is_expired()
Willy Tarreau [Thu, 4 Sep 2008 07:00:24 +0000 (09:00 +0200)] 
[OPTIM] add compiler hints in tick_is_expired()

adding those two unlikely() reduces the number of branches taken in
the common path and the size of the code.

16 years ago[MEDIUM] move QUEUE and TAR timers to stream interfaces
Willy Tarreau [Wed, 3 Sep 2008 16:11:02 +0000 (18:11 +0200)] 
[MEDIUM] move QUEUE and TAR timers to stream interfaces

It was not practical to have QUEUE and TAR timers in buffers, as they caused
triggering of the timeout flags. Move them to the stream interface where they
belong.

16 years ago[CLEANUP] process_session: move debug outputs out of the critical loop
Willy Tarreau [Wed, 3 Sep 2008 09:37:47 +0000 (11:37 +0200)] 
[CLEANUP] process_session: move debug outputs out of the critical loop

The if(debug&closed) printfs have moved outside of the loop. It also
permitted to merge several of them.

16 years ago[MEDIUM] process_session: make use of the new buffer flags
Willy Tarreau [Sat, 30 Aug 2008 11:36:43 +0000 (13:36 +0200)] 
[MEDIUM] process_session: make use of the new buffer flags

Now we have almost two distinct parts between tcp and http.
Only the connection establishment code still requires some
resynchronization, the rest does not.

16 years ago[MEDIUM] buffers: add BF_READ_ATTACHED and BF_ANA_TIMEOUT
Willy Tarreau [Sat, 30 Aug 2008 10:31:07 +0000 (12:31 +0200)] 
[MEDIUM] buffers: add BF_READ_ATTACHED and BF_ANA_TIMEOUT

Those two flags will be used to wake up analysers only when
needed.

16 years ago[MEDIUM] stream interface: add the ->shutw method as well as in and out buffers
Willy Tarreau [Sat, 30 Aug 2008 02:58:38 +0000 (04:58 +0200)] 
[MEDIUM] stream interface: add the ->shutw method as well as in and out buffers

Those entries were really needed for cleaner and better code. Using them
has permitted to automatically close a file descriptor during a shut write,
reducing by 20% the number of calls to process_session() and derived
functions.

Process_session() does not need to know the file descriptor anymore, though
it still remains very complicated due to the special case for the connect
mode.

16 years ago[MAJOR] make stream sockets aware of the stream interface
Willy Tarreau [Sat, 30 Aug 2008 01:17:31 +0000 (03:17 +0200)] 
[MAJOR] make stream sockets aware of the stream interface

As of now, a stream socket does not directly wake up the task
but it does contact the stream interface which itself knows the
task. This allows us to perform a few cleanups upon errors and
shutdowns, which reduces the number of calls to data_update()
from 8 per session to 2 per session, and make all the functions
called in the process_session() loop completely swappable.

Some improvements are required. We need to provide a shutw()
function on stream interfaces so that one side which closes
its read part on an empty buffer can propagate the close to
the remote side.

16 years ago[MINOR] change type of fdtab[]->owner to void*
Willy Tarreau [Fri, 29 Aug 2008 21:36:51 +0000 (23:36 +0200)] 
[MINOR] change type of fdtab[]->owner to void*

The owner of an fd was initially a task but this was sometimes
casted to a (struct listener *). We'll soon need more types,
so void* is more appropriate.

16 years ago[MEDIUM] indicate a reason for a task wakeup
Willy Tarreau [Fri, 29 Aug 2008 16:19:04 +0000 (18:19 +0200)] 
[MEDIUM] indicate a reason for a task wakeup

It's very frequent to require some information about the
reason why a task is running. Some flags have been added
so that a task now knows if it got woken up due to I/O
completion, timeout, etc...

16 years ago[OPTIM] force inlining of large functions with gcc >= 3
Willy Tarreau [Fri, 29 Aug 2008 13:48:49 +0000 (15:48 +0200)] 
[OPTIM] force inlining of large functions with gcc >= 3

GCC 3 and above do not inline large functions, which is a problem
with ebtree where most core functions are inlined.

This simple patch has both reduced code size and increased speed.
It should be back-ported to ebtree.

16 years ago[OPTIM] reduce the number of calls to task_wakeup()
Willy Tarreau [Fri, 29 Aug 2008 13:26:14 +0000 (15:26 +0200)] 
[OPTIM] reduce the number of calls to task_wakeup()

A test has shown that more than 16% of the calls to task_wakeup()
could be avoided because the task is already woken up. So make it
inline and move the test to the inline part.

16 years ago[OPTIM] ev_sepoll: detect newly created FDs and check them once
Willy Tarreau [Fri, 29 Aug 2008 11:57:30 +0000 (13:57 +0200)] 
[OPTIM] ev_sepoll: detect newly created FDs and check them once

When an accept() creates a new FD, it is already marked as set for
reads. But the task will be woken up without first checking if the
socket could be read.

The speculative I/O gives us a chance to either read the FD if there
are data pending on it, or immediately mark it for poll mode if
nothing is pending.

Simply doing this reduces the number of calls to process_session
from 6 to 5 per session, 2 to 1 calls to process_request, 10% less
calls to epoll_ctl, fd_clr, fd_set, stream_sock_data_update, 20%
less eb32_insert/eb_delete, etc... General performance increase
seems to be around 3%.

16 years ago[MINOR] do not check for BF_SHUTR when computing write timeout
Willy Tarreau [Fri, 29 Aug 2008 09:30:14 +0000 (11:30 +0200)] 
[MINOR] do not check for BF_SHUTR when computing write timeout

This check was useless as !BF_SHUTR is already implied by tick_isset(rex).

16 years ago[MINOR] re-arrange buffer flags and rename some of them
Willy Tarreau [Fri, 29 Aug 2008 07:58:42 +0000 (09:58 +0200)] 
[MINOR] re-arrange buffer flags and rename some of them

The buffer flags became a big bazaar. Re-arrange them
so that their names are more explicit and so that they
are more easily readable in hex form. Some aggregates
have also been adjusted.

16 years ago[MEDIUM] reintroduce BF_HIJACK with produce_content
Willy Tarreau [Thu, 28 Aug 2008 14:01:32 +0000 (16:01 +0200)] 
[MEDIUM] reintroduce BF_HIJACK with produce_content

The stats dump are back. Even very large config files with
5000 servers work fast and well. The SN_SELF_GEN flag has
completely been removed.

16 years ago[MINOR] only call flow analysers when their read side is connected.
Willy Tarreau [Thu, 28 Aug 2008 09:07:58 +0000 (11:07 +0200)] 
[MINOR] only call flow analysers when their read side is connected.

It's useless to call flow analysers when their read side has not
seen a connection yet.

16 years ago[OPTIM] stream_sock_read must check for null-reads more often
Willy Tarreau [Thu, 28 Aug 2008 07:47:43 +0000 (09:47 +0200)] 
[OPTIM] stream_sock_read must check for null-reads more often

With small HTTP messages, stream_sock_read() tends to wake the
task up for a message read without indicating that it may be
the last one. The reason is that level-triggered pollers generally
don't report HUP with data, but only afterwards, so stream_sock_read
has no chance to detect this condition and needs a respin.

So now we return on incomplete buffers only when the buffer is known
as a streamer, because here it generally makes sense. The net result
is that the number of calls in a single HTTP session has dropped
from 5 to 3, with one less wake up and several less calls to
stream_sock_data_update().

16 years ago[MEDIUM] split stream_sock_process_data
Willy Tarreau [Thu, 28 Aug 2008 06:54:27 +0000 (08:54 +0200)] 
[MEDIUM] split stream_sock_process_data

It was a waste to constantly update the file descriptor's status
and timeouts during a flags update. So stream_sock_process_data
has been slit in two parts :
  stream_sock_data_update()  => computes updated flags
  stream_sock_data_finish()  => computes timeouts

Only the first one is called during flag updates. The second one
is only called upon completion. The number of calls to fd_set/fd_clr
has now significantly dropped.

Also, it's useless to check for errors and timeouts in the
process_session() loop, it's enough to check for them at the
beginning.

16 years ago[MAJOR] make the client side use stream_sock_process_data()
Willy Tarreau [Wed, 27 Aug 2008 21:57:16 +0000 (23:57 +0200)] 
[MAJOR] make the client side use stream_sock_process_data()

The client side now relies on stream_sock_process_data(). One
part has not yet been re-implemented, it concerns the calls
to produce_content().

process_session() has been adjusted to correctly check for
changing bits in order not to call useless functions too many
times.

It already appears that stream_sock_process_data() should be
split so that the timeout computations are only performed at
the exit of process_session().

16 years ago[MEDIUM] stream_sock_process_data moved to stream_sock.c
Willy Tarreau [Wed, 27 Aug 2008 19:41:35 +0000 (21:41 +0200)] 
[MEDIUM] stream_sock_process_data moved to stream_sock.c

The old temporary process_srv_data function moved to stream_sock.c.

16 years ago[MEDIUM] process_srv_data: ensure that we always correctly re-arm timeouts
Willy Tarreau [Wed, 27 Aug 2008 19:10:25 +0000 (21:10 +0200)] 
[MEDIUM] process_srv_data: ensure that we always correctly re-arm timeouts

We really want to ensure that we don't miss a timeout update and do not
update them for nothing. So the code takes care of updating the timeout
in the two following circumstances :
  - it was not set
  - some I/O has been performed

Maybe we'll be able to remove that from stream_sock_{read|write}, or
we'll find a way to ensure that we never have to re-enable this.

16 years ago[MEDIUM] third cleanup and optimization of process_srv_data()
Willy Tarreau [Wed, 27 Aug 2008 18:35:41 +0000 (20:35 +0200)] 
[MEDIUM] third cleanup and optimization of process_srv_data()

Some repeated tests were factored out.
Now the code makes sense and is fully understandable.

16 years ago[MEDIUM] second level of code cleanup for process_srv_data
Willy Tarreau [Wed, 27 Aug 2008 18:09:19 +0000 (20:09 +0200)] 
[MEDIUM] second level of code cleanup for process_srv_data

Now the function is 100% server-independant. Next step will
consist in using the same function for the client side too.

16 years ago[MEDIUM] massive cleanup of process_srv()
Willy Tarreau [Wed, 27 Aug 2008 16:52:22 +0000 (18:52 +0200)] 
[MEDIUM] massive cleanup of process_srv()

Server-specific calls were extracted and moved to the caller.
The function is now nearly server-agnostic.

16 years ago[OPTIM] remove useless fd_set(read) upon shutdown(write)
Willy Tarreau [Wed, 27 Aug 2008 13:19:25 +0000 (15:19 +0200)] 
[OPTIM] remove useless fd_set(read) upon shutdown(write)

Those old tricks are no longer needed and are overwritten
anyway. Remove them.

16 years ago[MAJOR] rework of the server FSM
Willy Tarreau [Sun, 19 Oct 2008 05:30:41 +0000 (07:30 +0200)] 
[MAJOR] rework of the server FSM

srv_state has been removed from HTTP state machines, and states
have been split in either TCP states or analyzers. For instance,
the TARPIT state has just become a simple analyzer.

New flags have been added to the struct buffer to compensate this.
The high-level stream processors sometimes need to force a disconnection
without touching a file-descriptor (eg: report an error). But if
they touched BF_SHUTW or BF_SHUTR, the file descriptor would not
be closed. Thus, the two SHUT?_NOW flags have been added so that
an application can request a forced close which the stream interface
will be forced to obey.

During this change, a new BF_HIJACK flag was added. It will
be used for data generation, eg during a stats dump. It
prevents the producer on a buffer from sending data into it.

  BF_SHUTR_NOW  /* the producer must shut down for reads ASAP  */
  BF_SHUTW_NOW  /* the consumer must shut down for writes ASAP */
  BF_HIJACK     /* the producer is temporarily replaced        */

BF_SHUTW_NOW has precedence over BF_HIJACK. BF_HIJACK has
precedence over BF_MAY_FORWARD (so that it does not need it).

New functions buffer_shutr_now(), buffer_shutw_now(), buffer_abort()
are provided to manipulate BF_SHUT* flags.

A new type "stream_interface" has been added to describe both
sides of a buffer. A stream interface has states and error
reporting. The session now has two stream interfaces (one per
side). Each buffer has stream_interface pointers to both
consumer and producer sides.

The server-side file descriptor has moved to its stream interface,
so that even the buffer has access to it.

process_srv() has been split into three parts :
  - tcp_get_connection() obtains a connection to the server
  - tcp_connection_failed() tests if a previously attempted
    connection has succeeded or not.
  - process_srv_data() only manages the data phase, and in
    this sense should be roughly equivalent to process_cli.

Little code has been removed, and a lot of old code has been
left in comments for now.

16 years ago[MEDIUM] make it possible for analysers to follow the whole session
Willy Tarreau [Thu, 21 Aug 2008 08:05:00 +0000 (10:05 +0200)] 
[MEDIUM] make it possible for analysers to follow the whole session

Some analysers will need to remain present after connection is
established. Change the way BF_MAY_FORWARD is set to allow this.

16 years ago[BUG] fix harmless but wrong fd insertion sequence
Willy Tarreau [Tue, 26 Aug 2008 11:25:39 +0000 (13:25 +0200)] 
[BUG] fix harmless but wrong fd insertion sequence

In backend.c, we had an EV_FD_SET() called before fd_insert().
This is wrong because fd_insert updates maxfd which might be
used by some of the pollers during EV_FD_SET(), although this
is not currently the case.

16 years ago[BUG] Fix empty X-Forwarded-For header name when set in defaults section
Willy Tarreau [Sat, 23 Aug 2008 06:18:21 +0000 (08:18 +0200)] 
[BUG] Fix empty X-Forwarded-For header name when set in defaults section

The following patch introduced a minor bug :
   [MINOR] permit renaming of x-forwarded-for header

If "option forwardfor" is declared in a defaults section, the header name
is never set and we see an empty header name before the value. Also, the
header name was not reset between two defaults sections.

16 years ago[TESTS] test-fsm: 22 regression tests for state machines
Willy Tarreau [Sun, 17 Aug 2008 17:30:03 +0000 (19:30 +0200)] 
[TESTS] test-fsm: 22 regression tests for state machines

22 regression tests for state machines are managed by the new
file tests/test-fsm.cfg. Check it, they are all documented
inside. Most of the bugs introduced during the FSM extraction
have been found with these tests.

16 years ago[BUG] process_request: HTTP body analysis must return zero if missing data
Willy Tarreau [Sun, 17 Aug 2008 17:17:57 +0000 (19:17 +0200)] 
[BUG] process_request: HTTP body analysis must return zero if missing data

This missing return and timeout check caused an infinite loop too.

16 years ago[BUG] process_cli/process_srv: don't call shutdown when already done
Willy Tarreau [Sun, 17 Aug 2008 16:16:38 +0000 (18:16 +0200)] 
[BUG] process_cli/process_srv: don't call shutdown when already done

A few missing checks of BF_SHUTR and BF_SHUTW caused busy loops upon
some error paths.

16 years ago[MEDIUM] merge inspect_exp and txn->exp into request buffer
Willy Tarreau [Sun, 17 Aug 2008 16:03:28 +0000 (18:03 +0200)] 
[MEDIUM] merge inspect_exp and txn->exp into request buffer

Since we may have several analysers on a buffer, it's more
convenient to have the analyser timeout attached to the
buffer itself.

16 years ago[BUILD] fix warning in proto_tcp.c with gcc >= 4
Willy Tarreau [Sun, 17 Aug 2008 15:13:47 +0000 (17:13 +0200)] 
[BUILD] fix warning in proto_tcp.c with gcc >= 4

signedness issues.

16 years ago[BUG] regparm is broken on gcc < 3
Willy Tarreau [Sun, 17 Aug 2008 15:06:37 +0000 (17:06 +0200)] 
[BUG] regparm is broken on gcc < 3

Gcc < 3 does not consider regparm declarations for function pointers.
This causes big trouble at least with pollers (and with any function
pointer after all). Disable CONFIG_HAP_USE_REGPARM for gcc < 3.

16 years ago[OPTIM] process_cli/process_srv: reduce the number of tests
Willy Tarreau [Sun, 17 Aug 2008 14:23:10 +0000 (16:23 +0200)] 
[OPTIM] process_cli/process_srv:  reduce the number of tests

We can skip a number of tests by simply checking a few flags,
it saves a few CPU cycles in the fast path.

16 years ago[MEDIUM] session: move the analysis bit field to the buffer
Willy Tarreau [Sun, 17 Aug 2008 13:20:19 +0000 (15:20 +0200)] 
[MEDIUM] session: move the analysis bit field to the buffer

It makes more sense to store the list of analysers in the buffer
than in the session since they are precisely plugged onto one
buffer.

16 years ago[MINOR] ensure the termination flags are set by process_xxx
Willy Tarreau [Sun, 17 Aug 2008 12:38:41 +0000 (14:38 +0200)] 
[MINOR] ensure the termination flags are set by process_xxx

When any processing remains on a buffer, it must be up to the
processing functions to set the termination flags, because they
are the only ones who know about higher levels.

16 years ago[MEDIUM] centralize buffer timeout checks at the top of process_session
Willy Tarreau [Sun, 17 Aug 2008 11:04:25 +0000 (13:04 +0200)] 
[MEDIUM] centralize buffer timeout checks at the top of process_session

it's more efficient and easier to check all the timeouts at once and
always rely on the buffer flags than to check them everywhere.

16 years ago[MEDIUM] use buffer->wex instead of buffer->cex for connect timeout
Willy Tarreau [Sun, 17 Aug 2008 10:11:14 +0000 (12:11 +0200)] 
[MEDIUM] use buffer->wex instead of buffer->cex for connect timeout

It's a shame not to use buffer->wex for connection timeouts since by
definition it cannot be used till the connection is not established.
Using it instead of ->cex also makes the buffer processing more
symmetric.

16 years ago[MAJOR] process_session: rely only on buffer flags
Willy Tarreau [Sat, 16 Aug 2008 23:00:46 +0000 (01:00 +0200)] 
[MAJOR] process_session: rely only on buffer flags

Instead of calling all functions in a loop, process_session now
calls them according to buffer flags changes. This ensures that
we almost never call functions for nothing. The flags settings
are still quite coarse, but the number of average functions
calls per session has dropped from 31 to 18 (the calls to
process_srv dropped from 13 to 7 and the calls to process_cli
dropped from 13 to 8).

This could still be improved by memorizing which flags each
function uses, but that would add a level of complexity which
is not desirable and maybe even not worth the small gain.

16 years ago[MEDIUM] buffers: add BF_EMPTY and BF_FULL to remove dependency on req/rep->l
Willy Tarreau [Sat, 16 Aug 2008 20:18:07 +0000 (22:18 +0200)] 
[MEDIUM] buffers: add BF_EMPTY and BF_FULL to remove dependency on req/rep->l

It is not always convenient to run checks on req->l in functions to
check if a buffer is empty or full. Now the stream_sock functions
set flags BF_EMPTY and BF_FULL according to the buffer contents. Of
course, functions which touch the buffer contents adjust the flags
too.

16 years ago[CLEANUP] get rid of BF_SHUT*_PENDING
Willy Tarreau [Sat, 16 Aug 2008 19:13:23 +0000 (21:13 +0200)] 
[CLEANUP] get rid of BF_SHUT*_PENDING

BF_SHUTR_PENDING and BF_SHUTW_PENDING were poor ideas because
BF_SHUTR is the pending of BF_SHUTW_DONE and BF_SHUTW is the
pending of BF_SHUTR_DONE. Remove those two useless and confusing
"pending" versions and rename buffer_shut{r,w}_* functions.

16 years ago[BUG] maintain_proxies must not disable backends
Willy Tarreau [Sat, 16 Aug 2008 16:41:13 +0000 (18:41 +0200)] 
[BUG] maintain_proxies must not disable backends

maintain_proxies could disable backends (p->maxconn == 0) which is
wrong (but apparently harmless). Add a check for p->maxconn == 0.

16 years ago[BUG] process_response: do not touch srv_state
Willy Tarreau [Sat, 16 Aug 2008 16:40:18 +0000 (18:40 +0200)] 
[BUG] process_response: do not touch srv_state

process_response is not allowed to touch srv_state (this is an
incident which has survived the code migration). This bug was
causing connection exhaustion on frontend due to some closed
sockets marked SV_STDATA again.

16 years ago[BUG] buffers: remove BF_MAY_CONNECT and fix forwarding issue
Willy Tarreau [Sat, 16 Aug 2008 14:39:26 +0000 (16:39 +0200)] 
[BUG] buffers: remove BF_MAY_CONNECT and fix forwarding issue

It wasn't really wise to separate BF_MAY_CONNECT and BF_MAY_FORWARD,
as it caused trouble in TCP mode because the connection was allowed
but not the forwarding. Remove BF_MAY_CONNECT.