From: Willy Tarreau Date: Fri, 30 Nov 2007 19:48:53 +0000 (+0100) Subject: [MEDIUM] add the "nbsrv" ACL verb X-Git-Tag: v1.3.14~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9d3c1e6a31b0e6b847409fe82241789221dc101;p=thirdparty%2Fhaproxy.git [MEDIUM] add the "nbsrv" ACL verb The new "nbsrv" ACL verb matches the number of active servers in a backend. By default, it applies to the backend where it is declared, but optionally it can receive the name of another backend as an argument in parenthesis. It counts the number of enabled active servers first, then the number of enabled backup servers. --- diff --git a/src/backend.c b/src/backend.c index 1c544749f0..4dc2b9caf0 100644 --- a/src/backend.c +++ b/src/backend.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include +#include #include #include #include @@ -1541,6 +1543,51 @@ int backend_parse_balance(const char **args, char *err, int errlen, struct proxy return 0; } + +/************************************************************************/ +/* All supported keywords must be declared here. */ +/************************************************************************/ + +/* set test->i to the number of enabled servers on the proxy */ +static int +acl_fetch_nbsrv(struct proxy *px, struct session *l4, void *l7, int dir, + struct acl_expr *expr, struct acl_test *test) +{ + test->flags = ACL_TEST_F_VOL_TEST; + if (expr->arg_len) { + /* another proxy was designated, we must look for it */ + for (px = proxy; px; px = px->next) + if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str)) + break; + } + if (!px) + return 0; + + if (px->srv_act) + test->i = px->srv_act; + else if (px->lbprm.fbck) + test->i = 1; + else + test->i = px->srv_bck; + + 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 }, + { NULL, NULL, NULL, NULL }, +}}; + + +__attribute__((constructor)) +static void __backend_init(void) +{ + acl_register_keywords(&acl_kws); +} + + /* * Local variables: * c-indent-level: 8