Skip to content

Commit d3083c9

Browse files
committed
MINOR: quic: reconnect quic-conn socket on address migration
UDP addresses may change over time for a QUIC connection. When using quic-conn owned socket, we have to detect address change to break the bind/connect association on the socket. For the moment, on change detected, QUIC connection socket is closed and a new one is opened. In the future, we may improve this by trying to keep the original socket and reexecute only bind/connect syscalls. This change is part of quic-conn owned socket implementation. It may be backported to 2.7 after a period of observation.
1 parent b2bd839 commit d3083c9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

include/haproxy/quic_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static inline char qc_test_fd(struct quic_conn *qc)
6363

6464
void qc_alloc_fd(struct quic_conn *qc, const struct sockaddr_storage *src,
6565
const struct sockaddr_storage *dst);
66-
void qc_release_fd(struct quic_conn *qc);
66+
void qc_release_fd(struct quic_conn *qc, int reinit);
6767

6868
void quic_accept_push_qc(struct quic_conn *qc);
6969

src/quic_conn.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4960,7 +4960,7 @@ void quic_conn_release(struct quic_conn *qc)
49604960
BUG_ON(qc->mux_state == QC_MUX_READY);
49614961

49624962
/* Close quic-conn socket fd. */
4963-
qc_release_fd(qc);
4963+
qc_release_fd(qc, 0);
49644964

49654965
/* in the unlikely (but possible) case the connection was just added to
49664966
* the accept_list we must delete it from there.
@@ -6369,6 +6369,16 @@ static int qc_handle_conn_migration(struct quic_conn *qc,
63696369
* peer's address, unless it has previously validated that address.
63706370
*/
63716371

6372+
/* Update quic-conn owned socket if in used.
6373+
* TODO try to reuse it instead of closing and opening a new one.
6374+
*/
6375+
if (qc_test_fd(qc)) {
6376+
/* TODO try to reuse socket instead of closing it and opening a new one. */
6377+
TRACE_STATE("Connection migration detected, allocate a new connection socket", QUIC_EV_CONN_LPKT, qc);
6378+
qc_release_fd(qc, 1);
6379+
qc_alloc_fd(qc, local_addr, peer_addr);
6380+
}
6381+
63726382
qc->local_addr = *local_addr;
63736383
qc->peer_addr = *peer_addr;
63746384
HA_ATOMIC_INC(&qc->prx_counters->conn_migration_done);

src/quic_sock.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,17 @@ void qc_alloc_fd(struct quic_conn *qc, const struct sockaddr_storage *src,
748748
close(fd);
749749
}
750750

751-
/* Release socket file-descriptor specific for QUIC connection <qc>. */
752-
void qc_release_fd(struct quic_conn *qc)
751+
/* Release socket file-descriptor specific for QUIC connection <qc>. Set
752+
* <reinit> if socket should be reinitialized after address migration.
753+
*/
754+
void qc_release_fd(struct quic_conn *qc, int reinit)
753755
{
754756
if (qc_test_fd(qc)) {
755757
fd_delete(qc->fd);
756758
qc->fd = DEAD_FD_MAGIC;
759+
760+
if (reinit)
761+
qc_init_fd(qc);
757762
}
758763
}
759764

0 commit comments

Comments
 (0)