]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] acl: add srv_conn acl to count connections on a
authorHervé COMMOWICK <vr@exosec.fr>
Fri, 5 Aug 2011 10:09:44 +0000 (12:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 6 Aug 2011 13:52:27 +0000 (15:52 +0200)
specific backend server

These ACLs are used to check the number of active connections on the specified server in the specified backend.

doc/configuration.txt
include/types/acl.h
src/acl.c
src/backend.c

index cd5f979ebd94689260219113f09710d17a20f8c9..d2f75a7ab3e09447b495109a57c2d883eecc4b09 100644 (file)
@@ -7456,6 +7456,12 @@ src_updt_conn_cnt(table) <integer>
             tcp-request content reject if { src_update_count gt 3 }
             server local 127.0.0.1:22
 
+srv_conn(backend/server) <integer>
+  Applies to the number of currently established connections on the server,
+  possibly including the connection being evaluated.
+  It can be used to use a specific farm when one server is full.
+  See also the "fe_conn", "be_conn" and "queue" criteria.
+
 srv_id <integer>
   Applies to the server's id. Can be used in frontends or backends.
 
index a22b6cccbcb36280507bff62b32a9c9aa88b939c..9afd85c06805ff3ef8e4b04541e91ade7521b1e1 100644 (file)
@@ -308,7 +308,7 @@ struct acl_expr {
        union {                     /* optional argument of the subject (eg: header or cookie name) */
                char *str;
                struct userlist *ul;
-               struct server *srv;
+               struct server *srv; /* must be initialised by acl_find_targets */
        } arg;
        int arg_len;                /* optional argument length */
        struct list patterns;       /* list of acl_patterns */
index 26b82cb35d710e6441195b51ea5bd2e3a7b70fa3..9d9a7466a643024d5406613a2e5ce63cdb98a418 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -1732,7 +1732,8 @@ acl_find_targets(struct proxy *p)
 
        list_for_each_entry(acl, &p->acl, list) {
                list_for_each_entry(expr, &acl->expr, list) {
-                       if (strcmp(expr->kw->kw, "srv_is_up") == 0) {
+                       if (strcmp(expr->kw->kw, "srv_is_up") == 0 ||
+                           strcmp(expr->kw->kw, "srv_conn") == 0) {
                                struct proxy *px;
                                struct server *srv;
                                char *pname, *sname;
index 4b923a7e597bd0f8199771f9e5b4d7676ffd510d..d76324fc5446151b832c27391822adcfb165dad8 100644 (file)
@@ -1551,6 +1551,17 @@ acl_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, int dir
        return 1;
 }
 
+/* set test->i to the number of concurrent connections on the server in the backend */
+static int
+acl_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, int dir,
+                 struct acl_expr *expr, struct acl_test *test)
+{
+       struct server *srv = expr->arg.srv;
+
+       test->i = srv->cur_sess;
+       return 1;
+}
+
 /* Note: must not be declared <const> as its list will be overwritten */
 static struct acl_kw_list acl_kws = {{ },{
        { "nbsrv",        acl_parse_int,     acl_fetch_nbsrv,          acl_match_int,     ACL_USE_NOTHING },
@@ -1562,6 +1573,7 @@ static struct acl_kw_list acl_kws = {{ },{
        { "avg_queue",    acl_parse_int,     acl_fetch_avg_queue_size, acl_match_int,     ACL_USE_NOTHING },
        { "srv_is_up",    acl_parse_nothing, acl_fetch_srv_is_up,      acl_match_nothing, ACL_USE_NOTHING },
        { "srv_id",       acl_parse_int,     acl_fetch_srv_id,         acl_match_int,     ACL_USE_RTR_INTERNAL },
+       { "srv_conn",     acl_parse_int,     acl_fetch_srv_conn,       acl_match_int,     ACL_USE_NOTHING },
        { NULL, NULL, NULL, NULL },
 }};