]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
12 years agoMAJOR: connection: add a new CO_FL_CONNECTED flag
Willy Tarreau [Mon, 23 Jul 2012 17:45:44 +0000 (19:45 +0200)] 
MAJOR: connection: add a new CO_FL_CONNECTED flag

This new flag is used to indicate that the connection was already
connected. It can be used by I/O handlers to know that a connection
has just completed. It is used by stream_sock_update_conn(), allowing
the sock_opt handlers not to manipulate the SI timeout nor the
BF_WRITE_NULL flag anymore.

12 years agoMEDIUM: stream_interface: centralize the SI_FL_ERR management
Willy Tarreau [Mon, 23 Jul 2012 17:19:51 +0000 (19:19 +0200)] 
MEDIUM: stream_interface: centralize the SI_FL_ERR management

It's better to have only stream_sock_update_conn() handle the conversion
of the CO_FL_ERROR flag to SI_FL_ERR than having it in each and every I/O
callback.

12 years agoMEDIUM: stream_interface: pass connection instead of fd in sock_ops
Willy Tarreau [Mon, 23 Jul 2012 16:53:03 +0000 (18:53 +0200)] 
MEDIUM: stream_interface: pass connection instead of fd in sock_ops

The sock_ops I/O callbacks made use of an FD till now. This has become
inappropriate and the struct connection is much more useful. It also
fixes the race condition introduced by previous change.

12 years agoMAJOR: remove the stream interface and task management code from sock_*
Willy Tarreau [Mon, 23 Jul 2012 16:24:25 +0000 (18:24 +0200)] 
MAJOR: remove the stream interface and task management code from sock_*

The socket data layer code must only focus on moving data between a
socket and a buffer. We need a special stream interface handler to
update the stream interface and the file descriptor status.

At the moment the code works but suffers from a race condition caused
by its API : the read/write callbacks still make use of the fd instead
of using the connection. And when a double shutdown is performed, a call
to ->write() after ->read() processed an error results in dereferencing
a NULL fdtab[]->owner. This is only a temporary issue which doesn't need
to be fixed now since this will automatically go away when the functions
change to use the connection instead.

12 years agoCLEANUP: remove the now unused fdtab direct I/O callbacks
Willy Tarreau [Fri, 6 Jul 2012 14:02:29 +0000 (16:02 +0200)] 
CLEANUP: remove the now unused fdtab direct I/O callbacks

They were all left to NULL since last commit so we can safely remove them
all now and remove the temporary dual polling logic in pollers.

12 years agoMAJOR: tcp: remove the specific I/O callbacks for TCP connection probes
Willy Tarreau [Mon, 23 Jul 2012 13:07:23 +0000 (15:07 +0200)] 
MAJOR: tcp: remove the specific I/O callbacks for TCP connection probes

Use a single tcp_connect_probe() instead of tcp_connect_write() and
tcp_connect_read(). We call this one only when no data layer function
have been processed, so this is a fallback to test for completion of
a connection attempt.

With this done, we don't have the need for any direct I/O callback
anymore.

The function still relies on ->write() to wake the stream interface up,
so it's not finished.

12 years agoMEDIUM: connection: extract the send_proxy callback from proto_tcp
Willy Tarreau [Fri, 6 Jul 2012 15:12:34 +0000 (17:12 +0200)] 
MEDIUM: connection: extract the send_proxy callback from proto_tcp

This handshake handler must be independant, so move it away from
proto_tcp. It has a dedicated connection flag. It is tested before
I/O handlers and automatically removes the CO_FL_WAIT_L4_CONN flag
upon success.

It also sets the BF_WRITE_NULL flag on the stream interface and
stops the SI timeout. However it does not perform the task_wakeup(),
and relies on the data handler to do so for now. The SI wakeup will
have to be moved elsewhere anyway.

12 years agoMEDIUM: connection: remove the FD_POLL_* flags only once
Willy Tarreau [Mon, 23 Jul 2012 10:14:26 +0000 (12:14 +0200)] 
MEDIUM: connection: remove the FD_POLL_* flags only once

It's inappropriate to remove FD_POLL_IN and FD_POLL_OUT in the IO callback
handlers, first because they shouldn't care about this, and second because
it will make it harder to chain multiple callers.

So let's flush these flags only once for all in the connection handler.
Right now, the HUP and ERR flags are still flushed in each IO handler to
avoid multiple calls. This will probably have to be fixed later.

12 years agoMINOR: fd: make fdtab->owner a connection and not a stream_interface anymore
Willy Tarreau [Fri, 6 Jul 2012 12:54:49 +0000 (14:54 +0200)] 
MINOR: fd: make fdtab->owner a connection and not a stream_interface anymore

It is more convenient with a connection here and will abstract stream_interface
more easily.

12 years agoMAJOR: connection: replace direct I/O callbacks with the connection callback
Willy Tarreau [Fri, 6 Jul 2012 12:29:45 +0000 (14:29 +0200)] 
MAJOR: connection: replace direct I/O callbacks with the connection callback

Almost all direct I/O callbacks have been changed to use the connection
callback instead. Only the TCP connection validation remains.

12 years agoMINOR: connection: add a handler for fd-based connections
Willy Tarreau [Fri, 6 Jul 2012 12:13:49 +0000 (14:13 +0200)] 
MINOR: connection: add a handler for fd-based connections

This connection handler will be used as an I/O handler for events
detected on a file descriptor. It is not used yet.

12 years agoMEDIUM: protocols: use the generic I/O callback for accept callbacks
Willy Tarreau [Fri, 6 Jul 2012 10:25:58 +0000 (12:25 +0200)] 
MEDIUM: protocols: use the generic I/O callback for accept callbacks

This one is used only on read events, and it was easy to convert to
use the new I/O callback.

12 years agoMEDIUM: checks: make use of fdtab->iocb instead of cb[]
Willy Tarreau [Fri, 6 Jul 2012 10:00:49 +0000 (12:00 +0200)] 
MEDIUM: checks: make use of fdtab->iocb instead of cb[]

Use the single I/O callback to handle the checks. This should soon be
replaced by the common connection handler.

12 years agoMEDIUM: polling: prepare to call the iocb() function when defined.
Willy Tarreau [Fri, 6 Jul 2012 09:44:28 +0000 (11:44 +0200)] 
MEDIUM: polling: prepare to call the iocb() function when defined.

We will need this to centralize I/O callbacks. Nobody sets it right
now so the code should have no impact.

12 years agoMINOR: fd: add a new I/O handler to fdtab
Willy Tarreau [Fri, 6 Jul 2012 08:53:51 +0000 (10:53 +0200)] 
MINOR: fd: add a new I/O handler to fdtab

This one will eventually replace both cb[] handlers. At the moment it
is not used yet.

12 years agoMAJOR: get rid of fdtab[].state and use connection->flags instead
Willy Tarreau [Fri, 6 Jul 2012 08:17:53 +0000 (10:17 +0200)] 
MAJOR: get rid of fdtab[].state and use connection->flags instead

fdtab[].state was only used to know whether a connection was in progress
or an error was encountered. Instead we now use connection->flags to store
a flag for both. This way, connection management will be able to update the
connection status on I/O.

12 years agoMINOR: connection: add flags to the connection struct
Willy Tarreau [Fri, 6 Jul 2012 07:52:14 +0000 (09:52 +0200)] 
MINOR: connection: add flags to the connection struct

We're doing this to take over fdtab[].state.

