From: Hervé COMMOWICK Date: Fri, 5 Aug 2011 10:09:44 +0000 (+0200) Subject: [MINOR] acl: add srv_conn acl to count connections on a X-Git-Tag: v1.5-dev8~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daa824e513cc9de9b57211d66f4025b7c7d32ac5;p=thirdparty%2Fhaproxy.git [MINOR] acl: add srv_conn acl to count connections on a specific backend server These ACLs are used to check the number of active connections on the specified server in the specified backend. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index cd5f979ebd..d2f75a7ab3 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -7456,6 +7456,12 @@ src_updt_conn_cnt(table) tcp-request content reject if { src_update_count gt 3 } server local 127.0.0.1:22 +srv_conn(backend/server) + 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 Applies to the server's id. Can be used in frontends or backends. diff --git a/include/types/acl.h b/include/types/acl.h index a22b6cccbc..9afd85c068 100644 --- a/include/types/acl.h +++ b/include/types/acl.h @@ -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 */ diff --git a/src/acl.c b/src/acl.c index 26b82cb35d..9d9a7466a6 100644 --- 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; diff --git a/src/backend.c b/src/backend.c index 4b923a7e59..d76324fc54 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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 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 }, }};