mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
[MINOR] session: add the trk_conn_cnt ACL keyword to track connection counts
Most of the time we'll want to check the connection count of the criterion we're currently tracking. So instead of duplicating the src* tests, let's add trk_conn_cnt to report the total number of connections from the stick table entry currently being tracked. A nice part of the code was factored, and we should do the same for the other criteria.
This commit is contained in:
parent
855e4bbcc7
commit
9a3f849371
@ -2071,14 +2071,40 @@ void default_srv_error(struct session *s, struct stream_interface *si)
|
|||||||
/* All supported ACL keywords must be declared here. */
|
/* All supported ACL keywords must be declared here. */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
/* set test->i to the number of connections from the session's source address
|
/* set test->i to the cumulated number of connections in the stksess entry <ts> */
|
||||||
* in the table pointed to by expr.
|
static int
|
||||||
|
acl_fetch_conn_cnt(struct stktable *table, struct acl_test *test, struct stksess *ts)
|
||||||
|
{
|
||||||
|
test->flags = ACL_TEST_F_VOL_TEST;
|
||||||
|
test->i = 0;
|
||||||
|
if (ts != NULL) {
|
||||||
|
void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CNT);
|
||||||
|
if (!ptr)
|
||||||
|
return 0; /* parameter not stored */
|
||||||
|
test->i = stktable_data_cast(ptr, conn_cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set test->i to the cumulated number of connections from the session's tracked counters */
|
||||||
|
static int
|
||||||
|
acl_fetch_trk_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||||
|
struct acl_expr *expr, struct acl_test *test)
|
||||||
|
{
|
||||||
|
if (!l4->tracked_counters)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return acl_fetch_conn_cnt(l4->tracked_table, test, l4->tracked_counters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set test->i to the cumulated number of connections from the session's source
|
||||||
|
* address in the table pointed to by expr.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
||||||
struct acl_expr *expr, struct acl_test *test)
|
struct acl_expr *expr, struct acl_test *test)
|
||||||
{
|
{
|
||||||
struct stksess *ts;
|
|
||||||
struct stktable_key *key;
|
struct stktable_key *key;
|
||||||
|
|
||||||
key = tcpv4_src_to_stktable_key(l4);
|
key = tcpv4_src_to_stktable_key(l4);
|
||||||
@ -2091,16 +2117,7 @@ acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, int dir,
|
|||||||
if (!px)
|
if (!px)
|
||||||
return 0; /* table not found */
|
return 0; /* table not found */
|
||||||
|
|
||||||
test->flags = ACL_TEST_F_VOL_TEST;
|
return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key));
|
||||||
test->i = 0;
|
|
||||||
if ((ts = stktable_lookup_key(&px->table, key)) != NULL) {
|
|
||||||
void *ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT);
|
|
||||||
if (!ptr)
|
|
||||||
return 0; /* parameter not stored */
|
|
||||||
test->i = stktable_data_cast(ptr, conn_cnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set test->i to the number of connections from the session's source address
|
/* set test->i to the number of connections from the session's source address
|
||||||
@ -2245,6 +2262,7 @@ acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, int dir
|
|||||||
|
|
||||||
/* 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 = {{ },{
|
||||||
|
{ "trk_conn_cnt", acl_parse_int, acl_fetch_trk_conn_cnt, acl_match_int, ACL_USE_NOTHING },
|
||||||
{ "src_conn_cnt", acl_parse_int, acl_fetch_src_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_conn_cnt", acl_parse_int, acl_fetch_src_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
{ "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
{ "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user