Commit Graph

2646 Commits

Author SHA1 Message Date
Willy Tarreau
74beec32a5 REORG: connection: rename app_cb "data"
Now conn->data will designate the data layer which is the client for
the transport layer. In practice it's the stream interface and will
soon also be the health checks.
2012-10-04 22:26:10 +02:00
Willy Tarreau
f7bc57ca6e REORG: connection: rename the data layer the "transport layer"
While working on the changes required to make the health checks use the
new connections, it started to become obvious that some naming was not
logical at all in the connections. Specifically, it is not logical to
call the "data layer" the layer which is in charge for all the handshake
and which does not yet provide a data layer once established until a
session has allocated all the required buffers.

In fact, it's more a transport layer, which makes much more sense. The
transport layer offers a medium on which data can transit, and it offers
the functions to move these data when the upper layer requests this. And
it is the upper layer which iterates over the transport layer's functions
to move data which should be called the data layer.

The use case where it's obvious is with embryonic sessions : an incoming
SSL connection is accepted. Only the connection is allocated, not the
buffers nor stream interface, etc... The connection handles the SSL
handshake by itself. Once this handshake is complete, we can't use the
data functions because the buffers and stream interface are not there
yet. Hence we have to first call a specific function to complete the
session initialization, after which we'll be able to use the data
functions. This clearly proves that SSL here is only a transport layer
and that the stream interface constitutes the data layer.

A similar change will be performed to rename app_cb => data, but the
two could not be in the same commit for obvious reasons.
2012-10-04 22:26:09 +02:00
Willy Tarreau
6f5d141149 MEDIUM: raw_sock: improve connection error reporting
When a connection setup is pending and we receive an error without a
POLL_IN flag, we're certain there will be nothing to read from it and
we can safely report an error without attempting a recv() call. This
will be significantly better for health checks which will avoid a useless
recv() on all failed checks.
2012-10-04 22:26:09 +02:00
Willy Tarreau
c0e98868fe MINOR: raw_sock: always report asynchronous connection errors
Depending on the pollers used, a connection error may be notified
with POLLOUT|POLLERR|POLLHUP. POLLHUP by itself is enough for the
connection handler to call the read actor, which would only consider
this flag as a good indication of a hangup, without considering the
POLLERR flag.

In order to address this, we directly jump to the read0 label if
POLLERR was not set.

This will be important with health checks as we don't want to believe
a connection was properly established when it's not the case !
2012-10-04 22:26:09 +02:00
Willy Tarreau
8c89c2059f MINOR: buffers: add a few functions to write chars, strings and blocks
bo_put{chr,blk,str,chk} are used to write data on the output of a buffer.
Output is truncated if the buffer is not large enough.
2012-10-04 22:26:09 +02:00
Willy Tarreau
c39b0d17f2 MINOR: signal: really ignore signals configured with no handler
Until now, signals configured with no handler were still enabled and
ignored upon signal reception. Until now it was not an issue but with
SSL causing many EPIPE all the time, it becomes obvious that signal
processing comes with a cost. So set the handler to SIG_IGN when the
function is NULL.
2012-10-04 22:26:09 +02:00
Willy Tarreau
f8cfa447c6 BUG/MINOR: epoll: correctly disable FD polling in fd_rem()
When calling fd_rem(), the polling was not correctly disabled because the
->prev state was set to zero instead of the previous value. fd_rem() is
very rarely used, only just before closing a socket.

The effect is that upon an error reported at the connection level, if the
task assigned to the connection was too slow to be woken up because of too
many other tasks in the run queue, the FD was still not disabled and caused
the connection handler to be called again with the same event until the task
was finally executed to close the fd.

This issue only affects the epoll poller, not the sepoll variant nor any of
the other ones.

It was already present in 1.4 and even 1.3 with the same almost unnoticeable
effects. The bug can in fact only be discovered during development where it
emphasizes other bugs.

