]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: define bc_reused fetch
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 28 Mar 2025 15:54:12 +0000 (16:54 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 2 Apr 2025 12:57:40 +0000 (14:57 +0200)
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.

doc/configuration.txt
src/tcp_sample.c

index 6ae4b93b8a14aefd04af167a9f33465889842839..156130282025419b770877270b8e914ac3c22159 100644 (file)
@@ -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
index a552ebd4f911bd46d7a95a9313a44a735b08e3fe..1cde726111ceb4b4b1b593a809985c9d1c237898 100644 (file)
@@ -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 },