BUG/MINOR: vars: improve accuracy of the rules used to check expression validity
The set-var() expression naturally checks whether expressions are valid
in the context of the rule, but it fails to differentiate frontends from
backends. As such for tcp-content and http-request rules, it will only
accept frontend-compatible sample-fetches, excluding those declared with
SMP_UES_BKEND (a few such as be_id, be_name). For the response it accepts
the backend-compatible expressions only, though it seems that there are
no sample-fetch function that are valid only in the frontend's content,
so that should not cause any problem.
Note that while allowing valid configs to be used, the fix might also
uncover some incorrect configurations where some expressions currently
return nothing (e.g. something depending on frontend declared in a
backend), and which could be rejected, but there does not seem to be
any such keyword. Thus while it should be backported, better not backport
it too far (2.4 and possibly 2.3 only).
(cherry picked from commit 843096d72a4fa2b5b857dde92be9f02258ab2655)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/vars.c b/src/vars.c
index d533b18..6fa894b 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -780,14 +780,30 @@
return ACT_RET_PRS_ERR;
switch (rule->from) {
- case ACT_F_TCP_REQ_SES: flags = SMP_VAL_FE_SES_ACC; break;
- case ACT_F_TCP_REQ_CNT: flags = SMP_VAL_FE_REQ_CNT; break;
- case ACT_F_TCP_RES_CNT: flags = SMP_VAL_BE_RES_CNT; break;
- case ACT_F_HTTP_REQ: flags = SMP_VAL_FE_HRQ_HDR; break;
- case ACT_F_HTTP_RES: flags = SMP_VAL_BE_HRS_HDR; break;
- case ACT_F_TCP_CHK: flags = SMP_VAL_BE_CHK_RUL; break;
- case ACT_F_CFG_PARSER: flags = SMP_VAL_CFG_PARSER; break;
- case ACT_F_CLI_PARSER: flags = SMP_VAL_CLI_PARSER; break;
+ case ACT_F_TCP_REQ_SES:
+ flags = SMP_VAL_FE_SES_ACC;
+ break;
+ case ACT_F_TCP_REQ_CNT:
+ flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_REQ_CNT : SMP_VAL_BE_REQ_CNT;
+ break;
+ case ACT_F_TCP_RES_CNT:
+ flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_RES_CNT : SMP_VAL_BE_RES_CNT;
+ break;
+ case ACT_F_HTTP_REQ:
+ flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR;
+ break;
+ case ACT_F_HTTP_RES:
+ flags = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR;
+ break;
+ case ACT_F_TCP_CHK:
+ flags = SMP_VAL_BE_CHK_RUL;
+ break;
+ case ACT_F_CFG_PARSER:
+ flags = SMP_VAL_CFG_PARSER;
+ break;
+ case ACT_F_CLI_PARSER:
+ flags = SMP_VAL_CLI_PARSER;
+ break;
default:
memprintf(err,
"internal error, unexpected rule->from=%d, please report this bug!",