Commit Graph

128 Commits

Author SHA1 Message Date
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
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
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
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
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
Willy Tarreau
15e91e1b36 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.
2015-04-06 11:35:53 +02:00
Willy Tarreau
eee5b51248 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.
2015-04-06 11:35:52 +02:00
Willy Tarreau
cb7dd015be 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.
2015-04-06 11:35:52 +02:00
Willy Tarreau
9ad7bd48d2 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.
2015-04-06 11:34:29 +02:00
Willy Tarreau
40606ab976 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.
2015-04-06 11:23:58 +02:00
Willy Tarreau
e36cbcb3b0 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.
2015-04-06 11:23:58 +02:00
Willy Tarreau
fb0afa77c9 MEDIUM: stream: move the listener's pointer to the session
The listener is session-specific, move it there.
2015-04-06 11:23:57 +02:00
Willy Tarreau
feb764040d MEDIUM: stream: allocate the session when a stream is created
This is where we'll put some session-wide information.
2015-04-06 11:23:57 +02:00
Willy Tarreau
b1ec8c4a59 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.
2015-04-06 11:23:57 +02:00
Willy Tarreau
e7dff02dd4 REORG/MEDIUM: stream: rename stream flags from SN_* to SF_*
This is in order to keep things consistent.
2015-04-06 11:23:57 +02:00
Willy Tarreau
87b09668be 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.
2015-04-06 11:23:56 +02:00
Willy Tarreau
7073c471a1 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.
2015-04-06 11:23:23 +02:00
Willy Tarreau
da5f10827b 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.
2015-04-06 11:23:23 +02:00
Willy Tarreau
bcb39cc339 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.
2015-04-06 11:23:23 +02:00
Willy Tarreau
9a8ad86648 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.
2015-04-06 11:14:06 +02:00
Willy Tarreau
b2ccb5644b 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.
2015-04-06 11:11:15 +02:00
Willy Tarreau
de49138b9c 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.
2015-04-06 11:04:28 +02:00
Willy Tarreau
07081fe6b7 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.
2015-04-06 10:59:20 +02:00
Willy Tarreau
08ef3d055d 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.
2015-04-06 10:54:36 +02:00
Willy Tarreau
482564f309 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.
2015-04-06 10:43:23 +02:00
Willy Tarreau
32f61e288d 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.
2015-03-18 17:54:59 +01:00
Thierry FOURNIER
36d1374484 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.
2015-03-18 11:34:06 +01:00
Thierry FOURNIER
c798b5d282 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.
2015-03-18 11:34:06 +01:00
Thierry FOURNIER
08504f4e19 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
2015-03-18 11:34:06 +01:00
Thierry FOURNIER
2cce3538ca MINOR: lua: txn: add function set_(loglevel|tos|mark)
This patch adds the "loglevel", "tos" and "mark" manipulation related to
one transaction.
2015-03-18 11:34:06 +01:00
Thierry FOURNIER
a85cfb1db5 BUG/MEDIUM: lua: undetected infinite loop
If the Lua code causes an infinite loop without yield possible, the
clock is not updated. This patch check the clock when the Lua control
code cannot yield.
2015-03-14 15:54:35 +01:00
Willy Tarreau
94aa6170cd CLEANUP: lua: don't use si_ic/si_oc on known stream-ints
When we explicitly write si[0] or si[1], we know whether we're working
with s->req or s->res, so better use that instead of si_ic/si_oc(), to
make the code simpler and more readable.
2015-03-13 14:19:06 +01:00
Thierry FOURNIER
3caa0399c8 BUG/MINOR: lua: set current proxy as default value if it is possible
Some fetches uses a proxy name as first parameter. This is used to identify
frontend, backend or table. This first argument is declared as mandatory,
but the documentation says that is optional.

The behavior of the function smp_resolve_args() is to use the current proxy
if it match the required argument.

This patch implements the same behavior in the Lua argument checker for
sample-fetches and sample-converters.
2015-03-13 14:10:35 +01:00
Thierry FOURNIER
dd6f4b43e2 BUG/MINOR: lua: error in detection of mandatory arguments
The last mandatory arguments in sample fetches or converters are
ignored. This is due to a bad control.
2015-03-13 14:10:33 +01:00
Thierry FOURNIER
7f4942a978 MEDIUM: lua: automatically converts strings in proxy, tables, server and ip
This patch adds automatic solve of proxy, table and server names.
If ips or masks are required, they try to convert from the input
string.
2015-03-13 14:10:27 +01:00
Thierry FOURNIER
53dd3cf76b BUG/MEDIUM: lua: bad argument number in analyser and in error message
The first argument in the stack is 1 and not 0. So the analyzer
starts at bad argument number, and the error message contains
also bad argument number.
2015-03-13 14:10:20 +01:00
Willy Tarreau
bc18da17aa MEDIUM: channel: don't always set CF_WAKE_WRITE on bi_put*
It was inappropriate to put this flag on every failed write into an
input buffer because it depends where it happens. When it's in the
context of an analyser (eg: hlua) it makes sense. When it's in the
context of an applet (eg: dumpstats), it does not make sense, and
it only happens to work because currently applets are scheduled by
the sessions. The proper solution for applets would be to add the
flag SI_FL_WAIT_ROOM on the stream interface.

Thus, we now don't set any flag anymore in bi_put* and it's up to the
caller to either set CF_WAKE_WRITE on the channel or SI_FL_WAIT_ROOM
on the stream interface. Changes were applied to hlua, peers and
dumpstats.
2015-03-13 14:00:47 +01:00
Willy Tarreau
2ec2274f90 MEDIUM: lua: remove hlua_sample_fetch
This struct used to carry only a sample fetch function. Thanks to
lua_pushuserdata(), we don't need to have the Lua engine allocate
that struct for us and we can simply push our pointer onto the stack.
This makes the code more readable by removing several occurrences of
"f->f->". Just like the previous patch, it comes with the nice effect
of saving about 1.3% of performance when fetching samples from Lua.
2015-03-11 20:41:47 +01:00
Willy Tarreau
47860ed505 MEDIUM: lua: remove struct hlua_channel
Since last cleanups, this one was only used to carry a struct channel.
Removing it makes the code a bit cleaner (no more chn->chn) and easier
to follow (no more abstraction for a common type). Interestingly it
happens to also make the Lua code slightly faster (about 1.5%) when
using channels, probably thanks to less pointer dereferences and maybe
the use of lua_pushlightuserdata().
2015-03-11 20:41:47 +01:00
Willy Tarreau
2a71af4c4f CLEANUP: lua: hlua_channel_new() doesn't need the pointer to the session anymore
Let's remove it now.
2015-03-11 20:41:47 +01:00
Willy Tarreau
f6870521e5 CLEANUP: lua: remove the session pointer from hlua_channel
It was only used to find what side the channel belongs to.
2015-03-11 20:41:47 +01:00
Willy Tarreau
6c6dc16505 MEDIUM: lua: use CF_ISRESP to detect the channel's side
Instead of comparing with session's channels, we check the channel's
flags to find what side it belongs to.
2015-03-11 20:41:47 +01:00
Willy Tarreau
78955f4c8b MEDIUM: session: simplify receive buffer allocator to only use the channel
Now that we can get the session from the channel, let's simplify the
prototype of session_alloc_recv_buffer() to only require the channel.
Both the caller and the function are now simplified.
2015-03-11 20:41:47 +01:00