]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: use server ack_delay_exponent when sending ack.
Roman Arutyunyan [Thu, 4 Feb 2021 11:35:36 +0000 (14:35 +0300)]
QUIC: use server ack_delay_exponent when sending ack.

Previously, client one was used.

5 years agoQUIC: removed redundant "app" flag from ngx_quic_close_frame_t.
Sergey Kandaurov [Wed, 3 Feb 2021 09:39:41 +0000 (12:39 +0300)]
QUIC: removed redundant "app" flag from ngx_quic_close_frame_t.

The flag was introduced to create type-aware CONNECTION_CLOSE frames,
and now is replaced with frame type information, directly accessible.
Notably, this fixes type logging for received frames in b3d9e57d0f62.

5 years agoHTTP/3: reverted version check for keepalive flag.
Roman Arutyunyan [Tue, 2 Feb 2021 12:09:48 +0000 (15:09 +0300)]
HTTP/3: reverted version check for keepalive flag.

The flag is used in ngx_http_finalize_connection() to switch client connection
to the keepalive mode.  Since eaea7dac3292 this code is not executed for HTTP/3
which allows us to revert the change and get back to the default branch code.

5 years agoHTTP/3: fixed format specifier.
Roman Arutyunyan [Mon, 1 Feb 2021 15:48:18 +0000 (18:48 +0300)]
HTTP/3: fixed format specifier.

5 years agoHTTP/2: lingering close changed to handle NGX_AGAIN.
Ruslan Ermilov [Mon, 1 Feb 2021 13:42:50 +0000 (16:42 +0300)]
HTTP/2: lingering close changed to handle NGX_AGAIN.

This part somehow slipped away from c5840ca2063d.

While it is not expected to be needed in case of lingering close,
it is good to keep it for correctness (see 2b5528023f6b).

5 years agoClean up trailers in ngx_http_clean_header() as well.
Sergey Kandaurov [Tue, 26 Jan 2021 09:39:28 +0000 (12:39 +0300)]
Clean up trailers in ngx_http_clean_header() as well.

The function has not been updated with introduction of trailers support
in 7034:1b068a4e82d8 (1.13.2).

5 years agoHTTP/3: refactored request body parser.
Roman Arutyunyan [Mon, 25 Jan 2021 13:16:47 +0000 (16:16 +0300)]
HTTP/3: refactored request body parser.

The change reduces diff to the default branch for
src/http/ngx_http_request_body.c.

Also, client Content-Length, if present, is now checked against the real body
size sent by client.

5 years agoQUIC: fixed stateless reset recognition and send.
Roman Arutyunyan [Mon, 1 Feb 2021 11:46:36 +0000 (14:46 +0300)]
QUIC: fixed stateless reset recognition and send.

Previously, if an unexpected packet was received on an existing QUIC
connection, stateless reset token was neither recognized nor sent.

5 years agoQUIC: refactored packet processing.
Roman Arutyunyan [Thu, 28 Jan 2021 09:35:18 +0000 (12:35 +0300)]
QUIC: refactored packet processing.

- split ngx_quic_process_packet() in two functions with the second one called
  ngx_quic_process_payload() in charge of decrypring and handling the payload
- renamed ngx_quic_payload_handler() to ngx_quic_handle_frames()
- moved error cleanup from ngx_quic_input() to ngx_quic_process_payload()
- moved handling closed connection from ngx_quic_handle_frames() to
  ngx_quic_process_payload()
- minor fixes

5 years agoQUIC: stateless retry.
Vladimir Homutov [Fri, 29 Jan 2021 12:53:47 +0000 (15:53 +0300)]
QUIC: stateless retry.

Previously, quic connection object was created when Retry packet was sent.
This is neither necessary nor convenient, and contradicts the idea of retry:
protecting from bad clients and saving server resources.

Now, the connection is not created, token is verified cryptographically
instead of holding it in connection.

5 years agoHTTP/3: call ngx_handle_read_event() from client header handler.
Roman Arutyunyan [Fri, 29 Jan 2021 16:42:47 +0000 (19:42 +0300)]
HTTP/3: call ngx_handle_read_event() from client header handler.

This function should be called at the end of an event handler to prepare the
event for the next handler call.  Particularly, the "active" flag is set or
cleared depending on data availability.

With this call missing in one code path, read handler was not called again
after handling the initial part of the client request, if the request was too
big to fit into a single STREAM frame.

Now ngx_handle_read_event() is called in this code path.  Also, read timer is
restarted.

5 years agoREADME: reflect renaming of several transport parameter directives.
Sergey Kandaurov [Wed, 27 Jan 2021 10:09:45 +0000 (13:09 +0300)]
README: reflect renaming of several transport parameter directives.

