MINOR: muxes: Implement ->sctl() callback for muxes and return the stream id

All muxes now implements the ->sctl() callback function and are able to
return the stream ID. For the PT multiplexer, it is always 0. For the H1
multiplexer it is the request count for the current H1 connection (added for
this purpose). The FCGI, H2 and QUIC muxes, the stream ID is returned.

The stream ID is returned as a signed 64 bits integer.
This commit is contained in:
Christopher Faulet 2023-11-28 15:12:51 +01:00
parent 0f15dcd9a7
commit fd8ce788a5
5 changed files with 90 additions and 0 deletions

View File

@ -3102,6 +3102,22 @@ static int fcgi_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *ou
}
}
static int fcgi_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
{
int ret = 0;
struct fcgi_strm *fstrm = __sc_mux_strm(sc);
switch (mux_sctl) {
case MUX_SCTL_SID:
if (output)
*((int64_t *)output) = fstrm->id;
return ret;
default:
return -1;
}
}
/* Connection timeout management. The principle is that if there's no receipt
* nor sending for a certain amount of time, the connection is closed. If the
* MUX buffer still has lying data or is not allocatable, the connection is
@ -4230,6 +4246,7 @@ static const struct mux_ops mux_fcgi_ops = {
.shutr = fcgi_shutr,
.shutw = fcgi_shutw,
.ctl = fcgi_ctl,
.sctl = fcgi_sctl,
.show_fd = fcgi_show_fd,
.takeover = fcgi_takeover,
.flags = MX_FL_HTX|MX_FL_HOL_RISK|MX_FL_NO_UPG,

View File

@ -53,6 +53,8 @@ struct h1c {
int timeout; /* client/server timeout duration */
int shut_timeout; /* client-fin/server-fin timeout duration */
unsigned int req_count; /* The number of requests handled by this H1 connection */
struct h1_counters *px_counters; /* h1 counters attached to proxy */
struct buffer_wait buf_wait; /* Wait list for buffer allocation */
struct wait_event wait_event; /* To be used if we're waiting for I/Os */
@ -872,6 +874,7 @@ static void h1s_destroy(struct h1s *h1s)
h1s->req.state == H1_MSG_DONE && h1s->res.state == H1_MSG_DONE) { /* req/res in DONE state */
h1c->state = H1_CS_IDLE;
h1c->flags |= H1C_F_WAIT_NEXT_REQ;
h1c->req_count++;
TRACE_STATE("set idle mode on h1c, waiting for the next request", H1_EV_H1C_ERR, h1c->conn, h1s);
}
else {
@ -918,6 +921,7 @@ static int h1_init(struct connection *conn, struct proxy *proxy, struct session
h1c->obuf = BUF_NULL;
h1c->h1s = NULL;
h1c->task = NULL;
h1c->req_count = 0;
LIST_INIT(&h1c->buf_wait.list);
h1c->wait_event.tasklet = tasklet_new();
@ -4834,6 +4838,22 @@ static int h1_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *outp
}
}
static int h1_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
{
int ret = 0;
struct h1s *h1s = __sc_mux_strm(sc);
switch (mux_sctl) {
case MUX_SCTL_SID:
if (output)
*((int64_t *)output) = h1s->h1c->req_count;
return ret;
default:
return -1;
}
}
/* appends some info about connection <h1c> to buffer <msg>, or does nothing if
* <h1c> is NULL. Returns non-zero if the connection is considered suspicious.
* May emit multiple lines, each new one being prefixed with <pfx>, if <pfx> is
@ -5251,6 +5271,7 @@ static const struct mux_ops mux_http_ops = {
.show_fd = h1_show_fd,
.show_sd = h1_show_sd,
.ctl = h1_ctl,
.sctl = h1_sctl,
.takeover = h1_takeover,
.flags = MX_FL_HTX,
.name = "H1",
@ -5278,6 +5299,7 @@ static const struct mux_ops mux_h1_ops = {
.show_fd = h1_show_fd,
.show_sd = h1_show_sd,
.ctl = h1_ctl,
.sctl = h1_sctl,
.takeover = h1_takeover,
.flags = MX_FL_HTX|MX_FL_NO_UPG,
.name = "H1",

View File

@ -4526,6 +4526,22 @@ static int h2_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *outp
}
}
static int h2_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
{
int ret = 0;
struct h2s *h2s = __sc_mux_strm(sc);
switch (mux_sctl) {
case MUX_SCTL_SID:
if (output)
*((int64_t *)output) = h2s->id;
return ret;
default:
return -1;
}
}
/*
* Destroy the mux and the associated connection, if it is no longer used
*/
@ -7447,6 +7463,7 @@ static const struct mux_ops h2_ops = {
.shutr = h2_shutr,
.shutw = h2_shutw,
.ctl = h2_ctl,
.sctl = h2_sctl,
.show_fd = h2_show_fd,
.show_sd = h2_show_sd,
.takeover = h2_takeover,

View File

@ -795,6 +795,21 @@ static int mux_pt_ctl(struct connection *conn, enum mux_ctl_type mux_ctl, void *
}
}
static int mux_pt_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
{
int ret = 0;
switch (mux_sctl) {
case MUX_SCTL_SID:
if (output)
*((int64_t *)output) = 0;
return ret;
default:
return -1;
}
}
/* The mux operations */
const struct mux_ops mux_tcp_ops = {
.init = mux_pt_init,
@ -814,6 +829,7 @@ const struct mux_ops mux_tcp_ops = {
.used_streams = mux_pt_used_streams,
.destroy = mux_pt_destroy_meth,
.ctl = mux_pt_ctl,
.sctl = mux_pt_sctl,
.shutr = mux_pt_shutr,
.shutw = mux_pt_shutw,
.flags = MX_FL_NONE,
@ -839,6 +855,7 @@ const struct mux_ops mux_pt_ops = {
.used_streams = mux_pt_used_streams,
.destroy = mux_pt_destroy_meth,
.ctl = mux_pt_ctl,
.sctl = mux_pt_sctl,
.shutr = mux_pt_shutr,
.shutw = mux_pt_shutw,
.flags = MX_FL_NONE|MX_FL_NO_UPG,

View File

@ -2976,6 +2976,22 @@ static void qmux_strm_shutw(struct stconn *sc, enum co_shw_mode mode)
TRACE_LEAVE(QMUX_EV_STRM_SHUT, qcc->conn, qcs);
}
static int qmux_sctl(struct stconn *sc, enum mux_sctl_type mux_sctl, void *output)
{
int ret = 0;
struct qcs *qcs = __sc_mux_strm(sc);
switch (mux_sctl) {
case MUX_SCTL_SID:
if (output)
*((int64_t *)output) = qcs->id;
return ret;
default:
return -1;
}
}
/* for debugging with CLI's "show sess" command. May emit multiple lines, each
* new one being prefixed with <pfx>, if <pfx> is not NULL, otherwise a single
* line is used. Each field starts with a space so it's safe to print it after
@ -3016,6 +3032,7 @@ static const struct mux_ops qmux_ops = {
.unsubscribe = qmux_strm_unsubscribe,
.wake = qmux_wake,
.shutw = qmux_strm_shutw,
.sctl = qmux_sctl,
.show_sd = qmux_strm_show_sd,
.flags = MX_FL_HTX|MX_FL_NO_UPG|MX_FL_FRAMED,
.name = "QUIC",