]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoHTTP/3: removed $http3 that served its purpose.
Sergey Kandaurov [Mon, 31 May 2021 08:54:47 +0000 (11:54 +0300)]
HTTP/3: removed $http3 that served its purpose.

To specify final protocol version by hand:

    add_header Alt-Svc h3=":443";

5 years agoREADME: updated after QUIC RFC publication, nginx 1.21 rebase.
Sergey Kandaurov [Fri, 28 May 2021 10:45:09 +0000 (13:45 +0300)]
README: updated after QUIC RFC publication, nginx 1.21 rebase.

5 years agoMerged with the default branch.
Sergey Kandaurov [Fri, 28 May 2021 10:33:08 +0000 (13:33 +0300)]
Merged with the default branch.

5 years agoHTTP/3: fixed Insert With Name Reference index processing.
Sergey Kandaurov [Thu, 27 May 2021 10:29:00 +0000 (13:29 +0300)]
HTTP/3: fixed Insert With Name Reference index processing.

Based on a patch by Zhiyong Sun.

5 years agoQUIC: call stream read handler on new data arrival.
Roman Arutyunyan [Wed, 26 May 2021 10:07:06 +0000 (13:07 +0300)]
QUIC: call stream read handler on new data arrival.

This was broken in b3f6ad181df4.

5 years agoQUIC: make sure stream data size is lower than final size.
Roman Arutyunyan [Tue, 25 May 2021 13:41:59 +0000 (16:41 +0300)]
QUIC: make sure stream data size is lower than final size.

As per quic-transport 34, FINAL_SIZE_ERROR is generated if an endpoint received
a STREAM frame or a RESET_STREAM frame containing a final size that was lower
than the size of stream data that was already received.

5 years agorelease-1.21.0 tag
Maxim Dounin [Tue, 25 May 2021 12:28:56 +0000 (15:28 +0300)]
release-1.21.0 tag

5 years agonginx-1.21.0-RELEASE release-1.21.0
Maxim Dounin [Tue, 25 May 2021 12:28:55 +0000 (15:28 +0300)]
nginx-1.21.0-RELEASE

5 years agoResolver: explicit check for compression pointers in question.
Maxim Dounin [Tue, 25 May 2021 12:17:50 +0000 (15:17 +0300)]
Resolver: explicit check for compression pointers in question.

Since nginx always uses exactly one entry in the question section of
a DNS query, and never uses compression pointers in this entry, parsing
of a DNS response in ngx_resolver_process_response() does not expect
compression pointers to appear in the question section of the DNS
response.  Indeed, compression pointers in the first name of a DNS response
hardly make sense, do not seem to be allowed by RFC 1035 (which says
"a pointer to a prior occurance of the same name", note "prior"), and
were never observed in practice.

Added an explicit check to ngx_resolver_process_response()'s parsing
of the question section to properly report an error if compression pointers
nevertheless appear in the question section.

5 years agoResolver: simplified ngx_resolver_copy().
Maxim Dounin [Tue, 25 May 2021 12:17:45 +0000 (15:17 +0300)]
Resolver: simplified ngx_resolver_copy().

Instead of checking on each label if we need to place a dot or not,
now it always adds a dot after a label, and reduces the resulting
length afterwards.

5 years agoResolver: reworked ngx_resolver_copy() copy loop.
Maxim Dounin [Tue, 25 May 2021 12:17:43 +0000 (15:17 +0300)]
Resolver: reworked ngx_resolver_copy() copy loop.

To make the code easier to read, reworked the ngx_resolver_copy()
copy loop to match the one used to calculate length.  No functional
changes.

5 years agoResolver: fixed label types handling in ngx_resolver_copy().
Maxim Dounin [Tue, 25 May 2021 12:17:41 +0000 (15:17 +0300)]
Resolver: fixed label types handling in ngx_resolver_copy().

Previously, anything with any of the two high bits set were interpreted
as compression pointers.  This is incorrect, as RFC 1035 clearly states
that "The 10 and 01 combinations are reserved for future use".  Further,
the 01 combination is actually allocated for EDNS extended label type
(see RFC 2671 and RFC 6891), not really used though.

Fix is to reject unrecognized label types rather than misinterpreting
them as compression pointers.

5 years agoResolver: fixed off-by-one read in ngx_resolver_copy().
Maxim Dounin [Tue, 25 May 2021 12:17:38 +0000 (15:17 +0300)]
Resolver: fixed off-by-one read in ngx_resolver_copy().

It is believed to be harmless, and in the worst case it uses some
uninitialized memory as a part of the compression pointer length,
eventually leading to the "name is out of DNS response" error.

5 years agoResolver: fixed off-by-one write in ngx_resolver_copy().
Maxim Dounin [Tue, 25 May 2021 12:17:36 +0000 (15:17 +0300)]
Resolver: fixed off-by-one write in ngx_resolver_copy().

Reported by Luis Merino, Markus Vervier, Eric Sesterhenn, X41 D-Sec GmbH.