Reported by Kyriakos Zarifis.

5 years agoYear 2021.
Maxim Dounin [Tue, 19 Jan 2021 17:35:17 +0000 (20:35 +0300)]
Year 2021.

5 years agoCore: removed post_accept_timeout.
Maxim Dounin [Tue, 19 Jan 2021 17:32:00 +0000 (20:32 +0300)]
Core: removed post_accept_timeout.

Keeping post_accept_timeout in ngx_listening_t is no longer needed since
we've switched to 1 second timeout for deferred accept in 5541:fdb67cfc957d.

Further, using it in HTTP code can result in client_header_timeout being
used from an incorrect server block, notably if address-specific virtual
servers are used along with a wildcard listening socket, or if we've switched
to a different server block based on SNI in SSL handshake.

5 years agoRemoved incorrect optimization of HEAD requests.
Maxim Dounin [Tue, 19 Jan 2021 17:21:12 +0000 (20:21 +0300)]
Removed incorrect optimization of HEAD requests.

The stub status module and ngx_http_send_response() (used by the empty gif
module and the "return" directive) incorrectly assumed that responding
to HEAD requests always results in r->header_only being set.  This is not
true, and results in incorrect behaviour, for example, in the following
configuration:

   location / {
       image_filter size;
       return 200 test;
   }

Fix is to remove this incorrect micro-optimization from both stub status
module and ngx_http_send_response().

Reported by Chris Newton.

5 years agoUpstream: fixed zero size buf alerts on extra data (ticket #2117).
Maxim Dounin [Tue, 12 Jan 2021 13:59:31 +0000 (16:59 +0300)]
Upstream: fixed zero size buf alerts on extra data (ticket #2117).

After 7675:9afa45068b8f and 7678:bffcc5af1d72 (1.19.1), during non-buffered
simple proxying, responses with extra data might result in zero size buffers
being generated and "zero size buf" alerts in writer.  This bug is similar
to the one with FastCGI proxying fixed in 7689:da8d758aabeb.

In non-buffered mode, normally the filter function is not called if
u->length is already 0, since u->length is checked after each call of
the filter function.  There is a case when this can happen though: if
the response length is 0, and there are pre-read response body data left
after reading response headers.  As such, a check for u->length is needed
at the start of non-buffered filter functions, similar to the one
for p->length present in buffered filter functions.

Appropriate checks added to the existing non-buffered copy filters
in the upstream (used by scgi and uwsgi proxying) and proxy modules.

5 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Tue, 29 Dec 2020 11:13:57 +0000 (13:13 +0200)]
Contrib: vim syntax, update core and 3rd party module directives.

5 years agoVersion bump.
Maxim Dounin [Mon, 11 Jan 2021 19:06:27 +0000 (22:06 +0300)]
Version bump.

5 years agoHTTP/3: removed HTTP/3-specific code.
Roman Arutyunyan [Mon, 21 Dec 2020 17:35:13 +0000 (17:35 +0000)]
HTTP/3: removed HTTP/3-specific code.

The ngx_http_set_lingering_close() function is not called for HTTP/3.

The change reduces diff to the default branch.

5 years agoHTTP/3: client header validation.
Roman Arutyunyan [Mon, 18 Jan 2021 10:43:36 +0000 (13:43 +0300)]
HTTP/3: client header validation.

A header with the name containing null, CR, LF, colon or uppercase characters,
is now considered an error.  A header with the value containing null, CR or LF,
is also considered an error.

Also, header is considered invalid unless its name only contains lowercase
characters, digits, minus and optionally underscore.  Such header can be
optionally ignored.

5 years agoHTTP/3: added comment.
Roman Arutyunyan [Tue, 12 Jan 2021 21:08:55 +0000 (21:08 +0000)]
HTTP/3: added comment.

5 years agoHTTP/3: client pseudo-headers restrictions.
Roman Arutyunyan [Fri, 22 Jan 2021 12:57:41 +0000 (15:57 +0300)]
HTTP/3: client pseudo-headers restrictions.

- :method, :path and :scheme are expected exactly once and not empty
- :method and :scheme character validation is added
- :authority cannot appear more than once

5 years agoHTTP/3: refactored request parser.
Roman Arutyunyan [Fri, 22 Jan 2021 13:34:06 +0000 (16:34 +0300)]
HTTP/3: refactored request parser.

The change reduces diff to the default branch for
src/http/ngx_http_request.c and src/http/ngx_http_parse.c.

5 years agoQUIC: draft-33 salt and retry keys.
Sergey Kandaurov [Mon, 11 Jan 2021 12:25:48 +0000 (15:25 +0300)]
QUIC: draft-33 salt and retry keys.

Notably, the version negotiation table is updated to reject draft-33/QUICv1
(which requires a new TLS codepoint) unless explicitly asked to built with.

5 years agoQUIC: fixed header protection macro name.
Vladimir Homutov [Wed, 30 Dec 2020 17:47:35 +0000 (20:47 +0300)]
QUIC: fixed header protection macro name.

5 years agoQUIC: ngx_quic_bpf module.
Vladimir Homutov [Fri, 25 Dec 2020 12:01:15 +0000 (15:01 +0300)]
QUIC: ngx_quic_bpf module.

The quic kernel bpf helper inspects packet payload for DCID, extracts key
and routes the packet into socket matching the key.

Due to reuseport feature, each worker owns a personal socket, which is
identified by the same key, used to create DCID.

BPF objects are locked in RAM and are subject to RLIMIT_MEMLOCK.
The "ulimit -l" command may be used to setup proper limits, if maps
cannot be created with EPERM or updated with ETOOLONG.

5 years agorelease-1.19.6 tag
Maxim Dounin [Tue, 15 Dec 2020 14:41:39 +0000 (17:41 +0300)]
release-1.19.6 tag

5 years agonginx-1.19.6-RELEASE release-1.19.6
Maxim Dounin [Tue, 15 Dec 2020 14:41:39 +0000 (17:41 +0300)]
nginx-1.19.6-RELEASE

5 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 15 Dec 2020 13:49:24 +0000 (16:49 +0300)]
Updated OpenSSL used for win32 builds.

