Mercurial > hg > nginx
annotate src/event/quic/ngx_event_quic.h @ 9295:c5623963c29e
Upstream: fixed proxy_no_cache when caching errors.
Caching errors, notably intercepted errors and internally generated
502/504 errors, as well as handling of cache revalidation with 304,
did not take into account u->conf->no_cache predicates configured.
As a result, an error might be cached even if configuration explicitly
says not to. Fix is to check u->conf->no_cache in these cases.
To simplify usage in multiple places, checking u->conf->no_cache is now
done in a separate function. As a minor optimization, u->conf->no_cache
is only checked if u->cacheable is set.
As a side effect, this change also fixes caching errors after
proxy_cache_bypass. Also, during cache revalidation u->cacheable is
now tested, so 304 responses which disable caching won't extend
cacheability of stored responses.
Additionally, when caching internally generated 502/504 errors
u->cacheable is now explicitly updated from u->headers_in.no_cache and
u->headers_in.expired, restoring the behaviour before 8041:0784ab86ad08
(1.23.0) when an error happens while reading the response headers.
Reported by Kirill A. Korinsky,
https://freenginx.org/pipermail/nginx/2024-April/000082.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 21:44:50 +0300 |
parents | ad3d34ddfdcc |
children |
rev | line source |
---|---|
8167
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 /* |
8182
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
8181
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
8167
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 */ |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 #ifndef _NGX_EVENT_QUIC_H_INCLUDED_ |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 #define _NGX_EVENT_QUIC_H_INCLUDED_ |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
8347
a5141e6b3214
Fixed includes in quic headers.
Roman Arutyunyan <arut@nginx.com>
parents:
8345
diff
changeset
|
11 #include <ngx_config.h> |
a5141e6b3214
Fixed includes in quic headers.
Roman Arutyunyan <arut@nginx.com>
parents:
8345
diff
changeset
|
12 #include <ngx_core.h> |
8170
53a5cdbe500c
QUIC add_handshake_data callback, varint routines.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8169
diff
changeset
|
13 |
8221
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
14 |
8415
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8383
diff
changeset
|
15 #define NGX_QUIC_MAX_UDP_PAYLOAD_SIZE 65527 |
8432
391d06a51bc0
Limited max udp payload size for outgoing packets.
Vladimir Homutov <vl@nginx.com>
parents:
8418
diff
changeset
|
16 |
8265
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
8263
diff
changeset
|
17 #define NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT 3 |
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
8263
diff
changeset
|
18 #define NGX_QUIC_DEFAULT_MAX_ACK_DELAY 25 |
8694
cef042935003
QUIC: the "quic_host_key" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8686
diff
changeset
|
19 #define NGX_QUIC_DEFAULT_HOST_KEY_LEN 32 |
cef042935003
QUIC: the "quic_host_key" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8686
diff
changeset
|
20 #define NGX_QUIC_SR_KEY_LEN 32 |
cef042935003
QUIC: the "quic_host_key" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8686
diff
changeset
|
21 #define NGX_QUIC_AV_KEY_LEN 32 |
8265
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
8263
diff
changeset
|
22 |
8747 | 23 #define NGX_QUIC_SR_TOKEN_LEN 16 |
8355
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
8352
diff
changeset
|
24 |
8345
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8334
diff
changeset
|
25 #define NGX_QUIC_MIN_INITIAL_SIZE 1200 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8334
diff
changeset
|
26 |
8280
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8273
diff
changeset
|
27 #define NGX_QUIC_STREAM_SERVER_INITIATED 0x01 |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8273
diff
changeset
|
28 #define NGX_QUIC_STREAM_UNIDIRECTIONAL 0x02 |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8273
diff
changeset
|
29 |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8224
diff
changeset
|
30 |
9058
b0c2234aaa9f
QUIC: application init() callback.
Roman Arutyunyan <arut@nginx.com>
parents:
9055
diff
changeset
|
31 typedef ngx_int_t (*ngx_quic_init_pt)(ngx_connection_t *c); |
9055
1192923be0aa
QUIC: idle mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9052
diff
changeset
|
32 typedef void (*ngx_quic_shutdown_pt)(ngx_connection_t *c); |
1192923be0aa
QUIC: idle mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9052
diff
changeset
|
33 |
1192923be0aa
QUIC: idle mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9052
diff
changeset
|
34 |
8990
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
35 typedef enum { |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
36 NGX_QUIC_STREAM_SEND_READY = 0, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
37 NGX_QUIC_STREAM_SEND_SEND, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
38 NGX_QUIC_STREAM_SEND_DATA_SENT, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
39 NGX_QUIC_STREAM_SEND_DATA_RECVD, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
40 NGX_QUIC_STREAM_SEND_RESET_SENT, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
41 NGX_QUIC_STREAM_SEND_RESET_RECVD |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
42 } ngx_quic_stream_send_state_e; |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
43 |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
44 |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
45 typedef enum { |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
46 NGX_QUIC_STREAM_RECV_RECV = 0, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
47 NGX_QUIC_STREAM_RECV_SIZE_KNOWN, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
48 NGX_QUIC_STREAM_RECV_DATA_RECVD, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
49 NGX_QUIC_STREAM_RECV_DATA_READ, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
50 NGX_QUIC_STREAM_RECV_RESET_RECVD, |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
51 NGX_QUIC_STREAM_RECV_RESET_READ |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
52 } ngx_quic_stream_recv_state_e; |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
53 |
b42a041d23a2
QUIC: introduced explicit stream states.
Roman Arutyunyan <arut@nginx.com>
parents:
8979
diff
changeset
|
54 |
8334
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
8282
diff
changeset
|
55 typedef struct { |
9011
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
56 uint64_t size; |
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
57 uint64_t offset; |
9014
8d11e2171697
QUIC: optimize insertion at the end of QUIC buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
9011
diff
changeset
|
58 uint64_t last_offset; |
9011
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
59 ngx_chain_t *chain; |
9016
55b38514729b
QUIC: fixed insertion at the end of buffer.
Roman Arutyunyan <arut@nginx.com>
parents:
9014
diff
changeset
|
60 ngx_chain_t *last_chain; |
9011
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
61 } ngx_quic_buffer_t; |
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
62 |
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
63 |
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
64 typedef struct { |
8992 | 65 ngx_ssl_t *ssl; |
8924
d6ef13c5fd8e
QUIC: simplified configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8906
diff
changeset
|
66 |
8992 | 67 ngx_flag_t retry; |
68 ngx_flag_t gso_enabled; | |
69 ngx_flag_t disable_active_migration; | |
9158
ad3d34ddfdcc
QUIC: "handshake_timeout" configuration parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
9107
diff
changeset
|
70 ngx_msec_t handshake_timeout; |
ad3d34ddfdcc
QUIC: "handshake_timeout" configuration parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
9107
diff
changeset
|
71 ngx_msec_t idle_timeout; |
8992 | 72 ngx_str_t host_key; |
73 size_t stream_buffer_size; | |
74 ngx_uint_t max_concurrent_streams_bidi; | |
75 ngx_uint_t max_concurrent_streams_uni; | |
76 ngx_uint_t active_connection_id_limit; | |
77 ngx_int_t stream_close_code; | |
78 ngx_int_t stream_reject_code_uni; | |
79 ngx_int_t stream_reject_code_bidi; | |
8924
d6ef13c5fd8e
QUIC: simplified configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8906
diff
changeset
|
80 |
9058
b0c2234aaa9f
QUIC: application init() callback.
Roman Arutyunyan <arut@nginx.com>
parents:
9055
diff
changeset
|
81 ngx_quic_init_pt init; |
9055
1192923be0aa
QUIC: idle mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9052
diff
changeset
|
82 ngx_quic_shutdown_pt shutdown; |
1192923be0aa
QUIC: idle mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9052
diff
changeset
|
83 |
8992 | 84 u_char av_token_key[NGX_QUIC_AV_KEY_LEN]; |
85 u_char sr_token_key[NGX_QUIC_SR_KEY_LEN]; | |
8481
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
8480
diff
changeset
|
86 } ngx_quic_conf_t; |
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
8480
diff
changeset
|
87 |
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
8480
diff
changeset
|
88 |
8208
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
8182
diff
changeset
|
89 struct ngx_quic_stream_s { |
8992 | 90 ngx_rbtree_node_t node; |
91 ngx_queue_t queue; | |
92 ngx_connection_t *parent; | |
93 ngx_connection_t *connection; | |
94 uint64_t id; | |
9052
2e51cf3ffd90
QUIC: defer stream removal until all its data is acked.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
95 uint64_t sent; |
8992 | 96 uint64_t acked; |
97 uint64_t send_max_data; | |
9010 | 98 uint64_t send_offset; |
99 uint64_t send_final_size; | |
8992 | 100 uint64_t recv_max_data; |
101 uint64_t recv_offset; | |
102 uint64_t recv_window; | |
103 uint64_t recv_last; | |
9010 | 104 uint64_t recv_final_size; |
9011
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
105 ngx_quic_buffer_t send; |
f9c788f3f5cc
QUIC: ngx_quic_buffer_t object.
Roman Arutyunyan <arut@nginx.com>
parents:
9010
diff
changeset
|
106 ngx_quic_buffer_t recv; |
8992 | 107 ngx_quic_stream_send_state_e send_state; |
108 ngx_quic_stream_recv_state_e recv_state; | |
9052
2e51cf3ffd90
QUIC: defer stream removal until all its data is acked.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
109 unsigned cancelable:1; |
2e51cf3ffd90
QUIC: defer stream removal until all its data is acked.
Roman Arutyunyan <arut@nginx.com>
parents:
9051
diff
changeset
|
110 unsigned fin_acked:1; |
8208
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
8182
diff
changeset
|
111 }; |
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
8182
diff
changeset
|
112 |
8168 | 113 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9016
diff
changeset
|
114 void ngx_quic_recvmsg(ngx_event_t *ev); |
8563
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8562
diff
changeset
|
115 void ngx_quic_run(ngx_connection_t *c, ngx_quic_conf_t *conf); |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8483
diff
changeset
|
116 ngx_connection_t *ngx_quic_open_stream(ngx_connection_t *c, ngx_uint_t bidi); |
8458
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
8438
diff
changeset
|
117 void ngx_quic_finalize_connection(ngx_connection_t *c, ngx_uint_t err, |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
8438
diff
changeset
|
118 const char *reason); |
8724
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8711
diff
changeset
|
119 void ngx_quic_shutdown_connection(ngx_connection_t *c, ngx_uint_t err, |
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8711
diff
changeset
|
120 const char *reason); |
8703
d710c457171c
QUIC: added ability to reset a stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8694
diff
changeset
|
121 ngx_int_t ngx_quic_reset_stream(ngx_connection_t *c, ngx_uint_t err); |
8890
b4c7853b0488
QUIC: added shutdown support in stream proxy.
Vladimir Homutov <vl@nginx.com>
parents:
8855
diff
changeset
|
122 ngx_int_t ngx_quic_shutdown_stream(ngx_connection_t *c, int how); |
9051
37d5dddabaea
QUIC: reusable mode for main connection.
Roman Arutyunyan <arut@nginx.com>
parents:
9017
diff
changeset
|
123 void ngx_quic_cancelable_stream(ngx_connection_t *c); |
8628
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
8626
diff
changeset
|
124 ngx_int_t ngx_quic_get_packet_dcid(ngx_log_t *log, u_char *data, size_t len, |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
8626
diff
changeset
|
125 ngx_str_t *dcid); |
8755
b4e6b7049984
QUIC: normalize header inclusion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8754
diff
changeset
|
126 ngx_int_t ngx_quic_derive_key(ngx_log_t *log, const char *label, |
b4e6b7049984
QUIC: normalize header inclusion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8754
diff
changeset
|
127 ngx_str_t *secret, ngx_str_t *salt, u_char *out, size_t len); |
8167
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 |
5d91389e0fd3
Initial QUIC support in http.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 #endif /* _NGX_EVENT_QUIC_H_INCLUDED_ */ |