12 years agoREORG/MINOR: checks: put a struct connection into the server
Willy Tarreau [Fri, 6 Jul 2012 07:40:59 +0000 (09:40 +0200)] 
REORG/MINOR: checks: put a struct connection into the server

This will be used to handle the connection state once it goes away from fdtab.
There is no functional change at the moment.

12 years agoREORG/MINOR: connection: move declaration to its own include file
Willy Tarreau [Fri, 6 Jul 2012 07:47:57 +0000 (09:47 +0200)] 
REORG/MINOR: connection: move declaration to its own include file

This way we don't depend on stream_interface anymore.

12 years agoREORG/MEDIUM: fd: get rid of FD_STLISTEN
Willy Tarreau [Thu, 5 Jul 2012 21:36:42 +0000 (23:36 +0200)] 
REORG/MEDIUM: fd: get rid of FD_STLISTEN

This state was only used so that ev_sepoll did not match FD_STERROR, which
changed in previous patch. We can now safely remove this state.

12 years agoREORG/MEDIUM: fd: remove checks for FD_STERROR in ev_sepoll
Willy Tarreau [Thu, 5 Jul 2012 21:33:51 +0000 (23:33 +0200)] 
REORG/MEDIUM: fd: remove checks for FD_STERROR in ev_sepoll

This test is present only in this poller as an optimization, but this
optimization adds some complexity to remove fdtab[].state. Let's get
rid of it for now.

12 years agoREORG/MEDIUM: fd: remove FD_STCLOSE from struct fdtab
Willy Tarreau [Thu, 5 Jul 2012 21:19:22 +0000 (23:19 +0200)] 
REORG/MEDIUM: fd: remove FD_STCLOSE from struct fdtab

In an attempt to get rid of fdtab[].state, and to move the relevant
parts to the connection struct, we remove the FD_STCLOSE state which
can easily be deduced from the <owner> pointer as there is a 1:1 match.

12 years agoDOC: fix name for "option independant-streams"
Jamie Gloudon [Sat, 25 Aug 2012 04:18:33 +0000 (00:18 -0400)] 
DOC: fix name for "option independant-streams"

The correct spelling is "independent", not "independant". This patch
fixes the doc and the configuration parser to accept the correct form.
The config parser still allows the old naming for backwards compatibility.

12 years agoDOC: Typos cleanup
Jamie Gloudon [Sat, 25 Aug 2012 04:18:33 +0000 (00:18 -0400)] 
DOC: Typos cleanup

I came across a couple of typos in configuration.txt and made this patch.
Also, there is an inconsistency between using the word analys/ze in
configuration.txt as well. However, I did not provide a patch for that.

-- Jamie Gloudon

[wt: won't fix the us/uk language mistakes, they'll always exist anyway]

12 years agoMEDIUM: stats/cli: add support for "set table key" to enter values
Willy Tarreau [Wed, 6 Jun 2012 23:03:16 +0000 (01:03 +0200)] 
MEDIUM: stats/cli: add support for "set table key" to enter values

This is used to enter values for stick tables. The most likely usage
is to set gpc0 for a specific IP address in order to block traffic
for abusers without having to reload. Since all data types are
supported, other usages are possible (eg: replace a users's assigned
server).

12 years agoMINOR: stats/cli: add plans to support more stick-table actions
Willy Tarreau [Wed, 6 Jun 2012 21:37:08 +0000 (23:37 +0200)] 
MINOR: stats/cli: add plans to support more stick-table actions

Right now we only support show/clear on a table. In order to introduce
the "set" keyword we need to get rid of the "show" boolean arg. There
is no functional change up to this commit.

12 years agoBUG: stktable: tcp_src_to_stktable_key() must return NULL on invalid families
Willy Tarreau [Thu, 30 Aug 2012 20:52:28 +0000 (22:52 +0200)] 
BUG: stktable: tcp_src_to_stktable_key() must return NULL on invalid families

Source addresses of non-TCP families were not correctly handled by
tcp_src_to_stktable_key() as it forgot to return NULL and instead left
the previous value in the stick-table buffer.

This bug is 1.5-specific and was introduced by commit 4f92d320 in 1.5-dev6
so it does not need any backport.

12 years agoBUG/MINOR: to_log erased with unique-id-format
William Lallemand [Thu, 9 Aug 2012 14:41:35 +0000 (16:41 +0200)] 
BUG/MINOR: to_log erased with unique-id-format

curproxy->to_log was reset to LW_INIT when using unique-id-format,
so logs looked like option logasap

12 years agoMINOR: http: add the urlp_val ACL match
Willy Tarreau [Tue, 31 Jul 2012 05:51:48 +0000 (07:51 +0200)] 
MINOR: http: add the urlp_val ACL match

It's derived from other urlp_* matches, but there was no way to check for
an integer value and it seems like it's significantly used.

12 years agoBUG/MINOR: polling: some events were not set in various pollers
Willy Tarreau [Fri, 6 Jul 2012 09:16:01 +0000 (11:16 +0200)] 
BUG/MINOR: polling: some events were not set in various pollers

fdtab[].ev was only set in ev_sepoll. Unfortunately, some I/O handling
functions now rely on this, so depending on the polling mechanism, some
useless operations might have been performed, such as performing a useless
recv() when a HUP was reported.

This is a very old issue, the flags were only added to the fdtab and not
propagated into any poller. Then they were used in ev_sepoll which needed
them for the cache. It is unsure whether a backport to 1.4 is appropriate
or not.

12 years agoBUG/MINOR: tarpit: fix condition to return the HTTP 500 message
Willy Tarreau [Mon, 23 Jul 2012 08:55:43 +0000 (10:55 +0200)] 
BUG/MINOR: tarpit: fix condition to return the HTTP 500 message

Commit fa7e1025 (1.3.16-rc1) introduced a minor bug by comparing req->flags
with BF_READ_ERROR instead of checking for the bit. The result is that the
error message is always returned even in case of client error. This has no
real impact but this must be fixed.

It may be backported to 1.4 and 1.3.

12 years agoMINOR: IPv6 support for transparent proxy
David du Colombier [Fri, 13 Jul 2012 12:34:59 +0000 (14:34 +0200)] 
MINOR: IPv6 support for transparent proxy

Set socket option IPV6_TRANSPARENT on binding
to enable transparent proxy on IPv6.
This option is available from Linux 2.6.37.

12 years agoOPTIM: i386: make use of kernel-mode-linux when available
Willy Tarreau [Mon, 18 Jun 2012 18:01:30 +0000 (20:01 +0200)] 
OPTIM: i386: make use of kernel-mode-linux when available

If haproxy is built with support for USE_VSYSCALL_DLSYM, it's very
easy to check for KML availability. So let's enable it. Tests show
a small overall performance improvement around 1%. Other tests show
that the syscall overhead is divided by 4 on a Geode LX using this
method.

12 years agoMEDIUM: pattern: add the "base" sample fetch method
Willy Tarreau [Sun, 29 Apr 2012 13:39:40 +0000 (15:39 +0200)] 
MEDIUM: pattern: add the "base" sample fetch method

This one returns the concatenation of the first Host header entry with
the path. It can make content-switching rules easier, help with fighting
DDoS on certain URLs and improve shared caches efficiency.

12 years agoMINOR: replace acl_fetch_{path,url}* with smp_fetch_*
Willy Tarreau [Sun, 29 Apr 2012 07:28:50 +0000 (09:28 +0200)] 
MINOR: replace acl_fetch_{path,url}* with smp_fetch_*

