]> git.ipfire.org Git - thirdparty/haproxy.git/log
thirdparty/haproxy.git
5 years agoDOC: Fix the tcp-check and http-check directives layout
Christopher Faulet [Thu, 23 Apr 2020 13:43:35 +0000 (15:43 +0200)] 
DOC: Fix the tcp-check and http-check directives layout

5 years agoDOC: Add documentation about comments for tcp-check and http-check directives
Christopher Faulet [Thu, 23 Apr 2020 13:22:33 +0000 (15:22 +0200)] 
DOC: Add documentation about comments for tcp-check and http-check directives

The documentation about the comment argument for some tcp-check and http-check
directives was missing. As well as the description of "tcp-check comment" and
"http-check comment" directives.

5 years agoRevert "MEDIUM: checks: capture groups in expect regexes"
Christopher Faulet [Wed, 22 Apr 2020 13:32:11 +0000 (15:32 +0200)] 
Revert "MEDIUM: checks: capture groups in expect regexes"

This reverts commit 1979943c30ef285ed04f07ecf829514de971d9b2.

Captures in comment was only used when a tcp-check expect based on a negative
regex matching failed to eventually report what was captured while it was not
expected. It is a bit far-fetched to be useable IMHO. on-error and on-success
log-format strings are far more usable. For now there is few check sample
fetches (in fact only one...). But it could be really powerful to report info in
logs.

5 years agoREGTEST: Add scripts to test based tcp-check health-checks
Christopher Faulet [Wed, 22 Apr 2020 13:16:58 +0000 (15:16 +0200)] 
REGTEST: Add scripts to test based tcp-check health-checks

These scripts have been added to validate the health-checks based on tcp-check
rules (http, redis, MySQL...).

5 years agoBUG/MINOR: checks: Send the right amount of outgoing data for HTTP checks
Christopher Faulet [Wed, 22 Apr 2020 09:09:25 +0000 (11:09 +0200)] 
BUG/MINOR: checks: Send the right amount of outgoing data for HTTP checks

HTTP health-checks now use HTX multiplexers. So it is important to really send
the amount of outgoing data for such checks because the HTX buffers appears
always full.

No backport needed.

5 years agoMINOR: checks: Use a tree instead of a list to store tcp-check rulesets
Christopher Faulet [Tue, 21 Apr 2020 11:45:00 +0000 (13:45 +0200)] 
MINOR: checks: Use a tree instead of a list to store tcp-check rulesets

Since all tcp-check rulesets are globally stored, it is a problem to use
list. For configuration with many backends, the lookups in list may be costly
and slow downs HAProxy startup. To solve this problem, tcp-check rulesets are
now stored in a tree.

5 years agoBUG/MEDIUM: checks: Be sure to subscribe for sends if outgoing data remains
Christopher Faulet [Tue, 21 Apr 2020 11:02:14 +0000 (13:02 +0200)] 
BUG/MEDIUM: checks: Be sure to subscribe for sends if outgoing data remains

When some data are scheduled to be sent, we must be sure to subscribe for sends
if nothing was sent. Because of a bug, when nothing was sent, connection errors
are checks. If no error is found, we exit, waiting for more data, without any
subcription on send events.

No need to backport.

5 years agoMINOR: checks: Use ist API as far as possible
Christopher Faulet [Tue, 21 Apr 2020 08:57:42 +0000 (10:57 +0200)] 
MINOR: checks: Use ist API as far as possible

Instead of accessing directly to the ist fields, the ist API is used instead. To
get its length or its pointer, to release it or to duplicate it. It is more
readable this way.

5 years agoMINOR: ist: Add a function to retrieve the ist pointer
Christopher Faulet [Tue, 21 Apr 2020 08:46:43 +0000 (10:46 +0200)] 
MINOR: ist: Add a function to retrieve the ist pointer

There is already the istlen() function to get the ist length. Now, it is
possible to call istptr() to get the ist pointer.

5 years agoREGTEST: Fix reg-tests about health-checks to adapt them to recent changes
Christopher Faulet [Mon, 20 Apr 2020 12:59:20 +0000 (14:59 +0200)] 
REGTEST: Fix reg-tests about health-checks to adapt them to recent changes

5 years agoCLEANUP: checks: Reorg checks.c file to be more readable
Christopher Faulet [Mon, 20 Apr 2020 12:54:42 +0000 (14:54 +0200)] 
CLEANUP: checks: Reorg checks.c file to be more readable

The patch is not obvious at the first glance. But it is just a reorg. Functions
have been grouped and ordered in a more logical way. Some structures and flags
are now private to the checks module (so moved from the .h to the .c file).

5 years agoMINOR: checks: Remove unused code about pure TCP checks
Christopher Faulet [Mon, 20 Apr 2020 07:04:37 +0000 (09:04 +0200)] 
MINOR: checks: Remove unused code about pure TCP checks

Thanks to previous change, it is now possible to removed all code handling pure
tcp checks. Now every connection based health-checks are handled by the
tcpcheck_main() function. __event_srv_chk_w() and __event_srv_chk_r() have been
removed. And all connection establishment is handled at one place.

5 years agoMEDIUM: checks: Implement default TCP check using tcp-check rules
Christopher Faulet [Fri, 17 Apr 2020 18:15:59 +0000 (20:15 +0200)] 
MEDIUM: checks: Implement default TCP check using tcp-check rules

Defaut health-checks, without any option, doing only a connection check, are now
based on tcp-checks. An implicit default tcp-check connect rule is used. A
shared tcp-check ruleset, name "*tcp-check" is created to support these checks.

5 years agoMAJOR: checks: Use the best mux depending on the protocol for health checks
Christopher Faulet [Thu, 16 Apr 2020 12:50:06 +0000 (14:50 +0200)] 
MAJOR: checks: Use the best mux depending on the protocol for health checks

When a tcp-check connect rule is evaluated, the mux protocol corresponding to
the health-check is chosen. So for TCP based health-checks, the mux-pt is
used. For HTTP based health-checks, the mux-h1 is used. The connection is marked
as private to be sure to not ruse regular HTTP connection for
health-checks. Connections reuse will be evaluated later.

