Commit Graph

670 Commits

Author SHA1 Message Date
Willy Tarreau
d6f087ea1c [BUG] fix truncated responses with sepoll
Due to the way Linux delivers EPOLLIN and EPOLLHUP, a closed connection
received after some server data sometimes results in truncated responses
if the client disconnects before server starts to respond. The reason
is that the EPOLLHUP flag is processed as an indication of end of
transfer while some data may remain in the system's socket buffers.

This problem could only be triggered with sepoll, although nothing should
prevent it from happening with normal epoll. In fact, the work factoring
performed by sepoll increases the risk that this bug appears.

The fix consists in making FD_POLL_HUP and FD_POLL_ERR sticky and that
they are only checked if FD_POLL_IN is not set, meaning that we have
read all pending data.

That way, the problem is definitely fixed and sepoll still remains about
17% faster than epoll since it can take into account all information
returned by the kernel.
2008-01-18 17:20:13 +01:00
Willy Tarreau
b881608e57 [BUILD] code did not build in full debug mode 2008-01-18 12:18:15 +01:00
Willy Tarreau
8b3977ffe3 [BUG] log response byte count, not request
Due to a shameless copy-paste typo, the number of bytes logged was
from the request and not the response. This bug has been present
for a long time.
2008-01-18 11:16:32 +01:00
Willy Tarreau
ced27013b6 [DOC] added documentation about HTTP header manipulations
This section has been inserted before the logging section.
2008-01-17 20:35:34 +01:00
Willy Tarreau
303c035725 [DOC] document all req* and rsp* keywords. 2008-01-17 19:01:39 +01:00
Willy Tarreau
198a744e1d [DOC] all server parameters have been documented 2008-01-17 12:05:32 +01:00
Willy Tarreau
eabeafaa21 [DOC] added "server", "source" and "stats" keywords
The documentation now lists all keywords except the req* and rsp*. The
"server" keyword has been documented for mandatory parameters. Specific
settings are still waiting to be written in a dedicated section.
2008-01-16 16:17:06 +01:00
Willy Tarreau
4864c35209 [BUG] build failed on CONFIG_HAP_LINUX_TPROXY without CONFIG_HAP_CTTPROXY
changed #ifdef
2008-01-14 16:36:15 +01:00
Willy Tarreau
e8c66afd41 [MEDIUM] fix server health checks source address selection
The source address selection for health checks did not consider
the new transparent proxy method. Rely on the same unified function
as the other connect() calls.

This patch also fixes a bug by which the proxy's source address was
ignored if cttproxy was used.
2008-01-13 18:40:14 +01:00
Willy Tarreau
c297b52df5 [BUG] fix overlapping server flags
Server flags SRV_GOINGDOWN, SRV_WARMINGUP were overlapping
SRV_TPROXY_*.
2008-01-13 18:12:24 +01:00
Willy Tarreau
786d1915b0 [BUG] use backend's source and not server's source with tproxy
copy-paste typo.
2008-01-13 18:10:06 +01:00
Willy Tarreau
0a45989de3 [MINOR] add transparent proxy support for balabit's Tproxy v4
Balabit's TPROXY version 4 which replaces CTTPROXY provides a similar
API to the previous proxy, but relies on IP_FREEBIND instead of
IP_TRANSPARENT. Let's add it.
2008-01-13 17:37:16 +01:00
Willy Tarreau
5b6995c31b [MEDIUM] add non-local bind to connect() on Linux
Using some Linux kernel patches which add the IP_TRANSPARENT
SOL_IP option , it is possible to bind to a non-local address
on without having resort to any sort of NAT, thus causing no
performance degradation.

This is by far faster and cleaner than the previous CTTPROXY
method. The code has been slightly changed in order to remain
compatible with CTTPROXY as a fallback for the new method when
it does not work.