Doing so allows us to support sticking on URL, URL's IP, URL's port and
path.

Both fetch functions should be improved to support an optional depth
allowing to stick to a server depending on just a few directory
components. This would help with portals, some prefetch-capable
caches and with outgoing connections using multiple internet links.

13 years agoDOC: specify the default value for maxconn in the context of a proxy
Vincent Bernat [Wed, 27 Jun 2012 15:18:30 +0000 (17:18 +0200)] 
DOC: specify the default value for maxconn in the context of a proxy

Default value for maxconn in the context of a proxy is 2000 and is
unrelated to any other value (like global ulimit-n or global
maxconn). Without an explicit a user may think that the default value
is either no limit or equal to the global maxconn value.

13 years agoBUG/MINOR: ACL implicit arguments must be created with unresolved flag
Willy Tarreau [Fri, 15 Jun 2012 06:02:34 +0000 (08:02 +0200)] 
BUG/MINOR: ACL implicit arguments must be created with unresolved flag

Commit 496aa0 fixed a design issue by adding an "unresolved" flag to the
ACL arguments. Unfortunately this unresolved flag was not set when building
the fake argument some ACL need when using an implicit argument pointing to
the local proxy.

Special thanks to Michael Kearey who reported the issue with a reproducer
and the commit introducing the bug.

13 years agoOPTIM: halog: improve cold-cache behaviour when loading a file
Willy Tarreau [Tue, 12 Jun 2012 07:16:56 +0000 (09:16 +0200)] 
OPTIM: halog: improve cold-cache behaviour when loading a file

Using posix_fadvise() it is possible to tell the system that we're
going to read a whole file at once. The kernel then doubles the
read-ahead size for this file. On Linux with an SSD, this has improved
cold-cache performance by around 20%. Hot-cache is not affected at all.

13 years agoOPTIM: halog: make use of memchr() on platforms which provide a fast one
Willy Tarreau [Tue, 12 Jun 2012 06:52:22 +0000 (08:52 +0200)] 
OPTIM: halog: make use of memchr() on platforms which provide a fast one

glibc-2.11 on x86_64 provides a machine-specific memchr() which is faster
than the generic C implementation by around 40%, so let's make it possible
to use it instead of the hand-coded version.

13 years agoCLEANUP: halog: make clean should also remove .o files
Willy Tarreau [Tue, 12 Jun 2012 05:59:16 +0000 (07:59 +0200)] 
CLEANUP: halog: make clean should also remove .o files

13 years agoBUG/MEDIUM: ebtree: ebmb_insert() must not call cmp_bits on full-length matches
Willy Tarreau [Sat, 9 Jun 2012 13:43:36 +0000 (15:43 +0200)] 
BUG/MEDIUM: ebtree: ebmb_insert() must not call cmp_bits on full-length matches

Otherwise we end up comparing the byte past the end, resulting
in duplicate values still being inserted into the tree even if
undesired.

This generally has low impact, though it can sometimes cause one new entry
to be added next to an existing one for stick tables, preventing the results
from being merged.

(cherry picked from commit 12e54ac493a91bb02064568f410592c2700d3933)

13 years agoMINOR: halog: use the more recent dual-mode fgets2 implementation
Willy Tarreau [Sat, 9 Jun 2012 07:44:03 +0000 (09:44 +0200)] 
MINOR: halog: use the more recent dual-mode fgets2 implementation

This version implements both 32 and 64 bit versions at once, it
avoids the need to have two separate output files. It also improves
efficiency on i386 platforms by adding a little bit of assembly where
gcc isn't efficient.

13 years agoMEDIUM: fd/si: move peeraddr from struct fdinfo to struct connection
Willy Tarreau [Fri, 8 Jun 2012 20:57:36 +0000 (22:57 +0200)] 
MEDIUM: fd/si: move peeraddr from struct fdinfo to struct connection

The destination address is purely a connection thing and not an fd thing.
It's also likely that later the address will be stored into the connection
and linked to by the SI.

struct fdinfo only keeps the pointer to the port range and the local port
for now. All of this also needs to move to the connection but before this
the release of the port range must move from fd_delete() to a new function
dedicated to the connection.

13 years agoBUILD: add an AIX 5.2 (and later) target.
Willy Tarreau [Wed, 6 Jun 2012 14:15:03 +0000 (16:15 +0200)] 
BUILD: add an AIX 5.2 (and later) target.

It's always a real pain to build on AIX and I constantly lose my flags,
so let's store them once for all in the Makefile.

13 years agoBUG/MAJOR: cookie prefix doesn't support cookie-less servers
Willy Tarreau [Wed, 6 Jun 2012 14:07:00 +0000 (16:07 +0200)] 
BUG/MAJOR: cookie prefix doesn't support cookie-less servers

Commit 827aee91 merged in 1.5-dev5 introduced a regression causing
the srv pointer to be tested twice instead of srv then srv->cookie.
The result is that if a server has no cookie in prefix mode, haproxy
will crash when trying to modify it.

Such a config is very unlikely to happen, except maybe with a backup
server, which would cause haproxy to die with the last server in the
farm.

No backport is needed, only 1.5-dev was affected.

13 years ago[RELEASE] Released version 1.5-dev11
Willy Tarreau [Sun, 3 Jun 2012 22:43:45 +0000 (00:43 +0200)] 
[RELEASE] Released version 1.5-dev11

Released version 1.5-dev11 with the following main changes :
    - BUG/MEDIUM: option forwardfor if-none doesn't work with some configurations
    - BUG/MAJOR: trash must always be the size of a buffer
    - DOC: fix minor regex example issue and improve doc on stats
    - MINOR: stream_interface: add a pointer to the listener for TARG_TYPE_CLIENT
    - MEDIUM: protocol: add a pointer to struct sock_ops to the listener struct
    - MINOR: checks: add on-marked-up option
    - MINOR: balance uri: added 'whole' parameter to include query string in hash calculation
    - MEDIUM: stream_interface: remove the si->init
    - MINOR: buffers: add a rewind function
    - BUG/MAJOR: fix regression on content-based hashing and http-send-name-header
    - MAJOR: http: stop using msg->sol outside the parsers
    - CLEANUP: http: make it more obvious that msg->som is always null outside of chunks
    - MEDIUM: http: get rid of msg->som which is not used anymore
    - MEDIUM: http: msg->sov and msg->sol will never wrap
    - BUG/MAJOR: checks: don't call set_server_status_* when no LB algo is set
    - BUG/MINOR: stop connect timeout when connect succeeds
    - REORG: move the send-proxy code to tcp_connect_write()
    - REORG/MINOR: session: detect the TCP monitor checks at the protocol accept
    - MINOR: stream_interface: introduce a new "struct connection" type
    - REORG/MINOR: stream_interface: move si->fd to struct connection
    - REORG/MEDIUM: stream_interface: move applet->state and private to connection
    - MINOR: stream_interface: add a data channel close function
    - MEDIUM: stream_interface: call si_data_close() before releasing the si
    - MINOR: peers: use the socket layer operations from the peer instead of sock_raw
    - BUG/MINOR: checks: expire on timeout.check if smaller than timeout.connect
    - MINOR: add a new function call tracer for debugging purposes
    - BUG/MINOR: perform_http_redirect also needs to rewind the buffer
    - BUG/MAJOR: b_rew() must pass a signed offset to b_ptr()
    - BUG/MEDIUM: register peer sync handler in the proper order
    - BUG/MEDIUM: buffers: fix bi_putchr() to correctly advance the pointer
    - BUG/MINOR: fix option httplog validation with TCP frontends
    - BUG/MINOR: log: don't report logformat errors in backends
    - REORG/MINOR: use dedicated proxy flags for the cookie handling
    - BUG/MINOR: config: do not report twice the incompatibility between cookie and non-http
    - MINOR: http: add support for "httponly" and "secure" cookie attributes
    - BUG/MEDIUM: ensure that unresolved arguments are freed exactly once
    - BUG/MINOR: commit 196729ef used wrong condition resulting in freeing constants
    - MEDIUM: stats: add support for soft stop/soft start in the admin interface
    - MEDIUM: stats: add the ability to kill sessions from the admin interface
    - BUILD: add support for linux kernels >= 2.6.28