5 years agoCore: added interface to linux bpf() system call.
Vladimir Homutov [Tue, 15 Dec 2020 12:23:07 +0000 (15:23 +0300)]
Core: added interface to linux bpf() system call.

It contains wrappers for operations with BPF maps and for loading BPF programs.

5 years agoQUIC: ngx_quic_module.
Vladimir Homutov [Fri, 25 Dec 2020 11:18:51 +0000 (14:18 +0300)]
QUIC: ngx_quic_module.

5 years agoQUIC: moved all quic sources into src/event/quic.
Vladimir Homutov [Fri, 25 Dec 2020 11:01:28 +0000 (14:01 +0300)]
QUIC: moved all quic sources into src/event/quic.

5 years agoQUIC: removed unused <openssl/aes.h> inclusion.
Sergey Kandaurov [Tue, 22 Dec 2020 13:41:56 +0000 (16:41 +0300)]
QUIC: removed unused <openssl/aes.h> inclusion.

The low-level API was used in early QUIC development.

5 years agoQUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).
Sergey Kandaurov [Tue, 22 Dec 2020 09:04:16 +0000 (12:04 +0300)]
QUIC: fixed -Wtype-limits with GCC <= 5 (ticket #2104).

5 years agoQUIC: fixed logging PATH_CHALLENGE/RESPONSE and build with GCC < 5.
Sergey Kandaurov [Tue, 22 Dec 2020 09:04:15 +0000 (12:04 +0300)]
QUIC: fixed logging PATH_CHALLENGE/RESPONSE and build with GCC < 5.

5 years agoQUIC: fixed building ALPN callback without debug and http2.
Sergey Kandaurov [Tue, 22 Dec 2020 09:04:15 +0000 (12:04 +0300)]
QUIC: fixed building ALPN callback without debug and http2.

5 years agoQUIC: fixed build with OpenSSL < 1.1.1.
Sergey Kandaurov [Tue, 22 Dec 2020 09:03:43 +0000 (12:03 +0300)]
QUIC: fixed build with OpenSSL < 1.1.1.

The <openssl/kdf.h> header is available since OpenSSL 1.1.0, and HKDF API
used for separate Extract and Expand steps in TLSv1.3 - since OpenSSL 1.1.1.

5 years agoQUIC: converted to SSL_CIPHER_get_protocol_id().
Sergey Kandaurov [Mon, 21 Dec 2020 12:05:43 +0000 (15:05 +0300)]
QUIC: converted to SSL_CIPHER_get_protocol_id().

This API is available in BoringSSL for quite some time:
https://boringssl.googlesource.com/boringssl/+/3743aaf

5 years agoHTTP/3: staticize internal parsing functions.
Sergey Kandaurov [Wed, 16 Dec 2020 12:47:41 +0000 (12:47 +0000)]
HTTP/3: staticize internal parsing functions.

5 years agoHTTP/3: staticize ngx_http_v3_methods.
Sergey Kandaurov [Wed, 16 Dec 2020 12:47:38 +0000 (12:47 +0000)]
HTTP/3: staticize ngx_http_v3_methods.

5 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 15 Dec 2020 16:55:43 +0000 (16:55 +0000)]
Merged with the default branch.