It is not needed anymore to specify the outgoing source address
for connect, it can remain 0.0.0.0.
2008-01-13 16:31:17 +01:00
Willy Tarreau
b1e52e8c44 [MEDIUM] support fully transparent proxy on Linux (USE_LINUX_TPROXY)
Using some Linux kernel patches, it is possible to redirect non-local
traffic to local sockets when IP forwarding is enabled. In order to
enable this option, we introduce the "transparent" option keyword on
the "bind" command line. It will make the socket reachable by remote
sources even if the destination address does not belong to the machine.
2008-01-13 14:49:51 +01:00
Willy Tarreau
fe10a0619d [BUG] connect_server: server might not exist when sending error report
In connect_server(), we may send an alert with the server name while
the server might not exist, eg in dispatch mode.
2008-01-12 22:22:34 +01:00
Willy Tarreau
844e3c53da [DOC] added documentation for "option tcplog" to "use_backend"
- options tcplog, tcpsplice and transparent have been documented.
- keywords "srvtimeout", "timeout queue", "timeout server" and
  "timeout tarpit" have been documented
- keywords "transparent" and "use_backend" have been documented

Only "server", "source" and "stats *" remain undocumented
2008-01-11 16:28:18 +01:00
Willy Tarreau
a453bddac2 [DOC] document options nolinger to ssl-hello-chk
Options nolinger, persist, smtpchk and ssl-hello-chk have been
documented. All keywords and options up to and including option
tcpka are now documented.
2008-01-08 19:50:52 +01:00
Willy Tarreau
00559e7117 [BUG] fix typo in redispatched connection
a copy-paste typo was present in the reconnection code responsible
for respatching. The client's FSM would not be re-evaluated if an
error occurred. It looks harmless but better fix it.
2008-01-06 23:46:19 +01:00
Willy Tarreau
541b5c24ca [MEDIUM] add a turn-around state of one second after a connection failure
Several users have complained that when haproxy gets a connection
failure due to an active reject from a server, it immediately
retries, often leading to the same situation being repeated until
the retry counter reaches zero.

Now if a connection error shows up, a turn-around state of 1 second
is applied before retrying. This is performed by faking a connection
timeout in order not to touch much code. However, a cleaner method
would involve an extra state.
2008-01-06 23:34:21 +01:00
Krzysztof Piotr Oledzki
25b501a6b1 [MEDIUM]: Count retries and redispatches also for servers, fix redistribute_pending, extend logs, %d->%u cleanup
This patch extends a little previously added functionality to also
count retries and redispatches for servers. Now it is possible to know
which server causes redispatches as it is not always the same that takes
most retries.

While working with the code I found that redistribute_pending() does not increment
srv->redispatches && be->redispatches. I don't know how to test it but
I think the fix is correct. If not I can withdraw it.

I also extended logs to show how many retries were done and if redispatching
was necessary ('+'). I'm using an additional session flag SN_REDISP to match
redispatched connections. I had to rearrange all defines in session.h to make
more room for it.

The documentation about logs was also fixed a little (sorry, english only),
as current version uses totally different format. BTW: examples are still
outdated, maybe next time...

Finally, I changed %d -> %u for retries/redispatches as those variables
are declared as unsigned.
2008-01-06 16:43:05 +01:00
Willy Tarreau
98937b8757 [BUG] increment server connections for each connect()
It was abnormal to see more connect errors than connect attempts.
This was caused by the fact that the server's connection count was
not incremented for failed connect() attempts.

Now the per-server connections are correctly incremented for each
connect() attempt. This includes the retries too. The number of
connections effectively served by a server will then be :

   srv->cum_sess - srv->errors - srv->warnings