13 years agoBUILD: add support for linux kernels >= 2.6.28
Willy Tarreau [Sun, 3 Jun 2012 22:42:09 +0000 (00:42 +0200)] 
BUILD: add support for linux kernels >= 2.6.28

Since all kernels starting from 2.6.28 support both splice() and tproxy,
add such a target to simplify the build process.

13 years agoMEDIUM: stats: add the ability to kill sessions from the admin interface
Willy Tarreau [Sun, 3 Jun 2012 22:26:23 +0000 (00:26 +0200)] 
MEDIUM: stats: add the ability to kill sessions from the admin interface

It was not possible to kill remaining sessions from the admin interface,
which is annoying especially when switching to maintenance mode. Now it's
possible.

13 years agoMEDIUM: stats: add support for soft stop/soft start in the admin interface
Willy Tarreau [Sun, 3 Jun 2012 22:22:44 +0000 (00:22 +0200)] 
MEDIUM: stats: add support for soft stop/soft start in the admin interface

One important missing feature on the web interface is the ability to perform
a soft stop/soft start. This is now possible.

13 years agoMINOR: checks: add on-marked-up option
Justin Karneges [Thu, 24 May 2012 22:28:52 +0000 (15:28 -0700)] 
MINOR: checks: add on-marked-up option

This implements the feature discussed in the earlier thread of killing
connections on backup servers when a non-backup server comes back up. For
example, you can use this to route to a mysql master & slave and ensure
clients don't stay on the slave after the master goes from down->up. I've done
some minimal testing and it seems to work.

[WT: added session flag & doc, moved the killing after logging the server UP,
 and ensured that the new server is really usable]

13 years agoBUG/MINOR: commit 196729ef used wrong condition resulting in freeing constants
Willy Tarreau [Fri, 1 Jun 2012 08:58:06 +0000 (10:58 +0200)] 
BUG/MINOR: commit 196729ef used wrong condition resulting in freeing constants

Recent commit 196729ef had inverted condition to free format strings. No
backport is needed, it was never released.

13 years agoBUG/MEDIUM: ensure that unresolved arguments are freed exactly once
Willy Tarreau [Fri, 1 Jun 2012 08:38:29 +0000 (10:38 +0200)] 
BUG/MEDIUM: ensure that unresolved arguments are freed exactly once

When passing arguments to ACLs and samples, some types are stored as
strings then resolved later after config parsing is done. Upon exit,
the arguments need to be freed only if the string was not resolved
yet. At the moment we can encounter double free during deinit()
because some arguments (eg: userlists) are freed once as their own
type and once as a string.

The solution consists in adding an "unresolved" flag to the args to
say whether the value is still held in the <str> part or is final.

This could be debugged thanks to a useful bug report from Sander Klein.

13 years agoMINOR: http: add support for "httponly" and "secure" cookie attributes
Willy Tarreau [Thu, 31 May 2012 19:02:17 +0000 (21:02 +0200)] 
MINOR: http: add support for "httponly" and "secure" cookie attributes

   httponly  This option tells haproxy to add an "HttpOnly" cookie attribute
             when a cookie is inserted. This attribute is used so that a
             user agent doesn't share the cookie with non-HTTP components.
             Please check RFC6265 for more information on this attribute.

   secure    This option tells haproxy to add a "Secure" cookie attribute when
             a cookie is inserted. This attribute is used so that a user agent
             never emits this cookie over non-secure channels, which means
             that a cookie learned with this flag will be presented only over
             SSL/TLS connections. Please check RFC6265 for more information on
             this attribute.

13 years agoBUG/MINOR: config: do not report twice the incompatibility between cookie and non...
Willy Tarreau [Thu, 31 May 2012 18:43:11 +0000 (20:43 +0200)] 
BUG/MINOR: config: do not report twice the incompatibility between cookie and non-http

This one was already taken care of in proxy_cfg_ensure_no_http(), so if a
cookie is presented in a TCP backend, we got two warnings.

This can be backported to 1.4 since it's been this way for 2 years (although not dramatic).

13 years agoREORG/MINOR: use dedicated proxy flags for the cookie handling
Willy Tarreau [Thu, 31 May 2012 18:40:20 +0000 (20:40 +0200)] 
REORG/MINOR: use dedicated proxy flags for the cookie handling

Cookies were mixed with many other options while they're not used as options.
Move them to a dedicated bitmask (ck_opts). This has released 7 flags in the
proxy options and leaves some room for new proxy flags.

13 years agoBUG/MINOR: log: don't report logformat errors in backends
Willy Tarreau [Thu, 31 May 2012 17:39:23 +0000 (19:39 +0200)] 
BUG/MINOR: log: don't report logformat errors in backends

Logs have always been ignored by backends, do not report useless warnings there.

13 years agoBUG/MINOR: fix option httplog validation with TCP frontends
Willy Tarreau [Thu, 31 May 2012 17:30:26 +0000 (19:30 +0200)] 
BUG/MINOR: fix option httplog validation with TCP frontends

Option httplog needs to be checked only once the proxy has been validated,
so that its final mode (tcp/http) can be used. Also we need to check for
httplog before checking the log format, so that we can report a warning
about this specific option and not about the format it implies.

13 years agoBUG/MEDIUM: buffers: fix bi_putchr() to correctly advance the pointer
Willy Tarreau [Thu, 31 May 2012 14:37:11 +0000 (16:37 +0200)] 
BUG/MEDIUM: buffers: fix bi_putchr() to correctly advance the pointer

bi_putchr() failed to move the buffer pointer forward. The only user
was the peer handler which was broken, it failed to sync. Thanks to
Hervé Commowick for reporting the issue.

13 years agoBUG/MEDIUM: register peer sync handler in the proper order
Willy Tarreau [Thu, 31 May 2012 12:16:59 +0000 (14:16 +0200)] 
BUG/MEDIUM: register peer sync handler in the proper order

Hervé Commowick reported a failure to resync upon restart caused by a
segfault on the old process. This is due to the data_ctx of the connection
being initialized after the stream interface.

13 years agoBUG/MAJOR: b_rew() must pass a signed offset to b_ptr()
Willy Tarreau [Thu, 31 May 2012 09:33:42 +0000 (11:33 +0200)] 
BUG/MAJOR: b_rew() must pass a signed offset to b_ptr()

Commit 13e66da introduced b_rew() but passes -adv which is an unsigned
quantity on 64-bit platforms, causing the buffer to advance in the wrong
direction.

No backport is needed.

