Commit Graph

1997 Commits

Author SHA1 Message Date
Willy Tarreau
96dd079b49 [BUG] proto_tcp: fix address binding on remote source
Mark Brooks reported that commit 1b4b7c broke tproxy in 1.5-dev6. Nick
Chalk tracked the issue down to a missing address family setting in
tcp_bind_socket() which resulted in a failure to use get_addr_len().
This issue is 1.5-specific.
2011-04-19 07:20:57 +02:00
Willy Tarreau
787aed5078 [DOC] fix minor typo in the "dispatch" doc
Bradley Falzon reported a left-over of a copy-paste from the "disabled"
keyword in the "dispatch" section.
2011-04-15 06:45:37 +02:00
Willy Tarreau
a164fb5721 [BUG] checks: http-check expect could fail a check on multi-packet responses
Christopher Blencowe reported that the httpchk_expect() function was
lacking a test for incomplete responses : if the server sends only the
headers in the first packet and the body in a subsequent one, there is
a risk that the check fails without waiting for more data. A failure
rate of about 1% was reported.

This fix must be backported to 1.4.
2011-04-13 09:32:41 +02:00
Willy Tarreau
04df1125cf [RELEASE] Released version 1.5-dev6
Released version 1.5-dev6 with the following main changes :
    - [BUG] stream_sock: use get_addr_len() instead of sizeof() on sockaddr_storage
    - [BUG] TCP source tracking was broken with IPv6 changes
    - [BUG] stick-tables did not work when converting IPv6 to IPv4
    - [CRITICAL] fix risk of crash when dealing with space in response cookies
2011-04-08 00:56:41 +02:00
Willy Tarreau
1fc1f45618 [CRITICAL] fix risk of crash when dealing with space in response cookies
When doing fix 24581bae02 to correctly handle
response cookies, an unfortunate typo was inserted in the less likely code
path, resulting in a risk of crash when cookie-based persistence is enabled
and the server emits a cookie with several spaces around the equal sign.

This bug was noticed during a code backport. Its effects were never reported
because this situation is very unlikely to appear, but it can be provoked on
purpose by the server.

This patch must be backported to 1.4 versions which contain the fix above
(anything > 1.4.8), and to similar 1.3 versions > 1.3.25. 1.5-dev versions
after 1.5-dev2 are affected too.
2011-04-08 00:50:36 +02:00
Willy Tarreau
442452034e [BUG] stick-tables did not work when converting IPv6 to IPv4
A stick-table of type IPv6 would store a wrong IPv4 address as the
result of an IPv6 to IPv4 conversion. This bug was introduced in
1.5-dev5.
2011-04-07 10:53:30 +02:00
Willy Tarreau
c9f6011760 [BUG] TCP source tracking was broken with IPv6 changes
John Helliwell reported a bug when using TCP source address
tracking on Solaris. The bug was introduced in haproxy 1.5-dev5.
2011-04-07 10:53:25 +02:00
Willy Tarreau
1b4b7ce6dd [BUG] stream_sock: use get_addr_len() instead of sizeof() on sockaddr_storage
John Helliwell reported a runtime issue on Solaris since 1.5-dev5. Traces
show that connect() returns EINVAL, which means the socket length is not
appropriate for the family. Solaris does not like being called with sizeof
and needs the address family's size on sockaddr_storage.

