From: Amaury Denoyelle Date: Fri, 28 Mar 2025 15:54:12 +0000 (+0100) Subject: MINOR: sample: define bc_reused fetch X-Git-Tag: v3.2-dev9~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec76d52cea739b392d2721dd67450e30e2c08718;p=thirdparty%2Fhaproxy.git MINOR: sample: define bc_reused fetch Define a new layer4 sample fetch "bc_reused". It is used as a boolean, set to true if backend connection was reused for the request. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 6ae4b93b8..156130282 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -23083,6 +23083,7 @@ bc_err_str string bc_glitches integer bc_http_major integer bc_nb_streams integer +bc_reused boolean bc_src ip bc_src_port integer bc_srv_queue integer @@ -23375,6 +23376,9 @@ bc_http_major : integer bc_nb_streams : integer Returns the number of streams opened on the backend connection. +bc_reused : boolean + Returns true if the transfer was performed via a reused backend connection. + bc_src : ip This is the source ip address of the connection on the server side, which is the server address HAProxy connected from. It is of type IP and works on both diff --git a/src/tcp_sample.c b/src/tcp_sample.c index a552ebd4f..1cde72611 100644 --- a/src/tcp_sample.c +++ b/src/tcp_sample.c @@ -116,6 +116,17 @@ smp_fetch_sport(const struct arg *args, struct sample *smp, const char *kw, void return 1; } +/* return a valid test if the current request was performed using connection reuse */ +static int smp_fetch_reused(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + if (!smp->strm) + return 0; + + smp->data.type = SMP_T_BOOL; + smp->data.u.sint = !!(smp->strm->flags & SF_SRV_REUSED); + return 1; +} + /* fetch the connection's destination IPv4/IPv6 address. Depending on the * keyword, it may be the frontend or the backend connection. */ @@ -551,6 +562,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { { "bc_dst_port", smp_fetch_dport, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV }, { "bc_src", smp_fetch_src, 0, NULL, SMP_T_ADDR, SMP_USE_L4SRV }, { "bc_src_port", smp_fetch_sport, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV }, + { "bc_reused", smp_fetch_reused, 0, NULL, SMP_T_BOOL, SMP_USE_L4SRV }, { "dst", smp_fetch_dst, 0, NULL, SMP_T_ADDR, SMP_USE_L4CLI }, { "dst_is_local", smp_fetch_dst_is_local, 0, NULL, SMP_T_BOOL, SMP_USE_L4CLI },