]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] acl: add support for table_cnt and table_avl matches
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Mar 2011 22:57:02 +0000 (00:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Mar 2011 22:57:02 +0000 (00:57 +0200)
Those trivial matches respectively return the number of entries used
in a stick-table and the number of entries still available in a table.

doc/configuration.txt
src/session.c

index 3a3ddcc41db6d59335cd279943f42114cc001339..3ebbb471c75e128557f141420e3df282a6890e97 100644 (file)
@@ -7402,6 +7402,17 @@ srv_is_up(<backend>/<server>)
   as boolean variables that can be enabled or disabled from the CLI, so that
   rules depending on those ACLs can be tweaked in realtime.
 
+table_avl <integer>
+table_avl(table) <integer>
+  Returns the total number of available entries in the current proxy's
+  stick-table or in the designated stick-table. See also table_cnt.
+
+table_cnt <integer>
+table_cnt(table) <integer>
+  Returns the total number of entries currently in use in the current proxy's
+  stick-table or in the designated stick-table. See also src_conn_cnt and
+  table_avl for other entry counting methods.
+
 
 7.5.2. Matching contents at Layer 4 (also called Layer 6)
 ---------------------------------------------------------
index d673aaa63c24dc91a336adf79afc1b08eb3132e3..b7914d030b5d02818a263b36ad04119425f6cb4d 100644 (file)
@@ -3166,6 +3166,37 @@ acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int
        return acl_fetch_bytes_out_rate(&px->table, test, stktable_lookup_key(&px->table, key));
 }
 
+/* set test->i to the number of used entries in the table pointed to by expr. */
+static int
+acl_fetch_table_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
+                       struct acl_expr *expr, struct acl_test *test)
+{
+       if (expr->arg_len)
+               px = find_stktable(expr->arg.str);
+
+       if (!px)
+               return 0; /* table not found */
+
+       test->flags = ACL_TEST_F_VOL_TEST;
+       test->i = px->table.current;
+       return 1;
+}
+
+/* set test->i to the number of free entries in the table pointed to by expr. */
+static int
+acl_fetch_table_avl(struct proxy *px, struct session *l4, void *l7, int dir,
+                            struct acl_expr *expr, struct acl_test *test)
+{
+       if (expr->arg_len)
+               px = find_stktable(expr->arg.str);
+
+       if (!px)
+               return 0; /* table not found */
+
+       test->flags = ACL_TEST_F_VOL_TEST;
+       test->i = px->table.size - px->table.current;
+       return 1;
+}
 
 /* Note: must not be declared <const> as its list will be overwritten */
 static struct acl_kw_list acl_kws = {{ },{
@@ -3215,6 +3246,8 @@ static struct acl_kw_list acl_kws = {{ },{
        { "sc1_bytes_out_rate", acl_parse_int,   acl_fetch_sc1_bytes_out_rate, acl_match_int, ACL_USE_NOTHING },
        { "sc2_bytes_out_rate", acl_parse_int,   acl_fetch_sc2_bytes_out_rate, acl_match_int, ACL_USE_NOTHING },
        { "src_bytes_out_rate", acl_parse_int,   acl_fetch_src_bytes_out_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
+       { "table_avl",          acl_parse_int,   acl_fetch_table_avl,          acl_match_int, ACL_USE_NOTHING },
+       { "table_cnt",          acl_parse_int,   acl_fetch_table_cnt,          acl_match_int, ACL_USE_NOTHING },
        { NULL, NULL, NULL, NULL },
 }};