]> git.kaiwu.me - nginx.git/log
nginx.git
5 years agoQUIC: consistent use of 12-byte buffers in nonce computation.
Sergey Kandaurov [Wed, 16 Jun 2021 14:54:21 +0000 (17:54 +0300)]
QUIC: consistent use of 12-byte buffers in nonce computation.

All supported cipher suites produce 96-bit IV (RFC 5116, 5.1, RFC 8439, 2.3).
This eliminates a few magic numbers and run-time overhead.

5 years agoQUIC: consistent use of 5-byte buffers for header protection.
Sergey Kandaurov [Wed, 16 Jun 2021 14:53:18 +0000 (17:53 +0300)]
QUIC: consistent use of 5-byte buffers for header protection.

The output buffer is now also of 5 bytes.  Header protection uses
stream ciphers, which don't produce extra output nor PKCS padding.

5 years agoQUIC: updated specification references.
Sergey Kandaurov [Wed, 16 Jun 2021 08:55:12 +0000 (11:55 +0300)]
QUIC: updated specification references.

This includes updating citations and further clarification.

5 years agoHTTP/3: client GOAWAY support.
Roman Arutyunyan [Fri, 11 Jun 2021 10:24:24 +0000 (13:24 +0300)]
HTTP/3: client GOAWAY support.

5 years agoHTTP/3: generate more H3_FRAME_UNEXPECTED.
Roman Arutyunyan [Fri, 11 Jun 2021 09:11:08 +0000 (12:11 +0300)]
HTTP/3: generate more H3_FRAME_UNEXPECTED.

As per quic-http-34, these are the cases when this error should be generated:

   If an endpoint receives a second SETTINGS frame
   on the control stream, the endpoint MUST respond with a connection
   error of type H3_FRAME_UNEXPECTED

   SETTINGS frames MUST NOT be sent on any stream other than the control
   stream.  If an endpoint receives a SETTINGS frame on a different
   stream, the endpoint MUST respond with a connection error of type
   H3_FRAME_UNEXPECTED.

   A client MUST NOT send a PUSH_PROMISE frame.  A server MUST treat the
   receipt of a PUSH_PROMISE frame as a connection error of type
   H3_FRAME_UNEXPECTED; see Section 8.

   The MAX_PUSH_ID frame is always sent on the control stream.  Receipt
   of a MAX_PUSH_ID frame on any other stream MUST be treated as a
   connection error of type H3_FRAME_UNEXPECTED.

   Receipt of an invalid sequence of frames MUST be treated as a
   connection error of type H3_FRAME_UNEXPECTED; see Section 8.  In
   particular, a DATA frame before any HEADERS frame, or a HEADERS or
   DATA frame after the trailing HEADERS frame, is considered invalid.

   A CANCEL_PUSH frame is sent on the control stream.  Receiving a
   CANCEL_PUSH frame on a stream other than the control stream MUST be
   treated as a connection error of type H3_FRAME_UNEXPECTED.

   The GOAWAY frame is always sent on the control stream.

5 years agoHTTP/3: reordered H3_MISSING_SETTINGS and H3_FRAME_UNEXPECTED.
Roman Arutyunyan [Fri, 11 Jun 2021 07:56:51 +0000 (10:56 +0300)]
HTTP/3: reordered H3_MISSING_SETTINGS and H3_FRAME_UNEXPECTED.

The quic-http-34 is ambiguous as to what error should be generated for the
first frame in control stream:

   Each side MUST initiate a single control stream at the beginning of
   the connection and send its SETTINGS frame as the first frame on this
   stream.  If the first frame of the control stream is any other frame
   type, this MUST be treated as a connection error of type
   H3_MISSING_SETTINGS.

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

   If a HEADERS frame is received on a control stream, the recipient MUST
   respond with a connection error of type H3_FRAME_UNEXPECTED.

Previously, H3_FRAME_UNEXPECTED had priority, but now H3_MISSING_SETTINGS has.
The arguments in the spec sound more compelling for H3_MISSING_SETTINGS.

5 years agoQUIC: improved errors readability.
Vladimir Homutov [Thu, 10 Jun 2021 20:17:51 +0000 (23:17 +0300)]
QUIC: improved errors readability.

5 years agoQUIC: persistent congestion calculation.
Vladimir Homutov [Wed, 9 Jun 2021 12:11:43 +0000 (15:11 +0300)]
QUIC: persistent congestion calculation.

