summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2021-05-05 14:53:36 +0300
committerRoman Arutyunyan <arut@nginx.com>2021-05-05 14:53:36 +0300
commit38773a3c1130d34715f1cce24527a10258447354 (patch)
tree21ab82b33f79ae8a9a316eb62c7b8df418ec1877
parent82f8734935ef28fbda4450fd88410b7d1f359c62 (diff)
downloadnginx-38773a3c1130d34715f1cce24527a10258447354.tar.gz
nginx-38773a3c1130d34715f1cce24527a10258447354.tar.bz2
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.
-rw-r--r--src/http/modules/ngx_http_quic_module.c2
-rw-r--r--src/http/modules/ngx_http_quic_module.h4
-rw-r--r--src/http/ngx_http.h2
-rw-r--r--src/http/ngx_http_request.h5
-rw-r--r--src/http/v3/ngx_http_v3.h19
-rw-r--r--src/http/v3/ngx_http_v3_streams.c23
-rw-r--r--src/http/v3/ngx_http_v3_tables.c7
7 files changed, 30 insertions, 32 deletions
diff --git a/src/http/modules/ngx_http_quic_module.c b/src/http/modules/ngx_http_quic_module.c
index b7661b42c..2354dfd8b 100644
--- 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;
diff --git a/src/http/modules/ngx_http_quic_module.h b/src/http/modules/ngx_http_quic_module.h
index 21d4a40a1..8cadfbb87 100644
--- 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);
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index f5d772e65..6f2d38d8b 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -21,6 +21,8 @@ typedef struct ngx_http_log_ctx_s ngx_http_log_ctx_t;
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);
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 5231ad6f2..01ae716fe 100644
--- 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;
diff --git a/src/http/v3/ngx_http_v3.h b/src/http/v3/ngx_http_v3.h
index 9ee809fa1..10ea94592 100644
--- 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);
diff --git a/src/http/v3/ngx_http_v3_streams.c b/src/http/v3/ngx_http_v3_streams.c
index 513738469..cf3204edd 100644
--- 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_t *c)
{
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_t *c)
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_t *c)
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_t *c)
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);
diff --git a/src/http/v3/ngx_http_v3_tables.c b/src/http/v3/ngx_http_v3_tables.c
index c2ce14660..46dcc6734 100644
--- 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_t *c, ngx_uint_t capacity)
"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_connection_t *c, ngx_uint_t *insert_count)
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_connection_t *c, ngx_uint_t insert_count)
}
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,