diff --git a/Makefile b/Makefile index 9d70f3645..afdd7d738 100644 --- a/Makefile +++ b/Makefile @@ -791,7 +791,7 @@ endif OBJS = src/mux_h2.o src/stream.o src/mux_fcgi.o src/cfgparse-listen.o \ src/http_ana.o src/stats.o src/mux_h1.o src/flt_spoe.o src/server.o \ - src/cfgparse.o src/checks.o src/backend.o src/log.o src/peers.o \ + src/cfgparse.o src/check.o src/backend.o src/log.o src/peers.o \ src/cli.o src/haproxy.o src/stick_table.o src/tools.o src/sample.o \ src/proxy.o src/stream_interface.o src/pattern.o src/dns.o \ src/proto_tcp.o src/listener.o src/cfgparse-global.o src/h1.o \ diff --git a/include/types/checks.h b/include/haproxy/check-t.h similarity index 95% rename from include/types/checks.h rename to include/haproxy/check-t.h index 9d05ffc8e..832a3f552 100644 --- a/include/types/checks.h +++ b/include/haproxy/check-t.h @@ -1,7 +1,9 @@ /* - * Health-checks. + * include/haproxy/check-t.h + * Health-checks definitions, enums, macros and bitfields. * * Copyright 2008-2009 Krzysztof Piotr Oledzki + * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -10,22 +12,25 @@ * */ -#ifndef _TYPES_CHECKS_H -#define _TYPES_CHECKS_H +#ifndef _HAPROXY_CHECKS_T_H +#define _HAPROXY_CHECKS_T_H -#include #include - #include +#include #include #include #include -#include -#include +#include +#include -#include -#include -#include +/* Please note: this file tends to commonly be part of circular dependencies, + * so it is important to keep its includes list to the minimum possible (i.e. + * only types whose size needs to be known). Since there are no function + * prototypes nor pointers here, forward declarations are not really necessary. + * This file oughtt to be split into multiple parts, at least regular checks vs + * tcp-checks. + */ /* enum used by check->result. Must remain in this order, as some code uses * result >= CHK_RES_PASSED to declare success. @@ -131,46 +136,7 @@ enum { HANA_OBS_SIZE }; -struct proxy; -struct server; -struct check { - enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */ - struct session *sess; /* Health check session. */ - struct vars vars; /* Health check dynamic variables. */ - struct xprt_ops *xprt; /* transport layer operations for health checks */ - struct conn_stream *cs; /* conn_stream state for health checks */ - struct buffer bi, bo; /* input and output buffers to send/recv check */ - struct task *task; /* the task associated to the health check processing, NULL if disabled */ - struct timeval start; /* last health check start time */ - long duration; /* time in ms took to finish last health check */ - short status, code; /* check result, check code */ - unsigned short port; /* the port to use for the health checks */ - char desc[HCHK_DESC_LEN]; /* health check description */ - signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */ - int send_proxy; /* send a PROXY protocol header with checks */ - struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */ - struct tcpcheck_rule *current_step; /* current step when using tcpcheck */ - int inter, fastinter, downinter; /* checks: time in milliseconds */ - enum chk_result result; /* health-check result : CHK_RES_* */ - int state; /* state of the check : CHK_ST_* */ - int health; /* 0 to rise-1 = bad; - * rise to rise+fall-1 = good */ - int rise, fall; /* time in iterations */ - int type; /* Check type, one of PR_O2_*_CHK */ - struct server *server; /* back-pointer to server */ - struct proxy *proxy; /* proxy to be used */ - char **argv; /* the arguments to use if running a process-based check */ - char **envp; /* the environment to use if running a process-based check */ - struct pid_list *curpid; /* entry in pid_list used for current process-based test, or -1 if not in test */ - struct sockaddr_storage addr; /* the address to check */ - struct wait_event wait_list; /* Waiting for I/O events */ - char *sni; /* Server name */ - char *alpn_str; /* ALPN to use for checks */ - int alpn_len; /* ALPN string length */ - const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */ - int via_socks4; /* check the connection via socks4 proxy */ -}; - +/* options for tcp-check connect */ #define TCPCHK_OPT_NONE 0x0000 /* no options specified, default */ #define TCPCHK_OPT_SEND_PROXY 0x0001 /* send proxy-protocol string */ #define TCPCHK_OPT_SSL 0x0002 /* SSL connection */ @@ -179,17 +145,6 @@ struct check { #define TCPCHK_OPT_IMPLICIT 0x0010 /* Implicit connect */ #define TCPCHK_OPT_SOCKS4 0x0020 /* check the connection via socks4 proxy */ -struct tcpcheck_connect { - char *sni; /* server name to use for SSL connections */ - char *alpn; /* ALPN to use for the SSL connection */ - int alpn_len; /* ALPN string length */ - const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */ - uint16_t options; /* options when setting up a new connection */ - uint16_t port; /* port to connect to */ - struct sample_expr *port_expr; /* sample expr to determine the port, may be NULL */ - struct sockaddr_storage addr; /* the address to the connect */ -}; - enum tcpcheck_send_type { TCPCHK_SEND_UNDEF = 0, /* Send is not parsed. */ TCPCHK_SEND_STRING, /* Send an ASCII string. */ @@ -199,43 +154,11 @@ enum tcpcheck_send_type { TCPCHK_SEND_HTTP, /* Send an HTTP request */ }; -struct tcpcheck_http_hdr { - struct ist name; /* the header name */ - struct list value; /* the log-format string value */ - struct list list; /* header chained list */ -}; - -struct tcpcheck_codes { - unsigned int (*codes)[2]; /* an array of roange of codes: [0]=min [1]=max */ - size_t num; /* number of entry in the array */ -}; - +/* flags for tcp-check send */ #define TCPCHK_SND_HTTP_FL_URI_FMT 0x0001 /* Use a log-format string for the uri */ #define TCPCHK_SND_HTTP_FL_BODY_FMT 0x0002 /* Use a log-format string for the body */ #define TCPCHK_SND_HTTP_FROM_OPT 0x0004 /* Send rule coming from "option httpck" directive */ -struct tcpcheck_send { - enum tcpcheck_send_type type; - union { - struct ist data; /* an ASCII string or a binary sequence */ - struct list fmt; /* an ASCII or hexa log-format string */ - struct { - unsigned int flags; /* TCPCHK_SND_HTTP_FL_* */ - struct http_meth meth; /* the HTTP request method */ - union { - struct ist uri; /* the HTTP request uri is a string */ - struct list uri_fmt; /* or a log-format string */ - }; - struct ist vsn; /* the HTTP request version string */ - struct list hdrs; /* the HTTP request header list */ - union { - struct ist body; /* the HTTP request payload is a string */ - struct list body_fmt; /* or a log-format string */ - }; - } http; /* Info about the HTTP request to send */ - }; -}; - enum tcpcheck_eval_ret { TCPCHK_EVAL_WAIT = 0, TCPCHK_EVAL_STOP, @@ -279,6 +202,115 @@ enum tcpcheck_expect_type { #define TCPCHK_EXPT_FL_HTTP_HNAME_TYPE 0x003E /* Mask to get matching method on header name */ #define TCPCHK_EXPT_FL_HTTP_HVAL_TYPE 0x1F00 /* Mask to get matching method on header value */ +/* possible actions for tcpcheck_rule->action */ +enum tcpcheck_rule_type { + TCPCHK_ACT_SEND = 0, /* send action, regular string format */ + TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */ + TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */ + TCPCHK_ACT_COMMENT, /* no action, simply a comment used for logs */ + TCPCHK_ACT_ACTION_KW, /* custom registered action_kw rule. */ +}; + +#define TCPCHK_RULES_NONE 0x00000000 +#define TCPCHK_RULES_UNUSED_TCP_RS 0x00000001 /* An unused tcp-check ruleset exists */ +#define TCPCHK_RULES_UNUSED_HTTP_RS 0x00000002 /* An unused http-check ruleset exists */ +#define TCPCHK_RULES_UNUSED_RS 0x00000003 /* Mask for unused ruleset */ + +#define TCPCHK_RULES_PGSQL_CHK 0x00000010 +#define TCPCHK_RULES_REDIS_CHK 0x00000020 +#define TCPCHK_RULES_SMTP_CHK 0x00000030 +#define TCPCHK_RULES_HTTP_CHK 0x00000040 +#define TCPCHK_RULES_MYSQL_CHK 0x00000050 +#define TCPCHK_RULES_LDAP_CHK 0x00000060 +#define TCPCHK_RULES_SSL3_CHK 0x00000070 +#define TCPCHK_RULES_AGENT_CHK 0x00000080 +#define TCPCHK_RULES_SPOP_CHK 0x00000090 +/* Unused 0x000000A0..0x00000FF0 (reserverd for futur proto) */ +#define TCPCHK_RULES_TCP_CHK 0x00000FF0 +#define TCPCHK_RULES_PROTO_CHK 0x00000FF0 /* Mask to cover protocol check */ + +struct check { + enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */ + struct session *sess; /* Health check session. */ + struct vars vars; /* Health check dynamic variables. */ + struct xprt_ops *xprt; /* transport layer operations for health checks */ + struct conn_stream *cs; /* conn_stream state for health checks */ + struct buffer bi, bo; /* input and output buffers to send/recv check */ + struct task *task; /* the task associated to the health check processing, NULL if disabled */ + struct timeval start; /* last health check start time */ + long duration; /* time in ms took to finish last health check */ + short status, code; /* check result, check code */ + unsigned short port; /* the port to use for the health checks */ + char desc[HCHK_DESC_LEN]; /* health check description */ + signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */ + int send_proxy; /* send a PROXY protocol header with checks */ + struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */ + struct tcpcheck_rule *current_step; /* current step when using tcpcheck */ + int inter, fastinter, downinter; /* checks: time in milliseconds */ + enum chk_result result; /* health-check result : CHK_RES_* */ + int state; /* state of the check : CHK_ST_* */ + int health; /* 0 to rise-1 = bad; + * rise to rise+fall-1 = good */ + int rise, fall; /* time in iterations */ + int type; /* Check type, one of PR_O2_*_CHK */ + struct server *server; /* back-pointer to server */ + struct proxy *proxy; /* proxy to be used */ + char **argv; /* the arguments to use if running a process-based check */ + char **envp; /* the environment to use if running a process-based check */ + struct pid_list *curpid; /* entry in pid_list used for current process-based test, or -1 if not in test */ + struct sockaddr_storage addr; /* the address to check */ + struct wait_event wait_list; /* Waiting for I/O events */ + char *sni; /* Server name */ + char *alpn_str; /* ALPN to use for checks */ + int alpn_len; /* ALPN string length */ + const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */ + int via_socks4; /* check the connection via socks4 proxy */ +}; + +struct tcpcheck_connect { + char *sni; /* server name to use for SSL connections */ + char *alpn; /* ALPN to use for the SSL connection */ + int alpn_len; /* ALPN string length */ + const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */ + uint16_t options; /* options when setting up a new connection */ + uint16_t port; /* port to connect to */ + struct sample_expr *port_expr; /* sample expr to determine the port, may be NULL */ + struct sockaddr_storage addr; /* the address to the connect */ +}; + +struct tcpcheck_http_hdr { + struct ist name; /* the header name */ + struct list value; /* the log-format string value */ + struct list list; /* header chained list */ +}; + +struct tcpcheck_codes { + unsigned int (*codes)[2]; /* an array of roange of codes: [0]=min [1]=max */ + size_t num; /* number of entry in the array */ +}; + +struct tcpcheck_send { + enum tcpcheck_send_type type; + union { + struct ist data; /* an ASCII string or a binary sequence */ + struct list fmt; /* an ASCII or hexa log-format string */ + struct { + unsigned int flags; /* TCPCHK_SND_HTTP_FL_* */ + struct http_meth meth; /* the HTTP request method */ + union { + struct ist uri; /* the HTTP request uri is a string */ + struct list uri_fmt; /* or a log-format string */ + }; + struct ist vsn; /* the HTTP request version string */ + struct list hdrs; /* the HTTP request header list */ + union { + struct ist body; /* the HTTP request payload is a string */ + struct list body_fmt; /* or a log-format string */ + }; + } http; /* Info about the HTTP request to send */ + }; +}; + struct tcpcheck_expect { enum tcpcheck_expect_type type; /* Type of pattern used for matching. */ unsigned int flags; /* TCPCHK_EXPT_FL_* */ @@ -318,15 +350,6 @@ struct tcpcheck_action_kw { struct act_rule *rule; }; -/* possible actions for tcpcheck_rule->action */ -enum tcpcheck_rule_type { - TCPCHK_ACT_SEND = 0, /* send action, regular string format */ - TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */ - TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */ - TCPCHK_ACT_COMMENT, /* no action, simply a comment used for logs */ - TCPCHK_ACT_ACTION_KW, /* custom registered action_kw rule. */ -}; - struct tcpcheck_rule { struct list list; /* list linked to from the proxy */ enum tcpcheck_rule_type action; /* type of the rule. */ @@ -340,24 +363,6 @@ struct tcpcheck_rule { }; }; -#define TCPCHK_RULES_NONE 0x00000000 -#define TCPCHK_RULES_UNUSED_TCP_RS 0x00000001 /* An unused tcp-check ruleset exists */ -#define TCPCHK_RULES_UNUSED_HTTP_RS 0x00000002 /* An unused http-check ruleset exists */ -#define TCPCHK_RULES_UNUSED_RS 0x00000003 /* Mask for unused ruleset */ - -#define TCPCHK_RULES_PGSQL_CHK 0x00000010 -#define TCPCHK_RULES_REDIS_CHK 0x00000020 -#define TCPCHK_RULES_SMTP_CHK 0x00000030 -#define TCPCHK_RULES_HTTP_CHK 0x00000040 -#define TCPCHK_RULES_MYSQL_CHK 0x00000050 -#define TCPCHK_RULES_LDAP_CHK 0x00000060 -#define TCPCHK_RULES_SSL3_CHK 0x00000070 -#define TCPCHK_RULES_AGENT_CHK 0x00000080 -#define TCPCHK_RULES_SPOP_CHK 0x00000090 -/* Unused 0x000000A0..0x00000FF0 (reserverd for futur proto) */ -#define TCPCHK_RULES_TCP_CHK 0x00000FF0 -#define TCPCHK_RULES_PROTO_CHK 0x00000FF0 /* Mask to cover protocol check */ - /* A list of tcp-check vars, to be registered before executing a ruleset */ struct tcpcheck_var { struct ist name; /* the variable name with the scope */ @@ -379,4 +384,4 @@ struct tcpcheck_ruleset { }; -#endif /* _TYPES_CHECKS_H */ +#endif /* _HAPROXY_CHECKS_T_H */ diff --git a/include/proto/checks.h b/include/haproxy/check.h similarity index 74% rename from include/proto/checks.h rename to include/haproxy/check.h index d24943e75..85fc49b0d 100644 --- a/include/proto/checks.h +++ b/include/haproxy/check.h @@ -1,30 +1,33 @@ /* - include/proto/checks.h - Functions prototypes for the checks. + * include/haproxy/check.h + * Functions prototypes for the checks. + * + * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ - Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, version 2.1 - exclusively. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _PROTO_CHECKS_H -#define _PROTO_CHECKS_H +#ifndef _HAPROXY_CHECKS_H +#define _HAPROXY_CHECKS_H #include +#include +#include #include -#include +#include +#include const char *get_check_status_description(short check_status); const char *get_check_status_info(short check_status); @@ -88,7 +91,7 @@ int proxy_parse_external_check_opt(char **args, int cur_arg, struct proxy *curpx int set_srv_agent_send(struct server *srv, const char *send); -#endif /* _PROTO_CHECKS_H */ +#endif /* _HAPROXY_CHECKS_H */ /* * Local variables: diff --git a/include/haproxy/obj_type.h b/include/haproxy/obj_type.h index 56597056e..6f741e4de 100644 --- a/include/haproxy/obj_type.h +++ b/include/haproxy/obj_type.h @@ -23,6 +23,7 @@ #define _HAPROXY_OBJ_TYPE_H #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include static inline enum obj_type obj_type(const enum obj_type *t) { diff --git a/include/proto/http_fetch.h b/include/proto/http_fetch.h index 3a7261aa8..2c844355b 100644 --- a/include/proto/http_fetch.h +++ b/include/proto/http_fetch.h @@ -23,10 +23,10 @@ #define _PROTO_HTTP_FETCH_H #include +#include #include #include #include -#include #include struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, struct check *check, int vol); diff --git a/include/types/proxy.h b/include/types/proxy.h index a72232f6a..5ba68c7b9 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include #include -#include #include #include #include diff --git a/include/types/server.h b/include/types/server.h index 38326b0a1..1f9ef1f69 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,6 @@ #include #include #include -#include /* server states. Only SRV_ST_STOPPED indicates a down server. */ diff --git a/src/backend.c b/src/backend.c index 4a1b050a1..8e8618a50 100644 --- a/src/backend.c +++ b/src/backend.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -42,7 +43,6 @@ #include #include #include -#include #include #include #include diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 205fbef2d..943c4c811 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -24,7 +25,6 @@ #include #include -#include #include #include #include diff --git a/src/cfgparse.c b/src/cfgparse.c index c5b3944ba..6051b155e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +68,6 @@ #include #include #include -#include #include #include #include diff --git a/src/checks.c b/src/check.c similarity index 99% rename from src/checks.c rename to src/check.c index a9feb79d2..dfa30988d 100644 --- a/src/checks.c +++ b/src/check.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,6 @@ #include #include -#include #include #include #include diff --git a/src/cli.c b/src/cli.c index 4208ceabf..63d2b58f7 100644 --- a/src/cli.c +++ b/src/cli.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -50,7 +51,6 @@ #include #include #include -#include #include #include #include diff --git a/src/dns.c b/src/dns.c index 35f12d320..b49f62d84 100644 --- a/src/dns.c +++ b/src/dns.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,6 @@ #include #include -#include #include #include #include diff --git a/src/http_ana.c b/src/http_ana.c index 546e13957..edfacc4ff 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include -#include #include #include #include diff --git a/src/server.c b/src/server.c index 243dcafd3..904cadb89 100644 --- a/src/server.c +++ b/src/server.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -35,7 +36,6 @@ #include #include -#include #include #include #include diff --git a/src/stats.c b/src/stats.c index 281638cfe..1f1e5cd71 100644 --- a/src/stats.c +++ b/src/stats.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -53,7 +54,6 @@ #include #include -#include #include #include #include diff --git a/src/stream.c b/src/stream.c index 28ce2e54d..2f6ff043e 100644 --- a/src/stream.c +++ b/src/stream.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/src/vars.c b/src/vars.c index d2c87ded7..4a3b4574f 100644 --- a/src/vars.c +++ b/src/vars.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include /* This contains a pool of struct vars */ DECLARE_STATIC_POOL(var_pool, "vars", sizeof(struct var));