]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy/checks: Move parsing of tcp-check option in checks.c
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Apr 2020 13:28:16 +0000 (15:28 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:38 +0000 (09:39 +0200)
Parsing of the proxy directive "option tcp-check" have been moved in checks.c.

include/proto/checks.h
src/cfgparse-listen.c
src/checks.c

index cc0ab0b80f1247ee32f4f6fce923fb9d5c7c9314..563e01f4c126eb138be8c8dee0e6f82c2d30cbf8 100644 (file)
@@ -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,
index 4c8444c3b1c6e1baacfb11ad97d33bc9c165c264..eb175a1c5521cd72d5a785c739c7ac5f3e9156ed 100644 (file)
@@ -2370,38 +2370,8 @@ stats_error_parsing:
                                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")) {
index ceb53ea58529c19fca50e0087c3169bc9d93399f..240201b1081a6dc1e37be2e1b3bbd1e4071f52f0 100644 (file)
@@ -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,