]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: set idle timer when sending an ack-eliciting packet.
Roman Arutyunyan [Thu, 18 Feb 2021 09:22:28 +0000 (12:22 +0300)]
QUIC: set idle timer when sending an ack-eliciting packet.

As per quic-transport-34:

   An endpoint also restarts its idle timer when sending an ack-eliciting
   packet if no other ack-eliciting packets have been sent since last receiving
   and processing a packet.

Previously, the timer was set for any packet.

5 years agoHTTP/3: limited client header size.
Roman Arutyunyan [Wed, 17 Feb 2021 08:58:32 +0000 (11:58 +0300)]
HTTP/3: limited client header size.

The limit is the size of all large client header buffers.  Client header size
is the total size of all client header names and values.

5 years agoHTTP/3: introduced ngx_http_v3_parse_t structure.
Roman Arutyunyan [Wed, 17 Feb 2021 12:56:34 +0000 (15:56 +0300)]
HTTP/3: introduced ngx_http_v3_parse_t structure.

The structure is used to parse an HTTP/3 request.  An object of this type is
added to ngx_http_request_t instead of h3_parse generic pointer.

Also, the new field is located outside of the request ephemeral zone to keep it
safe after request headers are parsed.

5 years agoHTTP/3: removed http3_max_field_size.
Roman Arutyunyan [Tue, 16 Feb 2021 15:50:01 +0000 (18:50 +0300)]
HTTP/3: removed http3_max_field_size.

Instead, size of one large_client_header_buffers buffer is used.

5 years agoMerged with the default branch.
Sergey Kandaurov [Wed, 17 Feb 2021 11:48:35 +0000 (14:48 +0300)]
Merged with the default branch.

5 years agoQUIC: added ability to reset a stream.
Sergey Kandaurov [Wed, 17 Feb 2021 11:25:07 +0000 (14:25 +0300)]
QUIC: added ability to reset a stream.

5 years agorelease-1.19.7 tag
Maxim Dounin [Tue, 16 Feb 2021 15:57:18 +0000 (18:57 +0300)]
release-1.19.7 tag

5 years agonginx-1.19.7-RELEASE release-1.19.7
Maxim Dounin [Tue, 16 Feb 2021 15:57:18 +0000 (18:57 +0300)]
nginx-1.19.7-RELEASE

5 years agoQUIC: fixed indentation.
Sergey Kandaurov [Mon, 15 Feb 2021 11:54:28 +0000 (14:54 +0300)]
QUIC: fixed indentation.

5 years agoQUIC: added check of client transport parameters.
Vladimir Homutov [Mon, 15 Feb 2021 11:05:46 +0000 (14:05 +0300)]
QUIC: added check of client transport parameters.

Parameters sent by client are verified and defaults are set for parameters
omitted by client.

5 years agoHTTP/2: removed http2_max_field_size and http2_max_header_size.
Maxim Dounin [Thu, 11 Feb 2021 18:52:26 +0000 (21:52 +0300)]
HTTP/2: removed http2_max_field_size and http2_max_header_size.

Instead, size of one large_client_header_buffers buffer and all large
client header buffers are used.

5 years agoHTTP/2: keepalive_timeout now armed once between requests.
Maxim Dounin [Thu, 11 Feb 2021 18:52:24 +0000 (21:52 +0300)]
HTTP/2: keepalive_timeout now armed once between requests.

Previously, PINGs and other frames extended possible keepalive time,
making it possible to keep an open HTTP/2 connection for a long time.
Now the connection is always closed as long as keepalive_timeout expires,
similarly to how it happens in HTTP/1.x.

Note that as a part of this change, incomplete frames are no longer
trigger a separate timeout, so http2_recv_timeout (replaced by
client_header_timeout in previous patches) is essentially cancelled.
The client_header_timeout is, however, used for SSL handshake and
while reading HEADERS frames.

5 years agoHTTP/2: removed http2_idle_timeout and http2_max_requests.
Maxim Dounin [Thu, 11 Feb 2021 18:52:23 +0000 (21:52 +0300)]
HTTP/2: removed http2_idle_timeout and http2_max_requests.

Instead, keepalive_timeout and keepalive_requests are now used.  This
is expected to simplify HTTP/2 code and usage.  This also matches
directives used by upstream module for all protocols.

In case of default settings, this effectively changes maximum number
of requests per connection from 1000 to 100.  This looks acceptable,
especially given that HTTP/2 code now properly supports lingering close.

Further, this changes default keepalive timeout in HTTP/2 from 300 seconds
to 75 seconds.  This also looks acceptable, and larger than PING interval
used by Firefox (network.http.spdy.ping-threshold defaults to 58s),
the only browser to use PINGs.

5 years agoHTTP/2: removed http2_recv_timeout.
Maxim Dounin [Thu, 11 Feb 2021 18:52:20 +0000 (21:52 +0300)]
HTTP/2: removed http2_recv_timeout.

Instead, the client_header_timeout is now used for HTTP/2 reading.
Further, the timeout is changed to be set once till no further data
left to read, similarly to how client_header_timeout is used in other
places.

5 years agoHTTP/2: removed SPDY directives handling.
Maxim Dounin [Thu, 11 Feb 2021 18:52:19 +0000 (21:52 +0300)]
HTTP/2: removed SPDY directives handling.

The spdy_* directives are not available since introduction of HTTP/2 module
in nginx 1.9.5 more than five years ago.

