From b50b3e6d0adb2abb5b304bcb7784294814d8da0b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 5 May 2020 18:43:43 +0200 Subject: [PATCH] MINOR: checks: Use dedicated actions to send log-format strings in send rules Following actions have been added to send log-format strings from a tcp-check ruleset instead the log-format parameter: * tcp-check send-lf * tcp-check send-binary-lf It is easier for tools generating configurations. Each action may only be interpreted in one way. --- doc/configuration.txt | 33 +++++++++++++++++++-------------- src/checks.c | 31 +++++++++++++++++-------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index a4bc26e50..b183b98e4 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2763,7 +2763,9 @@ tcp-check comment X - X X tcp-check connect X - X X tcp-check expect X - X X tcp-check send X - X X +tcp-check send-lf X - X X tcp-check send-binary X - X X +tcp-check send-binary-lf X - X X tcp-check set-var X - X X tcp-check unset-var X - X X tcp-request connection - X X - @@ -10318,18 +10320,21 @@ tcp-check expect [min-recv ] [comment ] "tcp-check send-binary", "http-check expect", tune.chksize -tcp-check send [comment ] [log-format] - Specify a string to be sent as a question during a generic health check +tcp-check send [comment ] +tcp-check send-lf [comment ] + Specify a string or a log-format string to be sent as a question during a + generic health check May be used in sections: defaults | frontend | listen | backend yes | no | yes | yes Arguments : comment defines a message to report if the rule evaluation fails. - log-format specifies must be evaluated a log-format string. + is the string that will be sent during a generic health + check session. - the data to be sent as a question during a generic health check - session. For now, must be a string. + is the log-format string that will be sent, once evaluated, + during a generic health check session. Examples : # look for the redis master server @@ -10341,22 +10346,22 @@ tcp-check send [comment ] [log-format] "tcp-check send-binary", tune.chksize -tcp-check send-binary [comment ] [log-format] - Specify a hex digits string to be sent as a binary question during a raw - tcp health check +tcp-check send-binary [comment ] +tcp-check send-binary-lf [comment ] + Specify an hex digits string or an hex digits log-format string to be sent as + a binary question during a raw tcp health check May be used in sections: defaults | frontend | listen | backend yes | no | yes | yes Arguments : comment defines a message to report if the rule evaluation fails. - log-format specifies must be evaluated a log-format string. + is the hexadecimal string that will be send, once converted + to binary, during a generic health check session. - test the exact string in its hexadecimal form matches in the - response buffer. A health check response will be considered - valid if the response's buffer contains this exact hexadecimal - string. Purpose is to send binary data to ask on binary - protocols. + is the hexadecimal log-format string that will be send, once + evaluated and converted to binary, during a generic health + check session. Examples : # redis check in binary diff --git a/src/checks.c b/src/checks.c index 5e66ec0e4..172cdd608 100644 --- a/src/checks.c +++ b/src/checks.c @@ -3895,7 +3895,15 @@ static struct tcpcheck_rule *parse_tcpcheck_send(char **args, int cur_arg, struc char *comment = NULL, *data = NULL; enum tcpcheck_send_type type = TCPCHK_SEND_UNDEF; - type = ((strcmp(args[cur_arg], "send-binary") == 0) ? TCPCHK_SEND_BINARY : TCPCHK_SEND_STRING); + if (strcmp(args[cur_arg], "send-binary-lf") == 0) + type = TCPCHK_SEND_BINARY_LF; + else if (strcmp(args[cur_arg], "send-binary") == 0) + type = TCPCHK_SEND_BINARY; + else if (strcmp(args[cur_arg], "send-lf") == 0) + type = TCPCHK_SEND_STRING_LF; + else if (strcmp(args[cur_arg], "send") == 0) + type = TCPCHK_SEND_STRING; + if (!*(args[cur_arg+1])) { memprintf(errmsg, "'%s' expects a %s as argument", (type == TCPCHK_SEND_BINARY ? "binary string": "string"), args[cur_arg]); @@ -3919,14 +3927,8 @@ static struct tcpcheck_rule *parse_tcpcheck_send(char **args, int cur_arg, struc goto error; } } - else if (strcmp(args[cur_arg], "log-format") == 0) { - if (type == TCPCHK_SEND_BINARY) - type = TCPCHK_SEND_BINARY_LF; - else if (type == TCPCHK_SEND_STRING) - type = TCPCHK_SEND_STRING_LF; - } else { - memprintf(errmsg, "expects 'comment', 'log-format' but got '%s' as argument.", + memprintf(errmsg, "expects 'comment' but got '%s' as argument.", args[cur_arg]); goto error; } @@ -5960,7 +5962,8 @@ static int proxy_parse_tcpcheck(char **args, int section, struct proxy *curpx, cur_arg = 1; if (strcmp(args[cur_arg], "connect") == 0) chk = parse_tcpcheck_connect(args, cur_arg, curpx, &rs->rules, file, line, errmsg); - else if (strcmp(args[cur_arg], "send") == 0 || strcmp(args[cur_arg], "send-binary") == 0) + else if (strcmp(args[cur_arg], "send") == 0 || strcmp(args[cur_arg], "send-binary") == 0 || + strcmp(args[cur_arg], "send-lf") == 0 || strcmp(args[cur_arg], "send-binary-lf") == 0) chk = parse_tcpcheck_send(args, cur_arg, curpx, &rs->rules, file, line, errmsg); else if (strcmp(args[cur_arg], "expect") == 0) chk = parse_tcpcheck_expect(args, cur_arg, curpx, &rs->rules, 0, file, line, errmsg); @@ -6359,7 +6362,7 @@ int proxy_parse_ssl_hello_chk_opt(char **args, int cur_arg, struct proxy *curpx, goto error; } - chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary", sslv3_client_hello, "log-format", ""}, + chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary-lf", sslv3_client_hello, ""}, 1, curpx, &rs->rules, file, line, &errmsg); if (!chk) { ha_alert("parsing [%s:%d] : %s\n", file, line, errmsg); @@ -6494,7 +6497,7 @@ int proxy_parse_smtpchk_opt(char **args, int cur_arg, struct proxy *curpx, struc chk->index = 2; LIST_ADDQ(&rs->rules, &chk->list); - chk = parse_tcpcheck_send((char *[]){"tcp-check", "send", smtp_req, "log-format", ""}, + chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", smtp_req, ""}, 1, curpx, &rs->rules, file, line, &errmsg); if (!chk) { ha_alert("parsing [%s:%d] : %s\n", file, line, errmsg); @@ -6629,7 +6632,7 @@ int proxy_parse_pgsql_check_opt(char **args, int cur_arg, struct proxy *curpx, s chk->index = 0; LIST_ADDQ(&rs->rules, &chk->list); - chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary", pgsql_req, "log-format", ""}, + chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary-lf", pgsql_req, ""}, 1, curpx, &rs->rules, file, line, &errmsg); if (!chk) { ha_alert("parsing [%s:%d] : %s\n", file, line, errmsg); @@ -6858,7 +6861,7 @@ int proxy_parse_mysql_check_opt(char **args, int cur_arg, struct proxy *curpx, s LIST_ADDQ(&rs->rules, &chk->list); if (mysql_req) { - chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary", mysql_req, "log-format", ""}, + chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-binary-lf", mysql_req, ""}, 1, curpx, &rs->rules, file, line, &errmsg); if (!chk) { ha_alert("parsing [%s:%d] : %s\n", file, line, errmsg); @@ -7381,7 +7384,7 @@ static int srv_parse_agent_check(char **args, int *cur_arg, struct proxy *curpx, goto error; } - chk = parse_tcpcheck_send((char *[]){"tcp-check", "send", "%[var(check.agent_string)]", "log-format", ""}, + chk = parse_tcpcheck_send((char *[]){"tcp-check", "send-lf", "%[var(check.agent_string)]", ""}, 1, curpx, &rs->rules, srv->conf.file, srv->conf.line, errmsg); if (!chk) { memprintf(errmsg, "'%s': %s", args[*cur_arg], *errmsg);