]> git.kaiwu.me - nginx.git/log
nginx.git
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 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 agoQUIC: avoided pool usage in token calculation.
Vladimir Homutov [Tue, 31 May 2022 07:05:22 +0000 (11:05 +0400)]
QUIC: avoided pool usage in token calculation.

3 years agoQUIC: removed ngx_quic_keys_new().
Vladimir Homutov [Wed, 27 Jul 2022 13:31:16 +0000 (17:31 +0400)]
QUIC: removed ngx_quic_keys_new().

The ngx_quic_keys_t structure is now exposed.

3 years agoQUIC: avoided pool usage in ngx_quic_protection.c.
Vladimir Homutov [Wed, 27 Jul 2022 13:16:40 +0000 (17:16 +0400)]
QUIC: avoided pool usage in ngx_quic_protection.c.

3 years agoQUIC: fixed-length buffers for secrets.
Vladimir Homutov [Wed, 27 Jul 2022 13:15:33 +0000 (17:15 +0400)]
QUIC: fixed-length buffers for secrets.

3 years agoMerged with the default branch.
Sergey Kandaurov [Tue, 26 Jul 2022 15:54:11 +0000 (19:54 +0400)]
Merged with the default branch.

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.

3 years agoUpstream: optimized use of SSL contexts (ticket #1234).
Maxim Dounin [Tue, 28 Jun 2022 23:47:45 +0000 (02:47 +0300)]
Upstream: optimized use of SSL contexts (ticket #1234).

To ensure optimal use of memory, SSL contexts for proxying are now
inherited from previous levels as long as relevant proxy_ssl_* directives
are not redefined.

Further, when no proxy_ssl_* directives are redefined in a server block,
we now preserve plcf->upstream.ssl in the "http" section configuration
to inherit it to all servers.

Similar changes made in uwsgi, grpc, and stream proxy.

3 years agoVersion bump.
Maxim Dounin [Tue, 28 Jun 2022 23:47:38 +0000 (02:47 +0300)]
Version bump.

3 years agoMerged with the default branch.
Sergey Kandaurov [Wed, 22 Jun 2022 14:34:58 +0000 (18:34 +0400)]
Merged with the default branch.

3 years agorelease-1.23.0 tag
Maxim Dounin [Tue, 21 Jun 2022 14:25:37 +0000 (17:25 +0300)]
release-1.23.0 tag

3 years agonginx-1.23.0-RELEASE release-1.23.0
Maxim Dounin [Tue, 21 Jun 2022 14:25:36 +0000 (17:25 +0300)]
nginx-1.23.0-RELEASE

3 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 21 Jun 2022 14:09:34 +0000 (17:09 +0300)]
Updated OpenSSL used for win32 builds.

3 years agoMisc: win32 sources now preserved in release tarballs.
Maxim Dounin [Mon, 20 Jun 2022 16:30:50 +0000 (19:30 +0300)]
Misc: win32 sources now preserved in release tarballs.

This makes it possible to build nginx under Windows from release tarballs
instead of using source code repository.

3 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Sat, 18 Jun 2022 12:54:40 +0000 (15:54 +0300)]
Contrib: vim syntax, update core and 3rd party module directives.

List of 3rd party modules github repositories are obtained from
https://github.com/freebsd/freebsd-ports/blob/main/www/nginx-devel/Makefile.extmod

3 years agoPerl: removed unused variables, forgotten in ef6a3a99a81a.
Sergey Kandaurov [Tue, 14 Jun 2022 06:39:58 +0000 (10:39 +0400)]
Perl: removed unused variables, forgotten in ef6a3a99a81a.

3 years agoHTTP/3: updated SETTINGS_MAX_FIELD_SECTION_SIZE name.
Sergey Kandaurov [Wed, 8 Jun 2022 12:19:01 +0000 (16:19 +0400)]
HTTP/3: updated SETTINGS_MAX_FIELD_SECTION_SIZE name.

3 years agoREADME: updated after HTTP/3 RFC publication, minor refinements.
Sergey Kandaurov [Wed, 8 Jun 2022 11:30:08 +0000 (15:30 +0400)]
README: updated after HTTP/3 RFC publication, minor refinements.

3 years agoResolver: make TCP write timer event cancelable.
Aleksei Bavshin [Thu, 2 Jun 2022 03:17:23 +0000 (20:17 -0700)]
Resolver: make TCP write timer event cancelable.

