]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: fixed address validation issues in a new connection.
Sergey Kandaurov [Mon, 2 Nov 2020 17:38:11 +0000 (17:38 +0000)]
QUIC: fixed address validation issues in a new connection.

The client address validation didn't complete with a valid token,
which was broken after packet processing refactoring in d0d3fc0697a0.

An invalid or expired token was treated as a connection error.
Now we proceed as outlined in draft-ietf-quic-transport-32,
section 8.1.3 "Address Validation for Future Connections" below,
which is unlike validating the client address using Retry packets.

   When a server receives an Initial packet with an address validation
   token, it MUST attempt to validate the token, unless it has already
   completed address validation.  If the token is invalid then the
   server SHOULD proceed as if the client did not have a validated
   address, including potentially sending a Retry.

The connection is now closed in this case on internal errors only.

5 years agoQUIC: refactored key handling.
Sergey Kandaurov [Mon, 2 Nov 2020 15:21:34 +0000 (18:21 +0300)]
QUIC: refactored key handling.

All key handling functionality is moved into ngx_quic_protection.c.
Public structures from ngx_quic_protection.h are now private and new
methods are available to manipulate keys.

A negotiated cipher is cached in QUIC connection from the set secret callback
to avoid calling SSL_get_current_cipher() on each encrypt/decrypt operation.
This also reduces the number of unwanted c->ssl->connection occurrences.

5 years agoQUIC: refactored SSL_do_handshake() handling.
Sergey Kandaurov [Thu, 29 Oct 2020 21:50:49 +0000 (21:50 +0000)]
QUIC: refactored SSL_do_handshake() handling.

No functional changes.

5 years agoQUIC: passing ssl_conn to SSL_get0_alpn_selected() directly.
Sergey Kandaurov [Thu, 29 Oct 2020 21:50:19 +0000 (21:50 +0000)]
QUIC: passing ssl_conn to SSL_get0_alpn_selected() directly.

No functional changes.

5 years agoMerged with the default branch.
Sergey Kandaurov [Thu, 29 Oct 2020 14:53:58 +0000 (14:53 +0000)]
Merged with the default branch.

5 years agoQUIC: handle more frames in ngx_quic_resend_frames().
Roman Arutyunyan [Thu, 29 Oct 2020 14:25:02 +0000 (14:25 +0000)]
QUIC: handle more frames in ngx_quic_resend_frames().

When a packet is declared lost, its frames are handled differently according to
13.3. Retransmission of Information.

5 years agoQUIC: avoided retransmission of stale ack frames.
Vladimir Homutov [Wed, 28 Oct 2020 11:22:51 +0000 (14:22 +0300)]
QUIC: avoided retransmission of stale ack frames.

Acknowledgments are regenerated using the most recent data available.

5 years agoCore: added format specifiers to output binary data as hex.
Vladimir Homutov [Wed, 28 Oct 2020 07:56:11 +0000 (10:56 +0300)]
Core: added format specifiers to output binary data as hex.

Now "s", "V", and "v" format specifiers may be prefixed with "x" (lowercase)
or "X" (uppercase) to output corresponding data in hexadecimal format.

In collaboration with Maxim Dounin.

5 years agoVersion bump.
Vladimir Homutov [Thu, 5 Nov 2020 19:37:27 +0000 (22:37 +0300)]
Version bump.

5 years agoQUIC: changed STREAM frame debugging.
Roman Arutyunyan [Tue, 27 Oct 2020 18:21:36 +0000 (18:21 +0000)]
QUIC: changed STREAM frame debugging.

5 years agoQUIC: changed ACK frame debugging.
Roman Arutyunyan [Wed, 28 Oct 2020 09:15:04 +0000 (09:15 +0000)]
QUIC: changed ACK frame debugging.

Previously ACK ranges were logged as a gap/range sequence.  Now these
values are expanded to packet number ranges for easier reading.

5 years agorelease-1.19.4 tag
Maxim Dounin [Tue, 27 Oct 2020 15:09:20 +0000 (18:09 +0300)]
release-1.19.4 tag

5 years agonginx-1.19.4-RELEASE release-1.19.4
Maxim Dounin [Tue, 27 Oct 2020 15:09:20 +0000 (18:09 +0300)]
nginx-1.19.4-RELEASE

5 years agoQUIC: unified range format for rx and tx ACK frames.
Roman Arutyunyan [Tue, 27 Oct 2020 13:24:00 +0000 (13:24 +0000)]
QUIC: unified range format for rx and tx ACK frames.

Previously, tx ACK frames held ranges in an array of ngx_quic_ack_range_t,
while rx ACK frames held ranges in the serialized format.  Now serialized format
is used for both types of frames.

5 years agoQUIC: cleanup send context properly.
Vladimir Homutov [Mon, 26 Oct 2020 21:14:24 +0000 (00:14 +0300)]
QUIC: cleanup send context properly.

The patch resets ctx->frames queue, which may contain frames.  It was possible
that congestion or amplification limits prevented all frames to be sent.

