On Sun, 15 Jul 2018 17:14:01 +0100
Alistair Lowe <alist...@skyiot.co.uk> wrote:

> Hi folks,
> I'm looking to use LUA in HAProxy to enable two use cases:
>    1. Redirect a connection based upon inspecting initial traffic for a
>    server name.
>    2. Redirect a connection when the target server closes its connection.
> My understanding is that both of these scenarios should be possible if I
> inspect a connection for its duration, however I'm also wishing to build
> something high-performance and wish for connections to remain primarily in
> TCP pass-through mode, most of the time.
> My questions are:
>    1. What's the most CPU friendly way to inspect a connection for a
>    time-limited period (i.e. what configuration and commands in LUA should I
>    be looking at etc).

I'm not sure to understand your question. You want to analyse received data
before taking a decision ? the Lua receive function doesn't consume CPU while
is waiting for data. Once data are available the function receive() returns
and ou can process these data.

>    2. Is there anyway to trigger a LUA action upon TCP active close from
>    the target?

If you're using http, once the first bytes are send to the client, you can't
send you own response. So the only one case is when th server close without
sending anything.

Maybe you can use a "tcp-response content" Lua function and call dup() function
(https://www.arpalert.org/src/haproxy-lua-api/1.8/index.html#Channel.dup). If
you receive data, it's ok, if the channel is close you receive 'nil' reponse,
and you can send your redirect.

I'm not sure that the dup() function wait for data, and I'm not sure that
HAPRoxy call the Lua function if the client close the connection.


Reply via email to