[MINOR] move the load balancing algorithm to be->lbprm.algo
The number of possible options for a proxy has already reached
32, which is the current limit due to the fact that they are
each represented as a bit in a 32-bit word.
It's possible to move the load balancing algorithms to another
place. It will also save some space for future algorithms.
diff --git a/src/backend.c b/src/backend.c
index 9b0f0aa..91027e8 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -85,7 +85,7 @@
if (srv->state & SRV_BACKUP) {
if (!px->srv_bck &&
- !(px->options & PR_O_USE_ALL_BK))
+ !(px->lbprm.algo & PR_O_USE_ALL_BK))
px->lbprm.fbck = srv;
px->srv_bck++;
px->lbprm.tot_wbck += srv->eweight;
@@ -884,7 +884,7 @@
return SRV_STATUS_INTERNAL;
if (!(s->flags & SN_ASSIGNED)) {
- if (s->be->options & PR_O_BALANCE) {
+ if (s->be->lbprm.algo & BE_LB_ALGO) {
int len;
if (s->flags & SN_DIRECT) {
@@ -895,13 +895,13 @@
if (!s->be->lbprm.tot_weight)
return SRV_STATUS_NOSRV;
- switch (s->be->options & PR_O_BALANCE) {
- case PR_O_BALANCE_RR:
+ switch (s->be->lbprm.algo & BE_LB_ALGO) {
+ case BE_LB_ALGO_RR:
s->srv = fwrr_get_next_server(s->be);
if (!s->srv)
return SRV_STATUS_FULL;
break;
- case PR_O_BALANCE_SH:
+ case BE_LB_ALGO_SH:
if (s->cli_addr.ss_family == AF_INET)
len = 4;
else if (s->cli_addr.ss_family == AF_INET6)
@@ -913,13 +913,13 @@
(void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr,
len);
break;
- case PR_O_BALANCE_UH:
+ case BE_LB_ALGO_UH:
/* URI hashing */
s->srv = get_server_uh(s->be,
s->txn.req.sol + s->txn.req.sl.rq.u,
s->txn.req.sl.rq.u_l);
break;
- case PR_O_BALANCE_PH:
+ case BE_LB_ALGO_PH:
/* URL Parameter hashing */
s->srv = get_server_ph(s->be,
s->txn.req.sol + s->txn.req.sl.rq.u,
@@ -965,7 +965,7 @@
fprintf(stderr,"assign_server_address : s=%p\n",s);
#endif
- if ((s->flags & SN_DIRECT) || (s->be->options & PR_O_BALANCE)) {
+ if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_ALGO)) {
/* A server is necessarily known for this session */
if (!(s->flags & SN_ASSIGNED))
return SRV_STATUS_INTERNAL;
@@ -1478,30 +1478,30 @@
{
if (!*(args[0])) {
/* if no option is set, use round-robin by default */
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_RR;
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_RR;
return 0;
}
if (!strcmp(args[0], "roundrobin")) {
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_RR;
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_RR;
}
else if (!strcmp(args[0], "source")) {
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_SH;
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_SH;
}
else if (!strcmp(args[0], "uri")) {
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_UH;
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_UH;
}
else if (!strcmp(args[0], "url_param")) {
if (!*args[1]) {
snprintf(err, errlen, "'balance url_param' requires an URL parameter name.");
return -1;
}
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_PH;
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_PH;
if (curproxy->url_param_name)
free(curproxy->url_param_name);
curproxy->url_param_name = strdup(args[1]);
diff --git a/src/cfgparse.c b/src/cfgparse.c
index d9b2ce6..4753012 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -588,6 +588,7 @@
/* set default values */
curproxy->state = defproxy.state;
curproxy->options = defproxy.options;
+ curproxy->lbprm.algo = defproxy.lbprm.algo;
curproxy->except_net = defproxy.except_net;
curproxy->except_mask = defproxy.except_mask;
@@ -2472,14 +2473,15 @@
}
else if (curproxy->cap & PR_CAP_BE &&
((curproxy->mode != PR_MODE_HEALTH) &&
- !(curproxy->options & (PR_O_TRANSP | PR_O_BALANCE)) &&
+ !(curproxy->options & PR_O_TRANSP) &&
+ !(curproxy->lbprm.algo & BE_LB_ALGO) &&
(*(int *)&curproxy->dispatch_addr.sin_addr == 0))) {
Alert("parsing %s : %s '%s' has no dispatch address and is not in transparent or balance mode.\n",
file, proxy_type_str(curproxy), curproxy->id);
cfgerr++;
}
- if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->options & PR_O_BALANCE)) {
+ if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->lbprm.algo & BE_LB_ALGO)) {
if (curproxy->options & PR_O_TRANSP) {
Alert("parsing %s : %s '%s' cannot use both transparent and balance mode.\n",
file, proxy_type_str(curproxy), curproxy->id);
@@ -2515,9 +2517,9 @@
Warning("parsing %s : monitor-uri will be ignored for %s '%s'.\n",
file, proxy_type_str(curproxy), curproxy->id);
}
- if (curproxy->options & PR_O_BALANCE_L7) {
- curproxy->options &= ~PR_O_BALANCE;
- curproxy->options |= PR_O_BALANCE_RR;
+ if (curproxy->lbprm.algo & BE_LB_ALGO_L7) {
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Warning("parsing %s : Layer 7 hash not possible for %s '%s'. Falling back to round robin.\n",
file, proxy_type_str(curproxy), curproxy->id);
@@ -2658,7 +2660,7 @@
curproxy->lbprm.wdiv = 1; /* default weight divider */
/* round robin relies on a weight tree */
- if ((curproxy->options & PR_O_BALANCE) == PR_O_BALANCE_RR)
+ if ((curproxy->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_RR)
fwrr_init_server_groups(curproxy);
else
init_server_map(curproxy);