2006-06-15 15:48:13 -04:00
|
|
|
/*
|
2020-06-04 17:20:13 -04:00
|
|
|
* include/haproxy/server.h
|
2009-10-04 17:12:44 -04:00
|
|
|
* This file defines everything related to servers.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2006-06-15 15:48:13 -04:00
|
|
|
|
2020-06-04 17:20:13 -04:00
|
|
|
#ifndef _HAPROXY_SERVER_H
|
|
|
|
|
#define _HAPROXY_SERVER_H
|
2006-06-25 20:48:02 -04:00
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2020-05-27 06:58:42 -04:00
|
|
|
#include <haproxy/api.h>
|
2020-06-09 03:07:15 -04:00
|
|
|
#include <haproxy/applet-t.h>
|
2020-06-04 17:20:13 -04:00
|
|
|
#include <haproxy/freq_ctr.h>
|
2020-06-04 16:29:18 -04:00
|
|
|
#include <haproxy/proxy-t.h>
|
2021-02-12 13:42:55 -05:00
|
|
|
#include <haproxy/resolvers-t.h>
|
2020-06-04 17:20:13 -04:00
|
|
|
#include <haproxy/server-t.h>
|
2020-06-04 16:01:04 -04:00
|
|
|
#include <haproxy/task.h>
|
2020-06-04 17:20:13 -04:00
|
|
|
#include <haproxy/thread-t.h>
|
2020-06-01 05:05:15 -04:00
|
|
|
#include <haproxy/time.h>
|
2006-06-15 15:48:13 -04:00
|
|
|
|
2019-02-14 12:29:09 -05:00
|
|
|
|
2020-06-05 02:40:51 -04:00
|
|
|
__decl_thread(extern HA_SPINLOCK_T idle_conn_srv_lock);
|
2021-01-11 03:21:52 -05:00
|
|
|
extern struct idle_conns idle_conns[MAX_THREADS];
|
2019-02-14 12:29:09 -05:00
|
|
|
extern struct task *idle_conn_task;
|
2021-03-05 04:23:32 -05:00
|
|
|
extern struct list servers_list;
|
2020-11-20 03:28:26 -05:00
|
|
|
extern struct dict server_key_dict;
|
2019-02-14 12:29:09 -05:00
|
|
|
|
2013-11-01 03:46:15 -04:00
|
|
|
int srv_downtime(const struct server *s);
|
2014-02-03 16:26:46 -05:00
|
|
|
int srv_lastsession(const struct server *s);
|
2013-02-23 01:35:38 -05:00
|
|
|
int srv_getinter(const struct check *check);
|
2021-03-08 10:36:46 -05:00
|
|
|
int parse_server(const char *file, int linenum, char **args, struct proxy *curproxy, const struct proxy *defproxy, int parse_flags);
|
2021-02-16 06:07:47 -05:00
|
|
|
int srv_update_addr(struct server *s, void *ip, int ip_sin_family, const char *updater);
|
|
|
|
|
const char *srv_update_addr_port(struct server *s, const char *addr, const char *port, char *updater);
|
|
|
|
|
const char *srv_update_check_addr_port(struct server *s, const char *addr, const char *port);
|
|
|
|
|
const char *srv_update_agent_addr_port(struct server *s, const char *addr, const char *port);
|
2015-07-08 16:03:56 -04:00
|
|
|
struct server *server_find_by_id(struct proxy *bk, int id);
|
|
|
|
|
struct server *server_find_by_name(struct proxy *bk, const char *name);
|
|
|
|
|
struct server *server_find_best_match(struct proxy *bk, char *name, int id, int *diff);
|
2015-08-19 10:44:03 -04:00
|
|
|
void apply_server_state(void);
|
BUG/MEDIUM: servers: properly propagate the maintenance states during startup
Right now there is an issue with the way the maintenance flags are
propagated upon startup. They are not propagate, just copied from the
tracked server. This implies that depending on the server's order, some
tracking servers may not be marked down. For example this configuration
does not work as expected :
server s1 1.1.1.1:8000 track s2
server s2 1.1.1.1:8000 track s3
server s3 1.1.1.1:8000 track s4
server s4 wtap:8000 check inter 1s disabled
It results in s1/s2 being up, and s3/s4 being down, while all of them
should be down.
The only clean way to process this is to run through all "root" servers
(those not tracking any other server), and to propagate their state down
to all their trackers. This is the same algorithm used to propagate the
state changes. It has to be done both to compute the IDRAIN flag and the
IMAINT flag. However, doing so requires that tracking servers are not
marked as inherited maintenance anymore while parsing the configuration
(and given that it is wrong, better drop it).
This fix also addresses another side effect of the bug above which is
that the IDRAIN/IMAINT flags are stored in the state files, and if
restored while the tracked server doesn't have the equivalent flag,
the servers may end up in a situation where it's impossible to remove
these flags. For example in the configuration above, after removing
"disabled" on server s4, the other servers would have remained down,
and not anymore with this fix. Similarly, the combination of IMAINT
or IDRAIN with their respective forced modes was not accepted on
reload, which is wrong as well.
This bug has been present at least since 1.5, maybe even 1.4 (it came
with tracking support). The fix needs to be backported there, though
the srv-state parts are irrelevant.
This commit relies on previous patch to silence warnings on startup.
2016-11-03 14:22:19 -04:00
|
|
|
void srv_compute_all_admin_states(struct proxy *px);
|
2016-11-02 10:34:05 -04:00
|
|
|
int srv_set_addr_via_libc(struct server *srv, int *err_code);
|
|
|
|
|
int srv_init_addr(void);
|
2016-11-23 11:15:08 -05:00
|
|
|
struct server *cli_find_server(struct appctx *appctx, char *arg);
|
2018-10-26 08:47:32 -04:00
|
|
|
struct server *new_server(struct proxy *proxy);
|
2021-08-25 09:34:53 -04:00
|
|
|
void srv_take(struct server *srv);
|
|
|
|
|
struct server *srv_drop(struct server *srv);
|
2021-06-15 09:33:20 -04:00
|
|
|
int srv_init_per_thr(struct server *srv);
|
2021-10-06 05:48:34 -04:00
|
|
|
void srv_set_ssl(struct server *s, int use_ssl);
|
2006-06-25 20:48:02 -04:00
|
|
|
|
2015-04-13 19:15:08 -04:00
|
|
|
/* functions related to server name resolution */
|
2021-02-16 06:07:47 -05:00
|
|
|
int srv_prepare_for_resolution(struct server *srv, const char *hostname);
|
2021-03-11 12:03:21 -05:00
|
|
|
int srvrq_update_srv_status(struct server *s, int has_no_ip);
|
2017-07-06 12:46:47 -04:00
|
|
|
int snr_update_srv_status(struct server *s, int has_no_ip);
|
2021-02-16 06:07:47 -05:00
|
|
|
int srv_set_fqdn(struct server *srv, const char *fqdn, int resolv_locked);
|
|
|
|
|
const char *srv_update_fqdn(struct server *server, const char *fqdn, const char *updater, int dns_locked);
|
2020-12-23 11:41:43 -05:00
|
|
|
int snr_resolution_cb(struct resolv_requester *requester, struct dns_counters *counters);
|
2020-11-19 16:38:33 -05:00
|
|
|
int srvrq_resolution_error_cb(struct resolv_requester *requester, int error_code);
|
2020-12-23 11:41:43 -05:00
|
|
|
int snr_resolution_error_cb(struct resolv_requester *requester, int error_code);
|
2017-05-03 09:43:12 -04:00
|
|
|
struct server *snr_check_ip_callback(struct server *srv, void *ip, unsigned char *ip_family);
|
2021-03-02 10:09:26 -05:00
|
|
|
struct task *srv_cleanup_idle_conns(struct task *task, void *ctx, unsigned int state);
|
2021-10-06 12:30:04 -04:00
|
|
|
void srv_release_conn(struct server *srv, struct connection *conn);
|
|
|
|
|
struct connection *srv_lookup_conn(struct eb_root *tree, uint64_t hash);
|
|
|
|
|
struct connection *srv_lookup_conn_next(struct connection *conn);
|
|
|
|
|
|
|
|
|
|
int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_safe);
|
2021-03-02 10:09:26 -05:00
|
|
|
struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
|
2015-04-13 19:15:08 -04:00
|
|
|
|
2021-07-13 04:35:23 -04:00
|
|
|
int srv_apply_track(struct server *srv, struct proxy *curproxy);
|
|
|
|
|
|
2012-10-10 02:27:36 -04:00
|
|
|
/*
|
|
|
|
|
* Registers the server keyword list <kwl> as a list of valid keywords for next
|
|
|
|
|
* parsing sessions.
|
|
|
|
|
*/
|
|
|
|
|
void srv_register_keywords(struct srv_kw_list *kwl);
|
|
|
|
|
|
|
|
|
|
/* Return a pointer to the server keyword <kw>, or NULL if not found. */
|
|
|
|
|
struct srv_kw *srv_find_kw(const char *kw);
|
|
|
|
|
|
|
|
|
|
/* Dumps all registered "server" keywords to the <out> string pointer. */
|
|
|
|
|
void srv_dump_kws(char **out);
|
|
|
|
|
|
2013-11-21 05:22:01 -05:00
|
|
|
/* Recomputes the server's eweight based on its state, uweight, the current time,
|
2020-03-10 03:06:11 -04:00
|
|
|
* and the proxy's algorithm. To be used after updating sv->uweight. The warmup
|
2013-11-21 05:22:01 -05:00
|
|
|
* state is automatically disabled if the time is elapsed.
|
|
|
|
|
*/
|
2018-08-02 05:48:52 -04:00
|
|
|
void server_recalc_eweight(struct server *sv, int must_update);
|
2013-11-21 05:22:01 -05:00
|
|
|
|
2013-02-11 20:45:51 -05:00
|
|
|
/*
|
|
|
|
|
* Parses weight_str and configures sv accordingly.
|
|
|
|
|
* Returns NULL on success, error message string otherwise.
|
|
|
|
|
*/
|
|
|
|
|
const char *server_parse_weight_change_request(struct server *sv,
|
|
|
|
|
const char *weight_str);
|
|
|
|
|
|
2015-04-13 16:54:33 -04:00
|
|
|
/*
|
2016-02-24 02:25:39 -05:00
|
|
|
* Parses addr_str and configures sv accordingly. updater precise
|
|
|
|
|
* the source of the change in the associated message log.
|
2015-04-13 16:54:33 -04:00
|
|
|
* Returns NULL on success, error message string otherwise.
|
|
|
|
|
*/
|
|
|
|
|
const char *server_parse_addr_change_request(struct server *sv,
|
2016-02-24 02:25:39 -05:00
|
|
|
const char *addr_str, const char *updater);
|
2015-04-13 16:54:33 -04:00
|
|
|
|
2016-04-24 17:10:06 -04:00
|
|
|
/*
|
|
|
|
|
* Parses maxconn_str and configures sv accordingly.
|
|
|
|
|
* Returns NULL on success, error message string otherwise.
|
|
|
|
|
*/
|
|
|
|
|
const char *server_parse_maxconn_change_request(struct server *sv,
|
|
|
|
|
const char *maxconn_str);
|
|
|
|
|
|
2014-05-16 05:48:10 -04:00
|
|
|
/* Shutdown all connections of a server. The caller must pass a termination
|
2015-04-02 19:14:29 -04:00
|
|
|
* code in <why>, which must be one of SF_ERR_* indicating the reason for the
|
2014-05-16 05:48:10 -04:00
|
|
|
* shutdown.
|
|
|
|
|
*/
|
2016-02-22 10:08:58 -05:00
|
|
|
void srv_shutdown_streams(struct server *srv, int why);
|
2014-05-16 05:48:10 -04:00
|
|
|
|
|
|
|
|
/* Shutdown all connections of all backup servers of a proxy. The caller must
|
2015-04-02 19:14:29 -04:00
|
|
|
* pass a termination code in <why>, which must be one of SF_ERR_* indicating
|
2014-05-16 05:48:10 -04:00
|
|
|
* the reason for the shutdown.
|
|
|
|
|
*/
|
2016-02-22 10:08:58 -05:00
|
|
|
void srv_shutdown_backup_streams(struct proxy *px, int why);
|
2014-05-16 05:48:10 -04:00
|
|
|
|
2018-07-13 05:56:34 -04:00
|
|
|
void srv_append_status(struct buffer *msg, struct server *s, struct check *,
|
|
|
|
|
int xferred, int forced);
|
2017-10-19 08:42:30 -04:00
|
|
|
|
|
|
|
|
void srv_set_stopped(struct server *s, const char *reason, struct check *check);
|
|
|
|
|
void srv_set_running(struct server *s, const char *reason, struct check *check);
|
|
|
|
|
void srv_set_stopping(struct server *s, const char *reason, struct check *check);
|
2014-05-21 07:54:57 -04:00
|
|
|
|
2014-05-22 10:14:34 -04:00
|
|
|
/* Enables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to
|
|
|
|
|
* enforce either maint mode or drain mode. It is not allowed to set more than
|
|
|
|
|
* one flag at once. The equivalent "inherited" flag is propagated to all
|
|
|
|
|
* tracking servers. Maintenance mode disables health checks (but not agent
|
|
|
|
|
* checks). When either the flag is already set or no flag is passed, nothing
|
2016-11-07 09:53:43 -05:00
|
|
|
* is done. If <cause> is non-null, it will be displayed at the end of the log
|
|
|
|
|
* lines to justify the state change.
|
2014-05-22 10:14:34 -04:00
|
|
|
*/
|
2016-11-07 09:53:43 -05:00
|
|
|
void srv_set_admin_flag(struct server *s, enum srv_admin mode, const char *cause);
|
2014-05-22 10:14:34 -04:00
|
|
|
|
|
|
|
|
/* Disables admin flag <mode> (among SRV_ADMF_*) on server <s>. This is used to
|
|
|
|
|
* stop enforcing either maint mode or drain mode. It is not allowed to set more
|
|
|
|
|
* than one flag at once. The equivalent "inherited" flag is propagated to all
|
|
|
|
|
* tracking servers. Leaving maintenance mode re-enables health checks. When
|
|
|
|
|
* either the flag is already cleared or no flag is passed, nothing is done.
|
|
|
|
|
*/
|
|
|
|
|
void srv_clr_admin_flag(struct server *s, enum srv_admin mode);
|
|
|
|
|
|
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
|
|
|
/* Calculates the dynamic persitent cookie for a server, if a secret key has
|
|
|
|
|
* been provided.
|
|
|
|
|
*/
|
|
|
|
|
void srv_set_dyncookie(struct server *s);
|
|
|
|
|
|
2021-10-18 08:39:57 -04:00
|
|
|
int srv_check_reuse_ws(struct server *srv);
|
|
|
|
|
const struct mux_ops *srv_get_ws_proto(struct server *srv);
|
|
|
|
|
|
2020-06-04 17:20:13 -04:00
|
|
|
/* increase the number of cumulated connections on the designated server */
|
|
|
|
|
static inline void srv_inc_sess_ctr(struct server *s)
|
|
|
|
|
{
|
2021-04-06 07:53:36 -04:00
|
|
|
_HA_ATOMIC_INC(&s->counters.cum_sess);
|
2020-06-04 17:20:13 -04:00
|
|
|
HA_ATOMIC_UPDATE_MAX(&s->counters.sps_max,
|
|
|
|
|
update_freq_ctr(&s->sess_per_sec, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the time of last session on the designated server */
|
|
|
|
|
static inline void srv_set_sess_last(struct server *s)
|
|
|
|
|
{
|
|
|
|
|
s->counters.last_sess = now.tv_sec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* returns the current server throttle rate between 0 and 100% */
|
|
|
|
|
static inline unsigned int server_throttle_rate(struct server *sv)
|
|
|
|
|
{
|
|
|
|
|
struct proxy *px = sv->proxy;
|
|
|
|
|
|
|
|
|
|
/* when uweight is 0, we're in soft-stop so that cannot be a slowstart,
|
|
|
|
|
* thus the throttle is 100%.
|
|
|
|
|
*/
|
|
|
|
|
if (!sv->uweight)
|
|
|
|
|
return 100;
|
|
|
|
|
|
|
|
|
|
return (100U * px->lbprm.wmult * sv->cur_eweight + px->lbprm.wdiv - 1) / (px->lbprm.wdiv * sv->uweight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return true if the server has a zero user-weight, meaning it's in draining
|
|
|
|
|
* mode (ie: not taking new non-persistent connections).
|
|
|
|
|
*/
|
|
|
|
|
static inline int server_is_draining(const struct server *s)
|
|
|
|
|
{
|
|
|
|
|
return !s->uweight || (s->cur_admin & SRV_ADMF_DRAIN);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 05:25:16 -04:00
|
|
|
/* Puts server <s> into maintenance mode, and propagate that status down to all
|
2014-05-22 10:14:34 -04:00
|
|
|
* tracking servers.
|
|
|
|
|
*/
|
|
|
|
|
static inline void srv_adm_set_maint(struct server *s)
|
|
|
|
|
{
|
2016-11-07 09:53:43 -05:00
|
|
|
srv_set_admin_flag(s, SRV_ADMF_FMAINT, NULL);
|
2014-05-22 10:14:34 -04:00
|
|
|
srv_clr_admin_flag(s, SRV_ADMF_FDRAIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Puts server <s> into drain mode, and propagate that status down to all
|
|
|
|
|
* tracking servers.
|
|
|
|
|
*/
|
|
|
|
|
static inline void srv_adm_set_drain(struct server *s)
|
|
|
|
|
{
|
2016-11-07 09:53:43 -05:00
|
|
|
srv_set_admin_flag(s, SRV_ADMF_FDRAIN, NULL);
|
2014-05-22 10:14:34 -04:00
|
|
|
srv_clr_admin_flag(s, SRV_ADMF_FMAINT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Puts server <s> into ready mode, and propagate that status down to all
|
|
|
|
|
* tracking servers.
|
|
|
|
|
*/
|
|
|
|
|
static inline void srv_adm_set_ready(struct server *s)
|
|
|
|
|
{
|
|
|
|
|
srv_clr_admin_flag(s, SRV_ADMF_FDRAIN);
|
|
|
|
|
srv_clr_admin_flag(s, SRV_ADMF_FMAINT);
|
|
|
|
|
}
|
2014-05-16 05:25:16 -04:00
|
|
|
|
2016-09-21 14:26:16 -04:00
|
|
|
/* appends an initaddr method to the existing list. Returns 0 on failure. */
|
|
|
|
|
static inline int srv_append_initaddr(unsigned int *list, enum srv_initaddr addr)
|
|
|
|
|
{
|
|
|
|
|
int shift = 0;
|
|
|
|
|
|
|
|
|
|
while (shift + 3 < 32 && (*list >> shift))
|
|
|
|
|
shift += 3;
|
|
|
|
|
|
|
|
|
|
if (shift + 3 > 32)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
*list |= addr << shift;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:10:17 -04:00
|
|
|
/* returns the next initaddr method and removes it from <list> by shifting
|
|
|
|
|
* it right (implying that it MUST NOT be the server's. Returns SRV_IADDR_END
|
|
|
|
|
* at the end.
|
|
|
|
|
*/
|
|
|
|
|
static inline enum srv_initaddr srv_get_next_initaddr(unsigned int *list)
|
|
|
|
|
{
|
|
|
|
|
enum srv_initaddr ret;
|
|
|
|
|
|
|
|
|
|
ret = *list & 7;
|
|
|
|
|
*list >>= 3;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 12:17:04 -04:00
|
|
|
static inline void srv_use_conn(struct server *srv, struct connection *conn)
|
2020-07-02 09:45:56 -04:00
|
|
|
{
|
2021-03-03 12:12:11 -05:00
|
|
|
unsigned int curr;
|
|
|
|
|
|
2021-04-06 05:44:07 -04:00
|
|
|
curr = _HA_ATOMIC_ADD_FETCH(&srv->curr_used_conns, 1);
|
2020-07-02 09:45:56 -04:00
|
|
|
|
|
|
|
|
/* It's ok not to do that atomically, we don't need an
|
|
|
|
|
* exact max.
|
|
|
|
|
*/
|
2021-03-03 12:12:11 -05:00
|
|
|
if (srv->max_used_conns < curr)
|
|
|
|
|
srv->max_used_conns = curr;
|
2020-07-02 09:45:56 -04:00
|
|
|
|
2021-03-03 12:12:11 -05:00
|
|
|
if (srv->est_need_conns < curr)
|
|
|
|
|
srv->est_need_conns = curr;
|
2020-07-02 09:45:56 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-04 17:20:13 -04:00
|
|
|
#endif /* _HAPROXY_SERVER_H */
|
2014-07-28 05:31:57 -04:00
|
|
|
|
2006-06-25 20:48:02 -04:00
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|