MEDIUM: counters: factor out smp_fetch_sc*_get_gpc0
smp_fetch_sc0_get_gpc0, smp_fetch_sc1_get_gpc0, smp_fetch_sc2_get_gpc0,
smp_fetch_src_get_gpc0 and smp_fetch_get_gpc0 were merged into a single
function which relies on the fetch name to decide what to return.
diff --git a/src/session.c b/src/session.c
index 35643eb..ba692f0 100644
--- a/src/session.c
+++ b/src/session.c
@@ -2619,15 +2619,26 @@
return 1;
}
-/* set temp integer to the General Purpose Counter 0 value in the stksess entry <ts> */
+/* set <smp> to the General Purpose Counter 0 value from the session's tracked
+ * frontend counters or from the src.
+ * Supports being called as "sc[0-9]_get_gpc0" or "src_get_gpc0" only. Value
+ * zero is returned if the key is new.
+ */
static int
-smp_fetch_get_gpc0(struct stktable *table, struct sample *smp, struct stksess *ts)
+smp_fetch_sc_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+ const struct arg *args, struct sample *smp, const char *kw)
{
+ struct stkctr *stkctr = smp_fetch_sc_stkctr(l4, args, kw);
+
+ if (!stkctr)
+ return 0;
+
smp->flags = SMP_F_VOL_TEST;
smp->type = SMP_T_UINT;
smp->data.uint = 0;
- if (ts != NULL) {
- void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0);
+
+ if (stkctr->entry != NULL) {
+ void *ptr = stktable_data_ptr(stkctr->table, stkctr->entry, STKTABLE_DT_GPC0);
if (!ptr)
return 0; /* parameter not stored */
smp->data.uint = stktable_data_cast(ptr, gpc0);
@@ -2635,60 +2646,6 @@
return 1;
}
-/* set temp integer to the General Purpose Counter 0 value from the session's tracked
- * frontend counters.
- */
-static int
-smp_fetch_sc0_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
- const struct arg *args, struct sample *smp, const char *kw)
-{
- if (!l4->stkctr[0].entry)
- return 0;
- return smp_fetch_get_gpc0(l4->stkctr[0].table, smp, l4->stkctr[0].entry);
-}
-
-/* set temp integer to the General Purpose Counter 0 value from the session's tracked
- * backend counters.
- */
-static int
-smp_fetch_sc1_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
- const struct arg *args, struct sample *smp, const char *kw)
-{
- if (!l4->stkctr[1].entry)
- return 0;
- return smp_fetch_get_gpc0(l4->stkctr[1].table, smp, l4->stkctr[1].entry);
-}
-
-/* set temp integer to the General Purpose Counter 0 value from the session's tracked
- * backend counters.
- */
-static int
-smp_fetch_sc2_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
- const struct arg *args, struct sample *smp, const char *kw)
-{
- if (!l4->stkctr[2].entry)
- return 0;
- return smp_fetch_get_gpc0(l4->stkctr[2].table, smp, l4->stkctr[2].entry);
-}
-
-/* set temp integer to the General Purpose Counter 0 value from the session's source
- * address in the table pointed to by expr.
- * Accepts exactly 1 argument of type table.
- */
-static int
-smp_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
- const struct arg *args, struct sample *smp, const char *kw)
-{
- struct stktable_key *key;
-
- key = addr_to_stktable_key(&l4->si[0].conn->addr.from);
- if (!key)
- return 0;
-
- px = args->data.prx;
- return smp_fetch_get_gpc0(&px->table, smp, stktable_lookup_key(&px->table, key));
-}
-
/* set temp integer to the General Purpose Counter 0's event rate in the stksess entry <ts> */
static int
smp_fetch_gpc0_rate(struct stktable *table, struct sample *smp, struct stksess *ts)
@@ -3958,7 +3915,7 @@
{ "sc0_conn_cnt", smp_fetch_sc0_conn_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc0_conn_cur", smp_fetch_sc0_conn_cur, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc0_conn_rate", smp_fetch_sc0_conn_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
- { "sc0_get_gpc0", smp_fetch_sc0_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
+ { "sc0_get_gpc0", smp_fetch_sc_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc0_gpc0_rate", smp_fetch_sc0_gpc0_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc0_http_err_cnt", smp_fetch_sc0_http_err_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc0_http_err_rate", smp_fetch_sc0_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3977,7 +3934,7 @@
{ "sc1_conn_cnt", smp_fetch_sc1_conn_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc1_conn_cur", smp_fetch_sc1_conn_cur, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc1_conn_rate", smp_fetch_sc1_conn_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
- { "sc1_get_gpc0", smp_fetch_sc1_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
+ { "sc1_get_gpc0", smp_fetch_sc_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc1_gpc0_rate", smp_fetch_sc1_gpc0_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc1_http_err_cnt", smp_fetch_sc1_http_err_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc1_http_err_rate", smp_fetch_sc1_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3996,7 +3953,7 @@
{ "sc2_conn_cnt", smp_fetch_sc2_conn_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc2_conn_cur", smp_fetch_sc2_conn_cur, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc2_conn_rate", smp_fetch_sc2_conn_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
- { "sc2_get_gpc0", smp_fetch_sc2_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
+ { "sc2_get_gpc0", smp_fetch_sc_get_gpc0, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc2_gpc0_rate", smp_fetch_sc2_gpc0_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc2_http_err_cnt", smp_fetch_sc2_http_err_cnt, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
{ "sc2_http_err_rate", smp_fetch_sc2_http_err_rate, 0, NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -4015,7 +3972,7 @@
{ "src_conn_cnt", smp_fetch_src_conn_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
{ "src_conn_cur", smp_fetch_src_conn_cur, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
{ "src_conn_rate", smp_fetch_src_conn_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
- { "src_get_gpc0", smp_fetch_src_get_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+ { "src_get_gpc0", smp_fetch_sc_get_gpc0, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
{ "src_gpc0_rate", smp_fetch_src_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
{ "src_http_err_cnt", smp_fetch_src_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
{ "src_http_err_rate", smp_fetch_src_http_err_rate, ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },