From: Frédéric Lécaille Date: Fri, 4 Aug 2023 15:02:25 +0000 (+0200) Subject: MINOR: quic: Move some counters from [rt]x quic_conn anonymous struct X-Git-Tag: v2.9-dev3~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7ab5918d1fb8d00ffd27db6cd3c53ae9b04e11b;p=thirdparty%2Fhaproxy.git MINOR: quic: Move some counters from [rt]x quic_conn anonymous struct Move rx.bytes, tx.bytes and tx.prep_bytes quic_conn struct member to bytes anonymous struct (bytes.rx, bytes.tx and bytes.prep member respectively). They are moved before being defined into a bytes anonoymous struct common to a future struct to be defined. Consequently adapt the code. --- diff --git a/include/haproxy/quic_conn-t.h b/include/haproxy/quic_conn-t.h index 491ec8bb5c..eff1a0d184 100644 --- a/include/haproxy/quic_conn-t.h +++ b/include/haproxy/quic_conn-t.h @@ -510,18 +510,20 @@ struct quic_conn { struct connection *conn; struct { - /* Number of sent bytes. */ - uint64_t bytes; /* Number of bytes for prepared packets */ - uint64_t prep_bytes; + uint64_t prep; + /* Number of sent bytes. */ + uint64_t tx; + /* Number of received bytes. */ + uint64_t rx; + } bytes; + struct { /* Transport parameters sent by the peer */ struct quic_transport_params params; /* Send buffer used to write datagrams. */ struct buffer buf; } tx; struct { - /* Number of received bytes. */ - uint64_t bytes; /* Transport parameters the peer will receive */ struct quic_transport_params params; /* RX buffer */ diff --git a/include/haproxy/quic_conn.h b/include/haproxy/quic_conn.h index 0f4ab0bad3..2f7b36982a 100644 --- a/include/haproxy/quic_conn.h +++ b/include/haproxy/quic_conn.h @@ -474,7 +474,7 @@ static inline size_t quic_path_prep_data(struct quic_path *path) */ static inline size_t quic_may_send_bytes(struct quic_conn *qc) { - return 3 * qc->rx.bytes - qc->tx.prep_bytes; + return 3 * qc->bytes.rx - qc->bytes.prep; } /* CRYPTO data buffer handling functions. */ diff --git a/src/quic_conn.c b/src/quic_conn.c index 5a4fcfaf31..95f4f79b08 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -149,7 +149,7 @@ int quic_peer_validated_addr(struct quic_conn *qc) qc->state >= QUIC_HS_ST_COMPLETE) return 1; - BUG_ON(qc->tx.prep_bytes > 3 * qc->rx.bytes); + BUG_ON(qc->bytes.prep > 3 * qc->bytes.rx); return 0; } @@ -1133,11 +1133,11 @@ struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4, TLS_EXTENSION_QUIC_TRANSPORT_PARAMETERS_DRAFT: TLS_EXTENSION_QUIC_TRANSPORT_PARAMETERS; /* TX part. */ - qc->tx.bytes = qc->tx.prep_bytes = 0; + qc->bytes.tx = qc->bytes.prep = 0; memset(&qc->tx.params, 0, sizeof(qc->tx.params)); qc->tx.buf = BUF_NULL; /* RX part. */ - qc->rx.bytes = 0; + qc->bytes.rx = 0; memset(&qc->rx.params, 0, sizeof(qc->rx.params)); qc->rx.buf = b_make(qc->rx.buf.area, QUIC_CONN_RX_BUFSZ, 0, 0); for (i = 0; i < QCS_MAX_TYPES; i++) diff --git a/src/quic_rx.c b/src/quic_rx.c index 6d38e57545..d28faa5a8d 100644 --- a/src/quic_rx.c +++ b/src/quic_rx.c @@ -2559,7 +2559,7 @@ int quic_dgram_parse(struct quic_dgram *dgram, struct quic_conn *from_qc, * if this datagram could be associated to a connection. */ if (dgram->qc) - dgram->qc->rx.bytes += dgram->len; + dgram->qc->bytes.rx += dgram->len; /* This must never happen. */ BUG_ON(pos > end); diff --git a/src/quic_trace.c b/src/quic_trace.c index c2b2e307dc..372063ba13 100644 --- a/src/quic_trace.c +++ b/src/quic_trace.c @@ -500,9 +500,9 @@ static void quic_trace(enum trace_level level, uint64_t mask, const struct trace (unsigned long)pkt->pn_node.key, quic_pktns_char(qc, pkt->pktns), (unsigned long long)pkt->in_flight_len); - chunk_appendf(&trace_buf, " rx.bytes=%llu tx.bytes=%llu", - (unsigned long long)qc->rx.bytes, - (unsigned long long)qc->tx.bytes); + chunk_appendf(&trace_buf, " bytes.rx=%llu bytes.tx=%llu", + (unsigned long long)qc->bytes.rx, + (unsigned long long)qc->bytes.tx); list_for_each_entry(frm, &pkt->frms, list) { chunk_appendf(&trace_buf, " frm@%p", frm); chunk_frm_appendf(&trace_buf, frm); diff --git a/src/quic_tx.c b/src/quic_tx.c index 4f479596e3..0926486057 100644 --- a/src/quic_tx.c +++ b/src/quic_tx.c @@ -626,7 +626,7 @@ int qc_send_ppkts(struct buffer *buf, struct ssl_sock_ctx *ctx) } b_del(buf, dglen + headlen); - qc->tx.bytes += tmpbuf.data; + qc->bytes.tx += tmpbuf.data; time_sent = now_ms; for (pkt = first_pkt; pkt; pkt = next_pkt) { @@ -2477,8 +2477,8 @@ static struct quic_tx_packet *qc_build_pkt(unsigned char **pos, /* Consume a packet number */ qel->pktns->tx.next_pn++; - qc->tx.prep_bytes += pkt->len; - if (qc->tx.prep_bytes >= 3 * qc->rx.bytes && !quic_peer_validated_addr(qc)) { + qc->bytes.prep += pkt->len; + if (qc->bytes.prep >= 3 * qc->bytes.rx && !quic_peer_validated_addr(qc)) { qc->flags |= QUIC_FL_CONN_ANTI_AMPLIFICATION_REACHED; TRACE_PROTO("anti-amplification limit reached", QUIC_EV_CONN_TXPKT, qc); }