summaryrefslogtreecommitdiffhomepage
path: root/src/core (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-01-25Merged with the default branch.Sergey Kandaurov2-17/+5
2022-01-19Core: simplify reader lock release.Pavel Pautov1-15/+3
2021-12-29Version bump.Maxim Dounin1-2/+2
2021-12-29Merged with the default branch.Sergey Kandaurov6-102/+462
2021-12-27Support for sendfile(SF_NOCACHE).Maxim Dounin1-4/+13
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.
2021-12-27Simplified sendfile(SF_NODISKIO) usage.Maxim Dounin4-37/+2
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;".
2021-12-25Core: added NGX_REGEX_MULTILINE for 3rd party modules.Maxim Dounin2-2/+11
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.
2021-12-25PCRE2 and PCRE binary compatibility.Maxim Dounin2-15/+48
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.
2021-12-25PCRE2 library support.Maxim Dounin2-10/+351
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.
2021-12-25Core: ngx_regex.c style cleanup.Maxim Dounin1-17/+17
Notably, ngx_pcre_pool and ngx_pcre_studies are renamed to ngx_regex_pool and ngx_regex_studies, respectively.
2021-12-25Core: fixed ngx_pcre_studies cleanup.Maxim Dounin1-40/+43
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).
2021-12-24Merged with the default branch.Ruslan Ermilov1-2/+2
2021-11-23Version bump.Sergey Kandaurov1-2/+2
2021-10-30Changed ngx_chain_update_chains() to test tag first (ticket #2248).Maxim Dounin1-4/+4
Without this change, aio used with HTTP/2 can result in connection hang, as observed with "aio threads; aio_write on;" and proxying (ticket #2248). The problem is that HTTP/2 updates buffers outside of the output filters (notably, marks them as sent), and then posts a write event to call output filters. If a filter does not call the next one for some reason (for example, because of an AIO operation in progress), this might result in a state when the owner of a buffer already called ngx_chain_update_chains() and can reuse the buffer, while the same buffer is still sitting in the busy chain of some other filter. In the particular case a buffer was sitting in output chain's ctx->busy, and was reused by event pipe. Output chain's ctx->busy was permanently blocked by it, and this resulted in connection hang. Fix is to change ngx_chain_update_chains() to skip buffers from other modules unconditionally, without trying to wait for these buffers to become empty.
2021-10-29Upstream: sendfile_max_chunk support.Maxim Dounin1-0/+4
Previously, connections to upstream servers used sendfile() if it was enabled, but never honored sendfile_max_chunk. This might result in worker monopolization for a long time if large request bodies are allowed.
2021-11-03Merged with the default branch.Sergey Kandaurov5-10/+14
2021-09-14Removed NGX_OPENSSL_QUIC macro, NGX_QUIC is enough.Ruslan Ermilov1-1/+1
2021-09-08Merged with the default branch.Sergey Kandaurov1-2/+2
2021-09-06QUIC: store QUIC connection fd in stream fake connection.Roman Arutyunyan1-6/+6
Previously it had -1 as fd. This fixes proxying, which relies on downstream connection having a real fd. Also, this reduces diff to the default branch for ngx_close_connection().
2021-09-03Version bump.Roman Arutyunyan1-2/+2
2021-09-01Merged with the default branch.Sergey Kandaurov1-2/+2
2021-08-19Core: removed unnecessary restriction in hash initialization.Alexey Radkov1-0/+4
Hash initialization ignores elements with key.data set to NULL. Nevertheless, the initial hash bucket size check didn't skip them, resulting in unnecessary restrictions on, for example, variables with long names and with the NGX_HTTP_VARIABLE_NOHASH flag. Fix is to update the initial hash bucket size check to skip elements with key.data set to NULL, similarly to how it is done in other parts of the code.
2021-10-21Removed CLOCK_MONOTONIC_COARSE support.Maxim Dounin1-4/+0
While clock_gettime(CLOCK_MONOTONIC_COARSE) is faster than clock_gettime(CLOCK_MONOTONIC), the latter is fast enough on Linux for practical usage, and the difference is negligible compared to other costs at each event loop iteration. On the other hand, CLOCK_MONOTONIC_COARSE causes various issues with typical CONFIG_HZ=250, notably very inaccurate limit_rate handling in some edge cases (ticket #1678) and negative difference between $request_time and $upstream_response_time (ticket #1965).
2021-09-14Version bump.Roman Arutyunyan1-2/+2
2021-08-03Version bump.Maxim Dounin1-2/+2
2021-07-15Merged with the default branch.Sergey Kandaurov5-32/+49
2021-06-28Core: escaping of chars not allowed in URIs per RFC 3986.Maxim Dounin1-16/+29
Per RFC 3986 only the following characters are allowed in URIs unescaped: unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" And "%" can appear as a part of escaping itself. The following characters are not allowed and need to be escaped: %00-%1F, %7F-%FF, " ", """, "<", ">", "\", "^", "`", "{", "|", "}". Not escaping ">" is known to cause problems at least with MS Exchange (see http://nginx.org/pipermail/nginx-ru/2010-January/031261.html) and in Tomcat (ticket #2191). The patch adds escaping of the following chars in all URI parts: """, "<", ">", "\", "^", "`", "{", "|", "}". Note that comments are mostly preserved to outline important characters being escaped.
2021-06-28Core: fixed comment about escaping in arguments.Maxim Dounin1-1/+1
After 4954530db2af, the ";" character is escaped by ngx_escape_uri(NGX_ESCAPE_ARGS).
2021-06-21Core: added the ngx_rbtree_data() macro.Vladimir Homutov2-3/+4
2021-05-31Core: disabled SO_REUSEADDR on UDP sockets while testing config.Maxim Dounin1-11/+14
On Linux, SO_REUSEADDR allows completely duplicate UDP sockets, so using SO_REUSEADDR when testing configuration results in packets being dropped if there is an existing traffic on the sockets being tested (ticket #2187). While dropped packets are expected with UDP, it is better to avoid this when possible. With this change, SO_REUSEADDR is no longer set on datagram sockets when testing configuration.
2021-05-31Version bump.Maxim Dounin1-2/+2
2021-05-28Merged with the default branch.Sergey Kandaurov3-21/+30
2021-05-25Resolver: explicit check for compression pointers in question.Maxim Dounin1-0/+6
Since nginx always uses exactly one entry in the question section of a DNS query, and never uses compression pointers in this entry, parsing of a DNS response in ngx_resolver_process_response() does not expect compression pointers to appear in the question section of the DNS response. Indeed, compression pointers in the first name of a DNS response hardly make sense, do not seem to be allowed by RFC 1035 (which says "a pointer to a prior occurance of the same name", note "prior"), and were never observed in practice. Added an explicit check to ngx_resolver_process_response()'s parsing of the question section to properly report an error if compression pointers nevertheless appear in the question section.
2021-05-25Resolver: simplified ngx_resolver_copy().Maxim Dounin1-8/+5
Instead of checking on each label if we need to place a dot or not, now it always adds a dot after a label, and reduces the resulting length afterwards.
2021-05-25Resolver: reworked ngx_resolver_copy() copy loop.Maxim Dounin1-11/+7
To make the code easier to read, reworked the ngx_resolver_copy() copy loop to match the one used to calculate length. No functional changes.
2021-05-25Resolver: fixed label types handling in ngx_resolver_copy().Maxim Dounin1-0/+5
Previously, anything with any of the two high bits set were interpreted as compression pointers. This is incorrect, as RFC 1035 clearly states that "The 10 and 01 combinations are reserved for future use". Further, the 01 combination is actually allocated for EDNS extended label type (see RFC 2671 and RFC 6891), not really used though. Fix is to reject unrecognized label types rather than misinterpreting them as compression pointers.
2021-05-25Resolver: fixed off-by-one read in ngx_resolver_copy().Maxim Dounin1-0/+5
It is believed to be harmless, and in the worst case it uses some uninitialized memory as a part of the compression pointer length, eventually leading to the "name is out of DNS response" error.
2021-05-25Resolver: fixed off-by-one write in ngx_resolver_copy().Maxim Dounin1-4/+4
Reported by Luis Merino, Markus Vervier, Eric Sesterhenn, X41 D-Sec GmbH.
2021-05-19Core: fixed comment about msie_refresh escaping.Ruslan Ermilov1-1/+1
After 12a656452ad1, the "%" character is no longer escaped by ngx_escape_uri(NGX_ESCAPE_REFRESH).
2021-04-21Version bump.Maxim Dounin1-2/+2
2021-04-08Introduced the "keepalive_time" directive.Maxim Dounin2-0/+5
Similar to lingering_time, it limits total connection lifetime before keepalive is switched off. The default is 1 hour, which is close to the total maximum connection lifetime possible with default keepalive_requests and keepalive_timeout.
2021-04-16Merged with the default branch.Sergey Kandaurov3-2/+7
2021-04-05Version bump.Maxim Dounin1-2/+2
2021-03-28Resolver: added missing event handling after reading.Maxim Dounin1-2/+17
If we need to be notified about further events, ngx_handle_read_event() needs to be called after a read event is processed. Without this, an event can be removed from the kernel and won't be reported again, notably when using oneshot event methods, such as eventport on Solaris. While here, error handling is also added, similar to one present in ngx_resolver_tcp_read(). This is not expected to make a difference and mostly added for consistency.
2021-03-30Merged with the default branch.Sergey Kandaurov2-4/+19
2021-03-23Core: fixed build with BPF on non-64bit platforms (ticket #2152).Vladimir Homutov1-8/+8
2021-03-11Version bump.Maxim Dounin1-2/+2
2021-03-10Merged with the default branch.Sergey Kandaurov1-2/+2
2021-02-20Version bump.Ruslan Ermilov1-2/+2
2021-02-17Merged with the default branch.Sergey Kandaurov3-4/+18