Similar to 70e65bf8dfd7, the change is made to ensure that the ability to
cancel resolver tasks is fully controlled by the caller.  As mentioned in the
referenced commit, it is safe to make this timer cancelable because resolve
tasks can have their own timeouts that are not cancelable.

The scenario where this may become a problem is a periodic background resolve
task (not tied to a specific request or a client connection), which receives a
response with short TTL, large enough to warrant fallback to a TCP query.
With each event loop wakeup, we either have a previously set write timer
instance or schedule a new one.  The non-cancelable write timer can delay or
block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable
flag is set by the API user, and there are no other tasks or connections.

We use the resolver API in this way to maintain the list of upstream server
addresses specified with the 'resolve' parameter, and there could be third-party
modules implementing similar logic.

3 years agoHTTP/3: require that field section base index is not negative.
Roman Arutyunyan [Thu, 26 May 2022 12:17:56 +0000 (16:17 +0400)]
HTTP/3: require that field section base index is not negative.

RFC 9204 explicitly requires that.

3 years agoStream: don't flush empty buffers created for read errors.
Aleksei Bavshin [Mon, 23 May 2022 18:29:44 +0000 (11:29 -0700)]
Stream: don't flush empty buffers created for read errors.

When we generate the last_buf buffer for an UDP upstream recv error, it does
not contain any data from the wire. ngx_stream_write_filter attempts to forward
it anyways, which is incorrect (e.g., UDP upstream ECONNREFUSED will be
translated to an empty packet).

This happens because we mark the buffer as both 'flush' and 'last_buf', and
ngx_stream_write_filter has special handling for flush with certain types of
connections (see d127837c714f32b0ba4855a6).  The flags are meant to be
mutually exclusive, so the fix is to ensure that flush and last_buf are not set
at the same time.

Reproduction:

stream {
    upstream unreachable {
        server     127.0.0.1:8880;
    }
    server {
        listen     127.0.0.1:8998 udp;
        proxy_pass unreachable;
    }
}

1 0.000000000    127.0.0.1 → 127.0.0.1    UDP 47 45588 → 8998 Len=5
2 0.000166300    127.0.0.1 → 127.0.0.1    UDP 47 51149 → 8880 Len=5
3 0.000172600    127.0.0.1 → 127.0.0.1    ICMP 75 Destination unreachable (Port
unreachable)
4 0.000202400    127.0.0.1 → 127.0.0.1    UDP 42 8998 → 45588 Len=0

Fixes d127837c714f.

3 years agoMp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().
Maxim Dounin [Tue, 7 Jun 2022 18:58:52 +0000 (21:58 +0300)]
Mp4: fixed potential overflow in ngx_http_mp4_crop_stts_data().

Both "count" and "duration" variables are 32-bit, so their product might
potentially overflow.  It is used to reduce 64-bit start_time variable,
and with very large start_time this can result in incorrect seeking.

Found by Coverity (CID 1499904).

3 years agoUpstream: handling of certificates specified as an empty string.
Sergey Kandaurov [Tue, 7 Jun 2022 16:08:57 +0000 (20:08 +0400)]
Upstream: handling of certificates specified as an empty string.

Now, if the directive is given an empty string, such configuration cancels
loading of certificates, in particular, if they would be otherwise inherited
from the previous level.  This restores previous behaviour, before variables
support in certificates was introduced (3ab8e1e2f0f7).

3 years agoUpstream: fixed X-Accel-Expires/Cache-Control/Expires handling.
Maxim Dounin [Mon, 6 Jun 2022 21:07:12 +0000 (00:07 +0300)]
Upstream: fixed X-Accel-Expires/Cache-Control/Expires handling.