It should be backported anyway.
2012-10-04 22:26:09 +02:00
Willy Tarreau
050536d582 MEDIUM: proxy: add the global frontend to the list of normal proxies
Since recent changes on the global frontend, it was not possible anymore
to soft-reload a process which had a stats socket because the socket would
not be disabled upon reload. The only solution to this endless madness is
to have the global frontend part of normal proxies.

Since we don't want to get an ID that shifts all other proxies and causes
trouble in deployed environments, we assign it ID #0 which other proxies
can't grab, and we don't report it in the stats pages.
2012-10-04 08:58:23 +02:00
Willy Tarreau
b3fb60bdcd BUG/MEDIUM: listener: don't pause protocols that do not support it
Pausing a UNIX_STREAM socket results in a major pain because the socket
does not correctly resume, it wakes poll() but return EAGAIN on accept(),
resulting in a busy loop. So let's only pause protocols that support it.

This issues has existed since UNIX sockets were introduced on bind lines.
2012-10-04 08:58:21 +02:00
Willy Tarreau
8113a5d78f BUG/MINOR: config: use a copy of the file name in proxy configurations
Each proxy contains a reference to the original config file and line
number where it was declared. The pointer used is just a reference to
the one passed to the function instead of being duplicated. The effect
is that it is not valid anymore at the end of the parsing and that all
proxies will be enumerated as coming from the same file on some late
configuration errors. This may happen for exmaple when reporting SSL
certificate issues.

By copying using strdup(), we avoid this issue.

1.4 has the same issue, though no report of the proxy file name is done
out of the config section. Anyway a backport is recommended to ease
post-mortem analysis.
2012-10-04 08:13:32 +02:00
Willy Tarreau
d1a33e35fb BUG/MEDIUM: proxy: must not try to stop disabled proxies upon reload
Hervé Commowick reported an issue : haproxy dies in a segfault during a
soft restart if it tries to pause a disabled proxy. This is because disabled
proxies have no management task so we must not wake the task up. This could
easily remain unnoticed since the old process was expected to go away, so
having it go away faster was not really troubling. However, with sync peers,
it is obvious that there is no peer sync during this reload.

This issue has been introduced in 1.5-dev7 with the removal of the
maintain_proxies() function. No backport is needed.
2012-10-04 00:20:55 +02:00
Willy Tarreau
8923019a1d BUG/MINOR: ssl: report the L4 connection as established when possible
If we get an SSL error during the handshake, we at least try to see
if a syscall reported an error or not. In case of an error, it generally
means that the connection failed. If there is no error, then the connection
established successfully.

The difference is important for health checks which report the precise cause
to the logs and to the stats.
2012-10-02 19:54:38 +02:00
Emeric Brun
051cdab68b BUG/MINOR: build: Fix compilation issue on openssl 0.9.6 due to missing CRL feature. 2012-10-02 19:54:38 +02:00
Emeric Brun
561e574e2f BUG/MINOR: ssl: Fix CRL check was not enabled when crlfile was specified. 2012-10-02 16:05:51 +02:00
Emeric Brun
90ad8727dd DOC: ssl: add 'no-tls-tickets' statement documentation.
Disables the stateless session resumption (RFC 5077 TLS Ticket
extension) and force to use stateful session resumption. Stateless
session resumption is more expensive in CPU usage.
2012-10-02 16:05:35 +02:00
Emeric Brun
2d0c482682 MINOR: ssl: add statement 'no-tls-tickets' on bind to disable stateless session resumption
Disables the stateless session resumption (RFC 5077 TLS Ticket extension)
and force to use stateful session resumption.
Stateless session resumption is more expensive in CPU usage.
2012-10-02 16:05:33 +02:00
Emeric Brun
c6678e21bb MEDIUM: config: authorize frontend and listen without bind.
This allows to easily add/remove "bind" entries to a frontend without
being forced to remove it when the last entry is temporarily removed.
While "disabled" may sometimes work in a frontend, it becomes trickier
on "listen" sections which can also hold servers and be referenced by
other frontends.

