]> git.kaiwu.me - nginx.git/log
nginx.git
6 years agoQUIC: cleaned up quic encryption state tracking.
Vladimir Homutov [Thu, 18 Jun 2020 11:29:24 +0000 (14:29 +0300)]
QUIC: cleaned up quic encryption state tracking.

The patch removes remnants of the old state tracking mechanism, which did
not take into account assimetry of read/write states and was not very
useful.

The encryption state now is entirely tracked using SSL_quic_read/write_level().

6 years agoQUIC: added ALPN checks.
Vladimir Homutov [Thu, 18 Jun 2020 10:58:46 +0000 (13:58 +0300)]
QUIC: added ALPN checks.

quic-transport draft 29:

    section 7:

    *  authenticated negotiation of an application protocol (TLS uses
       ALPN [RFC7301] for this purpose)

    ...

    Endpoints MUST explicitly negotiate an application protocol.  This
    avoids situations where there is a disagreement about the protocol
    that is in use.

    section 8.1:

    When using ALPN, endpoints MUST immediately close a connection (see
    Section 10.3 of [QUIC-TRANSPORT]) with a no_application_protocol TLS
    alert (QUIC error code 0x178; see Section 4.10) if an application
    protocol is not negotiated.

Changes in ngx_quic_close_quic() function are required to avoid attempts
to generated and send packets without proper keys, what happens in case
of failed ALPN check.

6 years agoQUIC: fixed off-by-one in frame range handler.
Vladimir Homutov [Thu, 18 Jun 2020 08:16:35 +0000 (11:16 +0300)]
QUIC: fixed off-by-one in frame range handler.

The ctx->pnum is incremented after the packet is sent, thus pointing to the
next packet number, which should not be used in comparison.

6 years agoQUIC: further limiting maximum QUIC packet size.
Vladimir Homutov [Tue, 16 Jun 2020 08:54:05 +0000 (11:54 +0300)]
QUIC: further limiting maximum QUIC packet size.

quic-transport draft 29, section 14:

    QUIC depends upon a minimum IP packet size of at least 1280 bytes.
    This is the IPv6 minimum size [RFC8200] and is also supported by most
    modern IPv4 networks.  Assuming the minimum IP header size, this
    results in a QUIC maximum packet size of 1232 bytes for IPv6 and 1252
    bytes for IPv4.

Since the packet size can change during connection lifetime, the
ngx_quic_max_udp_payload() function is introduced that currently
returns minimal allowed size, depending on address family.

6 years agoQUIC: raise error on missing transport parameters.
Vladimir Homutov [Mon, 15 Jun 2020 14:06:40 +0000 (17:06 +0300)]
QUIC: raise error on missing transport parameters.

quic-tls, 8.2:

    The quic_transport_parameters extension is carried in the ClientHello
    and the EncryptedExtensions messages during the handshake.  Endpoints
    MUST send the quic_transport_parameters extension; endpoints that
    receive ClientHello or EncryptedExtensions messages without the
    quic_transport_parameters extension MUST close the connection with an
    error of type 0x16d (equivalent to a fatal TLS missing_extension
    alert, see Section 4.10).

6 years agoQUIC: Fixed connection cleanup.
Vladimir Homutov [Mon, 15 Jun 2020 13:59:53 +0000 (16:59 +0300)]
QUIC: Fixed connection cleanup.

A posted event need to be deleted during the connection close.

6 years agoStyle.
Vladimir Homutov [Wed, 10 Jun 2020 18:37:48 +0000 (21:37 +0300)]
Style.

6 years agoLimited max udp payload size for outgoing packets.
Vladimir Homutov [Wed, 10 Jun 2020 18:37:08 +0000 (21:37 +0300)]
Limited max udp payload size for outgoing packets.

This allows to avoid problems with packet fragmentation in real networks.
This is a temporary workaround.

6 years agoIncreased default initial retransmit timeout.
Vladimir Homutov [Wed, 10 Jun 2020 18:33:20 +0000 (21:33 +0300)]
Increased default initial retransmit timeout.

This is a temporary workaround, proper retransmission mechanism based on
quic-recovery rfc draft is yet to be implemented.

Currently hardcoded value is too small for real networks.  The patch
sets static PTO, considering rtt of ~333ms, what gives about 1s.

6 years agoFixed usage of own/client transport parameters.
Vladimir Homutov [Wed, 10 Jun 2020 18:23:10 +0000 (21:23 +0300)]
Fixed usage of own/client transport parameters.

