MINOR: checks: Set the tcp-check rule index during parsing

Now the position of a tcp-check rule in a chain is set during the parsing. This
simplify significantly the function retrieving the current step id.
This commit is contained in:
Gaetan Rivet 2020-02-25 17:19:17 +01:00 committed by Christopher Faulet
parent fd6c2291bb
commit 5301b01f99
2 changed files with 10 additions and 10 deletions

View File

@ -249,6 +249,7 @@ enum tcpcheck_rule_type {
struct tcpcheck_rule { struct tcpcheck_rule {
struct list list; /* list linked to from the proxy */ struct list list; /* list linked to from the proxy */
enum tcpcheck_rule_type action; /* type of the rule. */ enum tcpcheck_rule_type action; /* type of the rule. */
int index; /* Index within the list. Starts at 0. */
char *comment; /* comment to be used in the logs and on the stats socket */ char *comment; /* comment to be used in the logs and on the stats socket */
char *string; /* sent string */ char *string; /* sent string */
int string_len; /* sent string length */ int string_len; /* sent string length */

View File

@ -2730,9 +2730,6 @@ static int httpchk_expect(struct server *s, int done)
*/ */
static int tcpcheck_get_step_id(struct check *check) static int tcpcheck_get_step_id(struct check *check)
{ {
struct tcpcheck_rule *cur;
int i = 0;
/* not even started anything yet => step 0 = initial connect */ /* not even started anything yet => step 0 = initial connect */
if (!check->current_step && !check->last_started_step) if (!check->current_step && !check->last_started_step)
return 0; return 0;
@ -2741,12 +2738,7 @@ static int tcpcheck_get_step_id(struct check *check)
if (!check->last_started_step) if (!check->last_started_step)
return 1; return 1;
list_for_each_entry(cur, check->tcpcheck_rules, list) { return check->last_started_step->index + 1;
if (cur->list.p == &check->last_started_step->list)
break;
i++;
}
return i;
} }
/* /*
@ -4257,7 +4249,7 @@ static int proxy_parse_tcpcheck(char **args, int section, struct proxy *curpx,
{ {
struct list *rules = curpx->tcpcheck_rules; struct list *rules = curpx->tcpcheck_rules;
struct tcpcheck_rule *chk = NULL; struct tcpcheck_rule *chk = NULL;
int cur_arg, ret = 0; int index, cur_arg, ret = 0;
if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[0], NULL)) if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[0], NULL))
ret = 1; ret = 1;
@ -4277,6 +4269,12 @@ static int proxy_parse_tcpcheck(char **args, int section, struct proxy *curpx,
curpx->tcpcheck_rules = rules; curpx->tcpcheck_rules = rules;
} }
index = 0;
if (!LIST_ISEMPTY(rules)) {
chk = LIST_PREV(rules, typeof(chk), list);
index = chk->index + 1;
}
cur_arg = 1; cur_arg = 1;
if (strcmp(args[cur_arg], "connect") == 0) if (strcmp(args[cur_arg], "connect") == 0)
chk = parse_tcpcheck_connect(args, cur_arg, curpx, rules, errmsg); chk = parse_tcpcheck_connect(args, cur_arg, curpx, rules, errmsg);
@ -4299,6 +4297,7 @@ static int proxy_parse_tcpcheck(char **args, int section, struct proxy *curpx,
ret = (*errmsg != NULL); /* Handle warning */ ret = (*errmsg != NULL); /* Handle warning */
/* No error: add the tcp-check rule in the list */ /* No error: add the tcp-check rule in the list */
chk->index = index;
LIST_ADDQ(rules, &chk->list); LIST_ADDQ(rules, &chk->list);
return ret; return ret;