2008-01-06 15:43:38 +01:00
Willy Tarreau
51c9bde060 [MINOR] tarpit timeout is also allowed in backends
Since the tarpit action may be set in backends too, its timeout
must be configurable there.
2008-01-06 13:40:03 +01:00
Willy Tarreau
036fae0ec9 [MEDIUM] introduce "timeout http-request" in frontends
In order to offer DoS protection, it may be required to lower the maximum
accepted time to receive a complete HTTP request without affecting the client
timeout. This helps protecting against established connections on which
nothing is sent. The client timeout cannot offer a good protection against
this abuse because it is an inactivity timeout, which means that if the
attacker sends one character every now and then, the timeout will not
trigger. With the HTTP request timeout, no matter what speed the client
types, the request will be aborted if it does not complete in time.
2008-01-06 13:24:40 +01:00
Willy Tarreau
a0250ba38d [OPTIM] introduce global parameter "tune.maxaccept"
This new parameter makes it possible to override the default
number of consecutive incoming connections which can be
accepted on a socket. By default it is not limited on single
process mode, and limited to 8 in multi-process mode.
2008-01-06 11:22:57 +01:00
Willy Tarreau
c73ce2b111 [MINOR] add support for the "backlog" parameter
Add the "backlog" parameter to frontends, to give hints to
the system about the approximate listen backlog desired size.

In order to protect against SYN flood attacks, one solution is
to increase the system's SYN backlog size. Depending on the
system, sometimes it is just tunable via a system parameter,
sometimes it is not adjustable at all, and sometimes the system
relies on hints given by the application at the time of the
listen() syscall. By default, HAProxy passes the frontend's
maxconn value to the listen() syscall. On systems which can
make use of this value, it can sometimes be useful to be able
to specify a different value, hence this backlog parameter.
2008-01-06 10:55:10 +01:00
Willy Tarreau
c27debfe56 [DOC] document options forwardfor to logasap
Options forwardfor, http_proxy, httpchk, httpclose, httplog and logasap
have been documented.
2008-01-06 08:57:02 +01:00
Willy Tarreau
a8efd362b2 [STATS] add support for "show info" on the unix socket
It is sometimes required to know some informations such as the
process uptime when consulting statistics. This patch adds the
"show info" command to query those informations on the UNIX
socket.
2008-01-03 10:19:15 +01:00
Willy Tarreau
9f2b73064b [BUILD] major rework of the GNU Makefile
The build process was getting annoying under some conditions,
especially on platforms which are used to set CFLAGS, as well
as those which set a lot of complex defines. The new Makefile
takes care of this situation by not mixing TARGET, CPU and user
values, and by making privileging the pre-setting of common
variables with the ability to override them.

Now CFLAGS and LDFLAGS are set by default and may be overridden
without the risk of breaking useful defines. Options are better
dealt with, and as a bonus, it was possible to merge the FreeBSD
and OpenBSD targets into the common GNU Makefile.

The report of build options by "haproxy -vv" has been slightly
adapted to the new mode. Options implied by architecture are not
reported, only user-specified options are. It is also possible to
add options which will not be reported in order not to mangle the
output when specifying dirty informations such as URLs...

The Makefile was copiously documented and it should be easier to
build for any target now. Backwards compatibility with older
build processes was kept, and warnings are emitted for deprecated
build options.
2008-01-02 20:48:34 +01:00
Willy Tarreau
bf1f816ecf [DOC] document more options
All options up to and including "forceclose" have been documented.
2007-12-28 17:42:56 +01:00
Willy Tarreau
2769aa050a [DOC] large update to the configuration manual
Keywords from "errorloc" to "monitor-uri" inclusive have been added.
Some fixes applied too.
2007-12-27 18:26:09 +01:00
Krzysztof Oledzki
336d475d13 [MEDIUM]: Inversion for options
This patch adds a possibility to invert most of available options by
introducing the "no" keyword, available as an additional prefix.
If it is found arguments are shifted left and an additional flag (inv)
is set.

It allows to use all options from a current defaults section, except
the selected ones, for example:

-- cut here --
defaults
        contimeout      4200
        clitimeout      50000
        srvtimeout      40000
        option contstats

listen stats 1.2.3.4:80
	no option contstats
-- cut here --

Currenly inversion works only with the "option" keyword.

The patch also moves last_checks calculation at the end of the readcfgfile()
function and changes "PR_O_FORCE_CLO | PR_O_HTTP_CLOSE" into "PR_O_FORCE_CLO"
in cfg_opts so it is possible to invert forceclose without breaking httpclose
(and vice versa) and to invert tcpsplice in one proxy but to keep a proper
last_checks value when tcpsplice is used in another proxy. Now, the code
checks for PR_O_FORCE_CLO everywhere it checks for PR_O_HTTP_CLOSE.