The functions evaluating HTTP send rules and expect rules have been updated to
be HTX compliant. The main change for users is that HTTP health-checks are now
stricter on the HTTP message format. While before, the HTTP formatting and
parsing were minimalist, now messages should be well formatted.

5 years agoMINOR: connection: Add a function to install a mux for a health-check
Christopher Faulet [Tue, 21 Apr 2020 10:18:05 +0000 (12:18 +0200)] 
MINOR: connection: Add a function to install a mux for a health-check

This function is unused for now. But it will have be used to install a mux for
an outgoing connection openned in a health-check context. In this case, the
session's origin is the check itself, and it is used to know the mode, HTTP or
TCP, depending on the tcp-check type and not the proxy mode. The check is also
used to get the mux protocol if configured.

5 years agoMINOR: checks: Add a mux proto to health-check and tcp-check connect rule
Christopher Faulet [Tue, 21 Apr 2020 09:59:32 +0000 (11:59 +0200)] 
MINOR: checks: Add a mux proto to health-check and tcp-check connect rule

It is not set and not used for now, but it will be possible to force the mux
protocol thanks to this patch. A mux proto field is added to the checks and to
tcp-check connect rules.

5 years agoMINOR: checks: Use the check as origin when a session is created
Christopher Faulet [Tue, 21 Apr 2020 09:53:32 +0000 (11:53 +0200)] 
MINOR: checks: Use the check as origin when a session is created

Before, the server was used as origin during session creation. It was only used
to get the check associated to the server when a variable is get or set in the
check scope or when a check sample fetch was called. So it seems easier to use
the check as origin of a session. It is also more logical becaues the session is
created by the health-check itself and not its server.

5 years agoBUG/MINOR: obj_type: Handle stream object in obj_base_ptr() function
Christopher Faulet [Tue, 21 Apr 2020 09:48:53 +0000 (11:48 +0200)] 
BUG/MINOR: obj_type: Handle stream object in obj_base_ptr() function

The stream object (OBJ_TYPE_STREAM) was missing in the switch statement of the
obj_base_ptr() function.

This patch must be backported as far as 2.0.

5 years agoMINOR: checks/obj_type: Add a new object type for checks
Christopher Faulet [Tue, 21 Apr 2020 09:46:40 +0000 (11:46 +0200)] 
MINOR: checks/obj_type: Add a new object type for checks

An object type is now affected to the check structure.

5 years agoMEDIUM: checks: Refactor how data are received in tcpcheck_main()
Christopher Faulet [Thu, 16 Apr 2020 11:25:58 +0000 (13:25 +0200)] 
MEDIUM: checks: Refactor how data are received in tcpcheck_main()

A dedicated function is now used to received data. fundamentally, it should do
the same operations than before. But the way data are received has been reworked
to be closer to the si_cs_recv() function.

5 years agoMINOR: connection: Add macros to know if a conn or a cs uses an HTX mux
Christopher Faulet [Thu, 16 Apr 2020 08:03:58 +0000 (10:03 +0200)] 
MINOR: connection: Add macros to know if a conn or a cs uses an HTX mux

IS_HTX_CONN() and IS_HTX_CS may now be used to know if a connection or a
conn-stream use an HTX based multiplexer.

5 years agoMINOR: checks: Make resume conditions more explicit in tcpcheck_main()
Christopher Faulet [Thu, 16 Apr 2020 07:52:42 +0000 (09:52 +0200)] 
MINOR: checks: Make resume conditions more explicit in tcpcheck_main()

First tests before executing the loop on tcp-check rules in tcpcheck_main()
function have been slightly modified to be more explicit and easier to
understand.

5 years agoMAJOR: checks: Implement HTTP check using tcp-check rules
Christopher Faulet [Wed, 15 Apr 2020 09:32:03 +0000 (11:32 +0200)] 
MAJOR: checks: Implement HTTP check using tcp-check rules

HTTP health-checks are now internally based on tcp-checks. Of course all the
configuration parsing of the "http-check" keyword and the httpchk option has
been rewritten. But the main changes is that now, as for tcp-check ruleset, it
is possible to perform several send/expect sequences into the same
health-checks. Thus the connect rule is now also available from HTTP checks, jst
like set-var, unset-var and comment rules.

Because the request defined by the "option httpchk" line is used for the first
request only, it is now possible to set the method, the uri and the version on a
"http-check send" line.

5 years agoMINOR: checks: Add a reverse non-comment rule iterator to get last rule
Christopher Faulet [Wed, 15 Apr 2020 09:34:04 +0000 (11:34 +0200)] 
MINOR: checks: Add a reverse non-comment rule iterator to get last rule

the get_last_tcpcheck_rule() function iters on a rule list in the reverse order
and returns the first non comment and non action-kw rule. If no such rule is
found, NULL is returned.

5 years agoMINOR: standard: Add my_memspn and my_memcspn
Christopher Faulet [Wed, 15 Apr 2020 08:23:01 +0000 (10:23 +0200)] 
MINOR: standard: Add my_memspn and my_memcspn

Do the same than strsnp() and strcspn() but on a raw bytes buffer.

5 years agoMINOR: checks: Introduce flags to configure in tcp-check expect rules
Christopher Faulet [Fri, 10 Apr 2020 07:58:42 +0000 (09:58 +0200)] 
MINOR: checks: Introduce flags to configure in tcp-check expect rules

Instead of having 2 independent integers, used as boolean values, to know if the
expect rule is invered and to know if the matching regexp has captures, we know
use a 32-bits bitfield.

5 years agoMINOR: checks: Use an indirect string to represent the expect matching string
Christopher Faulet [Fri, 10 Apr 2020 07:20:02 +0000 (09:20 +0200)] 
MINOR: checks: Use an indirect string to represent the expect matching string

Instead of having a string in the expect union with its length outside of the
union, directly in the expect structure, an indirect string is now used.

