]> git.kaiwu.me - nginx.git/commitdiff
QUIC: distinct files for connection migration.
authorVladimir Homutov <vl@nginx.com>
Wed, 31 Mar 2021 11:57:15 +0000 (14:57 +0300)
committerVladimir Homutov <vl@nginx.com>
Wed, 31 Mar 2021 11:57:15 +0000 (14:57 +0300)
The connection migration-related code from quic.c with dependencies is moved
into separate file.

auto/modules
src/event/quic/ngx_event_quic.c
src/event/quic/ngx_event_quic_connection.h
src/event/quic/ngx_event_quic_migration.c [new file with mode: 0644]
src/event/quic/ngx_event_quic_migration.h [new file with mode: 0644]

index 079b09bc4954851ccb91638f75bc25cbd51fb7de..0098d4c5491ff7bdd4b7daaa00d84ede0c0a8ed9 100644 (file)
@@ -1342,10 +1342,12 @@ if [ $USE_OPENSSL$USE_OPENSSL_QUIC = YESYES ]; then
     ngx_module_deps="src/event/quic/ngx_event_quic.h \
                      src/event/quic/ngx_event_quic_transport.h \
                      src/event/quic/ngx_event_quic_protection.h \
-                     src/event/quic/ngx_event_quic_connection.h"
+                     src/event/quic/ngx_event_quic_connection.h \
+                     src/event/quic/ngx_event_quic_migration.h"
     ngx_module_srcs="src/event/quic/ngx_event_quic.c \
                      src/event/quic/ngx_event_quic_transport.c \
-                     src/event/quic/ngx_event_quic_protection.c"
+                     src/event/quic/ngx_event_quic_protection.c \
+                     src/event/quic/ngx_event_quic_migration.c"
 
     ngx_module_libs=
     ngx_module_link=YES
index 4fedf755bbbf8e1c7aa8d7ad20b7db92443ac9da..4129aa3163512f9de6927d086be91e5e3d772ef2 100644 (file)
 #include <ngx_event_quic_transport.h>
 #include <ngx_event_quic_protection.h>
 #include <ngx_event_quic_connection.h>
+#include <ngx_event_quic_migration.h>
 #include <ngx_sha1.h>
 
 
-/*  0-RTT and 1-RTT data exist in the same packet number space,
- *  so we have 3 packet number spaces:
- *
- *  0 - Initial
- *  1 - Handshake
- *  2 - 0-RTT and 1-RTT
- */
-#define ngx_quic_get_send_ctx(qc, level)                                      \
-    ((level) == ssl_encryption_initial) ? &((qc)->send_ctx[0])                \
-        : (((level) == ssl_encryption_handshake) ? &((qc)->send_ctx[1])       \
-                                                 : &((qc)->send_ctx[2]))
-
 #define ngx_quic_lost_threshold(qc)                                           \
     ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt),     \
             NGX_QUIC_TIME_GRANULARITY)
@@ -141,8 +130,6 @@ static ngx_int_t ngx_quic_handle_ack_frame_range(ngx_connection_t *c,
     ngx_msec_t *send_time);
 static void ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack,
     enum ssl_encryption_level_t level, ngx_msec_t send_time);
-static ngx_inline ngx_msec_t ngx_quic_pto(ngx_connection_t *c,
-    ngx_quic_send_ctx_t *ctx);
 static void ngx_quic_handle_stream_ack(ngx_connection_t *c,
     ngx_quic_frame_t *f);
 
@@ -177,8 +164,6 @@ static ngx_int_t ngx_quic_handle_stop_sending_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f);
 static ngx_int_t ngx_quic_handle_max_streams_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f);
-static ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
-    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f);
 static ngx_int_t ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f);
 static ngx_int_t ngx_quic_retire_connection_id(ngx_connection_t *c,
@@ -2755,6 +2740,17 @@ ngx_quic_handle_frames(ngx_connection_t *c, ngx_quic_header_t *pkt)
 
             break;
 
+        case NGX_QUIC_FT_PATH_RESPONSE:
+
+            if (ngx_quic_handle_path_response_frame(c, pkt,
+                                                    &frame.u.path_response)
+                != NGX_OK)
+            {
+                return NGX_ERROR;
+            }
+
+            break;
+
         case NGX_QUIC_FT_NEW_CONNECTION_ID:
 
             if (ngx_quic_handle_new_connection_id_frame(c, pkt, &frame.u.ncid)
@@ -2776,13 +2772,6 @@ ngx_quic_handle_frames(ngx_connection_t *c, ngx_quic_header_t *pkt)
 
             break;
 
-        case NGX_QUIC_FT_PATH_RESPONSE:
-
-            /* TODO: handle */
-            ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                           "quic frame handler not implemented");
-            break;
-
         default:
             ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
                            "quic missing frame handler");