According to RFC 9002 (quic-recovery) 7.6.

5 years agoQUIC: stream flow control refactored.
Roman Arutyunyan [Mon, 7 Jun 2021 07:12:46 +0000 (10:12 +0300)]
QUIC: stream flow control refactored.

- Function ngx_quic_control_flow() is introduced.  This functions does
both MAX_DATA and MAX_STREAM_DATA flow controls.  The function is called
from STREAM and RESET_STREAM frame handlers.  Previously, flow control
was only accounted for STREAM.  Also, MAX_DATA flow control was not accounted
at all.

- Function ngx_quic_update_flow() is introduced.  This function advances flow
control windows and sends MAX_DATA/MAX_STREAM_DATA.  The function is called
from RESET_STREAM frame handler, stream cleanup handler and stream recv()
handler.

5 years agoFixed SSL logging with lingering close.
Maxim Dounin [Tue, 1 Jun 2021 14:37:51 +0000 (17:37 +0300)]
Fixed SSL logging with lingering close.

Recent fixes to SSL shutdown with lingering close (554c6ae25ffc, 1.19.5)
broke logging of SSL variables.  To make sure logging of SSL variables
works properly, avoid freeing c->ssl when doing an SSL shutdown before
lingering close.

Reported by Reinis Rozitis
(http://mailman.nginx.org/pipermail/nginx/2021-May/060670.html).

5 years agoSSL: ngx_ssl_shutdown() rework.
Maxim Dounin [Tue, 1 Jun 2021 14:37:49 +0000 (17:37 +0300)]
SSL: ngx_ssl_shutdown() rework.

Instead of calling SSL_free() with each return point, introduced a single
place where cleanup happens.  As a positive side effect, this fixes two
potential memory leaks on ngx_handle_read_event() and ngx_handle_write_event()
errors where there were no SSL_free() calls (though unlikely practical,
as errors there are only expected to happen due to bugs or kernel issues).

5 years agoHTTP/3: undo 5a92523e50d3 after parser refactoring (e1eb7f4ca9f1).
Sergey Kandaurov [Tue, 1 Jun 2021 09:02:08 +0000 (12:02 +0300)]
HTTP/3: undo 5a92523e50d3 after parser refactoring (e1eb7f4ca9f1).

This is no longer needed after HTTP/3 request processing has moved
into its own function ngx_http_v3_process_header().

5 years agoHTTP/3: fixed parsing encoder insertions with empty header value.
Sergey Kandaurov [Tue, 1 Jun 2021 08:41:38 +0000 (11:41 +0300)]
HTTP/3: fixed parsing encoder insertions with empty header value.

When starting processing a new encoder instruction, the header state is not
memzero'ed because generally it's burdensome.  If the header value is empty,
this resulted in inserting a stale value left from the previous instruction.

Based on a patch by Zhiyong Sun.

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 agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Sun, 30 May 2021 09:26:00 +0000 (12:26 +0300)]
Contrib: vim syntax, update core and 3rd party module directives.

5 years agoCore: disabled SO_REUSEADDR on UDP sockets while testing config.
Maxim Dounin [Mon, 31 May 2021 13:36:51 +0000 (16:36 +0300)]
Core: disabled SO_REUSEADDR on UDP sockets while testing config.

On Linux, SO_REUSEADDR allows completely duplicate UDP sockets, so using
SO_REUSEADDR when testing configuration results in packets being dropped
if there is an existing traffic on the sockets being tested (ticket #2187).
While dropped packets are expected with UDP, it is better to avoid this
when possible.

With this change, SO_REUSEADDR is no longer set on datagram sockets when
testing configuration.

5 years agoCore: disabled cloning sockets when testing config (ticket #2188).
Maxim Dounin [Mon, 31 May 2021 13:36:37 +0000 (16:36 +0300)]
Core: disabled cloning sockets when testing config (ticket #2188).

Since we anyway do not set SO_REUSEPORT when testing configuration
(see ecb5cd305b06), trying to open additional sockets does not make much
sense, as all these additional sockets are expected to result in EADDRINUSE
errors from bind().  On the other hand, there are reports that trying
to open these sockets takes significant time under load: total configuration
testing time greater than 15s was observed in ticket #2188, compared to less
than 1s without load.

With this change, no additional sockets are opened during testing
configuration.

5 years agoVersion bump.
Maxim Dounin [Mon, 31 May 2021 13:36:12 +0000 (16:36 +0300)]
Version bump.

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.