MINOR: quic: Do not consume the RX buffer on QUIC sock i/o handler side
Rename quic_lstnr_dgram_read() to quic_lstnr_dgram_dispatch() to reflect its new role.
After calling this latter, the sock i/o handler must consume the buffer only if
the datagram it received is detected as wrong by quic_lstnr_dgram_dispatch().
The datagram handler task mark the datagram as consumed atomically setting ->buf
to NULL value. The sock i/o handler is responsible of flushing its RX buffer
before using it. It also keeps a datagram among the consumed ones so that
to pass it to quic_lstnr_dgram_dispatch() and prevent it from allocating a new one.
diff --git a/src/quic_sock.c b/src/quic_sock.c
index ef03908..468cf64 100644
--- a/src/quic_sock.c
+++ b/src/quic_sock.c
@@ -175,6 +175,7 @@
struct sockaddr_storage saddr = {0};
size_t max_sz;
socklen_t saddrlen;
+ struct quic_dgram *dgram, *dgramp, *new_dgram;
BUG_ON(!l);
@@ -187,8 +188,23 @@
rxbuf = MT_LIST_POP(&l->rx.rxbuf_list, typeof(rxbuf), mt_list);
if (!rxbuf)
goto out;
+
buf = &rxbuf->buf;
+ new_dgram = NULL;
+ /* Remove all consumed datagrams of this buffer */
+ list_for_each_entry_safe(dgram, dgramp, &rxbuf->dgrams, list) {
+ if (HA_ATOMIC_LOAD(&dgram->buf))
+ break;
+
+ LIST_DELETE(&dgram->list);
+ b_del(buf, dgram->len);
+ if (!new_dgram)
+ new_dgram = dgram;
+ else
+ pool_free(pool_head_quic_dgram, dgram);
+ }
+
params = &l->bind_conf->quic_params;
max_sz = params->max_udp_payload_size;
if (b_contig_space(buf) < max_sz) {
@@ -212,9 +228,11 @@
} while (0);
b_add(buf, ret);
- quic_lstnr_dgram_read((unsigned char *)b_head(buf), ret,
- l, &saddr, &rxbuf->dgrams);
- b_del(buf, ret);
+ if (!quic_lstnr_dgram_dispatch((unsigned char *)b_head(buf), ret,
+ l, &saddr, new_dgram, &rxbuf->dgrams)) {
+ /* If wrong, consume this datagram */
+ b_del(buf, ret);
+ }
out:
MT_LIST_APPEND(&l->rx.rxbuf_list, &rxbuf->mt_list);
}