MINOR: tcp-sample: permit retrieving tcp_info from the connection/session stage
Some checks are pending
Contrib / build (push) Waiting to run
alpine/musl / gcc (push) Waiting to run
VTest / Generate Build Matrix (push) Waiting to run
VTest / (push) Blocked by required conditions
Windows / Windows, gcc, all features (push) Waiting to run

The fc_xxx info that are retrieved over tcp_info could currently not
be accessed before a stream is created due to a test that verified the
existence of a stream. The rationale here was that the function works
both for frontend and backend. Let's always retrieve these info from
the session for the frontend case so that it now becomes possible to
set variables at connection/session time. The doc did not mention this
limitation so this could almost be considered as a bug.
This commit is contained in:
Willy Tarreau 2026-01-11 15:19:18 +01:00
parent 880bbeeda4
commit 2560cce7c5

View file

@ -323,21 +323,20 @@ static inline int get_tcp_info(const struct arg *args, struct sample *smp,
{
struct connection *conn;
/* strm can be null. */
if (!smp->strm)
return 0;
smp->data.type = SMP_T_SINT;
/* get the object associated with the stream connector.The
* object can be other thing than a connection. For example,
* it could be an appctx.
/* The front connection may be obtained either via the stream or the
* session. Since the session is always there, we use it. Note that
* the origin is not necessarily a connection (e.g. appctx). The back
* connection however only works with a stream, so we check both.
*/
conn = (dir == 0 ? sc_conn(smp->strm->scf) : sc_conn(smp->strm->scb));
conn = dir == 0 ?
objt_conn(smp->sess->origin) :
smp->strm ? sc_conn(smp->strm->scb) : NULL;
if (!conn || !conn->ctrl->get_info ||
!conn->ctrl->get_info(conn, &smp->data.u.sint, val))
return 0;
return 1;
}