Mercurial > hg > nginx
annotate src/http/v3/ngx_http_v3_uni.c @ 9279:2fce021888f9
Removed incorrect NGX_SUPPRESS_WARN usage.
The len variable in ngx_http_variable_unknown_header() needs to be
initialized to 0, as it is incremented by subsequent code.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 31 May 2024 04:38:40 +0300 |
parents | f742b1b46901 |
children |
rev | line source |
---|---|
8215 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
14 ngx_http_v3_parse_uni_t parse; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
15 ngx_int_t index; |
8215 | 16 } ngx_http_v3_uni_stream_t; |
17 | |
18 | |
19 static void ngx_http_v3_close_uni_stream(ngx_connection_t *c); | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
20 static void ngx_http_v3_uni_read_handler(ngx_event_t *rev); |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
21 static void ngx_http_v3_uni_dummy_read_handler(ngx_event_t *wev); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
22 static void ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
23 static ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c, |
8215 | 24 ngx_uint_t type); |
8725
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8724
diff
changeset
|
25 |
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8724
diff
changeset
|
26 |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
27 void |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
28 ngx_http_v3_init_uni_stream(ngx_connection_t *c) |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
29 { |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
30 uint64_t n; |
9054
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
31 ngx_http_v3_session_t *h3c; |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
32 ngx_http_v3_uni_stream_t *us; |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
33 |
9054
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
34 h3c = ngx_http_v3_get_session(c); |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
35 if (h3c->hq) { |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
36 ngx_http_v3_finalize_connection(c, |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
37 NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR, |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
38 "uni stream in hq mode"); |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
39 c->data = NULL; |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
40 ngx_http_v3_close_uni_stream(c); |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
41 return; |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
42 } |
6546c2ae1c7b
HTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
43 |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
44 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init uni stream"); |
8215 | 45 |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
46 n = c->quic->id >> 2; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
47 |
8924
d6ef13c5fd8e
QUIC: simplified configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8903
diff
changeset
|
48 if (n >= NGX_HTTP_V3_MAX_UNI_STREAMS) { |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
49 ngx_http_v3_finalize_connection(c, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
50 NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
51 "reached maximum number of uni streams"); |
8903
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
52 c->data = NULL; |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
53 ngx_http_v3_close_uni_stream(c); |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
54 return; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
55 } |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
56 |
9051
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
57 ngx_quic_cancelable_stream(c); |
8724
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
58 |
8215 | 59 us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t)); |
60 if (us == NULL) { | |
8903
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
61 ngx_http_v3_finalize_connection(c, |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
62 NGX_HTTP_V3_ERR_INTERNAL_ERROR, |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
63 "memory allocation error"); |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
64 c->data = NULL; |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
65 ngx_http_v3_close_uni_stream(c); |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
66 return; |
8215 | 67 } |
68 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
69 us->index = -1; |
8215 | 70 |
71 c->data = us; | |
72 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
73 c->read->handler = ngx_http_v3_uni_read_handler; |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
74 c->write->handler = ngx_http_v3_uni_dummy_write_handler; |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
75 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
76 ngx_http_v3_uni_read_handler(c->read); |
8215 | 77 } |
78 | |
79 | |
80 static void | |
81 ngx_http_v3_close_uni_stream(ngx_connection_t *c) | |
82 { | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
83 ngx_pool_t *pool; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
84 ngx_http_v3_session_t *h3c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
85 ngx_http_v3_uni_stream_t *us; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
86 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
87 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream"); |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
88 |
8903
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
89 us = c->data; |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
90 |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
91 if (us && us->index >= 0) { |
0d3bf08eaac0
HTTP/3: allowed QUIC stream connection reuse.
Roman Arutyunyan <arut@nginx.com>
parents:
8902
diff
changeset
|
92 h3c = ngx_http_v3_get_session(c); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
93 h3c->known_streams[us->index] = NULL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
94 } |
8215 | 95 |
96 c->destroyed = 1; | |
97 | |
98 pool = c->pool; | |
99 | |
100 ngx_close_connection(c); | |
101 | |
102 ngx_destroy_pool(pool); | |
103 } | |
104 | |
105 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
106 ngx_int_t |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
107 ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type) |
8215 | 108 { |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
109 ngx_int_t index; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
110 ngx_http_v3_session_t *h3c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
111 ngx_http_v3_uni_stream_t *us; |
8215 | 112 |
8821
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
113 h3c = ngx_http_v3_get_session(c); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
114 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
115 switch (type) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
116 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
117 case NGX_HTTP_V3_STREAM_ENCODER: |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
118 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
119 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
120 "http3 encoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
121 index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
122 break; |
8215 | 123 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
124 case NGX_HTTP_V3_STREAM_DECODER: |
8215 | 125 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
126 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
127 "http3 decoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
128 index = NGX_HTTP_V3_STREAM_CLIENT_DECODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
129 break; |
8215 | 130 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
131 case NGX_HTTP_V3_STREAM_CONTROL: |
8215 | 132 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
133 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
134 "http3 control stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
135 index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
136 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
137 break; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
138 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
139 default: |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
140 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
141 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
142 "http3 stream 0x%02xL", type); |
8821
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
143 |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
144 if (h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_ENCODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
145 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_DECODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
146 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_CONTROL] == NULL) |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
147 { |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
148 ngx_log_error(NGX_LOG_INFO, c->log, 0, "missing mandatory stream"); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
149 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
150 } |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
151 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
152 index = -1; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
153 } |
8215 | 154 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
155 if (index >= 0) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
156 if (h3c->known_streams[index]) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
157 ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
158 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
8215 | 159 } |
160 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
161 h3c->known_streams[index] = c; |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
162 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
163 us = c->data; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
164 us->index = index; |
8215 | 165 } |
166 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
167 return NGX_OK; |
8215 | 168 } |
169 | |
170 | |
171 static void | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
172 ngx_http_v3_uni_read_handler(ngx_event_t *rev) |
8215 | 173 { |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
174 u_char buf[128]; |
8215 | 175 ssize_t n; |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
176 ngx_buf_t b; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
177 ngx_int_t rc; |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
178 ngx_connection_t *c; |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
179 ngx_http_v3_session_t *h3c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
180 ngx_http_v3_uni_stream_t *us; |
8215 | 181 |
182 c = rev->data; | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
183 us = c->data; |
8215 | 184 |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
185 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler"); |
8215 | 186 |
9051
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
187 if (c->close) { |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
188 ngx_http_v3_close_uni_stream(c); |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
189 return; |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
190 } |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
191 |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
192 ngx_memzero(&b, sizeof(ngx_buf_t)); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
193 |
8215 | 194 while (rev->ready) { |
195 | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
196 n = c->recv(c, buf, sizeof(buf)); |
8215 | 197 |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
198 if (n == NGX_ERROR) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
199 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
8215 | 200 goto failed; |
201 } | |
202 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
203 if (n == 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
204 if (us->index >= 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
205 rc = NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
206 goto failed; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
207 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
208 |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
209 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read eof"); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
210 ngx_http_v3_close_uni_stream(c); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
211 return; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
212 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
213 |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
214 if (n == NGX_AGAIN) { |
8215 | 215 break; |
216 } | |
217 | |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
218 b.pos = buf; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
219 b.last = buf + n; |
8215 | 220 |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
221 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
222 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
223 |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
224 if (ngx_http_v3_check_flood(c) != NGX_OK) { |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
225 ngx_http_v3_close_uni_stream(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
226 return; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
227 } |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
228 |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
229 rc = ngx_http_v3_parse_uni(c, &us->parse, &b); |
8215 | 230 |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
231 if (rc == NGX_DONE) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
232 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
233 "http3 read done"); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
234 ngx_http_v3_close_uni_stream(c); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
235 return; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
236 } |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
237 |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
238 if (rc > 0) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
239 goto failed; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
240 } |
8215 | 241 |
8838
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
242 if (rc != NGX_AGAIN) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
243 rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8824
diff
changeset
|
244 goto failed; |
8215 | 245 } |
246 } | |
247 | |
248 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
249 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
8215 | 250 goto failed; |
251 } | |
252 | |
253 return; | |
254 | |
255 failed: | |
256 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
257 ngx_http_v3_finalize_connection(c, rc, "stream error"); |
8215 | 258 ngx_http_v3_close_uni_stream(c); |
259 } | |
260 | |
261 | |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
262 static void |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
263 ngx_http_v3_uni_dummy_read_handler(ngx_event_t *rev) |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
264 { |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
265 u_char ch; |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
266 ngx_connection_t *c; |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
267 |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
268 c = rev->data; |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
269 |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
270 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy read handler"); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
271 |
9051
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
272 if (c->close) { |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
273 ngx_http_v3_close_uni_stream(c); |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
274 return; |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
275 } |
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
276 |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
277 if (rev->ready) { |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
278 if (c->recv(c, &ch, 1) != 0) { |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
279 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, NULL); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
280 ngx_http_v3_close_uni_stream(c); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
281 return; |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
282 } |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
283 } |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
284 |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
285 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
286 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
287 NULL); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
288 ngx_http_v3_close_uni_stream(c); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
289 } |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
290 } |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
291 |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
292 |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
293 static void |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
294 ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev) |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
295 { |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
296 ngx_connection_t *c; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
297 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
298 c = wev->data; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
299 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
300 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy write handler"); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
301 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
302 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
303 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
304 NULL); |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
305 ngx_http_v3_close_uni_stream(c); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
306 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
307 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
308 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
309 |
8215 | 310 static ngx_connection_t * |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
311 ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type) |
8215 | 312 { |
313 u_char buf[NGX_HTTP_V3_VARLEN_INT_LEN]; | |
314 size_t n; | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
315 ngx_int_t index; |
8215 | 316 ngx_connection_t *sc; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
317 ngx_http_v3_session_t *h3c; |
8215 | 318 ngx_http_v3_uni_stream_t *us; |
319 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
320 switch (type) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
321 case NGX_HTTP_V3_STREAM_ENCODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
322 index = NGX_HTTP_V3_STREAM_SERVER_ENCODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
323 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
324 case NGX_HTTP_V3_STREAM_DECODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
325 index = NGX_HTTP_V3_STREAM_SERVER_DECODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
326 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
327 case NGX_HTTP_V3_STREAM_CONTROL: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
328 index = NGX_HTTP_V3_STREAM_SERVER_CONTROL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
329 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
330 default: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
331 index = -1; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
332 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
333 |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
334 h3c = ngx_http_v3_get_session(c); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
335 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
336 if (index >= 0) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
337 if (h3c->known_streams[index]) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
338 return h3c->known_streams[index]; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
339 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
340 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
341 |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
342 sc = ngx_quic_open_stream(c, 0); |
8215 | 343 if (sc == NULL) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
344 goto failed; |
8215 | 345 } |
346 | |
9051
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
347 ngx_quic_cancelable_stream(sc); |
8724
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
348 |
8215 | 349 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
350 "http3 create uni stream, type:%ui", type); | |
351 | |
352 us = ngx_pcalloc(sc->pool, sizeof(ngx_http_v3_uni_stream_t)); | |
353 if (us == NULL) { | |
354 goto failed; | |
355 } | |
356 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
357 us->index = index; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
358 |
8215 | 359 sc->data = us; |
360 | |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
361 sc->read->handler = ngx_http_v3_uni_dummy_read_handler; |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
362 sc->write->handler = ngx_http_v3_uni_dummy_write_handler; |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
363 |
8403
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
364 if (index >= 0) { |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
365 h3c->known_streams[index] = sc; |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
366 } |
8215 | 367 |
368 n = (u_char *) ngx_http_v3_encode_varlen_int(buf, type) - buf; | |
369 | |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
370 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
371 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
372 |
8215 | 373 if (sc->send(sc, buf, n) != (ssize_t) n) { |
374 goto failed; | |
375 } | |
376 | |
8991
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
377 ngx_post_event(sc->read, &ngx_posted_events); |
3436b441239b
HTTP/3: proper uni stream closure detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8925
diff
changeset
|
378 |
8215 | 379 return sc; |
380 | |
381 failed: | |
382 | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
383 ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to create server stream"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
384 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
385 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
386 "failed to create server stream"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
387 if (sc) { |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
388 ngx_http_v3_close_uni_stream(sc); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
389 } |
8215 | 390 |
391 return NULL; | |
392 } | |
393 | |
394 | |
8774
f4d3f5d93a82
HTTP/3: moved session initialization to a separate file.
Roman Arutyunyan <arut@nginx.com>
parents:
8772
diff
changeset
|
395 ngx_int_t |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
396 ngx_http_v3_send_settings(ngx_connection_t *c) |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
397 { |
8769
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
398 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6]; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
399 size_t n; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
400 ngx_connection_t *cc; |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
401 ngx_http_v3_session_t *h3c; |
8769
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
402 ngx_http_v3_srv_conf_t *h3scf; |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
403 |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
404 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings"); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
405 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
406 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
407 if (cc == NULL) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
408 return NGX_ERROR; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
409 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
410 |
8769
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
411 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
412 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
413 n = ngx_http_v3_encode_varlen_int(NULL, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
414 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
415 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_table_capacity); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
416 n += ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
417 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_blocked_streams); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
418 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
419 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
420 NGX_HTTP_V3_FRAME_SETTINGS); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
421 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
422 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
423 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
424 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_table_capacity); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
425 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
426 NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
427 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_blocked_streams); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
428 n = p - buf; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
429 |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
430 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
431 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
432 |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
433 if (cc->send(cc, buf, n) != (ssize_t) n) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
434 goto failed; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
435 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
436 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
437 return NGX_OK; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
438 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
439 failed: |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
440 |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
441 ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send settings"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
442 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
443 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
444 "failed to send settings"); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
445 ngx_http_v3_close_uni_stream(cc); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
446 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
447 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
448 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
449 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
450 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
451 ngx_int_t |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
452 ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id) |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
453 { |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
454 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 3]; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
455 size_t n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
456 ngx_connection_t *cc; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
457 ngx_http_v3_session_t *h3c; |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
458 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
459 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send goaway %uL", id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
460 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
461 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
462 if (cc == NULL) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
463 return NGX_ERROR; |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
464 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
465 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
466 n = ngx_http_v3_encode_varlen_int(NULL, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
467 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, NGX_HTTP_V3_FRAME_GOAWAY); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
468 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
469 p = (u_char *) ngx_http_v3_encode_varlen_int(p, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
470 n = p - buf; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
471 |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
472 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
473 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
474 |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
475 if (cc->send(cc, buf, n) != (ssize_t) n) { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
476 goto failed; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
477 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
478 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
479 return NGX_OK; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
480 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
481 failed: |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
482 |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
483 ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send goaway"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
484 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
485 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
486 "failed to send goaway"); |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
487 ngx_http_v3_close_uni_stream(cc); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
488 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
489 return NGX_ERROR; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
490 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
491 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
492 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
493 ngx_int_t |
8807
0ac25efb2da3
HTTP/3: quic-qpack term updates.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8796
diff
changeset
|
494 ngx_http_v3_send_ack_section(ngx_connection_t *c, ngx_uint_t stream_id) |
8215 | 495 { |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
496 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
497 size_t n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
498 ngx_connection_t *dc; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
499 ngx_http_v3_session_t *h3c; |
8215 | 500 |
501 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
502 "http3 send section acknowledgement %ui", stream_id); |
8215 | 503 |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
504 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 505 if (dc == NULL) { |
506 return NGX_ERROR; | |
507 } | |
508 | |
509 buf[0] = 0x80; | |
510 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 7) - buf; | |
511 | |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
512 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
513 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
514 |
8215 | 515 if (dc->send(dc, buf, n) != (ssize_t) n) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
516 goto failed; |
8215 | 517 } |
518 | |
519 return NGX_OK; | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
520 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
521 failed: |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
522 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
523 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
524 "failed to send section acknowledgement"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
525 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
526 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
527 "failed to send section acknowledgement"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
528 ngx_http_v3_close_uni_stream(dc); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
529 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
530 return NGX_ERROR; |
8215 | 531 } |
532 | |
533 | |
534 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
535 ngx_http_v3_send_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
8215 | 536 { |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
537 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
538 size_t n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
539 ngx_connection_t *dc; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
540 ngx_http_v3_session_t *h3c; |
8215 | 541 |
542 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
543 "http3 send stream cancellation %ui", stream_id); |
8215 | 544 |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
545 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 546 if (dc == NULL) { |
547 return NGX_ERROR; | |
548 } | |
549 | |
550 buf[0] = 0x40; | |
551 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 6) - buf; | |
552 | |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
553 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
554 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
555 |
8215 | 556 if (dc->send(dc, buf, n) != (ssize_t) n) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
557 goto failed; |
8215 | 558 } |
559 | |
560 return NGX_OK; | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
561 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
562 failed: |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
563 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
564 ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send stream cancellation"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
565 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
566 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
567 "failed to send stream cancellation"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
568 ngx_http_v3_close_uni_stream(dc); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
569 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
570 return NGX_ERROR; |
8215 | 571 } |
572 | |
573 | |
574 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
575 ngx_http_v3_send_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc) |
8215 | 576 { |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
577 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
578 size_t n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
579 ngx_connection_t *dc; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
580 ngx_http_v3_session_t *h3c; |
8215 | 581 |
582 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
583 "http3 send insert count increment %ui", inc); |
8215 | 584 |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
585 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 586 if (dc == NULL) { |
587 return NGX_ERROR; | |
588 } | |
589 | |
590 buf[0] = 0; | |
591 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, inc, 6) - buf; | |
592 | |
8881
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
593 h3c = ngx_http_v3_get_session(c); |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
594 h3c->total_bytes += n; |
72b304f6207c
HTTP/3: traffic-based flood detection.
Roman Arutyunyan <arut@nginx.com>
parents:
8879
diff
changeset
|
595 |
8215 | 596 if (dc->send(dc, buf, n) != (ssize_t) n) { |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
597 goto failed; |
8215 | 598 } |
599 | |
600 return NGX_OK; | |
8902
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
601 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
602 failed: |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
603 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
604 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
605 "failed to send insert count increment"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
606 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
607 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD, |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
608 "failed to send insert count increment"); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
609 ngx_http_v3_close_uni_stream(dc); |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
610 |
925572184d4a
HTTP/3: adjusted QUIC connection finalization.
Roman Arutyunyan <arut@nginx.com>
parents:
8881
diff
changeset
|
611 return NGX_ERROR; |
8215 | 612 } |
8497 | 613 |
614 | |
615 ngx_int_t | |
8767
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
616 ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
617 { |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
618 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
619 "http3 cancel stream %ui", stream_id); |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
620 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
621 /* we do not use dynamic tables */ |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
622 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
623 return NGX_OK; |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
624 } |