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.
This commit is contained in:
Christopher Faulet 2023-11-28 16:34:23 +01:00
parent fd8ce788a5
commit 24059615a7
2 changed files with 62 additions and 1 deletions

View File

@ -21213,7 +21213,7 @@ ssl_bc_client_random : binary
ssl_bc_curve : string ssl_bc_curve : string
Returns the name of the curve used in the key agreement when the outgoing 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. OpenSSL >= 3.0.0.
ssl_bc_err : integer 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 all invalid usage (for instance inside a log-format string or a
sample expression). So be careful. 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(<token>[,<occ>]) : binary distcc_body(<token>[,<occ>]) : binary
Parses a distcc message and returns the body associated to occurrence #<occ> Parses a distcc message and returns the body associated to occurrence #<occ>
of the token <token>. Occurrences start at 1, and when unspecified, any may of the token <token>. Occurrences start at 1, and when unspecified, any may
@ -21939,6 +21943,11 @@ distcc_param(<token>[,<occ>]) : integer
# send large files to the big farm # send large files to the big farm
use_backend big_farm if { distcc_param(DOTI) gt 1000000 } 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(<offset>,<length>) : binary (deprecated) payload(<offset>,<length>) : binary (deprecated)
This is an alias for "req.payload" when used in the context of a request (e.g. 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 "stick on", "stick match"), and for "res.payload" when used in the context of

View File

@ -17,6 +17,7 @@
#include <haproxy/http_ana.h> #include <haproxy/http_ana.h>
#include <haproxy/pipe.h> #include <haproxy/pipe.h>
#include <haproxy/pool.h> #include <haproxy/pool.h>
#include <haproxy/sample.h>
#include <haproxy/sc_strm.h> #include <haproxy/sc_strm.h>
#include <haproxy/stconn.h> #include <haproxy/stconn.h>
#include <haproxy/xref.h> #include <haproxy/xref.h>
@ -1990,3 +1991,54 @@ void sc_conn_commit_endp_upgrade(struct stconn *sc)
BUG_ON(!sc); BUG_ON(!sc);
BUG_ON(!sc->sedesc); 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 <const> 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);