]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
10 years agoMEDIUM: http: configurable http result codes for http-request deny
CJ Ess [Tue, 7 Apr 2015 16:03:37 +0000 (12:03 -0400)] 
MEDIUM: http: configurable http result codes for http-request deny

This patch adds support for error codes 429 and 405 to Haproxy and a
"deny_status XXX" option to "http-request deny" where you can specify which
code is returned with 403 being the default. We really want to do this the
"haproxy way" and hope to have this patch included in the mainline. We'll
be happy address any feedback on how this is implemented.

10 years agoBUG/MINOR: ssl: Display correct filename in error message
Alexander Rigbo [Tue, 7 Apr 2015 12:02:16 +0000 (14:02 +0200)] 
BUG/MINOR: ssl: Display correct filename in error message

This patch should be backported to 1.5.

10 years agoMINOR: stream: pass the pointer to the origin explicitly to stream_new()
Willy Tarreau [Wed, 8 Apr 2015 16:26:29 +0000 (18:26 +0200)] 
MINOR: stream: pass the pointer to the origin explicitly to stream_new()

We don't pass sess->origin anymore but the pointer to the previous step. Now
it should be much easier to chain elements together once applets are moved out
of streams. Indeed, the session is only used for configuration and not for the
dynamic chaining anymore.

10 years agoMEDIUM: session: adjust the connection flags before stream_new()
Willy Tarreau [Wed, 8 Apr 2015 16:18:15 +0000 (18:18 +0200)] 
MEDIUM: session: adjust the connection flags before stream_new()

It's not the stream's job to manipulate the connection's flags, it's
more related to the session that accepted the new connection. And the
only case where we have to do it conditionally is based on the frontend
which is known from the session, thus it makes sense to do it there.

10 years agoMINOR: session: maintain the session count stats in the session, not the stream
Willy Tarreau [Wed, 8 Apr 2015 16:10:49 +0000 (18:10 +0200)] 
MINOR: session: maintain the session count stats in the session, not the stream

This has nothing to do in the stream, as we'll face absurdities when chaining
multiple streams. The session is where it must be accounted for.

10 years agoCLEANUP: namespaces: fix protection against multiple inclusions
Willy Tarreau [Tue, 7 Apr 2015 19:00:08 +0000 (21:00 +0200)] 
CLEANUP: namespaces: fix protection against multiple inclusions

The include file did not protect correctly against multiple inclusions,
as it didn't define the file name after checking for it. That's currently
harmless as the file is only included from .c but that could change.

10 years agoMINOR: lua: map system integration in Lua
Thierry FOURNIER [Tue, 7 Apr 2015 09:27:54 +0000 (11:27 +0200)] 
MINOR: lua: map system integration in Lua

This patch cretes a new Map class that permits to do some lookup in
HAProxy maps. This Map class is integration in the HAProxy update
system, so we can modify the map throught the socket.

10 years agoMINOR: lua: (req|res)_get_headers return more than one header value
Thierry FOURNIER [Wed, 18 Mar 2015 12:43:10 +0000 (13:43 +0100)] 
MINOR: lua: (req|res)_get_headers return more than one header value

the functions (req|res)_get_headers() return only the last entry
for each header with the same name. This patch fix this behavior.
Each header name contain an array of values.

10 years agoDOC: lua: some fixes
Thierry FOURNIER [Wed, 18 Mar 2015 12:37:27 +0000 (13:37 +0100)] 
DOC: lua: some fixes

 - remove trailing spces
 - update fetches ans converters documentation

10 years agoCLEANUP: stream-int: swap stream-int and appctx declarations
Willy Tarreau [Mon, 6 Apr 2015 09:43:45 +0000 (11:43 +0200)] 
CLEANUP: stream-int: swap stream-int and appctx declarations

This is just in order to remove two forward declarations of si_applet
and stream_interface that are not needed once properly ordered.

10 years agoMINOR: peers: no need for setting timeouts / conn_retries in peer_session_create()
Willy Tarreau [Sun, 5 Apr 2015 23:06:42 +0000 (01:06 +0200)] 
MINOR: peers: no need for setting timeouts / conn_retries in peer_session_create()

For the client side this is done already by stream_new(). For the
server side it will be done when establishing the connection.

10 years agoMINOR: lua: no need for setting timeouts / conn_retries in hlua_socket_new()
Willy Tarreau [Sun, 5 Apr 2015 22:52:04 +0000 (00:52 +0200)] 
MINOR: lua: no need for setting timeouts / conn_retries in hlua_socket_new()

For the client side this is done already by stream_new(). For the
server side it will be done when establishing the connection.

10 years agoMINOR: lua: minor cleanup in hlua_socket_new()
Willy Tarreau [Sun, 5 Apr 2015 22:48:33 +0000 (00:48 +0200)] 
MINOR: lua: minor cleanup in hlua_socket_new()

Just limit the number of dereferences of socket-> since we allocate
the stream at the beginning.

10 years agoMEDIUM: lua: make use of stream_new() to create an outgoing connection
Willy Tarreau [Sun, 5 Apr 2015 22:39:18 +0000 (00:39 +0200)] 
MEDIUM: lua: make use of stream_new() to create an outgoing connection

This significantly simplifies the session management because we don't
have to know all the intimate tricks of setting up a stream and a
session.

10 years agoMEDIUM: stream: don't rely on the session's listener anymore in stream_new()
Willy Tarreau [Sun, 5 Apr 2015 22:25:48 +0000 (00:25 +0200)] 
MEDIUM: stream: don't rely on the session's listener anymore in stream_new()

When the stream is instanciated from an applet, it doesn't necessarily
have a listener. The listener was sparsely used there, just to retrieve
the task function, update the listeners' stats, and set the analysers
and default target, both of which are often zero from applets. Thus
these elements are now initialized with default values that the caller
is free to change if desired.

