From: Aurelien DARRAGON Date: Mon, 30 Dec 2024 18:26:36 +0000 (+0100) Subject: MINOR: stktable: add sc[0-2]_key fetches X-Git-Tag: v3.2-dev4~41 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=24042df94e27485550d83770138d99d3d07ae6a4;p=thirdparty%2Fhaproxy.git MINOR: stktable: add sc[0-2]_key fetches As discussed in GH #1750, we were lacking a sample fetch to be able to retrieve the key from the currently tracked counter entry. To do so, sc_key fetch can now be used. It returns a sample with the correct type (table key type) corresponding to the tracked counter entry (from previous track-sc rules). If no entry is currently tracked, it returns nothing. It can be used using the standard form "sc_key()" or the legacy form: "sc0_key", "sc1_key", "sc2_key" Documentation was updated. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 6478bc8521..36be7e8e60 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -22748,6 +22748,10 @@ sc_kbytes_out([,]) integer sc0_kbytes_out([
]) integer sc1_kbytes_out([
]) integer sc2_kbytes_out([
]) integer +sc_key() any +sc0_key any +sc1_key any +sc2_key any sc_sess_cnt([,
]) integer sc0_sess_cnt([
]) integer sc1_sess_cnt([
]) integer @@ -23560,6 +23564,12 @@ sc2_kbytes_out([
]) : integer counters, measured in kilobytes. The test is currently performed on 32-bit integers, which limits values to 4 terabytes. See also src_kbytes_out. +sc_key() : any +sc0_key : any +sc1_key : any +sc2_key : any + Returns the key used to match the currently tracked counter. + sc_sess_cnt([,
]) : integer sc0_sess_cnt([
]) : integer sc1_sess_cnt([
]) : integer diff --git a/src/stick_table.c b/src/stick_table.c index 7f788f8f7d..eebf3354dd 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -5115,6 +5115,32 @@ smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char * return 1; } +/* set to the key associated to the stream's tracked entry. + * Supports being called as "sc[0-9]_key" or "sc_key" only. + */ +static int +smp_fetch_sc_key(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + struct stkctr tmpstkctr; + struct stkctr *stkctr; + struct stksess *entry; + + stkctr = smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw, &tmpstkctr); + if (!stkctr) + return 0; + + entry = stkctr_entry(stkctr); + if (entry != NULL) { + int ret = stkey_to_smp(smp, stksess_getkey(stkctr->table, entry), stkctr->table->type); + + if (stkctr == &tmpstkctr) + stktable_release(stkctr->table, entry); + + return !!ret; + } + return 0; /* nothing currently tracked */ +} + /* set to the data rate sent to clients in bytes/s, as found in the * stream's tracked frontend counters. Supports being called as * "sc[0-9]_bytes_out_rate" or "src_bytes_out_rate" only. @@ -6049,6 +6075,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc_kbytes_in", smp_fetch_sc_kbytes_in, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, { "sc_kbytes_out", smp_fetch_sc_kbytes_out, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, + { "sc_key", smp_fetch_sc_key, ARG1(1,SINT), NULL, SMP_T_ANY, SMP_USE_INTRN, }, { "sc_sess_cnt", smp_fetch_sc_sess_cnt, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc_sess_rate", smp_fetch_sc_sess_rate, ARG2(1,SINT,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc_tracked", smp_fetch_sc_tracked, ARG2(1,SINT,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, @@ -6077,6 +6104,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc0_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc0_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, { "sc0_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, + { "sc0_key", smp_fetch_sc_key, 0, NULL, SMP_T_ANY, SMP_USE_INTRN, }, { "sc0_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc0_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc0_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, @@ -6106,6 +6134,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc1_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc1_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, { "sc1_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, + { "sc1_key", smp_fetch_sc_key, 0, NULL, SMP_T_ANY, SMP_USE_INTRN, }, { "sc1_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc1_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc1_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, }, @@ -6134,6 +6163,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, { { "sc2_inc_gpc1", smp_fetch_sc_inc_gpc1, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc2_kbytes_in", smp_fetch_sc_kbytes_in, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, { "sc2_kbytes_out", smp_fetch_sc_kbytes_out, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_L4CLI, }, + { "sc2_key", smp_fetch_sc_key, 0, NULL, SMP_T_ANY, SMP_USE_INTRN, }, { "sc2_sess_cnt", smp_fetch_sc_sess_cnt, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc2_sess_rate", smp_fetch_sc_sess_rate, ARG1(0,TAB), NULL, SMP_T_SINT, SMP_USE_INTRN, }, { "sc2_tracked", smp_fetch_sc_tracked, ARG1(0,TAB), NULL, SMP_T_BOOL, SMP_USE_INTRN, },