2006-06-25 20:48:02 -04:00
|
|
|
/*
|
2011-03-20 05:32:26 -04:00
|
|
|
* include/types/server.h
|
|
|
|
|
* This file defines everything related to servers.
|
|
|
|
|
*
|
2012-02-13 11:12:08 -05:00
|
|
|
* Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
|
2011-03-20 05:32:26 -04:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2006-06-25 20:48:02 -04:00
|
|
|
|
|
|
|
|
#ifndef _TYPES_SERVER_H
|
|
|
|
|
#define _TYPES_SERVER_H
|
|
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
2006-06-29 12:54:54 -04:00
|
|
|
#include <common/config.h>
|
2006-06-29 11:53:05 -04:00
|
|
|
#include <common/mini-clist.h>
|
2017-06-08 08:04:45 -04:00
|
|
|
#include <common/hathreads.h>
|
2019-05-10 03:58:43 -04:00
|
|
|
#include <common/openssl-compat.h>
|
2017-06-08 08:04:45 -04:00
|
|
|
|
2009-10-26 16:10:04 -04:00
|
|
|
#include <eb32tree.h>
|
2006-06-25 20:48:02 -04:00
|
|
|
|
2012-07-06 03:40:59 -04:00
|
|
|
#include <types/connection.h>
|
2009-10-04 08:52:57 -04:00
|
|
|
#include <types/counters.h>
|
2016-02-17 15:25:09 -05:00
|
|
|
#include <types/dns.h>
|
2009-03-05 12:43:00 -05:00
|
|
|
#include <types/freq_ctr.h>
|
2012-11-11 18:42:33 -05:00
|
|
|
#include <types/obj_type.h>
|
2006-06-25 20:48:02 -04:00
|
|
|
#include <types/proxy.h>
|
|
|
|
|
#include <types/queue.h>
|
2019-05-10 03:58:43 -04:00
|
|
|
#include <types/ssl_sock.h>
|
2006-06-25 20:48:02 -04:00
|
|
|
#include <types/task.h>
|
2009-09-23 16:09:24 -04:00
|
|
|
#include <types/checks.h>
|
2006-06-25 20:48:02 -04:00
|
|
|
|
|
|
|
|
|
2014-12-09 21:21:30 -05:00
|
|
|
/* server states. Only SRV_ST_STOPPED indicates a down server. */
|
2014-05-13 09:54:22 -04:00
|
|
|
enum srv_state {
|
2014-05-13 17:41:20 -04:00
|
|
|
SRV_ST_STOPPED = 0, /* the server is down. Please keep set to zero. */
|
|
|
|
|
SRV_ST_STARTING, /* the server is warming up (up but throttled) */
|
|
|
|
|
SRV_ST_RUNNING, /* the server is fully up */
|
|
|
|
|
SRV_ST_STOPPING, /* the server is up but soft-stopping (eg: 404) */
|
2017-11-26 01:26:48 -05:00
|
|
|
} __attribute__((packed));
|
2014-05-13 13:44:56 -04:00
|
|
|
|
2014-05-22 10:14:34 -04:00
|
|
|
/* Administrative status : a server runs in one of these 3 stats :
|
|
|
|
|
* - READY : normal mode
|
|
|
|
|
* - DRAIN : takes no new visitor, equivalent to weight == 0
|
|
|
|
|
* - MAINT : maintenance mode, no more traffic nor health checks.
|
|
|
|
|
*
|
|
|
|
|
* Each server may be in maintenance by itself or may inherit this status from
|
|
|
|
|
* another server it tracks. It can also be in drain mode by itself or inherit
|
|
|
|
|
* it from another server. Let's store these origins here as flags. These flags
|
|
|
|
|
* are combined this way :
|
|
|
|
|
*
|
|
|
|
|
* FMAINT IMAINT FDRAIN IDRAIN Resulting state
|
|
|
|
|
* 0 0 0 0 READY
|
|
|
|
|
* 0 0 0 1 DRAIN
|
|
|
|
|
* 0 0 1 x DRAIN
|
|
|
|
|
* 0 1 x x MAINT
|
|
|
|
|
* 1 x x x MAINT
|
|
|
|
|
*
|
|
|
|
|
* This can be simplified this way :
|
|
|
|
|
*
|
|
|
|
|
* state_str = (state & MAINT) ? "MAINT" : (state & DRAIN) : "DRAIN" : "READY"
|
2014-05-13 13:44:56 -04:00
|
|
|
*/
|
|
|
|
|
enum srv_admin {
|
2015-08-08 09:49:13 -04:00
|
|
|
SRV_ADMF_FMAINT = 0x01, /* the server was explicitly forced into maintenance */
|
|
|
|
|
SRV_ADMF_IMAINT = 0x02, /* the server has inherited the maintenance status from a tracked server */
|
2016-11-02 16:31:27 -04:00
|
|
|
SRV_ADMF_MAINT = 0x23, /* mask to check if any maintenance flag is present */
|
2015-08-08 09:49:13 -04:00
|
|
|
SRV_ADMF_CMAINT = 0x04, /* the server is in maintenance because of the configuration */
|
|
|
|
|
SRV_ADMF_FDRAIN = 0x08, /* the server was explicitly forced into drain state */
|
|
|
|
|
SRV_ADMF_IDRAIN = 0x10, /* the server has inherited the drain status from a tracked server */
|
|
|
|
|
SRV_ADMF_DRAIN = 0x18, /* mask to check if any drain flag is present */
|
2016-11-02 16:31:27 -04:00
|
|
|
SRV_ADMF_RMAINT = 0x20, /* the server is down because of an IP address resolution failure */
|
2017-04-26 05:24:02 -04:00
|
|
|
SRV_ADMF_HMAINT = 0x40, /* the server FQDN has been set from socket stats */
|
2017-11-26 01:26:48 -05:00
|
|
|
} __attribute__((packed));
|
2014-05-13 09:54:22 -04:00
|
|
|
|
2016-09-21 14:26:16 -04:00
|
|
|
/* options for servers' "init-addr" parameter
|
|
|
|
|
* this parameter may be used to drive HAProxy's behavior when parsing a server
|
|
|
|
|
* address at start up time.
|
|
|
|
|
* These values are stored as a list into an integer ordered from first to last
|
|
|
|
|
* starting with the lowest to highest bits. SRV_IADDR_END (0) is used to
|
|
|
|
|
* indicate the end of the list. 3 bits are enough to store each value.
|
|
|
|
|
*/
|
|
|
|
|
enum srv_initaddr {
|
|
|
|
|
SRV_IADDR_END = 0, /* end of the list */
|
|
|
|
|
SRV_IADDR_NONE = 1, /* the server won't have any address at start up */
|
|
|
|
|
SRV_IADDR_LIBC = 2, /* address set using the libc DNS resolver */
|
|
|
|
|
SRV_IADDR_LAST = 3, /* we set the IP address found in state-file for this server */
|
2016-11-02 10:05:56 -04:00
|
|
|
SRV_IADDR_IP = 4, /* we set an arbitrary IP address to the server */
|
2017-11-26 01:26:48 -05:00
|
|
|
} __attribute__((packed));
|
2016-09-21 14:26:16 -04:00
|
|
|
|
2015-05-08 17:34:06 -04:00
|
|
|
/* server-state-file version */
|
|
|
|
|
#define SRV_STATE_FILE_VERSION 1
|
|
|
|
|
#define SRV_STATE_FILE_VERSION_MIN 1
|
|
|
|
|
#define SRV_STATE_FILE_VERSION_MAX 1
|
2017-04-26 05:24:02 -04:00
|
|
|
#define SRV_STATE_FILE_FIELD_NAMES \
|
|
|
|
|
"be_id " \
|
|
|
|
|
"be_name " \
|
|
|
|
|
"srv_id " \
|
|
|
|
|
"srv_name " \
|
|
|
|
|
"srv_addr " \
|
|
|
|
|
"srv_op_state " \
|
|
|
|
|
"srv_admin_state " \
|
|
|
|
|
"srv_uweight " \
|
|
|
|
|
"srv_iweight " \
|
|
|
|
|
"srv_time_since_last_change " \
|
|
|
|
|
"srv_check_status " \
|
|
|
|
|
"srv_check_result " \
|
|
|
|
|
"srv_check_health " \
|
|
|
|
|
"srv_check_state " \
|
|
|
|
|
"srv_agent_state " \
|
|
|
|
|
"bk_f_forced_id " \
|
|
|
|
|
"srv_f_forced_id " \
|
2017-08-01 02:47:19 -04:00
|
|
|
"srv_fqdn " \
|
2018-07-02 11:00:54 -04:00
|
|
|
"srv_port " \
|
|
|
|
|
"srvrecord"
|
2017-04-26 05:24:02 -04:00
|
|
|
|
2018-07-02 11:00:54 -04:00
|
|
|
#define SRV_STATE_FILE_MAX_FIELDS 20
|
|
|
|
|
#define SRV_STATE_FILE_NB_FIELDS_VERSION_1 19
|
2015-05-08 17:34:06 -04:00
|
|
|
#define SRV_STATE_LINE_MAXLEN 512
|
|
|
|
|
|
2017-01-23 15:38:57 -05:00
|
|
|
/* server flags -- 32 bits */
|
2014-05-13 09:54:22 -04:00
|
|
|
#define SRV_F_BACKUP 0x0001 /* this server is a backup server */
|
|
|
|
|
#define SRV_F_MAPPORTS 0x0002 /* this server uses mapped ports */
|
|
|
|
|
#define SRV_F_NON_STICK 0x0004 /* never add connections allocated to this server to a stick table */
|
2014-11-17 09:11:45 -05:00
|
|
|
#define SRV_F_USE_NS_FROM_PP 0x0008 /* use namespace associated with connection if present */
|
2015-07-07 16:02:20 -04:00
|
|
|
#define SRV_F_FORCED_ID 0x0010 /* server's ID was forced in the configuration */
|
2016-08-11 17:12:18 -04:00
|
|
|
#define SRV_F_CHECKADDR 0x0020 /* this server has a check addr configured */
|
|
|
|
|
#define SRV_F_CHECKPORT 0x0040 /* this server has a check port configured */
|
|
|
|
|
#define SRV_F_AGENTADDR 0x0080 /* this server has a agent addr configured */
|
MINOR: server: Add dynamic session cookies.
This adds a new "dynamic" keyword for the cookie option. If set, a cookie
will be generated for each server (assuming one isn't already provided on
the "server" line), from the IP of the server, the TCP port, and a secret
key provided. To provide the secret key, a new keyword as been added,
"dynamic-cookie-key", for backends.
Example :
backend bk_web
balance roundrobin
dynamic-cookie-key "bla"
cookie WEBSRV insert dynamic
server s1 127.0.0.1:80 check
server s2 192.168.56.1:80 check
This is a first step to be able to dynamically add and remove servers,
without modifying the configuration file, and still have all the load
balancers redirect the traffic to the right server.
Provide a way to generate session cookies, based on the IP address of the
server, the TCP port, and a secret key provided.
2017-03-14 15:01:29 -04:00
|
|
|
#define SRV_F_COOKIESET 0x0100 /* this server has a cookie configured, so don't generate dynamic cookies */
|
2019-05-08 13:48:32 -04:00
|
|
|
#define SRV_F_FASTOPEN 0x0200 /* Use TCP Fast Open to connect to server */
|
2019-05-22 07:44:48 -04:00
|
|
|
#define SRV_F_SOCKS4_PROXY 0x0400 /* this server uses SOCKS4 proxy */
|
2006-06-25 20:48:02 -04:00
|
|
|
|
2014-05-08 23:42:08 -04:00
|
|
|
/* configured server options for send-proxy (server->pp_opts) */
|
2018-02-01 09:53:52 -05:00
|
|
|
#define SRV_PP_V1 0x0001 /* proxy protocol version 1 */
|
|
|
|
|
#define SRV_PP_V2 0x0002 /* proxy protocol version 2 */
|
|
|
|
|
#define SRV_PP_V2_SSL 0x0004 /* proxy protocol version 2 with SSL */
|
|
|
|
|
#define SRV_PP_V2_SSL_CN 0x0008 /* proxy protocol version 2 with CN */
|
|
|
|
|
#define SRV_PP_V2_SSL_KEY_ALG 0x0010 /* proxy protocol version 2 with cert key algorithm */
|
|
|
|
|
#define SRV_PP_V2_SSL_SIG_ALG 0x0020 /* proxy protocol version 2 with cert signature algorithm */
|
|
|
|
|
#define SRV_PP_V2_SSL_CIPHER 0x0040 /* proxy protocol version 2 with cipher used */
|
2018-02-01 12:29:59 -05:00
|
|
|
#define SRV_PP_V2_AUTHORITY 0x0080 /* proxy protocol version 2 with authority */
|
2018-02-05 09:26:43 -05:00
|
|
|
#define SRV_PP_V2_CRC32C 0x0100 /* proxy protocol version 2 with crc32c */
|
2014-05-08 23:42:08 -04:00
|
|
|
|
2006-06-25 20:48:02 -04:00
|
|
|
/* function which act on servers need to return various errors */
|
|
|
|
|
#define SRV_STATUS_OK 0 /* everything is OK. */
|
|
|
|
|
#define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */
|
|
|
|
|
#define SRV_STATUS_NOSRV 2 /* no server is available */
|
|
|
|
|
#define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */
|
|
|
|
|
#define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */
|
|
|
|
|
|
2007-12-02 05:01:23 -05:00
|
|
|
/* various constants */
|
|
|
|
|
#define SRV_UWGHT_RANGE 256
|
2013-07-21 19:44:53 -04:00
|
|
|
#define SRV_UWGHT_MAX (SRV_UWGHT_RANGE)
|
2007-12-02 05:01:23 -05:00
|
|
|
#define SRV_EWGHT_RANGE (SRV_UWGHT_RANGE * BE_WEIGHT_SCALE)
|
|
|
|
|
#define SRV_EWGHT_MAX (SRV_UWGHT_MAX * BE_WEIGHT_SCALE)
|
|
|
|
|
|
2012-10-05 07:48:26 -04:00
|
|
|
#ifdef USE_OPENSSL
|
|
|
|
|
/* server ssl options */
|
|
|
|
|
#define SRV_SSL_O_NONE 0x0000
|
2012-10-11 09:28:34 -04:00
|
|
|
#define SRV_SSL_O_NO_TLS_TICKETS 0x0100 /* disable session resumption tickets */
|
2015-02-05 10:47:07 -05:00
|
|
|
#define SRV_SSL_O_NO_REUSE 0x200 /* disable session reuse */
|
2017-11-03 11:27:47 -04:00
|
|
|
#define SRV_SSL_O_EARLY_DATA 0x400 /* Allow using early data */
|
2012-10-05 07:48:26 -04:00
|
|
|
#endif
|
|
|
|
|
|
2019-05-20 03:47:07 -04:00
|
|
|
/* The server names dictionary */
|
|
|
|
|
extern struct dict server_name_dict;
|
|
|
|
|
|
2014-06-19 23:30:16 -04:00
|
|
|
struct pid_list {
|
|
|
|
|
struct list list;
|
|
|
|
|
pid_t pid;
|
|
|
|
|
struct task *t;
|
|
|
|
|
int status;
|
|
|
|
|
int exited;
|
|
|
|
|
};
|
|
|
|
|
|
[MEDIUM] backend: implement consistent hashing variation
Consistent hashing provides some interesting advantages over common
hashing. It avoids full redistribution in case of a server failure,
or when expanding the farm. This has a cost however, the hashing is
far from being perfect, as we associate a server to a request by
searching the server with the closest key in a tree. Since servers
appear multiple times based on their weights, it is recommended to
use weights larger than approximately 10-20 in order to smoothen
the distribution a bit.
In some cases, playing with weights will be the only solution to
make a server appear more often and increase chances of being picked,
so stats are very important with consistent hashing.
In order to indicate the type of hashing, use :
hash-type map-based (default, old one)
hash-type consistent (new one)
Consistent hashing can make sense in a cache farm, in order not
to redistribute everyone when a cache changes state. It could also
probably be used for long sessions such as terminal sessions, though
that has not be attempted yet.
More details on this method of hashing here :
http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/
2009-10-01 01:52:15 -04:00
|
|
|
/* A tree occurrence is a descriptor of a place in a tree, with a pointer back
|
|
|
|
|
* to the server itself.
|
|
|
|
|
*/
|
|
|
|
|
struct server;
|
|
|
|
|
struct tree_occ {
|
|
|
|
|
struct server *server;
|
|
|
|
|
struct eb32_node node;
|
|
|
|
|
};
|
|
|
|
|
|
2006-06-25 20:48:02 -04:00
|
|
|
struct server {
|
2012-11-11 18:42:33 -05:00
|
|
|
enum obj_type obj_type; /* object type == OBJ_TYPE_SERVER */
|
2017-08-31 08:41:55 -04:00
|
|
|
enum srv_state next_state, cur_state; /* server state among SRV_ST_* */
|
|
|
|
|
enum srv_admin next_admin, cur_admin; /* server maintenance status : SRV_ADMF_* */
|
2018-03-19 13:14:02 -04:00
|
|
|
unsigned char use_ssl; /* ssl enabled */
|
2018-02-05 09:26:43 -05:00
|
|
|
unsigned int pp_opts; /* proxy protocol options (SRV_PP_*) */
|
2006-06-25 20:48:02 -04:00
|
|
|
struct server *next;
|
2009-09-23 16:09:24 -04:00
|
|
|
int cklen; /* the len of the cookie, to speed up checks */
|
2008-02-14 14:25:24 -05:00
|
|
|
int rdr_len; /* the length of the redirection prefix */
|
2007-03-25 15:03:01 -04:00
|
|
|
char *cookie; /* the id set in the cookie */
|
2008-02-14 14:25:24 -05:00
|
|
|
char *rdr_pfx; /* the redirection prefix */
|
2007-03-25 15:03:01 -04:00
|
|
|
|
|
|
|
|
struct proxy *proxy; /* the proxy this server belongs to */
|
2018-12-02 07:08:34 -05:00
|
|
|
const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */
|
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
|
|
|
int served; /* # of active sessions currently being served (ie not pending) */
|
2009-10-04 17:12:44 -04:00
|
|
|
int cur_sess; /* number of currently active sessions (including syn_sent) */
|
2007-03-25 15:03:01 -04:00
|
|
|
unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */
|
2009-10-04 17:12:44 -04:00
|
|
|
int nbpend; /* number of pending connections */
|
2018-05-11 12:52:31 -04:00
|
|
|
unsigned int queue_idx; /* count of pending connections which have been de-queued */
|
2007-10-25 14:15:38 -04:00
|
|
|
int maxqueue; /* maximum number of pending connections allowed */
|
2011-10-21 12:51:57 -04:00
|
|
|
struct freq_ctr sess_per_sec; /* sessions per second on this server */
|
CLEANUP: counters: move from 3 types to 2 types
We used to have 3 types of counters with a huge overlap :
- listener counters : stats collected for each bind line
- proxy counters : union of the frontend and backend counters
- server counters : stats collected per server
It happens that quite a good part was common between listeners and
proxies due to the frontend counters being updated at the two locations,
and that similarly the server and proxy counters were overlapping and
being updated together.
This patch cleans this up to propose only two types of counters :
- fe_counters: used by frontends and listeners, related to
incoming connections activity
- be_counters: used by backends and servers, related to outgoing
connections activity
This allowed to remove some non-sensical counters from both parts. For
frontends, the following entries were removed :
cum_lbconn, last_sess, nbpend_max, failed_conns, failed_resp,
retries, redispatches, q_time, c_time, d_time, t_time
For backends, this ones was removed : intercepted_req.
While doing this it was discovered that we used to incorrectly report
intercepted_req for backends in the HTML stats, which was always zero
since it's never updated.
Also it revealed a few inconsistencies (which were not fixed as they
are harmless). For example, backends count connections (cum_conn)
instead of sessions while servers count sessions and not connections.
Over the long term, some extra cleanups may be performed by having
some counters update functions touching both the server and backend
at the same time, as well as both the frontend and listener, to
ensure that all sides have all their stats properly filled. The stats
dump will also be able to factor the dump functions by counter types.
2016-11-25 08:44:52 -05:00
|
|
|
struct be_counters counters; /* statistics counters */
|
2009-10-04 17:12:44 -04:00
|
|
|
|
2018-05-11 12:52:31 -04:00
|
|
|
struct eb_root pendconns; /* pending connections */
|
2011-06-21 01:34:57 -04:00
|
|
|
struct list actconns; /* active connections */
|
2017-07-03 09:41:01 -04:00
|
|
|
struct list *priv_conns; /* private idle connections attached to stream interfaces */
|
|
|
|
|
struct list *idle_conns; /* sharable idle connections attached or not to a stream interface */
|
|
|
|
|
struct list *safe_conns; /* safe idle connections attached to stream interfaces, shared */
|
2019-08-08 09:47:21 -04:00
|
|
|
struct mt_list *idle_orphan_conns; /* Orphan connections idling */
|
2018-12-14 12:15:36 -05:00
|
|
|
unsigned int pool_purge_delay; /* Delay before starting to purge the idle conns pool */
|
2018-12-10 12:30:32 -05:00
|
|
|
unsigned int max_idle_conns; /* Max number of connection allowed in the orphan connections list */
|
|
|
|
|
unsigned int curr_idle_conns; /* Current number of orphan idling connections */
|
2019-02-18 10:41:17 -05:00
|
|
|
unsigned int *curr_idle_thr; /* Current number of orphan idling connections per thread */
|
2019-01-23 04:21:49 -05:00
|
|
|
int max_reuse; /* Max number of requests on a same connection */
|
2019-02-14 12:29:09 -05:00
|
|
|
struct eb32_node idle_node; /* When to next do cleanup in the idle connections */
|
2011-10-31 06:53:20 -04:00
|
|
|
struct task *warmup; /* the task dedicated to the warmup when slowstart is set */
|
2007-03-25 15:03:01 -04:00
|
|
|
|
2012-12-08 16:29:20 -05:00
|
|
|
struct conn_src conn_src; /* connection source settings */
|
2007-03-25 15:03:01 -04:00
|
|
|
|
2013-12-11 09:27:05 -05:00
|
|
|
struct server *track; /* the server we're currently tracking, if any */
|
|
|
|
|
struct server *trackers; /* the list of servers tracking us, if any */
|
|
|
|
|
struct server *tracknext; /* next server tracking <track> in <track>'s trackers list */
|
2008-02-17 19:26:35 -05:00
|
|
|
char *trackit; /* temporary variable to make assignment deferrable */
|
2009-12-15 16:31:24 -05:00
|
|
|
int consecutive_errors; /* current number of consecutive errors */
|
|
|
|
|
int consecutive_errors_limit; /* number of consecutive errors that triggers an event */
|
|
|
|
|
short observe, onerror; /* observing mode: one of HANA_OBS_*; what to do on error: on of ANA_ONERR_* */
|
2012-05-24 18:28:52 -04:00
|
|
|
short onmarkeddown; /* what to do when marked down: one of HANA_ONMARKEDDOWN_* */
|
|
|
|
|
short onmarkedup; /* what to do when marked up: one of HANA_ONMARKEDUP_* */
|
2017-11-26 01:26:48 -05:00
|
|
|
unsigned int flags; /* server flags (SRV_F_*) */
|
2007-11-30 11:42:05 -05:00
|
|
|
int slowstart; /* slowstart time in seconds (ms in the conf) */
|
2007-03-25 15:03:01 -04:00
|
|
|
|
|
|
|
|
char *id; /* just for identification */
|
2017-08-31 08:41:55 -04:00
|
|
|
unsigned iweight,uweight, cur_eweight; /* initial weight, user-specified weight, and effective weight */
|
2007-03-25 15:16:40 -04:00
|
|
|
unsigned wscore; /* weight score, used during srv map computation */
|
2017-08-31 08:41:55 -04:00
|
|
|
unsigned next_eweight; /* next pending eweight to commit */
|
2007-11-25 19:15:43 -05:00
|
|
|
unsigned rweight; /* remainer of weight in the current LB tree */
|
2016-10-25 12:49:45 -04:00
|
|
|
unsigned cumulative_weight; /* weight of servers prior to this one in the same group, for chash balancing */
|
2007-11-25 19:15:43 -05:00
|
|
|
unsigned npos, lpos; /* next and last positions in the LB tree */
|
|
|
|
|
struct eb32_node lb_node; /* node used for tree-based load balancing */
|
|
|
|
|
struct eb_root *lb_tree; /* we want to know in what tree the server is */
|
|
|
|
|
struct server *next_full; /* next server in the temporary full list */
|
[MEDIUM] backend: implement consistent hashing variation
Consistent hashing provides some interesting advantages over common
hashing. It avoids full redistribution in case of a server failure,
or when expanding the farm. This has a cost however, the hashing is
far from being perfect, as we associate a server to a request by
searching the server with the closest key in a tree. Since servers
appear multiple times based on their weights, it is recommended to
use weights larger than approximately 10-20 in order to smoothen
the distribution a bit.
In some cases, playing with weights will be the only solution to
make a server appear more often and increase chances of being picked,
so stats are very important with consistent hashing.
In order to indicate the type of hashing, use :
hash-type map-based (default, old one)
hash-type consistent (new one)
Consistent hashing can make sense in a cache farm, in order not
to redistribute everyone when a cache changes state. It could also
probably be used for long sessions such as terminal sessions, though
that has not be attempted yet.
More details on this method of hashing here :
http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/
2009-10-01 01:52:15 -04:00
|
|
|
unsigned lb_nodes_tot; /* number of allocated lb_nodes (C-HASH) */
|
|
|
|
|
unsigned lb_nodes_now; /* number of lb_nodes placed in the tree (C-HASH) */
|
|
|
|
|
struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */
|
2007-03-25 15:03:01 -04:00
|
|
|
|
2014-11-17 09:11:45 -05:00
|
|
|
const struct netns_entry *netns; /* contains network namespace name or NULL. Network namespace comes from configuration */
|
2011-10-21 12:51:57 -04:00
|
|
|
/* warning, these structs are huge, keep them at the bottom */
|
2017-01-06 11:41:29 -05:00
|
|
|
struct sockaddr_storage addr; /* the address to connect to, doesn't include the port */
|
REORG: connection: rename the data layer the "transport layer"
While working on the changes required to make the health checks use the
new connections, it started to become obvious that some naming was not
logical at all in the connections. Specifically, it is not logical to
call the "data layer" the layer which is in charge for all the handshake
and which does not yet provide a data layer once established until a
session has allocated all the required buffers.
In fact, it's more a transport layer, which makes much more sense. The
transport layer offers a medium on which data can transit, and it offers
the functions to move these data when the upper layer requests this. And
it is the upper layer which iterates over the transport layer's functions
to move data which should be called the data layer.
The use case where it's obvious is with embryonic sessions : an incoming
SSL connection is accepted. Only the connection is allocated, not the
buffers nor stream interface, etc... The connection handles the SSL
handshake by itself. Once this handshake is complete, we can't use the
data functions because the buffers and stream interface are not there
yet. Hence we have to first call a specific function to complete the
session initialization, after which we'll be able to use the data
functions. This clearly proves that SSL here is only a transport layer
and that the stream interface constitutes the data layer.
A similar change will be performed to rename app_cb => data, but the
two could not be in the same commit for obvious reasons.
2012-10-02 18:19:48 -04:00
|
|
|
struct xprt_ops *xprt; /* transport-layer operations */
|
2017-11-26 01:26:48 -05:00
|
|
|
unsigned int svc_port; /* the port to connect to (for relevant families) */
|
[MEDIUM] stats: report server and backend cumulated downtime
Hello,
This patch implements new statistics for SLA calculation by adding new
field 'Dwntime' with total down time since restart (both HTTP/CSV) and
extending status field (HTTP) or inserting a new one (CSV) with time
showing how long each server/backend is in a current state. Additionaly,
down transations are also calculated and displayed for backends, so it is
possible to know how many times selected backend was down, generating "No
server is available to handle this request." error.
New information are presentetd in two different ways:
- for HTTP: a "human redable form", one of "100000d 23h", "23h 59m" or
"59m 59s"
- for CSV: seconds
I believe that seconds resolution is enough.
As there are more columns in the status page I decided to shrink some
names to make more space:
- Weight -> Wght
- Check -> Chk
- Down -> Dwn
Making described changes I also made some improvements and fixed some
small bugs:
- don't increment s->health above 's->rise + s->fall - 1'. Previously it
was incremented an then (re)set to 's->rise + s->fall - 1'.
- do not set server down if it is down already
- do not set server up if it is up already
- fix colspan in multiple places (mostly introduced by my previous patch)
- add missing "status" header to CSV
- fix order of retries/redispatches in server (CSV)
- s/Tthen/Then/
- s/server/backend/ in DATA_ST_PX_BE (dumpstats.c)
Changes from previous version:
- deal with negative time intervales
- don't relay on s->state (SRV_RUNNING)
- little reworked human_time + compacted format (no spaces). If needed it
can be used in the future for other purposes by optionally making "cnt"
as an argument
- leave set_server_down mostly unchanged
- only little reworked "process_chk: 9"
- additional fields in CSV are appended to the rigth
- fix "SEC" macro
- named arguments (human_time, be_downtime, srv_downtime)
Hope it is OK. If there are only cosmetic changes needed please fill free
to correct it, however if there are some bigger changes required I would
like to discuss it first or at last to know what exactly was changed
especially since I already put this patch into my production server. :)
Thank you,
Best regards,
Krzysztof Oledzki
2007-10-22 10:21:10 -04:00
|
|
|
unsigned down_time; /* total time the server was down */
|
|
|
|
|
time_t last_change; /* last time, when the state was changed */
|
|
|
|
|
|
2012-02-13 11:12:08 -05:00
|
|
|
int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo */
|
2015-10-13 10:16:41 -04:00
|
|
|
int tcp_ut; /* for TCP, user timeout */
|
2009-10-04 08:52:57 -04:00
|
|
|
|
2017-03-14 06:20:13 -04:00
|
|
|
int do_check; /* temporary variable used during parsing to denote if health checks must be enabled */
|
2017-03-21 11:39:15 -04:00
|
|
|
int do_agent; /* temporary variable used during parsing to denote if an auxiliary agent check must be enabled */
|
2013-02-22 20:16:43 -05:00
|
|
|
struct check check; /* health-check specific configuration */
|
2013-11-24 20:46:36 -05:00
|
|
|
struct check agent; /* agent specific configuration */
|
[MEDIUM] checks: support multi-packet health check responses
We are seeing both real servers repeatedly going on- and off-line with
a period of tens of seconds. Packet tracing, stracing, and adding
debug code to HAProxy itself has revealed that the real servers are
always responding correctly, but HAProxy is sometimes receiving only
part of the response.
It appears that the real servers are sending the test page as three
separate packets. HAProxy receives the contents of one, two, or three
packets, apparently randomly. Naturally, the health check only
succeeds when all three packets' data are seen by HAProxy. If HAProxy
and the real servers are modified to use a plain HTML page for the
health check, the response is in the form of a single packet and the
checks do not fail.
(...)
I've added buffer and length variables to struct server, and allocated
space with the rest of the server initialisation.
(...)
It seems to be working fine in my tests, and handles check responses
that are bigger than the buffer.
2010-03-16 11:50:46 -04:00
|
|
|
|
MAJOR/REORG: dns: DNS resolution task and requester queues
This patch is a major upgrade of the internal run-time DNS resolver in
HAProxy and it brings the following 2 main changes:
1. DNS resolution task
Up to now, DNS resolution was triggered by the health check task.
From now, DNS resolution task is autonomous. It is started by HAProxy
right after the scheduler is available and it is woken either when a
network IO occurs for one of its nameserver or when a timeout is
matched.
From now, this means we can enable DNS resolution for a server without
enabling health checking.
2. Introduction of a dns_requester structure
Up to now, DNS resolution was purposely made for resolving server
hostnames.
The idea, is to ensure that any HAProxy internal object should be able
to trigger a DNS resolution. For this purpose, 2 things has to be done:
- clean up the DNS code from the server structure (this was already
quite clean actually) and clean up the server's callbacks from
manipulating too much DNS resolution
- create an agnostic structure which allows linking a DNS resolution
and a requester of any type (using obj_type enum)
3. Manage requesters through queues
Up to now, there was an uniq relationship between a resolution and it's
owner (aka the requester now). It's a shame, because in some cases,
multiple objects may share the same hostname and may benefit from a
resolution being performed by a third party.
This patch introduces the notion of queues, which are basically lists of
either currently running resolution or waiting ones.
The resolutions are now available as a pool, which belongs to the resolvers.
The pool has has a default size of 64 resolutions per resolvers and is
allocated at configuration parsing.
2017-05-22 09:17:15 -04:00
|
|
|
struct dns_requester *dns_requester; /* used to link a server to its DNS resolution */
|
2015-04-13 19:15:08 -04:00
|
|
|
char *resolvers_id; /* resolvers section used by this server */
|
2017-05-03 06:12:02 -04:00
|
|
|
struct dns_resolvers *resolvers; /* pointer to the resolvers structure used by this server */
|
2016-11-02 10:34:05 -04:00
|
|
|
char *lastaddr; /* the address string provided by the server-state file */
|
2016-02-17 15:25:09 -05:00
|
|
|
struct dns_options dns_opts;
|
2018-11-15 11:57:51 -05:00
|
|
|
int hostname_dn_len; /* sting length of the server hostname in Domain Name format */
|
2017-11-26 01:26:48 -05:00
|
|
|
char *hostname_dn; /* server hostname in Domain Name format */
|
|
|
|
|
char *hostname; /* server hostname */
|
2016-11-02 10:05:56 -04:00
|
|
|
struct sockaddr_storage init_addr; /* plain IP address specified on the init-addr line */
|
2016-09-21 14:26:16 -04:00
|
|
|
unsigned int init_addr_methods; /* initial address setting, 3-bit per method, ends at 0, enough to store 10 entries */
|
2015-04-13 19:15:08 -04:00
|
|
|
|
2012-05-18 09:46:21 -04:00
|
|
|
#ifdef USE_OPENSSL
|
2017-03-20 09:54:41 -04:00
|
|
|
char *sni_expr; /* Temporary variable to store a sample expression for SNI */
|
2012-05-18 09:46:21 -04:00
|
|
|
struct {
|
|
|
|
|
SSL_CTX *ctx;
|
2017-11-16 11:42:52 -05:00
|
|
|
struct {
|
|
|
|
|
unsigned char *ptr;
|
|
|
|
|
int size;
|
|
|
|
|
int allocated_size;
|
|
|
|
|
} * reused_sess;
|
2012-09-03 17:34:19 -04:00
|
|
|
char *ciphers; /* cipher suite to use if non-null */
|
2019-05-09 07:26:41 -04:00
|
|
|
#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
|
2018-09-14 05:14:21 -04:00
|
|
|
char *ciphersuites; /* TLS 1.3 cipher suite to use if non-null */
|
|
|
|
|
#endif
|
2012-10-05 07:48:26 -04:00
|
|
|
int options; /* ssl options */
|
2012-10-11 10:11:36 -04:00
|
|
|
int verify; /* verify method (set of SSL_VERIFY_* flags) */
|
2017-11-26 01:26:48 -05:00
|
|
|
struct tls_version_filter methods; /* ssl methods */
|
2013-06-27 03:05:25 -04:00
|
|
|
char *verify_host; /* hostname of certificate must match this host */
|
2012-10-11 10:11:36 -04:00
|
|
|
char *ca_file; /* CAfile to use on verify */
|
|
|
|
|
char *crl_file; /* CRLfile to use on verify */
|
2012-10-26 06:58:00 -04:00
|
|
|
char *client_crt; /* client certificate to send */
|
2015-07-09 05:40:25 -04:00
|
|
|
struct sample_expr *sni; /* sample expression for SNI */
|
2018-11-20 17:33:50 -05:00
|
|
|
#ifdef OPENSSL_NPN_NEGOTIATED
|
|
|
|
|
char *npn_str; /* NPN protocol string */
|
|
|
|
|
int npn_len; /* NPN protocol string length */
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
|
|
|
|
|
char *alpn_str; /* ALPN protocol string */
|
|
|
|
|
int alpn_len; /* ALPN protocol string length */
|
|
|
|
|
#endif
|
2012-05-18 09:46:21 -04:00
|
|
|
} ssl_ctx;
|
|
|
|
|
#endif
|
2017-11-26 01:26:48 -05:00
|
|
|
struct dns_srvrq *srvrq; /* Pointer representing the DNS SRV requeest, if any */
|
2019-07-30 05:59:34 -04:00
|
|
|
__decl_hathreads(HA_SPINLOCK_T lock); /* may enclose the proxy's lock, must not be taken under */
|
2009-10-04 14:54:54 -04:00
|
|
|
struct {
|
|
|
|
|
const char *file; /* file where the section appears */
|
2009-10-04 17:04:08 -04:00
|
|
|
struct eb32_node id; /* place in the tree of used IDs */
|
2019-05-17 08:29:15 -04:00
|
|
|
struct ebpt_node name; /* place in the tree of used names */
|
2017-11-26 01:26:48 -05:00
|
|
|
int line; /* line where the section appears */
|
2009-10-04 14:54:54 -04:00
|
|
|
} conf; /* config information */
|
2017-04-13 12:24:23 -04:00
|
|
|
/* Template information used only for server objects which
|
|
|
|
|
* serve as template filled at parsing time and used during
|
|
|
|
|
* server allocations from server templates.
|
|
|
|
|
*/
|
|
|
|
|
struct {
|
|
|
|
|
char *prefix;
|
|
|
|
|
int nb_low;
|
|
|
|
|
int nb_high;
|
|
|
|
|
} tmpl_info;
|
2017-10-19 08:42:30 -04:00
|
|
|
struct {
|
|
|
|
|
long duration;
|
2017-11-26 01:26:48 -05:00
|
|
|
short status, code;
|
|
|
|
|
char reason[128];
|
2017-10-19 08:42:30 -04:00
|
|
|
} op_st_chg; /* operational status change's reason */
|
2018-11-15 11:57:51 -05:00
|
|
|
char adm_st_chg_cause[48]; /* administrative status change's cause */
|
2019-05-22 07:44:48 -04:00
|
|
|
|
|
|
|
|
struct sockaddr_storage socks4_addr; /* the address of the SOCKS4 Proxy, including the port */
|
2006-06-25 20:48:02 -04:00
|
|
|
};
|
|
|
|
|
|
2019-06-13 07:24:29 -04:00
|
|
|
|
|
|
|
|
/* Storage structure to load server-state lines from a flat file into
|
|
|
|
|
* an ebtree, for faster processing
|
|
|
|
|
*/
|
|
|
|
|
struct state_line {
|
|
|
|
|
char *line;
|
|
|
|
|
struct ebmb_node name_name;
|
|
|
|
|
/* WARNING don't put anything after name_name, it's used by the key */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2012-10-10 02:27:36 -04:00
|
|
|
/* Descriptor for a "server" keyword. The ->parse() function returns 0 in case of
|
|
|
|
|
* success, or a combination of ERR_* flags if an error is encountered. The
|
|
|
|
|
* function pointer can be NULL if not implemented. The function also has an
|
|
|
|
|
* access to the current "server" config line. The ->skip value tells the parser
|
|
|
|
|
* how many words have to be skipped after the keyword. If the function needs to
|
|
|
|
|
* parse more keywords, it needs to update cur_arg.
|
|
|
|
|
*/
|
|
|
|
|
struct srv_kw {
|
|
|
|
|
const char *kw;
|
|
|
|
|
int (*parse)(char **args, int *cur_arg, struct proxy *px, struct server *srv, char **err);
|
|
|
|
|
int skip; /* nb min of args to skip, for use when kw is not handled */
|
|
|
|
|
int default_ok; /* non-zero if kw is supported in default-server section */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A keyword list. It is a NULL-terminated array of keywords. It embeds a
|
|
|
|
|
* struct list in order to be linked to other lists, allowing it to easily
|
|
|
|
|
* be declared where it is needed, and linked without duplicating data nor
|
|
|
|
|
* allocating memory. It is also possible to indicate a scope for the keywords.
|
|
|
|
|
*/
|
|
|
|
|
struct srv_kw_list {
|
|
|
|
|
const char *scope;
|
|
|
|
|
struct list list;
|
|
|
|
|
struct srv_kw kw[VAR_ARRAY];
|
|
|
|
|
};
|
2006-06-25 20:48:02 -04:00
|
|
|
|
|
|
|
|
#endif /* _TYPES_SERVER_H */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|