Commit Graph

4433 Commits

Author SHA1 Message Date
Thierry FOURNIER
0054392509 BUG/MINOR: lua: sockets receive behavior doesn't follows the specs
Specs says that the receive() function with an argument "*l"
must return a line without the final "\n" ( or without "\r\n").
This patch removes these two final bytes.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
95ad96a7ea BUG/MEDIUM: lua: cannot connect socket
The Lua stack is not waked up when the connect() receive a positive
or negatibe response. This patch adds a signal to wake up the Lua
stack.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
486d52a2a3 BUG/MEDIUM: lua: sockets don't have buffer to write data
When we try to write data in a session from another session, the "req"
buffer is not allowed. This patch try to allocate the buffer. The session
wait if the buffer is not yet avalaible.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
e83766afd1 BUG/MINOR: log: segfault if there are no proxy reference
The HAProxy API allow to send log without defined proxy (it
set to the NULL value). An incomplete test if done to choose
the log tag and an invalid pointer is dereferenced.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
4a6170cce1 BUG/MINOR: lua: check buffers before initializing socket
When a socket is initilized in the body context, a segfaut is generated
because the memory pools are not initilized. This atch check if these
memory pool are initialized.
2015-03-09 18:46:48 +01:00
Thierry FOURNIER
d2b597aa10 BUG/MEDIUM: lua: segfault with buffer_replace2
The function buffer_contig_space() returns the contiguous space avalaible
to add data (at the end of the input side) while the function
hlua_channel_send_yield() needs to insert data starting at p. Here we
introduce a new function bi_space_for_replace() which returns the amount
of space that can be inserted at the head of the input side with one of
the buffer_replace* functions.

This patch proposes a function that returns the space avalaible after buf->p.
2015-03-09 18:12:59 +01:00
Thierry FOURNIER
cd9084f776 BUG/MEDIUM: lua: can't handle the response bytes
The request action can't handle the reponse trafic because its
automatically forwarded. The forard with CHN_INFINITE_FORWARD
is set because any anamizers are registered on  the response
channel.

This patch automatically register the request analyzer on the
reponse channel when its yield. This prevent the automatic
tranfer of the response bytes.
2015-03-09 17:50:42 +01:00
Thierry FOURNIER
cae49c9ee8 BUG/MAJOR: lua: some function are not yieldable, the forced yield causes errors
The hook function called each nth Lua instructions just
do a yield. Sometimes this yield is not allowed, because
some functions are not compatible.

The Lua-5.3 permits to known if the yield is avalaible with
the function lua_isyieldable().

If the processing is interrupted in non yieldable state,
we try to execute a yield asap. The yield will be may
available at the end of the non-yieldable currently
executed function. So, we require interrupt at the end
of the current function.

But, Lua cannot yield when its returning from a function,
so, we can fix the interrupt hook to 1 instruction,
expecting that the function is finnished.

During this time, the execution timeout is always checked.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
f90838b71a MEDIUM: lua: use the Lua-5.3 version of the library
The Lua-5.3 version of the library adds a required function to fix
a bug with the forced-yield system.

This patch permits to build with the Lua-5.3 library. Main changes
are:
 - "unsigned" type disappear to be replaced by signed type,
 - prototype of the yield function callback changes.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
deb5d73883 BUG/MEDIUM: lua: many errors when we try to send data with the channel API
First we allow to use the reserved size to write the data that
will be sent. The reserved size remain guaranty because the
writed data will be sent quickly and the reserved room we be
again avalaible.

This permits to guaranty that the function send always have
avalaible space to send data (except if it cannot connect to
the server).

The function buffer_replace2 works only on contiguous buffer.
This patch also detects if the required size is contiguous.
If it not the case we realign the buffer.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
53e08ecc41 BUG/MEDIUM: lua: the Lua process is not waked up after sending data on requests side
If we are writing in the request buffer, we are not waked up
when the data are forwarded because it is useles. The request
analyzers are waked up only when data is incoming. So, if the
request buffer is full, we set the WAKE_ON_WRITE flag.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
ef6a2115fd BUG/MEDIUM: lua: fix infinite loop about channel
Before this patch, each yield in a Lua action set a flags to be
waked up when some activity were detected on the response channel.
This behavior causes loop in the analyzer process.