5 years agoMEDIUM: checks: Use a shared ruleset to store tcp-check rules
Christopher Faulet [Thu, 9 Apr 2020 21:13:54 +0000 (23:13 +0200)] 
MEDIUM: checks: Use a shared ruleset to store tcp-check rules

All tcp-check rules are now stored in the globla shared list. The ones created
to parse a specific protocol, for instance redis, are already stored in this
list. Now pure tcp-check rules are also stored in it. The ruleset name is
created using the proxy name and its config file and line. tcp-check rules
declared in a defaults section are also stored this way using "defaults" as
proxy name.

For now, all tcp-check ruleset are stored in a list. But it could be a bit slow
to looks for a specific ruleset with a huge number of backends. So, it could be
a good idea to use a tree instead.

5 years agoMINOR: proxy/checks: Register a keyword to parse external-check rules
Christopher Faulet [Thu, 9 Apr 2020 16:12:08 +0000 (18:12 +0200)] 
MINOR: proxy/checks: Register a keyword to parse external-check rules

The keyword 'external-check' is now parsed in a dedicated callback
function. Thus the code to parse these rules is now located in checks.c.

5 years agoMINOR: proxy/checks: Move parsing of external-check option in checks.c
Christopher Faulet [Thu, 9 Apr 2020 13:58:50 +0000 (15:58 +0200)] 
MINOR: proxy/checks: Move parsing of external-check option in checks.c

Parsing of the proxy directive "option external-check" have been moved in checks.c.

5 years agoMINOR: proxy/checks: Register a keyword to parse http-check rules
Christopher Faulet [Thu, 9 Apr 2020 13:54:18 +0000 (15:54 +0200)] 
MINOR: proxy/checks: Register a keyword to parse http-check rules

The keyword 'http-check' is now parsed in a dedicated callback function. Thus
the code to parse these rules is now located in checks.c.

5 years agoMINOR: proxy/checks: Move parsing of tcp-check option in checks.c
Christopher Faulet [Thu, 9 Apr 2020 13:28:16 +0000 (15:28 +0200)] 
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.

5 years agoMINOR: proxy/checks: Move parsing of httpchk option in checks.c
Christopher Faulet [Thu, 9 Apr 2020 12:48:48 +0000 (14:48 +0200)] 
MINOR: proxy/checks: Move parsing of httpchk option in checks.c

Parsing of the proxy directive "option httpchk" have been moved in checks.c.

5 years agoMINOR: checks: Improve log message of tcp-checks on success
Christopher Faulet [Tue, 7 Apr 2020 14:04:38 +0000 (16:04 +0200)] 
MINOR: checks: Improve log message of tcp-checks on success

5 years agoMINOR: checks: Add an option to set success status of tcp-check expect rules
Christopher Faulet [Tue, 7 Apr 2020 12:56:26 +0000 (14:56 +0200)] 
MINOR: checks: Add an option to set success status of tcp-check expect rules

It is now possible to specified the healthcheck status to use on success of a
tcp-check rule, if it is the last evaluated rule. The option "ok-status"
supports "L4OK", "L6OK", "L7OK" and "L7OKC" status.

5 years agoMINOR: Produce tcp-check info message for pure tcp-check rules only
Christopher Faulet [Tue, 7 Apr 2020 10:06:14 +0000 (12:06 +0200)] 
MINOR: Produce tcp-check info message for pure tcp-check rules only

This way, messages reported by protocol checks are closer that the old one.

5 years agoREGTEST: Adapt regtests about checks to recent changes
Christopher Faulet [Tue, 7 Apr 2020 06:00:35 +0000 (08:00 +0200)] 
REGTEST: Adapt regtests about checks to recent changes

5 years agoMEDIUM: checks: Implement agent check using tcp-check rules
Christopher Faulet [Mon, 6 Apr 2020 15:54:24 +0000 (17:54 +0200)] 
MEDIUM: checks: Implement agent check using tcp-check rules

A shared tcp-check ruleset is now created to support agent checks. The following
sequence is used :

    tcp-check send "%[var(check.agent_string)] log-format
    tcp-check expect custom

The custom function to evaluate the expect rule does the same that it was done
to handle agent response when a custom check was used.

5 years agoMINOR: server/checks: Move parsing of server check keywords in checks.c
Christopher Faulet [Mon, 6 Apr 2020 13:04:11 +0000 (15:04 +0200)] 
MINOR: server/checks: Move parsing of server check keywords in checks.c

Parsing of following keywords have been moved in checks.c file : addr, check,
check-send-proxy, check-via-socks4, no-check, no-check-send-proxy, rise, fall,
inter, fastinter, downinter and port.

5 years agoMINOR: server/checks: Move parsing of agent keywords in checks.c
Christopher Faulet [Mon, 6 Apr 2020 12:26:30 +0000 (14:26 +0200)] 
MINOR: server/checks: Move parsing of agent keywords in checks.c

Parsing of following keywords have been moved in checks.c file: agent-addr,
agent-check, agent-inter, agent-port, agent-send and no-agent-check.

5 years agoMEDIUM: checks: Implement SPOP check using tcp-check rules
Christopher Faulet [Sat, 4 Apr 2020 08:27:09 +0000 (10:27 +0200)] 
MEDIUM: checks: Implement SPOP check using tcp-check rules

A share tcp-check ruleset is now created to support SPOP checks. This way no
extra memory is used if several backends use a SPOP check.

The following sequence is used :

    tcp-check send-binary SPOP_REQ
    tcp-check expect custom min-recv 4

The spop request is the result of the function
spoe_prepare_healthcheck_request() and the expect rule relies on a custom
function calling spoe_handle_healthcheck_response().

5 years agoMEDIUM: checks: Implement LDAP check using tcp-check rules
Christopher Faulet [Fri, 3 Apr 2020 21:13:50 +0000 (23:13 +0200)] 
MEDIUM: checks: Implement LDAP check using tcp-check rules

A shared tcp-check ruleset is now created to support LDAP check. This way no
extra memory is used if several backends use a LDAP check.

