From: Remi Tricot-Le Breton Date: Wed, 1 Sep 2021 13:52:15 +0000 (+0200) Subject: MINOR: connection: Add a connection error code sample fetch for backend side X-Git-Tag: v2.5-dev6~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=942c16722916b556ec2bf9b1e44c315502a47134;p=thirdparty%2Fhaproxy.git MINOR: connection: Add a connection error code sample fetch for backend side The bc_conn_err and bc_conn_err_str sample fetches give the status of the connection on the backend side. The error codes and error messages are the same than the ones that can be raised by the fc_conn_err fetch. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index dbbf19ea1a..f524dda3bf 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -17733,6 +17733,17 @@ table may be specified with the "sc*" form, in which case the currently tracked key will be looked up into this alternate table instead of the table currently being tracked. +bc_conn_err : integer + Returns the ID of the error that might have occurred on the current backend + connection. See the "fc_conn_err_str" fetch for a full list of error codes + and their corresponding error message. + +bc_conn_err_str : string + Returns an error message describing what problem happened on the current + backend connection, resulting in a connection failure. See the + "fc_conn_err_str" fetch for a full list of error codes and their + corresponding error message. + bc_dst : ip This is the destination ip address of the connection on the server side, which is the server address HAProxy connected to. It is of type IP and works diff --git a/src/connection.c b/src/connection.c index 09c91a5421..f85cae956d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -1503,7 +1503,12 @@ int smp_fetch_fc_conn_err(const struct arg *args, struct sample *smp, const char { struct connection *conn; - conn = objt_conn(smp->sess->origin); + 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; @@ -1525,7 +1530,12 @@ int smp_fetch_fc_conn_err_str(const struct arg *args, struct sample *smp, const struct connection *conn; const char *err_code_str; - conn = objt_conn(smp->sess->origin); + 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; @@ -1560,6 +1570,8 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { { "fc_pp_unique_id", smp_fetch_fc_pp_unique_id, 0, NULL, SMP_T_STR, SMP_USE_L4CLI }, { "fc_conn_err", smp_fetch_fc_conn_err, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI }, { "fc_conn_err_str", smp_fetch_fc_conn_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4CLI }, + { "bc_conn_err", smp_fetch_fc_conn_err, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV }, + { "bc_conn_err_str", smp_fetch_fc_conn_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4SRV }, { /* END */ }, }};