]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: muxes: Implement ->sctl() callback for muxes and return the stream id
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Nov 2023 14:12:51 +0000 (15:12 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 29 Nov 2023 10:11:12 +0000 (11:11 +0100)
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.

src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/mux_quic.c

index 73437be8a74a9998ed3f82b426c11f063b0619b3..0230e6b79d28abd4e730c2f8bde0198ac72599c4 100644 (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,
index 9be77a177e06b0dae99a4c47498f3c2e3f4bd26f..99f3bd51e80eded6c4ca78966e3b3c27d34c3cfe 100644 (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",
index 5f85c00113f5cd785a2a96c9c3d10ada181ceb0a..641b5dafc4fd0776680cfbfcbf061fd794607ddf 100644 (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,
index 47aa5e645a2a7bfd4a3c5f70e4544f1c29bf8f7c..11f47058537a2e3182bfcf8bd32478befda98f55 100644 (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,
index 36e5671a1e1a46144404104c9429912b01381a01..714bc32f9de685e2771ba14d647c902660d126aa 100644 (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",