10 years agoCLEANUP: frontend: remove one useless local variable
Willy Tarreau [Sun, 5 Apr 2015 16:19:23 +0000 (18:19 +0200)] 
CLEANUP: frontend: remove one useless local variable

"p" was a copy of sess->fe which itself is also used. It's used in a
few cases, let's remove it and reduce the code as well.

10 years agoMEDIUM: frontend: move some remaining stream settings to stream_new()
Willy Tarreau [Sun, 5 Apr 2015 16:15:59 +0000 (18:15 +0200)] 
MEDIUM: frontend: move some remaining stream settings to stream_new()

The auto-forwarding mechanism in case no analyser is set is generic
to the streams. Also the timeouts on the client side are better preset
in the stream initialization as well.

10 years agoMEDIUM: frontend: don't restrict frontend_accept() to connections anymore
Willy Tarreau [Sun, 5 Apr 2015 16:01:06 +0000 (18:01 +0200)] 
MEDIUM: frontend: don't restrict frontend_accept() to connections anymore

Now it can also initialize streams initiated by applets. This will be
needed for HTTP/2.

10 years agoMEDIUM: frontend: move the fd-specific settings to session_accept_fd()
Willy Tarreau [Sun, 5 Apr 2015 15:56:47 +0000 (17:56 +0200)] 
MEDIUM: frontend: move the fd-specific settings to session_accept_fd()

The frontend is generic and does not depend on a file descriptor,
so applying some socket options to the incoming fd is not its role.
Let's move the setsockopt() calls earlier in session_accept_fd()
where others are done as well.

10 years agoMEDIUM: frontend: move some stream initialisation to stream_new()
Willy Tarreau [Sun, 5 Apr 2015 10:03:54 +0000 (12:03 +0200)] 
MEDIUM: frontend: move some stream initialisation to stream_new()

This is mostly what is related to logging, and which is more of
a stream initialization than anything frontend-specific.

10 years agoMEDIUM: stream: return the stream upon accept()
Willy Tarreau [Sun, 5 Apr 2015 10:00:52 +0000 (12:00 +0200)] 
MEDIUM: stream: return the stream upon accept()

The function was called stream_accept_session(), let's rename it
stream_new() and make it return the newly allocated pointer. It's
more convenient for some callers who need it.

10 years agoMEDIUM: frontend: make ->accept only return +/-1
Willy Tarreau [Sun, 5 Apr 2015 09:52:08 +0000 (11:52 +0200)] 
MEDIUM: frontend: make ->accept only return +/-1

This function was specified as being able to return 3 states, which had
repercussions to the stream accept function. It was used at the time
when the frontend would do the monitoring itself. This is not the case
anymore, so let's simplify this.

10 years agoMEDIUM: peers: make use of stream_accept_session()
Willy Tarreau [Sat, 4 Apr 2015 23:35:34 +0000 (01:35 +0200)] 
MEDIUM: peers: make use of stream_accept_session()

Instead of going through some obscure initialization sequences, we now
rely on the stream code to initialize our stream. Some parts are still
a bit tricky as we cannot call the frontend's accept code which is only
made for appctx in input. So part of the initialization past the stream
code is what ought to be in the frontend code instead. Still, even
without this, these are 71 lines that were removed.

10 years agoMEDIUM: stream: also accept appctx as origin in stream_accept_session()
Willy Tarreau [Sat, 4 Apr 2015 23:33:13 +0000 (01:33 +0200)] 
MEDIUM: stream: also accept appctx as origin in stream_accept_session()

It's likely that the code could be simplified a bit though.

10 years agoMEDIUM: stream: isolate connection-specific initialization code
Willy Tarreau [Sat, 4 Apr 2015 23:30:42 +0000 (01:30 +0200)] 
MEDIUM: stream: isolate connection-specific initialization code

In stream_accept_session(), we perform some operations that explicitly
want a connection as the origin, but we'll soon have other types of
origin (eg: applet). Thus change the test to ensure we only call this
code with connections. Additionally, we refrain from calling fe->accept()
if the origin is not a connection, because for now the only fe->accept()
may only use a connection (frontend_accept).

10 years agoCLEANUP: stream.c: do not re-attach the connection to the stream
Willy Tarreau [Sat, 4 Apr 2015 23:05:44 +0000 (01:05 +0200)] 
CLEANUP: stream.c: do not re-attach the connection to the stream

This was a leftover from the initial code, it's not needed at all
anymore.

10 years agoMINOR: session: set the CO_FL_CONNECTED flag on the connection once ready
Willy Tarreau [Sat, 4 Apr 2015 23:04:01 +0000 (01:04 +0200)] 
MINOR: session: set the CO_FL_CONNECTED flag on the connection once ready

If we know there's no handshake, we must set the flag on the connection,
it's not the job of the stream initializer to do it.

10 years agoMEDIUM: peers: initialize the task before the stream
Willy Tarreau [Sat, 4 Apr 2015 22:46:36 +0000 (00:46 +0200)] 
MEDIUM: peers: initialize the task before the stream

Thanks to this we should be able to make use of stream_accept_session()
now.

10 years agoMINOR: peers: make use of session_new() when creating a new session
Willy Tarreau [Sat, 4 Apr 2015 22:39:55 +0000 (00:39 +0200)] 
MINOR: peers: make use of session_new() when creating a new session

It's better than open-coding it.

10 years agoMINOR: session: make use of session_new() when creating a new session
Willy Tarreau [Sat, 4 Apr 2015 22:39:16 +0000 (00:39 +0200)] 
MINOR: session: make use of session_new() when creating a new session

It's better than open-coding it.

10 years agoMINOR: session: introduce session_new()
Willy Tarreau [Sat, 4 Apr 2015 22:38:48 +0000 (00:38 +0200)] 
MINOR: session: introduce session_new()

This one creates a new session and does the minimum initialization.