5 years agoFixed double close of non-regular files in flv and mp4.
Maxim Dounin [Fri, 11 Dec 2020 10:42:07 +0000 (13:42 +0300)]
Fixed double close of non-regular files in flv and mp4.

With introduction of open_file_cache in 1454:f497ed7682a7, opening a file
with ngx_open_cached_file() automatically adds a cleanup handler to close
the file.  As such, calling ngx_close_file() directly for non-regular files
is no longer needed and will result in duplicate close() call.

In 1454:f497ed7682a7 ngx_close_file() call for non-regular files was removed
in the static module, but wasn't in the flv module.  And the resulting
incorrect code was later copied to the mp4 module.  Fix is to remove the
ngx_close_file() call from both modules.

Reported by Chris Newton.

5 years agoRemoved extra allocation for r->uri.
Maxim Dounin [Thu, 10 Dec 2020 17:09:39 +0000 (20:09 +0300)]
Removed extra allocation for r->uri.

The ngx_http_parse_complex_uri() function cannot make URI longer and does
not null-terminate URI, so there is no need to allocate an extra byte.  This
allocation appears to be a leftover from changes in 461:a88a3e4e158f (0.1.5),
where null-termination of r->uri and many other strings was removed.

5 years agoFixed parsing of absolute URIs with empty path (ticket #2079).
Maxim Dounin [Thu, 10 Dec 2020 17:09:30 +0000 (20:09 +0300)]
Fixed parsing of absolute URIs with empty path (ticket #2079).

When the request line contains request-target in the absolute-URI form,
it can contain path-empty instead of a single slash (see RFC 7230, RFC 3986).
Previously, the ngx_http_parse_request_line() function only accepted empty
path when there was no query string.

With this change, non-empty query is also correctly handled.  That is,
request line "GET http://example.com?foo HTTP/1.1" is accepted and results
in $uri "/" and $args "foo".

Note that $request_uri remains "?foo", similarly to how spaces in URIs
are handled.  Providing "/?foo", similarly to how "/" is provided for
"GET http://example.com HTTP/1.1", requires allocation.

5 years agoQUIC: always calculate rtt for largest acknowledged packet.
Roman Arutyunyan [Wed, 9 Dec 2020 21:26:21 +0000 (21:26 +0000)]
QUIC: always calculate rtt for largest acknowledged packet.

Previously, when processing client ACK, rtt could be calculated for a packet
different than the largest if it was missing in the sent chain.  Even though
this is an unlikely situation, rtt based on a different packet could be larger
than needed leading to bigger pto timeout and performance degradation.

5 years agoQUIC: send and process ack_delay for Initial and Handshake levels.
Roman Arutyunyan [Thu, 10 Dec 2020 14:54:53 +0000 (14:54 +0000)]
QUIC: send and process ack_delay for Initial and Handshake levels.

Previously, this only worked for Application level because before
quic-transport-30, there were the following constraints:

   Because the receiver doesn't use the ACK Delay for Initial and Handshake
   packets, a sender SHOULD send a value of 0.

   When adjusting an RTT sample using peer-reported acknowledgement delays, an
   endpoint ...  MUST ignore the ACK Delay field of the ACK frame for packets
   sent in the Initial and Handshake packet number space.

5 years agoQUIC: use client max_ack_delay when computing pto timeout.
Roman Arutyunyan [Wed, 9 Dec 2020 16:15:24 +0000 (16:15 +0000)]
QUIC: use client max_ack_delay when computing pto timeout.

Previously, server max_ack_delay was used which is wrong.

Also, level check is simplified.

5 years agoQUIC: resend handshake packets along with initial.
Roman Arutyunyan [Tue, 8 Dec 2020 17:10:22 +0000 (17:10 +0000)]
QUIC: resend handshake packets along with initial.

To speed up handshake, resend both initial and handshake packets if there's
at least one unacknowledged initial packet.

5 years agoQUIC: set the temporary flag for input frame buffers.
Roman Arutyunyan [Tue, 8 Dec 2020 14:44:41 +0000 (14:44 +0000)]
QUIC: set the temporary flag for input frame buffers.

Missing flag prevented frame data from being copied as the buffer was not
considered a memory buffer.

5 years agoSSL: fixed SSL shutdown on lingering close.
Ruslan Ermilov [Mon, 7 Dec 2020 22:43:36 +0000 (01:43 +0300)]
SSL: fixed SSL shutdown on lingering close.

Ensure c->recv is properly reset to ngx_recv if SSL_shutdown()
blocks on writing.

The bug had appeared in 554c6ae25ffc.

5 years agoQUIC: coalesce output packets into a single UDP datagram.
Roman Arutyunyan [Mon, 7 Dec 2020 15:09:08 +0000 (15:09 +0000)]
QUIC: coalesce output packets into a single UDP datagram.

Now initial output packet is not padded anymore if followed by a handshake
packet.  If the datagram is still not big enough to satisfy minimum size
requirements, handshake packet is padded.

5 years agoQUIC: introduced QUIC buffers.
Roman Arutyunyan [Tue, 1 Dec 2020 19:11:01 +0000 (19:11 +0000)]
QUIC: introduced QUIC buffers.

Buffers are used to hold frame data.  They have a fixed size and are reused
after being freed.

5 years agoQUIC: fixed handling of clients connected to wildcard address.
Vladimir Homutov [Mon, 7 Dec 2020 11:06:00 +0000 (14:06 +0300)]
QUIC: fixed handling of clients connected to wildcard address.

The patch replaces c->send() occurences with c->send_chain(), because the
latter accounts for the local address, which may be different if the wildcard
listener is used.

Previously, server sent response to client using address different from
one client connected to.

5 years agoQUIC: disabling bidirectional SSL shutdown earlier.
Sergey Kandaurov [Sun, 6 Dec 2020 14:24:38 +0000 (14:24 +0000)]
QUIC: disabling bidirectional SSL shutdown earlier.

Notably, this fixes an issue with Chrome that can emit a "certificate_unknown"
alert during the SSL handshake where c->ssl->no_wait_shutdown is not yet set.

5 years agoQUIC: fixed missing quic flag on listener in the stream module.
Vladimir Homutov [Fri, 4 Dec 2020 12:19:03 +0000 (15:19 +0300)]
QUIC: fixed missing quic flag on listener in the stream module.

5 years agoHTTP/3: introduced ngx_http_v3_filter.
Roman Arutyunyan [Fri, 27 Nov 2020 17:46:21 +0000 (17:46 +0000)]
HTTP/3: introduced ngx_http_v3_filter.

The filter is responsible for creating HTTP/3 response header and body.

The change removes differences to the default branch for
ngx_http_chunked_filter_module and ngx_http_header_filter_module.

5 years agoQUIC: fixed send contexts cleanup.
Vladimir Homutov [Wed, 2 Dec 2020 07:55:49 +0000 (10:55 +0300)]
QUIC: fixed send contexts cleanup.

The ngx_quic_get_send_ctx() macro takes 'level' argument, not send context
index.

5 years agoQUIC: removed ngx_quic_hexdump() macro.
Vladimir Homutov [Fri, 27 Nov 2020 15:43:36 +0000 (18:43 +0300)]
QUIC: removed ngx_quic_hexdump() macro.

Instead, appropriate format specifier for hexadecimal is used
in ngx_log_debug().

The STREAM frame "data" debug is moved into ngx_quic_log_frame(), similar
to all other frame fields debug.

5 years agoUpstream: excluded down servers from the next_upstream tries.
Ruslan Ermilov [Thu, 26 Nov 2020 21:01:20 +0000 (00:01 +0300)]
Upstream: excluded down servers from the next_upstream tries.

Previously, the number of next_upstream tries included servers marked
as "down", resulting in "no live upstreams" with the code 502 instead
of the code derived from an attempt to connect to the last tried "up"
server (ticket #2096).

5 years agoVersion bump.
Ruslan Ermilov [Thu, 26 Nov 2020 20:46:59 +0000 (23:46 +0300)]
Version bump.

5 years agoHTTP/3: eliminated r->method_start.
Roman Arutyunyan [Wed, 25 Nov 2020 17:57:43 +0000 (17:57 +0000)]
HTTP/3: eliminated r->method_start.

The field was introduced to ease parsing HTTP/3 requests.

The change reduces diff to the default branch.

5 years agorelease-1.19.5 tag
Maxim Dounin [Tue, 24 Nov 2020 15:06:34 +0000 (18:06 +0300)]
release-1.19.5 tag

5 years agonginx-1.19.5-RELEASE release-1.19.5
Maxim Dounin [Tue, 24 Nov 2020 15:06:34 +0000 (18:06 +0300)]
nginx-1.19.5-RELEASE

5 years agogRPC: RST_STREAM(NO_ERROR) handling after "trailer only" responses.
Pavel Pautov [Thu, 19 Nov 2020 02:41:16 +0000 (18:41 -0800)]
gRPC: RST_STREAM(NO_ERROR) handling after "trailer only" responses.

Similarly to the problem fixed in 2096b21fcd10 (ticket #1792),
when a "trailer only" gRPC response (that is, a response with the
END_STREAM flag in the HEADERS frame) was immediately followed by
RST_STREAM(NO_ERROR) in the data preread along with the response
header, RST_STREAM wasn't properly skipped and caused "upstream
rejected request with error 0" errors.
Observed with "unknown service" gRPC errors returned by grpc-go.

Fix is to set ctx->done if we are going to parse additional data,
so the RST_STREAM(NO_ERROR) is properly skipped.  Additionally, now
ngx_http_grpc_filter() will complain about frames sent for closed
stream if there are any.

5 years agoUse .Mt to mark up email addresses.
Sergey Kandaurov [Thu, 19 Nov 2020 17:15:22 +0000 (17:15 +0000)]
Use .Mt to mark up email addresses.

5 years agoCore: "-e" command line option.
Igor Ippolitov [Thu, 19 Nov 2020 16:59:00 +0000 (16:59 +0000)]
Core: "-e" command line option.

When installing or running from a non-root user it is sometimes required to
override default, compiled in error log path. There was no way to do this
without rebuilding the binary (ticket #147).

This patch introduced "-e" command line option which allows one to override
compiled in error log path.

5 years agoHTTP/3: null-terminate empty header value.
Roman Arutyunyan [Tue, 17 Nov 2020 20:54:10 +0000 (20:54 +0000)]
HTTP/3: null-terminate empty header value.

Header value returned from the HTTP parser is expected to be null-terminated or
have a spare byte after the value bytes.  When an empty header value was passed
by client in a literal header representation, neither was true.  This could
result in segfault.  The fix is to assign a literal empty null-terminated
string in this case.

Thanks to Andrey Kolyshkin.

5 years agoHTTP/3: finalize chunked response body chain with NULL.
Roman Arutyunyan [Tue, 17 Nov 2020 21:12:36 +0000 (21:12 +0000)]
HTTP/3: finalize chunked response body chain with NULL.

Unfinalized chain could result in segfault.  The problem was introduced in
ef83990f0e25.

Patch by Andrey Kolyshkin.

5 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 24 Nov 2020 17:19:40 +0000 (17:19 +0000)]
Merged with the default branch.

5 years agoQUIC: rejecting zero-length packets with PROTOCOL_VIOLATION.
Sergey Kandaurov [Wed, 18 Nov 2020 20:56:11 +0000 (20:56 +0000)]
QUIC: rejecting zero-length packets with PROTOCOL_VIOLATION.

Per the latest post draft-32 specification updates on the topic:
https://github.com/quicwg/base-drafts/pull/4391

5 years agoQUIC: simplified and streamlined ngx_quic_decrypt().
Sergey Kandaurov [Tue, 17 Nov 2020 21:33:16 +0000 (21:33 +0000)]
QUIC: simplified and streamlined ngx_quic_decrypt().

Both clearflags and badflags are removed.  It makes a little sense now
to keep them as intermediate storage.

5 years agoQUIC: merged create_long/short_packet() functions.
Sergey Kandaurov [Tue, 17 Nov 2020 21:33:12 +0000 (21:33 +0000)]
QUIC: merged create_long/short_packet() functions.

They no longer differ.

5 years agoQUIC: macros for manipulating header protection and reserved bits.
Sergey Kandaurov [Tue, 17 Nov 2020 21:32:22 +0000 (21:32 +0000)]
QUIC: macros for manipulating header protection and reserved bits.

This gets rid of magic numbers from quic protection and allows to push down
header construction specifics further to quic transport.

5 years agoQUIC: hide header creation internals in ngx_event_quic_transport.c.
Sergey Kandaurov [Tue, 17 Nov 2020 21:32:06 +0000 (21:32 +0000)]
QUIC: hide header creation internals in ngx_event_quic_transport.c.

It doesn't make sense to expose the header type in a public function.

5 years agoQUIC: refactored long header parsing.
Sergey Kandaurov [Tue, 17 Nov 2020 21:32:04 +0000 (21:32 +0000)]
QUIC: refactored long header parsing.

The largely duplicate type-specific functions ngx_quic_parse_initial_header(),
ngx_quic_parse_handshake_header(), and a missing one for 0-RTT, were merged.
The new order of functions listed in ngx_event_quic_transport.c reflects this.

|_ ngx_quic_parse_long_header    - version-invariant long header fields
\_ ngx_quic_supported_version    - a helper to decide we can go further
\_ ngx_quic_parse_long_header_v1 - QUICv1-specific long header fields

0-RTT packets previously appeared as Handshake are now logged as appropriate:
 *1 quic packet rx long flags:db version:ff00001d
 *1 quic packet rx early len:870

Logging SCID/DCID is no longer duplicated as were seen with Initial packets.

5 years agoQUIC: sorted header parsing functions in order of appearance.
Sergey Kandaurov [Tue, 17 Nov 2020 21:31:51 +0000 (21:31 +0000)]
QUIC: sorted header parsing functions in order of appearance.

No functional changes.

5 years agoQUIC: removed macros for stream limits unused since c5324bb3a704.
Sergey Kandaurov [Tue, 17 Nov 2020 12:22:24 +0000 (12:22 +0000)]
QUIC: removed macros for stream limits unused since c5324bb3a704.

5 years agoCore: hide "struct ngx_quic_connection_s" and further reduce diffs.
Sergey Kandaurov [Fri, 13 Nov 2020 15:11:29 +0000 (15:11 +0000)]
Core: hide "struct ngx_quic_connection_s" and further reduce diffs.

As with the previous change, it became feasible with feec2cc762f6
that removes ngx_quic_connection_t from ngx_connection_s.

5 years agoCore: reduced diff to the default branch.
Sergey Kandaurov [Fri, 13 Nov 2020 15:11:27 +0000 (15:11 +0000)]
Core: reduced diff to the default branch.

It became feasible to reduce after feec2cc762f6 that
removes ngx_quic_connection_t from ngx_connection_s.

5 years agoQUIC: microoptimization in varint parsing.
Sergey Kandaurov [Fri, 13 Nov 2020 13:24:45 +0000 (13:24 +0000)]
QUIC: microoptimization in varint parsing.

Removed a useless mask from the value being shifted, since it is 1-byte wide.

5 years agoFixed generating chunked response after 46e3542d51b3.
Roman Arutyunyan [Tue, 10 Nov 2020 20:42:45 +0000 (20:42 +0000)]
Fixed generating chunked response after 46e3542d51b3.

If trailers were missing and a chain carrying the last_buf flag had no data
in it, then last HTTP/1 chunk was broken.  The problem was introduced while
implementing HTTP/3 response body generation.

The change fixes the issue and reduces diff to the mainline nginx.

5 years agoQUIC: generate default stateless reset token key.
Roman Arutyunyan [Wed, 11 Nov 2020 21:08:48 +0000 (21:08 +0000)]
QUIC: generate default stateless reset token key.

Previously, if quic_stateless_reset_token_key was empty or unspecified,
initial stateless reset token was not generated.  However subsequent tokens
were generated with empty key, which resulted in error with certain SSL
libraries, for example OpenSSL.

Now a random 32-byte stateless reset token key is generated if none is
specified in the configuration.  As a result, stateless reset tokens are now
generated for all server ids.

5 years agoQUIC: removed comment.
Roman Arutyunyan [Wed, 11 Nov 2020 19:40:41 +0000 (19:40 +0000)]
QUIC: removed comment.

5 years agoQUIC: added quic_stateless_reset_token_key Stream directive.
Roman Arutyunyan [Wed, 11 Nov 2020 19:39:23 +0000 (19:39 +0000)]
QUIC: added quic_stateless_reset_token_key Stream directive.

A similar directive is already available in HTTP.

5 years agoQUIC: reallocate qc->dcid on retry.
Roman Arutyunyan [Wed, 11 Nov 2020 17:56:02 +0000 (17:56 +0000)]
QUIC: reallocate qc->dcid on retry.

Previously new dcid was generated in the same memory that was allocated for
qc->dcid when creating the QUIC connection.  However this memory was also
referenced by initial_source_connection_id and retry_source_connection_id
transport parameters.  As a result these parameters changed their values after
retry which broke the protocol.

5 years agoQUIC: renamed c->qs to c->quic.
Roman Arutyunyan [Tue, 10 Nov 2020 19:40:00 +0000 (19:40 +0000)]
QUIC: renamed c->qs to c->quic.

5 years agoQUIC: got rid of the c->quic field.
Roman Arutyunyan [Tue, 10 Nov 2020 18:38:42 +0000 (18:38 +0000)]
QUIC: got rid of the c->quic field.

Now QUIC connection is accessed via the c->udp field.

5 years agoQUIC: connection multiplexing per port.
Roman Arutyunyan [Wed, 11 Nov 2020 11:57:50 +0000 (11:57 +0000)]
QUIC: connection multiplexing per port.

Also, connection migration within a single worker is implemented.

5 years agoConfigure: shared sources for addon modules.
Maxim Dounin [Tue, 10 Nov 2020 14:13:20 +0000 (17:13 +0300)]
Configure: shared sources for addon modules.

Addon modules, both dynamic and static, can now use shared source files.
Shared sources result in only one make rule even if specified several
times in different modules.

5 years agoConfigure: initialization of NGX_ADDON_SRCS.
Maxim Dounin [Tue, 10 Nov 2020 14:13:17 +0000 (17:13 +0300)]
Configure: initialization of NGX_ADDON_SRCS.

5 years agoConfigure: style.
Maxim Dounin [Tue, 10 Nov 2020 14:13:14 +0000 (17:13 +0300)]
Configure: style.

5 years agoRequest body: removed error assumption (ticket #2058).
Maxim Dounin [Mon, 9 Nov 2020 19:41:54 +0000 (22:41 +0300)]
Request body: removed error assumption (ticket #2058).

Before introduction of request body filter in 42d9beeb22db, the only
possible return code from the ngx_http_request_body_filter() call
without actual buffers was NGX_HTTP_INTERNAL_SERVER_ERROR, and
the code in ngx_http_read_client_request_body() hardcoded the only
possible error to simplify the code of initial call to set rb->rest.

This is no longer true after introduction of request body filters though,
as a request body filter might need to return other errors, such as 403.
Fix is to preserve the error code actually returned by the call
instead of assuming 500.

5 years agoRequest body: improved logging.
Maxim Dounin [Mon, 9 Nov 2020 19:40:53 +0000 (22:40 +0300)]
Request body: improved logging.

Added logging before returning NGX_HTTP_INTERNAL_SERVER_ERROR if there
are busy buffers after a request body flush.  This should never happen
with current code, though bugs can be introduced by 3rd party modules.
Make sure debugging will be easy enough.

5 years agoQUIC: renamed field and function related to client ids.
Roman Arutyunyan [Mon, 9 Nov 2020 18:58:29 +0000 (18:58 +0000)]
QUIC: renamed field and function related to client ids.

Particularly, c->curr_seqnum is renamed to c->client_seqnum and
ngx_quic_alloc_connection_id() is renamed to ngx_quic_alloc_client_id().

5 years agoQUIC: multiple versions support in ALPN.
Sergey Kandaurov [Mon, 9 Nov 2020 21:32:56 +0000 (00:32 +0300)]
QUIC: multiple versions support in ALPN.

Previously, a version based on NGX_QUIC_DRAFT_VERSION was always set.
Now it is taken from the negotiated QUIC version that may differ.

5 years agoQUIC: multiple versions support.
Sergey Kandaurov [Mon, 9 Nov 2020 21:23:04 +0000 (00:23 +0300)]
QUIC: multiple versions support.

Draft-29 and beyond are now treated as compatible versions.

5 years agoQUIC: preparatory changes for multiple QUIC versions support.
Sergey Kandaurov [Mon, 9 Nov 2020 21:20:44 +0000 (00:20 +0300)]
QUIC: preparatory changes for multiple QUIC versions support.

A negotiated version is decoupled from NGX_QUIC_VERSION and, if supported,
now stored in c->quic->version after packets processing.  It is then used
to create long header packets.  Otherwise, the list of supported versions
(which may be many now) is sent in the Version Negotiation packet.

All packets in the connection are expected to have the same version.
Incoming packets with mismatched version are now rejected.

5 years agoSSL: fixed non-working SSL shutdown on lingering close.
Ruslan Ermilov [Fri, 6 Nov 2020 20:44:54 +0000 (23:44 +0300)]
SSL: fixed non-working SSL shutdown on lingering close.

When doing lingering close, the socket was first shut down for writing,
so SSL shutdown initiated after lingering close was not able to send
the close_notify alerts (ticket #2056).

The fix is to call ngx_ssl_shutdown() before shutting down the socket.

5 years agoRemoved dead code from ngx_http_set_keepalive().
Ruslan Ermilov [Fri, 6 Nov 2020 20:44:47 +0000 (23:44 +0300)]
Removed dead code from ngx_http_set_keepalive().

The code removed became dead after 98f03cd8d6cc (0.8.14),
circa when the request reference counting was introduced.

5 years agoQUIC: added proper logging of special values.
Vladimir Homutov [Fri, 6 Nov 2020 15:21:31 +0000 (18:21 +0300)]
QUIC: added proper logging of special values.

A number of unsigned variables has a special value, usually -1 or some maximum,
which produces huge numeric value in logs and makes them hard to read.

In order to distinguish such values in log, they are casted to the signed type
and printed as literal '-1'.