]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: fixed dead store assignment.
Sergey Kandaurov [Wed, 7 Oct 2020 13:51:05 +0000 (14:51 +0100)]
QUIC: fixed dead store assignment.

Found by Clang Static Analyzer.

5 years agoQUIC: fixed format specifier in debug message.
Vladimir Homutov [Wed, 7 Oct 2020 12:29:23 +0000 (15:29 +0300)]
QUIC: fixed format specifier in debug message.

5 years agoQUIC: added debug message with final packet processing status.
Vladimir Homutov [Fri, 2 Oct 2020 13:20:41 +0000 (16:20 +0300)]
QUIC: added debug message with final packet processing status.

5 years agoQUIC: set local_socklen in stream connections.
Roman Arutyunyan [Wed, 7 Oct 2020 11:24:03 +0000 (12:24 +0100)]
QUIC: set local_socklen in stream connections.

Previously, this field was not set while creating a QUIC stream connection.
As a result, calling ngx_connection_local_sockaddr() led to getsockname()
bad descriptor error.

5 years agoQUIC: enabled more key-related debug by default.
Vladimir Homutov [Fri, 2 Oct 2020 09:40:49 +0000 (12:40 +0300)]
QUIC: enabled more key-related debug by default.

5 years agoQUIC: added connection id debug.
Vladimir Homutov [Fri, 2 Oct 2020 09:56:34 +0000 (12:56 +0300)]
QUIC: added connection id debug.

5 years agoQUIC: updated c->log->action strings to reflect proper state.
Vladimir Homutov [Wed, 7 Oct 2020 10:38:17 +0000 (13:38 +0300)]
QUIC: updated c->log->action strings to reflect proper state.

5 years agoQUIC: fixed memory leak in ngx_quic_send_frames().
Vladimir Homutov [Wed, 7 Oct 2020 07:14:02 +0000 (10:14 +0300)]
QUIC: fixed memory leak in ngx_quic_send_frames().

The function did not free passed frames in case of error.

5 years agoQUIC: fixed measuring ACK Delay against 0-RTT packets.
Sergey Kandaurov [Tue, 6 Oct 2020 17:08:55 +0000 (18:08 +0100)]
QUIC: fixed measuring ACK Delay against 0-RTT packets.

5 years agoQUIC: do not resend empty queue when speeding up handshake.
Sergey Kandaurov [Mon, 5 Oct 2020 12:02:53 +0000 (13:02 +0100)]
QUIC: do not resend empty queue when speeding up handshake.

If client acknowledged an Initial packet with CRYPTO frame and then
sent another Initial packet containing duplicate CRYPTO again, this
could result in resending frames off the empty send queue.

5 years agoQUIC: zero out packet length in frames prior to send.
Sergey Kandaurov [Mon, 5 Oct 2020 12:02:38 +0000 (13:02 +0100)]
QUIC: zero out packet length in frames prior to send.

It could be that a frame was previously sent and may have stale information.
This was previously broken by merging frames on resend in b383120afca3.

5 years agoQUIC: fixed build with clang and NGX_QUIC_DEBUG_CRYPTO enabled.
Vladimir Homutov [Mon, 5 Oct 2020 11:36:17 +0000 (14:36 +0300)]
QUIC: fixed build with clang and NGX_QUIC_DEBUG_CRYPTO enabled.

The ngx_quic_hexdump() function is wrapped into macros to cast "data"
argument to "* u_char".

5 years agoQUIC: inline function instead of macro for hexdump.
Vladimir Homutov [Mon, 5 Oct 2020 07:03:01 +0000 (10:03 +0300)]
QUIC: inline function instead of macro for hexdump.

This prevents name clashes with local variables.

5 years agoQUIC: fixed handling of incorrect packets.
Vladimir Homutov [Thu, 1 Oct 2020 19:20:51 +0000 (22:20 +0300)]
QUIC: fixed handling of incorrect packets.

Instead of ignoring, connection was closed. This was broken in d0d3fc0697a0.

5 years agoMerged with the default branch.
Sergey Kandaurov [Thu, 1 Oct 2020 11:21:11 +0000 (12:21 +0100)]
Merged with the default branch.

5 years agoQUIC: a bandaid for calculating ack_delay with non-monotonic time.
Sergey Kandaurov [Thu, 1 Oct 2020 11:10:37 +0000 (12:10 +0100)]
QUIC: a bandaid for calculating ack_delay with non-monotonic time.

5 years agoQUIC: speeding up handshake completion.
Sergey Kandaurov [Thu, 1 Oct 2020 11:10:22 +0000 (12:10 +0100)]
QUIC: speeding up handshake completion.

As per quic-recovery draft, section-6.2.3: resend CRYPTO frames
when receiving an Initial packet containing duplicate CRYPTO data.

5 years agoQUIC: fixed clang-ast asserts.
Sergey Kandaurov [Thu, 1 Oct 2020 11:09:47 +0000 (12:09 +0100)]
QUIC: fixed clang-ast asserts.

5 years agoQUIC: fixed build with OpenSSL after bed310672f39.
Sergey Kandaurov [Thu, 1 Oct 2020 11:00:12 +0000 (12:00 +0100)]
QUIC: fixed build with OpenSSL after bed310672f39.

5 years agoQUIC: moved ssl configuration pointer to quic configuration.
Vladimir Homutov [Thu, 1 Oct 2020 07:04:35 +0000 (10:04 +0300)]
QUIC: moved ssl configuration pointer to quic configuration.

The ssl configuration is obtained at config time and saved for future use.

5 years agoQUIC: added stateless reset support.
Vladimir Homutov [Wed, 30 Sep 2020 17:54:46 +0000 (20:54 +0300)]
QUIC: added stateless reset support.

The new "quic_stateless_reset_token_key" directive is added.  It sets the
endpoint key used to generate stateless reset tokens and enables feature.

If the endpoint receives short-header packet that can't be matched to
existing  connection, a stateless reset packet is generated with
a proper token.

If a valid stateless reset token is found in the incoming packet,
the connection is closed.

Example configuration:

http {
    quic_stateless_reset_token_key  "foo";
    ...
}

5 years agoQUIC: refined the "c->quic->initialized" flag usage.
Vladimir Homutov [Wed, 30 Sep 2020 18:27:52 +0000 (21:27 +0300)]
QUIC: refined the "c->quic->initialized" flag usage.

The flag is tied to the initial secret creation.  The presence of c->quic
pointer is sufficient to enable execution of ngx_quic_close_quic().

The ngx_quic_new_connection() function now returns the allocated quic
connection object and the c->quic pointer is set by the caller.

If an early error occurs before secrets initialization (i.e. in cases
of invalid retry token or nginx exiting), it is still possible to
generate an error response by trying to initialize secrets directly
in the ngx_quic_send_cc() function.

Before the change such early errors failed to send proper connection close
message and logged an error.

An auxilliary ngx_quic_init_secrets() function is introduced to avoid
verbose call to ngx_quic_set_initial_secret() requiring local variable.

5 years agoQUIC: packet processing refactoring.
Vladimir Homutov [Wed, 30 Sep 2020 12:14:09 +0000 (15:14 +0300)]
QUIC: packet processing refactoring.

All packet header parsing is now performed by ngx_quic_parse_packet()
function, located in the ngx_quic_transport.c file.

The packet processing is centralized in the ngx_quic_process_packet()
function which decides if the packet should be accepted, ignored or
connection should be closed, depending on the connection state.

As a result of refactoring, behavior has changed in some places:

 - minimal size of Initial packet is now always tested
 - connection IDs are always tested in existing connections
 - old keys are discarded on encryption level switch

5 years agorelease-1.19.3 tag
Maxim Dounin [Tue, 29 Sep 2020 14:32:10 +0000 (17:32 +0300)]
release-1.19.3 tag

5 years agonginx-1.19.3-RELEASE release-1.19.3
Maxim Dounin [Tue, 29 Sep 2020 14:32:10 +0000 (17:32 +0300)]
nginx-1.19.3-RELEASE

5 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 29 Sep 2020 12:56:16 +0000 (15:56 +0300)]
Updated OpenSSL used for win32 builds.

5 years agoProxy: error checking for array init, missed in 7716:d6a5e14aa3e4.
Maxim Dounin [Tue, 29 Sep 2020 12:54:09 +0000 (15:54 +0300)]
Proxy: error checking for array init, missed in 7716:d6a5e14aa3e4.

Found by Coverity (CID 1467637).

5 years agoUserid: userid_flags fixup.
Maxim Dounin [Tue, 29 Sep 2020 12:52:18 +0000 (15:52 +0300)]
Userid: userid_flags fixup.

In 7717:e3e8b8234f05, the 1st bit was incorrectly used.  It shouldn't
be used for bitmask values, as it is used by NGX_CONF_BITMASK_SET.

Additionally, special value "off" added to make it possible to clear
inherited userid_flags value.

5 years agoResolver: improved error messages (ticket #2024).
Maxim Dounin [Mon, 28 Sep 2020 14:41:22 +0000 (17:41 +0300)]
Resolver: improved error messages (ticket #2024).

5 years agoUserid: userid_flags directive to set cookie flags.
Maxim Dounin [Mon, 28 Sep 2020 14:07:48 +0000 (17:07 +0300)]
Userid: userid_flags directive to set cookie flags.

5 years agoProxy: added the "proxy_cookie_flags" directive.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:11 +0000 (23:21 +0300)]
Proxy: added the "proxy_cookie_flags" directive.

5 years agoProxy: changed interface of some internal functions.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:10 +0000 (23:21 +0300)]
Proxy: changed interface of some internal functions.

This is in preparation for the next change.