Note that a "listen" section with no "bind" is equivalent to a "backend"
section.

Configs without any listeners are still reported as invalid and refuse
to load.
2012-10-02 08:34:39 +02:00
Emeric Brun
f5da49392a DOC: ssl : add statements 'notlsv11' and 'notlsv12' and rename 'notlsv1' to 'notlsv10'.
This applies both to "bind" and "server" statements.
2012-10-02 08:34:38 +02:00
Emeric Brun
c0ff4924c0 MINOR: ssl : add statements 'notlsv11' and 'notlsv12' and rename 'notlsv1' to 'notlsv10'.
This is because "notlsv1" used to disable TLSv1.0 only and had no effect
on v1.1/v1.2. so better have an option for each version. This applies both
to "bind" and "server" statements.
2012-10-02 08:34:38 +02:00
Emeric Brun
9faf071acb MINOR: ssl: add build param USE_PRIVATE_CACHE to build cache without shared memory
It removes dependencies with futex or mutex but ssl performances decrease
using nbproc > 1 because switching process force session renegotiation.

This can be useful on small systems which never intend to run in multi-process
mode.
2012-10-02 08:34:38 +02:00
Emeric Brun
4b3091e54e MINOR: ssl: disable shared memory and locks on session cache if nbproc == 1
We don't needa to lock the memory when there is a single process. This can
make a difference on small systems where locking is much more expensive than
just a test.
2012-10-02 08:34:38 +02:00
Emeric Brun
3603fbe0af DOC: ssl: add fetches and ACLs 'ssl_verify_crterr', 'ssl_verify_caerr', and 'ssl_verify_crterr_depth' 2012-10-02 08:34:37 +02:00
Emeric Brun
f282a810b7 MINOR: ssl: add fetches and ACLs to return verify errors
Add fetch 'ssl_verify_caerr':
returns the first ssl verify error at depth > 0 (CA chain).

Add fetch 'ssl_verify_caerr_depth':
returns the first ssl verify error depth (max returns is 15 if depth > 15).

Add fetch 'ssl_verify_crterr':
returns the fist ssl verify error at depth == 0.
2012-10-02 08:34:37 +02:00
Emeric Brun
c68af8db6f DOC: ssl: add fetch and ACL 'ssl_verify_result' 2012-10-02 08:34:37 +02:00
Emeric Brun
baf8ffb673 MINOR: ssl: add fetch and ACL 'ssl_verify_result'
This fetch returns the final ssl verify error.
2012-10-02 08:34:37 +02:00
Emeric Brun
b6dc934302 DOC: ssl: add 'ca-ignore-err' and 'crt-ignore-err' statements on 'bind' 2012-10-02 08:34:34 +02:00
Emeric Brun
81c00f0a7a MINOR: ssl: add ignore verify errors options
Allow to ignore some verify errors and to let them pass the handshake.

