]> git.kaiwu.me - nginx.git/log
nginx.git
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.

6 years agoRefactored ngx_quic_close_connection().
Vladimir Homutov [Thu, 23 Apr 2020 08:15:44 +0000 (11:15 +0300)]
Refactored ngx_quic_close_connection().

The function is split into three:
    ngx_quic_close_connection() itself cleans up all core nginx things
    ngx_quic_close_quic()  deals with everything inside c->quic
    ngx_quic_close_streams() deals with streams cleanup

The quic and streams cleanup functions may return NGX_AGAIN, thus signalling
that cleanup is not ready yet, and the close cannot continue to next step.

6 years agoHTTP/3: directives with limited values converted to post handler.
Sergey Kandaurov [Wed, 22 Apr 2020 12:59:19 +0000 (15:59 +0300)]
HTTP/3: directives with limited values converted to post handler.

The purpose is to show a precise line number with an invalid value.

6 years agoHTTP/3: bytes holding directives changed to ngx_conf_set_size_slot.
Sergey Kandaurov [Wed, 22 Apr 2020 12:48:39 +0000 (15:48 +0300)]
HTTP/3: bytes holding directives changed to ngx_conf_set_size_slot.

This allows to specify directive values with measurement units.

6 years agoImproved ngx_quic_build_int() code and readability.
Sergey Kandaurov [Wed, 22 Apr 2020 11:52:16 +0000 (14:52 +0300)]
Improved ngx_quic_build_int() code and readability.

The function now generates somewhat shorter assembler after inlining.

6 years agoFixed QUIC buffer consumption in send_chain().
Roman Arutyunyan [Tue, 21 Apr 2020 14:52:32 +0000 (17:52 +0300)]
Fixed QUIC buffer consumption in send_chain().

6 years agoHTTP/3: fixed encoding variable-length integers.
Roman Arutyunyan [Tue, 21 Apr 2020 14:11:49 +0000 (17:11 +0300)]
HTTP/3: fixed encoding variable-length integers.

6 years agoFixed memory leak with reordered stream frames.
Vladimir Homutov [Mon, 20 Apr 2020 15:32:46 +0000 (18:32 +0300)]
Fixed memory leak with reordered stream frames.

6 years agoFixed includes in quic headers.
Roman Arutyunyan [Tue, 21 Apr 2020 09:06:24 +0000 (12:06 +0300)]
Fixed includes in quic headers.

6 years agoAdded MAX_STREAM_DATA stub handler.
Vladimir Homutov [Mon, 20 Apr 2020 14:18:04 +0000 (17:18 +0300)]
Added MAX_STREAM_DATA stub handler.

Currently sending code is ignoring this.

6 years agoRespecting maximum packet size.
Vladimir Homutov [Mon, 20 Apr 2020 19:25:22 +0000 (22:25 +0300)]
Respecting maximum packet size.

The header size macros for long and short packets were fixed to provide
correct values in bytes.

Currently the sending code limits frames so they don't exceed max_packet_size.
But it does not account the case when a single frame can exceed the limit.

As a result of this patch, big payload (CRYPTO and STREAM) will be split
into a number of smaller frames that fit into advertised max_packet_size
(which specifies final packet size, after encryption).

6 years agoRemoved source/destination swap from the function creating header.
Vladimir Homutov [Mon, 20 Apr 2020 09:12:17 +0000 (12:12 +0300)]
Removed source/destination swap from the function creating header.

The function now creates a header according to fileds provided in the "pkt"
argument without applying any logic regarding sending side.

6 years agoRevert "Rejecting new connections with non-zero Initial packet."
Sergey Kandaurov [Fri, 17 Apr 2020 09:01:45 +0000 (12:01 +0300)]
Revert "Rejecting new connections with non-zero Initial packet."

chrome-unstable 83.0.4103.7 starts with Initial packet number 1.

I couldn't find a proper explanation besides this text in quic-transport:
    An endpoint MAY skip packet numbers when sending
    packets to detect this (Optimistic ACK Attack) behavior.

6 years agoFixed error descriptions.
Vladimir Homutov [Thu, 16 Apr 2020 13:54:22 +0000 (16:54 +0300)]
Fixed error descriptions.

The check for array bound is done inside function that returns error
description.  Missing initialization element is added.

6 years agoRemoved outdated TODO.
Vladimir Homutov [Thu, 16 Apr 2020 10:28:43 +0000 (13:28 +0300)]
Removed outdated TODO.

If required, frame handler can invoke output itself.  There is no need to
call output directly in the payload handler, queuing is enough.

6 years agoAdded handling of incorrect values in TP configuration.
Vladimir Homutov [Thu, 16 Apr 2020 09:17:41 +0000 (12:17 +0300)]
Added handling of incorrect values in TP configuration.

Some parameters have minimal/maximum values defined by standard.

6 years agoParsing of truncated packet numbers.
Sergey Kandaurov [Thu, 16 Apr 2020 09:46:48 +0000 (12:46 +0300)]
Parsing of truncated packet numbers.

For sample decoding algorithm, see quic-transport-27#appendix-A.

