]> git.kaiwu.me - nginx.git/log
nginx.git
4 years agoQUIC: improved size calculation in ngx_quic_write_chain().
Roman Arutyunyan [Thu, 3 Feb 2022 18:29:05 +0000 (21:29 +0300)]
QUIC: improved size calculation in ngx_quic_write_chain().

Previously, size was calculated based on the number of input bytes processed
by the function.  Now only the copied bytes are considered.  This prevents
overlapping buffers from contributing twice to the overall written size.

4 years agoQUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov [Wed, 2 Feb 2022 12:57:08 +0000 (15:57 +0300)]
QUIC: do not arm loss detection timer if nothing was sent.

Notably, this became quite practicable after the recent fix in cd8018bc81a5.

Additionally, do not arm loss detection timer on connection termination.

4 years agoQUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov [Wed, 2 Feb 2022 11:16:48 +0000 (14:16 +0300)]
QUIC: fixed padding of initial packets in case of limited path.

Previously, non-padded initial packet could be sent as a result of the
following situation:

 - initial queue is not empty (so padding to 1200 is required)
 - handshake queue is not empty (so padding is to be added after h/s packet)
 - path is limited

If serializing handshake packet would violate path limit, such packet was
omitted, and the non-padded initial packet was sent.

The fix is to avoid sending the packet at all in such case.  This follows the
original intention introduced in c5155a0cb12f.

4 years agoQUIC: do not declare SSL buffering, it's not used.
Sergey Kandaurov [Tue, 1 Feb 2022 17:46:32 +0000 (20:46 +0300)]
QUIC: do not declare SSL buffering, it's not used.

No functional changes.

4 years agoQUIC: improved debug logging.
Vladimir Homutov [Tue, 1 Feb 2022 12:43:56 +0000 (15:43 +0300)]
QUIC: improved debug logging.

 - wording in log->action is adjusted to match function names.

 - connection close steps are made obvious and start with "quic close" prefix:
     *1 quic close initiated rc:-4
     *1 quic close silent drain:0 timedout:1
     *1 quic close resumed rc:-1
     *1 quic close resumed rc:-1
     *1 quic close resumed rc:-4
     *1 quic close completed

   this makes it easy to understand if particular "close" record is an initial
   cause or lasting process, or the final one.

 - cases of close without quic connection now logged as "packet rejected":
     *14 quic run
     *14 quic packet rx long flags:ec version:1
     *14 quic packet rx hs len:61
     *14 quic packet rx dcid len:20 00000000000002c32f60e4aa2b90a64a39dc4228
     *14 quic packet rx scid len:8 81190308612cd019
     *14 quic expected initial, got handshake
     *14 quic packet done rc:-1 level:hs decr:0 pn:0 perr:0
     *14 quic packet rejected rc:-1, cleanup connection
     *14 reusable connection: 0

   this makes it easy to spot early packet rejection and avoid confuse with
   quic connection closing (which in fact was not even created).

 - packet processing summary now uses same prefix "quic packet done rc:"

 - added debug to places where packet was rejected without any reason logged

4 years agoQUIC: got rid of hash symbol in backup and logging.
Vladimir Homutov [Fri, 28 Jan 2022 11:57:33 +0000 (14:57 +0300)]
QUIC: got rid of hash symbol in backup and logging.

Now all objectes with sequence number (i.e. sockets, connection ids and
paths) are logged as "foo seq:N".

4 years agoQUIC: dead code removed.
Vladimir Homutov [Tue, 1 Feb 2022 10:01:10 +0000 (13:01 +0300)]
QUIC: dead code removed.

The ngx_quic_parse_packet() now returns NGX_OK, NGX_ERROR (parsing failed)
and NGX_ABORT (unsupported version).

4 years agoQUIC: merged ngx_quic_close_quic() and ngx_quic_close_connection().
Vladimir Homutov [Tue, 1 Feb 2022 10:05:38 +0000 (13:05 +0300)]
QUIC: merged ngx_quic_close_quic() and ngx_quic_close_connection().

The separate ngx_quic_close_quic() doesn't make much sense.

4 years agoQUIC: revised ngx_quic_handle_datagram() error codes.
Vladimir Homutov [Tue, 1 Feb 2022 11:35:31 +0000 (14:35 +0300)]
QUIC: revised ngx_quic_handle_datagram() error codes.

The NGX_DECLINED is replaced with NGX_DONE to match closer to return code
of ngx_quic_handle_packet() and ngx_quic_close_connection() rc argument.

The ngx_quic_close_connection() rc code is used only when quic connection
exists, thus anything goes if qc == NULL.

The ngx_quic_handle_datagram() does not return NG_OK in cases when quic
connection is not yet created.

4 years agoQUIC: stream event setting function.
Roman Arutyunyan [Wed, 26 Jan 2022 09:01:31 +0000 (12:01 +0300)]
QUIC: stream event setting function.

The function ngx_quic_set_event() is now called instead of posting events
directly.

4 years agoQUIC: style.
Roman Arutyunyan [Mon, 31 Jan 2022 15:09:03 +0000 (18:09 +0300)]
QUIC: style.

