From: Christopher Faulet Date: Thu, 15 Apr 2021 07:39:38 +0000 (+0200) Subject: MINOR: tcp_samples: Be able to call bc_src/bc_dst from the health-checks X-Git-Tag: v2.4-dev17~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=003df1cff962702ec53e72bfe8f4da48a9e16496;p=thirdparty%2Fhaproxy.git MINOR: tcp_samples: Be able to call bc_src/bc_dst from the health-checks The new L4 sample fetches used to get source and destination info of the backend connection may now be called from an health-check. --- diff --git a/src/tcp_sample.c b/src/tcp_sample.c index 4fbd98c1c4..8242fa4ab6 100644 --- a/src/tcp_sample.c +++ b/src/tcp_sample.c @@ -47,8 +47,13 @@ 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;