&val, labels, &out, max))
goto full;
next_sv:
- sv = watcher_next(&ctx->srv_watch, sv->next);
+ sv = watcher_next(&ctx->srv_watch, proxy_next_server(sv));
}
next_px:
px = watcher_next(&ctx->px_watch, main_proxies_next(px));
if (px) {
/* Update ctx.p[1] via watcher. */
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
sv = ctx->p[1];
}
}
px = main_proxies_first();
watcher_attach(&ctx->px_watch, px);
if (likely(px)) {
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
sv = ctx->p[1];
}
}
goto full;
next_sv2:
- sv = watcher_next(&ctx->srv_watch, sv->next);
+ sv = watcher_next(&ctx->srv_watch, proxy_next_server(sv));
}
next_px2:
px = watcher_next(&ctx->px_watch, main_proxies_next(px));
if (px) {
/* Update ctx.p[1] via watcher. */
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
sv = ctx->p[1];
}
}
px = main_proxies_first();
watcher_attach(&ctx->px_watch, px);
if (likely(px)) {
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
sv = ctx->p[1];
}
}
watcher_attach(&ctx->px_watch, px);
if (likely(px)) {
/* Update ctx.p[1] via watcher. */
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
}
}
__fallthrough;
return LIST_ELEM(px->el.n, struct proxy *, el);
}
+static inline struct server *proxy_first_server(const struct proxy *px)
+{
+ return px->srv;
+}
+
+static inline struct server *proxy_next_server(const struct server *srv)
+{
+ return srv->next;
+}
+
#endif /* _HAPROXY_PROXY_H */
/*
}
else if (strcmp(args[0], "peer") == 0 ||
strcmp(args[0], "server") == 0) { /* peer or server definition */
- struct server *prev_srv;
+ struct server *srv, *prev_srv;
int local_peer, peer;
int parse_addr = 0;
* or if we are parsing a "server" line and the current peer is not the local one.
*/
parse_addr = (peer || !local_peer) ? SRV_PARSE_PARSE_ADDR : 0;
- prev_srv = curpeers->peers_fe->srv;
+ prev_srv = proxy_first_server(curpeers->peers_fe);
err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL,
SRV_PARSE_IN_PEER_SECTION|parse_addr|SRV_PARSE_INITIAL_RESOLVE);
- if (curpeers->peers_fe->srv == prev_srv) {
+ if (prev_srv == proxy_first_server(curpeers->peers_fe)) {
/* parse_server didn't add a server:
* Remove the newly allocated peer.
*/
goto out;
}
+ srv = proxy_first_server(curpeers->peers_fe);
+
if (!parse_addr && bind_addr) {
/* local peer declared using "server": has name but no
* address: we use the known "bind" line addr settings
* as implicit server's addr and port.
*/
- curpeers->peers_fe->srv->addr = *bind_addr;
- curpeers->peers_fe->srv->svc_port = get_host_port(bind_addr);
+ srv->addr = *bind_addr;
+ srv->svc_port = get_host_port(bind_addr);
}
- if (nb_shards && curpeers->peers_fe->srv->shard > nb_shards) {
+ if (nb_shards && srv->shard > nb_shards) {
ha_warning("parsing [%s:%d] : '%s %s' : %d peer shard greater value than %d shards value is ignored.\n",
- file, linenum, args[0], args[1], curpeers->peers_fe->srv->shard, nb_shards);
- curpeers->peers_fe->srv->shard = 0;
+ file, linenum, args[0], args[1], srv->shard, nb_shards);
+ srv->shard = 0;
err_code |= ERR_WARN;
}
- if (curpeers->peers_fe->srv->init_addr_methods || curpeers->peers_fe->srv->resolvers_id ||
- curpeers->peers_fe->srv->do_check || curpeers->peers_fe->srv->do_agent) {
+ if (srv->init_addr_methods || srv->resolvers_id ||
+ srv->do_check || srv->do_agent) {
ha_warning("parsing [%s:%d] : '%s %s' : init_addr, resolvers, check and agent are ignored for peers.\n", file, linenum, args[0], args[1]);
err_code |= ERR_WARN;
}
HA_SPIN_INIT(&newpeer->lock);
- newpeer->srv = curpeers->peers_fe->srv;
+ newpeer->srv = srv;
if (!newpeer->local)
goto out;
if (ctx->px) {
/* First iteration, initialize list on the first server */
- cur = ctx->px->srv;
+ cur = proxy_first_server(ctx->px);
watcher_attach(&ctx->srv_watch, cur);
ctx->px = NULL;
}
}
/* compute next server */
- ctx->next = watcher_next(&ctx->srv_watch, cur->next);
+ ctx->next = watcher_next(&ctx->srv_watch, proxy_next_server(cur));
lua_pushstring(L, cur->id);
hlua_fcn_new_server(L, cur);
*/
if ((att_end - att_beg == s->be->cookie_len) && (s->be->cookie_name != NULL) &&
(memcmp(att_beg, s->be->cookie_name, att_end - att_beg) == 0)) {
- struct server *srv = s->be->srv;
+ struct server *srv = proxy_first_server(s->be);
char *delim;
/* if we're in cookie prefix mode, we'll search the delimiter so that we
if ((delim == val_beg) || (s->flags & (SF_IGNORE_PRST | SF_ASSIGNED)))
srv = NULL;
- while (srv) {
+ for (; srv; srv = proxy_next_server(srv)) {
if (srv->cookie && (srv->cklen == delim - val_beg) &&
!memcmp(val_beg, srv->cookie, delim - val_beg)) {
if ((srv->cur_state != SRV_ST_STOPPED) ||
txn->flags |= TX_CK_DOWN;
}
}
- srv = srv->next;
}
if (!srv && !(txn->flags & (TX_CK_DOWN|TX_CK_EXPIRED|TX_CK_OLD))) {
#include <haproxy/backend.h>
#include <haproxy/errors.h>
#include <haproxy/guid.h>
+#include <haproxy/proxy.h>
#include <haproxy/queue.h>
#include <haproxy/server.h>
#include <haproxy/tools.h>
*/
struct server *srv2 = p->lbprm.fbck;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 &&
!((srv2->flags & SRV_F_BACKUP) &&
srv_willbe_usable(srv2)));
*/
struct server *srv2 = srv;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 && (srv2 != p->lbprm.fbck));
if (srv2)
p->lbprm.fbck = srv;
#include <import/eb32tree.h>
#include <haproxy/api.h>
#include <haproxy/backend.h>
+#include <haproxy/proxy.h>
#include <haproxy/queue.h>
#include <haproxy/server-t.h>
*/
struct server *srv2 = p->lbprm.fbck;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 &&
!((srv2->flags & SRV_F_BACKUP) &&
srv_willbe_usable(srv2)));
*/
struct server *srv2 = srv;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 && (srv2 != p->lbprm.fbck));
if (srv2)
p->lbprm.fbck = srv;
#include <import/eb32tree.h>
#include <haproxy/api.h>
#include <haproxy/backend.h>
+#include <haproxy/proxy.h>
#include <haproxy/queue.h>
#include <haproxy/server-t.h>
#include <haproxy/task.h>
*/
struct server *srv2 = p->lbprm.fbck;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 &&
!((srv2->flags & SRV_F_BACKUP) &&
srv_willbe_usable(srv2)));
*/
struct server *srv2 = srv;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 && (srv2 != p->lbprm.fbck));
if (srv2)
p->lbprm.fbck = srv;
#include <haproxy/queue.h>
#include <haproxy/server-t.h>
#include <haproxy/global.h>
+#include <haproxy/proxy.h>
static inline void fwrr_remove_from_tree(struct server *s, int tgid);
*/
struct server *srv2 = p->lbprm.fbck;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 &&
!((srv2->flags & SRV_F_BACKUP) &&
srv_willbe_usable(srv2)));
*/
struct server *srv2 = srv;
do {
- srv2 = srv2->next;
+ srv2 = proxy_next_server(srv2);
} while (srv2 && (srv2 != p->lbprm.fbck));
if (srv2)
p->lbprm.fbck = srv;
srv, i + 1);
}
j = 0;
- for (srv = p->srv; srv && j < i; srv = srv->next) {
+ for (srv = proxy_first_server(p); srv && j < i; srv = proxy_next_server(srv)) {
j++;
if (!srv_currently_usable(srv))
continue;
#include <haproxy/api.h>
#include <haproxy/backend.h>
#include <haproxy/lb_map.h>
+#include <haproxy/proxy.h>
#include <haproxy/queue.h>
#include <haproxy/server-t.h>
* find a non-zero weight server.
*/
pgcd = 1;
- srv = p->srv;
+ srv = proxy_first_server(p);
while (srv && !srv->uweight)
- srv = srv->next;
+ srv = proxy_next_server(srv);
if (srv) {
pgcd = srv->uweight; /* note: cannot be zero */
- while (pgcd > 1 && (srv = srv->next)) {
+ while (pgcd > 1 && (srv = proxy_next_server(srv))) {
int w = srv->uweight;
while (w) {
int t = pgcd % w;
char *srvrecord;
if (!ctx->sv)
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
- for (; ctx->sv; watcher_next(&ctx->srv_watch, ctx->sv->next)) {
+ for (; ctx->sv; watcher_next(&ctx->srv_watch, proxy_next_server(ctx->sv))) {
srv = ctx->sv;
dump_server_addr(&srv->addr, srv_addr);
goto out;
}
- if (dns_stream_init(newnameserver, curr_resolvers->px->srv) < 0) {
+ if (dns_stream_init(newnameserver, proxy_first_server(curr_resolvers->px)) < 0) {
ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
err_code |= ERR_ALERT|ERR_ABORT;
free(newnameserver);
static int cli_parse_delete_server(char **args, char *payload, struct appctx *appctx, void *private)
{
struct proxy *be;
- struct server *srv;
+ struct server *srv, *next;
struct ist be_name, sv_name;
struct watcher *srv_watch;
const char *msg;
if (srv->proxy->lbprm.ops && srv->proxy->lbprm.ops->server_deinit)
srv->proxy->lbprm.ops->server_deinit(srv);
+ next = proxy_next_server(srv);
+ BUG_ON(next && next->flags & SRV_F_DELETED);
while (!MT_LIST_ISEMPTY(&srv->watcher_list)) {
srv_watch = MT_LIST_NEXT(&srv->watcher_list, struct watcher *, el);
- BUG_ON(srv->next && srv->next->flags & SRV_F_DELETED);
- watcher_next(srv_watch, srv->next);
+ watcher_next(srv_watch, next);
}
/* detach the server from the proxy linked list
}
/* for servers ctx.obj2 is set via watcher_attach() */
- watcher_attach(&ctx->srv_watch, px->srv);
+ watcher_attach(&ctx->srv_watch, proxy_first_server(px));
ctx->px_st = STAT_PX_ST_SV;
__fallthrough;
case STAT_PX_ST_SV:
/* obj2 is updated and returned through watcher_next() */
for (sv = ctx->obj2; sv;
- sv = watcher_next(&ctx->srv_watch, sv->next)) {
+ sv = watcher_next(&ctx->srv_watch, proxy_next_server(sv))) {
if (stats_is_full(appctx, buf, htx))
goto full;