Also, moved optimization from ngx_http_proxy_rewrite_regex_handler()
to ngx_http_proxy_rewrite().

5 years agoProxy: strengthen syntax checking for some directives.
Ruslan Ermilov [Sun, 27 Sep 2020 20:21:09 +0000 (23:21 +0300)]
Proxy: strengthen syntax checking for some directives.

The "false" parameter of the proxy_redirect directive is deprecated.
Warning has been emitted since c2230102df6f (0.7.54).

The "off" parameter of the proxy_redirect, proxy_cookie_domain, and
proxy_cookie_path directives tells nginx not to inherit the
configuration from the previous configuration level.

Previously, after specifying the directive with the "off" parameter,
any other directives were ignored, and syntax checking was disabled.

The syntax was enforced to allow either one directive with the "off"
parameter, or several directives with other parameters.

Also, specifying "proxy_redirect default foo" no longer works like
"proxy_redirect default".

5 years agoQUIC: simplified packet header parsing.
Vladimir Homutov [Fri, 25 Sep 2020 18:47:28 +0000 (21:47 +0300)]
QUIC: simplified packet header parsing.

Now flags are processed in ngx_quic_input(), and raw->pos points to the first
byte after the flags. Redundant checks from ngx_quic_parse_short_header() and
ngx_quic_parse_long_header() are removed.

5 years agoQUIC: keep the entire packet size in pkt->len.
Roman Arutyunyan [Fri, 25 Sep 2020 18:46:55 +0000 (21:46 +0300)]
QUIC: keep the entire packet size in pkt->len.

Previously pkt->len kept the length of the packet remainder starting from
pkt->raw->pos.

5 years agoQUIC: switched to using fixed-length server connection IDs.
Vladimir Homutov [Fri, 18 Sep 2020 12:53:37 +0000 (15:53 +0300)]
QUIC: switched to using fixed-length server connection IDs.

5 years agoQUIC: resend frames by moving them to output queue.
Roman Arutyunyan [Wed, 30 Sep 2020 19:23:16 +0000 (20:23 +0100)]
QUIC: resend frames by moving them to output queue.

Previously, when a packet was declared lost, another packet was sent with the
same frames.  Now lost frames are moved to the output frame queue and push
event is posted.  This has the advantage of forming packets with more frames
than before.

Also, the start argument is removed from the ngx_quic_resend_frames()
function as excess information.

5 years agoQUIC: switch stream context to a server selected by SNI.
Roman Arutyunyan [Tue, 29 Sep 2020 21:09:09 +0000 (22:09 +0100)]
QUIC: switch stream context to a server selected by SNI.

Previously the default server configuration context was used until the
:authority or host header was parsed.  This led to using the configuration
parameters like client_header_buffer_size or request_pool_size from the default
server rather than from the server selected by SNI.

Also, the switch to the right server log is implemented.  This issue manifested
itself as QUIC stream being logged to the default server log until :authority
or host is parsed.

5 years agoQUIC: unbreak client certificate verification after 0d2b2664b41c.
Sergey Kandaurov [Wed, 23 Sep 2020 12:13:04 +0000 (13:13 +0100)]
QUIC: unbreak client certificate verification after 0d2b2664b41c.

Initially, client certificate verification didn't work due to the missing
hc->ssl on a QUIC stream, which is started to be set in 7738:7f0981be07c4.
Then it was lost in 7999:0d2b2664b41c introducing "quic" listen parameter.

This change re-adds hc->ssl back for all QUIC connections, similar to SSL.

5 years agoQUIC: prevented posted push event while in the draining state.
Vladimir Homutov [Mon, 21 Sep 2020 10:58:17 +0000 (13:58 +0300)]
QUIC: prevented posted push event while in the draining state.

If the push event was posted before ngx_quic_close_connection(), it could send
data in the draining state.

5 years agoHTTP/3: rearranged length check when parsing header.
Roman Arutyunyan [Wed, 16 Sep 2020 19:21:03 +0000 (20:21 +0100)]
HTTP/3: rearranged length check when parsing header.

The new code looks simpler and is similar to other checks.

5 years agoHTTP/3: removed HTTP/3 parser call from discard body filter.
Roman Arutyunyan [Wed, 16 Sep 2020 18:48:33 +0000 (19:48 +0100)]
HTTP/3: removed HTTP/3 parser call from discard body filter.

Request body discard is disabled for QUIC streams anyway.

5 years agoHTTP/3: reject HTTP/2 frames.
Roman Arutyunyan [Wed, 16 Sep 2020 11:27:23 +0000 (12:27 +0100)]
HTTP/3: reject HTTP/2 frames.

As per HTTP/3 draft 30, section 7.2.8:

   Frame types that were used in HTTP/2 where there is no corresponding
   HTTP/3 frame have also been reserved (Section 11.2.1).  These frame
   types MUST NOT be sent, and their receipt MUST be treated as a
   connection error of type H3_FRAME_UNEXPECTED.

5 years agoStream: set module.
Pavel Pautov [Fri, 28 Aug 2020 21:10:54 +0000 (14:10 -0700)]
Stream: set module.

Adds 'set' directive to the stream server context.

5 years agoSSL: abort handshake on SSL_set_SSL_CTX() errors.
Sergey Kandaurov [Thu, 24 Sep 2020 12:51:29 +0000 (13:51 +0100)]
SSL: abort handshake on SSL_set_SSL_CTX() errors.

In rare cases, such as memory allocation failure, SSL_set_SSL_CTX() returns
NULL, which could mean that a different SSL configuration has not been set.
Note that this new behaviour seemingly originated in OpenSSL-1.1.0 release.

5 years agoHTTP/2: run posted requests after reading body.
Maxim Dounin [Wed, 23 Sep 2020 16:52:31 +0000 (19:52 +0300)]
HTTP/2: run posted requests after reading body.

HTTP/2 code failed to run posted requests after calling the request body
handler, and this resulted in connection hang if a subrequest was created
in the body handler and no other actions were made.

5 years agoHTTP/2: fixed segfault on DATA frames after 400 errors.
Maxim Dounin [Wed, 23 Sep 2020 16:50:49 +0000 (19:50 +0300)]
HTTP/2: fixed segfault on DATA frames after 400 errors.

If 400 errors were redirected to an upstream server using the error_page
directive, DATA frames from the client might cause segmentation fault
due to null pointer dereference.  The bug had appeared in 6989:2c4dbcd6f2e4
(1.13.0).

Fix is to skip such frames in ngx_http_v2_state_read_data() (similarly
to 7561:9f1f9d6e056a).  With the fix, behaviour of 400 errors in HTTP/2
is now similar to one in HTTP/1.x, that is, nginx doesn't try to read the
request body.

Note that proxying 400 errors, as well as other early stage errors, to
upstream servers might not be a good idea anyway.  These errors imply
that reading and processing of the request (and the request headers)
wasn't complete, and proxying of such incomplete request might lead to
various errors.

Reported by Chenglong Zhang.

5 years agoSSL: disabled shutdown when there are buffered data.
Maxim Dounin [Wed, 16 Sep 2020 15:26:25 +0000 (18:26 +0300)]
SSL: disabled shutdown when there are buffered data.

This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors
as observed on the second SSL_shutdown() call after SSL shutdown fixes in
09fb2135a589 (1.19.2), notably when HTTP/2 connections are closed due
to read timeouts while there are incomplete writes.

5 years agoSSL: disabled shutdown after connection errors.
Maxim Dounin [Wed, 16 Sep 2020 15:26:24 +0000 (18:26 +0300)]
SSL: disabled shutdown after connection errors.

This fixes "SSL_shutdown() failed (SSL: ... bad write retry)" errors
as observed on the second SSL_shutdown() call after SSL shutdown fixes in
09fb2135a589 (1.19.2), notably when sending fails in ngx_http_test_expect(),
similarly to ticket #1194.

Note that there are some places where c->error is misused to prevent
further output, such as ngx_http_v2_finalize_connection() if there
are pending streams, or in filter finalization.  These places seem
to be extreme enough to don't care about missing shutdown though.
For example, filter finalization currently prevents keepalive from
being used.

5 years agoSSL: fixed event handling during shutdown.
Maxim Dounin [Wed, 16 Sep 2020 15:26:23 +0000 (18:26 +0300)]
SSL: fixed event handling during shutdown.

The c->read->ready and c->write->ready flags need to be cleared to ensure
that appropriate read or write events will be reported by kernel.  Without
this, SSL shutdown might wait till the timeout after blocking on writing
or reading even if there is a socket activity.

5 years agoSSL: workaround for incorrect SSL_write() errors in OpenSSL 1.1.1.
Maxim Dounin [Wed, 16 Sep 2020 15:26:22 +0000 (18:26 +0300)]
SSL: workaround for incorrect SSL_write() errors in OpenSSL 1.1.1.

OpenSSL 1.1.1 fails to return SSL_ERROR_SYSCALL if an error happens
during SSL_write() after close_notify alert from the peer, and returns
SSL_ERROR_ZERO_RETURN instead.  Broken by this commit, which removes
the "i == 0" check around the SSL_RECEIVED_SHUTDOWN one:

https://git.openssl.org/?p=openssl.git;a=commitdiff;h=8051ab2

In particular, if a client closed the connection without reading
the response but with properly sent close_notify alert, this resulted in
unexpected "SSL_write() failed while ..." critical log message instead
of correct "SSL_write() failed (32: Broken pipe)" at the info level.

Since SSL_ERROR_ZERO_RETURN cannot be legitimately returned after
SSL_write(), the fix is to convert all SSL_ERROR_ZERO_RETURN errors
after SSL_write() to SSL_ERROR_SYSCALL.

