]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] session: add the trk_conn_cur ACL keyword to track concurrent connection
authorWilly Tarreau <w@1wt.eu>
Fri, 18 Jun 2010 19:14:36 +0000 (21:14 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 10 Aug 2010 16:04:13 +0000 (18:04 +0200)
This one applies to the entry being tracked by current session.

src/session.c

index 55a8066c691d7ca2c6bbe12f120ee76775d2708a..b09caaeee92b7dd40dda01964b2217e7dd26770c 100644 (file)
@@ -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 <ts> */
+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 },