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.
This commit is contained in:
Frédéric Lécaille 2022-01-27 11:31:50 +01:00 committed by Amaury Denoyelle
parent 794d068d8f
commit 37ae505c21
4 changed files with 35 additions and 8 deletions

View File

@ -250,6 +250,7 @@ extern struct pool_head *pool_head_quic_rxbuf;
extern struct pool_head *pool_head_quic_rx_packet; extern struct pool_head *pool_head_quic_rx_packet;
extern struct pool_head *pool_head_quic_tx_packet; extern struct pool_head *pool_head_quic_tx_packet;
extern struct pool_head *pool_head_quic_frame; extern struct pool_head *pool_head_quic_frame;
extern struct pool_head *pool_head_quic_dgram;
/* QUIC connection id data. /* QUIC connection id data.
* *

View File

@ -1185,8 +1185,9 @@ void chunk_frm_appendf(struct buffer *buf, const struct quic_frame *frm);
void quic_set_tls_alert(struct quic_conn *qc, int alert); void quic_set_tls_alert(struct quic_conn *qc, int alert);
int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len); int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alpn_len);
struct task *quic_lstnr_dghdlr(struct task *t, void *ctx, unsigned int state); struct task *quic_lstnr_dghdlr(struct task *t, void *ctx, unsigned int state);
int quic_lstnr_dgram_read(unsigned char *buf, size_t len, void *owner, int quic_lstnr_dgram_dispatch(unsigned char *buf, size_t len, void *owner,
struct sockaddr_storage *saddr, struct list *dgrams); struct sockaddr_storage *saddr,
struct quic_dgram *new_dgram, struct list *dgrams);
#endif /* USE_QUIC */ #endif /* USE_QUIC */
#endif /* _HAPROXY_XPRT_QUIC_H */ #endif /* _HAPROXY_XPRT_QUIC_H */

View File

@ -175,6 +175,7 @@ void quic_sock_fd_iocb(int fd)
struct sockaddr_storage saddr = {0}; struct sockaddr_storage saddr = {0};
size_t max_sz; size_t max_sz;
socklen_t saddrlen; socklen_t saddrlen;
struct quic_dgram *dgram, *dgramp, *new_dgram;
BUG_ON(!l); BUG_ON(!l);
@ -187,8 +188,23 @@ void quic_sock_fd_iocb(int fd)
rxbuf = MT_LIST_POP(&l->rx.rxbuf_list, typeof(rxbuf), mt_list); rxbuf = MT_LIST_POP(&l->rx.rxbuf_list, typeof(rxbuf), mt_list);
if (!rxbuf) if (!rxbuf)
goto out; goto out;
buf = &rxbuf->buf; 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; params = &l->bind_conf->quic_params;
max_sz = params->max_udp_payload_size; max_sz = params->max_udp_payload_size;
if (b_contig_space(buf) < max_sz) { if (b_contig_space(buf) < max_sz) {
@ -212,9 +228,11 @@ void quic_sock_fd_iocb(int fd)
} while (0); } while (0);
b_add(buf, ret); b_add(buf, ret);
quic_lstnr_dgram_read((unsigned char *)b_head(buf), ret, if (!quic_lstnr_dgram_dispatch((unsigned char *)b_head(buf), ret,
l, &saddr, &rxbuf->dgrams); l, &saddr, new_dgram, &rxbuf->dgrams)) {
b_del(buf, ret); /* If wrong, consume this datagram */
b_del(buf, ret);
}
out: out:
MT_LIST_APPEND(&l->rx.rxbuf_list, &rxbuf->mt_list); MT_LIST_APPEND(&l->rx.rxbuf_list, &rxbuf->mt_list);
} }

View File

@ -5403,6 +5403,8 @@ struct task *quic_lstnr_dghdlr(struct task *t, void *ctx, unsigned int state)
/* If the packet length could not be found, we cannot continue. */ /* If the packet length could not be found, we cannot continue. */
break; break;
} while (pos < end); } while (pos < end);
/* Mark this datagram as consumed */
HA_ATOMIC_STORE(&dgram->buf, NULL);
/* Increasing the received bytes counter by the UDP datagram length /* Increasing the received bytes counter by the UDP datagram length
* if this datagram could be associated to a connection. * if this datagram could be associated to a connection.
@ -5449,8 +5451,13 @@ static int quic_get_dgram_dcid(unsigned char *buf, const unsigned char *end,
return 0; return 0;
} }
int quic_lstnr_dgram_read(unsigned char *buf, size_t len, void *owner, /* Retrieve the DCID from the datagram found in <buf> and deliver it to the
struct sockaddr_storage *saddr, struct list *dgrams) * correct datagram handler.
* Return 1 if a correct datagram could be found, 0 if not.
*/
int quic_lstnr_dgram_dispatch(unsigned char *buf, size_t len, void *owner,
struct sockaddr_storage *saddr,
struct quic_dgram *new_dgram, struct list *dgrams)
{ {
struct quic_dgram *dgram; struct quic_dgram *dgram;
unsigned char *dcid; unsigned char *dcid;
@ -5461,7 +5468,7 @@ int quic_lstnr_dgram_read(unsigned char *buf, size_t len, void *owner,
if (!len || !quic_get_dgram_dcid(buf, buf + len, &dcid, &dcid_len)) if (!len || !quic_get_dgram_dcid(buf, buf + len, &dcid, &dcid_len))
goto err; goto err;
dgram = pool_alloc(pool_head_quic_dgram); dgram = new_dgram ? new_dgram : pool_alloc(pool_head_quic_dgram);
if (!dgram) if (!dgram)
goto err; goto err;