The fix consists in adding a get_addr_len() function which returns the
socket's address length based on its family. Tests show that this works
for both IPv4 and IPv6 addresses.
2011-04-05 16:56:50 +02:00
Willy Tarreau
b06ed2c6af [RELEASE] Released version 1.5-dev5
Released version 1.5-dev5 with the following main changes :
    - [BUG] standard: is_addr return value for IPv4 was inverted
    - [MINOR] update comment about IPv6 support for server
    - [MEDIUM] use getaddrinfo to resolve names if gethostbyname fail
    - [DOC] update IPv6 support for bind
    - [DOC] document IPv6 support for server
    - [DOC] fix a minor typo
    - [MEDIUM] IPv6 support for syslog
    - [DOC] document IPv6 support for syslog
    - [MEDIUM] IPv6 support for stick-tables
    - [DOC] document IPv6 support for stick-tables
    - [DOC] update ROADMAP file
    - [BUG] session: src_conn_cur was returning src_conn_cnt instead
    - [MINOR] frontend: add a make_proxy_line function
    - [MEDIUM] stream_sock: add support for sending the proxy protocol header line
    - [MEDIUM] server: add support for the "send-proxy" option
    - [DOC] update the spec on the proxy protocol
    - [BUILD] proto_tcp: fix build issue with CTTPROXY
    - [DOC] update ROADMAP file
    - [MEDIUM] config: rework the IPv4/IPv6 address parser to support host-only addresses
    - [MINOR] cfgparse: better report wrong listening addresses and make use of str2sa_range
    - [BUILD] add the USE_GETADDRINFO build option
    - [TESTS] provide a test case for various address formats
    - [BUG] session: conn_retries was not always initialized
    - [BUG] log: retrieve the target from the session, not the SI
    - [BUG] http: fix possible incorrect forwarded wrapping chunk size (take 2)
    - [MINOR] tools: add two macros MID_RANGE and MAX_RANGE
    - [BUG] http: fix content-length handling on 32-bit platforms
    - [OPTIM] buffers: uninline buffer_forward()
    - [BUG] stream_sock: fix handling for server side PROXY protocol
    - [MINOR] acl: add support for table_cnt and table_avl matches
    - [DOC] update ROADMAP file
2011-03-29 01:10:33 +02:00
David du Colombier
9a6d3c93de [DOC] document IPv6 support for stick-tables 2011-03-29 01:09:15 +02:00
David du Colombier
4f92d32004 [MEDIUM] IPv6 support for stick-tables
Since IPv6 is a different type than IPv4, the pattern fetch functions
src6 and dst6 were added. IPv6 stick-tables can also fetch IPv4 addresses
with src and dst. In this case, the IPv4 addresses are mapped to their
IPv6 counterpart, according to RFC 4291.
2011-03-29 01:09:14 +02:00
Willy Tarreau
be2e1d3ef4 [DOC] update ROADMAP file 2011-03-29 01:00:12 +02:00
Willy Tarreau
c735a0728e [MINOR] acl: add support for table_cnt and table_avl matches
Those trivial matches respectively return the number of entries used
in a stick-table and the number of entries still available in a table.
2011-03-29 00:57:02 +02:00
Willy Tarreau
68f49da972 [BUG] stream_sock: fix handling for server side PROXY protocol
Patch 5ab04ec47c was incomplete,
because if the first send() fails on an empty buffer, we fail
to rearm the polling and we can't establish the connection
anymore.

The issue was reported by Ben Timby who provided large amounts
of traces of various tests helping to reliably reproduce the issue.
2011-03-28 23:17:54 +02:00
David du Colombier
24bb5f504b [DOC] document IPv6 support for syslog 2011-03-28 18:47:16 +02:00
David du Colombier
11bcb6c4f5 [MEDIUM] IPv6 support for syslog 2011-03-28 18:45:15 +02:00
Willy Tarreau
0bc3493d2c [OPTIM] buffers: uninline buffer_forward()
Since the latest additions to buffer_forward(), it became too large for
inlining, so let's uninline it. The code size drops by 3kB. Should be
backported to 1.4 too.
2011-03-28 16:25:58 +02:00
Willy Tarreau
d8ee85a0a3 [BUG] http: fix content-length handling on 32-bit platforms
Despite much care around handling the content-length as a 64-bit integer,
forwarding was broken on 32-bit platforms due to the 32-bit nature of
the ->to_forward member of the "buffer" struct. The issue is that this
member is declared as a long, so while it works OK on 64-bit platforms,
32-bit truncate the content-length to the lower 32-bits.

One solution could consist in turning to_forward to a long long, but it
is used a lot in the critical path, so it's not acceptable to perform
all buffer size computations on 64-bit there.

The fix consists in changing the to_forward member to a strict 32-bit
integer and ensure in buffer_forward() that only the amount of bytes
that can fit into it is considered. Callers of buffer_forward() are
responsible for checking that their data were taken into account. We
arbitrarily ensure we never consider more than 2G at once.

That's the way it was intended to work on 32-bit platforms except that
it did not.

