MINOR: checks: Add support of be_id, be_name, srv_id and srv_name sample fetches

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.
This commit is contained in:
Christopher Faulet 2020-04-30 09:51:15 +02:00
parent 78f371e498
commit d1b4464b69
2 changed files with 37 additions and 17 deletions

View 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
----------------------------------

View 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)
struct server *srv = NULL;
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;
if (!objt_server(smp->strm->target))
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;