]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: quic: Move qc_handle_conn_migration() to quic_conn.c
authorFrédéric Lécaille <flecaille@haproxy.com>
Mon, 27 Nov 2023 15:56:50 +0000 (16:56 +0100)
committerFrédéric Lécaille <flecaille@haproxy.com>
Tue, 28 Nov 2023 14:37:50 +0000 (15:37 +0100)
This function manipulates only quic_conn objects. Its location is definitively
in quic_conn.c.

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

index 3ef4febcb8b91106d5d16668c2afe3837901e197..73d178940c426d39ddbee37c048e1ca441147181 100644 (file)
@@ -181,6 +181,9 @@ int quic_dgram_parse(struct quic_dgram *dgram, struct quic_conn *qc,
 
 int qc_set_tid_affinity(struct quic_conn *qc, uint new_tid, struct listener *new_li);
 void qc_finalize_affinity_rebind(struct quic_conn *qc);
+int qc_handle_conn_migration(struct quic_conn *qc,
+                             const struct sockaddr_storage *peer_addr,
+                             const struct sockaddr_storage *local_addr);
 
 /* Function pointer that can be used to compute a hash from first generated CID (derived from ODCID) */
 extern uint64_t (*quic_hash64_from_cid)(const unsigned char *cid, int size, const unsigned char *secret, size_t secretlen);
index 14d9c9a2ce543b2ad27ed247e4d0fecb55150dc3..4d599fadeee5d9fa80adad256a0684afe18cf601 100644 (file)
@@ -1181,6 +1181,74 @@ struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4,
        return NULL;
 }
 
+/* React to a connection migration initiated on <qc> by a client with the new
+ * path addresses <peer_addr>/<local_addr>.
+ *
+ * Returns 0 on success else non-zero.
+ */
+int qc_handle_conn_migration(struct quic_conn *qc,
+                             const struct sockaddr_storage *peer_addr,
+                             const struct sockaddr_storage *local_addr)
+{
+       TRACE_ENTER(QUIC_EV_CONN_LPKT, qc);
+
+       /* RFC 9000. Connection Migration
+        *
+        * If the peer sent the disable_active_migration transport parameter,
+        * an endpoint also MUST NOT send packets (including probing packets;
+        * see Section 9.1) from a different local address to the address the peer
+        * used during the handshake, unless the endpoint has acted on a
+        * preferred_address transport parameter from the peer.
+        */
+       if (qc->li->bind_conf->quic_params.disable_active_migration) {
+               TRACE_ERROR("Active migration was disabled, datagram dropped", QUIC_EV_CONN_LPKT, qc);
+               goto err;
+       }
+
+       /* RFC 9000 9. Connection Migration
+        *
+        * The design of QUIC relies on endpoints retaining a stable address for
+        * the duration of the handshake.  An endpoint MUST NOT initiate
+        * connection migration before the handshake is confirmed, as defined in
+        * Section 4.1.2 of [QUIC-TLS].
+        */
+       if (qc->state < QUIC_HS_ST_COMPLETE) {
+               TRACE_STATE("Connection migration during handshake rejected", QUIC_EV_CONN_LPKT, qc);
+               goto err;
+       }
+
+       /* RFC 9000 9. Connection Migration
+        *
+        * TODO
+        * An endpoint MUST
+        * perform path validation (Section 8.2) if it detects any change to a
+        * 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);
+               /* TODO need to adjust <jobs> on socket allocation failure. */
+               qc_alloc_fd(qc, local_addr, peer_addr);
+       }
+
+       qc->local_addr = *local_addr;
+       qc->peer_addr = *peer_addr;
+       qc->cntrs.conn_migration_done++;
+
+       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
+       return 0;
+
+ err:
+       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
+       return 1;
+}
+
+
 /* Update the proxy counters of <qc> QUIC connection from its counters */
 static inline void quic_conn_prx_cntrs_update(struct quic_conn *qc)
 {
index 995755012036d931e98d6b79e754a0d08bd1cd96..368b2ac01ea70d1b425d76b9b8df3ee55abfe487 100644 (file)
@@ -2195,73 +2195,6 @@ static int qc_rx_check_closing(struct quic_conn *qc,
        return 1;
 }
 
-/* React to a connection migration initiated on <qc> by a client with the new
- * path addresses <peer_addr>/<local_addr>.
- *
- * Returns 0 on success else non-zero.
- */
-static int qc_handle_conn_migration(struct quic_conn *qc,
-                                    const struct sockaddr_storage *peer_addr,
-                                    const struct sockaddr_storage *local_addr)
-{
-       TRACE_ENTER(QUIC_EV_CONN_LPKT, qc);
-
-       /* RFC 9000. Connection Migration
-        *
-        * If the peer sent the disable_active_migration transport parameter,
-        * an endpoint also MUST NOT send packets (including probing packets;
-        * see Section 9.1) from a different local address to the address the peer
-        * used during the handshake, unless the endpoint has acted on a
-        * preferred_address transport parameter from the peer.
-        */
-       if (qc->li->bind_conf->quic_params.disable_active_migration) {
-               TRACE_ERROR("Active migration was disabled, datagram dropped", QUIC_EV_CONN_LPKT, qc);
-               goto err;
-       }
-
-       /* RFC 9000 9. Connection Migration
-        *
-        * The design of QUIC relies on endpoints retaining a stable address for
-        * the duration of the handshake.  An endpoint MUST NOT initiate
-        * connection migration before the handshake is confirmed, as defined in
-        * Section 4.1.2 of [QUIC-TLS].
-        */
-       if (qc->state < QUIC_HS_ST_COMPLETE) {
-               TRACE_STATE("Connection migration during handshake rejected", QUIC_EV_CONN_LPKT, qc);
-               goto err;
-       }
-
-       /* RFC 9000 9. Connection Migration
-        *
-        * TODO
-        * An endpoint MUST
-        * perform path validation (Section 8.2) if it detects any change to a
-        * 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);
-               /* TODO need to adjust <jobs> on socket allocation failure. */
-               qc_alloc_fd(qc, local_addr, peer_addr);
-       }
-
-       qc->local_addr = *local_addr;
-       qc->peer_addr = *peer_addr;
-       qc->cntrs.conn_migration_done++;
-
-       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
-       return 0;
-
- err:
-       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
-       return 1;
-}
-
 /* Release the memory for the RX packets which are no more referenced
  * and consume their payloads which have been copied to the RX buffer
  * for the connection.