Commit Graph

4609 Commits

Author SHA1 Message Date
Willy Tarreau
042cd75bc2 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.
2015-04-08 18:10:49 +02:00
Willy Tarreau
1b90511eeb 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.
2015-04-08 17:31:40 +02:00
Thierry FOURNIER
3def393f8d 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.
2015-04-07 15:56:21 +02:00
Thierry FOURNIER
04c57b3357 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.
2015-04-07 15:56:14 +02:00
Thierry FOURNIER
2e4893cb7f DOC: lua: some fixes
- remove trailing spces
 - update fetches ans converters documentation
2015-04-07 15:55:58 +02:00
Willy Tarreau
d414f8e8b7 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.
2015-04-06 11:43:45 +02:00
Willy Tarreau
0c5c68ec28 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.
2015-04-06 11:37:36 +02:00
Willy Tarreau
7ddf7c5641 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.
2015-04-06 11:37:36 +02:00
Willy Tarreau
61cf7c885d MINOR: lua: minor cleanup in hlua_socket_new()
Just limit the number of dereferences of socket-> since we allocate
the stream at the beginning.
2015-04-06 11:37:36 +02:00
Willy Tarreau
d420a975d7 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.
2015-04-06 11:37:36 +02:00
Willy Tarreau
d1769b8b9a 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
fb9f584956 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
c8815efb06 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
e0232f1e33 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
f9d1bc6d9a 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
99eb0f13bc 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.
2015-04-06 11:37:35 +02:00
Willy Tarreau
02d863866d 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.
2015-04-06 11:37:34 +02:00
Willy Tarreau
c5a7ff4a86 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.
2015-04-06 11:37:34 +02:00
Willy Tarreau
342bfb180c 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.
2015-04-06 11:37:34 +02:00
Willy Tarreau
470280ef63 MEDIUM: stream: also accept appctx as origin in stream_accept_session()
It's likely that the code could be simplified a bit though.
2015-04-06 11:37:34 +02:00
Willy Tarreau
f2b9874bcf 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).
2015-04-06 11:37:34 +02:00
Willy Tarreau
ce7eec9186 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.
2015-04-06 11:37:33 +02:00
Willy Tarreau
18b95a4b27 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.
2015-04-06 11:37:33 +02:00
Willy Tarreau
8baf906366 MEDIUM: peers: initialize the task before the stream
Thanks to this we should be able to make use of stream_accept_session()
now.
2015-04-06 11:37:33 +02:00
Willy Tarreau
4099a7c273 MINOR: peers: make use of session_new() when creating a new session
It's better than open-coding it.
2015-04-06 11:37:33 +02:00
Willy Tarreau
64beab202c MINOR: session: make use of session_new() when creating a new session
It's better than open-coding it.
2015-04-06 11:37:33 +02:00
Willy Tarreau
c38f71cfcd MINOR: session: introduce session_new()
This one creates a new session and does the minimum initialization.
2015-04-06 11:37:33 +02:00
Willy Tarreau
d990baf0cc 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().
2015-04-06 11:37:32 +02:00
Willy Tarreau
a7513f5d00 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.
2015-04-06 11:37:32 +02:00
Willy Tarreau
9903f0e1a2 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.
2015-04-06 11:37:32 +02:00
Willy Tarreau
32990b531b 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.
2015-04-06 11:37:32 +02:00
Willy Tarreau
02a0c0e407 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.
2015-04-06 11:37:32 +02:00
Willy Tarreau
5ecb069c58 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.
2015-04-06 11:37:31 +02:00
Willy Tarreau
1df0cc6466 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().
2015-04-06 11:37:31 +02:00
Willy Tarreau
e73ef85a63 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.
2015-04-06 11:37:31 +02:00
Willy Tarreau
70f454e8fa 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.
2015-04-06 11:37:31 +02:00
Willy Tarreau
bb2ef12a60 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.
2015-04-06 11:37:31 +02:00
Willy Tarreau
8b7f8688ee 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.
2015-04-06 11:37:31 +02:00
Willy Tarreau
7698c9080a 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.
2015-04-06 11:37:30 +02:00
Willy Tarreau
b2bf8331fb 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.
2015-04-06 11:37:30 +02:00
Willy Tarreau
11c3624c32 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.
2015-04-06 11:37:30 +02:00
Willy Tarreau
8d2eca73eb 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.
2015-04-06 11:37:30 +02:00
Willy Tarreau
7ea671b914 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.
2015-04-06 11:37:30 +02:00
Willy Tarreau
15b5e14faa 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.
2015-04-06 11:37:29 +02:00
Willy Tarreau
1f52bb27ec 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.
2015-04-06 11:37:29 +02:00
Willy Tarreau
d0d8da989b 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().
2015-04-06 11:37:29 +02:00
Willy Tarreau
192252e2d8 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
2015-04-06 11:37:25 +02:00
Willy Tarreau
fdcd2ae1f8 CLEANUP: lua: don't pass http_txn anymore to hlua_request_act_wrapper()
It doesn't use it anymore at all.
2015-04-06 11:35:53 +02:00
Willy Tarreau
987e3fb868 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.
2015-04-06 11:35:53 +02:00
Willy Tarreau
f3bf3050a1 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.
2015-04-06 11:35:53 +02:00