4 years agoHTTP/3: proper uni stream closure detection.
Roman Arutyunyan [Mon, 31 Jan 2022 06:46:30 +0000 (09:46 +0300)]
HTTP/3: proper uni stream closure detection.

Previously, closure detection for server-initiated uni streams was not properly
implemented.  Instead, HTTP/3 code relied on QUIC code posting the read event
and setting rev->error when it needed to close the stream.  Then, regular
uni stream read handler called c->recv() and received error, which closed the
stream.  This was an ad-hoc solution.  If, for whatever reason, the read
handler was called earlier, c->recv() would return 0, which would also close
the stream.

Now server-initiated uni streams have a separate read event handler for
tracking stream closure.  The handler calls c->recv(), which normally returns
0, but may return error in case of closure.

4 years agoQUIC: introduced explicit stream states.
Roman Arutyunyan [Mon, 31 Jan 2022 06:46:02 +0000 (09:46 +0300)]
QUIC: introduced explicit stream states.

This allows to eliminate the usage of stream connection event flags for tracking
stream state.

4 years agoHTTP/3: delayed Insert Count Increment instruction.
Roman Arutyunyan [Thu, 27 Jan 2022 09:20:47 +0000 (12:20 +0300)]
HTTP/3: delayed Insert Count Increment instruction.

Sending the instruction is delayed until the end of the current event cycle.
Delaying the instruction is allowed by quic-qpack-21, section 2.2.2.3.
The goal is to reduce the amount of data sent back to client by accumulating
several inserts in one instruction and sometimes not sending the instruction at
all, if Section Acknowledgement was sent just before it.

4 years agoQUIC: allowed main QUIC connection for some operations.
Roman Arutyunyan [Mon, 31 Jan 2022 06:16:47 +0000 (09:16 +0300)]
QUIC: allowed main QUIC connection for some operations.

Operations like ngx_quic_open_stream(), ngx_http_quic_get_connection(),
ngx_http_v3_finalize_connection(), ngx_http_v3_shutdown_connection() used to
receive a QUIC stream connection.  Now they can receive the main QUIC
connection as well.  This is useful when calling them from a stream context.

4 years agoQUIC: limited SSL_set_quic_use_legacy_codepoint() API usage.
Sergey Kandaurov [Thu, 27 Jan 2022 10:14:01 +0000 (13:14 +0300)]
QUIC: limited SSL_set_quic_use_legacy_codepoint() API usage.

As advertised in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5,
it may be dropped once callers implementing the draft versions cycle out.

4 years agoQUIC: style.
Roman Arutyunyan [Wed, 26 Jan 2022 15:03:45 +0000 (18:03 +0300)]
QUIC: style.

4 years agoQUIC: fixed handling of initial source connection id.
Vladimir Homutov [Wed, 26 Jan 2022 12:48:12 +0000 (15:48 +0300)]
QUIC: fixed handling of initial source connection id.

This was broken in 1e2f4e9c8195.

While there, adjusted formatting of debug message with socket seqnum.

4 years agoREADME: updated link to nginx-devel mailman.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
README: updated link to nginx-devel mailman.

4 years agoREADME: updated info about incomplete features.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
README: updated info about incomplete features.

4 years agoREADME: updated to QUICv1.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
README: updated to QUICv1.

While here, removed old browsers tips.

4 years agoQUIC: set to standard TLS codepoint after draft versions removal.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
QUIC: set to standard TLS codepoint after draft versions removal.

This is to ease transition with oldish BoringSSL versions,
the default for SSL_set_quic_use_legacy_codepoint() has been
flipped in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5.

4 years agoQUIC: removed draft versions support.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
QUIC: removed draft versions support.

4 years agoHTTP/3: removed draft versions support in ALPN.
Sergey Kandaurov [Wed, 26 Jan 2022 11:15:40 +0000 (14:15 +0300)]
HTTP/3: removed draft versions support in ALPN.

4 years agoQUIC: changed debug message.
Roman Arutyunyan [Fri, 21 Jan 2022 08:20:18 +0000 (11:20 +0300)]
QUIC: changed debug message.

4 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 25 Jan 2022 20:42:48 +0000 (23:42 +0300)]
Merged with the default branch.

4 years agorelease-1.21.6 tag
Maxim Dounin [Tue, 25 Jan 2022 15:03:52 +0000 (18:03 +0300)]
release-1.21.6 tag

4 years agonginx-1.21.6-RELEASE release-1.21.6
Maxim Dounin [Tue, 25 Jan 2022 15:03:51 +0000 (18:03 +0300)]
nginx-1.21.6-RELEASE

4 years agoQUIC: fixed macro style.
Vladimir Homutov [Tue, 25 Jan 2022 12:48:05 +0000 (15:48 +0300)]
QUIC: fixed macro style.

4 years agoQUIC: fixed chain returned from ngx_quic_write_chain().
Roman Arutyunyan [Tue, 25 Jan 2022 06:45:50 +0000 (09:45 +0300)]
QUIC: fixed chain returned from ngx_quic_write_chain().