This issue was tracked down hard at Exosec with Bertrand Jacquin,
Thierry Fournier and Julien Thomas. It remained undetected for a long
time because files larger than 4G are almost always transferred in
chunked-encoded format, and most platforms dealing with huge contents
these days run on 64-bit.

The bug affects all 1.5 and 1.4 versions, and must be backported.
2011-03-28 16:25:16 +02:00
Willy Tarreau
d3db94399f [MINOR] tools: add two macros MID_RANGE and MAX_RANGE
Those will be used later, they return the largest and middle integer
possible for a given variable or type.
2011-03-28 15:55:43 +02:00
Willy Tarreau
26f0f17200 [BUG] http: fix possible incorrect forwarded wrapping chunk size (take 2)
Fix acd20f80 was incomplete, the computed "bytes" value was not used.

This fix must be backported to 1.4.
2011-03-27 20:00:03 +02:00
Willy Tarreau
7b7a8e9d83 [BUG] log: retrieve the target from the session, not the SI
Since we now have the copy of the target in the session, use it instead
of relying on the SI for it. The SI drops the target upon unregister()
so applets such as stats were logged as "NOSRV".
2011-03-27 19:53:06 +02:00
Willy Tarreau
0b3a411543 [BUG] session: conn_retries was not always initialized
Johannes Smith reported some wrong retries count in logs associated with bad
requests. The cause was that the conn_retries field in the stream interface
was only initialized when attempting to connect, but is used when logging,
possibly with an uninitialized value holding last connection's conn_retries.
This could have been avoided by making use of a stream interface initializer.

This bug is 1.5-specific.
2011-03-27 19:16:56 +02:00
Willy Tarreau
d3cff72fb6 [TESTS] provide a test case for various address formats 2011-03-23 22:49:57 +01:00
David du Colombier
a13d1b97c1 [DOC] fix a minor typo 2011-03-23 22:49:56 +01:00
David du Colombier
486df477e6 [DOC] document IPv6 support for server 2011-03-23 22:49:56 +01:00
David du Colombier
9c938daf69 [DOC] update IPv6 support for bind 2011-03-23 22:49:56 +01:00
Willy Tarreau
64bc40b654 [BUILD] add the USE_GETADDRINFO build option
This one is used to call getaddrinfo() to resolve IPv6 host names.
2011-03-23 22:49:56 +01:00
David du Colombier
d5f4328efd [MEDIUM] use getaddrinfo to resolve names if gethostbyname fail
Function gethostbyname is deprecated since IEEE Std 1003.1-2008 and
was replaced by getaddrinfo (available since IEEE Std 1003.1-2004).
Contrary to gethostbyname, getaddrinfo is specified to support both
IPv4 and IPv4 addresses.
Since some libc doesn't handle getaddrinfo properly, constant
USE_GETADDRINFO must be defined at compile time to enable use of
getaddrinfo.
2011-03-23 22:49:55 +01:00
Willy Tarreau
2dff0c28e8 [MINOR] cfgparse: better report wrong listening addresses and make use of str2sa_range
It's always been a mess to debug wrong listening addresses because
the parsing function does not indicate the file and line number. Now
it does. Since the code was almost a duplicate of str2sa_range, it
now makes use of it and has been sensibly reduced.
2011-03-23 22:49:55 +01:00
David du Colombier
9842ff1ae6 [MINOR] update comment about IPv6 support for server 2011-03-23 22:49:55 +01:00
Willy Tarreau
fab5a43726 [MEDIUM] config: rework the IPv4/IPv6 address parser to support host-only addresses
The parser now distinguishes between pure addresses and address:port. This
is useful for some config items where only an address is required.