6 years agoAdded primitive flow control mechanisms.
Vladimir Homutov [Wed, 15 Apr 2020 15:54:03 +0000 (18:54 +0300)]
Added primitive flow control mechanisms.

 + MAX_STREAM_DATA frame is sent when recv() is performed on stream
   The new value is a sum of total bytes received by stream + free
   space in a buffer;

   The sending of MAX_STREM_DATA frame in response to STREAM_DATA_BLOCKED
   frame is adjusted to follow the same logic as above.

 + MAX_DATA frame is sent when total amount of received data is 2x
   of current limit.  The limit is doubled.

 + Default values of transport parameters are adjusted to more meaningful
   values:

   initial stream limits are set to quic buffer size instead of
   unrealistically small 255.

   initial max data is decreased to 16 buffer sizes, in an assumption that
   this is enough for a relatively short connection, instead of randomly
   chosen big number.

All this allows to initiate a stable flow of streams that does not block
on stream/connection limits (tested with FF 77.0a1 and 100K requests)

6 years agoCreate new stream immediately on receiving new stream id.
Vladimir Homutov [Wed, 15 Apr 2020 11:29:00 +0000 (14:29 +0300)]
Create new stream immediately on receiving new stream id.

Before the patch, full STREAM frame handling was delayed until the frame with
zero offset is received.  Only node in the streams tree was created.

This lead to problems when such stream was deleted, in particular, it had no
handlers set for read events.

This patch creates new stream immediately, but delays data delivery until
the proper offset will arrive. This is somewhat similar to how accept()
operation works.

The ngx_quic_add_stream() function is no longer needed and merged into stream
handler.  The ngx_quic_stream_input() now only handles frames for existing
streams and does not deal with stream creation.

6 years agoFree remaining frames on connection close.
Vladimir Homutov [Wed, 15 Apr 2020 10:09:39 +0000 (13:09 +0300)]
Free remaining frames on connection close.

Frames can still float in the following queues:

 - crypto frames reordering queues (one per encryption level)
 - moved crypto frames cleanup to the moment where all streams are closed
 - stream frames reordering queues (one per packet number namespace)
 - frames retransmit queues (one per packet number namespace)

6 years agorelease-1.17.10 tag
Maxim Dounin [Tue, 14 Apr 2020 14:19:26 +0000 (17:19 +0300)]
release-1.17.10 tag

6 years agonginx-1.17.10-RELEASE release-1.17.10
Maxim Dounin [Tue, 14 Apr 2020 14:19:26 +0000 (17:19 +0300)]
nginx-1.17.10-RELEASE

6 years agoSorted functions and functions declarations.
Vladimir Homutov [Tue, 14 Apr 2020 13:30:41 +0000 (16:30 +0300)]
Sorted functions and functions declarations.

6 years agoAdded reordering support for STREAM frames.
Vladimir Homutov [Wed, 15 Apr 2020 08:11:54 +0000 (11:11 +0300)]
Added reordering support for STREAM frames.

Each stream node now includes incoming frames queue and sent/received counters
for tracking offset. The sent counter is not used, c->sent is used, not like
in crypto buffers, which have no connections.

6 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 14 Apr 2020 12:15:16 +0000 (15:15 +0300)]
Updated OpenSSL used for win32 builds.

6 years agoCrypto buffer frames reordering.
Vladimir Homutov [Tue, 14 Apr 2020 09:16:25 +0000 (12:16 +0300)]
Crypto buffer frames reordering.

If offset in CRYPTO frame doesn't match expected, following actions are taken:
    a) Duplicate frames or frames within [0...current offset] are ignored
    b) New data from intersecting ranges (starts before current_offset, ends
       after) is consumed
    c) "Future" frames are stored in a sorted queue (min offset .. max offset)

Once a frame is consumed, current offset is updated and the queue is inspected:
    we iterate the queue until the gap is found and act as described
    above for each frame.

The amount of data in buffered frames is limited by corresponding macro.

The CRYPTO and STREAM frame structures are now compatible: they share
the same set of initial fields.  This allows to have code that deals with
both of this frames.

The ordering layer now processes the frame with offset and invokes the
handler when it can organise an ordered stream of data.

6 years agoCleaned up magic numbers in ngx_quic_output_frames().
Vladimir Homutov [Mon, 13 Apr 2020 11:57:58 +0000 (14:57 +0300)]
Cleaned up magic numbers in ngx_quic_output_frames().

6 years agoRename types and variables used for packet number space.
Vladimir Homutov [Tue, 14 Apr 2020 09:06:32 +0000 (12:06 +0300)]
Rename types and variables used for packet number space.

Quote: Conceptually, a packet number space is the context in which a packet
       can be processed and acknowledged.

ngx_quic_namespace_t => ngx_quic_send_ctx_t
qc->ns               => qc->send_ctx
ns->largest          => send_ctx->largest_ack

The ngx_quic_ns(level) macro now returns pointer, not just index:
    ngx_quic_get_send_ctx(c->quic, level)

ngx_quic_retransmit_ns() => ngx_quic_retransmit()
ngx_quic_output_ns() => ngx_quic_output_frames()