10 years agoMEDIUM: peers: move the appctx initialization earlier
Willy Tarreau [Sat, 4 Apr 2015 22:32:03 +0000 (00:32 +0200)] 
MEDIUM: peers: move the appctx initialization earlier

The purpose is to initialize the appctx prior to the stream in
order to reuse stream_accept_session().

10 years agoMINOR: stream-int: make appctx_new() take the applet in argument
Willy Tarreau [Sat, 4 Apr 2015 22:15:26 +0000 (00:15 +0200)] 
MINOR: stream-int: make appctx_new() take the applet in argument

Doing so simplifies the initialization of a new appctx. We don't
need appctx_set_applet() anymore.

10 years agoREORG: session: move the session parts out of stream.c
Willy Tarreau [Sat, 4 Apr 2015 16:50:31 +0000 (18:50 +0200)] 
REORG: session: move the session parts out of stream.c

This concerns everythins related to accepting a new session and
expiring the embryonic session. There's still a hard-coded call
to stream_accept_session() which could be set somewhere in the
frontend, but for now it's not a problem.

10 years agoMEDIUM: session: remove the task pointer from the session
Willy Tarreau [Sat, 4 Apr 2015 16:29:59 +0000 (18:29 +0200)] 
MEDIUM: session: remove the task pointer from the session

Now that the previous changes were made, we can add a struct task
pointer to stream_complete() and get rid of it in struct session.

The new relation between connection, session and task are like this :

          orig -- sess <-- context
           |                   |
           v                   |
          conn -- owner ---> task

Some session-specific parts should now move away from stream.

10 years agoMAJOR: stream: don't initialize the stream anymore in stream_accept
Willy Tarreau [Sat, 4 Apr 2015 16:08:21 +0000 (18:08 +0200)] 
MAJOR: stream: don't initialize the stream anymore in stream_accept

The function now only initializes a session, calls the tcp req connection
rules, and calls stream_complete() to finish initialization. If a handshake
is needed, it is done without allocating the stream at all.

Temporarily, in order to limit the amount of changes, the task allocated
is put into sess->task, and it is used by the connection for the handshake
or is offered to the stream. At this point we set the relation between
sess/task/conn this way :

        orig -- sess  <-- context
         |       ^ +- task -+  |
         v       |          v  |
        conn -- owner       task

The task must not remain in the session and ultimately it is planned to
remove this task pointer from the session because it can be found by
having conn->owner = task, and looping back from sess to conn, and to
find the session from the connection via the task.

10 years agoMEDIUM: stream: move all the session-specific stuff of stream_accept() earlier
Willy Tarreau [Sat, 4 Apr 2015 14:55:53 +0000 (16:55 +0200)] 
MEDIUM: stream: move all the session-specific stuff of stream_accept() earlier

Since the tcp-request connection rules don't need the stream anymore, we
can safely move the session-specific stuff earlier and prepare for a split
of session and stream initialization. Some work remains to be done.

10 years agoMEDIUM: stream: don't call stream_store_counters() in kill_mini_session() nor session...
Willy Tarreau [Sat, 4 Apr 2015 14:44:19 +0000 (16:44 +0200)] 
MEDIUM: stream: don't call stream_store_counters() in kill_mini_session() nor session_accept()

This one is not needed anymore since we cannot track the stream counters
prior to reaching these locations. Only session counters may be tracked
and they're properly committed during session_free().

10 years agoMAJOR: tcp: make tcp_exec_req_rules() only rely on the session
Willy Tarreau [Sat, 4 Apr 2015 14:41:45 +0000 (16:41 +0200)] 
MAJOR: tcp: make tcp_exec_req_rules() only rely on the session

It passes a NULL wherever a stream was needed (acl_exec_cond() and
action_ptr mainly). It can still track the connection rate correctly
and block based on ACLs.

10 years agoMEDIUM: proto_tcp: track the session's counters in the connection ruleset
Willy Tarreau [Sat, 4 Apr 2015 14:38:07 +0000 (16:38 +0200)] 
MEDIUM: proto_tcp: track the session's counters in the connection ruleset

The tcp-request connection ruleset now only tracks session counters and
not stream counters. Thus it does not need access to the stream anymore.

10 years agoMEDIUM: session: update the session's stick counters upon session_free()
Willy Tarreau [Sat, 4 Apr 2015 14:31:16 +0000 (16:31 +0200)] 
MEDIUM: session: update the session's stick counters upon session_free()

Whenever session_free() is called, any possible stick counter stored in
the session will be synchronized.

10 years agoMEDIUM: streams: support looking up stkctr in the session
Willy Tarreau [Sat, 4 Apr 2015 14:29:12 +0000 (16:29 +0200)] 
MEDIUM: streams: support looking up stkctr in the session

In order to support sessions tracking counters, we first ensure that there
is no overlap between streams' stkctr and sessions', and we allow an
automatic lookup into the session's counters when the stream doesn't
have a counter or when the stream doesn't exist during an access via
a sample fetch. The functions used to update the stream counters only
update them and not the session counters however.

10 years agoREORG: stktable: move the stkctr_* functions from stream to sticktable
Willy Tarreau [Sat, 4 Apr 2015 14:24:42 +0000 (16:24 +0200)] 
REORG: stktable: move the stkctr_* functions from stream to sticktable

These ones are not stream-specific at all and will be needed outside of
stream, so let's move them to stick_tables where struct stkctr is defined.

10 years agoMINOR: session: add stick counters to the struct session
Willy Tarreau [Sat, 4 Apr 2015 13:58:58 +0000 (15:58 +0200)] 
MINOR: session: add stick counters to the struct session

The stick counters in the session will be used for everything not related
to contents, hence the connections / concurrent sessions / etc. They will
be usable by "tcp-request connection" rules even without a stream. For now
they're just allocated and initialized.

