Mercurial > hg > nginx-quic
comparison src/http/v3/ngx_http_v3_table.c @ 8714:18d23ed15eef quic
HTTP/3: renamed files.
ngx_http_v3_tables.h and ngx_http_v3_tables.c are renamed to
ngx_http_v3_table.h and ngx_http_v3_table.c to better match HTTP/2 code.
ngx_http_v3_streams.h and ngx_http_v3_streams.c are renamed to
ngx_http_v3_uni.h and ngx_http_v3_uni.c to better match their content.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 07 Dec 2021 13:01:28 +0300 |
parents | src/http/v3/ngx_http_v3_tables.c@925572184d4a |
children | 81a3429db8b0 |
comparison
equal
deleted
inserted
replaced
8713:d6ef13c5fd8e | 8714:18d23ed15eef |
---|---|
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 #define ngx_http_v3_table_entry_size(n, v) ((n)->len + (v)->len + 32) | |
14 | |
15 | |
16 static ngx_int_t ngx_http_v3_evict(ngx_connection_t *c, size_t need); | |
17 static void ngx_http_v3_unblock(void *data); | |
18 static ngx_int_t ngx_http_v3_new_entry(ngx_connection_t *c); | |
19 | |
20 | |
21 typedef struct { | |
22 ngx_queue_t queue; | |
23 ngx_connection_t *connection; | |
24 ngx_uint_t *nblocked; | |
25 } ngx_http_v3_block_t; | |
26 | |
27 | |
28 static ngx_http_v3_field_t ngx_http_v3_static_table[] = { | |
29 | |
30 { ngx_string(":authority"), ngx_string("") }, | |
31 { ngx_string(":path"), ngx_string("/") }, | |
32 { ngx_string("age"), ngx_string("0") }, | |
33 { ngx_string("content-disposition"), ngx_string("") }, | |
34 { ngx_string("content-length"), ngx_string("0") }, | |
35 { ngx_string("cookie"), ngx_string("") }, | |
36 { ngx_string("date"), ngx_string("") }, | |
37 { ngx_string("etag"), ngx_string("") }, | |
38 { ngx_string("if-modified-since"), ngx_string("") }, | |
39 { ngx_string("if-none-match"), ngx_string("") }, | |
40 { ngx_string("last-modified"), ngx_string("") }, | |
41 { ngx_string("link"), ngx_string("") }, | |
42 { ngx_string("location"), ngx_string("") }, | |
43 { ngx_string("referer"), ngx_string("") }, | |
44 { ngx_string("set-cookie"), ngx_string("") }, | |
45 { ngx_string(":method"), ngx_string("CONNECT") }, | |
46 { ngx_string(":method"), ngx_string("DELETE") }, | |
47 { ngx_string(":method"), ngx_string("GET") }, | |
48 { ngx_string(":method"), ngx_string("HEAD") }, | |
49 { ngx_string(":method"), ngx_string("OPTIONS") }, | |
50 { ngx_string(":method"), ngx_string("POST") }, | |
51 { ngx_string(":method"), ngx_string("PUT") }, | |
52 { ngx_string(":scheme"), ngx_string("http") }, | |
53 { ngx_string(":scheme"), ngx_string("https") }, | |
54 { ngx_string(":status"), ngx_string("103") }, | |
55 { ngx_string(":status"), ngx_string("200") }, | |
56 { ngx_string(":status"), ngx_string("304") }, | |
57 { ngx_string(":status"), ngx_string("404") }, | |
58 { ngx_string(":status"), ngx_string("503") }, | |
59 { ngx_string("accept"), ngx_string("*/*") }, | |
60 { ngx_string("accept"), | |
61 ngx_string("application/dns-message") }, | |
62 { ngx_string("accept-encoding"), ngx_string("gzip, deflate, br") }, | |
63 { ngx_string("accept-ranges"), ngx_string("bytes") }, | |
64 { ngx_string("access-control-allow-headers"), | |
65 ngx_string("cache-control") }, | |
66 { ngx_string("access-control-allow-headers"), | |
67 ngx_string("content-type") }, | |
68 { ngx_string("access-control-allow-origin"), | |
69 ngx_string("*") }, | |
70 { ngx_string("cache-control"), ngx_string("max-age=0") }, | |
71 { ngx_string("cache-control"), ngx_string("max-age=2592000") }, | |
72 { ngx_string("cache-control"), ngx_string("max-age=604800") }, | |
73 { ngx_string("cache-control"), ngx_string("no-cache") }, | |
74 { ngx_string("cache-control"), ngx_string("no-store") }, | |
75 { ngx_string("cache-control"), | |
76 ngx_string("public, max-age=31536000") }, | |
77 { ngx_string("content-encoding"), ngx_string("br") }, | |
78 { ngx_string("content-encoding"), ngx_string("gzip") }, | |
79 { ngx_string("content-type"), | |
80 ngx_string("application/dns-message") }, | |
81 { ngx_string("content-type"), | |
82 ngx_string("application/javascript") }, | |
83 { ngx_string("content-type"), ngx_string("application/json") }, | |
84 { ngx_string("content-type"), | |
85 ngx_string("application/x-www-form-urlencoded") }, | |
86 { ngx_string("content-type"), ngx_string("image/gif") }, | |
87 { ngx_string("content-type"), ngx_string("image/jpeg") }, | |
88 { ngx_string("content-type"), ngx_string("image/png") }, | |
89 { ngx_string("content-type"), ngx_string("text/css") }, | |
90 { ngx_string("content-type"), | |
91 ngx_string("text/html;charset=utf-8") }, | |
92 { ngx_string("content-type"), ngx_string("text/plain") }, | |
93 { ngx_string("content-type"), | |
94 ngx_string("text/plain;charset=utf-8") }, | |
95 { ngx_string("range"), ngx_string("bytes=0-") }, | |
96 { ngx_string("strict-transport-security"), | |
97 ngx_string("max-age=31536000") }, | |
98 { ngx_string("strict-transport-security"), | |
99 ngx_string("max-age=31536000;includesubdomains") }, | |
100 { ngx_string("strict-transport-security"), | |
101 ngx_string("max-age=31536000;includesubdomains;preload") }, | |
102 { ngx_string("vary"), ngx_string("accept-encoding") }, | |
103 { ngx_string("vary"), ngx_string("origin") }, | |
104 { ngx_string("x-content-type-options"), | |
105 ngx_string("nosniff") }, | |
106 { ngx_string("x-xss-protection"), ngx_string("1;mode=block") }, | |
107 { ngx_string(":status"), ngx_string("100") }, | |
108 { ngx_string(":status"), ngx_string("204") }, | |
109 { ngx_string(":status"), ngx_string("206") }, | |
110 { ngx_string(":status"), ngx_string("302") }, | |
111 { ngx_string(":status"), ngx_string("400") }, | |
112 { ngx_string(":status"), ngx_string("403") }, | |
113 { ngx_string(":status"), ngx_string("421") }, | |
114 { ngx_string(":status"), ngx_string("425") }, | |
115 { ngx_string(":status"), ngx_string("500") }, | |
116 { ngx_string("accept-language"), ngx_string("") }, | |
117 { ngx_string("access-control-allow-credentials"), | |
118 ngx_string("FALSE") }, | |
119 { ngx_string("access-control-allow-credentials"), | |
120 ngx_string("TRUE") }, | |
121 { ngx_string("access-control-allow-headers"), | |
122 ngx_string("*") }, | |
123 { ngx_string("access-control-allow-methods"), | |
124 ngx_string("get") }, | |
125 { ngx_string("access-control-allow-methods"), | |
126 ngx_string("get, post, options") }, | |
127 { ngx_string("access-control-allow-methods"), | |
128 ngx_string("options") }, | |
129 { ngx_string("access-control-expose-headers"), | |
130 ngx_string("content-length") }, | |
131 { ngx_string("access-control-request-headers"), | |
132 ngx_string("content-type") }, | |
133 { ngx_string("access-control-request-method"), | |
134 ngx_string("get") }, | |
135 { ngx_string("access-control-request-method"), | |
136 ngx_string("post") }, | |
137 { ngx_string("alt-svc"), ngx_string("clear") }, | |
138 { ngx_string("authorization"), ngx_string("") }, | |
139 { ngx_string("content-security-policy"), | |
140 ngx_string("script-src 'none';object-src 'none';base-uri 'none'") }, | |
141 { ngx_string("early-data"), ngx_string("1") }, | |
142 { ngx_string("expect-ct"), ngx_string("") }, | |
143 { ngx_string("forwarded"), ngx_string("") }, | |
144 { ngx_string("if-range"), ngx_string("") }, | |
145 { ngx_string("origin"), ngx_string("") }, | |
146 { ngx_string("purpose"), ngx_string("prefetch") }, | |
147 { ngx_string("server"), ngx_string("") }, | |
148 { ngx_string("timing-allow-origin"), ngx_string("*") }, | |
149 { ngx_string("upgrade-insecure-requests"), | |
150 ngx_string("1") }, | |
151 { ngx_string("user-agent"), ngx_string("") }, | |
152 { ngx_string("x-forwarded-for"), ngx_string("") }, | |
153 { ngx_string("x-frame-options"), ngx_string("deny") }, | |
154 { ngx_string("x-frame-options"), ngx_string("sameorigin") } | |
155 }; | |
156 | |
157 | |
158 ngx_int_t | |
159 ngx_http_v3_ref_insert(ngx_connection_t *c, ngx_uint_t dynamic, | |
160 ngx_uint_t index, ngx_str_t *value) | |
161 { | |
162 ngx_str_t name; | |
163 ngx_http_v3_session_t *h3c; | |
164 ngx_http_v3_dynamic_table_t *dt; | |
165 | |
166 if (dynamic) { | |
167 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
168 "http3 ref insert dynamic[%ui] \"%V\"", index, value); | |
169 | |
170 h3c = ngx_http_v3_get_session(c); | |
171 dt = &h3c->table; | |
172 | |
173 if (dt->base + dt->nelts <= index) { | |
174 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
175 } | |
176 | |
177 index = dt->base + dt->nelts - 1 - index; | |
178 | |
179 if (ngx_http_v3_lookup(c, index, &name, NULL) != NGX_OK) { | |
180 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
181 } | |
182 | |
183 } else { | |
184 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
185 "http3 ref insert static[%ui] \"%V\"", index, value); | |
186 | |
187 if (ngx_http_v3_lookup_static(c, index, &name, NULL) != NGX_OK) { | |
188 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
189 } | |
190 } | |
191 | |
192 return ngx_http_v3_insert(c, &name, value); | |
193 } | |
194 | |
195 | |
196 ngx_int_t | |
197 ngx_http_v3_insert(ngx_connection_t *c, ngx_str_t *name, ngx_str_t *value) | |
198 { | |
199 u_char *p; | |
200 size_t size; | |
201 ngx_http_v3_field_t *field; | |
202 ngx_http_v3_session_t *h3c; | |
203 ngx_http_v3_dynamic_table_t *dt; | |
204 | |
205 size = ngx_http_v3_table_entry_size(name, value); | |
206 | |
207 if (ngx_http_v3_evict(c, size) != NGX_OK) { | |
208 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
209 } | |
210 | |
211 h3c = ngx_http_v3_get_session(c); | |
212 dt = &h3c->table; | |
213 | |
214 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
215 "http3 insert [%ui] \"%V\":\"%V\", size:%uz", | |
216 dt->base + dt->nelts, name, value, size); | |
217 | |
218 p = ngx_alloc(sizeof(ngx_http_v3_field_t) + name->len + value->len, | |
219 c->log); | |
220 if (p == NULL) { | |
221 return NGX_ERROR; | |
222 } | |
223 | |
224 field = (ngx_http_v3_field_t *) p; | |
225 | |
226 field->name.data = p + sizeof(ngx_http_v3_field_t); | |
227 field->name.len = name->len; | |
228 field->value.data = ngx_cpymem(field->name.data, name->data, name->len); | |
229 field->value.len = value->len; | |
230 ngx_memcpy(field->value.data, value->data, value->len); | |
231 | |
232 dt->elts[dt->nelts++] = field; | |
233 dt->size += size; | |
234 | |
235 /* TODO increment can be sent less often */ | |
236 | |
237 if (ngx_http_v3_send_inc_insert_count(c, 1) != NGX_OK) { | |
238 return NGX_ERROR; | |
239 } | |
240 | |
241 if (ngx_http_v3_new_entry(c) != NGX_OK) { | |
242 return NGX_ERROR; | |
243 } | |
244 | |
245 return NGX_OK; | |
246 } | |
247 | |
248 | |
249 ngx_int_t | |
250 ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity) | |
251 { | |
252 ngx_uint_t max, prev_max; | |
253 ngx_http_v3_field_t **elts; | |
254 ngx_http_v3_session_t *h3c; | |
255 ngx_http_v3_srv_conf_t *h3scf; | |
256 ngx_http_v3_dynamic_table_t *dt; | |
257 | |
258 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
259 "http3 set capacity %ui", capacity); | |
260 | |
261 h3c = ngx_http_v3_get_session(c); | |
262 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); | |
263 | |
264 if (capacity > h3scf->max_table_capacity) { | |
265 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
266 "client exceeded http3_max_table_capacity limit"); | |
267 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
268 } | |
269 | |
270 dt = &h3c->table; | |
271 | |
272 if (dt->size > capacity) { | |
273 if (ngx_http_v3_evict(c, dt->size - capacity) != NGX_OK) { | |
274 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
275 } | |
276 } | |
277 | |
278 max = capacity / 32; | |
279 prev_max = dt->capacity / 32; | |
280 | |
281 if (max > prev_max) { | |
282 elts = ngx_alloc(max * sizeof(void *), c->log); | |
283 if (elts == NULL) { | |
284 return NGX_ERROR; | |
285 } | |
286 | |
287 if (dt->elts) { | |
288 ngx_memcpy(elts, dt->elts, dt->nelts * sizeof(void *)); | |
289 ngx_free(dt->elts); | |
290 } | |
291 | |
292 dt->elts = elts; | |
293 } | |
294 | |
295 dt->capacity = capacity; | |
296 | |
297 return NGX_OK; | |
298 } | |
299 | |
300 | |
301 void | |
302 ngx_http_v3_cleanup_table(ngx_http_v3_session_t *h3c) | |
303 { | |
304 ngx_uint_t n; | |
305 ngx_http_v3_dynamic_table_t *dt; | |
306 | |
307 dt = &h3c->table; | |
308 | |
309 if (dt->elts == NULL) { | |
310 return; | |
311 } | |
312 | |
313 for (n = 0; n < dt->nelts; n++) { | |
314 ngx_free(dt->elts[n]); | |
315 } | |
316 | |
317 ngx_free(dt->elts); | |
318 } | |
319 | |
320 | |
321 static ngx_int_t | |
322 ngx_http_v3_evict(ngx_connection_t *c, size_t need) | |
323 { | |
324 size_t size, target; | |
325 ngx_uint_t n; | |
326 ngx_http_v3_field_t *field; | |
327 ngx_http_v3_session_t *h3c; | |
328 ngx_http_v3_dynamic_table_t *dt; | |
329 | |
330 h3c = ngx_http_v3_get_session(c); | |
331 dt = &h3c->table; | |
332 | |
333 if (need > dt->capacity) { | |
334 ngx_log_error(NGX_LOG_ERR, c->log, 0, | |
335 "not enough dynamic table capacity"); | |
336 return NGX_ERROR; | |
337 } | |
338 | |
339 target = dt->capacity - need; | |
340 n = 0; | |
341 | |
342 while (dt->size > target) { | |
343 field = dt->elts[n++]; | |
344 size = ngx_http_v3_table_entry_size(&field->name, &field->value); | |
345 | |
346 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
347 "http3 evict [%ui] \"%V\":\"%V\" size:%uz", | |
348 dt->base, &field->name, &field->value, size); | |
349 | |
350 ngx_free(field); | |
351 dt->size -= size; | |
352 } | |
353 | |
354 if (n) { | |
355 dt->nelts -= n; | |
356 dt->base += n; | |
357 ngx_memmove(dt->elts, &dt->elts[n], dt->nelts * sizeof(void *)); | |
358 } | |
359 | |
360 return NGX_OK; | |
361 } | |
362 | |
363 | |
364 ngx_int_t | |
365 ngx_http_v3_duplicate(ngx_connection_t *c, ngx_uint_t index) | |
366 { | |
367 ngx_str_t name, value; | |
368 ngx_http_v3_session_t *h3c; | |
369 ngx_http_v3_dynamic_table_t *dt; | |
370 | |
371 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 duplicate %ui", index); | |
372 | |
373 h3c = ngx_http_v3_get_session(c); | |
374 dt = &h3c->table; | |
375 | |
376 if (dt->base + dt->nelts <= index) { | |
377 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
378 } | |
379 | |
380 index = dt->base + dt->nelts - 1 - index; | |
381 | |
382 if (ngx_http_v3_lookup(c, index, &name, &value) != NGX_OK) { | |
383 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; | |
384 } | |
385 | |
386 return ngx_http_v3_insert(c, &name, &value); | |
387 } | |
388 | |
389 | |
390 ngx_int_t | |
391 ngx_http_v3_ack_section(ngx_connection_t *c, ngx_uint_t stream_id) | |
392 { | |
393 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
394 "http3 ack section %ui", stream_id); | |
395 | |
396 /* we do not use dynamic tables */ | |
397 | |
398 return NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR; | |
399 } | |
400 | |
401 | |
402 ngx_int_t | |
403 ngx_http_v3_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc) | |
404 { | |
405 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
406 "http3 increment insert count %ui", inc); | |
407 | |
408 /* we do not use dynamic tables */ | |
409 | |
410 return NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR; | |
411 } | |
412 | |
413 | |
414 ngx_int_t | |
415 ngx_http_v3_lookup_static(ngx_connection_t *c, ngx_uint_t index, | |
416 ngx_str_t *name, ngx_str_t *value) | |
417 { | |
418 ngx_uint_t nelts; | |
419 ngx_http_v3_field_t *field; | |
420 | |
421 nelts = sizeof(ngx_http_v3_static_table) | |
422 / sizeof(ngx_http_v3_static_table[0]); | |
423 | |
424 if (index >= nelts) { | |
425 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
426 "http3 static[%ui] lookup out of bounds: %ui", | |
427 index, nelts); | |
428 return NGX_ERROR; | |
429 } | |
430 | |
431 field = &ngx_http_v3_static_table[index]; | |
432 | |
433 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
434 "http3 static[%ui] lookup \"%V\":\"%V\"", | |
435 index, &field->name, &field->value); | |
436 | |
437 if (name) { | |
438 *name = field->name; | |
439 } | |
440 | |
441 if (value) { | |
442 *value = field->value; | |
443 } | |
444 | |
445 return NGX_OK; | |
446 } | |
447 | |
448 | |
449 ngx_int_t | |
450 ngx_http_v3_lookup(ngx_connection_t *c, ngx_uint_t index, ngx_str_t *name, | |
451 ngx_str_t *value) | |
452 { | |
453 ngx_http_v3_field_t *field; | |
454 ngx_http_v3_session_t *h3c; | |
455 ngx_http_v3_dynamic_table_t *dt; | |
456 | |
457 h3c = ngx_http_v3_get_session(c); | |
458 dt = &h3c->table; | |
459 | |
460 if (index < dt->base || index - dt->base >= dt->nelts) { | |
461 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
462 "http3 dynamic[%ui] lookup out of bounds: [%ui,%ui]", | |
463 index, dt->base, dt->base + dt->nelts); | |
464 return NGX_ERROR; | |
465 } | |
466 | |
467 field = dt->elts[index - dt->base]; | |
468 | |
469 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
470 "http3 dynamic[%ui] lookup \"%V\":\"%V\"", | |
471 index, &field->name, &field->value); | |
472 | |
473 if (name) { | |
474 *name = field->name; | |
475 } | |
476 | |
477 if (value) { | |
478 *value = field->value; | |
479 } | |
480 | |
481 return NGX_OK; | |
482 } | |
483 | |
484 | |
485 ngx_int_t | |
486 ngx_http_v3_decode_insert_count(ngx_connection_t *c, ngx_uint_t *insert_count) | |
487 { | |
488 ngx_uint_t max_entries, full_range, max_value, | |
489 max_wrapped, req_insert_count; | |
490 ngx_http_v3_srv_conf_t *h3scf; | |
491 ngx_http_v3_session_t *h3c; | |
492 ngx_http_v3_dynamic_table_t *dt; | |
493 | |
494 /* QPACK 4.5.1.1. Required Insert Count */ | |
495 | |
496 if (*insert_count == 0) { | |
497 return NGX_OK; | |
498 } | |
499 | |
500 h3c = ngx_http_v3_get_session(c); | |
501 dt = &h3c->table; | |
502 | |
503 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); | |
504 | |
505 max_entries = h3scf->max_table_capacity / 32; | |
506 full_range = 2 * max_entries; | |
507 | |
508 if (*insert_count > full_range) { | |
509 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; | |
510 } | |
511 | |
512 max_value = dt->base + dt->nelts + max_entries; | |
513 max_wrapped = (max_value / full_range) * full_range; | |
514 req_insert_count = max_wrapped + *insert_count - 1; | |
515 | |
516 if (req_insert_count > max_value) { | |
517 if (req_insert_count <= full_range) { | |
518 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; | |
519 } | |
520 | |
521 req_insert_count -= full_range; | |
522 } | |
523 | |
524 if (req_insert_count == 0) { | |
525 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; | |
526 } | |
527 | |
528 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
529 "http3 decode insert_count %ui -> %ui", | |
530 *insert_count, req_insert_count); | |
531 | |
532 *insert_count = req_insert_count; | |
533 | |
534 return NGX_OK; | |
535 } | |
536 | |
537 | |
538 ngx_int_t | |
539 ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count) | |
540 { | |
541 size_t n; | |
542 ngx_pool_cleanup_t *cln; | |
543 ngx_http_v3_block_t *block; | |
544 ngx_http_v3_session_t *h3c; | |
545 ngx_http_v3_srv_conf_t *h3scf; | |
546 ngx_http_v3_dynamic_table_t *dt; | |
547 | |
548 h3c = ngx_http_v3_get_session(c); | |
549 dt = &h3c->table; | |
550 | |
551 n = dt->base + dt->nelts; | |
552 | |
553 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
554 "http3 check insert count req:%ui, have:%ui", | |
555 insert_count, n); | |
556 | |
557 if (n >= insert_count) { | |
558 return NGX_OK; | |
559 } | |
560 | |
561 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 block stream"); | |
562 | |
563 block = NULL; | |
564 | |
565 for (cln = c->pool->cleanup; cln; cln = cln->next) { | |
566 if (cln->handler == ngx_http_v3_unblock) { | |
567 block = cln->data; | |
568 break; | |
569 } | |
570 } | |
571 | |
572 if (block == NULL) { | |
573 cln = ngx_pool_cleanup_add(c->pool, sizeof(ngx_http_v3_block_t)); | |
574 if (cln == NULL) { | |
575 return NGX_ERROR; | |
576 } | |
577 | |
578 cln->handler = ngx_http_v3_unblock; | |
579 | |
580 block = cln->data; | |
581 block->queue.prev = NULL; | |
582 block->connection = c; | |
583 block->nblocked = &h3c->nblocked; | |
584 } | |
585 | |
586 if (block->queue.prev == NULL) { | |
587 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); | |
588 | |
589 if (h3c->nblocked == h3scf->max_blocked_streams) { | |
590 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
591 "client exceeded http3_max_blocked_streams limit"); | |
592 | |
593 ngx_http_v3_finalize_connection(c, | |
594 NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED, | |
595 "too many blocked streams"); | |
596 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; | |
597 } | |
598 | |
599 h3c->nblocked++; | |
600 ngx_queue_insert_tail(&h3c->blocked, &block->queue); | |
601 } | |
602 | |
603 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
604 "http3 blocked:%ui", h3c->nblocked); | |
605 | |
606 return NGX_BUSY; | |
607 } | |
608 | |
609 | |
610 static void | |
611 ngx_http_v3_unblock(void *data) | |
612 { | |
613 ngx_http_v3_block_t *block = data; | |
614 | |
615 if (block->queue.prev) { | |
616 ngx_queue_remove(&block->queue); | |
617 block->queue.prev = NULL; | |
618 (*block->nblocked)--; | |
619 } | |
620 } | |
621 | |
622 | |
623 static ngx_int_t | |
624 ngx_http_v3_new_entry(ngx_connection_t *c) | |
625 { | |
626 ngx_queue_t *q; | |
627 ngx_connection_t *bc; | |
628 ngx_http_v3_block_t *block; | |
629 ngx_http_v3_session_t *h3c; | |
630 | |
631 h3c = ngx_http_v3_get_session(c); | |
632 | |
633 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
634 "http3 new dynamic entry, blocked:%ui", h3c->nblocked); | |
635 | |
636 while (!ngx_queue_empty(&h3c->blocked)) { | |
637 q = ngx_queue_head(&h3c->blocked); | |
638 block = (ngx_http_v3_block_t *) q; | |
639 bc = block->connection; | |
640 | |
641 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, bc->log, 0, "http3 unblock stream"); | |
642 | |
643 ngx_http_v3_unblock(block); | |
644 ngx_post_event(bc->read, &ngx_posted_events); | |
645 } | |
646 | |
647 return NGX_OK; | |
648 } | |
649 | |
650 | |
651 ngx_int_t | |
652 ngx_http_v3_set_param(ngx_connection_t *c, uint64_t id, uint64_t value) | |
653 { | |
654 switch (id) { | |
655 | |
656 case NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY: | |
657 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
658 "http3 param QPACK_MAX_TABLE_CAPACITY:%uL", value); | |
659 break; | |
660 | |
661 case NGX_HTTP_V3_PARAM_MAX_HEADER_LIST_SIZE: | |
662 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
663 "http3 param SETTINGS_MAX_HEADER_LIST_SIZE:%uL", value); | |
664 break; | |
665 | |
666 case NGX_HTTP_V3_PARAM_BLOCKED_STREAMS: | |
667 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
668 "http3 param QPACK_BLOCKED_STREAMS:%uL", value); | |
669 break; | |
670 | |
671 default: | |
672 | |
673 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
674 "http3 param #%uL:%uL", id, value); | |
675 } | |
676 | |
677 return NGX_OK; | |
678 } |