5 years agoQUIC: refactored CRYPTO and STREAM buffer ordering.
Roman Arutyunyan [Tue, 25 May 2021 10:55:12 +0000 (13:55 +0300)]
QUIC: refactored CRYPTO and STREAM buffer ordering.

Generic function ngx_quic_order_bufs() is introduced.  This function creates
and maintains a chain of buffers with holes.  Holes are marked with b->sync
flag.  Several buffers and holes in this chain may share the same underlying
memory buffer.

When processing STREAM frames with this function, frame data is copied only
once to the right place in the stream input chain.  Previously data could
be copied twice.  First when buffering an out-of-order frame data, and then
when filling stream buffer from ordered frame queue.  Now there's only one
data chain for both tasks.

5 years agoLocation header escaping in redirects (ticket #882).
Ruslan Ermilov [Mon, 24 May 2021 18:55:20 +0000 (21:55 +0300)]
Location header escaping in redirects (ticket #882).

The header is escaped in redirects based on request URI or
location name (auto redirect).

5 years agoFixed log action when using SSL certificates with variables.
Maxim Dounin [Mon, 24 May 2021 15:23:42 +0000 (18:23 +0300)]
Fixed log action when using SSL certificates with variables.

When variables are used in ssl_certificate or ssl_certificate_key, a request
is created in the certificate callback to evaluate the variables, and then
freed.  Freeing it, however, updates c->log->action to "closing request",
resulting in confusing error messages like "client timed out ... while
closing request" when a client times out during the SSL handshake.

Fix is to restore c->log->action after calling ngx_http_free_request().

5 years agoQUIC: unroll and inline ngx_quic_varint_len()/ngx_quic_build_int().
Sergey Kandaurov [Sat, 22 May 2021 15:40:45 +0000 (18:40 +0300)]
QUIC: unroll and inline ngx_quic_varint_len()/ngx_quic_build_int().

According to profiling, those two are among most frequently called,
so inlining is generally useful, and unrolling should help with it.
Further, this fixes undefined behaviour seen with invalid values.

Inspired by Yu Liu.

5 years agoStream: the "fastopen" parameter of the "listen" directive.
Ruslan Ermilov [Thu, 20 May 2021 16:59:16 +0000 (19:59 +0300)]
Stream: the "fastopen" parameter of the "listen" directive.

Based on a patch by Anbang Wen.

5 years agoCore: fixed comment about msie_refresh escaping.
Ruslan Ermilov [Wed, 19 May 2021 13:24:13 +0000 (16:24 +0300)]
Core: fixed comment about msie_refresh escaping.

After 12a656452ad1, the "%" character is no longer escaped by
ngx_escape_uri(NGX_ESCAPE_REFRESH).

5 years agoMail: max_errors directive.
Maxim Dounin [Wed, 19 May 2021 00:13:31 +0000 (03:13 +0300)]
Mail: max_errors directive.

Similarly to smtpd_hard_error_limit in Postfix and smtp_max_unknown_commands
in Exim, specifies the number of errors after which the connection is closed.

5 years agoMail: IMAP pipelining support.
Maxim Dounin [Wed, 19 May 2021 00:13:28 +0000 (03:13 +0300)]
Mail: IMAP pipelining support.

The change is mostly the same as the SMTP one (04e43d03e153 and 3f5d0af4e40a),
and ensures that nginx is able to properly handle or reject multiple IMAP
commands.  The s->cmd field is not really used and set for consistency.

Non-synchronizing literals handling in invalid/unknown commands is limited,
so when a non-synchronizing literal is detected at the end of a discarded
line, the connection is closed.

5 years agoMail: stricter checking of IMAP tags.
Maxim Dounin [Wed, 19 May 2021 00:13:26 +0000 (03:13 +0300)]
Mail: stricter checking of IMAP tags.

Only "A-Za-z0-9-._" characters now allowed (which is stricter than what
RFC 3501 requires, but expected to be enough for all known clients),
and tags shouldn't be longer than 32 characters.

5 years agoMail: fixed backslash handling in IMAP literals.
Maxim Dounin [Wed, 19 May 2021 00:13:23 +0000 (03:13 +0300)]
Mail: fixed backslash handling in IMAP literals.

Previously, s->backslash was set if any of the arguments was a quoted
string with a backslash character.  After successful command parsing
this resulted in all arguments being filtered to remove backslashes.
This is, however, incorrect, as backslashes should not be removed from
IMAP literals.  For example:

   S: * OK IMAP4 ready
   C: a01 login {9}
   S: + OK
   C: user\name "pass\"word"
   S: * BAD internal server error

resulted in "Auth-User: username" instead of "Auth-User: user\name"
as it should.

Fix is to apply backslash filtering on per-argument basis during parsing.

5 years agoMail: removed dead s->arg_start handling.
Maxim Dounin [Wed, 19 May 2021 00:13:22 +0000 (03:13 +0300)]
Mail: removed dead s->arg_start handling.

As discussed in the previous change, s->arg_start handling in the "done"
labels of ngx_mail_pop3_parse_command(), ngx_mail_imap_parse_command(),
and ngx_mail_smtp_parse_command() is wrong: s->arg_start cannot be
set there, as it is handled and cleared on all code paths where the
"done" labels are reached.  The relevant code is dead and now removed.

5 years agoMail: fixed s->arg_start clearing on invalid IMAP commands.
Maxim Dounin [Wed, 19 May 2021 00:13:20 +0000 (03:13 +0300)]
Mail: fixed s->arg_start clearing on invalid IMAP commands.

Previously, s->arg_start was left intact after invalid IMAP commands,
and this might result in an argument incorrectly added to the following
command.  Similarly, s->backslash was left intact as well, leading
to unneeded backslash removal.

For example (LFs from the client are explicitly shown as "<LF>"):

  S: * OK IMAP4 ready
  C: a01 login "\<LF>
  S: a01 BAD invalid command
  C: a0000000000\2 authenticate <LF>
  S: a00000000002 aBAD invalid command

The backslash followed by LF generates invalid command with s->arg_start
and s->backslash set, the following command incorrectly treats anything
from the old s->arg_start to the space after the command as an argument,
and removes the backslash from the tag.  If there is no space, s->arg_end
will be NULL.

Both things seem to be harmless though.  In particular:

- This can be used to provide an incorrect argument to a command without
  arguments.  The only command which seems to look at the single argument
  is AUTHENTICATE, and it checks the argument length before trying to
  access it.

- Backslash removal uses the "end" pointer, and stops due to "src < end"
  condition instead of scanning all the process memory if s->arg_end is
  NULL (and arg[0].len is huge).

- There should be no backslashes in unquoted strings.

An obvious fix is to clear s->arg_start and s->backslash on invalid commands,
similarly to how it is done in POP3 parsing (added in 810:e3aa8f305d21) and
SMTP parsing.

This, however, makes it clear that s->arg_start handling in the "done"
label is wrong: s->arg_start cannot be legitimately set there, as it
is expected to be cleared in all possible cases when the "done" label is
reached.  The relevant code is dead and will be removed by the following
change.

5 years agoMail: POP3 pipelining support.
Maxim Dounin [Wed, 19 May 2021 00:13:18 +0000 (03:13 +0300)]
Mail: POP3 pipelining support.

The change is mostly the same as the SMTP one (04e43d03e153 and 3f5d0af4e40a),
and ensures that nginx is able to properly handle or reject multiple POP3
commands, as required by the PIPELINING capability (RFC 2449).  The s->cmd
field is not really used and set for consistency.

5 years agoMail: optimized discarding invalid SMTP commands.
Maxim Dounin [Wed, 19 May 2021 00:13:17 +0000 (03:13 +0300)]
Mail: optimized discarding invalid SMTP commands.

There is no need to scan buffer from s->buffer->pos, as we already scanned
the buffer till "p" and wasn't able to find an LF.

There is no real need for this change in SMTP, since it is at most a
microoptimization of a non-common code path.  Similar code in IMAP, however,
will have to start scanning from "p" to be correct, since there can be
newlines in IMAP literals.

5 years agoMail: fixed handling of invalid SMTP commands split between reads.
Maxim Dounin [Wed, 19 May 2021 00:13:15 +0000 (03:13 +0300)]
Mail: fixed handling of invalid SMTP commands split between reads.

Previously, if an invalid SMTP command was split between reads, nginx failed
to wait for LF before returning an error, and interpreted the rest of the
command received later as a separate command.

The sw_invalid state in ngx_mail_smtp_parse_command(), introduced in
04e43d03e153, did not work, since ngx_mail_smtp_auth_state() clears
s->state when returning an error due to NGX_MAIL_PARSE_INVALID_COMMAND.
And not clearing s->state will introduce another problem: the rest
of the command would trigger duplicate error when rest of the command is
received.

Fix is to return NGX_AGAIN from ngx_mail_smtp_parse_command() until full
command is received.

5 years agoMail: fixed SMTP pipelining to send the response immediately.
Maxim Dounin [Wed, 19 May 2021 00:13:12 +0000 (03:13 +0300)]
Mail: fixed SMTP pipelining to send the response immediately.

Previously, if there were some pipelined SMTP data in the buffer when
a proxied connection with the backend was established, nginx called
ngx_mail_proxy_handler() to send these data, and not tried to send the
response to the last command.  In most cases, this response was later sent
along with the response to the pipelined command, but if for some reason
client decides to wait for the response before finishing the next command
this might result in a connection hang.

Fix is to always call ngx_mail_proxy_handler() to send the response, and
additionally post an event to send the pipelined data if needed.

5 years agoHTTP/3: fixed server push after 9ec3e71f8a61.
Roman Arutyunyan [Tue, 18 May 2021 15:17:25 +0000 (18:17 +0300)]
HTTP/3: fixed server push after 9ec3e71f8a61.

When using server push, a segfault occured because
ngx_http_v3_create_push_request() accessed ngx_http_v3_session_t object the old
way.  Prior to 9ec3e71f8a61, HTTP/3 session was stored directly in c->data.
Now it's referenced by the v3_session field of ngx_http_connection_t.

5 years agoMIME: added application/wasm type (ticket #1606).
Maxim Dounin [Sat, 8 May 2021 17:31:03 +0000 (20:31 +0300)]
MIME: added application/wasm type (ticket #1606).

5 years agoUpstream: variables support in certificates.
Maxim Dounin [Wed, 5 May 2021 23:22:09 +0000 (02:22 +0300)]
Upstream: variables support in certificates.

5 years agoAuth basic: changed alcf->user_file to be a pointer.
Maxim Dounin [Wed, 5 May 2021 23:22:07 +0000 (02:22 +0300)]
Auth basic: changed alcf->user_file to be a pointer.

This saves some memory in typical case when auth_basic_user_file is not
explicitly set, and unifies the code with alcf->realm.

5 years agoChanged complex value slots to use NGX_CONF_UNSET_PTR.
Maxim Dounin [Wed, 5 May 2021 23:22:03 +0000 (02:22 +0300)]
Changed complex value slots to use NGX_CONF_UNSET_PTR.

With this change, it is now possible to use ngx_conf_merge_ptr_value()
to merge complex values.  This change follows much earlier changes in
ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot()
in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22), and the
change in ngx_conf_set_keyval_slot() (7728:485dba3e2a01, 1.19.4).

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

5 years agoQUIC: generic buffering for stream input.
Roman Arutyunyan [Wed, 5 May 2021 14:15:20 +0000 (17:15 +0300)]
QUIC: generic buffering for stream input.

Previously each stream had an input buffer.  Now memory is allocated as
bytes arrive.  Generic buffering mechanism is used for this.

5 years agoQUIC: simplified sending 1-RTT only frames.
Sergey Kandaurov [Wed, 5 May 2021 16:32:49 +0000 (19:32 +0300)]
QUIC: simplified sending 1-RTT only frames.

5 years agoQUIC: relaxed client id requirements.
Vladimir Homutov [Wed, 5 May 2021 15:11:55 +0000 (18:11 +0300)]
QUIC: relaxed client id requirements.

Client IDs cannot be reused on different paths.  This change allows to reuse
client id previosly seen on the same path (but with different dcid) in case
when no unused client IDs are available.

5 years agoQUIC: consider NEW_CONNECTION_ID a probing frame.
Vladimir Homutov [Thu, 6 May 2021 09:36:14 +0000 (12:36 +0300)]
QUIC: consider NEW_CONNECTION_ID a probing frame.

According to quic-transport, 9.1:

   PATH_CHALLENGE, PATH_RESPONSE, NEW_CONNECTION_ID, and PADDING frames
   are "probing frames", and all other frames are "non-probing frames".

5 years agoHTTP/3: clean up table from session cleanup handler.
Roman Arutyunyan [Wed, 28 Apr 2021 08:30:27 +0000 (11:30 +0300)]
HTTP/3: clean up table from session cleanup handler.

Previously table had a separate cleanup handler.

5 years agoHTTP/3: moved session initialization to a separate file.
Roman Arutyunyan [Wed, 5 May 2021 12:15:48 +0000 (15:15 +0300)]
HTTP/3: moved session initialization to a separate file.

Previously it was in ngx_http_v3_streams.c, but it's unrelated to streams.

5 years agoHTTP/3: separate header files for existing source files.
Roman Arutyunyan [Wed, 5 May 2021 12:09:23 +0000 (15:09 +0300)]
HTTP/3: separate header files for existing source files.

5 years agoHTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan [Wed, 5 May 2021 12:00:17 +0000 (15:00 +0300)]
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.

Previously it was parsed in ngx_http_v3_streams.c, while the streams were
parsed in ngx_http_v3_parse.c.  Now all parsing is done in one file.  This
simplifies parsing API and cleans up ngx_http_v3_streams.c.

5 years agoHTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan [Tue, 27 Apr 2021 18:32:50 +0000 (21:32 +0300)]
HTTP/3: renamed ngx_http_v3_client_XXX() functions.

The functions are renamed to ngx_http_v3_send_XXX() similar to
ngx_http_v3_send_settings() and ngx_http_v3_send_goaway().

5 years agoHTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan [Wed, 5 May 2021 09:54:10 +0000 (12:54 +0300)]
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.

5 years agoHTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan [Wed, 5 May 2021 11:53:36 +0000 (14:53 +0300)]
HTTP/3: reference h3c directly from ngx_http_connection_t.

Previously, an ngx_http_v3_connection_t object was created for HTTP/3 and
then assinged to c->data instead of the generic ngx_http_connection_t object.
Now a direct reference is added to ngx_http_connection_t, which is less
confusing and does not require a flag for http3.

5 years agoHTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan [Fri, 30 Apr 2021 16:10:11 +0000 (19:10 +0300)]
HTTP/3: ngx_http_v3_get_session() macro.

It's used instead of accessing c->quic->parent->data directly.  Apart from being
simpler, it allows to change the way session is stored in the future by changing
the macro.

5 years agoHTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan [Wed, 5 May 2021 12:15:17 +0000 (15:15 +0300)]
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.

5 years agoHTTP/3: fixed decoder stream stubs.
Roman Arutyunyan [Tue, 4 May 2021 10:38:59 +0000 (13:38 +0300)]
HTTP/3: fixed decoder stream stubs.

Now ngx_http_v3_ack_header() and ngx_http_v3_inc_insert_count() always generate
decoder error.  Our implementation does not use dynamic tables and does not
expect client to send Section Acknowledgement or Insert Count Increment.

Stream Cancellation, on the other hand, is allowed to be sent anyway.  This is
why ngx_http_v3_cancel_stream() does not return an error.

5 years agoHTTP/3: reject empty DATA and HEADERS frames on control stream.
Roman Arutyunyan [Wed, 5 May 2021 10:28:05 +0000 (13:28 +0300)]
HTTP/3: reject empty DATA and HEADERS frames on control stream.

Previously only non-empty frames were rejected.

5 years agoQUIC: fixed build with NGX_QUIC_DEBUG_ALLOC enabled.
Vladimir Homutov [Wed, 28 Apr 2021 10:37:18 +0000 (13:37 +0300)]
QUIC: fixed build with NGX_QUIC_DEBUG_ALLOC enabled.

5 years agoQUIC: connection migration.
Vladimir Homutov [Thu, 29 Apr 2021 12:35:02 +0000 (15:35 +0300)]
QUIC: connection migration.

The patch adds proper transitions between multiple networking addresses that
can be used by a single quic connection. New networking paths are validated
using PATH_CHALLENGE/PATH_RESPONSE frames.

5 years agoRestored zeroing of ngx_channel_t in ngx_pass_open_channel().
Ruslan Ermilov [Thu, 22 Apr 2021 13:12:52 +0000 (16:12 +0300)]
Restored zeroing of ngx_channel_t in ngx_pass_open_channel().

Due to structure's alignment, some uninitialized memory contents may have
been passed between processes.

Zeroing was removed in 0215ec9aaa8a.

Reported by Johnny Wang.

5 years agoHTTP/3: adjusted control stream parsing.
Vladimir Homutov [Thu, 22 Apr 2021 10:49:18 +0000 (13:49 +0300)]
HTTP/3: adjusted control stream parsing.

7.2.1:
   If a DATA frame is received on a control stream, the recipient MUST
   respond with a connection error of type H3_FRAME_UNEXPECTED;

7.2.2:
   If a HEADERS frame is received on a control stream, the recipient MUST
   respond with a connection error (Section 8) of type H3_FRAME_UNEXPECTED.

5 years agoMail: fixed reading with fully filled buffer (ticket #2159).
Maxim Dounin [Wed, 21 Apr 2021 20:24:59 +0000 (23:24 +0300)]
Mail: fixed reading with fully filled buffer (ticket #2159).

With SMTP pipelining, ngx_mail_read_command() can be called with s->buffer
without any space available, to parse additional commands received to the
buffer on previous calls.  Previously, this resulted in recv() being called
with zero length, resulting in zero being returned, which was interpreted
as a connection close by the client, so nginx silently closed connection.

Fix is to avoid calling c->recv() if there is no free space in the buffer,
but continue parsing of the already received commands.

5 years agoVersion bump.
Maxim Dounin [Wed, 21 Apr 2021 20:24:48 +0000 (23:24 +0300)]
Version bump.

5 years agoQUIC: renamed stream variables from sn to qs.
Roman Arutyunyan [Mon, 19 Apr 2021 14:25:56 +0000 (17:25 +0300)]
QUIC: renamed stream variables from sn to qs.

Currently both names are used which is confusing.  Historically these were
different objects, but now it's the same one.  The name qs (quic stream) makes
more sense than sn (stream node).

5 years agoQUIC: renamed stream field from c to connection.
Roman Arutyunyan [Mon, 19 Apr 2021 14:21:07 +0000 (17:21 +0300)]
QUIC: renamed stream field from c to connection.

5 years agoQUIC: fixed permitted packet types for PATH_RESPONSE.
Sergey Kandaurov [Fri, 16 Apr 2021 20:03:59 +0000 (23:03 +0300)]
QUIC: fixed permitted packet types for PATH_RESPONSE.

PATH_RESPONSE was explicitly forbidden in 0-RTT since at least draft-22, but
the Frame Types table was not updated until recently while in IESG evaluation.

5 years agoQUIC: added missing checks for limits in stream frames parsing.
Vladimir Homutov [Mon, 19 Apr 2021 06:46:37 +0000 (09:46 +0300)]
QUIC: added missing checks for limits in stream frames parsing.

5 years agoQUIC: fixed parsing of unknown frame types.
Vladimir Homutov [Mon, 19 Apr 2021 08:36:41 +0000 (11:36 +0300)]
QUIC: fixed parsing of unknown frame types.

The ngx_quic_frame_allowed() function only expects known frame types.

5 years agoQUIC: avoid sending extra frames in case of error.
Vladimir Homutov [Thu, 15 Apr 2021 09:17:19 +0000 (12:17 +0300)]
QUIC: avoid sending extra frames in case of error.

5 years agorelease-1.19.10 tag
Maxim Dounin [Tue, 13 Apr 2021 15:13:59 +0000 (18:13 +0300)]
release-1.19.10 tag

5 years agonginx-1.19.10-RELEASE release-1.19.10
Maxim Dounin [Tue, 13 Apr 2021 15:13:58 +0000 (18:13 +0300)]
nginx-1.19.10-RELEASE

5 years agoQUIC: normalize header inclusion.
Sergey Kandaurov [Tue, 13 Apr 2021 09:38:34 +0000 (12:38 +0300)]
QUIC: normalize header inclusion.

Stop including QUIC headers with no user-serviceable parts inside.
This allows to provide a much cleaner QUIC interface.  To cope with that,
ngx_quic_derive_key() is now explicitly exported for v3 and quic modules.
Additionally, this completely hides the ngx_quic_keys_t internal type.

5 years agoQUIC: ngx_quic_frames_stream_t made opaque.
Sergey Kandaurov [Tue, 13 Apr 2021 08:49:52 +0000 (11:49 +0300)]
QUIC: ngx_quic_frames_stream_t made opaque.

5 years agoQUIC: separate files for SSL library interfaces.
Vladimir Homutov [Wed, 14 Apr 2021 11:47:04 +0000 (14:47 +0300)]
QUIC: separate files for SSL library interfaces.

5 years agoQUIC: separate files for tokens related processing.
Vladimir Homutov [Tue, 13 Apr 2021 11:41:52 +0000 (14:41 +0300)]
QUIC: separate files for tokens related processing.

5 years agoQUIC: separate files for output and ack related processing.
Vladimir Homutov [Tue, 13 Apr 2021 11:41:20 +0000 (14:41 +0300)]
QUIC: separate files for output and ack related processing.

5 years agoQUIC: separate files for stream related processing.
Vladimir Homutov [Tue, 13 Apr 2021 11:40:00 +0000 (14:40 +0300)]
QUIC: separate files for stream related processing.

5 years agoQUIC: separate files for frames related processing.
Vladimir Homutov [Tue, 13 Apr 2021 11:38:46 +0000 (14:38 +0300)]
QUIC: separate files for frames related processing.

5 years agoQUIC: separate files for connection id related processing.
Vladimir Homutov [Tue, 13 Apr 2021 11:37:41 +0000 (14:37 +0300)]
QUIC: separate files for connection id related processing.

5 years agoQUIC: headers cleanup.
Vladimir Homutov [Wed, 14 Apr 2021 11:47:37 +0000 (14:47 +0300)]
QUIC: headers cleanup.

The "ngx_event_quic.h" header file now contains only public definitions,
used by modules.  All internal definitions are moved into
the "ngx_event_quic_connection.h" header file.

5 years agoQUIC: separate function for connection ids initialization.
Vladimir Homutov [Fri, 9 Apr 2021 08:33:10 +0000 (11:33 +0300)]
QUIC: separate function for connection ids initialization.

The function correctly cleans up resources in case of failure to create
initial server id: it removes previously created udp node for odcid from
listening rbtree.

5 years agoChanged keepalive_requests default to 1000 (ticket #2155).
Maxim Dounin [Wed, 7 Apr 2021 21:16:30 +0000 (00:16 +0300)]
Changed keepalive_requests default to 1000 (ticket #2155).

It turns out no browsers implement HTTP/2 GOAWAY handling properly, and
large enough number of resources on a page results in failures to load
some resources.  In particular, Chrome seems to experience errors if
loading of all resources requires more than 1 connection (while it
is usually able to retry requests at least once, even with 2 connections
there are occasional failures for some reason), Safari if loading requires
more than 3 connections, and Firefox if loading requires more than 10
connections (can be configured with network.http.request.max-attempts,
defaults to 10).

It does not seem to be possible to resolve this on nginx side, even strict
limiting of maximum concurrency does not help, and loading issues seems to
be triggered by merely queueing of a request for a particular connection.
The only available mitigation seems to use higher keepalive_requests value.

The new default is 1000 and matches previously used default for
http2_max_requests.  It is expected to be enough for 99.98% of the pages
(https://httparchive.org/reports/state-of-the-web?start=latest#reqTotal)
even in Chrome.

5 years agoAdded $connection_time variable.
Maxim Dounin [Wed, 7 Apr 2021 21:16:17 +0000 (00:16 +0300)]
Added $connection_time variable.

5 years agoIntroduced the "keepalive_time" directive.
Maxim Dounin [Wed, 7 Apr 2021 21:15:48 +0000 (00:15 +0300)]
Introduced the "keepalive_time" directive.

Similar to lingering_time, it limits total connection lifetime before
keepalive is switched off.  The default is 1 hour, which is close to
the total maximum connection lifetime possible with default
keepalive_requests and keepalive_timeout.

5 years agoQUIC: fixed ngx_quic_send_ack_range() function.
Vladimir Homutov [Wed, 7 Apr 2021 10:09:26 +0000 (13:09 +0300)]
QUIC: fixed ngx_quic_send_ack_range() function.

Created frame was not added to the output queue.

5 years agoHTTP/2: relaxed PRIORITY frames limit.
Maxim Dounin [Tue, 6 Apr 2021 23:03:29 +0000 (02:03 +0300)]
HTTP/2: relaxed PRIORITY frames limit.

Firefox uses several idle streams for PRIORITY frames[1], and
"http2_max_concurrent_streams 1;" results in "client sent too many
PRIORITY frames" errors when a connection is established by Firefox.

Fix is to relax the PRIORITY frames limit to use at least 100 as
the initial value (which is the recommended by the HTTP/2 protocol
minimum limit on the number of concurrent streams, so it is not
unreasonable for clients to assume that similar number of idle streams
can be used for prioritization).

[1] https://hg.mozilla.org/mozilla-central/file/32a9e6e145d6e3071c3993a20bb603a2f388722b/netwerk/protocol/http/Http2Stream.cpp#l1270

5 years agoConfigure: fixed --test-build-epoll on FreeBSD 13.
Maxim Dounin [Mon, 5 Apr 2021 17:14:16 +0000 (20:14 +0300)]
Configure: fixed --test-build-epoll on FreeBSD 13.

In FreeBSD 13, eventfd(2) was added, and this breaks build
with --test-build-epoll and without --with-file-aio.  Fix is
to move eventfd(2) detection to auto/os/linux, as it is used
only on Linux as a notification mechanism for epoll().

5 years agoQUIC: fixed debug message macro.
Vladimir Homutov [Mon, 5 Apr 2021 08:35:46 +0000 (11:35 +0300)]
QUIC: fixed debug message macro.

5 years agoQUIC: added error codes and messages from latest drafts.
Vladimir Homutov [Mon, 5 Apr 2021 08:31:03 +0000 (11:31 +0300)]
QUIC: added error codes and messages from latest drafts.

The AEAD_LIMIT_REACHED was addeded in draft-31.
The NO_VIABLE_PATH was added in draft-33.

5 years agoHTTP/3: keepalive_time support.
Sergey Kandaurov [Fri, 16 Apr 2021 16:42:03 +0000 (19:42 +0300)]
HTTP/3: keepalive_time support.

5 years agoMerged with the default branch.
Sergey Kandaurov [Fri, 16 Apr 2021 16:35:55 +0000 (19:35 +0300)]
Merged with the default branch.

5 years agoHTTP/3: removed h3scf->quic leftover after 0d2b2664b41c.
Sergey Kandaurov [Mon, 12 Apr 2021 09:30:30 +0000 (12:30 +0300)]
HTTP/3: removed h3scf->quic leftover after 0d2b2664b41c.

5 years agoQUIC: fixed memory leak in ngx_hkdf_extract()/ngx_hkdf_expand().
Sergey Kandaurov [Wed, 7 Apr 2021 12:14:41 +0000 (15:14 +0300)]
QUIC: fixed memory leak in ngx_hkdf_extract()/ngx_hkdf_expand().

This fixes leak on successful path when built with OpenSSL.

5 years agoGzip: updated handling of zlib variant from Intel.
Maxim Dounin [Mon, 5 Apr 2021 01:07:17 +0000 (04:07 +0300)]
Gzip: updated handling of zlib variant from Intel.

In current versions (all versions based on zlib 1.2.11, at least
since 2018) it no longer uses 64K hash and does not force window
bits to 13 if it is less than 13.  That is, it needs just 16 bytes
more memory than normal zlib, so these bytes are simply added to
the normal size calculation.

5 years agoGzip: support for zlib-ng.
Maxim Dounin [Mon, 5 Apr 2021 01:06:58 +0000 (04:06 +0300)]
Gzip: support for zlib-ng.

5 years agoVersion bump.
Maxim Dounin [Mon, 5 Apr 2021 01:03:10 +0000 (04:03 +0300)]
Version bump.

5 years agorelease-1.19.9 tag
Maxim Dounin [Tue, 30 Mar 2021 14:47:11 +0000 (17:47 +0300)]
release-1.19.9 tag

5 years agonginx-1.19.9-RELEASE release-1.19.9
Maxim Dounin [Tue, 30 Mar 2021 14:47:11 +0000 (17:47 +0300)]
nginx-1.19.9-RELEASE

5 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 30 Mar 2021 14:44:36 +0000 (17:44 +0300)]
Updated OpenSSL used for win32 builds.

5 years agoFixed handling of already closed connections.
Maxim Dounin [Sun, 28 Mar 2021 14:45:39 +0000 (17:45 +0300)]
Fixed handling of already closed connections.

In limit_req, auth_delay, and upstream code to check for broken
connections, tests for possible connection close by the client
did not work if the connection was already closed when relevant
event handler was set.  This happened because there were no additional
events in case of edge-triggered event methods, and read events
were disabled in case of level-triggered ones.

Fix is to explicitly post a read event if the c->read->ready flag
is set.

5 years agoUpstream: fixed broken connection check with eventport.
Maxim Dounin [Sun, 28 Mar 2021 14:45:37 +0000 (17:45 +0300)]
Upstream: fixed broken connection check with eventport.

For connection close to be reported with eventport on Solaris,
ngx_handle_read_event() needs to be called.

5 years agoUpstream: fixed non-buffered proxying with eventport.
Maxim Dounin [Sun, 28 Mar 2021 14:45:35 +0000 (17:45 +0300)]
Upstream: fixed non-buffered proxying with eventport.

For new data to be reported with eventport on Solaris,
ngx_handle_read_event() needs to be called after reading response
headers.  To do so, ngx_http_upstream_process_non_buffered_upstream()
now called unconditionally if there are no prepread data.  This
won't cause any read() syscalls as long as upstream connection
is not ready for reading (c->read->ready is not set), but will result
in proper handling of all events.

5 years agoResolver: added missing event handling after reading.
Maxim Dounin [Sun, 28 Mar 2021 14:45:31 +0000 (17:45 +0300)]
Resolver: added missing event handling after reading.

If we need to be notified about further events, ngx_handle_read_event()
needs to be called after a read event is processed.  Without this,
an event can be removed from the kernel and won't be reported again,
notably when using oneshot event methods, such as eventport on Solaris.

While here, error handling is also added, similar to one present in
ngx_resolver_tcp_read().  This is not expected to make a difference
and mostly added for consistency.

5 years agoEvents: fixed "port_dissociate() failed" alerts with eventport.
Maxim Dounin [Sun, 28 Mar 2021 14:45:29 +0000 (17:45 +0300)]
Events: fixed "port_dissociate() failed" alerts with eventport.

If an attempt is made to delete an event which was already reported,
port_dissociate() returns an error.  Fix is avoid doing anything if
ev->active is not set.

Possible alternative approach would be to avoid calling ngx_del_event()
at all if ev->active is not set.  This approach, however, will require
something else to re-add the other event of the connection, since both
read and write events are dissociated if an event is reported on a file
descriptor.  Currently ngx_eventport_del_event() re-associates write
event if called to delete read event, and vice versa.

5 years agoEvents: fixed expiration of timers in the past.
Maxim Dounin [Thu, 25 Mar 2021 22:44:59 +0000 (01:44 +0300)]
Events: fixed expiration of timers in the past.

If, at the start of an event loop iteration, there are any timers
in the past (including timers expiring now), the ngx_process_events()
function is called with zero timeout, and returns immediately even
if there are no events.  But the following code only calls
ngx_event_expire_timers() if time actually changed, so this results
in nginx spinning in the event loop till current time changes.

While such timers are not expected to appear under normal conditions,
as all such timers should be removed on previous event loop iterations,
they still can appear due to bugs, zero timeouts set in the configuration
(if this is not explicitly handled by the code), or due to external
time changes on systems without clock_gettime(CLOCK_MONOTONIC).

Fix is to call ngx_event_expire_timers() unconditionally.  Calling
it on each event loop iteration is not expected to be significant from
performance point of view, especially compared to a syscall in
ngx_process_events().

5 years agoHTTP/2: improved handling of "keepalive_timeout 0".
Maxim Dounin [Thu, 25 Mar 2021 22:44:57 +0000 (01:44 +0300)]
HTTP/2: improved handling of "keepalive_timeout 0".

Without explicit handling, a zero timer was actually added, leading to
multiple unneeded syscalls.  Further, sending GOAWAY frame early might
be beneficial for clients.

Reported by Sergey Kandaurov.

5 years agoCancel keepalive and lingering close on EOF better (ticket #2145).
Sergey Kandaurov [Wed, 24 Mar 2021 11:03:33 +0000 (14:03 +0300)]
Cancel keepalive and lingering close on EOF better (ticket #2145).

Unlike in 75e908236701, which added the logic to ngx_http_finalize_request(),
this change moves it to a more generic routine ngx_http_finalize_connection()
to cover cases when a request is finalized with NGX_DONE.

In particular, this fixes unwanted connection transition into the keepalive
state after receiving EOF while discarding request body.  With edge-triggered
event methods that means the connection will last for extra seconds as set in
the keepalive_timeout directive.