From: Yeonggi Kim Date: Thu, 15 Oct 2026 23:45:52 +0000 (+0900) Subject: MINOR: quic: use the listener for Retry and Version Negotiation emission X-Git-Tag: v3.5-dev10~184 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=4616641fdfb83dbef08aa6e352225530f4198031;p=haproxy.git MINOR: quic: use the listener for Retry and Version Negotiation emission send_retry() and send_version_negotiation() take the listener socket FD as first argument, while send_stateless_reset() takes the listener instance. Make the first two also take the listener instance. Also rename their argument to to remove any ambiguity, as it is the destination of the emitted datagram, and fix send_stateless_reset() comment which still mentioned a FD. This patch does not introduce any functional change. It is a prerequisite for the following fixes on Retry, Stateless Reset and Version Negotiation emission. As such, it should be backported with them up to 2.8. Prior to 2.9, these functions are static functions defined in quic_conn.c. --- diff --git a/include/haproxy/quic_tx.h b/include/haproxy/quic_tx.h index 60d567a72..f68fbc26b 100644 --- a/include/haproxy/quic_tx.h +++ b/include/haproxy/quic_tx.h @@ -47,11 +47,11 @@ int qc_send(struct quic_conn *qc, int old_data, struct list *send_list, int qc_dgrams_retransmit(struct quic_conn *qc); void qc_prep_hdshk_fast_retrans(struct quic_conn *qc, struct list *ifrms, struct list *hfrms); -int send_retry(int fd, struct sockaddr_storage *addr, +int send_retry(struct listener *l, struct sockaddr_storage *dst, struct quic_rx_packet *pkt, const struct quic_version *qv); int send_stateless_reset(struct listener *l, struct sockaddr_storage *dstaddr, struct quic_rx_packet *rxpkt); -int send_version_negotiation(int fd, struct sockaddr_storage *addr, +int send_version_negotiation(struct listener *l, struct sockaddr_storage *dst, struct quic_rx_packet *pkt); /* The TX packets sent in the same datagram are linked to each others in diff --git a/src/quic_rx.c b/src/quic_rx.c index c4411c9cd..fbefac588 100644 --- a/src/quic_rx.c +++ b/src/quic_rx.c @@ -1845,7 +1845,7 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt, /* Validate the token, retry or not only when connection is unknown. */ if (!quic_token_validate(pkt, dgram, l, qc, &token_odcid)) { if (dgram->flags & QUIC_DGRAM_FL_SEND_RETRY) { - if (send_retry(l->rx.fd, (struct sockaddr_storage *)&dgram->saddr, pkt, pkt->version)) { + if (send_retry(l, (struct sockaddr_storage *)&dgram->saddr, pkt, pkt->version)) { TRACE_ERROR("Error during Retry generation", QUIC_EV_CONN_LPKT, NULL, NULL, NULL, pkt->version); } @@ -1875,7 +1875,7 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt, TRACE_PROTO("Initial without token, sending retry", QUIC_EV_CONN_LPKT, NULL, NULL, NULL, pkt->version); - if (send_retry(l->rx.fd, (struct sockaddr_storage *)&dgram->saddr, pkt, pkt->version)) { + if (send_retry(l, (struct sockaddr_storage *)&dgram->saddr, pkt, pkt->version)) { TRACE_ERROR("Error during Retry generation", QUIC_EV_CONN_LPKT, NULL, NULL, NULL, pkt->version); goto out; @@ -2054,7 +2054,7 @@ static int quic_rx_pkt_parse(struct quic_conn *qc, struct quic_rx_packet *pkt, */ if (l && !pkt->version) { /* unsupported version, send Negotiation packet */ - if (send_version_negotiation(l->rx.fd, (struct sockaddr_storage *)&dgram->saddr, pkt)) { + if (send_version_negotiation(l, (struct sockaddr_storage *)&dgram->saddr, pkt)) { TRACE_ERROR("VN packet not sent", QUIC_EV_CONN_LPKT); goto drop_silent; } diff --git a/src/quic_tx.c b/src/quic_tx.c index 43ce8fc57..7339c0a83 100644 --- a/src/quic_tx.c +++ b/src/quic_tx.c @@ -1136,21 +1136,21 @@ int qc_dgrams_retransmit(struct quic_conn *qc) } /* - * Send a Version Negotiation packet on response to on socket to - * address . + * Send a Version Negotiation packet on response to on listener + * socket to address. * Implementation of RFC9000 6. Version Negotiation * * TODO implement a rate-limiting sending of Version Negotiation packets * * Returns 0 on success else non-zero */ -int send_version_negotiation(int fd, struct sockaddr_storage *addr, +int send_version_negotiation(struct listener *l, struct sockaddr_storage *dst, struct quic_rx_packet *pkt) { char buf[256]; int ret = 0, i = 0, j; uint32_t version; - const socklen_t addrlen = get_addr_len(addr); + const socklen_t addrlen = get_addr_len(dst); TRACE_ENTER(QUIC_EV_CONN_TXPKT); /* @@ -1187,7 +1187,7 @@ int send_version_negotiation(int fd, struct sockaddr_storage *addr, i += sizeof(version); } - if (sendto(fd, buf, i, 0, (struct sockaddr *)addr, addrlen) < 0) + if (sendto(l->rx.fd, buf, i, 0, (struct sockaddr *)dst, addrlen) < 0) goto out; ret = 1; @@ -1203,8 +1203,8 @@ int send_version_negotiation(int fd, struct sockaddr_storage *addr, static THREAD_LOCAL struct freq_ctr quic_stateless_reset_freq_ctr; static THREAD_LOCAL uint quic_stateless_reset_rate; -/* Send a stateless reset packet depending on RX packet information - * from UDP socket to +/* Send a stateless reset packet depending on RX packet information + * from listener socket to * Return 1 if succeeded, 0 if not. */ int send_stateless_reset(struct listener *l, struct sockaddr_storage *dstaddr, @@ -1305,18 +1305,18 @@ static inline int quic_pkt_type(int type, uint32_t version) } -/* Generate a Retry packet and send it on socket to in response to - * the Initial packet. +/* Generate a Retry packet and send it on listener socket to in + * response to the Initial packet. * * Returns 0 on success else non-zero. */ -int send_retry(int fd, struct sockaddr_storage *addr, +int send_retry(struct listener *l, struct sockaddr_storage *dst, struct quic_rx_packet *pkt, const struct quic_version *qv) { int ret = 0; unsigned char buf[128]; int i = 0, token_len; - const socklen_t addrlen = get_addr_len(addr); + const socklen_t addrlen = get_addr_len(dst); struct quic_cid scid; TRACE_ENTER(QUIC_EV_CONN_TXPKT); @@ -1348,7 +1348,7 @@ int send_retry(int fd, struct sockaddr_storage *addr, /* token */ if (!(token_len = quic_generate_retry_token(&buf[i], sizeof(buf) - i, qv->num, - &pkt->dcid, &pkt->scid, addr))) { + &pkt->dcid, &pkt->scid, dst))) { TRACE_ERROR("quic_generate_retry_token() failed", QUIC_EV_CONN_TXPKT); goto out; } @@ -1365,7 +1365,7 @@ int send_retry(int fd, struct sockaddr_storage *addr, i += QUIC_TLS_TAG_LEN; - if (sendto(fd, buf, i, 0, (struct sockaddr *)addr, addrlen) < 0) { + if (sendto(l->rx.fd, buf, i, 0, (struct sockaddr *)dst, addrlen) < 0) { TRACE_ERROR("quic_tls_generate_retry_integrity_tag() failed", QUIC_EV_CONN_TXPKT); goto out; }