]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tcpcheck: Support 2-steps args resolution in defaults sections
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Oct 2021 13:18:36 +0000 (15:18 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Oct 2021 12:12:19 +0000 (14:12 +0200)
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.

src/cfgparse-listen.c
src/log.c
src/tcpcheck.c
src/vars.c

index e2f412de93ac09c3a5c8e7ce2e2e815793b0fb82..d079ecf40b72d7965a1a4e1bfb7213212211b141 100644 (file)
@@ -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;
index 11b422680f60c22c4ab219585263a7978489269a..245675434969e0fd1c79e564162600ce6c5a0e51 100644 (file)
--- 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;
index aa6db673a4f9ed0e4305414837307e9ce207541c..b7827967325dca15e6778b7fd889e04cc182f972 100644 (file)
@@ -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;
index 10f7d82d151847858758c319e29ab5f30f71459a..03b4bc7b6503715e8db9a7c9011df6a20322ea21 100644 (file)
@@ -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;