From: Frédéric Lécaille Date: Tue, 6 Jul 2021 15:19:44 +0000 (+0200) Subject: MINOR: quic: Remove old TX buffer implementation X-Git-Tag: v2.5-dev8~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8d3f873e8e18bf7c51e738ebc8d7f20edae3fdc;p=thirdparty%2Fhaproxy.git MINOR: quic: Remove old TX buffer implementation 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. --- diff --git a/include/haproxy/xprt_quic-t.h b/include/haproxy/xprt_quic-t.h index 6c31c21e43..b5e7cad530 100644 --- a/include/haproxy/xprt_quic-t.h +++ b/include/haproxy/xprt_quic-t.h @@ -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. */ diff --git a/include/haproxy/xprt_quic.h b/include/haproxy/xprt_quic.h index 8a82b3754a..92091778ff 100644 --- a/include/haproxy/xprt_quic.h +++ b/include/haproxy/xprt_quic.h @@ -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 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 buffer. */ -static inline const unsigned char *q_buf_end(struct q_buf *buf) -{ - return buf->end; -} - -/* Set the position of buffer to 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 buffer. */ -static inline ssize_t q_buf_room(struct q_buf *buf) -{ - return q_buf_end(buf) - q_buf_getpos(buf); -} - -/* Reset (or empty) 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 is empty, 0 if not. */ -static inline int q_buf_empty(struct q_buf *buf) -{ - return !buf->data; -} - /* Return 1 if header form is long, 0 if not. */ static inline int qc_pkt_long(const struct quic_rx_packet *pkt) { diff --git a/src/xprt_quic.c b/src/xprt_quic.c index d5dcd37690..8340be6afc 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -2741,66 +2741,6 @@ static int quic_conn_enc_level_init(struct quic_conn *qc, return 0; } -/* Release the memory allocated for array of buffers, with 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 buffers of 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 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;