Retransmitted frames could be accounted twice as inflight: first time in
ngx_quic_congestion_lost() called from ngx_quic_resend_frames(), and later
from ngx_quic_discard_ctx().

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 agoSSL: ssl_reject_handshake directive (ticket #195).
Maxim Dounin [Thu, 22 Oct 2020 15:02:28 +0000 (18:02 +0300)]
SSL: ssl_reject_handshake directive (ticket #195).

In some cases it might be needed to reject SSL handshake based on SNI
server name provided, for example, to make sure an invalid certificate
is not returned to clients trying to contact a name-based virtual server
without SSL configured.  Previously, a "ssl_ciphers aNULL;" was used for
this.  This workaround, however, is not compatible with TLSv1.3, in
particular, when using BoringSSL, where it is not possible to configure
TLSv1.3 ciphers at all.

With this change, the ssl_reject_handshake directive is introduced,
which instructs nginx to reject SSL handshakes with an "unrecognized_name"
alert in a particular server block.

For example, to reject handshake with names other than example.com,
one can use the following configuration:

    server {
        listen 443 ssl;
        ssl_reject_handshake on;
    }

    server {
        listen 443 ssl;
        server_name example.com;
        ssl_certificate example.com.crt;
        ssl_certificate_key example.com.key;
    }

The following configuration can be used to reject all SSL handshakes
without SNI server name provided:

    server {
        listen 443 ssl;
        ssl_reject_handshake on;
    }

    server {
        listen 443 ssl;
        server_name ~^;
        ssl_certificate example.crt;
        ssl_certificate_key example.key;
    }

Additionally, the ssl_reject_handshake directive makes configuring
certificates for the default server block optional.  If no certificates
are configured in the default server for a given listening socket,
certificates must be defined in all non-default server blocks with
the listening socket in question.

5 years agoStream: proxy_ssl_conf_command directive.
Maxim Dounin [Thu, 22 Oct 2020 15:00:27 +0000 (18:00 +0300)]
Stream: proxy_ssl_conf_command directive.

Similarly to ssl_conf_command, proxy_ssl_conf_command can be used to
set arbitrary OpenSSL configuration parameters as long as nginx is
compiled with OpenSSL 1.0.2 or later, when connecting to upstream
servers with SSL.  Full list of available configuration commands
can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

5 years agoUpstream: proxy_ssl_conf_command and friends.
Maxim Dounin [Thu, 22 Oct 2020 15:00:23 +0000 (18:00 +0300)]
Upstream: proxy_ssl_conf_command and friends.

Similarly to ssl_conf_command, proxy_ssl_conf_command (grpc_ssl_conf_command,
uwsgi_ssl_conf_command) can be used to set arbitrary OpenSSL configuration
parameters as long as nginx is compiled with OpenSSL 1.0.2 or later,
when connecting to upstream servers with SSL.  Full list of available
configuration commands can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

5 years agoSSL: ssl_conf_command directive.
Maxim Dounin [Thu, 22 Oct 2020 15:00:22 +0000 (18:00 +0300)]
SSL: ssl_conf_command directive.

With the ssl_conf_command directive it is now possible to set
arbitrary OpenSSL configuration parameters as long as nginx is compiled
with OpenSSL 1.0.2 or later.  Full list of available configuration
commands can be found in the SSL_CONF_cmd manual page
(https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html).

In particular, this allows configuring PrioritizeChaCha option
(ticket #1445):

    ssl_conf_command Options PrioritizeChaCha;

It can be also used to configure TLSv1.3 ciphers in OpenSSL,
which fails to configure them via the SSL_CTX_set_cipher_list()
interface (ticket #1529):

    ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;

Configuration commands are applied after nginx own configuration
for SSL, so they can be used to override anything set by nginx.
Note though that configuring OpenSSL directly with ssl_conf_command
might result in a behaviour nginx does not expect, and should be
done with care.

5 years agoCore: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.
Maxim Dounin [Thu, 22 Oct 2020 15:00:20 +0000 (18:00 +0300)]
Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.

With this change, it is now possible to use ngx_conf_merge_ptr_value()
to merge keyval arrays.  This change actually follows much earlier
changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot()
in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22).

To preserve compatibility with existing 3rd party modules, both NULL
and NGX_CONF_UNSET_PTR are accepted for now.

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 agoCpp test: added stream.
Ruslan Ermilov [Tue, 13 Oct 2020 04:44:09 +0000 (07:44 +0300)]
Cpp test: added stream.

5 years agoLimit req: unlocking of nodes on complex value errors.
Maxim Dounin [Thu, 8 Oct 2020 14:44:34 +0000 (17:44 +0300)]
Limit req: unlocking of nodes on complex value errors.

Previously, if there were multiple limits configured, errors in
ngx_http_complex_value() during processing of a non-first limit
resulted in reference count leak in shared memory nodes of already
processed limits.  Fix is to explicity unlock relevant nodes, much
like we do when rejecting requests.

5 years agoMail: proxy_smtp_auth directive.
Maxim Dounin [Sat, 3 Oct 2020 18:04:57 +0000 (21:04 +0300)]
Mail: proxy_smtp_auth directive.

The proxy_smtp_auth directive instructs nginx to authenticate users
on backend via the AUTH command (using the PLAIN SASL mechanism),
similar to what is normally done for IMAP and POP3.

If xclient is enabled along with proxy_smtp_auth, the XCLIENT command
won't try to send the LOGIN parameter.

5 years agoVersion bump.
Maxim Dounin [Sat, 3 Oct 2020 18:01:12 +0000 (21:01 +0300)]
Version bump.

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 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 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.