From: Christopher Faulet Date: Wed, 13 Oct 2021 13:18:36 +0000 (+0200) Subject: MINOR: tcpcheck: Support 2-steps args resolution in defaults sections X-Git-Tag: v2.5-dev10~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ff7de5d6438679c2376611077b5cd58c664f8ea;p=thirdparty%2Fhaproxy.git MINOR: tcpcheck: Support 2-steps args resolution in defaults sections With the commit eaba25dd9 ("BUG/MINOR: tcpcheck: Don't use arg list for default proxies during parsing"), we restricted the use of sample fetch in tcpcheck rules defined in a defaults section to those depending on explicit arguments only. This means a tcpcheck rules defined in a defaults section cannot rely on argument unresolved during the configuration parsing. Thanks to recent changes, it is now possible again. This patch is mandatory to support TCP/HTTP rules in defaults sections. --- diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index e2f412de93..d079ecf40b 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -333,6 +333,15 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } + if (curr_defproxy && (curr_defproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) && + (curproxy->cap & PR_CAP_LISTEN) == PR_CAP_BE) { + /* If the current default proxy defines tcpcheck rules, the + * current proxy will keep a reference on it. but only if the + * current proxy has the backend capability. + */ + proxy_ref_defaults(curproxy, curr_defproxy); + } + if (rc & PR_CAP_DEF) { /* last and current proxies must be updated to this one */ curr_defproxy = last_defproxy = curproxy; diff --git a/src/log.c b/src/log.c index 11b422680f..2456754349 100644 --- a/src/log.c +++ b/src/log.c @@ -418,7 +418,7 @@ int add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct prox cmd_arg = 0; expr = sample_parse_expr(cmd, &cmd_arg, curpx->conf.args.file, curpx->conf.args.line, err, - (curpx->cap & PR_CAP_DEF) ? NULL: &curpx->conf.args, endptr); + &curpx->conf.args, endptr); if (!expr) { memprintf(err, "failed to parse sample expression <%s> : %s", text, *err); goto error_free; diff --git a/src/tcpcheck.c b/src/tcpcheck.c index aa6db673a4..b782796732 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -2431,7 +2431,7 @@ struct tcpcheck_rule *parse_tcpcheck_connect(char **args, int cur_arg, struct pr px->conf.args.ctx = ARGC_SRV; port_expr = sample_parse_expr((char *[]){args[cur_arg], NULL}, &idx, - file, line, errmsg, (px->cap & PR_CAP_DEF) ? NULL: &px->conf.args, NULL); + file, line, errmsg, &px->conf.args, NULL); if (!port_expr) { memprintf(errmsg, "error detected while parsing port expression : %s", *errmsg); @@ -3233,7 +3233,7 @@ struct tcpcheck_rule *parse_tcpcheck_expect(char **args, int cur_arg, struct pro release_sample_expr(status_expr); px->conf.args.ctx = ARGC_SRV; status_expr = sample_parse_expr((char *[]){args[cur_arg], NULL}, &idx, - file, line, errmsg, (px->cap & PR_CAP_DEF) ? NULL: &px->conf.args, NULL); + file, line, errmsg, &px->conf.args, NULL); if (!status_expr) { memprintf(errmsg, "error detected while parsing status-code expression : %s", *errmsg); goto error; diff --git a/src/vars.c b/src/vars.c index 10f7d82d15..03b4bc7b65 100644 --- a/src/vars.c +++ b/src/vars.c @@ -879,7 +879,7 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy } else { /* set-var */ rule->arg.vars.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, - px->conf.args.line, err, (px->cap & PR_CAP_DEF) ? NULL: &px->conf.args, NULL); + px->conf.args.line, err, &px->conf.args, NULL); if (!rule->arg.vars.expr) return ACT_RET_PRS_ERR;