]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tcp_samples: Be able to call bc_src/bc_dst from the health-checks
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 15 Apr 2021 07:39:38 +0000 (09:39 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Apr 2021 06:31:05 +0000 (08:31 +0200)
The new L4 sample fetches used to get source and destination info of the
backend connection may now be called from an health-check.

src/tcp_sample.c

index 4fbd98c1c4eb76e850c93424714df245cb81bbbc..8242fa4ab66172f69d39bc7d7723661f4a6f2c20 100644 (file)
 static int
 smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct connection *conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
-               smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
+       struct connection *conn;
+
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+                conn = (kw[0] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
+        else
+                conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
+                       smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
 
        if (!conn)
                return 0;
@@ -79,8 +84,13 @@ smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, void *
 static int
 smp_fetch_sport(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct connection *conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
-               smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
+       struct connection *conn;
+
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+                conn = (kw[0] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
+        else
+                conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
+                       smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
 
        if (!conn)
                return 0;
@@ -102,8 +112,13 @@ smp_fetch_sport(const struct arg *args, struct sample *smp, const char *kw, void
 static int
 smp_fetch_dst(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct connection *conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
-               smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
+       struct connection *conn;
+
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+                conn = (kw[0] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
+        else
+                conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
+                       smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
 
        if (!conn)
                return 0;
@@ -174,8 +189,13 @@ int smp_fetch_src_is_local(const struct arg *args, struct sample *smp, const cha
 static int
 smp_fetch_dport(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct connection *conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
-               smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
+       struct connection *conn;
+
+       if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+                conn = (kw[0] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL;
+        else
+                conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
+                       smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
 
        if (!conn)
                return 0;