From: Willy Tarreau Date: Fri, 18 Jun 2010 19:14:36 +0000 (+0200) Subject: [MINOR] session: add the trk_conn_cur ACL keyword to track concurrent connection X-Git-Tag: v1.5-dev8~520 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9b0ddcfd843399c32b5a269d3af27a240c92810e;p=thirdparty%2Fhaproxy.git [MINOR] session: add the trk_conn_cur ACL keyword to track concurrent connection This one applies to the entry being tracked by current session. --- diff --git a/src/session.c b/src/session.c index 55a8066c69..b09caaeee9 100644 --- a/src/session.c +++ b/src/session.c @@ -2083,7 +2083,6 @@ acl_fetch_conn_cnt(struct stktable *table, struct acl_test *test, struct stksess return 0; /* parameter not stored */ test->i = stktable_data_cast(ptr, conn_cnt); } - return 1; } @@ -2160,6 +2159,33 @@ acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, int return 1; } +/* set test->i to the number of concurrent connections in the stksess entry */ +static int +acl_fetch_conn_cur(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_CUR); + if (!ptr) + return 0; /* parameter not stored */ + test->i = stktable_data_cast(ptr, conn_cur); + } + return 1; +} + +/* set test->i to the number of concurrent connections from the session's tracked counters */ +static int +acl_fetch_trk_conn_cur(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_cur(l4->tracked_table, test, l4->tracked_counters); +} + /* set test->i to the number of concurrent connections from the session's source * address in the table pointed to by expr. */ @@ -2167,7 +2193,6 @@ static int acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct acl_test *test) { - struct stksess *ts; struct stktable_key *key; key = tcpv4_src_to_stktable_key(l4); @@ -2180,17 +2205,7 @@ acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, int dir, if (!px) return 0; /* table not found */ - test->flags = ACL_TEST_F_VOL_TEST; - test->i = 0; - - if ((ts = stktable_lookup_key(&px->table, key)) != NULL) { - void *ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CUR); - if (!ptr) - return 0; /* parameter not stored */ - test->i = stktable_data_cast(ptr, conn_cur); - } - - return 1; + return acl_fetch_conn_cnt(&px->table, test, stktable_lookup_key(&px->table, key)); } /* set test->i to the number of kbytes received from the session's source @@ -2265,6 +2280,7 @@ 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_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE }, + { "trk_conn_cur", acl_parse_int, acl_fetch_trk_conn_cur, acl_match_int, ACL_USE_NOTHING }, { "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE }, { "src_kbytes_in", acl_parse_int, acl_fetch_src_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE }, { "src_kbytes_out", acl_parse_int, acl_fetch_src_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE },