[nginx] QUIC: refined sending CONNECTION_CLOSE in various packet types.
Sergey Kandaurov
pluknet at nginx.com
Fri Sep 1 21:15:36 UTC 2023
details: https://hg.nginx.org/nginx/rev/36b59521a41c
branches:
changeset: 9156:36b59521a41c
user: Sergey Kandaurov <pluknet at nginx.com>
date: Fri Sep 01 20:31:46 2023 +0400
description:
QUIC: refined sending CONNECTION_CLOSE in various packet types.
As per RFC 9000, section 10.2.3, to ensure that peer successfully removed
packet protection, CONNECTION_CLOSE can be sent in multiple packets using
different packet protection levels.
Now it is sent in all protection levels available.
This roughly corresponds to the following paragraph:
* Prior to confirming the handshake, a peer might be unable to process 1-RTT
packets, so an endpoint SHOULD send a CONNECTION_CLOSE frame in both Handshake
and 1-RTT packets. A server SHOULD also send a CONNECTION_CLOSE frame in an
Initial packet.
In practice, this change allows to avoid sending an Initial packet when we know
the client has handshake keys, by checking if we have discarded initial keys.
Also, this fixes sending CONNECTION_CLOSE when using QuicTLS with old QUIC API,
where TLS stack releases application read keys before handshake confirmation;
it is fixed by sending CONNECTION_CLOSE additionally in a Handshake packet.
diffstat:
src/event/quic/ngx_event_quic.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
diffs (42 lines):
diff -r 35bb47f65cab -r 36b59521a41c src/event/quic/ngx_event_quic.c
--- a/src/event/quic/ngx_event_quic.c Thu Aug 31 22:59:17 2023 +0300
+++ b/src/event/quic/ngx_event_quic.c Fri Sep 01 20:31:46 2023 +0400
@@ -509,9 +509,6 @@ ngx_quic_close_connection(ngx_connection
* to terminate the connection immediately.
*/
- qc->error_level = c->ssl ? SSL_quic_read_level(c->ssl->connection)
- : ssl_encryption_initial;
-
if (qc->error == (ngx_uint_t) -1) {
qc->error = NGX_QUIC_ERR_INTERNAL_ERROR;
qc->error_app = 0;
@@ -524,17 +521,19 @@ ngx_quic_close_connection(ngx_connection
qc->error_app ? "app " : "", qc->error,
qc->error_reason ? qc->error_reason : "");
- if (rc == NGX_OK) {
- ctx = ngx_quic_get_send_ctx(qc, qc->error_level);
- ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
- }
+ for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) {
+ ctx = &qc->send_ctx[i];
+
+ if (!ngx_quic_keys_available(qc->keys, ctx->level)) {
+ continue;
+ }
- (void) ngx_quic_send_cc(c);
+ qc->error_level = ctx->level;
+ (void) ngx_quic_send_cc(c);
- if (qc->error_level == ssl_encryption_handshake) {
- /* for clients that might not have handshake keys */
- qc->error_level = ssl_encryption_initial;
- (void) ngx_quic_send_cc(c);
+ if (rc == NGX_OK && !qc->close.timer_set) {
+ ngx_add_timer(&qc->close, 3 * ngx_quic_pto(c, ctx));
+ }
}
}
More information about the nginx-devel
mailing list