The following sequance is used :

    tcp-check send-binary "300C020101600702010304008000"

    tcp-check expect rbinary "^30" min-recv 14 \
        on-error "Not LDAPv3 protocol"

    tcp-check expect custom

The last expect rule relies on a custom function to check the LDAP server reply.

5 years agoMEDIUM: checks: Implement MySQL check using tcp-check rules
Christopher Faulet [Thu, 2 Apr 2020 16:07:37 +0000 (18:07 +0200)] 
MEDIUM: checks: Implement MySQL check using tcp-check rules

A share tcp-check ruleset is now created to support MySQL checks. This way no
extra memory is used if several backends use a MySQL check.

One for the following sequence is used :

    ## If no extra params are set
    tcp-check connect default linger
    tcp-check expect custom  ## will test the initial handshake

    ## If the username is defined
    tcp-check connect default linger
    tcp-check send-binary MYSQL_REQ log-format
    tcp-check expect custom  ## will test the initial handshake
    tcp-check expect custom  ## will test the reply to the client message

The log-format hexa string MYSQL_REQ depends on 2 preset variables, the packet
header containing the packet length and the sequence ID (check.header) and the
username (check.username). If is also different if the "post-41" option is set
or not. Expect rules relies on custom functions to check MySQL server packets.

5 years agoMEDIUM: checks: Implement postgres check using tcp-check rules
Christopher Faulet [Thu, 2 Apr 2020 09:44:39 +0000 (11:44 +0200)] 
MEDIUM: checks: Implement postgres check using tcp-check rules

A shared tcp-check ruleset is now created to support postgres check. This way no
extra memory is used if several backends use a pgsql check.

The following sequence is used :

    tcp-check connect default linger

    tcp-check send-binary PGSQL_REQ log-format

    tcp-check expect !rstring "^E" min-recv 5 \
        error-status "L7RSP" on-error "%[check.payload(6,0)]"

    tcp-check expect rbinary "^520000000800000000 min-recv "9" \
        error-status "L7STS" \
        on-success "PostgreSQL server is ok" \
        on-error "PostgreSQL unknown error"

The log-format hexa string PGSQL_REQ depends on 2 preset variables, the packet
length (check.plen) and the username (check.username).

5 years agoMEDIUM: checks: Implement smtp check using tcp-check rules
Christopher Faulet [Wed, 1 Apr 2020 18:54:05 +0000 (20:54 +0200)] 
MEDIUM: checks: Implement smtp check using tcp-check rules

A share tcp-check ruleset is now created to support smtp checks. This way no
extra memory is used if several backends use a smtp check.

The following sequence is used :

    tcp-check connect default linger

    tcp-check expect rstring "^[0-9]{3}[ \r]" min-recv 4 \
        error-status "L7RSP" on-error "%[check.payload(),cut_crlf]"

    tcp-check expect rstring "^2[0-9]{2}[ \r]" min-recv 4 \
        error-status "L7STS" \
        on-error %[check.payload(4,0),ltrim(' '),cut_crlf] \
        status-code "check.payload(0,3)"

    tcp-echeck send "%[var(check.smtp_cmd)]\r\n" log-format

    tcp-check expect rstring "^2[0-9]{2}[- \r]" min-recv 4 \
        error-status "L7STS" \
        on-error %[check.payload(4,0),ltrim(' '),cut_crlf] \
        on-success "%[check.payload(4,0),ltrim(' '),cut_crlf]" \
        status-code "check.payload(0,3)"

The variable check.smtp_cmd is by default the string "HELO localhost" by may be
customized setting <helo> and <domain> parameters on the option smtpchk
line. Note there is a difference with the old smtp check. The server gretting
message is checked before send the HELO/EHLO comand.

5 years agoMEDIUM: checks: Implement ssl-hello check using tcp-check rules
Christopher Faulet [Wed, 1 Apr 2020 09:10:27 +0000 (11:10 +0200)] 
MEDIUM: checks: Implement ssl-hello check using tcp-check rules

A shared tcp-check ruleset is now created to support ssl-hello check. This way
no extra memory is used if several backends use a ssl-hello check.

The following sequence is used :

    tcp-check send-binary SSLV3_CLIENT_HELLO log-format

    tcp-check expect rbinary "^1[56]" min-recv 5 \
        error-status "L6RSP" tout-status "L6TOUT"

SSLV3_CLIENT_HELLO is a log-format hexa string representing a SSLv3 CLIENT HELLO
packet. It is the same than the one used by the old ssl-hello except the sample
expression "%[date(),htonl,hex]" is used to set the date field.

5 years agoMEDIUM: checks: Implement redis check using tcp-check rules
Christopher Faulet [Wed, 1 Apr 2020 09:08:50 +0000 (11:08 +0200)] 
MEDIUM: checks: Implement redis check using tcp-check rules

A share tcp-check ruleset is now created to support redis checks. This way no
extra memory is used if several backends use a redis check.

The following sequence is used :

  tcp-check send "*1\r\n$4\r\nPING\r\n"

  tcp-check expect string "+PONG\r\n" error-status "L7STS" \
      on-error "%[check.payload(),cut_crlf]" on-success "Redis server is ok"

5 years agoMINOR: checks: Support custom functions to eval a tcp-check expect rules
Christopher Faulet [Fri, 3 Apr 2020 13:24:06 +0000 (15:24 +0200)] 
MINOR: checks: Support custom functions to eval a tcp-check expect rules

It is now possible to set a custom function to evaluate a tcp-check expect
rule. It is an internal and not documentd option because the right pointer of
function must be set and it is not possible to express it in the
configuration. It will be used to convert some protocol healthchecks to
tcp-checks.

Custom functions must have the following signature:

  enum tcpcheck_eval_ret (*custom)(struct check *, struct tcpcheck_rule *, int);

5 years agoMINOR: checks: Use dedicated function to handle onsuccess/onerror messages
Christopher Faulet [Fri, 3 Apr 2020 12:51:06 +0000 (14:51 +0200)] 
MINOR: checks: Use dedicated function to handle onsuccess/onerror messages

