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.
This commit is contained in:
Amaury Denoyelle 2022-12-01 16:20:06 +01:00
parent b2bd83972b
commit d3083c9df9
3 changed files with 19 additions and 4 deletions

View File

@ -63,7 +63,7 @@ static inline char qc_test_fd(struct quic_conn *qc)
void qc_alloc_fd(struct quic_conn *qc, const struct sockaddr_storage *src,
const struct sockaddr_storage *dst);
void qc_release_fd(struct quic_conn *qc);
void qc_release_fd(struct quic_conn *qc, int reinit);
void quic_accept_push_qc(struct quic_conn *qc);

View File

@ -4960,7 +4960,7 @@ void quic_conn_release(struct quic_conn *qc)
BUG_ON(qc->mux_state == QC_MUX_READY);
/* Close quic-conn socket fd. */
qc_release_fd(qc);
qc_release_fd(qc, 0);
/* in the unlikely (but possible) case the connection was just added to
* the accept_list we must delete it from there.
@ -6369,6 +6369,16 @@ static int qc_handle_conn_migration(struct quic_conn *qc,
* peer's address, unless it has previously validated that address.
*/
/* Update quic-conn owned socket if in used.
* TODO try to reuse it instead of closing and opening a new one.
*/
if (qc_test_fd(qc)) {
/* TODO try to reuse socket instead of closing it and opening a new one. */
TRACE_STATE("Connection migration detected, allocate a new connection socket", QUIC_EV_CONN_LPKT, qc);
qc_release_fd(qc, 1);
qc_alloc_fd(qc, local_addr, peer_addr);
}
qc->local_addr = *local_addr;
qc->peer_addr = *peer_addr;
HA_ATOMIC_INC(&qc->prx_counters->conn_migration_done);

View File

@ -748,12 +748,17 @@ void qc_alloc_fd(struct quic_conn *qc, const struct sockaddr_storage *src,
close(fd);
}
/* Release socket file-descriptor specific for QUIC connection <qc>. */
void qc_release_fd(struct quic_conn *qc)
/* Release socket file-descriptor specific for QUIC connection <qc>. Set
* <reinit> if socket should be reinitialized after address migration.
*/
void qc_release_fd(struct quic_conn *qc, int reinit)
{
if (qc_test_fd(qc)) {
fd_delete(qc->fd);
qc->fd = DEAD_FD_MAGIC;
if (reinit)
qc_init_fd(qc);
}
}