[MINOR] acl: add support for table_cnt and table_avl matches

Those trivial matches respectively return the number of entries used
in a stick-table and the number of entries still available in a table.
This commit is contained in:
Willy Tarreau 2011-03-29 00:57:02 +02:00
parent 68f49da972
commit c735a0728e
2 changed files with 44 additions and 0 deletions

View File

@ -7402,6 +7402,17 @@ srv_is_up(<backend>/<server>)
as boolean variables that can be enabled or disabled from the CLI, so that as boolean variables that can be enabled or disabled from the CLI, so that
rules depending on those ACLs can be tweaked in realtime. 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) 7.5.2. Matching contents at Layer 4 (also called Layer 6)
--------------------------------------------------------- ---------------------------------------------------------

View 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)); 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 */ /* Note: must not be declared <const> as its list will be overwritten */
static struct acl_kw_list acl_kws = {{ },{ 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 }, { "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 }, { "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 }, { "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 }, { NULL, NULL, NULL, NULL },
}}; }};