error and success messages produced when tcp-check healthchecks end are now
handled in dedicated functions.

5 years agoMINOR: checks: Export the tcpcheck_eval_ret enum
Christopher Faulet [Fri, 3 Apr 2020 09:16:13 +0000 (11:16 +0200)] 
MINOR: checks: Export the tcpcheck_eval_ret enum

This enum will be used to define custom function for tcp-check expect rules.

5 years agoMEDIUM: checks: Add a list of vars to set before executing a tpc-check ruleset
Christopher Faulet [Thu, 2 Apr 2020 16:05:11 +0000 (18:05 +0200)] 
MEDIUM: checks: Add a list of vars to set before executing a tpc-check ruleset

A list of variables is now associated to each tcp-check ruleset. It is more a
less a list of set-var expressions. This list may be filled during the
configuration parsing. The listed variables will then be set during each
execution of the tcp-check healthcheck, at the begining, before execution of the
the first tcp-check rule.

This patch is mandatory to convert all protocol checks to tcp-checks. It is a
way to customize shared tcp-check rulesets.

5 years agoMINOR: checks: Relax the default option for tcp-check connect rules
Christopher Faulet [Wed, 1 Apr 2020 14:52:17 +0000 (16:52 +0200)] 
MINOR: checks: Relax the default option for tcp-check connect rules

Now this option may be mixed with other options. This way, options on the server
line are used but may be overridden by tcp-check connect options.

5 years agoMEDIUM: checks: Add status-code sample expression on tcp-check expect rules
Christopher Faulet [Wed, 1 Apr 2020 18:52:31 +0000 (20:52 +0200)] 
MEDIUM: checks: Add status-code sample expression on tcp-check expect rules

This option defines a sample expression, evaluated as an integer, to set the
status code (check->code) if a tcp-check healthcheck ends on the corresponding
expect rule.

5 years agoMEDIUM: checks: Add on-error/on-success option on tcp-check expect rules
Christopher Faulet [Wed, 1 Apr 2020 14:30:22 +0000 (16:30 +0200)] 
MEDIUM: checks: Add on-error/on-success option on tcp-check expect rules

These options define log-format strings used to produce the info message if a
tcp-check expect rule fails (on-error option) or succeeds (on-success
option). For this last option, it must be the ending rule, otherwise the
parameter is ignored.

5 years agoMINOR: checks: Add a sample fetch to extract a block from the input check buffer
Christopher Faulet [Wed, 1 Apr 2020 14:27:05 +0000 (16:27 +0200)] 
MINOR: checks: Add a sample fetch to extract a block from the input check buffer

It is now possible to extract information from the check input buffer using the
check.payload sample fetch. As req.payload or res.payload, an offset and a
length must be specified.

A new section has been added in the configuration manual. Now check sample
fetches will have to be documented under the section 7.3.7 (Fetching
health-check samples).

5 years agoMINOR: checks: Merge tcp-check comment rules with the others at config parsing
Christopher Faulet [Wed, 1 Apr 2020 11:11:41 +0000 (13:11 +0200)] 
MINOR: checks: Merge tcp-check comment rules with the others at config parsing

When a tcp-check healthcheck fails on a specific rule with no dedicated comment,
we look in previous rules if a comment rule is specified. Now, instead of doing
it during tcp-checks execution, we assign the comment to the corresponding rules
during the configuration parsing. So after HAProxy startup, no more comment
rules remains in a tcp-check ruleset.

5 years agoMINOR: checks: Add option to tcp-check expect rules to customize error status
Christopher Faulet [Wed, 1 Apr 2020 09:04:52 +0000 (11:04 +0200)] 
MINOR: checks: Add option to tcp-check expect rules to customize error status

It is now possible to specified the healthcheck status to use on error or on
timeout for tcp-check expect rules. First, to define the error status, the
option "error-status" must be used followed by "L4CON", "L6RSP", "L7RSP" or
"L7STS". Then, to define the timeout status, the option "tout-status" must be
used followed by "L4TOUT", "L6TOUT" or "L7TOUT".

These options will be used to convert specific protocol healthchecks (redis,
pgsql...) to tcp-check ones.
x

5 years agoMINOR: checks: Use a name for the healthcheck status enum
Christopher Faulet [Wed, 1 Apr 2020 08:37:29 +0000 (10:37 +0200)] 
MINOR: checks: Use a name for the healthcheck status enum

The enum defining all healthcheck status (HCHK_STATUS_*) is now named.

5 years agoMINOR: sample: add rtrim converter
Christopher Faulet [Wed, 1 Apr 2020 15:24:47 +0000 (17:24 +0200)] 
MINOR: sample: add rtrim converter

This converter strips specified characters from the end of a string.

5 years agoMINOR: sample: add ltrim converter
Christopher Faulet [Wed, 1 Apr 2020 15:24:41 +0000 (17:24 +0200)] 
MINOR: sample: add ltrim converter

This converter strips specified characters from the beginning of a string.

5 years agoMINOR: sample: add cut_crlf converter
Christopher Faulet [Wed, 1 Apr 2020 14:21:44 +0000 (16:21 +0200)] 
MINOR: sample: add cut_crlf converter

This converter cuts a string on the first \r or \n found.

5 years agoMINOR: sample: add htonl converter
Christopher Faulet [Wed, 1 Apr 2020 07:08:32 +0000 (09:08 +0200)] 
MINOR: sample: add htonl converter

This converter tranform a integer to its binary representation in the network
byte order. Integer are already automatically converted to binary during sample
expression evaluation. But because samples own 8-bytes integers, the conversion
produces 8 bytes. the htonl converter do the same but for 4-bytes integer.

5 years agoMEDIUM: checks: Add a shared list of tcp-check rules
Christopher Faulet [Mon, 30 Mar 2020 18:34:34 +0000 (20:34 +0200)] 
MEDIUM: checks: Add a shared list of tcp-check rules

A global list to tcp-check ruleset can now be used to share common rulesets with
all backends without any duplication. It is mandatory to convert all specific
protocol checks (redis, pgsql...) to tcp-check healthchecks.