Previously, if caching was disabled due to Expires in the past, nginx
failed to cache the response even if it was cacheable as per subsequently
parsed Cache-Control header (ticket #964).

Similarly, if caching was disabled due to Expires in the past,
"Cache-Control: no-cache" or "Cache-Control: max-age=0", caching was not
used if it was cacheable as per subsequently parsed X-Accel-Expires header.

Fix is to avoid disabling caching immediately after parsing Expires in
the past or Cache-Control, but rather set flags which are later checked by
ngx_http_upstream_process_headers() (and cleared by "Cache-Control: max-age"
and X-Accel-Expires).

Additionally, now X-Accel-Expires does not prevent parsing of cache control
extensions, notably stale-while-revalidate and stale-if-error.  This
ensures that order of the X-Accel-Expires and Cache-Control headers is not
important.

Prodded by Vadim Fedorenko and Yugo Horie.

3 years agoUpstream: fixed build without http cache (broken by cd73509f21e2).
Maxim Dounin [Mon, 30 May 2022 21:14:11 +0000 (00:14 +0300)]
Upstream: fixed build without http cache (broken by cd73509f21e2).

3 years agoHeaders filter: improved memory allocation error handling.
Maxim Dounin [Mon, 30 May 2022 18:25:57 +0000 (21:25 +0300)]
Headers filter: improved memory allocation error handling.

3 years agoMultiple WWW-Authenticate headers with "satisfy any;".
Maxim Dounin [Mon, 30 May 2022 18:25:56 +0000 (21:25 +0300)]
Multiple WWW-Authenticate headers with "satisfy any;".

If a module adds multiple WWW-Authenticate headers (ticket #485) to the
response, linked in r->headers_out.www_authenticate, all headers are now
cleared if another module later allows access.

This change is a nop for standard modules, since the only access module which
can add multiple WWW-Authenticate headers is the auth request module, and
it is checked after other standard access modules.  Though this might
affect some third party access modules.

Note that if a 3rd party module adds a single WWW-Authenticate header
and not yet modified to set the header's next pointer to NULL, attempt to
clear such a header with this change will result in a segmentation fault.

3 years agoAuth request: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin [Mon, 30 May 2022 18:25:54 +0000 (21:25 +0300)]
Auth request: multiple WWW-Authenticate headers (ticket #485).

When using auth_request with an upstream server which returns 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.

3 years agoUpstream: multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin [Mon, 30 May 2022 18:25:53 +0000 (21:25 +0300)]
Upstream: multiple WWW-Authenticate headers (ticket #485).

When using proxy_intercept_errors and an error page for error 401
(Unauthorized), multiple WWW-Authenticate headers from the upstream server
response are now properly copied to the response.

3 years agoUpstream: handling of multiple Vary headers (ticket #1423).
Maxim Dounin [Mon, 30 May 2022 18:25:51 +0000 (21:25 +0300)]
Upstream: handling of multiple Vary headers (ticket #1423).

Previously, only the last header value was used when caching.

3 years agoUpstream: duplicate headers ignored or properly linked.
Maxim Dounin [Mon, 30 May 2022 18:25:49 +0000 (21:25 +0300)]
Upstream: duplicate headers ignored or properly linked.

Most of the known duplicate upstream response headers are now ignored
with a warning.

If syntax permits multiple headers, these are now properly linked to
the lists, notably Vary and WWW-Authenticate.  This makes it possible
to further handle such lists where it makes sense.

3 years agoUpstream: header handlers can now return parsing errors.
Maxim Dounin [Mon, 30 May 2022 18:25:48 +0000 (21:25 +0300)]
Upstream: header handlers can now return parsing errors.

With this change, duplicate Content-Length and Transfer-Encoding headers
are now rejected.  Further, responses with invalid Content-Length or
Transfer-Encoding headers are now rejected, as well as responses with both
Content-Length and Transfer-Encoding.

3 years agoUpstream: all known headers in u->headers_in are linked lists now.
Maxim Dounin [Mon, 30 May 2022 18:25:46 +0000 (21:25 +0300)]
Upstream: all known headers in u->headers_in are linked lists now.

3 years agoAll known output headers can be linked lists now.
Maxim Dounin [Mon, 30 May 2022 18:25:45 +0000 (21:25 +0300)]
All known output headers can be linked lists now.

The h->next pointer properly provided as NULL in all cases where known
output headers are added.

Note that there are 3rd party modules which might not do this, and it
might be risky to rely on this for arbitrary headers.

3 years agoUpstream: simplified Accept-Ranges handling.
Maxim Dounin [Mon, 30 May 2022 18:25:43 +0000 (21:25 +0300)]
Upstream: simplified Accept-Ranges handling.

The u->headers_in.accept_ranges field is not used anywhere and hence removed.

3 years agoUpstream: simplified Content-Encoding handling.
Maxim Dounin [Mon, 30 May 2022 18:25:42 +0000 (21:25 +0300)]
Upstream: simplified Content-Encoding handling.

Since introduction of offset handling in ngx_http_upstream_copy_header_line()
in revision 573:58475592100c, the ngx_http_upstream_copy_content_encoding()
function is no longer needed, as its behaviour is exactly equivalent to
ngx_http_upstream_copy_header_line() with appropriate offset.  As such,
the ngx_http_upstream_copy_content_encoding() function was removed.

Further, the u->headers_in.content_encoding field is not used anywhere,
so it was removed as well.

Further, Content-Encoding handling no longer depends on NGX_HTTP_GZIP,
as it can be used even without any gzip handling compiled in (for example,
in the charset filter).

3 years agoUpstream: style.
Maxim Dounin [Mon, 30 May 2022 18:25:40 +0000 (21:25 +0300)]
Upstream: style.

3 years agoPerl: combining unknown headers during $r->header_in() lookup.
Maxim Dounin [Mon, 30 May 2022 18:25:38 +0000 (21:25 +0300)]
Perl: combining unknown headers during $r->header_in() lookup.

3 years agoPerl: all known input headers are handled identically.
Maxim Dounin [Mon, 30 May 2022 18:25:36 +0000 (21:25 +0300)]
Perl: all known input headers are handled identically.

As all known input headers are now linked lists, these are now handled
identically.  In particular, this makes it possible to access properly
combined values of headers not specifically handled previously, such
as "Via" or "Connection".

3 years agoAll non-unique input headers are now linked lists.
Maxim Dounin [Mon, 30 May 2022 18:25:35 +0000 (21:25 +0300)]
All non-unique input headers are now linked lists.

The ngx_http_process_multi_header_lines() function is removed, as it is
exactly equivalent to ngx_http_process_header_line().  Similarly,
ngx_http_variable_header() is used instead of ngx_http_variable_headers().

3 years agoReworked multi headers to use linked lists.
Maxim Dounin [Mon, 30 May 2022 18:25:33 +0000 (21:25 +0300)]
Reworked multi headers to use linked lists.

Multi headers are now using linked lists instead of arrays.  Notably,
the following fields were changed: r->headers_in.cookies (renamed
to r->headers_in.cookie), r->headers_in.x_forwarded_for,
r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control
u->headers_in.cookies (renamed to u->headers_in.set_cookie).

The r->headers_in.cookies and u->headers_in.cookies fields were renamed
to r->headers_in.cookie and u->headers_in.set_cookie to match header names.

The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines()
functions were changed accordingly.

With this change, multi headers are now essentially equivalent to normal
headers, and following changes will further make them equivalent.

3 years agoCombining unknown headers during variables lookup (ticket #1316).
Maxim Dounin [Mon, 30 May 2022 18:25:32 +0000 (21:25 +0300)]
Combining unknown headers during variables lookup (ticket #1316).

Previously, $http_*, $sent_http_*, $sent_trailer_*, $upstream_http_*,
and $upstream_trailer_* variables returned only the first header (with
a few specially handled exceptions: $http_cookie, $http_x_forwarded_for,
$sent_http_cache_control, $sent_http_link).

With this change, all headers are returned, combined together.  For
example, $http_foo variable will be "a, b" if there are "Foo: a" and
"Foo: b" headers in the request.

Note that $upstream_http_set_cookie will also return all "Set-Cookie"
headers (ticket #1843), though this might not be what one want, since
the "Set-Cookie" header does not follow the list syntax (see RFC 7230,
section 3.2.2).

3 years agoUwsgi: combining headers with identical names (ticket #1724).
Maxim Dounin [Mon, 30 May 2022 18:25:30 +0000 (21:25 +0300)]
Uwsgi: combining headers with identical names (ticket #1724).

The uwsgi specification states that "The uwsgi block vars represent a
dictionary/hash".  This implies that no duplicate headers are expected.

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".

3 years agoSCGI: combining headers with identical names (ticket #1724).
Maxim Dounin [Mon, 30 May 2022 18:25:28 +0000 (21:25 +0300)]
SCGI: combining headers with identical names (ticket #1724).

SCGI specification explicitly forbids headers with duplicate names
(section "3. Request Format"): "Duplicate names are not allowed in
the headers".

Further, provided headers are expected to follow CGI specification,
which also requires to combine headers (RFC 3875, section "4.1.18.
Protocol-Specific Meta-Variables"): "If multiple header fields with
the same field-name are received then the server MUST rewrite them
as a single value having the same semantics".

3 years agoFastCGI: combining headers with identical names (ticket #1724).
Maxim Dounin [Mon, 30 May 2022 18:25:27 +0000 (21:25 +0300)]
FastCGI: combining headers with identical names (ticket #1724).

FastCGI responder is expected to receive CGI/1.1 environment variables
in the parameters (see section "6.2 Responder" of the FastCGI specification).
Obviously enough, there cannot be multiple environment variables with
the same name.

Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific
Meta-Variables") explicitly requires to combine headers: "If multiple
header fields with the same field-name are received then the server MUST
rewrite them as a single value having the same semantics".

3 years agoPerl: fixed $r->header_in("Connection").
Maxim Dounin [Mon, 30 May 2022 18:25:25 +0000 (21:25 +0300)]
Perl: fixed $r->header_in("Connection").

Previously, the r->header_in->connection pointer was never set despite
being present in ngx_http_headers_in, resulting in incorrect value returned
by $r->header_in("Connection") in embedded perl.

3 years agoFixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball [Sun, 29 May 2022 23:38:07 +0000 (02:38 +0300)]
Fixed runtime handling of systems without EPOLLRDHUP support.

In 7583:efd71d49bde0 (nginx 1.17.5) along with introduction of the
ioctl(FIONREAD) support proper handling of systems without EPOLLRDHUP
support in the kernel (but with EPOLLRDHUP in headers) was broken.

Before the change, rev->available was never set to 0 unless
ngx_use_epoll_rdhup was also set (that is, runtime test for EPOLLRDHUP
introduced in 6536:f7849bfb6d21 succeeded).  After the change,
rev->available might reach 0 on systems without runtime EPOLLRDHUP
support, stopping further reading in ngx_readv_chain() and ngx_unix_recv().
And, if EOF happened to be already reported along with the last event,
it is not reported again by epoll_wait(), leading to connection hangs
and timeouts on such systems.

This affects Linux kernels before 2.6.17 if nginx was compiled
with newer headers, and, more importantly, emulation layers, such as
DigitalOcean's App Platform's / gVisor's epoll emulation layer.

Fix is to explicitly check ngx_use_epoll_rdhup before the corresponding
rev->pending_eof tests in ngx_readv_chain() and ngx_unix_recv().

3 years agoVersion bump.
Maxim Dounin [Sun, 29 May 2022 23:37:59 +0000 (02:37 +0300)]
Version bump.

3 years agoUpdated OpenSSL and zlib used for win32 builds.
Maxim Dounin [Mon, 23 May 2022 23:51:49 +0000 (02:51 +0300)]
Updated OpenSSL and zlib used for win32 builds.

4 years agoConfigure: recognize arm64 machine name as a synonym for aarch64.
Sergey Kandaurov [Fri, 29 Apr 2022 13:38:01 +0000 (17:38 +0400)]
Configure: recognize arm64 machine name as a synonym for aarch64.

In particular, this sets a reasonable cacheline size on FreeBSD and macOS,
which prefer to use this name and both lack _SC_LEVEL1_DCACHE_LINESIZE.

4 years agoQUIC: separate UDP framework for QUIC.
Roman Arutyunyan [Wed, 20 Apr 2022 12:01:17 +0000 (16:01 +0400)]
QUIC: separate UDP framework for QUIC.

Previously, QUIC used the existing UDP framework, which was created for UDP in
Stream.  However the way QUIC connections are created and looked up is different
from the way UDP connections in Stream are created and looked up.  Now these
two implementations are decoupled.

4 years agoQUIC: fixed insertion at the end of buffer.
Roman Arutyunyan [Thu, 17 Feb 2022 19:38:42 +0000 (22:38 +0300)]
QUIC: fixed insertion at the end of buffer.

Previously, last buffer was tracked by keeping a pointer to the previous
chain link "next" field.  When the previous buffer was split and then removed,
the pointer was no longer valid.  Writing at this pointer resulted in broken
data chains.

Now last buffer is tracked by keeping a direct pointer to it.

4 years agoQUIC: fixed indentation.
Sergey Kandaurov [Wed, 16 Feb 2022 12:45:47 +0000 (15:45 +0300)]
QUIC: fixed indentation.

4 years agoQUIC: optimize insertion at the end of QUIC buffer.
Roman Arutyunyan [Mon, 14 Feb 2022 11:54:34 +0000 (14:54 +0300)]
QUIC: optimize insertion at the end of QUIC buffer.

4 years agoQUIC: eliminated ngx_quic_copy_buf().
Roman Arutyunyan [Mon, 14 Feb 2022 11:53:46 +0000 (14:53 +0300)]
QUIC: eliminated ngx_quic_copy_buf().

Its only call is substituted with QUIC buffer write/read pair.

4 years agoQUIC: trim input chain in ngx_quic_buffer_write().
Roman Arutyunyan [Mon, 14 Feb 2022 11:51:10 +0000 (14:51 +0300)]
QUIC: trim input chain in ngx_quic_buffer_write().

This allows to eliminate explicit trimming when handling input STREAM frame.
As a result, ngx_quic_trim_chain() is eliminated as well.

4 years agoQUIC: ngx_quic_buffer_t object.
Roman Arutyunyan [Mon, 14 Feb 2022 12:27:59 +0000 (15:27 +0300)]
QUIC: ngx_quic_buffer_t object.

The object is used instead of ngx_chain_t pointer for buffer operations like
ngx_quic_write_chain() and ngx_quic_read_chain().  These functions are renamed
to ngx_quic_write_buffer() and ngx_quic_read_buffer().

4 years agoSSL: logging level of "application data after close notify".
Sergey Kandaurov [Tue, 8 Feb 2022 14:35:27 +0000 (17:35 +0300)]
SSL: logging level of "application data after close notify".

Such fatal errors are reported by OpenSSL 1.1.1, and similarly by BoringSSL,
if application data is encountered during SSL shutdown, which started to be
observed on the second SSL_shutdown() call after SSL shutdown fixes made in
09fb2135a589 (1.19.2).  The error means that the client continues to send
application data after receiving the "close_notify" alert (ticket #2318).
Previously it was reported as SSL_shutdown() error of SSL_ERROR_SYSCALL.

4 years agoQUIC: stream lingering.
Roman Arutyunyan [Sat, 5 Feb 2022 09:54:54 +0000 (12:54 +0300)]
QUIC: stream lingering.

Now ngx_quic_stream_t is decoupled from ngx_connection_t in a way that it
can persist after connection is closed by application.  During this period,
server is expecting stream final size from client for correct flow control.
Also, buffered output is sent to client as more flow control credit is granted.

4 years agoQUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov [Tue, 15 Feb 2022 11:12:34 +0000 (14:12 +0300)]
QUIC: optimized datagram expansion with half-RTT tickets.

As shown in RFC 8446, section 2.2, Figure 3, and further specified in
section 4.6.1, BoringSSL releases session tickets in Application Data
(along with Finished) early, based on a precalculated client Finished
transcript, once client signalled early data in extensions.

4 years agoMerged with the default branch.
Sergey Kandaurov [Mon, 14 Feb 2022 07:14:07 +0000 (10:14 +0300)]
Merged with the default branch.

4 years agoQUIC: fixed in-flight bytes accounting.
Vladimir Homutov [Wed, 9 Feb 2022 12:51:42 +0000 (15:51 +0300)]
QUIC: fixed in-flight bytes accounting.

Initially, frames are genereated and stored in ctx->frames.
Next, ngx_quic_output() collects frames to be sent in in ctx->sending.
On failure, ngx_quic_revert_sned() returns frames into ctx->frames.

On success, the ngx_quic_commit_send() moves ack-eliciting frames into
ctx->sent and frees non-ack-eliciting frames.
This function also updates in-flight bytes counter, so only actually sent
frames are accounted.

The counter is decremented in the following cases:
 - acknowledgment is received
 - packet was declared lost
 - we are discarding context completely

In each of this cases frame is removed from ctx->sent queue and in-flight
counter is accordingly decremented.

The patch fixes the case of discarding context - only removing frames
from ctx->sent must be followed by in-flight bytes counter decrement,
otherwise cg->in_flight could experience type underflow.

The issue appeared in b1676cd64dc9.

4 years agoQUIC: fixed output context restoring.
Vladimir Homutov [Wed, 9 Feb 2022 12:53:21 +0000 (15:53 +0300)]
QUIC: fixed output context restoring.

The cd8018bc81a5 fixed unintended send of non-padded initial packets,
but failed to restore context properly: only processed contexts need
to be restored.  As a consequence, a packet number could be restored
from uninitialized value.

4 years agoQUIC: fixed resetting stream wev->ready flag.
Roman Arutyunyan [Wed, 9 Feb 2022 11:49:05 +0000 (14:49 +0300)]
QUIC: fixed resetting stream wev->ready flag.

Previously, the flag could be reset after send_chain() with a limit, even
though there was room for more data.  The application then started waiting for
a write event notification, which never happened.

Now the wev->ready flag is only reset when flow control is exhausted.

4 years agoQUIC: fixed the "quic_stream_buffer_size" directive.
Vladimir Homutov [Tue, 8 Feb 2022 20:00:12 +0000 (23:00 +0300)]
QUIC: fixed the "quic_stream_buffer_size" directive.

The default value is now correctly set and the configuration
is properly merged.

4 years agoYear 2022.
Sergey Kandaurov [Fri, 4 Feb 2022 10:29:31 +0000 (13:29 +0300)]
Year 2022.

4 years agoHTTP/2: fixed closed_nodes overflow (ticket #1708).
Maxim Dounin [Thu, 3 Feb 2022 19:46:01 +0000 (22:46 +0300)]
HTTP/2: fixed closed_nodes overflow (ticket #1708).

With large http2_max_concurrent_streams or http2_max_concurrent_pushes, more
than 255 ngx_http_v2_node_t structures might be allocated, eventually leading
to h2c->closed_nodes overflow when closing corresponding streams.  This will
in turn result in additional allocations in ngx_http_v2_get_node_by_id().

While mostly harmless, it can result in excessive memory usage by a HTTP/2
connection, notably in configurations with many keepalive_requests allowed.
Fix is to use ngx_uint_t for h2c->closed_nodes instead of unsigned:8.

4 years agoQUIC: switch stream to DATA_RECVD state.
Roman Arutyunyan [Thu, 3 Feb 2022 15:11:59 +0000 (18:11 +0300)]
QUIC: switch stream to DATA_RECVD state.

The switch happens when received byte counter reaches stream final size.
Previously, this state was skipped.  The stream went from SIZE_KNOWN to
DATA_READ when all bytes were read by application.

The change prevents STOP_SENDING frames from being sent when all data is
received from client, but not yet fully read by application.

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 agoHTTP/2: made it possible to flush response headers (ticket #1743).
Maxim Dounin [Wed, 2 Feb 2022 22:44:38 +0000 (01:44 +0300)]
HTTP/2: made it possible to flush response headers (ticket #1743).

Response headers can be buffered in the SSL buffer.  But stream's fake
connection buffered flag did not reflect this, so any attempts to flush
the buffer without sending additional data were stopped by the write filter.

It does not seem to be possible to reflect this in fc->buffered though, as
we never known if main connection's c->buffered corresponds to the particular
stream or not.  As such, fc->buffered might prevent request finalization
due to sending data on some other stream.

Fix is to implement handling of flush buffers when the c->need_flush_buf
flag is set, similarly to the existing last buffer handling.  The same
flag is now used for UDP sockets in the stream module instead of explicit
checking of c->type.

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 agoCache: fixed race in ngx_http_file_cache_forced_expire().
Maxim Dounin [Tue, 1 Feb 2022 13:29:28 +0000 (16:29 +0300)]
Cache: fixed race in ngx_http_file_cache_forced_expire().

During configuration reload two cache managers might exist for a short
time.  If both tried to delete the same cache node, the "ignore long locked
inactive cache entry" alert appeared in logs.  Additionally,
ngx_http_file_cache_forced_expire() might be also called by worker
processes, with similar results.

Fix is to ignore cache nodes being deleted, similarly to how it is
done in ngx_http_file_cache_expire() since 3755:76e3a93821b1.  This
was somehow missed in 7002:ab199f0eb8e8, when ignoring long locked
cache entries was introduced in ngx_http_file_cache_forced_expire().

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 agoCore: added autotest for UDP segmentation offloading.
Vladimir Homutov [Wed, 26 Jan 2022 17:40:00 +0000 (20:40 +0300)]
Core: added autotest for UDP segmentation offloading.

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.