13 years agoBUG/MINOR: perform_http_redirect also needs to rewind the buffer
Willy Tarreau [Wed, 30 May 2012 05:59:54 +0000 (07:59 +0200)] 
BUG/MINOR: perform_http_redirect also needs to rewind the buffer

Commit d1de8af362905d43bcd96e7522fcee62a93a53bf was incomplete, because
perform_http_redirect() also needs to rewind the buffer since it's called
after data are scheduled for forwarding.

No backport needed.

13 years agoBUG/MEDIUM: option forwardfor if-none doesn't work with some configurations
Cyril Bonté [Tue, 29 May 2012 21:27:41 +0000 (23:27 +0200)] 
BUG/MEDIUM: option forwardfor if-none doesn't work with some configurations

When "option forwardfor" is enabled in a frontend that uses backends,
"if-none" ignores the header name provided in the frontend.
This prevents haproxy to add the X-Forwarded-For header if the option is not
used in the backend.

This may introduce security issues for servers/applications that rely on the
header provided by haproxy.

A minimal configuration which can reproduce the bug:
defaults
mode http

listen OK
bind :9000

option forwardfor if-none
server s1 127.0.0.1:80

listen BUG-frontend
bind :9001

option forwardfor if-none

default_backend BUG-backend

backend BUG-backend
server s1 127.0.0.1:80

13 years agoMINOR: add a new function call tracer for debugging purposes
Willy Tarreau [Fri, 25 May 2012 21:53:16 +0000 (23:53 +0200)] 
MINOR: add a new function call tracer for debugging purposes

This feature relies on GCC's ability to call helpers at function entry/exit
points. We define these helpers to quickly dump the minimum info into a trace
file that can be converted to a human readable format using a script in the
contrib/trace directory. This has only been implemented in the GNU makefile
for now on as it is unsure whether it's supported on all OSes.

The feature is enabled by building with "TRACE=1". The performance impact is
huge, so this feature should only be used when debugging. To limit the loss
of performance, fprintf() has been disabled and the output is hand-crafted
and emitted using fwrite(), resulting in doubling the performance. Using the
TSC instead of gettimeofday() also doubles the performance. Around 1200 conns/s
may be achieved on a Pentium-M 1.7 GHz which leads to around 50 MB/s of traces.

The entry and exits of all functions will be dumped into a file designated
by the HAPROXY_TRACE environment variable, or by default "trace.out". If the
trace file name is empty or "/dev/null", then traces are disabled. If
opening the trace file fails, then stderr is used. If HAPROXY_TRACE_FAST is
used, then the time is taken from the global <now> variable. Last, if
HAPROXY_TRACE_TSC is used, then the machine's TSC is used instead of the
real time (almost twice as fast).

The output format is :

  <sec.usec> <level> <caller_ptr> <dir> <callee_ptr>
or :
  <tsc> <level> <caller_ptr> <dir> <callee_ptr>

where <dir> is '>' when entering a function and '<' when leaving.

The awk script in contrib/trace provides a nicer indented output :

6f74989e6f8 ->->->   run_poll_loop > signal_process_queue [src/haproxy.c:1097:0x804bd69] > [include/proto/signal.h:32:0x8049cd0]
6f74989eb00          run_poll_loop < signal_process_queue [src/haproxy.c:1097:0x804bd69] < [include/proto/signal.h:32:0x8049cd0]
6f74989ef44 ->->->   run_poll_loop > wake_expired_tasks [src/haproxy.c:1100:0x804bd72] > [src/task.c:123:0x8055060]
6f74989f3a6 ->->->->   wake_expired_tasks > eb32_lookup_ge [src/task.c:128:0x8055091] > [ebtree/eb32tree.c:138:0x80a8c70]
6f74989f7e9            wake_expired_tasks < eb32_lookup_ge [src/task.c:128:0x8055091] < [ebtree/eb32tree.c:138:0x80a8c70]
6f74989fc0d ->->->->   wake_expired_tasks > eb32_first [src/task.c:134:0x80550d5] > [ebtree/eb32tree.h:55:0x8054ad0]
6f7498a003d ->->->->->   eb32_first > eb_first [ebtree/eb32tree.h:56:0x8054af1] > [ebtree/ebtree.h:520:0x8054a10]
6f7498a0436 ->->->->->->   eb_first > eb_walk_down [ebtree/ebtree.h:521:0x8054a33] > [ebtree/ebtree.h:442:0x80549a0]
6f7498a0843 ->->->->->->->   eb_walk_down > eb_gettag [ebtree/ebtree.h:445:0x80549d6] > [ebtree/ebtree.h:418:0x80548e0]
6f7498a0c2b                  eb_walk_down < eb_gettag [ebtree/ebtree.h:445:0x80549d6] < [ebtree/ebtree.h:418:0x80548e0]
6f7498a1042 ->->->->->->->   eb_walk_down > eb_untag [ebtree/ebtree.h:447:0x80549e2] > [ebtree/ebtree.h:412:0x80548a0]
6f7498a1498                  eb_walk_down < eb_untag [ebtree/ebtree.h:447:0x80549e2] < [ebtree/ebtree.h:412:0x80548a0]
6f7498a18c6 ->->->->->->->   eb_walk_down > eb_root_to_node [ebtree/ebtree.h:448:0x80549e7] > [ebtree/ebtree.h:432:0x8054960]
6f7498a1cd4                  eb_walk_down < eb_root_to_node [ebtree/ebtree.h:448:0x80549e7] < [ebtree/ebtree.h:432:0x8054960]
6f7498a20c4                eb_first < eb_walk_down [ebtree/ebtree.h:521:0x8054a33] < [ebtree/ebtree.h:442:0x80549a0]
6f7498a24b4              eb32_first < eb_first [ebtree/eb32tree.h:56:0x8054af1] < [ebtree/ebtree.h:520:0x8054a10]
6f7498a289c            wake_expired_tasks < eb32_first [src/task.c:134:0x80550d5] < [ebtree/eb32tree.h:55:0x8054ad0]
6f7498a2c8c          run_poll_loop < wake_expired_tasks [src/haproxy.c:1100:0x804bd72] < [src/task.c:123:0x8055060]
6f7498a3095 ->->->   run_poll_loop > process_runnable_tasks [src/haproxy.c:1103:0x804bd7a] > [src/task.c:190:0x8055150]