To do so, a flag is now attached to each tcp-check ruleset to know if it is a
shared ruleset or not. tcp-check rules defined in a backend are still directly
attached to the proxy and not shared. In addition a second flag is used to know
if the ruleset is inherited from the defaults section.

5 years agoMINOR: log: Don't systematically set LW_REQ when a sample expr is added
Christopher Faulet [Mon, 6 Apr 2020 16:29:14 +0000 (18:29 +0200)] 
MINOR: log: Don't systematically set LW_REQ when a sample expr is added

When a log-format string is parsed, if a sample fetch is found, the flag LW_REQ
is systematically added on the proxy. Unfortunately, this produce a warning
during HAProxy start-up when a log-format string is used for a tcp-check send
rule. Now this flag is only added if the parsed sample fetch depends on HTTP
information.

5 years agoMINOR: log: Don't depends on a stream to process samples in log-format string
Christopher Faulet [Mon, 6 Apr 2020 08:40:02 +0000 (10:40 +0200)] 
MINOR: log: Don't depends on a stream to process samples in log-format string

When a log-format string is evaluated, there is no reason to process sample
fetches only when a stream is defined. Several sample fetches are available
outside the stream scope. All others should handle calls without stream. This
patch is mandatory to support log-format string in tcp-check rules.

5 years agoMEDIUM: checks: Support log-format strings for tcp-check send rules
Christopher Faulet [Mon, 30 Mar 2020 17:52:29 +0000 (19:52 +0200)] 
MEDIUM: checks: Support log-format strings for tcp-check send rules

An extra parameter for tcp-check send rules can be specified to handle the
string or the hexa string as a log-format one. Using "log-format" option,
instead of considering the data to send as raw data, it is parsed as a
log-format string. Thus it is possible to call sample fetches to customize data
sent to a server. Of course, because we have no stream attached to healthchecks,
not all sample fetches are available. So be careful.

    tcp-check set-var(check.port) int(8000)
    tcp-check set-var(check.uri) str(/status)
    tcp-check connect port var(check.port)
    tcp-check send "GET %[check.uri] HTTP/1.0\r\n" log-format
    tcp-check send "Host: %[srv_name]\r\n" log-format
    tcp-check send "\r\n"

5 years agoMEDIUM: checks: Support expression to set the port
Christopher Faulet [Mon, 30 Mar 2020 13:19:03 +0000 (15:19 +0200)] 
MEDIUM: checks: Support expression to set the port

Since we have a session attached to tcp-check healthchecks, It is possible use
sample expression and variables. In addition, it is possible to add tcp-check
set-var rules to define custom variables. So, now, a sample expression can be
used to define the port to use to establish a connection for a tcp-check connect
rule. For instance:

    tcp-check set-var(check.port) int(8888)
    tcp-check connect port var(check.port)

5 years agoMINOR: checks: Add the addr option for tcp-check connect rule
Christopher Faulet [Tue, 31 Mar 2020 06:15:58 +0000 (08:15 +0200)] 
MINOR: checks: Add the addr option for tcp-check connect rule

With this option, it is now possible to use a specific address to open the
connection for a tcp-check connect rule. If the port option is also specified,
it is used in priority.

5 years agoMINOR: checks: Add the default option for tcp-check connect rules
Christopher Faulet [Mon, 30 Mar 2020 11:54:42 +0000 (13:54 +0200)] 
MINOR: checks: Add the default option for tcp-check connect rules

With this option, it is possible to open a connection from a tcp-check connect
rule using all parameter of the server line, like any other healthcheck. For
now, this parameter is exclusive with all other option for a tcp-check connect
rule.

5 years agoMINOR: ssl: Export a generic function to parse an alpn string
Christopher Faulet [Mon, 20 Apr 2020 16:32:29 +0000 (18:32 +0200)] 
MINOR: ssl: Export a generic function to parse an alpn string

Parsing of an alpn string has been moved in a dedicated function and exposed to
be used from outside the ssl_sock module.

5 years agoMINOR: checks: Add the alpn option for tcp-check connect rules
Christopher Faulet [Mon, 30 Mar 2020 11:16:44 +0000 (13:16 +0200)] 
MINOR: checks: Add the alpn option for tcp-check connect rules

This option defines which protocols to advertise with ALPN on the SSL conection
opened by a tcp-check connect rule.

5 years agoMINOR: checks: Add the via-socks4 option for tcp-check connect rules
Christopher Faulet [Mon, 30 Mar 2020 11:07:02 +0000 (13:07 +0200)] 
MINOR: checks: Add the via-socks4 option for tcp-check connect rules

With this option, it is possible to establish the connection opened by a
tcp-check connect rule using upstream socks4 proxy. Info from the socks4
parameter on the server are used.

5 years agoMINOR: checks: Add the sni option for tcp-check connect rules
Christopher Faulet [Mon, 30 Mar 2020 11:00:05 +0000 (13:00 +0200)] 
MINOR: checks: Add the sni option for tcp-check connect rules

With this option, it is possible to specify the SNI to be used for SSL
conncection opened by a tcp-check connect rule.

5 years agoMINOR: checks: Add support to set-var and unset-var rules in tcp-checks
Gaetan Rivet [Mon, 24 Feb 2020 16:34:11 +0000 (17:34 +0100)] 
MINOR: checks: Add support to set-var and unset-var rules in tcp-checks

Evaluate the registered action_ptr associated with each CHK_ACTION_KW rules from
a ruleset. Currently only the 'set-var' and 'unset-var' are parsed by the
tcp-check parser. Thus it is now possible to set or unset variables. It is
possible to use such rules before the first connect of the ruleset.

5 years agoMEDIUM: checks: Parse custom action rules in tcp-checks
Gaetan Rivet [Fri, 21 Feb 2020 17:14:59 +0000 (18:14 +0100)] 
MEDIUM: checks: Parse custom action rules in tcp-checks

Register the custom action rules "set-var" and "unset-var", that will
call the parse_store() command upon parsing.

