mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-19 21:45:33 +00:00
MEDIUM: config: relax use_backend check to make the condition optional
Since it became possible to use log-format expressions in use_backend, having a mandatory condition becomes annoying because configurations are full of "if TRUE". Let's relax the check to accept no condition like many other keywords (eg: redirect).
This commit is contained in:
parent
74774c0f86
commit
f51658dac4
@ -7705,8 +7705,7 @@ unique-id-header <name>
|
|||||||
|
|
||||||
See also: "unique-id-format"
|
See also: "unique-id-format"
|
||||||
|
|
||||||
use_backend <backend> if <condition>
|
use_backend <backend> [{if | unless} <condition>]
|
||||||
use_backend <backend> unless <condition>
|
|
||||||
Switch to a specific backend if/unless an ACL-based condition is matched.
|
Switch to a specific backend if/unless an ACL-based condition is matched.
|
||||||
May be used in sections : defaults | frontend | listen | backend
|
May be used in sections : defaults | frontend | listen | backend
|
||||||
no | yes | yes | no
|
no | yes | yes | no
|
||||||
@ -7714,7 +7713,8 @@ use_backend <backend> unless <condition>
|
|||||||
<backend> is the name of a valid backend or "listen" section, or a
|
<backend> is the name of a valid backend or "listen" section, or a
|
||||||
"log-format" string resolving to a backend name.
|
"log-format" string resolving to a backend name.
|
||||||
|
|
||||||
<condition> is a condition composed of ACLs, as described in section 7.
|
<condition> is a condition composed of ACLs, as described in section 7. If
|
||||||
|
it is omitted, the rule is unconditionally applied.
|
||||||
|
|
||||||
When doing content-switching, connections arrive on a frontend and are then
|
When doing content-switching, connections arrive on a frontend and are then
|
||||||
dispatched to various backends depending on a number of conditions. The
|
dispatched to various backends depending on a number of conditions. The
|
||||||
|
@ -2866,22 +2866,17 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) {
|
if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) {
|
||||||
Alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n",
|
if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
|
||||||
file, linenum, args[0]);
|
Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
file, linenum, errmsg);
|
||||||
goto out;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
}
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if ((cond = build_acl_cond(file, linenum, curproxy, (const char **)args + 2, &errmsg)) == NULL) {
|
err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
|
||||||
Alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n",
|
|
||||||
file, linenum, errmsg);
|
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum);
|
|
||||||
|
|
||||||
rule = (struct switching_rule *)calloc(1, sizeof(*rule));
|
rule = (struct switching_rule *)calloc(1, sizeof(*rule));
|
||||||
rule->cond = cond;
|
rule->cond = cond;
|
||||||
rule->be.name = strdup(args[1]);
|
rule->be.name = strdup(args[1]);
|
||||||
|
@ -1085,8 +1085,10 @@ void deinit(void)
|
|||||||
|
|
||||||
list_for_each_entry_safe(rule, ruleb, &p->switching_rules, list) {
|
list_for_each_entry_safe(rule, ruleb, &p->switching_rules, list) {
|
||||||
LIST_DEL(&rule->list);
|
LIST_DEL(&rule->list);
|
||||||
prune_acl_cond(rule->cond);
|
if (rule->cond) {
|
||||||
free(rule->cond);
|
prune_acl_cond(rule->cond);
|
||||||
|
free(rule->cond);
|
||||||
|
}
|
||||||
free(rule);
|
free(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1238,12 +1238,14 @@ static int process_switching_rules(struct session *s, struct channel *req, int a
|
|||||||
struct switching_rule *rule;
|
struct switching_rule *rule;
|
||||||
|
|
||||||
list_for_each_entry(rule, &s->fe->switching_rules, list) {
|
list_for_each_entry(rule, &s->fe->switching_rules, list) {
|
||||||
int ret;
|
int ret = 1;
|
||||||
|
|
||||||
ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
|
if (rule->cond) {
|
||||||
ret = acl_pass(ret);
|
ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
|
||||||
if (rule->cond->pol == ACL_COND_UNLESS)
|
ret = acl_pass(ret);
|
||||||
ret = !ret;
|
if (rule->cond->pol == ACL_COND_UNLESS)
|
||||||
|
ret = !ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
/* If the backend name is dynamic, try to resolve the name.
|
/* If the backend name is dynamic, try to resolve the name.
|
||||||
|
Loading…
Reference in New Issue
Block a user