6 years agoStream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.
Sergey Kandaurov [Fri, 5 Jun 2020 17:59:27 +0000 (20:59 +0300)]
Stream ID handling in MAX_STREAM_DATA and STREAM_DATA_BLOCKED.

6 years agoStream ID handling in RESET_STREAM and STOP_SENDING frames.
Sergey Kandaurov [Fri, 5 Jun 2020 17:59:27 +0000 (20:59 +0300)]
Stream ID handling in RESET_STREAM and STOP_SENDING frames.

6 years agoReject invalid STREAM ID with STREAM_STATE_ERROR connection error.
Sergey Kandaurov [Fri, 5 Jun 2020 17:59:26 +0000 (20:59 +0300)]
Reject invalid STREAM ID with STREAM_STATE_ERROR connection error.

6 years agoIntroduced connection error APPLICATION_ERROR from draft-28.
Sergey Kandaurov [Fri, 5 Jun 2020 10:20:03 +0000 (13:20 +0300)]
Introduced connection error APPLICATION_ERROR from draft-28.

6 years agoReceipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.
Sergey Kandaurov [Fri, 5 Jun 2020 10:20:02 +0000 (13:20 +0300)]
Receipt of CONNECTION_CLOSE in 0-RTT is permitted in draft-28.

6 years agoTreat receipt of NEW_TOKEN as connection error PROTOCOL_VIOLATION.
Sergey Kandaurov [Fri, 5 Jun 2020 10:20:02 +0000 (13:20 +0300)]
Treat receipt of NEW_TOKEN as connection error PROTOCOL_VIOLATION.

6 years agoDecoupled validation of Host and :authority for HTTP/2 and HTTP/3.
Roman Arutyunyan [Tue, 2 Jun 2020 12:59:14 +0000 (15:59 +0300)]
Decoupled validation of Host and :authority for HTTP/2 and HTTP/3.

Previously an error was triggered for HTTP/2 when host with port was passed
by client.

6 years agoCompatibility with BoringSSL master branch.
Sergey Kandaurov [Mon, 1 Jun 2020 16:53:13 +0000 (19:53 +0300)]
Compatibility with BoringSSL master branch.

Recently BoringSSL introduced SSL_set_quic_early_data_context()
that serves as an additional constrain to enable 0-RTT in QUIC.

Relevant changes:
 * https://boringssl.googlesource.com/boringssl/+/7c52299%5E!/
 * https://boringssl.googlesource.com/boringssl/+/8519432%5E!/

6 years agoFixed transport parameters on a new connection with a valid token.
Sergey Kandaurov [Mon, 1 Jun 2020 16:16:44 +0000 (19:16 +0300)]
Fixed transport parameters on a new connection with a valid token.

Previously, the retry transport parameter was sent regardless.

6 years agoRequire ":authority" or "Host" in HTTP/3 and HTTP/2 requests.
Roman Arutyunyan [Fri, 29 May 2020 09:42:23 +0000 (12:42 +0300)]
Require ":authority" or "Host" in HTTP/3 and HTTP/2 requests.

Also, if both are present, require that they have the same value.  These
requirements are specified in HTTP/3 draft 28.

Current implementation of HTTP/2 treats ":authority" and "Host"
interchangeably.  New checks only make sure at least one of these values is
present in the request.  A similar check existed earlier and was limited only
to HTTP/1.1 in 38c0898b6df7.

6 years agoAdded propagation of the "wildcard" flag to c->listening.
Vladimir Homutov [Fri, 29 May 2020 10:29:24 +0000 (13:29 +0300)]
Added propagation of the "wildcard" flag to c->listening.

The flags was originally added by 8f038068f4bc, and is propagated correctly
in the stream module.  With QUIC introduction, http module now uses datagram
sockets as well, thus the fix.

6 years agoMade NGX_QUIC_DRAFT_VERSION tunable from configure parameters.
Sergey Kandaurov [Fri, 29 May 2020 12:07:46 +0000 (15:07 +0300)]
Made NGX_QUIC_DRAFT_VERSION tunable from configure parameters.

Now it can be switched using --with-cc-opt='-DNGX_QUIC_DRAFT_VERSION=28'.

6 years agoQUIC draft-28 transport parameters support.
Sergey Kandaurov [Fri, 29 May 2020 12:06:33 +0000 (15:06 +0300)]
QUIC draft-28 transport parameters support.