5 years agoHTTP/2: fixed reusing connections with active requests.
Maxim Dounin [Thu, 11 Feb 2021 18:52:17 +0000 (21:52 +0300)]
HTTP/2: fixed reusing connections with active requests.

New connections are marked reusable by ngx_http_init_connection() if there
are no data available for reading.  As a result, if SSL is not used,
ngx_http_v2_init() might be called when the connection is marked reusable.
If a HEADERS frame is immediately available for reading, this resulted
in connection being preserved in reusable state with an active request,
and possibly closed later as if during worker shutdown (that is, after
all active requests were finalized).

Fix is to explicitly mark connections non-reusable in ngx_http_v2_init()
instead of (incorrectly) assuming they are already non-reusable.

Found by Sergey Kandaurov.

5 years agoHTTP/2: reuse of connections with incomplete frames.
Maxim Dounin [Thu, 11 Feb 2021 18:52:12 +0000 (21:52 +0300)]
HTTP/2: reuse of connections with incomplete frames.

Prodded by Taewoo Kim.

5 years agoAdditional connections reuse.
Maxim Dounin [Thu, 11 Feb 2021 18:52:11 +0000 (21:52 +0300)]
Additional connections reuse.

If ngx_drain_connections() fails to immediately reuse any connections
and there are no free connections, it now additionally tries to reuse
a connection again.  This helps to provide at least one free connection
in case of HTTP/2 with lingering close, where merely trying to reuse
a connection once does not free it, but makes it reusable again,
waiting for lingering close.

5 years agoReuse of connections in lingering close.
Maxim Dounin [Thu, 11 Feb 2021 18:52:09 +0000 (21:52 +0300)]
Reuse of connections in lingering close.

This is particularly important in HTTP/2, where keepalive connections
are closed with lingering.  Before the patch, reusing a keepalive HTTP/2
connection resulted in the connection waiting for lingering close to
remain in the reusable connections queue, preventing ngx_drain_connections()
from closing additional connections.

The patch fixes it by marking the connection reusable again, and so
moving it in the reusable connections queue.  Further, it makes actually
possible to reuse such connections if needed.

5 years agoQUIC: updated list of transport parameters to be sent.
Vladimir Homutov [Mon, 8 Feb 2021 17:48:25 +0000 (20:48 +0300)]
QUIC: updated list of transport parameters to be sent.

The "max_ack_delay", "ack_delay_exponent", and "max_udp_payload_size"
transport parameters were not communicated to client.

The "disable_active_migration" and "active_connection_id_limit"
parameters were not saved into zero-rtt context.

5 years agoQUIC: distinguish reserved transport parameters in logging.
Vladimir Homutov [Wed, 10 Feb 2021 11:10:14 +0000 (14:10 +0300)]
QUIC: distinguish reserved transport parameters in logging.

  18.1.  Reserved Transport Parameters

     Transport parameters with an identifier of the form "31 * N + 27" for
     integer values of N are reserved to exercise the requirement that
     unknown transport parameters be ignored.  These transport parameters
     have no semantics, and can carry arbitrary values.

5 years agoQUIC: send PING frames on PTO expiration.
Roman Arutyunyan [Fri, 12 Feb 2021 11:51:53 +0000 (14:51 +0300)]
QUIC: send PING frames on PTO expiration.

Two PING frames are sent per level that generate two UDP datagrams.

5 years agoQUIC: improved setting the lost timer.
Roman Arutyunyan [Fri, 12 Feb 2021 11:40:33 +0000 (14:40 +0300)]
QUIC: improved setting the lost timer.

Setting the timer is brought into compliance with quic-recovery-34.  Now it's
set from a single function ngx_quic_set_lost_timer() that takes into account
both loss detection and PTO.  The following issues are fixed with this change:

- when in loss detection mode, discarding a context could turn off the
  timer forever after switching to the PTO mode
- when in loss detection mode, sending a packet resulted in rescheduling the
  timer as if it's always in the PTO mode

5 years agoQUIC: disabled non-immediate ACKs for Initial and Handshake.
Roman Arutyunyan [Thu, 4 Feb 2021 17:39:47 +0000 (20:39 +0300)]
QUIC: disabled non-immediate ACKs for Initial and Handshake.

As per quic-transport-33:

   An endpoint MUST acknowledge all ack-eliciting Initial and Handshake
   packets immediately

If a packet carrying Initial or Handshake ACK was lost, a non-immediate ACK
should not be sent later.  Instead, client is expected to send a new packet
to acknowledge.

Sending non-immediate ACKs for Initial packets can cause the client to
generate an inflated RTT sample.

5 years agoQUIC: fixed logging ACK frames.
Roman Arutyunyan [Tue, 9 Feb 2021 11:31:36 +0000 (14:31 +0300)]
QUIC: fixed logging ACK frames.

Previously, the wrong end pointer was used, which could lead to errors
"quic failed to parse ack frame gap".

5 years agoQUIC: the "quic_host_key" directive.
Vladimir Homutov [Mon, 8 Feb 2021 13:49:33 +0000 (16:49 +0300)]
QUIC: the "quic_host_key" directive.

The token generation in QUIC is reworked. Single host key is used to generate
all required keys of needed sizes using HKDF.

The "quic_stateless_reset_token_key" directive is removed.  Instead, the
"quic_host_key" directive is used, which reads key from file, or sets it
to random bytes if not specified.

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.