This patch set the wake up on response buffer activity only if we
really want to be waked up on this activity.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
1bfc09b4cf BUG/MEDIUM: lua: reset flags before resuming execution
This patch reset the flags except th run flag before resuming
the Lua execution. If this initialisation is not done, some
flags can remain at the end of the Lua execution and give bad
informations.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
3e3a608f19 BUG/MINOR: lua: set buffer if it is nnot avalaible.
Check if the buffer is avalaible because HAProxy doesn't allocate
the request buffer if its not required. Sometimes, the Lua need to
write some data to the server before that the client send his data.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
bd1f1325e1 MINOR: lua: add the struct session in the lua channel struct
This is used later to modify some flags in the session.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
90da191345 DOC: lua: Lua configuration documentation
This patch adds the documentation of the Lua configuration directives.
The documentation was read back by Andjelko Iharos.
2015-03-09 17:47:52 +01:00
Thierry FOURNIER
dc9ca96a11 BUG/MEDIUM: lua: the execution timeout is ignored in yield case
This patch check the expiration of the execution timeout for each
yield source, and test also the execution timeout before resuming
the execution of the Lua code.
2015-03-05 11:50:01 +01:00
Willy Tarreau
c46c965540 BUG/MEDIUM: task: fix recently introduced scheduler skew
Commit 501260b ("MEDIUM: task: always ensure that the run queue is
consistent") introduced a skew in the scheduler : if a negatively niced
task is woken up, it can be inserted prior to the current index and will
be skipped as long as there is some activity with less prioritary tasks.
The immediate effect is that it's not possible to get access to the stats
under full load until the load goes down.

This is because the rq_next constantly evolves within more recent
positions. The fix is simple, __task_wakeup() must empty rq_next. The
sad thing is that this issue was fixed during development and missed
during the commit. No backport is needed, this is purely 1.6 stuff.
2015-03-05 11:49:17 +01:00
Thierry FOURNIER
d44731fca0 MEDIUM: lua: change the sleep function core
This patch uses the last yield functionalities. The sleep function
just return the wake up time.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
ee9f802c4f MEDIUM: lua: interrupt the Lua execution for running other process
This patch permits to interrupt the Lua execution each n# of
instructions. It is useful for controling the execution time
of an Lua code, and permits at the HAProxy schedule to process
some others tasks waiting execution.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
4abd3ae184 MINOR: lua: adds "forced yield" flag
This flag indicate that the current yield is returned by the Lua
execution task control. If this flag is set, the current task may
quit but will be set in the run queue to be re-executed immediatly.

This patch modify the "hlua_yieldk()" function, it adds an argument
that contain a field containing yield options.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
c42c1ae885 MEDIUM: lua: each yielding function returns a wake up time.
This is used to ensure that the task doesn't become a zombie
when the Lua returns a yield. The yield wrapper ensure that an
timer used for waking up the task will be set.

The timer is reseted to TICK_ETERNITY if the Lua execution is
done.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
bd41349831 MINOR: lua: set skeleton for Lua execution expiration
This first patch permits to cofigure the Lua execution exipiration.
This expiration is configured but it is not yet avalaible, it will
be add in a future patch.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
a097fdfb62 MINOR: lua: use bitfield and macro in place of integer and enum
In the future, the lua execution must return scheduling informations.
We want more than one flag, so I convert an integer used with an
enum into an interer used as bitfield.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
a718b29b6d MINOR: lua: remove some #define
The #define compilation directives are centralized in the hlua
include files. This permits to remove ome #ifdef from the haproxy
main code.
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
5c49aeb1b0 MINOR: remove unused declaration.
This declaration is removed in the patch 'Lua initialisation on demand".
commit id 05ac42455f
2015-03-04 17:58:52 +01:00
Thierry FOURNIER
506e46c352 BUG/MAJOR: lua: send function fails and return bad bytes
In some cases the Lua "send" function fails. This is caused by the
return of "buffer_replace2()" is not tested. I checked avalaible space
in the buffer and I supposed than "buffer_replace2()" took all the
data. In some cases, "buffer_replace2()" cannot take the incoming
data, it returns the amount of data copied.

This patch check the amount of data really copied by "buffer_replace2()"
and advance the buffer with taking this value in account.
2015-03-04 13:36:41 +01:00
Cyril Bonté
d1039e5dc5 BUILD/CLEANUP: systemd: avoid a warning due to mixed code and declaration
Gcc complains because the systemd wrapper mixed code and declaration :
"warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]".
2015-03-04 10:11:57 +01:00
Cyril Bonté
c21adb5b00 BUILD: try to automatically detect the Lua library name
Depending on the distribution, the Lua library can have different names.
Some distributions will require -llua5.2, others -llua52, and other systems may
require -llua.

Now, the Makefile will try to guess the library name, in order of priority :
"lua5.2", "lua52", or "lua".
2015-03-04 10:11:57 +01:00
Baptiste Assmann
84bb49328d BUILD: lua: missing ifdef related to SSL when enabling LUA
A couple of ifdef are missing around SSL related functions in LUA.
It prevents from compiling LUA without SSL.
Current patch fix this.
2015-03-03 13:17:28 +01:00
Cyril Bonté
928ae5c822 BUG/MEDIUM: lua: segfault when calling haproxy sample fetches from lua
When a Lua script calls an internal haproxy sample fetch, it may segfault in
some conditions :
- when a fetch has no argument,
- when there is no room left to store the special type ARGT_STOP in the argument
  list (this one shouldn't happen currently as there isn't any sample fetch with
  enough arguments to fill the allocated buffer).

Example of Lua code which reproduces a segfault :
core.register_fetches("segfault", function(txn, ...)
  return txn.req_ver(txn)
end)
2015-03-02 13:41:09 +01:00
Cyril Bonté
dc0306e3e4 MINOR: lua: add a compilation error message when compiled with an incompatible version
haproxy Lua support begins with Lua 5.2. In order to ease the diagnostic on
compilation error, a preprocessor error is added when an incompatible version
is used.

The compatibility is determined by the presence of LUA_VERSION_NUM and its
magic value (502 for Lua 5.2.x).
2015-03-02 13:41:09 +01:00
Cyril Bonté
47eb2193d7 MINOR: report the Lua version in -vv
As of the other libraries used by haproxy, it can be useful to display the Lua
version used at compilation time.
A new line is added to "haproxy -vv", which shows if Lua is supported by the
binary, and with which version it was compiled.
2015-03-02 13:41:09 +01:00
Cyril Bonté
577a36a174 MINOR: lua: typo in an error message
A small typo was introduced in an error message, occuring when too many
arguments are provided ("Malformed argument mask").
2015-03-02 13:41:09 +01:00
Thierry FOURNIER
05ac42455f MEDIUM: lua: Lua initialisation "on demand"
Actually, the Lua context is always initilized in each
session, even if the session doesn't use Lua. This
behavior cause 5% performances loss.

This patch initilize the Lua only if it is use by the
session. The initialization is now on demand.
2015-02-28 23:12:37 +01:00
Willy Tarreau
80f5fae591 BUILD: lua: cleanup many mixed occurrences declarations & code
The code was a bit of a pain to follow because of this, especially
when some of it heavily relies on longjmp... This refreshing makes
it slightly easier to read.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
893bfa3492 MINOR: lua: txn: add binding for closing the client connection. 2015-02-28 23:12:36 +01:00
Thierry FOURNIER
13416fe0db MINOR: lua: core: can yield an execution stack
This patch provides a yield function. This function permits to
give back the hand at the HAProxy scheduler. It is used when the
lua processing consumes a lot of time.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
37196f4ecb MINOR: lua: core: can set the nice of the current task
This patch adds an LUA binding that permits to change the
task priority.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
e94e77400a MINOR: lua: txn: object "txn" provides two objects "channel"
This patch adds two functions that creates and returns channel
object from a txn object.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
5a6d3fdf51 MINOR: lua: channel: add "channel" class
The channel class permits manipulation of channels. A channel is
an FIFO buffer between the client and the server. This class provides
function to read, write, forward, destroy and alter data between
the input and the ouput of the buffer.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
83758bbee7 MINOR: lua: core: pattern and acl manipulation
The functions added by this patch add LUA bindings for the ACL
and map manipulation.
2015-02-28 23:12:36 +01:00
Thierry FOURNIER
7e7ac32dad MEDIUM: lua: socket: add "socket" class for TCP I/O
This patch adds the TCP I/O functionnality. The class implemented
provides the same functions than the "lua socket" project. This
make network compatibility with another LUA project. The documentation
is located here:

   http://w3.impa.br/~diego/software/luasocket/tcp.html
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
5b8608f1ed MINOR: lua: core: add sleep functions
This version of sleep is based on a coroutine. A sleeping
task is started and a signal is registered. This sleep version
must disapear to be replaced by a version using the internal
timers.
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
258d8aafa6 MINOR: lua: add bindings for tcp and http actions
This patch adds the runtime environment for http and tcp actions.
It provides also the function for action registering.
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
9be813f861 MINOR: lua: register and execute converters in LUA
This patch permits to write LUA converters. Note that
all the converters declared trough LUA are automatically
prefixed by "lua.".

The Lua converters needs the current session to be executed,
but the writed and executed Lua code must be static and
contextless. The TXN object is not created for the converters.
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
fa0e5dd217 MINOR: lua: register and execute sample-fetches in LUA
This patch permits to write LUA samples fetches. Note that
all the fethes declared trough LUA are automatically prefixed
by "lua.".
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
9a819e7305 MINOR: lua: txn: add lua function in TXN that returns an array of http headers
This patch adds an LUA binding that returns an array of
HTTP headers. The key is the header name and the value is
the header value.
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
d0fa538fe3 MINOR: lua: txn: import existing sample-fetches in the class TXN
This patch adds the browsing of all the HAProxy fetches and
create associated LUA functions. The HAProxy internal fetches
can be used in LUA trough the class "TXN".

Note that the symbols "-", "+" and "." in the name of current
sample fetch are rewrited as "_" in LUA because ".", "-" and "+"
are operators.
2015-02-28 23:12:35 +01:00
Thierry FOURNIER
05c0b8ab0d MINOR: lua: add shared context in the lua stack
The shared context is a global reference dedicated to one Lua stack.
Even if the TXN is not required, the shared context it is associated
with a TXN object. In fact, the shared has no sense outside a TXN
context
2015-02-28 23:12:34 +01:00