]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] group PR_O_BALANCE_* bits into a checkable value
authorWilly Tarreau <w@1wt.eu>
Thu, 1 Nov 2007 20:08:19 +0000 (21:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Nov 2007 22:01:49 +0000 (23:01 +0100)
In preparation for newer balance algorithms, group the
sparse PR_O_BALANCE_* values into layer4 and layer7-based
algorithms. This will ease addition of newer algorithms.

include/types/backend.h
src/backend.c
src/cfgparse.c

index 921eaed89ed451149f49c6496ddb9fb9c408b720..3c5273b09aaa869e1690fefc7092e1cf13656d1b 100644 (file)
@@ -2,7 +2,7 @@
   include/types/backend.h
   This file rassembles definitions for backends
 
-  Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2007 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
@@ -32,7 +32,7 @@
 #define PR_O_COOK_INS   0x00000010      /* insert cookies when not accessing a server directly */
 #define PR_O_COOK_PFX   0x00000020      /* rewrite all cookies by prefixing the right serverid */
 #define PR_O_COOK_ANY   (PR_O_COOK_RW | PR_O_COOK_IND | PR_O_COOK_INS | PR_O_COOK_PFX)
-#define PR_O_BALANCE_RR 0x00000040      /* balance in round-robin mode */
+#define PR_O_SMTP_CHK   0x00000040      /* use SMTP EHLO check for server health - pvandijk@vision6.com.au */
 #define        PR_O_KEEPALIVE  0x00000080      /* follow keep-alive sessions */
 #define        PR_O_FWDFOR     0x00000100      /* insert x-forwarded-for with client address */
 #define        PR_O_BIND_SRC   0x00000200      /* bind to a specific source address when connect()ing */
 #define PR_O_TCP_SRV_KA 0x00080000      /* enable TCP keep-alive on server-side sessions */
 #define PR_O_USE_ALL_BK 0x00100000      /* load-balance between backup servers */
 #define PR_O_FORCE_CLO  0x00200000      /* enforce the connection close immediately after server response */
-#define PR_O_BALANCE_SH 0x00400000      /* balance on source IP hash */
+#define PR_O_TCP_NOLING 0x00400000      /* disable lingering on client and server connections */
 #define PR_O_ABRT_CLOSE 0x00800000      /* immediately abort request when client closes */
 #define PR_O_SSL3_CHK   0x01000000      /* use SSLv3 CLIENT_HELLO packets for server health */
 
+/* TPXY: exclusive values */
 #define        PR_O_TPXY_ADDR  0x02000000      /* bind to this non-local address when connect()ing */
 #define        PR_O_TPXY_CIP   0x04000000      /* bind to the client's IP address when connect()ing */
 #define        PR_O_TPXY_CLI   0x06000000      /* bind to the client's IP+port when connect()ing */
 #define        PR_O_TPXY_MASK  0x06000000      /* bind to a non-local address when connect()ing */
 #define        PR_O_TCPSPLICE  0x08000000      /* delegate data transfer to linux kernel's tcp_splice */
-#define PR_O_BALANCE_UH 0x10000000      /* balance on URI hash */
-#define PR_O_BALANCE    (PR_O_BALANCE_RR | PR_O_BALANCE_SH | PR_O_BALANCE_UH)
-#define PR_O_SMTP_CHK   0x20000000      /* use SMTP EHLO check for server health - pvandijk@vision6.com.au */
-#define PR_O_TCP_NOLING 0x40000000      /* disable lingering on client and server connections */
+
+/* BALANCE: exclusive values */
+#define PR_O_BALANCE_RR 0x10000000      /* balance in round-robin mode */
+#define PR_O_BALANCE_SH 0x20000000      /* balance on source IP hash */
+#define PR_O_BALANCE_L4 0x30000000      /* mask to match layer4-based algorithms */
+#define PR_O_BALANCE_UH 0x40000000      /* balance on URI hash */
+#define PR_O_BALANCE_L7 0x40000000      /* mask to match layer7-based algorithms */
+#define PR_O_BALANCE    0x70000000      /* mask to extract BALANCE algorithm */
 
 
 #endif /* _TYPES_BACKEND_H */
index faf5db89a9cee80ab033dc50d8ae64a33c3b050e..758b42967c5e51c581cfaca7f6d4c8c686166eb7 100644 (file)
@@ -164,21 +164,23 @@ int assign_server(struct session *s)
 
        if (!(s->flags & SN_ASSIGNED)) {
                if (s->be->options & PR_O_BALANCE) {
+                       int len;
+               
                        if (s->flags & SN_DIRECT) {
                                s->flags |= SN_ASSIGNED;
                                return SRV_STATUS_OK;
                        }
+
                        if (!s->be->srv_act && !s->be->srv_bck)
                                return SRV_STATUS_NOSRV;
 
-                       if (s->be->options & PR_O_BALANCE_RR) {
+                       switch (s->be->options & PR_O_BALANCE) {
+                       case PR_O_BALANCE_RR:
                                s->srv = get_server_rr_with_conns(s->be);
                                if (!s->srv)
                                        return SRV_STATUS_FULL;
-                       }
-                       else if (s->be->options & PR_O_BALANCE_SH) {
-                               int len;
-               
+                               break;
+                       case PR_O_BALANCE_SH:
                                if (s->cli_addr.ss_family == AF_INET)
                                        len = 4;
                                else if (s->cli_addr.ss_family == AF_INET6)
@@ -189,15 +191,17 @@ int assign_server(struct session *s)
                                s->srv = get_server_sh(s->be,
                                                       (void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr,
                                                       len);
-                       }
-                       else if (s->be->options & PR_O_BALANCE_UH) {
+                               break;
+                       case PR_O_BALANCE_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);
-                       }
-                       else /* unknown balancing algorithm */
+                               break;
+                       default:
+                               /* unknown balancing algorithm */
                                return SRV_STATUS_INTERNAL;
+                       }
                }
                else if (!*(int *)&s->be->dispatch_addr.sin_addr &&
                         !(s->fe->options & PR_O_TRANSP)) {
index e347cff8fbdfce70ba98d3297d749e58e71673f9..8e390d56381199e32c90ff2bb79133870e702836 100644 (file)
@@ -2513,11 +2513,11 @@ int readcfgfile(const char *file)
                                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_UH) {
+                       if (curproxy->options & PR_O_BALANCE_L7) {
                                curproxy->options &= ~PR_O_BALANCE;
                                curproxy->options |= PR_O_BALANCE_RR;
 
-                               Warning("parsing %s : URI hash will be ignored for %s '%s'. Falling back to round robin.\n",
+                               Warning("parsing %s : Layer 7 hash not possible for %s '%s'. Falling back to round robin.\n",
                                        file, proxy_type_str(curproxy), curproxy->id);
                        }
                }