From: Christopher Faulet Date: Tue, 4 Nov 2025 16:46:10 +0000 (+0100) Subject: MINOR: stconn: Add counters to SC to know number of bytes received and sent X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=629fbbce19482879110c1ff13e37ccbcefde9f1d;p=thirdparty%2Fhaproxy.git MINOR: stconn: Add counters to SC to know number of bytes received and sent and counters were added to SC to count, respectively, the number of bytes received from an endpoint or sent to an endpoint. These counters are updated for connections and applets. This patch is related to issue #1617. --- diff --git a/include/haproxy/stconn-t.h b/include/haproxy/stconn-t.h index 2195ea14b..f93c5b6f6 100644 --- a/include/haproxy/stconn-t.h +++ b/include/haproxy/stconn-t.h @@ -377,6 +377,9 @@ struct stconn { * -1 : the SC is waiting for room but not on a specific amount of data * >= 0 : min free space required to progress. 0 means SC must be unblocked ASAP */ + unsigned long long bytes_in; /* total number of bytes received from the SE */ + unsigned long long bytes_out; /* total number of bytes sent to the SE */ + struct wait_event wait_event; /* We're in a wait list */ struct sedesc *sedesc; /* points to the stream endpoint descriptor */ enum obj_type *app; /* points to the applicative point (stream or check) */ diff --git a/src/stconn.c b/src/stconn.c index 4b27e5314..41d0fe396 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -211,6 +211,7 @@ static struct stconn *sc_new(struct sedesc *sedesc) sc->app_ops = NULL; sc->src = NULL; sc->dst = NULL; + sc->bytes_in = sc->bytes_out = 0; sc->wait_event.tasklet = NULL; sc->wait_event.events = 0; @@ -550,6 +551,7 @@ int sc_reset_endp(struct stconn *sc) BUG_ON(sc->sedesc); sc->sedesc = new_sd; sc->sedesc->sc = sc; + sc->bytes_in = sc->bytes_out = 0; sc_ep_set(sc, SE_FL_DETACHED); return 0; } @@ -1352,6 +1354,7 @@ int sc_conn_recv(struct stconn *sc) else if (ret > 0) { if (ic->to_forward != CHN_INFINITE_FORWARD) ic->to_forward -= ret; + sc->bytes_in += ret; ic->total += ret; cur_read += ret; ic->flags |= CF_READ_EVENT; @@ -1454,6 +1457,7 @@ int sc_conn_recv(struct stconn *sc) } ic->flags |= CF_READ_EVENT; + sc->bytes_in += ret; ic->total += ret; /* End-of-input reached, we can leave. In this case, it is @@ -1662,8 +1666,10 @@ int sc_conn_send(struct stconn *sc) send_flag |= CO_SFL_STREAMER; ret = conn->mux->resume_fastfwd(sc, send_flag); - if (ret > 0) + if (ret > 0) { + sc->bytes_out += ret; did_send = 1; + } if (sc_ep_have_ff_data(sc)) goto end; @@ -1736,7 +1742,7 @@ int sc_conn_send(struct stconn *sc) did_send = 1; c_rew(oc, ret); c_realign_if_empty(oc); - + sc->bytes_out += ret; if (!co_data(oc)) { /* Always clear both flags once everything has been sent, they're one-shot */ sc->flags &= ~(SC_FL_SND_ASAP|SC_FL_SND_EXP_MORE); @@ -2032,6 +2038,7 @@ int sc_applet_recv(struct stconn *sc) else if (ret > 0) { if (ic->to_forward != CHN_INFINITE_FORWARD) ic->to_forward -= ret; + sc->bytes_in += ret; ic->total += ret; cur_read += ret; ic->flags |= CF_READ_EVENT; @@ -2115,6 +2122,7 @@ int sc_applet_recv(struct stconn *sc) } ic->flags |= CF_READ_EVENT; + sc->bytes_in += ret; ic->total += ret; /* End-of-input reached, we can leave. In this case, it is @@ -2263,7 +2271,7 @@ int sc_applet_send(struct stconn *sc) did_send = 1; c_rew(oc, ret); c_realign_if_empty(oc); - + sc->bytes_out += ret; if (!co_data(oc)) { /* Always clear both flags once everything has been sent, they're one-shot */ sc->flags &= ~(SC_FL_SND_ASAP|SC_FL_SND_EXP_MORE); diff --git a/src/stream.c b/src/stream.c index ccb3ecd4e..07b6523ad 100644 --- a/src/stream.c +++ b/src/stream.c @@ -299,6 +299,7 @@ int stream_upgrade_from_sc(struct stconn *sc, struct buffer *input) s->req.buf = *input; *input = BUF_NULL; s->req.total = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf)); + s->scf->bytes_in = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf)); sc_ep_report_read_activity(s->scf); } @@ -573,6 +574,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer s->req.buf = *input; *input = BUF_NULL; s->req.total = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf)); + s->scf->bytes_in = (IS_HTX_STRM(s) ? htxbuf(&s->req.buf)->data : b_data(&s->req.buf)); sc_ep_report_read_activity(s->scf); }