]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: Remove old TX buffer implementation
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 6 Jul 2021 15:19:44 +0000 (17:19 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Sep 2021 13:27:25 +0000 (15:27 +0200)
We use only ring buffers (struct qring) to prepare and send QUIC datagrams.
We can safely remove the old buffering implementation which was not thread safe.

include/haproxy/xprt_quic-t.h
include/haproxy/xprt_quic.h
src/xprt_quic.c

index 6c31c21e43179cb4e9f0c379540b0a12379dd0dd..b5e7cad53031dbfdef7596fe98d60ef6fd1d7c4e 100644 (file)
@@ -623,8 +623,6 @@ struct quic_conn {
                /* The remaining frames to send. */
                struct list frms_to_send;
 
-               /* Array of buffers. */
-               struct q_buf **bufs;
                /* The size of the previous array. */
                size_t nb_buf;
                /* Writer index. */
index 8a82b3754a4e8e2b21d294ac40cf18c35f34e327..92091778ffaee1c24e341cbd326b0b9888e61791 100644 (file)
@@ -1009,77 +1009,6 @@ static inline int c_buf_consumed(struct quic_enc_level *qel)
        return qel->tx.crypto.offset == qel->tx.crypto.sz;
 }
 
-
-/* QUIC buffer handling functions */
-
-/* Returns the current buffer which may be used to build outgoing packets. */
-static inline struct q_buf *q_wbuf(struct quic_conn *qc)
-{
-       return qc->tx.bufs[qc->tx.wbuf];
-}
-
-static inline struct q_buf *q_rbuf(struct quic_conn *qc)
-{
-       return qc->tx.bufs[qc->tx.rbuf];
-}
-
-/* Returns the next buffer to be used to send packets from. */
-static inline struct q_buf *q_next_rbuf(struct quic_conn *qc)
-{
-       qc->tx.rbuf = (qc->tx.rbuf + 1) & (QUIC_CONN_TX_BUFS_NB - 1);
-       return q_rbuf(qc);
-}
-
-/* Return the next buffer which may be used to build outgoing packets.
- * Also decrement by one the number of remaining probing datagrams
- * which may be sent.
- */
-static inline struct q_buf *q_next_wbuf(struct quic_conn *qc)
-{
-       qc->tx.wbuf = (qc->tx.wbuf + 1) & (QUIC_CONN_TX_BUFS_NB - 1);
-       /* Decrement the number of prepared datagrams (only when probing). */
-       if (qc->tx.nb_pto_dgrams)
-               --qc->tx.nb_pto_dgrams;
-       return q_wbuf(qc);
-}
-
-/* Return the position of <buf> buffer to be used to write outgoing packets. */
-static inline unsigned char *q_buf_getpos(struct q_buf *buf)
-{
-       return buf->pos;
-}
-
-/* Return the pointer to one past the end of <buf> buffer. */
-static inline const unsigned char *q_buf_end(struct q_buf *buf)
-{
-       return buf->end;
-}
-
-/* Set the position of <buf> buffer to <pos> value. */
-static inline void q_buf_setpos(struct q_buf *buf, unsigned char *pos)
-{
-       buf->pos = pos;
-}
-
-/* Returns the remaining amount of room left in <buf> buffer. */
-static inline ssize_t q_buf_room(struct q_buf *buf)
-{
-       return q_buf_end(buf) - q_buf_getpos(buf);
-}
-
-/* Reset (or empty) <buf> buffer to prepare it for the next writing. */
-static inline void q_buf_reset(struct q_buf *buf)
-{
-       buf->pos = buf->area;
-       buf->data = 0;
-}
-
-/* Returns 1 if <buf> is empty, 0 if not. */
-static inline int q_buf_empty(struct q_buf *buf)
-{
-       return !buf->data;
-}
-
 /* Return 1 if <pkt> header form is long, 0 if not. */
 static inline int qc_pkt_long(const struct quic_rx_packet *pkt)
 {
index d5dcd37690163439746ade21c8b23f430d66c99b..8340be6afc07226f4cb98d4c2668ce469927d4ee 100644 (file)
@@ -2741,66 +2741,6 @@ static int quic_conn_enc_level_init(struct quic_conn *qc,
        return 0;
 }
 
-/* Release the memory allocated for <buf> array of buffers, with <nb> as size.
- * Never fails.
- */
-static inline void free_quic_conn_tx_bufs(struct q_buf **bufs, size_t nb)
-{
-       struct q_buf **p;
-
-       if (!bufs)
-               return;
-
-       p = bufs;
-       while (--nb) {
-               if (!*p) {
-                       p++;
-                       continue;
-               }
-               ha_free(&(*p)->area);
-               ha_free(p);
-               p++;
-       }
-       free(bufs);
-}
-
-/* Allocate an array or <nb> buffers of <sz> bytes each.
- * Return this array if succeeded, NULL if failed.
- */
-static inline struct q_buf **quic_conn_tx_bufs_alloc(size_t nb, size_t sz)
-{
-       int i;
-       struct q_buf **bufs, **p;
-
-       bufs = calloc(nb, sizeof *bufs);
-       if (!bufs)
-               return NULL;
-
-       i = 0;
-       p = bufs;
-       while (i++ < nb) {
-               *p = calloc(1, sizeof **p);
-               if (!*p)
-                       goto err;
-
-               (*p)->area = malloc(sz);
-               if (!(*p)->area)
-                   goto err;
-
-               (*p)->pos = (*p)->area;
-               (*p)->end = (*p)->area + sz;
-               (*p)->data = 0;
-               LIST_INIT(&(*p)->pkts);
-               p++;
-       }
-
-       return bufs;
-
- err:
-       free_quic_conn_tx_bufs(bufs, nb);
-       return NULL;
-}
-
 /* Release all the memory allocated for <conn> QUIC connection. */
 static void quic_conn_free(struct quic_conn *conn)
 {
@@ -2812,7 +2752,6 @@ static void quic_conn_free(struct quic_conn *conn)
        free_quic_conn_cids(conn);
        for (i = 0; i < QUIC_TLS_ENC_LEVEL_MAX; i++)
                quic_conn_enc_level_uninit(&conn->els[i]);
-       free_quic_conn_tx_bufs(conn->tx.bufs, conn->tx.nb_buf);
        if (conn->timer_task)
                task_destroy(conn->timer_task);
        pool_free(pool_head_quic_conn, conn);
@@ -2938,15 +2877,9 @@ static struct quic_conn *qc_new_conn(unsigned int version, int ipv4,
                qc->els[i].pktns = &qc->pktns[quic_tls_pktns(i)];
        }
 
+       qc->version = version;
        /* TX part. */
        LIST_INIT(&qc->tx.frms_to_send);
-       qc->tx.bufs = quic_conn_tx_bufs_alloc(QUIC_CONN_TX_BUFS_NB, QUIC_CONN_TX_BUF_SZ);
-       if (!qc->tx.bufs) {
-               TRACE_PROTO("Could not allocate TX bufs", QUIC_EV_CONN_INIT);
-               goto err;
-       }
-
-       qc->version = version;
        qc->tx.nb_buf = QUIC_CONN_TX_BUFS_NB;
        qc->tx.wbuf = qc->tx.rbuf = 0;
        qc->tx.bytes = 0;