From 430e480510242c22d599e0d151e0d25ddc30dcb1 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 9 Apr 2020 15:28:16 +0200 Subject: [PATCH] MINOR: proxy/checks: Move parsing of tcp-check option in checks.c Parsing of the proxy directive "option tcp-check" have been moved in checks.c. --- include/proto/checks.h | 2 ++ src/cfgparse-listen.c | 34 ++------------------------------ src/checks.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/include/proto/checks.h b/include/proto/checks.h index cc0ab0b80f..563e01f4c1 100644 --- a/include/proto/checks.h +++ b/include/proto/checks.h @@ -69,6 +69,8 @@ int dup_tcpcheck_vars(struct list *dst, struct list *src); int spoe_prepare_healthcheck_request(char **req, int *len); int spoe_handle_healthcheck_response(char *frame, size_t size, char *err, int errlen); +int proxy_parse_tcp_check_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx, + const char *file, int line); int proxy_parse_redis_check_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx, const char *file, int line); int proxy_parse_ssl_hello_chk_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx, diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 4c8444c3b1..eb175a1c55 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -2370,38 +2370,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } else if (!strcmp(args[1], "tcp-check")) { - struct tcpcheck_rules *rules = &curproxy->tcpcheck_rules; - - /* use raw TCPCHK send/expect to check servers' health */ - if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) - err_code |= ERR_WARN; - - if (rules->flags & TCPCHK_RULES_DEF) { - /* Only shared ruleset can be inherited from the default section */ - rules->flags = 0; - rules->list = NULL; - } - else if (rules->list && (rules->flags & TCPCHK_RULES_SHARED)) { - ha_alert("parsing [%s:%d] : A shared tcp-check ruleset alreayd configured.\n", file, linenum); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - if (curproxy != &defproxy && !rules->list) { - rules->list = calloc(1, sizeof(*rules->list)); - if (!rules->list) { - ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - LIST_INIT(rules->list); - } - - free(curproxy->check_req); - curproxy->check_req = NULL; - curproxy->options2 &= ~PR_O2_CHK_ANY; - curproxy->options2 |= PR_O2_TCPCHK_CHK; - if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) + err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, &defproxy, file, linenum); + if (err_code & ERR_FATAL) goto out; } else if (!strcmp(args[1], "external-check")) { diff --git a/src/checks.c b/src/checks.c index ceb53ea585..240201b108 100644 --- a/src/checks.c +++ b/src/checks.c @@ -5143,6 +5143,50 @@ static void tcpcheck_ruleset_release(struct tcpcheck_ruleset *rs) free(rs); } +/* Parses the "option tcp-check" proxy keyword */ +int proxy_parse_tcp_check_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx, + const char *file, int line) +{ + struct tcpcheck_rules *rules = &curpx->tcpcheck_rules; + int err_code = 0; + + if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[cur_arg+1], NULL)) + err_code |= ERR_WARN; + + if (alertif_too_many_args_idx(0, 1, file, line, args, &err_code)) + goto out; + + if (rules->flags & TCPCHK_RULES_DEF) { + /* Only shared ruleset can be inherited from the default section */ + rules->flags = 0; + rules->list = NULL; + } + else if (rules->list && (rules->flags & TCPCHK_RULES_SHARED)) { + ha_alert("parsing [%s:%d] : A shared tcp-check ruleset alreayd configured.\n", file, line); + goto error; + } + + if (curpx != defpx && !rules->list) { + rules->list = calloc(1, sizeof(*rules->list)); + if (!rules->list) { + ha_alert("parsing [%s:%d] : out of memory.\n", file, line); + goto error; + } + LIST_INIT(rules->list); + } + + free(curpx->check_req); + curpx->check_req = NULL; + curpx->options2 &= ~PR_O2_CHK_ANY; + curpx->options2 |= PR_O2_TCPCHK_CHK; + + out: + return err_code; + + error: + err_code |= ERR_ALERT | ERR_FATAL; + goto out; +} /* Parses the "option redis-check" proxy keyword */ int proxy_parse_redis_check_opt(char **args, int cur_arg, struct proxy *curpx, struct proxy *defpx,