5 years agoCache: keep c->body_start when Vary changes (ticket #2029).
Sergey Kandaurov [Wed, 9 Sep 2020 16:26:27 +0000 (19:26 +0300)]
Cache: keep c->body_start when Vary changes (ticket #2029).

If the variant hash doesn't match one we used as a secondary cache key,
we switch back to the original key.  In this case, c->body_start was kept
updated from an existing cache node overwriting the new response value.
After file cache update, it led to discrepancy between a cache node and
cache file seen as critical errors "file cache .. has too long header".

5 years agoHTTP/3: skip unknown frames on request stream.
Roman Arutyunyan [Mon, 24 Aug 2020 06:56:36 +0000 (09:56 +0300)]
HTTP/3: skip unknown frames on request stream.

As per HTTP/3 draft 29, section 4.1:

   Frames of unknown types (Section 9), including reserved frames
   (Section 7.2.8) MAY be sent on a request or push stream before,
   after, or interleaved with other frames described in this section.

Also, trailers frame is now used as an indication of the request body end.

5 years agoHTTP/3: fixed handling request body eof.
Roman Arutyunyan [Wed, 16 Sep 2020 17:59:25 +0000 (18:59 +0100)]
HTTP/3: fixed handling request body eof.

While for HTTP/1 unexpected eof always means an error, for HTTP/3 an eof right
after a DATA frame end means the end of the request body.  For this reason,
since adding HTTP/3 support, eof no longer produced an error right after recv()
but was passed to filters which would make a decision.  This decision was made
in ngx_http_parse_chunked() and ngx_http_v3_parse_request_body() based on the
b->last_buf flag.

Now that since 0f7f1a509113 (1.19.2) rb->chunked->length is a lower threshold
for the expected number of bytes, it can be set to zero to indicate that more
bytes may or may not follow.  Now it's possible to move the check for eof from
parser functions to ngx_http_request_body_chunked_filter() and clean up the
parsing code.

Also, in the default branch, in case of eof, the following three things
happened, which were replaced with returning NGX_ERROR while implementing
HTTP/3:

- "client prematurely closed connection" message was logged
- c->error flag was set
- NGX_HTTP_BAD_REQUEST was returned

The change brings back this behavior for HTTP/1 as well as HTTP/3.

5 years agoQUIC: switched to draft 29 by default.
Vladimir Homutov [Fri, 11 Sep 2020 07:56:05 +0000 (10:56 +0300)]
QUIC: switched to draft 29 by default.

5 years agoQUIC: allowed old DCID for initial packets until first ACK.
Roman Arutyunyan [Wed, 9 Sep 2020 13:35:29 +0000 (16:35 +0300)]
QUIC: allowed old DCID for initial packets until first ACK.

If a packet sent in response to an initial client packet was lost, then
successive client initial packets were dropped by nginx with the unexpected
dcid message logged.  This was because the new DCID generated by the server was
not available to the client.

5 years agoQUIC: eliminated idle timeout restart for dropped packets.
Roman Arutyunyan [Tue, 8 Sep 2020 12:54:02 +0000 (15:54 +0300)]
QUIC: eliminated idle timeout restart for dropped packets.

5 years agoQUIC: removed check for packet size beyond MAX_UDP_PAYLOAD_SIZE.
Sergey Kandaurov [Tue, 8 Sep 2020 10:35:50 +0000 (13:35 +0300)]
QUIC: removed check for packet size beyond MAX_UDP_PAYLOAD_SIZE.

The check tested the total size of a packet header and unprotected packet
payload, which doesn't include the packet number length and expansion of
the packet protection AEAD.  If the packet was corrupted, it could cause
false triggering of the condition due to unsigned type underflow leading
to a connection error.

Existing checks for the QUIC header and protected packet payload lengths
should be enough.

5 years agoQUIC: check that the packet length is of at least sample size.
Sergey Kandaurov [Tue, 8 Sep 2020 10:28:56 +0000 (13:28 +0300)]
QUIC: check that the packet length is of at least sample size.

From quic-tls draft, section 5.4.2:
   An endpoint MUST discard packets that are not long enough to contain
   a complete sample.

The check includes the Packet Number field assumed to be 4 bytes long.

5 years agoQUIC: update packet length for short packets too.
Sergey Kandaurov [Tue, 8 Sep 2020 10:27:39 +0000 (13:27 +0300)]
QUIC: update packet length for short packets too.

During long packet header parsing, pkt->len is updated with the Length
field value that is used to find next coalesced packets in a datagram.
For short packets it still contained the whole QUIC packet size.

This change uniforms packet length handling to always contain the total
length of the packet number and protected packet payload in pkt->len.

5 years agoQUIC: added logging output stream frame offset.
Roman Arutyunyan [Mon, 7 Sep 2020 17:55:36 +0000 (20:55 +0300)]
QUIC: added logging output stream frame offset.

5 years agoQUIC: refactored ngx_quic_retry_input().
Vladimir Homutov [Fri, 4 Sep 2020 12:48:53 +0000 (15:48 +0300)]
QUIC: refactored ngx_quic_retry_input().

The function now returns NGX_DECLINED for packets that need to be ignored
and integrates nicely into ngx_quic_input().

5 years agoQUIC: do not send STOP_SENDING after STREAM fin.
Roman Arutyunyan [Sun, 6 Sep 2020 11:51:23 +0000 (14:51 +0300)]
QUIC: do not send STOP_SENDING after STREAM fin.

Previously STOP_SENDING was sent to client upon stream closure if rev->eof and
rev->error were not set.  This was an indirect indication that no RESET_STREAM
or STREAM fin has arrived.  But it is indeed possible that rev->eof is not set,
but STREAM fin has already been received, just not read out by the application.
In this case sending STOP_SENDING does not make sense and can be misleading for
some clients.

5 years agoQUIC: added support for multiple connection IDs.
Vladimir Homutov [Thu, 3 Sep 2020 10:11:27 +0000 (13:11 +0300)]
QUIC: added support for multiple connection IDs.

The peer may issue additional connection IDs up to the limit defined by
transport parameter "active_connection_id_limit", using NEW_CONNECTION_ID
frames, and retire such IDs using RETIRE_CONNECTION_ID frame.

5 years agoQUIC: style.
Vladimir Homutov [Thu, 27 Aug 2020 07:15:37 +0000 (10:15 +0300)]
QUIC: style.

Moved processing of RETIRE_CONNECTION_ID right after the NEW_CONNECTION_ID.

5 years agoQUIC: pass return code from ngx_quic_decrypt() to the caller.
Vladimir Homutov [Wed, 2 Sep 2020 19:34:15 +0000 (22:34 +0300)]
QUIC: pass return code from ngx_quic_decrypt() to the caller.

It is required to distinguish internal errors from corrupted packets and
perform actions accordingly: drop the packet or close the connection.

While there, made processing of ngx_quic_decrypt() erorrs similar and
removed couple of protocol violation errors.

5 years agoQUIC: discard unrecognized long packes.
Vladimir Homutov [Wed, 2 Sep 2020 06:54:15 +0000 (09:54 +0300)]
QUIC: discard unrecognized long packes.

While there, updated comment about discarded packets.

5 years agoHTTP/3: do not set the never-indexed literal bit by default.
Roman Arutyunyan [Mon, 31 Aug 2020 15:42:26 +0000 (18:42 +0300)]
HTTP/3: do not set the never-indexed literal bit by default.

The "Literal Header Field Never Indexed" header field representation is not
used in HTTP/2, and it makes little sense to make a distinction in HTTP/3.

5 years agoQUIC: discard incorrect packets instead of closing the connection.
Vladimir Homutov [Tue, 1 Sep 2020 14:20:42 +0000 (17:20 +0300)]
QUIC: discard incorrect packets instead of closing the connection.

quic-transport

5.2:
    Packets that are matched to an existing connection are discarded if
    the packets are inconsistent with the state of that connection.

5.2.2:
   Servers MUST drop incoming packets under all other circumstances.

5 years agoQUIC: do not update largest packet number from a bad packet.
Roman Arutyunyan [Tue, 1 Sep 2020 12:21:49 +0000 (15:21 +0300)]
QUIC: do not update largest packet number from a bad packet.

The removal of QUIC packet protection depends on the largest packet number
received.  When a garbage packet was received, the decoder still updated the
largest packet number from that packet.  This could affect removing protection
from subsequent QUIC packets.

5 years agoQUIC: handle PATH_CHALLENGE frame.
Roman Arutyunyan [Fri, 28 Aug 2020 09:01:35 +0000 (12:01 +0300)]
QUIC: handle PATH_CHALLENGE frame.

A PATH_RESPONSE frame with the same data is sent in response.

5 years agoQUIC: enforce flow control on incoming STREAM and CRYPTO frames.
Roman Arutyunyan [Tue, 25 Aug 2020 14:22:57 +0000 (17:22 +0300)]
QUIC: enforce flow control on incoming STREAM and CRYPTO frames.

5 years agoHTTP/3: drop the unwanted remainder of the request.
Roman Arutyunyan [Tue, 25 Aug 2020 09:45:21 +0000 (12:45 +0300)]
HTTP/3: drop the unwanted remainder of the request.

As per HTTP/3 draft 29, section 4.1:

   When the server does not need to receive the remainder of the request,
   it MAY abort reading the request stream, send a complete response, and
   cleanly close the sending part of the stream.

5 years agoQUIC: send STOP_SENDING on stream closure.
Roman Arutyunyan [Tue, 25 Aug 2020 11:07:26 +0000 (14:07 +0300)]
QUIC: send STOP_SENDING on stream closure.

The frame is sent for a read-enabled stream which has not received a FIN or
RESET_STREAM.

5 years agoQUIC: updated README.
Vladimir Homutov [Fri, 21 Aug 2020 11:55:32 +0000 (14:55 +0300)]
QUIC: updated README.

 - version negotiation is implemented
 - quic recovery implementation is greatly improved

5 years agoQUIC: disabled bidirectional SSL shutdown after 09fb2135a589.
Sergey Kandaurov [Fri, 21 Aug 2020 11:41:42 +0000 (14:41 +0300)]
QUIC: disabled bidirectional SSL shutdown after 09fb2135a589.

On QUIC connections, SSL_shutdown() is used to call the send_alert callback
to send a CONNECTION_CLOSE frame.  The reverse side is handled by other means.
At least BoringSSL doesn't differentiate whether this is a QUIC SSL method,
so waiting for the peer's close_notify alert should be explicitly disabled.

5 years agoQUIC: stripped down debug traces that have served its purpose.
Sergey Kandaurov [Fri, 21 Aug 2020 11:41:41 +0000 (14:41 +0300)]
QUIC: stripped down debug traces that have served its purpose.

The most observable remainers are incoming packet and stream payload
that could still be useful to debug various QUIC and HTTP/3 frames.

5 years agoQUIC: dead code removed.
Vladimir Homutov [Fri, 21 Aug 2020 07:00:25 +0000 (10:00 +0300)]
QUIC: dead code removed.

This case was already handled in c70446e3d771.

5 years agoQUIC: removed outdated TODOs.
Vladimir Homutov [Thu, 20 Aug 2020 13:45:48 +0000 (16:45 +0300)]
QUIC: removed outdated TODOs.

The logical quic connection state is tested by handler functions that
process corresponding types of packets (initial/handshake/application).
The packet is declined if state is incorrect.

No timeout is required for the input queue.

5 years agoQUIC: added version negotiation support.
Vladimir Homutov [Thu, 20 Aug 2020 14:11:04 +0000 (17:11 +0300)]
QUIC: added version negotiation support.

If a client attemtps to start a new connection with unsupported version,
a version negotiation packet is sent that contains a list of supported
versions (currently this is a single version, selected at compile time).

5 years agoHTTP/3: special handling of client errors in the upstream module.
Roman Arutyunyan [Thu, 20 Aug 2020 09:33:00 +0000 (12:33 +0300)]
HTTP/3: special handling of client errors in the upstream module.

The function ngx_http_upstream_check_broken_connection() terminates the HTTP/1
request if client sends eof.  For QUIC (including HTTP/3) the c->write->error
flag is now checked instead.  This flag is set when the entire QUIC connection
is closed or STOP_SENDING was received from client.

5 years agoHTTP/3: request more client body bytes.
Roman Arutyunyan [Tue, 18 Aug 2020 14:23:16 +0000 (17:23 +0300)]
HTTP/3: request more client body bytes.

Previously the request body DATA frame header was read by one byte because
filters were called only when the requested number of bytes were read.  Now,
after 08ff2e10ae92 (1.19.2), filters are called after each read.  More bytes
can be read at once, which simplifies and optimizes the code.

This also reduces diff with the default branch.

5 years agoQUIC: fixed format specifiers.
Sergey Kandaurov [Wed, 19 Aug 2020 13:00:12 +0000 (16:00 +0300)]
QUIC: fixed format specifiers.

5 years agoQUIC: changed c->quic->pto_count type to ngx_uint_t.
Sergey Kandaurov [Wed, 19 Aug 2020 12:58:03 +0000 (15:58 +0300)]
QUIC: changed c->quic->pto_count type to ngx_uint_t.

This field is served as a simple counter for PTO backoff.

5 years agoQUIC: do not artificially delay sending queued frames.
Sergey Kandaurov [Wed, 19 Aug 2020 10:24:54 +0000 (13:24 +0300)]
QUIC: do not artificially delay sending queued frames.

This interacts badly with retransmissions of lost packets
and can provoke spurious client retransmits.

5 years agoQUIC: do not arm loss detection timer on packet threshold.
Sergey Kandaurov [Wed, 19 Aug 2020 10:24:53 +0000 (13:24 +0300)]
QUIC: do not arm loss detection timer on packet threshold.

5 years agoQUIC: do not arm loss detection timer for succeeding packets.
Sergey Kandaurov [Wed, 19 Aug 2020 10:24:47 +0000 (13:24 +0300)]
QUIC: do not arm loss detection timer for succeeding packets.

5 years agoQUIC: handling packets with send time equal to lost send time.
Sergey Kandaurov [Wed, 19 Aug 2020 10:24:30 +0000 (13:24 +0300)]
QUIC: handling packets with send time equal to lost send time.

Previously, such packets weren't handled as the resulting zero remaining time
prevented setting the loss detection timer, which, instead, could be disarmed.
For implementation details, see quic-recovery draft 29, appendix A.10.

5 years agoQUIC: sending probe packets on PTO timer expiration.
Sergey Kandaurov [Wed, 19 Aug 2020 10:24:23 +0000 (13:24 +0300)]
QUIC: sending probe packets on PTO timer expiration.

The PTO handler is split into separate PTO and loss detection handlers
that operate interchangeably depending on which timer should be set.

The present ngx_quic_lost_handler is now only used for packet loss detection.
It replaces ngx_quic_pto_handler if there are packets preceeding largest_ack.
Once there is no more such packets, ngx_quic_pto_handler is installed again.

Probes carry unacknowledged data previously sent in the oldest packet number,
one per each packet number space.  That is, it could be up to two probes.

PTO backoff is now increased before scheduling next probes.

5 years agoQUIC: changed ctx->largest_ack initial value to type maximum.
Sergey Kandaurov [Tue, 18 Aug 2020 20:33:40 +0000 (23:33 +0300)]
QUIC: changed ctx->largest_ack initial value to type maximum.

In particular, this prevents declaring packet number 0 as lost if
there aren't yet any acknowledgements in this packet number space.
For example, only Initial packets were acknowledged in handshake.

5 years agoHTTP/3: fixed context storage in request body parser.
Sergey Kandaurov [Tue, 18 Aug 2020 14:11:32 +0000 (17:11 +0300)]
HTTP/3: fixed context storage in request body parser.

5 years agoMerged with the default branch.
Roman Arutyunyan [Tue, 18 Aug 2020 13:22:00 +0000 (16:22 +0300)]
Merged with the default branch.

5 years agoQUIC: coalesce neighbouring stream send buffers.
Roman Arutyunyan [Tue, 18 Aug 2020 09:28:33 +0000 (12:28 +0300)]
QUIC: coalesce neighbouring stream send buffers.

Previously a single STREAM frame was created for each buffer in stream output
chain which is wasteful with respect to memory.  The following changes were
made in the stream send code:

- ngx_quic_stream_send_chain() no longer calls ngx_quic_stream_send() and got
  a separate implementation that coalesces neighbouring buffers into a single
  frame
- the new ngx_quic_stream_send_chain() respects the limit argument, which fixes
  sendfile_max_chunk and limit_rate
- ngx_quic_stream_send() is reimplemented to call ngx_quic_stream_send_chain()
- stream frame size limit is moved out to a separate function
  ngx_quic_max_stream_frame()
- flow control is moved out to a separate function ngx_quic_max_stream_flow()
- ngx_quic_stream_send_chain() is relocated next to ngx_quic_stream_send()

5 years agoQUIC: packet based bytes_in_flight accounting.
Sergey Kandaurov [Fri, 14 Aug 2020 13:54:13 +0000 (16:54 +0300)]
QUIC: packet based bytes_in_flight accounting.

A packet size is kept in one of the frames belonging to the packet.

5 years agoQUIC: fixed leak of bytes_in_flight on keys discard.
Sergey Kandaurov [Fri, 14 Aug 2020 13:54:06 +0000 (16:54 +0300)]
QUIC: fixed leak of bytes_in_flight on keys discard.

This applies to discarding Initial and Handshake keys.

5 years agoQUIC: fixed leak of bytes_in_flight attributed to lost packets.
Sergey Kandaurov [Fri, 14 Aug 2020 13:53:56 +0000 (16:53 +0300)]
QUIC: fixed leak of bytes_in_flight attributed to lost packets.

5 years agorelease-1.19.2 tag
Maxim Dounin [Tue, 11 Aug 2020 14:52:30 +0000 (17:52 +0300)]
release-1.19.2 tag

5 years agonginx-1.19.2-RELEASE release-1.19.2
Maxim Dounin [Tue, 11 Aug 2020 14:52:30 +0000 (17:52 +0300)]
nginx-1.19.2-RELEASE

5 years agoCore: reusing connections in advance.
Maxim Dounin [Mon, 10 Aug 2020 15:53:07 +0000 (18:53 +0300)]
Core: reusing connections in advance.

Reworked connections reuse, so closing connections is attempted in
advance, as long as number of free connections is less than 1/16 of
worker connections configured.  This ensures that new connections can
be handled even if closing a reusable connection requires some time,
for example, for a lingering close (ticket #2017).

The 1/16 ratio is selected to be smaller than 1/8 used for disabling
accept when working with accept mutex, so nginx will try to balance
new connections to different workers first, and will start reusing
connections only if this won't help.

5 years agoCore: added a warning about reusing connections.
Maxim Dounin [Mon, 10 Aug 2020 15:52:59 +0000 (18:52 +0300)]
Core: added a warning about reusing connections.

Previously, reusing connections happened silently and was only
visible in monitoring systems.  This was shown to be not very user-friendly,
and administrators often didn't realize there were too few connections
available to withstand the load, and configured timeouts (keepalive_timeout
and http2_idle_timeout) were effectively reduced to keep things running.

To provide at least some information about this, a warning is now logged
(at most once per second, to avoid flooding the logs).