@@ -3510,7 +3499,7 @@ ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack,
 }
 
 
-static ngx_inline ngx_msec_t
+ngx_msec_t
 ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
 {
     ngx_msec_t              duration;
@@ -4377,30 +4366,6 @@ ngx_quic_handle_max_streams_frame(ngx_connection_t *c,
 }
 
 
-static ngx_int_t
-ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
-    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f)
-{
-    ngx_quic_frame_t       *frame;
-    ngx_quic_connection_t  *qc;
-
-    qc = ngx_quic_get_connection(c);
-
-    frame = ngx_quic_alloc_frame(c);
-    if (frame == NULL) {
-        return NGX_ERROR;
-    }
-
-    frame->level = pkt->level;
-    frame->type = NGX_QUIC_FT_PATH_RESPONSE;
-    frame->u.path_response = *f;
-
-    ngx_quic_queue_frame(qc, frame);
-
-    return NGX_OK;
-}
-
-
 static ngx_int_t
 ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c,
     ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f)
index 298857a83bcba4a95fa670cd62f1774cba78b0b9..acbec5133504b173e221b4c7185ad9369fcdd044 100644 (file)
 
 typedef struct ngx_quic_connection_s  ngx_quic_connection_t;
 
+/*  0-RTT and 1-RTT data exist in the same packet number space,
+ *  so we have 3 packet number spaces:
+ *
+ *  0 - Initial
+ *  1 - Handshake
+ *  2 - 0-RTT and 1-RTT
+ */
+#define ngx_quic_get_send_ctx(qc, level)                                      \
+    ((level) == ssl_encryption_initial) ? &((qc)->send_ctx[0])                \
+        : (((level) == ssl_encryption_handshake) ? &((qc)->send_ctx[1])       \
+                                                 : &((qc)->send_ctx[2]))
+
 
 typedef struct {
     ngx_queue_t                       queue;
@@ -175,5 +187,6 @@ struct ngx_quic_connection_s {
 ngx_quic_frame_t *ngx_quic_alloc_frame(ngx_connection_t *c);
 void ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame);
 void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc);
+ngx_msec_t ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx);
 
 #endif
diff --git a/src/event/quic/ngx_event_quic_migration.c b/src/event/quic/ngx_event_quic_migration.c
new file mode 100644 (file)
index 0000000..de3d688
--- /dev/null
@@ -0,0 +1,46 @@
+
+/*
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_event.h>
+#include <ngx_event_quic_transport.h>
+#include <ngx_event_quic_connection.h>
+#include <ngx_event_quic_migration.h>
+
+
+ngx_int_t
+ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
+    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f)
+{
+    ngx_quic_frame_t       *frame;
+    ngx_quic_connection_t  *qc;
+
+    qc = ngx_quic_get_connection(c);
+
+    frame = ngx_quic_alloc_frame(c);
+    if (frame == NULL) {
+        return NGX_ERROR;
+    }
+
+    frame->level = pkt->level;
+    frame->type = NGX_QUIC_FT_PATH_RESPONSE;
+    frame->u.path_response = *f;
+
+    ngx_quic_queue_frame(qc, frame);
+
+    return NGX_OK;
+}
+
+
+ngx_int_t
+ngx_quic_handle_path_response_frame(ngx_connection_t *c,
+    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f)
+{
+    /* TODO */
+    return NGX_OK;
+}
+
diff --git a/src/event/quic/ngx_event_quic_migration.h b/src/event/quic/ngx_event_quic_migration.h
new file mode 100644 (file)
index 0000000..3231b7e
--- /dev/null
@@ -0,0 +1,20 @@
+
+/*
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#ifndef _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_
+#define _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
+    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f);
+ngx_int_t ngx_quic_handle_path_response_frame(ngx_connection_t *c,
+    ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f);
+
+#endif