blob: 31c191e25459bec883bb56169098e35d30f68279 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau62c3be22012-01-20 13:12:32 +01002 * include/proto/backend.h
3 * Functions prototypes for the backend.
4 *
5 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
22#ifndef _PROTO_BACKEND_H
23#define _PROTO_BACKEND_H
24
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020025#include <common/config.h>
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -050026#include <common/time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
28#include <types/backend.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020029#include <types/proxy.h>
30#include <types/server.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/session.h>
32
Willy Tarreaubaaee002006-06-26 02:48:02 +020033int assign_server(struct session *s);
34int assign_server_address(struct session *s);
35int assign_server_and_queue(struct session *s);
36int connect_server(struct session *s);
Willy Tarreaubaaee002006-06-26 02:48:02 +020037int srv_redispatch_connect(struct session *t);
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +010038const char *backend_lb_algo_str(int algo);
Willy Tarreaua93c74b2012-05-08 18:14:39 +020039int backend_parse_balance(const char **args, char **err, struct proxy *curproxy);
Willy Tarreau7421efb2012-07-02 15:11:27 +020040int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit);
Willy Tarreaubaaee002006-06-26 02:48:02 +020041
Krzysztof Oledzki85130942007-10-22 16:21:10 +020042int be_downtime(struct proxy *px);
Willy Tarreauc5d9c802009-10-01 09:17:05 +020043void recount_servers(struct proxy *px);
44void update_backend_weight(struct proxy *px);
Willy Tarreauca7d4b92009-10-01 09:21:55 +020045struct server *get_server_sh(struct proxy *px, const char *addr, int len);
46struct server *get_server_uh(struct proxy *px, char *uri, int uri_len);
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -050047int be_lastsession(const struct proxy *be);
48
49/* set the time of last session on the backend */
50static void inline be_set_sess_last(struct proxy *be)
51{
52 be->be_counters.last_sess = now.tv_sec;
53}
Willy Tarreauc5d9c802009-10-01 09:17:05 +020054
Willy Tarreau87eb1d62014-05-13 18:51:40 +020055/* This function returns non-zero if the designated server is usable for LB
56 * according to its current weight and current state. Otherwise it returns 0.
Willy Tarreauc5d9c802009-10-01 09:17:05 +020057 */
Willy Tarreau87eb1d62014-05-13 18:51:40 +020058static inline int srv_is_usable(const struct server *srv)
59{
Willy Tarreauc93cd162014-05-13 15:54:22 +020060 enum srv_state state = srv->state;
Willy Tarreau87eb1d62014-05-13 18:51:40 +020061
62 if (!srv->eweight)
63 return 0;
Willy Tarreau20125212014-05-13 19:44:56 +020064 if (srv->admin & SRV_ADMF_MAINT)
65 return 0;
Willy Tarreau892337c2014-05-13 23:41:20 +020066 switch (state) {
67 case SRV_ST_STARTING:
68 case SRV_ST_RUNNING:
69 return 1;
70 case SRV_ST_STOPPING:
71 case SRV_ST_STOPPED:
Willy Tarreau87eb1d62014-05-13 18:51:40 +020072 return 0;
Willy Tarreau892337c2014-05-13 23:41:20 +020073 }
74 return 0;
Willy Tarreau87eb1d62014-05-13 18:51:40 +020075}
76
77/* This function returns non-zero if the designated server was usable for LB
78 * according to its current weight and previous state. Otherwise it returns 0.
79 */
80static inline int srv_was_usable(const struct server *srv)
Willy Tarreauc5d9c802009-10-01 09:17:05 +020081{
Willy Tarreauc93cd162014-05-13 15:54:22 +020082 enum srv_state state = srv->prev_state;
Willy Tarreau87eb1d62014-05-13 18:51:40 +020083
84 if (!srv->prev_eweight)
Willy Tarreauc5d9c802009-10-01 09:17:05 +020085 return 0;
Willy Tarreau20125212014-05-13 19:44:56 +020086 if (srv->prev_admin & SRV_ADMF_MAINT)
87 return 0;
Willy Tarreau892337c2014-05-13 23:41:20 +020088 switch (state) {
89 case SRV_ST_STARTING:
90 case SRV_ST_RUNNING:
91 return 1;
92 case SRV_ST_STOPPING:
93 case SRV_ST_STOPPED:
Willy Tarreauc5d9c802009-10-01 09:17:05 +020094 return 0;
Willy Tarreau892337c2014-05-13 23:41:20 +020095 }
96 return 0;
Willy Tarreauc5d9c802009-10-01 09:17:05 +020097}
Willy Tarreaubaaee002006-06-26 02:48:02 +020098
Willy Tarreauc5150da2014-05-13 19:27:31 +020099/* This function commits the current server state and weight onto the previous
100 * ones in order to detect future changes.
101 */
102static inline void srv_lb_commit_status(struct server *srv)
103{
104 srv->prev_state = srv->state;
Willy Tarreau20125212014-05-13 19:44:56 +0200105 srv->prev_admin = srv->admin;
Willy Tarreauc5150da2014-05-13 19:27:31 +0200106 srv->prev_eweight = srv->eweight;
107}
108
109/* This function returns true when a server has experienced a change since last
110 * commit on its state or weight, otherwise zero.
111 */
112static inline int srv_lb_status_changed(const struct server *srv)
113{
114 return (srv->state != srv->prev_state ||
Willy Tarreau20125212014-05-13 19:44:56 +0200115 srv->admin != srv->prev_admin ||
Willy Tarreauc5150da2014-05-13 19:27:31 +0200116 srv->eweight != srv->prev_eweight);
117}
118
Willy Tarreaubaaee002006-06-26 02:48:02 +0200119#endif /* _PROTO_BACKEND_H */
120
121/*
122 * Local variables:
123 * c-indent-level: 8
124 * c-basic-offset: 8
125 * End:
126 */