10 years agoMINOR: session: implement session_free() and use it everywhere
Willy Tarreau [Sat, 4 Apr 2015 13:54:03 +0000 (15:54 +0200)] 
MINOR: session: implement session_free() and use it everywhere

We want to call this one everywhere we have to kill a session so
that future parts we move to the session can be released from there.

10 years agoMINOR: session: don't rely on s->logs.logwait in embryonic sessions
Willy Tarreau [Sat, 4 Apr 2015 12:54:14 +0000 (14:54 +0200)] 
MINOR: session: don't rely on s->logs.logwait in embryonic sessions

The embryonic session now only stores the task (to expire the session)
and the stick counters.

10 years agoMINOR: session: store the session's accept date
Willy Tarreau [Sat, 4 Apr 2015 12:46:56 +0000 (14:46 +0200)] 
MINOR: session: store the session's accept date

Doing so ensures we don't need to use the stream anymore to prepare the
log information to report a failed handshake on an embryonic session.
Thus, prepare_mini_sess_log_prefix() now takes a session in argument.

10 years agoMINOR: stream: move session initialization before the stream's
Willy Tarreau [Sat, 4 Apr 2015 12:38:25 +0000 (14:38 +0200)] 
MINOR: stream: move session initialization before the stream's

In an effort to completely separate stream from session, this patch
further separates the two by initializing the session before the stream.

10 years agoCLEANUP: stream: don't set ->target to the incoming connection anymore
Willy Tarreau [Sat, 4 Apr 2015 12:28:46 +0000 (14:28 +0200)] 
CLEANUP: stream: don't set ->target to the incoming connection anymore

Now that we have sess->origin to carry that information along, we don't
need to put that into strm->target anymore, so we remove one dependence
on the stream in embryonic connections.

10 years agoMINOR: stream: provide a few helpers to retrieve frontend, listener and origin
Willy Tarreau [Sat, 4 Apr 2015 00:10:38 +0000 (02:10 +0200)] 
MINOR: stream: provide a few helpers to retrieve frontend, listener and origin

Expressions are quite long when using strm_sess(strm)->whatever, so let's
provide a few helpers : strm_fe(), strm_li(), strm_orig().

10 years agoMAJOR: sample: pass a pointer to the session to each sample fetch function
Willy Tarreau [Fri, 3 Apr 2015 23:47:55 +0000 (01:47 +0200)] 
MAJOR: sample: pass a pointer to the session to each sample fetch function

Many such function need a session, and till now they used to dereference
the stream. Once we remove the stream from the embryonic session, this
will not be possible anymore.

So as of now, sample fetch functions will be called with this :

   - sess = NULL,  strm = NULL                     : never
   - sess = valid, strm = NULL                     : tcp-req connection
   - sess = valid, strm = valid, strm->txn = NULL  : tcp-req content
   - sess = valid, strm = valid, strm->txn = valid : http-req / http-res

10 years agoCLEANUP: lua: don't pass http_txn anymore to hlua_request_act_wrapper()
Willy Tarreau [Fri, 3 Apr 2015 23:11:28 +0000 (01:11 +0200)] 
CLEANUP: lua: don't pass http_txn anymore to hlua_request_act_wrapper()

It doesn't use it anymore at all.

10 years agoMEDIUM: http: remove the now useless http_txn from {req/res} rules
Willy Tarreau [Fri, 3 Apr 2015 23:09:08 +0000 (01:09 +0200)] 
MEDIUM: http: remove the now useless http_txn from {req/res} rules

The registerable http_req_rules / http_res_rules used to require a
struct http_txn at the end. It's redundant with struct stream and
propagates very deep into some parts (ie: it was the reason for lua
requiring l7). Let's remove it now.

10 years agoCLEANUP: lua: remove unused hlua_smp->l7 and hlua_txn->l7
Willy Tarreau [Fri, 3 Apr 2015 22:56:08 +0000 (00:56 +0200)] 
CLEANUP: lua: remove unused hlua_smp->l7 and hlua_txn->l7

Since last commit, we don't retrieve the HTTP transaction from there
anymore, so these entries can go.

10 years agoMAJOR: sample: don't pass l7 anymore to sample fetch functions
Willy Tarreau [Fri, 3 Apr 2015 22:52:09 +0000 (00:52 +0200)] 
MAJOR: sample: don't pass l7 anymore to sample fetch functions

All of them can now retrieve the HTTP transaction *if it exists* from
the stream and be sure to get NULL there when called with an embryonic
session.

The patch is a bit large because many locations were touched (all fetch
functions had to have their prototype adjusted). The opportunity was
taken to also uniformize the call names (the stream is now always "strm"
instead of "l4") and to fix indent where it was broken. This way when
we later introduce the session here there will be less confusion.

10 years agoMAJOR: http: move http_txn out of struct stream
Willy Tarreau [Fri, 3 Apr 2015 21:46:31 +0000 (23:46 +0200)] 
MAJOR: http: move http_txn out of struct stream

Now this one is dynamically allocated. It means that 280 bytes of memory
are saved per TCP stream, but more importantly that it will become
possible to remove the l7 pointer from fetches and converters since
it will be deduced from the stream and will support being null.

A lot of care was taken because it's easy to forget a test somewhere,
and the previous code used to always trust s->txn for being valid, but
all places seem to have been visited.

All HTTP fetch functions check the txn first so we shouldn't have any
issue there even when called from TCP. When branching from a TCP frontend
to an HTTP backend, the txn is properly allocated at the same time as the
hdr_idx.

10 years agoMINOR: http: create a dedicated pool for http_txn
Willy Tarreau [Fri, 3 Apr 2015 20:55:33 +0000 (22:55 +0200)] 
MINOR: http: create a dedicated pool for http_txn

This one will not necessarily be allocated for each stream, and we want
to use the fact that it equals null to know it's not present so that we
can always deduce its presence from the stream pointer.

This commit only creates the new pool.

