]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: lua: sample fetches based on response doesn't work
authorThierry FOURNIER <tfournier@arpalert.org>
Mon, 2 Nov 2015 09:01:59 +0000 (10:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 3 Nov 2015 09:50:14 +0000 (10:50 +0100)
The direction (request or response) is not propagated in the
sample fecthes called throught Lua. This patch adds the direction
status in some structs (hlua_txn and hlua_smp) to make sure that
the sample fetches will be called with all the information.

The converters can not access to a TXN object, so there are not
impacted the direction. However, the samples used as input of the
Lua converter wrapper are initiliazed with the direction. Thereby,
the struct smp stay consistent.
[wt: needs to be backported to 1.6]

include/types/hlua.h
src/hlua.c

index 48f7487f1ecc94d6954bfdba7d7a0f568c865f24..a9b6498f383ffe376d2e5a013377761ba219d320 100644 (file)
@@ -100,6 +100,7 @@ struct hlua_rule {
 struct hlua_txn {
        struct stream *s;
        struct proxy *p;
+       int dir;                /* SMP_OPT_DIR_{REQ,RES} */
 };
 
 /* This struct contains the applet context. */
@@ -114,6 +115,7 @@ struct hlua_smp {
        struct stream *s;
        struct proxy *p;
        int stringsafe;
+       int dir;                /* SMP_OPT_DIR_{REQ,RES} */
 };
 
 /* This struct contains data used with sleep functions. */
index 016aead824d89ad73b52442095bbbd42b5f73ead..8fc85a650d878ff0e6e048c714a51f1d0194949a 100644 (file)
@@ -2979,6 +2979,7 @@ static int hlua_fetches_new(lua_State *L, struct hlua_txn *txn, int stringsafe)
 
        hsmp->s = txn->s;
        hsmp->p = txn->p;
+       hsmp->dir = txn->dir;
        hsmp->stringsafe = stringsafe;
 
        /* Pop a class sesison metatable and affect it to the userdata. */
@@ -3032,7 +3033,7 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
        smp.px = hsmp->p;
        smp.sess = hsmp->s->sess;
        smp.strm = hsmp->s;
-       smp.opt = 0;
+       smp.opt = hsmp->dir & SMP_OPT_DIR;
        if (!f->process(args, &smp, f->kw, f->private)) {
                if (hsmp->stringsafe)
                        lua_pushstring(L, "");
@@ -3086,6 +3087,7 @@ static int hlua_converters_new(lua_State *L, struct hlua_txn *txn, int stringsaf
 
        hsmp->s = txn->s;
        hsmp->p = txn->p;
+       hsmp->dir = txn->dir;
        hsmp->stringsafe = stringsafe;
 
        /* Pop a class stream metatable and affect it to the table. */
@@ -3154,7 +3156,7 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
        smp.px = hsmp->p;
        smp.sess = hsmp->s->sess;
        smp.strm = hsmp->s;
-       smp.opt = 0;
+       smp.opt = hsmp->dir & SMP_OPT_DIR;
        if (!conv->process(args, &smp, conv->private)) {
                if (hsmp->stringsafe)
                        lua_pushstring(L, "");
@@ -4591,7 +4593,7 @@ __LJMP static int hlua_get_priv(lua_State *L)
  * return 0 if the stack does not contains free slots,
  * otherwise it returns 1.
  */
-static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p)
+static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir)
 {
        struct hlua_txn *htxn;
 
@@ -4610,6 +4612,7 @@ static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p)
 
        htxn->s = s;
        htxn->p = p;
+       htxn->dir = dir;
 
        /* Create the "f" field that contains a list of fetches. */
        lua_pushstring(L, "f");
@@ -5241,7 +5244,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
                lua_rawgeti(stream->hlua.T, LUA_REGISTRYINDEX, fcn->function_ref);
 
                /* push arguments in the stack. */
-               if (!hlua_txn_new(stream->hlua.T, stream, smp->px)) {
+               if (!hlua_txn_new(stream->hlua.T, stream, smp->px, smp->opt & SMP_OPT_DIR)) {
                        SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
                        RESET_SAFE_LJMP(stream->hlua.T);
                        return 0;
@@ -5482,7 +5485,7 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
                lua_rawgeti(s->hlua.T, LUA_REGISTRYINDEX, rule->arg.hlua_rule->fcn.function_ref);
 
                /* Create and and push object stream in the stack. */
-               if (!hlua_txn_new(s->hlua.T, s, px)) {
+               if (!hlua_txn_new(s->hlua.T, s, px, dir)) {
                        SEND_ERR(px, "Lua function '%s': full stack.\n",
                                 rule->arg.hlua_rule->fcn.name);
                        RESET_SAFE_LJMP(s->hlua.T);