]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: Add support of be_id, be_name, srv_id and srv_name sample fetches
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 30 Apr 2020 07:51:15 +0000 (09:51 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 5 May 2020 09:06:43 +0000 (11:06 +0200)
It is now possible to call be_id, be_name, srv_id and srv_name sample fetches
from any sample expression or log-format string in a tcp-check based ruleset.

doc/configuration.txt
src/backend.c

index 763e4ad7adb4c3f65acd281715390a68cef198c3..86f3f1a4cc71b22d25a145c39f5e104a81a7aae6 100644 (file)
@@ -15648,11 +15648,13 @@ bc_http_major : integer
 
 be_id : integer
   Returns an integer containing the current backend's id. It can be used in
-  frontends with responses to check which backend processed the request.
+  frontends with responses to check which backend processed the request. It can
+  also be used in a tcp-check or an http-check ruleset.
 
 be_name : string
   Returns a string containing the current backend's name. It can be used in
-  frontends with responses to check which backend processed the request.
+  frontends with responses to check which backend processed the request. It can
+  also be used in a tcp-check or an http-check ruleset.
 
 dst : ip
   This is the destination IPv4 address of the connection on the client side,
@@ -16243,12 +16245,12 @@ src_updt_conn_cnt([<table>]) : integer
 srv_id : integer
   Returns an integer containing the server's id when processing the response.
   While it's almost only used with ACLs, it may be used for logging or
-  debugging.
+  debugging. It can also be used in a tcp-check or an http-check ruleset.
 
 srv_name : string
   Returns a string containing the server's name when processing the response.
   While it's almost only used with ACLs, it may be used for logging or
-  debugging.
+  debugging. It can also be used in a tcp-check or an http-check ruleset.
 
 7.3.4. Fetching samples at Layer 5
 ----------------------------------
index ccf06b8171a5301ea52c36538eae019e84ac33d9..472d905533b73b537630c66c776618fb8f396415 100644 (file)
@@ -2544,12 +2544,18 @@ smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw,
 static int
 smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       if (!smp->strm)
+       struct proxy *px = NULL;
+
+       if (smp->strm)
+               px = smp->strm->be;
+       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+               px = __objt_check(smp->sess->origin)->proxy;
+       if (!px)
                return 0;
 
        smp->flags = SMP_F_VOL_TXN;
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = smp->strm->be->uuid;
+       smp->data.u.sint = px->uuid;
        return 1;
 }
 
@@ -2557,10 +2563,16 @@ smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void
 static int
 smp_fetch_be_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       if (!smp->strm)
+       struct proxy *px = NULL;
+
+       if (smp->strm)
+               px = smp->strm->be;
+       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+               px = __objt_check(smp->sess->origin)->proxy;
+       if (!px)
                return 0;
 
-       smp->data.u.str.area = (char *)smp->strm->be->id;
+       smp->data.u.str.area = (char *)px->id;
        if (!smp->data.u.str.area)
                return 0;
 
@@ -2575,14 +2587,17 @@ smp_fetch_be_name(const struct arg *args, struct sample *smp, const char *kw, vo
 static int
 smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       if (!smp->strm)
-               return 0;
+       struct server *srv = NULL;
 
-       if (!objt_server(smp->strm->target))
+       if (smp->strm)
+               srv = objt_server(smp->strm->target);
+       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+               srv = __objt_check(smp->sess->origin)->server;
+       if (!srv)
                return 0;
 
        smp->data.type = SMP_T_SINT;
-       smp->data.u.sint = __objt_server(smp->strm->target)->puid;
+       smp->data.u.sint = srv->puid;
 
        return 1;
 }
@@ -2591,13 +2606,16 @@ smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, voi
 static int
 smp_fetch_srv_name(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       if (!smp->strm)
-               return 0;
+       struct server *srv = NULL;
 
-       if (!objt_server(smp->strm->target))
+       if (smp->strm)
+               srv = objt_server(smp->strm->target);
+       else if (smp->sess && obj_type(smp->sess->origin) == OBJ_TYPE_CHECK)
+               srv = __objt_check(smp->sess->origin)->server;
+       if (!srv)
                return 0;
 
-       smp->data.u.str.area = (char *)__objt_server(smp->strm->target)->id;
+       smp->data.u.str.area = srv->id;
        if (!smp->data.u.str.area)
                return 0;