Mercurial > hg > nginx-quic
annotate src/event/ngx_event_quic.c @ 8135:eacca87c476e quic
QUIC: updated c->log->action strings to reflect proper state.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 07 Oct 2020 13:38:17 +0300 |
parents | 2b11bd029815 |
children | b38b41127489 |
rev | line source |
---|---|
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
2 /* |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
4 */ |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
5 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
6 |
7637 | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
9 #include <ngx_event.h> |
8004
d0ac4449a07f
QUIC: fixed bulding perl module by reducing header pollution.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8001
diff
changeset
|
10 #include <ngx_event_quic_transport.h> |
d0ac4449a07f
QUIC: fixed bulding perl module by reducing header pollution.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8001
diff
changeset
|
11 #include <ngx_event_quic_protection.h> |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
12 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
13 |
7773
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
14 /* 0-RTT and 1-RTT data exist in the same packet number space, |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
15 * so we have 3 packet number spaces: |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
16 * |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
17 * 0 - Initial |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
18 * 1 - Handshake |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
19 * 2 - 0-RTT and 1-RTT |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
20 */ |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
21 #define ngx_quic_get_send_ctx(qc, level) \ |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
22 ((level) == ssl_encryption_initial) ? &((qc)->send_ctx[0]) \ |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
23 : (((level) == ssl_encryption_handshake) ? &((qc)->send_ctx[1]) \ |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
24 : &((qc)->send_ctx[2])) |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
25 |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
26 #define NGX_QUIC_SEND_CTX_LAST (NGX_QUIC_ENCRYPTION_LAST - 1) |
7773
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
27 |
7780
de8981bf2dd5
Advertizing MAX_STREAMS (0x12) credit in advance.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7778
diff
changeset
|
28 #define NGX_QUIC_STREAMS_INC 16 |
de8981bf2dd5
Advertizing MAX_STREAMS (0x12) credit in advance.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7778
diff
changeset
|
29 #define NGX_QUIC_STREAMS_LIMIT (1ULL < 60) |
de8981bf2dd5
Advertizing MAX_STREAMS (0x12) credit in advance.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7778
diff
changeset
|
30 |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
31 /* |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
32 * 7.4. Cryptographic Message Buffering |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
33 * Implementations MUST support buffering at least 4096 bytes of data |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
34 */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
35 #define NGX_QUIC_MAX_BUFFERED 65535 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
36 |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
37 #define NGX_QUIC_STREAM_GONE (void *) -1 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
38 |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
39 /* |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
40 * Endpoints MUST discard packets that are too small to be valid QUIC |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
41 * packets. With the set of AEAD functions defined in [QUIC-TLS], |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
42 * packets that are smaller than 21 bytes are never valid. |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
43 */ |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
44 #define NGX_QUIC_MIN_PKT_LEN 21 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
45 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
46 #define NGX_QUIC_MIN_SR_PACKET 43 /* 5 random + 16 srt + 22 padding */ |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
47 #define NGX_QUIC_MAX_SR_PACKET 1200 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
48 |
7773
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
49 |
7691 | 50 typedef struct { |
51 ngx_rbtree_t tree; | |
52 ngx_rbtree_node_t sentinel; | |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
53 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
54 uint64_t received; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
55 uint64_t sent; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
56 uint64_t recv_max_data; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
57 uint64_t send_max_data; |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
58 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
59 uint64_t server_max_streams_uni; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
60 uint64_t server_max_streams_bidi; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
61 uint64_t server_streams_uni; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
62 uint64_t server_streams_bidi; |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
63 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
64 uint64_t client_max_streams_uni; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
65 uint64_t client_max_streams_bidi; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
66 uint64_t client_streams_uni; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
67 uint64_t client_streams_bidi; |
7691 | 68 } ngx_quic_streams_t; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
69 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
70 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
71 typedef struct { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
72 size_t in_flight; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
73 size_t window; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
74 size_t ssthresh; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
75 ngx_msec_t recovery_start; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
76 } ngx_quic_congestion_t; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
77 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
78 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
79 /* |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
80 * 12.3. Packet Numbers |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
81 * |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
82 * Conceptually, a packet number space is the context in which a packet |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
83 * can be processed and acknowledged. Initial packets can only be sent |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
84 * with Initial packet protection keys and acknowledged in packets which |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
85 * are also Initial packets. |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
86 */ |
7773
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
87 typedef struct { |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
88 ngx_quic_secret_t client_secret; |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
89 ngx_quic_secret_t server_secret; |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
90 |
7878 | 91 uint64_t pnum; /* to be sent */ |
92 uint64_t largest_ack; /* received from peer */ | |
93 uint64_t largest_pn; /* received from peer */ | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
94 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
95 ngx_queue_t frames; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
96 ngx_queue_t sent; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
97 } ngx_quic_send_ctx_t; |
7773
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
98 |
dc7ac778aafe
Introduced packet namespace in QUIC connection.
Vladimir Homutov <vl@nginx.com>
parents:
7772
diff
changeset
|
99 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
100 struct ngx_quic_connection_s { |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
101 ngx_str_t scid; /* initial client ID */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
102 ngx_str_t dcid; /* server (our own) ID */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
103 ngx_str_t odcid; /* original server ID */ |
7691 | 104 ngx_str_t token; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
105 |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
106 ngx_queue_t client_ids; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
107 ngx_queue_t free_client_ids; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
108 ngx_uint_t nclient_ids; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
109 uint64_t max_retired_seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
110 uint64_t curr_seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
111 |
7726
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
112 ngx_uint_t client_tp_done; |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
113 ngx_quic_tp_t tp; |
7731
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
114 ngx_quic_tp_t ctp; |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
115 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
116 ngx_quic_send_ctx_t send_ctx[NGX_QUIC_SEND_CTX_LAST]; |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
117 ngx_quic_secrets_t keys[NGX_QUIC_ENCRYPTION_LAST]; |
7785
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
118 ngx_quic_secrets_t next_key; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
119 ngx_quic_frames_stream_t crypto[NGX_QUIC_ENCRYPTION_LAST]; |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
120 |
7999
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
121 ngx_quic_conf_t *conf; |
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
122 |
7775 | 123 ngx_event_t push; |
7990 | 124 ngx_event_t pto; |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
125 ngx_event_t close; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
126 ngx_queue_t free_frames; |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
127 ngx_msec_t last_cc; |
7752 | 128 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
129 ngx_msec_t latest_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
130 ngx_msec_t avg_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
131 ngx_msec_t min_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
132 ngx_msec_t rttvar; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
133 |
8056
f9b1a4e52597
QUIC: changed c->quic->pto_count type to ngx_uint_t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8055
diff
changeset
|
134 ngx_uint_t pto_count; |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
135 |
7752 | 136 #if (NGX_DEBUG) |
137 ngx_uint_t nframes; | |
138 #endif | |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
139 |
7691 | 140 ngx_quic_streams_t streams; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
141 ngx_quic_congestion_t congestion; |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
142 size_t received; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
143 |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
144 ngx_uint_t error; |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
145 enum ssl_encryption_level_t error_level; |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
146 ngx_uint_t error_ftype; |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
147 const char *error_reason; |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
148 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
149 unsigned error_app:1; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
150 unsigned send_timer_set:1; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
151 unsigned closing:1; |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
152 unsigned draining:1; |
7785
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
153 unsigned key_phase:1; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
154 unsigned in_retry:1; |
7874
1245e274b9ba
Avoided excessive definitions for connection state.
Vladimir Homutov <vl@nginx.com>
parents:
7871
diff
changeset
|
155 unsigned initialized:1; |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
156 unsigned validated:1; |
7691 | 157 }; |
7672
8d6ac639feac
Added support of multiple QUIC packets in single datagram.
Vladimir Homutov <vl@nginx.com>
parents:
7671
diff
changeset
|
158 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
159 |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
160 typedef struct { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
161 ngx_queue_t queue; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
162 uint64_t seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
163 size_t len; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
164 u_char id[NGX_QUIC_CID_LEN_MAX]; |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
165 u_char sr_token[NGX_QUIC_SR_TOKEN_LEN]; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
166 } ngx_quic_client_id_t; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
167 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
168 |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
169 typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
170 ngx_quic_frame_t *frame, void *data); |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
171 |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
172 |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
173 #if BORINGSSL_API_VERSION >= 10 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
174 static int ngx_quic_set_read_secret(ngx_ssl_conn_t *ssl_conn, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
175 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
176 const uint8_t *secret, size_t secret_len); |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
177 static int ngx_quic_set_write_secret(ngx_ssl_conn_t *ssl_conn, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
178 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
179 const uint8_t *secret, size_t secret_len); |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
180 #else |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
181 static int ngx_quic_set_encryption_secrets(ngx_ssl_conn_t *ssl_conn, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
182 enum ssl_encryption_level_t level, const uint8_t *read_secret, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
183 const uint8_t *write_secret, size_t secret_len); |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
184 #endif |
7691 | 185 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
186 static int ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
187 enum ssl_encryption_level_t level, const uint8_t *data, size_t len); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
188 static int ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
189 static int ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
190 enum ssl_encryption_level_t level, uint8_t alert); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
191 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
192 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
193 static ngx_quic_connection_t *ngx_quic_new_connection(ngx_connection_t *c, |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
194 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
195 static ngx_int_t ngx_quic_send_stateless_reset(ngx_connection_t *c, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
196 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
197 static ngx_int_t ngx_quic_process_stateless_reset(ngx_connection_t *c, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
198 ngx_quic_header_t *pkt); |
8060
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
199 static ngx_int_t ngx_quic_negotiate_version(ngx_connection_t *c, |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
200 ngx_quic_header_t *inpkt); |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
201 static ngx_int_t ngx_quic_new_dcid(ngx_connection_t *c, |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
202 ngx_quic_connection_t *qc, ngx_str_t *odcid); |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
203 static ngx_int_t ngx_quic_send_retry(ngx_connection_t *c); |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
204 static ngx_int_t ngx_quic_new_token(ngx_connection_t *c, ngx_str_t *token); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
205 static ngx_int_t ngx_quic_validate_token(ngx_connection_t *c, |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
206 ngx_quic_header_t *pkt); |
7691 | 207 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); |
7931
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
208 static ngx_inline size_t ngx_quic_max_udp_payload(ngx_connection_t *c); |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
209 static void ngx_quic_input_handler(ngx_event_t *rev); |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
210 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
211 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
212 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
213 static void ngx_quic_close_timer_handler(ngx_event_t *ev); |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
214 static ngx_int_t ngx_quic_close_streams(ngx_connection_t *c, |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
215 ngx_quic_connection_t *qc); |
7691 | 216 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
217 static ngx_int_t ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
218 ngx_quic_conf_t *conf); |
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
219 static ngx_int_t ngx_quic_process_packet(ngx_connection_t *c, |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
220 ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
221 static ngx_int_t ngx_quic_init_secrets(ngx_connection_t *c); |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
222 static void ngx_quic_discard_ctx(ngx_connection_t *c, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
223 enum ssl_encryption_level_t level); |
7838 | 224 static ngx_int_t ngx_quic_check_peer(ngx_quic_connection_t *qc, |
225 ngx_quic_header_t *pkt); | |
7691 | 226 static ngx_int_t ngx_quic_payload_handler(ngx_connection_t *c, |
227 ngx_quic_header_t *pkt); | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
228 static ngx_int_t ngx_quic_send_ack(ngx_connection_t *c, ngx_quic_header_t *pkt); |
7988
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
229 static ngx_int_t ngx_quic_ack_delay(ngx_connection_t *c, |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
230 struct timeval *received, enum ssl_encryption_level_t level); |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
231 static ngx_int_t ngx_quic_send_cc(ngx_connection_t *c); |
7861
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
232 static ngx_int_t ngx_quic_send_new_token(ngx_connection_t *c); |
7691 | 233 |
234 static ngx_int_t ngx_quic_handle_ack_frame(ngx_connection_t *c, | |
235 ngx_quic_header_t *pkt, ngx_quic_ack_frame_t *f); | |
7792 | 236 static ngx_int_t ngx_quic_handle_ack_frame_range(ngx_connection_t *c, |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
237 ngx_quic_send_ctx_t *ctx, uint64_t min, uint64_t max, |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
238 ngx_msec_t *send_time); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
239 static void ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack, |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
240 enum ssl_encryption_level_t level, ngx_msec_t send_time); |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
241 static ngx_inline ngx_msec_t ngx_quic_pto(ngx_connection_t *c, |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
242 ngx_quic_send_ctx_t *ctx); |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
243 static void ngx_quic_handle_stream_ack(ngx_connection_t *c, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
244 ngx_quic_frame_t *f); |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
245 |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
246 static ngx_int_t ngx_quic_handle_ordered_frame(ngx_connection_t *c, |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
247 ngx_quic_frames_stream_t *fs, ngx_quic_frame_t *frame, |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
248 ngx_quic_frame_handler_pt handler, void *data); |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
249 static ngx_int_t ngx_quic_adjust_frame_offset(ngx_connection_t *c, |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
250 ngx_quic_frame_t *f, uint64_t offset_in); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
251 static ngx_int_t ngx_quic_buffer_frame(ngx_connection_t *c, |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
252 ngx_quic_frames_stream_t *stream, ngx_quic_frame_t *f); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
253 |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
254 static ngx_int_t ngx_quic_handle_crypto_frame(ngx_connection_t *c, |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
255 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
256 static ngx_int_t ngx_quic_crypto_input(ngx_connection_t *c, |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
257 ngx_quic_frame_t *frame, void *data); |
7691 | 258 static ngx_int_t ngx_quic_handle_stream_frame(ngx_connection_t *c, |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
259 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
260 static ngx_int_t ngx_quic_stream_input(ngx_connection_t *c, |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
261 ngx_quic_frame_t *frame, void *data); |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
262 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
263 static ngx_int_t ngx_quic_handle_max_data_frame(ngx_connection_t *c, |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
264 ngx_quic_max_data_frame_t *f); |
7711
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
265 static ngx_int_t ngx_quic_handle_streams_blocked_frame(ngx_connection_t *c, |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
266 ngx_quic_header_t *pkt, ngx_quic_streams_blocked_frame_t *f); |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
267 static ngx_int_t ngx_quic_handle_stream_data_blocked_frame(ngx_connection_t *c, |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
268 ngx_quic_header_t *pkt, ngx_quic_stream_data_blocked_frame_t *f); |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
269 static ngx_int_t ngx_quic_handle_max_stream_data_frame(ngx_connection_t *c, |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
270 ngx_quic_header_t *pkt, ngx_quic_max_stream_data_frame_t *f); |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
271 static ngx_int_t ngx_quic_handle_reset_stream_frame(ngx_connection_t *c, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
272 ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f); |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
273 static ngx_int_t ngx_quic_handle_stop_sending_frame(ngx_connection_t *c, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
274 ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f); |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
275 static ngx_int_t ngx_quic_handle_max_streams_frame(ngx_connection_t *c, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
276 ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f); |
8069
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
277 static ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
278 ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f); |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
279 static ngx_int_t ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c, |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
280 ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
281 static ngx_int_t ngx_quic_retire_connection_id(ngx_connection_t *c, |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
282 enum ssl_encryption_level_t level, uint64_t seqnum); |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
283 static ngx_quic_client_id_t *ngx_quic_alloc_connection_id(ngx_connection_t *c, |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
284 ngx_quic_connection_t *qc); |
7691 | 285 |
286 static void ngx_quic_queue_frame(ngx_quic_connection_t *qc, | |
287 ngx_quic_frame_t *frame); | |
288 | |
289 static ngx_int_t ngx_quic_output(ngx_connection_t *c); | |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
290 static ngx_int_t ngx_quic_output_frames(ngx_connection_t *c, |
7809
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
291 ngx_quic_send_ctx_t *ctx); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
292 static void ngx_quic_free_frames(ngx_connection_t *c, ngx_queue_t *frames); |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
293 static ngx_int_t ngx_quic_send_frames(ngx_connection_t *c, |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
294 ngx_quic_send_ctx_t *ctx, ngx_queue_t *frames); |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
295 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
296 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt, |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
297 ngx_quic_send_ctx_t *ctx); |
7990 | 298 static void ngx_quic_pto_handler(ngx_event_t *ev); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
299 static void ngx_quic_lost_handler(ngx_event_t *ev); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
300 static ngx_int_t ngx_quic_detect_lost(ngx_connection_t *c); |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
301 static void ngx_quic_resend_frames(ngx_connection_t *c, |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
302 ngx_quic_send_ctx_t *ctx); |
7775 | 303 static void ngx_quic_push_handler(ngx_event_t *ev); |
7691 | 304 |
305 static void ngx_quic_rbtree_insert_stream(ngx_rbtree_node_t *temp, | |
306 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); | |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
307 static ngx_quic_stream_t *ngx_quic_find_stream(ngx_rbtree_t *rbtree, |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
308 uint64_t id); |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
309 static ngx_quic_stream_t *ngx_quic_create_client_stream(ngx_connection_t *c, |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
310 uint64_t id); |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
311 static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c, |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
312 uint64_t id, size_t rcvbuf_size); |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
313 static ssize_t ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, |
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
314 size_t size); |
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
315 static ssize_t ngx_quic_stream_send(ngx_connection_t *c, u_char *buf, |
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
316 size_t size); |
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
317 static ngx_chain_t *ngx_quic_stream_send_chain(ngx_connection_t *c, |
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
318 ngx_chain_t *in, off_t limit); |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
319 static size_t ngx_quic_max_stream_frame(ngx_quic_connection_t *qc); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
320 static size_t ngx_quic_max_stream_flow(ngx_connection_t *c); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
321 static void ngx_quic_stream_cleanup_handler(void *data); |
7752 | 322 static ngx_quic_frame_t *ngx_quic_alloc_frame(ngx_connection_t *c, size_t size); |
323 static void ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame); | |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
324 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
325 static void ngx_quic_congestion_ack(ngx_connection_t *c, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
326 ngx_quic_frame_t *frame); |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
327 static void ngx_quic_congestion_lost(ngx_connection_t *c, |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
328 ngx_quic_frame_t *frame); |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
329 |
7691 | 330 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
331 static SSL_QUIC_METHOD quic_method = { |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
332 #if BORINGSSL_API_VERSION >= 10 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
333 ngx_quic_set_read_secret, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
334 ngx_quic_set_write_secret, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
335 #else |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
336 ngx_quic_set_encryption_secrets, |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
337 #endif |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
338 ngx_quic_add_handshake_data, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
339 ngx_quic_flush_flight, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
340 ngx_quic_send_alert, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
341 }; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
342 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
343 |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
344 #if BORINGSSL_API_VERSION >= 10 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
345 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
346 static int |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
347 ngx_quic_set_read_secret(ngx_ssl_conn_t *ssl_conn, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
348 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
349 const uint8_t *rsecret, size_t secret_len) |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
350 { |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
351 ngx_connection_t *c; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
352 ngx_quic_secrets_t *keys; |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
353 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
354 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
355 |
7836 | 356 #ifdef NGX_QUIC_DEBUG_CRYPTO |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
357 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
358 "quic ngx_quic_set_read_secret() level:%d", level); |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
359 ngx_quic_hexdump(c->log, "quic read secret", rsecret, secret_len); |
7836 | 360 #endif |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
361 |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
362 keys = &c->quic->keys[level]; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
363 |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
364 return ngx_quic_set_encryption_secret(c->pool, ssl_conn, level, |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
365 rsecret, secret_len, |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
366 &keys->client); |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
367 } |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
368 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
369 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
370 static int |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
371 ngx_quic_set_write_secret(ngx_ssl_conn_t *ssl_conn, |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
372 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
373 const uint8_t *wsecret, size_t secret_len) |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
374 { |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
375 ngx_connection_t *c; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
376 ngx_quic_secrets_t *keys; |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
377 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
378 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
379 |
7836 | 380 #ifdef NGX_QUIC_DEBUG_CRYPTO |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
381 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
382 "quic ngx_quic_set_write_secret() level:%d", level); |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
383 ngx_quic_hexdump(c->log, "quic write secret", wsecret, secret_len); |
7836 | 384 #endif |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
385 |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
386 keys = &c->quic->keys[level]; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
387 |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
388 return ngx_quic_set_encryption_secret(c->pool, ssl_conn, level, |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
389 wsecret, secret_len, |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
390 &keys->server); |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
391 } |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
392 |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
393 #else |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
394 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
395 static int |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
396 ngx_quic_set_encryption_secrets(ngx_ssl_conn_t *ssl_conn, |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
397 enum ssl_encryption_level_t level, const uint8_t *rsecret, |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
398 const uint8_t *wsecret, size_t secret_len) |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
399 { |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
400 ngx_int_t rc; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
401 ngx_connection_t *c; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
402 ngx_quic_secrets_t *keys; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
403 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
404 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
405 |
7836 | 406 #ifdef NGX_QUIC_DEBUG_CRYPTO |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
407 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
408 "quic ngx_quic_set_encryption_secrets() level:%d", level); |
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
409 ngx_quic_hexdump(c->log, "quic read", rsecret, secret_len); |
7836 | 410 #endif |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
411 |
7793
0ae50d90658a
Fixed build with OpenSSL using old callbacks API.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7792
diff
changeset
|
412 keys = &c->quic->keys[level]; |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
413 |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
414 rc = ngx_quic_set_encryption_secret(c->pool, ssl_conn, level, |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
415 rsecret, secret_len, |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
416 &keys->client); |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
417 if (rc != 1) { |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
418 return rc; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
419 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
420 |
7769
2ac03e80d013
TLS Early Data key derivation support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7768
diff
changeset
|
421 if (level == ssl_encryption_early_data) { |
2ac03e80d013
TLS Early Data key derivation support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7768
diff
changeset
|
422 return 1; |
2ac03e80d013
TLS Early Data key derivation support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7768
diff
changeset
|
423 } |
2ac03e80d013
TLS Early Data key derivation support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7768
diff
changeset
|
424 |
7836 | 425 #ifdef NGX_QUIC_DEBUG_CRYPTO |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
426 ngx_quic_hexdump(c->log, "quic write", wsecret, secret_len); |
7836 | 427 #endif |
7769
2ac03e80d013
TLS Early Data key derivation support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7768
diff
changeset
|
428 |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
429 return ngx_quic_set_encryption_secret(c->pool, ssl_conn, level, |
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
430 wsecret, secret_len, |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
431 &keys->server); |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
432 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
433 |
7670
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
434 #endif |
9e0c30e1f7fb
Compatibility with BoringSSL revised QUIC encryption secret APIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7669
diff
changeset
|
435 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
436 |
7650
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
437 static int |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
438 ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn, |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
439 enum ssl_encryption_level_t level, const uint8_t *data, size_t len) |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
440 { |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
441 u_char *p, *end; |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
442 size_t client_params_len, fsize, limit; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
443 const uint8_t *client_params; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
444 ngx_quic_frame_t *frame; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
445 ngx_connection_t *c; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
446 ngx_quic_connection_t *qc; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
447 ngx_quic_frames_stream_t *fs; |
7650
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
448 |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
449 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
450 qc = c->quic; |
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
451 |
7652
0a2683df5f11
Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents:
7651
diff
changeset
|
452 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 453 "quic ngx_quic_add_handshake_data"); |
7650
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
454 |
7726
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
455 if (!qc->client_tp_done) { |
7933 | 456 /* |
457 * things to do once during handshake: check ALPN and transport | |
458 * parameters; we want to break handshake if something is wrong | |
459 * here; | |
460 */ | |
461 | |
462 #if defined(TLSEXT_TYPE_application_layer_protocol_negotiation) | |
8000
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
463 if (qc->conf->require_alpn) { |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
464 unsigned int len; |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
465 const unsigned char *data; |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
466 |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
467 SSL_get0_alpn_selected(c->ssl->connection, &data, &len); |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
468 |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
469 if (len == 0) { |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
470 qc->error = 0x100 + SSL_AD_NO_APPLICATION_PROTOCOL; |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
471 qc->error_reason = "unsupported protocol in ALPN extension"; |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
472 |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
473 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
474 "quic unsupported protocol in ALPN extension"); |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
475 return 0; |
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
476 } |
7933 | 477 } |
478 #endif | |
7726
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
479 |
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
480 SSL_get_peer_quic_transport_params(ssl_conn, &client_params, |
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
481 &client_params_len); |
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
482 |
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
483 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 484 "quic SSL_get_peer_quic_transport_params():" |
485 " params_len %ui", client_params_len); | |
7726
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
486 |
7930
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
487 if (client_params_len == 0) { |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
488 /* quic-tls 8.2 */ |
7942
97adb87f149b
Get rid of hardcoded numbers used for quic handshake errors.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7941
diff
changeset
|
489 qc->error = NGX_QUIC_ERR_CRYPTO(SSL_AD_MISSING_EXTENSION); |
7930
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
490 qc->error_reason = "missing transport parameters"; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
491 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
492 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
493 "missing transport parameters"); |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
494 return 0; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
495 } |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
496 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
497 p = (u_char *) client_params; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
498 end = p + client_params_len; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
499 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
500 if (ngx_quic_parse_transport_params(p, end, &qc->ctp, c->log) |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
501 != NGX_OK) |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
502 { |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
503 qc->error = NGX_QUIC_ERR_TRANSPORT_PARAMETER_ERROR; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
504 qc->error_reason = "failed to process transport parameters"; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
505 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
506 return 0; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
507 } |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
508 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
509 if (qc->ctp.max_idle_timeout > 0 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
510 && qc->ctp.max_idle_timeout < qc->tp.max_idle_timeout) |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
511 { |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
512 qc->tp.max_idle_timeout = qc->ctp.max_idle_timeout; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
513 } |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
514 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
515 if (qc->ctp.max_udp_payload_size < NGX_QUIC_MIN_INITIAL_SIZE |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
516 || qc->ctp.max_udp_payload_size > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE) |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
517 { |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
518 qc->error = NGX_QUIC_ERR_TRANSPORT_PARAMETER_ERROR; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
519 qc->error_reason = "invalid maximum packet size"; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
520 |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
521 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
522 "quic maximum packet size is invalid"); |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
523 return 0; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
524 } |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
525 |
7931
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
526 if (qc->ctp.max_udp_payload_size > ngx_quic_max_udp_payload(c)) { |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
527 qc->ctp.max_udp_payload_size = ngx_quic_max_udp_payload(c); |
7930
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
528 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
529 "quic client maximum packet size truncated"); |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
530 } |
7927
391d06a51bc0
Limited max udp payload size for outgoing packets.
Vladimir Homutov <vl@nginx.com>
parents:
7926
diff
changeset
|
531 |
7912
6633f17044eb
QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7910
diff
changeset
|
532 #if (NGX_QUIC_DRAFT_VERSION >= 28) |
7930
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
533 if (qc->scid.len != qc->ctp.initial_scid.len |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
534 || ngx_memcmp(qc->scid.data, qc->ctp.initial_scid.data, |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
535 qc->scid.len) != 0) |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
536 { |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
537 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
538 "quic client initial_source_connection_id " |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
539 "mismatch"); |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
540 return 0; |
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
541 } |
7912
6633f17044eb
QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7910
diff
changeset
|
542 #endif |
6633f17044eb
QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7910
diff
changeset
|
543 |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
544 qc->streams.server_max_streams_bidi = qc->ctp.initial_max_streams_bidi; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
545 qc->streams.server_max_streams_uni = qc->ctp.initial_max_streams_uni; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
546 |
7930
5bc9229ec4cf
QUIC: raise error on missing transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7929
diff
changeset
|
547 qc->client_tp_done = 1; |
7726
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
548 } |
f388c0ad3477
Added processing of client transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7725
diff
changeset
|
549 |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
550 /* |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
551 * we need to fit at least 1 frame into a packet, thus account head/tail; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
552 * 17 = 1 + 8x2 is max header for CRYPTO frame, with 1 byte for frame type |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
553 */ |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
554 limit = qc->ctp.max_udp_payload_size - NGX_QUIC_MAX_LONG_HEADER - 17 |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
555 - EVP_GCM_TLS_TAG_LEN; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
556 |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
557 fs = &qc->crypto[level]; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
558 |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
559 p = (u_char *) data; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
560 end = (u_char *) data + len; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
561 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
562 while (p < end) { |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
563 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
564 fsize = ngx_min(limit, (size_t) (end - p)); |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
565 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
566 frame = ngx_quic_alloc_frame(c, fsize); |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
567 if (frame == NULL) { |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
568 return 0; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
569 } |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
570 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
571 ngx_memcpy(frame->data, p, fsize); |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
572 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
573 frame->level = level; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
574 frame->type = NGX_QUIC_FT_CRYPTO; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
575 frame->u.crypto.offset = fs->sent; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
576 frame->u.crypto.length = fsize; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
577 frame->u.crypto.data = frame->data; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
578 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
579 fs->sent += fsize; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
580 p += fsize; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
581 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
582 ngx_sprintf(frame->info, "crypto, generated by SSL len=%ui level=%d", |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
583 fsize, level); |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
584 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
585 ngx_quic_queue_frame(qc, frame); |
7652
0a2683df5f11
Implemented improved version of quic_output().
Vladimir Homutov <vl@nginx.com>
parents:
7651
diff
changeset
|
586 } |
7650
ec1f84996990
Split frame and packet generation into separate steps.
Vladimir Homutov <vl@nginx.com>
parents:
7649
diff
changeset
|
587 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
588 return 1; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
589 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
590 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
591 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
592 static int |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
593 ngx_quic_flush_flight(ngx_ssl_conn_t *ssl_conn) |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
594 { |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
595 #if (NGX_DEBUG) |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
596 ngx_connection_t *c; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
597 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
598 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
599 |
7836 | 600 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
601 "quic ngx_quic_flush_flight()"); | |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
602 #endif |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
603 return 1; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
604 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
605 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
606 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
607 static int |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
608 ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, enum ssl_encryption_level_t level, |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
609 uint8_t alert) |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
610 { |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
611 ngx_connection_t *c; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
612 ngx_quic_connection_t *qc; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
613 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
614 c = ngx_ssl_get_connection((ngx_ssl_conn_t *) ssl_conn); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
615 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
616 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 617 "quic ngx_quic_send_alert(), lvl=%d, alert=%d", |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
618 (int) level, (int) alert); |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
619 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
620 qc = c->quic; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
621 if (qc == NULL) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
622 return 1; |
7701
552d6868091b
Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7700
diff
changeset
|
623 } |
552d6868091b
Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7700
diff
changeset
|
624 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
625 qc->error_level = level; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
626 qc->error = NGX_QUIC_ERR_CRYPTO(alert); |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
627 qc->error_reason = "TLS alert"; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
628 qc->error_app = 0; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
629 qc->error_ftype = 0; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
630 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
631 if (ngx_quic_send_cc(c) != NGX_OK) { |
7701
552d6868091b
Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7700
diff
changeset
|
632 return 0; |
552d6868091b
Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7700
diff
changeset
|
633 } |
552d6868091b
Implemented send_alert callback, CONNECTION_CLOSE writer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7700
diff
changeset
|
634 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
635 return 1; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
636 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
637 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
638 |
7691 | 639 void |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
640 ngx_quic_run(ngx_connection_t *c, ngx_quic_conf_t *conf) |
7691 | 641 { |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
642 ngx_int_t rc; |
7691 | 643 |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
644 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic run"); |
7691 | 645 |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
646 rc = ngx_quic_input(c, c->buffer, conf); |
8074
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
647 if (rc != NGX_OK) { |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
648 ngx_quic_close_connection(c, rc == NGX_DECLINED ? NGX_DONE : NGX_ERROR); |
7691 | 649 return; |
650 } | |
651 | |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
652 ngx_add_timer(c->read, c->quic->in_retry ? NGX_QUIC_RETRY_TIMEOUT |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
653 : c->quic->tp.max_idle_timeout); |
7691 | 654 |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
655 c->read->handler = ngx_quic_input_handler; |
7691 | 656 |
657 return; | |
658 } | |
659 | |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
660 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
661 static ngx_quic_connection_t * |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
662 ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf, |
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
663 ngx_quic_header_t *pkt) |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
664 { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
665 ngx_uint_t i; |
7731
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
666 ngx_quic_tp_t *ctp; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
667 ngx_quic_client_id_t *cid; |
7691 | 668 ngx_quic_connection_t *qc; |
7864
eebdda507ec3
Added tests for connection id lengths in initial packet.
Vladimir Homutov <vl@nginx.com>
parents:
7863
diff
changeset
|
669 |
7691 | 670 qc = ngx_pcalloc(c->pool, sizeof(ngx_quic_connection_t)); |
671 if (qc == NULL) { | |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
672 return NULL; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
673 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
674 |
7691 | 675 ngx_rbtree_init(&qc->streams.tree, &qc->streams.sentinel, |
676 ngx_quic_rbtree_insert_stream); | |
677 | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
678 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
679 ngx_queue_init(&qc->send_ctx[i].frames); |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
680 ngx_queue_init(&qc->send_ctx[i].sent); |
7816
aba84d9ab256
Parsing of truncated packet numbers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7815
diff
changeset
|
681 qc->send_ctx[i].largest_pn = (uint64_t) -1; |
8050
6e1c88f82280
QUIC: changed ctx->largest_ack initial value to type maximum.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8027
diff
changeset
|
682 qc->send_ctx[i].largest_ack = (uint64_t) -1; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
683 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
684 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
685 for (i = 0; i < NGX_QUIC_ENCRYPTION_LAST; i++) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
686 ngx_queue_init(&qc->crypto[i].frames); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
687 } |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
688 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
689 ngx_queue_init(&qc->free_frames); |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
690 ngx_queue_init(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
691 ngx_queue_init(&qc->free_client_ids); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
692 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
693 qc->avg_rtt = NGX_QUIC_INITIAL_RTT; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
694 qc->rttvar = NGX_QUIC_INITIAL_RTT / 2; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
695 qc->min_rtt = NGX_TIMER_INFINITE; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
696 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
697 /* |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
698 * qc->latest_rtt = 0 |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
699 * qc->nclient_ids = 0 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
700 * qc->max_retired_seqnum = 0 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
701 */ |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
702 |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
703 qc->received = pkt->raw->last - pkt->raw->start; |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
704 |
7990 | 705 qc->pto.log = c->log; |
706 qc->pto.data = c; | |
707 qc->pto.handler = ngx_quic_pto_handler; | |
708 qc->pto.cancelable = 1; | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
709 |
7775 | 710 qc->push.log = c->log; |
711 qc->push.data = c; | |
712 qc->push.handler = ngx_quic_push_handler; | |
713 qc->push.cancelable = 1; | |
714 | |
7999
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
715 qc->conf = conf; |
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
716 qc->tp = conf->tp; |
7691 | 717 |
7731
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
718 ctp = &qc->ctp; |
7931
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
719 ctp->max_udp_payload_size = ngx_quic_max_udp_payload(c); |
7731
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
720 ctp->ack_delay_exponent = NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT; |
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
721 ctp->max_ack_delay = NGX_QUIC_DEFAULT_MAX_ACK_DELAY; |
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
722 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
723 qc->streams.recv_max_data = qc->tp.initial_max_data; |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
724 |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
725 qc->streams.client_max_streams_uni = qc->tp.initial_max_streams_uni; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
726 qc->streams.client_max_streams_bidi = qc->tp.initial_max_streams_bidi; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
727 |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
728 qc->congestion.window = ngx_min(10 * qc->tp.max_udp_payload_size, |
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
729 ngx_max(2 * qc->tp.max_udp_payload_size, |
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
730 14720)); |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
731 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
732 qc->congestion.recovery_start = ngx_current_msec; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
733 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
734 if (ngx_quic_new_dcid(c, qc, &pkt->dcid) != NGX_OK) { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
735 return NULL; |
7691 | 736 } |
7845 | 737 |
7916
c206233d9c29
Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7912
diff
changeset
|
738 #if (NGX_QUIC_DRAFT_VERSION >= 28) |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
739 qc->tp.original_dcid = qc->odcid; |
7916
c206233d9c29
Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7912
diff
changeset
|
740 #endif |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
741 qc->tp.initial_scid = qc->dcid; |
7912
6633f17044eb
QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7910
diff
changeset
|
742 |
7691 | 743 qc->scid.len = pkt->scid.len; |
744 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len); | |
745 if (qc->scid.data == NULL) { | |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
746 return NULL; |
7691 | 747 } |
748 ngx_memcpy(qc->scid.data, pkt->scid.data, qc->scid.len); | |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
749 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
750 cid = ngx_quic_alloc_connection_id(c, qc); |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
751 if (cid == NULL) { |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
752 return NULL; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
753 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
754 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
755 cid->seqnum = 0; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
756 cid->len = pkt->scid.len; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
757 ngx_memcpy(cid->id, pkt->scid.data, pkt->scid.len); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
758 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
759 ngx_queue_insert_tail(&qc->client_ids, &cid->queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
760 qc->nclient_ids++; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
761 qc->curr_seqnum = 0; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
762 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
763 return qc; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
764 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
765 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
766 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
767 static ngx_int_t |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
768 ngx_quic_send_stateless_reset(ngx_connection_t *c, ngx_quic_conf_t *conf, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
769 ngx_quic_header_t *pkt) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
770 { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
771 u_char *token; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
772 size_t len, max; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
773 uint16_t rndbytes; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
774 u_char buf[NGX_QUIC_MAX_SR_PACKET]; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
775 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
776 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
777 "quic handle stateless reset output"); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
778 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
779 if (conf->sr_token_key.len == 0) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
780 return NGX_DECLINED; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
781 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
782 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
783 if (pkt->len <= NGX_QUIC_MIN_PKT_LEN) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
784 return NGX_DECLINED; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
785 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
786 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
787 if (pkt->len <= NGX_QUIC_MIN_SR_PACKET) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
788 len = pkt->len - 1; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
789 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
790 } else { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
791 max = ngx_min(NGX_QUIC_MAX_SR_PACKET, pkt->len * 3); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
792 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
793 if (RAND_bytes((u_char *) &rndbytes, sizeof(rndbytes)) != 1) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
794 return NGX_ERROR; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
795 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
796 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
797 len = (rndbytes % (max - NGX_QUIC_MIN_SR_PACKET + 1)) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
798 + NGX_QUIC_MIN_SR_PACKET; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
799 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
800 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
801 if (RAND_bytes(buf, len - NGX_QUIC_SR_TOKEN_LEN) != 1) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
802 return NGX_ERROR; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
803 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
804 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
805 buf[0] &= ~NGX_QUIC_PKT_LONG; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
806 buf[0] |= NGX_QUIC_PKT_FIXED_BIT; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
807 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
808 token = &buf[len - NGX_QUIC_SR_TOKEN_LEN]; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
809 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
810 if (ngx_quic_new_sr_token(c, &pkt->dcid, &conf->sr_token_key, token) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
811 != NGX_OK) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
812 { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
813 return NGX_ERROR; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
814 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
815 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
816 (void) c->send(c, buf, len); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
817 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
818 return NGX_DECLINED; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
819 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
820 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
821 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
822 static ngx_int_t |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
823 ngx_quic_process_stateless_reset(ngx_connection_t *c, ngx_quic_header_t *pkt) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
824 { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
825 u_char *tail, ch; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
826 ngx_uint_t i; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
827 ngx_queue_t *q; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
828 ngx_quic_client_id_t *cid; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
829 ngx_quic_connection_t *qc; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
830 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
831 qc = c->quic; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
832 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
833 /* A stateless reset uses an entire UDP datagram */ |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
834 if (pkt->raw->start != pkt->data) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
835 return NGX_DECLINED; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
836 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
837 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
838 tail = pkt->raw->last - NGX_QUIC_SR_TOKEN_LEN; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
839 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
840 for (q = ngx_queue_head(&qc->client_ids); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
841 q != ngx_queue_sentinel(&qc->client_ids); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
842 q = ngx_queue_next(q)) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
843 { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
844 cid = ngx_queue_data(q, ngx_quic_client_id_t, queue); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
845 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
846 if (cid->seqnum == 0) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
847 /* no stateless reset token in initial connection id */ |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
848 continue; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
849 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
850 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
851 /* constant time comparison */ |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
852 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
853 for (ch = 0, i = 0; i < NGX_QUIC_SR_TOKEN_LEN; i++) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
854 ch |= tail[i] ^ cid->sr_token[i]; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
855 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
856 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
857 if (ch == 0) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
858 return NGX_OK; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
859 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
860 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
861 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
862 return NGX_DECLINED; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
863 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
864 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
865 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
866 static ngx_int_t |
8060
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
867 ngx_quic_negotiate_version(ngx_connection_t *c, ngx_quic_header_t *inpkt) |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
868 { |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
869 size_t len; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
870 ngx_quic_header_t pkt; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
871 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
872 /* buffer size is calculated assuming a single supported version */ |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
873 static u_char buf[NGX_QUIC_MAX_LONG_HEADER + sizeof(uint32_t)]; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
874 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
875 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
876 "sending version negotiation packet"); |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
877 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
878 pkt.log = c->log; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
879 pkt.flags = NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_FIXED_BIT; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
880 pkt.dcid = inpkt->scid; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
881 pkt.scid = inpkt->dcid; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
882 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
883 len = ngx_quic_create_version_negotiation(&pkt, buf); |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
884 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
885 #ifdef NGX_QUIC_DEBUG_PACKETS |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
886 ngx_quic_hexdump(c->log, "quic vnego packet to send", buf, len); |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
887 #endif |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
888 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
889 (void) c->send(c, buf, len); |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
890 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
891 return NGX_ERROR; |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
892 } |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
893 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
894 |
fc89d02bdca2
QUIC: added version negotiation support.
Vladimir Homutov <vl@nginx.com>
parents:
8057
diff
changeset
|
895 static ngx_int_t |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
896 ngx_quic_new_dcid(ngx_connection_t *c, ngx_quic_connection_t *qc, |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
897 ngx_str_t *odcid) |
7845 | 898 { |
8095
2727d402e5a5
QUIC: switched to using fixed-length server connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8094
diff
changeset
|
899 qc->dcid.len = NGX_QUIC_SERVER_CID_LEN; |
2727d402e5a5
QUIC: switched to using fixed-length server connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8094
diff
changeset
|
900 qc->dcid.data = ngx_pnalloc(c->pool, NGX_QUIC_SERVER_CID_LEN); |
7859
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
901 if (qc->dcid.data == NULL) { |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
902 return NGX_ERROR; |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
903 } |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
904 |
8095
2727d402e5a5
QUIC: switched to using fixed-length server connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8094
diff
changeset
|
905 if (RAND_bytes(qc->dcid.data, NGX_QUIC_SERVER_CID_LEN) != 1) { |
7845 | 906 return NGX_ERROR; |
907 } | |
908 | |
7859
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
909 #ifdef NGX_QUIC_DEBUG_PACKETS |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
910 ngx_quic_hexdump(c->log, "quic server CID", qc->dcid.data, qc->dcid.len); |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
911 #endif |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
912 |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
913 qc->odcid.len = odcid->len; |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
914 qc->odcid.data = ngx_pstrdup(c->pool, odcid); |
b7704303a7e5
Server CID change refactored.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7858
diff
changeset
|
915 if (qc->odcid.data == NULL) { |
7845 | 916 return NGX_ERROR; |
917 } | |
918 | |
919 return NGX_OK; | |
920 } | |
921 | |
922 | |
923 static ngx_int_t | |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
924 ngx_quic_send_retry(ngx_connection_t *c) |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
925 { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
926 ssize_t len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
927 ngx_str_t res, token; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
928 ngx_quic_header_t pkt; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
929 u_char buf[NGX_QUIC_RETRY_BUFFER_SIZE]; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
930 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
931 if (ngx_quic_new_token(c, &token) != NGX_OK) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
932 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
933 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
934 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
935 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
936 pkt.flags = NGX_QUIC_PKT_FIXED_BIT | NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_RETRY; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
937 pkt.log = c->log; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
938 pkt.odcid = c->quic->odcid; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
939 pkt.dcid = c->quic->scid; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
940 pkt.scid = c->quic->dcid; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
941 pkt.token = token; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
942 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
943 res.data = buf; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
944 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
945 if (ngx_quic_encrypt(&pkt, NULL, &res) != NGX_OK) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
946 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
947 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
948 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
949 #ifdef NGX_QUIC_DEBUG_PACKETS |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
950 ngx_quic_hexdump(c->log, "quic packet to send", res.data, res.len); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
951 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
952 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
953 len = c->send(c, res.data, res.len); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
954 if (len == NGX_ERROR || (size_t) len != res.len) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
955 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
956 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
957 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
958 c->quic->token = token; |
7916
c206233d9c29
Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7912
diff
changeset
|
959 #if (NGX_QUIC_DRAFT_VERSION < 28) |
c206233d9c29
Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7912
diff
changeset
|
960 c->quic->tp.original_dcid = c->quic->odcid; |
c206233d9c29
Fixed transport parameters on a new connection with a valid token.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7912
diff
changeset
|
961 #endif |
7912
6633f17044eb
QUIC draft-28 transport parameters support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7910
diff
changeset
|
962 c->quic->tp.retry_scid = c->quic->dcid; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
963 c->quic->in_retry = 1; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
964 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
965 return NGX_OK; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
966 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
967 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
968 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
969 static ngx_int_t |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
970 ngx_quic_new_token(ngx_connection_t *c, ngx_str_t *token) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
971 { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
972 int len, iv_len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
973 u_char *data, *p, *key, *iv; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
974 ngx_msec_t now; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
975 EVP_CIPHER_CTX *ctx; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
976 const EVP_CIPHER *cipher; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
977 struct sockaddr_in *sin; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
978 #if (NGX_HAVE_INET6) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
979 struct sockaddr_in6 *sin6; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
980 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
981 u_char in[NGX_QUIC_MAX_TOKEN_SIZE]; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
982 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
983 switch (c->sockaddr->sa_family) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
984 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
985 #if (NGX_HAVE_INET6) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
986 case AF_INET6: |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
987 sin6 = (struct sockaddr_in6 *) c->sockaddr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
988 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
989 len = sizeof(struct in6_addr); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
990 data = sin6->sin6_addr.s6_addr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
991 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
992 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
993 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
994 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
995 #if (NGX_HAVE_UNIX_DOMAIN) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
996 case AF_UNIX: |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
997 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
998 len = ngx_min(c->addr_text.len, NGX_QUIC_MAX_TOKEN_SIZE - sizeof(now)); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
999 data = c->addr_text.data; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1000 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1001 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1002 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1003 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1004 default: /* AF_INET */ |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1005 sin = (struct sockaddr_in *) c->sockaddr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1006 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1007 len = sizeof(in_addr_t); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1008 data = (u_char *) &sin->sin_addr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1009 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1010 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1011 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1012 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1013 p = ngx_cpymem(in, data, len); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1014 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1015 now = ngx_current_msec; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1016 len += sizeof(now); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1017 ngx_memcpy(p, &now, sizeof(now)); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1018 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1019 cipher = EVP_aes_256_cbc(); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1020 iv_len = EVP_CIPHER_iv_length(cipher); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1021 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1022 token->len = iv_len + len + EVP_CIPHER_block_size(cipher); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1023 token->data = ngx_pnalloc(c->pool, token->len); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1024 if (token->data == NULL) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1025 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1026 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1027 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1028 ctx = EVP_CIPHER_CTX_new(); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1029 if (ctx == NULL) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1030 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1031 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1032 |
7999
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
1033 key = c->quic->conf->token_key; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1034 iv = token->data; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1035 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1036 if (RAND_bytes(iv, iv_len) <= 0 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1037 || !EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv)) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1038 { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1039 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1040 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1041 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1042 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1043 token->len = iv_len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1044 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1045 if (EVP_EncryptUpdate(ctx, token->data + token->len, &len, in, len) != 1) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1046 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1047 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1048 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1049 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1050 token->len += len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1051 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1052 if (EVP_EncryptFinal_ex(ctx, token->data + token->len, &len) <= 0) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1053 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1054 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1055 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1056 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1057 token->len += len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1058 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1059 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1060 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1061 #ifdef NGX_QUIC_DEBUG_PACKETS |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1062 ngx_quic_hexdump(c->log, "quic new token", token->data, token->len); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1063 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1064 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1065 return NGX_OK; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1066 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1067 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1068 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1069 static ngx_int_t |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1070 ngx_quic_validate_token(ngx_connection_t *c, ngx_quic_header_t *pkt) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1071 { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1072 int len, tlen, iv_len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1073 u_char *key, *iv, *p, *data; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1074 ngx_msec_t msec; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1075 EVP_CIPHER_CTX *ctx; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1076 const EVP_CIPHER *cipher; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1077 struct sockaddr_in *sin; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1078 #if (NGX_HAVE_INET6) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1079 struct sockaddr_in6 *sin6; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1080 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1081 ngx_quic_connection_t *qc; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1082 u_char tdec[NGX_QUIC_MAX_TOKEN_SIZE]; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1083 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1084 qc = c->quic; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1085 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1086 /* Retry token */ |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1087 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1088 if (qc->token.len) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1089 if (pkt->token.len != qc->token.len) { |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1090 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1091 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1092 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1093 if (ngx_memcmp(pkt->token.data, qc->token.data, pkt->token.len) != 0) { |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1094 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1095 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1096 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1097 return NGX_OK; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1098 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1099 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1100 /* NEW_TOKEN in a previous connection */ |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1101 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1102 cipher = EVP_aes_256_cbc(); |
7999
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
1103 key = c->quic->conf->token_key; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1104 iv = pkt->token.data; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1105 iv_len = EVP_CIPHER_iv_length(cipher); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1106 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1107 /* sanity checks */ |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1108 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1109 if (pkt->token.len < (size_t) iv_len + EVP_CIPHER_block_size(cipher)) { |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1110 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1111 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1112 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1113 if (pkt->token.len > (size_t) iv_len + NGX_QUIC_MAX_TOKEN_SIZE) { |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1114 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1115 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1116 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1117 ctx = EVP_CIPHER_CTX_new(); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1118 if (ctx == NULL) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1119 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1120 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1121 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1122 if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv)) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1123 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1124 return NGX_ERROR; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1125 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1126 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1127 p = pkt->token.data + iv_len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1128 len = pkt->token.len - iv_len; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1129 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1130 if (EVP_DecryptUpdate(ctx, tdec, &len, p, len) != 1) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1131 EVP_CIPHER_CTX_free(ctx); |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1132 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1133 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1134 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1135 if (EVP_DecryptFinal_ex(ctx, tdec + len, &tlen) <= 0) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1136 EVP_CIPHER_CTX_free(ctx); |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1137 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1138 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1139 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1140 EVP_CIPHER_CTX_free(ctx); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1141 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1142 switch (c->sockaddr->sa_family) { |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1143 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1144 #if (NGX_HAVE_INET6) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1145 case AF_INET6: |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1146 sin6 = (struct sockaddr_in6 *) c->sockaddr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1147 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1148 len = sizeof(struct in6_addr); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1149 data = sin6->sin6_addr.s6_addr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1150 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1151 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1152 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1153 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1154 #if (NGX_HAVE_UNIX_DOMAIN) |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1155 case AF_UNIX: |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1156 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1157 len = ngx_min(c->addr_text.len, NGX_QUIC_MAX_TOKEN_SIZE - sizeof(msec)); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1158 data = c->addr_text.data; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1159 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1160 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1161 #endif |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1162 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1163 default: /* AF_INET */ |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1164 sin = (struct sockaddr_in *) c->sockaddr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1165 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1166 len = sizeof(in_addr_t); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1167 data = (u_char *) &sin->sin_addr; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1168 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1169 break; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1170 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1171 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1172 if (ngx_memcmp(tdec, data, len) != 0) { |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1173 goto bad_token; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1174 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1175 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1176 ngx_memcpy(&msec, tdec + len, sizeof(msec)); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1177 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1178 if (ngx_current_msec - msec > NGX_QUIC_RETRY_LIFETIME) { |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1179 ngx_log_error(NGX_LOG_INFO, c->log, 0, "quic expired token"); |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1180 return NGX_DECLINED; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1181 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1182 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1183 return NGX_OK; |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1184 |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1185 bad_token: |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1186 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1187 ngx_log_error(NGX_LOG_INFO, c->log, 0, "quic invalid token"); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1188 |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1189 qc->error = NGX_QUIC_ERR_INVALID_TOKEN; |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1190 qc->error_reason = "invalid_token"; |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1191 |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
1192 return NGX_ERROR; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1193 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1194 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1195 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1196 static ngx_int_t |
7687
69345a26ba69
Split transport and crypto parts into separate files.
Vladimir Homutov <vl@nginx.com>
parents:
7686
diff
changeset
|
1197 ngx_quic_init_connection(ngx_connection_t *c) |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1198 { |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1199 u_char *p; |
7917
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1200 size_t clen; |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1201 ssize_t len; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1202 ngx_ssl_conn_t *ssl_conn; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1203 ngx_quic_connection_t *qc; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1204 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1205 qc = c->quic; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1206 |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1207 if (ngx_ssl_create_connection(qc->conf->ssl, c, NGX_SSL_BUFFER) != NGX_OK) { |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1208 return NGX_ERROR; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1209 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1210 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1211 ssl_conn = c->ssl->connection; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1212 |
7698
253cf267f95a
Moved setting QUIC methods to runtime.
Roman Arutyunyan <arut@nginx.com>
parents:
7697
diff
changeset
|
1213 if (SSL_set_quic_method(ssl_conn, &quic_method) == 0) { |
253cf267f95a
Moved setting QUIC methods to runtime.
Roman Arutyunyan <arut@nginx.com>
parents:
7697
diff
changeset
|
1214 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7838 | 1215 "quic SSL_set_quic_method() failed"); |
7698
253cf267f95a
Moved setting QUIC methods to runtime.
Roman Arutyunyan <arut@nginx.com>
parents:
7697
diff
changeset
|
1216 return NGX_ERROR; |
253cf267f95a
Moved setting QUIC methods to runtime.
Roman Arutyunyan <arut@nginx.com>
parents:
7697
diff
changeset
|
1217 } |
253cf267f95a
Moved setting QUIC methods to runtime.
Roman Arutyunyan <arut@nginx.com>
parents:
7697
diff
changeset
|
1218 |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1219 #ifdef SSL_READ_EARLY_DATA_SUCCESS |
8102
b52b2a33b0e5
QUIC: fixed build with OpenSSL after bed310672f39.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8101
diff
changeset
|
1220 if (SSL_CTX_get_max_early_data(qc->conf->ssl->ctx)) { |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1221 SSL_set_quic_early_data_enabled(ssl_conn, 1); |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1222 } |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1223 #endif |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1224 |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1225 if (qc->conf->sr_token_key.len) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1226 qc->tp.sr_enabled = 1; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1227 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1228 if (ngx_quic_new_sr_token(c, &qc->dcid, &qc->conf->sr_token_key, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1229 qc->tp.sr_token) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1230 != NGX_OK) |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1231 { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1232 return NGX_ERROR; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1233 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1234 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1235 ngx_quic_hexdump(c->log, "quic stateless reset token", |
8103
0e12c4aca3ab
QUIC: fixed clang-ast asserts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8102
diff
changeset
|
1236 qc->tp.sr_token, (size_t) NGX_QUIC_SR_TOKEN_LEN); |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1237 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1238 |
7917
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1239 len = ngx_quic_create_transport_params(NULL, NULL, &qc->tp, &clen); |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1240 /* always succeeds */ |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1241 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1242 p = ngx_pnalloc(c->pool, len); |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1243 if (p == NULL) { |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1244 return NGX_ERROR; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1245 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1246 |
7917
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1247 len = ngx_quic_create_transport_params(p, p + len, &qc->tp, NULL); |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1248 if (len < 0) { |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1249 return NGX_ERROR; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1250 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1251 |
7836 | 1252 #ifdef NGX_QUIC_DEBUG_PACKETS |
7837
f175006124d0
Cleaned up hexdumps in debug output.
Vladimir Homutov <vl@nginx.com>
parents:
7836
diff
changeset
|
1253 ngx_quic_hexdump(c->log, "quic transport parameters", p, len); |
7836 | 1254 #endif |
1255 | |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7712
diff
changeset
|
1256 if (SSL_set_quic_transport_params(ssl_conn, p, len) == 0) { |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1257 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7838 | 1258 "quic SSL_set_quic_transport_params() failed"); |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1259 return NGX_ERROR; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1260 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1261 |
7917
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1262 #if NGX_OPENSSL_QUIC_ZRTT_CTX |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1263 if (SSL_set_quic_early_data_context(ssl_conn, p, clen) == 0) { |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1264 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1265 "quic SSL_set_quic_early_data_context() failed"); |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1266 return NGX_ERROR; |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1267 } |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1268 #endif |
90b02ff6b003
Compatibility with BoringSSL master branch.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7916
diff
changeset
|
1269 |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1270 return NGX_OK; |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1271 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1272 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1273 |
7931
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1274 static ngx_inline size_t |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1275 ngx_quic_max_udp_payload(ngx_connection_t *c) |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1276 { |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1277 /* TODO: path MTU discovery */ |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1278 |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1279 #if (NGX_HAVE_INET6) |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1280 if (c->sockaddr->sa_family == AF_INET6) { |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1281 return NGX_QUIC_MAX_UDP_PAYLOAD_OUT6; |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1282 } |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1283 #endif |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1284 |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1285 return NGX_QUIC_MAX_UDP_PAYLOAD_OUT; |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1286 } |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1287 |
9fe7875ce4bb
QUIC: further limiting maximum QUIC packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7930
diff
changeset
|
1288 |
7691 | 1289 static void |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
1290 ngx_quic_input_handler(ngx_event_t *rev) |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
1291 { |
7737
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1292 ssize_t n; |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1293 ngx_int_t rc; |
7737
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1294 ngx_buf_t b; |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1295 ngx_connection_t *c; |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1296 ngx_quic_connection_t *qc; |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
1297 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
1298 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1299 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, rev->log, 0, "quic input handler"); |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1300 |
7871 | 1301 ngx_memzero(&b, sizeof(ngx_buf_t)); |
7691 | 1302 b.start = buf; |
7731
d45325e90221
Limit output QUIC packets with client max_packet_size.
Roman Arutyunyan <arut@nginx.com>
parents:
7729
diff
changeset
|
1303 b.end = buf + sizeof(buf); |
7691 | 1304 b.pos = b.last = b.start; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1305 b.memory = 1; |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
1306 |
7691 | 1307 c = rev->data; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
1308 qc = c->quic; |
7677
6bc18966b8c1
Stream "connection" read/write methods.
Vladimir Homutov <vl@nginx.com>
parents:
7675
diff
changeset
|
1309 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1310 c->log->action = "handling quic input"; |
7678
e3c0b19a3a8a
Implemented ngx_quic_stream_send_chain() method.
Roman Arutyunyan <arut@nginx.com>
parents:
7677
diff
changeset
|
1311 |
7691 | 1312 if (rev->timedout) { |
7838 | 1313 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
1314 "quic client timed out"); | |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1315 ngx_quic_close_connection(c, NGX_DONE); |
7691 | 1316 return; |
7678
e3c0b19a3a8a
Implemented ngx_quic_stream_send_chain() method.
Roman Arutyunyan <arut@nginx.com>
parents:
7677
diff
changeset
|
1317 } |
e3c0b19a3a8a
Implemented ngx_quic_stream_send_chain() method.
Roman Arutyunyan <arut@nginx.com>
parents:
7677
diff
changeset
|
1318 |
7691 | 1319 if (c->close) { |
7937
b9bce2c4fe33
Close QUIC connection with NO_ERROR on c->close.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7934
diff
changeset
|
1320 qc->error_reason = "graceful shutdown"; |
b9bce2c4fe33
Close QUIC connection with NO_ERROR on c->close.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7934
diff
changeset
|
1321 ngx_quic_close_connection(c, NGX_OK); |
7691 | 1322 return; |
1323 } | |
7686
7ada2feeac18
Added processing of CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7684
diff
changeset
|
1324 |
7691 | 1325 n = c->recv(c, b.start, b.end - b.start); |
7681 | 1326 |
7691 | 1327 if (n == NGX_AGAIN) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1328 if (qc->closing) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1329 ngx_quic_close_connection(c, NGX_OK); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1330 } |
7691 | 1331 return; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1332 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1333 |
7691 | 1334 if (n == NGX_ERROR) { |
1335 c->read->eof = 1; | |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1336 ngx_quic_close_connection(c, NGX_ERROR); |
7691 | 1337 return; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1338 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1339 |
7691 | 1340 b.last += n; |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
1341 qc->received += n; |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1342 |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1343 rc = ngx_quic_input(c, &b, NULL); |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1344 |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1345 if (rc == NGX_ERROR) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1346 ngx_quic_close_connection(c, NGX_ERROR); |
7691 | 1347 return; |
1348 } | |
7737
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1349 |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1350 if (rc == NGX_DECLINED) { |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1351 return; |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1352 } |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1353 |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1354 /* rc == NGX_OK */ |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1355 |
7737
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1356 qc->send_timer_set = 0; |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
1357 ngx_add_timer(rev, qc->tp.max_idle_timeout); |
7665
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1358 } |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1359 |
1297dc83a6b9
Generic payload handler for quic packets.
Vladimir Homutov <vl@nginx.com>
parents:
7664
diff
changeset
|
1360 |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1361 static void |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1362 ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc) |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1363 { |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1364 ngx_pool_t *pool; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
1365 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1366 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 1367 "quic ngx_quic_close_connection, rc: %i", rc); |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1368 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1369 if (!c->quic) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1370 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 1371 "quic close connection early error"); |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1372 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1373 } else if (ngx_quic_close_quic(c, rc) == NGX_AGAIN) { |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1374 return; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
1375 } |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1376 |
7691 | 1377 if (c->ssl) { |
1378 (void) ngx_ssl_shutdown(c); | |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1379 } |
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1380 |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1381 if (c->read->timer_set) { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1382 ngx_del_timer(c->read); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1383 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1384 |
7691 | 1385 #if (NGX_STAT_STUB) |
1386 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); | |
1387 #endif | |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1388 |
7691 | 1389 c->destroyed = 1; |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1390 |
7691 | 1391 pool = c->pool; |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1392 |
7691 | 1393 ngx_close_connection(c); |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1394 |
7691 | 1395 ngx_destroy_pool(pool); |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1396 } |
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1397 |
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1398 |
7659
4355efde26d8
Added functions to decrypt long packets.
Vladimir Homutov <vl@nginx.com>
parents:
7658
diff
changeset
|
1399 static ngx_int_t |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1400 ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc) |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1401 { |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1402 ngx_uint_t i; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1403 ngx_quic_send_ctx_t *ctx; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1404 ngx_quic_connection_t *qc; |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1405 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1406 qc = c->quic; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1407 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1408 if (!qc->closing) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1409 |
7875
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1410 /* drop packets from retransmit queues, no ack is expected */ |
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1411 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1412 ctx = ngx_quic_get_send_ctx(qc, i); |
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1413 ngx_quic_free_frames(c, &ctx->sent); |
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1414 } |
8bec0ac23cf9
Fixed retransmission of frames after closing connection.
Vladimir Homutov <vl@nginx.com>
parents:
7874
diff
changeset
|
1415 |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1416 if (rc == NGX_DONE) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1417 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1418 /* |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1419 * 10.2. Idle Timeout |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1420 * |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1421 * If the idle timeout is enabled by either peer, a connection is |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1422 * silently closed and its state is discarded when it remains idle |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1423 */ |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1424 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1425 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1426 "quic closing %s connection", |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1427 qc->draining ? "drained" : "idle"); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1428 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1429 } else { |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1430 |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1431 /* |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1432 * 10.3. Immediate Close |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1433 * |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1434 * An endpoint sends a CONNECTION_CLOSE frame (Section 19.19) |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1435 * to terminate the connection immediately. |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1436 */ |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1437 |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1438 qc->error_level = c->ssl ? SSL_quic_read_level(c->ssl->connection) |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1439 : ssl_encryption_initial; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1440 |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1441 if (rc == NGX_OK) { |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1442 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1443 "quic immediate close, drain = %d", |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1444 qc->draining); |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1445 |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1446 qc->close.log = c->log; |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1447 qc->close.data = c; |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1448 qc->close.handler = ngx_quic_close_timer_handler; |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1449 qc->close.cancelable = 1; |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1450 |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1451 ctx = ngx_quic_get_send_ctx(qc, qc->error_level); |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1452 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
1453 ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx)); |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1454 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1455 qc->error = NGX_QUIC_ERR_NO_ERROR; |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1456 |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1457 } else { |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1458 if (qc->error == 0 && !qc->error_app) { |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1459 qc->error = NGX_QUIC_ERR_INTERNAL_ERROR; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1460 } |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1461 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1462 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1463 "quic immediate close due to %serror: %ui %s", |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1464 qc->error_app ? "app " : "", qc->error, |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1465 qc->error_reason ? qc->error_reason : ""); |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1466 } |
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1467 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1468 (void) ngx_quic_send_cc(c); |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1469 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1470 if (qc->error_level == ssl_encryption_handshake) { |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1471 /* for clients that might not have handshake keys */ |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1472 qc->error_level = ssl_encryption_initial; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1473 (void) ngx_quic_send_cc(c); |
7877
d96ddef458cd
Added sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7876
diff
changeset
|
1474 } |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1475 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1476 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1477 qc->closing = 1; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1478 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1479 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1480 if (rc == NGX_ERROR && qc->close.timer_set) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1481 /* do not wait for timer in case of fatal error */ |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1482 ngx_del_timer(&qc->close); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1483 } |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1484 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1485 if (ngx_quic_close_streams(c, qc) == NGX_AGAIN) { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1486 return NGX_AGAIN; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1487 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1488 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1489 if (qc->push.timer_set) { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1490 ngx_del_timer(&qc->push); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1491 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1492 |
7990 | 1493 if (qc->pto.timer_set) { |
1494 ngx_del_timer(&qc->pto); | |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1495 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1496 |
7929
ea4899591798
QUIC: Fixed connection cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7928
diff
changeset
|
1497 if (qc->push.posted) { |
ea4899591798
QUIC: Fixed connection cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7928
diff
changeset
|
1498 ngx_delete_posted_event(&qc->push); |
ea4899591798
QUIC: Fixed connection cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7928
diff
changeset
|
1499 } |
ea4899591798
QUIC: Fixed connection cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7928
diff
changeset
|
1500 |
8091
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1501 for (i = 0; i < NGX_QUIC_ENCRYPTION_LAST; i++) { |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1502 ngx_quic_free_frames(c, &qc->crypto[i].frames); |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1503 } |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1504 |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1505 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1506 ngx_quic_free_frames(c, &qc->send_ctx[i].frames); |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1507 ngx_quic_free_frames(c, &qc->send_ctx[i].sent); |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1508 } |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1509 |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1510 if (qc->close.timer_set) { |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1511 return NGX_AGAIN; |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1512 } |
dbcb9d0a3df1
QUIC: prevented posted push event while in the draining state.
Vladimir Homutov <vl@nginx.com>
parents:
8084
diff
changeset
|
1513 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1514 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1515 "quic part of connection is terminated"); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1516 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1517 /* may be tested from SSL callback during SSL shutdown */ |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1518 c->quic = NULL; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1519 |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1520 return NGX_OK; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1521 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1522 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1523 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1524 void |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1525 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:
7945
diff
changeset
|
1526 const char *reason) |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1527 { |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1528 ngx_quic_connection_t *qc; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1529 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1530 qc = c->quic; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1531 qc->error = err; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1532 qc->error_reason = reason; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1533 qc->error_app = 1; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1534 qc->error_ftype = 0; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1535 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1536 ngx_quic_close_connection(c, NGX_ERROR); |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1537 } |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1538 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
1539 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1540 static void |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1541 ngx_quic_close_timer_handler(ngx_event_t *ev) |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1542 { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1543 ngx_connection_t *c; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1544 |
7836 | 1545 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic close timer"); |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1546 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1547 c = ev->data; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1548 ngx_quic_close_connection(c, NGX_DONE); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1549 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1550 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
1551 |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1552 static ngx_int_t |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1553 ngx_quic_close_streams(ngx_connection_t *c, ngx_quic_connection_t *qc) |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1554 { |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1555 ngx_event_t *rev, *wev; |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1556 ngx_rbtree_t *tree; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1557 ngx_rbtree_node_t *node; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1558 ngx_quic_stream_t *qs; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1559 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1560 #if (NGX_DEBUG) |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1561 ngx_uint_t ns; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1562 #endif |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1563 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1564 tree = &qc->streams.tree; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1565 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1566 if (tree->root == tree->sentinel) { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1567 return NGX_OK; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1568 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1569 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1570 #if (NGX_DEBUG) |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1571 ns = 0; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1572 #endif |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1573 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1574 for (node = ngx_rbtree_min(tree->root, tree->sentinel); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1575 node; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1576 node = ngx_rbtree_next(tree, node)) |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1577 { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1578 qs = (ngx_quic_stream_t *) node; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1579 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1580 rev = qs->c->read; |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1581 rev->error = 1; |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1582 rev->ready = 1; |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1583 |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1584 wev = qs->c->write; |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1585 wev->error = 1; |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
1586 wev->ready = 1; |
7831
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1587 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1588 ngx_post_event(rev, &ngx_posted_events); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1589 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1590 if (rev->timer_set) { |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1591 ngx_del_timer(rev); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1592 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1593 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1594 #if (NGX_DEBUG) |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1595 ns++; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1596 #endif |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1597 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1598 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1599 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1600 "quic connection has %ui active streams", ns); |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1601 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1602 return NGX_AGAIN; |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1603 } |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1604 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1605 |
d11bc25fc4c3
Refactored ngx_quic_close_connection().
Vladimir Homutov <vl@nginx.com>
parents:
7827
diff
changeset
|
1606 static ngx_int_t |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1607 ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf) |
7659
4355efde26d8
Added functions to decrypt long packets.
Vladimir Homutov <vl@nginx.com>
parents:
7658
diff
changeset
|
1608 { |
7691 | 1609 u_char *p; |
1610 ngx_int_t rc; | |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1611 ngx_uint_t good; |
7691 | 1612 ngx_quic_header_t pkt; |
7659
4355efde26d8
Added functions to decrypt long packets.
Vladimir Homutov <vl@nginx.com>
parents:
7658
diff
changeset
|
1613 |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1614 good = 0; |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1615 |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1616 p = b->pos; |
7674
4ae9ac69ab93
HTTP/QUIC interface reworked.
Vladimir Homutov <vl@nginx.com>
parents:
7673
diff
changeset
|
1617 |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1618 while (p < b->last) { |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
1619 |
7691 | 1620 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); |
1621 pkt.raw = b; | |
1622 pkt.data = p; | |
1623 pkt.len = b->last - p; | |
1624 pkt.log = c->log; | |
7717
c217a907ce42
Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents:
7713
diff
changeset
|
1625 pkt.flags = p[0]; |
8097
a89a58c642ef
QUIC: simplified packet header parsing.
Vladimir Homutov <vl@nginx.com>
parents:
8096
diff
changeset
|
1626 pkt.raw->pos++; |
7659
4355efde26d8
Added functions to decrypt long packets.
Vladimir Homutov <vl@nginx.com>
parents:
7658
diff
changeset
|
1627 |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1628 rc = ngx_quic_process_packet(c, conf, &pkt); |
7659
4355efde26d8
Added functions to decrypt long packets.
Vladimir Homutov <vl@nginx.com>
parents:
7658
diff
changeset
|
1629 |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1630 if (rc == NGX_ERROR) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1631 return NGX_ERROR; |
7691 | 1632 } |
7672
8d6ac639feac
Added support of multiple QUIC packets in single datagram.
Vladimir Homutov <vl@nginx.com>
parents:
7671
diff
changeset
|
1633 |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1634 if (rc == NGX_OK) { |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1635 good = 1; |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1636 } |
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1637 |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1638 /* NGX_OK || NGX_DECLINED */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1639 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1640 /* |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1641 * we get NGX_DECLINED when there are no keys [yet] available |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1642 * to decrypt packet. |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1643 * Instead of queueing it, we ignore it and rely on the sender's |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1644 * retransmission: |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1645 * |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1646 * 12.2. Coalescing Packets: |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1647 * |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1648 * For example, if decryption fails (because the keys are |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1649 * not available or any other reason), the receiver MAY either |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1650 * discard or buffer the packet for later processing and MUST |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1651 * attempt to process the remaining packets. |
8073
eb5aa85294e9
QUIC: discard unrecognized long packes.
Vladimir Homutov <vl@nginx.com>
parents:
8071
diff
changeset
|
1652 * |
eb5aa85294e9
QUIC: discard unrecognized long packes.
Vladimir Homutov <vl@nginx.com>
parents:
8071
diff
changeset
|
1653 * We also skip packets that don't match connection state |
eb5aa85294e9
QUIC: discard unrecognized long packes.
Vladimir Homutov <vl@nginx.com>
parents:
8071
diff
changeset
|
1654 * or cannot be parsed properly. |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1655 */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
1656 |
7691 | 1657 /* b->pos is at header end, adjust by actual packet length */ |
8096
0f37b4ef3cd9
QUIC: keep the entire packet size in pkt->len.
Roman Arutyunyan <arut@nginx.com>
parents:
8095
diff
changeset
|
1658 b->pos = pkt.data + pkt.len; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1659 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1660 /* firefox workaround: skip zero padding at the end of quic packet */ |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1661 while (b->pos < b->last && *(b->pos) == 0) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1662 b->pos++; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1663 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1664 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1665 p = b->pos; |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1666 } |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1667 |
8083
702f1d2581a4
QUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan <arut@nginx.com>
parents:
8079
diff
changeset
|
1668 return good ? NGX_OK : NGX_DECLINED; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1669 } |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1670 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1671 |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1672 static ngx_int_t |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1673 ngx_quic_process_packet(ngx_connection_t *c, ngx_quic_conf_t *conf, |
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1674 ngx_quic_header_t *pkt) |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1675 { |
8074
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1676 ngx_int_t rc; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1677 ngx_ssl_conn_t *ssl_conn; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1678 ngx_quic_secrets_t *keys, *next, tmp; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1679 ngx_quic_send_ctx_t *ctx; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1680 ngx_quic_connection_t *qc; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1681 |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
1682 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1683 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1684 c->log->action = "parsing quic packet"; |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1685 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1686 rc = ngx_quic_parse_packet(pkt); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1687 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1688 if (rc == NGX_DECLINED || rc == NGX_ERROR) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1689 return rc; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1690 } |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1691 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1692 c->log->action = "processing quic packet"; |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1693 |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1694 qc = c->quic; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1695 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1696 if (qc) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1697 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1698 if (rc == NGX_ABORT) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1699 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1700 "quic unsupported version: 0x%xD", pkt->version); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1701 return NGX_DECLINED; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1702 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1703 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1704 if (ngx_quic_check_peer(qc, pkt) != NGX_OK) { |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1705 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1706 if (pkt->level == ssl_encryption_application) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1707 if (ngx_quic_process_stateless_reset(c, pkt) == NGX_OK) { |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1708 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1709 "quic stateless reset packet detected"); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1710 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1711 qc->draining = 1; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1712 ngx_quic_close_connection(c, NGX_OK); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1713 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1714 return NGX_OK; |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1715 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1716 |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1717 return ngx_quic_send_stateless_reset(c, qc->conf, pkt); |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1718 } |
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1719 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1720 return NGX_DECLINED; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1721 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1722 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1723 if (qc->in_retry) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1724 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1725 c->log->action = "retrying quic connection"; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1726 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1727 if (pkt->level != ssl_encryption_initial) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1728 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1729 "quic discard late retry packet"); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1730 return NGX_DECLINED; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1731 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1732 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1733 if (!pkt->token.len) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1734 return NGX_DECLINED; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1735 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1736 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1737 if (ngx_quic_new_dcid(c, qc, &pkt->dcid) != NGX_OK) { |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1738 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1739 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1740 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1741 qc->tp.initial_scid = qc->dcid; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1742 qc->in_retry = 0; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1743 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1744 if (ngx_quic_init_secrets(c) != NGX_OK) { |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1745 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1746 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1747 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1748 if (ngx_quic_validate_token(c, pkt) != NGX_OK) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1749 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1750 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1751 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1752 qc->validated = 1; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1753 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1754 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1755 } else { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1756 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1757 if (rc == NGX_ABORT) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1758 return ngx_quic_negotiate_version(c, pkt); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1759 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1760 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1761 if (pkt->level == ssl_encryption_initial) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1762 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1763 c->log->action = "creating quic connection"; |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1764 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1765 if (pkt->dcid.len < NGX_QUIC_CID_LEN_MIN) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1766 /* 7.2. Negotiating Connection IDs */ |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1767 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1768 "quic too short dcid in initial" |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1769 " packet: length %i", pkt->dcid.len); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1770 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1771 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1772 |
8101
bed310672f39
QUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov <vl@nginx.com>
parents:
8100
diff
changeset
|
1773 qc = ngx_quic_new_connection(c, conf, pkt); |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1774 if (qc == NULL) { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1775 return NGX_ERROR; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1776 } |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1777 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1778 c->quic = qc; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1779 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1780 if (ngx_terminate || ngx_exiting) { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1781 qc->error = NGX_QUIC_ERR_CONNECTION_REFUSED; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1782 return NGX_ERROR; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1783 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1784 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1785 if (pkt->token.len) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1786 if (ngx_quic_validate_token(c, pkt) != NGX_OK) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1787 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1788 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1789 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1790 } else if (conf->retry) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1791 return ngx_quic_send_retry(c); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1792 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1793 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1794 if (ngx_quic_init_secrets(c) != NGX_OK) { |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1795 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1796 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1797 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1798 } else if (pkt->level == ssl_encryption_application) { |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
1799 return ngx_quic_send_stateless_reset(c, conf, pkt); |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1800 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1801 } else { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1802 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1803 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1804 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1805 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1806 c->log->action = "decrypting packet"; |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1807 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1808 keys = &qc->keys[pkt->level]; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1809 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1810 if (keys->client.key.len == 0) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1811 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1812 "quic no level %d keys yet, ignoring packet", pkt->level); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1813 return NGX_DECLINED; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1814 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1815 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1816 next = &qc->next_key; |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
1817 |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1818 pkt->secret = &keys->client; |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1819 pkt->next = &next->client; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1820 pkt->key_phase = qc->key_phase; |
7860
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1821 pkt->plaintext = buf; |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1822 |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1823 ctx = ngx_quic_get_send_ctx(qc, pkt->level); |
7ea34e13937f
Address validation using Retry packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7859
diff
changeset
|
1824 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1825 ssl_conn = c->ssl ? c->ssl->connection : NULL; |
8074
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1826 |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1827 rc = ngx_quic_decrypt(pkt, ssl_conn, &ctx->largest_pn); |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1828 if (rc != NGX_OK) { |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1829 qc->error = pkt->error; |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1830 qc->error_reason = "failed to decrypt packet"; |
c6b963de0c00
QUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov <vl@nginx.com>
parents:
8073
diff
changeset
|
1831 return rc; |
7689 | 1832 } |
1833 | |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1834 if (c->ssl == NULL) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1835 if (ngx_quic_init_connection(c) != NGX_OK) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1836 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1837 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1838 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1839 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1840 if (pkt->level == ssl_encryption_handshake) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1841 /* |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1842 * 4.10.1. The successful use of Handshake packets indicates |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1843 * that no more Initial packets need to be exchanged |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1844 */ |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1845 ngx_quic_discard_ctx(c, ssl_encryption_initial); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1846 qc->validated = 1; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1847 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1848 |
8133
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1849 if (pkt->level == ssl_encryption_early_data |
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1850 || pkt->level == ssl_encryption_application) |
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1851 { |
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1852 ngx_gettimeofday(&pkt->received); |
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1853 } |
1d4417e4f2d0
QUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8132
diff
changeset
|
1854 |
8135
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1855 c->log->action = "handling payload"; |
eacca87c476e
QUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov <vl@nginx.com>
parents:
8134
diff
changeset
|
1856 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1857 if (pkt->level != ssl_encryption_application) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1858 return ngx_quic_payload_handler(c, pkt); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1859 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1860 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1861 /* switch keys on Key Phase change */ |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1862 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1863 if (pkt->key_update) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1864 qc->key_phase ^= 1; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1865 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1866 tmp = *keys; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1867 *keys = *next; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1868 *next = tmp; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1869 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1870 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1871 rc = ngx_quic_payload_handler(c, pkt); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1872 if (rc != NGX_OK) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1873 return rc; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1874 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1875 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1876 /* generate next keys */ |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1877 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1878 if (pkt->key_update) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1879 if (ngx_quic_key_update(c, keys, next) != NGX_OK) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1880 return NGX_ERROR; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1881 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1882 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1883 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1884 return NGX_OK; |
7689 | 1885 } |
1886 | |
1887 | |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1888 static ngx_int_t |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1889 ngx_quic_init_secrets(ngx_connection_t *c) |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1890 { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1891 ngx_quic_secrets_t *keys; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1892 ngx_quic_connection_t *qc; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1893 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1894 qc =c->quic; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1895 keys = &qc->keys[ssl_encryption_initial]; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1896 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1897 if (ngx_quic_set_initial_secret(c->pool, &keys->client, &keys->server, |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1898 &qc->odcid) |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1899 != NGX_OK) |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1900 { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1901 return NGX_ERROR; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1902 } |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1903 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1904 qc->initialized = 1; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1905 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1906 return NGX_OK; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1907 } |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1908 |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
1909 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1910 static void |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1911 ngx_quic_discard_ctx(ngx_connection_t *c, enum ssl_encryption_level_t level) |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1912 { |
8025
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1913 ngx_queue_t *q; |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1914 ngx_quic_frame_t *f; |
7816
aba84d9ab256
Parsing of truncated packet numbers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7815
diff
changeset
|
1915 ngx_quic_send_ctx_t *ctx; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1916 ngx_quic_connection_t *qc; |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
1917 |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1918 qc = c->quic; |
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1919 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1920 if (qc->keys[level].client.key.len == 0) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1921 return; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1922 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1923 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1924 qc->keys[level].client.key.len = 0; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1925 qc->pto_count = 0; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1926 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1927 ctx = ngx_quic_get_send_ctx(qc, level); |
8025
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1928 |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1929 while (!ngx_queue_empty(&ctx->sent)) { |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1930 q = ngx_queue_head(&ctx->sent); |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1931 ngx_queue_remove(q); |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1932 |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1933 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1934 ngx_quic_congestion_ack(c, f); |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1935 ngx_quic_free_frame(c, f); |
7f9938cbcd12
QUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8024
diff
changeset
|
1936 } |
7770
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1937 } |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1938 |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1939 |
90f94413177e
TLS Early Data support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7769
diff
changeset
|
1940 static ngx_int_t |
7838 | 1941 ngx_quic_check_peer(ngx_quic_connection_t *qc, ngx_quic_header_t *pkt) |
1942 { | |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1943 ngx_str_t *dcid; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1944 ngx_queue_t *q; |
8084
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1945 ngx_quic_send_ctx_t *ctx; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1946 ngx_quic_client_id_t *cid; |
7858
6e100d8c138a
Preserve original DCID and unbreak parsing 0-RTT packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7857
diff
changeset
|
1947 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1948 dcid = (pkt->level == ssl_encryption_early_data) ? &qc->odcid : &qc->dcid; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1949 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1950 if (pkt->dcid.len == dcid->len |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1951 && ngx_memcmp(pkt->dcid.data, dcid->data, dcid->len) == 0) |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1952 { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1953 if (pkt->level == ssl_encryption_application) { |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1954 return NGX_OK; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1955 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1956 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1957 goto found; |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1958 } |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1959 |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1960 /* |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1961 * a packet sent in response to an initial client packet might be lost, |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1962 * thus check also for old dcid |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1963 */ |
8084
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1964 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_initial); |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1965 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1966 if (pkt->level == ssl_encryption_initial |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1967 && ctx->largest_ack == (uint64_t) -1) |
8084
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1968 { |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1969 if (pkt->dcid.len == qc->odcid.len |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1970 && ngx_memcmp(pkt->dcid.data, qc->odcid.data, qc->odcid.len) == 0) |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1971 { |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1972 goto found; |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1973 } |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1974 } |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1975 |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1976 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic unexpected quic dcid"); |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1977 return NGX_ERROR; |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1978 |
eece8e35e64d
QUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan <arut@nginx.com>
parents:
8083
diff
changeset
|
1979 found: |
7838 | 1980 |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1981 for (q = ngx_queue_head(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1982 q != ngx_queue_sentinel(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1983 q = ngx_queue_next(q)) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1984 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1985 cid = ngx_queue_data(q, ngx_quic_client_id_t, queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1986 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1987 if (pkt->scid.len == cid->len |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1988 && ngx_memcmp(pkt->scid.data, cid->id, cid->len) == 0) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1989 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1990 return NGX_OK; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1991 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1992 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
1993 |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1994 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic unexpected quic scid"); |
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
1995 return NGX_ERROR; |
7648
b28ea685a56e
Moved all QUIC code into ngx_event_quic.c
Vladimir Homutov <vl@nginx.com>
parents:
7646
diff
changeset
|
1996 } |
7637 | 1997 |
1998 | |
7691 | 1999 static ngx_int_t |
2000 ngx_quic_payload_handler(ngx_connection_t *c, ngx_quic_header_t *pkt) | |
2001 { | |
2002 u_char *end, *p; | |
2003 ssize_t len; | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2004 ngx_uint_t ack_sent, do_close; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2005 ngx_quic_frame_t frame; |
7691 | 2006 ngx_quic_connection_t *qc; |
2007 | |
2008 qc = c->quic; | |
2009 | |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2010 if (qc->closing) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2011 /* |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2012 * 10.1 Closing and Draining Connection States |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2013 * ... delayed or reordered packets are properly discarded. |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2014 * |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2015 * An endpoint retains only enough information to generate |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2016 * a packet containing a CONNECTION_CLOSE frame and to identify |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2017 * packets as belonging to the connection. |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2018 */ |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2019 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2020 qc->error_level = pkt->level; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2021 qc->error = NGX_QUIC_ERR_NO_ERROR; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2022 qc->error_reason = "connection is closing, packet discarded"; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2023 qc->error_ftype = 0; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2024 qc->error_app = 0; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2025 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2026 return ngx_quic_send_cc(c); |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2027 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2028 |
7691 | 2029 p = pkt->payload.data; |
2030 end = p + pkt->payload.len; | |
2031 | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2032 ack_sent = 0; |
7691 | 2033 do_close = 0; |
2034 | |
2035 while (p < end) { | |
2036 | |
7741 | 2037 c->log->action = "parsing frames"; |
2038 | |
7706
1f002206a59b
Added boundaries checks into frame parser.
Vladimir Homutov <vl@nginx.com>
parents:
7705
diff
changeset
|
2039 len = ngx_quic_parse_frame(pkt, p, end, &frame); |
7717
c217a907ce42
Added checks for permitted frame types.
Vladimir Homutov <vl@nginx.com>
parents:
7713
diff
changeset
|
2040 |
7691 | 2041 if (len < 0) { |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2042 qc->error = pkt->error; |
7691 | 2043 return NGX_ERROR; |
2044 } | |
2045 | |
7741 | 2046 c->log->action = "handling frames"; |
2047 | |
7691 | 2048 p += len; |
2049 | |
2050 switch (frame.type) { | |
2051 | |
2052 case NGX_QUIC_FT_ACK: | |
2053 if (ngx_quic_handle_ack_frame(c, pkt, &frame.u.ack) != NGX_OK) { | |
2054 return NGX_ERROR; | |
2055 } | |
2056 | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2057 continue; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2058 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2059 case NGX_QUIC_FT_PADDING: |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2060 /* no action required */ |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2061 continue; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2062 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2063 case NGX_QUIC_FT_CONNECTION_CLOSE: |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2064 case NGX_QUIC_FT_CONNECTION_CLOSE_APP: |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2065 do_close = 1; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2066 continue; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2067 } |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2068 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2069 /* got there with ack-eliciting packet */ |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2070 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2071 if (!ack_sent) { |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2072 if (ngx_quic_send_ack(c, pkt) != NGX_OK) { |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2073 return NGX_ERROR; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2074 } |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2075 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2076 ack_sent = 1; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2077 } |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2078 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2079 switch (frame.type) { |
7691 | 2080 |
2081 case NGX_QUIC_FT_CRYPTO: | |
2082 | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2083 if (ngx_quic_handle_crypto_frame(c, pkt, &frame) != NGX_OK) { |
7691 | 2084 return NGX_ERROR; |
2085 } | |
2086 | |
2087 break; | |
2088 | |
2089 case NGX_QUIC_FT_PING: | |
2090 break; | |
2091 | |
2092 case NGX_QUIC_FT_STREAM0: | |
2093 case NGX_QUIC_FT_STREAM1: | |
2094 case NGX_QUIC_FT_STREAM2: | |
2095 case NGX_QUIC_FT_STREAM3: | |
2096 case NGX_QUIC_FT_STREAM4: | |
2097 case NGX_QUIC_FT_STREAM5: | |
2098 case NGX_QUIC_FT_STREAM6: | |
2099 case NGX_QUIC_FT_STREAM7: | |
2100 | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2101 if (ngx_quic_handle_stream_frame(c, pkt, &frame) != NGX_OK) { |
7691 | 2102 return NGX_ERROR; |
2103 } | |
2104 | |
2105 break; | |
2106 | |
7703
ff540f13d95d
MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7702
diff
changeset
|
2107 case NGX_QUIC_FT_MAX_DATA: |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2108 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2109 if (ngx_quic_handle_max_data_frame(c, &frame.u.max_data) != NGX_OK) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2110 { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2111 return NGX_ERROR; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2112 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2113 |
7703
ff540f13d95d
MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7702
diff
changeset
|
2114 break; |
ff540f13d95d
MAX_DATA frame parser/handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7702
diff
changeset
|
2115 |
7702
d3b26c3bea22
Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents:
7701
diff
changeset
|
2116 case NGX_QUIC_FT_STREAMS_BLOCKED: |
d3b26c3bea22
Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents:
7701
diff
changeset
|
2117 case NGX_QUIC_FT_STREAMS_BLOCKED2: |
7711
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2118 |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2119 if (ngx_quic_handle_streams_blocked_frame(c, pkt, |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2120 &frame.u.streams_blocked) |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2121 != NGX_OK) |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2122 { |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2123 return NGX_ERROR; |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2124 } |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
2125 |
7702
d3b26c3bea22
Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents:
7701
diff
changeset
|
2126 break; |
d3b26c3bea22
Added parsing of STREAMS BLOCKED frames.
Vladimir Homutov <vl@nginx.com>
parents:
7701
diff
changeset
|
2127 |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2128 case NGX_QUIC_FT_STREAM_DATA_BLOCKED: |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2129 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2130 if (ngx_quic_handle_stream_data_blocked_frame(c, pkt, |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2131 &frame.u.stream_data_blocked) |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2132 != NGX_OK) |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2133 { |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2134 return NGX_ERROR; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2135 } |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2136 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2137 break; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
2138 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2139 case NGX_QUIC_FT_MAX_STREAM_DATA: |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2140 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2141 if (ngx_quic_handle_max_stream_data_frame(c, pkt, |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2142 &frame.u.max_stream_data) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2143 != NGX_OK) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2144 { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2145 return NGX_ERROR; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2146 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2147 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2148 break; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
2149 |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2150 case NGX_QUIC_FT_RESET_STREAM: |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2151 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2152 if (ngx_quic_handle_reset_stream_frame(c, pkt, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2153 &frame.u.reset_stream) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2154 != NGX_OK) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2155 { |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2156 return NGX_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2157 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2158 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2159 break; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2160 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2161 case NGX_QUIC_FT_STOP_SENDING: |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2162 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2163 if (ngx_quic_handle_stop_sending_frame(c, pkt, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2164 &frame.u.stop_sending) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2165 != NGX_OK) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2166 { |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2167 return NGX_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2168 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2169 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2170 break; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
2171 |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2172 case NGX_QUIC_FT_MAX_STREAMS: |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2173 case NGX_QUIC_FT_MAX_STREAMS2: |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2174 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2175 if (ngx_quic_handle_max_streams_frame(c, pkt, &frame.u.max_streams) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2176 != NGX_OK) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2177 { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2178 return NGX_ERROR; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2179 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2180 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2181 break; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
2182 |
8069
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2183 case NGX_QUIC_FT_PATH_CHALLENGE: |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2184 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2185 if (ngx_quic_handle_path_challenge_frame(c, pkt, |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2186 &frame.u.path_challenge) |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2187 != NGX_OK) |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2188 { |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2189 return NGX_ERROR; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2190 } |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2191 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2192 break; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
2193 |
7791
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2194 case NGX_QUIC_FT_NEW_CONNECTION_ID: |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2195 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2196 if (ngx_quic_handle_new_connection_id_frame(c, pkt, &frame.u.ncid) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2197 != NGX_OK) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2198 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2199 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2200 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2201 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2202 break; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
2203 |
7791
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2204 case NGX_QUIC_FT_RETIRE_CONNECTION_ID: |
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2205 case NGX_QUIC_FT_PATH_RESPONSE: |
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2206 |
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2207 /* TODO: handle */ |
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2208 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2209 "quic frame handler not implemented"); |
7791
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2210 break; |
9b9d592c0da3
Ignore non-yet-implemented frames.
Vladimir Homutov <vl@nginx.com>
parents:
7788
diff
changeset
|
2211 |
7691 | 2212 default: |
7823
4e4485793418
Added MAX_STREAM_DATA stub handler.
Vladimir Homutov <vl@nginx.com>
parents:
7822
diff
changeset
|
2213 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2214 "quic missing frame handler"); |
7691 | 2215 return NGX_ERROR; |
2216 } | |
2217 } | |
2218 | |
2219 if (p != end) { | |
2220 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
7838 | 2221 "quic trailing garbage in payload: %ui bytes", end - p); |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2222 |
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2223 qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR; |
7691 | 2224 return NGX_ERROR; |
2225 } | |
2226 | |
2227 if (do_close) { | |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2228 qc->draining = 1; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2229 ngx_quic_close_connection(c, NGX_OK); |
7691 | 2230 } |
2231 | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2232 return NGX_OK; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2233 } |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2234 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2235 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2236 static ngx_int_t |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2237 ngx_quic_send_ack(ngx_connection_t *c, ngx_quic_header_t *pkt) |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2238 { |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2239 ngx_quic_frame_t *frame; |
7691 | 2240 |
7741 | 2241 c->log->action = "generating acknowledgment"; |
2242 | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2243 /* every ACK-eliciting packet is acknowledged, TODO ACK Ranges */ |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2244 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2245 frame = ngx_quic_alloc_frame(c, 0); |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2246 if (frame == NULL) { |
7691 | 2247 return NGX_ERROR; |
2248 } | |
2249 | |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2250 frame->level = (pkt->level == ssl_encryption_early_data) |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2251 ? ssl_encryption_application |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2252 : pkt->level; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2253 |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2254 frame->type = NGX_QUIC_FT_ACK; |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2255 frame->u.ack.largest = pkt->pn; |
7988
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2256 frame->u.ack.delay = ngx_quic_ack_delay(c, &pkt->received, frame->level); |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2257 |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
2258 ngx_sprintf(frame->info, "ACK for PN=%uL from frame handler level=%d", |
7844
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2259 pkt->pn, frame->level); |
c10e7d48aa85
Factored out sending ACK from payload handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7842
diff
changeset
|
2260 ngx_quic_queue_frame(c->quic, frame); |
7691 | 2261 |
7775 | 2262 return NGX_OK; |
7691 | 2263 } |
2264 | |
2265 | |
2266 static ngx_int_t | |
7988
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2267 ngx_quic_ack_delay(ngx_connection_t *c, struct timeval *received, |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2268 enum ssl_encryption_level_t level) |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2269 { |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2270 ngx_int_t ack_delay; |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2271 struct timeval tv; |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2272 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2273 ack_delay = 0; |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2274 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2275 if (level == ssl_encryption_application) { |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2276 ngx_gettimeofday(&tv); |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2277 ack_delay = (tv.tv_sec - received->tv_sec) * 1000000 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2278 + tv.tv_usec - received->tv_usec; |
8105
4983357258d7
QUIC: a bandaid for calculating ack_delay with non-monotonic time.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8104
diff
changeset
|
2279 ack_delay = ngx_max(ack_delay, 0); |
7988
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2280 ack_delay >>= c->quic->ctp.ack_delay_exponent; |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2281 } |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2282 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2283 return ack_delay; |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2284 } |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2285 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2286 |
0d1ad81dd65c
QUIC: delay field of an ACK frame is now calculated.
Vladimir Homutov <vl@nginx.com>
parents:
7987
diff
changeset
|
2287 static ngx_int_t |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2288 ngx_quic_send_cc(ngx_connection_t *c) |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2289 { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2290 ngx_quic_frame_t *frame; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2291 ngx_quic_connection_t *qc; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2292 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2293 qc = c->quic; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2294 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2295 if (qc->draining) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2296 return NGX_OK; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2297 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2298 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2299 if (!qc->initialized) { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2300 /* try to initialize secrets to send an early error */ |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2301 if (ngx_quic_init_secrets(c) != NGX_OK) { |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2302 return NGX_OK; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2303 } |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2304 } |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
2305 |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2306 if (qc->closing |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2307 && ngx_current_msec - qc->last_cc < NGX_QUIC_CC_MIN_INTERVAL) |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2308 { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2309 /* dot not send CC too often */ |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2310 return NGX_OK; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2311 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2312 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2313 frame = ngx_quic_alloc_frame(c, 0); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2314 if (frame == NULL) { |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2315 return NGX_ERROR; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2316 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2317 |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2318 frame->level = qc->error_level; |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2319 frame->type = NGX_QUIC_FT_CONNECTION_CLOSE; |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2320 frame->u.close.error_code = qc->error; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2321 frame->u.close.frame_type = qc->error_ftype; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2322 frame->u.close.app = qc->error_app; |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2323 |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2324 if (qc->error_reason) { |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2325 frame->u.close.reason.len = ngx_strlen(qc->error_reason); |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2326 frame->u.close.reason.data = (u_char *) qc->error_reason; |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
2327 } |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
2328 |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
2329 ngx_snprintf(frame->info, sizeof(frame->info) - 1, |
7953
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2330 "CONNECTION_CLOSE%s err:%ui level:%d ft:%ui reason:\"%s\"", |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2331 qc->error_app ? "_APP" : "", qc->error, qc->error_level, |
e0f92f68e018
QUIC: Introduced ngx_quic_finalize_connection().
Roman Arutyunyan <arut@nginx.com>
parents:
7945
diff
changeset
|
2332 qc->error_ftype, qc->error_reason ? qc->error_reason : "-"); |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2333 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2334 ngx_quic_queue_frame(c->quic, frame); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2335 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2336 qc->last_cc = ngx_current_msec; |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2337 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2338 return ngx_quic_output(c); |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2339 } |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2340 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2341 |
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
2342 static ngx_int_t |
7861
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2343 ngx_quic_send_new_token(ngx_connection_t *c) |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2344 { |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2345 ngx_str_t token; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2346 ngx_quic_frame_t *frame; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2347 |
7999
0d2b2664b41c
QUIC: added "quic" listen parameter.
Roman Arutyunyan <arut@nginx.com>
parents:
7998
diff
changeset
|
2348 if (!c->quic->conf->retry) { |
7861
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2349 return NGX_OK; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2350 } |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2351 |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2352 if (ngx_quic_new_token(c, &token) != NGX_OK) { |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2353 return NGX_ERROR; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2354 } |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2355 |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2356 frame = ngx_quic_alloc_frame(c, 0); |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2357 if (frame == NULL) { |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2358 return NGX_ERROR; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2359 } |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2360 |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2361 frame->level = ssl_encryption_application; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2362 frame->type = NGX_QUIC_FT_NEW_TOKEN; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2363 frame->u.token.length = token.len; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2364 frame->u.token.data = token.data; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2365 ngx_sprintf(frame->info, "NEW_TOKEN"); |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2366 ngx_quic_queue_frame(c->quic, frame); |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2367 |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2368 return NGX_OK; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2369 } |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2370 |
7945 | 2371 |
7861
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2372 static ngx_int_t |
7691 | 2373 ngx_quic_handle_ack_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2374 ngx_quic_ack_frame_t *ack) |
7691 | 2375 { |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2376 ssize_t n; |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2377 u_char *pos, *end; |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2378 uint64_t min, max, gap, range; |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2379 ngx_msec_t send_time; |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2380 ngx_uint_t i; |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2381 ngx_quic_send_ctx_t *ctx; |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2382 ngx_quic_connection_t *qc; |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2383 |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2384 qc = c->quic; |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2385 |
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2386 ctx = ngx_quic_get_send_ctx(qc, pkt->level); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2387 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2388 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2389 "quic ngx_quic_handle_ack_frame level %d", pkt->level); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2390 |
7792 | 2391 /* |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2392 * If any computed packet number is negative, an endpoint MUST |
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2393 * generate a connection error of type FRAME_ENCODING_ERROR. |
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2394 * (19.3.1) |
7792 | 2395 */ |
2396 | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2397 if (ack->first_range > ack->largest) { |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2398 qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2399 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7838 | 2400 "quic invalid first range in ack frame"); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2401 return NGX_ERROR; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2402 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2403 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2404 min = ack->largest - ack->first_range; |
7792 | 2405 max = ack->largest; |
2406 | |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2407 if (ngx_quic_handle_ack_frame_range(c, ctx, min, max, &send_time) |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2408 != NGX_OK) |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2409 { |
7792 | 2410 return NGX_ERROR; |
2411 } | |
2412 | |
2413 /* 13.2.3. Receiver Tracking of ACK Frames */ | |
8050
6e1c88f82280
QUIC: changed ctx->largest_ack initial value to type maximum.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8027
diff
changeset
|
2414 if (ctx->largest_ack < max || ctx->largest_ack == (uint64_t) -1) { |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
2415 ctx->largest_ack = max; |
7792 | 2416 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2417 "quic updated largest received ack: %uL", max); |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2418 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2419 /* |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2420 * An endpoint generates an RTT sample on receiving an |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2421 * ACK frame that meets the following two conditions: |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2422 * |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2423 * - the largest acknowledged packet number is newly acknowledged |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2424 * - at least one of the newly acknowledged packets was ack-eliciting. |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2425 */ |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2426 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2427 if (send_time != NGX_TIMER_INFINITE) { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2428 ngx_quic_rtt_sample(c, ack, pkt->level, send_time); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2429 } |
7792 | 2430 } |
2431 | |
2432 pos = ack->ranges_start; | |
2433 end = ack->ranges_end; | |
2434 | |
2435 for (i = 0; i < ack->range_count; i++) { | |
2436 | |
2437 n = ngx_quic_parse_ack_range(pkt, pos, end, &gap, &range); | |
2438 if (n == NGX_ERROR) { | |
2439 return NGX_ERROR; | |
2440 } | |
2441 pos += n; | |
2442 | |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2443 if (gap + 2 > min) { |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2444 qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR; |
7792 | 2445 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7838 | 2446 "quic invalid range %ui in ack frame", i); |
7792 | 2447 return NGX_ERROR; |
2448 } | |
2449 | |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2450 max = min - gap - 2; |
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2451 |
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2452 if (range > max) { |
7989
9ed4c12ec948
QUIC: caching c->quic in the ngx_quic_handle_ack_frame() function.
Vladimir Homutov <vl@nginx.com>
parents:
7988
diff
changeset
|
2453 qc->error = NGX_QUIC_ERR_FRAME_ENCODING_ERROR; |
7792 | 2454 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7838 | 2455 "quic invalid range %ui in ack frame", i); |
7792 | 2456 return NGX_ERROR; |
2457 } | |
2458 | |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2459 min = max - range; |
7792 | 2460 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2461 if (ngx_quic_handle_ack_frame_range(c, ctx, min, max, &send_time) |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2462 != NGX_OK) |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2463 { |
7792 | 2464 return NGX_ERROR; |
2465 } | |
2466 } | |
2467 | |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
2468 return ngx_quic_detect_lost(c); |
7792 | 2469 } |
2470 | |
2471 | |
2472 static ngx_int_t | |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
2473 ngx_quic_handle_ack_frame_range(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2474 uint64_t min, uint64_t max, ngx_msec_t *send_time) |
7792 | 2475 { |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2476 uint64_t found_num; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2477 ngx_uint_t found; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2478 ngx_queue_t *q; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2479 ngx_quic_frame_t *f; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2480 ngx_quic_connection_t *qc; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2481 |
8020
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2482 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2483 "quic handle ack range: min:%uL max:%uL", min, max); |
69033a50c3ae
QUIC: fixed ACK Ranges processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8019
diff
changeset
|
2484 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2485 qc = c->quic; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2486 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2487 *send_time = NGX_TIMER_INFINITE; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2488 found = 0; |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2489 found_num = 0; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2490 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2491 q = ngx_queue_last(&ctx->sent); |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
2492 |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
2493 while (q != ngx_queue_sentinel(&ctx->sent)) { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2494 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2495 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2496 q = ngx_queue_prev(q); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2497 |
7792 | 2498 if (f->pnum >= min && f->pnum <= max) { |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2499 ngx_quic_congestion_ack(c, f); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2500 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2501 ngx_quic_handle_stream_ack(c, f); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2502 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2503 if (f->pnum > found_num || !found) { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2504 *send_time = f->last; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2505 found_num = f->pnum; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2506 } |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2507 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2508 ngx_queue_remove(&f->queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2509 ngx_quic_free_frame(c, f); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2510 found = 1; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2511 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2512 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2513 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2514 if (!found) { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2515 |
7932
4e75267865de
QUIC: fixed off-by-one in frame range handler.
Vladimir Homutov <vl@nginx.com>
parents:
7931
diff
changeset
|
2516 if (max < ctx->pnum) { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2517 /* duplicate ACK or ACK for non-ack-eliciting frame */ |
7792 | 2518 return NGX_OK; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2519 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2520 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2521 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
7878 | 2522 "quic ACK for the packet not sent"); |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2523 |
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2524 qc->error = NGX_QUIC_ERR_PROTOCOL_VIOLATION; |
7876
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
2525 qc->error_ftype = NGX_QUIC_FT_ACK; |
ffd362e87eb2
Added more context to CONNECTION CLOSE frames.
Vladimir Homutov <vl@nginx.com>
parents:
7875
diff
changeset
|
2526 qc->error_reason = "unknown packet number"; |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
2527 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2528 return NGX_ERROR; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2529 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
2530 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2531 if (!qc->push.timer_set) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2532 ngx_post_event(&qc->push, &ngx_posted_events); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2533 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2534 |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2535 qc->pto_count = 0; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2536 |
7691 | 2537 return NGX_OK; |
2538 } | |
2539 | |
2540 | |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2541 static void |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2542 ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack, |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2543 enum ssl_encryption_level_t level, ngx_msec_t send_time) |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2544 { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2545 ngx_msec_t latest_rtt, ack_delay, adjusted_rtt, rttvar_sample; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2546 ngx_quic_connection_t *qc; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2547 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2548 qc = c->quic; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2549 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2550 latest_rtt = ngx_current_msec - send_time; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2551 qc->latest_rtt = latest_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2552 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2553 if (qc->min_rtt == NGX_TIMER_INFINITE) { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2554 qc->min_rtt = latest_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2555 qc->avg_rtt = latest_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2556 qc->rttvar = latest_rtt / 2; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2557 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2558 } else { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2559 qc->min_rtt = ngx_min(qc->min_rtt, latest_rtt); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2560 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2561 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2562 if (level == ssl_encryption_application) { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2563 ack_delay = ack->delay * (1 << qc->ctp.ack_delay_exponent) / 1000; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2564 ack_delay = ngx_min(ack_delay, qc->ctp.max_ack_delay); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2565 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2566 } else { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2567 ack_delay = 0; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2568 } |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2569 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2570 adjusted_rtt = latest_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2571 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2572 if (qc->min_rtt + ack_delay < latest_rtt) { |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2573 adjusted_rtt -= ack_delay; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2574 } |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2575 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2576 qc->avg_rtt = 0.875 * qc->avg_rtt + 0.125 * adjusted_rtt; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2577 rttvar_sample = ngx_abs((ngx_msec_int_t) (qc->avg_rtt - adjusted_rtt)); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2578 qc->rttvar = 0.75 * qc->rttvar + 0.25 * rttvar_sample; |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2579 } |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2580 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2581 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2582 "quic rtt sample: latest %M, min %M, avg %M, var %M", |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2583 latest_rtt, qc->min_rtt, qc->avg_rtt, qc->rttvar); |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2584 } |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2585 |
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2586 |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2587 static ngx_inline ngx_msec_t |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2588 ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2589 { |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2590 ngx_msec_t duration; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2591 ngx_quic_connection_t *qc; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2592 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2593 qc = c->quic; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2594 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2595 /* PTO calculation: quic-recovery, Appendix 8 */ |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2596 duration = qc->avg_rtt; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2597 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2598 duration += ngx_max(4 * qc->rttvar, NGX_QUIC_TIME_GRANULARITY); |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2599 duration <<= qc->pto_count; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2600 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2601 if (qc->congestion.in_flight == 0) { /* no in-flight packets */ |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2602 return duration; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2603 } |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2604 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2605 if (ctx == &qc->send_ctx[2] && c->ssl->handshaked) { |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2606 /* application send space */ |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2607 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2608 duration += qc->tp.max_ack_delay << qc->pto_count; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2609 } |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2610 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2611 return duration; |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2612 } |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2613 |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2614 |
7987
3b107aadc9f6
QUIC: added rtt estimation.
Vladimir Homutov <vl@nginx.com>
parents:
7953
diff
changeset
|
2615 static void |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2616 ngx_quic_handle_stream_ack(ngx_connection_t *c, ngx_quic_frame_t *f) |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2617 { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2618 uint64_t sent, unacked; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2619 ngx_event_t *wev; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2620 ngx_quic_stream_t *sn; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2621 ngx_quic_connection_t *qc; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2622 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2623 if (f->type < NGX_QUIC_FT_STREAM0 || f->type > NGX_QUIC_FT_STREAM7) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2624 return; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2625 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2626 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2627 qc = c->quic; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2628 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2629 sn = ngx_quic_find_stream(&qc->streams.tree, f->u.stream.stream_id); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2630 if (sn == NULL) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2631 return; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2632 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2633 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2634 wev = sn->c->write; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2635 sent = sn->c->sent; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2636 unacked = sent - sn->acked; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2637 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2638 if (unacked >= NGX_QUIC_STREAM_BUFSIZE && wev->active) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2639 wev->ready = 1; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2640 ngx_post_event(wev, &ngx_posted_events); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2641 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2642 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2643 sn->acked += f->u.stream.length; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2644 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2645 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, sn->c->log, 0, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2646 "quic stream ack %uL acked:%uL, unacked:%uL", |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2647 f->u.stream.length, sn->acked, sent - sn->acked); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2648 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2649 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
2650 |
7691 | 2651 static ngx_int_t |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2652 ngx_quic_handle_ordered_frame(ngx_connection_t *c, ngx_quic_frames_stream_t *fs, |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
2653 ngx_quic_frame_t *frame, ngx_quic_frame_handler_pt handler, void *data) |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2654 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2655 size_t full_len; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2656 ngx_int_t rc; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2657 ngx_queue_t *q; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2658 ngx_quic_ordered_frame_t *f; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2659 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2660 f = &frame->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2661 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2662 if (f->offset > fs->received) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2663 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
2664 "quic out-of-order frame: expecting %uL got %uL", |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2665 fs->received, f->offset); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2666 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2667 return ngx_quic_buffer_frame(c, fs, frame); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2668 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2669 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2670 if (f->offset < fs->received) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2671 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2672 if (ngx_quic_adjust_frame_offset(c, frame, fs->received) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2673 == NGX_DONE) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2674 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2675 /* old/duplicate data range */ |
8104
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2676 return handler == ngx_quic_crypto_input ? NGX_DECLINED : NGX_OK; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2677 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2678 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2679 /* intersecting data range, frame modified */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2680 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2681 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2682 /* f->offset == fs->received */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2683 |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
2684 rc = handler(c, frame, data); |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2685 if (rc == NGX_ERROR) { |
7691 | 2686 return NGX_ERROR; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2687 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2688 } else if (rc == NGX_DONE) { |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2689 /* handler destroyed stream, queue no longer exists */ |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2690 return NGX_OK; |
7691 | 2691 } |
2692 | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2693 /* rc == NGX_OK */ |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2694 |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2695 fs->received += f->length; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2696 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2697 /* now check the queue if we can continue with buffered frames */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2698 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2699 do { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2700 q = ngx_queue_head(&fs->frames); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2701 if (q == ngx_queue_sentinel(&fs->frames)) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2702 break; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2703 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2704 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2705 frame = ngx_queue_data(q, ngx_quic_frame_t, queue); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2706 f = &frame->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2707 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2708 if (f->offset > fs->received) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2709 /* gap found, nothing more to do */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2710 break; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2711 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2712 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2713 full_len = f->length; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2714 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2715 if (f->offset < fs->received) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2716 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2717 if (ngx_quic_adjust_frame_offset(c, frame, fs->received) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2718 == NGX_DONE) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2719 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2720 /* old/duplicate data range */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2721 ngx_queue_remove(q); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2722 fs->total -= f->length; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2723 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2724 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2725 "quic skipped buffered frame, total %ui", |
2726 fs->total); | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2727 ngx_quic_free_frame(c, frame); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2728 continue; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2729 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2730 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2731 /* frame was adjusted, proceed to input */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2732 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2733 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2734 /* f->offset == fs->received */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2735 |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
2736 rc = handler(c, frame, data); |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2737 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2738 if (rc == NGX_ERROR) { |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2739 return NGX_ERROR; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2740 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2741 } else if (rc == NGX_DONE) { |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2742 /* handler destroyed stream, queue no longer exists */ |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2743 return NGX_OK; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2744 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2745 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2746 fs->received += f->length; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2747 fs->total -= full_len; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2748 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2749 ngx_queue_remove(q); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2750 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2751 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2752 "quic consumed buffered frame, total %ui", fs->total); |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2753 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2754 ngx_quic_free_frame(c, frame); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2755 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2756 } while (1); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2757 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2758 return NGX_OK; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2759 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2760 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2761 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2762 static ngx_int_t |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2763 ngx_quic_adjust_frame_offset(ngx_connection_t *c, ngx_quic_frame_t *frame, |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2764 uint64_t offset_in) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2765 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2766 size_t tail; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2767 ngx_quic_ordered_frame_t *f; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2768 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2769 f = &frame->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2770 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2771 tail = offset_in - f->offset; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2772 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2773 if (tail >= f->length) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2774 /* range preceeding already received data or duplicate, ignore */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2775 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2776 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2777 "quic old or duplicate data in ordered frame, ignored"); |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2778 return NGX_DONE; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2779 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2780 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2781 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2782 "quic adjusted ordered frame data start to expected offset"); |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2783 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2784 /* intersecting range: adjust data size */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2785 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2786 f->offset += tail; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2787 f->data += tail; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2788 f->length -= tail; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2789 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2790 return NGX_OK; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2791 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2792 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2793 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2794 static ngx_int_t |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2795 ngx_quic_buffer_frame(ngx_connection_t *c, ngx_quic_frames_stream_t *fs, |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2796 ngx_quic_frame_t *frame) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2797 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2798 u_char *data; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2799 ngx_queue_t *q; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2800 ngx_quic_frame_t *dst, *item; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2801 ngx_quic_ordered_frame_t *f, *df; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2802 |
7836 | 2803 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
2804 "quic ngx_quic_buffer_frame"); | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2805 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2806 f = &frame->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2807 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2808 /* frame start offset is in the future, buffer it */ |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2809 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2810 dst = ngx_quic_alloc_frame(c, f->length); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2811 if (dst == NULL) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2812 return NGX_ERROR; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2813 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2814 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2815 data = dst->data; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2816 ngx_memcpy(dst, frame, sizeof(ngx_quic_frame_t)); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2817 dst->data = data; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2818 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2819 ngx_memcpy(dst->data, f->data, f->length); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2820 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2821 df = &dst->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2822 df->data = dst->data; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2823 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2824 fs->total += f->length; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2825 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2826 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2827 "quic ordered frame with unexpected offset:" |
2828 " buffered, total %ui", fs->total); | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2829 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2830 if (ngx_queue_empty(&fs->frames)) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2831 ngx_queue_insert_after(&fs->frames, &dst->queue); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2832 return NGX_OK; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2833 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2834 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2835 for (q = ngx_queue_last(&fs->frames); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2836 q != ngx_queue_sentinel(&fs->frames); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2837 q = ngx_queue_prev(q)) |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2838 { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2839 item = ngx_queue_data(q, ngx_quic_frame_t, queue); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2840 f = &item->u.ord; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2841 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2842 if (f->offset < df->offset) { |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2843 ngx_queue_insert_after(q, &dst->queue); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2844 return NGX_OK; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2845 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2846 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2847 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2848 ngx_queue_insert_after(&fs->frames, &dst->queue); |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2849 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2850 return NGX_OK; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2851 } |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2852 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2853 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2854 static ngx_int_t |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2855 ngx_quic_handle_crypto_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2856 ngx_quic_frame_t *frame) |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2857 { |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2858 uint64_t last; |
8104
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2859 ngx_int_t rc; |
8132
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2860 ngx_quic_send_ctx_t *ctx; |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2861 ngx_quic_connection_t *qc; |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2862 ngx_quic_crypto_frame_t *f; |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2863 ngx_quic_frames_stream_t *fs; |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2864 |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2865 qc = c->quic; |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2866 fs = &qc->crypto[pkt->level]; |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2867 f = &frame->u.crypto; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2868 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2869 /* no overflow since both values are 62-bit */ |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2870 last = f->offset + f->length; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2871 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2872 if (last > fs->received && last - fs->received > NGX_QUIC_MAX_BUFFERED) { |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2873 c->quic->error = NGX_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2874 return NGX_ERROR; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2875 } |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2876 |
8104
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2877 rc = ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_crypto_input, |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2878 NULL); |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2879 if (rc != NGX_DECLINED) { |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2880 return rc; |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2881 } |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2882 |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2883 /* speeding up handshake completion */ |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2884 |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2885 if (pkt->level == ssl_encryption_initial) { |
8132
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2886 ctx = ngx_quic_get_send_ctx(qc, pkt->level); |
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2887 |
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2888 if (!ngx_queue_empty(&ctx->sent)) { |
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2889 ngx_quic_resend_frames(c, ctx); |
6226f834b420
QUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8131
diff
changeset
|
2890 } |
8104
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2891 } |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2892 |
9588a2782c62
QUIC: speeding up handshake completion.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8103
diff
changeset
|
2893 return NGX_OK; |
7812
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2894 } |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2895 |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2896 |
76839f55bc48
Sorted functions and functions declarations.
Vladimir Homutov <vl@nginx.com>
parents:
7811
diff
changeset
|
2897 static ngx_int_t |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
2898 ngx_quic_crypto_input(ngx_connection_t *c, ngx_quic_frame_t *frame, void *data) |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2899 { |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
2900 int n, sslerr; |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2901 ngx_ssl_conn_t *ssl_conn; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2902 ngx_quic_crypto_frame_t *f; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2903 |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2904 f = &frame->u.crypto; |
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2905 |
7691 | 2906 ssl_conn = c->ssl->connection; |
2907 | |
2908 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
7836 | 2909 "quic SSL_quic_read_level: %d, SSL_quic_write_level: %d", |
7691 | 2910 (int) SSL_quic_read_level(ssl_conn), |
2911 (int) SSL_quic_write_level(ssl_conn)); | |
2912 | |
2913 if (!SSL_provide_quic_data(ssl_conn, SSL_quic_read_level(ssl_conn), | |
7810
167d32476737
Crypto buffer frames reordering.
Vladimir Homutov <vl@nginx.com>
parents:
7809
diff
changeset
|
2914 f->data, f->length)) |
7691 | 2915 { |
2916 ngx_ssl_error(NGX_LOG_INFO, c->log, 0, | |
2917 "SSL_provide_quic_data() failed"); | |
2918 return NGX_ERROR; | |
2919 } | |
2920 | |
2921 n = SSL_do_handshake(ssl_conn); | |
2922 | |
2923 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n); | |
2924 | |
2925 if (n == -1) { | |
2926 sslerr = SSL_get_error(ssl_conn, n); | |
2927 | |
2928 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", | |
2929 sslerr); | |
2930 | |
7766
23a2b5e7acc8
Improved SSL_do_handshake() error handling in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7765
diff
changeset
|
2931 if (sslerr != SSL_ERROR_WANT_READ) { |
7691 | 2932 ngx_ssl_error(NGX_LOG_ERR, c->log, 0, "SSL_do_handshake() failed"); |
7766
23a2b5e7acc8
Improved SSL_do_handshake() error handling in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7765
diff
changeset
|
2933 return NGX_ERROR; |
7691 | 2934 } |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
2935 |
7768
76818c9cdd6f
Sending HANDSHAKE_DONE just once with BoringSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7767
diff
changeset
|
2936 } else if (n == 1 && !SSL_in_init(ssl_conn)) { |
7691 | 2937 |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
2938 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7765 | 2939 "quic ssl cipher: %s", SSL_get_cipher(ssl_conn)); |
7691 | 2940 |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
2941 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2942 "quic handshake completed successfully"); |
7739
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2943 |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2944 c->ssl->handshaked = 1; |
8064
11fc65261689
QUIC: disabled bidirectional SSL shutdown after 09fb2135a589.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8063
diff
changeset
|
2945 c->ssl->no_wait_shutdown = 1; |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
2946 |
7752 | 2947 frame = ngx_quic_alloc_frame(c, 0); |
7739
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2948 if (frame == NULL) { |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2949 return NGX_ERROR; |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2950 } |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2951 |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2952 /* 12.4 Frames and frame types, figure 8 */ |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2953 frame->level = ssl_encryption_application; |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2954 frame->type = NGX_QUIC_FT_HANDSHAKE_DONE; |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2955 ngx_sprintf(frame->info, "HANDSHAKE DONE on handshake completed"); |
cb75f194f1f0
Implemented sending HANDSHAKE_DONE frame after handshake.
Vladimir Homutov <vl@nginx.com>
parents:
7738
diff
changeset
|
2956 ngx_quic_queue_frame(c->quic, frame); |
7785
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2957 |
7861
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2958 if (ngx_quic_send_new_token(c) != NGX_OK) { |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2959 return NGX_ERROR; |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2960 } |
52d0c4832570
Address validation using NEW_TOKEN frame.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7860
diff
changeset
|
2961 |
7785
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2962 /* |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2963 * Generating next keys before a key update is received. |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2964 * See quic-tls 9.4 Header Protection Timing Side-Channels. |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2965 */ |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2966 |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2967 if (ngx_quic_key_update(c, &c->quic->keys[ssl_encryption_application], |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2968 &c->quic->next_key) |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2969 != NGX_OK) |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2970 { |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2971 return NGX_ERROR; |
29354c6fc5f2
TLS Key Update in QUIC.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7782
diff
changeset
|
2972 } |
7870
e169cce912c7
Avoid retransmitting of packets with discarded keys.
Vladimir Homutov <vl@nginx.com>
parents:
7869
diff
changeset
|
2973 |
e169cce912c7
Avoid retransmitting of packets with discarded keys.
Vladimir Homutov <vl@nginx.com>
parents:
7869
diff
changeset
|
2974 /* |
e169cce912c7
Avoid retransmitting of packets with discarded keys.
Vladimir Homutov <vl@nginx.com>
parents:
7869
diff
changeset
|
2975 * 4.10.2 An endpoint MUST discard its handshake keys |
e169cce912c7
Avoid retransmitting of packets with discarded keys.
Vladimir Homutov <vl@nginx.com>
parents:
7869
diff
changeset
|
2976 * when the TLS handshake is confirmed |
e169cce912c7
Avoid retransmitting of packets with discarded keys.
Vladimir Homutov <vl@nginx.com>
parents:
7869
diff
changeset
|
2977 */ |
8098
d0d3fc0697a0
QUIC: packet processing refactoring.
Vladimir Homutov <vl@nginx.com>
parents:
8097
diff
changeset
|
2978 ngx_quic_discard_ctx(c, ssl_encryption_handshake); |
7729
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
2979 } |
1295b293d09a
Connection states code cleanup.
Vladimir Homutov <vl@nginx.com>
parents:
7726
diff
changeset
|
2980 |
7691 | 2981 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 2982 "quic SSL_quic_read_level: %d, SSL_quic_write_level: %d", |
7691 | 2983 (int) SSL_quic_read_level(ssl_conn), |
2984 (int) SSL_quic_write_level(ssl_conn)); | |
2985 | |
2986 return NGX_OK; | |
2987 } | |
2988 | |
2989 | |
2990 static ngx_int_t | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2991 ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2992 ngx_quic_frame_t *frame) |
7691 | 2993 { |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2994 size_t window; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2995 uint64_t last; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
2996 ngx_buf_t *b; |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
2997 ngx_pool_t *pool; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
2998 ngx_connection_t *sc; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
2999 ngx_quic_stream_t *sn; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3000 ngx_quic_connection_t *qc; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3001 ngx_quic_stream_frame_t *f; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3002 ngx_quic_frames_stream_t *fs; |
7691 | 3003 |
3004 qc = c->quic; | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3005 f = &frame->u.stream; |
7691 | 3006 |
7922
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3007 if ((f->stream_id & NGX_QUIC_STREAM_UNIDIRECTIONAL) |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3008 && (f->stream_id & NGX_QUIC_STREAM_SERVER_INITIATED)) |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3009 { |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3010 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3011 return NGX_ERROR; |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3012 } |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3013 |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3014 /* no overflow since both values are 62-bit */ |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3015 last = f->offset + f->length; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3016 |
7691 | 3017 sn = ngx_quic_find_stream(&qc->streams.tree, f->stream_id); |
3018 | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3019 if (sn == NULL) { |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3020 sn = ngx_quic_create_client_stream(c, f->stream_id); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3021 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3022 if (sn == NULL) { |
7922
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3023 return NGX_ERROR; |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3024 } |
d437ee1ce81e
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7919
diff
changeset
|
3025 |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3026 if (sn == NGX_QUIC_STREAM_GONE) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3027 return NGX_OK; |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
3028 } |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3029 |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3030 sc = sn->c; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3031 fs = &sn->fs; |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3032 b = sn->b; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3033 window = b->end - b->last; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3034 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3035 if (last > window) { |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3036 c->quic->error = NGX_QUIC_ERR_FLOW_CONTROL_ERROR; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3037 goto cleanup; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3038 } |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3039 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3040 if (ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_stream_input, |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3041 sn) |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3042 != NGX_OK) |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3043 { |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3044 goto cleanup; |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3045 } |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3046 |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3047 sc->listening->handler(sc); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3048 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3049 return NGX_OK; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3050 } |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3051 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3052 fs = &sn->fs; |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3053 b = sn->b; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3054 window = (b->pos - b->start) + (b->end - b->last); |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3055 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3056 if (last > fs->received && last - fs->received > window) { |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3057 c->quic->error = NGX_QUIC_ERR_FLOW_CONTROL_ERROR; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3058 return NGX_ERROR; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3059 } |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3060 |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
3061 return ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_stream_input, |
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
3062 sn); |
8068
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3063 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3064 cleanup: |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3065 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3066 pool = sc->pool; |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3067 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3068 ngx_close_connection(sc); |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3069 ngx_destroy_pool(pool); |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3070 |
f882b1784f30
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan <arut@nginx.com>
parents:
8066
diff
changeset
|
3071 return NGX_ERROR; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3072 } |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3073 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3074 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3075 static ngx_int_t |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
3076 ngx_quic_stream_input(ngx_connection_t *c, ngx_quic_frame_t *frame, void *data) |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3077 { |
8019
fc16e303003a
QUIC: fixed possible use-after-free on stream cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8018
diff
changeset
|
3078 uint64_t id; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3079 ngx_buf_t *b; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3080 ngx_event_t *rev; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3081 ngx_quic_stream_t *sn; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3082 ngx_quic_connection_t *qc; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3083 ngx_quic_stream_frame_t *f; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3084 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3085 qc = c->quic; |
7855
81a4f98a2556
Cleaned up reordering code.
Vladimir Homutov <vl@nginx.com>
parents:
7854
diff
changeset
|
3086 sn = data; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3087 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3088 f = &frame->u.stream; |
8019
fc16e303003a
QUIC: fixed possible use-after-free on stream cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8018
diff
changeset
|
3089 id = f->stream_id; |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3090 |
7691 | 3091 b = sn->b; |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3092 |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3093 if ((size_t) ((b->pos - b->start) + (b->end - b->last)) < f->length) { |
7838 | 3094 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
3095 "quic no space in stream buffer"); | |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3096 return NGX_ERROR; |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3097 } |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3098 |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3099 if ((size_t) (b->end - b->last) < f->length) { |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3100 b->last = ngx_movemem(b->start, b->pos, b->last - b->pos); |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3101 b->pos = b->start; |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3102 } |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3103 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
3104 b->last = ngx_cpymem(b->last, f->data, f->length); |
7691 | 3105 |
7760
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3106 rev = sn->c->read; |
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3107 rev->ready = 1; |
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3108 |
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3109 if (f->fin) { |
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3110 rev->pending_eof = 1; |
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
3111 } |
7691 | 3112 |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3113 if (rev->active) { |
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3114 rev->handler(rev); |
7780
de8981bf2dd5
Advertizing MAX_STREAMS (0x12) credit in advance.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7778
diff
changeset
|
3115 } |
de8981bf2dd5
Advertizing MAX_STREAMS (0x12) credit in advance.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7778
diff
changeset
|
3116 |
7814
ab443e80d9e4
Create new stream immediately on receiving new stream id.
Vladimir Homutov <vl@nginx.com>
parents:
7813
diff
changeset
|
3117 /* check if stream was destroyed by handler */ |
8019
fc16e303003a
QUIC: fixed possible use-after-free on stream cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8018
diff
changeset
|
3118 if (ngx_quic_find_stream(&qc->streams.tree, id) == NULL) { |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3119 return NGX_DONE; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3120 } |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3121 |
7691 | 3122 return NGX_OK; |
3123 } | |
3124 | |
3125 | |
7711
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3126 static ngx_int_t |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3127 ngx_quic_handle_max_data_frame(ngx_connection_t *c, |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3128 ngx_quic_max_data_frame_t *f) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3129 { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3130 ngx_event_t *wev; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3131 ngx_rbtree_t *tree; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3132 ngx_rbtree_node_t *node; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3133 ngx_quic_stream_t *qs; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3134 ngx_quic_connection_t *qc; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3135 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3136 qc = c->quic; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3137 tree = &qc->streams.tree; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3138 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3139 if (f->max_data <= qc->streams.send_max_data) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3140 return NGX_OK; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3141 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3142 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3143 if (qc->streams.sent >= qc->streams.send_max_data) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3144 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3145 for (node = ngx_rbtree_min(tree->root, tree->sentinel); |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3146 node; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3147 node = ngx_rbtree_next(tree, node)) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3148 { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3149 qs = (ngx_quic_stream_t *) node; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3150 wev = qs->c->write; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3151 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3152 if (wev->active) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3153 wev->ready = 1; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3154 ngx_post_event(wev, &ngx_posted_events); |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3155 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3156 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3157 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3158 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3159 qc->streams.send_max_data = f->max_data; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3160 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3161 return NGX_OK; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3162 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3163 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3164 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3165 static ngx_int_t |
7711
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3166 ngx_quic_handle_streams_blocked_frame(ngx_connection_t *c, |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3167 ngx_quic_header_t *pkt, ngx_quic_streams_blocked_frame_t *f) |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3168 { |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3169 return NGX_OK; |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3170 } |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3171 |
a14afe21e692
Double MAX_STREAMS on STREAMS_BLOCKED.
Roman Arutyunyan <arut@nginx.com>
parents:
7707
diff
changeset
|
3172 |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3173 static ngx_int_t |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3174 ngx_quic_handle_stream_data_blocked_frame(ngx_connection_t *c, |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3175 ngx_quic_header_t *pkt, ngx_quic_stream_data_blocked_frame_t *f) |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3176 { |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
3177 size_t n; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
3178 ngx_buf_t *b; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
3179 ngx_quic_frame_t *frame; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
3180 ngx_quic_stream_t *sn; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
3181 ngx_quic_connection_t *qc; |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3182 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3183 qc = c->quic; |
7924
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3184 |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3185 if ((f->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3186 && (f->id & NGX_QUIC_STREAM_SERVER_INITIATED)) |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3187 { |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3188 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3189 return NGX_ERROR; |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3190 } |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3191 |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3192 sn = ngx_quic_find_stream(&qc->streams.tree, f->id); |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3193 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3194 if (sn == NULL) { |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3195 sn = ngx_quic_create_client_stream(c, f->id); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3196 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3197 if (sn == NULL) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3198 return NGX_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3199 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3200 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3201 if (sn == NGX_QUIC_STREAM_GONE) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3202 return NGX_OK; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3203 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3204 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3205 b = sn->b; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3206 n = b->end - b->last; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3207 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3208 sn->c->listening->handler(sn->c); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3209 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3210 } else { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3211 b = sn->b; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3212 n = sn->fs.received + (b->pos - b->start) + (b->end - b->last); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3213 } |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3214 |
7752 | 3215 frame = ngx_quic_alloc_frame(c, 0); |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3216 if (frame == NULL) { |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3217 return NGX_ERROR; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3218 } |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3219 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3220 frame->level = pkt->level; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3221 frame->type = NGX_QUIC_FT_MAX_STREAM_DATA; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3222 frame->u.max_stream_data.id = f->id; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3223 frame->u.max_stream_data.limit = n; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3224 |
8018
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
3225 ngx_sprintf(frame->info, "MAX_STREAM_DATA id:0x%xL limit:%uL level=%d", |
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
3226 frame->u.max_stream_data.id, |
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
3227 frame->u.max_stream_data.limit, |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3228 frame->level); |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3229 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3230 ngx_quic_queue_frame(c->quic, frame); |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3231 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3232 return NGX_OK; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3233 } |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3234 |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
3235 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3236 static ngx_int_t |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3237 ngx_quic_handle_max_stream_data_frame(ngx_connection_t *c, |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3238 ngx_quic_header_t *pkt, ngx_quic_max_stream_data_frame_t *f) |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3239 { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3240 uint64_t sent; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3241 ngx_event_t *wev; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3242 ngx_quic_stream_t *sn; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3243 ngx_quic_connection_t *qc; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3244 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3245 qc = c->quic; |
7924
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3246 |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3247 if ((f->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3248 && (f->id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0) |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3249 { |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3250 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3251 return NGX_ERROR; |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3252 } |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3253 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3254 sn = ngx_quic_find_stream(&qc->streams.tree, f->id); |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3255 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3256 if (sn == NULL) { |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3257 sn = ngx_quic_create_client_stream(c, f->id); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3258 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3259 if (sn == NULL) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3260 return NGX_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3261 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3262 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3263 if (sn == NGX_QUIC_STREAM_GONE) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3264 return NGX_OK; |
7924
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3265 } |
8fc9fcf18608
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7923
diff
changeset
|
3266 |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3267 if (f->limit > sn->send_max_data) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3268 sn->send_max_data = f->limit; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3269 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3270 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3271 sn->c->listening->handler(sn->c); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3272 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
3273 return NGX_OK; |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3274 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3275 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3276 if (f->limit <= sn->send_max_data) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3277 return NGX_OK; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3278 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3279 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3280 sent = sn->c->sent; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3281 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3282 if (sent >= sn->send_max_data) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3283 wev = sn->c->write; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3284 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3285 if (wev->active) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3286 wev->ready = 1; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3287 ngx_post_event(wev, &ngx_posted_events); |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3288 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3289 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3290 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3291 sn->send_max_data = f->limit; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3292 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3293 return NGX_OK; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3294 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3295 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
3296 |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3297 static ngx_int_t |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3298 ngx_quic_handle_reset_stream_frame(ngx_connection_t *c, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3299 ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3300 { |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3301 ngx_event_t *rev; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3302 ngx_connection_t *sc; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3303 ngx_quic_stream_t *sn; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3304 ngx_quic_connection_t *qc; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3305 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3306 qc = c->quic; |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3307 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3308 if ((f->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3309 && (f->id & NGX_QUIC_STREAM_SERVER_INITIATED)) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3310 { |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3311 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3312 return NGX_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3313 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3314 |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3315 sn = ngx_quic_find_stream(&qc->streams.tree, f->id); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3316 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3317 if (sn == NULL) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3318 sn = ngx_quic_create_client_stream(c, f->id); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3319 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3320 if (sn == NULL) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3321 return NGX_ERROR; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3322 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3323 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3324 if (sn == NGX_QUIC_STREAM_GONE) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3325 return NGX_OK; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3326 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3327 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3328 sc = sn->c; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3329 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3330 rev = sc->read; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3331 rev->error = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3332 rev->ready = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3333 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3334 sc->listening->handler(sc); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3335 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3336 return NGX_OK; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3337 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3338 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3339 rev = sn->c->read; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3340 rev->error = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3341 rev->ready = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3342 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3343 if (rev->active) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3344 rev->handler(rev); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3345 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3346 |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3347 return NGX_OK; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3348 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3349 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3350 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3351 static ngx_int_t |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3352 ngx_quic_handle_stop_sending_frame(ngx_connection_t *c, |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3353 ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3354 { |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3355 ngx_event_t *wev; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3356 ngx_connection_t *sc; |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3357 ngx_quic_stream_t *sn; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3358 ngx_quic_connection_t *qc; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3359 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3360 qc = c->quic; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3361 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3362 if ((f->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3363 && (f->id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0) |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3364 { |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3365 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3366 return NGX_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3367 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3368 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3369 sn = ngx_quic_find_stream(&qc->streams.tree, f->id); |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3370 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3371 if (sn == NULL) { |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3372 sn = ngx_quic_create_client_stream(c, f->id); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3373 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3374 if (sn == NULL) { |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3375 return NGX_ERROR; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3376 } |
8023
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3377 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3378 if (sn == NGX_QUIC_STREAM_GONE) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3379 return NGX_OK; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3380 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3381 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3382 sc = sn->c; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3383 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3384 wev = sc->write; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3385 wev->error = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3386 wev->ready = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3387 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3388 sc->listening->handler(sc); |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3389 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3390 return NGX_OK; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3391 } |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3392 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3393 wev = sn->c->write; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3394 wev->error = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3395 wev->ready = 1; |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3396 |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3397 if (wev->active) { |
240931629995
QUIC: handle client RESET_STREAM and STOP_SENDING.
Roman Arutyunyan <arut@nginx.com>
parents:
8022
diff
changeset
|
3398 wev->handler(wev); |
7923
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3399 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3400 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3401 return NGX_OK; |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3402 } |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3403 |
953cf44708b0
Stream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7922
diff
changeset
|
3404 |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3405 static ngx_int_t |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3406 ngx_quic_handle_max_streams_frame(ngx_connection_t *c, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3407 ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3408 { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3409 ngx_quic_connection_t *qc; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3410 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3411 qc = c->quic; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3412 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3413 if (f->bidi) { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3414 if (qc->streams.server_max_streams_bidi < f->limit) { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3415 qc->streams.server_max_streams_bidi = f->limit; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3416 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3417 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3418 "quic max_streams_bidi:%uL", f->limit); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3419 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3420 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3421 } else { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3422 if (qc->streams.server_max_streams_uni < f->limit) { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3423 qc->streams.server_max_streams_uni = f->limit; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3424 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3425 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3426 "quic max_streams_uni:%uL", f->limit); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3427 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3428 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3429 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3430 return NGX_OK; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3431 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3432 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
3433 |
8069
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3434 static ngx_int_t |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3435 ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3436 ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f) |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3437 { |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3438 ngx_quic_frame_t *frame; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3439 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3440 frame = ngx_quic_alloc_frame(c, 0); |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3441 if (frame == NULL) { |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3442 return NGX_ERROR; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3443 } |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3444 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3445 frame->level = pkt->level; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3446 frame->type = NGX_QUIC_FT_PATH_RESPONSE; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3447 frame->u.path_response = *f; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3448 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3449 ngx_sprintf(frame->info, "PATH_RESPONSE data:0x%xL level:%d", |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3450 *(uint64_t *) &f->data, frame->level); |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3451 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3452 ngx_quic_queue_frame(c->quic, frame); |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3453 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3454 return NGX_OK; |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3455 } |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3456 |
4ff2a0b747d1
QUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan <arut@nginx.com>
parents:
8068
diff
changeset
|
3457 |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3458 static ngx_int_t |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3459 ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c, |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3460 ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3461 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3462 ngx_queue_t *q; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3463 ngx_quic_client_id_t *cid, *item; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3464 ngx_quic_connection_t *qc; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3465 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3466 qc = c->quic; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3467 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3468 if (f->seqnum < qc->max_retired_seqnum) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3469 /* |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3470 * An endpoint that receives a NEW_CONNECTION_ID frame with |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3471 * a sequence number smaller than the Retire Prior To field |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3472 * of a previously received NEW_CONNECTION_ID frame MUST send |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3473 * a corresponding RETIRE_CONNECTION_ID frame that retires |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3474 * the newly received connection ID, unless it has already |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3475 * done so for that sequence number. |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3476 */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3477 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3478 if (ngx_quic_retire_connection_id(c, pkt->level, f->seqnum) != NGX_OK) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3479 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3480 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3481 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3482 goto retire; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3483 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3484 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3485 cid = NULL; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3486 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3487 for (q = ngx_queue_head(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3488 q != ngx_queue_sentinel(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3489 q = ngx_queue_next(q)) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3490 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3491 item = ngx_queue_data(q, ngx_quic_client_id_t, queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3492 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3493 if (item->seqnum == f->seqnum) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3494 cid = item; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3495 break; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3496 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3497 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3498 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3499 if (cid) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3500 /* |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3501 * Transmission errors, timeouts and retransmissions might cause the |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3502 * same NEW_CONNECTION_ID frame to be received multiple times |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3503 */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3504 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3505 if (cid->len != f->len |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3506 || ngx_strncmp(cid->id, f->cid, f->len) != 0 |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
3507 || ngx_strncmp(cid->sr_token, f->srt, NGX_QUIC_SR_TOKEN_LEN) != 0) |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3508 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3509 /* |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3510 * ..a sequence number is used for different connection IDs, |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3511 * the endpoint MAY treat that receipt as a connection error |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3512 * of type PROTOCOL_VIOLATION. |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3513 */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3514 qc->error = NGX_QUIC_ERR_PROTOCOL_VIOLATION; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3515 qc->error_reason = "seqnum refers to different connection id/token"; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3516 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3517 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3518 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3519 } else { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3520 |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
3521 cid = ngx_quic_alloc_connection_id(c, qc); |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3522 if (cid == NULL) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3523 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3524 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3525 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3526 cid->seqnum = f->seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3527 cid->len = f->len; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3528 ngx_memcpy(cid->id, f->cid, f->len); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3529 |
8100
b31c02454539
QUIC: added stateless reset support.
Vladimir Homutov <vl@nginx.com>
parents:
8099
diff
changeset
|
3530 ngx_memcpy(cid->sr_token, f->srt, NGX_QUIC_SR_TOKEN_LEN); |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3531 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3532 ngx_queue_insert_tail(&qc->client_ids, &cid->queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3533 qc->nclient_ids++; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3534 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3535 /* always use latest available connection id */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3536 if (f->seqnum > qc->curr_seqnum) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3537 qc->scid.len = cid->len; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3538 qc->scid.data = cid->id; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3539 qc->curr_seqnum = f->seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3540 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3541 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3542 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3543 retire: |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3544 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3545 if (qc->max_retired_seqnum && f->retire <= qc->max_retired_seqnum) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3546 /* |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3547 * Once a sender indicates a Retire Prior To value, smaller values sent |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3548 * in subsequent NEW_CONNECTION_ID frames have no effect. A receiver |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3549 * MUST ignore any Retire Prior To fields that do not increase the |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3550 * largest received Retire Prior To value. |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3551 */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3552 goto done; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3553 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3554 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3555 qc->max_retired_seqnum = f->retire; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3556 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3557 q = ngx_queue_head(&qc->client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3558 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3559 while (q != ngx_queue_sentinel(&qc->client_ids)) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3560 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3561 cid = ngx_queue_data(q, ngx_quic_client_id_t, queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3562 q = ngx_queue_next(q); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3563 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3564 if (cid->seqnum >= f->retire) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3565 continue; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3566 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3567 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3568 /* this connection id must be retired */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3569 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3570 if (ngx_quic_retire_connection_id(c, pkt->level, cid->seqnum) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3571 != NGX_OK) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3572 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3573 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3574 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3575 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3576 ngx_queue_remove(&cid->queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3577 ngx_queue_insert_head(&qc->free_client_ids, &cid->queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3578 qc->nclient_ids--; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3579 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3580 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3581 done: |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3582 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3583 if (qc->nclient_ids > qc->tp.active_connection_id_limit) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3584 /* |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3585 * After processing a NEW_CONNECTION_ID frame and |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3586 * adding and retiring active connection IDs, if the number of active |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3587 * connection IDs exceeds the value advertised in its |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3588 * active_connection_id_limit transport parameter, an endpoint MUST |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3589 * close the connection with an error of type CONNECTION_ID_LIMIT_ERROR. |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3590 */ |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3591 qc->error = NGX_QUIC_ERR_CONNECTION_ID_LIMIT_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3592 qc->error_reason = "too many connection ids received"; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3593 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3594 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3595 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3596 return NGX_OK; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3597 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3598 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3599 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3600 static ngx_int_t |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3601 ngx_quic_retire_connection_id(ngx_connection_t *c, |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3602 enum ssl_encryption_level_t level, uint64_t seqnum) |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3603 { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3604 ngx_quic_frame_t *frame; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3605 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3606 frame = ngx_quic_alloc_frame(c, 0); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3607 if (frame == NULL) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3608 return NGX_ERROR; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3609 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3610 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3611 frame->level = level; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3612 frame->type = NGX_QUIC_FT_RETIRE_CONNECTION_ID; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3613 frame->u.retire_cid.sequence_number = seqnum; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3614 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3615 ngx_sprintf(frame->info, "RETIRE_CONNECTION_ID seqnum=%uL level=%d", |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3616 seqnum, frame->level); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3617 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3618 ngx_quic_queue_frame(c->quic, frame); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3619 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3620 return NGX_OK; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3621 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3622 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3623 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3624 static ngx_quic_client_id_t * |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
3625 ngx_quic_alloc_connection_id(ngx_connection_t *c, ngx_quic_connection_t *qc) |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3626 { |
8099
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
3627 ngx_queue_t *q; |
b4ef79ef1c23
QUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov <vl@nginx.com>
parents:
8098
diff
changeset
|
3628 ngx_quic_client_id_t *cid; |
8076
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3629 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3630 if (!ngx_queue_empty(&qc->free_client_ids)) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3631 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3632 q = ngx_queue_head(&qc->free_client_ids); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3633 cid = ngx_queue_data(q, ngx_quic_client_id_t, queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3634 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3635 ngx_queue_remove(&cid->queue); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3636 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3637 ngx_memzero(cid, sizeof(ngx_quic_client_id_t)); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3638 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3639 } else { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3640 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3641 cid = ngx_pcalloc(c->pool, sizeof(ngx_quic_client_id_t)); |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3642 if (cid == NULL) { |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3643 return NULL; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3644 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3645 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3646 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3647 return cid; |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3648 } |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3649 |
3afaaaa930ab
QUIC: added support for multiple connection IDs.
Vladimir Homutov <vl@nginx.com>
parents:
8074
diff
changeset
|
3650 |
7691 | 3651 static void |
3652 ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame) | |
3653 { | |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3654 ngx_quic_send_ctx_t *ctx; |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3655 |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3656 ctx = ngx_quic_get_send_ctx(qc, frame->level); |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3657 |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3658 ngx_queue_insert_tail(&ctx->frames, &frame->queue); |
7775 | 3659 |
7994
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3660 frame->len = ngx_quic_create_frame(NULL, frame); |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3661 /* always succeeds */ |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3662 |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3663 if (qc->closing) { |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3664 return; |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3665 } |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3666 |
8055
924882f42dea
QUIC: do not artificially delay sending queued frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8054
diff
changeset
|
3667 ngx_post_event(&qc->push, &ngx_posted_events); |
7691 | 3668 } |
3669 | |
3670 | |
3671 static ngx_int_t | |
3672 ngx_quic_output(ngx_connection_t *c) | |
3673 { | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3674 ngx_uint_t i; |
7691 | 3675 ngx_quic_connection_t *qc; |
3676 | |
7741 | 3677 c->log->action = "sending frames"; |
3678 | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3679 qc = c->quic; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3680 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3681 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
7809
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3682 if (ngx_quic_output_frames(c, &qc->send_ctx[i]) != NGX_OK) { |
7691 | 3683 return NGX_ERROR; |
3684 } | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3685 } |
7691 | 3686 |
7788
d9bc33166361
Do not set timers after the connection is closed.
Vladimir Homutov <vl@nginx.com>
parents:
7787
diff
changeset
|
3687 if (!qc->send_timer_set && !qc->closing) { |
7737
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
3688 qc->send_timer_set = 1; |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
3689 ngx_add_timer(c->read, qc->tp.max_idle_timeout); |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
3690 } |
8e54a17dabee
Respect QUIC max_idle_timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
7736
diff
changeset
|
3691 |
7691 | 3692 return NGX_OK; |
3693 } | |
3694 | |
3695 | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3696 static ngx_int_t |
7809
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3697 ngx_quic_output_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3698 { |
7994
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3699 size_t len, hlen; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3700 ngx_uint_t need_ack; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3701 ngx_queue_t *q, range; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3702 ngx_quic_frame_t *f; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3703 ngx_quic_congestion_t *cg; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3704 ngx_quic_connection_t *qc; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3705 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3706 qc = c->quic; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3707 cg = &qc->congestion; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3708 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3709 if (ngx_queue_empty(&ctx->frames)) { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3710 return NGX_OK; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3711 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3712 |
7809
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3713 q = ngx_queue_head(&ctx->frames); |
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3714 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3715 |
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3716 /* all frames in same send_ctx share same level */ |
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3717 hlen = (f->level == ssl_encryption_application) ? NGX_QUIC_MAX_SHORT_HEADER |
6ad871b63422
Cleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7808
diff
changeset
|
3718 : NGX_QUIC_MAX_LONG_HEADER; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3719 hlen += EVP_GCM_TLS_TAG_LEN; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3720 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3721 do { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3722 len = 0; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3723 need_ack = 0; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3724 ngx_queue_init(&range); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3725 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3726 do { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3727 /* process group of frames that fits into packet */ |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3728 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3729 |
7994
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3730 if (len && hlen + len + f->len > qc->ctp.max_udp_payload_size) { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3731 break; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3732 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3733 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3734 if (f->need_ack) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3735 need_ack = 1; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3736 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3737 |
7994
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3738 if (need_ack && cg->in_flight + len + f->len > cg->window) { |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3739 break; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3740 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3741 |
7995
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3742 if (!qc->validated) { |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3743 /* |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3744 * Prior to validation, endpoints are limited in what they |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3745 * are able to send. During the handshake, a server cannot |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3746 * send more than three times the data it receives; |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3747 */ |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3748 |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3749 if (((c->sent + len + f->len) / 3) > qc->received) { |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3750 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3751 "quic hit amplification limit" |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3752 " received %uz sent %O", |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3753 qc->received, c->sent); |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3754 break; |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3755 } |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3756 } |
031918df51c0
QUIC: added anti-amplification limit.
Vladimir Homutov <vl@nginx.com>
parents:
7994
diff
changeset
|
3757 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3758 q = ngx_queue_next(q); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3759 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3760 f->first = ngx_current_msec; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3761 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3762 ngx_queue_remove(&f->queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3763 ngx_queue_insert_tail(&range, &f->queue); |
7994
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3764 |
f9fbeb4ee0de
QUIC: added limit of queued data.
Vladimir Homutov <vl@nginx.com>
parents:
7993
diff
changeset
|
3765 len += f->len; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3766 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3767 } while (q != ngx_queue_sentinel(&ctx->frames)); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3768 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3769 if (ngx_queue_empty(&range)) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3770 break; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3771 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3772 |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3773 if (ngx_quic_send_frames(c, ctx, &range) != NGX_OK) { |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3774 return NGX_ERROR; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3775 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3776 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3777 } while (q != ngx_queue_sentinel(&ctx->frames)); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3778 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3779 return NGX_OK; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3780 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3781 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3782 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3783 static void |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3784 ngx_quic_free_frames(ngx_connection_t *c, ngx_queue_t *frames) |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3785 { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3786 ngx_queue_t *q; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3787 ngx_quic_frame_t *f; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3788 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3789 do { |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3790 q = ngx_queue_head(frames); |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3791 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3792 if (q == ngx_queue_sentinel(frames)) { |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3793 break; |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3794 } |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3795 |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3796 ngx_queue_remove(q); |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3797 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3798 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3799 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3800 ngx_quic_free_frame(c, f); |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
3801 } while (1); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3802 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3803 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3804 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3805 static ngx_int_t |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3806 ngx_quic_send_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3807 ngx_queue_t *frames) |
7691 | 3808 { |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3809 ssize_t len; |
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3810 u_char *p; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3811 ngx_msec_t now; |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3812 ngx_str_t out, res; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3813 ngx_queue_t *q; |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
3814 ngx_ssl_conn_t *ssl_conn; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3815 ngx_quic_frame_t *f, *start; |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3816 ngx_quic_header_t pkt; |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
3817 ngx_quic_secrets_t *keys; |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3818 ngx_quic_connection_t *qc; |
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3819 static ngx_str_t initial_token = ngx_null_string; |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
3820 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
3821 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
7691 | 3822 |
7836 | 3823 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
3824 "quic ngx_quic_send_frames"); | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3825 |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
3826 ssl_conn = c->ssl ? c->ssl->connection : NULL; |
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
3827 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3828 q = ngx_queue_head(frames); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3829 start = ngx_queue_data(q, ngx_quic_frame_t, queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3830 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3831 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); |
7691 | 3832 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3833 now = ngx_current_msec; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3834 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3835 p = src; |
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3836 out.data = src; |
7691 | 3837 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3838 for (q = ngx_queue_head(frames); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3839 q != ngx_queue_sentinel(frames); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3840 q = ngx_queue_next(q)) |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3841 { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3842 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
7691 | 3843 |
7836 | 3844 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
3845 "quic frame out: %s", f->info); | |
7691 | 3846 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3847 len = ngx_quic_create_frame(p, f); |
7691 | 3848 if (len == -1) { |
8134
2b11bd029815
QUIC: fixed memory leak in ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
8133
diff
changeset
|
3849 ngx_quic_free_frames(c, frames); |
7691 | 3850 return NGX_ERROR; |
3851 } | |
3852 | |
7778
053fa468b044
Fixed missing propagation of need_ack flag from frames to packet.
Vladimir Homutov <vl@nginx.com>
parents:
7777
diff
changeset
|
3853 if (f->need_ack) { |
053fa468b044
Fixed missing propagation of need_ack flag from frames to packet.
Vladimir Homutov <vl@nginx.com>
parents:
7777
diff
changeset
|
3854 pkt.need_ack = 1; |
053fa468b044
Fixed missing propagation of need_ack flag from frames to packet.
Vladimir Homutov <vl@nginx.com>
parents:
7777
diff
changeset
|
3855 } |
053fa468b044
Fixed missing propagation of need_ack flag from frames to packet.
Vladimir Homutov <vl@nginx.com>
parents:
7777
diff
changeset
|
3856 |
7691 | 3857 p += len; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3858 f->pnum = ctx->pnum; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
3859 f->last = now; |
8131
3bde57a0e6ce
QUIC: zero out packet length in frames prior to send.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8105
diff
changeset
|
3860 f->plen = 0; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3861 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3862 |
7691 | 3863 out.len = p - out.data; |
3864 | |
7767
c9fbe9508e1f
QUIC packet padding to fulfil header protection sample demands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7766
diff
changeset
|
3865 while (out.len < 4) { |
c9fbe9508e1f
QUIC packet padding to fulfil header protection sample demands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7766
diff
changeset
|
3866 *p++ = NGX_QUIC_FT_PADDING; |
c9fbe9508e1f
QUIC packet padding to fulfil header protection sample demands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7766
diff
changeset
|
3867 out.len++; |
c9fbe9508e1f
QUIC packet padding to fulfil header protection sample demands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7766
diff
changeset
|
3868 } |
c9fbe9508e1f
QUIC packet padding to fulfil header protection sample demands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7766
diff
changeset
|
3869 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3870 qc = c->quic; |
7691 | 3871 |
7772
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
3872 keys = &c->quic->keys[start->level]; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
3873 |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
3874 pkt.secret = &keys->server; |
058a5af7ddfc
Refactored QUIC secrets storage.
Vladimir Homutov <vl@nginx.com>
parents:
7771
diff
changeset
|
3875 |
7847
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3876 pkt.flags = NGX_QUIC_PKT_FIXED_BIT; |
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3877 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3878 if (start->level == ssl_encryption_initial) { |
7847
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3879 pkt.flags |= NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_INITIAL; |
7691 | 3880 pkt.token = initial_token; |
3881 | |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3882 } else if (start->level == ssl_encryption_handshake) { |
7847
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3883 pkt.flags |= NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_HANDSHAKE; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3884 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3885 } else { |
7847
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3886 if (c->quic->key_phase) { |
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3887 pkt.flags |= NGX_QUIC_PKT_KPHASE; |
262396242352
Reworked macros for parsing/assembling packet types.
Vladimir Homutov <vl@nginx.com>
parents:
7846
diff
changeset
|
3888 } |
7691 | 3889 } |
3890 | |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3891 ngx_quic_set_packet_number(&pkt, ctx); |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3892 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3893 pkt.log = c->log; |
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3894 pkt.level = start->level; |
7821
e0abe17a2878
Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
3895 pkt.dcid = qc->scid; |
e0abe17a2878
Removed source/destination swap from the function creating header.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
3896 pkt.scid = qc->dcid; |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3897 pkt.payload = out; |
7751
f85749b60e58
Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents:
7750
diff
changeset
|
3898 |
7755
949b95e4d504
Merged ngx_quic_send_packet() into ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
7754
diff
changeset
|
3899 res.data = dst; |
7751
f85749b60e58
Removed memory allocations from encryption code.
Vladimir Homutov <vl@nginx.com>
parents:
7750
diff
changeset
|
3900 |
7836 | 3901 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, c->log, 0, |
3902 "quic packet ready: %ui bytes at level %d" | |
3903 " need_ack: %d number: %L encoded %d:0x%xD", | |
3904 out.len, start->level, pkt.need_ack, pkt.number, | |
3905 pkt.num_len, pkt.trunc); | |
3906 | |
7862
fb7422074258
Added generation of CC frames with error on connection termination.
Vladimir Homutov <vl@nginx.com>
parents:
7861
diff
changeset
|
3907 if (ngx_quic_encrypt(&pkt, ssl_conn, &res) != NGX_OK) { |
8134
2b11bd029815
QUIC: fixed memory leak in ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
8133
diff
changeset
|
3908 ngx_quic_free_frames(c, frames); |
7691 | 3909 return NGX_ERROR; |
3910 } | |
3911 | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3912 len = c->send(c, res.data, res.len); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3913 if (len == NGX_ERROR || (size_t) len != res.len) { |
8134
2b11bd029815
QUIC: fixed memory leak in ngx_quic_send_frames().
Vladimir Homutov <vl@nginx.com>
parents:
8133
diff
changeset
|
3914 ngx_quic_free_frames(c, frames); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3915 return NGX_ERROR; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3916 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3917 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3918 /* len == NGX_OK || NGX_AGAIN */ |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3919 ctx->pnum++; |
7691 | 3920 |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3921 if (pkt.need_ack) { |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3922 /* move frames into the sent queue to wait for ack */ |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3923 |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3924 if (qc->closing) { |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3925 /* if we are closing, any ack will be discarded */ |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3926 ngx_quic_free_frames(c, frames); |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3927 |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3928 } else { |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3929 ngx_queue_add(&ctx->sent, frames); |
7993
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
3930 if (qc->pto.timer_set) { |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
3931 ngx_del_timer(&qc->pto); |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
3932 } |
b276833111cf
QUIC: implemented probe timeout (PTO) calculation.
Vladimir Homutov <vl@nginx.com>
parents:
7992
diff
changeset
|
3933 ngx_add_timer(&qc->pto, ngx_quic_pto(c, ctx)); |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
3934 |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
3935 start->plen = len; |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3936 } |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3937 |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
3938 qc->congestion.in_flight += len; |
7991
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3939 |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3940 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3941 "quic congestion send if:%uz", |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3942 qc->congestion.in_flight); |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3943 } else { |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3944 /* no ack is expected for this frames, so we can free them */ |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3945 ngx_quic_free_frames(c, frames); |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3946 } |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3947 |
1b9db5c8c29b
QUIC: reworked ngx_quic_send_frames() function.
Vladimir Homutov <vl@nginx.com>
parents:
7990
diff
changeset
|
3948 return NGX_OK; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3949 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3950 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3951 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3952 static void |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3953 ngx_quic_set_packet_number(ngx_quic_header_t *pkt, ngx_quic_send_ctx_t *ctx) |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3954 { |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3955 uint64_t delta; |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3956 |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3957 delta = ctx->pnum - ctx->largest_ack; |
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3958 pkt->number = ctx->pnum; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3959 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3960 if (delta <= 0x7F) { |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3961 pkt->num_len = 1; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3962 pkt->trunc = ctx->pnum & 0xff; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3963 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3964 } else if (delta <= 0x7FFF) { |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3965 pkt->num_len = 2; |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3966 pkt->flags |= 0x1; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3967 pkt->trunc = ctx->pnum & 0xffff; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3968 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3969 } else if (delta <= 0x7FFFFF) { |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3970 pkt->num_len = 3; |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3971 pkt->flags |= 0x2; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3972 pkt->trunc = ctx->pnum & 0xffffff; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3973 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3974 } else { |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3975 pkt->num_len = 4; |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3976 pkt->flags |= 0x3; |
7808
bda817d16cc2
Rename types and variables used for packet number space.
Vladimir Homutov <vl@nginx.com>
parents:
7794
diff
changeset
|
3977 pkt->trunc = ctx->pnum & 0xffffffff; |
7781
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3978 } |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3979 } |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3980 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3981 |
fdda518d10ba
Proper handling of packet number in header.
Vladimir Homutov <vl@nginx.com>
parents:
7780
diff
changeset
|
3982 static void |
7990 | 3983 ngx_quic_pto_handler(ngx_event_t *ev) |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3984 { |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3985 ngx_uint_t i; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3986 ngx_queue_t *q; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3987 ngx_connection_t *c; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3988 ngx_quic_frame_t *start; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3989 ngx_quic_send_ctx_t *ctx; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3990 ngx_quic_connection_t *qc; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3991 |
7990 | 3992 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic pto timer"); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3993 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
3994 c = ev->data; |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3995 qc = c->quic; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3996 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3997 qc->pto_count++; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3998 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
3999 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4000 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4001 ctx = &qc->send_ctx[i]; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4002 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4003 if (ngx_queue_empty(&ctx->sent)) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4004 continue; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4005 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4006 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4007 q = ngx_queue_head(&ctx->sent); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4008 start = ngx_queue_data(q, ngx_quic_frame_t, queue); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4009 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4010 if (start->pnum <= ctx->largest_ack |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4011 && ctx->largest_ack != (uint64_t) -1) |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4012 { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4013 continue; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4014 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4015 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4016 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8057
de7d6d943f68
QUIC: fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8056
diff
changeset
|
4017 "quic pto pnum:%uL pto_count:%ui level:%d", |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4018 start->pnum, c->quic->pto_count, start->level); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4019 |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4020 ngx_quic_resend_frames(c, ctx); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4021 } |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4022 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4023 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4024 |
7775 | 4025 static void |
4026 ngx_quic_push_handler(ngx_event_t *ev) | |
4027 { | |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
4028 ngx_connection_t *c; |
7775 | 4029 |
7836 | 4030 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic push timer"); |
7775 | 4031 |
4032 c = ev->data; | |
4033 | |
4034 if (ngx_quic_output(c) != NGX_OK) { | |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
4035 ngx_quic_close_connection(c, NGX_ERROR); |
7775 | 4036 return; |
4037 } | |
4038 } | |
4039 | |
4040 | |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4041 static |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4042 void ngx_quic_lost_handler(ngx_event_t *ev) |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4043 { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4044 ngx_connection_t *c; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4045 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4046 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "quic lost timer"); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4047 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4048 c = ev->data; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4049 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4050 if (ngx_quic_detect_lost(c) != NGX_OK) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4051 ngx_quic_close_connection(c, NGX_ERROR); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4052 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4053 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4054 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4055 |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4056 static ngx_int_t |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4057 ngx_quic_detect_lost(ngx_connection_t *c) |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4058 { |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4059 ngx_uint_t i; |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4060 ngx_msec_t now, wait, min_wait, thr; |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4061 ngx_queue_t *q; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4062 ngx_quic_frame_t *start; |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4063 ngx_quic_send_ctx_t *ctx; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4064 ngx_quic_connection_t *qc; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4065 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4066 qc = c->quic; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4067 now = ngx_current_msec; |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4068 |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4069 min_wait = 0; |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4070 |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4071 thr = NGX_QUIC_TIME_THR * ngx_max(qc->latest_rtt, qc->avg_rtt); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4072 thr = ngx_max(thr, NGX_QUIC_TIME_GRANULARITY); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4073 |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4074 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4075 |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4076 ctx = &qc->send_ctx[i]; |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4077 |
8053
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4078 if (ctx->largest_ack == (uint64_t) -1) { |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4079 continue; |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4080 } |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4081 |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4082 while (!ngx_queue_empty(&ctx->sent)) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4083 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4084 q = ngx_queue_head(&ctx->sent); |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4085 start = ngx_queue_data(q, ngx_quic_frame_t, queue); |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4086 |
8053
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4087 if (start->pnum > ctx->largest_ack) { |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4088 break; |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4089 } |
4e3a71621c9a
QUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8052
diff
changeset
|
4090 |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4091 wait = start->last + thr - now; |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4092 |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4093 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8057
de7d6d943f68
QUIC: fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8056
diff
changeset
|
4094 "quic detect_lost pnum:%uL thr:%M wait:%i level:%d", |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4095 start->pnum, thr, (ngx_int_t) wait, start->level); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4096 |
8054
355e079c5eee
QUIC: do not arm loss detection timer on packet threshold.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8053
diff
changeset
|
4097 if ((ngx_msec_int_t) wait > 0 |
355e079c5eee
QUIC: do not arm loss detection timer on packet threshold.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8053
diff
changeset
|
4098 && ctx->largest_ack - start->pnum < NGX_QUIC_PKT_THR) |
355e079c5eee
QUIC: do not arm loss detection timer on packet threshold.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8053
diff
changeset
|
4099 { |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4100 |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4101 if (min_wait == 0 || wait < min_wait) { |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4102 min_wait = wait; |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4103 } |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4104 |
8054
355e079c5eee
QUIC: do not arm loss detection timer on packet threshold.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8053
diff
changeset
|
4105 break; |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4106 } |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4107 |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4108 ngx_quic_resend_frames(c, ctx); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4109 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4110 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4111 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4112 /* no more preceeding packets */ |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4113 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4114 if (min_wait == 0) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4115 qc->pto.handler = ngx_quic_pto_handler; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4116 return NGX_OK; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4117 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4118 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4119 qc->pto.handler = ngx_quic_lost_handler; |
7992
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4120 |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4121 if (qc->pto.timer_set) { |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4122 ngx_del_timer(&qc->pto); |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4123 } |
909b989ec088
QUIC: reworked retransmission mechanism.
Vladimir Homutov <vl@nginx.com>
parents:
7991
diff
changeset
|
4124 |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4125 ngx_add_timer(&qc->pto, min_wait); |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4126 |
7691 | 4127 return NGX_OK; |
4128 } | |
4129 | |
4130 | |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4131 static void |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4132 ngx_quic_resend_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4133 { |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4134 ngx_queue_t *q; |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4135 ngx_quic_frame_t *f, *start; |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4136 ngx_quic_connection_t *qc; |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4137 |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4138 qc = c->quic; |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4139 q = ngx_queue_head(&ctx->sent); |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4140 start = ngx_queue_data(q, ngx_quic_frame_t, queue); |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4141 |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4142 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4143 "quic resend packet pnum:%uL", start->pnum); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4144 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4145 do { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4146 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4147 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4148 if (f->pnum != start->pnum) { |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4149 break; |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4150 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4151 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4152 q = ngx_queue_next(q); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4153 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4154 ngx_queue_remove(&f->queue); |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4155 ngx_queue_insert_tail(&ctx->frames, &f->queue); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4156 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4157 } while (q != ngx_queue_sentinel(&ctx->sent)); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4158 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4159 ngx_quic_congestion_lost(c, start); |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4160 |
8094
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4161 if (qc->closing) { |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4162 return; |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4163 } |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4164 |
b383120afca3
QUIC: resend frames by moving them to output queue.
Roman Arutyunyan <arut@nginx.com>
parents:
8091
diff
changeset
|
4165 ngx_post_event(&qc->push, &ngx_posted_events); |
8051
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4166 } |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4167 |
38f1be6c603f
QUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8050
diff
changeset
|
4168 |
7691 | 4169 ngx_connection_t * |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4170 ngx_quic_open_stream(ngx_connection_t *c, ngx_uint_t bidi) |
7691 | 4171 { |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4172 size_t rcvbuf_size; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4173 uint64_t id; |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4174 ngx_quic_stream_t *qs, *sn; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4175 ngx_quic_connection_t *qc; |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4176 |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4177 qs = c->qs; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4178 qc = qs->parent->quic; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4179 |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4180 if (bidi) { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4181 if (qc->streams.server_streams_bidi |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4182 >= qc->streams.server_max_streams_bidi) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4183 { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4184 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4185 "quic too many server bidi streams: %uL", |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4186 qc->streams.server_streams_bidi); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4187 return NULL; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4188 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4189 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4190 id = (qc->streams.server_streams_bidi << 2) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4191 | NGX_QUIC_STREAM_SERVER_INITIATED; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4192 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4193 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8017
b0e74a54c98b
QUIC: consistent Stream ID logging format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8014
diff
changeset
|
4194 "quic creating server bidi stream %uL/%uL id:0x%xL", |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4195 qc->streams.server_streams_bidi, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4196 qc->streams.server_max_streams_bidi, id); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4197 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4198 qc->streams.server_streams_bidi++; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4199 rcvbuf_size = qc->tp.initial_max_stream_data_bidi_local; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4200 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4201 } else { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4202 if (qc->streams.server_streams_uni |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4203 >= qc->streams.server_max_streams_uni) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4204 { |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4205 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4206 "quic too many server uni streams: %uL", |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4207 qc->streams.server_streams_uni); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4208 return NULL; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4209 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4210 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4211 id = (qc->streams.server_streams_uni << 2) |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4212 | NGX_QUIC_STREAM_SERVER_INITIATED |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4213 | NGX_QUIC_STREAM_UNIDIRECTIONAL; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4214 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4215 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8017
b0e74a54c98b
QUIC: consistent Stream ID logging format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8014
diff
changeset
|
4216 "quic creating server uni stream %uL/%uL id:0x%xL", |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4217 qc->streams.server_streams_uni, |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4218 qc->streams.server_max_streams_uni, id); |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4219 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4220 qc->streams.server_streams_uni++; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4221 rcvbuf_size = 0; |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4222 } |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4223 |
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8004
diff
changeset
|
4224 sn = ngx_quic_create_stream(qs->parent, id, rcvbuf_size); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4225 if (sn == NULL) { |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4226 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4227 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4228 |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4229 return sn->c; |
7691 | 4230 } |
4231 | |
4232 | |
4233 static void | |
4234 ngx_quic_rbtree_insert_stream(ngx_rbtree_node_t *temp, | |
4235 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
4236 { | |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4237 ngx_rbtree_node_t **p; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4238 ngx_quic_stream_t *qn, *qnt; |
7691 | 4239 |
4240 for ( ;; ) { | |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4241 qn = (ngx_quic_stream_t *) node; |
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4242 qnt = (ngx_quic_stream_t *) temp; |
7691 | 4243 |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4244 p = (qn->id < qnt->id) ? &temp->left : &temp->right; |
7691 | 4245 |
4246 if (*p == sentinel) { | |
4247 break; | |
4248 } | |
4249 | |
4250 temp = *p; | |
4251 } | |
4252 | |
4253 *p = node; | |
4254 node->parent = temp; | |
4255 node->left = sentinel; | |
4256 node->right = sentinel; | |
4257 ngx_rbt_red(node); | |
4258 } | |
4259 | |
4260 | |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4261 static ngx_quic_stream_t * |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4262 ngx_quic_find_stream(ngx_rbtree_t *rbtree, uint64_t id) |
7691 | 4263 { |
4264 ngx_rbtree_node_t *node, *sentinel; | |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4265 ngx_quic_stream_t *qn; |
7691 | 4266 |
4267 node = rbtree->root; | |
4268 sentinel = rbtree->sentinel; | |
4269 | |
4270 while (node != sentinel) { | |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4271 qn = (ngx_quic_stream_t *) node; |
7691 | 4272 |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4273 if (id == qn->id) { |
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4274 return qn; |
7691 | 4275 } |
4276 | |
7750
2935a11c55b6
Fixed QUIC stream insert and find.
Roman Arutyunyan <arut@nginx.com>
parents:
7748
diff
changeset
|
4277 node = (id < qn->id) ? node->left : node->right; |
7691 | 4278 } |
4279 | |
4280 return NULL; | |
4281 } | |
4282 | |
4283 | |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4284 static ngx_quic_stream_t * |
8022
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4285 ngx_quic_create_client_stream(ngx_connection_t *c, uint64_t id) |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4286 { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4287 size_t n; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4288 uint64_t min_id; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4289 ngx_quic_stream_t *sn; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4290 ngx_quic_connection_t *qc; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4291 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4292 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4293 "quic stream id 0x%xL is new", id); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4294 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4295 qc = c->quic; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4296 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4297 if (id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4298 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4299 if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4300 if ((id >> 2) < qc->streams.server_streams_uni) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4301 return NGX_QUIC_STREAM_GONE; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4302 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4303 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4304 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4305 return NULL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4306 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4307 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4308 if ((id >> 2) < qc->streams.client_streams_uni) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4309 return NGX_QUIC_STREAM_GONE; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4310 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4311 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4312 if ((id >> 2) >= qc->streams.client_max_streams_uni) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4313 qc->error = NGX_QUIC_ERR_STREAM_LIMIT_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4314 return NULL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4315 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4316 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4317 min_id = (qc->streams.client_streams_uni << 2) |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4318 | NGX_QUIC_STREAM_UNIDIRECTIONAL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4319 qc->streams.client_streams_uni = (id >> 2) + 1; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4320 n = qc->tp.initial_max_stream_data_uni; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4321 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4322 } else { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4323 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4324 if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4325 if ((id >> 2) < qc->streams.server_streams_bidi) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4326 return NGX_QUIC_STREAM_GONE; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4327 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4328 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4329 qc->error = NGX_QUIC_ERR_STREAM_STATE_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4330 return NULL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4331 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4332 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4333 if ((id >> 2) < qc->streams.client_streams_bidi) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4334 return NGX_QUIC_STREAM_GONE; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4335 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4336 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4337 if ((id >> 2) >= qc->streams.client_max_streams_bidi) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4338 qc->error = NGX_QUIC_ERR_STREAM_LIMIT_ERROR; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4339 return NULL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4340 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4341 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4342 min_id = (qc->streams.client_streams_bidi << 2); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4343 qc->streams.client_streams_bidi = (id >> 2) + 1; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4344 n = qc->tp.initial_max_stream_data_bidi_remote; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4345 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4346 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4347 if (n < NGX_QUIC_STREAM_BUFSIZE) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4348 n = NGX_QUIC_STREAM_BUFSIZE; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4349 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4350 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4351 /* |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4352 * 2.1. Stream Types and Identifiers |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4353 * |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4354 * Within each type, streams are created with numerically increasing |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4355 * stream IDs. A stream ID that is used out of order results in all |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4356 * streams of that type with lower-numbered stream IDs also being |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4357 * opened. |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4358 */ |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4359 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4360 for ( /* void */ ; min_id < id; min_id += 0x04) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4361 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4362 sn = ngx_quic_create_stream(c, min_id, n); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4363 if (sn == NULL) { |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4364 return NULL; |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4365 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4366 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4367 sn->c->listening->handler(sn->c); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4368 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4369 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4370 return ngx_quic_create_stream(c, id, n); |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4371 } |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4372 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4373 |
d277e25e37fc
QUIC: create streams for STREAM_DATA_BLOCKED and MAX_STREAM_DATA.
Roman Arutyunyan <arut@nginx.com>
parents:
8021
diff
changeset
|
4374 static ngx_quic_stream_t * |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4375 ngx_quic_create_stream(ngx_connection_t *c, uint64_t id, size_t rcvbuf_size) |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4376 { |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4377 ngx_log_t *log; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4378 ngx_pool_t *pool; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4379 ngx_quic_stream_t *sn; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4380 ngx_pool_cleanup_t *cln; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4381 ngx_quic_connection_t *qc; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4382 |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4383 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
8017
b0e74a54c98b
QUIC: consistent Stream ID logging format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8014
diff
changeset
|
4384 "quic stream id 0x%xL create", id); |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4385 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4386 qc = c->quic; |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4387 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4388 pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, c->log); |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4389 if (pool == NULL) { |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4390 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4391 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4392 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4393 sn = ngx_pcalloc(pool, sizeof(ngx_quic_stream_t)); |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4394 if (sn == NULL) { |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4395 ngx_destroy_pool(pool); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4396 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4397 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4398 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4399 sn->node.key = id; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4400 sn->parent = c; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4401 sn->id = id; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4402 |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4403 sn->b = ngx_create_temp_buf(pool, rcvbuf_size); |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4404 if (sn->b == NULL) { |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4405 ngx_destroy_pool(pool); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4406 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4407 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4408 |
7811
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
4409 ngx_queue_init(&sn->fs.frames); |
72d20158c814
Added reordering support for STREAM frames.
Vladimir Homutov <vl@nginx.com>
parents:
7810
diff
changeset
|
4410 |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4411 log = ngx_palloc(pool, sizeof(ngx_log_t)); |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4412 if (log == NULL) { |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4413 ngx_destroy_pool(pool); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4414 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4415 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4416 |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4417 *log = *c->log; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4418 pool->log = log; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4419 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4420 sn->c = ngx_get_connection(-1, log); |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4421 if (sn->c == NULL) { |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4422 ngx_destroy_pool(pool); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4423 return NULL; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4424 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4425 |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4426 sn->c->qs = sn; |
8000
893b3313f53c
QUIC: added "quic" listen parameter in Stream.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
4427 sn->c->type = SOCK_STREAM; |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4428 sn->c->pool = pool; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4429 sn->c->ssl = c->ssl; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4430 sn->c->sockaddr = c->sockaddr; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4431 sn->c->listening = c->listening; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4432 sn->c->addr_text = c->addr_text; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4433 sn->c->local_sockaddr = c->local_sockaddr; |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4434 sn->c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4435 |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4436 sn->c->recv = ngx_quic_stream_recv; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4437 sn->c->send = ngx_quic_stream_send; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4438 sn->c->send_chain = ngx_quic_stream_send_chain; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4439 |
7997
b250b515e5b6
QUIC: fixed stream read event log.
Roman Arutyunyan <arut@nginx.com>
parents:
7996
diff
changeset
|
4440 sn->c->read->log = log; |
b250b515e5b6
QUIC: fixed stream read event log.
Roman Arutyunyan <arut@nginx.com>
parents:
7996
diff
changeset
|
4441 sn->c->write->log = log; |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4442 |
7839
44cac24aaa44
Assign connection number to every QUIC stream log.
Roman Arutyunyan <arut@nginx.com>
parents:
7838
diff
changeset
|
4443 log->connection = sn->c->number; |
44cac24aaa44
Assign connection number to every QUIC stream log.
Roman Arutyunyan <arut@nginx.com>
parents:
7838
diff
changeset
|
4444 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4445 if ((id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4446 || (id & NGX_QUIC_STREAM_SERVER_INITIATED)) |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4447 { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4448 sn->c->write->ready = 1; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4449 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4450 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4451 if (id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4452 if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4453 sn->send_max_data = qc->ctp.initial_max_stream_data_uni; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4454 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4455 |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4456 } else { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4457 if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4458 sn->send_max_data = qc->ctp.initial_max_stream_data_bidi_remote; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4459 } else { |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4460 sn->send_max_data = qc->ctp.initial_max_stream_data_bidi_local; |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4461 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4462 } |
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4463 |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4464 cln = ngx_pool_cleanup_add(pool, 0); |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4465 if (cln == NULL) { |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4466 ngx_close_connection(sn->c); |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4467 ngx_destroy_pool(pool); |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4468 return NULL; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4469 } |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4470 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4471 cln->handler = ngx_quic_stream_cleanup_handler; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4472 cln->data = sn->c; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4473 |
7748
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4474 ngx_rbtree_insert(&c->quic->streams.tree, &sn->node); |
4cf00c14f11a
Safe QUIC stream creation.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
4475 |
7695
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4476 return sn; |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4477 } |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4478 |
cfc429911c0d
Implemented creation of server unidirectional streams.
Vladimir Homutov <vl@nginx.com>
parents:
7691
diff
changeset
|
4479 |
7691 | 4480 static ssize_t |
4481 ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, size_t size) | |
4482 { | |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4483 ssize_t len; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4484 ngx_buf_t *b; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4485 ngx_event_t *rev; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4486 ngx_connection_t *pc; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4487 ngx_quic_frame_t *frame; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4488 ngx_quic_stream_t *qs; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4489 ngx_quic_connection_t *qc; |
7691 | 4490 |
4491 qs = c->qs; | |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4492 b = qs->b; |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4493 pc = qs->parent; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4494 qc = pc->quic; |
7745
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4495 rev = c->read; |
7691 | 4496 |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4497 if (rev->error) { |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4498 return NGX_ERROR; |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4499 } |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4500 |
7836 | 4501 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4502 "quic stream id 0x%xL recv: eof:%d, avail:%z", |
7836 | 4503 qs->id, rev->pending_eof, b->last - b->pos); |
7745
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4504 |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4505 if (b->pos == b->last) { |
7745
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4506 rev->ready = 0; |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4507 |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4508 if (rev->pending_eof) { |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4509 rev->eof = 1; |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4510 return 0; |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4511 } |
5f223cdad40e
Implemented eof in QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7744
diff
changeset
|
4512 |
7836 | 4513 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4514 "quic stream id 0x%xL recv() not ready", qs->id); |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4515 return NGX_AGAIN; |
7691 | 4516 } |
4517 | |
4518 len = ngx_min(b->last - b->pos, (ssize_t) size); | |
4519 | |
4520 ngx_memcpy(buf, b->pos, len); | |
4521 | |
4522 b->pos += len; | |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4523 qc->streams.received += len; |
7691 | 4524 |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4525 if (b->pos == b->last) { |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4526 b->pos = b->start; |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4527 b->last = b->start; |
7760
32db41d603cd
Fixed handling QUIC stream eof.
Roman Arutyunyan <arut@nginx.com>
parents:
7759
diff
changeset
|
4528 rev->ready = rev->pending_eof; |
7732
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4529 } |
f92e583fc256
Better flow control and buffering for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7731
diff
changeset
|
4530 |
7836 | 4531 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4532 "quic stream id 0x%xL recv: %z of %uz", qs->id, len, size); |
7691 | 4533 |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4534 if (!rev->pending_eof) { |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4535 frame = ngx_quic_alloc_frame(pc, 0); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4536 if (frame == NULL) { |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4537 return NGX_ERROR; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4538 } |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4539 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4540 frame->level = ssl_encryption_application; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4541 frame->type = NGX_QUIC_FT_MAX_STREAM_DATA; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4542 frame->u.max_stream_data.id = qs->id; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4543 frame->u.max_stream_data.limit = qs->fs.received + (b->pos - b->start) |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4544 + (b->end - b->last); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4545 |
8017
b0e74a54c98b
QUIC: consistent Stream ID logging format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8014
diff
changeset
|
4546 ngx_sprintf(frame->info, |
8018
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
4547 "MAX_STREAM_DATA id:0x%xL limit:%uL l=%d on recv", |
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
4548 frame->u.max_stream_data.id, |
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
4549 frame->u.max_stream_data.limit, |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4550 frame->level); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4551 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4552 ngx_quic_queue_frame(pc->quic, frame); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4553 } |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4554 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4555 if ((qc->streams.recv_max_data / 2) < qc->streams.received) { |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4556 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4557 frame = ngx_quic_alloc_frame(pc, 0); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4558 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4559 if (frame == NULL) { |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4560 return NGX_ERROR; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4561 } |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4562 |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4563 qc->streams.recv_max_data *= 2; |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4564 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4565 frame->level = ssl_encryption_application; |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4566 frame->type = NGX_QUIC_FT_MAX_DATA; |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4567 frame->u.max_data.max_data = qc->streams.recv_max_data; |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4568 |
8018
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
4569 ngx_sprintf(frame->info, "MAX_DATA max_data:%uL level=%d on recv", |
12576ac9556d
QUIC: fixed format specifiers and removed casts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8017
diff
changeset
|
4570 frame->u.max_data.max_data, frame->level); |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4571 |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4572 ngx_quic_queue_frame(pc->quic, frame); |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4573 |
7836 | 4574 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4575 "quic stream id 0x%xL recv: increased max data: %uL", |
7842
fab75acb1f72
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan <arut@nginx.com>
parents:
7841
diff
changeset
|
4576 qs->id, qc->streams.recv_max_data); |
7815
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4577 } |
0f9e9786b90d
Added primitive flow control mechanisms.
Vladimir Homutov <vl@nginx.com>
parents:
7814
diff
changeset
|
4578 |
7691 | 4579 return len; |
4580 } | |
4581 | |
4582 | |
4583 static ssize_t | |
4584 ngx_quic_stream_send(ngx_connection_t *c, u_char *buf, size_t size) | |
4585 { | |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4586 ngx_buf_t b; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4587 ngx_chain_t cl; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4588 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4589 ngx_memzero(&b, sizeof(ngx_buf_t)); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4590 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4591 b.memory = 1; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4592 b.pos = buf; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4593 b.last = buf + size; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4594 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4595 cl.buf = &b; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4596 cl.next = NULL; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4597 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4598 if (ngx_quic_stream_send_chain(c, &cl, 0) == NGX_CHAIN_ERROR) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4599 return NGX_ERROR; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4600 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4601 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4602 if (b.pos == buf) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4603 return NGX_AGAIN; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4604 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4605 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4606 return b.pos - buf; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4607 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4608 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4609 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4610 static ngx_chain_t * |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4611 ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4612 { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4613 u_char *p; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4614 size_t n, max, max_frame, max_flow, max_limit, len; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4615 #if (NGX_DEBUG) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4616 size_t sent; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4617 #endif |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4618 ngx_buf_t *b; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4619 #if (NGX_DEBUG) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4620 ngx_uint_t nframes; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4621 #endif |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4622 ngx_event_t *wev; |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4623 ngx_chain_t *cl; |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4624 ngx_connection_t *pc; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4625 ngx_quic_frame_t *frame; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4626 ngx_quic_stream_t *qs; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4627 ngx_quic_connection_t *qc; |
7691 | 4628 |
4629 qs = c->qs; | |
4630 pc = qs->parent; | |
4631 qc = pc->quic; | |
8021
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4632 wev = c->write; |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4633 |
b66a2a041d7e
QUIC: fixed ngx_http_test_reading() for QUIC streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8020
diff
changeset
|
4634 if (wev->error) { |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4635 return NGX_CHAIN_ERROR; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4636 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4637 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4638 max_frame = ngx_quic_max_stream_frame(qc); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4639 max_flow = ngx_quic_max_stream_flow(c); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4640 max_limit = limit; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4641 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4642 #if (NGX_DEBUG) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4643 sent = 0; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4644 nframes = 0; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4645 #endif |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4646 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4647 for ( ;; ) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4648 max = ngx_min(max_frame, max_flow); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4649 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4650 if (limit) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4651 max = ngx_min(max, max_limit); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4652 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4653 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4654 for (cl = in, n = 0; in; in = in->next) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4655 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4656 if (!ngx_buf_in_memory(in->buf)) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4657 continue; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4658 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4659 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4660 n += ngx_buf_size(in->buf); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4661 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4662 if (n > max) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4663 n = max; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4664 break; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4665 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4666 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4667 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4668 if (n == 0) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4669 wev->ready = (max_flow ? 1 : 0); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4670 break; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4671 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4672 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4673 frame = ngx_quic_alloc_frame(pc, n); |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4674 if (frame == NULL) { |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4675 return NGX_CHAIN_ERROR; |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4676 } |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4677 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4678 frame->level = ssl_encryption_application; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4679 frame->type = NGX_QUIC_FT_STREAM6; /* OFF=1 LEN=1 FIN=0 */ |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4680 frame->u.stream.off = 1; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4681 frame->u.stream.len = 1; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4682 frame->u.stream.fin = 0; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4683 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4684 frame->u.stream.type = frame->type; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4685 frame->u.stream.stream_id = qs->id; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4686 frame->u.stream.offset = c->sent; |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4687 frame->u.stream.length = n; |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4688 frame->u.stream.data = frame->data; |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4689 |
8079
dcbb58e7ed11
QUIC: added logging output stream frame offset.
Roman Arutyunyan <arut@nginx.com>
parents:
8078
diff
changeset
|
4690 ngx_sprintf(frame->info, "STREAM id:0x%xL offset:%O len:%uz level:%d", |
dcbb58e7ed11
QUIC: added logging output stream frame offset.
Roman Arutyunyan <arut@nginx.com>
parents:
8078
diff
changeset
|
4691 qs->id, c->sent, n, frame->level); |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4692 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4693 c->sent += n; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4694 qc->streams.sent += n; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4695 max_flow -= n; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4696 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4697 if (limit) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4698 max_limit -= n; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4699 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4700 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4701 #if (NGX_DEBUG) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4702 sent += n; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4703 nframes++; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4704 #endif |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4705 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4706 for (p = frame->data; n > 0; cl = cl->next) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4707 b = cl->buf; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4708 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4709 if (!ngx_buf_in_memory(b)) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4710 continue; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4711 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4712 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4713 len = ngx_min(n, (size_t) (b->last - b->pos)); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4714 p = ngx_cpymem(p, b->pos, len); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4715 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4716 b->pos += len; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4717 n -= len; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4718 } |
7822
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4719 |
6481427ca3fc
Respecting maximum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
7821
diff
changeset
|
4720 ngx_quic_queue_frame(qc, frame); |
7691 | 4721 } |
4722 | |
8027
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4723 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4724 "quic send_chain sent:%uz, frames:%ui", sent, nframes); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4725 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4726 return in; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4727 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4728 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4729 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4730 static size_t |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4731 ngx_quic_max_stream_frame(ngx_quic_connection_t *qc) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4732 { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4733 /* |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4734 * we need to fit at least 1 frame into a packet, thus account head/tail; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4735 * 25 = 1 + 8x3 is max header for STREAM frame, with 1 byte for frame type |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4736 */ |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4737 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4738 return qc->ctp.max_udp_payload_size - NGX_QUIC_MAX_SHORT_HEADER - 25 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4739 - EVP_GCM_TLS_TAG_LEN; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4740 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4741 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4742 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4743 static size_t |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4744 ngx_quic_max_stream_flow(ngx_connection_t *c) |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4745 { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4746 size_t size; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4747 uint64_t sent, unacked; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4748 ngx_quic_stream_t *qs; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4749 ngx_quic_connection_t *qc; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4750 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4751 qs = c->qs; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4752 qc = qs->parent->quic; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4753 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4754 size = NGX_QUIC_STREAM_BUFSIZE; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4755 sent = c->sent; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4756 unacked = sent - qs->acked; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4757 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4758 if (qc->streams.send_max_data == 0) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4759 qc->streams.send_max_data = qc->ctp.initial_max_data; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4760 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4761 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4762 if (unacked >= NGX_QUIC_STREAM_BUFSIZE) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4763 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4764 "quic send flow hit buffer size"); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4765 return 0; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4766 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4767 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4768 if (unacked + size > NGX_QUIC_STREAM_BUFSIZE) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4769 size = NGX_QUIC_STREAM_BUFSIZE - unacked; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4770 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4771 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4772 if (qc->streams.sent >= qc->streams.send_max_data) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4773 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4774 "quic send flow hit MAX_DATA"); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4775 return 0; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4776 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4777 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4778 if (qc->streams.sent + size > qc->streams.send_max_data) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4779 size = qc->streams.send_max_data - qc->streams.sent; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4780 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4781 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4782 if (sent >= qs->send_max_data) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4783 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4784 "quic send flow hit MAX_STREAM_DATA"); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4785 return 0; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4786 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4787 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4788 if (sent + size > qs->send_max_data) { |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4789 size = qs->send_max_data - sent; |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4790 } |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4791 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4792 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4793 "quic send flow: %uz", size); |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4794 |
bce9e9643444
QUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan <arut@nginx.com>
parents:
8026
diff
changeset
|
4795 return size; |
7691 | 4796 } |
4797 | |
4798 | |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4799 static void |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4800 ngx_quic_stream_cleanup_handler(void *data) |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4801 { |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4802 ngx_connection_t *c = data; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4803 |
7746
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4804 ngx_connection_t *pc; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4805 ngx_quic_frame_t *frame; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4806 ngx_quic_stream_t *qs; |
b364af7f9f3f
Removed ngx_quic_stream_node_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7745
diff
changeset
|
4807 ngx_quic_connection_t *qc; |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4808 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4809 qs = c->qs; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4810 pc = qs->parent; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4811 qc = pc->quic; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4812 |
7836 | 4813 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4814 "quic stream id 0x%xL cleanup", qs->id); |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4815 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4816 ngx_rbtree_delete(&qc->streams.tree, &qs->node); |
7825
d42b50d239f4
Fixed memory leak with reordered stream frames.
Vladimir Homutov <vl@nginx.com>
parents:
7823
diff
changeset
|
4817 ngx_quic_free_frames(pc, &qs->fs.frames); |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4818 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4819 if (qc->closing) { |
7832
ad3a6f069498
Added proper handling of connection close phases.
Vladimir Homutov <vl@nginx.com>
parents:
7831
diff
changeset
|
4820 /* schedule handler call to continue ngx_quic_close_connection() */ |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4821 ngx_post_event(pc->read, &ngx_posted_events); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4822 return; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4823 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7746
diff
changeset
|
4824 |
8066
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4825 if ((qs->id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0 |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4826 || (qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0) |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4827 { |
8077
62db595a86b5
QUIC: do not send STOP_SENDING after STREAM fin.
Roman Arutyunyan <arut@nginx.com>
parents:
8076
diff
changeset
|
4828 if (!c->read->pending_eof && !c->read->error) { |
8066
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4829 frame = ngx_quic_alloc_frame(pc, 0); |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4830 if (frame == NULL) { |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4831 return; |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4832 } |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4833 |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4834 frame->level = ssl_encryption_application; |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4835 frame->type = NGX_QUIC_FT_STOP_SENDING; |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4836 frame->u.stop_sending.id = qs->id; |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4837 frame->u.stop_sending.error_code = 0x100; /* HTTP/3 no error */ |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4838 |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4839 ngx_sprintf(frame->info, "STOP_SENDING id:0x%xL err:0x%xL level:%d", |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4840 qs->id, frame->u.stop_sending.error_code, frame->level); |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4841 |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4842 ngx_quic_queue_frame(qc, frame); |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4843 } |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4844 } |
97da6521657c
QUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan <arut@nginx.com>
parents:
8064
diff
changeset
|
4845 |
8014
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4846 if ((qs->id & NGX_QUIC_STREAM_SERVER_INITIATED) == 0) { |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4847 frame = ngx_quic_alloc_frame(pc, 0); |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4848 if (frame == NULL) { |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4849 return; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4850 } |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4851 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4852 frame->level = ssl_encryption_application; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4853 frame->type = NGX_QUIC_FT_MAX_STREAMS; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4854 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4855 if (qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4856 frame->u.max_streams.limit = ++qc->streams.client_max_streams_uni; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4857 frame->u.max_streams.bidi = 0; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4858 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4859 } else { |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4860 frame->u.max_streams.limit = ++qc->streams.client_max_streams_bidi; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4861 frame->u.max_streams.bidi = 1; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4862 } |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4863 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4864 ngx_sprintf(frame->info, "MAX_STREAMS limit:%uL bidi:%ui level=%d", |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4865 frame->u.max_streams.limit, |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4866 frame->u.max_streams.bidi, |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4867 (int) frame->level); |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4868 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4869 ngx_quic_queue_frame(qc, frame); |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4870 |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4871 if (qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4872 /* do not send fin for client unidirectional streams */ |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4873 return; |
c5324bb3a704
QUIC: limited the number of client-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8013
diff
changeset
|
4874 } |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4875 } |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4876 |
7836 | 4877 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7996
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7995
diff
changeset
|
4878 "quic stream id 0x%xL send fin", qs->id); |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4879 |
7752 | 4880 frame = ngx_quic_alloc_frame(pc, 0); |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4881 if (frame == NULL) { |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4882 return; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4883 } |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4884 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4885 frame->level = ssl_encryption_application; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4886 frame->type = NGX_QUIC_FT_STREAM7; /* OFF=1 LEN=1 FIN=1 */ |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4887 frame->u.stream.off = 1; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4888 frame->u.stream.len = 1; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4889 frame->u.stream.fin = 1; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4890 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4891 frame->u.stream.type = frame->type; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4892 frame->u.stream.stream_id = qs->id; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4893 frame->u.stream.offset = c->sent; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4894 frame->u.stream.length = 0; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4895 frame->u.stream.data = NULL; |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4896 |
8079
dcbb58e7ed11
QUIC: added logging output stream frame offset.
Roman Arutyunyan <arut@nginx.com>
parents:
8078
diff
changeset
|
4897 ngx_sprintf(frame->info, "STREAM id:0x%xL offset:%O fin:1 level:%d", |
dcbb58e7ed11
QUIC: added logging output stream frame offset.
Roman Arutyunyan <arut@nginx.com>
parents:
8078
diff
changeset
|
4898 qs->id, c->sent, frame->level); |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4899 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4900 ngx_quic_queue_frame(qc, frame); |
7759
1ec905f4d851
Push QUIC stream frames in send() and cleanup handler.
Roman Arutyunyan <arut@nginx.com>
parents:
7756
diff
changeset
|
4901 |
1ec905f4d851
Push QUIC stream frames in send() and cleanup handler.
Roman Arutyunyan <arut@nginx.com>
parents:
7756
diff
changeset
|
4902 (void) ngx_quic_output(pc); |
7705
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4903 } |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4904 |
5ad7bffd3850
Send a FIN frame when QUIC stream is closed.
Roman Arutyunyan <arut@nginx.com>
parents:
7703
diff
changeset
|
4905 |
7752 | 4906 static ngx_quic_frame_t * |
4907 ngx_quic_alloc_frame(ngx_connection_t *c, size_t size) | |
4908 { | |
4909 u_char *p; | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4910 ngx_queue_t *q; |
7752 | 4911 ngx_quic_frame_t *frame; |
4912 ngx_quic_connection_t *qc; | |
4913 | |
4914 if (size) { | |
4915 p = ngx_alloc(size, c->log); | |
4916 if (p == NULL) { | |
4917 return NULL; | |
4918 } | |
4919 | |
4920 } else { | |
4921 p = NULL; | |
4922 } | |
4923 | |
4924 qc = c->quic; | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4925 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4926 if (!ngx_queue_empty(&qc->free_frames)) { |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4927 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4928 q = ngx_queue_head(&qc->free_frames); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4929 frame = ngx_queue_data(q, ngx_quic_frame_t, queue); |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4930 |
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
4931 ngx_queue_remove(&frame->queue); |
7752 | 4932 |
7836 | 4933 #ifdef NGX_QUIC_DEBUG_FRAMES_ALLOC |
7752 | 4934 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 4935 "quic reuse frame n:%ui", qc->nframes); |
4936 #endif | |
7752 | 4937 |
4938 } else { | |
4939 frame = ngx_pcalloc(c->pool, sizeof(ngx_quic_frame_t)); | |
4940 if (frame == NULL) { | |
4941 ngx_free(p); | |
4942 return NULL; | |
4943 } | |
4944 | |
4945 #if (NGX_DEBUG) | |
4946 ++qc->nframes; | |
4947 #endif | |
4948 | |
7836 | 4949 #ifdef NGX_QUIC_DEBUG_FRAMES_ALLOC |
7752 | 4950 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 4951 "quic alloc frame n:%ui", qc->nframes); |
4952 #endif | |
7752 | 4953 } |
4954 | |
4955 ngx_memzero(frame, sizeof(ngx_quic_frame_t)); | |
4956 | |
4957 frame->data = p; | |
4958 | |
4959 return frame; | |
4960 } | |
4961 | |
4962 | |
4963 static void | |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4964 ngx_quic_congestion_ack(ngx_connection_t *c, ngx_quic_frame_t *f) |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4965 { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4966 ngx_msec_t timer; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4967 ngx_quic_congestion_t *cg; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4968 ngx_quic_connection_t *qc; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4969 |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4970 if (f->plen == 0) { |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4971 return; |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4972 } |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4973 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4974 qc = c->quic; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4975 cg = &qc->congestion; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4976 |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4977 cg->in_flight -= f->plen; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4978 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4979 timer = f->last - cg->recovery_start; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4980 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4981 if ((ngx_msec_int_t) timer <= 0) { |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4982 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4983 "quic congestion ack recovery win:%uz, ss:%uz, if:%uz", |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4984 cg->window, cg->ssthresh, cg->in_flight); |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4985 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4986 return; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4987 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4988 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4989 if (cg->window < cg->ssthresh) { |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4990 cg->window += f->plen; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4991 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4992 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4993 "quic congestion slow start win:%uz, ss:%uz, if:%uz", |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4994 cg->window, cg->ssthresh, cg->in_flight); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4995 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4996 } else { |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
4997 cg->window += qc->tp.max_udp_payload_size * f->plen / cg->window; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4998 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
4999 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5000 "quic congestion avoidance win:%uz, ss:%uz, if:%uz", |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5001 cg->window, cg->ssthresh, cg->in_flight); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5002 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5003 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5004 /* prevent recovery_start from wrapping */ |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5005 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5006 timer = cg->recovery_start - ngx_current_msec + qc->tp.max_idle_timeout * 2; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5007 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5008 if ((ngx_msec_int_t) timer < 0) { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5009 cg->recovery_start = ngx_current_msec - qc->tp.max_idle_timeout * 2; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5010 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5011 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5012 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5013 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5014 static void |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5015 ngx_quic_congestion_lost(ngx_connection_t *c, ngx_quic_frame_t *f) |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5016 { |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5017 ngx_msec_t timer; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5018 ngx_quic_congestion_t *cg; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5019 ngx_quic_connection_t *qc; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5020 |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5021 if (f->plen == 0) { |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5022 return; |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5023 } |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5024 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5025 qc = c->quic; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5026 cg = &qc->congestion; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5027 |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5028 cg->in_flight -= f->plen; |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5029 |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5030 timer = f->last - cg->recovery_start; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5031 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5032 if ((ngx_msec_int_t) timer <= 0) { |
8026
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5033 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5034 "quic congestion lost recovery win:%uz, ss:%uz, if:%uz", |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5035 cg->window, cg->ssthresh, cg->in_flight); |
4604e6043657
QUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8025
diff
changeset
|
5036 |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5037 return; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5038 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5039 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5040 cg->recovery_start = ngx_current_msec; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5041 cg->window /= 2; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5042 |
7910
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
5043 if (cg->window < qc->tp.max_udp_payload_size * 2) { |
125cbfa77013
Renamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7908
diff
changeset
|
5044 cg->window = qc->tp.max_udp_payload_size * 2; |
7841
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5045 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5046 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5047 cg->ssthresh = cg->window; |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5048 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5049 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5050 "quic congestion lost win:%uz, ss:%uz, if:%uz", |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5051 cg->window, cg->ssthresh, cg->in_flight); |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5052 } |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5053 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5054 |
eee307399229
QUIC basic congestion control.
Roman Arutyunyan <arut@nginx.com>
parents:
7840
diff
changeset
|
5055 static void |
7752 | 5056 ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame) |
5057 { | |
5058 ngx_quic_connection_t *qc; | |
5059 | |
5060 qc = c->quic; | |
5061 | |
5062 if (frame->data) { | |
5063 ngx_free(frame->data); | |
7871 | 5064 frame->data = NULL; |
7752 | 5065 } |
5066 | |
7774
e10b4c61420f
Implemented retransmission and retransmit queue.
Vladimir Homutov <vl@nginx.com>
parents:
7773
diff
changeset
|
5067 ngx_queue_insert_head(&qc->free_frames, &frame->queue); |
7752 | 5068 |
7836 | 5069 #ifdef NGX_QUIC_DEBUG_FRAMES_ALLOC |
7752 | 5070 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
7836 | 5071 "quic free frame n:%ui", qc->nframes); |
5072 #endif | |
7752 | 5073 } |