These rules are thus built and integrated to the tcp-check ruleset, but
have no further effect for the moment.

5 years agoMINOR: checks/vars: Add a check scope for variables
Gaetan Rivet [Fri, 21 Feb 2020 17:13:44 +0000 (18:13 +0100)] 
MINOR: checks/vars: Add a check scope for variables

Add a dedicated vars scope for checks. This scope is considered as part of the
session scope for accounting purposes.

The scope can be addressed by a valid session, even embryonic. The stream is not
necessary.

The scope is initialized after the check session is created. All variables are
then pruned before the session is destroyed.

5 years agoMEDIUM: checks: Associate a session to each tcp-check healthcheck
Gaetan Rivet [Fri, 14 Feb 2020 16:42:54 +0000 (17:42 +0100)] 
MEDIUM: checks: Associate a session to each tcp-check healthcheck

Create a session for each healthcheck relying on a tcp-check ruleset. When such
check is started, a session is allocated, which will be freed when the check
finishes. A dummy static frontend is used to create these sessions. This will be
useful to support variables and sample expression. This will also be used,
later, by HTTP healthchecks to rely on HTTP muxes.

5 years agoMAJOR: checks: Refactor and simplify the tcp-check loop
Christopher Faulet [Mon, 30 Mar 2020 09:05:10 +0000 (11:05 +0200)] 
MAJOR: checks: Refactor and simplify the tcp-check loop

The loop in tcpcheck_main() function is quite hard to understand. Depending
where we are in the loop, The current_step is the currentely executed rule or
the one to execute on the next call to tcpcheck_main(). When the check result is
reported, we rely on the rule pointed by last_started_step or the one pointed by
current_step. In addition, the loop does not use the common list_for_each_entry
macro and it is thus quite confusing.

So the loop has been totally rewritten and splitted to several functions to
simplify its reading and its understanding. Tcp-check rules are evaluated in
dedicated functions. And a common for_each loop is used and only one rule is
referenced, the current one.

5 years agoMEDIUM: checks: Add implicit tcp-check connect rule
Christopher Faulet [Thu, 26 Mar 2020 16:38:49 +0000 (17:38 +0100)] 
MEDIUM: checks: Add implicit tcp-check connect rule

After the configuration parsing, when its validity check, an implicit tcp-check
connect rule is added in front of the tcp-check ruleset if the first non-comment
rule is not a connect one. This implicit rule is flagged to use the default
check parameter.

This means now, all tcp-check rulesets begin with a connect and are never
empty. When tcp-check healthchecks are used, all connections are thus handled by
tcpcheck_main() function.

5 years agoMINOR: checks: define a tcp-check connect type
Gaetan Rivet [Fri, 21 Feb 2020 17:49:05 +0000 (18:49 +0100)] 
MINOR: checks: define a tcp-check connect type

The check rule itself is not changed, only its representation.

5 years agoMINOR: checks: define tcp-check send type
Gaetan Rivet [Fri, 21 Feb 2020 17:41:28 +0000 (18:41 +0100)] 
MINOR: checks: define tcp-check send type

The check rule itself is not changed, only its representation.

5 years agoMINOR: checks: Set the tcp-check rule index during parsing
Gaetan Rivet [Tue, 25 Feb 2020 16:19:17 +0000 (17:19 +0100)] 
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.

5 years agoMEDIUM: proxy/checks: Register a keyword to parse tcp-check rules
Christopher Faulet [Wed, 25 Mar 2020 17:20:15 +0000 (18:20 +0100)] 
MEDIUM: proxy/checks: Register a keyword to parse tcp-check rules

The keyword 'tcp-check' is now parsed in a dedicated callback function. Thus the
code to parse these rules is now located in checks.c. In addition, a deinit
function have been added to release proxy tcp-check rules, on error or when
HAProxy is stopped.

This patch is based on Gaetan Rivet work. It uses a callback function registerd
on the 'tcp-check' keyword instead, but the spirit is the same.

5 years agoMEDIUM: checks: Use a non-comment rule iterator to get next rule
Gaetan Rivet [Fri, 14 Feb 2020 16:47:08 +0000 (17:47 +0100)] 
MEDIUM: checks: Use a non-comment rule iterator to get next rule

This kind of iteration is used several times with various degrees of
clarity. Make a proper function for this use.

5 years agoMINOR: checks: Don't use a static tcp rule list head
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: Don't use a static tcp rule list head

To allow reusing these blocks without consuming more memory, their list
should be static and share-able accross uses. The head of the list will
be shared as well.

It is thus necessary to extract the head of the rule list from the proxy
itself. Transform it into a pointer instead, that can be easily set to
an external dynamically allocated head.

5 years agoMEDIUM: checks: capture groups in expect regexes
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MEDIUM: checks: capture groups in expect regexes

Parse back-references in comments of tcp-check expect rules.  If references are
made, capture groups in the match and replace references to it within the
comment when logging the error. Both text and binary regex can caputre groups
and reference them in the expect rule comment.

[Cf: I slightly updated the patch. exp_replace() function is used instead of a
custom one. And if the trash buffer is too small to contain the comment during
the substitution, the comment is ignored.]

5 years agoMINOR: checks: Simplify functions to get step id and comment
Christopher Faulet [Tue, 24 Mar 2020 12:31:19 +0000 (13:31 +0100)] 
MINOR: checks: Simplify functions to get step id and comment

The loop to find the id corresponding to the current rule in
tcpcheck_get_step_id() function has been simplified. And
tcpcheck_get_step_comment() function now only relies on the current rule to find
the rigth comment string. The step id is no longer used. To do so, we iterate
backward from the current step to find the first COMMENT rule immediately
preceedding the expect rule chain.

5 years agoMINOR: checks: add rbinary expect match type
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: add rbinary expect match type

The rbinary match works similarly to the rstring match type, however the
received data is rewritten as hex-string before the match operation is
done.

This allows using regexes on binary content even with the POSIX regex
engine.

[Cf: I slightly updated the patch. mem2hex function was removed and dump_binary
is used instead.]

