From 24059615a7a45fe95e50d99bd7f56e85b5ad86c1 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 28 Nov 2023 16:34:23 +0100 Subject: [PATCH] MINOR: Add sample fetches to get the frontend and backend stream ID "fc.id" and "bc.id" sample fetches can now be used to get, respectively, the frontend or the backend stream ID. They rely on ->sctl() callback function on the mux attached to the corresponding SC. It means these sample fetches work only for connection, not applets, and from the time a multiplexer is installed. --- doc/configuration.txt | 11 ++++++++- src/stconn.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 1f47d1ebc..2f611d244 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -21213,7 +21213,7 @@ ssl_bc_client_random : binary ssl_bc_curve : string Returns the name of the curve used in the key agreement when the outgoing - connection was made over an SSL/TLS transport layer. This requires + connection was made over an SSL/TLS transport layer. This requires OpenSSL >= 3.0.0. ssl_bc_err : integer @@ -21913,6 +21913,10 @@ Warning : Following sample fetches are ignored if used from HTTP proxies. They all invalid usage (for instance inside a log-format string or a sample expression). So be careful. +bs.id : integer + Returns the multiplexer's stream ID on the server side. It is the + multiplexer's responsibility to return the appropriate information. + distcc_body([,]) : binary Parses a distcc message and returns the body associated to occurrence # of the token . Occurrences start at 1, and when unspecified, any may @@ -21939,6 +21943,11 @@ distcc_param([,]) : integer # send large files to the big farm use_backend big_farm if { distcc_param(DOTI) gt 1000000 } +fs.id : integer + Returns the multiplexer's stream ID on the client side. It is the + multiplexer's responsibility to return the appropriate information. For + instance, on a raw TCP, 0 is always returned because there is no stream. + payload(,) : binary (deprecated) This is an alias for "req.payload" when used in the context of a request (e.g. "stick on", "stick match"), and for "res.payload" when used in the context of diff --git a/src/stconn.c b/src/stconn.c index b2342c98c..2afe8d152 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1990,3 +1991,54 @@ void sc_conn_commit_endp_upgrade(struct stconn *sc) BUG_ON(!sc); BUG_ON(!sc->sedesc); } + +/* return the frontend or backend mux stream ID. + */ +static int +smp_fetch_sid(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + struct connection *conn; + struct stconn *sc; + int64_t sid = 0; + + if (!smp->strm) + return 0; + + sc = (kw[0] == 'f' ? smp->strm->scf : smp->strm->scb); + conn = sc_conn(sc); + + /* No connection */ + if (!conn) + return 0; + + /* No mux install, this may change */ + if (!conn->mux) { + smp->flags |= SMP_F_MAY_CHANGE; + return 0; + } + + /* No sctl, report sid=0 in this case */ + if (conn->mux->sctl) { + if (conn->mux->sctl(sc, MUX_SCTL_SID, &sid) == -1) + return 0; + } + + smp->flags = SMP_F_VOL_TXN; + smp->data.type = SMP_T_SINT; + smp->data.u.sint = sid; + + return 1; +} + +/* Note: must not be declared as its list will be overwritten. + * Note: fetches that may return multiple types should be declared using the + * appropriate pseudo-type. If not available it must be declared as the lowest + * common denominator, the type that can be casted into all other ones. + */ +static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { + { "bs.id", smp_fetch_sid, 0, NULL, SMP_T_SINT, SMP_USE_L6REQ }, + { "fs.id", smp_fetch_sid, 0, NULL, SMP_T_STR, SMP_USE_L6RES }, + { /* END */ }, +}}; + +INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);