Raw IPv6 addresses are now parsed, but IPv6 host name resolution is still not
handled (gethostbyname does not resolve IPv6 names to addresses).
2011-03-23 19:01:18 +01:00
David du Colombier
64e9c90e69 [BUG] standard: is_addr return value for IPv4 was inverted 2011-03-22 14:39:16 +01:00
Willy Tarreau
1bd53be25c [DOC] update ROADMAP file 2011-03-22 14:38:00 +01:00
Willy Tarreau
6f831b446c [BUILD] proto_tcp: fix build issue with CTTPROXY
Recent sockaddr_storage changes broke the almost unused cttproxy code.
Fix is obvious.
2011-03-20 14:03:54 +01:00
Willy Tarreau
7f89851f54 [DOC] update the spec on the proxy protocol
We now support it on the server side too.
2011-03-20 11:53:50 +01:00
Willy Tarreau
5ab04ec47c [MEDIUM] server: add support for the "send-proxy" option
This option enables use of the PROXY protocol with the server, which
allows haproxy to transport original client's address across multiple
architecture layers.
2011-03-20 11:53:50 +01:00
Willy Tarreau
b22e55bc8f [MEDIUM] stream_sock: add support for sending the proxy protocol header line
Upon connection establishment, stream_sock is now able to send a PROXY
line before sending any data. Since it's possible that the buffer is
already full, and we don't want to allocate a block for that line, we
compute it on-the-fly when we need it. We just store the offset from
which to (re-)send from the end of the line, since it's assumed that
multiple outputs of the same proxy line will be strictly equivalent. In
practice, one call is enough. We just make sure to handle the case where
the first send() would indicate an incomplete output, eventhough it's
very unlikely to ever happen.
2011-03-20 10:16:46 +01:00
Willy Tarreau
a73fcaf424 [MINOR] frontend: add a make_proxy_line function
This function will build a PROXY protocol line header from two addresses
(IPv4 or IPv6). AF_UNIX family will be reported as UNKNOWN.
2011-03-20 10:15:22 +01:00
Willy Tarreau
1b6e608c11 [BUG] session: src_conn_cur was returning src_conn_cnt instead
Issue reported by Cory Forsyth and diagnosed by Cyril Bonté.
Just a plain stupid copy-paste of the wrong fetch function call.
2011-03-16 06:56:57 +01:00
Willy Tarreau
a1525cdf17 [DOC] update ROADMAP file 2011-03-16 06:54:36 +01:00
Willy Tarreau
e0052ccd27 [RELEASE] Released version 1.5-dev4
Released version 1.5-dev4 with the following main changes :
    - [MINOR] cfgparse: Check whether the path given for the stats socket actually fits into the sockaddr_un structure to avoid truncation.
    - [MINOR] unix sockets : inherits the backlog size from the listener
    - [CLEANUP] unix sockets : move create_uxst_socket() in uxst_bind_listener()
    - [DOC] fix a minor typo
    - [DOC] fix ignore-persist documentation
    - [MINOR] add warnings on features not compatible with multi-process mode
    - [BUG] http: fix http-pretend-keepalive and httpclose/tunnel mode
    - [MINOR] stats: add support for several packets in stats admin
    - [BUG] stats: admin commands must check the proxy state
    - [BUG] stats: admin web interface must check the proxy state
    - [MINOR] http: add pattern extraction method to stick on query string parameter
    - [MEDIUM] add internal support for IPv6 server addresses
    - [MINOR] acl: add be_id/srv_id to match backend's and server's id
    - [MINOR] log: add support for passing the forwarded hostname
    - [MINOR] log: ability to override the syslog tag
    - [MINOR] checks: add PostgreSQL health check
    - [DOC] update ROADMAP file
    - [BUILD] pattern: use 'int' instead of 'int32_t'
    - [OPTIM] linux: add support for bypassing libc to force using vsyscalls
    - [BUG] debug: report the correct poller list in verbose mode
    - [BUG] capture: do not capture a cookie if there is no memory left
    - [BUG] appsession: fix possible double free in case of out of memory
    - [CRITICAL] cookies: mixing cookies in indirect mode and appsession can crash the process
    - [BUG] http: correctly update the header list when removing two consecutive headers
    - [BUILD] add the CPU=native and ARCH=32/64 build options
    - [BUILD] add -fno-strict-aliasing to fix warnings with gcc >= 4.4
    - [CLEANUP] hash: move the avalanche hash code globally available
    - [MEDIUM] hash: add support for an 'avalanche' hash-type
    - [DOC] update roadmap file
    - [BUG] http: do not re-enable the PROXY analyser on keep-alive
    - [OPTIM] http: don't send each chunk in a separate packet
    - [DOC] fix minor typos reported recently in the peers section
    - [DOC] fix another typo in the doc
    - [MINOR] stats: report HTTP message state and buffer flags in error dumps
    - [BUG] http chunking: don't report a parsing error on connection errors
    - [BUG] stream_interface: truncate buffers when sending error messages
    - [MINOR] http: support wrapping messages in error captures
    - [MINOR] http: capture incorrectly chunked message bodies
    - [MINOR] stats: add global event ID and count
    - [BUG] http: analyser optimizations broke pipelining
    - [CLEANUP] frontend: only apply TCP-specific settings to TCP/TCP6 sockets
    - [BUG] http: fix incorrect error reporting during data transfers
    - [CRITICAL] session: correctly leave turn-around and queue states on abort
    - [BUG] session: release slot before processing pending connections
    - [MINOR] tcp: add support for dynamic MSS setting
    - [BUG] stick-table: correctly terminate string keys during lookups
    - [BUG] acl: fix handling of empty lines in pattern files
    - [BUG] stick-table: use the private buffer when padding strings
    - [BUG] ebtree: fix ebmb_lookup() with len smaller than the tree's keys
    - [OPTIM] ebtree: ebmb_lookup: reduce stack usage by moving the return code out of the loop
    - [OPTIM] ebtree: inline ebst_lookup_len and ebis_lookup_len
    - [REVERT] undo the stick-table string key lookup fixes
    - [MINOR] http: improve url_param pattern extraction to ignore empty values
    - [BUILD] frontend: shut a warning with TCP_MAXSEG
    - [BUG] http: update the header list's tail when removing the last header
    - [DOC] fix minor typo in the proxy protocol doc
    - [DOC] fix typos (http-request instead of http-check)
    - [BUG] http: use correct ACL pointer when evaluating authentication
    - [BUG] cfgparse: correctly count one socket per port in ranges
    - [BUG] startup: set the rlimits before binding ports, not after.
    - [BUG] acl: srv_id must return no match when the server is NULL
    - [MINOR] acl: add ability to check for internal response-only parameters
    - [MINOR] acl: srv_id is only valid in responses
    - [MINOR] config: warn if response-only conditions are used in "redirect" rules
    - [BUG] acl: fd leak when reading patterns from file
    - [DOC] fix minor typo in "usesrc"
    - [BUG] http: fix possible incorrect forwarded wrapping chunk size
    - [BUG] http: fix computation of message body length after forwarding has started
    - [BUG] http: balance url_param did not work with first parameters on POST
    - [TESTS] update the url_param regression test to test check_post too
    - [DOC] update ROADMAP
    - [DOC] internal: reflect the fact that SI_ST_ASS is transient
    - [BUG] config: don't crash on empty pattern files.
    - [MINOR] stream_interface: make use of an applet descriptor for IO handlers
    - [REORG] stream_interface: move the st0, st1 and private members to the applet
    - [REORG] stream_interface: split the struct members in 3 parts
    - [REORG] session: move client and server address to the stream interface
    - [REORG] tcp: make tcpv4_connect_server() take the target address from the SI
    - [MEDIUM] stream_interface: store the target pointer and type
    - [CLEANUP] stream_interface: remove the applet.handler pointer
    - [MEDIUM] log: take the logged server name from the stream interface
    - [CLEANUP] session: remove data_source from struct session
    - [CLEANUP] stats: make all dump functions only rely on the stream interface
    - [REORG] session: move the data_ctx struct to the stream interface's applet
    - [MINOR] proxy: add PR_O2_DISPATCH to detect dispatch mode
    - [MINOR] cfgparse: only keep one of dispatch, transparent, http_proxy
    - [MINOR] session: add a pointer to the new target into the session
    - [MEDIUM] session: remove s->prev_srv which is not needed anymore
    - [CLEANUP] stream_interface: use inline functions to manipulate targets
    - [MAJOR] session: remove the ->srv pointer from struct session
    - [MEDIUM] stats: split frontend and backend stats
    - [MEDIUM] http: always evaluate http-request rules before stats http-request
    - [REORG] http: move the http-request rules to proto_http
    - [BUG] http: stats were not incremented on http-request deny
    - [MINOR] checks: report it if checks fail due to socket creation error
