]> git.kaiwu.me - nginx.git/log
nginx.git
3 years agoHTTP/3: insert count block timeout.
Roman Arutyunyan [Thu, 5 Jan 2023 15:03:22 +0000 (19:03 +0400)]
HTTP/3: insert count block timeout.

Previously, there was no timeout for a request stream blocked on insert count,
which could result in infinite wait.  Now client_header_timeout is set when
stream is first blocked.

3 years agoHTTP/3: trigger 400 (Bad Request) on stream error while blocked.
Roman Arutyunyan [Thu, 5 Jan 2023 14:15:46 +0000 (18:15 +0400)]
HTTP/3: trigger 400 (Bad Request) on stream error while blocked.

Previously, stream was closed with NGX_HTTP_CLOSE.  However, in a similar case
when recv() returns eof or error, status 400 is triggered.

3 years agoQUIC: set stream error flag on reset.
Roman Arutyunyan [Tue, 10 Jan 2023 13:42:40 +0000 (17:42 +0400)]
QUIC: set stream error flag on reset.

Now, when RESET_STREAM is sent or received, or when streams are closed,
stream connection error flag is set.  Previously, only stream state was
changed, which resulted in setting the error flag only after calling
recv()/send()/send_chain().  However, there are cases when none of these
functions is called, but it's still important to know if the stream is being
closed.  For example, when an HTTP/3 request stream is blocked on insert count,
receiving RESET_STREAM should trigger stream closure, which was not the case.

The change also fixes ngx_http_upstream_check_broken_connection() and
ngx_http_test_reading() with QUIC streams.

3 years agoQUIC: automatically add and never delete stream events.
Roman Arutyunyan [Tue, 10 Jan 2023 10:05:18 +0000 (14:05 +0400)]
QUIC: automatically add and never delete stream events.

Previously, stream events were added and deleted by ngx_handle_read_event() and
ngx_handle_write_event() in a way similar to level-triggered events.  However,
QUIC stream events are effectively edge-triggered and can stay active all time.
Moreover, the events are now active since the moment a stream is created.

3 years agoHTTP/3: fixed $connection_time.
Sergey Kandaurov [Tue, 10 Jan 2023 13:59:16 +0000 (17:59 +0400)]
HTTP/3: fixed $connection_time.

Previously, start_time wasn't set for a new stream.
The fix is to derive it from the parent connection.
Also it's used to simplify tracking keepalive_time.

3 years agoHTTP/3: handled insertion reference to a going to be evicted entry.
Roman Arutyunyan [Tue, 3 Jan 2023 12:24:45 +0000 (16:24 +0400)]
HTTP/3: handled insertion reference to a going to be evicted entry.

As per RFC 9204, section 3.2.2, a new entry can reference an entry in the
dynamic table that will be evicted when adding this new entry into the dynamic
table.

