]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: added push event afer the address was validated.
Vladimir Homutov [Mon, 26 Oct 2020 21:00:56 +0000 (00:00 +0300)]
QUIC: added push event afer the address was validated.

This allows to continue processing when the anti-amplification limit was hit.

5 years agoQUIC: updated anti-amplification check for draft 32.
Vladimir Homutov [Mon, 26 Oct 2020 20:58:34 +0000 (23:58 +0300)]
QUIC: updated anti-amplification check for draft 32.

This accounts for the following change:

   *  Require expansion of datagrams to ensure that a path supports at
      least 1200 bytes:

      -  During the handshake ack-eliciting Initial packets from the
         server need to be expanded

5 years agoQUIC: got rid of "pkt" abbreviation in logs.
Vladimir Homutov [Mon, 26 Oct 2020 20:47:49 +0000 (23:47 +0300)]
QUIC: got rid of "pkt" abbreviation in logs.

5 years agoQUIC: added "rx" and "tx" prefixes to packet debug.
Vladimir Homutov [Mon, 26 Oct 2020 20:47:16 +0000 (23:47 +0300)]
QUIC: added "rx" and "tx" prefixes to packet debug.

5 years agoQUIC: added connection state debug to event handlers.
Vladimir Homutov [Mon, 26 Oct 2020 20:17:54 +0000 (23:17 +0300)]
QUIC: added connection state debug to event handlers.

5 years agoQUIC: added logging of a declined packet without retry token.
Vladimir Homutov [Sun, 25 Oct 2020 21:34:24 +0000 (00:34 +0300)]
QUIC: added logging of a declined packet without retry token.

5 years agoQUIC: revised value separators in debug and error messages.
Vladimir Homutov [Tue, 27 Oct 2020 11:12:31 +0000 (14:12 +0300)]
QUIC: revised value separators in debug and error messages.

All values are prefixed with name and separated from it using colon.
Multiple values are listed without commas in between.

Rationale: this greatly simplifies log parsing for analysis.

5 years agoQUIC: single function for frame debug logging.
Vladimir Homutov [Tue, 27 Oct 2020 11:32:08 +0000 (14:32 +0300)]
QUIC: single function for frame debug logging.

The function may be called for any initialized frame, both rx and tx.

While there, shortened level names.

5 years agoQUIC: optimized acknowledgement generation.
Vladimir Homutov [Fri, 23 Oct 2020 14:08:50 +0000 (17:08 +0300)]
QUIC: optimized acknowledgement generation.

For application level packets, only every second packet is now acknowledged,
respecting max ack delay.

13.2.1 Sending ACK Frames

   In order to assist loss detection at the sender, an endpoint SHOULD
   generate and send an ACK frame without delay when it receives an ack-
   eliciting packet either:

   *  when the received packet has a packet number less than another
      ack-eliciting packet that has been received, or

   *  when the packet has a packet number larger than the highest-
      numbered ack-eliciting packet that has been received and there are
      missing packets between that packet and this packet.

13.2.2.  Acknowledgement Frequency

    A receiver SHOULD send an ACK frame after receiving at least two
    ack-eliciting packets.

5 years agoQUIC: added missing "quic" prefix in debug messages.
Vladimir Homutov [Fri, 23 Oct 2020 15:22:01 +0000 (18:22 +0300)]
QUIC: added missing "quic" prefix in debug messages.

5 years agoQUIC: updated README.
Sergey Kandaurov [Thu, 22 Oct 2020 11:55:15 +0000 (12:55 +0100)]
QUIC: updated README.

 - ACK ranges are implemented
 - up to draft-32 is now supported
 - removed mentions of early alpha quality and further cleanup

5 years agoQUIC: restored proper usage of ngx_quic_drop_ack_ranges().
Sergey Kandaurov [Thu, 22 Oct 2020 10:05:50 +0000 (11:05 +0100)]
QUIC: restored proper usage of ngx_quic_drop_ack_ranges().

ACK Ranges are again managed based on the remembered Largest Acknowledged
sent in the packet being acknowledged, which partially reverts c01964fd7b8b.

5 years agoQUIC: fixed dropping output ack ranges on input ack.
Vladimir Homutov [Wed, 21 Oct 2020 17:39:25 +0000 (20:39 +0300)]
QUIC: fixed dropping output ack ranges on input ack.

While there, additional debug messages were added.

5 years agoQUIC: added macro for unset packet number.
Vladimir Homutov [Wed, 21 Oct 2020 15:44:25 +0000 (18:44 +0300)]
QUIC: added macro for unset packet number.

5 years agoQUIC: drop acknowledged ranges.
Vladimir Homutov [Tue, 20 Oct 2020 15:53:25 +0000 (18:53 +0300)]
QUIC: drop acknowledged ranges.