Draft-27 and draft-28 support can now be enabled interchangeably,
it's based on the compile-time macro NGX_QUIC_DRAFT_VERSION.

6 years agoIntroduced macros for building length-value transport parameters.
Sergey Kandaurov [Fri, 29 May 2020 10:05:57 +0000 (13:05 +0300)]
Introduced macros for building length-value transport parameters.

6 years agoRenamed max_packet_size to max_udp_payload_size, from draft-28.
Sergey Kandaurov [Fri, 29 May 2020 09:56:08 +0000 (12:56 +0300)]
Renamed max_packet_size to max_udp_payload_size, from draft-28.

No functional changes.

6 years agoRejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.
Sergey Kandaurov [Fri, 29 May 2020 09:55:39 +0000 (12:55 +0300)]
Rejected forbidden transport parameters with TRANSPORT_PARAMETER_ERROR.

6 years agoFixed return codes in ngx_quic_add_handshake_data() callback.
Sergey Kandaurov [Fri, 29 May 2020 09:50:20 +0000 (12:50 +0300)]
Fixed return codes in ngx_quic_add_handshake_data() callback.

6 years agoREADME: update after merging 1.19.0.
Sergey Kandaurov [Tue, 26 May 2020 17:41:43 +0000 (20:41 +0300)]
README: update after merging 1.19.0.

6 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 26 May 2020 17:26:44 +0000 (20:26 +0300)]
Merged with the default branch.

6 years agorelease-1.19.0 tag
Maxim Dounin [Tue, 26 May 2020 15:00:20 +0000 (18:00 +0300)]
release-1.19.0 tag

6 years agonginx-1.19.0-RELEASE release-1.19.0
Maxim Dounin [Tue, 26 May 2020 15:00:20 +0000 (18:00 +0300)]
nginx-1.19.0-RELEASE

6 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Mon, 25 May 2020 19:10:37 +0000 (22:10 +0300)]
Updated OpenSSL used for win32 builds.

6 years agoUpdated README with "Contributing" section and draft details.
Vladimir Homutov [Mon, 25 May 2020 15:37:43 +0000 (18:37 +0300)]
Updated README with "Contributing" section and draft details.