5 years agoMINOR: checks: Stop xform buffers to null-terminated string for tcp-check rules
Christopher Faulet [Thu, 19 Mar 2020 15:59:45 +0000 (16:59 +0100)] 
MINOR: checks: Stop xform buffers to null-terminated string for tcp-check rules

On the input buffer, it was mainly done to call regex_exec() function. But
regex_exec2() can be used instead. This way, it is no more required to add the
terminating null byte. For the output buffer, it was only done for debugging
purpose.

5 years agoMEDIUM: checks: rewrite tcp-check expect block
Gaetan Rivet [Wed, 26 Feb 2020 14:59:22 +0000 (15:59 +0100)] 
MEDIUM: checks: rewrite tcp-check expect block

Simplify and shorten the tcp-check expect rule processing, to clarify
steps and avoid code duplication.

5 years agoMINOR: checks: define a tcp expect type
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: define a tcp expect type

Extract the expect definition from its tcpcheck ; create a standalone type.

5 years agoMINOR: checks: add linger option to tcp connect
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: add linger option to tcp connect

Allow declaring tcpcheck connect commands with a new parameter,
"linger". This option will configure the connection to avoid using an
RST segment to close, instead following the four-way termination
handshake. Some servers would otherwise log each healthcheck as
an error.

5 years agoMINOR: checks: add min-recv tcp-check expect option
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: add min-recv tcp-check expect option

Some expect rules cannot be satisfied due to inherent ambiguity towards
the received data: in the absence of match, the current behavior is to
be forced to wait either the end of the connection or a buffer full,
whichever comes first. Only then does the matching diagnostic is
considered  conclusive. For instance :

    tcp-check connect
    tcp-check expect !rstring "^error"
    tcp-check expect string "valid"

This check will only succeed if the connection is closed by the server before
the check timeout. Otherwise the first expect rule will wait for more data until
"^error" regex matches or the check expires.

Allow the user to explicitly define an amount of data that will be
considered enough to determine the value of the check.

This allows succeeding on negative rstring rules, as previously
in valid condition no match happened, and the matching was repeated
until the end of the connection. This could timeout the check
while no error was happening.

[Cf: I slighly updated the patch. The parameter was renamed and the value is a
signed integer to support -1 as default value to ignore the parameter.]

5 years agoMINOR: checks: simplify tcp expect config parser
Gaetan Rivet [Fri, 7 Feb 2020 14:37:17 +0000 (15:37 +0100)] 
MINOR: checks: simplify tcp expect config parser

Reduce copy of parsing portions that is common to all three types of
expect actions.

This reduces the amount of code, helping maintainability and reducing
future change spread.

Functionality is identical.

5 years agoMEDIUM: checks: rewind to the first inverse expect rule of a chain on new data
Gaetan Rivet [Wed, 26 Feb 2020 15:19:40 +0000 (16:19 +0100)] 
MEDIUM: checks: rewind to the first inverse expect rule of a chain on new data

When receiving additional data while chaining multiple tcp-check expects,
previous inverse expects might have a different result with the new data. They
need to be evaluated again against the new data.

Add a pointer to the first inverse expect rule of the current expect chain
(possibly of length one) to each expect rule. When receiving new data, the
currently evaluated tcp-check rule is set back to this pointed rule.

Fonctionnaly speaking, it is a bug and it exists since the introduction of the
feature. But there is no way for now to hit it because when an expect rule does
not match, we wait for more data, independently on the inverse flag. The only
way to move to the following rule is to be sure no more data will be received.

This patch depends on the commit "MINOR: mini-clist: Add functions to iterate
backward on a list".

[Cf: I slightly updated the patch. First, it only concerns inverse expect
rule. Normal expect rules are not concerned. Then, I removed the BUG tag
because, for now, it is not possible to move to the following rule when the
current one does not match while more data can be received.]

5 years agoMINOR: checks: Simplify connection flag parsing in tcp-check connect
Gaetan Rivet [Fri, 28 Feb 2020 10:04:21 +0000 (11:04 +0100)] 
MINOR: checks: Simplify connection flag parsing in tcp-check connect

The ternary operator is useless here, this can be simpler and clearer to
read.

5 years agoMINOR: checks: Use an enum to describe the tcp-check rule type
Gaetan Rivet [Fri, 14 Feb 2020 10:25:09 +0000 (11:25 +0100)] 
MINOR: checks: Use an enum to describe the tcp-check rule type

Replace the generic integer with an enumerated list. This allows light
type check and helps debugging (seeing action = 2 in the struct is not
helpful).

5 years agoBUG/MINOR: checks: Forbid tcp-check lines in default section as documented
Christopher Faulet [Mon, 6 Apr 2020 05:49:19 +0000 (07:49 +0200)] 
BUG/MINOR: checks: Forbid tcp-check lines in default section as documented

5 years agoBUG/MINOR: checks: chained expect will not properly wait for enough data
Gaetan Rivet [Thu, 13 Feb 2020 09:30:01 +0000 (10:30 +0100)] 
BUG/MINOR: checks: chained expect will not properly wait for enough data

TCP check expect matching strings or binary patterns are able to know
prior to applying their match function whether the available data is
already sufficient to attempt the match or not.

As such, on insufficient data the expect is postponed. This behavior
avoids unnecessary matches when the data could not possibly match.

When chaining expect, upon passing the previous and going onto the next
however, this length check is not done again. Then the match is done and
will necessarily fail, triggering a new wait for more data. The end
result is the same for a slightly higher cost.

Check received data length for all expects in a chain.

This bug exists since the introduction of the feature:
Fixes: 5ecb77f4c76f ("MEDIUM: checks: add send/expect tcp based check")
Version 1.5+ impacted.

5 years agoCLEANUP: checks: Don't export anymore init_check and srv_check_healthcheck_port
Christopher Faulet [Thu, 26 Mar 2020 20:10:03 +0000 (21:10 +0100)] 
CLEANUP: checks: Don't export anymore init_check and srv_check_healthcheck_port

These functions are no longer called outside the checks.