changeset 8769:9ec3e71f8a61 quic

HTTP/3: reference h3c directly from ngx_http_connection_t. Previously, an ngx_http_v3_connection_t object was created for HTTP/3 and then assinged to c->data instead of the generic ngx_http_connection_t object. Now a direct reference is added to ngx_http_connection_t, which is less confusing and does not require a flag for http3.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 05 May 2021 14:53:36 +0300
parents 40d710a66aef
children 67f0eb150047
files src/http/modules/ngx_http_quic_module.c src/http/modules/ngx_http_quic_module.h src/http/ngx_http.h src/http/ngx_http_request.h src/http/v3/ngx_http_v3.h src/http/v3/ngx_http_v3_streams.c src/http/v3/ngx_http_v3_tables.c
diffstat 7 files changed, 30 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/modules/ngx_http_quic_module.c
+++ b/src/http/modules/ngx_http_quic_module.c
@@ -201,7 +201,7 @@ ngx_http_quic_init(ngx_connection_t *c)
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http init quic stream");
 
-    phc = c->quic->parent->data;
+    phc = ngx_http_quic_get_connection(c);
 
     if (phc->ssl_servername) {
         hc->ssl_servername = phc->ssl_servername;
--- a/src/http/modules/ngx_http_quic_module.h
+++ b/src/http/modules/ngx_http_quic_module.h
@@ -18,6 +18,10 @@
 #define NGX_HTTP_QUIC_ALPN_DRAFT_FMT  "\x05hq-%02uD"
 
 
+#define ngx_http_quic_get_connection(c)                                       \
+    ((ngx_http_connection_t *) (c)->quic->parent->data)
+
+
 ngx_int_t ngx_http_quic_init(ngx_connection_t *c);
 
 
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -21,6 +21,8 @@ typedef struct ngx_http_log_ctx_s     ng
 typedef struct ngx_http_chunked_s     ngx_http_chunked_t;
 typedef struct ngx_http_v2_stream_s   ngx_http_v2_stream_t;
 typedef struct ngx_http_v3_parse_s    ngx_http_v3_parse_t;
+typedef struct ngx_http_v3_connection_s
+                                      ngx_http_v3_connection_t;
 
 typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r,
     ngx_table_elt_t *h, ngx_uint_t offset);
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -318,6 +318,10 @@ typedef struct {
 #endif
 #endif
 
+#if (NGX_HTTP_V3 || NGX_COMPAT)
+    ngx_http_v3_connection_t         *v3_session;
+#endif
+
     ngx_chain_t                      *busy;
     ngx_int_t                         nbusy;
 
@@ -325,7 +329,6 @@ typedef struct {
 
     unsigned                          ssl:1;
     unsigned                          proxy_protocol:1;
-    unsigned                          http3:1;
 } ngx_http_connection_t;
 
 
--- a/src/http/v3/ngx_http_v3.h
+++ b/src/http/v3/ngx_http_v3.h
@@ -74,18 +74,15 @@
 #define NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR       0x202
 
 
-#define ngx_http_v3_get_session(c)                                            \
-    ((ngx_http_v3_connection_t *) (c)->quic->parent->data)
+#define ngx_http_v3_get_session(c)  ngx_http_quic_get_connection(c)->v3_session
 
 #define ngx_http_v3_get_module_loc_conf(c, module)                            \
-    ngx_http_get_module_loc_conf(                                             \
-           ((ngx_http_v3_connection_t *) c->quic->parent->data)->hc.conf_ctx, \
-           module)
+    ngx_http_get_module_loc_conf(ngx_http_quic_get_connection(c)->conf_ctx,     \
+                                 module)
 
 #define ngx_http_v3_get_module_srv_conf(c, module)                            \
-    ngx_http_get_module_srv_conf(                                             \
-           ((ngx_http_v3_connection_t *) c->quic->parent->data)->hc.conf_ctx, \
-           module)
+    ngx_http_get_module_srv_conf(ngx_http_quic_get_connection(c)->conf_ctx,     \
+                                 module)
 
 #define ngx_http_v3_finalize_connection(c, code, reason)                      \
     ngx_quic_finalize_connection(c->quic->parent, code, reason)
@@ -130,9 +127,7 @@ typedef struct {
 } ngx_http_v3_dynamic_table_t;
 
 
-typedef struct {
-    /* the http connection must be first */
-    ngx_http_connection_t         hc;
+struct ngx_http_v3_connection_s {
     ngx_http_v3_dynamic_table_t   table;
 
     ngx_event_t                   keepalive;
@@ -149,7 +144,7 @@ typedef struct {
     ngx_uint_t                    goaway;  /* unsigned  goaway:1; */
 
     ngx_connection_t             *known_streams[NGX_HTTP_V3_MAX_KNOWN_STREAM];
-} ngx_http_v3_connection_t;
+};
 
 
 void ngx_http_v3_init(ngx_connection_t *c);
--- a/src/http/v3/ngx_http_v3_streams.c
+++ b/src/http/v3/ngx_http_v3_streams.c
@@ -46,13 +46,13 @@ ngx_http_v3_init_session(ngx_connection_
 {
     ngx_connection_t          *pc;
     ngx_pool_cleanup_t        *cln;
-    ngx_http_connection_t     *phc;
+    ngx_http_connection_t     *hc;
     ngx_http_v3_connection_t  *h3c;
 
     pc = c->quic->parent;
-    phc = pc->data;
+    hc = pc->data;
 
-    if (phc->http3) {
+    if (hc->v3_session) {
         return NGX_OK;
     }
 
@@ -63,8 +63,6 @@ ngx_http_v3_init_session(ngx_connection_
         return NGX_ERROR;
     }
 
-    h3c->hc = *phc;
-    h3c->hc.http3 = 1;
     h3c->max_push_id = (uint64_t) -1;
 
     ngx_queue_init(&h3c->blocked);
@@ -83,7 +81,7 @@ ngx_http_v3_init_session(ngx_connection_
     cln->handler = ngx_http_v3_cleanup_session;
     cln->data = h3c;
 
-    pc->data = h3c;
+    hc->v3_session = h3c;
 
     return ngx_http_v3_send_settings(c);
 }
@@ -519,13 +517,10 @@ failed:
 static ngx_int_t
 ngx_http_v3_send_settings(ngx_connection_t *c)
 {
-    u_char                    *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6];
-    size_t                     n;
-    ngx_connection_t          *cc;
-    ngx_http_v3_srv_conf_t    *h3scf;
-    ngx_http_v3_connection_t  *h3c;
-
-    h3c = ngx_http_v3_get_session(c);
+    u_char                  *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6];
+    size_t                   n;
+    ngx_connection_t        *cc;
+    ngx_http_v3_srv_conf_t  *h3scf;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings");
 
@@ -534,7 +529,7 @@ ngx_http_v3_send_settings(ngx_connection
         return NGX_DECLINED;
     }
 
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     n = ngx_http_v3_encode_varlen_int(NULL,
                                       NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY);
--- a/src/http/v3/ngx_http_v3_tables.c
+++ b/src/http/v3/ngx_http_v3_tables.c
@@ -251,7 +251,7 @@ ngx_http_v3_set_capacity(ngx_connection_
                    "http3 set capacity %ui", capacity);
 
     h3c = ngx_http_v3_get_session(c);
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     if (capacity > h3scf->max_table_capacity) {
         ngx_log_error(NGX_LOG_INFO, c->log, 0,
@@ -498,7 +498,7 @@ ngx_http_v3_decode_insert_count(ngx_conn
     h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     max_entries = h3scf->max_table_capacity / 32;
     full_range = 2 * max_entries;
@@ -582,8 +582,7 @@ ngx_http_v3_check_insert_count(ngx_conne
     }
 
     if (block->queue.prev == NULL) {
-        h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx,
-                                             ngx_http_v3_module);
+        h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
         if (h3c->nblocked == h3scf->max_blocked_streams) {
             ngx_log_error(NGX_LOG_INFO, c->log, 0,