I also decided to depreciate "redisp" and "redispatch" keywords as it is IMHO
better to use "option redispatch" which can be inverted.

Some useful documentation were added and at the same time I sorted
(alfabetically) all valid options both in the code and the documentation.
2007-12-27 11:52:06 +01:00
Willy Tarreau
0ba2750591 [DOC] big update to the configuration manual
New in this version is a small intro to HTTP, then a detailed
explanation of the following keywords :

  acl, appsession, balance, bind, block, capture cookie,
  capture request header, capture response header, clitimeout,
  contimeout, cookie, default_backend, disabled, enabled, errorfile,
  http-check disable-on-404, monitor fail, option contstats,
  timeout client, timeout clitimeout, timeout connect,
  timeout contimeout.

Others will be alphabetically added.
2007-12-24 16:55:16 +01:00
Willy Tarreau
e13e9251a6 [BUG] hot reconfiguration failed because of a wrong error check
The error check in return of start_proxies checked for exact ERR_RETRYABLE
but did not consider the return as a bit field. The function returned both
ERR_RETRYABLE and ERR_ALERT, hence the problem.
2007-12-20 23:09:54 +01:00
Willy Tarreau
4009f016c2 [BUG] transparent proxy address was ignored in backend
When the "source x.x.x.x usesrc y.y.y.y" statement was present in a
backend, the y.y.y.y address was fetched from the server instead of
the backend.
2007-12-14 19:54:43 +01:00
Willy Tarreau
e5b77e82c7 [RELEASE] Released version 1.3.14
Released version 1.3.14 with the following main changes :
    - New option http_proxy (Alexandre Cassen)
    - add support for "maxqueue" to limit server queue overload (Elijah Epifanov)
    - Check for duplicated conflicting proxies (Krzysztof Oledzki)
    - stats: report server and backend cumulated downtime (Krzysztof Oledzki)
    - use backends only with use_backend directive (Krzysztof Oledzki)
    - Handle long lines properly (Krzysztof Oledzki)
    - Implement and use generic findproxy and relax duplicated proxy check (Krzysztof Oledzki)
    - continous statistics (Krzysztof Oledzki)
    - add support for logging via a UNIX socket (Robert Tsai)
    - fix error checking in strl2ic/strl2uic()
    - fix calls to localtime()
    - provide easier-to-use ultoa_* functions
    - provide easy-to-use limit_r and LIM2A* macros
    - add a simple test for the status page
    - move error codes to common/errors.h
    - silent warning about LIST_* being redefined on OpenBSD
    - add socket address length to the protocols
    - group PR_O_BALANCE_* bits into a checkable value
    - externalize the "balance" option parser to backend.c
    - introduce the "url_param" balance method
    - make default_backend work in TCP mode too
    - disable warning about localtime_r on Solaris
    - adjust error messages about conflicting proxies
    - avoid calling some layer7 functions if not needed
    - simplify error path in event_accept()
    - add an options field to the listeners
    - added a new state to listeners
    - unbind_listener() must use fd_delete() and not close()
    - add a generic unbind_listener() primitive
    - add a generic delete_listener() primitive
    - add a generic unbind_all_listeners() primitive
    - create proto_tcp and move initialization of proxy listeners
    - stats: report numerical process ID, proxy ID and server ID
    - relative_pid was not initialized
    - missing header names in raw stats output
    - fix missing parenthesis in check_response_for_cacheability
    - small optimization on session_process_counters()
    - merge ebtree version 3.0
    - make ebtree headers multiple-include compatible
    - ebtree: include config.h for REGPRM*
    - differentiate between generic LB params and map-specific ones
    - add a weight divisor to the struct proxy
    - implement the Fast Weighted Round Robin (FWRR) algo
    - include filltab25.c to experiment on FWRR for dynamic weights
    - merge test-fwrr.cfg to validate dynamic weights
    - move the load balancing algorithm to be->lbprm.algo
    - change server check result to a bit field
    - implement "http-check disable-on-404" for graceful shutdown
    - secure the calling conditions of ->set_server_status_{up,down}
    - report disabled servers as "NOLB" when they are still UP
    - document the "http-check disable-on-404" option
    - http-check disable-on-404 is not limited to HTTP mode
    - add a test file for disable-on-404
    - use distinct bits per load-balancing algorithm type
    - implement the slowstart parameter for servers
    - document the server's slowstart parameter
    - stats: report the server warm up status in a "throttle" column
    - fix 2 minor issues on AIX
    - add the "nbsrv" ACL verb
    - add the "fail" condition to monitor requests
    - remove a warning from gcc due to htons() in standard.c
    - fwrr: ensure that we never overflow in placements
    - store the build options to report with -vv
    - fix the status return of the init script (R.I. Pienaar)
    - stats: real time monitoring script for unix socket (Prizee)
    - document "nbsrv" and "monitor fail"
    - restrict the set of allowed characters for identifiers
    - implement a time parsing function
    - add support for time units in the configuration
    - add a bit of documentation about timers
    - introduce separation between contimeout, and tarpit + queue
    - introduce the "timeout" keyword
    - grouped all timeouts in one structure
    - slowstart is in ms, not seconds
    - slowstart: ensure we don't start with a null weight
    - report the number of times each server was selected
    - fix build on AIX due to recent log changes
    - fix build on Solaris due to recent log changes