10 years agoMEDIUM: http: move header captures from http_txn to struct stream
Willy Tarreau [Fri, 3 Apr 2015 20:16:32 +0000 (22:16 +0200)] 
MEDIUM: http: move header captures from http_txn to struct stream

The header captures are now general purpose captures since tcp rules
can use them to capture various contents. That removes a dependency
on http_txn that appeared in some sample fetch functions and in the
order by which captures and http_txn were allocated.

Interestingly the reset of the header captures were done at too many
places as http_init_txn() used to do it while it was done previously
in every call place.

10 years agoCLEANUP: sample: remove useless tests in fetch functions for l4 != NULL
Willy Tarreau [Fri, 3 Apr 2015 19:38:18 +0000 (21:38 +0200)] 
CLEANUP: sample: remove useless tests in fetch functions for l4 != NULL

The stream may never be null given that all these functions are called
from sample_process(). Let's remove this now confusing test which
sometimes happens after a dereference was already done.

10 years agoMEDIUM: session: use the pointer to the origin instead of s->si[0].end
Willy Tarreau [Fri, 3 Apr 2015 17:19:59 +0000 (19:19 +0200)] 
MEDIUM: session: use the pointer to the origin instead of s->si[0].end

When s->si[0].end was dereferenced as a connection or anything in
order to retrieve information about the originating session, we'll
now use sess->origin instead so that when we have to chain multiple
streams in HTTP/2, we'll keep accessing the same origin.

10 years agoMINOR: session: add a pointer to the session's origin
Willy Tarreau [Fri, 3 Apr 2015 16:08:29 +0000 (18:08 +0200)] 
MINOR: session: add a pointer to the session's origin

A session's origin is the entity that was responsible for creating
the session. It can be an applet or a connection for now.

10 years agoMEDIUM: stream: move the frontend's pointer to the session
Willy Tarreau [Fri, 3 Apr 2015 13:40:56 +0000 (15:40 +0200)] 
MEDIUM: stream: move the frontend's pointer to the session

Just like for the listener, the frontend is session-wide so let's move
it to the session. There are a lot of places which were changed but the
changes are minimal in fact.

10 years agoMEDIUM: stream: move the listener's pointer to the session
Willy Tarreau [Fri, 3 Apr 2015 12:46:27 +0000 (14:46 +0200)] 
MEDIUM: stream: move the listener's pointer to the session

The listener is session-specific, move it there.

10 years agoMEDIUM: stream: allocate the session when a stream is created
Willy Tarreau [Fri, 3 Apr 2015 12:10:06 +0000 (14:10 +0200)] 
MEDIUM: stream: allocate the session when a stream is created

This is where we'll put some session-wide information.

10 years agoMINOR: session: start to reintroduce struct session
Willy Tarreau [Fri, 3 Apr 2015 11:53:24 +0000 (13:53 +0200)] 
MINOR: session: start to reintroduce struct session

There is now a pointer to the session in the stream, which is NULL
for now. The session pool is created as well. Some parts will move
from the stream to the session now.

10 years agoREORG/MEDIUM: stream: rename stream flags from SN_* to SF_*
Willy Tarreau [Thu, 2 Apr 2015 23:14:29 +0000 (01:14 +0200)] 
REORG/MEDIUM: stream: rename stream flags from SN_* to SF_*

This is in order to keep things consistent.

10 years agoREORG/MAJOR: session: rename the "session" entity to "stream"
Willy Tarreau [Thu, 2 Apr 2015 22:22:06 +0000 (00:22 +0200)] 
REORG/MAJOR: session: rename the "session" entity to "stream"

With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.

In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.

The files stream.{c,h} were added and session.{c,h} removed.

The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.

Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.

Once all changes are completed, we should see approximately this :

   L7 - http_txn
   L6 - stream
   L5 - session
   L4 - connection | applet

There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.

Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.

10 years agoCLEANUP: lua: get rid of the last two "*hs" for hlua_smp
Willy Tarreau [Mon, 6 Apr 2015 09:15:40 +0000 (11:15 +0200)] 
CLEANUP: lua: get rid of the last two "*hs" for hlua_smp

The two last occurrences were in hlua_fetches_new() and hlua_converters_new().
Now they're called hsmp as in other places.

10 years agoCLEANUP: lua: rename variable "sc" for struct hlua_smp
Willy Tarreau [Mon, 6 Apr 2015 09:17:13 +0000 (11:17 +0200)] 
CLEANUP: lua: rename variable "sc" for struct hlua_smp

It's unclear where this name comes from, but better rename it now to "hsmp"
to be in line with the rest of the code.

10 years agoCLEANUP: lua: rename last occurrences of "*s" to "*htxn" for hlua_txn
Willy Tarreau [Mon, 6 Apr 2015 09:21:44 +0000 (11:21 +0200)] 
CLEANUP: lua: rename last occurrences of "*s" to "*htxn" for hlua_txn

These ones were found in the actions to set the query/path/method/uri.
Where it's used, "s" makes one think about session or something like
this, especially when mixed with http_txn.

10 years agoCLEANUP: lua: get rid of the last "*ht" for struct hlua_txn.
Willy Tarreau [Mon, 6 Apr 2015 09:14:06 +0000 (11:14 +0200)] 
CLEANUP: lua: get rid of the last "*ht" for struct hlua_txn.

All other ones are called "htxn", call it similarly in hlua_http_new(),
this will make copy-paste safer.

10 years agoCLEANUP: hlua: stop using variable name "s" alternately for hlua_txn and hlua_smp
Willy Tarreau [Mon, 6 Apr 2015 09:11:15 +0000 (11:11 +0200)] 
CLEANUP: hlua: stop using variable name "s" alternately for hlua_txn and hlua_smp

hlua_run_sample_fetch() uses "struct hlua_smp *s" which starts to become
confusing when "s->s" is used, then hlua_txn_close() uses this for struct
hlua_txn with the same "s->s" everywhere. Let's uniformize everything with
htxn and hsmp as in other places.