13.2.4.  Limiting Ranges by Tracking ACK Frames

   When a packet containing an ACK frame is sent, the largest
   acknowledged in that frame may be saved.  When a packet containing an
   ACK frame is acknowledged, the receiver can stop acknowledging
   packets less than or equal to the largest acknowledged in the sent
   ACK frame.

5 years agoQUIC: added ACK frame range support.
Vladimir Homutov [Tue, 20 Oct 2020 15:53:00 +0000 (18:53 +0300)]
QUIC: added ACK frame range support.

The history of acknowledged packet is kept in send context as ranges.
Up to NGX_QUIC_MAX_RANGES ranges is stored.

As a result, instead of separate ack frames, single frame with ranges
is sent.

5 years agoQUIC: expand UDP datagrams with an ack-eliciting Initial packet.
Sergey Kandaurov [Wed, 21 Oct 2020 11:46:23 +0000 (12:46 +0100)]
QUIC: expand UDP datagrams with an ack-eliciting Initial packet.

Per draft-ietf-quic-transport-32 on the topic:

:   Similarly, a server MUST expand the payload of all UDP datagrams carrying
:   ack-eliciting Initial packets to at least the smallest allowed maximum
:   datagram size of 1200 bytes.

5 years agoQUIC: teach how to compute only the length of created QUIC headers.
Sergey Kandaurov [Wed, 21 Oct 2020 11:03:23 +0000 (12:03 +0100)]
QUIC: teach how to compute only the length of created QUIC headers.

It will be used for precise expansion of UDP datagram payload.

5 years agoQUIC: simplified ngx_quic_create_long_header().
Sergey Kandaurov [Wed, 21 Oct 2020 11:03:22 +0000 (12:03 +0100)]
QUIC: simplified ngx_quic_create_long_header().

As seen in the quic-transport draft, which this implementation follows:
Initial packets sent by the server MUST set the Token Length field to zero.

5 years agoQUIC: avoided excessive initialization in ngx_quic_send_frames().
Sergey Kandaurov [Wed, 21 Oct 2020 11:03:22 +0000 (12:03 +0100)]
QUIC: avoided excessive initialization in ngx_quic_send_frames().

A zero-length token was used to initialize a prezeroed packet header.

5 years agoQUIC: sorted ngx_quic_send_frames() declarations.
Sergey Kandaurov [Wed, 21 Oct 2020 11:03:21 +0000 (12:03 +0100)]
QUIC: sorted ngx_quic_send_frames() declarations.

5 years agoQUIC: account packet header length in amplification limit.
Vladimir Homutov [Mon, 19 Oct 2020 09:19:38 +0000 (12:19 +0300)]
QUIC: account packet header length in amplification limit.

This is the restoration of 02ee77f8d53d accidentally reverted by 93be5658a250.

5 years agoQUIC: reverted previous 3 commits.
Vladimir Homutov [Mon, 19 Oct 2020 07:32:53 +0000 (10:32 +0300)]
QUIC: reverted previous 3 commits.

Changes were intended for the test repository.

5 years agotry: --skiptests
Vladimir Homutov [Mon, 19 Oct 2020 07:10:21 +0000 (10:10 +0300)]
try:   --skiptests

5 years agoQUIC: added ACK frame range support.
Vladimir Homutov [Wed, 14 Oct 2020 20:21:36 +0000 (23:21 +0300)]
QUIC: added ACK frame range support.

The history of acknowledged packet is kept in send context as ranges.
Up to NGX_QUIC_MAX_RANGES ranges is stored.

As a result, instead of separate ack frames, single frame with ranges
is sent.

5 years agoSSL: added the "ssl_keys_file" directive.
Vladimir Homutov [Tue, 15 Sep 2020 19:44:46 +0000 (22:44 +0300)]
SSL: added the "ssl_keys_file" directive.

5 years agoQUIC: account packet header length in amplification limit.
Vladimir Homutov [Thu, 15 Oct 2020 08:37:01 +0000 (11:37 +0300)]
QUIC: account packet header length in amplification limit.

Header length calculation is adjusted to account real connection id lengths
instead of worst case.

5 years agoQUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.
Sergey Kandaurov [Mon, 12 Oct 2020 13:00:00 +0000 (14:00 +0100)]
QUIC: fixed ngx_http_upstream_init() much like HTTP/2 connections.

5 years agoQUIC: reset error and error_reason prior to processing packet.
Vladimir Homutov [Fri, 9 Oct 2020 13:57:19 +0000 (16:57 +0300)]
QUIC: reset error and error_reason prior to processing packet.

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.