Previously, such inserts resulted in use-after-free since the old entry was
evicted before the insertion (ticket #2431).  Now it's evicted after the
insertion.

This change fixes Insert with Name Reference and Duplicate encoder instructions.

3 years agoMerged with the default branch.
Sergey Kandaurov [Mon, 2 Jan 2023 13:10:22 +0000 (17:10 +0400)]
Merged with the default branch.

3 years agoUpdated link to OpenVZ suspend/resume bug.
Maxim Dounin [Wed, 21 Dec 2022 11:53:27 +0000 (14:53 +0300)]
Updated link to OpenVZ suspend/resume bug.

3 years agoFixed port ranges support in the listen directive.
Valentin Bartenev [Sun, 18 Dec 2022 18:29:02 +0000 (21:29 +0300)]
Fixed port ranges support in the listen directive.

Ports difference must be respected when checking addresses for duplicates,
otherwise configurations like this are broken:

  listen 127.0.0.1:6000-6005

It was broken by 4cc2bfeff46c (nginx 1.23.3).

3 years agoStyle.
BullerDu [Thu, 15 Dec 2022 21:15:15 +0000 (01:15 +0400)]
Style.

3 years agoVersion bump.
Sergey Kandaurov [Thu, 15 Dec 2022 21:15:13 +0000 (01:15 +0400)]
Version bump.

3 years agoMerged with the default branch.
Sergey Kandaurov [Thu, 15 Dec 2022 15:40:44 +0000 (19:40 +0400)]
Merged with the default branch.

3 years agorelease-1.23.3 tag
Maxim Dounin [Tue, 13 Dec 2022 15:53:53 +0000 (18:53 +0300)]
release-1.23.3 tag

3 years agonginx-1.23.3-RELEASE release-1.23.3
Maxim Dounin [Tue, 13 Dec 2022 15:53:53 +0000 (18:53 +0300)]
nginx-1.23.3-RELEASE

3 years agoUpdated OpenSSL and zlib used for win32 builds.
Maxim Dounin [Tue, 13 Dec 2022 00:32:57 +0000 (03:32 +0300)]
Updated OpenSSL and zlib used for win32 builds.

3 years agoWin32: event flags handling edge cases in ngx_wsarecv().
Maxim Dounin [Thu, 1 Dec 2022 01:22:36 +0000 (04:22 +0300)]
Win32: event flags handling edge cases in ngx_wsarecv().

Fixed event flags handling edge cases in ngx_wsarecv() and ngx_wsarecv_chain(),
notably to always reset rev->ready in case of errors (which wasn't the case
after ngx_socket_nread() errors), and after EOF (rev->ready was not cleared
if due to a misconfiguration a zero-sized buffer was used for reading).

3 years agoSSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.
Maxim Dounin [Thu, 1 Dec 2022 01:22:31 +0000 (04:22 +0300)]
SSL: fixed ngx_ssl_recv() to reset c->read->ready after errors.

With this change, behaviour of ngx_ssl_recv() now matches ngx_unix_recv(),
which used to always reset c->read->ready to 0 when returning errors.

This fixes an infinite loop in unbuffered SSL proxying if writing to the
client is blocked and an SSL error happens (ticket #2418).

With this change, the fix for a similar issue in the stream module
(6868:ee3645078759), which used a different approach of explicitly
testing c->read->error instead, is no longer needed and was reverted.

3 years agoRemoved casts from ngx_memcmp() macro.
Maxim Dounin [Wed, 30 Nov 2022 15:01:53 +0000 (18:01 +0300)]
Removed casts from ngx_memcmp() macro.

Casts are believed to be not needed, since memcmp() has "const void *"
arguments since introduction of the "void" type in C89.  And on pre-C89
platforms nginx is unlikely to compile without warnings anyway, as there
are no casts in memcpy() and memmove() calls.

These casts were added in 1648:89a47f19b9ec without any details on why they
were added, and Igor does not remember details either.  The most plausible
explanation is that they were copied from ngx_strcmp() and were not really
needed even at that time.

Prodded by Alejandro Colomar.

3 years agoFixed alignment of ngx_memmove()/ngx_movemem() macro definitions.
Maxim Dounin [Wed, 30 Nov 2022 15:01:43 +0000 (18:01 +0300)]
Fixed alignment of ngx_memmove()/ngx_movemem() macro definitions.

3 years agoSSL: fixed debug logging of SSL_sendfile() return value.
Sergey Kandaurov [Thu, 24 Nov 2022 19:08:30 +0000 (23:08 +0400)]
SSL: fixed debug logging of SSL_sendfile() return value.

3 years agoFixed segfault when switching off master process during upgrade.
Maxim Dounin [Wed, 23 Nov 2022 20:48:53 +0000 (23:48 +0300)]
Fixed segfault when switching off master process during upgrade.

Binary upgrades are not supported without master process, but it is,
however, possible, that nginx running with master process is asked
to upgrade binary, and the configuration file as available on disk
at this time includes "master_process off;".

If this happens, listening sockets inherited from the previous binary
will have ls[i].previous set.  But the old cycle on initial process
startup, including startup after binary upgrade, is destroyed by
ngx_init_cycle() once configuration parsing is complete.  As a result,
an attempt to dereference ls[i].previous in ngx_event_process_init()
accesses already freed memory.

Fix is to avoid looking into ls[i].previous if the old cycle is already
freed.

With this change it is also no longer needed to clear ls[i].previous in
worker processes, so the relevant code was removed.

3 years agoDisabled cloning of sockets without master process (ticket #2403).
Maxim Dounin [Wed, 23 Nov 2022 20:12:04 +0000 (23:12 +0300)]
Disabled cloning of sockets without master process (ticket #2403).

Cloning of listening sockets for each worker process does not make sense
when working without master process, and causes some of the connections
not to be accepted if worker_processes is set to more than one and there
are listening sockets configured with the reuseport flag.  Fix is to
disable cloning when master process is disabled.

3 years agoFiltering duplicate addresses in listen (ticket #2400).
Maxim Dounin [Wed, 23 Nov 2022 14:30:08 +0000 (17:30 +0300)]
Filtering duplicate addresses in listen (ticket #2400).

Due to the glibc bug[1], getaddrinfo("localhost") with AI_ADDRCONFIG
on a typical host with glibc and without IPv6 returns two 127.0.0.1
addresses, and therefore "listen localhost:80;" used to result in
"duplicate ... address and port pair" after 4f9b72a229c1.

Fix is to explicitly filter out duplicate addresses returned during
resolution of a name.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=14969

3 years agoProcess events posted by ngx_close_idle_connections() immediately.
Roman Arutyunyan [Fri, 18 Nov 2022 15:31:38 +0000 (19:31 +0400)]
Process events posted by ngx_close_idle_connections() immediately.

Previously, if an event was posted by a read event handler, called by
ngx_close_idle_connections(), that event was not processed until the next
event loop iteration, which could happen after a timeout.

3 years agoSSI: handling of subrequests from other modules (ticket #1263).
Ciel Zhao [Mon, 21 Nov 2022 14:01:34 +0000 (17:01 +0300)]
SSI: handling of subrequests from other modules (ticket #1263).

As the SSI parser always uses the context from the main request for storing
variables and blocks, that context should always exist for subrequests using
SSI, even though the main request does not necessarily have SSI enabled.

However, `ngx_http_get_module_ctx(r->main, ...)` is getting NULL in such cases,
resulting in the worker crashing SIGSEGV when accessing its attributes.

This patch links the first initialized context to the main request, and
upgrades it only when main context is initialized.

3 years agoFixed PROXY protocol to use ngx_memcpy()/ngx_memcmp().
Maxim Dounin [Tue, 8 Nov 2022 09:48:21 +0000 (12:48 +0300)]
Fixed PROXY protocol to use ngx_memcpy()/ngx_memcmp().

3 years agoAdded logging to PROXY protocol write buffer check.
Maxim Dounin [Tue, 8 Nov 2022 09:48:19 +0000 (12:48 +0300)]
Added logging to PROXY protocol write buffer check.

The check is not expected to fail unless there is a bug in the calling
code.  But given the check is here, it should log an alert if it fails
instead of silently closing the connection.

3 years agoIncreased maximum read PROXY protocol header size.
Roman Arutyunyan [Wed, 2 Nov 2022 09:46:16 +0000 (13:46 +0400)]
Increased maximum read PROXY protocol header size.

Maximum size for reading the PROXY protocol header is increased to 4096 to
accommodate a bigger number of TLVs, which are supported since cca4c8a715de.

Maximum size for writing the PROXY protocol header is not changed since only
version 1 is currently supported.

3 years agoVersion bump.
Roman Arutyunyan [Thu, 3 Nov 2022 11:52:55 +0000 (15:52 +0400)]
Version bump.

3 years agoHTTP/3: implement keepalive for hq.
Roman Arutyunyan [Tue, 25 Oct 2022 08:52:09 +0000 (12:52 +0400)]
HTTP/3: implement keepalive for hq.

Previously, keepalive timer was deleted in ngx_http_v3_wait_request_handler()
and set in request cleanup handler.  This worked for HTTP/3 connections, but not
for hq connections.  Now keepalive timer is deleted in
ngx_http_v3_init_request_stream() and set in connection cleanup handler,
which works both for HTTP/3 and hq.

3 years agoQUIC: application init() callback.
Roman Arutyunyan [Wed, 30 Nov 2022 08:51:15 +0000 (12:51 +0400)]
QUIC: application init() callback.

It's called after handshake completion or prior to the first early data stream
creation.  The callback should initialize application-level data before
creating streams.

HTTP/3 callback implementation sets keepalive timer and sends SETTINGS.

Also, this allows to limit max handshake time in ngx_http_v3_init_stream().

3 years agorelease-1.23.2 tag
Maxim Dounin [Wed, 19 Oct 2022 07:56:21 +0000 (10:56 +0300)]
release-1.23.2 tag

3 years agonginx-1.23.2-RELEASE release-1.23.2
Maxim Dounin [Wed, 19 Oct 2022 07:56:20 +0000 (10:56 +0300)]
nginx-1.23.2-RELEASE

3 years agoMp4: disabled duplicate atoms.
Roman Arutyunyan [Wed, 19 Oct 2022 07:53:17 +0000 (10:53 +0300)]
Mp4: disabled duplicate atoms.

Most atoms should not appear more than once in a container.  Previously,
this was not enforced by the module, which could result in worker process
crash, memory corruption and disclosure.

3 years agoSSL: improved validation of ssl_session_cache and ssl_ocsp_cache.
Sergey Kandaurov [Mon, 17 Oct 2022 12:24:53 +0000 (16:24 +0400)]
SSL: improved validation of ssl_session_cache and ssl_ocsp_cache.

Now it properly detects invalid shared zone configuration with omitted size.
Previously it used to read outside of the buffer boundary.

Found with AddressSanitizer.

3 years agoSSL: removed cast not needed after 5ffd76a9ccf3.
Sergey Kandaurov [Thu, 13 Oct 2022 12:18:56 +0000 (16:18 +0400)]
SSL: removed cast not needed after 5ffd76a9ccf3.

3 years agoSSL: workaround for session timeout handling with TLSv1.3.
Maxim Dounin [Wed, 12 Oct 2022 17:14:57 +0000 (20:14 +0300)]
SSL: workaround for session timeout handling with TLSv1.3.

OpenSSL with TLSv1.3 updates the session creation time on session
resumption and keeps the session timeout unmodified, making it possible
to maintain the session forever, bypassing client certificate expiration
and revocation.  To make sure session timeouts are actually used, we
now update the session creation time and reduce the session timeout
accordingly.

BoringSSL with TLSv1.3 ignores configured session timeouts and uses a
hardcoded timeout instead, 7 days.  So we update session timeout to
the configured value as soon as a session is created.

3 years agoSSL: optimized rotation of session ticket keys.
Maxim Dounin [Wed, 12 Oct 2022 17:14:55 +0000 (20:14 +0300)]
SSL: optimized rotation of session ticket keys.

Instead of syncing keys with shared memory on each ticket operation,
the code now does this only when the worker is going to change expiration
of the current key, or going to switch to a new key: that is, usually
at most once per second.

To do so without races, the code maintains 3 keys: current, previous,
and next.  If a worker will switch to the next key earlier, other workers
will still be able to decrypt new tickets, since they will be encrypted
with the next key.

3 years agoSSL: automatic rotation of session ticket keys.
Maxim Dounin [Wed, 12 Oct 2022 17:14:53 +0000 (20:14 +0300)]
SSL: automatic rotation of session ticket keys.

As long as ssl_session_cache in shared memory is configured, session ticket
keys are now automatically generated in shared memory, and rotated
periodically.  This can be beneficial from forward secrecy point of view,
and also avoids increased CPU usage after configuration reloads.

This also helps BoringSSL to properly resume sessions in configurations
with multiple worker processes and no ssl_session_ticket_key directives,
as BoringSSL tries to automatically rotate session ticket keys and does
this independently in different worker processes, thus breaking session
resumption between worker processes.

3 years agoSSL: shorter debug messages about session tickets.
Maxim Dounin [Wed, 12 Oct 2022 17:14:51 +0000 (20:14 +0300)]
SSL: shorter debug messages about session tickets.

3 years agoSSL: renamed session ticket key functions and data index.
Maxim Dounin [Wed, 12 Oct 2022 17:14:49 +0000 (20:14 +0300)]
SSL: renamed session ticket key functions and data index.

Previously used names are way too long, renamed to simplify writing code.

3 years agoSSL: renamed session ticket key type.
Maxim Dounin [Wed, 12 Oct 2022 17:14:47 +0000 (20:14 +0300)]
SSL: renamed session ticket key type.

The ngx_ssl_session_ticket_key_t is way too long, renamed to
ngx_ssl_ticket_key_t to simplify writing code.

3 years agoSSL: style.
Maxim Dounin [Wed, 12 Oct 2022 17:14:45 +0000 (20:14 +0300)]
SSL: style.

Runtime OCSP functions separated from configuration ones.

3 years agoSSL: explicit clearing of expired sessions.
Maxim Dounin [Wed, 12 Oct 2022 17:14:43 +0000 (20:14 +0300)]
SSL: explicit clearing of expired sessions.

This reduces lifetime of session keying material in server's memory, and
therefore can be beneficial from forward secrecy point of view.

3 years agoSSL: single allocation in session cache on 32-bit platforms.
Maxim Dounin [Wed, 12 Oct 2022 17:14:40 +0000 (20:14 +0300)]
SSL: single allocation in session cache on 32-bit platforms.

Given the present typical SSL session sizes, on 32-bit platforms it is
now beneficial to store all data in a single allocation, since rbtree
node + session id + ASN1 representation of a session takes 256 bytes of
shared memory (36 + 32 + 150 = about 218 bytes plus SNI server name).

Storing all data in a single allocation is beneficial for SNI names up to
about 40 characters long and makes it possible to store about 4000 sessions
in one megabyte (instead of about 3000 sessions now).  This also slightly
simplifies the code.

3 years agoSSL: explicit session id length checking.
Maxim Dounin [Wed, 12 Oct 2022 17:14:39 +0000 (20:14 +0300)]
SSL: explicit session id length checking.

Session ids are not expected to be longer than 32 bytes, but this is
theoretically possible with TLSv1.3, where session ids are essentially
arbitrary and sent as session tickets.  Since on 64-bit platforms we
use fixed 32-byte buffer for session ids, added an explicit length check
to make sure the buffer is large enough.

3 years agoSSL: updated comment about session sizes.
Maxim Dounin [Wed, 12 Oct 2022 17:14:37 +0000 (20:14 +0300)]
SSL: updated comment about session sizes.

Previous numbers are somewhat outdated, typical ASN1 representations of
sessions are slightly bigger now.

3 years agoSSL: reduced logging of session cache failures (ticket #621).
Maxim Dounin [Wed, 12 Oct 2022 17:14:36 +0000 (20:14 +0300)]
SSL: reduced logging of session cache failures (ticket #621).

Session cache allocations might fail as long as the new session is different
in size from the one least recently used (and freed when the first allocation
fails).  In particular, it might not be possible to allocate space for
sessions with client certificates, since they are noticeably bigger than
normal sessions.

To ensure such allocation failures won't clutter logs, logging level changed
to "warn", and logging is now limited to at most one warning per second.

3 years agoSSL: disabled saving tickets to session cache.
Maxim Dounin [Wed, 12 Oct 2022 17:14:34 +0000 (20:14 +0300)]
SSL: disabled saving tickets to session cache.

OpenSSL tries to save TLSv1.3 sessions into session cache even when using
tickets for stateless session resumption, "because some applications just
want to know about the creation of a session".  To avoid trashing session
cache with useless data, we do not save such sessions now.

3 years agoAdded type cast to ngx_proxy_protocol_parse_uint16().
Roman Arutyunyan [Tue, 27 Sep 2022 07:31:16 +0000 (11:31 +0400)]
Added type cast to ngx_proxy_protocol_parse_uint16().

The cast is added to make ngx_proxy_protocol_parse_uint16() similar to
ngx_proxy_protocol_parse_uint32().

3 years agoPROXY protocol v2 TLV variables.
Roman Arutyunyan [Wed, 12 Oct 2022 12:58:16 +0000 (16:58 +0400)]
PROXY protocol v2 TLV variables.

The variables have prefix $proxy_protocol_tlv_ and are accessible by name
and by type.  Examples are: $proxy_protocol_tlv_0x01, $proxy_protocol_tlv_alpn.

3 years agoLog only the first line of user input on PROXY protocol v1 error.
Roman Arutyunyan [Mon, 10 Oct 2022 09:57:31 +0000 (13:57 +0400)]
Log only the first line of user input on PROXY protocol v1 error.

Previously, all received user input was logged.  If a multi-line text was
received from client and logged, it could reduce log readability and also make
it harder to parse nginx log by scripts.  The change brings to PROXY protocol
the same behavior that exists for HTTP request line in
ngx_http_log_error_handler().

3 years agoSSL: silenced GCC warnings when building with BoringSSL.
Sergey Kandaurov [Thu, 8 Sep 2022 09:53:49 +0000 (13:53 +0400)]
SSL: silenced GCC warnings when building with BoringSSL.

BoringSSL uses macro stub for SSL_CTX_set_ecdh_auto that expands to 1,
which triggers -Wunused-value "statement with no effect" warnings.

3 years agoWin32: disabled threads support in OpenSSL builds.
Maxim Dounin [Tue, 6 Sep 2022 21:47:31 +0000 (00:47 +0300)]
Win32: disabled threads support in OpenSSL builds.

Threads are disabled during UNIX builds (see b329c0ab1a48), and also not
needed for Windows builds.

This used to be the default before OpenSSL 1.1.0.

3 years agoWin32: fixed build on Windows with OpenSSL 3.0.x (ticket #2379).
Maxim Dounin [Tue, 6 Sep 2022 21:47:17 +0000 (00:47 +0300)]
Win32: fixed build on Windows with OpenSSL 3.0.x (ticket #2379).

SSL_sendfile() expects integer file descriptor as an argument, but nginx
uses OS file handles (HANDLE) to work with files on Windows, and passing
HANDLE instead of an integer correctly results in build failure.  Since
SSL_sendfile() is not expected to work on Windows anyway, the code is now
disabled on Windows with appropriate compile-time checks.

3 years agoWin32: disabled C4306 warnings with MSVC.
Maxim Dounin [Tue, 6 Sep 2022 21:47:07 +0000 (00:47 +0300)]
Win32: disabled C4306 warnings with MSVC.

Multiple C4306 warnings (conversion from 'type1' to 'type2' of greater size)
appear during 64-bit compilation with MSVC 2010 (and older) due to extensively
used constructs like "(void *) -1", so they were disabled.

In newer MSVC versions C4306 warnings were replaced with C4312 ones, and
these are not generated for such trivial type casts.

3 years agoWin32: removed misleading comment about warnings being disabled.
Maxim Dounin [Tue, 6 Sep 2022 21:47:02 +0000 (00:47 +0300)]
Win32: removed misleading comment about warnings being disabled.

Warnings being disabled are not only from the "-W4" level since e4590dfd97ff.

3 years agoSSL: fixed incorrect usage of #if instead of #ifdef.
Maxim Dounin [Tue, 6 Sep 2022 21:44:10 +0000 (00:44 +0300)]
SSL: fixed incorrect usage of #if instead of #ifdef.

In 2014ed60f17f, "#if SSL_CTRL_SET_ECDH_AUTO" test was incorrectly used
instead of "#ifdef SSL_CTRL_SET_ECDH_AUTO".  There is no practical
difference, since SSL_CTRL_SET_ECDH_AUTO evaluates to a non-zero numeric
value when defined, but anyway it's better to correctly test if the value
is defined.

3 years agoEvents: fixed style and wrong error handling in the iocp module.
Maxim Dounin [Tue, 6 Sep 2022 21:43:51 +0000 (00:43 +0300)]
Events: fixed style and wrong error handling in the iocp module.

3 years agoHTTP/3: renamed functions.
Roman Arutyunyan [Mon, 22 Aug 2022 10:09:03 +0000 (14:09 +0400)]
HTTP/3: renamed functions.

ngx_http_v3_init() is renamed ngx_http_v3_init_stream().
ngx_http_v3_reset_connection() is renamed to ngx_http_v3_reset_stream().

3 years agoQUIC: removed cancelable flag from QUIC and HTTP/3 events.
Roman Arutyunyan [Wed, 30 Nov 2022 10:09:08 +0000 (14:09 +0400)]
QUIC: removed cancelable flag from QUIC and HTTP/3 events.

All these events are created in context of a client connection and are deleted
when the connection is closed.  Setting ev->cancelable could trigger premature
connection closure and a socket leak alert.

3 years agoQUIC: idle mode for main connection.
Roman Arutyunyan [Wed, 19 Oct 2022 13:45:18 +0000 (17:45 +0400)]
QUIC: idle mode for main connection.

Now main QUIC connection for HTTP/3 always has c->idle flag set.  This allows
the connection to receive worker shutdown notification.  It is passed to
application level via a new conf->shutdown() callback.

The HTTP/3 shutdown callback sends GOAWAY to client and gracefully shuts down
the QUIC connection.

3 years agoHTTP/3: unified hq code with regular HTTP/3 code.
Roman Arutyunyan [Wed, 19 Oct 2022 13:45:30 +0000 (17:45 +0400)]
HTTP/3: unified hq code with regular HTTP/3 code.

The change removes hq-specific request handler.  Now hq requests are handled
by the HTTP/3 request handler.

3 years agoQUIC: do not send MAX_STREAMS in shutdown state.
Roman Arutyunyan [Wed, 7 Sep 2022 09:12:56 +0000 (13:12 +0400)]
QUIC: do not send MAX_STREAMS in shutdown state.

No more streams are expected from client.

3 years agoQUIC: defer stream removal until all its data is acked.
Roman Arutyunyan [Mon, 22 Aug 2022 11:33:23 +0000 (15:33 +0400)]
QUIC: defer stream removal until all its data is acked.

Previously, stream was kept alive until all its data is sent.  This resulted
in disabling retransmission of final part of stream when QUIC connection
was closed right after closing stream connection.

3 years agoQUIC: reusable mode for main connection.
Roman Arutyunyan [Tue, 29 Nov 2022 13:46:46 +0000 (17:46 +0400)]
QUIC: reusable mode for main connection.

The connection is automatically switched to this mode by transport layer when
there are no non-cancelable streams.  Currently, cancelable streams are
HTTP/3 encoder/decoder/control streams.

3 years agoQUIC: post close event for connection close.
Roman Arutyunyan [Wed, 7 Sep 2022 15:25:13 +0000 (19:25 +0400)]
QUIC: post close event for connection close.

Previously, close event was used only for close timeout, while read event was
used for posting connection close.

3 years agoQUIC: made ngx_quic_finalize_connecion() more graceful.
Roman Arutyunyan [Mon, 22 Aug 2022 11:28:51 +0000 (15:28 +0400)]
QUIC: made ngx_quic_finalize_connecion() more graceful.

Previously, ngx_quic_finalize_connection() closed the connection with NGX_ERROR
code, which resulted in immediate connection closure.  Now the code is NGX_OK,
which provides a more graceful shutdown with a timeout.

3 years agoQUIC: treat qc->error == -1 as a missing error.
Roman Arutyunyan [Wed, 7 Sep 2022 08:37:15 +0000 (12:37 +0400)]
QUIC: treat qc->error == -1 as a missing error.

Previously, zero was used for this purpose.  However, NGX_QUIC_ERR_NO_ERROR is
zero too.  As a result, NGX_QUIC_ERR_NO_ERROR was changed to
NGX_QUIC_ERR_INTERNAL_ERROR when closing a QUIC connection.

3 years agoQUIC: fixed computation of nonce with packet numbers beyond 2^32.
Sergey Kandaurov [Fri, 25 Nov 2022 11:56:33 +0000 (15:56 +0400)]
QUIC: fixed computation of nonce with packet numbers beyond 2^32.

Prodded by Yu Zhu.

3 years agoHTTP/3: fixed build without NGX_PCRE (broken by 0f5fc7a320db).
Jiuzhou Cui [Fri, 25 Nov 2022 07:07:23 +0000 (15:07 +0800)]
HTTP/3: fixed build without NGX_PCRE (broken by 0f5fc7a320db).

3 years agoQUIC: fixed triggering stream read event (ticket #2409).
Roman Arutyunyan [Wed, 23 Nov 2022 14:50:26 +0000 (18:50 +0400)]
QUIC: fixed triggering stream read event (ticket #2409).

If a client packet carrying a stream data frame is not acked due to packet loss,
the stream data is retransmitted later by client.  It's also possible that the
retransmitted range is bigger than before due to more stream data being
available by then.  If the original data was read out by the application,
there would be no read event triggered by the retransmitted frame, even though
it contains new data.

3 years agoQUIC: fixed C4334 MSVC warning about 32 to 64 bits conversion.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:37 +0000 (18:05 +0400)]
QUIC: fixed C4334 MSVC warning about 32 to 64 bits conversion.

3 years agoQUIC: plug MSVC warning about potentially uninitialized variable.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:37 +0000 (18:05 +0400)]
QUIC: plug MSVC warning about potentially uninitialized variable.

3 years agoAdded shutdown macros for win32 required for QUIC.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:36 +0000 (18:05 +0400)]
Added shutdown macros for win32 required for QUIC.

3 years agoQUIC: fixed C4389 MSVC warning about signed/unsigned mismatch.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:36 +0000 (18:05 +0400)]
QUIC: fixed C4389 MSVC warning about signed/unsigned mismatch.

3 years agoQUIC: avoid using C99 designated initializers.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:35 +0000 (18:05 +0400)]
QUIC: avoid using C99 designated initializers.

They are not supported by MSVC till 2012.

SSL_QUIC_METHOD initialization is moved to run-time to preserve portability
among SSL library implementations, which allows to reduce its visibility.
Note using of a static storage to keep SSL_set_quic_method() reference valid.

3 years agoQUIC: moved variable declaration to fix build with MSVC 2010.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:35 +0000 (18:05 +0400)]
QUIC: moved variable declaration to fix build with MSVC 2010.

Previously, ngx_quic_hkdf_t variables used declaration with assignment
in the middle of a function, which is not supported by MSVC 2010.
Fixing this also required to rewrite the ngx_quic_hkdf_set macro
and to switch to an explicit array size.

3 years agoQUIC: fixed C4706 warnings with MSVC 2010.
Sergey Kandaurov [Tue, 22 Nov 2022 14:05:34 +0000 (18:05 +0400)]
QUIC: fixed C4706 warnings with MSVC 2010.

The fix is to avoid assignments within conditional expression.

3 years agoHTTP/3: fixed server_name regex captures (ticket #2407).
Sergey Kandaurov [Tue, 22 Nov 2022 10:10:04 +0000 (14:10 +0400)]
HTTP/3: fixed server_name regex captures (ticket #2407).

Previously, HTTP/3 stream connection didn't inherit the servername regex
from the main QUIC connection saved when processing SNI and using regular
expressions in server names.  As a result, it didn't execute to set regex
captures when choosing the virtual server while parsing HTTP/3 headers.

3 years agoSet default listen socket type in http.
Roman Arutyunyan [Tue, 1 Nov 2022 13:00:35 +0000 (17:00 +0400)]
Set default listen socket type in http.

The type field was added in 7999d3fbb765 at early stages of QUIC implementation
and was not initialized for default listen.  Missing initialization resulted in
default listen socket creation error.

3 years agoMerged with the default branch.
Sergey Kandaurov [Thu, 20 Oct 2022 12:41:36 +0000 (16:41 +0400)]
Merged with the default branch.

3 years agoREADME: converted to passive voice, LibreSSL support.
Sergey Kandaurov [Thu, 20 Oct 2022 12:30:43 +0000 (16:30 +0400)]
README: converted to passive voice, LibreSSL support.

3 years agoQUIC: removed compatibility with older BoringSSL API.
Sergey Kandaurov [Thu, 20 Oct 2022 12:21:07 +0000 (16:21 +0400)]
QUIC: removed compatibility with older BoringSSL API.

SSL_CIPHER_get_protocol_id() appeared in BoringSSL somewhere between
BORINGSSL_API_VERSION 12 and 13 for compatibility with OpenSSL 1.1.1.
It was adopted without a proper macro test, which remained unnoticed.
This justifies that such old BoringSSL API isn't widely used and its
support can be dropped.

While here, removed SSL_set_quic_use_legacy_codepoint() that became
useless after the default was flipped in BoringSSL over a year ago.

3 years agoQUIC: support for setting QUIC methods with LibreSSL.
Sergey Kandaurov [Thu, 20 Oct 2022 12:21:06 +0000 (16:21 +0400)]
QUIC: support for setting QUIC methods with LibreSSL.

Setting QUIC methods is converted to use C99 designated initializers
for simplicity, as LibreSSL 3.6.0 has different SSL_QUIC_METHOD layout.

Additionally, only set_read_secret/set_write_secret callbacks are set.
Although they are preferred in LibreSSL over set_encryption_secrets,
better be on a safe side as LibreSSL has unexpectedly incompatible
set_encryption_secrets calling convention expressed in passing read
and write secrets split in separate calls, unlike this is documented
in old BoringSSL sources.  To avoid introducing further changes for
the old API, it is simply disabled.

3 years agoQUIC: using SSL_set_quic_early_data_enabled() only with QuicTLS.
Sergey Kandaurov [Thu, 20 Oct 2022 12:21:06 +0000 (16:21 +0400)]
QUIC: using SSL_set_quic_early_data_enabled() only with QuicTLS.

This function is present in QuicTLS only.  After SSL_READ_EARLY_DATA_SUCCESS
became visible in LibreSSL together with experimental QUIC API, this required
to revise the conditional compilation test to use more narrow macros.

3 years agoQUIC: using native TLSv1.3 cipher suite constants.
Sergey Kandaurov [Thu, 20 Oct 2022 12:21:05 +0000 (16:21 +0400)]
QUIC: using native TLSv1.3 cipher suite constants.

After BoringSSL aligned[1] with OpenSSL on TLS1_3_CK_* macros, and
LibreSSL uses OpenSSL naming, our own variants can be dropped now.
Compatibility is preserved with libraries that lack these macros.

Additionally, transition to SSL_CIPHER_get_id() fixes build error
with LibreSSL that doesn't implement SSL_CIPHER_get_protocol_id().

[1] https://boringssl.googlesource.com/boringssl/+/dfddbc4ded

3 years agoQUIC: "info" logging level on insufficient client connection ids.
Sergey Kandaurov [Fri, 30 Sep 2022 13:24:47 +0000 (17:24 +0400)]
QUIC: "info" logging level on insufficient client connection ids.

Apparently, this error is reported on NAT rebinding if client didn't
previously send NEW_CONNECTION_ID to supply additional connection ids.

3 years agoREADME: updated the current status.
Sergey Kandaurov [Mon, 12 Sep 2022 14:37:36 +0000 (18:37 +0400)]
README: updated the current status.

3 years agoSSL: logging level of "bad record type" errors.
Murilo Andrade [Tue, 9 Aug 2022 20:13:46 +0000 (17:13 -0300)]
SSL: logging level of "bad record type" errors.

The SSL_R_BAD_RECORD_TYPE ("bad record type") errors are reported by
OpenSSL 1.1.1 or newer when using TLSv1.3 if the client sends a record
with unknown or unexpected type.  These errors are now logged at the
"info" level.

3 years agoVersion bump.
Maxim Dounin [Mon, 29 Aug 2022 22:52:51 +0000 (01:52 +0300)]
Version bump.

3 years agoHTTP/3: skip empty request body buffers (ticket #2374).
Roman Arutyunyan [Wed, 3 Aug 2022 12:59:51 +0000 (16:59 +0400)]
HTTP/3: skip empty request body buffers (ticket #2374).

When client DATA frame header and its content come in different QUIC packets,
it may happen that only the header is processed by the first
ngx_http_v3_request_body_filter() call.  In this case an empty request body
buffer is added to r->request_body->bufs, which is later reused in a
subsequent ngx_http_v3_request_body_filter() call without being removed from
the body chain.  As a result, rb->request_body->bufs ends up with two copies of
the same buffer.

The fix is to avoid adding empty request body buffers to r->request_body->bufs.

3 years agorelease-1.23.1 tag
Maxim Dounin [Tue, 19 Jul 2022 14:05:27 +0000 (17:05 +0300)]
release-1.23.1 tag

3 years agonginx-1.23.1-RELEASE release-1.23.1
Maxim Dounin [Tue, 19 Jul 2022 14:05:27 +0000 (17:05 +0300)]
nginx-1.23.1-RELEASE

3 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 19 Jul 2022 14:03:30 +0000 (17:03 +0300)]
Updated OpenSSL used for win32 builds.

3 years agoEvents: fixed EPOLLRDHUP with FIONREAD (ticket #2367).
Maxim Dounin [Fri, 15 Jul 2022 12:19:32 +0000 (15:19 +0300)]
Events: fixed EPOLLRDHUP with FIONREAD (ticket #2367).

When reading exactly rev->available bytes, rev->available might become 0
after FIONREAD usage introduction in efd71d49bde0.  On the next call of
ngx_readv_chain() on systems with EPOLLRDHUP this resulted in return without
any actions, that is, with rev->ready set, and this in turn resulted in no
timers set in event pipe, leading to socket leaks.

Fix is to reset rev->ready in ngx_readv_chain() when returning due to
rev->available being 0 with EPOLLRDHUP, much like it is already done in
ngx_unix_recv().  This ensures that if rev->available will become 0, on
systems with EPOLLRDHUP support appropriate EPOLLRDHUP-specific handling
will happen on the next ngx_readv_chain() call.

While here, also synced ngx_readv_chain() to match ngx_unix_recv() and
reset rev->ready when returning due to rev->available being 0 with kqueue.
This is mostly cosmetic change, as rev->ready is anyway reset when
rev->available is set to 0.

3 years agoRange filter: clearing of pre-existing Content-Range headers.
Maxim Dounin [Fri, 15 Jul 2022 04:01:44 +0000 (07:01 +0300)]
Range filter: clearing of pre-existing Content-Range headers.

Some servers might emit Content-Range header on 200 responses, and this
does not seem to contradict RFC 9110: as per RFC 9110, the Content-Range
header has no meaning for status codes other than 206 and 416.  Previously
this resulted in duplicate Content-Range headers in nginx responses handled
by the range filter.  Fix is to clear pre-existing headers.

3 years agoResolver: fixed memory leak for the "ipv4=off" case.
Sergey Kandaurov [Thu, 14 Jul 2022 17:26:54 +0000 (21:26 +0400)]
Resolver: fixed memory leak for the "ipv4=off" case.

This change partially reverts 2a77754cd9fe to properly free rn->query.

Found by Coverity (CID 1507244).

3 years agoThe "ipv4=" parameter of the "resolver" directive.
Ruslan Ermilov [Tue, 12 Jul 2022 17:44:02 +0000 (21:44 +0400)]
The "ipv4=" parameter of the "resolver" directive.

When set to "off", only IPv6 addresses will be resolved, and no
A queries are ever sent (ticket #2196).

3 years agoSSL: logging levels of various errors added in OpenSSL 1.1.1.
Maxim Dounin [Tue, 12 Jul 2022 12:55:22 +0000 (15:55 +0300)]
SSL: logging levels of various errors added in OpenSSL 1.1.1.

Starting with OpenSSL 1.1.1, various additional errors can be reported
by OpenSSL in case of client-related issues, most notably during TLSv1.3
handshakes.  In particular, SSL_R_BAD_KEY_SHARE ("bad key share"),
SSL_R_BAD_EXTENSION ("bad extension"), SSL_R_BAD_CIPHER ("bad cipher"),
SSL_R_BAD_ECPOINT ("bad ecpoint").  These are now logged at the "info"
level.