10 years agoCLEANUP: lua: fix confusing local variable naming in hlua_txn_new()
Willy Tarreau [Mon, 6 Apr 2015 09:04:28 +0000 (11:04 +0200)] 
CLEANUP: lua: fix confusing local variable naming in hlua_txn_new()

Struct hlua_txn is called "htxn" or "ht" everywhere, while here it's
called "hs" which is the name used everywhere for struct "hlua_smp".
Such confusion participate to the dangers of copy-pasting code, so
let's fix the name here.

10 years agoCLEANUP: lua: remove hard-coded sizeof() in object creations and mallocs
Willy Tarreau [Mon, 6 Apr 2015 08:59:20 +0000 (10:59 +0200)] 
CLEANUP: lua: remove hard-coded sizeof() in object creations and mallocs

Last bug was an example of a side effect of abuse of copy-paste, but
there are other places at risk, so better fix all occurrences of sizeof
to really reference the object size in order to limit the risks in the
future.

10 years agoBUG/MAJOR: lua: use correct object size when initializing a new converter
Willy Tarreau [Mon, 6 Apr 2015 08:50:55 +0000 (10:50 +0200)] 
BUG/MAJOR: lua: use correct object size when initializing a new converter

In hlua_converters_new(), we used to allocate the size of an hlua_txn
instead of hlua_smp, resulting in random crashes with one integer being
randomly overwritten at the end, even when no converter is being used.

10 years agoCLEANUP: lua: remove the unused hlua_sleep memory pool
Willy Tarreau [Mon, 6 Apr 2015 08:43:23 +0000 (10:43 +0200)] 
CLEANUP: lua: remove the unused hlua_sleep memory pool

Commit d44731f ("MEDIUM: lua: change the sleep function core") removed
the use for this pool but forgot to remove the pool which is still
created.

10 years agoBUG/MAJOR: http: null-terminate the http actions keywords list
Willy Tarreau [Fri, 3 Apr 2015 07:52:01 +0000 (09:52 +0200)] 
BUG/MAJOR: http: null-terminate the http actions keywords list

Commit a0dc23f ("MEDIUM: http: implement http-request set-{method,path,query,uri}")
forgot to null-terminate the list, resulting in crashes when these actions
are used if the platform doesn't pad the struct with nulls.

Thanks to Gunay Arslan for reporting a detailed trace showing the
origin of this bug.

No backport to 1.5 is needed.

10 years agoBUG/MEDIUM: http: hdr_cnt would not count any header when called without name
Willy Tarreau [Wed, 1 Apr 2015 17:16:09 +0000 (19:16 +0200)] 
BUG/MEDIUM: http: hdr_cnt would not count any header when called without name

It's documented that these sample fetch functions should count all headers
and/or all values when called with no name but in practice it's not what is
being done as a missing name causes an immediate return and an absence of
result.

This bug is present in 1.5 as well and must be backported.

10 years agoMAJOR: compression: integrate support for libslz
Willy Tarreau [Sun, 29 Mar 2015 01:32:06 +0000 (03:32 +0200)] 
MAJOR: compression: integrate support for libslz

This library is designed to emit a zlib-compatible stream with no
memory usage and to favor resource savings over compression ratio.
While zlib requires 256 kB of RAM per compression context (and can only
support 4000 connections per GB of RAM), the stateless compression
offered by libslz does not need to retain buffers between subsequent
calls. In theory this slightly reduces the compression ratio but in
practice it does not have that much of an effect since the zlib
window is limited to 32kB.

Libslz is available at :

      http://git.1wt.eu/web?p=libslz.git

It was designed for web compression and provides a lot of savings
over zlib in haproxy. Here are the preliminary results on a single
core of a core2-quad 3.0 GHz in 32-bit for only 300 concurrent
sessions visiting the home page of www.haproxy.org (76 kB) with
the default 16kB buffers :

          BW In      BW Out     BW Saved   Ratio   memory VSZ/RSS
zlib      237 Mbps    92 Mbps   145 Mbps   2.58     84M /  69M
slz       733 Mbps   380 Mbps   353 Mbps   1.93    5.9M / 4.2M

So while the compression ratio is lower, the bandwidth savings are
much more important due to the significantly lower compression cost
which allows to consume even more data from the servers. In the
example above, zlib became the bottleneck at 24% of the output
bandwidth. Also the difference in memory usage is obvious.

More tests run on a single core of a core i5-3320M, with 500 concurrent
users and the default 16kB buffers :

At 100% CPU (no limit) :
          BW In      BW Out     BW Saved   Ratio   memory VSZ/RSS  hits/s
zlib      480 Mbps   188 Mbps   292 Mbps   2.55     130M / 101M     744
slz      1700 Mbps   810 Mbps   890 Mbps   2.10    23.7M / 9.7M    2382

At 85% CPU (limited) :
          BW In      BW Out     BW Saved   Ratio   memory VSZ/RSS  hits/s
zlib     1240 Mbps   976 Mbps   264 Mbps   1.27     130M / 100M    1738
slz      1600 Mbps   976 Mbps   624 Mbps   1.64    23.7M / 9.7M    2210

The most important benefit really happens when the CPU usage is
limited by "maxcompcpuusage" or the BW limited by "maxcomprate" :
in order to preserve resources, haproxy throttles the compression
ratio until usage is within limits. Since slz is much cheaper, the
average compression ratio is much higher and the input bandwidth
is quite higher for one Gbps output.

Other tests made with some reference files :

                           BW In     BW Out    BW Saved  Ratio  hits/s
daniels.html       zlib  1320 Mbps  163 Mbps  1157 Mbps   8.10    1925
                   slz   3600 Mbps  580 Mbps  3020 Mbps   6.20    5300

tv.com/listing     zlib   980 Mbps  124 Mbps   856 Mbps   7.90     310
                   slz   3300 Mbps  553 Mbps  2747 Mbps   5.97    1100