6 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 14 Apr 2020 16:35:20 +0000 (19:35 +0300)]
Merged with the default branch.

6 years agoHTTP/3: fixed reading request body.
Roman Arutyunyan [Mon, 13 Apr 2020 14:54:23 +0000 (17:54 +0300)]
HTTP/3: fixed reading request body.

6 years agoThe new auth_delay directive for delaying unauthorized requests.
Ruslan Ermilov [Tue, 7 Apr 2020 22:02:17 +0000 (01:02 +0300)]
The new auth_delay directive for delaying unauthorized requests.

The request processing is delayed by a timer.  Since nginx updates
internal time once at the start of each event loop iteration, this
normally ensures constant time delay, adding a mitigation from
time-based attacks.

A notable exception to this is the case when there are no additional
events before the timer expires.  To ensure constant-time processing
in this case as well, we trigger an additional event loop iteration
by posting a dummy event for the next event loop iteration.

6 years agoAdded basic offset support in client CRYPTO frames.
Vladimir Homutov [Tue, 7 Apr 2020 12:50:38 +0000 (15:50 +0300)]
Added basic offset support in client CRYPTO frames.

The offset in client CRYPTO frames is tracked in c->quic->crypto_offset_in.
This means that CRYPTO frames with non-zero offset are now accepted making
possible to finish handshake with client certificates that exceed max packet
size (if no reordering happens).

The c->quic->crypto_offset field is renamed to crypto_offset_out to avoid
confusion with tracking of incoming CRYPTO stream.

6 years agoFixed build with OpenSSL using old callbacks API.
Sergey Kandaurov [Tue, 7 Apr 2020 09:54:34 +0000 (12:54 +0300)]
Fixed build with OpenSSL using old callbacks API.

6 years agoACK ranges processing.
Vladimir Homutov [Mon, 6 Apr 2020 13:19:26 +0000 (16:19 +0300)]
ACK ranges processing.

 + since number of ranges in unknown, provide a function to parse them once
   again in handler to avoid memory allocation

 + ack handler now processes all ranges, not only the first

 + ECN counters are parsed and saved into frame if present

6 years agoIgnore non-yet-implemented frames.
Vladimir Homutov [Mon, 6 Apr 2020 08:16:45 +0000 (11:16 +0300)]
Ignore non-yet-implemented frames.

Such frames are grouped together in a switch and just ignored, instead of
closing the connection  This may improve test coverage.  All such frames
require acknowledgment.

6 years agoAdded check for SSL_get_current_cipher() results.
Vladimir Homutov [Sat, 4 Apr 2020 19:25:41 +0000 (22:25 +0300)]
Added check for SSL_get_current_cipher() results.

The function may return NULL and result need to be checked before use.

6 years agoAdded a bit more debugging in STREAM frame parser.
Vladimir Homutov [Mon, 6 Apr 2020 08:17:14 +0000 (11:17 +0300)]
Added a bit more debugging in STREAM frame parser.

6 years agoDo not set timers after the connection is closed.
Vladimir Homutov [Sat, 4 Apr 2020 19:27:29 +0000 (22:27 +0300)]
Do not set timers after the connection is closed.

The qc->closing flag is set when a connection close is initiated for the first
time.

No timers will be set if the flag is active.

TODO: this is a temporary solution to avoid running timer handlers after
connection (and it's pool) was destroyed.  It looks like currently we have
no clear policy of connection closing in regard to timers.

6 years agoDiscarding Handshake packets if no Handshake keys yet.
Sergey Kandaurov [Mon, 6 Apr 2020 11:54:10 +0000 (14:54 +0300)]
Discarding Handshake packets if no Handshake keys yet.

Found with a previously received Initial packet with ACK only, which
instantiates a new connection but do not produce the handshake keys.

This can be triggered by a fairly well behaving client, if the server
stands behind a load balancer that stripped Initial packets exchange.

Found by F5 test suite.

6 years agoRejecting new connections with non-zero Initial packet.
Sergey Kandaurov [Mon, 6 Apr 2020 11:54:10 +0000 (14:54 +0300)]
Rejecting new connections with non-zero Initial packet.

6 years agoTLS Key Update in QUIC.
Sergey Kandaurov [Mon, 6 Apr 2020 11:54:08 +0000 (14:54 +0300)]
TLS Key Update in QUIC.

Old keys retention is yet to be implemented.

6 years agoRemoved excessive debugging in QUIC packet creation.
Sergey Kandaurov [Sat, 4 Apr 2020 14:34:39 +0000 (17:34 +0300)]
Removed excessive debugging in QUIC packet creation.

While here, eliminated further difference in between.

6 years agoLogging of packet numbers in QUIC packet creation.
Sergey Kandaurov [Sat, 4 Apr 2020 14:34:04 +0000 (17:34 +0300)]
Logging of packet numbers in QUIC packet creation.

6 years agoRemoved unneccesary milliseconds conversion.
Vladimir Homutov [Fri, 3 Apr 2020 13:33:59 +0000 (16:33 +0300)]
Removed unneccesary milliseconds conversion.