A nice improvement would possibly consist in trying to get the function's
arguments in the stack and to dump a few more infor for some well-known
functions (eg: the session's status for process_session).

13 years agoBUG/MINOR: checks: expire on timeout.check if smaller than timeout.connect
Willy Tarreau [Fri, 25 May 2012 05:41:38 +0000 (07:41 +0200)] 
BUG/MINOR: checks: expire on timeout.check if smaller than timeout.connect

It happens that haproxy doesn't displace the task in the wait queue when
validating a connection, so if the check timeout is set to a smaller value
than timeout.connect, it will not strike before timeout.connect.

The bug is present at least in 1.4.15..1.4.21, so the fix must be backported.

13 years agoMINOR: balance uri: added 'whole' parameter to include query string in hash calculation
Oskar Stolc [Sat, 19 May 2012 09:19:54 +0000 (10:19 +0100)] 
MINOR: balance uri: added 'whole' parameter to include query string in hash calculation

This patch brings a new "whole" parameter to "balance uri" which makes
the hash work over the whole uri, not just the part before the query
string. Len and depth parameter are still honnored.

The reason for this new feature is explained below.

I have 3 backend servers, each accepting different form of HTTP queries:

http://backend1.server.tld/service1.php?q=...
http://backend1.server.tld/service2.php?q=...

http://backend2.server.tld/index.php?query=...&subquery=...

http://backend3.server.tld/image/49b8c0d9ff

Each backend server returns a different response based on either:
- the URI path (the left part of the URI before the question mark)
- the query string (the right part of the URI after the question mark)
- or the combination of both

I wanted to set up a common caching cluster (using 6 Squid servers, each
configured as reverse proxy for those 3 backends) and have HAProxy balance
the queries among the Squid servers based on URL. I also wanted to achieve
hight cache hit ration on each Squid server and send the same queries to
the same Squid servers. Initially I was considering using the 'balance uri'
algorithm, but that would not work as in case of backend2 all queries would
go to only one Squid server. The 'balance url_param' would not work either
as it would send the backend3 queries to only one Squid server.

So I thought the simplest solution would be to use 'balance uri', but to
calculate the hash based on the whole URI (URI path + query string),
instead of just the URI path.

13 years agoMEDIUM: protocol: add a pointer to struct sock_ops to the listener struct
Emeric Brun [Fri, 18 May 2012 16:30:29 +0000 (18:30 +0200)] 
MEDIUM: protocol: add a pointer to struct sock_ops to the listener struct

The listener struct is now aware of the socket layer to use upon accept().
At the moment, only sock_raw is supported so this patch should not change
anything.

13 years agoMINOR: stream_interface: add a pointer to the listener for TARG_TYPE_CLIENT
Emeric Brun [Fri, 18 May 2012 14:32:13 +0000 (16:32 +0200)] 
MINOR: stream_interface: add a pointer to the listener for TARG_TYPE_CLIENT

When the target is a client, it will be convenient to have a pointer to the
original listener so that we can retrieve some configuration information at
the stream interface level.

13 years agoMINOR: peers: use the socket layer operations from the peer instead of sock_raw
Willy Tarreau [Mon, 21 May 2012 20:18:17 +0000 (22:18 +0200)] 
MINOR: peers: use the socket layer operations from the peer instead of sock_raw

At the moment, all the peers are initialized to use sock_raw as the socket
layer, so use this info in peers_session_create() instead of the hard-coded
sock_raw.

13 years agoMEDIUM: stream_interface: call si_data_close() before releasing the si
Willy Tarreau [Mon, 21 May 2012 16:05:40 +0000 (18:05 +0200)] 
MEDIUM: stream_interface: call si_data_close() before releasing the si

This will ensure that the data layer releases anything previously allocated.

13 years agoMINOR: stream_interface: add a data channel close function
Willy Tarreau [Mon, 21 May 2012 15:28:50 +0000 (17:28 +0200)] 
MINOR: stream_interface: add a data channel close function

This function will be called later when splitting the shutdown in two
steps. It will be needed by SSL and for remote socket operations to
release unused contexts.

13 years agoREORG/MEDIUM: stream_interface: move applet->state and private to connection
Willy Tarreau [Mon, 21 May 2012 15:09:48 +0000 (17:09 +0200)] 
REORG/MEDIUM: stream_interface: move applet->state and private to connection

The state and the private pointer are not specific to the applets, since SSL
will require exactly both of them. Move them to the connection layer now and
rename them. We also now ensure that both are NULL on first call.

13 years agoREORG/MINOR: stream_interface: move si->fd to struct connection
Willy Tarreau [Mon, 21 May 2012 14:47:54 +0000 (16:47 +0200)] 
REORG/MINOR: stream_interface: move si->fd to struct connection

The socket fd is used only when in socket mode and with a connection.

13 years agoMINOR: stream_interface: introduce a new "struct connection" type
Willy Tarreau [Mon, 21 May 2012 14:31:45 +0000 (16:31 +0200)] 
MINOR: stream_interface: introduce a new "struct connection" type

We start to move everything needed to manage a connection to a special
entity "struct connection". We have the data layer operations and the
control operations there. We'll also have more info in the future such
as file descriptors and applet contexts, so that in the end it becomes
detachable from the stream interface, which will allow connections to
be reused between sessions.

For now on, we start with minimal changes.

13 years agoREORG/MINOR: session: detect the TCP monitor checks at the protocol accept
Willy Tarreau [Sun, 20 May 2012 17:22:25 +0000 (19:22 +0200)] 
REORG/MINOR: session: detect the TCP monitor checks at the protocol accept

It does not make sense anymore to wait for a session creation to process
a TCP monitor check which only closes the connection and returns. Better
to process this immediately after the accept() return. It also saves us
from counting a connection for monitor checks, which is much more logical.

13 years agoREORG: move the send-proxy code to tcp_connect_write()
Willy Tarreau [Sun, 20 May 2012 16:35:19 +0000 (18:35 +0200)] 
REORG: move the send-proxy code to tcp_connect_write()

It is much better and more efficient to consider that the send-proxy
feature is part of the protocol layer than part of the data layer.
Now the connection is considered established once the send-proxy line
has been sent.

This way the data layer doesn't have to care anymore about this specific
part.

The tcp_connect_write() function now automatically calls the data layer
write() function once the connection is established, which saves calls
to epoll_ctl/epoll_wait/process_session.

It's starting to look more and more obvious that tcp_connect_read() and
tcp_connect_write() are not TCP-specific but only socket-specific and as
such should probably move, along with some functions from protocol.c, to
a socket-specific file (eg: stream_sock).

It would be nice to be able to support autonomous listeners to parse the
proxy protocol before accepting a connection, so that we get rid of it
at the session layer and to support using these informations in the
tcp-request connection rules.

13 years agoBUG/MINOR: stop connect timeout when connect succeeds
Willy Tarreau [Sun, 20 May 2012 08:38:46 +0000 (10:38 +0200)] 
BUG/MINOR: stop connect timeout when connect succeeds

If the connect succeeds exactly at the same millisecond as the connect
timeout is supposed to strike, the timeout is still considered while
data may have already be sent. This results in a new connection attempt
with no data and with the response being lost.

Note that in practice the only real-world situation where this is observed
is when connect timeouts are extremely low, too low for safe operations.
This bug was encountered with a 1ms connect timeout.

It is also present on 1.4 and needs to be fixed there too.

13 years agoBUG/MAJOR: checks: don't call set_server_status_* when no LB algo is set
Willy Tarreau [Sat, 19 May 2012 17:07:40 +0000 (19:07 +0200)] 
BUG/MAJOR: checks: don't call set_server_status_* when no LB algo is set

David Touzeau reported that haproxy dies when a server is checked and is
used in a farm with only "option transparent" and no LB algo. This is
because the LB params are NULL, the functions should be checked before
being called.

The same bug is present in 1.4 so this patch must be backported.

13 years agoMEDIUM: http: msg->sov and msg->sol will never wrap
Willy Tarreau [Fri, 18 May 2012 21:41:28 +0000 (23:41 +0200)] 
MEDIUM: http: msg->sov and msg->sol will never wrap

These ones are offsets now, so they cannot wrap. Let's remove the useless
wrapping detection and simplify the forwarding code.

13 years agoMEDIUM: http: get rid of msg->som which is not used anymore
Willy Tarreau [Fri, 18 May 2012 21:22:52 +0000 (23:22 +0200)] 
MEDIUM: http: get rid of msg->som which is not used anymore

msg->som was zero before the body and was used to carry the beginning
of a chunk size for chunked-encoded messages, at a moment when msg->sol
is always zero.

Remove msg->som and replace it with msg->sol where needed.

13 years agoCLEANUP: http: make it more obvious that msg->som is always null outside of chunks
Willy Tarreau [Fri, 18 May 2012 21:04:32 +0000 (23:04 +0200)] 
CLEANUP: http: make it more obvious that msg->som is always null outside of chunks

Since the recent buffer reorg, msg->som is redundant with buf->p but still
appears at a number of places. This tiny patch allows to confirm that som
follows two states :
  - 0 from the moment the message starts to be parsed
  - relative offset to ->p for start of chunk when parsing chunks

During this second state, ->sol is never used, so we should probably merge
the two.

13 years agoMAJOR: http: stop using msg->sol outside the parsers
Willy Tarreau [Fri, 18 May 2012 20:36:34 +0000 (22:36 +0200)] 
MAJOR: http: stop using msg->sol outside the parsers

This is a left-over from the buffer changes. Msg->sol is always null at the
end of the parsing, so we must not use it anymore to read headers or find
the beginning of a message. As a side effect, the dump of the request in
debug mode is working again because it was relying on msg->sol not being
null.

Maybe it will even be mergeable with another of the message pointers.

13 years agoBUG/MAJOR: fix regression on content-based hashing and http-send-name-header
Willy Tarreau [Fri, 18 May 2012 20:12:14 +0000 (22:12 +0200)] 
BUG/MAJOR: fix regression on content-based hashing and http-send-name-header

The recent split between the buffers and HTTP messages in 1.5-dev9 caused
a major trouble : in the past, we used to keep a pointer to HTTP data in the
buffer struct itself, which was the cause of most of the pain we had to deal
with buffers.

Now the two are split but we lost the information about the beginning of
the HTTP message once it's being forwarded. While it seems normal, it happens
that several parts of the code currently rely on this ability to inspect a
buffer containing old contents :
  - balance uri
  - balance url_param
  - balance url_param check_post
  - balance hdr()
  - balance rdp-cookie()
  - http-send-name-header

All these happen after the data are scheduled for being forwarded, which
also causes a server to be selected. So for a long time we've been relying
on supposedly sent data that we still had a pointer to.

Now that we don't have such a pointer anymore, we only have one possibility :
when we need to inspect such data, we have to rewind the buffer so that ->p
points to where it previously was. We're lucky, no data can leave the buffer
before it's being connecting outside, and since no inspection can begin until
it's empty, we know that the skipped data are exactly ->o. So we rewind the
buffer by ->o to get headers and advance it back by the same amount.

Proceeding this way is particularly important when dealing with chunked-
encoded requests, because the ->som and ->sov fields may be reused by the
chunk parser before the connection attempt is made, so we cannot rely on
them.

Also, we need to be able to come back after retries and redispatches, which
might change the size of the request if http-send-name-header is set. All of
this is accounted for by the output queue so in the end it does not look like
a bad solution.

No backport is needed.

13 years agoMINOR: buffers: add a rewind function
Willy Tarreau [Fri, 18 May 2012 20:11:27 +0000 (22:11 +0200)] 
MINOR: buffers: add a rewind function

b_rew() will be used to rewind a buffer for certain specific operations
such as header inspection on data already in the output queue.

13 years agoMEDIUM: stream_interface: remove the si->init
Willy Tarreau [Fri, 18 May 2012 13:15:26 +0000 (15:15 +0200)] 
MEDIUM: stream_interface: remove the si->init

Calling the init() function in sess_establish was a bad idea, it is
too late to allow it to fail on lack of resource and does not help at
all. Remove it for now before it's used.

13 years agoBUG/MAJOR: trash must always be the size of a buffer
David du Colombier [Wed, 16 May 2012 12:16:48 +0000 (14:16 +0200)] 
BUG/MAJOR: trash must always be the size of a buffer

Before it was possible to resize the buffers using global.tune.bufsize,
the trash has always been the size of a buffer by design. Unfortunately,
the recent buffer sizing at runtime forgot to adjust the trash, resulting
in it being too short for content rewriting if buffers were enlarged from
the default value.

The bug was encountered in 1.4 so the fix must be backported there.

13 years agoDOC: fix minor regex example issue and improve doc on stats
Dmitry Sivachenko [Wed, 16 May 2012 10:00:26 +0000 (14:00 +0400)] 
DOC: fix minor regex example issue and improve doc on stats

URL rewriting should use [^\ :]* to avoid matching headers.

13 years ago[RELEASE] Released version 1.5-dev10 v1.5-dev10
Willy Tarreau [Mon, 14 May 2012 05:26:56 +0000 (07:26 +0200)] 
[RELEASE] Released version 1.5-dev10

Released version 1.5-dev10 with the following main changes :
    - BUG/MINOR: stats admin: "Unexpected result" was displayed unconditionally
    - BUG/MAJOR: acl: http_auth_group() must not accept any user from the userlist
    - CLEANUP: auth: make the code build again with DEBUG_AUTH
    - BUG/MEDIUM: config: don't crash at config load time on invalid userlist names
    - REORG: use the name sock_raw instead of stream_sock
    - MINOR: stream_interface: add a client target : TARG_TYPE_CLIENT
    - BUG/MEDIUM: stream_interface: restore get_src/get_dst
    - CLEANUP: sock_raw: remove last references to stream_sock
    - CLEANUP: stream_interface: stop exporting socket layer functions
    - MINOR: stream_interface: add an init callback to sock_ops
    - MEDIUM: stream_interface: derive the socket operations from the target
    - MAJOR: fd: remove the need for the socket layer to recheck the connection
    - MINOR: session: call the socket layer init function when a session establishes
    - MEDIUM: session: add support for tunnel timeouts
    - MINOR: standard: add a new debug macro : fddebug()
    - CLEANUP: fd: remove unused cb->b pointers in the struct fdtab
    - OPTIM: proto_http: don't enable quick-ack on empty buffers
    - OPTIM/MAJOR: ev_sepoll: process spec events after polled events
    - OPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag

13 years agoOPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag
Willy Tarreau [Sun, 13 May 2012 12:48:59 +0000 (14:48 +0200)] 
OPTIM/MEDIUM: stream_interface: add a new SI_FL_NOHALF flag

This flag indicates that we're not interested in keeping half-open
connections on a stream interface. It has the benefit of allowing
the socket layer to cause an immediate write close when detecting
an incoming read close. This releases resources much faster and
saves one syscall (either a shutdown or setsockopt).

This flag is only set by HTTP on the interface going to the server
since we don't want to continue pushing data there when it has
closed.

Another benefit is that it responds with a FIN to a server's FIN
instead of responding with an RST as it used to, which is much
cleaner.

Performance gains of 7.5% have been measured on HTTP connection
rate on empty objects.

13 years agoOPTIM/MAJOR: ev_sepoll: process spec events after polled events
Willy Tarreau [Sun, 13 May 2012 07:42:26 +0000 (09:42 +0200)] 
OPTIM/MAJOR: ev_sepoll: process spec events after polled events

A suboptimal behaviour was appearing quite often with sepoll. When a
speculative write failed after a connect(), the socket was added to
the poll list using epoll_ctl(ADD). Then when epoll_wait() returned a
write event, the send() was performed and write event disabled, causing
it to get back to the spec list in order to be disabled later. But if
some new accept() did succeed in the same run, then fd_created was not
null, causing a new run of the spec list to happen. This run would then
detect the old event in STOP state and would remove it from the poll
list using epoll_ctl(DEL).

After this, process_session() enables reading on the FD, attempting
an speculative recv() which fails then adds it again using epoll_ctl(ADD)
to do it again. So the total sequence of syscalls looked like this :

connect(fd) = EAGAIN
send(fd) = EAGAIN
epoll_ctl(ADD(fd:OUT))
epoll_wait() = fd:OUT
send(fd) > 0
epoll_ctl(DEL(fd))
recv(fd) = EAGAIN
epoll_ctl(ADD(fd:IN))
recv(fd) > 0

In order to fix this stupid situation, we must compute the epoll_ctl()
parameters at the last moment, just before doing epoll_wait(). This is
what was done except that the spec events were processed just before doing
that without leaving time for the tasks to adjust the FDs if needed. This
is also the reason we have the re_poll_once label to try to catch new
events in case of a successful accept().

The new solution consists in doing the opposite :

  - compute epoll_ctl()
  - call epoll_wait()
  - call spec events

This significantly reduces the number of iterations on the spec events
and avoids a huge number of epoll_ctl() ping/pongs. The new sequence
above simply becomes :

connect(fd) = EAGAIN
send(fd) = EAGAIN
epoll_ctl(ADD(fd:OUT))
epoll_wait() = fd:OUT
send(fd) > 0
epoll_ctl(MOD(fd:IN))
recv(fd) > 0

Also, there is no need to re-run the spec events after an accept() as
it will automatically be detected in the spec list after a return from
polled events.

The gains are important, with up to 4.5% global performance increase in
connection rate on HTTP with small objects. The code is less tricky and
does not need anymore to skip epoll_wait() every other call, nor to
track the number of FDs newly created.

13 years agoOPTIM: proto_http: don't enable quick-ack on empty buffers
Willy Tarreau [Sun, 13 May 2012 06:44:16 +0000 (08:44 +0200)] 
OPTIM: proto_http: don't enable quick-ack on empty buffers

Commit 5e205524 was a bit overzealous by inconditionally enabling
quick ack when a request is not yet in the buffer, because it also
does so when nothing has been received yet, causing a useless ACK
to be emitted.

Improve the situation by doing this only if the input buffer is
empty (indicating that nothing was sent by the client).

In case of keep-alive, an empty buffer means we already have a
response in flight which will serve as an ACK.

13 years agoCLEANUP: fd: remove unused cb->b pointers in the struct fdtab
Willy Tarreau [Sat, 12 May 2012 22:35:44 +0000 (00:35 +0200)] 
CLEANUP: fd: remove unused cb->b pointers in the struct fdtab

These pointers were used to hold pointers to buffers in the past, but
since we introduced the stream interface, they're no longer used but
they were still sometimes set.

Removing them shrink the struct fdtab from 32 to 24 bytes on 32-bit machines,
and from 52 to 36 bytes on 64-bit machines, which is a significant saving. A
quick tests shows a steady 0.5% performance gain, probably due to the better
cache efficiency.

13 years agoMINOR: standard: add a new debug macro : fddebug()
Willy Tarreau [Sat, 12 May 2012 22:21:17 +0000 (00:21 +0200)] 
MINOR: standard: add a new debug macro : fddebug()

This macro is usable like printf but sends messages to fd #-1, which has no
visible effect but is easy to spot in strace. This is very useful to put
tracers at many points during debugging sessions.

13 years agoMEDIUM: session: add support for tunnel timeouts
Willy Tarreau [Sat, 12 May 2012 10:50:00 +0000 (12:50 +0200)] 
MEDIUM: session: add support for tunnel timeouts

Tunnel timeouts are used when TCP connections are forwarded, or
when forwarding upgraded HTTP connections (WebSocket) as well as
CONNECT requests to proxies.

This timeout allows long-lived sessions to be supported without
having to set large timeouts to normal requests.

13 years agoMINOR: session: call the socket layer init function when a session establishes
Willy Tarreau [Sat, 12 May 2012 06:08:09 +0000 (08:08 +0200)] 
MINOR: session: call the socket layer init function when a session establishes

In sess_establish, once we've prepared everythin, we can call the socket layer
init function. We pass an argument for targets which have one (eg: servers). At
the moment, the existing socket layers don't have init functions, but SSL will
need one.

13 years agoMAJOR: fd: remove the need for the socket layer to recheck the connection
Willy Tarreau [Fri, 11 May 2012 17:53:32 +0000 (19:53 +0200)] 
MAJOR: fd: remove the need for the socket layer to recheck the connection

Up to now, if an outgoing connection had no data to send, the socket layer
had to perform a connect() again to check for establishment. This is not
acceptable for SSL, and will cause problems with socketpair(). Some socket
layers will also need an initializer before sending data (eg: SSL).

The solution consists in moving the connect() test to the protocol layer
(eg: TCP) and to make it hold the fd->write callback until the connection
is validated. At this point, it will switch the write callback to the
socket layer's write function. In fact we need to hold both read and write
callbacks to ensure the socket layer is never called before being initialized.

This intermediate callback is used only if there is a socket init function
or if there are no data to send.

The socket layer does not have any code to check for connection establishment
anymore, which makes sense.

13 years agoMEDIUM: stream_interface: derive the socket operations from the target
Willy Tarreau [Fri, 11 May 2012 16:32:18 +0000 (18:32 +0200)] 
MEDIUM: stream_interface: derive the socket operations from the target

Instead of hard-coding sock_raw in connect_server(), we set this socket
operation at config parsing time. Right now, only servers and peers have
it. Proxies are still hard-coded as sock_raw. This will be needed for
future work on SSL which requires a different socket layer.

13 years agoMINOR: stream_interface: add an init callback to sock_ops
Willy Tarreau [Fri, 11 May 2012 16:38:44 +0000 (18:38 +0200)] 
MINOR: stream_interface: add an init callback to sock_ops

This will be needed for some socket layers such as SSL. It's not used
at the moment.

13 years agoCLEANUP: stream_interface: stop exporting socket layer functions
Willy Tarreau [Fri, 11 May 2012 15:47:17 +0000 (17:47 +0200)] 
CLEANUP: stream_interface: stop exporting socket layer functions

Similarly to the previous patch, we don't need the socket-layer functions
outside of stream_interface. They could even move to a file dedicated to
applets, though that does not seem particularly useful at the moment.

13 years agoCLEANUP: sock_raw: remove last references to stream_sock
Willy Tarreau [Fri, 11 May 2012 14:59:14 +0000 (16:59 +0200)] 
CLEANUP: sock_raw: remove last references to stream_sock

We also stop exporting all functions since they're not needed anymore outside
of sock_raw.c.

13 years agoBUG/MEDIUM: stream_interface: restore get_src/get_dst
Willy Tarreau [Fri, 11 May 2012 14:16:40 +0000 (16:16 +0200)] 
BUG/MEDIUM: stream_interface: restore get_src/get_dst

Commit e164e7a removed get_src/get_dst setting in the stream interfaces but
forgot to set it in proto_tcp. Get the feature back because we need it for
logging, transparent mode, ACLs etc... We now rely on the stream interface
direction to know what syscall to use.

One benefit of doing it this way is that we don't use getsockopt() anymore
on outgoing stream interfaces nor on UNIX sockets.