2007-12-06 01:25:44 +01:00
Willy Tarreau
127f966f4b [BUILD] fix build on Solaris due to recent log changes
Solaris, as well as many other unixes doesn't know about sun_len
for UNIX domain sockets. It does not honnor the __SOCKADDR_COMMON
macro either. After looking at MacOS-X man (which is the same as
BSD man), OpenBSD man, and examples on the net, it appears that
those which support sun_len do not actually use it, or at least
ignore it as long as it's zero. Since all the sockaddr structures
are zeroed prior to being filled, it causes no problem not to set
sun_len, and this fixes build on other platforms.

Another problem on Solaris was that the "sun" name is already
defined as a macro returning a number, so it was necessary to
rename it.
2007-12-06 00:53:51 +01:00
Willy Tarreau
019767b546 [BUILD] fix build on AIX due to recent log changes 2007-12-05 11:11:55 +01:00
Robert Tsai
81ae1953bf [MEDIUM] add support for logging via a UNIX socket
The code in haproxy-1.3.13.1 only supports syslogging to an internet
address. The attached patch:

 - Adds support for syslogging to a UNIX domain socket (e.g., /dev/log).
   If the address field begins with '/' (absolute file path), then
   AF_UNIX is used to construct the socket. Otherwise, AF_INET is used.

 - Achieves clean single-source build on both Mac OS X and Linux
   (sockaddr_in.sin_len and sockaddr_un.sun_len field aren't always present).

For handling sendto() failures in send_log(), it appears that the existing
code is fine (no need to close/recreate socket) for both UDP and UNIX-domain
syslog server. So I left things alone (did not close/recreate socket).
Closing/recreating socket after each failure would also work, but would lead
to increased amount of unnecessary socket creation/destruction if syslog is
temporarily unavailable for some reason (especially for verbose loggers).

Please consider this patch for inclusion into the upstream haproxy codebase.
2007-12-05 10:47:29 +01:00
Willy Tarreau
ddbb82ff47 [STATS] report the number of times each server was selected
One user reported that an indicator was missing in the statistics:
the number of times each server was selected by load balancing. It
is in fact the total number of sessions assigned to a server by the
load balancing algorithm. It should directly reflect the weight for
"fair" algorithms such as round-robin, since it will not account for
persistant connections.

It should help a lot tuning each server's weight depending on the
load it receives.
2007-12-05 10:34:49 +01:00
Willy Tarreau
5542af65dc [MEDIUM] slowstart: ensure we don't start with a null weight
Because of a divide, it was possible to have a null weight during
a slowstart, which is pretty annoying, especially with a single
server and a long slowstart.

Also, fix the way we report the values in the stats page to avoid
confusion.
2007-12-03 02:04:00 +01:00
Willy Tarreau
3259e3369e [BUG] slowstart is in ms, not seconds 2007-12-03 01:51:45 +01:00
Willy Tarreau
d7c30f9a8c [CLEANUP] grouped all timeouts in one structure
All known timeouts in a proxy have been grouped into a
"timeout" sub-structure.
2007-12-03 01:38:36 +01:00
Willy Tarreau
e219db7a46 [MEDIUM] introduce the "timeout" keyword
A new "timeout" keyword replaces old "{con|cli|srv}timeout", and
provides the ability to independantly set the following timeouts :

  - client
  - tarpit
  - queue
  - connect
  - server
  - appsession

Additionally, the "clitimeout", "contimeout" and "srvtimeout" values
are supported but deprecated. No warning is emitted yet when they are
used since the option is very new.

Other timeouts should follow soon now.
2007-12-03 01:30:13 +01:00
Willy Tarreau
1fa3126ec4 [MEDIUM] introduce separation between contimeout, and tarpit + queue
Now the connect timeout, tarpit timeout and queue timeout are
distinct. In order to retain compatibility with older versions,
if either queue or tarpit is left unset both in the proxy and
in the default proxy, then it is inherited from the connect
timeout as before.
2007-12-03 00:36:16 +01:00
Willy Tarreau
befdff11aa [DOC] add a bit of documentation about timers 2007-12-02 22:27:38 +01:00
Willy Tarreau
b3f32f5f8a [MEDIUM] add support for time units in the configuration
It is not always handy to manipulate large values exprimed
in milliseconds for timeouts. Also, some values are entered
in seconds (such as the stats refresh interval). This patch
adds support for time units. It knows about 'us', 'ms', 's',
'm', 'h', and 'd'. It automatically converts each value into
the caller's expected unit. Unit-less values are still passed
unchanged.

The unit must be passed as a suffix to the number. For instance:

     clitimeout 15m

If any character is not understood, an error is returned.
2007-12-02 22:15:14 +01:00
Willy Tarreau
a0d37b69ef [MINOR] implement a time parsing function
This new function accepts inputs in various default units, from
the microsecond to the day. It detects suffixes after numbers
and performs the appropriate conversions between the user's unit
and the program's unit, considering a unit-less number in the
default unit.
2007-12-02 22:00:35 +01:00
Willy Tarreau
2e74c3f202 [MEDIUM] restrict the set of allowed characters for identifiers
In order to avoid issues in the future, we want to restrict
the set of allowed characters for identifiers. Starting from
now, only A-Z, a-z, 0-9, '-', '_', '.' and ':' will be allowed
for a proxy, a server or an ACL name.

A test file has been added to check the restriction.
2007-12-02 18:45:09 +01:00
Willy Tarreau
c7246fcdf3 [DOC] document "nbsrv" and "monitor fail" 2007-12-02 17:31:20 +01:00
Willy Tarreau
240f9fd1bc [TESTS] stats: real time monitoring script for unix socket.
Julien Antony and Matthieu Huguet of Prizee provided this convenient
script to monitor activity via the unix socket. It requires presence
of the "socat" utility. Example of usage :

lb1:/home/scripts# ./stats_haproxy.sh -s prizee_media,FRONTEND
189 session/s (avg: 189 )       1040 concurrent sessions
182 session/s (avg: 185 )       1022 concurrent sessions
164 session/s (avg: 178 )       1015 concurrent sessions
175 session/s (avg: 177 )       1015 concurrent sessions
226 session/s (avg: 187 )       1031 concurrent sessions
252 session/s (avg: 198 )       1056 concurrent sessions
273 session/s (avg: 208 )       1072 concurrent sessions
268 session/s (avg: 216 )       1080 concurrent sessions
271 session/s (avg: 222 )       1131 concurrent sessions
241 session/s (avg: 224 )       1128 concurrent sessions
215 session/s (avg: 223 )       1136 concurrent sessions
206 session/s (avg: 221 )       1140 concurrent sessions
2007-12-02 14:11:36 +01:00