s->listener->counters->bytes_in += bytes;
if (s->tracked_counters) {
- void *ptr = stktable_data_ptr(s->tracked_table,
- s->tracked_counters,
- STKTABLE_DT_BYTES_IN_CNT);
+ void *ptr;
+
+ ptr = stktable_data_ptr(s->tracked_table,
+ s->tracked_counters,
+ STKTABLE_DT_BYTES_IN_CNT);
if (ptr)
stktable_data_cast(ptr, bytes_in_cnt) += bytes;
+
+ ptr = stktable_data_ptr(s->tracked_table,
+ s->tracked_counters,
+ STKTABLE_DT_BYTES_IN_RATE);
+ if (ptr)
+ update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
+ s->tracked_table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes);
}
}
}
s->listener->counters->bytes_out += bytes;
if (s->tracked_counters) {
- void *ptr = stktable_data_ptr(s->tracked_table,
- s->tracked_counters,
- STKTABLE_DT_BYTES_OUT_CNT);
+ void *ptr;
+
+ ptr = stktable_data_ptr(s->tracked_table,
+ s->tracked_counters,
+ STKTABLE_DT_BYTES_OUT_CNT);
if (ptr)
stktable_data_cast(ptr, bytes_out_cnt) += bytes;
+
+ ptr = stktable_data_ptr(s->tracked_table,
+ s->tracked_counters,
+ STKTABLE_DT_BYTES_OUT_RATE);
+ if (ptr)
+ update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
+ s->tracked_table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes);
}
}
}
return acl_fetch_kbytes_in(&px->table, test, stktable_lookup_key(&px->table, key));
}
+/* set test->i to the bytes rate from clients in the stksess entry <ts> over the
+ * configured period.
+ */
+static int
+acl_fetch_bytes_in_rate(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_BYTES_IN_RATE);
+ if (!ptr)
+ return 0; /* parameter not stored */
+ test->i = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
+ table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
+ }
+ return 1;
+}
+
+/* set test->i to the bytes rate from clients from the session's tracked
+ * counters over the configured period.
+ */
+static int
+acl_fetch_trk_bytes_in_rate(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_bytes_in_rate(l4->tracked_table, test, l4->tracked_counters);
+}
+
+/* set test->i to the bytes rate from clients from the session's source address
+ * in the table pointed to by expr, over the configured period.
+ */
+static int
+acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+ struct acl_expr *expr, struct acl_test *test)
+{
+ struct stktable_key *key;
+
+ key = tcpv4_src_to_stktable_key(l4);
+ if (!key)
+ return 0; /* only TCPv4 is supported right now */
+
+ if (expr->arg_len)
+ px = find_stktable(expr->arg.str);
+
+ if (!px)
+ return 0; /* table not found */
+
+ return acl_fetch_bytes_in_rate(&px->table, test, stktable_lookup_key(&px->table, key));
+}
+
/* set test->i to the number of kbytes sent to clients matching the stksess entry <ts> */
static int
acl_fetch_kbytes_out(struct stktable *table, struct acl_test *test, struct stksess *ts)
return acl_fetch_kbytes_out(&px->table, test, stktable_lookup_key(&px->table, key));
}
+/* set test->i to the bytes rate to clients in the stksess entry <ts> over the
+ * configured period.
+ */
+static int
+acl_fetch_bytes_out_rate(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_BYTES_OUT_RATE);
+ if (!ptr)
+ return 0; /* parameter not stored */
+ test->i = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
+ table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
+ }
+ return 1;
+}
+
+/* set test->i to the bytes rate to clients from the session's tracked counters
+ * over the configured period.
+ */
+static int
+acl_fetch_trk_bytes_out_rate(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_bytes_out_rate(l4->tracked_table, test, l4->tracked_counters);
+}
+
+/* set test->i to the bytes rate to client from the session's source address in
+ * the table pointed to by expr, over the configured period.
+ */
+static int
+acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, int dir,
+ struct acl_expr *expr, struct acl_test *test)
+{
+ struct stktable_key *key;
+
+ key = tcpv4_src_to_stktable_key(l4);
+ if (!key)
+ return 0; /* only TCPv4 is supported right now */
+
+ if (expr->arg_len)
+ px = find_stktable(expr->arg.str);
+
+ if (!px)
+ return 0; /* table not found */
+
+ return acl_fetch_bytes_out_rate(&px->table, test, stktable_lookup_key(&px->table, key));
+}
+
/* Note: must not be declared <const> as its list will be overwritten */
static struct acl_kw_list acl_kws = {{ },{
{ "src_sess_rate", acl_parse_int, acl_fetch_src_sess_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
{ "trk_kbytes_in", acl_parse_int, acl_fetch_trk_kbytes_in, 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 },
+ { "trk_bytes_in_rate", acl_parse_int, acl_fetch_trk_bytes_in_rate, acl_match_int, ACL_USE_NOTHING },
+ { "src_bytes_in_rate", acl_parse_int, acl_fetch_src_bytes_in_rate, acl_match_int, ACL_USE_TCP4_VOLATILE },
{ "trk_kbytes_out", acl_parse_int, acl_fetch_trk_kbytes_out, 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 },
+ { "trk_bytes_out_rate", acl_parse_int, acl_fetch_trk_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 },
{ NULL, NULL, NULL, NULL },
}};