Add option 'crt-ignore-err <list>'
Ignore verify errors at depth == 0 (client certificate)
<list> is string 'all' or a comma separated list of verify error IDs
(see http://www.openssl.org/docs/apps/verify.html)

Add option 'ca-ignore-err <list>'
Same as 'crt-ignore-err' for all depths > 0 (CA chain certs)

Ex ignore all errors on CA and expired or not-yet-valid errors
on client certificate:

bind 0.0.0.0:443 ssl crt crt.pem verify required
 cafile ca.pem ca-ignore-err all crt-ignore-err 10,9
2012-10-02 08:32:50 +02:00
Emeric Brun
b4354087ee DOC: ssl: add fetch and ACL 'client_cert' 2012-10-02 08:32:50 +02:00
Emeric Brun
e64aef124a MINOR: ssl: add fetch and ACL 'client_crt' to test a client cert is present
Useful in case of 'verify optional' to know if the client sent a certificate.
2012-10-02 08:32:50 +02:00
Emeric Brun
1a073b4650 DOC: ssl: add 'verify', 'cafile' and 'crlfile' statements on 'bind' 2012-10-02 08:32:37 +02:00
Emeric Brun
d94b3fe98f MEDIUM: ssl: add client certificate authentication support
Add keyword 'verify' on bind:
'verify none': authentication disabled (default)
'verify optional': accept connection without certificate
                   and process a verify if the client sent a certificate
'verify required': reject connection without certificate
                   and process a verify if the client send a certificate

Add keyword 'cafile' on bind:
'cafile <path>' path to a client CA file used to verify.
'crlfile <path>' path to a client CRL file used to verify.
2012-10-02 08:04:49 +02:00
Emeric Brun
7fb34422fe DOC: ssl: add 'ecdhe' statement on 'bind' 2012-10-02 08:03:35 +02:00
Emeric Brun
2b58d040b6 MINOR: ssl: add elliptic curve Diffie-Hellman support for ssl key generation
Add 'ecdhe' on 'bind' statement: to set named curve used to generate ECDHE keys
(ex: ecdhe secp521r1)
2012-10-02 08:03:21 +02:00
Emeric Brun
e032bfaa33 DOC: ssl: update 'crt' statement on 'bind' about Diffie-Hellman parameters loading 2012-10-02 08:02:08 +02:00
Emeric Brun
a4bcd9a5a8 MINOR: ssl: try to load Diffie-Hellman parameters from cert file
Feature is disabled if openssl compiled with OPENSSL_NO_DH.
2012-10-02 08:01:42 +02:00
Willy Tarreau
e603e69d18 MEDIUM: connection: make use of the owner instead of container_of
This way the connection can become independant on the stream interface.
2012-09-28 00:01:23 +02:00
Willy Tarreau
cd379950a7 MINOR: connection: add a pointer to the connection owner
This will be needed to find the stream interface from the connection
once they're detached, but in the more immediate term, we'll need this
for health checks since they don't use a stream interface.
2012-09-28 00:01:22 +02:00
Willy Tarreau
82569f9158 MEDIUM: monitor: simplify handling of monitor-net and mode health
We were having several different behaviours with monitor-net and
"mode health" :
  - monitor-net on TCP connections was evaluated just after accept(),
    did not count a connection on the frontend and were not subject
    to tcp-request connection rules, and caused an immediate close().

  - monitor-net in HTTP mode was evaluated once the session was
    accepted (eg: on top of SSL), returned "HTTP/1.0 200 OK\r\n\r\n"
    over the connection's data layer and instanciated a session which
    was responsible for closing this connection. A connection AND a
    session were counted for the frontend ;

  - "mode health" with "option httpchk" would do exactly the same as
    monitor-net in HTTP mode ;

  - "mode health" without "option httpchk" would do the same as above
    except that "OK" was returned instead of "HTTP/1.0 200 OK\r\n\r\n".

None of them took care of cleaning the input buffer, sometimes resulting
in a TCP reset to be emitted after the last packet if a request was received
over the connection.

Given the inconsistencies and the complexity in keeping all these features
handled at the right position, we now slightly changed the way they are
handled :

  - all of them are handled just after the "tcp-request connection" rules,
    so that all of them may be blocked using such rules, offering more
    flexibility and consistency ;

  - no connection handshake is performed anymore for non-TCP modes

  - all of them send the response as raw data over the socket, there is no
    more difference between TCP and HTTP mode for example (these rules were
    never meant to be served over SSL connections and were never documented
    as able to do that).

  - any possible pending data on the incoming socket is drained before the
    response is sent, in order to avoid the risk of a reset.

  - none of them exactly did what was documented !

This results in more consistent, more flexible and more accurate handling of
monitor rules, with smaller and more robust code.
2012-09-28 00:01:22 +02:00
Willy Tarreau
b8ffd378f0 BUG/MAJOR: http: chunk parser was broken with buffer changes
Since at least commit a458b679, msg->sov could become negative in
http_parse_chunk_size() if a chunk size wrapped around the buffer.
The effect is that at some point channel_forward() was called with
a negative size, causing all data to be transferred without being
analyzed anymore.

Since haproxy does not support keep-alive with the server yet, this
issue is not really noticeable, as the server closes the connection
in response. Still, when tunnel mode is used or when pretent-keepalive
is used, it is possible to see the problem.

This issue was reported and diagnosed by William Lallemand at
Exceliance.
2012-09-27 15:08:56 +02:00
Willy Tarreau
3c7a79dbb1 MINOR: cli: allow to set frontend maxconn to zero
It is sometimes useful to completely disable accepting new connections
on a frontend during maintenance operations. By setting a frontend's
maxconn to zero, connections are not accepted anymore until the limit
is increased again.
2012-09-26 21:07:15 +02:00
Willy Tarreau
a7944ad9ef BUG: stats: fix regression introduced by commit 4348fad1
Recent commit 4348fad1 (listeners: use dual-linked lists to chain listeners
with frontends) broke frontend lookup in stats sockets by using the wrong
iterator in the listeners.
2012-09-26 21:03:11 +02:00
Willy Tarreau
3631d41778 CLEANUP: config: fix typo inteface => interface
This was in an error message.
2012-09-25 16:31:00 +02:00
Willy Tarreau
dda5e7c986 CLEANUP: connection: offer conn_prepare() to set up a connection
This will be used by checks as well as stream interfaces.
2012-09-24 22:49:06 +02:00
Willy Tarreau
173e7fbd94 BUG/MINOR: config: check the proper pointer to report unknown protocol
Check the protocol pointer and not the socket to report an unknown family
in servers or peers. This can never happen anyway, it's just to be completely
clean.
2012-09-24 22:49:06 +02:00
Willy Tarreau
e92693af26 BUG: http: do not print garbage on invalid requests in debug mode
Cyril Bonté reported a mangled debug output when an invalid request
was sent with a faulty request line. The reason was the use of the
msg->sl.rq.l offset which was not yet initialized in this case. So
we change the way to report such an error so that first we initialize
it to zero before parsing a message, then we use that to know whether
we can trust it or not. If it's still zero, then we display the whole
buffer, truncated by debug_hdr() to the first CR or LF character, which
results in the first line only.

The same operation was performed for the response, which was wrong too.
2012-09-24 21:16:42 +02:00
Cyril Bonté
3aaba440a2 BUILD: fix compilation error with DEBUG_FULL
Recent changes in structures broke the compilation when using DEBUG_FULL.
Let's update apply the changes also to the variables used in DPRINTF calls.
2012-09-24 20:36:39 +02:00
Willy Tarreau
086fbf53b5 DOC: fix index to reference bind and server options
Last commit forgot to update the index.
2012-09-24 20:35:19 +02:00
Willy Tarreau
abb175f0e9 DOC: stats: refer to "bind" section for "stats socket" settings
They're all shared now, so let's have them described at one single
place.
2012-09-24 12:43:26 +02:00
Willy Tarreau
b6205fd092 DOC: move bind options to their own section
There are now too many bind options to still have them in the middle
of the keyword matrix, so let's move them with the server options in
section 5. No new option was documented yet at this point.
2012-09-24 12:27:33 +02:00
Willy Tarreau
d578120a3e MEDIUM: stats: make use of the standard "bind" parsers to parse global socket
The global stats socket statement now makes use of the standard bind parsers.
This results in all UNIX socket options being set by proto_uxst and in all
TCP and SSL options being inherited and usable. For example it is now possible
to enable a stats socket over SSL/TCP by appending the "ssl" keyword and a
certificate after "crt".

The code is simplified since we don't have a special case to parse this config
keyword anymore.
2012-09-24 10:53:17 +02:00