jquery.min.js      zlib   430 Mbps  180 Mbps   250 Mbps   2.39     547
                   slz   1470 Mbps  764 Mbps   706 Mbps   1.92    1815

bootstrap.min.css  zlib   790 Mbps  165 Mbps   625 Mbps   4.79     777
                   slz   2450 Mbps  650 Mbps  1800 Mbps   3.77    2400

So on top of saving a lot of memory, slz is constantly 2.5-3.5 times
faster than zlib and results in providing more savings for a fixed CPU
usage. For links smaller than 100 Mbps, zlib still provides a better
compression ratio, at the expense of a much higher CPU usage.

Larger input files provide slightly higher bandwidth for both libs, at
the expense of a bit more memory usage for zlib (it converges to 256kB
per connection).

10 years agoCLEANUP: compression: remove unused reset functions
Willy Tarreau [Sat, 28 Mar 2015 21:08:25 +0000 (22:08 +0100)] 
CLEANUP: compression: remove unused reset functions

It's unclear what purpose these functions used to server, however they
are not used anywhere, one good reason to remove them.

10 years agoMEDIUM: compression: split deflate_flush() into flush and finish
Willy Tarreau [Sat, 28 Mar 2015 18:17:31 +0000 (19:17 +0100)] 
MEDIUM: compression: split deflate_flush() into flush and finish

This function used to take a zlib-specific flag as argument to indicate
whether a buffer flush or end of contents was met, let's split it in two
so that we don't depend on zlib anymore.

10 years agoMEDIUM: compression: add new "raw-deflate" compression algorithm
Willy Tarreau [Sat, 28 Mar 2015 16:00:39 +0000 (17:00 +0100)] 
MEDIUM: compression: add new "raw-deflate" compression algorithm

This algorithm is exactly the same as "deflate" without the zlib wrapper,
and used as an alternative when the browser wants "deflate". All major
browsers understand it and despite violating the standards, it is known
to work better than "deflate", at least on MSIE and some versions of
Safari. Do not use it in conjunction with "deflate", use either one or
the other since both react to the same Accept-Encoding token. Note that
the lack of Adler32 checksum makes it slightly faster.

10 years agoMEDIUM: compression: add a distinction between UA- and config- algorithms
Willy Tarreau [Sat, 28 Mar 2015 15:40:46 +0000 (16:40 +0100)] 
MEDIUM: compression: add a distinction between UA- and config- algorithms

Thanks to MSIE/IIS, the "deflate" name is ambigous. According to the RFC
it's a zlib-wrapped deflate stream, but IIS used to send only a raw deflate
stream, which is the only format MSIE understands for "deflate". The other
widely used browsers do support both formats. For this reason some people
prefer to emit a raw deflate stream on "deflate" to serve more users even
it that means violating the standards. Haproxy only follows the standard,
so they cannot do this.

This patch makes it possible to have one algorithm name in the configuration
and another one in the protocol. This will make it possible to have a new
configuration token to add a different algorithm so that users can decide if
they want a raw deflate or the standard one.

10 years agoCLEANUP: compression: statify all algo-specific functions
Willy Tarreau [Sat, 28 Mar 2015 14:46:00 +0000 (15:46 +0100)] 
CLEANUP: compression: statify all algo-specific functions

There's no reason for exporting identity_* nor deflate_*, they're only
used in the same file. Mark them static, it will make it easier to add
other algorithms.

10 years agoMINOR: http: check the algo name "identity" instead of the function pointer
Willy Tarreau [Sat, 28 Mar 2015 14:41:42 +0000 (15:41 +0100)] 
MINOR: http: check the algo name "identity" instead of the function pointer

Next patch will statity all compression functions, so let's stop relying
on a function pointer comparison and use the algo name instead.

10 years agoBUG/MINOR: compression: consider the expansion factor in init
Willy Tarreau [Sat, 28 Mar 2015 11:20:33 +0000 (12:20 +0100)] 
BUG/MINOR: compression: consider the expansion factor in init

When checking if the buffer is large enough, we used to rely on a fixed
size that was "apparently" enough. We need to consider the expansion
factor of deflate-encoded streams instead, which is of 5 bytes per 32kB.
The previous value was OK till 128kB buffers but became wrong past that.
It's totally harmless since we always keep the reserve when compressiong,
so there's 1kB or so available, which is enough for buffers as large as
6.5 MB, but better fix the check anyway.

This fix could be backported into 1.5 since compression was added there.

10 years agoMEDIUM: compression: don't send leading zeroes with chunk size
Willy Tarreau [Sat, 28 Mar 2015 11:05:47 +0000 (12:05 +0100)] 
MEDIUM: compression: don't send leading zeroes with chunk size

Till now we used to rely on a fixed maximum chunk size. Thanks to last
commit we're now free to adjust the chunk's length before sending the
data, so we don't have to use 6 digits all the time anymore, and if
one wants buffers larger than 16 MB it is now possible.

10 years agoMEDIUM: compression: postpone buffer adjustments after compression
Willy Tarreau [Sat, 28 Mar 2015 10:10:56 +0000 (11:10 +0100)] 
MEDIUM: compression: postpone buffer adjustments after compression

Till now we used to copy the pending outgoing data into the new buffer,
then compute the chunk size, then compress, then fix the chunk size,
then copy the remaining data into the destination buffer. If the
compression would fail for whatever reason (eg: not enough input bytes
to push an extra block), this work still had to be performed for no
added value. It also presents the disadvantage of having to use a fixed
length to encode the chunk size.

Thanks to the body parser changes that went late into 1.5, the buffers
are not modified anymore during these operations. So this patch rearranges
operations so that they're more optimal :

1) init() prepares a new buffer and reserves space in it for pending
   outgoing data (no copy) and for chunk size