2011-03-13 22:15:02 +01:00
Willy Tarreau
d11ad78c26 [MINOR] checks: report it if checks fail due to socket creation error
If the check fails for a low-level socket error (eg: address family not
supportd), we currently ignore the status. We must report the error and
declare a failed health check in this case. The only real reason for this
would be when an IPv6 check is required on an IPv4-only system.
2011-03-13 22:12:54 +01:00
Willy Tarreau
6da0f6d6dd [BUG] http: stats were not incremented on http-request deny
A counter increase was missing here.
This should be backported to 1.4 with care, as the code has changed a bit.
2011-03-13 22:00:24 +01:00
Willy Tarreau
ff011f26e9 [REORG] http: move the http-request rules to proto_http
And also rename "req_acl_rule" "http_req_rule". At the beginning that
was a bit confusing to me, especially the "req_acl" list which in fact
holds what we call rules. After some digging, it appeared that some
part of the code is 100% HTTP and not just related to authentication
anymore, so let's move that part to HTTP and keep the auth-only code
in auth.c.
2011-03-13 22:00:24 +01:00
Willy Tarreau
f68a15a951 [MEDIUM] http: always evaluate http-request rules before stats http-request
Right now, http-request rules are not evaluated if the URL matches the
stats request. This is quite unexpected. For instance, in the config
below, an abuser present in the abusers list will not be prevented access
to the stats.

   listen pub
        bind :8181
	acl abuser src -f abusers.lst
        http-request deny if abuser
        stats uri /stats

