]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: reconnect quic-conn socket on address migration
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 1 Dec 2022 15:20:06 +0000 (16:20 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 2 Dec 2022 13:45:43 +0000 (14:45 +0100)
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.

include/haproxy/quic_sock.h
src/quic_conn.c
src/quic_sock.c

index f7b0eb5eb203369a0a8100ada9740f05edf8b3c8..55ea170a18c06b321fe1ce0895a796bda23678e9 100644 (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);
 
index f86ad4b2a0bd17e50aff2d2e720c1fcbb981eabf..0fc2f5eb9a15ab66c22d52637956ec0e4e8fc243 100644 (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);
index 284c9614d4b67dfb31b003e498fac0e22d183f44..cbd5e77d6ece0868a085efee6979edbe44462fcc 100644 (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);
        }
 }