2) data are compressed
3) only if data were added to the buffer, then the old data are copied
   and the chunk size is set.

A few optimisations are still possible to go further :

  - decide whether we prefer to copy pending outgoing data from the
    old buffer to the new one, or pending incoming compressed data
    from the new one to the old one, based on the amount of outgoing
    data available. Given that pending outgoing data are rare and the
    operation could be complex in the presence of extra input data,
    it's probably better to ignore this one ;

  - compute the needed length for the chunk size. This would avoid
    sending lots of leading zeroes when not needed.

10 years agoMEDIUM: check: include server address and port in the send-state header
Joseph Lynch [Fri, 16 Jan 2015 01:52:59 +0000 (17:52 -0800)] 
MEDIUM: check: include server address and port in the send-state header

This fixes an issue that occurs when backend servers run on different
addresses or ports and you wish to healthcheck them via a consistent
port. For example, if you allocate backends dynamically as containers
that expose different ports and you use an inetd based healthchecking
component that runs on a dedicated port.

By adding the server address and port to the send-state header, the
healthcheck component can deduce which address and port to check by
reading the X-Haproxy-Server-State header out of the healthcheck and
parsing out the address and port.

10 years agoMEDIUM: lua: implement a simple memory allocator
Willy Tarreau [Wed, 18 Mar 2015 16:54:59 +0000 (17:54 +0100)] 
MEDIUM: lua: implement a simple memory allocator

Lua supports a memory allocator. This is very important as it's the
only way we can control the amount of memory allocatable by Lua scripts.
That avoids prevents bogus scripts from eating all of the system's memory.
The value can be enforced using tune.lua.maxmem in the global section.

10 years agoBUG/MINOR: lua: Fix SSL initialisation
Thierry FOURNIER [Tue, 17 Mar 2015 15:48:53 +0000 (16:48 +0100)] 
BUG/MINOR: lua: Fix SSL initialisation

This new initialisation mode for the SSL make easiest the arguments
declaration. In other way, this patch fix a bug in the SSL
initialisation.

10 years agoMINOR: lua: add log functions
Thierry FOURNIER [Tue, 17 Mar 2015 00:09:57 +0000 (01:09 +0100)] 
MINOR: lua: add log functions

Thispatch adds global log function. Each log message is writed on
the stderr and is sent to the default syslog server. These two
actions are done according the configuration.

10 years agoDOC: lua: fix some typos
Thierry FOURNIER [Mon, 16 Mar 2015 14:13:03 +0000 (15:13 +0100)] 
DOC: lua: fix some typos

The class name before the function doesn't have the same
syntax than the declared class names.

The return code is not declared in the prototype of the function.

After the last API modification, the hello world example does not
yet run.

10 years agoMINOR: lua: create and register HTTP class
Thierry FOURNIER [Mon, 16 Mar 2015 13:17:08 +0000 (14:17 +0100)] 
MINOR: lua: create and register HTTP class

This class is accessible via the TXN object. It is created only if
the attached proxy have HTTP mode. It contain all the HTTP
manipulation functions:

 - req_get_headers
 - req_del_header
 - req_rep_header
 - req_rep_value
 - req_add_header
 - req_set_header
 - req_set_method
 - req_set_path
 - req_set_query
 - req_set_uri

 - res_get_headers
 - res_del_header
 - res_rep_header
 - res_rep_value
 - res_add_header
 - res_set_header

10 years agoMINOR: lua: txn: add function set_(loglevel|tos|mark)
Thierry FOURNIER [Mon, 16 Mar 2015 11:04:16 +0000 (12:04 +0100)] 
MINOR: lua: txn: add function set_(loglevel|tos|mark)

This patch adds the "loglevel", "tos" and "mark" manipulation related to
one transaction.

10 years agoMINOR: http: export function inet_set_tos()
Thierry FOURNIER [Mon, 16 Mar 2015 11:03:44 +0000 (12:03 +0100)] 
MINOR: http: export function inet_set_tos()

This is used by Lua.

10 years agoMINOR: http: split http_transform_header() function in two parts.
Thierry FOURNIER [Mon, 16 Mar 2015 10:15:50 +0000 (11:15 +0100)] 
MINOR: http: split http_transform_header() function in two parts.

This function is a callback for HTTP actions. This function
creates the replacement string from a build_logline() format
and transform the header.

This patch split this function in two part. With this modification,
the header transformation and the replacement string are separed.

We can now transform the header with another replacement string
source than a build_logline() format.

10 years agoMINOR: http: split the function http_action_set_req_line() in two parts
Thierry FOURNIER [Sat, 14 Mar 2015 12:55:46 +0000 (13:55 +0100)] 
MINOR: http: split the function http_action_set_req_line() in two parts

The first part is the replacement engine. It take a replacement action
number and a replacement string and process the action.

The second part is the function which is called by the 'http-request
action' to replace a request line part. This function makes the
string used as replacement.

This split permits to use the replacement engine in other parts of the
code than the request action. The Lua use it for his own http action.

10 years agoMEDIUM: http: allows 'R' and 'S' in the protocol alphabet
Thierry FOURNIER [Sat, 28 Feb 2015 18:03:56 +0000 (19:03 +0100)] 
MEDIUM: http: allows 'R' and 'S' in the protocol alphabet

This patch allow the 'R' and the 'S' in the protocol/version
alphabet. It permits to process RTSP requests like HTTP.

10 years agoBUILD: fix automatic inclusion of libdl.
Willy Tarreau [Tue, 17 Mar 2015 13:33:22 +0000 (14:33 +0100)] 
BUILD: fix automatic inclusion of libdl.

Last commit ecc9547 ("BUILD: lua: it miss the '-ldl' directive") broke
build on systems without libdl (eg: FreeBSD). Since lua requires libdl
on some systems, let's simplify this by adding a USE_DL build directive
to enable/disable use of libdl. It's set by default on all linux flavors.