6 years agoHTTP/2: invalid connection preface logging (ticket #1981).
Maxim Dounin [Mon, 25 May 2020 15:33:42 +0000 (18:33 +0300)]
HTTP/2: invalid connection preface logging (ticket #1981).

Previously, invalid connection preface errors were only logged at debug
level, providing no visible feedback, in particular, when a plain text
HTTP/2 listening socket is erroneously used for HTTP/1.x connections.
Now these are explicitly logged at the info level, much like other
client-related errors.

6 years agoFixed format specifiers.
Sergey Kandaurov [Sat, 23 May 2020 12:53:08 +0000 (15:53 +0300)]
Fixed format specifiers.

6 years agoOCSP: certificate status cache.
Roman Arutyunyan [Fri, 22 May 2020 14:25:27 +0000 (17:25 +0300)]
OCSP: certificate status cache.

When enabled, certificate status is stored in cache and is used to validate
the certificate in future requests.

New directive ssl_ocsp_cache is added to configure the cache.

6 years agoSSL: client certificate validation with OCSP (ticket #1534).
Roman Arutyunyan [Fri, 22 May 2020 14:30:12 +0000 (17:30 +0300)]
SSL: client certificate validation with OCSP (ticket #1534).

OCSP validation for client certificates is enabled by the "ssl_ocsp" directive.
OCSP responder can be optionally specified by "ssl_ocsp_responder".

When session is reused, peer chain is not available for validation.
If the verified chain contains certificates from the peer chain not available
at the server, validation will fail.

6 years agoOCSP stapling: iterate over all responder addresses.
Roman Arutyunyan [Fri, 22 May 2020 17:35:05 +0000 (20:35 +0300)]
OCSP stapling: iterate over all responder addresses.

Previously only the first responder address was used per each stapling update.
Now, in case of a network or parsing error, next address is used.

This also fixes the issue with unsupported responder address families
(ticket #1330).

6 years agoOCSP stapling: keep extra chain in the staple object.
Roman Arutyunyan [Sun, 17 May 2020 11:24:35 +0000 (14:24 +0300)]
OCSP stapling: keep extra chain in the staple object.

6 years agoHTTP/3: reallocate strings inserted into the dynamic table.
Roman Arutyunyan [Thu, 14 May 2020 13:02:32 +0000 (16:02 +0300)]
HTTP/3: reallocate strings inserted into the dynamic table.

They should always be allocated from the main QUIC connection pool.

6 years agoFixed client buffer reallocation for HTTP/3.
Roman Arutyunyan [Tue, 19 May 2020 13:20:33 +0000 (16:20 +0300)]
Fixed client buffer reallocation for HTTP/3.

Preserving pointers within the client buffer is not needed for HTTP/3 because
all data is either allocated from pool or static.  Unlike with HTTP/1, data
typically cannot be referenced directly within the client buffer.  Trying to
preserve NULLs or external pointers lead to broken pointers.

Also, reverted changes in ngx_http_alloc_large_header_buffer() not relevant
for HTTP/3 to minimize diff to mainstream.

6 years agoFixed $request_length for HTTP/3.
Roman Arutyunyan [Tue, 19 May 2020 12:47:37 +0000 (15:47 +0300)]
Fixed $request_length for HTTP/3.

New field r->parse_start is introduced to substitute r->request_start and
r->header_name_start for request length accounting.  These fields only work for
this purpose in HTTP/1 because HTTP/1 request line and header line start with
these values.

Also, error logging is now fixed to output the right part of the request.

6 years agoHTTP/3: restricted symbols in header names.
Roman Arutyunyan [Tue, 19 May 2020 12:34:00 +0000 (15:34 +0300)]
HTTP/3: restricted symbols in header names.

As per HTTP/3 draft 27, a request or response containing uppercase header
field names MUST be treated as malformed.  Also, existing rules applied
when parsing HTTP/1 header names are also applied to HTTP/3 header names:

- null character is not allowed
- underscore character may or may not be treated as invalid depending on the
  value of "underscores_in_headers"
- all non-alphanumeric characters with the exception of '-' are treated as
  invalid

Also, the r->locase_header field is now filled while parsing an HTTP/3
header.

Error logging for invalid headers is fixed as well.

6 years agoHTTP/3: split header parser in two functions.
Roman Arutyunyan [Tue, 19 May 2020 12:29:10 +0000 (15:29 +0300)]
HTTP/3: split header parser in two functions.

The first one parses pseudo-headers and is analagous to the request line
parser in HTTP/1.  The second one parses regular headers and is analogous to
the header parser in HTTP/1.

Additionally, error handling of client passing malformed uri is now fixed.

6 years agoHTTP/3: move body parser call out of ngx_http_parse_chunked().
Roman Arutyunyan [Thu, 14 May 2020 11:49:53 +0000 (14:49 +0300)]
HTTP/3: move body parser call out of ngx_http_parse_chunked().

The function ngx_http_parse_chunked() is also called from the proxy module to
parse the upstream response.  It should always parse HTTP/1 body in this case.

6 years agoHTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan [Tue, 19 May 2020 12:41:41 +0000 (15:41 +0300)]
HTTP/3: prevent array access by negative index for unknown streams.

Currently there are no such streams, but the function
ngx_http_v3_get_uni_stream() supports them.

6 years agoREADME: documented Retry, 0-RTT, TLSv1.3 configuration.
Sergey Kandaurov [Sat, 23 May 2020 11:41:08 +0000 (14:41 +0300)]
README: documented Retry, 0-RTT, TLSv1.3 configuration.

6 years agoStyle.
Vladimir Homutov [Thu, 21 May 2020 12:48:39 +0000 (15:48 +0300)]
Style.

Rephrased error message and removed trailing space.  Long comments were
shortened/rephrased.

6 years agoAdded sending of extra CONNECTION_CLOSE frames.
Vladimir Homutov [Fri, 22 May 2020 15:14:35 +0000 (18:14 +0300)]
Added sending of extra CONNECTION_CLOSE frames.

According to quic-transport draft 28 section 10.3.1:

   When sending CONNECTION_CLOSE, the goal is to ensure that the peer
   will process the frame.  Generally, this means sending the frame in a
   packet with the highest level of packet protection to avoid the
   packet being discarded.  After the handshake is confirmed (see
   Section 4.1.2 of [QUIC-TLS]), an endpoint MUST send any
   CONNECTION_CLOSE frames in a 1-RTT packet.  However, prior to
   confirming the handshake, it is possible that more advanced packet
   protection keys are not available to the peer, so another
   CONNECTION_CLOSE frame MAY be sent in a packet that uses a lower
   packet protection level.

6 years agoAdded more context to CONNECTION CLOSE frames.
Vladimir Homutov [Fri, 22 May 2020 15:08:02 +0000 (18:08 +0300)]
Added more context to CONNECTION CLOSE frames.

Now it is possible to specify frame type that caused an error
and a human-readable reason phrase.

6 years agoFixed retransmission of frames after closing connection.
Vladimir Homutov [Thu, 21 May 2020 12:41:01 +0000 (15:41 +0300)]
Fixed retransmission of frames after closing connection.

Frames in sent queues are discarded, as no acknowledgment is expected
if the connection is closing.

6 years agoAvoided excessive definitions for connection state.
Vladimir Homutov [Thu, 21 May 2020 12:38:52 +0000 (15:38 +0300)]
Avoided excessive definitions for connection state.

There is no need in a separate type for the QUIC connection state.
The only state not found in the SSL library is NGX_QUIC_ST_UNAVAILABLE,
which is actually a flag used by the ngx_quic_close_quic() function
to prevent cleanup of uninitialized connection.

6 years agoREADME: pointed out Alt-Svc "ma" parameter useful with curl.
Sergey Kandaurov [Fri, 22 May 2020 15:22:00 +0000 (18:22 +0300)]
README: pointed out Alt-Svc "ma" parameter useful with curl.

6 years agoFixed a typo.
Vladimir Homutov [Fri, 22 May 2020 15:16:34 +0000 (18:16 +0300)]
Fixed a typo.

6 years agoAssorted fixes.
Sergey Kandaurov [Wed, 20 May 2020 12:36:24 +0000 (15:36 +0300)]
Assorted fixes.

Found by Clang Static Analyzer.

6 years agoAvoid retransmitting of packets with discarded keys.
Vladimir Homutov [Mon, 18 May 2020 10:54:53 +0000 (13:54 +0300)]
Avoid retransmitting of packets with discarded keys.

Sections 4.10.1 and 4.10.2 of quic transport describe discarding of initial
and handshake keys.  Since the keys are discarded, we no longer need
to retransmit packets and corresponding queues should be emptied.

This patch removes previously added workaround that did not require
acknowledgement for initial packets, resulting in avoiding retransmission,
which is wrong because a packet could be lost and we have to retransmit it.

6 years agoFixed frame retransmissions.
Vladimir Homutov [Mon, 18 May 2020 10:54:35 +0000 (13:54 +0300)]
Fixed frame retransmissions.

It was possible that retransmit timer was not set after the first
retransmission attempt, due to ngx_quic_retransmit() did not set
wait time properly, and the condition in retransmit handler was incorrect.

6 years agoRemoved outdated debug.
Vladimir Homutov [Thu, 14 May 2020 15:10:53 +0000 (18:10 +0300)]
Removed outdated debug.

6 years agoFixed a typo.
Vladimir Homutov [Thu, 14 May 2020 14:22:29 +0000 (17:22 +0300)]
Fixed a typo.

6 years agoREADME: Retry support, protocol error messages implemented.
Sergey Kandaurov [Thu, 14 May 2020 13:33:46 +0000 (16:33 +0300)]
README: Retry support, protocol error messages implemented.

6 years agoFixed time comparison.
Vladimir Homutov [Tue, 12 May 2020 15:45:44 +0000 (18:45 +0300)]
Fixed time comparison.

6 years agoAdded tests for connection id lengths in initial packet.
Vladimir Homutov [Thu, 14 May 2020 11:49:28 +0000 (14:49 +0300)]
Added tests for connection id lengths in initial packet.

6 years agoDiscard packets without fixed bit or reserved bits set.
Vladimir Homutov [Wed, 13 May 2020 22:06:45 +0000 (01:06 +0300)]
Discard packets without fixed bit or reserved bits set.

Section 17.2 and 17.3 of QUIC transport:

Fixed bit: Packets containing a zero value for this bit are not
valid packets in this version and MUST be discarded.

Reserved bit: An endpoint MUST treat receipt of a packet that has
a non-zero value for these bits, after removing both packet and
header protection, as a connection error of type PROTOCOL_VIOLATION.

6 years agoAdded generation of CC frames with error on connection termination.
Vladimir Homutov [Thu, 14 May 2020 12:54:45 +0000 (15:54 +0300)]
Added generation of CC frames with error on connection termination.

When an error occurs, then c->quic->error field may be populated
with an appropriate error code, and the CONNECTION CLOSE frame will be
sent to the peer before the connection is closed.  Otherwise, the error
treated as internal and INTERNAL_ERROR code is sent.

The pkt->error field is populated by functions processing packets to
indicate an error when it does not fit into pass/fail return status.

6 years agoAddress validation using NEW_TOKEN frame.
Sergey Kandaurov [Thu, 14 May 2020 12:47:24 +0000 (15:47 +0300)]
Address validation using NEW_TOKEN frame.

6 years agoAddress validation using Retry packets.
Sergey Kandaurov [Thu, 14 May 2020 12:47:18 +0000 (15:47 +0300)]
Address validation using Retry packets.

The behaviour is toggled with the new directive "quic_retry on|off".
QUIC token construction is made suitable for issuing with NEW_TOKEN.

6 years agoServer CID change refactored.
Sergey Kandaurov [Wed, 13 May 2020 15:34:34 +0000 (18:34 +0300)]
Server CID change refactored.

6 years agoPreserve original DCID and unbreak parsing 0-RTT packets.
Sergey Kandaurov [Tue, 12 May 2020 15:18:58 +0000 (18:18 +0300)]
Preserve original DCID and unbreak parsing 0-RTT packets.

As per QUIC transport, the first flight of 0-RTT packets obviously uses same
Destination and Source Connection ID values as the client's first Initial.

The fix is to match 0-RTT against original DCID after it has been switched.

6 years agoRemoved redundant long packet type checks.
Sergey Kandaurov [Sat, 9 May 2020 14:41:07 +0000 (17:41 +0300)]
Removed redundant long packet type checks.

6 years agoRemoved redundant SSL_do_handshake call before any handshake data.
Sergey Kandaurov [Sat, 9 May 2020 14:39:47 +0000 (17:39 +0300)]
Removed redundant SSL_do_handshake call before any handshake data.

6 years agoCleaned up reordering code.
Vladimir Homutov [Fri, 8 May 2020 10:08:04 +0000 (13:08 +0300)]
Cleaned up reordering code.

The ordered frame handler is always called for the existing stream, as it is
allocated from this stream.  Instead of searching stream by id, pointer to the
stream node is passed.

6 years agoCleaned up firefox workaround.
Vladimir Homutov [Thu, 7 May 2020 09:34:04 +0000 (12:34 +0300)]
Cleaned up firefox workaround.

The idea is to skip any zeroes that follow valid QUIC packet.  Currently such
behavior can be only observed with Firefox which sends zero-padded initial
packets.

6 years agoOCSP stapling: moved response verification to a separate function.
Roman Arutyunyan [Wed, 6 May 2020 18:44:14 +0000 (21:44 +0300)]
OCSP stapling: moved response verification to a separate function.

6 years agoUpstream: jump out of loop after matching the status code.
Jinhua Tan [Wed, 13 May 2020 14:02:47 +0000 (22:02 +0800)]
Upstream: jump out of loop after matching the status code.

6 years agoVariables: fixed buffer over-read when evaluating "$arg_".
Sergey Kandaurov [Fri, 8 May 2020 16:19:16 +0000 (19:19 +0300)]
Variables: fixed buffer over-read when evaluating "$arg_".

6 years agoRestored ngx_quic_encrypt return type.
Sergey Kandaurov [Wed, 6 May 2020 11:34:44 +0000 (14:34 +0300)]
Restored ngx_quic_encrypt return type.

It was inadvertently changed while working on removing memory allocations.

6 years agoStore clearflags in pkt->flags after decryption.
Vladimir Homutov [Thu, 30 Apr 2020 09:22:35 +0000 (12:22 +0300)]
Store clearflags in pkt->flags after decryption.

It doesn't make sense to store protected flags.

6 years agoConfigure: fixed static compilation with OpenSSL 1.1.1 / BoringSSL.
Sergey Kandaurov [Fri, 1 May 2020 10:02:30 +0000 (13:02 +0300)]
Configure: fixed static compilation with OpenSSL 1.1.1 / BoringSSL.

See 7246:04ebf29eaf5b for details.

6 years agoMention quic branch in README.
Sergey Kandaurov [Thu, 30 Apr 2020 12:59:14 +0000 (15:59 +0300)]
Mention quic branch in README.

6 years agoConfigure: unbreak with old OpenSSL, --with-http_v3_module added.
Sergey Kandaurov [Thu, 30 Apr 2020 12:47:43 +0000 (15:47 +0300)]
Configure: unbreak with old OpenSSL, --with-http_v3_module added.

6 years agoRemoved outdated/incorrect comments and fixed style.
Vladimir Homutov [Wed, 29 Apr 2020 11:45:55 +0000 (14:45 +0300)]
Removed outdated/incorrect comments and fixed style.

 - we need transport parameters early to get packet size limits at least.

6 years agoReworked macros for parsing/assembling packet types.
Vladimir Homutov [Thu, 30 Apr 2020 09:38:38 +0000 (12:38 +0300)]
Reworked macros for parsing/assembling packet types.

Previously, macros checking a packet type with the long header also checked
whether this is a long header.  Now it requires a separate preceding check.

6 years agoRenamed retransmit event object in preparation for retry support.
Sergey Kandaurov [Wed, 29 Apr 2020 11:59:21 +0000 (14:59 +0300)]
Renamed retransmit event object in preparation for retry support.

6 years agoServer CID change.
Sergey Kandaurov [Tue, 28 Apr 2020 15:24:01 +0000 (18:24 +0300)]
Server CID change.

6 years agoFactored out sending ACK from payload handler.
Sergey Kandaurov [Tue, 28 Apr 2020 15:23:56 +0000 (18:23 +0300)]
Factored out sending ACK from payload handler.

Now there's no need to annotate every frame in ACK-eliciting packet.
Sending ACK was moved to the first place, so that queueing ACK frame
no longer postponed up to the next packet after pushing STREAM frames.

6 years agoAdded README.
Vladimir Homutov [Tue, 28 Apr 2020 15:16:13 +0000 (18:16 +0300)]
Added README.

6 years agoRespect MAX_DATA and MAX_STREAM_DATA from QUIC client.
Roman Arutyunyan [Tue, 28 Apr 2020 13:37:32 +0000 (16:37 +0300)]
Respect MAX_DATA and MAX_STREAM_DATA from QUIC client.

6 years agoQUIC basic congestion control.
Roman Arutyunyan [Tue, 28 Apr 2020 13:42:43 +0000 (16:42 +0300)]
QUIC basic congestion control.

6 years agoFixed packet retransmission.
Roman Arutyunyan [Fri, 24 Apr 2020 14:20:37 +0000 (17:20 +0300)]
Fixed packet retransmission.

Previously frames in ctx->sent queue could be lost.

6 years agoAssign connection number to every QUIC stream log.
Roman Arutyunyan [Thu, 23 Apr 2020 15:05:05 +0000 (18:05 +0300)]
Assign connection number to every QUIC stream log.

6 years agoError messages cleanup.
Vladimir Homutov [Fri, 24 Apr 2020 11:38:49 +0000 (14:38 +0300)]
Error messages cleanup.

 + added "quic" prefix to all error messages
 + rephrased some messages
 + removed excessive error logging from frame parser
 + added ngx_quic_check_peer() function to check proper source/destination
   match and do it one place

6 years agoCleaned up hexdumps in debug output.
Vladimir Homutov [Fri, 24 Apr 2020 08:33:00 +0000 (11:33 +0300)]
Cleaned up hexdumps in debug output.

 - the ngx_quic_hexdump0() macro is renamed to ngx_quic_hexdump();
   the original ngx_quic_hexdump() macro with variable argument is
   removed, extra information is logged normally, with ngx_log_debug()

 - all labels in hex dumps are prefixed with "quic"

 - the hexdump format is simplified, length is moved forward to avoid
   situations when the dump is truncated, and length is not shown

 - ngx_quic_flush_flight() function contents is debug-only, placed under
   NGX_DEBUG macro to avoid "unused variable" warnings from compiler

 - frame names in labels are capitalized, similar to other places

6 years agoDebug cleanup.
Vladimir Homutov [Fri, 24 Apr 2020 07:11:47 +0000 (10:11 +0300)]
Debug cleanup.

 + all dumps are moved under one of the following macros (undefined by default):
    NGX_QUIC_DEBUG_PACKETS
    NGX_QUIC_DEBUG_FRAMES
    NGX_QUIC_DEBUG_FRAMES_ALLOC
    NGX_QUIC_DEBUG_CRYPTO

 + all QUIC debug messages got "quic " prefix

 + all input frames are reported as "quic frame in FOO_FRAME bar:1 baz:2"

 + all outgoing frames re reported as "quic frame out foo bar baz"

 + all stream operations are prefixed with id, like: "quic stream id 0x33 recv"

 + all transport parameters are prefixed with "quic tp"
   (hex dump is moved to caller, to avoid using ngx_cycle->log)

 + packet flags and some other debug messages are updated to
   include packet type

6 years agogRPC: WINDOW_UPDATE after END_STREAM handling (ticket #1797).
Ruslan Ermilov [Thu, 23 Apr 2020 12:10:26 +0000 (15:10 +0300)]
gRPC: WINDOW_UPDATE after END_STREAM handling (ticket #1797).

As per https://tools.ietf.org/html/rfc7540#section-6.9,
WINDOW_UPDATE received after a frame with the END_STREAM flag
should be handled and not treated as an error.

6 years agogRPC: RST_STREAM(NO_ERROR) handling (ticket #1792).
Ruslan Ermilov [Thu, 23 Apr 2020 12:10:24 +0000 (15:10 +0300)]
gRPC: RST_STREAM(NO_ERROR) handling (ticket #1792).

As per https://tools.ietf.org/html/rfc7540#section-8.1,

: A server can send a complete response prior to the client
: sending an entire request if the response does not depend on
: any portion of the request that has not been sent and
: received.  When this is true, a server MAY request that the
: client abort transmission of a request without error by
: sending a RST_STREAM with an error code of NO_ERROR after
: sending a complete response (i.e., a frame with the
: END_STREAM flag).  Clients MUST NOT discard responses as a
: result of receiving such a RST_STREAM, though clients can
: always discard responses at their discretion for other
: reasons.

Previously, RST_STREAM(NO_ERROR) received from upstream after
a frame with the END_STREAM flag was incorrectly treated as an
error.  Now, a single RST_STREAM(NO_ERROR) is properly handled.

This fixes problems observed with modern grpc-c [1], as well
as with the Go gRPC module.

[1] https://github.com/grpc/grpc/pull/1661

6 years agoVersion bump.
Ruslan Ermilov [Thu, 23 Apr 2020 12:10:21 +0000 (15:10 +0300)]
Version bump.

6 years agoTODOs cleanup in transport.
Vladimir Homutov [Thu, 23 Apr 2020 09:25:00 +0000 (12:25 +0300)]
TODOs cleanup in transport.

We always generate stream frames that have length. The 'len' member is used
during parsing incoming frames and can be safely ignored when generating
output.

6 years agoRetired the ngx_quic_parse_int_multi() function.
Vladimir Homutov [Thu, 23 Apr 2020 09:10:56 +0000 (12:10 +0300)]
Retired the ngx_quic_parse_int_multi() function.

It used variable-length arguments what is not really necessary.

6 years agoRemoved support of drafts older than currently latest 27.
Vladimir Homutov [Thu, 23 Apr 2020 08:50:20 +0000 (11:50 +0300)]
Removed support of drafts older than currently latest 27.

6 years agoAdded proper handling of connection close phases.
Vladimir Homutov [Thu, 23 Apr 2020 10:41:08 +0000 (13:41 +0300)]
Added proper handling of connection close phases.

There are following flags in quic connection:

closing  - true, when a connection close is initiated, for whatever reason
draining - true, when a CC frame is received from peer

The following state machine is used for closing:

 +------------------+
 |       I/HS/AD    |
 +------------------+
 |        |       |
 |        |       V
 |        |   immediate close initiated:
 |        |     reasons: close by top-level protocol, fatal error
 |        |     + sends CC (probably with app-level message)
 |        |     + starts close_timer: 3 * PTO (current probe timeout)
 |        |       |
 |        |       V
 |        |   +---------+  - Reply to input with CC (rate-limited)
 |        |   | CLOSING |  - Close/Reset all streams
 |        |   +---------+
 |        |       |    |
 |        V       V    |
 |       receives CC   |
 |          |          |
idle        |          |
timer       |          |
 |          V          |
 |      +----------+   |  - MUST NOT send anything (MAY send a single CC)
 |      | DRAINING |   |  - if not already started, starts close_timer: 3 * PTO
 |      +----------+   |  - if not already done, close all streams
 |          |          |
 |          |          |
 |       close_timer fires
 |          |
 V          V
 +------------------------+
 |       CLOSED           | - clean up all the resources, drop connection
 +------------------------+   state completely

The ngx_quic_close_connection() function gets an "rc" argument, that signals
reason of connection closing:
    NGX_OK    - initiated by application (i.e. http/3), follow state machine
    NGX_DONE  - timedout (while idle or draining)
    NGX_ERROR - fatal error, destroy connection immediately

The PTO calculations are not yet implemented, hardcoded value of 5s is used.