It is not a big deal but it's not documented as such either. For 1.5, let's
have both lists be evaluated in turn, until one blocks. For 1.4 we'll simply
update the doc to indicate that.

Also instead of duplicating the code, the patch factors out the list walking
code. The HTTP auth has been moved slightly earlier, because it was set after
the header addition code, but we don't need to add headers to a request we're
dropping.
2011-03-13 22:00:24 +01:00
Willy Tarreau
7d0aaf39d1 [MEDIUM] stats: split frontend and backend stats
It's very annoying that frontend and backend stats are merged because we
don't know what we're observing. For instance, if a "listen" instance
makes use of a distinct backend, it's impossible to know what the bytes_out
means.

Some points take care of not updating counters twice if the backend points
to the frontend, indicating a "listen" instance. The thing becomes more
complex when we try to add support for server side keep-alive, because we
have to maintain a pointer to the backend used for last request, and to
update its stats. But we can't perform such comparisons anymore because
the counters will not match anymore.

So in order to get rid of this situation, let's have both frontend AND
backend stats in the "struct proxy". We simply update the relevant ones
during activity. Some of them are only accounted for in the backend,
while others are just for frontend. Maybe we can improve a bit on that
later, but the essential part is that those counters now reflect what
they really mean.
2011-03-13 22:00:23 +01:00
David du Colombier
6f5ccb1589 [MEDIUM] add internal support for IPv6 server addresses
This patch turns internal server addresses to sockaddr_storage to
store IPv6 addresses, and makes the connect() function use it. This
code already works but some caveats with getaddrinfo/gethostbyname
still need to be sorted out while the changes had to be merged at
this stage of internal architecture changes. So for now the config
parser will not emit an IPv6 address yet so that user experience
remains unchanged.

This change should have absolutely zero user-visible effect, otherwise
it's a bug introduced during the merge, that should be reported ASAP.
2011-03-13 22:00:12 +01:00
Willy Tarreau
827aee913f [MAJOR] session: remove the ->srv pointer from struct session
This one has been removed and is now totally superseded by ->target.
To get the server, one must use target_srv(&s->target) instead of
s->srv now.

The function ensures that non-server targets still return NULL.
2011-03-10 23:32:17 +01:00
Willy Tarreau
9e000c6ec8 [CLEANUP] stream_interface: use inline functions to manipulate targets
The connection target involves a type and a union of pointers, let's
make the code cleaner using simple wrappers.
2011-03-10 23:32:17 +01:00
Willy Tarreau
3d80d911aa [MEDIUM] session: remove s->prev_srv which is not needed anymore
s->prev_srv is used by assign_server() only, but all code paths leading
to it now take s->prev_srv from the existing s->srv. So assign_server()
can do that copy into its own stack.

If at one point a different srv is needed, we still have a copy of the
last server on which we failed a connection attempt in s->target.
2011-03-10 23:32:16 +01:00