You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.9 KiB

  1. commit ff96b8bd3f85155f65b2b9c9f046fe3e40f630a4
  2. Author: Christopher Faulet <cfaulet@haproxy.com>
  3. Date: Fri Jul 26 15:09:53 2019 +0200
  4. MINOR: hlua: Add a flag on the lua txn to know in which context it can be used
  5. When a lua action or a lua sample fetch is called, a lua transaction is
  6. created. It is an entry in the stack containing the class TXN. Thanks to it, we
  7. can know the direction (request or response) of the call. But, for some
  8. functions, it is also necessary to know if the buffer is "HTTP ready" for the
  9. given direction. "HTTP ready" means there is a valid HTTP message in the
  10. channel's buffer. So, when a lua action or a lua sample fetch is called, the
  11. flag HLUA_TXN_HTTP_RDY is set if it is appropriate.
  12. (cherry picked from commit bfab2dddad3ded87617d1e2db54761943d1eb32d)
  13. Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
  14. diff --git a/include/types/hlua.h b/include/types/hlua.h
  15. index 70c76852..2f4e38be 100644
  16. --- a/include/types/hlua.h
  17. +++ b/include/types/hlua.h
  18. @@ -43,7 +43,8 @@ struct stream;
  19. #define HLUA_F_AS_STRING 0x01
  20. #define HLUA_F_MAY_USE_HTTP 0x02
  21. -#define HLUA_TXN_NOTERM 0x00000001
  22. +#define HLUA_TXN_NOTERM 0x00000001
  23. +#define HLUA_TXN_HTTP_RDY 0x00000002 /* Set if the txn is HTTP ready for the defined direction */
  24. #define HLUA_CONCAT_BLOCSZ 2048
  25. diff --git a/src/hlua.c b/src/hlua.c
  26. index 36454cdc..d37e3c61 100644
  27. --- a/src/hlua.c
  28. +++ b/src/hlua.c
  29. @@ -6494,6 +6494,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
  30. struct stream *stream = smp->strm;
  31. const char *error;
  32. const struct buffer msg = { };
  33. + unsigned int hflags = HLUA_TXN_NOTERM;
  34. if (!stream)
  35. return 0;
  36. @@ -6517,6 +6518,13 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
  37. consistency_set(stream, smp->opt, &stream->hlua->cons);
  38. + if (stream->be->mode == PR_MODE_HTTP) {
  39. + if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ)
  40. + hflags |= ((stream->txn->req.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
  41. + else
  42. + hflags |= ((stream->txn->rsp.msg_state < HTTP_MSG_BODY) ? 0 : HLUA_TXN_HTTP_RDY);
  43. + }
  44. +
  45. /* If it is the first run, initialize the data for the call. */
  46. if (!HLUA_IS_RUNNING(stream->hlua)) {
  47. @@ -6541,8 +6549,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
  48. lua_rawgeti(stream->hlua->T, LUA_REGISTRYINDEX, fcn->function_ref);
  49. /* push arguments in the stack. */
  50. - if (!hlua_txn_new(stream->hlua->T, stream, smp->px, smp->opt & SMP_OPT_DIR,
  51. - HLUA_TXN_NOTERM)) {
  52. + if (!hlua_txn_new(stream->hlua->T, stream, smp->px, smp->opt & SMP_OPT_DIR, hflags)) {
  53. SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
  54. RESET_SAFE_LJMP(stream->hlua->T);
  55. return 0;
  56. @@ -6759,16 +6766,16 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
  57. struct session *sess, struct stream *s, int flags)
  58. {
  59. char **arg;
  60. - unsigned int analyzer;
  61. + unsigned int hflags = 0;
  62. int dir;
  63. const char *error;
  64. const struct buffer msg = { };
  65. switch (rule->from) {
  66. - case ACT_F_TCP_REQ_CNT: analyzer = AN_REQ_INSPECT_FE ; dir = SMP_OPT_DIR_REQ; break;
  67. - case ACT_F_TCP_RES_CNT: analyzer = AN_RES_INSPECT ; dir = SMP_OPT_DIR_RES; break;
  68. - case ACT_F_HTTP_REQ: analyzer = AN_REQ_HTTP_PROCESS_FE; dir = SMP_OPT_DIR_REQ; break;
  69. - case ACT_F_HTTP_RES: analyzer = AN_RES_HTTP_PROCESS_BE; dir = SMP_OPT_DIR_RES; break;
  70. + case ACT_F_TCP_REQ_CNT: ; dir = SMP_OPT_DIR_REQ; break;
  71. + case ACT_F_TCP_RES_CNT: ; dir = SMP_OPT_DIR_RES; break;
  72. + case ACT_F_HTTP_REQ: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_REQ; break;
  73. + case ACT_F_HTTP_RES: hflags = HLUA_TXN_HTTP_RDY ; dir = SMP_OPT_DIR_RES; break;
  74. default:
  75. SEND_ERR(px, "Lua: internal error while execute action.\n");
  76. return ACT_RET_CONT;
  77. @@ -6821,7 +6828,7 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
  78. lua_rawgeti(s->hlua->T, LUA_REGISTRYINDEX, rule->arg.hlua_rule->fcn.function_ref);
  79. /* Create and and push object stream in the stack. */
  80. - if (!hlua_txn_new(s->hlua->T, s, px, dir, 0)) {
  81. + if (!hlua_txn_new(s->hlua->T, s, px, dir, hflags)) {
  82. SEND_ERR(px, "Lua function '%s': full stack.\n",
  83. rule->arg.hlua_rule->fcn.name);
  84. RESET_SAFE_LJMP(s->hlua->T);
  85. @@ -6864,9 +6871,9 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
  86. case HLUA_E_AGAIN:
  87. /* Set timeout in the required channel. */
  88. if (s->hlua->wake_time != TICK_ETERNITY) {
  89. - if (analyzer & (AN_REQ_INSPECT_FE|AN_REQ_HTTP_PROCESS_FE))
  90. + if (dir & SMP_OPT_DIR_REQ)
  91. s->req.analyse_exp = s->hlua->wake_time;
  92. - else if (analyzer & (AN_RES_INSPECT|AN_RES_HTTP_PROCESS_BE))
  93. + else
  94. s->res.analyse_exp = s->hlua->wake_time;
  95. }
  96. /* Some actions can be wake up when a "write" event