Previously, when input ended on a QUIC buffer boundary, input chain was not
advanced to the next buffer.  As a result, ngx_quic_write_chain() returned
a chain with an empty buffer instead of NULL.  This broke HTTP write filter,
preventing it from closing the HTTP request and eventually timing out.

Now input chain is always advanced to a buffer that has data, before checking
QUIC buffer boundary condition.

4 years agoSSL: always renewing tickets with TLSv1.3 (ticket #1892).
Maxim Dounin [Mon, 24 Jan 2022 14:18:50 +0000 (17:18 +0300)]
SSL: always renewing tickets with TLSv1.3 (ticket #1892).

Chrome only uses TLS session tickets once with TLS 1.3, likely following
RFC 8446 Appendix C.4 recommendation.  With OpenSSL, this works fine with
built-in session tickets, since these are explicitly renewed in case of
TLS 1.3 on each session reuse, but results in only two connections being
reused after an initial handshake when using ssl_session_ticket_key.

Fix is to always renew TLS session tickets in case of TLS 1.3 when using
ssl_session_ticket_key, similarly to how it is done by OpenSSL internally.

4 years agoContrib: vim syntax adjusted to save cpoptions (ticket #2276).
Maxim Dounin [Fri, 21 Jan 2022 21:28:51 +0000 (00:28 +0300)]
Contrib: vim syntax adjusted to save cpoptions (ticket #2276).

Line continuation as used in the syntax file might be broken if "compatible"
is set or "C" is added to cpoptions.  Fix is to set the "cpoptions" option
to vim default value at script start and restore it later, see
":help use-cpo-save".

4 years agoQUIC: removed stale declaration.
Vladimir Homutov [Fri, 21 Jan 2022 08:41:39 +0000 (11:41 +0300)]
QUIC: removed stale declaration.

The ngx_quic_get_unconnected_socket() was removed in 1e2f4e9c8195.

4 years agoQUIC: avoid logging error in case of version negotiation.
Vladimir Homutov [Sun, 23 Jan 2022 18:29:36 +0000 (21:29 +0300)]
QUIC: avoid logging error in case of version negotiation.

Previously, "early error" message was logged in this case.

4 years agoQUIC: additional limit for probing packets.
Vladimir Homutov [Thu, 20 Jan 2022 19:00:25 +0000 (22:00 +0300)]
QUIC: additional limit for probing packets.

RFC 9000, 9.3.  Responding to Connection Migration:
    An endpoint only changes the address to which it sends packets in
    response to the highest-numbered non-probing packet.

The patch extends this requirement to probing packets.  Although it may
seem excessive, it helps with mitigation of reply attacks (when an off-path
attacker has copied packet with PATH_CHALLENGE and uses different
addresses to exhaust available connection ids).

4 years agoCore: simplify reader lock release.
Pavel Pautov [Thu, 20 Jan 2022 01:37:34 +0000 (17:37 -0800)]
Core: simplify reader lock release.

4 years agoQUIC: reworked migration handling.
Vladimir Homutov [Wed, 19 Jan 2022 19:39:24 +0000 (22:39 +0300)]
QUIC: reworked migration handling.

The quic connection now holds active, backup and probe paths instead
of sockets.  The number of migration paths is now limited and cannot
be inflated by a bad client or an attacker.

The client id is now associated with path rather than socket. This allows
to simplify processing of output and connection ids handling.

New migration abandons any previously started migrations.  This allows to
free consumed client ids and request new for use in future migrations and
make progress in case when connection id limit is hit during migration.

A path now can be revalidated without losing its state.

The patch also fixes various issues with NAT rebinding case handling:
    - paths are now validated (previously, there was no validation
      and paths were left in limited state)
    - attempt to reuse id on different path is now again verified
      (this was broken in 40445fc7c403)
    - former path is now validated in case of apparent migration

4 years agoQUIC: the "quic_active_connection_id_limit" directive.
Vladimir Homutov [Tue, 18 Jan 2022 09:49:55 +0000 (12:49 +0300)]
QUIC: the "quic_active_connection_id_limit" directive.

The directive sets corresponding transport parameter and limits number of
created client ids.

4 years agoSSL: free pkey on SSL_CTX_set0_tmp_dh_pkey() failure.
Sergey Kandaurov [Mon, 17 Jan 2022 14:05:12 +0000 (17:05 +0300)]
SSL: free pkey on SSL_CTX_set0_tmp_dh_pkey() failure.

The behaviour was changed in OpenSSL 3.0.1:
https://git.openssl.org/?p=openssl.git;a=commitdiff;h=bf17b7b

4 years agoQUIC: introduced function ngx_quic_split_chain().
Roman Arutyunyan [Mon, 17 Jan 2022 11:39:04 +0000 (14:39 +0300)]
QUIC: introduced function ngx_quic_split_chain().

The function splits a buffer at given offset.  The function is now
called from ngx_quic_read_chain() and ngx_quic_write_chain(), which
simplifies both functions.

4 years agoQUIC: fixed format specifier after 3789f4a56d65.
Roman Arutyunyan [Sat, 15 Jan 2022 21:28:13 +0000 (00:28 +0300)]
QUIC: fixed format specifier after 3789f4a56d65.

4 years agoQUIC: return written size from ngx_quic_write_chain().
Roman Arutyunyan [Thu, 13 Jan 2022 08:34:42 +0000 (11:34 +0300)]
QUIC: return written size from ngx_quic_write_chain().

This allows to escape calculating it before calling the function.

4 years agoREADME: documented QuicTLS support.
Sergey Kandaurov [Thu, 13 Jan 2022 13:56:07 +0000 (16:56 +0300)]
README: documented QuicTLS support.

4 years agoQUIC: removed ngx_send_lowat() check for QUIC connections.
Sergey Kandaurov [Thu, 13 Jan 2022 12:57:21 +0000 (15:57 +0300)]
QUIC: removed ngx_send_lowat() check for QUIC connections.

After 9ae239d2547d, ngx_quic_handle_write_event() no longer runs into
ngx_send_lowat() for QUIC connections, so the check became excessive.
It is assumed that external modules operating with SO_SNDLOWAT
(I'm not aware of any) should do this check on their own.

4 years agoHTTP/3: removed useless warning regarding OpenSSL library.
Sergey Kandaurov [Thu, 13 Jan 2022 12:57:15 +0000 (15:57 +0300)]
HTTP/3: removed useless warning regarding OpenSSL library.

After 0e6528551f26, it became impossible to run into this path.

4 years agoQUIC: fixed handling stream input buffers.
Roman Arutyunyan [Thu, 13 Jan 2022 08:23:53 +0000 (11:23 +0300)]
QUIC: fixed handling stream input buffers.

Previously, ngx_quic_write_chain() treated each input buffer as a memory
buffer, which is not always the case.  Special buffers were not skipped, which
is especially important when hitting the input byte limit.

The issue manifested itself with ngx_quic_write_chain() returning a non-empty
chain consisting of a special last_buf buffer when called from QUIC stream
send_chain().  In order for this to happen, input byte limit should be equal to
the chain length, and the input chain should end with an empty last_buf buffer.
An easy way to achieve this is the following:

  location /empty {
      return 200;
  }

When this non-empty chain was returned from send_chain(), it signalled to the
caller that input was blocked, while in fact it wasn't.  This prevented HTTP
request from finalization, which prevented QUIC from sending STREAM FIN to
the client.  The QUIC stream was then reset after a timeout.

Now special buffers are skipped and send_chain() returns NULL in the case
above, which signals to the caller a successful operation.

Also, original byte limit is now passed to ngx_quic_write_chain() from
send_chain() instead of actual chain length to make sure it's never zero.

4 years agoQUIC: fixed handling STREAM FIN.
Roman Arutyunyan [Tue, 11 Jan 2022 15:57:02 +0000 (18:57 +0300)]
QUIC: fixed handling STREAM FIN.

Previously, when a STREAM FIN frame with no data bytes was received after all
prior stream data were already read by the application layer, the frame was
ignored and eof was not reported to the application.

4 years agoHTTP/3: set c->error on read error in ngx_http_test_reading().
Roman Arutyunyan [Wed, 12 Jan 2022 08:57:46 +0000 (11:57 +0300)]
HTTP/3: set c->error on read error in ngx_http_test_reading().

Similar to other error/eof cases.

4 years agoHTTP/3: simplified code.
Roman Arutyunyan [Wed, 12 Jan 2022 08:57:06 +0000 (11:57 +0300)]
HTTP/3: simplified code.

4 years agoQUIC: modified HTTP version test.
Roman Arutyunyan [Wed, 12 Jan 2022 08:54:39 +0000 (11:54 +0300)]
QUIC: modified HTTP version test.

The new condition produces smaller diff to the default branch and is similar to
HTTP/2 case.

4 years agoAvoid sending "Connection: keep-alive" when shutting down.
Maxim Dounin [Mon, 10 Jan 2022 23:23:49 +0000 (02:23 +0300)]
Avoid sending "Connection: keep-alive" when shutting down.

When a worker process is shutting down, keepalive is not used: this is checked
before the ngx_http_set_keepalive() call in ngx_http_finalize_connection().
Yet the "Connection: keep-alive" header was still sent, even if we know that
the worker process is shutting down, potentially resulting in additional
requests being sent to the connection which is going to be closed anyway.
While clients are expected to be able to handle asynchronous close events
(see ticket #1022), it is certainly possible to send the "Connection: close"
header instead, informing the client that the connection is going to be closed
and potentially saving some unneeded work.

With this change, we additionally check for worker process shutdown just
before sending response headers, and disable keepalive accordingly.

4 years agoHTTP/3: improved processing of multiple Cookie field lines.
Sergey Kandaurov [Thu, 30 Dec 2021 09:59:32 +0000 (12:59 +0300)]
HTTP/3: improved processing of multiple Cookie field lines.

As per draft-ietf-quic-http, 4.1.1.2, and similar to HTTP/2 specification,
they ought to be concatenated.  This closely follows ngx_http_v2_module.

4 years agoEvents: fixed balancing between workers with EPOLLEXCLUSIVE.
Maxim Dounin [Wed, 29 Dec 2021 22:08:46 +0000 (01:08 +0300)]
Events: fixed balancing between workers with EPOLLEXCLUSIVE.

Linux with EPOLLEXCLUSIVE usually notifies only the process which was first
to add the listening socket to the epoll instance.  As a result most of the
connections are handled by the first worker process (ticket #2285).  To fix
this, we re-add the socket periodically, so other workers will get a chance
to accept connections.

4 years agoVersion bump.
Maxim Dounin [Wed, 29 Dec 2021 19:59:53 +0000 (22:59 +0300)]
Version bump.

4 years agoStyle.
Roman Arutyunyan [Wed, 29 Dec 2021 12:33:51 +0000 (15:33 +0300)]
Style.

4 years agoMerged with the default branch.
Sergey Kandaurov [Wed, 29 Dec 2021 12:17:26 +0000 (15:17 +0300)]
Merged with the default branch.

4 years agorelease-1.21.5 tag
Maxim Dounin [Tue, 28 Dec 2021 15:28:38 +0000 (18:28 +0300)]
release-1.21.5 tag

4 years agonginx-1.21.5-RELEASE release-1.21.5
Maxim Dounin [Tue, 28 Dec 2021 15:28:37 +0000 (18:28 +0300)]
nginx-1.21.5-RELEASE

4 years agoUpdated OpenSSL and PCRE used for win32 builds.
Maxim Dounin [Tue, 28 Dec 2021 14:56:16 +0000 (17:56 +0300)]
Updated OpenSSL and PCRE used for win32 builds.

4 years agoSupport for sendfile(SF_NOCACHE).
Maxim Dounin [Mon, 27 Dec 2021 16:49:26 +0000 (19:49 +0300)]
Support for sendfile(SF_NOCACHE).

The SF_NOCACHE flag, introduced in FreeBSD 11 along with the new non-blocking
sendfile() implementation by glebius@, makes it possible to use sendfile()
along with the "directio" directive.

4 years agoSSL: SSL_sendfile(SF_NODISKIO) support.
Maxim Dounin [Mon, 27 Dec 2021 16:48:42 +0000 (19:48 +0300)]
SSL: SSL_sendfile(SF_NODISKIO) support.

4 years agoSimplified sendfile(SF_NODISKIO) usage.
Maxim Dounin [Mon, 27 Dec 2021 16:48:33 +0000 (19:48 +0300)]
Simplified sendfile(SF_NODISKIO) usage.

Starting with FreeBSD 11, there is no need to use AIO operations to preload
data into cache for sendfile(SF_NODISKIO) to work.  Instead, sendfile()
handles non-blocking loading data from disk by itself.  It still can, however,
return EBUSY if a page is already being loaded (for example, by a different
process).  If this happens, we now post an event for the next event loop
iteration, so sendfile() is retried "after a short period", as manpage
recommends.

The limit of the number of EBUSY tolerated without any progress is preserved,
but now it does not result in an alert, since on an idle system event loop
iteration might be very short and EBUSY can happen many times in a row.
Instead, SF_NODISKIO is simply disabled for one call once the limit is
reached.

With this change, sendfile(SF_NODISKIO) is now used automatically as long as
sendfile() is enabled, and no longer requires "aio on;".

4 years agoRemoved "aio sendfile", deprecated since 1.7.11.
Maxim Dounin [Mon, 27 Dec 2021 16:47:05 +0000 (19:47 +0300)]
Removed "aio sendfile", deprecated since 1.7.11.

4 years agoQUIC: got rid of ngx_quic_create_temp_socket().
Vladimir Homutov [Mon, 27 Dec 2021 10:49:56 +0000 (13:49 +0300)]
QUIC: got rid of ngx_quic_create_temp_socket().

It was mostly copy of the ngx_quic_listen().  Now ngx_quic_listen() no
longer generates server id and increments seqnum.  Instead, the server
id is generated when the socket is created.

The ngx_quic_alloc_socket() function is renamed to ngx_quic_create_socket().

4 years agoFixed a mismerge in 5c86189a1c1b.
Ruslan Ermilov [Tue, 28 Dec 2021 12:01:02 +0000 (15:01 +0300)]
Fixed a mismerge in 5c86189a1c1b.

4 years agoQUIC: renamed input handling functions.
Roman Arutyunyan [Mon, 27 Dec 2021 13:15:28 +0000 (16:15 +0300)]
QUIC: renamed input handling functions.

Now these functions have names ngx_quic_handle_XXX():

  - ngx_quic_process_stateless_reset() -> ngx_quic_handle_stateless_reset()
  - ngx_quic_input() -> ngx_quic_handle_datagram()
  - ngx_quic_process_packet() -> ngx_quic_handle_packet()
  - ngx_quic_process_payload() -> ngx_quic_handle_payload()

4 years agoQUIC: fixed format specifier after 6ccf3867959a.
Roman Arutyunyan [Tue, 28 Dec 2021 10:50:01 +0000 (13:50 +0300)]
QUIC: fixed format specifier after 6ccf3867959a.

4 years agoQUIC: fixed config test with bpf (ticket #2292).
Vladimir Homutov [Tue, 28 Dec 2021 10:24:58 +0000 (13:24 +0300)]
QUIC: fixed config test with bpf (ticket #2292).

The SO_REUSEPORT socket option is not set during configuration testing,
thus making the further module initialization impossible and meaningless.

4 years agoCore: added NGX_REGEX_MULTILINE for 3rd party modules.
Maxim Dounin [Fri, 24 Dec 2021 22:07:18 +0000 (01:07 +0300)]
Core: added NGX_REGEX_MULTILINE for 3rd party modules.

Notably, NAXSI is known to misuse ngx_regex_compile() with rc.options set
to PCRE_CASELESS | PCRE_MULTILINE.  With PCRE2 support, and notably binary
compatibility changes, it is no longer possible to set PCRE[2]_MULTILINE
option without using proper interface.  To facilitate correct usage,
this change adds the NGX_REGEX_MULTILINE option.

4 years agoPCRE2 and PCRE binary compatibility.
Maxim Dounin [Fri, 24 Dec 2021 22:07:16 +0000 (01:07 +0300)]
PCRE2 and PCRE binary compatibility.

With this change, dynamic modules using nginx regex interface can be used
regardless of the variant of the PCRE library nginx was compiled with.

If a module is compiled with different PCRE library variant, in case of
ngx_regex_exec() errors it will report wrong function name in error
messages.  This is believed to be tolerable, given that fixing this will
require interface changes.

4 years agoPCRE2 library support.
Maxim Dounin [Fri, 24 Dec 2021 22:07:15 +0000 (01:07 +0300)]
PCRE2 library support.

The PCRE2 library is now used by default if found, instead of the
original PCRE library.  If needed for some reason, this can be disabled
with the --without-pcre2 configure option.

To make it possible to specify paths to the library and include files
via --with-cc-opt / --with-ld-opt, the library is first tested without
any additional paths and options.  If this fails, the pcre2-config script
is used.

Similarly to the original PCRE library, it is now possible to build PCRE2
from sources with nginx configure, by using the --with-pcre= option.
It automatically detects if PCRE or PCRE2 sources are provided.

Note that compiling PCRE2 10.33 and later requires inttypes.h.  When
compiling on Windows with MSVC, inttypes.h is only available starting
with MSVC 2013.  In older versions some replacement needs to be provided
("echo '#include <stdint.h>' > pcre2-10.xx/src/inttypes.h" is good enough
for MSVC 2010).

The interface on nginx side remains unchanged.

4 years agoConfigure: simplified PCRE compilation.
Maxim Dounin [Fri, 24 Dec 2021 22:07:14 +0000 (01:07 +0300)]
Configure: simplified PCRE compilation.

Removed ICC-specific PCRE optimizations which tried to link with PCRE
object files instead of the library.  Made compiler-specific code
minimal.

4 years agoCore: ngx_regex.c style cleanup.
Maxim Dounin [Fri, 24 Dec 2021 22:07:12 +0000 (01:07 +0300)]
Core: ngx_regex.c style cleanup.

Notably, ngx_pcre_pool and ngx_pcre_studies are renamed to ngx_regex_pool
and ngx_regex_studies, respectively.

4 years agoCore: fixed ngx_pcre_studies cleanup.
Maxim Dounin [Fri, 24 Dec 2021 22:07:10 +0000 (01:07 +0300)]
Core: fixed ngx_pcre_studies cleanup.

If a configuration parsing fails for some reason, ngx_regex_module_init()
is not called, and ngx_pcre_studies remained set despite the fact that
the pool it was allocated from is already freed.  This might result in
a segmentation fault during runtime regular expression compilation, such
as in SSI, for example, in the single process mode, or if a worker process
died and was respawned from a master process in such an inconsistent state.

Fix is to clear ngx_pcre_studies from the pool cleanup handler (which is
anyway used to free JIT-compiled patterns).

4 years agoQUIC: refactored buffer allocation, spliting and freeing.
Roman Arutyunyan [Fri, 24 Dec 2021 15:39:22 +0000 (18:39 +0300)]
QUIC: refactored buffer allocation, spliting and freeing.

Previously, buffer lists was used to track used buffers.  Now reference
counter is used instead.  The new implementation is simpler and faster with
many buffer clones.

4 years agoMoved Huffman coding out of HTTP/2.
Ruslan Ermilov [Tue, 21 Dec 2021 04:54:16 +0000 (07:54 +0300)]
Moved Huffman coding out of HTTP/2.

ngx_http_v2_huff_decode.c and ngx_http_v2_huff_encode.c are renamed
to ngx_http_huff_decode.c and ngx_http_huff_encode.c.

4 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Mon, 20 Dec 2021 18:02:48 +0000 (20:02 +0200)]
Contrib: vim syntax, update core and 3rd party module directives.

4 years agoQUIC: removed ngx_quic_copy_chain().
Roman Arutyunyan [Thu, 16 Dec 2021 14:07:11 +0000 (17:07 +0300)]
QUIC: removed ngx_quic_copy_chain().

The function is unused.

4 years agoQUIC: renamed buffer-related functions.
Roman Arutyunyan [Thu, 16 Dec 2021 14:06:35 +0000 (17:06 +0300)]
QUIC: renamed buffer-related functions.

ngx_quic_alloc_buf() -> ngx_quic_alloc_chain(),
ngx_quic_free_bufs() -> ngx_quic_free_chain(),
ngx_quic_trim_bufs() -> ngx_quic_trim_chain()

4 years agoQUIC: refactored ngx_quic_order_bufs() and ngx_quic_split_bufs().
Roman Arutyunyan [Fri, 24 Dec 2021 15:17:23 +0000 (18:17 +0300)]
QUIC: refactored ngx_quic_order_bufs() and ngx_quic_split_bufs().

They are replaced with ngx_quic_write_chain() and ngx_quic_read_chain().
These functions represent the API to data buffering.

The first function adds data of given size at given offset to the buffer.
Now it returns the unwritten part of the chain similar to c->send_chain().

The second function returns data of given size from the beginning of the buffer.
Its second argument and return value are swapped compared to
ngx_quic_split_bufs() to better match ngx_quic_write_chain().

Added, returned and stored data are regular ngx_chain_t/ngx_buf_t chains.
Missing data is marked with b->sync flag.

The functions are now used in both send and recv data chains in QUIC streams.

4 years agoQUIC: avoid excessive buffer allocations in stream output.
Roman Arutyunyan [Fri, 24 Dec 2021 15:13:51 +0000 (18:13 +0300)]
QUIC: avoid excessive buffer allocations in stream output.

Previously, when a few bytes were send to a QUIC stream by the application, a
4K buffer was allocated for these bytes.  Then a STREAM frame was created and
that entire buffer was used as data for that frame.  The frame with the buffer
were in use up until the frame was acked by client.  Meanwhile, when more
bytes were send to the stream, more buffers were allocated and assigned as
data to newer STREAM frames.  In this scenario most buffer memory is unused.

Now the unused part of the stream output buffer is available for further
stream output while earlier parts of the buffer are waiting to be acked.
This is achieved by splitting the output buffer.

4 years agoQUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov [Mon, 27 Dec 2021 10:52:57 +0000 (13:52 +0300)]
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.

The output is always sent to the active path, which is stored in the
quic connection.  There is no need to pass it in arguments.

When output has to be send to to a specific path (in rare cases, such as
path probing), a separate method exists (ngx_quic_frame_sendto()).

4 years agoQUIC: refactored ngx_quic_validate_path().
Vladimir Homutov [Thu, 16 Dec 2021 08:49:08 +0000 (11:49 +0300)]
QUIC: refactored ngx_quic_validate_path().

The function now accepts path argument, as suggested by the name. Socket is
not really needed inside.

4 years agoQUIC: added missing check for backup path existence.
Vladimir Homutov [Thu, 16 Dec 2021 08:42:28 +0000 (11:42 +0300)]
QUIC: added missing check for backup path existence.

4 years agoMerged with the default branch.
Ruslan Ermilov [Fri, 24 Dec 2021 12:53:59 +0000 (15:53 +0300)]
Merged with the default branch.

4 years agoQUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan [Tue, 14 Dec 2021 13:24:20 +0000 (16:24 +0300)]
QUIC: added path limiting function ngx_quic_path_limit().

4 years agoQUIC: decoupled path state and limitation status.
Vladimir Homutov [Mon, 13 Dec 2021 06:48:33 +0000 (09:48 +0300)]
QUIC: decoupled path state and limitation status.

The path validation status and anti-amplification limit status is actually
two different variables.  It is possible that validating path should not
be limited (for example, when re-validating former path).

4 years agoQUIC: improved path validation.
Vladimir Homutov [Mon, 13 Dec 2021 14:27:29 +0000 (17:27 +0300)]
QUIC: improved path validation.

Previously, path was considered valid during arbitrary selected 10m timeout
since validation.  This is quite not what RFC 9000 says; the relevant
part is:

    An endpoint MAY skip validation of a peer address if that
    address has been seen recently.

The patch considers a path to be 'recently seen' if packets were received
during idle timeout.  If a packet is received from the path that was seen
not so recently, such path is considered new, and anti-amplification
restrictions apply.

4 years agoQUIC: write and full stream shutdown support.
Roman Arutyunyan [Mon, 13 Dec 2021 11:49:42 +0000 (14:49 +0300)]
QUIC: write and full stream shutdown support.

Full stream shutdown is now called from stream cleanup handler instead of
explicitly sending frames.

4 years agoQUIC: simplified stream initialization.
Roman Arutyunyan [Fri, 10 Dec 2021 16:43:50 +0000 (19:43 +0300)]
QUIC: simplified stream initialization.

After creation, a client stream is added to qc->streams.uninitialized queue.
After initialization it's removed from the queue.  If a stream is never
initialized, it is freed in ngx_quic_close_streams().  Stream initializer
is now set as read event handler in stream connection.

Previously qc->streams.uninitialized was used only for delayed stream
initialization.

The change makes it possible not to handle separately the case of a new stream
in stream-related frame handlers.  It makes these handlers simpler since new
streams and existing streams are now handled by the same code.

4 years agoHTTP/2: fixed sendfile() aio handling.
Maxim Dounin [Thu, 25 Nov 2021 19:02:10 +0000 (22:02 +0300)]
HTTP/2: fixed sendfile() aio handling.

With sendfile() in threads ("aio threads; sendfile on;"), client connection
can block on writing, waiting for sendfile() to complete.  In HTTP/2 this
might result in the request hang, since an attempt to continue processing
in thread event handler will call request's write event handler, which
is usually stopped by ngx_http_v2_send_chain(): it does nothing if there
are no additional data and stream->queued is set.  Further, HTTP/2 resets
stream's c->write->ready to 0 if writing blocks, so just fixing
ngx_http_v2_send_chain() is not enough.

Can be reproduced with test suite on Linux with:

TEST_NGINX_GLOBALS_HTTP="aio threads; sendfile on;" prove h2*.t

The following tests currently fail: h2_keepalive.t, h2_priority.t,
h2_proxy_max_temp_file_size.t, h2.t, h2_trailers.t.

Similarly, sendfile() with AIO preloading on FreeBSD can block as well,
with similar results.  This is, however, harder to reproduce, especially
on modern FreeBSD systems, since sendfile() usually does not return EBUSY.

Fix is to modify ngx_http_v2_send_chain() so it actually tries to send
data to the main connection when called, and to make sure that
c->write->ready is set by the relevant event handlers.

4 years agoHTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin [Thu, 25 Nov 2021 19:02:05 +0000 (22:02 +0300)]
HTTP/2: fixed "task already active" with sendfile in threads.

With sendfile in threads, "task already active" alerts might appear in logs
if a write event happens on the main HTTP/2 connection, triggering a sendfile
in threads while another thread operation is already running.  Observed
with "aio threads; aio_write on; sendfile on;" and with thread event handlers
modified to post a write event to the main HTTP/2 connection (though can
happen without any modifications).

Similarly, sendfile() with AIO preloading on FreeBSD can trigger duplicate
aio operation, resulting in "second aio post" alerts.  This is, however,
harder to reproduce, especially on modern FreeBSD systems, since sendfile()
usually does not return EBUSY.

Fix is to avoid starting a sendfile operation if other thread operation
is active by checking r->aio in the thread handler (and, similarly, in
aio preload handler).  The added check also makes duplicate calls protection
redundant, so it is removed.

4 years agoQUIC: post stream events instead of calling their handlers.
Roman Arutyunyan [Tue, 23 Nov 2021 18:39:51 +0000 (21:39 +0300)]
QUIC: post stream events instead of calling their handlers.

This potentially reduces the number of handler calls.

4 years agoQUIC: removed configure time test for BPF sockhash.
Ruslan Ermilov [Thu, 9 Dec 2021 12:30:50 +0000 (15:30 +0300)]
QUIC: removed configure time test for BPF sockhash.

The test verifies kernel version on a build machine,
but actually used kernel may be different.

4 years agoQUIC: configure cleanup.
Ruslan Ermilov [Thu, 9 Dec 2021 12:30:01 +0000 (15:30 +0300)]
QUIC: configure cleanup.

Renamed and removed some macros.

4 years agoQUIC: added missing frame initialization.
Vladimir Homutov [Mon, 6 Dec 2021 08:04:55 +0000 (11:04 +0300)]
QUIC: added missing frame initialization.

Currently, all used fields are initialized, but usage may change in future.

4 years agoQUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov [Thu, 9 Dec 2021 09:40:14 +0000 (12:40 +0300)]
QUIC: refactored ngx_quic_frame_sendto() function.

The function now takes path as an argument to deal with associated
restrictions and update sent counter.

4 years agoQUIC: fixed e06283038ec8 mis-merge.
Sergey Kandaurov [Thu, 9 Dec 2021 08:15:25 +0000 (11:15 +0300)]
QUIC: fixed e06283038ec8 mis-merge.

The NGX_HTTP_QUIC macro was removed in 33226ac61076.

4 years agoHTTP/3: cleanup after "listen .. quic" removal in be08b858086a.
Sergey Kandaurov [Wed, 8 Dec 2021 14:04:56 +0000 (17:04 +0300)]
HTTP/3: cleanup after "listen .. quic" removal in be08b858086a.

4 years agoQUIC: updated README.
Vladimir Homutov [Tue, 7 Dec 2021 13:07:47 +0000 (16:07 +0300)]
QUIC: updated README.

The ngx_http_quic_module is merged to ngx_http_v3_module.
The $quic variable no longer exists, it is replaced with $http3 variable.